From a4cd5630b060871c42e59f7b95cf1e823c417db6 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Wed, 18 Sep 1996 05:35:50 +0000 Subject: [PATCH] Import of unmodified (but trimmed) gcc-2.7.2. The bigger parts of the non-i386, non-unix, and generatable files have been trimmed, but can easily be added in later if needed. gcc-2.7.2.1 will follow shortly, it's a very small delta to this and it's handy to have both available for reference for such little cost. The freebsd-specific changes will then be committed, and once the dust has settled, the bmakefiles will be committed to use this code. --- contrib/gcc/BUGS | 23 + contrib/gcc/COPYING | 339 + contrib/gcc/COPYING.LIB | 482 + contrib/gcc/ChangeLog | 5684 ++++++++++ contrib/gcc/Makefile.in | 2538 +++++ contrib/gcc/NEWS | 735 ++ contrib/gcc/ORDERS | 3757 +++++++ contrib/gcc/PROBLEMS | 117 + contrib/gcc/PROJECTS | 448 + contrib/gcc/README | 26 + contrib/gcc/README-fixinc | 9 + contrib/gcc/README.ACORN | 18 + contrib/gcc/README.ALTOS | 55 + contrib/gcc/README.APOLLO | 112 + contrib/gcc/README.DWARF | 574 + contrib/gcc/README.FRESCO | 17 + contrib/gcc/README.NS32K | 130 + contrib/gcc/README.RS6000 | 111 + contrib/gcc/README.TRAD | 55 + contrib/gcc/README.X11 | 447 + contrib/gcc/SERVICE | 852 ++ contrib/gcc/TESTS.FLUNK | 39 + contrib/gcc/alloca.c | 492 + contrib/gcc/assert.h | 54 + contrib/gcc/basic-block.h | 69 + contrib/gcc/bc-emit.c | 992 ++ contrib/gcc/bc-emit.h | 133 + contrib/gcc/bc-optab.c | 789 ++ contrib/gcc/bc-optab.h | 75 + contrib/gcc/bc-typecd.def | 21 + contrib/gcc/bc-typecd.h | 54 + contrib/gcc/bi-arity.c | 80 + contrib/gcc/bi-defs.h | 48 + contrib/gcc/bi-lexer.c | 167 + contrib/gcc/bi-opcode.c | 78 + contrib/gcc/bi-opname.c | 59 + contrib/gcc/bi-parser.y | 169 + contrib/gcc/bi-reverse.c | 61 + contrib/gcc/bi-run.h | 159 + contrib/gcc/build-make | 32 + contrib/gcc/bytecode.def | 322 + contrib/gcc/bytecode.h | 81 + contrib/gcc/bytetypes.h | 35 + contrib/gcc/c-aux-info.c | 644 ++ contrib/gcc/c-common.c | 2255 ++++ contrib/gcc/c-convert.c | 96 + contrib/gcc/c-decl.c | 6967 ++++++++++++ contrib/gcc/c-iterate.c | 596 + contrib/gcc/c-lang.c | 180 + contrib/gcc/c-lex.c | 2021 ++++ contrib/gcc/c-lex.h | 80 + contrib/gcc/c-parse.gperf | 84 + contrib/gcc/c-parse.in | 2900 +++++ contrib/gcc/c-pragma.c | 168 + contrib/gcc/c-pragma.h | 46 + contrib/gcc/c-tree.h | 490 + contrib/gcc/c-typeck.c | 6602 +++++++++++ contrib/gcc/caller-save.c | 770 ++ contrib/gcc/calls.c | 3203 ++++++ contrib/gcc/cccp.1 | 681 ++ contrib/gcc/cccp.c | 10440 ++++++++++++++++++ contrib/gcc/cexp.y | 1047 ++ contrib/gcc/collect2.c | 3409 ++++++ contrib/gcc/combine.c | 11103 +++++++++++++++++++ contrib/gcc/conditions.h | 116 + contrib/gcc/config.guess | 565 + contrib/gcc/config.sub | 867 ++ contrib/gcc/config/README | 5 + contrib/gcc/config/aoutos.h | 88 + contrib/gcc/config/fp-bit.c | 1352 +++ contrib/gcc/config/gnu.h | 30 + contrib/gcc/config/gofast.h | 96 + contrib/gcc/config/i386/386bsd.h | 81 + contrib/gcc/config/i386/aix386.h | 69 + contrib/gcc/config/i386/aix386ng.h | 143 + contrib/gcc/config/i386/att.h | 106 + contrib/gcc/config/i386/bsd.h | 130 + contrib/gcc/config/i386/bsd386.h | 18 + contrib/gcc/config/i386/config-nt.sed | 38 + contrib/gcc/config/i386/freebsd.h | 256 + contrib/gcc/config/i386/freebsd.h.fixed | 256 + contrib/gcc/config/i386/gas.h | 155 + contrib/gcc/config/i386/gnu.h | 20 + contrib/gcc/config/i386/go32.h | 64 + contrib/gcc/config/i386/gstabs.h | 9 + contrib/gcc/config/i386/i386-aout.h | 34 + contrib/gcc/config/i386/i386-coff.h | 97 + contrib/gcc/config/i386/i386.c | 3245 ++++++ contrib/gcc/config/i386/i386.h | 1934 ++++ contrib/gcc/config/i386/i386.md | 5775 ++++++++++ contrib/gcc/config/i386/i386iscgas.h | 67 + contrib/gcc/config/i386/isc.h | 89 + contrib/gcc/config/i386/isccoff.h | 12 + contrib/gcc/config/i386/iscdbx.h | 43 + contrib/gcc/config/i386/linux-aout.h | 76 + contrib/gcc/config/i386/linux-oldld.h | 76 + contrib/gcc/config/i386/linux.h | 212 + contrib/gcc/config/i386/lynx-ng.h | 37 + contrib/gcc/config/i386/lynx.h | 39 + contrib/gcc/config/i386/mach.h | 20 + contrib/gcc/config/i386/netbsd.h | 80 + contrib/gcc/config/i386/next.c | 7 + contrib/gcc/config/i386/next.h | 226 + contrib/gcc/config/i386/os2.h | 76 + contrib/gcc/config/i386/osfelf.h | 79 + contrib/gcc/config/i386/osfrose.h | 923 ++ contrib/gcc/config/i386/perform.h | 98 + contrib/gcc/config/i386/sco.h | 117 + contrib/gcc/config/i386/sco4.h | 86 + contrib/gcc/config/i386/sco4dbx.h | 81 + contrib/gcc/config/i386/scodbx.h | 92 + contrib/gcc/config/i386/seq-gas.h | 46 + contrib/gcc/config/i386/seq-sysv3.h | 56 + contrib/gcc/config/i386/seq2-sysv3.h | 8 + contrib/gcc/config/i386/sequent.h | 152 + contrib/gcc/config/i386/sol2-c1.asm | 156 + contrib/gcc/config/i386/sol2-ci.asm | 51 + contrib/gcc/config/i386/sol2-cn.asm | 46 + contrib/gcc/config/i386/sol2.h | 91 + contrib/gcc/config/i386/sun.h | 83 + contrib/gcc/config/i386/sun386.h | 143 + contrib/gcc/config/i386/svr3.ifile | 45 + contrib/gcc/config/i386/svr3dbx.h | 97 + contrib/gcc/config/i386/svr3gas.h | 305 + contrib/gcc/config/i386/svr3z.ifile | 45 + contrib/gcc/config/i386/sysv3.h | 124 + contrib/gcc/config/i386/sysv4.h | 245 + contrib/gcc/config/i386/sysv4gdb.h | 7 + contrib/gcc/config/i386/t-crtpic | 9 + contrib/gcc/config/i386/t-crtstuff | 2 + contrib/gcc/config/i386/t-i386bare | 3 + contrib/gcc/config/i386/t-iscscodbx | 2 + contrib/gcc/config/i386/t-next | 9 + contrib/gcc/config/i386/t-sol2 | 32 + contrib/gcc/config/i386/t-svr3dbx | 7 + contrib/gcc/config/i386/t-vsta | 2 + contrib/gcc/config/i386/t-winnt | 2 + contrib/gcc/config/i386/unix.h | 148 + contrib/gcc/config/i386/v3gas.h | 80 + contrib/gcc/config/i386/vsta.h | 78 + contrib/gcc/config/i386/win-nt.h | 152 + contrib/gcc/config/i386/winnt.c | 60 + contrib/gcc/config/i386/x-aix | 12 + contrib/gcc/config/i386/x-freebsd | 3 + contrib/gcc/config/i386/x-isc | 3 + contrib/gcc/config/i386/x-isc3 | 4 + contrib/gcc/config/i386/x-ncr3000 | 34 + contrib/gcc/config/i386/x-next | 3 + contrib/gcc/config/i386/x-osfrose | 31 + contrib/gcc/config/i386/x-sco | 7 + contrib/gcc/config/i386/x-sco4 | 10 + contrib/gcc/config/i386/x-sysv3 | 1 + contrib/gcc/config/i386/x-vsta | 1 + contrib/gcc/config/i386/xm-aix.h | 37 + contrib/gcc/config/i386/xm-bsd386.h | 6 + contrib/gcc/config/i386/xm-dos.h | 20 + contrib/gcc/config/i386/xm-freebsd.h | 4 + contrib/gcc/config/i386/xm-gnu.h | 5 + contrib/gcc/config/i386/xm-i386.h | 43 + contrib/gcc/config/i386/xm-isc.h | 6 + contrib/gcc/config/i386/xm-linux.h | 24 + contrib/gcc/config/i386/xm-lynx.h | 33 + contrib/gcc/config/i386/xm-netbsd.h | 4 + contrib/gcc/config/i386/xm-next.h | 5 + contrib/gcc/config/i386/xm-os2.h | 57 + contrib/gcc/config/i386/xm-osf.h | 32 + contrib/gcc/config/i386/xm-sco.h | 22 + contrib/gcc/config/i386/xm-sun.h | 27 + contrib/gcc/config/i386/xm-sysv3.h | 4 + contrib/gcc/config/i386/xm-sysv4.h | 16 + contrib/gcc/config/i386/xm-vsta.h | 26 + contrib/gcc/config/i386/xm-winnt.h | 24 + contrib/gcc/config/linux-aout.h | 51 + contrib/gcc/config/linux.h | 88 + contrib/gcc/config/lynx-ng.h | 118 + contrib/gcc/config/lynx.h | 180 + contrib/gcc/config/netbsd.h | 196 + contrib/gcc/config/nextstep.c | 84 + contrib/gcc/config/nextstep.h | 567 + contrib/gcc/config/nextstep21.h | 65 + contrib/gcc/config/svr3.h | 385 + contrib/gcc/config/svr4.h | 887 ++ contrib/gcc/config/t-libc-ok | 2 + contrib/gcc/config/t-svr4 | 7 + contrib/gcc/config/x-linux | 14 + contrib/gcc/config/x-lynx | 6 + contrib/gcc/config/x-netbsd | 6 + contrib/gcc/config/x-svr4 | 9 + contrib/gcc/config/xm-freebsd.h | 33 + contrib/gcc/config/xm-gnu.h | 31 + contrib/gcc/config/xm-linux.h | 40 + contrib/gcc/config/xm-lynx.h | 51 + contrib/gcc/config/xm-netbsd.h | 27 + contrib/gcc/config/xm-svr3.h | 33 + contrib/gcc/config/xm-svr4.h | 35 + contrib/gcc/configure | 3080 ++++++ contrib/gcc/convert.c | 472 + contrib/gcc/convert.h | 24 + contrib/gcc/cp/ChangeLog | 9459 ++++++++++++++++ contrib/gcc/cp/Make-lang.in | 197 + contrib/gcc/cp/Makefile.in | 265 + contrib/gcc/cp/call.c | 2993 +++++ contrib/gcc/cp/class.c | 5086 +++++++++ contrib/gcc/cp/class.h | 117 + contrib/gcc/cp/config-lang.in | 35 + contrib/gcc/cp/cp-tree.h | 2496 +++++ contrib/gcc/cp/cvt.c | 1820 +++ contrib/gcc/cp/decl.c | 12878 ++++++++++++++++++++++ contrib/gcc/cp/decl.h | 59 + contrib/gcc/cp/decl2.c | 3511 ++++++ contrib/gcc/cp/edsel.c | 928 ++ contrib/gcc/cp/errfn.c | 230 + contrib/gcc/cp/error.c | 1482 +++ contrib/gcc/cp/except.c | 1690 +++ contrib/gcc/cp/expr.c | 372 + contrib/gcc/cp/g++.1 | 674 ++ contrib/gcc/cp/g++.c | 582 + contrib/gcc/cp/gc.c | 1550 +++ contrib/gcc/cp/gpcompare.texi | 236 + contrib/gcc/cp/gxx.gperf | 102 + contrib/gcc/cp/gxxint.texi | 1585 +++ contrib/gcc/cp/init.c | 4180 +++++++ contrib/gcc/cp/input.c | 202 + contrib/gcc/cp/lang-options.h | 107 + contrib/gcc/cp/lang-specs.h | 59 + contrib/gcc/cp/lex.c | 4717 ++++++++ contrib/gcc/cp/lex.h | 135 + contrib/gcc/cp/method.c | 2287 ++++ contrib/gcc/cp/parse.y | 3906 +++++++ contrib/gcc/cp/pt.c | 2694 +++++ contrib/gcc/cp/ptree.c | 168 + contrib/gcc/cp/reno.texi | 752 ++ contrib/gcc/cp/repo.c | 409 + contrib/gcc/cp/search.c | 3524 ++++++ contrib/gcc/cp/sig.c | 1049 ++ contrib/gcc/cp/spew.c | 455 + contrib/gcc/cp/templates.texi | 235 + contrib/gcc/cp/tree.c | 1995 ++++ contrib/gcc/cp/tree.def | 116 + contrib/gcc/cp/typeck.c | 7615 +++++++++++++ contrib/gcc/cp/typeck2.c | 1681 +++ contrib/gcc/cp/xref.c | 840 ++ contrib/gcc/cplus-dem.c | 3001 +++++ contrib/gcc/cpp.1 | 1 + contrib/gcc/cpp.texi | 2856 +++++ contrib/gcc/cppalloc.c | 64 + contrib/gcc/cpperror.c | 128 + contrib/gcc/cppexp.c | 997 ++ contrib/gcc/cpphash.c | 214 + contrib/gcc/cpphash.h | 38 + contrib/gcc/cpplib.c | 7527 +++++++++++++ contrib/gcc/cpplib.h | 651 ++ contrib/gcc/cppmain.c | 100 + contrib/gcc/cross-make | 27 + contrib/gcc/crtstuff.c | 324 + contrib/gcc/cse.c | 8779 +++++++++++++++ contrib/gcc/dbxout.c | 2518 +++++ contrib/gcc/dbxstclass.h | 17 + contrib/gcc/defaults.h | 143 + contrib/gcc/demangle.h | 108 + contrib/gcc/doschk.c | 360 + contrib/gcc/dostage2 | 2 + contrib/gcc/dostage3 | 3 + contrib/gcc/dwarf.h | 311 + contrib/gcc/dwarfout.c | 5651 ++++++++++ contrib/gcc/emit-rtl.c | 3448 ++++++ contrib/gcc/enquire.c | 2837 +++++ contrib/gcc/explow.c | 1218 ++ contrib/gcc/expmed.c | 4223 +++++++ contrib/gcc/expr.c | 10747 ++++++++++++++++++ contrib/gcc/expr.h | 854 ++ contrib/gcc/extend.texi | 3197 ++++++ contrib/gcc/final.c | 3151 ++++++ contrib/gcc/fix-header.c | 1202 ++ contrib/gcc/fixcpp | 109 + contrib/gcc/fixinc-nt.sed | 5 + contrib/gcc/fixinc.dgux | 185 + contrib/gcc/fixinc.ptx | 197 + contrib/gcc/fixinc.sco | 315 + contrib/gcc/fixinc.svr4 | 1653 +++ contrib/gcc/fixinc.winnt | 232 + contrib/gcc/fixincludes | 2528 +++++ contrib/gcc/fixproto | 273 + contrib/gcc/flags.h | 363 + contrib/gcc/floatlib.c | 581 + contrib/gcc/flow.c | 2956 +++++ contrib/gcc/fold-const.c | 5129 +++++++++ contrib/gcc/function.c | 5703 ++++++++++ contrib/gcc/function.h | 232 + contrib/gcc/gbl-ctors.h | 88 + contrib/gcc/gcc.1 | 4119 +++++++ contrib/gcc/gcc.c | 5254 +++++++++ contrib/gcc/gcc.texi | 4722 ++++++++ contrib/gcc/gen-protos.c | 179 + contrib/gcc/genattr.c | 432 + contrib/gcc/genattrtab.c | 5715 ++++++++++ contrib/gcc/gencodes.c | 161 + contrib/gcc/genconfig.c | 356 + contrib/gcc/genemit.c | 800 ++ contrib/gcc/genextract.c | 556 + contrib/gcc/genflags.c | 294 + contrib/gcc/genmultilib | 231 + contrib/gcc/genopinit.c | 385 + contrib/gcc/genoutput.c | 1000 ++ contrib/gcc/genpeep.c | 509 + contrib/gcc/genrecog.c | 1814 +++ contrib/gcc/getopt.c | 765 ++ contrib/gcc/getopt.h | 129 + contrib/gcc/getopt1.c | 180 + contrib/gcc/getpwd.c | 101 + contrib/gcc/ginclude/iso646.h | 15 + contrib/gcc/ginclude/math-3300.h | 461 + contrib/gcc/ginclude/math-68881.h | 529 + contrib/gcc/ginclude/proto.h | 4 + contrib/gcc/ginclude/stdarg.h | 174 + contrib/gcc/ginclude/stddef.h | 311 + contrib/gcc/ginclude/va-alpha.h | 100 + contrib/gcc/ginclude/va-clipper.h | 57 + contrib/gcc/ginclude/va-h8300.h | 53 + contrib/gcc/ginclude/va-i860.h | 211 + contrib/gcc/ginclude/va-i960.h | 76 + contrib/gcc/ginclude/va-m88k.h | 84 + contrib/gcc/ginclude/va-mips.h | 110 + contrib/gcc/ginclude/va-pa.h | 49 + contrib/gcc/ginclude/va-ppc.h | 144 + contrib/gcc/ginclude/va-pyr.h | 130 + contrib/gcc/ginclude/va-sparc.h | 203 + contrib/gcc/ginclude/va-spur.h | 61 + contrib/gcc/ginclude/varargs.h | 190 + contrib/gcc/glimits.h | 93 + contrib/gcc/global.c | 1714 +++ contrib/gcc/gmon.c | 330 + contrib/gcc/gstab.h | 17 + contrib/gcc/gsyms.h | 76 + contrib/gcc/gsyslimits.h | 8 + contrib/gcc/halfpic.c | 400 + contrib/gcc/halfpic.h | 89 + contrib/gcc/hard-reg-set.h | 271 + contrib/gcc/input.h | 47 + contrib/gcc/install.sh | 238 + contrib/gcc/install.texi | 2176 ++++ contrib/gcc/integrate.c | 3112 ++++++ contrib/gcc/integrate.h | 126 + contrib/gcc/invoke.texi | 4492 ++++++++ contrib/gcc/jump.c | 4513 ++++++++ contrib/gcc/just-fixinc | 39 + contrib/gcc/libgcc1-test.c | 100 + contrib/gcc/libgcc1.c | 596 + contrib/gcc/libgcc2.c | 2473 +++++ contrib/gcc/limitx.h | 12 + contrib/gcc/limity.h | 10 + contrib/gcc/listing | 227 + contrib/gcc/local-alloc.c | 2381 ++++ contrib/gcc/longlong.h | 1181 ++ contrib/gcc/loop.c | 6631 +++++++++++ contrib/gcc/loop.h | 176 + contrib/gcc/machmode.def | 119 + contrib/gcc/machmode.h | 171 + contrib/gcc/md.texi | 3993 +++++++ contrib/gcc/mips-tdump.c | 1617 +++ contrib/gcc/mips-tfile.c | 5803 ++++++++++ contrib/gcc/modemap.def | 31 + contrib/gcc/move-if-change | 17 + contrib/gcc/objc-act.c | 8268 ++++++++++++++ contrib/gcc/objc-act.h | 117 + contrib/gcc/objc-tree.def | 37 + contrib/gcc/objc/Makefile | 100 + contrib/gcc/objc/NXConstStr.h | 38 + contrib/gcc/objc/NXConstStr.m | 36 + contrib/gcc/objc/Object.h | 124 + contrib/gcc/objc/Object.m | 389 + contrib/gcc/objc/Protocol.h | 58 + contrib/gcc/objc/Protocol.m | 128 + contrib/gcc/objc/README | 97 + contrib/gcc/objc/archive.c | 1616 +++ contrib/gcc/objc/class.c | 327 + contrib/gcc/objc/encoding.c | 537 + contrib/gcc/objc/encoding.h | 75 + contrib/gcc/objc/hash.c | 253 + contrib/gcc/objc/hash.h | 202 + contrib/gcc/objc/init.c | 363 + contrib/gcc/objc/list.h | 150 + contrib/gcc/objc/makefile.dos | 56 + contrib/gcc/objc/misc.c | 80 + contrib/gcc/objc/objc-api.h | 477 + contrib/gcc/objc/objc.h | 153 + contrib/gcc/objc/objects.c | 92 + contrib/gcc/objc/runtime.h | 74 + contrib/gcc/objc/sarray.c | 441 + contrib/gcc/objc/sarray.h | 232 + contrib/gcc/objc/selector.c | 321 + contrib/gcc/objc/sendmsg.c | 558 + contrib/gcc/objc/typedstream.h | 132 + contrib/gcc/obstack.c | 497 + contrib/gcc/obstack.h | 516 + contrib/gcc/optabs.c | 4320 ++++++++ contrib/gcc/output.h | 428 + contrib/gcc/pcp.h | 101 + contrib/gcc/print-rtl.c | 329 + contrib/gcc/print-tree.c | 738 ++ contrib/gcc/protoize.c | 4732 ++++++++ contrib/gcc/pself.c | 1 + contrib/gcc/pself1.c | 1 + contrib/gcc/pself2.c | 1 + contrib/gcc/pself3.c | 1 + contrib/gcc/real.c | 6122 ++++++++++ contrib/gcc/real.h | 438 + contrib/gcc/recog.c | 1981 ++++ contrib/gcc/recog.h | 121 + contrib/gcc/reg-stack.c | 3134 ++++++ contrib/gcc/regclass.c | 1900 ++++ contrib/gcc/regs.h | 175 + contrib/gcc/reload.c | 5955 ++++++++++ contrib/gcc/reload.h | 237 + contrib/gcc/reload1.c | 7176 ++++++++++++ contrib/gcc/reorg.c | 4397 ++++++++ contrib/gcc/rtl.c | 851 ++ contrib/gcc/rtl.def | 765 ++ contrib/gcc/rtl.h | 968 ++ contrib/gcc/rtl.texi | 2801 +++++ contrib/gcc/rtlanal.c | 1840 ++++ contrib/gcc/scan-decls.c | 252 + contrib/gcc/scan-types.sh | 139 + contrib/gcc/scan.c | 240 + contrib/gcc/scan.h | 75 + contrib/gcc/sched.c | 4968 +++++++++ contrib/gcc/sdbout.c | 1547 +++ contrib/gcc/sort-protos | 9 + contrib/gcc/stab.def | 232 + contrib/gcc/stack.h | 42 + contrib/gcc/stmt.c | 5883 ++++++++++ contrib/gcc/stor-layout.c | 1243 +++ contrib/gcc/stupid.c | 558 + contrib/gcc/sys-protos.h | 1347 +++ contrib/gcc/sys-types.h | 239 + contrib/gcc/tm.texi | 6467 +++++++++++ contrib/gcc/toplev.c | 4036 +++++++ contrib/gcc/tree.c | 4468 ++++++++ contrib/gcc/tree.def | 710 ++ contrib/gcc/tree.h | 1716 +++ contrib/gcc/typeclass.h | 14 + contrib/gcc/unprotoize.c | 1 + contrib/gcc/unroll.c | 3503 ++++++ contrib/gcc/varasm.c | 4064 +++++++ contrib/gcc/version.c | 1 + contrib/gcc/xcoffout.c | 531 + contrib/gcc/xcoffout.h | 180 + 447 files changed, 454870 insertions(+) create mode 100644 contrib/gcc/BUGS create mode 100644 contrib/gcc/COPYING create mode 100644 contrib/gcc/COPYING.LIB create mode 100644 contrib/gcc/ChangeLog create mode 100644 contrib/gcc/Makefile.in create mode 100644 contrib/gcc/NEWS create mode 100644 contrib/gcc/ORDERS create mode 100644 contrib/gcc/PROBLEMS create mode 100644 contrib/gcc/PROJECTS create mode 100644 contrib/gcc/README create mode 100644 contrib/gcc/README-fixinc create mode 100644 contrib/gcc/README.ACORN create mode 100644 contrib/gcc/README.ALTOS create mode 100644 contrib/gcc/README.APOLLO create mode 100644 contrib/gcc/README.DWARF create mode 100644 contrib/gcc/README.FRESCO create mode 100644 contrib/gcc/README.NS32K create mode 100644 contrib/gcc/README.RS6000 create mode 100644 contrib/gcc/README.TRAD create mode 100644 contrib/gcc/README.X11 create mode 100644 contrib/gcc/SERVICE create mode 100644 contrib/gcc/TESTS.FLUNK create mode 100644 contrib/gcc/alloca.c create mode 100644 contrib/gcc/assert.h create mode 100644 contrib/gcc/basic-block.h create mode 100644 contrib/gcc/bc-emit.c create mode 100644 contrib/gcc/bc-emit.h create mode 100644 contrib/gcc/bc-optab.c create mode 100644 contrib/gcc/bc-optab.h create mode 100644 contrib/gcc/bc-typecd.def create mode 100644 contrib/gcc/bc-typecd.h create mode 100644 contrib/gcc/bi-arity.c create mode 100644 contrib/gcc/bi-defs.h create mode 100644 contrib/gcc/bi-lexer.c create mode 100644 contrib/gcc/bi-opcode.c create mode 100644 contrib/gcc/bi-opname.c create mode 100644 contrib/gcc/bi-parser.y create mode 100644 contrib/gcc/bi-reverse.c create mode 100644 contrib/gcc/bi-run.h create mode 100644 contrib/gcc/build-make create mode 100644 contrib/gcc/bytecode.def create mode 100644 contrib/gcc/bytecode.h create mode 100644 contrib/gcc/bytetypes.h create mode 100644 contrib/gcc/c-aux-info.c create mode 100644 contrib/gcc/c-common.c create mode 100644 contrib/gcc/c-convert.c create mode 100644 contrib/gcc/c-decl.c create mode 100644 contrib/gcc/c-iterate.c create mode 100644 contrib/gcc/c-lang.c create mode 100644 contrib/gcc/c-lex.c create mode 100644 contrib/gcc/c-lex.h create mode 100644 contrib/gcc/c-parse.gperf create mode 100644 contrib/gcc/c-parse.in create mode 100644 contrib/gcc/c-pragma.c create mode 100644 contrib/gcc/c-pragma.h create mode 100644 contrib/gcc/c-tree.h create mode 100644 contrib/gcc/c-typeck.c create mode 100644 contrib/gcc/caller-save.c create mode 100644 contrib/gcc/calls.c create mode 100644 contrib/gcc/cccp.1 create mode 100644 contrib/gcc/cccp.c create mode 100644 contrib/gcc/cexp.y create mode 100644 contrib/gcc/collect2.c create mode 100644 contrib/gcc/combine.c create mode 100644 contrib/gcc/conditions.h create mode 100755 contrib/gcc/config.guess create mode 100755 contrib/gcc/config.sub create mode 100644 contrib/gcc/config/README create mode 100644 contrib/gcc/config/aoutos.h create mode 100644 contrib/gcc/config/fp-bit.c create mode 100644 contrib/gcc/config/gnu.h create mode 100644 contrib/gcc/config/gofast.h create mode 100644 contrib/gcc/config/i386/386bsd.h create mode 100644 contrib/gcc/config/i386/aix386.h create mode 100644 contrib/gcc/config/i386/aix386ng.h create mode 100644 contrib/gcc/config/i386/att.h create mode 100644 contrib/gcc/config/i386/bsd.h create mode 100644 contrib/gcc/config/i386/bsd386.h create mode 100644 contrib/gcc/config/i386/config-nt.sed create mode 100644 contrib/gcc/config/i386/freebsd.h create mode 100644 contrib/gcc/config/i386/freebsd.h.fixed create mode 100644 contrib/gcc/config/i386/gas.h create mode 100644 contrib/gcc/config/i386/gnu.h create mode 100644 contrib/gcc/config/i386/go32.h create mode 100644 contrib/gcc/config/i386/gstabs.h create mode 100644 contrib/gcc/config/i386/i386-aout.h create mode 100644 contrib/gcc/config/i386/i386-coff.h create mode 100644 contrib/gcc/config/i386/i386.c create mode 100644 contrib/gcc/config/i386/i386.h create mode 100644 contrib/gcc/config/i386/i386.md create mode 100644 contrib/gcc/config/i386/i386iscgas.h create mode 100644 contrib/gcc/config/i386/isc.h create mode 100644 contrib/gcc/config/i386/isccoff.h create mode 100644 contrib/gcc/config/i386/iscdbx.h create mode 100644 contrib/gcc/config/i386/linux-aout.h create mode 100644 contrib/gcc/config/i386/linux-oldld.h create mode 100644 contrib/gcc/config/i386/linux.h create mode 100644 contrib/gcc/config/i386/lynx-ng.h create mode 100644 contrib/gcc/config/i386/lynx.h create mode 100644 contrib/gcc/config/i386/mach.h create mode 100644 contrib/gcc/config/i386/netbsd.h create mode 100644 contrib/gcc/config/i386/next.c create mode 100644 contrib/gcc/config/i386/next.h create mode 100644 contrib/gcc/config/i386/os2.h create mode 100644 contrib/gcc/config/i386/osfelf.h create mode 100644 contrib/gcc/config/i386/osfrose.h create mode 100644 contrib/gcc/config/i386/perform.h create mode 100644 contrib/gcc/config/i386/sco.h create mode 100644 contrib/gcc/config/i386/sco4.h create mode 100644 contrib/gcc/config/i386/sco4dbx.h create mode 100644 contrib/gcc/config/i386/scodbx.h create mode 100644 contrib/gcc/config/i386/seq-gas.h create mode 100644 contrib/gcc/config/i386/seq-sysv3.h create mode 100644 contrib/gcc/config/i386/seq2-sysv3.h create mode 100644 contrib/gcc/config/i386/sequent.h create mode 100644 contrib/gcc/config/i386/sol2-c1.asm create mode 100644 contrib/gcc/config/i386/sol2-ci.asm create mode 100644 contrib/gcc/config/i386/sol2-cn.asm create mode 100644 contrib/gcc/config/i386/sol2.h create mode 100644 contrib/gcc/config/i386/sun.h create mode 100644 contrib/gcc/config/i386/sun386.h create mode 100644 contrib/gcc/config/i386/svr3.ifile create mode 100644 contrib/gcc/config/i386/svr3dbx.h create mode 100644 contrib/gcc/config/i386/svr3gas.h create mode 100644 contrib/gcc/config/i386/svr3z.ifile create mode 100644 contrib/gcc/config/i386/sysv3.h create mode 100644 contrib/gcc/config/i386/sysv4.h create mode 100644 contrib/gcc/config/i386/sysv4gdb.h create mode 100644 contrib/gcc/config/i386/t-crtpic create mode 100644 contrib/gcc/config/i386/t-crtstuff create mode 100644 contrib/gcc/config/i386/t-i386bare create mode 100644 contrib/gcc/config/i386/t-iscscodbx create mode 100644 contrib/gcc/config/i386/t-next create mode 100644 contrib/gcc/config/i386/t-sol2 create mode 100644 contrib/gcc/config/i386/t-svr3dbx create mode 100644 contrib/gcc/config/i386/t-vsta create mode 100644 contrib/gcc/config/i386/t-winnt create mode 100644 contrib/gcc/config/i386/unix.h create mode 100644 contrib/gcc/config/i386/v3gas.h create mode 100644 contrib/gcc/config/i386/vsta.h create mode 100644 contrib/gcc/config/i386/win-nt.h create mode 100644 contrib/gcc/config/i386/winnt.c create mode 100644 contrib/gcc/config/i386/x-aix create mode 100644 contrib/gcc/config/i386/x-freebsd create mode 100644 contrib/gcc/config/i386/x-isc create mode 100644 contrib/gcc/config/i386/x-isc3 create mode 100644 contrib/gcc/config/i386/x-ncr3000 create mode 100644 contrib/gcc/config/i386/x-next create mode 100644 contrib/gcc/config/i386/x-osfrose create mode 100644 contrib/gcc/config/i386/x-sco create mode 100644 contrib/gcc/config/i386/x-sco4 create mode 100644 contrib/gcc/config/i386/x-sysv3 create mode 100644 contrib/gcc/config/i386/x-vsta create mode 100644 contrib/gcc/config/i386/xm-aix.h create mode 100644 contrib/gcc/config/i386/xm-bsd386.h create mode 100644 contrib/gcc/config/i386/xm-dos.h create mode 100644 contrib/gcc/config/i386/xm-freebsd.h create mode 100644 contrib/gcc/config/i386/xm-gnu.h create mode 100644 contrib/gcc/config/i386/xm-i386.h create mode 100644 contrib/gcc/config/i386/xm-isc.h create mode 100644 contrib/gcc/config/i386/xm-linux.h create mode 100644 contrib/gcc/config/i386/xm-lynx.h create mode 100644 contrib/gcc/config/i386/xm-netbsd.h create mode 100644 contrib/gcc/config/i386/xm-next.h create mode 100644 contrib/gcc/config/i386/xm-os2.h create mode 100644 contrib/gcc/config/i386/xm-osf.h create mode 100644 contrib/gcc/config/i386/xm-sco.h create mode 100644 contrib/gcc/config/i386/xm-sun.h create mode 100644 contrib/gcc/config/i386/xm-sysv3.h create mode 100644 contrib/gcc/config/i386/xm-sysv4.h create mode 100644 contrib/gcc/config/i386/xm-vsta.h create mode 100644 contrib/gcc/config/i386/xm-winnt.h create mode 100644 contrib/gcc/config/linux-aout.h create mode 100644 contrib/gcc/config/linux.h create mode 100644 contrib/gcc/config/lynx-ng.h create mode 100644 contrib/gcc/config/lynx.h create mode 100644 contrib/gcc/config/netbsd.h create mode 100644 contrib/gcc/config/nextstep.c create mode 100644 contrib/gcc/config/nextstep.h create mode 100644 contrib/gcc/config/nextstep21.h create mode 100644 contrib/gcc/config/svr3.h create mode 100644 contrib/gcc/config/svr4.h create mode 100644 contrib/gcc/config/t-libc-ok create mode 100644 contrib/gcc/config/t-svr4 create mode 100644 contrib/gcc/config/x-linux create mode 100644 contrib/gcc/config/x-lynx create mode 100644 contrib/gcc/config/x-netbsd create mode 100644 contrib/gcc/config/x-svr4 create mode 100644 contrib/gcc/config/xm-freebsd.h create mode 100644 contrib/gcc/config/xm-gnu.h create mode 100644 contrib/gcc/config/xm-linux.h create mode 100644 contrib/gcc/config/xm-lynx.h create mode 100644 contrib/gcc/config/xm-netbsd.h create mode 100644 contrib/gcc/config/xm-svr3.h create mode 100644 contrib/gcc/config/xm-svr4.h create mode 100755 contrib/gcc/configure create mode 100644 contrib/gcc/convert.c create mode 100644 contrib/gcc/convert.h create mode 100644 contrib/gcc/cp/ChangeLog create mode 100644 contrib/gcc/cp/Make-lang.in create mode 100644 contrib/gcc/cp/Makefile.in create mode 100644 contrib/gcc/cp/call.c create mode 100644 contrib/gcc/cp/class.c create mode 100644 contrib/gcc/cp/class.h create mode 100644 contrib/gcc/cp/config-lang.in create mode 100644 contrib/gcc/cp/cp-tree.h create mode 100644 contrib/gcc/cp/cvt.c create mode 100644 contrib/gcc/cp/decl.c create mode 100644 contrib/gcc/cp/decl.h create mode 100644 contrib/gcc/cp/decl2.c create mode 100644 contrib/gcc/cp/edsel.c create mode 100644 contrib/gcc/cp/errfn.c create mode 100644 contrib/gcc/cp/error.c create mode 100644 contrib/gcc/cp/except.c create mode 100644 contrib/gcc/cp/expr.c create mode 100644 contrib/gcc/cp/g++.1 create mode 100644 contrib/gcc/cp/g++.c create mode 100644 contrib/gcc/cp/gc.c create mode 100644 contrib/gcc/cp/gpcompare.texi create mode 100644 contrib/gcc/cp/gxx.gperf create mode 100644 contrib/gcc/cp/gxxint.texi create mode 100644 contrib/gcc/cp/init.c create mode 100644 contrib/gcc/cp/input.c create mode 100644 contrib/gcc/cp/lang-options.h create mode 100644 contrib/gcc/cp/lang-specs.h create mode 100644 contrib/gcc/cp/lex.c create mode 100644 contrib/gcc/cp/lex.h create mode 100644 contrib/gcc/cp/method.c create mode 100644 contrib/gcc/cp/parse.y create mode 100644 contrib/gcc/cp/pt.c create mode 100644 contrib/gcc/cp/ptree.c create mode 100644 contrib/gcc/cp/reno.texi create mode 100644 contrib/gcc/cp/repo.c create mode 100644 contrib/gcc/cp/search.c create mode 100644 contrib/gcc/cp/sig.c create mode 100644 contrib/gcc/cp/spew.c create mode 100644 contrib/gcc/cp/templates.texi create mode 100644 contrib/gcc/cp/tree.c create mode 100644 contrib/gcc/cp/tree.def create mode 100644 contrib/gcc/cp/typeck.c create mode 100644 contrib/gcc/cp/typeck2.c create mode 100644 contrib/gcc/cp/xref.c create mode 100644 contrib/gcc/cplus-dem.c create mode 100644 contrib/gcc/cpp.1 create mode 100644 contrib/gcc/cpp.texi create mode 100644 contrib/gcc/cppalloc.c create mode 100644 contrib/gcc/cpperror.c create mode 100644 contrib/gcc/cppexp.c create mode 100644 contrib/gcc/cpphash.c create mode 100644 contrib/gcc/cpphash.h create mode 100644 contrib/gcc/cpplib.c create mode 100644 contrib/gcc/cpplib.h create mode 100644 contrib/gcc/cppmain.c create mode 100644 contrib/gcc/cross-make create mode 100644 contrib/gcc/crtstuff.c create mode 100644 contrib/gcc/cse.c create mode 100644 contrib/gcc/dbxout.c create mode 100644 contrib/gcc/dbxstclass.h create mode 100644 contrib/gcc/defaults.h create mode 100644 contrib/gcc/demangle.h create mode 100644 contrib/gcc/doschk.c create mode 100755 contrib/gcc/dostage2 create mode 100755 contrib/gcc/dostage3 create mode 100644 contrib/gcc/dwarf.h create mode 100644 contrib/gcc/dwarfout.c create mode 100644 contrib/gcc/emit-rtl.c create mode 100644 contrib/gcc/enquire.c create mode 100644 contrib/gcc/explow.c create mode 100644 contrib/gcc/expmed.c create mode 100644 contrib/gcc/expr.c create mode 100644 contrib/gcc/expr.h create mode 100644 contrib/gcc/extend.texi create mode 100644 contrib/gcc/final.c create mode 100644 contrib/gcc/fix-header.c create mode 100755 contrib/gcc/fixcpp create mode 100644 contrib/gcc/fixinc-nt.sed create mode 100755 contrib/gcc/fixinc.dgux create mode 100644 contrib/gcc/fixinc.ptx create mode 100755 contrib/gcc/fixinc.sco create mode 100755 contrib/gcc/fixinc.svr4 create mode 100644 contrib/gcc/fixinc.winnt create mode 100755 contrib/gcc/fixincludes create mode 100755 contrib/gcc/fixproto create mode 100644 contrib/gcc/flags.h create mode 100644 contrib/gcc/floatlib.c create mode 100644 contrib/gcc/flow.c create mode 100644 contrib/gcc/fold-const.c create mode 100644 contrib/gcc/function.c create mode 100644 contrib/gcc/function.h create mode 100644 contrib/gcc/gbl-ctors.h create mode 100644 contrib/gcc/gcc.1 create mode 100644 contrib/gcc/gcc.c create mode 100644 contrib/gcc/gcc.texi create mode 100644 contrib/gcc/gen-protos.c create mode 100644 contrib/gcc/genattr.c create mode 100644 contrib/gcc/genattrtab.c create mode 100644 contrib/gcc/gencodes.c create mode 100644 contrib/gcc/genconfig.c create mode 100644 contrib/gcc/genemit.c create mode 100644 contrib/gcc/genextract.c create mode 100644 contrib/gcc/genflags.c create mode 100644 contrib/gcc/genmultilib create mode 100644 contrib/gcc/genopinit.c create mode 100644 contrib/gcc/genoutput.c create mode 100644 contrib/gcc/genpeep.c create mode 100644 contrib/gcc/genrecog.c create mode 100644 contrib/gcc/getopt.c create mode 100644 contrib/gcc/getopt.h create mode 100644 contrib/gcc/getopt1.c create mode 100644 contrib/gcc/getpwd.c create mode 100644 contrib/gcc/ginclude/iso646.h create mode 100644 contrib/gcc/ginclude/math-3300.h create mode 100644 contrib/gcc/ginclude/math-68881.h create mode 100644 contrib/gcc/ginclude/proto.h create mode 100644 contrib/gcc/ginclude/stdarg.h create mode 100644 contrib/gcc/ginclude/stddef.h create mode 100644 contrib/gcc/ginclude/va-alpha.h create mode 100644 contrib/gcc/ginclude/va-clipper.h create mode 100644 contrib/gcc/ginclude/va-h8300.h create mode 100644 contrib/gcc/ginclude/va-i860.h create mode 100644 contrib/gcc/ginclude/va-i960.h create mode 100644 contrib/gcc/ginclude/va-m88k.h create mode 100644 contrib/gcc/ginclude/va-mips.h create mode 100644 contrib/gcc/ginclude/va-pa.h create mode 100644 contrib/gcc/ginclude/va-ppc.h create mode 100644 contrib/gcc/ginclude/va-pyr.h create mode 100644 contrib/gcc/ginclude/va-sparc.h create mode 100644 contrib/gcc/ginclude/va-spur.h create mode 100644 contrib/gcc/ginclude/varargs.h create mode 100644 contrib/gcc/glimits.h create mode 100644 contrib/gcc/global.c create mode 100644 contrib/gcc/gmon.c create mode 100644 contrib/gcc/gstab.h create mode 100644 contrib/gcc/gsyms.h create mode 100644 contrib/gcc/gsyslimits.h create mode 100644 contrib/gcc/halfpic.c create mode 100644 contrib/gcc/halfpic.h create mode 100644 contrib/gcc/hard-reg-set.h create mode 100644 contrib/gcc/input.h create mode 100755 contrib/gcc/install.sh create mode 100644 contrib/gcc/install.texi create mode 100644 contrib/gcc/integrate.c create mode 100644 contrib/gcc/integrate.h create mode 100644 contrib/gcc/invoke.texi create mode 100644 contrib/gcc/jump.c create mode 100755 contrib/gcc/just-fixinc create mode 100644 contrib/gcc/libgcc1-test.c create mode 100644 contrib/gcc/libgcc1.c create mode 100644 contrib/gcc/libgcc2.c create mode 100644 contrib/gcc/limitx.h create mode 100644 contrib/gcc/limity.h create mode 100755 contrib/gcc/listing create mode 100644 contrib/gcc/local-alloc.c create mode 100644 contrib/gcc/longlong.h create mode 100644 contrib/gcc/loop.c create mode 100644 contrib/gcc/loop.h create mode 100644 contrib/gcc/machmode.def create mode 100644 contrib/gcc/machmode.h create mode 100644 contrib/gcc/md.texi create mode 100644 contrib/gcc/mips-tdump.c create mode 100644 contrib/gcc/mips-tfile.c create mode 100644 contrib/gcc/modemap.def create mode 100755 contrib/gcc/move-if-change create mode 100644 contrib/gcc/objc-act.c create mode 100644 contrib/gcc/objc-act.h create mode 100644 contrib/gcc/objc-tree.def create mode 100644 contrib/gcc/objc/Makefile create mode 100644 contrib/gcc/objc/NXConstStr.h create mode 100644 contrib/gcc/objc/NXConstStr.m create mode 100644 contrib/gcc/objc/Object.h create mode 100644 contrib/gcc/objc/Object.m create mode 100644 contrib/gcc/objc/Protocol.h create mode 100644 contrib/gcc/objc/Protocol.m create mode 100644 contrib/gcc/objc/README create mode 100644 contrib/gcc/objc/archive.c create mode 100644 contrib/gcc/objc/class.c create mode 100644 contrib/gcc/objc/encoding.c create mode 100644 contrib/gcc/objc/encoding.h create mode 100644 contrib/gcc/objc/hash.c create mode 100644 contrib/gcc/objc/hash.h create mode 100644 contrib/gcc/objc/init.c create mode 100644 contrib/gcc/objc/list.h create mode 100644 contrib/gcc/objc/makefile.dos create mode 100644 contrib/gcc/objc/misc.c create mode 100644 contrib/gcc/objc/objc-api.h create mode 100644 contrib/gcc/objc/objc.h create mode 100644 contrib/gcc/objc/objects.c create mode 100644 contrib/gcc/objc/runtime.h create mode 100644 contrib/gcc/objc/sarray.c create mode 100644 contrib/gcc/objc/sarray.h create mode 100644 contrib/gcc/objc/selector.c create mode 100644 contrib/gcc/objc/sendmsg.c create mode 100644 contrib/gcc/objc/typedstream.h create mode 100644 contrib/gcc/obstack.c create mode 100644 contrib/gcc/obstack.h create mode 100644 contrib/gcc/optabs.c create mode 100644 contrib/gcc/output.h create mode 100644 contrib/gcc/pcp.h create mode 100644 contrib/gcc/print-rtl.c create mode 100644 contrib/gcc/print-tree.c create mode 100644 contrib/gcc/protoize.c create mode 100644 contrib/gcc/pself.c create mode 100644 contrib/gcc/pself1.c create mode 100644 contrib/gcc/pself2.c create mode 100644 contrib/gcc/pself3.c create mode 100644 contrib/gcc/real.c create mode 100644 contrib/gcc/real.h create mode 100644 contrib/gcc/recog.c create mode 100644 contrib/gcc/recog.h create mode 100644 contrib/gcc/reg-stack.c create mode 100644 contrib/gcc/regclass.c create mode 100644 contrib/gcc/regs.h create mode 100644 contrib/gcc/reload.c create mode 100644 contrib/gcc/reload.h create mode 100644 contrib/gcc/reload1.c create mode 100644 contrib/gcc/reorg.c create mode 100644 contrib/gcc/rtl.c create mode 100644 contrib/gcc/rtl.def create mode 100644 contrib/gcc/rtl.h create mode 100644 contrib/gcc/rtl.texi create mode 100644 contrib/gcc/rtlanal.c create mode 100644 contrib/gcc/scan-decls.c create mode 100755 contrib/gcc/scan-types.sh create mode 100644 contrib/gcc/scan.c create mode 100644 contrib/gcc/scan.h create mode 100644 contrib/gcc/sched.c create mode 100644 contrib/gcc/sdbout.c create mode 100755 contrib/gcc/sort-protos create mode 100644 contrib/gcc/stab.def create mode 100644 contrib/gcc/stack.h create mode 100644 contrib/gcc/stmt.c create mode 100644 contrib/gcc/stor-layout.c create mode 100644 contrib/gcc/stupid.c create mode 100644 contrib/gcc/sys-protos.h create mode 100644 contrib/gcc/sys-types.h create mode 100644 contrib/gcc/tm.texi create mode 100644 contrib/gcc/toplev.c create mode 100644 contrib/gcc/tree.c create mode 100644 contrib/gcc/tree.def create mode 100644 contrib/gcc/tree.h create mode 100644 contrib/gcc/typeclass.h create mode 100644 contrib/gcc/unprotoize.c create mode 100644 contrib/gcc/unroll.c create mode 100644 contrib/gcc/varasm.c create mode 100644 contrib/gcc/version.c create mode 100644 contrib/gcc/xcoffout.c create mode 100644 contrib/gcc/xcoffout.h diff --git a/contrib/gcc/BUGS b/contrib/gcc/BUGS new file mode 100644 index 00000000000..dc023cffc51 --- /dev/null +++ b/contrib/gcc/BUGS @@ -0,0 +1,23 @@ +If you think you may have found a bug in GNU CC, please +read the Bugs section of the Emacs manual for advice on + +(1) how to tell when to report a bug, +(2) where to send your bug report, and +(2) how to write a useful bug report and what information +it needs to have. + +There are three ways to read the Bugs section. + +(1) In a printed copy of the GCC manual. You can order one from the +Free Software Foundation; see the file ORDERS. But if you don't have +a copy on hand and you think you have found a bug, you shouldn't wait +to get a printed manual; you should read the section right away as +described below. + +(2) With Info. Start Emacs, do C-h i to enter Info, +then m gcc RET to get to the GCC manual, then m Bugs RET +to get to the section on bugs. Or use standalone Info in +a like manner. (Standalone Info is part of the Texinfo distribution.) + +(3) By hand. Search for the chapter "Reporting Bugs" in gcc.texi, or + cat /usr/local/info/gcc* | more "+/^File: emacs, Node: Bugs," diff --git a/contrib/gcc/COPYING b/contrib/gcc/COPYING new file mode 100644 index 00000000000..916d1f0f284 --- /dev/null +++ b/contrib/gcc/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/contrib/gcc/COPYING.LIB b/contrib/gcc/COPYING.LIB new file mode 100644 index 00000000000..161a3d1d47b --- /dev/null +++ b/contrib/gcc/COPYING.LIB @@ -0,0 +1,482 @@ + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/contrib/gcc/ChangeLog b/contrib/gcc/ChangeLog new file mode 100644 index 00000000000..21a129dc72b --- /dev/null +++ b/contrib/gcc/ChangeLog @@ -0,0 +1,5684 @@ +Sun Nov 26 14:47:42 1995 Richard Kenner + + * Version 2.7.2 released. + + * function.c (fixup_var_refs_1): Make pseudo for DEST + in PROMOTED_MODE unless in a SUBREG. + + * cse.c (insert): Don't put a REG into qty_const. + + * msdos/top.sed: Change version to 2.7.2. + * winnt/config-nt.sed: Likewise. + +Sun Nov 26 14:41:49 1995 Douglas Rupp (drupp@cs.washington.edu) + + * Makefile.in (stamp-objlist): Change .o to $objext. + + * alpha/win-nt.h (CPP_PREDEFINES): Set __unaligned and __stdcall + to null. + (ASM_SPEC): Add a translation for -g to -Zi. + * winnt/ld.c (main): Don't pass -g to link. + * winnt/oldnames.c: Reformat and add some new functions for gnat1. + * winnt/win-nt.h (LINK_SPEC): Pass -g to ld.exe. + Increase default stack size. + * configure ({alpha-dec,i386-ibm}-winnt3.5): Add oldnames.o + to extra_objs. + * libgcc2.c (trampoline): Add getpagesize and mprotect for WINNT. + +Sun Nov 26 14:25:26 1995 Uwe Seimet (seimet@chemie.uni-kl.de) + + * atari.h (FUNCTION_VALUE): Deleted; incorrect. + +Sun Nov 26 14:23:03 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * fixincludes (curses.h): Allow space or tab after bool keyword, + instead of tab or tab. + +Sun Nov 26 14:14:11 1995 Oliver Kellogg (oliver.kellogg@space.otn.dasa.de) + + * 1750a.md (pattern for HImode PSHM): Corrected. + (trunchiqi2, zero_extendqihi2, extendhftqf2): Corrected. + (pattern for movhi of CONST_INT to REG): Corrected. + (divmodqi pattern for DISN): Corrected. + (all shift patterns): Corrected. + + * 1750a.h (REG_OK_FOR_INDEX_P, REG_OK_FOR_BASE_P): Corrected. + (ASM_OUTPUT_[datatype]): Corrected datalbl[].size computation + for output of arrays. + +Sun Nov 26 14:08:57 1995 Dave Love + + * mips/iris5.h (NO_IMPLICIT_EXTERN_C): Define this again so + that unistd.h doesn't get badly `fixed' for C++. libg++ will now + build with this definition. + +Sun Nov 26 14:02:43 1995 Robert E. Brown (brown@grettir.bibliotech.com) + + * configure: Better workaround for Nextstep bug. + +Sun Nov 26 13:55:07 1995 Torbjorn Granlund + + * rs6000.md (load_multiple matcher): Fix typo in opcode. + +Sun Nov 26 13:51:08 1995 Lee Iverson + + * final.c (final_start_function): Move call to sdbout_begin_function + back to final_scan_insn on MIPS systems so parameter descriptions are + recognized. + +Sun Nov 26 13:43:06 1995 DJ Delorie (dj@delorie.co)m + + * msdos/top.sed: Don't insert "go32". + +Sun Nov 26 12:08:23 1995 Jim Wilson + + * combine.c (nonzero_bits, case REG): Put POINTERS_EXTEND_UNSIGNED + code before stack pointer code. Return nonzero at end of stack + pointer code. + + * sparc.h (PRINT_OPERAND_ADDRESS): Handle CONST inside PLUS. + + * Makefile.in (cppalloc.o): Add a rule to build it. + + * alpha.c (alpha_emit_set_const): Don't output SImode sequences + that rely on invisible overflow. Sign extend new when SImode. + Don't recur if new == c. Don't allow shift outside mode. Make + logical right shift be unsigned. + +Sun Nov 26 11:37:50 1995 Arne H. Juul (arnej@idt.unit.no) + + * Makefile.in (compare*): Add "|| true" to avoid spurious + failure messages from some versions of make. + +Sun Nov 26 11:20:09 1995 Dmitry K. Butskoy (buc@stu.spb.su) + + * expr.c (truthvalue_conversion): Add declaration. + +Sun Nov 12 18:09:35 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Version 2.7.1 released. + + * function.c (put_reg_into_stack): New arg volatile_p. + (put_var_into_stack): Call with new arg. + +Sat Nov 11 08:25:34 1995 Jim Wilson + + * reload.c (output.h): Include it. + * Makefile.in (reload.o): Add dependence on output.h. + +Thu Nov 9 11:24:20 1995 Jim Wilson + + * mips.h (HARD_REGNO_NREGS): If FP_REG_P, always use UNITS_PER_FPREG + to calculate number of words needed. + +Thu Nov 9 11:04:50 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * 1750a.md (cmphf): Addd Base Reg with Offset address mode (LB,STB,..) + (movqi,movhi,movhf,addqi3,addhf3,subqi3,subhf3,mulqihi3): Likewise. + (mulhf3,divhf3,andqi3,iorqi3): Likewise. + (define_peephole): Remove the Base mode peepholes. Replace the + special addqi define_insn for "LIM Ra,sym,Rb" by a define_peephole. + (ashlqi3): Took out futile 0th alternative. + (lshrqi3, lshrhi3, ashrqi3, ahsrhi3): Correct case of non-constant + shift count. + + * 1750a.h (REG_ALLOC_ORDER): Define. + (REGNO_OK_FOR_BASE_P): Include stack pointer in test against + reg_renumber[REGNO]. + (ASM_OUTPUT_DESTRUCTOR): Remove bogus assembler comment. + +Thu Nov 9 11:01:33 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (expand_expr, case ARRAY_REF): Properly convert types + of index, size, and multiplication. + +Wed Nov 8 09:00:22 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * arm.md (mov*cc_{,soft_}insn): Use match_operator to test the + comparison and check that the condition code register is used. + +Wed Nov 8 08:49:35 1995 Michael Meissner + + * rs6000/sysv4.h (ASM_OUTPUT_{CONSTRUCTOR,DESTRUCTOR}): Undef before + including svr4.h. + +Tue Nov 7 10:58:12 1995 Torbjorn Granlund + + * m68k.md (subxf3): Properly name pattern. + +Tue Nov 7 10:53:09 1995 Michael Meissner + + * libgcc2.c (__{C,D}TOR_LIST): For AIX, initialize these arrays to + 0,0, just like NeXT to avoid a warning message from the AIX 4.1 + linker. + +Tue Nov 7 09:58:34 1995 John F. Carr + + * cppexp.c (cpp_lex): Correctly parse character constants. + +Tue Nov 7 09:52:15 1995 Jason Merrill + + * rs6000.h (ASM_OUTPUT_{DES,CONS}TRUCTOR): Define. + +Mon Nov 6 10:27:15 1995 Doug Evans + + * combine.c (force_to_mode): Fix typo. + +Sun Nov 5 18:37:02 1995 Torbjorn Granlund + + * m68k.md (cmpxf): Don't call force_const_mem, it looses for PIC; + get predicates right instead. Get rid of separate DEFINE_EXPAND. + (addxf3, subxf3, mulxf3, divxf3): Likewise. + (All XFmode patterns): Delete `F' and `G' constraints. + (absxf2, negxf2): Delete spurious condition on TARGET_FPA. + +Sun Nov 5 11:05:44 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * fixincludes (malloc.h): Fix return type of {m,re}alloc. + +Sun Nov 5 11:02:26 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * cse.c (invalidate): For a pseudo register, do a loop to + invalidate all table entries, irrespective of mode. + +Sun Nov 5 10:57:43 1995 Richard Kenner + + * combine.c (force_to_mode): Put in last change properly. + +Sun Nov 5 10:53:49 1995 Jeffrey A Law (law@cygnus.com) + + * pa.h (CONDITIONAL_REGISTER_USAGE): Make sure FP regs + get disabled regardless of PA1.0 vs PA1.1 code generation + when TARGET_SOFT_FLOAT or TARGET_DISABLE_FPREGS is on. + +Sun Nov 5 10:49:43 1995 Doug Evans + + * i960.c (emit_move_sequence): Add a scratch register to + multi-reg stores. + (i960_output_move_{double,quad}): New functions. + (i960_print_operand): Handle new operand types E, F. + * i960.md (movdi matchers): Rewrite. + (store_unaligned_di_reg): New pattern. + (movti matchers): Rewrite. + (store_unaligned_ti_reg): New pattern. + +Sun Nov 5 10:45:24 1995 Ian Lance Taylor (ian@cygnus.com) + + * mips.h (MULTILIB_DEFAULTS): Define. + * mips/elf64.h, mips/iris6.h (MULTILIB_DEFAULTS): Define. + +Sun Nov 5 10:41:48 1995 Jim Wilson + + * reload.c (push_reload): Delete abort for RELOAD_OTHER case added + in last change. + * reload1.c (emit_reload_insns): For RELOAD_OTHER output reloads, + output the reload insns in descending order of reloads. + + * sh.md (mulsidi3-1, mulsidi3, umulsidi3-1, umulsidi3): Enable. + (smulsi3_highpart-1, smulsi3_highpart): New patterns. + (umulsi3_highpart-1, umulsi3_highpart): Likewise. + (movdi-1): Add r/x constraint. + * t-sh (MULTILIB_OPTIONS): Add m2. + (MULTILIB_DIRNAMES): Add m2. + (MULTILIB_MATCHES): Define. + + * sparc.h (RTX_COSTS, case MULT): Check for TARGET_SPARCLITE. + + * abi64.h, elf64.h (CPP_SPEC): Add -EB and -EL support. + +Sat Nov 4 10:36:26 1995 Jim Wilson + + * sh.md (casesi_worker): Change constraint from = to +. + + * svr4.h (ASM_IDENTIFY_GCC_AFTER_SOURCE): Delete. + (ASM_IDENTIFY_GCC): Output stab here. + +Sat Nov 4 10:32:37 1995 John Carr + + * cpplib.c (finclude): Set current input pointer when input + is not a regular file. + + * cppmain.c: Define progname, required by cpplib. + +Sun Oct 29 07:48:36 1995 Michael Meissner + + * xcoffout.h (DBX_FINISH_SYMBOL): Deal with names created via + the __asm__ construct that start with a leading '*'. + * xcoffout.c (xcoff_declare_function): Likewise. + +Sun Oct 29 07:45:41 1995 Jim Wilson + + * stupid.c (stupid_mark_refs): Handle SUBREG of pseudo-reg in a + SET_DEST same as we handle a pseudo-reg in a SET_DEST. + +Sun Oct 29 07:43:15 1995 Pat Rankin + + * libgcc2.c (L_eh: __unwind_function): Implement for VAX. + * vax.h (RETURN_ADDRESS_OFFSET, RETURN_ADDR_RTX): Define. + +Sun Oct 29 12:39:08 1995 Richard Kenner a + + * i386/sol2.h (CPP_PREDEFINES): Add -D__SVR4. + +Sun Oct 29 07:14:36 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * reload.c (find_equiv_reg): Check for nonsaving setjmp. + +Fri Oct 27 15:15:56 1995 Jim Wilson + + * Makefile.in (out_object_file): Depend on TREE_H. + +Fri Oct 27 06:42:36 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.c (call_operand): Only allow reg 27 on NT too. + * alpha.md (call_value_nt, call_nt): Force non-SYMBOL_REF + into reg 27, just like for OSF. + + * rs6000.c (struct asm_option): Changed from struct option. + (expand_block_move_mem): Remove erroneously-added line. + + * expr.c (clear_storage): SIZE is now rtx, not int. + (store_constructor): Call clear_storage with rtx. + (get_inner_reference): Convert index to precision of + sizetype, not POINTER_SIZE. + (expand_expr, case ARRAY_REF): Likewise. + * expr.h (clear_storage): Second arg is rtx, not int. + +Fri Oct 27 05:45:58 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * combine.c (force_to_mode, case ASHIFTRT): Properly handle + mask wider than HOST_WIDE_INT. + + * c-decl.c (pushdecl): Don't test TREE_PUBLIC when deciding whether + to register a duplicate decl in the current block. + +Thu Oct 26 21:55:39 1995 Jason Merrill + + * calls.c (expand_call): Don't trust the callee to copy a + TREE_ADDRESSABLE type. + * function.c (assign_parms): Likewise. + +Thu Oct 26 19:25:05 1995 Mike Stump + + * libgcc2.c (__unwind_function): Provide a default definition for + implementations that don't yet have a function unwinder. + +Thu Oct 26 18:08:19 1995 Paul Eggert + + * cccp.c (handle_directive): Don't treat newline as white + space when coalescing white space around a backslash-newline. + +Thu Oct 26 17:57:34 1995 Ian Lance Taylor + + * mips-tdump.c (enum st): Define st_Struct, st_Union, and st_Enum. + (st_to_string): Handle them. + (type_to_string): Add fdp argument; pass it to emit_aggregate. + (print_symbol): Add fdp argument; pass it to type_to_string. + Handle st_Struct, st_Union, and st_Enum. + (emit_aggregate): Add fdp argument. Handle opaque types. Map + through RFD entries. + (print_file_desc): Pass FDR to print_symbol. + (main): Pass null FDR to type_to_string. + +Thu Oct 26 08:07:10 1995 Michael Meissner + + * configure (powerpc-ibm-aix[456789]*): Use rs6000/t-newas, + not rs6000/t-rs6000. + (rs6000-ibm-aix3.2.[456789]*): Likewise. + (rs6000-ibm-aix[456789]*): Likewise. + + * rs6000/t-newas: Copy from t-rs6000. + * t-rs6000: Don't build -mcpu=common multilib variants of libgcc.a. + + * rs6000.md (load_multiple insn): If address register is among regs, + don't load it with a lwsi instruction, which is undefined on PowerPC. + +Thu Oct 26 08:01:32 1995 Jim Wilson + + * dwarfout.c (output_compile_unit_die): Handle language_string + of "GNU F77". + + * reload.c (find_reloads_address): When check for out of range constant + plus register, accept any hard register instead of just fp, ap, sp. + + * combine.c (distribute_notes): For Oct 19 change, add additional + check to verify that place has a valid INSN_CUID. + + * sparc/t-vxsparc (LIBGCC1_TEST): Define. + + * sh.md (negdi2): Use TARGET_LITTLE_ENDIAN. + + * combine.c (force_to_mode, case ASHIFTRT): Verify mode bitsize is + within HOST_BITS_PER_WIDE_INT before shifting by it. + + * final.c (final_scan_insn): When recur for instruction in delay slot, + add loop around recursive call in case the instruction gets split. + +Thu Oct 26 07:28:45 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * genrecog.c (write_tree_1): Avoid emitting '-2147483648'. + + * jump.c (duplicate_loop_exit_test): Return 0 if found + a NOTE_INSN_LOOP_CONT. + +Tue Oct 24 15:30:14 1995 Jeffrey A Law + + * calls.c (expand_call): Make sure valreg is at least + a full word. + +Sun Oct 22 19:35:41 1995 Jim Wilson + + * sh.h (INIT_SECTION_ASM_OP): Delete. + (HAVE_ATEXIT): Define. + +Sun Oct 22 07:46:04 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * libgcc2.c (__fixuns[xds]fsi): #undef MIN and MAX before #include + of limits.h. + + * pa.c (pa_adjust_cost): Use pa_cpu, not pa_cpu_attr. + +Sun Oct 22 07:38:58 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * alpha.h (CONST_OK_FOR_LETTER_P): Use 'U' for unsigned constants. + * alpha.c (alpha_emit_set_const): Likewise. + * mips.c (gen_int_relational): Likewise. + +Sun Oct 22 07:14:35 1995 Douglas Rupp (drupp@cs.washington.edu) + + * i386.c (i386_return_pops_args): Don't need a FUNDECL to + check for type attributes in FUNTYPE. + +Sat Oct 21 18:17:42 1995 Jim Wilson + + * sh.md (define_delay): Don't accept any instruction for an annulled + slot, only accept those for which in_delay_slot is yes. + * sh.c (find_barrier): When hi_const returns true, increment count_si + by two if found_si is true. + Always use get_attr_length to compute length of instructions. + If count_hi or count_si out of range at end, need two PREV_INSN calls + not one. + When create new label, set LABEL_NUSES to 1. + (reg_unused_after): Ifdef out code for handling labels. + (prepare_scc_operands): New local variable mode. Set it from + sh_compare_op0 or sh_compare_op1. Use it instead of SImode in + force_reg calls. + + * optabs.c (expand_float): Emit missing barrier after unconditional + jump. + +Sat Oct 21 14:16:46 1995 Torbjorn Granlund + + * alpha.md (cmpdf): Make conditional on TARGET_FP. + +Fri Oct 20 19:11:12 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * combine.c (distribute_notes): Delete instructions without + side effect that set a subreg of an unused register. + + * m68k.h (PREFERRED_RELOAD_CLASS): Check for !G constants + for DATA_OR_FP_REGS also. + +Fri Oct 20 18:57:10 1995 Ian Lance Taylor + + * genmultilib: Output negations of unused alternatives, even if + one of the alternatives is selected. + +Fri Oct 20 18:48:50 1995 Jeff Law (law@hurl.cygnus.com) + + * integrate.c (output_inline_function): Turn on flag_no_inline + to avoid function integration once we begin writing deferred + output functions. + +Fri Oct 20 18:46:33 1995 Michael Meissner + + * rs6000.c (float_conv_temp): Delete global variable. + (stack_temps): New static array to hold stack temps. + (offsettable_mem_operand): Delete function. + (offsettable_addr_operand, rs6000_stack_temp): New functions. + (output_epilog): Zero stack_temps. + + * rs6000.h (offsettable_addr_operand): Declare instead of + offsettable_mem_operand. + (PREDICATE_CODES): Use offsettable_addr_operand. + (float_conv_temp): Delete variable. + + * rs6000.md (move_to_float insns): Change move_to_float so + that it doesn't have a clobber of the memory address, and instead + passes the stack temp's memory address as one of the unspec args. + (fix_truncdfsi2): Use rs6000_stack_temp to allocate the temp. + (multiply, shift insns): Fix all cases of multiply and shift insns so + that the right mnemonics are used for -mcpu=common with both + -m{old,new}-mnemonics. + +Fri Oct 20 17:58:19 1995 Jim Wilson + + * expr.c (safe_from_p, case RTL_EXPR): Return 0 if RTL_EXPR_SEQUENCE + exists. Delete code to return 0 if exp_rtl is zero. + + * function.c (init_function_start): Don't call init_insn_lengths here. + * toplev.c (rest_of_compilation): Call it here. + +Thu Oct 19 19:19:06 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-common.c (check_format_info): Make test for null pointer + more general. + +Thu Oct 19 18:56:16 1995 Satoshi Adachi (adachi@wisdom.aa.ap.titech.ac.jp) + + * fixincludes (stdlib.h): Be more general in edit to change + declaration of {c,m,re}alloc. + +Thu Oct 19 18:48:53 1995 Torbjorn Granlund + + * libgcc2.c (__udiv_w_sdiv): If we don't have sdiv_qrnnd, define + dummy variant of __udiv_w_sdiv. + +Thu Oct 19 18:45:21 1995 Jim Wilson + + * alpha.h (ASM_SPEC): If GNU as is the default, then pass -g to + the assembler if -malpha-as. If GNU as is not the default, then pass + -g to the assembler is not -mgas. + + * combine.c (distribute_notes): When search for new place to put + REG_DEAD note, call distribute_links if this new place is between + i2 and i3, and i2 uses the register. + +Thu Oct 19 18:41:36 1995 Michael Meissner + + * rs6000.md (float{,uns}sidf2): Rewrite to break the conversion + process into several general insns. + (move_to_float): New insns to move 2 integer regs into a float register + through memory, taking endianess into account. Make sure that the + floating temporary is a valid address. Use one temporary for all + floats converted. + (fix_truncdfsi2): Take endianess into account. + + * rs6000.c ({low_32_bit,offsettable_mem}_operand): The function + low_32_bit_operand is now unused, delete it. New function + offsettable_mem_operand to determine if a memory address is + offsettable. + * rs6000.h ({low_32_bit,offsettable_mem}_operand): Ditto. + (PREDICATE_CODES): Ditto. + + * rs6000.{c,h} (float_conv_temp): New global. + * rs6000.c (output_epilog): Zero out float_conv_temp. + + * Makefile.in (libgcc{1,2}.a): Allow LIB{1,2}FUNCS_EXTRA files to + end in .S as well as .c and .asm. + +Wed Oct 18 17:56:45 1995 Jose Alonso (sidinf@fpsp.fapesp.br) + + * c-typeck.c (parser_build_binary_op): Warn about x^y==z, etc. + +Mon Oct 9 12:38:06 1995 Michael Meissner + + * protoize.c (reverse_def_dec_list): Silence compiler warnings. + +Mon Oct 9 12:35:54 1995 Andrew Cagney + + * ginclude/va-ppc.h (va_arg): Deal with long longs that would be + passed in the 7th register, and are passed in the stack instead. + +Fri Oct 6 13:47:10 1995 Jim Wilson + + * alpha.h (ASM_SPEC): Add -g. + +Fri Oct 6 13:42:50 1995 Richard Kenner + + * alpha.h (alpha_{arg,auto}_offset): Make extern. + +Fri Oct 6 13:24:43 1995 Michael Meissner + + * rs6000.h (RETURN_ADDRESS_OFFSET): Correct previous change. + +Fri Oct 6 13:14:43 1995 Doug Evans + + * rtlanal.c (reg_set_last): Fix call to reg_set_between_p. + +Tue Oct 3 12:31:38 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * stor-layout.c (layout_type, case ARRAY_TYPE): Strip MAX_EXPR + from upper bound when computing length if it just protects against + negative length. + + * expr.c (emit_move_insn_1): When doing multi-word move, show + output is clobbered. + +Tue Oct 3 12:26:07 1995 Jim Wilson + + * cse.c (set_nonvarying_address_components, case AND): Add *pend to + end. Add constant to start instead of subtracting it. + +Tue Oct 3 12:23:28 1995 Torbjorn Granlund + + * combine.c (simplify_rtx): In code that attempts to simplify + conditional expressions, if the result is an NE around another + comparison, return the original expression. + + * longlong.h (mips umul_ppmm): Use `l' and `h' constraints; + remove mflo and mfhi instructions. + +Tue Oct 3 12:21:29 1995 Michael Meissner + + * ginclude/va-ppc.h (va_start, stdarg case): Call + __builtin_next_arg, and ignore the result, so that the compiler + can report the proper error, if the second argument is not the + last argument. + +Tue Oct 3 12:02:51 1995 Kohtala Marko + + * function.c (assign_stack_temp): Adjust full_size field of + temp_slot when splitting an unused slot. + +Tue Oct 3 11:51:59 1995 Mike Stump + + * expr.c (expand_builtin_return_addr): Break out functionality + from expand_builtin. + (expand_builtin): Call expand_builtin_return_addr. + * rs6000.h (RETURN_ADDR_RTX): Remove call to copy_to_reg. + Offset to return address is 4 when !TARGET_64BIT and v4_call_p, + 8 otherwise. + * sparc.h (RETURN_ADDR_RTX): Remove call to copy_to_reg. + * alpha.h (RETURN_ADDR_RTX): New definition. + +Sun Oct 1 21:23:30 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * tree.c (staticp, case INDIRECT_EXPR): Disable case. + + * expr.c (expand_expr, case COMPONENT_REF): If getting component + of union of variable size, propagate TARGET. + +Fri Sep 29 07:48:09 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (store_expr): When storing promoted value, don't return + MEM if address contains target. + +Thu Sep 28 14:30:03 1995 Paul Eggert + + * cccp.c (rescan): Expand `#if foo && #bar' without a bogus + complaint about preprocessor directives within macro args. + Expand `foo' in `foo#bar' without requiring a space before `#'. + +Thu Sep 28 14:24:26 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (anonymous DImode shift patterns setting cc0): Turned + off due to reload problems. + +Thu Sep 28 14:05:22 1995 Niklas Hallqvist (niklas@appli.se) + + * Makefile.in (USER_H): Move up so can override. + (INSTALL_ASSERT_H): New definition. + (install-headers): Use it. + (stmp-int-hdrs): Handle USER_H being empty. + * config/x-netbsd (INSTALL_ASSERT_H): Define as empty. + + * i386/netbsd.h (WCHAR_{TYPE,UNSIGNED,TYPE_SIZE}): Now int. + * m68k/netbsd.h, ns32k/netbsd.h, sparc/netbsd.h: Likewise. + * vax/netbsd.h: Likewise. + (SIZE_TYPE): Use unsigned int. + + * m68k.c (output_scc_di): Swap operands when needed. + * m68k.h (LEGITIMATE_PIC_OPERAND): Allow SYMBOL_REF_FLAG symref. + * m68k.md: Make both assembler syntaxes do the same for PIC calls. + +Tue Sep 26 16:51:44 1995 Michael Meissner + + * mips.c (override_options): Don't allow anything but integers to + go in the HI/LO registers. + +Tue Sep 26 16:36:18 1995 John F. Carr + + * c-common.c (check_format_info): Don't warn about format type + mismatch if the argument is an ERROR_MARK. + +Mon Sep 25 17:50:50 1995 Craig Burley (burley@gnu.ai.mit.edu) + + * stor-layout.c (put_pending_sizes): New function. + * tree.h (put_pending_sizes): Add declaration. + * tree.c (save_expr): Return original for ERROR_MARK. + +Fri Sep 22 19:20:01 1995 Jeff Law (law@hurl.cygnus.com) + + * expr.c (expand_builtin, case BUILT_IN_MEMCPY): Strip off + all NOP exprs from the source and destination nodes, then + set MEM_IN_STRUCT_P. + +Fri Sep 22 18:50:31 1995 Michael Meissner + + * rs6000/eabi.h (ASM_OUTPUT_INT): Test for whether the integer + being output is also a constant so &sym - &sym2 is not fixed up. + +Fri Sep 22 18:49:07 1995 Peter Flass (FLASS@LBDRSCS.BITNET) + + * i370.md (cmpsi): Add missing constraints to operand 1. + +Fri Sep 22 18:27:33 1995 Torbjorn Granlund + + * i386.h (CONST_OK_FOR_LETTER_P): Make `N' match range 0..255 + for `outb' instruction. + + * pyr.h (PRINT_OPERAND): Handle code `R' for REG. + * longlong.h (pyr umul_ppmm): Use it. + +Fri Sep 22 18:24:38 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-parse.in (enumlist): Propagate error_mark_node. + + * c-aux-info.c (gen_type): Handle ERROR_MARK. + + * alpha.md (movdi): Avoid memory sharing problem when in reload. + +Wed Sep 20 14:27:09 1995 Peter Flass + + * mvs.h (FUNCTION_PROLOGUE): Maintain savearea forward chain + per MVS standards. + +Wed Sep 20 14:20:52 1995 Torbjorn Granlund + + * pyr.md (cmphi recognizer): Make condition match constraints. + (cmpqi recognizer): Likewise. + +Wed Sep 20 12:42:59 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * integrate.c (expand_inline_function): Do copy something setting + the result register if it is setting it to itself and has a REG_NOTE. + + * integrate.c (set_decl_{origin_self,abstract_flags}): Treat + a DECL_INITIAL of error_mark_node the same as one of NULL_TREE. + +Tue Sep 19 19:30:18 1995 Dave Pitts (dpitts@nyx.cs.du.edu) + + * i370.md (cmphi, movhi, movstricthi, extendhisi2): Correct generation + of short integer (Halfword) + ({add,sub,mul,and,ior,xor}hi3): Likewise. + * i370/mvs.h (MACROPROLOGUE): New macro. + (FUNCTION_{PRO,EPI}LOGUE): Added ability to use IBM supplied function + prologue macros. + (FUNCTION_PROLOGUE): Corrected function "in-line" prologue alignment + problems. + (ASM_DECLARE_FUNCTION_NAME): Changed alignment to FullWord. + (ASM_OUTPUT_{SHORT,ASCII}): Reworked. + +Tue Sep 19 19:22:15 1995 Douglas Rupp (drupp@cs.washington.edu) + + * winnt/win-nt.h: Renamed from winnt/win-nt.h. + (LINK_SPEC): Add -noinhibit-exec. + * {alpha,i386}/win-nt.h: Renamed from {alpha,i386}/winnt.h. + Include winnt/win-nt.h, not winnt/winnt.h. + * winnt/oldnames.c: New file. + * winnt/headers.mak (fixinc-nt.obj): Fix typo. + * winnt/config-nt.bat: Change winnt.h to win-nt.h. + * i386/config-nt.sed: Likewise. + * configure ({alpha,i386}-*-winnt3*): Likewise. + +Mon Sep 18 14:00:45 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * 1750a.h (enum reg_class, REG_CLASS_NAMES, REG_CLASS_CONTENTS): + Added R2 and R0_1. + (REG_CLASS_FROM_LETTER): New letters 't' and 'z'. + (EXTRA_CONSTRAINT): New letter 'Q'. + +Sun Sep 17 12:39:22 1995 Jeff Law (law@snake.cs.utah.edu) + + * pa.h (ASM_DECLARE_FUNCTION_NAME): If a parameter's type + has TYPE_NEEDS_CONSTRUCTING on, then it's passed by invisible + reference. + +Sat Sep 16 17:42:33 1995 Jim Wilson + + * loop.c (find_and_verify_loops): Fix error in last change. + +Sat Sep 16 08:38:22 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.h (GO_IF_LEGITIMATE_ADDRESS): Disallow SYMBOL_REF for + current function. + + * cse.c (recorded_label_ref): New variable. + (insert): Set instead of cse_jumps_altered. + (cse_main): Initialize it and return 1 if nonzero at end. + +Fri Sep 15 18:26:49 1995 Torbjorn Granlund (tege@matematik.su.se) + + * fold-const (div_and_round_double): Change `carry', `quo_est', + and `scale' from plain int to `unsigned HOST_WIDE_INT'. + +Fri Sep 15 18:24:24 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cse.c (insert): Set cse_jumps_altered when inserting a LABEL_REF. + +Fri Sep 15 17:29:41 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * 1750a.c (b_mode_operand): New function. + (print_operand): Added code 'Q'. + +Fri Sep 15 17:27:23 1995 Jim Wilson + + * loop.c (find_and_verify_loops): When moving exit blocks out of + the loop, verify that the target of P is within the current loop. + + * reorg.c (fill_slots_from_thread): Update thread if it is split. + +Fri Sep 15 17:06:51 1995 Michael Meissner + + * rs6000.md (decrement_and_branchsi and related insns): Don't use + a "2" to select a register preference for operand 1 if operand 2 + hasn't been seen yet. + Add appropriate clobbers in decrement_and_branchsi. + Add patterns where the pc/label_ref are interchanged. + + * Makefile.in (gnucompare, stmp-multilib-sub): Remove extra . in + front of $(objext). + + * rs6000.c (output_toc): Align DF constants if STRICT_ALIGNMENT. + + * config/fp-bit.c (FLO_union_type): Add words field if double + precision to get at the separate words. + (FLO_union_type, pack_d, unpack_d): Use FLOAT_BIT_ORDER_MISMATCH + to determine when the bitfields need to be reversed, and + FLOAT_WORD_ORDER_MISMATCH when the words need to be reversed. + +Fri Sep 15 16:41:43 1995 Jeff Law (law@snake.cs.utah.edu) + + * reorg.c (fill_simple_delay_slots): When filling insn's delay slot + with JUMP_INSN, don't assume it immediately follows insn on + unfilled slots obstack. + + * Makefile.in (caller-save.o): Depend on insn-codes.h. + +Thu Sep 14 17:41:49 1995 Jim Meyering (meyering@comco.com) + + * protoize.c (do_cleaning): Don't blank out backslash-escaped + newlines in double quoted strings. + +Thu Sep 14 16:20:35 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * emit-rtl.c (gen_lowpart): If gen_lowpart_common fails + for a REG, load it into a pseudo and try again. + +Thu Sep 14 14:15:16 1995 Stan Cox (coxs@dg-rtp.dg.com) + + * m88k.h (VERSION_INFO1): Removed BCS reference. + * m88k/dgux.h (ASM_SPEC, *_LEGEND): + Added -mno-legend option. -mstandard no longer implies that legend + legend information not be produced. + (LINK_SPEC): Removed -z text + +Tue Sep 12 19:05:39 1995 Jim Wilson + + * cccp.c (is_system_include): Call skip_redundant_dir_prefix. + +Tue Sep 12 18:58:21 1995 John Carr + + * sparc.md: Change `*return "string"' to "string" in patterns. + +Tue Sep 12 18:48:47 1995 Craig Burley (burley@gnu.ai.mit.edu) + + * function.c (put_var_into_stack): For CONCAT case, order of + placement depends on FRAME_GROWS_DOWNWARD, not STACK_GROWS_DOWNWARD. + +Tue Sep 12 18:34:10 1995 Doug Evans + + * va-sparc.h (v9 varargs va_start): Handle __builtin_va_alist + being stack argument. + + * sparc.h (STATIC_CHAIN_REGNUM): Use %g5 for sparc64. + (TRAMPOLINE_TEMPLATE): Rewrite for sparc64. + (TRAMPOLINE_SIZE): Is 40 for sparc64. + * sparc.c (sparc64_initialize_trampoline): Rewrite. + +Tue Sep 12 18:30:22 1995 Douglas Rupp (drupp@cs.washington.edu) + + * cp/Make-lang.in (cc1plus) : Removed unnecessary $(exeext). + + * configure: Added code to handle gcc_extra_objs. + (alpha-winnt): Changed xmake_file to winnt/x-winnt. + Added extra_gcc_objs=spawnv.o; changed extra_programs to ld.exe. + (i386-winnt): Changed xmake_file to winnt/x-winnt. + Added extra_gcc_objs=spawnv.o; changed extra_programs to ld.exe. + * configure.bat: Changed to used common winnt/config-nt.bat. + * Makefile.in: Changed various .o's to .$(objext)'s + (specs): Removed unnecessary $(exeext). + (EXTRA_GCC_OBJS): New variable. + (clean): Removed $(LIB2FUNCS_EXTRA) + * objc/Makefile: Changed archive command for libobjc.a to use $? + for objects. + + * alpha/x-winnt, i386/x-winnt: Deleted. + * alpha/config-nt.bat, i386/config-nt.bat: Deleted. + * alpha/config-nt.sed, i386/config-nt.sed: Moved architecture + independent commands to config/winnt/config-nt.sed. + * alpha/winnt.h: Added -D_M_ALPHA to CPP_PREDEFINES. + Changed LIB_SPEC to be compatible with Gnu ld for NT. + * i386/winnt.h: Added -D_cdecl=__attribute__((__cdecl__)). + Change LIB_SPEC to be compatible with Gnu ld for NT. + * winnt/config-nt.bat, winnt/config-nt.sed: New files. + * winnt/dirent.{c,h}, winnt/fixinc-nt.c, winnt/headers.mak: New files. + * winnt/ld.c: Changed precedence of libraries to look for + libfoo.lib before libfoo.a + Changed to work like Gnu ld for NT. + * winnt/libgcc.mak, winnt/mklibgcc.c: New files. + * winnt/spawnv.c: Changed spawn function entry points to __spawn* + instead of spawn*. + * winnt/x-winnt: New file. + * fixinc-nt.sed: New file. + * fixinc.winnt: Rewritten to use fixinc-nt.sed. + + * gcc.c: Remove fix_argv kludge. + +Tue Sep 12 13:24:17 1995 Michael Meissner + + * rs6000.md (power subdi3 pattern): Fix pattern to have 5 + alternatives, and correct 4th alternative to match reality. + + * rs6000.md (adddi3, subdi3, negdi2): Add constraints so output reg + does not overlap one reg with one of the inputs. + +Tue Sep 12 13:09:48 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.c (output_scc_di): Fixed for non-SGS_CMP_ORDER syntax. + + * collect2.c (scan_libraries): Cast lsyms' alloca to LDSYM*. + +Tue Sep 12 13:04:12 1995 Niklas Hallqvist (niklas@appli.se) + + * stmt.c (expand_start_stmt_expr): Do stack adjust in right place. + + * stdarg.h (__gnuc_va_list): Make char * for NetBSD. + +Tue Sep 12 12:44:46 1995 Jason Merrill + + * ginclude/va-ppc.h (va_arg): Reorganize to avoid BIND_EXPRs of + aggregate or array type. + +Tue Sep 12 12:42:27 1995 Ian Lance Taylor + + * fixincludes: Fix HP/UX for g++ -pedantic-errors. + + * fixincludes (curses.h): typedef bool need not take up entire line. + +Mon Sep 11 19:05:42 1995 Stan Cox (coxs@dg-rtp.dg.com) + + * c-typeck.c (digest_init): Don't recursively call digest_init + when in traditional mode if the type is invalid. + +Mon Sep 11 18:58:26 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * 1750a.md: Added DLB/DSTB peepholes for HFmode. + Corrected mnemonics for HImode DSTB peephole. + +Mon Sep 11 18:48:06 1995 Michael Meissner + + * config/fp-bit.c (FLO_union_type): Remove bitfields to set sign, + exponent, and mantissa, and add value_raw field, which is an + integer of the appropriate type. If _DEBUG_BITFLOAT is defined, + provide little and big endian bitfields. If the macro + FLOAT_BIT_ORDER_MISMATCH is defined, use explicit bitfields. + (pack_d, unpack_d): Switch to use value_raw and explicit shifts + and masks so that we don't have to worry about whether the target + is big or little endian unless FLOAT_BIT_ORDER_MISMATCH is + defined. If single precision floating point, rename to pack_f and + unpack_f, so there is no confusion in the debugger. + + * rs6000.h (rs6000_abi): New enumeration to describe which + ABI we're conforming to. + (rs6000_stack): Use abi enum, not AIX vs. V.4 boolean. + (ASM_OUTPUT_OPTIONS): New macro to print output options in .s file. + (ASM_FILE_START): Use it. + (output_options,rs6000_float_const): Declare new functions. + + * rs6000.c (output_option{,s}): New functions to write -f, -m, + and -W options to the asm file. + (rs6000_float_const): New function to generate floating point + constants portably used in signed,unsigned -> double conversions. + (rs6000_stack_info,debug_stack_info): Use ABI enumeration instead + of AIX vs. V.4 boolean. + + * rs6000.md (float{,uns}sidf2): Call rs6000_float_const to + portably build the proper floating point constant for conversions. + (movdi): Properly handle movdi of CONST_{INT,DOUBLE} on little + endian systems. + + * rs6000/sysv4.h (LIBGCC2_WORDS_BIG_ENDIAN): Define to be 0/1 + depending on the target endianess. + (ASM_FILE_START): Define, to call output_options in addition to + output_file_directive. + (TRAMPOLINE_SIZE): Correct size to match code. + + * rs6000/eabi{,le}sim.h (CPP_SPEC): Define the correct endian + macro for varargs/stdargs use. + +Mon Sep 11 18:41:58 1995 Jim Wilson + + * c-decl.c (redeclaration_error_message): For TYPE_DECLs, return 0 + if TYPE_MAIN_VARIANT of old type is same as new type. + +Mon Sep 11 17:39:35 1995 Rob Ryan (robr@cmu.edu) + + * xcoffout.c (xcoff_inlining): New variable, used in place of + xcoff_current_include_file when determining whether to use + absolute line numbers. + (xcoffout_source_file): Switched to using xcoff_inlining to + determine when to emit .bi/.ei directives. + +Mon Sep 11 16:55:06 1995 Torbjorn Granlund + + * m68k.md (cmpdi): Change patterns to allocate scratch register at + RTL generation time. + (tstdi): Likewise. + +Sun Sep 3 09:03:50 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (size_binop): Don't pass 1 to NOTRUNC. + +Thu Aug 31 19:27:00 1995 Roland McGrath + + * libgcc2.c: Include longlong.h. + [L_udivdi3 || L_divdi3 || L_umoddi3 || L_moddi3] (__udivmoddi4): + Define this `static inline' when defining these, so they all + remain leaf functions. + +Thu Aug 31 18:38:21 1995 Paul Eggert + + * c-parse.in (ends_in_label): New %union member. + (stmts, stmt_or_label): Use new member to avoid lexical lookahead hack. + (lineno_stmt_or_labels): New rule. + (lineno_stmt_or_label, stmt_or_label): Yield nonzero if it ends + in a label. + +Thu Aug 31 08:31:40 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cse.c (canon_hash, CONST_DOUBLE): Hash integer and real + differently. + * varasm.c (struct rtx_const): Add new field DI to union. + (decode_rtx_const, case CONST_DOUBLE): Use to hash CONST_DOUBLE + representing an integer. + + * va-alpha.h (__gnuc_va_list): Make __offset an int. + * alpha.c (alpha_builtin_saveregs): Properly compute address + of __offset both both OSF and WINNT. + + * xm-alpha.h (sbrk): Don't define here. + * gmon.c (sbrk): Define here for __alpha. + * toplev.c (sbrk): Likewise. + * mips-tfile.c (malloc, calloc, realloc): Don't define for anybody. + + * reload.c (push_reload): Add case for output reload of a SUBREG + of a hard reg when output mode is invalid for that mode. + In both that case and existing case for in, don't remove SUBREG. + * reload1.c (emit_reload_insn): Emit RELOAD_OTHER output reloads last. + +Tue Aug 29 19:16:06 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-common.c (decl_attribute, case A_PACKED): Check is_type first. + (decl_attribute, case A_T_UNION): Likewise. + Don't access TYPE_FIELDS if DECL is zero. + * c-decl.c (finish_struct): If transparent_union attribute + specified, validate it once we finish laying the union out. + +Mon Aug 28 05:58:03 1995 Paul Eggert + + * arm.c (arm_gen_movstrqi): Remove unused variable const_sxteen. + + * bi-lexer.c (buffer, inpoint): Remove unused variables. + + * i370/mvs.h, i370/mvs370.c (mvs_label_emitted): Renamed + from mvs_label_emited. + + * msdos/configur.bat: Fix misspelling of `maintainer-clean'. + +Sat Aug 26 06:57:17 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * reload.c (push_secondary_reload): If X is a paradoxical SUBREG, + get mode and thing to reload from inside. + * reload1.c (emit_reload_insns): Do nothing for SUBREG whose + operand is unused subsequently. + In secondary reload case, if paradoxical SUBREG for output, reload + thing inside SUBREG, just like gen_reload. + +Fri Aug 25 19:26:53 1995 Paul Eggert + + * c-typeck.c (set_init_label): Don't die if an entire + brace-pair level is superfluous in the containing level. + +Fri Aug 25 19:22:46 1995 Michael Meissner + + * configure (powerpc{,le}-eabisim): Add support for a new target + that works under the PSIM simulator. + * rs6000/eabisim.h, rs6000/eabilesim.h, rs6000/t-eabisim: New files. + + * rs6000/eabi.h (STRICT_ALIGNMENT): If little endian, always set + strict alignment to 1. + +Fri Aug 25 19:22:23 1995 David Edelsohn + + * rs6000.md ({add,sub,mulsi}di3): Support both endian possibilities. + (negdi2): Likewise. + +Fri Aug 25 19:10:41 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * 1750a.md: Added peephole definitions for Load/Store Base insns + and eliminating redundant load in an equivalent store/load sequence. + +Fri Aug 25 18:33:27 1995 Craig Burley (burley@gnu.ai.mit.edu) + + * toplev.c (report_error_function): Don't attempt to use input + file stack to identify nesting of #include's if file name oflocation + diagnosed is not same as input_filename. + +Fri Aug 25 07:31:47 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * integrate.c (output_inline_function): Switch to function obstack. + +Mon Aug 21 13:29:54 1995 J"orn Rennecke (amylaar@meolyon.hanse.de) + + * i386.c (arithmetic_comparison_operator): New function. + (print_operand): Take into account that overflow flag is not + set the same as after a compare instruction. + * i386.md (decrement_and_branch_until_zero): Use + arithmetic_comparison_operator to decide if there is comparison + suitable to be expressed by condition code from an arithmetic op. + +Mon Aug 21 13:26:13 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (adddi3, subdi3): "&" added to clobber's constraints. + +Mon Aug 21 12:11:14 1995 Jim Wilson + + * t-sparclite (MULTILIB_*, LIBGCC, INSTALL_LIBGCC): Define. + + * sh.md (movdi-1, movdf-1): Make conditional on reload_completed, + delete conditions checking for pseudo registers and Q addresses. + Add code to handle SUBREG. + + * local-alloc.c (wipe_dead_reg): Make a register mentioned in a + REG_INC note die after the instruction. + + * m68k.md: For all dbra pattern, change constraint from 'g' to 'd*g'. + + * Makefile.in: (underscore.c): Rename rule to stamp-under, and + touch stamp-under at the end. Add new rule for underscore.c that + depends on stamp-under. + + * sh.c (reg_unused_after): For a SEQUENCE, make sure all insns are + safe before returning 1. + + * sh.h (PROMOTE_FUNCTION_ARGS, PROMOTE_FUNCTION_RETURN): Define. + + * sh.c (output_stack_adjust): Add new argument reg. Use it instead + of stack_pointer_rtx. + (sh_expand_prologue, sh_expand_epilogue): Pass new argument to + output_stack_adjust. + +Sat Aug 19 17:34:15 1995 Jim Wilson + + * sparc/gmon-sol2.c (_mcount): Define. + * sparc/sol2.h (STARTFILE_SPEC, ENDFILE_SPEC): Delete superfluous + -pg tests. + (LINK_SPEC): Add libp directories to -Y when -pg. + + * unroll.c (calculate_giv_inc): Handle increment computed by ASHIFT. + +Sat Aug 19 17:28:56 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (subdi3): Should not be commutative. + (one_cmpldi2): Fixed typo with register operand. + +Sat Aug 19 17:20:43 1995 Michael Meissner + + * rs6000.c (output_prolog): Fixup code to set stack pointer + if stack size > 32k. + * rs6000.md (sync_isync): Renamed from sync; added an isync insn + after the sync to properly deal with PowerPC's with split I/D caches. + * sysv4.h (INITIALIZE_TRAMPOLINE): Sync function now named sync_isync. + +Sat Aug 19 17:07:09 1995 Doug Evans + + * h8300.h (STATIC_CHAIN_REGNUM): Use r3. + (REGISTER_NAMES): Print r7 as sp. + (ADDITIONAL_REGISTER_NAMES): Recognize r7. + (ASM_OUTPUT_ALIGN): Alignment is power of 2. + * h8300.md (fancy_btst,fancy_btst1): Branch target must be + operand 0 for length attribute to work. + +Sat Aug 19 16:43:11 1995 Paul Franklin + + * assert.h: Declare __eprintf with attribute noreturn. + +Sat Aug 19 16:40:12 1995 Jason Merrill + + * stddef.h: Don't define wchar_t if __cplusplus is defined. + +Tue Aug 15 18:01:01 1995 Paul Eggert + + * cccp.c (warning_with_line): Fix typo in declaration when + !HAVE_VPRINTF and defined (__STDC__). + +Tue Aug 15 17:57:54 1995 Stephen L Moshier + + * real.c (ediv, emul): Set sign bit of IEEE -0.0 result. + +Tue Aug 15 17:49:47 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (safe_from_p): Only safe if EXP is variable-size and X + is BLKmode. + + * stmt.c (fixup_gotos): When some fixups done, reset to point + to next instead of zeroing TREE_VALUE, which may be shared. + +Mon Aug 14 09:15:45 1995 Doug Evans + + * m68k/m68kemb.h (STARTFILE_SPEC): Define as empty. + +Mon Aug 14 09:08:57 1995 Pat Rankin + + * vax.c (vms_check_external): Update `pending_head' properly + when the first list element is removed. + +Mon Aug 14 09:01:32 1995 Jeffrey A. Law + + * pa.md (call expanders): Emit a blockage insn after restoring + %r19 when generating PIC. + +Sun Aug 13 21:58:49 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * toplev.c (main): Change text of unsupported -g option warning. + +Sun Aug 13 21:47:57 1995 Andrew McCallum + + * objc/selector.c (sel_get_any_typed_uid): New function. + * objc/objc-api.h (sel_get_any_typed_uid): Declare new function. + +Sun Aug 13 21:43:17 1995 John Carr + + * c-typeck.c (c_expand_asm_operands): Check for read-only output + operand where the variable is read-only but the type is not. + +Sun Aug 13 21:16:12 1995 David Edelsohn + + * rs6000.c (direct_return): Epilogue required if CR saved. + +Sun Aug 13 19:09:25 1995 Jeff Law (law@snake.cs.utah.edu) + + * configure (hppa1.?-hp-hpux10): Recognize and treat just like hpux9. + +Sun Aug 13 19:07:23 1995 Doug Evans + + * i960.md (movdi matchers): Fix src/dest order in unaligned + reg->reg case. + +Sun Aug 13 18:49:01 1995 DJ Delorie + + * i386/xm-dos.h (HAVE_STRERROR): New definition. + + * msdos/configur.bat: Add missing carriage return. + +Sun Aug 13 18:40:55 1995 Andrew Cagney + + * Makefile.in (USER_H): Add va-ppc.h. + +Sun Aug 13 18:36:17 1995 M. Warner Losh + + * stmt.c (expand_asm_operands): Type '0'..'4' operands may + allow regs, so move them to the default case. + +Sun Aug 13 18:32:35 1995 Paul Eggert + + * cccp.c (warning_with_line): New function. + (trigraph_pcp): Use it, to avoid reporting line number. + (vwarning_with_line): Don't report line number if zero. + +Sun Aug 13 18:23:08 1995 Jason Merrill + + * toplev.c (vmessage): Support four arguments. + +Sun Aug 13 18:19:51 1995 Michael Meissner + + * ginclude/stdarg.h: Add ppc svr4 calling sequence support. + * ginclude/varargs.h: Likewise. + * ginclude/va-ppc.h: New file. + +Sun Aug 13 18:05:20 1995 Michael Gschwind + + * configure (pdp-*-*): Add support for t-pdp11. + * t-pdp11: New file. + * Makefile.in (LIBGCC2_CFLAGS): Add TARGET_LIBGCC2_CFLAGS. + +Sun Aug 13 14:50:58 1995 Jim Wilson + + * final.c (final_start_function): Always call sdbout_begin_function + and xcoffout_begin_function, even if no line number info. + + * mips/abi64.h (SETUP_INCOMING_VARARGS): In if statement, only + subtract one for stdarg. Don't subtract PRETEND_SIZE from + argument pointer when calculating stack address. + * mips.h (INITIAL_ELIMINATION_OFFSET): For 64 bit ABI, subtract + current_function_pretend_args_size when converting from argument + pointer. + * va-mips.h (va_start): For stdarg, delete separate define for + 64 bit ABI. For varargs, don't subtract 64, and only add -8 when + all argument registers are used. + + * gcc.c (main): When concat gcc_exec_prefix and + standard_startfile_prefix, put machine_suffix in the middle. + + * iris6.h (INIT_SECTION_ASM_OP): Don't define. + (LD_INIT_SWITCH, LD_FINI_SWITCH, HAS_INIT_SECTION): Don't undef. + (ASM_OUTPUT_CONSTRUCTOR, ASM_OUTPUT_DESTRUCTOR): Ifdef out. + * configure (mips-sgi-irix6, mips-sgi-irix5cross64): Define + use_collect2 to yes. + + * combine.c (move_deaths): When have a multi-reg hard register, + if don't find a note, then recur for each individual hard register. + + * cse.c (set_nonvarying_address_components): Handle addresses + which are the sum of two constant pseudo regs. + (cse_rtx_addr_varies_p): Likewise. + + * Makefile.in (gfloat.h): Add a - before the rm command. + + * loop.c (find_and_verify_loops): Set dest_loop only if + JUMP_LABEL (insn) is non-zero. + +Mon Jul 31 14:31:53 1995 Ian Lance Taylor + + * fixincludes: Avoid clobbering VxWorks drv/netif/if_med.h file. + +Sat Jul 29 16:21:42 1995 Jason Merrill + + * collect2.c: (XCOFF_SCAN_LIBS): Define if OBJECT_FORMAT_COFF and + XCOFF_DEBUGGING_FORMAT. + (SCAN_LIBRARIES): Also define if XCOFF_SCAN_LIBS. + +Sat Jul 29 16:19:42 1995 Stuart D. Gathman + + * collect2.c (scan_libraries): Implement for AIX. + +Sat Jul 29 09:59:33 1995 Michael Gschwind + + * configure: (pdp11-*-bsd) New target. + * 2bsd.h: New file. + + * pdp11.c (output_move_double): Handle CONST_INT parameters properly. + * pdp11.h (RTX_COSTS): Fill in missing default values. + * pdp11.md (truncdfsf2, extendsfdf2, floatsidf2, fix_truncdfsi2): + Allow register parameters, required by gcc to generate correct code. + * xm-pdp11.h: Include tm.h. + +Sat Jul 29 09:55:17 1995 Andreas Schwab + + * configure (m68k-*-linux*aout*, m68k-*-linux*): New targets. + * m68k/linux-aout.h, m68k/linux.h, m68k/t-linux, m68k/xm-linux.h: New. + * m68k.md [USE_GAS]: Output `jbsr' instead of `jsr' for normal + function calls and `bsr.l' instead of `bsr' for pic function calls. + +Sat Jul 29 09:44:13 1995 Jim Wilson + + * sh.h (CAN_DEBUG_WITHOUT_FP): Comment out. + + * reload.c (find_reloads_address_1, case PLUS): When handle SUBREG, + add SUBREG_WORD offset to SUBREG_REG register number. + (find_reloads_address_1, case SUBREG): If a pseudo register inside + a SUBREG is larger than the class, then reload the entire SUBREG. + * sh.h (SUBREG_OK_FOR_INDEX_P): New macro. + (INDEX_REGISTER_RTX_P): Use it. + +Sat Jul 29 09:33:19 1995 Doug Evans + + * mips/netbsd.h (CPP_SPEC): Fix typo. + + * configure (a29k-*-vxworks*): Define extra_parts for crt{begin,end}.o. + * t-a29k, t-a29kbase, t-vx29k ({,CROSS_}LIBGCC1): Define as empty. + +Sat Jul 29 09:15:17 1995 Jeffrey A. Law + + * pa/lib2funcs.asm (gcc_plt_call): Rewrite to avoid the need + for being called by _sr4export. Inline expand $$dyncall to + avoid the need for long-call and PIC support. + +Sat Jul 29 07:30:04 1995 Oliver Kellogg (Oliver.Kellogg@space.otn.dasa.de) + + * ms1750.inc (ucim.m, ucr.m, uc.m): New. + * 1750a.md (cmpqi): Account for unsigned comparisons. + (rotrqi3, rotrhi3): Reworked. + * 1750a.c (notice_update_cc): INCM and DECM set condition codes. + (unsigned_comparison_operator, next_cc_user_is_unsigned): New fcns. + * 1750a.h (FUNCTION_EPILOGUE): Local variables freed from SP, not FP. + (ASM_OUTPUT_BYTE): Make distinct from ASM_OUTPUT_CHAR. + (ASM_OUTPUT_CONSTRUCTOR): Add FILE arg to assemble_name. + +Fri Jul 28 09:40:07 1995 Jeffrey A. Law + + * pa.h (DO_GLOBAL_DTORS_BODY): Use an asm statement to keep optimizer + from deleting an assignment it believes dead. + +Fri Jul 28 08:47:51 1995 Jim Wilson + + * unroll.c (unroll_loop): When preconditioning, output code to + execute loop once if initial value is greater than or equal to final + value. + + * configure (lang_specs_files, lang_options_files): Add $srcdir to + file names when adding them to these variables. + + * c-typeck.c (pointer_int_sum): Don't distribute if intop is unsigned + and not the same size as ptrop. + + * function.c (assign_stack_temp): When split a slot, set base_offset + and full_size in the newly created slot. + (combine_temp_slots): Update full_size when slots are combined. + + * sh.c (reg_unused_after): New function. + * sh.md (define_peephole): Add peepholes to use r0+rN addressing mode + for some address reloads. + + * final.c (final_start_function): If SDB_DEBUG, call + sdbout_begin_function. If XCOFF_DEBUG, call xcoffout_begin_function + instead of xcoffout_output_first_source_line. + (final_scan_insn): Don't call sdbout_begin_function or + xcoffout_begin_function. + * xcoffout.c (xcoffout_output_first_source_line): Delete. + (xcoffout_begin_function): Call dbxout_parms and + ASM_OUTPUT_SOURCE_LINE. + + * va-mips.h: Change every occurance of #if __mips>=3 to + #ifdef __mips64. + * mips/abi64.h (CPP_SPEC): Output -D__mips64 when -mips3, or -mips4, + or -mgp64. Output -U__mips64 when -mgp32. + * mips/dec-bsd.h, mips/elf64.h, mips/iris3.h: Likewise. + * mips/iris5.h, mips/mips.h, mips/netbsd.h, mips/osfrose.h: Likewise. + + * i960.c (i960_function_epilogue): Don't clear g14 for functions with + an argument block. + (i960_output_reg_insn): Likewise. + (i960_output_call_insn): Clear g14 for functions wtih an argument + block. + +Fri Jul 28 08:43:52 1995 Doug Evans + + * i960.c (i960_arg_size_and_align): Correct alignment of XFmode + values in library calls. + * i960.md (movdi matchers): Support odd numbered regs. + +Fri Jul 28 08:37:25 1995 Michael Gschwind + + * pdp11.md (divhi3, modhi3, divmodhi4): Rewrite. + +Wed Jul 26 10:15:52 1995 Hallvard B Furuseth (h.b.furuseth@usit.uio.no) + + * collect2.c (end_file): Fix typo in error message text. + +Wed Jul 26 09:22:22 1995 Jeff Law (law@snake.cs.utah.edu) + + * xm-pa.h (USE_C_ALLOCA): Always define. + * xm-pahpux.h (USE_C_ALLOCA): Likewise. + + * x-pa (CC): Remove useless definition. + * xm-pa.h (HAVE_STRERROR): Define. + (__BSD_NET2__): Define. + +Wed Jul 26 09:10:25 1995 Jason Merrill + + * expr.c (preexpand_calls): Don't look past a CLEANUP_POINT_EXPR. + +Wed Jul 26 08:43:42 1995 Jim Wilson + + * cse.c (cse_insn): When do special handling for (set REG0 REG1), + must delete REG_EQUAL note from insn if it mentions REG0. + + * loop.c (find_and_verify_loops): When moving blocks of code, verify + that the just destination is not in an inner nested loop. + (mark_loop_jump): Don't mark label as loop exit if it jumps to + an inner nested loop. + +Wed Jul 26 08:40:31 1995 Paul Eggert + + * cccp.c (do_include, read_name_map): Omit leading "./" and + trailing "/" when it makes sense. + (skip_redundant_dir_prefix): New function. + +Wed Jul 26 08:36:41 1995 Michael Meissner + + * stmt.c (emit_nop): Do not emit a nop if there is a single + insn before a label or at the start of a function. + +Wed Jul 26 08:21:21 1995 Doug Evans + + * Makefile.in (gfloat.h): Delete previous copy before updating. + +Wed Jul 26 08:18:29 1995 Roland McGrath + + * Makefile.in (STAGESTUFF): Add stamp-crtS. + (crtbeginS.o, crtendS.o, stamp-crtS): New rules; just like + crtbegin.o et al, but compiled using -fPIC. + * configure (*-*-gnu*): Add crtbeginS.o and crtendS.o to $extra_parts. + +Wed Jul 26 08:11:52 1995 Michael Gschwind + + * pdp11.md: Fixed typos ('bhos' -> 'bhis'). + +Wed Jul 26 08:05:41 1995 Jim Wilson + + * hp320.h, m68k.h, m68kv4.h (LEGITIMATE_PIC_OPERAND_P): Reject + CONST_DOUBLE with MEM with invalid pic address. + * reload1.c (real.h): Include it. + * Makefile.in (reload1.o): Depends on real.h. + +Wed Jul 26 07:58:22 1995 Ian Lance Taylor + + * gcc.c (MULTILIB_DIRS): Provide default if not defined. + (multilib_defaults): New static variable. + (default_arg): New static function. + (set_multilib_dir): Ignore default arguments. + (print_multilib_info): Ignore entries which use default arguments. + +Tue Jul 25 10:06:09 1995 Michael Meissner + + * rs6000.md (allocate_stack): Don't copy the LR register to + the new stack end. + * rs6000.c (rs6000_stack_info): Correctly store the LR in + the caller's frame, not the current frame, for V.4 calls. + * rs6000/eabi.asm (_save*, _rest*): Provide all mandated V.4 save + and restore functions, except for the save*_g functions which + return the GOT address. + +Fri Jul 21 14:24:25 1995 Michael Meissner + + * rs6000/eabi.h (__eabi): Load up r13 to be the small data + pointer, unless -mrelocatable. + + * rs6000/aix3newas.h (LINK_SPEC): Import machine independent + functions if -mcpu=common. + * rs6000/milli.exp: Import file referenced in aix3newas.h. + + * rs6000/eabi.asm (__eabi): Support for fixing up user initialized + pointers when -mrelocatable is used. + * rs6000/eabi.h (ASM_OUTPUT_INT): Record any pointers initialized + by the user if -mrelocatable, to be fixed up by __eabi. + (CONST_SECTION_ASM_OP): If -mrelocatable, put read-only stuff in .data, + not .rodata, to allow user initialized pointers to be updated by __eabi. + + * rs6000.h (TARGET_SWITCHES): Add -mdebug-{stack,arg}. + (TARGET_{ELF,NO_TOC,TOC}): Add defaults for non system V. + (rs6000_stack): New structure to describe stack layout. + (RS6000_{REG_SAVE,SAVE_AREA,VARARGS_*}): New macros used to + support both AIX and V.4 calling sequences. + (FP_ARG_*, GP_ARG_*): Ditto. + (FP_SAVE_INLINE): Ditto. + (STARTING_FRAME_OFFSET): Modify to support both AIX and V.4 + calling sequences. + (FIRST_PARM_OFFSET): Ditto. + (REG_PARM_STACK_SPACE): Ditto. + (STACK_POINTER_OFFSET): Ditto. + (FUNCTION_ARG_REGNO_P): Ditto. + ({,INIT_}CUMULATIVE_ARGS): Ditto. + (LEGITIMATE_LO_SUM_ADDRESS_P): Ditto. + (FUNCTION_ARG{,_ADVANCE,PARTIAL_NREGS,PASS_BY_REFERENCE}): Ditto. + (SETUP_INCOMING_VARARGS): Ditto. + (EXPAND_BUILTIN_SAVEREGS): Ditto. + (CAN_ELIMINATE): Ditto. + (INITIAL_ELIMINATION_OFFSET): Ditto. + (LEGITIMATE_CONSTANT_POOL_{BASE,ADDRESS}_P): Ditto. + (GO_IF_{LEGITIMATE_ADDRESS,MODE_DEPENDENT_ADDRESS}): Ditto. + (LEGITIMIZE_ADDRESS): Ditto. + (CONST_COSTS): Ditto. + (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P): Ditto. + (ASM_OUTPUT_REG_{PUSH,POP}): Use reg_names to print registers. + (function declarations): Add new rs6000.c function declarations, + and delete decls of deleted functions. + (SHIFT_COUNT_TRUNCATED): Parenthesize the expression. + + * rs6000.c (init_cumulative_args): New function to support AIX + and V.4 calling sequences. + (function_arg{,_advance,partial_nregs,pass_by_reference}): Ditto. + (setup_incoming_varargs): Ditto. + (expand_builtin_saveregs): Ditto. + (rs6000_stack_info): Ditto. + (debug_stack_info): Ditto. + (direct_return): Changes to support AIX and V.4 calling sequences. + (first_reg_to_save): Ditto. + (svr4_traceback): Ditto. + (output_{prolog,epilog}): Ditto. + (print_operand): Use reg_names to print registers. Add support + for V.4 HIGH/LO_SUM address modes. + (must_save_cr): Function deleted, in rewrite of AIX/V.4 calling + sequence support. + (rs6000_sa_size): Ditto. + (rs6000_pushes_stack): Ditto. + (output_toc): Add abort if no toc. + + * rs6000.md (call insns): Add a new argument to flag a V.4 + function needs to set bit 6 of the CR. + (elf_{low,high}): New V.4 functions to create addresses via HIGH + and LO_SUM patterns. + (movsi): Use elf_{low,high} if appropriate. + (mov{si,di}_update): Name these patterns for allocate_stack. + (allocate_stack): Support for V.4 stack layout. + (sync): New pattern for V.4 trampolines to issue the sync + instruction. + + * rs6000/sysv4.h (TARGET_SWTICHES): Add -mcall-{aix,sysv}, and + -mprototype. Remove separate flag bit for -mno-toc. + (SUBTARGET_OVERRIDE_OPTIONS): Don't test for -mno-toc. + (FP_ARG_*): Adjust for V.4 calling sequences. + (RS6000_*): Ditto. + (FP_SAVE_INLINE): Ditto. + (toc_section): Eliminate use of AIX style full TOC. + (TRAMPOLINE_{TEMPLATE,SIZE}): Redefine for V.4 support. + (INITIALIZE_TRAMPOLINE): Ditto. + + * rs6000/eabi.h (CPP_SPEC): Define _CALL_SYSV or _CALL_AIX, + depending on whether -mcall-sysv or -mcall-aix was used. + * rs6000/eabile.h (CPP_SPEC): Ditto. + * rs6000/sysv4le.h (CPP_SPEC): Ditto. + + * rs6000/t-eabigas (MULTILIB_{OPTIONS,DIRNAMES}): Delete no-toc + libraries, explicit big endian libraries. + * rs6000/t-ppcgas (MULTILIB_{OPTIONS,DIRNAMES}): Ditto. + + * rs6000/t-eabiaix: New file for eabi, using -mcall-aix as the + default. + * rs6000/eabiaix.h: Ditto. + + * rs6000/t-eabilegas: New file for eabi on little endian systems. + * rs6000/t-ppclegas: New file for V.4 on little endian systems. + + * rs6000/t-rs6000 (MULTILIB_{OPTIONS,DIRNAMES}): Build libgcc.a + for -mcpu=common. + + * configure (powerpc-*-eabiaix): New configuration for defaulting + to old-style AIX calling sequence. + (powerpcle*): Use new t-{eabi,ppc}legas files, to avoid building + explicit little endian multilib libraries. + +Fri Jul 21 13:23:06 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * toplev.c (main): Don't define sbrk #ifdef __alpha__. + +Tue Jul 18 19:23:44 1995 Paul Eggert + + * cccp.c (do_include): Prefix -H output lines with spaces, not dots. + (output_dots): Remove. + + * cccp.c (main): cplusplus_comments now defaults to 1. + But clear it if -traditional or the new option -lang-c89 is given. + * gcc.c (default_compilers, cpp): Specify -lang-c89 if -ansi is given. + This turns off C++ comment recognition. + +Tue Jul 18 19:16:38 1995 Jim Wilson + + * va-sparc.h (va_arg): Add support for 128 bit long double type. + +Tue Jul 18 19:11:18 1995 Jorn Rennecke (amylaar@meolyon.hanse.de) + + * c-common.c (decl_attributes, case A_ALIGNED): Handle is_type + case properly. + +Tue Jul 18 19:03:02 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (fold, case CONVERT_EXPR): Don't merge conversions + if outer is to handle a type with differing precision. + +Mon Jul 17 14:37:35 1995 Pat Rankin (rankin@eql.caltech.edu) + + * vax/vms.h (HAVE_ATEXIT): Define. + (DO_GLOBAL_CTORS_BODY): Don't call atexit; let __do_global_ctors do it. + * vax/xm-vms.h (HAVE_VPRINTF): Define. + +Mon Jul 17 06:41:19 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-typeck.c ({unsigned,signed}_type): Handle intXX_type_node types. + + * xm-alpha.h (sbrk): Add declaration. + + * convert.c (convert_to_integer): If TYPE is a enumeral type or + if its precision is not the same as the size of its mode, + convert in two steps. + + * m68k.md (tstdi, cmpdi): Use match_scratch, not match_operand. + +Fri Jul 14 19:23:42 1995 Andreas Schwab + + * c-decl.c (field_decl_cmp): Rewritten to make sure that a null + name always sorts low against other names. + * c-typeck.c (lookup_field): Change name comparison to match what + field_decl_cmp does. + +Fri Jul 14 18:46:24 1995 Michael Meissner + + * rs6000.md (movsi): Convert a CONST_DOUBLE into a CONST_INT of + the low part. + +Fri Jul 14 18:30:52 1995 Doug Evans + + * toplev.c (main): Reword dwarf/c++/-g warning. + +Fri Jul 14 18:19:34 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.h (NO_DEFER_POP): Remove last change. + * expr.c (stor_expr): Force stack adjust before NO_DEFER_POP. + (expand_expr, case COND_EXPR): Likewise. + * stmt.c (expand_start_stmt_expr): Likewise. + +Fri Jul 14 07:58:35 1995 Jim Wilson + + * function.c (struct temp_slot): New fields base_offset, full_size. + (assign_stack_temp): For !FRAME_GROWS_DOWNWARD, set p->size to size. + Set new fields base_offset and full_size. + (combine_temp_slots): Use new fields base_offset and full_size instead + of slot and size. + + * loop.c (loop_number_exit_count): New global variable. + (loop_optimize): Allocate space for it. + (find_and_verify_loops, mark_loop_jump): Set it. + (strength_reduce, check_dbra_loop): Use loop_number_exit_count + instead of loop_number_exit_labels. + * loop.h (loop_number_exit_count): Declare it. + * unroll.c (find_splittable_{regs,givs}, final_[bg]iv_value): Use + loop_number_exit_count instead of loop_number_exit_labels. + (reg_dead_after_loop): Check loop_number_exit_count, and fail + if the count doesn't match loop_number_exit_labels. + + * cse.c (cse_insn): Ifdef out code that pre-truncates src_folded. + + * sparc.md (sethi_di_sp64): Return null string at end. + + * function.h (struct function): Add stdarg field. + * function.c (current_function_stdarg): New global variable. + (push_function_context_to): Save it. + (pop_function_context_from): Restore it. + (assign_parms): Set it. + (init_function_start): Clear it. + * output.h (current_function_stdarg): Declare it. + * i960.md: Modify all patterns which handle stores to memory to also + check current_function_varargs and current_function_stdarg. + + * reorg.c (fill_simple_delay_slots): When trying to take instruction + from after the branch, don't continue past target label. Local + variables passed_label and target_uses are no longer necessary. + +Thu Jul 13 19:30:04 1995 Jeff Law (law@snake.cs.utah.edu) + + * pa.c (output_bb): Fix error in long backwards branch with + nullified delay slot. + +Thu Jul 13 19:26:13 1995 Jim Wilson + + * expmed.c (SHIFT_COUNT_TRUNCATED): Use #ifdef not #if. + +Mon Jul 10 20:16:44 1995 Paul Eggert + + * cccp.c (rescan): Don't address outside of array when + preprocessing C++ comments. + +Mon Jul 10 20:05:46 1995 Michael Meissner + + * rs6000.c (expand_block_move): Remove #if 0 conditionals + against using larger block moves. + + * t-rs6000 (EXTRA_PARTS): Copy milli.exp to release dir. + (milli.exp): Copy to build dir from machine dependend dir. + +Mon Jul 10 20:03:29 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * arm.md (matcher for (shiftable_op (cond-exp) (reg))): If + shiftable_op is minus, then subtract from zero when cond fails. + +Mon Jul 10 19:58:26 1995 John F. Carr + + * sparc.h (SELECT_SECTION): Use TREE_CODE_CLASS instead of directly + referencing tree_code_type. + +Mon Jul 10 19:54:31 1995 Jim Wilson + + * protoize.c (reverse_def_dec_list): Delete const qualifiers from + local variables, and delete casts which were casting away const. + +Mon Jul 10 19:14:39 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-lang.c (finish_file): Add missing parm to start_function call. + + * jump.c (jump_optimize): Pass outer_code arg to rtx_cost. + + * varasm.c (assemble_name, bc_assemble_integer): Call + bc_emit_labelref with proper args. + + * function.c (setjmp_args_warning): Remove bogus arg. + +Mon Jul 10 18:20:54 1995 Fergus Henderson (fjh@cs.mu.oz.au) + + * gcc.c (p{fatal,error}_with_name, perror_exec): Quote filename. + +Mon Jul 10 18:12:51 1995 Gran Uddeborg (uddeborg@carmen.se) + + * i386/iscdbx.h (STARTFILE_SPEC): Handle -Xp. + +Wed Jul 5 02:42:17 1995 Per Bothner (bothner@spiff.gnu.ai.mit.edu) + + * cpphash.h (enum node_type): Remove unneeded and non-standard + forward declaration. + +Sat Jul 1 20:15:39 1995 Jim Wilson + + * mips/t-mips, mips/t-mips-gas (MULTILIB_*, LIBGCC, INSTALL_LIBGCC): + Delete. + + * sparc/sol2.h (LINK_SPEC): Revert March 16 change. Do not add -R + for each -L. + + * collect2.c (libcompare): Verify that file name extensions are valid. + Put files with invalid extensions last in the sort. + + * integrate.c (integrate_decl_tree): Set DECL_ABTRACT_ORIGIN before + pushdecl call for local variables. + +Sat Jul 1 08:13:38 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * cpplib.c (output_line_command): If not emitting #line directives + delay returning until after adjust_position has been called. + + * arm.md (mov{si,sf,df}cc): Call gen_compare_reg to generate + the condition code register. + +Sat Jul 1 06:55:09 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (decode_field_reference): New parm PAND_MASK. + (unextend): New parm MASK. + (fold_truthop): Pass new parms to decode_field_reference and unextend. + + * va-alpha.h (__va_tsize): Use __extension__ to avoid warning + on use of `long long'. + + * expr.h (NO_DEFER_POP): Do any pending stack adjusts. + + * recog.c (register_operand): Disallow subreg of reg not allowed to + change size. + +Thu Jun 29 05:51:57 1995 Jeff Law (law@snake.cs.utah.edu) + + * pa.md (reload addsi3): New pattern to avoid reload lossage + with register eliminations. + + * pa.c (output_cbranch): When checking for a jump to the given + insn's delay slot, handle the case where JUMP_LABEL for the + given insn does not point to the first label in a series of + labels. + (output_bb, output_dbra, output_movb): Likewise. + +Wed Jun 28 18:04:56 1995 Jeff Law (law@snake.cs.utah.edu) + + * pa.h (PIC_OFFEST_TABLE_REGNUM_SAVED): Define to %r4. + (CONDITIONAL_REGISTER_USAGE): Make it fixed when compiling + PIC code. + (INIT_EXPANDERS): Delete. + * pa.c (hppa_save_pic_table_rtx): Delete variable. + (hppa_expand_prologue): For PIC generation, copy the PIC + register into a fixed callee register at the end of the + prologue of non-leaf functions. + * pa.md (call expanders): Reload the PIC register from the + fixed callee saved register. Don't try to save the PIC + register before the call. + +Wed Jun 28 18:01:14 1995 Stan Cox (coxs@dg-rtp.dg.com) + + * m88k/dguxbcs.h (ASM_SPEC): Removed -h flag. + * m88k/dgux.h (ASM_SPEC): Likewise. + +Wed Jun 28 17:01:58 1995 David Edelsohn + + * rs6000.c (processor_target_table): Remove CPU name synonyms. + * rs6000.h (CPP_SPEC): Likewise. + * rs6000/sysv4.h (CPP_SPEC): Likewise. + (ASM_SPEC): Likewise. + * rs6000/sysv4le.h (CPP_SPEC): Likewise. + * rs6000/eabile.h (CPP_SPEC): Likewise. + * rs6000/powerpc.h (CPP_SPEC): Likewise. + (ASM_SPEC): Set assembler target according to compiler target. + * rs6000/aix3newas.h (CPP_SPEC): Likewise. + (ASM_SPEC): Likewise. + * rs6000/aix41.h (CPP_SPEC): Likewise. + (ASM_SPEC): Likewise. + +Wed Jun 28 16:25:53 1995 Gran Uddeborg (uddeborg@carmen.se) + + * i386/x-isc3 (INSTALL_HEADERS_DIR): Delete; done by configure. + +Wed Jun 28 16:10:47 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * xm-rs6000.h (alloca): Extern decl added for non-GNU compiler. + +Wed Jun 28 11:31:30 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cpplib.c (progname): Remove definition from here. + + * final.c (final_scan_insn): Fix error in last change. + + * rtlanal.c (reg_set_p_1): Now static; add extra parm. + + * stmt.c: Delete redundant forward decls. + (expand_anon_union_decl): Correctly call expand_decl. + + * toplev.c (strip_off_ending): Strip off any ending; don't + pretend we know what valid endings are. + + * svr4.h (ASM_OUTPUT_SECTION_NAME): Don't crash if DECL is null. + + * rs6000.md ({load,store}_multiple): Don't use indirect_operand + in define_insn; use explicit MEM of register_operand instead. + +Tue Jun 27 11:42:56 1995 Stephen L Moshier + + * i386/i386.c (print_operand, case `J'): Use jns for GE and js for + LT. + +Tue Jun 27 07:58:55 1995 Jason Merrill + + * expr.c (expand_expr, TARGET_EXPR): Only use original_target + if !ignore. + +Tue Jun 27 07:27:26 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (fold_truthop): Commute unextend and convert on + l_const and r_const. + + * c-common.c (decl_attributes, case A_CONSTRUCTOR, A_DESTRUCTOR): + Set TREE_USED. + + * final.c (final_scan_insn): Don't call alter_cond unless + condition is on cc0. + + * stmt.c (expand_asm_operands): Handle input operands that may not + be in a register. + +Mon Jun 26 19:23:05 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * arm/lib1funcs.asm (L_dvmd_tls): Renamed from L_divmodsi_tools. + * arm/t-semi (LIB1ASMFUNCS): Rename _dvmd_tls from _divmodsi_tools. + +Mon Jun 26 19:18:06 1995 Jim Wilson + + * unroll.c (find_splittable_regs): When completely unrolling loop, + check for non-invariant initial biv values. + +Mon Jun 26 19:13:54 1995 Gran Uddeborg + + * configure (i[345]86-*-isc*): Fix misspelled "rfile" to "ifile". + +Mon Jun 26 18:58:22 1995 Mike Stump + + * expr.c (expand_expr, case COND_EXPR): Protect the condition from + being evaluated more than once. + (do_jump, case TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR): Likewise. + +Mon Jun 26 18:52:36 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * fixincludes (string.h): Fix return value for mem{ccpy,chr,cpy,set} + and str{len,spn,cspn} on sysV68. + +Mon Jun 26 06:54:50 1995 Michael Meissner (meissner@cygnus.com) + + * i386/osfrose.h (LONG_DOUBLE_TYPE_SIZE): Go back to making long + double == double. + +Thu Jun 22 19:14:41 1995 Pat Rankin (rankin@eql.caltech.edu) + + * make-cc1.com (if DO_LINK): Skip c-parse.* processing when + only relinking. + (gas_message): Update to reflect current version, and give + a different message if/when no version of gas is found.xo + +Thu Jun 22 18:52:37 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * arm/lib1funcs.asm (___modsi3): Correctly set SIGN register for + modulo involving negative numbers. + +Thu Jun 22 18:32:27 1995 Uwe Seimet (seimet@chemie.uni-kl.de) + + * xm-atari.h (HZ): Now 100 and don't define if already defined. + +Thu Jun 22 18:26:12 1995 Jeffrey A Law (law@snake.cs.utah.edu) + + * calls.c (expand_call): Correctly handle returning BLKmode + structures in registers when the size of the structure is not + a multiple of word_size. + * stmt.c (expand_return): Likewise. + + * pa-gux7.h (LIB_SPEC): Undefine before redefining. + * pa-hpux.h (LIB_SPEC): Likewise. + * pa-hpux7.h (LIB_SPEC): Likewise. + + * genmultilib: Work around hpux8 /bin/sh case bug. + + * pa.h (LIB_SPEC): Define to avoid -lg. + +Thu Jun 22 18:19:09 1995 Jason Merrill + + * expr.c (expand_expr, TARGET_EXPR): Use original_target. + + * collect2.c (locatelib): Fix parsing of LD_LIBRARY_PATH. + +Thu Jun 22 18:15:54 1995 Paul Eggert + + * configure: Create an empty Makefile.sed first, to work + around a Nextstep 3.3 bug. + +Thu Jun 22 18:03:44 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Makefile.in (STAGESTUFF): Add stamp-crt. + (crtbegin.o, crtend.o): Now depend on stamp-crt. + (stamp-crt): New rule, to actually build crt{begin,end}.o. + + * collect2.c (main): Unlink export_file before we return. + +Thu Jun 22 14:25:56 1995 Michael Meissner (meissner@cygnus.com) + + * rs6000.h (STRIP_NAME_ENCODING): Store NAME and strlen(NAME) into + local variables; cast result of alloca to avoid compiler warnings. + +Tue Jun 20 18:25:29 1995 Douglas Rupp (drupp@cs.washington.edu) + + * alpha/config-nt.sed, i386/config-nt.sed: Edit to add + a missing $(exeext) for CCCP. + +Tue Jun 20 18:18:00 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * protoize.c (default_include): Use name and two ints to be + compatible with definition of INCLUDE_DEFAULTS. + +Mon Jun 19 19:24:29 1995 Ted Lemon + + * mips/netbsd.h (ASM_DECLARE_FUNCTION_NAME): Don't emit function label. + +Mon Jun 19 18:34:55 1995 Jason Merrill + + * fixincludes: Don't define wchar_t under C++. + +Mon Jun 19 17:12:41 1995 Paul Eggert + + * cccp.c (collect_expansion): Work around enum bug in vax + ultrix 4.3 pcc. + * tree.c (simple_cst_equal): Likewise. + +Mon Jun 19 16:53:00 1995 Douglas Rupp (drupp@cs.washington.edu) + + * winnt/spawnv.c: New file. + +Mon Jun 19 16:30:29 1995 Glenn Brown + + * caller-save.c (save_call_clobbered_regs): If AUTO_INC_DEC, mark + register indicated by REG_INC notes as live so they will be saved. + +Mon Jun 19 16:21:12 1995 Jeffrey A Law (law@snake.cs.utah.edu) + + * pa.h (PRINT_OPERAND_ADDRESS, case LOW_SUM): Fix logic bug + in last change. + +Mon Jun 19 14:11:49 1995 Jim Wilson + + * integrate.c (integrate_decl_tree): Only set DECL_ABSTRACT_ORIGIN + if the decl returned by pushdecl is the one we started with. + + * mips.h (current_function_name): Delete declaration. + (ASM_DECLARE_FUNCTION_NAME): Don't set current_function_name. + * gnu.h (ASM_DECLARE_FUNCTION_NAME): Likewise. + * mips.c (current_function_decl): Delete declaration. + (function_prologue): New variable fnname. Use it instead of + current_function_name. + (function_epilogue): Likewise. + +Mon Jun 19 13:13:15 1995 Richard Kenner + + * alpha.h (ASM_OUTPUT_ASCII): Always reset line count when + starting new line. + + * scan-decls.c (scan_decls): Fix typo when resetting PREV_ID_START. + + * i386/config-nt.sed, alpha/config-nt.sed: Change version to 2.7.1. + +Mon Jun 19 13:06:14 1995 DJ Delorie (dj@delorie.com) + + * msdos/top.sed: Support new build variables. + * msdos/configur.bat: Make options.h and specs.h. + Change realclean to maintainer-clean. + +Fri Jun 16 06:54:03 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Version 2.7.0 Released. + + * obstack.c: Always enable this code for now. + + * alpha.c (alpha_builtin_saveregs): Use ptr_mode and conversions + when need so works for both OSF and NT. + * va-alpha.h (__va_tsize): Round to long long not long. + +Thu Jun 15 17:54:52 1995 Bdale Garbee + + * configure (a29k-*-coff): Synonym for a29k-*-udi. + +Thu Jun 15 17:51:21 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * function.c (assign_parms): Do all conversions in CONVERSION_INSNS. + +Thu Jun 15 17:36:49 1995 Michael Meissner + + * reg-stack.c (record_reg_life): Call record_reg_life_pat with 0 + for douse argument so that USE's created to mark variables within + blocks don't get marked as set. + +Thu Jun 15 06:28:15 1995 Dennis Glatting (dennisg@CyberSAFE.COM) + + * configure: Change one sed command to work around m68k-next bug. + +Wed Jun 14 22:14:39 1995 Jason Merrill + + * collect2.c (main): Don't turn off auto_export because of -g. + (main): Ignore the argument to -o. + + * alpha.h (LINK_SPEC): Don't pass -init __main anymore. + * alpha/osf12.h (LINK_SPEC): Ditto. + * mips/iris5.h (LINK_SPEC): Ditto. + + * collect2.c (main): Place o_file after an initial .o (like crt0.o). + If we have LD_INIT_SWITCH, use init and fini functions for + executables, too. Specify the unique function names. + (write_c_file_stat): Fix the case of destructors but no constructors. + Don't include the generic-named functions for executables. + (write_c_file): If we have LD_INIT_SWITCH, always use + write_c_file_stat. + + * collect2.c (main): Also add _GLOBAL__D? to export list. + + * ginclude/iso646.h: Do nothing if compiled as C++. + +Wed Jun 14 17:39:10 1995 Roland McGrath (roland@gnu.ai.mit.edu) + + * c-common.c (format_char_info, case 'm'): Set type to void. + (check_format_info): If type is void, ignore operand. + +Wed Jun 14 17:04:10 1995 Paul F. Kunz (Paul_Kunz@SLAC.Stanford.EDU) + + * expr.c (expand_builtin_apply_args): Put back original + register save and restore order. + +Wed Jun 14 16:56:22 1995 Michael Meissner + + * rs6000/eabi.h (INVOKE__main): Define, so __eabi is called after + main's arguments are saved. + + * rs6000.c (output_prolog): Don't call __eabi here, let + compiler call it after the arguments to main are saved. + (output_{prolog,epilog}): Don't use functions under V.4 to save + and restore floating point registers. + +Wed Jun 14 16:52:12 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k/mot3300.h (PCC_BITFIELD_TYPE_MATTERS): Defined. + +Wed Jun 14 16:48:53 1995 Jerry Frain (jerry@tivoli.com) + + * Makefile.in (stage[1-4]): Correctly link `as', `ld', and `collect2'. + +Wed Jun 14 05:52:04 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * objc-act.c (hack_method_prototype): Set DECL_CONTEXT of parms. + + * expmed.c (emit_store_flag): Always set LAST. + + * c-decl.c (start_function): New parameter for attributes. + * c-tree.h (start_function): Likewise. + * c-lang.c (finish_file): Pass extra parm to start_function. + * objc-act.c (build_module_descriptor, really_start_method): Likewise. + * c-parse.in (fndef, nested_function, notype_nested_function): + Likewise. + + * function.c (assign_parms): Use convert_to_mode instead of + gen_lowpart when converting incoming parm. + +Tue Jun 13 19:10:32 1995 Richard Kenner + + * rs6000.md (decrement_and_branch): Finish last fix; update matching + constraint. + +Tue Jun 13 18:32:51 1995 Torbjorn Granlund + + * fold-const.c (fold): When converting a COND_EXPR to an ABS_EXPR, + get the types right for ABS_EXPR to work. + +Mon Jun 12 17:09:55 1995 Michael Tiemann (tiemann@axon.cygnus.com) + + * reorg.c (fill_simple_delay_slots): Set MAYBE_NEVER according to + code of TRIAL_DELAY, not TRIAL. + +Mon Jun 12 15:02:37 1995 Doug Evans + + * configure: Restore code to make ld symlink if ! use_collect2. + + * gcc.c (link_command_spec): Undo patch of May 11. + -nostdlib implies -nostartfiles again. + * dsp16xx.h (CROSS_LINK_SPEC): Likewise. + * i386/freebsd.h (LINK_SPEC): Undo patch of May 24. + Don't pass "-e start" if nostdlib. + * i386/sun.h (LINK_SPEC): Likewise. + * m68k/sun2o4.h (LINK_SPEC): Likewise. + * m68k/sun3.h (LINK_SPEC): Likewise. + * m68k/vxm68k.h (LINK_SPEC): Likewise. + * mips/netbsd.h (LINK_SPEC): Likewise. + * config/netbsd.h (LINK_SPEC): Likewise. + * rs6000/mach.h (LINK_SPEC): Likewise. + * sparc.h (LINK_SPEC): Likewise. + * sparc/vxsparc.h (LINK_SPEC): Likewise. + + * gcc.c (link_command_spec): New argument -nodefaultlibs. + +Sun Jun 11 20:47:53 1995 Stephen L Moshier (moshier@world.std.com) + + * Makefile.in (fix-header.o): Depends on xsys-protos.h. + +Sun Jun 11 15:07:58 1995 Tim Carver (timc@ibeam.intel.com) + + * reload1.c (emit_reload_insns): Don't call HARD_REGNO_NREGS + on psuedo when clearing reg_last_reload_reg. + +Sun Jun 11 14:07:05 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md ({add,sub}di{_mem,3}): Patterns merged. + +Sun Jun 11 13:43:26 1995 Torbjorn Granlund + + * m68k.md (cmpdi matcher): Set cc_status before returning. + + * config/xm-freebsd.h (DONT_DECLARE_SYS_SIGLIST): Define. + +Sun Jun 11 13:38:49 1995 Jason Merrill + + * fixincludes (math.h): Keep declaration of abs on HPUX. + +Sun Jun 11 12:31:42 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * stor-layout.c (variable_size): Do nothing if SIZE is constant. + + * stmt.c (expand_asm_operands): See if output operand permits + register. If not, mark output addressable, call expand_operand + on it, and give error if not MEM. + + * function.c (assign_parms): Handle promotions of both + passed and nominal modes separately and insert needed conversions. + (promoted_input_arg): Return 0 if nominal and passed modes differ. + + * stmt.c (all_cases_count, case INTEGER_TYPE): Fix typo in checking + for integer bounds. + +Sat Jun 10 08:55:25 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * libgcc2.c (_floatdidf): Correctly set float sizes. + + * c-decl.c (c_decode_option, case "-Wall"): Don't set extra_warnings. + + * Makefile.in (cpplib.o, fix-header.o): Update dependencies. + (cpperror.o, cppexp.o, cpphash.o): New rules, to show .h dependencies. + +Fri Jun 9 18:06:10 1995 Doug Evans + + * cse.c (cse_basic_block): Fix test for whether block ends with a + barrier. Return next insn, not 0, if block ends in a barrier. + +Fri Jun 9 17:58:29 1995 Paul Eggert + + * fold-const.c (lshift_double): Replace `&' with `%' to fix typo. + ([lr]shift_double): Truncate shift count only if SHIFT_COUNT_TRUNCATED. + Remove unnecessary `count >= prec' test. + + * cexp.y (left_shift): Ignore integer overflow. + + * cexp.y (skip_evaluation): New variable. + (&&, ||, ?:): Increment it in unevaluated subexpressions. + (/, %, integer_overflow): Suppress diagnostics if skip_evaluation != 0. + (yyerror): Clear skip_evaluation. + +Fri Jun 9 17:49:05 1995 Torbjorn Granlund + + * m68k.md (tstdi): Rewrite. + +Fri Jun 9 17:28:55 1995 Per Bothner + + * scan-decls.c (scan_decls): Handle declarations with + multiple comma-separated declarators. + +Thu Jun 8 19:16:12 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * arm.md (mov[sd]f expands): Don't allow fp constants in pseudos + when TARGET_SOFT_FLOAT. + +Thu Jun 8 19:11:43 1995 Jim Wilson + + * expmed.c (store_split_bit_field): When adjust arg in + BYTES_BIT_ENDIAN case, use number of bits in arg for MEM operands + and BITS_PER_WORD for other operands. + (extract_fixed_bit_field): Undo last change. + + * unroll.c (verify_addresses): New function. + (find_splittable_givs): Use it instead of memory_address_p. + +Thu Jun 8 18:58:18 1995 Torbjorn Granlund + + * expmed.c (expand_divmod): Always check result of emit_store_flag. + +Thu Jun 8 12:02:34 1995 David D Zuhn (zoo@armadillo.com) + + * cpplib.c (cpp_push_buffer): Include filename in error message. + +Thu Jun 8 11:53:45 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * function.c (assign_parms): Don't call promote_mode on arg + unless PROMOTE_FUNCTION_ARGS defined. + + * rs6000.md (decrement_and_branch): Ensure label is operand 0. + + * rs6000.md (aux_truncdfsf2): New pattern. + (movsf): Use it instead of invalid SUBREG and truncdfsf2. + + * varasm.c (assemble_name): Disable warn_id_clash around + get_identifier call. + +Wed Jun 7 17:22:25 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * configure (gdb_needs_out_file_path): New variable. + (m68k-motorola-sysv): Set gdb_needs_out_file_path if not using gas. + (.gdbinit): If gdb_needs_out_file_path is set, add a 'dir' command + for $(out_file). + +Wed Jun 7 17:17:19 1995 Torbjorn Granlund + + * fold-const.c (fold): When folding `<' type nodes, make true_value + and false_value have correct types. + +Wed Jun 7 05:06:42 1995 Jason Merrill + + * collect2.c (COFF scan_prog_file): Use the AIX duplicate entry. + +Tue Jun 6 18:43:09 1995 Jeffrey A Law (law@snake.cs.utah.edu) + + * pa.h (FUNCTION_ARG_CALLEE_COPIES): Define. + +Tue Jun 6 18:21:18 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (expand_expr, case PLACEHOLDER_EXPR): Consider two types + identical if their TYPE_MAIN_VARIANTs are the same. + + * c-decl.c (start_decl): Set DECL_COMMON before calling + decl_attributes. + + * a29k.c (print_operands): Cast args to bcopy to char *. + + * c-decl.c (duplicate_decls): Don't clear DECL_CONTEXT of + new decl if it is a function. + +Tue Jun 6 17:57:44 1995 Eberhard Mattes (mattes@azu.informatik.uni-stuttgart.de) + + * gcc.c (do_spec_1, case 'g'): Handle %O as suffix if MKTEMP_EACH_FILE. + +Tue Jun 6 17:53:05 1995 Michael Meissner + + * rs6000.c (expand_block_move): Update source and destination pointers + inside the loop moving the bytes, not outside. + +Tue Jun 6 14:58:37 1995 Andreas Schwab + + * m68k.h (CONDITIONAL_REGISTER_USAGE): Don't mark pic reg as fixed. + * m68k.c (finalize_pic): Emit USE insn at start and end of function. + +Tue Jun 6 13:46:57 1995 Jim Wilson + + * sh.c (print_operand): Check for annulled branches. + (output_movedouble): Handle SUBREG addresses. + (output_branch): Handle annulled branches. + (sh_expand_prologue): Correct number of saved registers for + varargs functions. + * sh.h: Add some comments. + * sh.md: Add some comments. Cleanup formatting. + (type attribute): Add pstore and call. + (return define_delay): Reorganize to make clearer. + (call/sfunc define_delay): Define. + (cbranch define_delay): Define to have annul-true delay slot. + (subsi3): Use arith_reg_operand for operand 2. + (shift patterns): Use const_int_operand instead of immediate_operand + for shift counts. + (push): Add pstore constraint case. + (movsi_i): Move t/z constraint pair to the front of the list. + (calli, call_valuei): Add "call" attribute. + +Mon Jun 5 19:23:13 1995 Jim Wilson + + * sched.c (attach_deaths): In last change, use find_reg_note instead + of find_regno_note. + +Mon Jun 5 19:17:31 1995 Tom Quiggle (quiggle@lovelace.engr.sgi.com) + + * mips/iris5.h (MACHINE_TYPE): Say "IRIX 5.x", not "5.0". + (NO_DOLLAR_IN_LABEL): Undefine. + * mips.h (sdb_begin_function_line): New declaration. + (PUT_SDB_FUNCTION_END): New definition. + +Mon Jun 5 18:56:10 1995 Michael Meissner + + * rs6000.c (expand_block_move): Don't do block moves where we clobber + fixed numbers of regs, instead move just 1-8 bytes at a time. + + * Makefile.in (STAGESTUFF): Copy files produced by -da and + -save-temps to the stage subdirectories. + +Mon Jun 5 08:18:46 1995 Torbjorn Granlund + + * combine.c (reg_dead_at_p): When scanning backwards, stop at BARRIER. + + * m68k.c (print_operand): Handle 'R' for registers. + * m68k.md (cmpdi): Rewrite to avoid bogus matching constraints. + + * optabs.c (expand_binop): In last change, don't defererence TARGET + if it is 0. + + * pa.md (movsicc): Use MATCH_DUP for operand 4 and 5. + +Mon Jun 5 08:14:56 1995 Jeffrey A Law (law@cs.utah.edu) + + * pa.c (hppa_encode_label): Allocate stuff on permanent_obstack + rather than via malloc. + + * c-common.c (decl_attributes): Fix typo in size passed to alloca. + +Mon Jun 5 08:10:55 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.md: Use "some_operand" for patterns valid only during + reload and meant to handle adding more PLUS operators during + register elimination. + +Mon Jun 5 07:31:53 1995 Stephen L Moshier (moshier@world.std.com) + + * cse.c (simplify_unary_operation, case FLOAT, UNSIGNED_FLOAT): + Truncate to requested mode. + +Sat Jun 3 22:08:51 1995 Jim Wilson + + * sched.c (attach_deaths): Don't add a REG_DEAD note if a REG_UNUSED + note is already present. + +Sat Jun 3 18:36:57 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * pa.h (hppa_builtin_saveregs): Add declaration. + +Sat Jun 3 18:11:26 1995 Jason Merrill + + * Makefile.in (scan-decls.o): Depends on cpplib.h. + +Fri Jun 2 19:23:47 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * optabs.c (expand_binop): Don't use non-REG TARGET in 2-word case. + +Thu Jun 1 19:30:30 1995 Tor Egge (tegge@flipper.pvv.unit.no) + + * m88k.h (RETURN_POPS_ARGS): New argument. + * m88k/dolphin.ld: Added start of comment. + +Thu Jun 1 19:12:28 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * configure (a29k-*-bsd*): Fix typo in last change. + +Thu Jun 1 18:51:53 1995 Jim Wilson + + * expmed.c (extract_fixed_bit_field): For REG case, compute total_bits + from mode instead of assuming BITS_PER_WORD. + +Thu Jun 1 18:34:31 1995 Michael Meissner + + * rs6000.h (FIXED_R13): Default to 0. + ({FIXED,CALL_USED}_REGISTERS): Use FIXED_R13 for register 13. + * sysv4.h (FIXED_R13): Define to be 1. + +Wed May 31 20:57:26 1995 Torbjorn Granlund + + * m68k.md ([su]mulsi3_highpart): Pass correct number of arguments to + const_uint32_operand. + * m68k.c (const_uint32_operand): Reject negative numbers. + + * expmed.c (expand_mult_highpart): Use wide_op1 for all multiplies. + (expand_divmod): Undo Nov 12 change. Instead, add special case + for division by MIN_INT in signed TRUNC_DIV_EXPR case. + +Wed May 31 20:44:21 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (one_cmpldi2): New pattern. + ({a,l}shrdi{3,_const}): Allow 63 as shift count. + +Wed May 31 14:56:31 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * varasm.c (assemble_start_function, assemble_variable): + Make sure first_global_object_name is in permanent obstack. + + * reload1.c (alter_reg): Clean up setting of RTX_UNCHANGING_P + when making a MEM. + + * reorg.c (struct resources): New field unch_memory. + (CLEAR_RESOURCES, mark_target_live_regs, dbr_schedule): Clear it. + (mark_{referenced,set}_resources, redundant_insn): Set it. + (fill_simple_delay_slots): Likewise. + (resource_conflicts_p): Test it. + + * unroll.c (copy_loop_body): Fix typo in call to sets_cc0_p. + + * integrate.c (output_inline_function): Don't call expand_function_end. + + * calls.c (prepare_call_address): Only call use_reg on + static_chain_rtx if it is a REG. + + * configure (a29k-*-bsd*): Use t-a29k. + * t-a29k: New file. + * a29k/t-a29kbare (LIBGCC1_TEST): New null definition. + * a29k/t-vx29k (LIBGCC1_TEST): Likewise. + +Wed May 31 14:17:42 1995 Jeffrey A Law (law@snake.cs.utah.edu) + + * configure (hppa*-*-bsd*): Do not run fixincludes. + (hppa*-*-osf*): Likewise. + (hppa*-*-lites*): Likewise. + + * pa.h (PRINT_OPERAND_ADDRESS): Use "RR'" rather than "R'" for + symbolic addresses. + * pa.md (symbolic HIGH patterns): Likewise. + (symbolic LO_SUM pattern): Likewise. + +Wed May 31 14:11:53 1995 Michael Meissner + + * rs6000.md (all movstri recognizers): Eliminate updating the pointers. + * rs6000.c (expand_block_move): Don't pass argument of # bytes to + increment pointers by to movstrsi expanders. + + * rs6000.c (rs6000_override_options): Fix typo with -mstring handling. + + * rs6000.h (TARGET_SWITCHES): Set MASK_STRING_SET explicitly + if -mno-string, so that it can override the processor default. + +Wed May 31 07:31:53 1995 Jason Merrill + + * c-common.c (truthvalue_conversion, BIT_AND_EXPR): Make sure that + the result has boolean_type_node. + +Tue May 30 19:03:21 1995 J.T. Conklin + + * stddef.h: Undefine _BSD_XXX_T_ if _GCC_XXX_T is defined on BSD + Net/2 derived systems. + +Tue May 30 08:17:37 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (decrement_and_branch_until_zero): Operand 0 constraint + changed from "+g" to "+d*am". + (similar anonymous HImode pattern): Likewise. + + * m68k.md (tstdi): Use tst/subx #0 instead of neg/negx. + Allow "a" and ">" for operand 0. + +Mon May 29 19:24:43 1995 Niklas Hallqvist (niklas@appli.se) + + * m68k.md (addsi_lshrsi_31): Use match_dup, not constraint "1", + for matching inputs. + +Mon May 29 12:39:58 1995 Allen Briggs + + * i386/isc.h ({STARTFILE,LIB,CPP}_SPEC): Handle -Xp like -posix. + * i386/x-isc3 (X_CFLAGS): Add -Xp. + +Mon May 29 12:28:41 1995 J.T. Conklin (jtc@cygnus.com) + + * configure (sparc-*-netbsd): Add missing asterisk at end. + +Mon May 29 08:55:48 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * combine.c (recog_for_combine): New parm PADDED_SCRATCHES; set it. + (try_combine): Accumulate number of scratches and update max_scratch. + (simplify_set): Add extra parm to recog_for_combine. + + * romp.md (call): Put USE for r0 in CALL_INSN; call call_internal + to emit insn. + (call_internal): New name for anonymous call. + (call_value, call_value_internal): Likewise. + + * winnt/xm-winnt.h: Protect most definitions with #ifndef. + * alpha/xm-winnt.h: Include alpha/xm-alpha.h, then winnt/xm-winnt.h. + (POSIX): Undefine. + * xm-alpha.h: Don't include alloca.h for winnt. + +Sun May 28 18:34:01 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * configure: Make sed commands more uniform. + + * Makefile.in: Properly use $(srcdir) for files that have it + in their reference as a target of a rule. + (libgcc1.a): Add missing RANLIB_TEST use. + + * stmt.c (expand_computed_goto): Call do_pending_stack_adjust. + +Sun May 28 18:08:41 1995 Torbjorn Granlund + + * m68k.md (divmodhi4, udivmodhi4): Use "dmsK" for operand 2. + +Fri May 26 17:01:22 1995 Paul Eggert + + * fixincludes: Fix bogus recursive in NEWS-OS 4.0C. + +Fri May 26 08:02:14 1995 Michael Meissner (meissner@cygnus.com) + + * c-typeck.c (initializer_constant_valid_p): For the CONSTRUCTOR + case, if the type is a record, recurse, just like for unions. + +Thu May 25 07:56:14 1995 Paul Eggert + + * fixincludes: Add `sel', `tahoe', `r3000', `r4000' to the + list of pre-ANSI symbols that need to be surrounded with __ __. + Allow white space between `#' and `if' when looking for lines to patch. + + * objc/sarray.h (PRECOMPUTE_SELECTORS, struct soffset): + Use #ifdef __sparc__, not sparc. + + * m68k.md (addsi_lshrsi_31, ashldi_const, ashrdi_const, lshrdi_const): + Replace `mov' with `move'. + +Thu May 25 07:35:37 1995 Allen Briggs + + * libgcc2.c (L_eh, i386): Remove in-line comments in assembly + code--the '#' character is not valid for the SYSV as. + +Thu May 25 07:28:54 1995 Pat Rankin (rankin@eql.caltech.edu) + + * Makefile.in (BC_ALL): Restore it from May 22 change; vms uses it. + (STAGESTUFF): Use it. + +Thu May 25 07:11:56 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.c (alpha_emit_set_const): Don't call expand_binop for + other than add if SImode and can't create pseudos. + +Wed May 24 21:38:24 1995 Jim Wilson + + * sched.c (reemit_notes): New function. + (schedule_block): Call reemit_notes twice. Reorganize code for + handling SCHED_GROUP_P insns, so that reemit_notes works. + + * sh/sh.c (shiftcosts, genshifty_op): Add SH3 support. + * sh/sh.md (ashlsi3, lshrsi3): Add SH3 support. + (ashlsi3_d, ashrsi3_d, lshrsi3_d): New patterns for SH3. + (ashrsi2_31): Remove r/!r constraint. + +Wed May 24 17:00:47 1995 Jason Merrill + + * tree.c (type_list_equal): Call simple_cst_equal before checking + types. + +Wed May 24 16:49:49 1995 Douglas Rupp (drupp@cs.washington.edu) + + * Makefile.in (libgcc2.a): Handle case of separate srcdir. + +Wed May 24 16:22:01 1995 Paul Eggert + + * configure: Define $(MAKE) if `make' doesn't. + +Wed May 24 15:50:51 1995 Doug Evans + + * dsp16xx.h (CROSS_LINK_SPEC): ENDFILE_SPEC moved to -nostartfiles. + * i386/freebsd.h (LINK_SPEC): Don't pass "-e start" if nostartfiles + rather than nostdlib. + * i386/sun.h (LINK_SPEC): Likewise. + * m68k/sun2o4.h (LINK_SPEC): Likewise. + * m68k/sun3.h (LINK_SPEC): Likewise. + * m68k/vxm68k.h (LINK_SPEC): Likewise. + * mips/netbsd.h (LINK_SPEC): Likewise. + * config/netbsd.h (LINK_SPEC): Likewise. + * rs6000/mach.h (LINK_SPEC): Likewise. + * sparc.h (LINK_SPEC): Likewise. + * sparc/vxsparc.h (LINK_SPEC): Likewise. + + * m88k/m88k.h (FUNCTION_ARG_BOUNDARY): Use GET_MODE_BITSIZE. + +Wed May 24 15:44:04 1995 Jason Merrill + + * fold-const.c (fold): Make sure that a folded TRUTH_NOT_EXPR + retains the same type. + + * c-common.c (truthvalue_conversion): Also accept TRUTH_NOT_EXPR. + +Wed May 24 15:41:51 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cplus-dem.c (strstr, strncmp, strlen): Remove declarations. + + * tree.c (type_list_equal, simple_cst_list_equal, index_type_equal): + Check for simple_cst_equal return value of -1. + +Wed May 24 10:05:24 1995 Michael Meissner + + * libgcc1-test.c (start, _start): Provide declarations, so that + the GNU linker doesn't give a warning message about defaulting the + start address. + + * rs6000/sysv4.h (STRIP_NAME_ENCODING): Redefine back to the + original defination, rather than the defination used in rs6000.h. + (ASM_OUTPUT_SOURCE_LINE): Use STRIP_NAME_ENCODING. + * rs6000.h (STRIP_NAME_ENCODING): Skip leading '*'. + + * rs6000.h (MASK_STRING_SET, TARGET_STRING_SET): Add target + flags bit for whether -mstring was actually used. + (TARGET_SWITCHES): Add MASK_STRING to all power targets. Set + MASK_STRING_SET for -mstring and -mno-string. + (TARGET_DEFAULT): Add MASK_STRING. + + * rs6000.c (rs6000_override_options): Add MASK_STRING to + all power targets. Make an explicit -mstring/-mno-string override + the -mcpu=processor default. + + * rs6000/eabile.h (CPP_SPEC): Copy from sysvle.h to provide the + appropriate little endian defaults. + + * rs6000/sysv4.h (ASM_OUTPUT_SOURCE_LINE): Use assemble_name to + output the canonical name. + +Wed May 24 01:21:15 1995 Jason Merrill + + * rs6000.h (STRIP_NAME_ENCODING): Define. + (RS6000_OUTPUT_BASENAME): Use it. + +Tue May 23 19:54:21 1995 Doug Evans + + * gcc.c (link_command_spec): Move ENDFILE_SPEC from -nostdlib + to -nostartfiles. + +Tue May 23 17:01:50 1995 Jim Wilson + + * alpha.md (negsi2-2): Change output pattern to #. + + * mips.c (embedded_pic_offset): Output RTL to initialize + embedded_pic_fnaddr_rtx. + (mips_finalize_pic): Delete. + * mips.h (mips_finalize_pic): Delete declaration. + (FINALIZE_PIC): Delete. + (INIT_EXPANDERS): Clear embedded_pic_fnaddr_rtx. + * mips.md (get_fnaddr): Add = to output contraint. + + * sh.c (shift_amounts): Correct entry for shifts by 29. + * sh.md (sett): New pattern. + (movsi_i): Change source constraint for move to T reg to be 'z'. + + * mips/ecoff.h (STARTFILE_SPEC): Define to null string. + * mips/elfl.h, mips/elfl64.h: Correct typo in comment. + + * mips/elflorion.h, mips/elforion.h (MIPS_CPU_DEFAULT): Delete. + * mips.c (override_options): Delete #ifdef MIPS_CPU_DEFAULT code. + Add #ifdef MIPS_CPU_DEFAULT_STRING code before the first + mips_cpu_string test. + +Tue May 23 07:22:36 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * romp.c (hash_rtx): Avoid warning on int-to-pointer conversion. + (output_fpops): Cast args to bcopy to char *. + + * cpplib.c (initialize_builtins): Add missing parm to timestamp call. + + * Makefile.in (install-libobjc): Don't depend on libobjc.a. + + * c-parse.in: Objc shift/reduce conflicts now 48. + (parm): Use setspecs/restore here. + (parmlist_or_identifiers): Not here. + +Mon May 22 19:30:30 1995 Doug Evans + + * h8300.md (movsf_h8300h): Add missing post-inc case to constraints. + +Mon May 22 14:38:36 1995 Michael Meissner + + * rs6000.c (rs6000_override_options): Do SUBTARGET_OVERRIDE_OPTIONS + here. + * rs6000.h (OVERRIDE_OPTIONS): Not here. + + * rs6000.c (expand_block_move): Handle moves without string + instructions by generating a series of loads and stores. + (output_prolog): Support -mno-toc on V.4 and eabi systems. + + * rs6000/sysv4.h (TARGET_SWITCHES): Add -mtoc and -mno-toc. + (SUBTARGET_OVERRIDE_OPTIONS): Add some warnings for incompatible + switches. + (TOC_SECTION_FUNCTION): Make -mno-toc like -mrelocatable in that + we don't put the minimal toc pointer in the global toc section. + (LINK_SPEC): Use -oformat to set link output format, not -m. + + * rs6000/t-eabigas (MULTILIB_OPTIONS, MULTILIB_DIRNAMES): Build + libgcc.a variants with -mno-toc support. + * rs6000/t-ppcgas (MULTILIB_OPTIONS, MULTILIB_DIRNAMES): Ditto. + +Mon May 22 07:10:52 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cplus-dem.c (mystrstr): Replacement for strstr. + + * configure: Split up long sed command. + * Makefile.in (SYMLINK): Deleted; unused. + (oldobjext): Deleted; no longer used. + (FLAGS_TO_PASS): Include objext and exeext. + (STAGESTUFF, protoize.o, unprotoize.o): Use $(objext), not .o. + (test_protoize_simple, compare{,3}, gnucompare{,3}): Likewise. + (STAGESTUFF, specs, gcc-cross, collect2): Add missing $(exeext). + (libgcc1.null, libgcc[12].a, stage[1-4]): Likewise. + (xgcc, cc1, cc1obj, enquire): Use $@ instead of filename for -o value. + (collect2, mips-tfile, mips-tdump, gen*): Likewise. + (bi-arity, bi-opcode, bi-opname, cccp, cppmain): Likewise. + (protoize, unprotoize, gen-protos, fix-header): Likewise. + (crtbegin.o, crtend.o): Don't use -o; move output to proper + filename (using objext) instead. + (BI_ALL, BC_ALL, bytecode): Deleted; unused. + (bi-*.o, cexp.o, stamp-{proto,fixinc}): Remove unneeded $(srcdir). + (getopt{,1}.o, SYSCALLS.c.X): Likewise. + (install-driver): New target. + (install-normal): Depend on it. + (install-common): Don't depend on xgcc. + (maketest): Deleted; no longer used. + (stage[1-4]): Use name collect-ld, not real-ld. + (risky-stage[1-4]): Use stage[1-4] as dependencies; don't copy. + * alpha/config-nt.bat, i386/config-nt.bat: Make {,h,t}config.h + and tm.h by writing a single #include line. + Update way specs.h and options.h are written. + * alpha/config-nt.sed, i386/config-nt.sed: Set new variables + into Makefile. + Build winnt.obj. + Edit CCCP definition. + * alpha/x-winnt, i386/x-winnt (oldobjext): Deleted. + Add rules for .c.obj, .adb.obj, and .ads.obj. + (LIB2FUNCS_EXTRA, spawnv.o): New rules. + * i386/x-winnt (objext): Now .obj, not .o. + + * gcc.c (HAVE_OBJECT_SUFFIX): New macro. + (process_command): Convert x.o to x.foo for OBJECT_SUFFIX of ".foo". + (do_spec_1): Avoid shadow variable "i" and always use for loop var. + + * c-decl.c (finish_decl_top_level): Removed; no longer used. + * objc-act.c: Numerous formatting changes. + (NULLT): Deleted; all uses changed to NULL_TREE. + (get_{static,object}_reference, objc_add_static_instance): + Use push_obstacks instead of saving obstacks manually. + (build_{selector,class}_reference_decl): Likewise. + (build_objc_string_decl, build_protocol_reference): Likewise. + (comp_{method,proto}_with_proto): Likewise. + (create_builtin_decl, synth_module_prologue): Set DECL_ARTIFICIAL + for internal objects. + (build_{selector,class}_reference_decl, add_objc_decls): Likewise. + (generate_objc_symtab_decl, build_module_descriptor): Likewise. + (build_protocol_reference): Likewise. + (build_objc_string_decl, synch_forward_declarations): Likewise. + Delete call to end_temporary_allocation. + (generate_static_references, generate_strings): Likewise. + (build_selector_translation_table, generate_category): Likewise. + (generate_{ivars,protocol}_list, build_protocol_reference): Likewise. + (build_objc_string_object): If next_runtime, put everything in + permanent obstack. + (objc_add_static_instance): Use build_decl instead of start_decl + and finish_decl_top_level. + (build_{class_reference,objc_string}_decl): Clear DECL_CONTEXT. + (start_class): Exit with FATAL_EXIT_CODE, not 1. + (add_objc_decls): Don't set DECL_IN_SYSTEM_HEADER. + + * tree.c (valid_machine_attribute): Handle attribute on + pointer-to-function types. + +Sun May 21 17:16:37 1995 J. T. Conklin + + * mips/netbsd.h (HAVE_STRERROR): Remove. + * mips/xm-netbsd.h: New file. + * mips/t-mips-netbsd: Deleted. + * configure (mips-dec-netbsd): Use xm-netbsd.h and t-libc-ok. + +Sun May 21 17:16:37 1995 Arne H. Juul (arnej@pvv.unit.no) + + * mips/netbsd.h: Use __start as entry point. Ifdef some + paths on CROSS_COMPILE. + +Sun May 21 08:39:26 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-parse.in (datadef, fndef, ivar_decl, mydecls): + Restore declspec_stack since setspecs is used. + (parmlist_or_identifiers): Use setspecs before parsing parms + and restore after parsing parms. + +Sun May 21 01:04:52 1995 Jeffrey A. Law + + * pa.c (hppa_encode_label): New variable "permanent" to + where/how memory is allocated for the new label. All + callers changed. + +Sat May 20 16:53:30 1995 Mike Meissner + + * rs6000.md (insv, extz): Fail if the structure is QI or HI reg to + avoid paradoxical subreg's being created in RTL phase, which uses + SImode to load from memory if structure is later moved to stack. + +Sat May 20 06:44:59 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (udivmodhi4): Output "divu" instead of "divs". + +Sat May 20 06:11:32 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * reload.c (push_reload): Don't reload inside a SUBREG + when SUBREG_WORD is nonzero. + + * c-decl.c (shadow_tag_warned): Don't warn about useless keyword + if in system header file. + + * tree.c (simple_cst_equal): Don't look at language-specific + nodes since we don't know what's in them. + + * cpperror.c: #include config.h before any other .h file. + * collect2.c: Likewise. + + * i386/config-nt.bat: Add missing ^M on two lines. + Add case for Fortran; fix typo in Ada case. + * alpha/config-nt.bat: Add case for Fortran; fix typo in Ada case. + + * m68k/t-next (LIBGCC1, CROSS_LIBGCC1): Make not, not "libgcc1.null". + (OTHER_FIXINCLUDES_DIRS, LIMITS_H_TEST): Delete from here. + * m68k/x-next (OTHER_FIXINCLUDES_DIR, LIMITS_H_TEST): Move to here. + +Fri May 19 19:30:20 1995 Stan Cox (gcc@dg-rtp.dg.com) + + * crtstuff.c: Added reference to INIT_SECTION_PREAMBLE for systems that + do something which must be undone prior to __do_global_ctors. + +Fri May 19 19:27:08 1995 Alan Modra + + * i386/linux-aout.h (CPP_SPEC): Add defines for -fPIC. + * i386/linux-oldld.h (CPP_SPEC): Likewise. + +Fri May 19 17:46:28 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * collect2.c (strstr): Deleted. + * cplus-dem.c (strstr): Define ifndef POSIX. + +Fri May 19 11:16:51 1995 Per Bothner + + * cpplib.c (collect_expansion): Don't escape '@' inside string. + +Fri May 19 06:59:21 1995 Pat Rankin (rankin@eql.caltech.edu) + + * vmsconfig.com (process_objc_lib, configure_makefile): New routines. + (bc_all.list, ./vax.md, objc-objs.opt, objc-hdrs.list): New files + created at config time. + (bc_all.opt, ./md.): No longer created. + * make-cc1.com: Handle revised filenames from vmsconfig.com; + (DO_OBJCLIB): New variable, plus code to compile objc/*.{c,m}. + +Wed May 17 16:15:31 1995 Torbjorn Granlund + + * i960.c (i960_output_ldconst): New code for XFmode. + Also, move SFmode code to immediately after DFmode code. + (S_MODES, D_MODES): Handle XFmode. + (XF_MODES): Was TF_MODES, handle XFmode instead of TFmode. + (hard_regno_mode_ok): Replace TFmode with XFmode. + (i960_output_long_double): New function. + + * i960.h (DATA_ALIGNMENT): Define. + (ROUND_TYPE_ALIGN): Align XFmode scalars at 128 bit boundaries. + (ROUND_TYPE_SIZE): Round up the size of XFmode objects to 128 bits. + (CONST_DOUBLE_OK_FOR_LETTER_P): Use CONST0_RTX and CONST1_RTX + so that all FP modes are recognized. + (ASM_OUTPUT_LONG_DOUBLE): Define. + + * i960.md: Change all TFmode patterns to have XFmode. + (movxf recognizer, frame version): Use movt, ldt, and stt. + (movxf recognizer, non-frame version): Delete. + (extenddfxf2): Delete * before f constraint. + (extendsfxf2): Likewise. + +Wed May 17 17:53:35 1995 Jim Wilson + + * unroll.c (unroll_loop): Increment copy_start_luid if copy_start + is loop_start. + +Wed May 17 17:44:57 1995 Lee Iverson + + * fold-const.c (invert_truthvalue, case CLEANUP_POINT_EXPR): New case. + +Tue May 16 18:51:16 1995 Michael Meissner + + * rs6000/rs6000.h (TARGET_SWITCHES): Add -mstring to enable string + instructions, and -mno-string to disable them. + (MOVE_MAX): Don't test TARGET_MULTIPLE anymore. + (MAX_MOVE_MAX): Set to 8, not 16. + (expand_block_move): Add declaration. + + * rs6000/rs6000.c (expand_block_move): New function to expand + block moves when -mstring is used. + + * rs6000/rs6000.md (movti): Use TARGET_STRING, not TARGET_MULTIPLE. + (load_multiple, store_multiple): Ditto. + (string insns): Add 8, 6, 4, 2, and 1 register variants for using + the native string instructions if -mstring. + + * rs6000/sysv4.h (CPP_SPEC): If little endian, define + _LITTLE_ENDIAN and set littleendian assertion. If big endian, + define _BIG_ENDIAN and set bigendian assertion. + * rs6000/sysv4le.h (CPP_SPEC): Copy from sysv4.h, and change + default to little endian. + + * rs6000/rs6000.c (override_options): Check for -mmultiple and + -mstring on little endian systems here. + * rs6000/sysv4.h (SUBTARGET_OVERRIDE_OPTIONS): Don't do the check + here. + +Tue May 16 18:36:41 1995 Douglas Rupp (drupp@cs.washington.edu) + + * alpha.c: Changed WINNT to _WIN32. + * alpha/config-nt.bat, i386/config-nt.bat: Added commands to + generate specs.h and options.h. + * i386/config-nt.sed: Changed link32 to link. + * winnt/ld.c (main): Removed call to free. + * configure.bat: Added line to echo usage on invalid input. + * gcc.c (fix_argv): Removed call to free. + * gcc.c, getpwd.c, protoize.c, sdbout.c: Changed WINNT to _WIN32. + * toplev.c: Likewise. + +Tue May 16 18:04:47 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * toplev.c (pfatal_with_name, fatal_io_error, vfatal): + Use FATAL_EXIT_CODE instead of magic number. + * cccp.c, cpplib.c, cpplib.h: Use FATAL_EXIT_CODE instead + of FAILURE_EXIT_CODE. + * fix-header.c, gen-protos.c: Likewise. + * cpperror.c, cppmain.c: Likewise. + Include config.h #ifndef EMACS. + * xm-alpha.h, xm-rs6000.h, xm-vms.h (FAILURE_EXIT_CODE): Remove. + +Tue May 16 17:46:57 1995 Adam Fedor + + * objc/archive.c (__objc_write_class): Write class version. + (__objc_write_selector, objc_{write,read}_selector): Handle null + selector. + + * objc/sarray.h (struct sarray): Make capacity size_t. + * objc/sarray.c (sarray_realloc): Make array index variables size_t. + +Tue May 16 06:59:08 1995 Paul Eggert + + * dsp16xx.c (print_operand_address): Fix misspellings in messages. + * i370/mvs.h (FUNCTION_PROFILER): Likewise. + * mips-tdump.c (type_to_string): Likewise. + * print-tree.c (print_node): Likewise. + + * protoize.c (edit_fn_definition): Fix mispelled local `have_flotsam'. + + * objc/sendmsg.c (__objc_init_install_dtable): Fix misspelling + in name of local label `already_initialized'. + + * winnt/winnt.h (STDC_VALUE): Was misspelled. + + * m68k/ccur-GAS.h (FUNCTION_BOUNDARY): Was misspelled. + + * 1750a.h (DEFAULT_PCC_STRUCT_RETURN): Was misspelled. + +Mon May 15 23:41:25 1995 Jeffrey A. Law + + * pa.h (ASM_OUTPUT_EXTERNAL_LIBCALL): Make sure to encode section + info for all libcalls. + +Mon May 15 20:58:00 1995 Jason Merrill + + * collect2.c (strstr): Define ifndef POSIX. + + * defaults.h (SUPPORTS_WEAK): Provide default. + * aoutos.h, sparc/sunos4.h: Don't support weak symbols. + * netbsd.h, svr4.h, i386/freebsd.h, i386/osfrose.h, + m88k/m88k.h: Define ASM_WEAKEN_LABEL instead of WEAK_ASM_OP. + * c-pragma.h: Check ASM_WEAKEN_LABEL instead of WEAK_ASM_OP. + HANDLE_PRAGMA_WEAK is never defined in a tm.h file. + * c-decl.c (duplicate_decls): Propagate DECL_WEAK. + * tree.h (DECL_WEAK): New macro. + (tree_decl): Add weak_flag. + * varasm.c (assemble_start_function): Declare the symbol weak if + appropriate. + (assemble_variable): Ditto. + (assemble_alias): Ditto. Mark the decl as written. + (declare_weak): Check for weak declaration after definition. + Set DECL_WEAK. + (weak_finish): Use ASM_WEAKEN_LABEL. + * libgcc2.c: The C++ free-store management functions are weak + aliases on targets that always support them. + +Mon May 15 19:01:43 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * configure (out_object_file): New variable; put value in Makefile. + * Makefile.in (out_object_file): Use in place of aux-output.o. + + * fold-const.c (const_binop): Don't pass OVERFLOW to force_fit_type + if type is unsigned. + +Mon May 15 18:48:26 1995 Paul Eggert + + * install.sh (transformbasename): Fix misspelling. + + * tahoe.h (CHECK_FLOAT_VALUE): Fix misspelling of OVERFLOW parameter. + + * i386.h (VALID_MACHINE_{DECL,TYPE_ATTRIBUTE): Fix typo. + + * fx80.h (CHECK_FLOAT_VALUE): Fix misspelled use of parameter. + + * a29k.c (spec_reg_operand): Fix misspelling of `default:'. + +Mon May 15 18:36:41 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.md (b{eq,ne,ge,lt}0_di): Fixed for non-MOTOROLA syntax. + * m68k/xm-mot3300.h (alloca): Extern decl added for non-GNU compiler. + +Mon May 15 13:14:29 1995 Per Bothner + + * cppexp.c (cpp_reader): Test for '#' (start of assertion) *after* + skipping hspace, not before. + +Mon May 15 08:13:54 1995 Pat Rankin (rankin@eql.caltech.edu) + + * vmsconfig.com: Construct options.h and specs.h to #include + all "*/lang-{options|specs}.h" files found. + +Sun May 14 21:32:49 1995 Doug Evans + + * alpha/alpha.md (movsicc, case NE): Don't generate unrecognizable + insn. + (movdicc, case NE): Likewise. + +Sun May 14 15:44:54 1995 Jim Wilson + + * unroll.c (unroll_loop): Make local_regno have size + max_reg_before_loop. Don't do local register optimization if + copy_end has no INSN_LUID. + +Sun May 14 10:38:23 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * objc-act.c (start_method_def): Mark _self as possibly unused. + + * configure: Create specs.h and options.h from */lang-specs.h + and */lang-options.h. + Set lang_specs_files and lang_options_file variables in Makefile. + * Makefile.in (lang_{specs,options}_files): New variables. + (gcc.o): Depends on $(lang_specs_files). + (toplev.o): Depends on $(lang_options_file); merge two dep lists. + (distclean): Remove spes.h and options. + * gcc.c (default_compilers): Remove entries for Ada, C++, Chill, + and Fortran; #include specs.h instead. + * toplev.c (lang_options): Remove entries for Ada, C++, and Fortran; + include options.h instead. + +Sat May 13 23:11:21 1995 DJ Delorie + + * configure (i[345]86-go32-msdos, i[345]86-*-go32): New targets. + +Sat May 13 10:58:38 1995 Jim Wilson + + * loop.c (record_giv): When computing replaceable, use + back_branch_in_range_p instead of looking for branches to named + labels. + * loop.h (back_branch_in_range_p): Declare. + * unroll.c (back_branch_in_range_p): No longer static. + +Sat May 13 06:47:11 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * combine.c (simplify_shift_count, case LSHIFTRT): Don't merge + shifts of different modes if first is any right shift. + +Sat May 13 05:39:09 1995 Richard Earnshaw (rearnsha@armltd.co.uk) + + * configure (arm-semi-aout): New configuration. + * config.sub: Add support for semi-hosted ARM. + * arm/t-semi, arm/semi.h: New files. + +Fri May 12 21:51:22 1995 Doug Evans + + * flow.c (find_basic_blocks): Only perform n_basic_blocks sanity + check on first pass, and on second pass ensure it has the correct + value. + +Fri May 12 19:23:11 1995 Jim Wilson + + * c-typeck.c (build_binary_op): Warn when ~unsigned is compared + against unsigned, and type promotions result in an unexpected + answer. + +Fri May 12 19:10:21 1995 Roland McGrath + + * configure (*-*-gnu*): Always use ELF; set tm_file=${cpu_type}/gnu.h. + * config/i386/gnu.h: Contents replaced with old i386/gnuelf.h. + * config/i386/gnuelf.h: File removed. + +Fri May 12 17:29:57 1995 Ken Raeburn (raeburn@cygnus.com) + + * m68k/lb1sf68.asm (__IMMEDIATE_PREFIX__): Default to #. + (IMM): New macro. + (all code): Use IMM macro instead of hardcoding # for immediate + operands. + +Fri May 12 16:52:10 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * m68k.c (output_scc_di): New function. + (extend_operator) : Allow DImode target. + * m68k.h (HARD_REGNO_MODE_OK): Don't allow d7/a0 as DImode reg pair. + * m68k.md (tstdi, cmpdi, addsi_lshrsi_31, ashldi_extsi): New patterns. + (extendqidi2, extendhidi2, extendsidi2): Allow "general_operand" + instead of "register_operand" 0. + (adddid_sexthishl32, subdid_sexthishl32, subdi_dishl32): Likewise. + (adddi_dilshr32): Operand 0 constraint changed from "ro" to "do"; + Code generation fixed. + (adddi_mem, subdi_mem): Fixed for "<" and ">" operand 0. + (adddi3, subdi3): Operand 2 constraint changed from "ao" to "*ao" + (ashldi_sexthi, ashrdi_const32): Allow only "register_operand" + instead of "general_operand" 0. + (ash[lr]di_const, ash[lr]di3): Allow also 8 and 16 as shift count. + (subreg1ashrdi_const32): Pattern deleted. + (subreghi1ashrdi_const32, subregsi1ashrdi_const32): New pattern. + (lshrsi_31): New implementation. + (scc0_di, scc_di, beq0_di, bne0_di, bge0_di, blt0_di): New patterns. + +Fri May 12 16:50:49 1995 Jeffrey A. Law + + * pa.md (bb patterns): Fix bugs in length computation exposed by + recent branch shortening and genattrtab changes. + +Fri May 12 16:22:27 1995 Ken Raeburn + + * cccp.c (enum node_type): Add T_IMMEDIATE_PREFIX_TYPE. + (special_symbol): Handle it; emit value of IMMEDIATE_PREFIX. + (IMMEDIATE_PREFIX): Default to empty string. + (initialize_builtins): Install __IMMEDIATE_PREFIX__ builtin, + parallel to __REGISTER_PREFIX__. + +Fri May 12 14:40:03 1995 Pat Rankin (rankin@eql.caltech.edu) + + * cccp.c: #if VMS, don't define `stat' macro to be VMS_stat. + Compare enums explicitly to 0 to work around VAX C bug. + (do_include): Cast alloca's value. + + * make-cc1.com (bc_loop): Process comma-separated list rather + than space-separated one; restore .h suffix stripped by vmsconfig; + (loop1): More robust handling of directory prefix on file names. + * vmsconfig.com (TPU makefile.in): Reorganize and reformat code. + Make generated .opt files have more consistent format (all comma + separated, excess whitespace eliminated); + (additional_compiler): New routine. + (process_makefile): Use it to handle cc1plus via cp/Make-lang.in. + +Fri May 12 13:35:07 1995 Doug Evans + + * arm.h: Replace ARM_REG_PREFIX with REGISTER_PREFIX. + Replace ARM_COMMENT_CHAR with ASM_COMMENT_START. + (REGISTER_PREFIX): Define. + (USER_LABEL_PREFIX, LOCAL_LABEL_PREFIX): Define. + (SECONDARY_OUTPUT_RELOAD_CLASS): Handle DFmodes only if + TARGET_HARD_FLOAT. + (PREDICATE_CODES): Add soft_df_operand. + * arm.c: Replace ARM_REG_PREFIX with REGISTER_PREFIX. + Replace ARM_COMMENT_CHAR with ASM_COMMENT_START. + (arm_asm_output_label): Use USER_LABEL_PREFIX. + (soft_df_operand): New function. + * arm.md (movsicc): New pattern. + (movsfcc, movdfcc, *movsicc_insn, *movsfcc_hard_insn): Likewise. + (*movsfcc_soft_insn, *movdfcc_insn): Likewise. + (*movdf_soft_insn): Rewrite. + (movsi matcher): Fix typo in type attribute. + +Fri May 12 10:25:40 1995 Michael Meissner (meissner@cygnus.com) + + * i386.h (TARGET_RTD): Use MASK_RTD, not MASK_REGPARM. + (TARGET_SWITCHES): Add -m{,no-}align-double switch. + (TARGET_OPTIONS): Add -mregparm= switch to set number of registers + to use for passing arguments. Add -malign-loops= switch to set + the alignment for loops. Add -malign-jumps= switch to set the + alignment for code that is jumped to. Add -malign-functions= + switch to set the initial alignment of functions. + (TARGET_REGPARM): Delete, in favor of -mregparm= + (TARGET_SWITCHES): Delete -mregparm, add -mdebug-arg switches. + (RETURN_POPS_ARGS): Call i386_return_pops_args to do the real work. + (VALID_MACHINE_DECL_ATTRIBUTE): Define as function call. + (VALID_MACHINE_TYPE_ATTRIBUTE): Define as function call. + (COMP_TYPE_ATTRIBUTES): Define as function call. + (REGPARM_MAX): Maximum number of regs to use for passing arguments. + (CUMULATIVE_ARGS): Make this a structure, not an int. + (INIT_CUMULATIVE_ARGS, FUNCTION_ARG{,_ADVANCE}): Call function. + (FUNCTION_ARG_PARTIAL_NREGS): Likewise. + (MAX_CODE_ALIGN): Maximum value to align loops/jumps to. + (BIGGEST_ALIGNMENT): Return 64 if -malign-double, 32 otherwise. + (ASM_OUTPUT_ALIGN_CODE): Use value of -malign-jumps= switch. + (ASM_OUTPUT_LOOP_ALIGN): Use value of -malign-loops= switch. + (toplevel): Declare all new functions and external variables added + in i386.c. + + * i386.c (i386_regparm_string, i386_regparm): New variables + for -mregparm= switch to set the number of registers to use for + passing arguments. + (i386_align_loops_string, i386_align_loops): New variables for + -malign-loops= switch to set alignment to use for loops. + (i386_align_jumps_string, i386_align_jumps): New variables for + -malign-jumps= switch to set alignment to use for labels that are + jumped to. + (override_options): Support new switches. + (i386_valid_decl_attribute_p): New function to validate decl + specific attributes. Presently returns 0. + (i386_valid_type_attribute_p): New function to validate type + specific attributes. Recognize "stdcall", which says function + with fixed numbers of arguments is responsible for popping stack, + "cdecl", which says to use the normal C calling sequence, even if + -mrtd is used, and "regparm", which specifies the number of + registers to use for passing arguments. + (i386_comp_type_attributes): New function, to validate whether + attributes are compatible. + (i386_return_pops_args): New function, to return whether or not + the function pops its argument list or not, taking into account + -mrtd, and the stdcall/cdecl attributes. + (init_cumulative_args): Rewrite as a function, taking variable + argument functions, and regparm support into account. + (function_arg{,_advance,_partial_nreg}): Likewise. + (print_operand): Support %J, to print appropriate jump insn. + + * i386.md (decrement_and_branch_until_zero): Define pattern, + so that loops that count down to zero, don't have an unneeded + compare after the decrement. Add a general insn recognizer for + add to a value and compare against zero. + + * i386/go32.h, i386/winnt.h (VALID_MACHINE_DECL_ATTRIBUTE): + Delete, code folded into the mainline. + (RETURN_POPS_ARGS): Likewise. + + * i386/winnt.h (ENCODE_SECTION_INFO): The stdcall attribute is now + stored on the type field, rather than the decl. + + * i386/gas.h (ASM_OUTPUT_ALIGN_CODE, ASM_OUTPUT_LOOP_ALIGN): Use + i386_align_{loops,jumps} variables to do alignment. + * i386/osfrose.h, i386/svr3dbx.h: Likewise. + +Fri May 12 12:48:19 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * stor-layout.c (layout_type, case ARRAY_TYPE): Compute length using + MAX of length and zero if sizetype signed and neither bound constant. + + * i386/gnuelf.h, i386/linux-oldld.h, i386/lynx-ng.h, i386/v3gas.h: + Use <...> in #include instead of "...". + * m68k/lynx-ng.h, sparc/lynx-ng.h: Likewise. + + * c-parse.in (myparm): Handle attributes. + * objc-act.c (unused_list): New variable. + (build_tmp_function_decl): Call push_parm_decl with new format. + (start_class): Initialize unused_list. + (start_method_def): Call push_parm_decl with new format and + mark _cmp as possibly unused. + + * combine.c (simplify_shift_const): Don't change SHIFT_MODE + for LSHIFTRT either. + + * unroll.c (unroll_loop): Don't move reg if used in copy_end and + that is a JUMP_INSN. + +Fri May 12 12:31:37 1995 Doug Evans + + * arm/lib1funcs.asm: New file. + +Fri May 12 11:52:03 1995 Kung Hsu + + * configure (a29k-*-vxworks*): New target. + * config.sub (vxworks29k): New alias. + * a29k/t-vx29k: New file. + * a29k/vx29k.h: New file. + +Fri May 12 11:17:28 1995 Jim Wilson + + * loop.c (check_dbra_loop): When reversing loop when + no_use_except_counting is false, there must be only one biv. + +Fri May 12 07:10:00 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * unroll.c (unroll_loop): Only use local_regno for pseudos. + + * genattrtab.c (write_test_expr, case MATCH_DUP): Use operands[N] + instead of JUMP_LABEL (which may not be set). + (walk_attr_value, case MATCH_DUP): Set must_extract. + + * c-parse.in: Adjust number of shift/reduce conflicts. + (parm): Support attributes. + * c-decl.c (push_parm_decl): Pass any attributes to decl_attributes. + +Fri May 12 00:36:26 1995 Per Bothner + + * cpplib.c (skip_quoted_string): Removed - no longer needed. + (skip_if_group): Use cpp_get_token instead of skip_quoted_string. + + * cpplib.h (struct cpp_reader): Remove start_line field. + Add multiline_string_line field. + + * cpplib.c (cpp_error_with_line, cpp_warning_with_line, + cpp_pedwarn_with_line): Take extra column number parameter. + (macroexpand, cpp_get_token): Fix reporting of unterminated strings. + (line_for_error): Removed - no longer needed. + +Fri May 12 02:21:34 1995 Jim Wilson + + * mips/svr4-t.h (MD_STARTFILE_PREFIX, MD_EXEC_PREFIX, + STARTFILE_SPEC, LINK_SPEC): Define. + * configure (mips-tandem-sysv4): Use t-mips not t-svr4. + +Thu May 11 19:18:54 1995 Per Bothner + + * cpplib.c (line_for_error): Make it work; add extra parameter. + (skip_quoted_string, cpp_get_token): Update calls to line_for_error. + (macroexpand): Remember initial line so we can report it if the + call is unterminated. Also, simplify error logic slightly. + (do_include): Cast alloca return value, to avoid pcc warning. + + * cppexp.c (parse_number): Cleanup some Cygnus crud for MPW. + +Thu May 11 21:35:23 1995 Torbjorn Granlund + + From Moshier: + * i960.c (i960_output_ldconst): Let split_double handle DImode. + (i960_print_operand): Use REAL_VALUE_TO_DECIMAL for decimal strings. + (i960_output_double, i960_output_float): Likewise; also change arg + VALUE from `double' to `REAL_VALUE_TYPE'. + +Thu May 11 21:09:25 1995 Per Bothner (bothner@wombat.gnu.ai.mit.edu) + + * cpperror.c (cpp_print_containing_files): Remove some + Cygnus-local stuff. + +Thu May 11 21:06:47 1995 Doug Evans + + * gcc.c (link_command_spec): Make -nostdlib no longer imply + -nostartfiles. + +Thu May 11 18:48:57 1995 Paul Eggert + + * c-common.c (convert_and_check): Don't diagnose overflow in constant + expression merely because conversion overflowed. + +Thu May 11 18:43:59 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-decl.c (grokdeclarator): Use PARM_FLAG to see if should + make PARM_DECL. + * c-parse.in (nested_function, notype_nested_function): + Allow old-style arg definitions (use xdecls). + + * c-decl.c (finish_struct): Properly update DECL_PACKED. + +Thu May 11 15:24:15 1995 Jason Merrill + + * fold-const.c (fold): Also fold CLEANUP_POINT_EXPRs into + TRUTH_*_EXPRs and into the first operand. + (operand_equal_for_comparison_p): Also make sure the second operand + is integral. + +Thu May 11 14:22:03 1995 Ted Lemon + + * config/mips/netbsd.h: New file. + * config/mips/t-mips-netbsd: New file. + * config/mips/x-netbsd: New file. + + * configure (mips-dec-netbsd*): Add entry. + + * mips.h (LOCAL_LABEL_PREFIX, USER_LABEL_PREFIX): Define. + (PUT_SDB_BLOCK_START, PUT_SDB_BLOCK_END, ASM_OUTPUT_LABEL_REF, + ASM_OUTPUT_INTERNAL_LABEL, ASM_GENERATE_INTERNAL_LABEL, + ASM_OUTPUT_ADDR_VEC_ELT, ASM_OUTPUT_ADDR_DIFF_ELT): Use them. + + * mips.c (mips_output_lineno): Use LOCAL_LABEL_PREFIX. + +Thu May 11 14:22:03 1995 Stan Cox (gcc@dg-rtp.dg.com) + + * dwarfout.c (output_decl): Don't output DIE for struct or union type + with no name or with ERROR_MARK for the fields. + +Thu May 11 06:36:34 1995 Michael Meissner (meissner@cygnus.com) + + * flow.c (mark_used_regs): If a SUBREG does not have a REG in the + SUBREG_REG position, recursively call mark_used_regs, instead of + segfaulting. + +Thu May 11 06:44:34 1995 Pat Rankin (rankin@eql.caltech.edu) + + * expr.c (do_jump, case EQ_EXPR, NE_EXPR): Fix typo for complex. + +Wed May 10 12:34:46 1995 Michael Meissner + + * configure: Add support for the little endian variant of the + PowerPC System V.4 and Eabi targets. If the GNU assembler was not + specified, don't build libgcc.a variants on the PowerPC systems + that use -mrelocatable, -mlittle, and -mbig. + + * genmultilib: For MULTILIB_MATCHES arguments, map question marks + into equal signs after spliting the left and right side of + equivalent options, to all support for options like: -mcpu=403. + + * rs6000/rs6000.md (rs6000_immed_double_const): New function that + is like immed_double_const, except that it reverses the two words + in the constant if the target is little endian. + + * rs6000/rs6000.md (floatsidf2): Use rs6000_immed_double_const, + not immed_double_const. + (floatunssidf2): Ditto. + + * rs6000/rs6000.h: Add declarations for all functions in rs6000.c. + + * rs6000/sysv4.h (TARGET_SWITCHES): Add -mlittle, -mlittle-endian, + -mbig, and -mbig-endian for bi-endian support. + (ASM_SPEC): Pass -mlittle/-mbig to the assembler if it was passed + to us. + (LINK_SPEC): If explicit little or big endian support was + requested, tell the GNU linker to use the appropriate target + format. + + * rs6000/t-eabi (MULTILIB_*): Build libgcc.a variants for software + floating point. Remove mrelocatable libgcc.a variant. + + * rs6000/t-eabigas: New file, cloned from t-eabi. Build + mrelocatable libgcc.a variant in addition to the other variants. + + * rs6000/t-ppc: New file, for PowerPC System V.4 support without + the GNU assembler. + + * rs6000/t-ppcgas: New file, for PowerPC System V.4 support with + the GNU assembler. + + * rs6000/eabile.h: New file, little endian eabi config file. + * rs6000/sysv4le.h: New file, little endian V.4 config file. + +Wed May 10 14:22:28 1995 Doug Evans + + * libgcc1-test.c (main_without__main): Renamed from `main'. + * Makefile.in (libgcc1-test): Tell the user to ignore warnings. + + * configure: Support --enable-foo, --disable-foo. + +Wed May 10 10:34:00 1995 Lee Iverson + + * unroll.c: Add declarations of static functions. + (unroll_loop): Renumber regs local to loop for each unrolled iteration. + +Wed May 10 08:27:03 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.c (alpha_set_emit_const): Cleanups to work properly + when run on 32-bit host. + + * configure: Instead of symlinking tm.h and {h,t,}config.h, + make them files that #include the proper file; pass to Makefile. + Pass out_file and md_file to Makefile instead of making symlinks. + * Makefile.in (out_file, md_file, tm_file, {build,host}_xm_file): + New symbols, to be overridden by configure. + (insn-*): Use $(md_file), not md. + (aux-output.o): Use $(out_file), not aux-output.c. + ($(MD_FILE)): Rework to use new conventions. + (gen*.o, bi-*.o): Depend on $(build_xm_file), not hconfig.h. + (scan.o, fix-header.o, scan-decls.o): Likewise. + (distclean): Adjust files removed for new convention. + +Tue May 9 19:26:42 1995 Jason Merrill + + * rs6000/rs6000.h (LIBGCC_SPEC): Do link with libgcc when -shared. + + * Makefile.in (STAGESTUFF): Add underscore.c. + (underscore.c): Rename temporary files to begin with 'tmp-' so that + they will be removed by 'make mostlyclean'. + +Tue May 9 19:19:55 1995 Mike Stump + + * toplev.c (lang_options): Add new flag -ffor-scope. + +Tue May 9 19:11:47 1995 Lee Iverson (leei@ai.sri.com) + + * objc/init.c (objc_init_statics): Fix missing part of last change. + +Tue May 9 18:25:34 1995 Richard Kenner + + * i386/gnu.h, i386/linux.h, i386/linux-aout.h, i386/lynx.h: + Use <...> in #include instead of "..." to avoid recursion. + * i386/netbsd.h, i386/xm-gnu.h, i386/xm-linux.h: Likewise. + * i386/xm-lynx.h, i386/xm-freebsd.h, i386/xm-netbsd.h: Likewise. + * m68k/lynx.h, m68k/netbsd.h, m68k/xm-lynx.h: Likewise. + * m68k/xm-netbsd.h, mips/gnu.h, ns32k/netbsd.h: Likewise. + * ns32k/xm-netbsd.h, rs6000/lynx.h, rs6000/xm-lynx.h: Likewise. + * sparc/lynx.h, sparc/netbsd.h, sparc/xm-lynx.h: Likewise. + * sparc/xm-netbsd.h, vax/netbsd.h, vax/xm-netbsd.h: Likewise. + +Tue May 9 15:52:05 1995 Michael Meissner + + * config.sub: Recognize powerpcle as the little endian varient of + the PowerPC. Recgonize ppc as a PowerPC variant, and ppcle as a + powerpcle variant. Convert pentium into i586, not i486. Add p5 + alias for i586. Map new x86 variants p6, k5, nexgen into i586 + temporarily. + +Tue May 9 15:43:27 1995 Jason Merrill + + * rs6000/rs6000.h (LINK_SPEC, LIB_SPEC): Don't mess with libg + if -shared. + * rs6000/aix41ppc.h (LINK_SPEC): Ditto. + + * rs6000/powerpc.h: Don't emit .extern directives. + +Tue May 9 14:08:09 1995 Jim Wilson + + * sh/lib1funcs.asm (__ashrsi3, __ashlsi3, __lshrsi3): Use .byte + instead of .word offsets in switch table. + +Tue May 9 11:44:47 1995 Jeremy Bettis + + * objc/sendmsg.c (__objc_send_initialize): Call superclass if object + does not implement +initialize. + +Tue May 9 02:44:16 1995 Jason Merrill + + * rs6000/xm-rs6000.h (COLLECT_EXPORT_LIST): Define if not + cross-compiling. + * rs6000/xm-mach.h: #undef COLLECT_EXPORT_LIST. + * rs6000/rs6000.h (COLLECT_SCAN_OBJECTS): Lose. + + * collect2.c (collect_exit): Unlink export_file. + (prefix_from_string): Broken out from prefix_from_env. + (prefix_from_env): Call it. + (main): Under AIX, recognize -bE: and -bexport:, and don't + automatically export everything if we see one. Otherwise, scan the + objects individually and add all their symbols to an export file to be + passed to the linker. + (write_export_file): New function. + (scan_prog_file): Ignore symbols starting with '.' + + * c-common.c (declare_hidden_char_array): Mark decl artificial. + +Mon May 8 18:13:57 1995 Adam Fedor + + * objc/init.c (_objc_load_callback): Add declaration. + (__objc_exec_class): Call _objc_load_callback after every Class + or Category is added. + * objc/objc-api.h (_objc_load_callback): Add declaration. + +Mon May 8 17:56:28 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (expand_expr, case INDIRECT_REF): Set RTX_UNCHANGING_P + if both TREE_READONLY and TREE_STATIC set. + + * c-typeck.c (convert_for_assignment): Don't give errors about + adding const or volatile unless both sides point to functions. + +Mon May 8 11:48:23 1995 Michael Meissner + + * configure: If ../ld/Makefile, symlink ../ld/ld.new to collect-ld, + not real-ld. Don't test for $use_collect2 any more. + +Sun May 7 17:52:23 1995 Jason Merrill + + * calls.c (expand_call): Improve -Winline warnings. + +Sun May 7 17:28:27 1995 DJ Delorie (dj@delorie.com) + + * configure.bat: Use "go32" instead of "msdos" for future expansion. + + * i386/go32.h: Add support for win32's stdcall functions. + + * configure.bat: Add ^M to end of each line. + * i386/config-nt.bat, alpha/config-nt.bat: Likewise. + +Sun May 7 02:12:26 1995 Jason Merrill + + * tree.h (DECL_ARTIFICIAL): New macro. + + * function.c (expand_function_end): Don't warn about unused + anonymous or artificial parms. + +Fri May 5 18:41:22 1995 Jim Meyering (meyering@comco.com) + + * configure: Fix typo in name of "maintainer-clean". + +Fri May 5 14:58:01 1995 Jeffrey A. Law + + * pa.c (emit_move_sequence): Force problematical constants + into memory during the reload pass when generating PIC. + +Fri May 5 13:30:33 1995 Doug Evans + + * objc/NXConstStr.m: NXConstantString.h renamed to NXConststr.h. + +Fri May 5 07:10:15 1995 Stephen L Moshier (moshier@world.std.com) + + * real.c (emdnorm, toe64, etoe64): Significand of Intel long double + denormals is shifted down one bit. + +Fri May 5 07:04:12 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-typeck.c (process_init_element): Don't clear_momentary if + constructor_stack is not empty. + + * objc/Makefile (SHELL): Now /bin/sh. + + * c-typeck.c (build_binary_op): Also warn about ordered + comparison of pointer with zero if -Wall. + + * expr.c (do_jump, case EQ_EXPR, NE_EXPR): Properly compare complex. + +Thu May 4 18:01:25 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * objc/Makefile: NXConstantString renamed to NXConstStr. + * objc/NXConstStr.m: Renamed from objc/NXConstantString.m. + * objc/NXConstStr.h: Renamed from objc/NXConstantString.h. + +Thu May 4 17:38:21 1995 J.T. Conklin + + * configure (vax-*-netbsd*): New configuration. + * vax/netbsd.h, vax/xm-netbsd.h: New files. + +Thu May 4 16:39:05 1995 Jason Merrill + + * collect2.c (main): Add check for 'collect-ld', just like + 'real-ld', except that old versions won't be looking for it in the + path. Don't look for 'real-ld' in the path anymore. Sigh. + + * collect2.c: #include demangle.h and obstack.h. + (obstack_chunk_alloc): Define. + (obstack_chunk_free): Define. + (generic): Don't define. Don't use. + (main): Initialize obstacks and demangling. + + * collect2.c (dump_file): Adjust space padding in output to + maintain tabulation with Solaris ld. Don't demangle if the + environment variable COLLECT_NO_DEMANGLE is set. + + * collect2.c (main): Redirect the output of the first link and + demangle it. Don't collect static c/dtors unless USE_COLLECT2 is + defined. Null-terminate the list of objects. + (dump_file): New function. + (file_exists): New function. + (collect_exit): Renamed from my_exit. Dump and remove the temporary + ld output file. + (collect_execute): Break out from fork_execute. Support redirection. + (fork_execute): Call it. + (fatal_perror, fatal, error): Make non-static. + (xcalloc, xmalloc): Don't use generic. + (xrealloc): Define. + (collect_wait): Break out for do_wait. Just return the exit status. + (do_wait): Call it. + + * collect2.c: Check SUNOS4_SHARED_LIBRARIES using #if, not #ifdef. + + * Makefile.in (collect2): Now uses cplus-dem.o and underscore.o. + (collect2.o): Pass MAYBE_USE_COLLECT2 to compile. + (underscore.c): Rules for creation. + + * cplus-dem.c, demangle.h: Copy from libiberty. + +Thu May 4 14:12:35 1995 Jim Wilson + + * sdbout.c (plain_type): Pass additional argument to plain_type_1. + (plain_type_1): New parameter level. Increment it when making + recursive calls. Force the type to void_type_mode before starting + a 7th level of recursion. + + * sh.c (general_movsrc_operand, general_movdst_operand): Delete + references to POST_DEC and PRE_INC. + * sh.h: Clean up whitespace, comments, etc. + (TARGET_SH, RTL_BIT, DT_BIT, C_BIT, R_BIT, TARGET_DUMP_RTL, + TARGET_DUMP_R, TARGET_CDUMP): Delete. + (TARGET_SWITCHES): Delete -mR, -mc, -mr options. + (CONST_DOUBLE_OK_FOR_LETTER_P): Delete 'G' contraint. + (FUNCTION_VALUE): Simplify. + (REG_OK_FOR_PRE_POST_P, IS_INDEX): Delete. + (BASE_REGISTER_RTX_P, INDEX_REGISTER_RTX_P): Rewrite to allow + SUBREGs. + (GO_IF_LEGITIMATE_INDEX): Delete unused REGNO argument. + (GO_IF_LEGITIMATE_ADDRESS): Use BASE_REGISTER_RTX_P instead of + REG_OK_FOR_PRE_POST_P. Don't accept PRE_INC or POST_DEC addresses. + (PREDICATE_CODES, PROMOTE_MODE): Define. + +Wed May 3 09:57:55 1995 Michael Meissner + + * rs6000/rs6000.md (non power abs insns): If not powerpc, use + sf/subfc instructions, not subf. + +Wed May 3 08:49:06 1995 Alan Modra + + * protoize.c (gen_aux_info_file): Use strerror #ifdef HAVE_STRERROR. + +Wed May 3 01:06:01 1995 Jeffrey A. Law + + * pa.c (output_call): Fix typo/thinko in last change. + (output_function_epilogue): Align the data section before + emitting deferred plabels. + + From Torbjorn: + * pa.c (before functions): Declare deferred_plabels and + n_deferred_plabels. + (output_call): When generating pic, don't use LP and RP. Use 32 bit + plabel instead. + (output_function_epilogue): Output plabels accumulated in output_call. + +Tue May 2 17:15:08 1995 Jeffrey A. Law + + * pa.c (hppa_expand_epilogue): Fix thinko in last change. + +Tue May 2 16:54:35 1995 Doug Evans + + * jump.c (jump_optimize, can_reach_end determination): A barrier can + follow the return insn. + +Tue May 2 12:39:55 1995 Mike Stump + + * fold-const.c (fold): Ensure that we don't alter the expression's + type when folding CLEANUP_POINT_EXPRs. + +Tue May 2 13:36:08 1995 Michael Meissner + + * expmed.c (emit_store_flag): When creating store flag + instructions from simpler parts, such as XOR, ABS, etc. do not + reuse pseudo registers if expensive optimizations, instead create new + pseudos for each insn result. + +Tue May 2 01:25:29 1995 Jeffrey A. Law + + * pa.c (hppa_expand_epilogue): Correctly handle restore of %rp + for functions with a stack size of exactly 8kbytes and no frame + pointer. + +Mon May 1 19:27:08 1995 Jim Wilson + + * sdbout.c (sdbout_one_type): Don't switch to text section if + in function with section attribute. + + * combine.c (combine_instrutions): Set subst_prev_insn to zero. + (try_combine, undo_all): Likewise. + (get_last_value): Return zero if subst_prev_insn set. + + * sparc.h (INIT_TARGET_OPTABS): Move INIT_SUBTARGET_OPTABS to end. + + * Makefile.in (install-dir): chmod a+rx all newly created directories. + + * expr.c (expand_expr, case SAVE_EXPR): Handle the case where + mode is VOIDmode. + +Fri Apr 28 15:39:38 1995 Per Bothner + + * cpplib.h (cpp_buffer): Note new escape combination "@ ". + * cpplib.c (macroexpand): Delete "@ " if stringifying. + (cpp_skip_hspace): Also skip "@ " if input buffer has_escapes. + (collect_expansion): Cleanup white-space handling. + (create_definition): Remove all leading spaces, not just first one. + (cpp_expand_to_buffer): Set has_escapes on resulting input buffer. + (macroexpand): Set output_escapes during whole function (and + specifically during calls of macarg). + (macroexpand): Set "@ " before and after expansion result. + (push_macro_expansion): Remove unneeded initial "@ ", not " ". + (cpp_get_token): Remove unneeded "@ " (not " ") at end of expansion. + (cpp_get_token): Handle "@ ". + + * cpplib.c (read_name_map): Add cpp_reader parameter. Access + map_list from former (instead of having it be static). + (open_include_file): Extra parameter (because of above changes). + (do_include, lookup_import): Update calls of open_include_file. + + * cpplib.c (do_include): Fix memory leak. + + * cpplib.c (delete_assertion): Also delete tokenlist. + (do_unassert): Don't delete tokenlist (handled by delete_assertion). + (cpp_cleanup): New function. Frees resources used by a cpp_reader. + * cpphash.c (cpp_hash_cleanup): New function. + (delete_macro): Enable commented-out code. + (file_cleanup): Free actual buffer. + + * cpplib.c (cpp_options): Add map_list. + + * cpplib.h (PARSE_GETC): Removed. Bogus and unused. + * cppmain.c (main): Remove commented-out code that used PARSE_GETC. + + * cpplib.c: Don't #include . Causes clashes + on Nextstep (when index/rindex are macros). + (cpp_grow_buffer, int_parse_file): Cast to U_CHAR*, rather than char*. + +Sun Apr 30 08:11:23 1995 Alan Modra (alan@spri.levels.unisa.edu.au) + + * stdarg.h, varargs.h (va_arg): Don't assume __va_rounded_size (char) + has the value of 4. + +Sun Apr 30 07:13:43 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * vax.h (NOTICE_UPDATE_CC): Correctly handle aob insns. + + * expr.c (expand_expr, case CONSTRUCTOR): Don't set target to + zero if more then one word. + Pass size and alignment to move_by_pieces_ninsns in bytes, not bits. + + * cse.c (cse_insn): Properly set IN_MEMORY for SET_DEST. + + * tree.c (substitute_in_expr): Preserve TREE_READONLY. + + * c-common.c (enum attrs): Add A_UNUSED. + (init_attributes): Initialize it. + (decl_attributes, case A_UNUSED): New case. + +Sat Apr 29 15:42:03 1995 Paul Eggert + + * cccp.c (do_include): Re-fix minor memory leak by using + alloca instead of xmalloc and free. + + * cccp.c (macarg): Except for reporting error, treat unterminated + macro call as if it were terminated, since `macroexpand' relies + on *argptr being filled in. + +Sat Apr 29 06:09:35 1995 Torbjorn Granlund + + * pa.c (output_mul_insn): Simplify, it is never called with + UNSIGNEDP set. + + * pa.md (divsi3, udivsi3, modsi3, umodsi3): Simplify. + (ashlsi3): Clean up indentation and commentary. + +Fri Apr 28 12:48:01 1995 Jason Merrill + + * integrate.c (expand_inline_function): Don't emit any notes until + after we've expanded the actual parameters. + +Fri Apr 28 11:51:06 1995 Stan Cox (gcc@dg-rtp.dg.com) + + * m88k/dgux.h: (ENDFILE_SPEC, LIB_SPEC) Fix crtbegin and crtend + (SELECT_RTX_SECTION) Put relocatable pic constants in data section + + * m88k/dguxbcs.h: (LIB_SPEC) Likewise + + * m88k/m88k.c: (symbolic_operand) Put relocatable pic constants in data + + * m88k/m88k.h: (FRAME_POINTER_REQUIRED) Add -momit-leaf-frame-pointer + + * m88k/m88k.md: (umulsidi3) Doesn't work for 88110 with mod/div changes + + * m88k/x-dgux: (GCC_FOR_TARGET) tdesc gets mixed up for crtbegin/crtend + +Fri Apr 28 06:36:47 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-typeck.c (pop_init_level, output_init_element): Pass + require_constant_* to digest_init. + + * alpha.c (alpha_emit_set_const): Now returns rtx and take MODE arg. + Rework to use a new pseudo for intermediate values if high opt level. + Also use expand_{bin,un}op. + * alpha.h (alpha_emit_set_const): Add declaration. + * alpha.md (mov[sd]i and splits): Change call to alpha_emit_set_const. + + * reg-stack.c (stack_result): Fix bug in last change. + +Fri Apr 28 01:08:43 1995 Doug Evans + + * objc-act.c: Update calls to start_decl, finish_struct, + pass NULLs for attributes. + +Thu Apr 27 21:13:14 1995 Doug Evans + + * sparc.md (tablejump): Only if ! TARGET_MEDANY. + (casesi): New pattern for TARGET_MEDANY case. + + * c-common.c (decl_attributes): Always continue if attribute not found. + * c-typeck.c (common_type): Call lookup_attribute instead of + value_member. + * tree.c (attribute_hash_list): New function. + (build_type_attribute_variant): Call it. + (valid_machine_attribute): Handle attributes with arguments. + (is_attribute_p): New function. + (lookup_attribute): New function. + (attribute_in_list): Deleted. + (attribute_list_contained): Check TREE_PURPOSE and TREE_VALUE. + * tree.h (valid_machine_attribute): Add prototype. + (is_attribute_p, lookup_attribute): Likewise. + * i386/winnt.h (RETURN_POPS_ARGS): Call lookup_attribute. + (ENCODE_SECTION_INFO): Likewise. + (CPP_PREDEFINES): Use __stdcall__, __cdecl__. + (VALID_MACHINE_DECL_ATTRIBUTE): Call is_attribute_p. + `args' must be NULL. + +Thu Apr 27 21:10:41 1995 David Edelsohn + + * rs6000.md (insv): New anonymous patterns to combine insert with + arbitrary ashift, ashiftrt, lshiftrt, or zero_extract. (Based on + patch from John Brooks .) + (ashlsi3): Remove extraneous operand processing. + +Thu Apr 27 18:47:24 1995 Jim Wilson + + * sh/ashlsi3.c, sh/ashrsi3.c, sh/lshrsi3.c: Delete. + * sh/lib1funcs.asm (ashiftrt_r4_*): Rewrite for efficiency. + (ashrsi3, lshrsi3, lshrsi3): Add. + * t-sh (LIB1ASMFUNCS): Add new functions. + (LIBGCC2_CFLAGS): Delete. + (LIB2FUNCS_EXTRA): Remove deleted files. + (ashlsi3.c, ashrsi3.c, lshrsi3.c): Remove rules for deleted files. + + * stmt.c (expand_return): When returning BLKmode structure, use + operand_subword instead of doing arithmetic on the register number. + Also, for structures smaller than word_mode, copy it into a word_mode + temporary and then subreg it. + + * sparc.md: Delete two define_peepholes which print `bad peephole'. + +Thu Apr 27 16:17:01 1995 Torbjorn Granlund + + * toplev.c (rest_of_compilation): Call shorten_branches even when + !optimize. + * final.c (shorten_branches): For non-optimizing compiles, break + after first pass. + +Thu Apr 27 14:22:50 1995 Michael Meissner + + * i386/linux-oldld.h: New file, that is cloned from linux-aout.h, + except that it does not pass -m i386linux to the linker. This is + to support the original Linux ld that is on most distributions. + + * configure (i[345]86-*-linux*oldld*): Use i386/linux-oldld.h as + the target file. + +Thu Apr 27 08:56:50 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * tree.c (valid_machine_attribute): Update last change. + +Thu Apr 27 08:06:33 1995 Philippe De Muyter (phdm@info.ucl.ac.be) + + * fix-header.c, cpplib.c: Don't include twice. + * cpplib.c (cpp_grow_buffer, init_parse_file): Cast {xmalloc,xrealloc} + for token_buffer to U_CHAR* instead of char*. + + * m68k/x-mot3300: New file. + * configure (m68k-motorola-sysv*): Use x-mot3300 instead of x-alloca. + +Thu Apr 27 07:04:09 1995 Paul Eggert + + * cccp.c (do_include): Fix minor memory leak. + + * cccp.c (struct argdata): Remove unused `comments' member. + (macarg): Don't set `comments' member. + + * cccp.c (collect_expansion): Assume leading white space + already removed. + Don't allocate unnecessary space for expansion. + + * cccp.c (deps_output): Don't generate overly long output lines. + Do not invoke self recursively with spacer == 0; this simplifies + the code a bit. + +Wed Apr 26 19:20:02 1995 Andrew McCallum + + * objc/Object.h: Changed Class * to Class in order to match NEXTSTEP + and OpenStep runtime. + * objc/Object.m, objc/Object.h, objc/archive.c, objc/class.c: Likewise. + * objc/encoding.c, objc/init.c, objc/objc-api.h, objc/objc.h: Likewise. + * objc/objects.c, objc/runtime.h, objc/selector.c: Likewise. + * objc/sendmsg.c, objc/typedstream.h: Likewise. + +Wed Apr 26 19:18:52 1995 Pieter Schoenmakers + + * objc/objc-api.h (objc_static_instances): New struct to record + static instances of a certain class. + (objc_module): New tag STATICS to point to the table of + objc_statics_instances. + + * objc/init.c (OBJC_VERSION): Version 7. + (objc_init_statics): New function. + (__objc_exec_class): Invoke objc_init_statics if needed. + + * objc/NXConstantString.m, objc/NXConstantString.h: New files. + * objc/Makefile (OBJC_O): Added bare-bones implementation of + NXConstantString. + + * objc-act.c (OBJC_VERSION): Version 7. + (build_objc_string_object): Build a full declaration if not using + the next runtime. + (objc_add_static_instance): New function. + (init_module_descriptor): Add reference to static instances table. + (build_module_descriptor): Add field for static instances table. + (get_objc_string_decl): New function. + (generate_static_references): New function. + (finish_objc): Call generate_static_references if needed. + + * c-tree.h (finish_decl_top_level): New declaration. + * c-decl.c (finish_decl_top_level): New function. + +Wed Apr 26 18:04:32 1995 Dirk Steinberg (Dirk.Steinberg@gmd.de) + + * stddef.h: Treat _MACHINE_ANSI_H_ like _ANSI_H_. + +Wed Apr 26 14:09:59 1995 Jim Wilson + + * sparc.h (NEGTF2_LIBCALL): Define. + (INIT_TARGET_OPTABS): Add support for all TFmode *_LIBCALL macros. + * optabs.c (init_optabs): Delete all uses of undocumented TImode and + TFmode *_LIBCALL macros. + + * combine.c (simplify_rtx, case TRUNCATE): Add. Use force_to_mode. + (force_to_mode, case AND): Allow some simplifications when GET_MODE (x) + has more bits than HOST_BITS_PER_WIDE_INT. + * mips/mips.md (truncdiqi2+[456]): Add patterns to simplify ZERO_EXTEND + of a TRUNCATE. + +Wed Apr 26 13:01:22 1995 Doug Evans + + * sparc.md (memop define_splits): Rewrite to not use memop. + Preserve MEM_IN_STRUCT_P, MEM_VOLATILE_P, RTX_UNCHANGING_P bits. + * sparc.c (memop): Deleted. + (splittable_symbolic_memory_operand): New function. + (splittable_immediate_memory_operand): New function. + +Wed Apr 26 12:54:26 1995 Jeffrey A. Law + + * configure: Add hppa1.1-hp-lites support. + +Wed Apr 26 08:04:46 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * sh.md (ashrsi2_31): Don't use dead_or_set_p after reload. + * pyr.md: Remove bad peepholes that improperly use dead_or_set_p. + + * function.c (expand_function_end): Warn about unused parms + if both -Wunused and -W. + + * tree.h (TYPE_PARSE_INFO): Delete unused field. + (TYPE_PACKED): Add new macro. + (struct tree_type): Delete unused field `parse_info'. + Add new field `packed_flag'. + * c-tree.h (finish_enum, finish_struct): Add ATTRIBUTES argument. + * c-common.c (init_attributes): Don't require decl for A_PACKED. + (decl_attributes, case A_PACKED): Set TYPE_PACKED for type. + * c-parse.in: Update number of shift/reduce conflicts. + (structsp): Pass attribute arg to finish_struct. + Support attributes on enums and pass to finish_enum. + * c-decl.c (finish_struct): Add ATTRIBUTES argument, call + decl_attributes and set DECL_PACKED from TYPE_PACKED. + (finish_enum): Add ATTRIBUTES argument, call decl_attributes, + and make enum narrow if TYPE_PACKED. + * print-tree.c (print_node): Print TYPE_PACKED. + + * c-decl.c (init_decl_processing): Don't give builtin__constant_p an + argument type. + * expr.c (expand_builtin, case BUILT_IN_CONSTANT_P): A pointer to a + string constant is a constant. + + * c-typeck.c (output_init_element): Constructor is not simple if + a bitfield is being assigned a non-integer. + + * c-typeck.c (push_init_level): Update constructor_depth when we + push spelling level. + +Tue Apr 25 19:50:06 1995 Jeffrey A. Law + + * pa.c (emit_move_sequence): Handle function label arithmetic for + PIC code generation too. + +Tue Apr 25 18:52:43 1995 Stephen R. van den Berg (berg@pool.informatik.rwth-aachen.de) + + * reg-stack.c (current_function_returns_real): Deleted (unused). + (FP_mode_reg): Trimmed to a smaller size, less overhead. + (FP_MODE_REG): New macro over which FP_mode_reg will be accessed. + (mark_regs_pat, straighten_stack): New functions. + (reg_to_stack): Amend initialisation of FP_mode_reg. + Mark FP registers mentioned in USE insns before NOTE_INSN_FUNCTION_BEG. + (get_true_reg): Eliminate FP subreg accesses in favour of the + actual FP register in use. + (record_reg_life_pat): Make it work on SUBREGs as well. Make use of + the new mark_regs_pat function. Handle USE insns if called unnested. + (record_reg_life): Don't check for QImode again, we know that it + is there. Process CALL_INSNs like all other insns, they might `use' + some FP argument registers if register passing. + (stack_result_p): Changed in stack_result and returning an rtx. + (stack_reg_life_analysis): Take a new stackentry state argument. + Use stack_result and the rtx to mark using mark_regs_pat. This ensures + that types that need multiple FP registers are handled correctly. + Delete the no_live_regs shortcut to save space. + Use stackentry state to determine filled registers. + (replace_reg): Accept COMPLEX_FLOAT as well. + (move_for_stack_reg): Optimise away some pointer dereferencing. + (subst_stack_regs): Make sure the stack is in the right order + and of the right size for register passing. + (goto_block_pat): Make sure the stack is in the right order + to return possible multi-register values from the function. + (convert_regs): Fix comment about CALL_INSN, it's no longer valid. + Make sure the stack is of the right size and in the right order + to return possible multi-register values from the function. + + * function.c (assign_parms): If STACK_REGS is defined, generate USE + insns before the function body, thus showing which registers are filled + with parameters. + * expr.c (expand_builtin_apply_args): Likewise. + Reverse order of saving registers, more compact code for i387. + (expand_builtin_apply): Likewise. + * emit-rtl.c (gen_highpart): Add comment about broken implementation. + * i386.md (untyped_call): Make it return a complex double. + + * c-parse.in (attrib): Permit null-length argument list to attributes. + + * tree.c (valid_machine_attribute): Use new function attribute_in_list, + makes sure type_attribute_variants are reused even when attributes have + parameters. + Assign any new type to TREE_TYPE (decl). + (attribute_in_list): New function. + (attribute_list_contained): Use it. + * tree.h (attribute_in_list): New declaration. + +Tue Apr 25 18:25:53 1995 Jim Wilson + + * expr.c (struct move_by_pieces): Add to_struct and from_struct fields. + (move_by_pieces): Set to_struct and from_struct fields. + (move_by_pieces_1): Set MEM_IN_STRUCT_P of to1 and from1. + (expand_builtin, case BUILT_IN_MEMCPY): New variable type. + Set MEM_IN_STRUCT_P of src_mem and dest_mem. + + * Makefile.in (clean): Delete libgcc1-asm.a. + + * m68k/vxm68k.h (CPP_SPEC): Define. + + * c-decl.c (pushdecl): Don't test DECL_EXTERNAL when deciding whether + to register a duplicate decl in the current block. + + * cross64.h (INIT_ENVIRONMENT): Define as string not putenv call. + * gcc.c (main): Pass INIT_ENVIRONMENT to putenv. + + * stmt.c (expand_return): When returning BLKmode structure in + registers, copy it to a psuedo-reg instead of to hard registers. + +Tue Apr 25 15:14:58 1995 Michael Meissner + + * rs6000.h (LEGITIMIZE_ADDRESS): Don't create a DF address using two + regs if -msoft-float or -mcpu=403. + +Tue Apr 25 15:45:44 1995 Richard Henderson (richard@atheist.tamu.edu) + + * m68k.md (divhi3, udivhi3, modhi3, umodhi3): Deleted + these insns plus some surrounding trash. + (divmodhi4, udivmodhi4): Added these insns. + +Tue Apr 25 10:12:40 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.c (alpha_builtin_saveregs): Refine last change to work + for both stdarg and varargs. + + * tree.c (chain_member_purpose): Make similar to chain_member_value. + + * Makefile.in, configure: Change "realclean" to "maintainer-clean". + + * protoize.c: Removed __NetBSD__ from conditional. + Declare strerror if HAVE_STRERROR is defined; otherwise + declare sys_errlist and sys_nerr. + (my_strerror): New function. + (errno): Don't define if already defined as a macro. + + * alpha.c (current_file_function_operand): Return false if profiling. + + * expr.c (convert_move): Don't access a hard reg in an invalid + mode when doing a truncation. + + * alpha.c (add_operand): Test for exactly the constants allowed by + the constraints. + * alpha.h (CONST_OK_FOR_LETTER_P, case 'L'): Reject 0x80000000. + + * c-parse.in (initdcl, notype_initdcl): Pass attributes to + start_decl; delete call to decl_attributes. + * c-tree.h (start_decl): Two new tree parameters. + * c-decl.c (start_decl): New args for attributes; call decl_attributes. + + * c-decl.c (duplicate_decls): Don't look at TYPE_ACTUAL_ARG_TYPES + if it is not set. + + * xm-1750a.h: New file. + + * alpha.c (alpha_builtin_saveregs): Add to incoming args addr + if less than 6 named args, not less than or equal to. + +Mon Apr 24 15:25:19 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * mips-tfile.c (fatal, error): Make first arg const to avoid warning. + + * stmt.c (expand_end_bindings): Write a BARRIER after call + to abort in nonlocal handler. + + * stmt.c (expand_decl_init): Call preserve_temp_slots to keep + around any temp whose address was taken. + +Fri Apr 21 16:26:15 1995 Torbjorn Granlund + + * pa.md (call_internal_reg): Fix typos in length calculation. + (call_value_internal_reg): Likewise. + +Fri Apr 21 13:17:15 1995 Roland McGrath + + * config/gnu.h (STANDARD_INCLUDE_DIR): New macro. + * config/mips/gnu.h (STANDARD_INCLUDE_DIR): Macro moved there. + +Fri Apr 21 08:23:58 1995 Tom Quiggle (quiggle@lovelace.engr.sgi.com) + + * toplev.c (lang_options): Add -I for GNAT. + * gcc.c (default_compilers): Pass -I to gnat1. + +Fri Apr 21 07:58:06 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * tree.c (integer_all_onesp): Test to size of mode, not TYPE_PRECISION. + + * toplev.c (main): Turn on -fforce-mem for -O2. + + * fold-const.c ([lr]rotate_double): Replace; old versions were bogus. + (fold, shift and rotate): Don't call tree_int_cst_sgn on non-integer. + (fold, case LROTATE_EXPR): If constant count, convert to RROTATE_EXPR. + (fold, case RROTATE_EXPR): Sometimes commute logical op with rotate. + Delete pair of counteracting shifts. + + * combine.c (simplify_logical, case AND): If still an AND, get + new values for op0 and op1. + +Thu Apr 20 17:52:10 1995 Jim Wilson + + * sh.c: Completely rewritten. + * sh.h (FAST_BIT, CONSTLEN_2_BIT, CONSTLEN_3_BIT, CONSTLEN_0_BIT, + TARGET_FASTCODE, TARGET_CLEN3, TARGET_CLEN0, TARGET_OPTIONS): Delete. + (TARGET_SWITCHES): Delete -mclen3 and -mclen0 options. + (TARGET_DEFAULT): Is zero. + (OVERRIDE_OPTIONS): Delete code to set max_count_si and max_count_hi. + (SPECIAL_REG): New macro. + (HARD_REGNO_MODE_OK): Allow any mode in any general register. + (GO_IF_LEGITIMATE_ADDRESS): Delete constant + reg address case. + (MOVE_RATIO): Define to 2 when TARGET_SMALLCODE. + (max_si, max_hi, max_count_si, max_count_hi): Delete. + * sh.md: Delete spurious constraints from all define_expands. + (rotlsi3_1): Set T reg instead of clobbering it. + (ashrsi3): Use expand_ashiftrt instead of gen_shifty_op. + (movsi_i, movhi_i, movsf_i): Add conditions to reject patterns + needing a reload. + (movdi-2, movdf_k): Correct conditions to reject patterns needing + a reload. + ([inverse_]branch_{true,false}): Pass operands to output_branch. + (jump): Delete unnecessary braces. + (call, call_value): Don't use expand_acall. Force operand0 into + a register. + +Thu Apr 20 12:57:16 1995 Jason Merrill + + * function.c (assign_parms): Use TREE_ADDRESSABLE rather than + TYPE_NEEDS_CONSTRUCTING to decide whether a parameter needs to be + passed by invisible reference. + + * calls.c (expand_call): Ditto. Abort if we try to pre-evaluate a + parameter of TREE_ADDRESSABLE type. + +Wed Apr 19 17:50:24 1995 Torbjorn Granlund + + * pa.h (TARGET_SWITCHES): Fix typo. + +Tue Apr 18 18:06:03 1995 Per Bothner + + * expr.c (store_constructor): Use BYTES_BIG_ENDIAN rather + than BITS_BIG_ENDIAN to layout bits within bitstring. + * tree.c (get_set_constructor_bytes): Likewise. + +Tue Apr 18 17:22:46 1995 Per Bothner (bothner@wombat.gnu.ai.mit.edu) + + * config/m68k/{x-hp320,x-hp320g} (FIXPROTO_DEFINES): + Define _HPUX_SOURCE so putenv and other functions get seen. + +Tue Apr 18 03:57:35 1995 Michael Meissner (meissner@cygnus.com) + + * varasm.c (weak_decls): Make this a unique structure, instead of + a tree structure. + (handle_pragma_weak): Don't redeclare asm_out_file. Use new weak + structure to copy name and value to. Protect name and value by + copying them to the permanent obstack. + (declare_weak): Call handle_pragma_weak, instead of duplicating + the code. + (finish_weak): Rewrite to use new weak symbols list structure. + + * c-pragma.h: New file to define the c-pragma.c interfaces. + * c-pragma.c: Include it. + * varasm.c: Include it. + * c-lex.c: Include it. + * cp/lex.c: Include it. + + * varasm.c (handle_pragma_weak): No longer pass output file + stream, since weak pragmas are delayed until the end of the + compilation. + * c-pragma.c (handle_pragma_token): Call handle_pragma_weak + without file stream argument. + + * Makefile.in (varasm.o, c-lex.o, c-pragma.o): Add dependencies on + c-pragma.h. + + * config/rs6000.md (movdf): If -msoft-float, do not generate + memory to memory references, like is already done for the + -mhard-float case. Remove an extra test for -mhard-float inside + of -mhard-float code. + +Tue Apr 18 06:19:50 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (size_int): Arg is unsigned HOST_WIDE_INT. + * tree.h (size_int): Likewise. + +Mon Apr 17 23:36:57 1995 Jason Merrill + + * rs6000/aix41.h: Restore March 11th changes, plus + (ASM_OUTPUT_EXTERNAL): Do add [DS] or [RW], just don't emit + anything. + * rs6000/aix3newas.h (ASM_OUTPUT_EXTERNAL): Ditto. + +Mon Apr 17 15:58:52 1995 Per Bothner + + * config/mips/x-iris (FIXPROTO_DEFINES): Add -D_LANGUAGE_C_PLUS_PLUS. + * config/mips/x-iris6: Likewise. + + * cpplib.c: Rename make_definition to cpp_define. + * cpplib.h (cpp_define): New declaration. + + * cpplib.c (special_symbol): For T_SPECLINE, calculate __LINE__ + in enclosing file buffer, not current buffer (if macro expanding). + (cpp_get_token): Fix thinko (in code for chopping unneeded space). + +Mon Apr 17 11:36:07 1995 Jim Wilson + + * abi64.h (CPP_SPECS): Define and use _ABI64 instead of + _MIPS_SIM_ABI64. + (SETUP_INCOMING_VARARGS): Set MEM_IN_STRUCT_P if big endian target. + * iris6.h (ASM_IDENTIFY_GCC, ASM_IDENTIFY_LANGUAGE): Define. + + * combine.c (get_last_value): Ignore BARRIER when scanning backwards. + (move_deaths): New variables before_dead and after_dead. Set them + to instructions that have valid INSN_CUID values and use in test. + + * combine.c (subst_prev_insn): New variable. + (try_combine): Set it. + (get_last_value): Use it. + + * reload.c (find_reloads): Recompute reg_equiv_address from + reg_equiv_memory_loc before using it. + (find_reloads_toplev, make_memloc): Likewise. + + * expr.c (expand_builtin, case BUILT_IN_MEMCPY): Call force_operand + on dest_rtx before returning it. + + * function.c (instantiate_decls): Use temporary allocation if + DECL_DEFER_OUTPUT is set. + +Sat Apr 15 23:19:03 1995 Jason Merrill + + * aoutos.h (ASM_OUTPUT_DEF): Define instead of SET_ASM_OP. + * sparc/sunos4.h (ASM_OUTPUT_DEF): Ditto. + + * varasm.c (weak_finish): Don't handle aliases. + (declare_weak): Ditto. + (assemble_alias): Handle aliases. + + * c-common.c (enum attrs): Add A_ALIAS. + (init_attributes): Ditto. + (decl_attributes): Ditto. + +Sat Apr 15 13:26:34 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * calls.c (expand_call): Call preserve_temp_slots on temps + made for BLKmode args returned in registers. + + * pa.c (override_options): Fix typo. + +Sat Apr 15 12:11:46 1995 Brendan Kehoe + + * alpha/alpha.c (output_epilog): Initialize fp_offset to 0, and + make sure it's non-zero before we try to use it to restore the + frame pointer. + +Fri Apr 14 19:45:05 1995 Jason Merrill + + * ginclude/va-{clipper,pa,pyr,sparc,spur}.h (va_arg): Reorganize + to avoid BIND_EXPRs and COND_EXPRs of aggregate type. + +Fri Apr 14 19:31:14 1995 Roland McGrath + + * config/svr4.h (ASM_OUTPUT_SECTION_NAME): Make the section + read-only executable "ax" if DECL is a FUNCTION_DECL; read-only + "a" (previously the case always) if DECL is TREE_READONLY; + otherwise writable "aw". + +Fri Apr 14 18:49:11 1995 Linus Torvalds + + * alpha.md (probe_stack): Probe with write, not read. + (allocate_stack): Update and correct stack probe code. + * alpha.c (output_prolog): Changed stack probe at function entry. + +Fri Apr 14 18:42:34 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * jump.c (delete_insn): When deleting after label, delete + a BARRIER as well. + +Fri Apr 14 14:40:48 1995 Jason Merrill + + * toplev.c (compile_file): Call weak_finish. + + * c-common.c (enum attrs): Add A_WEAK. + (init_attributes): Ditto. + (decl_attributes): Support __attribute__ ((weak)) by + calling declare_weak. + + * sparc/sunos4.h (HANDLE_PRAGMA_WEAK, WEAK_ASM_OP, SET_ASM_OP): + Define to support weak symbols with -fgnu-linker. + * aoutos.h: Ditto. + + * varasm.c (handle_pragma_weak): Add declared weak symbols to + weak_decls rather than emitting them immediately. + (declare_weak): Add the indicated declaration to weak_decls. + (weak_finish): Emit .weak directives for any weak symbols. + + * libgcc2.c: The C++ free-store management functions are weak. + +Fri Apr 14 13:00:29 1995 Michael Meissner (meissner@cygnus.com) + + * rs6000/rs6000.c (output_prolog): For eabi systems, emit main's + call to __eabi before setting up the minimal TOC used with the + -mrelocatable support. + + * rs6000/eabi.h (INVOKE__main): Don't define any more, + output_prolog will emit the call. + +Fri Apr 14 09:09:03 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * alpha.c (call_operand): Any reg is valid for NT. + (output_prologue): Never need GP for Windows/NT. + Set SYMBOL_REF_FLAG in current function decl. + +Thu Apr 13 20:19:30 1995 Jason Merrill + + * alpha/xm-alpha.h (HAVE_VPRINTF): Define. + (HAVE_PUTENV): Define. + (POSIX): Define. + +Thu Apr 13 19:57:44 1995 Doug Evans + + * emit-rtl.c (gen_sequence): If the insn has a non-null + CALL_INSN_FUNCTION_USAGE field, output it as a sequence so the + latter isn't discarded. + + * c-parse.in: Update expected conflict count. + +Thu Apr 13 08:10:20 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * configure.bat: Arg 2 is which machine (i386 or alpha). + * configure (alpha-*-winnt3*): New configuration. + * alpha.c: Don't #include stamp.h for WINNT. + (input_operand, case CONST): Allow ptr_mode and DImode. + * alpha.h (WINDOWS_NT): Provide default definition. + (ASM_OUTPUT_INT): Use output_addr_const. + (ASM_OUTPUT_ADDR_DIFF_ELT): Use .long for NT. + * alpha.md (calll, tablejump, movsi): New variants for NT. + * alpha/winnt.h, alpha/xm-winnt.h, alpha/x-winnt: New files. + * alpha/config-nt.bat, alpha/config-nt.sed: New files. + * i386/config-nt.bat: Add Ada fragments to Makefile. + * i386/config-nt.sed: Adjust for deletion of config.run in Makefile.in + Change version to 2.6.3. + Add some missing tabs. + * winnt/winnt.h (TARGET_MEM_FUNCTIONS): Define. + (LINK_SPEC): Delete "align:0x1000". + * winnt/xm-winnt.h (OBJECT_SUFFIX): Define. + * ginclude/stdarg.h, ginclude/varargs.h: Clean up code that + defines *DEFINED* symbols. + + * configure (a29k-*-sym1*): Same as a29k-*-bsd*. + * a29k.h (ASM_OUTPUT_SECTION_NAME): New macro. + +Wed Apr 12 14:36:03 1995 Jim Wilson + + * dbxout.c (dbxout_type_fields): Correct arguments to CHARS macro + in flag_minimal_debug case. + (dbxout_symbol_name): Use DECL_ASSEMBLER_NAME unconditionally. + * sdbout.c (sdbout_record_type_name): Correct indentation. + (sdbout_symbol): Use DECL_ASSEMBLER_NAME unconditionally. + (sdbout_one_type): Likewise. + +Tue Apr 11 13:24:13 1995 Per Bothner + + * fix-header.c (main): Fix loop over required_functions_list. + (fatal): Also print inc_filename. + + * cpplib.c (cpp_push_buffer): Added missing initializatuon of buf. + (cpp_file_buffer): Compare against CPP_NULL_BUFFER, not NULL. + (finclude): No longer call cpp_push_buffer - let callers do it. + (do_include): Add call to cpp_push_buffer. + (push_parse_file): Call cpp_push_buffer early, so initial + defines can use file and line from a valid cpp_buffer. + (nreverse_pending): New function. + (push_parse_file): Use nreverse_pending. + (push_parse_file): For -include files, just push them in reverse + order - we don't need to scan them now. + (cpp_error_from_errno, cpp_perror_with_name): Don't emit extra '\n'. + +Tue Apr 11 13:36:44 1995 Jim Wilson + + * configure (mips-dec-mach3): Add. + + * sh.c (shiftby_operand): Delete. + * sh.h (TARGET_SWITCHES): -m3 and -m3l also set SH2_BIT. + (OVERRIDE_OPTIONS): Don't add CPU_SH2 to CPU_SH3 when TARGET_SH3. + * sh.md (ashlsi3): Use nonmemory_operand as a predicate instead of + shiftby_operand. Don't use shiftby_operand in the output statement. + (lshrsi3): Likewise. + + * c-decl.c (poplevel): Do output inline function if + DECL_ABSTRACT_ORIGIN points to itself. + + * varasm.c (output_constant): Cast assemble_string argument to char *. + +Mon Apr 10 14:29:28 1995 Torbjorn Granlund + + * recog.c (constrain_operands, case 'E'): Make this work like + constraint character `F' when REAL_ARITHMETIC is defined. + * regclass.c (record_reg_classes, case 'E'): Likewise. + * reload.c (find_reloads, case 'E'): Likewise. + +Mon Apr 10 14:30:31 1995 Michael Meissner + + * rs6000/aix3newas.h, rs6000/aix41.h: Eliminate March 11th changes + to undefine ASM_OUTPUT_EXTERNAL{,_LIBCALL}, since this causes the + compiler not to bootstrap. + +Mon Apr 10 07:17:39 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cppalloc.c: #include config.h. + * cppexp.c: Add declarations of xmalloc and xrealloc. + (cpp_parse_expr): Cast args to bcopy to char *. + * cpphash.c: Add declaration of xmalloc. + * cpplib.c (init_parse_options, cpp_reader): Cast args to bcopy, + bcmp, and bzero to char *. + (add_import, push_parse_file, init_parse_file): Likewise. + + * c-common.c (enum attrs): New attribute, A_NOCOMMON. + (init_attribute): Initialize it. + (decl_attributes): Implement it. + * varasm.c (make_decl_rtl): Allow section attribute if -fno-common + or variable is not to be placed in common for some other reason. + + * combine.c (simplify_set): Don't move a SUBREG to dest if it + is changing the size of a hard reg in CLASS_CANNOT_CHANGE_SIZE. + + * reload.c (find_equiv_reg): If goal is a pseudo that got memory, + a store into memory makes it invalid. + * reload1.c (reload_as_needed): Call forget_old_reloads_1 on + pattern before reg elimination. + +Mon Apr 10 00:26:14 1995 Jeffrey A. Law + + * pa.c (pa_reorg): Bump label use count for each entry in an + exploded ADDR_VEC. + +Sun Apr 9 09:22:51 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * i386.md (adddi3, subdi3): Need scratch reg whenever operand 0 in + mem and operands 1 not '0'. + (subdi3): Don't treat two non-equal MEMs as non-aliasing. + +Sat Apr 8 22:53:38 1995 Jeffrey A. Law + + * pa.c (pa_reorg): Fix typo. + +Sat Apr 8 19:36:36 1995 Michael Meissner + + * rs6000/rs6000.h (SELECT_SECTION): TREE_CODE_CLASS must be called + with a tree code, not a tree value. + +Sat Apr 8 12:41:01 1995 Mike Stump + + * cpphash.c: Don't use const on compilers that don't support it. + +Sat Apr 8 16:32:22 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * expr.c (expand_increment): Handle case where INCREMENTED + has a non-trivial conversion. + +Fri Apr 7 19:33:21 1995 Phil Nelson (phil@cs.wwu.edu) + + * ns32k.h (TRAMPOLINE_TEMPLATE, TRANSFER_FROM_TRAMPOLINE): + Fix assembler syntax errors. + +Fri Apr 7 19:27:23 1995 Pat Rankin (rankin@eql.caltech.edu) + + * cccp.c (VMS_fstat, VMS_stat): New functions. + +Fri Apr 7 19:25:21 1995 Paul Eggert + + * cccp.c (collect_expansion): If traditional, set stringify + member to SHARP_TOKEN regardless of the value of + stringify_sharp_token_type. + +Fri Apr 7 07:48:35 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cse.c (simplify_unary_operation): #ifdef POINTERS_EXTEND_UNSIGNED, + handle sign- or zero-extending addresses. + + * optabs.c (init{,_integral,_floating,_complex}_libfuncs): + Change SUFFIX to "char" to avoid confusion with prototype. + + * explow.c (convert_memory_address): No longer static. + New arg, TO_MODE. + Do something special for SYMBOL_REF, LABEL_REF, and CONST. + (memory_address): Add extra arg to call to convert_memory_address. + * rtl.h (convert_memory_address): Add extra arg. + * expr.c (expand_expr, case ADDR_EXPR): Always call + convert_memory_address when converting; add extra arg. + * stmt.c (expand_computed_goto): Convert from ptr_mode to Pmode. + + * gcc.c (OBJECT_SUFFIX): Default now ".o", not "o". + (all specs): Remove "." before %O; use %O in a few missing cases. + * i386/os2.h (OBJECT_SUFFIX): Delete from here. + * i386/xm-os2.h (OBJECT_SUFFIX): Move to here; now has period. + + * Makefile.in (STAGESTUFF): Use $(exeext) for executables. + +Fri Apr 7 03:32:29 1995 Richard Stallman + + * config.sub: Accept -lites* as op sys. + +Thu Apr 6 23:08:50 1995 Per Bothner + + * cpplib.c (bcopy, bzero, bcmp): Remove #undefs. + * cppalloc.c (xcalloc): Re-implement using calloc, + rather than malloc+bzero. + * cpplib.c (SELF_DIR_DUMMY): New macro. + (do_include): Don't pass searchptr to finclude if it is dsp, + since that is on the stack, and would cause a dangling pointer. + If handling #include_next, recognize SELF_DIR_DUMMY. + +Fri Apr 7 00:54:24 1995 Jeffrey A. Law + + * pa.h (MACHINE_DEPENDENT_REORG): Define. + * pa.md (switch_jump): New pattern for jumps which implement + a switch table. + * pa.c (pa_reorg): New function to explode jump tables. + (pa_adjust_insn_length): Account for jumps in switch tables with + unfilled delay slots. + +Thu Apr 6 14:31:10 1995 Jason Merrill + + * c-typeck.c (build_binary_op): Don't call common_type for + uncommon pointer types. + +Wed Apr 5 13:53:17 1995 Per Bothner + + Re-write fixproto/fix-header/etc to use cpplib: + * fix-header.c: Comment out support for adding missing extern "C" + using #ifdef ADD_MISSING_EXTERN_C instead of #if 0. + * fixproto: Removed case of required functions. Instead use ... + * fix-header.c (std_include_table): ... new required-functions table. + (cpp_file_line_for_message, cpp_print_containing_files, cpp_message): + New stub functions, to intercept cpplib error message. + * fixproto: Don't call $CPP, since fix-header now incorporates cpplib. + * gen-protos.c (fatal, hashf): New functions. + (main): Use hashf, instead of hash. + * scan-decls.c (scan_decls, skip_to_closing_brace): Re-write to + take a cpp_reader* as argument, not a FILE*. + * scan.h (hash): Make parameter const. + * scan.c (hash): Removed. + * scan.c (memory_full, xmalloc, xrealloc): Removed. + Use functions from cppalloc.c instead. + * Makefile.in (gen-prtos, fix-header, stmp-fixproto): Update. + +Wed Apr 5 13:24:14 1995 Per Bothner + + * cpplib.c (cpp_get_token): If traditional, return after comment, + instead of reading more, so end-of-line can be peeked at. + * cpperror.c (cpp_file_line_for_message, cpp_message): New + functions, that do the actual printing of error messages. + (cpp_print_file_and_line, cpp_error, cpp_warning, cpp_pedwarn, + cpp_error_with_line, cpp_warning_with_line, cpp_pedwarn_with_line, + cpp_pedwarn_with_file_and_line, cpp_error_from_errno, my_strerror, + cpp_perror_with_name): Re-write to use cpp_file_line_for_message + and cpp_message, and move to cpplib.c. + +Tue Apr 4 23:35:49 1995 Roland McGrath + + * config/gnu.h (GNU_CPP_PREDEFINES): Remove -D__HURD__. + +Tue Apr 4 17:15:54 1995 Jeffrey A. Law + + * pa.h (DO_GLOBAL_DTORS_BODY): Fix pointer -> integer assignment + problem. + + * reorg.c (fill_simple_delay_slots): Don't use a JUMP_INSN + a the target of another JUMP_INSN to fill a delay slot. + +Mon Apr 3 19:03:48 1995 Torbjorn Granlund + + * cse.c (simplify_unary_operation): Sign-extend constants when + they have the most significant bit set for the target. + + * m68k.md (umulsi3_highpart): Test for CONST_INT and CONST_DOUBLE, + not CONSTANT_P. + (smulsi3_highpart): Likewise. + * m68k.c (const_uint32_operand): New function. + (const_sint32_operand): New function. + * m68k.md (const_umulsi3_highpart): Use const_uint32_operand instead + of immediate_operand for op3. Delete mode. + (const_smulsi3_highpart): Analogous change. + +Mon Apr 3 19:03:48 1995 Jim Wilson + + * cse.c (simplify_binary_operation): Sign-extend constants when + they have the most significant bit set for the target. + + * combine.c (force_to_mode, case PLUS): Sign extend masks that are + negative in OP_MODE. + (simplify_and_const_int): Sign-extend constants when they have the + most significant bit set for the target. + (merge_outer_ops): Likewise. + (simplify_shift_const): Likewise. + +Mon Apr 3 18:23:48 1995 Jason Merrill + + * toplev.c (lang_options): Add -f{no-,}repo. + +Mon Apr 3 18:13:15 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * combine.c (nonzero_bits, case REG): Check POINTERS_EXTEND_UNSIGNED. + (num_sign_bit_copies, case REG): Likewise. + * explow.c (convert_memory_address): New function. + (memory_address): Call if it needed. + (promote_mode, case POINTER_TYPE): Use Pmode and pointer extension. + (allocate_dynamic_stack_space): Convert size from ptr_mode. + * expr.c (clear_storage, expand_assignment, store_{expr,constructor}): + Use ptr_mode instead of Pmode in some places. + (expand_expr, expand_builtin): Likewise. + (push_block, store_expr): Convert size to Pmode. + (expand_expr, case ADDR_EXPR): Convert from Pmode to ptr_mode. + +Mon Apr 3 18:00:52 1995 Jim Wilson + + * explow.c (allocate_dynamic_stack_space): Correct typo in last + change. + + * sh.c (gen_shifty_op, case ASHIFTRT): Return 0 if shift count is not + a constant. + +Mon Apr 3 12:17:10 1995 Michael Meissner (meissner@cygnus.com) + + * expmed.c (extract_bit_field): When converting a SUBREG into a + REG, if the system is big endian, adjust the bit offset + appropriately. + +Mon Apr 3 00:08:45 1995 Roland McGrath + + * config/i386/linux.h: Include "config/linux.h" instead of + "linux.h", to avoid recursion. + +Sun Apr 2 23:50:27 1995 Roland McGrath + + * config/i386/gnuelf.h: Include i386/linux.h instead of + i386/linuxelf.h. + +Sun Apr 2 17:35:10 1995 Jim Wilson + + * cse.c (simplify_relational_operation): Don't simplify A-B for + compare of A and B when the compare is unsigned. + +Sun Apr 2 08:23:38 1995 Paul Eggert + + * fixincludes (stdio.h): BSDI 2.0 changed the spelling of _VA_LIST_ + to _BSD_VA_LIST_. + +Sun Apr 2 07:57:28 1995 Richard Kenner + + * i386/xm-bsd386.h: New file. + * configure (i[345]86-*-bsd*): Add xm_file. + + * gcc.c (default_compilers): Pass -W and -w to gnat1. + + * winnt/winnt.h (STDC_VALUE): Add #undef. + * i386/winnt.h (LIB_SPEC): Likewise. + +Sun Apr 2 07:55:25 1995 Douglas Rupp (drupp@cs.washington.edu) + + * i386/winnt.h (RETURN_POPS_ARGS, ENCODE_SECTION_INFO): Call + chain_member_purpose, not chain_member_value. + (ASM_FILE_START, LIB_SPEC): Move to here. + * winnt/winnt.h (ASM_FILE_START, LIB_SPEC): Delete from here. + * tree.c (chain_member_purpose): New function. + +Sat Apr 1 12:19:14 1995 Jason Merrill + + * c-typeck.c (build_binary_op): New variable build_type controls + type given to expression when created. Set to integer_type_node for + comparison ops instead of result_type so result_type still holds type + in which comparison is done. When checking for comparison between + signed and unsigned, use result_type rather than (possibly shortened) + type of op0. Don't warn about equality comparison of signed operand + to unsigned constant that fits in signed type. + +Sat Apr 1 09:47:02 1995 Douglas Rupp (drupp@cs.washington.edu) + + * i386/winnt.h (CPP_PREDEFINES): Add definitions for __stdcall + and __cdecl. + * winnt/winnt.h (LIB_SPEC): Add OLDNAMES.LIB. + * winnt/xm-winnt.h: Remove unneeded #define's for non-ANSI functions. + * fixinc.winnt: Remove unneeded fixes relating to __stdcall. + + * objc/Makefile (SHELL): New definition. + +Sat Apr 1 08:25:26 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * cse.c (cse_insn): When emitting a BARRIER, don't put it after + a deleted insn. + + * reload.c (push_reload): Initialize secondary_{in,out}_icode. + + * gcc.c (print_multilib_info): Don't use LAST_PATH if not set. + +Sat Apr 1 08:15:59 1995 Pat Rankin (rankin@eql.caltech.edu) + + * vax.md (extv, extzv): Don't use immediate value for operand 1. + +Sat Apr 1 07:48:29 1995 Yury Shevchuk (sizif@botik.yaroslavl.su) + + * stmt.c (expand_asm_operands): Properly ignore invalid reg in clobber. + +Sat Apr 1 07:02:24 1995 Paul Eggert + + * cccp.c: General code cleanup. + Add prototypes for static functions. + Remove unnecessary casts to (char *); add casts to (U_CHAR *). + Add parentheses suggested by `gcc -Wparentheses'. + Rename local variables as suggested by `gcc -Wshadow'. + , , , : New includes. + , : Include only if defined(RLIMIT_STACK). + : Include, unless already does. + (HAVE_FCNTL_H, HAVE_STDLIB_H, HAVE_SYS_TIME_H): New symbols. + (HAVE_UNISTD_H, STDC_HEADERS, TIME_WITH_SYS_TIME): Likewise. + (__attribute__, PROTO, VA_START, PRINTF_ALIST, PRINTF_DCL): New macros. + (PRINTF_PROTO{,_1,_2,_3}, DO_PROTO): Likewise. + (bcopy, bzero, bcmp): If #defined by configuration file, use that. + If STDC_HEADERS is defined, use standard C functions. + If BSTRING is defined, or USG and VMS are not defined, use + the C library. Otherwise, use my_bcopy, my_bzero, my_bcmp. + (localtime): Remove no-longer-necessary explicit declaration. + (getenv, index, rindex): Don't declare explicitly if the + appropriate system header should declare it. + (fdopen): Remove no-longer-used declaration. + (vprintf): Define a subsitute macro if !defined(HAVE_VPRINTF). + (main): Replace `fdopen (dup (fileno (stdout)), "w"))' + with `stdout'. + (get_lintcmd, rescan, create_definition): Use bcmp instead of strncmp + when both operands are known to be free of null bytes. + (check_macro_name, compare_defs, collect_expansion): Likewise. + (do_assert, compare_token_lists, assertion_lookup, do_line): Likewise. + (skip_if_group, lookup): Likewise. + (rescan): Remove unused label `startagain'. + Abort instead of printing nonsense if the stack is corrupted + when there was an unterminated successful conditional. + (pcfinclude): Include explicit double-cast through GENERICPTR + to identify particularly egregious type puns. + (create_definition, do_define, check_macro_name): Use %.*s + printf format to avoid painful copying-and-casting. + (do_once): Return void, not (unused) int. + (do_ident, do_pragma, do_sccs): Accept extra arguments so that + all directive-handler's types match. + (do_sccs): Define only if SCCS_DIRECTIVE is defined. + (skip_if_group, dump_single_macro): Add `default: break;' to + keep -Wswitch happy. + (error, warning, error_with_line, vwarning_with_line, pedwarn): Use + stdarg/vararg/vfprintf instead of passing bogus char * args around. + (pedwarn_with_line, pedwarn_with_file_and_line, fatal): Likewise. + (verror, vwarning, verror_with_line, vwarning_with_line): New fcns. + (dump_single_macro): Abort if ap points to garbage. + (make_definition, make_undef, make_assertion): Parameter now char *. + (xmalloc, xrealloc, xcalloc, savestring, index0): Make sizes size_t + instead of unsigned; make pointer parameters GENERICPTR, not char *. + (xcalloc): Use bzero to clear memory instead of using own loop. + +Fri Mar 31 08:33:07 1995 Ken Raeburn (raeburn@wombat.gnu.ai.mit.edu) + + * longlong.h (umul_ppmm mc68000): Use %# instead of #. + +Fri Mar 31 06:37:54 1995 Michael Meissner (meissner@cygnus.com) + + * stor-layout.c (layout_decl): Implment -fpack-struct. + (layout_record): Ditto. + + * flags.h (flag_pack_struct): New flag variable. + + * toplev.c (flag_pack_struct): New flag variable. + (f_options): Add -fpack-struct support. + + * Makefile.in (stor-layout.o): Add flags.h dependency. + +Fri Mar 31 08:40:16 1995 Douglas Rupp (drupp@cs.washington.edu) + + * configure (i[345]86-*-winnt3*): Add tmake_file. + * i386/x-winnt (winnt.o): Deleted. + * i386/t-winnt: New file. + +Fri Mar 31 07:26:37 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * m68k/netbsd.h, m68k/hp3bsd44.h: Remove #include of machine/ansi.h. + + * configure (a29k-*-bsd): Set tmake_file to t-libc-ok. + + * stmt.c (expand_asm_operands): Properly handle output that can't + be directly written into. + + * c-parse.in (structsp): Correct error in last change. + * c-common.c (init_attributes): A_FORMAT is only for decls. + +Thu Mar 30 18:27:34 1995 Jason Merrill + + * libgcc2.c: Remove explicit 0-initializations of static variables. + +Thu Mar 30 18:22:39 1995 Fergus Henderson + + * c-typeck.c (internal_build_compound_expr): Warn if LHS of comma + expression has no side effects, or computes value which is not used. + * stmt.c (make warn_if_unused_value): No longer static. + * tree.h (warn_if_unused_value): Add declaration. + +Thu Mar 30 18:15:11 1995 Jim Wilson + + * combine.c (get_last_value): Revert back to use prev_nonnote_insn + instead of prev_real_insn. Modify test that ignores USE insns. + + * rs6000.h (SELECT_SECTION): Apply constant DECL_INITIAL test + only to DECLs. + + * explow.c (allocate_dynamic_stack_space): Test STACK_BOUNDARY against + BIGGEST_ALIGNMENT at run time instead of at compile time. + Give MUST_ALIGN macro a value, and test this value in if statements. + +Thu Mar 30 08:59:56 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-parse.in: Now have 27 shift/reduce conflicts. + (attribute_list): Just make chain of all attributes. + (attrib): Consistently put name as PURPOSE, args, if any, as VALUE. + (structsp): Allow attributes on any struct or union. + * c-common.c (enum attrs): New enum class. + (attrtab, attrtab_idx): New variables. + (add_attribute, init_attributes): New functions. + (decl_attributes): Major rewrite. + * tree.c (valid_machine_attribute): Now receive name and args. + +Thu Mar 30 07:20:14 1995 Paul Eggert + + * protoize.c: Use the phrase `preprocessing directive' consistently. + * cccp.c (handle_directive, do_line, skip_if_group): Likewise. + (output_line_directive): Renamed from output_line_command. + (no_line_directives): Renamed from no_line_commands. + + * cccp.c (rescan): Don't recognize preprocessing directives + within macro args. Warn if one is found. + +Thu Mar 30 06:20:36 1995 H.J. Lu (hjl@nynexst.com) + + * configure (i[345]86-*-linux*): Set xmake_file=x-linux, + tm_file=i386/linux.h, and don't set extra_parts. + (i[345]86-*-linux*aout*): New configuration. + (i[345]86-*-linuxelf): Deleted. + * config/linux{,-aout}.h, config/x-linux, config/xm-linux.h: New files. + * config/i386/linux-aout.h: New file. + * config/i386/linux.h: Extensive modifications to use ELF format + as default. + (LIB_SPEC): Don't use libc_p.a for -p. don't use libg.a + unless for -ggdb. + (LINUX_DEFAULT_ELF): Defined. + * config/i386/linuxelf.h,config/i386/x-linux: Files deleted. + * config/i386/xm-linux.h: Just include xm-i386.h and xm-linux.h. + +Wed Mar 29 19:09:36 1995 Mike Stump + + * libgcc2.c (__throw_type_match): Update to use new calling convention. + +Wed Mar 29 14:53:23 1995 Jim Wilson + + * gcc.c (process_command): Delete code modifying gcc_exec_prefix. + (main): Put it here after last use of gcc_exec_prefix. For cross + compiler, set startfile_prefixes if gcc_exec_prefix is set and + standard_startfile_prefix is a relative path. + + * combine.c (make_compound_operation, AND case): Undo July 7, 1994 + change. + + * mips/mips.md (call_internal1, call_value_internal1): Move %* from + start of assembler output to immediately before the jal. + + * mips/mips.c (function_prologue): Put SDB_DEBUGGING_INFO ifdef around + code for SDB_DEBUG support. + (mips_select_rtx_section, mips_select_section): Change rdata_section + to READONLY_DATA_SECTION and sdata_section to SMALL_DATA_SECTION. + * mips/mips.h (SMALL_DATA_SECTION): Define. + + * reorg.c (mark_referenced_resources): Make setjmp use all registers. + + * flow.c (mark_used_regs, case SUBREG): Only fall through to REG case + if operand is a REG. + + * i960/i960.h (TARGET_SWITCHES): Make -mold-align set + TARGET_FLAG_STRICT_ALIGN. + (STRICT_ALIGNMENT): Test TARGET_STRICT_ALIGN. + + * sh/sh.c (andcosts): Modify costs to match the hardware, and add + explanatory comments. + + * sparc/sol2.h (CPP_PREDEFINES): Add -D__SVR4. + +Wed Mar 29 14:30:30 1995 Michael Meissner + + * rs6000/rs6000.md (movsf): When moving to/from integer registers, + don't move floating point to memory if it is being simulated with + -msoft-float. + +Wed Mar 29 06:47:36 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-parse.in (initdcl): Only call decl_attributes once. + * c-common.c (decl_attributes): Clean up test for __mode__. + +Tue Mar 28 08:34:37 1995 John Hassey (hassey@dg-rtp.dg.com) + + * i386.md (adddi3): Don't treat two non-equal MEMs as non-aliasing. + +Tue Mar 28 08:20:49 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * a29k.h (CONSTANT_ADDRESS_P): Provide consistent definition. + +Tue Mar 28 07:26:41 1995 Paul Eggert + + * cccp.c (do_xifdef, do_endif): Remove unnecessary pointer comparisons. + +Mon Mar 27 20:45:15 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * calls.c (expand_call, store_one_arg): Don't set KEEP in calls + to assign_stack_temp. + * function.c (preserve_temp_slots): Clear ADDR_TAKEN on item + that we are preserving. + +Mon Mar 27 14:39:35 1995 Ian Lance Taylor + + * mips/mips.h (FIRST_PSEUDO_REGISTER): Increment. + (FIXED_REGISTERS, CALL_USED_REGISTERS): Add new register. + (MD_REG_LAST): Increment. + (ST_REG_FIRST, ST_REG_LAST): Increment. + (HILO_REGNUM): Define. + (enum reg_class): Add HILO_REG. + (REG_CLASS_NAMES): Add "HILO_REG". + (REG_CLASS_CONTENTS): Add HILO_REG initializer, and adjust ST_REGS + and ALL_REGS initializers. + (SECONDARY_RELOAD_CLASS): Remove. + (SECONDARY_INPUT_RELOAD_CLASS): Define. + (SECONDARY_OUTPUT_RELOAD_CLASS): Define. + (REGISTER_MOVE_COST): Treat HILO_REG as MD_REGS. + (REGISTER_NAMES): Add initialization line. + (DEBUG_REGISTER_NAMES): Add "accum". + * mips/mips.md: For each instruction which sets HI or LO, clobber + HILO_REGNUM with (clobber (match_scratch:MODE N "=a")). Change + each explicit reference to register 66 to register 67. + (mulsidi3): Change to define_expand. + (mulsidi3_internal): New name of old mulsidi3. + (mulsidi3_64bit): New insn. + (umulsidi3): Change to define_expand. + (umulsidi3_internal): New name of old umulsidi3. + (umulsidi3_64bit): New insn. + (madddi_64bit, umaddi_64bit): New insns. + (movdi_internal2): Add case for setting HILO_REG to zero. + (reload_indi, reload_outdi): New define_expands. + (movsi_internal1, movsi_internal2): Add cases for setting MD_REGS + to zero, and for setting a general reg to HILO_REG. + (reload_outsi): New define_expand. + * mips/mips.c (mips_reg_names): Add "accum". + (mips_sw_reg_names): Likewise. + (mips_regno_to_class): Map HILO_REGNUM to HILO_REG. + (mips_move_1word): Handle moving HILO_REGNUM to a general + register. Make sure that the normal MD_REG cases aren't used for + HILO_REGNUM. Handle moving zero to a MD_REG. + (mips_move_2words): Make sure that the normal MD_REG cases aren't + used for HILO_REGNUM. Handle moving zero to a MD_REG. + (override_options): Set mips_char_to_class for 'a' and 'b'. + (mips_secondary_reload_class): Add in_p argument. Handle + HILO_REGNUM. + +Mon Mar 27 07:16:05 1995 Warner Losh + + * gcc.c: Removed __NetBSD__ from conditional. + Declare strerror if HAVE_STRERROR is defined; otherwise + declare sys_errlist and sys_nerr. + (my_strerror): New function. + +Fri Mar 24 18:08:14 1995 Jason Merrill + + * i386/linux.h (LIB_SPEC): Don't try to link with libraries we + know only exist in archive form unless -static. + +Fri Mar 24 16:12:16 1995 Doug Evans + + * Makefile.in (multilib.h): Depend on Makefile, not config.status. + +Fri Mar 24 15:01:17 1995 Michael Meissner + + * rs6000/rs6000.h (TARGET_MULTIPLE_SET): New target_flags bit that + indicates -mmultiple or -mno-multiple was explicitly passed by the + user, and not set as part of the cpu defaults. + (TARGET_SWITCHES): Set TARGET_MULTIPLE_SET bit for both -mmultiple + and -mno-multiple. + + * rs6000/rs6000.c (rs6000_override_options): If -mmultiple or + -mno-multiple was explicitly used, don't override the setting with + the processor default. + +Wed Mar 22 21:42:13 1995 Doug Evans + + * i960/i960.c (i960_function_arg_advance): Ensure all regs marked + as used if stack is also used (for va_start). + (i960_setup_incoming_varargs): Rewrite to be similar to Intel's + version, but don't allocate reg block unless necessary. + * ginclude/va-i960.h (varargs va_start): Save g14 explicitly. + Account for arguments preceding va_alist. + +Wed Mar 22 13:24:55 1995 Torbjorn Granlund + + * pa.c (singlemove_string): Handle SFmode constants again. Simplify. + (zdepi_cint_p): Make some variables HOST_WIDE_INT. + (lhs_lshift_cint_operand): Likewise. + (output_and): Likewise. + (output_ior): Likewise. + +Wed Mar 22 12:40:09 1995 Jim Wilson + + * sh.md (udivsi3): Don't clobber register 6. + (udivsi3, divsi3, mulsi3_call): Use a pseudo-reg with regclass 'z' + for output rather than hard register 0. + (block_move_real): Don't clobber registers 4 and 5. + + * mips.c (mips_select_section): Apply constant DEC_INITIAL tests + only to VAR_DECLs. + +Wed Mar 22 03:53:17 1995 Richard Stallman + + * config.sub (rm400, rm600): New machine names. + (sinix5.*, sinix): New os aliases. + (mips-siemens): Default os to sysv4. + +Mon Mar 20 21:56:47 1995 Per Bothner + + Merged Paul Eggert's patch to cccp.c of Wed Mar 8 18:21:51 1995: + * cpplib.c (do_include): Fix type typo: pcfbuflimit is char *, not int. + + Merged Doug Evans' patch to cccp.c of Mon Feb 27 17:06:47 1995: + * cpplib.c (do_include): Check for redundant file before opening in + relative path case. Don't call fstat unnecessarily. + + Merged J.T. Conklin's patch to cccp.c of Wed Feb 22 20:29:31 1995: + * cpperror.c: Removed __NetBSD__ from conditional. + + Merged Kenner's patch to cccp.c & cexp.y of Tue Sep 20 17:49:47 1994: + * cppexp.c (struct operation): Make value by HOST_WIDE_INT. + (cpp_parse_expr): Change return type to HOST_WIDE_INT. + * cpplib (eval_if_expr): Likewise. + (do_if, do_elif): Update appropriately. + * cpplib.h (cpp_parse_expr): Removed, to avoid defining HOST_WIDE_INT. + + Merged Paul Eggert's patch to cccp.c of Mon Aug 8 19:42:09 1994: + * cpplib.c (create_definition): Warn about `#define a@', since a + diagnostic is now required (see ISO TC1's addition to subclause 6.8). + Also warn about `#define is-empty(x) (!x)'. + +Tue Mar 21 00:10:50 1995 Jeffrey A. Law + + * x-pa (CC): Add "-Dbsd4_4". + +Mon Mar 20 18:40:31 1995 Per Bothner + + * toplev.c (print_error_function): New function hook. + (default_print_error_function): New function. Default value + of print_error_function. Code moved here from report_error_function. + (report_error_function): Use print_error_function hook. + +Mon Mar 20 20:27:43 1995 Doug Evans + + * cccp.c (do_xifdef): Handle c++ comments. + (do_endif): Likewise. + +Mon Mar 20 15:31:45 1995 Jason Merrill + + * configure (i386 configurations): Prepend i386/ to t-crt*. + +Mon Mar 20 07:58:04 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * stmt.c (fixup_gotos): Add missing call from last change. + + * objc/misc.c: Put Alpha-specific decls before #include of runtime.h. + + * alpha.h (EXTRA_SECTIONS): Write zeros first time in .rdata. + +Sat Mar 18 16:37:24 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * flow.c (mark_used_regs, case SUBREG): Set reg_changes_size even + for integer modes. + (mark_used_regs): Set reg_changes_size for RHS, if necessary. + * combine.c (gen_lowpart_for_combine): Set reg_changes_size, if needed. + * reload.c (push_reload): Reload a SUBREG if paradoxical and + class is CLASS_CANNOT_CHANGE_SIZE. + * reload1.c (gen_reload): Handle paradoxical SUBREGs. + * alpha.h (SECONDARY_{INPUT,OUTPUT}_RELOAD_CLASS): Need GENERAL_REGS + for paradoxical SUBREG and FLOAT_REGS. + (SECONDARY_NEEDED_MODE): Use actual mode for 4 bytes or wider. + * alpha.md (movsi): Allow FP regs and add case for store of FP reg. + Remove cvtlq from MEM to FP reg case. + + * rtl.h (emit_insns_after): Add declaration. + * stmt.c (fixup_gotos): Do a cleanup for a block when it is exited + even if label if not defined yet. + + * function.c (pop_function_context): Fix error in last change; + reference old value of current_function_decl before we modify it. + +Fri Mar 17 21:57:44 1995 Jason Merrill + + * toplev.c (rest_of_compilation): Handle -Wreturn-type properly + for inlines we aren't compiling yet. + +Fri Mar 17 21:26:48 1995 Mike Stump + + * libgcc2.c (__register_exceptions): Handle empty tables. + +Fri Mar 17 11:48:31 1995 Douglas Rupp (drupp@cs.washington.edu) + + * i386/winnt.c (winnt_function_prologue): Deleted. + (gen_stdcall_suffix): New function. + +Thu Mar 16 17:36:52 1995 Jason Merrill + + * svr4.h (LINK_SPEC): If the user did not specify -h name, use the + output file name, if any. + * sparc/sol2.h (LINK_SPEC): Ditto. Also, if the user did not + specify -R path, add an -R for each -L. + + Move SunOS 4-specific assembler switches into the appropriate place. + * m68k/sun[23].h (ASM_SPEC): Add %{R} %{j} %{J} %{h} %{d2} + %{keep-local-as-symbols:-L}. + * i386/sun.h (ASM_SPEC): Add %{R} %{keep-local-as-symbols:-L}. + * sparc/sparc.h (ASM_SPEC): Ditto. + * gcc.c (default_compilers): Remove %{R} %{j} %{J} %{h} %{d2} + %{keep-local-as-symbols:-L} from assembler rules. + +Thu Mar 16 16:58:09 1995 Michael Meissner + + * rs6000/eabi-ctors.c: New file, handle C++ static constructors + and destructors without requiring anything else from a libc. + + * rs6000/t-eabi (LIB2FUNCS_EXTRA): Build eabi-ctors.c. + + * rs6000/eabi.asm: Do not load up register 2 if there is no .got + section. Jump to the __do_global_ctors function at the end of + processing to call C++ static constructors, and it will return to + __eabi's caller. Use normal volatile registers, instead of saving + and restoring registers 30 and 31. + + * rs6000/eabi.h (STARTFILE_SPEC): Define as null. + (LIB_SPEC): Ditto. + (ENDFILE_SPEC): Ditto. + (LIBGCC_SPEC): Always look for libgcc.a. + +Thu Mar 16 17:05:14 1995 Richard Kenner + + * stmt.c (warn_if_unused_value, case SAVE_EXPR): New case. + (warn_if_unused_value, case NOP_EXPR): OK if CALL_EXPR inside. + + * c-common.c (decl_attributes): Allow alignment for TYPE_DECLs. + + * Makefile.in (xsys-protos.h): Fix typo in -U operand. + +Thu Mar 16 13:49:10 1995 Per Bothner + + * cpplib.c, cpplib.h: New files - a C PreProcessor library. + * cpphash.c, cpphash.h, cppalloc.c, cpperror.c, cppexp.c: + New files - utility features used by cpplib. + * cppmain.c: New file - cpp replacement main program for cpplib. + * Makefile.in: New rules to build cppmain. + +Thu Mar 16 16:11:05 1995 Douglas Rupp (drupp@cs.washington.edu) + + * i386/winnt.h (FUNCTION_PROLOGUE, HAVE_probe, gen_probe): Deleted. + (ENCODE_SECTION_INFO, VALID_MACHINE_DECL_ATTRIBUTE): New macro. + +Thu Mar 16 15:58:24 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * combine.c (apply_distributive_law, case SUBREG): Fix typo when + checking for paradoxical SUBREG. + +Wed Mar 15 18:45:08 1995 Doug Evans + + * libgcc1-test.c: Renamed from cross-test.c. + * Makefile.in (LIBGCC1_TEST): Renamed from CROSS_TEST. + (all.cross): Delete $(ENQUIRE) dependency. + (libgcc1-test): Renamed from cross-test. + Delete unnecessary gcc-cross and $(LIBGCC) dependencies. + Link with -nostartfiles -nostdlib + `$(GCC_FOR_TARGET) --print-libgcc-file-name`. + (libgcc1-test.o): Renamed from cross-test.o. + Change gcc-cross dependency to xgcc since the latter is used. + +Wed Mar 15 13:49:21 1995 Jason Merrill + + * tree.c (save_tree_status): Now takes a tree 'context' instead of + a boolean 'toplevel' as an argument. If 'context' is not + current_function_decl, create a new obstack for the new function. + Also save inline_obstacks. + (restore_tree_status): No longer takes a second argument. Also + restore inline_obstacks. + (temporary_allocation): Clear inline_obstacks. + (permanent_allocation): Free up the obstacks in inline_obstacks. + + * function.h (struct function): New fields contains_functions and + inline_obstacks. + + * function.c (push_function_context_to): Now takes a tree + 'context' instead of a boolean 'toplevel' as an argument. + Also save current_function_contains_functions. + (push_function_context): Pass current_function_decl to it. + (pop_function_context_from): Takes 'context' instead of 'toplevel'. + Set current_function_contains_functions properly. + (pop_function_context): Pass current_function_decl to it. + +Wed Mar 15 14:53:09 1995 Michael Meissner + + * rs6000/rs6000.md (abssi2): Turn into a define_expand. If + TARGET_POWER, do old code that uses the abs instruction. If not, + do abs in three instructions, using a temporary register, which + enables generating more reasonable code for sne. Add a recognizer + for negative of the absolute value. Add define_splits for the + PowerPC. + (sne insn): Add a recognizer for sne on the PowerPc to use two + instructions, compared to the four generated using the absolute + value insn. + +Tue Mar 14 18:38:40 1995 J.T. Conklin + + * m68k.md ({add,sub,mul,div}[sdx]f3): Add new patterns for recognizing + SImode, HImode, and QImode operands. + +Mon Mar 13 18:59:36 EST 1995 David Edelsohn + + * rs6000.h (CPP_SPEC): Add PPC403. + (processor_type): Add PPC403. + (RTX_COSTS): Add PPC403. + * powerpc.h (CPP_SPEC): Add PPC403. + * sysv4.h (CPP_SPEC): Add PPC403. + * rs6000.c (processor_target_table): Add PPC403. + * rs6000.md (define_attr cpu and function units): Add PPC403. + +Mon Mar 13 14:40:23 1995 Michael Meissner + + * rs6000/rs6000.md (call, call_value insns): Do not put a nop + after a bl instruction on System V.4 and eABI. + + * rs6000/sysv.4 (SUBTARGET_SWITCHES): Add support for + -mno-traceback to suppress the V.4 traceback word. + (ASM_DECLARE_FUNCTION_NAME): Don't put out a traceback work if + -mno-traceback. + +Mon Mar 13 13:36:37 1995 Jason Merrill + + * t-svr4, i386/t-{crtpic,sol2}, m88k/t-svr4, sparc/t-sol2: + Use -fPIC, rather than -fpic, for building crtstuff. + +Sat Mar 11 17:27:08 1995 Jason Merrill + + * configure: Use aix3newas.h for AIX 3.2.4 and 5. + * rs6000/aix41.h: Undefine ASM_OUTPUT_EXTERNAL{,_LIBCALL}. + * rs6000/aix3newas.h: New file. Define ASM_SPEC to -u, and + undefine ASM_OUTPUT_EXTERNAL{,_LIBCALL}. + +Sat Mar 11 06:42:50 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * dbxout.c (dbxout_symbol): Properly handle decl whose DECL_NAME + points to a TYPE_DECL with a zero TYPE_NAME. + +Fri Mar 10 18:18:33 1995 Torbjorn Granlund + + * pa.h (PROMOTE_MODE): Define. + +Fri Mar 10 14:37:58 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * sdbout.c (sdbout_record_type_name): If TYPE_NAME is + a TYPE_DECL, get name from DECL_NAME. + +Fri Mar 10 14:09:26 1995 Doug Evans + + * arm/riscix.h (SUBTARGET_SWITCHES): Renamed from + ARM_EXTRA_TARGET_SWITCHES. + * arm/riscix1-1.h (SUBTARGET_SWITCHES): Likewise. + * arm.h (SUBTARGET_SWITCHES): Likewise. + (TARGET_HARD_FLOAT, TARGET_SOFT_FLOAT): Define. + (TARGET_SWITCHES): Add -msoft-float, -mhard-float. + (BYTES_BIG_ENDIAN): Delete #ifndef/#endif. + (CONDITIONAL_REGISTER_USAGE): If -msoft-float, disable fp regs. + (FUNCTION_VALUE): R16 is return reg only if !-msoft-float. + (LIBCALL_VALUE): Likewise. + * arm.md (all fp patterns): Conditionalize on TARGET_HARD_FLOAT. + (*movsf_soft_insn, *movdf_soft_insn): New patterns. + +Fri Mar 10 13:53:46 1995 Jim Wilson + + * reorg.c (steal_delay_list_from_target): Exit at the top if the + branch in SEQ is not a single set. + + * sh.md (movdi define_split, movdf define_split): Correct indentation + and formatting. Make the condition fail if an operand is a MEM + with an auto-inc address. + + * varasm.c (copy_constant): Copy operand of ADDR_EXPR if it is a + constant. + + * mips/abi64.h (SETUP_INCOMING_VARARGS): Correct arguments to + move_block_from_reg call. + + * expr.c (expand_assignment): When offset is zero, make new MEM + before setting MEM_VOLATILE_P. + + * reload.c (find_reloads, case 'o'): Accept a fully reloaded + auto-increment address. + + * combine.c (max_uid_cuid): New static variable. + (INSN_CUID): Call abort if INSN is out of range. + (combine_instructions): Set max_uid_cuid. Set uid_cuid directly + instead of through INSN_CUID. + (get_last_value): Use prev_real_insn instead of prev_nonnote_insn. + Ignore USE insns generated by combine. + +Fri Mar 10 13:47:08 1995 Rod Barman + + * m68k/fpgnulib.c (__fixdfsi): Catch values < 0.5 in magnitude. + +Fri Mar 10 12:02:33 1995 Ian Lance Taylor + + * fixincludes: Fix `typedef struct term;' on hppa1.1-hp-hpux9. + +Fri Mar 10 05:50:11 1995 Oliver Kellogg (Oliver.Kellogg@RST13.DASA.DBMAIL.d400.de) + + * 1750a.c (sectname): Reverse Init and Normal. + (print_operand_address, case PLUS): Add case for LABEL_REF. + (print_operand_address, case LABEL_REF): Split fom SYMBOL_REF. + (print_operand_address, case CODE_LABEL): New case. + (ASM_FILE_END): Delete. + * 1750a.h (FUNCTION_EPILOGUE): Restore stack before freeing local vars. + (DEFAULT_SIGNED_CHAR): Now 1. + (DATA_SECTION_ASM_OP): Use pseudo-op for read-only data (later copied). + (JUMP_TABLES_IN_TEXT_SECTION): Define. + (ASM_OUTPUT_ASCII): Split into multiple lines if long. + (ASM_OUTPUT_{CHAR,SHORT,INT,LONG_INT}): Split up. + (ASM_OUTPUT_COMMON): Call check_section. + +Thu Mar 9 12:46:53 1995 Michael Meissner + + * rs6000.md (movsf): Do not call truncdfsf2 for non PowerPC + when expanding a store to memory and -msoft-float was used. + +Thu Mar 9 08:51:35 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * c-decl.c (start_function): Handle new parameter ATTRIBUTES. + * c-tree.h (start_function): Add new parameter. + * c-lang.c (finish_file): Pass new parm to start_function. + * objc-act.c (build_module_descriptor, really_start_method): Likewise. + * c-parse.in (fndef, nested_function): Pass prefix_attributes + to start_function. + (setspecs): Save prefix_attributes in declspec_stack. + (decl rules): Restore prefix_attributes along with current_declspecs. + (setattrs): Concatenate prefix_attributes to previous value. + * c-common.c (decl_attributes): Handle prefix and suffix attributes + the same way. + + * print-tree.c (print_node): Fix typo in printing large INTEGER_CST. + + * varasm.c (assemble_variable): Consistently use DECL_SIZE for + everything. + + * c-typeck.c (convert_for_assignment): Fix typo in testing for + pointer to function type. + + * varasm.c (record_constant_1): Handle NON_LVALUE_EXPR. + Rewrite to use switch instead of if/then/elseif/else. + +Wed Mar 8 18:21:51 1995 Paul Eggert + + * cccp.c (do_include): Fix type typo: pcfbuflimit is char *, not int. + +Wed Mar 8 17:30:29 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * fold-const.c (force_fit_type): Always propagate OVERFLOW. + + * rtl.def (INLINE_HEADER): Add new "e" field. + * rtl.h (FORCED_LABELS): New field; other fields adjusted. + (gen_inline_header_rtx): New parm FORCED_LABELS. + * emit-rtl.c (gen_inline_header): Add new parm FORCED_LABELS. + * integrate.c (initialize_for_inline, output_inline_function): + Handle FORCED_LABELS. + +Wed Mar 8 13:47:20 1995 Jason Merrill (jason@cygnus.com) + + * alpha.h (WORD_SWITCH_TAKES_ARG): Add -rpath. + (LINK_SPEC): Pass through -taso and -rpath. + * alpha/osf12.h (LINK_SPEC): Ditto. + +Wed Mar 8 09:59:56 1995 Michael Meissner + + * rs6000/eabi.asm: Rewrite so that the initialized pointers go + into the .got2 section, which allows eabi.asm to be assembled with + the -mrelocatable option. Move the data picked up from the bl + instruction to before the traceback tag. + + * rs6000/sysv4.h (CPP_SPEC): Define _RELOCATABLE if -mrelocatable + switch is used. + + * libgcc2.c (__new_handler): Don't initialize the pointer variable + with the address of __default_new_handler, which may not work in + some shared library mechanisms. + (__builtin_new): If __new_handler is NULL, call the function + __default_new_handler. + +Tue Mar 7 17:34:59 1995 Ian Lance Taylor + + * i960.h (PROCESS_PRAGMA): Define. + (ROUND_TYPE_ALIGN): Pass maximum of COMPUTED and SPECIFIED to + i960_round_align. + (ROUND_TYPE_SIZE): Delete. + * i960.c (process_pragma): Uncomment, and rewrite for gcc 2. + (i960_round_size): Delete. + (i960_round_align): Don't adjust suggested alignment downward. + Restrict alignment to value set by #pragma align. + +Tue Mar 7 12:14:46 1995 Doug Evans + + * configure (sparc64-*-elf): Add crtbegin.o, crtend.o to extra_parts. + * sparc/sp64-elf.h (TARGET_VERSION): Define. + (CPP_PREDEFINES): Delete sun, sparc, unix. Delete OS assertions. + (ASM_SPEC): Define. + (LINK_SPEC): Delete solaris stuff, this is an embedded target. + (STARTFILE_SPEC, ENDFILE_SPEC): Define. + +Mon Mar 6 17:54:01 1995 Doug Evans + + * Makefile.in (install-common): Fix typo in installation of cpp. + Likewise with gcc-cross. + +Mon Mar 6 02:29:05 1995 Jeffrey A. Law + + * pa.md (movsicc): New expander. + +Fri Mar 3 13:34:20 1995 Michael Meissner (meissner@cygnus.com) + + * rs6000/sysv4.h (ASM_SPEC): If -mrelocatable was passed to + compiler, pass it on to the assembler. + +Fri Mar 3 12:11:28 1995 Ian Lance Taylor + + * fixincludes: Add fixes for VxWorks header files. + * ginclude/stddef.h: If VxWorks typedef macros are defined, invoke + them as appropriate. + +Fri Mar 3 05:48:54 1995 Paul Eggert + + * cccp.c (dump_single_macro): Fix typo: % wasn't properly + doubled in printf formats. + +Thu Mar 2 19:44:02 1995 Jason Merrill + + * expr.c (expand_expr, CLEANUP_POINT_EXPR): Force the operand out + of memory before running cleanups. + +Thu Mar 2 19:15:24 1995 Paul Eggert + + * cccp.c (rescan): Prevent accidental token-pasting to + get !=, *=, /=, ==, or ^=. + +Thu Mar 2 15:37:13 1995 Jason Merrill + + * c-typeck.c (build_binary_op): Avoid spurious warning + comparing enumerator to unsigned variable. + +Thu Mar 2 18:18:38 1995 J.T. Conklin + + * m68k.md (sqrtsf2,sqrtdf2): Use fp precision specifiers. + +Thu Mar 2 18:09:01 1995 Stephen L Moshier (moshier@world.std.com) + + * c-lex.c (yylex, case !NOT_FLOAT): Remove previous change. + +Thu Mar 2 15:26:50 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Makefile.in (bootstrap*): Pass new STAGE_PREFIX to recursive makes. + +Wed Mar 1 14:52:16 1995 Ian Lance Taylor + + * i960/i960-coff.h (ASM_FILE_START): Define. + (CTORS_SECTION_ASM_OP, DTORS_SECTION_ASM_OP): Define. + (EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS): Define. + (CTORS_SECTION_FUNCTION, DTORS_SECTION_FUNCTION): Define. + (INT_ASM_OP): Define. + (ASM_OUTPUT_CONSTRUCTOR, ASM_OUTPUT_DESTRUCTOR): Define. + * i960/vx960-coff.h (CPP_PREDEFINES): Define. + (CPP_SPEC): Define. + (CC1_SPEC): Default to -mca. + +Wed Mar 1 11:10:54 1995 Michael Meissner (meissner@cygnus.com) + + * rs6000/rs6000.c (output_prologue): Do not emit the word that + gives the PC relative location to the local GOT table for the + -mrelocatable option here. + * rs6000/sysv4.h (ASM_DECLARE_FUNCTION_NAME): Emit it here. + + * t-eabi (MULTILIB_OPTIONS, MULTILIB_DIRNAMES): Build -msoft-float + and -mrelocatable versions of the library. + + * rs6000/powerpc.h (CPP_PREDEFINES): Define the cpu and machine as + powerpc, not rs6000. + + * libgcc2.c (_unwind_function): Clone for powerpc, using the + PowerPC mnemonics. + + * rs6000/rs6000.md (uminsi3, umaxsi3): Silence warnings that + -2147483648 is too large to fit in a signed integer on 32-bit + hosts. + +Wed Mar 1 06:48:31 1995 Richard Kenner + + * fold-const.c (decode_field_reference): Don't check TREE_CODE + of EXP; let get_inner_reference decide if have reference. + Allow no bit reference if have AND_MASK. + (all_ones_mask_p): Use tree_int_cst_equal, not operand_equal_p. + (unextend): New function. + (fold_truthop): For constant cases, use new function, rework + conversion, and warn if comparison can never be true. + + * expr.c (store_expr): Do conversion in two steps for promoted lhs. + +See ChangeLog.9 for earlier changes. diff --git a/contrib/gcc/Makefile.in b/contrib/gcc/Makefile.in new file mode 100644 index 00000000000..0eaa67bed09 --- /dev/null +++ b/contrib/gcc/Makefile.in @@ -0,0 +1,2538 @@ +# Makefile for GNU C compiler. +# Copyright (C) 1987, 88, 90-94, 1995 Free Software Foundation, Inc. + +#This file is part of GNU CC. + +#GNU CC is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2, or (at your option) +#any later version. + +#GNU CC is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with GNU CC; see the file COPYING. If not, write to +#the Free Software Foundation, 59 Temple Place - Suite 330, +#Boston MA 02111-1307, USA. + +# The targets for external use include: +# all, doc, proto, install, install-cross, install-cross-rest, +# uninstall, TAGS, mostlyclean, clean, distclean, maintainer-clean, +# stage1, stage2, stage3, stage4. + +# Suppress smart makes who think they know how to automake Yacc files +.y.c: + +# Variables that exist for you to override. +# See below for how to change them for certain systems. + +# List of language subdirectories. +# This is overridden by configure. +SUBDIRS = + +# Selection of languages to be made. +# This is overridden by configure. +LANGUAGES = c objective-c proto + +ALLOCA = +ALLOCA_FLAGS = +ALLOCA_FINISH = true + +# Various ways of specifying flags for compilations: +# CFLAGS is for the user to override to, e.g., do a bootstrap with -O2. +# BOOT_CFLAGS is the value of CFLAGS to pass +# to the stage2 and stage3 compilations +# XCFLAGS is used for most compilations but not when using the GCC just built. +XCFLAGS = +CFLAGS = -g +BOOT_CFLAGS = -O $(CFLAGS) +# These exists to be overridden by the x-* and t-* files, respectively. +X_CFLAGS = +T_CFLAGS = + +X_CPPFLAGS = +T_CPPFLAGS = + +CC = cc +BISON = bison +BISONFLAGS = +LEX = flex +LEXFLAGS = +AR = ar +OLDAR_FLAGS = qc +AR_FLAGS = rc +SHELL = /bin/sh +# on sysV, define this as cp. +INSTALL = install -c +# These permit overriding just for certain files. +INSTALL_PROGRAM = $(INSTALL) +INSTALL_DATA = $(INSTALL) +MAKEINFO = makeinfo +TEXI2DVI = texi2dvi +# For GNUmake: let us decide what gets passed to recursive makes. +MAKEOVERRIDES = + +# Define this as & to perform parallel make on a Sequent. +# Note that this has some bugs, and it seems currently necessary +# to compile all the gen* files first by hand to avoid erroneous results. +P = + +# How to invoke ranlib. +RANLIB = ranlib +# Test to use to see whether ranlib exists on the system. +RANLIB_TEST = [ -f /usr/bin/ranlib -o -f /bin/ranlib ] + +# Compiler to use for compiling libgcc1.a. +# OLDCC should not be the GNU C compiler, +# since that would compile typical libgcc1.a functions such as mulsi3 +# into infinite recursions. +OLDCC = cc + +# CFLAGS for use with OLDCC, for compiling libgcc1.a. +# NOTE: -O does not work on some Unix systems! +CCLIBFLAGS = -O + +# Version of ar to use when compiling libgcc1.a. +OLDAR = ar + +# Target to use when installing include directory. Either +# install-headers-tar or install-headers-cpio. +INSTALL_HEADERS_DIR = install-headers-tar + +# Header files that are made available under the same name +# to programs compiled with GCC. +USER_H = $(srcdir)/ginclude/stdarg.h $(srcdir)/ginclude/stddef.h \ + $(srcdir)/ginclude/varargs.h $(srcdir)/ginclude/va-alpha.h \ + $(srcdir)/ginclude/va-h8300.h $(srcdir)/ginclude/va-i860.h \ + $(srcdir)/ginclude/va-i960.h $(srcdir)/ginclude/va-mips.h \ + $(srcdir)/ginclude/va-m88k.h $(srcdir)/ginclude/va-pa.h \ + $(srcdir)/ginclude/va-pyr.h $(srcdir)/ginclude/va-sparc.h \ + $(srcdir)/ginclude/va-clipper.h $(srcdir)/ginclude/va-spur.h \ + $(srcdir)/ginclude/iso646.h $(srcdir)/ginclude/va-ppc.h \ + $(srcdir)/ginclude/proto.h $(EXTRA_HEADERS) + +# Target to use whe installing assert.h. Some systems may +# want to set this empty. +INSTALL_ASSERT_H = install-assert-h + +# The GCC to use for compiling libgcc2.a, enquire, and libgcc1-test. +# Usually the one we just built. +# Don't use this as a dependency--use $(GCC_PASSES) or $(GCC_PARTS). +GCC_FOR_TARGET = ./xgcc -B./ + +# This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET. +# It omits XCFLAGS, and specifies -B./. +# It also specifies -I./include to find, e.g., stddef.h. +GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) -I./include + +# Special flags for compiling enquire. +# We disable optimization to make floating point more reliable. +ENQUIRE_CFLAGS = -DNO_MEM -DNO_LONG_DOUBLE_IO -O0 +ENQUIRE_LDFLAGS = $(LDFLAGS) + +# Sed command to transform gcc to installed name. Overwritten by configure. +program_transform_name = -e s,x,x, +program_transform_cross_name = -e s,^,$(target)-, + +# Tools to use when building a cross-compiler. +# These are used because `configure' appends `cross-make' +# to the makefile when making a cross-compiler. + +TARGET_TOOLPREFIX = $(tooldir)/bin/ +AR_FOR_TARGET = $(TARGET_TOOLPREFIX)ar +AR_FOR_TARGET_FLAGS = rc +RANLIB_FOR_TARGET = $(TARGET_TOOLPREFIX)ranlib +RANLIB_TEST_FOR_TARGET = [ -f $(TARGET_TOOLPREFIX)ranlib ] + +# Dir to search for system headers. Overridden by cross-make. +SYSTEM_HEADER_DIR = /usr/include + +# Control whether to run fixproto. +STMP_FIXPROTO = stmp-fixproto + +# Test to see whether exists in the system header files. +LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h ] + +# There may be a premade insn-attrtab.c for this machine. +# (You could rebuild it with genattrtab as usual, but it takes a long time.) +# PREMADE_ATTRTAB is the file name of the file to use. +# PREMADE_ATTRTAB_MD is the md file it corresponds to. +PREMADE_ATTRTAB_MD = Makefile # Guaranteed not to cmp equal to md. +PREMADE_ATTRTAB = + +target= ... `configure' substitutes actual target name here. +xmake_file= ... `configure' substitutes actual x- file name here. +tmake_file= ... `configure' substitutes actual t- file name here. +out_file= ... `configure' substitutes actual out file name here. +out_object_file= ... `configure' substitutes actual out object file name here. +md_file= ... `configure' substitutes actual md file name here. +tm_file= ... `configure' substitutes actual tm file name here. +build_xm_file= ... `configure' substitutes actual build xm- file name here. +host_xm_file= ... `configure' substitutes actual host xm- file name here. +lang_specs_files= ... `configure' substitutes actual lang spec file names here. +lang_options_files= ... `configure' puts actual lang options file names here. +version=`sed -e 's/.*\"\([^ \"]*\)[ \"].*/\1/' < $(srcdir)/version.c` +mainversion=`sed -e 's/.*\"\([0-9]*\.[0-9]*\).*/\1/' < $(srcdir)/version.c` + +# Directory where sources are, from where we are. +srcdir = . +# Common prefix for installation directories. +# NOTE: This directory must exist when you start installation. +prefix = /usr/local +# Directory in which to put localized header files. On the systems with +# gcc as the native cc, `local_prefix' may not be `prefix' which is +# `/usr'. +# NOTE: local_prefix *should not* default from prefix. +local_prefix = /usr/local +# Directory in which to put host dependent programs and libraries +exec_prefix = $(prefix) +# Directory in which to put the executable for the command `gcc' +bindir = $(exec_prefix)/bin +# Directory in which to put the directories used by the compiler. +libdir = $(exec_prefix)/lib +# Directory in which the compiler finds executables, libraries, etc. +libsubdir = $(libdir)/gcc-lib/$(target)/$(version) +# Directory in which the compiler finds g++ includes. +gxx_include_dir= $(libdir)/g++-include +# Directory to search for site-specific includes. +includedir = $(local_prefix)/include +# assertdir is overridden in cross-make. +# (But this currently agrees with what is in cross-make.) +assertdir = $(tooldir)/include +# where the info files go +infodir = $(prefix)/info +# Extension (if any) to put in installed man-page filename. +manext = .1 +objext = .o +exeext = + +# Directory in which to put man pages. +mandir = $(prefix)/man/man1 +# Directory in which to find other cross-compilation tools and headers. +# Used in install-cross. +tooldir = $(exec_prefix)/$(target) +# Dir for temp files. +tmpdir = /tmp + +# Additional system libraries to link with. +CLIB= + +# Change this to a null string if obstacks are installed in the +# system library. +OBSTACK=obstack.o + +# Specify the rule for actually making libgcc.a, +LIBGCC = libgcc.a +# and the rule for installing it. +INSTALL_LIBGCC = install-libgcc + +# Specify the rule for actually making libgcc1.a. +# The value may be empty; that means to do absolutely nothing +# with or for libgcc1.a. +LIBGCC1 = libgcc1.a + +# Specify the rule for making libgcc1.a for a cross-compiler. +# The default rule assumes that libgcc1.a is supplied by the user. +CROSS_LIBGCC1 = libgcc1.cross + +# Specify the rule for actually making libgcc2.a. +LIBGCC2 = libgcc2.a + +# Options to use when compiling libgcc2.a. +# -g1 causes output of debug info only for file-scope entities. +# we use this here because that should be enough, and also +# so that -g1 will be tested. +LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) -g1 + +# Additional options to use when compiling libgcc2.a. +# Some targets override this to -Iinclude +LIBGCC2_INCLUDES = + +# Additional target-dependent options for compiling libgcc2.a. +TARGET_LIBGCC2_CFLAGS = + +# Things which must be built before building libgcc2.a. +# Some targets override this to stmp-int-hdrs +LIBGCC2_DEPS = + +# Enquire target (This is a variable so that a target can choose not to +# build it.) +ENQUIRE = enquire + +# libgcc1-test target (must also be overridable for a target) +LIBGCC1_TEST = libgcc1-test + +# List of extra executables that should be compiled for this target machine +# that are used for compiling from source code to object code. +# The rules for compiling them should be in the t-* file for the machine. +EXTRA_PASSES = + +# Like EXTRA_PASSES, but these are used when linking. +EXTRA_PROGRAMS = + +# List of extra object files that should be compiled for this target machine. +# The rules for compiling them should be in the t-* file for the machine. +EXTRA_PARTS = + +# List of extra object files that should be compiled and linked with +# compiler proper (cc1, cc1obj, cc1plus). +EXTRA_OBJS = + +# List of extra object files that should be compiled and linked with +# the gcc driver. +EXTRA_GCC_OBJS = + +# List of additional header files to install. +# Often this is edited directly by `configure'. +EXTRA_HEADERS = + +# Set this to `ld' to enable use of collect2. +# USE_COLLECT2 = +# It is convenient for configure to add the assignment at the beginning, +# so don't override it here. + +# List of extra C and assembler files to add to libgcc1.a. +# Assembler files should have names ending in `.asm'. +LIB1FUNCS_EXTRA = + +# List of extra C and assembler files to add to libgcc2.a. +# Assembler files should have names ending in `.asm'. +LIB2FUNCS_EXTRA = + +# Default float.h source to use for cross-compiler. +CROSS_FLOAT_H=float.h-cross + +# Program to convert libraries. +LIBCONVERT = + +# Control whether header files are installed. +INSTALL_HEADERS=install-headers + +# Options for tar when copying trees. So HPUX can override it. +TAROUTOPTS = xpBf + +# Select which version of fixincludes to use (I.E. regular versus SVR4) +# This value is overridden directly by configure. +FIXINCLUDES=fixincludes + +# Additional directories of header files to run fixincludes on. +# These should be directories searched automatically by default +# just as /usr/include is. +# *Do not* use this for directories that happen to contain +# header files, but are not searched automatically by default. +# On most systems, this is empty. +OTHER_FIXINCLUDES_DIRS= + +# List of things which should already be built whenever we try to use xgcc +# to compile anything (without linking). +GCC_PASSES=xgcc cc1 cpp $(EXTRA_PASSES) + +# List of things which should already be built whenever we try to use xgcc +# to link anything. +GCC_PARTS=$(GCC_PASSES) $(LIBGCC) $(EXTRA_PROGRAMS) $(USE_COLLECT2) $(EXTRA_PARTS) + +# Directory to link to, when using the target `maketest'. +DIR = ../gcc + +# Guaranteed to not exist when not passing md through cpp. +# This value is overridden directly by configure. +MD_FILE = md-cpp-not-used + +# Flags to use when cross-building GCC. +# Prefix to apply to names of object files when using them +# to run on the machine we are compiling on. +HOST_PREFIX= +# Prefix to apply to names of object files when compiling them +# to run on the machine we are compiling on. +# The default for this variable is chosen to keep these rules +# out of the way of the other rules for compiling the same source files. +HOST_PREFIX_1=loser- +HOST_CC=$(CC) +HOST_CFLAGS=$(ALL_CFLAGS) +HOST_CLIB=$(CLIB) +HOST_LDFLAGS=$(LDFLAGS) +HOST_CPPFLAGS=$(ALL_CPPFLAGS) +HOST_ALLOCA=$(ALLOCA) +HOST_MALLOC=$(MALLOC) +HOST_OBSTACK=$(OBSTACK) + +# Actual name to use when installing a native compiler. +GCC_INSTALL_NAME = `t='$(program_transform_name)'; echo gcc | sed $$t` + +# Actual name to use when installing a cross-compiler. +GCC_CROSS_NAME = `t='$(program_transform_cross_name)'; echo gcc | sed $$t` + +# Choose the real default target. +ALL=all.internal + +# Choose the real install target. +INSTALL_TARGET=install-normal + +# Source for float.h. Overridden by cross-make. +FLOAT_H=float.h-nat + +# Extra symbols for fixproto to define when parsing headers. +FIXPROTO_DEFINES = + +# Extra flags to use when compiling crt{begin,end}.o. +CRTSTUFF_T_CFLAGS = + +# End of variables for you to override. + +# Definition of `all' is here so that new rules inserted by sed +# do not specify the default target. +# The real definition is under `all.internal' (for native compilers) +# or `all.cross' (for cross compilers). +all: all.indirect + +# This tells GNU Make version 3 not to put all variables in the environment. +.NOEXPORT: + +# sed inserts variable overrides after the following line. +####target overrides +####host overrides +####cross overrides +####build overrides + +# Now figure out from those variables how to compile and link. + +all.indirect: $(ALL) + +# IN_GCC tells obstack.h that we are using gcc's file. +# ??? IN_GCC should be obsolete now. +INTERNAL_CFLAGS = $(CROSS) -DIN_GCC + +# This is the variable actually used when we compile. +ALL_CFLAGS = $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) $(XCFLAGS) + +# Likewise. +ALL_CPPFLAGS = $(CPPFLAGS) $(X_CPPFLAGS) $(T_CPPFLAGS) + +# Even if ALLOCA is set, don't use it if compiling with GCC. +USE_ALLOCA= ` case "${CC}" in "${OLDCC}") echo "${ALLOCA}" ;; esac ` +USE_HOST_ALLOCA= ` case "${HOST_CC}"@"${HOST_ALLOCA}" in "${OLDCC}"@?*) echo ${HOST_PREFIX}${HOST_ALLOCA} ;; esac ` +USE_HOST_MALLOC= ` case "${HOST_MALLOC}" in ?*) echo ${HOST_PREFIX}${HOST_MALLOC} ;; esac ` +USE_HOST_OBSTACK= ` case "${HOST_OBSTACK}" in ?*) echo ${HOST_PREFIX}${HOST_OBSTACK} ;; esac ` + +# Dependency on obstack, alloca, malloc or whatever library facilities +# are not installed in the system libraries. +# We don't use USE_ALLOCA because backquote expansion doesn't work in deps. +LIBDEPS= $(OBSTACK) $(ALLOCA) $(MALLOC) + +# Likewise, for use in the tools that must run on this machine +# even if we are cross-building GCC. +# We don't use USE_ALLOCA because backquote expansion doesn't work in deps. +HOST_LIBDEPS= $(HOST_PREFIX)$(HOST_OBSTACK) $(HOST_PREFIX)$(HOST_ALLOCA) $(HOST_PREFIX)$(HOST_MALLOC) + +# How to link with both our special library facilities +# and the system's installed libraries. +LIBS = $(OBSTACK) $(USE_ALLOCA) $(MALLOC) $(CLIB) + +# Likewise, for use in the tools that must run on this machine +# even if we are cross-building GCC. +HOST_LIBS = $(USE_HOST_OBSTACK) $(USE_HOST_ALLOCA) $(USE_HOST_MALLOC) \ + $(HOST_CLIB) + +HOST_RTL = $(HOST_PREFIX)rtl.o +HOST_RTLANAL = $(HOST_PREFIX)rtlanal.o +HOST_PRINT = $(HOST_PREFIX)print-rtl.o + +# Specify the directories to be searched for header files. +# Both . and srcdir are used, in that order, +# so that tm.h and config.h will be found in the compilation +# subdirectory rather than in the source directory. +INCLUDES = -I. -I$(srcdir) -I$(srcdir)/config + +# Always use -I$(srcdir)/config when compiling. +.c.o: + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< + +# This tells GNU make version 3 not to export all the variables +# defined in this file into the environment. +.NOEXPORT: + +# Support for additional languages (other than c and objc). +# ??? objc can be supported this way too (leave for later). + +# These next lines are overridden by configure. +LANG_MAKEFILES = +LANG_STAGESTUFF = +LANG_DIFF_EXCLUDES = + +# Flags to pass to recursive makes. +# CC is set by configure. Hosts without symlinks need special handling +# because we need CC="stage1/xgcc -Bstage1/" to work in the language +# subdirectories. +# ??? The choices here will need some experimenting with. +FLAGS_TO_PASS = \ + "AR_FLAGS=$(AR_FLAGS)" \ + "AR_FOR_TARGET=$(AR_FOR_TARGET)" \ + "BISON=$(BISON)" \ + "BISONFLAGS=$(BISONFLAGS)" \ + "CC=set-by-configure" \ + "CFLAGS=$(CFLAGS)" \ + "GCC_FOR_TARGET=$(GCC_FOR_TARGET)" \ + "LDFLAGS=$(LDFLAGS)" \ + "LEX=$(LEX)" \ + "LEXFLAGS=$(LEXFLAGS)" \ + "MAKEINFO=$(MAKEINFO)" \ + "MAKEINFOFLAGS=$(MAKEINFOFLAGS)" \ + "RANLIB_FOR_TARGET=$(RANLIB_FOR_TARGET)" \ + "RANLIB_TEST_FOR_TARGET=$(RANLIB_TEST_FOR_TARGET)" \ + "SHELL=$(SHELL)" \ + "exeext=$(exeext)" \ + "objext=$(objext)" \ + "exec_prefix=$(exec_prefix)" \ + "prefix=$(prefix)" \ + "tooldir=$(tooldir)" \ + "bindir=$(bindir)" \ + "libsubdir=$(libsubdir)" + +# Lists of files for various purposes. + +# A list of all the language-specific executables. +# This is overridden by configure. +COMPILERS = cc1$(exeext) cc1obj$(exeext) + +# Language-specific object files for C. +C_OBJS = c-parse.o c-lang.o c-lex.o c-pragma.o \ + c-decl.o c-typeck.o c-convert.o c-aux-info.o c-common.o c-iterate.o + +# Language-specific object files for Objective C. +OBJC_OBJS = objc-parse.o objc-act.o c-lex.o c-pragma.o \ + c-decl.o c-typeck.o c-convert.o c-aux-info.o c-common.o c-iterate.o + +# Files specific to the C interpreter bytecode compiler(s). +BC_OBJS = bc-emit.o bc-optab.o + +# Bytecode header files constructed at build time; vmsconfig.com wants this. +BC_ALL = bc-arity.h bc-opcode.h bc-opname.h + +# Language-independent object files. +OBJS = toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o \ + function.o stmt.o expr.o calls.o expmed.o explow.o optabs.o varasm.o \ + rtl.o print-rtl.o rtlanal.o emit-rtl.o real.o \ + dbxout.o sdbout.o dwarfout.o xcoffout.o \ + integrate.o jump.o cse.o loop.o unroll.o flow.o stupid.o combine.o \ + regclass.o local-alloc.o global.o reload.o reload1.o caller-save.o \ + insn-peep.o reorg.o sched.o final.o recog.o reg-stack.o \ + insn-opinit.o insn-recog.o insn-extract.o insn-output.o insn-emit.o \ + insn-attrtab.o $(out_object_file) getpwd.o convert.o $(EXTRA_OBJS) + +# GEN files are listed separately, so they can be built before doing parallel +# makes for cc1 or cc1plus. Otherwise sequent parallel make attempts to load +# them before rtl.o is compiled. +GEN= genemit genoutput genrecog genextract genflags gencodes genconfig genpeep + +CCCP=cccp +# Uncomment this line if you want to use cppmain (w/cpplib) as cpp. +#CCCP=cppmain + +# Files to be copied away after each stage in building. +STAGESTUFF = *$(objext) insn-flags.h insn-config.h insn-codes.h \ + insn-output.c insn-recog.c insn-emit.c insn-extract.c insn-peep.c \ + insn-attr.h insn-attrtab.c insn-opinit.c \ + stamp-flags stamp-config stamp-codes \ + stamp-output stamp-recog stamp-emit stamp-extract stamp-peep \ + stamp-attr stamp-attrtab stamp-opinit stamp-proto stamp-crt stamp-crtS \ + genemit$(exeext) genoutput$(exeext) genrecog$(exeext) genextract$(exeext) \ + genflags$(exeext) gencodes$(exeext) genconfig$(exeext) genpeep$(exeext) \ + genattrtab$(exeext) genattr$(exeext) genopinit$(exeext) \ + $(BC_ALL) \ + stamp-bcarity stamp-bcopcode stamp-bcopname \ + bi-arity$(exeext) bi-opcode$(exeext) bi-opname$(exeext) \ + $(GCC_PASSES) $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) \ + $(CCCP)$(exeext) cc1obj$(exeext) enquire$(exeext) \ + protoize$(exeext) unprotoize$(exeext) \ + specs collect2$(exeext) $(USE_COLLECT2) underscore.c \ + *.greg *.lreg *.combine *.flow *.cse *.jump *.rtl *.tree *.loop \ + *.dbr *.jump2 *.sched *.cse2 *.sched2 *.stack \ + *.[si] \ + $(LANG_STAGESTUFF) + +# Members of libgcc1.a. +LIB1FUNCS = _mulsi3 _udivsi3 _divsi3 _umodsi3 _modsi3 \ + _lshrsi3 _ashrsi3 _ashlsi3 \ + _divdf3 _muldf3 _negdf2 _adddf3 _subdf3 \ + _fixdfsi _fixsfsi _floatsidf _floatsisf _truncdfsf2 _extendsfdf2 \ + _addsf3 _negsf2 _subsf3 _mulsf3 _divsf3 \ + _eqdf2 _nedf2 _gtdf2 _gedf2 _ltdf2 _ledf2 \ + _eqsf2 _nesf2 _gtsf2 _gesf2 _ltsf2 _lesf2 + +# Library members defined in libgcc2.c. +LIB2FUNCS = _muldi3 _divdi3 _moddi3 _udivdi3 _umoddi3 _negdi2 \ + _lshrdi3 _ashldi3 _ashrdi3 _ffsdi2 \ + _udiv_w_sdiv _udivmoddi4 _cmpdi2 _ucmpdi2 _floatdidf _floatdisf \ + _fixunsdfsi _fixunssfsi _fixunsdfdi _fixdfdi _fixunssfdi _fixsfdi \ + _fixxfdi _fixunsxfdi _floatdixf _fixunsxfsi \ + _fixtfdi _fixunstfdi _floatditf \ + __gcc_bcmp _varargs _eprintf _op_new _op_vnew _new_handler _op_delete \ + _op_vdel _bb _shtab _clear_cache _trampoline __main _exit _ctors _eh \ + _pure + +# The files that "belong" in CONFIG_H are deliberately omitted +# because having them there would not be useful in actual practice. +# All they would do is cause complete recompilation every time +# one of the machine description files is edited. +# That may or may not be what one wants to do. +# If it is, rm *.o is an easy way to do it. +# CONFIG_H = $(host_xm_file) $(tm_file) +CONFIG_H = +RTL_H = rtl.h rtl.def machmode.h machmode.def +TREE_H = tree.h real.h tree.def machmode.h machmode.def +BYTECODE_H = bytecode.h bc-emit.h bc-optab.h + +# Language makefile fragments. + +# The following targets define the interface between us and the languages. +# +# all.build, all.cross, start.encap, rest.encap, +# info, dvi, +# install-normal, install-common, install-info, install-man, +# uninstall, distdir, +# mostlyclean, clean, distclean, extraclean, maintainer-clean, +# stage1, stage2, stage3, stage4 +# +# Each language is linked in with a series of hooks (since we can't use `::' +# targets). The name of each hooked is "lang.${target_name}" (eg: lang.info). +# Configure computes and adds these here. + +####language hooks + +# sed inserts language fragments after the following line. +####language fragments + +# End of language makefile fragments. + +# Avoid a lot of time thinking about remaking Makefile.in and *.def. +.SUFFIXES: .in .def + +Makefile: $(srcdir)/Makefile.in $(srcdir)/configure $(srcdir)/version.c \ + $(srcdir)/config/$(xmake_file) $(srcdir)/config/$(tmake_file) \ + $(LANG_MAKEFILES) + cp config.status config.run + $(SHELL) config.run + rm -f config.run + +all.internal: start.encap rest.encap +# This is what to compile if making a cross-compiler. +# Note that we can compile enquire using the cross-compiler just built, +# although we can't run it on this machine. +all.cross: native gcc-cross specs stmp-headers $(LIBGCC) $(STMP_FIXPROTO) \ + $(LIBGCC1_TEST) $(EXTRA_PARTS) lang.all.cross +# This is what to compile if making gcc with a cross-compiler. +all.build: native xgcc $(EXTRA_PARTS) lang.all.build +# This is what must be made before installing GCC and converting libraries. +start.encap: native xgcc specs $(LIBGCC1) xlimits.h lang.start.encap +# These can't be made until after GCC can run. +rest.encap: stmp-headers $(LIBGCC) $(STMP_FIXPROTO) $(EXTRA_PARTS) lang.rest.encap +# This is what is made with the host's compiler +# whether making a cross compiler or not. +native: config.status cpp $(LANGUAGES) $(EXTRA_PASSES) $(EXTRA_PROGRAMS) $(USE_COLLECT2) + +# Define the names for selecting languages in LANGUAGES. +C c: cc1 +OBJC objc: cc1obj objc-runtime +OBJECTIVE-C objective-c: cc1obj objc-runtime +PROTO: proto + +# Tell GNU make these are phony targets. +.PHONY: C c OBJC objc OBJECTIVE-C objective-c PROTO proto + +# Really, really stupid make features, such as SUN's KEEP_STATE, may force +# a target to build even if it is up-to-date. So we must verify that +# config.status does not exist before failing. +config.status: + @if [ ! -f config.status ] ; then \ + echo You must configure gcc. Look at the INSTALL file for details.; \ + false; \ + else \ + true; \ + fi + +# On the target machine, finish building a cross compiler. +# This does the things that can't be done on the host machine. +rest.cross: $(LIBGCC) gfloat.h specs + +# Verify that it works to compile and link libgcc1-test. +# If it does, then there are sufficient replacements for libgcc1.a. +libgcc1-test: libgcc1-test.o native $(GCC_PARTS) + @echo "Testing libgcc1. Ignore linker warning messages." + $(GCC_FOR_TARGET) $(GCC_CFLAGS) libgcc1-test.o -o libgcc1-test \ + -nostartfiles -nostdlib `$(GCC_FOR_TARGET) --print-libgcc-file-name` +libgcc1-test.o: libgcc1-test.c native xgcc + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(ALL_CPPFLAGS) -c $(srcdir)/libgcc1-test.c + +# Recompile all the language-independent object files. +# This is used only if the user explicitly asks for it. +compilations: ${OBJS} + +# Create a list of the language-independent object files so the language +# subdirectories needn't mention their names explicitly. +stamp-objlist: Makefile $(OBJS) $(BC_OBJS) + echo " $(OBJS) $(BC_OBJS)" | sed -e 's, \([a-z]\), ../\1,g' -e 's/\.o/$(objext)/g' >stamp-objlist + +# We call this executable `xgcc' rather than `gcc' +# to avoid confusion if the current directory is in the path +# and CC is `gcc'. It is renamed to `gcc' when it is installed. +xgcc: gcc.o version.o $(LIBDEPS) $(EXTRA_GCC_OBJS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ gcc.o version.o $(EXTRA_GCC_OBJS) $(LIBS) + +# Dump a specs file to make -B./ read these specs over installed ones. +specs: xgcc + $(GCC_FOR_TARGET) -dumpspecs > tmp-specs + mv tmp-specs specs + +# We do want to create an executable named `xgcc', so we can use it to +# compile libgcc2.a. +# Also create gcc-cross, so that install-common will install properly. +gcc-cross: xgcc + cp xgcc$(exeext) gcc-cross$(exeext) + +cc1: $(P) $(C_OBJS) $(OBJS) $(BC_OBJS) $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(C_OBJS) $(OBJS) $(BC_OBJS) $(LIBS) + +cc1obj: $(P) $(OBJC_OBJS) $(OBJS) $(BC_OBJS) $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(OBJC_OBJS) $(OBJS) $(BC_OBJS) $(LIBS) + +# Copy float.h from its source. +gfloat.h: $(FLOAT_H) + -rm -f gfloat.h + cp $(FLOAT_H) gfloat.h + +# Create float.h source for the native machine. +float.h-nat: enquire + -./enquire -f > tmp-float.h + mv tmp-float.h float.h-nat + +# Create a dummy float.h source for a cross-compiler. +float.h-cross: + echo "#error float.h values not known for cross-compiler" > t-float.h-cross + mv t-float.h-cross float.h-cross + +# Used to compile enquire with standard cc, but have forgotten why. +# Let's try with GCC. +enquire: enquire.o $(GCC_PARTS) + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(ENQUIRE_LDFLAGS) enquire.o -o $@ +enquire.o: $(srcdir)/enquire.c $(GCC_PASSES) stmp-int-hdrs +# Breaking this line caused a problem with one version of GNU make. + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(ALL_CPPFLAGS) $(ENQUIRE_CFLAGS) -I. -c $(srcdir)/enquire.c + +# Build the version of limits.h that we will install. +xlimits.h: glimits.h limitx.h limity.h + if $(LIMITS_H_TEST) ; then \ + cat $(srcdir)/limitx.h $(srcdir)/glimits.h $(srcdir)/limity.h > tmp-xlimits.h; \ + else \ + cat $(srcdir)/glimits.h > tmp-xlimits.h; \ + fi + mv tmp-xlimits.h xlimits.h + +# Build libgcc.a. +# This is done in two parts because some functions, in libgcc1.c, +# must be compiled with something other than GCC, +# while the rest, in libgcc2.c, must be compiled with xgcc. +# That means we can't do libgcc2.c until after xgcc, cc1, etc. + +# Use this as value of LIBGCC1 to cause conversion to GNU library format. +# LIBCONVERT should put its output in libgcc1.conv. +libgcc1.conv: libgcc1.a + $(LIBCONVERT) libgcc1.a libgcc1.conv + +# Use this as value of LIBGCC1 to inhibit use of libgcc1.c entirely. +# Make an empty file instead. +libgcc1.null: $(GCC_PASSES) + echo "__foo () {}" > dummy.c + $(GCC_FOR_TARGET) $(GCC_CFLAGS) -c dummy.c + $(OLDAR) $(OLDAR_FLAGS) libgcc1.null dummy$(objext) + rm -f dummy$(objext) dummy.c + +# This is $(LIBGCC1) for a cross-compiler. +# We have no automatic way of building libgcc1.a, +# so it's up to the installer to find a way to do that. +# This rule deliberately does not depend on libgcc1.a +# so that it will fail if the installer hasn't provided it. +libgcc1.cross: + mv libgcc1.a libgcc1.cross || (echo You must find a way to make libgcc1.a; false) + +# Compile the library of arithmetic subroutines with the native compiler. +# Don't compile it with GCC! +# (That would cause most arithmetic functions to call themselves.) +libgcc1.a: libgcc1.c $(CONFIG_H) $(LIB1FUNCS_EXTRA) config.status + -rm -f tmplibgcc1.a +# Actually build it in tmplibgcc1.a, then rename at end, +# so that libgcc1.a itself remains nonexistent if compilation is aborted. +# -e causes any failing command to make this rule fail. +# -e doesn't work in certain shells, so we test $$? as well. +# lynx has a broken ar, it always complains when the initial library is +# empty, thus this command works only if we don't do -e +# There is a trailing backslash (\) deleted from the following line. +# set -e; + for name in $(LIB1FUNCS); \ + do \ + echo $${name}; \ + rm -f $${name}$(objext); \ + $(OLDCC) $(CCLIBFLAGS) $(INCLUDES) -c -DL$${name} $(srcdir)/libgcc1.c; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + mv libgcc1$(objext) $${name}$(objext); \ + $(OLDAR) $(OLDAR_FLAGS) tmplibgcc1.a $${name}$(objext); \ + rm -f $${name}$(objext); \ + done +# Some shells crash when a loop has no items. +# So make sure there is always at least one--`..'. +# Then ignore it. +# We don't use -e here because there are if statements +# that should not make the command give up when the if condition is false. +# Instead, we test for failure after each command where it matters. + for file in .. $(LIB1FUNCS_EXTRA); \ + do \ + if [ x$${file} != x.. ]; then \ + name=`echo $${file} | sed -e 's/[.][cS]$$//' -e 's/[.]asm$$//'`; \ + echo $${name}; \ + if [ $${name}.asm = $${file} ]; then \ + cp $${file} $${name}.s || exit 1; file=$${name}.s; \ + else true; fi; \ + $(OLDCC) $(CCLIBFLAGS) $(INCLUDES) -c $${file}; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + $(OLDAR) $(OLDAR_FLAGS) tmplibgcc1.a $${name}$(objext); \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + rm -f $${name}.s $${name}$(objext); \ + else true; \ + fi; \ + done + -if $(RANLIB_TEST) ; then $(RANLIB) tmplibgcc1.a; else true; fi + mv tmplibgcc1.a libgcc1.a + +# Build libgcc1.a from assembler source. LIB1ASMFUNCS is the list of +# functions. LIB1ASMSRC is the name of the source file in the config +# subdirectory. +libgcc1-asm.a: libgcc2.ready config.status $(srcdir)/config/$(LIB1ASMSRC) + -rm -f tmplibgcc1.a libgcc1.S + cp $(srcdir)/config/$(LIB1ASMSRC) libgcc1.S +# Actually build it in tmplibgcc1.a, then rename at end, +# so that libgcc1-asm.a itself remains nonexistent if compilation is aborted. +# -e causes any failing command to make this rule fail. +# -e doesn't work in certain shells, so we test $$? as well. +# lynx has a broken ar, it always complains when the initial library is +# empty, thus this command works only if we don't do -e +# There is a trailing backslash (\) deleted from the following line. +# set -e; + for name in $(LIB1ASMFUNCS); \ + do \ + echo $${name}; \ + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) -c -DL$${name} libgcc1.S; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + mv libgcc1$(objext) $${name}$(objext); \ + $(AR) $(AR_FLAGS) tmplibgcc1.a $${name}$(objext); \ + rm -f $${name}$(objext); \ + done + -rm -f libgcc1.S + mv tmplibgcc1.a libgcc1-asm.a + +# Generate assembly versions of the functions required for libgcc1. +# You'll still need to massage the code by hand (possibly hacking +# underscores and local labels) but this will get you started. +libgcc1.S: libgcc1.c $(CONFIG_H) config.status + -rm -f libgcc1.S + touch libgcc1.S + for name in $(LIB1FUNCS); \ + do \ + echo $${name}; \ + $(OLDCC) $(CCLIBFLAGS) $(INCLUDES) -S -DL$${name} $(srcdir)/libgcc1.c; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + echo '#ifdef ' L$${name} >> libgcc1.S; \ + cat libgcc1.s >> libgcc1.S; \ + echo '#endif /*' L$${name} '*/' >> libgcc1.S; \ + echo "" >> libgcc1.S; \ + done + +# Compiling libgcc2.a requires making sure that cc1, etc. have been compiled. +# But recompiling cc1 should not force recompilation of libgcc2.a. +# If you want to force recompilation, delete libgcc2.a. +libgcc2.ready: $(GCC_PASSES) $(LIBGCC2_DEPS) stmp-int-hdrs + -if [ -f libgcc2.ready ] ; then \ + true; \ + else \ + touch libgcc2.ready; \ + fi + +libgcc2.a: libgcc2.c libgcc2.ready $(CONFIG_H) $(LIB2FUNCS_EXTRA) \ + machmode.h longlong.h gbl-ctors.h config.status +# Actually build it in tmplibgcc2.a, then rename at end, +# so that libgcc2.a itself remains nonexistent if compilation is aborted. + -rm -f tmplibgcc2.a +# -e causes any failing command to make this rule fail. +# -e doesn't work in certain shells, so we test $$? as well. +# lynx has a broken ar, it always complains when the initial library is +# empty, thus this command works only if we don't do -e +# There is a trailing backslash (\) deleted from the following line. +# set -e; + for name in $(LIB2FUNCS); \ + do \ + echo $${name}; \ + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) -c -DL$${name} \ + $(srcdir)/libgcc2.c -o $${name}$(objext); \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + $(AR) $(AR_FLAGS) tmplibgcc2.a $${name}$(objext); \ + rm -f $${name}$(objext); \ + done +# Some shells crash when a loop has no items. +# So make sure there is always at least one--`..'. +# Then ignore it. +# We don't use -e here because there are if statements +# that should not make the command give up when the if condition is false. +# Instead, we test for failure after each command where it matters. + for file in .. $(LIB2FUNCS_EXTRA); \ + do \ + if [ x$${file} != x.. ]; then \ + name=`echo $${file} | sed -e 's/[.][cS]$$//' -e 's/[.]asm$$//'`; \ + oname=` echo $${name} | sed -e 's,.*/,,'`; \ + echo $${name}; \ + if [ $${name}.asm = $${file} ]; then \ + cp $${file} $${name}.s || exit 1; file=$${name}.s; \ + else true; fi; \ + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(INCLUDES) -c $${file}; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + $(AR) $(AR_FLAGS) tmplibgcc2.a $${oname}$(objext); \ + rm -f $${name}.s $${oname}$(objext); \ + else true; \ + fi; \ + done + mv tmplibgcc2.a libgcc2.a +# These lines were deleted from above the mv command +# because ranlibing libgcc.a itself should suffice. +# -if [ x${HPUX_GAS} = x ] ; then \ +# if $(RANLIB_TEST) ; then $(RANLIB) tmplibgcc2.a; else true; fi; \ +# else true; fi + +# Combine the various libraries into a single library, libgcc.a. +libgcc.a: $(LIBGCC1) $(LIBGCC2) + -rm -rf tmplibgcc.a libgcc.a tmpcopy + mkdir tmpcopy + -if [ x$(LIBGCC1) != x ]; \ + then (cd tmpcopy; $(AR) x ../$(LIBGCC1)); \ + else true; \ + fi +# Some versions of ar (specifically the one in RISC/os 5.x), create an +# unwritable table of contents file, and then print an error message when +# the second ar command tries to overwrite this file. To avoid the error +# message from ar, we make sure all files are writable. + -(cd tmpcopy; chmod +w * > /dev/null 2>&1) + (cd tmpcopy; $(AR) x ../$(LIBGCC2)) + (cd tmpcopy; $(AR) $(AR_FLAGS) ../tmplibgcc.a *$(objext)) + rm -rf tmpcopy + -if $(RANLIB_TEST) ; then $(RANLIB) tmplibgcc.a; else true; fi +# Actually build it in tmplibgcc.a, then rename at end, +# so that libgcc.a itself remains nonexistent if compilation is aborted. + mv tmplibgcc.a libgcc.a + +# Use the genmultilib shell script to generate the information the gcc +# driver program needs to select the library directory based on the +# switches. +multilib.h: $(srcdir)/genmultilib Makefile + $(SHELL) $(srcdir)/genmultilib "$(MULTILIB_OPTIONS)" \ + "$(MULTILIB_DIRNAMES)" "$(MULTILIB_MATCHES)" > multilib.h + +# Build multiple copies of libgcc.a, one for each target switch. +stmp-multilib: $(LIBGCC1) libgcc2.c libgcc2.ready $(CONFIG_H) \ + $(LIB2FUNCS_EXTRA) machmode.h longlong.h gbl-ctors.h config.status + for i in `$(GCC_FOR_TARGET) --print-multi-lib`; do \ + dir=`echo $$i | sed -e 's/;.*$$//'`; \ + flags=`echo $$i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`; \ + $(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \ + AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + RANLIB="$(RANLIB)" RANLIB_TEST="$(RANLIB_TEST)" \ + HOST_PREFIX="$(HOST_PREFIX)" HOST_PREFIX_1="$(HOST_PREFIX_1)" \ + LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS) $${flags}" \ + LIBGCC1="$(LIBGCC1)" LIBGCC2="$(LIBGCC2)" \ + dir="$${dir}" stmp-multilib-sub; \ + if [ $$? -eq 0 ] ; then true; else exit 1; fi; \ + done + touch stmp-multilib + +# Subroutine of stmp-multilib so make -n works. +stmp-multilib-sub: + rm -f $(dir)/libgcc.a $(LIBGCC2) + $(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \ + AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + HOST_PREFIX="$(HOST_PREFIX)" HOST_PREFIX_1="$(HOST_PREFIX_1)" \ + LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)" $(LIBGCC2) + if [ x$(LIBGCC1) != xlibgcc1-asm.a ]; \ + then true; \ + else rm -f $(LIBGCC1); \ + fi + if [ x$(LIBGCC1) != xlibgcc1-asm.a ]; \ + then true; \ + else \ + $(MAKE) GCC_FOR_TARGET="$(GCC_FOR_TARGET)" \ + AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" CC="$(CC)" CFLAGS="$(CFLAGS)" \ + HOST_PREFIX="$(HOST_PREFIX)" HOST_PREFIX_1="$(HOST_PREFIX_1)" \ + LIBGCC2_CFLAGS="$(LIBGCC2_CFLAGS)" $(LIBGCC1); \ + fi + rm -rf tmplibgcc.a tmpcopy + mkdir tmpcopy + if [ x$(LIBGCC1) != x ]; \ + then (cd tmpcopy; $(AR) x ../$(LIBGCC1)); \ + else true; \ + fi + (cd tmpcopy; $(AR) x ../$(LIBGCC2)) + (cd tmpcopy; $(AR) $(AR_FLAGS) ../tmplibgcc.a *$(objext)) + rm -rf libgcc2.a tmpcopy + if $(RANLIB_TEST) ; then $(RANLIB) tmplibgcc.a; else true; fi + if [ -d $(dir) ]; then true; else mkdir $(dir); fi + mv tmplibgcc.a $(dir)/libgcc.a + +objc-runtime: libobjc.a + +# Build the Objective C runtime library. +libobjc.a: cc1obj stmp-int-hdrs libgcc2.ready $(USE_COLLECT2) $(EXTRA_PARTS) + if [ -d objc ]; then true; else mkdir objc; fi + thisdir1=`pwd`; \ + srcdir1=`cd $(srcdir); pwd`; \ + cd objc; \ + $(MAKE) -f $${srcdir1}/objc/Makefile libobjc.a \ + srcdir=$${srcdir1} tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \ + GCC_FOR_TARGET="$${thisdir1}/xgcc -B$${thisdir1}/" \ + GCC_CFLAGS="$(GCC_CFLAGS)" + -rm -f libobjc.a + ln objc/libobjc.a . >/dev/null 2>&1 || cp objc/libobjc.a . + -if $(RANLIB_TEST) ; then $(RANLIB) libobjc.a; else true; fi + +# This is used by objc/Makefile if the user runs that directly. +sublibobjc.a: cc1obj stmp-int-hdrs libgcc2.ready + thisdir1=`pwd`; \ + srcdir1=`cd $(srcdir); pwd`; \ + cd objc; \ + $(MAKE) -f $$srcdir1/objc/Makefile libobjc.a \ + srcdir=$$srcdir1 tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \ + GCC_FOR_TARGET="$$thisdir1/xgcc -B$$thisdir1/" \ + GCC_CFLAGS="$(GCC_CFLAGS)" + +# Compile two additional files that are linked with every program +# linked using GCC on systems using COFF or ELF, for the sake of C++ +# constructors. +crtbegin.o: stamp-crt ; @true +crtend.o: stamp-crt; @true + +stamp-crt: crtstuff.c $(GCC_PASSES) $(CONFIG_H) gbl-ctors.h + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(CRTSTUFF_T_CFLAGS) \ + -DCRT_BEGIN -finhibit-size-directive -fno-inline-functions \ + -g0 -c $(srcdir)/crtstuff.c + mv crtstuff$(objext) crtbegin$(objext) + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(CRTSTUFF_T_CFLAGS) \ + -DCRT_END -finhibit-size-directive -fno-inline-functions \ + -g0 -c $(srcdir)/crtstuff.c + mv crtstuff$(objext) crtend$(objext) + touch stamp-crt + +# On some systems we also want to install versions of these files +# compiled using PIC for use in shared libraries. +crtbeginS.o crtendS.o: stamp-crtS ; @true + +stamp-crtS: crtstuff.c $(GCC_PASSES) $(CONFIG_H) gbl-ctors.h + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(CRTSTUFF_T_CFLAGS) \ + -DCRT_BEGIN -finhibit-size-directive -fno-inline-functions \ + -g0 -c $(srcdir)/crtstuff.c -fPIC + mv crtstuff$(objext) crtbeginS$(objext) + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) $(CRTSTUFF_T_CFLAGS) \ + -DCRT_END -finhibit-size-directive -fno-inline-functions \ + -g0 -c $(srcdir)/crtstuff.c -fPIC + mv crtstuff$(objext) crtendS$(objext) + touch stamp-crtS + +# Compiling object files from source files. + +# Note that dependencies on obstack.h are not written +# because that file is not part of GCC. + +# C language specific files. + +c-parse.o : $(srcdir)/c-parse.c $(CONFIG_H) $(TREE_H) c-lex.h \ + $(srcdir)/c-parse.h c-tree.h input.h flags.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $(srcdir)/c-parse.c +$(srcdir)/c-parse.h: $(srcdir)/c-parse.c +$(srcdir)/c-parse.c: $(srcdir)/c-parse.y + cd $(srcdir); $(BISON) $(BISONFLAGS) -d c-parse.y -o c-parse.c +$(srcdir)/c-parse.y: c-parse.in + sed -e "/^ifobjc$$/,/^end ifobjc$$/d" \ + -e "/^ifc$$/d" -e "/^end ifc$$/d" \ + $(srcdir)/c-parse.in >tmp-c-parse.y + $(srcdir)/move-if-change tmp-c-parse.y $(srcdir)/c-parse.y + +$(srcdir)/c-gperf.h: c-parse.gperf + gperf -p -j1 -i 1 -g -o -t -G -N is_reserved_word -k1,3,$$ \ + $(srcdir)/c-parse.gperf >tmp-gperf.h + $(srcdir)/move-if-change tmp-gperf.h $(srcdir)/c-gperf.h + +c-decl.o : c-decl.c $(CONFIG_H) $(TREE_H) c-tree.h c-lex.h flags.h output.h +c-typeck.o : c-typeck.c $(CONFIG_H) $(TREE_H) c-tree.h flags.h output.h +c-lang.o : c-lang.c $(CONFIG_H) $(TREE_H) +c-lex.o : c-lex.c $(CONFIG_H) $(TREE_H) c-lex.h c-tree.h $(srcdir)/c-parse.h \ + input.h flags.h $(srcdir)/c-gperf.h c-pragma.h +c-aux-info.o : c-aux-info.c $(CONFIG_H) $(TREE_H) c-tree.h flags.h +c-convert.o : c-convert.c $(CONFIG_H) $(TREE_H) flags.h +c-pragma.o: c-pragma.c $(CONFIG_H) $(TREE_H) c-pragma.h +c-iterate.o: c-iterate.c $(CONFIG_H) $(TREE_H) $(RTL_H) c-tree.h flags.h + +# To make a configuration always use collect2, set USE_COLLECT2 to ld. +ld: collect2 + rm -f ld$(exeext) + ln collect2$(exeext) ld$(exeext) > /dev/null 2>&1 \ + || cp collect2$(exeext) ld$(exeext) + +collect2 : collect2.o cplus-dem.o underscore.o version.o $(LIBDEPS) +# Don't try modifying collect2 (aka ld) in place--it might be linking this. + -rm -f collect2$(exeext) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ collect2.o \ + cplus-dem.o underscore.o version.o $(LIBS) + +collect2.o : collect2.c $(CONFIG_H) gstab.h obstack.h demangle.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DTARGET_MACHINE=\"$(target)\" $(MAYBE_USE_COLLECT2) \ + -c `echo $(srcdir)/collect2.c | sed 's,^\./,,'` + +cplus-dem.o: cplus-dem.c demangle.h + +underscore.c: stamp-under ; @true + +stamp-under: $(GCC_PASSES) + echo "int xxy_us_dummy;" >tmp-dum.c + $(GCC_FOR_TARGET) -S tmp-dum.c + echo '/*WARNING: This file is automatically generated!*/' >tmp-under.c + if grep _xxy_us_dummy tmp-dum.s > /dev/null ; then \ + echo "int prepends_underscore = 1;" >>tmp-under.c; \ + else \ + echo "int prepends_underscore = 0;" >>tmp-under.c; \ + fi + $(srcdir)/move-if-change tmp-under.c underscore.c + -rm -f tmp-dum.c tmp-dum.s + touch stamp-under + +# Objective C language specific files. + +objc-parse.o : $(srcdir)/objc-parse.c $(CONFIG_H) $(TREE_H) c-lex.h \ + c-tree.h input.h flags.h objc-act.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $(srcdir)/objc-parse.c +$(srcdir)/objc-parse.c : $(srcdir)/objc-parse.y + cd $(srcdir); $(BISON) $(BISONFLAGS) objc-parse.y -o objc-parse.c +$(srcdir)/objc-parse.y: $(srcdir)/c-parse.in + sed -e "/^ifc$$/,/^end ifc$$/d" \ + -e "/^ifobjc$$/d" -e "/^end ifobjc$$/d" \ + $(srcdir)/c-parse.in >tmp-objc-prs.y + $(srcdir)/move-if-change tmp-objc-prs.y $(srcdir)/objc-parse.y + +objc-act.o : objc-act.c $(CONFIG_H) $(TREE_H) $(RTL_H) c-tree.h c-lex.h \ + flags.h objc-act.h input.h function.h $(srcdir)/c-parse.h + +# A file used by all variants of C. + +c-common.o : c-common.c $(CONFIG_H) $(TREE_H) c-tree.h c-lex.h flags.h + +# Language-independent files. + +gcc.o: gcc.c $(CONFIG_H) multilib.h config.status $(lang_specs_files) + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DSTANDARD_STARTFILE_PREFIX=\"$(libdir)/\" \ + -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc-lib/\" \ + -DDEFAULT_TARGET_VERSION=\"$(version)\" \ + -DDEFAULT_TARGET_MACHINE=\"$(target)\" \ + -DTOOLDIR_BASE_PREFIX=\"$(exec_prefix)/\" \ + $(MAYBE_TARGET_DEFAULT) \ + -c `echo $(srcdir)/gcc.c | sed 's,^\./,,'` + +dumpvers: dumpvers.c + +version.o: version.c +obstack.o: obstack.c + +convert.o: convert.c $(CONFIG_H) $(TREE_H) flags.h convert.h + +tree.o : tree.c $(CONFIG_H) $(TREE_H) flags.h function.h +print-tree.o : print-tree.c $(CONFIG_H) $(TREE_H) +stor-layout.o : stor-layout.c $(CONFIG_H) $(TREE_H) flags.h function.h +fold-const.o : fold-const.c $(CONFIG_H) $(TREE_H) flags.h +toplev.o : toplev.c $(CONFIG_H) $(TREE_H) $(RTL_H) bytecode.h bc-emit.h \ + flags.h input.h insn-attr.h xcoffout.h defaults.h output.h \ + $(lang_options_files) + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + $(MAYBE_TARGET_DEFAULT) $(MAYBE_USE_COLLECT2) \ + -c `echo $(srcdir)/toplev.c | sed 's,^\./,,'` + +rtl.o : rtl.c $(CONFIG_H) $(RTL_H) + +print-rtl.o : print-rtl.c $(CONFIG_H) $(RTL_H) +rtlanal.o : rtlanal.c $(CONFIG_H) $(RTL_H) + +varasm.o : varasm.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h function.h \ + defaults.h insn-codes.h expr.h hard-reg-set.h regs.h xcoffout.h \ + output.h bytecode.h c-pragma.h +function.o : function.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h function.h \ + insn-flags.h insn-codes.h expr.h regs.h hard-reg-set.h insn-config.h \ + recog.h output.h bytecode.h +stmt.o : stmt.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h function.h \ + insn-flags.h insn-config.h insn-codes.h hard-reg-set.h expr.h loop.h \ + recog.h bytecode.h bc-typecd.h bc-typecd.def bc-opcode.h bc-optab.h \ + bc-emit.h +expr.o : expr.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h function.h regs.h \ + insn-flags.h insn-codes.h expr.h insn-config.h recog.h output.h \ + typeclass.h bytecode.h bc-opcode.h bc-typecd.h bc-typecd.def bc-optab.h \ + bc-emit.h modemap.def +calls.o : calls.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h expr.h insn-codes.h \ + insn-flags.h +expmed.o : expmed.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h \ + insn-flags.h insn-config.h insn-codes.h expr.h recog.h real.h +explow.o : explow.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h hard-reg-set.h \ + insn-config.h expr.h recog.h insn-flags.h insn-codes.h +optabs.o : optabs.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h \ + insn-flags.h insn-config.h insn-codes.h expr.h recog.h reload.h +dbxout.o : dbxout.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h regs.h \ + insn-config.h reload.h gstab.h xcoffout.h defaults.h output.h +sdbout.o : sdbout.c $(CONFIG_H) $(TREE_H) $(RTL_H) gsyms.h flags.h \ + insn-config.h reload.h +dwarfout.o : dwarfout.c $(CONFIG_H) $(TREE_H) $(RTL_H) dwarf.h flags.h \ + insn-config.h reload.h output.h defaults.h +xcoffout.o : xcoffout.c $(CONFIG_H) $(TREE_H) $(RTL_H) xcoffout.h flags.h +emit-rtl.o : emit-rtl.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h \ + function.h regs.h insn-config.h insn-codes.h real.h expr.h bytecode.h \ + bc-opcode.h bc-typecd.h bc-typecd.def bc-optab.h bc-emit.h bc-opname.h +real.o : real.c $(CONFIG_H) $(TREE_H) +getpwd.o : getpwd.c $(CONFIG_H) + +integrate.o : integrate.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h integrate.h \ + insn-flags.h insn-config.h insn-codes.h expr.h real.h function.h \ + bytecode.h + +jump.o : jump.c $(CONFIG_H) $(RTL_H) flags.h hard-reg-set.h regs.h \ + insn-config.h insn-flags.h insn-codes.h expr.h real.h +stupid.o : stupid.c $(CONFIG_H) $(RTL_H) regs.h hard-reg-set.h flags.h + +cse.o : cse.c $(CONFIG_H) $(RTL_H) regs.h hard-reg-set.h flags.h real.h \ + insn-config.h recog.h +loop.o : loop.c $(CONFIG_H) $(RTL_H) flags.h loop.h insn-config.h \ + insn-flags.h insn-codes.h regs.h hard-reg-set.h recog.h expr.h real.h +unroll.o : unroll.c $(CONFIG_H) $(RTL_H) insn-config.h insn-codes.h \ + integrate.h regs.h flags.h expr.h loop.h +flow.o : flow.c $(CONFIG_H) $(RTL_H) flags.h insn-config.h \ + basic-block.h regs.h hard-reg-set.h output.h +combine.o : combine.c $(CONFIG_H) $(RTL_H) flags.h \ + insn-config.h insn-flags.h insn-codes.h insn-attr.h regs.h expr.h \ + basic-block.h recog.h real.h hard-reg-set.h +regclass.o : regclass.c $(CONFIG_H) $(RTL_H) hard-reg-set.h flags.h \ + basic-block.h regs.h insn-config.h recog.h reload.h real.h bytecode.h +local-alloc.o : local-alloc.c $(CONFIG_H) $(RTL_H) flags.h basic-block.h \ + regs.h hard-reg-set.h insn-config.h recog.h output.h +global.o : global.c $(CONFIG_H) $(RTL_H) flags.h \ + basic-block.h regs.h hard-reg-set.h insn-config.h output.h + +reload.o : reload.c $(CONFIG_H) $(RTL_H) flags.h output.h \ + reload.h recog.h hard-reg-set.h insn-config.h insn-codes.h regs.h real.h +reload1.o : reload1.c $(CONFIG_H) $(RTL_H) real.h flags.h expr.h \ + reload.h regs.h hard-reg-set.h insn-config.h insn-flags.h insn-codes.h \ + basic-block.h recog.h output.h +caller-save.o : caller-save.c $(CONFIG_H) $(RTL_H) flags.h \ + regs.h hard-reg-set.h insn-codes.h insn-config.h basic-block.h recog.h \ + reload.h expr.h +reorg.o : reorg.c $(CONFIG_H) $(RTL_H) conditions.h hard-reg-set.h \ + basic-block.h regs.h insn-config.h insn-attr.h insn-flags.h recog.h \ + flags.h output.h +sched.o : sched.c $(CONFIG_H) $(RTL_H) basic-block.h regs.h hard-reg-set.h \ + flags.h insn-config.h insn-attr.h +final.o : final.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h regs.h \ + recog.h conditions.h insn-config.h insn-attr.h real.h output.h \ + hard-reg-set.h insn-flags.h insn-codes.h gstab.h xcoffout.h defaults.h +recog.o : recog.c $(CONFIG_H) $(RTL_H) \ + regs.h recog.h hard-reg-set.h flags.h insn-config.h insn-attr.h \ + insn-flags.h insn-codes.h real.h +reg-stack.o : reg-stack.c $(CONFIG_H) $(RTL_H) $(TREE_H) \ + regs.h hard-reg-set.h flags.h insn-config.h + +$(out_object_file): $(out_file) $(CONFIG_H) $(TREE_H) \ + $(RTL_H) regs.h hard-reg-set.h real.h insn-config.h conditions.h \ + insn-flags.h output.h insn-attr.h insn-codes.h + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(out_file) + +# Build auxiliary files that support ecoff format. +mips-tfile: mips-tfile.o version.o $(LIBDEPS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tfile.o version.o $(LIBS) + +mips-tfile.o : mips-tfile.c $(CONFIG_H) $(RTL_H) + +mips-tdump: mips-tdump.o version.o $(LIBDEPS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ mips-tdump.o version.o $(LIBS) + +mips-tdump.o : mips-tdump.c $(CONFIG_H) $(RTL_H) + +# Build file to support OSF/rose half-pic format. +halfpic.o: halfpic.c $(CONFIG_H) $(RTL_H) $(TREE_H) + +# Normally this target is not used; but it is used if you +# define ALLOCA=alloca.o. In that case, you must get a suitable alloca.c +# from the GNU Emacs distribution. +alloca.o: alloca.c + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(ALLOCA_FLAGS) \ + -c `echo $(srcdir)/alloca.c | sed 's,^\./,,'` + $(ALLOCA_FINISH) + +# Generate header and source files from the machine description, +# and compile them. + +.PRECIOUS: insn-config.h insn-flags.h insn-codes.h \ + insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c \ + insn-attr.h insn-attrtab.c + +# The following pair of rules has this effect: +# genconfig is run only if the md has changed since genconfig was last run; +# but the file insn-config.h is touched only when its contents actually change. + +# Each of the other insn-* files is handled by a similar pair of rules. + +# This causes an anomaly in the results of make -n +# because insn-* is older than stamp-* +# and thus make -n thinks that insn-* will be updated +# and force recompilation of things that depend on it. +# We use move-if-change precisely to avoid such recompilation. +# But there is no way to teach make -n that it will be avoided. + +# Each of the insn-*.[ch] rules has a semicolon at the end, +# for otherwise the system Make on SunOS 4.1 never tries +# to recompile insn-*.o. To avoid problems and extra noise from +# versions of make which don't like empty commands (nothing after the +# trailing `;'), we call true for each. + +insn-config.h: stamp-config ; @true +stamp-config : $(md_file) genconfig $(srcdir)/move-if-change + ./genconfig $(md_file) > tmp-config.h + $(srcdir)/move-if-change tmp-config.h insn-config.h + touch stamp-config + +insn-flags.h: stamp-flags ; @true +stamp-flags : $(md_file) genflags $(srcdir)/move-if-change + ./genflags $(md_file) > tmp-flags.h + $(srcdir)/move-if-change tmp-flags.h insn-flags.h + touch stamp-flags + +insn-codes.h: stamp-codes ; @true +stamp-codes : $(md_file) gencodes $(srcdir)/move-if-change + ./gencodes $(md_file) > tmp-codes.h + $(srcdir)/move-if-change tmp-codes.h insn-codes.h + touch stamp-codes + +insn-emit.o : insn-emit.c $(CONFIG_H) $(RTL_H) expr.h real.h output.h \ + insn-config.h insn-flags.h insn-codes.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-emit.c + +insn-emit.c: stamp-emit ; @true +stamp-emit : $(md_file) genemit $(srcdir)/move-if-change + ./genemit $(md_file) > tmp-emit.c + $(srcdir)/move-if-change tmp-emit.c insn-emit.c + touch stamp-emit + +insn-recog.o : insn-recog.c $(CONFIG_H) $(RTL_H) insn-config.h recog.h \ + real.h output.h flags.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-recog.c + +insn-recog.c: stamp-recog ; @true +stamp-recog : $(md_file) genrecog $(srcdir)/move-if-change + ./genrecog $(md_file) > tmp-recog.c + $(srcdir)/move-if-change tmp-recog.c insn-recog.c + touch stamp-recog + +insn-opinit.o : insn-opinit.c $(CONFIG_H) $(RTL_H) insn-codes.h insn-flags.h \ + insn-config.h flags.h rtl.h recog.h expr.h reload.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-opinit.c + +insn-opinit.c: stamp-opinit ; @true +stamp-opinit : $(md_file) genopinit $(srcdir)/move-if-change + ./genopinit $(md_file) > tmp-opinit.c + $(srcdir)/move-if-change tmp-opinit.c insn-opinit.c + touch stamp-opinit + +insn-extract.o : insn-extract.c $(CONFIG_H) $(RTL_H) + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-extract.c + +insn-extract.c: stamp-extract ; @true +stamp-extract : $(md_file) genextract $(srcdir)/move-if-change + ./genextract $(md_file) > tmp-extract.c + $(srcdir)/move-if-change tmp-extract.c insn-extract.c + touch stamp-extract + +insn-peep.o : insn-peep.c $(CONFIG_H) $(RTL_H) regs.h output.h real.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-peep.c + +insn-peep.c: stamp-peep ; @true +stamp-peep : $(md_file) genpeep $(srcdir)/move-if-change + ./genpeep $(md_file) > tmp-peep.c + $(srcdir)/move-if-change tmp-peep.c insn-peep.c + touch stamp-peep + +insn-attrtab.o : insn-attrtab.c $(CONFIG_H) $(RTL_H) regs.h real.h output.h \ + insn-attr.h insn-config.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-attrtab.c + +insn-attr.h: stamp-attr ; @true +stamp-attr : $(md_file) genattr $(srcdir)/move-if-change + ./genattr $(md_file) > tmp-attr.h + $(srcdir)/move-if-change tmp-attr.h insn-attr.h + touch stamp-attr + +insn-attrtab.c: stamp-attrtab ; @true +stamp-attrtab : $(md_file) genattrtab $(srcdir)/move-if-change + if cmp -s $(PREMADE_ATTRTAB_MD) $(md_file); \ + then \ + echo Using $(PREMADE_ATTRTAB); \ + cp $(PREMADE_ATTRTAB) tmp-attrtab.c; \ + else \ + ./genattrtab $(md_file) > tmp-attrtab.c; \ + fi + $(srcdir)/move-if-change tmp-attrtab.c insn-attrtab.c + touch stamp-attrtab + +insn-output.o : insn-output.c $(CONFIG_H) $(RTL_H) regs.h real.h conditions.h \ + hard-reg-set.h insn-config.h insn-flags.h insn-attr.h output.h recog.h \ + insn-codes.h + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c insn-output.c + +insn-output.c: stamp-output ; @true +stamp-output : $(md_file) genoutput $(srcdir)/move-if-change + ./genoutput $(md_file) > tmp-output.c + $(srcdir)/move-if-change tmp-output.c insn-output.c + touch stamp-output + +# Compile the programs that generate insn-* from the machine description. +# They are compiled with $(HOST_CC), and associated libraries, +# since they need to run on this machine +# even if GCC is being compiled to run on some other machine. + +# $(CONFIG_H) is omitted from the deps of the gen*.o +# because these programs don't really depend on anything +# about the target machine. They do depend on config.h itself, +# since that describes the host machine. + +# Pass the md file through cpp if the target requests it. +$(MD_FILE): $(MD_DEPS) + rm -f $@ + $(MD_CPP) $(MD_CPPFLAGS) $(md_file) | sed 's/^# /; /g' > tmp-$@ + mv tmp-$@ $@ + +genconfig : genconfig.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genconfig.o $(HOST_RTL) $(HOST_LIBS) + +genconfig.o : genconfig.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genconfig.c + +genflags : genflags.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genflags.o $(HOST_RTL) $(HOST_LIBS) + +genflags.o : genflags.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genflags.c + +gencodes : gencodes.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + gencodes.o $(HOST_RTL) $(HOST_LIBS) + +gencodes.o : gencodes.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gencodes.c + +genemit : genemit.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genemit.o $(HOST_RTL) $(HOST_LIBS) + +genemit.o : genemit.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genemit.c + +genopinit : genopinit.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genopinit.o $(HOST_RTL) $(HOST_LIBS) + +genopinit.o : genopinit.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genopinit.c + +genrecog : genrecog.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genrecog.o $(HOST_RTL) $(HOST_LIBS) + +genrecog.o : genrecog.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genrecog.c + +genextract : genextract.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genextract.o $(HOST_RTL) $(HOST_LIBS) + +genextract.o : genextract.c $(RTL_H) $(build_xm_file) insn-config.h + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genextract.c + +genpeep : genpeep.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genpeep.o $(HOST_RTL) $(HOST_LIBS) + +genpeep.o : genpeep.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genpeep.c + +genattr : genattr.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genattr.o $(HOST_RTL) $(HOST_LIBS) + +genattr.o : genattr.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genattr.c + +genattrtab : genattrtab.o $(HOST_RTL) $(HOST_PRINT) $(HOST_RTLANAL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genattrtab.o $(HOST_RTL) $(HOST_PRINT) $(HOST_RTLANAL) $(HOST_LIBS) + +genattrtab.o : genattrtab.c $(RTL_H) $(build_xm_file) insn-config.h + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genattrtab.c + +genoutput : genoutput.o $(HOST_RTL) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + genoutput.o $(HOST_RTL) $(HOST_LIBS) + +genoutput.o : genoutput.c $(RTL_H) $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genoutput.c + +# Compile the libraries to be used by gen*. +# If we are not cross-building, gen* use the same .o's that cc1 will use, +# and HOST_PREFIX_1 is `foobar', just to ensure these rules don't conflict +# with the rules for rtl.o, alloca.o, etc. +$(HOST_PREFIX_1)rtl.o: $(srcdir)/rtl.c $(CONFIG_H) $(RTL_H) + rm -f $(HOST_PREFIX)rtl.c + sed -e 's/config[.]h/hconfig.h/' $(srcdir)/rtl.c > $(HOST_PREFIX)rtl.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)rtl.c + +$(HOST_PREFIX_1)print-rtl.o: $(srcdir)/print-rtl.c $(CONFIG_H) $(RTL_H) + rm -f $(HOST_PREFIX)print-rtl.c + sed -e 's/config[.]h/hconfig.h/' $(srcdir)/print-rtl.c > $(HOST_PREFIX)print-rtl.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)print-rtl.c + +$(HOST_PREFIX_1)rtlanal.o: $(srcdir)/rtlanal.c $(CONFIG_H) $(RTL_H) + rm -f $(HOST_PREFIX)rtlanal.c + sed -e 's/config[.]h/hconfig.h/' $(srcdir)/rtlanal.c > $(HOST_PREFIX)rtlanal.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)rtlanal.c + +$(HOST_PREFIX_1)alloca.o: alloca.c + rm -f $(HOST_PREFIX)alloca.c + cp $(srcdir)/alloca.c $(HOST_PREFIX)alloca.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)alloca.c + +$(HOST_PREFIX_1)obstack.o: obstack.c + rm -f $(HOST_PREFIX)obstack.c + sed -e 's/config[.]h/hconfig.h/' $(srcdir)/obstack.c > $(HOST_PREFIX)obstack.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)obstack.c + +$(HOST_PREFIX_1)malloc.o: malloc.c + rm -f $(HOST_PREFIX)malloc.c + sed -e 's/config[.]h/hconfig.h/' $(srcdir)/malloc.c > $(HOST_PREFIX)malloc.c + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(HOST_PREFIX)malloc.c + +# This satisfies the dependency that we get if you cross-compile a compiler +# that does not need to compile alloca, malloc or whatever. +$(HOST_PREFIX_1): + touch $(HOST_PREFIX_1) + +# Remake bytecode files. +BI_OBJ=bi-parser.o bi-lexer.o bi-reverse.o + +bc-emit.o : bc-emit.c $(CONFIG_H) $(RTL_H) real.h $(BYTECODE_H) \ + bc-arity.h bc-opcode.h bc-typecd.h bc-typecd.def bi-run.h bytetypes.h +bc-optab.o : bc-optab.c $(CONFIG_H) $(REAL_H) $(BYTECODE_H) \ + bc-opcode.h bc-typecd.h bc-typecd.def + +bi-arity: bi-arity.o $(BI_OBJ) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + bi-arity.o $(BI_OBJ) $(HOST_LIBS) +bi-opcode: bi-opcode.o $(BI_OBJ) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + bi-opcode.o $(BI_OBJ) $(HOST_LIBS) +bi-opname: bi-opname.o $(BI_OBJ) $(HOST_LIBDEPS) + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + bi-opname.o $(BI_OBJ) $(HOST_LIBS) + +$(srcdir)/bi-parser.h: $(srcdir)/bi-parser.c +$(srcdir)/bi-parser.c: $(srcdir)/bi-parser.y + cd $(srcdir); $(BISON) $(BISONFLAGS) -d bi-parser.y -o bi-parser.c + +bi-parser.o: $(srcdir)/bi-parser.c bi-defs.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-parser.c +bi-lexer.o: bi-lexer.c $(srcdir)/bi-parser.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-lexer.c +bi-arity.o: bi-arity.c bi-defs.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-arity.c +bi-opcode.o: bi-opcode.c bi-defs.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-opcode.c +bi-opname.o: bi-opname.c bi-defs.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-opname.c +bi-reverse.o: bi-reverse.c bi-defs.h + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) \ + $(srcdir)/bi-reverse.c + +bc-arity.h: stamp-bcarity ; @true +stamp-bcarity : $(srcdir)/bytecode.def bi-arity $(srcdir)/move-if-change + ./bi-arity < $(srcdir)/bytecode.def >tmp-bc-arity.h + $(srcdir)/move-if-change tmp-bc-arity.h bc-arity.h + touch stamp-bcarity + +bc-opcode.h: stamp-bcopcode ; @true +stamp-bcopcode : $(srcdir)/bytecode.def bi-opcode $(srcdir)/move-if-change + ./bi-opcode < $(srcdir)/bytecode.def >tmp-bcopcd.h + $(srcdir)/move-if-change tmp-bcopcd.h bc-opcode.h + touch stamp-bcopcode + +bc-opname.h: stamp-bcopname ; @true +stamp-bcopname : $(srcdir)/bytecode.def bi-opname $(srcdir)/move-if-change + ./bi-opname < $(srcdir)/bytecode.def >tmp-bcopnm.h + $(srcdir)/move-if-change tmp-bcopnm.h bc-opname.h + touch stamp-bcopname + +bytecode.mostlyclean: + -rm -f bc-arity.h bc-opcode.h bc-opname.h + +bytecode.distclean bytecode.clean: bytecode.mostlyclean + -rm -f bi-arity bi-opcode bi-opname bi-lexer + +bytecode.maintainer-clean: bytecode.clean + -rm -f bi-parser.c bi-parser.h + + +# Remake cpp and protoize. + +# Making the preprocessor +cpp: $(CCCP) + -rm -f cpp$(exeext) + ln $(CCCP)$(exeext) cpp$(exeext) > /dev/null 2>&1 \ + || cp $(CCCP)$(exeext) cpp$(exeext) +cccp: cccp.o cexp.o version.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ cccp.o cexp.o \ + version.o $(LIBS) +cexp.o: $(srcdir)/cexp.c $(CONFIG_H) + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) -c $(srcdir)/cexp.c +$(srcdir)/cexp.c: $(srcdir)/cexp.y + cd $(srcdir); $(BISON) -o cexp.c cexp.y + +cccp.o: cccp.c $(CONFIG_H) pcp.h version.c config.status +# The reason we use $(libdir)/g++-include rather than using libsubdir +# is for compatibility with the current version of libg++. + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \ + -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \ + -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \ + -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \ + -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \ + -c `echo $(srcdir)/cccp.c | sed 's,^\./,,'` + +cppmain: cppmain.o cpplib.o cpphash.o cppalloc.o cpperror.o cppexp.o \ + version.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ cppmain.o cpplib.o cpphash.o \ + cppalloc.o cpperror.o cppexp.o version.o $(LIBS) + +cpplib.o: cpplib.c $(CONFIG_H) cpplib.h cpphash.h config.status + $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \ + -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \ + -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \ + -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \ + -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \ + -c `echo $(srcdir)/cpplib.c | sed 's,^\./,,'` + +cpperror.o: cpperror.c $(CONFIG_H) cpplib.h + +cppexp.o: cppexp.c $(CONFIG_H) cpplib.h + +cpphash.o: cpphash.c cpplib.h cpphash.h + +cppalloc.o: cppalloc.c $(CONFIG_H) + +# Note for the stamp targets, we run the program `true' instead of +# having an empty command (nothing following the semicolon). + +proto: config.status protoize unprotoize SYSCALLS.c.X + +protoize: protoize.o getopt.o getopt1.o getpwd.o version.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \ + protoize.o getopt.o getopt1.o getpwd.o version.o $(LIBS) +protoize.o: stamp-proto ; @true + +unprotoize: unprotoize.o getopt.o getopt1.o getpwd.o version.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \ + unprotoize.o getopt.o getopt1.o getpwd.o version.o $(LIBS) +unprotoize.o: stamp-proto ; @true + +stamp-proto: protoize.c getopt.h $(CONFIG_H) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \ + -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \ + -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \ + -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \ + -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \ + -DSTD_PROTO_DIR=\"$(libsubdir)\" \ + -DUNPROTOIZE $(srcdir)/protoize.c + mv protoize$(objext) unprotoize$(objext) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=\"$(libsubdir)/include\" \ + -DGPLUSPLUS_INCLUDE_DIR=\"$(gxx_include_dir)\" \ + -DCROSS_INCLUDE_DIR=\"$(libsubdir)/sys-include\" \ + -DTOOL_INCLUDE_DIR=\"$(tooldir)/include\" \ + -DLOCAL_INCLUDE_DIR=\"$(includedir)\" \ + -DSTD_PROTO_DIR=\"$(libsubdir)\" \ + $(srcdir)/protoize.c + touch stamp-proto + +getopt.o: getopt.c getopt.h + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/getopt.c +getopt1.o: getopt1.c getopt.h + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/getopt1.c + +# This info describes the target machine, so compile with GCC just built. +SYSCALLS.c.X: $(srcdir)/sys-types.h $(srcdir)/sys-protos.h $(GCC_PASSES) \ + stmp-int-hdrs + -rm -f SYSCALLS.c tmp-SYSCALLS.s + cat $(srcdir)/sys-types.h $(srcdir)/sys-protos.h > SYSCALLS.c + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -aux-info $@ -S -o tmp-SYSCALLS.s SYSCALLS.c + -rm -f SYSCALLS.c tmp-SYSCALLS.s + + +test-protoize-simple: ./protoize ./unprotoize $(GCC_PASSES) + -rm -f tmp-proto.[cso] + cp $(srcdir)/protoize.c tmp-proto.c + chmod u+w tmp-proto.c + ./protoize -N -B ./ -x getopt.h -c "-B./ -Wall -Wwrite-strings \ + $(CFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=0 \ + -DGPLUSPLUS_INCLUDE_DIR=0 \ + -DCROSS_INCLUDE_DIR=0 \ + -DTOOL_INCLUDE_DIR=0 \ + -DSTD_PROTO_DIR=0" tmp-proto.c + @echo '**********' Expect 400 lines of differences. + -diff $(srcdir)/protoize.c tmp-proto.c > tmp-proto.diff + -wc -l tmp-proto.diff + ./unprotoize -N -x getopt.h -c "-B./ -Wall -Wwrite-strings \ + $(CFLAGS) $(INCLUDES) \ + -DGCC_INCLUDE_DIR=0 \ + -DGPLUSPLUS_INCLUDE_DIR=0 \ + -DCROSS_INCLUDE_DIR=0 \ + -DTOOL_INCLUDE_DIR=0 \ + -DSTD_PROTO_DIR=0" tmp-proto.c + @echo Expect zero differences. + diff $(srcdir)/protoize.c tmp-proto.c | cat + -rm -f tmp-proto.[cs] tmp-proto$(objext) + +# Build the include directory. The stamp files are stmp-* rather than +# stamp-* so that mostlyclean does not force the include directory to +# be rebuilt. + +# Build the include directory except for float.h (which depends upon +# enquire). +stmp-int-hdrs: stmp-fixinc $(USER_H) xlimits.h objc-headers +# Copy in the headers provided with gcc. +# The sed command gets just the last file name component; +# this is necessary because VPATH could add a dirname. +# Using basename would be simpler, but some systems don't have it. + objdir=`pwd`; \ + cd $(srcdir); \ + for file in .. $(USER_H); do \ + if [ X$$file != X.. ]; then \ + realfile=`echo $$file | sed -e 's|.*/\([^/]*\)$$|\1|'`; \ + rm -f $$objdir/include/$$realfile; \ + cp ginclude/$$realfile $$objdir/include; \ + chmod a+r $$objdir/include/$$realfile; \ + fi; \ + done + rm -f include/limits.h + cp xlimits.h include/limits.h + chmod a+r include/limits.h +# Install the README + rm -f include/README + cp $(srcdir)/README-fixinc include/README + chmod a+r include/README + touch stmp-int-hdrs + +# Build the complete include directory. +stmp-headers: stmp-int-hdrs gfloat.h + rm -f include/float.h + cp gfloat.h include/float.h + chmod a+r include/float.h + touch stmp-headers + +# Build fixed copies of system files. +stmp-fixinc: $(FIXINCLUDES) gsyslimits.h + rm -rf include + mkdir include + if [ x$(FIXINCLUDES) != xMakefile.in ]; \ + then \ + for dir in $(SYSTEM_HEADER_DIR) $(OTHER_FIXINCLUDES_DIRS); do \ + if [ -d $$dir ]; \ + then \ + $(SHELL) $(srcdir)/$(FIXINCLUDES) include $$dir; \ + else true; fi; \ + done; \ + else true; \ + fi + rm -f include/syslimits.h + if [ -f include/limits.h ]; then \ + mv include/limits.h include/syslimits.h; \ + else \ + cp $(srcdir)/gsyslimits.h include/syslimits.h; \ + fi + chmod a+r include/syslimits.h + touch stmp-fixinc + +# copy objc header files into build directory +objc-headers: stmp-fixinc + if [ -d include ]; then true; else mkdir include; fi + if [ -d objc ]; then true; else mkdir objc; fi + thisdir1=`pwd`; \ + srcdir1=`cd $(srcdir); pwd`; \ + cd objc; \ + $(MAKE) -f $${srcdir1}/objc/Makefile copy-headers \ + srcdir=$${srcdir1} tooldir=$(tooldir) AR="$(AR)" AR_FLAGS="$(AR_FLAGS)" \ + GCC_FOR_TARGET="$${thisdir1}/xgcc -B$${thisdir1}/" \ + GCC_CFLAGS="$(GCC_CFLAGS)" incinstalldir=$${thisdir1}/include + touch objc-headers + +# Files related to the fixproto script. + +deduced.h: $(GCC_PASSES) $(srcdir)/scan-types.sh stmp-int-hdrs + CC="$(GCC_FOR_TARGET) $(GCC_CFLAGS) $(ALL_CPPFLAGS) -I. -I$(srcdir) -Iinclude -I${SYSTEM_HEADER_DIR}"; \ + export CC; \ + $(SHELL) $(srcdir)/scan-types.sh "$(srcdir)" >tmp-deduced.h + mv tmp-deduced.h deduced.h + +gen-protos: gen-protos.o scan.o cppalloc.o $(HOST_LIBDEPS) + ${HOST_CC} $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \ + gen-protos.o scan.o cppalloc.o $(HOST_LIBS) + +gen-protos.o: gen-protos.c scan.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gen-protos.c + +scan.o: scan.c scan.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/scan.c + +xsys-protos.h: $(GCC_PASSES) $(srcdir)/sys-protos.h deduced.h gen-protos Makefile + cat deduced.h $(srcdir)/sys-protos.h > tmp-fixtmp.c + mv tmp-fixtmp.c fixtmp.c + $(GCC_FOR_TARGET) fixtmp.c -w -U__SIZE_TYPE__ -U__PTRDIFF_TYPE__ -U__WCHAR_TYPE__ -E \ + | sed -e 's/ / /g' -e 's/ *(/ (/g' -e 's/ [ ]*/ /g' -e 's/( )/()/' \ + | ./gen-protos >xsys-protos.hT + mv xsys-protos.hT xsys-protos.h + rm -rf fixtmp.c + +fix-header: fix-header.o scan-decls.o scan.o xsys-protos.h $(HOST_LIBDEPS) \ + cpplib.o cpphash.o cppalloc.o cppexp.o cpperror.o version.o + $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ fix-header.o \ + scan-decls.o scan.o cpplib.o cpphash.o cppalloc.o version.o \ + cppexp.o $(HOST_LIBS) + +fix-header.o: fix-header.c obstack.h scan.h xsys-protos.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/fix-header.c + +scan-decls.o: scan-decls.c scan.h cpplib.h $(build_xm_file) + $(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/scan-decls.c + +# stmp-fixproto depends on this, not on fix-header directly. +# The idea is to make sure fix-header gets built, +# but not rerun fixproto after each stage +# just because fix-header's mtime has changed. +fixhdr.ready: fix-header + -if [ -f fixhdr.ready ] ; then \ + true; \ + else \ + touch fixhdr.ready; \ + fi + +# stmp-headers is to make sure fixincludes has already finished. +# The if statement is so that we don't run fixproto a second time +# if it has already been run on the files in `include'. +stmp-fixproto: fixhdr.ready fixproto stmp-headers + @echo "Various warnings and error messages from fixproto are normal" + -if [ -d include ] ; then true; else mkdir include; fi + -if [ -f include/fixed ] ; then true; \ + else \ + : This line works around a 'make' bug in BSDI 1.1.; \ + FIXPROTO_DEFINES="$(FIXPROTO_DEFINES)"; export FIXPROTO_DEFINES; \ + $(SHELL) ${srcdir}/fixproto include include $(SYSTEM_HEADER_DIR); \ + touch include/fixed; \ + fi + touch stmp-fixproto + +# Remake the info files. + +doc: info +info: $(srcdir)/cpp.info $(srcdir)/gcc.info lang.info + +$(srcdir)/cpp.info: cpp.texi + cd $(srcdir); $(MAKEINFO) cpp.texi + +$(srcdir)/gcc.info: gcc.texi extend.texi install.texi invoke.texi \ + md.texi rtl.texi tm.texi + cd $(srcdir); $(MAKEINFO) gcc.texi + +dvi: $(srcdir)/gcc.dvi $(srcdir)/cpp.dvi lang.dvi + +# This works with GNU Make's default rule. +$(srcdir)/gcc.dvi: gcc.texi extend.texi install.texi invoke.texi \ + md.texi rtl.texi tm.texi + $(TEXI2DVI) $< + +# This works with GNU Make's default rule. +$(srcdir)/cpp.dvi: cpp.texi + $(TEXI2DVI) $< + +$(srcdir)/INSTALL: install1.texi install.texi + $(MAKEINFO) -D INSTALLONLY --no-header --no-split \ + `echo $(srcdir)/install1.texi | sed 's,^\./,,'` + +# Deletion of files made during compilation. +# There are four levels of this: +# `mostlyclean', `clean', `distclean' and `maintainer-clean'. +# `mostlyclean' is useful while working on a particular type of machine. +# It deletes most, but not all, of the files made by compilation. +# It does not delete libgcc.a or its parts, so it won't have to be recompiled. +# `clean' deletes everything made by running `make all'. +# `distclean' also deletes the files made by config. +# `maintainer-clean' also deletes everything that could be regenerated +# automatically. We remove as much from the language subdirectories as we can +# (less duplicated code). + + +mostlyclean: bytecode.mostlyclean lang.mostlyclean + -rm -f $(STAGESTUFF) +# Clean the objc subdir if we created one. + if [ -d objc ]; then \ + srcdir1=`cd $(srcdir); pwd`; \ + cd objc; $(MAKE) -f $$srcdir1/objc/Makefile mostlyclean; \ + else true; fi + -rm -f libobjc.a +# Delete the temporary source copies for cross compilation. + -rm -f $(HOST_PREFIX_1)rtl.c $(HOST_PREFIX_1)rtlanal.c + -rm -f $(HOST_PREFIX_1)alloca.c $(HOST_PREFIX_1)malloc.c + -rm -f $(HOST_PREFIX_1)obstack.c +# Delete the temp files made in the course of building libgcc.a. + -rm -f tmplibgcc* tmpcopy xlimits.h + for name in $(LIB1FUNCS); do rm -f $${name}.c; done +# Delete other temporary files. + -rm -f tmp-float.h tmp-gcc.xtar.gz + -rm -f tmp-foo1 tmp-foo2 tmp-proto.* tmp-unproto.1 tmp-SYSCALLS.s + -rm -f tmp-c-parse.y tmp-objc-prs.y tmp-gperf.h + -rm -f tmp-specs t-float.h-cross tmp-xlimits.h + -rm -f tmp-fixtmp.c xsys-protos.hT +# Delete the stamp files. + -rm -f stamp-* tmp-* + -rm -f */stamp-* */tmp-* +# Delete debugging dump files. + -rm -f *.greg *.lreg *.combine *.flow *.cse *.jump *.rtl *.tree *.loop + -rm -f *.dbr *.jump2 *.sched *.cse2 *.sched2 *.stack + -rm -f */*.greg */*.lreg */*.combine */*.flow */*.cse */*.jump */*.rtl + -rm -f */*.tree */*.loop */*.dbr */*.jump2 */*.sched */*.cse2 + -rm -f */*.sched2 */*.stack +# Delete some files made during installation. + -rm -f specs gfloat.h float.h-* enquire SYSCALLS.c.X SYSCALLS.c + -rm -f collect collect2 mips-tfile mips-tdump alloca.s +# Delete files generated for fixproto + -rm -rf fix-header xsys-protos.h deduced.h tmp-deduced.h \ + gen-protos fixproto.list fixtmp.* fixhdr.ready +# Delete unwanted output files from TeX. + -rm -f *.toc *.log *.vr *.fn *.cp *.tp *.ky *.pg + -rm -f */*.toc */*.log */*.vr */*.fn */*.cp */*.tp */*.ky */*.pg +# Delete sorted indices we don't actually use. + -rm -f gcc.vrs gcc.kys gcc.tps gcc.pgs gcc.fns +# Delete core dumps. + -rm -f core */core + +# Delete all files made by compilation +# that don't exist in the distribution. +clean: mostlyclean bytecode.clean lang.clean +# It may not be quite desirable to delete unprotoize.c here, +# but the spec for `make clean' requires it. +# Using unprotoize.c is not quite right in the first place, +# but what better way is there? + -rm -f libgcc.a libgcc1.a libgcc1-asm.a libgcc2.a libgcc2.ready + -rm -f libgcc1.null + -rm -f *.dvi + -rm -f */*.dvi + -if [ -f md.pre-cpp ]; then \ + rm -f md ; \ + fi +# Delete the include directory. + -rm -rf stmp-* include objc-headers + -rm -f */stmp-* +# Delete files used by the "multilib" facility (including libgcc subdirs). + -rm -f multilib.h tmpmultilib* + -if [ "x$(MULTILIB_DIRNAMES)" != x ] ; then \ + rm -rf $(MULTILIB_DIRNAMES); \ + else if [ "x$(MULTILIB_OPTIONS)" != x ] ; then \ + rm -rf `echo $(MULTILIB_OPTIONS) | sed -e 's/\// /g'`; \ + fi ; fi + +# Delete all files that users would normally create +# while building and installing GCC. +distclean: clean bytecode.distclean lang.distclean + -rm -f tm.h config.h tconfig.h hconfig.h md + -rm -f config.status config.run + -rm -f Makefile specs.h options.h *.oaux + -rm -fr stage1 stage2 stage3 stage4 + -rm -f */stage1 */stage2 */stage3 */stage4 */include + -rm -f objc-parse.output + -rm -f c-parse.output + -rm -f *.asm + +# Delete anything likely to be found in the source directory +# that shouldn't be in the distribution. +extraclean: distclean lang.extraclean + -rm -rf =* ./"#"* *~* config/=* config/"#"* config/*~* + -rm -f patch* *.orig *.rej config/patch* config/*.orig config/*.rej + -rm -f config/*/=* config/*/"#"* config/*/*~* + -rm -f config/*/*.orig config/*/*.rej + -rm -f *.dvi *.ps *.oaux *.d *.[zZ] *.gz + -rm -f *.tar *.xtar *diff *.diff.* *.tar.* *.xtar.* *diffs + -rm -f *lose config/*lose config/*/*lose + -rm -f *.s *.s[0-9] *.i install1.texi config/ChangeLog + -rm -f */=* */"#"* */*~* + -rm -f */patch* */*.orig */*.rej + -rm -f */*.dvi */*.oaux */*.d */*.[zZ] */*.gz + -rm -f */*.tar */*.xtar */*diff */*.diff.* */*.tar.* */*.xtar.* */*diffs + -rm -f */*lose */*.s */*.s[0-9] */*.i + +# Get rid of every file that's generated from some other file. +# Most of these files ARE PRESENT in the GCC distribution. +maintainer-clean: distclean bytecode.maintainer-clean lang.maintainer-clean + -rm -f c-parse.y c-gperf.h objc-parse.y + -rm -f objc-parse.c objc-parse.output + -rm -f c-parse.c c-parse.h c-parse.output + -rm -f cexp.c cexp.output TAGS + -rm -f cpp.info* cpp.??s cpp.*aux + -rm -f gcc.info* gcc.??s gcc.*aux + +# Entry points `install' and `uninstall'. +# Also use `install-collect2' to install collect2 when the config files don't. + +# The semicolon is to prevent the install.sh -> install default rule +# from doing anything. Having it run true helps avoid problems and +# noise from versions of make which don't like to have null commands. +install: $(INSTALL_TARGET) ; @true + +# Copy the compiler files into directories where they will be run. +# Install the driver last so that the window when things are +# broken is small. +install-normal: install-common $(INSTALL_HEADERS) $(INSTALL_LIBGCC) \ + install-libobjc install-man install-info lang.install-normal install-driver + +# Do nothing while making gcc with a cross-compiler. The person who +# makes gcc for the target machine has to know how to put a complete +# gcc together by hand. +install-build: force + @echo You have to install gcc on your target machine by hand. + +# Run this on the target machine +# to finish installation of cross compiler. +install-cross-rest: install-float-h-cross + +# Install float.h for cross compiler. +# Run this on the target machine! +install-float-h-cross: install-dir +# if [ -f enquire ] ; then true; else false; fi +# Note: don't use -. We should fail right away if enquire was not made. + ./enquire -f > $(tmpdir)/float.h + -rm -f $(libsubdir)/include/float.h + $(INSTALL_DATA) $(tmpdir)/float.h $(libsubdir)/include/float.h + -rm -f $(tmpdir)/float.h + chmod a-x $(libsubdir)/include/float.h + +# Create the installation directory. +install-dir: + -if [ -d $(libdir) ] ; then true ; else mkdir $(libdir) ; chmod a+rx $(libdir) ; fi + -if [ -d $(libdir)/gcc-lib ] ; then true ; else mkdir $(libdir)/gcc-lib ; chmod a+rx $(libdir)/gcc-lib ; fi +# This dir isn't currently searched by cpp. +# -if [ -d $(libdir)/gcc-lib/include ] ; then true ; else mkdir $(libdir)/gcc-lib/include ; chmod a+rx $(libdir)/gcc-lib/include ; fi + -if [ -d $(libdir)/gcc-lib/$(target) ] ; then true ; else mkdir $(libdir)/gcc-lib/$(target) ; chmod a+rx $(libdir)/gcc-lib/$(target) ; fi + -if [ -d $(libdir)/gcc-lib/$(target)/$(version) ] ; then true ; else mkdir $(libdir)/gcc-lib/$(target)/$(version) ; chmod a+rx $(libdir)/gcc-lib/$(target)/$(version) ; fi + -if [ -d $(libdir)/gcc-lib/$(target)/$(version)/include ] ; then true ; else mkdir $(libdir)/gcc-lib/$(target)/$(version)/include ; chmod a+rx $(libdir)/gcc-lib/$(target)/$(version)/include ; fi + -if [ -d $(bindir) ] ; then true ; else mkdir $(bindir) ; chmod a+rx $(bindir) ; fi + -if [ -d $(includedir) ] ; then true ; else mkdir $(includedir) ; chmod a+rx $(includedir) ; fi + -if [ -d $(tooldir) ] ; then true ; else mkdir $(tooldir) ; chmod a+rx $(tooldir) ; fi + -if [ -d $(assertdir) ] ; then true ; else mkdir $(assertdir) ; chmod a+rx $(assertdir) ; fi + -if [ -d $(infodir) ] ; then true ; else mkdir $(infodir) ; chmod a+rx $(infodir) ; fi +# We don't use mkdir -p to create the parents of mandir, +# because some systems don't support it. +# Instead, we use this technique to create the immediate parent of mandir. + -parent=`echo $(mandir)|sed -e 's@/[^/]*$$@@'`; \ + if [ -d $$parent ] ; then true ; else mkdir $$parent ; chmod a+rx $$parent ; fi + -if [ -d $(mandir) ] ; then true ; else mkdir $(mandir) ; chmod a+rx $(mandir) ; fi + +# Install the compiler executables built during cross compilation. +install-common: native install-dir $(EXTRA_PARTS) lang.install-common + for file in $(COMPILERS); do \ + if [ -f $$file ] ; then \ + rm -f $(libsubdir)/$$file; \ + $(INSTALL_PROGRAM) $$file $(libsubdir)/$$file; \ + else true; \ + fi; \ + done + for file in $(EXTRA_PASSES) $(EXTRA_PROGRAMS) $(USE_COLLECT2) ..; do \ + if [ x"$$file" != x.. ]; then \ + rm -f $(libsubdir)/$$file; \ + $(INSTALL_PROGRAM) $$file $(libsubdir)/$$file; \ + else true; fi; \ + done + for file in $(EXTRA_PARTS) ..; do \ + if [ x"$$file" != x.. ]; then \ + rm -f $(libsubdir)/$$file; \ + $(INSTALL_DATA) $$file $(libsubdir)/$$file; \ + else true; fi; \ + done +# Don't mess with specs if it doesn't exist yet. + -if [ -f specs ] ; then \ + rm -f $(libsubdir)/specs; \ + $(INSTALL_DATA) specs $(libsubdir)/specs; \ + fi +# Install protoize if it was compiled. + -if [ -f protoize$(exeext) ]; \ + then \ + rm -f $(bindir)/protoize$(exeext); \ + $(INSTALL_PROGRAM) protoize$(exeext) $(bindir)/protoize$(exeext); \ + rm -f $(bindir)/unprotoize$(exeext); \ + $(INSTALL_PROGRAM) unprotoize$(exeext) $(bindir)/unprotoize$(exeext); \ + rm -f $(libsubdir)/SYSCALLS.c.X; \ + $(INSTALL_DATA) SYSCALLS.c.X $(libsubdir)/SYSCALLS.c.X; \ + chmod a-x $(libsubdir)/SYSCALLS.c.X; \ + fi + -rm -f $(libsubdir)/cpp$(exeext) + $(INSTALL_PROGRAM) cpp$(exeext) $(libsubdir)/cpp$(exeext) + +# Install the driver program as $(target)-gcc +# and also as either gcc (if native) or $(tooldir)/bin/gcc. +install-driver: xgcc + -if [ -f gcc-cross$(exeext) ] ; then \ + rm -f $(bindir)/$(GCC_CROSS_NAME)$(exeext); \ + $(INSTALL_PROGRAM) gcc-cross$(exeext) $(bindir)/$(GCC_CROSS_NAME)$(exeext); \ + if [ -d $(tooldir)/bin/. ] ; then \ + rm -f $(tooldir)/bin/gcc$(exeext); \ + $(INSTALL_PROGRAM) gcc-cross$(exeext) $(tooldir)/bin/gcc$(exeext); \ + else true; fi; \ + else \ + rm -f $(bindir)/$(GCC_INSTALL_NAME)$(exeext); \ + $(INSTALL_PROGRAM) xgcc$(exeext) $(bindir)/$(GCC_INSTALL_NAME)$(exeext); \ + rm -f $(bindir)/$(target)-gcc-1$(exeext); \ + ln $(bindir)/$(GCC_INSTALL_NAME)$(exeext) $(bindir)/$(target)-gcc-1$(exeext) \ + > /dev/null 2>&1 \ + || cp $(bindir)/$(GCC_INSTALL_NAME)$(exeext) $(bindir)/$(target)-gcc-1$(exeext); \ + mv $(bindir)/$(target)-gcc-1$(exeext) $(bindir)/$(target)-gcc$(exeext); \ + fi + +# Install the info files. +install-info: doc install-dir lang.install-info + -rm -f $(infodir)/cpp.info* $(infodir)/gcc.info* + cd $(srcdir); for f in cpp.info* gcc.info*; \ + do $(INSTALL_DATA) $$f $(infodir)/$$f; done + -chmod a-x $(infodir)/cpp.info* $(infodir)/gcc.info* + +# Install the man pages. +install-man: install-dir $(srcdir)/gcc.1 $(srcdir)/cccp.1 lang.install-man + -if [ -f gcc-cross ] ; then \ + rm -f $(mandir)/$(GCC_CROSS_NAME)$(manext); \ + $(INSTALL_DATA) $(srcdir)/gcc.1 $(mandir)/$(GCC_CROSS_NAME)$(manext); \ + chmod a-x $(mandir)/$(GCC_CROSS_NAME)$(manext); \ + else \ + rm -f $(mandir)/$(GCC_INSTALL_NAME)$(manext); \ + $(INSTALL_DATA) $(srcdir)/gcc.1 $(mandir)/$(GCC_INSTALL_NAME)$(manext); \ + chmod a-x $(mandir)/$(GCC_INSTALL_NAME)$(manext); \ + fi + -rm -f $(mandir)/cccp$(manext) + -$(INSTALL_DATA) $(srcdir)/cccp.1 $(mandir)/cccp$(manext) + -chmod a-x $(mandir)/cccp$(manext) + +# Install the library. +install-libgcc: libgcc.a install-dir + -if [ -f libgcc.a ] ; then \ + rm -f $(libsubdir)/libgcc.a; \ + $(INSTALL_DATA) libgcc.a $(libsubdir)/libgcc.a; \ + if $(RANLIB_TEST) ; then \ + (cd $(libsubdir); $(RANLIB) libgcc.a); else true; fi; \ + chmod a-x $(libsubdir)/libgcc.a; \ + else true; fi + +# Install multiple versions of libgcc.a. +install-multilib: stmp-multilib install-dir + for i in `$(GCC_FOR_TARGET) --print-multi-lib`; do \ + dir=`echo $$i | sed -e 's/;.*$$//'`; \ + if [ -d $(libsubdir)/$${dir} ]; then true; else mkdir $(libsubdir)/$${dir}; fi; \ + rm -f $(libsubdir)/$${dir}/libgcc.a; \ + $(INSTALL_DATA) $${dir}/libgcc.a $(libsubdir)/$${dir}/libgcc.a; \ + if $(RANLIB_TEST); then \ + (cd $(libsubdir)/$${dir}; $(RANLIB) libgcc.a); else true; fi; \ + chmod a-x $(libsubdir)/$${dir}/libgcc.a; \ + done + +# Install the objc run time library. +install-libobjc: install-dir + -if [ -f libobjc.a ] ; then \ + rm -f $(libsubdir)/libobjc.a; \ + $(INSTALL_DATA) libobjc.a $(libsubdir)/libobjc.a; \ + if $(RANLIB_TEST) ; then \ + (cd $(libsubdir); $(RANLIB) libobjc.a); else true; fi; \ + chmod a-x $(libsubdir)/libobjc.a; \ + else true; fi + +# Install all the header files built in the include subdirectory. +install-headers: install-include-dir $(INSTALL_HEADERS_DIR) $(INSTALL_ASSERT_H) +# Fix symlinks to absolute paths in the installed include directory to +# point to the installed directory, not the build directory. + -files=`cd $(libsubdir)/include; find . -type l -print 2>/dev/null`; \ + if [ $$? -eq 0 ]; then \ + dir=`cd include; pwd`; \ + for i in $$files; do \ + dest=`ls -ld $(libsubdir)/include/$$i | sed -n 's/.*-> //p'`; \ + if expr "$$dest" : "$$dir.*" > /dev/null; then \ + rm -f $(libsubdir)/include/$$i; \ + ln -s `echo $$i | sed "s|/[^/]*|/..|g" | sed 's|/..$$||'``echo "$$dest" | sed "s|$$dir||"` $(libsubdir)/include/$$i; \ + fi; \ + done; \ + fi + +# Create or recreate the gcc private include file directory. +install-include-dir: install-dir + -rm -rf $(libsubdir)/include + mkdir $(libsubdir)/include + -chmod a+rx $(libsubdir)/include + +# Install the include directory using tar. +install-headers-tar: stmp-headers $(STMP_FIXPROTO) install-include-dir + (cd include; \ + tar -cf - .; exit 0) | (cd $(libsubdir)/include; tar $(TAROUTOPTS) - ) +# /bin/sh on some systems returns the status of the first tar, +# and that can lose with GNU tar which always writes a full block. +# So use `exit 0' to ignore its exit status. + +# Install the include directory using cpio. +install-headers-cpio: stmp-headers $(STMP_FIXPROTO) install-include-dir + (cd include; find . -print) | (cd include; cpio -pdum $(libsubdir)/include) + +# Put assert.h where it won't override GNU libc's assert.h. +# It goes in a dir that is searched after GNU libc's headers; +# thus, the following conditionals are no longer needed. +# But it's not worth deleting them now. +## Don't replace the assert.h already there if it is not from GCC. +## This code would be simpler if it tested for -f ... && ! grep ... +## but supposedly the ! operator is missing in sh on some systems. +install-assert-h: assert.h install-dir + if [ -f $(assertdir)/assert.h ]; \ + then \ + if grep "__eprintf" $(assertdir)/assert.h >/dev/null; \ + then \ + rm -f $(assertdir)/assert.h; \ + $(INSTALL_DATA) $(srcdir)/assert.h $(assertdir)/assert.h; \ + chmod a-x $(assertdir)/assert.h; \ + else true; \ + fi; \ + else \ + rm -f $(assertdir)/assert.h; \ + $(INSTALL_DATA) $(srcdir)/assert.h $(assertdir)/assert.h; \ + chmod a-x $(assertdir)/assert.h; \ + fi + +# Use this target to install the program `collect2' under the name `ld'. +install-collect2: collect2 install-dir + $(INSTALL_PROGRAM) collect2$(exeext) $(libsubdir)/ld$(exeext) +# Install the driver program as $(libsubdir)/gcc for collect2. + $(INSTALL_PROGRAM) xgcc$(exeext) $(libsubdir)/gcc$(exeext) + +# Cancel installation by deleting the installed files. +uninstall: lang.uninstall + -rm -rf $(libsubdir) + -rm -rf $(bindir)/$(GCC_INSTALL_NAME)$(exeext) + -rm -rf $(bindir)/$(GCC_CROSS_NAME)$(exeext) + -rm -rf $(bindir)/protoize$(exeext) + -rm -rf $(bindir)/unprotoize$(exeext) + -rm -rf $(mandir)/$(GCC_INSTALL_NAME)$(manext) + -rm -rf $(mandir)/$(GCC_CROSS_NAME)$(manext) + -rm -rf $(mandir)/cccp$(manext) + -rm -rf $(mandir)/protoize$(manext) + -rm -rf $(mandir)/unprotoize$(manext) + +# These exist for maintenance purposes. + +# Update the tags table. +TAGS: force + cd $(srcdir); \ + mkdir temp; \ + mv -f c-parse.[ch] objc-parse.c cexp.c =*.[chy] temp; \ + etags *.y *.h *.c; \ + mv temp/* .; \ + rmdir temp + +# Create the distribution tar file. +#dist: gcc-$(version).tar.gz +dist: gcc.xtar.gz + +gcc.xtar.gz: gcc.xtar + gzip --best < gcc.xtar > tmp-gcc.xtar.gz + mv tmp-gcc.xtar.gz gcc.xtar.gz + +#gcc-$(version).tar.gz: gcc-$(version).tar +# gzip < gcc-$(version).tar > gcc-$(version).tar.gz + +#gcc-$(version).tar: +gcc.xtar: distdir +# Make the distribution. + tar -chf gcc.xtar gcc-$(version) + +# This target exists to do the initial work before the language specific +# stuff gets done. +distdir-start: doc $(srcdir)/INSTALL $(srcdir)/c-parse.y $(srcdir)/c-gperf.h \ + $(srcdir)/objc-parse.y $(srcdir)/c-parse.c $(srcdir)/objc-parse.c \ + $(srcdir)/cexp.c + @if grep -s "for version ${mainversion}" gcc.texi > /dev/null; \ + then true; \ + else echo "You must update the version number in \`gcc.texi'"; sleep 10;\ + fi +# Update the version number in README + awk '$$1 " " $$2 " " $$3 == "This directory contains" \ + { $$6 = version; print $$0 } \ + $$1 " " $$2 " " $$3 != "This directory contains"' \ + version=$(version) README > tmp.README + mv tmp.README README + -rm -rf gcc-$(version) tmp +# Put all the files in a temporary subdirectory +# which has the name that we want to have in the tar file. + mkdir tmp + mkdir tmp/config + mkdir tmp/ginclude + mkdir tmp/objc + for file in *[0-9a-zA-Z+]; do \ + ln $$file tmp > /dev/null 2>&1 || cp $$file tmp; \ + done + cd config; \ + for file in *[0-9a-zA-Z+]; do \ + if test -d $$file && test "$$file" != RCS; then \ + mkdir ../tmp/config/$$file; \ + cd $$file; \ + for subfile in *[0-9a-zA-Z+]; do \ + ln $$subfile ../../tmp/config/$$file >/dev/null 2>&1 \ + || cp $$subfile ../../tmp/config/$$file; \ + done; \ + cd ..; \ + else \ + ln $$file ../tmp/config >/dev/null 2>&1 \ + || cp $$file ../tmp/config; \ + fi; \ + done + cd ginclude; \ + for file in *[0-9a-zA-Z+]; do \ + ln $$file ../tmp/ginclude >/dev/null 2>&1 \ + || cp $$file ../tmp/ginclude; \ + done + cd objc; \ + for file in *[0-9a-zA-Z+]; do \ + ln $$file ../tmp/objc >/dev/null 2>&1 || cp $$file ../tmp/objc; \ + done + ln .gdbinit tmp + +# Finish making `distdir', after the languages have done their thing. +distdir-finish: + mv tmp gcc-$(version) +# Get rid of everything we don't want in the distribution. We'd want +# this to use Makefile.in, but it doesn't have the `lang.foo' targets +# expanded. + cd gcc-$(version); make extraclean + +distdir: distdir-start lang.distdir distdir-finish + +# make diff oldversion=M.N +# creates a diff file between an older distribution and this one. +# The -P option assumes this is GNU diff. +diff: + diff -rc2P -x c-parse.y -x c-parse.c -x c-parse.h -x c-gperf.h \ + -x cexp.c -x bi-parser.c -x objc-parse.y -x objc-parse.c \ + -x TAGS \ + -x "gcc.??" -x "gcc.??s" -x gcc.aux -x "gcc.info*" \ + -x "cpp.??" -x "cpp.??s" -x cpp.aux -x "cpp.info*" \ + $(LANG_DIFF_EXCLUDES) \ + gcc-$(oldversion) gcc-$(version) > diffs + +bootstrap: force +# Only build the C compiler for stage1, because that is the only one that +# we can guarantee will build with the native compiler, and also it is the +# only thing useful for building stage2. + $(MAKE) CC="$(CC)" libdir=$(libdir) LANGUAGES=c + $(MAKE) stage1 +# This used to define ALLOCA as empty, but that would lead to bad results +# for a subsequent `make install' since that would not have ALLOCA empty. +# To prevent `make install' from compiling alloca.o and then relinking cc1 +# because alloca.o is newer, we permit these recursive makes to compile +# alloca.o. Then cc1 is newer, so it won't have to be relinked. + $(MAKE) CC="stage1/xgcc -Bstage1/" CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(BOOT_LDFLAGS)" libdir=$(libdir) STAGE_PREFIX=stage1/ LANGUAGES="$(LANGUAGES)" + $(MAKE) stage2 + $(MAKE) CC="stage2/xgcc -Bstage2/" CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(BOOT_LDFLAGS)" libdir=$(libdir) STAGE_PREFIX=stage2/ LANGUAGES="$(LANGUAGES)" + +bootstrap2: force + $(MAKE) CC="stage1/xgcc -Bstage1/" CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(BOOT_LDFLAGS)" libdir=$(libdir) STAGE_PREFIX=stage1/ LANGUAGES="$(LANGUAGES)" + $(MAKE) stage2 + $(MAKE) CC="stage2/xgcc -Bstage2/" CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(BOOT_LDFLAGS)" libdir=$(libdir) STAGE_PREFIX=stage2/ LANGUAGES="$(LANGUAGES)" + +bootstrap3: force + $(MAKE) CC="stage2/xgcc -Bstage2/" CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(BOOT_LDFLAGS)" libdir=$(libdir) STAGE_PREFIX=stage2/ LANGUAGES="$(LANGUAGES)" + +# Compare the object files in the current directory with those in the +# stage2 directory. + +# ./ avoids bug in some versions of tail. +compare: force + for file in *$(objext); do \ + tail +16c ./$$file > tmp-foo1; \ + tail +16c stage2/$$file > tmp-foo2 2>/dev/null \ + && (cmp tmp-foo1 tmp-foo2 || echo $$file differs) || true; \ + done + for dir in tmp-foo $(SUBDIRS); do \ + if [ "`echo $$dir/*$(objext)`" != "$$dir/*$(objext)" ] ; then \ + for file in $$dir/*$(objext); do \ + tail +16c ./$$file > tmp-foo1; \ + tail +16c stage2/$$file > tmp-foo2 2>/dev/null \ + && (cmp tmp-foo1 tmp-foo2 || echo $$file differs) || true; \ + done; \ + fi; \ + done + -rm -f tmp-foo* + +# Similar, but compare with stage3 directory +compare3: force + for file in *$(objext); do \ + tail +16c ./$$file > tmp-foo1; \ + tail +16c stage3/$$file > tmp-foo2 2>/dev/null \ + && (cmp tmp-foo1 tmp-foo2 || echo $$file differs) || true; \ + done + for dir in tmp-foo $(SUBDIRS); do \ + if [ "`echo $$dir/*$(objext)`" != "$$dir/*$(objext)" ] ; then \ + for file in $$dir/*$(objext); do \ + tail +16c ./$$file > tmp-foo1; \ + tail +16c stage3/$$file > tmp-foo2 2>/dev/null \ + && (cmp tmp-foo1 tmp-foo2 || echo $$file differs) || true; \ + done; \ + fi; \ + done + -rm -f tmp-foo* + +# Compare the object files in the current directory with those in the +# stage2 directory. Use gnu cmp (diffutils v2.4 or later) to avoid +# running tail and the overhead of twice copying each object file. + +gnucompare: force + for file in *$(objext); do \ + cmp --ignore-initial=16 $$file stage2/$$file || true ; \ + done + for dir in tmp-foo $(SUBDIRS); do \ + if [ "`echo $$dir/*$(objext)`" != "$$dir/*$(objext)" ] ; then \ + for file in $$dir/*$(objext); do \ + cmp --ignore-initial=16 $$file stage2/$$file || true ; \ + done; \ + fi; \ + done + +# Similar, but compare with stage3 directory +gnucompare3: force + for file in *$(objext); do \ + cmp --ignore-initial=16 $$file stage3/$$file || true ; \ + done + for dir in tmp-foo $(SUBDIRS); do \ + if [ "`echo $$dir/*$(objext)`" != "$$dir/*$(objext)" ] ; then \ + for file in $$dir/*$(objext); do \ + cmp --ignore-initial=16 $$file stage3/$$file || true ; \ + done; \ + fi; \ + done + +# Copy the object files from a particular stage into a subdirectory. +stage1-start: + -if [ -d stage1 ] ; then true ; else mkdir stage1 ; fi + -for dir in . $(SUBDIRS) ; \ + do \ + if [ -d stage1/$$dir ] ; then true ; else mkdir stage1/$$dir ; fi ; \ + done + -mv $(STAGESTUFF) stage1 +# Copy as/ld if they exist to stage dir, so that running xgcc from the stage +# dir will work properly. + -if [ -f as$(exeext) ] ; then ln -s ../as$(exeext) stage1 || cp as$(exeext) stage1 ; else true ; fi + -if [ -f ld$(exeext) ] ; then ln -s ../ld$(exeext) stage1 || cp ld$(exeext) stage1 ; else true ; fi + -if [ -f collect-ld$(exeext) ] ; then ln -s ../collect-ld$(exeext) stage1 || cp collect-ld$(exeext) stage1 ; else true ; fi + -rm -f stage1/libgcc.a + -cp libgcc.a stage1 + -if $(RANLIB_TEST) ; then $(RANLIB) stage1/libgcc.a; else true; fi +stage1: force stage1-start lang.stage1 + +stage2-start: + -if [ -d stage2 ] ; then true ; else mkdir stage2 ; fi + -for dir in . $(SUBDIRS) ; \ + do \ + if [ -d stage2/$$dir ] ; then true ; else mkdir stage2/$$dir ; fi ; \ + done + -mv $(STAGESTUFF) stage2 +# Copy as/ld if they exist to stage dir, so that running xgcc from the stage +# dir will work properly. + -if [ -f as$(exeext) ] ; then ln -s ../as$(exeext) stage2 || cp as$(exeext) stage2 ; else true ; fi + -if [ -f ld$(exeext) ] ; then ln -s ../ld$(exeext) stage2 || cp ld$(exeext) stage2 ; else true ; fi + -if [ -f collect-ld ] ; then ln -s ../collect-ld$(exeext) stage2 || cp collect-ld$(exeext) stage2 ; else true ; fi + -rm -f stage2/libgcc.a + -cp libgcc.a stage2 + -if $(RANLIB_TEST) ; then $(RANLIB) stage2/libgcc.a; else true; fi +stage2: force stage2-start lang.stage2 + +stage3-start: + -if [ -d stage3 ] ; then true ; else mkdir stage3 ; fi + -for dir in . $(SUBDIRS) ; \ + do \ + if [ -d stage3/$$dir ] ; then true ; else mkdir stage3/$$dir ; fi ; \ + done + -mv $(STAGESTUFF) stage3 +# Copy as/ld if they exist to stage dir, so that running xgcc from the stage +# dir will work properly. + -if [ -f as$(exeext) ] ; then ln -s ../as$(exeext) stage3 || cp as$(exeext) stage3 ; else true ; fi + -if [ -f ld$(exeext) ] ; then ln -s ../ld$(exeext) stage3 || cp ld$(exeext) stage3 ; else true ; fi + -if [ -f collect-ld$(exeext) ] ; then ln -s ../collect-ld$(exeext) stage3 || cp collect-ld$(exeext) stage3 ; else true ; fi + -rm -f stage3/libgcc.a + -cp libgcc.a stage3 + -if $(RANLIB_TEST) ; then $(RANLIB) stage3/libgcc.a; else true; fi +stage3: force stage3-start lang.stage3 + +stage4-start: + -if [ -d stage4 ] ; then true ; else mkdir stage4 ; fi + -for dir in . $(SUBDIRS) ; \ + do \ + if [ -d stage4/$$dir ] ; then true ; else mkdir stage4/$$dir ; fi ; \ + done + -mv $(STAGESTUFF) stage4 +# Copy as/ld if they exist to stage dir, so that running xgcc from the stage +# dir will work properly. + -if [ -f as$(exeext) ] ; then ln -s ../as$(exeext) stage4 || cp as$(exeext) stage4 ; else true ; fi + -if [ -f ld$(exeext) ] ; then ln -s ../ld$(exeext) stage4 || cp ld$(exeext) stage4 ; else true ; fi + -if [ -f collect-ld$(exeext) ] ; then ln -s ../collect-ld$(exeext) stage4 || cp collect-ld$(exeext) stage4 ; else true ; fi + -rm -f stage4/libgcc.a + -cp libgcc.a stage4 + -if $(RANLIB_TEST) ; then $(RANLIB) stage4/libgcc.a; else true; fi +stage4: force stage4-start lang.stage4 + +# Copy just the executable files from a particular stage into a subdirectory, +# and delete the object files. Use this if you're just verifying a version +# that is pretty sure to work, and you are short of disk space. +risky-stage1: stage1 + - make clean + +risky-stage2: stage2 + -make clean + +risky-stage3: stage3 + -make clean + +risky-stage4: stage4 + -make clean + +#In GNU Make, ignore whether `stage*' exists. +.PHONY: stage1 stage2 stage3 stage4 clean maintainer-clean TAGS bootstrap +.PHONY: risky-stage1 risky-stage2 risky-stage3 risky-stage4 + +force: diff --git a/contrib/gcc/NEWS b/contrib/gcc/NEWS new file mode 100644 index 00000000000..2a665a1a60c --- /dev/null +++ b/contrib/gcc/NEWS @@ -0,0 +1,735 @@ +Noteworthy changes in GCC version 2.7.2: + +A few bugs have been fixed (most notably the generation of an +invalid assembler opcode on some RS/6000 systems). + +Noteworthy changes in GCC version 2.7.1: + +This release fixes numerous bugs (mostly minor) in GCC 2.7.0, but +also contains a few new features, mostly related to specific targets. + +Major changes have been made in code to support Windows NT. + +The following new targets are supported: + + 2.9 BSD on PDP-11 + Linux on m68k + HP/UX version 10 on HP PA RISC (treated like version 9) + DEC Alpha running Windows NT + +When parsing C, GCC now recognizes C++ style `//' comments unless you +specify `-ansi' or `-traditional'. + +The PowerPC System V targets (powerpc-*-sysv, powerpc-*-eabi) now use the +calling sequence specified in the System V Application Binary Interface +Processor Supplement (PowerPC Processor ABI Supplement) rather than the calling +sequence used in GCC version 2.7.0. That calling sequence was based on the AIX +calling sequence without function descriptors. To compile code for that older +calling sequence, either configure the compiler for powerpc-*-eabiaix or use +the -mcall-aix switch when compiling and linking. + +Noteworthy changes in GCC version 2.7.0: + +GCC now works better on systems that use ".obj" and ".exe" instead of +".o" and no extension. This involved changes to the driver program, +gcc.c, to convert ".o" names to ".obj" and to GCC's Makefile to use +".obj" and ".exe" in filenames that are not targets. In order to +build GCC on such systems, you may need versions of GNU make and/or +compatible shells. At this point, this support is preliminary. + +Object file extensions of ".obj" and executable file extensions of +".exe" are allowed when using appropriate version of GNU Make. + +Numerous enhancements were made to the __attribute__ facility including +more attributes and more places that support it. We now support the +"packed", "nocommon", "noreturn", "volatile", "const", "unused", +"transparent_union", "constructor", "destructor", "mode", "section", +"align", "format", "weak", and "alias" attributes. Each of these +names may also be specified with added underscores, e.g., "__packed__". +__attribute__ may now be applied to parameter definitions, function +definitions, and structure, enum, and union definitions. + +GCC now supports returning more structures in registers, as specified by +many calling sequences (ABIs), such as on the HP PA RISC. + +A new option '-fpack-struct' was added to automatically pack all structure +members together without holes. + +There is a new library (cpplib) and program (cppmain) that at some +point will replace cpp (aka cccp). To use cppmain as cpp now, pass +the option CCCP=cppmain to make. The library is already used by the +fix-header program, which should speed up the fixproto script. + +New options for supported targets: + + GNU on many targets. + NetBSD on MIPS, m68k, VAX, and x86. + LynxOS on x86, m68k, Sparc, and RS/6000. + VxWorks on many targets. + + Windows/NT on x86 architecture. Initial support for Windows/NT on Alpha + (not fully working). + + Many embedded targets, specifically UDI on a29k, aout, coff, elf, + and vsta "operating systems" on m68k, m88k, mips, sparc, and x86. + +Additional support for x86 (i386, i486, and Pentium): + + Work with old and new linkers for Linux-based GNU systems, + supporting both a.out and ELF. + FreeBSD on x86. + Stdcall convention. + -malign-double, -mregparm=, -malign-loops= and -malign-jumps= switches. + On ISC systems, support -Xp like -posix. + +Additions for RS/6000: + + Instruction scheduling information for PowerPC 403. + AIX 4.1 on PowerPC. + -mstring and -mno-string. + -msoft-float and floating-point emulation included. + Preliminary support for PowerPC System V.4 with or without the GNU as. + Preliminary support for EABI. + Preliminary support for 64-bit systems. + Both big and little endian systems. + +New features for MIPS-based systems: + + r4650. + mips4 and R8000. + Irix 6.0. + 64-bit ABI. + Allow dollar signs in labels on SGI/Irix 5.x. + +New support for HP PA RISC: + + Generation of PIC (requires binutils-2.5.2.u6 or later). + HP-UX version 9 on HP PA RISC (dynamically links even with -g). + Processor variants for HP PA RISC: 700, 7100, and 7100LC. + Automatic generation of long calls when needed. + -mfast-indirect-calls for kernels and static binaries. + + The called routine now copies arguments passed by invisible reference, + as required by the calling standard. + +Other new miscellaneous target-specific support: + + -mno-multm on a29k. + -mold-align for i960. + Configuration for "semi-hosted" ARM. + -momit-leaf-frame-pointer for M88k. + SH3 variant of Hitachi Super-H and support both big and little endian. + +Changes to Objective-C: + + Bare-bones implementation of NXConstantString has been added, + which is invoked by the @"string" directive. + + Class * has been changed to Class to conform to the NextSTEP and + OpenStep runtime. + + Enhancements to make dynamic loading easier. + + The module version number has been updated to Version 7, thus existing + code will need to be recompiled to use the current run-time library. + +GCC now supports the ISO Normative Addendum 1 to the C Standard. +As a result: + + The header defines macros for C programs written + in national variants of ISO 646. + + The following digraph tokens are supported: + <: :> <% %> %: %:%: + These behave like the following, respectively: + [ ] { } # ## + + Digraph tokens are supported unless you specify the `-traditional' + option; you do not need to specify `-ansi' or `-trigraphs'. Except + for contrived and unlikely examples involving preprocessor + stringizing, digraph interpretation doesn't change the meaning of + programs; this is unlike trigraph interpretation, which changes the + meanings of relatively common strings. + + The macro __STDC_VERSION__ has the value 199409L. + + As usual, for full conformance to the standard, you also need a + C library that conforms. + +The following lists changes that have been made to g++. If some +features mentioned below sound unfamiliar, you will probably want to +look at the recently-released public review copy of the C++ Working +Paper. For PostScript and PDF (Adobe Acrobat) versions, see the +archive at ftp://research.att.com/dist/stdc++/WP. For HTML and ASCII +versions, see ftp://ftp.cygnus.com/pub/g++. On the web, see +http://www.cygnus.com/~mrs/wp-draft. + +The scope of variables declared in the for-init-statement has been changed +to conform to http://www.cygnus.com/~mrs/wp-draft/stmt.html#stmt.for; as a +result, packages such as groff 1.09 will not compile unless you specify the +-fno-for-scope flag. PLEASE DO NOT REPORT THIS AS A BUG; this is a change +mandated by the C++ standardization committee. + +Binary incompatibilities: + + The builtin 'bool' type is now the size of a machine word on RISC targets, + for code efficiency; it remains one byte long on CISC targets. + + Code that does not use #pragma interface/implementation will most + likely shrink dramatically, as g++ now only emits the vtable for a + class in the translation unit where its first non-inline, non-abstract + virtual function is defined. + + Classes that do not define the copy constructor will sometimes be + passed and returned in registers. This may illuminate latent bugs in + your code. + +Support for automatic template instantiation has *NOT* been added, due +to a disagreement over design philosophies. + +Support for exception handling has been improved; more targets are now +supported, and throws will use the RTTI mechanism to match against the +catch parameter type. Optimization is NOT SUPPORTED with +-fhandle-exceptions; no need to report this as a bug. + +Support for Run-Time Type Identification has been added with -frtti. +This support is still in alpha; one major restriction is that any file +compiled with -frtti must include . + +Preliminary support for namespaces has been added. This support is far +from complete, and probably not useful. + +Synthesis of compiler-generated constructors, destructors and +assignment operators is now deferred until the functions are used. + +The parsing of expressions such as `a ? b : c = 1' has changed from +`(a ? b : c) = 1' to `a : b ? (c = 1)'. + +The code generated for testing conditions, especially those using || +and &&, is now more efficient. + +The operator keywords and, and_eq, bitand, bitor, compl, not, not_eq, +or, or_eq, xor and xor_eq are now supported. Use -ansi or +-foperator-names to enable them. + +The 'explicit' keyword is now supported. 'explicit' is used to mark +constructors and type conversion operators that should not be used +implicitly. + +g++ now accepts the typename keyword, though it currently has no +semantics; it can be a no-op in the current template implementation. +You may want to start using it in your code, however, since the +pending rewrite of the template implementation to compile STL properly +(perhaps for 2.8.0, perhaps not) will require you to use it as +indicated by the current draft. + +Handling of user-defined type conversion has been overhauled so that +type conversion operators are now found and used properly in +expressions and function calls. + +-fno-strict-prototype now only applies to function declarations with +"C" linkage. + +g++ now warns about 'if (x=0)' with -Wparentheses or -Wall. + +#pragma weak and #pragma pack are supported on System V R4 targets, as +are various other target-specific #pragmas supported by gcc. + +new and delete of const types is now allowed (with no additional +semantics). + +Explicit instantiation of template methods is now supported. Also, +'inline template class foo;' can be used to emit only the vtable +for a template class. + +With -fcheck-new, g++ will check the return value of all calls to +operator new, and not attempt to modify a returned null pointer. + +The template instantiation code now handles more conversions when +passing to a parameter that does not depend on template arguments. +This means that code like 'string s; cout << s;' now works. + +Invalid jumps in a switch statement past declarations that require +initializations are now caught. + +Functions declared 'extern inline' now have the same linkage semantics +as inline member functions. On supported targets, where previously +these functions (and vtables, and template instantiations) would have +been defined statically, they will now be defined as weak symbols so +that only one out-of-line definition is used. + +collect2 now demangles linker output, and c++filt has become part of +the gcc distribution. + +Noteworthy changes in GCC version 2.6.3: + +A few more bugs have been fixed. + +Noteworthy changes in GCC version 2.6.2: + +A few bugs have been fixed. + +Names of attributes can now be preceded and followed by double underscores. + +Noteworthy changes in GCC version 2.6.1: + +Numerous (mostly minor) bugs have been fixed. + +The following new configurations are supported: + + GNU on x86 (instead of treating it like MACH) + NetBSD on Sparc and Motorola 68k + AIX 4.1 on RS/6000 and PowerPC systems + Sequent DYNUX/ptx 1.x and 2.x. + Both COFF and ELF configurations on AViiON without using /bin/gcc + Windows/NT on x86 architecture; preliminary + AT&T DSP1610 digital signal processor chips + i960 systems on bare boards using COFF + PDP11; target only and not extensively tested + +The -pg option is now supported for Alpha under OSF/1 V3.0 or later. + +Files with an extension of ".c++" are treated as C++ code. + +The -Xlinker and -Wl arguments are now passed to the linker in the +position they were specified on the command line. This makes it +possible, for example, to pass flags to the linker about specific +object files. + +The use of positional arguments to the configure script is no longer +recommended. Use --target= to specify the target; see the GCC manual. + +The 386 now supports two new switches: -mreg-alloc= changes +the default register allocation order used by the compiler, and +-mno-wide-multiply disables the use of the mul/imul instructions that +produce 64 bit results in EAX:EDX from 32 bit operands to do long long +multiplies and 32-bit division by constants. + +Noteworthy changes in GCC version 2.6.0: + +Numerous bugs have been fixed, in the C and C++ front-ends, as +well as in the common compiler code. + +This release includes the C, Objective-C, and C++ compilers. However, +we have moved the files for the C++ compiler (G++) files to a +subdirectory, cp. Subsequent releases of GCC will split these files +to a separate TAR file. + +The G++ team has been tracking the development of the ANSI standard for C++. +Here are some new features added from the latest working paper: + + * built-in boolean type 'bool', with constants 'true' and 'false'. + * array new and delete (operator new [] and delete []). + * WP-conforming lifetime of temporaries. + * explicit instantiation of templates (template class A;), + along with an option (-fno-implicit-templates) to disable emission + of implicitly instantiated templates, obsoletes -fexternal-templates. + * static member constants (static const int foo = 4; within the + class declaration). + +Many error messages have been improved to tell the user more about the +problem. Conformance checking with -pedantic-errors has been +improved. G++ now compiles Fresco. + +There is now an experimental implementation of virtual functions using +thunks instead of Cfront-style vtables, enabled with -fvtable-thunks. +This option also enables a heuristic which causes the compiler to only +emit the vtable in the translation unit where its first non-inline +virtual function is defined; using this option and +-fno-implicit-templates, users should be able to avoid #pragma +interface/implementation altogether. + +Signatures have been added as a GNU C++ extension. Using the option +-fhandle-signatures, users are able to turn on recognition of +signatures. A short introduction on signatures is in the section +`Extension to the C++ Language' in the manual. + +The `g++' program is now a C program, rather than a shell script. + +Lots and lots and lots of bugs fixes, in nested types, access control, +pointers to member functions, the parser, templates, overload +resolution, etc, etc. + +There have been two major enhancements to the Objective-C compiler: + +1) Added portability. It now runs on Alpha, and some problems with + message forwarding have been addressed on other platforms. + +2) Selectors have been redefined to be pointers to structs like: + { void *sel_id, char *sel_types }, where the sel_id is the unique + identifier, the selector itself is no longer unique. + + Programmers should use the new function sel_eq to test selector + equivalence. + +The following major changes have been made to the base compiler and +machine-specific files. + +- The MIL-STD-1750A is a new port, but still preliminary. + +- The h8/300h is now supported; both the h8/300 and h8/300h ports come + with 32 bit IEEE 754 software floating point support. + +- The 64-bit Sparc (v9) and 64-bit MIPS chips are supported. + +- NetBSD is supported on m68k, Intel x86, and pc523 systems and FreeBSD + on x86. + +- COFF is supported on x86, m68k, and Sparc systems running LynxOS. + +- 68K systems from Bull and Concurrent are supported and System V + Release 4 is supported on the Atari. + +- GCC supports GAS on the Motorola 3300 (sysV68) and debugging + (assuming GAS) on the Plexus 68K system. (However, GAS does not yet + work on those systems). + +- System V Release 4 is supported on MIPS (Tandem). + +- For DG/UX, an ELF configuration is now supported, and both the ELF + and BCS configurations support ELF and COFF object file formats. + +- OSF/1 V2.0 is supported on Alpha. + +- Function profiling is also supported on Alpha. + +- GAS and GDB is supported for Irix 5 (MIPS). + +- "common mode" (code that will run on both POWER and PowerPC + architectures) is now supported for the RS/6000 family; the + compiler knows about more PPC chips. + +- Both NeXTStep 2.1 and 3 are supported on 68k-based architectures. + +- On the AMD 29k, the -msoft-float is now supported, as well as + -mno-sum-in-toc for RS/6000, -mapp-regs and -mflat for Sparc, and + -membedded-pic for MIPS. + +- GCC can now convert division by integer constants into the equivalent + multiplication and shift operations when that is faster than the + division. + +- Two new warning options, -Wbad-function-cast and + -Wmissing-declarations have been added. + +- Configurations may now add machine-specific __attribute__ options on + type; many machines support the `section' attribute. + +- The -ffast-math flag permits some optimization that violate strict + IEEE rules, such as converting X * 0.0 to 0.0. + +Noteworthy changes in GCC version 2.5.8: + +This release only fixes a few serious bugs. These include fixes for a +bug that prevented most programs from working on the RS/6000, a bug +that caused invalid assembler code for programs with a `switch' +statement on the NS32K, a G++ problem that caused undefined names in +some configurations, and several less serious problems, some of which +can affect most configuration. + +Noteworthy change in GCC version 2.5.7: + +This release only fixes a few bugs, one of which was causing bootstrap +compare errors on some systems. + +Noteworthy change in GCC version 2.5.6: + +A few backend bugs have been fixed, some of which only occur on one +machine. + +The C++ compiler in 2.5.6 includes: + + * fixes for some common crashes + * correct handling of nested types that are referenced as `foo::bar' + * spurious warnings about friends being declared static and never + defined should no longer appear + * enums that are local to a method in a class, or a class that's + local to a function, are now handled correctly. For example: + class foo { void bar () { enum { x, y } E; x; } }; + void bar () { class foo { enum { x, y } E; E baz; }; } + +Noteworthy change in GCC version 2.5.5: + +A large number of C++ bugs have been fixed. + +The fixproto script adds prototypes conditionally on __cplusplus. + +Noteworthy change in GCC version 2.5.4: + +A bug fix in passing of structure arguments for the HP-PA architecture +makes code compiled with GCC 2.5.4 incompatible with code compiled +with earlier versions (if it passes struct arguments of 33 to 64 bits, +interspersed with other types of arguments). + +Noteworthy change in gcc version 2.5.3: + +The method of "mangling" C++ function names has been changed. So you +must recompile all C++ programs completely when you start using GCC +2.5. Also, GCC 2.5 requires libg++ version 2.5. Earlier libg++ +versions won't work with GCC 2.5. (This is generally true--GCC +version M.N requires libg++ version M.N.) + +Noteworthy GCC changes in version 2.5: + +* There is now support for the IBM 370 architecture as a target. +Currently the only operating system supported is MVS; GCC does not run +on MVS, so you must produce .s files using GCC as a cross compiler, +then transfer them to MVS to assemble them. This port is not reliable +yet. + +* The Power PC is now supported. + +* The i860-based Paragon machine is now supported. + +* The Hitachi 3050 (an HP-PA machine) is now supported. + +* The variable __GNUC_MINOR__ holds the minor version number of GCC, as +an integer. For version 2.5.X, the value is 5. + +* In C, initializers for static and global variables are now processed +an element at a time, so that they don't need a lot of storage. + +* The C syntax for specifying which structure field comes next in an +initializer is now `.FIELDNAME='. The corresponding syntax for +array initializers is now `[INDEX]='. For example, + + char whitespace[256] + = { [' '] = 1, ['\t'] = 1, ['\n'] = 1 }; + +This was changed to accord with the syntax proposed by the Numerical +C Extensions Group (NCEG). + +* Complex numbers are now supported in C. Use the keyword __complex__ +to declare complex data types. See the manual for details. + +* GCC now supports `long double' meaningfully on the Sparc (128-bit +floating point) and on the 386 (96-bit floating point). The Sparc +support is enabled on on Solaris 2.x because earlier system versions +(SunOS 4) have bugs in the emulation. + +* All targets now have assertions for cpu, machine and system. So you +can now use assertions to distinguish among all supported targets. + +* Nested functions in C may now be inline. Just declare them inline +in the usual way. + +* Packed structure members are now supported fully; it should be possible +to access them on any supported target, no matter how little alignment +they have. + +* To declare that a function does not return, you must now write +something like this (works only in 2.5): + + void fatal () __attribute__ ((noreturn)); + +or like this (works in older versions too): + + typedef void voidfn (); + + volatile voidfn fatal; + +It used to be possible to do so by writing this: + + volatile void fatal (); + +but it turns out that ANSI C requires that to mean something +else (which is useless). + +Likewise, to declare that a function is side-effect-free +so that calls may be deleted or combined, write +something like this (works only in 2.5): + + int computation () __attribute__ ((const)); + +or like this (works in older versions too): + + typedef int intfn (); + + const intfn computation; + +* The new option -iwithprefixbefore specifies a directory to add to +the search path for include files in the same position where -I would +put it, but uses the specified prefix just like -iwithprefix. + +* Basic block profiling has been enhanced to record the function the +basic block comes from, and if the module was compiled for debugging, +the line number and filename. A default version of the basic block +support module has been added to libgcc2 that appends the basic block +information to a text file 'bb.out'. Machine descriptions can now +override the basic block support module in the target macro file. + +New features in g++: + +* The new flag `-fansi-overloading' for C++. Use a newly implemented +scheme of argument matching for C++. It makes g++ more accurately +obey the rules set down in Chapter 13 of the Annotated C++ Reference +Manual (the ARM). This option will be turned on by default in a +future release. + +* The -finline-debug flag is now gone (it was never really used by the + compiler). + +* Recognizing the syntax for pointers to members, e.g., "foo::*bar", has been + dramatically improved. You should not get any syntax errors or incorrect + runtime results while using pointers to members correctly; if you do, it's + a definite bug. + +* Forward declaration of an enum is now flagged as an error. + +* Class-local typedefs are now working properly. + +* Nested class support has been significantly improved. The compiler + will now (in theory) support up to 240 nested classes before hitting + other system limits (like memory size). + +* There is a new C version of the `g++' driver, to replace the old + shell script. This should significantly improve the performance of + executing g++ on a system where a user's PATH environment variable + references many NFS-mounted filesystems. This driver also works + under MS-DOS and OS/2. + +* The ANSI committee working on the C++ standard has adopted a new + keyword `mutable'. This will allow you to make a specific member be + modifiable in an otherwise const class. + +Noteworthy GCC changes in version 2.4.4: + + A crash building g++ on various hosts (including m68k) has been + fixed. Also the g++ compiler no longer reports incorrect + ambiguities in some situations where they do not exist, and + const template member functions are now being found properly. + +Noteworthy GCC changes in version 2.4: + +* On each target, the default is now to return short structures +compatibly with the "usual" compiler on that target. + +For most targets, this means the default is to return all structures +in memory, like long structures, in whatever way is used on that +target. Use -freg-struct-return to enable returning short structures +(and unions) in registers. + +This change means that newly compiled binaries are incompatible with +binaries compiled with previous versions of GCC. + +On some targets, GCC is itself the usual compiler. On these targets, +the default way to return short structures is still in registers. +Use -fpcc-struct-return to tell GCC to return them in memory. + +* There is now a floating point emulator which can imitate the way all +supported target machines do floating point arithmetic. + +This makes it possible to have cross compilation to and from the VAX, +and between machines of different endianness. However, this works +only when the target machine description is updated to use the new +facilities, and not all have been updated. + +This also makes possible support for longer floating point types. +GCC 2.4 supports extended format on the 68K if you use `long double', +for targets that have a 68881. (When we have run time library +routines for extended floating point, then `long double' will use +extended format on all 68K targets.) + +We expect to support extended floating point on the i386 and Sparc in +future versions. + +* Building GCC now automatically fixes the system's header files. +This should require no attention. + +* GCC now installs an unsigned data type as size_t when it fixes the +header files (on all but a handful of old target machines). +Therefore, the bug that size_t failed to be unsigned is fixed. + +* Building and installation are now completely separate. +All new files are constructed during the build process; +installation just copies them. + +* New targets supported: Clipper, Hitachi SH, Hitachi 8300, and Sparc +Lite. + +* A totally new and much better Objective C run time system is included. + +* Objective C supports many new features. Alas, I can't describe them +since I don't use that language; however, they are the same ones +supported in recent versions of the NeXT operating system. + +* The builtin functions __builtin_apply_args, __builtin_apply and +__builtin_return let you record the arguments and returned +value of a function without knowing their number or type. + +* The builtin string variables __FUNCTION__ and __PRETTY_FUNCTION__ +give the name of the function in the source, and a pretty-printed +version of the name. The two are the same in C, but differ in C++. + +* Casts to union types do not yield lvalues. + +* ## before an empty rest argument discards the preceding sequence +of non-whitespace characters from the macro definition. +(This feature is subject to change.) + + +New features specific to C++: + +* The manual contains a new section ``Common Misunderstandings with +GNU C++'' that C++ users should read. + +* #pragma interface and #pragma implementation let you use the same +C++ source file for both interface and implementation. +However, this mechanism is still in transition. + +* Named returned values let you avoid an extra constructor call +when a function result has a class type. + +* The C++ operators ? yield min and max, respectively. + +* C++ gotos can exit a block safely even if the block has +aggregates that require destructors. + +* gcc defines the macro __GNUG__ when compiling C++ programs. + +* GNU C++ now correctly distinguishes between the prefix and postfix +forms of overloaded operator ++ and --. To avoid breaking old +code, if a class defines only the prefix form, the compiler +accepts either ++obj or obj++, unless -pedantic is used. + +* If you are using version 2.3 of libg++, you need to rebuild it with +`make CC=gcc' to avoid mismatches in the definition of `size_t'. + +Newly documented compiler options: + +-fnostartfiles + Omit the standard system startup files when linking. + +-fvolatile-global + Consider memory references to extern and global data items to + be volatile. + +-idirafter DIR + Add DIR to the second include path. + +-iprefix PREFIX + Specify PREFIX for later -iwithprefix options. + +-iwithprefix DIR + Add PREFIX/DIR to the second include path. + +-mv8 + Emit Sparc v8 code (with integer multiply and divide). +-msparclite + Emit Sparclite code (roughly v7.5). + +-print-libgcc-file-name + Search for the libgcc.a file, print its absolute file name, and exit. + +-Woverloaded-virtual + Warn when a derived class function declaration may be an error + in defining a C++ virtual function. + +-Wtemplate-debugging + When using templates in a C++ program, warn if debugging is + not yet fully available. + ++eN + Control how C++ virtual function definitions are used + (like cfront 1.x). + diff --git a/contrib/gcc/ORDERS b/contrib/gcc/ORDERS new file mode 100644 index 00000000000..665c26df4ca --- /dev/null +++ b/contrib/gcc/ORDERS @@ -0,0 +1,3757 @@ +The actual order form follows the descriptions of media contents. + +Most of this file is excerpted from the draft of the June 1995 GNU's Bulletin. +The Order Form itself is accurate, but the information in the other articles +is not completely updated. You can ask gnu@prep.ai.mit.edu for the complete +June, 1995 Order From to get up-to-date information. + +Please send suggestions for improvements to gnu@prep.ai.mit.edu or the postal +address at the end of the order form. Thank You. + +--------------------------------------------------------------------- + + +FSF Order Form with Descriptions preliminary, June 1995 + + + +Free Software Foundation, Inc. Telephone: +1-617-542-5942 +59 Temple Place - Suite 330 Fax: (including Japan) +1-617-542-2652 +Boston, MA 02111-1307 Free Dial Fax (in Japan): +USA 0031-13-2473 (KDD) +Electronic mail: `gnu@prep.ai.mit.edu' 0066-3382-0158 (IDC) + + +There are some sections (e.g. ``Forthcoming GNUs'' and ``How to Get GNU +Software'') which are not in this Order Form file. If you wish to see them, +ask gnu@prep.ai.mit.edu for the complete June, 1995 GNU's Bulletin. + + +Table of Contents +----------------- + + Donations Translate Into Free Software + Cygnus Matches Donations! + Free Software Redistributors Donate + Help from Free Software Companies + (not included) Major Changes in GNU Software and Documentation (not + included as it was not done when this file was assembled). + GNU Documentation + GNU Software (not completely up to date) + Program/Package Cross Reference (not completely up to date) + Tapes + Languages Tape (version numbers not completely up to date) + Lisps and Emacs Tape (version numbers not completely up to date) + Utilities Tape (version numbers not completely up to date) + Scheme Tape + X11 Tapes + Berkeley 4.4BSD-Lite Tape + VMS Emacs and VMS Compiler Tapes + CD-ROMs + Pricing of the GNU CD-ROMs + MS-DOS CD-ROM + Debian GNU/Linux CD-ROM + Compiler Tools Binaries CD-ROM + Source Code CD-ROMs + June 1995 Source Code CD-ROM (version numbers not completely up + to date) + May 1994 Source Code CD-ROM + November 1993 Source Code CD-ROM + MS-DOS Diskettes + DJGPP Diskettes (version numbers not completely up to date) + Emacs Diskettes (version numbers not completely up to date) + Selected Utilities Diskettes (not completely up to date) + Windows Diskette + Tape & CD-ROM Subscription Service + The Deluxe Distribution + FSF T-shirt + Free Software Foundation Order Form + + + +Donations Translate Into Free Software +************************************** + +If you appreciate Emacs, GNU CC, Ghostscript, and other free software, you +may wish to help us make sure there is more in the future--remember, +*donations translate into more free software!* + +Your donation to us is tax-deductible in the United States. We gladly accept +*any* currency, although the U.S. dollar is the most convenient. +m{No Value For "ergegrafkludge"} If your employer has a matching gifts +program for charitable donations, please arrange to: add the FSF to the list +of organizations for your employer's matching gifts program; and have your +donation matched (note *Note Cygnus Matches Donations!::), if you do not +know, please ask your personnel department. Circle amount you are donating, +cut out this form, and send it with your donation to: + Free Software Foundation + 59 Temple Place -- Suite 330 + Boston, MA 02111-1307 + USA + + $500 $250 $100 $50 other $________ + + Other currency:________ + + +You can charge a donation to any of Carte Blanche, Diner's Club, JCB, +Mastercard, Visa, or American Express. Charges may also be faxed to ++1-617-492-9057. Individuals in Japan who are unable to place international +calls may use the "free dial" numbers: 0031-13-2473 (KDD) and +0066-3382-0158 (IDC). + + Card type: __________________ Expiration Date: _____________ + + Account Number: _____________________________________________ + + Cardholder's Signature: _____________________________________ + + Name: _______________________________________________________ + + Street Address: _____________________________________________ + + City/State/Province: ________________________________________ + + Zip Code/Postal Code/Country: _______________________________ + + + +Cygnus Matches Donations! +************************* + +To encourage cash donations to the Free Software Foundation, Cygnus Support +will continue to contribute corporate funds to FSF to accompany gifts by its +employees, and by its customers and their employees. + +Donations payable to the Free Software Foundation should be sent by eligible +persons to Cygnus Support, which will add its gifts and forward the total to +the FSF each quarter. The FSF will provide the contributor with a receipt to +recognize the contribution (which is tax-deductible on U.S. tax returns). +For more information, please contact Cygnus: + Cygnus Support + 1937 Landings Drive + Mountain View, CA 94043 + USA + + Telephone: 415-903-1400 + +1-800-Cygnus1 (-294-6871) + Fax: 415-903-0122 + Electronic-Mail: `info@cygnus.com' + FTP: `ftp.cygnus.com' + WWW: `http://www.cygnus.com/' + + + +Free Software Redistributors Donate +*********************************** + +by Richard Stallman + +The Sun Users Group Deutschland and ASCII Corporation (Japan) have added +donations to the FSF to the price of their next CD-ROM of GNU software. +Potential purchasers will know precisely how much of the price is for the FSF +and how much is for the redistributor. + +Austin Code Works, a redistributor of free software, is supporting free +software development by giving the FSF 20% of the selling price for the GNU +software packages they produce and sell. The producers of the SNOW 2.1 CD +added the words "Includes $5 donation to the FSF" to the front of their CD. +Walnut Creek CDROM and Info Magic, two more free software redistributors, are +also giving us a percentage of their selling price. CQ Publishing made a +large donation from the sales of their book about GAWK in Japanese. + +In the long run, the success of free software depends on how much new free +software people develop. Free software distribution offers an opportunity to +raise funds for such development in an ethical way. These redistributors +have made use of the opportunity. Many others let it go to waste. + +You can help promote free software development by convincing for-a-fee +redistributors to contribute--either by doing development themselves, or by +donating to development organizations (the FSF and others). + +The way to convince distributors to contribute is to demand and expect this +of them. This means choosing among distributors partly by how much they give +to free software development. Then you can show distributors they must +compete to be the one who gives the most. + +To make this work, you must insist on numbers that you can compare, such as, +"We will give ten dollars to the Foobar project for each disk sold." A vague +commitment, such as "A portion of the profits is donated," doesn't give you a +basis for comparison. Even a precise fraction "of the profits from this +disk" is not very meaningful, since creative accounting and unrelated +business decisions can greatly alter what fraction of the sales price counts +as profit. + +Also, press developers for firm information about what kind of development +they do or support. Some kinds make much more long-term difference than +others. For example, maintaining a separate version of a GNU program +contributes very little; maintaining a program on behalf of the GNU Project +contributes much. Easy new ports contribute little, since someone else would +surely do them; difficult ports such as adding a new CPU to the GNU compiler +contribute more; major new features and programs contribute the most. + +By establishing the idea that supporting further development is "the proper +thing to do" when distributing free software for a fee, we can assure a +steady flow of resources for making more free software. + + + +Help from Free Software Companies +********************************* + +When choosing a free software business, ask those you are considering how +much they do to assist free software development, e.g., by contributing money +to free software development or by writing free software improvements +themselves for general use. By basing your decision partially on this +factor, you can help encourage those who profit from free software to +contribute to its growth. + +These free software support companies regularly donate a part of their income +to the Free Software Foundation to support the development of new GNU +programs. Listing them here is our way of thanking them. Wingnut has made a +pledge to donate 10% of their income to the FSF, and has also purchased +several Deluxe Distribution packages in Japan. (Wingnut is SRA's special GNU +support group). Also see *Note Cygnus Matches Donations!::. + + Wingnut Project + Software Research Associates, Inc. + 1-1-1 Hirakawa-cho, Chiyoda-ku + Tokyo 102, Japan + + Phone: (+81-3)3234-2611 + Fax: (+81-3)3942-5174 + E-mail: `info-wingnut@sra.co.jp' + + + +GNU Documentation +***************** + +GNU is dedicated to having quality, easy-to-use online and printed +documentation. GNU manuals are intended to explain underlying concepts, +describe how to use all the features of each program, and give examples of +command use. GNU manuals are distributed as Texinfo source files, which +yield both typeset hardcopy via the TeX document formatting system, and online +hypertext display via the menu-driven Info system. Source for these manuals +comes with our software; here we list the manuals that we publish as printed +books as well; see the *note Free Software Foundation Order Form::.. + +Most GNU manuals are bound as soft cover books with "lay-flat" bindings. +This allows you to open them so they lie flat on a table without creasing the +binding. These books have an inner cloth spine and an outer cardboard cover +that will not break or crease as an ordinary paperback will. Currently, the +`GDB', `Emacs', `Emacs Lisp Reference', `GAWK', `Make', `Bison', and `Texinfo' +manuals have this binding. The other GNU manuals also lie flat when opened, +using a GBC or Wire-O binding. All of our manuals are 7in by 9.25in except +the 8.5in by 11in `Calc' manual. + +The edition number of the manual and version number of the program listed +after each manual's name were current at the time this Bulletin was published. + +`Debugging with GDB' (Edition 4.12 for Version 4.14) tells how to use the GNU +Debugger, run your program under debugger control, examine and alter data, +modify a program's flow of control, and use GDB through GNU Emacs. + +The `Emacs Manual' (11th Edition for Version 19.29) describes editing with +GNU Emacs. It explains advanced features, including outline mode and regular +expression search; how to use special modes for programming in languages like +C++ and TeX; how to use the `tags' utility; how to compile and correct code; +how to make your own keybindings; and other elementary customizations. + +`Programming in Emacs Lisp, An Introduction' (Edition 1.03 for Version 19.29) +is an elementary introduction to programming in Emacs Lisp. It is written +for people who are not necessarily interested in programming, but who do want +to customize or extend their computing environment. It tells how to write +programs that find files; switchbuffers; use searches, conditionals, loops, +and recursion; how to write Emacs initialization files; and how to run the +Emacs Lisp debuggers. If you read the text in GNU Emacs under Info mode, you +can run the sample programs directly. + +The `GNU Emacs Lisp Reference Manual' (Edition 2.4 for Version 19.29) covers +this programming language in depth, including data types, control structures, +functions, macros, syntax tables, searching/matching, modes, windows, +keymaps, byte compilation, and the operating system interface. + +The `GAWK Manual' (Edition 0.16 for Version 2.16) tells how to use the GNU +implementation of `awk'. It is written for those who have never used `awk' +and describes the features of this powerful string and record manipulation +language. + +The `Make Manual' (Edition 0.46 for Version 3.72) describes GNU `make', a +program used to rebuild parts of other programs. The manual tells how to +write "makefiles", which specify how a program is to be compiled and how its +files depend on each other. Included are an introductory chapter for novice +users and a section about automatically generated dependencies. + +The `Flex Manual' (Edition 1.03 for Version 2.3.7) teaches you to write a +lexical scanner definition for the `flex' program to create a C++ or C-coded +scanner that recognizes the patterns defined. You need no prior knowledge of +scanners. + +The `Bison Manual' (December 1993 Edition for Version 1.23) teaches you how +to write context-free grammars for the Bison program that convert into +C-coded parsers. You need no prior knowledge of parser generators. + +`Using and Porting GNU CC' (September 1994 Edition for Version 2.6) tells how +to run, install, and port the GNU C Compiler to new systems. It lists new +features and incompatibilities of GCC, but people not familiar with C will +still need a good reference on the C programming language. It also covers +G++. + +The `Texinfo Manual' (Edition 2.20 for Version 3) explains the markup +language used to generate both the online Info documentation and typeset +hardcopies. It tells you how to make tables, lists, chapters, nodes, +indexes, cross references, how to use Texinfo mode in GNU Emacs, and how to +catch mistakes. This second edition describes over 50 new commands. + +The `Termcap Manual' (2nd Edition for Version 1.2), often described as "twice +as much as you ever wanted to know about termcap," details the format of the +termcap database, the definitions of terminal capabilities, and the process +of interrogating a terminal description. This manual is primarily for +programmers. + +The `C Library Reference Manual' (Edition 0.06 for Version 1.09) describes +most of the facilities of the GNU C library, including both what Unix calls +"library functions" and "system calls." We are doing limited copier runs of +this manual until it becomes more stable. Please send corrections and +improvements to `bug-glibc-manual@prep.ai.mit.edu'. + +The `Emacs Calc Manual' (Edition 2.02 for Version 2.02) is both a tutorial +and a reference manual. It tells how to do ordinary arithmetic, how to use +Calc for algebra, calculus, and other forms of mathematics, and how to extend +Calc. + + + +GNU Software - (NOT COMPLETELY UP TO DATE) +************ + +All our software is available via FTP; see *Note How to Get GNU Software::. +In addition, we offer software on various media and printed documentation: + + * *Note CD-ROMs::. + + * *Note Tapes::. + + * *Note MS-DOS Diskettes::. + + * *Note Documentation::, which includes manuals and reference cards. + +We welcome all bug reports sent to the appropriate electronic mailing list +(*note Free Software Support::.). + +In the articles describing the contents of each medium, the version number +listed after each program name was current when we published this Bulletin. +When you order a distribution tape, diskette or newer CD-ROM, some of the +programs may be newer, and therefore the version number higher. + +Key to cross reference: + + + BinCD + Binaries CD-ROM + + DjgppD + Djgpp Diskettes + + DosCD + MS-DOS CD-ROM + + EmcsD + Emacs Diskettes + + LspEmcT + Lisps/Emacs Tape + + LangT + Languages Tape + + LiteT + 4.4BSD-Lite Tape + + SchmT + Scheme Tape + + SrcCD + Source CD-ROM + + UtilD + Selected Utilities Diskettes + + UtilT + Utilities Tape + + VMSCompT + VMS Compiler Tape + + VMSEmcsT + VMS Emacs Tape + + WdwsD + Windows Diskette + + X11OptT + X11 Optional Tape + + X11ReqT + X11 Required Tape + + + +Configuring GNU Software: + +We are using a uniform scheme for configuring GNU software packages in order +to compile them. It uses the `Autoconf' program (see item below). The goal +is to have all GNU software support the same alternatives for naming machine +and system types. When the GNU system is complete it will be possible to +configure and build the entire system at once, eliminating the need to +separately configure each individual package. The configuration scheme lets +you specify both the host and target system to build cross-compilation tools. + + + +GNU software currently available: + +(For new features and coming programs, see *Note Forthcoming GNUs::.) + + * `acm' (SrcCD, UtilT) + + `acm' is a LAN-oriented, multiplayer aerial combat simulation that runs + under the X Window System. Players engage in air to air combat against + one another using heat seeking missiles and cannons. We are working on + more accurate simulation of real airplane flight characteristics. + + * Autoconf (SrcCD, UtilT) + + Autoconf produces shell scripts which automatically configure source code + packages. These scripts adapt the packages to many kinds of Unix-like + systems without manual user intervention. Autoconf creates a script for + a package from a template file which lists the operating system features + which the package can use, in the form of `m4' macro calls. Autoconf + requires GNU `m4' to operate, but the resulting configure scripts it + generates do not. + + Most GNU programs now use Autoconf-generated configure scripts. + + * BASH (SrcCD, UtilT) + + The GNU shell, BASH (Bourne Again SHell), is compatible with the Unix + `sh' and offers many extensions found in `csh' and `ksh'. BASH has job + control, `csh'-style command history, and command-line editing (with + Emacs and `vi' modes built-in, and the ability to rebind keys) via the + readline library. BASH conforms to the POSIX 1003.2 shell specification. + + * `bc' (DjgppD, DosCD, SrcCD, UtilT) + + `bc' is an interactive algebraic language with arbitrary precision + numbers. GNU `bc' follows the POSIX.2-1992 standard, with several + extensions including multi-character variable names, an `else' + statement, and full Boolean expressions. The RPN calculator `dc' is now + distributed as part of the same package, but GNU `bc' is not implemented + as a `dc' preprocessor. + + * BFD (BinCD, DjggpD, DosCD, LangT, SrcCD) + + The Binary File Descriptor library allows a program which operates on + object files (e.g., `ld' or GDB) to support many different formats in a + clean way. BFD provides a portable interface, so that only BFD needs to + know the details of a particular format. One result is that all + programs using BFD will support formats such as a.out, COFF, and ELF. + BFD comes with source for Texinfo documentation (not yet published on + paper). Presently BFD is not distributed separately; it is included + with packages that use it. + + * Binutils (BinCD, DjgppD, DosCD, LangT, SrcCD) + + Binutils includes the programs: `ar', `c++filt', `demangle', `gas', + `gprof', `ld', `nlmconv', `nm', `objcopy', `objdump', `ranlib', `size', + `strings', and `strip'. + + Binutils Version 2 uses the BFD library. The GNU linker `ld' emits + source-line numbered error messages for multiply-defined symbols and + undefined references. It interprets a superset of the AT&T Linker + Command Language, which gives general control over where segments are + placed in memory. `nlmconv' converts object files into Novell NetWare + Loadable Modules. `objdump' can disassemble code for a29k, ALPHA, + H8/300, H8/500, HP-PA, i386, i960, m68k, m88k, MIPS, SH, SPARC, & Z8000 + processors, and can display other data (e.g., symbols & relocations) + from any file format understood by BFD. + + * Bison (BinCD, DjgppD, DosCD, LangT, SrcCD, VMSCompT) + + Bison is an upwardly compatible replacement for the parser generator + `yacc'. Texinfo source for the `Bison Manual' and reference card are + included. *Note Documentation::. + + We recently decided to change the policy for using the parsers that + Bison generates. It is now permitted to use Bison-generated parsers in + non-free programs. *Note GNUs Flashes::. + + * GNU C Library (BinCD, LangT, SrcCD) + + The GNU C library supports ANSI C-1989, POSIX 1003.1-1990 and most of the + functions in POSIX 1003.2-1992. It is upwardly compatible with 4.4BSD + and includes many System V functions, plus GNU extensions. + + The C Library will perform many functions of the Unix system calls in + the Hurd. Mike Haertel has written a fast `malloc' which wastes less + memory than the old GNU version. The GNU regular-expression functions + (`regex' and `rx') now nearly conform to the POSIX 1003.2 standard. + + GNU `stdio' lets you define new kinds of streams, just by writing a few + C functions. The `fmemopen' function uses this to open a stream on a + string, which can grow as necessary. You can define your own `printf' + formats to use a C function you have written. For example, you can + safely use format strings from user input to implement a `printf'-like + function for another programming language. Extended `getopt' functions + are already used to parse options, including long options, in many GNU + utilities. + + The C Library runs on Sun-3 (SunOS 4.1), Sun-4 (SunOS 4.1 or Solaris 2), + HP 9000/300 (4.3BSD), SONY News 800 (NewsOS 3 or 4), MIPS DECstation + (Ultrix 4), DEC Alpha (OSF/1), i386/i486 (System V, SVR4, BSD, SCO 3.2 & + SCO ODT 2.0), Sequent Symmetry i386 (Dynix 3) & SGI (Irix 4). Texinfo + source for the `GNU C Library Reference Manual' is included (*note + Documentation::.); the manual is now being updated. + + * GNU C++ Library (BinCD, DjgppD, DosCD, LangT, SrcCD) + + The GNU C++ library (libg++) contains an extensive collection of C++ + `forest' classes, an IOStream library for input/output routines, and + support tools for use with G++. Supported classes include: Obstacks, + multiple-precision Integers and Rationals, Complex numbers, arbitrary + length Strings, BitSets and BitStrings. Version 2.6.2 includes the + initial release of the libstdc++ library. This implements library + facilities defined by the forthcoming ANSI/ISO C++ standard, including + the Standard Template Library. + + * Calc (LspEmcT, SrcCD) + + Calc (written by Dave Gillespie in Emacs Lisp) is an extensible, advanced + desk calculator & mathematical tool that runs as part of GNU Emacs. You + can use Calc just as a simple four-function calculator, but it has many + more features including: choice of algebraic or RPN (stack-based) entry; + logarithmic, trigonometric & financial functions; arbitrary precision; + complex numbers; vectors; matrices; dates; times; infinities; sets; + algebraic simplification; differentiation & integration. It outputs to + `gnuplot' & comes with source for a reference card & a Manual. *Note + Documentation::. + + * GNU Chess (SrcCD, UtilT, WdwsD) + + GNU Chess lets the computer play a full game of chess with you. It runs + on most platforms & has dumb terminal, "curses" & X terminal interfaces. + The X terminal interface is based on the `xboard' program. + m{No Value For "ergegrafkludge"} GNU Chess implements many specialized + features including the null move heuristic, a hash table with aging, the + history heuristic (another form of the earlier killer heuristic), + caching of static evaluations, & a database which lets it play the first + several moves of the game quickly. Recent improvements include better + heuristics, faster evaluation, thinking on opponent's time, a perfect + King and Pawn vs King endgame routine, Swedish & German language + support, support for more book formats, a rudimentary Bobby Fischer + clock, & bug fixes. It is primarily supported by Stuart Cracraft, Chua + Kong Sian, & Tim Mann on behalf of the FSF. + + * CLISP (LspEmcT, SrcCD) + + CLISP is a Common Lisp implementation by Bruno Haible and Michael Stoll. + It mostly supports the Lisp described by `Common LISP: The Language (2nd + edition)' and the ANSI Common Lisp standard. CLISP includes an + interpreter, a byte-compiler, a large subset of CLOS, a foreign language + interface and, for some machines, a screen editor. The user interface + language (English, German, French) is chooseable at run time. Major + packages that run in CLISP include CLX & Garnet. CLISP needs only 2 MB + of memory & runs on many microcomputers (including MS-DOS systems, OS/2, + the Atari ST, Amiga 500-4000, Acorn RISC PC) & Unix-like systems + (GNU/Linux, Sun4, SVR4, SGI, HP-UX, DEC Alpha, NeXTstep & others). + + * GNU Common Lisp (LspEmcT, SrcCD) + + GNU Common Lisp (GCL) has a compiler and interpreter for Common Lisp. It + used to be known as Kyoto Common Lisp. It is very portable and extremely + efficient on a wide class of applications. It compares favorably in + performance with commercial Lisps on several large theorem-prover and + symbolic algebra systems. It supports the CLtL1 specification but is + moving towards the proposed ANSI definition. GCL compiles to C and + then uses the native optimizing C compilers (e.g., GCC). A function + with a fixed number of args and one value turns into a C function of the + same number of args, returning one value, so GCL is maximally efficient + on such calls. It has a conservative garbage collector which allows + great freedom for the C compiler to put Lisp values in arbitrary + registers. It has a source level Lisp debugger for interpreted code, + with display of source code in an Emacs window. Ita profiling tools + (based on the C profiling tools) count function calls and the time spent + in each function. CLX works with GCL. + + There is now a builtin interface with the TK widget system. It runs in + a separate process so that users may monitor progress on lisp + computations, or interact with running computations via a windowing + interface. + + There is also an Xlib interface via C (xgcl-2). PCL runs with GCL (see + PCL item later in this article). *Note Forthcoming GNUs::, for plans for + about GCL, or for recent developments. GCL version 2.0 is released + under the GNU Library General Public License. + + * `cpio' (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + `cpio' is an alternative archive program with all the features of SVR4 + `cpio', including support for the final POSIX 1003.1 `ustar' standard. + `mt', a program to position magnetic tapes, is included with `cpio'. + + * CVS (SrcCD, UtilT) + + CVS, the Concurrent Version System, manages software revision and release + control in a multi-developer, multi-directory, multi-group environment. + It works best in conjunction with RCS versions 4 and above, but will + parse older RCS formats with the loss of CVS's fancier features. See + Berliner, Brian, "CVS-II: Parallelizing Software Development," + `Proceedings of the Winter 1990 USENIX Association Conference'. To find + out how to get a copy of this report, contact `office@usenix.org'. + + * DejaGnu (LangT, SrcCD) + + DejaGnu is a framework for testing other programs that provides a single + front end for all tests. The framework's flexibility and consistency + makes it easy to write tests for any program. DejaGnu comes with + `expect', which runs scripts to conduct dialogs with programs. + + * Diffutils (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + GNU `diff' compares files showing line-by-line changes in several + flexible formats. It is much faster than traditional Unix versions. The + Diffutils package contains `diff', `diff3', `sdiff', and `cmp'. + + Recent Diffutils improvements include more consistent handling of + character sets, and a new `diff' option to do all input/output in + binary; this is useful on some non-Posix hosts. + + Plans for the Diffutils package include support for internationalization + (e.g., error messages in Chinese), and for some non-Unix PC environments. + + * DJGPP (BinCD, DjgppD, DosCD) + + DJ Delorie has ported GCC/G++ 2.6.0 (see the GCC item in this section) + to the i386 MS-DOS platform. The DJGPP package also contains a 32-bit + 80386 DOS extender with symbolic debugger; development libraries; and + ports of Bison, `flex', GAS, and the GNU Binutils. Full source code is + provided. It requires at least 5MB of hard disk space to install and + 512K of RAM to use. It supports SVGA (up to 1024x768), XMS & VDISK + memory allocation, `himem.sys', VCPI (e.g., QEMM, DESQview, & 386MAX), + and DPMI (e.g., Windows 3.x, OS/2, QEMM, & QDPMI). Ask + `djgpp-request@sun.soe.clarkson.edu' to join a DJGPP users mailing list. + + * `dld' (LangT, SrcCD) + + `dld' is a dynamic linker written by W. Wilson Ho. Linking your program + with the `dld' library allows you to dynamically load object files into + the running binary. Currently supported are VAX (Ultrix), Sun 3 (SunOS + 3.4 & 4.0), SPARC (SunOS 4.0), Sequent Symmetry (Dynix), & Atari ST. + + * `doschk' (DjgppD, DosCD, SrcCD, UtilT) + + This program is intended as a utility to help software developers ensure + that their source file names are distinguishable on System V platforms + with 14-character filenames and on MS-DOS with 8+3 character filenames. + + * `ecc' (SrcCD, UtilT) + + `ecc' is a Reed-Solomon error correction checking program, which can + correct three byte errors in a block of 255 bytes and detect more severe + errors. Contact `paulf@Stanford.EDU' for more information. + + * `ed' (SrcCD, UtilT) + + Ed is the standard text editor. + + * Elib (LspEmcT, SrcCD) + + Elib is a small library of Emacs Lisp functions, including routines for + using AVL trees and doubly-linked lists. + + * GNU Emacs + + In 1975, Richard Stallman developed the first Emacs, an extensible, + customizable real-time display editor and computing environment. GNU + Emacs is his second implementation. It offers true Lisp--smoothly + integrated into the editor--for writing extensions, and provides an + interface to the X Window System. It also runs on MS-DOS and Windows + NT. In addition to its powerful native command set, Emacs has + extensions which emulate the editors vi and EDT (DEC's VMS editor). + Emacs has many other features which make it a full computing support + environment. Our long term plan is now to move it in the direction of a + WYSIWYG word processor and make it easy for beginners to use. Source + for the `GNU Emacs Manual', `Programming in Emacs Lisp, An + Introduction', the `GNU Emacs Lisp Reference Manual', and a reference + card come with the software. *Note Documentation::. + + * GNU Emacs 18 (EmcsD, LspEmcT, SrcCD, VMSEmcsT) + + GNU Emacs 18.59 is the last release of version 18 from the FSF. We are + no longer maintaining it. It runs on many Unix systems. In hardware + order: Alliant FX/80 & FX/2800, Altos 3068, Amdahl (UTS), Apollo, AT&T + (3Bs & 7300 PC), DG Aviion, Bull DPX/2 (2nn & 3nn) CCI 5/32 & 6/32, + Celerity, Convex, Digital (DECstation 3100 & 5000 (PMAXes), Mips, VAX + (BSD, SysV & VMS)), Motorola Delta 147 & 187, Dual, Elxsi 6400, Encore + (DPC, APC & XPC), Gould, HP (9000 series 200, 300, 700 & 800, but not + 500), HLH Orion (original & 1/05), IBM (RS/6000 (AIX), RT/PC (4.2 & AIX) + & PS/2 (AIX (386 only))), ISI (Optimum V, 80386), Intel 860 & 80386 + (BSD, Esix, SVR3, SVR4, SCO, ISC, IX, AIX & others), Iris (2500, 2500 + Turbo & 4D), Masscomp, MIPS, National Semiconductor 32000, NeXT (Mach), + NCR Tower 32 (SVR2 & SVR3), Nixdorf Targon 31, Nu (TI & LMI), pfa50, + Plexus, Prime EXL, Pyramid (original & MIPS), Sequent (Balance & + Symmetry), SONY News (m68k & MIPS), Stride (system release 2), all Suns + including 386i (all SunOS & some Solaris vers.), Tadpole, Tahoe, Tandem + Integrity S2, Tektronix (16000 & 4300), Triton 88, Ustation E30 (SS5E), + Whitechapel (MG1) & Wicat. + + In operating system order: AIX (RS/6000, RT/PC, 386-PS/2), BSD (vers. + 4.1, 4.2, 4.3), DomainOS, Esix (386), HP-UX (HP 9000 series 200, 300, + 700, 800 but not 500), ISC (386), IX (386), Mach, Microport, NewsOS + (Sony m68k & MIPS) SCO (386), SVR0 (Vax, AT&T 3Bs), SVR2, SVR3, SVR4, + Solaris 2.0, SunOS, UTS (Amdahl), Ultrix (vers. 3.0, 4,1), Uniplus 5.2 + (Dual machines), VMS (vers. 4.0, 4.2, 4.4, 5.5) & Xenix (386). + + * GNU Emacs 19 (DosCD, EmacsD, LspEmcT, SrcCD) + + Emacs 19 works with character-only terminals as well as with the X + Window System (with or without the X toolkit); New features in Emacs 19 + include: multiple X windows ("frames" to Emacs), with either a separate + X window for the minibuffer or a minibuffer attached to each X window; + property lists associated with regions of text in a buffer; multiple + fonts and colors defined by those properties; simplified and improved + processing of function keys, mouse clicks and mouse movement; X + selection processing, including clipboard selections; hooks to be run if + point or mouse moves outside a certain range; menu bars and popup menus + defined by keymaps; scrollbars; before and after change hooks; + source-level debugging of Emacs Lisp programs; European character sets + support; floating point numbers; improved buffer allocation, including + returning storage to the system when a buffer is killed; interfacing + with the X resource manager; GNU configuration scheme support; good RCS + support; & many updated libraries. + + Recent features include support for Motif widgets as well as the Athena + widgets, displaying multiple views of an outline at the same time, + version control support for CVS and for multiple branches, ability to + open frames on more than one X display from a single Emacs job, + operation on MS-DOS and MS Windows, commands to edit text properties, + text properties for formatting text, the ability to save text properties + in files, & GNU-standard long named command line options. + + Emacs 19.29 is believed to work on, in hardware order: Acorn Risc + machine (RISCiX); Alliant FX/2800 (BSD); Alpha (OSF/1); Apollo + (DomainOS); Bull DPX/2 2nn & 3nn (SysV.3) & sps7 (SysV.2); Clipper; + Convex (BSD); Cubix QBx (SysV); Data General Aviion (DGUX); DEC MIPS + (Ultrix 4.2 & OSF/1, not VMS); Elxsi 6400 (SysV); Gould Power Node & NP1 + (4.2 & 4.3BSD); Harris Night Hawk 1200 and 3000, 4000 and 5000 (cxux); + Honeywell XPS100 (SysV); HP 9000 series 200, 300, 700, 800 (but not 500) + (4.3BSD or HP-UX 7, 8, 9); Intel i386, i486 and Pentium (386BSD, AIX, + BSDI/386, FreeBSD, Esix, GNU/Linux, ISC, MS-DOS (*note MS-DOS + Diskettes::. & *Note MS-DOS CD-ROM::), NetBSD, SCO3.2v4, SysV, Xenix, + WindowsNT); IBM RS6000 (AIX 3.2); IBM RT/PC (AIX or BSD); Motorola Delta + 147 & 187 (SysV.3, SysV.4, & m88kbcs); National Semiconductor 32K + (Genix); NeXT (BSD or Mach 2 w/ NeXTStep 3.0); Paragon (OSF/1); Prime + EXL (SysV); Pyramid (BSD); Sequent Symmetry (BSD, ptx); Siemens RM400 + and RM600 (SysV); SGI Iris 4D (Irix 4.x & 5.x); Sony News/RISC (NewsOS); + Stardent i860 (SysV); Sun 3 & 4, SPARC 1, 1+, 2, 10 & Classic (SunOS + 4.0, 4.1, Solaris 2.0-2.3); Tadpole 68k (SysV); Tektronix XD88 (SysV.3) + & 4300 (BSD); & Titan P2 & P3 (SysV). + + In operating system order: AIX (i386, RS6000, RT/PC); 4.1, 4.2, 4.3BSD + (i386, i860, Convex, Gould Power Node & NP1, HP9000 series 300, NeXT, + Pyramid, Symmetry, Tektronix 4300, RT/PC); DG/UX (Aviion); + DomainOS(Apollo); Esix (i386); FreeBSD (i386); Genix (ns32k); GNU/Linux + (i386); HP-UX 7, 8, 9 (HP 9000 series 200, 300, 700, 800, but not 500); + Irix 4 & 5 (Iris 4D); ISC (i386); Mach 2 & 3 (i386, NeXT); MS-DOS (*note + MS-DOS Diskettes::. & *Note MS-DOS CD-ROM::); NetBSD (i386, HP9000 + series 300); OSF/1 (Alpha, Paragon); RISCiX (Acorn); SCO 3.2v4 (i386); + SysV (Cubix QBx, Elxsi 6400, Honeywell XPS100, Intel i386, Prime EXL, + Siemens RM400 and RM600, Stardent, Tadpole 68k, Titan P2 & P3); SysV.2 + (Bull sps7); SysV.3 (Bull DPX/2 2nn & 3nn, Motorola Delta 147 & 187, + Tektronix XD88); SysV.4 (Motorola Delta 147 & 187, Stardent i860); + Solaris 2 (SPARC 1, 1+, 2, 10, Classic); SunOS 4.0, 4.1 (Sun 3 & 4, + SPARC 1, 1+, 2, 10 & Classic); Ultrix 4.2 (DEC MIPS); Windows NT; & + Xenix (i386). + + Other configurations supported by Emacs 18 should work with few changes + in Emacs 19; as users tell us more about their experiences with different + systems, we will augment the list. Also see *Note Forthcoming GNUs::. + + * `es' (SrcCD, UtilT) + + `es' is an extensible shell based on `rc' with first class functions, + lexical scope, exceptions, and rich return values (i.e., functions can + return values other than just numbers). `es''s extensibility comes from + the ability to modify and extend the shell's builtin services, such as + path searching and redirection. Like `rc', it is great for both + interactive use and for scripting, particularly since its quoting rules + are much less baroque than the C or Bourne shells. + + * `f2c' (LangT, SrcCD) + + `f2c' converts Fortran-77 source files into C or C++, which can be + compiled with GCC. You can get bug fixes by FTP from site + `netlib.att.com' or by email from `netlib@research.att.com'. The fixes + are summarized in the file `/netlib/f2c/changes.Z'. *Note Forthcoming + GNUs::, for information about GNU Fortran. + + * Fileutils (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + The fileutils work on files: `chgrp', `chmod', `chown', `cp', `dd', `df', + `dir', `du', `install', `ln', `ls', `mkdir', `mkfifo', `mknod', `mv', + `mvdir', `rm', `rmdir', `sync', `touch', & `vdir'. Only some of these + are on the *Note Selected Utilities Diskettes::. + + * Findutils (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + `find' is frequently used both interactively and in shell scripts to + find files which match certain criteria and perform arbitrary operations + on them. Also included are `xargs', which applies a command to a list + of files, and `locate', which scans a database for file names that match + a pattern. + + * Finger (SrcCD, UtilT) + + GNU Finger has more features than other finger programs. For sites with + many hosts, a single host may be designated as the finger "server" host, + and other hosts at that site configured as finger "clients". The server + host collects information about who is logged in to the clients. To + finger a user at a GNU Finger site, a query to any its client hosts gets + useful information. GNU Finger supports many customization features, + including user output filters, and site programmable output for special + target names. + + * `flex' (DjgppD, DosCD, LangT, SrcCD, UtilD) + + `flex' is a replacement for the `lex' scanner generator. `flex' was + written by Vern Paxson of the Lawrence Berkeley Laboratory and generates + far more efficient scanners than `lex' does. Source for the `Flex + Manual' and reference card are included. *Note Documentation::. + + * FlexFAX (UtilT) + + FlexFAX is now called HylaFAX. For more information, *Note GNU + Software::. + + * Fontutils (SrcCD, UtilT) + + The fontutils create fonts for use with Ghostscript or TeX, starting + with a scanned type image and converting the bitmaps to outlines. They + also contain general conversion programs and other utilities. + + Fontutils programs include: `bpltobzr', `bzrto', `charspace', + `fontconvert', `gsrenderfont', `imageto', `imgrotate', `limn', and + `xbfe'. + + * GAWK (DjgppD, DosCD, LangT, SrcCD) + + GAWK is upwardly compatible with the latest POSIX specification of + `awk'. It also provides several useful extensions not found in other + `awk' implementations. Texinfo source for the `GAWK Manual' comes with + the software. *Note Documentation::. + + * GCC (BinCD, DjgppD, DosCD, LangT, SrcCD, VMSCompT) + + Version 2 of the GNU C Compiler supports multiple languages; the source + file name suffix or a compiler option selects the language. The GNU C + Compiler distribution includes support for C, C++ and Objective-C. + Support for Objective-C was donated by NeXT. The runtime support needed + to run Objective-C programs is now distributed with GCC (this does not + include any Objective-C classes aside from `object'). As much as + possible, G++ is kept compatible with the evolving draft ANSI standard, + but not with `cfront' (AT&T's compiler), which has been diverging from + ANSI. + + The GNU C Compiler is a fairly portable optimizing compiler which + performs automatic register allocation, common sub-expression + elimination, invariant code motion from loops, induction variable + optimizations, constant propagation and copy propagation, delayed + popping of function call arguments, tail recursion elimination, + integration of inline functions and frame pointer elimination, + instruction scheduling, loop unrolling, filling of delay slots, leaf + function optimization, optimized multiplication by constants, a certain + amount of common subexpression elimination (CSE) between basic blocks + (though not all of the supported machine descriptions provide for + scheduling or delay slots), a feature for assigning attributes to + instructions, and many local optimizations that are automatically + deduced from the machine description. Position-independent code is + supported on the 68k, i386, i486, Pentium, Hitachi Slt, Hitachi H8/300, + Clipper, 88k, SPARC & SPARClite. + + GCC can open-code most arithmetic on 64-bit values (type `long long + int'). It supports extended floating point (type `long double') on the + 68k; other machines will follow. + + GCC supports full ANSI C, traditional C & GNU C extensions (including: + nested functions support, nonlocal gotos & taking the address of a + label). + + GCC can generate a.out, COFF, ELF & OSF-Rose files when used with a + suitable assembler. It can produce debugging information in these + formats: BSD stabs, COFF, ECOFF, ECOFF with stabs & DWARF. + + GCC generates code for many CPUs, including: a29k, Alpha, ARM, AT&T + DSP1610, Convex cN, Clipper, Elxsi, Fujitsu Gmicro, H8/300, HP-PA (1.0 + and 1.1) i370, i386, i486, Pentium, i860, i960, m68k, m68020, m68030, + m68040, m88k, MIL-STD-1750a, MIPS, ns32k, PDP-11, Pyramid, ROMP, RS6000, + SH, SPARC, SPARClite, VAX, & we32k. + + Operating systems supported include: AIX, ACIS, AOS, BSD, Clix, Ctix, + DG/UX, Dynix, Genix, GNU, HP-UX, ISC, Irix, GNU/Linux, Luna, LynxOS, + Mach, Minix, NetBSD, NewsOS, OSF, OSF-Rose, RISCOS, SCO, Solaris 2, + SunOS 4, SysV, Ultrix, Unos, VMS & Windows/NT. + + Using the configuration scheme for GCC, building a cross-compiler is as + easy as building a native compiler. + + We no longer maintain version 1 of GCC, G++, or libg++. + + Texinfo source for the `Using and Porting GNU CC' manual, is included + with GCC. *Note Forthcoming GNUs::, for plans for later releases of + GCC. + + * GDB (BinCD, DjgppD, DosCD, LangT, SrcCD) + + GDB, the GNU DeBugger, is a source-level debugger which supports C, C++, + and Fortran. + + GDB can debug both C and C++ programs, and will work with executables + produced by many different compilers; however, C++ debugging will have + some limitations if you do not use GCC. + + GDB has a command line user interface; GNU Emacs comes with a GDB mode, + and `xxgdb' provides an X interface (but it is not distributed or + maintained by the FSF; FTP it from `ftp.x.org' in the + `/contrib/utilities' directory). + + Executable files and symbol tables are read via the BFD library, which + allows a single copy of GDB to debug programs with multiple object file + formats (e.g., a.out, COFF, ELF). Other features include a rich command + language, remote debugging over serial lines or TCP/IP, and watchpoints + (breakpoints triggered when the value of an expression changes). + + GDB defines a standard interface for simulators, and the included + simulator library includes simulators for the Zilog Z8001/2, Hitachi + H8/300, H8/500 & Super-H. + + GDB can perform cross-debugging. To say that GDB "targets" a platform + means that it can perform native or cross-debugging for it. To say that + GDB can "host" a given platform means that it can be built on it, but + cannot necessarily debug native programs. GDB can: + + * "target" & "host": Amiga 3000 (Amix), DEC Alpha (OSF/1), DECstation + 3100 & 5000 (Ultrix), HP 9000/300 (BSD, HP-UX), HP 9000/700 (HP-UX), + i386 (BSD, FreeBSD, GNU/Linux, LynxOS, NetBSD, SCO), IBM RS/6000 + (AIX, LynxOS), Motorola Delta m88k (System V, CX/UX), PC532 + (NetBSD), Motorola m68k MVME-167 (LynxOS), NCR 3000 (SVR4), SGI + (Irix V3, V4, V5), SONY News (NewsOS 3.x), SPARC (SunOS 4.1, + Solaris, NetBSD, LynxOS) Sun-3 (SunOS 4.1), & Ultracomputer (a29k + running Sym1). + + * "target", but not "host": AMD 29000 (COFF & a.out), Hitachi H8/300, + Hitachi SH, i386 (a.out, COFF, OS/9000) i960 (Nindy, VxWorks), + m68k/m68332 (a.out, COFF, VxWorks), MIPS (IDT ecoff, ELF), Fujitsu + SPARClite (a.out, COFF), & Z8000. + + * "host", but not "target": IBM RT/PC (AIX), and HP/Apollo 68k (BSD). + + GDB can use the symbol tables emitted by the vendor-supplied compilers of + most MIPS-based machines, including DEC. (These tables are in a format + which almost nobody else uses.) Source for the manual + `Debugging with GDB' and a reference card are included. *Note + Documentation::. + + * `gdbm' (LangT, SrcCD, UtilD) + + `gdbm' is the GNU replacement for the traditional `dbm' and `ndbm' + libraries. It implements a database using quick lookup by hashing. + `gdbm' does not ordinarily make sparse files (unlike its Unix and BSD + counterparts). + + * Ghostscript (DjgppD, DosCD, SrcCD, UtilT) + + GNU Ghostscript is the GNU release of Ghostscript, which is an + interpreter for the Postscript graphics language (*note Forthcoming + GNUs::., for news on future plans). + + The current version of GNU Ghostscript is 2.6.2. Features include the + ability to use the fonts provided by the platform on which Ghostscript + runs (X Window System and Microsoft Windows), resulting in much + better-looking screen displays; improved text file printing (like + `enscript'); a utility to extract the text from a Postscript language + document; a much more reliable (and faster) Microsoft Windows + implementation; support for Microsoft C/C++ 7.0; drivers for many new + printers, including the SPARCprinter, and for TIFF/F (fax) file format; + many more Postscript Level 2 facilities, including most of the color + space facilities (but not patterns), and the ability to switch between + Level 1 and Level 2 dynamically. Version 2.6.2 adds a LaserJet 4 driver + and several important bug fixes to version 2.6.1. + + Ghostscript executes commands in the Postscript language by writing + directly to a printer, drawing on an X window, or writing to a file for + later printing (or to a bitmap file that you can manipulate with other + graphics programs). + + Ghostscript includes a C-callable graphics library (for client programs + that do not want to deal with the Postscript language). It also supports + IBM PCs and compatibles with EGA, VGA, or SuperVGA graphics (but please + do *not* ask the FSF staff any questions about this; we do not use PCs). + + * Ghostview (SrcCD, UtilT) + + Tim Theisen, `ghostview@cs.wisc.edu', has created Ghostview, a previewer + for multi-page files with an X11 user interface. Ghostview and + Ghostscript function as two cooperating programs; Ghostview creates a + viewing window and Ghostscript draws in it. + + * `gmp' (LangT, SrcCD) + + GNU mp is a library for arbitrary precision arithmetic on signed integers + and rational numbers. It has a rich set of functions with a regular + interface. + + * GNATS (SrcCD, UtilT) + + GNATS (GNats: A Tracking System, not to be confused with GNAT, The GNU + Ada Translator) is a bug-tracking system. It is based upon the paradigm + of a central site or organization which receives problem reports and + negotiates their resolution by electronic mail. Although it has been + used primarily as a software bug-tracking system so far, it is + sufficiently generalized so that it could be used for handling system + administration issues, project management or any number of other + applications. + + * `gnuplot' (SrcCD, UtilT, WdwsD) + + `gnuplot' is an interactive program for plotting mathematical + expressions and data. It handles both curves (2 dimensions) and surfaces + (3 dimensions). Curiously, the program was neither written nor named for + the GNU Project; the name is a coincidence. Various GNU programs use + `gnuplot' to produce graphical output. + + * GnuGo (SrcCD, UtilT) + + GnuGo plays the game of Go (Wei-Chi); it is not yet very sophisticated. + + * `gperf' (LangT, SrcCD) + + `gperf' generates perfect hash tables. There are two implementations of + `gperf', written in C and C++. Both produce hash functions in either C + or C++. + + * GNU Graphics (SrcCD, UtilT) + + GNU Graphics is a system which produces x-y plots from ASCII or binary + data. It supports output in Postscript, Tektronix 4010 compatible and + Unix device-independent "plot" formats as well as a previewer for the X + Window System. Features include a `spline' interpolation program; + examples of shell scripts using `graph' and `plot'; and a statistics + toolkit; and output in TekniCAD TDA and ln03 file formats. Email bugs or + questions to Rich Murphey, `Rich@lamprey.utmb.edu'. + + * grep (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + This package has GNU `grep', `egrep', and `fgrep' which find lines that + match inputed patterns. They are much faster than the traditional Unix + versions. + + * Groff (DjgppD, DosCD, SrcCD, UtilT) + + Groff is a document formatting system based on an implementation of + device-independent troff, which also includes implementations of `eqn', + `nroff', `pic', `refer', `tbl', `troff', and the `man', `ms', and `mm' + macros, as well as drivers for Postscript, TeX `dvi' format, and + typewriter-like devices. + + Groff's `mm' macro package is almost compatible with the DWB `mm' macros + and has several extensions. Also included is a modified version of the + Berkeley `me' macros and an enhanced version of the X11 `xditview' + previewer. Written in C++, these programs can be compiled with GNU C++ + Version 2.5 or later. A driver for the LaserJet 4 series of printers is + currently in test. + + Groff users are encouraged to contribute enhancements. Most needed are + complete Texinfo documentation, a `grap' emulation (a `pic' preprocessor + for typesetting graphs), a page-makeup postprocessor similar to `pm' + (see `Computing Systems', Vol. 2, No. 2; ask `office@usenix.org' how to + get a copy) and an ASCII output class for `pic' so that `pic' can be + integrated with Texinfo. Questions and bug reports from users who have + read the documentation provided with groff can be sent to + `bug-groff@prep.ai.mit.edu'. + + * `gzip' (DjgppD, DosCD, LangT, LspEmcT, SrcCD, UtilT) + + Some of the contents of our tape and FTP distributions are compressed. + We have software on our tapes and FTP sites to uncompress these files. + Due to patent troubles with `compress', we use another compression + program, `gzip'. (Such prohibitions on software development are fought + by the League for Programming Freedom, *note What Is the LPF::., for + details.) `gzip' can expand LZW-compressed files but uses another, + unpatented algorithm for compression which generally produces better + results. It also expands files compressed with System V's `pack' + program. + + * `hello' (DjgppD, DosCD, SrcCD, UtilT) + + The GNU `hello' program produces a familiar, friendly greeting. It + allows non-programmers to use a classic computer science tool which would + otherwise be unavailable to them. Because it is protected by the GNU + General Public License, users are free to share and change it. + + Like any truly useful program, `hello' contains a built-in mail reader. + + * `hp2xx' (SrcCD, UtilT) + + GNU `hp2xx' reads HP-GL files, decomposes all drawing commands into + elementary vectors, and converts them into a variety of vector and raster + output formats. It is also an HP-GL previewer. Currently supported + vector formats include encapsulated Postscript, Uniplex RGIP, Metafont + and various special TeX-related formats, and simplified HP-GL (line + drawing only) for imports. Raster formats supported include IMG, PBM, + PCX, & HP-PCL (including Deskjet & DJ5xxC support). Previewers work + under X11 (Unix), OS/2 (PM & full screen), MS-DOS (SVGA, VGA, & HGC). + + * HylaFAX (UtilT) + + HylaFAX is a facsimile system for Unix systems. It supports sending, + receiving, and polled retrieval of facsimile, as well as transparent + shared data use of the modem. Information is also available on the + World Wide Web at URL: `http://www.vix.com/hylafax/'. + + * `indent' (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + GNU `indent' is a revision of the BSD version. By default, it formats C + source according to the GNU coding standards. The BSD default, K&R and + other formats are available as options. It is also possible to define + your own format. GNU `indent' is more robust and provides more + functionality than other versions, e.g., it handles C++ comments. + + * Ispell (DjgppD, DosCD, SrcCD, UtilT) + + Ispell is an interactive spell checker that suggests "near misses" as + replacements for unrecognized words. System & user-maintained + dictionaries for multiple languages can be used. Standalone & GNU Emacs + interfaces are available. Previously, the GNU Project had its own + version of ispell ("Ispell 4.0"), but has dropped it for a parallel + branch that has had more development ("Ispell 3.1"). (Version 3 was an + earlier release from the original Ispell author, but others have since + made it more sophisticated.) + + * JACAL *Not available from the FSF* + + JACAL is a symbolic mathematics system for the manipulation and + simplification of equations and single and multiple-valued algebraic + expressions constructed of numbers, variables, radicals, differential + operators, and algebraic and holonomic functions. Vectors, matrices, + and tensors of these objects are also supported. + + JACAL was written in Scheme by Aubrey Jaffer. It comes with SCM, an IEEE + P1178 and R4RS compliant version of Scheme written in C. SCM runs on + Amiga, Atari-ST, MS-DOS, OS/2, NOS/VE, Unicos, VMS, Unix, and similar + systems. SLIB is a portable Scheme library used by JACAL. + m{No Value For "ergegrafkludge"} The FSF is not distributing JACAL on + any media. To receive an IBM PC floppy disk with the source and + executable files, send $99.00 to: + Aubrey Jaffer + 84 Pleasant Street + Wakefield, MA 01880-1846 + USA + + * `less' (SrcCD, UtilD, UtilT) + + `less' is a display paginator similar to `more' and `pg' but with + various features (such as the ability to scroll backwards) that most + pagers lack. + + * `m4' (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + GNU `m4' is an implementation of the traditional Unix macro processor. + It is mostly SVR4 compatible, although it has some extensions (for + example, handling more than 9 positional parameters to macros). `m4' + also has built-in functions for including files, running shell commands, + doing arithmetic, etc. + + * `make' (BinCD, DjgppD, DosCD, LangT, LspEmcT, SrcCD, UtilD, + UtilT) + + GNU `make' supports POSIX 1003.2 and has all but a few obscure features + of the BSD and System V versions of `make', as well as many of our own + extensions. GNU extensions include long options, parallel compilation, + flexible implicit pattern rules, conditional execution and powerful text + manipulation functions. Texinfo source for the `Make Manual' comes with + the program. *Note Documentation::. + + GNU `make' is on several of our tapes because some system vendors supply + no `make' utility at all, and some native `make' programs lack the + `VPATH' feature essential for using the GNU configure system to its full + extent. The GNU `make' sources have a shell script to build `make' + itself on such systems. + + MS-DOS binaries for `make' are available with the DJGPP distribution. + + * MandelSpawn (SrcCD, UtilT) + + A parallel Mandelbrot generation program for the X Window System. + + * mtools (SrcCD, UtilT) + + mtools is a set of public domain programs to allow Unix systems to read, + write and manipulate files on an MS-DOS file system (usually a diskette). + + * MULE (EmcsD, DosCD, SrcCD) + + MULE is a MULtilingual Enhancement to GNU Emacs. It can handle many + character sets at once including Japanese, Chinese, Korean, Vietnamese, + Thai, Greek, the ISO Latin-1 through Latin-8 character sets, Ukrainian, + Arabic, Hebrew, Russian, and other Cyrillic alphabets. A text buffer in + MULE can contain a mixture of characters from these languages. To input + any of these characters, you can use various input methods provided by + MULE itself. In addition, if you use MULE under some terminal emulators + (kterm, cxterm, or exterm), you can use its input methods. MULE is + being merged into GNU Emacs. *Note GNU and Other Free Software in + Japan::, for more information about MULE. + + * NetHack (SrcCD, UtilT) + + NetHack is a display-oriented adventure game similar to Rogue. Both + ASCII and X displays are supported. + + * NIH Class Library (LangT, SrcCD) + + The NIH Class Library (formerly known as "OOPS", Object-Oriented Program + Support) is a portable collection of C++ classes, similar to those in + Smalltalk-80, which has been developed by Keith Gorlen of the National + Institutes of Health (NIH), using the C++ programming language. + + * `nvi' (SrcCD, UtilT) + + `nvi' is a free implementation of the `vi'/`ex' Unix editor. It has + most of the functionality of the original `vi'/`ex', except "open" mode + & the `lisp' option, which will be added. Enhancements over `vi'/`ex' + include split screens with multiple buffers, handling 8-bit data, + infinite file & line lengths, tag stacks, infinite undo & extended + regular expressions. It runs under GNU/Linux, BSD, NetBSD, FreeBSD, + BSDI, AIX, HP-UX, DGUX, IRIX, PSF, PTX, Solaris, SunOS, Ultrix, Unixware + & should port easily to many other systems. + + * GNU Objective-C Library (LangT, SrcCD) + + The GNU Objective-C Class Library (`libobjects') is a library of + general-purpose, non-graphical Objective-C objects written by Andrew + McCallum and other volunteers. It includes collection classes for + maintaining groups of objects and C types, streams for I/O to various + destinations, coders for formatting objects and C types to streams, ports + for network packet transmission, distributed objects (remote object + messaging), string classes, pseudo-random number generators, and time + handling facilities. The package will also include the foundation + classes for the GNUStep project; over 50 of these classes have already + been implemented. The library is known to work on i386, i486, Pentium, + m68k, SPARC, MIPS, & RS6000. Send queries and bug reports to + `mccallum@gnu.ai.mit.edu'. + + * `OBST' (LangT, SrcCD) + + `OBST' is a persistent object management system with bindings to C++. + `OBST' supports incremental loading of methods. Its graphical tools + require the X Window System. It features a hands-on tutorial including + sample programs. It compiles with g++ and should install easily on most + Unix platforms. + + * Octave (LangT, SrcCD) + + Octave is a high-level language similar to MATLAB that is primarily + intended for numerical computations. It provides a convenient command + line interface for solving linear and nonlinear problems numerically. + m{No Value For "ergegrafkludge"} Octave does arithmetic for real and + complex scalars and matrices, solves sets of nonlinear algebraic + equations, integrates systems of ordinary differential and + differential-algebraic equations, and integrates functions over finite + and infinite intervals. Two- and three-dimensional plotting is + available using `gnuplot'. Send queries and bug reports to: + `bug-octave@che.utexas.edu'. Source is included for a 220+ page + Texinfo manual, which is not yet published by the FSF. + + * Oleo (SrcCD, UtilT) + + Oleo is a spreadsheet program (better for you than the more expensive + spreadsheets). It supports the X Window System and character-based + terminals, and can output Embedded Postscript renditions of spreadsheets. + Keybindings should be familiar to Emacs users and are configurable. + Under X and in Postscript output, Oleo supports multiple, variable width + fonts. *Note Forthcoming GNUs::, for the plans for later releases of + Oleo. + + * `p2c' (LangT, SrcCD) + + `p2c' is a Pascal-to-C translator written by Dave Gillespie. It + recognizes many Pascal dialects including Turbo, HP, VAX, and ISO, and + produces readable, maintainable, portable C. + + * `patch' (DjgppD, DosCD, SrcCD, UtilT) + + `patch' is our version of Larry Wall's program to take `diff''s output + and apply those differences to an original file to generate the modified + version. + + * PCL (LspEmcT, SrcCD) + + PCL is a free implementation of a large subset of CLOS, the Common Lisp + Object System. It runs under both GCL and CLISP, mentioned above. + + * `perl' (LangT, SrcCD) + + Larry Wall's `perl' combines the features and capabilities of `sed', + `awk', `sh' and C, as well as interfaces to the Unix system calls and + many C library routines. + + * `ptx' (SrcCD, UtilD, UtilT) + + GNU `ptx' is our version of the traditional permuted index generator. + It handles multiple input files at once, produces TeX compatible output, + & outputs readable "KWIC" (KeyWords In Context) indexes. It does not + yet handle input files that do not fit in memory all at once. + + * `rc' (SrcCD, UtilT) + + `rc' is a shell that features a C-like syntax (much more so than `csh') + and far cleaner quoting rules than the C or Bourne shells. It's + intended to be used interactively, but is also great for writing + scripts. It inspired the shell `es'. + + * RCS (SrcCD, UtilD, UtilT) + + RCS, the Revision Control System, is used for version control & + management of software projects. When used with GNU `diff', RCS can + handle binary files (executables, object files, 8-bit data, etc). Also + see the item about CVS in this section. + + * `recode' (SrcCD, UtilT) + + GNU `recode' converts files between character sets and usages. When + exact transliterations are not possible, it may get rid of the offending + characters or fall back on approximations. This program recognizes or + produces nearly 150 different character sets and is able to + transliterate files between almost any pair. Most RFC 1345 character + sets are supported. + + * regex (LangT, SrcCD) + + The GNU regular expression library supports POSIX.2, except for + internationalization features. It is included in many GNU programs which + do regular expression matching and available separately. An alternative + regular expression package, `rx', comes with `sed'; it has the potential + to be faster than `regex' in most cases, but still needs work. + + * Scheme (SchmT, SrcCD) + + For information about Scheme, see *Note Scheme Tape::. + + * `screen' (SrcCD, UtilT) + + `screen' is a terminal multiplexer that runs several separate "screens" + (ttys) on a single character-based terminal. Each virtual terminal + emulates a DEC VT100 plus several ISO 6429 (ECMA 48, ANSI X3.64) and ISO + 2022 functions. Arbitrary keyboard input translation is also supported. + `screen' sessions can be detached and resumed later on a different + terminal type. Output in detached sessions is saved for later viewing. + + * `sed' (DjgppD, DosCD, SrcCD, UtilD, UtilT) + + `sed' is a stream-oriented version of `ed'. GNU `sed' comes with the + `rx' library, a faster version of `regex' (*note Forthcoming GNUs::.). + + * Sharutils (SrcCD, UtilT) + + `shar' makes so-called shell archives out of many files, preparing them + for transmission by electronic mail services, while `unshar' helps + unpack these shell archives after reception. `uuencode' prepares a file + for transmission over an electronic channel which ignores or otherwise + mangles the high order bit of bytes, while `uudecode' does the converse + transformation. + + * Shellutils (DjgppD, DosCD, SrcCD, UtilT) + + Use shellutils interactively or in shell scripts: `basename', `date', + `dirname', `echo', `env', `expr', `false', `groups', `hostname', `id', + `logname', `nice', `nohup', `pathchk', `printenv', `printf', `pwd', + `sleep', `stty', `su', `tee', `test', `true', `tty', `uname', `users', + `who', `whoami', and `yes'. + + * GNU Shogi (SrcCD, UtilT) + + Shogi is a Japanese game similar to Chess; a major difference is that + captured pieces can be returned into play. GNU Shogi is a variant of + GNU Chess; GNU Shogi implements the same features as GNU Chess and uses + similar heuristics. As a new feature, sequences of partial board + patterns can be introduced in order to help the program play toward + specific opening patterns. There are both character and X display + interfaces. GNU Shogi is primarily supported by Matthias Mutz on + behalf of the FSF. + + * Smalltalk (LangT, SrcCD) + + GNU Smalltalk is an interpreted object-oriented programming language + system written in highly portable C. It has been successfully ported to + many Unix and some other platforms, including DOS (but these non-Unix + ports are not available from the FSF). Current features include a + binary image save capability, the ability to invoke user-written C code + and pass parameters to it, a GNU Emacs editing mode, a version of the X + protocol invocable from Smalltalk, optional byte-code compilation + tracing and byte-code execution tracing, and automatically loaded + per-user initialization files. It implements all of the classes and + protocol in the Smalltalk-80 book "Smalltalk-80: The Language", except + for the graphic user interface (`GUI') related classes. + + *Note Forthcoming GNUs::, for plans for later releases of Smalltalk. + + * Superopt (LangT, SrcCD) + + Superopt is a function sequence generator that uses an exhaustive + generate-and-test approach to find the shortest instruction sequence for + a given function. You provide a function as input, a CPU to generate + code for, and how many instructions you can accept. Its application in + GCC is described in the `ACM SIGPLAN PLDI'92' proceedings. Superopt + supports: SPARC, m68k, m68020, m88k, IBM RS/6000, AMD 29000, Intel + 80x86, Pyramid, DEC Alpha, & HP-PA. + + * `tar' (SrcCD, UtilT) + + GNU `tar' includes multivolume support, the ability to archive sparse + files, automatic archive compression/decompression, remote archives and + special features that allow `tar' to be used for incremental and full + backups. Unfortunately, GNU `tar' implements an early draft of the + POSIX 1003.1 `ustar' standard which is different from the final + standard. Adding support for the new changes in a backward-compatible + fashion is not trivial. + + * Termcap Library (SrcCD, UtilT) + + The GNU Termcap library is a drop-in replacement for `libtermcap.a' on + any system. It does not place an arbitrary limit on the size of Termcap + entries, unlike most other Termcap libraries. Included is source for the + `Termcap Manual' in Texinfo format. *Note Documentation::. + + * TeX (SrcCD) + + TeX is a document formatting system that handles complicated + typesetting, including mathematics. It is GNU's standard text formatter. + + You can obtain TeX from the University of Washington, which maintains and + supports a tape distribution of TeX for Unix systems. The core material + consists of Karl Berry's `web2c' TeX package, the sources for which are + available via anonymous ftp; retrieval instructions are in + `pub/tex/unixtex.ftp' on `ftp.cs.umb.edu'. If you receive any + installation support from the University of Washington, please consider + sending them a donation. + + To order a full distribution written in `tar' on either a 1/4inch + 4-track QIC-24 cartridge or a 4mm DAT cartridge, send $210.00 to: + + Pierre A. MacKay + Department of Classics + DH-10, Denny Hall 218 + University of Washington + Seattle, WA 98195 + USA + + Electronic-Mail: `mackay@cs.washington.edu' + Telephone: +1-206-543-2268 + + Please make checks payable to the University of Washington. Do not + specify any other payee. That causes accounting difficulties. Checks + must be in U.S. dollars, drawn on a U.S. bank. Prepaid orders are the + only orders that can now be handled. Overseas sites: please add to the + base cost $20.00 for shipment via air parcel post, or $30.00 for + shipment via courier. Please check with the above for current prices + and formats. + + * Texinfo (DjgppD, DosCD, LangT, LspEmcT, SrcCD, UtilD, UtilT) + + Texinfo is a set of utilities which generate both printed manuals and + online hypertext documentation (called "Info"). There are also programs + for reading online Info documents. Version 3 has both GNU Emacs Lisp + and standalone programs written in C or shell script. Texinfo mode for + GNU Emacs enables easy editing and updating of Texinfo files. Programs + provided include `makeinfo', `info', `texi2dvi', `texindex', `tex2patch', + and `fixfonts'. Source for the `Texinfo Manual' is included. *Note + Documentation::. + + * Textutils (DjgppD, DosCD, SrcCD, UtilT) + + The Textutils programs manipulate textual data. They include: `cat', + `cksum', `comm', `csplit', `cut', `expand', `fmt', `fold', `head', + `join', `nl', `od', `paste', `pr', `sort', `split', `sum', `tac', `tail', + `tr', `unexpand', `uniq', and `wc'. + + * Tile Forth (LangT, SrcCD) + + Tile Forth is a 32-bit implementation of the Forth-83 standard written + in C, allowing it to be easily ported to new systems, and extended with + "any" C-function (graphics, windowing, etc). Many Forth libraries with + full documentation are available including ones for top-down parsing, + multi-threads, and object oriented programming. + + * `time' (SrcCD, UtilT) + + `time' is used to report statistics (usually from a shell) about the + amount of user, system and real time used by a process. On some systems + it also reports memory usage, page faults, and other statistics. + + * `tput' (SrcCD, UtilT) + + `tput' is a portable way for shell scripts to use special terminal + capabilities. Our `tput' uses the Termcap database, instead of Terminfo + as most others do. + + * UUCP (SrcCD, UtilT) + + This version of UUCP was written by Ian Lance Taylor, and is GNU's + standard UUCP system. It supports the `f', `g' and `v' (in all window + and packet sizes), `G', `t', `e', Zmodem and two new bidirectional (`i' + and `j') protocols. If you have a Berkeley sockets library, it can make + TCP connections. If you have TLI libraries, it can make TLI + connections. Source is included for a Texinfo manual, which is not yet + published by the FSF. + + * `wdiff' (DjgppD, DosCD, SrcCD, UtilT) + + `wdiff' is a front-end to GNU `diff'. It compares two files, finding + the words deleted or added to the first to make the second. It has many + output formats and works well with terminals and pagers. `wdiff' is + very useful when two texts differ only by a few words and paragraphs + have been refilled. + + * `Ygl' (SrcCD, UtilT) + + `Ygl' emulates SGI's GL (Graphics Language) library under X11. It runs + under GNU/Linux with XFree, AIX 3.2, ConvexOS, HP-UX 7.0/8.0/9.0, SunOS + and many others. + + + +Program/Package Cross Reference - (NOT COMPLETELY UP TO DATE) +******************************* + +Here is a list of what package each GNU program or library is in. You can +anonymously FTP a full list in the file `/pub/gnu/ProgramIndex' from a GNU +FTP host (*note How to Get GNU Software::. for a list). + + * a2p perl + * a2x xopt + * ac bsd44 + * accton bsd44 + * acl bsd44 + * acm acm + * acms acm + * addftinfo Groff + * adventure bsd44 + * afm2tfm TeX + * amd bsd44 + * ansitape bsd44 + * AnswerGarden xopt + * apply bsd44 + * appres xreq + * apropos bsd44 + * ar Binutils + * arithmetic bsd44 + * arp bsd44 + * atc bsd44 + * autoconf Autoconf + * autoheader Autoconf + * autoreconf Autoconf + * autoscan Autoconf + * autoupdate Autoconf + * auto_box xopt + * auto_box xreq + + * b2m Emacs + * backgammon bsd44 + * bad144 bsd44 + * badsect bsd44 + * banner bsd44 + * basename Shellutils + * bash BASH + * battlestar bsd44 + * bc bc + * bcd bsd44 + * bdes bsd44 + * bdftops Ghostscript + * beach_ball xopt + * beach_ball xreq + * beach_ball2 xopt + * bibtex TeX + * biff bsd44 + * bison Bison + * bitmap xreq + * boggle bsd44 + * bpltobzr Fontutils + * bugfiler bsd44 + * build ispell + * bzrto Fontutils + + * c++ GCC + * c++filt Binutils + * c2ph perl + * ca100 xopt + * caeser bsd44 + * cal bsd44 + * calendar bsd44 + * canfield bsd44 + * cat Textutils + * cbars wdiff + * cc GCC + * cc1 GCC + * cc1obj GCC + * cc1plus GCC + * cccp GCC + * charspace Fontutils + * checknr bsd44 + * chess bsd44 + * chflags bsd44 + * chgrp Fileutils + * ching bsd44 + * chmod Fileutils + * chown Fileutils + * chpass bsd44 + * chroot bsd44 + * ci RCS + * cksum Textutils + * clisp CLISP + * clri bsd44 + * cmail xboard + * cmmf TeX + * cmodext xopt + * cmp Diffutils + * co RCS + * col bsd44 + * colcrt bsd44 + * colrm bsd44 + * column bsd44 + * comm Textutils + * compress bsd44 + * comsat bsd44 + * connectd bsd44 + * cp Fileutils + * cpicker xopt + * cpio cpio + * cpp GCC + * cppstdin perl + * cribbage bsd44 + * crock xopt + * csh bsd44 + * csplit Textutils + * ctags Emacs + * ctwm xopt + * cu UUCP + * cut Textutils + * cvs CVS + * cvscheck CVS + * cvtmail Emacs + * cxterm xopt + + * d Fileutils + * date Shellutils + * dc bc + * dd Fileutils + * delatex TeX + * demangle Binutils + * descend CVS + * detex TeX + * df Fileutils + * diff Diffutils + * diff3 Diffutils + * digest-doc Emacs + * dipress bsd44 + * dir Fileutils + * dirname Shellutils + * dish xopt + * disklabel bsd44 + * diskpart bsd44 + * dld dld + * dm bsd44 + * dmesg bsd44 + * doschk doschk + * dox xopt + * du Fileutils + * dump bsd44 + * dumpfs bsd44 + * dvi2tty TeX + * dvicopy TeX + * dvips TeX + * dvitype TeX + + * ecc ecc + * echo Shellutils + * ed ed + * edit-pr GNATS + * editres xreq + * edquota bsd44 + * eeprom bsd44 + * egrep grep + * emacs Emacs + * emacsclient Emacs + * emacsserver Emacs + * emacstool Emacs + * emu xopt + * env Shellutils + * eqn Groff + * error bsd44 + * es es + * esdebug es + * etags Emacs + * ex nvi + * expand Textutils + * expect DejaGnu + * expr Shellutils + * exterm xopt + + * f2c f2c + * factor bsd44 + * fakemail Emacs + * false Shellutils + * fastboot bsd44 + * fax2ps HylaFAX + * faxalter HylaFAX + * faxanswer HylaFAX + * faxcover HylaFAX + * faxd HylaFAX + * faxd.recv HylaFAX + * faxmail HylaFAX + * faxquit HylaFAX + * faxrcvd HylaFAX + * faxrm HylaFAX + * faxstat HylaFAX + * fc f2c + * fdraw xopt + * fgrep grep + * file bsd44 + * find Findutils + * find2perl perl + * finger finger + * fingerd finger + * fish bsd44 + * fixfonts Texinfo + * fixinc.svr4 GCC + * fixincludes GCC + * flex flex + * fmt bsd44 + * fold Textutils + * font2c Ghostscript + * fontconvert Fontutils + * forth Tile Forth + * forthicon Tile Forth + * forthtool Tile Forth + * fortune bsd44 + * fpr bsd44 + * freq ispell + * freqtbl ispell + * from bsd44 + * fsck bsd44 + * fsplit bsd44 + * fstat bsd44 + * ftp bsd44 + * ftpd bsd44 + + * g++ GCC + * gas Binutils + * gawk Gawk + * gcc GCC + * gcore bsd44 + * gdb GDB + * genclass libg++ + * getty bsd44 + * gftodvi TeX + * gftopk TeX + * gftype TeX + * ghostview Ghostview + * gnats GNATS + * gnuchess Chess + * gnuchessc Chess + * gnuchessn Chess + * gnuchessr Chess + * gnuchessx Chess + * gnupdisp Shogi + * gnuplot gnuplot + * gnuplot_x11 gnuplot + * gnushogi Shogi + * gnushogir Shogi + * gnushogix Shogi + * go GnuGo + * gpc xopt + * gpc xreq + * gperf gperf + * gperf libg++ + * gprof Binutils + * graph Graphics + * grep grep + * grodvi Groff + * groff Groff + * grops Groff + * grotty Groff + * groups Shellutils + * gs Ghostscript + * gsbj Ghostscript + * gsdj Ghostscript + * gslj Ghostscript + * gslp Ghostscript + * gsnd Ghostscript + * gsrenderfont Fontutils + * gunzip gzip + * gwm xopt + * gzexe gzip + * gzip gzip + + * h2ph perl + * h2pl perl + * hack bsd44 + * hangman bsd44 + * head Textutils + * hello hello + * hexdump bsd44 + * hexl Emacs + * hostname Shellutils + * hp2xx hp2xx + * hterm xopt + + * i18nOlwmV2 xopt + * i2mif xopt + * ico xopt + * ico xreq + * id Shellutils + * ident RCS + * ifconfig bsd44 + * ifnames Autoconf + * ImageMagick xopt + * imageto Fontutils + * iman xopt + * imgrotate Fontutils + * indent indent + * indxbib Groff + * inetd bsd44 + * info Texinfo + * inimf TeX + * init bsd44 + * initex TeX + * inn bsd44 + * install Fileutils + * iostat bsd44 + * ispell ispell + * ixterm xopt + * ixx xopt + + * join Textutils + * jot bsd44 + * jove bsd44 + + * kdestroy bsd44 + * kdump bsd44 + * kermit bsd44 + * kgames xopt + * kgmon bsd44 + * kill bsd44 + * kinit bsd44 + * kinput2 xopt + * klist bsd44 + * kpasswdd bsd44 + * ksrvtgt bsd44 + * kterm xopt + * ktrace bsd44 + + * lam bsd44 + * larn bsd44 + * lasergnu gnuplot + * last bsd44 + * lastcomm bsd44 + * latex TeX + * lclock xopt + * ld Binutils + * leave bsd44 + * less less + * lesskey less + * libbfd.a Binutils + * libbfd.a GAS + * libbfd.a GDB + * libbzr.a Fontutils + * libc.a C Library + * libcompat.a bsd44 + * libcurses.a bsd44 + * libcurses.a nvi + * libedit.a bsd44 + * libF77.a f2c + * libg++.a libg++ + * libgdbm.a gdbm + * libgf.a Fontutils + * libgmp.a gmp + * libI77.a f2c + * libkvm.a bsd44 + * libm.a bsd44 + * libnihcl.a NIHCL + * libnihclmi.a NIHCL + * libnihclvec.a NIHCL + * libnls.a xreq + * liboctave.a Octave + * liboldX.a xreq + * libpbm.a Fontutils + * libPEXt.a xopt + * libpk.a Fontutils + * libresolv.a bsd44 + * librpc.a bsd44 + * libtcl.a DejaGnu + * libtelnet.a bsd44 + * libterm.a bsd44 + * libtermcap.a Termcap + * libtfm.a Fontutils + * libutil.a bsd44 + * libWc.a xopt + * libwidgets.a Fontutils + * libX.a xreq + * libXau.a xreq + * libXaw.a xreq + * libXcp.a xopt + * libXcu.a xopt + * libXdmcp.a xreq + * libXmp.a xopt + * libXmu.a xreq + * libXO.a xopt + * libXop.a xopt + * libXp.a xopt + * libXpex.a xopt + * libXt.a xopt + * libXt.a xreq + * libXwchar.a xopt + * liby.a bsd44 + * libYgl.a Ygl + * limn Fontutils + * listres xopt + * listres xreq + * lkbib Groff + * ln Fileutils + * locate Findutils + * lock bsd44 + * logger bsd44 + * login bsd44 + * logname Shellutils + * look ispell + * lookbib Groff + * lorder bsd44 + * lpr bsd44 + * ls Fileutils + + * m4 m4 + * mail bsd44 + * make Make + * make-docfile Emacs + * make-path Emacs + * makeindex TeX + * makeinfo Texinfo + * MakeTeXPK TeX + * man bsd44 + * man-macros Groff + * mattrib mtools + * maze xopt + * maze xreq + * mazewar xopt + * mcd mtools + * mcopy mtools + * mdel mtools + * mdir mtools + * me-macros Groff + * merge RCS + * mesg bsd44 + * mf TeX + * mformat mtools + * mft TeX + * mgdiff xopt + * mh bsd44 + * mille bsd44 + * mkdep bsd44 + * mkdir Fileutils + * mkfifo Fileutils + * mklocale bsd44 + * mkmanifest mtools + * mkmf bsd44 + * mkmodules CVS + * mknod Fileutils + * mkstr bsd44 + * mlabel mtools + * mm-macros Groff + * mmd mtools + * monop bsd44 + * more bsd44 + * morse bsd44 + * mount bsd44 + * mountd bsd44 + * movemail Emacs + * mprof bsd44 + * mrd mtools + * mread mtools + * mren mtools + * ms-macros Groff + * msgs bsd44 + * mt cpio + * mterm xopt + * mtree bsd44 + * mtype mtools + * mule MULE + * muncher xopt + * mv Fileutils + * mvdir Fileutils + * mwrite mtools + + * nethack Nethack + * netstat bsd44 + * newfs bsd44 + * nfsd bsd44 + * nfsiod bsd44 + * nfsstat bsd44 + * nice Shellutils + * nl Textutils + * nlmconv Binutils + * nm Binutils + * nohup Shellutils + * notify HylaFAX + * nroff Groff + * number bsd44 + + * objc GCC + * objcopy Binutils + * objdump Binutils + * objective-c GCC + * obst-boot OBST + * obst-CC OBST + * obst-cct OBST + * obst-cgc OBST + * obst-cmp OBST + * obst-cnt OBST + * obst-cpcnt OBST + * obst-csz OBST + * obst-dir OBST + * obst-dmp OBST + * obst-gen OBST + * obst-gsh OBST + * obst-init OBST + * obst-scp OBST + * obst-sil OBST + * obst-stf OBST + * oclock xreq + * octave Octave + * od Textutils + * oleo Oleo + * ora-examples xopt + + * p2c p2c + * pagesize bsd44 + * palette xopt + * pascal bsd44 + * passwd bsd44 + * paste Textutils + * patch patch + * patgen TeX + * pathalias bsd44 + * pathchk Shellutils + * pax bsd44 + * pbmplus xopt + * perl perl + * pfbtops Groff + * phantasia bsd44 + * pic Groff + * pig bsd44 + * ping bsd44 + * pixedit xopt + * pixmap xopt + * pktogf TeX + * pktype TeX + * plaid xopt + * plot2fig Graphics + * plot2plot Graphics + * plot2ps Graphics + * plot2tek Graphics + * pltotf TeX + * pollrcvd HylaFAX + * pom bsd44 + * pooltype TeX + * portmap bsd44 + * ppt bsd44 + * pr Textutils + * pr-addr GNATS + * pr-edit GNATS + * primes bsd44 + * printenv Shellutils + * printf Shellutils + * protoize GCC + * ps bsd44 + * ps2ascii Ghostscript + * ps2epsi Ghostscript + * ps2fax HylaFAX + * psbb Groff + * pstat bsd44 + * psycho xopt + * ptx ptx + * pubdic+ xopt + * puzzle xopt + * puzzle xreq + * pwd Shellutils + * pyramid xopt + + * query-pr GNATS + * quiz bsd44 + * quot bsd44 + * quota bsd44 + * quotacheck bsd44 + * quotaon bsd44 + + * rain bsd44 + * random bsd44 + * ranlib Binutils + * rbootd bsd44 + * rc rc + * rcp bsd44 + * rcs RCS + * rcs-to-cvs CVS + * rcs2log Emacs + * rcsdiff RCS + * rcsfreeze RCS + * rcsmerge RCS + * rdist bsd44 + * reboot bsd44 + * recode recode + * recvstats HylaFAX + * refer Groff + * renice bsd44 + * repquota bsd44 + * restore bsd44 + * rev bsd44 + * rexecd bsd44 + * rlog RCS + * rlogin bsd44 + * rlogind bsd44 + * rm Fileutils + * rmail bsd44 + * rmdir Fileutils + * rmt cpio + * rmt tar + * robots bsd44 + * rogue bsd44 + * route bsd44 + * routed bsd44 + * rr xopt + * rs bsd44 + * rsh bsd44 + * rshd bsd44 + * runtest DejaGnu + * runtest.exp DejaGnu + * ruptime bsd44 + * rwho bsd44 + * rwhod bsd44 + + * s2p perl + * sail bsd44 + * savecore bsd44 + * sc bsd44 + * sccs bsd44 + * sccs2rcs CVS + * scdisp xopt + * screen screen + * script bsd44 + * scsiformat bsd44 + * sctext xopt + * sdiff Diffutils + * sed sed + * send-pr GNATS + * sendfax HylaFAX + * sendmail bsd44 + * sgi2fax HylaFAX + * sh bsd44 + * shar Sharutils + * shinbun xopt + * shogi Shogi + * showfont xopt + * showmount bsd44 + * shutdown bsd44 + * size Binutils + * sj3 xopt + * sjxa xopt + * slattach bsd44 + * sleep Shellutils + * sliplogin bsd44 + * snake bsd44 + * snftobdf xopt + * soelim Groff + * sort Textutils + * sos2obst OBST + * spider xopt + * split Textutils + * startslip bsd44 + * stf OBST + * strings Binutils + * strip Binutils + * stty Shellutils + * su Shellutils + * sum Textutils + * superopt Superopt + * swapon bsd44 + * sync bsd44 + * sysctl bsd44 + * syslogd bsd44 + * systat bsd44 + + * tac Textutils + * tail Textutils + * taintperl perl + * talk bsd44 + * talkd bsd44 + * tangle TeX + * tar tar + * tbl Groff + * tcl DejaGnu + * tclsh DejaGnu + * tcopy bsd44 + * tcp Emacs + * tee Shellutils + * tek2plot Graphics + * telnet bsd44 + * telnetd bsd44 + * test Shellutils + * test-g++ DejaGnu + * test-tool DejaGnu + * tetris bsd44 + * tex TeX + * tex3patch Texinfo + * texi2dvi Texinfo + * texindex Texinfo + * texspell TeX + * textfmt HylaFAX + * tfmtodit Groff + * tftopl TeX + * tftp bsd44 + * tftpd bsd44 + * tgrind TeX + * time time + * timed bsd44 + * timer Emacs + * timex xopt + * tip bsd44 + * tkpostage xopt + * tn3270 bsd44 + * touch Fileutils + * tput tput + * tr Textutils + * traceroute bsd44 + * transcript HylaFAX + * transfig xopt + * trek bsd44 + * trn3 bsd44 + * troff Groff + * trpt bsd44 + * trsp bsd44 + * true Shellutils + * tset bsd44 + * tsort bsd44 + * tty Shellutils + * tunefs bsd44 + * tvtwm xopt + * twm xreq + + * ul bsd44 + * umount bsd44 + * uname Shellutils + * uncompress gzip + * unexpand Textutils + * unifdef bsd44 + * uniq Textutils + * unprotoize GCC + * unshar Sharutils + * unvis bsd44 + * update bsd44 + * updatedb Findutils + * users Shellutils + * uuchk UUCP + * uucico UUCP + * uuconv UUCP + * uucp UUCP + * uucpd bsd44 + * uudecode Sharutils + * uudir UUCP + * uuencode Sharutils + * uulog UUCP + * uuname UUCP + * uupick UUCP + * uurate UUCP + * uusched UUCP + * uustat UUCP + * uuto UUCP + * uux UUCP + * uuxqt UUCP + + * v Fileutils + * vacation bsd44 + * vandal xopt + * vcdiff Emacs + * vdir Fileutils + * vftovp TeX + * vgrind bsd44 + * vi nvi + * viewres xopt + * viewres xreq + * vine xopt + * vipw bsd44 + * virmf TeX + * virtex TeX + * vis bsd44 + * vmstat bsd44 + * vptovf TeX + + * w bsd44 + * wakeup Emacs + * wall bsd44 + * wargames bsd44 + * wc Textutils + * wdiff wdiff + * weave TeX + * what bsd44 + * whatis bsd44 + * whereis bsd44 + * who Shellutils + * whoami Shellutils + * whois bsd44 + * window bsd44 + * winterp xopt + * wish DejaGnu + * worm bsd44 + * worms bsd44 + * write bsd44 + * wump bsd44 + + * x11perf xreq + * x2p perl + * xalarm xopt + * xancur xopt + * xargs Findutils + * xauth xreq + * xbfe Fontutils + * xbiff xopt + * xbiff xreq + * xboard xboard + * xboing xopt + * xbuffy3 xopt + * xcalc xopt + * xcalc xreq + * xcalendar xopt + * xcdplayer xopt + * xcell xopt + * xclipboard xreq + * xclock xreq + * xcmdmenu xopt + * xcms xopt + * xcmsdb xreq + * xcmstest xreq + * xco xopt + * xcolorize xopt + * xcolors xopt + * xconsole xreq + * xcrtca xopt + * xdaliclock xopt + * xdiary xopt + * xditview Groff + * xditview xopt + * xditview xreq + * xdm xreq + * xdpyinfo xreq + * xdu xopt + * xdvi TeX + * xdvi xopt + * xdvorak xopt + * xearth xopt + * xed xopt + * xedit xopt + * xedit xreq + * xev xopt + * xev xreq + * xexit xopt + * xeyes xopt + * xeyes xreq + * xfd xreq + * xfed xopt + * xfedor xopt + * xfeoak xopt + * xferstats HylaFAX + * xfig xopt + * xfontsel xopt + * xfontsel xreq + * xforecast xopt + * xgas xopt + * xgas xreq + * xgc xopt + * xgc xreq + * xhearts xopt + * xhelp xopt + * xhost xreq + * xinit xreq + * xkeycaps xopt + * xkill xreq + * xlax xopt + * xlayout xopt + * xlbiff xopt + * xless xopt + * xload xopt + * xload xreq + * xlogin xopt + * xlogo xreq + * xlsatoms xreq + * xlsclients xreq + * xlsfonts xreq + * xmag xreq + * xmail xopt + * xmailbox xopt + * xmailwatcher xopt + * xman xopt + * xman xreq + * xmandel xopt + * xmessage xopt + * xmeter xopt + * xmh xreq + * xmh-icons xopt + * xmh.editor xopt + * xmodmap xreq + * xmon xopt + * xmove xopt + * xmphone xopt + * xpd xopt + * xphoon xopt + * xpipeman xopt + * xplot Graphics + * xpostit xopt + * xpr xopt + * xpr xreq + * xprompt xopt + * xproof xopt + * xprop xreq + * xpserv xopt + * xrdb xreq + * xrefresh xreq + * xrsh xopt + * xrubik xopt + * xrunclient xopt + * xscope xopt + * xscreensaver xopt + * xsession xopt + * xset xreq + * xsetroot xreq + * xshogi xshogi + * xstdcmap xreq + * xstr bsd44 + * xtalk xopt + * xterm xreq + * xterm_color xopt + * xtetris xopt + * xTeXcad.13 xopt + * xtiff xopt + * xtree xopt + * xtv xopt + * xwd xreq + * xwininfo xreq + * xwud xreq + + * yacc bsd44 + * yes Shellutils + * youbin xopt + * yow Emacs + + * zcat gzip + * zcmp gzip + * zdiff gzip + * zforce gzip + * zgrep gzip + * zmore gzip + * znew gzip + + * [ Shellutils + + + +Tapes +***** + +We offer Unix source code on tapes in `tar' format on these media: + + * 4mm DAT cartridges + + * 8mm Exabyte cartridges + + * Sun DC300XLP QIC-24 1/4in cartridges (readable on some other systems) + + * Hewlett-Packard 16-track DC600HC 1/4in cartridges + + * IBM RS/6000 QIC-150 1/4in cartridges (readable on some other systems) + + * 1600bpi 9-track 1/2in reel tape + +The contents of the reel and various cartridge tapes for Unix systems are the +same (except for the RS/6000 Emacs tape, which also has executables for +Emacs); only the media are different. For pricing information, see the *note +Free Software Foundation Order Form::.. Source code for the manuals and +reference cards is included (*note Documentation::.). + +Some of the files on the tapes may be compressed with `gzip' to make them +fit. Refer to the top-level `README' file at the beginning of each tape for +instructions on uncompressing them. `uncompress' and `unpack' *do not work*! + + + +Languages Tape - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +-------------- + +This tape contains programming tools: compilers, interpreters, and related +programs (parsers, conversion programs, debuggers, etc.). + + * Binutils 2.5.2 + * Bison 1.22 + * C Library 1.09 + * DejaGnu 1.2 + * dld 3.2.3 + * ecc 1.2.1 + * f2c 1994.11.03 + * flex 2.4.7 + * Gawk 2.15.5 + * GCC/G++/Objective-C 2.7.0 + * GDB 4.13 + * gdbm 1.7.3 + * gmp 1.3.2 + * gperf 2.1a + * gzip 1.2.4 + * indent 1.9.1 + * libg++ 2.6.1 + * libobjects 0.1.0 + * Make 3.72.1 + * NIHCL 3.0 + * OBST 3.4 + * Octave 1.0 + * p2c 1.20 + * perl 4.036 + * perl 5.000 + * regex 0.12 + * rx 0.05 + * Smalltalk 1.1.1 + * Superopt 2.3 + * Texinfo 3.1 + * Tile Forth 2.1 + + + +Lisps and Emacs Tape - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +-------------------- + +This tape has Common Lisp systems and libraries, GNU Emacs, assorted +extensions that work with GNU Emacs, and a few other important utilities. + + * Calc 2.02c + * CLISP 1994.10.26 + * Common Lisp 1.1 + * elib 0.06 + * Emacs 18.59 + * Emacs 19.29 + * GNU Emacs Lisp Reference Manaul, Ed. 2.3 + * gzip 1.2.4 + * Make 3.72.1 + * MULE 2.1 + * PCL 1993.03.18 + * Texinfo 3.1 + + + +Utilities Tape - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +-------------- + +This tape consists mostly of smaller utilities and miscellaneous applications. + + * acm 4.6 + * Autoconf 1.11 + * Autoconf 2.1 + * BASH 1.14.2 + * bc 1.03 + * Chess 4.0.73 + * cpio 2.3 + * CVS 1.3 + * dc 0.2 + * Diffutils 2.7 + * doschk 1.1 + * ed 0.2 + * es 0.84 + * Fileutils 3.12 + * Findutils 4.1 + * finger 1.37 + * HylaFAX 2.2.2.1 + * Fontutils 0.6 + * Ghostscript 2.6.1 + * Ghostview 1.5 + * GNATS 3.2 + * GnuGo 1.1 + * gnuplot 3.5 + * Graphics 0.17 + * grep 2.0 + * Groff 1.09 + * gzip 1.2.4 + * hello 1.3 + * hp2xx 3.1.4 + * ispell 3.1.13 + * m4 1.3 + * Make 3.72.1 + * mkisofs 1.01 + * mm 1.07 + * mtools 2.0.7 + * Nethack 3.1.3 + * nvi 1.34 + * Oleo 1.6 + * patch 2.1 + * ptx 0.4 + * rc 1.4 + * RCS 5.6.0.1 + * recode 3.4 + * saoimage 1.08 + * screen 3.5.2 + * screen 3.6.0 + * sed 1.18 & 2.05 + * Sharutils 4.1 + * Shellutils 1.12 + * Shogi 1.2.02 + * tar 1.11.2 + * Termcap 1.2 + * Texinfo 3.1 + * Textutils 1.11 + * time 1.6 + * tput 1.0 + * UUCP 1.05 + * wdiff 0.04 + * xboard 3.1.1 + * xshogi 1.2.02 + * Ygl 2.9 + + + +Scheme Tape +----------- + +Scheme is a simplified, lexically-scoped dialect of Lisp. It was designed at +MIT and other universities to teach students the art of programming, and to +research new parallel programming constructs and compilation techniques. + +This tape now contains MIT Scheme 7.3, which conforms to the "Revised^4 +Report On the Algorithmic Language Scheme" (MIT AI Lab Memo 848b), for which +TeX source is included. It is written partly in C, but is presently hard to +bootstrap. Binaries that can be used to bootstrap Scheme are available for: + + * HP 9000 series 300, 400, 700 & 800 running HP-UX 7.0 or 8.0 + + * NeXT running NeXT OS 1.0 or 2.0 + + * Sun-3 or Sun-4 running SunOS 4.1 + + * DECstation 3100/5100 running Ultrix 4.0 + + * Sony NeWS-3250 running NEWS OS 5.01 + + * Vax running 4.3BSD + +If your system is not on this list and you don't enjoy the bootstrap +challenge, see the JACAL item in *Note GNU Software::. + + + +X11 Tapes +--------- + +The two X11 tapes contain Version 11, Release 6 of the X Window System. The +first tape contains all of the core software, documentation and some +contributed clients. We call this the "required" X tape since it is +necessary for running X or running GNU Emacs under X. The second, "optional" +tape contains contributed libraries and other toolkits, the Andrew User +Interface System, games, and other programs. + +The X11 Required tape also contains all fixes and patches released to date. +We update this tape as new fixes and patches are released for programs on +both tapes. *Note Tape & CD-ROM Subscription Service::. + +We will distribute X11R5 on tape until X11R6 is stable, and on the *Note +November 1993 Source Code CD-ROM::, while supplies last. + + + +Berkeley 4.4BSD-Lite Tape +------------------------- + +The "4.4BSD-Lite" release is the last from the Computer Systems Research +Group at the University of California at Berkeley. It has most of the BSD +software system, except for a few files that remain proprietary. It is much +more complete than the previous "Net2" release. + + + +VMS Emacs and VMS Compiler Tapes +-------------------------------- + +We offer two VMS tapes. One has just GNU Emacs 18.59 (none of the other +software on the *Note Lisps/Emacs Tape::, is included). The other has GCC +2.3.3, Bison 1.19 (to compile GCC), GAS 1.38 (to assemble GCC's output) and +some library and include files (none of the other software on the *Note +Languages Tape::, is included). We are not aware of a GDB port for VMS. +Both VMS tapes have DEC VAX executables from which you can bootstrap, as the +DEC VMS C compiler cannot compile GCC. We do not have executables for DEC +Alpha VMS systems. Please do not ask us to devote effort to VMS support, +because it is peripheral to the GNU Project. + + + +CD-ROMs +******* + +We offer these CD-ROMs: + + * *Note MS-DOS CD-ROM::, expected in September 1995. + + * *Note Debian GNU/Linux CD-ROM::, expected in late fall 1995. + + * *Note Compiler Tools Binaries CD-ROM::. + + * *Note June 1995 Source Code CD-ROM::. + + * *Note May 1994 Source Code CD-ROM::. + + * *Note November 1993 Source Code CD-ROM::. + +Our CD-ROMs are in ISO 9660 format & can be mounted as a read-only file +system on most computers. If your driver supports it you can mount each +CD-ROM with "Rock Ridge" extensions (the MS-DOS CD-ROM is only in ISO 9660 +format) & it will look just like an ordinary Unix file system, rather than +one full of truncated & otherwise mangled names that fit vanilla ISO 9660. + +You can build most of the software without copying the sources off the CD. +You only need enough disk space for object files and intermediate build +targets. + + + +Pricing of the GNU CD-ROMs +-------------------------- + +If a business or organization is ultimately paying, the June 1995 Source CD +costs $240. It costs $60 if you, an individual, are paying out of your own +pocket. The December 1994 Compiler Tools Binaries CD-ROM costs $220 for a +business or organization, and $55 for an individual. + + + +What do the individual and company prices mean? + +The software on our disk is free; anyone can copy it and anyone can run it. +What we charge for is the physical disk and the service of distribution. + +We charge two different prices depending on who is buying. When a company or +other organization buys the June 1995 Source CD-ROM, we charge $240. When an +individual buys the same disk, we charge just $60. + +This distinction is not a matter of who is allowed to use the software. In +either case, once you have a copy, you can distribute as many copies as you +wish, and there's no restriction on who can have or run them. The price +distinction is entirely a matter of what kind of entity pays for the CD. + +You, the reader, are certainly an individual, not a company. If you are +buying a disk "in person", then you are probably doing so as an individual. +But if you expect to be reimbursed by your employer, then the disk is really +for the company; so please pay the company price and get reimbursed for it. +We won't try to check up on you--we use the honor system--so please cooperate. + +Buying CDs at the company price is very helpful for GNU; just 140 Source CDs +at that price supports an FSF programmer or tech writer for a year. + + + +Why is there an individual price? + +In the past, our distribution tapes have been ordered mainly by companies. +The CD at the price of $240 provides them with all of our software for a much +lower price than they would previously have paid for six different tapes. To +lower the price more would cut into the FSF's funds very badly, and decrease +the software development we can do. + +However, for individuals, $240 is too high a price; hardly anyone could +afford that. So we decided to make CDs available to individuals at the lower +price of $60. + + + +Is there a maximum price? + +Our stated prices are minimum prices. Feel free to pay a higher price if you +wish to support GNU development more. The sky's the limit; we will accept as +high a price as you can offer. Or simply give a donation (tax-deductible in +the U.S.) to the Free Software Foundation, a tax-exempt public charity. + + + +MS-DOS CD-ROM +------------- + +We expect to release our first CD-ROM for MS-DOS in September, 1995. Contact +either address on page 1 for more information at that time. The MS-DOS CD +will be packaged inside a book describing its contents. It will have all the +sources and executables on the MS-DOS Diskettes. For details and version +numbers, *note MS-DOS Diskettes::.. + + + +Debian GNU/Linux CD-ROM +----------------------- + +The FSF expects to ship a CD-ROM with Debian GNU/Linux on it in the late fall +1995. This CD will be packaged inside a book describing its contents. +m{No Value For "ergegrafkludge"} Debian GNU/Linux is a complete operating +system for x86 machines, available in both source code and binary form. It +is a GNU/Linux system--that is to say, a variant GNU system which uses Linux +as the kernel. (All the systems now available which use the Linux kernel are +GNU/Linux systems.) + +Debian is being developed by Ian Murdock and the Debian Association in +conjunction with the Free Software Foundation. We are distributing it as an +interim measure until the GNU kernel (the Hurd) is ready for users. + +Debian GNU/Linux is available for FTP at `ftp.cps.cmich.edu' in file +`/pub/debian'. For more information about the Debian Project and how to get +involved, see `/pub/gnu/GNUinfo/DEBIAN' on a GNU FTP host (*note How to Get +GNU Software::. for a list). + + + +December 1994 Compiler Tools Binaries CD-ROM +-------------------------------------------- + +We are now offering a CD-ROM that contains executables for GNU compiler tools +for some systems which lack a compiler. This enables the people who use +these systems to compile GNU and other free software without having to buy a +proprietary compiler. You can also use the GNU compilation system to compile +your own C/C++/Objective-C programs. + +We hope to have more systems on each update of this CD. If you can help +build binaries for new systems (especially those that don't come with a C +compiler), or have one to suggest, please contact us at the addresses on page +1. + +These packages: + + *DJGPP 1.12.m2 from GCC 2.6.0 + *GCC/G++/Objective-C 2.6.2 + *GNU C Library 1.09 + *GDB 4.13 + *Binutils 2.5.2 + *Bison 1.22 + *Emacs 19.26 (MS-DOS only) + *Flex 2.4.7 + *Make 3.72.1 + *libg++ 2.6.1 + +On these platforms: + + *`i386-msdos' + *`hppa1.1-hp-hpux9' + *`sparc-sun-solaris2' + *`sparc-sun-sunos4.1' + + + +Source Code CD-ROMs +------------------- + +We have several versions of our Source Code CD-ROMs available: + + * *Note June 1995 Source Code CD-ROM::. + + * *Note May 1994 Source Code CD-ROM::. + + * *Note November 1993 Source Code CD-ROM::. + +The older Source Code CDs will be available while supplies last at a reduced +price; see the *note Free Software Foundation Order Form::.. + +All of the Source Code CDs also contain Texinfo source for the GNU manuals +listed in *Note Documentation::. + +The VMS tapes' contents are *not* included. Many programs that are only on +MS-DOS diskettes and not on the tapes are also *not* included. The contents +of the MIT Scheme & X11 Optional tapes are *not* on the November 1993 & May +1994 Source CDs. *Note Tapes:: & *Note MS-DOS Diskettes::. + +There are no precompiled programs on these Source CDs. You will need a C +compiler (programs which need some other interpreter or compiler normally +provide the C source for a bootstrapping program). We ship C compiler +binaries for some systems on the *Note Compiler Tools Binaries CD-ROM::. + + + +June 1995 Source Code CD-ROM - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +............................ + +We now have the sixth edition of our Source CD. This CD has Edition X.X for +version 19 of the `GNU Emacs Lisp Reference Manual' & some additional +software; not all FSF distributed software is included (*note Source Code +CD-ROMs::.). It contains the following packages: + *XXXXX UPDATE THIS LIST XXXXX* + *acm 4.5 + *Autoconf 1.10 + *BASH 1.13.5 + *bc 1.02 + *Binutils 2.3 + *Bison 1.22 + *C Library 1.08 + *Calc 2.02c + *Chess 4.0.69 + *CLISP 1994.01.08 + *Common Lisp 1.0 + *cpio 2.3 + *CVS 1.3 + *dc 0.2 + *DejaGnu 1.2 + *Diffutils 2.6 + *dld 3.2.3 + *doschk 1.1 + *ecc 1.2.1 + *ed 0.1 + *elib 0.06 + *Emacs 18.59 + *Emacs 19.23 + *es 0.84 + *f2c 1994.04.14 + *Fileutils 3.9 + *find 3.8 + *finger 1.37 + *flex 2.4.6 + *Fontutils 0.6 + *GAS 1.36.utah + *GAS 2.2 + *Gawk 2.15.4 + *GCC 2.5.8 + *GDB 4.12 + *gdbm 1.7.1 + *Ghostscript 2.6.1 + *Ghostview 1.5 + *Ghostview for Windows 1.0 + *gmp 1.3.2 + *GNATS 3.2 + *GnuGo 1.1 + *gnuplot 3.5 + *gperf 2.1a + *Graphics 0.17 + *grep 2.0 + *Groff 1.09 + *gzip 1.2.4 + *hello 1.3 + *hp2xx 3.1.4 + *indent 1.9.1 + *ispell 4.0 + *libg++ 2.5.3 + *m4 1.1 + *Make 3.71 + *MandelSpawn 0.07 + *mtools 2.0.7 + *MULE 1.0 + *NetFax 3.2.1 + *Nethack 3.1.3 + *NIHCL 3.0 + *nvi 1.11 + *Octave 1.0 + *Oleo 1.5 + *p2c 1.20 + *patch 2.1 + *PCL 1993.03.18 + *perl 4.036 + *ptx 0.3 + *rc 1.4 + *RCS 5.6.0.1 + *recode 3.3 + *regex 0.12 + *screen 3.5.2 + *sed 2.05 + *shellutils 1.9.4 + *Shogi 1.1.02 + *Smalltalk 1.1.1 + *Superopt 2.3 + *tar 1.11.2 + *Termcap 1.2 + *TeX 3.1 + *Texinfo 3.1 + *Textutils 1.9.1 + *Tile Forth 2.1 + *time 1.6 + *tput 1.0 + *UUCP 1.05 + *uuencode 1.0 + *wdiff 0.04 + *X11R6 + *xboard 3.0.9 + *xshogi 1.2.02 + + + +May 1994 Source Code CD-ROM +........................... + +We still have the fourth edition of our Source CD, at a reduced price. This +CD has Edition 2.3 for version 19 of the `GNU Emacs Lisp Reference Manual' & +some additional software; not all FSF distributed software is included (*note +Source Code CD-ROMs::.). It contains these packages: + *acm 4.5 + *Autoconf 1.10 + *BASH 1.13.5 + *bc 1.02 + *Binutils 2.3 + *Bison 1.22 + *C Library 1.08 + *Calc 2.02c + *Chess 4.0.69 + *CLISP 1994.01.08 + *Common Lisp 1.0 + *cpio 2.3 + *CVS 1.3 + *dc 0.2 + *DejaGnu 1.2 + *Diffutils 2.6 + *dld 3.2.3 + *doschk 1.1 + *ecc 1.2.1 + *ed 0.1 + *elib 0.06 + *Emacs 18.59 + *Emacs 19.23 + *es 0.84 + *f2c 1994.04.14 + *Fileutils 3.9 + *find 3.8 + *finger 1.37 + *flex 2.4.6 + *Fontutils 0.6 + *GAS 1.36.utah + *GAS 2.2 + *Gawk 2.15.4 + *GCC 2.5.8 + *GDB 4.12 + *gdbm 1.7.1 + *Ghostscript 2.6.1 + *Ghostview 1.5 + *Ghostview for Windows 1.0 + *gmp 1.3.2 + *GNATS 3.2 + *GnuGo 1.1 + *gnuplot 3.5 + *gperf 2.1a + *Graphics 0.17 + *grep 2.0 + *Groff 1.09 + *gzip 1.2.4 + *hello 1.3 + *hp2xx 3.1.4 + *indent 1.9.1 + *ispell 4.0 + *libg++ 2.5.3 + *m4 1.1 + *Make 3.71 + *MandelSpawn 0.07 + *mtools 2.0.7 + *MULE 1.0 + *NetFax 3.2.1 + *Nethack 3.1.3 + *NIHCL 3.0 + *nvi 1.11 + *Octave 1.0 + *Oleo 1.5 + *p2c 1.20 + *patch 2.1 + *PCL 1993.03.18 + *perl 4.036 + *ptx 0.3 + *rc 1.4 + *RCS 5.6.0.1 + *recode 3.3 + *regex 0.12 + *screen 3.5.2 + *sed 2.05 + *shellutils 1.9.4 + *Shogi 1.1.02 + *Smalltalk 1.1.1 + *Superopt 2.3 + *tar 1.11.2 + *Termcap 1.2 + *TeX 3.1 + *Texinfo 3.1 + *Textutils 1.9.1 + *Tile Forth 2.1 + *time 1.6 + *tput 1.0 + *UUCP 1.05 + *uuencode 1.0 + *wdiff 0.04 + *X11R6 + *xboard 3.0.9 + *xshogi 1.2.02 + + + +November 1993 Source Code CD-ROM +................................ + +We still have the third edition of our Source CD, at a reduced price. It +contains X11R5, as we feel that people should have a choice between X11R5 and +X11R6 until the latter is stable. This CD has Edition 2.2 for version 19 of +the `GNU Emacs Lisp Reference Manual' & some additional software; not all FSF +distributed software is included (*note Source Code CD-ROMs::.). It contains +the following packages: + *acm 3.1 + *Autoconf 1.7 + *BASH 1.13.4 + *bc 1.02 + *Binutils 1.9 2.3 + *Bison 1.22 + *C Library 1.06.7 + *Calc 2.02b + *Chess 4.0p62 + *CLISP 93.11.08 + *cpio 2.3 + *CVS 1.3 + *dc 0.2 + *DejaGnu 1.0.1 + *Diffutils 2.6 + *dld 3.2.3 + *doschk 1.1 + *ecc 1.2.1 + *elib 0.06 + *Emacs 18.59 + *Emacs 19.21 + *es 0.84 + *f2c 1993.04.28 + *Fileutils 3.9 + *find 3.8 + *finger 1.37 + *flex 2.3.8 + *Fontutils 0.6 + *GAS 1.36.utah + *GAS 1.38.1 + *GAS 2.2 + *Gawk 2.15.3 + *GCC 2.5.4 + *GDB 4.11 + *gdbm 1.7.1 + *Ghostscript 2.6.1 + *Ghostview 1.5 + *Ghostview for Windows 1.0 + *gmp 1.3.2 + *GNATS 3.01 + *GnuGo 1.1 + *gnuplot 3.5 + *gperf 2.1a + *Graphics 0.17 + *grep 2.0 + *Groff 1.08 + *gzip 1.2.4 + *hello 1.3 + *hp2xx 3.1.3a + *indent 1.8 + *Ispell 4.0 + *less 177 + *libg++ 2.5.1 + *m4 1.1 + *Make 3.69.1 + *MandelSpawn 0.06 + *mtools 2.0.7 + *MULE 1.0 + *NetFax 3.2.1 + *Nethack 3.1.3 + *NIHCL 3.0 + *Oleo 1.5 + *p2c 1.20 + *patch 2.1 + *PCL 93.03.18 + *perl 4.036 + *ptx 0.3 + *rc 1.4 + *RCS 5.6.0.1 + *recode 3.2.4 + *regex 0.12 + *screen 3.5.2 + *sed 1.18 2.03 + *Shellutils 1.9.1 + *Shogi 1.1p02 + *Smalltalk 1.1.1 + *Superopt 2.3 + *tar 1.11.2 + *Termcap 1.2 + *TeX 3.1 + *Texinfo 3.1 + *Tile Forth 2.1 + *time 1.6 + *time 1.6 + *tput 1.0 + *UUCP 1.04 + *uuencode 1.0 + *wdiff 0.04 + *X11R5 + + + + +MS-DOS Diskettes +**************** + +The FSF distributes some of the GNU software ported to MS-DOS, on 3.5inch +1.44MB diskettes. These disks have both sources and executables. + + + +DJGPP Diskettes - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +--------------- + +We offer DJGPP on 30 diskettes. For further details, see *Note GNU +Software::. The DJGPP diskettes contain the following: + + * bc 1.03 + * Binutils 2.4 + * Bison 1.22 + * cpio 2.3 + * Diffutils 2.6 + * doschk 1.1 + * Fileutils 3.9 + * Findutils 3.8 + * GAS 2.4 + * Gawk 2.15.5 + * GCC 2.6.0 + * GDB 4.12 + * Ghostscript 2.6.1 + * Ghostview for Windows 1.0 + * Groff 1.09 + * gzip 1.24 + * hello 1.3 + * indent 1.9 + * ispell 4.0 + * m4 1.2 + * Make 3.71 + * patch 2.1 + * sed 1.18 + * shellutils 1.9 + * Texinfo 3.1 + * texutils 1.9 + * wdiff 0.04 + + + +Emacs Diskettes - (VERSION NUMBERS NOT COMPLETELY UP TO DATE) +--------------- + +Two versions of GNU Emacs are included on the Emacs diskettes we distribute: +GNU Emacs version 19.29 handles 8-bit character sets; the other, MULE version +2.1, handles 16-bit character sets including Kanji. + + + +Selected Utilities Diskettes - (NOT COMPLETELY UP TO DATE) +---------------------------- + +The GNUish MS-DOS Project ported GNU software to PC compatibles. Though the +GNUish Project is no longer active, users still ask for these ports that were +done several years ago. You can anonymous FTP files +`/pub/gnu/MicrosPorts/MSDOS*' from `prep.ai.mit.edu' to find out how to +access these ports over the Internet. We offer these programs on five +diskettes. In general, this software will run on 8086 and 80286-based 16-bit +machines; an 80386 is not required. Some of these utilities are necessarily +missing features. Included are: `cpio', `diff', `find', `flex', `gdbm', +`grep', `indent', `less', `m4', `make', `ptx', RCS, `sed', `shar', `sort', & +Texinfo. + + + +Windows Diskette +---------------- + +We offer GNU Chess and `gnuplot' for Microsoft Windows on a single diskette. + + + +Tape & CD-ROM Subscription Service +********************************** + +If you do not have net access, our subscription service enables you to stay +current with the latest GNU developments. For a one-time cost equivalent to +three tapes or CD-ROMs (plus shipping in some cases), we will ship you four +new versions of the tape of your choice or the Source Code CD-ROM. The tapes +are sent each quarter; the CD-ROMs are sent as they are issued (which is +between two and four times a year.) + +Regularly, we will send you a new version of an Lisps/Emacs, Languages, +Utilities, or X Window System (X11R6) Required tape or the Source CD-ROM. +The MIT Scheme and X Window System Optional tapes are not changed often +enough to warrant quarterly updates. We do not yet know if we will be +offering subscriptions to the Compiler Tools Binaries or our new CD-ROMs. + +Since Emacs 19 is on the Lisps/Emacs Tape and the Source CD-ROM, a +subscription to either is an easy way to keep current with Emacs 19 as it +evolves. + +A subscription is an easy way to keep up with the regular bug fixes to the X +Window System. We update the X11R6 Required tape as fixes and patches are +issued throughout the year. Each new edition of the *Note Source Code +CD-ROMs::, also has updated sources for the X Window System. + +Please note: In two cases, you must pay 4 times the normal shipping required +for a single order when you pay for each subscription. If you're in Alaska, +Hawaii, or Puerto Rico you must add $20.00 for shipping for each +subscription. If you're outside of U.S., Canada, and Puerto Rico, you have +to add $80.00 for each subscription. See "Unix and VMS Software" & "Shipping +Instructions" on the *note Free Software Foundation Order Form::.. + + + +The Deluxe Distribution +*********************** + +The Free Software Foundation has been asked repeatedly to create a package +that provides executables for all of our software. Normally we offer only +sources. In addition to providing binaries with the source code, the Deluxe +Distribution includes a complete set of our printed manuals and reference +cards. + +The FSF Deluxe Distribution contains the binaries and sources to hundreds of +different programs including GNU Emacs, the GNU C Compiler, the GNU Debugger, +the complete X Window System, and all the GNU utilities. + +We will make a Deluxe Distribution for any machine, with any operating +system. We will send someone to your office to do the compilation, if we +can't find a suitable machine close to us! However, we can only compile the +programs that already support your chosen machine and system - porting is a +separate matter (if you wish to commission a port, see the GNU Service +Directory, details in *Note Free Software Support::). Compiling all these +programs take time; a Deluxe Distribution for an unusual machine will take +longer to produce then one for a common machine. Please contact the FSF +office if you have any questions. + +We supply the software in one of these tape formats in Unix `tar' format: +1600 or 6250bpi 1/2in reel, Sun DC300XLP 1/4in cartridge - QIC24, +Hewlett-Packard 16-track DC600HC 1/4in cartridge, IBM RS/6000 1/4in cartridge +- QIC 150, Exabyte 8mm cartridge, or DAT 4mm cartridge. If your computer +cannot read any of these, please contact us to see if we can handle your +format. + +The manuals included are one each of the `Bison', `Calc', `Gawk', `GNU C +Compiler', `GNU C Library', `GDB', `Flex', `GNU Emacs Lisp Reference', +`Programming in Emacs Lisp: An Introduction', `Make', `Texinfo', & `Termcap' +manuals; six copies of the `GNU Emacs' manual; and a packet of ten reference +cards each for GNU Emacs, Bison, Calc, Flex, & GDB. Every Deluxe +Distribution also includes a copy of the latest editions of our CD-ROMs +(including the MS-DOS CD & the Debian GNU/Linux CD when they are available) +that contain sources of our software & compiler tool binaries for some +systems. The MS-DOS CD is in ISO 9660 format. The other CDs are in ISO 9660 +format with Rock Ridge extensions. + +The price of the Deluxe Distribution is $5000 (shipping included). These +sales provide enormous financial assistance to help the FSF develop more free +software. To order, please fill out the "Deluxe Distribution" section on the +*note Free Software Foundation Order Form::. and send it to: + + Free Software Foundation, Inc. + 59 Temple Place -- Suite 330 + Boston, MA 02111--1307 + USA + + Telephone: +1-617-542-5942 + Fax (including Japan): +1-617-542-2652 + Free Dial Fax (in Japan): + 0031-13-2473 (KDD) + 0066-3382-0158 (IDC) + Electronic mail: gnu@prep.ai.mit.edu + + + +FSF T-shirt +*********** + +Our latest T-shirt has artwork by Berkeley, CA artist Etienne Suvasa. The +front has the ever-popular picture of GNArnold from the `Flex Manual', while +the back has the Preamble to the GNU General Public License. + +They are available in two colors, Natural & Black. Natural is an off-white, +unbleached, undyed, environment-friendly cotton, printed with black ink, & is +great for tye-dyeing or displaying as is. Black is printed with white ink & +is perfect for late night hacking. All shirts are thick 100% cotton, & are +available in sizes M, L, XL & XXL. This shirt makes a great gift for your +favorite hacker! + +The previous version of the T-shirt will be available while supplies last, +but please contact the FSF to see if we have what you would like before +ordering. + + + +Free Software Foundation Order Form +*********************************** + +All items are distributed with permission to copy and to redistribute. +Texinfo source for each manual and source for each reference card is on +the appropriate tape, diskette, or CD-ROM; the prices for these magnetic +media do not include printed documentation. All items are provided on +an ``as is'' basis, with no warranty of any kind. Please allow six +weeks for delivery (though it won't usually take that long). + + + PRICE AND CONTENTS MAY CHANGE WITHOUT NOTICE AFTER January 31, 1996. + + + +Unix and VMS Software +--------------------- + +These tapes in the formats indicated (*note Tapes::., for contents): + + Please circle the dollar amount for each tape you order. + + Reel to Sun (1) HP IBM (2) Exabyte DAT + reel RS/6000 + Unix tar Unix tar Unix tar Unix tar Unix tar Unix tar + 9-track QIC-24 16-track QIC-150 + 1600 bpi DC300XLP DC600HC DC600A + 1/2" reel 1/4" c.t. 1/4" c.t. 1/4" c.t. 8mm c.t. 4mm c.t. + + (c.t. = cartridge tape) + +Lisps/Emacs $200 $210 $230 $215 (3) $205 $225 +Languages $200 $210 $230 $215 $205 $225 +Utilities $200 $210 $230 $215 $205 $225 +4.4BSD-Lite $200 $210 $230 $215 $205 $225 +Scheme $200 $210 $230 $215 $205 $225 +X11R5-Required $200 $210 $230 $215 $205 $225 +X11R5-Optional $200 $210 $230 $215 $205 $225 +X11R6-Required $200 $210 $230 $215 $205 $225 +X11R6-Optional $200 $210 $230 $215 $205 $225 + + (1) Sun tapes can be read on some other Unix systems. + (2) IBM RS/6000 tapes can be read on some other Unix systems. + (3) The IBM Emacs tape also has binaries for GNU Emacs. + + +Subscriptions, 4 updates for one year (*note Tape & CD-ROM Subscription Service::.): + +Emacs $600 $630 $690 $645 $615 $675 +Languages $600 $630 $690 $645 $615 $675 +Utilities $600 $630 $690 $645 $615 $675 +X11R6-Required $600 $630 $690 $645 $615 $675 + + Subtotal $ ______ Please put total of the above circled amounts here. + + +These 1600 bpi reel-to-reel 9 track 1/2" tapes, in VMS BACKUP format (aka +interchange format) (*note VMS Emacs and VMS Compiler Tapes::.): + +____ @ $195 = $ ______ VMS Emacs, GNU Emacs source & executables only. + +____ @ $195 = $ ______ VMS Compiler, GCC, GAS, and Bison source and + executables only. + + +FSF Deluxe Distribution (*note Deluxe Distribution::.): +...................................................... + + +____ @ $5000 = $ ______ The Deluxe Distribution, with manuals, etc. + +Machine: _____________________________________________________________________ + +Operating system: ____________________________________________________________ + +Media type: __________________________________________________________________ + + + +CD-ROMs, in ISO 9660 format (*note CD-ROMs::.): +.............................................. + + +GNU Source Code CD-ROM, Version 6 with X11R6 (*note June 1995 Source Code CD-ROM::.): + +____ @ $240 = $ ______ for corporations and other organizations. + +____ @ $ 60 = $ ______ for individuals. + + + +GNU Compiler Tools Binaries CD-ROM, Version 2, December 1994 Edition +(*note Compiler Tools Binaries CD-ROM::.): + +____ @ $220 = $ ______ for corporations and other organizations. + +____ @ $55 = $ ______ for individuals. + + + +Debian GNU/Linux Book with CD-ROM - expected late fall 1995 (*note Debian GNU/Linux CD-ROM::.): + +____ @ $200 = $ ______ for corporations and other organizations. + +____ @ $50 = $ ______ for individuals. + + +Subscriptions, next 4 updates, of the Source Code CD-ROM, in ISO 9660 format +(*note Tape & CD-ROM Subscription Service::.): + +____ @ $720 = $ ______ for corporations and other organizations. + +____ @ $180 = $ ______ for individuals. + + + +MS-DOS Software +--------------- + +MS-DOS Book with CD-ROM - expected September 1995 (*note MS-DOS CD-ROM::.): + +____ @ $180 = $ ______ for corporations and other organizations. + +____ @ $45 = $ ______ for individuals. + + + +The following sources and executables for MS-DOS, on 3.5" 1.44MB diskettes +(*note MS-DOS Diskettes::.): + +____ @ $ 90 = $ ______ Emacs diskettes, GNU Emacs, for 80386 and up. + +____ @ $ 80 = $ ______ DJGPP diskettes, GCC version 2, for 80386 and up + (also on the *note Compiler Tools Binaries CD-ROM::. and *note MS-DOS CD-ROM::..) +____ @ $ 85 = $ ______ Selected Utilities diskettes, 8086 and up. + +____ @ $ 40 = $ ______ Windows diskette, GNU Chess and gnuplot for + Microsoft Windows. + + +Manuals +------- + +These manuals (*note Documentation::.). Please call for bulk purchase +discounts. + +____ @ $300 = $ ______ One copy each of the following 13 manuals. + +____ @ $ 25 = $ ______ GNU Emacs version manual, with a reference card. + +____ @ $ 50 = $ ______ GNU Emacs Lisp Reference manual, in two volumes. + +____ @ $ 50 = $ ______ Using and Porting GNU CC. + +____ @ $ 50 = $ ______ GNU C Library Reference Manual. + +____ @ $ 50 = $ ______ GNU Emacs Calc manual, with a reference card. + +____ @ $ 20 = $ ______ Programming in Emacs Lisp, An Introduction + +____ @ $ 20 = $ ______ Debugging with GDB, with a reference card. + +____ @ $ 20 = $ ______ Gawk manual. + +____ @ $ 20 = $ ______ Make manual. + +____ @ $ 20 = $ ______ Bison manual, with a reference card. + +____ @ $ 20 = $ ______ Flex manual, with a reference card. + +____ @ $ 20 = $ ______ Texinfo manual. + +____ @ $ 15 = $ ______ Termcap manual. + + + +Reference Cards +--------------- + +The following reference cards, in packets of ten. For single copies please +call. + +____ @ $ 10 = $ ______ GNU Emacs version 19 reference cards. + +____ @ $ 10 = $ ______ GNU Emacs Calc reference cards. + +____ @ $ 10 = $ ______ GDB reference cards. + +____ @ $ 10 = $ ______ Bison reference cards. + +____ @ $ 10 = $ ______ Flex reference cards. + + + +T-shirts +-------- + +GNU/FSF T-shirts, thick 100% cotton (*note FSF T-shirt::.): + +____ @ $ 15 = $ ______ Size M ____ natural ____ black. + +____ @ $ 15 = $ ______ Size L ____ natural ____ black. + +____ @ $ 15 = $ ______ Size XL ____ natural ____ black. + +____ @ $ 15 = $ ______ Size XXL ____ natural ____ black. + + + +Older Items +----------- + +Older items are only available while supplies last. + +____ @ $ 5 = $ ______ GNU Emacs version 18 reference cards, in packets + of ten. + +Please fill in the number of each older CD-ROM you order: + + for for + corporations individuals: + and other + organizations: + +GNU Compiler Tools Binaries CD-ROM + December 1993 Edition (Version 1) ____________ ____________ + + +GNU Source Code CD-ROM + May 1994 edition with X11R6 ____________ ____________ + +GNU Source Code CD-ROM + November 1993 edition with X11R5 ____________ ____________ + +GNU Source Code CD-ROM + May 1993 edition with X11R5 ____________ ____________ + +GNU Source Code CD-ROM + October 1992 edition with X11R5 ____________ ____________ + + +Please put the total count and cost of the above older CD-ROMs here: + +____ @ $ 80 = $ ______ for corporations and other organizations. + +____ @ $ 20 = $ ______ for individuals. + + ====== + + Subtotal $ ______ + + + +Tax and Shipping Costs +---------------------- + + + $ ______ In Massachusetts: add 5% sales tax, or give tax + exempt number. + + $ ______ In Alaska, Hawaii, or Puerto Rico for shipping: + for GNU Emacs Lisp Reference and GNU Emacs Calc + manuals, add $5 *each*. For *each* tape or + CD-ROM subscription, add $20. For all other + items, add $5 base charge, then $1 per item except + reference cards; i.e., + shipping for all other items = $5 + ($1 * i). + + $ ______ Outside of U.S., Canada, and Puerto Rico for + shipping: Add $20 base charge; then add $80 more + for *each* tape or CD-ROM subscription; and then + add $10 more for *each* manual in the order; + i.e., shipping for all other items + = $20 + ($80 * s) + ($10 * m). + + $ ______ Optional (tax-deductible in the U.S.) donation. + ------ We suggest 5% if paying by credit card. + + TOTAL $ ______ We pay for shipping via UPS ground transportation in + the contiguous 48 states and Canada. For very + large orders, ask about actual shipping costs for + that order. + + + +Shipping Information +-------------------- + +Name: ________________________________________________________________________ + +Mail Stop/Dept. Name: ________________________________________________________ + +Organization: ________________________________________________________________ + +Street Address: ______________________________________________________________ + +City/State/Province: _________________________________________________________ + +Zip Code/Postal Code/Country: ________________________________________________ + +Telephone number in case of a problem with your order. +For international orders, please include a FAX number. _______________________ + + +------------------------------------------------------------------------------ +| | +| Orders filled only upon receipt of check, money order or credit card | +| order in U.S. dollars. Unpaid orders will be returned to the sender. | +| We do not have the staff to handle the billing of unpaid orders. Please | +| help keep our lives simple by including your payment with your order. | +| | +------------------------------------------------------------------------------ + + +For orders from outside the U.S.: +--------------------------------- + +You are responsible for paying all duties, tariffs, and taxes. If you +refuse to pay the charges, the shipper will return or abandon the order. + + + --------------------------------------------------------------------------- + | | + | Please make checks payable to the ``Free Software Foundation''. | + | | + --------------------------------------------------------------------------- + + +For Credit Card Orders: +----------------------- + +The Free Software Foundation takes these credit cards: Carte Blanche, +Diner's Club, JCB, Mastercard, Visa, or American Express. Please note that +we are charged about 5% of an order's total amount in credit card +processing fees. Please consider paying by check instead, or adding on a +5% donation to make up the difference. To place a credit card order, +please give us this information: + + +Card type: ___________________________________________________________________ + +Account Number: ______________________________________________________________ + +Expiration Date: _____________________________________________________________ + +Cardholder's Signature: ______________________________________________________ + + + +------------------------------------------------------------------------------ +| | +| If you wish to pay by wire transfer, or you are a reseller, please | +| call or write us for details. | +| | +------------------------------------------------------------------------------ + + + Please mail orders to: Free Software Foundation + 59 Temple Place -- Suite 330 + Boston, MA 02111 + +1-617-542-5942 + FAX (including Japan): +1-617-542-2652 + Free Dial FAX numbers in Japan: +PRICES AND CONTENTS MAY CHANGE 0031-13-2473 (KDD) +WITHOUT NOTICE AFTER January 31, 1996. 0066-3382-0158 (IDC) + +Version: June 1995 ASCII Bull to June 1995 Src CD/GNU 19.29/GCC 2.7.0 + +--------------------------------------------------------------------- +local variables: +mode: text +fill-column: 78 +end: diff --git a/contrib/gcc/PROBLEMS b/contrib/gcc/PROBLEMS new file mode 100644 index 00000000000..bc532e641a8 --- /dev/null +++ b/contrib/gcc/PROBLEMS @@ -0,0 +1,117 @@ +3. When find_reloads is used to count number of spills needed +it does not take into account the fact that a reload may +turn out to be a dummy. + +I'm not sure this really happens any more. Doesn't it find +all the dummies on both passes? + +10. movl a3@,a0 + movl a3@(16),a1 + clrb a0@(a1:l) +is generated and may be worse than + movl a3@,a0 + addl a3@(16),a0 + clrb a0@ +If ordering of operands is improved, many more +such cases will be generated from typical array accesses. + +38. Hack expand_mult so that if there is no same-modes multiply +it will use a widening multiply and then truncate rather than +calling the library. + +39. Hack expanding of division to notice cases for +long -> short division. + +40. Represent divide insns as (DIV:SI ...) followed by +a separate lowpart extract. Represent remainder insns as DIV:SI +followed by a separate highpart extract. Then cse can work on +the DIV:SI part. Problem is, this may not be desirable on machines +where computing the quotient alone does not necessarily give +a remainder--such as the 68020 for long operands. + +52. Reloading can look at how reload_contents got set up. +If it was copied from a register, just reload from that register. +Otherwise, perhaps can change the previous insn to move the +data via the reload reg, thus avoiding one memory ref. + +63. Potential problem in cc_status.value2, if it ever activates itself +after a two-address subtraction (which currently cannot happen). +It is supposed to compare the current value of the destination +but eliminating it would use the results of the subtraction, equivalent +to comparing the previous value of the destination. + +65. Should loops that neither start nor end with a break +be rearranged to end with the last break? + +69. Define the floating point converting arithmetic instructions +for the 68881. + +74. Combine loop opt with cse opt in one pass. Do cse on each loop, +then loop opt on that loop, and go from innermost loops outward. +Make loop invariants available for cse at end of loop. + +85. pea can force a value to be reloaded into an areg +which can make it worse than separate adding and pushing. +This can only happen for adding something within addql range +and it only loses if the qty becomes dead at that point +so it can be added to with no copying. + +93. If a pseudo doesn't get a hard reg everywhere, +can it get one during a loop? + +96. Can do SImode bitfield insns without reloading, but must +alter the operands in special ways. + +99. final could check loop-entry branches to see if they +screw up deletion of a test instruction. If they do, +can put another test instruction before the branch and +make it conditional and redirect it. + +106. Aliasing may be impossible if data types of refs differ +and data type of containing objects also differ. +(But check this wrt unions.) + +108. Can speed up flow analysis by making a table saying which +register is set and which registers are used by each instruction that +only sets one register and only uses two. This way avoid the tree +walk for such instructions (most instructions). + +109. It is desirable to avoid converting INDEX to SImode if a +narrower mode suffices, as HImode does on the 68000. +How can this be done? + +110. Possible special combination pattern: +If the two operands to a comparison die there and both come from insns +that are identical except for replacing one operand with the other, +throw away those insns. Ok if insns being discarded are known 1 to 1. +An andl #1 after a seq is 1 to 1, but how should compiler know that? + +112. Can convert float to unsigned int by subtracting a constant, +converting to signed int, and changing the sign bit. + +117. Any number of slow zero-extensions in one loop, that have +their clr insns moved out of the loop, can share one register +if their original life spans are disjoint. +But it may be hard to be sure of this since +the life span data that regscan produces may be hard to interpret +validly or may be incorrect after cse. + +118. In cse, when a bfext insn refers to a register, if the field +corresponds to a halfword or a byte and the register is equivalent +to a memory location, it would be possible to detect this and +replace it with a simple memory reference. + +121. Insns that store two values cannot be moved out of loops. +The code in scan_loop doesn't even try to deal with them. + +122. When insn-output.c turns a bit-test into a sign-test, +it should see whether the cc is already set up with that sign. + +123. When a conditional expression is used as a function arg, it would +be faster (and in some cases shorter) to push each alternative rather +than compute in a register and push that. This would require +being able to specify "push this" as a target for expand_expr. + +124. On the 386, bad code results from foo (bar ()) when bar +returns a double, because the pseudo used fails to get preferenced +into an fp reg because of the distinction between regs 8 and 9. diff --git a/contrib/gcc/PROJECTS b/contrib/gcc/PROJECTS new file mode 100644 index 00000000000..ee9be0241ed --- /dev/null +++ b/contrib/gcc/PROJECTS @@ -0,0 +1,448 @@ +0. Improved efficiency. + +* Parse and output array initializers an element at a time, freeing +storage after each, instead of parsing the whole initializer first and +then outputting. This would reduce memory usage for large +initializers. + +* See if the techniques describe in Oct 1991 SIGPLAN Notices +(Frazer and Hanson) are applicable to GCC. + +1. Better optimization. + +* Constants in unused inline functions + +It would be nice to delay output of string constants so that string +constants mentioned in unused inline functions are never generated. +Perhaps this would also take care of string constants in dead code. + +The difficulty is in finding a clean way for the RTL which refers +to the constant (currently, only by an assembler symbol name) +to point to the constant and cause it to be output. + +* More cse + +The techniques for doing full global cse are described in the red +dragon book, or (a different version) in Frederick Chow's thesis from +Stanford. It is likely to be slow and use a lot of memory, but it +might be worth offering as an additional option. + +It is probably possible to extend cse to a few very frequent cases +without so much expense. + +For example, it is not very hard to handle cse through if-then +statements with no else clauses. Here's how to do it. On reaching a +label, notice that the label's use-count is 1 and that the last +preceding jump jumps conditionally to this label. Now you know it +is a simple if-then statement. Remove from the hash table +all the expressions that were entered since that jump insn +and you can continue with cse. + +It is probably not hard to handle cse from the end of a loop +around to the beginning, and a few loops would be greatly sped +up by this. + +* Optimize a sequence of if statements whose conditions are exclusive. + +It is possible to optimize + + if (x == 1) ...; + if (x == 2) ...; + if (x == 3) ...; + +into + + if (x == 1) ...; + else if (x == 2) ...; + else if (x == 3) ...; + +provided that x is not altered by the contents of the if statements. + +It's not certain whether this is worth doing. Perhaps programmers +nearly always write the else's themselves, leaving few opportunities +to improve anything. + +* Un-cse. + +Perhaps we should have an un-cse step right after cse, which tries to +replace a reg with its value if the value can be substituted for the +reg everywhere, if that looks like an improvement. Which is if the +reg is used only a few times. Use rtx_cost to determine if the +change is really an improvement. + +* Clean up how cse works. + +The scheme is that each value has just one hash entry. The +first_same_value and next_same_value chains are no longer needed. + +For arithmetic, each hash table elt has the following slots: + +* Operation. This is an rtx code. +* Mode. +* Operands 0, 1 and 2. These point to other hash table elements. + +So, if we want to enter (PLUS:SI (REG:SI 30) (CONST_INT 104)), we +first enter (CONST_INT 104) and find the entry that (REG:SI 30) now +points to. Then we put these elts into operands 0 and 1 of a new elt. +We put PLUS and SI into the new elt. + +Registers and mem refs would never be entered into the table as such. +However, the values they contain would be entered. There would be a +table indexed by regno which points at the hash entry for the value in +that reg. + +The hash entry index now plays the role of a qty number. +We still need qty_first_reg, reg_next_eqv, etc. to record which regs +share a particular qty. + +When a reg is used whose contents are unknown, we need to create a +hash table entry whose contents say "unknown", as a place holder for +whatever the reg contains. If that reg is added to something, then +the hash entry for the sum will refer to the "unknown" entry. Use +UNKNOWN for the rtx code in this entry. This replaces make_new_qty. + +For a constant, a unique hash entry would be made based on the +value of the constant. + +What about MEM? Each time a memory address is referenced, we need a +qty (a hash table elt) to represent what is in it. (Just as for a +register.) If this isn't known, create one, just as for a reg whose +contents are unknown. + +We need a way to find all mem refs that still contain a certain value. +Do this with a chain of hash elts (for memory addresses) that point to +locations that hold the value. The hash elt for the value itself should +point to the start of the chain. It would be good for the hash elt +for an address to point to the hash elt for the contents of that address +(but this ptr can be null if the contents have never been entered). + +With this data structure, nothing need ever be invalidated except +the lists of which regs or mems hold a particular value. It is easy +to see if there is a reg or mem that is equiv to a particular value. +If the value is constant, it is always explicitly constant. + +* Support more general tail-recursion among different functions. + +This might be possible under certain circumstances, such as when +the argument lists of the functions have the same lengths. +Perhaps it could be done with a special declaration. + +You would need to verify in the calling function that it does not +use the addresses of any local variables and does not use setjmp. + +* Put short statics vars at low addresses and use short addressing mode? + +Useful on the 68000/68020 and perhaps on the 32000 series, +provided one has a linker that works with the feature. +This is said to make a 15% speedup on the 68000. + +* Keep global variables in registers. + +Here is a scheme for doing this. A global variable, or a local variable +whose address is taken, can be kept in a register for an entire function +if it does not use non-constant memory addresses and (for globals only) +does not call other functions. If the entire function does not meet +this criterion, a loop may. + +The VAR_DECL for such a variable would have to have two RTL expressions: +the true home in memory, and the pseudo-register used temporarily. +It is necessary to emit insns to copy the memory location into the +pseudo-register at the beginning of the function or loop, and perhaps +back out at the end. These insns should have REG_EQUIV notes so that, +if the pseudo-register does not get a hard register, it is spilled into +the memory location which exists in any case. + +The easiest way to set up these insns is to modify the routine +put_var_into_stack so that it does not apply to the entire function +(sparing any loops which contain nothing dangerous) and to call it at +the end of the function regardless of where in the function the +address of a local variable is taken. It would be called +unconditionally at the end of the function for all relevant global +variables. + +For debugger output, the thing to do is to invent a new binding level +around the appropriate loop and define the variable name as a register +variable with that scope. + +* Live-range splitting. + +Currently a variable is allocated a hard register either for the full +extent of its use or not at all. Sometimes it would be good to +allocate a variable a hard register for just part of a function; for +example, through a particular loop where the variable is mostly used, +or outside of a particular loop where the variable is not used. (The +latter is nice because it might let the variable be in a register most +of the time even though the loop needs all the registers.) + +It might not be very hard to do this in global.c when a variable +fails to get a hard register for its entire life span. + +The first step is to find a loop in which the variable is live, but +which is not the whole life span or nearly so. It's probably best to +use a loop in which the variable is heavily used. + +Then create a new pseudo-register to represent the variable in that loop. +Substitute this for the old pseudo-register there, and insert move insns +to copy between the two at the loop entry and all exits. (When several +such moves are inserted at the same place, some new feature should be +added to say that none of those registers conflict merely because of +overlap between the new moves. And the reload pass should reorder them +so that a store precedes a load, for any given hard register.) + +After doing this for all the reasonable candidates, run global-alloc +over again. With luck, one of the two pseudo-registers will be fit +somewhere. It may even have a much higher priority due to its reduced +life span. + +There will be no room in general for the new pseudo-registers in +basic_block_live_at_start, so there will need to be a second such +matrix exclusively for the new ones. Various other vectors indexed by +register number will have to be made bigger, or there will have to be +secondary extender vectors just for global-alloc. + +A simple new feature could arrange that both pseudo-registers get the +same stack slot if they both fail to get hard registers. + +Other compilers split live ranges when they are not connected, or +try to split off pieces `at the edge'. I think splitting around loops +will provide more speedup. + +Creating a fake binding block and a new like-named variable with +shorter life span and different address might succeed in describing +this technique for the debugger. + +* Detect dead stores into memory? + +A store into memory is dead if it is followed by another store into +the same location; and, in between, there is no reference to anything +that might be that location (including no reference to a variable +address). + +* Loop optimization. + +Strength reduction and iteration variable elimination could be +smarter. They should know how to decide which iteration variables are +not worth making explicit because they can be computed as part of an +address calculation. Based on this information, they should decide +when it is desirable to eliminate one iteration variable and create +another in its place. + +It should be possible to compute what the value of an iteration +variable will be at the end of the loop, and eliminate the variable +within the loop by computing that value at the loop end. + +When a loop has a simple increment that adds 1, +instead of jumping in after the increment, +decrement the loop count and jump to the increment. +This allows aob insns to be used. + +* Using constraints on values. + +Many operations could be simplified based on knowledge of the +minimum and maximum possible values of a register at any particular time. +These limits could come from the data types in the tree, via rtl generation, +or they can be deduced from operations that are performed. For example, +the result of an `and' operation one of whose operands is 7 must be in +the range 0 to 7. Compare instructions also tell something about the +possible values of the operand, in the code beyond the test. + +Value constraints can be used to determine the results of a further +comparison. They can also indicate that certain `and' operations are +redundant. Constraints might permit a decrement and branch +instruction that checks zeroness to be used when the user has +specified to exit if negative. + +* Smarter reload pass. + +The reload pass as currently written can reload values only into registers +that are reserved for reloading. This means that in order to use a +register for reloading it must spill everything out of that register. + +It would be straightforward, though complicated, for reload1.c to keep +track, during its scan, of which hard registers were available at each +point in the function, and use for reloading even registers that were +free only at the point they were needed. This would avoid much spilling +and make better code. + +* Change the type of a variable. + +Sometimes a variable is declared as `int', it is assigned only once +from a value of type `char', and then it is used only by comparison +against constants. On many machines, better code would result if +the variable had type `char'. If the compiler could detect this +case, it could change the declaration of the variable and change +all the places that use it. + +* Better handling for very sparse switches. + +There may be cases where it would be better to compile a switch +statement to use a fixed hash table rather than the current +combination of jump tables and binary search. + +* Order of subexpressions. + +It might be possible to make better code by paying attention +to the order in which to generate code for subexpressions of an expression. + +* More code motion. + +Consider hoisting common code up past conditional branches or +tablejumps. + +* Trace scheduling. + +This technique is said to be able to figure out which way a jump +will usually go, and rearrange the code to make that path the +faster one. + +* Distributive law. + +The C expression *(X + 4 * (Y + C)) compiles better on certain +machines if rewritten as *(X + 4*C + 4*Y) because of known addressing +modes. It may be tricky to determine when, and for which machines, to +use each alternative. + +Some work has been done on this, in combine.c. + +* Can optimize by changing if (x) y; else z; into z; if (x) y; +if z and x do not interfere and z has no effects not undone by y. +This is desirable if z is faster than jumping. + +* For a two-insn loop on the 68020, such as + foo: movb a2@+,a3@+ + jne foo +it is better to insert dbeq d0,foo before the jne. +d0 can be a junk register. The challenge is to fit this into +a portable framework: when can you detect this situation and +still be able to allocate a junk register? + +2. Simpler porting. + +Right now, describing the target machine's instructions is done +cleanly, but describing its addressing mode is done with several +ad-hoc macro definitions. Porting would be much easier if there were +an RTL description for addressing modes like that for instructions. +Tools analogous to genflags and genrecog would generate macros from +this description. + +There would be one pattern in the address-description file for each +kind of addressing, and this pattern would have: + + * the RTL expression for the address + * C code to verify its validity (since that may depend on + the exact data). + * C code to print the address in assembler language. + * C code to convert the address into a valid one, if it is not valid. + (This would replace LEGITIMIZE_ADDRESS). + * Register constraints for all indeterminates that appear + in the RTL expression. + +3. Other languages. + +Front ends for Pascal, Fortran, Algol, Cobol, Modula-2 and Ada are +desirable. + +Pascal, Modula-2 and Ada require the implementation of functions +within functions. Some of the mechanisms for this already exist. + +4. More extensions. + +* Generated unique labels. Have some way of generating distinct labels +for use in extended asm statements. I don't know what a good syntax would +be. + +* A way of defining a structure containing a union, in which the choice of +union alternative is controlled by a previous structure component. + +Here is a possible syntax for this. + +struct foo { + enum { INT, DOUBLE } code; + auto union { case INT: int i; case DOUBLE: double d;} value : code; +}; + +* Allow constructor expressions as lvalues, like this: + + (struct foo) {a, b, c} = foo(); + +This would call foo, which returns a structure, and then store the +several components of the structure into the variables a, b, and c. + +5. Generalize the machine model. + +* Some new compiler features may be needed to do a good job on machines +where static data needs to be addressed using base registers. + +* Some machines have two stacks in different areas of memory, one used +for scalars and another for large objects. The compiler does not +now have a way to understand this. + +6. Useful warnings. + +* Warn about statements that are undefined because the order of +evaluation of increment operators makes a big difference. Here is an +example: + + *foo++ = hack (*foo); + +7. Better documentation of how GCC works and how to port it. + +Here is an outline proposed by Allan Adler. + +I. Overview of this document +II. The machines on which GCC is implemented + A. Prose description of those characteristics of target machines and + their operating systems which are pertinent to the implementation + of GCC. + i. target machine characteristics + ii. comparison of this system of machine characteristics with + other systems of machine specification currently in use + B. Tables of the characteristics of the target machines on which + GCC is implemented. + C. A priori restrictions on the values of characteristics of target + machines, with special reference to those parts of the source code + which entail those restrictions + i. restrictions on individual characteristics + ii. restrictions involving relations between various characteristics + D. The use of GCC as a cross-compiler + i. cross-compilation to existing machines + ii. cross-compilation to non-existent machines + E. Assumptions which are made regarding the target machine + i. assumptions regarding the architecture of the target machine + ii. assumptions regarding the operating system of the target machine + iii. assumptions regarding software resident on the target machine + iv. where in the source code these assumptions are in effect made +III. A systematic approach to writing the files tm.h and xm.h + A. Macros which require special care or skill + B. Examples, with special reference to the underlying reasoning +IV. A systematic approach to writing the machine description file md + A. Minimal viable sets of insn descriptions + B. Examples, with special reference to the underlying reasoning +V. Uses of the file aux-output.c +VI. Specification of what constitutes correct performance of an + implementation of GCC + A. The components of GCC + B. The itinerary of a C program through GCC + C. A system of benchmark programs + D. What your RTL and assembler should look like with these benchmarks + E. Fine tuning for speed and size of compiled code +VII. A systematic procedure for debugging an implementation of GCC + A. Use of GDB + i. the macros in the file .gdbinit for GCC + ii. obstacles to the use of GDB + a. functions implemented as macros can't be called in GDB + B. Debugging without GDB + i. How to turn off the normal operation of GCC and access specific + parts of GCC + C. Debugging tools + D. Debugging the parser + i. how machine macros and insn definitions affect the parser + E. Debugging the recognizer + i. how machine macros and insn definitions affect the recognizer + +ditto for other components + +VIII. Data types used by GCC, with special reference to restrictions not + specified in the formal definition of the data type +IX. References to the literature for the algorithms used in GCC + diff --git a/contrib/gcc/README b/contrib/gcc/README new file mode 100644 index 00000000000..43ed75d6f9f --- /dev/null +++ b/contrib/gcc/README @@ -0,0 +1,26 @@ +This directory contains the version 2.7.2 release of the GNU C +compiler. It includes all of the support for compiling C++ and +Objective C, including a run-time library for Objective C. + +The GNU C compiler is free software. See the file COPYING for copying +permission. + +See the file gcc.texi (together with other files that it includes) for +installation and porting information. The file INSTALL contains a +copy of the installation information, as plain ASCII. + +Installing this package will create various files in subdirectories of +/usr/local/lib, which are passes used by the compiler and a library +named libgcc.a. It will also create /usr/local/bin/gcc, which is +the user-level command to do a compilation. + +See the Bugs chapter of the GCC Manual for how to report bugs +usefully. An online readable version of the manual is in the files +gcc.info*. + +The files pself.c and pself1.c are not part of GCC. +They are programs that print themselves on standard output. +They were written by Dario Dariol and Giovanni Cozzi, and are +included for your hacking pleasure. Likewise pself2.c +(Who is the author of that?) and pself3.c (by Vlad Taeerov and Rashit +Fakhreyev). diff --git a/contrib/gcc/README-fixinc b/contrib/gcc/README-fixinc new file mode 100644 index 00000000000..4b303ddc63a --- /dev/null +++ b/contrib/gcc/README-fixinc @@ -0,0 +1,9 @@ +This README file is copied into the directory for GCC-only header files +when fixincludes is run by the makefile for GCC. + +Many of the files in this directory were made from the standard system +header files of this system by the shell script `fixincludes'. +They are system-specific, and will not work on any other kind of system. +They are also not part of GCC. The reason for making the files here +is to fix the places in the header files which use constructs +that are incompatible with ANSI C. diff --git a/contrib/gcc/README.ACORN b/contrib/gcc/README.ACORN new file mode 100644 index 00000000000..769dba74a33 --- /dev/null +++ b/contrib/gcc/README.ACORN @@ -0,0 +1,18 @@ +Specifying the -g flag to GCC on a RISC iX machine requires upgrading the +standard assembler distributed with both RISC iX 1.1 and RISC iX 1.2 with a +replacement that is available from Acorn. This version of the assembler is +also an order of magnitude faster when assembling to an NFS mounted +file-system. + +Users of RISC iX 1.2 and above can obtain a copy of the assembler from the +following places: + +1) Via ftp from acorn.acorn.co.uk, directory pub/riscix. + +2) From Acorn Customer Services. + +3) From Granada Microcare. + +Users of versions of RISC iX prior 1.2 should contact Acorn Customer Services; +the assembler available on the net will not work with these versions due to +changes in the shared libraries and system call numbers. diff --git a/contrib/gcc/README.ALTOS b/contrib/gcc/README.ALTOS new file mode 100644 index 00000000000..c0a1a04145f --- /dev/null +++ b/contrib/gcc/README.ALTOS @@ -0,0 +1,55 @@ +Since COFF-encapsulation is obsolete, this may not be needed anymore. + +Return-Path: +Date: Mon, 10 Apr 89 10:13:45 +0300 +From: Jyrki Kuoppala +Sender: jkp@sauna.hut.fi +To: info-gcc@prep.ai.mit.edu +Subject: Kernel fix needed for Altos 3068 to get coff-encapsulation working right +Organization: Helsinki University of Technology, Finland. + +Here's a description how to fix a kernel bug in Altos 3068 and get +gcc-compiled programs working. + +Author: Jyrki Kuoppala (jkp@cs.hut.fi) +Last modified: Mon Apr 10 09:28:40 1989 + +There's a bug in the Altos 3068 kernel that causes gcc-compiled +programs to fail in certain situations when the machine has a heavy +load and also in some other situations. The bug exists at least in +SVR 2.2 1.0gT1 and SVR 2.2 1.0e. + +If you have source code to your system, apply the following change to +os/exec.c (function gethead): + +Change the lines containing + + u.u_exdata.ux_tstart = sizeof(struct naout) + + sizeof(struct filhd) + (ep->ef.nscns * sizeof(struct scnhdr)); + +to + + u.u_exdata.ux_tstart = u.u_exdata.ux_txtorg; + +If you only have binary, use sdb to find out the address of the +previous lines (on our system it's gethead+0x140) and use your +favourite binary editor to change the bytes '3036 0162 fffc 0002 0280 +0000' to '23f9 01fb f4ca 01fb f4c2 6016'. This may or may not work in +your case, depending on the version of the operating system and the +phase of the moon. + +Here's what is just before gethead+0x140 to ease finding out the right place: + +0x9224 (gethead+0x122): 23f9 01fb f4ca 01fb f4ce mov.l &0x1fbf4ca.L,&0 +x1fbf4ce.L [] +0x922e (gethead+0x12c): 23f9 01fb f4c6 01fb f4ca mov.l &0x1fbf4c6.L,&0 +x1fbf4ca.L [] +0x9238 (gethead+0x136): 23f9 01fb f4c2 01fb f4c6 mov.l &0x1fbf4c2.L,&0 +x1fbf4c6.L [] + +Good luck ! + +//Jyrki + +jkp@cs.hut.fi + diff --git a/contrib/gcc/README.APOLLO b/contrib/gcc/README.APOLLO new file mode 100644 index 00000000000..ca02de14284 --- /dev/null +++ b/contrib/gcc/README.APOLLO @@ -0,0 +1,112 @@ +README.apollo + +Building GCC 2.0 for 680x0 based Apollo systems requires the GNU +assembler (GAS) version 1.38.1, with John Vasta's patches applied. + +If you haven't done so yet, get `gas-1.38.1.tar.Z' from your favourite +GNU distribution site. Furthermore, get `apollo-gas-1.38.1.diffs' +from `labrea.stanford.edu:/pub/gnu', apply the patches, compile and +install gas (under the name as). This should go through without any +problems. + +After switching into the BSD environment, you can configure GCC 2.0 +with the command + +% ./configure m68k-apollo-bsd + +The Apollo's `/usr/include/setjmp.h' uses a nonstandard `#options()' +construct. You should create a local copy of this file and remove +these constructs from the declarations of SIGSETJMP and SIGLONGJMP. + +The Apollo's `/usr/include/sys/types.h' (BSD Version) doesn't allow +to test for the definition of `size_t'. This should be fixed by + + #ifndef _SIZE_T + #define _SIZE_T + typedef long size_t; + #endif + +The script `patch-apollo-includes' fixes these two problems, but does +_not_ pretend to be a full fledged `fixincludes' for this system. + +If you now follow the standard GCC installation instructions, building +GCC 2.0 (including G++ 2.0) should proceed without any problems. + +NB: Debugging is not yet supported for the Apollo. If someone wants + to do a _big_ favour to the Apollo users, he/she should consider + porting the Binary File Description library (BFD) to the Apollo. + This library can be found in the gdb-4.x distributions or in the + binutils-1.9x distributions. + + + + +#!/bin/sh +# patch-apollo-includes -- fix some (but not all!) Apollo brain damage. + +FILES_TO_PATCH='sys/types.h setjmp.h' + +mkdir sys + +for i in $FILES_TO_PATCH; +do + cp /bsd4.3/usr/include/$i ./$i +done + +patch -b -apollo <<'EOP' +*** /bsd4.3/usr/include/sys/types.h Fri Apr 8 20:29:06 1988 +--- sys/types.h Wed Feb 26 21:17:57 1992 +*************** +*** 38,44 **** +--- 38,47 ---- + typedef char * caddr_t; + typedef u_long ino_t; + typedef long swblk_t; ++ #ifndef _SIZE_T ++ #define _SIZE_T + typedef long size_t; ++ #endif + typedef long time_t; + typedef long dev_t; + typedef long off_t; +*** /bsd4.3/usr/include/setjmp.h Fri Feb 3 21:40:21 1989 +--- setjmp.h Sun Feb 23 19:06:55 1992 +*************** +*** 24,30 **** +--- 24,39 ---- + #endif + + ++ #ifdef __GNUC__ + #ifdef _PROTOTYPES ++ extern int sigsetjmp (sigjmp_buf env, int savemask); ++ extern void siglongjmp (sigjmp_buf env, int val); ++ #else ++ extern int sigsetjmp(); ++ extern void siglongjmp(); ++ #endif /* _PROTOTYPES */ ++ #else /* not __GNUC__ */ ++ #ifdef _PROTOTYPES + extern int sigsetjmp( + sigjmp_buf env, + int savemask +*************** +*** 37,43 **** + extern int sigsetjmp() #options(abnormal); + extern void siglongjmp() #options(noreturn); + #endif /* _PROTOTYPES */ +! + #undef _PROTOTYPES + + #ifdef __cplusplus +--- 46,52 ---- + extern int sigsetjmp() #options(abnormal); + extern void siglongjmp() #options(noreturn); + #endif /* _PROTOTYPES */ +! #endif /* not __GNUC__ */ + #undef _PROTOTYPES + + #ifdef __cplusplus +EOP + +exit 0 diff --git a/contrib/gcc/README.DWARF b/contrib/gcc/README.DWARF new file mode 100644 index 00000000000..ac4719d0493 --- /dev/null +++ b/contrib/gcc/README.DWARF @@ -0,0 +1,574 @@ +Notes on the GNU Implementation of DWARF Debugging Information +-------------------------------------------------------------- +Last Updated: Sun Jul 17 08:17:42 PDT 1994 by rfg@segfault.us.com +------------------------------------------------------------ + +This file describes special and unique aspects of the GNU implementation +of the DWARF debugging information language, as provided in the GNU version +2.x compiler(s). + +For general information about the DWARF debugging information language, +you should obtain the DWARF version 1 specification document (and perhaps +also the DWARF version 2 draft specification document) developed by the +UNIX International Programming Languages Special Interest Group. A copy +of the the DWARF version 1 specification (in PostScript form) may be +obtained either from me or from the main Data General +FTP server. (See below.) The file you are looking at now only describes +known deviations from the DWARF version 1 specification, together with +those things which are allowed by the DWARF version 1 specification but +which are known to cause interoperability problems (e.g. with SVR4 SDB). + +To obtain a copy of the DWARF Version 1 and/or DWARF Version 2 specification +from Data General's FTP server, use the following procedure: + +--------------------------------------------------------------------------- + ftp to machine: "dg-rtp.dg.com" (128.222.1.2). + + Log in as "ftp". + cd to "plsig" + get any of the following file you are interested in: + + dwarf.1.0.3.ps + dwarf.2.0.0.index.ps + dwarf.2.0.0.ps +--------------------------------------------------------------------------- + +The generation of DWARF debugging information by the GNU version 2.x C +compiler has now been tested rather extensively for m88k, i386, i860, and +Sparc targets. The DWARF output of the GNU C compiler appears to inter- +operate well with the standard SVR4 SDB debugger on these kinds of target +systems (but of course, there are no guarantees). + +DWARF generation for the GNU g++ compiler is still not operable. This is +due primarily to the many remaining cases where the g++ front end does not +conform to the conventions used in the GNU C front end for representing +various kinds of declarations in the TREE data structure. It is not clear +at this time how these problems will be addressed. + +Future plans for the dwarfout.c module of the GNU compiler(s) includes the +addition of full support for GNU FORTRAN. (This should, in theory, be a +lot simpler to add than adding support for g++... but we'll see.) + +Many features of the DWARF version 2 specification have been adapted to +(and used in) the GNU implementation of DWARF (version 1). In most of +these cases, a DWARF version 2 approach is used in place of (or in addition +to) DWARF version 1 stuff simply because it is apparent that DWARF version +1 is not sufficiently expressive to provide the kinds of information which +may be necessary to support really robust debugging. In all of these cases +however, the use of DWARF version 2 features should not interfere in any +way with the interoperability (of GNU compilers) with generally available +"classic" (pre version 1) DWARF consumer tools (e.g. SVR4 SDB). + +The DWARF generation enhancement for the GNU compiler(s) was initially +donated to the Free Software Foundation by Network Computing Devices. +(Thanks NCD!) Additional development and maintenance of dwarfout.c has +been largely supported (i.e. funded) by Intel Corporation. (Thanks Intel!) + +If you have questions or comments about the DWARF generation feature, please +send mail to me . I will be happy to investigate any bugs +reported and I may even provide fixes (but of course, I can make no promises). + +The DWARF debugging information produced by GCC may deviate in a few minor +(but perhaps significant) respects from the DWARF debugging information +currently produced by other C compilers. A serious attempt has been made +however to conform to the published specifications, to existing practice, +and to generally accepted norms in the GNU implementation of DWARF. + + ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** + +Under normal circumstances, the DWARF information generated by the GNU +compilers (in an assembly language file) is essentially impossible for +a human being to read. This fact can make it very difficult to debug +certain DWARF-related problems. In order to overcome this difficulty, +a feature has been added to dwarfout.c (enabled by the -fverbose-asm +option) which causes additional comments to be placed into the assembly +language output file, out to the right-hand side of most bits of DWARF +material. The comments indicate (far more clearly that the obscure +DWARF hex codes do) what is actually being encoded in DWARF. Thus, the +-fverbose-asm option can be highly useful for those who must study the +DWARF output from the GNU compilers in detail. + +--------- + +(Footnote: Within this file, the term `Debugging Information Entry' will +be abbreviated as `DIE'.) + + +Release Notes (aka known bugs) +------------------------------- + +In one very obscure case involving dynamically sized arrays, the DWARF +"location information" for such an array may make it appear that the +array has been totally optimized out of existence, when in fact it +*must* actually exist. (This only happens when you are using *both* -g +*and* -O.) This is due to aggressive dead store elimination in the +compiler, and to the fact that the DECL_RTL expressions associated with +variables are not always updated to correctly reflect the effects of +GCC's aggressive dead store elimination. + +------------------------------- + +When attempting to set a breakpoint at the "start" of a function compiled +with -g1, the debugger currently has no way of knowing exactly where the +end of the prologue code for the function is. Thus, for most targets, +all the debugger can do is to set the breakpoint at the AT_low_pc address +for the function. But if you stop there and then try to look at one or +more of the formal parameter values, they may not have been "homed" yet, +so you may get inaccurate answers (or perhaps even addressing errors). + +Some people may consider this simply a non-feature, but I consider it a +bug, and I hope to provide some some GNU-specific attributes (on function +DIEs) which will specify the address of the end of the prologue and the +address of the beginning of the epilogue in a future release. + +------------------------------- + +It is believed at this time that old bugs relating to the AT_bit_offset +values for bit-fields have been fixed. + +There may still be some very obscure bugs relating to the DWARF description +of type `long long' bit-fields for target machines (e.g. 80x86 machines) +where the alignment of type `long long' data objects is different from +(and less than) the size of a type `long long' data object. + +Please report any problems with the DWARF description of bit-fields as you +would any other GCC bug. (Procedures for bug reporting are given in the +GNU C compiler manual.) + +-------------------------------- + +At this time, GCC does not know how to handle the GNU C "nested functions" +extension. (See the GCC manual for more info on this extension to ANSI C.) + +-------------------------------- + +The GNU compilers now represent inline functions (and inlined instances +thereof) in exactly the manner described by the current DWARF version 2 +(draft) specification. The version 1 specification for handling inline +functions (and inlined instances) was known to be brain-damaged (by the +PLSIG) when the version 1 spec was finalized, but it was simply too late +in the cycle to get it removed before the version 1 spec was formally +released to the public (by UI). + +-------------------------------- + +At this time, GCC does not generate the kind of really precise information +about the exact declared types of entities with signed integral types which +is required by the current DWARF draft specification. + +Specifically, the current DWARF draft specification seems to require that +the type of an non-unsigned integral bit-field member of a struct or union +type be represented as either a "signed" type or as a "plain" type, +depending upon the the exact set of keywords that were used in the +type specification for the given bit-field member. It was felt (by the +UI/PLSIG) that this distinction between "plain" and "signed" integral types +could have some significance (in the case of bit-fields) because ANSI C +does not constrain the signedness of a plain bit-field, whereas it does +constrain the signedness of an explicitly "signed" bit-field. For this +reason, the current DWARF specification calls for compilers to produce +type information (for *all* integral typed entities... not just bit-fields) +which explicitly indicates the signedness of the relevant type to be +"signed" or "plain" or "unsigned". + +Unfortunately, the GNU DWARF implementation is currently incapable of making +such distinctions. + +-------------------------------- + + +Known Interoperability Problems +------------------------------- + +Although the GNU implementation of DWARF conforms (for the most part) with +the current UI/PLSIG DWARF version 1 specification (with many compatible +version 2 features added in as "vendor specific extensions" just for good +measure) there are a few known cases where GCC's DWARF output can cause +some confusion for "classic" (pre version 1) DWARF consumers such as the +System V Release 4 SDB debugger. These cases are described in this section. + +-------------------------------- + +The DWARF version 1 specification includes the fundamental type codes +FT_ext_prec_float, FT_complex, FT_dbl_prec_complex, and FT_ext_prec_complex. +Since GNU C is only a C compiler (and since C doesn't provide any "complex" +data types) the only one of these fundamental type codes which GCC ever +generates is FT_ext_prec_float. This fundamental type code is generated +by GCC for the `long double' data type. Unfortunately, due to an apparent +bug in the SVR4 SDB debugger, SDB can become very confused wherever any +attempt is made to print a variable, parameter, or field whose type was +given in terms of FT_ext_prec_float. + +(Actually, SVR4 SDB fails to understand *any* of the four fundamental type +codes mentioned here. This will fact will cause additional problems when +there is a GNU FORTRAN front-end.) + +-------------------------------- + +In general, it appears that SVR4 SDB is not able to effectively ignore +fundamental type codes in the "implementation defined" range. This can +cause problems when a program being debugged uses the `long long' data +type (or the signed or unsigned varieties thereof) because these types +are not defined by ANSI C, and thus, GCC must use its own private fundamental +type codes (from the implementation-defined range) to represent these types. + +-------------------------------- + + +General GNU DWARF extensions +---------------------------- + +In the current DWARF version 1 specification, no mechanism is specified by +which accurate information about executable code from include files can be +properly (and fully) described. (The DWARF version 2 specification *does* +specify such a mechanism, but it is about 10 times more complicated than +it needs to be so I'm not terribly anxious to try to implement it right +away.) + +In the GNU implementation of DWARF version 1, a fully downward-compatible +extension has been implemented which permits the GNU compilers to specify +which executable lines come from which files. This extension places +additional information (about source file names) in GNU-specific sections +(which should be totally ignored by all non-GNU DWARF consumers) so that +this extended information can be provided (to GNU DWARF consumers) in a way +which is totally transparent (and invisible) to non-GNU DWARF consumers +(e.g. the SVR4 SDB debugger). The additional information is placed *only* +in specialized GNU-specific sections, where it should never even be seen +by non-GNU DWARF consumers. + +To understand this GNU DWARF extension, imagine that the sequence of entries +in the .lines section is broken up into several subsections. Each contiguous +sequence of .line entries which relates to a sequence of lines (or statements) +from one particular file (either a `base' file or an `include' file) could +be called a `line entries chunk' (LEC). + +For each LEC there is one entry in the .debug_srcinfo section. + +Each normal entry in the .debug_srcinfo section consists of two 4-byte +words of data as follows: + + (1) The starting address (relative to the entire .line section) + of the first .line entry in the relevant LEC. + + (2) The starting address (relative to the entire .debug_sfnames + section) of a NUL terminated string representing the + relevant filename. (This filename name be either a + relative or an absolute filename, depending upon how the + given source file was located during compilation.) + +Obviously, each .debug_srcinfo entry allows you to find the relevant filename, +and it also points you to the first .line entry that was generated as a result +of having compiled a given source line from the given source file. + +Each subsequent .line entry should also be assumed to have been produced +as a result of compiling yet more lines from the same file. The end of +any given LEC is easily found by looking at the first 4-byte pointer in +the *next* .debug_srcinfo entry. That next .debug_srcinfo entry points +to a new and different LEC, so the preceding LEC (implicitly) must have +ended with the last .line section entry which occurs at the 2 1/2 words +just before the address given in the first pointer of the new .debug_srcinfo +entry. + +The following picture may help to clarify this feature. Let's assume that +`LE' stands for `.line entry'. Also, assume that `* 'stands for a pointer. + + + .line section .debug_srcinfo section .debug_sfnames section + ---------------------------------------------------------------- + + LE <---------------------- * + LE * -----------------> "foobar.c" <--- + LE | + LE | + LE <---------------------- * | + LE * -----------------> "foobar.h" <| | + LE | | + LE | | + LE <---------------------- * | | + LE * -----------------> "inner.h" | | + LE | | + LE <---------------------- * | | + LE * ------------------------------- | + LE | + LE | + LE | + LE | + LE <---------------------- * | + LE * ----------------------------------- + LE + LE + LE + +In effect, each entry in the .debug_srcinfo section points to *both* a +filename (in the .debug_sfnames section) and to the start of a block of +consecutive LEs (in the .line section). + +Note that just like in the .line section, there are specialized first and +last entries in the .debug_srcinfo section for each object file. These +special first and last entries for the .debug_srcinfo section are very +different from the normal .debug_srcinfo section entries. They provide +additional information which may be helpful to a debugger when it is +interpreting the data in the .debug_srcinfo, .debug_sfnames, and .line +sections. + +The first entry in the .debug_srcinfo section for each compilation unit +consists of five 4-byte words of data. The contents of these five words +should be interpreted (by debuggers) as follows: + + (1) The starting address (relative to the entire .line section) + of the .line section for this compilation unit. + + (2) The starting address (relative to the entire .debug_sfnames + section) of the .debug_sfnames section for this compilation + unit. + + (3) The starting address (in the execution virtual address space) + of the .text section for this compilation unit. + + (4) The ending address plus one (in the execution virtual address + space) of the .text section for this compilation unit. + + (5) The date/time (in seconds since midnight 1/1/70) at which the + compilation of this compilation unit occurred. This value + should be interpreted as an unsigned quantity because gcc + might be configured to generate a default value of 0xffffffff + in this field (in cases where it is desired to have object + files created at different times from identical source files + be byte-for-byte identical). By default, these timestamps + are *not* generated by dwarfout.c (so that object files + compiled at different times will be byte-for-byte identical). + If you wish to enable this "timestamp" feature however, you + can simply place a #define for the symbol `DWARF_TIMESTAMPS' + in your target configuration file and then rebuild the GNU + compiler(s). + +Note that the first string placed into the .debug_sfnames section for each +compilation unit is the name of the directory in which compilation occurred. +This string ends with a `/' (to help indicate that it is the pathname of a +directory). Thus, the second word of each specialized initial .debug_srcinfo +entry for each compilation unit may be used as a pointer to the (string) +name of the compilation directory, and that string may in turn be used to +"absolutize" any relative pathnames which may appear later on in the +.debug_sfnames section entries for the same compilation unit. + +The fifth and last word of each specialized starting entry for a compilation +unit in the .debug_srcinfo section may (depending upon your configuration) +indicate the date/time of compilation, and this may be used (by a debugger) +to determine if any of the source files which contributed code to this +compilation unit are newer than the object code for the compilation unit +itself. If so, the debugger may wish to print an "out-of-date" warning +about the compilation unit. + +The .debug_srcinfo section associated with each compilation will also have +a specialized terminating entry. This terminating .debug_srcinfo section +entry will consist of the following two 4-byte words of data: + + (1) The offset, measured from the start of the .line section to + the beginning of the terminating entry for the .line section. + + (2) A word containing the value 0xffffffff. + +-------------------------------- + +In the current DWARF version 1 specification, no mechanism is specified by +which information about macro definitions and un-definitions may be provided +to the DWARF consumer. + +The DWARF version 2 (draft) specification does specify such a mechanism. +That specification was based on the GNU ("vendor specific extension") +which provided some support for macro definitions and un-definitions, +but the "official" DWARF version 2 (draft) specification mechanism for +handling macros and the GNU implementation have diverged somewhat. I +plan to update the GNU implementation to conform to the "official" +DWARF version 2 (draft) specification as soon as I get time to do that. + +Note that in the GNU implementation, additional information about macro +definitions and un-definitions is *only* provided when the -g3 level of +debug-info production is selected. (The default level is -g2 and the +plain old -g option is considered to be identical to -g2.) + +GCC records information about macro definitions and undefinitions primarily +in a section called the .debug_macinfo section. Normal entries in the +.debug_macinfo section consist of the following three parts: + + (1) A special "type" byte. + + (2) A 3-byte line-number/filename-offset field. + + (3) A NUL terminated string. + +The interpretation of the second and third parts is dependent upon the +value of the leading (type) byte. + +The type byte may have one of four values depending upon the type of the +.debug_macinfo entry which follows. The 1-byte MACINFO type codes presently +used, and their meanings are as follows: + + MACINFO_start A base file or an include file starts here. + MACINFO_resume The current base or include file ends here. + MACINFO_define A #define directive occurs here. + MACINFO_undef A #undef directive occur here. + +(Note that the MACINFO_... codes mentioned here are simply symbolic names +for constants which are defined in the GNU dwarf.h file.) + +For MACINFO_define and MACINFO_undef entries, the second (3-byte) field +contains the number of the source line (relative to the start of the current +base source file or the current include files) when the #define or #undef +directive appears. For a MACINFO_define entry, the following string field +contains the name of the macro which is defined, followed by its definition. +Note that the definition is always separated from the name of the macro +by at least one whitespace character. For a MACINFO_undef entry, the +string which follows the 3-byte line number field contains just the name +of the macro which is being undef'ed. + +For a MACINFO_start entry, the 3-byte field following the type byte contains +the offset, relative to the start of the .debug_sfnames section for the +current compilation unit, of a string which names the new source file which +is beginning its inclusion at this point. Following that 3-byte field, +each MACINFO_start entry always contains a zero length NUL terminated +string. + +For a MACINFO_resume entry, the 3-byte field following the type byte contains +the line number WITHIN THE INCLUDING FILE at which the inclusion of the +current file (whose inclusion ends here) was initiated. Following that +3-byte field, each MACINFO_resume entry always contains a zero length NUL +terminated string. + +Each set of .debug_macinfo entries for each compilation unit is terminated +by a special .debug_macinfo entry consisting of a 4-byte zero value followed +by a single NUL byte. + +-------------------------------- + +In the current DWARF draft specification, no provision is made for providing +a separate level of (limited) debugging information necessary to support +tracebacks (only) through fully-debugged code (e.g. code in system libraries). + +A proposal to define such a level was submitted (by me) to the UI/PLSIG. +This proposal was rejected by the UI/PLSIG for inclusion into the DWARF +version 1 specification for two reasons. First, it was felt (by the PLSIG) +that the issues involved in supporting a "traceback only" subset of DWARF +were not well understood. Second, and perhaps more importantly, the PLSIG +is already having enough trouble agreeing on what it means to be "conforming" +to the DWARF specification, and it was felt that trying to specify multiple +different *levels* of conformance would only complicate our discussions of +this already divisive issue. Nonetheless, the GNU implementation of DWARF +provides an abbreviated "traceback only" level of debug-info production for +use with fully-debugged "system library" code. This level should only be +used for fully debugged system library code, and even then, it should only +be used where there is a very strong need to conserve disk space. This +abbreviated level of debug-info production can be used by specifying the +-g1 option on the compilation command line. + +-------------------------------- + +As mentioned above, the GNU implementation of DWARF currently uses the DWARF +version 2 (draft) approach for inline functions (and inlined instances +thereof). This is used in preference to the version 1 approach because +(quite simply) the version 1 approach is highly brain-damaged and probably +unworkable. + +-------------------------------- + + +GNU DWARF Representation of GNU C Extensions to ANSI C +------------------------------------------------------ + +The file dwarfout.c has been designed and implemented so as to provide +some reasonable DWARF representation for each and every declarative +construct which is accepted by the GNU C compiler. Since the GNU C +compiler accepts a superset of ANSI C, this means that there are some +cases in which the DWARF information produced by GCC must take some +liberties in improvising DWARF representations for declarations which +are only valid in (extended) GNU C. + +In particular, GNU C provides at least three significant extensions to +ANSI C when it comes to declarations. These are (1) inline functions, +and (2) dynamic arrays, and (3) incomplete enum types. (See the GCC +manual for more information on these GNU extensions to ANSI C.) When +used, these GNU C extensions are represented (in the generated DWARF +output of GCC) in the most natural and intuitively obvious ways. + +In the case of inline functions, the DWARF representation is exactly as +called for in the DWARF version 2 (draft) specification for an identical +function written in C++; i.e. we "reuse" the representation of inline +functions which has been defined for C++ to support this GNU C extension. + +In the case of dynamic arrays, we use the most obvious representational +mechanism available; i.e. an array type in which the upper bound of +some dimension (usually the first and only dimension) is a variable +rather than a constant. (See the DWARF version 1 specification for more +details.) + +In the case of incomplete enum types, such types are represented simply +as TAG_enumeration_type DIEs which DO NOT contain either AT_byte_size +attributes or AT_element_list attributes. + +-------------------------------- + + +Future Directions +----------------- + +The codes, formats, and other paraphernalia necessary to provide proper +support for symbolic debugging for the C++ language are still being worked +on by the UI/PLSIG. The vast majority of the additions to DWARF which will +be needed to completely support C++ have already been hashed out and agreed +upon, but a few small issues (e.g. anonymous unions, access declarations) +are still being discussed. Also, we in the PLSIG are still discussing +whether or not we need to do anything special for C++ templates. (At this +time it is not yet clear whether we even need to do anything special for +these.) + +Unfortunately, as mentioned above, there are quite a few problems in the +g++ front end itself, and these are currently responsible for severely +restricting the progress which can be made on adding DWARF support +specifically for the g++ front-end. Furthermore, Richard Stallman has +expressed the view that C++ friendships might not be important enough to +describe (in DWARF). This view directly conflicts with both the DWARF +version 1 and version 2 (draft) specifications, so until this small +misunderstanding is cleared up, DWARF support for g++ is unlikely. + +With regard to FORTRAN, the UI/PLSIG has defined what is believed to be a +complete and sufficient set of codes and rules for adequately representing +all of FORTRAN 77, and most of Fortran 90 in DWARF. While some support for +this has been implemented in dwarfout.c, further implementation and testing +will have to await the arrival of the GNU Fortran front-end (which is +currently in early alpha test as of this writing). + +GNU DWARF support for other languages (i.e. Pascal and Modula) is a moot +issue until there are GNU front-ends for these other languages. + +GNU DWARF support for DWARF version 2 will probably not be attempted until +such time as the version 2 specification is finalized. (More work needs +to be done on the version 2 specification to make the new "abbreviations" +feature of version 2 more easily implementable. Until then, it will be +a royal pain the ass to implement version 2 "abbreviations".) For the +time being, version 2 features will be added (in a version 1 compatible +manner) when and where these features seem necessary or extremely desirable. + +As currently defined, DWARF only describes a (binary) language which can +be used to communicate symbolic debugging information from a compiler +through an assembler and a linker, to a debugger. There is no clear +specification of what processing should be (or must be) done by the +assembler and/or the linker. Fortunately, the role of the assembler +is easily inferred (by anyone knowledgeable about assemblers) just by +looking at examples of assembly-level DWARF code. Sadly though, the +allowable (or required) processing steps performed by a linker are +harder to infer and (perhaps) even harder to agree upon. There are +several forms of very useful `post-processing' steps which intelligent +linkers *could* (in theory) perform on object files containing DWARF, +but any and all such link-time transformations are currently both disallowed +and unspecified. + +In particular, possible link-time transformations of DWARF code which could +provide significant benefits include (but are not limited to): + + Commonization of duplicate DIEs obtained from multiple input + (object) files. + + Cross-compilation type checking based upon DWARF type information + for objects and functions. + + Other possible `compacting' transformations designed to save disk + space and to reduce linker & debugger I/O activity. diff --git a/contrib/gcc/README.FRESCO b/contrib/gcc/README.FRESCO new file mode 100644 index 00000000000..334e78023a9 --- /dev/null +++ b/contrib/gcc/README.FRESCO @@ -0,0 +1,17 @@ +Compiling Fresco with g++ +----------------------------- + +Fresco is an evolving interface and toolkit for object-oriented +graphics. A preliminary version (written in C++) was released +with x11r6. + +Previous versions of Fresco have not compiled using g++, +partly because of the use of true and false as identifiers. +(They are now reserved words in g++, as required by the +ANSI/ISO draft standard for C++.) + +If you get x11r6 with public patch #5 or a later version +of Fresco, these problems should now be fixed. + +See http://www.faslab.com/fresco/HomePage.html for information +on Fresco, including how to get the latest version. diff --git a/contrib/gcc/README.NS32K b/contrib/gcc/README.NS32K new file mode 100644 index 00000000000..93c5beaef54 --- /dev/null +++ b/contrib/gcc/README.NS32K @@ -0,0 +1,130 @@ +This file describes the implementation notes of the GNU C Compiler for +the National Semiconductor 32032 chip (and 32000 family). + +The 32032 machine description and configuration file for this compiler +is, for NS32000 family machine, primarily machine independent. +However, since this release still depends on vendor-supplied +assemblers and linkers, the compiler must obey the existing +conventions of the actual machine to which this compiler is targeted. +In this case, the actual machine which this compiler was targeted to +is a Sequent Balance 8000, running DYNIX 2.1. + +The assembler for DYNIX 2.1 (and DYNIX 3.0, alas) does not cope with +the full generality of the addressing mode REGISTER RELATIVE. +Specifically, it generates incorrect code for operands of the +following form: + + sym(rn) + +Where `rn' is one of the general registers. Correct code is generated +for operands of the form + + sym(pn) + +where `pn' is one of the special processor registers (sb, fp, or sp). + +An equivalent operand can be generated by the form + + sym[rn:b] + +although this addressing mode is about twice as slow on the 32032. + +The more efficient addressing mode is controlled by defining the +constant SEQUENT_ADDRESS_BUG to 0. It is currently defined to be 1. + +Another bug in the assembler makes it impossible to compute with +explicit addresses. In order to compute with a symbolic address, it +is necessary to load that address into a register using the "addr" +instruction. For example, it is not possible to say + + cmpd _p,@_x + +Rather one must say + + addr _x,rn + cmpd _p,rn + + +The ns32032 chip has a number of known bugs. Any attempt to make the +compiler unaware of these deficiencies will surely bring disaster. +The current list of know bugs are as follows (list provided by Richard +Stallman): + +1) instructions with two overlapping operands in memory +(unlikely in C code, perhaps impossible). + +2) floating point conversion instructions with constant +operands (these may never happen, but I'm not certain). + +3) operands crossing a page boundary. These can be prevented +by setting the flag in tm.h that requires strict alignment. + +4) Scaled indexing in an insn following an insn that has a read-write +operand in memory. This can be prevented by placing a no-op in +between. I, Michael Tiemann, do not understand what exactly is meant +by `read-write operand in memory'. If this is referring to the special +TOS mode, for example "addd 5,tos" then one need not fear, since this +will never be generated. However, is this includes "addd 5,-4(fp)" +then there is room for disaster. The Sequent compiler does not insert +a no-op for code involving the latter, and I have been informed that +Sequent is aware of this list of bugs, so I must assume that it is not +a problem. + +5) The 32032 cannot shift by 32 bits. It shifts modulo the word size +of the operand. Therefore, for 32-bit operations, 32-bit shifts are +interpreted as zero bit shifts. 32-bit shifts have been removed from +the compiler, but future hackers must be careful not to reintroduce +them. + +6) The ns32032 is a very slow chip; however, some instructions are +still very much slower than one might expect. For example, it is +almost always faster to double a quantity by adding it to itself than +by shifting it by one, even if that quantity is deep in memory. The +MOVM instruction has a 20-cycle setup time, after which it moves data +at about the speed that normal moves would. It is also faster to use +address generation instructions than shift instructions for left +shifts less than 4. I do not claim that I generate optimal code for all +given patterns, but where I did escape from National's "clean +architecture", I did so because the timing specification from the data +book says that I will win if I do. I suppose this is called the +"performance gap". + + +Signed bitfield extraction has not been implemented. It is not +provided by the NS32032, and while it is most certainly possible to do +better than the standard shift-left/shift-right sequence, it is also +quite hairy. Also, since signed bitfields do not yet exist in C, this +omission seems relatively harmless. + + +Zero extractions could be better implemented if it were possible in +GCC to provide sized zero extractions: i.e. a byte zero extraction +would be allowed to yield a byte result. The current implementation +of GCC manifests 68000-ist thinking, where bitfields are extracted +into a register, and automatically sign/zero extended to fill the +register. See comments in ns32k.md around the "extzv" insn for more +details. + + +It should be noted that while the NS32000 family was designed to +provide odd-aligned addressing capability for multi-byte data (also +provided by the 68020, but not by the 68000 or 68010), many machines +do not opt to take advantage of this. For example, on the sequent, +although there is no advantage to long-word aligning word data, shorts +must be int-aligned in structs. This is an example of another +machine-specific machine dependency. + + +Because the ns32032 is has a coherent byte-order/bit-order +architecture, many instructions which would be different for +68000-style machines, fold into the same instruction for the 32032. +The classic case is push effective address, where it does not matter +whether one is pushing a long, word, or byte address. They all will +push the same address. + + +The macro FUNCTION_VALUE_REGNO_P is probably not sufficient, what is +needed is FUNCTION_VALUE_P, which also takes a MODE parameter. In +this way it will be possible to determine more exactly whether a +register is really a function value register, or just one that happens +to look right. diff --git a/contrib/gcc/README.RS6000 b/contrib/gcc/README.RS6000 new file mode 100644 index 00000000000..d29604f968a --- /dev/null +++ b/contrib/gcc/README.RS6000 @@ -0,0 +1,111 @@ + AIX 3.1 and 3.2 assembler problems + +Specifying the -g flag to GCC on the RS/6000 requires upgrading the +standard AIX assembler distributed with AIX 3.1 and versions of AIX +3.2 earlier than 3.2.4 with a replacement that is available from IBM. +Note that Makefile.in specifies the -g when compiling libgcc2.c. + +You can test for the presence of a fixed assembler by entering the following: + % as -u < /dev/null +If the command exits normally, the assembler fix already is installed. +If the assembler complains that "-u" is an unknown flag, you need to order +the fix. + +If you are running AIX 3.1 (lslpp -h bos.obj output reports +03.01.0005.XXXX where the 0005 can be any higher number and the XXXX +can be any value), call IBM Support at 800-237-5511 and ask for +shipment of AIX/6000 fix PTF U403044 for APAR IX22829 (.extern foo +conflicts with defining foo). + +If you are running AIX 3.2 but not 3.2.4 or later (lslpp -h bos.obj +output reports 03.02.0000.0000), a newer update to the assembler fix +is available. Ask for shipment of AIX/6000 fix PTF U416277 for +IX32992 (.global prevents detection of duplicate symbol). + +If you are running AIX 3.2.4 or later, you already have the new +assembler. + +Any customer can order and get the replacement assembler, and install it on +one or more machines. It is available on diskette from IBM Customer Support +and from the IBM Internet fix anonymous ftp server (FixDist) at +aix.boulder.ibm.com (198.17.57.66). + +If you contact IBM Customer Support, they may also ask you for your customer +number. If you do not know it, you will still be able to get the fix, but +you will have to be persistent. IBM has corresponding support organizations +outside of North America. Call your IBM branch office and ask them to put +you in touch with the department that handles fixes for AIX/6000. If that +doesn't work, ask for the department that handles software defect support +for AIX/6000 and ask for the APAR fix. + +If you use the GNU assembler instead of the system supplied assembler, you need +an assembler modified after October 16th, 1995 in order to build the GNU C +compiler. This is because the GNU C compiler wants to build a variant of its +library, libgcc.a with the -mcpu=common switch to support building programs +that can run on either the Power or PowerPC machines. + + + AIX NLS problems + +AIX on the RS/6000 provides support (NLS) for environments outside of +the United States. Compilers and assemblers use NLS to support +locale-specific representations of various objects including +floating-point numbers ("." vs "," for separating decimal fractions). +There have been problems reported where the library linked with GCC does +not produce the same floating-point formats that the assembler accepts. +If you have this problem, set the LANG environment variable to "C" or +"En_US". + + + AIX 3.2.5 XLC-1.3 problems + +XLC version 1.3.0.0 distributed with AIX 3.2.5 will miscompile jump.c when +building the stage1 compiler during the bootstrap process. This will cause +GCC to crash and the bootstrap to fail later while compiling libgcc2.c. XLC +version 1.3.0.1 or later fixes this problem. XLC-1.3.0.19 also cannot +bootstrap GCC so please avoid that release as well. You can obtain +XLC-1.3.0.24 by requesting PTF 432238 from IBM, or just ask for the latest +release of XLC-1.3. + +There also have been reports of problems bootstrapping GCC with some older +releases of xlc-1.2.1, including xlc-1.2.1.8. Newer releases of xlc-1.2.1 +do not exhibit this problem: xlc-1.2.1.28 is known to bootstrap properly. + + + AIX 3.2 common-mode support + +AIX common-mode providing transparent support of both the POWER and PowerPC +architectures is usable in AIX 3.2.3 and above but an export file and +support for hidden export via libc.a will not exist until AIX 4.1. libgcc.a +also must be compiled in common-mode. Note that executables generated for +the POWER (RIOS1 and RSC) architecture will run directly on systems using +the MPC601 chip. Common-mode only improves the performance of a single +executable run on both POWER and PowerPC architecture platforms by not using +POWER- or PowerPC-specific instructions and eliminating the need to trap to +emulation (for POWER instructions run on PowerPC). + +To link a common-mode application prior to AIX 4.1 and run it on a system at +AIX level 3.2.3 or above, use the text between the "<>" as an export file +(e.g. milli.exp) + +<><><><><><><><><><><> +#! +__mulh 0x3100 +__mull 0x3180 +__divss 0x3200 +__divus 0x3280 +__quoss 0x3300 +__quous 0x3380 +<><><><><><><><><><><> + +and then link with -Wl,-bI:milli.exp. + + + AIX 4.1 binder + +Due to changes in the way that GCC invokes the binder (linker) for AIX 4.1, +the link step now may produce warnings of duplicate symbols which were not +reported before. The assembly files generated by GCC for AIX always have +included multiple symbol definitions for certain global variable and +function declarations in the original program. The warnings should not +prevent the linker from producing a correct library or runnable executable. diff --git a/contrib/gcc/README.TRAD b/contrib/gcc/README.TRAD new file mode 100644 index 00000000000..07ccd16437b --- /dev/null +++ b/contrib/gcc/README.TRAD @@ -0,0 +1,55 @@ +This is a partial list of how `gcc -traditional' disagrees with +traditional C compilers (perhaps only some of them). Most of these +differences are not bugs. + +--------------------------------------------------------------------------- +K&R-1 (2.4.3) says: + + "If the character following a backslash is not one of those + specified {in the table above}, the backslash is ignored." + +Up until recently, `gcc -traditional' complained about \x \a and \v +appearing in a character or string literal. I believe however that +this non-feature has been eliminated (recently). + +--------------------------------------------------------------------------- +When in -traditional mode, gcc allows the following erroneous pair of +declarations to appear together in a given scope: + + typedef int foo; + typedef foo foo; + +--------------------------------------------------------------------------- +K&R-1 (8.5) says: + + "No field may be wider than a word." + +Gcc however allows: + + struct S { int i:33; }; + +--------------------------------------------------------------------------- +In K&R-1 there is no restriction against comments crossing include file +boundaries. Gcc however doesn't allow this, even when in -traditional mode. + +--------------------------------------------------------------------------- +Regarding the length of identifiers, K&R-1 (2.2) says: + + "No more than the first eight characters are significant, + although more may be used." + +Gcc treats all characters of identifiers as significant, even when in +-traditional mode. + +--------------------------------------------------------------------------- +K&R-1 (2.2) says: + + "An identifier is a sequence of letters and digits; the first + character must be a letter. The underscore _ counts as a letter." + +Gcc also allows dollar signs in identifiers. (This may also be an issue +for the -pedantic option.) + +--------------------------------------------------------------------------- + + diff --git a/contrib/gcc/README.X11 b/contrib/gcc/README.X11 new file mode 100644 index 00000000000..359dd5f9603 --- /dev/null +++ b/contrib/gcc/README.X11 @@ -0,0 +1,447 @@ +[This file contains two alternative recipes for compiling X11 with GCC. +The first alternative puts libgcc.a into the shared X library; the second +does not. Neither alternative works on all kinds of systems. +It may be that when using GCC 2.4, both alternatives work okay on +relatively recent Sparc systems. The first alternative is likely +not to work on a Sun 3 without hardware floating point.] + +How to compile X11R5 (patch level 11) with GCC version 2: + +The patches include support for building the shared libraries with GCC +2 on the Sparc and 68k machines. This version includes the necessary +parts of libgcc.a in the shared library for X, in case functions in +that library need it. Thus the default behavior is now to build +everything, including the libraries, with gcc. + +If you build the shared library this way, it may not work with +executables made with older versions of GCC (2.3.3 and earlier). +If that happens, relink those executables with the latest GCC. +IF YOU THINK YOU MIGHT COMPILE X FOR SOLARIS 2, then you really don't +need this patch: get /contrib/R5.SunOS5.patch.tar.Z from +export.lcs.mit.edu instead. It has everything you need to do the +build for Solaris 2, sets you up to everything with GCC, and is +backward compatible with Sunos 4.*. Get the the README +(/contrib/R5.SunOS5.patch.README at export) for more info. + +If you see undefined symbols _dlopen, _dlsym, or _dlclose when linking +with -lX11, compile and link against the file mit/util/misc/dlsym.c in +the MIT X11R5 distribution. Alternatively, do dynamic linking +by using a non-GNU ld. + +mit/config/Imake.tmpl -- Do not set -fstrength-reduce if we have GCC 2. +If -fstrength-reduce (or any other -f option) is a major win, then it +will most likely be turned on by -O2 optimization. + +mit/config/sunLib.rules -- If HasGcc and GccVersion > 1 are true, then +use gcc -fpic to generate PIC code. Make sure that gcc does not use +gas (the GNU assembler) when compiling PIC code; gas does not assemble +it correctly. + +***If you have gas installed where gcc uses it by default, you might have +to add -B/bin/ to the PositionIndependentCFlags.*** + +mit/config/site.def -- Define GccVersion to be 2. + +mit/config/sun.cf -- When compiling with GCC 2, use -O2 optimization. + +mit/config/sunLib.rules -- When compiling with GCC 2, use -fpic for +position independent code generation. + +mit/rgb/Imakefile -- No longer need to compile some modules with +cc on the Sparc since GCC 2 produces proper -fpcc-struct-return code. + +mit/server/os/Imakefile -- Likewise. + +mit/server/ddx/sun/Imakefile -- When compiling with GCC 2, some modules +should be compiled with -fvolatile. + +mit/clients/twm/Imakefile -- Fix bad decls of malloc, realloc in gram.c. + +mit/lib/X/Imakefile -- Make libgcc.a a required lib for libX11.so + +*** mit/clients/twm/Imakefile Mon May 17 22:05:22 1993 +--- new/clients/twm/Imakefile Mon May 17 22:28:46 1993 +*************** +*** 32,41 **** +--- 32,48 ---- + ComplexProgramTarget(twm) + InstallNonExecFile(system.twmrc,$(TWMDIR)) + ++ #if HasGcc && GccVersion > 1 && defined (SunArchitecture) + gram.h gram.c: gram.y + yacc $(YFLAGS) gram.y ++ sed -e 's/^extern char \*malloc(), \*realloc();//g' y.tab.c >gram.c ++ $(MV) y.tab.h gram.h ++ #else ++ gram.h gram.c: gram.y ++ yacc $(YFLAGS) gram.y + $(MV) y.tab.c gram.c + $(MV) y.tab.h gram.h ++ #endif + + clean:: + $(RM) y.tab.h y.tab.c lex.yy.c gram.h gram.c lex.c deftwmrc.c +*** mit/config/Imake.tmpl Mon May 17 22:02:57 1993 +--- new/config/Imake.tmpl Mon May 17 22:15:06 1993 +*************** +*** 500,506 **** +--- 500,510 ---- + #endif + #ifndef CcCmd + #if HasGcc ++ #if GccVersion > 1 ++ #define CcCmd gcc -fpcc-struct-return ++ #else + #define CcCmd gcc -fstrength-reduce -fpcc-struct-return ++ #endif + #else + #define CcCmd cc + #endif +*** mit/config/site.def Mon May 17 22:02:44 1993 +--- new/config/site.def Mon May 17 22:22:28 1993 +*************** +*** 25,31 **** + + #ifdef BeforeVendorCF + +! /* #define HasGcc YES */ + + #endif /* BeforeVendorCF */ + +--- 25,33 ---- + + #ifdef BeforeVendorCF + +! #define HasGcc YES +! /* GccVersion > 1 implies building shared libraries with gcc */ +! #define GccVersion 2 + + #endif /* BeforeVendorCF */ + +*** mit/config/sun.cf Mon May 17 22:03:02 1993 +--- new/config/sun.cf Mon May 17 22:24:55 1993 +*************** +*** 41,49 **** +--- 41,55 ---- + + #if HasGcc + ++ #if GccVersion > 1 ++ #define OptimizedCDebugFlags -O2 ++ #else ++ #define OptimizedCDebugFlags -O + #define SharedLibraryCcCmd cc + #define ExtraLoadFlags -B/usr/bin/ + #define AllocateLocalDefines /**/ ++ #endif ++ + + .c.o: + $(CC) -c $(CFLAGS) $*.c +*** mit/config/sunLib.rules Mon May 17 22:02:46 1993 +--- new/config/sunLib.rules Mon May 17 22:19:06 1993 +*************** +*** 23,29 **** +--- 23,33 ---- + #define SharedLibraryLoadFlags -assert pure-text + #endif + #ifndef PositionIndependentCFlags ++ #if defined(HasGcc) && GccVersion > 1 ++ #define PositionIndependentCFlags -fpic ++ #else + #define PositionIndependentCFlags -pic ++ #endif + #endif + + /* +*** mit/lib/X/Imakefile Mon May 17 22:05:03 1993 +--- new/lib/X/Imakefile Mon May 17 22:32:26 1993 +*************** +*** 9,14 **** +--- 9,31 ---- + #define MotifBC NO + #endif + ++ #if defined(SunArchitecture) ++ #if SystemV4 ++ #if HasGcc ++ REQUIREDLIBS= -lgcc -lc ++ #else ++ REQUIREDLIBS= -lc ++ #endif ++ #else ++ #if HasGcc && GccVersion > 1 ++ XCOMM Hack to fix gcc 2 ``-nostdlib'' deficiency on SunOS 4.x ++ REQUIREDLIBS= `gcc -v 2>&1 | awk '{print $$4}' | sed -e 's/specs$$/libgcc.a/'` ++ #else ++ REQUIREDLIBS= ++ #endif ++ #endif ++ #endif ++ + #ifndef BuildXimp + #define BuildXimp NO + #endif +*** mit/rgb/Imakefile Mon May 17 22:05:31 1993 +--- new/rgb/Imakefile Mon May 17 22:25:30 1993 +*************** +*** 17,23 **** + #if !(defined(SGIArchitecture) || SystemV4) + DBMLIB = -ldbm + #endif +! #if defined(SparcArchitecture) && HasGcc + CC = cc + CCOPTIONS = /**/ + EXTRA_LOAD_FLAGS = /**/ +--- 17,23 ---- + #if !(defined(SGIArchitecture) || SystemV4) + DBMLIB = -ldbm + #endif +! #if defined(SparcArchitecture) && HasGcc && GccVersion <= 1 + CC = cc + CCOPTIONS = /**/ + EXTRA_LOAD_FLAGS = /**/ +*** mit/server/ddx/sun/Imakefile Mon May 17 22:05:57 1993 +--- new/server/ddx/sun/Imakefile Mon May 17 22:27:23 1993 +*************** +*** 43,48 **** +--- 43,53 ---- + LinkFile(sunGX.o,sunGX.o.dist) + #endif + ++ #if HasGcc && GccVersion > 1 ++ SpecialObjectRule(sunCG2C.o,sunCG2C.c,-fvolatile) ++ SpecialObjectRule(sunCG2M.o,sunCG2M.c,-fvolatile) ++ #endif ++ + sunInitExtMono.o: $(ICONFIGFILES) + ObjectFromSpecialSource(sunInitExtMono,../mi/miinitext,-UPEXEXT) + ObjectFromSpecialSource(sunInitMono,sunInit,-DMONO_ONLY) +*** mit/server/os/Imakefile Mon May 17 22:05:46 1993 +--- new/server/os/Imakefile Mon May 17 22:26:02 1993 +*************** +*** 132,138 **** + SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES)) + SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES)) + SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES)) +! #if defined(SparcArchitecture) && HasGcc + oscolor.o: $(ICONFIGFILES) + $(RM) $@ + cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c +--- 132,138 ---- + SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES)) + SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES)) + SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES)) +! #if defined(SparcArchitecture) && HasGcc && GccVersion <= 1 + oscolor.o: $(ICONFIGFILES) + $(RM) $@ + cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c + + +[This is the older version] + +How to compile X11R5 (patch level 11) with GCC version 2: + +The patches include support for building the shared libraries with GCC 2 on +the Sparc and 68k machines. + +NOTE: Such shared libraries built with GCC version 2.3 DID NOT WORK +with executables previously linked using Sun CC! This is because +neither those executables nor the gcc-compiled shared libraries contain +libgcc.a. The shared libraries did work with executables linked using +GCC (running the Sun linker, of course) because GCC tells the linker to +link in libgcc.a. Because of these limitations the default behavior is +to NOT build the shared libraries with gcc. + +Changes in GCC 2.4 seem to have eliminated the problem, and such a +shared library now seems work with all executables. If you want the +gcc-compiled shared libraries turn on "Gcc2BuildLibs" in site.def. If +you try this, please tell bug-gcc@prep.ai.mit.edu whether it works. + +Sun forgot to include a static version of libdl.a with some versions +of SunOS (4.1 mainly). If you see undefined symbols _dlopen, _dlsym, +or _dlclose when linking with -lX11, compile and link against the file +mit/util/misc/dlsym.c in the MIT X11R5 distribution. + +mit/config/Imake.tmpl -- Do not set -fstrength-reduce if we have GCC 2. If +-fstrength-reduce (or any other -f option) is a major win, then it will +most likely be turned on by -O2 optimization. + +mit/config/sunLib.rules -- If HasGcc2 and Gcc2BuildLibs are defined, then +use gcc -fpic to generate PIC code. Make sure that gcc does not use gas (the +GNU assembler) when compiling PIC code; gas does not assemble it correctly. +If you have gas installed where gcc uses it by default, you might have to add +-B/bin/ to the PositionIndependentCFlags. + +mit/config/site.def -- Define HasGcc2 to be YES. + +mit/config/sun.cf -- When compiling with GCC 2, use -O2 optimization. + +mit/rgb/Imakefile -- No longer need to compile some modules with +cc on the Sparc since GCC 2 produces proper -fpcc-struct-return code. + +mit/server/os/Imakefile -- Likewise. + +mit/clients/twm/Imakefile -- fix bad decls of malloc, realloc in gram.c. + +*** mit/config/Imake.tmpl.ORIG Tue Dec 31 11:07:56 1991 +--- mit/config/Imake.tmpl Tue Dec 31 12:30:47 1991 +*************** +*** 499,508 **** +--- 499,512 ---- + #define HasGcc NO + #endif + #ifndef CcCmd ++ #if HasGcc2 ++ #define CcCmd gcc -fpcc-struct-return ++ #else + #if HasGcc + #define CcCmd gcc -fstrength-reduce -fpcc-struct-return + #else + #define CcCmd cc ++ #endif + #endif + #endif + #if HasFortran +*** mit/config/sunLib.rules.ORIG Tue Dec 31 11:11:24 1991 +--- mit/config/sunLib.rules Tue May 5 12:26:12 1992 +*************** +*** 23,30 **** +--- 23,34 ---- + #define SharedLibraryLoadFlags -assert pure-text + #endif + #ifndef PositionIndependentCFlags ++ #if defined(HasGcc2) && defined (Gcc2BuildLibs) ++ #define PositionIndependentCFlags -fpic ++ #else + #define PositionIndependentCFlags -pic + #endif ++ #endif + + /* + * InstallSharedLibrary - generate rules to install the shared library. +*** mit/config/site.def.ORIG Tue Dec 31 11:13:49 1991 +--- mit/config/site.def Tue Dec 31 12:02:59 1991 +*************** +*** 25,31 **** + + #ifdef BeforeVendorCF + +! /* #define HasGcc YES */ + + #endif /* BeforeVendorCF */ + +--- 25,33 ---- + + #ifdef BeforeVendorCF + +! #define HasGcc YES +! #define HasGcc2 YES +! /* #define Gcc2BuildLibs YES */ + + #endif /* BeforeVendorCF */ + +*** mit/config/sun.cf.ORIG Tue Dec 31 11:13:57 1991 +--- mit/config/sun.cf Tue May 5 12:29:50 1992 +*************** +*** 34,42 **** +--- 41,61 ---- + + #if HasGcc + ++ #if defined(HasGcc2) ++ #define OptimizedCDebugFlags -O2 ++ /* Leave Alone XXX */ ++ #else ++ #define OptimizedCDebugFlags -O + #define SharedLibraryCcCmd cc + #define ExtraLoadFlags -B/usr/bin/ + #define AllocateLocalDefines /**/ ++ #endif ++ ++ #if !defined(Gcc2BuildLibs) ++ #define SharedLibraryCcCmd cc ++ #define ExtraLoadFlags -B/usr/bin/ ++ #define AllocateLocalDefines /**/ ++ #endif + + .c.o: + $(CC) -c $(CFLAGS) $*.c +*** mit/rgb/Imakefile.ORIG Wed Jan 15 16:43:18 1992 +--- mit/rgb/Imakefile Thu Jan 2 13:34:09 1992 +*************** +*** 17,23 **** + #if !(defined(SGIArchitecture) || SystemV4) + DBMLIB = -ldbm + #endif +! #if defined(SparcArchitecture) && HasGcc + CC = cc + CCOPTIONS = /**/ + EXTRA_LOAD_FLAGS = /**/ +--- 17,23 ---- + #if !(defined(SGIArchitecture) || SystemV4) + DBMLIB = -ldbm + #endif +! #if defined(SparcArchitecture) && HasGcc && !defined(HasGcc2) + CC = cc + CCOPTIONS = /**/ + EXTRA_LOAD_FLAGS = /**/ +*** mit/server/os/Imakefile.ORIG Wed Jan 15 16:46:23 1992 +--- mit/server/os/Imakefile Wed Jan 15 16:46:48 1992 +*************** +*** 132,138 **** + SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES)) + SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES)) + SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES)) +! #if defined(SparcArchitecture) && HasGcc + oscolor.o: $(ICONFIGFILES) + $(RM) $@ + cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c +--- 132,138 ---- + SpecialObjectRule(osinit.o,$(ICONFIGFILES),$(ADM_DEFINES)) + SpecialObjectRule(WaitFor.o,$(ICONFIGFILES),$(EXT_DEFINES)) + SpecialObjectRule(fonttype.o,$(ICONFIGFILES),$(FONT_DEFINES)) +! #if defined(SparcArchitecture) && HasGcc && !defined(HasGcc2) + oscolor.o: $(ICONFIGFILES) + $(RM) $@ + cc -c $(DBM_DEFINES) $(CDEBUGFLAGS) $(ALLDEFINES) $*.c +*** 1.1 1992/09/08 19:52:07 +--- mit/server/ddx/sun/Imakefile 1992/09/08 21:10:22 +*************** +*** 43,48 **** +--- 43,53 ---- + LinkFile(sunGX.o,sunGX.o.dist) + #endif + ++ #if HasGcc2 ++ SpecialObjectRule(sunCG2C.o,sunCG2C.c,-fvolatile) ++ SpecialObjectRule(sunCG2M.o,sunCG2M.c,-fvolatile) ++ #endif ++ + sunInitExtMono.o: $(ICONFIGFILES) + ObjectFromSpecialSource(sunInitExtMono,../mi/miinitext,-UPEXEXT) + ObjectFromSpecialSource(sunInitMono,sunInit,-DMONO_ONLY) + +*** /tmp/RCSAa24446 Tue Sep 15 12:23:32 1992 +--- mit/clients/twm/Imakefile Thu Aug 13 18:18:07 1992 +*************** +*** 32,41 **** +--- 32,48 ---- + ComplexProgramTarget(twm) + InstallNonExecFile(system.twmrc,$(TWMDIR)) + ++ #if HasGcc2 && defined (SunArchitecture) + gram.h gram.c: gram.y + yacc $(YFLAGS) gram.y ++ sed -e 's/^extern char \*malloc(), \*realloc();//g' y.tab.c >gram.c ++ $(MV) y.tab.h gram.h ++ #else ++ gram.h gram.c: gram.y ++ yacc $(YFLAGS) gram.y + $(MV) y.tab.c gram.c + $(MV) y.tab.h gram.h ++ #endif + + clean:: + $(RM) y.tab.h y.tab.c lex.yy.c gram.h gram.c lex.c deftwmrc.c + diff --git a/contrib/gcc/SERVICE b/contrib/gcc/SERVICE new file mode 100644 index 00000000000..11e266a33c2 --- /dev/null +++ b/contrib/gcc/SERVICE @@ -0,0 +1,852 @@ + -*- text -*- +GNU Service Directory +--------------------- + +This is a list of people who have asked to be listed as offering +support services for GNU software, including GNU Emacs, for a fee +or in some cases at no charge. + +The information comes from the people who asked to be listed; +we do not include any information we know to be false, but we +cannot check out any of the information; we are transmitting it to +you as it was given to us and do not promise it is correct. +Also, this is not an endorsement of the people listed here. +We have no opinions and usually no information about the abilities of +any specific person. We provide this list to enable you to contact +service providers and decide for yourself whether to hire one. + +Before FSF will list your name in the GNU Service Directory, we ask +that you agree informally to the following terms: + +1. You will not restrict (except by copyleft) the use or distribution +of any software, documentation, or other information you supply anyone +in the course of modifying, extending, or supporting GNU software. +This includes any information specifically designed to ameliorate the +use of GNU software. + +2. You will not take advantage of contact made through the Service +Directory to advertise an unrelated business (e.g., sales of +non-GNU-related proprietary information). You may spontaneously +mention your availability for general consulting, but you should not +promote a specific unrelated business unless the client asks. + +Please include some indication of your rates, because otherwise users +have nothing to go by. Please put each e-mail address inside "<>". +Please put nothing else inside "<>". Thanks! + +For a current copy of this directory, or to have yourself listed, ask: + gnu@prep.ai.mit.edu + +** Please keep the entries in this file alphabetical ** + + +Joseph Arceneaux +PO Box 460633 http://www.samsara.com/~jla +San Francisco, CA 94146-0633 ++1 415 648 9988 ++1 415 285 9088 + +Recently led the project making Wells Fargo Bank the first to provide +secure customer account access over the Internet. + +Former FSF staffmember. Performed X11 implementation of Emacs version +19, designed and implemented WYSIWYG Emacs. Installed and +administered FSF network. Maintainer of GNU indent. Over 15 years +experience with Unix and other systems, from writing ROM monitors to +UI design and system administration. + +I provide installation, porting, debugging and customization or +development of GNU and other Unix software. I also design and +implement free software projects and consult on software engineering +and systems design. Handholding and teaching services are also +available as well as things like LAN and compute--infrastructure design. + +Time and material rates around $150 USD per hour, depending upon the +particular job. I am also very interested in fixed-bid jobs. For +selected non-profit organizations with worthy goals, I work for free. + +Updated: 17Oct95 + +Gerd Aschemann +Osannstr. 49 +D-64285 Darmstadt +Tel.: +49 6151 16 2259 +http://www.informatik.th-darmstadt.de/~ascheman/ + +- System Administrator (UNIX) at CS Department, TU Darmstadt, Germany +- 15 years expirience with CS, Systemadministration on different platforms +- 8 years with UNIX/Networking/FreeWare/GNU/X11 +- 6 years organizer of Operating Systems and Distributed Systems courses +- Lectures on System and Network Administration +- Platforms: Solaris, SunOS, Ultrix, OSF1, HP-UX, Linux, FreeBSD, AIX +- Experience with parallel environments (Connection Machine, Meiko, Parsytec) +- Consultant for other UNIX users at TU Darmstadt + +Rates are at 100,-- DM (~60 US$) per hour minimum, depending on the job. +I am willing to travel for sufficiently large jobs. + +Updated: 17Oct95 + +Giuseppe Attardi +Dipartimento di Informatica +Corso Italia 40 +I-56125 Pisa, Italy ++39 50 887-244 + +GNU: help on obtaininig GNU, for italian sites. + +Updated: 5Apr94 + +James Craig Burley +97 Arrowhead Circle +Ashland, MA 01721-1987 +508 881-6087, -4745 +(Please call only between 0900-1700 Eastern time, and only if you +are prepared to hire me -- ask me to help you for free only +via email, to which I might or might not respond.) +Email: --preferred-- + + + +Expertise: + Compiler Internals (author of GNU Fortran, for example) + Operating Systems Internals + Tools/Utilities Development and Maintenance + Microcode Development and Maintenance (primarily VLIW machines) + System Design (computers, operating systems, toolsets, &c) + Debugging (often asked to help debug Other People's Code) + Documentation (authored many books and ran a few doc projects) + Extensive experience with a variety of operating systems, hardware, + languages, and so on + +Rate: $70/hour -- willing to consider flat-fee arrangements + +Updated: 14Aug95 + +Michael I. Bushnell +545 Technology Square, NE43-426 +Cambridge, MA 02139 +(617) 253-8568 + +All GNU software: Installation, customization, answering simple or + complex questions, bug fixing, extension. + +Experience: I have done Unix and GNU programming for several years, + I am the primary author of the Hurd (which provides most + kernel related facilities for the GNU OS). + +I am easily available in the Cambridge/Boston area; work via email. +I am willing to travel for sufficiently large jobs. + +Rates: $100/hr, negotiable, less for non-profit organizaions. + +Updated: 5Apr94 + +C2V Renaud Dumeur +82 bd Haussmann Michel Delval +75009 Paris Jean-Alain Le Borgne +France +Tel (1) 40.08.07.07 +Fax (1) 43.87.35.99 + +We offer source or source+binary distribution, installation, training, +maintenance, technical support, consulting, specific development and +followup on the GNU software development environment: Emacs, gcc/g++, +binutils, gas, gdb. + +Experience: adapted gcc, gas and binutils to work as cross-development +tools for the Thomson st18950 DSP chip: GCC parser and typing system +have been augmented to allow the manipulation of variables located in +separated memory spaces. Porting on new platforms, and professionally +developing software with the GNU tools in the Unix/X11 environment +since they were first available. + +Rates: from 2000 FF/day to 150 000 FF/year, 40% discount for +educational institutions, add taxes and expenses. Ask for list. + +Entered: 5May94 + +Contributed Software +Graefestr. 76 +10967 Berlin, Germany +phone: (+49 30) 694 69 07 +FAX: (+49 30) 694 68 09 +modems: (+49 30) 694 60 55 (5xZyXEL ) +modems: (+49 30) 693 40 51 (8xUSR DS) +email: +internet: uropax.contrib.de [192.109.39.2], login as 'guest'. + +We distribute, install, port, teach and support free software +in general, i.e. X11, GNU, khoros etc. Rates are ECU 80,-- plus +tax per hour. We offer maintenance and support contracts for full +customer satisfaction. +Highlights are transparent development environments for multi-platform +sites and configuration management. Traveling is no problem. + +Free Archive login for downloading on above modem numbers. + +Updated: 5Apr94 + +Stuart Cracraft +25682 Cresta Loma +Laguna Niguel, Ca. +92677 +GNUline: 714-347-8106 +Rate: $75/hour +Consultation topics: + Entire GNU suite - porting, compilation, installation, + user-training, administrator-training +Method: telephone line support, call-in via modem to your site, +or direct visit. + +Experience: supporting GNU since the mid-1980's, coordinator +of GNU Chess (original author), GNU Shogi, GNU Go. Ported GNU Emacs +to Solaris (System V Release 4). Expertise in C, Emacs Lisp, and Perl. +Customized programming also available. + +Entered: 5Apr94 + +Cygnus Support +1937 Landings Drive ...uunet!cygint!info +Mountain View, CA 94043 USA ++1 415 903 1400 voice ++1 415 903 0122 fax + +Cygnus Support +48 Grove Street +Somerville, MA 02144 ++1 617 629 3000 voice ++1 617 629 3010 fax + +Cygnus Support continues to provide supported, maintained versions of +the GNU toolset including GCC, G++, the GNU debugger with graphical +user interface, GNU linker, GNU macro-assembler and Emacs 19. In +keeping with the rapidly advancing needs of software developers, +Cygnus maintains a 90 day release cycle of the GNU toolset. Each +release is regression tested and includes substantial improvements and +additions to the existing matrix of over 65 supported platform +configurations. + +Updated: 2Feb95 + +Free Software Association of Germany +Michaela Merz +Heimatring 19 +6000 Frankfurt/Main 70 +phone: (+49 69) 6312083) +ert : (+49-172-6987246) +email: (info@elara.fsag.de) + +Supporting all kinds of freeware (i.e. GNU), freeware development, consulting, +training, installation. Special LINUX support group. + +RATES: + +Companies and for profit +organizations : 100 US$ / hour +Private and not-for-profit +organizations : 40 US$ / hour +ert (24h Emergency +response team) : 300 US$ / hour + +Entered: 14Apr94 + +Noah Friedman +Building 600, Suite 214 2002-A Guadalupe St. #214 +One Kendall Square Austin, TX 78705 +Cambridge, MA 02139 (Local, faster to reach me) +(Permanent) + + +Author of several Emacs Lisp packages and parts of Emacs 19, as well as +numerous utilities written in shell script and perl. Co-maintained GNU +Texinfo and Autoconf for a couple of years. System administrator for a +network of heterogenous machines. FSF employee Feb 1991--Sep 1994. + +I can perform installation, porting, and enhancement of all GNU software +and any other free software; system administration for unix-type systems +and ethernet networks; and I am willing to teach shell programming and +Emacs Lisp. + +Fees negotiable, averaging $60-$75/hour. I can work in the Austin, TX area +or anywhere accessible on the Internet. For larger jobs I may be willing +to travel. + +Updated: 16Aug95 + +Ronald F. Guilmette +Infinite Monkeys & Co. +1751 East Roseville Pkwy. #1828 +Roseville, CA 95661 +Tel: +1 916 786 7945 +FAX: +1 916 786 5311 + +Services: Development & porting of GNU software development tools. + +GNU Contributions: + Invented, designed, and implemented the protoize and + unprotoize tools supplied with GCC2. + + Designed and developed all code to support the generation + of Dwarf symbolic debugging information for System V Release + 4 in GCC2. + + Performed original port of GNU compilers to SVr4 system. + + Finished port of GNU compilers to Intel i860 RISC + processor. + +Experience: 13+ years UNIX systems experience, all working on compilers + and related tools. + + 7+ years working professionally on GCC, G++, and GDB under + contract to various firms including the Microelectronics + and Computer Technology Corporation (MCC), Data General (DG), + Network Computing Devices (NCD), and Intel Corp. + +Other qualifications: + Developer of the RoadTest (tm) C and C++ commercial + compiler test suites. + + Former vice-chairman of UNIX International Programming + Languages Special Interest Group (UI/PLSIG). + + Bachelor's and a Master's degrees, both in Computer Science. + +Rates: Variable depending upon contract duration. Call for quote. + +Updated: 23Sep95 + +Hundred Acre Consulting +1155 W Fourth St Ste 225 +PO Box 6209 +Reno NV 89513-6209 +(702)-348-7299 +Hundred Acre is a consulting group providing support and development +services to organizations of all sizes. We support GNU C++ and C in +particular, but also provide support for all other GNU software and +certain non-GNU public domain software as well. We work on a "service +contract" basis for support -- for a yearly fee, we provide multiple +levels of email and toll free telephone support, and free updates and +bug fixes. The highersupport levels have on-site support. Development +is charged on either an hourly or fixed bid basis. + +Consulting rates: $70 to $90 per hour, or fixed bid. +Support contracts: Several levels, from $495 to $90000 per year. + +Updated: 27Dec94 + +Interactive Information Limited + +Interactive Information Limited is an Edinburgh-based company that +specialises in WWW services and support for using the Internet for +marketing. + +Our staff have many years experience in using, and developing lisp packages +within, Emacs, and in using other GNU/Unix tools, particularly under public +domain UNIXes. + +We can provide services throughout the UK, at any level from general +consultancy through fetching, installing and customising software to +bespoke programming. Fees would be in the range #300 - #600 per day, +depending primarily on the size of the job. + +You can contact us + by email: + by phone: 0370 30 40 52 (UK) + (+44) 370 30 40 52 (International) + by post: 3, Lauriston Gardens, + Edinburgh EH3 9HH + Scotland + +Entered: 13Nov95 + +Scott D. Kalter + : Dennis Fitzgerald + +Kaman Sciences has performed a GNU port for a custom RISC processor. +We have experience in the definition and description of the machine +register transfer language to the GNU tool-set. This includes rewriting +and modification of the necessary description and source files of gcc, gas, +and gld and other binutils. Kaman also has services for installation and +setup of GNU tools, (GAWK, GCC, EMACS, etc.) on Sun workstations. + +Work is on a "service contract" basis and development is charged either +hourly or as a fixed price contract. + +Consulting rates: $70 to $200 per hour. + +Entered: 13Jan95 + +Scott J. Kramer +P.O. Box 620207 +Woodside, CA 94062 ++1 415-941-0755 + +GNU Software: Tutoring, installations/upgrades, Emacs Lisp customizations, + general troubleshooting/support. Prefer that work I do + becomes part integrated into official Free Software Foundation + distributions. + +Systems Administration: Sun (SunOS & Solaris) and SGI (IRIX) + UNIX hardware/software platforms. + +Rate: Task- and time-dependent; non-monetary offers accepted. + +Updated: 12Apr94 + +Fen Labalme + +Services: Supply, porting, installation, consultation on all GNU +products. + +Experience: 20 years OS and compiler experience, portations of most +GNU products. Author of ported software CD-ROM for Unix 4.2. + +Rates: Choice of DM 150 per hour or hotline rates 3 DM per minute + 10 +DM per phone call. Quick questions may be free. Limited free support +available for purchasers of LEMIS CD-ROMs. + +Updated: 21Feb95 + +Marty Leisner +332 Shaftsbury Road +Rochester, New York 14610 +Home:(716) 654-7931 + +Experience: 12 years C/Unix, 7 years DOS. + Extensive experience with GNU binary tools, cross-compilers, + embedded/hosted systems, realtime. +Degree : BS CS, Cornell University +Rates: $75/hr + + + +marty + + +Updated: 15Apr94 + +Richard Levitte (in TeX: Richard Levitte +Södra Långgatan 39, II S\"odra L{\aa}nggatan 39, II +S-171 49 Solna S-171 49 Solna +Sweden Sweden) +Tel.nr.: +46 (8) 18 30 99 (there is an answering machine) +e-mail: (preferred) + + +What I do: + Primarly I work on GNU software for VMS, both VAX and AXP. I + also work on GNU stuff for Unix on occasion. I'm familiar with + SunOS (version 4.x.x), BSD (version 4.2 and up), + Ultrix (version 4.2 and up). + I've been porting GNU Emacs to VMS since spring 1991. This + includes versions 18.57 to 18.59 and version 19.22. + I maintain GNU vmslib. + +Programs supported: + GNU vmslib: extending, installation, upgrading aid, + simple and complex questions, you name it. + GNU Emacs: porting, extending, installation, upgrading aid, + customization, simple or complex questions, + training, you name it. + GNU autoconf: porting, extending, installation, upgrading aid. + GNU zip, diffutils, m4, patch, texinfo: + porting, installation, upgrading aid. + GNU C/C++: installation, upgrading aid. I might start to + hack at it some day. + +The list of programs I currently support represents both my interests and +current priorities. Your interest and funding can influence my priorities. + +Experience: + Fluent in C, C++, Emacs Lisp, Pascal as well as assembler + on VAX, Motorola 680x0, Intel 8086 and 80x86. Modified key + elements in Emacs (e.g., memory and process management) to work + transparently on VMS. I have very good knowledge in the VMS + operating system, as well as MS-DOS and IBM PC compatibles. + I have worked for four and a half years as a VMS system manager. + I've also provided consulting services on IBM PC compatibles, + as well as held classes for IBM PC users. + A reference list is available on request. + +Your Rate: + $50-$80/hour (400-700 SEK in sweden), plus expenses. My rates + are negotiable, depending on how interesting the project is to me. + + +Entered: 18Aug94 + +Roland McGrath +545 Tech Sq, Rm 426 +Cambridge, MA 02139 +Work: (617) 253-8568 + +Co-author of GNU Make (with Richard Stallman); maintainer of GNU Make. +Author and maintainer of the GNU C Library and co-author of the GNU Hurd. +Author of several GNU Emacs Lisp packages and parts of GNU Emacs 19. +FSF employee summer 1989, fall 1990 to the present. + +Installation, maintenance, porting, enhancement of all GNU software. I can +install GNU software and maintain its installation on call via the Internet. + +Fees negotiable; $75-$100/hour, higher for very short term projects. I can +work anywhere in the Boston or SF Bay Area, or anywhere on the Internet. I +am working full-time for the FSF on the GNU Hurd, so I am likely to take on +only jobs that either can be done entirely via the Internet and are +short-term, or that are very interesting. + +Updated: 21Jan95 + +Wolfgang S. Rupprecht +47 Esparito Ave. +Fremont, CA 94539-3827 +(510) 659-9757 + +Anything, (lisp, C, customization, porting, installing) I have +written thousands of lines of GNU Emacs C and Lisp code. Original +author of the floating point additions in Emacs 19. + +Rates: $95/hr. + +Updated: 14Apr94 + +Signum Support AB +Box 2044 _ ...!seunet!signum!info +S-580 02 Linkoping, Sweden ++46 13 21 46 00 voice ++46 13 21 47 00 fax + +Signum Support AB is a company dedicated to supporting, developing +and distributing free software for, including but not limited to, +UNIX systems. The people behind Signum Support AB have many years +of general UNIX experience, both as system administrators and as +programmers, and also extensive experience in maintaining the GNU +programs, both administrating it and finding and fixing bugs. + +Services offered: + + - Installation and customizing GNU and other free software. We will + make free software as easy to install and use as shrink wrapped + programs. + - Warranty protection. + - Customization and porting. + - Subscriptions to new versions which we will send monthly or with + any other interval. + - Finding, Recommending and Investigation of free software in any + area of the customers choise. + - Regular consulting. + +Rates: For software items, request our price list. + For consulting, 400-800 SEK/hour. + +Updated: 14Apr94 + +Small Business Systems, Inc. +Box 17220, Route 104 +Esmond, RI 02917 +401.273.4669 + +Rate: Varies depending on complexity of task. + Hourly and fixed-rate contracts are available. +Programs Supported: All + +Updated: 14Apr94 + +Julian H. Stacey. +Vector Systems Ltd, Holz Strasse 27d, D 80469 Munich (Muenchen), GERMANY. +Tel. +49 89 268616 (089 268616 in Germany) 09:00-21:00 Timezone=GMT+01:00 + +Sources: All FSF/GNU, FreeBSD-current, X-Windows, XFree86, NetBSD, Mach, etc. + (Plus various other things, such as, but not limited to: + blas blt cflow CAD cnews crypt dvi2lj eispack elm encryption expect + ezd f2c flexfax gic gopher info-zip ingres inn jpeg kermit ksh + less lha linpack md5 mh mprof mtools mush nntp octave pbmplus + popper sather sc schemetoc slurp sml spreadsheet sup tcl tcl-dp + tcsh tcx term tex tiff tk top trn unarj ups urt wine xlock xv + xview xxgdb zmodem zip zircon zoo zsh.) +Media: QIC 1/4" Cartridge 525M, 150M, & 60M, TEAC CAS-60 60M Cassette, + CD-ROM, Floppies 1.4M & 1.2 & 720K & 360K. DAT arrangeable. + Postal Service C.O.D.(=`Nachnahme') or pre payment available. +Commercial Consultancy: + Custom Designs, Provision & support of FreeBSD or Unix, C, FSF tools, + X Windows, own tools, systems engineering, hardware interfacing, + multi lingual European, Cyrillic & Chinese tools & systems, + Unix, MSDOS, real time etc, communications & scientific & industrial. +DEUTSCH + FRANCAIS: + Man kann mir in Deutsch schreiben, (oder mich anrufen). + Je comprend Francais, mais je n'ecris pas des responses en Francais. + (Contact me in English, German, or French). +FREE for Symmetric Computer Systems Model 375 owners: + Free Binaries & sources on SCS/375's TEAC 50/60M Cassette, for: + GCC-1.40, UUCP-1.4, Ghostscript 2.3, Tar-1.08, Gzip-1.2.2 etc. + (Native SCS compiler can't compile GCC on this NSC32016 based BSD4.2) +On Request: Resume, Company Profile, Index of public & proprietary tools, +Rate: ~120 DM/hour. ~100DM/Cartridge. (1.5DM = $1 USA = 0.6 UK Pounds @4/'94) +Short enquiries free. (Kurze Anfragen Ohne Gebuhr). + +Updated: 14Jun94 + +Richard M. Stallman +UUCP: {mit-eddie,ucbvax,uunet,harvard,uw-beaver}!ai.mit.edu!rms +545 Tech Sq, Rm 430 +Cambridge, MA 02139 + +Emacs: anything whatever +Is anyone interested in courses in using or extending GNU Emacs? + +Original inventor of Emacs and main author of GNU Emacs and GCC. + +Rates: $6/min or $250/hr. + +Updated: 14Apr94 + +JoS-Ware Comp Tech Johan Svensson +Box 739 +220 07 LUND +SWEDEN +Tel +46-46-104505 (Dept. of Economics, University of LUND) +Fax +46-46-188445 (JoS-Ware Comp Tech) + +What: We offer consulting services regarding installation, + customization, troubleshooting, porting and integration + of all free software, including GNU software. + +Spec.: Network integration, integration of public domain software + into commercial systems, WorldWideWeb, C, X-Windows, Linux, + networked information systems + +How: Remote login over internet, email, modem, phone, personal + visits (in southern Sweden mainly) + +Rates: 550SEK (+ tax) per hour within Sweden + 370SEK (+ tax) per hour within Sweden for educational org. + US $90 per hour outside Sweden + US $70 per hour outside Sweden for educational org. + Note: fees may vary and special arrangements may be considered + +Entered: 7Apr94 + +Kayvan Sylvan +Sylvan Associates +879 Lewiston Drive +San Jose, CA 95136 +Phone: 408-978-1407 + +I will help you port, install and customize GNU Emacs, GCC, G++, +bison, and other GNU tools on almost any architechture and operating +system. Questions answered. GNU C and lisp hacking available. I will +also do ongoing support and periodic upgrades if you get on my GNU +software subscription list. + +Rates: $60-$100/hour, depending on type of work. Substantial discounts +for long-term contracts and also for educational or non-profit +institutions. + +Experience: Many different Unix systems (2.9BSD to 4.4BSD, SVR3 and +SVR4, Linux, Xenix). Systems programming and system administration on all +brands of Unix. Kernel hacking experience. Lots of porting experience. +I can port anything to anything (within reason). + +Updated: 14Apr94 + +Leonard H. Tower Jr. +36 Porter Street +Somerville, MA 02143, USA ++1 (617) 623-7739 + +Will work on most GNU software. +Installation, handholding, trouble shooting, extensions, teaching. + +Rates: 100.00/hour + travel expenses. Negotiable for non-profits. + +Experience: Have hacked on over a dozen architectures in many languages. Have +system mothered several varieties of Unixes. Assisted rms with the front end +of gcc and it's back-end support. Resume available on request. + +Entered: 14Apr94 + +UrbanSoft AO +68 Malooktinskii Prospect +St. Petersburg, Russia 195272 + +Custom GhostScript and TeX programming by e-mail. +Database documents, directories, standard forms. + +UrbanSoft uses a portion of its revenues to contribute +diskette distributions of GNU software to Russian +universities (most of which lack FTP access). + +Rates: 30,000 rubles (currently USD 16.80) per hour. + Fixed rate contracts also possible. + Payable by bank transfer. + +Updated: 20Apr94 + +noris network +Matthias Urlichs +Schleiermacherstrasse 12 +90491 Nuernberg +Germany +Phone: +49 911 9959621 +Fax: +49 911 5980150 + +http://info.noris.de/ (German) + +Expertise: + OS internals, esp. Linux and BSD, esp. device drivers + Network protocol / program design and coding + Utilities coding and maintainance + Program debugging, testing + User interface design and testing + Several programming and tool languages + +Services: + Installation, debugging, enhancement, distribution, + for all kinds of free software. + System administration for most Unix-like systems. + Email, Fax, phone, and in-person consulting (and/or "question answering"). + Remote support and system monitoring (over the Internet), + Update service (new tools tested and installed automagically) + Internet access + +Rates: + DM 110 (~$70) per hour + Support contracts start at DM 170/month + DM 30/supported system. + Willing to travel for sufficiently large jobs. + Rates don't include taxes. + +Entered: 16Aug94 + +Joe Wells +Postal Address: + care of: Boston University Computer Science Department + 111 Cummington Street, Room 138 + Boston, Massachusetts 02215 +Work Telephone: (617) 353-3381 (sorry, but no answering machine or voice mail) +Home Telephone: (617) 739-7456 (until August 1995) +Finger "jbw@cs.bu.edu" for up-to-date contact information. + +Experience: + I have B.A. and M.A. degrees in Computer Science and have completed + all but the dissertation for a Ph.D. in C.S. My research for my + Ph.D. is in the areas of logic, type systems, and programming + language theory. My primary programming languages are Emacs Lisp, + Perl, and Bourne shell, but of course I can program in any language. + I have written numerous Emacs Lisp packages. I started the USENET + "List of Frequently Asked Questions about GNU Emacs with Answers" and + maintained it for more than two years. Most of my work has been + related to the telephone system (modems, voice mail, etc.), but I am + not limited to that. Send e-mail for my complete resume or curriculum + vita. + +Programs supported: + GNU Emacs and Taylor UUCP: + Installation, training, customization, bug fixing, troubleshooting, + extension, development, porting, or answering any kind of question. + Any other GNU program: + The same things, but I don't necessarily have huge amounts of + experience with the particular program. + +Working conditions: + I am usually available for part-time work (less than 20 hours per week + including any travel time). I can sometimes make time for full-time + work for a month or two; please inquire. I can either work in or near + Boston or via the Internet or via telephone; travel outside the Boston + metropolitan area can be negotiated. My schedule is very flexible. + Any programs I write will normally have the copying conditions of the + GNU General Public License; this is negotiable. + +Rates: $65/hour as an independent contractor. + travel and telephone expenses. + higher rates if extensive travel is required. + +Updated: 27Sep94. + +Herb Wood +phone: 1-415-789-7173 +email: + +I'm a better "planner" than I am a hacker. A really good hacker will be able +to keep many pieces of information in their short-term memory and to memorize +new pieces of information at a fast rate. This is not my strong point. +Rather, I excel in domains that require knowledge of the slightly more +theoretical parts of computer science --for example, logic, formal methods of +program development, and functional programming. I can write, and I have +"tutoring" (teaching one-on-one) experience, an, unlike some programmers, +I enjoy doing these things. + +I have spend a lot of time looking at the Emacs Lisp sources and customizing +Emacs and VM. I think I can customize Emacs and its packages quickly and +effectively. + +Entered: 30Jul95 + +Yggdrasil Computing, Inc./ Freesoft, Inc. +4880 Stevens Creek Blvd. Ste. 205 +San Jose, CA 95129 +(408) 261-6630 +(800) 261 6630 + +Updated: 14Apr94 + + +For a current copy of this directory, or to have yourself listed, ask: + gnu@prep.ai.mit.edu + +** Please keep the entries in this file alphabetical ** diff --git a/contrib/gcc/TESTS.FLUNK b/contrib/gcc/TESTS.FLUNK new file mode 100644 index 00000000000..04641e3c8fb --- /dev/null +++ b/contrib/gcc/TESTS.FLUNK @@ -0,0 +1,39 @@ +This is a collection of things that test suites have +said were "wrong" with GCC--but that I don't agree with. + +First, test suites sometimes test for compatibility with +traditional C. GCC with -traditional is not completely +compatible with traditional C, and in some ways I think it +should not be. + +* K&R C allowed \x to appear in a string literal (or character +literal?) even in cases where it is *not* followed by a sequence of +hex digits. I'm not convinced this is desirable. + +* K&R compilers allow comments to cross over an inclusion boundary (i.e. +started in an include file and ended in the including file). +I think this would be quite ugly and can't imagine it could +be needed. + +Sometimes tests disagree with GCC's interpretation of the ANSI standard. + +* One test claims that this function should return 1. + + enum {A, B} foo; + + func (enum {B, A} arg) + { + return B; + } + +I think it should return 0, because the definition of B that +applies is the one in func. + +* Some tests report failure when the compiler does not produce +an error message for a certain program. + +ANSI C requires a "diagnostic" message for certain kinds of invalid +programs, but a warning counts as a diagnostic. If GCC produces +a warning but not an error, that is correct ANSI support. +When test suites call this "failure", the tests are broken. + diff --git a/contrib/gcc/alloca.c b/contrib/gcc/alloca.c new file mode 100644 index 00000000000..7020f32c882 --- /dev/null +++ b/contrib/gcc/alloca.c @@ -0,0 +1,492 @@ +/* alloca.c -- allocate automatically reclaimed memory + (Mostly) portable public-domain implementation -- D A Gwyn + + This implementation of the PWB library alloca function, + which is used to allocate space off the run-time stack so + that it is automatically reclaimed upon procedure exit, + was inspired by discussions with J. Q. Johnson of Cornell. + J.Otto Tennant contributed the Cray support. + + There are some preprocessor constants that can + be defined when compiling for your specific system, for + improved efficiency; however, the defaults should be okay. + + The general concept of this implementation is to keep + track of all alloca-allocated blocks, and reclaim any + that are found to be deeper in the stack than the current + invocation. This heuristic does not reclaim storage as + soon as it becomes invalid, but it will do so eventually. + + As a special case, alloca(0) reclaims storage without + allocating any. It is a good idea to use alloca(0) in + your main control loop, etc. to force garbage collection. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef emacs +#include "blockinput.h" +#endif + +/* If compiling with GCC 2, this file's not needed. */ +#if !defined (__GNUC__) || __GNUC__ < 2 + +/* If someone has defined alloca as a macro, + there must be some other way alloca is supposed to work. */ +#ifndef alloca + +#ifdef emacs +#ifdef static +/* actually, only want this if static is defined as "" + -- this is for usg, in which emacs must undefine static + in order to make unexec workable + */ +#ifndef STACK_DIRECTION +you +lose +-- must know STACK_DIRECTION at compile-time +#endif /* STACK_DIRECTION undefined */ +#endif /* static */ +#endif /* emacs */ + +/* If your stack is a linked list of frames, you have to + provide an "address metric" ADDRESS_FUNCTION macro. */ + +#if defined (CRAY) && defined (CRAY_STACKSEG_END) +long i00afunc (); +#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg)) +#else +#define ADDRESS_FUNCTION(arg) &(arg) +#endif + +#if __STDC__ +typedef void *pointer; +#else +typedef char *pointer; +#endif + +#define NULL 0 + +/* Different portions of Emacs need to call different versions of + malloc. The Emacs executable needs alloca to call xmalloc, because + ordinary malloc isn't protected from input signals. On the other + hand, the utilities in lib-src need alloca to call malloc; some of + them are very simple, and don't have an xmalloc routine. + + Non-Emacs programs expect this to call use xmalloc. + + Callers below should use malloc. */ + +#ifndef emacs +#define malloc xmalloc +#endif +extern pointer malloc (); + +/* Define STACK_DIRECTION if you know the direction of stack + growth for your system; otherwise it will be automatically + deduced at run-time. + + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ + +#ifndef STACK_DIRECTION +#define STACK_DIRECTION 0 /* Direction unknown. */ +#endif + +#if STACK_DIRECTION != 0 + +#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */ + +#else /* STACK_DIRECTION == 0; need run-time code. */ + +static int stack_dir; /* 1 or -1 once known. */ +#define STACK_DIR stack_dir + +static void +find_stack_direction () +{ + static char *addr = NULL; /* Address of first `dummy', once known. */ + auto char dummy; /* To get stack address. */ + + if (addr == NULL) + { /* Initial entry. */ + addr = ADDRESS_FUNCTION (dummy); + + find_stack_direction (); /* Recurse once. */ + } + else + { + /* Second entry. */ + if (ADDRESS_FUNCTION (dummy) > addr) + stack_dir = 1; /* Stack grew upward. */ + else + stack_dir = -1; /* Stack grew downward. */ + } +} + +#endif /* STACK_DIRECTION == 0 */ + +/* An "alloca header" is used to: + (a) chain together all alloca'ed blocks; + (b) keep track of stack depth. + + It is very important that sizeof(header) agree with malloc + alignment chunk size. The following default should work okay. */ + +#ifndef ALIGN_SIZE +#define ALIGN_SIZE sizeof(double) +#endif + +typedef union hdr +{ + char align[ALIGN_SIZE]; /* To force sizeof(header). */ + struct + { + union hdr *next; /* For chaining headers. */ + char *deep; /* For stack depth measure. */ + } h; +} header; + +static header *last_alloca_header = NULL; /* -> last alloca header. */ + +/* Return a pointer to at least SIZE bytes of storage, + which will be automatically reclaimed upon exit from + the procedure that called alloca. Originally, this space + was supposed to be taken from the current stack frame of the + caller, but that method cannot be made to work for some + implementations of C, for example under Gould's UTX/32. */ + +pointer +alloca (size) + unsigned size; +{ + auto char probe; /* Probes stack depth: */ + register char *depth = ADDRESS_FUNCTION (probe); + +#if STACK_DIRECTION == 0 + if (STACK_DIR == 0) /* Unknown growth direction. */ + find_stack_direction (); +#endif + + /* Reclaim garbage, defined as all alloca'd storage that + was allocated from deeper in the stack than currently. */ + + { + register header *hp; /* Traverses linked list. */ + +#ifdef emacs + BLOCK_INPUT; +#endif + + for (hp = last_alloca_header; hp != NULL;) + if ((STACK_DIR > 0 && hp->h.deep > depth) + || (STACK_DIR < 0 && hp->h.deep < depth)) + { + register header *np = hp->h.next; + + free ((pointer) hp); /* Collect garbage. */ + + hp = np; /* -> next header. */ + } + else + break; /* Rest are not deeper. */ + + last_alloca_header = hp; /* -> last valid storage. */ + +#ifdef emacs + UNBLOCK_INPUT; +#endif + } + + if (size == 0) + return NULL; /* No allocation required. */ + + /* Allocate combined header + user data storage. */ + + { + register pointer new = malloc (sizeof (header) + size); + /* Address of header. */ + + ((header *) new)->h.next = last_alloca_header; + ((header *) new)->h.deep = depth; + + last_alloca_header = (header *) new; + + /* User storage begins just after header. */ + + return (pointer) ((char *) new + sizeof (header)); + } +} + +#if defined (CRAY) && defined (CRAY_STACKSEG_END) + +#ifdef DEBUG_I00AFUNC +#include +#endif + +#ifndef CRAY_STACK +#define CRAY_STACK +#ifndef CRAY2 +/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */ +struct stack_control_header + { + long shgrow:32; /* Number of times stack has grown. */ + long shaseg:32; /* Size of increments to stack. */ + long shhwm:32; /* High water mark of stack. */ + long shsize:32; /* Current size of stack (all segments). */ + }; + +/* The stack segment linkage control information occurs at + the high-address end of a stack segment. (The stack + grows from low addresses to high addresses.) The initial + part of the stack segment linkage control information is + 0200 (octal) words. This provides for register storage + for the routine which overflows the stack. */ + +struct stack_segment_linkage + { + long ss[0200]; /* 0200 overflow words. */ + long sssize:32; /* Number of words in this segment. */ + long ssbase:32; /* Offset to stack base. */ + long:32; + long sspseg:32; /* Offset to linkage control of previous + segment of stack. */ + long:32; + long sstcpt:32; /* Pointer to task common address block. */ + long sscsnm; /* Private control structure number for + microtasking. */ + long ssusr1; /* Reserved for user. */ + long ssusr2; /* Reserved for user. */ + long sstpid; /* Process ID for pid based multi-tasking. */ + long ssgvup; /* Pointer to multitasking thread giveup. */ + long sscray[7]; /* Reserved for Cray Research. */ + long ssa0; + long ssa1; + long ssa2; + long ssa3; + long ssa4; + long ssa5; + long ssa6; + long ssa7; + long sss0; + long sss1; + long sss2; + long sss3; + long sss4; + long sss5; + long sss6; + long sss7; + }; + +#else /* CRAY2 */ +/* The following structure defines the vector of words + returned by the STKSTAT library routine. */ +struct stk_stat + { + long now; /* Current total stack size. */ + long maxc; /* Amount of contiguous space which would + be required to satisfy the maximum + stack demand to date. */ + long high_water; /* Stack high-water mark. */ + long overflows; /* Number of stack overflow ($STKOFEN) calls. */ + long hits; /* Number of internal buffer hits. */ + long extends; /* Number of block extensions. */ + long stko_mallocs; /* Block allocations by $STKOFEN. */ + long underflows; /* Number of stack underflow calls ($STKRETN). */ + long stko_free; /* Number of deallocations by $STKRETN. */ + long stkm_free; /* Number of deallocations by $STKMRET. */ + long segments; /* Current number of stack segments. */ + long maxs; /* Maximum number of stack segments so far. */ + long pad_size; /* Stack pad size. */ + long current_address; /* Current stack segment address. */ + long current_size; /* Current stack segment size. This + number is actually corrupted by STKSTAT to + include the fifteen word trailer area. */ + long initial_address; /* Address of initial segment. */ + long initial_size; /* Size of initial segment. */ + }; + +/* The following structure describes the data structure which trails + any stack segment. I think that the description in 'asdef' is + out of date. I only describe the parts that I am sure about. */ + +struct stk_trailer + { + long this_address; /* Address of this block. */ + long this_size; /* Size of this block (does not include + this trailer). */ + long unknown2; + long unknown3; + long link; /* Address of trailer block of previous + segment. */ + long unknown5; + long unknown6; + long unknown7; + long unknown8; + long unknown9; + long unknown10; + long unknown11; + long unknown12; + long unknown13; + long unknown14; + }; + +#endif /* CRAY2 */ +#endif /* not CRAY_STACK */ + +#ifdef CRAY2 +/* Determine a "stack measure" for an arbitrary ADDRESS. + I doubt that "lint" will like this much. */ + +static long +i00afunc (long *address) +{ + struct stk_stat status; + struct stk_trailer *trailer; + long *block, size; + long result = 0; + + /* We want to iterate through all of the segments. The first + step is to get the stack status structure. We could do this + more quickly and more directly, perhaps, by referencing the + $LM00 common block, but I know that this works. */ + + STKSTAT (&status); + + /* Set up the iteration. */ + + trailer = (struct stk_trailer *) (status.current_address + + status.current_size + - 15); + + /* There must be at least one stack segment. Therefore it is + a fatal error if "trailer" is null. */ + + if (trailer == 0) + abort (); + + /* Discard segments that do not contain our argument address. */ + + while (trailer != 0) + { + block = (long *) trailer->this_address; + size = trailer->this_size; + if (block == 0 || size == 0) + abort (); + trailer = (struct stk_trailer *) trailer->link; + if ((block <= address) && (address < (block + size))) + break; + } + + /* Set the result to the offset in this segment and add the sizes + of all predecessor segments. */ + + result = address - block; + + if (trailer == 0) + { + return result; + } + + do + { + if (trailer->this_size <= 0) + abort (); + result += trailer->this_size; + trailer = (struct stk_trailer *) trailer->link; + } + while (trailer != 0); + + /* We are done. Note that if you present a bogus address (one + not in any segment), you will get a different number back, formed + from subtracting the address of the first block. This is probably + not what you want. */ + + return (result); +} + +#else /* not CRAY2 */ +/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP. + Determine the number of the cell within the stack, + given the address of the cell. The purpose of this + routine is to linearize, in some sense, stack addresses + for alloca. */ + +static long +i00afunc (long address) +{ + long stkl = 0; + + long size, pseg, this_segment, stack; + long result = 0; + + struct stack_segment_linkage *ssptr; + + /* Register B67 contains the address of the end of the + current stack segment. If you (as a subprogram) store + your registers on the stack and find that you are past + the contents of B67, you have overflowed the segment. + + B67 also points to the stack segment linkage control + area, which is what we are really interested in. */ + + stkl = CRAY_STACKSEG_END (); + ssptr = (struct stack_segment_linkage *) stkl; + + /* If one subtracts 'size' from the end of the segment, + one has the address of the first word of the segment. + + If this is not the first segment, 'pseg' will be + nonzero. */ + + pseg = ssptr->sspseg; + size = ssptr->sssize; + + this_segment = stkl - size; + + /* It is possible that calling this routine itself caused + a stack overflow. Discard stack segments which do not + contain the target address. */ + + while (!(this_segment <= address && address <= stkl)) + { +#ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl); +#endif + if (pseg == 0) + break; + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + this_segment = stkl - size; + } + + result = address - this_segment; + + /* If you subtract pseg from the current end of the stack, + you get the address of the previous stack segment's end. + This seems a little convoluted to me, but I'll bet you save + a cycle somewhere. */ + + while (pseg != 0) + { +#ifdef DEBUG_I00AFUNC + fprintf (stderr, "%011o %011o\n", pseg, size); +#endif + stkl = stkl - pseg; + ssptr = (struct stack_segment_linkage *) stkl; + size = ssptr->sssize; + pseg = ssptr->sspseg; + result += size; + } + return (result); +} + +#endif /* not CRAY2 */ +#endif /* CRAY */ + +#endif /* no alloca */ +#endif /* not GCC version 2 */ diff --git a/contrib/gcc/assert.h b/contrib/gcc/assert.h new file mode 100644 index 00000000000..ecc02ee9991 --- /dev/null +++ b/contrib/gcc/assert.h @@ -0,0 +1,54 @@ +/* Allow this file to be included multiple times + with different settings of NDEBUG. */ +#undef assert +#undef __assert + +#ifdef NDEBUG +#define assert(ignore) ((void) 0) +#else + +#ifndef __GNUC__ + +#define assert(expression) \ + ((void) ((expression) ? 0 : __assert (expression, __FILE__, __LINE__))) + +#define __assert(expression, file, lineno) \ + (printf ("%s:%u: failed assertion\n", file, lineno), \ + abort (), 0) + +#else + +#if defined(__STDC__) || defined (__cplusplus) + +/* Defined in libgcc.a */ +#ifdef __cplusplus +extern "C" { +extern void __eprintf (const char *, const char *, unsigned, const char *) + __attribute__ ((noreturn)); +} +#else +extern void __eprintf (const char *, const char *, unsigned, const char *) + __attribute__ ((noreturn)); +#endif + +#define assert(expression) \ + ((void) ((expression) ? 0 : __assert (#expression, __FILE__, __LINE__))) + +#define __assert(expression, file, line) \ + (__eprintf ("%s:%u: failed assertion `%s'\n", \ + file, line, expression), 0) + +#else /* no __STDC__ and not C++; i.e. -traditional. */ + +extern void __eprintf () __attribute__ ((noreturn)); /* Defined in libgcc.a */ + +#define assert(expression) \ + ((void) ((expression) ? 0 : __assert (expression, __FILE__, __LINE__))) + +#define __assert(expression, file, lineno) \ + (__eprintf ("%s:%u: failed assertion `%s'\n", \ + file, lineno, "expression"), 0) + +#endif /* no __STDC__ and not C++; i.e. -traditional. */ +#endif /* no __GNU__; i.e., /bin/cc. */ +#endif diff --git a/contrib/gcc/basic-block.h b/contrib/gcc/basic-block.h new file mode 100644 index 00000000000..3755388c92b --- /dev/null +++ b/contrib/gcc/basic-block.h @@ -0,0 +1,69 @@ +/* Define control and data flow tables, and regsets. + Copyright (C) 1987 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Number of bits in each actual element of a regset. */ + +#define REGSET_ELT_BITS HOST_BITS_PER_WIDE_INT + +/* Type to use for a regset element. Note that lots of code assumes + that the initial part of a regset that contains information on the + hard registers is the same format as a HARD_REG_SET. */ + +#define REGSET_ELT_TYPE unsigned HOST_WIDE_INT + +/* Define the type for a pointer to a set with a bit for each + (hard or pseudo) register. */ + +typedef REGSET_ELT_TYPE *regset; + +/* Size of a regset for the current function, + in (1) bytes and (2) elements. */ + +extern int regset_bytes; +extern int regset_size; + +/* Number of basic blocks in the current function. */ + +extern int n_basic_blocks; + +/* Index by basic block number, get first insn in the block. */ + +extern rtx *basic_block_head; + +/* Index by basic block number, get last insn in the block. */ + +extern rtx *basic_block_end; + +/* Index by basic block number, get address of regset + describing the registers live at the start of that block. */ + +extern regset *basic_block_live_at_start; + +/* Indexed by n, gives number of basic block that (REG n) is used in. + If the value is REG_BLOCK_GLOBAL (-2), + it means (REG n) is used in more than one basic block. + REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know. + This information remains valid for the rest of the compilation + of the current function; it is used to control register allocation. */ + +#define REG_BLOCK_UNKNOWN -1 +#define REG_BLOCK_GLOBAL -2 +extern int *reg_basic_block; diff --git a/contrib/gcc/bc-emit.c b/contrib/gcc/bc-emit.c new file mode 100644 index 00000000000..9a7c0f981b6 --- /dev/null +++ b/contrib/gcc/bc-emit.c @@ -0,0 +1,992 @@ +/* Output bytecodes for GNU C-compiler. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#ifdef __STDC__ +#include +#else +#include +#endif +#include "machmode.h" +#include "rtl.h" +#include "real.h" +#include "obstack.h" +#include "bytecode.h" +#ifdef __GNUC__ +#include "bytetypes.h" +#endif +#include "bc-emit.h" +#include "bc-opcode.h" +#include "bc-typecd.h" +#include "bi-run.h" + +#include + +extern char *xmalloc (), *xrealloc (); +extern void free (); + +extern struct obstack *rtl_obstack; + +/* Indexed by mode class, gives the narrowest mode for each class. */ + +extern enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS]; + +/* Commonly used modes. */ +/* Mode whose width is BITS_PER_UNIT */ +extern enum machine_mode byte_mode; + +/* Mode whose width is BITS_PER_WORD */ +extern enum machine_mode word_mode; + +/* Vector indexed by opcode giving info about the args for each opcode. */ +static struct arityvec arityvec[] = { +#include "bc-arity.h" +}; + +/* How to print a symbol name for the assembler. */ +static void +prsym (file, s) + FILE *file; + char *s; +{ + if (*s == '*') + fprintf (file, "%s", s + 1); + else + +#ifdef NAMES_HAVE_UNDERSCORES + fprintf (file, "_%s", s); +#else + fprintf (file, "%s", s); +#endif + +} + +/* Maintain a bucket hash table for symbol names. */ + +#define HASH_BITS 32 +#define HASH_SIZE 509 + +static struct bc_sym *hashtab[HASH_SIZE]; + +static unsigned int +hash (name) + char *name; +{ + unsigned int hash = 0; + + while (*name) + { + hash = hash << 3 | hash >> HASH_BITS - 3; + hash += *name++; + } + + return hash % HASH_SIZE; +} + + +/* Look up the named symbol, creating it if it doesn't exist. */ +struct bc_sym * +sym_lookup (name) + char *name; +{ + int i; + struct bc_sym *s; + + i = hash (name); + for (s = hashtab[i]; s; s = s->next) + if (!strcmp (s->name, name)) + return s; + + s = (struct bc_sym *) xmalloc (sizeof (struct bc_sym)); + s->name = xmalloc (strlen (name) + 1); + strcpy (s->name, name); + s->defined = s->global = s->common = 0; + s->val = 0; + s->next = hashtab[i]; + hashtab[i] = s; + return s; +} + + +/* Write out .globl and common symbols to the named file. */ +static void +bc_sym_write (file) + FILE *file; +{ + int i; + struct bc_sym *s; + + for (i = 0; i < HASH_SIZE; ++i) + for (s = hashtab[i]; s; s = s->next) + { + if (s->global) + { + fprintf (file, "\n\t.globl "); + prsym (file, s->name); + putc ('\n', file); + if (s->common) + { + fprintf (file, "\n\t.comm "); + prsym (file, s->name); + fprintf (file, ", %lu\n", s->val); + } + } + else if (s->common) + { + fprintf (file, "\n\t.lcomm "); + prsym (file, s->name); + fprintf (file, ", %lu\n", s->val); + } + } +} + + + + +/* Create and initialize a new segment. */ +static struct bc_seg * +seg_create () +{ + struct bc_seg *result; + + result = (struct bc_seg *) xmalloc (sizeof (struct bc_seg)); + result->alloc = 256; + result->data = xmalloc (result->alloc); + result->size = 0; + result->syms = 0; + result->relocs = 0; + return result; +} + + +/* Advance the segment index to the next alignment boundary. */ +static void +seg_align (seg, log) + struct bc_seg *seg; + int log; +{ + unsigned int oldsize = seg->size; + + seg->size = seg->size + (1 << log) - 1 & ~((1 << log) - 1); + if (seg->size > seg->alloc) + { + while (seg->size > seg->alloc) + seg->alloc *= 2; + seg->data = xrealloc (seg->data, seg->alloc); + } + bzero (seg->data + oldsize, seg->size - oldsize); +} + + +/* Append the given data to the given segment. */ +static void +seg_data (seg, data, size) + struct bc_seg *seg; + char *data; + unsigned int size; +{ + if (seg->size + size > seg->alloc) + { + while (seg->size + size > seg->alloc) + seg->alloc *= 2; + seg->data = xrealloc (seg->data, seg->alloc); + } + + bcopy (data, seg->data + seg->size, size); + seg->size += size; +} + + +/* Append a zero-filled skip to the given segment. */ +static void +seg_skip (seg, size) + struct bc_seg *seg; + unsigned int size; +{ + if (seg->size + size > seg->alloc) + { + while (seg->size + size > seg->alloc) + seg->alloc *= 2; + seg->data = xrealloc (seg->data, seg->alloc); + } + + memset (seg->data + seg->size, 0, size); + seg->size += size; +} + + +/* Define the given name as the current offset in the given segment. It + is an error if the name is already defined. Return 0 or 1 indicating + failure or success respectively. */ +static int +seg_defsym (seg, name) + struct bc_seg *seg; + char *name; +{ + struct bc_sym *sym; + struct bc_segsym *segsym; + + sym = sym_lookup (name); + if (sym->defined) + return 0; + + sym->defined = 1; + sym->val = seg->size; + segsym = (struct bc_segsym *) xmalloc (sizeof (struct bc_segsym)); + segsym->sym = sym; + segsym->next = seg->syms; + seg->syms = segsym; + return 1; +} + + +/* Generate in seg's data a reference to the given sym, adjusted by + the given offset. */ +static void +seg_refsym (seg, name, offset) + struct bc_seg *seg; + char *name; + int offset; +{ + struct bc_sym *sym; + struct bc_segreloc *segreloc; + + sym = sym_lookup (name); + segreloc = (struct bc_segreloc *) xmalloc (sizeof (struct bc_segreloc)); + segreloc->offset = seg->size; + segreloc->sym = sym; + segreloc->next = seg->relocs; + seg->relocs = segreloc; + seg_data (seg, (char *) &offset, sizeof offset); +} + + +/* Concatenate the contents of given segments into the first argument. */ +static void +seg_concat (result, seg) + struct bc_seg *result, *seg; +{ + unsigned int fix; + struct bc_segsym *segsym; + struct bc_segreloc *segreloc; + + seg_align (result, MACHINE_SEG_ALIGN); + fix = result->size; + seg_data (result, seg->data, seg->size); + free (seg->data); + + /* Go through the symbols and relocs of SEG, adjusting their offsets + for their new location in RESULT. */ + if (seg->syms) + { + segsym = seg->syms; + do + segsym->sym->val += fix; + while (segsym->next && (segsym = segsym->next)); + segsym->next = result->syms; + result->syms = seg->syms; + } + if (seg->relocs) + { + segreloc = seg->relocs; + do + segreloc->offset += fix; + while (segreloc->next && (segreloc = segreloc->next)); + segreloc->next = result->relocs; + result->relocs = seg->relocs; + } + + free ((char *) seg); +} + +/* Write a segment to a file. */ +static void +bc_seg_write (seg, file) + struct bc_seg *seg; + FILE *file; +{ + struct bc_segsym *segsym, *nsegsym, *psegsym; + struct bc_segreloc *segreloc, *nsegreloc, *psegreloc; + int i, offset, flag; + + /* Reverse the list of symbols. */ + for (psegsym = 0, segsym = seg->syms; segsym; segsym = nsegsym) + { + nsegsym = segsym->next; + segsym->next = psegsym; + psegsym = segsym; + } + seg->syms = psegsym; + + /* Reverse the list of relocs. */ + for (psegreloc = 0, segreloc = seg->relocs; segreloc; segreloc = nsegreloc) + { + nsegreloc = segreloc->next; + segreloc->next = psegreloc; + psegreloc = segreloc; + } + seg->relocs = psegreloc; + + /* Output each byte of the segment. */ + for (i = 0, segsym = seg->syms, segreloc = seg->relocs; i < seg->size; ++i) + { + while (segsym && segsym->sym->val == i) + { + if (i % 8 != 0) + putc ('\n', file); + + BC_WRITE_SEGSYM (segsym, file); + segsym = segsym->next; + flag = 1; + } + if (segreloc && segreloc->offset == i) + { + if (i % 8 != 0) + putc ('\n', file); + + bcopy (seg->data + i, (char *) &offset, sizeof (int)); + i += sizeof (int) - 1; + + BC_WRITE_RELOC_ENTRY (segreloc, file, offset); + segreloc = segreloc->next; + flag = 1; + } + else + { + if (i % 8 == 0 || flag) + BC_START_BYTECODE_LINE (file); + + BC_WRITE_BYTECODE (i % 8 == 0 || flag ? ' ' : ',', + seg->data[i] & 0xFF, + file); + flag = 0; + if (i % 8 == 7) + putc ('\n', file); + } + } + + /* Paranoia check--we should have visited all syms and relocs during + the output pass. */ + + if (segsym || segreloc) + abort (); +} + + + +/* Text and data segments of the object file in making. */ +static struct bc_seg *bc_text_seg; +static struct bc_seg *bc_data_seg; + +/* Called before anything else in this module. */ +void +bc_initialize () +{ + int min_class_size[(int) MAX_MODE_CLASS]; + enum machine_mode mode; + int i; + + bc_init_mode_to_code_map (); + + bc_text_seg = seg_create (); + bc_data_seg = seg_create (); + + dconst0 = REAL_VALUE_ATOF ("0", DFmode); + dconst1 = REAL_VALUE_ATOF ("1", DFmode); + dconst2 = REAL_VALUE_ATOF ("2", DFmode); + dconstm1 = REAL_VALUE_ATOF ("-1", DFmode); + + /* Find the narrowest mode for each class and compute the word and byte + modes. */ + + for (i = 0; i < (int) MAX_MODE_CLASS; i++) + min_class_size[i] = 1000; + + for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE; + mode = (enum machine_mode) ((int) mode + 1)) + { + if (GET_MODE_SIZE (mode) < min_class_size[(int) GET_MODE_CLASS (mode)]) + { + class_narrowest_mode[(int) GET_MODE_CLASS (mode)] = mode; + min_class_size[(int) GET_MODE_CLASS (mode)] = GET_MODE_SIZE (mode); + } + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_BITSIZE (mode) == BITS_PER_UNIT) + byte_mode = mode; + + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_BITSIZE (mode) == BITS_PER_WORD) + word_mode = mode; + } +} + + +/* External addresses referenced in a function. Rather than trying to + work relocatable address directly into bytecoded functions (which would + require us to provide hairy location info and possibly obey alignment + rules imposed by the architecture) we build an auxiliary table of + pointer constants, and encode just offsets into this table into the + actual bytecode. */ +static struct bc_seg *ptrconsts; + +/* Trampoline code for the function entry. */ +struct bc_seg *trampoline; + +/* Actual byte code of the function. */ +struct bc_seg *bytecode; + +/* List of labels defined in the function. */ +struct bc_label *labels; + +/* List of label references in the function. */ +struct bc_labelref *labelrefs; + + +/* Add symbol to pointer table. Return offset into table where + pointer was stored. The offset usually goes into the bytecode + stream as a constP literal. */ +int +bc_define_pointer (p) + char *p; +{ + int offset = ptrconsts->size; + + seg_refsym (ptrconsts, p, 0); + return offset; +} + + +/* Begin a bytecoded function. */ +int +bc_begin_function (name) + char *name; +{ + ptrconsts = seg_create (); + trampoline = seg_create (); + bytecode = seg_create (); + return seg_defsym (trampoline, name); +} + + +/* Force alignment in inline bytecode. */ +void +bc_align_bytecode (align) + int align; +{ + seg_align (bytecode, align); +} + + +/* Emit data inline into bytecode. */ +void +bc_emit_bytecode_const (data, size) + char *data; + unsigned int size; +{ + if (bytecode) + seg_data (bytecode, data, size); +} + + +/* Create a new "bytecode label", to have its value defined later. + Bytecode labels have nothing to do with the object file symbol table, + and are purely local to a given bytecoded function. */ +struct bc_label * +bc_get_bytecode_label () +{ + struct bc_label *result; + + result = (struct bc_label *) xmalloc (sizeof (struct bc_label)); + result->defined = 0; + result->next = labels; + result->uid = 0; + labels = result; + return result; +} + + +/* Define the given label with the current location counter. */ +int +bc_emit_bytecode_labeldef (label) + struct bc_label *label; +{ + extern int bc_new_uid (); + + if (!label || label->defined) + return 0; + + label->offset = bytecode->size; + label->defined = 1; + label->uid = bc_new_uid (); + +#ifdef DEBUG_PRINT_CODE + fprintf (stderr, "$%lx:\n", label); +#endif + + return 1; +} + + +/* Generate a location-relative reference to the given bytecode label. + It need not be defined yet; label references will be backpatched later. */ +void +bc_emit_bytecode_labelref (label) + struct bc_label *label; +{ + struct bc_labelref *labelref; + static int zero; + + labelref = (struct bc_labelref *) xmalloc (sizeof (struct bc_labelref)); + labelref->label = label; + labelref->offset = bytecode->size; + labelref->next = labelrefs; + labelrefs = labelref; + +#ifdef DEBUG_PRINT_CODE + fprintf (stderr, " $%lx", label); +#endif + + seg_data (bytecode, (char *) &zero, sizeof zero); +} + + +/* Emit a reference to an external address; generate the reference in the + ptrconst area, and emit an offset in the bytecode. */ +void +bc_emit_code_labelref (name, offset) + char *name; + int offset; +{ + int ptroff; + + ptroff = ptrconsts->size / sizeof (char *); + seg_data (bytecode, (char *) &ptroff, sizeof ptroff); + seg_refsym (ptrconsts, name, offset); + +#ifdef DEBUG_PRINT_CODE + fprintf (stderr, " [external <%x> %s]", ptroff, name); +#endif +} + + +/* Backpatch label references in the byte code, and concatenate the bytecode + and pointer constant segments to the cumulative text for the object file. + Return a label name for the pointer constants region. */ +char * +bc_end_function () +{ + int addr; + struct bc_label *label, *next; + struct bc_labelref *ref, *nextref; + char ptrconsts_label[20]; + static int nlab; + + /* Backpatch bytecode label references. */ + for (ref = labelrefs; ref; ref = ref->next) + if (ref->label->defined) + { + addr = ref->label->offset; + bcopy ((char *) &addr, bytecode->data + ref->offset, sizeof addr); + } + + /* Free the chains of labelrefs and labeldefs. */ + for (ref = labelrefs; ref; ref = nextref) + { + nextref = ref->next; + free ((char *) ref); + } + + for (label = labels; label; label = next) + { + next = label->next; + free ((char *) label); + } + + seg_concat (trampoline, bytecode); + seg_align (trampoline, MACHINE_SEG_ALIGN); + sprintf (ptrconsts_label, "*LP%d", nlab++); + seg_defsym (trampoline, ptrconsts_label); + seg_concat (trampoline, ptrconsts); + seg_concat (bc_text_seg, trampoline); + + labels = 0; + labelrefs = 0; + trampoline = 0; + bytecode = 0; + ptrconsts = 0; + + return sym_lookup (ptrconsts_label)->name; +} + +/* Force alignment in const data. */ +void +bc_align_const (align) + int align; +{ + seg_align (bc_text_seg, align); +} + +/* Emit const data. */ +void +bc_emit_const (data, size) + char *data; + unsigned int size; +{ + seg_data (bc_text_seg, data, size); +} + +/* Emit a zero-filled constant skip. */ +void +bc_emit_const_skip (size) + unsigned int size; +{ + seg_skip (bc_text_seg, size); +} + +/* Emit a label definition in const data. */ +int +bc_emit_const_labeldef (name) + char *name; +{ + return seg_defsym (bc_text_seg, name); +} + +/* Emit a label reference in const data. */ +void +bc_emit_const_labelref (name, offset) + char *name; + int offset; +{ + seg_refsym (bc_text_seg, name, offset); +} + +/* Force alignment in data. */ +void +bc_align_data (align) + int align; +{ + seg_align (bc_data_seg, align); +} + +/* Emit data. */ +void +bc_emit_data (data, size) + char *data; + unsigned int size; +{ + seg_data (bc_data_seg, data, size); +} + +/* Emit a zero-filled data skip. */ +void +bc_emit_data_skip (size) + unsigned int size; +{ + seg_skip (bc_data_seg, size); +} + +/* Emit label definition in data. */ +int +bc_emit_data_labeldef (name) + char *name; +{ + return seg_defsym (bc_data_seg, name); +} + +/* Emit label reference in data. */ +void +bc_emit_data_labelref (name, offset) + char *name; + int offset; +{ + seg_refsym (bc_data_seg, name, offset); +} + +/* Emit a common block of the given name and size. Note that + when the .o file is actually written non-global "common" + blocks will have to be turned into space in the data section. */ +int +bc_emit_common (name, size) + char *name; + unsigned int size; +{ + struct bc_sym *sym; + + sym = sym_lookup (name); + if (sym->defined) + return 0; + + sym->defined = 1; + sym->common = 1; + sym->val = size; + return 1; +} + +/* Globalize the given label. */ +void +bc_globalize_label (name) + char *name; +{ + struct bc_sym *sym; + + sym = sym_lookup (name); + sym->global = 1; +} + +static enum { in_text, in_data } section = in_text; + +void +bc_text () +{ + section = in_text; +} + +void +bc_data () +{ + section = in_data; +} + +void +bc_align (align) + int align; +{ + if (section == in_text) + bc_align_const (align); + else + bc_align_data (align); +} + +void +bc_emit (data, size) + char *data; + unsigned int size; +{ + if (section == in_text) + bc_emit_const (data, size); + else + bc_emit_data (data, size); +} + +void +bc_emit_skip (size) + unsigned int size; +{ + if (section == in_text) + bc_emit_const_skip (size); + else + bc_emit_data_skip (size); +} + +int +bc_emit_labeldef (name) + char *name; +{ + if (section == in_text) + return bc_emit_const_labeldef (name); + else + return bc_emit_data_labeldef (name); +} + +void +bc_emit_labelref (name, offset) + char *name; + int offset; +{ + if (section == in_text) + bc_emit_const_labelref (name, offset); + else + bc_emit_data_labelref (name, offset); +} + +void +bc_write_file (file) + FILE *file; +{ + BC_WRITE_FILE (file); +} + + +/* Allocate a new bytecode rtx. + If you supply a null BC_LABEL, we generate one. */ + +rtx +bc_gen_rtx (label, offset, bc_label) + char *label; + int offset; + struct bc_label *bc_label; +{ + rtx r; + + if (bc_label == 0) + bc_label = (struct bc_label *) xmalloc (sizeof (struct bc_label)); + + r = gen_rtx (CODE_LABEL, VOIDmode, label, bc_label); + bc_label->offset = offset; + + return r; +} + + +/* Print bytecode rtx */ +void +bc_print_rtl (fp, r) + FILE *fp; + rtx r; +{ +#if 0 /* This needs to get fixed to really work again. */ + /* BC_WRITE_RTL has a definition + that doesn't even make sense for this use. */ + BC_WRITE_RTL (r, fp); +#endif +} + + +/* Emit a bytecode, keeping a running tally of the stack depth. */ +void +bc_emit_bytecode (bytecode) + enum bytecode_opcode bytecode; +{ + char byte; + static int prev_lineno = -1; + + byte = (char) bytecode; + +#ifdef BCDEBUG_PRINT_CODE + if (lineno != prev_lineno) + { + fprintf (stderr, "\n", lineno); + prev_lineno = lineno; + } + + fputs (opcode_name[(unsigned int) bytecode], stderr); +#endif + + /* Due to errors we are often requested to output bytecodes that + will cause an interpreter stack undeflow when executed. Instead of + dumping core on such occasions, we omit the bytecode. Erroneous code + should not be executed, regardless. This makes life much easier, since + we don't have to deceive ourselves about the known stack depth. */ + + bc_emit_bytecode_const (&byte, 1); + + if ((stack_depth -= arityvec[(int) bytecode].ninputs) >= 0) + { + if ((stack_depth += arityvec[(int) bytecode].noutputs) > max_stack_depth) + max_stack_depth = stack_depth; + } + +#ifdef VALIDATE_STACK_FOR_BC + VALIDATE_STACK_FOR_BC (); +#endif +} + + +#ifdef BCDEBUG_PRINT_CODE +#define PRLIT(TYPE, PTR) fprintf (stderr, " [%x]", *(TYPE *) PTR) +#else +#define PRLIT(X,Y) +#endif + +/* Emit a complete bytecode instruction, expecting the correct number + of literal values in the call. First argument is the instruction, the + remaining arguments are literals of size HOST_WIDE_INT or smaller. */ +void +bc_emit_instruction VPROTO((enum bytecode_opcode opcode, ...)) +{ +#ifndef __STDC__ + enum bytecode_opcode opcode; +#endif + va_list arguments; + int nliteral, instruction; + + VA_START (arguments, opcode); + +#ifndef __STDC__ + opcode = va_arg (arguments, enum bytecode_opcode); +#endif + + /* Emit instruction bytecode */ + bc_emit_bytecode (opcode); + instruction = (int) opcode; + + /* Loop literals and emit as bytecode constants */ + for (nliteral = 0; nliteral < arityvec[instruction].nliterals; nliteral++) + { + switch (arityvec[instruction].literals[nliteral]) + { +/* This conditional is a kludge, but it's necessary + because TYPE might be long long. */ +#ifdef __GNUC__ + /* Expand definitions into case statements */ +#define DEFTYPECODE(CODE, NAME, MODE, TYPE) \ + case CODE: \ + { \ + TYPE temp = va_arg (arguments, TYPE); \ + bc_emit_bytecode_const ((void *) &temp, sizeof temp); \ + PRLIT (TYPE, &temp); } \ + break; + +#include "bc-typecd.def" + +#undef DEFTYPECODE +#endif /* __GNUC__ */ + + default: + abort (); + } + } + +#ifdef BCDEBUG_PRINT_CODE + fputc ('\n', stderr); +#endif +} + +/* Emit the machine-code interface trampoline at the beginning of a byte + coded function. The argument is a label name of the interpreter + bytecode callinfo structure; the return value is a label name for + the beginning of the actual bytecode. */ +char * +bc_emit_trampoline (callinfo) + char *callinfo; +{ + char mylab[20]; + static int n; + + sprintf (mylab, "*LB%d", n++); + + BC_EMIT_TRAMPOLINE (trampoline, callinfo); + + seg_defsym (bytecode, mylab); + return sym_lookup (mylab)->name; +} + + +/* Simple strdup */ +char * +bc_xstrdup (str) + char *str; +{ + char *tmp = xmalloc (strlen (str) + 1); + + strcpy (tmp, str); + return tmp; +} diff --git a/contrib/gcc/bc-emit.h b/contrib/gcc/bc-emit.h new file mode 100644 index 00000000000..c00da5b3539 --- /dev/null +++ b/contrib/gcc/bc-emit.h @@ -0,0 +1,133 @@ +/* bc-emit.h - declare entry points for producing object files of bytecodes. */ + +/* Internal format of symbol table for the object file. */ +struct bc_sym +{ + /* Private copy separately malloc'd. */ + char *name; + + /* Symbol has a defined value. */ + unsigned int defined:1; + + /* Symbol has been globalized. */ + unsigned int global:1; + + /* Symbol is common. */ + unsigned int common:1; + + /* Value if defined. */ + unsigned long int val; + + /* Used in internal symbol table structure. */ + struct bc_sym *next; +}; + + +/* List of symbols defined in a particular segment. */ +struct bc_segsym +{ + struct bc_sym *sym; + struct bc_segsym *next; +}; + + +/* List of relocations needed in a particular segment. */ +struct bc_segreloc +{ + /* Offset of datum to be relocated. */ + unsigned int offset; + + /* Symbol to be relocated by. */ + struct bc_sym *sym; + + struct bc_segreloc *next; +}; + + +/* Segment of an object file. */ +struct bc_seg +{ + /* Size allocated to contents. */ + unsigned int alloc; + + /* Pointer to base of contents. */ + char *data; + + /* Actual size of contents. */ + unsigned int size; + + /* List of symbols defined in this segment. */ + struct bc_segsym *syms; + + /* List of relocations for this segment. */ + struct bc_segreloc *relocs; +}; + + +/* Anonymous bytecode label within a single function. */ +struct bc_label +{ + /* Offset of label from start of segment. */ + unsigned int offset; + + /* True when offset is valid. */ + unsigned int defined:1; + + /* Unique bytecode ID, used to determine innermost + block containment */ + int uid; + + /* Next node in list */ + struct bc_label *next; +}; + + +/* Reference to a bc_label; a list of all such references is kept for + the function, then when it is finished they are backpatched to + contain the correct values. */ + +struct bc_labelref +{ + /* Label referenced. */ + struct bc_label *label; + + /* Code offset of reference. */ + unsigned int offset; + + /* Next labelref in list */ + struct bc_labelref *next; +}; + + + +extern void bc_initialize(); +extern int bc_begin_function(); +extern char *bc_emit_trampoline(); +extern void bc_emit_bytecode(); +extern void bc_emit_bytecode_const(); +extern struct bc_label *bc_get_bytecode_label(); +extern int bc_emit_bytecode_labeldef(); +extern void bc_emit_bytecode_labelref(); +extern void bc_emit_code_labelref(); +extern char *bc_end_function(); +extern void bc_align_const(); +extern void bc_emit_const(); +extern void bc_emit_const_skip(); +extern int bc_emit_const_labeldef(); +extern void bc_emit_const_labelref(); +extern void bc_align_data(); +extern void bc_emit_data(); +extern void bc_emit_data_skip(); +extern int bc_emit_data_labeldef(); +extern void bc_emit_data_labelref(); +extern int bc_define_pointer (); +extern int bc_emit_common(); +extern void bc_globalize_label(); +extern void bc_text(); +extern void bc_data(); +extern void bc_align(); +extern void bc_emit(); +extern void bc_emit_skip(); +extern int bc_emit_labeldef(); +extern void bc_emit_labelref(); +extern void bc_write_file(); diff --git a/contrib/gcc/bc-optab.c b/contrib/gcc/bc-optab.c new file mode 100644 index 00000000000..b7ff4865237 --- /dev/null +++ b/contrib/gcc/bc-optab.c @@ -0,0 +1,789 @@ +/* Bytecode conversion definitions for GNU C-compiler. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "machmode.h" +#include "obstack.h" +#include "bytecode.h" +#include "bc-typecd.h" +#include "bc-opcode.h" +#include "bc-optab.h" + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +extern char *xmalloc (); +extern void free (); + +/* Table relating interpreter typecodes to machine modes. */ +#define GET_TYPECODE_MODE(CODE) (typecode_mode[((int) CODE)]) +enum machine_mode typecode_mode[] = { +#define DEFTYPECODE(CODE, NAME, MODE, TYPE) MODE, +#include "bc-typecd.def" +#undef DEFTYPECODE +}; + +/* Machine mode to type code map */ +static enum typecode signed_mode_to_code_map[MAX_MACHINE_MODE+1]; +static enum typecode unsigned_mode_to_code_map[MAX_MACHINE_MODE+1]; + +#define GET_TYPECODE_SIZE(CODE) GET_MODE_SIZE (GET_TYPECODE_MODE (CODE)) + +#define BIG_ARBITRARY_NUMBER 100000 + +/* Table of recipes for conversions among scalar types, to be filled + in as needed at run time. */ +static struct conversion_recipe +{ + unsigned char *opcodes; /* Bytecodes to emit in order. */ + int nopcodes; /* Count of bytecodes. */ + int cost; /* A rather arbitrary cost function. */ +} conversion_recipe[NUM_TYPECODES][NUM_TYPECODES]; + +/* Binary operator tables. */ +struct binary_operator optab_plus_expr[] = { + { addSI, SIcode, SIcode, SIcode }, + { addDI, DIcode, DIcode, DIcode }, + { addSF, SFcode, SFcode, SFcode }, + { addDF, DFcode, DFcode, DFcode }, + { addXF, XFcode, XFcode, XFcode }, + { addPSI, Pcode, Pcode, SIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_minus_expr[] = { + { subSI, SIcode, SIcode, SIcode }, + { subDI, DIcode, DIcode, DIcode }, + { subSF, SFcode, SFcode, SFcode }, + { subDF, DFcode, DFcode, DFcode }, + { subXF, XFcode, XFcode, XFcode }, + { subPP, SIcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +/* The ordering of the tables for multiplicative operators + is such that unsigned operations will be preferred to signed + operations when one argument is unsigned. */ + +struct binary_operator optab_mult_expr[] = { + { mulSU, SUcode, SUcode, SUcode }, + { mulDU, DUcode, DUcode, DUcode }, + { mulSI, SIcode, SIcode, SIcode }, + { mulDI, DIcode, DIcode, DIcode }, + { mulSF, SFcode, SFcode, SFcode }, + { mulDF, DFcode, DFcode, DFcode }, + { mulXF, XFcode, XFcode, XFcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_trunc_div_expr[] = { + { divSU, SUcode, SUcode, SUcode }, + { divDU, DUcode, DUcode, DUcode }, + { divSI, SIcode, SIcode, SIcode }, + { divDI, DIcode, DIcode, DIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_trunc_mod_expr[] = { + { modSU, SUcode, SUcode, SUcode }, + { modDU, DUcode, DUcode, DUcode }, + { modSI, SIcode, SIcode, SIcode }, + { modDI, DIcode, DIcode, DIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_rdiv_expr[] = { + { divSF, SFcode, SFcode, SFcode }, + { divDF, DFcode, DFcode, DFcode }, + { divXF, XFcode, XFcode, XFcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_bit_and_expr[] = { + { andSI, SIcode, SIcode, SIcode }, + { andDI, DIcode, DIcode, DIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_bit_ior_expr[] = { + { iorSI, SIcode, SIcode, SIcode }, + { iorDI, DIcode, DIcode, DIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_bit_xor_expr[] = { + { xorSI, SIcode, SIcode, SIcode }, + { xorDI, DIcode, DIcode, DIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_lshift_expr[] = { + { lshiftSI, SIcode, SIcode, SIcode }, + { lshiftSU, SUcode, SUcode, SIcode }, + { lshiftDI, DIcode, DIcode, SIcode }, + { lshiftDU, DUcode, DUcode, SIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_rshift_expr[] = { + { rshiftSI, SIcode, SIcode, SIcode }, + { rshiftSU, SUcode, SUcode, SIcode }, + { rshiftDI, DIcode, DIcode, SIcode }, + { rshiftDU, DUcode, DUcode, SIcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_truth_and_expr[] = { + { andSI, SIcode, Tcode, Tcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_truth_or_expr[] = { + { iorSI, SIcode, Tcode, Tcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_lt_expr[] = { + { ltSI, Tcode, SIcode, SIcode }, + { ltSU, Tcode, SUcode, SUcode }, + { ltDI, Tcode, DIcode, DIcode }, + { ltDU, Tcode, DUcode, DUcode }, + { ltSF, Tcode, SFcode, SFcode }, + { ltDF, Tcode, DFcode, DFcode }, + { ltXF, Tcode, XFcode, XFcode }, + { ltP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_le_expr[] = { + { leSI, Tcode, SIcode, SIcode }, + { leSU, Tcode, SUcode, SUcode }, + { leDI, Tcode, DIcode, DIcode }, + { leDU, Tcode, DUcode, DUcode }, + { leSF, Tcode, SFcode, SFcode }, + { leDF, Tcode, DFcode, DFcode }, + { leXF, Tcode, XFcode, XFcode }, + { leP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_ge_expr[] = { + { geSI, Tcode, SIcode, SIcode }, + { geSU, Tcode, SUcode, SUcode }, + { geDI, Tcode, DIcode, DIcode }, + { geDU, Tcode, DUcode, DUcode }, + { geSF, Tcode, SFcode, SFcode }, + { geDF, Tcode, DFcode, DFcode }, + { geXF, Tcode, XFcode, XFcode }, + { geP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_gt_expr[] = { + { gtSI, Tcode, SIcode, SIcode }, + { gtSU, Tcode, SUcode, SUcode }, + { gtDI, Tcode, DIcode, DIcode }, + { gtDU, Tcode, DUcode, DUcode }, + { gtSF, Tcode, SFcode, SFcode }, + { gtDF, Tcode, DFcode, DFcode }, + { gtXF, Tcode, XFcode, XFcode }, + { gtP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_eq_expr[] = { + { eqSI, Tcode, SIcode, SIcode }, + { eqDI, Tcode, DIcode, DIcode }, + { eqSF, Tcode, SFcode, SFcode }, + { eqDF, Tcode, DFcode, DFcode }, + { eqXF, Tcode, XFcode, XFcode }, + { eqP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +struct binary_operator optab_ne_expr[] = { + { neSI, Tcode, SIcode, SIcode }, + { neDI, Tcode, DIcode, DIcode }, + { neSF, Tcode, SFcode, SFcode }, + { neDF, Tcode, DFcode, DFcode }, + { neXF, Tcode, XFcode, XFcode }, + { neP, Tcode, Pcode, Pcode }, + { -1, -1, -1, -1 }, +}; + +/* Unary operator tables. */ +struct unary_operator optab_negate_expr[] = { + { negSI, SIcode, SIcode }, + { negDI, DIcode, DIcode }, + { negSF, SFcode, SFcode }, + { negDF, DFcode, DFcode }, + { negXF, XFcode, XFcode }, + { -1, -1, -1 }, +}; + +struct unary_operator optab_bit_not_expr[] = { + { notSI, SIcode, SIcode }, + { notDI, DIcode, DIcode }, + { -1, -1, -1 }, +}; + +struct unary_operator optab_truth_not_expr[] = { + { notT, SIcode, SIcode }, + { -1, -1, -1 }, +}; + +/* Increment operator tables. */ +struct increment_operator optab_predecrement_expr[] = { + { predecQI, QIcode }, + { predecQI, QUcode }, + { predecHI, HIcode }, + { predecHI, HUcode }, + { predecSI, SIcode }, + { predecSI, SUcode }, + { predecDI, DIcode }, + { predecDI, DUcode }, + { predecP, Pcode }, + { predecSF, SFcode }, + { predecDF, DFcode }, + { predecXF, XFcode }, + { -1, -1 }, +}; + +struct increment_operator optab_preincrement_expr[] = { + { preincQI, QIcode }, + { preincQI, QUcode }, + { preincHI, HIcode }, + { preincHI, HUcode }, + { preincSI, SIcode }, + { preincSI, SUcode }, + { preincDI, DIcode }, + { preincDI, DUcode }, + { preincP, Pcode }, + { preincSF, SFcode }, + { preincDF, DFcode }, + { preincXF, XFcode }, + { -1, -1 }, +}; + +struct increment_operator optab_postdecrement_expr[] = { + { postdecQI, QIcode }, + { postdecQI, QUcode }, + { postdecHI, HIcode }, + { postdecHI, HUcode }, + { postdecSI, SIcode }, + { postdecSI, SUcode }, + { postdecDI, DIcode }, + { postdecDI, DUcode }, + { postdecP, Pcode }, + { postdecSF, SFcode }, + { postdecDF, DFcode }, + { postdecXF, XFcode }, + { -1, -1 }, +}; + +struct increment_operator optab_postincrement_expr[] = { + { postincQI, QIcode }, + { postincQI, QUcode }, + { postincHI, HIcode }, + { postincHI, HUcode }, + { postincSI, SIcode }, + { postincSI, SUcode }, + { postincDI, DIcode }, + { postincDI, DUcode }, + { postincP, Pcode }, + { postincSF, SFcode }, + { postincDF, DFcode }, + { postincXF, XFcode }, + { -1, -1 }, +}; + +/* Table of conversions supported by the interpreter. */ +static struct conversion_info +{ + enum bytecode_opcode opcode; /* here indicates the conversion needs no opcode. */ + enum typecode from; + enum typecode to; + int cost; /* 1 for no-op conversions, 2 for widening conversions, + 4 for int/float conversions, 8 for narrowing conversions. */ +} conversion_info[] = { + { -1, QIcode, QUcode, 1 }, + { -1, HIcode, HUcode, 1 }, + { -1, SIcode, SUcode, 1 }, + { -1, DIcode, DUcode, 1 }, + { -1, QUcode, QIcode, 1 }, + { -1, HUcode, HIcode, 1 }, + { -1, SUcode, SIcode, 1 }, + { -1, DUcode, DIcode, 1 }, + { -1, Tcode, SIcode, 1 }, + { convertQIHI, QIcode, HIcode, 2 }, + { convertQUHU, QUcode, HUcode, 2 }, + { convertQUSU, QUcode, SUcode, 2 }, + { convertHISI, HIcode, SIcode, 2 }, + { convertHUSU, HUcode, SUcode, 2 }, + { convertSIDI, SIcode, DIcode, 2 }, + { convertSUDU, SUcode, DUcode, 2 }, + { convertSFDF, SFcode, DFcode, 2 }, + { convertDFXF, DFcode, XFcode, 2 }, + { convertHIQI, HIcode, QIcode, 8 }, + { convertSIQI, SIcode, QIcode, 8 }, + { convertSIHI, SIcode, HIcode, 8 }, + { convertSUQU, SUcode, QUcode, 8 }, + { convertDISI, DIcode, SIcode, 8 }, + { convertDFSF, DFcode, SFcode, 8 }, + { convertXFDF, XFcode, DFcode, 8 }, + { convertPSI, Pcode, SIcode, 2 }, + { convertSIP, SIcode, Pcode, 2 }, + { convertSIT, SIcode, Tcode, 2 }, + { convertDIT, DIcode, Tcode, 2 }, + { convertSFT, SFcode, Tcode, 2 }, + { convertDFT, DFcode, Tcode, 2 }, + { convertXFT, XFcode, Tcode, 2 }, + { convertQISI, QIcode, SIcode, 2 }, + { convertPT, Pcode, Tcode, 2 }, + { convertSISF, SIcode, SFcode, 4 }, + { convertSIDF, SIcode, DFcode, 4 }, + { convertSIXF, SIcode, XFcode, 4 }, + { convertSUSF, SUcode, SFcode, 4 }, + { convertSUDF, SUcode, DFcode, 4 }, + { convertSUXF, SUcode, XFcode, 4 }, + { convertDISF, DIcode, SFcode, 4 }, + { convertDIDF, DIcode, DFcode, 4 }, + { convertDIXF, DIcode, XFcode, 4 }, + { convertDUSF, DUcode, SFcode, 4 }, + { convertDUDF, DUcode, DFcode, 4 }, + { convertDUXF, DUcode, XFcode, 4 }, + { convertSFSI, SFcode, SIcode, 4 }, + { convertDFSI, DFcode, SIcode, 4 }, + { convertXFSI, XFcode, SIcode, 4 }, + { convertSFSU, SFcode, SUcode, 4 }, + { convertDFSU, DFcode, SUcode, 4 }, + { convertXFSU, XFcode, SUcode, 4 }, + { convertSFDI, SFcode, DIcode, 4 }, + { convertDFDI, DFcode, DIcode, 4 }, + { convertXFDI, XFcode, DIcode, 4 }, + { convertSFDU, SFcode, DUcode, 4 }, + { convertDFDU, DFcode, DUcode, 4 }, + { convertXFDU, XFcode, DUcode, 4 }, + { convertSIQI, SIcode, QIcode, 8 }, +}; + +#define NUM_CONVERSIONS (sizeof conversion_info / sizeof (struct conversion_info)) + +/* List form of a conversion recipe. */ +struct conversion_list +{ + enum bytecode_opcode opcode; + enum typecode to; + int cost; + struct conversion_list *prev; +}; + +/* Determine if it is "reasonable" to add a given conversion to + a given list of conversions. The following criteria define + "reasonable" conversion lists: + * No typecode appears more than once in the sequence (no loops). + * At most one conversion from integer to float or vice versa is present. + * Either sign extensions or zero extensions may be present, but not both. + * No widening conversions occur after a signed/unsigned conversion. + * The sequence of sizes must be strict nonincreasing or nondecreasing. */ +static int +conversion_reasonable_p (conversion, list) + struct conversion_info *conversion; + struct conversion_list *list; +{ + struct conversion_list *curr; + int curr_size, prev_size; + int has_int_float, has_float_int; + int has_sign_extend, has_zero_extend; + int has_signed_unsigned, has_unsigned_signed; + + has_int_float = 0; + has_float_int = 0; + has_sign_extend = 0; + has_zero_extend = 0; + has_signed_unsigned = 0; + has_unsigned_signed = 0; + + /* Make sure the destination typecode doesn't already appear in + the list. */ + for (curr = list; curr; curr = curr->prev) + if (conversion->to == curr->to) + return 0; + + /* Check for certain kinds of conversions. */ + if (TYPECODE_INTEGER_P (conversion->from) + && TYPECODE_FLOAT_P (conversion->to)) + has_int_float = 1; + if (TYPECODE_FLOAT_P (conversion->from) + && TYPECODE_INTEGER_P (conversion->to)) + has_float_int = 1; + if (TYPECODE_SIGNED_P (conversion->from) + && TYPECODE_SIGNED_P (conversion->to) + && GET_TYPECODE_SIZE (conversion->from) + < GET_TYPECODE_SIZE (conversion->to)) + has_sign_extend = 1; + if (TYPECODE_UNSIGNED_P (conversion->from) + && TYPECODE_UNSIGNED_P (conversion->to) + && GET_TYPECODE_SIZE (conversion->from) + < GET_TYPECODE_SIZE (conversion->to)) + has_zero_extend = 1; + + for (curr = list; curr && curr->prev; curr = curr->prev) + { + if (TYPECODE_INTEGER_P (curr->prev->to) + && TYPECODE_FLOAT_P (curr->to)) + has_int_float = 1; + if (TYPECODE_FLOAT_P (curr->prev->to) + && TYPECODE_INTEGER_P (curr->to)) + has_float_int = 1; + if (TYPECODE_SIGNED_P (curr->prev->to) + && TYPECODE_SIGNED_P (curr->to) + && GET_TYPECODE_SIZE (curr->prev->to) + < GET_TYPECODE_SIZE (curr->to)) + has_sign_extend = 1; + if (TYPECODE_UNSIGNED_P (curr->prev->to) + && TYPECODE_UNSIGNED_P (curr->to) + && GET_TYPECODE_SIZE (curr->prev->to) + < GET_TYPECODE_SIZE (curr->to)) + has_zero_extend = 1; + if (TYPECODE_SIGNED_P (curr->prev->to) + && TYPECODE_UNSIGNED_P (curr->to)) + has_signed_unsigned = 1; + if (TYPECODE_UNSIGNED_P (curr->prev->to) + && TYPECODE_SIGNED_P (curr->to)) + has_unsigned_signed = 1; + } + + if (TYPECODE_INTEGER_P (conversion->from) + && TYPECODE_INTEGER_P (conversion->to) + && GET_TYPECODE_SIZE (conversion->to) + > GET_TYPECODE_SIZE (conversion->from) + && (has_signed_unsigned || has_unsigned_signed)) + return 0; + + if (has_float_int && has_int_float || has_sign_extend && has_zero_extend) + return 0; + + /* Make sure the sequence of destination typecode sizes is + strictly nondecreasing or strictly nonincreasing. */ + prev_size = GET_TYPECODE_SIZE (conversion->to); + for (curr = list; curr; curr = curr->prev) + { + curr_size = GET_TYPECODE_SIZE (curr->to); + if (curr_size != prev_size) + break; + } + if (!curr) + return 1; + + if (curr_size < prev_size) + for (prev_size = curr_size; curr; curr = curr->prev) + { + curr_size = GET_TYPECODE_SIZE (curr->to); + if (curr_size > prev_size) + return 0; + prev_size = curr_size; + } + else + for (prev_size = curr_size; curr; curr = curr->prev) + { + curr_size = GET_TYPECODE_SIZE (curr->to); + if (curr_size < prev_size) + return 0; + prev_size = curr_size; + } + return 1; +} + + +/* Exhaustively search all reasonable conversions to find one to + convert the given types. */ +static struct conversion_recipe +deduce_conversion (from, to) + enum typecode from, to; +{ + struct rl + { + struct conversion_list *list; + struct rl *next; + } *prev, curr, *good, *temp; + struct conversion_list *conv, *best; + int i, cost, bestcost; + struct conversion_recipe result; + struct obstack recipe_obstack; + + + obstack_init (&recipe_obstack); + curr.next = (struct rl *) obstack_alloc (&recipe_obstack, sizeof (struct rl)); + curr.next->list = + (struct conversion_list *) obstack_alloc (&recipe_obstack, + sizeof (struct conversion_list)); + curr.next->list->opcode = -1; + curr.next->list->to = from; + curr.next->list->cost = 0; + curr.next->list->prev = 0; + curr.next->next = 0; + good = 0; + + while (curr.next) + { + /* Remove successful conversions from further consideration. */ + for (prev = &curr; prev; prev = prev->next) + if (prev->next && prev->next->list->to == to) + { + temp = prev->next->next; + prev->next->next = good; + good = prev->next; + prev->next = temp; + } + + /* Go through each of the pending conversion chains, trying + all possible candidate conversions on them. */ + for (prev = curr.next, curr.next = 0; prev; prev = prev->next) + for (i = 0; i < NUM_CONVERSIONS; ++i) + if (conversion_info[i].from == prev->list->to + && conversion_reasonable_p (&conversion_info[i], prev->list)) + { + temp = (struct rl *) obstack_alloc (&recipe_obstack, + sizeof (struct rl)); + temp->list = (struct conversion_list *) + obstack_alloc (&recipe_obstack, + sizeof (struct conversion_list)); + temp->list->opcode = conversion_info[i].opcode; + temp->list->to = conversion_info[i].to; + temp->list->cost = conversion_info[i].cost; + temp->list->prev = prev->list; + temp->next = curr.next; + curr.next = temp; + } + } + + bestcost = BIG_ARBITRARY_NUMBER; + best = 0; + for (temp = good; temp; temp = temp->next) + { + for (conv = temp->list, cost = 0; conv; conv = conv->prev) + cost += conv->cost; + if (cost < bestcost) + { + bestcost = cost; + best = temp->list; + } + } + + if (!best) + abort (); + + for (i = 0, conv = best; conv; conv = conv->prev) + if (conv->opcode != -1) + ++i; + + result.opcodes = (unsigned char *) xmalloc (i); + result.nopcodes = i; + for (conv = best; conv; conv = conv->prev) + if (conv->opcode != -1) + result.opcodes[--i] = conv->opcode; + result.cost = bestcost; + obstack_free (&recipe_obstack, 0); + return result; +} + +#define DEDUCE_CONVERSION(FROM, TO) \ + (conversion_recipe[(int) FROM][(int) TO].opcodes ? 0 \ + : (conversion_recipe[(int) FROM][(int) TO] \ + = deduce_conversion (FROM, TO), 0)) + + +/* Emit a conversion between the given scalar types. */ +void +emit_typecode_conversion (from, to) + enum typecode from, to; +{ + int i; + + DEDUCE_CONVERSION (from, to); + for (i = 0; i < conversion_recipe[(int) from][(int) to].nopcodes; ++i) + bc_emit_instruction (conversion_recipe[(int) from][(int) to].opcodes[i]); +} + + +/* Initialize mode_to_code_map[] */ +void +bc_init_mode_to_code_map () +{ + int mode; + + for (mode = 0; mode < MAX_MACHINE_MODE + 1; mode++) + { + signed_mode_to_code_map[mode] = + unsigned_mode_to_code_map[mode] = + LAST_AND_UNUSED_TYPECODE; + } + +#define DEF_MODEMAP(SYM, CODE, UCODE, CONST, LOAD, STORE) \ + { signed_mode_to_code_map[(int) SYM] = CODE; \ + unsigned_mode_to_code_map[(int) SYM] = UCODE; } +#include "modemap.def" +#undef DEF_MODEMAP + + /* Initialize opcode maps for const, load, and store */ + bc_init_mode_to_opcode_maps (); +} + +/* Given a machine mode return the preferred typecode. */ +enum typecode +preferred_typecode (mode, unsignedp) + enum machine_mode mode; + int unsignedp; +{ + enum typecode code = (unsignedp + ? unsigned_mode_to_code_map + : signed_mode_to_code_map) [MIN ((int) mode, + (int) MAX_MACHINE_MODE)]; + + if (code == LAST_AND_UNUSED_TYPECODE) + abort (); + + return code; +} + + +/* Expand a conversion between the given types. */ +void +bc_expand_conversion (from, to) + tree from, to; +{ + enum typecode fcode, tcode; + + fcode = preferred_typecode (TYPE_MODE (from), TREE_UNSIGNED (from)); + tcode = preferred_typecode (TYPE_MODE (to), TREE_UNSIGNED (to)); + + emit_typecode_conversion (fcode, tcode); +} + +/* Expand a conversion of the given type to a truth value. */ +void +bc_expand_truth_conversion (from) + tree from; +{ + enum typecode fcode; + + fcode = preferred_typecode (TYPE_MODE (from), TREE_UNSIGNED (from)); + emit_typecode_conversion (fcode, Tcode); +} + +/* Emit an appropriate binary operation. */ +void +bc_expand_binary_operation (optab, resulttype, arg0, arg1) + struct binary_operator optab[]; + tree resulttype, arg0, arg1; +{ + int i, besti, cost, bestcost; + enum typecode resultcode, arg0code, arg1code; + + resultcode = preferred_typecode (TYPE_MODE (resulttype), TREE_UNSIGNED (resulttype)); + arg0code = preferred_typecode (TYPE_MODE (TREE_TYPE (arg0)), TREE_UNSIGNED (resulttype)); + arg1code = preferred_typecode (TYPE_MODE (TREE_TYPE (arg1)), TREE_UNSIGNED (resulttype)); + + besti = -1; + bestcost = BIG_ARBITRARY_NUMBER; + + for (i = 0; optab[i].opcode != -1; ++i) + { + cost = 0; + DEDUCE_CONVERSION (arg0code, optab[i].arg0); + cost += conversion_recipe[(int) arg0code][(int) optab[i].arg0].cost; + DEDUCE_CONVERSION (arg1code, optab[i].arg1); + cost += conversion_recipe[(int) arg1code][(int) optab[i].arg1].cost; + if (cost < bestcost) + { + besti = i; + bestcost = cost; + } + } + + if (besti == -1) + abort (); + + expand_expr (arg1, 0, VOIDmode, 0); + emit_typecode_conversion (arg1code, optab[besti].arg1); + expand_expr (arg0, 0, VOIDmode, 0); + emit_typecode_conversion (arg0code, optab[besti].arg0); + bc_emit_instruction (optab[besti].opcode); + emit_typecode_conversion (optab[besti].result, resultcode); +} + +/* Emit an appropriate unary operation. */ +void +bc_expand_unary_operation (optab, resulttype, arg0) + struct unary_operator optab[]; + tree resulttype, arg0; +{ + int i, besti, cost, bestcost; + enum typecode resultcode, arg0code; + + resultcode = preferred_typecode (TYPE_MODE (resulttype), TREE_UNSIGNED (resulttype)); + arg0code = preferred_typecode (TYPE_MODE (TREE_TYPE (arg0)), TREE_UNSIGNED (TREE_TYPE (arg0))); + + besti = -1; + bestcost = BIG_ARBITRARY_NUMBER; + + for (i = 0; optab[i].opcode != -1; ++i) + { + DEDUCE_CONVERSION (arg0code, optab[i].arg0); + cost = conversion_recipe[(int) arg0code][(int) optab[i].arg0].cost; + if (cost < bestcost) + { + besti = i; + bestcost = cost; + } + } + + if (besti == -1) + abort (); + + expand_expr (arg0, 0, VOIDmode, 0); + emit_typecode_conversion (arg0code, optab[besti].arg0); + bc_emit_instruction (optab[besti].opcode); + emit_typecode_conversion (optab[besti].result, resultcode); +} + + +/* Emit an appropriate increment. */ +void +bc_expand_increment (optab, type) + struct increment_operator optab[]; + tree type; +{ + enum typecode code; + int i; + + code = preferred_typecode (TYPE_MODE (type), TREE_UNSIGNED (type)); + for (i = 0; (int) optab[i].opcode >= 0; ++i) + if (code == optab[i].arg) + { + bc_emit_instruction (optab[i].opcode); + return; + } + abort (); +} diff --git a/contrib/gcc/bc-optab.h b/contrib/gcc/bc-optab.h new file mode 100644 index 00000000000..6ad0b8592f6 --- /dev/null +++ b/contrib/gcc/bc-optab.h @@ -0,0 +1,75 @@ +/* Bytecode token definitions for GNU C-compiler. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +extern void bc_expand_conversion (); +extern void bc_expand_truth_conversion (); +extern void bc_expand_binary_operation (); +extern void bc_expand_unary_operation (); + +struct binary_operator +{ + enum bytecode_opcode opcode; + enum typecode result; + enum typecode arg0; + enum typecode arg1; +}; + +extern struct binary_operator optab_plus_expr[]; +extern struct binary_operator optab_minus_expr[]; +extern struct binary_operator optab_mult_expr[]; +extern struct binary_operator optab_trunc_div_expr[]; +extern struct binary_operator optab_trunc_mod_expr[]; +extern struct binary_operator optab_rdiv_expr[]; +extern struct binary_operator optab_bit_and_expr[]; +extern struct binary_operator optab_bit_ior_expr[]; +extern struct binary_operator optab_bit_xor_expr[]; +extern struct binary_operator optab_lshift_expr[]; +extern struct binary_operator optab_rshift_expr[]; +extern struct binary_operator optab_truth_and_expr[]; +extern struct binary_operator optab_truth_or_expr[]; +extern struct binary_operator optab_lt_expr[]; +extern struct binary_operator optab_le_expr[]; +extern struct binary_operator optab_ge_expr[]; +extern struct binary_operator optab_gt_expr[]; +extern struct binary_operator optab_eq_expr[]; +extern struct binary_operator optab_ne_expr[]; + +struct unary_operator +{ + enum bytecode_opcode opcode; + enum typecode result; + enum typecode arg0; +}; + +extern struct unary_operator optab_negate_expr[]; +extern struct unary_operator optab_bit_not_expr[]; +extern struct unary_operator optab_truth_not_expr[]; + +struct increment_operator +{ + enum bytecode_opcode opcode; + enum typecode arg; +}; + +extern struct increment_operator optab_predecrement_expr[]; +extern struct increment_operator optab_preincrement_expr[]; +extern struct increment_operator optab_postdecrement_expr[]; +extern struct increment_operator optab_postincrement_expr[]; diff --git a/contrib/gcc/bc-typecd.def b/contrib/gcc/bc-typecd.def new file mode 100644 index 00000000000..fd92cdd9282 --- /dev/null +++ b/contrib/gcc/bc-typecd.def @@ -0,0 +1,21 @@ +/* Typecodes used by the interpreter and their related + machine modes and types. + + The last argument is used for retrieving the given + type from a varargs list. Due to a bug in varargs, + the type has to be the generic machine type of + larger. */ + +DEFTYPECODE (QIcode, "QI", QImode, SItype) +DEFTYPECODE (QUcode, "QU", QImode, SUtype) +DEFTYPECODE (HIcode, "HI", HImode, SItype) +DEFTYPECODE (HUcode, "HU", HImode, SUtype) +DEFTYPECODE (SIcode, "SI", SImode, SItype) +DEFTYPECODE (SUcode, "SU", SImode, SUtype) +DEFTYPECODE (DIcode, "DI", DImode, DItype) +DEFTYPECODE (DUcode, "DU", DImode, DUtype) +DEFTYPECODE (SFcode, "SF", SFmode, SFtype) +DEFTYPECODE (DFcode, "DF", DFmode, DFtype) +DEFTYPECODE (XFcode, "XF", XFmode, XFtype) +DEFTYPECODE (Pcode, "P", PSImode, Ptype) +DEFTYPECODE (Tcode, "T", SImode, SItype) diff --git a/contrib/gcc/bc-typecd.h b/contrib/gcc/bc-typecd.h new file mode 100644 index 00000000000..2dcea0e08f5 --- /dev/null +++ b/contrib/gcc/bc-typecd.h @@ -0,0 +1,54 @@ +/* Typecode definitions for Bytecode Interpreter. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef TYPECODE_H +#define TYPECODE_H + +enum typecode +{ +#define DEFTYPECODE(CODE, NAME, MACHMODE, TYPE) CODE, +#include "bc-typecd.def" +#undef DEFTYPECODE + + LAST_AND_UNUSED_TYPECODE +}; + +/* Determine if a given type is integer. */ +#define TYPECODE_INTEGER_P(TYPECODE) ((int) (TYPECODE) < (int) SFcode) + +/* Determine if a given type is unsigned. */ +#define TYPECODE_UNSIGNED_P(TYPECODE) \ + (TYPECODE_INTEGER_P(TYPECODE) && (int) (TYPECODE) & 1) + +/* Determine if a given type is signed. */ +#define TYPECODE_SIGNED_P(TYPECODE) \ + (TYPECODE_INTEGER_P(TYPECODE) && !((int) (TYPECODE) & 1)) + +/* Determine if a given type is floating. */ +#define TYPECODE_FLOAT_P(TYPECODE) \ + ((int) (TYPECODE) < (int) Pcode && !TYPECODE_INTEGER_P(TYPECODE)) + +/* Determine if the given type is arithmetic. */ +#define TYPECODE_ARITH_P(TYPECODE) \ + (TYPECODE_INTEGER_P(TYPECODE) || TYPECODE_FLOAT_P(TYPECODE)) + +#define NUM_TYPECODES ((int) LAST_AND_UNUSED_TYPECODE) + +#endif diff --git a/contrib/gcc/bi-arity.c b/contrib/gcc/bi-arity.c new file mode 100644 index 00000000000..da3607fbf5d --- /dev/null +++ b/contrib/gcc/bi-arity.c @@ -0,0 +1,80 @@ +/* Bytecode Interpreter utility to generate arity table. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include +#include "hconfig.h" +#include "bi-defs.h" + +int +length (n) + struct node *n; +{ + int k; + + for (k = 0; n; n = n->next) + ++k; + return k; +} + +int +main () +{ + struct def *d; + struct variation *v; + struct node *n; + + yyparse (); + reverse (); + + for (d = defs; d; d = d->next) + for (v = d->variations; v; v = v->next) + { + printf ("{ %d, %d, %d, {", length (v->inputs), + length (v->outputs), length (v->literals)); + for (n = v->literals; n; n = n->next) + printf ("(char) %scode, ", n->text); + if (v->literals == 0) + printf ("0"); + printf ("}},\n"); + } + + fflush (stdout); + exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); + /* NOTREACHED */ + return 0; +} + +/* Safely allocate NBYTES bytes of memory. Returns pointer to block of + memory. */ +char * +xmalloc (nbytes) + int nbytes; +{ + char *tmp = (char *) malloc (nbytes); + + if (!tmp) + { + fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", nbytes); + exit (FATAL_EXIT_CODE); + } + + return tmp; +} diff --git a/contrib/gcc/bi-defs.h b/contrib/gcc/bi-defs.h new file mode 100644 index 00000000000..868312a847d --- /dev/null +++ b/contrib/gcc/bi-defs.h @@ -0,0 +1,48 @@ +/* Definitions for Bytecode Interpreter. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +struct node +{ + char *text; + struct node *next; +}; + +struct variation +{ + char *name; + int code; + struct node *inputs; + struct node *outputs; + struct node *literals; + struct variation *next; +}; + +struct def +{ + char *basename; + char *template; + struct variation *variations; + struct def *next; +}; + +extern struct def *defs; +extern int ndefs; +extern void reverse(); diff --git a/contrib/gcc/bi-lexer.c b/contrib/gcc/bi-lexer.c new file mode 100644 index 00000000000..6601c52c05b --- /dev/null +++ b/contrib/gcc/bi-lexer.c @@ -0,0 +1,167 @@ +/* Lexer for scanner of bytecode definition file. + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "hconfig.h" +#include "bi-parser.h" + + +/* Safely allocate NBYTES bytes of memory. Returns pointer to block of + memory. */ + +static char * +xmalloc (nbytes) + int nbytes; +{ + char *tmp = (char *) malloc (nbytes); + + if (!tmp) + { + fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", nbytes); + exit (FATAL_EXIT_CODE); + } + + return tmp; +} + + +/* Safely reallocate BLOCK so its size becomes NBYTES. + The block returned may be different from the one supplied. */ + +static char * +xrealloc (block, nbytes) + char *block; + int nbytes; +{ + char *tmp = (block + ? (char *) realloc (block, nbytes) + : (char *) malloc (nbytes)); + + if (!tmp) + { + fprintf (stderr, "can't reallocate %d bytes (out of virtual memory)\n", nbytes); + exit (FATAL_EXIT_CODE); + } + + return tmp; +} + + +/* Scan for string token on standard input. A string is, for our + purposes here, a sequence of characters that starts with the regexp + ``[^ #\t\n(),]'' and is then followed by the regexp ``[^#(),]*''. Any + character is accepted if preceded by a backslash, "\\". It is assumed + that the first character has already been checked by the main loop. */ + +static char * +scan_string () +{ + char *buffer = NULL; + char *point = NULL; + int buffer_size = 0; + int c; + + while ((c = getc (stdin)) != EOF + && c != '#' && c != '(' && c != ')' && c != ',') + { + /* Extend buffer, if necessary (minus two so there's room for the NUL + trailer as well as another character if this one is a backslash). */ + if (!buffer_size || (point - buffer >= buffer_size-2)) + { + int previous_point_index = point - buffer; + + buffer_size = (!buffer_size ? 32 : buffer_size * 2); + if (!buffer) + buffer = xmalloc (buffer_size); + else + buffer = xrealloc (buffer, buffer_size); + + point = buffer + previous_point_index; + } + *point++ = c & 0xff; + + if (c == '\\') + { + c = getc (stdin); + + /* Catch special case: backslash at end of file */ + if (c == EOF) + break; + + *point++ = c; + } + } + *point = 0; + + if (c != EOF) + ungetc (c, stdin); + + return buffer; +} + + +int +yylex () +{ + int c; + char *token; + + + /* First char determines what token we're looking at */ + for (;;) + { + c = getc (stdin); + + switch (c) + { + case EOF: + return 0; + + case ' ': + case '\t': + case '\n': + /* Ignore whitespace */ + continue; + + case '#': + /* Comments advance to next line */ + while ((c = getc (stdin)) != '\n' && c != EOF); + continue; + + default: + if (c != '(' && c != ')' && c != '\\' && c != ',') + { + ungetc (c, stdin); + yylval.string = scan_string (); + + /* Check if string is "define_operator"; if so, return + a DEFOP token instead. */ + if (!strcmp (yylval.string, "define_operator")) + { + free (yylval.string); + yylval.string = 0; + return DEFOP; + } + return STRING; + } + return c & 0xff; + } + } +} diff --git a/contrib/gcc/bi-opcode.c b/contrib/gcc/bi-opcode.c new file mode 100644 index 00000000000..6b1ebe4a69e --- /dev/null +++ b/contrib/gcc/bi-opcode.c @@ -0,0 +1,78 @@ +/* Utility to generate opcode list from bytecode definition. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "hconfig.h" +#include "bi-defs.h" + +int +main(argc, argv) + int argc; + char **argv; +{ + struct def *d; + struct variation *v; + int i; + + yyparse(); + reverse(); + + + printf ("/* This file is automatically generated from bytecode.def,\n"); + printf ("do not make any changes here. Instead edit bytecode.def. */\n\n"); + printf ("enum bytecode_opcode\n{"); + + i = 0; + for (d = defs; d; d = d->next) + for (v = d->variations; v; v = v->next) + { + printf (" %s%s,\n", d->basename, v->name); + ++i; + } + + puts (" LAST_AND_UNUSED_OPCODE\n};"); + + if (i > 256) + fprintf (stderr, "%s: warning, number of opcodes is %d\n", *argv, i); + else + fprintf (stderr, "(Number of opcodes is %d)\n", i); + + fflush (stdout); + exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); + /* NOTREACHED */ + return 0; +} + +/* Safely allocate NBYTES bytes of memory. Returns pointer to block of + memory. */ +char * +xmalloc (nbytes) + int nbytes; +{ + char *tmp = (char *) malloc (nbytes); + + if (!tmp) + { + fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", nbytes); + exit (FATAL_EXIT_CODE); + } + + return tmp; +} diff --git a/contrib/gcc/bi-opname.c b/contrib/gcc/bi-opname.c new file mode 100644 index 00000000000..1862e7120fb --- /dev/null +++ b/contrib/gcc/bi-opname.c @@ -0,0 +1,59 @@ +/* Utility to generate opcode name list from bytecode definition file. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "hconfig.h" +#include "bi-defs.h" + +int +main() +{ + struct def *d; + struct variation *v; + + yyparse(); + reverse(); + + for (d = defs; d; d = d->next) + for (v = d->variations; v; v = v->next) + printf("\"%s%s\",\n", d->basename, v->name); + + fflush (stdout); + exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); + /* NOTREACHED */ + return 0; +} + +/* Safely allocate NBYTES bytes of memory. Returns pointer to block of + memory. */ +char * +xmalloc (nbytes) + int nbytes; +{ + char *tmp = (char *) malloc (nbytes); + + if (!tmp) + { + fprintf (stderr, "can't allocate %d bytes (out of virtual memory)\n", nbytes); + exit (FATAL_EXIT_CODE); + } + + return tmp; +} diff --git a/contrib/gcc/bi-parser.y b/contrib/gcc/bi-parser.y new file mode 100644 index 00000000000..0a03d0f05ad --- /dev/null +++ b/contrib/gcc/bi-parser.y @@ -0,0 +1,169 @@ +/* Bytecode definition file parser. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +%{ + +#include +#include "hconfig.h" +#include "bi-defs.h" + +extern char yytext[]; +extern int yyleng; + + +/* Chain of all defs built by the parser. */ +struct def *defs; +int ndefs; + +static struct node *makenode (); +static struct variation *makevar (); +static struct def *makedef (); + +void yyerror (); + +%} + +%union +{ + char *string; + struct def *def; + struct variation *variation; + struct node *node; +} + +%token DEFOP STRING +%type opt_string +%type defs def +%type variations variation +%type list items item + +%% + +top: + defs + { defs = $1; } + ; + +defs: + def + | defs def + { $2->next = $1; $$ = $2; } + ; + +def: + DEFOP '(' STRING ',' opt_string ',' '(' variations ')' ')' + { $$ = makedef ($3, $5, $8); } + ; + +variations: + variation + | variations ',' variation + { $3->next = $1; $$ = $3; } + ; + +variation: + '(' opt_string ')' + { $$ = makevar ($2, (struct node *) NULL, (struct node *) NULL, (struct node *) NULL); } + | '(' opt_string ',' list ')' + { $$ = makevar ($2, $4, (struct node *) NULL, (struct node *) NULL); } + | '(' opt_string ',' list ',' list ')' + { $$ = makevar ($2, $4, $6, (struct node *) NULL); } + | '(' opt_string ',' list ',' list ',' list ')' + { $$ = makevar ($2, $4, $6, $8); } + ; + +opt_string: + /* empty */ { $$ = ""; } + | STRING { $$ = $1; } + ; + +list: + '(' items ')' + { $$ = $2; } + | /* empty */ + { $$ = NULL; } + ; + +items: + item + /* Note right recursion. */ + | item ',' items + { $1->next = $3; $$ = $1; } + ; + +item: + STRING + { $$ = makenode ($1); } + ; + +%% + +static struct node * +makenode (s) + char *s; +{ + struct node *n; + + n = (struct node *) malloc (sizeof (struct node)); + n->text = s; + n->next = NULL; + return n; +} + +static struct variation * +makevar (name, inputs, outputs, literals) + char *name; + struct node *inputs, *outputs, *literals; +{ + struct variation *v; + + v = (struct variation *) malloc (sizeof (struct variation)); + v->name = name; + v->code = ndefs++; + v->inputs = inputs; + v->outputs = outputs; + v->literals = literals; + v->next = NULL; + return v; +} + +static struct def * +makedef (name, template, vars) + char *name, *template; + struct variation *vars; +{ + struct def *d; + + d = (struct def *) malloc (sizeof (struct def)); + d->basename = name; + d->template = template; + d->variations = vars; + d->next = NULL; + return d; +} + +void +yyerror (s) + char *s; +{ + fprintf (stderr, "syntax error in input\n"); + exit (FATAL_EXIT_CODE); +} diff --git a/contrib/gcc/bi-reverse.c b/contrib/gcc/bi-reverse.c new file mode 100644 index 00000000000..6a84f827e73 --- /dev/null +++ b/contrib/gcc/bi-reverse.c @@ -0,0 +1,61 @@ +/* Reverse order of definitions obtained from bytecode definition file. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "hconfig.h" +#include "bi-defs.h" + +void +reverse() +{ + struct def *dp, *d, *dn; + struct variation *vp, *v, *vn; + + dp = defs; + if (dp) + { + vp = dp->variations; + if (vp) + { + for (v = vp->next, vp->next = 0; v; vp = v, v = vn) + { + vn = v->next; + v->next = vp; + } + dp->variations = vp; + } + for (d = dp->next, dp->next = 0; d; dp = d, d = dn) + { + vp = d->variations; + if (vp) + { + for (v = vp->next, vp->next = 0; v; vp = v, v = vn) + { + vn = v->next; + v->next = vp; + } + d->variations = vp; + } + dn = d->next; + d->next = dp; + } + defs = dp; + } +} diff --git a/contrib/gcc/bi-run.h b/contrib/gcc/bi-run.h new file mode 100644 index 00000000000..dc9192f78b8 --- /dev/null +++ b/contrib/gcc/bi-run.h @@ -0,0 +1,159 @@ +/* Definitions for Bytecode Interpreter. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define MAXLITERALS 5 + +struct arityvec +{ + char ninputs; + char noutputs; + char nliterals; + char literals[MAXLITERALS]; +}; + +struct argtype +{ + int modealign; /* Argument mode:alignment */ + int size; /* Argument size, in bytes */ +}; + +struct callinfo +{ + int nargs; /* Number of arguments in call */ + struct argtype retvaltype; /* Type of return value */ + struct argtype argtypes[1]; /* Argument types */ +}; + +/* Structure describing a bytecode function. If this changes, we also + need to change expand_function_end () in bc-trans.c */ +struct bytecode +{ + int stacksize; /* Depth required of evaluation stack. */ + int localsize; /* Size in bytes of local variables. */ + unsigned char *pc0; /* Initial program counter. */ + void **ptrlit; /* Vector of (relocatable) pointer literals. */ + struct callinfo *callinfo; /* Vector of procedure call type info. */ +}; + + +#define INTERP_BPC 8 /* Bits per char */ +#define INTERP_BPI \ + (sizeof (int) * INTERP_BPC) /* Bits per int */ + + +#ifndef min +#define min(L, R) ((L) < (R) ? (L) : (R)) +#endif + + +/* bit field operations. */ + +/* Low (high) mask: int with low (high) N bits set */ + +#define LM(N) ((1 << (N)) - 1) +#define HM(N) ((~LM (INTERP_BPI - (N)))) + + +/* Sign-extend SIZE low bits of VALUE to integer (typeof VALUE) + Signed bitfields are loaded from memory by the sxloadBI instruction, + which first retrieves the bitfield with XFIELD and then sign extends + it to an SItype. */ + +#define EXTEND(SIZE, VALUE) \ + ({ SUtype value = (SUtype) (VALUE); \ + (value & (1 << ((SIZE) - 1)) ? value | ~LM (SIZE) : value); }) + + +/* Given OFFSET:SIZE for a bitfield, calculate: + + [1] BYTE_OFFSET = the byte offset of the bit field. + [2] BIT_OFFSET = the bit offset of the bit field (less than INTERP_BPC). + [3] NBYTES = the number of integral bytes in the bit field. + [4] TRAILING_BITS= the number of trailing bits (less than INTERP_BPC). + + + , , , , , (memory bytes) + ---------------- (bitfield) + | | || | | (divisions) + ^ ^ ^ ^ + | | | |__ [4] (bits) + | | |_________ [3] (bytes) + | |_________________ [2] (bits) + |___________________________ [1] (bytes) + + + The above applies to BYTE_LOW_ENDIAN machines. In BYTE_BIG_ENDIAN machines, the + bit numbering is reversed (i.e. bit 0 is the sign bit). + + (All right, so I drew this to keep my tongue in cheek while writing the code below, + not because I'm into ASCII art.) */ + + +#define BI_PARAMS(OFFSET, SIZE, BYTE_OFFSET, BIT_OFFSET, NBYTES, TRAILING_BITS) \ + { BYTE_OFFSET = (OFFSET) / (INTERP_BPC); \ + BIT_OFFSET = (OFFSET) % (INTERP_BPC); \ + NBYTES = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) / INTERP_BPC; \ + if ((NBYTES) < 0 || ((NBYTES) > 64)) \ + NBYTES = 0; \ + if ((SIZE) + (BIT_OFFSET) <= INTERP_BPC) \ + TRAILING_BITS = 0; \ + else \ + TRAILING_BITS = ((SIZE) - (INTERP_BPC - (BIT_OFFSET))) % INTERP_BPC; } + + +/* SHIFT_IN_BITS retrieves NBITS bits from SOURCE and shifts into + DEST. The bit field starts OFFSET bits into SOURCE. + + OR_IN_BITS copies the NBITS low bits from VALUE into a the bitfield in + DEST offset by OFFSET bits. */ + + +#define SHIFT_IN_BITS(DEST, SOURCE, OFFSET, NBITS) \ + (DEST = ((DEST) << (NBITS)) \ + | (LM ((NBITS)) \ + & ((SOURCE) \ + >> (BYTES_BIG_ENDIAN \ + ? (INTERP_BPC - (OFFSET) - (NBITS)) \ + : (OFFSET))))) + +#define OR_IN_BITS(DEST, VALUE, OFFSET, NBITS) \ + (DEST = ((DEST) & ~(LM ((NBITS)) \ + << (BIG_ENDIAN \ + ? (INTERP_BPC - (OFFSET) - (NBITS)) \ + : (OFFSET))) \ + | (((VALUE) & LM ((NBITS))) \ + << (BIG_ENDIAN \ + ? (INTERP_BPC - (OFFSET) - (NBITS)) \ + : (OFFSET))))) + +/* Procedure call; arguments are a pointer to the function to be called, + a pointer to a place to store the return value, a pointer to a vector + describing the type of procedure call, and the interpreter's stack pointer, + which will point to the first of the arguments at this point. */ + +#define CALL(FUNC, CALLDESC, RETVAL, SP) __call(FUNC, CALLDESC, RETVAL, SP) + + +/* Procedure return; arguments are a pointer to the calldesc for this + function, and a pointer to the place where the value to be returned + may be found. Generally the MACHARGS above contain a machine dependent + cookie that is used to determine where to jump to. */ + +#define PROCRET(CALLDESC, RETVAL) return diff --git a/contrib/gcc/build-make b/contrib/gcc/build-make new file mode 100644 index 00000000000..1d6e18be6f8 --- /dev/null +++ b/contrib/gcc/build-make @@ -0,0 +1,32 @@ +# We have to use the cross-compiler we just built to compile it. +CC = gcc -b $(target) + +# Need those to compile binaries running on host machine. +# It is configured by +# +# configure --host=target_cpu-target_os \ +# --target=host=target_cpu-target_os --build=host_cpu-host_os +# +# That HOST stuff has to be taken care of very carefully. +HOST_PREFIX=l- +HOST_PREFIX_1=$(HOST_PREFIX) +HOST_CC=$(CC) -b $(build) +HOST_CFLAGS=$(INTERNAL_CFLAGS) $(T_CFLAGS) $(CFLAGS) $(XCFLAGS) +HOST_CLIB= +HOST_LDFLAGS=$(LDFLAGS) +HOST_CPPFLAGS=$(ALL_CPPFLAGS) +HOST_ALLOCA=$(ALLOCA) +HOST_MALLOC=$(MALLOC) +HOST_OBSTACK=$(OBSTACK) + +# To build the native compiler with the cross compiler, the headers +# for the target are already fixed. And /usr/include is for host, not +# target. +FIXINCLUDES=Makefile.in + +# Cause installation using install-build. We do nothing here. +INSTALL_TARGET = install-build + +# Don't try to compile the things we can't compile or we have made +# while making gcc with the cross-compiler. +ALL = all.build diff --git a/contrib/gcc/bytecode.def b/contrib/gcc/bytecode.def new file mode 100644 index 00000000000..5b24df70ed6 --- /dev/null +++ b/contrib/gcc/bytecode.def @@ -0,0 +1,322 @@ +# -*- C -*- +# bytecode.def - definitions of bytecodes for the stack machine. + +# The production of the bytecode interpreter and compiler is +# heavily automated by using this file creatively. + +# Various elementary data types are understood by the bytecode interpreter. +# Q[IU] - quarter word (byte) signed and unsigned integers (char). +# H[IU] - half word signed and unsigned integers (short int, maybe int). +# S[IU] - single word signed and unsigned integers (maybe int, long int). +# D[IU] - double word signed and unsigned integers (long long int). +# SF - single precision floating point (float). +# DF - double precision floating point (double). +# XF - extended precision floating point (long double). +# P - pointer type for address arithmetic and other purposes. + +# The bytecode specification consists of a series of define_operator +# forms, that are parsed by preprocessors to automatically build +# various switch statements. +# define_operator(name, +# , +# ) +# The is self explanatory. +# The consists of a (parenthesized list) of +# variation items, each of which is in itself a list. A variation +# item consists of a name suffix, the types of the input arguments +# expected on the stack (shallowest item first) and (optionally) the +# types of the output arguments (similarly ordered). Finally, the +# types of the literal arguments (if any) may appear. + +# Substitution in the C prototype code is as follows: +# Substitution happens only after a dollar sign. To get a literal +# dollar sign (why would you ever want one anyway?) use $$. +# $R1 means "result 1" $TR1 means "type name of result one" +# $S1 means "source 1" and similarly with $TS1. +# $L1 means "literal (inline) argument 1" and $TL1 means type thereof. +# + +# Notice that the number following $R doesn't affect the push order; +# it's used only for clarity and orthogonality, although it's checked +# to make sure it doesn't exceed the number of outputs. A $R reference +# results in a push, and represents the result lvalue. E.g. + +# $R1 = 2\, $R2 = 17 +# will expand to: +# INTERP_PUSH($TR1) = 2, INTERP_PUSH($TR2) = 17 +# + +# Opcode 0 should never happen. +define_operator(neverneverland, abort\(\), (())) + +# Stack manipulations. +define_operator(drop, 0, ((, (SI)))) +define_operator(duplicate, 0, ((, (SI), (SI, SI)))) +define_operator(over, 0, ((, (SI), (SI, SI)))) + +# Adjust stack pointer + +define_operator(setstack, 0, ((SI,,,(SI)))) +define_operator(adjstack, 0, ((SI,,,(SI)))) + +# Constants, loads, and stores. +define_operator(const, + $R1 = $L1, + ((QI,, (QI), (QI)), (HI,, (HI), (HI)), + (SI,, (SI), (SI)), (DI,, (DI), (DI)), + (SF,, (SF), (SF)), (DF,, (DF), (DF)), + (XF,, (XF), (XF)), (P,, (P), (P)))) +define_operator(load, + $R1 = *\($TR1 *\) $S1, + ((QI, (P), (QI)), (HI, (P), (HI)), + (SI, (P), (SI)), (DI, (P), (DI)), + (SF, (P), (SF)), (DF, (P), (DF)), + (XF, (P), (XF)), (P, (P), (P)))) +define_operator(store, + *\($TS2 *\) $S1 = $S2, + ((QI, (P, QI)), (HI, (P, HI)), + (SI, (P, SI)), (DI, (P, DI)), + (SF, (P, SF)), (DF, (P, DF)), + (XF, (P, XF)), (P, (P, P)), + (BLK, (SI, BLK, BLK)))) + +# Clear memory block + +define_operator(clear, $S1 + $S2, ((BLK, (SI, BLK)))) + + +# Advance pointer by SI constant + +define_operator(addconst, $R1 = $S1, ((PSI, (P), (P), (SI)))) + + +# newlocalSI is used for creating variable-sized storage during function +# initialization. + +# Create local space, return pointer to block + +define_operator(newlocal, $R1 = $S1, ((SI, (SI), (P)))) + + +# Push the address of a local variable. +define_operator(local, $R1 = locals + $L1, ((P,, (P), (SI)))) + +# Push the address of an argument variable. +define_operator(arg, $R1 = args + $L1, ((P,, (P), (SI)))) + +# Arithmetic conversions. +define_operator(convert, + $R1 = \($TR1\) $S1, + (# Signed integral promotions (sign extensions). + (QIHI, (QI), (HI)), (HISI, (HI), (SI)), (SIDI, (SI), (DI)), + (QISI, (QI), (SI)), + # Unsigned integral promotions (zero extensions). + (QUHU, (QU), (HU)), (HUSU, (HU), (SU)), (SUDU, (SU), (DU)), + (QUSU, (QU), (SU)), + # Floating promotions. + (SFDF, (SF), (DF)), (DFXF, (DF), (XF)), + # Integral truncation. + (HIQI, (HI), (QI)), (SIHI, (SI), (HI)), (DISI, (DI), (SI)), + (SIQI, (SI), (QI)), + # Unsigned truncation. + (SUQU, (SU), (QU)), + # Floating truncation. + (DFSF, (DF), (SF)), (XFDF, (XF), (DF)), + # Integral conversions to floating types. + (SISF, (SI), (SF)), (SIDF, (SI), (DF)), (SIXF, (SI), (XF)), + (SUSF, (SU), (SF)), (SUDF, (SU), (DF)), (SUXF, (SU), (XF)), + (DISF, (DI), (SF)), (DIDF, (DI), (DF)), (DIXF, (DI), (XF)), + (DUSF, (DU), (SF)), (DUDF, (DU), (DF)), (DUXF, (DU), (XF)), + # Floating conversions to integral types. + (SFSI, (SF), (SI)), (DFSI, (DF), (SI)), (XFSI, (XF), (SI)), + (SFSU, (SF), (SU)), (DFSU, (DF), (SU)), (XFSU, (XF), (SU)), + (SFDI, (SF), (DI)), (DFDI, (DF), (DI)), (XFDI, (XF), (DI)), + (SFDU, (SF), (DU)), (DFDU, (DF), (DU)), (XFDU, (XF), (DU)), + # Pointer/integer conversions. + (PSI, (P), (SI)), (SIP, (SI), (P)))) + +# Truth value conversion. These are necessary because conversions of, e.g., +# floating types to integers may not function correctly for large values. +define_operator(convert, + $R1 = !!$S1, + ((SIT, (SI), (T)), (DIT, (DI), (T)), + (SFT, (SF), (T)), (DFT, (DF), (T)), + (XFT, (XF), (T)), (PT, (P), (T)))) + +# Bit field load/store. + +# Load and zero-extend bitfield + +define_operator(zxload, $R1 = $S1, ((BI, (SU, SU, P), (SU)))) + +# Load and sign-extend bitfield + +define_operator(sxload, $R1 = $S1, ((BI, (SU, SU, P), (SI)))) + +# Store integer in bitfield + +define_operator(sstore, $R1 = $S1, ((BI, (SU, SU, P, SI)))) + + +# Binary operations. +define_operator(add, + $R1 = $S1 + $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)), + (SF, (SF, SF), (SF)), (DF, (DF, DF), (DF)), + (XF, (XF, XF), (XF)), + (PSI, (P, SI), (P)))) +define_operator(sub, + $R1 = $S1 - $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)), + (SF, (SF, SF), (SF)), (DF, (DF, DF), (DF)), + (XF, (XF, XF), (XF)), + (PP, (P, P), (SI)))) +define_operator(mul, + $R1 = $S1 * $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)), + (SU, (SU, SU), (SU)), (DU, (DU, DU), (DU)), + (SF, (SF, SF), (SF)), (DF, (DF, DF), (DF)), + (XF, (XF, XF), (XF)))) +define_operator(div, + $R1 = $S1 / $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)), + (SU, (SU, SU), (SU)), (DU, (DU, DU), (DU)), + (SF, (SF, SF), (SF)), (DF, (DF, DF), (DF)), + (XF, (XF, XF), (XF)))) +define_operator(mod, + $R1 = $S1 % $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)), + (SU, (SU, SU), (SU)), (DU, (DU, DU), (DU)))) +define_operator(and, + $R1 = $S1 & $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)))) +define_operator(ior, + $R1 = $S1 | $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)))) +define_operator(xor, + $R1 = $S1 ^ $S2, + ((SI, (SI, SI), (SI)), (DI, (DI, DI), (DI)))) +define_operator(lshift, + $R1 = $S1 << $S2, + ((SI, (SI, SI), (SI)), (SU, (SU, SI), (SU)), + (DI, (DI, SI), (DI)), (DU, (DU, SI), (DU)))) +define_operator(rshift, + $R1 = $S1 >> $S2, + ((SI, (SI, SI), (SI)), (SU, (SU, SI), (SU)), + (DI, (DI, SI), (DI)), (DU, (DU, SI), (DU)))) +define_operator(lt, + $R1 = $S1 < $S2, + ((SI, (SI, SI), (T)), (SU, (SU, SU), (T)), + (DI, (DI, DI), (T)), (DU, (DU, DU), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) +define_operator(le, + $R1 = $S1 <= $S2, + ((SI, (SI, SI), (T)), (SU, (SU, SU), (T)), + (DI, (DI, DI), (T)), (DU, (DU, DU), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) +define_operator(ge, + $R1 = $S1 >= $S2, + ((SI, (SI, SI), (T)), (SU, (SU, SU), (T)), + (DI, (DI, DI), (T)), (DU, (DU, DU), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) +define_operator(gt, + $R1 = $S1 > $S2, + ((SI, (SI, SI), (T)), (SU, (SU, SU), (T)), + (DI, (DI, DI), (T)), (DU, (DU, DU), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) +define_operator(eq, + $R1 = $S1 == $S2, + ((SI, (SI, SI), (T)), (DI, (DI, DI), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) +define_operator(ne, + $R1 = $S1 != $S2, + ((SI, (SI, SI), (T)), (DI, (DI, DI), (T)), + (SF, (SF, SF), (T)), (DF, (DF, DF), (T)), + (XF, (XF, XF), (T)), (P, (P, P), (T)))) + +# Unary operations. +define_operator(neg, + $R1 = -$S1, + ((SI, (SI), (SI)), (DI, (DI), (DI)), + (SF, (SF), (SF)), (DF, (DF), (DF)), + (XF, (XF), (XF)))) +define_operator(not, + $R1 = ~$S1, + ((SI, (SI), (SI)), (DI, (DI), (DI)))) +define_operator(not, + $R1 = !$S1, + ((T, (SI), (SI)))) + +# Increment operations. +define_operator(predec, + $R1 = *\($TR1 *\) $S1 -= $S2, + ((QI, (P, QI), (QI)), (HI, (P, HI), (HI)), + (SI, (P, SI), (SI)), (DI, (P, DI), (DI)), + (P, (P, SI), (P)), (SF, (P, SF), (SF)), + (DF, (P, DF), (DF)), (XF, (P, XF), (XF)), + (BI, (SU, SU, P, SI), (SI)))) + +define_operator(preinc, + $R1 = *\($TR1 *\) $S1 += $S2, + ((QI, (P, QI), (QI)), (HI, (P, HI), (HI)), + (SI, (P, SI), (SI)), (DI, (P, DI), (DI)), + (P, (P, SI), (P)), (SF, (P, SF), (SF)), + (DF, (P, DF), (DF)), (XF, (P, XF), (XF)), + (BI, (SU, SU, P, SI), (SI)))) + +define_operator(postdec, + $R1 = *\($TR1 *\) $S1\, *\($TR1 *\) $S1 -= $S2, + ((QI, (P, QI), (QI)), (HI, (P, HI), (HI)), + (SI, (P, SI), (SI)), (DI, (P, DI), (DI)), + (P, (P, SI), (P)), (SF, (P, SF), (SF)), + (DF, (P, DF), (DF)), (XF, (P, XF), (XF)), + (BI, (SU, SU, P, SI), (SI)))) + +define_operator(postinc, + $R1 = *\($TR1 *\) $S1\, *\($TR1 *\) $S1 += $S2, + ((QI, (P, QI), (QI)), (HI, (P, HI), (HI)), + (SI, (P, SI), (SI)), (DI, (P, DI), (DI)), + (P, (P, SI), (P)), (SF, (P, SF), (SF)), + (DF, (P, DF), (DF)), (XF, (P, XF), (XF)), + (BI, (SU, SU, P, SI), (SI)))) + +# Jumps. +define_operator(xjumpif, if \($S1\) pc = code->pc0 + $L1, ((, (T),, (SI)))) +define_operator(xjumpifnot, if \(! $S1\) pc = code->pc0 + $L1, ((, (T),, (SI)))) +define_operator(jump, pc = code->pc0 + $L1, ((,,,(SI)))) + +# This is for GCC2. It jumps to the address on the stack. +define_operator(jump, pc = \(void *\) $S1, ((P,,))) + +# Switches. In order to (eventually) support ranges we provide four different +# varieties of switches. Arguments are the switch index from the stack, the +# bytecode offset of the switch table, the size of the switch table, and +# the default label. +define_operator(caseSI, CASESI\($S1\, $L1\, $L2\, $L3\), ((, (SI),, (SI, SI, SI)))) +define_operator(caseSU, CASESU\($S1\, $L1\, $L2\, $L3\), ((, (SU),, (SI, SI, SI)))) +define_operator(caseDI, CASEDI\($S1\, $L1\, $L2\, $L3\), ((, (DI),, (SI, SI, SI)))) +define_operator(caseDU, CASEDU\($S1\, $L1\, $L2\, $L3\), ((, (DU),, (SI, SI, SI)))) + +# Procedure call. +# Stack arguments are (deepest first): +# procedure arguments in reverse order. +# pointer to the place to hold the return value. +# address of the call description vector. +# pointer to the procedure to be called. +define_operator(call, CALL\($S1\, $S2\, $S3\, sp\), ((, (P, P, P)))) + +# Procedure return. +# Pushes on interpreter stack: +# value of retptr (pointer to return value storage slot) +define_operator(return, $R1 = retptr, ((P,,(P)))) + +# Really return. +define_operator(ret, return, (())) + +# Print an obnoxious line number. +define_operator(linenote, fprintf\(stderr\, "%d\\n"\, $L1\), ((,,,(SI)))) diff --git a/contrib/gcc/bytecode.h b/contrib/gcc/bytecode.h new file mode 100644 index 00000000000..f2233aa880d --- /dev/null +++ b/contrib/gcc/bytecode.h @@ -0,0 +1,81 @@ +/* Bytecode definitions for GNU C-compiler. + Copyright (C) 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +extern int output_bytecode; +extern int stack_depth; +extern int max_stack_depth; + +/* Emit DI constant according to target machine word ordering */ + +#define bc_emit_bytecode_DI_const(CST) \ +{ int opcode; \ + opcode = (WORDS_BIG_ENDIAN \ + ? TREE_INT_CST_HIGH (CST) \ + : TREE_INT_CST_LOW (CST)); \ + bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \ + opcode = (WORDS_BIG_ENDIAN \ + ? TREE_INT_CST_LOW (CST) \ + : TREE_INT_CST_HIGH (CST)); \ + bc_emit_bytecode_const ((char *) &opcode, sizeof opcode); \ +} + +extern void bc_expand_expr (); +extern void bc_output_data_constructor (); +extern void bc_store_field (); +extern void bc_load_bit_field (); +extern void bc_store_bit_field (); +extern void bc_push_offset_and_size (); +extern void bc_init_mode_to_code_map (); + +/* These are just stubs, so the compiler will compile for targets + that aren't yet supported by the bytecode generator. */ + +#ifndef TARGET_SUPPORTS_BYTECODE + +#define MACHINE_SEG_ALIGN 1 +#define INT_ALIGN 1 +#define PTR_ALIGN 1 +#define NAMES_HAVE_UNDERSCORES +#define BC_NOP (0) +#define BC_GLOBALIZE_LABEL(FP, NAME) BC_NOP +#define BC_OUTPUT_COMMON(FP, NAME, SIZE, ROUNDED) BC_NOP +#define BC_OUTPUT_LOCAL(FP, NAME, SIZE, ROUNDED) BC_NOP +#define BC_OUTPUT_ALIGN(FP, ALIGN) BC_NOP +#define BC_OUTPUT_LABEL(FP, NAME) BC_NOP +#define BC_OUTPUT_SKIP(FP, SIZE) BC_NOP +#define BC_OUTPUT_LABELREF(FP, NAME) BC_NOP +#define BC_OUTPUT_FLOAT(FP, VAL) BC_NOP +#define BC_OUTPUT_DOUBLE(FP, VAL) BC_NOP +#define BC_OUTPUT_BYTE(FP, VAL) BC_NOP +#define BC_OUTPUT_FILE ASM_OUTPUT_FILE +#define BC_OUTPUT_ASCII ASM_OUTPUT_ASCII +#define BC_OUTPUT_IDENT ASM_OUTPUT_IDENT +#define BCXSTR(RTX) ((RTX)->bc_label) +#define BC_WRITE_FILE(FP) BC_NOP +#define BC_WRITE_SEGSYM(SEGSYM, FP) BC_NOP +#define BC_WRITE_RELOC_ENTRY(SEGRELOC, FP, OFFSET) BC_NOP +#define BC_START_BYTECODE_LINE(FP) BC_NOP +#define BC_WRITE_BYTECODE(SEP, VAL, FP) BC_NOP +#define BC_WRITE_RTL(R, FP) BC_NOP +#define BC_EMIT_TRAMPOLINE(TRAMPSEG, CALLINFO) BC_NOP +#define VALIDATE_STACK BC_NOP + +#endif /* !TARGET_SUPPORTS_BYTECODE */ diff --git a/contrib/gcc/bytetypes.h b/contrib/gcc/bytetypes.h new file mode 100644 index 00000000000..f91566900c6 --- /dev/null +++ b/contrib/gcc/bytetypes.h @@ -0,0 +1,35 @@ +/* These should come from genemit */ + +/* Use __signed__ in case compiling with -traditional. */ + +typedef __signed__ char QItype; +typedef unsigned char QUtype; +typedef __signed__ short int HItype; +typedef unsigned short int HUtype; +typedef __signed__ long int SItype; +typedef unsigned long int SUtype; +typedef __signed__ long long int DItype; +typedef unsigned long long int DUtype; +typedef float SFtype; +typedef double DFtype; +typedef long double XFtype; +typedef char *Ptype; +typedef int Ttype; + + +typedef union stacktype +{ + QItype QIval; + QUtype QUval; + HItype HIval; + HUtype HUval; + SItype SIval; + SUtype SUval; + DItype DIval; + DUtype DUval; + SFtype SFval; + DFtype DFval; + XFtype XFval; + Ptype Pval; + Ttype Tval; +} stacktype; diff --git a/contrib/gcc/c-aux-info.c b/contrib/gcc/c-aux-info.c new file mode 100644 index 00000000000..d8caa6af194 --- /dev/null +++ b/contrib/gcc/c-aux-info.c @@ -0,0 +1,644 @@ +/* Generate information regarding function declarations and definitions based + on information stored in GCC's tree structure. This code implements the + -aux-info option. + Copyright (C) 1989, 1991, 1994, 1995 Free Software Foundation, Inc. + Contributed by Ron Guilmette (rfg@segfault.us.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "config.h" +#include "flags.h" +#include "tree.h" +#include "c-tree.h" + +extern char* xmalloc (); + +enum formals_style_enum { + ansi, + k_and_r_names, + k_and_r_decls +}; +typedef enum formals_style_enum formals_style; + + +static char* data_type; + +static char * concat (); +static char * concat3 (); +static char * gen_formal_list_for_type (); +static int deserves_ellipsis (); +static char * gen_formal_list_for_func_def (); +static char * gen_type (); +static char * gen_decl (); +void gen_aux_info_record (); + +/* Take two strings and mash them together into a newly allocated area. */ + +static char* +concat (s1, s2) + char* s1; + char* s2; +{ + int size1, size2; + char* ret_val; + + if (!s1) + s1 = ""; + if (!s2) + s2 = ""; + + size1 = strlen (s1); + size2 = strlen (s2); + ret_val = xmalloc (size1 + size2 + 1); + strcpy (ret_val, s1); + strcpy (&ret_val[size1], s2); + return ret_val; +} + +/* Take three strings and mash them together into a newly allocated area. */ + +static char* +concat3 (s1, s2, s3) + char* s1; + char* s2; + char* s3; +{ + int size1, size2, size3; + char* ret_val; + + if (!s1) + s1 = ""; + if (!s2) + s2 = ""; + if (!s3) + s3 = ""; + + size1 = strlen (s1); + size2 = strlen (s2); + size3 = strlen (s3); + ret_val = xmalloc (size1 + size2 + size3 + 1); + strcpy (ret_val, s1); + strcpy (&ret_val[size1], s2); + strcpy (&ret_val[size1+size2], s3); + return ret_val; +} + +/* Given a string representing an entire type or an entire declaration + which only lacks the actual "data-type" specifier (at its left end), + affix the data-type specifier to the left end of the given type + specification or object declaration. + + Because of C language weirdness, the data-type specifier (which normally + goes in at the very left end) may have to be slipped in just to the + right of any leading "const" or "volatile" qualifiers (there may be more + than one). Actually this may not be strictly necessary because it seems + that GCC (at least) accepts ` const foo;' and treats it the + same as `const foo;' but people are accustomed to seeing + `const char *foo;' and *not* `char const *foo;' so we try to create types + that look as expected. */ + +static char* +affix_data_type (type_or_decl) + char *type_or_decl; +{ + char *p = type_or_decl; + char *qualifiers_then_data_type; + char saved; + + /* Skip as many leading const's or volatile's as there are. */ + + for (;;) + { + if (!strncmp (p, "volatile ", 9)) + { + p += 9; + continue; + } + if (!strncmp (p, "const ", 6)) + { + p += 6; + continue; + } + break; + } + + /* p now points to the place where we can insert the data type. We have to + add a blank after the data-type of course. */ + + if (p == type_or_decl) + return concat3 (data_type, " ", type_or_decl); + + saved = *p; + *p = '\0'; + qualifiers_then_data_type = concat (type_or_decl, data_type); + *p = saved; + return concat3 (qualifiers_then_data_type, " ", p); +} + +/* Given a tree node which represents some "function type", generate the + source code version of a formal parameter list (of some given style) for + this function type. Return the whole formal parameter list (including + a pair of surrounding parens) as a string. Note that if the style + we are currently aiming for is non-ansi, then we just return a pair + of empty parens here. */ + +static char* +gen_formal_list_for_type (fntype, style) + tree fntype; + formals_style style; +{ + char* formal_list = ""; + tree formal_type; + + if (style != ansi) + return "()"; + + formal_type = TYPE_ARG_TYPES (fntype); + while (formal_type && TREE_VALUE (formal_type) != void_type_node) + { + char* this_type; + + if (*formal_list) + formal_list = concat (formal_list, ", "); + + this_type = gen_type ("", TREE_VALUE (formal_type), ansi); + formal_list = + (strlen (this_type)) + ? concat (formal_list, affix_data_type (this_type)) + : concat (formal_list, data_type); + + formal_type = TREE_CHAIN (formal_type); + } + + /* If we got to here, then we are trying to generate an ANSI style formal + parameters list. + + New style prototyped ANSI formal parameter lists should in theory always + contain some stuff between the opening and closing parens, even if it is + only "void". + + The brutal truth though is that there is lots of old K&R code out there + which contains declarations of "pointer-to-function" parameters and + these almost never have fully specified formal parameter lists associated + with them. That is, the pointer-to-function parameters are declared + with just empty parameter lists. + + In cases such as these, protoize should really insert *something* into + the vacant parameter lists, but what? It has no basis on which to insert + anything in particular. + + Here, we make life easy for protoize by trying to distinguish between + K&R empty parameter lists and new-style prototyped parameter lists + that actually contain "void". In the latter case we (obviously) want + to output the "void" verbatim, and that what we do. In the former case, + we do our best to give protoize something nice to insert. + + This "something nice" should be something that is still valid (when + re-compiled) but something that can clearly indicate to the user that + more typing information (for the parameter list) should be added (by + hand) at some convenient moment. + + The string chosen here is a comment with question marks in it. */ + + if (!*formal_list) + { + if (TYPE_ARG_TYPES (fntype)) + /* assert (TREE_VALUE (TYPE_ARG_TYPES (fntype)) == void_type_node); */ + formal_list = "void"; + else + formal_list = "/* ??? */"; + } + else + { + /* If there were at least some parameters, and if the formals-types-list + petered out to a NULL (i.e. without being terminated by a + void_type_node) then we need to tack on an ellipsis. */ + if (!formal_type) + formal_list = concat (formal_list, ", ..."); + } + + return concat3 (" (", formal_list, ")"); +} + +/* For the generation of an ANSI prototype for a function definition, we have + to look at the formal parameter list of the function's own "type" to + determine if the function's formal parameter list should end with an + ellipsis. Given a tree node, the following function will return non-zero + if the "function type" parameter list should end with an ellipsis. */ + +static int +deserves_ellipsis (fntype) + tree fntype; +{ + tree formal_type; + + formal_type = TYPE_ARG_TYPES (fntype); + while (formal_type && TREE_VALUE (formal_type) != void_type_node) + formal_type = TREE_CHAIN (formal_type); + + /* If there were at least some parameters, and if the formals-types-list + petered out to a NULL (i.e. without being terminated by a void_type_node) + then we need to tack on an ellipsis. */ + + return (!formal_type && TYPE_ARG_TYPES (fntype)); +} + +/* Generate a parameter list for a function definition (in some given style). + + Note that this routine has to be separate (and different) from the code that + generates the prototype parameter lists for function declarations, because + in the case of a function declaration, all we have to go on is a tree node + representing the function's own "function type". This can tell us the types + of all of the formal parameters for the function, but it cannot tell us the + actual *names* of each of the formal parameters. We need to output those + parameter names for each function definition. + + This routine gets a pointer to a tree node which represents the actual + declaration of the given function, and this DECL node has a list of formal + parameter (variable) declarations attached to it. These formal parameter + (variable) declaration nodes give us the actual names of the formal + parameters for the given function definition. + + This routine returns a string which is the source form for the entire + function formal parameter list. */ + +static char* +gen_formal_list_for_func_def (fndecl, style) + tree fndecl; + formals_style style; +{ + char* formal_list = ""; + tree formal_decl; + + formal_decl = DECL_ARGUMENTS (fndecl); + while (formal_decl) + { + char *this_formal; + + if (*formal_list && ((style == ansi) || (style == k_and_r_names))) + formal_list = concat (formal_list, ", "); + this_formal = gen_decl (formal_decl, 0, style); + if (style == k_and_r_decls) + formal_list = concat3 (formal_list, this_formal, "; "); + else + formal_list = concat (formal_list, this_formal); + formal_decl = TREE_CHAIN (formal_decl); + } + if (style == ansi) + { + if (!DECL_ARGUMENTS (fndecl)) + formal_list = concat (formal_list, "void"); + if (deserves_ellipsis (TREE_TYPE (fndecl))) + formal_list = concat (formal_list, ", ..."); + } + if ((style == ansi) || (style == k_and_r_names)) + formal_list = concat3 (" (", formal_list, ")"); + return formal_list; +} + +/* Generate a string which is the source code form for a given type (t). This + routine is ugly and complex because the C syntax for declarations is ugly + and complex. This routine is straightforward so long as *no* pointer types, + array types, or function types are involved. + + In the simple cases, this routine will return the (string) value which was + passed in as the "ret_val" argument. Usually, this starts out either as an + empty string, or as the name of the declared item (i.e. the formal function + parameter variable). + + This routine will also return with the global variable "data_type" set to + some string value which is the "basic" data-type of the given complete type. + This "data_type" string can be concatenated onto the front of the returned + string after this routine returns to its caller. + + In complicated cases involving pointer types, array types, or function + types, the C declaration syntax requires an "inside out" approach, i.e. if + you have a type which is a "pointer-to-function" type, you need to handle + the "pointer" part first, but it also has to be "innermost" (relative to + the declaration stuff for the "function" type). Thus, is this case, you + must prepend a "(*" and append a ")" to the name of the item (i.e. formal + variable). Then you must append and prepend the other info for the + "function type" part of the overall type. + + To handle the "innermost precedence" rules of complicated C declarators, we + do the following (in this routine). The input parameter called "ret_val" + is treated as a "seed". Each time gen_type is called (perhaps recursively) + some additional strings may be appended or prepended (or both) to the "seed" + string. If yet another (lower) level of the GCC tree exists for the given + type (as in the case of a pointer type, an array type, or a function type) + then the (wrapped) seed is passed to a (recursive) invocation of gen_type() + this recursive invocation may again "wrap" the (new) seed with yet more + declarator stuff, by appending, prepending (or both). By the time the + recursion bottoms out, the "seed value" at that point will have a value + which is (almost) the complete source version of the declarator (except + for the data_type info). Thus, this deepest "seed" value is simply passed + back up through all of the recursive calls until it is given (as the return + value) to the initial caller of the gen_type() routine. All that remains + to do at this point is for the initial caller to prepend the "data_type" + string onto the returned "seed". */ + +static char* +gen_type (ret_val, t, style) + char* ret_val; + tree t; + formals_style style; +{ + tree chain_p; + + if (TYPE_NAME (t) && DECL_NAME (TYPE_NAME (t))) + data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t))); + else + { + switch (TREE_CODE (t)) + { + case POINTER_TYPE: + if (TYPE_READONLY (t)) + ret_val = concat ("const ", ret_val); + if (TYPE_VOLATILE (t)) + ret_val = concat ("volatile ", ret_val); + + ret_val = concat ("*", ret_val); + + if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE || TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) + ret_val = concat3 ("(", ret_val, ")"); + + ret_val = gen_type (ret_val, TREE_TYPE (t), style); + + return ret_val; + + case ARRAY_TYPE: + if (TYPE_SIZE (t) == 0 || TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST) + ret_val = gen_type (concat (ret_val, "[]"), TREE_TYPE (t), style); + else if (int_size_in_bytes (t) == 0) + ret_val = gen_type (concat (ret_val, "[0]"), TREE_TYPE (t), style); + else + { + int size = (int_size_in_bytes (t) / int_size_in_bytes (TREE_TYPE (t))); + char buff[10]; + sprintf (buff, "[%d]", size); + ret_val = gen_type (concat (ret_val, buff), + TREE_TYPE (t), style); + } + break; + + case FUNCTION_TYPE: + ret_val = gen_type (concat (ret_val, gen_formal_list_for_type (t, style)), TREE_TYPE (t), style); + break; + + case IDENTIFIER_NODE: + data_type = IDENTIFIER_POINTER (t); + break; + + /* The following three cases are complicated by the fact that a + user may do something really stupid, like creating a brand new + "anonymous" type specification in a formal argument list (or as + part of a function return type specification). For example: + + int f (enum { red, green, blue } color); + + In such cases, we have no name that we can put into the prototype + to represent the (anonymous) type. Thus, we have to generate the + whole darn type specification. Yuck! */ + + case RECORD_TYPE: + if (TYPE_NAME (t)) + data_type = IDENTIFIER_POINTER (TYPE_NAME (t)); + else + { + data_type = ""; + chain_p = TYPE_FIELDS (t); + while (chain_p) + { + data_type = concat (data_type, gen_decl (chain_p, 0, ansi)); + chain_p = TREE_CHAIN (chain_p); + data_type = concat (data_type, "; "); + } + data_type = concat3 ("{ ", data_type, "}"); + } + data_type = concat ("struct ", data_type); + break; + + case UNION_TYPE: + if (TYPE_NAME (t)) + data_type = IDENTIFIER_POINTER (TYPE_NAME (t)); + else + { + data_type = ""; + chain_p = TYPE_FIELDS (t); + while (chain_p) + { + data_type = concat (data_type, gen_decl (chain_p, 0, ansi)); + chain_p = TREE_CHAIN (chain_p); + data_type = concat (data_type, "; "); + } + data_type = concat3 ("{ ", data_type, "}"); + } + data_type = concat ("union ", data_type); + break; + + case ENUMERAL_TYPE: + if (TYPE_NAME (t)) + data_type = IDENTIFIER_POINTER (TYPE_NAME (t)); + else + { + data_type = ""; + chain_p = TYPE_VALUES (t); + while (chain_p) + { + data_type = concat (data_type, + IDENTIFIER_POINTER (TREE_PURPOSE (chain_p))); + chain_p = TREE_CHAIN (chain_p); + if (chain_p) + data_type = concat (data_type, ", "); + } + data_type = concat3 ("{ ", data_type, " }"); + } + data_type = concat ("enum ", data_type); + break; + + case TYPE_DECL: + data_type = IDENTIFIER_POINTER (DECL_NAME (t)); + break; + + case INTEGER_TYPE: + data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t))); + /* Normally, `unsigned' is part of the deal. Not so if it comes + with `const' or `volatile'. */ + if (TREE_UNSIGNED (t) && (TYPE_READONLY (t) || TYPE_VOLATILE (t))) + data_type = concat ("unsigned ", data_type); + break; + + case REAL_TYPE: + data_type = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (t))); + break; + + case VOID_TYPE: + data_type = "void"; + break; + + case ERROR_MARK: + data_type = "[ERROR]"; + break; + + default: + abort (); + } + } + if (TYPE_READONLY (t)) + ret_val = concat ("const ", ret_val); + if (TYPE_VOLATILE (t)) + ret_val = concat ("volatile ", ret_val); + return ret_val; +} + +/* Generate a string (source) representation of an entire entity declaration + (using some particular style for function types). + + The given entity may be either a variable or a function. + + If the "is_func_definition" parameter is non-zero, assume that the thing + we are generating a declaration for is a FUNCTION_DECL node which is + associated with a function definition. In this case, we can assume that + an attached list of DECL nodes for function formal arguments is present. */ + +static char* +gen_decl (decl, is_func_definition, style) + tree decl; + int is_func_definition; + formals_style style; +{ + char* ret_val; + + if (DECL_NAME (decl)) + ret_val = IDENTIFIER_POINTER (DECL_NAME (decl)); + else + ret_val = ""; + + /* If we are just generating a list of names of formal parameters, we can + simply return the formal parameter name (with no typing information + attached to it) now. */ + + if (style == k_and_r_names) + return ret_val; + + /* Note that for the declaration of some entity (either a function or a + data object, like for instance a parameter) if the entity itself was + declared as either const or volatile, then const and volatile properties + are associated with just the declaration of the entity, and *not* with + the `type' of the entity. Thus, for such declared entities, we have to + generate the qualifiers here. */ + + if (TREE_THIS_VOLATILE (decl)) + ret_val = concat ("volatile ", ret_val); + if (TREE_READONLY (decl)) + ret_val = concat ("const ", ret_val); + + data_type = ""; + + /* For FUNCTION_DECL nodes, there are two possible cases here. First, if + this FUNCTION_DECL node was generated from a function "definition", then + we will have a list of DECL_NODE's, one for each of the function's formal + parameters. In this case, we can print out not only the types of each + formal, but also each formal's name. In the second case, this + FUNCTION_DECL node came from an actual function declaration (and *not* + a definition). In this case, we do nothing here because the formal + argument type-list will be output later, when the "type" of the function + is added to the string we are building. Note that the ANSI-style formal + parameter list is considered to be a (suffix) part of the "type" of the + function. */ + + if (TREE_CODE (decl) == FUNCTION_DECL && is_func_definition) + { + ret_val = concat (ret_val, gen_formal_list_for_func_def (decl, ansi)); + + /* Since we have already added in the formals list stuff, here we don't + add the whole "type" of the function we are considering (which + would include its parameter-list info), rather, we only add in + the "type" of the "type" of the function, which is really just + the return-type of the function (and does not include the parameter + list info). */ + + ret_val = gen_type (ret_val, TREE_TYPE (TREE_TYPE (decl)), style); + } + else + ret_val = gen_type (ret_val, TREE_TYPE (decl), style); + + ret_val = affix_data_type (ret_val); + + if (DECL_REGISTER (decl)) + ret_val = concat ("register ", ret_val); + if (TREE_PUBLIC (decl)) + ret_val = concat ("extern ", ret_val); + if (TREE_CODE (decl) == FUNCTION_DECL && !TREE_PUBLIC (decl)) + ret_val = concat ("static ", ret_val); + + return ret_val; +} + +extern FILE* aux_info_file; + +/* Generate and write a new line of info to the aux-info (.X) file. This + routine is called once for each function declaration, and once for each + function definition (even the implicit ones). */ + +void +gen_aux_info_record (fndecl, is_definition, is_implicit, is_prototyped) + tree fndecl; + int is_definition; + int is_implicit; + int is_prototyped; +{ + if (flag_gen_aux_info) + { + static int compiled_from_record = 0; + + /* Each output .X file must have a header line. Write one now if we + have not yet done so. */ + + if (! compiled_from_record++) + { + /* The first line tells which directory file names are relative to. + Currently, -aux-info works only for files in the working + directory, so just use a `.' as a placeholder for now. */ + fprintf (aux_info_file, "/* compiled from: . */\n"); + } + + /* Write the actual line of auxiliary info. */ + + fprintf (aux_info_file, "/* %s:%d:%c%c */ %s;", + DECL_SOURCE_FILE (fndecl), + DECL_SOURCE_LINE (fndecl), + (is_implicit) ? 'I' : (is_prototyped) ? 'N' : 'O', + (is_definition) ? 'F' : 'C', + gen_decl (fndecl, is_definition, ansi)); + + /* If this is an explicit function declaration, we need to also write + out an old-style (i.e. K&R) function header, just in case the user + wants to run unprotoize. */ + + if (is_definition) + { + fprintf (aux_info_file, " /*%s %s*/", + gen_formal_list_for_func_def (fndecl, k_and_r_names), + gen_formal_list_for_func_def (fndecl, k_and_r_decls)); + } + + fprintf (aux_info_file, "\n"); + } +} diff --git a/contrib/gcc/c-common.c b/contrib/gcc/c-common.c new file mode 100644 index 00000000000..78b4d858acb --- /dev/null +++ b/contrib/gcc/c-common.c @@ -0,0 +1,2255 @@ +/* Subroutines shared by all languages that are variants of C. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "tree.h" +#include "c-lex.h" +#include "c-tree.h" +#include "flags.h" +#include "obstack.h" +#include +#include + +extern struct obstack permanent_obstack; + +enum attrs {A_PACKED, A_NOCOMMON, A_NORETURN, A_CONST, A_T_UNION, + A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED, + A_UNUSED, A_FORMAT, A_WEAK, A_ALIAS}; + +static void declare_hidden_char_array PROTO((char *, char *)); +static void add_attribute PROTO((enum attrs, char *, + int, int, int)); +static void init_attributes PROTO((void)); + +/* Make bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ + +void +declare_function_name () +{ + char *name, *printable_name; + + if (current_function_decl == NULL) + { + name = ""; + printable_name = "top level"; + } + else + { + char *kind = "function"; + if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE) + kind = "method"; + /* Allow functions to be nameless (such as artificial ones). */ + if (DECL_NAME (current_function_decl)) + name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl)); + else + name = ""; + printable_name = (*decl_printable_name) (current_function_decl, &kind); + } + + declare_hidden_char_array ("__FUNCTION__", name); + declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name); +} + +static void +declare_hidden_char_array (name, value) + char *name, *value; +{ + tree decl, type, init; + int vlen; + + /* If the default size of char arrays isn't big enough for the name, + or if we want to give warnings for large objects, make a bigger one. */ + vlen = strlen (value) + 1; + type = char_array_type_node; + if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TREE_TYPE (type))) < vlen + || warn_larger_than) + type = build_array_type (char_type_node, + build_index_type (build_int_2 (vlen, 0))); + push_obstacks_nochange (); + decl = build_decl (VAR_DECL, get_identifier (name), type); + TREE_STATIC (decl) = 1; + TREE_READONLY (decl) = 1; + TREE_ASM_WRITTEN (decl) = 1; + DECL_SOURCE_LINE (decl) = 0; + DECL_ARTIFICIAL (decl) = 1; + DECL_IN_SYSTEM_HEADER (decl) = 1; + DECL_IGNORED_P (decl) = 1; + init = build_string (vlen, value); + TREE_TYPE (init) = type; + DECL_INITIAL (decl) = init; + finish_decl (pushdecl (decl), init, NULL_TREE); +} + +/* Given a chain of STRING_CST nodes, + concatenate them into one STRING_CST + and give it a suitable array-of-chars data type. */ + +tree +combine_strings (strings) + tree strings; +{ + register tree value, t; + register int length = 1; + int wide_length = 0; + int wide_flag = 0; + int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT; + int nchars; + + if (TREE_CHAIN (strings)) + { + /* More than one in the chain, so concatenate. */ + register char *p, *q; + + /* Don't include the \0 at the end of each substring, + except for the last one. + Count wide strings and ordinary strings separately. */ + for (t = strings; t; t = TREE_CHAIN (t)) + { + if (TREE_TYPE (t) == wchar_array_type_node) + { + wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes); + wide_flag = 1; + } + else + length += (TREE_STRING_LENGTH (t) - 1); + } + + /* If anything is wide, the non-wides will be converted, + which makes them take more space. */ + if (wide_flag) + length = length * wchar_bytes + wide_length; + + p = savealloc (length); + + /* Copy the individual strings into the new combined string. + If the combined string is wide, convert the chars to ints + for any individual strings that are not wide. */ + + q = p; + for (t = strings; t; t = TREE_CHAIN (t)) + { + int len = (TREE_STRING_LENGTH (t) + - ((TREE_TYPE (t) == wchar_array_type_node) + ? wchar_bytes : 1)); + if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag) + { + bcopy (TREE_STRING_POINTER (t), q, len); + q += len; + } + else + { + int i; + for (i = 0; i < len; i++) + ((int *) q)[i] = TREE_STRING_POINTER (t)[i]; + q += len * wchar_bytes; + } + } + if (wide_flag) + { + int i; + for (i = 0; i < wchar_bytes; i++) + *q++ = 0; + } + else + *q = 0; + + value = make_node (STRING_CST); + TREE_STRING_POINTER (value) = p; + TREE_STRING_LENGTH (value) = length; + TREE_CONSTANT (value) = 1; + } + else + { + value = strings; + length = TREE_STRING_LENGTH (value); + if (TREE_TYPE (value) == wchar_array_type_node) + wide_flag = 1; + } + + /* Compute the number of elements, for the array type. */ + nchars = wide_flag ? length / wchar_bytes : length; + + /* Create the array type for the string constant. + -Wwrite-strings says make the string constant an array of const char + so that copying it to a non-const pointer will get a warning. */ + if (warn_write_strings + && (! flag_traditional && ! flag_writable_strings)) + { + tree elements + = build_type_variant (wide_flag ? wchar_type_node : char_type_node, + 1, 0); + TREE_TYPE (value) + = build_array_type (elements, + build_index_type (build_int_2 (nchars - 1, 0))); + } + else + TREE_TYPE (value) + = build_array_type (wide_flag ? wchar_type_node : char_type_node, + build_index_type (build_int_2 (nchars - 1, 0))); + TREE_CONSTANT (value) = 1; + TREE_STATIC (value) = 1; + return value; +} + +/* To speed up processing of attributes, we maintain an array of + IDENTIFIER_NODES and the corresponding attribute types. */ + +/* Array to hold attribute information. */ + +static struct {enum attrs id; tree name; int min, max, decl_req;} attrtab[50]; + +static int attrtab_idx = 0; + +/* Add an entry to the attribute table above. */ + +static void +add_attribute (id, string, min_len, max_len, decl_req) + enum attrs id; + char *string; + int min_len, max_len; + int decl_req; +{ + char buf[100]; + + attrtab[attrtab_idx].id = id; + attrtab[attrtab_idx].name = get_identifier (string); + attrtab[attrtab_idx].min = min_len; + attrtab[attrtab_idx].max = max_len; + attrtab[attrtab_idx++].decl_req = decl_req; + + sprintf (buf, "__%s__", string); + + attrtab[attrtab_idx].id = id; + attrtab[attrtab_idx].name = get_identifier (buf); + attrtab[attrtab_idx].min = min_len; + attrtab[attrtab_idx].max = max_len; + attrtab[attrtab_idx++].decl_req = decl_req; +} + +/* Initialize attribute table. */ + +static void +init_attributes () +{ + add_attribute (A_PACKED, "packed", 0, 0, 0); + add_attribute (A_NOCOMMON, "nocommon", 0, 0, 1); + add_attribute (A_NORETURN, "noreturn", 0, 0, 1); + add_attribute (A_NORETURN, "volatile", 0, 0, 1); + add_attribute (A_UNUSED, "unused", 0, 0, 1); + add_attribute (A_CONST, "const", 0, 0, 1); + add_attribute (A_T_UNION, "transparent_union", 0, 0, 0); + add_attribute (A_CONSTRUCTOR, "constructor", 0, 0, 1); + add_attribute (A_DESTRUCTOR, "destructor", 0, 0, 1); + add_attribute (A_MODE, "mode", 1, 1, 1); + add_attribute (A_SECTION, "section", 1, 1, 1); + add_attribute (A_ALIGNED, "aligned", 0, 1, 0); + add_attribute (A_FORMAT, "format", 3, 3, 1); + add_attribute (A_WEAK, "weak", 0, 0, 1); + add_attribute (A_ALIAS, "alias", 1, 1, 1); +} + +/* Process the attributes listed in ATTRIBUTES and PREFIX_ATTRIBUTES + and install them in NODE, which is either a DECL (including a TYPE_DECL) + or a TYPE. PREFIX_ATTRIBUTES can appear after the declaration specifiers + and declaration modifiers but before the declaration proper. */ + +void +decl_attributes (node, attributes, prefix_attributes) + tree node, attributes, prefix_attributes; +{ + tree decl = 0, type; + int is_type; + tree a; + + if (attrtab_idx == 0) + init_attributes (); + + if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd') + { + decl = node; + type = TREE_TYPE (decl); + is_type = TREE_CODE (node) == TYPE_DECL; + } + else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't') + type = node, is_type = 1; + + attributes = chainon (prefix_attributes, attributes); + + for (a = attributes; a; a = TREE_CHAIN (a)) + { + tree name = TREE_PURPOSE (a); + tree args = TREE_VALUE (a); + int i; + enum attrs id; + + for (i = 0; i < attrtab_idx; i++) + if (attrtab[i].name == name) + break; + + if (i == attrtab_idx) + { + if (! valid_machine_attribute (name, args, decl, type)) + warning ("`%s' attribute directive ignored", + IDENTIFIER_POINTER (name)); + continue; + } + else if (attrtab[i].decl_req && decl == 0) + { + warning ("`%s' attribute does not apply to types", + IDENTIFIER_POINTER (name)); + continue; + } + else if (list_length (args) < attrtab[i].min + || list_length (args) > attrtab[i].max) + { + error ("wrong number of arguments specified for `%s' attribute", + IDENTIFIER_POINTER (name)); + continue; + } + + id = attrtab[i].id; + switch (id) + { + case A_PACKED: + if (is_type) + TYPE_PACKED (type) = 1; + else if (TREE_CODE (decl) == FIELD_DECL) + DECL_PACKED (decl) = 1; + /* We can't set DECL_PACKED for a VAR_DECL, because the bit is + used for DECL_REGISTER. It wouldn't mean anything anyway. */ + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_NOCOMMON: + if (TREE_CODE (decl) == VAR_DECL) + DECL_COMMON (decl) = 0; + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_NORETURN: + if (TREE_CODE (decl) == FUNCTION_DECL) + TREE_THIS_VOLATILE (decl) = 1; + else if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + TREE_TYPE (decl) = type + = build_pointer_type + (build_type_variant (TREE_TYPE (type), + TREE_READONLY (TREE_TYPE (type)), 1)); + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_UNUSED: + if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL + || TREE_CODE (decl) == FUNCTION_DECL) + TREE_USED (decl) = 1; + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_CONST: + if (TREE_CODE (decl) == FUNCTION_DECL) + TREE_READONLY (decl) = 1; + else if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + TREE_TYPE (decl) = type + = build_pointer_type + (build_type_variant (TREE_TYPE (type), 1, + TREE_THIS_VOLATILE (TREE_TYPE (type)))); + else + warning ( "`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_T_UNION: + if (is_type + && TREE_CODE (type) == UNION_TYPE + && (decl == 0 + || TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type)))) + TYPE_TRANSPARENT_UNION (type) = 1; + else if (decl != 0 && TREE_CODE (decl) == PARM_DECL + && TREE_CODE (type) == UNION_TYPE + && TYPE_MODE (type) == DECL_MODE (TYPE_FIELDS (type))) + DECL_TRANSPARENT_UNION (decl) = 1; + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_CONSTRUCTOR: + if (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (type) == FUNCTION_TYPE + && decl_function_context (decl) == 0) + { + DECL_STATIC_CONSTRUCTOR (decl) = 1; + TREE_USED (decl) = 1; + } + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_DESTRUCTOR: + if (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (type) == FUNCTION_TYPE + && decl_function_context (decl) == 0) + { + DECL_STATIC_DESTRUCTOR (decl) = 1; + TREE_USED (decl) = 1; + } + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + + case A_MODE: + if (TREE_CODE (TREE_VALUE (args)) != IDENTIFIER_NODE) + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + else + { + int j; + char *p = IDENTIFIER_POINTER (TREE_VALUE (args)); + int len = strlen (p); + enum machine_mode mode = VOIDmode; + tree typefm; + + if (len > 4 && p[0] == '_' && p[1] == '_' + && p[len - 1] == '_' && p[len - 2] == '_') + { + char *newp = (char *) alloca (len - 1); + + strcpy (newp, &p[2]); + newp[len - 4] = '\0'; + p = newp; + } + + /* Give this decl a type with the specified mode. + First check for the special modes. */ + if (! strcmp (p, "byte")) + mode = byte_mode; + else if (!strcmp (p, "word")) + mode = word_mode; + else if (! strcmp (p, "pointer")) + mode = ptr_mode; + else + for (j = 0; j < NUM_MACHINE_MODES; j++) + if (!strcmp (p, GET_MODE_NAME (j))) + mode = (enum machine_mode) j; + + if (mode == VOIDmode) + error ("unknown machine mode `%s'", p); + else if (0 == (typefm = type_for_mode (mode, + TREE_UNSIGNED (type)))) + error ("no data type for mode `%s'", p); + else + { + TREE_TYPE (decl) = type = typefm; + DECL_SIZE (decl) = 0; + layout_decl (decl, 0); + } + } + break; + + case A_SECTION: +#ifdef ASM_OUTPUT_SECTION_NAME + if ((TREE_CODE (decl) == FUNCTION_DECL + || TREE_CODE (decl) == VAR_DECL) + && TREE_CODE (TREE_VALUE (args)) == STRING_CST) + { + if (TREE_CODE (decl) == VAR_DECL + && current_function_decl != NULL_TREE) + error_with_decl (decl, + "section attribute cannot be specified for local variables"); + /* The decl may have already been given a section attribute from + a previous declaration. Ensure they match. */ + else if (DECL_SECTION_NAME (decl) != NULL_TREE + && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)), + TREE_STRING_POINTER (TREE_VALUE (args))) != 0) + error_with_decl (node, + "section of `%s' conflicts with previous declaration"); + else + DECL_SECTION_NAME (decl) = TREE_VALUE (args); + } + else + error_with_decl (node, + "section attribute not allowed for `%s'"); +#else + error_with_decl (node, + "section attributes are not supported for this target"); +#endif + break; + + case A_ALIGNED: + { + tree align_expr + = args ? TREE_VALUE (args) : size_int (BIGGEST_ALIGNMENT); + int align; + + /* Strip any NOPs of any kind. */ + while (TREE_CODE (align_expr) == NOP_EXPR + || TREE_CODE (align_expr) == CONVERT_EXPR + || TREE_CODE (align_expr) == NON_LVALUE_EXPR) + align_expr = TREE_OPERAND (align_expr, 0); + + if (TREE_CODE (align_expr) != INTEGER_CST) + { + error ("requested alignment is not a constant"); + continue; + } + + align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT; + + if (exact_log2 (align) == -1) + error ("requested alignment is not a power of 2"); + else if (is_type) + TYPE_ALIGN (type) = align; + else if (TREE_CODE (decl) != VAR_DECL + && TREE_CODE (decl) != FIELD_DECL) + error_with_decl (decl, + "alignment may not be specified for `%s'"); + else + DECL_ALIGN (decl) = align; + } + break; + + case A_FORMAT: + { + tree format_type = TREE_VALUE (args); + tree format_num_expr = TREE_VALUE (TREE_CHAIN (args)); + tree first_arg_num_expr + = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args))); + int format_num; + int first_arg_num; + int is_scan; + tree argument; + int arg_num; + + if (TREE_CODE (decl) != FUNCTION_DECL) + { + error_with_decl (decl, + "argument format specified for non-function `%s'"); + continue; + } + + if (TREE_CODE (format_type) == IDENTIFIER_NODE + && (!strcmp (IDENTIFIER_POINTER (format_type), "printf") + || !strcmp (IDENTIFIER_POINTER (format_type), + "__printf__"))) + is_scan = 0; + else if (TREE_CODE (format_type) == IDENTIFIER_NODE + && (!strcmp (IDENTIFIER_POINTER (format_type), "scanf") + || !strcmp (IDENTIFIER_POINTER (format_type), + "__scanf__"))) + is_scan = 1; + else + { + error ("unrecognized format specifier for `%s'"); + continue; + } + + /* Strip any conversions from the string index and first arg number + and verify they are constants. */ + while (TREE_CODE (format_num_expr) == NOP_EXPR + || TREE_CODE (format_num_expr) == CONVERT_EXPR + || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR) + format_num_expr = TREE_OPERAND (format_num_expr, 0); + + while (TREE_CODE (first_arg_num_expr) == NOP_EXPR + || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR + || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR) + first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0); + + if (TREE_CODE (format_num_expr) != INTEGER_CST + || TREE_CODE (first_arg_num_expr) != INTEGER_CST) + { + error ("format string has non-constant operand number"); + continue; + } + + format_num = TREE_INT_CST_LOW (format_num_expr); + first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr); + if (first_arg_num != 0 && first_arg_num <= format_num) + { + error ("format string arg follows the args to be formatted"); + continue; + } + + /* If a parameter list is specified, verify that the format_num + argument is actually a string, in case the format attribute + is in error. */ + argument = TYPE_ARG_TYPES (type); + if (argument) + { + for (arg_num = 1; ; ++arg_num) + { + if (argument == 0 || arg_num == format_num) + break; + argument = TREE_CHAIN (argument); + } + if (! argument + || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE + || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument))) + != char_type_node)) + { + error ("format string arg not a string type"); + continue; + } + if (first_arg_num != 0) + { + /* Verify that first_arg_num points to the last arg, + the ... */ + while (argument) + arg_num++, argument = TREE_CHAIN (argument); + if (arg_num != first_arg_num) + { + error ("args to be formatted is not ..."); + continue; + } + } + } + + record_function_format (DECL_NAME (decl), + DECL_ASSEMBLER_NAME (decl), + is_scan, format_num, first_arg_num); + break; + } + + case A_WEAK: + declare_weak (decl); + break; + + case A_ALIAS: + if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) + || TREE_CODE (decl) != FUNCTION_DECL && ! DECL_EXTERNAL (decl)) + error_with_decl (decl, + "`%s' defined both normally and as an alias"); + else if (decl_function_context (decl) == 0) + { + tree id = get_identifier (TREE_STRING_POINTER + (TREE_VALUE (args))); + if (TREE_CODE (decl) == FUNCTION_DECL) + DECL_INITIAL (decl) = error_mark_node; + else + DECL_EXTERNAL (decl) = 0; + assemble_alias (decl, id); + } + else + warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); + break; + } + } +} + +/* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against + a parameter list. */ + +#define T_I &integer_type_node +#define T_L &long_integer_type_node +#define T_LL &long_long_integer_type_node +#define T_S &short_integer_type_node +#define T_UI &unsigned_type_node +#define T_UL &long_unsigned_type_node +#define T_ULL &long_long_unsigned_type_node +#define T_US &short_unsigned_type_node +#define T_F &float_type_node +#define T_D &double_type_node +#define T_LD &long_double_type_node +#define T_C &char_type_node +#define T_V &void_type_node +#define T_W &wchar_type_node +#define T_ST &sizetype + +typedef struct { + char *format_chars; + int pointer_count; + /* Type of argument if no length modifier is used. */ + tree *nolen; + /* Type of argument if length modifier for shortening is used. + If NULL, then this modifier is not allowed. */ + tree *hlen; + /* Type of argument if length modifier `l' is used. + If NULL, then this modifier is not allowed. */ + tree *llen; + /* Type of argument if length modifier `q' or `ll' is used. + If NULL, then this modifier is not allowed. */ + tree *qlen; + /* Type of argument if length modifier `L' is used. + If NULL, then this modifier is not allowed. */ + tree *bigllen; + /* List of other modifier characters allowed with these options. */ + char *flag_chars; +} format_char_info; + +static format_char_info print_char_table[] = { + { "di", 0, T_I, T_I, T_L, T_LL, T_LL, "-wp0 +" }, + { "oxX", 0, T_UI, T_UI, T_UL, T_ULL, T_ULL, "-wp0#" }, + { "u", 0, T_UI, T_UI, T_UL, T_ULL, T_ULL, "-wp0" }, +/* Two GNU extensions. */ + { "Z", 0, T_ST, NULL, NULL, NULL, NULL, "-wp0" }, + { "m", 0, T_V, NULL, NULL, NULL, NULL, "-wp" }, + { "feEgG", 0, T_D, NULL, NULL, NULL, T_LD, "-wp0 +#" }, + { "c", 0, T_I, NULL, T_W, NULL, NULL, "-w" }, + { "C", 0, T_W, NULL, NULL, NULL, NULL, "-w" }, + { "s", 1, T_C, NULL, T_W, NULL, NULL, "-wp" }, + { "S", 1, T_W, NULL, NULL, NULL, NULL, "-wp" }, + { "p", 1, T_V, NULL, NULL, NULL, NULL, "-w" }, + { "n", 1, T_I, T_S, T_L, T_LL, NULL, "" }, + { NULL } +}; + +static format_char_info scan_char_table[] = { + { "di", 1, T_I, T_S, T_L, T_LL, T_LL, "*" }, + { "ouxX", 1, T_UI, T_US, T_UL, T_ULL, T_ULL, "*" }, + { "efgEG", 1, T_F, NULL, T_D, NULL, T_LD, "*" }, + { "sc", 1, T_C, NULL, T_W, NULL, NULL, "*a" }, + { "[", 1, T_C, NULL, NULL, NULL, NULL, "*a" }, + { "C", 1, T_W, NULL, NULL, NULL, NULL, "*" }, + { "S", 1, T_W, NULL, NULL, NULL, NULL, "*" }, + { "p", 2, T_V, NULL, NULL, NULL, NULL, "*" }, + { "n", 1, T_I, T_S, T_L, T_LL, NULL, "" }, + { NULL } +}; + +typedef struct function_format_info { + struct function_format_info *next; /* next structure on the list */ + tree name; /* identifier such as "printf" */ + tree assembler_name; /* optional mangled identifier (for C++) */ + int is_scan; /* TRUE if *scanf */ + int format_num; /* number of format argument */ + int first_arg_num; /* number of first arg (zero for varargs) */ +} function_format_info; + +static function_format_info *function_format_list = NULL; + +static void check_format_info PROTO((function_format_info *, tree)); + +/* Initialize the table of functions to perform format checking on. + The ANSI functions are always checked (whether is + included or not), since it is common to call printf without + including . There shouldn't be a problem with this, + since ANSI reserves these function names whether you include the + header file or not. In any case, the checking is harmless. */ + +void +init_function_format_info () +{ + record_function_format (get_identifier ("printf"), NULL_TREE, 0, 1, 2); + record_function_format (get_identifier ("fprintf"), NULL_TREE, 0, 2, 3); + record_function_format (get_identifier ("sprintf"), NULL_TREE, 0, 2, 3); + record_function_format (get_identifier ("scanf"), NULL_TREE, 1, 1, 2); + record_function_format (get_identifier ("fscanf"), NULL_TREE, 1, 2, 3); + record_function_format (get_identifier ("sscanf"), NULL_TREE, 1, 2, 3); + record_function_format (get_identifier ("vprintf"), NULL_TREE, 0, 1, 0); + record_function_format (get_identifier ("vfprintf"), NULL_TREE, 0, 2, 0); + record_function_format (get_identifier ("vsprintf"), NULL_TREE, 0, 2, 0); +} + +/* Record information for argument format checking. FUNCTION_IDENT is + the identifier node for the name of the function to check (its decl + need not exist yet). IS_SCAN is true for scanf-type format checking; + false indicates printf-style format checking. FORMAT_NUM is the number + of the argument which is the format control string (starting from 1). + FIRST_ARG_NUM is the number of the first actual argument to check + against teh format string, or zero if no checking is not be done + (e.g. for varargs such as vfprintf). */ + +void +record_function_format (name, assembler_name, is_scan, + format_num, first_arg_num) + tree name; + tree assembler_name; + int is_scan; + int format_num; + int first_arg_num; +{ + function_format_info *info; + + /* Re-use existing structure if it's there. */ + + for (info = function_format_list; info; info = info->next) + { + if (info->name == name && info->assembler_name == assembler_name) + break; + } + if (! info) + { + info = (function_format_info *) xmalloc (sizeof (function_format_info)); + info->next = function_format_list; + function_format_list = info; + + info->name = name; + info->assembler_name = assembler_name; + } + + info->is_scan = is_scan; + info->format_num = format_num; + info->first_arg_num = first_arg_num; +} + +static char tfaff[] = "too few arguments for format"; + +/* Check the argument list of a call to printf, scanf, etc. + NAME is the function identifier. + ASSEMBLER_NAME is the function's assembler identifier. + (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.) + PARAMS is the list of argument values. */ + +void +check_function_format (name, assembler_name, params) + tree name; + tree assembler_name; + tree params; +{ + function_format_info *info; + + /* See if this function is a format function. */ + for (info = function_format_list; info; info = info->next) + { + if (info->assembler_name + ? (info->assembler_name == assembler_name) + : (info->name == name)) + { + /* Yup; check it. */ + check_format_info (info, params); + break; + } + } +} + +/* Check the argument list of a call to printf, scanf, etc. + INFO points to the function_format_info structure. + PARAMS is the list of argument values. */ + +static void +check_format_info (info, params) + function_format_info *info; + tree params; +{ + int i; + int arg_num; + int suppressed, wide, precise; + int length_char; + int format_char; + int format_length; + tree format_tree; + tree cur_param; + tree cur_type; + tree wanted_type; + tree first_fillin_param; + char *format_chars; + format_char_info *fci; + static char message[132]; + char flag_chars[8]; + int has_operand_number = 0; + + /* Skip to format argument. If the argument isn't available, there's + no work for us to do; prototype checking will catch the problem. */ + for (arg_num = 1; ; ++arg_num) + { + if (params == 0) + return; + if (arg_num == info->format_num) + break; + params = TREE_CHAIN (params); + } + format_tree = TREE_VALUE (params); + params = TREE_CHAIN (params); + if (format_tree == 0) + return; + /* We can only check the format if it's a string constant. */ + while (TREE_CODE (format_tree) == NOP_EXPR) + format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */ + if (integer_zerop (format_tree)) + { + warning ("null format string"); + return; + } + if (TREE_CODE (format_tree) != ADDR_EXPR) + return; + format_tree = TREE_OPERAND (format_tree, 0); + if (TREE_CODE (format_tree) != STRING_CST) + return; + format_chars = TREE_STRING_POINTER (format_tree); + format_length = TREE_STRING_LENGTH (format_tree); + if (format_length <= 1) + warning ("zero-length format string"); + if (format_chars[--format_length] != 0) + { + warning ("unterminated format string"); + return; + } + /* Skip to first argument to check. */ + while (arg_num + 1 < info->first_arg_num) + { + if (params == 0) + return; + params = TREE_CHAIN (params); + ++arg_num; + } + + first_fillin_param = params; + while (1) + { + int aflag; + if (*format_chars == 0) + { + if (format_chars - TREE_STRING_POINTER (format_tree) != format_length) + warning ("embedded `\\0' in format"); + if (info->first_arg_num != 0 && params != 0 && ! has_operand_number) + warning ("too many arguments for format"); + return; + } + if (*format_chars++ != '%') + continue; + if (*format_chars == 0) + { + warning ("spurious trailing `%%' in format"); + continue; + } + if (*format_chars == '%') + { + ++format_chars; + continue; + } + flag_chars[0] = 0; + suppressed = wide = precise = FALSE; + if (info->is_scan) + { + suppressed = *format_chars == '*'; + if (suppressed) + ++format_chars; + while (isdigit (*format_chars)) + ++format_chars; + } + else + { + /* See if we have a number followed by a dollar sign. If we do, + it is an operand number, so set PARAMS to that operand. */ + if (*format_chars >= '0' && *format_chars <= '9') + { + char *p = format_chars; + + while (*p >= '0' && *p++ <= '9') + ; + + if (*p == '$') + { + int opnum = atoi (format_chars); + + params = first_fillin_param; + format_chars = p + 1; + has_operand_number = 1; + + for (i = 1; i < opnum && params != 0; i++) + params = TREE_CHAIN (params); + + if (opnum == 0 || params == 0) + { + warning ("operand number out of range in format"); + return; + } + } + } + + while (*format_chars != 0 && index (" +#0-", *format_chars) != 0) + { + if (index (flag_chars, *format_chars) != 0) + { + sprintf (message, "repeated `%c' flag in format", + *format_chars); + warning (message); + } + i = strlen (flag_chars); + flag_chars[i++] = *format_chars++; + flag_chars[i] = 0; + } + /* "If the space and + flags both appear, + the space flag will be ignored." */ + if (index (flag_chars, ' ') != 0 + && index (flag_chars, '+') != 0) + warning ("use of both ` ' and `+' flags in format"); + /* "If the 0 and - flags both appear, + the 0 flag will be ignored." */ + if (index (flag_chars, '0') != 0 + && index (flag_chars, '-') != 0) + warning ("use of both `0' and `-' flags in format"); + if (*format_chars == '*') + { + wide = TRUE; + /* "...a field width...may be indicated by an asterisk. + In this case, an int argument supplies the field width..." */ + ++format_chars; + if (params == 0) + { + warning (tfaff); + return; + } + if (info->first_arg_num != 0) + { + cur_param = TREE_VALUE (params); + params = TREE_CHAIN (params); + ++arg_num; + /* size_t is generally not valid here. + It will work on most machines, because size_t and int + have the same mode. But might as well warn anyway, + since it will fail on other machines. */ + if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param)) + != integer_type_node) + && + (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param)) + != unsigned_type_node)) + { + sprintf (message, + "field width is not type int (arg %d)", + arg_num); + warning (message); + } + } + } + else + { + while (isdigit (*format_chars)) + { + wide = TRUE; + ++format_chars; + } + } + if (*format_chars == '.') + { + precise = TRUE; + ++format_chars; + if (*format_chars != '*' && !isdigit (*format_chars)) + warning ("`.' not followed by `*' or digit in format"); + /* "...a...precision...may be indicated by an asterisk. + In this case, an int argument supplies the...precision." */ + if (*format_chars == '*') + { + if (info->first_arg_num != 0) + { + ++format_chars; + if (params == 0) + { + warning (tfaff); + return; + } + cur_param = TREE_VALUE (params); + params = TREE_CHAIN (params); + ++arg_num; + if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param)) + != integer_type_node) + { + sprintf (message, + "field width is not type int (arg %d)", + arg_num); + warning (message); + } + } + } + else + { + while (isdigit (*format_chars)) + ++format_chars; + } + } + } + if (*format_chars == 'h' || *format_chars == 'l' || *format_chars == 'q' || + *format_chars == 'L') + length_char = *format_chars++; + else + length_char = 0; + if (length_char == 'l' && *format_chars == 'l') + length_char = 'q', format_chars++; + aflag = 0; + if (*format_chars == 'a') + { + aflag = 1; + format_chars++; + } + if (suppressed && length_char != 0) + { + sprintf (message, + "use of `*' and `%c' together in format", + length_char); + warning (message); + } + format_char = *format_chars; + if (format_char == 0) + { + warning ("conversion lacks type at end of format"); + continue; + } + format_chars++; + fci = info->is_scan ? scan_char_table : print_char_table; + while (fci->format_chars != 0 + && index (fci->format_chars, format_char) == 0) + ++fci; + if (fci->format_chars == 0) + { + if (format_char >= 040 && format_char < 0177) + sprintf (message, + "unknown conversion type character `%c' in format", + format_char); + else + sprintf (message, + "unknown conversion type character 0x%x in format", + format_char); + warning (message); + continue; + } + if (wide && index (fci->flag_chars, 'w') == 0) + { + sprintf (message, "width used with `%c' format", + format_char); + warning (message); + } + if (precise && index (fci->flag_chars, 'p') == 0) + { + sprintf (message, "precision used with `%c' format", + format_char); + warning (message); + } + if (aflag && index (fci->flag_chars, 'a') == 0) + { + sprintf (message, "`a' flag used with `%c' format", + format_char); + warning (message); + } + if (info->is_scan && format_char == '[') + { + /* Skip over scan set, in case it happens to have '%' in it. */ + if (*format_chars == '^') + ++format_chars; + /* Find closing bracket; if one is hit immediately, then + it's part of the scan set rather than a terminator. */ + if (*format_chars == ']') + ++format_chars; + while (*format_chars && *format_chars != ']') + ++format_chars; + if (*format_chars != ']') + /* The end of the format string was reached. */ + warning ("no closing `]' for `%%[' format"); + } + if (suppressed) + { + if (index (fci->flag_chars, '*') == 0) + { + sprintf (message, + "suppression of `%c' conversion in format", + format_char); + warning (message); + } + continue; + } + for (i = 0; flag_chars[i] != 0; ++i) + { + if (index (fci->flag_chars, flag_chars[i]) == 0) + { + sprintf (message, "flag `%c' used with type `%c'", + flag_chars[i], format_char); + warning (message); + } + } + if (precise && index (flag_chars, '0') != 0 + && (format_char == 'd' || format_char == 'i' + || format_char == 'o' || format_char == 'u' + || format_char == 'x' || format_char == 'x')) + { + sprintf (message, + "precision and `0' flag not both allowed with `%c' format", + format_char); + warning (message); + } + switch (length_char) + { + default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break; + case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break; + case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break; + case 'q': wanted_type = fci->qlen ? *(fci->qlen) : 0; break; + case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break; + } + if (wanted_type == 0) + { + sprintf (message, + "use of `%c' length character with `%c' type character", + length_char, format_char); + warning (message); + } + + /* + ** XXX -- should kvetch about stuff such as + ** { + ** const int i; + ** + ** scanf ("%d", &i); + ** } + */ + + /* Finally. . .check type of argument against desired type! */ + if (info->first_arg_num == 0) + continue; + if (fci->pointer_count == 0 && wanted_type == void_type_node) + /* This specifier takes no argument. */ + continue; + if (params == 0) + { + warning (tfaff); + return; + } + cur_param = TREE_VALUE (params); + params = TREE_CHAIN (params); + ++arg_num; + cur_type = TREE_TYPE (cur_param); + + /* Check the types of any additional pointer arguments + that precede the "real" argument. */ + for (i = 0; i < fci->pointer_count; ++i) + { + if (TREE_CODE (cur_type) == POINTER_TYPE) + { + cur_type = TREE_TYPE (cur_type); + continue; + } + if (TREE_CODE (cur_type) != ERROR_MARK) + { + sprintf (message, + "format argument is not a %s (arg %d)", + ((fci->pointer_count == 1) ? "pointer" : "pointer to a pointer"), + arg_num); + warning (message); + } + break; + } + + /* Check the type of the "real" argument, if there's a type we want. */ + if (i == fci->pointer_count && wanted_type != 0 + && TREE_CODE (cur_type) != ERROR_MARK + && wanted_type != TYPE_MAIN_VARIANT (cur_type) + /* If we want `void *', allow any pointer type. + (Anything else would already have got a warning.) */ + && ! (wanted_type == void_type_node + && fci->pointer_count > 0) + /* Don't warn about differences merely in signedness. */ + && !(TREE_CODE (wanted_type) == INTEGER_TYPE + && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE + && (TREE_UNSIGNED (wanted_type) + ? wanted_type == (cur_type = unsigned_type (cur_type)) + : wanted_type == (cur_type = signed_type (cur_type)))) + /* Likewise, "signed char", "unsigned char" and "char" are + equivalent but the above test won't consider them equivalent. */ + && ! (wanted_type == char_type_node + && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node + || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node))) + { + register char *this; + register char *that; + + this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type))); + that = 0; + if (TREE_CODE (cur_type) != ERROR_MARK + && TYPE_NAME (cur_type) != 0 + && TREE_CODE (cur_type) != INTEGER_TYPE + && !(TREE_CODE (cur_type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE)) + { + if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL + && DECL_NAME (TYPE_NAME (cur_type)) != 0) + that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type))); + else + that = IDENTIFIER_POINTER (TYPE_NAME (cur_type)); + } + + /* A nameless type can't possibly match what the format wants. + So there will be a warning for it. + Make up a string to describe vaguely what it is. */ + if (that == 0) + { + if (TREE_CODE (cur_type) == POINTER_TYPE) + that = "pointer"; + else + that = "different type"; + } + + /* Make the warning better in case of mismatch of int vs long. */ + if (TREE_CODE (cur_type) == INTEGER_TYPE + && TREE_CODE (wanted_type) == INTEGER_TYPE + && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type) + && TYPE_NAME (cur_type) != 0 + && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL) + that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type))); + + if (strcmp (this, that) != 0) + { + sprintf (message, "%s format, %s arg (arg %d)", + this, that, arg_num); + warning (message); + } + } + } +} + +/* Print a warning if a constant expression had overflow in folding. + Invoke this function on every expression that the language + requires to be a constant expression. + Note the ANSI C standard says it is erroneous for a + constant expression to overflow. */ + +void +constant_expression_warning (value) + tree value; +{ + if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST + || TREE_CODE (value) == COMPLEX_CST) + && TREE_CONSTANT_OVERFLOW (value) && pedantic) + pedwarn ("overflow in constant expression"); +} + +/* Print a warning if an expression had overflow in folding. + Invoke this function on every expression that + (1) appears in the source code, and + (2) might be a constant expression that overflowed, and + (3) is not already checked by convert_and_check; + however, do not invoke this function on operands of explicit casts. */ + +void +overflow_warning (value) + tree value; +{ + if ((TREE_CODE (value) == INTEGER_CST + || (TREE_CODE (value) == COMPLEX_CST + && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)) + && TREE_OVERFLOW (value)) + { + TREE_OVERFLOW (value) = 0; + warning ("integer overflow in expression"); + } + else if ((TREE_CODE (value) == REAL_CST + || (TREE_CODE (value) == COMPLEX_CST + && TREE_CODE (TREE_REALPART (value)) == REAL_CST)) + && TREE_OVERFLOW (value)) + { + TREE_OVERFLOW (value) = 0; + warning ("floating-pointer overflow in expression"); + } +} + +/* Print a warning if a large constant is truncated to unsigned, + or if -Wconversion is used and a constant < 0 is converted to unsigned. + Invoke this function on every expression that might be implicitly + converted to an unsigned type. */ + +void +unsigned_conversion_warning (result, operand) + tree result, operand; +{ + if (TREE_CODE (operand) == INTEGER_CST + && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE + && TREE_UNSIGNED (TREE_TYPE (result)) + && !int_fits_type_p (operand, TREE_TYPE (result))) + { + if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result)))) + /* This detects cases like converting -129 or 256 to unsigned char. */ + warning ("large integer implicitly truncated to unsigned type"); + else if (warn_conversion) + warning ("negative integer implicitly converted to unsigned type"); + } +} + +/* Convert EXPR to TYPE, warning about conversion problems with constants. + Invoke this function on every expression that is converted implicitly, + i.e. because of language rules and not because of an explicit cast. */ + +tree +convert_and_check (type, expr) + tree type, expr; +{ + tree t = convert (type, expr); + if (TREE_CODE (t) == INTEGER_CST) + { + if (TREE_OVERFLOW (t)) + { + TREE_OVERFLOW (t) = 0; + + /* Do not diagnose overflow in a constant expression merely + because a conversion overflowed. */ + TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr); + + /* No warning for converting 0x80000000 to int. */ + if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr)) + && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE + && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr)))) + /* If EXPR fits in the unsigned version of TYPE, + don't warn unless pedantic. */ + if (pedantic + || TREE_UNSIGNED (type) + || ! int_fits_type_p (expr, unsigned_type (type))) + warning ("overflow in implicit constant conversion"); + } + else + unsigned_conversion_warning (t, expr); + } + return t; +} + +void +c_expand_expr_stmt (expr) + tree expr; +{ + /* Do default conversion if safe and possibly important, + in case within ({...}). */ + if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr)) + || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE) + expr = default_conversion (expr); + + if (TREE_TYPE (expr) != error_mark_node + && TYPE_SIZE (TREE_TYPE (expr)) == 0 + && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE) + error ("expression statement has incomplete type"); + + expand_expr_stmt (expr); +} + +/* Validate the expression after `case' and apply default promotions. */ + +tree +check_case_value (value) + tree value; +{ + if (value == NULL_TREE) + return value; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + STRIP_TYPE_NOPS (value); + + if (TREE_CODE (value) != INTEGER_CST + && value != error_mark_node) + { + error ("case label does not reduce to an integer constant"); + value = error_mark_node; + } + else + /* Promote char or short to int. */ + value = default_conversion (value); + + constant_expression_warning (value); + + return value; +} + +/* Return an integer type with BITS bits of precision, + that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */ + +tree +type_for_size (bits, unsignedp) + unsigned bits; + int unsignedp; +{ + if (bits == TYPE_PRECISION (integer_type_node)) + return unsignedp ? unsigned_type_node : integer_type_node; + + if (bits == TYPE_PRECISION (signed_char_type_node)) + return unsignedp ? unsigned_char_type_node : signed_char_type_node; + + if (bits == TYPE_PRECISION (short_integer_type_node)) + return unsignedp ? short_unsigned_type_node : short_integer_type_node; + + if (bits == TYPE_PRECISION (long_integer_type_node)) + return unsignedp ? long_unsigned_type_node : long_integer_type_node; + + if (bits == TYPE_PRECISION (long_long_integer_type_node)) + return (unsignedp ? long_long_unsigned_type_node + : long_long_integer_type_node); + + if (bits <= TYPE_PRECISION (intQI_type_node)) + return unsignedp ? unsigned_intQI_type_node : intQI_type_node; + + if (bits <= TYPE_PRECISION (intHI_type_node)) + return unsignedp ? unsigned_intHI_type_node : intHI_type_node; + + if (bits <= TYPE_PRECISION (intSI_type_node)) + return unsignedp ? unsigned_intSI_type_node : intSI_type_node; + + if (bits <= TYPE_PRECISION (intDI_type_node)) + return unsignedp ? unsigned_intDI_type_node : intDI_type_node; + + return 0; +} + +/* Return a data type that has machine mode MODE. + If the mode is an integer, + then UNSIGNEDP selects between signed and unsigned types. */ + +tree +type_for_mode (mode, unsignedp) + enum machine_mode mode; + int unsignedp; +{ + if (mode == TYPE_MODE (integer_type_node)) + return unsignedp ? unsigned_type_node : integer_type_node; + + if (mode == TYPE_MODE (signed_char_type_node)) + return unsignedp ? unsigned_char_type_node : signed_char_type_node; + + if (mode == TYPE_MODE (short_integer_type_node)) + return unsignedp ? short_unsigned_type_node : short_integer_type_node; + + if (mode == TYPE_MODE (long_integer_type_node)) + return unsignedp ? long_unsigned_type_node : long_integer_type_node; + + if (mode == TYPE_MODE (long_long_integer_type_node)) + return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; + + if (mode == TYPE_MODE (intQI_type_node)) + return unsignedp ? unsigned_intQI_type_node : intQI_type_node; + + if (mode == TYPE_MODE (intHI_type_node)) + return unsignedp ? unsigned_intHI_type_node : intHI_type_node; + + if (mode == TYPE_MODE (intSI_type_node)) + return unsignedp ? unsigned_intSI_type_node : intSI_type_node; + + if (mode == TYPE_MODE (intDI_type_node)) + return unsignedp ? unsigned_intDI_type_node : intDI_type_node; + + if (mode == TYPE_MODE (float_type_node)) + return float_type_node; + + if (mode == TYPE_MODE (double_type_node)) + return double_type_node; + + if (mode == TYPE_MODE (long_double_type_node)) + return long_double_type_node; + + if (mode == TYPE_MODE (build_pointer_type (char_type_node))) + return build_pointer_type (char_type_node); + + if (mode == TYPE_MODE (build_pointer_type (integer_type_node))) + return build_pointer_type (integer_type_node); + + return 0; +} + +/* Return the minimum number of bits needed to represent VALUE in a + signed or unsigned type, UNSIGNEDP says which. */ + +int +min_precision (value, unsignedp) + tree value; + int unsignedp; +{ + int log; + + /* If the value is negative, compute its negative minus 1. The latter + adjustment is because the absolute value of the largest negative value + is one larger than the largest positive value. This is equivalent to + a bit-wise negation, so use that operation instead. */ + + if (tree_int_cst_sgn (value) < 0) + value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value)); + + /* Return the number of bits needed, taking into account the fact + that we need one more bit for a signed than unsigned type. */ + + if (integer_zerop (value)) + log = 0; + else if (TREE_INT_CST_HIGH (value) != 0) + log = HOST_BITS_PER_WIDE_INT + floor_log2 (TREE_INT_CST_HIGH (value)); + else + log = floor_log2 (TREE_INT_CST_LOW (value)); + + return log + 1 + ! unsignedp; +} + +/* Print an error message for invalid operands to arith operation CODE. + NOP_EXPR is used as a special case (see truthvalue_conversion). */ + +void +binary_op_error (code) + enum tree_code code; +{ + register char *opname = "unknown"; + + switch (code) + { + case NOP_EXPR: + error ("invalid truth-value expression"); + return; + + case PLUS_EXPR: + opname = "+"; break; + case MINUS_EXPR: + opname = "-"; break; + case MULT_EXPR: + opname = "*"; break; + case MAX_EXPR: + opname = "max"; break; + case MIN_EXPR: + opname = "min"; break; + case EQ_EXPR: + opname = "=="; break; + case NE_EXPR: + opname = "!="; break; + case LE_EXPR: + opname = "<="; break; + case GE_EXPR: + opname = ">="; break; + case LT_EXPR: + opname = "<"; break; + case GT_EXPR: + opname = ">"; break; + case LSHIFT_EXPR: + opname = "<<"; break; + case RSHIFT_EXPR: + opname = ">>"; break; + case TRUNC_MOD_EXPR: + case FLOOR_MOD_EXPR: + opname = "%"; break; + case TRUNC_DIV_EXPR: + case FLOOR_DIV_EXPR: + opname = "/"; break; + case BIT_AND_EXPR: + opname = "&"; break; + case BIT_IOR_EXPR: + opname = "|"; break; + case TRUTH_ANDIF_EXPR: + opname = "&&"; break; + case TRUTH_ORIF_EXPR: + opname = "||"; break; + case BIT_XOR_EXPR: + opname = "^"; break; + case LROTATE_EXPR: + case RROTATE_EXPR: + opname = "rotate"; break; + } + error ("invalid operands to binary %s", opname); +} + +/* Subroutine of build_binary_op, used for comparison operations. + See if the operands have both been converted from subword integer types + and, if so, perhaps change them both back to their original type. + This function is also responsible for converting the two operands + to the proper common type for comparison. + + The arguments of this function are all pointers to local variables + of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1, + RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE. + + If this function returns nonzero, it means that the comparison has + a constant value. What this function returns is an expression for + that value. */ + +tree +shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr) + tree *op0_ptr, *op1_ptr; + tree *restype_ptr; + enum tree_code *rescode_ptr; +{ + register tree type; + tree op0 = *op0_ptr; + tree op1 = *op1_ptr; + int unsignedp0, unsignedp1; + int real1, real2; + tree primop0, primop1; + enum tree_code code = *rescode_ptr; + + /* Throw away any conversions to wider types + already present in the operands. */ + + primop0 = get_narrower (op0, &unsignedp0); + primop1 = get_narrower (op1, &unsignedp1); + + /* Handle the case that OP0 does not *contain* a conversion + but it *requires* conversion to FINAL_TYPE. */ + + if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr) + unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0)); + if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr) + unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1)); + + /* If one of the operands must be floated, we cannot optimize. */ + real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE; + real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE; + + /* If first arg is constant, swap the args (changing operation + so value is preserved), for canonicalization. Don't do this if + the second arg is 0. */ + + if (TREE_CONSTANT (primop0) + && ! integer_zerop (primop1) && ! real_zerop (primop1)) + { + register tree tem = primop0; + register int temi = unsignedp0; + primop0 = primop1; + primop1 = tem; + tem = op0; + op0 = op1; + op1 = tem; + *op0_ptr = op0; + *op1_ptr = op1; + unsignedp0 = unsignedp1; + unsignedp1 = temi; + temi = real1; + real1 = real2; + real2 = temi; + + switch (code) + { + case LT_EXPR: + code = GT_EXPR; + break; + case GT_EXPR: + code = LT_EXPR; + break; + case LE_EXPR: + code = GE_EXPR; + break; + case GE_EXPR: + code = LE_EXPR; + break; + } + *rescode_ptr = code; + } + + /* If comparing an integer against a constant more bits wide, + maybe we can deduce a value of 1 or 0 independent of the data. + Or else truncate the constant now + rather than extend the variable at run time. + + This is only interesting if the constant is the wider arg. + Also, it is not safe if the constant is unsigned and the + variable arg is signed, since in this case the variable + would be sign-extended and then regarded as unsigned. + Our technique fails in this case because the lowest/highest + possible unsigned results don't follow naturally from the + lowest/highest possible values of the variable operand. + For just EQ_EXPR and NE_EXPR there is another technique that + could be used: see if the constant can be faithfully represented + in the other operand's type, by truncating it and reextending it + and see if that preserves the constant's value. */ + + if (!real1 && !real2 + && TREE_CODE (primop1) == INTEGER_CST + && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)) + { + int min_gt, max_gt, min_lt, max_lt; + tree maxval, minval; + /* 1 if comparison is nominally unsigned. */ + int unsignedp = TREE_UNSIGNED (*restype_ptr); + tree val; + + type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)); + + maxval = TYPE_MAX_VALUE (type); + minval = TYPE_MIN_VALUE (type); + + if (unsignedp && !unsignedp0) + *restype_ptr = signed_type (*restype_ptr); + + if (TREE_TYPE (primop1) != *restype_ptr) + primop1 = convert (*restype_ptr, primop1); + if (type != *restype_ptr) + { + minval = convert (*restype_ptr, minval); + maxval = convert (*restype_ptr, maxval); + } + + if (unsignedp && unsignedp0) + { + min_gt = INT_CST_LT_UNSIGNED (primop1, minval); + max_gt = INT_CST_LT_UNSIGNED (primop1, maxval); + min_lt = INT_CST_LT_UNSIGNED (minval, primop1); + max_lt = INT_CST_LT_UNSIGNED (maxval, primop1); + } + else + { + min_gt = INT_CST_LT (primop1, minval); + max_gt = INT_CST_LT (primop1, maxval); + min_lt = INT_CST_LT (minval, primop1); + max_lt = INT_CST_LT (maxval, primop1); + } + + val = 0; + /* This used to be a switch, but Genix compiler can't handle that. */ + if (code == NE_EXPR) + { + if (max_lt || min_gt) + val = boolean_true_node; + } + else if (code == EQ_EXPR) + { + if (max_lt || min_gt) + val = boolean_false_node; + } + else if (code == LT_EXPR) + { + if (max_lt) + val = boolean_true_node; + if (!min_lt) + val = boolean_false_node; + } + else if (code == GT_EXPR) + { + if (min_gt) + val = boolean_true_node; + if (!max_gt) + val = boolean_false_node; + } + else if (code == LE_EXPR) + { + if (!max_gt) + val = boolean_true_node; + if (min_gt) + val = boolean_false_node; + } + else if (code == GE_EXPR) + { + if (!min_lt) + val = boolean_true_node; + if (max_lt) + val = boolean_false_node; + } + + /* If primop0 was sign-extended and unsigned comparison specd, + we did a signed comparison above using the signed type bounds. + But the comparison we output must be unsigned. + + Also, for inequalities, VAL is no good; but if the signed + comparison had *any* fixed result, it follows that the + unsigned comparison just tests the sign in reverse + (positive values are LE, negative ones GE). + So we can generate an unsigned comparison + against an extreme value of the signed type. */ + + if (unsignedp && !unsignedp0) + { + if (val != 0) + switch (code) + { + case LT_EXPR: + case GE_EXPR: + primop1 = TYPE_MIN_VALUE (type); + val = 0; + break; + + case LE_EXPR: + case GT_EXPR: + primop1 = TYPE_MAX_VALUE (type); + val = 0; + break; + } + type = unsigned_type (type); + } + + if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST) + { + /* This is the case of (char)x >?< 0x80, which people used to use + expecting old C compilers to change the 0x80 into -0x80. */ + if (val == boolean_false_node) + warning ("comparison is always 0 due to limited range of data type"); + if (val == boolean_true_node) + warning ("comparison is always 1 due to limited range of data type"); + } + + if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST) + { + /* This is the case of (unsigned char)x >?< -1 or < 0. */ + if (val == boolean_false_node) + warning ("comparison is always 0 due to limited range of data type"); + if (val == boolean_true_node) + warning ("comparison is always 1 due to limited range of data type"); + } + + if (val != 0) + { + /* Don't forget to evaluate PRIMOP0 if it has side effects. */ + if (TREE_SIDE_EFFECTS (primop0)) + return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val); + return val; + } + + /* Value is not predetermined, but do the comparison + in the type of the operand that is not constant. + TYPE is already properly set. */ + } + else if (real1 && real2 + && (TYPE_PRECISION (TREE_TYPE (primop0)) + == TYPE_PRECISION (TREE_TYPE (primop1)))) + type = TREE_TYPE (primop0); + + /* If args' natural types are both narrower than nominal type + and both extend in the same manner, compare them + in the type of the wider arg. + Otherwise must actually extend both to the nominal + common type lest different ways of extending + alter the result. + (eg, (short)-1 == (unsigned short)-1 should be 0.) */ + + else if (unsignedp0 == unsignedp1 && real1 == real2 + && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr) + && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr)) + { + type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1)); + type = signed_or_unsigned_type (unsignedp0 + || TREE_UNSIGNED (*restype_ptr), + type); + /* Make sure shorter operand is extended the right way + to match the longer operand. */ + primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)), + primop0); + primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)), + primop1); + } + else + { + /* Here we must do the comparison on the nominal type + using the args exactly as we received them. */ + type = *restype_ptr; + primop0 = op0; + primop1 = op1; + + if (!real1 && !real2 && integer_zerop (primop1) + && TREE_UNSIGNED (*restype_ptr)) + { + tree value = 0; + switch (code) + { + case GE_EXPR: + /* All unsigned values are >= 0, so we warn if extra warnings + are requested. However, if OP0 is a constant that is + >= 0, the signedness of the comparison isn't an issue, + so suppress the warning. */ + if (extra_warnings + && ! (TREE_CODE (primop0) == INTEGER_CST + && ! TREE_OVERFLOW (convert (signed_type (type), + primop0)))) + warning ("unsigned value >= 0 is always 1"); + value = boolean_true_node; + break; + + case LT_EXPR: + if (extra_warnings + && ! (TREE_CODE (primop0) == INTEGER_CST + && ! TREE_OVERFLOW (convert (signed_type (type), + primop0)))) + warning ("unsigned value < 0 is always 0"); + value = boolean_false_node; + } + + if (value != 0) + { + /* Don't forget to evaluate PRIMOP0 if it has side effects. */ + if (TREE_SIDE_EFFECTS (primop0)) + return build (COMPOUND_EXPR, TREE_TYPE (value), + primop0, value); + return value; + } + } + } + + *op0_ptr = convert (type, primop0); + *op1_ptr = convert (type, primop1); + + *restype_ptr = boolean_type_node; + + return 0; +} + +/* Prepare expr to be an argument of a TRUTH_NOT_EXPR, + or validate its data type for an `if' or `while' statement or ?..: exp. + + This preparation consists of taking the ordinary + representation of an expression expr and producing a valid tree + boolean expression describing whether expr is nonzero. We could + simply always do build_binary_op (NE_EXPR, expr, boolean_false_node, 1), + but we optimize comparisons, &&, ||, and !. + + The resulting type should always be `boolean_type_node'. */ + +tree +truthvalue_conversion (expr) + tree expr; +{ + if (TREE_CODE (expr) == ERROR_MARK) + return expr; + +#if 0 /* This appears to be wrong for C++. */ + /* These really should return error_mark_node after 2.4 is stable. + But not all callers handle ERROR_MARK properly. */ + switch (TREE_CODE (TREE_TYPE (expr))) + { + case RECORD_TYPE: + error ("struct type value used where scalar is required"); + return boolean_false_node; + + case UNION_TYPE: + error ("union type value used where scalar is required"); + return boolean_false_node; + + case ARRAY_TYPE: + error ("array type value used where scalar is required"); + return boolean_false_node; + + default: + break; + } +#endif /* 0 */ + + switch (TREE_CODE (expr)) + { + /* It is simpler and generates better code to have only TRUTH_*_EXPR + or comparison expressions as truth values at this level. */ +#if 0 + case COMPONENT_REF: + /* A one-bit unsigned bit-field is already acceptable. */ + if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1))) + && TREE_UNSIGNED (TREE_OPERAND (expr, 1))) + return expr; + break; +#endif + + case EQ_EXPR: + /* It is simpler and generates better code to have only TRUTH_*_EXPR + or comparison expressions as truth values at this level. */ +#if 0 + if (integer_zerop (TREE_OPERAND (expr, 1))) + return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0); +#endif + case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + case TRUTH_XOR_EXPR: + case TRUTH_NOT_EXPR: + TREE_TYPE (expr) = boolean_type_node; + return expr; + + case ERROR_MARK: + return expr; + + case INTEGER_CST: + return integer_zerop (expr) ? boolean_false_node : boolean_true_node; + + case REAL_CST: + return real_zerop (expr) ? boolean_false_node : boolean_true_node; + + case ADDR_EXPR: + if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0))) + return build (COMPOUND_EXPR, boolean_type_node, + TREE_OPERAND (expr, 0), boolean_true_node); + else + return boolean_true_node; + + case COMPLEX_EXPR: + return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) + ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), + truthvalue_conversion (TREE_OPERAND (expr, 0)), + truthvalue_conversion (TREE_OPERAND (expr, 1)), + 0); + + case NEGATE_EXPR: + case ABS_EXPR: + case FLOAT_EXPR: + case FFS_EXPR: + /* These don't change whether an object is non-zero or zero. */ + return truthvalue_conversion (TREE_OPERAND (expr, 0)); + + case LROTATE_EXPR: + case RROTATE_EXPR: + /* These don't change whether an object is zero or non-zero, but + we can't ignore them if their second arg has side-effects. */ + if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) + return build (COMPOUND_EXPR, boolean_type_node, TREE_OPERAND (expr, 1), + truthvalue_conversion (TREE_OPERAND (expr, 0))); + else + return truthvalue_conversion (TREE_OPERAND (expr, 0)); + + case COND_EXPR: + /* Distribute the conversion into the arms of a COND_EXPR. */ + return fold (build (COND_EXPR, boolean_type_node, TREE_OPERAND (expr, 0), + truthvalue_conversion (TREE_OPERAND (expr, 1)), + truthvalue_conversion (TREE_OPERAND (expr, 2)))); + + case CONVERT_EXPR: + /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, + since that affects how `default_conversion' will behave. */ + if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE + || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE) + break; + /* fall through... */ + case NOP_EXPR: + /* If this is widening the argument, we can ignore it. */ + if (TYPE_PRECISION (TREE_TYPE (expr)) + >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) + return truthvalue_conversion (TREE_OPERAND (expr, 0)); + break; + + case MINUS_EXPR: + /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize + this case. */ + if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT + && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE) + break; + /* fall through... */ + case BIT_XOR_EXPR: + /* This and MINUS_EXPR can be changed into a comparison of the + two objects. */ + if (TREE_TYPE (TREE_OPERAND (expr, 0)) + == TREE_TYPE (TREE_OPERAND (expr, 1))) + return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0), + TREE_OPERAND (expr, 1), 1); + return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0), + fold (build1 (NOP_EXPR, + TREE_TYPE (TREE_OPERAND (expr, 0)), + TREE_OPERAND (expr, 1))), 1); + + case BIT_AND_EXPR: + if (integer_onep (TREE_OPERAND (expr, 1)) + && TREE_TYPE (expr) != boolean_type_node) + /* Using convert here would cause infinite recursion. */ + return build1 (NOP_EXPR, boolean_type_node, expr); + break; + + case MODIFY_EXPR: + if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR) + warning ("suggest parentheses around assignment used as truth value"); + break; + } + + if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE) + return (build_binary_op + ((TREE_SIDE_EFFECTS (expr) + ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), + truthvalue_conversion (build_unary_op (REALPART_EXPR, expr, 0)), + truthvalue_conversion (build_unary_op (IMAGPART_EXPR, expr, 0)), + 0)); + + return build_binary_op (NE_EXPR, expr, integer_zero_node, 1); +} + +/* Read the rest of a #-directive from input stream FINPUT. + In normal use, the directive name and the white space after it + have already been read, so they won't be included in the result. + We allow for the fact that the directive line may contain + a newline embedded within a character or string literal which forms + a part of the directive. + + The value is a string in a reusable buffer. It remains valid + only until the next time this function is called. */ + +char * +get_directive_line (finput) + register FILE *finput; +{ + static char *directive_buffer = NULL; + static unsigned buffer_length = 0; + register char *p; + register char *buffer_limit; + register int looking_for = 0; + register int char_escaped = 0; + + if (buffer_length == 0) + { + directive_buffer = (char *)xmalloc (128); + buffer_length = 128; + } + + buffer_limit = &directive_buffer[buffer_length]; + + for (p = directive_buffer; ; ) + { + int c; + + /* Make buffer bigger if it is full. */ + if (p >= buffer_limit) + { + register unsigned bytes_used = (p - directive_buffer); + + buffer_length *= 2; + directive_buffer + = (char *)xrealloc (directive_buffer, buffer_length); + p = &directive_buffer[bytes_used]; + buffer_limit = &directive_buffer[buffer_length]; + } + + c = getc (finput); + + /* Discard initial whitespace. */ + if ((c == ' ' || c == '\t') && p == directive_buffer) + continue; + + /* Detect the end of the directive. */ + if (c == '\n' && looking_for == 0) + { + ungetc (c, finput); + c = '\0'; + } + + *p++ = c; + + if (c == 0) + return directive_buffer; + + /* Handle string and character constant syntax. */ + if (looking_for) + { + if (looking_for == c && !char_escaped) + looking_for = 0; /* Found terminator... stop looking. */ + } + else + if (c == '\'' || c == '"') + looking_for = c; /* Don't stop buffering until we see another + another one of these (or an EOF). */ + + /* Handle backslash. */ + char_escaped = (c == '\\' && ! char_escaped); + } +} + +/* Make a variant type in the proper way for C/C++, propagating qualifiers + down to the element type of an array. */ + +tree +c_build_type_variant (type, constp, volatilep) + tree type; + int constp, volatilep; +{ + if (TREE_CODE (type) == ARRAY_TYPE) + { + tree real_main_variant = TYPE_MAIN_VARIANT (type); + + push_obstacks (TYPE_OBSTACK (real_main_variant), + TYPE_OBSTACK (real_main_variant)); + type = build_array_type (c_build_type_variant (TREE_TYPE (type), + constp, volatilep), + TYPE_DOMAIN (type)); + + /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not, + make a copy. (TYPE might have come from the hash table and + REAL_MAIN_VARIANT might be in some function's obstack.) */ + + if (TYPE_OBSTACK (type) != TYPE_OBSTACK (real_main_variant)) + { + type = copy_node (type); + TYPE_POINTER_TO (type) = TYPE_REFERENCE_TO (type) = 0; + } + + TYPE_MAIN_VARIANT (type) = real_main_variant; + pop_obstacks (); + } + return build_type_variant (type, constp, volatilep); +} diff --git a/contrib/gcc/c-convert.c b/contrib/gcc/c-convert.c new file mode 100644 index 00000000000..8ba93a9816a --- /dev/null +++ b/contrib/gcc/c-convert.c @@ -0,0 +1,96 @@ +/* Language-level data type conversion for GNU C. + Copyright (C) 1987, 1988, 1991 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file contains the functions for converting C expressions + to different data types. The only entry point is `convert'. + Every language front end must have a `convert' function + but what kind of conversions it does will depend on the language. */ + +#include "config.h" +#include "tree.h" +#include "flags.h" +#include "convert.h" + +/* Change of width--truncation and extension of integers or reals-- + is represented with NOP_EXPR. Proper functioning of many things + assumes that no other conversions can be NOP_EXPRs. + + Conversion between integer and pointer is represented with CONVERT_EXPR. + Converting integer to real uses FLOAT_EXPR + and real to integer uses FIX_TRUNC_EXPR. + + Here is a list of all the functions that assume that widening and + narrowing is always done with a NOP_EXPR: + In convert.c, convert_to_integer. + In c-typeck.c, build_binary_op (boolean ops), and truthvalue_conversion. + In expr.c: expand_expr, for operands of a MULT_EXPR. + In fold-const.c: fold. + In tree.c: get_narrower and get_unwidened. */ + +/* Subroutines of `convert'. */ + + + +/* Create an expression whose value is that of EXPR, + converted to type TYPE. The TREE_TYPE of the value + is always TYPE. This function implements all reasonable + conversions; callers should filter out those that are + not permitted by the language being compiled. */ + +tree +convert (type, expr) + tree type, expr; +{ + register tree e = expr; + register enum tree_code code = TREE_CODE (type); + + if (type == TREE_TYPE (expr) + || TREE_CODE (expr) == ERROR_MARK) + return expr; + if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) + return fold (build1 (NOP_EXPR, type, expr)); + if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK) + return error_mark_node; + if (TREE_CODE (TREE_TYPE (expr)) == VOID_TYPE) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + if (code == VOID_TYPE) + return build1 (CONVERT_EXPR, type, e); +#if 0 + /* This is incorrect. A truncation can't be stripped this way. + Extensions will be stripped by the use of get_unwidened. */ + if (TREE_CODE (expr) == NOP_EXPR) + return convert (type, TREE_OPERAND (expr, 0)); +#endif + if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) + return fold (convert_to_integer (type, e)); + if (code == POINTER_TYPE) + return fold (convert_to_pointer (type, e)); + if (code == REAL_TYPE) + return fold (convert_to_real (type, e)); + if (code == COMPLEX_TYPE) + return fold (convert_to_complex (type, e)); + + error ("conversion to non-scalar type requested"); + return error_mark_node; +} diff --git a/contrib/gcc/c-decl.c b/contrib/gcc/c-decl.c new file mode 100644 index 00000000000..ca33a4c99f3 --- /dev/null +++ b/contrib/gcc/c-decl.c @@ -0,0 +1,6967 @@ +/* Process declarations and variables for C compiler. + Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Process declarations and symbol lookup for C front end. + Also constructs types; the standard scalar types at initialization, + and structure, union, array and enum types when they are declared. */ + +/* ??? not all decl nodes are given the most useful possible + line numbers. For example, the CONST_DECLs for enum values. */ + +#include "config.h" +#include "tree.h" +#include "flags.h" +#include "output.h" +#include "c-tree.h" +#include "c-lex.h" +#include + +/* In grokdeclarator, distinguish syntactic contexts of declarators. */ +enum decl_context +{ NORMAL, /* Ordinary declaration */ + FUNCDEF, /* Function definition */ + PARM, /* Declaration of parm before function body */ + FIELD, /* Declaration inside struct or union */ + BITFIELD, /* Likewise but with specified width */ + TYPENAME}; /* Typename (inside cast or sizeof) */ + +#ifndef CHAR_TYPE_SIZE +#define CHAR_TYPE_SIZE BITS_PER_UNIT +#endif + +#ifndef SHORT_TYPE_SIZE +#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) +#endif + +#ifndef INT_TYPE_SIZE +#define INT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_TYPE_SIZE +#define LONG_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_LONG_TYPE_SIZE +#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef WCHAR_UNSIGNED +#define WCHAR_UNSIGNED 0 +#endif + +#ifndef FLOAT_TYPE_SIZE +#define FLOAT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef DOUBLE_TYPE_SIZE +#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +/* We let tm.h override the types used here, to handle trivial differences + such as the choice of unsigned int or long unsigned int for size_t. + When machines start needing nontrivial differences in the size type, + it would be best to do something here to figure out automatically + from other information what type to use. */ + +#ifndef SIZE_TYPE +#define SIZE_TYPE "long unsigned int" +#endif + +#ifndef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" +#endif + +#ifndef WCHAR_TYPE +#define WCHAR_TYPE "int" +#endif + +/* a node which has tree code ERROR_MARK, and whose type is itself. + All erroneous expressions are replaced with this node. All functions + that accept nodes as arguments should avoid generating error messages + if this node is one of the arguments, since it is undesirable to get + multiple error messages from one error in the input. */ + +tree error_mark_node; + +/* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ + +tree short_integer_type_node; +tree integer_type_node; +tree long_integer_type_node; +tree long_long_integer_type_node; + +tree short_unsigned_type_node; +tree unsigned_type_node; +tree long_unsigned_type_node; +tree long_long_unsigned_type_node; + +tree boolean_type_node; +tree boolean_false_node; +tree boolean_true_node; + +tree ptrdiff_type_node; + +tree unsigned_char_type_node; +tree signed_char_type_node; +tree char_type_node; +tree wchar_type_node; +tree signed_wchar_type_node; +tree unsigned_wchar_type_node; + +tree float_type_node; +tree double_type_node; +tree long_double_type_node; + +tree complex_integer_type_node; +tree complex_float_type_node; +tree complex_double_type_node; +tree complex_long_double_type_node; + +tree intQI_type_node; +tree intHI_type_node; +tree intSI_type_node; +tree intDI_type_node; + +tree unsigned_intQI_type_node; +tree unsigned_intHI_type_node; +tree unsigned_intSI_type_node; +tree unsigned_intDI_type_node; + +/* a VOID_TYPE node. */ + +tree void_type_node; + +/* Nodes for types `void *' and `const void *'. */ + +tree ptr_type_node, const_ptr_type_node; + +/* Nodes for types `char *' and `const char *'. */ + +tree string_type_node, const_string_type_node; + +/* Type `char[SOMENUMBER]'. + Used when an array of char is needed and the size is irrelevant. */ + +tree char_array_type_node; + +/* Type `int[SOMENUMBER]' or something like it. + Used when an array of int needed and the size is irrelevant. */ + +tree int_array_type_node; + +/* Type `wchar_t[SOMENUMBER]' or something like it. + Used when a wide string literal is created. */ + +tree wchar_array_type_node; + +/* type `int ()' -- used for implicit declaration of functions. */ + +tree default_function_type; + +/* function types `double (double)' and `double (double, double)', etc. */ + +tree double_ftype_double, double_ftype_double_double; +tree int_ftype_int, long_ftype_long; +tree float_ftype_float; +tree ldouble_ftype_ldouble; + +/* Function type `void (void *, void *, int)' and similar ones */ + +tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; + +/* Function type `char *(char *, char *)' and similar ones */ +tree string_ftype_ptr_ptr, int_ftype_string_string; + +/* Function type `int (const void *, const void *, size_t)' */ +tree int_ftype_cptr_cptr_sizet; + +/* Two expressions that are constants with value zero. + The first is of type `int', the second of type `void *'. */ + +tree integer_zero_node; +tree null_pointer_node; + +/* A node for the integer constant 1. */ + +tree integer_one_node; + +/* Nonzero if we have seen an invalid cross reference + to a struct, union, or enum, but not yet printed the message. */ + +tree pending_invalid_xref; +/* File and line to appear in the eventual error message. */ +char *pending_invalid_xref_file; +int pending_invalid_xref_line; + +/* While defining an enum type, this is 1 plus the last enumerator + constant value. Note that will do not have to save this or `enum_overflow' + around nested function definition since such a definition could only + occur in an enum value expression and we don't use these variables in + that case. */ + +static tree enum_next_value; + +/* Nonzero means that there was overflow computing enum_next_value. */ + +static int enum_overflow; + +/* Parsing a function declarator leaves a list of parameter names + or a chain or parameter decls here. */ + +static tree last_function_parms; + +/* Parsing a function declarator leaves here a chain of structure + and enum types declared in the parmlist. */ + +static tree last_function_parm_tags; + +/* After parsing the declarator that starts a function definition, + `start_function' puts here the list of parameter names or chain of decls. + `store_parm_decls' finds it here. */ + +static tree current_function_parms; + +/* Similar, for last_function_parm_tags. */ +static tree current_function_parm_tags; + +/* Similar, for the file and line that the prototype came from if this is + an old-style definition. */ +static char *current_function_prototype_file; +static int current_function_prototype_line; + +/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function + that have names. Here so we can clear out their names' definitions + at the end of the function. */ + +static tree named_labels; + +/* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ + +static tree shadowed_labels; + +/* Nonzero when store_parm_decls is called indicates a varargs function. + Value not meaningful after store_parm_decls. */ + +static int c_function_varargs; + +/* The FUNCTION_DECL for the function currently being compiled, + or 0 if between functions. */ +tree current_function_decl; + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement that specifies a return value is seen. */ + +int current_function_returns_value; + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement with no argument is seen. */ + +int current_function_returns_null; + +/* Set to nonzero by `grokdeclarator' for a function + whose return type is defaulted, if warnings for this are desired. */ + +static int warn_about_return_type; + +/* Nonzero when starting a function declared `extern inline'. */ + +static int current_extern_inline; + +/* For each binding contour we allocate a binding_level structure + * which records the names defined in that contour. + * Contours include: + * 0) the global one + * 1) one for each function definition, + * where internal declarations of the parameters appear. + * 2) one for each compound statement, + * to record its declarations. + * + * The current meaning of a name can be found by searching the levels from + * the current one out to the global one. + */ + +/* Note that the information in the `names' component of the global contour + is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ + +struct binding_level + { + /* A chain of _DECL nodes for all variables, constants, functions, + and typedef types. These are in the reverse of the order supplied. + */ + tree names; + + /* A list of structure, union and enum definitions, + * for looking up tag names. + * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, + * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, + * or ENUMERAL_TYPE node. + */ + tree tags; + + /* For each level, a list of shadowed outer-level local definitions + to be restored when this level is popped. + Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and + whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ + tree shadowed; + + /* For each level (except not the global one), + a chain of BLOCK nodes for all the levels + that were entered and exited one level down. */ + tree blocks; + + /* The BLOCK node for this level, if one has been preallocated. + If 0, the BLOCK is allocated (if needed) when the level is popped. */ + tree this_block; + + /* The binding level which this one is contained in (inherits from). */ + struct binding_level *level_chain; + + /* Nonzero for the level that holds the parameters of a function. */ + char parm_flag; + + /* Nonzero if this level "doesn't exist" for tags. */ + char tag_transparent; + + /* Nonzero if sublevels of this level "don't exist" for tags. + This is set in the parm level of a function definition + while reading the function body, so that the outermost block + of the function body will be tag-transparent. */ + char subblocks_tag_transparent; + + /* Nonzero means make a BLOCK for this level regardless of all else. */ + char keep; + + /* Nonzero means make a BLOCK if this level has any subblocks. */ + char keep_if_subblocks; + + /* Number of decls in `names' that have incomplete + structure or union types. */ + int n_incomplete; + + /* A list of decls giving the (reversed) specified order of parms, + not including any forward-decls in the parmlist. + This is so we can put the parms in proper order for assign_parms. */ + tree parm_order; + }; + +#define NULL_BINDING_LEVEL (struct binding_level *) NULL + +/* The binding level currently in effect. */ + +static struct binding_level *current_binding_level; + +/* A chain of binding_level structures awaiting reuse. */ + +static struct binding_level *free_binding_level; + +/* The outermost binding level, for names of file scope. + This is created when the compiler is started and exists + through the entire run. */ + +static struct binding_level *global_binding_level; + +/* Binding level structures are initialized by copying this one. */ + +static struct binding_level clear_binding_level + = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0, + NULL}; + +/* Nonzero means unconditionally make a BLOCK for the next level pushed. */ + +static int keep_next_level_flag; + +/* Nonzero means make a BLOCK for the next level pushed + if it has subblocks. */ + +static int keep_next_if_subblocks; + +/* The chain of outer levels of label scopes. + This uses the same data structure used for binding levels, + but it works differently: each link in the chain records + saved values of named_labels and shadowed_labels for + a label binding level outside the current one. */ + +static struct binding_level *label_level_chain; + +/* Functions called automatically at the beginning and end of execution. */ + +tree static_ctors, static_dtors; + +/* Forward declarations. */ + +static tree grokparms (), grokdeclarator (); +tree pushdecl (); +tree builtin_function (); +void shadow_tag_warned (); + +static tree lookup_tag (); +static tree lookup_tag_reverse (); +tree lookup_name_current_level (); +static char *redeclaration_error_message (); +static void layout_array_type (); + +/* C-specific option variables. */ + +/* Nonzero means allow type mismatches in conditional expressions; + just make their values `void'. */ + +int flag_cond_mismatch; + +/* Nonzero means give `double' the same size as `float'. */ + +int flag_short_double; + +/* Nonzero means don't recognize the keyword `asm'. */ + +int flag_no_asm; + +/* Nonzero means don't recognize any builtin functions. */ + +int flag_no_builtin; + +/* Nonzero means don't recognize the non-ANSI builtin functions. + -ansi sets this. */ + +int flag_no_nonansi_builtin; + +/* Nonzero means do some things the same way PCC does. */ + +int flag_traditional; + +/* Nonzero means to allow single precision math even if we're generally + being traditional. */ +int flag_allow_single_precision = 0; + +/* Nonzero means to treat bitfields as signed unless they say `unsigned'. */ + +int flag_signed_bitfields = 1; +int explicit_flag_signed_bitfields = 0; + +/* Nonzero means handle `#ident' directives. 0 means ignore them. */ + +int flag_no_ident = 0; + +/* Nonzero means warn about implicit declarations. */ + +int warn_implicit; + +/* Nonzero means give string constants the type `const char *' + to get extra warnings from them. These warnings will be too numerous + to be useful, except in thoroughly ANSIfied programs. */ + +int warn_write_strings; + +/* Nonzero means warn about pointer casts that can drop a type qualifier + from the pointer target type. */ + +int warn_cast_qual; + +/* Nonzero means warn when casting a function call to a type that does + not match the return type (e.g. (float)sqrt() or (anything*)malloc() + when there is no previous declaration of sqrt or malloc. */ + +int warn_bad_function_cast; + +/* Warn about traditional constructs whose meanings changed in ANSI C. */ + +int warn_traditional; + +/* Nonzero means warn about sizeof(function) or addition/subtraction + of function pointers. */ + +int warn_pointer_arith; + +/* Nonzero means warn for non-prototype function decls + or non-prototyped defs without previous prototype. */ + +int warn_strict_prototypes; + +/* Nonzero means warn for any global function def + without separate previous prototype decl. */ + +int warn_missing_prototypes; + +/* Nonzero means warn for any global function def + without separate previous decl. */ + +int warn_missing_declarations; + +/* Nonzero means warn about multiple (redundant) decls for the same single + variable or function. */ + +int warn_redundant_decls = 0; + +/* Nonzero means warn about extern declarations of objects not at + file-scope level and about *all* declarations of functions (whether + extern or static) not at file-scope level. Note that we exclude + implicit function declarations. To get warnings about those, use + -Wimplicit. */ + +int warn_nested_externs = 0; + +/* Warn about *printf or *scanf format/argument anomalies. */ + +int warn_format; + +/* Warn about a subscript that has type char. */ + +int warn_char_subscripts = 0; + +/* Warn if a type conversion is done that might have confusing results. */ + +int warn_conversion; + +/* Warn if adding () is suggested. */ + +int warn_parentheses; + +/* Warn if initializer is not completely bracketed. */ + +int warn_missing_braces; + +/* Nonzero means `$' can be in an identifier. + See cccp.c for reasons why this breaks some obscure ANSI C programs. */ + +#ifndef DOLLARS_IN_IDENTIFIERS +#define DOLLARS_IN_IDENTIFIERS 1 +#endif +int dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1; + +/* Decode the string P as a language-specific option for C. + Return 1 if it is recognized (and handle it); + return 0 if not recognized. */ + +int +c_decode_option (p) + char *p; +{ + if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) + { + flag_traditional = 1; + flag_writable_strings = 1; +#if DOLLARS_IN_IDENTIFIERS > 0 + dollars_in_ident = 1; +#endif + } + else if (!strcmp (p, "-fallow-single-precision")) + flag_allow_single_precision = 1; + else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional")) + { + flag_traditional = 0; + flag_writable_strings = 0; + dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1; + } + else if (!strcmp (p, "-fdollars-in-identifiers")) + { +#if DOLLARS_IN_IDENTIFIERS > 0 + dollars_in_ident = 1; +#endif + } + else if (!strcmp (p, "-fno-dollars-in-identifiers")) + dollars_in_ident = 0; + else if (!strcmp (p, "-fsigned-char")) + flag_signed_char = 1; + else if (!strcmp (p, "-funsigned-char")) + flag_signed_char = 0; + else if (!strcmp (p, "-fno-signed-char")) + flag_signed_char = 0; + else if (!strcmp (p, "-fno-unsigned-char")) + flag_signed_char = 1; + else if (!strcmp (p, "-fsigned-bitfields") + || !strcmp (p, "-fno-unsigned-bitfields")) + { + flag_signed_bitfields = 1; + explicit_flag_signed_bitfields = 1; + } + else if (!strcmp (p, "-funsigned-bitfields") + || !strcmp (p, "-fno-signed-bitfields")) + { + flag_signed_bitfields = 0; + explicit_flag_signed_bitfields = 1; + } + else if (!strcmp (p, "-fshort-enums")) + flag_short_enums = 1; + else if (!strcmp (p, "-fno-short-enums")) + flag_short_enums = 0; + else if (!strcmp (p, "-fcond-mismatch")) + flag_cond_mismatch = 1; + else if (!strcmp (p, "-fno-cond-mismatch")) + flag_cond_mismatch = 0; + else if (!strcmp (p, "-fshort-double")) + flag_short_double = 1; + else if (!strcmp (p, "-fno-short-double")) + flag_short_double = 0; + else if (!strcmp (p, "-fasm")) + flag_no_asm = 0; + else if (!strcmp (p, "-fno-asm")) + flag_no_asm = 1; + else if (!strcmp (p, "-fbuiltin")) + flag_no_builtin = 0; + else if (!strcmp (p, "-fno-builtin")) + flag_no_builtin = 1; + else if (!strcmp (p, "-fno-ident")) + flag_no_ident = 1; + else if (!strcmp (p, "-fident")) + flag_no_ident = 0; + else if (!strcmp (p, "-ansi")) + flag_no_asm = 1, flag_no_nonansi_builtin = 1, dollars_in_ident = 0; + else if (!strcmp (p, "-Wimplicit")) + warn_implicit = 1; + else if (!strcmp (p, "-Wno-implicit")) + warn_implicit = 0; + else if (!strcmp (p, "-Wwrite-strings")) + warn_write_strings = 1; + else if (!strcmp (p, "-Wno-write-strings")) + warn_write_strings = 0; + else if (!strcmp (p, "-Wcast-qual")) + warn_cast_qual = 1; + else if (!strcmp (p, "-Wno-cast-qual")) + warn_cast_qual = 0; + else if (!strcmp (p, "-Wbad-function-cast")) + warn_bad_function_cast = 1; + else if (!strcmp (p, "-Wno-bad-function-cast")) + warn_bad_function_cast = 0; + else if (!strcmp (p, "-Wpointer-arith")) + warn_pointer_arith = 1; + else if (!strcmp (p, "-Wno-pointer-arith")) + warn_pointer_arith = 0; + else if (!strcmp (p, "-Wstrict-prototypes")) + warn_strict_prototypes = 1; + else if (!strcmp (p, "-Wno-strict-prototypes")) + warn_strict_prototypes = 0; + else if (!strcmp (p, "-Wmissing-prototypes")) + warn_missing_prototypes = 1; + else if (!strcmp (p, "-Wno-missing-prototypes")) + warn_missing_prototypes = 0; + else if (!strcmp (p, "-Wmissing-declarations")) + warn_missing_declarations = 1; + else if (!strcmp (p, "-Wno-missing-declarations")) + warn_missing_declarations = 0; + else if (!strcmp (p, "-Wredundant-decls")) + warn_redundant_decls = 1; + else if (!strcmp (p, "-Wno-redundant-decls")) + warn_redundant_decls = 0; + else if (!strcmp (p, "-Wnested-externs")) + warn_nested_externs = 1; + else if (!strcmp (p, "-Wno-nested-externs")) + warn_nested_externs = 0; + else if (!strcmp (p, "-Wtraditional")) + warn_traditional = 1; + else if (!strcmp (p, "-Wno-traditional")) + warn_traditional = 0; + else if (!strcmp (p, "-Wformat")) + warn_format = 1; + else if (!strcmp (p, "-Wno-format")) + warn_format = 0; + else if (!strcmp (p, "-Wchar-subscripts")) + warn_char_subscripts = 1; + else if (!strcmp (p, "-Wno-char-subscripts")) + warn_char_subscripts = 0; + else if (!strcmp (p, "-Wconversion")) + warn_conversion = 1; + else if (!strcmp (p, "-Wno-conversion")) + warn_conversion = 0; + else if (!strcmp (p, "-Wparentheses")) + warn_parentheses = 1; + else if (!strcmp (p, "-Wno-parentheses")) + warn_parentheses = 0; + else if (!strcmp (p, "-Wreturn-type")) + warn_return_type = 1; + else if (!strcmp (p, "-Wno-return-type")) + warn_return_type = 0; + else if (!strcmp (p, "-Wcomment")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wno-comment")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wcomments")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wno-comments")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wtrigraphs")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wno-trigraphs")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wimport")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wno-import")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "-Wmissing-braces")) + warn_missing_braces = 1; + else if (!strcmp (p, "-Wno-missing-braces")) + warn_missing_braces = 0; + else if (!strcmp (p, "-Wall")) + { + /* We save the value of warn_uninitialized, since if they put + -Wuninitialized on the command line, we need to generate a + warning about not using it without also specifying -O. */ + if (warn_uninitialized != 1) + warn_uninitialized = 2; + warn_implicit = 1; + warn_return_type = 1; + warn_unused = 1; + warn_switch = 1; + warn_format = 1; + warn_char_subscripts = 1; + warn_parentheses = 1; + warn_missing_braces = 1; + } + else + return 0; + + return 1; +} + +/* Hooks for print_node. */ + +void +print_lang_decl (file, node, indent) + FILE *file; + tree node; + int indent; +{ +} + +void +print_lang_type (file, node, indent) + FILE *file; + tree node; + int indent; +{ +} + +void +print_lang_identifier (file, node, indent) + FILE *file; + tree node; + int indent; +{ + print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); + print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); + print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); + print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); + print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); + print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4); +} + +/* Hook called at end of compilation to assume 1 elt + for a top-level array decl that wasn't complete before. */ + +void +finish_incomplete_decl (decl) + tree decl; +{ + if (TREE_CODE (decl) == VAR_DECL && TREE_TYPE (decl) != error_mark_node) + { + tree type = TREE_TYPE (decl); + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == 0 + && TREE_CODE (decl) != TYPE_DECL) + { + complete_array_type (type, NULL_TREE, 1); + + layout_decl (decl, 0); + } + } +} + +/* Create a new `struct binding_level'. */ + +static +struct binding_level * +make_binding_level () +{ + /* NOSTRICT */ + return (struct binding_level *) xmalloc (sizeof (struct binding_level)); +} + +/* Nonzero if we are currently in the global binding level. */ + +int +global_bindings_p () +{ + return current_binding_level == global_binding_level; +} + +void +keep_next_level () +{ + keep_next_level_flag = 1; +} + +/* Nonzero if the current level needs to have a BLOCK made. */ + +int +kept_level_p () +{ + return ((current_binding_level->keep_if_subblocks + && current_binding_level->blocks != 0) + || current_binding_level->keep + || current_binding_level->names != 0 + || (current_binding_level->tags != 0 + && !current_binding_level->tag_transparent)); +} + +/* Identify this binding level as a level of parameters. + DEFINITION_FLAG is 1 for a definition, 0 for a declaration. + But it turns out there is no way to pass the right value for + DEFINITION_FLAG, so we ignore it. */ + +void +declare_parm_level (definition_flag) + int definition_flag; +{ + current_binding_level->parm_flag = 1; +} + +/* Nonzero if currently making parm declarations. */ + +int +in_parm_level_p () +{ + return current_binding_level->parm_flag; +} + +/* Enter a new binding level. + If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, + not for that of tags. */ + +void +pushlevel (tag_transparent) + int tag_transparent; +{ + register struct binding_level *newlevel = NULL_BINDING_LEVEL; + + /* If this is the top level of a function, + just make sure that NAMED_LABELS is 0. */ + + if (current_binding_level == global_binding_level) + { + named_labels = 0; + } + + /* Reuse or create a struct for this binding level. */ + + if (free_binding_level) + { + newlevel = free_binding_level; + free_binding_level = free_binding_level->level_chain; + } + else + { + newlevel = make_binding_level (); + } + + /* Add this level to the front of the chain (stack) of levels that + are active. */ + + *newlevel = clear_binding_level; + newlevel->tag_transparent + = (tag_transparent + || (current_binding_level + ? current_binding_level->subblocks_tag_transparent + : 0)); + newlevel->level_chain = current_binding_level; + current_binding_level = newlevel; + newlevel->keep = keep_next_level_flag; + keep_next_level_flag = 0; + newlevel->keep_if_subblocks = keep_next_if_subblocks; + keep_next_if_subblocks = 0; +} + +/* Exit a binding level. + Pop the level off, and restore the state of the identifier-decl mappings + that were in effect when this level was entered. + + If KEEP is nonzero, this level had explicit declarations, so + and create a "block" (a BLOCK node) for the level + to record its declarations and subblocks for symbol table output. + + If FUNCTIONBODY is nonzero, this level is the body of a function, + so create a block as if KEEP were set and also clear out all + label names. + + If REVERSE is nonzero, reverse the order of decls before putting + them into the BLOCK. */ + +tree +poplevel (keep, reverse, functionbody) + int keep; + int reverse; + int functionbody; +{ + register tree link; + /* The chain of decls was accumulated in reverse order. + Put it into forward order, just for cleanliness. */ + tree decls; + tree tags = current_binding_level->tags; + tree subblocks = current_binding_level->blocks; + tree block = 0; + tree decl; + int block_previously_created; + + keep |= current_binding_level->keep; + + /* This warning is turned off because it causes warnings for + declarations like `extern struct foo *x'. */ +#if 0 + /* Warn about incomplete structure types in this level. */ + for (link = tags; link; link = TREE_CHAIN (link)) + if (TYPE_SIZE (TREE_VALUE (link)) == 0) + { + tree type = TREE_VALUE (link); + char *errmsg; + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + errmsg = "`struct %s' incomplete in scope ending here"; + break; + case UNION_TYPE: + errmsg = "`union %s' incomplete in scope ending here"; + break; + case ENUMERAL_TYPE: + errmsg = "`enum %s' incomplete in scope ending here"; + break; + } + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); + else + /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ + error (errmsg, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); + } +#endif /* 0 */ + + /* Get the decls in the order they were written. + Usually current_binding_level->names is in reverse order. + But parameter decls were previously put in forward order. */ + + if (reverse) + current_binding_level->names + = decls = nreverse (current_binding_level->names); + else + decls = current_binding_level->names; + + /* Output any nested inline functions within this block + if they weren't already output. */ + + for (decl = decls; decl; decl = TREE_CHAIN (decl)) + if (TREE_CODE (decl) == FUNCTION_DECL + && ! TREE_ASM_WRITTEN (decl) + && DECL_INITIAL (decl) != 0 + && TREE_ADDRESSABLE (decl)) + { + /* If this decl was copied from a file-scope decl + on account of a block-scope extern decl, + propagate TREE_ADDRESSABLE to the file-scope decl. + + DECL_ABSTRACT_ORIGIN can be set to itself if warn_return_type is + true, since then the decl goes through save_for_inline_copying. */ + if (DECL_ABSTRACT_ORIGIN (decl) != 0 + && DECL_ABSTRACT_ORIGIN (decl) != decl) + TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; + else + { + push_function_context (); + output_inline_function (decl); + pop_function_context (); + } + } + + /* If there were any declarations or structure tags in that level, + or if this level is a function body, + create a BLOCK to record them for the life of this function. */ + + block = 0; + block_previously_created = (current_binding_level->this_block != 0); + if (block_previously_created) + block = current_binding_level->this_block; + else if (keep || functionbody + || (current_binding_level->keep_if_subblocks && subblocks != 0)) + block = make_node (BLOCK); + if (block != 0) + { + BLOCK_VARS (block) = decls; + BLOCK_TYPE_TAGS (block) = tags; + BLOCK_SUBBLOCKS (block) = subblocks; + remember_end_note (block); + } + + /* In each subblock, record that this is its superior. */ + + for (link = subblocks; link; link = TREE_CHAIN (link)) + BLOCK_SUPERCONTEXT (link) = block; + + /* Clear out the meanings of the local variables of this level. */ + + for (link = decls; link; link = TREE_CHAIN (link)) + { + if (DECL_NAME (link) != 0) + { + /* If the ident. was used or addressed via a local extern decl, + don't forget that fact. */ + if (DECL_EXTERNAL (link)) + { + if (TREE_USED (link)) + TREE_USED (DECL_NAME (link)) = 1; + if (TREE_ADDRESSABLE (link)) + TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; + } + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; + } + } + + /* Restore all name-meanings of the outer levels + that were shadowed by this level. */ + + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + + /* If the level being exited is the top level of a function, + check over all the labels, and clear out the current + (function local) meanings of their names. */ + + if (functionbody) + { + /* If this is the top level block of a function, + the vars are the function's parameters. + Don't leave them in the BLOCK because they are + found in the FUNCTION_DECL instead. */ + + BLOCK_VARS (block) = 0; + + /* Clear out the definitions of all label names, + since their scopes end here, + and add them to BLOCK_VARS. */ + + for (link = named_labels; link; link = TREE_CHAIN (link)) + { + register tree label = TREE_VALUE (link); + + if (DECL_INITIAL (label) == 0) + { + error_with_decl (label, "label `%s' used but not defined"); + /* Avoid crashing later. */ + define_label (input_filename, lineno, + DECL_NAME (label)); + } + else if (warn_unused && !TREE_USED (label)) + warning_with_decl (label, "label `%s' defined but not used"); + IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0; + + /* Put the labels into the "variables" of the + top-level block, so debugger can see them. */ + TREE_CHAIN (label) = BLOCK_VARS (block); + BLOCK_VARS (block) = label; + } + } + + /* Pop the current level, and free the structure for reuse. */ + + { + register struct binding_level *level = current_binding_level; + current_binding_level = current_binding_level->level_chain; + + level->level_chain = free_binding_level; + free_binding_level = level; + } + + /* Dispose of the block that we just made inside some higher level. */ + if (functionbody) + DECL_INITIAL (current_function_decl) = block; + else if (block) + { + if (!block_previously_created) + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); + } + /* If we did not make a block for the level just exited, + any blocks made for inner levels + (since they cannot be recorded as subblocks in that level) + must be carried forward so they will later become subblocks + of something else. */ + else if (subblocks) + current_binding_level->blocks + = chainon (current_binding_level->blocks, subblocks); + + /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this + binding contour so that they point to the appropriate construct, i.e. + either to the current FUNCTION_DECL node, or else to the BLOCK node + we just constructed. + + Note that for tagged types whose scope is just the formal parameter + list for some function type specification, we can't properly set + their TYPE_CONTEXTs here, because we don't have a pointer to the + appropriate FUNCTION_TYPE node readily available to us. For those + cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set + in `grokdeclarator' as soon as we have created the FUNCTION_TYPE + node which will represent the "scope" for these "parameter list local" + tagged types. + */ + + if (functionbody) + for (link = tags; link; link = TREE_CHAIN (link)) + TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl; + else if (block) + for (link = tags; link; link = TREE_CHAIN (link)) + TYPE_CONTEXT (TREE_VALUE (link)) = block; + + if (block) + TREE_USED (block) = 1; + return block; +} + +/* Delete the node BLOCK from the current binding level. + This is used for the block inside a stmt expr ({...}) + so that the block can be reinserted where appropriate. */ + +void +delete_block (block) + tree block; +{ + tree t; + if (current_binding_level->blocks == block) + current_binding_level->blocks = TREE_CHAIN (block); + for (t = current_binding_level->blocks; t;) + { + if (TREE_CHAIN (t) == block) + TREE_CHAIN (t) = TREE_CHAIN (block); + else + t = TREE_CHAIN (t); + } + TREE_CHAIN (block) = NULL; + /* Clear TREE_USED which is always set by poplevel. + The flag is set again if insert_block is called. */ + TREE_USED (block) = 0; +} + +/* Insert BLOCK at the end of the list of subblocks of the + current binding level. This is used when a BIND_EXPR is expanded, + to handle the BLOCK node inside the BIND_EXPR. */ + +void +insert_block (block) + tree block; +{ + TREE_USED (block) = 1; + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); +} + +/* Set the BLOCK node for the innermost scope + (the one we are currently in). */ + +void +set_block (block) + register tree block; +{ + current_binding_level->this_block = block; +} + +void +push_label_level () +{ + register struct binding_level *newlevel; + + /* Reuse or create a struct for this binding level. */ + + if (free_binding_level) + { + newlevel = free_binding_level; + free_binding_level = free_binding_level->level_chain; + } + else + { + newlevel = make_binding_level (); + } + + /* Add this level to the front of the chain (stack) of label levels. */ + + newlevel->level_chain = label_level_chain; + label_level_chain = newlevel; + + newlevel->names = named_labels; + newlevel->shadowed = shadowed_labels; + named_labels = 0; + shadowed_labels = 0; +} + +void +pop_label_level () +{ + register struct binding_level *level = label_level_chain; + tree link, prev; + + /* Clear out the definitions of the declared labels in this level. + Leave in the list any ordinary, non-declared labels. */ + for (link = named_labels, prev = 0; link;) + { + if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link))) + { + if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0) + { + error_with_decl (TREE_VALUE (link), + "label `%s' used but not defined"); + /* Avoid crashing later. */ + define_label (input_filename, lineno, + DECL_NAME (TREE_VALUE (link))); + } + else if (warn_unused && !TREE_USED (TREE_VALUE (link))) + warning_with_decl (TREE_VALUE (link), + "label `%s' defined but not used"); + IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0; + + /* Delete this element from the list. */ + link = TREE_CHAIN (link); + if (prev) + TREE_CHAIN (prev) = link; + else + named_labels = link; + } + else + { + prev = link; + link = TREE_CHAIN (link); + } + } + + /* Bring back all the labels that were shadowed. */ + for (link = shadowed_labels; link; link = TREE_CHAIN (link)) + if (DECL_NAME (TREE_VALUE (link)) != 0) + IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) + = TREE_VALUE (link); + + named_labels = chainon (named_labels, level->names); + shadowed_labels = level->shadowed; + + /* Pop the current level, and free the structure for reuse. */ + label_level_chain = label_level_chain->level_chain; + level->level_chain = free_binding_level; + free_binding_level = level; +} + +/* Push a definition or a declaration of struct, union or enum tag "name". + "type" should be the type node. + We assume that the tag "name" is not already defined. + + Note that the definition may really be just a forward reference. + In that case, the TYPE_SIZE will be zero. */ + +void +pushtag (name, type) + tree name, type; +{ + register struct binding_level *b; + + /* Find the proper binding level for this type tag. */ + + for (b = current_binding_level; b->tag_transparent; b = b->level_chain) + continue; + + if (name) + { + /* Record the identifier as the type's name if it has none. */ + + if (TYPE_NAME (type) == 0) + TYPE_NAME (type) = name; + } + + if (b == global_binding_level) + b->tags = perm_tree_cons (name, type, b->tags); + else + b->tags = saveable_tree_cons (name, type, b->tags); + + /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the + tagged type we just added to the current binding level. This fake + NULL-named TYPE_DECL node helps dwarfout.c to know when it needs + to output a representation of a tagged type, and it also gives + us a convenient place to record the "scope start" address for the + tagged type. */ + + TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); +} + +/* Handle when a new declaration NEWDECL + has the same name as an old one OLDDECL + in the same binding contour. + Prints an error message if appropriate. + + If safely possible, alter OLDDECL to look like NEWDECL, and return 1. + Otherwise, return 0. */ + +static int +duplicate_decls (newdecl, olddecl) + register tree newdecl, olddecl; +{ + int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); + int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_INITIAL (newdecl) != 0); + tree oldtype = TREE_TYPE (olddecl); + tree newtype = TREE_TYPE (newdecl); + char *errmsg = 0; + + if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') + DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); + + if (TREE_CODE (newtype) == ERROR_MARK + || TREE_CODE (oldtype) == ERROR_MARK) + types_match = 0; + + /* New decl is completely inconsistent with the old one => + tell caller to replace the old one. + This is always an error except in the case of shadowing a builtin. */ + if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) + { + if (TREE_CODE (olddecl) == FUNCTION_DECL + && (DECL_BUILT_IN (olddecl) + || DECL_BUILT_IN_NONANSI (olddecl))) + { + /* If you declare a built-in or predefined function name as static, + the old definition is overridden, + but optionally warn this was a bad choice of name. */ + if (!TREE_PUBLIC (newdecl)) + { + if (!warn_shadow) + ; + else if (DECL_BUILT_IN (olddecl)) + warning_with_decl (newdecl, "shadowing built-in function `%s'"); + else + warning_with_decl (newdecl, "shadowing library function `%s'"); + } + /* Likewise, if the built-in is not ansi, then programs can + override it even globally without an error. */ + else if (! DECL_BUILT_IN (olddecl)) + warning_with_decl (newdecl, + "library function `%s' declared as non-function"); + + else if (DECL_BUILT_IN_NONANSI (olddecl)) + warning_with_decl (newdecl, + "built-in function `%s' declared as non-function"); + else + warning_with_decl (newdecl, + "built-in function `%s' declared as non-function"); + } + else + { + error_with_decl (newdecl, "`%s' redeclared as different kind of symbol"); + error_with_decl (olddecl, "previous declaration of `%s'"); + } + + return 0; + } + + /* For real parm decl following a forward decl, + return 1 so old decl will be reused. */ + if (types_match && TREE_CODE (newdecl) == PARM_DECL + && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl)) + return 1; + + /* The new declaration is the same kind of object as the old one. + The declarations may partially match. Print warnings if they don't + match enough. Ultimately, copy most of the information from the new + decl to the old one, and keep using the old one. */ + + if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL + && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl + && DECL_INITIAL (olddecl) == 0) + /* If -traditional, avoid error for redeclaring fcn + after implicit decl. */ + ; + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_BUILT_IN (olddecl)) + { + /* A function declaration for a built-in function. */ + if (!TREE_PUBLIC (newdecl)) + { + /* If you declare a built-in function name as static, the + built-in definition is overridden, + but optionally warn this was a bad choice of name. */ + if (warn_shadow) + warning_with_decl (newdecl, "shadowing built-in function `%s'"); + /* Discard the old built-in function. */ + return 0; + } + else if (!types_match) + { + /* Accept the return type of the new declaration if same modes. */ + tree oldreturntype = TREE_TYPE (TREE_TYPE (olddecl)); + tree newreturntype = TREE_TYPE (TREE_TYPE (newdecl)); + + /* Make sure we put the new type in the same obstack as the old ones. + If the old types are not both in the same obstack, use the + permanent one. */ + if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype)) + push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); + else + { + push_obstacks_nochange (); + end_temporary_allocation (); + } + + if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype)) + { + /* Function types may be shared, so we can't just modify + the return type of olddecl's function type. */ + tree newtype + = build_function_type (newreturntype, + TYPE_ARG_TYPES (TREE_TYPE (olddecl))); + + types_match = comptypes (TREE_TYPE (newdecl), newtype); + if (types_match) + TREE_TYPE (olddecl) = newtype; + } + /* Accept harmless mismatch in first argument type also. + This is for ffs. */ + if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0 + && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0 + && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl))) != 0 + && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (olddecl))) != 0 + && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl)))) + == + TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (olddecl)))))) + { + /* Function types may be shared, so we can't just modify + the return type of olddecl's function type. */ + tree newtype + = build_function_type (TREE_TYPE (TREE_TYPE (olddecl)), + tree_cons (NULL_TREE, + TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl))), + TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (olddecl))))); + + types_match = comptypes (TREE_TYPE (newdecl), newtype); + if (types_match) + TREE_TYPE (olddecl) = newtype; + } + + pop_obstacks (); + } + if (!types_match) + { + /* If types don't match for a built-in, throw away the built-in. */ + warning_with_decl (newdecl, "conflicting types for built-in function `%s'"); + return 0; + } + } + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_SOURCE_LINE (olddecl) == 0) + { + /* A function declaration for a predeclared function + that isn't actually built in. */ + if (!TREE_PUBLIC (newdecl)) + { + /* If you declare it as static, the + default definition is overridden. */ + return 0; + } + else if (!types_match) + { + /* If the types don't match, preserve volatility indication. + Later on, we will discard everything else about the + default declaration. */ + TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); + } + } + /* Permit char *foo () to match void *foo (...) if not pedantic, + if one of them came from a system header file. */ + else if (!types_match + && TREE_CODE (olddecl) == FUNCTION_DECL + && TREE_CODE (newdecl) == FUNCTION_DECL + && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE + && (DECL_IN_SYSTEM_HEADER (olddecl) + || DECL_IN_SYSTEM_HEADER (newdecl)) + && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node + && TYPE_ARG_TYPES (oldtype) == 0 + && self_promoting_args_p (TYPE_ARG_TYPES (newtype)) + && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node) + || + (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node + && TYPE_ARG_TYPES (newtype) == 0 + && self_promoting_args_p (TYPE_ARG_TYPES (oldtype)) + && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node))) + { + if (pedantic) + pedwarn_with_decl (newdecl, "conflicting types for `%s'"); + /* Make sure we keep void * as ret type, not char *. */ + if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node) + TREE_TYPE (newdecl) = newtype = oldtype; + + /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration + we will come back here again. */ + DECL_IN_SYSTEM_HEADER (newdecl) = 1; + } + else if (!types_match + /* Permit char *foo (int, ...); followed by char *foo (); + if not pedantic. */ + && ! (TREE_CODE (olddecl) == FUNCTION_DECL + && ! pedantic + /* Return types must still match. */ + && comptypes (TREE_TYPE (oldtype), + TREE_TYPE (newtype)) + && TYPE_ARG_TYPES (newtype) == 0)) + { + error_with_decl (newdecl, "conflicting types for `%s'"); + /* Check for function type mismatch + involving an empty arglist vs a nonempty one. */ + if (TREE_CODE (olddecl) == FUNCTION_DECL + && comptypes (TREE_TYPE (oldtype), + TREE_TYPE (newtype)) + && ((TYPE_ARG_TYPES (oldtype) == 0 + && DECL_INITIAL (olddecl) == 0) + || + (TYPE_ARG_TYPES (newtype) == 0 + && DECL_INITIAL (newdecl) == 0))) + { + /* Classify the problem further. */ + register tree t = TYPE_ARG_TYPES (oldtype); + if (t == 0) + t = TYPE_ARG_TYPES (newtype); + for (; t; t = TREE_CHAIN (t)) + { + register tree type = TREE_VALUE (t); + + if (TREE_CHAIN (t) == 0 + && TYPE_MAIN_VARIANT (type) != void_type_node) + { + error ("A parameter list with an ellipsis can't match"); + error ("an empty parameter name list declaration."); + break; + } + + if (TYPE_MAIN_VARIANT (type) == float_type_node + || C_PROMOTING_INTEGER_TYPE_P (type)) + { + error ("An argument type that has a default promotion"); + error ("can't match an empty parameter name list declaration."); + break; + } + } + } + error_with_decl (olddecl, "previous declaration of `%s'"); + } + else + { + errmsg = redeclaration_error_message (newdecl, olddecl); + if (errmsg) + { + error_with_decl (newdecl, errmsg); + error_with_decl (olddecl, + ((DECL_INITIAL (olddecl) + && current_binding_level == global_binding_level) + ? "`%s' previously defined here" + : "`%s' previously declared here")); + } + else if (TREE_CODE (newdecl) == TYPE_DECL + && (DECL_IN_SYSTEM_HEADER (olddecl) + || DECL_IN_SYSTEM_HEADER (newdecl))) + { + warning_with_decl (newdecl, "redefinition of `%s'"); + warning_with_decl + (olddecl, + ((DECL_INITIAL (olddecl) + && current_binding_level == global_binding_level) + ? "`%s' previously defined here" + : "`%s' previously declared here")); + } + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_INITIAL (olddecl) != 0 + && TYPE_ARG_TYPES (oldtype) == 0 + && TYPE_ARG_TYPES (newtype) != 0 + && TYPE_ACTUAL_ARG_TYPES (oldtype) != 0) + { + register tree type, parm; + register int nargs; + /* Prototype decl follows defn w/o prototype. */ + + for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype), + type = TYPE_ARG_TYPES (newtype), + nargs = 1; + (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) != void_type_node + || TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node); + parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++) + { + if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node + || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) + { + errmsg = "prototype for `%s' follows and number of arguments"; + break; + } + /* Type for passing arg must be consistent + with that declared for the arg. */ + if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)) + /* If -traditional, allow `unsigned int' instead of `int' + in the prototype. */ + && (! (flag_traditional + && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node + && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))) + { + errmsg = "prototype for `%s' follows and argument %d"; + break; + } + } + if (errmsg) + { + error_with_decl (newdecl, errmsg, nargs); + error_with_decl (olddecl, + "doesn't match non-prototype definition here"); + } + else + { + warning_with_decl (newdecl, "prototype for `%s' follows"); + warning_with_decl (olddecl, "non-prototype definition here"); + } + } + /* Warn about mismatches in various flags. */ + else + { + /* Warn if function is now inline + but was previously declared not inline and has been called. */ + if (TREE_CODE (olddecl) == FUNCTION_DECL + && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) + && TREE_USED (olddecl)) + warning_with_decl (newdecl, + "`%s' declared inline after being called"); + if (TREE_CODE (olddecl) == FUNCTION_DECL + && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) + && DECL_INITIAL (olddecl) != 0) + warning_with_decl (newdecl, + "`%s' declared inline after its definition"); + + /* If pedantic, warn when static declaration follows a non-static + declaration. Otherwise, do so only for functions. */ + if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL) + && TREE_PUBLIC (olddecl) + && !TREE_PUBLIC (newdecl)) + warning_with_decl (newdecl, "static declaration for `%s' follows non-static"); + + /* Warn when const declaration follows a non-const + declaration, but not for functions. */ + if (TREE_CODE (olddecl) != FUNCTION_DECL + && !TREE_READONLY (olddecl) + && TREE_READONLY (newdecl)) + warning_with_decl (newdecl, "const declaration for `%s' follows non-const"); + /* These bits are logically part of the type, for variables. + But not for functions + (where qualifiers are not valid ANSI anyway). */ + else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL + && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) + || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) + pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl"); + } + } + + /* Optionally warn about more than one declaration for the same name. */ + if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0 + /* Dont warn about a function declaration + followed by a definition. */ + && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0 + && DECL_INITIAL (olddecl) == 0) + /* Don't warn about extern decl followed by (tentative) definition. */ + && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) + { + warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope"); + warning_with_decl (olddecl, "previous declaration of `%s'"); + } + + /* Copy all the DECL_... slots specified in the new decl + except for any that we copy here from the old type. + + Past this point, we don't change OLDTYPE and NEWTYPE + even if we change the types of NEWDECL and OLDDECL. */ + + if (types_match) + { + /* Make sure we put the new type in the same obstack as the old ones. + If the old types are not both in the same obstack, use the permanent + one. */ + if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype)) + push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); + else + { + push_obstacks_nochange (); + end_temporary_allocation (); + } + + /* Merge the data types specified in the two decls. */ + if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl)) + TREE_TYPE (newdecl) + = TREE_TYPE (olddecl) + = common_type (newtype, oldtype); + + /* Lay the type out, unless already done. */ + if (oldtype != TREE_TYPE (newdecl)) + { + if (TREE_TYPE (newdecl) != error_mark_node) + layout_type (TREE_TYPE (newdecl)); + if (TREE_CODE (newdecl) != FUNCTION_DECL + && TREE_CODE (newdecl) != TYPE_DECL + && TREE_CODE (newdecl) != CONST_DECL) + layout_decl (newdecl, 0); + } + else + { + /* Since the type is OLDDECL's, make OLDDECL's size go with. */ + DECL_SIZE (newdecl) = DECL_SIZE (olddecl); + if (TREE_CODE (olddecl) != FUNCTION_DECL) + if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) + DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); + } + + /* Keep the old rtl since we can safely use it. */ + DECL_RTL (newdecl) = DECL_RTL (olddecl); + + /* Merge the type qualifiers. */ + if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl) + && !TREE_THIS_VOLATILE (newdecl)) + TREE_THIS_VOLATILE (olddecl) = 0; + if (TREE_READONLY (newdecl)) + TREE_READONLY (olddecl) = 1; + if (TREE_THIS_VOLATILE (newdecl)) + { + TREE_THIS_VOLATILE (olddecl) = 1; + if (TREE_CODE (newdecl) == VAR_DECL) + make_var_volatile (newdecl); + } + + /* Keep source location of definition rather than declaration. + Likewise, keep decl at outer scope. */ + if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0) + || (DECL_CONTEXT (newdecl) != 0 && DECL_CONTEXT (olddecl) == 0)) + { + DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); + DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); + + if (DECL_CONTEXT (olddecl) == 0 + && TREE_CODE (newdecl) != FUNCTION_DECL) + DECL_CONTEXT (newdecl) = 0; + } + + /* Merge the unused-warning information. */ + if (DECL_IN_SYSTEM_HEADER (olddecl)) + DECL_IN_SYSTEM_HEADER (newdecl) = 1; + else if (DECL_IN_SYSTEM_HEADER (newdecl)) + DECL_IN_SYSTEM_HEADER (olddecl) = 1; + + /* Merge the initialization information. */ + if (DECL_INITIAL (newdecl) == 0) + DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); + + /* Merge the section attribute. + We want to issue an error if the sections conflict but that must be + done later in decl_attributes since we are called before attributes + are assigned. */ + if (DECL_SECTION_NAME (newdecl) == NULL_TREE) + DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); + + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); + DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); + } + + pop_obstacks (); + } + /* If cannot merge, then use the new type and qualifiers, + and don't preserve the old rtl. */ + else + { + TREE_TYPE (olddecl) = TREE_TYPE (newdecl); + TREE_READONLY (olddecl) = TREE_READONLY (newdecl); + TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); + TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); + } + + /* Merge the storage class information. */ + DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); + /* For functions, static overrides non-static. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); + /* This is since we don't automatically + copy the attributes of NEWDECL into OLDDECL. */ + TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); + /* If this clears `static', clear it in the identifier too. */ + if (! TREE_PUBLIC (olddecl)) + TREE_PUBLIC (DECL_NAME (olddecl)) = 0; + } + if (DECL_EXTERNAL (newdecl)) + { + TREE_STATIC (newdecl) = TREE_STATIC (olddecl); + DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); + /* An extern decl does not override previous storage class. */ + TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); + } + else + { + TREE_STATIC (olddecl) = TREE_STATIC (newdecl); + TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); + } + + /* If either decl says `inline', this fn is inline, + unless its definition was passed already. */ + if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0) + DECL_INLINE (olddecl) = 1; + DECL_INLINE (newdecl) = DECL_INLINE (olddecl); + + /* Get rid of any built-in function if new arg types don't match it + or if we have a function definition. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_BUILT_IN (olddecl) + && (!types_match || new_is_definition)) + { + TREE_TYPE (olddecl) = TREE_TYPE (newdecl); + DECL_BUILT_IN (olddecl) = 0; + } + + /* If redeclaring a builtin function, and not a definition, + it stays built in. + Also preserve various other info from the definition. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL && !new_is_definition) + { + if (DECL_BUILT_IN (olddecl)) + { + DECL_BUILT_IN (newdecl) = 1; + DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); + } + else + DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); + + DECL_RESULT (newdecl) = DECL_RESULT (olddecl); + DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); + DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl); + DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); + } + + /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. + But preserve OLDdECL's DECL_UID. */ + { + register unsigned olddecl_uid = DECL_UID (olddecl); + + bcopy ((char *) newdecl + sizeof (struct tree_common), + (char *) olddecl + sizeof (struct tree_common), + sizeof (struct tree_decl) - sizeof (struct tree_common)); + DECL_UID (olddecl) = olddecl_uid; + } + + return 1; +} + +/* Record a decl-node X as belonging to the current lexical scope. + Check for errors (such as an incompatible declaration for the same + name already seen in the same scope). + + Returns either X or an old decl for the same name. + If an old decl is returned, it may have been smashed + to agree with what X says. */ + +tree +pushdecl (x) + tree x; +{ + register tree t; + register tree name = DECL_NAME (x); + register struct binding_level *b = current_binding_level; + + DECL_CONTEXT (x) = current_function_decl; + /* A local extern declaration for a function doesn't constitute nesting. + A local auto declaration does, since it's a forward decl + for a nested function coming later. */ + if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0 + && DECL_EXTERNAL (x)) + DECL_CONTEXT (x) = 0; + + if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level + && x != IDENTIFIER_IMPLICIT_DECL (name) + /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */ + && !DECL_IN_SYSTEM_HEADER (x)) + warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name)); + + if (name) + { + char *file; + int line; + int declared_global; + + /* Don't type check externs here when -traditional. This is so that + code with conflicting declarations inside blocks will get warnings + not errors. X11 for instance depends on this. */ + if (DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional) + t = lookup_name_current_level_global (name); + else + t = lookup_name_current_level (name); + if (t != 0 && t == error_mark_node) + /* error_mark_node is 0 for a while during initialization! */ + { + t = 0; + error_with_decl (x, "`%s' used prior to declaration"); + } + + if (t != 0) + { + file = DECL_SOURCE_FILE (t); + line = DECL_SOURCE_LINE (t); + } + + /* duplicate_decls might write to TREE_PUBLIC (x) and DECL_EXTERNAL (x) + to make it identical to the initial declaration. */ + declared_global = TREE_PUBLIC (x) || DECL_EXTERNAL (x); + if (t != 0 && duplicate_decls (x, t)) + { + if (TREE_CODE (t) == PARM_DECL) + { + /* Don't allow more than one "real" duplicate + of a forward parm decl. */ + TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x); + return t; + } + /* If this decl is `static' and an implicit decl was seen previously, + warn. But don't complain if -traditional, + since traditional compilers don't complain. */ + if (!flag_traditional && TREE_PUBLIC (name) + + /* should this be '&& ! declared_global' ? */ + && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x) + + /* We used to warn also for explicit extern followed by static, + but sometimes you need to do it that way. */ + && IDENTIFIER_IMPLICIT_DECL (name) != 0) + { + pedwarn ("`%s' was declared implicitly `extern' and later `static'", + IDENTIFIER_POINTER (name)); + pedwarn_with_file_and_line (file, line, + "previous declaration of `%s'", + IDENTIFIER_POINTER (name)); + } + + /* If this is a global decl, and there exists a conflicting local + decl in a parent block, then we can't return as yet, because we + need to register this decl in the current binding block. */ + /* A test for TREE_PUBLIC (x) will fail for variables that have + been declared static first, and extern now. */ + if (! declared_global || lookup_name (name) == t) + return t; + } + + /* If we are processing a typedef statement, generate a whole new + ..._TYPE node (which will be just an variant of the existing + ..._TYPE node with identical properties) and then install the + TYPE_DECL node generated to represent the typedef name as the + TYPE_NAME of this brand new (duplicate) ..._TYPE node. + + The whole point here is to end up with a situation where each + and every ..._TYPE node the compiler creates will be uniquely + associated with AT MOST one node representing a typedef name. + This way, even though the compiler substitutes corresponding + ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very + early on, later parts of the compiler can always do the reverse + translation and get back the corresponding typedef name. For + example, given: + + typedef struct S MY_TYPE; + MY_TYPE object; + + Later parts of the compiler might only know that `object' was of + type `struct S' if if were not for code just below. With this + code however, later parts of the compiler see something like: + + struct S' == struct S + typedef struct S' MY_TYPE; + struct S' object; + + And they can then deduce (from the node for type struct S') that + the original object declaration was: + + MY_TYPE object; + + Being able to do this is important for proper support of protoize, + and also for generating precise symbolic debugging information + which takes full account of the programmer's (typedef) vocabulary. + + Obviously, we don't want to generate a duplicate ..._TYPE node if + the TYPE_DECL node that we are now processing really represents a + standard built-in type. + + Since all standard types are effectively declared at line zero + in the source file, we can easily check to see if we are working + on a standard type by checking the current value of lineno. */ + + if (TREE_CODE (x) == TYPE_DECL) + { + if (DECL_SOURCE_LINE (x) == 0) + { + if (TYPE_NAME (TREE_TYPE (x)) == 0) + TYPE_NAME (TREE_TYPE (x)) = x; + } + else if (TREE_TYPE (x) != error_mark_node) + { + tree tt = TREE_TYPE (x); + + tt = build_type_copy (tt); + TYPE_NAME (tt) = x; + TREE_TYPE (x) = tt; + } + } + + /* Multiple external decls of the same identifier ought to match. + Check against both global declarations (when traditional) and out of + scope (limbo) block level declarations. + + We get warnings about inline functions where they are defined. + Avoid duplicate warnings where they are used. */ + if (TREE_PUBLIC (x) && ! DECL_INLINE (x)) + { + tree decl; + + if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0 + && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) + || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) + decl = IDENTIFIER_GLOBAL_VALUE (name); + else if (IDENTIFIER_LIMBO_VALUE (name) != 0) + /* Decls in limbo are always extern, so no need to check that. */ + decl = IDENTIFIER_LIMBO_VALUE (name); + else + decl = 0; + + if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl)) + /* If old decl is built-in, we already warned if we should. */ + && !DECL_BUILT_IN (decl)) + { + pedwarn_with_decl (x, + "type mismatch with previous external decl"); + pedwarn_with_decl (decl, "previous external decl of `%s'"); + } + } + + /* If a function has had an implicit declaration, and then is defined, + make sure they are compatible. */ + + if (IDENTIFIER_IMPLICIT_DECL (name) != 0 + && IDENTIFIER_GLOBAL_VALUE (name) == 0 + && TREE_CODE (x) == FUNCTION_DECL + && ! comptypes (TREE_TYPE (x), + TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name)))) + { + warning_with_decl (x, "type mismatch with previous implicit declaration"); + warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name), + "previous implicit declaration of `%s'"); + } + + /* In PCC-compatibility mode, extern decls of vars with no current decl + take effect at top level no matter where they are. */ + if (flag_traditional && DECL_EXTERNAL (x) + && lookup_name (name) == 0) + { + tree type = TREE_TYPE (x); + + /* But don't do this if the type contains temporary nodes. */ + while (type) + { + if (type == error_mark_node) + break; + if (! TREE_PERMANENT (type)) + { + warning_with_decl (x, "type of external `%s' is not global"); + /* By exiting the loop early, we leave TYPE nonzero, + and thus prevent globalization of the decl. */ + break; + } + else if (TREE_CODE (type) == FUNCTION_TYPE + && TYPE_ARG_TYPES (type) != 0) + /* The types might not be truly local, + but the list of arg types certainly is temporary. + Since prototypes are nontraditional, + ok not to do the traditional thing. */ + break; + type = TREE_TYPE (type); + } + + if (type == 0) + b = global_binding_level; + } + + /* This name is new in its binding level. + Install the new declaration and return it. */ + if (b == global_binding_level) + { + /* Install a global value. */ + + /* If the first global decl has external linkage, + warn if we later see static one. */ + if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x)) + TREE_PUBLIC (name) = 1; + + IDENTIFIER_GLOBAL_VALUE (name) = x; + + /* We no longer care about any previous block level declarations. */ + IDENTIFIER_LIMBO_VALUE (name) = 0; + + /* Don't forget if the function was used via an implicit decl. */ + if (IDENTIFIER_IMPLICIT_DECL (name) + && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) + TREE_USED (x) = 1, TREE_USED (name) = 1; + + /* Don't forget if its address was taken in that way. */ + if (IDENTIFIER_IMPLICIT_DECL (name) + && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) + TREE_ADDRESSABLE (x) = 1; + + /* Warn about mismatches against previous implicit decl. */ + if (IDENTIFIER_IMPLICIT_DECL (name) != 0 + /* If this real decl matches the implicit, don't complain. */ + && ! (TREE_CODE (x) == FUNCTION_DECL + && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x))) + == integer_type_node))) + pedwarn ("`%s' was previously implicitly declared to return `int'", + IDENTIFIER_POINTER (name)); + + /* If this decl is `static' and an `extern' was seen previously, + that is erroneous. */ + if (TREE_PUBLIC (name) + && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) + { + /* Okay to redeclare an ANSI built-in as static. */ + if (t != 0 && DECL_BUILT_IN (t)) + ; + /* Okay to declare a non-ANSI built-in as anything. */ + else if (t != 0 && DECL_BUILT_IN_NONANSI (t)) + ; + else if (IDENTIFIER_IMPLICIT_DECL (name)) + pedwarn ("`%s' was declared implicitly `extern' and later `static'", + IDENTIFIER_POINTER (name)); + else + pedwarn ("`%s' was declared `extern' and later `static'", + IDENTIFIER_POINTER (name)); + } + } + else + { + /* Here to install a non-global value. */ + tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); + tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); + IDENTIFIER_LOCAL_VALUE (name) = x; + + /* If this is an extern function declaration, see if we + have a global definition or declaration for the function. */ + if (oldlocal == 0 + && DECL_EXTERNAL (x) && !DECL_INLINE (x) + && oldglobal != 0 + && TREE_CODE (x) == FUNCTION_DECL + && TREE_CODE (oldglobal) == FUNCTION_DECL) + { + /* We have one. Their types must agree. */ + if (! comptypes (TREE_TYPE (x), + TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)))) + pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one"); + else + { + /* Inner extern decl is inline if global one is. + Copy enough to really inline it. */ + if (DECL_INLINE (oldglobal)) + { + DECL_INLINE (x) = DECL_INLINE (oldglobal); + DECL_INITIAL (x) = (current_function_decl == oldglobal + ? 0 : DECL_INITIAL (oldglobal)); + DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); + DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal); + DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); + DECL_RESULT (x) = DECL_RESULT (oldglobal); + TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); + DECL_ABSTRACT_ORIGIN (x) = oldglobal; + } + /* Inner extern decl is built-in if global one is. */ + if (DECL_BUILT_IN (oldglobal)) + { + DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal); + DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal); + } + /* Keep the arg types from a file-scope fcn defn. */ + if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0 + && DECL_INITIAL (oldglobal) + && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0) + TREE_TYPE (x) = TREE_TYPE (oldglobal); + } + } + +#if 0 /* This case is probably sometimes the right thing to do. */ + /* If we have a local external declaration, + then any file-scope declaration should not + have been static. */ + if (oldlocal == 0 && oldglobal != 0 + && !TREE_PUBLIC (oldglobal) + && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) + warning ("`%s' locally external but globally static", + IDENTIFIER_POINTER (name)); +#endif + + /* If we have a local external declaration, + and no file-scope declaration has yet been seen, + then if we later have a file-scope decl it must not be static. */ + if (oldlocal == 0 + && oldglobal == 0 + && DECL_EXTERNAL (x) + && TREE_PUBLIC (x)) + { + TREE_PUBLIC (name) = 1; + + /* Save this decl, so that we can do type checking against + other decls after it falls out of scope. + + Only save it once. This prevents temporary decls created in + expand_inline_function from being used here, since this + will have been set when the inline function was parsed. + It also helps give slightly better warnings. */ + if (IDENTIFIER_LIMBO_VALUE (name) == 0) + IDENTIFIER_LIMBO_VALUE (name) = x; + } + + /* Warn if shadowing an argument at the top level of the body. */ + if (oldlocal != 0 && !DECL_EXTERNAL (x) + /* This warning doesn't apply to the parms of a nested fcn. */ + && ! current_binding_level->parm_flag + /* Check that this is one level down from the parms. */ + && current_binding_level->level_chain->parm_flag + /* Check that the decl being shadowed + comes from the parm level, one level up. */ + && chain_member (oldlocal, current_binding_level->level_chain->names)) + { + if (TREE_CODE (oldlocal) == PARM_DECL) + pedwarn ("declaration of `%s' shadows a parameter", + IDENTIFIER_POINTER (name)); + else + pedwarn ("declaration of `%s' shadows a symbol from the parameter list", + IDENTIFIER_POINTER (name)); + } + + /* Maybe warn if shadowing something else. */ + else if (warn_shadow && !DECL_EXTERNAL (x) + /* No shadow warnings for internally generated vars. */ + && DECL_SOURCE_LINE (x) != 0 + /* No shadow warnings for vars made for inlining. */ + && ! DECL_FROM_INLINE (x)) + { + char *warnstring = 0; + + if (TREE_CODE (x) == PARM_DECL + && current_binding_level->level_chain->parm_flag) + /* Don't warn about the parm names in function declarator + within a function declarator. + It would be nice to avoid warning in any function + declarator in a declaration, as opposed to a definition, + but there is no way to tell it's not a definition. */ + ; + else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL) + warnstring = "declaration of `%s' shadows a parameter"; + else if (oldlocal != 0) + warnstring = "declaration of `%s' shadows previous local"; + else if (IDENTIFIER_GLOBAL_VALUE (name) != 0 + && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node) + warnstring = "declaration of `%s' shadows global declaration"; + + if (warnstring) + warning (warnstring, IDENTIFIER_POINTER (name)); + } + + /* If storing a local value, there may already be one (inherited). + If so, record it for restoration when this binding level ends. */ + if (oldlocal != 0) + b->shadowed = tree_cons (name, oldlocal, b->shadowed); + } + + /* Keep count of variables in this level with incomplete type. */ + if (TYPE_SIZE (TREE_TYPE (x)) == 0) + ++b->n_incomplete; + } + + /* Put decls on list in reverse order. + We will reverse them later if necessary. */ + TREE_CHAIN (x) = b->names; + b->names = x; + + return x; +} + +/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ + +tree +pushdecl_top_level (x) + tree x; +{ + register tree t; + register struct binding_level *b = current_binding_level; + + current_binding_level = global_binding_level; + t = pushdecl (x); + current_binding_level = b; + return t; +} + +/* Generate an implicit declaration for identifier FUNCTIONID + as a function of type int (). Print a warning if appropriate. */ + +tree +implicitly_declare (functionid) + tree functionid; +{ + register tree decl; + int traditional_warning = 0; + /* Only one "implicit declaration" warning per identifier. */ + int implicit_warning; + + /* Save the decl permanently so we can warn if definition follows. */ + push_obstacks_nochange (); + end_temporary_allocation (); + + /* We used to reuse an old implicit decl here, + but this loses with inline functions because it can clobber + the saved decl chains. */ +/* if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0) + decl = IDENTIFIER_IMPLICIT_DECL (functionid); + else */ + decl = build_decl (FUNCTION_DECL, functionid, default_function_type); + + /* Warn of implicit decl following explicit local extern decl. + This is probably a program designed for traditional C. */ + if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0) + traditional_warning = 1; + + /* Warn once of an implicit declaration. */ + implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0); + + DECL_EXTERNAL (decl) = 1; + TREE_PUBLIC (decl) = 1; + + /* Record that we have an implicit decl and this is it. */ + IDENTIFIER_IMPLICIT_DECL (functionid) = decl; + + /* ANSI standard says implicit declarations are in the innermost block. + So we record the decl in the standard fashion. + If flag_traditional is set, pushdecl does it top-level. */ + pushdecl (decl); + + /* This is a no-op in c-lang.c or something real in objc-actions.c. */ + maybe_objc_check_decl (decl); + + rest_of_decl_compilation (decl, NULL_PTR, 0, 0); + + if (warn_implicit && implicit_warning) + warning ("implicit declaration of function `%s'", + IDENTIFIER_POINTER (functionid)); + else if (warn_traditional && traditional_warning) + warning ("function `%s' was previously declared within a block", + IDENTIFIER_POINTER (functionid)); + + /* Write a record describing this implicit function declaration to the + prototypes file (if requested). */ + + gen_aux_info_record (decl, 0, 1, 0); + + pop_obstacks (); + + return decl; +} + +/* Return zero if the declaration NEWDECL is valid + when the declaration OLDDECL (assumed to be for the same name) + has already been seen. + Otherwise return an error message format string with a %s + where the identifier should go. */ + +static char * +redeclaration_error_message (newdecl, olddecl) + tree newdecl, olddecl; +{ + if (TREE_CODE (newdecl) == TYPE_DECL) + { + if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl)) + return 0; + /* pushdecl creates distinct types for TYPE_DECLs by calling + build_type_copy, so the above comparison generally fails. We do + another test against the TYPE_MAIN_VARIANT of the olddecl, which + is equivalent to what this code used to do before the build_type_copy + call. The variant type distinction should not matter for traditional + code, because it doesn't have type qualifiers. */ + if (flag_traditional + && TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)) == TREE_TYPE (newdecl)) + return 0; + if (DECL_IN_SYSTEM_HEADER (olddecl) || DECL_IN_SYSTEM_HEADER (newdecl)) + return 0; + return "redefinition of `%s'"; + } + else if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + /* Declarations of functions can insist on internal linkage + but they can't be inconsistent with internal linkage, + so there can be no error on that account. + However defining the same name twice is no good. */ + if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0 + /* However, defining once as extern inline and a second + time in another way is ok. */ + && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl) + && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl)))) + return "redefinition of `%s'"; + return 0; + } + else if (current_binding_level == global_binding_level) + { + /* Objects declared at top level: */ + /* If at least one is a reference, it's ok. */ + if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) + return 0; + /* Reject two definitions. */ + if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0) + return "redefinition of `%s'"; + /* Now we have two tentative defs, or one tentative and one real def. */ + /* Insist that the linkage match. */ + if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) + return "conflicting declarations of `%s'"; + return 0; + } + else if (current_binding_level->parm_flag + && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) + return 0; + else + { + /* Newdecl has block scope. If olddecl has block scope also, then + reject two definitions, and reject a definition together with an + external reference. Otherwise, it is OK, because newdecl must + be an extern reference to olddecl. */ + if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)) + && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)) + return "redeclaration of `%s'"; + return 0; + } +} + +/* Get the LABEL_DECL corresponding to identifier ID as a label. + Create one if none exists so far for the current function. + This function is called for both label definitions and label references. */ + +tree +lookup_label (id) + tree id; +{ + register tree decl = IDENTIFIER_LABEL_VALUE (id); + + if (current_function_decl == 0) + { + error ("label %s referenced outside of any function", + IDENTIFIER_POINTER (id)); + return 0; + } + + /* Use a label already defined or ref'd with this name. */ + if (decl != 0) + { + /* But not if it is inherited and wasn't declared to be inheritable. */ + if (DECL_CONTEXT (decl) != current_function_decl + && ! C_DECLARED_LABEL_FLAG (decl)) + return shadow_label (id); + return decl; + } + + decl = build_decl (LABEL_DECL, id, void_type_node); + + /* Make sure every label has an rtx. */ + label_rtx (decl); + + /* A label not explicitly declared must be local to where it's ref'd. */ + DECL_CONTEXT (decl) = current_function_decl; + + DECL_MODE (decl) = VOIDmode; + + /* Say where one reference is to the label, + for the sake of the error if it is not defined. */ + DECL_SOURCE_LINE (decl) = lineno; + DECL_SOURCE_FILE (decl) = input_filename; + + IDENTIFIER_LABEL_VALUE (id) = decl; + + named_labels = tree_cons (NULL_TREE, decl, named_labels); + + return decl; +} + +/* Make a label named NAME in the current function, + shadowing silently any that may be inherited from containing functions + or containing scopes. + + Note that valid use, if the label being shadowed + comes from another scope in the same function, + requires calling declare_nonlocal_label right away. */ + +tree +shadow_label (name) + tree name; +{ + register tree decl = IDENTIFIER_LABEL_VALUE (name); + + if (decl != 0) + { + register tree dup; + + /* Check to make sure that the label hasn't already been declared + at this label scope */ + for (dup = named_labels; dup; dup = TREE_CHAIN (dup)) + if (TREE_VALUE (dup) == decl) + { + error ("duplicate label declaration `%s'", + IDENTIFIER_POINTER (name)); + error_with_decl (TREE_VALUE (dup), + "this is a previous declaration"); + /* Just use the previous declaration. */ + return lookup_label (name); + } + + shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); + IDENTIFIER_LABEL_VALUE (name) = decl = 0; + } + + return lookup_label (name); +} + +/* Define a label, specifying the location in the source file. + Return the LABEL_DECL node for the label, if the definition is valid. + Otherwise return 0. */ + +tree +define_label (filename, line, name) + char *filename; + int line; + tree name; +{ + tree decl = lookup_label (name); + + /* If label with this name is known from an outer context, shadow it. */ + if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl) + { + shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); + IDENTIFIER_LABEL_VALUE (name) = 0; + decl = lookup_label (name); + } + + if (DECL_INITIAL (decl) != 0) + { + error ("duplicate label `%s'", IDENTIFIER_POINTER (name)); + return 0; + } + else + { + /* Mark label as having been defined. */ + DECL_INITIAL (decl) = error_mark_node; + /* Say where in the source. */ + DECL_SOURCE_FILE (decl) = filename; + DECL_SOURCE_LINE (decl) = line; + return decl; + } +} + +/* Return the list of declarations of the current level. + Note that this list is in reverse order unless/until + you nreverse it; and when you do nreverse it, you must + store the result back using `storedecls' or you will lose. */ + +tree +getdecls () +{ + return current_binding_level->names; +} + +/* Return the list of type-tags (for structs, etc) of the current level. */ + +tree +gettags () +{ + return current_binding_level->tags; +} + +/* Store the list of declarations of the current level. + This is done for the parameter declarations of a function being defined, + after they are modified in the light of any missing parameters. */ + +static void +storedecls (decls) + tree decls; +{ + current_binding_level->names = decls; +} + +/* Similarly, store the list of tags of the current level. */ + +static void +storetags (tags) + tree tags; +{ + current_binding_level->tags = tags; +} + +/* Given NAME, an IDENTIFIER_NODE, + return the structure (or union or enum) definition for that name. + Searches binding levels from BINDING_LEVEL up to the global level. + If THISLEVEL_ONLY is nonzero, searches only the specified context + (but skips any tag-transparent contexts to find one that is + meaningful for tags). + CODE says which kind of type the caller wants; + it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. + If the wrong kind of type is found, an error is reported. */ + +static tree +lookup_tag (code, name, binding_level, thislevel_only) + enum tree_code code; + struct binding_level *binding_level; + tree name; + int thislevel_only; +{ + register struct binding_level *level; + + for (level = binding_level; level; level = level->level_chain) + { + register tree tail; + for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) + { + if (TREE_PURPOSE (tail) == name) + { + if (TREE_CODE (TREE_VALUE (tail)) != code) + { + /* Definition isn't the kind we were looking for. */ + pending_invalid_xref = name; + pending_invalid_xref_file = input_filename; + pending_invalid_xref_line = lineno; + } + return TREE_VALUE (tail); + } + } + if (thislevel_only && ! level->tag_transparent) + return NULL_TREE; + } + return NULL_TREE; +} + +/* Print an error message now + for a recent invalid struct, union or enum cross reference. + We don't print them immediately because they are not invalid + when used in the `struct foo;' construct for shadowing. */ + +void +pending_xref_error () +{ + if (pending_invalid_xref != 0) + error_with_file_and_line (pending_invalid_xref_file, + pending_invalid_xref_line, + "`%s' defined as wrong kind of tag", + IDENTIFIER_POINTER (pending_invalid_xref)); + pending_invalid_xref = 0; +} + +/* Given a type, find the tag that was defined for it and return the tag name. + Otherwise return 0. */ + +static tree +lookup_tag_reverse (type) + tree type; +{ + register struct binding_level *level; + + for (level = current_binding_level; level; level = level->level_chain) + { + register tree tail; + for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) + { + if (TREE_VALUE (tail) == type) + return TREE_PURPOSE (tail); + } + } + return NULL_TREE; +} + +/* Look up NAME in the current binding level and its superiors + in the namespace of variables, functions and typedefs. + Return a ..._DECL node of some kind representing its definition, + or return 0 if it is undefined. */ + +tree +lookup_name (name) + tree name; +{ + register tree val; + if (current_binding_level != global_binding_level + && IDENTIFIER_LOCAL_VALUE (name)) + val = IDENTIFIER_LOCAL_VALUE (name); + else + val = IDENTIFIER_GLOBAL_VALUE (name); + return val; +} + +/* Similar to `lookup_name' but look only at current binding level. */ + +tree +lookup_name_current_level (name) + tree name; +{ + register tree t; + + if (current_binding_level == global_binding_level) + return IDENTIFIER_GLOBAL_VALUE (name); + + if (IDENTIFIER_LOCAL_VALUE (name) == 0) + return 0; + + for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) + if (DECL_NAME (t) == name) + break; + + return t; +} + +/* Similar to `lookup_name_current_level' but also look at the global binding + level. */ + +tree +lookup_name_current_level_global (name) + tree name; +{ + register tree t = 0; + + if (current_binding_level == global_binding_level) + return IDENTIFIER_GLOBAL_VALUE (name); + + if (IDENTIFIER_LOCAL_VALUE (name) != 0) + for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) + if (DECL_NAME (t) == name) + break; + + if (t == 0) + t = IDENTIFIER_GLOBAL_VALUE (name); + + return t; +} + +/* Create the predefined scalar types of C, + and some nodes representing standard constants (0, 1, (void *)0). + Initialize the global binding level. + Make definitions for built-in primitive functions. */ + +void +init_decl_processing () +{ + register tree endlink; + /* Either char* or void*. */ + tree traditional_ptr_type_node; + /* Data types of memcpy and strlen. */ + tree memcpy_ftype, strlen_ftype; + tree void_ftype_any; + int wchar_type_size; + tree temp; + tree array_domain_type; + + current_function_decl = NULL; + named_labels = NULL; + current_binding_level = NULL_BINDING_LEVEL; + free_binding_level = NULL_BINDING_LEVEL; + pushlevel (0); /* make the binding_level structure for global names */ + global_binding_level = current_binding_level; + + /* Define `int' and `char' first so that dbx will output them first. */ + + integer_type_node = make_signed_type (INT_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT], + integer_type_node)); + + /* Define `char', which is like either `signed char' or `unsigned char' + but not the same as either. */ + + char_type_node + = (flag_signed_char + ? make_signed_type (CHAR_TYPE_SIZE) + : make_unsigned_type (CHAR_TYPE_SIZE)); + pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), + char_type_node)); + + long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"), + long_integer_type_node)); + + unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"), + unsigned_type_node)); + + long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"), + long_unsigned_type_node)); + + long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"), + long_long_integer_type_node)); + + long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"), + long_long_unsigned_type_node)); + + /* `unsigned long' is the standard type for sizeof. + Traditionally, use a signed type. + Note that stddef.h uses `unsigned long', + and this must agree, even of long and int are the same size. */ + sizetype + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); + if (flag_traditional && TREE_UNSIGNED (sizetype)) + sizetype = signed_type (sizetype); + + ptrdiff_type_node + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); + + TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; + + error_mark_node = make_node (ERROR_MARK); + TREE_TYPE (error_mark_node) = error_mark_node; + + short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"), + short_integer_type_node)); + + short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"), + short_unsigned_type_node)); + + /* Define both `signed char' and `unsigned char'. */ + signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"), + signed_char_type_node)); + + unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"), + unsigned_char_type_node)); + + intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); + + intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); + + intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); + + intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); + + unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); + + unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); + + unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); + + unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); + + float_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; + pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT], + float_type_node)); + layout_type (float_type_node); + + double_type_node = make_node (REAL_TYPE); + if (flag_short_double) + TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; + else + TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; + pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE], + double_type_node)); + layout_type (double_type_node); + + long_double_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; + pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"), + long_double_type_node)); + layout_type (long_double_type_node); + + complex_integer_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), + complex_integer_type_node)); + TREE_TYPE (complex_integer_type_node) = integer_type_node; + layout_type (complex_integer_type_node); + + complex_float_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), + complex_float_type_node)); + TREE_TYPE (complex_float_type_node) = float_type_node; + layout_type (complex_float_type_node); + + complex_double_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), + complex_double_type_node)); + TREE_TYPE (complex_double_type_node) = double_type_node; + layout_type (complex_double_type_node); + + complex_long_double_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), + complex_long_double_type_node)); + TREE_TYPE (complex_long_double_type_node) = long_double_type_node; + layout_type (complex_long_double_type_node); + + wchar_type_node + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); + wchar_type_size = TYPE_PRECISION (wchar_type_node); + signed_wchar_type_node = signed_type (wchar_type_node); + unsigned_wchar_type_node = unsigned_type (wchar_type_node); + + integer_zero_node = build_int_2 (0, 0); + TREE_TYPE (integer_zero_node) = integer_type_node; + integer_one_node = build_int_2 (1, 0); + TREE_TYPE (integer_one_node) = integer_type_node; + + boolean_type_node = integer_type_node; + boolean_true_node = integer_one_node; + boolean_false_node = integer_zero_node; + + size_zero_node = build_int_2 (0, 0); + TREE_TYPE (size_zero_node) = sizetype; + size_one_node = build_int_2 (1, 0); + TREE_TYPE (size_one_node) = sizetype; + + void_type_node = make_node (VOID_TYPE); + pushdecl (build_decl (TYPE_DECL, + ridpointers[(int) RID_VOID], void_type_node)); + layout_type (void_type_node); /* Uses integer_zero_node */ + /* We are not going to have real types in C with less than byte alignment, + so we might as well not have any types that claim to have it. */ + TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; + + null_pointer_node = build_int_2 (0, 0); + TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); + layout_type (TREE_TYPE (null_pointer_node)); + + string_type_node = build_pointer_type (char_type_node); + const_string_type_node + = build_pointer_type (build_type_variant (char_type_node, 1, 0)); + + /* Make a type to be the domain of a few array types + whose domains don't really matter. + 200 is small enough that it always fits in size_t + and large enough that it can hold most function names for the + initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ + array_domain_type = build_index_type (build_int_2 (200, 0)); + + /* make a type for arrays of characters. + With luck nothing will ever really depend on the length of this + array type. */ + char_array_type_node + = build_array_type (char_type_node, array_domain_type); + /* Likewise for arrays of ints. */ + int_array_type_node + = build_array_type (integer_type_node, array_domain_type); + /* This is for wide string constants. */ + wchar_array_type_node + = build_array_type (wchar_type_node, array_domain_type); + + default_function_type + = build_function_type (integer_type_node, NULL_TREE); + + ptr_type_node = build_pointer_type (void_type_node); + const_ptr_type_node + = build_pointer_type (build_type_variant (void_type_node, 1, 0)); + + endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE); + + void_ftype_any + = build_function_type (void_type_node, NULL_TREE); + + float_ftype_float + = build_function_type (float_type_node, + tree_cons (NULL_TREE, float_type_node, endlink)); + + double_ftype_double + = build_function_type (double_type_node, + tree_cons (NULL_TREE, double_type_node, endlink)); + + ldouble_ftype_ldouble + = build_function_type (long_double_type_node, + tree_cons (NULL_TREE, long_double_type_node, + endlink)); + + double_ftype_double_double + = build_function_type (double_type_node, + tree_cons (NULL_TREE, double_type_node, + tree_cons (NULL_TREE, + double_type_node, endlink))); + + int_ftype_int + = build_function_type (integer_type_node, + tree_cons (NULL_TREE, integer_type_node, endlink)); + + long_ftype_long + = build_function_type (long_integer_type_node, + tree_cons (NULL_TREE, + long_integer_type_node, endlink)); + + void_ftype_ptr_ptr_int + = build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)))); + + int_ftype_cptr_cptr_sizet + = build_function_type (integer_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)))); + + void_ftype_ptr_int_int + = build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, integer_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)))); + + string_ftype_ptr_ptr /* strcpy prototype */ + = build_function_type (string_type_node, + tree_cons (NULL_TREE, string_type_node, + tree_cons (NULL_TREE, + const_string_type_node, + endlink))); + + int_ftype_string_string /* strcmp prototype */ + = build_function_type (integer_type_node, + tree_cons (NULL_TREE, const_string_type_node, + tree_cons (NULL_TREE, + const_string_type_node, + endlink))); + + strlen_ftype /* strlen prototype */ + = build_function_type (flag_traditional ? integer_type_node : sizetype, + tree_cons (NULL_TREE, const_string_type_node, + endlink)); + + traditional_ptr_type_node + = (flag_traditional ? string_type_node : ptr_type_node); + + memcpy_ftype /* memcpy prototype */ + = build_function_type (traditional_ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)))); + + builtin_function ("__builtin_constant_p", default_function_type, + BUILT_IN_CONSTANT_P, NULL_PTR); + + builtin_function ("__builtin_return_address", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + unsigned_type_node, + endlink)), + BUILT_IN_RETURN_ADDRESS, NULL_PTR); + + builtin_function ("__builtin_frame_address", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + unsigned_type_node, + endlink)), + BUILT_IN_FRAME_ADDRESS, NULL_PTR); + + builtin_function ("__builtin_alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, "alloca"); + builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); + /* Define alloca, ffs as builtins. + Declare _exit just to mark it as volatile. */ + if (! flag_no_builtin && !flag_no_nonansi_builtin) + { + temp = builtin_function ("alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, NULL_PTR); + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + temp = builtin_function ("_exit", void_ftype_any, NOT_BUILT_IN, + NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + } + + builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); + builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, + NULL_PTR); + builtin_function ("__builtin_saveregs", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_SAVEREGS, NULL_PTR); +/* EXPAND_BUILTIN_VARARGS is obsolete. */ +#if 0 + builtin_function ("__builtin_varargs", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)), + BUILT_IN_VARARGS, NULL_PTR); +#endif + builtin_function ("__builtin_classify_type", default_function_type, + BUILT_IN_CLASSIFY_TYPE, NULL_PTR); + builtin_function ("__builtin_next_arg", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_NEXT_ARG, NULL_PTR); + builtin_function ("__builtin_args_info", + build_function_type (integer_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)), + BUILT_IN_ARGS_INFO, NULL_PTR); + + /* Untyped call and return. */ + builtin_function ("__builtin_apply_args", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_APPLY_ARGS, NULL_PTR); + + temp = tree_cons (NULL_TREE, + build_pointer_type (build_function_type (void_type_node, + NULL_TREE)), + tree_cons (NULL_TREE, + ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink))); + builtin_function ("__builtin_apply", + build_function_type (ptr_type_node, temp), + BUILT_IN_APPLY, NULL_PTR); + builtin_function ("__builtin_return", + build_function_type (void_type_node, + tree_cons (NULL_TREE, + ptr_type_node, + endlink)), + BUILT_IN_RETURN, NULL_PTR); + + /* Currently under experimentation. */ + builtin_function ("__builtin_memcpy", memcpy_ftype, + BUILT_IN_MEMCPY, "memcpy"); + builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, + BUILT_IN_MEMCMP, "memcmp"); + builtin_function ("__builtin_strcmp", int_ftype_string_string, + BUILT_IN_STRCMP, "strcmp"); + builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, + BUILT_IN_STRCPY, "strcpy"); + builtin_function ("__builtin_strlen", strlen_ftype, + BUILT_IN_STRLEN, "strlen"); + builtin_function ("__builtin_sqrtf", float_ftype_float, + BUILT_IN_FSQRT, "sqrtf"); + builtin_function ("__builtin_fsqrt", double_ftype_double, + BUILT_IN_FSQRT, "sqrt"); + builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, + BUILT_IN_FSQRT, "sqrtl"); + builtin_function ("__builtin_sinf", float_ftype_float, + BUILT_IN_SIN, "sinf"); + builtin_function ("__builtin_sin", double_ftype_double, + BUILT_IN_SIN, "sin"); + builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, + BUILT_IN_SIN, "sinl"); + builtin_function ("__builtin_cosf", float_ftype_float, + BUILT_IN_COS, "cosf"); + builtin_function ("__builtin_cos", double_ftype_double, + BUILT_IN_COS, "cos"); + builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, + BUILT_IN_COS, "cosl"); + + /* In an ANSI C program, it is okay to supply built-in meanings + for these functions, since applications cannot validly use them + with any other meaning. + However, honor the -fno-builtin option. */ + if (!flag_no_builtin) + { + builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); + builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); + builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); + builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); + builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); + builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, + NULL_PTR); + builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, + NULL_PTR); + builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, + NULL_PTR); + builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); + builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, + NULL_PTR); + builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); + builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); + builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); + builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); + builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); + builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); + + /* Declare these functions volatile + to avoid spurious "control drops through" warnings. */ + /* Don't specify the argument types, to avoid errors + from certain code which isn't valid in ANSI but which exists. */ + temp = builtin_function ("abort", void_ftype_any, NOT_BUILT_IN, + NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + temp = builtin_function ("exit", void_ftype_any, NOT_BUILT_IN, NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + } + +#if 0 + /* Support for these has not been written in either expand_builtin + or build_function_call. */ + builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); + builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); + builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, + NULL_PTR); + builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, + NULL_PTR); + builtin_function ("__builtin_fmod", double_ftype_double_double, + BUILT_IN_FMOD, NULL_PTR); + builtin_function ("__builtin_frem", double_ftype_double_double, + BUILT_IN_FREM, NULL_PTR); + builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, + BUILT_IN_MEMSET, NULL_PTR); + builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, + NULL_PTR); + builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, + NULL_PTR); +#endif + + pedantic_lvalues = pedantic; + + /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ + declare_function_name (); + + start_identifier_warnings (); + + /* Prepare to check format strings against argument lists. */ + init_function_format_info (); + + init_iterators (); + + incomplete_decl_finalize_hook = finish_incomplete_decl; +} + +/* Return a definition for a builtin function named NAME and whose data type + is TYPE. TYPE should be a function type with argument types. + FUNCTION_CODE tells later passes how to compile calls to this function. + See tree.h for its possible values. + + If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, + the name to be called if we can't opencode the function. */ + +tree +builtin_function (name, type, function_code, library_name) + char *name; + tree type; + enum built_in_function function_code; + char *library_name; +{ + tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type); + DECL_EXTERNAL (decl) = 1; + TREE_PUBLIC (decl) = 1; + /* If -traditional, permit redefining a builtin function any way you like. + (Though really, if the program redefines these functions, + it probably won't work right unless compiled with -fno-builtin.) */ + if (flag_traditional && name[0] != '_') + DECL_BUILT_IN_NONANSI (decl) = 1; + if (library_name) + DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); + make_decl_rtl (decl, NULL_PTR, 1); + pushdecl (decl); + if (function_code != NOT_BUILT_IN) + { + DECL_BUILT_IN (decl) = 1; + DECL_FUNCTION_CODE (decl) = function_code; + } + /* Warn if a function in the namespace for users + is used without an occasion to consider it declared. */ + if (name[0] != '_' || name[1] != '_') + C_DECL_ANTICIPATED (decl) = 1; + + return decl; +} + +/* Called when a declaration is seen that contains no names to declare. + If its type is a reference to a structure, union or enum inherited + from a containing scope, shadow that tag name for the current scope + with a forward reference. + If its type defines a new named structure or union + or defines an enum, it is valid but we need not do anything here. + Otherwise, it is an error. */ + +void +shadow_tag (declspecs) + tree declspecs; +{ + shadow_tag_warned (declspecs, 0); +} + +void +shadow_tag_warned (declspecs, warned) + tree declspecs; + int warned; + /* 1 => we have done a pedwarn. 2 => we have done a warning, but + no pedwarn. */ +{ + int found_tag = 0; + register tree link; + + pending_invalid_xref = 0; + + for (link = declspecs; link; link = TREE_CHAIN (link)) + { + register tree value = TREE_VALUE (link); + register enum tree_code code = TREE_CODE (value); + + if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) + /* Used to test also that TYPE_SIZE (value) != 0. + That caused warning for `struct foo;' at top level in the file. */ + { + register tree name = lookup_tag_reverse (value); + register tree t; + + found_tag++; + + if (name == 0) + { + if (warned != 1 && code != ENUMERAL_TYPE) + /* Empty unnamed enum OK */ + { + pedwarn ("unnamed struct/union that defines no instances"); + warned = 1; + } + } + else + { + t = lookup_tag (code, name, current_binding_level, 1); + + if (t == 0) + { + t = make_node (code); + pushtag (name, t); + } + } + } + else + { + if (!warned && ! in_system_header) + { + warning ("useless keyword or type name in empty declaration"); + warned = 2; + } + } + } + + if (found_tag > 1) + error ("two types specified in one empty declaration"); + + if (warned != 1) + { + if (found_tag == 0) + pedwarn ("empty declaration"); + } +} + +/* Decode a "typename", such as "int **", returning a ..._TYPE node. */ + +tree +groktypename (typename) + tree typename; +{ + if (TREE_CODE (typename) != TREE_LIST) + return typename; + return grokdeclarator (TREE_VALUE (typename), + TREE_PURPOSE (typename), + TYPENAME, 0); +} + +/* Return a PARM_DECL node for a given pair of specs and declarator. */ + +tree +groktypename_in_parm_context (typename) + tree typename; +{ + if (TREE_CODE (typename) != TREE_LIST) + return typename; + return grokdeclarator (TREE_VALUE (typename), + TREE_PURPOSE (typename), + PARM, 0); +} + +/* Decode a declarator in an ordinary declaration or data definition. + This is called as soon as the type information and variable name + have been parsed, before parsing the initializer if any. + Here we create the ..._DECL node, fill in its type, + and put it on the list of decls for the current context. + The ..._DECL node is returned as the value. + + Exception: for arrays where the length is not specified, + the type is left null, to be filled in by `finish_decl'. + + Function definitions do not come here; they go to start_function + instead. However, external and forward declarations of functions + do go through here. Structure field declarations are done by + grokfield and not through here. */ + +/* Set this to zero to debug not using the temporary obstack + to parse initializers. */ +int debug_temp_inits = 1; + +tree +start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) + tree declarator, declspecs; + int initialized; + tree attributes, prefix_attributes; +{ + register tree decl = grokdeclarator (declarator, declspecs, + NORMAL, initialized); + register tree tem; + int init_written = initialized; + + /* The corresponding pop_obstacks is in finish_decl. */ + push_obstacks_nochange (); + + if (initialized) + /* Is it valid for this decl to have an initializer at all? + If not, set INITIALIZED to zero, which will indirectly + tell `finish_decl' to ignore the initializer once it is parsed. */ + switch (TREE_CODE (decl)) + { + case TYPE_DECL: + /* typedef foo = bar means give foo the same type as bar. + We haven't parsed bar yet, so `finish_decl' will fix that up. + Any other case of an initialization in a TYPE_DECL is an error. */ + if (pedantic || list_length (declspecs) > 1) + { + error ("typedef `%s' is initialized", + IDENTIFIER_POINTER (DECL_NAME (decl))); + initialized = 0; + } + break; + + case FUNCTION_DECL: + error ("function `%s' is initialized like a variable", + IDENTIFIER_POINTER (DECL_NAME (decl))); + initialized = 0; + break; + + case PARM_DECL: + /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ + error ("parameter `%s' is initialized", + IDENTIFIER_POINTER (DECL_NAME (decl))); + initialized = 0; + break; + + default: + /* Don't allow initializations for incomplete types + except for arrays which might be completed by the initialization. */ + if (TYPE_SIZE (TREE_TYPE (decl)) != 0) + { + /* A complete type is ok if size is fixed. */ + + if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST + || C_DECL_VARIABLE_SIZE (decl)) + { + error ("variable-sized object may not be initialized"); + initialized = 0; + } + } + else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) + { + error ("variable `%s' has initializer but incomplete type", + IDENTIFIER_POINTER (DECL_NAME (decl))); + initialized = 0; + } + else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0) + { + error ("elements of array `%s' have incomplete type", + IDENTIFIER_POINTER (DECL_NAME (decl))); + initialized = 0; + } + } + + if (initialized) + { +#if 0 /* Seems redundant with grokdeclarator. */ + if (current_binding_level != global_binding_level + && DECL_EXTERNAL (decl) + && TREE_CODE (decl) != FUNCTION_DECL) + warning ("declaration of `%s' has `extern' and is initialized", + IDENTIFIER_POINTER (DECL_NAME (decl))); +#endif + DECL_EXTERNAL (decl) = 0; + if (current_binding_level == global_binding_level) + TREE_STATIC (decl) = 1; + + /* Tell `pushdecl' this is an initialized decl + even though we don't yet have the initializer expression. + Also tell `finish_decl' it may store the real initializer. */ + DECL_INITIAL (decl) = error_mark_node; + } + + /* If this is a function declaration, write a record describing it to the + prototypes file (if requested). */ + + if (TREE_CODE (decl) == FUNCTION_DECL) + gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); + + /* For C and Objective-C, we by default put things in .common when + possible. */ + DECL_COMMON (decl) = 1; + + /* Set attributes here so if duplicate decl, will have proper attributes. */ + decl_attributes (decl, attributes, prefix_attributes); + + /* Add this decl to the current binding level. + TEM may equal DECL or it may be a previous decl of the same name. */ + tem = pushdecl (decl); + + /* For a local variable, define the RTL now. */ + if (current_binding_level != global_binding_level + /* But not if this is a duplicate decl + and we preserved the rtl from the previous one + (which may or may not happen). */ + && DECL_RTL (tem) == 0) + { + if (TYPE_SIZE (TREE_TYPE (tem)) != 0) + expand_decl (tem); + else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE + && DECL_INITIAL (tem) != 0) + expand_decl (tem); + } + + if (init_written) + { + /* When parsing and digesting the initializer, + use temporary storage. Do this even if we will ignore the value. */ + if (current_binding_level == global_binding_level && debug_temp_inits) + temporary_allocation (); + } + + return tem; +} + +/* Finish processing of a declaration; + install its initial value. + If the length of an array type is not known before, + it must be determined now, from the initial value, or it is an error. */ + +void +finish_decl (decl, init, asmspec_tree) + tree decl, init; + tree asmspec_tree; +{ + register tree type = TREE_TYPE (decl); + int was_incomplete = (DECL_SIZE (decl) == 0); + int temporary = allocation_temporary_p (); + char *asmspec = 0; + + /* If a name was specified, get the string. */ + if (asmspec_tree) + asmspec = TREE_STRING_POINTER (asmspec_tree); + + /* If `start_decl' didn't like having an initialization, ignore it now. */ + + if (init != 0 && DECL_INITIAL (decl) == 0) + init = 0; + /* Don't crash if parm is initialized. */ + if (TREE_CODE (decl) == PARM_DECL) + init = 0; + + if (ITERATOR_P (decl)) + { + if (init == 0) + error_with_decl (decl, "iterator has no initial value"); + else + init = save_expr (init); + } + + if (init) + { + if (TREE_CODE (decl) != TYPE_DECL) + store_init_value (decl, init); + else + { + /* typedef foo = bar; store the type of bar as the type of foo. */ + TREE_TYPE (decl) = TREE_TYPE (init); + DECL_INITIAL (decl) = init = 0; + } + } + + /* Pop back to the obstack that is current for this binding level. + This is because MAXINDEX, rtl, etc. to be made below + must go in the permanent obstack. But don't discard the + temporary data yet. */ + pop_obstacks (); +#if 0 /* pop_obstacks was near the end; this is what was here. */ + if (current_binding_level == global_binding_level && temporary) + end_temporary_allocation (); +#endif + + /* Deduce size of array from initialization, if not already known */ + + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == 0 + && TREE_CODE (decl) != TYPE_DECL) + { + int do_default + = (TREE_STATIC (decl) + /* Even if pedantic, an external linkage array + may have incomplete type at first. */ + ? pedantic && !TREE_PUBLIC (decl) + : !DECL_EXTERNAL (decl)); + int failure + = complete_array_type (type, DECL_INITIAL (decl), do_default); + + /* Get the completed type made by complete_array_type. */ + type = TREE_TYPE (decl); + + if (failure == 1) + error_with_decl (decl, "initializer fails to determine size of `%s'"); + + if (failure == 2) + { + if (do_default) + error_with_decl (decl, "array size missing in `%s'"); + /* If a `static' var's size isn't known, + make it extern as well as static, so it does not get + allocated. + If it is not `static', then do not mark extern; + finish_incomplete_decl will give it a default size + and it will get allocated. */ + else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl)) + DECL_EXTERNAL (decl) = 1; + } + + /* TYPE_MAX_VALUE is always one less than the number of elements + in the array, because we start counting at zero. Therefore, + warn only if the value is less than zero. */ + if (pedantic && TYPE_DOMAIN (type) != 0 + && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0) + error_with_decl (decl, "zero or negative size array `%s'"); + + layout_decl (decl, 0); + } + + if (TREE_CODE (decl) == VAR_DECL) + { + if (DECL_SIZE (decl) == 0 + && TYPE_SIZE (TREE_TYPE (decl)) != 0) + layout_decl (decl, 0); + + if (DECL_SIZE (decl) == 0 + && (TREE_STATIC (decl) + ? + /* A static variable with an incomplete type + is an error if it is initialized. + Also if it is not file scope. + Otherwise, let it through, but if it is not `extern' + then it may cause an error message later. */ + /* We must use DECL_CONTEXT instead of current_binding_level, + because a duplicate_decls call could have changed the binding + level of this decl. */ + (DECL_INITIAL (decl) != 0 || DECL_CONTEXT (decl) != 0) + : + /* An automatic variable with an incomplete type + is an error. */ + !DECL_EXTERNAL (decl))) + { + error_with_decl (decl, "storage size of `%s' isn't known"); + TREE_TYPE (decl) = error_mark_node; + } + + if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) + && DECL_SIZE (decl) != 0) + { + if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) + constant_expression_warning (DECL_SIZE (decl)); + else + error_with_decl (decl, "storage size of `%s' isn't constant"); + } + } + + /* If this is a function and an assembler name is specified, it isn't + builtin any more. Also reset DECL_RTL so we can give it its new + name. */ + if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) + { + DECL_BUILT_IN (decl) = 0; + DECL_RTL (decl) = 0; + } + + /* Output the assembler code and/or RTL code for variables and functions, + unless the type is an undefined structure or union. + If not, it will get done when the type is completed. */ + + if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) + { + if ((flag_traditional || TREE_PERMANENT (decl)) + && allocation_temporary_p ()) + { + push_obstacks_nochange (); + end_temporary_allocation (); + /* This is a no-op in c-lang.c or something real in objc-actions.c. */ + maybe_objc_check_decl (decl); + rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0, + 0); + pop_obstacks (); + } + else + { + /* This is a no-op in c-lang.c or something real in objc-actions.c. */ + maybe_objc_check_decl (decl); + rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0, + 0); + } + if (DECL_CONTEXT (decl) != 0) + { + /* Recompute the RTL of a local array now + if it used to be an incomplete type. */ + if (was_incomplete + && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl)) + { + /* If we used it already as memory, it must stay in memory. */ + TREE_ADDRESSABLE (decl) = TREE_USED (decl); + /* If it's still incomplete now, no init will save it. */ + if (DECL_SIZE (decl) == 0) + DECL_INITIAL (decl) = 0; + expand_decl (decl); + } + /* Compute and store the initial value. */ + if (TREE_CODE (decl) != FUNCTION_DECL) + expand_decl_init (decl); + } + } + + if (TREE_CODE (decl) == TYPE_DECL) + { + /* This is a no-op in c-lang.c or something real in objc-actions.c. */ + maybe_objc_check_decl (decl); + rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0, + 0); + } + + /* ??? After 2.3, test (init != 0) instead of TREE_CODE. */ + /* This test used to include TREE_PERMANENT, however, we have the same + problem with initializers at the function level. Such initializers get + saved until the end of the function on the momentary_obstack. */ + if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl)) + && temporary + /* DECL_INITIAL is not defined in PARM_DECLs, since it shares + space with DECL_ARG_TYPE. */ + && TREE_CODE (decl) != PARM_DECL) + { + /* We need to remember that this array HAD an initialization, + but discard the actual temporary nodes, + since we can't have a permanent node keep pointing to them. */ + /* We make an exception for inline functions, since it's + normal for a local extern redeclaration of an inline function + to have a copy of the top-level decl's DECL_INLINE. */ + if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node) + { + /* If this is a const variable, then preserve the + initializer instead of discarding it so that we can optimize + references to it. */ + /* This test used to include TREE_STATIC, but this won't be set + for function level initializers. */ + if (TREE_READONLY (decl) || ITERATOR_P (decl)) + { + preserve_initializer (); + /* Hack? Set the permanent bit for something that is permanent, + but not on the permanent obstack, so as to convince + output_constant_def to make its rtl on the permanent + obstack. */ + TREE_PERMANENT (DECL_INITIAL (decl)) = 1; + + /* The initializer and DECL must have the same (or equivalent + types), but if the initializer is a STRING_CST, its type + might not be on the right obstack, so copy the type + of DECL. */ + TREE_TYPE (DECL_INITIAL (decl)) = type; + } + else + DECL_INITIAL (decl) = error_mark_node; + } + } + + /* If requested, warn about definitions of large data objects. */ + + if (warn_larger_than + && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) + && !DECL_EXTERNAL (decl)) + { + register tree decl_size = DECL_SIZE (decl); + + if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) + { + unsigned units = TREE_INT_CST_LOW(decl_size) / BITS_PER_UNIT; + + if (units > larger_than_size) + warning_with_decl (decl, "size of `%s' is %u bytes", units); + } + } + +#if 0 + /* Resume permanent allocation, if not within a function. */ + /* The corresponding push_obstacks_nochange is in start_decl, + and in push_parm_decl and in grokfield. */ + pop_obstacks (); +#endif + + /* If we have gone back from temporary to permanent allocation, + actually free the temporary space that we no longer need. */ + if (temporary && !allocation_temporary_p ()) + permanent_allocation (0); + + /* At the end of a declaration, throw away any variable type sizes + of types defined inside that declaration. There is no use + computing them in the following function definition. */ + if (current_binding_level == global_binding_level) + get_pending_sizes (); +} + +/* If DECL has a cleanup, build and return that cleanup here. + This is a callback called by expand_expr. */ + +tree +maybe_build_cleanup (decl) + tree decl; +{ + /* There are no cleanups in C. */ + return NULL_TREE; +} + +/* Given a parsed parameter declaration, + decode it into a PARM_DECL and push that on the current binding level. + Also, for the sake of forward parm decls, + record the given order of parms in `parm_order'. */ + +void +push_parm_decl (parm) + tree parm; +{ + tree decl; + int old_immediate_size_expand = immediate_size_expand; + /* Don't try computing parm sizes now -- wait till fn is called. */ + immediate_size_expand = 0; + + /* The corresponding pop_obstacks is in finish_decl. */ + push_obstacks_nochange (); + + decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)), + TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0); + decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)), + TREE_PURPOSE (TREE_VALUE (parm))); + +#if 0 + if (DECL_NAME (decl)) + { + tree olddecl; + olddecl = lookup_name (DECL_NAME (decl)); + if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL) + pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef"); + } +#endif + + decl = pushdecl (decl); + + immediate_size_expand = old_immediate_size_expand; + + current_binding_level->parm_order + = tree_cons (NULL_TREE, decl, current_binding_level->parm_order); + + /* Add this decl to the current binding level. */ + finish_decl (decl, NULL_TREE, NULL_TREE); +} + +/* Clear the given order of parms in `parm_order'. + Used at start of parm list, + and also at semicolon terminating forward decls. */ + +void +clear_parm_order () +{ + current_binding_level->parm_order = NULL_TREE; +} + +/* Make TYPE a complete type based on INITIAL_VALUE. + Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, + 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ + +int +complete_array_type (type, initial_value, do_default) + tree type; + tree initial_value; + int do_default; +{ + register tree maxindex = NULL_TREE; + int value = 0; + + if (initial_value) + { + /* Note MAXINDEX is really the maximum index, + one less than the size. */ + if (TREE_CODE (initial_value) == STRING_CST) + { + int eltsize + = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); + maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) + / eltsize) - 1, 0); + } + else if (TREE_CODE (initial_value) == CONSTRUCTOR) + { + tree elts = CONSTRUCTOR_ELTS (initial_value); + maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); + for (; elts; elts = TREE_CHAIN (elts)) + { + if (TREE_PURPOSE (elts)) + maxindex = TREE_PURPOSE (elts); + else + maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); + } + maxindex = copy_node (maxindex); + } + else + { + /* Make an error message unless that happened already. */ + if (initial_value != error_mark_node) + value = 1; + + /* Prevent further error messages. */ + maxindex = build_int_2 (0, 0); + } + } + + if (!maxindex) + { + if (do_default) + maxindex = build_int_2 (0, 0); + value = 2; + } + + if (maxindex) + { + TYPE_DOMAIN (type) = build_index_type (maxindex); + if (!TREE_TYPE (maxindex)) + TREE_TYPE (maxindex) = TYPE_DOMAIN (type); +#if 0 /* I took out this change + together with the change in build_array_type. --rms */ + change_main_variant (type, + build_array_type (TREE_TYPE (type), + TYPE_DOMAIN (type))); +#endif + } + + /* Lay out the type now that we can get the real answer. */ + + layout_type (type); + + return value; +} + +/* Given declspecs and a declarator, + determine the name and type of the object declared + and construct a ..._DECL node for it. + (In one case we can return a ..._TYPE node instead. + For invalid input we sometimes return 0.) + + DECLSPECS is a chain of tree_list nodes whose value fields + are the storage classes and type specifiers. + + DECL_CONTEXT says which syntactic context this declaration is in: + NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. + FUNCDEF for a function definition. Like NORMAL but a few different + error messages in each case. Return value may be zero meaning + this definition is too screwy to try to parse. + PARM for a parameter declaration (either within a function prototype + or before a function body). Make a PARM_DECL, or return void_type_node. + TYPENAME if for a typename (in a cast or sizeof). + Don't make a DECL node; just return the ..._TYPE node. + FIELD for a struct or union field; make a FIELD_DECL. + BITFIELD for a field with specified width. + INITIALIZED is 1 if the decl has an initializer. + + In the TYPENAME case, DECLARATOR is really an absolute declarator. + It may also be so in the PARM case, for a prototype where the + argument type is specified but not the name. + + This function is where the complicated C meanings of `static' + and `extern' are interpreted. */ + +static tree +grokdeclarator (declarator, declspecs, decl_context, initialized) + tree declspecs; + tree declarator; + enum decl_context decl_context; + int initialized; +{ + int specbits = 0; + tree spec; + tree type = NULL_TREE; + int longlong = 0; + int constp; + int volatilep; + int inlinep; + int explicit_int = 0; + int explicit_char = 0; + int defaulted_int = 0; + tree typedef_decl = 0; + char *name; + tree typedef_type = 0; + int funcdef_flag = 0; + enum tree_code innermost_code = ERROR_MARK; + int bitfield = 0; + int size_varies = 0; + tree decl_machine_attr = NULL_TREE; + + if (decl_context == BITFIELD) + bitfield = 1, decl_context = FIELD; + + if (decl_context == FUNCDEF) + funcdef_flag = 1, decl_context = NORMAL; + + push_obstacks_nochange (); + + if (flag_traditional && allocation_temporary_p ()) + end_temporary_allocation (); + + /* Look inside a declarator for the name being declared + and get it as a string, for an error message. */ + { + register tree decl = declarator; + name = 0; + + while (decl) + switch (TREE_CODE (decl)) + { + case ARRAY_REF: + case INDIRECT_REF: + case CALL_EXPR: + innermost_code = TREE_CODE (decl); + decl = TREE_OPERAND (decl, 0); + break; + + case IDENTIFIER_NODE: + name = IDENTIFIER_POINTER (decl); + decl = 0; + break; + + default: + abort (); + } + if (name == 0) + name = "type name"; + } + + /* A function definition's declarator must have the form of + a function declarator. */ + + if (funcdef_flag && innermost_code != CALL_EXPR) + return 0; + + /* Anything declared one level down from the top level + must be one of the parameters of a function + (because the body is at least two levels down). */ + + /* If this looks like a function definition, make it one, + even if it occurs where parms are expected. + Then store_parm_decls will reject it and not use it as a parm. */ + if (decl_context == NORMAL && !funcdef_flag + && current_binding_level->parm_flag) + decl_context = PARM; + + /* Look through the decl specs and record which ones appear. + Some typespecs are defined as built-in typenames. + Others, the ones that are modifiers of other types, + are represented by bits in SPECBITS: set the bits for + the modifiers that appear. Storage class keywords are also in SPECBITS. + + If there is a typedef name or a type, store the type in TYPE. + This includes builtin typedefs such as `int'. + + Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char' + and did not come from a user typedef. + + Set LONGLONG if `long' is mentioned twice. */ + + for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) + { + register int i; + register tree id = TREE_VALUE (spec); + + if (id == ridpointers[(int) RID_INT]) + explicit_int = 1; + if (id == ridpointers[(int) RID_CHAR]) + explicit_char = 1; + + if (TREE_CODE (id) == IDENTIFIER_NODE) + for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++) + { + if (ridpointers[i] == id) + { + if (i == (int) RID_LONG && specbits & (1< 1) + pedwarn ("duplicate `const'"); + if (volatilep > 1) + pedwarn ("duplicate `volatile'"); + if (! flag_gen_aux_info && (TYPE_READONLY (type) || TYPE_VOLATILE (type))) + type = TYPE_MAIN_VARIANT (type); + + /* Warn if two storage classes are given. Default to `auto'. */ + + { + int nclasses = 0; + + if (specbits & 1 << (int) RID_AUTO) nclasses++; + if (specbits & 1 << (int) RID_STATIC) nclasses++; + if (specbits & 1 << (int) RID_EXTERN) nclasses++; + if (specbits & 1 << (int) RID_REGISTER) nclasses++; + if (specbits & 1 << (int) RID_TYPEDEF) nclasses++; + if (specbits & 1 << (int) RID_ITERATOR) nclasses++; + + /* Warn about storage classes that are invalid for certain + kinds of declarations (parameters, typenames, etc.). */ + + if (nclasses > 1) + error ("multiple storage classes in declaration of `%s'", name); + else if (funcdef_flag + && (specbits + & ((1 << (int) RID_REGISTER) + | (1 << (int) RID_AUTO) + | (1 << (int) RID_TYPEDEF)))) + { + if (specbits & 1 << (int) RID_AUTO + && (pedantic || current_binding_level == global_binding_level)) + pedwarn ("function definition declared `auto'"); + if (specbits & 1 << (int) RID_REGISTER) + error ("function definition declared `register'"); + if (specbits & 1 << (int) RID_TYPEDEF) + error ("function definition declared `typedef'"); + specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) + | (1 << (int) RID_AUTO)); + } + else if (decl_context != NORMAL && nclasses > 0) + { + if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER) + ; + else + { + error ((decl_context == FIELD + ? "storage class specified for structure field `%s'" + : (decl_context == PARM + ? "storage class specified for parameter `%s'" + : "storage class specified for typename")), + name); + specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) + | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC) + | (1 << (int) RID_EXTERN)); + } + } + else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag) + { + /* `extern' with initialization is invalid if not at top level. */ + if (current_binding_level == global_binding_level) + warning ("`%s' initialized and declared `extern'", name); + else + error ("`%s' has both `extern' and initializer", name); + } + else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag + && current_binding_level != global_binding_level) + error ("nested function `%s' declared `extern'", name); + else if (current_binding_level == global_binding_level + && specbits & (1 << (int) RID_AUTO)) + error ("top-level declaration of `%s' specifies `auto'", name); + else if ((specbits & 1 << (int) RID_ITERATOR) + && TREE_CODE (declarator) != IDENTIFIER_NODE) + { + error ("iterator `%s' has derived type", name); + type = error_mark_node; + } + else if ((specbits & 1 << (int) RID_ITERATOR) + && TREE_CODE (type) != INTEGER_TYPE) + { + error ("iterator `%s' has noninteger type", name); + type = error_mark_node; + } + } + + /* Now figure out the structure of the declarator proper. + Descend through it, creating more complex types, until we reach + the declared identifier (or NULL_TREE, in an absolute declarator). */ + + while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) + { + if (type == error_mark_node) + { + declarator = TREE_OPERAND (declarator, 0); + continue; + } + + /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), + an INDIRECT_REF (for *...), + a CALL_EXPR (for ...(...)), + an identifier (for the name being declared) + or a null pointer (for the place in an absolute declarator + where the name was omitted). + For the last two cases, we have just exited the loop. + + At this point, TYPE is the type of elements of an array, + or for a function to return, or for a pointer to point to. + After this sequence of ifs, TYPE is the type of the + array or function or pointer, and DECLARATOR has had its + outermost layer removed. */ + + if (TREE_CODE (declarator) == ARRAY_REF) + { + register tree itype = NULL_TREE; + register tree size = TREE_OPERAND (declarator, 1); + /* An uninitialized decl with `extern' is a reference. */ + int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); + /* The index is a signed object `sizetype' bits wide. */ + tree index_type = signed_type (sizetype); + + declarator = TREE_OPERAND (declarator, 0); + + /* Check for some types that there cannot be arrays of. */ + + if (TYPE_MAIN_VARIANT (type) == void_type_node) + { + error ("declaration of `%s' as array of voids", name); + type = error_mark_node; + } + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("declaration of `%s' as array of functions", name); + type = error_mark_node; + } + + if (size == error_mark_node) + type = error_mark_node; + + if (type == error_mark_node) + continue; + + /* If this is a block level extern, it must live past the end + of the function so that we can check it against other extern + declarations (IDENTIFIER_LIMBO_VALUE). */ + if (extern_ref && allocation_temporary_p ()) + end_temporary_allocation (); + + /* If size was specified, set ITYPE to a range-type for that size. + Otherwise, ITYPE remains null. finish_decl may figure it out + from an initial value. */ + + if (size) + { + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + STRIP_TYPE_NOPS (size); + + if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE + && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) + { + error ("size of array `%s' has non-integer type", name); + size = integer_one_node; + } + + if (pedantic && integer_zerop (size)) + pedwarn ("ANSI C forbids zero-size array `%s'", name); + + if (TREE_CODE (size) == INTEGER_CST) + { + constant_expression_warning (size); + if (tree_int_cst_sgn (size) < 0) + { + error ("size of array `%s' is negative", name); + size = integer_one_node; + } + } + else + { + /* Make sure the array size remains visibly nonconstant + even if it is (eg) a const variable with known value. */ + size_varies = 1; + + if (pedantic) + { + if (TREE_CONSTANT (size)) + pedwarn ("ANSI C forbids array `%s' whose size can't be evaluated", name); + else + pedwarn ("ANSI C forbids variable-size array `%s'", name); + } + } + + /* Convert size to index_type, so that if it is a variable + the computations will be done in the proper mode. */ + itype = fold (build (MINUS_EXPR, index_type, + convert (index_type, size), + convert (index_type, size_one_node))); + + if (size_varies) + itype = variable_size (itype); + itype = build_index_type (itype); + } + +#if 0 /* This had bad results for pointers to arrays, as in + union incomplete (*foo)[4]; */ + /* Complain about arrays of incomplete types, except in typedefs. */ + + if (TYPE_SIZE (type) == 0 + /* Avoid multiple warnings for nested array types. */ + && TREE_CODE (type) != ARRAY_TYPE + && !(specbits & (1 << (int) RID_TYPEDEF)) + && !C_TYPE_BEING_DEFINED (type)) + warning ("array type has incomplete element type"); +#endif + +#if 0 /* We shouldn't have a function type here at all! + Functions aren't allowed as array elements. */ + if (pedantic && TREE_CODE (type) == FUNCTION_TYPE + && (constp || volatilep)) + pedwarn ("ANSI C forbids const or volatile function types"); +#endif + + /* Build the array type itself, then merge any constancy or + volatility into the target type. We must do it in this order + to ensure that the TYPE_MAIN_VARIANT field of the array type + is set correctly. */ + + type = build_array_type (type, itype); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + +#if 0 /* don't clear these; leave them set so that the array type + or the variable is itself const or volatile. */ + constp = 0; + volatilep = 0; +#endif + + if (size_varies) + C_TYPE_VARIABLE_SIZE (type) = 1; + } + else if (TREE_CODE (declarator) == CALL_EXPR) + { + int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) + || current_binding_level == global_binding_level); + tree arg_types; + + /* Declaring a function type. + Make sure we have a valid type for the function to return. */ + if (type == error_mark_node) + continue; + + size_varies = 0; + + /* Warn about some types functions can't return. */ + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("`%s' declared as function returning a function", name); + type = integer_type_node; + } + if (TREE_CODE (type) == ARRAY_TYPE) + { + error ("`%s' declared as function returning an array", name); + type = integer_type_node; + } + +#ifndef TRADITIONAL_RETURN_FLOAT + /* Traditionally, declaring return type float means double. */ + + if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node) + type = double_type_node; +#endif /* TRADITIONAL_RETURN_FLOAT */ + + /* If this is a block level extern, it must live past the end + of the function so that we can check it against other extern + declarations (IDENTIFIER_LIMBO_VALUE). */ + if (extern_ref && allocation_temporary_p ()) + end_temporary_allocation (); + + /* Construct the function type and go to the next + inner layer of declarator. */ + + arg_types = grokparms (TREE_OPERAND (declarator, 1), + funcdef_flag + /* Say it's a definition + only for the CALL_EXPR + closest to the identifier. */ + && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE); +#if 0 /* This seems to be false. We turn off temporary allocation + above in this function if -traditional. + And this code caused inconsistent results with prototypes: + callers would ignore them, and pass arguments wrong. */ + + /* Omit the arg types if -traditional, since the arg types + and the list links might not be permanent. */ + type = build_function_type (type, + flag_traditional + ? NULL_TREE : arg_types); +#endif + /* ANSI seems to say that `const int foo ();' + does not make the function foo const. */ + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + constp = 0; + volatilep = 0; + + type = build_function_type (type, arg_types); + declarator = TREE_OPERAND (declarator, 0); + + /* Set the TYPE_CONTEXTs for each tagged type which is local to + the formal parameter list of this FUNCTION_TYPE to point to + the FUNCTION_TYPE node itself. */ + + { + register tree link; + + for (link = current_function_parm_tags; + link; + link = TREE_CHAIN (link)) + TYPE_CONTEXT (TREE_VALUE (link)) = type; + } + } + else if (TREE_CODE (declarator) == INDIRECT_REF) + { + /* Merge any constancy or volatility into the target type + for the pointer. */ + + if (pedantic && TREE_CODE (type) == FUNCTION_TYPE + && (constp || volatilep)) + pedwarn ("ANSI C forbids const or volatile function types"); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + constp = 0; + volatilep = 0; + size_varies = 0; + + type = build_pointer_type (type); + + /* Process a list of type modifier keywords + (such as const or volatile) that were given inside the `*'. */ + + if (TREE_TYPE (declarator)) + { + register tree typemodlist; + int erred = 0; + for (typemodlist = TREE_TYPE (declarator); typemodlist; + typemodlist = TREE_CHAIN (typemodlist)) + { + if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) + constp++; + else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) + volatilep++; + else if (!erred) + { + erred = 1; + error ("invalid type modifier within pointer declarator"); + } + } + if (constp > 1) + pedwarn ("duplicate `const'"); + if (volatilep > 1) + pedwarn ("duplicate `volatile'"); + } + + declarator = TREE_OPERAND (declarator, 0); + } + else + abort (); + + } + + /* Now TYPE has the actual type. */ + + /* If this is declaring a typedef name, return a TYPE_DECL. */ + + if (specbits & (1 << (int) RID_TYPEDEF)) + { + tree decl; + /* Note that the grammar rejects storage classes + in typenames, fields or parameters */ + if (pedantic && TREE_CODE (type) == FUNCTION_TYPE + && (constp || volatilep)) + pedwarn ("ANSI C forbids const or volatile function types"); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + pop_obstacks (); + decl = build_decl (TYPE_DECL, declarator, type); + if ((specbits & (1 << (int) RID_SIGNED)) + || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) + C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; + return decl; + } + + /* Detect the case of an array type of unspecified size + which came, as such, direct from a typedef name. + We must copy the type, so that each identifier gets + a distinct type, so that each identifier's size can be + controlled separately by its own initializer. */ + + if (type != 0 && typedef_type != 0 + && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type) + && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0) + { + type = build_array_type (TREE_TYPE (type), 0); + if (size_varies) + C_TYPE_VARIABLE_SIZE (type) = 1; + } + + /* If this is a type name (such as, in a cast or sizeof), + compute the type and return it now. */ + + if (decl_context == TYPENAME) + { + /* Note that the grammar rejects storage classes + in typenames, fields or parameters */ + if (pedantic && TREE_CODE (type) == FUNCTION_TYPE + && (constp || volatilep)) + pedwarn ("ANSI C forbids const or volatile function types"); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + pop_obstacks (); + return type; + } + + /* Aside from typedefs and type names (handle above), + `void' at top level (not within pointer) + is allowed only in public variables. + We don't complain about parms either, but that is because + a better error message can be made later. */ + + if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM + && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) + && ((specbits & (1 << (int) RID_EXTERN)) + || (current_binding_level == global_binding_level + && !(specbits + & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))))))) + { + error ("variable or field `%s' declared void", name); + type = integer_type_node; + } + + /* Now create the decl, which may be a VAR_DECL, a PARM_DECL + or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ + + { + register tree decl; + + if (decl_context == PARM) + { + tree type_as_written = type; + tree main_type; + + /* A parameter declared as an array of T is really a pointer to T. + One declared as a function is really a pointer to a function. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Transfer const-ness of array into that of type pointed to. */ + type = TREE_TYPE (type); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + type = build_pointer_type (type); + volatilep = constp = 0; + size_varies = 0; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + if (pedantic && (constp || volatilep)) + pedwarn ("ANSI C forbids const or volatile function types"); + if (constp || volatilep) + type = c_build_type_variant (type, constp, volatilep); + type = build_pointer_type (type); + volatilep = constp = 0; + } + + decl = build_decl (PARM_DECL, declarator, type); + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; + + /* Compute the type actually passed in the parmlist, + for the case where there is no prototype. + (For example, shorts and chars are passed as ints.) + When there is a prototype, this is overridden later. */ + + DECL_ARG_TYPE (decl) = type; + main_type = (type == error_mark_node + ? error_mark_node + : TYPE_MAIN_VARIANT (type)); + if (main_type == float_type_node) + DECL_ARG_TYPE (decl) = double_type_node; + /* Don't use TYPE_PRECISION to decide whether to promote, + because we should convert short if it's the same size as int, + but we should not convert long if it's the same size as int. */ + else if (TREE_CODE (main_type) != ERROR_MARK + && C_PROMOTING_INTEGER_TYPE_P (main_type)) + { + if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node) + && TREE_UNSIGNED (type)) + DECL_ARG_TYPE (decl) = unsigned_type_node; + else + DECL_ARG_TYPE (decl) = integer_type_node; + } + + DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written; + } + else if (decl_context == FIELD) + { + /* Structure field. It may not be a function. */ + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("field `%s' declared as a function", name); + type = build_pointer_type (type); + } + else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0) + { + error ("field `%s' has incomplete type", name); + type = error_mark_node; + } + /* Move type qualifiers down to element of an array. */ + if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep)) + { + type = build_array_type (c_build_type_variant (TREE_TYPE (type), + constp, volatilep), + TYPE_DOMAIN (type)); +#if 0 /* Leave the field const or volatile as well. */ + constp = volatilep = 0; +#endif + } + decl = build_decl (FIELD_DECL, declarator, type); + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + /* Every function declaration is "external" + except for those which are inside a function body + in which `auto' is used. + That is a case not specified by ANSI C, + and we use it for forward declarations for nested functions. */ + int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) + || current_binding_level == global_binding_level); + + if (specbits & (1 << (int) RID_AUTO) + && (pedantic || current_binding_level == global_binding_level)) + pedwarn ("invalid storage class for function `%s'", name); + if (specbits & (1 << (int) RID_REGISTER)) + error ("invalid storage class for function `%s'", name); + /* Function declaration not at top level. + Storage classes other than `extern' are not allowed + and `extern' makes no difference. */ + if (current_binding_level != global_binding_level + && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE))) + && pedantic) + pedwarn ("invalid storage class for function `%s'", name); + + /* If this is a block level extern, it must live past the end + of the function so that we can check it against other + extern declarations (IDENTIFIER_LIMBO_VALUE). */ + if (extern_ref && allocation_temporary_p ()) + end_temporary_allocation (); + + decl = build_decl (FUNCTION_DECL, declarator, type); + decl = build_decl_attribute_variant (decl, decl_machine_attr); + + if (pedantic && (constp || volatilep) + && ! DECL_IN_SYSTEM_HEADER (decl)) + pedwarn ("ANSI C forbids const or volatile functions"); + + if (volatilep + && TREE_TYPE (TREE_TYPE (decl)) != void_type_node) + warning ("`noreturn' function returns non-void value"); + + if (extern_ref) + DECL_EXTERNAL (decl) = 1; + /* Record absence of global scope for `static' or `auto'. */ + TREE_PUBLIC (decl) + = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO))); + + /* Record presence of `inline', if it is reasonable. */ + if (inlinep) + { + tree last = tree_last (TYPE_ARG_TYPES (type)); + + if (! strcmp (IDENTIFIER_POINTER (declarator), "main")) + warning ("cannot inline function `main'"); + else if (last && (TYPE_MAIN_VARIANT (TREE_VALUE (last)) + != void_type_node)) + warning ("inline declaration ignored for function with `...'"); + else + /* Assume that otherwise the function can be inlined. */ + DECL_INLINE (decl) = 1; + + if (specbits & (1 << (int) RID_EXTERN)) + current_extern_inline = 1; + } + } + else + { + /* It's a variable. */ + /* An uninitialized decl with `extern' is a reference. */ + int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); + + /* Move type qualifiers down to element of an array. */ + if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep)) + { + type = build_array_type (c_build_type_variant (TREE_TYPE (type), + constp, volatilep), + TYPE_DOMAIN (type)); +#if 0 /* Leave the variable const or volatile as well. */ + constp = volatilep = 0; +#endif + } + + /* If this is a block level extern, it must live past the end + of the function so that we can check it against other + extern declarations (IDENTIFIER_LIMBO_VALUE). */ + if (extern_ref && allocation_temporary_p ()) + end_temporary_allocation (); + + decl = build_decl (VAR_DECL, declarator, type); + if (size_varies) + C_DECL_VARIABLE_SIZE (decl) = 1; + + if (inlinep) + pedwarn_with_decl (decl, "variable `%s' declared `inline'"); + + DECL_EXTERNAL (decl) = extern_ref; + /* At top level, the presence of a `static' or `register' storage + class specifier, or the absence of all storage class specifiers + makes this declaration a definition (perhaps tentative). Also, + the absence of both `static' and `register' makes it public. */ + if (current_binding_level == global_binding_level) + { + TREE_PUBLIC (decl) + = !(specbits + & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))); + TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); + } + /* Not at top level, only `static' makes a static definition. */ + else + { + TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0; + TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); + } + + if (specbits & 1 << (int) RID_ITERATOR) + ITERATOR_P (decl) = 1; + } + + /* Record `register' declaration for warnings on & + and in case doing stupid register allocation. */ + + if (specbits & (1 << (int) RID_REGISTER)) + DECL_REGISTER (decl) = 1; + + /* Record constancy and volatility. */ + + if (constp) + TREE_READONLY (decl) = 1; + if (volatilep) + { + TREE_SIDE_EFFECTS (decl) = 1; + TREE_THIS_VOLATILE (decl) = 1; + } + /* If a type has volatile components, it should be stored in memory. + Otherwise, the fact that those components are volatile + will be ignored, and would even crash the compiler. */ + if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))) + mark_addressable (decl); + + pop_obstacks (); + + return decl; + } +} + +/* Decode the parameter-list info for a function type or function definition. + The argument is the value returned by `get_parm_info' (or made in parse.y + if there is an identifier list instead of a parameter decl list). + These two functions are separate because when a function returns + or receives functions then each is called multiple times but the order + of calls is different. The last call to `grokparms' is always the one + that contains the formal parameter names of a function definition. + + Store in `last_function_parms' a chain of the decls of parms. + Also store in `last_function_parm_tags' a chain of the struct, union, + and enum tags declared among the parms. + + Return a list of arg types to use in the FUNCTION_TYPE for this function. + + FUNCDEF_FLAG is nonzero for a function definition, 0 for + a mere declaration. A nonempty identifier-list gets an error message + when FUNCDEF_FLAG is zero. */ + +static tree +grokparms (parms_info, funcdef_flag) + tree parms_info; + int funcdef_flag; +{ + tree first_parm = TREE_CHAIN (parms_info); + + last_function_parms = TREE_PURPOSE (parms_info); + last_function_parm_tags = TREE_VALUE (parms_info); + + if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag + && !in_system_header) + warning ("function declaration isn't a prototype"); + + if (first_parm != 0 + && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) + { + if (! funcdef_flag) + pedwarn ("parameter names (without types) in function declaration"); + + last_function_parms = first_parm; + return 0; + } + else + { + tree parm; + tree typelt; + /* We no longer test FUNCDEF_FLAG. + If the arg types are incomplete in a declaration, + they must include undefined tags. + These tags can never be defined in the scope of the declaration, + so the types can never be completed, + and no call can be compiled successfully. */ +#if 0 + /* In a fcn definition, arg types must be complete. */ + if (funcdef_flag) +#endif + for (parm = last_function_parms, typelt = first_parm; + parm; + parm = TREE_CHAIN (parm)) + /* Skip over any enumeration constants declared here. */ + if (TREE_CODE (parm) == PARM_DECL) + { + /* Barf if the parameter itself has an incomplete type. */ + tree type = TREE_VALUE (typelt); + if (TYPE_SIZE (type) == 0) + { + if (funcdef_flag && DECL_NAME (parm) != 0) + error ("parameter `%s' has incomplete type", + IDENTIFIER_POINTER (DECL_NAME (parm))); + else + warning ("parameter has incomplete type"); + if (funcdef_flag) + { + TREE_VALUE (typelt) = error_mark_node; + TREE_TYPE (parm) = error_mark_node; + } + } +#if 0 /* This has been replaced by parm_tags_warning + which uses a more accurate criterion for what to warn about. */ + else + { + /* Now warn if is a pointer to an incomplete type. */ + while (TREE_CODE (type) == POINTER_TYPE + || TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + type = TYPE_MAIN_VARIANT (type); + if (TYPE_SIZE (type) == 0) + { + if (DECL_NAME (parm) != 0) + warning ("parameter `%s' points to incomplete type", + IDENTIFIER_POINTER (DECL_NAME (parm))); + else + warning ("parameter points to incomplete type"); + } + } +#endif + typelt = TREE_CHAIN (typelt); + } + + /* Allocate the list of types the way we allocate a type. */ + if (first_parm && ! TREE_PERMANENT (first_parm)) + { + /* Construct a copy of the list of types + on the saveable obstack. */ + tree result = NULL; + for (typelt = first_parm; typelt; typelt = TREE_CHAIN (typelt)) + result = saveable_tree_cons (NULL_TREE, TREE_VALUE (typelt), + result); + return nreverse (result); + } + else + /* The list we have is permanent already. */ + return first_parm; + } +} + + +/* Return a tree_list node with info on a parameter list just parsed. + The TREE_PURPOSE is a chain of decls of those parms. + The TREE_VALUE is a list of structure, union and enum tags defined. + The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE. + This tree_list node is later fed to `grokparms'. + + VOID_AT_END nonzero means append `void' to the end of the type-list. + Zero means the parmlist ended with an ellipsis so don't append `void'. */ + +tree +get_parm_info (void_at_end) + int void_at_end; +{ + register tree decl, t; + register tree types = 0; + int erred = 0; + tree tags = gettags (); + tree parms = getdecls (); + tree new_parms = 0; + tree order = current_binding_level->parm_order; + + /* Just `void' (and no ellipsis) is special. There are really no parms. */ + if (void_at_end && parms != 0 + && TREE_CHAIN (parms) == 0 + && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node + && DECL_NAME (parms) == 0) + { + parms = NULL_TREE; + storedecls (NULL_TREE); + return saveable_tree_cons (NULL_TREE, NULL_TREE, + saveable_tree_cons (NULL_TREE, void_type_node, NULL_TREE)); + } + + /* Extract enumerator values and other non-parms declared with the parms. + Likewise any forward parm decls that didn't have real parm decls. */ + for (decl = parms; decl; ) + { + tree next = TREE_CHAIN (decl); + + if (TREE_CODE (decl) != PARM_DECL) + { + TREE_CHAIN (decl) = new_parms; + new_parms = decl; + } + else if (TREE_ASM_WRITTEN (decl)) + { + error_with_decl (decl, "parameter `%s' has just a forward declaration"); + TREE_CHAIN (decl) = new_parms; + new_parms = decl; + } + decl = next; + } + + /* Put the parm decls back in the order they were in in the parm list. */ + for (t = order; t; t = TREE_CHAIN (t)) + { + if (TREE_CHAIN (t)) + TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t)); + else + TREE_CHAIN (TREE_VALUE (t)) = 0; + } + + new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0, + new_parms); + + /* Store the parmlist in the binding level since the old one + is no longer a valid list. (We have changed the chain pointers.) */ + storedecls (new_parms); + + for (decl = new_parms; decl; decl = TREE_CHAIN (decl)) + /* There may also be declarations for enumerators if an enumeration + type is declared among the parms. Ignore them here. */ + if (TREE_CODE (decl) == PARM_DECL) + { + /* Since there is a prototype, + args are passed in their declared types. */ + tree type = TREE_TYPE (decl); + DECL_ARG_TYPE (decl) = type; +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (decl) = integer_type_node; +#endif + + types = saveable_tree_cons (NULL_TREE, TREE_TYPE (decl), types); + if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred + && DECL_NAME (decl) == 0) + { + error ("`void' in parameter list must be the entire list"); + erred = 1; + } + } + + if (void_at_end) + return saveable_tree_cons (new_parms, tags, + nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types))); + + return saveable_tree_cons (new_parms, tags, nreverse (types)); +} + +/* At end of parameter list, warn about any struct, union or enum tags + defined within. Do so because these types cannot ever become complete. */ + +void +parmlist_tags_warning () +{ + tree elt; + static int already; + + for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt)) + { + enum tree_code code = TREE_CODE (TREE_VALUE (elt)); + /* An anonymous union parm type is meaningful as a GNU extension. + So don't warn for that. */ + if (code == UNION_TYPE && !pedantic) + continue; + if (TREE_PURPOSE (elt) != 0) + warning ("`%s %s' declared inside parameter list", + (code == RECORD_TYPE ? "struct" + : code == UNION_TYPE ? "union" + : "enum"), + IDENTIFIER_POINTER (TREE_PURPOSE (elt))); + else + warning ("anonymous %s declared inside parameter list", + (code == RECORD_TYPE ? "struct" + : code == UNION_TYPE ? "union" + : "enum")); + + if (! already) + { + warning ("its scope is only this definition or declaration,"); + warning ("which is probably not what you want."); + already = 1; + } + } +} + +/* Get the struct, enum or union (CODE says which) with tag NAME. + Define the tag as a forward-reference if it is not defined. */ + +tree +xref_tag (code, name) + enum tree_code code; + tree name; +{ + int temporary = allocation_temporary_p (); + + /* If a cross reference is requested, look up the type + already defined for this tag and return it. */ + + register tree ref = lookup_tag (code, name, current_binding_level, 0); + /* Even if this is the wrong type of tag, return what we found. + There will be an error message anyway, from pending_xref_error. + If we create an empty xref just for an invalid use of the type, + the main result is to create lots of superfluous error messages. */ + if (ref) + return ref; + + push_obstacks_nochange (); + + if (current_binding_level == global_binding_level && temporary) + end_temporary_allocation (); + + /* If no such tag is yet defined, create a forward-reference node + and record it as the "definition". + When a real declaration of this type is found, + the forward-reference will be altered into a real type. */ + + ref = make_node (code); + if (code == ENUMERAL_TYPE) + { + /* (In ANSI, Enums can be referred to only if already defined.) */ + if (pedantic) + pedwarn ("ANSI C forbids forward references to `enum' types"); + /* Give the type a default layout like unsigned int + to avoid crashing if it does not get defined. */ + TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); + TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); + TREE_UNSIGNED (ref) = 1; + TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); + TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); + TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); + } + + pushtag (name, ref); + + pop_obstacks (); + + return ref; +} + +/* Make sure that the tag NAME is defined *in the current binding level* + at least as a forward reference. + CODE says which kind of tag NAME ought to be. + + We also do a push_obstacks_nochange + whose matching pop is in finish_struct. */ + +tree +start_struct (code, name) + enum tree_code code; + tree name; +{ + /* If there is already a tag defined at this binding level + (as a forward reference), just return it. */ + + register tree ref = 0; + + push_obstacks_nochange (); + if (current_binding_level == global_binding_level) + end_temporary_allocation (); + + if (name != 0) + ref = lookup_tag (code, name, current_binding_level, 1); + if (ref && TREE_CODE (ref) == code) + { + C_TYPE_BEING_DEFINED (ref) = 1; + if (TYPE_FIELDS (ref)) + error ((code == UNION_TYPE ? "redefinition of `union %s'" + : "redefinition of `struct %s'"), + IDENTIFIER_POINTER (name)); + + return ref; + } + + /* Otherwise create a forward-reference just so the tag is in scope. */ + + ref = make_node (code); + pushtag (name, ref); + C_TYPE_BEING_DEFINED (ref) = 1; + return ref; +} + +/* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) + of a structure component, returning a FIELD_DECL node. + WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. + + This is done during the parsing of the struct declaration. + The FIELD_DECL nodes are chained together and the lot of them + are ultimately passed to `build_struct' to make the RECORD_TYPE node. */ + +tree +grokfield (filename, line, declarator, declspecs, width) + char *filename; + int line; + tree declarator, declspecs, width; +{ + tree value; + + /* The corresponding pop_obstacks is in finish_decl. */ + push_obstacks_nochange (); + + value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0); + + finish_decl (value, NULL_TREE, NULL_TREE); + DECL_INITIAL (value) = width; + + maybe_objc_check_decl (value); + return value; +} + +/* Function to help qsort sort FIELD_DECLs by name order. */ + +static int +field_decl_cmp (x, y) + tree *x, *y; +{ + if (DECL_NAME (*x) == DECL_NAME (*y)) + return 0; + if (DECL_NAME (*x) == NULL) + return -1; + if (DECL_NAME (*y) == NULL) + return 1; + if (DECL_NAME (*x) < DECL_NAME (*y)) + return -1; + return 1; +} + +/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. + FIELDLIST is a chain of FIELD_DECL nodes for the fields. + ATTRIBUTES are attributes to be applied to the structure. + + We also do a pop_obstacks to match the push in start_struct. */ + +tree +finish_struct (t, fieldlist, attributes) + tree t; + tree fieldlist; + tree attributes; +{ + register tree x; + int old_momentary; + int toplevel = global_binding_level == current_binding_level; + + /* If this type was previously laid out as a forward reference, + make sure we lay it out again. */ + + TYPE_SIZE (t) = 0; + + decl_attributes (t, attributes, NULL_TREE); + + /* Nameless union parm types are useful as GCC extension. */ + if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic) + /* Otherwise, warn about any struct or union def. in parmlist. */ + if (in_parm_level_p ()) + { + if (pedantic) + pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms" + : "structure defined inside parms")); + else if (! flag_traditional) + warning ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms" + : "structure defined inside parms")); + } + + old_momentary = suspend_momentary (); + + if (fieldlist == 0 && pedantic) + pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union has no members" + : "structure has no members")); + + /* Install struct as DECL_CONTEXT of each field decl. + Also process specified field sizes. + Set DECL_FIELD_SIZE to the specified size, or 0 if none specified. + The specified size is found in the DECL_INITIAL. + Store 0 there, except for ": 0" fields (so we can find them + and delete them, below). */ + + for (x = fieldlist; x; x = TREE_CHAIN (x)) + { + DECL_CONTEXT (x) = t; + DECL_PACKED (x) |= TYPE_PACKED (t); + DECL_FIELD_SIZE (x) = 0; + + /* If any field is const, the structure type is pseudo-const. */ + if (TREE_READONLY (x)) + C_TYPE_FIELDS_READONLY (t) = 1; + else + { + /* A field that is pseudo-const makes the structure likewise. */ + tree t1 = TREE_TYPE (x); + while (TREE_CODE (t1) == ARRAY_TYPE) + t1 = TREE_TYPE (t1); + if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (t1)) + C_TYPE_FIELDS_READONLY (t) = 1; + } + + /* Any field that is volatile means variables of this type must be + treated in some ways as volatile. */ + if (TREE_THIS_VOLATILE (x)) + C_TYPE_FIELDS_VOLATILE (t) = 1; + + /* Any field of nominal variable size implies structure is too. */ + if (C_DECL_VARIABLE_SIZE (x)) + C_TYPE_VARIABLE_SIZE (t) = 1; + + /* Detect invalid nested redefinition. */ + if (TREE_TYPE (x) == t) + error ("nested redefinition of `%s'", + IDENTIFIER_POINTER (TYPE_NAME (t))); + + /* Detect invalid bit-field size. */ + if (DECL_INITIAL (x)) + STRIP_NOPS (DECL_INITIAL (x)); + if (DECL_INITIAL (x)) + { + if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST) + constant_expression_warning (DECL_INITIAL (x)); + else + { + error_with_decl (x, "bit-field `%s' width not an integer constant"); + DECL_INITIAL (x) = NULL; + } + } + + /* Detect invalid bit-field type. */ + if (DECL_INITIAL (x) + && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE + && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) + { + error_with_decl (x, "bit-field `%s' has invalid type"); + DECL_INITIAL (x) = NULL; + } + if (DECL_INITIAL (x) && pedantic + && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node + && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node + /* Accept an enum that's equivalent to int or unsigned int. */ + && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE + && (TYPE_PRECISION (TREE_TYPE (x)) + == TYPE_PRECISION (integer_type_node)))) + pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C"); + + /* Detect and ignore out of range field width. */ + if (DECL_INITIAL (x)) + { + unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x)); + + if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0) + { + DECL_INITIAL (x) = NULL; + error_with_decl (x, "negative width in bit-field `%s'"); + } + else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0 + || width > TYPE_PRECISION (TREE_TYPE (x))) + { + DECL_INITIAL (x) = NULL; + pedwarn_with_decl (x, "width of `%s' exceeds its type"); + } + else if (width == 0 && DECL_NAME (x) != 0) + { + error_with_decl (x, "zero width for bit-field `%s'"); + DECL_INITIAL (x) = NULL; + } + } + + /* Process valid field width. */ + if (DECL_INITIAL (x)) + { + register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); + + DECL_FIELD_SIZE (x) = width; + DECL_BIT_FIELD (x) = 1; + DECL_INITIAL (x) = NULL; + + if (width == 0) + { + /* field size 0 => force desired amount of alignment. */ +#ifdef EMPTY_FIELD_BOUNDARY + DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY); +#endif +#ifdef PCC_BITFIELD_TYPE_MATTERS + DECL_ALIGN (x) = MAX (DECL_ALIGN (x), + TYPE_ALIGN (TREE_TYPE (x))); +#endif + } + } + else if (TREE_TYPE (x) != error_mark_node) + { + int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT + : TYPE_ALIGN (TREE_TYPE (x))); + /* Non-bit-fields are aligned for their type, except packed + fields which require only BITS_PER_UNIT alignment. */ + DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align); + } + } + + /* Now DECL_INITIAL is null on all members. */ + + /* Delete all duplicate fields from the fieldlist */ + for (x = fieldlist; x && TREE_CHAIN (x);) + /* Anonymous fields aren't duplicates. */ + if (DECL_NAME (TREE_CHAIN (x)) == 0) + x = TREE_CHAIN (x); + else + { + register tree y = fieldlist; + + while (1) + { + if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) + break; + if (y == x) + break; + y = TREE_CHAIN (y); + } + if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) + { + error_with_decl (TREE_CHAIN (x), "duplicate member `%s'"); + TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); + } + else x = TREE_CHAIN (x); + } + + /* Now we have the nearly final fieldlist. Record it, + then lay out the structure or union (including the fields). */ + + TYPE_FIELDS (t) = fieldlist; + + layout_type (t); + + /* Delete all zero-width bit-fields from the front of the fieldlist */ + while (fieldlist + && DECL_INITIAL (fieldlist)) + fieldlist = TREE_CHAIN (fieldlist); + /* Delete all such members from the rest of the fieldlist */ + for (x = fieldlist; x;) + { + if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x))) + TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); + else x = TREE_CHAIN (x); + } + + /* Now we have the truly final field list. + Store it in this type and in the variants. */ + + TYPE_FIELDS (t) = fieldlist; + + /* If there are lots of fields, sort so we can look through them fast. + We arbitrarily consider 16 or more elts to be "a lot". */ + { + int len = 0; + + for (x = fieldlist; x; x = TREE_CHAIN (x)) + { + if (len > 15) + break; + len += 1; + } + if (len > 15) + { + tree *field_array; + char *space; + + len += list_length (x); + /* Use the same allocation policy here that make_node uses, to + ensure that this lives as long as the rest of the struct decl. + All decls in an inline function need to be saved. */ + if (allocation_temporary_p ()) + space = savealloc (sizeof (struct lang_type) + len * sizeof (tree)); + else + space = oballoc (sizeof (struct lang_type) + len * sizeof (tree)); + + TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space; + TYPE_LANG_SPECIFIC (t)->len = len; + + field_array = &TYPE_LANG_SPECIFIC (t)->elts[0]; + len = 0; + for (x = fieldlist; x; x = TREE_CHAIN (x)) + field_array[len++] = x; + + qsort (field_array, len, sizeof (tree), field_decl_cmp); + } + } + + for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) + { + TYPE_FIELDS (x) = TYPE_FIELDS (t); + TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t); + TYPE_ALIGN (x) = TYPE_ALIGN (t); + } + + /* Promote each bit-field's type to int if it is narrower than that. */ + for (x = fieldlist; x; x = TREE_CHAIN (x)) + if (DECL_BIT_FIELD (x) + && (C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x)) + || DECL_FIELD_SIZE (x) < TYPE_PRECISION (integer_type_node))) + { + tree type = TREE_TYPE (x); + + /* Preserve unsignedness if traditional + or if not really getting any wider. */ + if (TREE_UNSIGNED (type) + && (flag_traditional + || + (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node) + && + DECL_FIELD_SIZE (x) == TYPE_PRECISION (integer_type_node)))) + TREE_TYPE (x) = unsigned_type_node; + else + TREE_TYPE (x) = integer_type_node; + } + + /* If this was supposed to be a transparent union, but we can't + make it one, warn and turn off the flag. */ + if (TREE_CODE (t) == UNION_TYPE + && TYPE_TRANSPARENT_UNION (t) + && TYPE_MODE (t) != DECL_MODE (TYPE_FIELDS (t))) + { + TYPE_TRANSPARENT_UNION (t) = 0; + warning ("cannot make `%s' a transparent union"); + } + + /* If this structure or union completes the type of any previous + variable declaration, lay it out and output its rtl. */ + + if (current_binding_level->n_incomplete != 0) + { + tree decl; + for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) + { + if (TREE_TYPE (decl) == t + && TREE_CODE (decl) != TYPE_DECL) + { + layout_decl (decl, 0); + /* This is a no-op in c-lang.c or something real in objc-actions.c. */ + maybe_objc_check_decl (decl); + rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); + if (! toplevel) + expand_decl (decl); + --current_binding_level->n_incomplete; + } + else if (TYPE_SIZE (TREE_TYPE (decl)) == 0 + && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) + { + tree element = TREE_TYPE (decl); + while (TREE_CODE (element) == ARRAY_TYPE) + element = TREE_TYPE (element); + if (element == t) + layout_array_type (TREE_TYPE (decl)); + } + } + } + + resume_momentary (old_momentary); + + /* Finish debugging output for this type. */ + rest_of_type_compilation (t, toplevel); + + /* The matching push is in start_struct. */ + pop_obstacks (); + + return t; +} + +/* Lay out the type T, and its element type, and so on. */ + +static void +layout_array_type (t) + tree t; +{ + if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) + layout_array_type (TREE_TYPE (t)); + layout_type (t); +} + +/* Begin compiling the definition of an enumeration type. + NAME is its name (or null if anonymous). + Returns the type object, as yet incomplete. + Also records info about it so that build_enumerator + may be used to declare the individual values as they are read. */ + +tree +start_enum (name) + tree name; +{ + register tree enumtype = 0; + + /* If this is the real definition for a previous forward reference, + fill in the contents in the same object that used to be the + forward reference. */ + + if (name != 0) + enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1); + + /* The corresponding pop_obstacks is in finish_enum. */ + push_obstacks_nochange (); + /* If these symbols and types are global, make them permanent. */ + if (current_binding_level == global_binding_level) + end_temporary_allocation (); + + if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) + { + enumtype = make_node (ENUMERAL_TYPE); + pushtag (name, enumtype); + } + + C_TYPE_BEING_DEFINED (enumtype) = 1; + + if (TYPE_VALUES (enumtype) != 0) + { + /* This enum is a named one that has been declared already. */ + error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name)); + + /* Completely replace its old definition. + The old enumerators remain defined, however. */ + TYPE_VALUES (enumtype) = 0; + } + + enum_next_value = integer_zero_node; + enum_overflow = 0; + + return enumtype; +} + +/* After processing and defining all the values of an enumeration type, + install their decls in the enumeration type and finish it off. + ENUMTYPE is the type object, VALUES a list of decl-value pairs, + and ATTRIBUTES are the specified attributes. + Returns ENUMTYPE. */ + +tree +finish_enum (enumtype, values, attributes) + tree enumtype; + tree values; + tree attributes; +{ + register tree pair, tem; + tree minnode = 0, maxnode = 0; + int lowprec, highprec, precision; + int toplevel = global_binding_level == current_binding_level; + + if (in_parm_level_p ()) + warning ("enum defined inside parms"); + + decl_attributes (enumtype, attributes, NULL_TREE); + + /* Calculate the maximum value of any enumerator in this type. */ + + if (values == error_mark_node) + minnode = maxnode = integer_zero_node; + else + for (pair = values; pair; pair = TREE_CHAIN (pair)) + { + tree value = TREE_VALUE (pair); + if (pair == values) + minnode = maxnode = TREE_VALUE (pair); + else + { + if (tree_int_cst_lt (maxnode, value)) + maxnode = value; + if (tree_int_cst_lt (value, minnode)) + minnode = value; + } + } + + TYPE_MIN_VALUE (enumtype) = minnode; + TYPE_MAX_VALUE (enumtype) = maxnode; + + /* An enum can have some negative values; then it is signed. */ + TREE_UNSIGNED (enumtype) = tree_int_cst_sgn (minnode) >= 0; + + /* Determine the precision this type needs. */ + + lowprec = min_precision (minnode, TREE_UNSIGNED (enumtype)); + highprec = min_precision (maxnode, TREE_UNSIGNED (enumtype)); + precision = MAX (lowprec, highprec); + + if (flag_short_enums || TYPE_PACKED (enumtype) + || precision > TYPE_PRECISION (integer_type_node)) + /* Use the width of the narrowest normal C type which is wide enough. */ + TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1)); + else + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + + TYPE_SIZE (enumtype) = 0; + layout_type (enumtype); + + if (values != error_mark_node) + { + /* Change the type of the enumerators to be the enum type. + Formerly this was done only for enums that fit in an int, + but the comment said it was done only for enums wider than int. + It seems necessary to do this for wide enums, + and best not to change what's done for ordinary narrower ones. */ + for (pair = values; pair; pair = TREE_CHAIN (pair)) + { + TREE_TYPE (TREE_PURPOSE (pair)) = enumtype; + DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype); + if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL) + DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype); + } + + /* Replace the decl nodes in VALUES with their names. */ + for (pair = values; pair; pair = TREE_CHAIN (pair)) + TREE_PURPOSE (pair) = DECL_NAME (TREE_PURPOSE (pair)); + + TYPE_VALUES (enumtype) = values; + } + + /* Fix up all variant types of this enum type. */ + for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) + { + TYPE_VALUES (tem) = TYPE_VALUES (enumtype); + TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); + TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); + TYPE_SIZE (tem) = TYPE_SIZE (enumtype); + TYPE_MODE (tem) = TYPE_MODE (enumtype); + TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); + TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); + TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); + } + + /* Finish debugging output for this type. */ + rest_of_type_compilation (enumtype, toplevel); + + /* This matches a push in start_enum. */ + pop_obstacks (); + + return enumtype; +} + +/* Build and install a CONST_DECL for one value of the + current enumeration type (one that was begun with start_enum). + Return a tree-list containing the CONST_DECL and its value. + Assignment of sequential values by default is handled here. */ + +tree +build_enumerator (name, value) + tree name, value; +{ + register tree decl, type; + + /* Validate and default VALUE. */ + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); + + if (value != 0) + { + if (TREE_CODE (value) == INTEGER_CST) + { + value = default_conversion (value); + constant_expression_warning (value); + } + else + { + error ("enumerator value for `%s' not integer constant", + IDENTIFIER_POINTER (name)); + value = 0; + } + } + + /* Default based on previous value. */ + /* It should no longer be possible to have NON_LVALUE_EXPR + in the default. */ + if (value == 0) + { + value = enum_next_value; + if (enum_overflow) + error ("overflow in enumeration values"); + } + + if (pedantic && ! int_fits_type_p (value, integer_type_node)) + { + pedwarn ("ANSI C restricts enumerator values to range of `int'"); + value = integer_zero_node; + } + + /* Set basis for default for next value. */ + enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0); + enum_overflow = tree_int_cst_lt (enum_next_value, value); + + /* Now create a declaration for the enum value name. */ + + type = TREE_TYPE (value); + type = type_for_size (MAX (TYPE_PRECISION (type), + TYPE_PRECISION (integer_type_node)), + ((flag_traditional + || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)) + && TREE_UNSIGNED (type))); + + decl = build_decl (CONST_DECL, name, type); + DECL_INITIAL (decl) = value; + TREE_TYPE (value) = type; + pushdecl (decl); + + return saveable_tree_cons (decl, value, NULL_TREE); +} + +/* Create the FUNCTION_DECL for a function definition. + DECLSPECS, DECLARATOR, PREFIX_ATTRIBUTES and ATTRIBUTES are the parts of + the declaration; they describe the function's name and the type it returns, + but twisted together in a fashion that parallels the syntax of C. + + This function creates a binding context for the function body + as well as setting up the FUNCTION_DECL in current_function_decl. + + Returns 1 on success. If the DECLARATOR is not suitable for a function + (it defines a datum instead), we return 0, which tells + yyparse to report a parse error. + + NESTED is nonzero for a function nested within another function. */ + +int +start_function (declspecs, declarator, prefix_attributes, attributes, nested) + tree declarator, declspecs, prefix_attributes, attributes; + int nested; +{ + tree decl1, old_decl; + tree restype; + int old_immediate_size_expand = immediate_size_expand; + + current_function_returns_value = 0; /* Assume, until we see it does. */ + current_function_returns_null = 0; + warn_about_return_type = 0; + current_extern_inline = 0; + c_function_varargs = 0; + named_labels = 0; + shadowed_labels = 0; + + /* Don't expand any sizes in the return type of the function. */ + immediate_size_expand = 0; + + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1); + + /* If the declarator is not suitable for a function definition, + cause a syntax error. */ + if (decl1 == 0) + return 0; + + decl_attributes (decl1, prefix_attributes, attributes); + + announce_function (decl1); + + if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0) + { + error ("return-type is an incomplete type"); + /* Make it return void instead. */ + TREE_TYPE (decl1) + = build_function_type (void_type_node, + TYPE_ARG_TYPES (TREE_TYPE (decl1))); + } + + if (warn_about_return_type) + warning ("return-type defaults to `int'"); + + /* Save the parm names or decls from this function's declarator + where store_parm_decls will find them. */ + current_function_parms = last_function_parms; + current_function_parm_tags = last_function_parm_tags; + + /* Make the init_value nonzero so pushdecl knows this is not tentative. + error_mark_node is replaced below (in poplevel) with the BLOCK. */ + DECL_INITIAL (decl1) = error_mark_node; + + /* If this definition isn't a prototype and we had a prototype declaration + before, copy the arg type info from that prototype. + But not if what we had before was a builtin function. */ + old_decl = lookup_name_current_level (DECL_NAME (decl1)); + if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE + && !DECL_BUILT_IN (old_decl) + && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) + == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl)))) + && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) + { + TREE_TYPE (decl1) = TREE_TYPE (old_decl); + current_function_prototype_file = DECL_SOURCE_FILE (old_decl); + current_function_prototype_line = DECL_SOURCE_LINE (old_decl); + } + + /* If there is no explicit declaration, look for any out-of-scope implicit + declarations. */ + if (old_decl == 0) + old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)); + + /* Optionally warn of old-fashioned def with no previous prototype. */ + if (warn_strict_prototypes + && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 + && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)) + warning ("function declaration isn't a prototype"); + /* Optionally warn of any global def with no previous prototype. */ + else if (warn_missing_prototypes + && TREE_PUBLIC (decl1) + && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0) + && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1)))) + warning_with_decl (decl1, "no previous prototype for `%s'"); + /* Optionally warn of any def with no previous prototype + if the function has already been used. */ + else if (warn_missing_prototypes + && old_decl != 0 && TREE_USED (old_decl) + && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) + warning_with_decl (decl1, + "`%s' was used with no prototype before its definition"); + /* Optionally warn of any global def with no previous declaration. */ + else if (warn_missing_declarations + && TREE_PUBLIC (decl1) + && old_decl == 0 + && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1)))) + warning_with_decl (decl1, "no previous declaration for `%s'"); + /* Optionally warn of any def with no previous declaration + if the function has already been used. */ + else if (warn_missing_declarations + && old_decl != 0 && TREE_USED (old_decl) + && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))) + warning_with_decl (decl1, + "`%s' was used with no declaration before its definition"); + + /* This is a definition, not a reference. + So normally clear DECL_EXTERNAL. + However, `extern inline' acts like a declaration + except for defining how to inline. So set DECL_EXTERNAL in that case. */ + DECL_EXTERNAL (decl1) = current_extern_inline; + + /* This function exists in static storage. + (This does not mean `static' in the C sense!) */ + TREE_STATIC (decl1) = 1; + + /* A nested function is not global. */ + if (current_function_decl != 0) + TREE_PUBLIC (decl1) = 0; + + /* Record the decl so that the function name is defined. + If we already have a decl for this name, and it is a FUNCTION_DECL, + use the old decl. */ + + current_function_decl = pushdecl (decl1); + + pushlevel (0); + declare_parm_level (1); + current_binding_level->subblocks_tag_transparent = 1; + + make_function_rtl (current_function_decl); + + restype = TREE_TYPE (TREE_TYPE (current_function_decl)); + /* Promote the value to int before returning it. */ + if (C_PROMOTING_INTEGER_TYPE_P (restype)) + { + /* It retains unsignedness if traditional + or if not really getting wider. */ + if (TREE_UNSIGNED (restype) + && (flag_traditional + || (TYPE_PRECISION (restype) + == TYPE_PRECISION (integer_type_node)))) + restype = unsigned_type_node; + else + restype = integer_type_node; + } + DECL_RESULT (current_function_decl) + = build_decl (RESULT_DECL, NULL_TREE, restype); + + if (!nested) + /* Allocate further tree nodes temporarily during compilation + of this function only. */ + temporary_allocation (); + + /* If this fcn was already referenced via a block-scope `extern' decl + (or an implicit decl), propagate certain information about the usage. */ + if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl))) + TREE_ADDRESSABLE (current_function_decl) = 1; + + immediate_size_expand = old_immediate_size_expand; + + return 1; +} + +/* Record that this function is going to be a varargs function. + This is called before store_parm_decls, which is too early + to call mark_varargs directly. */ + +void +c_mark_varargs () +{ + c_function_varargs = 1; +} + +/* Store the parameter declarations into the current function declaration. + This is called after parsing the parameter declarations, before + digesting the body of the function. + + For an old-style definition, modify the function's type + to specify at least the number of arguments. */ + +void +store_parm_decls () +{ + register tree fndecl = current_function_decl; + register tree parm; + + /* This is either a chain of PARM_DECLs (if a prototype was used) + or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */ + tree specparms = current_function_parms; + + /* This is a list of types declared among parms in a prototype. */ + tree parmtags = current_function_parm_tags; + + /* This is a chain of PARM_DECLs from old-style parm declarations. */ + register tree parmdecls = getdecls (); + + /* This is a chain of any other decls that came in among the parm + declarations. If a parm is declared with enum {foo, bar} x; + then CONST_DECLs for foo and bar are put here. */ + tree nonparms = 0; + + /* Nonzero if this definition is written with a prototype. */ + int prototype = 0; + + if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST) + { + /* This case is when the function was defined with an ANSI prototype. + The parms already have decls, so we need not do anything here + except record them as in effect + and complain if any redundant old-style parm decls were written. */ + + register tree next; + tree others = 0; + + prototype = 1; + + if (parmdecls != 0) + { + tree decl, link; + + error_with_decl (fndecl, + "parm types given both in parmlist and separately"); + /* Get rid of the erroneous decls; don't keep them on + the list of parms, since they might not be PARM_DECLs. */ + for (decl = current_binding_level->names; + decl; decl = TREE_CHAIN (decl)) + if (DECL_NAME (decl)) + IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0; + for (link = current_binding_level->shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + current_binding_level->names = 0; + current_binding_level->shadowed = 0; + } + + specparms = nreverse (specparms); + for (parm = specparms; parm; parm = next) + { + next = TREE_CHAIN (parm); + if (TREE_CODE (parm) == PARM_DECL) + { + if (DECL_NAME (parm) == 0) + error_with_decl (parm, "parameter name omitted"); + else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) + { + error_with_decl (parm, "parameter `%s' declared void"); + /* Change the type to error_mark_node so this parameter + will be ignored by assign_parms. */ + TREE_TYPE (parm) = error_mark_node; + } + pushdecl (parm); + } + else + { + /* If we find an enum constant or a type tag, + put it aside for the moment. */ + TREE_CHAIN (parm) = 0; + others = chainon (others, parm); + } + } + + /* Get the decls in their original chain order + and record in the function. */ + DECL_ARGUMENTS (fndecl) = getdecls (); + +#if 0 + /* If this function takes a variable number of arguments, + add a phony parameter to the end of the parm list, + to represent the position of the first unnamed argument. */ + if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))) + != void_type_node) + { + tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node); + /* Let's hope the address of the unnamed parm + won't depend on its type. */ + TREE_TYPE (dummy) = integer_type_node; + DECL_ARG_TYPE (dummy) = integer_type_node; + DECL_ARGUMENTS (fndecl) + = chainon (DECL_ARGUMENTS (fndecl), dummy); + } +#endif + + /* Now pushdecl the enum constants. */ + for (parm = others; parm; parm = next) + { + next = TREE_CHAIN (parm); + if (DECL_NAME (parm) == 0) + ; + else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) + ; + else if (TREE_CODE (parm) != PARM_DECL) + pushdecl (parm); + } + + storetags (chainon (parmtags, gettags ())); + } + else + { + /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes + each with a parm name as the TREE_VALUE. + + PARMDECLS is a chain of declarations for parameters. + Warning! It can also contain CONST_DECLs which are not parameters + but are names of enumerators of any enum types + declared among the parameters. + + First match each formal parameter name with its declaration. + Associate decls with the names and store the decls + into the TREE_PURPOSE slots. */ + + for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) + DECL_RESULT (parm) = 0; + + for (parm = specparms; parm; parm = TREE_CHAIN (parm)) + { + register tree tail, found = NULL; + + if (TREE_VALUE (parm) == 0) + { + error_with_decl (fndecl, "parameter name missing from parameter list"); + TREE_PURPOSE (parm) = 0; + continue; + } + + /* See if any of the parmdecls specifies this parm by name. + Ignore any enumerator decls. */ + for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) + if (DECL_NAME (tail) == TREE_VALUE (parm) + && TREE_CODE (tail) == PARM_DECL) + { + found = tail; + break; + } + + /* If declaration already marked, we have a duplicate name. + Complain, and don't use this decl twice. */ + if (found && DECL_RESULT (found) != 0) + { + error_with_decl (found, "multiple parameters named `%s'"); + found = 0; + } + + /* If the declaration says "void", complain and ignore it. */ + if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node) + { + error_with_decl (found, "parameter `%s' declared void"); + TREE_TYPE (found) = integer_type_node; + DECL_ARG_TYPE (found) = integer_type_node; + layout_decl (found, 0); + } + + /* Traditionally, a parm declared float is actually a double. */ + if (found && flag_traditional + && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) + { + TREE_TYPE (found) = double_type_node; + DECL_ARG_TYPE (found) = double_type_node; + layout_decl (found, 0); + } + + /* If no declaration found, default to int. */ + if (!found) + { + found = build_decl (PARM_DECL, TREE_VALUE (parm), + integer_type_node); + DECL_ARG_TYPE (found) = TREE_TYPE (found); + DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); + DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); + if (extra_warnings) + warning_with_decl (found, "type of `%s' defaults to `int'"); + pushdecl (found); + } + + TREE_PURPOSE (parm) = found; + + /* Mark this decl as "already found" -- see test, above. + It is safe to use DECL_RESULT for this + since it is not used in PARM_DECLs or CONST_DECLs. */ + DECL_RESULT (found) = error_mark_node; + } + + /* Put anything which is on the parmdecls chain and which is + not a PARM_DECL onto the list NONPARMS. (The types of + non-parm things which might appear on the list include + enumerators and NULL-named TYPE_DECL nodes.) Complain about + any actual PARM_DECLs not matched with any names. */ + + nonparms = 0; + for (parm = parmdecls; parm; ) + { + tree next = TREE_CHAIN (parm); + TREE_CHAIN (parm) = 0; + + if (TREE_CODE (parm) != PARM_DECL) + nonparms = chainon (nonparms, parm); + else + { + /* Complain about args with incomplete types. */ + if (TYPE_SIZE (TREE_TYPE (parm)) == 0) + { + error_with_decl (parm, "parameter `%s' has incomplete type"); + TREE_TYPE (parm) = error_mark_node; + } + + if (DECL_RESULT (parm) == 0) + { + error_with_decl (parm, + "declaration for parameter `%s' but no such parameter"); + /* Pretend the parameter was not missing. + This gets us to a standard state and minimizes + further error messages. */ + specparms + = chainon (specparms, + tree_cons (parm, NULL_TREE, NULL_TREE)); + } + } + + parm = next; + } + + /* Chain the declarations together in the order of the list of names. */ + /* Store that chain in the function decl, replacing the list of names. */ + parm = specparms; + DECL_ARGUMENTS (fndecl) = 0; + { + register tree last; + for (last = 0; parm; parm = TREE_CHAIN (parm)) + if (TREE_PURPOSE (parm)) + { + if (last == 0) + DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm); + else + TREE_CHAIN (last) = TREE_PURPOSE (parm); + last = TREE_PURPOSE (parm); + TREE_CHAIN (last) = 0; + } + } + + /* If there was a previous prototype, + set the DECL_ARG_TYPE of each argument according to + the type previously specified, and report any mismatches. */ + + if (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) + { + register tree type; + for (parm = DECL_ARGUMENTS (fndecl), + type = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) + != void_type_node)); + parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) + { + if (parm == 0 || type == 0 + || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) + { + error ("number of arguments doesn't match prototype"); + error_with_file_and_line (current_function_prototype_file, + current_function_prototype_line, + "prototype declaration"); + break; + } + /* Type for passing arg must be consistent + with that declared for the arg. */ + if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type))) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) + == TYPE_MAIN_VARIANT (TREE_VALUE (type))) + { + /* Adjust argument to match prototype. E.g. a previous + `int foo(float);' prototype causes + `int foo(x) float x; {...}' to be treated like + `int foo(float x) {...}'. This is particularly + useful for argument types like uid_t. */ + DECL_ARG_TYPE (parm) = TREE_TYPE (parm); +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE) + && TYPE_PRECISION (TREE_TYPE (parm)) + < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (parm) = integer_type_node; +#endif + if (pedantic) + { + pedwarn ("promoted argument `%s' doesn't match prototype", + IDENTIFIER_POINTER (DECL_NAME (parm))); + warning_with_file_and_line + (current_function_prototype_file, + current_function_prototype_line, + "prototype declaration"); + } + } + /* If -traditional, allow `int' argument to match + `unsigned' prototype. */ + else if (! (flag_traditional + && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node + && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)) + { + error ("argument `%s' doesn't match prototype", + IDENTIFIER_POINTER (DECL_NAME (parm))); + error_with_file_and_line (current_function_prototype_file, + current_function_prototype_line, + "prototype declaration"); + } + } + } + TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; + } + + /* Otherwise, create a prototype that would match. */ + + else + { + tree actual = 0, last = 0, type; + + for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) + { + type = perm_tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), + NULL_TREE); + if (last) + TREE_CHAIN (last) = type; + else + actual = type; + last = type; + } + type = perm_tree_cons (NULL_TREE, void_type_node, NULL_TREE); + if (last) + TREE_CHAIN (last) = type; + else + actual = type; + + /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES + of the type of this function, but we need to avoid having this + affect the types of other similarly-typed functions, so we must + first force the generation of an identical (but separate) type + node for the relevant function type. The new node we create + will be a variant of the main variant of the original function + type. */ + + TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl)); + + TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual; + } + + /* Now store the final chain of decls for the arguments + as the decl-chain of the current lexical scope. + Put the enumerators in as well, at the front so that + DECL_ARGUMENTS is not modified. */ + + storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); + } + + /* Make sure the binding level for the top of the function body + gets a BLOCK if there are any in the function. + Otherwise, the dbx output is wrong. */ + + keep_next_if_subblocks = 1; + + /* ??? This might be an improvement, + but needs to be thought about some more. */ +#if 0 + keep_next_level_flag = 1; +#endif + + /* Write a record describing this function definition to the prototypes + file (if requested). */ + + gen_aux_info_record (fndecl, 1, 0, prototype); + + /* Initialize the RTL code for the function. */ + + init_function_start (fndecl, input_filename, lineno); + + /* If this is a varargs function, inform function.c. */ + + if (c_function_varargs) + mark_varargs (); + + /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ + + declare_function_name (); + + /* Set up parameters and prepare for return, for the function. */ + + expand_function_start (fndecl, 0); + + /* If this function is `main', emit a call to `__main' + to run global initializers, etc. */ + if (DECL_NAME (fndecl) + && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 + && DECL_CONTEXT (fndecl) == NULL_TREE) + expand_main_function (); +} + +/* SPECPARMS is an identifier list--a chain of TREE_LIST nodes + each with a parm name as the TREE_VALUE. A null pointer as TREE_VALUE + stands for an ellipsis in the identifier list. + + PARMLIST is the data returned by get_parm_info for the + parmlist that follows the semicolon. + + We return a value of the same sort that get_parm_info returns, + except that it describes the combination of identifiers and parmlist. */ + +tree +combine_parm_decls (specparms, parmlist, void_at_end) + tree specparms, parmlist; + int void_at_end; +{ + register tree fndecl = current_function_decl; + register tree parm; + + tree parmdecls = TREE_PURPOSE (parmlist); + + /* This is a chain of any other decls that came in among the parm + declarations. They were separated already by get_parm_info, + so we just need to keep them separate. */ + tree nonparms = TREE_VALUE (parmlist); + + tree types = 0; + + for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) + DECL_RESULT (parm) = 0; + + for (parm = specparms; parm; parm = TREE_CHAIN (parm)) + { + register tree tail, found = NULL; + + /* See if any of the parmdecls specifies this parm by name. */ + for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) + if (DECL_NAME (tail) == TREE_VALUE (parm)) + { + found = tail; + break; + } + + /* If declaration already marked, we have a duplicate name. + Complain, and don't use this decl twice. */ + if (found && DECL_RESULT (found) != 0) + { + error_with_decl (found, "multiple parameters named `%s'"); + found = 0; + } + + /* If the declaration says "void", complain and ignore it. */ + if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node) + { + error_with_decl (found, "parameter `%s' declared void"); + TREE_TYPE (found) = integer_type_node; + DECL_ARG_TYPE (found) = integer_type_node; + layout_decl (found, 0); + } + + /* Traditionally, a parm declared float is actually a double. */ + if (found && flag_traditional + && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) + { + TREE_TYPE (found) = double_type_node; + DECL_ARG_TYPE (found) = double_type_node; + layout_decl (found, 0); + } + + /* If no declaration found, default to int. */ + if (!found) + { + found = build_decl (PARM_DECL, TREE_VALUE (parm), + integer_type_node); + DECL_ARG_TYPE (found) = TREE_TYPE (found); + DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); + DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); + error_with_decl (found, "type of parameter `%s' is not declared"); + pushdecl (found); + } + + TREE_PURPOSE (parm) = found; + + /* Mark this decl as "already found" -- see test, above. + It is safe to use DECL_RESULT for this + since it is not used in PARM_DECLs or CONST_DECLs. */ + DECL_RESULT (found) = error_mark_node; + } + + /* Complain about any actual PARM_DECLs not matched with any names. */ + + for (parm = parmdecls; parm; ) + { + tree next = TREE_CHAIN (parm); + TREE_CHAIN (parm) = 0; + + /* Complain about args with incomplete types. */ + if (TYPE_SIZE (TREE_TYPE (parm)) == 0) + { + error_with_decl (parm, "parameter `%s' has incomplete type"); + TREE_TYPE (parm) = error_mark_node; + } + + if (DECL_RESULT (parm) == 0) + { + error_with_decl (parm, + "declaration for parameter `%s' but no such parameter"); + /* Pretend the parameter was not missing. + This gets us to a standard state and minimizes + further error messages. */ + specparms + = chainon (specparms, + tree_cons (parm, NULL_TREE, NULL_TREE)); + } + + parm = next; + } + + /* Chain the declarations together in the order of the list of names. + At the same time, build up a list of their types, in reverse order. */ + + parm = specparms; + parmdecls = 0; + { + register tree last; + for (last = 0; parm; parm = TREE_CHAIN (parm)) + if (TREE_PURPOSE (parm)) + { + if (last == 0) + parmdecls = TREE_PURPOSE (parm); + else + TREE_CHAIN (last) = TREE_PURPOSE (parm); + last = TREE_PURPOSE (parm); + TREE_CHAIN (last) = 0; + + types = saveable_tree_cons (NULL_TREE, TREE_TYPE (parm), types); + } + } + + if (void_at_end) + return saveable_tree_cons (parmdecls, nonparms, + nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types))); + + return saveable_tree_cons (parmdecls, nonparms, nreverse (types)); +} + +/* Finish up a function declaration and compile that function + all the way to assembler language output. The free the storage + for the function definition. + + This is called after parsing the body of the function definition. + + NESTED is nonzero if the function being finished is nested in another. */ + +void +finish_function (nested) + int nested; +{ + register tree fndecl = current_function_decl; + +/* TREE_READONLY (fndecl) = 1; + This caused &foo to be of type ptr-to-const-function + which then got a warning when stored in a ptr-to-function variable. */ + + poplevel (1, 0, 1); + BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; + + /* Must mark the RESULT_DECL as being in this function. */ + + DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; + + /* Obey `register' declarations if `setjmp' is called in this fn. */ + if (flag_traditional && current_function_calls_setjmp) + { + setjmp_protect (DECL_INITIAL (fndecl)); + setjmp_protect_args (); + } + +#ifdef DEFAULT_MAIN_RETURN + if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) + != integer_type_node) + warning_with_decl (fndecl, "return type of `%s' is not `int'"); + else + { + /* Make it so that `main' always returns success by default. */ + DEFAULT_MAIN_RETURN; + } + } +#endif + + /* Generate rtl for function exit. */ + expand_function_end (input_filename, lineno, 0); + + /* So we can tell if jump_optimize sets it to 1. */ + can_reach_end = 0; + + /* Run the optimizers and output the assembler code for this function. */ + rest_of_compilation (fndecl); + + current_function_returns_null |= can_reach_end; + + if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) + warning ("`noreturn' function does return"); + else if (warn_return_type && can_reach_end + && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node) + /* If this function returns non-void and control can drop through, + complain. */ + warning ("control reaches end of non-void function"); + /* With just -W, complain only if function returns both with + and without a value. */ + else if (extra_warnings + && current_function_returns_value && current_function_returns_null) + warning ("this function may return with or without a value"); + + /* If requested, warn about function definitions where the function will + return a value (usually of some struct or union type) which itself will + take up a lot of stack space. */ + + if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl)) + { + register tree ret_type = TREE_TYPE (TREE_TYPE (fndecl)); + + if (ret_type) + { + register tree ret_type_size = TYPE_SIZE (ret_type); + + if (TREE_CODE (ret_type_size) == INTEGER_CST) + { + unsigned units + = TREE_INT_CST_LOW (ret_type_size) / BITS_PER_UNIT; + + if (units > larger_than_size) + warning_with_decl (fndecl, + "size of return value of `%s' is %u bytes", + units); + } + } + } + + /* Free all the tree nodes making up this function. */ + /* Switch back to allocating nodes permanently + until we start another function. */ + if (! nested) + permanent_allocation (1); + + if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested) + { + /* Stop pointing to the local nodes about to be freed. */ + /* But DECL_INITIAL must remain nonzero so we know this + was an actual function definition. */ + /* For a nested function, this is done in pop_c_function_context. */ + /* If rest_of_compilation set this to 0, leave it 0. */ + if (DECL_INITIAL (fndecl) != 0) + DECL_INITIAL (fndecl) = error_mark_node; + DECL_ARGUMENTS (fndecl) = 0; + } + + if (DECL_STATIC_CONSTRUCTOR (fndecl)) + { +#ifndef ASM_OUTPUT_CONSTRUCTOR + if (! flag_gnu_linker) + static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); + else +#endif + assemble_constructor (IDENTIFIER_POINTER (DECL_NAME (fndecl))); + } + if (DECL_STATIC_DESTRUCTOR (fndecl)) + { +#ifndef ASM_OUTPUT_DESTRUCTOR + if (! flag_gnu_linker) + static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); + else +#endif + assemble_destructor (IDENTIFIER_POINTER (DECL_NAME (fndecl))); + } + + if (! nested) + { + /* Let the error reporting routines know that we're outside a + function. For a nested function, this value is used in + pop_c_function_context and then reset via pop_function_context. */ + current_function_decl = NULL; + } +} + +/* Save and restore the variables in this file and elsewhere + that keep track of the progress of compilation of the current function. + Used for nested functions. */ + +struct c_function +{ + struct c_function *next; + tree named_labels; + tree shadowed_labels; + int returns_value; + int returns_null; + int warn_about_return_type; + int extern_inline; + struct binding_level *binding_level; +}; + +struct c_function *c_function_chain; + +/* Save and reinitialize the variables + used during compilation of a C function. */ + +void +push_c_function_context () +{ + struct c_function *p + = (struct c_function *) xmalloc (sizeof (struct c_function)); + + if (pedantic) + pedwarn ("ANSI C forbids nested functions"); + + push_function_context (); + + p->next = c_function_chain; + c_function_chain = p; + + p->named_labels = named_labels; + p->shadowed_labels = shadowed_labels; + p->returns_value = current_function_returns_value; + p->returns_null = current_function_returns_null; + p->warn_about_return_type = warn_about_return_type; + p->extern_inline = current_extern_inline; + p->binding_level = current_binding_level; +} + +/* Restore the variables used during compilation of a C function. */ + +void +pop_c_function_context () +{ + struct c_function *p = c_function_chain; + tree link; + + /* Bring back all the labels that were shadowed. */ + for (link = shadowed_labels; link; link = TREE_CHAIN (link)) + if (DECL_NAME (TREE_VALUE (link)) != 0) + IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) + = TREE_VALUE (link); + + if (DECL_SAVED_INSNS (current_function_decl) == 0) + { + /* Stop pointing to the local nodes about to be freed. */ + /* But DECL_INITIAL must remain nonzero so we know this + was an actual function definition. */ + DECL_INITIAL (current_function_decl) = error_mark_node; + DECL_ARGUMENTS (current_function_decl) = 0; + } + + pop_function_context (); + + c_function_chain = p->next; + + named_labels = p->named_labels; + shadowed_labels = p->shadowed_labels; + current_function_returns_value = p->returns_value; + current_function_returns_null = p->returns_null; + warn_about_return_type = p->warn_about_return_type; + current_extern_inline = p->extern_inline; + current_binding_level = p->binding_level; + + free (p); +} + +/* integrate_decl_tree calls this function, but since we don't use the + DECL_LANG_SPECIFIC field, this is a no-op. */ + +void +copy_lang_decl (node) + tree node; +{ +} diff --git a/contrib/gcc/c-iterate.c b/contrib/gcc/c-iterate.c new file mode 100644 index 00000000000..b35a167a46c --- /dev/null +++ b/contrib/gcc/c-iterate.c @@ -0,0 +1,596 @@ +/* Build expressions with type checking for C compiler. + Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is part of the C front end. + It is responsible for implementing iterators, + both their declarations and the expansion of statements using them. */ + +#include "config.h" +#include +#include "tree.h" +#include "c-tree.h" +#include "flags.h" +#include "obstack.h" +#include "rtl.h" + +static void expand_stmt_with_iterators_1 (); +static tree collect_iterators (); +static void iterator_loop_prologue (); +static void iterator_loop_epilogue (); +static void add_ixpansion (); +static void delete_ixpansion(); +static int top_level_ixpansion_p (); +static void istack_sublevel_to_current (); + +/* A special obstack, and a pointer to the start of + all the data in it (so we can free everything easily). */ +static struct obstack ixp_obstack; +static char *ixp_firstobj; + +/* + KEEPING TRACK OF EXPANSIONS + + In order to clean out expansions corresponding to statements inside + "{(...)}" constructs we have to keep track of all expansions. The + cleanup is needed when an automatic, or implicit, expansion on + iterator, say X, happens to a statement which contains a {(...)} + form with a statement already expanded on X. In this case we have + to go back and cleanup the inner expansion. This can be further + complicated by the fact that {(...)} can be nested. + + To make this cleanup possible, we keep lists of all expansions, and + to make it work for nested constructs, we keep a stack. The list at + the top of the stack (ITER_STACK.CURRENT_LEVEL) corresponds to the + currently parsed level. All expansions of the levels below the + current one are kept in one list whose head is pointed to by + ITER_STACK.SUBLEVEL_FIRST (SUBLEVEL_LAST is there for making merges + easy). The process works as follows: + + -- On "({" a new node is added to the stack by PUSH_ITERATOR_STACK. + The sublevel list is not changed at this point. + + -- On "})" the list for the current level is appended to the sublevel + list. + + -- On ";" sublevel lists are appended to the current level lists. + The reason is this: if they have not been superseded by the + expansion at the current level, they still might be + superseded later by the expansion on the higher level. + The levels do not have to distinguish levels below, so we + can merge the lists together. */ + +struct ixpansion +{ + tree ixdecl; /* Iterator decl */ + rtx ixprologue_start; /* First insn of epilogue. NULL means */ + /* explicit (FOR) expansion*/ + rtx ixprologue_end; + rtx ixepilogue_start; + rtx ixepilogue_end; + struct ixpansion *next; /* Next in the list */ +}; + +struct iter_stack_node +{ + struct ixpansion *first; /* Head of list of ixpansions */ + struct ixpansion *last; /* Last node in list of ixpansions */ + struct iter_stack_node *next; /* Next level iterator stack node */ +}; + +struct iter_stack_node *iter_stack; + +struct iter_stack_node sublevel_ixpansions; + +/* During collect_iterators, a list of SAVE_EXPRs already scanned. */ +static tree save_exprs; + +/* Initialize our obstack once per compilation. */ + +void +init_iterators () +{ + gcc_obstack_init (&ixp_obstack); + ixp_firstobj = (char *) obstack_alloc (&ixp_obstack, 0); +} + +/* Handle the start of an explicit `for' loop for iterator IDECL. */ + +void +iterator_for_loop_start (idecl) + tree idecl; +{ + ITERATOR_BOUND_P (idecl) = 1; + add_ixpansion (idecl, 0, 0, 0, 0); + iterator_loop_prologue (idecl, 0, 0); +} + +/* Handle the end of an explicit `for' loop for iterator IDECL. */ + +void +iterator_for_loop_end (idecl) + tree idecl; +{ + iterator_loop_epilogue (idecl, 0, 0); + ITERATOR_BOUND_P (idecl) = 0; +} + +/* + ITERATOR RTL EXPANSIONS + + Expanding simple statements with iterators is straightforward: + collect the list of all free iterators in the statement, and + generate a loop for each of them. + + An iterator is "free" if it has not been "bound" by a FOR + operator. The DECL_RTL of the iterator is the loop counter. */ + +/* Expand a statement STMT, possibly containing iterator usage, into RTL. */ + +void +iterator_expand (stmt) + tree stmt; +{ + tree iter_list; + save_exprs = NULL_TREE; + iter_list = collect_iterators (stmt, NULL_TREE); + expand_stmt_with_iterators_1 (stmt, iter_list); + istack_sublevel_to_current (); +} + + +static void +expand_stmt_with_iterators_1 (stmt, iter_list) + tree stmt, iter_list; +{ + if (iter_list == 0) + expand_expr_stmt (stmt); + else + { + tree current_iterator = TREE_VALUE (iter_list); + tree iter_list_tail = TREE_CHAIN (iter_list); + rtx p_start, p_end, e_start, e_end; + + iterator_loop_prologue (current_iterator, &p_start, &p_end); + expand_stmt_with_iterators_1 (stmt, iter_list_tail); + iterator_loop_epilogue (current_iterator, &e_start, &e_end); + + /** Delete all inner expansions based on current_iterator **/ + /** before adding the outer one. **/ + + delete_ixpansion (current_iterator); + add_ixpansion (current_iterator, p_start, p_end, e_start, e_end); + } +} + + +/* Return a list containing all the free (i.e. not bound by a + containing `for' statement) iterators mentioned in EXP, plus those + in LIST. Do not add duplicate entries to the list. */ + +static tree +collect_iterators (exp, list) + tree exp, list; +{ + if (exp == 0) return list; + + switch (TREE_CODE (exp)) + { + case VAR_DECL: + if (! ITERATOR_P (exp) || ITERATOR_BOUND_P (exp)) + return list; + if (value_member (exp, list)) + return list; + return tree_cons (NULL_TREE, exp, list); + + case TREE_LIST: + { + tree tail; + for (tail = exp; tail; tail = TREE_CHAIN (tail)) + list = collect_iterators (TREE_VALUE (tail), list); + return list; + } + + case SAVE_EXPR: + /* In each scan, scan a given save_expr only once. */ + if (value_member (exp, save_exprs)) + return list; + + save_exprs = tree_cons (NULL_TREE, exp, save_exprs); + return collect_iterators (TREE_OPERAND (exp, 0), list); + + /* we do not automatically iterate blocks -- one must */ + /* use the FOR construct to do that */ + + case BLOCK: + return list; + + default: + switch (TREE_CODE_CLASS (TREE_CODE (exp))) + { + case '1': + return collect_iterators (TREE_OPERAND (exp, 0), list); + + case '2': + case '<': + return collect_iterators (TREE_OPERAND (exp, 0), + collect_iterators (TREE_OPERAND (exp, 1), + list)); + + case 'e': + case 'r': + { + int num_args = tree_code_length[(int) TREE_CODE (exp)]; + int i; + + /* Some tree codes have RTL, not trees, as operands. */ + switch (TREE_CODE (exp)) + { + case CALL_EXPR: + num_args = 2; + break; + case METHOD_CALL_EXPR: + num_args = 3; + break; + case WITH_CLEANUP_EXPR: + num_args = 1; + break; + case RTL_EXPR: + return list; + } + + for (i = 0; i < num_args; i++) + list = collect_iterators (TREE_OPERAND (exp, i), list); + return list; + } + default: + return list; + } + } +} + +/* Emit rtl for the start of a loop for iterator IDECL. + + If necessary, create loop counter rtx and store it as DECL_RTL of IDECL. + + The prologue normally starts and ends with notes, which are returned + by this function in *START_NOTE and *END_NODE. + If START_NOTE and END_NODE are 0, we don't make those notes. */ + +static void +iterator_loop_prologue (idecl, start_note, end_note) + tree idecl; + rtx *start_note, *end_note; +{ + tree expr; + + /* Force the save_expr in DECL_INITIAL to be calculated + if it hasn't been calculated yet. */ + expand_expr (DECL_INITIAL (idecl), const0_rtx, VOIDmode, 0); + + if (DECL_RTL (idecl) == 0) + expand_decl (idecl); + + if (start_note) + *start_note = emit_note (0, NOTE_INSN_DELETED); + + /* Initialize counter. */ + expr = build (MODIFY_EXPR, TREE_TYPE (idecl), idecl, integer_zero_node); + TREE_SIDE_EFFECTS (expr) = 1; + expand_expr (expr, const0_rtx, VOIDmode, 0); + + expand_start_loop_continue_elsewhere (1); + + ITERATOR_BOUND_P (idecl) = 1; + + if (end_note) + *end_note = emit_note (0, NOTE_INSN_DELETED); +} + +/* Similar to the previous function, but for the end of the loop. + + DECL_RTL is zeroed unless we are inside "({...})". The reason for that is + described below. + + When we create two (or more) loops based on the same IDECL, and + both inside the same "({...})" construct, we must be prepared to + delete both of the loops and create a single one on the level + above, i.e. enclosing the "({...})". The new loop has to use the + same counter rtl because the references to the iterator decl + (IDECL) have already been expanded as references to the counter + rtl. + + It is incorrect to use the same counter reg in different functions, + and it is desirable to use different counters in disjoint loops + when we know there's no need to combine them (because then they can + get allocated separately). */ + +static void +iterator_loop_epilogue (idecl, start_note, end_note) + tree idecl; + rtx *start_note, *end_note; +{ + tree test, incr; + + if (start_note) + *start_note = emit_note (0, NOTE_INSN_DELETED); + expand_loop_continue_here (); + incr = build_binary_op (PLUS_EXPR, idecl, integer_one_node, 0); + incr = build (MODIFY_EXPR, TREE_TYPE (idecl), idecl, incr); + TREE_SIDE_EFFECTS (incr) = 1; + expand_expr (incr, const0_rtx, VOIDmode, 0); + test = build_binary_op (LT_EXPR, idecl, DECL_INITIAL (idecl), 0); + expand_exit_loop_if_false (0, test); + expand_end_loop (); + + ITERATOR_BOUND_P (idecl) = 0; + /* we can reset rtl since there is not chance that this expansion */ + /* would be superseded by a higher level one */ + if (top_level_ixpansion_p ()) + DECL_RTL (idecl) = 0; + if (end_note) + *end_note = emit_note (0, NOTE_INSN_DELETED); +} + +/* Return true if we are not currently inside a "({...})" construct. */ + +static int +top_level_ixpansion_p () +{ + return iter_stack == 0; +} + +/* Given two chains of iter_stack_nodes, + append the nodes in X into Y. */ + +static void +isn_append (x, y) + struct iter_stack_node *x, *y; +{ + if (x->first == 0) + return; + + if (y->first == 0) + { + y->first = x->first; + y->last = x->last; + } + else + { + y->last->next = x->first; + y->last = x->last; + } +} + +/** Make X empty **/ + +#define ISN_ZERO(X) (X).first=(X).last=0 + +/* Move the ixpansions in sublevel_ixpansions into the current + node on the iter_stack, or discard them if the iter_stack is empty. + We do this at the end of a statement. */ + +static void +istack_sublevel_to_current () +{ + /* At the top level we can throw away sublevel's expansions **/ + /* because there is nobody above us to ask for a cleanup **/ + if (iter_stack != 0) + /** Merging with empty sublevel list is a no-op **/ + if (sublevel_ixpansions.last) + isn_append (&sublevel_ixpansions, iter_stack); + + if (iter_stack == 0) + obstack_free (&ixp_obstack, ixp_firstobj); + + ISN_ZERO (sublevel_ixpansions); +} + +/* Push a new node on the iter_stack, when we enter a ({...}). */ + +void +push_iterator_stack () +{ + struct iter_stack_node *new_top + = (struct iter_stack_node*) + obstack_alloc (&ixp_obstack, sizeof (struct iter_stack_node)); + + new_top->first = 0; + new_top->last = 0; + new_top->next = iter_stack; + iter_stack = new_top; +} + +/* Pop iter_stack, moving the ixpansions in the node being popped + into sublevel_ixpansions. */ + +void +pop_iterator_stack () +{ + if (iter_stack == 0) + abort (); + + isn_append (iter_stack, &sublevel_ixpansions); + /** Pop current level node: */ + iter_stack = iter_stack->next; +} + + +/* Record an iterator expansion ("ixpansion") for IDECL. + The remaining parameters are the notes in the loop entry + and exit rtl. */ + +static void +add_ixpansion (idecl, pro_start, pro_end, epi_start, epi_end) + tree idecl; + rtx pro_start, pro_end, epi_start, epi_end; +{ + struct ixpansion* newix; + + /* Do nothing if we are not inside "({...})", + as in that case this expansion can't need subsequent RTL modification. */ + if (iter_stack == 0) + return; + + newix = (struct ixpansion*) obstack_alloc (&ixp_obstack, + sizeof (struct ixpansion)); + newix->ixdecl = idecl; + newix->ixprologue_start = pro_start; + newix->ixprologue_end = pro_end; + newix->ixepilogue_start = epi_start; + newix->ixepilogue_end = epi_end; + + newix->next = iter_stack->first; + iter_stack->first = newix; + if (iter_stack->last == 0) + iter_stack->last = newix; +} + +/* Delete the RTL for all ixpansions for iterator IDECL + in our sublevels. We do this when we make a larger + containing expansion for IDECL. */ + +static void +delete_ixpansion (idecl) + tree idecl; +{ + struct ixpansion* previx = 0, *ix; + + for (ix = sublevel_ixpansions.first; ix; ix = ix->next) + if (ix->ixdecl == idecl) + { + /** zero means that this is a mark for FOR -- **/ + /** we do not delete anything, just issue an error. **/ + + if (ix->ixprologue_start == 0) + error_with_decl (idecl, + "`for (%s)' appears within implicit iteration"); + else + { + rtx insn; + /* We delete all insns, including notes because leaving loop */ + /* notes and barriers produced by iterator expansion would */ + /* be misleading to other phases */ + + for (insn = NEXT_INSN (ix->ixprologue_start); + insn != ix->ixprologue_end; + insn = NEXT_INSN (insn)) + delete_insn (insn); + for (insn = NEXT_INSN (ix->ixepilogue_start); + insn != ix->ixepilogue_end; + insn = NEXT_INSN (insn)) + delete_insn (insn); + } + + /* Delete this ixpansion from sublevel_ixpansions. */ + if (previx) + previx->next = ix->next; + else + sublevel_ixpansions.first = ix->next; + if (sublevel_ixpansions.last == ix) + sublevel_ixpansions.last = previx; + } + else + previx = ix; +} + +#ifdef DEBUG_ITERATORS + +/* The functions below are for use from source level debugger. + They print short forms of iterator lists and the iterator stack. */ + +/* Print the name of the iterator D. */ + +void +prdecl (d) + tree d; +{ + if (d) + { + if (TREE_CODE (d) == VAR_DECL) + { + tree tname = DECL_NAME (d); + char *dname = IDENTIFIER_POINTER (tname); + fprintf (stderr, dname); + } + else + fprintf (stderr, "<>"); + } + else + fprintf (stderr, "<>"); +} + +/* Print Iterator List -- names only */ + +tree +pil (head) + tree head; +{ + tree current, next; + for (current = head; current; current = next) + { + tree node = TREE_VALUE (current); + prdecl (node); + next = TREE_CHAIN (current); + if (next) fprintf (stderr, ","); + } + fprintf (stderr, "\n"); +} + +/* Print IXpansion List */ + +struct ixpansion * +pixl (head) + struct ixpansion *head; +{ + struct ixpansion *current, *next; + fprintf (stderr, "> "); + if (head == 0) + fprintf (stderr, "(empty)"); + + for (current=head; current; current = next) + { + tree node = current->ixdecl; + prdecl (node); + next = current->next; + if (next) + fprintf (stderr, ","); + } + fprintf (stderr, "\n"); + return head; +} + +/* Print Iterator Stack*/ + +void +pis () +{ + struct iter_stack_node *stack_node; + + fprintf (stderr, "--SubLevel: "); + pixl (sublevel_ixpansions.first); + fprintf (stderr, "--Stack:--\n"); + for (stack_node = iter_stack; + stack_node; + stack_node = stack_node->next) + pixl (stack_node->first); +} + +#endif /* DEBUG_ITERATORS */ diff --git a/contrib/gcc/c-lang.c b/contrib/gcc/c-lang.c new file mode 100644 index 00000000000..ef9f184880d --- /dev/null +++ b/contrib/gcc/c-lang.c @@ -0,0 +1,180 @@ +/* Language-specific hook definitions for C front end. + Copyright (C) 1991, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "tree.h" +#include +#include "input.h" + +/* Each of the functions defined here + is an alternative to a function in objc-actions.c. */ + +int +lang_decode_option (p) + char *p; +{ + return c_decode_option (p); +} + +void +lang_init () +{ + /* the beginning of the file is a new line; check for # */ + /* With luck, we discover the real source file's name from that + and put it in input_filename. */ + ungetc (check_newline (), finput); +} + +void +lang_finish () +{ +} + +char * +lang_identify () +{ + return "c"; +} + +void +print_lang_statistics () +{ +} + +/* Used by c-lex.c, but only for objc. */ + +tree +lookup_interface (arg) + tree arg; +{ + return 0; +} + +tree +is_class_name (arg) + tree arg; +{ + return 0; +} + +void +maybe_objc_check_decl (decl) + tree decl; +{ +} + +int +maybe_objc_comptypes (lhs, rhs, reflexive) + tree lhs, rhs; + int reflexive; +{ + return -1; +} + +tree +maybe_objc_method_name (decl) + tree decl; +{ + return 0; +} + +tree +maybe_building_objc_message_expr () +{ + return 0; +} + +int +recognize_objc_keyword () +{ + return 0; +} + +tree +build_objc_string (len, str) + int len; + char *str; +{ + abort (); + return NULL_TREE; +} + +void +GNU_xref_begin () +{ + fatal ("GCC does not yet support XREF"); +} + +void +GNU_xref_end () +{ + fatal ("GCC does not yet support XREF"); +} + +/* called at end of parsing, but before end-of-file processing. */ +void +finish_file () +{ + extern tree static_ctors, static_dtors; + extern tree get_file_function_name (); + extern tree build_function_call PROTO((tree, tree)); + tree void_list_node = build_tree_list (NULL_TREE, void_type_node); +#ifndef ASM_OUTPUT_CONSTRUCTOR + if (static_ctors) + { + tree fnname = get_file_function_name ('I'); + start_function (void_list_node, + build_parse_node (CALL_EXPR, fnname, void_list_node, + NULL_TREE), + NULL_TREE, NULL_TREE, 0); + fnname = DECL_ASSEMBLER_NAME (current_function_decl); + store_parm_decls (); + + for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors)) + expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors), + NULL_TREE)); + + finish_function (0); + + assemble_constructor (IDENTIFIER_POINTER (fnname)); + } +#endif +#ifndef ASM_OUTPUT_DESTRUCTOR + if (static_dtors) + { + tree fnname = get_file_function_name ('D'); + start_function (void_list_node, + build_parse_node (CALL_EXPR, fnname, void_list_node, + NULL_TREE), + NULL_TREE, NULL_TREE, 0); + fnname = DECL_ASSEMBLER_NAME (current_function_decl); + store_parm_decls (); + + for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors)) + expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors), + NULL_TREE)); + + finish_function (0); + + assemble_destructor (IDENTIFIER_POINTER (fnname)); + } +#endif +} diff --git a/contrib/gcc/c-lex.c b/contrib/gcc/c-lex.c new file mode 100644 index 00000000000..007b3634384 --- /dev/null +++ b/contrib/gcc/c-lex.c @@ -0,0 +1,2021 @@ +/* Lexical analyzer for C and Objective C. + Copyright (C) 1987, 88, 89, 92, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include +#include +#include + +#include "config.h" +#include "rtl.h" +#include "tree.h" +#include "input.h" +#include "c-lex.h" +#include "c-tree.h" +#include "flags.h" +#include "c-parse.h" +#include "c-pragma.h" + +#include + +#ifdef MULTIBYTE_CHARS +#include +#include +#endif + +#ifndef errno +extern int errno; +#endif + +/* The elements of `ridpointers' are identifier nodes + for the reserved type names and storage classes. + It is indexed by a RID_... value. */ +tree ridpointers[(int) RID_MAX]; + +/* Cause the `yydebug' variable to be defined. */ +#define YYDEBUG 1 + +/* the declaration found for the last IDENTIFIER token read in. + yylex must look this up to detect typedefs, which get token type TYPENAME, + so it is left around in case the identifier is not a typedef but is + used in a context which makes it a reference to a variable. */ +tree lastiddecl; + +/* Nonzero enables objc features. */ + +int doing_objc_thang; + +extern tree is_class_name (); + +extern int yydebug; + +/* File used for outputting assembler code. */ +extern FILE *asm_out_file; + +#ifndef WCHAR_TYPE_SIZE +#ifdef INT_TYPE_SIZE +#define WCHAR_TYPE_SIZE INT_TYPE_SIZE +#else +#define WCHAR_TYPE_SIZE BITS_PER_WORD +#endif +#endif + +/* Number of bytes in a wide character. */ +#define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) + +static int maxtoken; /* Current nominal length of token buffer. */ +char *token_buffer; /* Pointer to token buffer. + Actual allocated length is maxtoken + 2. + This is not static because objc-parse.y uses it. */ + +/* Nonzero if end-of-file has been seen on input. */ +static int end_of_file; + +/* Buffered-back input character; faster than using ungetc. */ +static int nextchar = -1; + +int check_newline (); + +/* Do not insert generated code into the source, instead, include it. + This allows us to build gcc automatically even for targets that + need to add or modify the reserved keyword lists. */ +#include "c-gperf.h" + +/* Return something to represent absolute declarators containing a *. + TARGET is the absolute declarator that the * contains. + TYPE_QUALS is a list of modifiers such as const or volatile + to apply to the pointer type, represented as identifiers. + + We return an INDIRECT_REF whose "contents" are TARGET + and whose type is the modifier list. */ + +tree +make_pointer_declarator (type_quals, target) + tree type_quals, target; +{ + return build1 (INDIRECT_REF, type_quals, target); +} + +void +forget_protocol_qualifiers () +{ + int i, n = sizeof wordlist / sizeof (struct resword); + + for (i = 0; i < n; i++) + if ((int) wordlist[i].rid >= (int) RID_IN + && (int) wordlist[i].rid <= (int) RID_ONEWAY) + wordlist[i].name = ""; +} + +void +remember_protocol_qualifiers () +{ + int i, n = sizeof wordlist / sizeof (struct resword); + + for (i = 0; i < n; i++) + if (wordlist[i].rid == RID_IN) + wordlist[i].name = "in"; + else if (wordlist[i].rid == RID_OUT) + wordlist[i].name = "out"; + else if (wordlist[i].rid == RID_INOUT) + wordlist[i].name = "inout"; + else if (wordlist[i].rid == RID_BYCOPY) + wordlist[i].name = "bycopy"; + else if (wordlist[i].rid == RID_ONEWAY) + wordlist[i].name = "oneway"; +} + +void +init_lex () +{ + /* Make identifier nodes long enough for the language-specific slots. */ + set_identifier_size (sizeof (struct lang_identifier)); + + /* Start it at 0, because check_newline is called at the very beginning + and will increment it to 1. */ + lineno = 0; + +#ifdef MULTIBYTE_CHARS + /* Change to the native locale for multibyte conversions. */ + setlocale (LC_CTYPE, ""); +#endif + + maxtoken = 40; + token_buffer = (char *) xmalloc (maxtoken + 2); + + ridpointers[(int) RID_INT] = get_identifier ("int"); + ridpointers[(int) RID_CHAR] = get_identifier ("char"); + ridpointers[(int) RID_VOID] = get_identifier ("void"); + ridpointers[(int) RID_FLOAT] = get_identifier ("float"); + ridpointers[(int) RID_DOUBLE] = get_identifier ("double"); + ridpointers[(int) RID_SHORT] = get_identifier ("short"); + ridpointers[(int) RID_LONG] = get_identifier ("long"); + ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned"); + ridpointers[(int) RID_SIGNED] = get_identifier ("signed"); + ridpointers[(int) RID_INLINE] = get_identifier ("inline"); + ridpointers[(int) RID_CONST] = get_identifier ("const"); + ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); + ridpointers[(int) RID_AUTO] = get_identifier ("auto"); + ridpointers[(int) RID_STATIC] = get_identifier ("static"); + ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); + ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); + ridpointers[(int) RID_REGISTER] = get_identifier ("register"); + ridpointers[(int) RID_ITERATOR] = get_identifier ("iterator"); + ridpointers[(int) RID_COMPLEX] = get_identifier ("complex"); + ridpointers[(int) RID_ID] = get_identifier ("id"); + ridpointers[(int) RID_IN] = get_identifier ("in"); + ridpointers[(int) RID_OUT] = get_identifier ("out"); + ridpointers[(int) RID_INOUT] = get_identifier ("inout"); + ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy"); + ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway"); + forget_protocol_qualifiers(); + + /* Some options inhibit certain reserved words. + Clear those words out of the hash table so they won't be recognized. */ +#define UNSET_RESERVED_WORD(STRING) \ + do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ + if (s) s->name = ""; } while (0) + + if (! doing_objc_thang) + UNSET_RESERVED_WORD ("id"); + + if (flag_traditional) + { + UNSET_RESERVED_WORD ("const"); + UNSET_RESERVED_WORD ("volatile"); + UNSET_RESERVED_WORD ("typeof"); + UNSET_RESERVED_WORD ("signed"); + UNSET_RESERVED_WORD ("inline"); + UNSET_RESERVED_WORD ("iterator"); + UNSET_RESERVED_WORD ("complex"); + } + if (flag_no_asm) + { + UNSET_RESERVED_WORD ("asm"); + UNSET_RESERVED_WORD ("typeof"); + UNSET_RESERVED_WORD ("inline"); + UNSET_RESERVED_WORD ("iterator"); + UNSET_RESERVED_WORD ("complex"); + } +} + +void +reinit_parse_for_function () +{ +} + +/* Function used when yydebug is set, to print a token in more detail. */ + +void +yyprint (file, yychar, yylval) + FILE *file; + int yychar; + YYSTYPE yylval; +{ + tree t; + switch (yychar) + { + case IDENTIFIER: + case TYPENAME: + case OBJECTNAME: + t = yylval.ttype; + if (IDENTIFIER_POINTER (t)) + fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); + break; + + case CONSTANT: + t = yylval.ttype; + if (TREE_CODE (t) == INTEGER_CST) + fprintf (file, +#if HOST_BITS_PER_WIDE_INT == 64 +#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT + " 0x%lx%016lx", +#else + " 0x%x%016x", +#endif +#else +#if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT + " 0x%lx%08lx", +#else + " 0x%x%08x", +#endif +#endif + TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t)); + break; + } +} + + +/* If C is not whitespace, return C. + Otherwise skip whitespace and return first nonwhite char read. */ + +static int +skip_white_space (c) + register int c; +{ + static int newline_warning = 0; + + for (;;) + { + switch (c) + { + /* We don't recognize comments here, because + cpp output can include / and * consecutively as operators. + Also, there's no need, since cpp removes all comments. */ + + case '\n': + c = check_newline (); + break; + + case ' ': + case '\t': + case '\f': + case '\v': + case '\b': + c = getc (finput); + break; + + case '\r': + /* ANSI C says the effects of a carriage return in a source file + are undefined. */ + if (pedantic && !newline_warning) + { + warning ("carriage return in source file"); + warning ("(we only warn about the first carriage return)"); + newline_warning = 1; + } + c = getc (finput); + break; + + case '\\': + c = getc (finput); + if (c == '\n') + lineno++; + else + error ("stray '\\' in program"); + c = getc (finput); + break; + + default: + return (c); + } + } +} + +/* Skips all of the white space at the current location in the input file. + Must use and reset nextchar if it has the next character. */ + +void +position_after_white_space () +{ + register int c; + + if (nextchar != -1) + c = nextchar, nextchar = -1; + else + c = getc (finput); + + ungetc (skip_white_space (c), finput); +} + +/* Make the token buffer longer, preserving the data in it. + P should point to just beyond the last valid character in the old buffer. + The value we return is a pointer to the new buffer + at a place corresponding to P. */ + +static char * +extend_token_buffer (p) + char *p; +{ + int offset = p - token_buffer; + + maxtoken = maxtoken * 2 + 10; + token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); + + return token_buffer + offset; +} + +/* At the beginning of a line, increment the line number + and process any #-directive on this line. + If the line is a #-directive, read the entire line and return a newline. + Otherwise, return the line's first non-whitespace character. */ + +int +check_newline () +{ + register int c; + register int token; + + lineno++; + + /* Read first nonwhite char on the line. */ + + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + + if (c != '#') + { + /* If not #, return it so caller will use it. */ + return c; + } + + /* Read first nonwhite char after the `#'. */ + + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + + /* If a letter follows, then if the word here is `line', skip + it and ignore it; otherwise, ignore the line, with an error + if the word isn't `pragma', `ident', `define', or `undef'. */ + + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + { + if (c == 'p') + { + if (getc (finput) == 'r' + && getc (finput) == 'a' + && getc (finput) == 'g' + && getc (finput) == 'm' + && getc (finput) == 'a' + && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) + { +#ifdef HANDLE_SYSV_PRAGMA + return handle_sysv_pragma (finput, c); +#else /* !HANDLE_SYSV_PRAGMA */ +#ifdef HANDLE_PRAGMA + HANDLE_PRAGMA (finput); +#endif /* HANDLE_PRAGMA */ + goto skipline; +#endif /* !HANDLE_SYSV_PRAGMA */ + } + } + + else if (c == 'd') + { + if (getc (finput) == 'e' + && getc (finput) == 'f' + && getc (finput) == 'i' + && getc (finput) == 'n' + && getc (finput) == 'e' + && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) + { +#ifdef DWARF_DEBUGGING_INFO + if ((debug_info_level == DINFO_LEVEL_VERBOSE) + && (write_symbols == DWARF_DEBUG)) + dwarfout_define (lineno, get_directive_line (finput)); +#endif /* DWARF_DEBUGGING_INFO */ + goto skipline; + } + } + else if (c == 'u') + { + if (getc (finput) == 'n' + && getc (finput) == 'd' + && getc (finput) == 'e' + && getc (finput) == 'f' + && ((c = getc (finput)) == ' ' || c == '\t' || c == '\n')) + { +#ifdef DWARF_DEBUGGING_INFO + if ((debug_info_level == DINFO_LEVEL_VERBOSE) + && (write_symbols == DWARF_DEBUG)) + dwarfout_undef (lineno, get_directive_line (finput)); +#endif /* DWARF_DEBUGGING_INFO */ + goto skipline; + } + } + else if (c == 'l') + { + if (getc (finput) == 'i' + && getc (finput) == 'n' + && getc (finput) == 'e' + && ((c = getc (finput)) == ' ' || c == '\t')) + goto linenum; + } + else if (c == 'i') + { + if (getc (finput) == 'd' + && getc (finput) == 'e' + && getc (finput) == 'n' + && getc (finput) == 't' + && ((c = getc (finput)) == ' ' || c == '\t')) + { + /* #ident. The pedantic warning is now in cccp.c. */ + + /* Here we have just seen `#ident '. + A string constant should follow. */ + + while (c == ' ' || c == '\t') + c = getc (finput); + + /* If no argument, ignore the line. */ + if (c == '\n') + return c; + + ungetc (c, finput); + token = yylex (); + if (token != STRING + || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #ident"); + goto skipline; + } + + if (!flag_no_ident) + { +#ifdef ASM_OUTPUT_IDENT + ASM_OUTPUT_IDENT (asm_out_file, TREE_STRING_POINTER (yylval.ttype)); +#endif + } + + /* Skip the rest of this line. */ + goto skipline; + } + } + + error ("undefined or invalid # directive"); + goto skipline; + } + +linenum: + /* Here we have either `#line' or `# '. + In either case, it should be a line number; a digit should follow. */ + + while (c == ' ' || c == '\t') + c = getc (finput); + + /* If the # is the only nonwhite char on the line, + just ignore it. Check the new newline. */ + if (c == '\n') + return c; + + /* Something follows the #; read a token. */ + + ungetc (c, finput); + token = yylex (); + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST) + { + int old_lineno = lineno; + int used_up = 0; + /* subtract one, because it is the following line that + gets the specified number */ + + int l = TREE_INT_CST_LOW (yylval.ttype) - 1; + + /* Is this the last nonwhite stuff on the line? */ + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + if (c == '\n') + { + /* No more: store the line number and check following line. */ + lineno = l; + return c; + } + ungetc (c, finput); + + /* More follows: it must be a string constant (filename). */ + + /* Read the string constant. */ + token = yylex (); + + if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #line"); + goto skipline; + } + + input_filename + = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1); + strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype)); + lineno = l; + + /* Each change of file name + reinitializes whether we are now in a system header. */ + in_system_header = 0; + + if (main_input_filename == 0) + main_input_filename = input_filename; + + /* Is this the last nonwhite stuff on the line? */ + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + if (c == '\n') + { + /* Update the name in the top element of input_file_stack. */ + if (input_file_stack) + input_file_stack->name = input_filename; + + return c; + } + ungetc (c, finput); + + token = yylex (); + used_up = 0; + + /* `1' after file name means entering new file. + `2' after file name means just left a file. */ + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST) + { + if (TREE_INT_CST_LOW (yylval.ttype) == 1) + { + /* Pushing to a new file. */ + struct file_stack *p + = (struct file_stack *) xmalloc (sizeof (struct file_stack)); + input_file_stack->line = old_lineno; + p->next = input_file_stack; + p->name = input_filename; + input_file_stack = p; + input_file_stack_tick++; +#ifdef DWARF_DEBUGGING_INFO + if (debug_info_level == DINFO_LEVEL_VERBOSE + && write_symbols == DWARF_DEBUG) + dwarfout_start_new_source_file (input_filename); +#endif /* DWARF_DEBUGGING_INFO */ + + used_up = 1; + } + else if (TREE_INT_CST_LOW (yylval.ttype) == 2) + { + /* Popping out of a file. */ + if (input_file_stack->next) + { + struct file_stack *p = input_file_stack; + input_file_stack = p->next; + free (p); + input_file_stack_tick++; +#ifdef DWARF_DEBUGGING_INFO + if (debug_info_level == DINFO_LEVEL_VERBOSE + && write_symbols == DWARF_DEBUG) + dwarfout_resume_previous_source_file (input_file_stack->line); +#endif /* DWARF_DEBUGGING_INFO */ + } + else + error ("#-lines for entering and leaving files don't match"); + + used_up = 1; + } + } + + /* Now that we've pushed or popped the input stack, + update the name in the top element. */ + if (input_file_stack) + input_file_stack->name = input_filename; + + /* If we have handled a `1' or a `2', + see if there is another number to read. */ + if (used_up) + { + /* Is this the last nonwhite stuff on the line? */ + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + if (c == '\n') + return c; + ungetc (c, finput); + + token = yylex (); + used_up = 0; + } + + /* `3' after file name means this is a system header file. */ + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST + && TREE_INT_CST_LOW (yylval.ttype) == 3) + in_system_header = 1, used_up = 1; + + if (used_up) + { + /* Is this the last nonwhite stuff on the line? */ + c = getc (finput); + while (c == ' ' || c == '\t') + c = getc (finput); + if (c == '\n') + return c; + ungetc (c, finput); + } + + warning ("unrecognized text at end of #line"); + } + else + error ("invalid #-line"); + + /* skip the rest of this line. */ + skipline: + if (c == '\n') + return c; + while ((c = getc (finput)) != EOF && c != '\n'); + return c; +} + +#ifdef HANDLE_SYSV_PRAGMA + +/* Handle a #pragma directive. INPUT is the current input stream, + and C is a character to reread. Processes the entire input line + and returns a character for the caller to reread: either \n or EOF. */ + +/* This function has to be in this file, in order to get at + the token types. */ + +int +handle_sysv_pragma (input, c) + FILE *input; + int c; +{ + for (;;) + { + while (c == ' ' || c == '\t') + c = getc (input); + if (c == '\n' || c == EOF) + { + handle_pragma_token (0, 0); + return c; + } + ungetc (c, input); + switch (yylex ()) + { + case IDENTIFIER: + case TYPENAME: + case STRING: + case CONSTANT: + handle_pragma_token (token_buffer, yylval.ttype); + break; + default: + handle_pragma_token (token_buffer, 0); + } + if (nextchar >= 0) + c = nextchar, nextchar = -1; + else + c = getc (input); + } +} + +#endif /* HANDLE_SYSV_PRAGMA */ + +#define ENDFILE -1 /* token that represents end-of-file */ + +/* Read an escape sequence, returning its equivalent as a character, + or store 1 in *ignore_ptr if it is backslash-newline. */ + +static int +readescape (ignore_ptr) + int *ignore_ptr; +{ + register int c = getc (finput); + register int code; + register unsigned count; + unsigned firstdig = 0; + int nonnull; + + switch (c) + { + case 'x': + if (warn_traditional) + warning ("the meaning of `\\x' varies with -traditional"); + + if (flag_traditional) + return c; + + code = 0; + count = 0; + nonnull = 0; + while (1) + { + c = getc (finput); + if (!(c >= 'a' && c <= 'f') + && !(c >= 'A' && c <= 'F') + && !(c >= '0' && c <= '9')) + { + ungetc (c, finput); + break; + } + code *= 16; + if (c >= 'a' && c <= 'f') + code += c - 'a' + 10; + if (c >= 'A' && c <= 'F') + code += c - 'A' + 10; + if (c >= '0' && c <= '9') + code += c - '0'; + if (code != 0 || count != 0) + { + if (count == 0) + firstdig = code; + count++; + } + nonnull = 1; + } + if (! nonnull) + error ("\\x used with no following hex digits"); + else if (count == 0) + /* Digits are all 0's. Ok. */ + ; + else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) + || (count > 1 + && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4)) + <= firstdig))) + pedwarn ("hex escape out of range"); + return code; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + code = 0; + count = 0; + while ((c <= '7') && (c >= '0') && (count++ < 3)) + { + code = (code * 8) + (c - '0'); + c = getc (finput); + } + ungetc (c, finput); + return code; + + case '\\': case '\'': case '"': + return c; + + case '\n': + lineno++; + *ignore_ptr = 1; + return 0; + + case 'n': + return TARGET_NEWLINE; + + case 't': + return TARGET_TAB; + + case 'r': + return TARGET_CR; + + case 'f': + return TARGET_FF; + + case 'b': + return TARGET_BS; + + case 'a': + if (warn_traditional) + warning ("the meaning of `\\a' varies with -traditional"); + + if (flag_traditional) + return c; + return TARGET_BELL; + + case 'v': +#if 0 /* Vertical tab is present in common usage compilers. */ + if (flag_traditional) + return c; +#endif + return TARGET_VT; + + case 'e': + case 'E': + if (pedantic) + pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); + return 033; + + case '?': + return c; + + /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ + case '(': + case '{': + case '[': + /* `\%' is used to prevent SCCS from getting confused. */ + case '%': + if (pedantic) + pedwarn ("non-ANSI escape sequence `\\%c'", c); + return c; + } + if (c >= 040 && c < 0177) + pedwarn ("unknown escape sequence `\\%c'", c); + else + pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); + return c; +} + +void +yyerror (string) + char *string; +{ + char buf[200]; + + strcpy (buf, string); + + /* We can't print string and character constants well + because the token_buffer contains the result of processing escapes. */ + if (end_of_file) + strcat (buf, " at end of input"); + else if (token_buffer[0] == 0) + strcat (buf, " at null character"); + else if (token_buffer[0] == '"') + strcat (buf, " before string constant"); + else if (token_buffer[0] == '\'') + strcat (buf, " before character constant"); + else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177) + sprintf (buf + strlen (buf), " before character 0%o", + (unsigned char) token_buffer[0]); + else + strcat (buf, " before `%s'"); + + error (buf, token_buffer); +} + +#if 0 + +struct try_type +{ + tree *node_var; + char unsigned_flag; + char long_flag; + char long_long_flag; +}; + +struct try_type type_sequence[] = +{ + { &integer_type_node, 0, 0, 0}, + { &unsigned_type_node, 1, 0, 0}, + { &long_integer_type_node, 0, 1, 0}, + { &long_unsigned_type_node, 1, 1, 0}, + { &long_long_integer_type_node, 0, 1, 1}, + { &long_long_unsigned_type_node, 1, 1, 1} +}; +#endif /* 0 */ + +int +yylex () +{ + register int c; + register char *p; + register int value; + int wide_flag = 0; + int objc_flag = 0; + + if (nextchar >= 0) + c = nextchar, nextchar = -1; + else + c = getc (finput); + + /* Effectively do c = skip_white_space (c) + but do it faster in the usual cases. */ + while (1) + switch (c) + { + case ' ': + case '\t': + case '\f': + case '\v': + case '\b': + c = getc (finput); + break; + + case '\r': + /* Call skip_white_space so we can warn if appropriate. */ + + case '\n': + case '/': + case '\\': + c = skip_white_space (c); + default: + goto found_nonwhite; + } + found_nonwhite: + + token_buffer[0] = c; + token_buffer[1] = 0; + +/* yylloc.first_line = lineno; */ + + switch (c) + { + case EOF: + end_of_file = 1; + token_buffer[0] = 0; + value = ENDFILE; + break; + + case '$': + if (dollars_in_ident) + goto letter; + return '$'; + + case 'L': + /* Capital L may start a wide-string or wide-character constant. */ + { + register int c = getc (finput); + if (c == '\'') + { + wide_flag = 1; + goto char_constant; + } + if (c == '"') + { + wide_flag = 1; + goto string_constant; + } + ungetc (c, finput); + } + goto letter; + + case '@': + if (!doing_objc_thang) + { + value = c; + break; + } + else + { + /* '@' may start a constant string object. */ + register int c = getc(finput); + if (c == '"') + { + objc_flag = 1; + goto string_constant; + } + ungetc(c, finput); + /* Fall through to treat '@' as the start of an identifier. */ + } + + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case '_': + letter: + p = token_buffer; + while (isalnum (c) || c == '_' || c == '$' || c == '@') + { + /* Make sure this char really belongs in an identifier. */ + if (c == '@' && ! doing_objc_thang) + break; + if (c == '$' && ! dollars_in_ident) + break; + + if (p >= token_buffer + maxtoken) + p = extend_token_buffer (p); + + *p++ = c; + c = getc (finput); + } + + *p = 0; + nextchar = c; + + value = IDENTIFIER; + yylval.itype = 0; + + /* Try to recognize a keyword. Uses minimum-perfect hash function */ + + { + register struct resword *ptr; + + if (ptr = is_reserved_word (token_buffer, p - token_buffer)) + { + if (ptr->rid) + yylval.ttype = ridpointers[(int) ptr->rid]; + value = (int) ptr->token; + + /* Only return OBJECTNAME if it is a typedef. */ + if (doing_objc_thang && value == OBJECTNAME) + { + lastiddecl = lookup_name(yylval.ttype); + + if (lastiddecl == NULL_TREE + || TREE_CODE (lastiddecl) != TYPE_DECL) + value = IDENTIFIER; + } + + /* Even if we decided to recognize asm, still perhaps warn. */ + if (pedantic + && (value == ASM_KEYWORD || value == TYPEOF + || ptr->rid == RID_INLINE) + && token_buffer[0] != '_') + pedwarn ("ANSI does not permit the keyword `%s'", + token_buffer); + } + } + + /* If we did not find a keyword, look for an identifier + (or a typename). */ + + if (value == IDENTIFIER) + { + if (token_buffer[0] == '@') + error("invalid identifier `%s'", token_buffer); + + yylval.ttype = get_identifier (token_buffer); + lastiddecl = lookup_name (yylval.ttype); + + if (lastiddecl != 0 && TREE_CODE (lastiddecl) == TYPE_DECL) + value = TYPENAME; + /* A user-invisible read-only initialized variable + should be replaced by its value. + We handle only strings since that's the only case used in C. */ + else if (lastiddecl != 0 && TREE_CODE (lastiddecl) == VAR_DECL + && DECL_IGNORED_P (lastiddecl) + && TREE_READONLY (lastiddecl) + && DECL_INITIAL (lastiddecl) != 0 + && TREE_CODE (DECL_INITIAL (lastiddecl)) == STRING_CST) + { + tree stringval = DECL_INITIAL (lastiddecl); + + /* Copy the string value so that we won't clobber anything + if we put something in the TREE_CHAIN of this one. */ + yylval.ttype = build_string (TREE_STRING_LENGTH (stringval), + TREE_STRING_POINTER (stringval)); + value = STRING; + } + else if (doing_objc_thang) + { + tree objc_interface_decl = is_class_name (yylval.ttype); + + if (objc_interface_decl) + { + value = CLASSNAME; + yylval.ttype = objc_interface_decl; + } + } + } + + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case '.': + { + int base = 10; + int count = 0; + int largest_digit = 0; + int numdigits = 0; + /* for multi-precision arithmetic, + we actually store only HOST_BITS_PER_CHAR bits in each part. + The number of parts is chosen so as to be sufficient to hold + the enough bits to fit into the two HOST_WIDE_INTs that contain + the integer value (this is always at least as many bits as are + in a target `long long' value, but may be wider). */ +#define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2) + int parts[TOTAL_PARTS]; + int overflow = 0; + + enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag + = NOT_FLOAT; + + for (count = 0; count < TOTAL_PARTS; count++) + parts[count] = 0; + + p = token_buffer; + *p++ = c; + + if (c == '0') + { + *p++ = (c = getc (finput)); + if ((c == 'x') || (c == 'X')) + { + base = 16; + *p++ = (c = getc (finput)); + } + /* Leading 0 forces octal unless the 0 is the only digit. */ + else if (c >= '0' && c <= '9') + { + base = 8; + numdigits++; + } + else + numdigits++; + } + + /* Read all the digits-and-decimal-points. */ + + while (c == '.' + || (isalnum (c) && c != 'l' && c != 'L' + && c != 'u' && c != 'U' + && c != 'i' && c != 'I' && c != 'j' && c != 'J' + && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F'))))) + { + if (c == '.') + { + if (base == 16) + error ("floating constant may not be in radix 16"); + if (floatflag == TOO_MANY_POINTS) + /* We have already emitted an error. Don't need another. */ + ; + else if (floatflag == AFTER_POINT) + { + error ("malformed floating constant"); + floatflag = TOO_MANY_POINTS; + /* Avoid another error from atof by forcing all characters + from here on to be ignored. */ + p[-1] = '\0'; + } + else + floatflag = AFTER_POINT; + + base = 10; + *p++ = c = getc (finput); + /* Accept '.' as the start of a floating-point number + only when it is followed by a digit. + Otherwise, unread the following non-digit + and use the '.' as a structural token. */ + if (p == token_buffer + 2 && !isdigit (c)) + { + if (c == '.') + { + c = getc (finput); + if (c == '.') + { + *p++ = c; + *p = 0; + return ELLIPSIS; + } + error ("parse error at `..'"); + } + ungetc (c, finput); + token_buffer[1] = 0; + value = '.'; + goto done; + } + } + else + { + /* It is not a decimal point. + It should be a digit (perhaps a hex digit). */ + + if (isdigit (c)) + { + c = c - '0'; + } + else if (base <= 10) + { + if (c == 'e' || c == 'E') + { + base = 10; + floatflag = AFTER_POINT; + break; /* start of exponent */ + } + error ("nondigits in number and not hexadecimal"); + c = 0; + } + else if (c >= 'a') + { + c = c - 'a' + 10; + } + else + { + c = c - 'A' + 10; + } + if (c >= largest_digit) + largest_digit = c; + numdigits++; + + for (count = 0; count < TOTAL_PARTS; count++) + { + parts[count] *= base; + if (count) + { + parts[count] + += (parts[count-1] >> HOST_BITS_PER_CHAR); + parts[count-1] + &= (1 << HOST_BITS_PER_CHAR) - 1; + } + else + parts[0] += c; + } + + /* If the extra highest-order part ever gets anything in it, + the number is certainly too big. */ + if (parts[TOTAL_PARTS - 1] != 0) + overflow = 1; + + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = (c = getc (finput)); + } + } + + if (numdigits == 0) + error ("numeric constant with no digits"); + + if (largest_digit >= base) + error ("numeric constant contains digits beyond the radix"); + + /* Remove terminating char from the token buffer and delimit the string */ + *--p = 0; + + if (floatflag != NOT_FLOAT) + { + tree type = double_type_node; + int garbage_chars = 0, exceeds_double = 0; + int imag = 0; + REAL_VALUE_TYPE value; + jmp_buf handler; + + /* Read explicit exponent if any, and put it in tokenbuf. */ + + if ((c == 'e') || (c == 'E')) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getc (finput); + if ((c == '+') || (c == '-')) + { + *p++ = c; + c = getc (finput); + } + if (! isdigit (c)) + error ("floating constant exponent has no digits"); + while (isdigit (c)) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getc (finput); + } + } + + *p = 0; + errno = 0; + + /* Convert string to a double, checking for overflow. */ + if (setjmp (handler)) + { + error ("floating constant out of range"); + value = dconst0; + } + else + { + int fflag = 0, lflag = 0; + /* Copy token_buffer now, while it has just the number + and not the suffixes; once we add `f' or `i', + REAL_VALUE_ATOF may not work any more. */ + char *copy = (char *) alloca (p - token_buffer + 1); + bcopy (token_buffer, copy, p - token_buffer + 1); + + set_float_handler (handler); + + while (1) + { + int lose = 0; + + /* Read the suffixes to choose a data type. */ + switch (c) + { + case 'f': case 'F': + if (fflag) + error ("more than one `f' in numeric constant"); + fflag = 1; + break; + + case 'l': case 'L': + if (lflag) + error ("more than one `l' in numeric constant"); + lflag = 1; + break; + + case 'i': case 'I': + if (imag) + error ("more than one `i' or `j' in numeric constant"); + else if (pedantic) + pedwarn ("ANSI C forbids imaginary numeric constants"); + imag = 1; + break; + + default: + lose = 1; + } + + if (lose) + break; + + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + *p = 0; + c = getc (finput); + } + + /* The second argument, machine_mode, of REAL_VALUE_ATOF + tells the desired precision of the binary result + of decimal-to-binary conversion. */ + + if (fflag) + { + if (lflag) + error ("both `f' and `l' in floating constant"); + + type = float_type_node; + value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); + /* A diagnostic is required here by some ANSI C testsuites. + This is not pedwarn, become some people don't want + an error for this. */ + if (REAL_VALUE_ISINF (value) && pedantic) + warning ("floating point number exceeds range of `float'"); + } + else if (lflag) + { + type = long_double_type_node; + value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); + if (REAL_VALUE_ISINF (value) && pedantic) + warning ("floating point number exceeds range of `long double'"); + } + else + { + value = REAL_VALUE_ATOF (copy, TYPE_MODE (type)); + if (REAL_VALUE_ISINF (value) && pedantic) + warning ("floating point number exceeds range of `double'"); + } + + set_float_handler (NULL_PTR); + } +#ifdef ERANGE + if (errno == ERANGE && !flag_traditional && pedantic) + { + /* ERANGE is also reported for underflow, + so test the value to distinguish overflow from that. */ + if (REAL_VALUES_LESS (dconst1, value) + || REAL_VALUES_LESS (value, dconstm1)) + { + warning ("floating point number exceeds range of `double'"); + exceeds_double = 1; + } + } +#endif + garbage_chars = 0; + while (isalnum (c) || c == '.' || c == '_' + || (!flag_traditional && (c == '+' || c == '-') + && (p[-1] == 'e' || p[-1] == 'E'))) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getc (finput); + garbage_chars++; + } + if (garbage_chars > 0) + error ("garbage at end of number"); + + /* If the result is not a number, assume it must have been + due to some error message above, so silently convert + it to a zero. */ + if (REAL_VALUE_ISNAN (value)) + value = dconst0; + + /* Create a node with determined type and value. */ + if (imag) + yylval.ttype = build_complex (convert (type, integer_zero_node), + build_real (type, value)); + else + yylval.ttype = build_real (type, value); + + ungetc (c, finput); + *p = 0; + } + else + { + tree traditional_type, ansi_type, type; + HOST_WIDE_INT high, low; + int spec_unsigned = 0; + int spec_long = 0; + int spec_long_long = 0; + int spec_imag = 0; + int bytes, warn, i; + + while (1) + { + if (c == 'u' || c == 'U') + { + if (spec_unsigned) + error ("two `u's in integer constant"); + spec_unsigned = 1; + } + else if (c == 'l' || c == 'L') + { + if (spec_long) + { + if (spec_long_long) + error ("three `l's in integer constant"); + else if (pedantic) + pedwarn ("ANSI C forbids long long integer constants"); + spec_long_long = 1; + } + spec_long = 1; + } + else if (c == 'i' || c == 'j' || c == 'I' || c == 'J') + { + if (spec_imag) + error ("more than one `i' or `j' in numeric constant"); + else if (pedantic) + pedwarn ("ANSI C forbids imaginary numeric constants"); + spec_imag = 1; + } + else + { + if (isalnum (c) || c == '.' || c == '_' + || (!flag_traditional && (c == '+' || c == '-') + && (p[-1] == 'e' || p[-1] == 'E'))) + { + error ("garbage at end of number"); + while (isalnum (c) || c == '.' || c == '_' + || (!flag_traditional && (c == '+' || c == '-') + && (p[-1] == 'e' || p[-1] == 'E'))) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getc (finput); + } + } + break; + } + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getc (finput); + } + + ungetc (c, finput); + + /* If the constant is not long long and it won't fit in an + unsigned long, or if the constant is long long and won't fit + in an unsigned long long, then warn that the constant is out + of range. */ + + /* ??? This assumes that long long and long integer types are + a multiple of 8 bits. This better than the original code + though which assumed that long was exactly 32 bits and long + long was exactly 64 bits. */ + + if (spec_long_long) + bytes = TYPE_PRECISION (long_long_integer_type_node) / 8; + else + bytes = TYPE_PRECISION (long_integer_type_node) / 8; + + warn = overflow; + for (i = bytes; i < TOTAL_PARTS; i++) + if (parts[i]) + warn = 1; + if (warn) + pedwarn ("integer constant out of range"); + + /* This is simplified by the fact that our constant + is always positive. */ + + high = low = 0; + + for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) + { + high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT + / HOST_BITS_PER_CHAR)] + << (i * HOST_BITS_PER_CHAR)); + low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); + } + + yylval.ttype = build_int_2 (low, high); + TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; + + /* If warn_traditional, calculate both the ANSI type and the + traditional type, then see if they disagree. + Otherwise, calculate only the type for the dialect in use. */ + if (warn_traditional || flag_traditional) + { + /* Calculate the traditional type. */ + /* Traditionally, any constant is signed; + but if unsigned is specified explicitly, obey that. + Use the smallest size with the right number of bits, + except for one special case with decimal constants. */ + if (! spec_long && base != 10 + && int_fits_type_p (yylval.ttype, unsigned_type_node)) + traditional_type = (spec_unsigned ? unsigned_type_node + : integer_type_node); + /* A decimal constant must be long + if it does not fit in type int. + I think this is independent of whether + the constant is signed. */ + else if (! spec_long && base == 10 + && int_fits_type_p (yylval.ttype, integer_type_node)) + traditional_type = (spec_unsigned ? unsigned_type_node + : integer_type_node); + else if (! spec_long_long) + traditional_type = (spec_unsigned ? long_unsigned_type_node + : long_integer_type_node); + else + traditional_type = (spec_unsigned + ? long_long_unsigned_type_node + : long_long_integer_type_node); + } + if (warn_traditional || ! flag_traditional) + { + /* Calculate the ANSI type. */ + if (! spec_long && ! spec_unsigned + && int_fits_type_p (yylval.ttype, integer_type_node)) + ansi_type = integer_type_node; + else if (! spec_long && (base != 10 || spec_unsigned) + && int_fits_type_p (yylval.ttype, unsigned_type_node)) + ansi_type = unsigned_type_node; + else if (! spec_unsigned && !spec_long_long + && int_fits_type_p (yylval.ttype, long_integer_type_node)) + ansi_type = long_integer_type_node; + else if (! spec_long_long) + ansi_type = long_unsigned_type_node; + else if (! spec_unsigned + /* Verify value does not overflow into sign bit. */ + && TREE_INT_CST_HIGH (yylval.ttype) >= 0 + && int_fits_type_p (yylval.ttype, + long_long_integer_type_node)) + ansi_type = long_long_integer_type_node; + else + ansi_type = long_long_unsigned_type_node; + } + + type = flag_traditional ? traditional_type : ansi_type; + + if (warn_traditional && traditional_type != ansi_type) + { + if (TYPE_PRECISION (traditional_type) + != TYPE_PRECISION (ansi_type)) + warning ("width of integer constant changes with -traditional"); + else if (TREE_UNSIGNED (traditional_type) + != TREE_UNSIGNED (ansi_type)) + warning ("integer constant is unsigned in ANSI C, signed with -traditional"); + else + warning ("width of integer constant may change on other systems with -traditional"); + } + + if (!flag_traditional && !int_fits_type_p (yylval.ttype, type) + && !warn) + pedwarn ("integer constant out of range"); + + if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) + warning ("decimal constant is so large that it is unsigned"); + + if (spec_imag) + { + if (TYPE_PRECISION (type) + <= TYPE_PRECISION (integer_type_node)) + yylval.ttype + = build_complex (integer_zero_node, + convert (integer_type_node, yylval.ttype)); + else + error ("complex integer constant is too wide for `complex int'"); + } + else if (flag_traditional && !int_fits_type_p (yylval.ttype, type)) + /* The traditional constant 0x80000000 is signed + but doesn't fit in the range of int. + This will change it to -0x80000000, which does fit. */ + { + TREE_TYPE (yylval.ttype) = unsigned_type (type); + yylval.ttype = convert (type, yylval.ttype); + TREE_OVERFLOW (yylval.ttype) + = TREE_CONSTANT_OVERFLOW (yylval.ttype) = 0; + } + else + TREE_TYPE (yylval.ttype) = type; + + *p = 0; + } + + value = CONSTANT; break; + } + + case '\'': + char_constant: + { + register int result = 0; + register int num_chars = 0; + unsigned width = TYPE_PRECISION (char_type_node); + int max_chars; + + if (wide_flag) + { + width = WCHAR_TYPE_SIZE; +#ifdef MULTIBYTE_CHARS + max_chars = MB_CUR_MAX; +#else + max_chars = 1; +#endif + } + else + max_chars = TYPE_PRECISION (integer_type_node) / width; + + while (1) + { + tryagain: + + c = getc (finput); + + if (c == '\'' || c == EOF) + break; + + if (c == '\\') + { + int ignore = 0; + c = readescape (&ignore); + if (ignore) + goto tryagain; + if (width < HOST_BITS_PER_INT + && (unsigned) c >= (1 << width)) + pedwarn ("escape sequence out of range for character"); +#ifdef MAP_CHARACTER + if (isprint (c)) + c = MAP_CHARACTER (c); +#endif + } + else if (c == '\n') + { + if (pedantic) + pedwarn ("ANSI C forbids newline in character constant"); + lineno++; + } +#ifdef MAP_CHARACTER + else + c = MAP_CHARACTER (c); +#endif + + num_chars++; + if (num_chars > maxtoken - 4) + extend_token_buffer (token_buffer); + + token_buffer[num_chars] = c; + + /* Merge character into result; ignore excess chars. */ + if (num_chars < max_chars + 1) + { + if (width < HOST_BITS_PER_INT) + result = (result << width) | (c & ((1 << width) - 1)); + else + result = c; + } + } + + token_buffer[num_chars + 1] = '\''; + token_buffer[num_chars + 2] = 0; + + if (c != '\'') + error ("malformatted character constant"); + else if (num_chars == 0) + error ("empty character constant"); + else if (num_chars > max_chars) + { + num_chars = max_chars; + error ("character constant too long"); + } + else if (num_chars != 1 && ! flag_traditional) + warning ("multi-character character constant"); + + /* If char type is signed, sign-extend the constant. */ + if (! wide_flag) + { + int num_bits = num_chars * width; + if (num_bits == 0) + /* We already got an error; avoid invalid shift. */ + yylval.ttype = build_int_2 (0, 0); + else if (TREE_UNSIGNED (char_type_node) + || ((result >> (num_bits - 1)) & 1) == 0) + yylval.ttype + = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0 + >> (HOST_BITS_PER_WIDE_INT - num_bits)), + 0); + else + yylval.ttype + = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0 + >> (HOST_BITS_PER_WIDE_INT - num_bits)), + -1); + TREE_TYPE (yylval.ttype) = integer_type_node; + } + else + { +#ifdef MULTIBYTE_CHARS + /* Set the initial shift state and convert the next sequence. */ + result = 0; + /* In all locales L'\0' is zero and mbtowc will return zero, + so don't use it. */ + if (num_chars > 1 + || (num_chars == 1 && token_buffer[1] != '\0')) + { + wchar_t wc; + (void) mbtowc (NULL_PTR, NULL_PTR, 0); + if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars) + result = wc; + else + warning ("Ignoring invalid multibyte character"); + } +#endif + yylval.ttype = build_int_2 (result, 0); + TREE_TYPE (yylval.ttype) = wchar_type_node; + } + + value = CONSTANT; + break; + } + + case '"': + string_constant: + { + c = getc (finput); + p = token_buffer + 1; + + while (c != '"' && c >= 0) + { + if (c == '\\') + { + int ignore = 0; + c = readescape (&ignore); + if (ignore) + goto skipnewline; + if (!wide_flag + && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT + && c >= (1 << TYPE_PRECISION (char_type_node))) + pedwarn ("escape sequence out of range for character"); + } + else if (c == '\n') + { + if (pedantic) + pedwarn ("ANSI C forbids newline in string constant"); + lineno++; + } + + if (p == token_buffer + maxtoken) + p = extend_token_buffer (p); + *p++ = c; + + skipnewline: + c = getc (finput); + } + *p = 0; + + if (c < 0) + error ("Unterminated string constant"); + + /* We have read the entire constant. + Construct a STRING_CST for the result. */ + + if (wide_flag) + { + /* If this is a L"..." wide-string, convert the multibyte string + to a wide character string. */ + char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES); + int len; + +#ifdef MULTIBYTE_CHARS + len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer); + if (len < 0 || len >= (p - token_buffer)) + { + warning ("Ignoring invalid multibyte string"); + len = 0; + } + bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES); +#else + { + union { long l; char c[sizeof (long)]; } u; + int big_endian; + char *wp, *cp; + + /* Determine whether host is little or big endian. */ + u.l = 1; + big_endian = u.c[sizeof (long) - 1]; + wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0); + + bzero (widep, (p - token_buffer) * WCHAR_BYTES); + for (cp = token_buffer + 1; cp < p; cp++) + *wp = *cp, wp += WCHAR_BYTES; + len = p - token_buffer - 1; + } +#endif + yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep); + TREE_TYPE (yylval.ttype) = wchar_array_type_node; + value = STRING; + } + else if (objc_flag) + { + extern tree build_objc_string(); + /* Return an Objective-C @"..." constant string object. */ + yylval.ttype = build_objc_string (p - token_buffer, + token_buffer + 1); + TREE_TYPE (yylval.ttype) = char_array_type_node; + value = OBJC_STRING; + } + else + { + yylval.ttype = build_string (p - token_buffer, token_buffer + 1); + TREE_TYPE (yylval.ttype) = char_array_type_node; + value = STRING; + } + + *p++ = '"'; + *p = 0; + + break; + } + + case '+': + case '-': + case '&': + case '|': + case ':': + case '<': + case '>': + case '*': + case '/': + case '%': + case '^': + case '!': + case '=': + { + register int c1; + + combine: + + switch (c) + { + case '+': + yylval.code = PLUS_EXPR; break; + case '-': + yylval.code = MINUS_EXPR; break; + case '&': + yylval.code = BIT_AND_EXPR; break; + case '|': + yylval.code = BIT_IOR_EXPR; break; + case '*': + yylval.code = MULT_EXPR; break; + case '/': + yylval.code = TRUNC_DIV_EXPR; break; + case '%': + yylval.code = TRUNC_MOD_EXPR; break; + case '^': + yylval.code = BIT_XOR_EXPR; break; + case LSHIFT: + yylval.code = LSHIFT_EXPR; break; + case RSHIFT: + yylval.code = RSHIFT_EXPR; break; + case '<': + yylval.code = LT_EXPR; break; + case '>': + yylval.code = GT_EXPR; break; + } + + token_buffer[1] = c1 = getc (finput); + token_buffer[2] = 0; + + if (c1 == '=') + { + switch (c) + { + case '<': + value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; + case '>': + value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; + case '!': + value = EQCOMPARE; yylval.code = NE_EXPR; goto done; + case '=': + value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; + } + value = ASSIGN; goto done; + } + else if (c == c1) + switch (c) + { + case '+': + value = PLUSPLUS; goto done; + case '-': + value = MINUSMINUS; goto done; + case '&': + value = ANDAND; goto done; + case '|': + value = OROR; goto done; + case '<': + c = LSHIFT; + goto combine; + case '>': + c = RSHIFT; + goto combine; + } + else + switch (c) + { + case '-': + if (c1 == '>') + { value = POINTSAT; goto done; } + break; + case ':': + if (c1 == '>') + { value = ']'; goto done; } + break; + case '<': + if (c1 == '%') + { value = '{'; goto done; } + if (c1 == ':') + { value = '['; goto done; } + break; + case '%': + if (c1 == '>') + { value = '}'; goto done; } + break; + } + ungetc (c1, finput); + token_buffer[1] = 0; + + if ((c == '<') || (c == '>')) + value = ARITHCOMPARE; + else value = c; + goto done; + } + + case 0: + /* Don't make yyparse think this is eof. */ + value = 1; + break; + + default: + value = c; + } + +done: +/* yylloc.last_line = lineno; */ + + return value; +} + +/* Sets the value of the 'yydebug' variable to VALUE. + This is a function so we don't have to have YYDEBUG defined + in order to build the compiler. */ + +void +set_yydebug (value) + int value; +{ +#if YYDEBUG != 0 + yydebug = value; +#else + warning ("YYDEBUG not defined."); +#endif +} diff --git a/contrib/gcc/c-lex.h b/contrib/gcc/c-lex.h new file mode 100644 index 00000000000..c1aed084e5f --- /dev/null +++ b/contrib/gcc/c-lex.h @@ -0,0 +1,80 @@ +/* Define constants for communication with c-parse.y. + Copyright (C) 1987, 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + + +enum rid +{ + RID_UNUSED, + RID_INT, + RID_CHAR, + RID_FLOAT, + RID_DOUBLE, + RID_VOID, + RID_UNUSED1, + + RID_UNSIGNED, + RID_SHORT, + RID_LONG, + RID_AUTO, + RID_STATIC, + RID_EXTERN, + RID_REGISTER, + RID_TYPEDEF, + RID_SIGNED, + RID_CONST, + RID_VOLATILE, + RID_INLINE, + RID_NOALIAS, + RID_ITERATOR, + RID_COMPLEX, + + RID_IN, + RID_OUT, + RID_INOUT, + RID_BYCOPY, + RID_ONEWAY, + RID_ID, + + RID_MAX +}; + +#define NORID RID_UNUSED + +#define RID_FIRST_MODIFIER RID_UNSIGNED + +/* The elements of `ridpointers' are identifier nodes + for the reserved type names and storage classes. + It is indexed by a RID_... value. */ +extern tree ridpointers[(int) RID_MAX]; + +/* the declaration found for the last IDENTIFIER token read in. + yylex must look this up to detect typedefs, which get token type TYPENAME, + so it is left around in case the identifier is not a typedef but is + used in a context which makes it a reference to a variable. */ +extern tree lastiddecl; + +extern char *token_buffer; /* Pointer to token buffer. */ + +extern tree make_pointer_declarator (); +extern void reinit_parse_for_function (); +extern int yylex (); + +extern char *get_directive_line (); diff --git a/contrib/gcc/c-parse.gperf b/contrib/gcc/c-parse.gperf new file mode 100644 index 00000000000..90cab6ad1d8 --- /dev/null +++ b/contrib/gcc/c-parse.gperf @@ -0,0 +1,84 @@ +%{ +/* Command-line: gperf -p -j1 -i 1 -g -o -t -N is_reserved_word -k1,3,$ c-parse.gperf */ +%} +struct resword { char *name; short token; enum rid rid; }; +%% +@class, CLASS, NORID +@compatibility_alias, ALIAS, NORID +@defs, DEFS, NORID +@encode, ENCODE, NORID +@end, END, NORID +@implementation, IMPLEMENTATION, NORID +@interface, INTERFACE, NORID +@private, PRIVATE, NORID +@protected, PROTECTED, NORID +@protocol, PROTOCOL, NORID +@public, PUBLIC, NORID +@selector, SELECTOR, NORID +__alignof, ALIGNOF, NORID +__alignof__, ALIGNOF, NORID +__asm, ASM_KEYWORD, NORID +__asm__, ASM_KEYWORD, NORID +__attribute, ATTRIBUTE, NORID +__attribute__, ATTRIBUTE, NORID +__complex, TYPESPEC, RID_COMPLEX +__complex__, TYPESPEC, RID_COMPLEX +__const, TYPE_QUAL, RID_CONST +__const__, TYPE_QUAL, RID_CONST +__extension__, EXTENSION, NORID +__imag, IMAGPART, NORID +__imag__, IMAGPART, NORID +__inline, SCSPEC, RID_INLINE +__inline__, SCSPEC, RID_INLINE +__iterator, SCSPEC, RID_ITERATOR +__iterator__, SCSPEC, RID_ITERATOR +__label__, LABEL, NORID +__real, REALPART, NORID +__real__, REALPART, NORID +__signed, TYPESPEC, RID_SIGNED +__signed__, TYPESPEC, RID_SIGNED +__typeof, TYPEOF, NORID +__typeof__, TYPEOF, NORID +__volatile, TYPE_QUAL, RID_VOLATILE +__volatile__, TYPE_QUAL, RID_VOLATILE +asm, ASM_KEYWORD, NORID +auto, SCSPEC, RID_AUTO +break, BREAK, NORID +bycopy, TYPE_QUAL, RID_BYCOPY +case, CASE, NORID +char, TYPESPEC, RID_CHAR +const, TYPE_QUAL, RID_CONST +continue, CONTINUE, NORID +default, DEFAULT, NORID +do, DO, NORID +double, TYPESPEC, RID_DOUBLE +else, ELSE, NORID +enum, ENUM, NORID +extern, SCSPEC, RID_EXTERN +float, TYPESPEC, RID_FLOAT +for, FOR, NORID +goto, GOTO, NORID +id, OBJECTNAME, RID_ID +if, IF, NORID +in, TYPE_QUAL, RID_IN +inout, TYPE_QUAL, RID_INOUT +inline, SCSPEC, RID_INLINE +int, TYPESPEC, RID_INT +long, TYPESPEC, RID_LONG +oneway, TYPE_QUAL, RID_ONEWAY +out, TYPE_QUAL, RID_OUT +register, SCSPEC, RID_REGISTER +return, RETURN, NORID +short, TYPESPEC, RID_SHORT +signed, TYPESPEC, RID_SIGNED +sizeof, SIZEOF, NORID +static, SCSPEC, RID_STATIC +struct, STRUCT, NORID +switch, SWITCH, NORID +typedef, SCSPEC, RID_TYPEDEF +typeof, TYPEOF, NORID +union, UNION, NORID +unsigned, TYPESPEC, RID_UNSIGNED +void, TYPESPEC, RID_VOID +volatile, TYPE_QUAL, RID_VOLATILE +while, WHILE, NORID diff --git a/contrib/gcc/c-parse.in b/contrib/gcc/c-parse.in new file mode 100644 index 00000000000..044e4523249 --- /dev/null +++ b/contrib/gcc/c-parse.in @@ -0,0 +1,2900 @@ +/* YACC parser for C syntax and for Objective C. -*-c-*- + Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines the grammar of C and that of Objective C. + ifobjc ... end ifobjc conditionals contain code for Objective C only. + ifc ... end ifc conditionals contain code for C only. + Sed commands in Makefile.in are used to convert this file into + c-parse.y and into objc-parse.y. */ + +/* To whomever it may concern: I have heard that such a thing was once + written by AT&T, but I have never seen it. */ + +ifobjc +%expect 48 +end ifobjc +ifc +%expect 34 + +/* These are the 23 conflicts you should get in parse.output; + the state numbers may vary if minor changes in the grammar are made. + +State 42 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.) +State 44 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 103 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 110 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.) +State 111 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 115 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 132 contains 1 shift/reduce conflict. (See comment at component_decl.) +State 180 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTE.) +State 194 contains 2 shift/reduce conflict. (Four ways to parse this.) +State 202 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 214 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 220 contains 1 shift/reduce conflict. (Two ways to recover from error.) +State 304 contains 2 shift/reduce conflicts. (Four ways to parse this.) +State 335 contains 2 shift/reduce conflicts. (Four ways to parse this.) +State 347 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.) +State 352 contains 1 shift/reduce conflict. (Two ways to parse ATTRIBUTES.) +State 383 contains 2 shift/reduce conflicts. (Four ways to parse this.) +State 434 contains 2 shift/reduce conflicts. (Four ways to parse this.) */ + +end ifc + +%{ +#include +#include +#include + +#include "config.h" +#include "tree.h" +#include "input.h" +#include "c-lex.h" +#include "c-tree.h" +#include "flags.h" + +#ifdef MULTIBYTE_CHARS +#include +#include +#endif + +ifobjc +#include "objc-act.h" +end ifobjc + +/* Since parsers are distinct for each language, put the language string + definition here. */ +ifobjc +char *language_string = "GNU Obj-C"; +end ifobjc +ifc +char *language_string = "GNU C"; +end ifc + +#ifndef errno +extern int errno; +#endif + +void yyerror (); + +/* Like YYERROR but do call yyerror. */ +#define YYERROR1 { yyerror ("syntax error"); YYERROR; } + +/* Cause the `yydebug' variable to be defined. */ +#define YYDEBUG 1 +%} + +%start program + +%union {long itype; tree ttype; enum tree_code code; + char *filename; int lineno; int ends_in_label; } + +/* All identifiers that are not reserved words + and are not declared typedefs in the current block */ +%token IDENTIFIER + +/* All identifiers that are declared typedefs in the current block. + In some contexts, they are treated just like IDENTIFIER, + but they can also serve as typespecs in declarations. */ +%token TYPENAME + +/* Reserved words that specify storage class. + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token SCSPEC + +/* Reserved words that specify type. + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token TYPESPEC + +/* Reserved words that qualify type: "const" or "volatile". + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token TYPE_QUAL + +/* Character or numeric constants. + yylval is the node for the constant. */ +%token CONSTANT + +/* String constants in raw form. + yylval is a STRING_CST node. */ +%token STRING + +/* "...", used for functions with variable arglists. */ +%token ELLIPSIS + +/* the reserved words */ +/* SCO include files test "ASM", so use something else. */ +%token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT +%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF +%token ATTRIBUTE EXTENSION LABEL +%token REALPART IMAGPART + +/* Add precedence rules to solve dangling else s/r conflict */ +%nonassoc IF +%nonassoc ELSE + +/* Define the operator tokens and their precedences. + The value is an integer because, if used, it is the tree code + to use in the expression made from the operator. */ + +%right ASSIGN '=' +%right '?' ':' +%left OROR +%left ANDAND +%left '|' +%left '^' +%left '&' +%left EQCOMPARE +%left ARITHCOMPARE +%left LSHIFT RSHIFT +%left '+' '-' +%left '*' '/' '%' +%right UNARY PLUSPLUS MINUSMINUS +%left HYPERUNARY +%left POINTSAT '.' '(' '[' + +/* The Objective-C keywords. These are included in C and in + Objective C, so that the token codes are the same in both. */ +%token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE +%token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS + +/* Objective-C string constants in raw form. + yylval is an OBJC_STRING_CST node. */ +%token OBJC_STRING + + +%type unop + +%type identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist +%type expr_no_commas cast_expr unary_expr primary string STRING +%type typed_declspecs reserved_declspecs +%type typed_typespecs reserved_typespecquals +%type declmods typespec typespecqual_reserved +%type SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual +%type initdecls notype_initdecls initdcl notype_initdcl +%type init maybeasm +%type asm_operands nonnull_asm_operands asm_operand asm_clobbers +%type maybe_attribute attributes attribute attribute_list attrib +%type any_word + +%type compstmt + +%type declarator +%type notype_declarator after_type_declarator +%type parm_declarator + +%type structsp component_decl_list component_decl_list2 +%type component_decl components component_declarator +%type enumlist enumerator +%type typename absdcl absdcl1 type_quals +%type xexpr parms parm identifiers + +%type parmlist parmlist_1 parmlist_2 +%type parmlist_or_identifiers parmlist_or_identifiers_1 +%type identifiers_or_typenames + +%type setspecs + +%type lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label + +%type save_filename +%type save_lineno + +ifobjc +/* the Objective-C nonterminals */ + +%type ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator +%type methoddecl unaryselector keywordselector selector +%type keyworddecl receiver objcmessageexpr messageargs +%type keywordexpr keywordarglist keywordarg +%type myparms myparm optparmlist reservedwords objcselectorexpr +%type selectorarg keywordnamelist keywordname objcencodeexpr +%type objc_string protocolrefs identifier_list objcprotocolexpr +%type CLASSNAME OBJC_STRING OBJECTNAME +end ifobjc + +%{ +/* Number of statements (loosely speaking) seen so far. */ +static int stmt_count; + +/* Input file and line number of the end of the body of last simple_if; + used by the stmt-rule immediately after simple_if returns. */ +static char *if_stmt_file; +static int if_stmt_line; + +/* List of types and structure classes of the current declaration. */ +static tree current_declspecs; +static tree prefix_attributes = NULL_TREE; + +/* Stack of saved values of current_declspecs and prefix_attributes. */ +static tree declspec_stack; + +/* 1 if we explained undeclared var errors. */ +static int undeclared_variable_notice; + +ifobjc +/* Objective-C specific information */ + +tree objc_interface_context; +tree objc_implementation_context; +tree objc_method_context; +tree objc_ivar_chain; +tree objc_ivar_context; +enum tree_code objc_inherit_code; +int objc_receiver_context; +int objc_public_flag; + +end ifobjc + +/* Tell yyparse how to print a token's value, if yydebug is set. */ + +#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL) +extern void yyprint (); +%} + +%% +program: /* empty */ + { if (pedantic) + pedwarn ("ANSI C forbids an empty source file"); + finish_file (); + } + | extdefs + { + /* In case there were missing closebraces, + get us back to the global binding level. */ + while (! global_bindings_p ()) + poplevel (0, 0, 0); + finish_file (); + } + ; + +/* the reason for the strange actions in this rule + is so that notype_initdecls when reached via datadef + can find a valid list of type and sc specs in $0. */ + +extdefs: + {$$ = NULL_TREE; } extdef + | extdefs {$$ = NULL_TREE; } extdef + ; + +extdef: + fndef + | datadef +ifobjc + | objcdef +end ifobjc + | ASM_KEYWORD '(' expr ')' ';' + { STRIP_NOPS ($3); + if ((TREE_CODE ($3) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST) + || TREE_CODE ($3) == STRING_CST) + assemble_asm ($3); + else + error ("argument of `asm' is not a constant string"); } + ; + +datadef: + setspecs notype_initdecls ';' + { if (pedantic) + error ("ANSI C forbids data definition with no type or storage class"); + else if (!flag_traditional) + warning ("data definition has no type or storage class"); + + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($1); } + | declmods setspecs notype_initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs setspecs initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods ';' + { pedwarn ("empty declaration"); } + | typed_declspecs ';' + { shadow_tag ($1); } + | error ';' + | error '}' + | ';' + { if (pedantic) + pedwarn ("ANSI C does not allow extra `;' outside of a function"); } + ; + +fndef: + typed_declspecs setspecs declarator + { if (! start_function ($1, $3, prefix_attributes, + NULL_TREE, 0)) + YYERROR1; + reinit_parse_for_function (); } + xdecls + { store_parm_decls (); } + compstmt_or_error + { finish_function (0); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs setspecs declarator error + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_declarator + { if (! start_function ($1, $3, prefix_attributes, + NULL_TREE, 0)) + YYERROR1; + reinit_parse_for_function (); } + xdecls + { store_parm_decls (); } + compstmt_or_error + { finish_function (0); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_declarator error + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | setspecs notype_declarator + { if (! start_function (NULL_TREE, $2, + prefix_attributes, NULL_TREE, 0)) + YYERROR1; + reinit_parse_for_function (); } + xdecls + { store_parm_decls (); } + compstmt_or_error + { finish_function (0); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($1); } + | setspecs notype_declarator error + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($1); } + ; + +identifier: + IDENTIFIER + | TYPENAME +ifobjc + | OBJECTNAME + | CLASSNAME +end ifobjc + ; + +unop: '&' + { $$ = ADDR_EXPR; } + | '-' + { $$ = NEGATE_EXPR; } + | '+' + { $$ = CONVERT_EXPR; } + | PLUSPLUS + { $$ = PREINCREMENT_EXPR; } + | MINUSMINUS + { $$ = PREDECREMENT_EXPR; } + | '~' + { $$ = BIT_NOT_EXPR; } + | '!' + { $$ = TRUTH_NOT_EXPR; } + ; + +expr: nonnull_exprlist + { $$ = build_compound_expr ($1); } + ; + +exprlist: + /* empty */ + { $$ = NULL_TREE; } + | nonnull_exprlist + ; + +nonnull_exprlist: + expr_no_commas + { $$ = build_tree_list (NULL_TREE, $1); } + | nonnull_exprlist ',' expr_no_commas + { chainon ($1, build_tree_list (NULL_TREE, $3)); } + ; + +unary_expr: + primary + | '*' cast_expr %prec UNARY + { $$ = build_indirect_ref ($2, "unary *"); } + /* __extension__ turns off -pedantic for following primary. */ + | EXTENSION + { $1 = pedantic; + pedantic = 0; } + cast_expr %prec UNARY + { $$ = $3; + pedantic = $1; } + | unop cast_expr %prec UNARY + { $$ = build_unary_op ($1, $2, 0); + overflow_warning ($$); } + /* Refer to the address of a label as a pointer. */ + | ANDAND identifier + { tree label = lookup_label ($2); + if (pedantic) + pedwarn ("ANSI C forbids `&&'"); + if (label == 0) + $$ = null_pointer_node; + else + { + TREE_USED (label) = 1; + $$ = build1 (ADDR_EXPR, ptr_type_node, label); + TREE_CONSTANT ($$) = 1; + } + } +/* This seems to be impossible on some machines, so let's turn it off. + You can use __builtin_next_arg to find the anonymous stack args. + | '&' ELLIPSIS + { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl)); + $$ = error_mark_node; + if (TREE_VALUE (tree_last (types)) == void_type_node) + error ("`&...' used in function with fixed number of arguments"); + else + { + if (pedantic) + pedwarn ("ANSI C forbids `&...'"); + $$ = tree_last (DECL_ARGUMENTS (current_function_decl)); + $$ = build_unary_op (ADDR_EXPR, $$, 0); + } } +*/ + | SIZEOF unary_expr %prec UNARY + { if (TREE_CODE ($2) == COMPONENT_REF + && DECL_BIT_FIELD (TREE_OPERAND ($2, 1))) + error ("`sizeof' applied to a bit-field"); + $$ = c_sizeof (TREE_TYPE ($2)); } + | SIZEOF '(' typename ')' %prec HYPERUNARY + { $$ = c_sizeof (groktypename ($3)); } + | ALIGNOF unary_expr %prec UNARY + { $$ = c_alignof_expr ($2); } + | ALIGNOF '(' typename ')' %prec HYPERUNARY + { $$ = c_alignof (groktypename ($3)); } + | REALPART cast_expr %prec UNARY + { $$ = build_unary_op (REALPART_EXPR, $2, 0); } + | IMAGPART cast_expr %prec UNARY + { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); } + ; + +cast_expr: + unary_expr + | '(' typename ')' cast_expr %prec UNARY + { tree type = groktypename ($2); + $$ = build_c_cast (type, $4); } + | '(' typename ')' '{' + { start_init (NULL_TREE, NULL, 0); + $2 = groktypename ($2); + really_start_incremental_init ($2); } + initlist_maybe_comma '}' %prec UNARY + { char *name; + tree result = pop_init_level (0); + tree type = $2; + finish_init (); + + if (pedantic) + pedwarn ("ANSI C forbids constructor expressions"); + if (TYPE_NAME (type) != 0) + { + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + name = IDENTIFIER_POINTER (TYPE_NAME (type)); + else + name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + } + else + name = ""; + $$ = result; + if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0) + { + int failure = complete_array_type (type, $$, 1); + if (failure) + abort (); + } + } + ; + +expr_no_commas: + cast_expr + | expr_no_commas '+' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '-' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '*' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '/' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '%' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas LSHIFT expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas RSHIFT expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas ARITHCOMPARE expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas EQCOMPARE expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '&' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '|' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas '^' expr_no_commas + { $$ = parser_build_binary_op ($2, $1, $3); } + | expr_no_commas ANDAND expr_no_commas + { $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $3); } + | expr_no_commas OROR expr_no_commas + { $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $3); } + | expr_no_commas '?' xexpr ':' expr_no_commas + { $$ = build_conditional_expr ($1, $3, $5); } + | expr_no_commas '=' expr_no_commas + { $$ = build_modify_expr ($1, NOP_EXPR, $3); + C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); } + | expr_no_commas ASSIGN expr_no_commas + { $$ = build_modify_expr ($1, $2, $3); + /* This inhibits warnings in truthvalue_conversion. */ + C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); } + ; + +primary: + IDENTIFIER + { + $$ = lastiddecl; + if (!$$ || $$ == error_mark_node) + { + if (yychar == YYEMPTY) + yychar = YYLEX; + if (yychar == '(') + { +ifobjc + tree decl; + + if (objc_receiver_context + && ! (objc_receiver_context + && strcmp (IDENTIFIER_POINTER ($1), "super"))) + /* we have a message to super */ + $$ = get_super_receiver (); + else if (objc_method_context + && (decl = is_ivar (objc_ivar_chain, $1))) + { + if (is_private (decl)) + $$ = error_mark_node; + else + $$ = build_ivar_reference ($1); + } + else +end ifobjc + { + /* Ordinary implicit function declaration. */ + $$ = implicitly_declare ($1); + assemble_external ($$); + TREE_USED ($$) = 1; + } + } + else if (current_function_decl == 0) + { + error ("`%s' undeclared here (not in a function)", + IDENTIFIER_POINTER ($1)); + $$ = error_mark_node; + } + else + { +ifobjc + tree decl; + + if (objc_receiver_context + && ! strcmp (IDENTIFIER_POINTER ($1), "super")) + /* we have a message to super */ + $$ = get_super_receiver (); + else if (objc_method_context + && (decl = is_ivar (objc_ivar_chain, $1))) + { + if (is_private (decl)) + $$ = error_mark_node; + else + $$ = build_ivar_reference ($1); + } + else +end ifobjc + { + if (IDENTIFIER_GLOBAL_VALUE ($1) != error_mark_node + || IDENTIFIER_ERROR_LOCUS ($1) != current_function_decl) + { + error ("`%s' undeclared (first use this function)", + IDENTIFIER_POINTER ($1)); + + if (! undeclared_variable_notice) + { + error ("(Each undeclared identifier is reported only once"); + error ("for each function it appears in.)"); + undeclared_variable_notice = 1; + } + } + $$ = error_mark_node; + /* Prevent repeated error messages. */ + IDENTIFIER_GLOBAL_VALUE ($1) = error_mark_node; + IDENTIFIER_ERROR_LOCUS ($1) = current_function_decl; + } + } + } + else if (TREE_TYPE ($$) == error_mark_node) + $$ = error_mark_node; + else if (C_DECL_ANTICIPATED ($$)) + { + /* The first time we see a build-in function used, + if it has not been declared. */ + C_DECL_ANTICIPATED ($$) = 0; + if (yychar == YYEMPTY) + yychar = YYLEX; + if (yychar == '(') + { + /* Omit the implicit declaration we + would ordinarily do, so we don't lose + the actual built in type. + But print a diagnostic for the mismatch. */ +ifobjc + if (objc_method_context + && is_ivar (objc_ivar_chain, $1)) + error ("Instance variable `%s' implicitly declared as function", + IDENTIFIER_POINTER (DECL_NAME ($$))); + else +end ifobjc + if (TREE_CODE ($$) != FUNCTION_DECL) + error ("`%s' implicitly declared as function", + IDENTIFIER_POINTER (DECL_NAME ($$))); + else if ((TYPE_MODE (TREE_TYPE (TREE_TYPE ($$))) + != TYPE_MODE (integer_type_node)) + && (TREE_TYPE (TREE_TYPE ($$)) + != void_type_node)) + pedwarn ("type mismatch in implicit declaration for built-in function `%s'", + IDENTIFIER_POINTER (DECL_NAME ($$))); + /* If it really returns void, change that to int. */ + if (TREE_TYPE (TREE_TYPE ($$)) == void_type_node) + TREE_TYPE ($$) + = build_function_type (integer_type_node, + TYPE_ARG_TYPES (TREE_TYPE ($$))); + } + else + pedwarn ("built-in function `%s' used without declaration", + IDENTIFIER_POINTER (DECL_NAME ($$))); + + /* Do what we would ordinarily do when a fn is used. */ + assemble_external ($$); + TREE_USED ($$) = 1; + } + else + { + assemble_external ($$); + TREE_USED ($$) = 1; +ifobjc + /* we have a definition - still check if iVariable */ + + if (!objc_receiver_context + || (objc_receiver_context + && strcmp (IDENTIFIER_POINTER ($1), "super"))) + { + tree decl; + + if (objc_method_context + && (decl = is_ivar (objc_ivar_chain, $1))) + { + if (IDENTIFIER_LOCAL_VALUE ($1)) + warning ("local declaration of `%s' hides instance variable", + IDENTIFIER_POINTER ($1)); + else + { + if (is_private (decl)) + $$ = error_mark_node; + else + $$ = build_ivar_reference ($1); + } + } + } + else /* we have a message to super */ + $$ = get_super_receiver (); +end ifobjc + } + + if (TREE_CODE ($$) == CONST_DECL) + { + $$ = DECL_INITIAL ($$); + /* This is to prevent an enum whose value is 0 + from being considered a null pointer constant. */ + $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$); + TREE_CONSTANT ($$) = 1; + } + } + | CONSTANT + | string + { $$ = combine_strings ($1); } + | '(' expr ')' + { char class = TREE_CODE_CLASS (TREE_CODE ($2)); + if (class == 'e' || class == '1' + || class == '2' || class == '<') + C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK); + $$ = $2; } + | '(' error ')' + { $$ = error_mark_node; } + | '(' + { if (current_function_decl == 0) + { + error ("braced-group within expression allowed only inside a function"); + YYERROR; + } + /* We must force a BLOCK for this level + so that, if it is not expanded later, + there is a way to turn off the entire subtree of blocks + that are contained in it. */ + keep_next_level (); + push_iterator_stack (); + push_label_level (); + $$ = expand_start_stmt_expr (); } + compstmt ')' + { tree rtl_exp; + if (pedantic) + pedwarn ("ANSI C forbids braced-groups within expressions"); + pop_iterator_stack (); + pop_label_level (); + rtl_exp = expand_end_stmt_expr ($2); + /* The statements have side effects, so the group does. */ + TREE_SIDE_EFFECTS (rtl_exp) = 1; + + if (TREE_CODE ($3) == BLOCK) + { + /* Make a BIND_EXPR for the BLOCK already made. */ + $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp), + NULL_TREE, rtl_exp, $3); + /* Remove the block from the tree at this point. + It gets put back at the proper place + when the BIND_EXPR is expanded. */ + delete_block ($3); + } + else + $$ = $3; + } + | primary '(' exprlist ')' %prec '.' + { $$ = build_function_call ($1, $3); } + | primary '[' expr ']' %prec '.' + { $$ = build_array_ref ($1, $3); } + | primary '.' identifier + { +ifobjc + if (doing_objc_thang) + { + if (is_public ($1, $3)) + $$ = build_component_ref ($1, $3); + else + $$ = error_mark_node; + } + else +end ifobjc + $$ = build_component_ref ($1, $3); + } + | primary POINTSAT identifier + { + tree expr = build_indirect_ref ($1, "->"); + +ifobjc + if (doing_objc_thang) + { + if (is_public (expr, $3)) + $$ = build_component_ref (expr, $3); + else + $$ = error_mark_node; + } + else +end ifobjc + $$ = build_component_ref (expr, $3); + } + | primary PLUSPLUS + { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); } + | primary MINUSMINUS + { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); } +ifobjc + | objcmessageexpr + { $$ = build_message_expr ($1); } + | objcselectorexpr + { $$ = build_selector_expr ($1); } + | objcprotocolexpr + { $$ = build_protocol_expr ($1); } + | objcencodeexpr + { $$ = build_encode_expr ($1); } + | objc_string + { $$ = build_objc_string_object ($1); } +end ifobjc + ; + +/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */ +string: + STRING + | string STRING + { $$ = chainon ($1, $2); } + ; + +ifobjc +/* Produces an OBJC_STRING_CST with perhaps more OBJC_STRING_CSTs chained + onto it. */ +objc_string: + OBJC_STRING + | objc_string OBJC_STRING + { $$ = chainon ($1, $2); } + ; +end ifobjc + +xdecls: + /* empty */ + | datadecls + | datadecls ELLIPSIS + /* ... is used here to indicate a varargs function. */ + { c_mark_varargs (); + if (pedantic) + pedwarn ("ANSI C does not permit use of `varargs.h'"); } + ; + +/* The following are analogous to lineno_decl, decls and decl + except that they do not allow nested functions. + They are used for old-style parm decls. */ +lineno_datadecl: + save_filename save_lineno datadecl + { } + ; + +datadecls: + lineno_datadecl + | errstmt + | datadecls lineno_datadecl + | lineno_datadecl errstmt + ; + +datadecl: + typed_declspecs setspecs initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs ';' + { shadow_tag_warned ($1, 1); + pedwarn ("empty declaration"); } + | declmods ';' + { pedwarn ("empty declaration"); } + ; + +/* This combination which saves a lineno before a decl + is the normal thing to use, rather than decl itself. + This is to avoid shift/reduce conflicts in contexts + where statement labels are allowed. */ +lineno_decl: + save_filename save_lineno decl + { } + ; + +decls: + lineno_decl + | errstmt + | decls lineno_decl + | lineno_decl errstmt + ; + +/* records the type and storage class specs to use for processing + the declarators that follow. + Maintains a stack of outer-level values of current_declspecs, + for the sake of parm declarations nested in function declarators. */ +setspecs: /* empty */ + { $$ = suspend_momentary (); + pending_xref_error (); + declspec_stack = tree_cons (prefix_attributes, + current_declspecs, + declspec_stack); + current_declspecs = $0; + prefix_attributes = NULL_TREE; } + ; + +setattrs: /* empty */ + { prefix_attributes = chainon (prefix_attributes, $0); } + ; + +decl: + typed_declspecs setspecs initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_initdecls ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs setspecs nested_function + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_nested_function + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs ';' + { shadow_tag ($1); } + | declmods ';' + { pedwarn ("empty declaration"); } + ; + +/* Declspecs which contain at least one type specifier or typedef name. + (Just `const' or `volatile' is not enough.) + A typedef'd name following these is taken as a name to be declared. */ + +typed_declspecs: + typespec reserved_declspecs + { $$ = tree_cons (NULL_TREE, $1, $2); } + | declmods typespec reserved_declspecs + { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); } + ; + +reserved_declspecs: /* empty */ + { $$ = NULL_TREE; } + | reserved_declspecs typespecqual_reserved + { $$ = tree_cons (NULL_TREE, $2, $1); } + | reserved_declspecs SCSPEC + { if (extra_warnings) + warning ("`%s' is not at beginning of declaration", + IDENTIFIER_POINTER ($2)); + $$ = tree_cons (NULL_TREE, $2, $1); } + ; + +/* List of just storage classes and type modifiers. + A declaration can start with just this, but then it cannot be used + to redeclare a typedef-name. */ + +declmods: + TYPE_QUAL + { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); + TREE_STATIC ($$) = 1; } + | SCSPEC + { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); } + | declmods TYPE_QUAL + { $$ = tree_cons (NULL_TREE, $2, $1); + TREE_STATIC ($$) = 1; } + | declmods SCSPEC + { if (extra_warnings && TREE_STATIC ($1)) + warning ("`%s' is not at beginning of declaration", + IDENTIFIER_POINTER ($2)); + $$ = tree_cons (NULL_TREE, $2, $1); + TREE_STATIC ($$) = TREE_STATIC ($1); } + ; + + +/* Used instead of declspecs where storage classes are not allowed + (that is, for typenames and structure components). + Don't accept a typedef-name if anything but a modifier precedes it. */ + +typed_typespecs: + typespec reserved_typespecquals + { $$ = tree_cons (NULL_TREE, $1, $2); } + | nonempty_type_quals typespec reserved_typespecquals + { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); } + ; + +reserved_typespecquals: /* empty */ + { $$ = NULL_TREE; } + | reserved_typespecquals typespecqual_reserved + { $$ = tree_cons (NULL_TREE, $2, $1); } + ; + +/* A typespec (but not a type qualifier). + Once we have seen one of these in a declaration, + if a typedef name appears then it is being redeclared. */ + +typespec: TYPESPEC + | structsp + | TYPENAME + { /* For a typedef name, record the meaning, not the name. + In case of `foo foo, bar;'. */ + $$ = lookup_name ($1); } +ifobjc + | CLASSNAME protocolrefs + { $$ = get_static_reference ($1, $2); } + | OBJECTNAME protocolrefs + { $$ = get_object_reference ($2); } +end ifobjc + | TYPEOF '(' expr ')' + { $$ = TREE_TYPE ($3); } + | TYPEOF '(' typename ')' + { $$ = groktypename ($3); } + ; + +/* A typespec that is a reserved word, or a type qualifier. */ + +typespecqual_reserved: TYPESPEC + | TYPE_QUAL + | structsp + ; + +initdecls: + initdcl + | initdecls ',' initdcl + ; + +notype_initdecls: + notype_initdcl + | notype_initdecls ',' initdcl + ; + +maybeasm: + /* empty */ + { $$ = NULL_TREE; } + | ASM_KEYWORD '(' string ')' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); + $$ = $3; + } + ; + +initdcl: + declarator maybeasm maybe_attribute '=' + { $$ = start_decl ($1, current_declspecs, 1, + $3, prefix_attributes); + start_init ($$, $2, global_bindings_p ()); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { finish_init (); + finish_decl ($5, $6, $2); } + | declarator maybeasm maybe_attribute + { tree d = start_decl ($1, current_declspecs, 0, + $3, prefix_attributes); + finish_decl (d, NULL_TREE, $2); + } + ; + +notype_initdcl: + notype_declarator maybeasm maybe_attribute '=' + { $$ = start_decl ($1, current_declspecs, 1, + $3, prefix_attributes); + start_init ($$, $2, global_bindings_p ()); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { finish_init (); + decl_attributes ($5, $3, prefix_attributes); + finish_decl ($5, $6, $2); } + | notype_declarator maybeasm maybe_attribute + { tree d = start_decl ($1, current_declspecs, 0, + $3, prefix_attributes); + finish_decl (d, NULL_TREE, $2); } + ; +/* the * rules are dummies to accept the Apollo extended syntax + so that the header files compile. */ +maybe_attribute: + /* empty */ + { $$ = NULL_TREE; } + | attributes + { $$ = $1; } + ; + +attributes: + attribute + { $$ = $1; } + | attributes attribute + { $$ = chainon ($1, $2); } + ; + +attribute: + ATTRIBUTE '(' '(' attribute_list ')' ')' + { $$ = $4; } + ; + +attribute_list: + attrib + { $$ = $1; } + | attribute_list ',' attrib + { $$ = chainon ($1, $3); } + ; + +attrib: + /* empty */ + { $$ = NULL_TREE; } + | any_word + { $$ = build_tree_list ($1, NULL_TREE); } + | any_word '(' IDENTIFIER ')' + { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); } + | any_word '(' IDENTIFIER ',' nonnull_exprlist ')' + { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); } + | any_word '(' exprlist ')' + { $$ = build_tree_list ($1, $3); } + ; + +/* This still leaves out most reserved keywords, + shouldn't we include them? */ + +any_word: + identifier + | SCSPEC + | TYPESPEC + | TYPE_QUAL + ; + +/* Initializers. `init' is the entry point. */ + +init: + expr_no_commas + | '{' + { really_start_incremental_init (NULL_TREE); + /* Note that the call to clear_momentary + is in process_init_element. */ + push_momentary (); } + initlist_maybe_comma '}' + { $$ = pop_init_level (0); + if ($$ == error_mark_node + && ! (yychar == STRING || yychar == CONSTANT)) + pop_momentary (); + else + pop_momentary_nofree (); } + + | error + { $$ = error_mark_node; } + ; + +/* `initlist_maybe_comma' is the guts of an initializer in braces. */ +initlist_maybe_comma: + /* empty */ + { if (pedantic) + pedwarn ("ANSI C forbids empty initializer braces"); } + | initlist1 maybecomma + ; + +initlist1: + initelt + | initlist1 ',' initelt + ; + +/* `initelt' is a single element of an initializer. + It may use braces. */ +initelt: + expr_no_commas + { process_init_element ($1); } + | '{' + { push_init_level (0); } + initlist_maybe_comma '}' + { process_init_element (pop_init_level (0)); } + | error + /* These are for labeled elements. The syntax for an array element + initializer conflicts with the syntax for an Objective-C message, + so don't include these productions in the Objective-C grammar. */ +ifc + | '[' expr_no_commas ELLIPSIS expr_no_commas ']' '=' + { set_init_index ($2, $4); } + initelt + | '[' expr_no_commas ']' '=' + { set_init_index ($2, NULL_TREE); } + initelt + | '[' expr_no_commas ']' + { set_init_index ($2, NULL_TREE); } + initelt +end ifc + | identifier ':' + { set_init_label ($1); } + initelt + | '.' identifier '=' + { set_init_label ($2); } + initelt + ; + +nested_function: + declarator + { push_c_function_context (); + if (! start_function (current_declspecs, $1, + prefix_attributes, NULL_TREE, 1)) + { + pop_c_function_context (); + YYERROR1; + } + reinit_parse_for_function (); } + xdecls + { store_parm_decls (); } +/* This used to use compstmt_or_error. + That caused a bug with input `f(g) int g {}', + where the use of YYERROR1 above caused an error + which then was handled by compstmt_or_error. + There followed a repeated execution of that same rule, + which called YYERROR1 again, and so on. */ + compstmt + { finish_function (1); + pop_c_function_context (); } + ; + +notype_nested_function: + notype_declarator + { push_c_function_context (); + if (! start_function (current_declspecs, $1, + prefix_attributes, NULL_TREE, 1)) + { + pop_c_function_context (); + YYERROR1; + } + reinit_parse_for_function (); } + xdecls + { store_parm_decls (); } +/* This used to use compstmt_or_error. + That caused a bug with input `f(g) int g {}', + where the use of YYERROR1 above caused an error + which then was handled by compstmt_or_error. + There followed a repeated execution of that same rule, + which called YYERROR1 again, and so on. */ + compstmt + { finish_function (1); + pop_c_function_context (); } + ; + +/* Any kind of declarator (thus, all declarators allowed + after an explicit typespec). */ + +declarator: + after_type_declarator + | notype_declarator + ; + +/* A declarator that is allowed only after an explicit typespec. */ + +after_type_declarator: + '(' after_type_declarator ')' + { $$ = $2; } + | after_type_declarator '(' parmlist_or_identifiers %prec '.' + { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); } +/* | after_type_declarator '(' error ')' %prec '.' + { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE); + poplevel (0, 0, 0); } */ + | after_type_declarator '[' expr ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, $3); } + | after_type_declarator '[' ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); } + | '*' type_quals after_type_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | attributes setattrs after_type_declarator + { $$ = $3; } + | TYPENAME +ifobjc + | OBJECTNAME +end ifobjc + ; + +/* Kinds of declarator that can appear in a parameter list + in addition to notype_declarator. This is like after_type_declarator + but does not allow a typedef name in parentheses as an identifier + (because it would conflict with a function with that typedef as arg). */ + +parm_declarator: + parm_declarator '(' parmlist_or_identifiers %prec '.' + { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); } +/* | parm_declarator '(' error ')' %prec '.' + { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE); + poplevel (0, 0, 0); } */ + | parm_declarator '[' expr ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, $3); } + | parm_declarator '[' ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); } + | '*' type_quals parm_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | attributes setattrs parm_declarator + { $$ = $3; } + | TYPENAME + ; + +/* A declarator allowed whether or not there has been + an explicit typespec. These cannot redeclare a typedef-name. */ + +notype_declarator: + notype_declarator '(' parmlist_or_identifiers %prec '.' + { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); } +/* | notype_declarator '(' error ')' %prec '.' + { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE); + poplevel (0, 0, 0); } */ + | '(' notype_declarator ')' + { $$ = $2; } + | '*' type_quals notype_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | notype_declarator '[' expr ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, $3); } + | notype_declarator '[' ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); } + | attributes setattrs notype_declarator + { $$ = $3; } + | IDENTIFIER + ; + +structsp: + STRUCT identifier '{' + { $$ = start_struct (RECORD_TYPE, $2); + /* Start scope of tag before parsing components. */ + } + component_decl_list '}' maybe_attribute + { $$ = finish_struct ($4, $5, $7); } + | STRUCT '{' component_decl_list '}' maybe_attribute + { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE), + $3, $5); + } + | STRUCT identifier + { $$ = xref_tag (RECORD_TYPE, $2); } + | UNION identifier '{' + { $$ = start_struct (UNION_TYPE, $2); } + component_decl_list '}' maybe_attribute + { $$ = finish_struct ($4, $5, $7); } + | UNION '{' component_decl_list '}' maybe_attribute + { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE), + $3, $5); + } + | UNION identifier + { $$ = xref_tag (UNION_TYPE, $2); } + | ENUM identifier '{' + { $3 = suspend_momentary (); + $$ = start_enum ($2); } + enumlist maybecomma_warn '}' maybe_attribute + { $$ = finish_enum ($4, nreverse ($5), $8); + resume_momentary ($3); } + | ENUM '{' + { $2 = suspend_momentary (); + $$ = start_enum (NULL_TREE); } + enumlist maybecomma_warn '}' maybe_attribute + { $$ = finish_enum ($3, nreverse ($4), $7); + resume_momentary ($2); } + | ENUM identifier + { $$ = xref_tag (ENUMERAL_TYPE, $2); } + ; + +maybecomma: + /* empty */ + | ',' + ; + +maybecomma_warn: + /* empty */ + | ',' + { if (pedantic) pedwarn ("comma at end of enumerator list"); } + ; + +component_decl_list: + component_decl_list2 + { $$ = $1; } + | component_decl_list2 component_decl + { $$ = chainon ($1, $2); + pedwarn ("no semicolon at end of struct or union"); } + ; + +component_decl_list2: /* empty */ + { $$ = NULL_TREE; } + | component_decl_list2 component_decl ';' + { $$ = chainon ($1, $2); } + | component_decl_list2 ';' + { if (pedantic) + pedwarn ("extra semicolon in struct or union specified"); } +ifobjc + /* foo(sizeof(struct{ @defs(ClassName)})); */ + | DEFS '(' CLASSNAME ')' + { + tree interface = lookup_interface ($3); + + if (interface) + $$ = get_class_ivars (interface); + else + { + error ("Cannot find interface declaration for `%s'", + IDENTIFIER_POINTER ($3)); + $$ = NULL_TREE; + } + } +end ifobjc + ; + +/* There is a shift-reduce conflict here, because `components' may + start with a `typename'. It happens that shifting (the default resolution) + does the right thing, because it treats the `typename' as part of + a `typed_typespecs'. + + It is possible that this same technique would allow the distinction + between `notype_initdecls' and `initdecls' to be eliminated. + But I am being cautious and not trying it. */ + +component_decl: + typed_typespecs setspecs components + { $$ = $3; + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_typespecs + { if (pedantic) + pedwarn ("ANSI C forbids member declarations with no members"); + shadow_tag($1); + $$ = NULL_TREE; } + | nonempty_type_quals setspecs components + { $$ = $3; + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | nonempty_type_quals + { if (pedantic) + pedwarn ("ANSI C forbids member declarations with no members"); + shadow_tag($1); + $$ = NULL_TREE; } + | error + { $$ = NULL_TREE; } + ; + +components: + component_declarator + | components ',' component_declarator + { $$ = chainon ($1, $3); } + ; + +component_declarator: + save_filename save_lineno declarator maybe_attribute + { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE); + decl_attributes ($$, $4, prefix_attributes); } + | save_filename save_lineno + declarator ':' expr_no_commas maybe_attribute + { $$ = grokfield ($1, $2, $3, current_declspecs, $5); + decl_attributes ($$, $6, prefix_attributes); } + | save_filename save_lineno ':' expr_no_commas maybe_attribute + { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4); + decl_attributes ($$, $5, prefix_attributes); } + ; + +/* We chain the enumerators in reverse order. + They are put in forward order where enumlist is used. + (The order used to be significant, but no longer is so. + However, we still maintain the order, just to be clean.) */ + +enumlist: + enumerator + | enumlist ',' enumerator + { if ($1 == error_mark_node) + $$ = $1; + else + $$ = chainon ($3, $1); } + | error + { $$ = error_mark_node; } + ; + + +enumerator: + identifier + { $$ = build_enumerator ($1, NULL_TREE); } + | identifier '=' expr_no_commas + { $$ = build_enumerator ($1, $3); } + ; + +typename: + typed_typespecs absdcl + { $$ = build_tree_list ($1, $2); } + | nonempty_type_quals absdcl + { $$ = build_tree_list ($1, $2); } + ; + +absdcl: /* an absolute declarator */ + /* empty */ + { $$ = NULL_TREE; } + | absdcl1 + ; + +nonempty_type_quals: + TYPE_QUAL + { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); } + | nonempty_type_quals TYPE_QUAL + { $$ = tree_cons (NULL_TREE, $2, $1); } + ; + +type_quals: + /* empty */ + { $$ = NULL_TREE; } + | type_quals TYPE_QUAL + { $$ = tree_cons (NULL_TREE, $2, $1); } + ; + +absdcl1: /* a nonempty absolute declarator */ + '(' absdcl1 ')' + { $$ = $2; } + /* `(typedef)1' is `int'. */ + | '*' type_quals absdcl1 %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | '*' type_quals %prec UNARY + { $$ = make_pointer_declarator ($2, NULL_TREE); } + | absdcl1 '(' parmlist %prec '.' + { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); } + | absdcl1 '[' expr ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, $3); } + | absdcl1 '[' ']' %prec '.' + { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); } + | '(' parmlist %prec '.' + { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); } + | '[' expr ']' %prec '.' + { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); } + | '[' ']' %prec '.' + { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); } + | attributes setattrs absdcl1 + { $$ = $3; } + ; + +/* at least one statement, the first of which parses without error. */ +/* stmts is used only after decls, so an invalid first statement + is actually regarded as an invalid decl and part of the decls. */ + +stmts: + lineno_stmt_or_labels + { + if (pedantic && $1) + pedwarn ("ANSI C forbids label at end of compound statement"); + } + ; + +lineno_stmt_or_labels: + lineno_stmt_or_label + | lineno_stmt_or_labels lineno_stmt_or_label + { $$ = $2; } + | lineno_stmt_or_labels errstmt + { $$ = 0; } + ; + +xstmts: + /* empty */ + | stmts + ; + +errstmt: error ';' + ; + +pushlevel: /* empty */ + { emit_line_note (input_filename, lineno); + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); +ifobjc + if (objc_method_context) + add_objc_decls (); +end ifobjc + } + ; + +/* Read zero or more forward-declarations for labels + that nested functions can jump to. */ +maybe_label_decls: + /* empty */ + | label_decls + { if (pedantic) + pedwarn ("ANSI C forbids label declarations"); } + ; + +label_decls: + label_decl + | label_decls label_decl + ; + +label_decl: + LABEL identifiers_or_typenames ';' + { tree link; + for (link = $2; link; link = TREE_CHAIN (link)) + { + tree label = shadow_label (TREE_VALUE (link)); + C_DECLARED_LABEL_FLAG (label) = 1; + declare_nonlocal_label (label); + } + } + ; + +/* This is the body of a function definition. + It causes syntax errors to ignore to the next openbrace. */ +compstmt_or_error: + compstmt + {} + | error compstmt + ; + +compstmt: '{' '}' + { $$ = convert (void_type_node, integer_zero_node); } + | '{' pushlevel maybe_label_decls decls xstmts '}' + { emit_line_note (input_filename, lineno); + expand_end_bindings (getdecls (), 1, 0); + $$ = poplevel (1, 1, 0); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); } + | '{' pushlevel maybe_label_decls error '}' + { emit_line_note (input_filename, lineno); + expand_end_bindings (getdecls (), kept_level_p (), 0); + $$ = poplevel (kept_level_p (), 0, 0); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); } + | '{' pushlevel maybe_label_decls stmts '}' + { emit_line_note (input_filename, lineno); + expand_end_bindings (getdecls (), kept_level_p (), 0); + $$ = poplevel (kept_level_p (), 0, 0); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); } + ; + +/* Value is number of statements counted as of the closeparen. */ +simple_if: + if_prefix lineno_labeled_stmt +/* Make sure expand_end_cond is run once + for each call to expand_start_cond. + Otherwise a crash is likely. */ + | if_prefix error + ; + +if_prefix: + IF '(' expr ')' + { emit_line_note ($-1, $0); + expand_start_cond (truthvalue_conversion ($3), 0); + $$ = stmt_count; + if_stmt_file = $-1; + if_stmt_line = $0; + position_after_white_space (); } + ; + +/* This is a subroutine of stmt. + It is used twice, once for valid DO statements + and once for catching errors in parsing the end test. */ +do_stmt_start: + DO + { stmt_count++; + emit_line_note ($-1, $0); + /* See comment in `while' alternative, above. */ + emit_nop (); + expand_start_loop_continue_elsewhere (1); + position_after_white_space (); } + lineno_labeled_stmt WHILE + { expand_loop_continue_here (); } + ; + +save_filename: + { $$ = input_filename; } + ; + +save_lineno: + { $$ = lineno; } + ; + +lineno_labeled_stmt: + save_filename save_lineno stmt + { } +/* | save_filename save_lineno error + { } +*/ + | save_filename save_lineno label lineno_labeled_stmt + { } + ; + +lineno_stmt_or_label: + save_filename save_lineno stmt_or_label + { $$ = $3; } + ; + +stmt_or_label: + stmt + { $$ = 0; } + | label + { $$ = 1; } + ; + +/* Parse a single real statement, not including any labels. */ +stmt: + compstmt + { stmt_count++; } + | all_iter_stmt + | expr ';' + { stmt_count++; + emit_line_note ($-1, $0); +/* It appears that this should not be done--that a non-lvalue array + shouldn't get an error if the value isn't used. + Section 3.2.2.1 says that an array lvalue gets converted to a pointer + if it appears as a top-level expression, + but says nothing about non-lvalue arrays. */ +#if 0 + /* Call default_conversion to get an error + on referring to a register array if pedantic. */ + if (TREE_CODE (TREE_TYPE ($1)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE ($1)) == FUNCTION_TYPE) + $1 = default_conversion ($1); +#endif + iterator_expand ($1); + clear_momentary (); } + | simple_if ELSE + { expand_start_else (); + $1 = stmt_count; + position_after_white_space (); } + lineno_labeled_stmt + { expand_end_cond (); + if (extra_warnings && stmt_count == $1) + warning ("empty body in an else-statement"); } + | simple_if %prec IF + { expand_end_cond (); + /* This warning is here instead of in simple_if, because we + do not want a warning if an empty if is followed by an + else statement. Increment stmt_count so we don't + give a second error if this is a nested `if'. */ + if (extra_warnings && stmt_count++ == $1) + warning_with_file_and_line (if_stmt_file, if_stmt_line, + "empty body in an if-statement"); } +/* Make sure expand_end_cond is run once + for each call to expand_start_cond. + Otherwise a crash is likely. */ + | simple_if ELSE error + { expand_end_cond (); } + | WHILE + { stmt_count++; + emit_line_note ($-1, $0); + /* The emit_nop used to come before emit_line_note, + but that made the nop seem like part of the preceding line. + And that was confusing when the preceding line was + inside of an if statement and was not really executed. + I think it ought to work to put the nop after the line number. + We will see. --rms, July 15, 1991. */ + emit_nop (); } + '(' expr ')' + { /* Don't start the loop till we have succeeded + in parsing the end test. This is to make sure + that we end every loop we start. */ + expand_start_loop (1); + emit_line_note (input_filename, lineno); + expand_exit_loop_if_false (NULL_PTR, + truthvalue_conversion ($4)); + position_after_white_space (); } + lineno_labeled_stmt + { expand_end_loop (); } + | do_stmt_start + '(' expr ')' ';' + { emit_line_note (input_filename, lineno); + expand_exit_loop_if_false (NULL_PTR, + truthvalue_conversion ($3)); + expand_end_loop (); + clear_momentary (); } +/* This rule is needed to make sure we end every loop we start. */ + | do_stmt_start error + { expand_end_loop (); + clear_momentary (); } + | FOR + '(' xexpr ';' + { stmt_count++; + emit_line_note ($-1, $0); + /* See comment in `while' alternative, above. */ + emit_nop (); + if ($3) c_expand_expr_stmt ($3); + /* Next step is to call expand_start_loop_continue_elsewhere, + but wait till after we parse the entire for (...). + Otherwise, invalid input might cause us to call that + fn without calling expand_end_loop. */ + } + xexpr ';' + /* Can't emit now; wait till after expand_start_loop... */ + { $7 = lineno; + $$ = input_filename; } + xexpr ')' + { + /* Start the loop. Doing this after parsing + all the expressions ensures we will end the loop. */ + expand_start_loop_continue_elsewhere (1); + /* Emit the end-test, with a line number. */ + emit_line_note ($8, $7); + if ($6) + expand_exit_loop_if_false (NULL_PTR, + truthvalue_conversion ($6)); + /* Don't let the tree nodes for $9 be discarded by + clear_momentary during the parsing of the next stmt. */ + push_momentary (); + $7 = lineno; + $8 = input_filename; + position_after_white_space (); } + lineno_labeled_stmt + { /* Emit the increment expression, with a line number. */ + emit_line_note ($8, $7); + expand_loop_continue_here (); + if ($9) + c_expand_expr_stmt ($9); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); + expand_end_loop (); } + | SWITCH '(' expr ')' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_start_case ($3); + /* Don't let the tree nodes for $3 be discarded by + clear_momentary during the parsing of the next stmt. */ + push_momentary (); + position_after_white_space (); } + lineno_labeled_stmt + { expand_end_case ($3); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); } + | BREAK ';' + { stmt_count++; + emit_line_note ($-1, $0); + if ( ! expand_exit_something ()) + error ("break statement not within loop or switch"); } + | CONTINUE ';' + { stmt_count++; + emit_line_note ($-1, $0); + if (! expand_continue_loop (NULL_PTR)) + error ("continue statement not within a loop"); } + | RETURN ';' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_return (NULL_TREE); } + | RETURN expr ';' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_return ($2); } + | ASM_KEYWORD maybe_type_qual '(' expr ')' ';' + { stmt_count++; + emit_line_note ($-1, $0); + STRIP_NOPS ($4); + if ((TREE_CODE ($4) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST) + || TREE_CODE ($4) == STRING_CST) + expand_asm ($4); + else + error ("argument of `asm' is not a constant string"); } + /* This is the case with just output operands. */ + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); } + /* This is the case with input operands as well. */ + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_asm_operands ($4, $6, $8, NULL_TREE, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); } + /* This is the case with clobbered registers as well. */ + | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' + asm_operands ':' asm_clobbers ')' ';' + { stmt_count++; + emit_line_note ($-1, $0); + c_expand_asm_operands ($4, $6, $8, $10, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); } + | GOTO identifier ';' + { tree decl; + stmt_count++; + emit_line_note ($-1, $0); + decl = lookup_label ($2); + if (decl != 0) + { + TREE_USED (decl) = 1; + expand_goto (decl); + } + } + | GOTO '*' expr ';' + { stmt_count++; + emit_line_note ($-1, $0); + expand_computed_goto (convert (ptr_type_node, $3)); } + | ';' + ; + +all_iter_stmt: + all_iter_stmt_simple +/* | all_iter_stmt_with_decl */ + ; + +all_iter_stmt_simple: + FOR '(' primary ')' + { + /* The value returned by this action is */ + /* 1 if everything is OK */ + /* 0 in case of error or already bound iterator */ + + $$ = 0; + if (TREE_CODE ($3) != VAR_DECL) + error ("invalid `for (ITERATOR)' syntax"); + else if (! ITERATOR_P ($3)) + error ("`%s' is not an iterator", + IDENTIFIER_POINTER (DECL_NAME ($3))); + else if (ITERATOR_BOUND_P ($3)) + error ("`for (%s)' inside expansion of same iterator", + IDENTIFIER_POINTER (DECL_NAME ($3))); + else + { + $$ = 1; + iterator_for_loop_start ($3); + } + } + lineno_labeled_stmt + { + if ($5) + iterator_for_loop_end ($3); + } + +/* This really should allow any kind of declaration, + for generality. Fix it before turning it back on. + +all_iter_stmt_with_decl: + FOR '(' ITERATOR pushlevel setspecs iterator_spec ')' + { +*/ /* The value returned by this action is */ + /* 1 if everything is OK */ + /* 0 in case of error or already bound iterator */ +/* + iterator_for_loop_start ($6); + } + lineno_labeled_stmt + { + iterator_for_loop_end ($6); + emit_line_note (input_filename, lineno); + expand_end_bindings (getdecls (), 1, 0); + $$ = poplevel (1, 1, 0); + if (yychar == CONSTANT || yychar == STRING) + pop_momentary_nofree (); + else + pop_momentary (); + } +*/ + +/* Any kind of label, including jump labels and case labels. + ANSI C accepts labels only before statements, but we allow them + also at the end of a compound statement. */ + +label: CASE expr_no_commas ':' + { register tree value = check_case_value ($2); + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + stmt_count++; + + if (value != error_mark_node) + { + tree duplicate; + int success = pushcase (value, convert_and_check, + label, &duplicate); + if (success == 1) + error ("case label not within a switch statement"); + else if (success == 2) + { + error ("duplicate case value"); + error_with_decl (duplicate, "this is the first entry for that value"); + } + else if (success == 3) + warning ("case value out of range"); + else if (success == 5) + error ("case label within scope of cleanup or variable array"); + } + position_after_white_space (); } + | CASE expr_no_commas ELLIPSIS expr_no_commas ':' + { register tree value1 = check_case_value ($2); + register tree value2 = check_case_value ($4); + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + stmt_count++; + + if (value1 != error_mark_node && value2 != error_mark_node) + { + tree duplicate; + int success = pushcase_range (value1, value2, + convert_and_check, label, + &duplicate); + if (success == 1) + error ("case label not within a switch statement"); + else if (success == 2) + { + error ("duplicate case value"); + error_with_decl (duplicate, "this is the first entry for that value"); + } + else if (success == 3) + warning ("case value out of range"); + else if (success == 4) + warning ("empty case range"); + else if (success == 5) + error ("case label within scope of cleanup or variable array"); + } + position_after_white_space (); } + | DEFAULT ':' + { + tree duplicate; + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + int success = pushcase (NULL_TREE, 0, label, &duplicate); + stmt_count++; + if (success == 1) + error ("default label not within a switch statement"); + else if (success == 2) + { + error ("multiple default labels in one switch"); + error_with_decl (duplicate, "this is the first default label"); + } + position_after_white_space (); } + | identifier ':' + { tree label = define_label (input_filename, lineno, $1); + stmt_count++; + emit_nop (); + if (label) + expand_label (label); + position_after_white_space (); } + ; + +/* Either a type-qualifier or nothing. First thing in an `asm' statement. */ + +maybe_type_qual: + /* empty */ + { emit_line_note (input_filename, lineno); + $$ = NULL_TREE; } + | TYPE_QUAL + { emit_line_note (input_filename, lineno); } + ; + +xexpr: + /* empty */ + { $$ = NULL_TREE; } + | expr + ; + +/* These are the operands other than the first string and colon + in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */ +asm_operands: /* empty */ + { $$ = NULL_TREE; } + | nonnull_asm_operands + ; + +nonnull_asm_operands: + asm_operand + | nonnull_asm_operands ',' asm_operand + { $$ = chainon ($1, $3); } + ; + +asm_operand: + STRING '(' expr ')' + { $$ = build_tree_list ($1, $3); } + ; + +asm_clobbers: + string + { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); } + | asm_clobbers ',' string + { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); } + ; + +/* This is what appears inside the parens in a function declarator. + Its value is a list of ..._TYPE nodes. */ +parmlist: + { pushlevel (0); + clear_parm_order (); + declare_parm_level (0); } + parmlist_1 + { $$ = $2; + parmlist_tags_warning (); + poplevel (0, 0, 0); } + ; + +parmlist_1: + parmlist_2 ')' + | parms ';' + { tree parm; + if (pedantic) + pedwarn ("ANSI C forbids forward parameter declarations"); + /* Mark the forward decls as such. */ + for (parm = getdecls (); parm; parm = TREE_CHAIN (parm)) + TREE_ASM_WRITTEN (parm) = 1; + clear_parm_order (); } + parmlist_1 + { $$ = $4; } + | error ')' + { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); } + ; + +/* This is what appears inside the parens in a function declarator. + Is value is represented in the format that grokdeclarator expects. */ +parmlist_2: /* empty */ + { $$ = get_parm_info (0); } + | ELLIPSIS + { $$ = get_parm_info (0); + /* Gcc used to allow this as an extension. However, it does + not work for all targets, and thus has been disabled. + Also, since func (...) and func () are indistinguishable, + it caused problems with the code in expand_builtin which + tries to verify that BUILT_IN_NEXT_ARG is being used + correctly. */ + error ("ANSI C requires a named argument before `...'"); + } + | parms + { $$ = get_parm_info (1); } + | parms ',' ELLIPSIS + { $$ = get_parm_info (0); } + ; + +parms: + parm + { push_parm_decl ($1); } + | parms ',' parm + { push_parm_decl ($3); } + ; + +/* A single parameter declaration or parameter type name, + as found in a parmlist. */ +parm: + typed_declspecs setspecs parm_declarator maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $3), + build_tree_list (prefix_attributes, + $4)); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs setspecs notype_declarator maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $3), + build_tree_list (prefix_attributes, + $4)); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs setspecs absdcl maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $3), + build_tree_list (prefix_attributes, + $4)); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | declmods setspecs notype_declarator maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $3), + build_tree_list (prefix_attributes, + $4)); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + + | declmods setspecs absdcl maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $3), + build_tree_list (prefix_attributes, + $4)); + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + ; + +/* This is used in a function definition + where either a parmlist or an identifier list is ok. + Its value is a list of ..._TYPE nodes or a list of identifiers. */ +parmlist_or_identifiers: + { pushlevel (0); + clear_parm_order (); + declare_parm_level (1); } + parmlist_or_identifiers_1 + { $$ = $2; + parmlist_tags_warning (); + poplevel (0, 0, 0); } + ; + +parmlist_or_identifiers_1: + parmlist_1 + | identifiers ')' + { tree t; + for (t = $1; t; t = TREE_CHAIN (t)) + if (TREE_VALUE (t) == NULL_TREE) + error ("`...' in old-style identifier list"); + $$ = tree_cons (NULL_TREE, NULL_TREE, $1); } + ; + +/* A nonempty list of identifiers. */ +identifiers: + IDENTIFIER + { $$ = build_tree_list (NULL_TREE, $1); } + | identifiers ',' IDENTIFIER + { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); } + ; + +/* A nonempty list of identifiers, including typenames. */ +identifiers_or_typenames: + identifier + { $$ = build_tree_list (NULL_TREE, $1); } + | identifiers_or_typenames ',' identifier + { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); } + ; + +ifobjc +/* Objective-C productions. */ + +objcdef: + classdef + | classdecl + | aliasdecl + | protocoldef + | methoddef + | END + { + if (objc_implementation_context) + { + finish_class (objc_implementation_context); + objc_ivar_chain = NULL_TREE; + objc_implementation_context = NULL_TREE; + } + else + warning ("`@end' must appear in an implementation context"); + } + ; + +/* A nonempty list of identifiers. */ +identifier_list: + identifier + { $$ = build_tree_list (NULL_TREE, $1); } + | identifier_list ',' identifier + { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); } + ; + +classdecl: + CLASS identifier_list ';' + { + objc_declare_class ($2); + } + +aliasdecl: + ALIAS identifier identifier ';' + { + objc_declare_alias ($2, $3); + } + +classdef: + INTERFACE identifier protocolrefs '{' + { + objc_interface_context = objc_ivar_context + = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3); + objc_public_flag = 0; + } + ivar_decl_list '}' + { + continue_class (objc_interface_context); + } + methodprotolist + END + { + finish_class (objc_interface_context); + objc_interface_context = NULL_TREE; + } + + | INTERFACE identifier protocolrefs + { + objc_interface_context + = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3); + continue_class (objc_interface_context); + } + methodprotolist + END + { + finish_class (objc_interface_context); + objc_interface_context = NULL_TREE; + } + + | INTERFACE identifier ':' identifier protocolrefs '{' + { + objc_interface_context = objc_ivar_context + = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5); + objc_public_flag = 0; + } + ivar_decl_list '}' + { + continue_class (objc_interface_context); + } + methodprotolist + END + { + finish_class (objc_interface_context); + objc_interface_context = NULL_TREE; + } + + | INTERFACE identifier ':' identifier protocolrefs + { + objc_interface_context + = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5); + continue_class (objc_interface_context); + } + methodprotolist + END + { + finish_class (objc_interface_context); + objc_interface_context = NULL_TREE; + } + + | IMPLEMENTATION identifier '{' + { + objc_implementation_context = objc_ivar_context + = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE); + objc_public_flag = 0; + } + ivar_decl_list '}' + { + objc_ivar_chain + = continue_class (objc_implementation_context); + } + + | IMPLEMENTATION identifier + { + objc_implementation_context + = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE); + objc_ivar_chain + = continue_class (objc_implementation_context); + } + + | IMPLEMENTATION identifier ':' identifier '{' + { + objc_implementation_context = objc_ivar_context + = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE); + objc_public_flag = 0; + } + ivar_decl_list '}' + { + objc_ivar_chain + = continue_class (objc_implementation_context); + } + + | IMPLEMENTATION identifier ':' identifier + { + objc_implementation_context + = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE); + objc_ivar_chain + = continue_class (objc_implementation_context); + } + + | INTERFACE identifier '(' identifier ')' protocolrefs + { + objc_interface_context + = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6); + continue_class (objc_interface_context); + } + methodprotolist + END + { + finish_class (objc_interface_context); + objc_interface_context = NULL_TREE; + } + + | IMPLEMENTATION identifier '(' identifier ')' + { + objc_implementation_context + = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE); + objc_ivar_chain + = continue_class (objc_implementation_context); + } + ; + +protocoldef: + PROTOCOL identifier protocolrefs + { + remember_protocol_qualifiers (); + objc_interface_context + = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3); + } + methodprotolist END + { + forget_protocol_qualifiers(); + finish_protocol(objc_interface_context); + objc_interface_context = NULL_TREE; + } + ; + +protocolrefs: + /* empty */ + { + $$ = NULL_TREE; + } + | ARITHCOMPARE identifier_list ARITHCOMPARE + { + if ($1 == LT_EXPR && $3 == GT_EXPR) + $$ = $2; + else + YYERROR1; + } + ; + +ivar_decl_list: + ivar_decl_list visibility_spec ivar_decls + | ivar_decls + ; + +visibility_spec: + PRIVATE { objc_public_flag = 2; } + | PROTECTED { objc_public_flag = 0; } + | PUBLIC { objc_public_flag = 1; } + ; + +ivar_decls: + /* empty */ + { + $$ = NULL_TREE; + } + | ivar_decls ivar_decl ';' + | ivar_decls ';' + { + if (pedantic) + pedwarn ("extra semicolon in struct or union specified"); + } + ; + + +/* There is a shift-reduce conflict here, because `components' may + start with a `typename'. It happens that shifting (the default resolution) + does the right thing, because it treats the `typename' as part of + a `typed_typespecs'. + + It is possible that this same technique would allow the distinction + between `notype_initdecls' and `initdecls' to be eliminated. + But I am being cautious and not trying it. */ + +ivar_decl: + typed_typespecs setspecs ivars + { $$ = $3; + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | nonempty_type_quals setspecs ivars + { $$ = $3; + current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | error + { $$ = NULL_TREE; } + ; + +ivars: + /* empty */ + { $$ = NULL_TREE; } + | ivar_declarator + | ivars ',' ivar_declarator + ; + +ivar_declarator: + declarator + { + $$ = add_instance_variable (objc_ivar_context, + objc_public_flag, + $1, current_declspecs, + NULL_TREE); + } + | declarator ':' expr_no_commas + { + $$ = add_instance_variable (objc_ivar_context, + objc_public_flag, + $1, current_declspecs, $3); + } + | ':' expr_no_commas + { + $$ = add_instance_variable (objc_ivar_context, + objc_public_flag, + NULL_TREE, + current_declspecs, $2); + } + ; + +methoddef: + '+' + { + remember_protocol_qualifiers (); + if (objc_implementation_context) + objc_inherit_code = CLASS_METHOD_DECL; + else + fatal ("method definition not in class context"); + } + methoddecl + { + forget_protocol_qualifiers (); + add_class_method (objc_implementation_context, $3); + start_method_def ($3); + objc_method_context = $3; + } + optarglist + { + continue_method_def (); + } + compstmt_or_error + { + finish_method_def (); + objc_method_context = NULL_TREE; + } + + | '-' + { + remember_protocol_qualifiers (); + if (objc_implementation_context) + objc_inherit_code = INSTANCE_METHOD_DECL; + else + fatal ("method definition not in class context"); + } + methoddecl + { + forget_protocol_qualifiers (); + add_instance_method (objc_implementation_context, $3); + start_method_def ($3); + objc_method_context = $3; + } + optarglist + { + continue_method_def (); + } + compstmt_or_error + { + finish_method_def (); + objc_method_context = NULL_TREE; + } + ; + +/* the reason for the strange actions in this rule + is so that notype_initdecls when reached via datadef + can find a valid list of type and sc specs in $0. */ + +methodprotolist: + /* empty */ + | {$$ = NULL_TREE; } methodprotolist2 + ; + +methodprotolist2: /* eliminates a shift/reduce conflict */ + methodproto + | datadef + | methodprotolist2 methodproto + | methodprotolist2 {$$ = NULL_TREE; } datadef + ; + +semi_or_error: + ';' + | error + ; + +methodproto: + '+' + { + objc_inherit_code = CLASS_METHOD_DECL; + } + methoddecl + { + add_class_method (objc_interface_context, $3); + } + semi_or_error + + | '-' + { + objc_inherit_code = INSTANCE_METHOD_DECL; + } + methoddecl + { + add_instance_method (objc_interface_context, $3); + } + semi_or_error + ; + +methoddecl: + '(' typename ')' unaryselector + { + $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE); + } + + | unaryselector + { + $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE); + } + + | '(' typename ')' keywordselector optparmlist + { + $$ = build_method_decl (objc_inherit_code, $2, $4, $5); + } + + | keywordselector optparmlist + { + $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2); + } + ; + +/* "optarglist" assumes that start_method_def has already been called... + if it is not, the "xdecls" will not be placed in the proper scope */ + +optarglist: + /* empty */ + | ';' myxdecls + ; + +/* to get around the following situation: "int foo (int a) int b; {}" that + is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */ + +myxdecls: + /* empty */ + | mydecls + ; + +mydecls: + mydecl + | errstmt + | mydecls mydecl + | mydecl errstmt + ; + +mydecl: + typed_declspecs setspecs myparms ';' + { current_declspecs = TREE_VALUE (declspec_stack); + prefix_attributes = TREE_PURPOSE (declspec_stack); + declspec_stack = TREE_CHAIN (declspec_stack); + resume_momentary ($2); } + | typed_declspecs ';' + { shadow_tag ($1); } + | declmods ';' + { pedwarn ("empty declaration"); } + ; + +myparms: + myparm + { push_parm_decl ($1); } + | myparms ',' myparm + { push_parm_decl ($3); } + ; + +/* A single parameter declaration or parameter type name, + as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */ + +myparm: + parm_declarator maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $1), + build_tree_list (prefix_attributes, + $2)); } + | notype_declarator maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $1), + build_tree_list (prefix_attributes, + $2)); } + | absdcl maybe_attribute + { $$ = build_tree_list (build_tree_list (current_declspecs, + $1), + build_tree_list (prefix_attributes, + $2)); } + ; + +optparmlist: + /* empty */ + { + $$ = NULL_TREE; + } + | ',' ELLIPSIS + { + /* oh what a kludge! */ + $$ = (tree)1; + } + | ',' + { + pushlevel (0); + } + parmlist_2 + { + /* returns a tree list node generated by get_parm_info */ + $$ = $3; + poplevel (0, 0, 0); + } + ; + +unaryselector: + selector + ; + +keywordselector: + keyworddecl + + | keywordselector keyworddecl + { + $$ = chainon ($1, $2); + } + ; + +selector: + IDENTIFIER + | TYPENAME + | OBJECTNAME + | reservedwords + ; + +reservedwords: + ENUM { $$ = get_identifier (token_buffer); } + | STRUCT { $$ = get_identifier (token_buffer); } + | UNION { $$ = get_identifier (token_buffer); } + | IF { $$ = get_identifier (token_buffer); } + | ELSE { $$ = get_identifier (token_buffer); } + | WHILE { $$ = get_identifier (token_buffer); } + | DO { $$ = get_identifier (token_buffer); } + | FOR { $$ = get_identifier (token_buffer); } + | SWITCH { $$ = get_identifier (token_buffer); } + | CASE { $$ = get_identifier (token_buffer); } + | DEFAULT { $$ = get_identifier (token_buffer); } + | BREAK { $$ = get_identifier (token_buffer); } + | CONTINUE { $$ = get_identifier (token_buffer); } + | RETURN { $$ = get_identifier (token_buffer); } + | GOTO { $$ = get_identifier (token_buffer); } + | ASM_KEYWORD { $$ = get_identifier (token_buffer); } + | SIZEOF { $$ = get_identifier (token_buffer); } + | TYPEOF { $$ = get_identifier (token_buffer); } + | ALIGNOF { $$ = get_identifier (token_buffer); } + | TYPESPEC | TYPE_QUAL + ; + +keyworddecl: + selector ':' '(' typename ')' identifier + { + $$ = build_keyword_decl ($1, $4, $6); + } + + | selector ':' identifier + { + $$ = build_keyword_decl ($1, NULL_TREE, $3); + } + + | ':' '(' typename ')' identifier + { + $$ = build_keyword_decl (NULL_TREE, $3, $5); + } + + | ':' identifier + { + $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2); + } + ; + +messageargs: + selector + | keywordarglist + ; + +keywordarglist: + keywordarg + | keywordarglist keywordarg + { + $$ = chainon ($1, $2); + } + ; + + +keywordexpr: + nonnull_exprlist + { + if (TREE_CHAIN ($1) == NULL_TREE) + /* just return the expr., remove a level of indirection */ + $$ = TREE_VALUE ($1); + else + /* we have a comma expr., we will collapse later */ + $$ = $1; + } + ; + +keywordarg: + selector ':' keywordexpr + { + $$ = build_tree_list ($1, $3); + } + | ':' keywordexpr + { + $$ = build_tree_list (NULL_TREE, $2); + } + ; + +receiver: + expr + | CLASSNAME + { + $$ = get_class_reference ($1); + } + ; + +objcmessageexpr: + '[' + { objc_receiver_context = 1; } + receiver + { objc_receiver_context = 0; } + messageargs ']' + { + $$ = build_tree_list ($3, $5); + } + ; + +selectorarg: + selector + | keywordnamelist + ; + +keywordnamelist: + keywordname + | keywordnamelist keywordname + { + $$ = chainon ($1, $2); + } + ; + +keywordname: + selector ':' + { + $$ = build_tree_list ($1, NULL_TREE); + } + | ':' + { + $$ = build_tree_list (NULL_TREE, NULL_TREE); + } + ; + +objcselectorexpr: + SELECTOR '(' selectorarg ')' + { + $$ = $3; + } + ; + +objcprotocolexpr: + PROTOCOL '(' identifier ')' + { + $$ = $3; + } + ; + +/* extension to support C-structures in the archiver */ + +objcencodeexpr: + ENCODE '(' typename ')' + { + $$ = groktypename ($3); + } + ; + +end ifobjc +%% diff --git a/contrib/gcc/c-pragma.c b/contrib/gcc/c-pragma.c new file mode 100644 index 00000000000..480cfca8154 --- /dev/null +++ b/contrib/gcc/c-pragma.c @@ -0,0 +1,168 @@ +/* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack. + Copyright (C) 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "config.h" +#include "tree.h" +#include "function.h" +#include "defaults.h" +#include "c-pragma.h" + +#ifdef HANDLE_SYSV_PRAGMA + +/* When structure field packing is in effect, this variable is the + number of bits to use as the maximum alignment. When packing is not + in effect, this is zero. */ + +extern int maximum_field_alignment; + +/* File used for outputting assembler code. */ +extern FILE *asm_out_file; + +/* Handle one token of a pragma directive. TOKEN is the + current token, and STRING is its printable form. */ + +void +handle_pragma_token (string, token) + char *string; + tree token; +{ + static enum pragma_state state = ps_start, type; + static char *name; + static char *value; + static int align; + + if (string == 0) + { + if (type == ps_pack) + { + if (state == ps_right) + maximum_field_alignment = align * 8; + else + warning ("malformed `#pragma pack'"); + } + else if (type == ps_weak) + { +#ifdef HANDLE_PRAGMA_WEAK + if (HANDLE_PRAGMA_WEAK) + handle_pragma_weak (state, name, value); + +#endif /* HANDLE_PRAMA_WEAK */ + } + + type = state = ps_start; + return; + } + + switch (state) + { + case ps_start: + if (token && TREE_CODE (token) == IDENTIFIER_NODE) + { + if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0) + type = state = ps_pack; + else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0) + type = state = ps_weak; + else + type = state = ps_done; + } + else + type = state = ps_done; + break; + + case ps_weak: + if (token && TREE_CODE (token) == IDENTIFIER_NODE) + { + name = IDENTIFIER_POINTER (token); + state = ps_name; + } + else + state = ps_bad; + break; + + case ps_name: + state = (strcmp (string, "=") ? ps_bad : ps_equals); + break; + + case ps_equals: + if (token && TREE_CODE (token) == IDENTIFIER_NODE) + { + value = IDENTIFIER_POINTER (token); + state = ps_value; + } + else + state = ps_bad; + break; + + case ps_value: + state = ps_bad; + break; + + case ps_pack: + if (strcmp (string, "(") == 0) + state = ps_left; + else + state = ps_bad; + break; + + case ps_left: + if (token && TREE_CODE (token) == INTEGER_CST + && TREE_INT_CST_HIGH (token) == 0) + switch (TREE_INT_CST_LOW (token)) + { + case 1: + case 2: + case 4: + align = TREE_INT_CST_LOW (token); + state = ps_align; + break; + + default: + state = ps_bad; + } + else if (! token && strcmp (string, ")") == 0) + { + align = 0; + state = ps_right; + } + else + state = ps_bad; + break; + + case ps_align: + if (strcmp (string, ")") == 0) + state = ps_right; + else + state = ps_bad; + break; + + case ps_right: + state = ps_bad; + break; + + case ps_bad: + case ps_done: + break; + + default: + abort (); + } +} +#endif /* HANDLE_SYSV_PRAGMA */ diff --git a/contrib/gcc/c-pragma.h b/contrib/gcc/c-pragma.h new file mode 100644 index 00000000000..49c39fa591e --- /dev/null +++ b/contrib/gcc/c-pragma.h @@ -0,0 +1,46 @@ +/* Pragma related interfaces. + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Support #pragma weak iff ASM_WEAKEN_LABEL and ASM_OUTPUT_DEF are + defined. */ +#if defined (ASM_WEAKEN_LABEL) && defined (ASM_OUTPUT_DEF) +#define HANDLE_PRAGMA_WEAK SUPPORTS_WEAK +#endif + +enum pragma_state +{ + ps_start, + ps_done, + ps_bad, + ps_weak, + ps_name, + ps_equals, + ps_value, + ps_pack, + ps_left, + ps_align, + ps_right +}; + +/* Output asm to handle ``#pragma weak'' */ +extern void handle_pragma_weak PROTO((enum pragma_state, char *, char *)); + +/* Handle a C style pragma */ +extern void handle_pragma_token PROTO((char *, tree)); diff --git a/contrib/gcc/c-tree.h b/contrib/gcc/c-tree.h new file mode 100644 index 00000000000..02f57c3b9dc --- /dev/null +++ b/contrib/gcc/c-tree.h @@ -0,0 +1,490 @@ +/* Definitions for C parsing and type checking. + Copyright (C) 1987, 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef _C_TREE_H +#define _C_TREE_H + +/* Language-dependent contents of an identifier. */ + +/* The limbo_value is used for block level extern declarations, which need + to be type checked against subsequent extern declarations. They can't + be referenced after they fall out of scope, so they can't be global. */ + +struct lang_identifier +{ + struct tree_identifier ignore; + tree global_value, local_value, label_value, implicit_decl; + tree error_locus, limbo_value; +}; + +/* Macros for access to language-specific slots in an identifier. */ +/* Each of these slots contains a DECL node or null. */ + +/* This represents the value which the identifier has in the + file-scope namespace. */ +#define IDENTIFIER_GLOBAL_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->global_value) +/* This represents the value which the identifier has in the current + scope. */ +#define IDENTIFIER_LOCAL_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->local_value) +/* This represents the value which the identifier has as a label in + the current label scope. */ +#define IDENTIFIER_LABEL_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->label_value) +/* This records the extern decl of this identifier, if it has had one + at any point in this compilation. */ +#define IDENTIFIER_LIMBO_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->limbo_value) +/* This records the implicit function decl of this identifier, if it + has had one at any point in this compilation. */ +#define IDENTIFIER_IMPLICIT_DECL(NODE) \ + (((struct lang_identifier *)(NODE))->implicit_decl) +/* This is the last function in which we printed an "undefined variable" + message for this identifier. Value is a FUNCTION_DECL or null. */ +#define IDENTIFIER_ERROR_LOCUS(NODE) \ + (((struct lang_identifier *)(NODE))->error_locus) + +/* In identifiers, C uses the following fields in a special way: + TREE_PUBLIC to record that there was a previous local extern decl. + TREE_USED to record that such a decl was used. + TREE_ADDRESSABLE to record that the address of such a decl was used. */ + +/* Nonzero means reject anything that ANSI standard C forbids. */ +extern int pedantic; + +/* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */ +#define C_TYPE_FIELDS_READONLY(type) TREE_LANG_FLAG_1 (type) + +/* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is volatile. */ +#define C_TYPE_FIELDS_VOLATILE(type) TREE_LANG_FLAG_2 (type) + +/* In a RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE + nonzero if the definition of the type has already started. */ +#define C_TYPE_BEING_DEFINED(type) TYPE_LANG_FLAG_0 (type) + +/* In a RECORD_TYPE, a sorted array of the fields of the type. */ +struct lang_type +{ + int len; + tree elts[1]; +}; + +/* Mark which labels are explicitly declared. + These may be shadowed, and may be referenced from nested functions. */ +#define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label) + +/* Record whether a type or decl was written with nonconstant size. + Note that TYPE_SIZE may have simplified to a constant. */ +#define C_TYPE_VARIABLE_SIZE(type) TYPE_LANG_FLAG_1 (type) +#define C_DECL_VARIABLE_SIZE(type) DECL_LANG_FLAG_0 (type) + +/* Record in each node resulting from a binary operator + what operator was specified for it. */ +#define C_EXP_ORIGINAL_CODE(exp) ((enum tree_code) TREE_COMPLEXITY (exp)) + +#if 0 /* Not used. */ +/* Record whether a decl for a function or function pointer has + already been mentioned (in a warning) because it was called + but didn't have a prototype. */ +#define C_MISSING_PROTOTYPE_WARNED(decl) DECL_LANG_FLAG_2(decl) +#endif + +/* Store a value in that field. */ +#define C_SET_EXP_ORIGINAL_CODE(exp, code) \ + (TREE_COMPLEXITY (exp) = (int)(code)) + +/* Record whether a typedef for type `int' was actually `signed int'. */ +#define C_TYPEDEF_EXPLICITLY_SIGNED(exp) DECL_LANG_FLAG_1 ((exp)) + +/* Nonzero for a declaration of a built in function if there has been no + occasion that would declare the function in ordinary C. + Using the function draws a pedantic warning in this case. */ +#define C_DECL_ANTICIPATED(exp) DECL_LANG_FLAG_3 ((exp)) + +/* For FUNCTION_TYPE, a hidden list of types of arguments. The same as + TYPE_ARG_TYPES for functions with prototypes, but created for functions + without prototypes. */ +#define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_NONCOPIED_PARTS (NODE) + +/* Nonzero if the type T promotes to itself. + ANSI C states explicitly the list of types that promote; + in particular, short promotes to int even if they have the same width. */ +#define C_PROMOTING_INTEGER_TYPE_P(t) \ + (TREE_CODE ((t)) == INTEGER_TYPE \ + && (TYPE_MAIN_VARIANT (t) == char_type_node \ + || TYPE_MAIN_VARIANT (t) == signed_char_type_node \ + || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node \ + || TYPE_MAIN_VARIANT (t) == short_integer_type_node \ + || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node)) + +/* In a VAR_DECL, means the variable is really an iterator. */ +#define ITERATOR_P(D) (DECL_LANG_FLAG_4(D)) + +/* In a VAR_DECL for an iterator, means we are within + an explicit loop over that iterator. */ +#define ITERATOR_BOUND_P(NODE) ((NODE)->common.readonly_flag) + +/* in c-lang.c and objc-act.c */ +extern tree lookup_interface PROTO((tree)); +extern tree is_class_name PROTO((tree)); +extern void maybe_objc_check_decl PROTO((tree)); +extern int maybe_objc_comptypes PROTO((tree, tree, int)); +extern tree maybe_building_objc_message_expr PROTO((void)); +extern tree maybe_objc_method_name PROTO((tree)); +extern int recognize_objc_keyword PROTO((void)); +extern tree build_objc_string PROTO((int, char *)); + +/* in c-aux-info.c */ +extern void gen_aux_info_record PROTO((tree, int, int, int)); + +/* in c-common.c */ +extern void declare_function_name PROTO((void)); +extern void decl_attributes PROTO((tree, tree, tree)); +extern void init_function_format_info PROTO((void)); +extern void record_function_format PROTO((tree, tree, int, int, int)); +extern void check_function_format PROTO((tree, tree, tree)); +/* Print an error message for invalid operands to arith operation CODE. + NOP_EXPR is used as a special case (see truthvalue_conversion). */ +extern void binary_op_error PROTO((enum tree_code)); +extern void c_expand_expr_stmt PROTO((tree)); +/* Validate the expression after `case' and apply default promotions. */ +extern tree check_case_value PROTO((tree)); +/* Concatenate a list of STRING_CST nodes into one STRING_CST. */ +extern tree combine_strings PROTO((tree)); +extern void constant_expression_warning PROTO((tree)); +extern tree convert_and_check PROTO((tree, tree)); +extern void overflow_warning PROTO((tree)); +extern void unsigned_conversion_warning PROTO((tree, tree)); +/* Read the rest of the current #-directive line. */ +extern char *get_directive_line STDIO_PROTO((FILE *)); +/* Subroutine of build_binary_op, used for comparison operations. + See if the operands have both been converted from subword integer types + and, if so, perhaps change them both back to their original type. */ +extern tree shorten_compare PROTO((tree *, tree *, tree *, enum tree_code *)); +/* Prepare expr to be an argument of a TRUTH_NOT_EXPR, + or validate its data type for an `if' or `while' statement or ?..: exp. */ +extern tree truthvalue_conversion PROTO((tree)); +extern tree type_for_mode PROTO((enum machine_mode, int)); +extern tree type_for_size PROTO((unsigned, int)); + +/* in c-convert.c */ +extern tree convert PROTO((tree, tree)); + +/* in c-decl.c */ +/* Standard named or nameless data types of the C compiler. */ +extern tree char_array_type_node; +extern tree char_type_node; +extern tree const_ptr_type_node; +extern tree const_string_type_node; +extern tree default_function_type; +extern tree double_ftype_double; +extern tree double_ftype_double_double; +extern tree double_type_node; +extern tree float_type_node; +extern tree intDI_type_node; +extern tree intHI_type_node; +extern tree intQI_type_node; +extern tree intSI_type_node; +extern tree int_array_type_node; +extern tree int_ftype_cptr_cptr_sizet; +extern tree int_ftype_int; +extern tree int_ftype_ptr_ptr_int; +extern tree int_ftype_string_string; +extern tree integer_type_node; +extern tree long_double_type_node; +extern tree long_ftype_long; +extern tree long_integer_type_node; +extern tree long_long_integer_type_node; +extern tree long_long_unsigned_type_node; +extern tree long_unsigned_type_node; +extern tree complex_integer_type_node; +extern tree complex_float_type_node; +extern tree complex_double_type_node; +extern tree complex_long_double_type_node; +extern tree ptr_type_node; +extern tree ptrdiff_type_node; +extern tree short_integer_type_node; +extern tree short_unsigned_type_node; +extern tree signed_char_type_node; +extern tree signed_wchar_type_node; +extern tree string_ftype_ptr_ptr; +extern tree string_type_node; +extern tree unsigned_char_type_node; +extern tree unsigned_intDI_type_node; +extern tree unsigned_intHI_type_node; +extern tree unsigned_intQI_type_node; +extern tree unsigned_intSI_type_node; +extern tree unsigned_type_node; +extern tree unsigned_wchar_type_node; +extern tree void_ftype_ptr_int_int; +extern tree void_ftype_ptr_ptr_int; +extern tree void_type_node; +extern tree wchar_array_type_node; +extern tree wchar_type_node; +extern tree boolean_type_node; +extern tree boolean_true_node; +extern tree boolean_false_node; + +extern tree build_enumerator PROTO((tree, tree)); +/* Declare a predefined function. Return the declaration. */ +extern tree builtin_function PROTO((char *, tree, enum built_in_function function_, char *)); +/* Add qualifiers to a type, in the fashion for C. */ +extern tree c_build_type_variant PROTO((tree, int, int)); +extern int c_decode_option PROTO((char *)); +extern void c_mark_varargs PROTO((void)); +extern tree check_identifier PROTO((tree, tree)); +extern void clear_parm_order PROTO((void)); +extern tree combine_parm_decls PROTO((tree, tree, int)); +extern int complete_array_type PROTO((tree, tree, int)); +extern void declare_parm_level PROTO((int)); +extern tree define_label PROTO((char *, int, tree)); +extern void delete_block PROTO((tree)); +extern void finish_decl PROTO((tree, tree, tree)); +extern void finish_decl_top_level PROTO((tree, tree, tree)); +extern tree finish_enum PROTO((tree, tree, tree)); +extern void finish_function PROTO((int)); +extern tree finish_struct PROTO((tree, tree, tree)); +extern tree get_parm_info PROTO((int)); +extern tree getdecls PROTO((void)); +extern tree gettags PROTO((void)); +extern int global_bindings_p PROTO((void)); +extern tree grokfield PROTO((char *, int, tree, tree, tree)); +extern tree groktypename PROTO((tree)); +extern tree groktypename_in_parm_context PROTO((tree)); +extern tree implicitly_declare PROTO((tree)); +extern int in_parm_level_p PROTO((void)); +extern void init_decl_processing PROTO((void)); +extern void insert_block PROTO((tree)); +extern void keep_next_level PROTO((void)); +extern int kept_level_p PROTO((void)); +extern tree lookup_label PROTO((tree)); +extern tree lookup_name PROTO((tree)); +extern tree lookup_name_current_level PROTO((tree)); +extern tree lookup_name_current_level_global PROTO((tree)); +extern tree maybe_build_cleanup PROTO((tree)); +extern void parmlist_tags_warning PROTO((void)); +extern void pending_xref_error PROTO((void)); +extern void pop_c_function_context PROTO((void)); +extern void pop_label_level PROTO((void)); +extern tree poplevel PROTO((int, int, int)); +extern void print_lang_decl STDIO_PROTO((FILE *, tree, + int)); +extern void print_lang_identifier STDIO_PROTO((FILE *, tree, + int)); +extern void print_lang_type STDIO_PROTO((FILE *, tree, + int)); +extern void push_c_function_context PROTO((void)); +extern void push_label_level PROTO((void)); +extern void push_parm_decl PROTO((tree)); +extern tree pushdecl PROTO((tree)); +extern tree pushdecl_top_level PROTO((tree)); +extern void pushlevel PROTO((int)); +extern void pushtag PROTO((tree, tree)); +extern void set_block PROTO((tree)); +extern tree shadow_label PROTO((tree)); +extern void shadow_record_fields PROTO((tree)); +extern void shadow_tag PROTO((tree)); +extern void shadow_tag_warned PROTO((tree, int)); +extern tree start_enum PROTO((tree)); +extern int start_function PROTO((tree, tree, tree, + tree, int)); +extern tree start_decl PROTO((tree, tree, int, + tree, tree)); +extern tree start_struct PROTO((enum tree_code, tree)); +extern void store_parm_decls PROTO((void)); +extern tree xref_tag PROTO((enum tree_code, tree)); + +/* in c-typeck.c */ +extern tree require_complete_type PROTO((tree)); +extern void incomplete_type_error PROTO((tree, tree)); +/* Given two integer or real types, return the type for their sum. + Given two compatible ANSI C types, returns the merged type. */ +extern tree common_type PROTO((tree, tree)); +extern int comptypes PROTO((tree, tree)); +extern int self_promoting_args_p PROTO((tree)); +extern tree c_sizeof PROTO((tree)); +extern tree c_sizeof_nowarn PROTO((tree)); +extern tree c_size_in_bytes PROTO((tree)); +extern tree c_alignof PROTO((tree)); +extern tree c_alignof_expr PROTO((tree)); +extern tree default_conversion PROTO((tree)); +extern tree build_component_ref PROTO((tree, tree)); +extern tree build_indirect_ref PROTO((tree, char *)); +extern tree build_array_ref PROTO((tree, tree)); +extern tree build_function_call PROTO((tree, tree)); +extern tree parser_build_binary_op PROTO((enum tree_code, + tree, tree)); +extern tree build_binary_op PROTO((enum tree_code, + tree, tree, int)); +extern tree build_unary_op PROTO((enum tree_code, + tree, int)); +extern int lvalue_p PROTO((tree)); +extern int lvalue_or_else PROTO((tree, char *)); +extern void readonly_warning PROTO((tree, char *)); +extern int mark_addressable PROTO((tree)); +extern tree build_conditional_expr PROTO((tree, tree, tree)); +extern tree build_compound_expr PROTO((tree)); +extern tree build_c_cast PROTO((tree, tree)); +extern tree build_modify_expr PROTO((tree, enum tree_code, + tree)); +extern tree initializer_constant_valid_p PROTO((tree, tree)); +extern void store_init_value PROTO((tree, tree)); +extern void error_init PROTO((char *, char *, + char *)); +extern void pedwarn_init PROTO((char *, char *, + char *)); +extern void start_init PROTO((tree, tree, int)); +extern void finish_init PROTO((void)); +extern void really_start_incremental_init PROTO((tree)); +extern void push_init_level PROTO((int)); +extern tree pop_init_level PROTO((int)); +extern void set_init_index PROTO((tree, tree)); +extern void set_init_label PROTO((tree)); +extern void process_init_element PROTO((tree)); +extern void c_expand_asm_operands PROTO((tree, tree, tree, tree, + int, char *, int)); +extern void c_expand_return PROTO((tree)); +extern tree c_expand_start_case PROTO((tree)); + +/* in c-iterate.c */ +extern void iterator_expand PROTO((tree)); +extern void iterator_for_loop_start PROTO((tree)); +extern void iterator_for_loop_end PROTO((tree)); +extern void iterator_for_loop_record PROTO((tree)); +extern void push_iterator_stack PROTO((void)); +extern void pop_iterator_stack PROTO((void)); + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement that specifies a return value is seen. */ + +extern int current_function_returns_value; + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement with no argument is seen. */ + +extern int current_function_returns_null; + +/* Nonzero means `$' can be in an identifier. */ + +extern int dollars_in_ident; + +/* Nonzero means allow type mismatches in conditional expressions; + just make their values `void'. */ + +extern int flag_cond_mismatch; + +/* Nonzero means don't recognize the keyword `asm'. */ + +extern int flag_no_asm; + +/* Nonzero means ignore `#ident' directives. */ + +extern int flag_no_ident; + +/* Nonzero means warn about implicit declarations. */ + +extern int warn_implicit; + +/* Nonzero means give string constants the type `const char *' + to get extra warnings from them. These warnings will be too numerous + to be useful, except in thoroughly ANSIfied programs. */ + +extern int warn_write_strings; + +/* Nonzero means warn about sizeof (function) or addition/subtraction + of function pointers. */ + +extern int warn_pointer_arith; + +/* Nonzero means warn for all old-style non-prototype function decls. */ + +extern int warn_strict_prototypes; + +/* Nonzero means warn about multiple (redundant) decls for the same single + variable or function. */ + +extern int warn_redundant_decls; + +/* Nonzero means warn about extern declarations of objects not at + file-scope level and about *all* declarations of functions (whether + extern or static) not at file-scope level. Note that we exclude + implicit function declarations. To get warnings about those, use + -Wimplicit. */ + +extern int warn_nested_externs; + +/* Nonzero means warn about pointer casts that can drop a type qualifier + from the pointer target type. */ + +extern int warn_cast_qual; + +/* Nonzero means warn when casting a function call to a type that does + not match the return type (e.g. (float)sqrt() or (anything*)malloc() + when there is no previous declaration of sqrt or malloc. */ + +extern int warn_bad_function_cast; + +/* Warn about traditional constructs whose meanings changed in ANSI C. */ + +extern int warn_traditional; + +/* Warn about *printf or *scanf format/argument anomalies. */ + +extern int warn_format; + +/* Warn about a subscript that has type char. */ + +extern int warn_char_subscripts; + +/* Warn if a type conversion is done that might have confusing results. */ + +extern int warn_conversion; + +/* Nonzero means do some things the same way PCC does. */ + +extern int flag_traditional; + +/* Nonzero means to allow single precision math even if we're generally + being traditional. */ +extern int flag_allow_single_precision; + +/* Nonzero means warn about suggesting putting in ()'s. */ + +extern int warn_parentheses; + +/* Warn if initializer is not completely bracketed. */ + +extern int warn_missing_braces; + +/* Nonzero means this is a function to call to perform comptypes + on two record types. */ + +extern int (*comptypes_record_hook) (); + +/* Nonzero means we are reading code that came from a system header file. */ + +extern int system_header_p; + +/* Nonzero enables objc features. */ + +extern int doing_objc_thang; + +#endif /* not _C_TREE_H */ diff --git a/contrib/gcc/c-typeck.c b/contrib/gcc/c-typeck.c new file mode 100644 index 00000000000..e9d6b2a4196 --- /dev/null +++ b/contrib/gcc/c-typeck.c @@ -0,0 +1,6602 @@ +/* Build expressions with type checking for C compiler. + Copyright (C) 1987, 88, 91, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is part of the C front end. + It contains routines to build C expressions given their operands, + including computing the types of the result, C-specific error checks, + and some optimization. + + There are also routines to build RETURN_STMT nodes and CASE_STMT nodes, + and to process initializations in declarations (since they work + like a strange sort of assignment). */ + +#include "config.h" +#include +#include "tree.h" +#include "c-tree.h" +#include "flags.h" +#include "output.h" + +/* Nonzero if we've already printed a "missing braces around initializer" + message within this initializer. */ +static int missing_braces_mentioned; + +extern char *index (); +extern char *rindex (); + +static tree quality_type PROTO((tree, tree)); +static int comp_target_types PROTO((tree, tree)); +static int function_types_compatible_p PROTO((tree, tree)); +static int type_lists_compatible_p PROTO((tree, tree)); +static int self_promoting_type_p PROTO((tree)); +static tree decl_constant_value PROTO((tree)); +static tree lookup_field PROTO((tree, tree, tree *)); +static tree convert_arguments PROTO((tree, tree, tree, tree)); +static tree pointer_int_sum PROTO((enum tree_code, tree, tree)); +static tree pointer_diff PROTO((tree, tree)); +static tree unary_complex_lvalue PROTO((enum tree_code, tree)); +static void pedantic_lvalue_warning PROTO((enum tree_code)); +static tree internal_build_compound_expr PROTO((tree, int)); +static tree convert_for_assignment PROTO((tree, tree, char *, tree, + tree, int)); +static void warn_for_assignment PROTO((char *, char *, tree, int)); +static tree valid_compound_expr_initializer PROTO((tree, tree)); +static void push_string PROTO((char *)); +static void push_member_name PROTO((tree)); +static void push_array_bounds PROTO((int)); +static int spelling_length PROTO((void)); +static char *print_spelling PROTO((char *)); +static char *get_spelling PROTO((char *)); +static void warning_init PROTO((char *, char *, + char *)); +static tree digest_init PROTO((tree, tree, int, int)); +static void check_init_type_bitfields PROTO((tree)); +static void output_init_element PROTO((tree, tree, tree, int)); +static void output_pending_init_elements PROTO((int)); + +/* Do `exp = require_complete_type (exp);' to make sure exp + does not have an incomplete type. (That includes void types.) */ + +tree +require_complete_type (value) + tree value; +{ + tree type = TREE_TYPE (value); + + /* First, detect a valid value with a complete type. */ + if (TYPE_SIZE (type) != 0 + && type != void_type_node) + return value; + + incomplete_type_error (value, type); + return error_mark_node; +} + +/* Print an error message for invalid use of an incomplete type. + VALUE is the expression that was used (or 0 if that isn't known) + and TYPE is the type that was invalid. */ + +void +incomplete_type_error (value, type) + tree value; + tree type; +{ + char *errmsg; + + /* Avoid duplicate error message. */ + if (TREE_CODE (type) == ERROR_MARK) + return; + + if (value != 0 && (TREE_CODE (value) == VAR_DECL + || TREE_CODE (value) == PARM_DECL)) + error ("`%s' has an incomplete type", + IDENTIFIER_POINTER (DECL_NAME (value))); + else + { + retry: + /* We must print an error message. Be clever about what it says. */ + + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + errmsg = "invalid use of undefined type `struct %s'"; + break; + + case UNION_TYPE: + errmsg = "invalid use of undefined type `union %s'"; + break; + + case ENUMERAL_TYPE: + errmsg = "invalid use of undefined type `enum %s'"; + break; + + case VOID_TYPE: + error ("invalid use of void expression"); + return; + + case ARRAY_TYPE: + if (TYPE_DOMAIN (type)) + { + type = TREE_TYPE (type); + goto retry; + } + error ("invalid use of array with unspecified bounds"); + return; + + default: + abort (); + } + + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); + else + /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ + error ("invalid use of incomplete typedef `%s'", + IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); + } +} + +/* Return a variant of TYPE which has all the type qualifiers of LIKE + as well as those of TYPE. */ + +static tree +qualify_type (type, like) + tree type, like; +{ + int constflag = TYPE_READONLY (type) || TYPE_READONLY (like); + int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like); + return c_build_type_variant (type, constflag, volflag); +} + +/* Return the common type of two types. + We assume that comptypes has already been done and returned 1; + if that isn't so, this may crash. In particular, we assume that qualifiers + match. + + This is the type for the result of most arithmetic operations + if the operands have the given two types. */ + +tree +common_type (t1, t2) + tree t1, t2; +{ + register enum tree_code code1; + register enum tree_code code2; + tree attributes; + + /* Save time if the two types are the same. */ + + if (t1 == t2) return t1; + + /* If one type is nonsense, use the other. */ + if (t1 == error_mark_node) + return t2; + if (t2 == error_mark_node) + return t1; + + /* Merge the attributes */ + + { register tree a1, a2; + a1 = TYPE_ATTRIBUTES (t1); + a2 = TYPE_ATTRIBUTES (t2); + + /* Either one unset? Take the set one. */ + + if (!(attributes = a1)) + attributes = a2; + + /* One that completely contains the other? Take it. */ + + else if (a2 && !attribute_list_contained (a1, a2)) + if (attribute_list_contained (a2, a1)) + attributes = a2; + else + { + /* Pick the longest list, and hang on the other list. */ + /* ??? For the moment we punt on the issue of attrs with args. */ + + if (list_length (a1) < list_length (a2)) + attributes = a2, a2 = a1; + + for (; a2; a2 = TREE_CHAIN (a2)) + if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)), + attributes) == NULL_TREE) + { + a1 = copy_node (a2); + TREE_CHAIN (a1) = attributes; + attributes = a1; + } + } + } + + /* Treat an enum type as the unsigned integer type of the same width. */ + + if (TREE_CODE (t1) == ENUMERAL_TYPE) + t1 = type_for_size (TYPE_PRECISION (t1), 1); + if (TREE_CODE (t2) == ENUMERAL_TYPE) + t2 = type_for_size (TYPE_PRECISION (t2), 1); + + code1 = TREE_CODE (t1); + code2 = TREE_CODE (t2); + + /* If one type is complex, form the common type of the non-complex + components, then make that complex. Use T1 or T2 if it is the + required type. */ + if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE) + { + tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1; + tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2; + tree subtype = common_type (subtype1, subtype2); + + if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype) + return build_type_attribute_variant (t1, attributes); + else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype) + return build_type_attribute_variant (t2, attributes); + else + return build_type_attribute_variant (build_complex_type (subtype), + attributes); + } + + switch (code1) + { + case INTEGER_TYPE: + case REAL_TYPE: + /* If only one is real, use it as the result. */ + + if (code1 == REAL_TYPE && code2 != REAL_TYPE) + return build_type_attribute_variant (t1, attributes); + + if (code2 == REAL_TYPE && code1 != REAL_TYPE) + return build_type_attribute_variant (t2, attributes); + + /* Both real or both integers; use the one with greater precision. */ + + if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2)) + return build_type_attribute_variant (t1, attributes); + else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1)) + return build_type_attribute_variant (t2, attributes); + + /* Same precision. Prefer longs to ints even when same size. */ + + if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node + || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node) + return build_type_attribute_variant (long_unsigned_type_node, + attributes); + + if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node + || TYPE_MAIN_VARIANT (t2) == long_integer_type_node) + { + /* But preserve unsignedness from the other type, + since long cannot hold all the values of an unsigned int. */ + if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2)) + t1 = long_unsigned_type_node; + else + t1 = long_integer_type_node; + return build_type_attribute_variant (t1, attributes); + } + + /* Otherwise prefer the unsigned one. */ + + if (TREE_UNSIGNED (t1)) + return build_type_attribute_variant (t1, attributes); + else + return build_type_attribute_variant (t2, attributes); + + case POINTER_TYPE: + /* For two pointers, do this recursively on the target type, + and combine the qualifiers of the two types' targets. */ + /* This code was turned off; I don't know why. + But ANSI C specifies doing this with the qualifiers. + So I turned it on again. */ + { + tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)), + TYPE_MAIN_VARIANT (TREE_TYPE (t2))); + int constp + = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2)); + int volatilep + = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2)); + t1 = build_pointer_type (c_build_type_variant (target, constp, + volatilep)); + return build_type_attribute_variant (t1, attributes); + } +#if 0 + t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2))); + return build_type_attribute_variant (t1, attributes); +#endif + + case ARRAY_TYPE: + { + tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2)); + /* Save space: see if the result is identical to one of the args. */ + if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)) + return build_type_attribute_variant (t1, attributes); + if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)) + return build_type_attribute_variant (t2, attributes); + /* Merge the element types, and have a size if either arg has one. */ + t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2)); + return build_type_attribute_variant (t1, attributes); + } + + case FUNCTION_TYPE: + /* Function types: prefer the one that specified arg types. + If both do, merge the arg types. Also merge the return types. */ + { + tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2)); + tree p1 = TYPE_ARG_TYPES (t1); + tree p2 = TYPE_ARG_TYPES (t2); + int len; + tree newargs, n; + int i; + + /* Save space: see if the result is identical to one of the args. */ + if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2)) + return build_type_attribute_variant (t1, attributes); + if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1)) + return build_type_attribute_variant (t2, attributes); + + /* Simple way if one arg fails to specify argument types. */ + if (TYPE_ARG_TYPES (t1) == 0) + { + t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2)); + return build_type_attribute_variant (t1, attributes); + } + if (TYPE_ARG_TYPES (t2) == 0) + { + t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1)); + return build_type_attribute_variant (t1, attributes); + } + + /* If both args specify argument types, we must merge the two + lists, argument by argument. */ + + len = list_length (p1); + newargs = 0; + + for (i = 0; i < len; i++) + newargs = tree_cons (NULL_TREE, NULL_TREE, newargs); + + n = newargs; + + for (; p1; + p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n)) + { + /* A null type means arg type is not specified. + Take whatever the other function type has. */ + if (TREE_VALUE (p1) == 0) + { + TREE_VALUE (n) = TREE_VALUE (p2); + goto parm_done; + } + if (TREE_VALUE (p2) == 0) + { + TREE_VALUE (n) = TREE_VALUE (p1); + goto parm_done; + } + + /* Given wait (union {union wait *u; int *i} *) + and wait (union wait *), + prefer union wait * as type of parm. */ + if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE + && TREE_VALUE (p1) != TREE_VALUE (p2)) + { + tree memb; + for (memb = TYPE_FIELDS (TREE_VALUE (p1)); + memb; memb = TREE_CHAIN (memb)) + if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2))) + { + TREE_VALUE (n) = TREE_VALUE (p2); + if (pedantic) + pedwarn ("function types not truly compatible in ANSI C"); + goto parm_done; + } + } + if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE + && TREE_VALUE (p2) != TREE_VALUE (p1)) + { + tree memb; + for (memb = TYPE_FIELDS (TREE_VALUE (p2)); + memb; memb = TREE_CHAIN (memb)) + if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1))) + { + TREE_VALUE (n) = TREE_VALUE (p1); + if (pedantic) + pedwarn ("function types not truly compatible in ANSI C"); + goto parm_done; + } + } + TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2)); + parm_done: ; + } + + t1 = build_function_type (valtype, newargs); + /* ... falls through ... */ + } + + default: + return build_type_attribute_variant (t1, attributes); + } + +} + +/* Return 1 if TYPE1 and TYPE2 are compatible types for assignment + or various other operations. Return 2 if they are compatible + but a warning may be needed if you use them together. */ + +int +comptypes (type1, type2) + tree type1, type2; +{ + register tree t1 = type1; + register tree t2 = type2; + int attrval, val; + + /* Suppress errors caused by previously reported errors. */ + + if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK) + return 1; + + /* Treat an enum type as the integer type of the same width and + signedness. */ + + if (TREE_CODE (t1) == ENUMERAL_TYPE) + t1 = type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1)); + if (TREE_CODE (t2) == ENUMERAL_TYPE) + t2 = type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2)); + + if (t1 == t2) + return 1; + + /* Different classes of types can't be compatible. */ + + if (TREE_CODE (t1) != TREE_CODE (t2)) return 0; + + /* Qualifiers must match. */ + + if (TYPE_READONLY (t1) != TYPE_READONLY (t2)) + return 0; + if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2)) + return 0; + + /* Allow for two different type nodes which have essentially the same + definition. Note that we already checked for equality of the type + type qualifiers (just above). */ + + if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)) + return 1; + +#ifndef COMP_TYPE_ATTRIBUTES +#define COMP_TYPE_ATTRIBUTES(t1,t2) 1 +#endif + + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2))) + return 0; + + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + val = 0; + + switch (TREE_CODE (t1)) + { + case POINTER_TYPE: + val = (TREE_TYPE (t1) == TREE_TYPE (t2) + ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2))); + break; + + case FUNCTION_TYPE: + val = function_types_compatible_p (t1, t2); + break; + + case ARRAY_TYPE: + { + tree d1 = TYPE_DOMAIN (t1); + tree d2 = TYPE_DOMAIN (t2); + val = 1; + + /* Target types must match incl. qualifiers. */ + if (TREE_TYPE (t1) != TREE_TYPE (t2) + && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2)))) + return 0; + + /* Sizes must match unless one is missing or variable. */ + if (d1 == 0 || d2 == 0 || d1 == d2 + || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST + || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST + || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST + || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST) + break; + + if (! ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1)) + == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2))) + && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1)) + == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2))) + && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1)) + == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2))) + && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1)) + == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))))) + val = 0; + break; + } + + case RECORD_TYPE: + if (maybe_objc_comptypes (t1, t2, 0) == 1) + val = 1; + break; + } + return attrval == 2 && val == 1 ? 2 : val; +} + +/* Return 1 if TTL and TTR are pointers to types that are equivalent, + ignoring their qualifiers. */ + +static int +comp_target_types (ttl, ttr) + tree ttl, ttr; +{ + int val; + + /* Give maybe_objc_comptypes a crack at letting these types through. */ + if (val = maybe_objc_comptypes (ttl, ttr, 1) >= 0) + return val; + + val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)), + TYPE_MAIN_VARIANT (TREE_TYPE (ttr))); + + if (val == 2 && pedantic) + pedwarn ("types are not quite compatible"); + return val; +} + +/* Subroutines of `comptypes'. */ + +/* Return 1 if two function types F1 and F2 are compatible. + If either type specifies no argument types, + the other must specify a fixed number of self-promoting arg types. + Otherwise, if one type specifies only the number of arguments, + the other must specify that number of self-promoting arg types. + Otherwise, the argument types must match. */ + +static int +function_types_compatible_p (f1, f2) + tree f1, f2; +{ + tree args1, args2; + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + int val = 1; + int val1; + + if (!(TREE_TYPE (f1) == TREE_TYPE (f2) + || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2))))) + return 0; + + args1 = TYPE_ARG_TYPES (f1); + args2 = TYPE_ARG_TYPES (f2); + + /* An unspecified parmlist matches any specified parmlist + whose argument types don't need default promotions. */ + + if (args1 == 0) + { + if (!self_promoting_args_p (args2)) + return 0; + /* If one of these types comes from a non-prototype fn definition, + compare that with the other type's arglist. + If they don't match, ask for a warning (but no error). */ + if (TYPE_ACTUAL_ARG_TYPES (f1) + && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1))) + val = 2; + return val; + } + if (args2 == 0) + { + if (!self_promoting_args_p (args1)) + return 0; + if (TYPE_ACTUAL_ARG_TYPES (f2) + && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2))) + val = 2; + return val; + } + + /* Both types have argument lists: compare them and propagate results. */ + val1 = type_lists_compatible_p (args1, args2); + return val1 != 1 ? val1 : val; +} + +/* Check two lists of types for compatibility, + returning 0 for incompatible, 1 for compatible, + or 2 for compatible with warning. */ + +static int +type_lists_compatible_p (args1, args2) + tree args1, args2; +{ + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + int val = 1; + int newval = 0; + + while (1) + { + if (args1 == 0 && args2 == 0) + return val; + /* If one list is shorter than the other, + they fail to match. */ + if (args1 == 0 || args2 == 0) + return 0; + /* A null pointer instead of a type + means there is supposed to be an argument + but nothing is specified about what type it has. + So match anything that self-promotes. */ + if (TREE_VALUE (args1) == 0) + { + if (! self_promoting_type_p (TREE_VALUE (args2))) + return 0; + } + else if (TREE_VALUE (args2) == 0) + { + if (! self_promoting_type_p (TREE_VALUE (args1))) + return 0; + } + else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2)))) + { + /* Allow wait (union {union wait *u; int *i} *) + and wait (union wait *) to be compatible. */ + if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE + && (TYPE_NAME (TREE_VALUE (args1)) == 0 + || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1))) + && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST + && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)), + TYPE_SIZE (TREE_VALUE (args2)))) + { + tree memb; + for (memb = TYPE_FIELDS (TREE_VALUE (args1)); + memb; memb = TREE_CHAIN (memb)) + if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2))) + break; + if (memb == 0) + return 0; + } + else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE + && (TYPE_NAME (TREE_VALUE (args2)) == 0 + || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2))) + && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST + && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)), + TYPE_SIZE (TREE_VALUE (args1)))) + { + tree memb; + for (memb = TYPE_FIELDS (TREE_VALUE (args2)); + memb; memb = TREE_CHAIN (memb)) + if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1))) + break; + if (memb == 0) + return 0; + } + else + return 0; + } + + /* comptypes said ok, but record if it said to warn. */ + if (newval > val) + val = newval; + + args1 = TREE_CHAIN (args1); + args2 = TREE_CHAIN (args2); + } +} + +/* Return 1 if PARMS specifies a fixed number of parameters + and none of their types is affected by default promotions. */ + +int +self_promoting_args_p (parms) + tree parms; +{ + register tree t; + for (t = parms; t; t = TREE_CHAIN (t)) + { + register tree type = TREE_VALUE (t); + + if (TREE_CHAIN (t) == 0 && type != void_type_node) + return 0; + + if (type == 0) + return 0; + + if (TYPE_MAIN_VARIANT (type) == float_type_node) + return 0; + + if (C_PROMOTING_INTEGER_TYPE_P (type)) + return 0; + } + return 1; +} + +/* Return 1 if TYPE is not affected by default promotions. */ + +static int +self_promoting_type_p (type) + tree type; +{ + if (TYPE_MAIN_VARIANT (type) == float_type_node) + return 0; + + if (C_PROMOTING_INTEGER_TYPE_P (type)) + return 0; + + return 1; +} + +/* Return an unsigned type the same as TYPE in other respects. */ + +tree +unsigned_type (type) + tree type; +{ + tree type1 = TYPE_MAIN_VARIANT (type); + if (type1 == signed_char_type_node || type1 == char_type_node) + return unsigned_char_type_node; + if (type1 == integer_type_node) + return unsigned_type_node; + if (type1 == short_integer_type_node) + return short_unsigned_type_node; + if (type1 == long_integer_type_node) + return long_unsigned_type_node; + if (type1 == long_long_integer_type_node) + return long_long_unsigned_type_node; + if (type1 == intDI_type_node) + return unsigned_intDI_type_node; + if (type1 == intSI_type_node) + return unsigned_intSI_type_node; + if (type1 == intHI_type_node) + return unsigned_intHI_type_node; + if (type1 == intQI_type_node) + return unsigned_intQI_type_node; + return type; +} + +/* Return a signed type the same as TYPE in other respects. */ + +tree +signed_type (type) + tree type; +{ + tree type1 = TYPE_MAIN_VARIANT (type); + if (type1 == unsigned_char_type_node || type1 == char_type_node) + return signed_char_type_node; + if (type1 == unsigned_type_node) + return integer_type_node; + if (type1 == short_unsigned_type_node) + return short_integer_type_node; + if (type1 == long_unsigned_type_node) + return long_integer_type_node; + if (type1 == long_long_unsigned_type_node) + return long_long_integer_type_node; + if (type1 == unsigned_intDI_type_node) + return intDI_type_node; + if (type1 == unsigned_intSI_type_node) + return intSI_type_node; + if (type1 == unsigned_intHI_type_node) + return intHI_type_node; + if (type1 == unsigned_intQI_type_node) + return intQI_type_node; + return type; +} + +/* Return a type the same as TYPE except unsigned or + signed according to UNSIGNEDP. */ + +tree +signed_or_unsigned_type (unsignedp, type) + int unsignedp; + tree type; +{ + if (! INTEGRAL_TYPE_P (type)) + return type; + if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)) + return unsignedp ? unsigned_char_type_node : signed_char_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) + return unsignedp ? unsigned_type_node : integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) + return unsignedp ? short_unsigned_type_node : short_integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) + return unsignedp ? long_unsigned_type_node : long_integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) + return (unsignedp ? long_long_unsigned_type_node + : long_long_integer_type_node); + return type; +} + +/* Compute the value of the `sizeof' operator. */ + +tree +c_sizeof (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("sizeof applied to a function type"); + return size_int (1); + } + if (code == VOID_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("sizeof applied to a void type"); + return size_int (1); + } + if (code == ERROR_MARK) + return size_int (1); + if (TYPE_SIZE (type) == 0) + { + error ("sizeof applied to an incomplete type"); + return size_int (0); + } + + /* Convert in case a char is more than one unit. */ + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (TYPE_PRECISION (char_type_node))); + /* size_binop does not put the constant in range, so do it now. */ + if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0)) + TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1; + return t; +} + +tree +c_sizeof_nowarn (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE + || code == VOID_TYPE + || code == ERROR_MARK) + return size_int (1); + if (TYPE_SIZE (type) == 0) + return size_int (0); + + /* Convert in case a char is more than one unit. */ + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (TYPE_PRECISION (char_type_node))); + force_fit_type (t, 0); + return t; +} + +/* Compute the size to increment a pointer by. */ + +tree +c_size_in_bytes (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE) + return size_int (1); + if (code == VOID_TYPE) + return size_int (1); + if (code == ERROR_MARK) + return size_int (1); + if (TYPE_SIZE (type) == 0) + { + error ("arithmetic on pointer to an incomplete type"); + return size_int (1); + } + + /* Convert in case a char is more than one unit. */ + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (BITS_PER_UNIT)); + force_fit_type (t, 0); + return t; +} + +/* Implement the __alignof keyword: Return the minimum required + alignment of TYPE, measured in bytes. */ + +tree +c_alignof (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + + if (code == FUNCTION_TYPE) + return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT); + + if (code == VOID_TYPE || code == ERROR_MARK) + return size_int (1); + + return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT); +} + +/* Implement the __alignof keyword: Return the minimum required + alignment of EXPR, measured in bytes. For VAR_DECL's and + FIELD_DECL's return DECL_ALIGN (which can be set from an + "aligned" __attribute__ specification). */ + +tree +c_alignof_expr (expr) + tree expr; +{ + if (TREE_CODE (expr) == VAR_DECL) + return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT); + + if (TREE_CODE (expr) == COMPONENT_REF + && DECL_BIT_FIELD (TREE_OPERAND (expr, 1))) + { + error ("`__alignof' applied to a bit-field"); + return size_int (1); + } + else if (TREE_CODE (expr) == COMPONENT_REF + && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL) + return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT); + + if (TREE_CODE (expr) == INDIRECT_REF) + { + tree t = TREE_OPERAND (expr, 0); + tree best = t; + int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); + + while (TREE_CODE (t) == NOP_EXPR + && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE) + { + int thisalign; + + t = TREE_OPERAND (t, 0); + thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); + if (thisalign > bestalign) + best = t, bestalign = thisalign; + } + return c_alignof (TREE_TYPE (TREE_TYPE (best))); + } + else + return c_alignof (TREE_TYPE (expr)); +} +/* Return either DECL or its known constant value (if it has one). */ + +static tree +decl_constant_value (decl) + tree decl; +{ + if (! TREE_PUBLIC (decl) + /* Don't change a variable array bound or initial value to a constant + in a place where a variable is invalid. */ + && current_function_decl != 0 + && ! pedantic + && ! TREE_THIS_VOLATILE (decl) + && TREE_READONLY (decl) && ! ITERATOR_P (decl) + && DECL_INITIAL (decl) != 0 + && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK + /* This is invalid if initial value is not constant. + If it has either a function call, a memory reference, + or a variable, then re-evaluating it could give different results. */ + && TREE_CONSTANT (DECL_INITIAL (decl)) + /* Check for cases where this is sub-optimal, even though valid. */ + && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR + && DECL_MODE (decl) != BLKmode) + return DECL_INITIAL (decl); + return decl; +} + +/* Perform default promotions for C data used in expressions. + Arrays and functions are converted to pointers; + enumeral types or short or char, to int. + In addition, manifest constants symbols are replaced by their values. */ + +tree +default_conversion (exp) + tree exp; +{ + register tree type = TREE_TYPE (exp); + register enum tree_code code = TREE_CODE (type); + + /* Constants can be used directly unless they're not loadable. */ + if (TREE_CODE (exp) == CONST_DECL) + exp = DECL_INITIAL (exp); + + /* Replace a nonvolatile const static variable with its value unless + it is an array, in which case we must be sure that taking the + address of the array produces consistent results. */ + else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE) + { + exp = decl_constant_value (exp); + type = TREE_TYPE (exp); + } + + /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as + an lvalue. */ + /* Do not use STRIP_NOPS here! It will remove conversions from pointer + to integer and cause infinite recursion. */ + while (TREE_CODE (exp) == NON_LVALUE_EXPR + || (TREE_CODE (exp) == NOP_EXPR + && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp))) + exp = TREE_OPERAND (exp, 0); + + /* Normally convert enums to int, + but convert wide enums to something wider. */ + if (code == ENUMERAL_TYPE) + { + type = type_for_size (MAX (TYPE_PRECISION (type), + TYPE_PRECISION (integer_type_node)), + ((flag_traditional + || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)) + && TREE_UNSIGNED (type))); + return convert (type, exp); + } + + if (C_PROMOTING_INTEGER_TYPE_P (type)) + { + /* Traditionally, unsignedness is preserved in default promotions. + Also preserve unsignedness if not really getting any wider. */ + if (TREE_UNSIGNED (type) + && (flag_traditional + || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))) + return convert (unsigned_type_node, exp); + return convert (integer_type_node, exp); + } + if (flag_traditional && !flag_allow_single_precision + && TYPE_MAIN_VARIANT (type) == float_type_node) + return convert (double_type_node, exp); + if (code == VOID_TYPE) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + if (code == FUNCTION_TYPE) + { + return build_unary_op (ADDR_EXPR, exp, 0); + } + if (code == ARRAY_TYPE) + { + register tree adr; + tree restype = TREE_TYPE (type); + tree ptrtype; + int constp = 0; + int volatilep = 0; + + if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r' + || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd') + { + constp = TREE_READONLY (exp); + volatilep = TREE_THIS_VOLATILE (exp); + } + + if (TYPE_READONLY (type) || TYPE_VOLATILE (type) + || constp || volatilep) + restype = c_build_type_variant (restype, + TYPE_READONLY (type) || constp, + TYPE_VOLATILE (type) || volatilep); + + if (TREE_CODE (exp) == INDIRECT_REF) + return convert (TYPE_POINTER_TO (restype), + TREE_OPERAND (exp, 0)); + + if (TREE_CODE (exp) == COMPOUND_EXPR) + { + tree op1 = default_conversion (TREE_OPERAND (exp, 1)); + return build (COMPOUND_EXPR, TREE_TYPE (op1), + TREE_OPERAND (exp, 0), op1); + } + + if (!lvalue_p (exp) + && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp))) + { + error ("invalid use of non-lvalue array"); + return error_mark_node; + } + + ptrtype = build_pointer_type (restype); + + if (TREE_CODE (exp) == VAR_DECL) + { + /* ??? This is not really quite correct + in that the type of the operand of ADDR_EXPR + is not the target type of the type of the ADDR_EXPR itself. + Question is, can this lossage be avoided? */ + adr = build1 (ADDR_EXPR, ptrtype, exp); + if (mark_addressable (exp) == 0) + return error_mark_node; + TREE_CONSTANT (adr) = staticp (exp); + TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */ + return adr; + } + /* This way is better for a COMPONENT_REF since it can + simplify the offset for a component. */ + adr = build_unary_op (ADDR_EXPR, exp, 1); + return convert (ptrtype, adr); + } + return exp; +} + +/* Look up component name in the structure type definition. + + If this component name is found indirectly within an anonymous union, + store in *INDIRECT the component which directly contains + that anonymous union. Otherwise, set *INDIRECT to 0. */ + +static tree +lookup_field (type, component, indirect) + tree type, component; + tree *indirect; +{ + tree field; + + /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers + to the field elements. Use a binary search on this array to quickly + find the element. Otherwise, do a linear search. TYPE_LANG_SPECIFIC + will always be set for structures which have many elements. */ + + if (TYPE_LANG_SPECIFIC (type)) + { + int bot, top, half; + tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0]; + + field = TYPE_FIELDS (type); + bot = 0; + top = TYPE_LANG_SPECIFIC (type)->len; + while (top - bot > 1) + { + half = (top - bot + 1) >> 1; + field = field_array[bot+half]; + + if (DECL_NAME (field) == NULL_TREE) + { + /* Step through all anon unions in linear fashion. */ + while (DECL_NAME (field_array[bot]) == NULL_TREE) + { + tree anon, junk; + + field = field_array[bot++]; + anon = lookup_field (TREE_TYPE (field), component, &junk); + if (anon != NULL_TREE) + { + *indirect = field; + return anon; + } + } + + /* Entire record is only anon unions. */ + if (bot > top) + return NULL_TREE; + + /* Restart the binary search, with new lower bound. */ + continue; + } + + if (DECL_NAME (field) == component) + break; + if (DECL_NAME (field) < component) + bot += half; + else + top = bot + half; + } + + if (DECL_NAME (field_array[bot]) == component) + field = field_array[bot]; + else if (DECL_NAME (field) != component) + field = 0; + } + else + { + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + { + if (DECL_NAME (field) == NULL_TREE) + { + tree junk; + tree anon = lookup_field (TREE_TYPE (field), component, &junk); + if (anon != NULL_TREE) + { + *indirect = field; + return anon; + } + } + + if (DECL_NAME (field) == component) + break; + } + } + + *indirect = NULL_TREE; + return field; +} + +/* Make an expression to refer to the COMPONENT field of + structure or union value DATUM. COMPONENT is an IDENTIFIER_NODE. */ + +tree +build_component_ref (datum, component) + tree datum, component; +{ + register tree type = TREE_TYPE (datum); + register enum tree_code code = TREE_CODE (type); + register tree field = NULL; + register tree ref; + + /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it + unless we are not to support things not strictly ANSI. */ + switch (TREE_CODE (datum)) + { + case COMPOUND_EXPR: + { + tree value = build_component_ref (TREE_OPERAND (datum, 1), component); + return build (COMPOUND_EXPR, TREE_TYPE (value), + TREE_OPERAND (datum, 0), value); + } + case COND_EXPR: + return build_conditional_expr + (TREE_OPERAND (datum, 0), + build_component_ref (TREE_OPERAND (datum, 1), component), + build_component_ref (TREE_OPERAND (datum, 2), component)); + } + + /* See if there is a field or component with name COMPONENT. */ + + if (code == RECORD_TYPE || code == UNION_TYPE) + { + tree indirect = 0; + + if (TYPE_SIZE (type) == 0) + { + incomplete_type_error (NULL_TREE, type); + return error_mark_node; + } + + field = lookup_field (type, component, &indirect); + + if (!field) + { + error (code == RECORD_TYPE + ? "structure has no member named `%s'" + : "union has no member named `%s'", + IDENTIFIER_POINTER (component)); + return error_mark_node; + } + if (TREE_TYPE (field) == error_mark_node) + return error_mark_node; + + /* If FIELD was found buried within an anonymous union, + make one COMPONENT_REF to get that anonymous union, + then fall thru to make a second COMPONENT_REF to get FIELD. */ + if (indirect != 0) + { + ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect); + if (TREE_READONLY (datum) || TREE_READONLY (indirect)) + TREE_READONLY (ref) = 1; + if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect)) + TREE_THIS_VOLATILE (ref) = 1; + datum = ref; + } + + ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field); + + if (TREE_READONLY (datum) || TREE_READONLY (field)) + TREE_READONLY (ref) = 1; + if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field)) + TREE_THIS_VOLATILE (ref) = 1; + + return ref; + } + else if (code != ERROR_MARK) + error ("request for member `%s' in something not a structure or union", + IDENTIFIER_POINTER (component)); + + return error_mark_node; +} + +/* Given an expression PTR for a pointer, return an expression + for the value pointed to. + ERRORSTRING is the name of the operator to appear in error messages. */ + +tree +build_indirect_ref (ptr, errorstring) + tree ptr; + char *errorstring; +{ + register tree pointer = default_conversion (ptr); + register tree type = TREE_TYPE (pointer); + + if (TREE_CODE (type) == POINTER_TYPE) + { + if (TREE_CODE (pointer) == ADDR_EXPR + && !flag_volatile + && (TREE_TYPE (TREE_OPERAND (pointer, 0)) + == TREE_TYPE (type))) + return TREE_OPERAND (pointer, 0); + else + { + tree t = TREE_TYPE (type); + register tree ref = build1 (INDIRECT_REF, + TYPE_MAIN_VARIANT (t), pointer); + + if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE) + { + error ("dereferencing pointer to incomplete type"); + return error_mark_node; + } + if (TREE_CODE (t) == VOID_TYPE) + warning ("dereferencing `void *' pointer"); + + /* We *must* set TREE_READONLY when dereferencing a pointer to const, + so that we get the proper error message if the result is used + to assign to. Also, &* is supposed to be a no-op. + And ANSI C seems to specify that the type of the result + should be the const type. */ + /* A de-reference of a pointer to const is not a const. It is valid + to change it via some other pointer. */ + TREE_READONLY (ref) = TYPE_READONLY (t); + TREE_SIDE_EFFECTS (ref) + = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile; + TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t); + return ref; + } + } + else if (TREE_CODE (pointer) != ERROR_MARK) + error ("invalid type argument of `%s'", errorstring); + return error_mark_node; +} + +/* This handles expressions of the form "a[i]", which denotes + an array reference. + + This is logically equivalent in C to *(a+i), but we may do it differently. + If A is a variable or a member, we generate a primitive ARRAY_REF. + This avoids forcing the array out of registers, and can work on + arrays that are not lvalues (for example, members of structures returned + by functions). */ + +tree +build_array_ref (array, index) + tree array, index; +{ + if (index == 0) + { + error ("subscript missing in array reference"); + return error_mark_node; + } + + if (TREE_TYPE (array) == error_mark_node + || TREE_TYPE (index) == error_mark_node) + return error_mark_node; + + if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE + && TREE_CODE (array) != INDIRECT_REF) + { + tree rval, type; + + /* Subscripting with type char is likely to lose + on a machine where chars are signed. + So warn on any machine, but optionally. + Don't warn for unsigned char since that type is safe. + Don't warn for signed char because anyone who uses that + must have done so deliberately. */ + if (warn_char_subscripts + && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node) + warning ("array subscript has type `char'"); + + /* Apply default promotions *after* noticing character types. */ + index = default_conversion (index); + + /* Require integer *after* promotion, for sake of enums. */ + if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE) + { + error ("array subscript is not an integer"); + return error_mark_node; + } + + /* An array that is indexed by a non-constant + cannot be stored in a register; we must be able to do + address arithmetic on its address. + Likewise an array of elements of variable size. */ + if (TREE_CODE (index) != INTEGER_CST + || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0 + && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)) + { + if (mark_addressable (array) == 0) + return error_mark_node; + } + /* An array that is indexed by a constant value which is not within + the array bounds cannot be stored in a register either; because we + would get a crash in store_bit_field/extract_bit_field when trying + to access a non-existent part of the register. */ + if (TREE_CODE (index) == INTEGER_CST + && TYPE_VALUES (TREE_TYPE (array)) + && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array)))) + { + if (mark_addressable (array) == 0) + return error_mark_node; + } + + if (pedantic && !lvalue_p (array)) + { + if (DECL_REGISTER (array)) + pedwarn ("ANSI C forbids subscripting `register' array"); + else + pedwarn ("ANSI C forbids subscripting non-lvalue array"); + } + + if (pedantic) + { + tree foo = array; + while (TREE_CODE (foo) == COMPONENT_REF) + foo = TREE_OPERAND (foo, 0); + if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo)) + pedwarn ("ANSI C forbids subscripting non-lvalue array"); + } + + type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array))); + rval = build (ARRAY_REF, type, array, index); + /* Array ref is const/volatile if the array elements are + or if the array is. */ + TREE_READONLY (rval) + |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array))) + | TREE_READONLY (array)); + TREE_SIDE_EFFECTS (rval) + |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) + | TREE_SIDE_EFFECTS (array)); + TREE_THIS_VOLATILE (rval) + |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) + /* This was added by rms on 16 Nov 91. + It fixes vol struct foo *a; a->elts[1] + in an inline function. + Hope it doesn't break something else. */ + | TREE_THIS_VOLATILE (array)); + return require_complete_type (fold (rval)); + } + + { + tree ar = default_conversion (array); + tree ind = default_conversion (index); + + /* Put the integer in IND to simplify error checking. */ + if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE) + { + tree temp = ar; + ar = ind; + ind = temp; + } + + if (ar == error_mark_node) + return ar; + + if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE) + { + error ("subscripted value is neither array nor pointer"); + return error_mark_node; + } + if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE) + { + error ("array subscript is not an integer"); + return error_mark_node; + } + + return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0), + "array indexing"); + } +} + +/* Build a function call to function FUNCTION with parameters PARAMS. + PARAMS is a list--a chain of TREE_LIST nodes--in which the + TREE_VALUE of each node is a parameter-expression. + FUNCTION's data type may be a function type or a pointer-to-function. */ + +tree +build_function_call (function, params) + tree function, params; +{ + register tree fntype, fundecl = 0; + register tree coerced_params; + tree name = NULL_TREE, assembler_name = NULL_TREE; + + /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */ + STRIP_TYPE_NOPS (function); + + /* Convert anything with function type to a pointer-to-function. */ + if (TREE_CODE (function) == FUNCTION_DECL) + { + name = DECL_NAME (function); + assembler_name = DECL_ASSEMBLER_NAME (function); + + /* Differs from default_conversion by not setting TREE_ADDRESSABLE + (because calling an inline function does not mean the function + needs to be separately compiled). */ + fntype = build_type_variant (TREE_TYPE (function), + TREE_READONLY (function), + TREE_THIS_VOLATILE (function)); + fundecl = function; + function = build1 (ADDR_EXPR, build_pointer_type (fntype), function); + } + else + function = default_conversion (function); + + fntype = TREE_TYPE (function); + + if (TREE_CODE (fntype) == ERROR_MARK) + return error_mark_node; + + if (!(TREE_CODE (fntype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)) + { + error ("called object is not a function"); + return error_mark_node; + } + + /* fntype now gets the type of function pointed to. */ + fntype = TREE_TYPE (fntype); + + /* Convert the parameters to the types declared in the + function prototype, or apply default promotions. */ + + coerced_params + = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl); + + /* Check for errors in format strings. */ + + if (warn_format && (name || assembler_name)) + check_function_format (name, assembler_name, coerced_params); + + /* Recognize certain built-in functions so we can make tree-codes + other than CALL_EXPR. We do this when it enables fold-const.c + to do something useful. */ + + if (TREE_CODE (function) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL + && DECL_BUILT_IN (TREE_OPERAND (function, 0))) + switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0))) + { + case BUILT_IN_ABS: + case BUILT_IN_LABS: + case BUILT_IN_FABS: + if (coerced_params == 0) + return integer_zero_node; + return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0); + } + + { + register tree result + = build (CALL_EXPR, TREE_TYPE (fntype), + function, coerced_params, NULL_TREE); + + TREE_SIDE_EFFECTS (result) = 1; + if (TREE_TYPE (result) == void_type_node) + return result; + return require_complete_type (result); + } +} + +/* Convert the argument expressions in the list VALUES + to the types in the list TYPELIST. The result is a list of converted + argument expressions. + + If TYPELIST is exhausted, or when an element has NULL as its type, + perform the default conversions. + + PARMLIST is the chain of parm decls for the function being called. + It may be 0, if that info is not available. + It is used only for generating error messages. + + NAME is an IDENTIFIER_NODE or 0. It is used only for error messages. + + This is also where warnings about wrong number of args are generated. + + Both VALUES and the returned value are chains of TREE_LIST nodes + with the elements of the list in the TREE_VALUE slots of those nodes. */ + +static tree +convert_arguments (typelist, values, name, fundecl) + tree typelist, values, name, fundecl; +{ + register tree typetail, valtail; + register tree result = NULL; + int parmnum; + + /* Scan the given expressions and types, producing individual + converted arguments and pushing them on RESULT in reverse order. */ + + for (valtail = values, typetail = typelist, parmnum = 0; + valtail; + valtail = TREE_CHAIN (valtail), parmnum++) + { + register tree type = typetail ? TREE_VALUE (typetail) : 0; + register tree val = TREE_VALUE (valtail); + + if (type == void_type_node) + { + if (name) + error ("too many arguments to function `%s'", + IDENTIFIER_POINTER (name)); + else + error ("too many arguments to function"); + break; + } + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + /* Do not use STRIP_NOPS here! We do not want an enumerator with value 0 + to convert automatically to a pointer. */ + if (TREE_CODE (val) == NON_LVALUE_EXPR) + val = TREE_OPERAND (val, 0); + + if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE) + val = default_conversion (val); + + val = require_complete_type (val); + + if (type != 0) + { + /* Formal parm type is specified by a function prototype. */ + tree parmval; + + if (TYPE_SIZE (type) == 0) + { + error ("type of formal parameter %d is incomplete", parmnum + 1); + parmval = val; + } + else + { + /* Optionally warn about conversions that + differ from the default conversions. */ + if (warn_conversion) + { + int formal_prec = TYPE_PRECISION (type); + + if (INTEGRAL_TYPE_P (type) + && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) + warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1); + else if (TREE_CODE (type) == COMPLEX_TYPE + && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) + warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1); + else if (TREE_CODE (type) == REAL_TYPE + && INTEGRAL_TYPE_P (TREE_TYPE (val))) + warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1); + else if (TREE_CODE (type) == REAL_TYPE + && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE) + warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1); + /* ??? At some point, messages should be written about + conversions between complex types, but that's too messy + to do now. */ + else if (TREE_CODE (type) == REAL_TYPE + && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE) + { + /* Warn if any argument is passed as `float', + since without a prototype it would be `double'. */ + if (formal_prec == TYPE_PRECISION (float_type_node)) + warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1); + } + /* Detect integer changing in width or signedness. */ + else if (INTEGRAL_TYPE_P (type) + && INTEGRAL_TYPE_P (TREE_TYPE (val))) + { + tree would_have_been = default_conversion (val); + tree type1 = TREE_TYPE (would_have_been); + + if (TREE_CODE (type) == ENUMERAL_TYPE + && type == TREE_TYPE (val)) + /* No warning if function asks for enum + and the actual arg is that enum type. */ + ; + else if (formal_prec != TYPE_PRECISION (type1)) + warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1); + else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1)) + ; + /* Don't complain if the formal parameter type + is an enum, because we can't tell now whether + the value was an enum--even the same enum. */ + else if (TREE_CODE (type) == ENUMERAL_TYPE) + ; + else if (TREE_CODE (val) == INTEGER_CST + && int_fits_type_p (val, type)) + /* Change in signedness doesn't matter + if a constant value is unaffected. */ + ; + /* Likewise for a constant in a NOP_EXPR. */ + else if (TREE_CODE (val) == NOP_EXPR + && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST + && int_fits_type_p (TREE_OPERAND (val, 0), type)) + ; +#if 0 /* We never get such tree structure here. */ + else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE + && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type) + && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type)) + /* Change in signedness doesn't matter + if an enum value is unaffected. */ + ; +#endif + /* If the value is extended from a narrower + unsigned type, it doesn't matter whether we + pass it as signed or unsigned; the value + certainly is the same either way. */ + else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type) + && TREE_UNSIGNED (TREE_TYPE (val))) + ; + else if (TREE_UNSIGNED (type)) + warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1); + else + warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1); + } + } + + parmval = convert_for_assignment (type, val, + (char *)0, /* arg passing */ + fundecl, name, parmnum + 1); + +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) + parmval = default_conversion (parmval); +#endif + } + result = tree_cons (NULL_TREE, parmval, result); + } + else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE + && (TYPE_PRECISION (TREE_TYPE (val)) + < TYPE_PRECISION (double_type_node))) + /* Convert `float' to `double'. */ + result = tree_cons (NULL_TREE, convert (double_type_node, val), result); + else + /* Convert `short' and `char' to full-size `int'. */ + result = tree_cons (NULL_TREE, default_conversion (val), result); + + if (typetail) + typetail = TREE_CHAIN (typetail); + } + + if (typetail != 0 && TREE_VALUE (typetail) != void_type_node) + { + if (name) + error ("too few arguments to function `%s'", + IDENTIFIER_POINTER (name)); + else + error ("too few arguments to function"); + } + + return nreverse (result); +} + +/* This is the entry point used by the parser + for binary operators in the input. + In addition to constructing the expression, + we check for operands that were written with other binary operators + in a way that is likely to confuse the user. */ + +tree +parser_build_binary_op (code, arg1, arg2) + enum tree_code code; + tree arg1, arg2; +{ + tree result = build_binary_op (code, arg1, arg2, 1); + + char class; + char class1 = TREE_CODE_CLASS (TREE_CODE (arg1)); + char class2 = TREE_CODE_CLASS (TREE_CODE (arg2)); + enum tree_code code1 = ERROR_MARK; + enum tree_code code2 = ERROR_MARK; + + if (class1 == 'e' || class1 == '1' + || class1 == '2' || class1 == '<') + code1 = C_EXP_ORIGINAL_CODE (arg1); + if (class2 == 'e' || class2 == '1' + || class2 == '2' || class2 == '<') + code2 = C_EXP_ORIGINAL_CODE (arg2); + + /* Check for cases such as x+y< TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0))) + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0)))) + { + final_type = result_type; + op1 = TREE_OPERAND (op1, 0); + result_type = TREE_TYPE (op1); + } + if (TREE_CODE (op1) == INTEGER_CST + && TREE_CODE (op0) == NOP_EXPR + && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))) + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0)))) + { + final_type = result_type; + op0 = TREE_OPERAND (op0, 0); + result_type = TREE_TYPE (op0); + } + break; + + case TRUNC_MOD_EXPR: + case FLOOR_MOD_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + /* Although it would be tempting to shorten always here, that loses + on some targets, since the modulo instruction is undefined if the + quotient can't be represented in the computation mode. We shorten + only if unsigned or if dividing by something we know != -1. */ + shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0)) + || (TREE_CODE (op1) == INTEGER_CST + && (TREE_INT_CST_LOW (op1) != -1 + || TREE_INT_CST_HIGH (op1) != -1))); + common = 1; + } + break; + + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + case TRUTH_XOR_EXPR: + if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE + || code0 == REAL_TYPE || code0 == COMPLEX_TYPE) + && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE + || code1 == REAL_TYPE || code1 == COMPLEX_TYPE)) + { + /* Result of these operations is always an int, + but that does not mean the operands should be + converted to ints! */ + result_type = integer_type_node; + op0 = truthvalue_conversion (op0); + op1 = truthvalue_conversion (op1); + converted = 1; + } + break; + + /* Shift operations: result has same type as first operand; + always convert second operand to int. + Also set SHORT_SHIFT if shifting rightward. */ + + case RSHIFT_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_sgn (op1) < 0) + warning ("right shift count is negative"); + else + { + if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1)) + short_shift = 1; + if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("right shift count >= width of type"); + } + } + /* Use the type of the value to be shifted. + This is what most traditional C compilers do. */ + result_type = type0; + /* Unless traditional, convert the shift-count to an integer, + regardless of size of value being shifted. */ + if (! flag_traditional) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + /* Avoid converting op1 to result_type later. */ + converted = 1; + } + } + break; + + case LSHIFT_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_sgn (op1) < 0) + warning ("left shift count is negative"); + else if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("left shift count >= width of type"); + } + /* Use the type of the value to be shifted. + This is what most traditional C compilers do. */ + result_type = type0; + /* Unless traditional, convert the shift-count to an integer, + regardless of size of value being shifted. */ + if (! flag_traditional) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + /* Avoid converting op1 to result_type later. */ + converted = 1; + } + } + break; + + case RROTATE_EXPR: + case LROTATE_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_sgn (op1) < 0) + warning ("shift count is negative"); + else if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("shift count >= width of type"); + } + /* Use the type of the value to be shifted. + This is what most traditional C compilers do. */ + result_type = type0; + /* Unless traditional, convert the shift-count to an integer, + regardless of size of value being shifted. */ + if (! flag_traditional) + { + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + /* Avoid converting op1 to result_type later. */ + converted = 1; + } + } + break; + + case EQ_EXPR: + case NE_EXPR: + /* Result of comparison is always int, + but don't convert the args to int! */ + build_type = integer_type_node; + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE + || code0 == COMPLEX_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE + || code1 == COMPLEX_TYPE)) + short_compare = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + register tree tt0 = TREE_TYPE (type0); + register tree tt1 = TREE_TYPE (type1); + /* Anything compares with void *. void * compares with anything. + Otherwise, the targets must be compatible + and both must be object or both incomplete. */ + if (comp_target_types (type0, type1)) + result_type = common_type (type0, type1); + else if (TYPE_MAIN_VARIANT (tt0) == void_type_node) + { + /* op0 != orig_op0 detects the case of something + whose value is 0 but which isn't a valid null ptr const. */ + if (pedantic && (!integer_zerop (op0) || op0 != orig_op0) + && TREE_CODE (tt1) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids comparison of `void *' with function pointer"); + } + else if (TYPE_MAIN_VARIANT (tt1) == void_type_node) + { + if (pedantic && (!integer_zerop (op1) || op1 != orig_op1) + && TREE_CODE (tt0) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids comparison of `void *' with function pointer"); + } + else + pedwarn ("comparison of distinct pointer types lacks a cast"); + + if (result_type == NULL_TREE) + result_type = ptr_type_node; + } + else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST + && integer_zerop (op1)) + result_type = type0; + else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST + && integer_zerop (op0)) + result_type = type1; + else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (! flag_traditional) + pedwarn ("comparison between pointer and integer"); + } + else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + { + result_type = type1; + if (! flag_traditional) + pedwarn ("comparison between pointer and integer"); + } + break; + + case MAX_EXPR: + case MIN_EXPR: + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + shorten = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + if (comp_target_types (type0, type1)) + { + result_type = common_type (type0, type1); + if (pedantic + && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids ordered comparisons of pointers to functions"); + } + else + { + result_type = ptr_type_node; + pedwarn ("comparison of distinct pointer types lacks a cast"); + } + } + break; + + case LE_EXPR: + case GE_EXPR: + case LT_EXPR: + case GT_EXPR: + build_type = integer_type_node; + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + short_compare = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + if (comp_target_types (type0, type1)) + { + result_type = common_type (type0, type1); + if ((TYPE_SIZE (TREE_TYPE (type0)) != 0) + != (TYPE_SIZE (TREE_TYPE (type1)) != 0)) + pedwarn ("comparison of complete and incomplete pointers"); + else if (pedantic + && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids ordered comparisons of pointers to functions"); + } + else + { + result_type = ptr_type_node; + pedwarn ("comparison of distinct pointer types lacks a cast"); + } + } + else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST + && integer_zerop (op1)) + { + result_type = type0; + if (pedantic || extra_warnings) + pedwarn ("ordered comparison of pointer with integer zero"); + } + else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST + && integer_zerop (op0)) + { + result_type = type1; + if (pedantic) + pedwarn ("ordered comparison of pointer with integer zero"); + } + else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (! flag_traditional) + pedwarn ("comparison between pointer and integer"); + } + else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + { + result_type = type1; + if (! flag_traditional) + pedwarn ("comparison between pointer and integer"); + } + break; + } + + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE) + && + (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE)) + { + int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE); + + if (shorten || common || short_compare) + result_type = common_type (type0, type1); + + /* For certain operations (which identify themselves by shorten != 0) + if both args were extended from the same smaller type, + do the arithmetic in that type and then extend. + + shorten !=0 and !=1 indicates a bitwise operation. + For them, this optimization is safe only if + both args are zero-extended or both are sign-extended. + Otherwise, we might change the result. + Eg, (short)-1 | (unsigned short)-1 is (int)-1 + but calculated in (unsigned short) it would be (unsigned short)-1. */ + + if (shorten && none_complex) + { + int unsigned0, unsigned1; + tree arg0 = get_narrower (op0, &unsigned0); + tree arg1 = get_narrower (op1, &unsigned1); + /* UNS is 1 if the operation to be done is an unsigned one. */ + int uns = TREE_UNSIGNED (result_type); + tree type; + + final_type = result_type; + + /* Handle the case that OP0 (or OP1) does not *contain* a conversion + but it *requires* conversion to FINAL_TYPE. */ + + if ((TYPE_PRECISION (TREE_TYPE (op0)) + == TYPE_PRECISION (TREE_TYPE (arg0))) + && TREE_TYPE (op0) != final_type) + unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0)); + if ((TYPE_PRECISION (TREE_TYPE (op1)) + == TYPE_PRECISION (TREE_TYPE (arg1))) + && TREE_TYPE (op1) != final_type) + unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1)); + + /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */ + + /* For bitwise operations, signedness of nominal type + does not matter. Consider only how operands were extended. */ + if (shorten == -1) + uns = unsigned0; + + /* Note that in all three cases below we refrain from optimizing + an unsigned operation on sign-extended args. + That would not be valid. */ + + /* Both args variable: if both extended in same way + from same width, do it in that width. + Do it unsigned if args were zero-extended. */ + if ((TYPE_PRECISION (TREE_TYPE (arg0)) + < TYPE_PRECISION (result_type)) + && (TYPE_PRECISION (TREE_TYPE (arg1)) + == TYPE_PRECISION (TREE_TYPE (arg0))) + && unsigned0 == unsigned1 + && (unsigned0 || !uns)) + result_type + = signed_or_unsigned_type (unsigned0, + common_type (TREE_TYPE (arg0), TREE_TYPE (arg1))); + else if (TREE_CODE (arg0) == INTEGER_CST + && (unsigned1 || !uns) + && (TYPE_PRECISION (TREE_TYPE (arg1)) + < TYPE_PRECISION (result_type)) + && (type = signed_or_unsigned_type (unsigned1, + TREE_TYPE (arg1)), + int_fits_type_p (arg0, type))) + result_type = type; + else if (TREE_CODE (arg1) == INTEGER_CST + && (unsigned0 || !uns) + && (TYPE_PRECISION (TREE_TYPE (arg0)) + < TYPE_PRECISION (result_type)) + && (type = signed_or_unsigned_type (unsigned0, + TREE_TYPE (arg0)), + int_fits_type_p (arg1, type))) + result_type = type; + } + + /* Shifts can be shortened if shifting right. */ + + if (short_shift) + { + int unsigned_arg; + tree arg0 = get_narrower (op0, &unsigned_arg); + + final_type = result_type; + + if (arg0 == op0 && final_type == TREE_TYPE (op0)) + unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0)); + + if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type) + /* We can shorten only if the shift count is less than the + number of bits in the smaller type size. */ + && TREE_INT_CST_HIGH (op1) == 0 + && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1) + /* If arg is sign-extended and then unsigned-shifted, + we can simulate this with a signed shift in arg's type + only if the extended result is at least twice as wide + as the arg. Otherwise, the shift could use up all the + ones made by sign-extension and bring in zeros. + We can't optimize that case at all, but in most machines + it never happens because available widths are 2**N. */ + && (!TREE_UNSIGNED (final_type) + || unsigned_arg + || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type))) + { + /* Do an unsigned shift if the operand was zero-extended. */ + result_type + = signed_or_unsigned_type (unsigned_arg, + TREE_TYPE (arg0)); + /* Convert value-to-be-shifted to that type. */ + if (TREE_TYPE (op0) != result_type) + op0 = convert (result_type, op0); + converted = 1; + } + } + + /* Comparison operations are shortened too but differently. + They identify themselves by setting short_compare = 1. */ + + if (short_compare) + { + /* Don't write &op0, etc., because that would prevent op0 + from being kept in a register. + Instead, make copies of the our local variables and + pass the copies by reference, then copy them back afterward. */ + tree xop0 = op0, xop1 = op1, xresult_type = result_type; + enum tree_code xresultcode = resultcode; + tree val + = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); + if (val != 0) + return val; + op0 = xop0, op1 = xop1; + converted = 1; + resultcode = xresultcode; + + if (extra_warnings) + { + int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0)); + int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1)); + + int unsignedp0, unsignedp1; + tree primop0 = get_narrower (op0, &unsignedp0); + tree primop1 = get_narrower (op1, &unsignedp1); + + /* Avoid spurious warnings for comparison with enumerators. */ + + xop0 = orig_op0; + xop1 = orig_op1; + STRIP_TYPE_NOPS (xop0); + STRIP_TYPE_NOPS (xop1); + + /* Give warnings for comparisons between signed and unsigned + quantities that may fail. */ + /* Do the checking based on the original operand trees, so that + casts will be considered, but default promotions won't be. */ + + /* Do not warn if the comparison is being done in a signed type, + since the signed type will only be chosen if it can represent + all the values of the unsigned type. */ + if (! TREE_UNSIGNED (result_type)) + /* OK */; + /* Do not warn if both operands are unsigned. */ + else if (op0_signed == op1_signed) + /* OK */; + /* Do not warn if the signed quantity is an unsuffixed + integer literal (or some static constant expression + involving such literals) and it is non-negative. */ + else if ((op0_signed && TREE_CODE (xop0) == INTEGER_CST + && tree_int_cst_sgn (xop0) >= 0) + || (op1_signed && TREE_CODE (xop1) == INTEGER_CST + && tree_int_cst_sgn (xop1) >= 0)) + /* OK */; + /* Do not warn if the comparison is an equality operation, + the unsigned quantity is an integral constant and it does + not use the most significant bit of result_type. */ + else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR) + && ((op0_signed && TREE_CODE (xop1) == INTEGER_CST + && int_fits_type_p (xop1, signed_type (result_type)) + || (op1_signed && TREE_CODE (xop0) == INTEGER_CST + && int_fits_type_p (xop0, signed_type (result_type)))))) + /* OK */; + else + warning ("comparison between signed and unsigned"); + + /* Warn if two unsigned values are being compared in a size + larger than their original size, and one (and only one) is the + result of a `~' operator. This comparison will always fail. + + Also warn if one operand is a constant, and the constant + does not have all bits set that are set in the ~ operand + when it is extended. */ + + if ((TREE_CODE (primop0) == BIT_NOT_EXPR) + != (TREE_CODE (primop1) == BIT_NOT_EXPR)) + { + if (TREE_CODE (primop0) == BIT_NOT_EXPR) + primop0 = get_narrower (TREE_OPERAND (primop0, 0), + &unsignedp0); + else + primop1 = get_narrower (TREE_OPERAND (primop1, 0), + &unsignedp1); + + if (TREE_CODE (primop0) == INTEGER_CST + || TREE_CODE (primop1) == INTEGER_CST) + { + tree primop; + long constant, mask; + int unsignedp, bits; + + if (TREE_CODE (primop0) == INTEGER_CST) + { + primop = primop1; + unsignedp = unsignedp1; + constant = TREE_INT_CST_LOW (primop0); + } + else + { + primop = primop0; + unsignedp = unsignedp0; + constant = TREE_INT_CST_LOW (primop1); + } + + bits = TYPE_PRECISION (TREE_TYPE (primop)); + if (bits < TYPE_PRECISION (result_type) + && bits < HOST_BITS_PER_LONG && unsignedp) + { + mask = (~0L) << bits; + if ((mask & constant) != mask) + warning ("comparison of promoted ~unsigned with constant"); + } + } + else if (unsignedp0 && unsignedp1 + && (TYPE_PRECISION (TREE_TYPE (primop0)) + < TYPE_PRECISION (result_type)) + && (TYPE_PRECISION (TREE_TYPE (primop1)) + < TYPE_PRECISION (result_type))) + warning ("comparison of promoted ~unsigned with unsigned"); + } + } + } + } + + /* At this point, RESULT_TYPE must be nonzero to avoid an error message. + If CONVERTED is zero, both args will be converted to type RESULT_TYPE. + Then the expression will be built. + It will be given type FINAL_TYPE if that is nonzero; + otherwise, it will be given type RESULT_TYPE. */ + + if (!result_type) + { + binary_op_error (code); + return error_mark_node; + } + + if (! converted) + { + if (TREE_TYPE (op0) != result_type) + op0 = convert (result_type, op0); + if (TREE_TYPE (op1) != result_type) + op1 = convert (result_type, op1); + } + + if (build_type == NULL_TREE) + build_type = result_type; + + { + register tree result = build (resultcode, build_type, op0, op1); + register tree folded; + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1); + if (final_type != 0) + return convert (final_type, folded); + return folded; + } +} + +/* Return a tree for the sum or difference (RESULTCODE says which) + of pointer PTROP and integer INTOP. */ + +static tree +pointer_int_sum (resultcode, ptrop, intop) + enum tree_code resultcode; + register tree ptrop, intop; +{ + tree size_exp; + + register tree result; + register tree folded; + + /* The result is a pointer of the same type that is being added. */ + + register tree result_type = TREE_TYPE (ptrop); + + if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("pointer of type `void *' used in arithmetic"); + size_exp = integer_one_node; + } + else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("pointer to a function used in arithmetic"); + size_exp = integer_one_node; + } + else + size_exp = c_size_in_bytes (TREE_TYPE (result_type)); + + /* If what we are about to multiply by the size of the elements + contains a constant term, apply distributive law + and multiply that constant term separately. + This helps produce common subexpressions. */ + + if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR) + && ! TREE_CONSTANT (intop) + && TREE_CONSTANT (TREE_OPERAND (intop, 1)) + && TREE_CONSTANT (size_exp) + /* If the constant comes from pointer subtraction, + skip this optimization--it would cause an error. */ + && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE + /* If the constant is unsigned, and smaller than the pointer size, + then we must skip this optimization. This is because it could cause + an overflow error if the constant is negative but INTOP is not. */ + && (! TREE_UNSIGNED (TREE_TYPE (intop)) + || (TYPE_PRECISION (TREE_TYPE (intop)) + == TYPE_PRECISION (TREE_TYPE (ptrop))))) + { + enum tree_code subcode = resultcode; + tree int_type = TREE_TYPE (intop); + if (TREE_CODE (intop) == MINUS_EXPR) + subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR); + /* Convert both subexpression types to the type of intop, + because weird cases involving pointer arithmetic + can result in a sum or difference with different type args. */ + ptrop = build_binary_op (subcode, ptrop, + convert (int_type, TREE_OPERAND (intop, 1)), 1); + intop = convert (int_type, TREE_OPERAND (intop, 0)); + } + + /* Convert the integer argument to a type the same size as a pointer + so the multiply won't overflow spuriously. */ + + if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE) + intop = convert (type_for_size (POINTER_SIZE, 0), intop); + + /* Replace the integer argument with a suitable product by the object size. + Do this multiplication as signed, then convert to the appropriate + pointer type (actually unsigned integral). */ + + intop = convert (result_type, + build_binary_op (MULT_EXPR, intop, + convert (TREE_TYPE (intop), size_exp), 1)); + + /* Create the sum or difference. */ + + result = build (resultcode, result_type, ptrop, intop); + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop); + return folded; +} + +/* Return a tree for the difference of pointers OP0 and OP1. + The resulting tree has type int. */ + +static tree +pointer_diff (op0, op1) + register tree op0, op1; +{ + register tree result, folded; + tree restype = ptrdiff_type_node; + + tree target_type = TREE_TYPE (TREE_TYPE (op0)); + + if (pedantic || warn_pointer_arith) + { + if (TREE_CODE (target_type) == VOID_TYPE) + pedwarn ("pointer of type `void *' used in subtraction"); + if (TREE_CODE (target_type) == FUNCTION_TYPE) + pedwarn ("pointer to a function used in subtraction"); + } + + /* First do the subtraction as integers; + then drop through to build the divide operator. */ + + op0 = build_binary_op (MINUS_EXPR, convert (restype, op0), + convert (restype, op1), 1); + /* This generates an error if op1 is pointer to incomplete type. */ + if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0) + error ("arithmetic on pointer to an incomplete type"); + + /* This generates an error if op0 is pointer to incomplete type. */ + op1 = c_size_in_bytes (target_type); + + /* Divide by the size, in easiest possible way. */ + + result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1)); + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1); + return folded; +} + +/* Construct and perhaps optimize a tree representation + for a unary operation. CODE, a tree_code, specifies the operation + and XARG is the operand. NOCONVERT nonzero suppresses + the default promotions (such as from short to int). */ + +tree +build_unary_op (code, xarg, noconvert) + enum tree_code code; + tree xarg; + int noconvert; +{ + /* No default_conversion here. It causes trouble for ADDR_EXPR. */ + register tree arg = xarg; + register tree argtype = 0; + register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg)); + char *errstring = NULL; + tree val; + + if (typecode == ERROR_MARK) + return error_mark_node; + if (typecode == ENUMERAL_TYPE) + typecode = INTEGER_TYPE; + + switch (code) + { + case CONVERT_EXPR: + /* This is used for unary plus, because a CONVERT_EXPR + is enough to prevent anybody from looking inside for + associativity, but won't generate any code. */ + if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE + || typecode == COMPLEX_TYPE)) + errstring = "wrong type argument to unary plus"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case NEGATE_EXPR: + if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE + || typecode == COMPLEX_TYPE)) + errstring = "wrong type argument to unary minus"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case BIT_NOT_EXPR: + if (typecode == COMPLEX_TYPE) + { + code = CONJ_EXPR; + if (!noconvert) + arg = default_conversion (arg); + } + else if (typecode != INTEGER_TYPE) + errstring = "wrong type argument to bit-complement"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case ABS_EXPR: + if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE + || typecode == COMPLEX_TYPE)) + errstring = "wrong type argument to abs"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case CONJ_EXPR: + /* Conjugating a real value is a no-op, but allow it anyway. */ + if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE + || typecode == COMPLEX_TYPE)) + errstring = "wrong type argument to conjugation"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case TRUTH_NOT_EXPR: + if (typecode != INTEGER_TYPE + && typecode != REAL_TYPE && typecode != POINTER_TYPE + && typecode != COMPLEX_TYPE + /* These will convert to a pointer. */ + && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE) + { + errstring = "wrong type argument to unary exclamation mark"; + break; + } + arg = truthvalue_conversion (arg); + return invert_truthvalue (arg); + + case NOP_EXPR: + break; + + case REALPART_EXPR: + if (TREE_CODE (arg) == COMPLEX_CST) + return TREE_REALPART (arg); + else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) + return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg)); + else + return arg; + + case IMAGPART_EXPR: + if (TREE_CODE (arg) == COMPLEX_CST) + return TREE_IMAGPART (arg); + else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE) + return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg)); + else + return convert (TREE_TYPE (arg), integer_zero_node); + + case PREINCREMENT_EXPR: + case POSTINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case POSTDECREMENT_EXPR: + /* Handle complex lvalues (when permitted) + by reduction to simpler cases. */ + + val = unary_complex_lvalue (code, arg); + if (val != 0) + return val; + + /* Increment or decrement the real part of the value, + and don't change the imaginary part. */ + if (typecode == COMPLEX_TYPE) + { + tree real, imag; + + arg = stabilize_reference (arg); + real = build_unary_op (REALPART_EXPR, arg, 1); + imag = build_unary_op (IMAGPART_EXPR, arg, 1); + return build (COMPLEX_EXPR, TREE_TYPE (arg), + build_unary_op (code, real, 1), imag); + } + + /* Report invalid types. */ + + if (typecode != POINTER_TYPE + && typecode != INTEGER_TYPE && typecode != REAL_TYPE) + { + if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) + errstring ="wrong type argument to increment"; + else + errstring ="wrong type argument to decrement"; + break; + } + + { + register tree inc; + tree result_type = TREE_TYPE (arg); + + arg = get_unwidened (arg, 0); + argtype = TREE_TYPE (arg); + + /* Compute the increment. */ + + if (typecode == POINTER_TYPE) + { + /* If pointer target is an undefined struct, + we just cannot know how to do the arithmetic. */ + if (TYPE_SIZE (TREE_TYPE (result_type)) == 0) + error ("%s of pointer to unknown structure", + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement")); + else if ((pedantic || warn_pointer_arith) + && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)) + pedwarn ("wrong type argument to %s", + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement")); + inc = c_size_in_bytes (TREE_TYPE (result_type)); + } + else + inc = integer_one_node; + + inc = convert (argtype, inc); + + /* Handle incrementing a cast-expression. */ + + while (1) + switch (TREE_CODE (arg)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + pedantic_lvalue_warning (CONVERT_EXPR); + /* If the real type has the same machine representation + as the type it is cast to, we can make better output + by adding directly to the inside of the cast. */ + if ((TREE_CODE (TREE_TYPE (arg)) + == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0)))) + && (TYPE_MODE (TREE_TYPE (arg)) + == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0))))) + arg = TREE_OPERAND (arg, 0); + else + { + tree incremented, modify, value; + arg = stabilize_reference (arg); + if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR) + value = arg; + else + value = save_expr (arg); + incremented = build (((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? PLUS_EXPR : MINUS_EXPR), + argtype, value, inc); + TREE_SIDE_EFFECTS (incremented) = 1; + modify = build_modify_expr (arg, NOP_EXPR, incremented); + value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value); + TREE_USED (value) = 1; + return value; + } + break; + + default: + goto give_up; + } + give_up: + + /* Complain about anything else that is not a true lvalue. */ + if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"))) + return error_mark_node; + + /* Report a read-only lvalue. */ + if (TREE_READONLY (arg)) + readonly_warning (arg, + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement")); + + val = build (code, TREE_TYPE (arg), arg, inc); + TREE_SIDE_EFFECTS (val) = 1; + val = convert (result_type, val); + if (TREE_CODE (val) != code) + TREE_NO_UNUSED_WARNING (val) = 1; + return val; + } + + case ADDR_EXPR: + /* Note that this operation never does default_conversion + regardless of NOCONVERT. */ + + /* Let &* cancel out to simplify resulting code. */ + if (TREE_CODE (arg) == INDIRECT_REF) + { + /* Don't let this be an lvalue. */ + if (lvalue_p (TREE_OPERAND (arg, 0))) + return non_lvalue (TREE_OPERAND (arg, 0)); + return TREE_OPERAND (arg, 0); + } + + /* For &x[y], return x+y */ + if (TREE_CODE (arg) == ARRAY_REF) + { + if (mark_addressable (TREE_OPERAND (arg, 0)) == 0) + return error_mark_node; + return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0), + TREE_OPERAND (arg, 1), 1); + } + + /* Handle complex lvalues (when permitted) + by reduction to simpler cases. */ + val = unary_complex_lvalue (code, arg); + if (val != 0) + return val; + +#if 0 /* Turned off because inconsistent; + float f; *&(int)f = 3.4 stores in int format + whereas (int)f = 3.4 stores in float format. */ + /* Address of a cast is just a cast of the address + of the operand of the cast. */ + switch (TREE_CODE (arg)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + if (pedantic) + pedwarn ("ANSI C forbids the address of a cast expression"); + return convert (build_pointer_type (TREE_TYPE (arg)), + build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), + 0)); + } +#endif + + /* Allow the address of a constructor if all the elements + are constant. */ + if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg)) + ; + /* Anything not already handled and not a true memory reference + is an error. */ + else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'")) + return error_mark_node; + + /* Ordinary case; arg is a COMPONENT_REF or a decl. */ + argtype = TREE_TYPE (arg); + /* If the lvalue is const or volatile, + merge that into the type that the address will point to. */ + if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd' + || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r') + { + if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)) + argtype = c_build_type_variant (argtype, + TREE_READONLY (arg), + TREE_THIS_VOLATILE (arg)); + } + + argtype = build_pointer_type (argtype); + + if (mark_addressable (arg) == 0) + return error_mark_node; + + { + tree addr; + + if (TREE_CODE (arg) == COMPONENT_REF) + { + tree field = TREE_OPERAND (arg, 1); + + addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0); + + if (DECL_BIT_FIELD (field)) + { + error ("attempt to take address of bit-field structure member `%s'", + IDENTIFIER_POINTER (DECL_NAME (field))); + return error_mark_node; + } + + addr = convert (argtype, addr); + + if (! integer_zerop (DECL_FIELD_BITPOS (field))) + { + tree offset + = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field), + size_int (BITS_PER_UNIT)); + int flag = TREE_CONSTANT (addr); + addr = fold (build (PLUS_EXPR, argtype, + addr, convert (argtype, offset))); + TREE_CONSTANT (addr) = flag; + } + } + else + addr = build1 (code, argtype, arg); + + /* Address of a static or external variable or + file-scope function counts as a constant. */ + if (staticp (arg) + && ! (TREE_CODE (arg) == FUNCTION_DECL + && DECL_CONTEXT (arg) != 0)) + TREE_CONSTANT (addr) = 1; + return addr; + } + } + + if (!errstring) + { + if (argtype == 0) + argtype = TREE_TYPE (arg); + return fold (build1 (code, argtype, arg)); + } + + error (errstring); + return error_mark_node; +} + +#if 0 +/* If CONVERSIONS is a conversion expression or a nested sequence of such, + convert ARG with the same conversions in the same order + and return the result. */ + +static tree +convert_sequence (conversions, arg) + tree conversions; + tree arg; +{ + switch (TREE_CODE (conversions)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + return convert (TREE_TYPE (conversions), + convert_sequence (TREE_OPERAND (conversions, 0), + arg)); + + default: + return arg; + } +} +#endif /* 0 */ + +/* Return nonzero if REF is an lvalue valid for this language. + Lvalues can be assigned, unless their type has TYPE_READONLY. + Lvalues can have their address taken, unless they have DECL_REGISTER. */ + +int +lvalue_p (ref) + tree ref; +{ + register enum tree_code code = TREE_CODE (ref); + + switch (code) + { + case REALPART_EXPR: + case IMAGPART_EXPR: + case COMPONENT_REF: + return lvalue_p (TREE_OPERAND (ref, 0)); + + case STRING_CST: + return 1; + + case INDIRECT_REF: + case ARRAY_REF: + case VAR_DECL: + case PARM_DECL: + case RESULT_DECL: + case ERROR_MARK: + if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE + && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) + return 1; + break; + } + return 0; +} + +/* Return nonzero if REF is an lvalue valid for this language; + otherwise, print an error message and return zero. */ + +int +lvalue_or_else (ref, string) + tree ref; + char *string; +{ + int win = lvalue_p (ref); + if (! win) + error ("invalid lvalue in %s", string); + return win; +} + +/* Apply unary lvalue-demanding operator CODE to the expression ARG + for certain kinds of expressions which are not really lvalues + but which we can accept as lvalues. + + If ARG is not a kind of expression we can handle, return zero. */ + +static tree +unary_complex_lvalue (code, arg) + enum tree_code code; + tree arg; +{ + /* Handle (a, b) used as an "lvalue". */ + if (TREE_CODE (arg) == COMPOUND_EXPR) + { + tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0); + pedantic_lvalue_warning (COMPOUND_EXPR); + return build (COMPOUND_EXPR, TREE_TYPE (real_result), + TREE_OPERAND (arg, 0), real_result); + } + + /* Handle (a ? b : c) used as an "lvalue". */ + if (TREE_CODE (arg) == COND_EXPR) + { + pedantic_lvalue_warning (COND_EXPR); + return (build_conditional_expr + (TREE_OPERAND (arg, 0), + build_unary_op (code, TREE_OPERAND (arg, 1), 0), + build_unary_op (code, TREE_OPERAND (arg, 2), 0))); + } + + return 0; +} + +/* If pedantic, warn about improper lvalue. CODE is either COND_EXPR + COMPOUND_EXPR, or CONVERT_EXPR (for casts). */ + +static void +pedantic_lvalue_warning (code) + enum tree_code code; +{ + if (pedantic) + pedwarn ("ANSI C forbids use of %s expressions as lvalues", + code == COND_EXPR ? "conditional" + : code == COMPOUND_EXPR ? "compound" : "cast"); +} + +/* Warn about storing in something that is `const'. */ + +void +readonly_warning (arg, string) + tree arg; + char *string; +{ + char buf[80]; + strcpy (buf, string); + + /* Forbid assignments to iterators. */ + if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg)) + { + strcat (buf, " of iterator `%s'"); + pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg))); + } + + if (TREE_CODE (arg) == COMPONENT_REF) + { + if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0)))) + readonly_warning (TREE_OPERAND (arg, 0), string); + else + { + strcat (buf, " of read-only member `%s'"); + pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1)))); + } + } + else if (TREE_CODE (arg) == VAR_DECL) + { + strcat (buf, " of read-only variable `%s'"); + pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg))); + } + else + { + pedwarn ("%s of read-only location", buf); + } +} + +/* Mark EXP saying that we need to be able to take the + address of it; it should not be allocated in a register. + Value is 1 if successful. */ + +int +mark_addressable (exp) + tree exp; +{ + register tree x = exp; + while (1) + switch (TREE_CODE (x)) + { + case ADDR_EXPR: + case COMPONENT_REF: + case ARRAY_REF: + case REALPART_EXPR: + case IMAGPART_EXPR: + x = TREE_OPERAND (x, 0); + break; + + case CONSTRUCTOR: + TREE_ADDRESSABLE (x) = 1; + return 1; + + case VAR_DECL: + case CONST_DECL: + case PARM_DECL: + case RESULT_DECL: + if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x) + && DECL_NONLOCAL (x)) + { + if (TREE_PUBLIC (x)) + { + error ("global register variable `%s' used in nested function", + IDENTIFIER_POINTER (DECL_NAME (x))); + return 0; + } + pedwarn ("register variable `%s' used in nested function", + IDENTIFIER_POINTER (DECL_NAME (x))); + } + else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)) + { + if (TREE_PUBLIC (x)) + { + error ("address of global register variable `%s' requested", + IDENTIFIER_POINTER (DECL_NAME (x))); + return 0; + } + + /* If we are making this addressable due to its having + volatile components, give a different error message. Also + handle the case of an unnamed parameter by not trying + to give the name. */ + + else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x))) + { + error ("cannot put object with volatile field into register"); + return 0; + } + + pedwarn ("address of register variable `%s' requested", + IDENTIFIER_POINTER (DECL_NAME (x))); + } + put_var_into_stack (x); + + /* drops in */ + case FUNCTION_DECL: + TREE_ADDRESSABLE (x) = 1; +#if 0 /* poplevel deals with this now. */ + if (DECL_CONTEXT (x) == 0) + TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1; +#endif + + default: + return 1; + } +} + +/* Build and return a conditional expression IFEXP ? OP1 : OP2. */ + +tree +build_conditional_expr (ifexp, op1, op2) + tree ifexp, op1, op2; +{ + register tree type1; + register tree type2; + register enum tree_code code1; + register enum tree_code code2; + register tree result_type = NULL; + tree orig_op1 = op1, orig_op2 = op2; + + /* If second operand is omitted, it is the same as the first one; + make sure it is calculated only once. */ + if (op1 == 0) + { + if (pedantic) + pedwarn ("ANSI C forbids omitting the middle term of a ?: expression"); + ifexp = op1 = save_expr (ifexp); + } + + ifexp = truthvalue_conversion (default_conversion (ifexp)); + +#if 0 /* Produces wrong result if within sizeof. */ + /* Don't promote the operands separately if they promote + the same way. Return the unpromoted type and let the combined + value get promoted if necessary. */ + + if (TREE_TYPE (op1) == TREE_TYPE (op2) + && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE + && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE + && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE) + { + if (TREE_CODE (ifexp) == INTEGER_CST) + return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1); + + return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2)); + } +#endif + + /* Promote both alternatives. */ + + if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE) + op1 = default_conversion (op1); + if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE) + op2 = default_conversion (op2); + + if (TREE_CODE (ifexp) == ERROR_MARK + || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK + || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK) + return error_mark_node; + + type1 = TREE_TYPE (op1); + code1 = TREE_CODE (type1); + type2 = TREE_TYPE (op2); + code2 = TREE_CODE (type2); + + /* Quickly detect the usual case where op1 and op2 have the same type + after promotion. */ + if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)) + { + if (type1 == type2) + result_type = type1; + else + result_type = TYPE_MAIN_VARIANT (type1); + } + else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE) + && (code2 == INTEGER_TYPE || code2 == REAL_TYPE)) + { + result_type = common_type (type1, type2); + } + else if (code1 == VOID_TYPE || code2 == VOID_TYPE) + { + if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE)) + pedwarn ("ANSI C forbids conditional expr with only one void side"); + result_type = void_type_node; + } + else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) + { + if (comp_target_types (type1, type2)) + result_type = common_type (type1, type2); + else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node + && TREE_CODE (orig_op1) != NOP_EXPR) + result_type = qualify_type (type2, type1); + else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node + && TREE_CODE (orig_op2) != NOP_EXPR) + result_type = qualify_type (type1, type2); + else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node) + { + if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer"); + result_type = qualify_type (type1, type2); + } + else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node) + { + if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer"); + result_type = qualify_type (type2, type1); + } + else + { + pedwarn ("pointer type mismatch in conditional expression"); + result_type = build_pointer_type (void_type_node); + } + } + else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) + { + if (! integer_zerop (op2)) + pedwarn ("pointer/integer type mismatch in conditional expression"); + else + { + op2 = null_pointer_node; +#if 0 /* The spec seems to say this is permitted. */ + if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids conditional expr between 0 and function pointer"); +#endif + } + result_type = type1; + } + else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + if (!integer_zerop (op1)) + pedwarn ("pointer/integer type mismatch in conditional expression"); + else + { + op1 = null_pointer_node; +#if 0 /* The spec seems to say this is permitted. */ + if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE) + pedwarn ("ANSI C forbids conditional expr between 0 and function pointer"); +#endif + } + result_type = type2; + } + + if (!result_type) + { + if (flag_cond_mismatch) + result_type = void_type_node; + else + { + error ("type mismatch in conditional expression"); + return error_mark_node; + } + } + + /* Merge const and volatile flags of the incoming types. */ + result_type + = build_type_variant (result_type, + TREE_READONLY (op1) || TREE_READONLY (op2), + TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2)); + + if (result_type != TREE_TYPE (op1)) + op1 = convert_and_check (result_type, op1); + if (result_type != TREE_TYPE (op2)) + op2 = convert_and_check (result_type, op2); + +#if 0 + if (code1 == RECORD_TYPE || code1 == UNION_TYPE) + { + result_type = TREE_TYPE (op1); + if (TREE_CONSTANT (ifexp)) + return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1); + + if (TYPE_MODE (result_type) == BLKmode) + { + register tree tempvar + = build_decl (VAR_DECL, NULL_TREE, result_type); + register tree xop1 = build_modify_expr (tempvar, op1); + register tree xop2 = build_modify_expr (tempvar, op2); + register tree result = fold (build (COND_EXPR, result_type, + ifexp, xop1, xop2)); + + layout_decl (tempvar, TYPE_ALIGN (result_type)); + /* No way to handle variable-sized objects here. + I fear that the entire handling of BLKmode conditional exprs + needs to be redone. */ + if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST) + abort (); + DECL_RTL (tempvar) + = assign_stack_local (DECL_MODE (tempvar), + (TREE_INT_CST_LOW (DECL_SIZE (tempvar)) + + BITS_PER_UNIT - 1) + / BITS_PER_UNIT, + 0); + + TREE_SIDE_EFFECTS (result) + = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1) + | TREE_SIDE_EFFECTS (op2); + return build (COMPOUND_EXPR, result_type, result, tempvar); + } + } +#endif /* 0 */ + + if (TREE_CODE (ifexp) == INTEGER_CST) + return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1); + + return fold (build (COND_EXPR, result_type, ifexp, op1, op2)); +} + +/* Given a list of expressions, return a compound expression + that performs them all and returns the value of the last of them. */ + +tree +build_compound_expr (list) + tree list; +{ + return internal_build_compound_expr (list, TRUE); +} + +static tree +internal_build_compound_expr (list, first_p) + tree list; + int first_p; +{ + register tree rest; + + if (TREE_CHAIN (list) == 0) + { +#if 0 /* If something inside inhibited lvalueness, we should not override. */ + /* Consider (x, y+0), which is not an lvalue since y+0 is not. */ + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + if (TREE_CODE (list) == NON_LVALUE_EXPR) + list = TREE_OPERAND (list, 0); +#endif + + /* Don't let (0, 0) be null pointer constant. */ + if (!first_p && integer_zerop (TREE_VALUE (list))) + return non_lvalue (TREE_VALUE (list)); + return TREE_VALUE (list); + } + + if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0) + { + /* Convert arrays to pointers when there really is a comma operator. */ + if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE) + TREE_VALUE (TREE_CHAIN (list)) + = default_conversion (TREE_VALUE (TREE_CHAIN (list))); + } + + rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE); + + if (! TREE_SIDE_EFFECTS (TREE_VALUE (list))) + { + /* The left-hand operand of a comma expression is like an expression + statement: with -W or -Wunused, we should warn if it doesn't have + any side-effects, unless it was explicitly cast to (void). */ + if ((extra_warnings || warn_unused) + && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR + && TREE_TYPE (TREE_VALUE (list)) == void_type_node)) + warning ("left-hand operand of comma expression has no effect"); + + /* When pedantic, a compound expression can be neither an lvalue + nor an integer constant expression. */ + if (! pedantic) + return rest; + } + + /* With -Wunused, we should also warn if the left-hand operand does have + side-effects, but computes a value which is not used. For example, in + `foo() + bar(), baz()' the result of the `+' operator is not used, + so we should issue a warning. */ + else if (warn_unused) + warn_if_unused_value (TREE_VALUE (list)); + + return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest); +} + +/* Build an expression representing a cast to type TYPE of expression EXPR. */ + +tree +build_c_cast (type, expr) + register tree type; + tree expr; +{ + register tree value = expr; + + if (type == error_mark_node || expr == error_mark_node) + return error_mark_node; + type = TYPE_MAIN_VARIANT (type); + +#if 0 + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + if (TREE_CODE (value) == NON_LVALUE_EXPR) + value = TREE_OPERAND (value, 0); +#endif + + if (TREE_CODE (type) == ARRAY_TYPE) + { + error ("cast specifies array type"); + return error_mark_node; + } + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("cast specifies function type"); + return error_mark_node; + } + + if (type == TREE_TYPE (value)) + { + if (pedantic) + { + if (TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE) + pedwarn ("ANSI C forbids casting nonscalar to the same type"); + } + } + else if (TREE_CODE (type) == UNION_TYPE) + { + tree field; + if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE) + value = default_conversion (value); + + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)), + TYPE_MAIN_VARIANT (TREE_TYPE (value)))) + break; + + if (field) + { + char *name; + tree t; + + if (pedantic) + pedwarn ("ANSI C forbids casts to union type"); + if (TYPE_NAME (type) != 0) + { + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + name = IDENTIFIER_POINTER (TYPE_NAME (type)); + else + name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + } + else + name = ""; + t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE, + build_tree_list (field, value)), + 0, 0); + TREE_CONSTANT (t) = TREE_CONSTANT (value); + return t; + } + error ("cast to union type from type not present in union"); + return error_mark_node; + } + else + { + tree otype, ovalue; + + /* If casting to void, avoid the error that would come + from default_conversion in the case of a non-lvalue array. */ + if (type == void_type_node) + return build1 (CONVERT_EXPR, type, value); + + /* Convert functions and arrays to pointers, + but don't convert any other types. */ + if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE) + value = default_conversion (value); + otype = TREE_TYPE (value); + + /* Optionally warn about potentially worrisome casts. */ + + if (warn_cast_qual + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == POINTER_TYPE) + { + if (TYPE_VOLATILE (TREE_TYPE (otype)) + && ! TYPE_VOLATILE (TREE_TYPE (type))) + pedwarn ("cast discards `volatile' from pointer target type"); + if (TYPE_READONLY (TREE_TYPE (otype)) + && ! TYPE_READONLY (TREE_TYPE (type))) + pedwarn ("cast discards `const' from pointer target type"); + } + + /* Warn about possible alignment problems. */ + if (STRICT_ALIGNMENT && warn_cast_align + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE + && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE + && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) + warning ("cast increases required alignment of target type"); + + if (TREE_CODE (type) == INTEGER_TYPE + && TREE_CODE (otype) == POINTER_TYPE + && TYPE_PRECISION (type) != TYPE_PRECISION (otype) + && !TREE_CONSTANT (value)) + warning ("cast from pointer to integer of different size"); + + if (warn_bad_function_cast + && TREE_CODE (value) == CALL_EXPR + && TREE_CODE (type) != TREE_CODE (otype)) + warning ("cast does not match function type"); + + if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == INTEGER_TYPE + && TYPE_PRECISION (type) != TYPE_PRECISION (otype) +#if 0 + /* Don't warn about converting 0 to pointer, + provided the 0 was explicit--not cast or made by folding. */ + && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)) +#endif + /* Don't warn about converting any constant. */ + && !TREE_CONSTANT (value)) + warning ("cast to pointer from integer of different size"); + + ovalue = value; + value = convert (type, value); + + /* Ignore any integer overflow caused by the cast. */ + if (TREE_CODE (value) == INTEGER_CST) + { + TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue); + TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue); + } + } + + /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant. */ + if (pedantic && TREE_CODE (value) == INTEGER_CST + && TREE_CODE (expr) == INTEGER_CST + && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE) + value = non_lvalue (value); + + /* If pedantic, don't let a cast be an lvalue. */ + if (value == expr && pedantic) + value = non_lvalue (value); + + return value; +} + +/* Build an assignment expression of lvalue LHS from value RHS. + MODIFYCODE is the code for a binary operator that we use + to combine the old value of LHS with RHS to get the new value. + Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. */ + +tree +build_modify_expr (lhs, modifycode, rhs) + tree lhs, rhs; + enum tree_code modifycode; +{ + register tree result; + tree newrhs; + tree lhstype = TREE_TYPE (lhs); + tree olhstype = lhstype; + + /* Types that aren't fully specified cannot be used in assignments. */ + lhs = require_complete_type (lhs); + + /* Avoid duplicate error messages from operands that had errors. */ + if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) + return error_mark_node; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + /* Do not use STRIP_NOPS here. We do not want an enumerator + whose value is 0 to count as a null pointer constant. */ + if (TREE_CODE (rhs) == NON_LVALUE_EXPR) + rhs = TREE_OPERAND (rhs, 0); + + newrhs = rhs; + + /* Handle control structure constructs used as "lvalues". */ + + switch (TREE_CODE (lhs)) + { + /* Handle (a, b) used as an "lvalue". */ + case COMPOUND_EXPR: + pedantic_lvalue_warning (COMPOUND_EXPR); + newrhs = build_modify_expr (TREE_OPERAND (lhs, 1), + modifycode, rhs); + if (TREE_CODE (newrhs) == ERROR_MARK) + return error_mark_node; + return build (COMPOUND_EXPR, lhstype, + TREE_OPERAND (lhs, 0), newrhs); + + /* Handle (a ? b : c) used as an "lvalue". */ + case COND_EXPR: + pedantic_lvalue_warning (COND_EXPR); + rhs = save_expr (rhs); + { + /* Produce (a ? (b = rhs) : (c = rhs)) + except that the RHS goes through a save-expr + so the code to compute it is only emitted once. */ + tree cond + = build_conditional_expr (TREE_OPERAND (lhs, 0), + build_modify_expr (TREE_OPERAND (lhs, 1), + modifycode, rhs), + build_modify_expr (TREE_OPERAND (lhs, 2), + modifycode, rhs)); + if (TREE_CODE (cond) == ERROR_MARK) + return cond; + /* Make sure the code to compute the rhs comes out + before the split. */ + return build (COMPOUND_EXPR, TREE_TYPE (lhs), + /* But cast it to void to avoid an "unused" error. */ + convert (void_type_node, rhs), cond); + } + } + + /* If a binary op has been requested, combine the old LHS value with the RHS + producing the value we should actually store into the LHS. */ + + if (modifycode != NOP_EXPR) + { + lhs = stabilize_reference (lhs); + newrhs = build_binary_op (modifycode, lhs, rhs, 1); + } + + /* Handle a cast used as an "lvalue". + We have already performed any binary operator using the value as cast. + Now convert the result to the cast type of the lhs, + and then true type of the lhs and store it there; + then convert result back to the cast type to be the value + of the assignment. */ + + switch (TREE_CODE (lhs)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE) + newrhs = default_conversion (newrhs); + { + tree inner_lhs = TREE_OPERAND (lhs, 0); + tree result; + result = build_modify_expr (inner_lhs, NOP_EXPR, + convert (TREE_TYPE (inner_lhs), + convert (lhstype, newrhs))); + if (TREE_CODE (result) == ERROR_MARK) + return result; + pedantic_lvalue_warning (CONVERT_EXPR); + return convert (TREE_TYPE (lhs), result); + } + } + + /* Now we have handled acceptable kinds of LHS that are not truly lvalues. + Reject anything strange now. */ + + if (!lvalue_or_else (lhs, "assignment")) + return error_mark_node; + + /* Warn about storing in something that is `const'. */ + + if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype) + || ((TREE_CODE (lhstype) == RECORD_TYPE + || TREE_CODE (lhstype) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (lhstype))) + readonly_warning (lhs, "assignment"); + + /* If storing into a structure or union member, + it has probably been given type `int'. + Compute the type that would go with + the actual amount of storage the member occupies. */ + + if (TREE_CODE (lhs) == COMPONENT_REF + && (TREE_CODE (lhstype) == INTEGER_TYPE + || TREE_CODE (lhstype) == REAL_TYPE + || TREE_CODE (lhstype) == ENUMERAL_TYPE)) + lhstype = TREE_TYPE (get_unwidened (lhs, 0)); + + /* If storing in a field that is in actuality a short or narrower than one, + we must store in the field in its actual type. */ + + if (lhstype != TREE_TYPE (lhs)) + { + lhs = copy_node (lhs); + TREE_TYPE (lhs) = lhstype; + } + + /* Convert new value to destination type. */ + + newrhs = convert_for_assignment (lhstype, newrhs, "assignment", + NULL_TREE, NULL_TREE, 0); + if (TREE_CODE (newrhs) == ERROR_MARK) + return error_mark_node; + + result = build (MODIFY_EXPR, lhstype, lhs, newrhs); + TREE_SIDE_EFFECTS (result) = 1; + + /* If we got the LHS in a different type for storing in, + convert the result back to the nominal type of LHS + so that the value we return always has the same type + as the LHS argument. */ + + if (olhstype == TREE_TYPE (result)) + return result; + return convert_for_assignment (olhstype, result, "assignment", + NULL_TREE, NULL_TREE, 0); +} + +/* Convert value RHS to type TYPE as preparation for an assignment + to an lvalue of type TYPE. + The real work of conversion is done by `convert'. + The purpose of this function is to generate error messages + for assignments that are not allowed in C. + ERRTYPE is a string to use in error messages: + "assignment", "return", etc. If it is null, this is parameter passing + for a function call (and different error messages are output). Otherwise, + it may be a name stored in the spelling stack and interpreted by + get_spelling. + + FUNNAME is the name of the function being called, + as an IDENTIFIER_NODE, or null. + PARMNUM is the number of the argument, for printing in error messages. */ + +static tree +convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum) + tree type, rhs; + char *errtype; + tree fundecl, funname; + int parmnum; +{ + register enum tree_code codel = TREE_CODE (type); + register tree rhstype; + register enum tree_code coder; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + /* Do not use STRIP_NOPS here. We do not want an enumerator + whose value is 0 to count as a null pointer constant. */ + if (TREE_CODE (rhs) == NON_LVALUE_EXPR) + rhs = TREE_OPERAND (rhs, 0); + + if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE) + rhs = default_conversion (rhs); + else if (optimize && TREE_CODE (rhs) == VAR_DECL) + rhs = decl_constant_value (rhs); + + rhstype = TREE_TYPE (rhs); + coder = TREE_CODE (rhstype); + + if (coder == ERROR_MARK) + return error_mark_node; + + if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) + { + overflow_warning (rhs); + /* Check for Objective-C protocols. This will issue a warning if + there are protocol violations. No need to use the return value. */ + maybe_objc_comptypes (type, rhstype, 0); + return rhs; + } + + if (coder == VOID_TYPE) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + /* Arithmetic types all interconvert, and enum is treated like int. */ + if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE + || codel == COMPLEX_TYPE) + && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE + || coder == COMPLEX_TYPE)) + return convert_and_check (type, rhs); + + /* Conversion to a union from its member types. */ + else if (codel == UNION_TYPE) + { + tree memb_types; + + for (memb_types = TYPE_FIELDS (type); memb_types; + memb_types = TREE_CHAIN (memb_types)) + { + if (comptypes (TREE_TYPE (memb_types), TREE_TYPE (rhs))) + { + if (pedantic + && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl))) + pedwarn ("ANSI C prohibits argument conversion to union type"); + return build1 (NOP_EXPR, type, rhs); + } + + else if (coder == POINTER_TYPE + && TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE) + { + tree memb_type = TREE_TYPE (memb_types); + register tree ttl = TREE_TYPE (memb_type); + register tree ttr = TREE_TYPE (rhstype); + + /* Any non-function converts to a [const][volatile] void * + and vice versa; otherwise, targets must be the same. + Meanwhile, the lhs target must have all the qualifiers of + the rhs. */ + if (TYPE_MAIN_VARIANT (ttl) == void_type_node + || TYPE_MAIN_VARIANT (ttr) == void_type_node + || comp_target_types (memb_type, rhstype)) + { + /* Const and volatile mean something different for function + types, so the usual warnings are not appropriate. */ + if (TREE_CODE (ttr) != FUNCTION_TYPE + || TREE_CODE (ttl) != FUNCTION_TYPE) + { + if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + warn_for_assignment ("%s discards `const' from pointer target type", + get_spelling (errtype), funname, + parmnum); + if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + warn_for_assignment ("%s discards `volatile' from pointer target type", + get_spelling (errtype), funname, + parmnum); + } + else + { + /* Because const and volatile on functions are + restrictions that say the function will not do + certain things, it is okay to use a const or volatile + function where an ordinary one is wanted, but not + vice-versa. */ + if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr)) + warn_for_assignment ("%s makes `const *' function pointer from non-const", + get_spelling (errtype), funname, + parmnum); + if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr)) + warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile", + get_spelling (errtype), funname, + parmnum); + } + + if (pedantic + && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl))) + pedwarn ("ANSI C prohibits argument conversion to union type"); + return build1 (NOP_EXPR, type, rhs); + } + } + + /* Can convert integer zero to any pointer type. */ + else if (TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE + && (integer_zerop (rhs) + || (TREE_CODE (rhs) == NOP_EXPR + && integer_zerop (TREE_OPERAND (rhs, 0))))) + return build1 (NOP_EXPR, type, null_pointer_node); + } + } + + /* Conversions among pointers */ + else if (codel == POINTER_TYPE && coder == POINTER_TYPE) + { + register tree ttl = TREE_TYPE (type); + register tree ttr = TREE_TYPE (rhstype); + + /* Any non-function converts to a [const][volatile] void * + and vice versa; otherwise, targets must be the same. + Meanwhile, the lhs target must have all the qualifiers of the rhs. */ + if (TYPE_MAIN_VARIANT (ttl) == void_type_node + || TYPE_MAIN_VARIANT (ttr) == void_type_node + || comp_target_types (type, rhstype) + || (unsigned_type (TYPE_MAIN_VARIANT (ttl)) + == unsigned_type (TYPE_MAIN_VARIANT (ttr)))) + { + if (pedantic + && ((TYPE_MAIN_VARIANT (ttl) == void_type_node + && TREE_CODE (ttr) == FUNCTION_TYPE) + || + (TYPE_MAIN_VARIANT (ttr) == void_type_node + /* Check TREE_CODE to catch cases like (void *) (char *) 0 + which are not ANSI null ptr constants. */ + && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR) + && TREE_CODE (ttl) == FUNCTION_TYPE))) + warn_for_assignment ("ANSI forbids %s between function pointer and `void *'", + get_spelling (errtype), funname, parmnum); + /* Const and volatile mean something different for function types, + so the usual warnings are not appropriate. */ + else if (TREE_CODE (ttr) != FUNCTION_TYPE + && TREE_CODE (ttl) != FUNCTION_TYPE) + { + if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + warn_for_assignment ("%s discards `const' from pointer target type", + get_spelling (errtype), funname, parmnum); + else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + warn_for_assignment ("%s discards `volatile' from pointer target type", + get_spelling (errtype), funname, parmnum); + /* If this is not a case of ignoring a mismatch in signedness, + no warning. */ + else if (TYPE_MAIN_VARIANT (ttl) == void_type_node + || TYPE_MAIN_VARIANT (ttr) == void_type_node + || comp_target_types (type, rhstype)) + ; + /* If there is a mismatch, do warn. */ + else if (pedantic) + warn_for_assignment ("pointer targets in %s differ in signedness", + get_spelling (errtype), funname, parmnum); + } + else if (TREE_CODE (ttl) == FUNCTION_TYPE + && TREE_CODE (ttr) == FUNCTION_TYPE) + { + /* Because const and volatile on functions are restrictions + that say the function will not do certain things, + it is okay to use a const or volatile function + where an ordinary one is wanted, but not vice-versa. */ + if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr)) + warn_for_assignment ("%s makes `const *' function pointer from non-const", + get_spelling (errtype), funname, parmnum); + if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr)) + warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile", + get_spelling (errtype), funname, parmnum); + } + } + else + warn_for_assignment ("%s from incompatible pointer type", + get_spelling (errtype), funname, parmnum); + return convert (type, rhs); + } + else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) + { + /* An explicit constant 0 can convert to a pointer, + or one that results from arithmetic, even including + a cast to integer type. */ + if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)) + && + ! (TREE_CODE (rhs) == NOP_EXPR + && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE + && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST + && integer_zerop (TREE_OPERAND (rhs, 0)))) + { + warn_for_assignment ("%s makes pointer from integer without a cast", + get_spelling (errtype), funname, parmnum); + return convert (type, rhs); + } + return null_pointer_node; + } + else if (codel == INTEGER_TYPE && coder == POINTER_TYPE) + { + warn_for_assignment ("%s makes integer from pointer without a cast", + get_spelling (errtype), funname, parmnum); + return convert (type, rhs); + } + + if (!errtype) + { + if (funname) + { + tree selector = maybe_building_objc_message_expr (); + + if (selector && parmnum > 2) + error ("incompatible type for argument %d of `%s'", + parmnum - 2, IDENTIFIER_POINTER (selector)); + else + error ("incompatible type for argument %d of `%s'", + parmnum, IDENTIFIER_POINTER (funname)); + } + else + error ("incompatible type for argument %d of indirect function call", + parmnum); + } + else + error ("incompatible types in %s", get_spelling (errtype)); + + return error_mark_node; +} + +/* Print a warning using MSG. + It gets OPNAME as its one parameter. + If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'". + FUNCTION and ARGNUM are handled specially if we are building an + Objective-C selector. */ + +static void +warn_for_assignment (msg, opname, function, argnum) + char *msg; + char *opname; + tree function; + int argnum; +{ + static char argstring[] = "passing arg %d of `%s'"; + static char argnofun[] = "passing arg %d"; + + if (opname == 0) + { + tree selector = maybe_building_objc_message_expr (); + + if (selector && argnum > 2) + { + function = selector; + argnum -= 2; + } + if (function) + { + /* Function name is known; supply it. */ + opname = (char *) alloca (IDENTIFIER_LENGTH (function) + + sizeof (argstring) + 25 /*%d*/ + 1); + sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function)); + } + else + { + /* Function name unknown (call through ptr); just give arg number. */ + opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1); + sprintf (opname, argnofun, argnum); + } + } + pedwarn (msg, opname); +} + +/* Return nonzero if VALUE is a valid constant-valued expression + for use in initializing a static variable; one that can be an + element of a "constant" initializer. + + Return null_pointer_node if the value is absolute; + if it is relocatable, return the variable that determines the relocation. + We assume that VALUE has been folded as much as possible; + therefore, we do not need to check for such things as + arithmetic-combinations of integers. */ + +tree +initializer_constant_valid_p (value, endtype) + tree value; + tree endtype; +{ + switch (TREE_CODE (value)) + { + case CONSTRUCTOR: + if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) + && TREE_CONSTANT (value)) + return + initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)), + endtype); + + return TREE_STATIC (value) ? null_pointer_node : 0; + + case INTEGER_CST: + case REAL_CST: + case STRING_CST: + case COMPLEX_CST: + return null_pointer_node; + + case ADDR_EXPR: + return TREE_OPERAND (value, 0); + + case NON_LVALUE_EXPR: + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + case CONVERT_EXPR: + case NOP_EXPR: + /* Allow conversions between pointer types. */ + if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow conversions between real types. */ + if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow length-preserving conversions between integer types. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow conversions between other integer types only if + explicit value. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE) + { + tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + if (inner == null_pointer_node) + return null_pointer_node; + return 0; + } + + /* Allow (int) &foo provided int is as wide as a pointer. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + + /* Likewise conversions from int to pointers. */ + if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + + /* Allow conversions to union types if the value inside is okay. */ + if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + return 0; + + case PLUS_EXPR: + if (TREE_CODE (endtype) == INTEGER_TYPE + && TYPE_PRECISION (endtype) < POINTER_SIZE) + return 0; + { + tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), + endtype); + /* If either term is absolute, use the other terms relocation. */ + if (valid0 == null_pointer_node) + return valid1; + if (valid1 == null_pointer_node) + return valid0; + return 0; + } + + case MINUS_EXPR: + if (TREE_CODE (endtype) == INTEGER_TYPE + && TYPE_PRECISION (endtype) < POINTER_SIZE) + return 0; + { + tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), + endtype); + /* Win if second argument is absolute. */ + if (valid1 == null_pointer_node) + return valid0; + /* Win if both arguments have the same relocation. + Then the value is absolute. */ + if (valid0 == valid1) + return null_pointer_node; + return 0; + } + } + + return 0; +} + +/* If VALUE is a compound expr all of whose expressions are constant, then + return its value. Otherwise, return error_mark_node. + + This is for handling COMPOUND_EXPRs as initializer elements + which is allowed with a warning when -pedantic is specified. */ + +static tree +valid_compound_expr_initializer (value, endtype) + tree value; + tree endtype; +{ + if (TREE_CODE (value) == COMPOUND_EXPR) + { + if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype) + == error_mark_node) + return error_mark_node; + return valid_compound_expr_initializer (TREE_OPERAND (value, 1), + endtype); + } + else if (! TREE_CONSTANT (value) + && ! initializer_constant_valid_p (value, endtype)) + return error_mark_node; + else + return value; +} + +/* Perform appropriate conversions on the initial value of a variable, + store it in the declaration DECL, + and print any error messages that are appropriate. + If the init is invalid, store an ERROR_MARK. */ + +void +store_init_value (decl, init) + tree decl, init; +{ + register tree value, type; + + /* If variable's type was invalidly declared, just ignore it. */ + + type = TREE_TYPE (decl); + if (TREE_CODE (type) == ERROR_MARK) + return; + + /* Digest the specified initializer into an expression. */ + + value = digest_init (type, init, TREE_STATIC (decl), + TREE_STATIC (decl) || pedantic); + + /* Store the expression if valid; else report error. */ + +#if 0 + /* Note that this is the only place we can detect the error + in a case such as struct foo bar = (struct foo) { x, y }; + where there is one initial value which is a constructor expression. */ + if (value == error_mark_node) + ; + else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value)) + { + error ("initializer for static variable is not constant"); + value = error_mark_node; + } + else if (TREE_STATIC (decl) + && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0) + { + error ("initializer for static variable uses complicated arithmetic"); + value = error_mark_node; + } + else + { + if (pedantic && TREE_CODE (value) == CONSTRUCTOR) + { + if (! TREE_CONSTANT (value)) + pedwarn ("aggregate initializer is not constant"); + else if (! TREE_STATIC (value)) + pedwarn ("aggregate initializer uses complicated arithmetic"); + } + } +#endif + + DECL_INITIAL (decl) = value; + + /* ANSI wants warnings about out-of-range constant initializers. */ + STRIP_TYPE_NOPS (value); + constant_expression_warning (value); +} + +/* Methods for storing and printing names for error messages. */ + +/* Implement a spelling stack that allows components of a name to be pushed + and popped. Each element on the stack is this structure. */ + +struct spelling +{ + int kind; + union + { + int i; + char *s; + } u; +}; + +#define SPELLING_STRING 1 +#define SPELLING_MEMBER 2 +#define SPELLING_BOUNDS 3 + +static struct spelling *spelling; /* Next stack element (unused). */ +static struct spelling *spelling_base; /* Spelling stack base. */ +static int spelling_size; /* Size of the spelling stack. */ + +/* Macros to save and restore the spelling stack around push_... functions. + Alternative to SAVE_SPELLING_STACK. */ + +#define SPELLING_DEPTH() (spelling - spelling_base) +#define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth) + +/* Save and restore the spelling stack around arbitrary C code. */ + +#define SAVE_SPELLING_DEPTH(code) \ +{ \ + int __depth = SPELLING_DEPTH (); \ + code; \ + RESTORE_SPELLING_DEPTH (__depth); \ +} + +/* Push an element on the spelling stack with type KIND and assign VALUE + to MEMBER. */ + +#define PUSH_SPELLING(KIND, VALUE, MEMBER) \ +{ \ + int depth = SPELLING_DEPTH (); \ + \ + if (depth >= spelling_size) \ + { \ + spelling_size += 10; \ + if (spelling_base == 0) \ + spelling_base \ + = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling)); \ + else \ + spelling_base \ + = (struct spelling *) xrealloc (spelling_base, \ + spelling_size * sizeof (struct spelling)); \ + RESTORE_SPELLING_DEPTH (depth); \ + } \ + \ + spelling->kind = (KIND); \ + spelling->MEMBER = (VALUE); \ + spelling++; \ +} + +/* Push STRING on the stack. Printed literally. */ + +static void +push_string (string) + char *string; +{ + PUSH_SPELLING (SPELLING_STRING, string, u.s); +} + +/* Push a member name on the stack. Printed as '.' STRING. */ + +static void +push_member_name (decl) + tree decl; + +{ + char *string + = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : ""; + PUSH_SPELLING (SPELLING_MEMBER, string, u.s); +} + +/* Push an array bounds on the stack. Printed as [BOUNDS]. */ + +static void +push_array_bounds (bounds) + int bounds; +{ + PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i); +} + +/* Compute the maximum size in bytes of the printed spelling. */ + +static int +spelling_length () +{ + register int size = 0; + register struct spelling *p; + + for (p = spelling_base; p < spelling; p++) + { + if (p->kind == SPELLING_BOUNDS) + size += 25; + else + size += strlen (p->u.s) + 1; + } + + return size; +} + +/* Print the spelling to BUFFER and return it. */ + +static char * +print_spelling (buffer) + register char *buffer; +{ + register char *d = buffer; + register char *s; + register struct spelling *p; + + for (p = spelling_base; p < spelling; p++) + if (p->kind == SPELLING_BOUNDS) + { + sprintf (d, "[%d]", p->u.i); + d += strlen (d); + } + else + { + if (p->kind == SPELLING_MEMBER) + *d++ = '.'; + for (s = p->u.s; *d = *s++; d++) + ; + } + *d++ = '\0'; + return buffer; +} + +/* Provide a means to pass component names derived from the spelling stack. */ + +char initialization_message; + +/* Interpret the spelling of the given ERRTYPE message. */ + +static char * +get_spelling (errtype) + char *errtype; +{ + static char *buffer; + static int size = -1; + + if (errtype == &initialization_message) + { + /* Avoid counting chars */ + static char message[] = "initialization of `%s'"; + register int needed = sizeof (message) + spelling_length () + 1; + char *temp; + + if (size < 0) + buffer = (char *) xmalloc (size = needed); + if (needed > size) + buffer = (char *) xrealloc (buffer, size = needed); + + temp = (char *) alloca (needed); + sprintf (buffer, message, print_spelling (temp)); + return buffer; + } + + return errtype; +} + +/* Issue an error message for a bad initializer component. + FORMAT describes the message. OFWHAT is the name for the component. + LOCAL is a format string for formatting the insertion of the name + into the message. + + If OFWHAT is null, the component name is stored on the spelling stack. + If the component name is a null string, then LOCAL is omitted entirely. */ + +void +error_init (format, local, ofwhat) + char *format, *local, *ofwhat; +{ + char *buffer; + + if (ofwhat == 0) + ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); + buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2); + + if (*ofwhat) + sprintf (buffer, local, ofwhat); + else + buffer[0] = 0; + + error (format, buffer); +} + +/* Issue a pedantic warning for a bad initializer component. + FORMAT describes the message. OFWHAT is the name for the component. + LOCAL is a format string for formatting the insertion of the name + into the message. + + If OFWHAT is null, the component name is stored on the spelling stack. + If the component name is a null string, then LOCAL is omitted entirely. */ + +void +pedwarn_init (format, local, ofwhat) + char *format, *local, *ofwhat; +{ + char *buffer; + + if (ofwhat == 0) + ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); + buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2); + + if (*ofwhat) + sprintf (buffer, local, ofwhat); + else + buffer[0] = 0; + + pedwarn (format, buffer); +} + +/* Issue a warning for a bad initializer component. + FORMAT describes the message. OFWHAT is the name for the component. + LOCAL is a format string for formatting the insertion of the name + into the message. + + If OFWHAT is null, the component name is stored on the spelling stack. + If the component name is a null string, then LOCAL is omitted entirely. */ + +static void +warning_init (format, local, ofwhat) + char *format, *local, *ofwhat; +{ + char *buffer; + + if (ofwhat == 0) + ofwhat = print_spelling ((char *) alloca (spelling_length () + 1)); + buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2); + + if (*ofwhat) + sprintf (buffer, local, ofwhat); + else + buffer[0] = 0; + + warning (format, buffer); +} + +/* Digest the parser output INIT as an initializer for type TYPE. + Return a C expression of type TYPE to represent the initial value. + + The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors + if non-constant initializers or elements are seen. CONSTRUCTOR_CONSTANT + applies only to elements of constructors. */ + +static tree +digest_init (type, init, require_constant, constructor_constant) + tree type, init; + int require_constant, constructor_constant; +{ + enum tree_code code = TREE_CODE (type); + tree inside_init = init; + + if (init == error_mark_node) + return init; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + /* Do not use STRIP_NOPS here. We do not want an enumerator + whose value is 0 to count as a null pointer constant. */ + if (TREE_CODE (init) == NON_LVALUE_EXPR) + inside_init = TREE_OPERAND (init, 0); + + /* Initialization of an array of chars from a string constant + optionally enclosed in braces. */ + + if (code == ARRAY_TYPE) + { + tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + if ((typ1 == char_type_node + || typ1 == signed_char_type_node + || typ1 == unsigned_char_type_node + || typ1 == unsigned_wchar_type_node + || typ1 == signed_wchar_type_node) + && ((inside_init && TREE_CODE (inside_init) == STRING_CST))) + { + if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), + TYPE_MAIN_VARIANT (type))) + return inside_init; + + if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init))) + != char_type_node) + && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node)) + { + error_init ("char-array%s initialized from wide string", + " `%s'", NULL); + return error_mark_node; + } + if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init))) + == char_type_node) + && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)) + { + error_init ("int-array%s initialized from non-wide string", + " `%s'", NULL); + return error_mark_node; + } + + TREE_TYPE (inside_init) = type; + if (TYPE_DOMAIN (type) != 0 + && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) + { + register int size = TREE_INT_CST_LOW (TYPE_SIZE (type)); + size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT; + /* Subtract 1 (or sizeof (wchar_t)) + because it's ok to ignore the terminating null char + that is counted in the length of the constant. */ + if (size < TREE_STRING_LENGTH (inside_init) + - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node) + ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT + : 1)) + pedwarn_init ( + "initializer-string for array of chars%s is too long", + " `%s'", NULL); + } + return inside_init; + } + } + + /* Any type can be initialized + from an expression of the same type, optionally with braces. */ + + if (inside_init && TREE_TYPE (inside_init) != 0 + && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)), + TYPE_MAIN_VARIANT (type)) + || (code == ARRAY_TYPE + && comptypes (TREE_TYPE (inside_init), type)) + || (code == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE) + && comptypes (TREE_TYPE (TREE_TYPE (inside_init)), + TREE_TYPE (type))))) + { + if (code == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)) + inside_init = default_conversion (inside_init); + else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST + && TREE_CODE (inside_init) != CONSTRUCTOR) + { + error_init ("array%s initialized from non-constant array expression", + " `%s'", NULL); + return error_mark_node; + } + + if (optimize && TREE_CODE (inside_init) == VAR_DECL) + inside_init = decl_constant_value (inside_init); + + /* Compound expressions can only occur here if -pedantic or + -pedantic-errors is specified. In the later case, we always want + an error. In the former case, we simply want a warning. */ + if (require_constant && pedantic + && TREE_CODE (inside_init) == COMPOUND_EXPR) + { + inside_init + = valid_compound_expr_initializer (inside_init, + TREE_TYPE (inside_init)); + if (inside_init == error_mark_node) + error_init ("initializer element%s is not constant", + " for `%s'", NULL); + else + pedwarn_init ("initializer element%s is not constant", + " for `%s'", NULL); + if (flag_pedantic_errors) + inside_init = error_mark_node; + } + else if (require_constant && ! TREE_CONSTANT (inside_init)) + { + error_init ("initializer element%s is not constant", + " for `%s'", NULL); + inside_init = error_mark_node; + } + else if (require_constant + && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0) + { + error_init ("initializer element%s is not computable at load time", + " for `%s'", NULL); + inside_init = error_mark_node; + } + + return inside_init; + } + + /* Handle scalar types, including conversions. */ + + if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE + || code == ENUMERAL_TYPE || code == COMPLEX_TYPE) + { + /* Note that convert_for_assignment calls default_conversion + for arrays and functions. We must not call it in the + case where inside_init is a null pointer constant. */ + inside_init + = convert_for_assignment (type, init, "initialization", + NULL_TREE, NULL_TREE, 0); + + if (require_constant && ! TREE_CONSTANT (inside_init)) + { + error_init ("initializer element%s is not constant", + " for `%s'", NULL); + inside_init = error_mark_node; + } + else if (require_constant + && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0) + { + error_init ("initializer element%s is not computable at load time", + " for `%s'", NULL); + inside_init = error_mark_node; + } + + return inside_init; + } + + /* Come here only for records and arrays. */ + + if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) + { + error_init ("variable-sized object%s may not be initialized", + " `%s'", NULL); + return error_mark_node; + } + + /* Traditionally, you can write struct foo x = 0; + and it initializes the first element of x to 0. */ + if (flag_traditional) + { + tree top = 0, prev = 0, otype = type; + while (TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == ARRAY_TYPE + || TREE_CODE (type) == QUAL_UNION_TYPE + || TREE_CODE (type) == UNION_TYPE) + { + tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE); + if (prev == 0) + top = temp; + else + TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp); + prev = temp; + if (TREE_CODE (type) == ARRAY_TYPE) + type = TREE_TYPE (type); + else if (TYPE_FIELDS (type)) + type = TREE_TYPE (TYPE_FIELDS (type)); + else + { + error_init ("invalid initializer%s", " for `%s'", NULL); + return error_mark_node; + } + } + + if (otype != type) + { + TREE_OPERAND (prev, 1) + = build_tree_list (NULL_TREE, + digest_init (type, init, require_constant, + constructor_constant)); + return top; + } + else + return error_mark_node; + } + error_init ("invalid initializer%s", " for `%s'", NULL); + return error_mark_node; +} + +/* Handle initializers that use braces. */ + +/* Type of object we are accumulating a constructor for. + This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE. */ +static tree constructor_type; + +/* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields + left to fill. */ +static tree constructor_fields; + +/* For an ARRAY_TYPE, this is the specified index + at which to store the next element we get. + This is a special INTEGER_CST node that we modify in place. */ +static tree constructor_index; + +/* For an ARRAY_TYPE, this is the end index of the range + to initialize with the next element, or NULL in the ordinary case + where the element is used just once. */ +static tree constructor_range_end; + +/* For an ARRAY_TYPE, this is the maximum index. */ +static tree constructor_max_index; + +/* For a RECORD_TYPE, this is the first field not yet written out. */ +static tree constructor_unfilled_fields; + +/* For an ARRAY_TYPE, this is the index of the first element + not yet written out. + This is a special INTEGER_CST node that we modify in place. */ +static tree constructor_unfilled_index; + +/* In a RECORD_TYPE, the byte index of the next consecutive field. + This is so we can generate gaps between fields, when appropriate. + This is a special INTEGER_CST node that we modify in place. */ +static tree constructor_bit_index; + +/* If we are saving up the elements rather than allocating them, + this is the list of elements so far (in reverse order, + most recent first). */ +static tree constructor_elements; + +/* 1 if so far this constructor's elements are all compile-time constants. */ +static int constructor_constant; + +/* 1 if so far this constructor's elements are all valid address constants. */ +static int constructor_simple; + +/* 1 if this constructor is erroneous so far. */ +static int constructor_erroneous; + +/* 1 if have called defer_addressed_constants. */ +static int constructor_subconstants_deferred; + +/* List of pending elements at this constructor level. + These are elements encountered out of order + which belong at places we haven't reached yet in actually + writing the output. */ +static tree constructor_pending_elts; + +/* The SPELLING_DEPTH of this constructor. */ +static int constructor_depth; + +/* 0 if implicitly pushing constructor levels is allowed. */ +int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */ + +/* 1 if this constructor level was entered implicitly. */ +static int constructor_implicit; + +static int require_constant_value; +static int require_constant_elements; + +/* 1 if it is ok to output this constructor as we read it. + 0 means must accumulate a CONSTRUCTOR expression. */ +static int constructor_incremental; + +/* DECL node for which an initializer is being read. + 0 means we are reading a constructor expression + such as (struct foo) {...}. */ +static tree constructor_decl; + +/* start_init saves the ASMSPEC arg here for really_start_incremental_init. */ +static char *constructor_asmspec; + +/* Nonzero if this is an initializer for a top-level decl. */ +static int constructor_top_level; + +/* When we finish reading a constructor expression + (constructor_decl is 0), the CONSTRUCTOR goes here. */ +static tree constructor_result; + +/* This stack has a level for each implicit or explicit level of + structuring in the initializer, including the outermost one. It + saves the values of most of the variables above. */ + +struct constructor_stack +{ + struct constructor_stack *next; + tree type; + tree fields; + tree index; + tree range_end; + tree max_index; + tree unfilled_index; + tree unfilled_fields; + tree bit_index; + tree elements; + int offset; + tree pending_elts; + int depth; + /* If nonzero, this value should replace the entire + constructor at this level. */ + tree replacement_value; + char constant; + char simple; + char implicit; + char incremental; + char erroneous; + char outer; +}; + +struct constructor_stack *constructor_stack; + +/* This stack records separate initializers that are nested. + Nested initializers can't happen in ANSI C, but GNU C allows them + in cases like { ... (struct foo) { ... } ... }. */ + +struct initializer_stack +{ + struct initializer_stack *next; + tree decl; + char *asmspec; + struct constructor_stack *constructor_stack; + tree elements; + struct spelling *spelling; + struct spelling *spelling_base; + int spelling_size; + char top_level; + char incremental; + char require_constant_value; + char require_constant_elements; + char deferred; +}; + +struct initializer_stack *initializer_stack; + +/* Prepare to parse and output the initializer for variable DECL. */ + +void +start_init (decl, asmspec_tree, top_level) + tree decl; + tree asmspec_tree; + int top_level; +{ + char *locus; + struct initializer_stack *p + = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack)); + char *asmspec = 0; + + if (asmspec_tree) + asmspec = TREE_STRING_POINTER (asmspec_tree); + + p->decl = constructor_decl; + p->asmspec = constructor_asmspec; + p->incremental = constructor_incremental; + p->require_constant_value = require_constant_value; + p->require_constant_elements = require_constant_elements; + p->constructor_stack = constructor_stack; + p->elements = constructor_elements; + p->spelling = spelling; + p->spelling_base = spelling_base; + p->spelling_size = spelling_size; + p->deferred = constructor_subconstants_deferred; + p->top_level = constructor_top_level; + p->next = initializer_stack; + initializer_stack = p; + + constructor_decl = decl; + constructor_incremental = top_level; + constructor_asmspec = asmspec; + constructor_subconstants_deferred = 0; + constructor_top_level = top_level; + + if (decl != 0) + { + require_constant_value = TREE_STATIC (decl); + require_constant_elements + = ((TREE_STATIC (decl) || pedantic) + /* For a scalar, you can always use any value to initialize, + even within braces. */ + && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE + || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE)); + locus = IDENTIFIER_POINTER (DECL_NAME (decl)); + constructor_incremental |= TREE_STATIC (decl); + } + else + { + require_constant_value = 0; + require_constant_elements = 0; + locus = "(anonymous)"; + } + + constructor_stack = 0; + + missing_braces_mentioned = 0; + + spelling_base = 0; + spelling_size = 0; + RESTORE_SPELLING_DEPTH (0); + + if (locus) + push_string (locus); +} + +void +finish_init () +{ + struct initializer_stack *p = initializer_stack; + + /* Output subconstants (string constants, usually) + that were referenced within this initializer and saved up. + Must do this if and only if we called defer_addressed_constants. */ + if (constructor_subconstants_deferred) + output_deferred_addressed_constants (); + + /* Free the whole constructor stack of this initializer. */ + while (constructor_stack) + { + struct constructor_stack *q = constructor_stack; + constructor_stack = q->next; + free (q); + } + + /* Pop back to the data of the outer initializer (if any). */ + constructor_decl = p->decl; + constructor_asmspec = p->asmspec; + constructor_incremental = p->incremental; + require_constant_value = p->require_constant_value; + require_constant_elements = p->require_constant_elements; + constructor_stack = p->constructor_stack; + constructor_elements = p->elements; + spelling = p->spelling; + spelling_base = p->spelling_base; + spelling_size = p->spelling_size; + constructor_subconstants_deferred = p->deferred; + constructor_top_level = p->top_level; + initializer_stack = p->next; + free (p); +} + +/* Call here when we see the initializer is surrounded by braces. + This is instead of a call to push_init_level; + it is matched by a call to pop_init_level. + + TYPE is the type to initialize, for a constructor expression. + For an initializer for a decl, TYPE is zero. */ + +void +really_start_incremental_init (type) + tree type; +{ + struct constructor_stack *p + = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack)); + + if (type == 0) + type = TREE_TYPE (constructor_decl); + + /* Turn off constructor_incremental if type is a struct with bitfields. + Do this before the first push, so that the corrected value + is available in finish_init. */ + check_init_type_bitfields (type); + + p->type = constructor_type; + p->fields = constructor_fields; + p->index = constructor_index; + p->range_end = constructor_range_end; + p->max_index = constructor_max_index; + p->unfilled_index = constructor_unfilled_index; + p->unfilled_fields = constructor_unfilled_fields; + p->bit_index = constructor_bit_index; + p->elements = constructor_elements; + p->constant = constructor_constant; + p->simple = constructor_simple; + p->erroneous = constructor_erroneous; + p->pending_elts = constructor_pending_elts; + p->depth = constructor_depth; + p->replacement_value = 0; + p->implicit = 0; + p->incremental = constructor_incremental; + p->outer = 0; + p->next = 0; + constructor_stack = p; + + constructor_constant = 1; + constructor_simple = 1; + constructor_depth = SPELLING_DEPTH (); + constructor_elements = 0; + constructor_pending_elts = 0; + constructor_type = type; + + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + constructor_fields = TYPE_FIELDS (constructor_type); + /* Skip any nameless bit fields at the beginning. */ + while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields) + && DECL_NAME (constructor_fields) == 0) + constructor_fields = TREE_CHAIN (constructor_fields); + constructor_unfilled_fields = constructor_fields; + constructor_bit_index = copy_node (integer_zero_node); + } + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + constructor_range_end = 0; + if (TYPE_DOMAIN (constructor_type)) + { + constructor_max_index + = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); + constructor_index + = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); + } + else + constructor_index = copy_node (integer_zero_node); + constructor_unfilled_index = copy_node (constructor_index); + } + else + { + /* Handle the case of int x = {5}; */ + constructor_fields = constructor_type; + constructor_unfilled_fields = constructor_type; + } + + if (constructor_incremental) + { + int momentary = suspend_momentary (); + push_obstacks_nochange (); + if (TREE_PERMANENT (constructor_decl)) + end_temporary_allocation (); + make_decl_rtl (constructor_decl, constructor_asmspec, + constructor_top_level); + assemble_variable (constructor_decl, constructor_top_level, 0, 1); + pop_obstacks (); + resume_momentary (momentary); + } + + if (constructor_incremental) + { + defer_addressed_constants (); + constructor_subconstants_deferred = 1; + } +} + +/* Push down into a subobject, for initialization. + If this is for an explicit set of braces, IMPLICIT is 0. + If it is because the next element belongs at a lower level, + IMPLICIT is 1. */ + +void +push_init_level (implicit) + int implicit; +{ + struct constructor_stack *p; + + /* If we've exhausted any levels that didn't have braces, + pop them now. */ + while (constructor_stack->implicit) + { + if ((TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + && constructor_fields == 0) + process_init_element (pop_init_level (1)); + else if (TREE_CODE (constructor_type) == ARRAY_TYPE + && tree_int_cst_lt (constructor_max_index, constructor_index)) + process_init_element (pop_init_level (1)); + else + break; + } + + /* Structure elements may require alignment. Do this now + if necessary for the subaggregate. */ + if (constructor_incremental && constructor_type != 0 + && TREE_CODE (constructor_type) == RECORD_TYPE && constructor_fields) + { + /* Advance to offset of this element. */ + if (! tree_int_cst_equal (constructor_bit_index, + DECL_FIELD_BITPOS (constructor_fields))) + { + int next = (TREE_INT_CST_LOW + (DECL_FIELD_BITPOS (constructor_fields)) + / BITS_PER_UNIT); + int here = (TREE_INT_CST_LOW (constructor_bit_index) + / BITS_PER_UNIT); + + assemble_zeros (next - here); + } + } + + p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack)); + p->type = constructor_type; + p->fields = constructor_fields; + p->index = constructor_index; + p->range_end = constructor_range_end; + p->max_index = constructor_max_index; + p->unfilled_index = constructor_unfilled_index; + p->unfilled_fields = constructor_unfilled_fields; + p->bit_index = constructor_bit_index; + p->elements = constructor_elements; + p->constant = constructor_constant; + p->simple = constructor_simple; + p->erroneous = constructor_erroneous; + p->pending_elts = constructor_pending_elts; + p->depth = constructor_depth; + p->replacement_value = 0; + p->implicit = implicit; + p->incremental = constructor_incremental; + p->outer = 0; + p->next = constructor_stack; + constructor_stack = p; + + constructor_constant = 1; + constructor_simple = 1; + constructor_depth = SPELLING_DEPTH (); + constructor_elements = 0; + constructor_pending_elts = 0; + + /* Don't die if an entire brace-pair level is superfluous + in the containing level. */ + if (constructor_type == 0) + ; + else if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + /* Don't die if there are extra init elts at the end. */ + if (constructor_fields == 0) + constructor_type = 0; + else + { + constructor_type = TREE_TYPE (constructor_fields); + push_member_name (constructor_fields); + constructor_depth++; + if (constructor_fields != constructor_unfilled_fields) + constructor_incremental = 0; + } + } + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + constructor_type = TREE_TYPE (constructor_type); + push_array_bounds (TREE_INT_CST_LOW (constructor_index)); + constructor_depth++; + if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index) + || constructor_range_end != 0) + constructor_incremental = 0; + } + + if (constructor_type == 0) + { + error_init ("extra brace group at end of initializer%s", + " for `%s'", NULL); + constructor_fields = 0; + constructor_unfilled_fields = 0; + return; + } + + /* Turn off constructor_incremental if type is a struct with bitfields. */ + check_init_type_bitfields (constructor_type); + + if (implicit && warn_missing_braces && !missing_braces_mentioned) + { + missing_braces_mentioned = 1; + warning_init ("missing braces around initializer%s", " for `%s'", NULL); + } + + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + constructor_fields = TYPE_FIELDS (constructor_type); + /* Skip any nameless bit fields at the beginning. */ + while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields) + && DECL_NAME (constructor_fields) == 0) + constructor_fields = TREE_CHAIN (constructor_fields); + constructor_unfilled_fields = constructor_fields; + constructor_bit_index = copy_node (integer_zero_node); + } + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + constructor_range_end = 0; + if (TYPE_DOMAIN (constructor_type)) + { + constructor_max_index + = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)); + constructor_index + = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type))); + } + else + constructor_index = copy_node (integer_zero_node); + constructor_unfilled_index = copy_node (constructor_index); + } + else + { + warning_init ("braces around scalar initializer%s", " for `%s'", NULL); + constructor_fields = constructor_type; + constructor_unfilled_fields = constructor_type; + } +} + +/* Don't read a struct incrementally if it has any bitfields, + because the incremental reading code doesn't know how to + handle bitfields yet. */ + +static void +check_init_type_bitfields (type) + tree type; +{ + if (TREE_CODE (type) == RECORD_TYPE) + { + tree tail; + for (tail = TYPE_FIELDS (type); tail; + tail = TREE_CHAIN (tail)) + { + if (DECL_BIT_FIELD (tail) + /* This catches cases like `int foo : 8;'. */ + || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail))) + { + constructor_incremental = 0; + break; + } + + check_init_type_bitfields (TREE_TYPE (tail)); + } + } + + else if (TREE_CODE (type) == ARRAY_TYPE) + check_init_type_bitfields (TREE_TYPE (type)); +} + +/* At the end of an implicit or explicit brace level, + finish up that level of constructor. + If we were outputting the elements as they are read, return 0 + from inner levels (process_init_element ignores that), + but return error_mark_node from the outermost level + (that's what we want to put in DECL_INITIAL). + Otherwise, return a CONSTRUCTOR expression. */ + +tree +pop_init_level (implicit) + int implicit; +{ + struct constructor_stack *p; + int size = 0; + tree constructor = 0; + + if (implicit == 0) + { + /* When we come to an explicit close brace, + pop any inner levels that didn't have explicit braces. */ + while (constructor_stack->implicit) + process_init_element (pop_init_level (1)); + } + + p = constructor_stack; + + if (constructor_type != 0) + size = int_size_in_bytes (constructor_type); + + /* Now output all pending elements. */ + output_pending_init_elements (1); + +#if 0 /* c-parse.in warns about {}. */ + /* In ANSI, each brace level must have at least one element. */ + if (! implicit && pedantic + && (TREE_CODE (constructor_type) == ARRAY_TYPE + ? integer_zerop (constructor_unfilled_index) + : constructor_unfilled_fields == TYPE_FIELDS (constructor_type))) + pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL); +#endif + + /* Pad out the end of the structure. */ + + if (p->replacement_value) + { + /* If this closes a superfluous brace pair, + just pass out the element between them. */ + constructor = p->replacement_value; + /* If this is the top level thing within the initializer, + and it's for a variable, then since we already called + assemble_variable, we must output the value now. */ + if (p->next == 0 && constructor_decl != 0 + && constructor_incremental) + { + constructor = digest_init (constructor_type, constructor, + require_constant_value, + require_constant_elements); + + /* If initializing an array of unknown size, + determine the size now. */ + if (TREE_CODE (constructor_type) == ARRAY_TYPE + && TYPE_DOMAIN (constructor_type) == 0) + { + int failure; + int momentary_p; + + push_obstacks_nochange (); + if (TREE_PERMANENT (constructor_type)) + end_temporary_allocation (); + + momentary_p = suspend_momentary (); + + /* We shouldn't have an incomplete array type within + some other type. */ + if (constructor_stack->next) + abort (); + + failure + = complete_array_type (constructor_type, + constructor, 0); + if (failure) + abort (); + + size = int_size_in_bytes (constructor_type); + resume_momentary (momentary_p); + pop_obstacks (); + } + + output_constant (constructor, size); + } + } + else if (constructor_type == 0) + ; + else if (TREE_CODE (constructor_type) != RECORD_TYPE + && TREE_CODE (constructor_type) != UNION_TYPE + && TREE_CODE (constructor_type) != ARRAY_TYPE + && ! constructor_incremental) + { + /* A nonincremental scalar initializer--just return + the element, after verifying there is just one. */ + if (constructor_elements == 0) + { + error_init ("empty scalar initializer%s", + " for `%s'", NULL); + constructor = error_mark_node; + } + else if (TREE_CHAIN (constructor_elements) != 0) + { + error_init ("extra elements in scalar initializer%s", + " for `%s'", NULL); + constructor = TREE_VALUE (constructor_elements); + } + else + constructor = TREE_VALUE (constructor_elements); + } + else if (! constructor_incremental) + { + if (constructor_erroneous) + constructor = error_mark_node; + else + { + int momentary = suspend_momentary (); + + constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE, + nreverse (constructor_elements)); + if (constructor_constant) + TREE_CONSTANT (constructor) = 1; + if (constructor_constant && constructor_simple) + TREE_STATIC (constructor) = 1; + + resume_momentary (momentary); + } + } + else + { + tree filled; + int momentary = suspend_momentary (); + + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + /* Find the offset of the end of that field. */ + filled = size_binop (CEIL_DIV_EXPR, + constructor_bit_index, + size_int (BITS_PER_UNIT)); + } + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + /* If initializing an array of unknown size, + determine the size now. */ + if (TREE_CODE (constructor_type) == ARRAY_TYPE + && TYPE_DOMAIN (constructor_type) == 0) + { + tree maxindex + = size_binop (MINUS_EXPR, + constructor_unfilled_index, + integer_one_node); + + push_obstacks_nochange (); + if (TREE_PERMANENT (constructor_type)) + end_temporary_allocation (); + maxindex = copy_node (maxindex); + TYPE_DOMAIN (constructor_type) = build_index_type (maxindex); + TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type); + + /* TYPE_MAX_VALUE is always one less than the number of elements + in the array, because we start counting at zero. Therefore, + warn only if the value is less than zero. */ + if (pedantic + && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type))) + < 0)) + error_with_decl (constructor_decl, + "zero or negative array size `%s'"); + layout_type (constructor_type); + size = int_size_in_bytes (constructor_type); + pop_obstacks (); + } + + filled = size_binop (MULT_EXPR, constructor_unfilled_index, + size_in_bytes (TREE_TYPE (constructor_type))); + } + else + filled = 0; + + if (filled != 0) + assemble_zeros (size - TREE_INT_CST_LOW (filled)); + + resume_momentary (momentary); + } + + + constructor_type = p->type; + constructor_fields = p->fields; + constructor_index = p->index; + constructor_range_end = p->range_end; + constructor_max_index = p->max_index; + constructor_unfilled_index = p->unfilled_index; + constructor_unfilled_fields = p->unfilled_fields; + constructor_bit_index = p->bit_index; + constructor_elements = p->elements; + constructor_constant = p->constant; + constructor_simple = p->simple; + constructor_erroneous = p->erroneous; + constructor_pending_elts = p->pending_elts; + constructor_depth = p->depth; + constructor_incremental = p->incremental; + RESTORE_SPELLING_DEPTH (constructor_depth); + + constructor_stack = p->next; + free (p); + + if (constructor == 0) + { + if (constructor_stack == 0) + return error_mark_node; + return NULL_TREE; + } + return constructor; +} + +/* Within an array initializer, specify the next index to be initialized. + FIRST is that index. If LAST is nonzero, then initialize a range + of indices, running from FIRST through LAST. */ + +void +set_init_index (first, last) + tree first, last; +{ + while ((TREE_CODE (first) == NOP_EXPR + || TREE_CODE (first) == CONVERT_EXPR + || TREE_CODE (first) == NON_LVALUE_EXPR) + && (TYPE_MODE (TREE_TYPE (first)) + == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0))))) + (first) = TREE_OPERAND (first, 0); + if (last) + while ((TREE_CODE (last) == NOP_EXPR + || TREE_CODE (last) == CONVERT_EXPR + || TREE_CODE (last) == NON_LVALUE_EXPR) + && (TYPE_MODE (TREE_TYPE (last)) + == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0))))) + (last) = TREE_OPERAND (last, 0); + + if (TREE_CODE (first) != INTEGER_CST) + error_init ("nonconstant array index in initializer%s", " for `%s'", NULL); + else if (last != 0 && TREE_CODE (last) != INTEGER_CST) + error_init ("nonconstant array index in initializer%s", " for `%s'", NULL); + else if (tree_int_cst_lt (first, constructor_unfilled_index)) + error_init ("duplicate array index in initializer%s", " for `%s'", NULL); + else + { + TREE_INT_CST_LOW (constructor_index) + = TREE_INT_CST_LOW (first); + TREE_INT_CST_HIGH (constructor_index) + = TREE_INT_CST_HIGH (first); + + if (last != 0 && tree_int_cst_lt (last, first)) + error_init ("empty index range in initializer%s", " for `%s'", NULL); + else + { + if (pedantic) + pedwarn ("ANSI C forbids specifying element to initialize"); + constructor_range_end = last; + } + } +} + +/* Within a struct initializer, specify the next field to be initialized. */ + +void +set_init_label (fieldname) + tree fieldname; +{ + tree tail; + int passed = 0; + + /* Don't die if an entire brace-pair level is superfluous + in the containing level. */ + if (constructor_type == 0) + return; + + for (tail = TYPE_FIELDS (constructor_type); tail; + tail = TREE_CHAIN (tail)) + { + if (tail == constructor_unfilled_fields) + passed = 1; + if (DECL_NAME (tail) == fieldname) + break; + } + + if (tail == 0) + error ("unknown field `%s' specified in initializer", + IDENTIFIER_POINTER (fieldname)); + else if (!passed) + error ("field `%s' already initialized", + IDENTIFIER_POINTER (fieldname)); + else + { + constructor_fields = tail; + if (pedantic) + pedwarn ("ANSI C forbids specifying structure member to initialize"); + } +} + +/* "Output" the next constructor element. + At top level, really output it to assembler code now. + Otherwise, collect it in a list from which we will make a CONSTRUCTOR. + TYPE is the data type that the containing data type wants here. + FIELD is the field (a FIELD_DECL) or the index that this element fills. + + PENDING if non-nil means output pending elements that belong + right after this element. (PENDING is normally 1; + it is 0 while outputting pending elements, to avoid recursion.) */ + +static void +output_init_element (value, type, field, pending) + tree value, type, field; + int pending; +{ + int duplicate = 0; + + if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE + || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE + && !(TREE_CODE (value) == STRING_CST + && TREE_CODE (type) == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE) + && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)), + TYPE_MAIN_VARIANT (type)))) + value = default_conversion (value); + + if (value == error_mark_node) + constructor_erroneous = 1; + else if (!TREE_CONSTANT (value)) + constructor_constant = 0; + else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0 + || ((TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + && DECL_BIT_FIELD (field) && TREE_CODE (value) != INTEGER_CST)) + constructor_simple = 0; + + if (require_constant_value && ! TREE_CONSTANT (value)) + { + error_init ("initializer element%s is not constant", + " for `%s'", NULL); + value = error_mark_node; + } + else if (require_constant_elements + && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0) + { + error_init ("initializer element%s is not computable at load time", + " for `%s'", NULL); + value = error_mark_node; + } + + /* If this element duplicates one on constructor_pending_elts, + print a message and ignore it. Don't do this when we're + processing elements taken off constructor_pending_elts, + because we'd always get spurious errors. */ + if (pending) + { + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + if (purpose_member (field, constructor_pending_elts)) + { + error_init ("duplicate initializer%s", " for `%s'", NULL); + duplicate = 1; + } + } + if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + tree tail; + for (tail = constructor_pending_elts; tail; + tail = TREE_CHAIN (tail)) + if (TREE_PURPOSE (tail) != 0 + && TREE_CODE (TREE_PURPOSE (tail)) == INTEGER_CST + && tree_int_cst_equal (TREE_PURPOSE (tail), constructor_index)) + break; + + if (tail != 0) + { + error_init ("duplicate initializer%s", " for `%s'", NULL); + duplicate = 1; + } + } + } + + /* If this element doesn't come next in sequence, + put it on constructor_pending_elts. */ + if (TREE_CODE (constructor_type) == ARRAY_TYPE + && !tree_int_cst_equal (field, constructor_unfilled_index)) + { + if (! duplicate) + /* The copy_node is needed in case field is actually + constructor_index, which is modified in place. */ + constructor_pending_elts + = tree_cons (copy_node (field), + digest_init (type, value, require_constant_value, + require_constant_elements), + constructor_pending_elts); + } + else if (TREE_CODE (constructor_type) == RECORD_TYPE + && field != constructor_unfilled_fields) + { + /* We do this for records but not for unions. In a union, + no matter which field is specified, it can be initialized + right away since it starts at the beginning of the union. */ + if (!duplicate) + constructor_pending_elts + = tree_cons (field, + digest_init (type, value, require_constant_value, + require_constant_elements), + constructor_pending_elts); + } + else + { + /* Otherwise, output this element either to + constructor_elements or to the assembler file. */ + + if (!duplicate) + { + if (! constructor_incremental) + { + if (field && TREE_CODE (field) == INTEGER_CST) + field = copy_node (field); + constructor_elements + = tree_cons (field, digest_init (type, value, + require_constant_value, + require_constant_elements), + constructor_elements); + } + else + { + /* Structure elements may require alignment. + Do this, if necessary. */ + if (TREE_CODE (constructor_type) == RECORD_TYPE) + { + /* Advance to offset of this element. */ + if (! tree_int_cst_equal (constructor_bit_index, + DECL_FIELD_BITPOS (field))) + { + int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)) + / BITS_PER_UNIT); + int here = (TREE_INT_CST_LOW (constructor_bit_index) + / BITS_PER_UNIT); + + assemble_zeros (next - here); + } + } + output_constant (digest_init (type, value, + require_constant_value, + require_constant_elements), + int_size_in_bytes (type)); + + /* For a record or union, + keep track of end position of last field. */ + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field), + DECL_SIZE (field)); + TREE_INT_CST_LOW (constructor_bit_index) + = TREE_INT_CST_LOW (temp); + TREE_INT_CST_HIGH (constructor_bit_index) + = TREE_INT_CST_HIGH (temp); + } + } + } + + /* Advance the variable that indicates sequential elements output. */ + if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index, + integer_one_node); + TREE_INT_CST_LOW (constructor_unfilled_index) + = TREE_INT_CST_LOW (tem); + TREE_INT_CST_HIGH (constructor_unfilled_index) + = TREE_INT_CST_HIGH (tem); + } + else if (TREE_CODE (constructor_type) == RECORD_TYPE) + constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields); + else if (TREE_CODE (constructor_type) == UNION_TYPE) + constructor_unfilled_fields = 0; + + /* Now output any pending elements which have become next. */ + if (pending) + output_pending_init_elements (0); + } +} + +/* Output any pending elements which have become next. + As we output elements, constructor_unfilled_{fields,index} + advances, which may cause other elements to become next; + if so, they too are output. + + If ALL is 0, we return when there are + no more pending elements to output now. + + If ALL is 1, we output space as necessary so that + we can output all the pending elements. */ + +static void +output_pending_init_elements (all) + int all; +{ + tree tail; + tree next; + + retry: + + /* Look thru the whole pending list. + If we find an element that should be output now, + output it. Otherwise, set NEXT to the element + that comes first among those still pending. */ + + next = 0; + for (tail = constructor_pending_elts; tail; + tail = TREE_CHAIN (tail)) + { + if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + if (tree_int_cst_equal (TREE_PURPOSE (tail), + constructor_unfilled_index)) + { + output_init_element (TREE_VALUE (tail), + TREE_TYPE (constructor_type), + constructor_unfilled_index, 0); + goto retry; + } + else if (tree_int_cst_lt (TREE_PURPOSE (tail), + constructor_unfilled_index)) + ; + else if (next == 0 + || tree_int_cst_lt (TREE_PURPOSE (tail), next)) + next = TREE_PURPOSE (tail); + } + else if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + if (TREE_PURPOSE (tail) == constructor_unfilled_fields) + { + output_init_element (TREE_VALUE (tail), + TREE_TYPE (constructor_unfilled_fields), + constructor_unfilled_fields, + 0); + goto retry; + } + else if (constructor_unfilled_fields == 0 + || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)), + DECL_FIELD_BITPOS (constructor_unfilled_fields))) + ; + else if (next == 0 + || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)), + DECL_FIELD_BITPOS (next))) + next = TREE_PURPOSE (tail); + } + } + + /* Ordinarily return, but not if we want to output all + and there are elements left. */ + if (! (all && next != 0)) + return; + + /* Generate space up to the position of NEXT. */ + if (constructor_incremental) + { + tree filled; + tree nextpos_tree = size_int (0); + + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + { + /* Find the last field written out, if any. */ + for (tail = TYPE_FIELDS (constructor_type); tail; + tail = TREE_CHAIN (tail)) + if (TREE_CHAIN (tail) == constructor_unfilled_fields) + break; + + if (tail) + /* Find the offset of the end of that field. */ + filled = size_binop (CEIL_DIV_EXPR, + size_binop (PLUS_EXPR, + DECL_FIELD_BITPOS (tail), + DECL_SIZE (tail)), + size_int (BITS_PER_UNIT)); + else + filled = size_int (0); + + nextpos_tree = size_binop (CEIL_DIV_EXPR, + DECL_FIELD_BITPOS (next), + size_int (BITS_PER_UNIT)); + + TREE_INT_CST_HIGH (constructor_bit_index) + = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next)); + TREE_INT_CST_LOW (constructor_bit_index) + = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next)); + constructor_unfilled_fields = next; + } + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + filled = size_binop (MULT_EXPR, constructor_unfilled_index, + size_in_bytes (TREE_TYPE (constructor_type))); + nextpos_tree + = size_binop (MULT_EXPR, next, + size_in_bytes (TREE_TYPE (constructor_type))); + TREE_INT_CST_LOW (constructor_unfilled_index) + = TREE_INT_CST_LOW (next); + TREE_INT_CST_HIGH (constructor_unfilled_index) + = TREE_INT_CST_HIGH (next); + } + else + filled = 0; + + if (filled) + { + int nextpos = TREE_INT_CST_LOW (nextpos_tree); + + assemble_zeros (nextpos - TREE_INT_CST_LOW (filled)); + } + } + else + { + /* If it's not incremental, just skip over the gap, + so that after jumping to retry we will output the next + successive element. */ + if (TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + constructor_unfilled_fields = next; + else if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + TREE_INT_CST_LOW (constructor_unfilled_index) + = TREE_INT_CST_LOW (next); + TREE_INT_CST_HIGH (constructor_unfilled_index) + = TREE_INT_CST_HIGH (next); + } + } + + goto retry; +} + +/* Add one non-braced element to the current constructor level. + This adjusts the current position within the constructor's type. + This may also start or terminate implicit levels + to handle a partly-braced initializer. + + Once this has found the correct level for the new element, + it calls output_init_element. + + Note: if we are incrementally outputting this constructor, + this function may be called with a null argument + representing a sub-constructor that was already incrementally output. + When that happens, we output nothing, but we do the bookkeeping + to skip past that element of the current constructor. */ + +void +process_init_element (value) + tree value; +{ + tree orig_value = value; + int string_flag = value != 0 && TREE_CODE (value) == STRING_CST; + + /* Handle superfluous braces around string cst as in + char x[] = {"foo"}; */ + if (string_flag + && constructor_type + && TREE_CODE (constructor_type) == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE + && integer_zerop (constructor_unfilled_index)) + { + constructor_stack->replacement_value = value; + return; + } + + if (constructor_stack->replacement_value != 0) + { + error_init ("excess elements in struct initializer%s", + " after `%s'", NULL_PTR); + return; + } + + /* Ignore elements of a brace group if it is entirely superfluous + and has already been diagnosed. */ + if (constructor_type == 0) + return; + + /* If we've exhausted any levels that didn't have braces, + pop them now. */ + while (constructor_stack->implicit) + { + if ((TREE_CODE (constructor_type) == RECORD_TYPE + || TREE_CODE (constructor_type) == UNION_TYPE) + && constructor_fields == 0) + process_init_element (pop_init_level (1)); + else if (TREE_CODE (constructor_type) == ARRAY_TYPE + && tree_int_cst_lt (constructor_max_index, constructor_index)) + process_init_element (pop_init_level (1)); + else + break; + } + + while (1) + { + if (TREE_CODE (constructor_type) == RECORD_TYPE) + { + tree fieldtype; + enum tree_code fieldcode; + + if (constructor_fields == 0) + { + pedwarn_init ("excess elements in struct initializer%s", + " after `%s'", NULL_PTR); + break; + } + + fieldtype = TREE_TYPE (constructor_fields); + if (fieldtype != error_mark_node) + fieldtype = TYPE_MAIN_VARIANT (fieldtype); + fieldcode = TREE_CODE (fieldtype); + + /* Accept a string constant to initialize a subarray. */ + if (value != 0 + && fieldcode == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE + && string_flag) + value = orig_value; + /* Otherwise, if we have come to a subaggregate, + and we don't have an element of its type, push into it. */ + else if (value != 0 && !constructor_no_implicit + && value != error_mark_node + && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype + && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE + || fieldcode == UNION_TYPE)) + { + push_init_level (1); + continue; + } + + if (value) + { + push_member_name (constructor_fields); + output_init_element (value, fieldtype, constructor_fields, 1); + RESTORE_SPELLING_DEPTH (constructor_depth); + } + else + /* Do the bookkeeping for an element that was + directly output as a constructor. */ + { + /* For a record, keep track of end position of last field. */ + tree temp = size_binop (PLUS_EXPR, + DECL_FIELD_BITPOS (constructor_fields), + DECL_SIZE (constructor_fields)); + TREE_INT_CST_LOW (constructor_bit_index) + = TREE_INT_CST_LOW (temp); + TREE_INT_CST_HIGH (constructor_bit_index) + = TREE_INT_CST_HIGH (temp); + + constructor_unfilled_fields = TREE_CHAIN (constructor_fields); + } + + constructor_fields = TREE_CHAIN (constructor_fields); + /* Skip any nameless bit fields at the beginning. */ + while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields) + && DECL_NAME (constructor_fields) == 0) + constructor_fields = TREE_CHAIN (constructor_fields); + break; + } + if (TREE_CODE (constructor_type) == UNION_TYPE) + { + tree fieldtype; + enum tree_code fieldcode; + + if (constructor_fields == 0) + { + pedwarn_init ("excess elements in union initializer%s", + " after `%s'", NULL_PTR); + break; + } + + fieldtype = TREE_TYPE (constructor_fields); + if (fieldtype != error_mark_node) + fieldtype = TYPE_MAIN_VARIANT (fieldtype); + fieldcode = TREE_CODE (fieldtype); + + /* Accept a string constant to initialize a subarray. */ + if (value != 0 + && fieldcode == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE + && string_flag) + value = orig_value; + /* Otherwise, if we have come to a subaggregate, + and we don't have an element of its type, push into it. */ + else if (value != 0 && !constructor_no_implicit + && value != error_mark_node + && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype + && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE + || fieldcode == UNION_TYPE)) + { + push_init_level (1); + continue; + } + + if (value) + { + push_member_name (constructor_fields); + output_init_element (value, fieldtype, constructor_fields, 1); + RESTORE_SPELLING_DEPTH (constructor_depth); + } + else + /* Do the bookkeeping for an element that was + directly output as a constructor. */ + { + TREE_INT_CST_LOW (constructor_bit_index) + = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields)); + TREE_INT_CST_HIGH (constructor_bit_index) + = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields)); + + constructor_unfilled_fields = TREE_CHAIN (constructor_fields); + } + + constructor_fields = 0; + break; + } + if (TREE_CODE (constructor_type) == ARRAY_TYPE) + { + tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type)); + enum tree_code eltcode = TREE_CODE (elttype); + + /* Accept a string constant to initialize a subarray. */ + if (value != 0 + && eltcode == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE + && string_flag) + value = orig_value; + /* Otherwise, if we have come to a subaggregate, + and we don't have an element of its type, push into it. */ + else if (value != 0 && !constructor_no_implicit + && value != error_mark_node + && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype + && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE + || eltcode == UNION_TYPE)) + { + push_init_level (1); + continue; + } + + if (constructor_max_index != 0 + && tree_int_cst_lt (constructor_max_index, constructor_index)) + { + pedwarn_init ("excess elements in array initializer%s", + " after `%s'", NULL_PTR); + break; + } + + /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */ + if (constructor_range_end) + value = save_expr (value); + + /* Now output the actual element. + Ordinarily, output once. + If there is a range, repeat it till we advance past the range. */ + do + { + tree tem; + + if (value) + { + push_array_bounds (TREE_INT_CST_LOW (constructor_index)); + output_init_element (value, elttype, constructor_index, 1); + RESTORE_SPELLING_DEPTH (constructor_depth); + } + + tem = size_binop (PLUS_EXPR, constructor_index, + integer_one_node); + TREE_INT_CST_LOW (constructor_index) + = TREE_INT_CST_LOW (tem); + TREE_INT_CST_HIGH (constructor_index) + = TREE_INT_CST_HIGH (tem); + + if (!value) + /* If we are doing the bookkeeping for an element that was + directly output as a constructor, + we must update constructor_unfilled_index. */ + { + TREE_INT_CST_LOW (constructor_unfilled_index) + = TREE_INT_CST_LOW (constructor_index); + TREE_INT_CST_HIGH (constructor_unfilled_index) + = TREE_INT_CST_HIGH (constructor_index); + } + } + while (! (constructor_range_end == 0 + || tree_int_cst_lt (constructor_range_end, + constructor_index))); + + break; + } + + /* Handle the sole element allowed in a braced initializer + for a scalar variable. */ + if (constructor_fields == 0) + { + pedwarn_init ("excess elements in scalar initializer%s", + " after `%s'", NULL_PTR); + break; + } + + if (value) + output_init_element (value, constructor_type, NULL_TREE, 1); + constructor_fields = 0; + break; + } + + /* If the (lexically) previous elments are not now saved, + we can discard the storage for them. */ + if (constructor_incremental && constructor_pending_elts == 0 && value != 0 + && constructor_stack == 0) + clear_momentary (); +} + +/* Expand an ASM statement with operands, handling output operands + that are not variables or INDIRECT_REFS by transforming such + cases into cases that expand_asm_operands can handle. + + Arguments are same as for expand_asm_operands. */ + +void +c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) + tree string, outputs, inputs, clobbers; + int vol; + char *filename; + int line; +{ + int noutputs = list_length (outputs); + register int i; + /* o[I] is the place that output number I should be written. */ + register tree *o = (tree *) alloca (noutputs * sizeof (tree)); + register tree tail; + + if (TREE_CODE (string) == ADDR_EXPR) + string = TREE_OPERAND (string, 0); + if (TREE_CODE (string) != STRING_CST) + { + error ("asm template is not a string constant"); + return; + } + + /* Record the contents of OUTPUTS before it is modified. */ + for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) + o[i] = TREE_VALUE (tail); + + /* Perform default conversions on array and function inputs. */ + /* Don't do this for other types-- + it would screw up operands expected to be in memory. */ + for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++) + if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE) + TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail)); + + /* Generate the ASM_OPERANDS insn; + store into the TREE_VALUEs of OUTPUTS some trees for + where the values were actually stored. */ + expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line); + + /* Copy all the intermediate outputs into the specified outputs. */ + for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) + { + if (o[i] != TREE_VALUE (tail)) + { + expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)), + 0, VOIDmode, 0); + free_temp_slots (); + } + /* Detect modification of read-only values. + (Otherwise done by build_modify_expr.) */ + else + { + tree type = TREE_TYPE (o[i]); + if (TREE_READONLY (o[i]) + || TYPE_READONLY (type) + || ((TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (type))) + readonly_warning (o[i], "modification by `asm'"); + } + } + + /* Those MODIFY_EXPRs could do autoincrements. */ + emit_queue (); +} + +/* Expand a C `return' statement. + RETVAL is the expression for what to return, + or a null pointer for `return;' with no value. */ + +void +c_expand_return (retval) + tree retval; +{ + tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)); + + if (TREE_THIS_VOLATILE (current_function_decl)) + warning ("function declared `noreturn' has a `return' statement"); + + if (!retval) + { + current_function_returns_null = 1; + if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) + warning ("`return' with no value, in function returning non-void"); + expand_null_return (); + } + else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE) + { + current_function_returns_null = 1; + if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) + pedwarn ("`return' with a value, in function returning void"); + expand_return (retval); + } + else + { + tree t = convert_for_assignment (valtype, retval, "return", + NULL_TREE, NULL_TREE, 0); + tree res = DECL_RESULT (current_function_decl); + tree inner; + + if (t == error_mark_node) + return; + + inner = t = convert (TREE_TYPE (res), t); + + /* Strip any conversions, additions, and subtractions, and see if + we are returning the address of a local variable. Warn if so. */ + while (1) + { + switch (TREE_CODE (inner)) + { + case NOP_EXPR: case NON_LVALUE_EXPR: case CONVERT_EXPR: + case PLUS_EXPR: + inner = TREE_OPERAND (inner, 0); + continue; + + case MINUS_EXPR: + /* If the second operand of the MINUS_EXPR has a pointer + type (or is converted from it), this may be valid, so + don't give a warning. */ + { + tree op1 = TREE_OPERAND (inner, 1); + + while (! POINTER_TYPE_P (TREE_TYPE (op1)) + && (TREE_CODE (op1) == NOP_EXPR + || TREE_CODE (op1) == NON_LVALUE_EXPR + || TREE_CODE (op1) == CONVERT_EXPR)) + op1 = TREE_OPERAND (op1, 0); + + if (POINTER_TYPE_P (TREE_TYPE (op1))) + break; + + inner = TREE_OPERAND (inner, 0); + continue; + } + + case ADDR_EXPR: + inner = TREE_OPERAND (inner, 0); + + while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r') + inner = TREE_OPERAND (inner, 0); + + if (TREE_CODE (inner) == VAR_DECL + && ! DECL_EXTERNAL (inner) + && ! TREE_STATIC (inner) + && DECL_CONTEXT (inner) == current_function_decl) + warning ("function returns address of local variable"); + break; + } + + break; + } + + t = build (MODIFY_EXPR, TREE_TYPE (res), res, t); + TREE_SIDE_EFFECTS (t) = 1; + expand_return (t); + current_function_returns_value = 1; + } +} + +/* Start a C switch statement, testing expression EXP. + Return EXP if it is valid, an error node otherwise. */ + +tree +c_expand_start_case (exp) + tree exp; +{ + register enum tree_code code = TREE_CODE (TREE_TYPE (exp)); + tree type = TREE_TYPE (exp); + + if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK) + { + error ("switch quantity not an integer"); + exp = error_mark_node; + } + else + { + tree index; + type = TYPE_MAIN_VARIANT (TREE_TYPE (exp)); + + if (warn_traditional + && (type == long_integer_type_node + || type == long_unsigned_type_node)) + pedwarn ("`long' switch expression not converted to `int' in ANSI C"); + + exp = default_conversion (exp); + type = TREE_TYPE (exp); + index = get_unwidened (exp, NULL_TREE); + /* We can't strip a conversion from a signed type to an unsigned, + because if we did, int_fits_type_p would do the wrong thing + when checking case values for being in range, + and it's too hard to do the right thing. */ + if (TREE_UNSIGNED (TREE_TYPE (exp)) + == TREE_UNSIGNED (TREE_TYPE (index))) + exp = index; + } + + expand_start_case (1, exp, type, "switch statement"); + + return exp; +} diff --git a/contrib/gcc/caller-save.c b/contrib/gcc/caller-save.c new file mode 100644 index 00000000000..6dc90189ee6 --- /dev/null +++ b/contrib/gcc/caller-save.c @@ -0,0 +1,770 @@ +/* Save and restore call-clobbered registers which are live across a call. + Copyright (C) 1989, 1992, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "rtl.h" +#include "insn-config.h" +#include "flags.h" +#include "regs.h" +#include "hard-reg-set.h" +#include "recog.h" +#include "basic-block.h" +#include "reload.h" +#include "expr.h" + +#ifndef MAX_MOVE_MAX +#define MAX_MOVE_MAX MOVE_MAX +#endif + +#ifndef MIN_UNITS_PER_WORD +#define MIN_UNITS_PER_WORD UNITS_PER_WORD +#endif + +/* Modes for each hard register that we can save. The smallest mode is wide + enough to save the entire contents of the register. When saving the + register because it is live we first try to save in multi-register modes. + If that is not possible the save is done one register at a time. */ + +static enum machine_mode + regno_save_mode[FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX / MIN_UNITS_PER_WORD + 1]; + +/* For each hard register, a place on the stack where it can be saved, + if needed. */ + +static rtx + regno_save_mem[FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX / MIN_UNITS_PER_WORD + 1]; + +/* We will only make a register eligible for caller-save if it can be + saved in its widest mode with a simple SET insn as long as the memory + address is valid. We record the INSN_CODE is those insns here since + when we emit them, the addresses might not be valid, so they might not + be recognized. */ + +static enum insn_code + reg_save_code[FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX / MIN_UNITS_PER_WORD + 1]; +static enum insn_code + reg_restore_code[FIRST_PSEUDO_REGISTER][MAX_MOVE_MAX / MIN_UNITS_PER_WORD + 1]; + +/* Set of hard regs currently live (during scan of all insns). */ + +static HARD_REG_SET hard_regs_live; + +/* Set of hard regs currently residing in save area (during insn scan). */ + +static HARD_REG_SET hard_regs_saved; + +/* Set of hard regs which need to be restored before referenced. */ + +static HARD_REG_SET hard_regs_need_restore; + +/* Number of registers currently in hard_regs_saved. */ + +int n_regs_saved; + +static void set_reg_live PROTO((rtx, rtx)); +static void clear_reg_live PROTO((rtx)); +static void restore_referenced_regs PROTO((rtx, rtx, enum machine_mode)); +static int insert_save_restore PROTO((rtx, int, int, + enum machine_mode, int)); + +/* Initialize for caller-save. + + Look at all the hard registers that are used by a call and for which + regclass.c has not already excluded from being used across a call. + + Ensure that we can find a mode to save the register and that there is a + simple insn to save and restore the register. This latter check avoids + problems that would occur if we tried to save the MQ register of some + machines directly into memory. */ + +void +init_caller_save () +{ + char *first_obj = (char *) oballoc (0); + rtx addr_reg; + int offset; + rtx address; + int i, j; + + /* First find all the registers that we need to deal with and all + the modes that they can have. If we can't find a mode to use, + we can't have the register live over calls. */ + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + { + if (call_used_regs[i] && ! call_fixed_regs[i]) + { + for (j = 1; j <= MOVE_MAX / UNITS_PER_WORD; j++) + { + regno_save_mode[i][j] = choose_hard_reg_mode (i, j); + if (regno_save_mode[i][j] == VOIDmode && j == 1) + { + call_fixed_regs[i] = 1; + SET_HARD_REG_BIT (call_fixed_reg_set, i); + } + } + } + else + regno_save_mode[i][1] = VOIDmode; + } + + /* The following code tries to approximate the conditions under which + we can easily save and restore a register without scratch registers or + other complexities. It will usually work, except under conditions where + the validity of an insn operand is dependent on the address offset. + No such cases are currently known. + + We first find a typical offset from some BASE_REG_CLASS register. + This address is chosen by finding the first register in the class + and by finding the smallest power of two that is a valid offset from + that register in every mode we will use to save registers. */ + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if (TEST_HARD_REG_BIT (reg_class_contents[(int) BASE_REG_CLASS], i)) + break; + + if (i == FIRST_PSEUDO_REGISTER) + abort (); + + addr_reg = gen_rtx (REG, Pmode, i); + + for (offset = 1 << (HOST_BITS_PER_INT / 2); offset; offset >>= 1) + { + address = gen_rtx (PLUS, Pmode, addr_reg, GEN_INT (offset)); + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if (regno_save_mode[i][1] != VOIDmode + && ! strict_memory_address_p (regno_save_mode[i][1], address)) + break; + + if (i == FIRST_PSEUDO_REGISTER) + break; + } + + /* If we didn't find a valid address, we must use register indirect. */ + if (offset == 0) + address = addr_reg; + + /* Next we try to form an insn to save and restore the register. We + see if such an insn is recognized and meets its constraints. */ + + start_sequence (); + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (j = 1; j <= MOVE_MAX / UNITS_PER_WORD; j++) + if (regno_save_mode[i][j] != VOIDmode) + { + rtx mem = gen_rtx (MEM, regno_save_mode[i][j], address); + rtx reg = gen_rtx (REG, regno_save_mode[i][j], i); + rtx savepat = gen_rtx (SET, VOIDmode, mem, reg); + rtx restpat = gen_rtx (SET, VOIDmode, reg, mem); + rtx saveinsn = emit_insn (savepat); + rtx restinsn = emit_insn (restpat); + int ok; + + reg_save_code[i][j] = recog_memoized (saveinsn); + reg_restore_code[i][j] = recog_memoized (restinsn); + + /* Now extract both insns and see if we can meet their constraints. */ + ok = (reg_save_code[i][j] != -1 && reg_restore_code[i][j] != -1); + if (ok) + { + insn_extract (saveinsn); + ok = constrain_operands (reg_save_code[i][j], 1); + insn_extract (restinsn); + ok &= constrain_operands (reg_restore_code[i][j], 1); + } + + if (! ok) + { + regno_save_mode[i][j] = VOIDmode; + if (j == 1) + { + call_fixed_regs[i] = 1; + SET_HARD_REG_BIT (call_fixed_reg_set, i); + } + } + } + + end_sequence (); + + obfree (first_obj); +} + +/* Initialize save areas by showing that we haven't allocated any yet. */ + +void +init_save_areas () +{ + int i, j; + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (j = 1; j <= MOVE_MAX / UNITS_PER_WORD; j++) + regno_save_mem[i][j] = 0; +} + +/* Allocate save areas for any hard registers that might need saving. + We take a conservative approach here and look for call-clobbered hard + registers that are assigned to pseudos that cross calls. This may + overestimate slightly (especially if some of these registers are later + used as spill registers), but it should not be significant. + + Then perform register elimination in the addresses of the save area + locations; return 1 if all eliminated addresses are strictly valid. + We assume that our caller has set up the elimination table to the + worst (largest) possible offsets. + + Set *PCHANGED to 1 if we had to allocate some memory for the save area. + + Future work: + + In the fallback case we should iterate backwards across all possible + modes for the save, choosing the largest available one instead of + falling back to the smallest mode immediately. (eg TF -> DF -> SF). + + We do not try to use "move multiple" instructions that exist + on some machines (such as the 68k moveml). It could be a win to try + and use them when possible. The hard part is doing it in a way that is + machine independent since they might be saving non-consecutive + registers. (imagine caller-saving d0,d1,a0,a1 on the 68k) */ + +int +setup_save_areas (pchanged) + int *pchanged; +{ + int i, j, k; + HARD_REG_SET hard_regs_used; + int ok = 1; + + + /* Allocate space in the save area for the largest multi-register + pseudos first, then work backwards to single register + pseudos. */ + + /* Find and record all call-used hard-registers in this function. */ + CLEAR_HARD_REG_SET (hard_regs_used); + for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) + if (reg_renumber[i] >= 0 && reg_n_calls_crossed[i] > 0) + { + int regno = reg_renumber[i]; + int endregno + = regno + HARD_REGNO_NREGS (regno, GET_MODE (regno_reg_rtx[i])); + int nregs = endregno - regno; + + for (j = 0; j < nregs; j++) + { + if (call_used_regs[regno+j]) + SET_HARD_REG_BIT (hard_regs_used, regno+j); + } + } + + /* Now run through all the call-used hard-registers and allocate + space for them in the caller-save area. Try to allocate space + in a manner which allows multi-register saves/restores to be done. */ + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (j = MOVE_MAX / UNITS_PER_WORD; j > 0; j--) + { + int ok = 1; + int do_save; + + /* If no mode exists for this size, try another. Also break out + if we have already saved this hard register. */ + if (regno_save_mode[i][j] == VOIDmode || regno_save_mem[i][1] != 0) + continue; + + /* See if any register in this group has been saved. */ + do_save = 1; + for (k = 0; k < j; k++) + if (regno_save_mem[i + k][1]) + { + do_save = 0; + break; + } + if (! do_save) + continue; + + for (k = 0; k < j; k++) + { + int regno = i + k; + ok &= (TEST_HARD_REG_BIT (hard_regs_used, regno) != 0); + } + + /* We have found an acceptable mode to store in. */ + if (ok) + { + + regno_save_mem[i][j] + = assign_stack_local (regno_save_mode[i][j], + GET_MODE_SIZE (regno_save_mode[i][j]), 0); + + /* Setup single word save area just in case... */ + for (k = 0; k < j; k++) + { + /* This should not depend on WORDS_BIG_ENDIAN. + The order of words in regs is the same as in memory. */ + rtx temp = gen_rtx (MEM, regno_save_mode[i+k][1], + XEXP (regno_save_mem[i][j], 0)); + + regno_save_mem[i+k][1] + = adj_offsettable_operand (temp, k * UNITS_PER_WORD); + } + *pchanged = 1; + } + } + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + for (j = 1; j <= MOVE_MAX / UNITS_PER_WORD; j++) + if (regno_save_mem[i][j] != 0) + ok &= strict_memory_address_p (GET_MODE (regno_save_mem[i][j]), + XEXP (eliminate_regs (regno_save_mem[i][j], 0, NULL_RTX), 0)); + + return ok; +} + +/* Find the places where hard regs are live across calls and save them. + + INSN_MODE is the mode to assign to any insns that we add. This is used + by reload to determine whether or not reloads or register eliminations + need be done on these insns. */ + +void +save_call_clobbered_regs (insn_mode) + enum machine_mode insn_mode; +{ + rtx insn; + int b; + + for (b = 0; b < n_basic_blocks; b++) + { + regset regs_live = basic_block_live_at_start[b]; + rtx prev_block_last = PREV_INSN (basic_block_head[b]); + REGSET_ELT_TYPE bit; + int offset, i, j; + int regno; + + /* Compute hard regs live at start of block -- this is the + real hard regs marked live, plus live pseudo regs that + have been renumbered to hard regs. No registers have yet been + saved because we restore all of them before the end of the basic + block. */ + +#ifdef HARD_REG_SET + hard_regs_live = *regs_live; +#else + COPY_HARD_REG_SET (hard_regs_live, regs_live); +#endif + + CLEAR_HARD_REG_SET (hard_regs_saved); + CLEAR_HARD_REG_SET (hard_regs_need_restore); + n_regs_saved = 0; + + for (offset = 0, i = 0; offset < regset_size; offset++) + { + if (regs_live[offset] == 0) + i += REGSET_ELT_BITS; + else + for (bit = 1; bit && i < max_regno; bit <<= 1, i++) + if ((regs_live[offset] & bit) + && (regno = reg_renumber[i]) >= 0) + for (j = regno; + j < regno + HARD_REGNO_NREGS (regno, + PSEUDO_REGNO_MODE (i)); + j++) + SET_HARD_REG_BIT (hard_regs_live, j); + + } + + /* Now scan the insns in the block, keeping track of what hard + regs are live as we go. When we see a call, save the live + call-clobbered hard regs. */ + + for (insn = basic_block_head[b]; ; insn = NEXT_INSN (insn)) + { + RTX_CODE code = GET_CODE (insn); + + if (GET_RTX_CLASS (code) == 'i') + { + rtx link; + + /* If some registers have been saved, see if INSN references + any of them. We must restore them before the insn if so. */ + + if (n_regs_saved) + restore_referenced_regs (PATTERN (insn), insn, insn_mode); + + /* NB: the normal procedure is to first enliven any + registers set by insn, then deaden any registers that + had their last use at insn. This is incorrect now, + since multiple pseudos may have been mapped to the + same hard reg, and the death notes are ambiguous. So + it must be done in the other, safe, order. */ + + for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) + if (REG_NOTE_KIND (link) == REG_DEAD) + clear_reg_live (XEXP (link, 0)); + + /* When we reach a call, we need to save all registers that are + live, call-used, not fixed, and not already saved. We must + test at this point because registers that die in a CALL_INSN + are not live across the call and likewise for registers that + are born in the CALL_INSN. + + If registers are filled with parameters for this function, + and some of these are also being set by this function, then + they will not appear to die (no REG_DEAD note for them), + to check if in fact they do, collect the set registers in + hard_regs_live first. */ + + if (code == CALL_INSN) + { + HARD_REG_SET this_call_sets; + { + HARD_REG_SET old_hard_regs_live; + + /* Save the hard_regs_live information. */ + COPY_HARD_REG_SET (old_hard_regs_live, hard_regs_live); + + /* Now calculate hard_regs_live for this CALL_INSN + only. */ + CLEAR_HARD_REG_SET (hard_regs_live); + note_stores (PATTERN (insn), set_reg_live); + COPY_HARD_REG_SET (this_call_sets, hard_regs_live); + + /* Restore the hard_regs_live information. */ + COPY_HARD_REG_SET (hard_regs_live, old_hard_regs_live); + } + + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) + if (call_used_regs[regno] && ! call_fixed_regs[regno] + && TEST_HARD_REG_BIT (hard_regs_live, regno) + /* It must not be set by this instruction. */ + && ! TEST_HARD_REG_BIT (this_call_sets, regno) + && ! TEST_HARD_REG_BIT (hard_regs_saved, regno)) + regno += insert_save_restore (insn, 1, regno, + insn_mode, 0); + + /* Put the information for this CALL_INSN on top of what + we already had. */ + IOR_HARD_REG_SET (hard_regs_live, this_call_sets); + COPY_HARD_REG_SET (hard_regs_need_restore, hard_regs_saved); + + /* Must recompute n_regs_saved. */ + n_regs_saved = 0; + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) + if (TEST_HARD_REG_BIT (hard_regs_saved, regno)) + n_regs_saved++; + } + else + { + note_stores (PATTERN (insn), set_reg_live); +#ifdef AUTO_INC_DEC + for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) + if (REG_NOTE_KIND (link) == REG_INC) + set_reg_live (XEXP (link, 0), NULL_RTX); +#endif + } + + for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) + if (REG_NOTE_KIND (link) == REG_UNUSED) + clear_reg_live (XEXP (link, 0)); + } + + if (insn == basic_block_end[b]) + break; + } + + /* At the end of the basic block, we must restore any registers that + remain saved. If the last insn in the block is a JUMP_INSN, put + the restore before the insn, otherwise, put it after the insn. */ + + if (n_regs_saved) + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) + if (TEST_HARD_REG_BIT (hard_regs_need_restore, regno)) + regno += insert_save_restore ((GET_CODE (insn) == JUMP_INSN + ? insn : NEXT_INSN (insn)), 0, + regno, insn_mode, MOVE_MAX / UNITS_PER_WORD); + + /* If we added any insns at the start of the block, update the start + of the block to point at those insns. */ + basic_block_head[b] = NEXT_INSN (prev_block_last); + } +} + +/* Here from note_stores when an insn stores a value in a register. + Set the proper bit or bits in hard_regs_live. All pseudos that have + been assigned hard regs have had their register number changed already, + so we can ignore pseudos. */ + +static void +set_reg_live (reg, setter) + rtx reg, setter; +{ + register int regno, endregno, i; + enum machine_mode mode = GET_MODE (reg); + int word = 0; + + if (GET_CODE (reg) == SUBREG) + { + word = SUBREG_WORD (reg); + reg = SUBREG_REG (reg); + } + + if (GET_CODE (reg) != REG || REGNO (reg) >= FIRST_PSEUDO_REGISTER) + return; + + regno = REGNO (reg) + word; + endregno = regno + HARD_REGNO_NREGS (regno, mode); + + for (i = regno; i < endregno; i++) + { + SET_HARD_REG_BIT (hard_regs_live, i); + CLEAR_HARD_REG_BIT (hard_regs_saved, i); + CLEAR_HARD_REG_BIT (hard_regs_need_restore, i); + } +} + +/* Here when a REG_DEAD note records the last use of a reg. Clear + the appropriate bit or bits in hard_regs_live. Again we can ignore + pseudos. */ + +static void +clear_reg_live (reg) + rtx reg; +{ + register int regno, endregno, i; + + if (GET_CODE (reg) != REG || REGNO (reg) >= FIRST_PSEUDO_REGISTER) + return; + + regno = REGNO (reg); + endregno= regno + HARD_REGNO_NREGS (regno, GET_MODE (reg)); + + for (i = regno; i < endregno; i++) + { + CLEAR_HARD_REG_BIT (hard_regs_live, i); + CLEAR_HARD_REG_BIT (hard_regs_need_restore, i); + CLEAR_HARD_REG_BIT (hard_regs_saved, i); + } +} + +/* If any register currently residing in the save area is referenced in X, + which is part of INSN, emit code to restore the register in front of INSN. + INSN_MODE is the mode to assign to any insns that we add. */ + +static void +restore_referenced_regs (x, insn, insn_mode) + rtx x; + rtx insn; + enum machine_mode insn_mode; +{ + enum rtx_code code = GET_CODE (x); + char *fmt; + int i, j; + + if (code == CLOBBER) + return; + + if (code == REG) + { + int regno = REGNO (x); + + /* If this is a pseudo, scan its memory location, since it might + involve the use of another register, which might be saved. */ + + if (regno >= FIRST_PSEUDO_REGISTER + && reg_equiv_mem[regno] != 0) + restore_referenced_regs (XEXP (reg_equiv_mem[regno], 0), + insn, insn_mode); + else if (regno >= FIRST_PSEUDO_REGISTER + && reg_equiv_address[regno] != 0) + restore_referenced_regs (reg_equiv_address[regno], + insn, insn_mode); + + /* Otherwise if this is a hard register, restore any piece of it that + is currently saved. */ + + else if (regno < FIRST_PSEUDO_REGISTER) + { + int numregs = HARD_REGNO_NREGS (regno, GET_MODE (x)); + /* Save at most SAVEREGS at a time. This can not be larger than + MOVE_MAX, because that causes insert_save_restore to fail. */ + int saveregs = MIN (numregs, MOVE_MAX / UNITS_PER_WORD); + int endregno = regno + numregs; + + for (i = regno; i < endregno; i++) + if (TEST_HARD_REG_BIT (hard_regs_need_restore, i)) + i += insert_save_restore (insn, 0, i, insn_mode, saveregs); + } + + return; + } + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'e') + restore_referenced_regs (XEXP (x, i), insn, insn_mode); + else if (fmt[i] == 'E') + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + restore_referenced_regs (XVECEXP (x, i, j), insn, insn_mode); + } +} + +/* Insert a sequence of insns to save or restore, SAVE_P says which, + REGNO. Place these insns in front of INSN. INSN_MODE is the mode + to assign to these insns. MAXRESTORE is the maximum number of registers + which should be restored during this call (when SAVE_P == 0). It should + never be less than 1 since we only work with entire registers. + + Note that we have verified in init_caller_save that we can do this + with a simple SET, so use it. Set INSN_CODE to what we save there + since the address might not be valid so the insn might not be recognized. + These insns will be reloaded and have register elimination done by + find_reload, so we need not worry about that here. + + Return the extra number of registers saved. */ + +static int +insert_save_restore (insn, save_p, regno, insn_mode, maxrestore) + rtx insn; + int save_p; + int regno; + enum machine_mode insn_mode; + int maxrestore; +{ + rtx pat; + enum insn_code code; + int i, numregs; + + /* A common failure mode if register status is not correct in the RTL + is for this routine to be called with a REGNO we didn't expect to + save. That will cause us to write an insn with a (nil) SET_DEST + or SET_SRC. Instead of doing so and causing a crash later, check + for this common case and abort here instead. This will remove one + step in debugging such problems. */ + + if (regno_save_mem[regno][1] == 0) + abort (); + +#ifdef HAVE_cc0 + /* If INSN references CC0, put our insns in front of the insn that sets + CC0. This is always safe, since the only way we could be passed an + insn that references CC0 is for a restore, and doing a restore earlier + isn't a problem. We do, however, assume here that CALL_INSNs don't + reference CC0. Guard against non-INSN's like CODE_LABEL. */ + + if ((GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN) + && reg_referenced_p (cc0_rtx, PATTERN (insn))) + insn = prev_nonnote_insn (insn); +#endif + + /* Get the pattern to emit and update our status. */ + if (save_p) + { + int i, j, k; + int ok; + + /* See if we can save several registers with a single instruction. + Work backwards to the single register case. */ + for (i = MOVE_MAX / UNITS_PER_WORD; i > 0; i--) + { + ok = 1; + if (regno_save_mem[regno][i] != 0) + for (j = 0; j < i; j++) + { + if (! call_used_regs[regno + j] || call_fixed_regs[regno + j] + || ! TEST_HARD_REG_BIT (hard_regs_live, regno + j) + || TEST_HARD_REG_BIT (hard_regs_saved, regno + j)) + ok = 0; + } + else + continue; + + /* Must do this one save at a time */ + if (! ok) + continue; + + pat = gen_rtx (SET, VOIDmode, regno_save_mem[regno][i], + gen_rtx (REG, GET_MODE (regno_save_mem[regno][i]), regno)); + code = reg_save_code[regno][i]; + + /* Set hard_regs_saved for all the registers we saved. */ + for (k = 0; k < i; k++) + { + SET_HARD_REG_BIT (hard_regs_saved, regno + k); + SET_HARD_REG_BIT (hard_regs_need_restore, regno + k); + n_regs_saved++; + } + + numregs = i; + break; + } + } + else + { + int i, j, k; + int ok; + + /* See if we can restore `maxrestore' registers at once. Work + backwards to the single register case. */ + for (i = maxrestore; i > 0; i--) + { + ok = 1; + if (regno_save_mem[regno][i]) + for (j = 0; j < i; j++) + { + if (! TEST_HARD_REG_BIT (hard_regs_need_restore, regno + j)) + ok = 0; + } + else + continue; + + /* Must do this one restore at a time */ + if (! ok) + continue; + + pat = gen_rtx (SET, VOIDmode, + gen_rtx (REG, GET_MODE (regno_save_mem[regno][i]), + regno), + regno_save_mem[regno][i]); + code = reg_restore_code[regno][i]; + + + /* Clear status for all registers we restored. */ + for (k = 0; k < i; k++) + { + CLEAR_HARD_REG_BIT (hard_regs_need_restore, regno + k); + n_regs_saved--; + } + + numregs = i; + break; + } + } + /* Emit the insn and set the code and mode. */ + + insn = emit_insn_before (pat, insn); + PUT_MODE (insn, insn_mode); + INSN_CODE (insn) = code; + + /* Tell our callers how many extra registers we saved/restored */ + return numregs - 1; +} diff --git a/contrib/gcc/calls.c b/contrib/gcc/calls.c new file mode 100644 index 00000000000..ad05be4f7c0 --- /dev/null +++ b/contrib/gcc/calls.c @@ -0,0 +1,3203 @@ +/* Convert function calls to rtl insns, for GNU C compiler. + Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "rtl.h" +#include "tree.h" +#include "flags.h" +#include "expr.h" +#ifdef __STDC__ +#include +#else +#include +#endif +#include "insn-flags.h" + +/* Decide whether a function's arguments should be processed + from first to last or from last to first. + + They should if the stack and args grow in opposite directions, but + only if we have push insns. */ + +#ifdef PUSH_ROUNDING + +#if defined (STACK_GROWS_DOWNWARD) != defined (ARGS_GROW_DOWNWARD) +#define PUSH_ARGS_REVERSED /* If it's last to first */ +#endif + +#endif + +/* Like STACK_BOUNDARY but in units of bytes, not bits. */ +#define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) + +/* Data structure and subroutines used within expand_call. */ + +struct arg_data +{ + /* Tree node for this argument. */ + tree tree_value; + /* Mode for value; TYPE_MODE unless promoted. */ + enum machine_mode mode; + /* Current RTL value for argument, or 0 if it isn't precomputed. */ + rtx value; + /* Initially-compute RTL value for argument; only for const functions. */ + rtx initial_value; + /* Register to pass this argument in, 0 if passed on stack, or an + EXPR_LIST if the arg is to be copied into multiple different + registers. */ + rtx reg; + /* If REG was promoted from the actual mode of the argument expression, + indicates whether the promotion is sign- or zero-extended. */ + int unsignedp; + /* Number of registers to use. 0 means put the whole arg in registers. + Also 0 if not passed in registers. */ + int partial; + /* Non-zero if argument must be passed on stack. + Note that some arguments may be passed on the stack + even though pass_on_stack is zero, just because FUNCTION_ARG says so. + pass_on_stack identifies arguments that *cannot* go in registers. */ + int pass_on_stack; + /* Offset of this argument from beginning of stack-args. */ + struct args_size offset; + /* Similar, but offset to the start of the stack slot. Different from + OFFSET if this arg pads downward. */ + struct args_size slot_offset; + /* Size of this argument on the stack, rounded up for any padding it gets, + parts of the argument passed in registers do not count. + If REG_PARM_STACK_SPACE is defined, then register parms + are counted here as well. */ + struct args_size size; + /* Location on the stack at which parameter should be stored. The store + has already been done if STACK == VALUE. */ + rtx stack; + /* Location on the stack of the start of this argument slot. This can + differ from STACK if this arg pads downward. This location is known + to be aligned to FUNCTION_ARG_BOUNDARY. */ + rtx stack_slot; +#ifdef ACCUMULATE_OUTGOING_ARGS + /* Place that this stack area has been saved, if needed. */ + rtx save_area; +#endif +#ifdef STRICT_ALIGNMENT + /* If an argument's alignment does not permit direct copying into registers, + copy in smaller-sized pieces into pseudos. These are stored in a + block pointed to by this field. The next field says how many + word-sized pseudos we made. */ + rtx *aligned_regs; + int n_aligned_regs; +#endif +}; + +#ifdef ACCUMULATE_OUTGOING_ARGS +/* A vector of one char per byte of stack space. A byte if non-zero if + the corresponding stack location has been used. + This vector is used to prevent a function call within an argument from + clobbering any stack already set up. */ +static char *stack_usage_map; + +/* Size of STACK_USAGE_MAP. */ +static int highest_outgoing_arg_in_use; + +/* stack_arg_under_construction is nonzero when an argument may be + initialized with a constructor call (including a C function that + returns a BLKmode struct) and expand_call must take special action + to make sure the object being constructed does not overlap the + argument list for the constructor call. */ +int stack_arg_under_construction; +#endif + +static int calls_function PROTO((tree, int)); +static int calls_function_1 PROTO((tree, int)); +static void emit_call_1 PROTO((rtx, tree, tree, int, int, rtx, rtx, + int, rtx, int)); +static void store_one_arg PROTO ((struct arg_data *, rtx, int, int, + tree, int)); + +/* If WHICH is 1, return 1 if EXP contains a call to the built-in function + `alloca'. + + If WHICH is 0, return 1 if EXP contains a call to any function. + Actually, we only need return 1 if evaluating EXP would require pushing + arguments on the stack, but that is too difficult to compute, so we just + assume any function call might require the stack. */ + +static tree calls_function_save_exprs; + +static int +calls_function (exp, which) + tree exp; + int which; +{ + int val; + calls_function_save_exprs = 0; + val = calls_function_1 (exp, which); + calls_function_save_exprs = 0; + return val; +} + +static int +calls_function_1 (exp, which) + tree exp; + int which; +{ + register int i; + enum tree_code code = TREE_CODE (exp); + int type = TREE_CODE_CLASS (code); + int length = tree_code_length[(int) code]; + + /* If this code is language-specific, we don't know what it will do. */ + if ((int) code >= NUM_TREE_CODES) + return 1; + + /* Only expressions and references can contain calls. */ + if (type != 'e' && type != '<' && type != '1' && type != '2' && type != 'r' + && type != 'b') + return 0; + + switch (code) + { + case CALL_EXPR: + if (which == 0) + return 1; + else if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR + && (TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) + == FUNCTION_DECL)) + { + tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); + + if ((DECL_BUILT_IN (fndecl) + && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_ALLOCA) + || (DECL_SAVED_INSNS (fndecl) + && (FUNCTION_FLAGS (DECL_SAVED_INSNS (fndecl)) + & FUNCTION_FLAGS_CALLS_ALLOCA))) + return 1; + } + + /* Third operand is RTL. */ + length = 2; + break; + + case SAVE_EXPR: + if (SAVE_EXPR_RTL (exp) != 0) + return 0; + if (value_member (exp, calls_function_save_exprs)) + return 0; + calls_function_save_exprs = tree_cons (NULL_TREE, exp, + calls_function_save_exprs); + return (TREE_OPERAND (exp, 0) != 0 + && calls_function_1 (TREE_OPERAND (exp, 0), which)); + + case BLOCK: + { + register tree local; + + for (local = BLOCK_VARS (exp); local; local = TREE_CHAIN (local)) + if (DECL_INITIAL (local) != 0 + && calls_function_1 (DECL_INITIAL (local), which)) + return 1; + } + { + register tree subblock; + + for (subblock = BLOCK_SUBBLOCKS (exp); + subblock; + subblock = TREE_CHAIN (subblock)) + if (calls_function_1 (subblock, which)) + return 1; + } + return 0; + + case METHOD_CALL_EXPR: + length = 3; + break; + + case WITH_CLEANUP_EXPR: + length = 1; + break; + + case RTL_EXPR: + return 0; + } + + for (i = 0; i < length; i++) + if (TREE_OPERAND (exp, i) != 0 + && calls_function_1 (TREE_OPERAND (exp, i), which)) + return 1; + + return 0; +} + +/* Force FUNEXP into a form suitable for the address of a CALL, + and return that as an rtx. Also load the static chain register + if FNDECL is a nested function. + + CALL_FUSAGE points to a variable holding the prospective + CALL_INSN_FUNCTION_USAGE information. */ + +rtx +prepare_call_address (funexp, fndecl, call_fusage, reg_parm_seen) + rtx funexp; + tree fndecl; + rtx *call_fusage; + int reg_parm_seen; +{ + rtx static_chain_value = 0; + + funexp = protect_from_queue (funexp, 0); + + if (fndecl != 0) + /* Get possible static chain value for nested function in C. */ + static_chain_value = lookup_static_chain (fndecl); + + /* Make a valid memory address and copy constants thru pseudo-regs, + but not for a constant address if -fno-function-cse. */ + if (GET_CODE (funexp) != SYMBOL_REF) + funexp = +#ifdef SMALL_REGISTER_CLASSES + /* If we are using registers for parameters, force the + function address into a register now. */ + reg_parm_seen ? force_not_mem (memory_address (FUNCTION_MODE, funexp)) + : +#endif + memory_address (FUNCTION_MODE, funexp); + else + { +#ifndef NO_FUNCTION_CSE + if (optimize && ! flag_no_function_cse) +#ifdef NO_RECURSIVE_FUNCTION_CSE + if (fndecl != current_function_decl) +#endif + funexp = force_reg (Pmode, funexp); +#endif + } + + if (static_chain_value != 0) + { + emit_move_insn (static_chain_rtx, static_chain_value); + + if (GET_CODE (static_chain_rtx) == REG) + use_reg (call_fusage, static_chain_rtx); + } + + return funexp; +} + +/* Generate instructions to call function FUNEXP, + and optionally pop the results. + The CALL_INSN is the first insn generated. + + FNDECL is the declaration node of the function. This is given ot the + macro RETURN_POPS_ARGS to determine whether this function pops its own args. + + FUNTYPE is the data type of the function, or, for a library call, + the identifier for the name of the call. This is given to the + macro RETURN_POPS_ARGS to determine whether this function pops its own args. + + STACK_SIZE is the number of bytes of arguments on the stack, + rounded up to STACK_BOUNDARY; zero if the size is variable. + This is both to put into the call insn and + to generate explicit popping code if necessary. + + STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value. + It is zero if this call doesn't want a structure value. + + NEXT_ARG_REG is the rtx that results from executing + FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1) + just after all the args have had their registers assigned. + This could be whatever you like, but normally it is the first + arg-register beyond those used for args in this call, + or 0 if all the arg-registers are used in this call. + It is passed on to `gen_call' so you can put this info in the call insn. + + VALREG is a hard register in which a value is returned, + or 0 if the call does not return a value. + + OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before + the args to this call were processed. + We restore `inhibit_defer_pop' to that value. + + CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that + denote registers used by the called function. + + IS_CONST is true if this is a `const' call. */ + +static void +emit_call_1 (funexp, fndecl, funtype, stack_size, struct_value_size, + next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage, + is_const) + rtx funexp; + tree fndecl; + tree funtype; + int stack_size; + int struct_value_size; + rtx next_arg_reg; + rtx valreg; + int old_inhibit_defer_pop; + rtx call_fusage; + int is_const; +{ + rtx stack_size_rtx = GEN_INT (stack_size); + rtx struct_value_size_rtx = GEN_INT (struct_value_size); + rtx call_insn; + int already_popped = 0; + + /* Ensure address is valid. SYMBOL_REF is already valid, so no need, + and we don't want to load it into a register as an optimization, + because prepare_call_address already did it if it should be done. */ + if (GET_CODE (funexp) != SYMBOL_REF) + funexp = memory_address (FUNCTION_MODE, funexp); + +#ifndef ACCUMULATE_OUTGOING_ARGS +#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop) + if (HAVE_call_pop && HAVE_call_value_pop + && (RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0 + || stack_size == 0)) + { + rtx n_pop = GEN_INT (RETURN_POPS_ARGS (fndecl, funtype, stack_size)); + rtx pat; + + /* If this subroutine pops its own args, record that in the call insn + if possible, for the sake of frame pointer elimination. */ + + if (valreg) + pat = gen_call_value_pop (valreg, + gen_rtx (MEM, FUNCTION_MODE, funexp), + stack_size_rtx, next_arg_reg, n_pop); + else + pat = gen_call_pop (gen_rtx (MEM, FUNCTION_MODE, funexp), + stack_size_rtx, next_arg_reg, n_pop); + + emit_call_insn (pat); + already_popped = 1; + } + else +#endif +#endif + +#if defined (HAVE_call) && defined (HAVE_call_value) + if (HAVE_call && HAVE_call_value) + { + if (valreg) + emit_call_insn (gen_call_value (valreg, + gen_rtx (MEM, FUNCTION_MODE, funexp), + stack_size_rtx, next_arg_reg, + NULL_RTX)); + else + emit_call_insn (gen_call (gen_rtx (MEM, FUNCTION_MODE, funexp), + stack_size_rtx, next_arg_reg, + struct_value_size_rtx)); + } + else +#endif + abort (); + + /* Find the CALL insn we just emitted. */ + for (call_insn = get_last_insn (); + call_insn && GET_CODE (call_insn) != CALL_INSN; + call_insn = PREV_INSN (call_insn)) + ; + + if (! call_insn) + abort (); + + /* Put the register usage information on the CALL. If there is already + some usage information, put ours at the end. */ + if (CALL_INSN_FUNCTION_USAGE (call_insn)) + { + rtx link; + + for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0; + link = XEXP (link, 1)) + ; + + XEXP (link, 1) = call_fusage; + } + else + CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage; + + /* If this is a const call, then set the insn's unchanging bit. */ + if (is_const) + CONST_CALL_P (call_insn) = 1; + + /* Restore this now, so that we do defer pops for this call's args + if the context of the call as a whole permits. */ + inhibit_defer_pop = old_inhibit_defer_pop; + +#ifndef ACCUMULATE_OUTGOING_ARGS + /* If returning from the subroutine does not automatically pop the args, + we need an instruction to pop them sooner or later. + Perhaps do it now; perhaps just record how much space to pop later. + + If returning from the subroutine does pop the args, indicate that the + stack pointer will be changed. */ + + if (stack_size != 0 && RETURN_POPS_ARGS (fndecl, funtype, stack_size) > 0) + { + if (!already_popped) + CALL_INSN_FUNCTION_USAGE (call_insn) = + gen_rtx (EXPR_LIST, VOIDmode, + gen_rtx (CLOBBER, VOIDmode, stack_pointer_rtx), + CALL_INSN_FUNCTION_USAGE (call_insn)); + stack_size -= RETURN_POPS_ARGS (fndecl, funtype, stack_size); + stack_size_rtx = GEN_INT (stack_size); + } + + if (stack_size != 0) + { + if (flag_defer_pop && inhibit_defer_pop == 0 && !is_const) + pending_stack_adjust += stack_size; + else + adjust_stack (stack_size_rtx); + } +#endif +} + +/* Generate all the code for a function call + and return an rtx for its value. + Store the value in TARGET (specified as an rtx) if convenient. + If the value is stored in TARGET then TARGET is returned. + If IGNORE is nonzero, then we ignore the value of the function call. */ + +rtx +expand_call (exp, target, ignore) + tree exp; + rtx target; + int ignore; +{ + /* List of actual parameters. */ + tree actparms = TREE_OPERAND (exp, 1); + /* RTX for the function to be called. */ + rtx funexp; + /* Tree node for the function to be called (not the address!). */ + tree funtree; + /* Data type of the function. */ + tree funtype; + /* Declaration of the function being called, + or 0 if the function is computed (not known by name). */ + tree fndecl = 0; + char *name = 0; + + /* Register in which non-BLKmode value will be returned, + or 0 if no value or if value is BLKmode. */ + rtx valreg; + /* Address where we should return a BLKmode value; + 0 if value not BLKmode. */ + rtx structure_value_addr = 0; + /* Nonzero if that address is being passed by treating it as + an extra, implicit first parameter. Otherwise, + it is passed by being copied directly into struct_value_rtx. */ + int structure_value_addr_parm = 0; + /* Size of aggregate value wanted, or zero if none wanted + or if we are using the non-reentrant PCC calling convention + or expecting the value in registers. */ + int struct_value_size = 0; + /* Nonzero if called function returns an aggregate in memory PCC style, + by returning the address of where to find it. */ + int pcc_struct_value = 0; + + /* Number of actual parameters in this call, including struct value addr. */ + int num_actuals; + /* Number of named args. Args after this are anonymous ones + and they must all go on the stack. */ + int n_named_args; + /* Count arg position in order args appear. */ + int argpos; + + /* Vector of information about each argument. + Arguments are numbered in the order they will be pushed, + not the order they are written. */ + struct arg_data *args; + + /* Total size in bytes of all the stack-parms scanned so far. */ + struct args_size args_size; + /* Size of arguments before any adjustments (such as rounding). */ + struct args_size original_args_size; + /* Data on reg parms scanned so far. */ + CUMULATIVE_ARGS args_so_far; + /* Nonzero if a reg parm has been scanned. */ + int reg_parm_seen; + /* Nonzero if this is an indirect function call. */ + int current_call_is_indirect = 0; + + /* Nonzero if we must avoid push-insns in the args for this call. + If stack space is allocated for register parameters, but not by the + caller, then it is preallocated in the fixed part of the stack frame. + So the entire argument block must then be preallocated (i.e., we + ignore PUSH_ROUNDING in that case). */ + +#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) + int must_preallocate = 1; +#else +#ifdef PUSH_ROUNDING + int must_preallocate = 0; +#else + int must_preallocate = 1; +#endif +#endif + + /* Size of the stack reserved for parameter registers. */ + int reg_parm_stack_space = 0; + + /* 1 if scanning parms front to back, -1 if scanning back to front. */ + int inc; + /* Address of space preallocated for stack parms + (on machines that lack push insns), or 0 if space not preallocated. */ + rtx argblock = 0; + + /* Nonzero if it is plausible that this is a call to alloca. */ + int may_be_alloca; + /* Nonzero if this is a call to setjmp or a related function. */ + int returns_twice; + /* Nonzero if this is a call to `longjmp'. */ + int is_longjmp; + /* Nonzero if this is a call to an inline function. */ + int is_integrable = 0; + /* Nonzero if this is a call to a `const' function. + Note that only explicitly named functions are handled as `const' here. */ + int is_const = 0; + /* Nonzero if this is a call to a `volatile' function. */ + int is_volatile = 0; +#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE) + /* Define the boundary of the register parm stack space that needs to be + save, if any. */ + int low_to_save = -1, high_to_save; + rtx save_area = 0; /* Place that it is saved */ +#endif + +#ifdef ACCUMULATE_OUTGOING_ARGS + int initial_highest_arg_in_use = highest_outgoing_arg_in_use; + char *initial_stack_usage_map = stack_usage_map; +#endif + + rtx old_stack_level = 0; + int old_pending_adj = 0; + int old_stack_arg_under_construction; + int old_inhibit_defer_pop = inhibit_defer_pop; + tree old_cleanups = cleanups_this_call; + rtx call_fusage = 0; + register tree p; + register int i, j; + + /* See if we can find a DECL-node for the actual function. + As a result, decide whether this is a call to an integrable function. */ + + p = TREE_OPERAND (exp, 0); + if (TREE_CODE (p) == ADDR_EXPR) + { + fndecl = TREE_OPERAND (p, 0); + if (TREE_CODE (fndecl) != FUNCTION_DECL) + fndecl = 0; + else + { + if (!flag_no_inline + && fndecl != current_function_decl + && DECL_INLINE (fndecl) + && DECL_SAVED_INSNS (fndecl)) + is_integrable = 1; + else if (! TREE_ADDRESSABLE (fndecl)) + { + /* In case this function later becomes inlinable, + record that there was already a non-inline call to it. + + Use abstraction instead of setting TREE_ADDRESSABLE + directly. */ + if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline) + { + warning_with_decl (fndecl, "can't inline call to `%s'"); + warning ("called from here"); + } + mark_addressable (fndecl); + } + + if (TREE_READONLY (fndecl) && ! TREE_THIS_VOLATILE (fndecl) + && TYPE_MODE (TREE_TYPE (exp)) != VOIDmode) + is_const = 1; + + if (TREE_THIS_VOLATILE (fndecl)) + is_volatile = 1; + } + } + + /* If we don't have specific function to call, see if we have a + constant or `noreturn' function from the type. */ + if (fndecl == 0) + { + is_const = TREE_READONLY (TREE_TYPE (TREE_TYPE (p))); + is_volatile = TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (p))); + } + +#ifdef REG_PARM_STACK_SPACE +#ifdef MAYBE_REG_PARM_STACK_SPACE + reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; +#else + reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); +#endif +#endif + + /* Warn if this value is an aggregate type, + regardless of which calling convention we are using for it. */ + if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (exp))) + warning ("function call has aggregate value"); + + /* Set up a place to return a structure. */ + + /* Cater to broken compilers. */ + if (aggregate_value_p (exp)) + { + /* This call returns a big structure. */ + is_const = 0; + +#ifdef PCC_STATIC_STRUCT_RETURN + { + pcc_struct_value = 1; + /* Easier than making that case work right. */ + if (is_integrable) + { + /* In case this is a static function, note that it has been + used. */ + if (! TREE_ADDRESSABLE (fndecl)) + mark_addressable (fndecl); + is_integrable = 0; + } + } +#else /* not PCC_STATIC_STRUCT_RETURN */ + { + struct_value_size = int_size_in_bytes (TREE_TYPE (exp)); + + if (target && GET_CODE (target) == MEM) + structure_value_addr = XEXP (target, 0); + else + { + /* Assign a temporary on the stack to hold the value. */ + + /* For variable-sized objects, we must be called with a target + specified. If we were to allocate space on the stack here, + we would have no way of knowing when to free it. */ + + if (struct_value_size < 0) + abort (); + + structure_value_addr + = XEXP (assign_stack_temp (BLKmode, struct_value_size, 1), 0); + MEM_IN_STRUCT_P (structure_value_addr) + = AGGREGATE_TYPE_P (TREE_TYPE (exp)); + target = 0; + } + } +#endif /* not PCC_STATIC_STRUCT_RETURN */ + } + + /* If called function is inline, try to integrate it. */ + + if (is_integrable) + { + rtx temp; + rtx before_call = get_last_insn (); + + temp = expand_inline_function (fndecl, actparms, target, + ignore, TREE_TYPE (exp), + structure_value_addr); + + /* If inlining succeeded, return. */ + if ((HOST_WIDE_INT) temp != -1) + { + if (flag_short_temps) + { + /* Perform all cleanups needed for the arguments of this + call (i.e. destructors in C++). It is ok if these + destructors clobber RETURN_VALUE_REG, because the + only time we care about this is when TARGET is that + register. But in C++, we take care to never return + that register directly. */ + expand_cleanups_to (old_cleanups); + } + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* If the outgoing argument list must be preserved, push + the stack before executing the inlined function if it + makes any calls. */ + + for (i = reg_parm_stack_space - 1; i >= 0; i--) + if (i < highest_outgoing_arg_in_use && stack_usage_map[i] != 0) + break; + + if (stack_arg_under_construction || i >= 0) + { + rtx insn = NEXT_INSN (before_call), seq; + + /* Look for a call in the inline function code. + If OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) is + nonzero then there is a call and it is not necessary + to scan the insns. */ + + if (OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)) == 0) + for (; insn; insn = NEXT_INSN (insn)) + if (GET_CODE (insn) == CALL_INSN) + break; + + if (insn) + { + /* Reserve enough stack space so that the largest + argument list of any function call in the inline + function does not overlap the argument list being + evaluated. This is usually an overestimate because + allocate_dynamic_stack_space reserves space for an + outgoing argument list in addition to the requested + space, but there is no way to ask for stack space such + that an argument list of a certain length can be + safely constructed. */ + + int adjust = OUTGOING_ARGS_SIZE (DECL_SAVED_INSNS (fndecl)); +#ifdef REG_PARM_STACK_SPACE + /* Add the stack space reserved for register arguments + in the inline function. What is really needed is the + largest value of reg_parm_stack_space in the inline + function, but that is not available. Using the current + value of reg_parm_stack_space is wrong, but gives + correct results on all supported machines. */ + adjust += reg_parm_stack_space; +#endif + start_sequence (); + emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX); + allocate_dynamic_stack_space (GEN_INT (adjust), + NULL_RTX, BITS_PER_UNIT); + seq = get_insns (); + end_sequence (); + emit_insns_before (seq, NEXT_INSN (before_call)); + emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX); + } + } +#endif + + /* If the result is equivalent to TARGET, return TARGET to simplify + checks in store_expr. They can be equivalent but not equal in the + case of a function that returns BLKmode. */ + if (temp != target && rtx_equal_p (temp, target)) + return target; + return temp; + } + + /* If inlining failed, mark FNDECL as needing to be compiled + separately after all. If function was declared inline, + give a warning. */ + if (DECL_INLINE (fndecl) && warn_inline && !flag_no_inline + && ! TREE_ADDRESSABLE (fndecl)) + { + warning_with_decl (fndecl, "inlining failed in call to `%s'"); + warning ("called from here"); + } + mark_addressable (fndecl); + } + + /* When calling a const function, we must pop the stack args right away, + so that the pop is deleted or moved with the call. */ + if (is_const) + NO_DEFER_POP; + + function_call_count++; + + if (fndecl && DECL_NAME (fndecl)) + name = IDENTIFIER_POINTER (DECL_NAME (fndecl)); + + /* On some machines (such as the PA) indirect calls have a different + calling convention than normal calls. FUNCTION_ARG in the target + description can look at current_call_is_indirect to determine which + calling convention to use. */ + current_call_is_indirect = (fndecl == 0); +#if 0 + = TREE_CODE (TREE_OPERAND (exp, 0)) == NON_LVALUE_EXPR ? 1 : 0; +#endif + +#if 0 + /* Unless it's a call to a specific function that isn't alloca, + if it has one argument, we must assume it might be alloca. */ + + may_be_alloca = + (!(fndecl != 0 && strcmp (name, "alloca")) + && actparms != 0 + && TREE_CHAIN (actparms) == 0); +#else + /* We assume that alloca will always be called by name. It + makes no sense to pass it as a pointer-to-function to + anything that does not understand its behavior. */ + may_be_alloca = + (name && ((IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 6 + && name[0] == 'a' + && ! strcmp (name, "alloca")) + || (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 16 + && name[0] == '_' + && ! strcmp (name, "__builtin_alloca")))); +#endif + + /* See if this is a call to a function that can return more than once + or a call to longjmp. */ + + returns_twice = 0; + is_longjmp = 0; + + if (name != 0 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) <= 15) + { + char *tname = name; + + /* Disregard prefix _, __ or __x. */ + if (name[0] == '_') + { + if (name[1] == '_' && name[2] == 'x') + tname += 3; + else if (name[1] == '_') + tname += 2; + else + tname += 1; + } + + if (tname[0] == 's') + { + returns_twice + = ((tname[1] == 'e' + && (! strcmp (tname, "setjmp") + || ! strcmp (tname, "setjmp_syscall"))) + || (tname[1] == 'i' + && ! strcmp (tname, "sigsetjmp")) + || (tname[1] == 'a' + && ! strcmp (tname, "savectx"))); + if (tname[1] == 'i' + && ! strcmp (tname, "siglongjmp")) + is_longjmp = 1; + } + else if ((tname[0] == 'q' && tname[1] == 's' + && ! strcmp (tname, "qsetjmp")) + || (tname[0] == 'v' && tname[1] == 'f' + && ! strcmp (tname, "vfork"))) + returns_twice = 1; + + else if (tname[0] == 'l' && tname[1] == 'o' + && ! strcmp (tname, "longjmp")) + is_longjmp = 1; + } + + if (may_be_alloca) + current_function_calls_alloca = 1; + + /* Don't let pending stack adjusts add up to too much. + Also, do all pending adjustments now + if there is any chance this might be a call to alloca. */ + + if (pending_stack_adjust >= 32 + || (pending_stack_adjust > 0 && may_be_alloca)) + do_pending_stack_adjust (); + + /* Operand 0 is a pointer-to-function; get the type of the function. */ + funtype = TREE_TYPE (TREE_OPERAND (exp, 0)); + if (TREE_CODE (funtype) != POINTER_TYPE) + abort (); + funtype = TREE_TYPE (funtype); + + /* Push the temporary stack slot level so that we can free any temporaries + we make. */ + push_temp_slots (); + + /* Start updating where the next arg would go. */ + INIT_CUMULATIVE_ARGS (args_so_far, funtype, NULL_RTX); + + /* If struct_value_rtx is 0, it means pass the address + as if it were an extra parameter. */ + if (structure_value_addr && struct_value_rtx == 0) + { + /* If structure_value_addr is a REG other than + virtual_outgoing_args_rtx, we can use always use it. If it + is not a REG, we must always copy it into a register. + If it is virtual_outgoing_args_rtx, we must copy it to another + register in some cases. */ + rtx temp = (GET_CODE (structure_value_addr) != REG +#ifdef ACCUMULATE_OUTGOING_ARGS + || (stack_arg_under_construction + && structure_value_addr == virtual_outgoing_args_rtx) +#endif + ? copy_addr_to_reg (structure_value_addr) + : structure_value_addr); + + actparms + = tree_cons (error_mark_node, + make_tree (build_pointer_type (TREE_TYPE (funtype)), + temp), + actparms); + structure_value_addr_parm = 1; + } + + /* Count the arguments and set NUM_ACTUALS. */ + for (p = actparms, i = 0; p; p = TREE_CHAIN (p)) i++; + num_actuals = i; + + /* Compute number of named args. + Normally, don't include the last named arg if anonymous args follow. + We do include the last named arg if STRICT_ARGUMENT_NAMING is defined. + (If no anonymous args follow, the result of list_length is actually + one too large. This is harmless.) + + If SETUP_INCOMING_VARARGS is defined and STRICT_ARGUMENT_NAMING is not, + this machine will be able to place unnamed args that were passed in + registers into the stack. So treat all args as named. This allows the + insns emitting for a specific argument list to be independent of the + function declaration. + + If SETUP_INCOMING_VARARGS is not defined, we do not have any reliable + way to pass unnamed args in registers, so we must force them into + memory. */ +#if !defined(SETUP_INCOMING_VARARGS) || defined(STRICT_ARGUMENT_NAMING) + if (TYPE_ARG_TYPES (funtype) != 0) + n_named_args + = (list_length (TYPE_ARG_TYPES (funtype)) +#ifndef STRICT_ARGUMENT_NAMING + /* Don't include the last named arg. */ + - 1 +#endif + /* Count the struct value address, if it is passed as a parm. */ + + structure_value_addr_parm); + else +#endif + /* If we know nothing, treat all args as named. */ + n_named_args = num_actuals; + + /* Make a vector to hold all the information about each arg. */ + args = (struct arg_data *) alloca (num_actuals * sizeof (struct arg_data)); + bzero ((char *) args, num_actuals * sizeof (struct arg_data)); + + args_size.constant = 0; + args_size.var = 0; + + /* In this loop, we consider args in the order they are written. + We fill up ARGS from the front or from the back if necessary + so that in any case the first arg to be pushed ends up at the front. */ + +#ifdef PUSH_ARGS_REVERSED + i = num_actuals - 1, inc = -1; + /* In this case, must reverse order of args + so that we compute and push the last arg first. */ +#else + i = 0, inc = 1; +#endif + + /* I counts args in order (to be) pushed; ARGPOS counts in order written. */ + for (p = actparms, argpos = 0; p; p = TREE_CHAIN (p), i += inc, argpos++) + { + tree type = TREE_TYPE (TREE_VALUE (p)); + int unsignedp; + enum machine_mode mode; + + args[i].tree_value = TREE_VALUE (p); + + /* Replace erroneous argument with constant zero. */ + if (type == error_mark_node || TYPE_SIZE (type) == 0) + args[i].tree_value = integer_zero_node, type = integer_type_node; + + /* If TYPE is a transparent union, pass things the way we would + pass the first field of the union. We have already verified that + the modes are the same. */ + if (TYPE_TRANSPARENT_UNION (type)) + type = TREE_TYPE (TYPE_FIELDS (type)); + + /* Decide where to pass this arg. + + args[i].reg is nonzero if all or part is passed in registers. + + args[i].partial is nonzero if part but not all is passed in registers, + and the exact value says how many words are passed in registers. + + args[i].pass_on_stack is nonzero if the argument must at least be + computed on the stack. It may then be loaded back into registers + if args[i].reg is nonzero. + + These decisions are driven by the FUNCTION_... macros and must agree + with those made by function.c. */ + + /* See if this argument should be passed by invisible reference. */ + if ((TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST + && contains_placeholder_p (TYPE_SIZE (type))) + || TREE_ADDRESSABLE (type) +#ifdef FUNCTION_ARG_PASS_BY_REFERENCE + || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, TYPE_MODE (type), + type, argpos < n_named_args) +#endif + ) + { +#ifdef FUNCTION_ARG_CALLEE_COPIES + if (FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (type), type, + argpos < n_named_args) + /* If it's in a register, we must make a copy of it too. */ + /* ??? Is this a sufficient test? Is there a better one? */ + && !(TREE_CODE (args[i].tree_value) == VAR_DECL + && REG_P (DECL_RTL (args[i].tree_value))) + && ! TREE_ADDRESSABLE (type)) + { + args[i].tree_value = build1 (ADDR_EXPR, + build_pointer_type (type), + args[i].tree_value); + type = build_pointer_type (type); + } + else +#endif + { + /* We make a copy of the object and pass the address to the + function being called. */ + rtx copy; + + if (TYPE_SIZE (type) == 0 + || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) + { + /* This is a variable-sized object. Make space on the stack + for it. */ + rtx size_rtx = expr_size (TREE_VALUE (p)); + + if (old_stack_level == 0) + { + emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX); + old_pending_adj = pending_stack_adjust; + pending_stack_adjust = 0; + } + + copy = gen_rtx (MEM, BLKmode, + allocate_dynamic_stack_space (size_rtx, + NULL_RTX, + TYPE_ALIGN (type))); + } + else + { + int size = int_size_in_bytes (type); + copy = assign_stack_temp (TYPE_MODE (type), size, 0); + } + + MEM_IN_STRUCT_P (copy) = AGGREGATE_TYPE_P (type); + + store_expr (args[i].tree_value, copy, 0); + + args[i].tree_value = build1 (ADDR_EXPR, + build_pointer_type (type), + make_tree (type, copy)); + type = build_pointer_type (type); + } + } + + mode = TYPE_MODE (type); + unsignedp = TREE_UNSIGNED (type); + +#ifdef PROMOTE_FUNCTION_ARGS + mode = promote_mode (type, mode, &unsignedp, 1); +#endif + + args[i].unsignedp = unsignedp; + args[i].mode = mode; + args[i].reg = FUNCTION_ARG (args_so_far, mode, type, + argpos < n_named_args); +#ifdef FUNCTION_ARG_PARTIAL_NREGS + if (args[i].reg) + args[i].partial + = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, type, + argpos < n_named_args); +#endif + + args[i].pass_on_stack = MUST_PASS_IN_STACK (mode, type); + + /* If FUNCTION_ARG returned an (expr_list (nil) FOO), it means that + we are to pass this arg in the register(s) designated by FOO, but + also to pass it in the stack. */ + if (args[i].reg && GET_CODE (args[i].reg) == EXPR_LIST + && XEXP (args[i].reg, 0) == 0) + args[i].pass_on_stack = 1, args[i].reg = XEXP (args[i].reg, 1); + + /* If this is an addressable type, we must preallocate the stack + since we must evaluate the object into its final location. + + If this is to be passed in both registers and the stack, it is simpler + to preallocate. */ + if (TREE_ADDRESSABLE (type) + || (args[i].pass_on_stack && args[i].reg != 0)) + must_preallocate = 1; + + /* If this is an addressable type, we cannot pre-evaluate it. Thus, + we cannot consider this function call constant. */ + if (TREE_ADDRESSABLE (type)) + is_const = 0; + + /* Compute the stack-size of this argument. */ + if (args[i].reg == 0 || args[i].partial != 0 +#ifdef REG_PARM_STACK_SPACE + || reg_parm_stack_space > 0 +#endif + || args[i].pass_on_stack) + locate_and_pad_parm (mode, type, +#ifdef STACK_PARMS_IN_REG_PARM_AREA + 1, +#else + args[i].reg != 0, +#endif + fndecl, &args_size, &args[i].offset, + &args[i].size); + +#ifndef ARGS_GROW_DOWNWARD + args[i].slot_offset = args_size; +#endif + +#ifndef REG_PARM_STACK_SPACE + /* If a part of the arg was put into registers, + don't include that part in the amount pushed. */ + if (! args[i].pass_on_stack) + args[i].size.constant -= ((args[i].partial * UNITS_PER_WORD) + / (PARM_BOUNDARY / BITS_PER_UNIT) + * (PARM_BOUNDARY / BITS_PER_UNIT)); +#endif + + /* Update ARGS_SIZE, the total stack space for args so far. */ + + args_size.constant += args[i].size.constant; + if (args[i].size.var) + { + ADD_PARM_SIZE (args_size, args[i].size.var); + } + + /* Since the slot offset points to the bottom of the slot, + we must record it after incrementing if the args grow down. */ +#ifdef ARGS_GROW_DOWNWARD + args[i].slot_offset = args_size; + + args[i].slot_offset.constant = -args_size.constant; + if (args_size.var) + { + SUB_PARM_SIZE (args[i].slot_offset, args_size.var); + } +#endif + + /* Increment ARGS_SO_FAR, which has info about which arg-registers + have been used, etc. */ + + FUNCTION_ARG_ADVANCE (args_so_far, TYPE_MODE (type), type, + argpos < n_named_args); + } + +#ifdef FINAL_REG_PARM_STACK_SPACE + reg_parm_stack_space = FINAL_REG_PARM_STACK_SPACE (args_size.constant, + args_size.var); +#endif + + /* Compute the actual size of the argument block required. The variable + and constant sizes must be combined, the size may have to be rounded, + and there may be a minimum required size. */ + + original_args_size = args_size; + if (args_size.var) + { + /* If this function requires a variable-sized argument list, don't try to + make a cse'able block for this call. We may be able to do this + eventually, but it is too complicated to keep track of what insns go + in the cse'able block and which don't. */ + + is_const = 0; + must_preallocate = 1; + + args_size.var = ARGS_SIZE_TREE (args_size); + args_size.constant = 0; + +#ifdef STACK_BOUNDARY + if (STACK_BOUNDARY != BITS_PER_UNIT) + args_size.var = round_up (args_size.var, STACK_BYTES); +#endif + +#ifdef REG_PARM_STACK_SPACE + if (reg_parm_stack_space > 0) + { + args_size.var + = size_binop (MAX_EXPR, args_size.var, + size_int (REG_PARM_STACK_SPACE (fndecl))); + +#ifndef OUTGOING_REG_PARM_STACK_SPACE + /* The area corresponding to register parameters is not to count in + the size of the block we need. So make the adjustment. */ + args_size.var + = size_binop (MINUS_EXPR, args_size.var, + size_int (reg_parm_stack_space)); +#endif + } +#endif + } + else + { +#ifdef STACK_BOUNDARY + args_size.constant = (((args_size.constant + (STACK_BYTES - 1)) + / STACK_BYTES) * STACK_BYTES); +#endif + +#ifdef REG_PARM_STACK_SPACE + args_size.constant = MAX (args_size.constant, + reg_parm_stack_space); +#ifdef MAYBE_REG_PARM_STACK_SPACE + if (reg_parm_stack_space == 0) + args_size.constant = 0; +#endif +#ifndef OUTGOING_REG_PARM_STACK_SPACE + args_size.constant -= reg_parm_stack_space; +#endif +#endif + } + + /* See if we have or want to preallocate stack space. + + If we would have to push a partially-in-regs parm + before other stack parms, preallocate stack space instead. + + If the size of some parm is not a multiple of the required stack + alignment, we must preallocate. + + If the total size of arguments that would otherwise create a copy in + a temporary (such as a CALL) is more than half the total argument list + size, preallocation is faster. + + Another reason to preallocate is if we have a machine (like the m88k) + where stack alignment is required to be maintained between every + pair of insns, not just when the call is made. However, we assume here + that such machines either do not have push insns (and hence preallocation + would occur anyway) or the problem is taken care of with + PUSH_ROUNDING. */ + + if (! must_preallocate) + { + int partial_seen = 0; + int copy_to_evaluate_size = 0; + + for (i = 0; i < num_actuals && ! must_preallocate; i++) + { + if (args[i].partial > 0 && ! args[i].pass_on_stack) + partial_seen = 1; + else if (partial_seen && args[i].reg == 0) + must_preallocate = 1; + + if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode + && (TREE_CODE (args[i].tree_value) == CALL_EXPR + || TREE_CODE (args[i].tree_value) == TARGET_EXPR + || TREE_CODE (args[i].tree_value) == COND_EXPR + || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))) + copy_to_evaluate_size + += int_size_in_bytes (TREE_TYPE (args[i].tree_value)); + } + + if (copy_to_evaluate_size * 2 >= args_size.constant + && args_size.constant > 0) + must_preallocate = 1; + } + + /* If the structure value address will reference the stack pointer, we must + stabilize it. We don't need to do this if we know that we are not going + to adjust the stack pointer in processing this call. */ + + if (structure_value_addr + && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr) + || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr)) + && (args_size.var +#ifndef ACCUMULATE_OUTGOING_ARGS + || args_size.constant +#endif + )) + structure_value_addr = copy_to_reg (structure_value_addr); + + /* If this function call is cse'able, precompute all the parameters. + Note that if the parameter is constructed into a temporary, this will + cause an additional copy because the parameter will be constructed + into a temporary location and then copied into the outgoing arguments. + If a parameter contains a call to alloca and this function uses the + stack, precompute the parameter. */ + + /* If we preallocated the stack space, and some arguments must be passed + on the stack, then we must precompute any parameter which contains a + function call which will store arguments on the stack. + Otherwise, evaluating the parameter may clobber previous parameters + which have already been stored into the stack. */ + + for (i = 0; i < num_actuals; i++) + if (is_const + || ((args_size.var != 0 || args_size.constant != 0) + && calls_function (args[i].tree_value, 1)) + || (must_preallocate && (args_size.var != 0 || args_size.constant != 0) + && calls_function (args[i].tree_value, 0))) + { + /* If this is an addressable type, we cannot pre-evaluate it. */ + if (TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value))) + abort (); + + push_temp_slots (); + + args[i].initial_value = args[i].value + = expand_expr (args[i].tree_value, NULL_RTX, VOIDmode, 0); + + preserve_temp_slots (args[i].value); + pop_temp_slots (); + + /* ANSI doesn't require a sequence point here, + but PCC has one, so this will avoid some problems. */ + emit_queue (); + + args[i].initial_value = args[i].value + = protect_from_queue (args[i].initial_value, 0); + + if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) != args[i].mode) + args[i].value + = convert_modes (args[i].mode, + TYPE_MODE (TREE_TYPE (args[i].tree_value)), + args[i].value, args[i].unsignedp); + } + + /* Now we are about to start emitting insns that can be deleted + if a libcall is deleted. */ + if (is_const) + start_sequence (); + + /* If we have no actual push instructions, or shouldn't use them, + make space for all args right now. */ + + if (args_size.var != 0) + { + if (old_stack_level == 0) + { + emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX); + old_pending_adj = pending_stack_adjust; + pending_stack_adjust = 0; +#ifdef ACCUMULATE_OUTGOING_ARGS + /* stack_arg_under_construction says whether a stack arg is + being constructed at the old stack level. Pushing the stack + gets a clean outgoing argument block. */ + old_stack_arg_under_construction = stack_arg_under_construction; + stack_arg_under_construction = 0; +#endif + } + argblock = push_block (ARGS_SIZE_RTX (args_size), 0, 0); + } + else + { + /* Note that we must go through the motions of allocating an argument + block even if the size is zero because we may be storing args + in the area reserved for register arguments, which may be part of + the stack frame. */ + + int needed = args_size.constant; + + /* Store the maximum argument space used. It will be pushed by the + prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow checking). */ + + if (needed > current_function_outgoing_args_size) + current_function_outgoing_args_size = needed; + + if (must_preallocate) + { +#ifdef ACCUMULATE_OUTGOING_ARGS + /* Since the stack pointer will never be pushed, it is possible for + the evaluation of a parm to clobber something we have already + written to the stack. Since most function calls on RISC machines + do not use the stack, this is uncommon, but must work correctly. + + Therefore, we save any area of the stack that was already written + and that we are using. Here we set up to do this by making a new + stack usage map from the old one. The actual save will be done + by store_one_arg. + + Another approach might be to try to reorder the argument + evaluations to avoid this conflicting stack usage. */ + +#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) + /* Since we will be writing into the entire argument area, the + map must be allocated for its entire size, not just the part that + is the responsibility of the caller. */ + needed += reg_parm_stack_space; +#endif + +#ifdef ARGS_GROW_DOWNWARD + highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, + needed + 1); +#else + highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, + needed); +#endif + stack_usage_map = (char *) alloca (highest_outgoing_arg_in_use); + + if (initial_highest_arg_in_use) + bcopy (initial_stack_usage_map, stack_usage_map, + initial_highest_arg_in_use); + + if (initial_highest_arg_in_use != highest_outgoing_arg_in_use) + bzero (&stack_usage_map[initial_highest_arg_in_use], + highest_outgoing_arg_in_use - initial_highest_arg_in_use); + needed = 0; + + /* The address of the outgoing argument list must not be copied to a + register here, because argblock would be left pointing to the + wrong place after the call to allocate_dynamic_stack_space below. + */ + + argblock = virtual_outgoing_args_rtx; + +#else /* not ACCUMULATE_OUTGOING_ARGS */ + if (inhibit_defer_pop == 0) + { + /* Try to reuse some or all of the pending_stack_adjust + to get this space. Maybe we can avoid any pushing. */ + if (needed > pending_stack_adjust) + { + needed -= pending_stack_adjust; + pending_stack_adjust = 0; + } + else + { + pending_stack_adjust -= needed; + needed = 0; + } + } + /* Special case this because overhead of `push_block' in this + case is non-trivial. */ + if (needed == 0) + argblock = virtual_outgoing_args_rtx; + else + argblock = push_block (GEN_INT (needed), 0, 0); + + /* We only really need to call `copy_to_reg' in the case where push + insns are going to be used to pass ARGBLOCK to a function + call in ARGS. In that case, the stack pointer changes value + from the allocation point to the call point, and hence + the value of VIRTUAL_OUTGOING_ARGS_RTX changes as well. + But might as well always do it. */ + argblock = copy_to_reg (argblock); +#endif /* not ACCUMULATE_OUTGOING_ARGS */ + } + } + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* The save/restore code in store_one_arg handles all cases except one: + a constructor call (including a C function returning a BLKmode struct) + to initialize an argument. */ + if (stack_arg_under_construction) + { +#if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) + rtx push_size = GEN_INT (reg_parm_stack_space + args_size.constant); +#else + rtx push_size = GEN_INT (args_size.constant); +#endif + if (old_stack_level == 0) + { + emit_stack_save (SAVE_BLOCK, &old_stack_level, NULL_RTX); + old_pending_adj = pending_stack_adjust; + pending_stack_adjust = 0; + /* stack_arg_under_construction says whether a stack arg is + being constructed at the old stack level. Pushing the stack + gets a clean outgoing argument block. */ + old_stack_arg_under_construction = stack_arg_under_construction; + stack_arg_under_construction = 0; + /* Make a new map for the new argument list. */ + stack_usage_map = (char *)alloca (highest_outgoing_arg_in_use); + bzero (stack_usage_map, highest_outgoing_arg_in_use); + highest_outgoing_arg_in_use = 0; + } + allocate_dynamic_stack_space (push_size, NULL_RTX, BITS_PER_UNIT); + } + /* If argument evaluation might modify the stack pointer, copy the + address of the argument list to a register. */ + for (i = 0; i < num_actuals; i++) + if (args[i].pass_on_stack) + { + argblock = copy_addr_to_reg (argblock); + break; + } +#endif + + + /* If we preallocated stack space, compute the address of each argument. + We need not ensure it is a valid memory address here; it will be + validized when it is used. */ + if (argblock) + { + rtx arg_reg = argblock; + int arg_offset = 0; + + if (GET_CODE (argblock) == PLUS) + arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1)); + + for (i = 0; i < num_actuals; i++) + { + rtx offset = ARGS_SIZE_RTX (args[i].offset); + rtx slot_offset = ARGS_SIZE_RTX (args[i].slot_offset); + rtx addr; + + /* Skip this parm if it will not be passed on the stack. */ + if (! args[i].pass_on_stack && args[i].reg != 0) + continue; + + if (GET_CODE (offset) == CONST_INT) + addr = plus_constant (arg_reg, INTVAL (offset)); + else + addr = gen_rtx (PLUS, Pmode, arg_reg, offset); + + addr = plus_constant (addr, arg_offset); + args[i].stack = gen_rtx (MEM, args[i].mode, addr); + MEM_IN_STRUCT_P (args[i].stack) + = AGGREGATE_TYPE_P (TREE_TYPE (args[i].tree_value)); + + if (GET_CODE (slot_offset) == CONST_INT) + addr = plus_constant (arg_reg, INTVAL (slot_offset)); + else + addr = gen_rtx (PLUS, Pmode, arg_reg, slot_offset); + + addr = plus_constant (addr, arg_offset); + args[i].stack_slot = gen_rtx (MEM, args[i].mode, addr); + } + } + +#ifdef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we push args individually in reverse order, perform stack alignment + before the first push (the last arg). */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + + /* Don't try to defer pops if preallocating, not even from the first arg, + since ARGBLOCK probably refers to the SP. */ + if (argblock) + NO_DEFER_POP; + + /* Get the function to call, in the form of RTL. */ + if (fndecl) + { + /* If this is the first use of the function, see if we need to + make an external definition for it. */ + if (! TREE_USED (fndecl)) + { + assemble_external (fndecl); + TREE_USED (fndecl) = 1; + } + + /* Get a SYMBOL_REF rtx for the function address. */ + funexp = XEXP (DECL_RTL (fndecl), 0); + } + else + /* Generate an rtx (probably a pseudo-register) for the address. */ + { + push_temp_slots (); + funexp = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode, 0); + pop_temp_slots (); /* FUNEXP can't be BLKmode */ + emit_queue (); + } + + /* Figure out the register where the value, if any, will come back. */ + valreg = 0; + if (TYPE_MODE (TREE_TYPE (exp)) != VOIDmode + && ! structure_value_addr) + { + if (pcc_struct_value) + valreg = hard_function_value (build_pointer_type (TREE_TYPE (exp)), + fndecl); + else + valreg = hard_function_value (TREE_TYPE (exp), fndecl); + } + + /* Precompute all register parameters. It isn't safe to compute anything + once we have started filling any specific hard regs. */ + reg_parm_seen = 0; + for (i = 0; i < num_actuals; i++) + if (args[i].reg != 0 && ! args[i].pass_on_stack) + { + reg_parm_seen = 1; + + if (args[i].value == 0) + { + push_temp_slots (); + args[i].value = expand_expr (args[i].tree_value, NULL_RTX, + VOIDmode, 0); + preserve_temp_slots (args[i].value); + pop_temp_slots (); + + /* ANSI doesn't require a sequence point here, + but PCC has one, so this will avoid some problems. */ + emit_queue (); + } + + /* If we are to promote the function arg to a wider mode, + do it now. */ + + if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value))) + args[i].value + = convert_modes (args[i].mode, + TYPE_MODE (TREE_TYPE (args[i].tree_value)), + args[i].value, args[i].unsignedp); + + /* If the value is expensive, and we are inside an appropriately + short loop, put the value into a pseudo and then put the pseudo + into the hard reg. + + For small register classes, also do this if this call uses + register parameters. This is to avoid reload conflicts while + loading the parameters registers. */ + + if ((! (GET_CODE (args[i].value) == REG + || (GET_CODE (args[i].value) == SUBREG + && GET_CODE (SUBREG_REG (args[i].value)) == REG))) + && args[i].mode != BLKmode + && rtx_cost (args[i].value, SET) > 2 +#ifdef SMALL_REGISTER_CLASSES + && (reg_parm_seen || preserve_subexpressions_p ()) +#else + && preserve_subexpressions_p () +#endif + ) + args[i].value = copy_to_mode_reg (args[i].mode, args[i].value); + } + +#if defined(ACCUMULATE_OUTGOING_ARGS) && defined(REG_PARM_STACK_SPACE) + /* The argument list is the property of the called routine and it + may clobber it. If the fixed area has been used for previous + parameters, we must save and restore it. + + Here we compute the boundary of the that needs to be saved, if any. */ + +#ifdef ARGS_GROW_DOWNWARD + for (i = 0; i < reg_parm_stack_space + 1; i++) +#else + for (i = 0; i < reg_parm_stack_space; i++) +#endif + { + if (i >= highest_outgoing_arg_in_use + || stack_usage_map[i] == 0) + continue; + + if (low_to_save == -1) + low_to_save = i; + + high_to_save = i; + } + + if (low_to_save >= 0) + { + int num_to_save = high_to_save - low_to_save + 1; + enum machine_mode save_mode + = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1); + rtx stack_area; + + /* If we don't have the required alignment, must do this in BLKmode. */ + if ((low_to_save & (MIN (GET_MODE_SIZE (save_mode), + BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1))) + save_mode = BLKmode; + + stack_area = gen_rtx (MEM, save_mode, + memory_address (save_mode, + +#ifdef ARGS_GROW_DOWNWARD + plus_constant (argblock, + - high_to_save) +#else + plus_constant (argblock, + low_to_save) +#endif + )); + if (save_mode == BLKmode) + { + save_area = assign_stack_temp (BLKmode, num_to_save, 0); + MEM_IN_STRUCT_P (save_area) = 0; + emit_block_move (validize_mem (save_area), stack_area, + GEN_INT (num_to_save), + PARM_BOUNDARY / BITS_PER_UNIT); + } + else + { + save_area = gen_reg_rtx (save_mode); + emit_move_insn (save_area, stack_area); + } + } +#endif + + + /* Now store (and compute if necessary) all non-register parms. + These come before register parms, since they can require block-moves, + which could clobber the registers used for register parms. + Parms which have partial registers are not stored here, + but we do preallocate space here if they want that. */ + + for (i = 0; i < num_actuals; i++) + if (args[i].reg == 0 || args[i].pass_on_stack) + store_one_arg (&args[i], argblock, may_be_alloca, + args_size.var != 0, fndecl, reg_parm_stack_space); + +#ifdef STRICT_ALIGNMENT + /* If we have a parm that is passed in registers but not in memory + and whose alignment does not permit a direct copy into registers, + make a group of pseudos that correspond to each register that we + will later fill. */ + + for (i = 0; i < num_actuals; i++) + if (args[i].reg != 0 && ! args[i].pass_on_stack + && args[i].mode == BLKmode + && (TYPE_ALIGN (TREE_TYPE (args[i].tree_value)) + < MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD))) + { + int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value)); + int big_endian_correction = 0; + + args[i].n_aligned_regs + = args[i].partial ? args[i].partial + : (bytes + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD; + + args[i].aligned_regs = (rtx *) alloca (sizeof (rtx) + * args[i].n_aligned_regs); + + /* Structures smaller than a word are aligned to the least significant + byte (to the right). On a BYTES_BIG_ENDIAN machine, this means we + must skip the empty high order bytes when calculating the bit + offset. */ + if (BYTES_BIG_ENDIAN && bytes < UNITS_PER_WORD) + big_endian_correction = (BITS_PER_WORD - (bytes * BITS_PER_UNIT)); + + for (j = 0; j < args[i].n_aligned_regs; j++) + { + rtx reg = gen_reg_rtx (word_mode); + rtx word = operand_subword_force (args[i].value, j, BLKmode); + int bitsize = TYPE_ALIGN (TREE_TYPE (args[i].tree_value)); + int bitpos; + + args[i].aligned_regs[j] = reg; + + /* Clobber REG and move each partword into it. Ensure we don't + go past the end of the structure. Note that the loop below + works because we've already verified that padding + and endianness are compatible. */ + + emit_insn (gen_rtx (CLOBBER, VOIDmode, reg)); + + for (bitpos = 0; + bitpos < BITS_PER_WORD && bytes > 0; + bitpos += bitsize, bytes -= bitsize / BITS_PER_UNIT) + { + int xbitpos = bitpos + big_endian_correction; + + store_bit_field (reg, bitsize, xbitpos, word_mode, + extract_bit_field (word, bitsize, bitpos, 1, + NULL_RTX, word_mode, + word_mode, + bitsize / BITS_PER_UNIT, + BITS_PER_WORD), + bitsize / BITS_PER_UNIT, BITS_PER_WORD); + } + } + } +#endif + + /* Now store any partially-in-registers parm. + This is the last place a block-move can happen. */ + if (reg_parm_seen) + for (i = 0; i < num_actuals; i++) + if (args[i].partial != 0 && ! args[i].pass_on_stack) + store_one_arg (&args[i], argblock, may_be_alloca, + args_size.var != 0, fndecl, reg_parm_stack_space); + +#ifndef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we pushed args in forward order, perform stack alignment + after pushing the last arg. */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + + /* If register arguments require space on the stack and stack space + was not preallocated, allocate stack space here for arguments + passed in registers. */ +#if ! defined(ACCUMULATE_OUTGOING_ARGS) && defined(OUTGOING_REG_PARM_STACK_SPACE) + if (must_preallocate == 0 && reg_parm_stack_space > 0) + anti_adjust_stack (GEN_INT (reg_parm_stack_space)); +#endif + + /* Pass the function the address in which to return a structure value. */ + if (structure_value_addr && ! structure_value_addr_parm) + { + emit_move_insn (struct_value_rtx, + force_reg (Pmode, + force_operand (structure_value_addr, + NULL_RTX))); + if (GET_CODE (struct_value_rtx) == REG) + use_reg (&call_fusage, struct_value_rtx); + } + + funexp = prepare_call_address (funexp, fndecl, &call_fusage, reg_parm_seen); + + /* Now do the register loads required for any wholly-register parms or any + parms which are passed both on the stack and in a register. Their + expressions were already evaluated. + + Mark all register-parms as living through the call, putting these USE + insns in the CALL_INSN_FUNCTION_USAGE field. */ + + for (i = 0; i < num_actuals; i++) + { + rtx list = args[i].reg; + int partial = args[i].partial; + + while (list) + { + rtx reg; + int nregs; + + /* Process each register that needs to get this arg. */ + if (GET_CODE (list) == EXPR_LIST) + reg = XEXP (list, 0), list = XEXP (list, 1); + else + reg = list, list = 0; + + /* Set to non-negative if must move a word at a time, even if just + one word (e.g, partial == 1 && mode == DFmode). Set to -1 if + we just use a normal move insn. This value can be zero if the + argument is a zero size structure with no fields. */ + nregs = (partial ? partial + : (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode + ? ((int_size_in_bytes (TREE_TYPE (args[i].tree_value)) + + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) + : -1)); + + /* If simple case, just do move. If normal partial, store_one_arg + has already loaded the register for us. In all other cases, + load the register(s) from memory. */ + + if (nregs == -1) + emit_move_insn (reg, args[i].value); + +#ifdef STRICT_ALIGNMENT + /* If we have pre-computed the values to put in the registers in + the case of non-aligned structures, copy them in now. */ + + else if (args[i].n_aligned_regs != 0) + for (j = 0; j < args[i].n_aligned_regs; j++) + emit_move_insn (gen_rtx (REG, word_mode, REGNO (reg) + j), + args[i].aligned_regs[j]); +#endif + + else if (args[i].partial == 0 || args[i].pass_on_stack) + move_block_to_reg (REGNO (reg), + validize_mem (args[i].value), nregs, + args[i].mode); + + if (nregs == -1) + use_reg (&call_fusage, reg); + else + use_regs (&call_fusage, REGNO (reg), nregs == 0 ? 1 : nregs); + + /* PARTIAL referred only to the first register, so clear it for the + next time. */ + partial = 0; + } + } + + /* Perform postincrements before actually calling the function. */ + emit_queue (); + + /* All arguments and registers used for the call must be set up by now! */ + + /* Generate the actual call instruction. */ + emit_call_1 (funexp, fndecl, funtype, args_size.constant, struct_value_size, + FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1), + valreg, old_inhibit_defer_pop, call_fusage, is_const); + + /* If call is cse'able, make appropriate pair of reg-notes around it. + Test valreg so we don't crash; may safely ignore `const' + if return type is void. */ + if (is_const && valreg != 0) + { + rtx note = 0; + rtx temp = gen_reg_rtx (GET_MODE (valreg)); + rtx insns; + + /* Construct an "equal form" for the value which mentions all the + arguments in order as well as the function name. */ +#ifdef PUSH_ARGS_REVERSED + for (i = 0; i < num_actuals; i++) + note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note); +#else + for (i = num_actuals - 1; i >= 0; i--) + note = gen_rtx (EXPR_LIST, VOIDmode, args[i].initial_value, note); +#endif + note = gen_rtx (EXPR_LIST, VOIDmode, funexp, note); + + insns = get_insns (); + end_sequence (); + + emit_libcall_block (insns, temp, valreg, note); + + valreg = temp; + } + else if (is_const) + { + /* Otherwise, just write out the sequence without a note. */ + rtx insns = get_insns (); + + end_sequence (); + emit_insns (insns); + } + + /* For calls to `setjmp', etc., inform flow.c it should complain + if nonvolatile values are live. */ + + if (returns_twice) + { + emit_note (name, NOTE_INSN_SETJMP); + current_function_calls_setjmp = 1; + } + + if (is_longjmp) + current_function_calls_longjmp = 1; + + /* Notice functions that cannot return. + If optimizing, insns emitted below will be dead. + If not optimizing, they will exist, which is useful + if the user uses the `return' command in the debugger. */ + + if (is_volatile || is_longjmp) + emit_barrier (); + + /* If value type not void, return an rtx for the value. */ + + /* If there are cleanups to be called, don't use a hard reg as target. */ + if (cleanups_this_call != old_cleanups + && target && REG_P (target) + && REGNO (target) < FIRST_PSEUDO_REGISTER) + target = 0; + + if (TYPE_MODE (TREE_TYPE (exp)) == VOIDmode + || ignore) + { + target = const0_rtx; + } + else if (structure_value_addr) + { + if (target == 0 || GET_CODE (target) != MEM) + { + target = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), + memory_address (TYPE_MODE (TREE_TYPE (exp)), + structure_value_addr)); + MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp)); + } + } + else if (pcc_struct_value) + { + if (target == 0) + { + /* We used leave the value in the location that it is + returned in, but that causes problems if it is used more + than once in one expression. Rather than trying to track + when a copy is required, we always copy when TARGET is + not specified. This calling sequence is only used on + a few machines and TARGET is usually nonzero. */ + if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode) + { + target = assign_stack_temp (BLKmode, + int_size_in_bytes (TREE_TYPE (exp)), + 0); + + MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp)); + + /* Save this temp slot around the pop below. */ + preserve_temp_slots (target); + } + else + target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp))); + } + + if (TYPE_MODE (TREE_TYPE (exp)) != BLKmode) + emit_move_insn (target, gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), + copy_to_reg (valreg))); + else + emit_block_move (target, gen_rtx (MEM, BLKmode, copy_to_reg (valreg)), + expr_size (exp), + TYPE_ALIGN (TREE_TYPE (exp)) / BITS_PER_UNIT); + } + else if (target && GET_MODE (target) == TYPE_MODE (TREE_TYPE (exp)) + && GET_MODE (target) == GET_MODE (valreg)) + /* TARGET and VALREG cannot be equal at this point because the latter + would not have REG_FUNCTION_VALUE_P true, while the former would if + it were referring to the same register. + + If they refer to the same register, this move will be a no-op, except + when function inlining is being done. */ + emit_move_insn (target, valreg); + else if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode) + { + /* Some machines (the PA for example) want to return all small + structures in registers regardless of the structure's alignment. + + Deal with them explicitly by copying from the return registers + into the target MEM locations. */ + int bytes = int_size_in_bytes (TREE_TYPE (exp)); + int n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; + int i; + enum machine_mode tmpmode; + rtx src, dst; + int bitsize = MIN (TYPE_ALIGN (TREE_TYPE (exp)), BITS_PER_WORD); + int bitpos, xbitpos, big_endian_correction = 0; + + if (target == 0) + { + target = assign_stack_temp (BLKmode, bytes, 0); + MEM_IN_STRUCT_P (target) = AGGREGATE_TYPE_P (TREE_TYPE (exp)); + preserve_temp_slots (target); + } + + /* This code assumes valreg is at least a full word. If it isn't, + copy it into a new pseudo which is a full word. */ + if (GET_MODE (valreg) != BLKmode + && GET_MODE_SIZE (GET_MODE (valreg)) < UNITS_PER_WORD) + valreg = convert_to_mode (SImode, valreg, + TREE_UNSIGNED (TREE_TYPE (exp))); + + /* Structures whose size is not a multiple of a word are aligned + to the least significant byte (to the right). On a BYTES_BIG_ENDIAN + machine, this means we must skip the empty high order bytes when + calculating the bit offset. */ + if (BYTES_BIG_ENDIAN && bytes % UNITS_PER_WORD) + big_endian_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) + * BITS_PER_UNIT)); + + /* Copy the structure BITSIZE bites at a time. + + We could probably emit more efficient code for machines + which do not use strict alignment, but it doesn't seem + worth the effort at the current time. */ + for (bitpos = 0, xbitpos = big_endian_correction; + bitpos < bytes * BITS_PER_UNIT; + bitpos += bitsize, xbitpos += bitsize) + { + + /* We need a new source operand each time xbitpos is on a + word boundary and when xbitpos == big_endian_correction + (the first time through). */ + if (xbitpos % BITS_PER_WORD == 0 + || xbitpos == big_endian_correction) + src = operand_subword_force (valreg, + xbitpos / BITS_PER_WORD, + BLKmode); + + /* We need a new destination operand each time bitpos is on + a word boundary. */ + if (bitpos % BITS_PER_WORD == 0) + dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, BLKmode); + + /* Use xbitpos for the source extraction (right justified) and + xbitpos for the destination store (left justified). */ + store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, word_mode, + extract_bit_field (src, bitsize, + xbitpos % BITS_PER_WORD, 1, + NULL_RTX, word_mode, + word_mode, + bitsize / BITS_PER_UNIT, + BITS_PER_WORD), + bitsize / BITS_PER_UNIT, BITS_PER_WORD); + } + } + else + target = copy_to_reg (valreg); + +#ifdef PROMOTE_FUNCTION_RETURN + /* If we promoted this return value, make the proper SUBREG. TARGET + might be const0_rtx here, so be careful. */ + if (GET_CODE (target) == REG + && TYPE_MODE (TREE_TYPE (exp)) != BLKmode + && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp))) + { + tree type = TREE_TYPE (exp); + int unsignedp = TREE_UNSIGNED (type); + + /* If we don't promote as expected, something is wrong. */ + if (GET_MODE (target) + != promote_mode (type, TYPE_MODE (type), &unsignedp, 1)) + abort (); + + target = gen_rtx (SUBREG, TYPE_MODE (type), target, 0); + SUBREG_PROMOTED_VAR_P (target) = 1; + SUBREG_PROMOTED_UNSIGNED_P (target) = unsignedp; + } +#endif + + if (flag_short_temps) + { + /* Perform all cleanups needed for the arguments of this call + (i.e. destructors in C++). */ + expand_cleanups_to (old_cleanups); + } + + /* If size of args is variable or this was a constructor call for a stack + argument, restore saved stack-pointer value. */ + + if (old_stack_level) + { + emit_stack_restore (SAVE_BLOCK, old_stack_level, NULL_RTX); + pending_stack_adjust = old_pending_adj; +#ifdef ACCUMULATE_OUTGOING_ARGS + stack_arg_under_construction = old_stack_arg_under_construction; + highest_outgoing_arg_in_use = initial_highest_arg_in_use; + stack_usage_map = initial_stack_usage_map; +#endif + } +#ifdef ACCUMULATE_OUTGOING_ARGS + else + { +#ifdef REG_PARM_STACK_SPACE + if (save_area) + { + enum machine_mode save_mode = GET_MODE (save_area); + rtx stack_area + = gen_rtx (MEM, save_mode, + memory_address (save_mode, +#ifdef ARGS_GROW_DOWNWARD + plus_constant (argblock, - high_to_save) +#else + plus_constant (argblock, low_to_save) +#endif + )); + + if (save_mode != BLKmode) + emit_move_insn (stack_area, save_area); + else + emit_block_move (stack_area, validize_mem (save_area), + GEN_INT (high_to_save - low_to_save + 1), + PARM_BOUNDARY / BITS_PER_UNIT); + } +#endif + + /* If we saved any argument areas, restore them. */ + for (i = 0; i < num_actuals; i++) + if (args[i].save_area) + { + enum machine_mode save_mode = GET_MODE (args[i].save_area); + rtx stack_area + = gen_rtx (MEM, save_mode, + memory_address (save_mode, + XEXP (args[i].stack_slot, 0))); + + if (save_mode != BLKmode) + emit_move_insn (stack_area, args[i].save_area); + else + emit_block_move (stack_area, validize_mem (args[i].save_area), + GEN_INT (args[i].size.constant), + PARM_BOUNDARY / BITS_PER_UNIT); + } + + highest_outgoing_arg_in_use = initial_highest_arg_in_use; + stack_usage_map = initial_stack_usage_map; + } +#endif + + /* If this was alloca, record the new stack level for nonlocal gotos. + Check for the handler slots since we might not have a save area + for non-local gotos. */ + + if (may_be_alloca && nonlocal_goto_handler_slot != 0) + emit_stack_save (SAVE_NONLOCAL, &nonlocal_goto_stack_level, NULL_RTX); + + pop_temp_slots (); + + return target; +} + +/* Output a library call to function FUN (a SYMBOL_REF rtx) + (emitting the queue unless NO_QUEUE is nonzero), + for a value of mode OUTMODE, + with NARGS different arguments, passed as alternating rtx values + and machine_modes to convert them to. + The rtx values should have been passed through protect_from_queue already. + + NO_QUEUE will be true if and only if the library call is a `const' call + which will be enclosed in REG_LIBCALL/REG_RETVAL notes; it is equivalent + to the variable is_const in expand_call. + + NO_QUEUE must be true for const calls, because if it isn't, then + any pending increment will be emitted between REG_LIBCALL/REG_RETVAL notes, + and will be lost if the libcall sequence is optimized away. + + NO_QUEUE must be false for non-const calls, because if it isn't, the + call insn will have its CONST_CALL_P bit set, and it will be incorrectly + optimized. For instance, the instruction scheduler may incorrectly + move memory references across the non-const call. */ + +void +emit_library_call VPROTO((rtx orgfun, int no_queue, enum machine_mode outmode, + int nargs, ...)) +{ +#ifndef __STDC__ + rtx orgfun; + int no_queue; + enum machine_mode outmode; + int nargs; +#endif + va_list p; + /* Total size in bytes of all the stack-parms scanned so far. */ + struct args_size args_size; + /* Size of arguments before any adjustments (such as rounding). */ + struct args_size original_args_size; + register int argnum; + rtx fun; + int inc; + int count; + rtx argblock = 0; + CUMULATIVE_ARGS args_so_far; + struct arg { rtx value; enum machine_mode mode; rtx reg; int partial; + struct args_size offset; struct args_size size; }; + struct arg *argvec; + int old_inhibit_defer_pop = inhibit_defer_pop; + rtx call_fusage = 0; + /* library calls are never indirect calls. */ + int current_call_is_indirect = 0; + + VA_START (p, nargs); + +#ifndef __STDC__ + orgfun = va_arg (p, rtx); + no_queue = va_arg (p, int); + outmode = va_arg (p, enum machine_mode); + nargs = va_arg (p, int); +#endif + + fun = orgfun; + + /* Copy all the libcall-arguments out of the varargs data + and into a vector ARGVEC. + + Compute how to pass each argument. We only support a very small subset + of the full argument passing conventions to limit complexity here since + library functions shouldn't have many args. */ + + argvec = (struct arg *) alloca (nargs * sizeof (struct arg)); + + INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun); + + args_size.constant = 0; + args_size.var = 0; + + push_temp_slots (); + + for (count = 0; count < nargs; count++) + { + rtx val = va_arg (p, rtx); + enum machine_mode mode = va_arg (p, enum machine_mode); + + /* We cannot convert the arg value to the mode the library wants here; + must do it earlier where we know the signedness of the arg. */ + if (mode == BLKmode + || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode)) + abort (); + + /* On some machines, there's no way to pass a float to a library fcn. + Pass it as a double instead. */ +#ifdef LIBGCC_NEEDS_DOUBLE + if (LIBGCC_NEEDS_DOUBLE && mode == SFmode) + val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode; +#endif + + /* There's no need to call protect_from_queue, because + either emit_move_insn or emit_push_insn will do that. */ + + /* Make sure it is a reasonable operand for a move or push insn. */ + if (GET_CODE (val) != REG && GET_CODE (val) != MEM + && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val))) + val = force_operand (val, NULL_RTX); + +#ifdef FUNCTION_ARG_PASS_BY_REFERENCE + if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1)) + { + /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can + be viewed as just an efficiency improvement. */ + rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0); + emit_move_insn (slot, val); + val = force_operand (XEXP (slot, 0), NULL_RTX); + mode = Pmode; + } +#endif + + argvec[count].value = val; + argvec[count].mode = mode; + + argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1); + if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST) + abort (); +#ifdef FUNCTION_ARG_PARTIAL_NREGS + argvec[count].partial + = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1); +#else + argvec[count].partial = 0; +#endif + + locate_and_pad_parm (mode, NULL_TREE, + argvec[count].reg && argvec[count].partial == 0, + NULL_TREE, &args_size, &argvec[count].offset, + &argvec[count].size); + + if (argvec[count].size.var) + abort (); + +#ifndef REG_PARM_STACK_SPACE + if (argvec[count].partial) + argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD; +#endif + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +#ifdef REG_PARM_STACK_SPACE + || 1 +#endif + ) + args_size.constant += argvec[count].size.constant; + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* If this arg is actually passed on the stack, it might be + clobbering something we already put there (this library call might + be inside the evaluation of an argument to a function whose call + requires the stack). This will only occur when the library call + has sufficient args to run out of argument registers. Abort in + this case; if this ever occurs, code must be added to save and + restore the arg slot. */ + + if (argvec[count].reg == 0 || argvec[count].partial != 0) + abort (); +#endif + + FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1); + } + va_end (p); + + /* If this machine requires an external definition for library + functions, write one out. */ + assemble_external_libcall (fun); + + original_args_size = args_size; +#ifdef STACK_BOUNDARY + args_size.constant = (((args_size.constant + (STACK_BYTES - 1)) + / STACK_BYTES) * STACK_BYTES); +#endif + +#ifdef REG_PARM_STACK_SPACE + args_size.constant = MAX (args_size.constant, + REG_PARM_STACK_SPACE (NULL_TREE)); +#ifndef OUTGOING_REG_PARM_STACK_SPACE + args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE); +#endif +#endif + + if (args_size.constant > current_function_outgoing_args_size) + current_function_outgoing_args_size = args_size.constant; + +#ifdef ACCUMULATE_OUTGOING_ARGS + args_size.constant = 0; +#endif + +#ifndef PUSH_ROUNDING + argblock = push_block (GEN_INT (args_size.constant), 0, 0); +#endif + +#ifdef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we push args individually in reverse order, perform stack alignment + before the first push (the last arg). */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + +#ifdef PUSH_ARGS_REVERSED + inc = -1; + argnum = nargs - 1; +#else + inc = 1; + argnum = 0; +#endif + + /* Push the args that need to be pushed. */ + + for (count = 0; count < nargs; count++, argnum += inc) + { + register enum machine_mode mode = argvec[argnum].mode; + register rtx val = argvec[argnum].value; + rtx reg = argvec[argnum].reg; + int partial = argvec[argnum].partial; + + if (! (reg != 0 && partial == 0)) + emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0, + argblock, GEN_INT (argvec[count].offset.constant)); + NO_DEFER_POP; + } + +#ifndef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we pushed args in forward order, perform stack alignment + after pushing the last arg. */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + +#ifdef PUSH_ARGS_REVERSED + argnum = nargs - 1; +#else + argnum = 0; +#endif + + fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0); + + /* Now load any reg parms into their regs. */ + + for (count = 0; count < nargs; count++, argnum += inc) + { + register enum machine_mode mode = argvec[argnum].mode; + register rtx val = argvec[argnum].value; + rtx reg = argvec[argnum].reg; + int partial = argvec[argnum].partial; + + if (reg != 0 && partial == 0) + emit_move_insn (reg, val); + NO_DEFER_POP; + } + + /* For version 1.37, try deleting this entirely. */ + if (! no_queue) + emit_queue (); + + /* Any regs containing parms remain in use through the call. */ + for (count = 0; count < nargs; count++) + if (argvec[count].reg != 0) + use_reg (&call_fusage, argvec[count].reg); + + /* Don't allow popping to be deferred, since then + cse'ing of library calls could delete a call and leave the pop. */ + NO_DEFER_POP; + + /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which + will set inhibit_defer_pop to that value. */ + + emit_call_1 (fun, + get_identifier (XSTR (orgfun, 0)), + get_identifier (XSTR (orgfun, 0)), args_size.constant, 0, + FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1), + outmode != VOIDmode ? hard_libcall_value (outmode) : NULL_RTX, + old_inhibit_defer_pop + 1, call_fusage, no_queue); + + pop_temp_slots (); + + /* Now restore inhibit_defer_pop to its actual original value. */ + OK_DEFER_POP; +} + +/* Like emit_library_call except that an extra argument, VALUE, + comes second and says where to store the result. + (If VALUE is zero, this function chooses a convenient way + to return the value. + + This function returns an rtx for where the value is to be found. + If VALUE is nonzero, VALUE is returned. */ + +rtx +emit_library_call_value VPROTO((rtx orgfun, rtx value, int no_queue, + enum machine_mode outmode, int nargs, ...)) +{ +#ifndef __STDC__ + rtx orgfun; + rtx value; + int no_queue; + enum machine_mode outmode; + int nargs; +#endif + va_list p; + /* Total size in bytes of all the stack-parms scanned so far. */ + struct args_size args_size; + /* Size of arguments before any adjustments (such as rounding). */ + struct args_size original_args_size; + register int argnum; + rtx fun; + int inc; + int count; + rtx argblock = 0; + CUMULATIVE_ARGS args_so_far; + struct arg { rtx value; enum machine_mode mode; rtx reg; int partial; + struct args_size offset; struct args_size size; }; + struct arg *argvec; + int old_inhibit_defer_pop = inhibit_defer_pop; + rtx call_fusage = 0; + rtx mem_value = 0; + int pcc_struct_value = 0; + int struct_value_size = 0; + /* library calls are never indirect calls. */ + int current_call_is_indirect = 0; + int is_const; + + VA_START (p, nargs); + +#ifndef __STDC__ + orgfun = va_arg (p, rtx); + value = va_arg (p, rtx); + no_queue = va_arg (p, int); + outmode = va_arg (p, enum machine_mode); + nargs = va_arg (p, int); +#endif + + is_const = no_queue; + fun = orgfun; + + /* If this kind of value comes back in memory, + decide where in memory it should come back. */ + if (aggregate_value_p (type_for_mode (outmode, 0))) + { +#ifdef PCC_STATIC_STRUCT_RETURN + rtx pointer_reg + = hard_function_value (build_pointer_type (type_for_mode (outmode, 0)), + 0); + mem_value = gen_rtx (MEM, outmode, pointer_reg); + pcc_struct_value = 1; + if (value == 0) + value = gen_reg_rtx (outmode); +#else /* not PCC_STATIC_STRUCT_RETURN */ + struct_value_size = GET_MODE_SIZE (outmode); + if (value != 0 && GET_CODE (value) == MEM) + mem_value = value; + else + mem_value = assign_stack_temp (outmode, GET_MODE_SIZE (outmode), 0); +#endif + + /* This call returns a big structure. */ + is_const = 0; + } + + /* ??? Unfinished: must pass the memory address as an argument. */ + + /* Copy all the libcall-arguments out of the varargs data + and into a vector ARGVEC. + + Compute how to pass each argument. We only support a very small subset + of the full argument passing conventions to limit complexity here since + library functions shouldn't have many args. */ + + argvec = (struct arg *) alloca ((nargs + 1) * sizeof (struct arg)); + + INIT_CUMULATIVE_ARGS (args_so_far, NULL_TREE, fun); + + args_size.constant = 0; + args_size.var = 0; + + count = 0; + + push_temp_slots (); + + /* If there's a structure value address to be passed, + either pass it in the special place, or pass it as an extra argument. */ + if (mem_value && struct_value_rtx == 0 && ! pcc_struct_value) + { + rtx addr = XEXP (mem_value, 0); + nargs++; + + /* Make sure it is a reasonable operand for a move or push insn. */ + if (GET_CODE (addr) != REG && GET_CODE (addr) != MEM + && ! (CONSTANT_P (addr) && LEGITIMATE_CONSTANT_P (addr))) + addr = force_operand (addr, NULL_RTX); + + argvec[count].value = addr; + argvec[count].mode = Pmode; + argvec[count].partial = 0; + + argvec[count].reg = FUNCTION_ARG (args_so_far, Pmode, NULL_TREE, 1); +#ifdef FUNCTION_ARG_PARTIAL_NREGS + if (FUNCTION_ARG_PARTIAL_NREGS (args_so_far, Pmode, NULL_TREE, 1)) + abort (); +#endif + + locate_and_pad_parm (Pmode, NULL_TREE, + argvec[count].reg && argvec[count].partial == 0, + NULL_TREE, &args_size, &argvec[count].offset, + &argvec[count].size); + + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +#ifdef REG_PARM_STACK_SPACE + || 1 +#endif + ) + args_size.constant += argvec[count].size.constant; + + FUNCTION_ARG_ADVANCE (args_so_far, Pmode, (tree)0, 1); + + count++; + } + + for (; count < nargs; count++) + { + rtx val = va_arg (p, rtx); + enum machine_mode mode = va_arg (p, enum machine_mode); + + /* We cannot convert the arg value to the mode the library wants here; + must do it earlier where we know the signedness of the arg. */ + if (mode == BLKmode + || (GET_MODE (val) != mode && GET_MODE (val) != VOIDmode)) + abort (); + + /* On some machines, there's no way to pass a float to a library fcn. + Pass it as a double instead. */ +#ifdef LIBGCC_NEEDS_DOUBLE + if (LIBGCC_NEEDS_DOUBLE && mode == SFmode) + val = convert_modes (DFmode, SFmode, val, 0), mode = DFmode; +#endif + + /* There's no need to call protect_from_queue, because + either emit_move_insn or emit_push_insn will do that. */ + + /* Make sure it is a reasonable operand for a move or push insn. */ + if (GET_CODE (val) != REG && GET_CODE (val) != MEM + && ! (CONSTANT_P (val) && LEGITIMATE_CONSTANT_P (val))) + val = force_operand (val, NULL_RTX); + +#ifdef FUNCTION_ARG_PASS_BY_REFERENCE + if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, mode, NULL_TREE, 1)) + { + /* We do not support FUNCTION_ARG_CALLEE_COPIES here since it can + be viewed as just an efficiency improvement. */ + rtx slot = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0); + emit_move_insn (slot, val); + val = XEXP (slot, 0); + mode = Pmode; + } +#endif + + argvec[count].value = val; + argvec[count].mode = mode; + + argvec[count].reg = FUNCTION_ARG (args_so_far, mode, NULL_TREE, 1); + if (argvec[count].reg && GET_CODE (argvec[count].reg) == EXPR_LIST) + abort (); +#ifdef FUNCTION_ARG_PARTIAL_NREGS + argvec[count].partial + = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, mode, NULL_TREE, 1); +#else + argvec[count].partial = 0; +#endif + + locate_and_pad_parm (mode, NULL_TREE, + argvec[count].reg && argvec[count].partial == 0, + NULL_TREE, &args_size, &argvec[count].offset, + &argvec[count].size); + + if (argvec[count].size.var) + abort (); + +#ifndef REG_PARM_STACK_SPACE + if (argvec[count].partial) + argvec[count].size.constant -= argvec[count].partial * UNITS_PER_WORD; +#endif + + if (argvec[count].reg == 0 || argvec[count].partial != 0 +#ifdef REG_PARM_STACK_SPACE + || 1 +#endif + ) + args_size.constant += argvec[count].size.constant; + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* If this arg is actually passed on the stack, it might be + clobbering something we already put there (this library call might + be inside the evaluation of an argument to a function whose call + requires the stack). This will only occur when the library call + has sufficient args to run out of argument registers. Abort in + this case; if this ever occurs, code must be added to save and + restore the arg slot. */ + + if (argvec[count].reg == 0 || argvec[count].partial != 0) + abort (); +#endif + + FUNCTION_ARG_ADVANCE (args_so_far, mode, (tree)0, 1); + } + va_end (p); + + /* If this machine requires an external definition for library + functions, write one out. */ + assemble_external_libcall (fun); + + original_args_size = args_size; +#ifdef STACK_BOUNDARY + args_size.constant = (((args_size.constant + (STACK_BYTES - 1)) + / STACK_BYTES) * STACK_BYTES); +#endif + +#ifdef REG_PARM_STACK_SPACE + args_size.constant = MAX (args_size.constant, + REG_PARM_STACK_SPACE (NULL_TREE)); +#ifndef OUTGOING_REG_PARM_STACK_SPACE + args_size.constant -= REG_PARM_STACK_SPACE (NULL_TREE); +#endif +#endif + + if (args_size.constant > current_function_outgoing_args_size) + current_function_outgoing_args_size = args_size.constant; + +#ifdef ACCUMULATE_OUTGOING_ARGS + args_size.constant = 0; +#endif + +#ifndef PUSH_ROUNDING + argblock = push_block (GEN_INT (args_size.constant), 0, 0); +#endif + +#ifdef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we push args individually in reverse order, perform stack alignment + before the first push (the last arg). */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + +#ifdef PUSH_ARGS_REVERSED + inc = -1; + argnum = nargs - 1; +#else + inc = 1; + argnum = 0; +#endif + + /* Push the args that need to be pushed. */ + + for (count = 0; count < nargs; count++, argnum += inc) + { + register enum machine_mode mode = argvec[argnum].mode; + register rtx val = argvec[argnum].value; + rtx reg = argvec[argnum].reg; + int partial = argvec[argnum].partial; + + if (! (reg != 0 && partial == 0)) + emit_push_insn (val, mode, NULL_TREE, NULL_RTX, 0, partial, reg, 0, + argblock, GEN_INT (argvec[count].offset.constant)); + NO_DEFER_POP; + } + +#ifndef PUSH_ARGS_REVERSED +#ifdef STACK_BOUNDARY + /* If we pushed args in forward order, perform stack alignment + after pushing the last arg. */ + if (argblock == 0) + anti_adjust_stack (GEN_INT (args_size.constant + - original_args_size.constant)); +#endif +#endif + +#ifdef PUSH_ARGS_REVERSED + argnum = nargs - 1; +#else + argnum = 0; +#endif + + fun = prepare_call_address (fun, NULL_TREE, &call_fusage, 0); + + /* Now load any reg parms into their regs. */ + + for (count = 0; count < nargs; count++, argnum += inc) + { + register enum machine_mode mode = argvec[argnum].mode; + register rtx val = argvec[argnum].value; + rtx reg = argvec[argnum].reg; + int partial = argvec[argnum].partial; + + if (reg != 0 && partial == 0) + emit_move_insn (reg, val); + NO_DEFER_POP; + } + +#if 0 + /* For version 1.37, try deleting this entirely. */ + if (! no_queue) + emit_queue (); +#endif + + /* Any regs containing parms remain in use through the call. */ + for (count = 0; count < nargs; count++) + if (argvec[count].reg != 0) + use_reg (&call_fusage, argvec[count].reg); + + /* Pass the function the address in which to return a structure value. */ + if (mem_value != 0 && struct_value_rtx != 0 && ! pcc_struct_value) + { + emit_move_insn (struct_value_rtx, + force_reg (Pmode, + force_operand (XEXP (mem_value, 0), + NULL_RTX))); + if (GET_CODE (struct_value_rtx) == REG) + use_reg (&call_fusage, struct_value_rtx); + } + + /* Don't allow popping to be deferred, since then + cse'ing of library calls could delete a call and leave the pop. */ + NO_DEFER_POP; + + /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which + will set inhibit_defer_pop to that value. */ + + emit_call_1 (fun, + get_identifier (XSTR (orgfun, 0)), + get_identifier (XSTR (orgfun, 0)), args_size.constant, + struct_value_size, + FUNCTION_ARG (args_so_far, VOIDmode, void_type_node, 1), + (outmode != VOIDmode && mem_value == 0 + ? hard_libcall_value (outmode) : NULL_RTX), + old_inhibit_defer_pop + 1, call_fusage, is_const); + + /* Now restore inhibit_defer_pop to its actual original value. */ + OK_DEFER_POP; + + pop_temp_slots (); + + /* Copy the value to the right place. */ + if (outmode != VOIDmode) + { + if (mem_value) + { + if (value == 0) + value = mem_value; + if (value != mem_value) + emit_move_insn (value, mem_value); + } + else if (value != 0) + emit_move_insn (value, hard_libcall_value (outmode)); + else + value = hard_libcall_value (outmode); + } + + return value; +} + +#if 0 +/* Return an rtx which represents a suitable home on the stack + given TYPE, the type of the argument looking for a home. + This is called only for BLKmode arguments. + + SIZE is the size needed for this target. + ARGS_ADDR is the address of the bottom of the argument block for this call. + OFFSET describes this parameter's offset into ARGS_ADDR. It is meaningless + if this machine uses push insns. */ + +static rtx +target_for_arg (type, size, args_addr, offset) + tree type; + rtx size; + rtx args_addr; + struct args_size offset; +{ + rtx target; + rtx offset_rtx = ARGS_SIZE_RTX (offset); + + /* We do not call memory_address if possible, + because we want to address as close to the stack + as possible. For non-variable sized arguments, + this will be stack-pointer relative addressing. */ + if (GET_CODE (offset_rtx) == CONST_INT) + target = plus_constant (args_addr, INTVAL (offset_rtx)); + else + { + /* I have no idea how to guarantee that this + will work in the presence of register parameters. */ + target = gen_rtx (PLUS, Pmode, args_addr, offset_rtx); + target = memory_address (QImode, target); + } + + return gen_rtx (MEM, BLKmode, target); +} +#endif + +/* Store a single argument for a function call + into the register or memory area where it must be passed. + *ARG describes the argument value and where to pass it. + + ARGBLOCK is the address of the stack-block for all the arguments, + or 0 on a machine where arguments are pushed individually. + + MAY_BE_ALLOCA nonzero says this could be a call to `alloca' + so must be careful about how the stack is used. + + VARIABLE_SIZE nonzero says that this was a variable-sized outgoing + argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate + that we need not worry about saving and restoring the stack. + + FNDECL is the declaration of the function we are calling. */ + +static void +store_one_arg (arg, argblock, may_be_alloca, variable_size, fndecl, + reg_parm_stack_space) + struct arg_data *arg; + rtx argblock; + int may_be_alloca; + int variable_size; + tree fndecl; + int reg_parm_stack_space; +{ + register tree pval = arg->tree_value; + rtx reg = 0; + int partial = 0; + int used = 0; + int i, lower_bound, upper_bound; + + if (TREE_CODE (pval) == ERROR_MARK) + return; + + /* Push a new temporary level for any temporaries we make for + this argument. */ + push_temp_slots (); + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* If this is being stored into a pre-allocated, fixed-size, stack area, + save any previous data at that location. */ + if (argblock && ! variable_size && arg->stack) + { +#ifdef ARGS_GROW_DOWNWARD + /* stack_slot is negative, but we want to index stack_usage_map */ + /* with positive values. */ + if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) + upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1; + else + abort (); + + lower_bound = upper_bound - arg->size.constant; +#else + if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) + lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)); + else + lower_bound = 0; + + upper_bound = lower_bound + arg->size.constant; +#endif + + for (i = lower_bound; i < upper_bound; i++) + if (stack_usage_map[i] +#ifdef REG_PARM_STACK_SPACE + /* Don't store things in the fixed argument area at this point; + it has already been saved. */ + && i > reg_parm_stack_space +#endif + ) + break; + + if (i != upper_bound) + { + /* We need to make a save area. See what mode we can make it. */ + enum machine_mode save_mode + = mode_for_size (arg->size.constant * BITS_PER_UNIT, MODE_INT, 1); + rtx stack_area + = gen_rtx (MEM, save_mode, + memory_address (save_mode, XEXP (arg->stack_slot, 0))); + + if (save_mode == BLKmode) + { + arg->save_area = assign_stack_temp (BLKmode, + arg->size.constant, 0); + MEM_IN_STRUCT_P (arg->save_area) + = AGGREGATE_TYPE_P (TREE_TYPE (arg->tree_value)); + preserve_temp_slots (arg->save_area); + emit_block_move (validize_mem (arg->save_area), stack_area, + GEN_INT (arg->size.constant), + PARM_BOUNDARY / BITS_PER_UNIT); + } + else + { + arg->save_area = gen_reg_rtx (save_mode); + emit_move_insn (arg->save_area, stack_area); + } + } + } +#endif + + /* If this isn't going to be placed on both the stack and in registers, + set up the register and number of words. */ + if (! arg->pass_on_stack) + reg = arg->reg, partial = arg->partial; + + if (reg != 0 && partial == 0) + /* Being passed entirely in a register. We shouldn't be called in + this case. */ + abort (); + +#ifdef STRICT_ALIGNMENT + /* If this arg needs special alignment, don't load the registers + here. */ + if (arg->n_aligned_regs != 0) + reg = 0; +#endif + + /* If this is being partially passed in a register, but multiple locations + are specified, we assume that the one partially used is the one that is + listed first. */ + if (reg && GET_CODE (reg) == EXPR_LIST) + reg = XEXP (reg, 0); + + /* If this is being passed partially in a register, we can't evaluate + it directly into its stack slot. Otherwise, we can. */ + if (arg->value == 0) + { +#ifdef ACCUMULATE_OUTGOING_ARGS + /* stack_arg_under_construction is nonzero if a function argument is + being evaluated directly into the outgoing argument list and + expand_call must take special action to preserve the argument list + if it is called recursively. + + For scalar function arguments stack_usage_map is sufficient to + determine which stack slots must be saved and restored. Scalar + arguments in general have pass_on_stack == 0. + + If this argument is initialized by a function which takes the + address of the argument (a C++ constructor or a C function + returning a BLKmode structure), then stack_usage_map is + insufficient and expand_call must push the stack around the + function call. Such arguments have pass_on_stack == 1. + + Note that it is always safe to set stack_arg_under_construction, + but this generates suboptimal code if set when not needed. */ + + if (arg->pass_on_stack) + stack_arg_under_construction++; +#endif + arg->value = expand_expr (pval, + (partial + || TYPE_MODE (TREE_TYPE (pval)) != arg->mode) + ? NULL_RTX : arg->stack, + VOIDmode, 0); + + /* If we are promoting object (or for any other reason) the mode + doesn't agree, convert the mode. */ + + if (arg->mode != TYPE_MODE (TREE_TYPE (pval))) + arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)), + arg->value, arg->unsignedp); + +#ifdef ACCUMULATE_OUTGOING_ARGS + if (arg->pass_on_stack) + stack_arg_under_construction--; +#endif + } + + /* Don't allow anything left on stack from computation + of argument to alloca. */ + if (may_be_alloca) + do_pending_stack_adjust (); + + if (arg->value == arg->stack) + /* If the value is already in the stack slot, we are done. */ + ; + else if (arg->mode != BLKmode) + { + register int size; + + /* Argument is a scalar, not entirely passed in registers. + (If part is passed in registers, arg->partial says how much + and emit_push_insn will take care of putting it there.) + + Push it, and if its size is less than the + amount of space allocated to it, + also bump stack pointer by the additional space. + Note that in C the default argument promotions + will prevent such mismatches. */ + + size = GET_MODE_SIZE (arg->mode); + /* Compute how much space the push instruction will push. + On many machines, pushing a byte will advance the stack + pointer by a halfword. */ +#ifdef PUSH_ROUNDING + size = PUSH_ROUNDING (size); +#endif + used = size; + + /* Compute how much space the argument should get: + round up to a multiple of the alignment for arguments. */ + if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval))) + used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1) + / (PARM_BOUNDARY / BITS_PER_UNIT)) + * (PARM_BOUNDARY / BITS_PER_UNIT)); + + /* This isn't already where we want it on the stack, so put it there. + This can either be done with push or copy insns. */ + emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, + 0, partial, reg, used - size, + argblock, ARGS_SIZE_RTX (arg->offset)); + } + else + { + /* BLKmode, at least partly to be pushed. */ + + register int excess; + rtx size_rtx; + + /* Pushing a nonscalar. + If part is passed in registers, PARTIAL says how much + and emit_push_insn will take care of putting it there. */ + + /* Round its size up to a multiple + of the allocation unit for arguments. */ + + if (arg->size.var != 0) + { + excess = 0; + size_rtx = ARGS_SIZE_RTX (arg->size); + } + else + { + /* PUSH_ROUNDING has no effect on us, because + emit_push_insn for BLKmode is careful to avoid it. */ + excess = (arg->size.constant - int_size_in_bytes (TREE_TYPE (pval)) + + partial * UNITS_PER_WORD); + size_rtx = expr_size (pval); + } + + emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx, + TYPE_ALIGN (TREE_TYPE (pval)) / BITS_PER_UNIT, partial, + reg, excess, argblock, ARGS_SIZE_RTX (arg->offset)); + } + + + /* Unless this is a partially-in-register argument, the argument is now + in the stack. + + ??? Note that this can change arg->value from arg->stack to + arg->stack_slot and it matters when they are not the same. + It isn't totally clear that this is correct in all cases. */ + if (partial == 0) + arg->value = arg->stack_slot; + + /* Once we have pushed something, pops can't safely + be deferred during the rest of the arguments. */ + NO_DEFER_POP; + + /* ANSI doesn't require a sequence point here, + but PCC has one, so this will avoid some problems. */ + emit_queue (); + + /* Free any temporary slots made in processing this argument. Show + that we might have taken the address of something and pushed that + as an operand. */ + preserve_temp_slots (NULL_RTX); + free_temp_slots (); + pop_temp_slots (); + +#ifdef ACCUMULATE_OUTGOING_ARGS + /* Now mark the segment we just used. */ + if (argblock && ! variable_size && arg->stack) + for (i = lower_bound; i < upper_bound; i++) + stack_usage_map[i] = 1; +#endif +} diff --git a/contrib/gcc/cccp.1 b/contrib/gcc/cccp.1 new file mode 100644 index 00000000000..8664c61f7be --- /dev/null +++ b/contrib/gcc/cccp.1 @@ -0,0 +1,681 @@ +.\" Copyright (c) 1991, 1992, 1993 Free Software Foundation \-*-Text-*- +.\" See section COPYING for conditions for redistribution +.TH cpp 1 "30apr1993" "GNU Tools" "GNU Tools" +.SH NAME +cccp, cpp \- The GNU C-Compatible Compiler Preprocessor. +.SH SYNOPSIS +.hy 0 +.na +.TP +.B cccp +.RB "[\|" \-$ "\|]" +.RB "[\|" \-A \c +.I predicate\c +.RB [ (\c +.I value\c +.BR ) ]\|] +.RB "[\|" \-C "\|]" +.RB "[\|" \-D \c +.I name\c +.RB [ =\c +.I definition\c +\&]\|] +.RB "[\|" \-dD "\|]" +.RB "[\|" \-dM "\|]" +.RB "[\|" "\-I\ "\c +.I directory\c +\&\|] +.RB "[\|" \-H "\|]" +.RB "[\|" \-I\- "\|]" +.RB "[\|" "\-imacros\ "\c +.I file\c +\&\|] +.RB "[\|" "\-include\ "\c +.I file\c +\&\|] +.RB "[\|" "\-idirafter\ "\c +.I dir\c +\&\|] +.RB "[\|" "\-iprefix\ "\c +.I prefix\c +\&\|] +.RB "[\|" "\-iwithprefix\ "\c +.I dir\c +\&\|] +.RB "[\|" \-lang\-c "\|]" +.RB "[\|" \-lang\-c++ "\|]" +.RB "[\|" \-lang\-objc "\|]" +.RB "[\|" \-lang\-objc++ "\|]" +.RB "[\|" \-lint "\|]" +.RB "[\|" \-M\ [ \-MG "\|]]" +.RB "[\|" \-MM\ [ \-MG "\|]]" +.RB "[\|" \-MD\ \c +.I file\ \c +\&\|] +.RB "[\|" \-MMD\ \c +.I file\ \c +\&\|] +.RB "[\|" \-nostdinc "\|]" +.RB "[\|" \-nostdinc++ "\|]" +.RB "[\|" \-P "\|]" +.RB "[\|" \-pedantic "\|]" +.RB "[\|" \-pedantic\-errors "\|]" +.RB "[\|" \-traditional "\|]" +.RB "[\|" \-trigraphs "\|]" +.RB "[\|" \-U \c +.I name\c +\&\|] +.RB "[\|" \-undef "\|]" +.RB "[\|" \-Wtrigraphs "\|]" +.RB "[\|" \-Wcomment "\|]" +.RB "[\|" \-Wall "\|]" +.RB "[\|" \-Wtraditional "\|]" +.br +.RB "[\|" \c +.I infile\c +.RB | \- "\|]" +.RB "[\|" \c +.I outfile\c +.RB | \- "\|]" +.ad b +.hy 1 +.SH DESCRIPTION +The C preprocessor is a \c +.I macro processor\c +\& that is used automatically by +the C compiler to transform your program before actual compilation. It is +called a macro processor because it allows you to define \c +.I macros\c +\&, +which are brief abbreviations for longer constructs. + +The C preprocessor provides four separate facilities that you can use as +you see fit: +.TP +\(bu +Inclusion of header files. These are files of declarations that can be +substituted into your program. +.TP +\(bu +Macro expansion. You can define \c +.I macros\c +\&, which are abbreviations +for arbitrary fragments of C code, and then the C preprocessor will +replace the macros with their definitions throughout the program. +.TP +\(bu +Conditional compilation. Using special preprocessing directives, you +can include or exclude parts of the program according to various +conditions. +.TP +\(bu +Line control. If you use a program to combine or rearrange source files into +an intermediate file which is then compiled, you can use line control +to inform the compiler of where each source line originally came from. +.PP +C preprocessors vary in some details. For a full explanation of the +GNU C preprocessor, see the +.B info +file `\|\c +.B cpp.info\c +\&\|', or the manual +.I The C Preprocessor\c +\&. Both of these are built from the same documentation source file, `\|\c +.B cpp.texinfo\c +\&\|'. The GNU C +preprocessor provides a superset of the features of ANSI Standard C. + +ANSI Standard C requires the rejection of many harmless constructs commonly +used by today's C programs. Such incompatibility would be inconvenient for +users, so the GNU C preprocessor is configured to accept these constructs +by default. Strictly speaking, to get ANSI Standard C, you must use the +options `\|\c +.B \-trigraphs\c +\&\|', `\|\c +.B \-undef\c +\&\|' and `\|\c +.B \-pedantic\c +\&\|', but in +practice the consequences of having strict ANSI Standard C make it +undesirable to do this. + +Most often when you use the C preprocessor you will not have to invoke it +explicitly: the C compiler will do so automatically. However, the +preprocessor is sometimes useful individually. + +When you call the preprocessor individually, either name +(\c +.B cpp\c +\& or \c +.B cccp\c +\&) will do\(em\&they are completely synonymous. + +The C preprocessor expects two file names as arguments, \c +.I infile\c +\& and +\c +.I outfile\c +\&. The preprocessor reads \c +.I infile\c +\& together with any other +files it specifies with `\|\c +.B #include\c +\&\|'. All the output generated by the +combined input files is written in \c +.I outfile\c +\&. + +Either \c +.I infile\c +\& or \c +.I outfile\c +\& may be `\|\c +.B \-\c +\&\|', which as \c +.I infile\c +\& +means to read from standard input and as \c +.I outfile\c +\& means to write to +standard output. Also, if \c +.I outfile\c +\& or both file names are omitted, +the standard output and standard input are used for the omitted file names. +.SH OPTIONS +Here is a table of command options accepted by the C preprocessor. +These options can also be given when compiling a C program; they are +passed along automatically to the preprocessor when it is invoked by +the compiler. +.TP +.B \-P +Inhibit generation of `\|\c +.B #\c +\&\|'-lines with line-number information in +the output from the preprocessor. This might be +useful when running the preprocessor on something that is not C code +and will be sent to a program which might be confused by the +`\|\c +.B #\c +\&\|'-lines. +.TP +.B \-C +Do not discard comments: pass them through to the output file. +Comments appearing in arguments of a macro call will be copied to the +output before the expansion of the macro call. +.TP +.B \-traditional +Try to imitate the behavior of old-fashioned C, as opposed to ANSI C. +.TP +.B \-trigraphs +Process ANSI standard trigraph sequences. These are three-character +sequences, all starting with `\|\c +.B ??\c +\&\|', that are defined by ANSI C to +stand for single characters. For example, `\|\c +.B ??/\c +\&\|' stands for +`\|\c +.BR "\e" "\|'," +so `\|\c +.B '??/n'\c +\&\|' is a character constant for a newline. +Strictly speaking, the GNU C preprocessor does not support all +programs in ANSI Standard C unless `\|\c +.B \-trigraphs\c +\&\|' is used, but if +you ever notice the difference it will be with relief. + +You don't want to know any more about trigraphs. +.TP +.B \-pedantic +Issue warnings required by the ANSI C standard in certain cases such +as when text other than a comment follows `\|\c +.B #else\c +\&\|' or `\|\c +.B #endif\c +\&\|'. +.TP +.B \-pedantic\-errors +Like `\|\c +.B \-pedantic\c +\&\|', except that errors are produced rather than +warnings. +.TP +.B \-Wtrigraphs +Warn if any trigraphs are encountered (assuming they are enabled). +.TP +.B \-Wcomment +.TP +.B \-Wcomments +Warn whenever a comment-start sequence `\|\c +.B /*\c +\&\|' appears in a comment. +(Both forms have the same effect). +.TP +.B \-Wall +Requests both `\|\c +.B \-Wtrigraphs\c +\&\|' and `\|\c +.B \-Wcomment\c +\&\|' (but not +`\|\c +.B \-Wtraditional\c +\&\|'). +.TP +.B \-Wtraditional +Warn about certain constructs that behave differently in traditional and +ANSI C. +.TP +.BI "\-I " directory\c +\& +Add the directory \c +.I directory\c +\& to the end of the list of +directories to be searched for header files. +This can be used to override a system header file, substituting your +own version, since these directories are searched before the system +header file directories. If you use more than one `\|\c +.B \-I\c +\&\|' option, +the directories are scanned in left-to-right order; the standard +system directories come after. +.TP +.B \-I\- +Any directories specified with `\|\c +.B \-I\c +\&\|' options before the `\|\c +.B \-I\-\c +\&\|' +option are searched only for the case of `\|\c +.B #include "\c +.I file\c +\&"\c +\&\|'; +they are not searched for `\|\c +.B #include <\c +.I file\c +\&>\c +\&\|'. + +If additional directories are specified with `\|\c +.B \-I\c +\&\|' options after +the `\|\c +.B \-I\-\c +\&\|', these directories are searched for all `\|\c +.B #include\c +\&\|' +directives. + +In addition, the `\|\c +.B \-I\-\c +\&\|' option inhibits the use of the current +directory as the first search directory for `\|\c +.B #include "\c +.I file\c +\&"\c +\&\|'. +Therefore, the current directory is searched only if it is requested +explicitly with `\|\c +.B \-I.\c +\&\|'. Specifying both `\|\c +.B \-I\-\c +\&\|' and `\|\c +.B \-I.\c +\&\|' +allows you to control precisely which directories are searched before +the current one and which are searched after. +.TP +.B \-nostdinc +Do not search the standard system directories for header files. +Only the directories you have specified with `\|\c +.B \-I\c +\&\|' options +(and the current directory, if appropriate) are searched. +.TP +.B \-nostdinc++ +Do not search for header files in the C++ specific standard +directories, but do still search the other standard directories. +(This option is used when building libg++.) +.TP +.BI "\-D " "name"\c +\& +Predefine \c +.I name\c +\& as a macro, with definition `\|\c +.B 1\c +\&\|'. +.TP +.BI "\-D " "name" = definition +\& +Predefine \c +.I name\c +\& as a macro, with definition \c +.I definition\c +\&. +There are no restrictions on the contents of \c +.I definition\c +\&, but if +you are invoking the preprocessor from a shell or shell-like program +you may need to use the shell's quoting syntax to protect characters +such as spaces that have a meaning in the shell syntax. If you use more than +one `\|\c +.B \-D\c +\&\|' for the same +.I name\c +\&, the rightmost definition takes effect. +.TP +.BI "\-U " "name"\c +\& +Do not predefine \c +.I name\c +\&. If both `\|\c +.B \-U\c +\&\|' and `\|\c +.B \-D\c +\&\|' are +specified for one name, the `\|\c +.B \-U\c +\&\|' beats the `\|\c +.B \-D\c +\&\|' and the name +is not predefined. +.TP +.B \-undef +Do not predefine any nonstandard macros. +.TP +.BI "\-A " "name(" value ) +Assert (in the same way as the \c +.B #assert\c +\& directive) +the predicate \c +.I name\c +\& with tokenlist \c +.I value\c +\&. Remember to escape or quote the parentheses on +shell command lines. + +You can use `\|\c +.B \-A-\c +\&\|' to disable all predefined assertions; it also +undefines all predefined macros. +.TP +.B \-dM +Instead of outputting the result of preprocessing, output a list of +`\|\c +.B #define\c +\&\|' directives for all the macros defined during the +execution of the preprocessor, including predefined macros. This gives +you a way of finding out what is predefined in your version of the +preprocessor; assuming you have no file `\|\c +.B foo.h\c +\&\|', the command +.sp +.br +touch\ foo.h;\ cpp\ \-dM\ foo.h +.br +.sp +will show the values of any predefined macros. +.TP +.B \-dD +Like `\|\c +.B \-dM\c +\&\|' except in two respects: it does \c +.I not\c +\& include the +predefined macros, and it outputs \c +.I both\c +\& the `\|\c +.B #define\c +\&\|' +directives and the result of preprocessing. Both kinds of output go to +the standard output file. +.PP +.TP +.BR \-M\ [ \-MG ] +Instead of outputting the result of preprocessing, output a rule +suitable for \c +.B make\c +\& describing the dependencies of the main +source file. The preprocessor outputs one \c +.B make\c +\& rule containing +the object file name for that source file, a colon, and the names of +all the included files. If there are many included files then the +rule is split into several lines using `\|\c +.B \\\\\c +\&\|'-newline. + +`\|\c +.B \-MG\c +\&\|' says to treat missing header files as generated files and assume \c +they live in the same directory as the source file. It must be specified \c +in addition to `\|\c +.B \-M\c +\&\|'. + +This feature is used in automatic updating of makefiles. +.TP +.BR \-MM\ [ \-MG ] +Like `\|\c +.B \-M\c +\&\|' but mention only the files included with `\|\c +.B #include +"\c +.I file\c +\&"\c +\&\|'. System header files included with `\|\c +.B #include +<\c +.I file\c +\&>\c +\&\|' are omitted. +.TP +.BI \-MD\ file +Like `\|\c +.B \-M\c +\&\|' but the dependency information is written to `\|\c +.I file\c +\&\|'. This is in addition to compiling the file as +specified\(em\&`\|\c +.B \-MD\c +\&\|' does not inhibit ordinary compilation the way +`\|\c +.B \-M\c +\&\|' does. + +When invoking gcc, do not specify the `\|\c +.I file\c +\&\|' argument. Gcc will create file names made by replacing `\|\c +.B .c\c +\&\|' with `\|\c +.B .d\c +\&\|' at the end of the input file names. + +In Mach, you can use the utility \c +.B md\c +\& to merge multiple files +into a single dependency file suitable for using with the `\|\c +.B make\c +\&\|' +command. +.TP +.BI \-MMD\ file +Like `\|\c +.B \-MD\c +\&\|' except mention only user header files, not system +header files. +.TP +.B \-H +Print the name of each header file used, in addition to other normal +activities. +.TP +.BI "\-imacros " "file"\c +\& +Process \c +.I file\c +\& as input, discarding the resulting output, before +processing the regular input file. Because the output generated from +\c +.I file\c +\& is discarded, the only effect of `\|\c +.B \-imacros \c +.I file\c +\&\c +\&\|' is to +make the macros defined in \c +.I file\c +\& available for use in the main +input. The preprocessor evaluates any `\|\c +.B \-D\c +\&\|' and `\|\c +.B \-U\c +\&\|' options +on the command line before processing `\|\c +.B \-imacros \c +.I file\c +\&\|' \c +\&. +.TP +.BI "\-include " "file" +Process +.I file +as input, and include all the resulting output, +before processing the regular input file. +.TP +.BI "-idirafter " "dir"\c +\& +Add the directory \c +.I dir\c +\& to the second include path. The directories +on the second include path are searched when a header file is not found +in any of the directories in the main include path (the one that +`\|\c +.B \-I\c +\&\|' adds to). +.TP +.BI "-iprefix " "prefix"\c +\& +Specify \c +.I prefix\c +\& as the prefix for subsequent `\|\c +.B \-iwithprefix\c +\&\|' +options. +.TP +.BI "-iwithprefix " "dir"\c +\& +Add a directory to the second include path. The directory's name is +made by concatenating \c +.I prefix\c +\& and \c +.I dir\c +\&, where \c +.I prefix\c +\& +was specified previously with `\|\c +.B \-iprefix\c +\&\|'. +.TP +.B \-lang-c +.TP +.B \-lang-c++ +.TP +.B \-lang-objc +.TP +.B \-lang-objc++ +Specify the source language. `\|\c +.B \-lang-c++\c +\&\|' makes the preprocessor +handle C++ comment syntax, and includes extra default include +directories for C++, and `\|\c +.B \-lang-objc\c +\&\|' enables the Objective C +`\|\c +.B #import\c +\&\|' directive. `\|\c +.B \-lang-c\c +\&\|' explicitly turns off both of +these extensions, and `\|\c +.B \-lang-objc++\c +\&\|' enables both. + +These options are generated by the compiler driver \c +.B gcc\c +\&, but not +passed from the `\|\c +.B gcc\c +\&\|' command line. +.TP +.B \-lint +Look for commands to the program checker \c +.B lint\c +\& embedded in +comments, and emit them preceded by `\|\c +.B #pragma lint\c +\&\|'. For example, +the comment `\|\c +.B /* NOTREACHED */\c +\&\|' becomes `\|\c +.B #pragma lint +NOTREACHED\c +\&\|'. + +This option is available only when you call \c +.B cpp\c +\& directly; +\c +.B gcc\c +\& will not pass it from its command line. +.TP +.B \-$ +Forbid the use of `\|\c +.B $\c +\&\|' in identifiers. This is required for ANSI +conformance. \c +.B gcc\c +\& automatically supplies this option to the +preprocessor if you specify `\|\c +.B \-ansi\c +\&\|', but \c +.B gcc\c +\& doesn't +recognize the `\|\c +.B \-$\c +\&\|' option itself\(em\&to use it without the other +effects of `\|\c +.B \-ansi\c +\&\|', you must call the preprocessor directly. +.SH "SEE ALSO" +.RB "`\|" Cpp "\|'" +entry in +.B info\c +\&; +.I The C Preprocessor\c +, Richard M. Stallman. +.br +.BR gcc "(" 1 ");" +.RB "`\|" Gcc "\|'" +entry in +.B info\c +\&; +.I +Using and Porting GNU CC (for version 2.0)\c +, Richard M. Stallman. +.SH COPYING +Copyright (c) 1991, 1992, 1993 Free Software Foundation, Inc. +.PP +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. +.PP +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. +.PP +Permission is granted to copy and distribute translations of this +manual into another language, under the above conditions for modified +versions, except that this permission notice may be included in +translations approved by the Free Software Foundation instead of in +the original English. diff --git a/contrib/gcc/cccp.c b/contrib/gcc/cccp.c new file mode 100644 index 00000000000..39f1a5ae7c8 --- /dev/null +++ b/contrib/gcc/cccp.c @@ -0,0 +1,10440 @@ +/* C Compatible Compiler Preprocessor (CCCP) + Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Written by Paul Rubin, June 1986 + Adapted to ANSI C, Richard Stallman, Jan 1987 + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +typedef unsigned char U_CHAR; + +#ifdef EMACS +#define NO_SHORTNAMES +#include "../src/config.h" +#ifdef open +#undef open +#undef read +#undef write +#endif /* open */ +#endif /* EMACS */ + +/* The macro EMACS is defined when cpp is distributed as part of Emacs, + for the sake of machines with limited C compilers. */ +#ifndef EMACS +#include "config.h" +#endif /* not EMACS */ + +#ifndef STANDARD_INCLUDE_DIR +#define STANDARD_INCLUDE_DIR "/usr/include" +#endif + +#ifndef LOCAL_INCLUDE_DIR +#define LOCAL_INCLUDE_DIR "/usr/local/include" +#endif + +#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */ +#ifdef __STDC__ +#define PTR_INT_TYPE ptrdiff_t +#else +#define PTR_INT_TYPE long +#endif +#endif /* 0 */ + +#include "pcp.h" + +/* By default, colon separates directories in a path. */ +#ifndef PATH_SEPARATOR +#define PATH_SEPARATOR ':' +#endif + +#include +#include +#include +#include +#include + +/* The following symbols should be autoconfigured: + HAVE_FCNTL_H + HAVE_STDLIB_H + HAVE_SYS_TIME_H + HAVE_UNISTD_H + STDC_HEADERS + TIME_WITH_SYS_TIME + In the mean time, we'll get by with approximations based + on existing GCC configuration symbols. */ + +#ifdef POSIX +# ifndef HAVE_STDLIB_H +# define HAVE_STDLIB_H 1 +# endif +# ifndef HAVE_UNISTD_H +# define HAVE_UNISTD_H 1 +# endif +# ifndef STDC_HEADERS +# define STDC_HEADERS 1 +# endif +#endif /* defined (POSIX) */ + +#if defined (POSIX) || (defined (USG) && !defined (VMS)) +# ifndef HAVE_FCNTL_H +# define HAVE_FCNTL_H 1 +# endif +#endif + +#ifndef RLIMIT_STACK +# include +#else +# if TIME_WITH_SYS_TIME +# include +# include +# else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +# endif +# include +#endif + +#if HAVE_FCNTL_H +# include +#endif + +/* This defines "errno" properly for VMS, and gives us EACCES. */ +#include + +#if HAVE_STDLIB_H +# include +#else +char *getenv (); +#endif + +#if STDC_HEADERS +# include +# ifndef bcmp +# define bcmp(a, b, n) memcmp (a, b, n) +# endif +# ifndef bcopy +# define bcopy(s, d, n) memcpy (d, s, n) +# endif +# ifndef bzero +# define bzero(d, n) memset (d, 0, n) +# endif +#else /* !STDC_HEADERS */ +char *index (); +char *rindex (); + +# if !defined (BSTRING) && (defined (USG) || defined (VMS)) + +# ifndef bcmp +# define bcmp my_bcmp +static int +my_bcmp (a, b, n) + register char *a; + register char *b; + register unsigned n; +{ + while (n-- > 0) + if (*a++ != *b++) + return 1; + + return 0; +} +# endif /* !defined (bcmp) */ + +# ifndef bcopy +# define bcopy my_bcopy +static void +my_bcopy (s, d, n) + register char *s; + register char *d; + register unsigned n; +{ + while (n-- > 0) + *d++ = *s++; +} +# endif /* !defined (bcopy) */ + +# ifndef bzero +# define bzero my_bzero +static void +my_bzero (b, length) + register char *b; + register unsigned length; +{ + while (length-- > 0) + *b++ = 0; +} +# endif /* !defined (bzero) */ + +# endif /* !defined (BSTRING) && (defined (USG) || defined (VMS)) */ +#endif /* ! STDC_HEADERS */ + +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) +# define __attribute__(x) +#endif + +#ifndef PROTO +# if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +# define PROTO(ARGS) ARGS +# else +# define PROTO(ARGS) () +# endif +#endif + +#if defined (__STDC__) && defined (HAVE_VPRINTF) +# include +# define VA_START(va_list, var) va_start (va_list, var) +# define PRINTF_ALIST(msg) char *msg, ... +# define PRINTF_DCL(msg) +# define PRINTF_PROTO(ARGS, m, n) PROTO (ARGS) __attribute__ ((format (printf, m, n))) +#else +# include +# define VA_START(va_list, var) va_start (va_list) +# define PRINTF_ALIST(msg) msg, va_alist +# define PRINTF_DCL(msg) char *msg; va_dcl +# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (printf, m, n))) +# define vfprintf(file, msg, args) \ + { \ + char *a0 = va_arg(args, char *); \ + char *a1 = va_arg(args, char *); \ + char *a2 = va_arg(args, char *); \ + char *a3 = va_arg(args, char *); \ + fprintf (file, msg, a0, a1, a2, a3); \ + } +#endif + +#define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2) +#define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3) +#define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4) + +#if HAVE_UNISTD_H +# include +#endif + +/* VMS-specific definitions */ +#ifdef VMS +#include +#define O_RDONLY 0 /* Open arg for Read/Only */ +#define O_WRONLY 1 /* Open arg for Write/Only */ +#define read(fd,buf,size) VMS_read (fd,buf,size) +#define write(fd,buf,size) VMS_write (fd,buf,size) +#define open(fname,mode,prot) VMS_open (fname,mode,prot) +#define fopen(fname,mode) VMS_fopen (fname,mode) +#define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile) +#define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt) +#define fstat(fd,stbuf) VMS_fstat (fd,stbuf) +static int VMS_fstat (), VMS_stat (); +static char * VMS_strncat (); +static int VMS_read (); +static int VMS_write (); +static int VMS_open (); +static FILE * VMS_fopen (); +static FILE * VMS_freopen (); +static void hack_vms_include_specification (); +typedef struct { unsigned :16, :16, :16; } vms_ino_t; +#define ino_t vms_ino_t +#define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */ +#ifdef __GNUC__ +#define BSTRING /* VMS/GCC supplies the bstring routines */ +#endif /* __GNUC__ */ +#endif /* VMS */ + +#ifndef O_RDONLY +#define O_RDONLY 0 +#endif + +#undef MIN +#undef MAX +#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) +#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) + +/* Find the largest host integer type and set its size and type. */ + +#ifndef HOST_BITS_PER_WIDE_INT + +#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG +#define HOST_WIDE_INT long +#else +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT +#define HOST_WIDE_INT int +#endif + +#endif + +#ifndef S_ISREG +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif + +#ifndef S_ISDIR +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + +/* Define a generic NULL if one hasn't already been defined. */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef GENERIC_PTR +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define GENERIC_PTR void * +#else +#define GENERIC_PTR char * +#endif +#endif + +#ifndef NULL_PTR +#define NULL_PTR ((GENERIC_PTR)0) +#endif + +#ifndef INCLUDE_LEN_FUDGE +#define INCLUDE_LEN_FUDGE 0 +#endif + +/* External declarations. */ + +extern char *version_string; +#ifndef VMS +#ifndef HAVE_STRERROR +extern int sys_nerr; +#if defined(bsd4_4) +extern const char *const sys_errlist[]; +#else +extern char *sys_errlist[]; +#endif +#else /* HAVE_STRERROR */ +char *strerror (); +#endif +#else /* VMS */ +char *strerror (int,...); +#endif +int parse_escape PROTO((char **)); +HOST_WIDE_INT parse_c_expression PROTO((char *)); + +#ifndef errno +extern int errno; +#endif + +/* Name under which this program was invoked. */ + +static char *progname; + +/* Nonzero means use extra default include directories for C++. */ + +static int cplusplus; + +/* Nonzero means handle cplusplus style comments */ + +static int cplusplus_comments; + +/* Nonzero means handle #import, for objective C. */ + +static int objc; + +/* Nonzero means this is an assembly file, and allow + unknown directives, which could be comments. */ + +static int lang_asm; + +/* Current maximum length of directory names in the search path + for include files. (Altered as we get more of them.) */ + +static int max_include_len; + +/* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */ + +static int for_lint = 0; + +/* Nonzero means copy comments into the output file. */ + +static int put_out_comments = 0; + +/* Nonzero means don't process the ANSI trigraph sequences. */ + +static int no_trigraphs = 0; + +/* Nonzero means print the names of included files rather than + the preprocessed output. 1 means just the #include "...", + 2 means #include <...> as well. */ + +static int print_deps = 0; + +/* Nonzero if missing .h files in -M output are assumed to be generated + files and not errors. */ + +static int print_deps_missing_files = 0; + +/* Nonzero means print names of header files (-H). */ + +static int print_include_names = 0; + +/* Nonzero means don't output line number information. */ + +static int no_line_directives; + +/* Nonzero means output the text in failing conditionals, + inside #failed ... #endfailed. */ + +static int output_conditionals; + +/* dump_only means inhibit output of the preprocessed text + and instead output the definitions of all user-defined + macros in a form suitable for use as input to cccp. + dump_names means pass #define and the macro name through to output. + dump_definitions means pass the whole definition (plus #define) through +*/ + +static enum {dump_none, dump_only, dump_names, dump_definitions} + dump_macros = dump_none; + +/* Nonzero means pass all #define and #undef directives which we actually + process through to the output stream. This feature is used primarily + to allow cc1 to record the #defines and #undefs for the sake of + debuggers which understand about preprocessor macros, but it may + also be useful with -E to figure out how symbols are defined, and + where they are defined. */ +static int debug_output = 0; + +/* Nonzero indicates special processing used by the pcp program. The + special effects of this mode are: + + Inhibit all macro expansion, except those inside #if directives. + + Process #define directives normally, and output their contents + to the output file. + + Output preconditions to pcp_outfile indicating all the relevant + preconditions for use of this file in a later cpp run. +*/ +static FILE *pcp_outfile; + +/* Nonzero means we are inside an IF during a -pcp run. In this mode + macro expansion is done, and preconditions are output for all macro + uses requiring them. */ +static int pcp_inside_if; + +/* Nonzero means never to include precompiled files. + This is 1 since there's no way now to make precompiled files, + so it's not worth testing for them. */ +static int no_precomp = 1; + +/* Nonzero means give all the error messages the ANSI standard requires. */ + +int pedantic; + +/* Nonzero means try to make failure to fit ANSI C an error. */ + +static int pedantic_errors; + +/* Nonzero means don't print warning messages. -w. */ + +static int inhibit_warnings = 0; + +/* Nonzero means warn if slash-star appears in a comment. */ + +static int warn_comments; + +/* Nonzero means warn if a macro argument is (or would be) + stringified with -traditional. */ + +static int warn_stringify; + +/* Nonzero means warn if there are any trigraphs. */ + +static int warn_trigraphs; + +/* Nonzero means warn if #import is used. */ + +static int warn_import = 1; + +/* Nonzero means turn warnings into errors. */ + +static int warnings_are_errors; + +/* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */ + +int traditional; + +/* Nonzero causes output not to be done, + but directives such as #define that have side effects + are still obeyed. */ + +static int no_output; + +/* Nonzero means this file was included with a -imacros or -include + command line and should not be recorded as an include file. */ + +static int no_record_file; + +/* Nonzero means that we have finished processing the command line options. + This flag is used to decide whether or not to issue certain errors + and/or warnings. */ + +static int done_initializing = 0; + +/* Line where a newline was first seen in a string constant. */ + +static int multiline_string_line = 0; + +/* I/O buffer structure. + The `fname' field is nonzero for source files and #include files + and for the dummy text used for -D and -U. + It is zero for rescanning results of macro expansion + and for expanding macro arguments. */ +#define INPUT_STACK_MAX 400 +static struct file_buf { + char *fname; + /* Filename specified with #line directive. */ + char *nominal_fname; + /* Record where in the search path this file was found. + For #include_next. */ + struct file_name_list *dir; + int lineno; + int length; + U_CHAR *buf; + U_CHAR *bufp; + /* Macro that this level is the expansion of. + Included so that we can reenable the macro + at the end of this level. */ + struct hashnode *macro; + /* Value of if_stack at start of this file. + Used to prohibit unmatched #endif (etc) in an include file. */ + struct if_stack *if_stack; + /* Object to be freed at end of input at this level. */ + U_CHAR *free_ptr; + /* True if this is a header file included using . */ + char system_header_p; +} instack[INPUT_STACK_MAX]; + +static int last_error_tick; /* Incremented each time we print it. */ +static int input_file_stack_tick; /* Incremented when the status changes. */ + +/* Current nesting level of input sources. + `instack[indepth]' is the level currently being read. */ +static int indepth = -1; +#define CHECK_DEPTH(code) \ + if (indepth >= (INPUT_STACK_MAX - 1)) \ + { \ + error_with_line (line_for_error (instack[indepth].lineno), \ + "macro or `#include' recursion too deep"); \ + code; \ + } + +/* Current depth in #include directives that use <...>. */ +static int system_include_depth = 0; + +typedef struct file_buf FILE_BUF; + +/* The output buffer. Its LENGTH field is the amount of room allocated + for the buffer, not the number of chars actually present. To get + that, subtract outbuf.buf from outbuf.bufp. */ + +#define OUTBUF_SIZE 10 /* initial size of output buffer */ +static FILE_BUF outbuf; + +/* Grow output buffer OBUF points at + so it can hold at least NEEDED more chars. */ + +#define check_expand(OBUF, NEEDED) \ + (((OBUF)->length - ((OBUF)->bufp - (OBUF)->buf) <= (NEEDED)) \ + ? grow_outbuf ((OBUF), (NEEDED)) : 0) + +struct file_name_list + { + struct file_name_list *next; + char *fname; + /* If the following is nonzero, it is a macro name. + Don't include the file again if that macro is defined. */ + U_CHAR *control_macro; + /* If the following is nonzero, it is a C-language system include + directory. */ + int c_system_include_path; + /* Mapping of file names for this directory. */ + struct file_name_map *name_map; + /* Non-zero if name_map is valid. */ + int got_name_map; + }; + +/* #include "file" looks in source file dir, then stack. */ +/* #include just looks in the stack. */ +/* -I directories are added to the end, then the defaults are added. */ +/* The */ +static struct default_include { + char *fname; /* The name of the directory. */ + int cplusplus; /* Only look here if we're compiling C++. */ + int cxx_aware; /* Includes in this directory don't need to + be wrapped in extern "C" when compiling + C++. */ +} include_defaults_array[] +#ifdef INCLUDE_DEFAULTS + = INCLUDE_DEFAULTS; +#else + = { + /* Pick up GNU C++ specific include files. */ + { GPLUSPLUS_INCLUDE_DIR, 1, 1 }, +#ifdef CROSS_COMPILE + /* This is the dir for fixincludes. Put it just before + the files that we fix. */ + { GCC_INCLUDE_DIR, 0, 0 }, + /* For cross-compilation, this dir name is generated + automatically in Makefile.in. */ + { CROSS_INCLUDE_DIR, 0, 0 }, + /* This is another place that the target system's headers might be. */ + { TOOL_INCLUDE_DIR, 0, 0 }, +#else /* not CROSS_COMPILE */ + /* This should be /usr/local/include and should come before + the fixincludes-fixed header files. */ + { LOCAL_INCLUDE_DIR, 0, 1 }, + /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here. + Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */ + { TOOL_INCLUDE_DIR, 0, 0 }, + /* This is the dir for fixincludes. Put it just before + the files that we fix. */ + { GCC_INCLUDE_DIR, 0, 0 }, + /* Some systems have an extra dir of include files. */ +#ifdef SYSTEM_INCLUDE_DIR + { SYSTEM_INCLUDE_DIR, 0, 0 }, +#endif + { STANDARD_INCLUDE_DIR, 0, 0 }, +#endif /* not CROSS_COMPILE */ + { 0, 0, 0 } + }; +#endif /* no INCLUDE_DEFAULTS */ + +/* The code looks at the defaults through this pointer, rather than through + the constant structure above. This pointer gets changed if an environment + variable specifies other defaults. */ +static struct default_include *include_defaults = include_defaults_array; + +static struct file_name_list *include = 0; /* First dir to search */ + /* First dir to search for */ +/* This is the first element to use for #include <...>. + If it is 0, use the entire chain for such includes. */ +static struct file_name_list *first_bracket_include = 0; +/* This is the first element in the chain that corresponds to + a directory of system header files. */ +static struct file_name_list *first_system_include = 0; +static struct file_name_list *last_include = 0; /* Last in chain */ + +/* Chain of include directories to put at the end of the other chain. */ +static struct file_name_list *after_include = 0; +static struct file_name_list *last_after_include = 0; /* Last in chain */ + +/* Chain to put at the start of the system include files. */ +static struct file_name_list *before_system = 0; +static struct file_name_list *last_before_system = 0; /* Last in chain */ + +/* List of included files that contained #pragma once. */ +static struct file_name_list *dont_repeat_files = 0; + +/* List of other included files. + If ->control_macro if nonzero, the file had a #ifndef + around the entire contents, and ->control_macro gives the macro name. */ +static struct file_name_list *all_include_files = 0; + +/* Directory prefix that should replace `/usr' in the standard + include file directories. */ +static char *include_prefix; + +/* Global list of strings read in from precompiled files. This list + is kept in the order the strings are read in, with new strings being + added at the end through stringlist_tailp. We use this list to output + the strings at the end of the run. +*/ +static STRINGDEF *stringlist; +static STRINGDEF **stringlist_tailp = &stringlist; + + +/* Structure returned by create_definition */ +typedef struct macrodef MACRODEF; +struct macrodef +{ + struct definition *defn; + U_CHAR *symnam; + int symlen; +}; + +enum sharp_token_type { + NO_SHARP_TOKEN = 0, /* token not present */ + + SHARP_TOKEN = '#', /* token spelled with # only */ + WHITE_SHARP_TOKEN, /* token spelled with # and white space */ + + PERCENT_COLON_TOKEN = '%', /* token spelled with %: only */ + WHITE_PERCENT_COLON_TOKEN /* token spelled with %: and white space */ +}; + +/* Structure allocated for every #define. For a simple replacement + such as + #define foo bar , + nargs = -1, the `pattern' list is null, and the expansion is just + the replacement text. Nargs = 0 means a functionlike macro with no args, + e.g., + #define getchar() getc (stdin) . + When there are args, the expansion is the replacement text with the + args squashed out, and the reflist is a list describing how to + build the output from the input: e.g., "3 chars, then the 1st arg, + then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg". + The chars here come from the expansion. Whatever is left of the + expansion after the last arg-occurrence is copied after that arg. + Note that the reflist can be arbitrarily long--- + its length depends on the number of times the arguments appear in + the replacement text, not how many args there are. Example: + #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and + pattern list + { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL } + where (x, y) means (nchars, argno). */ + +typedef struct definition DEFINITION; +struct definition { + int nargs; + int length; /* length of expansion string */ + int predefined; /* True if the macro was builtin or */ + /* came from the command line */ + U_CHAR *expansion; + int line; /* Line number of definition */ + char *file; /* File of definition */ + char rest_args; /* Nonzero if last arg. absorbs the rest */ + struct reflist { + struct reflist *next; + + enum sharp_token_type stringify; /* set if a # operator before arg */ + enum sharp_token_type raw_before; /* set if a ## operator before arg */ + enum sharp_token_type raw_after; /* set if a ## operator after arg */ + + char rest_args; /* Nonzero if this arg. absorbs the rest */ + int nchars; /* Number of literal chars to copy before + this arg occurrence. */ + int argno; /* Number of arg to substitute (origin-0) */ + } *pattern; + union { + /* Names of macro args, concatenated in reverse order + with comma-space between them. + The only use of this is that we warn on redefinition + if this differs between the old and new definitions. */ + U_CHAR *argnames; + } args; +}; + +/* different kinds of things that can appear in the value field + of a hash node. Actually, this may be useless now. */ +union hashval { + char *cpval; + DEFINITION *defn; + KEYDEF *keydef; +}; + +/* + * special extension string that can be added to the last macro argument to + * allow it to absorb the "rest" of the arguments when expanded. Ex: + * #define wow(a, b...) process (b, a, b) + * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); } + * { wow (one, two); } -> { process (two, one, two); } + * if this "rest_arg" is used with the concat token '##' and if it is not + * supplied then the token attached to with ## will not be outputted. Ex: + * #define wow (a, b...) process (b ## , a, ## b) + * { wow (1, 2); } -> { process (2, 1, 2); } + * { wow (one); } -> { process (one); { + */ +static char rest_extension[] = "..."; +#define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1) + +/* The structure of a node in the hash table. The hash table + has entries for all tokens defined by #define directives (type T_MACRO), + plus some special tokens like __LINE__ (these each have their own + type, and the appropriate code is run when that type of node is seen. + It does not contain control words like "#define", which are recognized + by a separate piece of code. */ + +/* different flavors of hash nodes --- also used in keyword table */ +enum node_type { + T_DEFINE = 1, /* the `#define' keyword */ + T_INCLUDE, /* the `#include' keyword */ + T_INCLUDE_NEXT, /* the `#include_next' keyword */ + T_IMPORT, /* the `#import' keyword */ + T_IFDEF, /* the `#ifdef' keyword */ + T_IFNDEF, /* the `#ifndef' keyword */ + T_IF, /* the `#if' keyword */ + T_ELSE, /* `#else' */ + T_PRAGMA, /* `#pragma' */ + T_ELIF, /* `#elif' */ + T_UNDEF, /* `#undef' */ + T_LINE, /* `#line' */ + T_ERROR, /* `#error' */ + T_WARNING, /* `#warning' */ + T_ENDIF, /* `#endif' */ + T_SCCS, /* `#sccs', used on system V. */ + T_IDENT, /* `#ident', used on system V. */ + T_ASSERT, /* `#assert', taken from system V. */ + T_UNASSERT, /* `#unassert', taken from system V. */ + T_SPECLINE, /* special symbol `__LINE__' */ + T_DATE, /* `__DATE__' */ + T_FILE, /* `__FILE__' */ + T_BASE_FILE, /* `__BASE_FILE__' */ + T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ + T_VERSION, /* `__VERSION__' */ + T_SIZE_TYPE, /* `__SIZE_TYPE__' */ + T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */ + T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */ + T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */ + T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */ + T_IMMEDIATE_PREFIX_TYPE, /* `__IMMEDIATE_PREFIX__' */ + T_TIME, /* `__TIME__' */ + T_CONST, /* Constant value, used by `__STDC__' */ + T_MACRO, /* macro defined by `#define' */ + T_DISABLED, /* macro temporarily turned off for rescan */ + T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */ + T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */ + T_UNUSED /* Used for something not defined. */ + }; + +struct hashnode { + struct hashnode *next; /* double links for easy deletion */ + struct hashnode *prev; + struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash + chain is kept, in case the node is the head + of the chain and gets deleted. */ + enum node_type type; /* type of special token */ + int length; /* length of token, for quick comparison */ + U_CHAR *name; /* the actual name */ + union hashval value; /* pointer to expansion, or whatever */ +}; + +typedef struct hashnode HASHNODE; + +/* Some definitions for the hash table. The hash function MUST be + computed as shown in hashf () below. That is because the rescan + loop computes the hash value `on the fly' for most tokens, + in order to avoid the overhead of a lot of procedure calls to + the hashf () function. Hashf () only exists for the sake of + politeness, for use when speed isn't so important. */ + +#define HASHSIZE 1403 +static HASHNODE *hashtab[HASHSIZE]; +#define HASHSTEP(old, c) ((old << 2) + c) +#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */ + +/* Symbols to predefine. */ + +#ifdef CPP_PREDEFINES +static char *predefs = CPP_PREDEFINES; +#else +static char *predefs = ""; +#endif + +/* We let tm.h override the types used here, to handle trivial differences + such as the choice of unsigned int or long unsigned int for size_t. + When machines start needing nontrivial differences in the size type, + it would be best to do something here to figure out automatically + from other information what type to use. */ + +/* The string value for __SIZE_TYPE__. */ + +#ifndef SIZE_TYPE +#define SIZE_TYPE "long unsigned int" +#endif + +/* The string value for __PTRDIFF_TYPE__. */ + +#ifndef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" +#endif + +/* The string value for __WCHAR_TYPE__. */ + +#ifndef WCHAR_TYPE +#define WCHAR_TYPE "int" +#endif +char * wchar_type = WCHAR_TYPE; +#undef WCHAR_TYPE + +/* The string value for __USER_LABEL_PREFIX__ */ + +#ifndef USER_LABEL_PREFIX +#define USER_LABEL_PREFIX "" +#endif + +/* The string value for __REGISTER_PREFIX__ */ + +#ifndef REGISTER_PREFIX +#define REGISTER_PREFIX "" +#endif + +/* The string value for __IMMEDIATE_PREFIX__ */ + +#ifndef IMMEDIATE_PREFIX +#define IMMEDIATE_PREFIX "" +#endif + +/* In the definition of a #assert name, this structure forms + a list of the individual values asserted. + Each value is itself a list of "tokens". + These are strings that are compared by name. */ + +struct tokenlist_list { + struct tokenlist_list *next; + struct arglist *tokens; +}; + +struct assertion_hashnode { + struct assertion_hashnode *next; /* double links for easy deletion */ + struct assertion_hashnode *prev; + /* also, a back pointer to this node's hash + chain is kept, in case the node is the head + of the chain and gets deleted. */ + struct assertion_hashnode **bucket_hdr; + int length; /* length of token, for quick comparison */ + U_CHAR *name; /* the actual name */ + /* List of token-sequences. */ + struct tokenlist_list *value; +}; + +typedef struct assertion_hashnode ASSERTION_HASHNODE; + +/* Some definitions for the hash table. The hash function MUST be + computed as shown in hashf below. That is because the rescan + loop computes the hash value `on the fly' for most tokens, + in order to avoid the overhead of a lot of procedure calls to + the hashf function. hashf only exists for the sake of + politeness, for use when speed isn't so important. */ + +#define ASSERTION_HASHSIZE 37 +static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE]; + +/* Nonzero means inhibit macroexpansion of what seem to be + assertion tests, in rescan. For #if. */ +static int assertions_flag; + +/* `struct directive' defines one #-directive, including how to handle it. */ + +#define DO_PROTO PROTO((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)) + +struct directive { + int length; /* Length of name */ + int (*func) DO_PROTO; /* Function to handle directive */ + char *name; /* Name of directive */ + enum node_type type; /* Code which describes which directive. */ + char angle_brackets; /* Nonzero => <...> is special. */ + char traditional_comments; /* Nonzero: keep comments if -traditional. */ + char pass_thru; /* Copy preprocessed directive to output file. */ +}; + +/* These functions are declared to return int instead of void since they + are going to be placed in the table and some old compilers have trouble with + pointers to functions returning void. */ + +static int do_assert DO_PROTO; +static int do_define DO_PROTO; +static int do_elif DO_PROTO; +static int do_else DO_PROTO; +static int do_endif DO_PROTO; +static int do_error DO_PROTO; +static int do_ident DO_PROTO; +static int do_if DO_PROTO; +static int do_include DO_PROTO; +static int do_line DO_PROTO; +static int do_pragma DO_PROTO; +#ifdef SCCS_DIRECTIVE +static int do_sccs DO_PROTO; +#endif +static int do_unassert DO_PROTO; +static int do_undef DO_PROTO; +static int do_warning DO_PROTO; +static int do_xifdef DO_PROTO; + +/* Here is the actual list of #-directives, most-often-used first. */ + +static struct directive directive_table[] = { + { 6, do_define, "define", T_DEFINE, 0, 1}, + { 2, do_if, "if", T_IF}, + { 5, do_xifdef, "ifdef", T_IFDEF}, + { 6, do_xifdef, "ifndef", T_IFNDEF}, + { 5, do_endif, "endif", T_ENDIF}, + { 4, do_else, "else", T_ELSE}, + { 4, do_elif, "elif", T_ELIF}, + { 4, do_line, "line", T_LINE}, + { 7, do_include, "include", T_INCLUDE, 1}, + { 12, do_include, "include_next", T_INCLUDE_NEXT, 1}, + { 6, do_include, "import", T_IMPORT, 1}, + { 5, do_undef, "undef", T_UNDEF}, + { 5, do_error, "error", T_ERROR}, + { 7, do_warning, "warning", T_WARNING}, +#ifdef SCCS_DIRECTIVE + { 4, do_sccs, "sccs", T_SCCS}, +#endif + { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1}, + { 5, do_ident, "ident", T_IDENT}, + { 6, do_assert, "assert", T_ASSERT}, + { 8, do_unassert, "unassert", T_UNASSERT}, + { -1, 0, "", T_UNUSED}, +}; + +/* When a directive handler is called, + this points to the # (or the : of the %:) that started the directive. */ +U_CHAR *directive_start; + +/* table to tell if char can be part of a C identifier. */ +U_CHAR is_idchar[256]; +/* table to tell if char can be first char of a c identifier. */ +U_CHAR is_idstart[256]; +/* table to tell if c is horizontal space. */ +U_CHAR is_hor_space[256]; +/* table to tell if c is horizontal or vertical space. */ +static U_CHAR is_space[256]; +/* names of some characters */ +static char *char_name[256]; + +#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) +#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0) + +static int errors = 0; /* Error counter for exit code */ + +/* Name of output file, for error messages. */ +static char *out_fname; + +/* Zero means dollar signs are punctuation. + -$ stores 0; -traditional may store 1. Default is 1 for VMS, 0 otherwise. + This must be 0 for correct processing of this ANSI C program: + #define foo(a) #a + #define lose(b) foo (b) + #define test$ + lose (test) */ +static int dollars_in_ident; +#ifndef DOLLARS_IN_IDENTIFIERS +#define DOLLARS_IN_IDENTIFIERS 1 +#endif + + +/* Stack of conditionals currently in progress + (including both successful and failing conditionals). */ + +struct if_stack { + struct if_stack *next; /* for chaining to the next stack frame */ + char *fname; /* copied from input when frame is made */ + int lineno; /* similarly */ + int if_succeeded; /* true if a leg of this if-group + has been passed through rescan */ + U_CHAR *control_macro; /* For #ifndef at start of file, + this is the macro name tested. */ + enum node_type type; /* type of last directive seen in this group */ +}; +typedef struct if_stack IF_STACK_FRAME; +static IF_STACK_FRAME *if_stack = NULL; + +/* Buffer of -M output. */ +static char *deps_buffer; + +/* Number of bytes allocated in above. */ +static int deps_allocated_size; + +/* Number of bytes used. */ +static int deps_size; + +/* Number of bytes since the last newline. */ +static int deps_column; + +/* Nonzero means -I- has been seen, + so don't look for #include "foo" the source-file directory. */ +static int ignore_srcdir; + +static int safe_read PROTO((int, char *, int)); +static void safe_write PROTO((int, char *, int)); + +int main PROTO((int, char **)); + +static void path_include PROTO((char *)); + +static U_CHAR *index0 PROTO((U_CHAR *, int, size_t)); + +static void trigraph_pcp PROTO((FILE_BUF *)); + +static void newline_fix PROTO((U_CHAR *)); +static void name_newline_fix PROTO((U_CHAR *)); + +static char *get_lintcmd PROTO((U_CHAR *, U_CHAR *, U_CHAR **, int *, int *)); + +static void rescan PROTO((FILE_BUF *, int)); + +static FILE_BUF expand_to_temp_buffer PROTO((U_CHAR *, U_CHAR *, int, int)); + +static int handle_directive PROTO((FILE_BUF *, FILE_BUF *)); + +static struct tm *timestamp PROTO((void)); +static void special_symbol PROTO((HASHNODE *, FILE_BUF *)); + +static int redundant_include_p PROTO((char *)); +static int is_system_include PROTO((char *)); +static char *skip_redundant_dir_prefix PROTO((char *)); + +static char *read_filename_string PROTO((int, FILE *)); +static struct file_name_map *read_name_map PROTO((char *)); +static int open_include_file PROTO((char *, struct file_name_list *)); + +static void finclude PROTO((int, char *, FILE_BUF *, int, struct file_name_list *)); +static void record_control_macro PROTO((char *, U_CHAR *)); + +static int import_hash PROTO((char *)); +static int lookup_import PROTO((char *, struct file_name_list *)); +static void add_import PROTO((int, char *)); + +static char *check_precompiled PROTO((int, char *, char **)); +static int check_preconditions PROTO((char *)); +static void pcfinclude PROTO((U_CHAR *, U_CHAR *, U_CHAR *, FILE_BUF *)); +static void pcstring_used PROTO((HASHNODE *)); +static void write_output PROTO((void)); +static void pass_thru_directive PROTO((U_CHAR *, U_CHAR *, FILE_BUF *, struct directive *)); + +static MACRODEF create_definition PROTO((U_CHAR *, U_CHAR *, FILE_BUF *)); + +static int check_macro_name PROTO((U_CHAR *, char *)); +static int compare_defs PROTO((DEFINITION *, DEFINITION *)); +static int comp_def_part PROTO((int, U_CHAR *, int, U_CHAR *, int, int)); + +static DEFINITION *collect_expansion PROTO((U_CHAR *, U_CHAR *, int, struct arglist *)); + +int check_assertion PROTO((U_CHAR *, int, int, struct arglist *)); +static int compare_token_lists PROTO((struct arglist *, struct arglist *)); + +static struct arglist *read_token_list PROTO((U_CHAR **, U_CHAR *, int *)); +static void free_token_list PROTO((struct arglist *)); + +static ASSERTION_HASHNODE *assertion_install PROTO((U_CHAR *, int, int)); +static ASSERTION_HASHNODE *assertion_lookup PROTO((U_CHAR *, int, int)); +static void delete_assertion PROTO((ASSERTION_HASHNODE *)); + +static void do_once PROTO((void)); + +static HOST_WIDE_INT eval_if_expression PROTO((U_CHAR *, int)); +static void conditional_skip PROTO((FILE_BUF *, int, enum node_type, U_CHAR *, FILE_BUF *)); +static void skip_if_group PROTO((FILE_BUF *, int, FILE_BUF *)); +static void validate_else PROTO((U_CHAR *)); + +static U_CHAR *skip_to_end_of_comment PROTO((FILE_BUF *, int *, int)); +static U_CHAR *skip_quoted_string PROTO((U_CHAR *, U_CHAR *, int, int *, int *, int *)); +static char *quote_string PROTO((char *, char *)); +static U_CHAR *skip_paren_group PROTO((FILE_BUF *)); + +/* Last arg to output_line_directive. */ +enum file_change_code {same_file, enter_file, leave_file}; +static void output_line_directive PROTO((FILE_BUF *, FILE_BUF *, int, enum file_change_code)); + +static void macroexpand PROTO((HASHNODE *, FILE_BUF *)); + +struct argdata; +static char *macarg PROTO((struct argdata *, int)); + +static U_CHAR *macarg1 PROTO((U_CHAR *, U_CHAR *, int *, int *, int *, int)); + +static int discard_comments PROTO((U_CHAR *, int, int)); + +static int change_newlines PROTO((U_CHAR *, int)); + +char *my_strerror PROTO((int)); +void error PRINTF_PROTO_1((char *, ...)); +static void verror PROTO((char *, va_list)); +static void error_from_errno PROTO((char *)); +void warning PRINTF_PROTO_1((char *, ...)); +static void vwarning PROTO((char *, va_list)); +static void error_with_line PRINTF_PROTO_2((int, char *, ...)); +static void verror_with_line PROTO((int, char *, va_list)); +static void vwarning_with_line PROTO((int, char *, va_list)); +static void warning_with_line PRINTF_PROTO_2((int, char *, ...)); +void pedwarn PRINTF_PROTO_1((char *, ...)); +void pedwarn_with_line PRINTF_PROTO_2((int, char *, ...)); +static void pedwarn_with_file_and_line PRINTF_PROTO_3((char *, int, char *, ...)); + +static void print_containing_files PROTO((void)); + +static int line_for_error PROTO((int)); +static int grow_outbuf PROTO((FILE_BUF *, int)); + +static HASHNODE *install PROTO((U_CHAR *, int, enum node_type, char *, int)); +HASHNODE *lookup PROTO((U_CHAR *, int, int)); +static void delete_macro PROTO((HASHNODE *)); +static int hashf PROTO((U_CHAR *, int, int)); + +static void dump_single_macro PROTO((HASHNODE *, FILE *)); +static void dump_all_macros PROTO((void)); +static void dump_defn_1 PROTO((U_CHAR *, int, int, FILE *)); +static void dump_arg_n PROTO((DEFINITION *, int, FILE *)); + +static void initialize_char_syntax PROTO((void)); +static void initialize_builtins PROTO((FILE_BUF *, FILE_BUF *)); + +static void make_definition PROTO((char *, FILE_BUF *)); +static void make_undef PROTO((char *, FILE_BUF *)); + +static void make_assertion PROTO((char *, char *)); + +static void append_include_chain PROTO((struct file_name_list *, struct file_name_list *)); + +static void deps_output PROTO((char *, int)); + +static void fatal PRINTF_PROTO_1((char *, ...)) __attribute__ ((noreturn)); +void fancy_abort PROTO((void)) __attribute__ ((noreturn)); +static void perror_with_name PROTO((char *)); +static void pfatal_with_name PROTO((char *)) __attribute__ ((noreturn)); +static void pipe_closed PROTO((int)) __attribute__ ((noreturn)); + +static void memory_full PROTO((void)) __attribute__ ((noreturn)); +GENERIC_PTR xmalloc PROTO((size_t)); +static GENERIC_PTR xrealloc PROTO((GENERIC_PTR, size_t)); +static GENERIC_PTR xcalloc PROTO((size_t, size_t)); +static char *savestring PROTO((char *)); + +static int file_size_and_mode PROTO((int, int *, long int *)); + +/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME, + retrying if necessary. Return a negative value if an error occurs, + otherwise return the actual number of bytes read, + which must be LEN unless end-of-file was reached. */ + +static int +safe_read (desc, ptr, len) + int desc; + char *ptr; + int len; +{ + int left = len; + while (left > 0) { + int nchars = read (desc, ptr, left); + if (nchars < 0) + { +#ifdef EINTR + if (errno == EINTR) + continue; +#endif + return nchars; + } + if (nchars == 0) + break; + ptr += nchars; + left -= nchars; + } + return len - left; +} + +/* Write LEN bytes at PTR to descriptor DESC, + retrying if necessary, and treating any real error as fatal. */ + +static void +safe_write (desc, ptr, len) + int desc; + char *ptr; + int len; +{ + while (len > 0) { + int written = write (desc, ptr, len); + if (written < 0) + { +#ifdef EINTR + if (errno == EINTR) + continue; +#endif + pfatal_with_name (out_fname); + } + ptr += written; + len -= written; + } +} + +int +main (argc, argv) + int argc; + char **argv; +{ + int st_mode; + long st_size; + char *in_fname; + char *cp; + int f, i; + FILE_BUF *fp; + char **pend_files = (char **) xmalloc (argc * sizeof (char *)); + char **pend_defs = (char **) xmalloc (argc * sizeof (char *)); + char **pend_undefs = (char **) xmalloc (argc * sizeof (char *)); + char **pend_assertions = (char **) xmalloc (argc * sizeof (char *)); + char **pend_includes = (char **) xmalloc (argc * sizeof (char *)); + + /* Record the option used with each element of pend_assertions. + This is preparation for supporting more than one option for making + an assertion. */ + char **pend_assertion_options = (char **) xmalloc (argc * sizeof (char *)); + int inhibit_predefs = 0; + int no_standard_includes = 0; + int no_standard_cplusplus_includes = 0; + int missing_newline = 0; + + /* Non-0 means don't output the preprocessed program. */ + int inhibit_output = 0; + /* Non-0 means -v, so print the full set of include dirs. */ + int verbose = 0; + + /* File name which deps are being written to. + This is 0 if deps are being written to stdout. */ + char *deps_file = 0; + /* Fopen file mode to open deps_file with. */ + char *deps_mode = "a"; + /* Stream on which to print the dependency information. */ + FILE *deps_stream = 0; + /* Target-name to write with the dependency information. */ + char *deps_target = 0; + +#ifdef RLIMIT_STACK + /* Get rid of any avoidable limit on stack size. */ + { + struct rlimit rlim; + + /* Set the stack limit huge so that alloca (particularly stringtab + * in dbxread.c) does not fail. */ + getrlimit (RLIMIT_STACK, &rlim); + rlim.rlim_cur = rlim.rlim_max; + setrlimit (RLIMIT_STACK, &rlim); + } +#endif /* RLIMIT_STACK defined */ + +#ifdef SIGPIPE + signal (SIGPIPE, pipe_closed); +#endif + + cp = argv[0] + strlen (argv[0]); + while (cp != argv[0] && cp[-1] != '/' +#ifdef DIR_SEPARATOR + && cp[-1] != DIR_SEPARATOR +#endif + ) + --cp; + progname = cp; + +#ifdef VMS + { + /* Remove directories from PROGNAME. */ + char *p; + char *s = progname; + + if ((p = rindex (s, ':')) != 0) s = p + 1; /* skip device */ + if ((p = rindex (s, ']')) != 0) s = p + 1; /* skip directory */ + if ((p = rindex (s, '>')) != 0) s = p + 1; /* alternate (int'n'l) dir */ + s = progname = savestring (s); + if ((p = rindex (s, ';')) != 0) *p = '\0'; /* strip version number */ + if ((p = rindex (s, '.')) != 0 /* strip type iff ".exe" */ + && (p[1] == 'e' || p[1] == 'E') + && (p[2] == 'x' || p[2] == 'X') + && (p[3] == 'e' || p[3] == 'E') + && !p[4]) + *p = '\0'; + } +#endif + + in_fname = NULL; + out_fname = NULL; + + /* Initialize is_idchar to allow $. */ + dollars_in_ident = 1; + initialize_char_syntax (); + dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0; + + no_line_directives = 0; + no_trigraphs = 1; + dump_macros = dump_none; + no_output = 0; + cplusplus = 0; + cplusplus_comments = 1; + + bzero ((char *) pend_files, argc * sizeof (char *)); + bzero ((char *) pend_defs, argc * sizeof (char *)); + bzero ((char *) pend_undefs, argc * sizeof (char *)); + bzero ((char *) pend_assertions, argc * sizeof (char *)); + bzero ((char *) pend_includes, argc * sizeof (char *)); + + /* Process switches and find input file name. */ + + for (i = 1; i < argc; i++) { + if (argv[i][0] != '-') { + if (out_fname != NULL) + fatal ("Usage: %s [switches] input output", argv[0]); + else if (in_fname != NULL) + out_fname = argv[i]; + else + in_fname = argv[i]; + } else { + switch (argv[i][1]) { + + case 'i': + if (!strcmp (argv[i], "-include")) { + if (i + 1 == argc) + fatal ("Filename missing after `-include' option"); + else + pend_includes[i] = argv[i+1], i++; + } + if (!strcmp (argv[i], "-imacros")) { + if (i + 1 == argc) + fatal ("Filename missing after `-imacros' option"); + else + pend_files[i] = argv[i+1], i++; + } + if (!strcmp (argv[i], "-iprefix")) { + if (i + 1 == argc) + fatal ("Filename missing after `-iprefix' option"); + else + include_prefix = argv[++i]; + } + if (!strcmp (argv[i], "-ifoutput")) { + output_conditionals = 1; + } + if (!strcmp (argv[i], "-isystem")) { + struct file_name_list *dirtmp; + + if (i + 1 == argc) + fatal ("Filename missing after `-isystem' option"); + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 1; + dirtmp->fname = xmalloc (strlen (argv[i+1]) + 1); + strcpy (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (before_system == 0) + before_system = dirtmp; + else + last_before_system->next = dirtmp; + last_before_system = dirtmp; /* Tail follows the last one */ + } + /* Add directory to end of path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefix")) { + struct file_name_list *dirtmp; + char *prefix; + + if (include_prefix != 0) + prefix = include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-iwithprefix' option"); + + dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (after_include == 0) + after_include = dirtmp; + else + last_after_include->next = dirtmp; + last_after_include = dirtmp; /* Tail follows the last one */ + } + /* Add directory to main path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefixbefore")) { + struct file_name_list *dirtmp; + char *prefix; + + if (include_prefix != 0) + prefix = include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-iwithprefixbefore' option"); + + dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + append_include_chain (dirtmp, dirtmp); + } + /* Add directory to end of path for includes. */ + if (!strcmp (argv[i], "-idirafter")) { + struct file_name_list *dirtmp; + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-idirafter' option"); + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + + if (after_include == 0) + after_include = dirtmp; + else + last_after_include->next = dirtmp; + last_after_include = dirtmp; /* Tail follows the last one */ + } + break; + + case 'o': + if (out_fname != NULL) + fatal ("Output filename specified twice"); + if (i + 1 == argc) + fatal ("Filename missing after -o option"); + out_fname = argv[++i]; + if (!strcmp (out_fname, "-")) + out_fname = ""; + break; + + case 'p': + if (!strcmp (argv[i], "-pedantic")) + pedantic = 1; + else if (!strcmp (argv[i], "-pedantic-errors")) { + pedantic = 1; + pedantic_errors = 1; + } else if (!strcmp (argv[i], "-pcp")) { + char *pcp_fname; + if (i + 1 == argc) + fatal ("Filename missing after -pcp option"); + pcp_fname = argv[++i]; + pcp_outfile = + ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') + ? fopen (pcp_fname, "w") + : stdout); + if (pcp_outfile == 0) + pfatal_with_name (pcp_fname); + no_precomp = 1; + } + break; + + case 't': + if (!strcmp (argv[i], "-traditional")) { + traditional = 1; + cplusplus_comments = 0; + if (dollars_in_ident > 0) + dollars_in_ident = 1; + } else if (!strcmp (argv[i], "-trigraphs")) { + no_trigraphs = 0; + } + break; + + case 'l': + if (! strcmp (argv[i], "-lang-c")) + cplusplus = 0, cplusplus_comments = 1, objc = 0; + if (! strcmp (argv[i], "-lang-c89")) + cplusplus = 0, cplusplus_comments = 0, objc = 0; + if (! strcmp (argv[i], "-lang-c++")) + cplusplus = 1, cplusplus_comments = 1, objc = 0; + if (! strcmp (argv[i], "-lang-objc")) + objc = 1, cplusplus = 0, cplusplus_comments = 1; + if (! strcmp (argv[i], "-lang-objc++")) + objc = 1, cplusplus = 1, cplusplus_comments = 1; + if (! strcmp (argv[i], "-lang-asm")) + lang_asm = 1; + if (! strcmp (argv[i], "-lint")) + for_lint = 1; + break; + + case '+': + cplusplus = 1, cplusplus_comments = 1; + break; + + case 'w': + inhibit_warnings = 1; + break; + + case 'W': + if (!strcmp (argv[i], "-Wtrigraphs")) + warn_trigraphs = 1; + else if (!strcmp (argv[i], "-Wno-trigraphs")) + warn_trigraphs = 0; + else if (!strcmp (argv[i], "-Wcomment")) + warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comment")) + warn_comments = 0; + else if (!strcmp (argv[i], "-Wcomments")) + warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comments")) + warn_comments = 0; + else if (!strcmp (argv[i], "-Wtraditional")) + warn_stringify = 1; + else if (!strcmp (argv[i], "-Wno-traditional")) + warn_stringify = 0; + else if (!strcmp (argv[i], "-Wimport")) + warn_import = 1; + else if (!strcmp (argv[i], "-Wno-import")) + warn_import = 0; + else if (!strcmp (argv[i], "-Werror")) + warnings_are_errors = 1; + else if (!strcmp (argv[i], "-Wno-error")) + warnings_are_errors = 0; + else if (!strcmp (argv[i], "-Wall")) + { + warn_trigraphs = 1; + warn_comments = 1; + } + break; + + case 'M': + /* The style of the choices here is a bit mixed. + The chosen scheme is a hybrid of keeping all options in one string + and specifying each option in a separate argument: + -M|-MM|-MD file|-MMD file [-MG]. An alternative is: + -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: + -M[M][G][D file]. This is awkward to handle in specs, and is not + as extensible. */ + /* ??? -MG must be specified in addition to one of -M or -MM. + This can be relaxed in the future without breaking anything. + The converse isn't true. */ + + /* -MG isn't valid with -MD or -MMD. This is checked for later. */ + if (!strcmp (argv[i], "-MG")) + { + print_deps_missing_files = 1; + break; + } + if (!strcmp (argv[i], "-M")) + print_deps = 2; + else if (!strcmp (argv[i], "-MM")) + print_deps = 1; + else if (!strcmp (argv[i], "-MD")) + print_deps = 2; + else if (!strcmp (argv[i], "-MMD")) + print_deps = 1; + /* For -MD and -MMD options, write deps on file named by next arg. */ + if (!strcmp (argv[i], "-MD") + || !strcmp (argv[i], "-MMD")) { + if (i + 1 == argc) + fatal ("Filename missing after %s option", argv[i]); + i++; + deps_file = argv[i]; + deps_mode = "w"; + } else { + /* For -M and -MM, write deps on standard output + and suppress the usual output. */ + deps_stream = stdout; + inhibit_output = 1; + } + break; + + case 'd': + { + char *p = argv[i] + 2; + char c; + while ((c = *p++)) { + /* Arg to -d specifies what parts of macros to dump */ + switch (c) { + case 'M': + dump_macros = dump_only; + no_output = 1; + break; + case 'N': + dump_macros = dump_names; + break; + case 'D': + dump_macros = dump_definitions; + break; + } + } + } + break; + + case 'g': + if (argv[i][2] == '3') + debug_output = 1; + break; + + case 'v': + fprintf (stderr, "GNU CPP version %s", version_string); +#ifdef TARGET_VERSION + TARGET_VERSION; +#endif + fprintf (stderr, "\n"); + verbose = 1; + break; + + case 'H': + print_include_names = 1; + break; + + case 'D': + if (argv[i][2] != 0) + pend_defs[i] = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Macro name missing after -D option"); + else + i++, pend_defs[i] = argv[i]; + break; + + case 'A': + { + char *p; + + if (argv[i][2] != 0) + p = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Assertion missing after -A option"); + else + p = argv[++i]; + + if (!strcmp (p, "-")) { + /* -A- eliminates all predefined macros and assertions. + Let's include also any that were specified earlier + on the command line. That way we can get rid of any + that were passed automatically in from GCC. */ + int j; + inhibit_predefs = 1; + for (j = 0; j < i; j++) + pend_defs[j] = pend_assertions[j] = 0; + } else { + pend_assertions[i] = p; + pend_assertion_options[i] = "-A"; + } + } + break; + + case 'U': /* JF #undef something */ + if (argv[i][2] != 0) + pend_undefs[i] = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Macro name missing after -U option"); + else + pend_undefs[i] = argv[i+1], i++; + break; + + case 'C': + put_out_comments = 1; + break; + + case 'E': /* -E comes from cc -E; ignore it. */ + break; + + case 'P': + no_line_directives = 1; + break; + + case '$': /* Don't include $ in identifiers. */ + dollars_in_ident = 0; + break; + + case 'I': /* Add directory to path for includes. */ + { + struct file_name_list *dirtmp; + + if (! ignore_srcdir && !strcmp (argv[i] + 2, "-")) { + ignore_srcdir = 1; + /* Don't use any preceding -I directories for #include <...>. */ + first_bracket_include = 0; + } + else { + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (argv[i][2] != 0) + dirtmp->fname = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Directory name missing after -I option"); + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + append_include_chain (dirtmp, dirtmp); + } + } + break; + + case 'n': + if (!strcmp (argv[i], "-nostdinc")) + /* -nostdinc causes no default include directories. + You must specify all include-file directories with -I. */ + no_standard_includes = 1; + else if (!strcmp (argv[i], "-nostdinc++")) + /* -nostdinc++ causes no default C++-specific include directories. */ + no_standard_cplusplus_includes = 1; + else if (!strcmp (argv[i], "-noprecomp")) + no_precomp = 1; + break; + + case 'u': + /* Sun compiler passes undocumented switch "-undef". + Let's assume it means to inhibit the predefined symbols. */ + inhibit_predefs = 1; + break; + + case '\0': /* JF handle '-' as file name meaning stdin or stdout */ + if (in_fname == NULL) { + in_fname = ""; + break; + } else if (out_fname == NULL) { + out_fname = ""; + break; + } /* else fall through into error */ + + default: + fatal ("Invalid option `%s'", argv[i]); + } + } + } + + /* Add dirs from CPATH after dirs from -I. */ + /* There seems to be confusion about what CPATH should do, + so for the moment it is not documented. */ + /* Some people say that CPATH should replace the standard include dirs, + but that seems pointless: it comes before them, so it overrides them + anyway. */ + cp = getenv ("CPATH"); + if (cp && ! no_standard_includes) + path_include (cp); + + /* Now that dollars_in_ident is known, initialize is_idchar. */ + initialize_char_syntax (); + + /* Initialize output buffer */ + + outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE); + outbuf.bufp = outbuf.buf; + outbuf.length = OUTBUF_SIZE; + + /* Do partial setup of input buffer for the sake of generating + early #line directives (when -g is in effect). */ + + fp = &instack[++indepth]; + if (in_fname == NULL) + in_fname = ""; + fp->nominal_fname = fp->fname = in_fname; + fp->lineno = 0; + + /* In C++, wchar_t is a distinct basic type, and we can expect + __wchar_t to be defined by cc1plus. */ + if (cplusplus) + wchar_type = "__wchar_t"; + + /* Install __LINE__, etc. Must follow initialize_char_syntax + and option processing. */ + initialize_builtins (fp, &outbuf); + + /* Do standard #defines and assertions + that identify system and machine type. */ + + if (!inhibit_predefs) { + char *p = (char *) alloca (strlen (predefs) + 1); + strcpy (p, predefs); + while (*p) { + char *q; + while (*p == ' ' || *p == '\t') + p++; + /* Handle -D options. */ + if (p[0] == '-' && p[1] == 'D') { + q = &p[2]; + while (*p && *p != ' ' && *p != '\t') + p++; + if (*p != 0) + *p++= 0; + if (debug_output) + output_line_directive (fp, &outbuf, 0, same_file); + make_definition (q, &outbuf); + while (*p == ' ' || *p == '\t') + p++; + } else if (p[0] == '-' && p[1] == 'A') { + /* Handle -A options (assertions). */ + char *assertion; + char *past_name; + char *value; + char *past_value; + char *termination; + int save_char; + + assertion = &p[2]; + past_name = assertion; + /* Locate end of name. */ + while (*past_name && *past_name != ' ' + && *past_name != '\t' && *past_name != '(') + past_name++; + /* Locate `(' at start of value. */ + value = past_name; + while (*value && (*value == ' ' || *value == '\t')) + value++; + if (*value++ != '(') + abort (); + while (*value && (*value == ' ' || *value == '\t')) + value++; + past_value = value; + /* Locate end of value. */ + while (*past_value && *past_value != ' ' + && *past_value != '\t' && *past_value != ')') + past_value++; + termination = past_value; + while (*termination && (*termination == ' ' || *termination == '\t')) + termination++; + if (*termination++ != ')') + abort (); + if (*termination && *termination != ' ' && *termination != '\t') + abort (); + /* Temporarily null-terminate the value. */ + save_char = *termination; + *termination = '\0'; + /* Install the assertion. */ + make_assertion ("-A", assertion); + *termination = (char) save_char; + p = termination; + while (*p == ' ' || *p == '\t') + p++; + } else { + abort (); + } + } + } + + /* Now handle the command line options. */ + + /* Do -U's, -D's and -A's in the order they were seen. */ + for (i = 1; i < argc; i++) { + if (pend_undefs[i]) { + if (debug_output) + output_line_directive (fp, &outbuf, 0, same_file); + make_undef (pend_undefs[i], &outbuf); + } + if (pend_defs[i]) { + if (debug_output) + output_line_directive (fp, &outbuf, 0, same_file); + make_definition (pend_defs[i], &outbuf); + } + if (pend_assertions[i]) + make_assertion (pend_assertion_options[i], pend_assertions[i]); + } + + done_initializing = 1; + + { /* read the appropriate environment variable and if it exists + replace include_defaults with the listed path. */ + char *epath = 0; + switch ((objc << 1) + cplusplus) + { + case 0: + epath = getenv ("C_INCLUDE_PATH"); + break; + case 1: + epath = getenv ("CPLUS_INCLUDE_PATH"); + break; + case 2: + epath = getenv ("OBJC_INCLUDE_PATH"); + break; + case 3: + epath = getenv ("OBJCPLUS_INCLUDE_PATH"); + break; + } + /* If the environment var for this language is set, + add to the default list of include directories. */ + if (epath) { + char *nstore = (char *) alloca (strlen (epath) + 2); + int num_dirs; + char *startp, *endp; + + for (num_dirs = 1, startp = epath; *startp; startp++) + if (*startp == PATH_SEPARATOR) + num_dirs++; + include_defaults + = (struct default_include *) xmalloc ((num_dirs + * sizeof (struct default_include)) + + sizeof (include_defaults_array)); + startp = endp = epath; + num_dirs = 0; + while (1) { + /* Handle cases like c:/usr/lib:d:/gcc/lib */ + if ((*endp == PATH_SEPARATOR +#if 0 /* Obsolete, now that we use semicolons as the path separator. */ +#ifdef __MSDOS__ + && (endp-startp != 1 || !isalpha (*startp)) +#endif +#endif + ) + || *endp == 0) { + strncpy (nstore, startp, endp-startp); + if (endp == startp) + strcpy (nstore, "."); + else + nstore[endp-startp] = '\0'; + + include_defaults[num_dirs].fname = savestring (nstore); + include_defaults[num_dirs].cplusplus = cplusplus; + include_defaults[num_dirs].cxx_aware = 1; + num_dirs++; + if (*endp == '\0') + break; + endp = startp = endp + 1; + } else + endp++; + } + /* Put the usual defaults back in at the end. */ + bcopy ((char *) include_defaults_array, + (char *) &include_defaults[num_dirs], + sizeof (include_defaults_array)); + } + } + + append_include_chain (before_system, last_before_system); + first_system_include = before_system; + + /* Unless -fnostdinc, + tack on the standard include file dirs to the specified list */ + if (!no_standard_includes) { + struct default_include *p = include_defaults; + char *specd_prefix = include_prefix; + char *default_prefix = savestring (GCC_INCLUDE_DIR); + int default_len = 0; + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) { + default_len = strlen (default_prefix) - 7; + default_prefix[default_len] = 0; + } + /* Search "translated" versions of GNU directories. + These have /usr/local/lib/gcc... replaced by specd_prefix. */ + if (specd_prefix != 0 && default_len != 0) + for (p = include_defaults; p->fname; p++) { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) { + /* Does this dir start with the prefix? */ + if (!strncmp (p->fname, default_prefix, default_len)) { + /* Yes; change prefix and add to search list. */ + struct file_name_list *new + = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len; + char *str = xmalloc (this_len + 1); + strcpy (str, specd_prefix); + strcat (str, p->fname + default_len); + new->fname = str; + new->control_macro = 0; + new->c_system_include_path = !p->cxx_aware; + new->got_name_map = 0; + append_include_chain (new, new); + if (first_system_include == 0) + first_system_include = new; + } + } + } + /* Search ordinary names for GNU include directories. */ + for (p = include_defaults; p->fname; p++) { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) { + struct file_name_list *new + = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + new->control_macro = 0; + new->c_system_include_path = !p->cxx_aware; + new->fname = p->fname; + new->got_name_map = 0; + append_include_chain (new, new); + if (first_system_include == 0) + first_system_include = new; + } + } + } + + /* Tack the after_include chain at the end of the include chain. */ + append_include_chain (after_include, last_after_include); + if (first_system_include == 0) + first_system_include = after_include; + + /* With -v, print the list of dirs to search. */ + if (verbose) { + struct file_name_list *p; + fprintf (stderr, "#include \"...\" search starts here:\n"); + for (p = include; p; p = p->next) { + if (p == first_bracket_include) + fprintf (stderr, "#include <...> search starts here:\n"); + fprintf (stderr, " %s\n", p->fname); + } + fprintf (stderr, "End of search list.\n"); + } + + /* Scan the -imacros files before the main input. + Much like #including them, but with no_output set + so that only their macro definitions matter. */ + + no_output++; no_record_file++; + for (i = 1; i < argc; i++) + if (pend_files[i]) { + int fd = open (pend_files[i], O_RDONLY, 0666); + if (fd < 0) { + perror_with_name (pend_files[i]); + return FATAL_EXIT_CODE; + } + finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR); + } + no_output--; no_record_file--; + + /* Copy the entire contents of the main input file into + the stacked input buffer previously allocated for it. */ + + /* JF check for stdin */ + if (in_fname == NULL || *in_fname == 0) { + in_fname = ""; + f = 0; + } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0) + goto perror; + + /* -MG doesn't select the form of output and must be specified with one of + -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't + inhibit compilation. */ + if (print_deps_missing_files && (print_deps == 0 || !inhibit_output)) + fatal ("-MG must be specified with one of -M or -MM"); + + /* Either of two environment variables can specify output of deps. + Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", + where OUTPUT_FILE is the file to write deps info to + and DEPS_TARGET is the target to mention in the deps. */ + + if (print_deps == 0 + && (getenv ("SUNPRO_DEPENDENCIES") != 0 + || getenv ("DEPENDENCIES_OUTPUT") != 0)) { + char *spec = getenv ("DEPENDENCIES_OUTPUT"); + char *s; + char *output_file; + + if (spec == 0) { + spec = getenv ("SUNPRO_DEPENDENCIES"); + print_deps = 2; + } + else + print_deps = 1; + + s = spec; + /* Find the space before the DEPS_TARGET, if there is one. */ + /* This should use index. (mrs) */ + while (*s != 0 && *s != ' ') s++; + if (*s != 0) { + deps_target = s + 1; + output_file = xmalloc (s - spec + 1); + bcopy (spec, output_file, s - spec); + output_file[s - spec] = 0; + } + else { + deps_target = 0; + output_file = spec; + } + + deps_file = output_file; + deps_mode = "a"; + } + + /* For -M, print the expected object file name + as the target of this Make-rule. */ + if (print_deps) { + deps_allocated_size = 200; + deps_buffer = xmalloc (deps_allocated_size); + deps_buffer[0] = 0; + deps_size = 0; + deps_column = 0; + + if (deps_target) { + deps_output (deps_target, ':'); + } else if (*in_fname == 0) { + deps_output ("-", ':'); + } else { + char *p, *q; + int len; + + /* Discard all directory prefixes from filename. */ + if ((q = rindex (in_fname, '/')) != NULL +#ifdef DIR_SEPARATOR + && (q = rindex (in_fname, DIR_SEPARATOR)) != NULL +#endif + ) + ++q; + else + q = in_fname; + + /* Copy remainder to mungable area. */ + p = (char *) alloca (strlen(q) + 8); + strcpy (p, q); + + /* Output P, but remove known suffixes. */ + len = strlen (p); + q = p + len; + if (len >= 2 + && p[len - 2] == '.' + && index("cCsSm", p[len - 1])) + q = p + (len - 2); + else if (len >= 3 + && p[len - 3] == '.' + && p[len - 2] == 'c' + && p[len - 1] == 'c') + q = p + (len - 3); + else if (len >= 4 + && p[len - 4] == '.' + && p[len - 3] == 'c' + && p[len - 2] == 'x' + && p[len - 1] == 'x') + q = p + (len - 4); + else if (len >= 4 + && p[len - 4] == '.' + && p[len - 3] == 'c' + && p[len - 2] == 'p' + && p[len - 1] == 'p') + q = p + (len - 4); + + /* Supply our own suffix. */ +#ifndef VMS + strcpy (q, ".o"); +#else + strcpy (q, ".obj"); +#endif + + deps_output (p, ':'); + deps_output (in_fname, ' '); + } + } + + file_size_and_mode (f, &st_mode, &st_size); + fp->nominal_fname = fp->fname = in_fname; + fp->lineno = 1; + fp->system_header_p = 0; + /* JF all this is mine about reading pipes and ttys */ + if (! S_ISREG (st_mode)) { + /* Read input from a file that is not a normal disk file. + We cannot preallocate a buffer with the correct size, + so we must read in the file a piece at the time and make it bigger. */ + int size; + int bsize; + int cnt; + + bsize = 2000; + size = 0; + fp->buf = (U_CHAR *) xmalloc (bsize + 2); + for (;;) { + cnt = safe_read (f, (char *) fp->buf + size, bsize - size); + if (cnt < 0) goto perror; /* error! */ + size += cnt; + if (size != bsize) break; /* End of file */ + bsize *= 2; + fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2); + } + fp->length = size; + } else { + /* Read a file whose size we can determine in advance. + For the sake of VMS, st_size is just an upper bound. */ + fp->buf = (U_CHAR *) xmalloc (st_size + 2); + fp->length = safe_read (f, (char *) fp->buf, st_size); + if (fp->length < 0) goto perror; + } + fp->bufp = fp->buf; + fp->if_stack = if_stack; + + /* Make sure data ends with a newline. And put a null after it. */ + + if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n') + /* Backslash-newline at end is not good enough. */ + || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) { + fp->buf[fp->length++] = '\n'; + missing_newline = 1; + } + fp->buf[fp->length] = '\0'; + + /* Unless inhibited, convert trigraphs in the input. */ + + if (!no_trigraphs) + trigraph_pcp (fp); + + /* Now that we know the input file is valid, open the output. */ + + if (!out_fname || !strcmp (out_fname, "")) + out_fname = "stdout"; + else if (! freopen (out_fname, "w", stdout)) + pfatal_with_name (out_fname); + + output_line_directive (fp, &outbuf, 0, same_file); + + /* Scan the -include files before the main input. */ + + no_record_file++; + for (i = 1; i < argc; i++) + if (pend_includes[i]) { + int fd = open (pend_includes[i], O_RDONLY, 0666); + if (fd < 0) { + perror_with_name (pend_includes[i]); + return FATAL_EXIT_CODE; + } + finclude (fd, pend_includes[i], &outbuf, 0, NULL_PTR); + } + no_record_file--; + + /* Scan the input, processing macros and directives. */ + + rescan (&outbuf, 0); + + if (missing_newline) + fp->lineno--; + + if (pedantic && missing_newline) + pedwarn ("file does not end in newline"); + + /* Now we have processed the entire input + Write whichever kind of output has been requested. */ + + if (dump_macros == dump_only) + dump_all_macros (); + else if (! inhibit_output) { + write_output (); + } + + if (print_deps) { + /* Don't actually write the deps file if compilation has failed. */ + if (errors == 0) { + if (deps_file && ! (deps_stream = fopen (deps_file, deps_mode))) + pfatal_with_name (deps_file); + fputs (deps_buffer, deps_stream); + putc ('\n', deps_stream); + if (deps_file) { + if (ferror (deps_stream) || fclose (deps_stream) != 0) + fatal ("I/O error on output"); + } + } + } + + if (pcp_outfile && pcp_outfile != stdout + && (ferror (pcp_outfile) || fclose (pcp_outfile) != 0)) + fatal ("I/O error on `-pcp' output"); + + if (ferror (stdout) || fclose (stdout) != 0) + fatal ("I/O error on output"); + + if (errors) + exit (FATAL_EXIT_CODE); + exit (SUCCESS_EXIT_CODE); + + perror: + pfatal_with_name (in_fname); + return 0; +} + +/* Given a colon-separated list of file names PATH, + add all the names to the search path for include files. */ + +static void +path_include (path) + char *path; +{ + char *p; + + p = path; + + if (*p) + while (1) { + char *q = p; + char *name; + struct file_name_list *dirtmp; + + /* Find the end of this name. */ + while (*q != 0 && *q != PATH_SEPARATOR) q++; + if (p == q) { + /* An empty name in the path stands for the current directory. */ + name = xmalloc (2); + name[0] = '.'; + name[1] = 0; + } else { + /* Otherwise use the directory that is named. */ + name = xmalloc (q - p + 1); + bcopy (p, name, q - p); + name[q - p] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + dirtmp->fname = name; + dirtmp->got_name_map = 0; + append_include_chain (dirtmp, dirtmp); + + /* Advance past this name. */ + p = q; + if (*p == 0) + break; + /* Skip the colon. */ + p++; + } +} + +/* Return the address of the first character in S that equals C. + S is an array of length N, possibly containing '\0's, and followed by '\0'. + Return 0 if there is no such character. Assume that C itself is not '\0'. + If we knew we could use memchr, we could just invoke memchr (S, C, N), + but unfortunately memchr isn't autoconfigured yet. */ + +static U_CHAR * +index0 (s, c, n) + U_CHAR *s; + int c; + size_t n; +{ + char *p = (char *) s; + for (;;) { + char *q = index (p, c); + if (q) + return (U_CHAR *) q; + else { + size_t l = strlen (p); + if (l == n) + return 0; + l++; + p += l; + n -= l; + } + } +} + +/* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF + before main CCCP processing. Name `pcp' is also in honor of the + drugs the trigraph designers must have been on. + + Using an extra pass through the buffer takes a little extra time, + but is infinitely less hairy than trying to handle trigraphs inside + strings, etc. everywhere, and also makes sure that trigraphs are + only translated in the top level of processing. */ + +static void +trigraph_pcp (buf) + FILE_BUF *buf; +{ + register U_CHAR c, *fptr, *bptr, *sptr, *lptr; + int len; + + fptr = bptr = sptr = buf->buf; + lptr = fptr + buf->length; + while ((sptr = index0 (sptr, '?', (size_t) (lptr - sptr))) != NULL) { + if (*++sptr != '?') + continue; + switch (*++sptr) { + case '=': + c = '#'; + break; + case '(': + c = '['; + break; + case '/': + c = '\\'; + break; + case ')': + c = ']'; + break; + case '\'': + c = '^'; + break; + case '<': + c = '{'; + break; + case '!': + c = '|'; + break; + case '>': + c = '}'; + break; + case '-': + c = '~'; + break; + case '?': + sptr--; + continue; + default: + continue; + } + len = sptr - fptr - 2; + + /* BSD doc says bcopy () works right for overlapping strings. In ANSI + C, this will be memmove (). */ + if (bptr != fptr && len > 0) + bcopy ((char *) fptr, (char *) bptr, len); + + bptr += len; + *bptr++ = c; + fptr = ++sptr; + } + len = buf->length - (fptr - buf->buf); + if (bptr != fptr && len > 0) + bcopy ((char *) fptr, (char *) bptr, len); + buf->length -= fptr - bptr; + buf->buf[buf->length] = '\0'; + if (warn_trigraphs && fptr != bptr) + warning_with_line (0, "%d trigraph(s) encountered", (fptr - bptr) / 2); +} + +/* Move all backslash-newline pairs out of embarrassing places. + Exchange all such pairs following BP + with any potentially-embarrassing characters that follow them. + Potentially-embarrassing characters are / and * + (because a backslash-newline inside a comment delimiter + would cause it not to be recognized). */ + +static void +newline_fix (bp) + U_CHAR *bp; +{ + register U_CHAR *p = bp; + + /* First count the backslash-newline pairs here. */ + + while (p[0] == '\\' && p[1] == '\n') + p += 2; + + /* What follows the backslash-newlines is not embarrassing. */ + + if (*p != '/' && *p != '*') + return; + + /* Copy all potentially embarrassing characters + that follow the backslash-newline pairs + down to where the pairs originally started. */ + + while (*p == '*' || *p == '/') + *bp++ = *p++; + + /* Now write the same number of pairs after the embarrassing chars. */ + while (bp < p) { + *bp++ = '\\'; + *bp++ = '\n'; + } +} + +/* Like newline_fix but for use within a directive-name. + Move any backslash-newlines up past any following symbol constituents. */ + +static void +name_newline_fix (bp) + U_CHAR *bp; +{ + register U_CHAR *p = bp; + + /* First count the backslash-newline pairs here. */ + while (p[0] == '\\' && p[1] == '\n') + p += 2; + + /* What follows the backslash-newlines is not embarrassing. */ + + if (!is_idchar[*p]) + return; + + /* Copy all potentially embarrassing characters + that follow the backslash-newline pairs + down to where the pairs originally started. */ + + while (is_idchar[*p]) + *bp++ = *p++; + + /* Now write the same number of pairs after the embarrassing chars. */ + while (bp < p) { + *bp++ = '\\'; + *bp++ = '\n'; + } +} + +/* Look for lint commands in comments. + + When we come in here, ibp points into a comment. Limit is as one expects. + scan within the comment -- it should start, after lwsp, with a lint command. + If so that command is returned as a (constant) string. + + Upon return, any arg will be pointed to with argstart and will be + arglen long. Note that we don't parse that arg since it will just + be printed out again. +*/ + +static char * +get_lintcmd (ibp, limit, argstart, arglen, cmdlen) + register U_CHAR *ibp; + register U_CHAR *limit; + U_CHAR **argstart; /* point to command arg */ + int *arglen, *cmdlen; /* how long they are */ +{ + long linsize; + register U_CHAR *numptr; /* temp for arg parsing */ + + *arglen = 0; + + SKIP_WHITE_SPACE (ibp); + + if (ibp >= limit) return NULL; + + linsize = limit - ibp; + + /* Oh, I wish C had lexical functions... hell, I'll just open-code the set */ + if ((linsize >= 10) && !bcmp (ibp, "NOTREACHED", 10)) { + *cmdlen = 10; + return "NOTREACHED"; + } + if ((linsize >= 8) && !bcmp (ibp, "ARGSUSED", 8)) { + *cmdlen = 8; + return "ARGSUSED"; + } + if ((linsize >= 11) && !bcmp (ibp, "LINTLIBRARY", 11)) { + *cmdlen = 11; + return "LINTLIBRARY"; + } + if ((linsize >= 7) && !bcmp (ibp, "VARARGS", 7)) { + *cmdlen = 7; + ibp += 7; linsize -= 7; + if ((linsize == 0) || ! isdigit (*ibp)) return "VARARGS"; + + /* OK, read a number */ + for (numptr = *argstart = ibp; (numptr < limit) && isdigit (*numptr); + numptr++); + *arglen = numptr - *argstart; + return "VARARGS"; + } + return NULL; +} + +/* + * The main loop of the program. + * + * Read characters from the input stack, transferring them to the + * output buffer OP. + * + * Macros are expanded and push levels on the input stack. + * At the end of such a level it is popped off and we keep reading. + * At the end of any other kind of level, we return. + * #-directives are handled, except within macros. + * + * If OUTPUT_MARKS is nonzero, keep Newline markers found in the input + * and insert them when appropriate. This is set while scanning macro + * arguments before substitution. It is zero when scanning for final output. + * There are three types of Newline markers: + * * Newline - follows a macro name that was not expanded + * because it appeared inside an expansion of the same macro. + * This marker prevents future expansion of that identifier. + * When the input is rescanned into the final output, these are deleted. + * These are also deleted by ## concatenation. + * * Newline Space (or Newline and any other whitespace character) + * stands for a place that tokens must be separated or whitespace + * is otherwise desirable, but where the ANSI standard specifies there + * is no whitespace. This marker turns into a Space (or whichever other + * whitespace char appears in the marker) in the final output, + * but it turns into nothing in an argument that is stringified with #. + * Such stringified arguments are the only place where the ANSI standard + * specifies with precision that whitespace may not appear. + * + * During this function, IP->bufp is kept cached in IBP for speed of access. + * Likewise, OP->bufp is kept in OBP. Before calling a subroutine + * IBP, IP and OBP must be copied back to memory. IP and IBP are + * copied back with the RECACHE macro. OBP must be copied back from OP->bufp + * explicitly, and before RECACHE, since RECACHE uses OBP. + */ + +static void +rescan (op, output_marks) + FILE_BUF *op; + int output_marks; +{ + /* Character being scanned in main loop. */ + register U_CHAR c; + + /* Length of pending accumulated identifier. */ + register int ident_length = 0; + + /* Hash code of pending accumulated identifier. */ + register int hash = 0; + + /* Current input level (&instack[indepth]). */ + FILE_BUF *ip; + + /* Pointer for scanning input. */ + register U_CHAR *ibp; + + /* Pointer to end of input. End of scan is controlled by LIMIT. */ + register U_CHAR *limit; + + /* Pointer for storing output. */ + register U_CHAR *obp; + + /* REDO_CHAR is nonzero if we are processing an identifier + after backing up over the terminating character. + Sometimes we process an identifier without backing up over + the terminating character, if the terminating character + is not special. Backing up is done so that the terminating character + will be dispatched on again once the identifier is dealt with. */ + int redo_char = 0; + + /* 1 if within an identifier inside of which a concatenation + marker (Newline -) has been seen. */ + int concatenated = 0; + + /* While scanning a comment or a string constant, + this records the line it started on, for error messages. */ + int start_line; + + /* Record position of last `real' newline. */ + U_CHAR *beg_of_line; + +/* Pop the innermost input stack level, assuming it is a macro expansion. */ + +#define POPMACRO \ +do { ip->macro->type = T_MACRO; \ + if (ip->free_ptr) free (ip->free_ptr); \ + --indepth; } while (0) + +/* Reload `rescan's local variables that describe the current + level of the input stack. */ + +#define RECACHE \ +do { ip = &instack[indepth]; \ + ibp = ip->bufp; \ + limit = ip->buf + ip->length; \ + op->bufp = obp; \ + check_expand (op, limit - ibp); \ + beg_of_line = 0; \ + obp = op->bufp; } while (0) + + if (no_output && instack[indepth].fname != 0) + skip_if_group (&instack[indepth], 1, NULL); + + obp = op->bufp; + RECACHE; + + beg_of_line = ibp; + + /* Our caller must always put a null after the end of + the input at each input stack level. */ + if (*limit != 0) + abort (); + + while (1) { + c = *ibp++; + *obp++ = c; + + switch (c) { + case '\\': + if (*ibp == '\n' && !ip->macro) { + /* At the top level, always merge lines ending with backslash-newline, + even in middle of identifier. But do not merge lines in a macro, + since backslash might be followed by a newline-space marker. */ + ++ibp; + ++ip->lineno; + --obp; /* remove backslash from obuf */ + break; + } + /* If ANSI, backslash is just another character outside a string. */ + if (!traditional) + goto randomchar; + /* Otherwise, backslash suppresses specialness of following char, + so copy it here to prevent the switch from seeing it. + But first get any pending identifier processed. */ + if (ident_length > 0) + goto specialchar; + if (ibp < limit) + *obp++ = *ibp++; + break; + + case '%': + if (ident_length || ip->macro || traditional) + goto randomchar; + while (*ibp == '\\' && ibp[1] == '\n') { + ibp += 2; + ++ip->lineno; + } + if (*ibp != ':') + break; + /* Treat this %: digraph as if it were #. */ + /* Fall through. */ + + case '#': + if (assertions_flag) { + if (ident_length) + goto specialchar; + /* Copy #foo (bar lose) without macro expansion. */ + obp[-1] = '#'; /* In case it was '%'. */ + SKIP_WHITE_SPACE (ibp); + while (is_idchar[*ibp]) + *obp++ = *ibp++; + SKIP_WHITE_SPACE (ibp); + if (*ibp == '(') { + ip->bufp = ibp; + skip_paren_group (ip); + bcopy ((char *) ibp, (char *) obp, ip->bufp - ibp); + obp += ip->bufp - ibp; + ibp = ip->bufp; + } + break; + } + + /* If this is expanding a macro definition, don't recognize + preprocessing directives. */ + if (ip->macro != 0) + goto randomchar; + /* If this is expand_into_temp_buffer, + don't recognize them either. Warn about them + only after an actual newline at this level, + not at the beginning of the input level. */ + if (! ip->fname) { + if (ip->buf != beg_of_line) + warning ("preprocessing directive not recognized within macro arg"); + goto randomchar; + } + if (ident_length) + goto specialchar; + + + /* # keyword: a # must be first nonblank char on the line */ + if (beg_of_line == 0) + goto randomchar; + { + U_CHAR *bp; + + /* Scan from start of line, skipping whitespace, comments + and backslash-newlines, and see if we reach this #. + If not, this # is not special. */ + bp = beg_of_line; + /* If -traditional, require # to be at beginning of line. */ + if (!traditional) { + while (1) { + if (is_hor_space[*bp]) + bp++; + else if (*bp == '\\' && bp[1] == '\n') + bp += 2; + else if (*bp == '/' && bp[1] == '*') { + bp += 2; + while (!(*bp == '*' && bp[1] == '/')) + bp++; + bp += 2; + } + /* There is no point in trying to deal with C++ // comments here, + because if there is one, then this # must be part of the + comment and we would never reach here. */ + else break; + } + if (c == '%') { + if (bp[0] != '%') + break; + while (bp[1] == '\\' && bp[2] == '\n') + bp += 2; + if (bp + 1 != ibp) + break; + /* %: appears at start of line; skip past the ':' too. */ + bp++; + ibp++; + } + } + if (bp + 1 != ibp) + goto randomchar; + } + + /* This # can start a directive. */ + + --obp; /* Don't copy the '#' */ + + ip->bufp = ibp; + op->bufp = obp; + if (! handle_directive (ip, op)) { +#ifdef USE_C_ALLOCA + alloca (0); +#endif + /* Not a known directive: treat it as ordinary text. + IP, OP, IBP, etc. have not been changed. */ + if (no_output && instack[indepth].fname) { + /* If not generating expanded output, + what we do with ordinary text is skip it. + Discard everything until next # directive. */ + skip_if_group (&instack[indepth], 1, 0); + RECACHE; + beg_of_line = ibp; + break; + } + *obp++ = '#'; /* Copy # (even if it was originally %:). */ + /* Don't expand an identifier that could be a macro directive. + (Section 3.8.3 of the ANSI C standard) */ + SKIP_WHITE_SPACE (ibp); + if (is_idstart[*ibp]) + { + *obp++ = *ibp++; + while (is_idchar[*ibp]) + *obp++ = *ibp++; + } + goto randomchar; + } +#ifdef USE_C_ALLOCA + alloca (0); +#endif + /* A # directive has been successfully processed. */ + /* If not generating expanded output, ignore everything until + next # directive. */ + if (no_output && instack[indepth].fname) + skip_if_group (&instack[indepth], 1, 0); + obp = op->bufp; + RECACHE; + beg_of_line = ibp; + break; + + case '\"': /* skip quoted string */ + case '\'': + /* A single quoted string is treated like a double -- some + programs (e.g., troff) are perverse this way */ + + if (ident_length) + goto specialchar; + + start_line = ip->lineno; + + /* Skip ahead to a matching quote. */ + + while (1) { + if (ibp >= limit) { + if (ip->macro != 0) { + /* try harder: this string crosses a macro expansion boundary. + This can happen naturally if -traditional. + Otherwise, only -D can make a macro with an unmatched quote. */ + POPMACRO; + RECACHE; + continue; + } + if (!traditional) { + error_with_line (line_for_error (start_line), + "unterminated string or character constant"); + error_with_line (multiline_string_line, + "possible real start of unterminated constant"); + multiline_string_line = 0; + } + break; + } + *obp++ = *ibp; + switch (*ibp++) { + case '\n': + ++ip->lineno; + ++op->lineno; + /* Traditionally, end of line ends a string constant with no error. + So exit the loop and record the new line. */ + if (traditional) { + beg_of_line = ibp; + goto while2end; + } + if (c == '\'') { + error_with_line (line_for_error (start_line), + "unterminated character constant"); + goto while2end; + } + if (pedantic && multiline_string_line == 0) { + pedwarn_with_line (line_for_error (start_line), + "string constant runs past end of line"); + } + if (multiline_string_line == 0) + multiline_string_line = ip->lineno - 1; + break; + + case '\\': + if (ibp >= limit) + break; + if (*ibp == '\n') { + /* Backslash newline is replaced by nothing at all, + but keep the line counts correct. */ + --obp; + ++ibp; + ++ip->lineno; + } else { + /* ANSI stupidly requires that in \\ the second \ + is *not* prevented from combining with a newline. */ + while (*ibp == '\\' && ibp[1] == '\n') { + ibp += 2; + ++ip->lineno; + } + *obp++ = *ibp++; + } + break; + + case '\"': + case '\'': + if (ibp[-1] == c) + goto while2end; + break; + } + } + while2end: + break; + + case '/': + if (*ibp == '\\' && ibp[1] == '\n') + newline_fix (ibp); + + if (*ibp != '*' + && !(cplusplus_comments && *ibp == '/')) + goto randomchar; + if (ip->macro != 0) + goto randomchar; + if (ident_length) + goto specialchar; + + if (*ibp == '/') { + /* C++ style comment... */ + start_line = ip->lineno; + + /* Comments are equivalent to spaces. */ + if (! put_out_comments) + obp[-1] = ' '; + + { + U_CHAR *before_bp = ibp; + + while (++ibp < limit) { + if (*ibp == '\n') { + if (ibp[-1] != '\\') { + if (put_out_comments) { + bcopy ((char *) before_bp, (char *) obp, ibp - before_bp); + obp += ibp - before_bp; + } + break; + } + ++ip->lineno; + /* Copy the newline into the output buffer, in order to + avoid the pain of a #line every time a multiline comment + is seen. */ + if (!put_out_comments) + *obp++ = '\n'; + ++op->lineno; + } + } + break; + } + } + + /* Ordinary C comment. Skip it, optionally copying it to output. */ + + start_line = ip->lineno; + + ++ibp; /* Skip the star. */ + + /* If this cpp is for lint, we peek inside the comments: */ + if (for_lint) { + U_CHAR *argbp; + int cmdlen, arglen; + char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen); + + if (lintcmd != NULL) { + op->bufp = obp; + check_expand (op, cmdlen + arglen + 14); + obp = op->bufp; + /* I believe it is always safe to emit this newline: */ + obp[-1] = '\n'; + bcopy ("#pragma lint ", (char *) obp, 13); + obp += 13; + bcopy (lintcmd, (char *) obp, cmdlen); + obp += cmdlen; + + if (arglen != 0) { + *(obp++) = ' '; + bcopy (argbp, (char *) obp, arglen); + obp += arglen; + } + + /* OK, now bring us back to the state we were in before we entered + this branch. We need #line because the #pragma's newline always + messes up the line count. */ + op->bufp = obp; + output_line_directive (ip, op, 0, same_file); + check_expand (op, limit - ibp + 2); + obp = op->bufp; + *(obp++) = '/'; + } + } + + /* Comments are equivalent to spaces. + Note that we already output the slash; we might not want it. + For -traditional, a comment is equivalent to nothing. */ + if (! put_out_comments) { + if (traditional) + obp--; + else + obp[-1] = ' '; + } + else + *obp++ = '*'; + + { + U_CHAR *before_bp = ibp; + + while (ibp < limit) { + switch (*ibp++) { + case '/': + if (warn_comments && *ibp == '*') + warning ("`/*' within comment"); + break; + case '*': + if (*ibp == '\\' && ibp[1] == '\n') + newline_fix (ibp); + if (ibp >= limit || *ibp == '/') + goto comment_end; + break; + case '\n': + ++ip->lineno; + /* Copy the newline into the output buffer, in order to + avoid the pain of a #line every time a multiline comment + is seen. */ + if (!put_out_comments) + *obp++ = '\n'; + ++op->lineno; + } + } + comment_end: + + if (ibp >= limit) + error_with_line (line_for_error (start_line), + "unterminated comment"); + else { + ibp++; + if (put_out_comments) { + bcopy ((char *) before_bp, (char *) obp, ibp - before_bp); + obp += ibp - before_bp; + } + } + } + break; + + case '$': + if (!dollars_in_ident) + goto randomchar; + goto letter; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + /* If digit is not part of identifier, it starts a number, + which means that following letters are not an identifier. + "0x5" does not refer to an identifier "x5". + So copy all alphanumerics that follow without accumulating + as an identifier. Periods also, for sake of "3.e7". */ + + if (ident_length == 0) { + for (;;) { + while (ibp[0] == '\\' && ibp[1] == '\n') { + ++ip->lineno; + ibp += 2; + } + c = *ibp++; + if (!is_idchar[c] && c != '.') { + --ibp; + break; + } + *obp++ = c; + /* A sign can be part of a preprocessing number + if it follows an e. */ + if (c == 'e' || c == 'E') { + while (ibp[0] == '\\' && ibp[1] == '\n') { + ++ip->lineno; + ibp += 2; + } + if (*ibp == '+' || *ibp == '-') { + *obp++ = *ibp++; + /* But traditional C does not let the token go past the sign. */ + if (traditional) + break; + } + } + } + break; + } + /* fall through */ + + case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + letter: + ident_length++; + /* Compute step of hash function, to avoid a proc call on every token */ + hash = HASHSTEP (hash, c); + break; + + case '\n': + if (ip->fname == 0 && *ibp == '-') { + /* Newline - inhibits expansion of preceding token. + If expanding a macro arg, we keep the newline -. + In final output, it is deleted. + We recognize Newline - in macro bodies and macro args. */ + if (! concatenated) { + ident_length = 0; + hash = 0; + } + ibp++; + if (!output_marks) { + obp--; + } else { + /* If expanding a macro arg, keep the newline -. */ + *obp++ = '-'; + } + break; + } + + /* If reprocessing a macro expansion, newline is a special marker. */ + else if (ip->macro != 0) { + /* Newline White is a "funny space" to separate tokens that are + supposed to be separate but without space between. + Here White means any whitespace character. + Newline - marks a recursive macro use that is not + supposed to be expandable. */ + + if (is_space[*ibp]) { + /* Newline Space does not prevent expansion of preceding token + so expand the preceding token and then come back. */ + if (ident_length > 0) + goto specialchar; + + /* If generating final output, newline space makes a space. */ + if (!output_marks) { + obp[-1] = *ibp++; + /* And Newline Newline makes a newline, so count it. */ + if (obp[-1] == '\n') + op->lineno++; + } else { + /* If expanding a macro arg, keep the newline space. + If the arg gets stringified, newline space makes nothing. */ + *obp++ = *ibp++; + } + } else abort (); /* Newline followed by something random? */ + break; + } + + /* If there is a pending identifier, handle it and come back here. */ + if (ident_length > 0) + goto specialchar; + + beg_of_line = ibp; + + /* Update the line counts and output a #line if necessary. */ + ++ip->lineno; + ++op->lineno; + if (ip->lineno != op->lineno) { + op->bufp = obp; + output_line_directive (ip, op, 1, same_file); + check_expand (op, limit - ibp); + obp = op->bufp; + } + break; + + /* Come here either after (1) a null character that is part of the input + or (2) at the end of the input, because there is a null there. */ + case 0: + if (ibp <= limit) + /* Our input really contains a null character. */ + goto randomchar; + + /* At end of a macro-expansion level, pop it and read next level. */ + if (ip->macro != 0) { + obp--; + ibp--; + /* If traditional, and we have an identifier that ends here, + process it now, so we get the right error for recursion. */ + if (traditional && ident_length + && ! is_idchar[*instack[indepth - 1].bufp]) { + redo_char = 1; + goto randomchar; + } + POPMACRO; + RECACHE; + break; + } + + /* If we don't have a pending identifier, + return at end of input. */ + if (ident_length == 0) { + obp--; + ibp--; + op->bufp = obp; + ip->bufp = ibp; + goto ending; + } + + /* If we do have a pending identifier, just consider this null + a special character and arrange to dispatch on it again. + The second time, IDENT_LENGTH will be zero so we will return. */ + + /* Fall through */ + +specialchar: + + /* Handle the case of a character such as /, ', " or null + seen following an identifier. Back over it so that + after the identifier is processed the special char + will be dispatched on again. */ + + ibp--; + obp--; + redo_char = 1; + + default: + +randomchar: + + if (ident_length > 0) { + register HASHNODE *hp; + + /* We have just seen an identifier end. If it's a macro, expand it. + + IDENT_LENGTH is the length of the identifier + and HASH is its hash code. + + The identifier has already been copied to the output, + so if it is a macro we must remove it. + + If REDO_CHAR is 0, the char that terminated the identifier + has been skipped in the output and the input. + OBP-IDENT_LENGTH-1 points to the identifier. + If the identifier is a macro, we must back over the terminator. + + If REDO_CHAR is 1, the terminating char has already been + backed over. OBP-IDENT_LENGTH points to the identifier. */ + + if (!pcp_outfile || pcp_inside_if) { + for (hp = hashtab[MAKE_POS (hash) % HASHSIZE]; hp != NULL; + hp = hp->next) { + + if (hp->length == ident_length) { + int obufp_before_macroname; + int op_lineno_before_macroname; + register int i = ident_length; + register U_CHAR *p = hp->name; + register U_CHAR *q = obp - i; + int disabled; + + if (! redo_char) + q--; + + do { /* All this to avoid a strncmp () */ + if (*p++ != *q++) + goto hashcollision; + } while (--i); + + /* We found a use of a macro name. + see if the context shows it is a macro call. */ + + /* Back up over terminating character if not already done. */ + if (! redo_char) { + ibp--; + obp--; + } + + /* Save this as a displacement from the beginning of the output + buffer. We can not save this as a position in the output + buffer, because it may get realloc'ed by RECACHE. */ + obufp_before_macroname = (obp - op->buf) - ident_length; + op_lineno_before_macroname = op->lineno; + + if (hp->type == T_PCSTRING) { + pcstring_used (hp); /* Mark the definition of this key + as needed, ensuring that it + will be output. */ + break; /* Exit loop, since the key cannot have a + definition any longer. */ + } + + /* Record whether the macro is disabled. */ + disabled = hp->type == T_DISABLED; + + /* This looks like a macro ref, but if the macro was disabled, + just copy its name and put in a marker if requested. */ + + if (disabled) { +#if 0 + /* This error check caught useful cases such as + #define foo(x,y) bar (x (y,0), y) + foo (foo, baz) */ + if (traditional) + error ("recursive use of macro `%s'", hp->name); +#endif + + if (output_marks) { + check_expand (op, limit - ibp + 2); + *obp++ = '\n'; + *obp++ = '-'; + } + break; + } + + /* If macro wants an arglist, verify that a '(' follows. + first skip all whitespace, copying it to the output + after the macro name. Then, if there is no '(', + decide this is not a macro call and leave things that way. */ + if ((hp->type == T_MACRO || hp->type == T_DISABLED) + && hp->value.defn->nargs >= 0) + { + U_CHAR *old_ibp = ibp; + U_CHAR *old_obp = obp; + int old_iln = ip->lineno; + int old_oln = op->lineno; + + while (1) { + /* Scan forward over whitespace, copying it to the output. */ + if (ibp == limit && ip->macro != 0) { + POPMACRO; + RECACHE; + old_ibp = ibp; + old_obp = obp; + old_iln = ip->lineno; + old_oln = op->lineno; + } + /* A comment: copy it unchanged or discard it. */ + else if (*ibp == '/' && ibp[1] == '*') { + if (put_out_comments) { + *obp++ = '/'; + *obp++ = '*'; + } else if (! traditional) { + *obp++ = ' '; + } + ibp += 2; + while (ibp + 1 != limit + && !(ibp[0] == '*' && ibp[1] == '/')) { + /* We need not worry about newline-marks, + since they are never found in comments. */ + if (*ibp == '\n') { + /* Newline in a file. Count it. */ + ++ip->lineno; + ++op->lineno; + } + if (put_out_comments) + *obp++ = *ibp++; + else + ibp++; + } + ibp += 2; + if (put_out_comments) { + *obp++ = '*'; + *obp++ = '/'; + } + } + else if (is_space[*ibp]) { + *obp++ = *ibp++; + if (ibp[-1] == '\n') { + if (ip->macro == 0) { + /* Newline in a file. Count it. */ + ++ip->lineno; + ++op->lineno; + } else if (!output_marks) { + /* A newline mark, and we don't want marks + in the output. If it is newline-hyphen, + discard it entirely. Otherwise, it is + newline-whitechar, so keep the whitechar. */ + obp--; + if (*ibp == '-') + ibp++; + else { + if (*ibp == '\n') + ++op->lineno; + *obp++ = *ibp++; + } + } else { + /* A newline mark; copy both chars to the output. */ + *obp++ = *ibp++; + } + } + } + else break; + } + if (*ibp != '(') { + /* It isn't a macro call. + Put back the space that we just skipped. */ + ibp = old_ibp; + obp = old_obp; + ip->lineno = old_iln; + op->lineno = old_oln; + /* Exit the for loop. */ + break; + } + } + + /* This is now known to be a macro call. + Discard the macro name from the output, + along with any following whitespace just copied, + but preserve newlines if not outputting marks since this + is more likely to do the right thing with line numbers. */ + obp = op->buf + obufp_before_macroname; + if (output_marks) + op->lineno = op_lineno_before_macroname; + else { + int newlines = op->lineno - op_lineno_before_macroname; + while (0 < newlines--) + *obp++ = '\n'; + } + + /* Prevent accidental token-pasting with a character + before the macro call. */ + if (!traditional && obp != op->buf) { + switch (obp[-1]) { + case '!': case '%': case '&': case '*': + case '+': case '-': case '/': case ':': + case '<': case '=': case '>': case '^': + case '|': + /* If we are expanding a macro arg, make a newline marker + to separate the tokens. If we are making real output, + a plain space will do. */ + if (output_marks) + *obp++ = '\n'; + *obp++ = ' '; + } + } + + /* Expand the macro, reading arguments as needed, + and push the expansion on the input stack. */ + ip->bufp = ibp; + op->bufp = obp; + macroexpand (hp, op); + + /* Reexamine input stack, since macroexpand has pushed + a new level on it. */ + obp = op->bufp; + RECACHE; + break; + } +hashcollision: + ; + } /* End hash-table-search loop */ + } + ident_length = hash = 0; /* Stop collecting identifier */ + redo_char = 0; + concatenated = 0; + } /* End if (ident_length > 0) */ + } /* End switch */ + } /* End per-char loop */ + + /* Come here to return -- but first give an error message + if there was an unterminated successful conditional. */ + ending: + if (if_stack != ip->if_stack) + { + char *str; + + switch (if_stack->type) + { + case T_IF: + str = "if"; + break; + case T_IFDEF: + str = "ifdef"; + break; + case T_IFNDEF: + str = "ifndef"; + break; + case T_ELSE: + str = "else"; + break; + case T_ELIF: + str = "elif"; + break; + default: + abort (); + } + + error_with_line (line_for_error (if_stack->lineno), + "unterminated `#%s' conditional", str); + } + if_stack = ip->if_stack; +} + +/* + * Rescan a string into a temporary buffer and return the result + * as a FILE_BUF. Note this function returns a struct, not a pointer. + * + * OUTPUT_MARKS nonzero means keep Newline markers found in the input + * and insert such markers when appropriate. See `rescan' for details. + * OUTPUT_MARKS is 1 for macroexpanding a macro argument separately + * before substitution; it is 0 for other uses. + */ +static FILE_BUF +expand_to_temp_buffer (buf, limit, output_marks, assertions) + U_CHAR *buf, *limit; + int output_marks, assertions; +{ + register FILE_BUF *ip; + FILE_BUF obuf; + int length = limit - buf; + U_CHAR *buf1; + int odepth = indepth; + int save_assertions_flag = assertions_flag; + + assertions_flag = assertions; + + if (length < 0) + abort (); + + /* Set up the input on the input stack. */ + + buf1 = (U_CHAR *) alloca (length + 1); + { + register U_CHAR *p1 = buf; + register U_CHAR *p2 = buf1; + + while (p1 != limit) + *p2++ = *p1++; + } + buf1[length] = 0; + + /* Set up to receive the output. */ + + obuf.length = length * 2 + 100; /* Usually enough. Why be stingy? */ + obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length); + obuf.fname = 0; + obuf.macro = 0; + obuf.free_ptr = 0; + + CHECK_DEPTH ({return obuf;}); + + ++indepth; + + ip = &instack[indepth]; + ip->fname = 0; + ip->nominal_fname = 0; + ip->system_header_p = 0; + ip->macro = 0; + ip->free_ptr = 0; + ip->length = length; + ip->buf = ip->bufp = buf1; + ip->if_stack = if_stack; + + ip->lineno = obuf.lineno = 1; + + /* Scan the input, create the output. */ + rescan (&obuf, output_marks); + + /* Pop input stack to original state. */ + --indepth; + + if (indepth != odepth) + abort (); + + /* Record the output. */ + obuf.length = obuf.bufp - obuf.buf; + + assertions_flag = save_assertions_flag; + return obuf; +} + +/* + * Process a # directive. Expects IP->bufp to point after the '#', as in + * `#define foo bar'. Passes to the directive handler + * (do_define, do_include, etc.): the addresses of the 1st and + * last chars of the directive (starting immediately after the # + * keyword), plus op and the keyword table pointer. If the directive + * contains comments it is copied into a temporary buffer sans comments + * and the temporary buffer is passed to the directive handler instead. + * Likewise for backslash-newlines. + * + * Returns nonzero if this was a known # directive. + * Otherwise, returns zero, without advancing the input pointer. + */ + +static int +handle_directive (ip, op) + FILE_BUF *ip, *op; +{ + register U_CHAR *bp, *cp; + register struct directive *kt; + register int ident_length; + U_CHAR *resume_p; + + /* Nonzero means we must copy the entire directive + to get rid of comments or backslash-newlines. */ + int copy_directive = 0; + + U_CHAR *ident, *after_ident; + + bp = ip->bufp; + + /* Record where the directive started. do_xifdef needs this. */ + directive_start = bp - 1; + + /* Skip whitespace and \-newline. */ + while (1) { + if (is_hor_space[*bp]) { + if (*bp != ' ' && *bp != '\t' && pedantic) + pedwarn ("%s in preprocessing directive", char_name[*bp]); + bp++; + } else if (*bp == '/' && (bp[1] == '*' + || (cplusplus_comments && bp[1] == '/'))) { + ip->bufp = bp + 2; + skip_to_end_of_comment (ip, &ip->lineno, 0); + bp = ip->bufp; + } else if (*bp == '\\' && bp[1] == '\n') { + bp += 2; ip->lineno++; + } else break; + } + + /* Now find end of directive name. + If we encounter a backslash-newline, exchange it with any following + symbol-constituents so that we end up with a contiguous name. */ + + cp = bp; + while (1) { + if (is_idchar[*cp]) + cp++; + else { + if (*cp == '\\' && cp[1] == '\n') + name_newline_fix (cp); + if (is_idchar[*cp]) + cp++; + else break; + } + } + ident_length = cp - bp; + ident = bp; + after_ident = cp; + + /* A line of just `#' becomes blank. */ + + if (ident_length == 0 && *after_ident == '\n') { + ip->bufp = after_ident; + return 1; + } + + if (ident_length == 0 || !is_idstart[*ident]) { + U_CHAR *p = ident; + while (is_idchar[*p]) { + if (*p < '0' || *p > '9') + break; + p++; + } + /* Handle # followed by a line number. */ + if (p != ident && !is_idchar[*p]) { + static struct directive line_directive_table[] = { + { 4, do_line, "line", T_LINE}, + }; + if (pedantic) + pedwarn ("`#' followed by integer"); + after_ident = ident; + kt = line_directive_table; + goto old_linenum; + } + + /* Avoid error for `###' and similar cases unless -pedantic. */ + if (p == ident) { + while (*p == '#' || is_hor_space[*p]) p++; + if (*p == '\n') { + if (pedantic && !lang_asm) + warning ("invalid preprocessing directive"); + return 0; + } + } + + if (!lang_asm) + error ("invalid preprocessing directive name"); + + return 0; + } + + /* + * Decode the keyword and call the appropriate expansion + * routine, after moving the input pointer up to the next line. + */ + for (kt = directive_table; kt->length > 0; kt++) { + if (kt->length == ident_length && !bcmp (kt->name, ident, ident_length)) { + register U_CHAR *buf; + register U_CHAR *limit; + int unterminated; + int junk; + int *already_output; + + /* Nonzero means do not delete comments within the directive. + #define needs this when -traditional. */ + int keep_comments; + + old_linenum: + + limit = ip->buf + ip->length; + unterminated = 0; + already_output = 0; + keep_comments = traditional && kt->traditional_comments; + /* #import is defined only in Objective C, or when on the NeXT. */ + if (kt->type == T_IMPORT + && !(objc || lookup ((U_CHAR *) "__NeXT__", -1, -1))) + break; + + /* Find the end of this directive (first newline not backslashed + and not in a string or comment). + Set COPY_DIRECTIVE if the directive must be copied + (it contains a backslash-newline or a comment). */ + + buf = bp = after_ident; + while (bp < limit) { + register U_CHAR c = *bp++; + switch (c) { + case '\\': + if (bp < limit) { + if (*bp == '\n') { + ip->lineno++; + copy_directive = 1; + bp++; + } else if (traditional) + bp++; + } + break; + + case '\'': + case '\"': + bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, ©_directive, &unterminated); + /* Don't bother calling the directive if we already got an error + message due to unterminated string. Skip everything and pretend + we called the directive. */ + if (unterminated) { + if (traditional) { + /* Traditional preprocessing permits unterminated strings. */ + ip->bufp = bp; + goto endloop1; + } + ip->bufp = bp; + return 1; + } + break; + + /* <...> is special for #include. */ + case '<': + if (!kt->angle_brackets) + break; + while (bp < limit && *bp != '>' && *bp != '\n') { + if (*bp == '\\' && bp[1] == '\n') { + ip->lineno++; + copy_directive = 1; + bp++; + } + bp++; + } + break; + + case '/': + if (*bp == '\\' && bp[1] == '\n') + newline_fix (bp); + if (*bp == '*' + || (cplusplus_comments && *bp == '/')) { + U_CHAR *obp = bp - 1; + ip->bufp = bp + 1; + skip_to_end_of_comment (ip, &ip->lineno, 0); + bp = ip->bufp; + /* No need to copy the directive because of a comment at the end; + just don't include the comment in the directive. */ + if (bp == limit || *bp == '\n') { + bp = obp; + goto endloop1; + } + /* Don't remove the comments if -traditional. */ + if (! keep_comments) + copy_directive++; + } + break; + + case '\f': + case '\r': + case '\v': + if (pedantic) + pedwarn ("%s in preprocessing directive", char_name[c]); + break; + + case '\n': + --bp; /* Point to the newline */ + ip->bufp = bp; + goto endloop1; + } + } + ip->bufp = bp; + + endloop1: + resume_p = ip->bufp; + /* BP is the end of the directive. + RESUME_P is the next interesting data after the directive. + A comment may come between. */ + + /* If a directive should be copied through, and -E was given, + pass it through before removing comments. */ + if (!no_output && kt->pass_thru && put_out_comments) { + int len; + + /* Output directive name. */ + check_expand (op, kt->length + 2); + /* Make sure # is at the start of a line */ + if (op->bufp > op->buf && op->bufp[-1] != '\n') { + op->lineno++; + *op->bufp++ = '\n'; + } + *op->bufp++ = '#'; + bcopy (kt->name, op->bufp, kt->length); + op->bufp += kt->length; + + /* Output arguments. */ + len = (bp - buf); + check_expand (op, len); + bcopy (buf, (char *) op->bufp, len); + op->bufp += len; + /* Take account of any (escaped) newlines just output. */ + while (--len >= 0) + if (buf[len] == '\n') + op->lineno++; + + already_output = &junk; + } /* Don't we need a newline or #line? */ + + if (copy_directive) { + register U_CHAR *xp = buf; + /* Need to copy entire directive into temp buffer before dispatching */ + + cp = (U_CHAR *) alloca (bp - buf + 5); /* room for directive plus + some slop */ + buf = cp; + + /* Copy to the new buffer, deleting comments + and backslash-newlines (and whitespace surrounding the latter). */ + + while (xp < bp) { + register U_CHAR c = *xp++; + *cp++ = c; + + switch (c) { + case '\n': + abort (); /* A bare newline should never part of the line. */ + break; + + /* <...> is special for #include. */ + case '<': + if (!kt->angle_brackets) + break; + while (xp < bp && c != '>') { + c = *xp++; + if (c == '\\' && xp < bp && *xp == '\n') + xp++; + else + *cp++ = c; + } + break; + + case '\\': + if (*xp == '\n') { + xp++; + cp--; + if (cp != buf && is_hor_space[cp[-1]]) { + while (cp - 1 != buf && is_hor_space[cp[-2]]) + cp--; + SKIP_WHITE_SPACE (xp); + } else if (is_hor_space[*xp]) { + *cp++ = *xp++; + SKIP_WHITE_SPACE (xp); + } + } else if (traditional && xp < bp) { + *cp++ = *xp++; + } + break; + + case '\'': + case '\"': + { + register U_CHAR *bp1 + = skip_quoted_string (xp - 1, bp, ip->lineno, + NULL_PTR, NULL_PTR, NULL_PTR); + while (xp != bp1) + if (*xp == '\\') { + if (*++xp != '\n') + *cp++ = '\\'; + else + xp++; + } else + *cp++ = *xp++; + } + break; + + case '/': + if (*xp == '*' + || (cplusplus_comments && *xp == '/')) { + ip->bufp = xp + 1; + /* If we already copied the directive through, + already_output != 0 prevents outputting comment now. */ + skip_to_end_of_comment (ip, already_output, 0); + if (keep_comments) + while (xp != ip->bufp) + *cp++ = *xp++; + /* Delete or replace the slash. */ + else if (traditional) + cp--; + else + cp[-1] = ' '; + xp = ip->bufp; + } + } + } + + /* Null-terminate the copy. */ + + *cp = 0; + } else + cp = bp; + + ip->bufp = resume_p; + + /* Some directives should be written out for cc1 to process, + just as if they were not defined. And sometimes we're copying + definitions through. */ + + if (!no_output && already_output == 0 + && (kt->pass_thru + || (kt->type == T_DEFINE + && (dump_macros == dump_names + || dump_macros == dump_definitions)))) { + int len; + + /* Output directive name. */ + check_expand (op, kt->length + 1); + *op->bufp++ = '#'; + bcopy (kt->name, (char *) op->bufp, kt->length); + op->bufp += kt->length; + + if (kt->pass_thru || dump_macros == dump_definitions) { + /* Output arguments. */ + len = (cp - buf); + check_expand (op, len); + bcopy (buf, (char *) op->bufp, len); + op->bufp += len; + } else if (kt->type == T_DEFINE && dump_macros == dump_names) { + U_CHAR *xp = buf; + U_CHAR *yp; + SKIP_WHITE_SPACE (xp); + yp = xp; + while (is_idchar[*xp]) xp++; + len = (xp - yp); + check_expand (op, len + 1); + *op->bufp++ = ' '; + bcopy (yp, op->bufp, len); + op->bufp += len; + } + } /* Don't we need a newline or #line? */ + + /* Call the appropriate directive handler. buf now points to + either the appropriate place in the input buffer, or to + the temp buffer if it was necessary to make one. cp + points to the first char after the contents of the (possibly + copied) directive, in either case. */ + (*kt->func) (buf, cp, op, kt); + check_expand (op, ip->length - (ip->bufp - ip->buf)); + + return 1; + } + } + + /* It is deliberate that we don't warn about undefined directives. + That is the responsibility of cc1. */ + return 0; +} + +static struct tm * +timestamp () +{ + static struct tm *timebuf; + if (!timebuf) { + time_t t = time ((time_t *)0); + timebuf = localtime (&t); + } + return timebuf; +} + +static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + }; + +/* + * expand things like __FILE__. Place the expansion into the output + * buffer *without* rescanning. + */ + +static void +special_symbol (hp, op) + HASHNODE *hp; + FILE_BUF *op; +{ + char *buf; + int i, len; + int true_indepth; + FILE_BUF *ip = NULL; + struct tm *timebuf; + + int paren = 0; /* For special `defined' keyword */ + + if (pcp_outfile && pcp_inside_if + && hp->type != T_SPEC_DEFINED && hp->type != T_CONST) + error ("Predefined macro `%s' used inside `#if' during precompilation", + hp->name); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + if (ip == NULL) { + error ("cccp error: not in any file?!"); + return; /* the show must go on */ + } + + switch (hp->type) { + case T_FILE: + case T_BASE_FILE: + { + char *string; + if (hp->type == T_FILE) + string = ip->nominal_fname; + else + string = instack[0].nominal_fname; + + if (string) + { + buf = (char *) alloca (3 + 4 * strlen (string)); + quote_string (buf, string); + } + else + buf = "\"\""; + + break; + } + + case T_INCLUDE_LEVEL: + true_indepth = 0; + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) + true_indepth++; + + buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */ + sprintf (buf, "%d", true_indepth - 1); + break; + + case T_VERSION: + buf = (char *) alloca (3 + strlen (version_string)); + sprintf (buf, "\"%s\"", version_string); + break; + +#ifndef NO_BUILTIN_SIZE_TYPE + case T_SIZE_TYPE: + buf = SIZE_TYPE; + break; +#endif + +#ifndef NO_BUILTIN_PTRDIFF_TYPE + case T_PTRDIFF_TYPE: + buf = PTRDIFF_TYPE; + break; +#endif + + case T_WCHAR_TYPE: + buf = wchar_type; + break; + + case T_USER_LABEL_PREFIX_TYPE: + buf = USER_LABEL_PREFIX; + break; + + case T_REGISTER_PREFIX_TYPE: + buf = REGISTER_PREFIX; + break; + + case T_IMMEDIATE_PREFIX_TYPE: + buf = IMMEDIATE_PREFIX; + break; + + case T_CONST: + buf = hp->value.cpval; + if (pcp_inside_if && pcp_outfile) + /* Output a precondition for this macro use */ + fprintf (pcp_outfile, "#define %s %s\n", hp->name, buf); + break; + + case T_SPECLINE: + buf = (char *) alloca (10); + sprintf (buf, "%d", ip->lineno); + break; + + case T_DATE: + case T_TIME: + buf = (char *) alloca (20); + timebuf = timestamp (); + if (hp->type == T_DATE) + sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon], + timebuf->tm_mday, timebuf->tm_year + 1900); + else + sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min, + timebuf->tm_sec); + break; + + case T_SPEC_DEFINED: + buf = " 0 "; /* Assume symbol is not defined */ + ip = &instack[indepth]; + SKIP_WHITE_SPACE (ip->bufp); + if (*ip->bufp == '(') { + paren++; + ip->bufp++; /* Skip over the paren */ + SKIP_WHITE_SPACE (ip->bufp); + } + + if (!is_idstart[*ip->bufp]) + goto oops; + if ((hp = lookup (ip->bufp, -1, -1))) { + if (pcp_outfile && pcp_inside_if + && (hp->type == T_CONST + || (hp->type == T_MACRO && hp->value.defn->predefined))) + /* Output a precondition for this macro use. */ + fprintf (pcp_outfile, "#define %s\n", hp->name); + buf = " 1 "; + } + else + if (pcp_outfile && pcp_inside_if) { + /* Output a precondition for this macro use */ + U_CHAR *cp = ip->bufp; + fprintf (pcp_outfile, "#undef "); + while (is_idchar[*cp]) /* Ick! */ + fputc (*cp++, pcp_outfile); + putc ('\n', pcp_outfile); + } + while (is_idchar[*ip->bufp]) + ++ip->bufp; + SKIP_WHITE_SPACE (ip->bufp); + if (paren) { + if (*ip->bufp != ')') + goto oops; + ++ip->bufp; + } + break; + +oops: + + error ("`defined' without an identifier"); + break; + + default: + error ("cccp error: invalid special hash type"); /* time for gdb */ + abort (); + } + len = strlen (buf); + check_expand (op, len); + bcopy (buf, (char *) op->bufp, len); + op->bufp += len; + + return; +} + + +/* Routines to handle #directives */ + +/* Handle #include and #import. + This function expects to see "fname" or on the input. */ + +static int +do_include (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int importing = (keyword->type == T_IMPORT); + int skip_dirs = (keyword->type == T_INCLUDE_NEXT); + static int import_warning = 0; + char *fname; /* Dynamically allocated fname buffer */ + char *pcftry; + char *pcfname; + U_CHAR *fbeg, *fend; /* Beginning and end of fname */ + + struct file_name_list *search_start = include; /* Chain of dirs to search */ + struct file_name_list dsp[1]; /* First in chain, if #include "..." */ + struct file_name_list *searchptr = 0; + size_t flen; + + int f; /* file number */ + + int retried = 0; /* Have already tried macro + expanding the include line*/ + int angle_brackets = 0; /* 0 for "...", 1 for <...> */ + int pcf = -1; + char *pcfbuf; + char *pcfbuflimit; + int pcfnum; + f= -1; /* JF we iz paranoid! */ + + if (importing && warn_import && !inhibit_warnings + && !instack[indepth].system_header_p && !import_warning) { + import_warning = 1; + warning ("using `#import' is not recommended"); + fprintf (stderr, "The fact that a certain header file need not be processed more than once\n"); + fprintf (stderr, "should be indicated in the header file, not where it is used.\n"); + fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n"); + fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n"); + fprintf (stderr, " #define _FOO_H_INCLUDED\n"); + fprintf (stderr, " ... ...\n"); + fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n"); + fprintf (stderr, "Then users can use `#include' any number of times.\n"); + fprintf (stderr, "GNU C automatically avoids processing the file more than once\n"); + fprintf (stderr, "when it is equipped with such a conditional.\n"); + } + +get_filename: + + fbeg = buf; + SKIP_WHITE_SPACE (fbeg); + /* Discard trailing whitespace so we can easily see + if we have parsed all the significant chars we were given. */ + while (limit != fbeg && is_hor_space[limit[-1]]) limit--; + + switch (*fbeg++) { + case '\"': + { + FILE_BUF *fp; + /* Copy the operand text, concatenating the strings. */ + { + U_CHAR *fin = fbeg; + fbeg = (U_CHAR *) alloca (limit - fbeg + 1); + fend = fbeg; + while (fin != limit) { + while (fin != limit && *fin != '\"') + *fend++ = *fin++; + fin++; + if (fin == limit) + break; + /* If not at the end, there had better be another string. */ + /* Skip just horiz space, and don't go past limit. */ + while (fin != limit && is_hor_space[*fin]) fin++; + if (fin != limit && *fin == '\"') + fin++; + else + goto fail; + } + } + *fend = 0; + + /* We have "filename". Figure out directory this source + file is coming from and put it on the front of the list. */ + + /* If -I- was specified, don't search current dir, only spec'd ones. */ + if (ignore_srcdir) break; + + for (fp = &instack[indepth]; fp >= instack; fp--) + { + int n; + char *ep,*nam; + + if ((nam = fp->nominal_fname) != NULL) { + /* Found a named file. Figure out dir of the file, + and put it in front of the search list. */ + dsp[0].next = search_start; + search_start = dsp; +#ifndef VMS + ep = rindex (nam, '/'); +#ifdef DIR_SEPARATOR + if (ep == NULL) ep = rindex (nam, DIR_SEPARATOR); + else { + char *tmp = rindex (nam, DIR_SEPARATOR); + if (tmp != NULL && tmp > ep) ep = tmp; + } +#endif +#else /* VMS */ + ep = rindex (nam, ']'); + if (ep == NULL) ep = rindex (nam, '>'); + if (ep == NULL) ep = rindex (nam, ':'); + if (ep != NULL) ep++; +#endif /* VMS */ + if (ep != NULL) { + n = ep - nam; + dsp[0].fname = (char *) alloca (n + 1); + strncpy (dsp[0].fname, nam, n); + dsp[0].fname[n] = '\0'; + if (n + INCLUDE_LEN_FUDGE > max_include_len) + max_include_len = n + INCLUDE_LEN_FUDGE; + } else { + dsp[0].fname = 0; /* Current directory */ + } + dsp[0].got_name_map = 0; + break; + } + } + break; + } + + case '<': + fend = fbeg; + while (fend != limit && *fend != '>') fend++; + if (*fend == '>' && fend + 1 == limit) { + angle_brackets = 1; + /* If -I-, start with the first -I dir after the -I-. */ + if (first_bracket_include) + search_start = first_bracket_include; + break; + } + goto fail; + + default: +#ifdef VMS + /* + * Support '#include xyz' like VAX-C to allow for easy use of all the + * decwindow include files. It defaults to '#include ' (so the + * code from case '<' is repeated here) and generates a warning. + * (Note: macro expansion of `xyz' takes precedence.) + */ + if (retried && isalpha(*(--fbeg))) { + fend = fbeg; + while (fend != limit && (!isspace(*fend))) fend++; + warning ("VAX-C-style include specification found, use '#include ' !"); + if (fend == limit) { + angle_brackets = 1; + /* If -I-, start with the first -I dir after the -I-. */ + if (first_bracket_include) + search_start = first_bracket_include; + break; + } + } +#endif + + fail: + if (retried) { + error ("`#%s' expects \"FILENAME\" or ", keyword->name); + return 0; + } else { + /* Expand buffer and then remove any newline markers. + We can't just tell expand_to_temp_buffer to omit the markers, + since it would put extra spaces in include file names. */ + FILE_BUF trybuf; + U_CHAR *src; + trybuf = expand_to_temp_buffer (buf, limit, 1, 0); + src = trybuf.buf; + buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1); + limit = buf; + while (src != trybuf.bufp) { + switch ((*limit++ = *src++)) { + case '\n': + limit--; + src++; + break; + + case '\'': + case '\"': + { + U_CHAR *src1 = skip_quoted_string (src - 1, trybuf.bufp, 0, + NULL_PTR, NULL_PTR, NULL_PTR); + while (src != src1) + *limit++ = *src++; + } + break; + } + } + *limit = 0; + free (trybuf.buf); + retried++; + goto get_filename; + } + } + + /* For #include_next, skip in the search path + past the dir in which the containing file was found. */ + if (skip_dirs) { + FILE_BUF *fp; + for (fp = &instack[indepth]; fp >= instack; fp--) + if (fp->fname != NULL) { + /* fp->dir is null if the containing file was specified + with an absolute file name. In that case, don't skip anything. */ + if (fp->dir) + search_start = fp->dir->next; + break; + } + } + + flen = fend - fbeg; + + if (flen == 0) + { + error ("empty file name in `#%s'", keyword->name); + return 0; + } + + /* Allocate this permanently, because it gets stored in the definitions + of macros. */ + fname = xmalloc (max_include_len + flen + 4); + /* + 2 above for slash and terminating null. */ + /* + 2 added for '.h' on VMS (to support '#include filename') */ + + /* If specified file name is absolute, just open it. */ + + if (*fbeg == '/' +#ifdef DIR_SEPARATOR + || *fbeg == DIR_SEPARATOR +#endif + ) { + strncpy (fname, (char *) fbeg, flen); + fname[flen] = 0; + if (redundant_include_p (fname)) + return 0; + if (importing) + f = lookup_import (fname, NULL_PTR); + else + f = open_include_file (fname, NULL_PTR); + if (f == -2) + return 0; /* Already included this file */ + } else { + /* Search directory path, trying to open the file. + Copy each filename tried into FNAME. */ + + for (searchptr = search_start; searchptr; searchptr = searchptr->next) { + if (searchptr->fname) { + /* The empty string in a search path is ignored. + This makes it possible to turn off entirely + a standard piece of the list. */ + if (searchptr->fname[0] == 0) + continue; + strcpy (fname, skip_redundant_dir_prefix (searchptr->fname)); + if (fname[0] && fname[strlen (fname) - 1] != '/') + strcat (fname, "/"); + } else { + fname[0] = 0; + } + strncat (fname, (char *) fbeg, flen); +#ifdef VMS + /* Change this 1/2 Unix 1/2 VMS file specification into a + full VMS file specification */ + if (searchptr->fname && (searchptr->fname[0] != 0)) { + /* Fix up the filename */ + hack_vms_include_specification (fname); + } else { + /* This is a normal VMS filespec, so use it unchanged. */ + strncpy (fname, fbeg, flen); + fname[flen] = 0; + /* if it's '#include filename', add the missing .h */ + if (index(fname,'.')==NULL) { + strcat (fname, ".h"); + } + } +#endif /* VMS */ + /* ??? There are currently 3 separate mechanisms for avoiding processing + of redundant include files: #import, #pragma once, and + redundant_include_p. It would be nice if they were unified. */ + if (redundant_include_p (fname)) + return 0; + if (importing) + f = lookup_import (fname, searchptr); + else + f = open_include_file (fname, searchptr); + if (f == -2) + return 0; /* Already included this file */ +#ifdef EACCES + else if (f == -1 && errno == EACCES) + warning ("Header file %s exists, but is not readable", fname); +#endif + if (f >= 0) + break; + } + } + + if (f < 0) { + /* A file that was not found. */ + + strncpy (fname, (char *) fbeg, flen); + fname[flen] = 0; + /* If generating dependencies and -MG was specified, we assume missing + files are leaf files, living in the same directory as the source file + or other similar place; these missing files may be generated from + other files and may not exist yet (eg: y.tab.h). */ + if (print_deps_missing_files + && print_deps > (angle_brackets || (system_include_depth > 0))) + { + /* If it was requested as a system header file, + then assume it belongs in the first place to look for such. */ + if (angle_brackets) + { + for (searchptr = search_start; searchptr; searchptr = searchptr->next) + { + if (searchptr->fname) + { + char *p; + + if (searchptr->fname[0] == 0) + continue; + p = (char *) alloca (strlen (searchptr->fname) + + strlen (fname) + 2); + strcpy (p, skip_redundant_dir_prefix (searchptr->fname)); + if (p[0] && p[strlen (p) - 1] != '/') + strcat (p, "/"); + strcat (p, fname); + deps_output (p, ' '); + break; + } + } + } + else + { + /* Otherwise, omit the directory, as if the file existed + in the directory with the source. */ + deps_output (fname, ' '); + } + } + /* If -M was specified, and this header file won't be added to the + dependency list, then don't count this as an error, because we can + still produce correct output. Otherwise, we can't produce correct + output, because there may be dependencies we need inside the missing + file, and we don't know what directory this missing file exists in. */ + else if (print_deps + && (print_deps <= (angle_brackets || (system_include_depth > 0)))) + warning ("No include path in which to find %s", fname); + else if (search_start) + error_from_errno (fname); + else + error ("No include path in which to find %s", fname); + } else { + /* Check to see if this include file is a once-only include file. + If so, give up. */ + + struct file_name_list* ptr; + + for (ptr = dont_repeat_files; ptr; ptr = ptr->next) { + if (!strcmp (ptr->fname, fname)) { + close (f); + return 0; /* This file was once'd. */ + } + } + + for (ptr = all_include_files; ptr; ptr = ptr->next) { + if (!strcmp (ptr->fname, fname)) + break; /* This file was included before. */ + } + + if (ptr == 0) { + /* This is the first time for this file. */ + /* Add it to list of files included. */ + + ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + ptr->control_macro = 0; + ptr->c_system_include_path = 0; + ptr->next = all_include_files; + all_include_files = ptr; + ptr->fname = savestring (fname); + ptr->got_name_map = 0; + + /* For -M, add this file to the dependencies. */ + if (print_deps > (angle_brackets || (system_include_depth > 0))) + deps_output (fname, ' '); + } + + /* Handle -H option. */ + if (print_include_names) + fprintf (stderr, "%*s%s\n", indepth, "", fname); + + if (angle_brackets) + system_include_depth++; + + /* Actually process the file. */ + add_import (f, fname); /* Record file on "seen" list for #import. */ + + pcftry = (char *) alloca (strlen (fname) + 30); + pcfbuf = 0; + pcfnum = 0; + + if (!no_precomp) + { + struct stat stat_f; + + fstat (f, &stat_f); + + do { + sprintf (pcftry, "%s%d", fname, pcfnum++); + + pcf = open (pcftry, O_RDONLY, 0666); + if (pcf != -1) + { + struct stat s; + + fstat (pcf, &s); + if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino, + sizeof (s.st_ino)) + || stat_f.st_dev != s.st_dev) + { + pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit); + /* Don't need it any more. */ + close (pcf); + } + else + { + /* Don't need it at all. */ + close (pcf); + break; + } + } + } while (pcf != -1 && !pcfbuf); + } + + /* Actually process the file */ + if (pcfbuf) { + pcfname = xmalloc (strlen (pcftry) + 1); + strcpy (pcfname, pcftry); + pcfinclude ((U_CHAR *) pcfbuf, (U_CHAR *) pcfbuflimit, + (U_CHAR *) fname, op); + } + else + finclude (f, fname, op, is_system_include (fname), searchptr); + + if (angle_brackets) + system_include_depth--; + } + return 0; +} + +/* Return nonzero if there is no need to include file NAME + because it has already been included and it contains a conditional + to make a repeated include do nothing. */ + +static int +redundant_include_p (name) + char *name; +{ + struct file_name_list *l = all_include_files; + for (; l; l = l->next) + if (! strcmp (name, l->fname) + && l->control_macro + && lookup (l->control_macro, -1, -1)) + return 1; + return 0; +} + +/* Return nonzero if the given FILENAME is an absolute pathname which + designates a file within one of the known "system" include file + directories. We assume here that if the given FILENAME looks like + it is the name of a file which resides either directly in a "system" + include file directory, or within any subdirectory thereof, then the + given file must be a "system" include file. This function tells us + if we should suppress pedantic errors/warnings for the given FILENAME. + + The value is 2 if the file is a C-language system header file + for which C++ should (on most systems) assume `extern "C"'. */ + +static int +is_system_include (filename) + register char *filename; +{ + struct file_name_list *searchptr; + + for (searchptr = first_system_include; searchptr; + searchptr = searchptr->next) + if (searchptr->fname) { + register char *sys_dir = skip_redundant_dir_prefix (searchptr->fname); + register unsigned length = strlen (sys_dir); + + if (! strncmp (sys_dir, filename, length) + && (filename[length] == '/' +#ifdef DIR_SEPARATOR + || filename[length] == DIR_SEPARATOR +#endif + )) { + if (searchptr->c_system_include_path) + return 2; + else + return 1; + } + } + return 0; +} + +/* Skip leading "./" from a directory name. + This may yield the empty string, which represents the current directory. */ + +static char * +skip_redundant_dir_prefix (dir) + char *dir; +{ + while (dir[0] == '.' && dir[1] == '/') + for (dir += 2; *dir == '/'; dir++) + continue; + if (dir[0] == '.' && !dir[1]) + dir++; + return dir; +} + +/* The file_name_map structure holds a mapping of file names for a + particular directory. This mapping is read from the file named + FILE_NAME_MAP_FILE in that directory. Such a file can be used to + map filenames on a file system with severe filename restrictions, + such as DOS. The format of the file name map file is just a series + of lines with two tokens on each line. The first token is the name + to map, and the second token is the actual name to use. */ + +struct file_name_map +{ + struct file_name_map *map_next; + char *map_from; + char *map_to; +}; + +#define FILE_NAME_MAP_FILE "header.gcc" + +/* Read a space delimited string of unlimited length from a stdio + file. */ + +static char * +read_filename_string (ch, f) + int ch; + FILE *f; +{ + char *alloc, *set; + int len; + + len = 20; + set = alloc = xmalloc (len + 1); + if (! is_space[ch]) + { + *set++ = ch; + while ((ch = getc (f)) != EOF && ! is_space[ch]) + { + if (set - alloc == len) + { + len *= 2; + alloc = xrealloc (alloc, len + 1); + set = alloc + len / 2; + } + *set++ = ch; + } + } + *set = '\0'; + ungetc (ch, f); + return alloc; +} + +/* Read the file name map file for DIRNAME. */ + +static struct file_name_map * +read_name_map (dirname) + char *dirname; +{ + /* This structure holds a linked list of file name maps, one per + directory. */ + struct file_name_map_list + { + struct file_name_map_list *map_list_next; + char *map_list_name; + struct file_name_map *map_list_map; + }; + static struct file_name_map_list *map_list; + register struct file_name_map_list *map_list_ptr; + char *name; + FILE *f; + size_t dirlen; + int separator_needed; + + dirname = skip_redundant_dir_prefix (dirname); + + for (map_list_ptr = map_list; map_list_ptr; + map_list_ptr = map_list_ptr->map_list_next) + if (! strcmp (map_list_ptr->map_list_name, dirname)) + return map_list_ptr->map_list_map; + + map_list_ptr = ((struct file_name_map_list *) + xmalloc (sizeof (struct file_name_map_list))); + map_list_ptr->map_list_name = savestring (dirname); + map_list_ptr->map_list_map = NULL; + + dirlen = strlen (dirname); + separator_needed = dirlen != 0 && dirname[dirlen - 1] != '/'; + name = (char *) alloca (dirlen + strlen (FILE_NAME_MAP_FILE) + 2); + strcpy (name, dirname); + name[dirlen] = '/'; + strcpy (name + dirlen + separator_needed, FILE_NAME_MAP_FILE); + f = fopen (name, "r"); + if (!f) + map_list_ptr->map_list_map = NULL; + else + { + int ch; + + while ((ch = getc (f)) != EOF) + { + char *from, *to; + struct file_name_map *ptr; + + if (is_space[ch]) + continue; + from = read_filename_string (ch, f); + while ((ch = getc (f)) != EOF && is_hor_space[ch]) + ; + to = read_filename_string (ch, f); + + ptr = ((struct file_name_map *) + xmalloc (sizeof (struct file_name_map))); + ptr->map_from = from; + + /* Make the real filename absolute. */ + if (*to == '/') + ptr->map_to = to; + else + { + ptr->map_to = xmalloc (dirlen + strlen (to) + 2); + strcpy (ptr->map_to, dirname); + ptr->map_to[dirlen] = '/'; + strcpy (ptr->map_to + dirlen + separator_needed, to); + free (to); + } + + ptr->map_next = map_list_ptr->map_list_map; + map_list_ptr->map_list_map = ptr; + + while ((ch = getc (f)) != '\n') + if (ch == EOF) + break; + } + fclose (f); + } + + map_list_ptr->map_list_next = map_list; + map_list = map_list_ptr; + + return map_list_ptr->map_list_map; +} + +/* Try to open include file FILENAME. SEARCHPTR is the directory + being tried from the include file search path. This function maps + filenames on file systems based on information read by + read_name_map. */ + +static int +open_include_file (filename, searchptr) + char *filename; + struct file_name_list *searchptr; +{ + register struct file_name_map *map; + register char *from; + char *p, *dir; + + if (searchptr && ! searchptr->got_name_map) + { + searchptr->name_map = read_name_map (searchptr->fname + ? searchptr->fname : "."); + searchptr->got_name_map = 1; + } + + /* First check the mapping for the directory we are using. */ + if (searchptr && searchptr->name_map) + { + from = filename; + if (searchptr->fname) + from += strlen (searchptr->fname) + 1; + for (map = searchptr->name_map; map; map = map->map_next) + { + if (! strcmp (map->map_from, from)) + { + /* Found a match. */ + return open (map->map_to, O_RDONLY, 0666); + } + } + } + + /* Try to find a mapping file for the particular directory we are + looking in. Thus #include will look up sys/types.h + in /usr/include/header.gcc and look up types.h in + /usr/include/sys/header.gcc. */ + p = rindex (filename, '/'); +#ifdef DIR_SEPARATOR + if (! p) p = rindex (filename, DIR_SEPARATOR); + else { + char *tmp = rindex (filename, DIR_SEPARATOR); + if (tmp != NULL && tmp > p) p = tmp; + } +#endif + if (! p) + p = filename; + if (searchptr + && searchptr->fname + && strlen (searchptr->fname) == p - filename + && ! strncmp (searchptr->fname, filename, p - filename)) + { + /* FILENAME is in SEARCHPTR, which we've already checked. */ + return open (filename, O_RDONLY, 0666); + } + + if (p == filename) + { + dir = "."; + from = filename; + } + else + { + dir = (char *) alloca (p - filename + 1); + bcopy (filename, dir, p - filename); + dir[p - filename] = '\0'; + from = p + 1; + } + for (map = read_name_map (dir); map; map = map->map_next) + if (! strcmp (map->map_from, from)) + return open (map->map_to, O_RDONLY, 0666); + + return open (filename, O_RDONLY, 0666); +} + +/* Process the contents of include file FNAME, already open on descriptor F, + with output to OP. + SYSTEM_HEADER_P is 1 if this file resides in any one of the known + "system" include directories (as decided by the `is_system_include' + function above). + DIRPTR is the link in the dir path through which this file was found, + or 0 if the file name was absolute. */ + +static void +finclude (f, fname, op, system_header_p, dirptr) + int f; + char *fname; + FILE_BUF *op; + int system_header_p; + struct file_name_list *dirptr; +{ + int st_mode; + long st_size; + long i; + FILE_BUF *fp; /* For input stack frame */ + int missing_newline = 0; + + CHECK_DEPTH (return;); + + if (file_size_and_mode (f, &st_mode, &st_size) < 0) + { + perror_with_name (fname); + close (f); + return; + } + + fp = &instack[indepth + 1]; + bzero ((char *) fp, sizeof (FILE_BUF)); + fp->nominal_fname = fp->fname = fname; + fp->length = 0; + fp->lineno = 1; + fp->if_stack = if_stack; + fp->system_header_p = system_header_p; + fp->dir = dirptr; + + if (S_ISREG (st_mode)) { + fp->buf = (U_CHAR *) xmalloc (st_size + 2); + fp->bufp = fp->buf; + + /* Read the file contents, knowing that st_size is an upper bound + on the number of bytes we can read. */ + fp->length = safe_read (f, (char *) fp->buf, st_size); + if (fp->length < 0) goto nope; + } + else if (S_ISDIR (st_mode)) { + error ("directory `%s' specified in #include", fname); + close (f); + return; + } else { + /* Cannot count its file size before reading. + First read the entire file into heap and + copy them into buffer on stack. */ + + int bsize = 2000; + + st_size = 0; + fp->buf = (U_CHAR *) xmalloc (bsize + 2); + + for (;;) { + i = safe_read (f, (char *) fp->buf + st_size, bsize - st_size); + if (i < 0) + goto nope; /* error! */ + st_size += i; + if (st_size != bsize) + break; /* End of file */ + bsize *= 2; + fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2); + } + fp->bufp = fp->buf; + fp->length = st_size; + } + + if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n') + /* Backslash-newline at end is not good enough. */ + || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) { + fp->buf[fp->length++] = '\n'; + missing_newline = 1; + } + fp->buf[fp->length] = '\0'; + + /* Close descriptor now, so nesting does not use lots of descriptors. */ + close (f); + + /* Must do this before calling trigraph_pcp, so that the correct file name + will be printed in warning messages. */ + + indepth++; + input_file_stack_tick++; + + if (!no_trigraphs) + trigraph_pcp (fp); + + output_line_directive (fp, op, 0, enter_file); + rescan (op, 0); + + if (missing_newline) + fp->lineno--; + + if (pedantic && missing_newline) + pedwarn ("file does not end in newline"); + + indepth--; + input_file_stack_tick++; + output_line_directive (&instack[indepth], op, 0, leave_file); + free (fp->buf); + return; + + nope: + + perror_with_name (fname); + close (f); + free (fp->buf); +} + +/* Record that inclusion of the file named FILE + should be controlled by the macro named MACRO_NAME. + This means that trying to include the file again + will do something if that macro is defined. */ + +static void +record_control_macro (file, macro_name) + char *file; + U_CHAR *macro_name; +{ + struct file_name_list *new; + + for (new = all_include_files; new; new = new->next) { + if (!strcmp (new->fname, file)) { + new->control_macro = macro_name; + return; + } + } + + /* If the file is not in all_include_files, something's wrong. */ + abort (); +} + +/* Maintain and search list of included files, for #import. */ + +#define IMPORT_HASH_SIZE 31 + +struct import_file { + char *name; + ino_t inode; + dev_t dev; + struct import_file *next; +}; + +/* Hash table of files already included with #include or #import. */ + +static struct import_file *import_hash_table[IMPORT_HASH_SIZE]; + +/* Hash a file name for import_hash_table. */ + +static int +import_hash (f) + char *f; +{ + int val = 0; + + while (*f) val += *f++; + return (val%IMPORT_HASH_SIZE); +} + +/* Search for file FILENAME in import_hash_table. + Return -2 if found, either a matching name or a matching inode. + Otherwise, open the file and return a file descriptor if successful + or -1 if unsuccessful. */ + +static int +lookup_import (filename, searchptr) + char *filename; + struct file_name_list *searchptr; +{ + struct import_file *i; + int h; + int hashval; + struct stat sb; + int fd; + + hashval = import_hash (filename); + + /* Attempt to find file in list of already included files */ + i = import_hash_table[hashval]; + + while (i) { + if (!strcmp (filename, i->name)) + return -2; /* return found */ + i = i->next; + } + /* Open it and try a match on inode/dev */ + fd = open_include_file (filename, searchptr); + if (fd < 0) + return fd; + fstat (fd, &sb); + for (h = 0; h < IMPORT_HASH_SIZE; h++) { + i = import_hash_table[h]; + while (i) { + /* Compare the inode and the device. + Supposedly on some systems the inode is not a scalar. */ + if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino)) + && i->dev == sb.st_dev) { + close (fd); + return -2; /* return found */ + } + i = i->next; + } + } + return fd; /* Not found, return open file */ +} + +/* Add the file FNAME, open on descriptor FD, to import_hash_table. */ + +static void +add_import (fd, fname) + int fd; + char *fname; +{ + struct import_file *i; + int hashval; + struct stat sb; + + hashval = import_hash (fname); + fstat (fd, &sb); + i = (struct import_file *)xmalloc (sizeof (struct import_file)); + i->name = xmalloc (strlen (fname)+1); + strcpy (i->name, fname); + bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino)); + i->dev = sb.st_dev; + i->next = import_hash_table[hashval]; + import_hash_table[hashval] = i; +} + +/* Load the specified precompiled header into core, and verify its + preconditions. PCF indicates the file descriptor to read, which must + be a regular file. FNAME indicates the file name of the original + header. *LIMIT will be set to an address one past the end of the file. + If the preconditions of the file are not satisfied, the buffer is + freed and we return 0. If the preconditions are satisfied, return + the address of the buffer following the preconditions. The buffer, in + this case, should never be freed because various pieces of it will + be referred to until all precompiled strings are output at the end of + the run. +*/ +static char * +check_precompiled (pcf, fname, limit) + int pcf; + char *fname; + char **limit; +{ + int st_mode; + long st_size; + int length = 0; + char *buf; + char *cp; + + if (pcp_outfile) + return 0; + + if (file_size_and_mode (pcf, &st_mode, &st_size) < 0) + return 0; + + if (S_ISREG (st_mode)) + { + buf = xmalloc (st_size + 2); + length = safe_read (pcf, buf, st_size); + if (length < 0) + goto nope; + } + else + abort (); + + if (length > 0 && buf[length-1] != '\n') + buf[length++] = '\n'; + buf[length] = '\0'; + + *limit = buf + length; + + /* File is in core. Check the preconditions. */ + if (!check_preconditions (buf)) + goto nope; + for (cp = buf; *cp; cp++) + ; +#ifdef DEBUG_PCP + fprintf (stderr, "Using preinclude %s\n", fname); +#endif + return cp + 1; + + nope: +#ifdef DEBUG_PCP + fprintf (stderr, "Cannot use preinclude %s\n", fname); +#endif + free (buf); + return 0; +} + +/* PREC (null terminated) points to the preconditions of a + precompiled header. These are a series of #define and #undef + lines which must match the current contents of the hash + table. */ +static int +check_preconditions (prec) + char *prec; +{ + MACRODEF mdef; + char *lineend; + + while (*prec) { + lineend = index (prec, '\n'); + + if (*prec++ != '#') { + error ("Bad format encountered while reading precompiled file"); + return 0; + } + if (!strncmp (prec, "define", 6)) { + HASHNODE *hp; + + prec += 6; + mdef = create_definition ((U_CHAR *) prec, (U_CHAR *) lineend, NULL_PTR); + + if (mdef.defn == 0) + abort (); + + if ((hp = lookup (mdef.symnam, mdef.symlen, -1)) == NULL + || (hp->type != T_MACRO && hp->type != T_CONST) + || (hp->type == T_MACRO + && !compare_defs (mdef.defn, hp->value.defn) + && (mdef.defn->length != 2 + || mdef.defn->expansion[0] != '\n' + || mdef.defn->expansion[1] != ' '))) + return 0; + } else if (!strncmp (prec, "undef", 5)) { + char *name; + int len; + + prec += 5; + while (is_hor_space[(U_CHAR) *prec]) + prec++; + name = prec; + while (is_idchar[(U_CHAR) *prec]) + prec++; + len = prec - name; + + if (lookup ((U_CHAR *) name, len, -1)) + return 0; + } else { + error ("Bad format encountered while reading precompiled file"); + return 0; + } + prec = lineend + 1; + } + /* They all passed successfully */ + return 1; +} + +/* Process the main body of a precompiled file. BUF points to the + string section of the file, following the preconditions. LIMIT is one + character past the end. NAME is the name of the file being read + in. OP is the main output buffer */ +static void +pcfinclude (buf, limit, name, op) + U_CHAR *buf, *limit, *name; + FILE_BUF *op; +{ + FILE_BUF tmpbuf; + int nstrings; + U_CHAR *cp = buf; + + /* First in the file comes 4 bytes indicating the number of strings, */ + /* in network byte order. (MSB first). */ + nstrings = *cp++; + nstrings = (nstrings << 8) | *cp++; + nstrings = (nstrings << 8) | *cp++; + nstrings = (nstrings << 8) | *cp++; + + /* Looping over each string... */ + while (nstrings--) { + U_CHAR *string_start; + U_CHAR *endofthiskey; + STRINGDEF *str; + int nkeys; + + /* Each string starts with a STRINGDEF structure (str), followed */ + /* by the text of the string (string_start) */ + + /* First skip to a longword boundary */ + /* ??? Why a 4-byte boundary? On all machines? */ + /* NOTE: This works correctly even if HOST_WIDE_INT + is narrower than a pointer. + Do not try risky measures here to get another type to use! + Do not include stddef.h--it will fail! */ + if ((HOST_WIDE_INT) cp & 3) + cp += 4 - ((HOST_WIDE_INT) cp & 3); + + /* Now get the string. */ + str = (STRINGDEF *) (GENERIC_PTR) cp; + string_start = cp += sizeof (STRINGDEF); + + for (; *cp; cp++) /* skip the string */ + ; + + /* We need to macro expand the string here to ensure that the + proper definition environment is in place. If it were only + expanded when we find out it is needed, macros necessary for + its proper expansion might have had their definitions changed. */ + tmpbuf = expand_to_temp_buffer (string_start, cp++, 0, 0); + /* Lineno is already set in the precompiled file */ + str->contents = tmpbuf.buf; + str->len = tmpbuf.length; + str->writeflag = 0; + str->filename = name; + str->output_mark = outbuf.bufp - outbuf.buf; + + str->chain = 0; + *stringlist_tailp = str; + stringlist_tailp = &str->chain; + + /* Next comes a fourbyte number indicating the number of keys */ + /* for this string. */ + nkeys = *cp++; + nkeys = (nkeys << 8) | *cp++; + nkeys = (nkeys << 8) | *cp++; + nkeys = (nkeys << 8) | *cp++; + + /* If this number is -1, then the string is mandatory. */ + if (nkeys == -1) + str->writeflag = 1; + else + /* Otherwise, for each key, */ + for (; nkeys--; free (tmpbuf.buf), cp = endofthiskey + 1) { + KEYDEF *kp = (KEYDEF *) (GENERIC_PTR) cp; + HASHNODE *hp; + + /* It starts with a KEYDEF structure */ + cp += sizeof (KEYDEF); + + /* Find the end of the key. At the end of this for loop we + advance CP to the start of the next key using this variable. */ + endofthiskey = cp + strlen ((char *) cp); + kp->str = str; + + /* Expand the key, and enter it into the hash table. */ + tmpbuf = expand_to_temp_buffer (cp, endofthiskey, 0, 0); + tmpbuf.bufp = tmpbuf.buf; + + while (is_hor_space[*tmpbuf.bufp]) + tmpbuf.bufp++; + if (!is_idstart[*tmpbuf.bufp] + || tmpbuf.bufp == tmpbuf.buf + tmpbuf.length) { + str->writeflag = 1; + continue; + } + + hp = lookup (tmpbuf.bufp, -1, -1); + if (hp == NULL) { + kp->chain = 0; + install (tmpbuf.bufp, -1, T_PCSTRING, (char *) kp, -1); + } + else if (hp->type == T_PCSTRING) { + kp->chain = hp->value.keydef; + hp->value.keydef = kp; + } + else + str->writeflag = 1; + } + } + /* This output_line_directive serves to switch us back to the current + input file in case some of these strings get output (which will + result in line directives for the header file being output). */ + output_line_directive (&instack[indepth], op, 0, enter_file); +} + +/* Called from rescan when it hits a key for strings. Mark them all */ + /* used and clean up. */ +static void +pcstring_used (hp) + HASHNODE *hp; +{ + KEYDEF *kp; + + for (kp = hp->value.keydef; kp; kp = kp->chain) + kp->str->writeflag = 1; + delete_macro (hp); +} + +/* Write the output, interspersing precompiled strings in their */ + /* appropriate places. */ +static void +write_output () +{ + STRINGDEF *next_string; + U_CHAR *cur_buf_loc; + int line_directive_len = 80; + char *line_directive = xmalloc (line_directive_len); + int len; + + /* In each run through the loop, either cur_buf_loc == */ + /* next_string_loc, in which case we print a series of strings, or */ + /* it is less than next_string_loc, in which case we write some of */ + /* the buffer. */ + cur_buf_loc = outbuf.buf; + next_string = stringlist; + + while (cur_buf_loc < outbuf.bufp || next_string) { + if (next_string + && cur_buf_loc - outbuf.buf == next_string->output_mark) { + if (next_string->writeflag) { + len = 4 * strlen ((char *) next_string->filename) + 32; + while (len > line_directive_len) + line_directive = xrealloc (line_directive, + line_directive_len *= 2); + sprintf (line_directive, "\n# %d ", next_string->lineno); + strcpy (quote_string (line_directive + strlen (line_directive), + (char *) next_string->filename), + "\n"); + safe_write (fileno (stdout), line_directive, strlen (line_directive)); + safe_write (fileno (stdout), + (char *) next_string->contents, next_string->len); + } + next_string = next_string->chain; + } + else { + len = (next_string + ? (next_string->output_mark + - (cur_buf_loc - outbuf.buf)) + : outbuf.bufp - cur_buf_loc); + + safe_write (fileno (stdout), (char *) cur_buf_loc, len); + cur_buf_loc += len; + } + } + free (line_directive); +} + +/* Pass a directive through to the output file. + BUF points to the contents of the directive, as a contiguous string. + LIMIT points to the first character past the end of the directive. + KEYWORD is the keyword-table entry for the directive. */ + +static void +pass_thru_directive (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + register unsigned keyword_length = keyword->length; + + check_expand (op, 1 + keyword_length + (limit - buf)); + *op->bufp++ = '#'; + bcopy (keyword->name, (char *) op->bufp, keyword_length); + op->bufp += keyword_length; + if (limit != buf && buf[0] != ' ') + *op->bufp++ = ' '; + bcopy ((char *) buf, (char *) op->bufp, limit - buf); + op->bufp += (limit - buf); +#if 0 + *op->bufp++ = '\n'; + /* Count the line we have just made in the output, + to get in sync properly. */ + op->lineno++; +#endif +} + +/* The arglist structure is built by do_define to tell + collect_definition where the argument names begin. That + is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist + would contain pointers to the strings x, y, and z. + Collect_definition would then build a DEFINITION node, + with reflist nodes pointing to the places x, y, and z had + appeared. So the arglist is just convenience data passed + between these two routines. It is not kept around after + the current #define has been processed and entered into the + hash table. */ + +struct arglist { + struct arglist *next; + U_CHAR *name; + int length; + int argno; + char rest_args; +}; + +/* Create a DEFINITION node from a #define directive. Arguments are + as for do_define. */ +static MACRODEF +create_definition (buf, limit, op) + U_CHAR *buf, *limit; + FILE_BUF *op; +{ + U_CHAR *bp; /* temp ptr into input buffer */ + U_CHAR *symname; /* remember where symbol name starts */ + int sym_length; /* and how long it is */ + int line = instack[indepth].lineno; + char *file = instack[indepth].nominal_fname; + int rest_args = 0; + + DEFINITION *defn; + int arglengths = 0; /* Accumulate lengths of arg names + plus number of args. */ + MACRODEF mdef; + + bp = buf; + + while (is_hor_space[*bp]) + bp++; + + symname = bp; /* remember where it starts */ + sym_length = check_macro_name (bp, "macro"); + bp += sym_length; + + /* Lossage will occur if identifiers or control keywords are broken + across lines using backslash. This is not the right place to take + care of that. */ + + if (*bp == '(') { + struct arglist *arg_ptrs = NULL; + int argno = 0; + + bp++; /* skip '(' */ + SKIP_WHITE_SPACE (bp); + + /* Loop over macro argument names. */ + while (*bp != ')') { + struct arglist *temp; + + temp = (struct arglist *) alloca (sizeof (struct arglist)); + temp->name = bp; + temp->next = arg_ptrs; + temp->argno = argno++; + temp->rest_args = 0; + arg_ptrs = temp; + + if (rest_args) + pedwarn ("another parameter follows `%s'", + rest_extension); + + if (!is_idstart[*bp]) + pedwarn ("invalid character in macro parameter name"); + + /* Find the end of the arg name. */ + while (is_idchar[*bp]) { + bp++; + /* do we have a "special" rest-args extension here? */ + if (limit - bp > REST_EXTENSION_LENGTH && + bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) { + rest_args = 1; + temp->rest_args = 1; + break; + } + } + temp->length = bp - temp->name; + if (rest_args == 1) + bp += REST_EXTENSION_LENGTH; + arglengths += temp->length + 2; + SKIP_WHITE_SPACE (bp); + if (temp->length == 0 || (*bp != ',' && *bp != ')')) { + error ("badly punctuated parameter list in `#define'"); + goto nope; + } + if (*bp == ',') { + bp++; + SKIP_WHITE_SPACE (bp); + /* A comma at this point can only be followed by an identifier. */ + if (!is_idstart[*bp]) { + error ("badly punctuated parameter list in `#define'"); + goto nope; + } + } + if (bp >= limit) { + error ("unterminated parameter list in `#define'"); + goto nope; + } + { + struct arglist *otemp; + + for (otemp = temp->next; otemp != NULL; otemp = otemp->next) + if (temp->length == otemp->length && + bcmp (temp->name, otemp->name, temp->length) == 0) { + error ("duplicate argument name `%.*s' in `#define'", + temp->length, temp->name); + goto nope; + } + } + } + + ++bp; /* skip paren */ + SKIP_WHITE_SPACE (bp); + /* now everything from bp before limit is the definition. */ + defn = collect_expansion (bp, limit, argno, arg_ptrs); + defn->rest_args = rest_args; + + /* Now set defn->args.argnames to the result of concatenating + the argument names in reverse order + with comma-space between them. */ + defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1); + { + struct arglist *temp; + int i = 0; + for (temp = arg_ptrs; temp; temp = temp->next) { + bcopy (temp->name, &defn->args.argnames[i], temp->length); + i += temp->length; + if (temp->next != 0) { + defn->args.argnames[i++] = ','; + defn->args.argnames[i++] = ' '; + } + } + defn->args.argnames[i] = 0; + } + } else { + /* Simple expansion or empty definition. */ + + if (bp < limit) + { + if (is_hor_space[*bp]) { + bp++; + SKIP_WHITE_SPACE (bp); + } else { + switch (*bp) { + case '!': case '"': case '#': case '%': case '&': case '\'': + case ')': case '*': case '+': case ',': case '-': case '.': + case '/': case ':': case ';': case '<': case '=': case '>': + case '?': case '[': case '\\': case ']': case '^': case '{': + case '|': case '}': case '~': + warning ("missing white space after `#define %.*s'", + sym_length, symname); + break; + + default: + pedwarn ("missing white space after `#define %.*s'", + sym_length, symname); + break; + } + } + } + /* Now everything from bp before limit is the definition. */ + defn = collect_expansion (bp, limit, -1, NULL_PTR); + defn->args.argnames = (U_CHAR *) ""; + } + + defn->line = line; + defn->file = file; + + /* OP is null if this is a predefinition */ + defn->predefined = !op; + mdef.defn = defn; + mdef.symnam = symname; + mdef.symlen = sym_length; + + return mdef; + + nope: + mdef.defn = 0; + return mdef; +} + +/* Process a #define directive. +BUF points to the contents of the #define directive, as a contiguous string. +LIMIT points to the first character past the end of the definition. +KEYWORD is the keyword-table entry for #define. */ + +static int +do_define (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int hashcode; + MACRODEF mdef; + + /* If this is a precompiler run (with -pcp) pass thru #define directives. */ + if (pcp_outfile && op) + pass_thru_directive (buf, limit, op, keyword); + + mdef = create_definition (buf, limit, op); + if (mdef.defn == 0) + goto nope; + + hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE); + + { + HASHNODE *hp; + if ((hp = lookup (mdef.symnam, mdef.symlen, hashcode)) != NULL) { + int ok = 0; + /* Redefining a precompiled key is ok. */ + if (hp->type == T_PCSTRING) + ok = 1; + /* Redefining a macro is ok if the definitions are the same. */ + else if (hp->type == T_MACRO) + ok = ! compare_defs (mdef.defn, hp->value.defn); + /* Redefining a constant is ok with -D. */ + else if (hp->type == T_CONST) + ok = ! done_initializing; + /* Print the warning if it's not ok. */ + if (!ok) { + /* If we are passing through #define and #undef directives, do + that for this re-definition now. */ + if (debug_output && op) + pass_thru_directive (buf, limit, op, keyword); + + pedwarn ("`%.*s' redefined", mdef.symlen, mdef.symnam); + if (hp->type == T_MACRO) + pedwarn_with_file_and_line (hp->value.defn->file, hp->value.defn->line, + "this is the location of the previous definition"); + } + /* Replace the old definition. */ + hp->type = T_MACRO; + hp->value.defn = mdef.defn; + } else { + /* If we are passing through #define and #undef directives, do + that for this new definition now. */ + if (debug_output && op) + pass_thru_directive (buf, limit, op, keyword); + install (mdef.symnam, mdef.symlen, T_MACRO, + (char *) mdef.defn, hashcode); + } + } + + return 0; + +nope: + + return 1; +} + +/* Check a purported macro name SYMNAME, and yield its length. + USAGE is the kind of name this is intended for. */ + +static int +check_macro_name (symname, usage) + U_CHAR *symname; + char *usage; +{ + U_CHAR *p; + int sym_length; + + for (p = symname; is_idchar[*p]; p++) + ; + sym_length = p - symname; + if (sym_length == 0) + error ("invalid %s name", usage); + else if (!is_idstart[*symname] + || (sym_length == 7 && ! bcmp (symname, "defined", 7))) + error ("invalid %s name `%.*s'", usage, sym_length, symname); + return sym_length; +} + +/* + * return zero if two DEFINITIONs are isomorphic + */ +static int +compare_defs (d1, d2) + DEFINITION *d1, *d2; +{ + register struct reflist *a1, *a2; + register U_CHAR *p1 = d1->expansion; + register U_CHAR *p2 = d2->expansion; + int first = 1; + + if (d1->nargs != d2->nargs) + return 1; + if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames)) + return 1; + for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2; + a1 = a1->next, a2 = a2->next) { + if (!((a1->nchars == a2->nchars && ! bcmp (p1, p2, a1->nchars)) + || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0)) + || a1->argno != a2->argno + || a1->stringify != a2->stringify + || a1->raw_before != a2->raw_before + || a1->raw_after != a2->raw_after) + return 1; + first = 0; + p1 += a1->nchars; + p2 += a2->nchars; + } + if (a1 != a2) + return 1; + if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion), + p2, d2->length - (p2 - d2->expansion), 1)) + return 1; + return 0; +} + +/* Return 1 if two parts of two macro definitions are effectively different. + One of the parts starts at BEG1 and has LEN1 chars; + the other has LEN2 chars at BEG2. + Any sequence of whitespace matches any other sequence of whitespace. + FIRST means these parts are the first of a macro definition; + so ignore leading whitespace entirely. + LAST means these parts are the last of a macro definition; + so ignore trailing whitespace entirely. */ + +static int +comp_def_part (first, beg1, len1, beg2, len2, last) + int first; + U_CHAR *beg1, *beg2; + int len1, len2; + int last; +{ + register U_CHAR *end1 = beg1 + len1; + register U_CHAR *end2 = beg2 + len2; + if (first) { + while (beg1 != end1 && is_space[*beg1]) beg1++; + while (beg2 != end2 && is_space[*beg2]) beg2++; + } + if (last) { + while (beg1 != end1 && is_space[end1[-1]]) end1--; + while (beg2 != end2 && is_space[end2[-1]]) end2--; + } + while (beg1 != end1 && beg2 != end2) { + if (is_space[*beg1] && is_space[*beg2]) { + while (beg1 != end1 && is_space[*beg1]) beg1++; + while (beg2 != end2 && is_space[*beg2]) beg2++; + } else if (*beg1 == *beg2) { + beg1++; beg2++; + } else break; + } + return (beg1 != end1) || (beg2 != end2); +} + +/* Read a replacement list for a macro with parameters. + Build the DEFINITION structure. + Reads characters of text starting at BUF until END. + ARGLIST specifies the formal parameters to look for + in the text of the definition; NARGS is the number of args + in that list, or -1 for a macro name that wants no argument list. + MACRONAME is the macro name itself (so we can avoid recursive expansion) + and NAMELEN is its length in characters. + +Note that comments, backslash-newlines, and leading white space +have already been deleted from the argument. */ + +/* If there is no trailing whitespace, a Newline Space is added at the end + to prevent concatenation that would be contrary to the standard. */ + +static DEFINITION * +collect_expansion (buf, end, nargs, arglist) + U_CHAR *buf, *end; + int nargs; + struct arglist *arglist; +{ + DEFINITION *defn; + register U_CHAR *p, *limit, *lastp, *exp_p; + struct reflist *endpat = NULL; + /* Pointer to first nonspace after last ## seen. */ + U_CHAR *concat = 0; + /* Pointer to first nonspace after last single-# seen. */ + U_CHAR *stringify = 0; + /* How those tokens were spelled. */ + enum sharp_token_type concat_sharp_token_type = NO_SHARP_TOKEN; + enum sharp_token_type stringify_sharp_token_type = NO_SHARP_TOKEN; + int maxsize; + int expected_delimiter = '\0'; + + /* Scan thru the replacement list, ignoring comments and quoted + strings, picking up on the macro calls. It does a linear search + thru the arg list on every potential symbol. Profiling might say + that something smarter should happen. */ + + if (end < buf) + abort (); + + /* Find the beginning of the trailing whitespace. */ + limit = end; + p = buf; + while (p < limit && is_space[limit[-1]]) limit--; + + /* Allocate space for the text in the macro definition. + Each input char may or may not need 1 byte, + so this is an upper bound. + The extra 3 are for invented trailing newline-marker and final null. */ + maxsize = (sizeof (DEFINITION) + + (limit - p) + 3); + defn = (DEFINITION *) xcalloc (1, maxsize); + + defn->nargs = nargs; + exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION); + lastp = exp_p; + + if (p[0] == '#' + ? p[1] == '#' + : p[0] == '%' && p[1] == ':' && p[2] == '%' && p[3] == ':') { + error ("`##' at start of macro definition"); + p += p[0] == '#' ? 2 : 4; + } + + /* Process the main body of the definition. */ + while (p < limit) { + int skipped_arg = 0; + register U_CHAR c = *p++; + + *exp_p++ = c; + + if (!traditional) { + switch (c) { + case '\'': + case '\"': + if (expected_delimiter != '\0') { + if (c == expected_delimiter) + expected_delimiter = '\0'; + } else + expected_delimiter = c; + break; + + case '\\': + if (p < limit && expected_delimiter) { + /* In a string, backslash goes through + and makes next char ordinary. */ + *exp_p++ = *p++; + } + break; + + case '%': + if (!expected_delimiter && *p == ':') { + /* %: is not a digraph if preceded by an odd number of '<'s. */ + U_CHAR *p0 = p - 1; + while (buf < p0 && p0[-1] == '<') + p0--; + if ((p - p0) & 1) { + /* Treat %:%: as ## and %: as #. */ + if (p[1] == '%' && p[2] == ':') { + p += 2; + goto sharp_sharp_token; + } + if (nargs >= 0) { + p++; + goto sharp_token; + } + } + } + break; + + case '#': + /* # is ordinary inside a string. */ + if (expected_delimiter) + break; + if (*p == '#') { + sharp_sharp_token: + /* ##: concatenate preceding and following tokens. */ + /* Take out the first #, discard preceding whitespace. */ + exp_p--; + while (exp_p > lastp && is_hor_space[exp_p[-1]]) + --exp_p; + /* Skip the second #. */ + p++; + concat_sharp_token_type = c; + if (is_hor_space[*p]) { + concat_sharp_token_type = c + 1; + p++; + SKIP_WHITE_SPACE (p); + } + concat = p; + if (p == limit) + error ("`##' at end of macro definition"); + } else if (nargs >= 0) { + /* Single #: stringify following argument ref. + Don't leave the # in the expansion. */ + sharp_token: + exp_p--; + stringify_sharp_token_type = c; + if (is_hor_space[*p]) { + stringify_sharp_token_type = c + 1; + p++; + SKIP_WHITE_SPACE (p); + } + if (! is_idstart[*p] || nargs == 0) + error ("`#' operator is not followed by a macro argument name"); + else + stringify = p; + } + break; + } + } else { + /* In -traditional mode, recognize arguments inside strings and + and character constants, and ignore special properties of #. + Arguments inside strings are considered "stringified", but no + extra quote marks are supplied. */ + switch (c) { + case '\'': + case '\"': + if (expected_delimiter != '\0') { + if (c == expected_delimiter) + expected_delimiter = '\0'; + } else + expected_delimiter = c; + break; + + case '\\': + /* Backslash quotes delimiters and itself, but not macro args. */ + if (expected_delimiter != 0 && p < limit + && (*p == expected_delimiter || *p == '\\')) { + *exp_p++ = *p++; + continue; + } + break; + + case '/': + if (expected_delimiter != '\0') /* No comments inside strings. */ + break; + if (*p == '*') { + /* If we find a comment that wasn't removed by handle_directive, + this must be -traditional. So replace the comment with + nothing at all. */ + exp_p--; + p += 1; + while (p < limit && !(p[-2] == '*' && p[-1] == '/')) + p++; +#if 0 + /* Mark this as a concatenation-point, as if it had been ##. */ + concat = p; +#endif + } + break; + } + } + + /* Handle the start of a symbol. */ + if (is_idchar[c] && nargs > 0) { + U_CHAR *id_beg = p - 1; + int id_len; + + --exp_p; + while (p != limit && is_idchar[*p]) p++; + id_len = p - id_beg; + + if (is_idstart[c]) { + register struct arglist *arg; + + for (arg = arglist; arg != NULL; arg = arg->next) { + struct reflist *tpat; + + if (arg->name[0] == c + && arg->length == id_len + && bcmp (arg->name, id_beg, id_len) == 0) { + enum sharp_token_type tpat_stringify; + if (expected_delimiter) { + if (warn_stringify) { + if (traditional) { + warning ("macro argument `%.*s' is stringified.", + id_len, arg->name); + } else { + warning ("macro arg `%.*s' would be stringified with -traditional.", + id_len, arg->name); + } + } + /* If ANSI, don't actually substitute inside a string. */ + if (!traditional) + break; + tpat_stringify = SHARP_TOKEN; + } else { + tpat_stringify + = (stringify == id_beg + ? stringify_sharp_token_type : NO_SHARP_TOKEN); + } + /* make a pat node for this arg and append it to the end of + the pat list */ + tpat = (struct reflist *) xmalloc (sizeof (struct reflist)); + tpat->next = NULL; + tpat->raw_before + = concat == id_beg ? concat_sharp_token_type : NO_SHARP_TOKEN; + tpat->raw_after = NO_SHARP_TOKEN; + tpat->rest_args = arg->rest_args; + tpat->stringify = tpat_stringify; + + if (endpat == NULL) + defn->pattern = tpat; + else + endpat->next = tpat; + endpat = tpat; + + tpat->argno = arg->argno; + tpat->nchars = exp_p - lastp; + { + register U_CHAR *p1 = p; + SKIP_WHITE_SPACE (p1); + if (p1[0]=='#' + ? p1[1]=='#' + : p1[0]=='%' && p1[1]==':' && p1[2]=='%' && p1[3]==':') + tpat->raw_after = p1[0] + (p != p1); + } + lastp = exp_p; /* place to start copying from next time */ + skipped_arg = 1; + break; + } + } + } + + /* If this was not a macro arg, copy it into the expansion. */ + if (! skipped_arg) { + register U_CHAR *lim1 = p; + p = id_beg; + while (p != lim1) + *exp_p++ = *p++; + if (stringify == id_beg) + error ("`#' operator should be followed by a macro argument name"); + } + } + } + + if (!traditional && expected_delimiter == 0) { + /* If ANSI, put in a newline-space marker to prevent token pasting. + But not if "inside a string" (which in ANSI mode happens only for + -D option). */ + *exp_p++ = '\n'; + *exp_p++ = ' '; + } + + *exp_p = '\0'; + + defn->length = exp_p - defn->expansion; + + /* Crash now if we overrun the allocated size. */ + if (defn->length + 1 > maxsize) + abort (); + +#if 0 +/* This isn't worth the time it takes. */ + /* give back excess storage */ + defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1); +#endif + + return defn; +} + +static int +do_assert (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + U_CHAR *bp; /* temp ptr into input buffer */ + U_CHAR *symname; /* remember where symbol name starts */ + int sym_length; /* and how long it is */ + struct arglist *tokens = NULL; + + if (pedantic && done_initializing && !instack[indepth].system_header_p) + pedwarn ("ANSI C does not allow `#assert'"); + + bp = buf; + + while (is_hor_space[*bp]) + bp++; + + symname = bp; /* remember where it starts */ + sym_length = check_macro_name (bp, "assertion"); + bp += sym_length; + /* #define doesn't do this, but we should. */ + SKIP_WHITE_SPACE (bp); + + /* Lossage will occur if identifiers or control tokens are broken + across lines using backslash. This is not the right place to take + care of that. */ + + if (*bp != '(') { + error ("missing token-sequence in `#assert'"); + return 1; + } + + { + int error_flag = 0; + + bp++; /* skip '(' */ + SKIP_WHITE_SPACE (bp); + + tokens = read_token_list (&bp, limit, &error_flag); + if (error_flag) + return 1; + if (tokens == 0) { + error ("empty token-sequence in `#assert'"); + return 1; + } + + ++bp; /* skip paren */ + SKIP_WHITE_SPACE (bp); + } + + /* If this name isn't already an assertion name, make it one. + Error if it was already in use in some other way. */ + + { + ASSERTION_HASHNODE *hp; + int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE); + struct tokenlist_list *value + = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list)); + + hp = assertion_lookup (symname, sym_length, hashcode); + if (hp == NULL) { + if (sym_length == 7 && ! bcmp (symname, "defined", 7)) + error ("`defined' redefined as assertion"); + hp = assertion_install (symname, sym_length, hashcode); + } + + /* Add the spec'd token-sequence to the list of such. */ + value->tokens = tokens; + value->next = hp->value; + hp->value = value; + } + + return 0; +} + +static int +do_unassert (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + U_CHAR *bp; /* temp ptr into input buffer */ + U_CHAR *symname; /* remember where symbol name starts */ + int sym_length; /* and how long it is */ + + struct arglist *tokens = NULL; + int tokens_specified = 0; + + if (pedantic && done_initializing && !instack[indepth].system_header_p) + pedwarn ("ANSI C does not allow `#unassert'"); + + bp = buf; + + while (is_hor_space[*bp]) + bp++; + + symname = bp; /* remember where it starts */ + sym_length = check_macro_name (bp, "assertion"); + bp += sym_length; + /* #define doesn't do this, but we should. */ + SKIP_WHITE_SPACE (bp); + + /* Lossage will occur if identifiers or control tokens are broken + across lines using backslash. This is not the right place to take + care of that. */ + + if (*bp == '(') { + int error_flag = 0; + + bp++; /* skip '(' */ + SKIP_WHITE_SPACE (bp); + + tokens = read_token_list (&bp, limit, &error_flag); + if (error_flag) + return 1; + if (tokens == 0) { + error ("empty token list in `#unassert'"); + return 1; + } + + tokens_specified = 1; + + ++bp; /* skip paren */ + SKIP_WHITE_SPACE (bp); + } + + { + ASSERTION_HASHNODE *hp; + int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE); + struct tokenlist_list *tail, *prev; + + hp = assertion_lookup (symname, sym_length, hashcode); + if (hp == NULL) + return 1; + + /* If no token list was specified, then eliminate this assertion + entirely. */ + if (! tokens_specified) { + struct tokenlist_list *next; + for (tail = hp->value; tail; tail = next) { + next = tail->next; + free_token_list (tail->tokens); + free (tail); + } + delete_assertion (hp); + } else { + /* If a list of tokens was given, then delete any matching list. */ + + tail = hp->value; + prev = 0; + while (tail) { + struct tokenlist_list *next = tail->next; + if (compare_token_lists (tail->tokens, tokens)) { + if (prev) + prev->next = next; + else + hp->value = tail->next; + free_token_list (tail->tokens); + free (tail); + } else { + prev = tail; + } + tail = next; + } + } + } + + return 0; +} + +/* Test whether there is an assertion named NAME + and optionally whether it has an asserted token list TOKENS. + NAME is not null terminated; its length is SYM_LENGTH. + If TOKENS_SPECIFIED is 0, then don't check for any token list. */ + +int +check_assertion (name, sym_length, tokens_specified, tokens) + U_CHAR *name; + int sym_length; + int tokens_specified; + struct arglist *tokens; +{ + ASSERTION_HASHNODE *hp; + int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE); + + if (pedantic && !instack[indepth].system_header_p) + pedwarn ("ANSI C does not allow testing assertions"); + + hp = assertion_lookup (name, sym_length, hashcode); + if (hp == NULL) + /* It is not an assertion; just return false. */ + return 0; + + /* If no token list was specified, then value is 1. */ + if (! tokens_specified) + return 1; + + { + struct tokenlist_list *tail; + + tail = hp->value; + + /* If a list of tokens was given, + then succeed if the assertion records a matching list. */ + + while (tail) { + if (compare_token_lists (tail->tokens, tokens)) + return 1; + tail = tail->next; + } + + /* Fail if the assertion has no matching list. */ + return 0; + } +} + +/* Compare two lists of tokens for equality including order of tokens. */ + +static int +compare_token_lists (l1, l2) + struct arglist *l1, *l2; +{ + while (l1 && l2) { + if (l1->length != l2->length) + return 0; + if (bcmp (l1->name, l2->name, l1->length)) + return 0; + l1 = l1->next; + l2 = l2->next; + } + + /* Succeed if both lists end at the same time. */ + return l1 == l2; +} + +/* Read a space-separated list of tokens ending in a close parenthesis. + Return a list of strings, in the order they were written. + (In case of error, return 0 and store -1 in *ERROR_FLAG.) + Parse the text starting at *BPP, and update *BPP. + Don't parse beyond LIMIT. */ + +static struct arglist * +read_token_list (bpp, limit, error_flag) + U_CHAR **bpp; + U_CHAR *limit; + int *error_flag; +{ + struct arglist *token_ptrs = 0; + U_CHAR *bp = *bpp; + int depth = 1; + + *error_flag = 0; + + /* Loop over the assertion value tokens. */ + while (depth > 0) { + struct arglist *temp; + int eofp = 0; + U_CHAR *beg = bp; + + /* Find the end of the token. */ + if (*bp == '(') { + bp++; + depth++; + } else if (*bp == ')') { + depth--; + if (depth == 0) + break; + bp++; + } else if (*bp == '"' || *bp == '\'') + bp = skip_quoted_string (bp, limit, 0, NULL_PTR, NULL_PTR, &eofp); + else + while (! is_hor_space[*bp] && *bp != '(' && *bp != ')' + && *bp != '"' && *bp != '\'' && bp != limit) + bp++; + + temp = (struct arglist *) xmalloc (sizeof (struct arglist)); + temp->name = (U_CHAR *) xmalloc (bp - beg + 1); + bcopy ((char *) beg, (char *) temp->name, bp - beg); + temp->name[bp - beg] = 0; + temp->next = token_ptrs; + token_ptrs = temp; + temp->length = bp - beg; + + SKIP_WHITE_SPACE (bp); + + if (bp >= limit) { + error ("unterminated token sequence in `#assert' or `#unassert'"); + *error_flag = -1; + return 0; + } + } + *bpp = bp; + + /* We accumulated the names in reverse order. + Now reverse them to get the proper order. */ + { + register struct arglist *prev = 0, *this, *next; + for (this = token_ptrs; this; this = next) { + next = this->next; + this->next = prev; + prev = this; + } + return prev; + } +} + +static void +free_token_list (tokens) + struct arglist *tokens; +{ + while (tokens) { + struct arglist *next = tokens->next; + free (tokens->name); + free (tokens); + tokens = next; + } +} + +/* + * Install a name in the assertion hash table. + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +static ASSERTION_HASHNODE * +assertion_install (name, len, hash) + U_CHAR *name; + int len; + int hash; +{ + register ASSERTION_HASHNODE *hp; + register int i, bucket; + register U_CHAR *p, *q; + + i = sizeof (ASSERTION_HASHNODE) + len + 1; + hp = (ASSERTION_HASHNODE *) xmalloc (i); + bucket = hash; + hp->bucket_hdr = &assertion_hashtab[bucket]; + hp->next = assertion_hashtab[bucket]; + assertion_hashtab[bucket] = hp; + hp->prev = NULL; + if (hp->next != NULL) + hp->next->prev = hp; + hp->length = len; + hp->value = 0; + hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE); + p = hp->name; + q = name; + for (i = 0; i < len; i++) + *p++ = *q++; + hp->name[len] = 0; + return hp; +} + +/* + * find the most recent hash node for name name (ending with first + * non-identifier char) installed by install + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +static ASSERTION_HASHNODE * +assertion_lookup (name, len, hash) + U_CHAR *name; + int len; + int hash; +{ + register ASSERTION_HASHNODE *bucket; + + bucket = assertion_hashtab[hash]; + while (bucket) { + if (bucket->length == len && bcmp (bucket->name, name, len) == 0) + return bucket; + bucket = bucket->next; + } + return NULL; +} + +static void +delete_assertion (hp) + ASSERTION_HASHNODE *hp; +{ + + if (hp->prev != NULL) + hp->prev->next = hp->next; + if (hp->next != NULL) + hp->next->prev = hp->prev; + + /* make sure that the bucket chain header that + the deleted guy was on points to the right thing afterwards. */ + if (hp == *hp->bucket_hdr) + *hp->bucket_hdr = hp->next; + + free (hp); +} + +/* + * interpret #line directive. Remembers previously seen fnames + * in its very own hash table. + */ +#define FNAME_HASHSIZE 37 + +static int +do_line (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + register U_CHAR *bp; + FILE_BUF *ip = &instack[indepth]; + FILE_BUF tem; + int new_lineno; + enum file_change_code file_change = same_file; + + /* Expand any macros. */ + tem = expand_to_temp_buffer (buf, limit, 0, 0); + + /* Point to macroexpanded line, which is null-terminated now. */ + bp = tem.buf; + SKIP_WHITE_SPACE (bp); + + if (!isdigit (*bp)) { + error ("invalid format `#line' directive"); + return 0; + } + + /* The Newline at the end of this line remains to be processed. + To put the next line at the specified line number, + we must store a line number now that is one less. */ + new_lineno = atoi ((char *) bp) - 1; + + /* NEW_LINENO is one less than the actual line number here. */ + if (pedantic && new_lineno < 0) + pedwarn ("line number out of range in `#line' directive"); + + /* skip over the line number. */ + while (isdigit (*bp)) + bp++; + +#if 0 /* #line 10"foo.c" is supposed to be allowed. */ + if (*bp && !is_space[*bp]) { + error ("invalid format `#line' directive"); + return; + } +#endif + + SKIP_WHITE_SPACE (bp); + + if (*bp == '\"') { + static HASHNODE *fname_table[FNAME_HASHSIZE]; + HASHNODE *hp, **hash_bucket; + U_CHAR *fname, *p; + int fname_length; + + fname = ++bp; + + /* Turn the file name, which is a character string literal, + into a null-terminated string. Do this in place. */ + p = bp; + for (;;) + switch ((*p++ = *bp++)) { + case '\0': + error ("invalid format `#line' directive"); + return 0; + + case '\\': + { + char *bpc = (char *) bp; + int c = parse_escape (&bpc); + bp = (U_CHAR *) bpc; + if (c < 0) + p--; + else + p[-1] = c; + } + break; + + case '\"': + p[-1] = 0; + goto fname_done; + } + fname_done: + fname_length = p - fname; + + SKIP_WHITE_SPACE (bp); + if (*bp) { + if (pedantic) + pedwarn ("garbage at end of `#line' directive"); + if (*bp == '1') + file_change = enter_file; + else if (*bp == '2') + file_change = leave_file; + else if (*bp == '3') + ip->system_header_p = 1; + else if (*bp == '4') + ip->system_header_p = 2; + else { + error ("invalid format `#line' directive"); + return 0; + } + + bp++; + SKIP_WHITE_SPACE (bp); + if (*bp == '3') { + ip->system_header_p = 1; + bp++; + SKIP_WHITE_SPACE (bp); + } + if (*bp == '4') { + ip->system_header_p = 2; + bp++; + SKIP_WHITE_SPACE (bp); + } + if (*bp) { + error ("invalid format `#line' directive"); + return 0; + } + } + + hash_bucket = + &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)]; + for (hp = *hash_bucket; hp != NULL; hp = hp->next) + if (hp->length == fname_length && + bcmp (hp->value.cpval, fname, fname_length) == 0) { + ip->nominal_fname = hp->value.cpval; + break; + } + if (hp == 0) { + /* Didn't find it; cons up a new one. */ + hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1); + hp->next = *hash_bucket; + *hash_bucket = hp; + + hp->length = fname_length; + ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE); + bcopy (fname, hp->value.cpval, fname_length); + } + } else if (*bp) { + error ("invalid format `#line' directive"); + return 0; + } + + ip->lineno = new_lineno; + output_line_directive (ip, op, 0, file_change); + check_expand (op, ip->length - (ip->bufp - ip->buf)); + return 0; +} + +/* + * remove the definition of a symbol from the symbol table. + * according to un*x /lib/cpp, it is not an error to undef + * something that has no definitions, so it isn't one here either. + */ + +static int +do_undef (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int sym_length; + HASHNODE *hp; + U_CHAR *orig_buf = buf; + + /* If this is a precompiler run (with -pcp) pass thru #undef directives. */ + if (pcp_outfile && op) + pass_thru_directive (buf, limit, op, keyword); + + SKIP_WHITE_SPACE (buf); + sym_length = check_macro_name (buf, "macro"); + + while ((hp = lookup (buf, sym_length, -1)) != NULL) { + /* If we are generating additional info for debugging (with -g) we + need to pass through all effective #undef directives. */ + if (debug_output && op) + pass_thru_directive (orig_buf, limit, op, keyword); + if (hp->type != T_MACRO) + warning ("undefining `%s'", hp->name); + delete_macro (hp); + } + + if (pedantic) { + buf += sym_length; + SKIP_WHITE_SPACE (buf); + if (buf != limit) + pedwarn ("garbage after `#undef' directive"); + } + return 0; +} + +/* + * Report an error detected by the program we are processing. + * Use the text of the line in the error message. + * (We use error because it prints the filename & line#.) + */ + +static int +do_error (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int length = limit - buf; + U_CHAR *copy = (U_CHAR *) xmalloc (length + 1); + bcopy ((char *) buf, (char *) copy, length); + copy[length] = 0; + SKIP_WHITE_SPACE (copy); + error ("#error %s", copy); + return 0; +} + +/* + * Report a warning detected by the program we are processing. + * Use the text of the line in the warning message, then continue. + * (We use error because it prints the filename & line#.) + */ + +static int +do_warning (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int length = limit - buf; + U_CHAR *copy = (U_CHAR *) xmalloc (length + 1); + bcopy ((char *) buf, (char *) copy, length); + copy[length] = 0; + SKIP_WHITE_SPACE (copy); + warning ("#warning %s", copy); + return 0; +} + +/* Remember the name of the current file being read from so that we can + avoid ever including it again. */ + +static void +do_once () +{ + int i; + FILE_BUF *ip = NULL; + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) { + struct file_name_list *new; + + new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + new->next = dont_repeat_files; + dont_repeat_files = new; + new->fname = savestring (ip->fname); + new->control_macro = 0; + new->got_name_map = 0; + new->c_system_include_path = 0; + } +} + +/* #ident has already been copied to the output file, so just ignore it. */ + +static int +do_ident (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + FILE_BUF trybuf; + int len; + + /* Allow #ident in system headers, since that's not user's fault. */ + if (pedantic && !instack[indepth].system_header_p) + pedwarn ("ANSI C does not allow `#ident'"); + + trybuf = expand_to_temp_buffer (buf, limit, 0, 0); + buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1); + bcopy ((char *) trybuf.buf, (char *) buf, trybuf.bufp - trybuf.buf); + limit = buf + (trybuf.bufp - trybuf.buf); + len = (limit - buf); + free (trybuf.buf); + + /* Output directive name. */ + check_expand (op, 7); + bcopy ("#ident ", (char *) op->bufp, 7); + op->bufp += 7; + + /* Output the expanded argument line. */ + check_expand (op, len); + bcopy ((char *) buf, (char *) op->bufp, len); + op->bufp += len; + + return 0; +} + +/* #pragma and its argument line have already been copied to the output file. + Just check for some recognized pragmas that need validation here. */ + +static int +do_pragma (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + SKIP_WHITE_SPACE (buf); + if (!strncmp ((char *) buf, "once", 4)) { + /* Allow #pragma once in system headers, since that's not the user's + fault. */ + if (!instack[indepth].system_header_p) + warning ("`#pragma once' is obsolete"); + do_once (); + } + + if (!strncmp ((char *) buf, "implementation", 14)) { + /* Be quiet about `#pragma implementation' for a file only if it hasn't + been included yet. */ + struct file_name_list *ptr; + U_CHAR *p = buf + 14, *fname, *inc_fname; + SKIP_WHITE_SPACE (p); + if (*p == '\n' || *p != '\"') + return 0; + + fname = p + 1; + if ((p = (U_CHAR *) index ((char *) fname, '\"'))) + *p = '\0'; + + for (ptr = all_include_files; ptr; ptr = ptr->next) { + inc_fname = (U_CHAR *) rindex (ptr->fname, '/'); + inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname; + if (inc_fname && !strcmp ((char *) inc_fname, (char *) fname)) + warning ("`#pragma implementation' for `%s' appears after file is included", + fname); + } + } + + return 0; +} + +#if 0 +/* This was a fun hack, but #pragma seems to start to be useful. + By failing to recognize it, we pass it through unchanged to cc1. */ + +/* + * the behavior of the #pragma directive is implementation defined. + * this implementation defines it as follows. + */ + +static int +do_pragma () +{ + close (0); + if (open ("/dev/tty", O_RDONLY, 0666) != 0) + goto nope; + close (1); + if (open ("/dev/tty", O_WRONLY, 0666) != 1) + goto nope; + execl ("/usr/games/hack", "#pragma", 0); + execl ("/usr/games/rogue", "#pragma", 0); + execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0); + execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0); +nope: + fatal ("You are in a maze of twisty compiler features, all different"); +} +#endif + +#ifdef SCCS_DIRECTIVE + +/* Just ignore #sccs, on systems where we define it at all. */ + +static int +do_sccs (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + if (pedantic) + pedwarn ("ANSI C does not allow `#sccs'"); + return 0; +} + +#endif /* defined (SCCS_DIRECTIVE) */ + +/* + * handle #if directive by + * 1) inserting special `defined' keyword into the hash table + * that gets turned into 0 or 1 by special_symbol (thus, + * if the luser has a symbol called `defined' already, it won't + * work inside the #if directive) + * 2) rescan the input into a temporary output buffer + * 3) pass the output buffer to the yacc parser and collect a value + * 4) clean up the mess left from steps 1 and 2. + * 5) call conditional_skip to skip til the next #endif (etc.), + * or not, depending on the value from step 3. + */ + +static int +do_if (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + HOST_WIDE_INT value; + FILE_BUF *ip = &instack[indepth]; + + value = eval_if_expression (buf, limit - buf); + conditional_skip (ip, value == 0, T_IF, NULL_PTR, op); + return 0; +} + +/* + * handle a #elif directive by not changing if_stack either. + * see the comment above do_else. + */ + +static int +do_elif (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + HOST_WIDE_INT value; + FILE_BUF *ip = &instack[indepth]; + + if (if_stack == instack[indepth].if_stack) { + error ("`#elif' not within a conditional"); + return 0; + } else { + if (if_stack->type != T_IF && if_stack->type != T_ELIF) { + error ("`#elif' after `#else'"); + fprintf (stderr, " (matches line %d", if_stack->lineno); + if (if_stack->fname != NULL && ip->fname != NULL && + strcmp (if_stack->fname, ip->nominal_fname) != 0) + fprintf (stderr, ", file %s", if_stack->fname); + fprintf (stderr, ")\n"); + } + if_stack->type = T_ELIF; + } + + if (if_stack->if_succeeded) + skip_if_group (ip, 0, op); + else { + value = eval_if_expression (buf, limit - buf); + if (value == 0) + skip_if_group (ip, 0, op); + else { + ++if_stack->if_succeeded; /* continue processing input */ + output_line_directive (ip, op, 1, same_file); + } + } + return 0; +} + +/* + * evaluate a #if expression in BUF, of length LENGTH, + * then parse the result as a C expression and return the value as an int. + */ +static HOST_WIDE_INT +eval_if_expression (buf, length) + U_CHAR *buf; + int length; +{ + FILE_BUF temp_obuf; + HASHNODE *save_defined; + HOST_WIDE_INT value; + + save_defined = install ((U_CHAR *) "defined", -1, T_SPEC_DEFINED, + NULL_PTR, -1); + pcp_inside_if = 1; + temp_obuf = expand_to_temp_buffer (buf, buf + length, 0, 1); + pcp_inside_if = 0; + delete_macro (save_defined); /* clean up special symbol */ + + value = parse_c_expression ((char *) temp_obuf.buf); + + free (temp_obuf.buf); + + return value; +} + +/* + * routine to handle ifdef/ifndef. Try to look up the symbol, + * then do or don't skip to the #endif/#else/#elif depending + * on what directive is actually being processed. + */ + +static int +do_xifdef (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + int skip; + FILE_BUF *ip = &instack[indepth]; + U_CHAR *end; + int start_of_file = 0; + U_CHAR *control_macro = 0; + + /* Detect a #ifndef at start of file (not counting comments). */ + if (ip->fname != 0 && keyword->type == T_IFNDEF) { + U_CHAR *p = ip->buf; + while (p != directive_start) { + U_CHAR c = *p++; + if (is_space[c]) + ; + /* Make no special provision for backslash-newline here; this is + slower if backslash-newlines are present, but it's correct, + and it's not worth it to tune for the rare backslash-newline. */ + else if (c == '/' + && (*p == '*' || (cplusplus_comments && *p == '/'))) { + /* Skip this comment. */ + int junk = 0; + U_CHAR *save_bufp = ip->bufp; + ip->bufp = p + 1; + p = skip_to_end_of_comment (ip, &junk, 1); + ip->bufp = save_bufp; + } else { + goto fail; + } + } + /* If we get here, this conditional is the beginning of the file. */ + start_of_file = 1; + fail: ; + } + + /* Discard leading and trailing whitespace. */ + SKIP_WHITE_SPACE (buf); + while (limit != buf && is_hor_space[limit[-1]]) limit--; + + /* Find the end of the identifier at the beginning. */ + for (end = buf; is_idchar[*end]; end++); + + if (end == buf) { + skip = (keyword->type == T_IFDEF); + if (! traditional) + pedwarn (end == limit ? "`#%s' with no argument" + : "`#%s' argument starts with punctuation", + keyword->name); + } else { + HASHNODE *hp; + + if (pedantic && buf[0] >= '0' && buf[0] <= '9') + pedwarn ("`#%s' argument starts with a digit", keyword->name); + else if (end != limit && !traditional) + pedwarn ("garbage at end of `#%s' argument", keyword->name); + + hp = lookup (buf, end-buf, -1); + + if (pcp_outfile) { + /* Output a precondition for this macro. */ + if (hp && + (hp->type == T_CONST + || (hp->type == T_MACRO && hp->value.defn->predefined))) + fprintf (pcp_outfile, "#define %s\n", hp->name); + else { + U_CHAR *cp = buf; + fprintf (pcp_outfile, "#undef "); + while (is_idchar[*cp]) /* Ick! */ + fputc (*cp++, pcp_outfile); + putc ('\n', pcp_outfile); + } + } + + skip = (hp == NULL) ^ (keyword->type == T_IFNDEF); + if (start_of_file && !skip) { + control_macro = (U_CHAR *) xmalloc (end - buf + 1); + bcopy ((char *) buf, (char *) control_macro, end - buf); + control_macro[end - buf] = 0; + } + } + + conditional_skip (ip, skip, T_IF, control_macro, op); + return 0; +} + +/* Push TYPE on stack; then, if SKIP is nonzero, skip ahead. + If this is a #ifndef starting at the beginning of a file, + CONTROL_MACRO is the macro name tested by the #ifndef. + Otherwise, CONTROL_MACRO is 0. */ + +static void +conditional_skip (ip, skip, type, control_macro, op) + FILE_BUF *ip; + int skip; + enum node_type type; + U_CHAR *control_macro; + FILE_BUF *op; +{ + IF_STACK_FRAME *temp; + + temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME)); + temp->fname = ip->nominal_fname; + temp->lineno = ip->lineno; + temp->next = if_stack; + temp->control_macro = control_macro; + if_stack = temp; + + if_stack->type = type; + + if (skip != 0) { + skip_if_group (ip, 0, op); + return; + } else { + ++if_stack->if_succeeded; + output_line_directive (ip, &outbuf, 1, same_file); + } +} + +/* + * skip to #endif, #else, or #elif. adjust line numbers, etc. + * leaves input ptr at the sharp sign found. + * If ANY is nonzero, return at next directive of any sort. + */ +static void +skip_if_group (ip, any, op) + FILE_BUF *ip; + int any; + FILE_BUF *op; +{ + register U_CHAR *bp = ip->bufp, *cp; + register U_CHAR *endb = ip->buf + ip->length; + struct directive *kt; + IF_STACK_FRAME *save_if_stack = if_stack; /* don't pop past here */ + U_CHAR *beg_of_line = bp; + register int ident_length; + U_CHAR *ident, *after_ident; + /* Save info about where the group starts. */ + U_CHAR *beg_of_group = bp; + int beg_lineno = ip->lineno; + + if (output_conditionals && op != 0) { + char *ptr = "#failed\n"; + int len = strlen (ptr); + + if (op->bufp > op->buf && op->bufp[-1] != '\n') + { + *op->bufp++ = '\n'; + op->lineno++; + } + check_expand (op, len); + bcopy (ptr, (char *) op->bufp, len); + op->bufp += len; + op->lineno++; + output_line_directive (ip, op, 1, 0); + } + + while (bp < endb) { + switch (*bp++) { + case '/': /* possible comment */ + if (*bp == '\\' && bp[1] == '\n') + newline_fix (bp); + if (*bp == '*' + || (cplusplus_comments && *bp == '/')) { + ip->bufp = ++bp; + bp = skip_to_end_of_comment (ip, &ip->lineno, 0); + } + break; + case '\"': + case '\'': + bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno, + NULL_PTR, NULL_PTR); + break; + case '\\': + /* Char after backslash loses its special meaning. */ + if (bp < endb) { + if (*bp == '\n') + ++ip->lineno; /* But do update the line-count. */ + bp++; + } + break; + case '\n': + ++ip->lineno; + beg_of_line = bp; + break; + case '%': + if (beg_of_line == 0 || traditional) + break; + ip->bufp = bp - 1; + while (bp[0] == '\\' && bp[1] == '\n') + bp += 2; + if (*bp == ':') + goto sharp_token; + break; + case '#': + /* # keyword: a # must be first nonblank char on the line */ + if (beg_of_line == 0) + break; + ip->bufp = bp - 1; + sharp_token: + /* Scan from start of line, skipping whitespace, comments + and backslash-newlines, and see if we reach this #. + If not, this # is not special. */ + bp = beg_of_line; + /* If -traditional, require # to be at beginning of line. */ + if (!traditional) { + while (1) { + if (is_hor_space[*bp]) + bp++; + else if (*bp == '\\' && bp[1] == '\n') + bp += 2; + else if (*bp == '/' && bp[1] == '*') { + bp += 2; + while (!(*bp == '*' && bp[1] == '/')) + bp++; + bp += 2; + } + /* There is no point in trying to deal with C++ // comments here, + because if there is one, then this # must be part of the + comment and we would never reach here. */ + else break; + } + } + if (bp != ip->bufp) { + bp = ip->bufp + 1; /* Reset bp to after the #. */ + break; + } + + bp = ip->bufp + 1; /* Point after the '#' */ + if (ip->bufp[0] == '%') { + /* Skip past the ':' again. */ + while (*bp == '\\') { + ip->lineno++; + bp += 2; + } + bp++; + } + + /* Skip whitespace and \-newline. */ + while (1) { + if (is_hor_space[*bp]) + bp++; + else if (*bp == '\\' && bp[1] == '\n') + bp += 2; + else if (*bp == '/' && bp[1] == '*') { + bp += 2; + while (!(*bp == '*' && bp[1] == '/')) { + if (*bp == '\n') + ip->lineno++; + bp++; + } + bp += 2; + } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') { + bp += 2; + while (bp[-1] == '\\' || *bp != '\n') { + if (*bp == '\n') + ip->lineno++; + bp++; + } + } + else break; + } + + cp = bp; + + /* Now find end of directive name. + If we encounter a backslash-newline, exchange it with any following + symbol-constituents so that we end up with a contiguous name. */ + + while (1) { + if (is_idchar[*bp]) + bp++; + else { + if (*bp == '\\' && bp[1] == '\n') + name_newline_fix (bp); + if (is_idchar[*bp]) + bp++; + else break; + } + } + ident_length = bp - cp; + ident = cp; + after_ident = bp; + + /* A line of just `#' becomes blank. */ + + if (ident_length == 0 && *after_ident == '\n') { + continue; + } + + if (ident_length == 0 || !is_idstart[*ident]) { + U_CHAR *p = ident; + while (is_idchar[*p]) { + if (*p < '0' || *p > '9') + break; + p++; + } + /* Handle # followed by a line number. */ + if (p != ident && !is_idchar[*p]) { + if (pedantic) + pedwarn ("`#' followed by integer"); + continue; + } + + /* Avoid error for `###' and similar cases unless -pedantic. */ + if (p == ident) { + while (*p == '#' || is_hor_space[*p]) p++; + if (*p == '\n') { + if (pedantic && !lang_asm) + pedwarn ("invalid preprocessing directive"); + continue; + } + } + + if (!lang_asm && pedantic) + pedwarn ("invalid preprocessing directive name"); + continue; + } + + for (kt = directive_table; kt->length >= 0; kt++) { + IF_STACK_FRAME *temp; + if (ident_length == kt->length + && bcmp (cp, kt->name, kt->length) == 0) { + /* If we are asked to return on next directive, do so now. */ + if (any) + goto done; + + switch (kt->type) { + case T_IF: + case T_IFDEF: + case T_IFNDEF: + temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME)); + temp->next = if_stack; + if_stack = temp; + temp->lineno = ip->lineno; + temp->fname = ip->nominal_fname; + temp->type = kt->type; + break; + case T_ELSE: + case T_ENDIF: + if (pedantic && if_stack != save_if_stack) + validate_else (bp); + case T_ELIF: + if (if_stack == instack[indepth].if_stack) { + error ("`#%s' not within a conditional", kt->name); + break; + } + else if (if_stack == save_if_stack) + goto done; /* found what we came for */ + + if (kt->type != T_ENDIF) { + if (if_stack->type == T_ELSE) + error ("`#else' or `#elif' after `#else'"); + if_stack->type = kt->type; + break; + } + + temp = if_stack; + if_stack = if_stack->next; + free (temp); + break; + + default: + break; + } + break; + } + } + /* Don't let erroneous code go by. */ + if (kt->length < 0 && !lang_asm && pedantic) + pedwarn ("invalid preprocessing directive name"); + } + } + + ip->bufp = bp; + /* after this returns, rescan will exit because ip->bufp + now points to the end of the buffer. + rescan is responsible for the error message also. */ + + done: + if (output_conditionals && op != 0) { + char *ptr = "#endfailed\n"; + int len = strlen (ptr); + + if (op->bufp > op->buf && op->bufp[-1] != '\n') + { + *op->bufp++ = '\n'; + op->lineno++; + } + check_expand (op, beg_of_line - beg_of_group); + bcopy ((char *) beg_of_group, (char *) op->bufp, + beg_of_line - beg_of_group); + op->bufp += beg_of_line - beg_of_group; + op->lineno += ip->lineno - beg_lineno; + check_expand (op, len); + bcopy (ptr, (char *) op->bufp, len); + op->bufp += len; + op->lineno++; + } +} + +/* + * handle a #else directive. Do this by just continuing processing + * without changing if_stack ; this is so that the error message + * for missing #endif's etc. will point to the original #if. It + * is possible that something different would be better. + */ + +static int +do_else (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + FILE_BUF *ip = &instack[indepth]; + + if (pedantic) { + SKIP_WHITE_SPACE (buf); + if (buf != limit) + pedwarn ("text following `#else' violates ANSI standard"); + } + + if (if_stack == instack[indepth].if_stack) { + error ("`#else' not within a conditional"); + return 0; + } else { + /* #ifndef can't have its special treatment for containing the whole file + if it has a #else clause. */ + if_stack->control_macro = 0; + + if (if_stack->type != T_IF && if_stack->type != T_ELIF) { + error ("`#else' after `#else'"); + fprintf (stderr, " (matches line %d", if_stack->lineno); + if (strcmp (if_stack->fname, ip->nominal_fname) != 0) + fprintf (stderr, ", file %s", if_stack->fname); + fprintf (stderr, ")\n"); + } + if_stack->type = T_ELSE; + } + + if (if_stack->if_succeeded) + skip_if_group (ip, 0, op); + else { + ++if_stack->if_succeeded; /* continue processing input */ + output_line_directive (ip, op, 1, same_file); + } + return 0; +} + +/* + * unstack after #endif directive + */ + +static int +do_endif (buf, limit, op, keyword) + U_CHAR *buf, *limit; + FILE_BUF *op; + struct directive *keyword; +{ + if (pedantic) { + SKIP_WHITE_SPACE (buf); + if (buf != limit) + pedwarn ("text following `#endif' violates ANSI standard"); + } + + if (if_stack == instack[indepth].if_stack) + error ("unbalanced `#endif'"); + else { + IF_STACK_FRAME *temp = if_stack; + if_stack = if_stack->next; + if (temp->control_macro != 0) { + /* This #endif matched a #ifndef at the start of the file. + See if it is at the end of the file. */ + FILE_BUF *ip = &instack[indepth]; + U_CHAR *p = ip->bufp; + U_CHAR *ep = ip->buf + ip->length; + + while (p != ep) { + U_CHAR c = *p++; + if (!is_space[c]) { + if (c == '/' + && (*p == '*' || (cplusplus_comments && *p == '/'))) { + /* Skip this comment. */ + int junk = 0; + U_CHAR *save_bufp = ip->bufp; + ip->bufp = p + 1; + p = skip_to_end_of_comment (ip, &junk, 1); + ip->bufp = save_bufp; + } else + goto fail; + } + } + /* If we get here, this #endif ends a #ifndef + that contains all of the file (aside from whitespace). + Arrange not to include the file again + if the macro that was tested is defined. + + Do not do this for the top-level file in a -include or any + file in a -imacros. */ + if (indepth != 0 + && ! (indepth == 1 && no_record_file) + && ! (no_record_file && no_output)) + record_control_macro (ip->fname, temp->control_macro); + fail: ; + } + free (temp); + output_line_directive (&instack[indepth], op, 1, same_file); + } + return 0; +} + +/* When an #else or #endif is found while skipping failed conditional, + if -pedantic was specified, this is called to warn about text after + the directive name. P points to the first char after the directive name. */ + +static void +validate_else (p) + register U_CHAR *p; +{ + /* Advance P over whitespace and comments. */ + while (1) { + if (*p == '\\' && p[1] == '\n') + p += 2; + if (is_hor_space[*p]) + p++; + else if (*p == '/') { + if (p[1] == '\\' && p[2] == '\n') + newline_fix (p + 1); + if (p[1] == '*') { + p += 2; + /* Don't bother warning about unterminated comments + since that will happen later. Just be sure to exit. */ + while (*p) { + if (p[1] == '\\' && p[2] == '\n') + newline_fix (p + 1); + if (*p == '*' && p[1] == '/') { + p += 2; + break; + } + p++; + } + } + else if (cplusplus_comments && p[1] == '/') { + p += 2; + while (*p && (*p != '\n' || p[-1] == '\\')) + p++; + } + } else break; + } + if (*p && *p != '\n') + pedwarn ("text following `#else' or `#endif' violates ANSI standard"); +} + +/* Skip a comment, assuming the input ptr immediately follows the + initial slash-star. Bump *LINE_COUNTER for each newline. + (The canonical line counter is &ip->lineno.) + Don't use this routine (or the next one) if bumping the line + counter is not sufficient to deal with newlines in the string. + + If NOWARN is nonzero, don't warn about slash-star inside a comment. + This feature is useful when processing a comment that is going to be + processed or was processed at another point in the preprocessor, + to avoid a duplicate warning. Likewise for unterminated comment errors. */ + +static U_CHAR * +skip_to_end_of_comment (ip, line_counter, nowarn) + register FILE_BUF *ip; + int *line_counter; /* place to remember newlines, or NULL */ + int nowarn; +{ + register U_CHAR *limit = ip->buf + ip->length; + register U_CHAR *bp = ip->bufp; + FILE_BUF *op = &outbuf; /* JF */ + int output = put_out_comments && !line_counter; + int start_line = line_counter ? *line_counter : 0; + + /* JF this line_counter stuff is a crock to make sure the + comment is only put out once, no matter how many times + the comment is skipped. It almost works */ + if (output) { + *op->bufp++ = '/'; + *op->bufp++ = '*'; + } + if (cplusplus_comments && bp[-1] == '/') { + if (output) { + while (bp < limit) { + *op->bufp++ = *bp; + if (*bp == '\n' && bp[-1] != '\\') + break; + if (*bp == '\n') { + ++*line_counter; + ++op->lineno; + } + bp++; + } + op->bufp[-1] = '*'; + *op->bufp++ = '/'; + *op->bufp++ = '\n'; + } else { + while (bp < limit) { + if (bp[-1] != '\\' && *bp == '\n') { + break; + } else { + if (*bp == '\n' && line_counter) + ++*line_counter; + bp++; + } + } + } + ip->bufp = bp; + return bp; + } + while (bp < limit) { + if (output) + *op->bufp++ = *bp; + switch (*bp++) { + case '/': + if (warn_comments && !nowarn && bp < limit && *bp == '*') + warning ("`/*' within comment"); + break; + case '\n': + /* If this is the end of the file, we have an unterminated comment. + Don't swallow the newline. We are guaranteed that there will be a + trailing newline and various pieces assume it's there. */ + if (bp == limit) + { + --bp; + --limit; + break; + } + if (line_counter != NULL) + ++*line_counter; + if (output) + ++op->lineno; + break; + case '*': + if (*bp == '\\' && bp[1] == '\n') + newline_fix (bp); + if (*bp == '/') { + if (output) + *op->bufp++ = '/'; + ip->bufp = ++bp; + return bp; + } + break; + } + } + + if (!nowarn) + error_with_line (line_for_error (start_line), "unterminated comment"); + ip->bufp = bp; + return bp; +} + +/* + * Skip over a quoted string. BP points to the opening quote. + * Returns a pointer after the closing quote. Don't go past LIMIT. + * START_LINE is the line number of the starting point (but it need + * not be valid if the starting point is inside a macro expansion). + * + * The input stack state is not changed. + * + * If COUNT_NEWLINES is nonzero, it points to an int to increment + * for each newline passed. + * + * If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it + * if we pass a backslash-newline. + * + * If EOFP is nonzero, set *EOFP to 1 if the string is unterminated. + */ +static U_CHAR * +skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp) + register U_CHAR *bp; + register U_CHAR *limit; + int start_line; + int *count_newlines; + int *backslash_newlines_p; + int *eofp; +{ + register U_CHAR c, match; + + match = *bp++; + while (1) { + if (bp >= limit) { + error_with_line (line_for_error (start_line), + "unterminated string or character constant"); + error_with_line (multiline_string_line, + "possible real start of unterminated constant"); + multiline_string_line = 0; + if (eofp) + *eofp = 1; + break; + } + c = *bp++; + if (c == '\\') { + while (*bp == '\\' && bp[1] == '\n') { + if (backslash_newlines_p) + *backslash_newlines_p = 1; + if (count_newlines) + ++*count_newlines; + bp += 2; + } + if (*bp == '\n' && count_newlines) { + if (backslash_newlines_p) + *backslash_newlines_p = 1; + ++*count_newlines; + } + bp++; + } else if (c == '\n') { + if (traditional) { + /* Unterminated strings and character constants are 'valid'. */ + bp--; /* Don't consume the newline. */ + if (eofp) + *eofp = 1; + break; + } + if (pedantic || match == '\'') { + error_with_line (line_for_error (start_line), + "unterminated string or character constant"); + bp--; + if (eofp) + *eofp = 1; + break; + } + /* If not traditional, then allow newlines inside strings. */ + if (count_newlines) + ++*count_newlines; + if (multiline_string_line == 0) + multiline_string_line = start_line; + } else if (c == match) + break; + } + return bp; +} + +/* Place into DST a quoted string representing the string SRC. + Return the address of DST's terminating null. */ +static char * +quote_string (dst, src) + char *dst, *src; +{ + U_CHAR c; + + *dst++ = '\"'; + for (;;) + switch ((c = *src++)) + { + default: + if (isprint (c)) + *dst++ = c; + else + { + sprintf (dst, "\\%03o", c); + dst += 4; + } + break; + + case '\"': + case '\\': + *dst++ = '\\'; + *dst++ = c; + break; + + case '\0': + *dst++ = '\"'; + *dst = '\0'; + return dst; + } +} + +/* Skip across a group of balanced parens, starting from IP->bufp. + IP->bufp is updated. Use this with IP->bufp pointing at an open-paren. + + This does not handle newlines, because it's used for the arg of #if, + where there aren't any newlines. Also, backslash-newline can't appear. */ + +static U_CHAR * +skip_paren_group (ip) + register FILE_BUF *ip; +{ + U_CHAR *limit = ip->buf + ip->length; + U_CHAR *p = ip->bufp; + int depth = 0; + int lines_dummy = 0; + + while (p != limit) { + int c = *p++; + switch (c) { + case '(': + depth++; + break; + + case ')': + depth--; + if (depth == 0) + return ip->bufp = p; + break; + + case '/': + if (*p == '*') { + ip->bufp = p; + p = skip_to_end_of_comment (ip, &lines_dummy, 0); + p = ip->bufp; + } + + case '"': + case '\'': + { + int eofp = 0; + p = skip_quoted_string (p - 1, limit, 0, NULL_PTR, NULL_PTR, &eofp); + if (eofp) + return ip->bufp = p; + } + break; + } + } + + ip->bufp = p; + return p; +} + +/* + * write out a #line directive, for instance, after an #include file. + * If CONDITIONAL is nonzero, we can omit the #line if it would + * appear to be a no-op, and we can output a few newlines instead + * if we want to increase the line number by a small amount. + * FILE_CHANGE says whether we are entering a file, leaving, or neither. + */ + +static void +output_line_directive (ip, op, conditional, file_change) + FILE_BUF *ip, *op; + int conditional; + enum file_change_code file_change; +{ + int len; + char *line_directive_buf, *line_end; + + if (no_line_directives + || ip->fname == NULL + || no_output) { + op->lineno = ip->lineno; + return; + } + + if (conditional) { + if (ip->lineno == op->lineno) + return; + + /* If the inherited line number is a little too small, + output some newlines instead of a #line directive. */ + if (ip->lineno > op->lineno && ip->lineno < op->lineno + 8) { + check_expand (op, 10); + while (ip->lineno > op->lineno) { + *op->bufp++ = '\n'; + op->lineno++; + } + return; + } + } + + /* Don't output a line number of 0 if we can help it. */ + if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length + && *ip->bufp == '\n') { + ip->lineno++; + ip->bufp++; + } + + line_directive_buf = (char *) alloca (4 * strlen (ip->nominal_fname) + 100); + sprintf (line_directive_buf, "# %d ", ip->lineno); + line_end = quote_string (line_directive_buf + strlen (line_directive_buf), + ip->nominal_fname); + if (file_change != same_file) { + *line_end++ = ' '; + *line_end++ = file_change == enter_file ? '1' : '2'; + } + /* Tell cc1 if following text comes from a system header file. */ + if (ip->system_header_p) { + *line_end++ = ' '; + *line_end++ = '3'; + } +#ifndef NO_IMPLICIT_EXTERN_C + /* Tell cc1plus if following text should be treated as C. */ + if (ip->system_header_p == 2 && cplusplus) { + *line_end++ = ' '; + *line_end++ = '4'; + } +#endif + *line_end++ = '\n'; + len = line_end - line_directive_buf; + check_expand (op, len + 1); + if (op->bufp > op->buf && op->bufp[-1] != '\n') + *op->bufp++ = '\n'; + bcopy ((char *) line_directive_buf, (char *) op->bufp, len); + op->bufp += len; + op->lineno = ip->lineno; +} + +/* This structure represents one parsed argument in a macro call. + `raw' points to the argument text as written (`raw_length' is its length). + `expanded' points to the argument's macro-expansion + (its length is `expand_length'). + `stringified_length' is the length the argument would have + if stringified. + `use_count' is the number of times this macro arg is substituted + into the macro. If the actual use count exceeds 10, + the value stored is 10. + `free1' and `free2', if nonzero, point to blocks to be freed + when the macro argument data is no longer needed. */ + +struct argdata { + U_CHAR *raw, *expanded; + int raw_length, expand_length; + int stringified_length; + U_CHAR *free1, *free2; + char newlines; + char use_count; +}; + +/* Expand a macro call. + HP points to the symbol that is the macro being called. + Put the result of expansion onto the input stack + so that subsequent input by our caller will use it. + + If macro wants arguments, caller has already verified that + an argument list follows; arguments come from the input stack. */ + +static void +macroexpand (hp, op) + HASHNODE *hp; + FILE_BUF *op; +{ + int nargs; + DEFINITION *defn = hp->value.defn; + register U_CHAR *xbuf; + int xbuf_len; + int start_line = instack[indepth].lineno; + int rest_args, rest_zero; + + CHECK_DEPTH (return;); + + /* it might not actually be a macro. */ + if (hp->type != T_MACRO) { + special_symbol (hp, op); + return; + } + + /* This macro is being used inside a #if, which means it must be */ + /* recorded as a precondition. */ + if (pcp_inside_if && pcp_outfile && defn->predefined) + dump_single_macro (hp, pcp_outfile); + + nargs = defn->nargs; + + if (nargs >= 0) { + register int i; + struct argdata *args; + char *parse_error = 0; + + args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata)); + + for (i = 0; i < nargs; i++) { + args[i].raw = (U_CHAR *) ""; + args[i].expanded = 0; + args[i].raw_length = args[i].expand_length + = args[i].stringified_length = 0; + args[i].free1 = args[i].free2 = 0; + args[i].use_count = 0; + } + + /* Parse all the macro args that are supplied. I counts them. + The first NARGS args are stored in ARGS. + The rest are discarded. + If rest_args is set then we assume macarg absorbed the rest of the args. + */ + i = 0; + rest_args = 0; + do { + /* Discard the open-parenthesis or comma before the next arg. */ + ++instack[indepth].bufp; + if (rest_args) + continue; + if (i < nargs || (nargs == 0 && i == 0)) { + /* if we are working on last arg which absorbs rest of args... */ + if (i == nargs - 1 && defn->rest_args) + rest_args = 1; + parse_error = macarg (&args[i], rest_args); + } + else + parse_error = macarg (NULL_PTR, 0); + if (parse_error) { + error_with_line (line_for_error (start_line), parse_error); + break; + } + i++; + } while (*instack[indepth].bufp != ')'); + + /* If we got one arg but it was just whitespace, call that 0 args. */ + if (i == 1) { + register U_CHAR *bp = args[0].raw; + register U_CHAR *lim = bp + args[0].raw_length; + /* cpp.texi says for foo ( ) we provide one argument. + However, if foo wants just 0 arguments, treat this as 0. */ + if (nargs == 0) + while (bp != lim && is_space[*bp]) bp++; + if (bp == lim) + i = 0; + } + + /* Don't output an error message if we have already output one for + a parse error above. */ + rest_zero = 0; + if (nargs == 0 && i > 0) { + if (! parse_error) + error ("arguments given to macro `%s'", hp->name); + } else if (i < nargs) { + /* traditional C allows foo() if foo wants one argument. */ + if (nargs == 1 && i == 0 && traditional) + ; + /* the rest args token is allowed to absorb 0 tokens */ + else if (i == nargs - 1 && defn->rest_args) + rest_zero = 1; + else if (parse_error) + ; + else if (i == 0) + error ("macro `%s' used without args", hp->name); + else if (i == 1) + error ("macro `%s' used with just one arg", hp->name); + else + error ("macro `%s' used with only %d args", hp->name, i); + } else if (i > nargs) { + if (! parse_error) + error ("macro `%s' used with too many (%d) args", hp->name, i); + } + + /* Swallow the closeparen. */ + ++instack[indepth].bufp; + + /* If macro wants zero args, we parsed the arglist for checking only. + Read directly from the macro definition. */ + if (nargs == 0) { + xbuf = defn->expansion; + xbuf_len = defn->length; + } else { + register U_CHAR *exp = defn->expansion; + register int offset; /* offset in expansion, + copied a piece at a time */ + register int totlen; /* total amount of exp buffer filled so far */ + + register struct reflist *ap, *last_ap; + + /* Macro really takes args. Compute the expansion of this call. */ + + /* Compute length in characters of the macro's expansion. + Also count number of times each arg is used. */ + xbuf_len = defn->length; + for (ap = defn->pattern; ap != NULL; ap = ap->next) { + if (ap->stringify) + xbuf_len += args[ap->argno].stringified_length; + else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional) + /* Add 4 for two newline-space markers to prevent + token concatenation. */ + xbuf_len += args[ap->argno].raw_length + 4; + else { + /* We have an ordinary (expanded) occurrence of the arg. + So compute its expansion, if we have not already. */ + if (args[ap->argno].expanded == 0) { + FILE_BUF obuf; + obuf = expand_to_temp_buffer (args[ap->argno].raw, + args[ap->argno].raw + args[ap->argno].raw_length, + 1, 0); + + args[ap->argno].expanded = obuf.buf; + args[ap->argno].expand_length = obuf.length; + args[ap->argno].free2 = obuf.buf; + } + + /* Add 4 for two newline-space markers to prevent + token concatenation. */ + xbuf_len += args[ap->argno].expand_length + 4; + } + if (args[ap->argno].use_count < 10) + args[ap->argno].use_count++; + } + + xbuf = (U_CHAR *) xmalloc (xbuf_len + 1); + + /* Generate in XBUF the complete expansion + with arguments substituted in. + TOTLEN is the total size generated so far. + OFFSET is the index in the definition + of where we are copying from. */ + offset = totlen = 0; + for (last_ap = NULL, ap = defn->pattern; ap != NULL; + last_ap = ap, ap = ap->next) { + register struct argdata *arg = &args[ap->argno]; + int count_before = totlen; + + /* Add chars to XBUF. */ + for (i = 0; i < ap->nchars; i++, offset++) + xbuf[totlen++] = exp[offset]; + + /* If followed by an empty rest arg with concatenation, + delete the last run of nonwhite chars. */ + if (rest_zero && totlen > count_before + && ((ap->rest_args && ap->raw_before != 0) + || (last_ap != NULL && last_ap->rest_args + && last_ap->raw_after != 0))) { + /* Delete final whitespace. */ + while (totlen > count_before && is_space[xbuf[totlen - 1]]) { + totlen--; + } + + /* Delete the nonwhites before them. */ + while (totlen > count_before && ! is_space[xbuf[totlen - 1]]) { + totlen--; + } + } + + if (ap->stringify != 0) { + int arglen = arg->raw_length; + int escaped = 0; + int in_string = 0; + int c; + i = 0; + while (i < arglen + && (c = arg->raw[i], is_space[c])) + i++; + while (i < arglen + && (c = arg->raw[arglen - 1], is_space[c])) + arglen--; + if (!traditional) + xbuf[totlen++] = '\"'; /* insert beginning quote */ + for (; i < arglen; i++) { + c = arg->raw[i]; + + /* Special markers Newline Space + generate nothing for a stringified argument. */ + if (c == '\n' && arg->raw[i+1] != '\n') { + i++; + continue; + } + + /* Internal sequences of whitespace are replaced by one space + except within an string or char token. */ + if (! in_string + && (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c])) { + while (1) { + /* Note that Newline Space does occur within whitespace + sequences; consider it part of the sequence. */ + if (c == '\n' && is_space[arg->raw[i+1]]) + i += 2; + else if (c != '\n' && is_space[c]) + i++; + else break; + c = arg->raw[i]; + } + i--; + c = ' '; + } + + if (escaped) + escaped = 0; + else { + if (c == '\\') + escaped = 1; + if (in_string) { + if (c == in_string) + in_string = 0; + } else if (c == '\"' || c == '\'') + in_string = c; + } + + /* Escape these chars */ + if (c == '\"' || (in_string && c == '\\')) + xbuf[totlen++] = '\\'; + if (isprint (c)) + xbuf[totlen++] = c; + else { + sprintf ((char *) &xbuf[totlen], "\\%03o", (unsigned int) c); + totlen += 4; + } + } + if (!traditional) + xbuf[totlen++] = '\"'; /* insert ending quote */ + } else if (ap->raw_before != 0 || ap->raw_after != 0 || traditional) { + U_CHAR *p1 = arg->raw; + U_CHAR *l1 = p1 + arg->raw_length; + if (ap->raw_before != 0) { + while (p1 != l1 && is_space[*p1]) p1++; + while (p1 != l1 && is_idchar[*p1]) + xbuf[totlen++] = *p1++; + /* Delete any no-reexpansion marker that follows + an identifier at the beginning of the argument + if the argument is concatenated with what precedes it. */ + if (p1[0] == '\n' && p1[1] == '-') + p1 += 2; + } else if (!traditional) { + /* Ordinary expanded use of the argument. + Put in newline-space markers to prevent token pasting. */ + xbuf[totlen++] = '\n'; + xbuf[totlen++] = ' '; + } + if (ap->raw_after != 0) { + /* Arg is concatenated after: delete trailing whitespace, + whitespace markers, and no-reexpansion markers. */ + while (p1 != l1) { + if (is_space[l1[-1]]) l1--; + else if (l1[-1] == '-') { + U_CHAR *p2 = l1 - 1; + /* If a `-' is preceded by an odd number of newlines then it + and the last newline are a no-reexpansion marker. */ + while (p2 != p1 && p2[-1] == '\n') p2--; + if ((l1 - 1 - p2) & 1) { + l1 -= 2; + } + else break; + } + else break; + } + } + + bcopy ((char *) p1, (char *) (xbuf + totlen), l1 - p1); + totlen += l1 - p1; + if (!traditional && ap->raw_after == 0) { + /* Ordinary expanded use of the argument. + Put in newline-space markers to prevent token pasting. */ + xbuf[totlen++] = '\n'; + xbuf[totlen++] = ' '; + } + } else { + /* Ordinary expanded use of the argument. + Put in newline-space markers to prevent token pasting. */ + if (!traditional) { + xbuf[totlen++] = '\n'; + xbuf[totlen++] = ' '; + } + bcopy ((char *) arg->expanded, (char *) (xbuf + totlen), + arg->expand_length); + totlen += arg->expand_length; + if (!traditional) { + xbuf[totlen++] = '\n'; + xbuf[totlen++] = ' '; + } + /* If a macro argument with newlines is used multiple times, + then only expand the newlines once. This avoids creating output + lines which don't correspond to any input line, which confuses + gdb and gcov. */ + if (arg->use_count > 1 && arg->newlines > 0) { + /* Don't bother doing change_newlines for subsequent + uses of arg. */ + arg->use_count = 1; + arg->expand_length + = change_newlines (arg->expanded, arg->expand_length); + } + } + + if (totlen > xbuf_len) + abort (); + } + + /* if there is anything left of the definition + after handling the arg list, copy that in too. */ + + for (i = offset; i < defn->length; i++) { + /* if we've reached the end of the macro */ + if (exp[i] == ')') + rest_zero = 0; + if (! (rest_zero && last_ap != NULL && last_ap->rest_args + && last_ap->raw_after != 0)) + xbuf[totlen++] = exp[i]; + } + + xbuf[totlen] = 0; + xbuf_len = totlen; + + for (i = 0; i < nargs; i++) { + if (args[i].free1 != 0) + free (args[i].free1); + if (args[i].free2 != 0) + free (args[i].free2); + } + } + } else { + xbuf = defn->expansion; + xbuf_len = defn->length; + } + + /* Now put the expansion on the input stack + so our caller will commence reading from it. */ + { + register FILE_BUF *ip2; + + ip2 = &instack[++indepth]; + + ip2->fname = 0; + ip2->nominal_fname = 0; + /* This may not be exactly correct, but will give much better error + messages for nested macro calls than using a line number of zero. */ + ip2->lineno = start_line; + ip2->buf = xbuf; + ip2->length = xbuf_len; + ip2->bufp = xbuf; + ip2->free_ptr = (nargs > 0) ? xbuf : 0; + ip2->macro = hp; + ip2->if_stack = if_stack; + ip2->system_header_p = 0; + + /* Recursive macro use sometimes works traditionally. + #define foo(x,y) bar (x (y,0), y) + foo (foo, baz) */ + + if (!traditional) + hp->type = T_DISABLED; + } +} + +/* + * Parse a macro argument and store the info on it into *ARGPTR. + * REST_ARGS is passed to macarg1 to make it absorb the rest of the args. + * Return nonzero to indicate a syntax error. + */ + +static char * +macarg (argptr, rest_args) + register struct argdata *argptr; + int rest_args; +{ + FILE_BUF *ip = &instack[indepth]; + int paren = 0; + int newlines = 0; + int comments = 0; + char *result = 0; + + /* Try to parse as much of the argument as exists at this + input stack level. */ + U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length, + &paren, &newlines, &comments, rest_args); + + /* If we find the end of the argument at this level, + set up *ARGPTR to point at it in the input stack. */ + if (!(ip->fname != 0 && (newlines != 0 || comments != 0)) + && bp != ip->buf + ip->length) { + if (argptr != 0) { + argptr->raw = ip->bufp; + argptr->raw_length = bp - ip->bufp; + argptr->newlines = newlines; + } + ip->bufp = bp; + } else { + /* This input stack level ends before the macro argument does. + We must pop levels and keep parsing. + Therefore, we must allocate a temporary buffer and copy + the macro argument into it. */ + int bufsize = bp - ip->bufp; + int extra = newlines; + U_CHAR *buffer = (U_CHAR *) xmalloc (bufsize + extra + 1); + int final_start = 0; + + bcopy ((char *) ip->bufp, (char *) buffer, bufsize); + ip->bufp = bp; + ip->lineno += newlines; + + while (bp == ip->buf + ip->length) { + if (instack[indepth].macro == 0) { + result = "unterminated macro call"; + break; + } + ip->macro->type = T_MACRO; + if (ip->free_ptr) + free (ip->free_ptr); + ip = &instack[--indepth]; + newlines = 0; + comments = 0; + bp = macarg1 (ip->bufp, ip->buf + ip->length, &paren, + &newlines, &comments, rest_args); + final_start = bufsize; + bufsize += bp - ip->bufp; + extra += newlines; + buffer = (U_CHAR *) xrealloc (buffer, bufsize + extra + 1); + bcopy ((char *) ip->bufp, (char *) (buffer + bufsize - (bp - ip->bufp)), + bp - ip->bufp); + ip->bufp = bp; + ip->lineno += newlines; + } + + /* Now, if arg is actually wanted, record its raw form, + discarding comments and duplicating newlines in whatever + part of it did not come from a macro expansion. + EXTRA space has been preallocated for duplicating the newlines. + FINAL_START is the index of the start of that part. */ + if (argptr != 0) { + argptr->raw = buffer; + argptr->raw_length = bufsize; + argptr->free1 = buffer; + argptr->newlines = newlines; + if ((newlines || comments) && ip->fname != 0) + argptr->raw_length + = final_start + + discard_comments (argptr->raw + final_start, + argptr->raw_length - final_start, + newlines); + argptr->raw[argptr->raw_length] = 0; + if (argptr->raw_length > bufsize + extra) + abort (); + } + } + + /* If we are not discarding this argument, + macroexpand it and compute its length as stringified. + All this info goes into *ARGPTR. */ + + if (argptr != 0) { + register U_CHAR *buf, *lim; + register int totlen; + + buf = argptr->raw; + lim = buf + argptr->raw_length; + + while (buf != lim && is_space[*buf]) + buf++; + while (buf != lim && is_space[lim[-1]]) + lim--; + totlen = traditional ? 0 : 2; /* Count opening and closing quote. */ + while (buf != lim) { + register U_CHAR c = *buf++; + totlen++; + /* Internal sequences of whitespace are replaced by one space + in most cases, but not always. So count all the whitespace + in case we need to keep it all. */ +#if 0 + if (is_space[c]) + SKIP_ALL_WHITE_SPACE (buf); + else +#endif + if (c == '\"' || c == '\\') /* escape these chars */ + totlen++; + else if (!isprint (c)) + totlen += 3; + } + argptr->stringified_length = totlen; + } + return result; +} + +/* Scan text from START (inclusive) up to LIMIT (exclusive), + counting parens in *DEPTHPTR, + and return if reach LIMIT + or before a `)' that would make *DEPTHPTR negative + or before a comma when *DEPTHPTR is zero. + Single and double quotes are matched and termination + is inhibited within them. Comments also inhibit it. + Value returned is pointer to stopping place. + + Increment *NEWLINES each time a newline is passed. + REST_ARGS notifies macarg1 that it should absorb the rest of the args. + Set *COMMENTS to 1 if a comment is seen. */ + +static U_CHAR * +macarg1 (start, limit, depthptr, newlines, comments, rest_args) + U_CHAR *start; + register U_CHAR *limit; + int *depthptr, *newlines, *comments; + int rest_args; +{ + register U_CHAR *bp = start; + + while (bp < limit) { + switch (*bp) { + case '(': + (*depthptr)++; + break; + case ')': + if (--(*depthptr) < 0) + return bp; + break; + case '\\': + /* Traditionally, backslash makes following char not special. */ + if (bp + 1 < limit && traditional) + { + bp++; + /* But count source lines anyway. */ + if (*bp == '\n') + ++*newlines; + } + break; + case '\n': + ++*newlines; + break; + case '/': + if (bp[1] == '\\' && bp[2] == '\n') + newline_fix (bp + 1); + if (cplusplus_comments && bp[1] == '/') { + *comments = 1; + bp += 2; + while (bp < limit && (*bp != '\n' || bp[-1] == '\\')) { + if (*bp == '\n') ++*newlines; + bp++; + } + /* Now count the newline that we are about to skip. */ + ++*newlines; + break; + } + if (bp[1] != '*' || bp + 1 >= limit) + break; + *comments = 1; + bp += 2; + while (bp + 1 < limit) { + if (bp[0] == '*' + && bp[1] == '\\' && bp[2] == '\n') + newline_fix (bp + 1); + if (bp[0] == '*' && bp[1] == '/') + break; + if (*bp == '\n') ++*newlines; + bp++; + } + break; + case '\'': + case '\"': + { + int quotec; + for (quotec = *bp++; bp + 1 < limit && *bp != quotec; bp++) { + if (*bp == '\\') { + bp++; + if (*bp == '\n') + ++*newlines; + while (*bp == '\\' && bp[1] == '\n') { + bp += 2; + } + } else if (*bp == '\n') { + ++*newlines; + if (quotec == '\'') + break; + } + } + } + break; + case ',': + /* if we've returned to lowest level and we aren't absorbing all args */ + if ((*depthptr) == 0 && rest_args == 0) + return bp; + break; + } + bp++; + } + + return bp; +} + +/* Discard comments and duplicate newlines + in the string of length LENGTH at START, + except inside of string constants. + The string is copied into itself with its beginning staying fixed. + + NEWLINES is the number of newlines that must be duplicated. + We assume that that much extra space is available past the end + of the string. */ + +static int +discard_comments (start, length, newlines) + U_CHAR *start; + int length; + int newlines; +{ + register U_CHAR *ibp; + register U_CHAR *obp; + register U_CHAR *limit; + register int c; + + /* If we have newlines to duplicate, copy everything + that many characters up. Then, in the second part, + we will have room to insert the newlines + while copying down. + NEWLINES may actually be too large, because it counts + newlines in string constants, and we don't duplicate those. + But that does no harm. */ + if (newlines > 0) { + ibp = start + length; + obp = ibp + newlines; + limit = start; + while (limit != ibp) + *--obp = *--ibp; + } + + ibp = start + newlines; + limit = start + length + newlines; + obp = start; + + while (ibp < limit) { + *obp++ = c = *ibp++; + switch (c) { + case '\n': + /* Duplicate the newline. */ + *obp++ = '\n'; + break; + + case '\\': + if (*ibp == '\n') { + obp--; + ibp++; + } + break; + + case '/': + if (*ibp == '\\' && ibp[1] == '\n') + newline_fix (ibp); + /* Delete any comment. */ + if (cplusplus_comments && ibp[0] == '/') { + /* Comments are equivalent to spaces. */ + obp[-1] = ' '; + ibp++; + while (ibp < limit && (*ibp != '\n' || ibp[-1] == '\\')) + ibp++; + break; + } + if (ibp[0] != '*' || ibp + 1 >= limit) + break; + /* Comments are equivalent to spaces. + For -traditional, a comment is equivalent to nothing. */ + if (traditional) + obp--; + else + obp[-1] = ' '; + ibp++; + while (ibp + 1 < limit) { + if (ibp[0] == '*' + && ibp[1] == '\\' && ibp[2] == '\n') + newline_fix (ibp + 1); + if (ibp[0] == '*' && ibp[1] == '/') + break; + ibp++; + } + ibp += 2; + break; + + case '\'': + case '\"': + /* Notice and skip strings, so that we don't + think that comments start inside them, + and so we don't duplicate newlines in them. */ + { + int quotec = c; + while (ibp < limit) { + *obp++ = c = *ibp++; + if (c == quotec) + break; + if (c == '\n' && quotec == '\'') + break; + if (c == '\\' && ibp < limit) { + while (*ibp == '\\' && ibp[1] == '\n') + ibp += 2; + *obp++ = *ibp++; + } + } + } + break; + } + } + + return obp - start; +} + +/* Turn newlines to spaces in the string of length LENGTH at START, + except inside of string constants. + The string is copied into itself with its beginning staying fixed. */ + +static int +change_newlines (start, length) + U_CHAR *start; + int length; +{ + register U_CHAR *ibp; + register U_CHAR *obp; + register U_CHAR *limit; + register int c; + + ibp = start; + limit = start + length; + obp = start; + + while (ibp < limit) { + *obp++ = c = *ibp++; + switch (c) { + case '\n': + /* If this is a NEWLINE NEWLINE, then this is a real newline in the + string. Skip past the newline and its duplicate. + Put a space in the output. */ + if (*ibp == '\n') + { + ibp++; + obp--; + *obp++ = ' '; + } + break; + + case '\'': + case '\"': + /* Notice and skip strings, so that we don't delete newlines in them. */ + { + int quotec = c; + while (ibp < limit) { + *obp++ = c = *ibp++; + if (c == quotec) + break; + if (c == '\n' && quotec == '\'') + break; + } + } + break; + } + } + + return obp - start; +} + +/* + * my_strerror - return the descriptive text associated with an `errno' code. + */ + +char * +my_strerror (errnum) + int errnum; +{ + char *result; + +#ifndef VMS +#ifndef HAVE_STRERROR + result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0); +#else + result = strerror (errnum); +#endif +#else /* VMS */ + /* VAXCRTL's strerror() takes an optional second argument, which only + matters when the first argument is EVMSERR. However, it's simplest + just to pass it unconditionally. `vaxc$errno' is declared in + , and maintained by the library in parallel with `errno'. + We assume that caller's `errnum' either matches the last setting of + `errno' by the library or else does not have the value `EVMSERR'. */ + + result = strerror (errnum, vaxc$errno); +#endif + + if (!result) + result = "undocumented I/O error"; + + return result; +} + +/* + * error - print error message and increment count of errors. + */ + +void +error (PRINTF_ALIST (msg)) + PRINTF_DCL (msg) +{ + va_list args; + + VA_START (args, msg); + verror (msg, args); + va_end (args); +} + +static void +verror (msg, args) + char *msg; + va_list args; +{ + int i; + FILE_BUF *ip = NULL; + + print_containing_files (); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) + fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); + errors++; +} + +/* Error including a message from `errno'. */ + +static void +error_from_errno (name) + char *name; +{ + int i; + FILE_BUF *ip = NULL; + + print_containing_files (); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) + fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno); + + fprintf (stderr, "%s: %s\n", name, my_strerror (errno)); + + errors++; +} + +/* Print error message but don't count it. */ + +void +warning (PRINTF_ALIST (msg)) + PRINTF_DCL (msg) +{ + va_list args; + + VA_START (args, msg); + vwarning (msg, args); + va_end (args); +} + +static void +vwarning (msg, args) + char *msg; + va_list args; +{ + int i; + FILE_BUF *ip = NULL; + + if (inhibit_warnings) + return; + + if (warnings_are_errors) + errors++; + + print_containing_files (); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) + fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno); + fprintf (stderr, "warning: "); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); +} + +static void +#if defined (__STDC__) && defined (HAVE_VPRINTF) +error_with_line (int line, PRINTF_ALIST (msg)) +#else +error_with_line (line, PRINTF_ALIST (msg)) + int line; + PRINTF_DCL (msg) +#endif +{ + va_list args; + + VA_START (args, msg); + verror_with_line (line, msg, args); + va_end (args); +} + +static void +verror_with_line (line, msg, args) + int line; + char *msg; + va_list args; +{ + int i; + FILE_BUF *ip = NULL; + + print_containing_files (); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) + fprintf (stderr, "%s:%d: ", ip->nominal_fname, line); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); + errors++; +} + +static void +#if defined (__STDC__) && defined (HAVE_VPRINTF) +warning_with_line (int line, PRINTF_ALIST (msg)) +#else +warning_with_line (line, PRINTF_ALIST (msg)) + int line; + PRINTF_DCL (msg) +#endif +{ + va_list args; + + VA_START (args, msg); + vwarning_with_line (line, msg, args); + va_end (args); +} + +static void +vwarning_with_line (line, msg, args) + int line; + char *msg; + va_list args; +{ + int i; + FILE_BUF *ip = NULL; + + if (inhibit_warnings) + return; + + if (warnings_are_errors) + errors++; + + print_containing_files (); + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + if (ip != NULL) + fprintf (stderr, line ? "%s:%d: " : "%s: ", ip->nominal_fname, line); + fprintf (stderr, "warning: "); + vfprintf (stderr, msg, args); + fprintf (stderr, "\n"); +} + +/* print an error message and maybe count it. */ + +void +pedwarn (PRINTF_ALIST (msg)) + PRINTF_DCL (msg) +{ + va_list args; + + VA_START (args, msg); + if (pedantic_errors) + verror (msg, args); + else + vwarning (msg, args); + va_end (args); +} + +void +#if defined (__STDC__) && defined (HAVE_VPRINTF) +pedwarn_with_line (int line, PRINTF_ALIST (msg)) +#else +pedwarn_with_line (line, PRINTF_ALIST (msg)) + int line; + PRINTF_DCL (msg) +#endif +{ + va_list args; + + VA_START (args, msg); + if (pedantic_errors) + verror_with_line (line, msg, args); + else + vwarning_with_line (line, msg, args); + va_end (args); +} + +/* Report a warning (or an error if pedantic_errors) + giving specified file name and line number, not current. */ + +static void +#if defined (__STDC__) && defined (HAVE_VPRINTF) +pedwarn_with_file_and_line (char *file, int line, PRINTF_ALIST (msg)) +#else +pedwarn_with_file_and_line (file, line, PRINTF_ALIST (msg)) + char *file; + int line; + PRINTF_DCL (msg) +#endif +{ + va_list args; + + if (!pedantic_errors && inhibit_warnings) + return; + if (file != NULL) + fprintf (stderr, "%s:%d: ", file, line); + if (pedantic_errors) + errors++; + if (!pedantic_errors) + fprintf (stderr, "warning: "); + VA_START (args, msg); + vfprintf (stderr, msg, args); + va_end (args); + fprintf (stderr, "\n"); +} + +/* Print the file names and line numbers of the #include + directives which led to the current file. */ + +static void +print_containing_files () +{ + FILE_BUF *ip = NULL; + int i; + int first = 1; + + /* If stack of files hasn't changed since we last printed + this info, don't repeat it. */ + if (last_error_tick == input_file_stack_tick) + return; + + for (i = indepth; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + break; + } + + /* Give up if we don't find a source file. */ + if (ip == NULL) + return; + + /* Find the other, outer source files. */ + for (i--; i >= 0; i--) + if (instack[i].fname != NULL) { + ip = &instack[i]; + if (first) { + first = 0; + fprintf (stderr, "In file included"); + } else { + fprintf (stderr, ",\n "); + } + + fprintf (stderr, " from %s:%d", ip->nominal_fname, ip->lineno); + } + if (! first) + fprintf (stderr, ":\n"); + + /* Record we have printed the status as of this time. */ + last_error_tick = input_file_stack_tick; +} + +/* Return the line at which an error occurred. + The error is not necessarily associated with the current spot + in the input stack, so LINE says where. LINE will have been + copied from ip->lineno for the current input level. + If the current level is for a file, we return LINE. + But if the current level is not for a file, LINE is meaningless. + In that case, we return the lineno of the innermost file. */ + +static int +line_for_error (line) + int line; +{ + int i; + int line1 = line; + + for (i = indepth; i >= 0; ) { + if (instack[i].fname != 0) + return line1; + i--; + if (i < 0) + return 0; + line1 = instack[i].lineno; + } + abort (); + /*NOTREACHED*/ + return 0; +} + +/* + * If OBUF doesn't have NEEDED bytes after OPTR, make it bigger. + * + * As things stand, nothing is ever placed in the output buffer to be + * removed again except when it's KNOWN to be part of an identifier, + * so flushing and moving down everything left, instead of expanding, + * should work ok. + */ + +/* You might think void was cleaner for the return type, + but that would get type mismatch in check_expand in strict ANSI. */ +static int +grow_outbuf (obuf, needed) + register FILE_BUF *obuf; + register int needed; +{ + register U_CHAR *p; + int minsize; + + if (obuf->length - (obuf->bufp - obuf->buf) > needed) + return 0; + + /* Make it at least twice as big as it is now. */ + obuf->length *= 2; + /* Make it have at least 150% of the free space we will need. */ + minsize = (3 * needed) / 2 + (obuf->bufp - obuf->buf); + if (minsize > obuf->length) + obuf->length = minsize; + + if ((p = (U_CHAR *) xrealloc (obuf->buf, obuf->length)) == NULL) + memory_full (); + + obuf->bufp = p + (obuf->bufp - obuf->buf); + obuf->buf = p; + + return 0; +} + +/* Symbol table for macro names and special symbols */ + +/* + * install a name in the main hash table, even if it is already there. + * name stops with first non alphanumeric, except leading '#'. + * caller must check against redefinition if that is desired. + * delete_macro () removes things installed by install () in fifo order. + * this is important because of the `defined' special symbol used + * in #if, and also if pushdef/popdef directives are ever implemented. + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +static HASHNODE * +install (name, len, type, value, hash) + U_CHAR *name; + int len; + enum node_type type; + char *value; + int hash; +{ + register HASHNODE *hp; + register int i, bucket; + register U_CHAR *p, *q; + + if (len < 0) { + p = name; + while (is_idchar[*p]) + p++; + len = p - name; + } + + if (hash < 0) + hash = hashf (name, len, HASHSIZE); + + i = sizeof (HASHNODE) + len + 1; + hp = (HASHNODE *) xmalloc (i); + bucket = hash; + hp->bucket_hdr = &hashtab[bucket]; + hp->next = hashtab[bucket]; + hashtab[bucket] = hp; + hp->prev = NULL; + if (hp->next != NULL) + hp->next->prev = hp; + hp->type = type; + hp->length = len; + hp->value.cpval = value; + hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE); + p = hp->name; + q = name; + for (i = 0; i < len; i++) + *p++ = *q++; + hp->name[len] = 0; + return hp; +} + +/* + * find the most recent hash node for name name (ending with first + * non-identifier char) installed by install + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +HASHNODE * +lookup (name, len, hash) + U_CHAR *name; + int len; + int hash; +{ + register U_CHAR *bp; + register HASHNODE *bucket; + + if (len < 0) { + for (bp = name; is_idchar[*bp]; bp++) ; + len = bp - name; + } + + if (hash < 0) + hash = hashf (name, len, HASHSIZE); + + bucket = hashtab[hash]; + while (bucket) { + if (bucket->length == len && bcmp (bucket->name, name, len) == 0) + return bucket; + bucket = bucket->next; + } + return NULL; +} + +/* + * Delete a hash node. Some weirdness to free junk from macros. + * More such weirdness will have to be added if you define more hash + * types that need it. + */ + +/* Note that the DEFINITION of a macro is removed from the hash table + but its storage is not freed. This would be a storage leak + except that it is not reasonable to keep undefining and redefining + large numbers of macros many times. + In any case, this is necessary, because a macro can be #undef'd + in the middle of reading the arguments to a call to it. + If #undef freed the DEFINITION, that would crash. */ + +static void +delete_macro (hp) + HASHNODE *hp; +{ + + if (hp->prev != NULL) + hp->prev->next = hp->next; + if (hp->next != NULL) + hp->next->prev = hp->prev; + + /* make sure that the bucket chain header that + the deleted guy was on points to the right thing afterwards. */ + if (hp == *hp->bucket_hdr) + *hp->bucket_hdr = hp->next; + +#if 0 + if (hp->type == T_MACRO) { + DEFINITION *d = hp->value.defn; + struct reflist *ap, *nextap; + + for (ap = d->pattern; ap != NULL; ap = nextap) { + nextap = ap->next; + free (ap); + } + free (d); + } +#endif + free (hp); +} + +/* + * return hash function on name. must be compatible with the one + * computed a step at a time, elsewhere + */ +static int +hashf (name, len, hashsize) + register U_CHAR *name; + register int len; + int hashsize; +{ + register int r = 0; + + while (len--) + r = HASHSTEP (r, *name++); + + return MAKE_POS (r) % hashsize; +} + + +/* Dump the definition of a single macro HP to OF. */ +static void +dump_single_macro (hp, of) + register HASHNODE *hp; + FILE *of; +{ + register DEFINITION *defn = hp->value.defn; + struct reflist *ap; + int offset; + int concat; + + + /* Print the definition of the macro HP. */ + + fprintf (of, "#define %s", hp->name); + + if (defn->nargs >= 0) { + int i; + + fprintf (of, "("); + for (i = 0; i < defn->nargs; i++) { + dump_arg_n (defn, i, of); + if (i + 1 < defn->nargs) + fprintf (of, ", "); + } + fprintf (of, ")"); + } + + fprintf (of, " "); + + offset = 0; + concat = 0; + for (ap = defn->pattern; ap != NULL; ap = ap->next) { + dump_defn_1 (defn->expansion, offset, ap->nchars, of); + offset += ap->nchars; + if (!traditional) { + if (ap->nchars != 0) + concat = 0; + if (ap->stringify) { + switch (ap->stringify) { + case SHARP_TOKEN: fprintf (of, "#"); break; + case WHITE_SHARP_TOKEN: fprintf (of, "# "); break; + case PERCENT_COLON_TOKEN: fprintf (of, "%%:"); break; + case WHITE_PERCENT_COLON_TOKEN: fprintf (of, "%%: "); break; + default: abort (); + } + } + if (ap->raw_before != 0) { + if (concat) { + switch (ap->raw_before) { + case WHITE_SHARP_TOKEN: + case WHITE_PERCENT_COLON_TOKEN: + fprintf (of, " "); + break; + default: + break; + } + } else { + switch (ap->raw_before) { + case SHARP_TOKEN: fprintf (of, "##"); break; + case WHITE_SHARP_TOKEN: fprintf (of, "## "); break; + case PERCENT_COLON_TOKEN: fprintf (of, "%%:%%:"); break; + case WHITE_PERCENT_COLON_TOKEN: fprintf (of, "%%:%%: "); break; + default: abort (); + } + } + } + concat = 0; + } + dump_arg_n (defn, ap->argno, of); + if (!traditional && ap->raw_after != 0) { + switch (ap->raw_after) { + case SHARP_TOKEN: fprintf (of, "##"); break; + case WHITE_SHARP_TOKEN: fprintf (of, " ##"); break; + case PERCENT_COLON_TOKEN: fprintf (of, "%%:%%:"); break; + case WHITE_PERCENT_COLON_TOKEN: fprintf (of, " %%:%%:"); break; + default: abort (); + } + concat = 1; + } + } + dump_defn_1 (defn->expansion, offset, defn->length - offset, of); + fprintf (of, "\n"); +} + +/* Dump all macro definitions as #defines to stdout. */ + +static void +dump_all_macros () +{ + int bucket; + + for (bucket = 0; bucket < HASHSIZE; bucket++) { + register HASHNODE *hp; + + for (hp = hashtab[bucket]; hp; hp= hp->next) { + if (hp->type == T_MACRO) + dump_single_macro (hp, stdout); + } + } +} + +/* Output to OF a substring of a macro definition. + BASE is the beginning of the definition. + Output characters START thru LENGTH. + Unless traditional, discard newlines outside of strings, thus + converting funny-space markers to ordinary spaces. */ + +static void +dump_defn_1 (base, start, length, of) + U_CHAR *base; + int start; + int length; + FILE *of; +{ + U_CHAR *p = base + start; + U_CHAR *limit = base + start + length; + + if (traditional) + fwrite (p, sizeof (*p), length, of); + else { + while (p < limit) { + if (*p == '\"' || *p =='\'') { + U_CHAR *p1 = skip_quoted_string (p, limit, 0, NULL_PTR, + NULL_PTR, NULL_PTR); + fwrite (p, sizeof (*p), p1 - p, of); + p = p1; + } else { + if (*p != '\n') + putc (*p, of); + p++; + } + } + } +} + +/* Print the name of argument number ARGNUM of macro definition DEFN + to OF. + Recall that DEFN->args.argnames contains all the arg names + concatenated in reverse order with comma-space in between. */ + +static void +dump_arg_n (defn, argnum, of) + DEFINITION *defn; + int argnum; + FILE *of; +{ + register U_CHAR *p = defn->args.argnames; + while (argnum + 1 < defn->nargs) { + p = (U_CHAR *) index ((char *) p, ' ') + 1; + argnum++; + } + + while (*p && *p != ',') { + putc (*p, of); + p++; + } +} + +/* Initialize syntactic classifications of characters. */ + +static void +initialize_char_syntax () +{ + register int i; + + /* + * Set up is_idchar and is_idstart tables. These should be + * faster than saying (is_alpha (c) || c == '_'), etc. + * Set up these things before calling any routines tthat + * refer to them. + */ + for (i = 'a'; i <= 'z'; i++) { + is_idchar[i - 'a' + 'A'] = 1; + is_idchar[i] = 1; + is_idstart[i - 'a' + 'A'] = 1; + is_idstart[i] = 1; + } + for (i = '0'; i <= '9'; i++) + is_idchar[i] = 1; + is_idchar['_'] = 1; + is_idstart['_'] = 1; + is_idchar['$'] = dollars_in_ident; + is_idstart['$'] = dollars_in_ident; + + /* horizontal space table */ + is_hor_space[' '] = 1; + is_hor_space['\t'] = 1; + is_hor_space['\v'] = 1; + is_hor_space['\f'] = 1; + is_hor_space['\r'] = 1; + + is_space[' '] = 1; + is_space['\t'] = 1; + is_space['\v'] = 1; + is_space['\f'] = 1; + is_space['\n'] = 1; + is_space['\r'] = 1; + + char_name['\v'] = "vertical tab"; + char_name['\f'] = "formfeed"; + char_name['\r'] = "carriage return"; +} + +/* Initialize the built-in macros. */ + +static void +initialize_builtins (inp, outp) + FILE_BUF *inp; + FILE_BUF *outp; +{ + install ((U_CHAR *) "__LINE__", -1, T_SPECLINE, NULL_PTR, -1); + install ((U_CHAR *) "__DATE__", -1, T_DATE, NULL_PTR, -1); + install ((U_CHAR *) "__FILE__", -1, T_FILE, NULL_PTR, -1); + install ((U_CHAR *) "__BASE_FILE__", -1, T_BASE_FILE, NULL_PTR, -1); + install ((U_CHAR *) "__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, NULL_PTR, -1); + install ((U_CHAR *) "__VERSION__", -1, T_VERSION, NULL_PTR, -1); +#ifndef NO_BUILTIN_SIZE_TYPE + install ((U_CHAR *) "__SIZE_TYPE__", -1, T_SIZE_TYPE, NULL_PTR, -1); +#endif +#ifndef NO_BUILTIN_PTRDIFF_TYPE + install ((U_CHAR *) "__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, NULL_PTR, -1); +#endif + install ((U_CHAR *) "__WCHAR_TYPE__", -1, T_WCHAR_TYPE, NULL_PTR, -1); + install ((U_CHAR *) "__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, + NULL_PTR, -1); + install ((U_CHAR *) "__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, + NULL_PTR, -1); + install ((U_CHAR *) "__IMMEDIATE_PREFIX__", -1, T_IMMEDIATE_PREFIX_TYPE, + NULL_PTR, -1); + install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1); + if (!traditional) { + install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1); + install ((U_CHAR *) "__STDC_VERSION__", -1, T_CONST, "199409L", -1); + } + if (objc) + install ((U_CHAR *) "__OBJC__", -1, T_CONST, "1", -1); +/* This is supplied using a -D by the compiler driver + so that it is present only when truly compiling with GNU C. */ +/* install ((U_CHAR *) "__GNUC__", -1, T_CONST, "2", -1); */ + + if (debug_output) + { + char directive[2048]; + U_CHAR *udirective = (U_CHAR *) directive; + register struct directive *dp = &directive_table[0]; + struct tm *timebuf = timestamp (); + + sprintf (directive, " __BASE_FILE__ \"%s\"\n", + instack[0].nominal_fname); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + + sprintf (directive, " __VERSION__ \"%s\"\n", version_string); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + +#ifndef NO_BUILTIN_SIZE_TYPE + sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); +#endif + +#ifndef NO_BUILTIN_PTRDIFF_TYPE + sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); +#endif + + sprintf (directive, " __WCHAR_TYPE__ %s\n", wchar_type); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + + sprintf (directive, " __DATE__ \"%s %2d %4d\"\n", + monthnames[timebuf->tm_mon], + timebuf->tm_mday, timebuf->tm_year + 1900); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + + sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n", + timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + + if (!traditional) + { + sprintf (directive, " __STDC__ 1"); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + } + if (objc) + { + sprintf (directive, " __OBJC__ 1"); + output_line_directive (inp, outp, 0, same_file); + pass_thru_directive (udirective, &udirective[strlen (directive)], + outp, dp); + } + } +} + +/* + * process a given definition string, for initialization + * If STR is just an identifier, define it with value 1. + * If STR has anything after the identifier, then it should + * be identifier=definition. + */ + +static void +make_definition (str, op) + char *str; + FILE_BUF *op; +{ + FILE_BUF *ip; + struct directive *kt; + U_CHAR *buf, *p; + + p = buf = (U_CHAR *) str; + if (!is_idstart[*p]) { + error ("malformed option `-D %s'", str); + return; + } + while (is_idchar[*++p]) + ; + if (*p == '(') { + while (is_idchar[*++p] || *p == ',' || is_hor_space[*p]) + ; + if (*p++ != ')') + p = (U_CHAR *) str; /* Error */ + } + if (*p == 0) { + buf = (U_CHAR *) alloca (p - buf + 4); + strcpy ((char *)buf, str); + strcat ((char *)buf, " 1"); + } else if (*p != '=') { + error ("malformed option `-D %s'", str); + return; + } else { + U_CHAR *q; + /* Copy the entire option so we can modify it. */ + buf = (U_CHAR *) alloca (2 * strlen (str) + 1); + strncpy ((char *) buf, str, p - (U_CHAR *) str); + /* Change the = to a space. */ + buf[p - (U_CHAR *) str] = ' '; + /* Scan for any backslash-newline and remove it. */ + p++; + q = &buf[p - (U_CHAR *) str]; + while (*p) { + if (*p == '\"' || *p == '\'') { + int unterminated = 0; + U_CHAR *p1 = skip_quoted_string (p, p + strlen ((char *) p), 0, + NULL_PTR, NULL_PTR, &unterminated); + if (unterminated) + return; + while (p != p1) + if (*p == '\\' && p[1] == '\n') + p += 2; + else + *q++ = *p++; + } else if (*p == '\\' && p[1] == '\n') + p += 2; + /* Change newline chars into newline-markers. */ + else if (*p == '\n') + { + *q++ = '\n'; + *q++ = '\n'; + p++; + } + else + *q++ = *p++; + } + *q = 0; + } + + ip = &instack[++indepth]; + ip->nominal_fname = ip->fname = "*Initialization*"; + + ip->buf = ip->bufp = buf; + ip->length = strlen ((char *) buf); + ip->lineno = 1; + ip->macro = 0; + ip->free_ptr = 0; + ip->if_stack = if_stack; + ip->system_header_p = 0; + + for (kt = directive_table; kt->type != T_DEFINE; kt++) + ; + + /* Pass NULL instead of OP, since this is a "predefined" macro. */ + do_define (buf, buf + strlen ((char *) buf), NULL_PTR, kt); + --indepth; +} + +/* JF, this does the work for the -U option */ + +static void +make_undef (str, op) + char *str; + FILE_BUF *op; +{ + FILE_BUF *ip; + struct directive *kt; + + ip = &instack[++indepth]; + ip->nominal_fname = ip->fname = "*undef*"; + + ip->buf = ip->bufp = (U_CHAR *) str; + ip->length = strlen (str); + ip->lineno = 1; + ip->macro = 0; + ip->free_ptr = 0; + ip->if_stack = if_stack; + ip->system_header_p = 0; + + for (kt = directive_table; kt->type != T_UNDEF; kt++) + ; + + do_undef ((U_CHAR *) str, (U_CHAR *) str + strlen (str), op, kt); + --indepth; +} + +/* Process the string STR as if it appeared as the body of a #assert. + OPTION is the option name for which STR was the argument. */ + +static void +make_assertion (option, str) + char *option; + char *str; +{ + FILE_BUF *ip; + struct directive *kt; + U_CHAR *buf, *p, *q; + + /* Copy the entire option so we can modify it. */ + buf = (U_CHAR *) alloca (strlen (str) + 1); + strcpy ((char *) buf, str); + /* Scan for any backslash-newline and remove it. */ + p = q = buf; + while (*p) { + if (*p == '\\' && p[1] == '\n') + p += 2; + else + *q++ = *p++; + } + *q = 0; + + p = buf; + if (!is_idstart[*p]) { + error ("malformed option `%s %s'", option, str); + return; + } + while (is_idchar[*++p]) + ; + SKIP_WHITE_SPACE (p); + if (! (*p == 0 || *p == '(')) { + error ("malformed option `%s %s'", option, str); + return; + } + + ip = &instack[++indepth]; + ip->nominal_fname = ip->fname = "*Initialization*"; + + ip->buf = ip->bufp = buf; + ip->length = strlen ((char *) buf); + ip->lineno = 1; + ip->macro = 0; + ip->free_ptr = 0; + ip->if_stack = if_stack; + ip->system_header_p = 0; + + for (kt = directive_table; kt->type != T_ASSERT; kt++) + ; + + /* pass NULL as output ptr to do_define since we KNOW it never + does any output.... */ + do_assert (buf, buf + strlen ((char *) buf) , NULL_PTR, kt); + --indepth; +} + +/* Append a chain of `struct file_name_list's + to the end of the main include chain. + FIRST is the beginning of the chain to append, and LAST is the end. */ + +static void +append_include_chain (first, last) + struct file_name_list *first, *last; +{ + struct file_name_list *dir; + + if (!first || !last) + return; + + if (include == 0) + include = first; + else + last_include->next = first; + + if (first_bracket_include == 0) + first_bracket_include = first; + + for (dir = first; ; dir = dir->next) { + int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE; + if (len > max_include_len) + max_include_len = len; + if (dir == last) + break; + } + + last->next = NULL; + last_include = last; +} + +/* Add output to `deps_buffer' for the -M switch. + STRING points to the text to be output. + SPACER is ':' for targets, ' ' for dependencies. */ + +static void +deps_output (string, spacer) + char *string; + int spacer; +{ + int size = strlen (string); + + if (size == 0) + return; + +#ifndef MAX_OUTPUT_COLUMNS +#define MAX_OUTPUT_COLUMNS 72 +#endif + if (MAX_OUTPUT_COLUMNS - 1 /*spacer*/ - 2 /*` \'*/ < deps_column + size + && 1 < deps_column) { + bcopy (" \\\n ", &deps_buffer[deps_size], 4); + deps_size += 4; + deps_column = 1; + if (spacer == ' ') + spacer = 0; + } + + if (deps_size + size + 8 > deps_allocated_size) { + deps_allocated_size = (deps_size + size + 50) * 2; + deps_buffer = xrealloc (deps_buffer, deps_allocated_size); + } + if (spacer == ' ') { + deps_buffer[deps_size++] = ' '; + deps_column++; + } + bcopy (string, &deps_buffer[deps_size], size); + deps_size += size; + deps_column += size; + if (spacer == ':') { + deps_buffer[deps_size++] = ':'; + deps_column++; + } + deps_buffer[deps_size] = 0; +} + +static void +fatal (PRINTF_ALIST (msg)) + PRINTF_DCL (msg) +{ + va_list args; + + fprintf (stderr, "%s: ", progname); + VA_START (args, msg); + vfprintf (stderr, msg, args); + va_end (args); + fprintf (stderr, "\n"); + exit (FATAL_EXIT_CODE); +} + +/* More 'friendly' abort that prints the line and file. + config.h can #define abort fancy_abort if you like that sort of thing. */ + +void +fancy_abort () +{ + fatal ("Internal gcc abort."); +} + +static void +perror_with_name (name) + char *name; +{ + fprintf (stderr, "%s: ", progname); + fprintf (stderr, "%s: %s\n", name, my_strerror (errno)); + errors++; +} + +static void +pfatal_with_name (name) + char *name; +{ + perror_with_name (name); +#ifdef VMS + exit (vaxc$errno); +#else + exit (FATAL_EXIT_CODE); +#endif +} + +/* Handler for SIGPIPE. */ + +static void +pipe_closed (signo) + /* If this is missing, some compilers complain. */ + int signo; +{ + fatal ("output pipe has been closed"); +} + +static void +memory_full () +{ + fatal ("Memory exhausted."); +} + + +GENERIC_PTR +xmalloc (size) + size_t size; +{ + register GENERIC_PTR ptr = (GENERIC_PTR) malloc (size); + if (!ptr) + memory_full (); + return ptr; +} + +static GENERIC_PTR +xrealloc (old, size) + GENERIC_PTR old; + size_t size; +{ + register GENERIC_PTR ptr = (GENERIC_PTR) realloc (old, size); + if (!ptr) + memory_full (); + return ptr; +} + +static GENERIC_PTR +xcalloc (number, size) + size_t number, size; +{ + register size_t total = number * size; + register GENERIC_PTR ptr = (GENERIC_PTR) malloc (total); + if (!ptr) + memory_full (); + bzero (ptr, total); + return ptr; +} + +static char * +savestring (input) + char *input; +{ + size_t size = strlen (input); + char *output = xmalloc (size + 1); + strcpy (output, input); + return output; +} + +/* Get the file-mode and data size of the file open on FD + and store them in *MODE_POINTER and *SIZE_POINTER. */ + +static int +file_size_and_mode (fd, mode_pointer, size_pointer) + int fd; + int *mode_pointer; + long int *size_pointer; +{ + struct stat sbuf; + + if (fstat (fd, &sbuf) < 0) return (-1); + if (mode_pointer) *mode_pointer = sbuf.st_mode; + if (size_pointer) *size_pointer = sbuf.st_size; + return 0; +} + +#ifdef VMS + +/* Under VMS we need to fix up the "include" specification + filename so that everything following the 1st slash is + changed into its correct VMS file specification. */ + +static void +hack_vms_include_specification (fname) + char *fname; +{ + register char *cp, *cp1, *cp2; + int f, check_filename_before_returning, no_prefix_seen; + char Local[512]; + + check_filename_before_returning = 0; + no_prefix_seen = 0; + + /* Ignore leading "./"s */ + while (fname[0] == '.' && fname[1] == '/') { + strcpy (fname, fname+2); + no_prefix_seen = 1; /* mark this for later */ + } + /* Look for the boundary between the VMS and UNIX filespecs */ + cp = rindex (fname, ']'); /* Look for end of dirspec. */ + if (cp == 0) cp = rindex (fname, '>'); /* ... Ditto */ + if (cp == 0) cp = rindex (fname, ':'); /* Look for end of devspec. */ + if (cp) { + cp++; + } else { + cp = index (fname, '/'); /* Look for the "/" */ + } + + /* + * Check if we have a vax-c style '#include filename' + * and add the missing .h + */ + if (cp == 0) { + if (index(fname,'.') == 0) + strcat(fname, ".h"); + } else { + if (index(cp,'.') == 0) + strcat(cp, ".h"); + } + + cp2 = Local; /* initialize */ + + /* We are trying to do a number of things here. First of all, we are + trying to hammer the filenames into a standard format, such that later + processing can handle them. + + If the file name contains something like [dir.], then it recognizes this + as a root, and strips the ".]". Later processing will add whatever is + needed to get things working properly. + + If no device is specified, then the first directory name is taken to be + a device name (or a rooted logical). */ + + /* See if we found that 1st slash */ + if (cp == 0) return; /* Nothing to do!!! */ + if (*cp != '/') return; /* Nothing to do!!! */ + /* Point to the UNIX filename part (which needs to be fixed!) */ + cp1 = cp+1; + /* If the directory spec is not rooted, we can just copy + the UNIX filename part and we are done */ + if (((cp - fname) > 1) && ((cp[-1] == ']') || (cp[-1] == '>'))) { + if (cp[-2] != '.') { + /* + * The VMS part ends in a `]', and the preceding character is not a `.'. + * We strip the `]', and then splice the two parts of the name in the + * usual way. Given the default locations for include files in cccp.c, + * we will only use this code if the user specifies alternate locations + * with the /include (-I) switch on the command line. */ + cp -= 1; /* Strip "]" */ + cp1--; /* backspace */ + } else { + /* + * The VMS part has a ".]" at the end, and this will not do. Later + * processing will add a second directory spec, and this would be a syntax + * error. Thus we strip the ".]", and thus merge the directory specs. + * We also backspace cp1, so that it points to a '/'. This inhibits the + * generation of the 000000 root directory spec (which does not belong here + * in this case). + */ + cp -= 2; /* Strip ".]" */ + cp1--; }; /* backspace */ + } else { + + /* We drop in here if there is no VMS style directory specification yet. + * If there is no device specification either, we make the first dir a + * device and try that. If we do not do this, then we will be essentially + * searching the users default directory (as if they did a #include "asdf.h"). + * + * Then all we need to do is to push a '[' into the output string. Later + * processing will fill this in, and close the bracket. + */ + if (cp[-1] != ':') *cp2++ = ':'; /* dev not in spec. take first dir */ + *cp2++ = '['; /* Open the directory specification */ + } + + /* at this point we assume that we have the device spec, and (at least + the opening "[" for a directory specification. We may have directories + specified already */ + + /* If there are no other slashes then the filename will be + in the "root" directory. Otherwise, we need to add + directory specifications. */ + if (index (cp1, '/') == 0) { + /* Just add "000000]" as the directory string */ + strcpy (cp2, "000000]"); + cp2 += strlen (cp2); + check_filename_before_returning = 1; /* we might need to fool with this later */ + } else { + /* As long as there are still subdirectories to add, do them. */ + while (index (cp1, '/') != 0) { + /* If this token is "." we can ignore it */ + if ((cp1[0] == '.') && (cp1[1] == '/')) { + cp1 += 2; + continue; + } + /* Add a subdirectory spec. Do not duplicate "." */ + if (cp2[-1] != '.' && cp2[-1] != '[' && cp2[-1] != '<') + *cp2++ = '.'; + /* If this is ".." then the spec becomes "-" */ + if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) { + /* Add "-" and skip the ".." */ + *cp2++ = '-'; + cp1 += 3; + continue; + } + /* Copy the subdirectory */ + while (*cp1 != '/') *cp2++= *cp1++; + cp1++; /* Skip the "/" */ + } + /* Close the directory specification */ + if (cp2[-1] == '.') /* no trailing periods */ + cp2--; + *cp2++ = ']'; + } + /* Now add the filename */ + while (*cp1) *cp2++ = *cp1++; + *cp2 = 0; + /* Now append it to the original VMS spec. */ + strcpy (cp, Local); + + /* If we put a [000000] in the filename, try to open it first. If this fails, + remove the [000000], and return that name. This provides flexibility + to the user in that they can use both rooted and non-rooted logical names + to point to the location of the file. */ + + if (check_filename_before_returning && no_prefix_seen) { + f = open (fname, O_RDONLY, 0666); + if (f >= 0) { + /* The file name is OK as it is, so return it as is. */ + close (f); + return; + } + /* The filename did not work. Try to remove the [000000] from the name, + and return it. */ + cp = index (fname, '['); + cp2 = index (fname, ']') + 1; + strcpy (cp, cp2); /* this gets rid of it */ + } + return; +} +#endif /* VMS */ + +#ifdef VMS + +/* These are the read/write replacement routines for + VAX-11 "C". They make read/write behave enough + like their UNIX counterparts that CCCP will work */ + +static int +read (fd, buf, size) + int fd; + char *buf; + int size; +{ +#undef read /* Get back the REAL read routine */ + register int i; + register int total = 0; + + /* Read until the buffer is exhausted */ + while (size > 0) { + /* Limit each read to 32KB */ + i = (size > (32*1024)) ? (32*1024) : size; + i = read (fd, buf, i); + if (i <= 0) { + if (i == 0) return (total); + return (i); + } + /* Account for this read */ + total += i; + buf += i; + size -= i; + } + return (total); +} + +static int +write (fd, buf, size) + int fd; + char *buf; + int size; +{ +#undef write /* Get back the REAL write routine */ + int i; + int j; + + /* Limit individual writes to 32Kb */ + i = size; + while (i > 0) { + j = (i > (32*1024)) ? (32*1024) : i; + if (write (fd, buf, j) < 0) return (-1); + /* Account for the data written */ + buf += j; + i -= j; + } + return (size); +} + +/* The following wrapper functions supply additional arguments to the VMS + I/O routines to optimize performance with file handling. The arguments + are: + "mbc=16" - Set multi-block count to 16 (use a 8192 byte buffer). + "deq=64" - When extending the file, extend it in chunks of 32Kbytes. + "fop=tef"- Truncate unused portions of file when closing file. + "shr=nil"- Disallow file sharing while file is open. + */ + +static FILE * +freopen (fname, type, oldfile) + char *fname; + char *type; + FILE *oldfile; +{ +#undef freopen /* Get back the REAL fopen routine */ + if (strcmp (type, "w") == 0) + return freopen (fname, type, oldfile, "mbc=16", "deq=64", "fop=tef", "shr=nil"); + return freopen (fname, type, oldfile, "mbc=16"); +} + +static FILE * +fopen (fname, type) + char *fname; + char *type; +{ +#undef fopen /* Get back the REAL fopen routine */ + /* The gcc-vms-1.42 distribution's header files prototype fopen with two + fixed arguments, which matches ANSI's specification but not VAXCRTL's + pre-ANSI implementation. This hack circumvents the mismatch problem. */ + FILE *(*vmslib_fopen)() = (FILE *(*)()) fopen; + + if (*type == 'w') + return (*vmslib_fopen) (fname, type, "mbc=32", + "deq=64", "fop=tef", "shr=nil"); + else + return (*vmslib_fopen) (fname, type, "mbc=32"); +} + +static int +open (fname, flags, prot) + char *fname; + int flags; + int prot; +{ +#undef open /* Get back the REAL open routine */ + return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef"); +} + +/* Avoid run-time library bug, where copying M out of N+M characters with + N >= 65535 results in VAXCRTL's strncat falling into an infinite loop. + gcc-cpp exercises this particular bug. [Fixed in V5.5-2's VAXCRTL.] */ + +static char * +strncat (dst, src, cnt) + char *dst; + const char *src; + unsigned cnt; +{ + register char *d = dst, *s = (char *) src; + register int n = cnt; /* convert to _signed_ type */ + + while (*d) d++; /* advance to end */ + while (--n >= 0) + if (!(*d++ = *s++)) break; + if (n < 0) *d = '\0'; + return dst; +} + +/* more VMS hackery */ +#include +#include + +extern unsigned long sys$parse(), sys$search(); + +/* Work around another library bug. If a file is located via a searchlist, + and if the device it's on is not the same device as the one specified + in the first element of that searchlist, then both stat() and fstat() + will fail to return info about it. `errno' will be set to EVMSERR, and + `vaxc$errno' will be set to SS$_NORMAL due yet another bug in stat()! + We can get around this by fully parsing the filename and then passing + that absolute name to stat(). + + Without this fix, we can end up failing to find header files, which is + bad enough, but then compounding the problem by reporting the reason for + failure as "normal successful completion." */ + +#undef fstat /* get back to library version */ + +static int +VMS_fstat (fd, statbuf) + int fd; + struct stat *statbuf; +{ + int result = fstat (fd, statbuf); + + if (result < 0) + { + FILE *fp; + char nambuf[NAM$C_MAXRSS+1]; + + if ((fp = fdopen (fd, "r")) != 0 && fgetname (fp, nambuf) != 0) + result = VMS_stat (nambuf, statbuf); + /* No fclose(fp) here; that would close(fd) as well. */ + } + + return result; +} + +static int +VMS_stat (name, statbuf) + const char *name; + struct stat *statbuf; +{ + int result = stat (name, statbuf); + + if (result < 0) + { + struct FAB fab; + struct NAM nam; + char exp_nam[NAM$C_MAXRSS+1], /* expanded name buffer for sys$parse */ + res_nam[NAM$C_MAXRSS+1]; /* resultant name buffer for sys$search */ + + fab = cc$rms_fab; + fab.fab$l_fna = (char *) name; + fab.fab$b_fns = (unsigned char) strlen (name); + fab.fab$l_nam = (void *) &nam; + nam = cc$rms_nam; + nam.nam$l_esa = exp_nam, nam.nam$b_ess = sizeof exp_nam - 1; + nam.nam$l_rsa = res_nam, nam.nam$b_rss = sizeof res_nam - 1; + nam.nam$b_nop = NAM$M_PWD | NAM$M_NOCONCEAL; + if (sys$parse (&fab) & 1) + { + if (sys$search (&fab) & 1) + { + res_nam[nam.nam$b_rsl] = '\0'; + result = stat (res_nam, statbuf); + } + /* Clean up searchlist context cached by the system. */ + nam.nam$b_nop = NAM$M_SYNCHK; + fab.fab$l_fna = 0, fab.fab$b_fns = 0; + (void) sys$parse (&fab); + } + } + + return result; +} +#endif /* VMS */ diff --git a/contrib/gcc/cexp.y b/contrib/gcc/cexp.y new file mode 100644 index 00000000000..d83de803364 --- /dev/null +++ b/contrib/gcc/cexp.y @@ -0,0 +1,1047 @@ +/* Parse C expressions for CCCP. + Copyright (C) 1987, 1992, 1994, 1995 Free Software Foundation. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + + Adapted from expread.y of GDB by Paul Rubin, July 1986. */ + +/* Parse a C expression from text in a string */ + +%{ +#include "config.h" +#include +/* #define YYDEBUG 1 */ + +#ifdef MULTIBYTE_CHARS +#include +#include +#endif + +#include + +typedef unsigned char U_CHAR; + +/* This is used for communicating lists of keywords with cccp.c. */ +struct arglist { + struct arglist *next; + U_CHAR *name; + int length; + int argno; +}; + +/* Define a generic NULL if one hasn't already been defined. */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef GENERIC_PTR +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define GENERIC_PTR void * +#else +#define GENERIC_PTR char * +#endif +#endif + +/* Find the largest host integer type and set its size and type. */ + +#ifndef HOST_BITS_PER_WIDE_INT + +#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG +#define HOST_WIDE_INT long +#else +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT +#define HOST_WIDE_INT int +#endif + +#endif + +#ifndef NULL_PTR +#define NULL_PTR ((GENERIC_PTR)0) +#endif + +int yylex (); +void yyerror (); +HOST_WIDE_INT expression_value; + +static jmp_buf parse_return_error; + +/* Nonzero means count most punctuation as part of a name. */ +static int keyword_parsing = 0; + +/* Nonzero means do not evaluate this expression. + This is a count, since unevaluated expressions can nest. */ +static int skip_evaluation; + +/* some external tables of character types */ +extern unsigned char is_idstart[], is_idchar[], is_hor_space[]; + +extern char *xmalloc (); + +/* Flag for -pedantic. */ +extern int pedantic; + +/* Flag for -traditional. */ +extern int traditional; + +#ifndef CHAR_TYPE_SIZE +#define CHAR_TYPE_SIZE BITS_PER_UNIT +#endif + +#ifndef INT_TYPE_SIZE +#define INT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_TYPE_SIZE +#define LONG_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE INT_TYPE_SIZE +#endif + +#ifndef MAX_CHAR_TYPE_SIZE +#define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE +#endif + +#ifndef MAX_INT_TYPE_SIZE +#define MAX_INT_TYPE_SIZE INT_TYPE_SIZE +#endif + +#ifndef MAX_LONG_TYPE_SIZE +#define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE +#endif + +#ifndef MAX_WCHAR_TYPE_SIZE +#define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE +#endif + +/* Yield nonzero if adding two numbers with A's and B's signs can yield a + number with SUM's sign, where A, B, and SUM are all C integers. */ +#define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0) + +static void integer_overflow (); +static long left_shift (); +static long right_shift (); +%} + +%union { + struct constant {long value; int unsignedp;} integer; + struct name {U_CHAR *address; int length;} name; + struct arglist *keywords; +} + +%type exp exp1 start +%type keywords +%token INT CHAR +%token NAME +%token ERROR + +%right '?' ':' +%left ',' +%left OR +%left AND +%left '|' +%left '^' +%left '&' +%left EQUAL NOTEQUAL +%left '<' '>' LEQ GEQ +%left LSH RSH +%left '+' '-' +%left '*' '/' '%' +%right UNARY + +/* %expect 40 */ + +%% + +start : exp1 + { expression_value = $1.value; } + ; + +/* Expressions, including the comma operator. */ +exp1 : exp + | exp1 ',' exp + { if (pedantic) + pedwarn ("comma operator in operand of `#if'"); + $$ = $3; } + ; + +/* Expressions, not including the comma operator. */ +exp : '-' exp %prec UNARY + { $$.value = - $2.value; + if (($$.value & $2.value) < 0 && ! $2.unsignedp) + integer_overflow (); + $$.unsignedp = $2.unsignedp; } + | '!' exp %prec UNARY + { $$.value = ! $2.value; + $$.unsignedp = 0; } + | '+' exp %prec UNARY + { $$ = $2; } + | '~' exp %prec UNARY + { $$.value = ~ $2.value; + $$.unsignedp = $2.unsignedp; } + | '#' NAME + { $$.value = check_assertion ($2.address, $2.length, + 0, NULL_PTR); + $$.unsignedp = 0; } + | '#' NAME + { keyword_parsing = 1; } + '(' keywords ')' + { $$.value = check_assertion ($2.address, $2.length, + 1, $5); + keyword_parsing = 0; + $$.unsignedp = 0; } + | '(' exp1 ')' + { $$ = $2; } + ; + +/* Binary operators in order of decreasing precedence. */ +exp : exp '*' exp + { $$.unsignedp = $1.unsignedp || $3.unsignedp; + if ($$.unsignedp) + $$.value = (unsigned long) $1.value * $3.value; + else + { + $$.value = $1.value * $3.value; + if ($1.value + && ($$.value / $1.value != $3.value + || ($$.value & $1.value & $3.value) < 0)) + integer_overflow (); + } } + | exp '/' exp + { if ($3.value == 0) + { + if (!skip_evaluation) + error ("division by zero in #if"); + $3.value = 1; + } + $$.unsignedp = $1.unsignedp || $3.unsignedp; + if ($$.unsignedp) + $$.value = (unsigned long) $1.value / $3.value; + else + { + $$.value = $1.value / $3.value; + if (($$.value & $1.value & $3.value) < 0) + integer_overflow (); + } } + | exp '%' exp + { if ($3.value == 0) + { + if (!skip_evaluation) + error ("division by zero in #if"); + $3.value = 1; + } + $$.unsignedp = $1.unsignedp || $3.unsignedp; + if ($$.unsignedp) + $$.value = (unsigned long) $1.value % $3.value; + else + $$.value = $1.value % $3.value; } + | exp '+' exp + { $$.value = $1.value + $3.value; + $$.unsignedp = $1.unsignedp || $3.unsignedp; + if (! $$.unsignedp + && ! possible_sum_sign ($1.value, $3.value, + $$.value)) + integer_overflow (); } + | exp '-' exp + { $$.value = $1.value - $3.value; + $$.unsignedp = $1.unsignedp || $3.unsignedp; + if (! $$.unsignedp + && ! possible_sum_sign ($$.value, $3.value, + $1.value)) + integer_overflow (); } + | exp LSH exp + { $$.unsignedp = $1.unsignedp; + if ($3.value < 0 && ! $3.unsignedp) + $$.value = right_shift (&$1, -$3.value); + else + $$.value = left_shift (&$1, $3.value); } + | exp RSH exp + { $$.unsignedp = $1.unsignedp; + if ($3.value < 0 && ! $3.unsignedp) + $$.value = left_shift (&$1, -$3.value); + else + $$.value = right_shift (&$1, $3.value); } + | exp EQUAL exp + { $$.value = ($1.value == $3.value); + $$.unsignedp = 0; } + | exp NOTEQUAL exp + { $$.value = ($1.value != $3.value); + $$.unsignedp = 0; } + | exp LEQ exp + { $$.unsignedp = 0; + if ($1.unsignedp || $3.unsignedp) + $$.value = (unsigned long) $1.value <= $3.value; + else + $$.value = $1.value <= $3.value; } + | exp GEQ exp + { $$.unsignedp = 0; + if ($1.unsignedp || $3.unsignedp) + $$.value = (unsigned long) $1.value >= $3.value; + else + $$.value = $1.value >= $3.value; } + | exp '<' exp + { $$.unsignedp = 0; + if ($1.unsignedp || $3.unsignedp) + $$.value = (unsigned long) $1.value < $3.value; + else + $$.value = $1.value < $3.value; } + | exp '>' exp + { $$.unsignedp = 0; + if ($1.unsignedp || $3.unsignedp) + $$.value = (unsigned long) $1.value > $3.value; + else + $$.value = $1.value > $3.value; } + | exp '&' exp + { $$.value = $1.value & $3.value; + $$.unsignedp = $1.unsignedp || $3.unsignedp; } + | exp '^' exp + { $$.value = $1.value ^ $3.value; + $$.unsignedp = $1.unsignedp || $3.unsignedp; } + | exp '|' exp + { $$.value = $1.value | $3.value; + $$.unsignedp = $1.unsignedp || $3.unsignedp; } + | exp AND + { skip_evaluation += !$1.value; } + exp + { skip_evaluation -= !$1.value; + $$.value = ($1.value && $4.value); + $$.unsignedp = 0; } + | exp OR + { skip_evaluation += !!$1.value; } + exp + { skip_evaluation -= !!$1.value; + $$.value = ($1.value || $4.value); + $$.unsignedp = 0; } + | exp '?' + { skip_evaluation += !$1.value; } + exp ':' + { skip_evaluation += !!$1.value - !$1.value; } + exp + { skip_evaluation -= !!$1.value; + $$.value = $1.value ? $4.value : $7.value; + $$.unsignedp = $4.unsignedp || $7.unsignedp; } + | INT + { $$ = yylval.integer; } + | CHAR + { $$ = yylval.integer; } + | NAME + { $$.value = 0; + $$.unsignedp = 0; } + ; + +keywords : + { $$ = 0; } + | '(' keywords ')' keywords + { struct arglist *temp; + $$ = (struct arglist *) xmalloc (sizeof (struct arglist)); + $$->next = $2; + $$->name = (U_CHAR *) "("; + $$->length = 1; + temp = $$; + while (temp != 0 && temp->next != 0) + temp = temp->next; + temp->next = (struct arglist *) xmalloc (sizeof (struct arglist)); + temp->next->next = $4; + temp->next->name = (U_CHAR *) ")"; + temp->next->length = 1; } + | NAME keywords + { $$ = (struct arglist *) xmalloc (sizeof (struct arglist)); + $$->name = $1.address; + $$->length = $1.length; + $$->next = $2; } + ; +%% + +/* During parsing of a C expression, the pointer to the next character + is in this variable. */ + +static char *lexptr; + +/* Take care of parsing a number (anything that starts with a digit). + Set yylval and return the token type; update lexptr. + LEN is the number of characters in it. */ + +/* maybe needs to actually deal with floating point numbers */ + +int +parse_number (olen) + int olen; +{ + register char *p = lexptr; + register int c; + register unsigned long n = 0, nd, ULONG_MAX_over_base; + register int base = 10; + register int len = olen; + register int overflow = 0; + register int digit, largest_digit = 0; + int spec_long = 0; + + for (c = 0; c < len; c++) + if (p[c] == '.') { + /* It's a float since it contains a point. */ + yyerror ("floating point numbers not allowed in #if expressions"); + return ERROR; + } + + yylval.integer.unsignedp = 0; + + if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) { + p += 2; + base = 16; + len -= 2; + } + else if (*p == '0') + base = 8; + + ULONG_MAX_over_base = (unsigned long) -1 / base; + + for (; len > 0; len--) { + c = *p++; + + if (c >= '0' && c <= '9') + digit = c - '0'; + else if (base == 16 && c >= 'a' && c <= 'f') + digit = c - 'a' + 10; + else if (base == 16 && c >= 'A' && c <= 'F') + digit = c - 'A' + 10; + else { + /* `l' means long, and `u' means unsigned. */ + while (1) { + if (c == 'l' || c == 'L') + { + if (spec_long) + yyerror ("two `l's in integer constant"); + spec_long = 1; + } + else if (c == 'u' || c == 'U') + { + if (yylval.integer.unsignedp) + yyerror ("two `u's in integer constant"); + yylval.integer.unsignedp = 1; + } + else + break; + + if (--len == 0) + break; + c = *p++; + } + /* Don't look for any more digits after the suffixes. */ + break; + } + if (largest_digit < digit) + largest_digit = digit; + nd = n * base + digit; + overflow |= ULONG_MAX_over_base < n | nd < n; + n = nd; + } + + if (len != 0) { + yyerror ("Invalid number in #if expression"); + return ERROR; + } + + if (base <= largest_digit) + warning ("integer constant contains digits beyond the radix"); + + if (overflow) + warning ("integer constant out of range"); + + /* If too big to be signed, consider it unsigned. */ + if ((long) n < 0 && ! yylval.integer.unsignedp) + { + if (base == 10) + warning ("integer constant is so large that it is unsigned"); + yylval.integer.unsignedp = 1; + } + + lexptr = p; + yylval.integer.value = n; + return INT; +} + +struct token { + char *operator; + int token; +}; + +static struct token tokentab2[] = { + {"&&", AND}, + {"||", OR}, + {"<<", LSH}, + {">>", RSH}, + {"==", EQUAL}, + {"!=", NOTEQUAL}, + {"<=", LEQ}, + {">=", GEQ}, + {"++", ERROR}, + {"--", ERROR}, + {NULL, ERROR} +}; + +/* Read one token, getting characters through lexptr. */ + +int +yylex () +{ + register int c; + register int namelen; + register unsigned char *tokstart; + register struct token *toktab; + int wide_flag; + + retry: + + tokstart = (unsigned char *) lexptr; + c = *tokstart; + /* See if it is a special token of length 2. */ + if (! keyword_parsing) + for (toktab = tokentab2; toktab->operator != NULL; toktab++) + if (c == *toktab->operator && tokstart[1] == toktab->operator[1]) { + lexptr += 2; + if (toktab->token == ERROR) + { + char *buf = (char *) alloca (40); + sprintf (buf, "`%s' not allowed in operand of `#if'", toktab->operator); + yyerror (buf); + } + return toktab->token; + } + + switch (c) { + case 0: + return 0; + + case ' ': + case '\t': + case '\r': + case '\n': + lexptr++; + goto retry; + + case 'L': + /* Capital L may start a wide-string or wide-character constant. */ + if (lexptr[1] == '\'') + { + lexptr++; + wide_flag = 1; + goto char_constant; + } + if (lexptr[1] == '"') + { + lexptr++; + wide_flag = 1; + goto string_constant; + } + break; + + case '\'': + wide_flag = 0; + char_constant: + lexptr++; + if (keyword_parsing) { + char *start_ptr = lexptr - 1; + while (1) { + c = *lexptr++; + if (c == '\\') + c = parse_escape (&lexptr); + else if (c == '\'') + break; + } + yylval.name.address = tokstart; + yylval.name.length = lexptr - start_ptr; + return NAME; + } + + /* This code for reading a character constant + handles multicharacter constants and wide characters. + It is mostly copied from c-lex.c. */ + { + register int result = 0; + register num_chars = 0; + unsigned width = MAX_CHAR_TYPE_SIZE; + int max_chars; + char *token_buffer; + + if (wide_flag) + { + width = MAX_WCHAR_TYPE_SIZE; +#ifdef MULTIBYTE_CHARS + max_chars = MB_CUR_MAX; +#else + max_chars = 1; +#endif + } + else + max_chars = MAX_LONG_TYPE_SIZE / width; + + token_buffer = (char *) alloca (max_chars + 1); + + while (1) + { + c = *lexptr++; + + if (c == '\'' || c == EOF) + break; + + if (c == '\\') + { + c = parse_escape (&lexptr); + if (width < HOST_BITS_PER_INT + && (unsigned) c >= (1 << width)) + pedwarn ("escape sequence out of range for character"); + } + + num_chars++; + + /* Merge character into result; ignore excess chars. */ + if (num_chars < max_chars + 1) + { + if (width < HOST_BITS_PER_INT) + result = (result << width) | (c & ((1 << width) - 1)); + else + result = c; + token_buffer[num_chars - 1] = c; + } + } + + token_buffer[num_chars] = 0; + + if (c != '\'') + error ("malformatted character constant"); + else if (num_chars == 0) + error ("empty character constant"); + else if (num_chars > max_chars) + { + num_chars = max_chars; + error ("character constant too long"); + } + else if (num_chars != 1 && ! traditional) + warning ("multi-character character constant"); + + /* If char type is signed, sign-extend the constant. */ + if (! wide_flag) + { + int num_bits = num_chars * width; + + if (lookup ("__CHAR_UNSIGNED__", sizeof ("__CHAR_UNSIGNED__")-1, -1) + || ((result >> (num_bits - 1)) & 1) == 0) + yylval.integer.value + = result & ((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits)); + else + yylval.integer.value + = result | ~((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits)); + } + else + { +#ifdef MULTIBYTE_CHARS + /* Set the initial shift state and convert the next sequence. */ + result = 0; + /* In all locales L'\0' is zero and mbtowc will return zero, + so don't use it. */ + if (num_chars > 1 + || (num_chars == 1 && token_buffer[0] != '\0')) + { + wchar_t wc; + (void) mbtowc (NULL_PTR, NULL_PTR, 0); + if (mbtowc (& wc, token_buffer, num_chars) == num_chars) + result = wc; + else + warning ("Ignoring invalid multibyte character"); + } +#endif + yylval.integer.value = result; + } + } + + /* This is always a signed type. */ + yylval.integer.unsignedp = 0; + + return CHAR; + + /* some of these chars are invalid in constant expressions; + maybe do something about them later */ + case '/': + case '+': + case '-': + case '*': + case '%': + case '|': + case '&': + case '^': + case '~': + case '!': + case '@': + case '<': + case '>': + case '[': + case ']': + case '.': + case '?': + case ':': + case '=': + case '{': + case '}': + case ',': + case '#': + if (keyword_parsing) + break; + case '(': + case ')': + lexptr++; + return c; + + case '"': + string_constant: + if (keyword_parsing) { + char *start_ptr = lexptr; + lexptr++; + while (1) { + c = *lexptr++; + if (c == '\\') + c = parse_escape (&lexptr); + else if (c == '"') + break; + } + yylval.name.address = tokstart; + yylval.name.length = lexptr - start_ptr; + return NAME; + } + yyerror ("string constants not allowed in #if expressions"); + return ERROR; + } + + if (c >= '0' && c <= '9' && !keyword_parsing) { + /* It's a number */ + for (namelen = 0; + c = tokstart[namelen], is_idchar[c] || c == '.'; + namelen++) + ; + return parse_number (namelen); + } + + /* It is a name. See how long it is. */ + + if (keyword_parsing) { + for (namelen = 0;; namelen++) { + if (is_hor_space[tokstart[namelen]]) + break; + if (tokstart[namelen] == '(' || tokstart[namelen] == ')') + break; + if (tokstart[namelen] == '"' || tokstart[namelen] == '\'') + break; + } + } else { + if (!is_idstart[c]) { + yyerror ("Invalid token in expression"); + return ERROR; + } + + for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++) + ; + } + + lexptr += namelen; + yylval.name.address = tokstart; + yylval.name.length = namelen; + return NAME; +} + + +/* Parse a C escape sequence. STRING_PTR points to a variable + containing a pointer to the string to parse. That pointer + is updated past the characters we use. The value of the + escape sequence is returned. + + A negative value means the sequence \ newline was seen, + which is supposed to be equivalent to nothing at all. + + If \ is followed by a null character, we return a negative + value and leave the string pointer pointing at the null character. + + If \ is followed by 000, we return 0 and leave the string pointer + after the zeros. A value of 0 does not mean end of string. */ + +int +parse_escape (string_ptr) + char **string_ptr; +{ + register int c = *(*string_ptr)++; + switch (c) + { + case 'a': + return TARGET_BELL; + case 'b': + return TARGET_BS; + case 'e': + case 'E': + if (pedantic) + pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); + return 033; + case 'f': + return TARGET_FF; + case 'n': + return TARGET_NEWLINE; + case 'r': + return TARGET_CR; + case 't': + return TARGET_TAB; + case 'v': + return TARGET_VT; + case '\n': + return -2; + case 0: + (*string_ptr)--; + return 0; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + { + register int i = c - '0'; + register int count = 0; + while (++count < 3) + { + c = *(*string_ptr)++; + if (c >= '0' && c <= '7') + i = (i << 3) + c - '0'; + else + { + (*string_ptr)--; + break; + } + } + if ((i & ~((1 << MAX_CHAR_TYPE_SIZE) - 1)) != 0) + { + i &= (1 << MAX_CHAR_TYPE_SIZE) - 1; + warning ("octal character constant does not fit in a byte"); + } + return i; + } + case 'x': + { + register unsigned i = 0, overflow = 0, digits_found = 0, digit; + for (;;) + { + c = *(*string_ptr)++; + if (c >= '0' && c <= '9') + digit = c - '0'; + else if (c >= 'a' && c <= 'f') + digit = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + digit = c - 'A' + 10; + else + { + (*string_ptr)--; + break; + } + overflow |= i ^ (i << 4 >> 4); + i = (i << 4) + digit; + digits_found = 1; + } + if (!digits_found) + yyerror ("\\x used with no following hex digits"); + if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1))) + { + i &= (1 << BITS_PER_UNIT) - 1; + warning ("hex character constant does not fit in a byte"); + } + return i; + } + default: + return c; + } +} + +void +yyerror (s) + char *s; +{ + error (s); + skip_evaluation = 0; + longjmp (parse_return_error, 1); +} + +static void +integer_overflow () +{ + if (!skip_evaluation && pedantic) + pedwarn ("integer overflow in preprocessor expression"); +} + +static long +left_shift (a, b) + struct constant *a; + unsigned long b; +{ + /* It's unclear from the C standard whether shifts can overflow. + The following code ignores overflow; perhaps a C standard + interpretation ruling is needed. */ + if (b >= HOST_BITS_PER_LONG) + return 0; + else if (a->unsignedp) + return (unsigned long) a->value << b; + else + return a->value << b; +} + +static long +right_shift (a, b) + struct constant *a; + unsigned long b; +{ + if (b >= HOST_BITS_PER_LONG) + return a->unsignedp ? 0 : a->value >> (HOST_BITS_PER_LONG - 1); + else if (a->unsignedp) + return (unsigned long) a->value >> b; + else + return a->value >> b; +} + +/* This page contains the entry point to this file. */ + +/* Parse STRING as an expression, and complain if this fails + to use up all of the contents of STRING. */ +/* We do not support C comments. They should be removed before + this function is called. */ + +HOST_WIDE_INT +parse_c_expression (string) + char *string; +{ + lexptr = string; + + if (lexptr == 0 || *lexptr == 0) { + error ("empty #if expression"); + return 0; /* don't include the #if group */ + } + + /* if there is some sort of scanning error, just return 0 and assume + the parsing routine has printed an error message somewhere. + there is surely a better thing to do than this. */ + if (setjmp (parse_return_error)) + return 0; + + if (yyparse ()) + return 0; /* actually this is never reached + the way things stand. */ + if (*lexptr) + error ("Junk after end of expression."); + + return expression_value; /* set by yyparse () */ +} + +#ifdef TEST_EXP_READER +extern int yydebug; + +/* Main program for testing purposes. */ +int +main () +{ + int n, c; + char buf[1024]; + +/* + yydebug = 1; +*/ + initialize_random_junk (); + + for (;;) { + printf ("enter expression: "); + n = 0; + while ((buf[n] = getchar ()) != '\n' && buf[n] != EOF) + n++; + if (buf[n] == EOF) + break; + buf[n] = '\0'; + printf ("parser returned %ld\n", parse_c_expression (buf)); + } + + return 0; +} + +/* table to tell if char can be part of a C identifier. */ +unsigned char is_idchar[256]; +/* table to tell if char can be first char of a c identifier. */ +unsigned char is_idstart[256]; +/* table to tell if c is horizontal space. isspace () thinks that + newline is space; this is not a good idea for this program. */ +char is_hor_space[256]; + +/* + * initialize random junk in the hash table and maybe other places + */ +initialize_random_junk () +{ + register int i; + + /* + * Set up is_idchar and is_idstart tables. These should be + * faster than saying (is_alpha (c) || c == '_'), etc. + * Must do set up these things before calling any routines tthat + * refer to them. + */ + for (i = 'a'; i <= 'z'; i++) { + ++is_idchar[i - 'a' + 'A']; + ++is_idchar[i]; + ++is_idstart[i - 'a' + 'A']; + ++is_idstart[i]; + } + for (i = '0'; i <= '9'; i++) + ++is_idchar[i]; + ++is_idchar['_']; + ++is_idstart['_']; +#if DOLLARS_IN_IDENTIFIERS + ++is_idchar['$']; + ++is_idstart['$']; +#endif + + /* horizontal space table */ + ++is_hor_space[' ']; + ++is_hor_space['\t']; +} + +error (msg) +{ + printf ("error: %s\n", msg); +} + +warning (msg) +{ + printf ("warning: %s\n", msg); +} + +struct hashnode * +lookup (name, len, hash) + char *name; + int len; + int hash; +{ + return (DEFAULT_SIGNED_CHAR) ? 0 : ((struct hashnode *) -1); +} +#endif diff --git a/contrib/gcc/collect2.c b/contrib/gcc/collect2.c new file mode 100644 index 00000000000..a74a7f06992 --- /dev/null +++ b/contrib/gcc/collect2.c @@ -0,0 +1,3409 @@ +/* Collect static initialization info into data structures + that can be traversed by C++ initialization and finalization + routines. + + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Chris Smith (csmith@convex.com). + Heavily modified by Michael Meissner (meissner@cygnus.com), + Per Bothner (bothner@cygnus.com), and John Gilmore (gnu@cygnus.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Build tables of static constructors and destructors and run ld. */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#ifdef NO_WAIT_H +#include +#endif + +#define COLLECT + +#include "demangle.h" +#include "obstack.h" + +#ifndef errno +extern int errno; +#endif + +#ifndef HAVE_STRERROR +#if defined(bsd4_4) +extern const char *const sys_errlist[]; +#else +extern char *sys_errlist[]; +#endif +extern int sys_nerr; +#else +char *strerror(); +#endif + +/* Obstack allocation and deallocation routines. */ +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +#if !defined (__STDC__) && !defined (const) +#define const +#endif + +#ifdef USG +#define vfork fork +#endif + +/* Add prototype support. */ +#ifndef PROTO +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define PROTO(ARGS) ARGS +#else +#define PROTO(ARGS) () +#endif +#endif + +#ifndef R_OK +#define R_OK 4 +#define W_OK 2 +#define X_OK 1 +#endif + +#ifndef WIFSIGNALED +#define WIFSIGNALED(S) (((S) & 0xff) != 0 && ((S) & 0xff) != 0x7f) +#endif +#ifndef WTERMSIG +#define WTERMSIG(S) ((S) & 0x7f) +#endif +#ifndef WIFEXITED +#define WIFEXITED(S) (((S) & 0xff) == 0) +#endif +#ifndef WEXITSTATUS +#define WEXITSTATUS(S) (((S) & 0xff00) >> 8) +#endif + +/* On MSDOS, write temp files in current dir + because there's no place else we can expect to use. */ +#ifdef __MSDOS__ +#ifndef P_tmpdir +#define P_tmpdir "./" +#endif +#endif + +/* On certain systems, we have code that works by scanning the object file + directly. But this code uses system-specific header files and library + functions, so turn it off in a cross-compiler. Likewise, the names of + the utilities aren't correct for a cross-compiler; we have to hope that + cross-versions are in the proper directories. */ + +#ifdef CROSS_COMPILE +#undef SUNOS4_SHARED_LIBRARIES +#undef OBJECT_FORMAT_COFF +#undef OBJECT_FORMAT_ROSE +#undef MD_EXEC_PREFIX +#undef REAL_LD_FILE_NAME +#undef REAL_NM_FILE_NAME +#undef REAL_STRIP_FILE_NAME +#endif + +/* If we can't use a special method, use the ordinary one: + run nm to find what symbols are present. + In a cross-compiler, this means you need a cross nm, + but that isn't quite as unpleasant as special headers. */ + +#if !defined (OBJECT_FORMAT_COFF) && !defined (OBJECT_FORMAT_ROSE) +#define OBJECT_FORMAT_NONE +#endif + +#ifdef OBJECT_FORMAT_COFF + +#include +#include + +#ifdef UMAX +#include +#endif + +/* Many versions of ldfcn.h define these. */ +#ifdef FREAD +#undef FREAD +#undef FWRITE +#endif + +#include + +/* Some systems have an ISCOFF macro, but others do not. In some cases + the macro may be wrong. MY_ISCOFF is defined in tm.h files for machines + that either do not have an ISCOFF macro in /usr/include or for those + where it is wrong. */ + +#ifndef MY_ISCOFF +#define MY_ISCOFF(X) ISCOFF (X) +#endif + +#ifdef XCOFF_DEBUGGING_INFO +#define XCOFF_SCAN_LIBS +#endif + +#endif /* OBJECT_FORMAT_COFF */ + +#ifdef OBJECT_FORMAT_ROSE + +#ifdef _OSF_SOURCE +#define USE_MMAP +#endif + +#ifdef USE_MMAP +#include +#endif + +#include +#include +#include +#include +#include + +#endif /* OBJECT_FORMAT_ROSE */ + +#ifdef OBJECT_FORMAT_NONE + +/* Default flags to pass to nm. */ +#ifndef NM_FLAGS +#define NM_FLAGS "-p" +#endif + +#endif /* OBJECT_FORMAT_NONE */ + +/* Some systems use __main in a way incompatible with its use in gcc, in these + cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to + give the same symbol without quotes for an alternative entry point. You + must define both, or neither. */ +#ifndef NAME__MAIN +#define NAME__MAIN "__main" +#define SYMBOL__MAIN __main +#endif + +#if defined (LDD_SUFFIX) || SUNOS4_SHARED_LIBRARIES || defined(XCOFF_SCAN_LIBS) +#define SCAN_LIBRARIES +#endif + +#ifdef USE_COLLECT2 +int do_collecting = 1; +#else +int do_collecting = 0; +#endif + +/* Linked lists of constructor and destructor names. */ + +struct id +{ + struct id *next; + int sequence; + char name[1]; +}; + +struct head +{ + struct id *first; + struct id *last; + int number; +}; + +/* Enumeration giving which pass this is for scanning the program file. */ + +enum pass { + PASS_FIRST, /* without constructors */ + PASS_OBJ, /* individual objects */ + PASS_LIB, /* looking for shared libraries */ + PASS_SECOND /* with constructors linked in */ +}; + +#ifndef NO_SYS_SIGLIST +#ifndef DONT_DECLARE_SYS_SIGLIST +extern char *sys_siglist[]; +#endif +#endif +extern char *version_string; + +int vflag; /* true if -v */ +static int rflag; /* true if -r */ +static int strip_flag; /* true if -s */ + +int debug; /* true if -debug */ + +static int shared_obj; /* true if -shared */ + +static int temp_filename_length; /* Length of temp_filename */ +static char *temp_filename; /* Base of temp filenames */ +static char *c_file; /* .c for constructor/destructor list. */ +static char *o_file; /* .o for constructor/destructor list. */ +static char *export_file; /* .x for AIX export list. */ +static int auto_export = 1; /* true if exporting everything. */ +char *ldout; /* File for ld errors. */ +static char *output_file; /* Output file for ld. */ +static char *nm_file_name; /* pathname of nm */ +static char *ldd_file_name; /* pathname of ldd (or equivalent) */ +static char *strip_file_name; /* pathname of strip */ +char *c_file_name; /* pathname of gcc */ +static char *initname, *fininame; /* names of init and fini funcs */ + +static struct head constructors; /* list of constructors found */ +static struct head destructors; /* list of destructors found */ +static struct head exports; /* list of exported symbols */ + +struct obstack temporary_obstack; +struct obstack permanent_obstack; +char * temporary_firstobj; + +/* Defined in the automatically-generated underscore.c. */ +extern int prepends_underscore; + +extern char *getenv (); +extern char *mktemp (); +extern FILE *fdopen (); + +/* Structure to hold all the directories in which to search for files to + execute. */ + +struct prefix_list +{ + char *prefix; /* String to prepend to the path. */ + struct prefix_list *next; /* Next in linked list. */ +}; + +struct path_prefix +{ + struct prefix_list *plist; /* List of prefixes to try */ + int max_len; /* Max length of a prefix in PLIST */ + char *name; /* Name of this list (used in config stuff) */ +}; + +void collect_exit PROTO((int)); +void collect_execute PROTO((char *, char **, char *)); +void dump_file PROTO((char *)); +static void handler PROTO((int)); +static int is_ctor_dtor PROTO((char *)); +static void choose_temp_base PROTO((void)); +static int is_in_prefix_list PROTO((struct path_prefix *, char *, int)); +static char *find_a_file PROTO((struct path_prefix *, char *)); +static void add_prefix PROTO((struct path_prefix *, char *)); +static void prefix_from_env PROTO((char *, struct path_prefix *)); +static void prefix_from_string PROTO((char *, struct path_prefix *)); +static void do_wait PROTO((char *)); +static void fork_execute PROTO((char *, char **)); +static void maybe_unlink PROTO((char *)); +static void add_to_list PROTO((struct head *, char *)); +static void write_list PROTO((FILE *, char *, struct id *)); +static void write_list_with_asm PROTO((FILE *, char *, struct id *)); +static void write_c_file PROTO((FILE *, char *)); +static void write_export_file PROTO((FILE *)); +static void scan_prog_file PROTO((char *, enum pass)); +static void scan_libraries PROTO((char *)); + +char *xcalloc (); +char *xmalloc (); + +extern char *index (); +extern char *rindex (); +extern void free (); + +#ifdef NO_DUP2 +int +dup2 (oldfd, newfd) + int oldfd; + int newfd; +{ + int fdtmp[256]; + int fdx = 0; + int fd; + + if (oldfd == newfd) + return oldfd; + close (newfd); + while ((fd = dup (oldfd)) != newfd && fd >= 0) /* good enough for low fd's */ + fdtmp[fdx++] = fd; + while (fdx > 0) + close (fdtmp[--fdx]); + + return fd; +} +#endif + +char * +my_strerror (e) + int e; +{ + +#ifdef HAVE_STRERROR + return strerror (e); + +#else + + static char buffer[30]; + if (!e) + return ""; + + if (e > 0 && e < sys_nerr) + return sys_errlist[e]; + + sprintf (buffer, "Unknown error %d", e); + return buffer; +#endif +} + +/* Delete tempfiles and exit function. */ + +void +collect_exit (status) + int status; +{ + if (c_file != 0 && c_file[0]) + maybe_unlink (c_file); + + if (o_file != 0 && o_file[0]) + maybe_unlink (o_file); + + if (export_file != 0 && export_file[0]) + maybe_unlink (export_file); + + if (ldout != 0 && ldout[0]) + { + dump_file (ldout); + maybe_unlink (ldout); + } + + if (status != 0 && output_file != 0 && output_file[0]) + maybe_unlink (output_file); + + exit (status); +} + + +/* Die when sys call fails. */ + +void +fatal_perror (string, arg1, arg2, arg3) + char *string, *arg1, *arg2, *arg3; +{ + int e = errno; + + fprintf (stderr, "collect2: "); + fprintf (stderr, string, arg1, arg2, arg3); + fprintf (stderr, ": %s\n", my_strerror (e)); + collect_exit (1); +} + +/* Just die. */ + +void +fatal (string, arg1, arg2, arg3) + char *string, *arg1, *arg2, *arg3; +{ + fprintf (stderr, "collect2: "); + fprintf (stderr, string, arg1, arg2, arg3); + fprintf (stderr, "\n"); + collect_exit (1); +} + +/* Write error message. */ + +void +error (string, arg1, arg2, arg3, arg4) + char *string, *arg1, *arg2, *arg3, *arg4; +{ + fprintf (stderr, "collect2: "); + fprintf (stderr, string, arg1, arg2, arg3, arg4); + fprintf (stderr, "\n"); +} + +/* In case obstack is linked in, and abort is defined to fancy_abort, + provide a default entry. */ + +void +fancy_abort () +{ + fatal ("internal error"); +} + + +static void +handler (signo) + int signo; +{ + if (c_file != 0 && c_file[0]) + maybe_unlink (c_file); + + if (o_file != 0 && o_file[0]) + maybe_unlink (o_file); + + if (ldout != 0 && ldout[0]) + maybe_unlink (ldout); + + signal (signo, SIG_DFL); + kill (getpid (), signo); +} + + +char * +xcalloc (size1, size2) + int size1, size2; +{ + char *ptr = (char *) calloc (size1, size2); + if (ptr) + return ptr; + + fatal ("out of memory"); + return (char *)0; +} + +char * +xmalloc (size) + unsigned size; +{ + char *ptr = (char *) malloc (size); + if (ptr) + return ptr; + + fatal ("out of memory"); + return (char *)0; +} + +char * +xrealloc (ptr, size) + char *ptr; + unsigned size; +{ + register char *value = (char *) realloc (ptr, size); + if (value == 0) + fatal ("virtual memory exhausted"); + return value; +} + +int +file_exists (name) + char *name; +{ + return access (name, R_OK) == 0; +} + +/* Make a copy of a string INPUT with size SIZE. */ + +char * +savestring (input, size) + char *input; + int size; +{ + char *output = (char *) xmalloc (size + 1); + bcopy (input, output, size); + output[size] = 0; + return output; +} + +void +dump_file (name) + char *name; +{ + FILE *stream = fopen (name, "r"); + int no_demangle = !! getenv ("COLLECT_NO_DEMANGLE"); + + if (stream == 0) + return; + while (1) + { + int c; + while (c = getc (stream), + c != EOF && (isalnum (c) || c == '_' || c == '$' || c == '.')) + obstack_1grow (&temporary_obstack, c); + if (obstack_object_size (&temporary_obstack) > 0) + { + char *word, *p, *result; + obstack_1grow (&temporary_obstack, '\0'); + word = obstack_finish (&temporary_obstack); + + if (*word == '.') + ++word, putc ('.', stderr); + p = word; + if (*p == '_' && prepends_underscore) + ++p; + + if (no_demangle) + result = 0; + else + result = cplus_demangle (p, DMGL_PARAMS | DMGL_ANSI); + + if (result) + { + int diff; + fputs (result, stderr); + + diff = strlen (word) - strlen (result); + while (diff > 0) + --diff, putc (' ', stderr); + while (diff < 0 && c == ' ') + ++diff, c = getc (stream); + + free (result); + } + else + fputs (word, stderr); + + fflush (stderr); + obstack_free (&temporary_obstack, temporary_firstobj); + } + if (c == EOF) + break; + putc (c, stderr); + } +} + +/* Decide whether the given symbol is: + a constructor (1), a destructor (2), or neither (0). */ + +static int +is_ctor_dtor (s) + char *s; +{ + struct names { char *name; int len; int ret; int two_underscores; }; + + register struct names *p; + register int ch; + register char *orig_s = s; + + static struct names special[] = { +#ifdef NO_DOLLAR_IN_LABEL +#ifdef NO_DOT_IN_LABEL + { "GLOBAL__I_", sizeof ("GLOBAL__I_")-1, 1, 0 }, + { "GLOBAL__D_", sizeof ("GLOBAL__D_")-1, 2, 0 }, +#else + { "GLOBAL_.I.", sizeof ("GLOBAL_.I.")-1, 1, 0 }, + { "GLOBAL_.D.", sizeof ("GLOBAL_.D.")-1, 2, 0 }, +#endif +#else + { "GLOBAL_$I$", sizeof ("GLOBAL_$I$")-1, 1, 0 }, + { "GLOBAL_$D$", sizeof ("GLOBAL_$D$")-1, 2, 0 }, +#endif + { "GLOBAL__FI_", sizeof ("GLOBAL__FI_")-1, 3, 0 }, + { "GLOBAL__FD_", sizeof ("GLOBAL__FD_")-1, 4, 0 }, +#ifdef CFRONT_LOSSAGE /* Don't collect cfront initialization functions. + cfront has its own linker procedure to collect them; + if collect2 gets them too, they get collected twice + when the cfront procedure is run and the compiler used + for linking happens to be GCC. */ + { "sti__", sizeof ("sti__")-1, 1, 1 }, + { "std__", sizeof ("std__")-1, 2, 1 }, +#endif /* CFRONT_LOSSAGE */ + { NULL, 0, 0, 0 } + }; + + while ((ch = *s) == '_') + ++s; + + if (s == orig_s) + return 0; + + for (p = &special[0]; p->len > 0; p++) + { + if (ch == p->name[0] + && (!p->two_underscores || ((s - orig_s) >= 2)) + && strncmp(s, p->name, p->len) == 0) + { + return p->ret; + } + } + return 0; +} + + +/* Compute a string to use as the base of all temporary file names. + It is substituted for %g. */ + +static void +choose_temp_base () +{ + char *base = getenv ("TMPDIR"); + int len; + + if (base == (char *)0) + { +#ifdef P_tmpdir + if (access (P_tmpdir, R_OK | W_OK) == 0) + base = P_tmpdir; +#endif + if (base == (char *)0) + { + if (access ("/usr/tmp", R_OK | W_OK) == 0) + base = "/usr/tmp/"; + else + base = "/tmp/"; + } + } + + len = strlen (base); + temp_filename = xmalloc (len + sizeof("/ccXXXXXX") + 1); + strcpy (temp_filename, base); + if (len > 0 && temp_filename[len-1] != '/') + temp_filename[len++] = '/'; + strcpy (temp_filename + len, "ccXXXXXX"); + + mktemp (temp_filename); + temp_filename_length = strlen (temp_filename); +} + +/* Routine to add variables to the environment. */ + +#ifndef HAVE_PUTENV + +int +putenv (str) + char *str; +{ +#ifndef VMS /* nor about VMS */ + + extern char **environ; + char **old_environ = environ; + char **envp; + int num_envs = 0; + int name_len = 1; + char *p = str; + int ch; + + while ((ch = *p++) != '\0' && ch != '=') + name_len++; + + if (!ch) + abort (); + + /* Search for replacing an existing environment variable, and + count the number of total environment variables. */ + for (envp = old_environ; *envp; envp++) + { + num_envs++; + if (!strncmp (str, *envp, name_len)) + { + *envp = str; + return 0; + } + } + + /* Add a new environment variable */ + environ = (char **) xmalloc (sizeof (char *) * (num_envs+2)); + *environ = str; + bcopy ((char *) old_environ, (char *) (environ + 1), + sizeof (char *) * (num_envs+1)); + + return 0; +#endif /* VMS */ +} + +#endif /* HAVE_PUTENV */ + +/* By default, colon separates directories in a path. */ +#ifndef PATH_SEPARATOR +#define PATH_SEPARATOR ':' +#endif + +/* We maintain two prefix lists: one from COMPILER_PATH environment variable + and one from the PATH variable. */ + +static struct path_prefix cpath, path; + +#ifdef CROSS_COMPILE +/* This is the name of the target machine. We use it to form the name + of the files to execute. */ + +static char *target_machine = TARGET_MACHINE; +#endif + +/* Names under which we were executed. Never return one of those files in our + searches. */ + +static struct path_prefix our_file_names; + +/* Determine if STRING is in PPREFIX. + + This utility is currently only used to look up file names. Prefix lists + record directory names. This matters to us because the latter has a + trailing slash, so I've added a flag to handle both. */ + +static int +is_in_prefix_list (pprefix, string, filep) + struct path_prefix *pprefix; + char *string; + int filep; +{ + struct prefix_list *pl; + + if (filep) + { + int len = strlen (string); + + for (pl = pprefix->plist; pl; pl = pl->next) + { + if (strncmp (pl->prefix, string, len) == 0 + && strcmp (pl->prefix + len, "/") == 0) + return 1; + } + } + else + { + for (pl = pprefix->plist; pl; pl = pl->next) + { + if (strcmp (pl->prefix, string) == 0) + return 1; + } + } + + return 0; +} + +/* Search for NAME using prefix list PPREFIX. We only look for executable + files. + + Return 0 if not found, otherwise return its name, allocated with malloc. */ + +static char * +find_a_file (pprefix, name) + struct path_prefix *pprefix; + char *name; +{ + char *temp; + struct prefix_list *pl; + int len = pprefix->max_len + strlen (name) + 1; + +#ifdef EXECUTABLE_SUFFIX + len += strlen (EXECUTABLE_SUFFIX); +#endif + + temp = xmalloc (len); + + /* Determine the filename to execute (special case for absolute paths). */ + + if (*name == '/') + { + if (access (name, X_OK) == 0) + { + strcpy (temp, name); + return temp; + } + } + else + for (pl = pprefix->plist; pl; pl = pl->next) + { + strcpy (temp, pl->prefix); + strcat (temp, name); + if (! is_in_prefix_list (&our_file_names, temp, 1) + /* This is a kludge, but there seems no way around it. */ + && strcmp (temp, "./ld") != 0 + && access (temp, X_OK) == 0) + return temp; + +#ifdef EXECUTABLE_SUFFIX + /* Some systems have a suffix for executable files. + So try appending that. */ + strcat (temp, EXECUTABLE_SUFFIX); + if (! is_in_prefix_list (&our_file_names, temp, 1) + && access (temp, X_OK) == 0) + return temp; +#endif + } + + free (temp); + return 0; +} + +/* Add an entry for PREFIX to prefix list PPREFIX. */ + +static void +add_prefix (pprefix, prefix) + struct path_prefix *pprefix; + char *prefix; +{ + struct prefix_list *pl, **prev; + int len; + + if (pprefix->plist) + { + for (pl = pprefix->plist; pl->next; pl = pl->next) + ; + prev = &pl->next; + } + else + prev = &pprefix->plist; + + /* Keep track of the longest prefix */ + + len = strlen (prefix); + if (len > pprefix->max_len) + pprefix->max_len = len; + + pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list)); + pl->prefix = savestring (prefix, len); + + if (*prev) + pl->next = *prev; + else + pl->next = (struct prefix_list *) 0; + *prev = pl; +} + +/* Take the value of the environment variable ENV, break it into a path, and + add of the entries to PPREFIX. */ + +static void +prefix_from_env (env, pprefix) + char *env; + struct path_prefix *pprefix; +{ + char *p = getenv (env); + + if (p) + prefix_from_string (p, pprefix); +} + +static void +prefix_from_string (p, pprefix) + char *p; + struct path_prefix *pprefix; +{ + char *startp, *endp; + char *nstore = (char *) xmalloc (strlen (p) + 3); + + startp = endp = p; + while (1) + { + if (*endp == PATH_SEPARATOR || *endp == 0) + { + strncpy (nstore, startp, endp-startp); + if (endp == startp) + { + strcpy (nstore, "./"); + } + else if (endp[-1] != '/') + { + nstore[endp-startp] = '/'; + nstore[endp-startp+1] = 0; + } + else + nstore[endp-startp] = 0; + + add_prefix (pprefix, nstore); + if (*endp == 0) + break; + endp = startp = endp + 1; + } + else + endp++; + } +} + +/* Main program. */ + +int +main (argc, argv) + int argc; + char *argv[]; +{ + char *ld_suffix = "ld"; + char *full_ld_suffix = ld_suffix; + char *real_ld_suffix = "real-ld"; + char *full_real_ld_suffix = real_ld_suffix; + char *collect_ld_suffix = "collect-ld"; + char *nm_suffix = "nm"; + char *full_nm_suffix = nm_suffix; + char *gnm_suffix = "gnm"; + char *full_gnm_suffix = gnm_suffix; +#ifdef LDD_SUFFIX + char *ldd_suffix = LDD_SUFFIX; + char *full_ldd_suffix = ldd_suffix; +#endif + char *strip_suffix = "strip"; + char *full_strip_suffix = strip_suffix; + char *gstrip_suffix = "gstrip"; + char *full_gstrip_suffix = gstrip_suffix; + char *arg; + FILE *outf, *exportf; + char *ld_file_name; + char *collect_name; + char *collect_names; + char *p; + char **c_argv; + char **c_ptr; + char **ld1_argv = (char **) xcalloc (sizeof (char *), argc+3); + char **ld1 = ld1_argv; + char **ld2_argv = (char **) xcalloc (sizeof (char *), argc+6); + char **ld2 = ld2_argv; + char **object_lst = (char **) xcalloc (sizeof (char *), argc); + char **object = object_lst; + int first_file; + int num_c_args = argc+7; + +#ifdef DEBUG + debug = 1; + vflag = 1; +#endif + + output_file = "a.out"; + + obstack_begin (&temporary_obstack, 0); + obstack_begin (&permanent_obstack, 0); + temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0); + current_demangling_style = gnu_demangling; + + /* We must check that we do not call ourselves in an infinite + recursion loop. We append the name used for us to the COLLECT_NAMES + environment variable. + + In practice, collect will rarely invoke itself. This can happen now + that we are no longer called gld. A perfect example is when running + gcc in a build directory that has been installed. When looking for + ld's, we'll find our installed version and believe that's the real ld. */ + + /* We must also append COLLECT_NAME to COLLECT_NAMES to watch for the + previous version of collect (the one that used COLLECT_NAME and only + handled two levels of recursion). If we don't we may mutually recurse + forever. This can happen (I think) when bootstrapping the old version + and a new one is installed (rare, but we should handle it). + ??? Hopefully references to COLLECT_NAME can be removed at some point. */ + + collect_name = (char *) getenv ("COLLECT_NAME"); + collect_names = (char *) getenv ("COLLECT_NAMES"); + + p = (char *) xmalloc (strlen ("COLLECT_NAMES=") + + (collect_name ? strlen (collect_name) + 1 : 0) + + (collect_names ? strlen (collect_names) + 1 : 0) + + strlen (argv[0]) + 1); + strcpy (p, "COLLECT_NAMES="); + if (collect_name != 0) + sprintf (p + strlen (p), "%s%c", collect_name, PATH_SEPARATOR); + if (collect_names != 0) + sprintf (p + strlen (p), "%s%c", collect_names, PATH_SEPARATOR); + strcat (p, argv[0]); + putenv (p); + + prefix_from_env ("COLLECT_NAMES", &our_file_names); + + /* Set environment variable COLLECT_NAME to our name so the previous version + of collect won't find us. If it does we'll mutually recurse forever. + This can happen when bootstrapping the new version and an old version is + installed. + ??? Hopefully this bit of code can be removed at some point. */ + + p = xmalloc (strlen ("COLLECT_NAME=") + strlen (argv[0]) + 1); + sprintf (p, "COLLECT_NAME=%s", argv[0]); + putenv (p); + + p = (char *) getenv ("COLLECT_GCC_OPTIONS"); + if (p) + while (*p) + { + char *q = p; + while (*q && *q != ' ') q++; + if (*p == '-' && p[1] == 'm') + num_c_args++; + + if (*q) q++; + p = q; + } + + c_ptr = c_argv = (char **) xcalloc (sizeof (char *), num_c_args); + + if (argc < 2) + fatal ("no arguments"); + +#ifdef SIGQUIT + if (signal (SIGQUIT, SIG_IGN) != SIG_IGN) + signal (SIGQUIT, handler); +#endif + if (signal (SIGINT, SIG_IGN) != SIG_IGN) + signal (SIGINT, handler); +#ifdef SIGALRM + if (signal (SIGALRM, SIG_IGN) != SIG_IGN) + signal (SIGALRM, handler); +#endif +#ifdef SIGHUP + if (signal (SIGHUP, SIG_IGN) != SIG_IGN) + signal (SIGHUP, handler); +#endif + if (signal (SIGSEGV, SIG_IGN) != SIG_IGN) + signal (SIGSEGV, handler); +#ifdef SIGBUS + if (signal (SIGBUS, SIG_IGN) != SIG_IGN) + signal (SIGBUS, handler); +#endif + + /* Extract COMPILER_PATH and PATH into our prefix list. */ + prefix_from_env ("COMPILER_PATH", &cpath); + prefix_from_env ("PATH", &path); + +#ifdef CROSS_COMPILE + /* If we look for a program in the compiler directories, we just use + the short name, since these directories are already system-specific. + But it we look for a took in the system directories, we need to + qualify the program name with the target machine. */ + + full_ld_suffix + = xcalloc (strlen (ld_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_ld_suffix, target_machine); + strcat (full_ld_suffix, "-"); + strcat (full_ld_suffix, ld_suffix); + + full_real_ld_suffix + = xcalloc (strlen (real_ld_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_real_ld_suffix, target_machine); + strcat (full_real_ld_suffix, "-"); + strcat (full_real_ld_suffix, real_ld_suffix); + +#if 0 + full_gld_suffix + = xcalloc (strlen (gld_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_gld_suffix, target_machine); + strcat (full_gld_suffix, "-"); + strcat (full_gld_suffix, gld_suffix); +#endif + + full_nm_suffix + = xcalloc (strlen (nm_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_nm_suffix, target_machine); + strcat (full_nm_suffix, "-"); + strcat (full_nm_suffix, nm_suffix); + + full_gnm_suffix + = xcalloc (strlen (gnm_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_gnm_suffix, target_machine); + strcat (full_gnm_suffix, "-"); + strcat (full_gnm_suffix, gnm_suffix); + +#ifdef LDD_SUFFIX + full_ldd_suffix + = xcalloc (strlen (ldd_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_ldd_suffix, target_machine); + strcat (full_ldd_suffix, "-"); + strcat (full_ldd_suffix, ldd_suffix); +#endif + + full_strip_suffix + = xcalloc (strlen (strip_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_strip_suffix, target_machine); + strcat (full_strip_suffix, "-"); + strcat (full_strip_suffix, strip_suffix); + + full_gstrip_suffix + = xcalloc (strlen (gstrip_suffix) + strlen (target_machine) + 2, 1); + strcpy (full_gstrip_suffix, target_machine); + strcat (full_gstrip_suffix, "-"); + strcat (full_gstrip_suffix, gstrip_suffix); +#endif /* CROSS_COMPILE */ + + /* Try to discover a valid linker/nm/strip to use. */ + + /* Maybe we know the right file to use (if not cross). */ +#ifdef REAL_LD_FILE_NAME + ld_file_name = find_a_file (&path, REAL_LD_FILE_NAME); + if (ld_file_name == 0) +#endif + /* Search the (target-specific) compiler dirs for ld'. */ + ld_file_name = find_a_file (&cpath, real_ld_suffix); + /* Likewise for `collect-ld'. */ + if (ld_file_name == 0) + ld_file_name = find_a_file (&cpath, collect_ld_suffix); + /* Search the compiler directories for `ld'. We have protection against + recursive calls in find_a_file. */ + if (ld_file_name == 0) + ld_file_name = find_a_file (&cpath, ld_suffix); + /* Search the ordinary system bin directories + for `ld' (if native linking) or `TARGET-ld' (if cross). */ + if (ld_file_name == 0) + ld_file_name = find_a_file (&path, full_ld_suffix); + + /* If we've invoked ourselves, try again with LD_FILE_NAME. */ + + if (collect_names != 0) + { + if (ld_file_name != 0) + { + argv[0] = ld_file_name; + execvp (argv[0], argv); + } + fatal ("cannot find `ld'"); + } + +#ifdef REAL_NM_FILE_NAME + nm_file_name = find_a_file (&path, REAL_NM_FILE_NAME); + if (nm_file_name == 0) +#endif + nm_file_name = find_a_file (&cpath, gnm_suffix); + if (nm_file_name == 0) + nm_file_name = find_a_file (&path, full_gnm_suffix); + if (nm_file_name == 0) + nm_file_name = find_a_file (&cpath, nm_suffix); + if (nm_file_name == 0) + nm_file_name = find_a_file (&path, full_nm_suffix); + +#ifdef LDD_SUFFIX + ldd_file_name = find_a_file (&cpath, ldd_suffix); + if (ldd_file_name == 0) + ldd_file_name = find_a_file (&path, full_ldd_suffix); +#endif + +#ifdef REAL_STRIP_FILE_NAME + strip_file_name = find_a_file (&path, REAL_STRIP_FILE_NAME); + if (strip_file_name == 0) +#endif + strip_file_name = find_a_file (&cpath, gstrip_suffix); + if (strip_file_name == 0) + strip_file_name = find_a_file (&path, full_gstrip_suffix); + if (strip_file_name == 0) + strip_file_name = find_a_file (&cpath, strip_suffix); + if (strip_file_name == 0) + strip_file_name = find_a_file (&path, full_strip_suffix); + + /* Determine the full path name of the C compiler to use. */ + c_file_name = getenv ("COLLECT_GCC"); + if (c_file_name == 0) + { +#ifdef CROSS_COMPILE + c_file_name = xcalloc (sizeof ("gcc-") + strlen (target_machine) + 1, 1); + strcpy (c_file_name, target_machine); + strcat (c_file_name, "-gcc"); +#else + c_file_name = "gcc"; +#endif + } + + p = find_a_file (&cpath, c_file_name); + + /* Here it should be safe to use the system search path since we should have + already qualified the name of the compiler when it is needed. */ + if (p == 0) + p = find_a_file (&path, c_file_name); + + if (p) + c_file_name = p; + + *ld1++ = *ld2++ = ld_file_name; + + /* Make temp file names. */ + choose_temp_base (); + c_file = xcalloc (temp_filename_length + sizeof (".c"), 1); + o_file = xcalloc (temp_filename_length + sizeof (".o"), 1); + export_file = xmalloc (temp_filename_length + sizeof (".x")); + ldout = xmalloc (temp_filename_length + sizeof (".ld")); + sprintf (ldout, "%s.ld", temp_filename); + sprintf (c_file, "%s.c", temp_filename); + sprintf (o_file, "%s.o", temp_filename); + sprintf (export_file, "%s.x", temp_filename); + *c_ptr++ = c_file_name; + *c_ptr++ = "-c"; + *c_ptr++ = "-o"; + *c_ptr++ = o_file; + + /* !!! When GCC calls collect2, + it does not know whether it is calling collect2 or ld. + So collect2 cannot meaningfully understand any options + except those ld understands. + If you propose to make GCC pass some other option, + just imagine what will happen if ld is really ld!!! */ + + /* Parse arguments. Remember output file spec, pass the rest to ld. */ + /* After the first file, put in the c++ rt0. */ + + first_file = 1; + while ((arg = *++argv) != (char *)0) + { + *ld1++ = *ld2++ = arg; + + if (arg[0] == '-') + { + switch (arg[1]) + { + case 'd': + if (!strcmp (arg, "-debug")) + { + debug = 1; + vflag = 1; + ld1--; + ld2--; + } + break; + +#ifdef COLLECT_EXPORT_LIST + case 'b': + if ((!strncmp (arg, "-bE:", 4) + || !strncmp (arg, "-bexport:", 9)) + && strcmp (arg, "-bexport:/usr/lib/libg.exp")) + auto_export = 0; + break; +#endif + + case 'l': + if (first_file) + { + /* place o_file BEFORE this argument! */ + first_file = 0; + ld2--; + *ld2++ = o_file; + *ld2++ = arg; + } + break; + + case 'o': + if (arg[2] == '\0') + output_file = *ld1++ = *ld2++ = *++argv; + else + output_file = &arg[2]; + break; + + case 'r': + if (arg[2] == '\0') + rflag = 1; + break; + + case 's': + if (arg[2] == '\0' && do_collecting) + { + /* We must strip after the nm run, otherwise C++ linking + won't work. Thus we strip in the second ld run, or + else with strip if there is no second ld run. */ + strip_flag = 1; + ld1--; + } + break; + + case 'v': + if (arg[2] == '\0') + vflag = 1; + break; + } + } + else if ((p = rindex (arg, '.')) != (char *)0 + && (strcmp (p, ".o") == 0 || strcmp (p, ".a") == 0)) + { + if (first_file) + { + first_file = 0; + if (p[1] == 'o') + *ld2++ = o_file; + else + { + /* place o_file BEFORE this argument! */ + ld2--; + *ld2++ = o_file; + *ld2++ = arg; + } + } + if (p[1] == 'o') + *object++ = arg; + } + } + + /* Get any options that the upper GCC wants to pass to the sub-GCC. */ + p = (char *) getenv ("COLLECT_GCC_OPTIONS"); + if (p) + while (*p) + { + char *q = p; + while (*q && *q != ' ') q++; + if (*p == '-' && (p[1] == 'm' || p[1] == 'f')) + *c_ptr++ = savestring (p, q - p); + if (strncmp (p, "-shared", sizeof ("shared") - 1) == 0) + shared_obj = 1; + + if (*q) q++; + p = q; + } + +#ifdef COLLECT_EXPORT_LIST + /* The AIX linker will discard static constructors in object files if + nothing else in the file is referenced, so look at them first. */ + while (object_lst < object) + scan_prog_file (*object_lst++, PASS_OBJ); + + { + char *buf = alloca (strlen (export_file) + 5); + sprintf (buf, "-bE:%s", export_file); + *ld1++ = buf; + *ld2++ = buf; + exportf = fopen (export_file, "w"); + if (exportf == (FILE *)0) + fatal_perror ("%s", export_file); + write_export_file (exportf); + if (fclose (exportf)) + fatal_perror ("closing %s", export_file); + } +#endif + + *c_ptr++ = c_file; + *object = *c_ptr = *ld1 = (char *)0; + + if (vflag) + { + fprintf (stderr, "collect2 version %s", version_string); +#ifdef TARGET_VERSION + TARGET_VERSION; +#endif + fprintf (stderr, "\n"); + } + + if (debug) + { + char *ptr; + fprintf (stderr, "ld_file_name = %s\n", + (ld_file_name ? ld_file_name : "not found")); + fprintf (stderr, "c_file_name = %s\n", + (c_file_name ? c_file_name : "not found")); + fprintf (stderr, "nm_file_name = %s\n", + (nm_file_name ? nm_file_name : "not found")); +#ifdef LDD_SUFFIX + fprintf (stderr, "ldd_file_name = %s\n", + (ldd_file_name ? ldd_file_name : "not found")); +#endif + fprintf (stderr, "strip_file_name = %s\n", + (strip_file_name ? strip_file_name : "not found")); + fprintf (stderr, "c_file = %s\n", + (c_file ? c_file : "not found")); + fprintf (stderr, "o_file = %s\n", + (o_file ? o_file : "not found")); + + ptr = getenv ("COLLECT_NAMES"); + if (ptr) + fprintf (stderr, "COLLECT_NAMES = %s\n", ptr); + + ptr = getenv ("COLLECT_GCC_OPTIONS"); + if (ptr) + fprintf (stderr, "COLLECT_GCC_OPTIONS = %s\n", ptr); + + ptr = getenv ("COLLECT_GCC"); + if (ptr) + fprintf (stderr, "COLLECT_GCC = %s\n", ptr); + + ptr = getenv ("COMPILER_PATH"); + if (ptr) + fprintf (stderr, "COMPILER_PATH = %s\n", ptr); + + ptr = getenv ("LIBRARY_PATH"); + if (ptr) + fprintf (stderr, "LIBRARY_PATH = %s\n", ptr); + + fprintf (stderr, "\n"); + } + + /* Load the program, searching all libraries. */ + + collect_execute ("ld", ld1_argv, ldout); + do_wait ("ld"); + dump_file (ldout); + unlink (ldout); + + /* If -r or they'll be run via some other method, don't build the + constructor or destructor list, just return now. */ + if (rflag || ! do_collecting) + return 0; + + /* Examine the namelist with nm and search it for static constructors + and destructors to call. + Write the constructor and destructor tables to a .s file and reload. */ + + scan_prog_file (output_file, PASS_FIRST); + +#ifdef SCAN_LIBRARIES + scan_libraries (output_file); +#endif + + if (debug) + { + fprintf (stderr, "%d constructor(s) found\n", constructors.number); + fprintf (stderr, "%d destructor(s) found\n", destructors.number); + } + + if (constructors.number == 0 && destructors.number == 0 +#ifdef LDD_SUFFIX + /* If we will be running these functions ourselves, we want to emit + stubs into the shared library so that we don't have to relink + dependent programs when we add static objects. */ + && ! shared_obj +#endif + ) + { + /* Strip now if it was requested on the command line. */ + if (strip_flag) + { + char **strip_argv = (char **) xcalloc (sizeof (char *), 3); + strip_argv[0] = strip_file_name; + strip_argv[1] = output_file; + strip_argv[2] = (char *) 0; + fork_execute ("strip", strip_argv); + } + +#ifdef COLLECT_EXPORT_LIST + maybe_unlink (export_file); +#endif + return 0; + } + + maybe_unlink(output_file); + outf = fopen (c_file, "w"); + if (outf == (FILE *)0) + fatal_perror ("%s", c_file); + + write_c_file (outf, c_file); + + if (fclose (outf)) + fatal_perror ("closing %s", c_file); + + /* Tell the linker that we have initializer and finalizer functions. */ +#ifdef LD_INIT_SWITCH + *ld2++ = LD_INIT_SWITCH; + *ld2++ = initname; + *ld2++ = LD_FINI_SWITCH; + *ld2++ = fininame; +#endif + *ld2 = (char*)0; + +#ifdef COLLECT_EXPORT_LIST + if (shared_obj) + { + add_to_list (&exports, initname); + add_to_list (&exports, fininame); + add_to_list (&exports, "_GLOBAL__DI"); + add_to_list (&exports, "_GLOBAL__DD"); + exportf = fopen (export_file, "w"); + if (exportf == (FILE *)0) + fatal_perror ("%s", export_file); + write_export_file (exportf); + if (fclose (exportf)) + fatal_perror ("closing %s", export_file); + } +#endif + + if (debug) + { + fprintf (stderr, "\n========== output_file = %s, c_file = %s\n", + output_file, c_file); + write_c_file (stderr, "stderr"); + fprintf (stderr, "========== end of c_file\n\n"); +#ifdef COLLECT_EXPORT_LIST + fprintf (stderr, "\n========== export_file = %s\n", export_file); + write_export_file (stderr); + fprintf (stderr, "========== end of export_file\n\n"); +#endif + } + + /* Assemble the constructor and destructor tables. + Link the tables in with the rest of the program. */ + + fork_execute ("gcc", c_argv); + fork_execute ("ld", ld2_argv); + + /* Let scan_prog_file do any final mods (OSF/rose needs this for + constructors/destructors in shared libraries. */ + scan_prog_file (output_file, PASS_SECOND); + + maybe_unlink (c_file); + maybe_unlink (o_file); + maybe_unlink (export_file); + return 0; +} + + +/* Wait for a process to finish, and exit if a non-zero status is found. */ + +int +collect_wait (prog) + char *prog; +{ + int status; + + wait (&status); + if (status) + { + if (WIFSIGNALED (status)) + { + int sig = WTERMSIG (status); +#ifdef NO_SYS_SIGLIST + error ("%s terminated with signal %d %s", + prog, + sig, + (status & 0200) ? ", core dumped" : ""); +#else + error ("%s terminated with signal %d [%s]%s", + prog, + sig, + sys_siglist[sig], + (status & 0200) ? ", core dumped" : ""); +#endif + + collect_exit (127); + } + + if (WIFEXITED (status)) + return WEXITSTATUS (status); + } + return 0; +} + +static void +do_wait (prog) + char *prog; +{ + int ret = collect_wait (prog); + if (ret != 0) + { + error ("%s returned %d exit status", prog, ret); + collect_exit (ret); + } +} + + +/* Fork and execute a program, and wait for the reply. */ + +void +collect_execute (prog, argv, redir) + char *prog; + char **argv; + char *redir; +{ + int pid; + + if (vflag || debug) + { + char **p_argv; + char *str; + + if (argv[0]) + fprintf (stderr, "%s", argv[0]); + else + fprintf (stderr, "[cannot find %s]", prog); + + for (p_argv = &argv[1]; (str = *p_argv) != (char *)0; p_argv++) + fprintf (stderr, " %s", str); + + fprintf (stderr, "\n"); + } + + fflush (stdout); + fflush (stderr); + + /* If we can't find a program we need, complain error. Do this here + since we might not end up needing something that we couldn't find. */ + + if (argv[0] == 0) + fatal ("cannot find `%s'", prog); + + pid = vfork (); + if (pid == -1) + { +#ifdef vfork + fatal_perror ("fork"); +#else + fatal_perror ("vfork"); +#endif + } + + if (pid == 0) /* child context */ + { + if (redir) + { + unlink (redir); + if (freopen (redir, "a", stdout) == NULL) + fatal_perror ("redirecting stdout"); + if (freopen (redir, "a", stderr) == NULL) + fatal_perror ("redirecting stderr"); + } + + execvp (argv[0], argv); + fatal_perror ("executing %s", prog); + } +} + +static void +fork_execute (prog, argv) + char *prog; + char **argv; +{ + collect_execute (prog, argv, NULL); + do_wait (prog); +} + +/* Unlink a file unless we are debugging. */ + +static void +maybe_unlink (file) + char *file; +{ + if (!debug) + unlink (file); + else + fprintf (stderr, "[Leaving %s]\n", file); +} + + +/* Add a name to a linked list. */ + +static void +add_to_list (head_ptr, name) + struct head *head_ptr; + char *name; +{ + struct id *newid + = (struct id *) xcalloc (sizeof (struct id) + strlen (name), 1); + struct id *p; + static long sequence_number = 0; + strcpy (newid->name, name); + + if (head_ptr->first) + head_ptr->last->next = newid; + else + head_ptr->first = newid; + + /* Check for duplicate symbols. */ + for (p = head_ptr->first; + strcmp (name, p->name) != 0; + p = p->next) + ; + if (p != newid) + { + head_ptr->last->next = 0; + free (newid); + return; + } + + newid->sequence = ++sequence_number; + head_ptr->last = newid; + head_ptr->number++; +} + +/* Write: `prefix', the names on list LIST, `suffix'. */ + +static void +write_list (stream, prefix, list) + FILE *stream; + char *prefix; + struct id *list; +{ + while (list) + { + fprintf (stream, "%sx%d,\n", prefix, list->sequence); + list = list->next; + } +} + +static void +write_list_with_asm (stream, prefix, list) + FILE *stream; + char *prefix; + struct id *list; +{ + while (list) + { + fprintf (stream, "%sx%d __asm__ (\"%s\");\n", + prefix, list->sequence, list->name); + list = list->next; + } +} + +/* Write out the constructor and destructor tables statically (for a shared + object), along with the functions to execute them. */ + +static void +write_c_file_stat (stream, name) + FILE *stream; + char *name; +{ + char *prefix, *p, *q; + + /* Figure out name of output_file, stripping off .so version. */ + p = rindex (output_file, '/'); + if (p == 0) + p = (char *) output_file; + else + p++; + q = p; + while (q) + { + q = index (q,'.'); + if (q == 0) + { + q = p + strlen (p); + break; + } + else + { + if (strncmp (q, ".so", 3) == 0) + { + q += 3; + break; + } + else + q++; + } + } + /* q points to null at end of the string (or . of the .so version) */ + prefix = xmalloc (q - p + 1); + strncpy (prefix, p, q - p); + prefix[q - p] = 0; + for (q = prefix; *q; q++) + if (!isalnum (*q)) + *q = '_'; + if (debug) + fprintf (stderr, "\nwrite_c_file - output name is %s, prefix is %s\n", + output_file, prefix); + +#define INIT_NAME_FORMAT "_GLOBAL__FI_%s" + initname = xmalloc (strlen (prefix) + sizeof (INIT_NAME_FORMAT) - 2); + sprintf (initname, INIT_NAME_FORMAT, prefix); + +#define FINI_NAME_FORMAT "_GLOBAL__FD_%s" + fininame = xmalloc (strlen (prefix) + sizeof (FINI_NAME_FORMAT) - 2); + sprintf (fininame, FINI_NAME_FORMAT, prefix); + + free (prefix); + + /* Write the tables as C code */ + + fprintf (stream, "static int count;\n"); + fprintf (stream, "typedef void entry_pt();\n"); + write_list_with_asm (stream, "extern entry_pt ", constructors.first); + fprintf (stream, "void %s() {\n", initname); + if (constructors.number > 0) + { + fprintf (stream, "\tstatic entry_pt *ctors[] = {\n"); + write_list (stream, "\t\t", constructors.first); + fprintf (stream, "\t};\n"); + fprintf (stream, "\tentry_pt **p;\n"); + fprintf (stream, "\tif (count++ != 0) return;\n"); + fprintf (stream, "\tp = ctors + %d;\n", constructors.number); + fprintf (stream, "\twhile (p > ctors) (*--p)();\n"); + } + else + fprintf (stream, "\t++count;\n"); + fprintf (stream, "}\n"); + write_list_with_asm (stream, "extern entry_pt ", destructors.first); + fprintf (stream, "void %s() {\n", fininame); + if (destructors.number > 0) + { + fprintf (stream, "\tstatic entry_pt *dtors[] = {\n"); + write_list (stream, "\t\t", destructors.first); + fprintf (stream, "\t};\n"); + fprintf (stream, "\tentry_pt **p;\n"); + fprintf (stream, "\tif (--count != 0) return;\n"); + fprintf (stream, "\tp = dtors;\n"); + fprintf (stream, "\twhile (p < dtors + %d) (*p++)();\n", + destructors.number); + } + fprintf (stream, "}\n"); + + if (shared_obj) + { + fprintf (stream, "void _GLOBAL__DI() {\n\t%s();\n}\n", initname); + fprintf (stream, "void _GLOBAL__DD() {\n\t%s();\n}\n", fininame); + } +} + +/* Write the constructor/destructor tables. */ + +static void +write_c_file_glob (stream, name) + FILE *stream; + char *name; +{ + /* Write the tables as C code */ + + fprintf (stream, "typedef void entry_pt();\n\n"); + + write_list_with_asm (stream, "extern entry_pt ", constructors.first); + + fprintf (stream, "\nentry_pt * __CTOR_LIST__[] = {\n"); + fprintf (stream, "\t(entry_pt *) %d,\n", constructors.number); + write_list (stream, "\t", constructors.first); + fprintf (stream, "\t0\n};\n\n"); + + write_list_with_asm (stream, "extern entry_pt ", destructors.first); + + fprintf (stream, "\nentry_pt * __DTOR_LIST__[] = {\n"); + fprintf (stream, "\t(entry_pt *) %d,\n", destructors.number); + write_list (stream, "\t", destructors.first); + fprintf (stream, "\t0\n};\n\n"); + + fprintf (stream, "extern entry_pt %s;\n", NAME__MAIN); + fprintf (stream, "entry_pt *__main_reference = %s;\n\n", NAME__MAIN); +} + +static void +write_c_file (stream, name) + FILE *stream; + char *name; +{ +#ifndef LD_INIT_SWITCH + if (! shared_obj) + write_c_file_glob (stream, name); + else +#endif + write_c_file_stat (stream, name); +} + +static void +write_export_file (stream) + FILE *stream; +{ + struct id *list = exports.first; + for (; list; list = list->next) + fprintf (stream, "%s\n", list->name); +} + +#ifdef OBJECT_FORMAT_NONE + +/* Generic version to scan the name list of the loaded program for + the symbols g++ uses for static constructors and destructors. + + The constructor table begins at __CTOR_LIST__ and contains a count + of the number of pointers (or -1 if the constructors are built in a + separate section by the linker), followed by the pointers to the + constructor functions, terminated with a null pointer. The + destructor table has the same format, and begins at __DTOR_LIST__. */ + +static void +scan_prog_file (prog_name, which_pass) + char *prog_name; + enum pass which_pass; +{ + void (*int_handler) (); + void (*quit_handler) (); + char *nm_argv[4]; + int pid; + int argc = 0; + int pipe_fd[2]; + char *p, buf[1024]; + FILE *inf; + + if (which_pass == PASS_SECOND) + return; + + /* If we don't have an `nm', complain. */ + if (nm_file_name == 0) + fatal ("cannot find `nm'"); + + nm_argv[argc++] = nm_file_name; + if (NM_FLAGS[0] != '\0') + nm_argv[argc++] = NM_FLAGS; + + nm_argv[argc++] = prog_name; + nm_argv[argc++] = (char *)0; + + if (pipe (pipe_fd) < 0) + fatal_perror ("pipe"); + + inf = fdopen (pipe_fd[0], "r"); + if (inf == (FILE *)0) + fatal_perror ("fdopen"); + + /* Trace if needed. */ + if (vflag) + { + char **p_argv; + char *str; + + for (p_argv = &nm_argv[0]; (str = *p_argv) != (char *)0; p_argv++) + fprintf (stderr, " %s", str); + + fprintf (stderr, "\n"); + } + + fflush (stdout); + fflush (stderr); + + /* Spawn child nm on pipe */ + pid = vfork (); + if (pid == -1) + { +#ifdef vfork + fatal_perror ("fork"); +#else + fatal_perror ("vfork"); +#endif + } + + if (pid == 0) /* child context */ + { + /* setup stdout */ + if (dup2 (pipe_fd[1], 1) < 0) + fatal_perror ("dup2 (%d, 1)", pipe_fd[1]); + + if (close (pipe_fd[0]) < 0) + fatal_perror ("close (%d)", pipe_fd[0]); + + if (close (pipe_fd[1]) < 0) + fatal_perror ("close (%d)", pipe_fd[1]); + + execv (nm_file_name, nm_argv); + fatal_perror ("executing %s", nm_file_name); + } + + /* Parent context from here on. */ + int_handler = (void (*) ())signal (SIGINT, SIG_IGN); +#ifdef SIGQUIT + quit_handler = (void (*) ())signal (SIGQUIT, SIG_IGN); +#endif + + if (close (pipe_fd[1]) < 0) + fatal_perror ("close (%d)", pipe_fd[1]); + + if (debug) + fprintf (stderr, "\nnm output with constructors/destructors.\n"); + + /* Read each line of nm output. */ + while (fgets (buf, sizeof buf, inf) != (char *)0) + { + int ch, ch2; + char *name, *end; + + /* If it contains a constructor or destructor name, add the name + to the appropriate list. */ + + for (p = buf; (ch = *p) != '\0' && ch != '\n' && ch != '_'; p++) + if (ch == ' ' && p[1] == 'U' && p[2] == ' ') + break; + + if (ch != '_') + continue; + + name = p; + /* Find the end of the symbol name. + Don't include `|', because Encore nm can tack that on the end. */ + for (end = p; (ch2 = *end) != '\0' && !isspace (ch2) && ch2 != '|'; + end++) + continue; + + + *end = '\0'; + switch (is_ctor_dtor (name)) + { + case 1: + if (which_pass != PASS_LIB) + add_to_list (&constructors, name); + break; + + case 2: + if (which_pass != PASS_LIB) + add_to_list (&destructors, name); + break; + + case 3: + if (which_pass != PASS_LIB) + fatal ("init function found in object %s", prog_name); +#ifndef LD_INIT_SWITCH + add_to_list (&constructors, name); +#endif + break; + + case 4: + if (which_pass != PASS_LIB) + fatal ("fini function found in object %s", prog_name); +#ifndef LD_FINI_SWITCH + add_to_list (&destructors, name); +#endif + break; + + default: /* not a constructor or destructor */ + continue; + } + + if (debug) + fprintf (stderr, "\t%s\n", buf); + } + + if (debug) + fprintf (stderr, "\n"); + + if (fclose (inf) != 0) + fatal_perror ("fclose of pipe"); + + do_wait (nm_file_name); + + signal (SIGINT, int_handler); +#ifdef SIGQUIT + signal (SIGQUIT, quit_handler); +#endif +} + +#if SUNOS4_SHARED_LIBRARIES + +/* Routines to scan the SunOS 4 _DYNAMIC structure to find shared libraries + that the output file depends upon and their initialization/finalization + routines, if any. */ + +#include +#include +#include +#include +#include +#include +#include + +/* pointers to the object file */ +unsigned object; /* address of memory mapped file */ +unsigned objsize; /* size of memory mapped to file */ +char * code; /* pointer to code segment */ +char * data; /* pointer to data segment */ +struct nlist *symtab; /* pointer to symbol table */ +struct link_dynamic *ld; +struct link_dynamic_2 *ld_2; +struct head libraries; + +/* Map the file indicated by NAME into memory and store its address. */ + +static void +mapfile (name) + char *name; +{ + int fp; + struct stat s; + if ((fp = open (name, O_RDONLY)) == -1) + fatal ("unable to open file '%s'", name); + if (fstat (fp, &s) == -1) + fatal ("unable to stat file '%s'", name); + + objsize = s.st_size; + object = (unsigned) mmap (0, objsize, PROT_READ|PROT_WRITE, MAP_PRIVATE, + fp, 0); + if (object == -1) + fatal ("unable to mmap file '%s'", name); + + close (fp); +} + +/* Helpers for locatelib. */ + +static char *libname; + +static int +libselect (d) + struct direct *d; +{ + return (strncmp (libname, d->d_name, strlen (libname)) == 0); +} + +/* If one file has an additional numeric extension past LIBNAME, then put + that one first in the sort. If both files have additional numeric + extensions, then put the one with the higher number first in the sort. + + We must verify that the extension is numeric, because Sun saves the + original versions of patched libraries with a .FCS extension. Files with + invalid extensions must go last in the sort, so that they won't be used. */ + +static int +libcompare (d1, d2) + struct direct **d1, **d2; +{ + int i1, i2 = strlen (libname); + char *e1 = (*d1)->d_name + i2; + char *e2 = (*d2)->d_name + i2; + + while (*e1 && *e2 && *e1 == '.' && *e2 == '.' + && e1[1] && isdigit (e1[1]) && e2[1] && isdigit (e2[1])) + { + ++e1; + ++e2; + i1 = strtol (e1, &e1, 10); + i2 = strtol (e2, &e2, 10); + if (i1 != i2) + return i1 - i2; + } + + if (*e1) + { + /* It has a valid numeric extension, prefer this one. */ + if (*e1 == '.' && e1[1] && isdigit (e1[1])) + return 1; + /* It has a invalid numeric extension, must prefer the other one. */ + else + return -1; + } + else if (*e2) + { + /* It has a valid numeric extension, prefer this one. */ + if (*e2 == '.' && e2[1] && isdigit (e2[1])) + return -1; + /* It has a invalid numeric extension, must prefer the other one. */ + else + return 1; + } + else + return 0; +} + +/* Given the name NAME of a dynamic dependency, find its pathname and add + it to the list of libraries. */ + +static void +locatelib (name) + char *name; +{ + static char **l; + static int cnt; + char buf[MAXPATHLEN]; + char *p, *q; + char **pp; + + if (l == 0) + { + char *ld_rules; + char *ldr = 0; + /* counting elements in array, need 1 extra for null */ + cnt = 1; + ld_rules = (char *) (ld_2->ld_rules + code); + if (ld_rules) + { + cnt++; + for (; *ld_rules != 0; ld_rules++) + if (*ld_rules == ':') + cnt++; + ld_rules = (char *) (ld_2->ld_rules + code); + ldr = (char *) malloc (strlen (ld_rules) + 1); + strcpy (ldr, ld_rules); + } + p = getenv ("LD_LIBRARY_PATH"); + q = 0; + if (p) + { + cnt++; + for (q = p ; *q != 0; q++) + if (*q == ':') + cnt++; + q = (char *) malloc (strlen (p) + 1); + strcpy (q, p); + } + l = (char **) malloc ((cnt + 3) * sizeof (char *)); + pp = l; + if (ldr) + { + *pp++ = ldr; + for (; *ldr != 0; ldr++) + if (*ldr == ':') + { + *ldr++ = 0; + *pp++ = ldr; + } + } + if (q) + { + *pp++ = q; + for (; *q != 0; q++) + if (*q == ':') + { + *q++ = 0; + *pp++ = q; + } + } + /* built in directories are /lib, /usr/lib, and /usr/local/lib */ + *pp++ = "/lib"; + *pp++ = "/usr/lib"; + *pp++ = "/usr/local/lib"; + *pp = 0; + } + libname = name; + for (pp = l; *pp != 0 ; pp++) + { + struct direct **namelist; + int entries; + if ((entries = scandir (*pp, &namelist, libselect, libcompare)) > 0) + { + sprintf (buf, "%s/%s", *pp, namelist[entries - 1]->d_name); + add_to_list (&libraries, buf); + if (debug) + fprintf (stderr, "%s\n", buf); + break; + } + } + if (*pp == 0) + { + if (debug) + fprintf (stderr, "not found\n"); + else + fatal ("dynamic dependency %s not found", name); + } +} + +/* Scan the _DYNAMIC structure of the output file to find shared libraries + that it depends upon and any constructors or destructors they contain. */ + +static void +scan_libraries (prog_name) + char *prog_name; +{ + struct exec *header; + char *base; + struct link_object *lo; + char buff[MAXPATHLEN]; + struct id *list; + + mapfile (prog_name); + header = (struct exec *)object; + if (N_BADMAG (*header)) + fatal ("bad magic number in file '%s'", prog_name); + if (header->a_dynamic == 0) + return; + + code = (char *) (N_TXTOFF (*header) + (long) header); + data = (char *) (N_DATOFF (*header) + (long) header); + symtab = (struct nlist *) (N_SYMOFF (*header) + (long) header); + + if (header->a_magic == ZMAGIC && header->a_entry == 0x20) + { + /* shared object */ + ld = (struct link_dynamic *) (symtab->n_value + code); + base = code; + } + else + { + /* executable */ + ld = (struct link_dynamic *) data; + base = code-PAGSIZ; + } + + if (debug) + fprintf (stderr, "dynamic dependencies.\n"); + + ld_2 = (struct link_dynamic_2 *) ((long) ld->ld_un.ld_2 + (long)base); + for (lo = (struct link_object *) ld_2->ld_need; lo; + lo = (struct link_object *) lo->lo_next) + { + char *name; + lo = (struct link_object *) ((long) lo + code); + name = (char *) (code + lo->lo_name); + if (lo->lo_library) + { + if (debug) + fprintf (stderr, "\t-l%s.%d => ", name, lo->lo_major); + sprintf (buff, "lib%s.so.%d.%d", name, lo->lo_major, lo->lo_minor); + locatelib (buff); + } + else + { + if (debug) + fprintf (stderr, "\t%s\n", name); + add_to_list (&libraries, name); + } + } + + if (debug) + fprintf (stderr, "\n"); + + /* now iterate through the library list adding their symbols to + the list. */ + for (list = libraries.first; list; list = list->next) + scan_prog_file (list->name, PASS_LIB); +} + +#else /* SUNOS4_SHARED_LIBRARIES */ +#ifdef LDD_SUFFIX + +/* Use the List Dynamic Dependencies program to find shared libraries that + the output file depends upon and their initialization/finalization + routines, if any. */ + +static void +scan_libraries (prog_name) + char *prog_name; +{ + static struct head libraries; /* list of shared libraries found */ + struct id *list; + void (*int_handler) (); + void (*quit_handler) (); + char *ldd_argv[4]; + int pid; + int argc = 0; + int pipe_fd[2]; + char buf[1024]; + FILE *inf; + + /* If we don't have an `ldd', complain. */ + if (ldd_file_name == 0) + { + error ("cannot find `ldd'"); + return; + } + + ldd_argv[argc++] = ldd_file_name; + ldd_argv[argc++] = prog_name; + ldd_argv[argc++] = (char *) 0; + + if (pipe (pipe_fd) < 0) + fatal_perror ("pipe"); + + inf = fdopen (pipe_fd[0], "r"); + if (inf == (FILE *) 0) + fatal_perror ("fdopen"); + + /* Trace if needed. */ + if (vflag) + { + char **p_argv; + char *str; + + for (p_argv = &ldd_argv[0]; (str = *p_argv) != (char *) 0; p_argv++) + fprintf (stderr, " %s", str); + + fprintf (stderr, "\n"); + } + + fflush (stdout); + fflush (stderr); + + /* Spawn child ldd on pipe */ + pid = vfork (); + if (pid == -1) + { +#ifdef vfork + fatal_perror ("fork"); +#else + fatal_perror ("vfork"); +#endif + } + + if (pid == 0) /* child context */ + { + /* setup stdout */ + if (dup2 (pipe_fd[1], 1) < 0) + fatal_perror ("dup2 (%d, 1)", pipe_fd[1]); + + if (close (pipe_fd[0]) < 0) + fatal_perror ("close (%d)", pipe_fd[0]); + + if (close (pipe_fd[1]) < 0) + fatal_perror ("close (%d)", pipe_fd[1]); + + execv (ldd_file_name, ldd_argv); + fatal_perror ("executing %s", ldd_file_name); + } + + /* Parent context from here on. */ + int_handler = (void (*) ()) signal (SIGINT, SIG_IGN); +#ifdef SIGQUIT + quit_handler = (void (*) ()) signal (SIGQUIT, SIG_IGN); +#endif + + if (close (pipe_fd[1]) < 0) + fatal_perror ("close (%d)", pipe_fd[1]); + + if (debug) + fprintf (stderr, "\nldd output with constructors/destructors.\n"); + + /* Read each line of ldd output. */ + while (fgets (buf, sizeof buf, inf) != (char *) 0) + { + int ch, ch2; + char *name, *end, *p = buf; + + /* Extract names of libraries and add to list. */ + PARSE_LDD_OUTPUT (p); + if (p == 0) + continue; + + name = p; + if (strncmp (name, "not found", sizeof ("not found") - 1) == 0) + fatal ("dynamic dependency %s not found", buf); + + /* Find the end of the symbol name. */ + for (end = p; + (ch2 = *end) != '\0' && ch2 != '\n' && !isspace (ch2) && ch2 != '|'; + end++) + continue; + *end = '\0'; + + if (access (name, R_OK) == 0) + add_to_list (&libraries, name); + else + fatal ("unable to open dynamic dependency '%s'", buf); + + if (debug) + fprintf (stderr, "\t%s\n", buf); + } + if (debug) + fprintf (stderr, "\n"); + + if (fclose (inf) != 0) + fatal_perror ("fclose of pipe"); + + do_wait (ldd_file_name); + + signal (SIGINT, int_handler); +#ifdef SIGQUIT + signal (SIGQUIT, quit_handler); +#endif + + /* now iterate through the library list adding their symbols to + the list. */ + for (list = libraries.first; list; list = list->next) + scan_prog_file (list->name, PASS_LIB); +} + +#endif /* LDD_SUFFIX */ +#endif /* SUNOS4_SHARED_LIBRARIES */ + +#endif /* OBJECT_FORMAT_NONE */ + + +/* + * COFF specific stuff. + */ + +#ifdef OBJECT_FORMAT_COFF + +#if defined(EXTENDED_COFF) +# define GCC_SYMBOLS(X) (SYMHEADER(X).isymMax + SYMHEADER(X).iextMax) +# define GCC_SYMENT SYMR +# define GCC_OK_SYMBOL(X) ((X).st == stProc && (X).sc == scText) +# define GCC_SYMINC(X) (1) +# define GCC_SYMZERO(X) (SYMHEADER(X).isymMax) +# define GCC_CHECK_HDR(X) (PSYMTAB(X) != 0) +#else +# define GCC_SYMBOLS(X) (HEADER(ldptr).f_nsyms) +# define GCC_SYMENT SYMENT +# define GCC_OK_SYMBOL(X) \ + (((X).n_sclass == C_EXT) && \ + (((X).n_type & N_TMASK) == (DT_NON << N_BTSHFT) || \ + ((X).n_type & N_TMASK) == (DT_FCN << N_BTSHFT))) +# define GCC_SYMINC(X) ((X).n_numaux+1) +# define GCC_SYMZERO(X) 0 +# define GCC_CHECK_HDR(X) (1) +#endif + +extern char *ldgetname (); + +/* COFF version to scan the name list of the loaded program for + the symbols g++ uses for static constructors and destructors. + + The constructor table begins at __CTOR_LIST__ and contains a count + of the number of pointers (or -1 if the constructors are built in a + separate section by the linker), followed by the pointers to the + constructor functions, terminated with a null pointer. The + destructor table has the same format, and begins at __DTOR_LIST__. */ + +static void +scan_prog_file (prog_name, which_pass) + char *prog_name; + enum pass which_pass; +{ + LDFILE *ldptr = NULL; + int sym_index, sym_count; + + if (which_pass != PASS_FIRST && which_pass != PASS_OBJ) + return; + + if ((ldptr = ldopen (prog_name, ldptr)) == NULL) + fatal ("%s: can't open as COFF file", prog_name); + + if (!MY_ISCOFF (HEADER (ldptr).f_magic)) + fatal ("%s: not a COFF file", prog_name); + + if (GCC_CHECK_HDR (ldptr)) + { + sym_count = GCC_SYMBOLS (ldptr); + sym_index = GCC_SYMZERO (ldptr); + while (sym_index < sym_count) + { + GCC_SYMENT symbol; + + if (ldtbread (ldptr, sym_index, &symbol) <= 0) + break; + sym_index += GCC_SYMINC (symbol); + + if (GCC_OK_SYMBOL (symbol)) + { + char *name; + + if ((name = ldgetname (ldptr, &symbol)) == NULL) + continue; /* should never happen */ + +#ifdef XCOFF_DEBUGGING_INFO + /* All AIX function names have a duplicate entry beginning + with a dot. */ + if (*name == '.') + ++name; +#endif + + switch (is_ctor_dtor (name)) + { + case 1: + add_to_list (&constructors, name); + if (which_pass == PASS_OBJ) + add_to_list (&exports, name); + break; + + case 2: + add_to_list (&destructors, name); + if (which_pass == PASS_OBJ) + add_to_list (&exports, name); + break; + + default: /* not a constructor or destructor */ + if (which_pass == PASS_OBJ && auto_export) + add_to_list (&exports, name); + continue; + } + +#if !defined(EXTENDED_COFF) + if (debug) + fprintf (stderr, "\tsec=%d class=%d type=%s%o %s\n", + symbol.n_scnum, symbol.n_sclass, + (symbol.n_type ? "0" : ""), symbol.n_type, + name); +#else + if (debug) + fprintf (stderr, "\tiss = %5d, value = %5d, index = %5d, name = %s\n", + symbol.iss, symbol.value, symbol.index, name); +#endif + } + } + } + + (void) ldclose(ldptr); +} + +#ifdef XCOFF_SCAN_LIBS +/* Scan imported AIX libraries for GCC static ctors and dtors. + FIXME: it is possible to link an executable without the actual import + library by using an "import file" - a text file listing symbols + exported by a library. To support this, we would have to scan + import files as well as actual shared binaries to find GCC ctors. + TODO: use memory mapping instead of 'ld' routines, files are already + memory mapped, but we could eliminate the extra in-memory copies. + Is it worth the effort? */ + +static void +scan_libraries (prog_name) + char *prog_name; +{ + LDFILE *ldptr; + SCNHDR ldsh; + static struct path_prefix libpath; /* we should only do this once */ + + if ((ldptr = ldopen (prog_name, ldptr)) == NULL) + fatal ("%s: can't open as COFF file", prog_name); + + if (!MY_ISCOFF (HEADER (ldptr).f_magic)) + fatal ("%s: not a COFF file", prog_name); + + /* find and read loader section */ + if (ldnshread (ldptr, _LOADER, &ldsh)) + { + LDHDR ldh; + char *impbuf; + int idx; + FSEEK (ldptr, ldsh.s_scnptr, BEGINNING); + FREAD (&ldh, sizeof ldh, 1, ldptr); + /* read import library list */ + impbuf = alloca (ldh.l_istlen); + FSEEK (ldptr, ldh.l_impoff + ldsh.s_scnptr, BEGINNING); + FREAD (impbuf, ldh.l_istlen, 1, ldptr); + idx = strlen (impbuf) + 1; + idx += strlen (impbuf+idx) + 1; + if (debug) + fprintf (stderr, "LIBPATH=%s\n", impbuf); + prefix_from_string (impbuf, &libpath); + while (idx < ldh.l_istlen) + { + char *implib = impbuf + idx; + char *impmem = implib + strlen (implib) + 1; + char *soname = 0; + LDFILE *libptr = NULL; + struct prefix_list *pl; + ARCHDR ah; + idx += strlen (implib) + 1; + if (!implib[0]) + continue; + idx += strlen (impmem) + 1; + if (*implib == '/') + { + if (access (soname, R_OK) == 0) + soname = implib; + } + else + { + char *temp = alloca (libpath.max_len + strlen (implib) + 1); + for (pl = libpath.plist; pl; pl = pl->next) + { + strcpy (temp, pl->prefix); + strcat (temp, implib); + if (access (temp, R_OK) == 0) + { + soname = temp; + break; + } + } + } + if (!soname) + { + fatal ("%s: library not found", implib); + continue; + } + if (debug) + { + if (impmem[0]) + fprintf (stderr, "%s (%s)\n", soname, impmem); + else + fprintf (stderr, "%s\n", soname); + } + ah.ar_name[0] = 0; + do + { + /* scan imported shared objects for GCC GLOBAL ctors */ + short type; + if ((libptr = ldopen (soname, libptr)) == NULL) + fatal ("%s: can't open import library", soname); + if (TYPE (libptr) == ARTYPE) + { + LDFILE *memptr; + if (!impmem[0]) + fatal ("%s: no archive member specified", soname); + ldahread (libptr, &ah); + if (strcmp (ah.ar_name, impmem)) + continue; + } + type = HEADER (libptr).f_magic; + if (HEADER (libptr).f_flags & F_SHROBJ) + { + SCNHDR soldsh; + LDHDR soldh; + long symcnt, i; + char *ldstrings; + LDSYM *lsyms; + if (!ldnshread (libptr, _LOADER, &soldsh)) + fatal ("%s: not an import library", soname); + FSEEK (libptr, soldsh.s_scnptr, BEGINNING); + if (FREAD (&soldh, sizeof soldh, 1, libptr) != 1) + fatal ("%s: can't read loader section", soname); + /*fprintf (stderr, "\tscanning %s\n", soname);*/ + symcnt = soldh.l_nsyms; + lsyms = (LDSYM*) alloca (symcnt * sizeof *lsyms); + symcnt = FREAD (lsyms, sizeof *lsyms, symcnt, libptr); + ldstrings = alloca (soldh.l_stlen); + FSEEK (libptr, soldsh.s_scnptr+soldh.l_stoff, BEGINNING); + FREAD (ldstrings, soldh.l_stlen, 1, libptr); + for (i = 0; i < symcnt; ++i) + { + LDSYM *l = lsyms + i; + if (LDR_EXPORT (*l)) + { + char *expname = 0; + if (l->l_zeroes) + expname = l->l_name; + else if (l->l_offset < soldh.l_stlen) + expname = ldstrings + l->l_offset; + switch (is_ctor_dtor (expname)) + { + case 3: + if (debug) + fprintf (stderr, "\t%s\n", expname); + add_to_list (&constructors, expname); + break; + + case 4: + add_to_list (&destructors, expname); + break; + + default: /* not a constructor or destructor */ + continue; + } + } + } + } + else + fprintf (stderr, "%s: type = %04X flags = %04X\n", + ah.ar_name, type, HEADER (libptr).f_flags); + } + while (ldclose (libptr) == FAILURE); + /* printf (stderr, "closed %s\n", soname); */ + } + } +} +#endif /* XCOFF_SCAN_LIBS */ + +#endif /* OBJECT_FORMAT_COFF */ + + +/* + * OSF/rose specific stuff. + */ + +#ifdef OBJECT_FORMAT_ROSE + +/* Union of the various load commands */ + +typedef union load_union +{ + ldc_header_t hdr; /* common header */ + load_cmd_map_command_t map; /* map indexing other load cmds */ + interpreter_command_t iprtr; /* interpreter pathname */ + strings_command_t str; /* load commands strings section */ + region_command_t region; /* region load command */ + reloc_command_t reloc; /* relocation section */ + package_command_t pkg; /* package load command */ + symbols_command_t sym; /* symbol sections */ + entry_command_t ent; /* program start section */ + gen_info_command_t info; /* object information */ + func_table_command_t func; /* function constructors/destructors */ +} load_union_t; + +/* Structure to point to load command and data section in memory. */ + +typedef struct load_all +{ + load_union_t *load; /* load command */ + char *section; /* pointer to section */ +} load_all_t; + +/* Structure to contain information about a file mapped into memory. */ + +struct file_info +{ + char *start; /* start of map */ + char *name; /* filename */ + long size; /* size of the file */ + long rounded_size; /* size rounded to page boundary */ + int fd; /* file descriptor */ + int rw; /* != 0 if opened read/write */ + int use_mmap; /* != 0 if mmap'ed */ +}; + +extern int decode_mach_o_hdr (); +extern int encode_mach_o_hdr (); + +static void add_func_table PROTO((mo_header_t *, load_all_t *, + symbol_info_t *, int)); +static void print_header PROTO((mo_header_t *)); +static void print_load_command PROTO((load_union_t*, size_t, int)); +static void bad_header PROTO((int)); +static struct file_info *read_file PROTO((char *, int, int)); +static void end_file PROTO((struct file_info *)); + +/* OSF/rose specific version to scan the name list of the loaded + program for the symbols g++ uses for static constructors and + destructors. + + The constructor table begins at __CTOR_LIST__ and contains a count + of the number of pointers (or -1 if the constructors are built in a + separate section by the linker), followed by the pointers to the + constructor functions, terminated with a null pointer. The + destructor table has the same format, and begins at __DTOR_LIST__. */ + +static void +scan_prog_file (prog_name, which_pass) + char *prog_name; + enum pass which_pass; +{ + char *obj; + mo_header_t hdr; + load_all_t *load_array; + load_all_t *load_end; + load_all_t *load_cmd; + int symbol_load_cmds; + off_t offset; + int i; + int num_syms; + int status; + char *str_sect; + struct file_info *obj_file; + int prog_fd; + mo_lcid_t cmd_strings = -1; + symbol_info_t *main_sym = 0; + int rw = (which_pass != PASS_FIRST); + + prog_fd = open (prog_name, (rw) ? O_RDWR : O_RDONLY); + if (prog_fd < 0) + fatal_perror ("can't read %s", prog_name); + + obj_file = read_file (prog_name, prog_fd, rw); + obj = obj_file->start; + + status = decode_mach_o_hdr (obj, MO_SIZEOF_RAW_HDR, MOH_HEADER_VERSION, &hdr); + if (status != MO_HDR_CONV_SUCCESS) + bad_header (status); + + + /* Do some basic sanity checks. Note we explicitly use the big endian magic number, + since the hardware will automatically swap bytes for us on loading little endian + integers. */ + +#ifndef CROSS_COMPILE + if (hdr.moh_magic != MOH_MAGIC_MSB + || hdr.moh_header_version != MOH_HEADER_VERSION + || hdr.moh_byte_order != OUR_BYTE_ORDER + || hdr.moh_data_rep_id != OUR_DATA_REP_ID + || hdr.moh_cpu_type != OUR_CPU_TYPE + || hdr.moh_cpu_subtype != OUR_CPU_SUBTYPE + || hdr.moh_vendor_type != OUR_VENDOR_TYPE) + { + fatal ("incompatibilities between object file & expected values"); + } +#endif + + if (debug) + print_header (&hdr); + + offset = hdr.moh_first_cmd_off; + load_end = load_array + = (load_all_t *) xcalloc (sizeof (load_all_t), hdr.moh_n_load_cmds + 2); + + /* Build array of load commands, calculating the offsets */ + for (i = 0; i < hdr.moh_n_load_cmds; i++) + { + load_union_t *load_hdr; /* load command header */ + + load_cmd = load_end++; + load_hdr = (load_union_t *) (obj + offset); + + /* If modifying the program file, copy the header. */ + if (rw) + { + load_union_t *ptr = (load_union_t *) xmalloc (load_hdr->hdr.ldci_cmd_size); + bcopy ((char *)load_hdr, (char *)ptr, load_hdr->hdr.ldci_cmd_size); + load_hdr = ptr; + + /* null out old command map, because we will rewrite at the end. */ + if (ptr->hdr.ldci_cmd_type == LDC_CMD_MAP) + { + cmd_strings = ptr->map.lcm_ld_cmd_strings; + ptr->hdr.ldci_cmd_type = LDC_UNDEFINED; + } + } + + load_cmd->load = load_hdr; + if (load_hdr->hdr.ldci_section_off > 0) + load_cmd->section = obj + load_hdr->hdr.ldci_section_off; + + if (debug) + print_load_command (load_hdr, offset, i); + + offset += load_hdr->hdr.ldci_cmd_size; + } + + /* If the last command is the load command map and is not undefined, + decrement the count of load commands. */ + if (rw && load_end[-1].load->hdr.ldci_cmd_type == LDC_UNDEFINED) + { + load_end--; + hdr.moh_n_load_cmds--; + } + + /* Go through and process each symbol table section. */ + symbol_load_cmds = 0; + for (load_cmd = load_array; load_cmd < load_end; load_cmd++) + { + load_union_t *load_hdr = load_cmd->load; + + if (load_hdr->hdr.ldci_cmd_type == LDC_SYMBOLS) + { + symbol_load_cmds++; + + if (debug) + { + char *kind = "unknown"; + + switch (load_hdr->sym.symc_kind) + { + case SYMC_IMPORTS: kind = "imports"; break; + case SYMC_DEFINED_SYMBOLS: kind = "defined"; break; + case SYMC_STABS: kind = "stabs"; break; + } + + fprintf (stderr, "\nProcessing symbol table #%d, offset = 0x%.8lx, kind = %s\n", + symbol_load_cmds, load_hdr->hdr.ldci_section_off, kind); + } + + if (load_hdr->sym.symc_kind != SYMC_DEFINED_SYMBOLS) + continue; + + str_sect = load_array[load_hdr->sym.symc_strings_section].section; + if (str_sect == (char *)0) + fatal ("string section missing"); + + if (load_cmd->section == (char *)0) + fatal ("section pointer missing"); + + num_syms = load_hdr->sym.symc_nentries; + for (i = 0; i < num_syms; i++) + { + symbol_info_t *sym = ((symbol_info_t *) load_cmd->section) + i; + char *name = sym->si_name.symbol_name + str_sect; + + if (name[0] != '_') + continue; + + if (rw) + { + char *n = name + strlen (name) - strlen (NAME__MAIN); + + if ((n - name) < 0 || strcmp (n, NAME__MAIN)) + continue; + while (n != name) + if (*--n != '_') + continue; + + main_sym = sym; + } + else + { + switch (is_ctor_dtor (name)) + { + case 1: + add_to_list (&constructors, name); + break; + + case 2: + add_to_list (&destructors, name); + break; + + default: /* not a constructor or destructor */ + continue; + } + } + + if (debug) + fprintf (stderr, "\ttype = 0x%.4x, sc = 0x%.2x, flags = 0x%.8x, name = %.30s\n", + sym->si_type, sym->si_sc_type, sym->si_flags, name); + } + } + } + + if (symbol_load_cmds == 0) + fatal ("no symbol table found"); + + /* Update the program file now, rewrite header and load commands. At present, + we assume that there is enough space after the last load command to insert + one more. Since the first section written out is page aligned, and the + number of load commands is small, this is ok for the present. */ + + if (rw) + { + load_union_t *load_map; + size_t size; + + if (cmd_strings == -1) + fatal ("no cmd_strings found"); + + /* Add __main to initializer list. + If we are building a program instead of a shared library, don't + do anything, since in the current version, you cannot do mallocs + and such in the constructors. */ + + if (main_sym != (symbol_info_t *)0 + && ((hdr.moh_flags & MOH_EXECABLE_F) == 0)) + add_func_table (&hdr, load_array, main_sym, FNTC_INITIALIZATION); + + if (debug) + fprintf (stderr, "\nUpdating header and load commands.\n\n"); + + hdr.moh_n_load_cmds++; + size = sizeof (load_cmd_map_command_t) + (sizeof (mo_offset_t) * (hdr.moh_n_load_cmds - 1)); + + /* Create new load command map. */ + if (debug) + fprintf (stderr, "load command map, %d cmds, new size %ld.\n", + (int)hdr.moh_n_load_cmds, (long)size); + + load_map = (load_union_t *) xcalloc (1, size); + load_map->map.ldc_header.ldci_cmd_type = LDC_CMD_MAP; + load_map->map.ldc_header.ldci_cmd_size = size; + load_map->map.lcm_ld_cmd_strings = cmd_strings; + load_map->map.lcm_nentries = hdr.moh_n_load_cmds; + load_array[hdr.moh_n_load_cmds-1].load = load_map; + + offset = hdr.moh_first_cmd_off; + for (i = 0; i < hdr.moh_n_load_cmds; i++) + { + load_map->map.lcm_map[i] = offset; + if (load_array[i].load->hdr.ldci_cmd_type == LDC_CMD_MAP) + hdr.moh_load_map_cmd_off = offset; + + offset += load_array[i].load->hdr.ldci_cmd_size; + } + + hdr.moh_sizeofcmds = offset - MO_SIZEOF_RAW_HDR; + + if (debug) + print_header (&hdr); + + /* Write header */ + status = encode_mach_o_hdr (&hdr, obj, MO_SIZEOF_RAW_HDR); + if (status != MO_HDR_CONV_SUCCESS) + bad_header (status); + + if (debug) + fprintf (stderr, "writing load commands.\n\n"); + + /* Write load commands */ + offset = hdr.moh_first_cmd_off; + for (i = 0; i < hdr.moh_n_load_cmds; i++) + { + load_union_t *load_hdr = load_array[i].load; + size_t size = load_hdr->hdr.ldci_cmd_size; + + if (debug) + print_load_command (load_hdr, offset, i); + + bcopy ((char *)load_hdr, (char *)(obj + offset), size); + offset += size; + } + } + + end_file (obj_file); + + if (close (prog_fd)) + fatal_perror ("closing %s", prog_name); + + if (debug) + fprintf (stderr, "\n"); +} + + +/* Add a function table to the load commands to call a function + on initiation or termination of the process. */ + +static void +add_func_table (hdr_p, load_array, sym, type) + mo_header_t *hdr_p; /* pointer to global header */ + load_all_t *load_array; /* array of ptrs to load cmds */ + symbol_info_t *sym; /* pointer to symbol entry */ + int type; /* fntc_type value */ +{ + /* Add a new load command. */ + int num_cmds = ++hdr_p->moh_n_load_cmds; + int load_index = num_cmds - 1; + size_t size = sizeof (func_table_command_t) + sizeof (mo_addr_t); + load_union_t *ptr = xcalloc (1, size); + load_all_t *load_cmd; + int i; + + /* Set the unresolved address bit in the header to force the loader to be + used, since kernel exec does not call the initialization functions. */ + hdr_p->moh_flags |= MOH_UNRESOLVED_F; + + load_cmd = &load_array[load_index]; + load_cmd->load = ptr; + load_cmd->section = (char *)0; + + /* Fill in func table load command. */ + ptr->func.ldc_header.ldci_cmd_type = LDC_FUNC_TABLE; + ptr->func.ldc_header.ldci_cmd_size = size; + ptr->func.ldc_header.ldci_section_off = 0; + ptr->func.ldc_header.ldci_section_len = 0; + ptr->func.fntc_type = type; + ptr->func.fntc_nentries = 1; + + /* copy address, turn it from abs. address to (region,offset) if necessary. */ + /* Is the symbol already expressed as (region, offset)? */ + if ((sym->si_flags & SI_ABSOLUTE_VALUE_F) == 0) + { + ptr->func.fntc_entry_loc[i].adr_lcid = sym->si_value.def_val.adr_lcid; + ptr->func.fntc_entry_loc[i].adr_sctoff = sym->si_value.def_val.adr_sctoff; + } + + /* If not, figure out which region it's in. */ + else + { + mo_vm_addr_t addr = sym->si_value.abs_val; + int found = 0; + + for (i = 0; i < load_index; i++) + { + if (load_array[i].load->hdr.ldci_cmd_type == LDC_REGION) + { + region_command_t *region_ptr = &load_array[i].load->region; + + if ((region_ptr->regc_flags & REG_ABS_ADDR_F) != 0 + && addr >= region_ptr->regc_addr.vm_addr + && addr <= region_ptr->regc_addr.vm_addr + region_ptr->regc_vm_size) + { + ptr->func.fntc_entry_loc[0].adr_lcid = i; + ptr->func.fntc_entry_loc[0].adr_sctoff = addr - region_ptr->regc_addr.vm_addr; + found++; + break; + } + } + } + + if (!found) + fatal ("could not convert 0x%l.8x into a region", addr); + } + + if (debug) + fprintf (stderr, + "%s function, region %d, offset = %ld (0x%.8lx)\n", + (type == FNTC_INITIALIZATION) ? "init" : "term", + (int)ptr->func.fntc_entry_loc[i].adr_lcid, + (long)ptr->func.fntc_entry_loc[i].adr_sctoff, + (long)ptr->func.fntc_entry_loc[i].adr_sctoff); + +} + + +/* Print the global header for an OSF/rose object. */ + +static void +print_header (hdr_ptr) + mo_header_t *hdr_ptr; +{ + fprintf (stderr, "\nglobal header:\n"); + fprintf (stderr, "\tmoh_magic = 0x%.8lx\n", hdr_ptr->moh_magic); + fprintf (stderr, "\tmoh_major_version = %d\n", (int)hdr_ptr->moh_major_version); + fprintf (stderr, "\tmoh_minor_version = %d\n", (int)hdr_ptr->moh_minor_version); + fprintf (stderr, "\tmoh_header_version = %d\n", (int)hdr_ptr->moh_header_version); + fprintf (stderr, "\tmoh_max_page_size = %d\n", (int)hdr_ptr->moh_max_page_size); + fprintf (stderr, "\tmoh_byte_order = %d\n", (int)hdr_ptr->moh_byte_order); + fprintf (stderr, "\tmoh_data_rep_id = %d\n", (int)hdr_ptr->moh_data_rep_id); + fprintf (stderr, "\tmoh_cpu_type = %d\n", (int)hdr_ptr->moh_cpu_type); + fprintf (stderr, "\tmoh_cpu_subtype = %d\n", (int)hdr_ptr->moh_cpu_subtype); + fprintf (stderr, "\tmoh_vendor_type = %d\n", (int)hdr_ptr->moh_vendor_type); + fprintf (stderr, "\tmoh_load_map_cmd_off = %d\n", (int)hdr_ptr->moh_load_map_cmd_off); + fprintf (stderr, "\tmoh_first_cmd_off = %d\n", (int)hdr_ptr->moh_first_cmd_off); + fprintf (stderr, "\tmoh_sizeofcmds = %d\n", (int)hdr_ptr->moh_sizeofcmds); + fprintf (stderr, "\tmon_n_load_cmds = %d\n", (int)hdr_ptr->moh_n_load_cmds); + fprintf (stderr, "\tmoh_flags = 0x%.8lx", (long)hdr_ptr->moh_flags); + + if (hdr_ptr->moh_flags & MOH_RELOCATABLE_F) + fprintf (stderr, ", relocatable"); + + if (hdr_ptr->moh_flags & MOH_LINKABLE_F) + fprintf (stderr, ", linkable"); + + if (hdr_ptr->moh_flags & MOH_EXECABLE_F) + fprintf (stderr, ", execable"); + + if (hdr_ptr->moh_flags & MOH_EXECUTABLE_F) + fprintf (stderr, ", executable"); + + if (hdr_ptr->moh_flags & MOH_UNRESOLVED_F) + fprintf (stderr, ", unresolved"); + + fprintf (stderr, "\n\n"); + return; +} + + +/* Print a short summary of a load command. */ + +static void +print_load_command (load_hdr, offset, number) + load_union_t *load_hdr; + size_t offset; + int number; +{ + mo_long_t type = load_hdr->hdr.ldci_cmd_type; + char *type_str = (char *)0; + + switch (type) + { + case LDC_UNDEFINED: type_str = "UNDEFINED"; break; + case LDC_CMD_MAP: type_str = "CMD_MAP"; break; + case LDC_INTERPRETER: type_str = "INTERPRETER"; break; + case LDC_STRINGS: type_str = "STRINGS"; break; + case LDC_REGION: type_str = "REGION"; break; + case LDC_RELOC: type_str = "RELOC"; break; + case LDC_PACKAGE: type_str = "PACKAGE"; break; + case LDC_SYMBOLS: type_str = "SYMBOLS"; break; + case LDC_ENTRY: type_str = "ENTRY"; break; + case LDC_FUNC_TABLE: type_str = "FUNC_TABLE"; break; + case LDC_GEN_INFO: type_str = "GEN_INFO"; break; + } + + fprintf (stderr, + "cmd %2d, sz: 0x%.2lx, coff: 0x%.3lx, doff: 0x%.6lx, dlen: 0x%.6lx", + number, + (long) load_hdr->hdr.ldci_cmd_size, + (long) offset, + (long) load_hdr->hdr.ldci_section_off, + (long) load_hdr->hdr.ldci_section_len); + + if (type_str == (char *)0) + fprintf (stderr, ", ty: unknown (%ld)\n", (long) type); + + else if (type != LDC_REGION) + fprintf (stderr, ", ty: %s\n", type_str); + + else + { + char *region = ""; + switch (load_hdr->region.regc_usage_type) + { + case REG_TEXT_T: region = ", .text"; break; + case REG_DATA_T: region = ", .data"; break; + case REG_BSS_T: region = ", .bss"; break; + case REG_GLUE_T: region = ", .glue"; break; +#if defined (REG_RDATA_T) && defined (REG_SDATA_T) && defined (REG_SBSS_T) /*mips*/ + case REG_RDATA_T: region = ", .rdata"; break; + case REG_SDATA_T: region = ", .sdata"; break; + case REG_SBSS_T: region = ", .sbss"; break; +#endif + } + + fprintf (stderr, ", ty: %s, vaddr: 0x%.8lx, vlen: 0x%.6lx%s\n", + type_str, + (long) load_hdr->region.regc_vm_addr, + (long) load_hdr->region.regc_vm_size, + region); + } + + return; +} + + +/* Fatal error when {en,de}code_mach_o_header fails. */ + +static void +bad_header (status) + int status; +{ + char *msg = (char *)0; + + switch (status) + { + case MO_ERROR_BAD_MAGIC: msg = "bad magic number"; break; + case MO_ERROR_BAD_HDR_VERS: msg = "bad header version"; break; + case MO_ERROR_BAD_RAW_HDR_VERS: msg = "bad raw header version"; break; + case MO_ERROR_BUF2SML: msg = "raw header buffer too small"; break; + case MO_ERROR_OLD_RAW_HDR_FILE: msg = "old raw header file"; break; + case MO_ERROR_UNSUPPORTED_VERS: msg = "unsupported version"; break; + } + + if (msg == (char *)0) + fatal ("unknown {de,en}code_mach_o_hdr return value %d", status); + else + fatal ("%s", msg); +} + + +/* Read a file into a memory buffer. */ + +static struct file_info * +read_file (name, fd, rw) + char *name; /* filename */ + int fd; /* file descriptor */ + int rw; /* read/write */ +{ + struct stat stat_pkt; + struct file_info *p = (struct file_info *) xcalloc (sizeof (struct file_info), 1); +#ifdef USE_MMAP + static int page_size; +#endif + + if (fstat (fd, &stat_pkt) < 0) + fatal_perror ("fstat %s", name); + + p->name = name; + p->size = stat_pkt.st_size; + p->rounded_size = stat_pkt.st_size; + p->fd = fd; + p->rw = rw; + +#ifdef USE_MMAP + if (debug) + fprintf (stderr, "mmap %s, %s\n", name, (rw) ? "read/write" : "read-only"); + + if (page_size == 0) + page_size = sysconf (_SC_PAGE_SIZE); + + p->rounded_size = ((p->size + page_size - 1) / page_size) * page_size; + p->start = mmap ((caddr_t)0, + (rw) ? p->rounded_size : p->size, + (rw) ? (PROT_READ | PROT_WRITE) : PROT_READ, + MAP_FILE | MAP_VARIABLE | MAP_SHARED, + fd, + 0L); + + if (p->start != (char *)0 && p->start != (char *)-1) + p->use_mmap = 1; + + else +#endif /* USE_MMAP */ + { + long len; + + if (debug) + fprintf (stderr, "read %s\n", name); + + p->use_mmap = 0; + p->start = xmalloc (p->size); + if (lseek (fd, 0L, SEEK_SET) < 0) + fatal_perror ("lseek to 0 on %s", name); + + len = read (fd, p->start, p->size); + if (len < 0) + fatal_perror ("read %s", name); + + if (len != p->size) + fatal ("read %ld bytes, expected %ld, from %s", len, p->size, name); + } + + return p; +} + +/* Do anything necessary to write a file back from memory. */ + +static void +end_file (ptr) + struct file_info *ptr; /* file information block */ +{ +#ifdef USE_MMAP + if (ptr->use_mmap) + { + if (ptr->rw) + { + if (debug) + fprintf (stderr, "msync %s\n", ptr->name); + + if (msync (ptr->start, ptr->rounded_size, MS_ASYNC)) + fatal_perror ("msync %s", ptr->name); + } + + if (debug) + fprintf (stderr, "munmap %s\n", ptr->name); + + if (munmap (ptr->start, ptr->size)) + fatal_perror ("munmap %s", ptr->name); + } + else +#endif /* USE_MMAP */ + { + if (ptr->rw) + { + long len; + + if (debug) + fprintf (stderr, "write %s\n", ptr->name); + + if (lseek (ptr->fd, 0L, SEEK_SET) < 0) + fatal_perror ("lseek to 0 on %s", ptr->name); + + len = write (ptr->fd, ptr->start, ptr->size); + if (len < 0) + fatal_perror ("write %s", ptr->name); + + if (len != ptr->size) + fatal ("wrote %ld bytes, expected %ld, to %s", len, ptr->size, ptr->name); + } + + free (ptr->start); + } + + free (ptr); +} + +#endif /* OBJECT_FORMAT_ROSE */ diff --git a/contrib/gcc/combine.c b/contrib/gcc/combine.c new file mode 100644 index 00000000000..473adc83460 --- /dev/null +++ b/contrib/gcc/combine.c @@ -0,0 +1,11103 @@ +/* Optimize by combining instructions for GNU compiler. + Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This module is essentially the "combiner" phase of the U. of Arizona + Portable Optimizer, but redone to work on our list-structured + representation for RTL instead of their string representation. + + The LOG_LINKS of each insn identify the most recent assignment + to each REG used in the insn. It is a list of previous insns, + each of which contains a SET for a REG that is used in this insn + and not used or set in between. LOG_LINKs never cross basic blocks. + They were set up by the preceding pass (lifetime analysis). + + We try to combine each pair of insns joined by a logical link. + We also try to combine triples of insns A, B and C when + C has a link back to B and B has a link back to A. + + LOG_LINKS does not have links for use of the CC0. They don't + need to, because the insn that sets the CC0 is always immediately + before the insn that tests it. So we always regard a branch + insn as having a logical link to the preceding insn. The same is true + for an insn explicitly using CC0. + + We check (with use_crosses_set_p) to avoid combining in such a way + as to move a computation to a place where its value would be different. + + Combination is done by mathematically substituting the previous + insn(s) values for the regs they set into the expressions in + the later insns that refer to these regs. If the result is a valid insn + for our target machine, according to the machine description, + we install it, delete the earlier insns, and update the data flow + information (LOG_LINKS and REG_NOTES) for what we did. + + There are a few exceptions where the dataflow information created by + flow.c aren't completely updated: + + - reg_live_length is not updated + - reg_n_refs is not adjusted in the rare case when a register is + no longer required in a computation + - there are extremely rare cases (see distribute_regnotes) when a + REG_DEAD note is lost + - a LOG_LINKS entry that refers to an insn with multiple SETs may be + removed because there is no way to know which register it was + linking + + To simplify substitution, we combine only when the earlier insn(s) + consist of only a single assignment. To simplify updating afterward, + we never combine when a subroutine call appears in the middle. + + Since we do not represent assignments to CC0 explicitly except when that + is all an insn does, there is no LOG_LINKS entry in an insn that uses + the condition code for the insn that set the condition code. + Fortunately, these two insns must be consecutive. + Therefore, every JUMP_INSN is taken to have an implicit logical link + to the preceding insn. This is not quite right, since non-jumps can + also use the condition code; but in practice such insns would not + combine anyway. */ + +#include "config.h" +#ifdef __STDC__ +#include +#else +#include +#endif + +/* Must precede rtl.h for FFS. */ +#include + +#include "rtl.h" +#include "flags.h" +#include "regs.h" +#include "hard-reg-set.h" +#include "expr.h" +#include "basic-block.h" +#include "insn-config.h" +#include "insn-flags.h" +#include "insn-codes.h" +#include "insn-attr.h" +#include "recog.h" +#include "real.h" + +/* It is not safe to use ordinary gen_lowpart in combine. + Use gen_lowpart_for_combine instead. See comments there. */ +#define gen_lowpart dont_use_gen_lowpart_you_dummy + +/* Number of attempts to combine instructions in this function. */ + +static int combine_attempts; + +/* Number of attempts that got as far as substitution in this function. */ + +static int combine_merges; + +/* Number of instructions combined with added SETs in this function. */ + +static int combine_extras; + +/* Number of instructions combined in this function. */ + +static int combine_successes; + +/* Totals over entire compilation. */ + +static int total_attempts, total_merges, total_extras, total_successes; + +/* Define a default value for REVERSIBLE_CC_MODE. + We can never assume that a condition code mode is safe to reverse unless + the md tells us so. */ +#ifndef REVERSIBLE_CC_MODE +#define REVERSIBLE_CC_MODE(MODE) 0 +#endif + +/* Vector mapping INSN_UIDs to cuids. + The cuids are like uids but increase monotonically always. + Combine always uses cuids so that it can compare them. + But actually renumbering the uids, which we used to do, + proves to be a bad idea because it makes it hard to compare + the dumps produced by earlier passes with those from later passes. */ + +static int *uid_cuid; +static int max_uid_cuid; + +/* Get the cuid of an insn. */ + +#define INSN_CUID(INSN) (INSN_UID (INSN) > max_uid_cuid \ + ? (abort(), 0) \ + : uid_cuid[INSN_UID (INSN)]) + +/* Maximum register number, which is the size of the tables below. */ + +static int combine_max_regno; + +/* Record last point of death of (hard or pseudo) register n. */ + +static rtx *reg_last_death; + +/* Record last point of modification of (hard or pseudo) register n. */ + +static rtx *reg_last_set; + +/* Record the cuid of the last insn that invalidated memory + (anything that writes memory, and subroutine calls, but not pushes). */ + +static int mem_last_set; + +/* Record the cuid of the last CALL_INSN + so we can tell whether a potential combination crosses any calls. */ + +static int last_call_cuid; + +/* When `subst' is called, this is the insn that is being modified + (by combining in a previous insn). The PATTERN of this insn + is still the old pattern partially modified and it should not be + looked at, but this may be used to examine the successors of the insn + to judge whether a simplification is valid. */ + +static rtx subst_insn; + +/* This is an insn that belongs before subst_insn, but is not currently + on the insn chain. */ + +static rtx subst_prev_insn; + +/* This is the lowest CUID that `subst' is currently dealing with. + get_last_value will not return a value if the register was set at or + after this CUID. If not for this mechanism, we could get confused if + I2 or I1 in try_combine were an insn that used the old value of a register + to obtain a new value. In that case, we might erroneously get the + new value of the register when we wanted the old one. */ + +static int subst_low_cuid; + +/* This contains any hard registers that are used in newpat; reg_dead_at_p + must consider all these registers to be always live. */ + +static HARD_REG_SET newpat_used_regs; + +/* This is an insn to which a LOG_LINKS entry has been added. If this + insn is the earlier than I2 or I3, combine should rescan starting at + that location. */ + +static rtx added_links_insn; + +/* This is the value of undobuf.num_undo when we started processing this + substitution. This will prevent gen_rtx_combine from re-used a piece + from the previous expression. Doing so can produce circular rtl + structures. */ + +static int previous_num_undos; + +/* Basic block number of the block in which we are performing combines. */ +static int this_basic_block; + +/* The next group of arrays allows the recording of the last value assigned + to (hard or pseudo) register n. We use this information to see if a + operation being processed is redundant given a prior operation performed + on the register. For example, an `and' with a constant is redundant if + all the zero bits are already known to be turned off. + + We use an approach similar to that used by cse, but change it in the + following ways: + + (1) We do not want to reinitialize at each label. + (2) It is useful, but not critical, to know the actual value assigned + to a register. Often just its form is helpful. + + Therefore, we maintain the following arrays: + + reg_last_set_value the last value assigned + reg_last_set_label records the value of label_tick when the + register was assigned + reg_last_set_table_tick records the value of label_tick when a + value using the register is assigned + reg_last_set_invalid set to non-zero when it is not valid + to use the value of this register in some + register's value + + To understand the usage of these tables, it is important to understand + the distinction between the value in reg_last_set_value being valid + and the register being validly contained in some other expression in the + table. + + Entry I in reg_last_set_value is valid if it is non-zero, and either + reg_n_sets[i] is 1 or reg_last_set_label[i] == label_tick. + + Register I may validly appear in any expression returned for the value + of another register if reg_n_sets[i] is 1. It may also appear in the + value for register J if reg_last_set_label[i] < reg_last_set_label[j] or + reg_last_set_invalid[j] is zero. + + If an expression is found in the table containing a register which may + not validly appear in an expression, the register is replaced by + something that won't match, (clobber (const_int 0)). + + reg_last_set_invalid[i] is set non-zero when register I is being assigned + to and reg_last_set_table_tick[i] == label_tick. */ + +/* Record last value assigned to (hard or pseudo) register n. */ + +static rtx *reg_last_set_value; + +/* Record the value of label_tick when the value for register n is placed in + reg_last_set_value[n]. */ + +static int *reg_last_set_label; + +/* Record the value of label_tick when an expression involving register n + is placed in reg_last_set_value. */ + +static int *reg_last_set_table_tick; + +/* Set non-zero if references to register n in expressions should not be + used. */ + +static char *reg_last_set_invalid; + +/* Incremented for each label. */ + +static int label_tick; + +/* Some registers that are set more than once and used in more than one + basic block are nevertheless always set in similar ways. For example, + a QImode register may be loaded from memory in two places on a machine + where byte loads zero extend. + + We record in the following array what we know about the nonzero + bits of a register, specifically which bits are known to be zero. + + If an entry is zero, it means that we don't know anything special. */ + +static unsigned HOST_WIDE_INT *reg_nonzero_bits; + +/* Mode used to compute significance in reg_nonzero_bits. It is the largest + integer mode that can fit in HOST_BITS_PER_WIDE_INT. */ + +static enum machine_mode nonzero_bits_mode; + +/* Nonzero if we know that a register has some leading bits that are always + equal to the sign bit. */ + +static char *reg_sign_bit_copies; + +/* Nonzero when reg_nonzero_bits and reg_sign_bit_copies can be safely used. + It is zero while computing them and after combine has completed. This + former test prevents propagating values based on previously set values, + which can be incorrect if a variable is modified in a loop. */ + +static int nonzero_sign_valid; + +/* These arrays are maintained in parallel with reg_last_set_value + and are used to store the mode in which the register was last set, + the bits that were known to be zero when it was last set, and the + number of sign bits copies it was known to have when it was last set. */ + +static enum machine_mode *reg_last_set_mode; +static unsigned HOST_WIDE_INT *reg_last_set_nonzero_bits; +static char *reg_last_set_sign_bit_copies; + +/* Record one modification to rtl structure + to be undone by storing old_contents into *where. + is_int is 1 if the contents are an int. */ + +struct undo +{ + int is_int; + union {rtx r; int i;} old_contents; + union {rtx *r; int *i;} where; +}; + +/* Record a bunch of changes to be undone, up to MAX_UNDO of them. + num_undo says how many are currently recorded. + + storage is nonzero if we must undo the allocation of new storage. + The value of storage is what to pass to obfree. + + other_insn is nonzero if we have modified some other insn in the process + of working on subst_insn. It must be verified too. */ + +#define MAX_UNDO 50 + +struct undobuf +{ + int num_undo; + char *storage; + struct undo undo[MAX_UNDO]; + rtx other_insn; +}; + +static struct undobuf undobuf; + +/* Substitute NEWVAL, an rtx expression, into INTO, a place in some + insn. The substitution can be undone by undo_all. If INTO is already + set to NEWVAL, do not record this change. Because computing NEWVAL might + also call SUBST, we have to compute it before we put anything into + the undo table. */ + +#define SUBST(INTO, NEWVAL) \ + do { rtx _new = (NEWVAL); \ + if (undobuf.num_undo < MAX_UNDO) \ + { \ + undobuf.undo[undobuf.num_undo].is_int = 0; \ + undobuf.undo[undobuf.num_undo].where.r = &INTO; \ + undobuf.undo[undobuf.num_undo].old_contents.r = INTO; \ + INTO = _new; \ + if (undobuf.undo[undobuf.num_undo].old_contents.r != INTO) \ + undobuf.num_undo++; \ + } \ + } while (0) + +/* Similar to SUBST, but NEWVAL is an int. INTO will normally be an XINT + expression. + Note that substitution for the value of a CONST_INT is not safe. */ + +#define SUBST_INT(INTO, NEWVAL) \ + do { if (undobuf.num_undo < MAX_UNDO) \ +{ \ + undobuf.undo[undobuf.num_undo].is_int = 1; \ + undobuf.undo[undobuf.num_undo].where.i = (int *) &INTO; \ + undobuf.undo[undobuf.num_undo].old_contents.i = INTO; \ + INTO = NEWVAL; \ + if (undobuf.undo[undobuf.num_undo].old_contents.i != INTO) \ + undobuf.num_undo++; \ + } \ + } while (0) + +/* Number of times the pseudo being substituted for + was found and replaced. */ + +static int n_occurrences; + +static void init_reg_last_arrays PROTO(()); +static void setup_incoming_promotions PROTO(()); +static void set_nonzero_bits_and_sign_copies PROTO((rtx, rtx)); +static int can_combine_p PROTO((rtx, rtx, rtx, rtx, rtx *, rtx *)); +static int combinable_i3pat PROTO((rtx, rtx *, rtx, rtx, int, rtx *)); +static rtx try_combine PROTO((rtx, rtx, rtx)); +static void undo_all PROTO((void)); +static rtx *find_split_point PROTO((rtx *, rtx)); +static rtx subst PROTO((rtx, rtx, rtx, int, int)); +static rtx simplify_rtx PROTO((rtx, enum machine_mode, int, int)); +static rtx simplify_if_then_else PROTO((rtx)); +static rtx simplify_set PROTO((rtx)); +static rtx simplify_logical PROTO((rtx, int)); +static rtx expand_compound_operation PROTO((rtx)); +static rtx expand_field_assignment PROTO((rtx)); +static rtx make_extraction PROTO((enum machine_mode, rtx, int, rtx, int, + int, int, int)); +static rtx extract_left_shift PROTO((rtx, int)); +static rtx make_compound_operation PROTO((rtx, enum rtx_code)); +static int get_pos_from_mask PROTO((unsigned HOST_WIDE_INT, int *)); +static rtx force_to_mode PROTO((rtx, enum machine_mode, + unsigned HOST_WIDE_INT, rtx, int)); +static rtx if_then_else_cond PROTO((rtx, rtx *, rtx *)); +static rtx known_cond PROTO((rtx, enum rtx_code, rtx, rtx)); +static rtx make_field_assignment PROTO((rtx)); +static rtx apply_distributive_law PROTO((rtx)); +static rtx simplify_and_const_int PROTO((rtx, enum machine_mode, rtx, + unsigned HOST_WIDE_INT)); +static unsigned HOST_WIDE_INT nonzero_bits PROTO((rtx, enum machine_mode)); +static int num_sign_bit_copies PROTO((rtx, enum machine_mode)); +static int merge_outer_ops PROTO((enum rtx_code *, HOST_WIDE_INT *, + enum rtx_code, HOST_WIDE_INT, + enum machine_mode, int *)); +static rtx simplify_shift_const PROTO((rtx, enum rtx_code, enum machine_mode, + rtx, int)); +static int recog_for_combine PROTO((rtx *, rtx, rtx *, int *)); +static rtx gen_lowpart_for_combine PROTO((enum machine_mode, rtx)); +static rtx gen_rtx_combine PVPROTO((enum rtx_code code, enum machine_mode mode, + ...)); +static rtx gen_binary PROTO((enum rtx_code, enum machine_mode, + rtx, rtx)); +static rtx gen_unary PROTO((enum rtx_code, enum machine_mode, + enum machine_mode, rtx)); +static enum rtx_code simplify_comparison PROTO((enum rtx_code, rtx *, rtx *)); +static int reversible_comparison_p PROTO((rtx)); +static void update_table_tick PROTO((rtx)); +static void record_value_for_reg PROTO((rtx, rtx, rtx)); +static void record_dead_and_set_regs_1 PROTO((rtx, rtx)); +static void record_dead_and_set_regs PROTO((rtx)); +static int get_last_value_validate PROTO((rtx *, int, int)); +static rtx get_last_value PROTO((rtx)); +static int use_crosses_set_p PROTO((rtx, int)); +static void reg_dead_at_p_1 PROTO((rtx, rtx)); +static int reg_dead_at_p PROTO((rtx, rtx)); +static void move_deaths PROTO((rtx, int, rtx, rtx *)); +static int reg_bitfield_target_p PROTO((rtx, rtx)); +static void distribute_notes PROTO((rtx, rtx, rtx, rtx, rtx, rtx)); +static void distribute_links PROTO((rtx)); +static void mark_used_regs_combine PROTO((rtx)); + +/* Main entry point for combiner. F is the first insn of the function. + NREGS is the first unused pseudo-reg number. */ + +void +combine_instructions (f, nregs) + rtx f; + int nregs; +{ + register rtx insn, next, prev; + register int i; + register rtx links, nextlinks; + + combine_attempts = 0; + combine_merges = 0; + combine_extras = 0; + combine_successes = 0; + undobuf.num_undo = previous_num_undos = 0; + + combine_max_regno = nregs; + + reg_nonzero_bits + = (unsigned HOST_WIDE_INT *) alloca (nregs * sizeof (HOST_WIDE_INT)); + reg_sign_bit_copies = (char *) alloca (nregs * sizeof (char)); + + bzero ((char *) reg_nonzero_bits, nregs * sizeof (HOST_WIDE_INT)); + bzero (reg_sign_bit_copies, nregs * sizeof (char)); + + reg_last_death = (rtx *) alloca (nregs * sizeof (rtx)); + reg_last_set = (rtx *) alloca (nregs * sizeof (rtx)); + reg_last_set_value = (rtx *) alloca (nregs * sizeof (rtx)); + reg_last_set_table_tick = (int *) alloca (nregs * sizeof (int)); + reg_last_set_label = (int *) alloca (nregs * sizeof (int)); + reg_last_set_invalid = (char *) alloca (nregs * sizeof (char)); + reg_last_set_mode + = (enum machine_mode *) alloca (nregs * sizeof (enum machine_mode)); + reg_last_set_nonzero_bits + = (unsigned HOST_WIDE_INT *) alloca (nregs * sizeof (HOST_WIDE_INT)); + reg_last_set_sign_bit_copies + = (char *) alloca (nregs * sizeof (char)); + + init_reg_last_arrays (); + + init_recog_no_volatile (); + + /* Compute maximum uid value so uid_cuid can be allocated. */ + + for (insn = f, i = 0; insn; insn = NEXT_INSN (insn)) + if (INSN_UID (insn) > i) + i = INSN_UID (insn); + + uid_cuid = (int *) alloca ((i + 1) * sizeof (int)); + max_uid_cuid = i; + + nonzero_bits_mode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0); + + /* Don't use reg_nonzero_bits when computing it. This can cause problems + when, for example, we have j <<= 1 in a loop. */ + + nonzero_sign_valid = 0; + + /* Compute the mapping from uids to cuids. + Cuids are numbers assigned to insns, like uids, + except that cuids increase monotonically through the code. + + Scan all SETs and see if we can deduce anything about what + bits are known to be zero for some registers and how many copies + of the sign bit are known to exist for those registers. + + Also set any known values so that we can use it while searching + for what bits are known to be set. */ + + label_tick = 1; + + /* We need to initialize it here, because record_dead_and_set_regs may call + get_last_value. */ + subst_prev_insn = NULL_RTX; + + setup_incoming_promotions (); + + for (insn = f, i = 0; insn; insn = NEXT_INSN (insn)) + { + uid_cuid[INSN_UID (insn)] = ++i; + subst_low_cuid = i; + subst_insn = insn; + + if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') + { + note_stores (PATTERN (insn), set_nonzero_bits_and_sign_copies); + record_dead_and_set_regs (insn); + } + + if (GET_CODE (insn) == CODE_LABEL) + label_tick++; + } + + nonzero_sign_valid = 1; + + /* Now scan all the insns in forward order. */ + + this_basic_block = -1; + label_tick = 1; + last_call_cuid = 0; + mem_last_set = 0; + init_reg_last_arrays (); + setup_incoming_promotions (); + + for (insn = f; insn; insn = next ? next : NEXT_INSN (insn)) + { + next = 0; + + /* If INSN starts a new basic block, update our basic block number. */ + if (this_basic_block + 1 < n_basic_blocks + && basic_block_head[this_basic_block + 1] == insn) + this_basic_block++; + + if (GET_CODE (insn) == CODE_LABEL) + label_tick++; + + else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') + { + /* Try this insn with each insn it links back to. */ + + for (links = LOG_LINKS (insn); links; links = XEXP (links, 1)) + if ((next = try_combine (insn, XEXP (links, 0), NULL_RTX)) != 0) + goto retry; + + /* Try each sequence of three linked insns ending with this one. */ + + for (links = LOG_LINKS (insn); links; links = XEXP (links, 1)) + for (nextlinks = LOG_LINKS (XEXP (links, 0)); nextlinks; + nextlinks = XEXP (nextlinks, 1)) + if ((next = try_combine (insn, XEXP (links, 0), + XEXP (nextlinks, 0))) != 0) + goto retry; + +#ifdef HAVE_cc0 + /* Try to combine a jump insn that uses CC0 + with a preceding insn that sets CC0, and maybe with its + logical predecessor as well. + This is how we make decrement-and-branch insns. + We need this special code because data flow connections + via CC0 do not get entered in LOG_LINKS. */ + + if (GET_CODE (insn) == JUMP_INSN + && (prev = prev_nonnote_insn (insn)) != 0 + && GET_CODE (prev) == INSN + && sets_cc0_p (PATTERN (prev))) + { + if ((next = try_combine (insn, prev, NULL_RTX)) != 0) + goto retry; + + for (nextlinks = LOG_LINKS (prev); nextlinks; + nextlinks = XEXP (nextlinks, 1)) + if ((next = try_combine (insn, prev, + XEXP (nextlinks, 0))) != 0) + goto retry; + } + + /* Do the same for an insn that explicitly references CC0. */ + if (GET_CODE (insn) == INSN + && (prev = prev_nonnote_insn (insn)) != 0 + && GET_CODE (prev) == INSN + && sets_cc0_p (PATTERN (prev)) + && GET_CODE (PATTERN (insn)) == SET + && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (insn)))) + { + if ((next = try_combine (insn, prev, NULL_RTX)) != 0) + goto retry; + + for (nextlinks = LOG_LINKS (prev); nextlinks; + nextlinks = XEXP (nextlinks, 1)) + if ((next = try_combine (insn, prev, + XEXP (nextlinks, 0))) != 0) + goto retry; + } + + /* Finally, see if any of the insns that this insn links to + explicitly references CC0. If so, try this insn, that insn, + and its predecessor if it sets CC0. */ + for (links = LOG_LINKS (insn); links; links = XEXP (links, 1)) + if (GET_CODE (XEXP (links, 0)) == INSN + && GET_CODE (PATTERN (XEXP (links, 0))) == SET + && reg_mentioned_p (cc0_rtx, SET_SRC (PATTERN (XEXP (links, 0)))) + && (prev = prev_nonnote_insn (XEXP (links, 0))) != 0 + && GET_CODE (prev) == INSN + && sets_cc0_p (PATTERN (prev)) + && (next = try_combine (insn, XEXP (links, 0), prev)) != 0) + goto retry; +#endif + + /* Try combining an insn with two different insns whose results it + uses. */ + for (links = LOG_LINKS (insn); links; links = XEXP (links, 1)) + for (nextlinks = XEXP (links, 1); nextlinks; + nextlinks = XEXP (nextlinks, 1)) + if ((next = try_combine (insn, XEXP (links, 0), + XEXP (nextlinks, 0))) != 0) + goto retry; + + if (GET_CODE (insn) != NOTE) + record_dead_and_set_regs (insn); + + retry: + ; + } + } + + total_attempts += combine_attempts; + total_merges += combine_merges; + total_extras += combine_extras; + total_successes += combine_successes; + + nonzero_sign_valid = 0; +} + +/* Wipe the reg_last_xxx arrays in preparation for another pass. */ + +static void +init_reg_last_arrays () +{ + int nregs = combine_max_regno; + + bzero ((char *) reg_last_death, nregs * sizeof (rtx)); + bzero ((char *) reg_last_set, nregs * sizeof (rtx)); + bzero ((char *) reg_last_set_value, nregs * sizeof (rtx)); + bzero ((char *) reg_last_set_table_tick, nregs * sizeof (int)); + bzero ((char *) reg_last_set_label, nregs * sizeof (int)); + bzero (reg_last_set_invalid, nregs * sizeof (char)); + bzero ((char *) reg_last_set_mode, nregs * sizeof (enum machine_mode)); + bzero ((char *) reg_last_set_nonzero_bits, nregs * sizeof (HOST_WIDE_INT)); + bzero (reg_last_set_sign_bit_copies, nregs * sizeof (char)); +} + +/* Set up any promoted values for incoming argument registers. */ + +static void +setup_incoming_promotions () +{ +#ifdef PROMOTE_FUNCTION_ARGS + int regno; + rtx reg; + enum machine_mode mode; + int unsignedp; + rtx first = get_insns (); + + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) + if (FUNCTION_ARG_REGNO_P (regno) + && (reg = promoted_input_arg (regno, &mode, &unsignedp)) != 0) + record_value_for_reg (reg, first, + gen_rtx (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, + GET_MODE (reg), + gen_rtx (CLOBBER, mode, const0_rtx))); +#endif +} + +/* Called via note_stores. If X is a pseudo that is used in more than + one basic block, is narrower that HOST_BITS_PER_WIDE_INT, and is being + set, record what bits are known zero. If we are clobbering X, + ignore this "set" because the clobbered value won't be used. + + If we are setting only a portion of X and we can't figure out what + portion, assume all bits will be used since we don't know what will + be happening. + + Similarly, set how many bits of X are known to be copies of the sign bit + at all locations in the function. This is the smallest number implied + by any set of X. */ + +static void +set_nonzero_bits_and_sign_copies (x, set) + rtx x; + rtx set; +{ + int num; + + if (GET_CODE (x) == REG + && REGNO (x) >= FIRST_PSEUDO_REGISTER + && reg_n_sets[REGNO (x)] > 1 + && reg_basic_block[REGNO (x)] < 0 + /* If this register is undefined at the start of the file, we can't + say what its contents were. */ + && ! (basic_block_live_at_start[0][REGNO (x) / REGSET_ELT_BITS] + & ((REGSET_ELT_TYPE) 1 << (REGNO (x) % REGSET_ELT_BITS))) + && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT) + { + if (GET_CODE (set) == CLOBBER) + { + reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x)); + reg_sign_bit_copies[REGNO (x)] = 0; + return; + } + + /* If this is a complex assignment, see if we can convert it into a + simple assignment. */ + set = expand_field_assignment (set); + + /* If this is a simple assignment, or we have a paradoxical SUBREG, + set what we know about X. */ + + if (SET_DEST (set) == x + || (GET_CODE (SET_DEST (set)) == SUBREG + && (GET_MODE_SIZE (GET_MODE (SET_DEST (set))) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (set))))) + && SUBREG_REG (SET_DEST (set)) == x)) + { + rtx src = SET_SRC (set); + +#ifdef SHORT_IMMEDIATES_SIGN_EXTEND + /* If X is narrower than a word and SRC is a non-negative + constant that would appear negative in the mode of X, + sign-extend it for use in reg_nonzero_bits because some + machines (maybe most) will actually do the sign-extension + and this is the conservative approach. + + ??? For 2.5, try to tighten up the MD files in this regard + instead of this kludge. */ + + if (GET_MODE_BITSIZE (GET_MODE (x)) < BITS_PER_WORD + && GET_CODE (src) == CONST_INT + && INTVAL (src) > 0 + && 0 != (INTVAL (src) + & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (x)) - 1)))) + src = GEN_INT (INTVAL (src) + | ((HOST_WIDE_INT) (-1) + << GET_MODE_BITSIZE (GET_MODE (x)))); +#endif + + reg_nonzero_bits[REGNO (x)] + |= nonzero_bits (src, nonzero_bits_mode); + num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x)); + if (reg_sign_bit_copies[REGNO (x)] == 0 + || reg_sign_bit_copies[REGNO (x)] > num) + reg_sign_bit_copies[REGNO (x)] = num; + } + else + { + reg_nonzero_bits[REGNO (x)] = GET_MODE_MASK (GET_MODE (x)); + reg_sign_bit_copies[REGNO (x)] = 0; + } + } +} + +/* See if INSN can be combined into I3. PRED and SUCC are optionally + insns that were previously combined into I3 or that will be combined + into the merger of INSN and I3. + + Return 0 if the combination is not allowed for any reason. + + If the combination is allowed, *PDEST will be set to the single + destination of INSN and *PSRC to the single source, and this function + will return 1. */ + +static int +can_combine_p (insn, i3, pred, succ, pdest, psrc) + rtx insn; + rtx i3; + rtx pred, succ; + rtx *pdest, *psrc; +{ + int i; + rtx set = 0, src, dest; + rtx p, link; + int all_adjacent = (succ ? (next_active_insn (insn) == succ + && next_active_insn (succ) == i3) + : next_active_insn (insn) == i3); + + /* Can combine only if previous insn is a SET of a REG, a SUBREG or CC0. + or a PARALLEL consisting of such a SET and CLOBBERs. + + If INSN has CLOBBER parallel parts, ignore them for our processing. + By definition, these happen during the execution of the insn. When it + is merged with another insn, all bets are off. If they are, in fact, + needed and aren't also supplied in I3, they may be added by + recog_for_combine. Otherwise, it won't match. + + We can also ignore a SET whose SET_DEST is mentioned in a REG_UNUSED + note. + + Get the source and destination of INSN. If more than one, can't + combine. */ + + if (GET_CODE (PATTERN (insn)) == SET) + set = PATTERN (insn); + else if (GET_CODE (PATTERN (insn)) == PARALLEL + && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET) + { + for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) + { + rtx elt = XVECEXP (PATTERN (insn), 0, i); + + switch (GET_CODE (elt)) + { + /* We can ignore CLOBBERs. */ + case CLOBBER: + break; + + case SET: + /* Ignore SETs whose result isn't used but not those that + have side-effects. */ + if (find_reg_note (insn, REG_UNUSED, SET_DEST (elt)) + && ! side_effects_p (elt)) + break; + + /* If we have already found a SET, this is a second one and + so we cannot combine with this insn. */ + if (set) + return 0; + + set = elt; + break; + + default: + /* Anything else means we can't combine. */ + return 0; + } + } + + if (set == 0 + /* If SET_SRC is an ASM_OPERANDS we can't throw away these CLOBBERs, + so don't do anything with it. */ + || GET_CODE (SET_SRC (set)) == ASM_OPERANDS) + return 0; + } + else + return 0; + + if (set == 0) + return 0; + + set = expand_field_assignment (set); + src = SET_SRC (set), dest = SET_DEST (set); + + /* Don't eliminate a store in the stack pointer. */ + if (dest == stack_pointer_rtx + /* If we couldn't eliminate a field assignment, we can't combine. */ + || GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == STRICT_LOW_PART + /* Don't combine with an insn that sets a register to itself if it has + a REG_EQUAL note. This may be part of a REG_NO_CONFLICT sequence. */ + || (rtx_equal_p (src, dest) && find_reg_note (insn, REG_EQUAL, NULL_RTX)) + /* Can't merge a function call. */ + || GET_CODE (src) == CALL + /* Don't eliminate a function call argument. */ + || (GET_CODE (i3) == CALL_INSN + && (find_reg_fusage (i3, USE, dest) + || (GET_CODE (dest) == REG + && REGNO (dest) < FIRST_PSEUDO_REGISTER + && global_regs[REGNO (dest)]))) + /* Don't substitute into an incremented register. */ + || FIND_REG_INC_NOTE (i3, dest) + || (succ && FIND_REG_INC_NOTE (succ, dest)) + /* Don't combine the end of a libcall into anything. */ + || find_reg_note (insn, REG_RETVAL, NULL_RTX) + /* Make sure that DEST is not used after SUCC but before I3. */ + || (succ && ! all_adjacent + && reg_used_between_p (dest, succ, i3)) + /* Make sure that the value that is to be substituted for the register + does not use any registers whose values alter in between. However, + If the insns are adjacent, a use can't cross a set even though we + think it might (this can happen for a sequence of insns each setting + the same destination; reg_last_set of that register might point to + a NOTE). If INSN has a REG_EQUIV note, the register is always + equivalent to the memory so the substitution is valid even if there + are intervening stores. Also, don't move a volatile asm or + UNSPEC_VOLATILE across any other insns. */ + || (! all_adjacent + && (((GET_CODE (src) != MEM + || ! find_reg_note (insn, REG_EQUIV, src)) + && use_crosses_set_p (src, INSN_CUID (insn))) + || (GET_CODE (src) == ASM_OPERANDS && MEM_VOLATILE_P (src)) + || GET_CODE (src) == UNSPEC_VOLATILE)) + /* If there is a REG_NO_CONFLICT note for DEST in I3 or SUCC, we get + better register allocation by not doing the combine. */ + || find_reg_note (i3, REG_NO_CONFLICT, dest) + || (succ && find_reg_note (succ, REG_NO_CONFLICT, dest)) + /* Don't combine across a CALL_INSN, because that would possibly + change whether the life span of some REGs crosses calls or not, + and it is a pain to update that information. + Exception: if source is a constant, moving it later can't hurt. + Accept that special case, because it helps -fforce-addr a lot. */ + || (INSN_CUID (insn) < last_call_cuid && ! CONSTANT_P (src))) + return 0; + + /* DEST must either be a REG or CC0. */ + if (GET_CODE (dest) == REG) + { + /* If register alignment is being enforced for multi-word items in all + cases except for parameters, it is possible to have a register copy + insn referencing a hard register that is not allowed to contain the + mode being copied and which would not be valid as an operand of most + insns. Eliminate this problem by not combining with such an insn. + + Also, on some machines we don't want to extend the life of a hard + register. */ + + if (GET_CODE (src) == REG + && ((REGNO (dest) < FIRST_PSEUDO_REGISTER + && ! HARD_REGNO_MODE_OK (REGNO (dest), GET_MODE (dest))) + /* Don't extend the life of a hard register unless it is + user variable (if we have few registers) or it can't + fit into the desired register (meaning something special + is going on). */ + || (REGNO (src) < FIRST_PSEUDO_REGISTER + && (! HARD_REGNO_MODE_OK (REGNO (src), GET_MODE (src)) +#ifdef SMALL_REGISTER_CLASSES + || ! REG_USERVAR_P (src) +#endif + )))) + return 0; + } + else if (GET_CODE (dest) != CC0) + return 0; + + /* Don't substitute for a register intended as a clobberable operand. + Similarly, don't substitute an expression containing a register that + will be clobbered in I3. */ + if (GET_CODE (PATTERN (i3)) == PARALLEL) + for (i = XVECLEN (PATTERN (i3), 0) - 1; i >= 0; i--) + if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER + && (reg_overlap_mentioned_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0), + src) + || rtx_equal_p (XEXP (XVECEXP (PATTERN (i3), 0, i), 0), dest))) + return 0; + + /* If INSN contains anything volatile, or is an `asm' (whether volatile + or not), reject, unless nothing volatile comes between it and I3, + with the exception of SUCC. */ + + if (GET_CODE (src) == ASM_OPERANDS || volatile_refs_p (src)) + for (p = NEXT_INSN (insn); p != i3; p = NEXT_INSN (p)) + if (GET_RTX_CLASS (GET_CODE (p)) == 'i' + && p != succ && volatile_refs_p (PATTERN (p))) + return 0; + + /* If there are any volatile insns between INSN and I3, reject, because + they might affect machine state. */ + + for (p = NEXT_INSN (insn); p != i3; p = NEXT_INSN (p)) + if (GET_RTX_CLASS (GET_CODE (p)) == 'i' + && p != succ && volatile_insn_p (PATTERN (p))) + return 0; + + /* If INSN or I2 contains an autoincrement or autodecrement, + make sure that register is not used between there and I3, + and not already used in I3 either. + Also insist that I3 not be a jump; if it were one + and the incremented register were spilled, we would lose. */ + +#ifdef AUTO_INC_DEC + for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) + if (REG_NOTE_KIND (link) == REG_INC + && (GET_CODE (i3) == JUMP_INSN + || reg_used_between_p (XEXP (link, 0), insn, i3) + || reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i3)))) + return 0; +#endif + +#ifdef HAVE_cc0 + /* Don't combine an insn that follows a CC0-setting insn. + An insn that uses CC0 must not be separated from the one that sets it. + We do, however, allow I2 to follow a CC0-setting insn if that insn + is passed as I1; in that case it will be deleted also. + We also allow combining in this case if all the insns are adjacent + because that would leave the two CC0 insns adjacent as well. + It would be more logical to test whether CC0 occurs inside I1 or I2, + but that would be much slower, and this ought to be equivalent. */ + + p = prev_nonnote_insn (insn); + if (p && p != pred && GET_CODE (p) == INSN && sets_cc0_p (PATTERN (p)) + && ! all_adjacent) + return 0; +#endif + + /* If we get here, we have passed all the tests and the combination is + to be allowed. */ + + *pdest = dest; + *psrc = src; + + return 1; +} + +/* LOC is the location within I3 that contains its pattern or the component + of a PARALLEL of the pattern. We validate that it is valid for combining. + + One problem is if I3 modifies its output, as opposed to replacing it + entirely, we can't allow the output to contain I2DEST or I1DEST as doing + so would produce an insn that is not equivalent to the original insns. + + Consider: + + (set (reg:DI 101) (reg:DI 100)) + (set (subreg:SI (reg:DI 101) 0) ) + + This is NOT equivalent to: + + (parallel [(set (subreg:SI (reg:DI 100) 0) ) + (set (reg:DI 101) (reg:DI 100))]) + + Not only does this modify 100 (in which case it might still be valid + if 100 were dead in I2), it sets 101 to the ORIGINAL value of 100. + + We can also run into a problem if I2 sets a register that I1 + uses and I1 gets directly substituted into I3 (not via I2). In that + case, we would be getting the wrong value of I2DEST into I3, so we + must reject the combination. This case occurs when I2 and I1 both + feed into I3, rather than when I1 feeds into I2, which feeds into I3. + If I1_NOT_IN_SRC is non-zero, it means that finding I1 in the source + of a SET must prevent combination from occurring. + + On machines where SMALL_REGISTER_CLASSES is defined, we don't combine + if the destination of a SET is a hard register that isn't a user + variable. + + Before doing the above check, we first try to expand a field assignment + into a set of logical operations. + + If PI3_DEST_KILLED is non-zero, it is a pointer to a location in which + we place a register that is both set and used within I3. If more than one + such register is detected, we fail. + + Return 1 if the combination is valid, zero otherwise. */ + +static int +combinable_i3pat (i3, loc, i2dest, i1dest, i1_not_in_src, pi3dest_killed) + rtx i3; + rtx *loc; + rtx i2dest; + rtx i1dest; + int i1_not_in_src; + rtx *pi3dest_killed; +{ + rtx x = *loc; + + if (GET_CODE (x) == SET) + { + rtx set = expand_field_assignment (x); + rtx dest = SET_DEST (set); + rtx src = SET_SRC (set); + rtx inner_dest = dest, inner_src = src; + + SUBST (*loc, set); + + while (GET_CODE (inner_dest) == STRICT_LOW_PART + || GET_CODE (inner_dest) == SUBREG + || GET_CODE (inner_dest) == ZERO_EXTRACT) + inner_dest = XEXP (inner_dest, 0); + + /* We probably don't need this any more now that LIMIT_RELOAD_CLASS + was added. */ +#if 0 + while (GET_CODE (inner_src) == STRICT_LOW_PART + || GET_CODE (inner_src) == SUBREG + || GET_CODE (inner_src) == ZERO_EXTRACT) + inner_src = XEXP (inner_src, 0); + + /* If it is better that two different modes keep two different pseudos, + avoid combining them. This avoids producing the following pattern + on a 386: + (set (subreg:SI (reg/v:QI 21) 0) + (lshiftrt:SI (reg/v:SI 20) + (const_int 24))) + If that were made, reload could not handle the pair of + reg 20/21, since it would try to get any GENERAL_REGS + but some of them don't handle QImode. */ + + if (rtx_equal_p (inner_src, i2dest) + && GET_CODE (inner_dest) == REG + && ! MODES_TIEABLE_P (GET_MODE (i2dest), GET_MODE (inner_dest))) + return 0; +#endif + + /* Check for the case where I3 modifies its output, as + discussed above. */ + if ((inner_dest != dest + && (reg_overlap_mentioned_p (i2dest, inner_dest) + || (i1dest && reg_overlap_mentioned_p (i1dest, inner_dest)))) + /* This is the same test done in can_combine_p except that we + allow a hard register with SMALL_REGISTER_CLASSES if SRC is a + CALL operation. */ + || (GET_CODE (inner_dest) == REG + && REGNO (inner_dest) < FIRST_PSEUDO_REGISTER + && (! HARD_REGNO_MODE_OK (REGNO (inner_dest), + GET_MODE (inner_dest)) +#ifdef SMALL_REGISTER_CLASSES + || (GET_CODE (src) != CALL && ! REG_USERVAR_P (inner_dest)) +#endif + )) + || (i1_not_in_src && reg_overlap_mentioned_p (i1dest, src))) + return 0; + + /* If DEST is used in I3, it is being killed in this insn, + so record that for later. + Never add REG_DEAD notes for the FRAME_POINTER_REGNUM or the + STACK_POINTER_REGNUM, since these are always considered to be + live. Similarly for ARG_POINTER_REGNUM if it is fixed. */ + if (pi3dest_killed && GET_CODE (dest) == REG + && reg_referenced_p (dest, PATTERN (i3)) + && REGNO (dest) != FRAME_POINTER_REGNUM +#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM + && REGNO (dest) != HARD_FRAME_POINTER_REGNUM +#endif +#if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM + && (REGNO (dest) != ARG_POINTER_REGNUM + || ! fixed_regs [REGNO (dest)]) +#endif + && REGNO (dest) != STACK_POINTER_REGNUM) + { + if (*pi3dest_killed) + return 0; + + *pi3dest_killed = dest; + } + } + + else if (GET_CODE (x) == PARALLEL) + { + int i; + + for (i = 0; i < XVECLEN (x, 0); i++) + if (! combinable_i3pat (i3, &XVECEXP (x, 0, i), i2dest, i1dest, + i1_not_in_src, pi3dest_killed)) + return 0; + } + + return 1; +} + +/* Try to combine the insns I1 and I2 into I3. + Here I1 and I2 appear earlier than I3. + I1 can be zero; then we combine just I2 into I3. + + It we are combining three insns and the resulting insn is not recognized, + try splitting it into two insns. If that happens, I2 and I3 are retained + and I1 is pseudo-deleted by turning it into a NOTE. Otherwise, I1 and I2 + are pseudo-deleted. + + Return 0 if the combination does not work. Then nothing is changed. + If we did the combination, return the insn at which combine should + resume scanning. */ + +static rtx +try_combine (i3, i2, i1) + register rtx i3, i2, i1; +{ + /* New patterns for I3 and I3, respectively. */ + rtx newpat, newi2pat = 0; + /* Indicates need to preserve SET in I1 or I2 in I3 if it is not dead. */ + int added_sets_1, added_sets_2; + /* Total number of SETs to put into I3. */ + int total_sets; + /* Nonzero is I2's body now appears in I3. */ + int i2_is_used; + /* INSN_CODEs for new I3, new I2, and user of condition code. */ + int insn_code_number, i2_code_number, other_code_number; + /* Contains I3 if the destination of I3 is used in its source, which means + that the old life of I3 is being killed. If that usage is placed into + I2 and not in I3, a REG_DEAD note must be made. */ + rtx i3dest_killed = 0; + /* SET_DEST and SET_SRC of I2 and I1. */ + rtx i2dest, i2src, i1dest = 0, i1src = 0; + /* PATTERN (I2), or a copy of it in certain cases. */ + rtx i2pat; + /* Indicates if I2DEST or I1DEST is in I2SRC or I1_SRC. */ + int i2dest_in_i2src = 0, i1dest_in_i1src = 0, i2dest_in_i1src = 0; + int i1_feeds_i3 = 0; + /* Notes that must be added to REG_NOTES in I3 and I2. */ + rtx new_i3_notes, new_i2_notes; + /* Notes that we substituted I3 into I2 instead of the normal case. */ + int i3_subst_into_i2 = 0; + /* Notes that I1, I2 or I3 is a MULT operation. */ + int have_mult = 0; + /* Number of clobbers of SCRATCH we had to add. */ + int i3_scratches = 0, i2_scratches = 0, other_scratches = 0; + + int maxreg; + rtx temp; + register rtx link; + int i; + + /* If any of I1, I2, and I3 isn't really an insn, we can't do anything. + This can occur when flow deletes an insn that it has merged into an + auto-increment address. We also can't do anything if I3 has a + REG_LIBCALL note since we don't want to disrupt the contiguity of a + libcall. */ + + if (GET_RTX_CLASS (GET_CODE (i3)) != 'i' + || GET_RTX_CLASS (GET_CODE (i2)) != 'i' + || (i1 && GET_RTX_CLASS (GET_CODE (i1)) != 'i') + || find_reg_note (i3, REG_LIBCALL, NULL_RTX)) + return 0; + + combine_attempts++; + + undobuf.num_undo = previous_num_undos = 0; + undobuf.other_insn = 0; + + /* Save the current high-water-mark so we can free storage if we didn't + accept this combination. */ + undobuf.storage = (char *) oballoc (0); + + /* Reset the hard register usage information. */ + CLEAR_HARD_REG_SET (newpat_used_regs); + + /* If I1 and I2 both feed I3, they can be in any order. To simplify the + code below, set I1 to be the earlier of the two insns. */ + if (i1 && INSN_CUID (i1) > INSN_CUID (i2)) + temp = i1, i1 = i2, i2 = temp; + + added_links_insn = 0; + + /* First check for one important special-case that the code below will + not handle. Namely, the case where I1 is zero, I2 has multiple sets, + and I3 is a SET whose SET_SRC is a SET_DEST in I2. In that case, + we may be able to replace that destination with the destination of I3. + This occurs in the common code where we compute both a quotient and + remainder into a structure, in which case we want to do the computation + directly into the structure to avoid register-register copies. + + We make very conservative checks below and only try to handle the + most common cases of this. For example, we only handle the case + where I2 and I3 are adjacent to avoid making difficult register + usage tests. */ + + if (i1 == 0 && GET_CODE (i3) == INSN && GET_CODE (PATTERN (i3)) == SET + && GET_CODE (SET_SRC (PATTERN (i3))) == REG + && REGNO (SET_SRC (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER +#ifdef SMALL_REGISTER_CLASSES + && (GET_CODE (SET_DEST (PATTERN (i3))) != REG + || REGNO (SET_DEST (PATTERN (i3))) >= FIRST_PSEUDO_REGISTER + || REG_USERVAR_P (SET_DEST (PATTERN (i3)))) +#endif + && find_reg_note (i3, REG_DEAD, SET_SRC (PATTERN (i3))) + && GET_CODE (PATTERN (i2)) == PARALLEL + && ! side_effects_p (SET_DEST (PATTERN (i3))) + /* If the dest of I3 is a ZERO_EXTRACT or STRICT_LOW_PART, the code + below would need to check what is inside (and reg_overlap_mentioned_p + doesn't support those codes anyway). Don't allow those destinations; + the resulting insn isn't likely to be recognized anyway. */ + && GET_CODE (SET_DEST (PATTERN (i3))) != ZERO_EXTRACT + && GET_CODE (SET_DEST (PATTERN (i3))) != STRICT_LOW_PART + && ! reg_overlap_mentioned_p (SET_SRC (PATTERN (i3)), + SET_DEST (PATTERN (i3))) + && next_real_insn (i2) == i3) + { + rtx p2 = PATTERN (i2); + + /* Make sure that the destination of I3, + which we are going to substitute into one output of I2, + is not used within another output of I2. We must avoid making this: + (parallel [(set (mem (reg 69)) ...) + (set (reg 69) ...)]) + which is not well-defined as to order of actions. + (Besides, reload can't handle output reloads for this.) + + The problem can also happen if the dest of I3 is a memory ref, + if another dest in I2 is an indirect memory ref. */ + for (i = 0; i < XVECLEN (p2, 0); i++) + if (GET_CODE (XVECEXP (p2, 0, i)) == SET + && reg_overlap_mentioned_p (SET_DEST (PATTERN (i3)), + SET_DEST (XVECEXP (p2, 0, i)))) + break; + + if (i == XVECLEN (p2, 0)) + for (i = 0; i < XVECLEN (p2, 0); i++) + if (SET_DEST (XVECEXP (p2, 0, i)) == SET_SRC (PATTERN (i3))) + { + combine_merges++; + + subst_insn = i3; + subst_low_cuid = INSN_CUID (i2); + + added_sets_2 = added_sets_1 = 0; + i2dest = SET_SRC (PATTERN (i3)); + + /* Replace the dest in I2 with our dest and make the resulting + insn the new pattern for I3. Then skip to where we + validate the pattern. Everything was set up above. */ + SUBST (SET_DEST (XVECEXP (p2, 0, i)), + SET_DEST (PATTERN (i3))); + + newpat = p2; + i3_subst_into_i2 = 1; + goto validate_replacement; + } + } + +#ifndef HAVE_cc0 + /* If we have no I1 and I2 looks like: + (parallel [(set (reg:CC X) (compare:CC OP (const_int 0))) + (set Y OP)]) + make up a dummy I1 that is + (set Y OP) + and change I2 to be + (set (reg:CC X) (compare:CC Y (const_int 0))) + + (We can ignore any trailing CLOBBERs.) + + This undoes a previous combination and allows us to match a branch-and- + decrement insn. */ + + if (i1 == 0 && GET_CODE (PATTERN (i2)) == PARALLEL + && XVECLEN (PATTERN (i2), 0) >= 2 + && GET_CODE (XVECEXP (PATTERN (i2), 0, 0)) == SET + && (GET_MODE_CLASS (GET_MODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 0)))) + == MODE_CC) + && GET_CODE (SET_SRC (XVECEXP (PATTERN (i2), 0, 0))) == COMPARE + && XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 1) == const0_rtx + && GET_CODE (XVECEXP (PATTERN (i2), 0, 1)) == SET + && GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, 1))) == REG + && rtx_equal_p (XEXP (SET_SRC (XVECEXP (PATTERN (i2), 0, 0)), 0), + SET_SRC (XVECEXP (PATTERN (i2), 0, 1)))) + { + for (i = XVECLEN (PATTERN (i2), 0) - 1; i >= 2; i--) + if (GET_CODE (XVECEXP (PATTERN (i2), 0, i)) != CLOBBER) + break; + + if (i == 1) + { + /* We make I1 with the same INSN_UID as I2. This gives it + the same INSN_CUID for value tracking. Our fake I1 will + never appear in the insn stream so giving it the same INSN_UID + as I2 will not cause a problem. */ + + subst_prev_insn = i1 + = gen_rtx (INSN, VOIDmode, INSN_UID (i2), 0, i2, + XVECEXP (PATTERN (i2), 0, 1), -1, 0, 0); + + SUBST (PATTERN (i2), XVECEXP (PATTERN (i2), 0, 0)); + SUBST (XEXP (SET_SRC (PATTERN (i2)), 0), + SET_DEST (PATTERN (i1))); + } + } +#endif + + /* Verify that I2 and I1 are valid for combining. */ + if (! can_combine_p (i2, i3, i1, NULL_RTX, &i2dest, &i2src) + || (i1 && ! can_combine_p (i1, i3, NULL_RTX, i2, &i1dest, &i1src))) + { + undo_all (); + return 0; + } + + /* Record whether I2DEST is used in I2SRC and similarly for the other + cases. Knowing this will help in register status updating below. */ + i2dest_in_i2src = reg_overlap_mentioned_p (i2dest, i2src); + i1dest_in_i1src = i1 && reg_overlap_mentioned_p (i1dest, i1src); + i2dest_in_i1src = i1 && reg_overlap_mentioned_p (i2dest, i1src); + + /* See if I1 directly feeds into I3. It does if I1DEST is not used + in I2SRC. */ + i1_feeds_i3 = i1 && ! reg_overlap_mentioned_p (i1dest, i2src); + + /* Ensure that I3's pattern can be the destination of combines. */ + if (! combinable_i3pat (i3, &PATTERN (i3), i2dest, i1dest, + i1 && i2dest_in_i1src && i1_feeds_i3, + &i3dest_killed)) + { + undo_all (); + return 0; + } + + /* See if any of the insns is a MULT operation. Unless one is, we will + reject a combination that is, since it must be slower. Be conservative + here. */ + if (GET_CODE (i2src) == MULT + || (i1 != 0 && GET_CODE (i1src) == MULT) + || (GET_CODE (PATTERN (i3)) == SET + && GET_CODE (SET_SRC (PATTERN (i3))) == MULT)) + have_mult = 1; + + /* If I3 has an inc, then give up if I1 or I2 uses the reg that is inc'd. + We used to do this EXCEPT in one case: I3 has a post-inc in an + output operand. However, that exception can give rise to insns like + mov r3,(r3)+ + which is a famous insn on the PDP-11 where the value of r3 used as the + source was model-dependent. Avoid this sort of thing. */ + +#if 0 + if (!(GET_CODE (PATTERN (i3)) == SET + && GET_CODE (SET_SRC (PATTERN (i3))) == REG + && GET_CODE (SET_DEST (PATTERN (i3))) == MEM + && (GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_INC + || GET_CODE (XEXP (SET_DEST (PATTERN (i3)), 0)) == POST_DEC))) + /* It's not the exception. */ +#endif +#ifdef AUTO_INC_DEC + for (link = REG_NOTES (i3); link; link = XEXP (link, 1)) + if (REG_NOTE_KIND (link) == REG_INC + && (reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i2)) + || (i1 != 0 + && reg_overlap_mentioned_p (XEXP (link, 0), PATTERN (i1))))) + { + undo_all (); + return 0; + } +#endif + + /* See if the SETs in I1 or I2 need to be kept around in the merged + instruction: whenever the value set there is still needed past I3. + For the SETs in I2, this is easy: we see if I2DEST dies or is set in I3. + + For the SET in I1, we have two cases: If I1 and I2 independently + feed into I3, the set in I1 needs to be kept around if I1DEST dies + or is set in I3. Otherwise (if I1 feeds I2 which feeds I3), the set + in I1 needs to be kept around unless I1DEST dies or is set in either + I2 or I3. We can distinguish these cases by seeing if I2SRC mentions + I1DEST. If so, we know I1 feeds into I2. */ + + added_sets_2 = ! dead_or_set_p (i3, i2dest); + + added_sets_1 + = i1 && ! (i1_feeds_i3 ? dead_or_set_p (i3, i1dest) + : (dead_or_set_p (i3, i1dest) || dead_or_set_p (i2, i1dest))); + + /* If the set in I2 needs to be kept around, we must make a copy of + PATTERN (I2), so that when we substitute I1SRC for I1DEST in + PATTERN (I2), we are only substituting for the original I1DEST, not into + an already-substituted copy. This also prevents making self-referential + rtx. If I2 is a PARALLEL, we just need the piece that assigns I2SRC to + I2DEST. */ + + i2pat = (GET_CODE (PATTERN (i2)) == PARALLEL + ? gen_rtx (SET, VOIDmode, i2dest, i2src) + : PATTERN (i2)); + + if (added_sets_2) + i2pat = copy_rtx (i2pat); + + combine_merges++; + + /* Substitute in the latest insn for the regs set by the earlier ones. */ + + maxreg = max_reg_num (); + + subst_insn = i3; + + /* It is possible that the source of I2 or I1 may be performing an + unneeded operation, such as a ZERO_EXTEND of something that is known + to have the high part zero. Handle that case by letting subst look at + the innermost one of them. + + Another way to do this would be to have a function that tries to + simplify a single insn instead of merging two or more insns. We don't + do this because of the potential of infinite loops and because + of the potential extra memory required. However, doing it the way + we are is a bit of a kludge and doesn't catch all cases. + + But only do this if -fexpensive-optimizations since it slows things down + and doesn't usually win. */ + + if (flag_expensive_optimizations) + { + /* Pass pc_rtx so no substitutions are done, just simplifications. + The cases that we are interested in here do not involve the few + cases were is_replaced is checked. */ + if (i1) + { + subst_low_cuid = INSN_CUID (i1); + i1src = subst (i1src, pc_rtx, pc_rtx, 0, 0); + } + else + { + subst_low_cuid = INSN_CUID (i2); + i2src = subst (i2src, pc_rtx, pc_rtx, 0, 0); + } + + previous_num_undos = undobuf.num_undo; + } + +#ifndef HAVE_cc0 + /* Many machines that don't use CC0 have insns that can both perform an + arithmetic operation and set the condition code. These operations will + be represented as a PARALLEL with the first element of the vector + being a COMPARE of an arithmetic operation with the constant zero. + The second element of the vector will set some pseudo to the result + of the same arithmetic operation. If we simplify the COMPARE, we won't + match such a pattern and so will generate an extra insn. Here we test + for this case, where both the comparison and the operation result are + needed, and make the PARALLEL by just replacing I2DEST in I3SRC with + I2SRC. Later we will make the PARALLEL that contains I2. */ + + if (i1 == 0 && added_sets_2 && GET_CODE (PATTERN (i3)) == SET + && GET_CODE (SET_SRC (PATTERN (i3))) == COMPARE + && XEXP (SET_SRC (PATTERN (i3)), 1) == const0_rtx + && rtx_equal_p (XEXP (SET_SRC (PATTERN (i3)), 0), i2dest)) + { + rtx *cc_use; + enum machine_mode compare_mode; + + newpat = PATTERN (i3); + SUBST (XEXP (SET_SRC (newpat), 0), i2src); + + i2_is_used = 1; + +#ifdef EXTRA_CC_MODES + /* See if a COMPARE with the operand we substituted in should be done + with the mode that is currently being used. If not, do the same + processing we do in `subst' for a SET; namely, if the destination + is used only once, try to replace it with a register of the proper + mode and also replace the COMPARE. */ + if (undobuf.other_insn == 0 + && (cc_use = find_single_use (SET_DEST (newpat), i3, + &undobuf.other_insn)) + && ((compare_mode = SELECT_CC_MODE (GET_CODE (*cc_use), + i2src, const0_rtx)) + != GET_MODE (SET_DEST (newpat)))) + { + int regno = REGNO (SET_DEST (newpat)); + rtx new_dest = gen_rtx (REG, compare_mode, regno); + + if (regno < FIRST_PSEUDO_REGISTER + || (reg_n_sets[regno] == 1 && ! added_sets_2 + && ! REG_USERVAR_P (SET_DEST (newpat)))) + { + if (regno >= FIRST_PSEUDO_REGISTER) + SUBST (regno_reg_rtx[regno], new_dest); + + SUBST (SET_DEST (newpat), new_dest); + SUBST (XEXP (*cc_use, 0), new_dest); + SUBST (SET_SRC (newpat), + gen_rtx_combine (COMPARE, compare_mode, + i2src, const0_rtx)); + } + else + undobuf.other_insn = 0; + } +#endif + } + else +#endif + { + n_occurrences = 0; /* `subst' counts here */ + + /* If I1 feeds into I2 (not into I3) and I1DEST is in I1SRC, we + need to make a unique copy of I2SRC each time we substitute it + to avoid self-referential rtl. */ + + subst_low_cuid = INSN_CUID (i2); + newpat = subst (PATTERN (i3), i2dest, i2src, 0, + ! i1_feeds_i3 && i1dest_in_i1src); + previous_num_undos = undobuf.num_undo; + + /* Record whether i2's body now appears within i3's body. */ + i2_is_used = n_occurrences; + } + + /* If we already got a failure, don't try to do more. Otherwise, + try to substitute in I1 if we have it. */ + + if (i1 && GET_CODE (newpat) != CLOBBER) + { + /* Before we can do this substitution, we must redo the test done + above (see detailed comments there) that ensures that I1DEST + isn't mentioned in any SETs in NEWPAT that are field assignments. */ + + if (! combinable_i3pat (NULL_RTX, &newpat, i1dest, NULL_RTX, + 0, NULL_PTR)) + { + undo_all (); + return 0; + } + + n_occurrences = 0; + subst_low_cuid = INSN_CUID (i1); + newpat = subst (newpat, i1dest, i1src, 0, 0); + previous_num_undos = undobuf.num_undo; + } + + /* Fail if an autoincrement side-effect has been duplicated. Be careful + to count all the ways that I2SRC and I1SRC can be used. */ + if ((FIND_REG_INC_NOTE (i2, NULL_RTX) != 0 + && i2_is_used + added_sets_2 > 1) + || (i1 != 0 && FIND_REG_INC_NOTE (i1, NULL_RTX) != 0 + && (n_occurrences + added_sets_1 + (added_sets_2 && ! i1_feeds_i3) + > 1)) + /* Fail if we tried to make a new register (we used to abort, but there's + really no reason to). */ + || max_reg_num () != maxreg + /* Fail if we couldn't do something and have a CLOBBER. */ + || GET_CODE (newpat) == CLOBBER + /* Fail if this new pattern is a MULT and we didn't have one before + at the outer level. */ + || (GET_CODE (newpat) == SET && GET_CODE (SET_SRC (newpat)) == MULT + && ! have_mult)) + { + undo_all (); + return 0; + } + + /* If the actions of the earlier insns must be kept + in addition to substituting them into the latest one, + we must make a new PARALLEL for the latest insn + to hold additional the SETs. */ + + if (added_sets_1 || added_sets_2) + { + combine_extras++; + + if (GET_CODE (newpat) == PARALLEL) + { + rtvec old = XVEC (newpat, 0); + total_sets = XVECLEN (newpat, 0) + added_sets_1 + added_sets_2; + newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets)); + bcopy ((char *) &old->elem[0], (char *) &XVECEXP (newpat, 0, 0), + sizeof (old->elem[0]) * old->num_elem); + } + else + { + rtx old = newpat; + total_sets = 1 + added_sets_1 + added_sets_2; + newpat = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (total_sets)); + XVECEXP (newpat, 0, 0) = old; + } + + if (added_sets_1) + XVECEXP (newpat, 0, --total_sets) + = (GET_CODE (PATTERN (i1)) == PARALLEL + ? gen_rtx (SET, VOIDmode, i1dest, i1src) : PATTERN (i1)); + + if (added_sets_2) + { + /* If there is no I1, use I2's body as is. We used to also not do + the subst call below if I2 was substituted into I3, + but that could lose a simplification. */ + if (i1 == 0) + XVECEXP (newpat, 0, --total_sets) = i2pat; + else + /* See comment where i2pat is assigned. */ + XVECEXP (newpat, 0, --total_sets) + = subst (i2pat, i1dest, i1src, 0, 0); + } + } + + /* We come here when we are replacing a destination in I2 with the + destination of I3. */ + validate_replacement: + + /* Note which hard regs this insn has as inputs. */ + mark_used_regs_combine (newpat); + + /* Is the result of combination a valid instruction? */ + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + + /* If the result isn't valid, see if it is a PARALLEL of two SETs where + the second SET's destination is a register that is unused. In that case, + we just need the first SET. This can occur when simplifying a divmod + insn. We *must* test for this case here because the code below that + splits two independent SETs doesn't handle this case correctly when it + updates the register status. Also check the case where the first + SET's destination is unused. That would not cause incorrect code, but + does cause an unneeded insn to remain. */ + + if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL + && XVECLEN (newpat, 0) == 2 + && GET_CODE (XVECEXP (newpat, 0, 0)) == SET + && GET_CODE (XVECEXP (newpat, 0, 1)) == SET + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == REG + && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 1))) + && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 1))) + && asm_noperands (newpat) < 0) + { + newpat = XVECEXP (newpat, 0, 0); + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + } + + else if (insn_code_number < 0 && GET_CODE (newpat) == PARALLEL + && XVECLEN (newpat, 0) == 2 + && GET_CODE (XVECEXP (newpat, 0, 0)) == SET + && GET_CODE (XVECEXP (newpat, 0, 1)) == SET + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) == REG + && find_reg_note (i3, REG_UNUSED, SET_DEST (XVECEXP (newpat, 0, 0))) + && ! side_effects_p (SET_SRC (XVECEXP (newpat, 0, 0))) + && asm_noperands (newpat) < 0) + { + newpat = XVECEXP (newpat, 0, 1); + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + } + + /* If we were combining three insns and the result is a simple SET + with no ASM_OPERANDS that wasn't recognized, try to split it into two + insns. There are two ways to do this. It can be split using a + machine-specific method (like when you have an addition of a large + constant) or by combine in the function find_split_point. */ + + if (i1 && insn_code_number < 0 && GET_CODE (newpat) == SET + && asm_noperands (newpat) < 0) + { + rtx m_split, *split; + rtx ni2dest = i2dest; + + /* See if the MD file can split NEWPAT. If it can't, see if letting it + use I2DEST as a scratch register will help. In the latter case, + convert I2DEST to the mode of the source of NEWPAT if we can. */ + + m_split = split_insns (newpat, i3); + + /* We can only use I2DEST as a scratch reg if it doesn't overlap any + inputs of NEWPAT. */ + + /* ??? If I2DEST is not safe, and I1DEST exists, then it would be + possible to try that as a scratch reg. This would require adding + more code to make it work though. */ + + if (m_split == 0 && ! reg_overlap_mentioned_p (ni2dest, newpat)) + { + /* If I2DEST is a hard register or the only use of a pseudo, + we can change its mode. */ + if (GET_MODE (SET_DEST (newpat)) != GET_MODE (i2dest) + && GET_MODE (SET_DEST (newpat)) != VOIDmode + && GET_CODE (i2dest) == REG + && (REGNO (i2dest) < FIRST_PSEUDO_REGISTER + || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2 + && ! REG_USERVAR_P (i2dest)))) + ni2dest = gen_rtx (REG, GET_MODE (SET_DEST (newpat)), + REGNO (i2dest)); + + m_split = split_insns (gen_rtx (PARALLEL, VOIDmode, + gen_rtvec (2, newpat, + gen_rtx (CLOBBER, + VOIDmode, + ni2dest))), + i3); + } + + if (m_split && GET_CODE (m_split) == SEQUENCE + && XVECLEN (m_split, 0) == 2 + && (next_real_insn (i2) == i3 + || ! use_crosses_set_p (PATTERN (XVECEXP (m_split, 0, 0)), + INSN_CUID (i2)))) + { + rtx i2set, i3set; + rtx newi3pat = PATTERN (XVECEXP (m_split, 0, 1)); + newi2pat = PATTERN (XVECEXP (m_split, 0, 0)); + + i3set = single_set (XVECEXP (m_split, 0, 1)); + i2set = single_set (XVECEXP (m_split, 0, 0)); + + /* In case we changed the mode of I2DEST, replace it in the + pseudo-register table here. We can't do it above in case this + code doesn't get executed and we do a split the other way. */ + + if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER) + SUBST (regno_reg_rtx[REGNO (i2dest)], ni2dest); + + i2_code_number = recog_for_combine (&newi2pat, i2, &new_i2_notes, + &i2_scratches); + + /* If I2 or I3 has multiple SETs, we won't know how to track + register status, so don't use these insns. */ + + if (i2_code_number >= 0 && i2set && i3set) + insn_code_number = recog_for_combine (&newi3pat, i3, &new_i3_notes, + &i3_scratches); + if (insn_code_number >= 0) + newpat = newi3pat; + + /* It is possible that both insns now set the destination of I3. + If so, we must show an extra use of it. */ + + if (insn_code_number >= 0 && GET_CODE (SET_DEST (i3set)) == REG + && GET_CODE (SET_DEST (i2set)) == REG + && REGNO (SET_DEST (i3set)) == REGNO (SET_DEST (i2set))) + reg_n_sets[REGNO (SET_DEST (i2set))]++; + } + + /* If we can split it and use I2DEST, go ahead and see if that + helps things be recognized. Verify that none of the registers + are set between I2 and I3. */ + if (insn_code_number < 0 && (split = find_split_point (&newpat, i3)) != 0 +#ifdef HAVE_cc0 + && GET_CODE (i2dest) == REG +#endif + /* We need I2DEST in the proper mode. If it is a hard register + or the only use of a pseudo, we can change its mode. */ + && (GET_MODE (*split) == GET_MODE (i2dest) + || GET_MODE (*split) == VOIDmode + || REGNO (i2dest) < FIRST_PSEUDO_REGISTER + || (reg_n_sets[REGNO (i2dest)] == 1 && ! added_sets_2 + && ! REG_USERVAR_P (i2dest))) + && (next_real_insn (i2) == i3 + || ! use_crosses_set_p (*split, INSN_CUID (i2))) + /* We can't overwrite I2DEST if its value is still used by + NEWPAT. */ + && ! reg_referenced_p (i2dest, newpat)) + { + rtx newdest = i2dest; + enum rtx_code split_code = GET_CODE (*split); + enum machine_mode split_mode = GET_MODE (*split); + + /* Get NEWDEST as a register in the proper mode. We have already + validated that we can do this. */ + if (GET_MODE (i2dest) != split_mode && split_mode != VOIDmode) + { + newdest = gen_rtx (REG, split_mode, REGNO (i2dest)); + + if (REGNO (i2dest) >= FIRST_PSEUDO_REGISTER) + SUBST (regno_reg_rtx[REGNO (i2dest)], newdest); + } + + /* If *SPLIT is a (mult FOO (const_int pow2)), convert it to + an ASHIFT. This can occur if it was inside a PLUS and hence + appeared to be a memory address. This is a kludge. */ + if (split_code == MULT + && GET_CODE (XEXP (*split, 1)) == CONST_INT + && (i = exact_log2 (INTVAL (XEXP (*split, 1)))) >= 0) + { + SUBST (*split, gen_rtx_combine (ASHIFT, split_mode, + XEXP (*split, 0), GEN_INT (i))); + /* Update split_code because we may not have a multiply + anymore. */ + split_code = GET_CODE (*split); + } + +#ifdef INSN_SCHEDULING + /* If *SPLIT is a paradoxical SUBREG, when we split it, it should + be written as a ZERO_EXTEND. */ + if (split_code == SUBREG && GET_CODE (SUBREG_REG (*split)) == MEM) + SUBST (*split, gen_rtx_combine (ZERO_EXTEND, split_mode, + XEXP (*split, 0))); +#endif + + newi2pat = gen_rtx_combine (SET, VOIDmode, newdest, *split); + SUBST (*split, newdest); + i2_code_number + = recog_for_combine (&newi2pat, i2, &new_i2_notes, &i2_scratches); + + /* If the split point was a MULT and we didn't have one before, + don't use one now. */ + if (i2_code_number >= 0 && ! (split_code == MULT && ! have_mult)) + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + } + } + + /* Check for a case where we loaded from memory in a narrow mode and + then sign extended it, but we need both registers. In that case, + we have a PARALLEL with both loads from the same memory location. + We can split this into a load from memory followed by a register-register + copy. This saves at least one insn, more if register allocation can + eliminate the copy. + + We cannot do this if the destination of the second assignment is + a register that we have already assumed is zero-extended. Similarly + for a SUBREG of such a register. */ + + else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0 + && GET_CODE (newpat) == PARALLEL + && XVECLEN (newpat, 0) == 2 + && GET_CODE (XVECEXP (newpat, 0, 0)) == SET + && GET_CODE (SET_SRC (XVECEXP (newpat, 0, 0))) == SIGN_EXTEND + && GET_CODE (XVECEXP (newpat, 0, 1)) == SET + && rtx_equal_p (SET_SRC (XVECEXP (newpat, 0, 1)), + XEXP (SET_SRC (XVECEXP (newpat, 0, 0)), 0)) + && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)), + INSN_CUID (i2)) + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART + && ! (temp = SET_DEST (XVECEXP (newpat, 0, 1)), + (GET_CODE (temp) == REG + && reg_nonzero_bits[REGNO (temp)] != 0 + && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD + && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT + && (reg_nonzero_bits[REGNO (temp)] + != GET_MODE_MASK (word_mode)))) + && ! (GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) == SUBREG + && (temp = SUBREG_REG (SET_DEST (XVECEXP (newpat, 0, 1))), + (GET_CODE (temp) == REG + && reg_nonzero_bits[REGNO (temp)] != 0 + && GET_MODE_BITSIZE (GET_MODE (temp)) < BITS_PER_WORD + && GET_MODE_BITSIZE (GET_MODE (temp)) < HOST_BITS_PER_INT + && (reg_nonzero_bits[REGNO (temp)] + != GET_MODE_MASK (word_mode))))) + && ! reg_overlap_mentioned_p (SET_DEST (XVECEXP (newpat, 0, 1)), + SET_SRC (XVECEXP (newpat, 0, 1))) + && ! find_reg_note (i3, REG_UNUSED, + SET_DEST (XVECEXP (newpat, 0, 0)))) + { + rtx ni2dest; + + newi2pat = XVECEXP (newpat, 0, 0); + ni2dest = SET_DEST (XVECEXP (newpat, 0, 0)); + newpat = XVECEXP (newpat, 0, 1); + SUBST (SET_SRC (newpat), + gen_lowpart_for_combine (GET_MODE (SET_SRC (newpat)), ni2dest)); + i2_code_number + = recog_for_combine (&newi2pat, i2, &new_i2_notes, &i2_scratches); + + if (i2_code_number >= 0) + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + + if (insn_code_number >= 0) + { + rtx insn; + rtx link; + + /* If we will be able to accept this, we have made a change to the + destination of I3. This can invalidate a LOG_LINKS pointing + to I3. No other part of combine.c makes such a transformation. + + The new I3 will have a destination that was previously the + destination of I1 or I2 and which was used in i2 or I3. Call + distribute_links to make a LOG_LINK from the next use of + that destination. */ + + PATTERN (i3) = newpat; + distribute_links (gen_rtx (INSN_LIST, VOIDmode, i3, NULL_RTX)); + + /* I3 now uses what used to be its destination and which is + now I2's destination. That means we need a LOG_LINK from + I3 to I2. But we used to have one, so we still will. + + However, some later insn might be using I2's dest and have + a LOG_LINK pointing at I3. We must remove this link. + The simplest way to remove the link is to point it at I1, + which we know will be a NOTE. */ + + for (insn = NEXT_INSN (i3); + insn && (this_basic_block == n_basic_blocks - 1 + || insn != basic_block_head[this_basic_block + 1]); + insn = NEXT_INSN (insn)) + { + if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' + && reg_referenced_p (ni2dest, PATTERN (insn))) + { + for (link = LOG_LINKS (insn); link; + link = XEXP (link, 1)) + if (XEXP (link, 0) == i3) + XEXP (link, 0) = i1; + + break; + } + } + } + } + + /* Similarly, check for a case where we have a PARALLEL of two independent + SETs but we started with three insns. In this case, we can do the sets + as two separate insns. This case occurs when some SET allows two + other insns to combine, but the destination of that SET is still live. */ + + else if (i1 && insn_code_number < 0 && asm_noperands (newpat) < 0 + && GET_CODE (newpat) == PARALLEL + && XVECLEN (newpat, 0) == 2 + && GET_CODE (XVECEXP (newpat, 0, 0)) == SET + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != ZERO_EXTRACT + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != STRICT_LOW_PART + && GET_CODE (XVECEXP (newpat, 0, 1)) == SET + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != ZERO_EXTRACT + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != STRICT_LOW_PART + && ! use_crosses_set_p (SET_SRC (XVECEXP (newpat, 0, 1)), + INSN_CUID (i2)) + /* Don't pass sets with (USE (MEM ...)) dests to the following. */ + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 1))) != USE + && GET_CODE (SET_DEST (XVECEXP (newpat, 0, 0))) != USE + && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 1)), + XVECEXP (newpat, 0, 0)) + && ! reg_referenced_p (SET_DEST (XVECEXP (newpat, 0, 0)), + XVECEXP (newpat, 0, 1))) + { + newi2pat = XVECEXP (newpat, 0, 1); + newpat = XVECEXP (newpat, 0, 0); + + i2_code_number + = recog_for_combine (&newi2pat, i2, &new_i2_notes, &i2_scratches); + + if (i2_code_number >= 0) + insn_code_number + = recog_for_combine (&newpat, i3, &new_i3_notes, &i3_scratches); + } + + /* If it still isn't recognized, fail and change things back the way they + were. */ + if ((insn_code_number < 0 + /* Is the result a reasonable ASM_OPERANDS? */ + && (! check_asm_operands (newpat) || added_sets_1 || added_sets_2))) + { + undo_all (); + return 0; + } + + /* If we had to change another insn, make sure it is valid also. */ + if (undobuf.other_insn) + { + rtx other_pat = PATTERN (undobuf.other_insn); + rtx new_other_notes; + rtx note, next; + + CLEAR_HARD_REG_SET (newpat_used_regs); + + other_code_number + = recog_for_combine (&other_pat, undobuf.other_insn, + &new_other_notes, &other_scratches); + + if (other_code_number < 0 && ! check_asm_operands (other_pat)) + { + undo_all (); + return 0; + } + + PATTERN (undobuf.other_insn) = other_pat; + + /* If any of the notes in OTHER_INSN were REG_UNUSED, ensure that they + are still valid. Then add any non-duplicate notes added by + recog_for_combine. */ + for (note = REG_NOTES (undobuf.other_insn); note; note = next) + { + next = XEXP (note, 1); + + if (REG_NOTE_KIND (note) == REG_UNUSED + && ! reg_set_p (XEXP (note, 0), PATTERN (undobuf.other_insn))) + { + if (GET_CODE (XEXP (note, 0)) == REG) + reg_n_deaths[REGNO (XEXP (note, 0))]--; + + remove_note (undobuf.other_insn, note); + } + } + + for (note = new_other_notes; note; note = XEXP (note, 1)) + if (GET_CODE (XEXP (note, 0)) == REG) + reg_n_deaths[REGNO (XEXP (note, 0))]++; + + distribute_notes (new_other_notes, undobuf.other_insn, + undobuf.other_insn, NULL_RTX, NULL_RTX, NULL_RTX); + } + + /* We now know that we can do this combination. Merge the insns and + update the status of registers and LOG_LINKS. */ + + { + rtx i3notes, i2notes, i1notes = 0; + rtx i3links, i2links, i1links = 0; + rtx midnotes = 0; + register int regno; + /* Compute which registers we expect to eliminate. */ + rtx elim_i2 = (newi2pat || i2dest_in_i2src || i2dest_in_i1src + ? 0 : i2dest); + rtx elim_i1 = i1 == 0 || i1dest_in_i1src ? 0 : i1dest; + + /* Get the old REG_NOTES and LOG_LINKS from all our insns and + clear them. */ + i3notes = REG_NOTES (i3), i3links = LOG_LINKS (i3); + i2notes = REG_NOTES (i2), i2links = LOG_LINKS (i2); + if (i1) + i1notes = REG_NOTES (i1), i1links = LOG_LINKS (i1); + + /* Ensure that we do not have something that should not be shared but + occurs multiple times in the new insns. Check this by first + resetting all the `used' flags and then copying anything is shared. */ + + reset_used_flags (i3notes); + reset_used_flags (i2notes); + reset_used_flags (i1notes); + reset_used_flags (newpat); + reset_used_flags (newi2pat); + if (undobuf.other_insn) + reset_used_flags (PATTERN (undobuf.other_insn)); + + i3notes = copy_rtx_if_shared (i3notes); + i2notes = copy_rtx_if_shared (i2notes); + i1notes = copy_rtx_if_shared (i1notes); + newpat = copy_rtx_if_shared (newpat); + newi2pat = copy_rtx_if_shared (newi2pat); + if (undobuf.other_insn) + reset_used_flags (PATTERN (undobuf.other_insn)); + + INSN_CODE (i3) = insn_code_number; + PATTERN (i3) = newpat; + if (undobuf.other_insn) + INSN_CODE (undobuf.other_insn) = other_code_number; + + /* We had one special case above where I2 had more than one set and + we replaced a destination of one of those sets with the destination + of I3. In that case, we have to update LOG_LINKS of insns later + in this basic block. Note that this (expensive) case is rare. + + Also, in this case, we must pretend that all REG_NOTEs for I2 + actually came from I3, so that REG_UNUSED notes from I2 will be + properly handled. */ + + if (i3_subst_into_i2) + { + for (i = 0; i < XVECLEN (PATTERN (i2), 0); i++) + if (GET_CODE (SET_DEST (XVECEXP (PATTERN (i2), 0, i))) == REG + && SET_DEST (XVECEXP (PATTERN (i2), 0, i)) != i2dest + && ! find_reg_note (i2, REG_UNUSED, + SET_DEST (XVECEXP (PATTERN (i2), 0, i)))) + for (temp = NEXT_INSN (i2); + temp && (this_basic_block == n_basic_blocks - 1 + || basic_block_head[this_basic_block] != temp); + temp = NEXT_INSN (temp)) + if (temp != i3 && GET_RTX_CLASS (GET_CODE (temp)) == 'i') + for (link = LOG_LINKS (temp); link; link = XEXP (link, 1)) + if (XEXP (link, 0) == i2) + XEXP (link, 0) = i3; + + if (i3notes) + { + rtx link = i3notes; + while (XEXP (link, 1)) + link = XEXP (link, 1); + XEXP (link, 1) = i2notes; + } + else + i3notes = i2notes; + i2notes = 0; + } + + LOG_LINKS (i3) = 0; + REG_NOTES (i3) = 0; + LOG_LINKS (i2) = 0; + REG_NOTES (i2) = 0; + + if (newi2pat) + { + INSN_CODE (i2) = i2_code_number; + PATTERN (i2) = newi2pat; + } + else + { + PUT_CODE (i2, NOTE); + NOTE_LINE_NUMBER (i2) = NOTE_INSN_DELETED; + NOTE_SOURCE_FILE (i2) = 0; + } + + if (i1) + { + LOG_LINKS (i1) = 0; + REG_NOTES (i1) = 0; + PUT_CODE (i1, NOTE); + NOTE_LINE_NUMBER (i1) = NOTE_INSN_DELETED; + NOTE_SOURCE_FILE (i1) = 0; + } + + /* Get death notes for everything that is now used in either I3 or + I2 and used to die in a previous insn. */ + + move_deaths (newpat, i1 ? INSN_CUID (i1) : INSN_CUID (i2), i3, &midnotes); + if (newi2pat) + move_deaths (newi2pat, INSN_CUID (i1), i2, &midnotes); + + /* Distribute all the LOG_LINKS and REG_NOTES from I1, I2, and I3. */ + if (i3notes) + distribute_notes (i3notes, i3, i3, newi2pat ? i2 : NULL_RTX, + elim_i2, elim_i1); + if (i2notes) + distribute_notes (i2notes, i2, i3, newi2pat ? i2 : NULL_RTX, + elim_i2, elim_i1); + if (i1notes) + distribute_notes (i1notes, i1, i3, newi2pat ? i2 : NULL_RTX, + elim_i2, elim_i1); + if (midnotes) + distribute_notes (midnotes, NULL_RTX, i3, newi2pat ? i2 : NULL_RTX, + elim_i2, elim_i1); + + /* Distribute any notes added to I2 or I3 by recog_for_combine. We + know these are REG_UNUSED and want them to go to the desired insn, + so we always pass it as i3. We have not counted the notes in + reg_n_deaths yet, so we need to do so now. */ + + if (newi2pat && new_i2_notes) + { + for (temp = new_i2_notes; temp; temp = XEXP (temp, 1)) + if (GET_CODE (XEXP (temp, 0)) == REG) + reg_n_deaths[REGNO (XEXP (temp, 0))]++; + + distribute_notes (new_i2_notes, i2, i2, NULL_RTX, NULL_RTX, NULL_RTX); + } + + if (new_i3_notes) + { + for (temp = new_i3_notes; temp; temp = XEXP (temp, 1)) + if (GET_CODE (XEXP (temp, 0)) == REG) + reg_n_deaths[REGNO (XEXP (temp, 0))]++; + + distribute_notes (new_i3_notes, i3, i3, NULL_RTX, NULL_RTX, NULL_RTX); + } + + /* If I3DEST was used in I3SRC, it really died in I3. We may need to + put a REG_DEAD note for it somewhere. Similarly for I2 and I1. + Show an additional death due to the REG_DEAD note we make here. If + we discard it in distribute_notes, we will decrement it again. */ + + if (i3dest_killed) + { + if (GET_CODE (i3dest_killed) == REG) + reg_n_deaths[REGNO (i3dest_killed)]++; + + distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i3dest_killed, + NULL_RTX), + NULL_RTX, i3, newi2pat ? i2 : NULL_RTX, + NULL_RTX, NULL_RTX); + } + + /* For I2 and I1, we have to be careful. If NEWI2PAT exists and sets + I2DEST or I1DEST, the death must be somewhere before I2, not I3. If + we passed I3 in that case, it might delete I2. */ + + if (i2dest_in_i2src) + { + if (GET_CODE (i2dest) == REG) + reg_n_deaths[REGNO (i2dest)]++; + + if (newi2pat && reg_set_p (i2dest, newi2pat)) + distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX), + NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX); + else + distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i2dest, NULL_RTX), + NULL_RTX, i3, newi2pat ? i2 : NULL_RTX, + NULL_RTX, NULL_RTX); + } + + if (i1dest_in_i1src) + { + if (GET_CODE (i1dest) == REG) + reg_n_deaths[REGNO (i1dest)]++; + + if (newi2pat && reg_set_p (i1dest, newi2pat)) + distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX), + NULL_RTX, i2, NULL_RTX, NULL_RTX, NULL_RTX); + else + distribute_notes (gen_rtx (EXPR_LIST, REG_DEAD, i1dest, NULL_RTX), + NULL_RTX, i3, newi2pat ? i2 : NULL_RTX, + NULL_RTX, NULL_RTX); + } + + distribute_links (i3links); + distribute_links (i2links); + distribute_links (i1links); + + if (GET_CODE (i2dest) == REG) + { + rtx link; + rtx i2_insn = 0, i2_val = 0, set; + + /* The insn that used to set this register doesn't exist, and + this life of the register may not exist either. See if one of + I3's links points to an insn that sets I2DEST. If it does, + that is now the last known value for I2DEST. If we don't update + this and I2 set the register to a value that depended on its old + contents, we will get confused. If this insn is used, thing + will be set correctly in combine_instructions. */ + + for (link = LOG_LINKS (i3); link; link = XEXP (link, 1)) + if ((set = single_set (XEXP (link, 0))) != 0 + && rtx_equal_p (i2dest, SET_DEST (set))) + i2_insn = XEXP (link, 0), i2_val = SET_SRC (set); + + record_value_for_reg (i2dest, i2_insn, i2_val); + + /* If the reg formerly set in I2 died only once and that was in I3, + zero its use count so it won't make `reload' do any work. */ + if (! added_sets_2 && newi2pat == 0 && ! i2dest_in_i2src) + { + regno = REGNO (i2dest); + reg_n_sets[regno]--; + if (reg_n_sets[regno] == 0 + && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS] + & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS)))) + reg_n_refs[regno] = 0; + } + } + + if (i1 && GET_CODE (i1dest) == REG) + { + rtx link; + rtx i1_insn = 0, i1_val = 0, set; + + for (link = LOG_LINKS (i3); link; link = XEXP (link, 1)) + if ((set = single_set (XEXP (link, 0))) != 0 + && rtx_equal_p (i1dest, SET_DEST (set))) + i1_insn = XEXP (link, 0), i1_val = SET_SRC (set); + + record_value_for_reg (i1dest, i1_insn, i1_val); + + regno = REGNO (i1dest); + if (! added_sets_1 && ! i1dest_in_i1src) + { + reg_n_sets[regno]--; + if (reg_n_sets[regno] == 0 + && ! (basic_block_live_at_start[0][regno / REGSET_ELT_BITS] + & ((REGSET_ELT_TYPE) 1 << (regno % REGSET_ELT_BITS)))) + reg_n_refs[regno] = 0; + } + } + + /* Update reg_nonzero_bits et al for any changes that may have been made + to this insn. */ + + note_stores (newpat, set_nonzero_bits_and_sign_copies); + if (newi2pat) + note_stores (newi2pat, set_nonzero_bits_and_sign_copies); + + /* If we added any (clobber (scratch)), add them to the max for a + block. This is a very pessimistic calculation, since we might + have had them already and this might not be the worst block, but + it's not worth doing any better. */ + max_scratch += i3_scratches + i2_scratches + other_scratches; + + /* If I3 is now an unconditional jump, ensure that it has a + BARRIER following it since it may have initially been a + conditional jump. It may also be the last nonnote insn. */ + + if ((GET_CODE (newpat) == RETURN || simplejump_p (i3)) + && ((temp = next_nonnote_insn (i3)) == NULL_RTX + || GET_CODE (temp) != BARRIER)) + emit_barrier_after (i3); + } + + combine_successes++; + + /* Clear this here, so that subsequent get_last_value calls are not + affected. */ + subst_prev_insn = NULL_RTX; + + if (added_links_insn + && (newi2pat == 0 || INSN_CUID (added_links_insn) < INSN_CUID (i2)) + && INSN_CUID (added_links_insn) < INSN_CUID (i3)) + return added_links_insn; + else + return newi2pat ? i2 : i3; +} + +/* Undo all the modifications recorded in undobuf. */ + +static void +undo_all () +{ + register int i; + if (undobuf.num_undo > MAX_UNDO) + undobuf.num_undo = MAX_UNDO; + for (i = undobuf.num_undo - 1; i >= 0; i--) + { + if (undobuf.undo[i].is_int) + *undobuf.undo[i].where.i = undobuf.undo[i].old_contents.i; + else + *undobuf.undo[i].where.r = undobuf.undo[i].old_contents.r; + + } + + obfree (undobuf.storage); + undobuf.num_undo = 0; + + /* Clear this here, so that subsequent get_last_value calls are not + affected. */ + subst_prev_insn = NULL_RTX; +} + +/* Find the innermost point within the rtx at LOC, possibly LOC itself, + where we have an arithmetic expression and return that point. LOC will + be inside INSN. + + try_combine will call this function to see if an insn can be split into + two insns. */ + +static rtx * +find_split_point (loc, insn) + rtx *loc; + rtx insn; +{ + rtx x = *loc; + enum rtx_code code = GET_CODE (x); + rtx *split; + int len = 0, pos, unsignedp; + rtx inner; + + /* First special-case some codes. */ + switch (code) + { + case SUBREG: +#ifdef INSN_SCHEDULING + /* If we are making a paradoxical SUBREG invalid, it becomes a split + point. */ + if (GET_CODE (SUBREG_REG (x)) == MEM) + return loc; +#endif + return find_split_point (&SUBREG_REG (x), insn); + + case MEM: +#ifdef HAVE_lo_sum + /* If we have (mem (const ..)) or (mem (symbol_ref ...)), split it + using LO_SUM and HIGH. */ + if (GET_CODE (XEXP (x, 0)) == CONST + || GET_CODE (XEXP (x, 0)) == SYMBOL_REF) + { + SUBST (XEXP (x, 0), + gen_rtx_combine (LO_SUM, Pmode, + gen_rtx_combine (HIGH, Pmode, XEXP (x, 0)), + XEXP (x, 0))); + return &XEXP (XEXP (x, 0), 0); + } +#endif + + /* If we have a PLUS whose second operand is a constant and the + address is not valid, perhaps will can split it up using + the machine-specific way to split large constants. We use + the first pseudo-reg (one of the virtual regs) as a placeholder; + it will not remain in the result. */ + if (GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && ! memory_address_p (GET_MODE (x), XEXP (x, 0))) + { + rtx reg = regno_reg_rtx[FIRST_PSEUDO_REGISTER]; + rtx seq = split_insns (gen_rtx (SET, VOIDmode, reg, XEXP (x, 0)), + subst_insn); + + /* This should have produced two insns, each of which sets our + placeholder. If the source of the second is a valid address, + we can make put both sources together and make a split point + in the middle. */ + + if (seq && XVECLEN (seq, 0) == 2 + && GET_CODE (XVECEXP (seq, 0, 0)) == INSN + && GET_CODE (PATTERN (XVECEXP (seq, 0, 0))) == SET + && SET_DEST (PATTERN (XVECEXP (seq, 0, 0))) == reg + && ! reg_mentioned_p (reg, + SET_SRC (PATTERN (XVECEXP (seq, 0, 0)))) + && GET_CODE (XVECEXP (seq, 0, 1)) == INSN + && GET_CODE (PATTERN (XVECEXP (seq, 0, 1))) == SET + && SET_DEST (PATTERN (XVECEXP (seq, 0, 1))) == reg + && memory_address_p (GET_MODE (x), + SET_SRC (PATTERN (XVECEXP (seq, 0, 1))))) + { + rtx src1 = SET_SRC (PATTERN (XVECEXP (seq, 0, 0))); + rtx src2 = SET_SRC (PATTERN (XVECEXP (seq, 0, 1))); + + /* Replace the placeholder in SRC2 with SRC1. If we can + find where in SRC2 it was placed, that can become our + split point and we can replace this address with SRC2. + Just try two obvious places. */ + + src2 = replace_rtx (src2, reg, src1); + split = 0; + if (XEXP (src2, 0) == src1) + split = &XEXP (src2, 0); + else if (GET_RTX_FORMAT (GET_CODE (XEXP (src2, 0)))[0] == 'e' + && XEXP (XEXP (src2, 0), 0) == src1) + split = &XEXP (XEXP (src2, 0), 0); + + if (split) + { + SUBST (XEXP (x, 0), src2); + return split; + } + } + + /* If that didn't work, perhaps the first operand is complex and + needs to be computed separately, so make a split point there. + This will occur on machines that just support REG + CONST + and have a constant moved through some previous computation. */ + + else if (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (x, 0), 0))) != 'o' + && ! (GET_CODE (XEXP (XEXP (x, 0), 0)) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (XEXP (x, 0), 0)))) + == 'o'))) + return &XEXP (XEXP (x, 0), 0); + } + break; + + case SET: +#ifdef HAVE_cc0 + /* If SET_DEST is CC0 and SET_SRC is not an operand, a COMPARE, or a + ZERO_EXTRACT, the most likely reason why this doesn't match is that + we need to put the operand into a register. So split at that + point. */ + + if (SET_DEST (x) == cc0_rtx + && GET_CODE (SET_SRC (x)) != COMPARE + && GET_CODE (SET_SRC (x)) != ZERO_EXTRACT + && GET_RTX_CLASS (GET_CODE (SET_SRC (x))) != 'o' + && ! (GET_CODE (SET_SRC (x)) == SUBREG + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (SET_SRC (x)))) == 'o')) + return &SET_SRC (x); +#endif + + /* See if we can split SET_SRC as it stands. */ + split = find_split_point (&SET_SRC (x), insn); + if (split && split != &SET_SRC (x)) + return split; + + /* See if this is a bitfield assignment with everything constant. If + so, this is an IOR of an AND, so split it into that. */ + if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT + && (GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0))) + <= HOST_BITS_PER_WIDE_INT) + && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT + && GET_CODE (XEXP (SET_DEST (x), 2)) == CONST_INT + && GET_CODE (SET_SRC (x)) == CONST_INT + && ((INTVAL (XEXP (SET_DEST (x), 1)) + + INTVAL (XEXP (SET_DEST (x), 2))) + <= GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0)))) + && ! side_effects_p (XEXP (SET_DEST (x), 0))) + { + int pos = INTVAL (XEXP (SET_DEST (x), 2)); + int len = INTVAL (XEXP (SET_DEST (x), 1)); + int src = INTVAL (SET_SRC (x)); + rtx dest = XEXP (SET_DEST (x), 0); + enum machine_mode mode = GET_MODE (dest); + unsigned HOST_WIDE_INT mask = ((HOST_WIDE_INT) 1 << len) - 1; + + if (BITS_BIG_ENDIAN) + pos = GET_MODE_BITSIZE (mode) - len - pos; + + if (src == mask) + SUBST (SET_SRC (x), + gen_binary (IOR, mode, dest, GEN_INT (src << pos))); + else + SUBST (SET_SRC (x), + gen_binary (IOR, mode, + gen_binary (AND, mode, dest, + GEN_INT (~ (mask << pos) + & GET_MODE_MASK (mode))), + GEN_INT (src << pos))); + + SUBST (SET_DEST (x), dest); + + split = find_split_point (&SET_SRC (x), insn); + if (split && split != &SET_SRC (x)) + return split; + } + + /* Otherwise, see if this is an operation that we can split into two. + If so, try to split that. */ + code = GET_CODE (SET_SRC (x)); + + switch (code) + { + case AND: + /* If we are AND'ing with a large constant that is only a single + bit and the result is only being used in a context where we + need to know if it is zero or non-zero, replace it with a bit + extraction. This will avoid the large constant, which might + have taken more than one insn to make. If the constant were + not a valid argument to the AND but took only one insn to make, + this is no worse, but if it took more than one insn, it will + be better. */ + + if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT + && GET_CODE (XEXP (SET_SRC (x), 0)) == REG + && (pos = exact_log2 (INTVAL (XEXP (SET_SRC (x), 1)))) >= 7 + && GET_CODE (SET_DEST (x)) == REG + && (split = find_single_use (SET_DEST (x), insn, NULL_PTR)) != 0 + && (GET_CODE (*split) == EQ || GET_CODE (*split) == NE) + && XEXP (*split, 0) == SET_DEST (x) + && XEXP (*split, 1) == const0_rtx) + { + SUBST (SET_SRC (x), + make_extraction (GET_MODE (SET_DEST (x)), + XEXP (SET_SRC (x), 0), + pos, NULL_RTX, 1, 1, 0, 0)); + return find_split_point (loc, insn); + } + break; + + case SIGN_EXTEND: + inner = XEXP (SET_SRC (x), 0); + pos = 0; + len = GET_MODE_BITSIZE (GET_MODE (inner)); + unsignedp = 0; + break; + + case SIGN_EXTRACT: + case ZERO_EXTRACT: + if (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT + && GET_CODE (XEXP (SET_SRC (x), 2)) == CONST_INT) + { + inner = XEXP (SET_SRC (x), 0); + len = INTVAL (XEXP (SET_SRC (x), 1)); + pos = INTVAL (XEXP (SET_SRC (x), 2)); + + if (BITS_BIG_ENDIAN) + pos = GET_MODE_BITSIZE (GET_MODE (inner)) - len - pos; + unsignedp = (code == ZERO_EXTRACT); + } + break; + } + + if (len && pos >= 0 && pos + len <= GET_MODE_BITSIZE (GET_MODE (inner))) + { + enum machine_mode mode = GET_MODE (SET_SRC (x)); + + /* For unsigned, we have a choice of a shift followed by an + AND or two shifts. Use two shifts for field sizes where the + constant might be too large. We assume here that we can + always at least get 8-bit constants in an AND insn, which is + true for every current RISC. */ + + if (unsignedp && len <= 8) + { + SUBST (SET_SRC (x), + gen_rtx_combine + (AND, mode, + gen_rtx_combine (LSHIFTRT, mode, + gen_lowpart_for_combine (mode, inner), + GEN_INT (pos)), + GEN_INT (((HOST_WIDE_INT) 1 << len) - 1))); + + split = find_split_point (&SET_SRC (x), insn); + if (split && split != &SET_SRC (x)) + return split; + } + else + { + SUBST (SET_SRC (x), + gen_rtx_combine + (unsignedp ? LSHIFTRT : ASHIFTRT, mode, + gen_rtx_combine (ASHIFT, mode, + gen_lowpart_for_combine (mode, inner), + GEN_INT (GET_MODE_BITSIZE (mode) + - len - pos)), + GEN_INT (GET_MODE_BITSIZE (mode) - len))); + + split = find_split_point (&SET_SRC (x), insn); + if (split && split != &SET_SRC (x)) + return split; + } + } + + /* See if this is a simple operation with a constant as the second + operand. It might be that this constant is out of range and hence + could be used as a split point. */ + if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2' + || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c' + || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<') + && CONSTANT_P (XEXP (SET_SRC (x), 1)) + && (GET_RTX_CLASS (GET_CODE (XEXP (SET_SRC (x), 0))) == 'o' + || (GET_CODE (XEXP (SET_SRC (x), 0)) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (SET_SRC (x), 0)))) + == 'o')))) + return &XEXP (SET_SRC (x), 1); + + /* Finally, see if this is a simple operation with its first operand + not in a register. The operation might require this operand in a + register, so return it as a split point. We can always do this + because if the first operand were another operation, we would have + already found it as a split point. */ + if ((GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '2' + || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == 'c' + || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '<' + || GET_RTX_CLASS (GET_CODE (SET_SRC (x))) == '1') + && ! register_operand (XEXP (SET_SRC (x), 0), VOIDmode)) + return &XEXP (SET_SRC (x), 0); + + return 0; + + case AND: + case IOR: + /* We write NOR as (and (not A) (not B)), but if we don't have a NOR, + it is better to write this as (not (ior A B)) so we can split it. + Similarly for IOR. */ + if (GET_CODE (XEXP (x, 0)) == NOT && GET_CODE (XEXP (x, 1)) == NOT) + { + SUBST (*loc, + gen_rtx_combine (NOT, GET_MODE (x), + gen_rtx_combine (code == IOR ? AND : IOR, + GET_MODE (x), + XEXP (XEXP (x, 0), 0), + XEXP (XEXP (x, 1), 0)))); + return find_split_point (loc, insn); + } + + /* Many RISC machines have a large set of logical insns. If the + second operand is a NOT, put it first so we will try to split the + other operand first. */ + if (GET_CODE (XEXP (x, 1)) == NOT) + { + rtx tem = XEXP (x, 0); + SUBST (XEXP (x, 0), XEXP (x, 1)); + SUBST (XEXP (x, 1), tem); + } + break; + } + + /* Otherwise, select our actions depending on our rtx class. */ + switch (GET_RTX_CLASS (code)) + { + case 'b': /* This is ZERO_EXTRACT and SIGN_EXTRACT. */ + case '3': + split = find_split_point (&XEXP (x, 2), insn); + if (split) + return split; + /* ... fall through ... */ + case '2': + case 'c': + case '<': + split = find_split_point (&XEXP (x, 1), insn); + if (split) + return split; + /* ... fall through ... */ + case '1': + /* Some machines have (and (shift ...) ...) insns. If X is not + an AND, but XEXP (X, 0) is, use it as our split point. */ + if (GET_CODE (x) != AND && GET_CODE (XEXP (x, 0)) == AND) + return &XEXP (x, 0); + + split = find_split_point (&XEXP (x, 0), insn); + if (split) + return split; + return loc; + } + + /* Otherwise, we don't have a split point. */ + return 0; +} + +/* Throughout X, replace FROM with TO, and return the result. + The result is TO if X is FROM; + otherwise the result is X, but its contents may have been modified. + If they were modified, a record was made in undobuf so that + undo_all will (among other things) return X to its original state. + + If the number of changes necessary is too much to record to undo, + the excess changes are not made, so the result is invalid. + The changes already made can still be undone. + undobuf.num_undo is incremented for such changes, so by testing that + the caller can tell whether the result is valid. + + `n_occurrences' is incremented each time FROM is replaced. + + IN_DEST is non-zero if we are processing the SET_DEST of a SET. + + UNIQUE_COPY is non-zero if each substitution must be unique. We do this + by copying if `n_occurrences' is non-zero. */ + +static rtx +subst (x, from, to, in_dest, unique_copy) + register rtx x, from, to; + int in_dest; + int unique_copy; +{ + register enum rtx_code code = GET_CODE (x); + enum machine_mode op0_mode = VOIDmode; + register char *fmt; + register int len, i; + rtx new; + +/* Two expressions are equal if they are identical copies of a shared + RTX or if they are both registers with the same register number + and mode. */ + +#define COMBINE_RTX_EQUAL_P(X,Y) \ + ((X) == (Y) \ + || (GET_CODE (X) == REG && GET_CODE (Y) == REG \ + && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y))) + + if (! in_dest && COMBINE_RTX_EQUAL_P (x, from)) + { + n_occurrences++; + return (unique_copy && n_occurrences > 1 ? copy_rtx (to) : to); + } + + /* If X and FROM are the same register but different modes, they will + not have been seen as equal above. However, flow.c will make a + LOG_LINKS entry for that case. If we do nothing, we will try to + rerecognize our original insn and, when it succeeds, we will + delete the feeding insn, which is incorrect. + + So force this insn not to match in this (rare) case. */ + if (! in_dest && code == REG && GET_CODE (from) == REG + && REGNO (x) == REGNO (from)) + return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx); + + /* If this is an object, we are done unless it is a MEM or LO_SUM, both + of which may contain things that can be combined. */ + if (code != MEM && code != LO_SUM && GET_RTX_CLASS (code) == 'o') + return x; + + /* It is possible to have a subexpression appear twice in the insn. + Suppose that FROM is a register that appears within TO. + Then, after that subexpression has been scanned once by `subst', + the second time it is scanned, TO may be found. If we were + to scan TO here, we would find FROM within it and create a + self-referent rtl structure which is completely wrong. */ + if (COMBINE_RTX_EQUAL_P (x, to)) + return to; + + len = GET_RTX_LENGTH (code); + fmt = GET_RTX_FORMAT (code); + + /* We don't need to process a SET_DEST that is a register, CC0, or PC, so + set up to skip this common case. All other cases where we want to + suppress replacing something inside a SET_SRC are handled via the + IN_DEST operand. */ + if (code == SET + && (GET_CODE (SET_DEST (x)) == REG + || GET_CODE (SET_DEST (x)) == CC0 + || GET_CODE (SET_DEST (x)) == PC)) + fmt = "ie"; + + /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a constant. */ + if (fmt[0] == 'e') + op0_mode = GET_MODE (XEXP (x, 0)); + + for (i = 0; i < len; i++) + { + if (fmt[i] == 'E') + { + register int j; + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + { + if (COMBINE_RTX_EQUAL_P (XVECEXP (x, i, j), from)) + { + new = (unique_copy && n_occurrences ? copy_rtx (to) : to); + n_occurrences++; + } + else + { + new = subst (XVECEXP (x, i, j), from, to, 0, unique_copy); + + /* If this substitution failed, this whole thing fails. */ + if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx) + return new; + } + + SUBST (XVECEXP (x, i, j), new); + } + } + else if (fmt[i] == 'e') + { + if (COMBINE_RTX_EQUAL_P (XEXP (x, i), from)) + { + /* In general, don't install a subreg involving two modes not + tieable. It can worsen register allocation, and can even + make invalid reload insns, since the reg inside may need to + be copied from in the outside mode, and that may be invalid + if it is an fp reg copied in integer mode. + + We allow two exceptions to this: It is valid if it is inside + another SUBREG and the mode of that SUBREG and the mode of + the inside of TO is tieable and it is valid if X is a SET + that copies FROM to CC0. */ + if (GET_CODE (to) == SUBREG + && ! MODES_TIEABLE_P (GET_MODE (to), + GET_MODE (SUBREG_REG (to))) + && ! (code == SUBREG + && MODES_TIEABLE_P (GET_MODE (x), + GET_MODE (SUBREG_REG (to)))) +#ifdef HAVE_cc0 + && ! (code == SET && i == 1 && XEXP (x, 0) == cc0_rtx) +#endif + ) + return gen_rtx (CLOBBER, VOIDmode, const0_rtx); + + new = (unique_copy && n_occurrences ? copy_rtx (to) : to); + n_occurrences++; + } + else + /* If we are in a SET_DEST, suppress most cases unless we + have gone inside a MEM, in which case we want to + simplify the address. We assume here that things that + are actually part of the destination have their inner + parts in the first expression. This is true for SUBREG, + STRICT_LOW_PART, and ZERO_EXTRACT, which are the only + things aside from REG and MEM that should appear in a + SET_DEST. */ + new = subst (XEXP (x, i), from, to, + (((in_dest + && (code == SUBREG || code == STRICT_LOW_PART + || code == ZERO_EXTRACT)) + || code == SET) + && i == 0), unique_copy); + + /* If we found that we will have to reject this combination, + indicate that by returning the CLOBBER ourselves, rather than + an expression containing it. This will speed things up as + well as prevent accidents where two CLOBBERs are considered + to be equal, thus producing an incorrect simplification. */ + + if (GET_CODE (new) == CLOBBER && XEXP (new, 0) == const0_rtx) + return new; + + SUBST (XEXP (x, i), new); + } + } + + /* Try to simplify X. If the simplification changed the code, it is likely + that further simplification will help, so loop, but limit the number + of repetitions that will be performed. */ + + for (i = 0; i < 4; i++) + { + /* If X is sufficiently simple, don't bother trying to do anything + with it. */ + if (code != CONST_INT && code != REG && code != CLOBBER) + x = simplify_rtx (x, op0_mode, i == 3, in_dest); + + if (GET_CODE (x) == code) + break; + + code = GET_CODE (x); + + /* We no longer know the original mode of operand 0 since we + have changed the form of X) */ + op0_mode = VOIDmode; + } + + return x; +} + +/* Simplify X, a piece of RTL. We just operate on the expression at the + outer level; call `subst' to simplify recursively. Return the new + expression. + + OP0_MODE is the original mode of XEXP (x, 0); LAST is nonzero if this + will be the iteration even if an expression with a code different from + X is returned; IN_DEST is nonzero if we are inside a SET_DEST. */ + +static rtx +simplify_rtx (x, op0_mode, last, in_dest) + rtx x; + enum machine_mode op0_mode; + int last; + int in_dest; +{ + enum rtx_code code = GET_CODE (x); + enum machine_mode mode = GET_MODE (x); + rtx temp; + int i; + + /* If this is a commutative operation, put a constant last and a complex + expression first. We don't need to do this for comparisons here. */ + if (GET_RTX_CLASS (code) == 'c' + && ((CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT) + || (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'o' + && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o') + || (GET_CODE (XEXP (x, 0)) == SUBREG + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) == 'o' + && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o'))) + { + temp = XEXP (x, 0); + SUBST (XEXP (x, 0), XEXP (x, 1)); + SUBST (XEXP (x, 1), temp); + } + + /* If this is a PLUS, MINUS, or MULT, and the first operand is the + sign extension of a PLUS with a constant, reverse the order of the sign + extension and the addition. Note that this not the same as the original + code, but overflow is undefined for signed values. Also note that the + PLUS will have been partially moved "inside" the sign-extension, so that + the first operand of X will really look like: + (ashiftrt (plus (ashift A C4) C5) C4). + We convert this to + (plus (ashiftrt (ashift A C4) C2) C4) + and replace the first operand of X with that expression. Later parts + of this function may simplify the expression further. + + For example, if we start with (mult (sign_extend (plus A C1)) C2), + we swap the SIGN_EXTEND and PLUS. Later code will apply the + distributive law to produce (plus (mult (sign_extend X) C1) C3). + + We do this to simplify address expressions. */ + + if ((code == PLUS || code == MINUS || code == MULT) + && GET_CODE (XEXP (x, 0)) == ASHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS + && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ASHIFT + && GET_CODE (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1)) == CONST_INT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 1) == XEXP (XEXP (x, 0), 1) + && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT + && (temp = simplify_binary_operation (ASHIFTRT, mode, + XEXP (XEXP (XEXP (x, 0), 0), 1), + XEXP (XEXP (x, 0), 1))) != 0) + { + rtx new + = simplify_shift_const (NULL_RTX, ASHIFT, mode, + XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 0), + INTVAL (XEXP (XEXP (x, 0), 1))); + + new = simplify_shift_const (NULL_RTX, ASHIFTRT, mode, new, + INTVAL (XEXP (XEXP (x, 0), 1))); + + SUBST (XEXP (x, 0), gen_binary (PLUS, mode, new, temp)); + } + + /* If this is a simple operation applied to an IF_THEN_ELSE, try + applying it to the arms of the IF_THEN_ELSE. This often simplifies + things. Check for cases where both arms are testing the same + condition. + + Don't do anything if all operands are very simple. */ + + if (((GET_RTX_CLASS (code) == '2' || GET_RTX_CLASS (code) == 'c' + || GET_RTX_CLASS (code) == '<') + && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o' + && ! (GET_CODE (XEXP (x, 0)) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) + == 'o'))) + || (GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) != 'o' + && ! (GET_CODE (XEXP (x, 1)) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 1)))) + == 'o'))))) + || (GET_RTX_CLASS (code) == '1' + && ((GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) != 'o' + && ! (GET_CODE (XEXP (x, 0)) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (XEXP (x, 0)))) + == 'o')))))) + { + rtx cond, true, false; + + cond = if_then_else_cond (x, &true, &false); + if (cond != 0) + { + rtx cop1 = const0_rtx; + enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1); + + if (cond_code == NE && GET_RTX_CLASS (GET_CODE (cond)) == '<') + return x; + + /* Simplify the alternative arms; this may collapse the true and + false arms to store-flag values. */ + true = subst (true, pc_rtx, pc_rtx, 0, 0); + false = subst (false, pc_rtx, pc_rtx, 0, 0); + + /* Restarting if we generate a store-flag expression will cause + us to loop. Just drop through in this case. */ + + /* If the result values are STORE_FLAG_VALUE and zero, we can + just make the comparison operation. */ + if (true == const_true_rtx && false == const0_rtx) + x = gen_binary (cond_code, mode, cond, cop1); + else if (true == const0_rtx && false == const_true_rtx) + x = gen_binary (reverse_condition (cond_code), mode, cond, cop1); + + /* Likewise, we can make the negate of a comparison operation + if the result values are - STORE_FLAG_VALUE and zero. */ + else if (GET_CODE (true) == CONST_INT + && INTVAL (true) == - STORE_FLAG_VALUE + && false == const0_rtx) + x = gen_unary (NEG, mode, mode, + gen_binary (cond_code, mode, cond, cop1)); + else if (GET_CODE (false) == CONST_INT + && INTVAL (false) == - STORE_FLAG_VALUE + && true == const0_rtx) + x = gen_unary (NEG, mode, mode, + gen_binary (reverse_condition (cond_code), + mode, cond, cop1)); + else + return gen_rtx (IF_THEN_ELSE, mode, + gen_binary (cond_code, VOIDmode, cond, cop1), + true, false); + + code = GET_CODE (x); + op0_mode = VOIDmode; + } + } + + /* Try to fold this expression in case we have constants that weren't + present before. */ + temp = 0; + switch (GET_RTX_CLASS (code)) + { + case '1': + temp = simplify_unary_operation (code, mode, XEXP (x, 0), op0_mode); + break; + case '<': + temp = simplify_relational_operation (code, op0_mode, + XEXP (x, 0), XEXP (x, 1)); +#ifdef FLOAT_STORE_FLAG_VALUE + if (temp != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) + temp = ((temp == const0_rtx) ? CONST0_RTX (GET_MODE (x)) + : immed_real_const_1 (FLOAT_STORE_FLAG_VALUE, GET_MODE (x))); +#endif + break; + case 'c': + case '2': + temp = simplify_binary_operation (code, mode, XEXP (x, 0), XEXP (x, 1)); + break; + case 'b': + case '3': + temp = simplify_ternary_operation (code, mode, op0_mode, XEXP (x, 0), + XEXP (x, 1), XEXP (x, 2)); + break; + } + + if (temp) + x = temp, code = GET_CODE (temp); + + /* First see if we can apply the inverse distributive law. */ + if (code == PLUS || code == MINUS + || code == AND || code == IOR || code == XOR) + { + x = apply_distributive_law (x); + code = GET_CODE (x); + } + + /* If CODE is an associative operation not otherwise handled, see if we + can associate some operands. This can win if they are constants or + if they are logically related (i.e. (a & b) & a. */ + if ((code == PLUS || code == MINUS + || code == MULT || code == AND || code == IOR || code == XOR + || code == DIV || code == UDIV + || code == SMAX || code == SMIN || code == UMAX || code == UMIN) + && INTEGRAL_MODE_P (mode)) + { + if (GET_CODE (XEXP (x, 0)) == code) + { + rtx other = XEXP (XEXP (x, 0), 0); + rtx inner_op0 = XEXP (XEXP (x, 0), 1); + rtx inner_op1 = XEXP (x, 1); + rtx inner; + + /* Make sure we pass the constant operand if any as the second + one if this is a commutative operation. */ + if (CONSTANT_P (inner_op0) && GET_RTX_CLASS (code) == 'c') + { + rtx tem = inner_op0; + inner_op0 = inner_op1; + inner_op1 = tem; + } + inner = simplify_binary_operation (code == MINUS ? PLUS + : code == DIV ? MULT + : code == UDIV ? MULT + : code, + mode, inner_op0, inner_op1); + + /* For commutative operations, try the other pair if that one + didn't simplify. */ + if (inner == 0 && GET_RTX_CLASS (code) == 'c') + { + other = XEXP (XEXP (x, 0), 1); + inner = simplify_binary_operation (code, mode, + XEXP (XEXP (x, 0), 0), + XEXP (x, 1)); + } + + if (inner) + return gen_binary (code, mode, other, inner); + } + } + + /* A little bit of algebraic simplification here. */ + switch (code) + { + case MEM: + /* Ensure that our address has any ASHIFTs converted to MULT in case + address-recognizing predicates are called later. */ + temp = make_compound_operation (XEXP (x, 0), MEM); + SUBST (XEXP (x, 0), temp); + break; + + case SUBREG: + /* (subreg:A (mem:B X) N) becomes a modified MEM unless the SUBREG + is paradoxical. If we can't do that safely, then it becomes + something nonsensical so that this combination won't take place. */ + + if (GET_CODE (SUBREG_REG (x)) == MEM + && (GET_MODE_SIZE (mode) + <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) + { + rtx inner = SUBREG_REG (x); + int endian_offset = 0; + /* Don't change the mode of the MEM + if that would change the meaning of the address. */ + if (MEM_VOLATILE_P (SUBREG_REG (x)) + || mode_dependent_address_p (XEXP (inner, 0))) + return gen_rtx (CLOBBER, mode, const0_rtx); + + if (BYTES_BIG_ENDIAN) + { + if (GET_MODE_SIZE (mode) < UNITS_PER_WORD) + endian_offset += UNITS_PER_WORD - GET_MODE_SIZE (mode); + if (GET_MODE_SIZE (GET_MODE (inner)) < UNITS_PER_WORD) + endian_offset -= (UNITS_PER_WORD + - GET_MODE_SIZE (GET_MODE (inner))); + } + /* Note if the plus_constant doesn't make a valid address + then this combination won't be accepted. */ + x = gen_rtx (MEM, mode, + plus_constant (XEXP (inner, 0), + (SUBREG_WORD (x) * UNITS_PER_WORD + + endian_offset))); + MEM_VOLATILE_P (x) = MEM_VOLATILE_P (inner); + RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (inner); + MEM_IN_STRUCT_P (x) = MEM_IN_STRUCT_P (inner); + return x; + } + + /* If we are in a SET_DEST, these other cases can't apply. */ + if (in_dest) + return x; + + /* Changing mode twice with SUBREG => just change it once, + or not at all if changing back to starting mode. */ + if (GET_CODE (SUBREG_REG (x)) == SUBREG) + { + if (mode == GET_MODE (SUBREG_REG (SUBREG_REG (x))) + && SUBREG_WORD (x) == 0 && SUBREG_WORD (SUBREG_REG (x)) == 0) + return SUBREG_REG (SUBREG_REG (x)); + + SUBST_INT (SUBREG_WORD (x), + SUBREG_WORD (x) + SUBREG_WORD (SUBREG_REG (x))); + SUBST (SUBREG_REG (x), SUBREG_REG (SUBREG_REG (x))); + } + + /* SUBREG of a hard register => just change the register number + and/or mode. If the hard register is not valid in that mode, + suppress this combination. If the hard register is the stack, + frame, or argument pointer, leave this as a SUBREG. */ + + if (GET_CODE (SUBREG_REG (x)) == REG + && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER + && REGNO (SUBREG_REG (x)) != FRAME_POINTER_REGNUM +#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM + && REGNO (SUBREG_REG (x)) != HARD_FRAME_POINTER_REGNUM +#endif +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + && REGNO (SUBREG_REG (x)) != ARG_POINTER_REGNUM +#endif + && REGNO (SUBREG_REG (x)) != STACK_POINTER_REGNUM) + { + if (HARD_REGNO_MODE_OK (REGNO (SUBREG_REG (x)) + SUBREG_WORD (x), + mode)) + return gen_rtx (REG, mode, + REGNO (SUBREG_REG (x)) + SUBREG_WORD (x)); + else + return gen_rtx (CLOBBER, mode, const0_rtx); + } + + /* For a constant, try to pick up the part we want. Handle a full + word and low-order part. Only do this if we are narrowing + the constant; if it is being widened, we have no idea what + the extra bits will have been set to. */ + + if (CONSTANT_P (SUBREG_REG (x)) && op0_mode != VOIDmode + && GET_MODE_SIZE (mode) == UNITS_PER_WORD + && GET_MODE_SIZE (op0_mode) < UNITS_PER_WORD + && GET_MODE_CLASS (mode) == MODE_INT) + { + temp = operand_subword (SUBREG_REG (x), SUBREG_WORD (x), + 0, op0_mode); + if (temp) + return temp; + } + + /* If we want a subreg of a constant, at offset 0, + take the low bits. On a little-endian machine, that's + always valid. On a big-endian machine, it's valid + only if the constant's mode fits in one word. */ + if (CONSTANT_P (SUBREG_REG (x)) && subreg_lowpart_p (x) + && GET_MODE_SIZE (mode) < GET_MODE_SIZE (op0_mode) + && (! WORDS_BIG_ENDIAN + || GET_MODE_BITSIZE (op0_mode) <= BITS_PER_WORD)) + return gen_lowpart_for_combine (mode, SUBREG_REG (x)); + + /* A paradoxical SUBREG of a VOIDmode constant is the same constant, + since we are saying that the high bits don't matter. */ + if (CONSTANT_P (SUBREG_REG (x)) && GET_MODE (SUBREG_REG (x)) == VOIDmode + && GET_MODE_SIZE (mode) > GET_MODE_SIZE (op0_mode)) + return SUBREG_REG (x); + + /* Note that we cannot do any narrowing for non-constants since + we might have been counting on using the fact that some bits were + zero. We now do this in the SET. */ + + break; + + case NOT: + /* (not (plus X -1)) can become (neg X). */ + if (GET_CODE (XEXP (x, 0)) == PLUS + && XEXP (XEXP (x, 0), 1) == constm1_rtx) + return gen_rtx_combine (NEG, mode, XEXP (XEXP (x, 0), 0)); + + /* Similarly, (not (neg X)) is (plus X -1). */ + if (GET_CODE (XEXP (x, 0)) == NEG) + return gen_rtx_combine (PLUS, mode, XEXP (XEXP (x, 0), 0), + constm1_rtx); + + /* (not (xor X C)) for C constant is (xor X D) with D = ~ C. */ + if (GET_CODE (XEXP (x, 0)) == XOR + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && (temp = simplify_unary_operation (NOT, mode, + XEXP (XEXP (x, 0), 1), + mode)) != 0) + return gen_binary (XOR, mode, XEXP (XEXP (x, 0), 0), temp); + + /* (not (ashift 1 X)) is (rotate ~1 X). We used to do this for operands + other than 1, but that is not valid. We could do a similar + simplification for (not (lshiftrt C X)) where C is just the sign bit, + but this doesn't seem common enough to bother with. */ + if (GET_CODE (XEXP (x, 0)) == ASHIFT + && XEXP (XEXP (x, 0), 0) == const1_rtx) + return gen_rtx (ROTATE, mode, gen_unary (NOT, mode, mode, const1_rtx), + XEXP (XEXP (x, 0), 1)); + + if (GET_CODE (XEXP (x, 0)) == SUBREG + && subreg_lowpart_p (XEXP (x, 0)) + && (GET_MODE_SIZE (GET_MODE (XEXP (x, 0))) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (x, 0))))) + && GET_CODE (SUBREG_REG (XEXP (x, 0))) == ASHIFT + && XEXP (SUBREG_REG (XEXP (x, 0)), 0) == const1_rtx) + { + enum machine_mode inner_mode = GET_MODE (SUBREG_REG (XEXP (x, 0))); + + x = gen_rtx (ROTATE, inner_mode, + gen_unary (NOT, inner_mode, inner_mode, const1_rtx), + XEXP (SUBREG_REG (XEXP (x, 0)), 1)); + return gen_lowpart_for_combine (mode, x); + } + +#if STORE_FLAG_VALUE == -1 + /* (not (comparison foo bar)) can be done by reversing the comparison + code if valid. */ + if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<' + && reversible_comparison_p (XEXP (x, 0))) + return gen_rtx_combine (reverse_condition (GET_CODE (XEXP (x, 0))), + mode, XEXP (XEXP (x, 0), 0), + XEXP (XEXP (x, 0), 1)); + + /* (ashiftrt foo C) where C is the number of bits in FOO minus 1 + is (lt foo (const_int 0)), so we can perform the above + simplification. */ + + if (XEXP (x, 1) == const1_rtx + && GET_CODE (XEXP (x, 0)) == ASHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (x, 0), 1)) == GET_MODE_BITSIZE (mode) - 1) + return gen_rtx_combine (GE, mode, XEXP (XEXP (x, 0), 0), const0_rtx); +#endif + + /* Apply De Morgan's laws to reduce number of patterns for machines + with negating logical insns (and-not, nand, etc.). If result has + only one NOT, put it first, since that is how the patterns are + coded. */ + + if (GET_CODE (XEXP (x, 0)) == IOR || GET_CODE (XEXP (x, 0)) == AND) + { + rtx in1 = XEXP (XEXP (x, 0), 0), in2 = XEXP (XEXP (x, 0), 1); + + if (GET_CODE (in1) == NOT) + in1 = XEXP (in1, 0); + else + in1 = gen_rtx_combine (NOT, GET_MODE (in1), in1); + + if (GET_CODE (in2) == NOT) + in2 = XEXP (in2, 0); + else if (GET_CODE (in2) == CONST_INT + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) + in2 = GEN_INT (GET_MODE_MASK (mode) & ~ INTVAL (in2)); + else + in2 = gen_rtx_combine (NOT, GET_MODE (in2), in2); + + if (GET_CODE (in2) == NOT) + { + rtx tem = in2; + in2 = in1; in1 = tem; + } + + return gen_rtx_combine (GET_CODE (XEXP (x, 0)) == IOR ? AND : IOR, + mode, in1, in2); + } + break; + + case NEG: + /* (neg (plus X 1)) can become (not X). */ + if (GET_CODE (XEXP (x, 0)) == PLUS + && XEXP (XEXP (x, 0), 1) == const1_rtx) + return gen_rtx_combine (NOT, mode, XEXP (XEXP (x, 0), 0)); + + /* Similarly, (neg (not X)) is (plus X 1). */ + if (GET_CODE (XEXP (x, 0)) == NOT) + return plus_constant (XEXP (XEXP (x, 0), 0), 1); + + /* (neg (minus X Y)) can become (minus Y X). */ + if (GET_CODE (XEXP (x, 0)) == MINUS + && (! FLOAT_MODE_P (mode) + /* x-y != -(y-x) with IEEE floating point. */ + || TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || flag_fast_math)) + return gen_binary (MINUS, mode, XEXP (XEXP (x, 0), 1), + XEXP (XEXP (x, 0), 0)); + + /* (neg (xor A 1)) is (plus A -1) if A is known to be either 0 or 1. */ + if (GET_CODE (XEXP (x, 0)) == XOR && XEXP (XEXP (x, 0), 1) == const1_rtx + && nonzero_bits (XEXP (XEXP (x, 0), 0), mode) == 1) + return gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0), constm1_rtx); + + /* NEG commutes with ASHIFT since it is multiplication. Only do this + if we can then eliminate the NEG (e.g., + if the operand is a constant). */ + + if (GET_CODE (XEXP (x, 0)) == ASHIFT) + { + temp = simplify_unary_operation (NEG, mode, + XEXP (XEXP (x, 0), 0), mode); + if (temp) + { + SUBST (XEXP (XEXP (x, 0), 0), temp); + return XEXP (x, 0); + } + } + + temp = expand_compound_operation (XEXP (x, 0)); + + /* For C equal to the width of MODE minus 1, (neg (ashiftrt X C)) can be + replaced by (lshiftrt X C). This will convert + (neg (sign_extract X 1 Y)) to (zero_extract X 1 Y). */ + + if (GET_CODE (temp) == ASHIFTRT + && GET_CODE (XEXP (temp, 1)) == CONST_INT + && INTVAL (XEXP (temp, 1)) == GET_MODE_BITSIZE (mode) - 1) + return simplify_shift_const (temp, LSHIFTRT, mode, XEXP (temp, 0), + INTVAL (XEXP (temp, 1))); + + /* If X has only a single bit that might be nonzero, say, bit I, convert + (neg X) to (ashiftrt (ashift X C-I) C-I) where C is the bitsize of + MODE minus 1. This will convert (neg (zero_extract X 1 Y)) to + (sign_extract X 1 Y). But only do this if TEMP isn't a register + or a SUBREG of one since we'd be making the expression more + complex if it was just a register. */ + + if (GET_CODE (temp) != REG + && ! (GET_CODE (temp) == SUBREG + && GET_CODE (SUBREG_REG (temp)) == REG) + && (i = exact_log2 (nonzero_bits (temp, mode))) >= 0) + { + rtx temp1 = simplify_shift_const + (NULL_RTX, ASHIFTRT, mode, + simplify_shift_const (NULL_RTX, ASHIFT, mode, temp, + GET_MODE_BITSIZE (mode) - 1 - i), + GET_MODE_BITSIZE (mode) - 1 - i); + + /* If all we did was surround TEMP with the two shifts, we + haven't improved anything, so don't use it. Otherwise, + we are better off with TEMP1. */ + if (GET_CODE (temp1) != ASHIFTRT + || GET_CODE (XEXP (temp1, 0)) != ASHIFT + || XEXP (XEXP (temp1, 0), 0) != temp) + return temp1; + } + break; + + case TRUNCATE: + if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) + SUBST (XEXP (x, 0), + force_to_mode (XEXP (x, 0), GET_MODE (XEXP (x, 0)), + GET_MODE_MASK (mode), NULL_RTX, 0)); + break; + + case FLOAT_TRUNCATE: + /* (float_truncate:SF (float_extend:DF foo:SF)) = foo:SF. */ + if (GET_CODE (XEXP (x, 0)) == FLOAT_EXTEND + && GET_MODE (XEXP (XEXP (x, 0), 0)) == mode) + return XEXP (XEXP (x, 0), 0); + + /* (float_truncate:SF (OP:DF (float_extend:DF foo:sf))) is + (OP:SF foo:SF) if OP is NEG or ABS. */ + if ((GET_CODE (XEXP (x, 0)) == ABS + || GET_CODE (XEXP (x, 0)) == NEG) + && GET_CODE (XEXP (XEXP (x, 0), 0)) == FLOAT_EXTEND + && GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == mode) + return gen_unary (GET_CODE (XEXP (x, 0)), mode, mode, + XEXP (XEXP (XEXP (x, 0), 0), 0)); + + /* (float_truncate:SF (subreg:DF (float_truncate:SF X) 0)) + is (float_truncate:SF x). */ + if (GET_CODE (XEXP (x, 0)) == SUBREG + && subreg_lowpart_p (XEXP (x, 0)) + && GET_CODE (SUBREG_REG (XEXP (x, 0))) == FLOAT_TRUNCATE) + return SUBREG_REG (XEXP (x, 0)); + break; + +#ifdef HAVE_cc0 + case COMPARE: + /* Convert (compare FOO (const_int 0)) to FOO unless we aren't + using cc0, in which case we want to leave it as a COMPARE + so we can distinguish it from a register-register-copy. */ + if (XEXP (x, 1) == const0_rtx) + return XEXP (x, 0); + + /* In IEEE floating point, x-0 is not the same as x. */ + if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0))) + || flag_fast_math) + && XEXP (x, 1) == CONST0_RTX (GET_MODE (XEXP (x, 0)))) + return XEXP (x, 0); + break; +#endif + + case CONST: + /* (const (const X)) can become (const X). Do it this way rather than + returning the inner CONST since CONST can be shared with a + REG_EQUAL note. */ + if (GET_CODE (XEXP (x, 0)) == CONST) + SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0)); + break; + +#ifdef HAVE_lo_sum + case LO_SUM: + /* Convert (lo_sum (high FOO) FOO) to FOO. This is necessary so we + can add in an offset. find_split_point will split this address up + again if it doesn't match. */ + if (GET_CODE (XEXP (x, 0)) == HIGH + && rtx_equal_p (XEXP (XEXP (x, 0), 0), XEXP (x, 1))) + return XEXP (x, 1); + break; +#endif + + case PLUS: + /* If we have (plus (plus (A const) B)), associate it so that CONST is + outermost. That's because that's the way indexed addresses are + supposed to appear. This code used to check many more cases, but + they are now checked elsewhere. */ + if (GET_CODE (XEXP (x, 0)) == PLUS + && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1))) + return gen_binary (PLUS, mode, + gen_binary (PLUS, mode, XEXP (XEXP (x, 0), 0), + XEXP (x, 1)), + XEXP (XEXP (x, 0), 1)); + + /* (plus (xor (and (const_int pow2 - 1)) ) <-c>) + when c is (const_int (pow2 + 1) / 2) is a sign extension of a + bit-field and can be replaced by either a sign_extend or a + sign_extract. The `and' may be a zero_extend. */ + if (GET_CODE (XEXP (x, 0)) == XOR + && GET_CODE (XEXP (x, 1)) == CONST_INT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) == - INTVAL (XEXP (XEXP (x, 0), 1)) + && (i = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) >= 0 + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && ((GET_CODE (XEXP (XEXP (x, 0), 0)) == AND + && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == CONST_INT + && (INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1)) + == ((HOST_WIDE_INT) 1 << (i + 1)) - 1)) + || (GET_CODE (XEXP (XEXP (x, 0), 0)) == ZERO_EXTEND + && (GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (XEXP (x, 0), 0), 0))) + == i + 1)))) + return simplify_shift_const + (NULL_RTX, ASHIFTRT, mode, + simplify_shift_const (NULL_RTX, ASHIFT, mode, + XEXP (XEXP (XEXP (x, 0), 0), 0), + GET_MODE_BITSIZE (mode) - (i + 1)), + GET_MODE_BITSIZE (mode) - (i + 1)); + + /* (plus (comparison A B) C) can become (neg (rev-comp A B)) if + C is 1 and STORE_FLAG_VALUE is -1 or if C is -1 and STORE_FLAG_VALUE + is 1. This produces better code than the alternative immediately + below. */ + if (GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<' + && reversible_comparison_p (XEXP (x, 0)) + && ((STORE_FLAG_VALUE == -1 && XEXP (x, 1) == const1_rtx) + || (STORE_FLAG_VALUE == 1 && XEXP (x, 1) == constm1_rtx))) + return + gen_unary (NEG, mode, mode, + gen_binary (reverse_condition (GET_CODE (XEXP (x, 0))), + mode, XEXP (XEXP (x, 0), 0), + XEXP (XEXP (x, 0), 1))); + + /* If only the low-order bit of X is possibly nonzero, (plus x -1) + can become (ashiftrt (ashift (xor x 1) C) C) where C is + the bitsize of the mode - 1. This allows simplification of + "a = (b & 8) == 0;" */ + if (XEXP (x, 1) == constm1_rtx + && GET_CODE (XEXP (x, 0)) != REG + && ! (GET_CODE (XEXP (x,0)) == SUBREG + && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG) + && nonzero_bits (XEXP (x, 0), mode) == 1) + return simplify_shift_const (NULL_RTX, ASHIFTRT, mode, + simplify_shift_const (NULL_RTX, ASHIFT, mode, + gen_rtx_combine (XOR, mode, + XEXP (x, 0), const1_rtx), + GET_MODE_BITSIZE (mode) - 1), + GET_MODE_BITSIZE (mode) - 1); + + /* If we are adding two things that have no bits in common, convert + the addition into an IOR. This will often be further simplified, + for example in cases like ((a & 1) + (a & 2)), which can + become a & 3. */ + + if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (x, 0), mode) + & nonzero_bits (XEXP (x, 1), mode)) == 0) + return gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1)); + break; + + case MINUS: +#if STORE_FLAG_VALUE == 1 + /* (minus 1 (comparison foo bar)) can be done by reversing the comparison + code if valid. */ + if (XEXP (x, 0) == const1_rtx + && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<' + && reversible_comparison_p (XEXP (x, 1))) + return gen_binary (reverse_condition (GET_CODE (XEXP (x, 1))), + mode, XEXP (XEXP (x, 1), 0), + XEXP (XEXP (x, 1), 1)); +#endif + + /* (minus (and (const_int -pow2))) becomes + (and (const_int pow2-1)) */ + if (GET_CODE (XEXP (x, 1)) == AND + && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT + && exact_log2 (- INTVAL (XEXP (XEXP (x, 1), 1))) >= 0 + && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) + return simplify_and_const_int (NULL_RTX, mode, XEXP (x, 0), + - INTVAL (XEXP (XEXP (x, 1), 1)) - 1); + + /* Canonicalize (minus A (plus B C)) to (minus (minus A B) C) for + integers. */ + if (GET_CODE (XEXP (x, 1)) == PLUS && INTEGRAL_MODE_P (mode)) + return gen_binary (MINUS, mode, + gen_binary (MINUS, mode, XEXP (x, 0), + XEXP (XEXP (x, 1), 0)), + XEXP (XEXP (x, 1), 1)); + break; + + case MULT: + /* If we have (mult (plus A B) C), apply the distributive law and then + the inverse distributive law to see if things simplify. This + occurs mostly in addresses, often when unrolling loops. */ + + if (GET_CODE (XEXP (x, 0)) == PLUS) + { + x = apply_distributive_law + (gen_binary (PLUS, mode, + gen_binary (MULT, mode, + XEXP (XEXP (x, 0), 0), XEXP (x, 1)), + gen_binary (MULT, mode, + XEXP (XEXP (x, 0), 1), XEXP (x, 1)))); + + if (GET_CODE (x) != MULT) + return x; + } + break; + + case UDIV: + /* If this is a divide by a power of two, treat it as a shift if + its first operand is a shift. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0 + && (GET_CODE (XEXP (x, 0)) == ASHIFT + || GET_CODE (XEXP (x, 0)) == LSHIFTRT + || GET_CODE (XEXP (x, 0)) == ASHIFTRT + || GET_CODE (XEXP (x, 0)) == ROTATE + || GET_CODE (XEXP (x, 0)) == ROTATERT)) + return simplify_shift_const (NULL_RTX, LSHIFTRT, mode, XEXP (x, 0), i); + break; + + case EQ: case NE: + case GT: case GTU: case GE: case GEU: + case LT: case LTU: case LE: case LEU: + /* If the first operand is a condition code, we can't do anything + with it. */ + if (GET_CODE (XEXP (x, 0)) == COMPARE + || (GET_MODE_CLASS (GET_MODE (XEXP (x, 0))) != MODE_CC +#ifdef HAVE_cc0 + && XEXP (x, 0) != cc0_rtx +#endif + )) + { + rtx op0 = XEXP (x, 0); + rtx op1 = XEXP (x, 1); + enum rtx_code new_code; + + if (GET_CODE (op0) == COMPARE) + op1 = XEXP (op0, 1), op0 = XEXP (op0, 0); + + /* Simplify our comparison, if possible. */ + new_code = simplify_comparison (code, &op0, &op1); + +#if STORE_FLAG_VALUE == 1 + /* If STORE_FLAG_VALUE is 1, we can convert (ne x 0) to simply X + if only the low-order bit is possibly nonzero in X (such as when + X is a ZERO_EXTRACT of one bit). Similarly, we can convert EQ to + (xor X 1) or (minus 1 X); we use the former. Finally, if X is + known to be either 0 or -1, NE becomes a NEG and EQ becomes + (plus X 1). + + Remove any ZERO_EXTRACT we made when thinking this was a + comparison. It may now be simpler to use, e.g., an AND. If a + ZERO_EXTRACT is indeed appropriate, it will be placed back by + the call to make_compound_operation in the SET case. */ + + if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && nonzero_bits (op0, mode) == 1) + return gen_lowpart_for_combine (mode, + expand_compound_operation (op0)); + + else if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && (num_sign_bit_copies (op0, mode) + == GET_MODE_BITSIZE (mode))) + { + op0 = expand_compound_operation (op0); + return gen_unary (NEG, mode, mode, + gen_lowpart_for_combine (mode, op0)); + } + + else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && nonzero_bits (op0, mode) == 1) + { + op0 = expand_compound_operation (op0); + return gen_binary (XOR, mode, + gen_lowpart_for_combine (mode, op0), + const1_rtx); + } + + else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && (num_sign_bit_copies (op0, mode) + == GET_MODE_BITSIZE (mode))) + { + op0 = expand_compound_operation (op0); + return plus_constant (gen_lowpart_for_combine (mode, op0), 1); + } +#endif + +#if STORE_FLAG_VALUE == -1 + /* If STORE_FLAG_VALUE is -1, we have cases similar to + those above. */ + if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && (num_sign_bit_copies (op0, mode) + == GET_MODE_BITSIZE (mode))) + return gen_lowpart_for_combine (mode, + expand_compound_operation (op0)); + + else if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && nonzero_bits (op0, mode) == 1) + { + op0 = expand_compound_operation (op0); + return gen_unary (NEG, mode, mode, + gen_lowpart_for_combine (mode, op0)); + } + + else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && (num_sign_bit_copies (op0, mode) + == GET_MODE_BITSIZE (mode))) + { + op0 = expand_compound_operation (op0); + return gen_unary (NOT, mode, mode, + gen_lowpart_for_combine (mode, op0)); + } + + /* If X is 0/1, (eq X 0) is X-1. */ + else if (new_code == EQ && GET_MODE_CLASS (mode) == MODE_INT + && op1 == const0_rtx + && nonzero_bits (op0, mode) == 1) + { + op0 = expand_compound_operation (op0); + return plus_constant (gen_lowpart_for_combine (mode, op0), -1); + } +#endif + + /* If STORE_FLAG_VALUE says to just test the sign bit and X has just + one bit that might be nonzero, we can convert (ne x 0) to + (ashift x c) where C puts the bit in the sign bit. Remove any + AND with STORE_FLAG_VALUE when we are done, since we are only + going to test the sign bit. */ + if (new_code == NE && GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && (STORE_FLAG_VALUE + == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1)) + && op1 == const0_rtx + && mode == GET_MODE (op0) + && (i = exact_log2 (nonzero_bits (op0, mode))) >= 0) + { + x = simplify_shift_const (NULL_RTX, ASHIFT, mode, + expand_compound_operation (op0), + GET_MODE_BITSIZE (mode) - 1 - i); + if (GET_CODE (x) == AND && XEXP (x, 1) == const_true_rtx) + return XEXP (x, 0); + else + return x; + } + + /* If the code changed, return a whole new comparison. */ + if (new_code != code) + return gen_rtx_combine (new_code, mode, op0, op1); + + /* Otherwise, keep this operation, but maybe change its operands. + This also converts (ne (compare FOO BAR) 0) to (ne FOO BAR). */ + SUBST (XEXP (x, 0), op0); + SUBST (XEXP (x, 1), op1); + } + break; + + case IF_THEN_ELSE: + return simplify_if_then_else (x); + + case ZERO_EXTRACT: + case SIGN_EXTRACT: + case ZERO_EXTEND: + case SIGN_EXTEND: + /* If we are processing SET_DEST, we are done. */ + if (in_dest) + return x; + + return expand_compound_operation (x); + + case SET: + return simplify_set (x); + + case AND: + case IOR: + case XOR: + return simplify_logical (x, last); + + case ABS: + /* (abs (neg )) -> (abs ) */ + if (GET_CODE (XEXP (x, 0)) == NEG) + SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0)); + + /* If operand is something known to be positive, ignore the ABS. */ + if (GET_CODE (XEXP (x, 0)) == FFS || GET_CODE (XEXP (x, 0)) == ABS + || ((GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) + <= HOST_BITS_PER_WIDE_INT) + && ((nonzero_bits (XEXP (x, 0), GET_MODE (XEXP (x, 0))) + & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1))) + == 0))) + return XEXP (x, 0); + + + /* If operand is known to be only -1 or 0, convert ABS to NEG. */ + if (num_sign_bit_copies (XEXP (x, 0), mode) == GET_MODE_BITSIZE (mode)) + return gen_rtx_combine (NEG, mode, XEXP (x, 0)); + + break; + + case FFS: + /* (ffs (*_extend )) = (ffs ) */ + if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND + || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND) + SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0)); + break; + + case FLOAT: + /* (float (sign_extend )) = (float ). */ + if (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND) + SUBST (XEXP (x, 0), XEXP (XEXP (x, 0), 0)); + break; + + case ASHIFT: + case LSHIFTRT: + case ASHIFTRT: + case ROTATE: + case ROTATERT: + /* If this is a shift by a constant amount, simplify it. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT) + return simplify_shift_const (x, code, mode, XEXP (x, 0), + INTVAL (XEXP (x, 1))); + +#ifdef SHIFT_COUNT_TRUNCATED + else if (SHIFT_COUNT_TRUNCATED && GET_CODE (XEXP (x, 1)) != REG) + SUBST (XEXP (x, 1), + force_to_mode (XEXP (x, 1), GET_MODE (x), + ((HOST_WIDE_INT) 1 + << exact_log2 (GET_MODE_BITSIZE (GET_MODE (x)))) + - 1, + NULL_RTX, 0)); +#endif + + break; + } + + return x; +} + +/* Simplify X, an IF_THEN_ELSE expression. Return the new expression. */ + +static rtx +simplify_if_then_else (x) + rtx x; +{ + enum machine_mode mode = GET_MODE (x); + rtx cond = XEXP (x, 0); + rtx true = XEXP (x, 1); + rtx false = XEXP (x, 2); + enum rtx_code true_code = GET_CODE (cond); + int comparison_p = GET_RTX_CLASS (true_code) == '<'; + rtx temp; + int i; + + /* Simplify storing of the truth value. */ + if (comparison_p && true == const_true_rtx && false == const0_rtx) + return gen_binary (true_code, mode, XEXP (cond, 0), XEXP (cond, 1)); + + /* Also when the truth value has to be reversed. */ + if (comparison_p && reversible_comparison_p (cond) + && true == const0_rtx && false == const_true_rtx) + return gen_binary (reverse_condition (true_code), + mode, XEXP (cond, 0), XEXP (cond, 1)); + + /* Sometimes we can simplify the arm of an IF_THEN_ELSE if a register used + in it is being compared against certain values. Get the true and false + comparisons and see if that says anything about the value of each arm. */ + + if (comparison_p && reversible_comparison_p (cond) + && GET_CODE (XEXP (cond, 0)) == REG) + { + HOST_WIDE_INT nzb; + rtx from = XEXP (cond, 0); + enum rtx_code false_code = reverse_condition (true_code); + rtx true_val = XEXP (cond, 1); + rtx false_val = true_val; + int swapped = 0; + + /* If FALSE_CODE is EQ, swap the codes and arms. */ + + if (false_code == EQ) + { + swapped = 1, true_code = EQ, false_code = NE; + temp = true, true = false, false = temp; + } + + /* If we are comparing against zero and the expression being tested has + only a single bit that might be nonzero, that is its value when it is + not equal to zero. Similarly if it is known to be -1 or 0. */ + + if (true_code == EQ && true_val == const0_rtx + && exact_log2 (nzb = nonzero_bits (from, GET_MODE (from))) >= 0) + false_code = EQ, false_val = GEN_INT (nzb); + else if (true_code == EQ && true_val == const0_rtx + && (num_sign_bit_copies (from, GET_MODE (from)) + == GET_MODE_BITSIZE (GET_MODE (from)))) + false_code = EQ, false_val = constm1_rtx; + + /* Now simplify an arm if we know the value of the register in the + branch and it is used in the arm. Be careful due to the potential + of locally-shared RTL. */ + + if (reg_mentioned_p (from, true)) + true = subst (known_cond (copy_rtx (true), true_code, from, true_val), + pc_rtx, pc_rtx, 0, 0); + if (reg_mentioned_p (from, false)) + false = subst (known_cond (copy_rtx (false), false_code, + from, false_val), + pc_rtx, pc_rtx, 0, 0); + + SUBST (XEXP (x, 1), swapped ? false : true); + SUBST (XEXP (x, 2), swapped ? true : false); + + true = XEXP (x, 1), false = XEXP (x, 2), true_code = GET_CODE (cond); + } + + /* If we have (if_then_else FOO (pc) (label_ref BAR)) and FOO can be + reversed, do so to avoid needing two sets of patterns for + subtract-and-branch insns. Similarly if we have a constant in the true + arm, the false arm is the same as the first operand of the comparison, or + the false arm is more complicated than the true arm. */ + + if (comparison_p && reversible_comparison_p (cond) + && (true == pc_rtx + || (CONSTANT_P (true) + && GET_CODE (false) != CONST_INT && false != pc_rtx) + || true == const0_rtx + || (GET_RTX_CLASS (GET_CODE (true)) == 'o' + && GET_RTX_CLASS (GET_CODE (false)) != 'o') + || (GET_CODE (true) == SUBREG + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (true))) == 'o' + && GET_RTX_CLASS (GET_CODE (false)) != 'o') + || reg_mentioned_p (true, false) + || rtx_equal_p (false, XEXP (cond, 0)))) + { + true_code = reverse_condition (true_code); + SUBST (XEXP (x, 0), + gen_binary (true_code, GET_MODE (cond), XEXP (cond, 0), + XEXP (cond, 1))); + + SUBST (XEXP (x, 1), false); + SUBST (XEXP (x, 2), true); + + temp = true, true = false, false = temp, cond = XEXP (x, 0); + } + + /* If the two arms are identical, we don't need the comparison. */ + + if (rtx_equal_p (true, false) && ! side_effects_p (cond)) + return true; + + /* Look for cases where we have (abs x) or (neg (abs X)). */ + + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_CODE (false) == NEG + && rtx_equal_p (true, XEXP (false, 0)) + && comparison_p + && rtx_equal_p (true, XEXP (cond, 0)) + && ! side_effects_p (true)) + switch (true_code) + { + case GT: + case GE: + return gen_unary (ABS, mode, mode, true); + case LT: + case LE: + return gen_unary (NEG, mode, mode, gen_unary (ABS, mode, mode, true)); + } + + /* Look for MIN or MAX. */ + + if ((! FLOAT_MODE_P (mode) || flag_fast_math) + && comparison_p + && rtx_equal_p (XEXP (cond, 0), true) + && rtx_equal_p (XEXP (cond, 1), false) + && ! side_effects_p (cond)) + switch (true_code) + { + case GE: + case GT: + return gen_binary (SMAX, mode, true, false); + case LE: + case LT: + return gen_binary (SMIN, mode, true, false); + case GEU: + case GTU: + return gen_binary (UMAX, mode, true, false); + case LEU: + case LTU: + return gen_binary (UMIN, mode, true, false); + } + +#if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1 + + /* If we have (if_then_else COND (OP Z C1) Z) and OP is an identity when its + second operand is zero, this can be done as (OP Z (mult COND C2)) where + C2 = C1 * STORE_FLAG_VALUE. Similarly if OP has an outer ZERO_EXTEND or + SIGN_EXTEND as long as Z is already extended (so we don't destroy it). + We can do this kind of thing in some cases when STORE_FLAG_VALUE is + neither of the above, but it isn't worth checking for. */ + + if (comparison_p && mode != VOIDmode && ! side_effects_p (x)) + { + rtx t = make_compound_operation (true, SET); + rtx f = make_compound_operation (false, SET); + rtx cond_op0 = XEXP (cond, 0); + rtx cond_op1 = XEXP (cond, 1); + enum rtx_code op, extend_op = NIL; + enum machine_mode m = mode; + rtx z = 0, c1; + + if ((GET_CODE (t) == PLUS || GET_CODE (t) == MINUS + || GET_CODE (t) == IOR || GET_CODE (t) == XOR + || GET_CODE (t) == ASHIFT + || GET_CODE (t) == LSHIFTRT || GET_CODE (t) == ASHIFTRT) + && rtx_equal_p (XEXP (t, 0), f)) + c1 = XEXP (t, 1), op = GET_CODE (t), z = f; + + /* If an identity-zero op is commutative, check whether there + would be a match if we swapped the operands. */ + else if ((GET_CODE (t) == PLUS || GET_CODE (t) == IOR + || GET_CODE (t) == XOR) + && rtx_equal_p (XEXP (t, 1), f)) + c1 = XEXP (t, 0), op = GET_CODE (t), z = f; + else if (GET_CODE (t) == SIGN_EXTEND + && (GET_CODE (XEXP (t, 0)) == PLUS + || GET_CODE (XEXP (t, 0)) == MINUS + || GET_CODE (XEXP (t, 0)) == IOR + || GET_CODE (XEXP (t, 0)) == XOR + || GET_CODE (XEXP (t, 0)) == ASHIFT + || GET_CODE (XEXP (t, 0)) == LSHIFTRT + || GET_CODE (XEXP (t, 0)) == ASHIFTRT) + && GET_CODE (XEXP (XEXP (t, 0), 0)) == SUBREG + && subreg_lowpart_p (XEXP (XEXP (t, 0), 0)) + && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f) + && (num_sign_bit_copies (f, GET_MODE (f)) + > (GET_MODE_BITSIZE (mode) + - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 0)))))) + { + c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0)); + extend_op = SIGN_EXTEND; + m = GET_MODE (XEXP (t, 0)); + } + else if (GET_CODE (t) == SIGN_EXTEND + && (GET_CODE (XEXP (t, 0)) == PLUS + || GET_CODE (XEXP (t, 0)) == IOR + || GET_CODE (XEXP (t, 0)) == XOR) + && GET_CODE (XEXP (XEXP (t, 0), 1)) == SUBREG + && subreg_lowpart_p (XEXP (XEXP (t, 0), 1)) + && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f) + && (num_sign_bit_copies (f, GET_MODE (f)) + > (GET_MODE_BITSIZE (mode) + - GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (t, 0), 1)))))) + { + c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0)); + extend_op = SIGN_EXTEND; + m = GET_MODE (XEXP (t, 0)); + } + else if (GET_CODE (t) == ZERO_EXTEND + && (GET_CODE (XEXP (t, 0)) == PLUS + || GET_CODE (XEXP (t, 0)) == MINUS + || GET_CODE (XEXP (t, 0)) == IOR + || GET_CODE (XEXP (t, 0)) == XOR + || GET_CODE (XEXP (t, 0)) == ASHIFT + || GET_CODE (XEXP (t, 0)) == LSHIFTRT + || GET_CODE (XEXP (t, 0)) == ASHIFTRT) + && GET_CODE (XEXP (XEXP (t, 0), 0)) == SUBREG + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && subreg_lowpart_p (XEXP (XEXP (t, 0), 0)) + && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 0)), f) + && ((nonzero_bits (f, GET_MODE (f)) + & ~ GET_MODE_MASK (GET_MODE (XEXP (XEXP (t, 0), 0)))) + == 0)) + { + c1 = XEXP (XEXP (t, 0), 1); z = f; op = GET_CODE (XEXP (t, 0)); + extend_op = ZERO_EXTEND; + m = GET_MODE (XEXP (t, 0)); + } + else if (GET_CODE (t) == ZERO_EXTEND + && (GET_CODE (XEXP (t, 0)) == PLUS + || GET_CODE (XEXP (t, 0)) == IOR + || GET_CODE (XEXP (t, 0)) == XOR) + && GET_CODE (XEXP (XEXP (t, 0), 1)) == SUBREG + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && subreg_lowpart_p (XEXP (XEXP (t, 0), 1)) + && rtx_equal_p (SUBREG_REG (XEXP (XEXP (t, 0), 1)), f) + && ((nonzero_bits (f, GET_MODE (f)) + & ~ GET_MODE_MASK (GET_MODE (XEXP (XEXP (t, 0), 1)))) + == 0)) + { + c1 = XEXP (XEXP (t, 0), 0); z = f; op = GET_CODE (XEXP (t, 0)); + extend_op = ZERO_EXTEND; + m = GET_MODE (XEXP (t, 0)); + } + + if (z) + { + temp = subst (gen_binary (true_code, m, cond_op0, cond_op1), + pc_rtx, pc_rtx, 0, 0); + temp = gen_binary (MULT, m, temp, + gen_binary (MULT, m, c1, const_true_rtx)); + temp = subst (temp, pc_rtx, pc_rtx, 0, 0); + temp = gen_binary (op, m, gen_lowpart_for_combine (m, z), temp); + + if (extend_op != NIL) + temp = gen_unary (extend_op, mode, m, temp); + + return temp; + } + } +#endif + + /* If we have (if_then_else (ne A 0) C1 0) and either A is known to be 0 or + 1 and C1 is a single bit or A is known to be 0 or -1 and C1 is the + negation of a single bit, we can convert this operation to a shift. We + can actually do this more generally, but it doesn't seem worth it. */ + + if (true_code == NE && XEXP (cond, 1) == const0_rtx + && false == const0_rtx && GET_CODE (true) == CONST_INT + && ((1 == nonzero_bits (XEXP (cond, 0), mode) + && (i = exact_log2 (INTVAL (true))) >= 0) + || ((num_sign_bit_copies (XEXP (cond, 0), mode) + == GET_MODE_BITSIZE (mode)) + && (i = exact_log2 (- INTVAL (true))) >= 0))) + return + simplify_shift_const (NULL_RTX, ASHIFT, mode, + gen_lowpart_for_combine (mode, XEXP (cond, 0)), i); + + return x; +} + +/* Simplify X, a SET expression. Return the new expression. */ + +static rtx +simplify_set (x) + rtx x; +{ + rtx src = SET_SRC (x); + rtx dest = SET_DEST (x); + enum machine_mode mode + = GET_MODE (src) != VOIDmode ? GET_MODE (src) : GET_MODE (dest); + rtx other_insn; + rtx *cc_use; + + /* (set (pc) (return)) gets written as (return). */ + if (GET_CODE (dest) == PC && GET_CODE (src) == RETURN) + return src; + + /* Now that we know for sure which bits of SRC we are using, see if we can + simplify the expression for the object knowing that we only need the + low-order bits. */ + + if (GET_MODE_CLASS (mode) == MODE_INT) + src = force_to_mode (src, mode, GET_MODE_MASK (mode), NULL_RTX, 0); + + /* If we are setting CC0 or if the source is a COMPARE, look for the use of + the comparison result and try to simplify it unless we already have used + undobuf.other_insn. */ + if ((GET_CODE (src) == COMPARE +#ifdef HAVE_cc0 + || dest == cc0_rtx +#endif + ) + && (cc_use = find_single_use (dest, subst_insn, &other_insn)) != 0 + && (undobuf.other_insn == 0 || other_insn == undobuf.other_insn) + && GET_RTX_CLASS (GET_CODE (*cc_use)) == '<' + && rtx_equal_p (XEXP (*cc_use, 0), dest)) + { + enum rtx_code old_code = GET_CODE (*cc_use); + enum rtx_code new_code; + rtx op0, op1; + int other_changed = 0; + enum machine_mode compare_mode = GET_MODE (dest); + + if (GET_CODE (src) == COMPARE) + op0 = XEXP (src, 0), op1 = XEXP (src, 1); + else + op0 = src, op1 = const0_rtx; + + /* Simplify our comparison, if possible. */ + new_code = simplify_comparison (old_code, &op0, &op1); + +#ifdef EXTRA_CC_MODES + /* If this machine has CC modes other than CCmode, check to see if we + need to use a different CC mode here. */ + compare_mode = SELECT_CC_MODE (new_code, op0, op1); +#endif /* EXTRA_CC_MODES */ + +#if !defined (HAVE_cc0) && defined (EXTRA_CC_MODES) + /* If the mode changed, we have to change SET_DEST, the mode in the + compare, and the mode in the place SET_DEST is used. If SET_DEST is + a hard register, just build new versions with the proper mode. If it + is a pseudo, we lose unless it is only time we set the pseudo, in + which case we can safely change its mode. */ + if (compare_mode != GET_MODE (dest)) + { + int regno = REGNO (dest); + rtx new_dest = gen_rtx (REG, compare_mode, regno); + + if (regno < FIRST_PSEUDO_REGISTER + || (reg_n_sets[regno] == 1 && ! REG_USERVAR_P (dest))) + { + if (regno >= FIRST_PSEUDO_REGISTER) + SUBST (regno_reg_rtx[regno], new_dest); + + SUBST (SET_DEST (x), new_dest); + SUBST (XEXP (*cc_use, 0), new_dest); + other_changed = 1; + + dest = new_dest; + } + } +#endif + + /* If the code changed, we have to build a new comparison in + undobuf.other_insn. */ + if (new_code != old_code) + { + unsigned HOST_WIDE_INT mask; + + SUBST (*cc_use, gen_rtx_combine (new_code, GET_MODE (*cc_use), + dest, const0_rtx)); + + /* If the only change we made was to change an EQ into an NE or + vice versa, OP0 has only one bit that might be nonzero, and OP1 + is zero, check if changing the user of the condition code will + produce a valid insn. If it won't, we can keep the original code + in that insn by surrounding our operation with an XOR. */ + + if (((old_code == NE && new_code == EQ) + || (old_code == EQ && new_code == NE)) + && ! other_changed && op1 == const0_rtx + && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT + && exact_log2 (mask = nonzero_bits (op0, GET_MODE (op0))) >= 0) + { + rtx pat = PATTERN (other_insn), note = 0; + int scratches; + + if ((recog_for_combine (&pat, other_insn, ¬e, &scratches) < 0 + && ! check_asm_operands (pat))) + { + PUT_CODE (*cc_use, old_code); + other_insn = 0; + + op0 = gen_binary (XOR, GET_MODE (op0), op0, GEN_INT (mask)); + } + } + + other_changed = 1; + } + + if (other_changed) + undobuf.other_insn = other_insn; + +#ifdef HAVE_cc0 + /* If we are now comparing against zero, change our source if + needed. If we do not use cc0, we always have a COMPARE. */ + if (op1 == const0_rtx && dest == cc0_rtx) + { + SUBST (SET_SRC (x), op0); + src = op0; + } + else +#endif + + /* Otherwise, if we didn't previously have a COMPARE in the + correct mode, we need one. */ + if (GET_CODE (src) != COMPARE || GET_MODE (src) != compare_mode) + { + SUBST (SET_SRC (x), + gen_rtx_combine (COMPARE, compare_mode, op0, op1)); + src = SET_SRC (x); + } + else + { + /* Otherwise, update the COMPARE if needed. */ + SUBST (XEXP (src, 0), op0); + SUBST (XEXP (src, 1), op1); + } + } + else + { + /* Get SET_SRC in a form where we have placed back any + compound expressions. Then do the checks below. */ + src = make_compound_operation (src, SET); + SUBST (SET_SRC (x), src); + } + + /* If we have (set x (subreg:m1 (op:m2 ...) 0)) with OP being some operation, + and X being a REG or (subreg (reg)), we may be able to convert this to + (set (subreg:m2 x) (op)). + + We can always do this if M1 is narrower than M2 because that means that + we only care about the low bits of the result. + + However, on machines without WORD_REGISTER_OPERATIONS defined, we cannot + perform a narrower operation that requested since the high-order bits will + be undefined. On machine where it is defined, this transformation is safe + as long as M1 and M2 have the same number of words. */ + + if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src) + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (src))) != 'o' + && (((GET_MODE_SIZE (GET_MODE (src)) + (UNITS_PER_WORD - 1)) + / UNITS_PER_WORD) + == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))) + + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)) +#ifndef WORD_REGISTER_OPERATIONS + && (GET_MODE_SIZE (GET_MODE (src)) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))) +#endif +#ifdef CLASS_CANNOT_CHANGE_SIZE + && ! (GET_CODE (dest) == REG && REGNO (dest) < FIRST_PSEUDO_REGISTER + && (TEST_HARD_REG_BIT + (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE], + REGNO (dest))) + && (GET_MODE_SIZE (GET_MODE (src)) + != GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))) +#endif + && (GET_CODE (dest) == REG + || (GET_CODE (dest) == SUBREG + && GET_CODE (SUBREG_REG (dest)) == REG))) + { + SUBST (SET_DEST (x), + gen_lowpart_for_combine (GET_MODE (SUBREG_REG (src)), + dest)); + SUBST (SET_SRC (x), SUBREG_REG (src)); + + src = SET_SRC (x), dest = SET_DEST (x); + } + +#ifdef LOAD_EXTEND_OP + /* If we have (set FOO (subreg:M (mem:N BAR) 0)) with M wider than N, this + would require a paradoxical subreg. Replace the subreg with a + zero_extend to avoid the reload that would otherwise be required. */ + + if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src) + && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))) != NIL + && SUBREG_WORD (src) == 0 + && (GET_MODE_SIZE (GET_MODE (src)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src)))) + && GET_CODE (SUBREG_REG (src)) == MEM) + { + SUBST (SET_SRC (x), + gen_rtx_combine (LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (src))), + GET_MODE (src), XEXP (src, 0))); + + src = SET_SRC (x); + } +#endif + + /* If we don't have a conditional move, SET_SRC is an IF_THEN_ELSE, and we + are comparing an item known to be 0 or -1 against 0, use a logical + operation instead. Check for one of the arms being an IOR of the other + arm with some value. We compute three terms to be IOR'ed together. In + practice, at most two will be nonzero. Then we do the IOR's. */ + + if (GET_CODE (dest) != PC + && GET_CODE (src) == IF_THEN_ELSE + && GET_MODE_CLASS (GET_MODE (src)) == MODE_INT + && (GET_CODE (XEXP (src, 0)) == EQ || GET_CODE (XEXP (src, 0)) == NE) + && XEXP (XEXP (src, 0), 1) == const0_rtx + && GET_MODE (src) == GET_MODE (XEXP (XEXP (src, 0), 0)) +#ifdef HAVE_conditional_move + && ! can_conditionally_move_p (GET_MODE (src)) +#endif + && (num_sign_bit_copies (XEXP (XEXP (src, 0), 0), + GET_MODE (XEXP (XEXP (src, 0), 0))) + == GET_MODE_BITSIZE (GET_MODE (XEXP (XEXP (src, 0), 0)))) + && ! side_effects_p (src)) + { + rtx true = (GET_CODE (XEXP (src, 0)) == NE + ? XEXP (src, 1) : XEXP (src, 2)); + rtx false = (GET_CODE (XEXP (src, 0)) == NE + ? XEXP (src, 2) : XEXP (src, 1)); + rtx term1 = const0_rtx, term2, term3; + + if (GET_CODE (true) == IOR && rtx_equal_p (XEXP (true, 0), false)) + term1 = false, true = XEXP (true, 1), false = const0_rtx; + else if (GET_CODE (true) == IOR + && rtx_equal_p (XEXP (true, 1), false)) + term1 = false, true = XEXP (true, 0), false = const0_rtx; + else if (GET_CODE (false) == IOR + && rtx_equal_p (XEXP (false, 0), true)) + term1 = true, false = XEXP (false, 1), true = const0_rtx; + else if (GET_CODE (false) == IOR + && rtx_equal_p (XEXP (false, 1), true)) + term1 = true, false = XEXP (false, 0), true = const0_rtx; + + term2 = gen_binary (AND, GET_MODE (src), XEXP (XEXP (src, 0), 0), true); + term3 = gen_binary (AND, GET_MODE (src), + gen_unary (NOT, GET_MODE (src), GET_MODE (src), + XEXP (XEXP (src, 0), 0)), + false); + + SUBST (SET_SRC (x), + gen_binary (IOR, GET_MODE (src), + gen_binary (IOR, GET_MODE (src), term1, term2), + term3)); + + src = SET_SRC (x); + } + + /* If either SRC or DEST is a CLOBBER of (const_int 0), make this + whole thing fail. */ + if (GET_CODE (src) == CLOBBER && XEXP (src, 0) == const0_rtx) + return src; + else if (GET_CODE (dest) == CLOBBER && XEXP (dest, 0) == const0_rtx) + return dest; + else + /* Convert this into a field assignment operation, if possible. */ + return make_field_assignment (x); +} + +/* Simplify, X, and AND, IOR, or XOR operation, and return the simplified + result. LAST is nonzero if this is the last retry. */ + +static rtx +simplify_logical (x, last) + rtx x; + int last; +{ + enum machine_mode mode = GET_MODE (x); + rtx op0 = XEXP (x, 0); + rtx op1 = XEXP (x, 1); + + switch (GET_CODE (x)) + { + case AND: + /* Convert (A ^ B) & A to A & (~ B) since the latter is often a single + insn (and may simplify more). */ + if (GET_CODE (op0) == XOR + && rtx_equal_p (XEXP (op0, 0), op1) + && ! side_effects_p (op1)) + x = gen_binary (AND, mode, + gen_unary (NOT, mode, mode, XEXP (op0, 1)), op1); + + if (GET_CODE (op0) == XOR + && rtx_equal_p (XEXP (op0, 1), op1) + && ! side_effects_p (op1)) + x = gen_binary (AND, mode, + gen_unary (NOT, mode, mode, XEXP (op0, 0)), op1); + + /* Similarly for (~ (A ^ B)) & A. */ + if (GET_CODE (op0) == NOT + && GET_CODE (XEXP (op0, 0)) == XOR + && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1) + && ! side_effects_p (op1)) + x = gen_binary (AND, mode, XEXP (XEXP (op0, 0), 1), op1); + + if (GET_CODE (op0) == NOT + && GET_CODE (XEXP (op0, 0)) == XOR + && rtx_equal_p (XEXP (XEXP (op0, 0), 1), op1) + && ! side_effects_p (op1)) + x = gen_binary (AND, mode, XEXP (XEXP (op0, 0), 0), op1); + + if (GET_CODE (op1) == CONST_INT) + { + x = simplify_and_const_int (x, mode, op0, INTVAL (op1)); + + /* If we have (ior (and (X C1) C2)) and the next restart would be + the last, simplify this by making C1 as small as possible + and then exit. */ + if (last + && GET_CODE (x) == IOR && GET_CODE (op0) == AND + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (op1) == CONST_INT) + return gen_binary (IOR, mode, + gen_binary (AND, mode, XEXP (op0, 0), + GEN_INT (INTVAL (XEXP (op0, 1)) + & ~ INTVAL (op1))), op1); + + if (GET_CODE (x) != AND) + return x; + + if (GET_RTX_CLASS (GET_CODE (x)) == 'c' + || GET_RTX_CLASS (GET_CODE (x)) == '2') + op0 = XEXP (x, 0), op1 = XEXP (x, 1); + } + + /* Convert (A | B) & A to A. */ + if (GET_CODE (op0) == IOR + && (rtx_equal_p (XEXP (op0, 0), op1) + || rtx_equal_p (XEXP (op0, 1), op1)) + && ! side_effects_p (XEXP (op0, 0)) + && ! side_effects_p (XEXP (op0, 1))) + return op1; + + /* In the following group of tests (and those in case IOR below), + we start with some combination of logical operations and apply + the distributive law followed by the inverse distributive law. + Most of the time, this results in no change. However, if some of + the operands are the same or inverses of each other, simplifications + will result. + + For example, (and (ior A B) (not B)) can occur as the result of + expanding a bit field assignment. When we apply the distributive + law to this, we get (ior (and (A (not B))) (and (B (not B)))), + which then simplifies to (and (A (not B))). + + If we have (and (ior A B) C), apply the distributive law and then + the inverse distributive law to see if things simplify. */ + + if (GET_CODE (op0) == IOR || GET_CODE (op0) == XOR) + { + x = apply_distributive_law + (gen_binary (GET_CODE (op0), mode, + gen_binary (AND, mode, XEXP (op0, 0), op1), + gen_binary (AND, mode, XEXP (op0, 1), op1))); + if (GET_CODE (x) != AND) + return x; + } + + if (GET_CODE (op1) == IOR || GET_CODE (op1) == XOR) + return apply_distributive_law + (gen_binary (GET_CODE (op1), mode, + gen_binary (AND, mode, XEXP (op1, 0), op0), + gen_binary (AND, mode, XEXP (op1, 1), op0))); + + /* Similarly, taking advantage of the fact that + (and (not A) (xor B C)) == (xor (ior A B) (ior A C)) */ + + if (GET_CODE (op0) == NOT && GET_CODE (op1) == XOR) + return apply_distributive_law + (gen_binary (XOR, mode, + gen_binary (IOR, mode, XEXP (op0, 0), XEXP (op1, 0)), + gen_binary (IOR, mode, XEXP (op0, 0), XEXP (op1, 1)))); + + else if (GET_CODE (op1) == NOT && GET_CODE (op0) == XOR) + return apply_distributive_law + (gen_binary (XOR, mode, + gen_binary (IOR, mode, XEXP (op1, 0), XEXP (op0, 0)), + gen_binary (IOR, mode, XEXP (op1, 0), XEXP (op0, 1)))); + break; + + case IOR: + /* (ior A C) is C if all bits of A that might be nonzero are on in C. */ + if (GET_CODE (op1) == CONST_INT + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (op0, mode) & ~ INTVAL (op1)) == 0) + return op1; + + /* Convert (A & B) | A to A. */ + if (GET_CODE (op0) == AND + && (rtx_equal_p (XEXP (op0, 0), op1) + || rtx_equal_p (XEXP (op0, 1), op1)) + && ! side_effects_p (XEXP (op0, 0)) + && ! side_effects_p (XEXP (op0, 1))) + return op1; + + /* If we have (ior (and A B) C), apply the distributive law and then + the inverse distributive law to see if things simplify. */ + + if (GET_CODE (op0) == AND) + { + x = apply_distributive_law + (gen_binary (AND, mode, + gen_binary (IOR, mode, XEXP (op0, 0), op1), + gen_binary (IOR, mode, XEXP (op0, 1), op1))); + + if (GET_CODE (x) != IOR) + return x; + } + + if (GET_CODE (op1) == AND) + { + x = apply_distributive_law + (gen_binary (AND, mode, + gen_binary (IOR, mode, XEXP (op1, 0), op0), + gen_binary (IOR, mode, XEXP (op1, 1), op0))); + + if (GET_CODE (x) != IOR) + return x; + } + + /* Convert (ior (ashift A CX) (lshiftrt A CY)) where CX+CY equals the + mode size to (rotate A CX). */ + + if (((GET_CODE (op0) == ASHIFT && GET_CODE (op1) == LSHIFTRT) + || (GET_CODE (op1) == ASHIFT && GET_CODE (op0) == LSHIFTRT)) + && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0)) + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (XEXP (op1, 1)) == CONST_INT + && (INTVAL (XEXP (op0, 1)) + INTVAL (XEXP (op1, 1)) + == GET_MODE_BITSIZE (mode))) + return gen_rtx (ROTATE, mode, XEXP (op0, 0), + (GET_CODE (op0) == ASHIFT + ? XEXP (op0, 1) : XEXP (op1, 1))); + + /* If OP0 is (ashiftrt (plus ...) C), it might actually be + a (sign_extend (plus ...)). If so, OP1 is a CONST_INT, and the PLUS + does not affect any of the bits in OP1, it can really be done + as a PLUS and we can associate. We do this by seeing if OP1 + can be safely shifted left C bits. */ + if (GET_CODE (op1) == CONST_INT && GET_CODE (op0) == ASHIFTRT + && GET_CODE (XEXP (op0, 0)) == PLUS + && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT) + { + int count = INTVAL (XEXP (op0, 1)); + HOST_WIDE_INT mask = INTVAL (op1) << count; + + if (mask >> count == INTVAL (op1) + && (mask & nonzero_bits (XEXP (op0, 0), mode)) == 0) + { + SUBST (XEXP (XEXP (op0, 0), 1), + GEN_INT (INTVAL (XEXP (XEXP (op0, 0), 1)) | mask)); + return op0; + } + } + break; + + case XOR: + /* Convert (XOR (NOT x) (NOT y)) to (XOR x y). + Also convert (XOR (NOT x) y) to (NOT (XOR x y)), similarly for + (NOT y). */ + { + int num_negated = 0; + + if (GET_CODE (op0) == NOT) + num_negated++, op0 = XEXP (op0, 0); + if (GET_CODE (op1) == NOT) + num_negated++, op1 = XEXP (op1, 0); + + if (num_negated == 2) + { + SUBST (XEXP (x, 0), op0); + SUBST (XEXP (x, 1), op1); + } + else if (num_negated == 1) + return gen_unary (NOT, mode, mode, gen_binary (XOR, mode, op0, op1)); + } + + /* Convert (xor (and A B) B) to (and (not A) B). The latter may + correspond to a machine insn or result in further simplifications + if B is a constant. */ + + if (GET_CODE (op0) == AND + && rtx_equal_p (XEXP (op0, 1), op1) + && ! side_effects_p (op1)) + return gen_binary (AND, mode, + gen_unary (NOT, mode, mode, XEXP (op0, 0)), + op1); + + else if (GET_CODE (op0) == AND + && rtx_equal_p (XEXP (op0, 0), op1) + && ! side_effects_p (op1)) + return gen_binary (AND, mode, + gen_unary (NOT, mode, mode, XEXP (op0, 1)), + op1); + +#if STORE_FLAG_VALUE == 1 + /* (xor (comparison foo bar) (const_int 1)) can become the reversed + comparison. */ + if (op1 == const1_rtx + && GET_RTX_CLASS (GET_CODE (op0)) == '<' + && reversible_comparison_p (op0)) + return gen_rtx_combine (reverse_condition (GET_CODE (op0)), + mode, XEXP (op0, 0), XEXP (op0, 1)); + + /* (lshiftrt foo C) where C is the number of bits in FOO minus 1 + is (lt foo (const_int 0)), so we can perform the above + simplification. */ + + if (op1 == const1_rtx + && GET_CODE (op0) == LSHIFTRT + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) == GET_MODE_BITSIZE (mode) - 1) + return gen_rtx_combine (GE, mode, XEXP (op0, 0), const0_rtx); +#endif + + /* (xor (comparison foo bar) (const_int sign-bit)) + when STORE_FLAG_VALUE is the sign bit. */ + if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && (STORE_FLAG_VALUE + == (HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (mode) - 1)) + && op1 == const_true_rtx + && GET_RTX_CLASS (GET_CODE (op0)) == '<' + && reversible_comparison_p (op0)) + return gen_rtx_combine (reverse_condition (GET_CODE (op0)), + mode, XEXP (op0, 0), XEXP (op0, 1)); + break; + } + + return x; +} + +/* We consider ZERO_EXTRACT, SIGN_EXTRACT, and SIGN_EXTEND as "compound + operations" because they can be replaced with two more basic operations. + ZERO_EXTEND is also considered "compound" because it can be replaced with + an AND operation, which is simpler, though only one operation. + + The function expand_compound_operation is called with an rtx expression + and will convert it to the appropriate shifts and AND operations, + simplifying at each stage. + + The function make_compound_operation is called to convert an expression + consisting of shifts and ANDs into the equivalent compound expression. + It is the inverse of this function, loosely speaking. */ + +static rtx +expand_compound_operation (x) + rtx x; +{ + int pos = 0, len; + int unsignedp = 0; + int modewidth; + rtx tem; + + switch (GET_CODE (x)) + { + case ZERO_EXTEND: + unsignedp = 1; + case SIGN_EXTEND: + /* We can't necessarily use a const_int for a multiword mode; + it depends on implicitly extending the value. + Since we don't know the right way to extend it, + we can't tell whether the implicit way is right. + + Even for a mode that is no wider than a const_int, + we can't win, because we need to sign extend one of its bits through + the rest of it, and we don't know which bit. */ + if (GET_CODE (XEXP (x, 0)) == CONST_INT) + return x; + + /* Return if (subreg:MODE FROM 0) is not a safe replacement for + (zero_extend:MODE FROM) or (sign_extend:MODE FROM). It is for any MEM + because (SUBREG (MEM...)) is guaranteed to cause the MEM to be + reloaded. If not for that, MEM's would very rarely be safe. + + Reject MODEs bigger than a word, because we might not be able + to reference a two-register group starting with an arbitrary register + (and currently gen_lowpart might crash for a SUBREG). */ + + if (GET_MODE_SIZE (GET_MODE (XEXP (x, 0))) > UNITS_PER_WORD) + return x; + + len = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))); + /* If the inner object has VOIDmode (the only way this can happen + is if it is a ASM_OPERANDS), we can't do anything since we don't + know how much masking to do. */ + if (len == 0) + return x; + + break; + + case ZERO_EXTRACT: + unsignedp = 1; + case SIGN_EXTRACT: + /* If the operand is a CLOBBER, just return it. */ + if (GET_CODE (XEXP (x, 0)) == CLOBBER) + return XEXP (x, 0); + + if (GET_CODE (XEXP (x, 1)) != CONST_INT + || GET_CODE (XEXP (x, 2)) != CONST_INT + || GET_MODE (XEXP (x, 0)) == VOIDmode) + return x; + + len = INTVAL (XEXP (x, 1)); + pos = INTVAL (XEXP (x, 2)); + + /* If this goes outside the object being extracted, replace the object + with a (use (mem ...)) construct that only combine understands + and is used only for this purpose. */ + if (len + pos > GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0)))) + SUBST (XEXP (x, 0), gen_rtx (USE, GET_MODE (x), XEXP (x, 0))); + + if (BITS_BIG_ENDIAN) + pos = GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - len - pos; + + break; + + default: + return x; + } + + /* If we reach here, we want to return a pair of shifts. The inner + shift is a left shift of BITSIZE - POS - LEN bits. The outer + shift is a right shift of BITSIZE - LEN bits. It is arithmetic or + logical depending on the value of UNSIGNEDP. + + If this was a ZERO_EXTEND or ZERO_EXTRACT, this pair of shifts will be + converted into an AND of a shift. + + We must check for the case where the left shift would have a negative + count. This can happen in a case like (x >> 31) & 255 on machines + that can't shift by a constant. On those machines, we would first + combine the shift with the AND to produce a variable-position + extraction. Then the constant of 31 would be substituted in to produce + a such a position. */ + + modewidth = GET_MODE_BITSIZE (GET_MODE (x)); + if (modewidth >= pos - len) + tem = simplify_shift_const (NULL_RTX, unsignedp ? LSHIFTRT : ASHIFTRT, + GET_MODE (x), + simplify_shift_const (NULL_RTX, ASHIFT, + GET_MODE (x), + XEXP (x, 0), + modewidth - pos - len), + modewidth - len); + + else if (unsignedp && len < HOST_BITS_PER_WIDE_INT) + tem = simplify_and_const_int (NULL_RTX, GET_MODE (x), + simplify_shift_const (NULL_RTX, LSHIFTRT, + GET_MODE (x), + XEXP (x, 0), pos), + ((HOST_WIDE_INT) 1 << len) - 1); + else + /* Any other cases we can't handle. */ + return x; + + + /* If we couldn't do this for some reason, return the original + expression. */ + if (GET_CODE (tem) == CLOBBER) + return x; + + return tem; +} + +/* X is a SET which contains an assignment of one object into + a part of another (such as a bit-field assignment, STRICT_LOW_PART, + or certain SUBREGS). If possible, convert it into a series of + logical operations. + + We half-heartedly support variable positions, but do not at all + support variable lengths. */ + +static rtx +expand_field_assignment (x) + rtx x; +{ + rtx inner; + rtx pos; /* Always counts from low bit. */ + int len; + rtx mask; + enum machine_mode compute_mode; + + /* Loop until we find something we can't simplify. */ + while (1) + { + if (GET_CODE (SET_DEST (x)) == STRICT_LOW_PART + && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG) + { + inner = SUBREG_REG (XEXP (SET_DEST (x), 0)); + len = GET_MODE_BITSIZE (GET_MODE (XEXP (SET_DEST (x), 0))); + pos = const0_rtx; + } + else if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT + && GET_CODE (XEXP (SET_DEST (x), 1)) == CONST_INT) + { + inner = XEXP (SET_DEST (x), 0); + len = INTVAL (XEXP (SET_DEST (x), 1)); + pos = XEXP (SET_DEST (x), 2); + + /* If the position is constant and spans the width of INNER, + surround INNER with a USE to indicate this. */ + if (GET_CODE (pos) == CONST_INT + && INTVAL (pos) + len > GET_MODE_BITSIZE (GET_MODE (inner))) + inner = gen_rtx (USE, GET_MODE (SET_DEST (x)), inner); + + if (BITS_BIG_ENDIAN) + { + if (GET_CODE (pos) == CONST_INT) + pos = GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner)) - len + - INTVAL (pos)); + else if (GET_CODE (pos) == MINUS + && GET_CODE (XEXP (pos, 1)) == CONST_INT + && (INTVAL (XEXP (pos, 1)) + == GET_MODE_BITSIZE (GET_MODE (inner)) - len)) + /* If position is ADJUST - X, new position is X. */ + pos = XEXP (pos, 0); + else + pos = gen_binary (MINUS, GET_MODE (pos), + GEN_INT (GET_MODE_BITSIZE (GET_MODE (inner)) + - len), + pos); + } + } + + /* A SUBREG between two modes that occupy the same numbers of words + can be done by moving the SUBREG to the source. */ + else if (GET_CODE (SET_DEST (x)) == SUBREG + && (((GET_MODE_SIZE (GET_MODE (SET_DEST (x))) + + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) + == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x)))) + + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))) + { + x = gen_rtx (SET, VOIDmode, SUBREG_REG (SET_DEST (x)), + gen_lowpart_for_combine (GET_MODE (SUBREG_REG (SET_DEST (x))), + SET_SRC (x))); + continue; + } + else + break; + + while (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner)) + inner = SUBREG_REG (inner); + + compute_mode = GET_MODE (inner); + + /* Compute a mask of LEN bits, if we can do this on the host machine. */ + if (len < HOST_BITS_PER_WIDE_INT) + mask = GEN_INT (((HOST_WIDE_INT) 1 << len) - 1); + else + break; + + /* Now compute the equivalent expression. Make a copy of INNER + for the SET_DEST in case it is a MEM into which we will substitute; + we don't want shared RTL in that case. */ + x = gen_rtx (SET, VOIDmode, copy_rtx (inner), + gen_binary (IOR, compute_mode, + gen_binary (AND, compute_mode, + gen_unary (NOT, compute_mode, + compute_mode, + gen_binary (ASHIFT, + compute_mode, + mask, pos)), + inner), + gen_binary (ASHIFT, compute_mode, + gen_binary (AND, compute_mode, + gen_lowpart_for_combine + (compute_mode, + SET_SRC (x)), + mask), + pos))); + } + + return x; +} + +/* Return an RTX for a reference to LEN bits of INNER. If POS_RTX is nonzero, + it is an RTX that represents a variable starting position; otherwise, + POS is the (constant) starting bit position (counted from the LSB). + + INNER may be a USE. This will occur when we started with a bitfield + that went outside the boundary of the object in memory, which is + allowed on most machines. To isolate this case, we produce a USE + whose mode is wide enough and surround the MEM with it. The only + code that understands the USE is this routine. If it is not removed, + it will cause the resulting insn not to match. + + UNSIGNEDP is non-zero for an unsigned reference and zero for a + signed reference. + + IN_DEST is non-zero if this is a reference in the destination of a + SET. This is used when a ZERO_ or SIGN_EXTRACT isn't needed. If non-zero, + a STRICT_LOW_PART will be used, if zero, ZERO_EXTEND or SIGN_EXTEND will + be used. + + IN_COMPARE is non-zero if we are in a COMPARE. This means that a + ZERO_EXTRACT should be built even for bits starting at bit 0. + + MODE is the desired mode of the result (if IN_DEST == 0). */ + +static rtx +make_extraction (mode, inner, pos, pos_rtx, len, + unsignedp, in_dest, in_compare) + enum machine_mode mode; + rtx inner; + int pos; + rtx pos_rtx; + int len; + int unsignedp; + int in_dest, in_compare; +{ + /* This mode describes the size of the storage area + to fetch the overall value from. Within that, we + ignore the POS lowest bits, etc. */ + enum machine_mode is_mode = GET_MODE (inner); + enum machine_mode inner_mode; + enum machine_mode wanted_mem_mode = byte_mode; + enum machine_mode pos_mode = word_mode; + enum machine_mode extraction_mode = word_mode; + enum machine_mode tmode = mode_for_size (len, MODE_INT, 1); + int spans_byte = 0; + rtx new = 0; + rtx orig_pos_rtx = pos_rtx; + int orig_pos; + + /* Get some information about INNER and get the innermost object. */ + if (GET_CODE (inner) == USE) + /* (use:SI (mem:QI foo)) stands for (mem:SI foo). */ + /* We don't need to adjust the position because we set up the USE + to pretend that it was a full-word object. */ + spans_byte = 1, inner = XEXP (inner, 0); + else if (GET_CODE (inner) == SUBREG && subreg_lowpart_p (inner)) + { + /* If going from (subreg:SI (mem:QI ...)) to (mem:QI ...), + consider just the QI as the memory to extract from. + The subreg adds or removes high bits; its mode is + irrelevant to the meaning of this extraction, + since POS and LEN count from the lsb. */ + if (GET_CODE (SUBREG_REG (inner)) == MEM) + is_mode = GET_MODE (SUBREG_REG (inner)); + inner = SUBREG_REG (inner); + } + + inner_mode = GET_MODE (inner); + + if (pos_rtx && GET_CODE (pos_rtx) == CONST_INT) + pos = INTVAL (pos_rtx), pos_rtx = 0; + + /* See if this can be done without an extraction. We never can if the + width of the field is not the same as that of some integer mode. For + registers, we can only avoid the extraction if the position is at the + low-order bit and this is either not in the destination or we have the + appropriate STRICT_LOW_PART operation available. + + For MEM, we can avoid an extract if the field starts on an appropriate + boundary and we can change the mode of the memory reference. However, + we cannot directly access the MEM if we have a USE and the underlying + MEM is not TMODE. This combination means that MEM was being used in a + context where bits outside its mode were being referenced; that is only + valid in bit-field insns. */ + + if (tmode != BLKmode + && ! (spans_byte && inner_mode != tmode) + && ((pos_rtx == 0 && pos == 0 && GET_CODE (inner) != MEM + && (! in_dest + || (GET_CODE (inner) == REG + && (movstrict_optab->handlers[(int) tmode].insn_code + != CODE_FOR_nothing)))) + || (GET_CODE (inner) == MEM && pos_rtx == 0 + && (pos + % (STRICT_ALIGNMENT ? GET_MODE_ALIGNMENT (tmode) + : BITS_PER_UNIT)) == 0 + /* We can't do this if we are widening INNER_MODE (it + may not be aligned, for one thing). */ + && GET_MODE_BITSIZE (inner_mode) >= GET_MODE_BITSIZE (tmode) + && (inner_mode == tmode + || (! mode_dependent_address_p (XEXP (inner, 0)) + && ! MEM_VOLATILE_P (inner)))))) + { + /* If INNER is a MEM, make a new MEM that encompasses just the desired + field. If the original and current mode are the same, we need not + adjust the offset. Otherwise, we do if bytes big endian. + + If INNER is not a MEM, get a piece consisting of the just the field + of interest (in this case POS must be 0). */ + + if (GET_CODE (inner) == MEM) + { + int offset; + /* POS counts from lsb, but make OFFSET count in memory order. */ + if (BYTES_BIG_ENDIAN) + offset = (GET_MODE_BITSIZE (is_mode) - len - pos) / BITS_PER_UNIT; + else + offset = pos / BITS_PER_UNIT; + + new = gen_rtx (MEM, tmode, plus_constant (XEXP (inner, 0), offset)); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (inner); + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (inner); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (inner); + } + else if (GET_CODE (inner) == REG) + { + /* We can't call gen_lowpart_for_combine here since we always want + a SUBREG and it would sometimes return a new hard register. */ + if (tmode != inner_mode) + new = gen_rtx (SUBREG, tmode, inner, + (WORDS_BIG_ENDIAN + && GET_MODE_SIZE (inner_mode) > UNITS_PER_WORD + ? ((GET_MODE_SIZE (inner_mode) + - GET_MODE_SIZE (tmode)) + / UNITS_PER_WORD) + : 0)); + else + new = inner; + } + else + new = force_to_mode (inner, tmode, + len >= HOST_BITS_PER_WIDE_INT + ? GET_MODE_MASK (tmode) + : ((HOST_WIDE_INT) 1 << len) - 1, + NULL_RTX, 0); + + /* If this extraction is going into the destination of a SET, + make a STRICT_LOW_PART unless we made a MEM. */ + + if (in_dest) + return (GET_CODE (new) == MEM ? new + : (GET_CODE (new) != SUBREG + ? gen_rtx (CLOBBER, tmode, const0_rtx) + : gen_rtx_combine (STRICT_LOW_PART, VOIDmode, new))); + + /* Otherwise, sign- or zero-extend unless we already are in the + proper mode. */ + + return (mode == tmode ? new + : gen_rtx_combine (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, + mode, new)); + } + + /* Unless this is a COMPARE or we have a funny memory reference, + don't do anything with zero-extending field extracts starting at + the low-order bit since they are simple AND operations. */ + if (pos_rtx == 0 && pos == 0 && ! in_dest + && ! in_compare && ! spans_byte && unsignedp) + return 0; + + /* Unless we are allowed to span bytes, reject this if we would be + spanning bytes or if the position is not a constant and the length + is not 1. In all other cases, we would only be going outside + out object in cases when an original shift would have been + undefined. */ + if (! spans_byte + && ((pos_rtx == 0 && pos + len > GET_MODE_BITSIZE (is_mode)) + || (pos_rtx != 0 && len != 1))) + return 0; + + /* Get the mode to use should INNER be a MEM, the mode for the position, + and the mode for the result. */ +#ifdef HAVE_insv + if (in_dest) + { + wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_insv][0]; + pos_mode = insn_operand_mode[(int) CODE_FOR_insv][2]; + extraction_mode = insn_operand_mode[(int) CODE_FOR_insv][3]; + } +#endif + +#ifdef HAVE_extzv + if (! in_dest && unsignedp) + { + wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extzv][1]; + pos_mode = insn_operand_mode[(int) CODE_FOR_extzv][3]; + extraction_mode = insn_operand_mode[(int) CODE_FOR_extzv][0]; + } +#endif + +#ifdef HAVE_extv + if (! in_dest && ! unsignedp) + { + wanted_mem_mode = insn_operand_mode[(int) CODE_FOR_extv][1]; + pos_mode = insn_operand_mode[(int) CODE_FOR_extv][3]; + extraction_mode = insn_operand_mode[(int) CODE_FOR_extv][0]; + } +#endif + + /* Never narrow an object, since that might not be safe. */ + + if (mode != VOIDmode + && GET_MODE_SIZE (extraction_mode) < GET_MODE_SIZE (mode)) + extraction_mode = mode; + + if (pos_rtx && GET_MODE (pos_rtx) != VOIDmode + && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx))) + pos_mode = GET_MODE (pos_rtx); + + /* If this is not from memory or we have to change the mode of memory and + cannot, the desired mode is EXTRACTION_MODE. */ + if (GET_CODE (inner) != MEM + || (inner_mode != wanted_mem_mode + && (mode_dependent_address_p (XEXP (inner, 0)) + || MEM_VOLATILE_P (inner)))) + wanted_mem_mode = extraction_mode; + + orig_pos = pos; + + if (BITS_BIG_ENDIAN) + { + /* If position is constant, compute new position. Otherwise, + build subtraction. */ + if (pos_rtx == 0) + pos = (MAX (GET_MODE_BITSIZE (is_mode), + GET_MODE_BITSIZE (wanted_mem_mode)) + - len - pos); + else + pos_rtx + = gen_rtx_combine (MINUS, GET_MODE (pos_rtx), + GEN_INT (MAX (GET_MODE_BITSIZE (is_mode), + GET_MODE_BITSIZE (wanted_mem_mode)) + - len), + pos_rtx); + } + + /* If INNER has a wider mode, make it smaller. If this is a constant + extract, try to adjust the byte to point to the byte containing + the value. */ + if (wanted_mem_mode != VOIDmode + && GET_MODE_SIZE (wanted_mem_mode) < GET_MODE_SIZE (is_mode) + && ((GET_CODE (inner) == MEM + && (inner_mode == wanted_mem_mode + || (! mode_dependent_address_p (XEXP (inner, 0)) + && ! MEM_VOLATILE_P (inner)))))) + { + int offset = 0; + + /* The computations below will be correct if the machine is big + endian in both bits and bytes or little endian in bits and bytes. + If it is mixed, we must adjust. */ + + /* If bytes are big endian and we had a paradoxical SUBREG, we must + adjust OFFSET to compensate. */ + if (BYTES_BIG_ENDIAN + && ! spans_byte + && GET_MODE_SIZE (inner_mode) < GET_MODE_SIZE (is_mode)) + offset -= GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (inner_mode); + + /* If this is a constant position, we can move to the desired byte. */ + if (pos_rtx == 0) + { + offset += pos / BITS_PER_UNIT; + pos %= GET_MODE_BITSIZE (wanted_mem_mode); + } + + if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN + && ! spans_byte + && is_mode != wanted_mem_mode) + offset = (GET_MODE_SIZE (is_mode) + - GET_MODE_SIZE (wanted_mem_mode) - offset); + + if (offset != 0 || inner_mode != wanted_mem_mode) + { + rtx newmem = gen_rtx (MEM, wanted_mem_mode, + plus_constant (XEXP (inner, 0), offset)); + RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (inner); + MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (inner); + MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (inner); + inner = newmem; + } + } + + /* If INNER is not memory, we can always get it into the proper mode. */ + else if (GET_CODE (inner) != MEM) + inner = force_to_mode (inner, extraction_mode, + pos_rtx || len + orig_pos >= HOST_BITS_PER_WIDE_INT + ? GET_MODE_MASK (extraction_mode) + : (((HOST_WIDE_INT) 1 << len) - 1) << orig_pos, + NULL_RTX, 0); + + /* Adjust mode of POS_RTX, if needed. If we want a wider mode, we + have to zero extend. Otherwise, we can just use a SUBREG. */ + if (pos_rtx != 0 + && GET_MODE_SIZE (pos_mode) > GET_MODE_SIZE (GET_MODE (pos_rtx))) + pos_rtx = gen_rtx_combine (ZERO_EXTEND, pos_mode, pos_rtx); + else if (pos_rtx != 0 + && GET_MODE_SIZE (pos_mode) < GET_MODE_SIZE (GET_MODE (pos_rtx))) + pos_rtx = gen_lowpart_for_combine (pos_mode, pos_rtx); + + /* Make POS_RTX unless we already have it and it is correct. If we don't + have a POS_RTX but we do have an ORIG_POS_RTX, the latter must + be a CONST_INT. */ + if (pos_rtx == 0 && orig_pos_rtx != 0 && INTVAL (orig_pos_rtx) == pos) + pos_rtx = orig_pos_rtx; + + else if (pos_rtx == 0) + pos_rtx = GEN_INT (pos); + + /* Make the required operation. See if we can use existing rtx. */ + new = gen_rtx_combine (unsignedp ? ZERO_EXTRACT : SIGN_EXTRACT, + extraction_mode, inner, GEN_INT (len), pos_rtx); + if (! in_dest) + new = gen_lowpart_for_combine (mode, new); + + return new; +} + +/* See if X contains an ASHIFT of COUNT or more bits that can be commuted + with any other operations in X. Return X without that shift if so. */ + +static rtx +extract_left_shift (x, count) + rtx x; + int count; +{ + enum rtx_code code = GET_CODE (x); + enum machine_mode mode = GET_MODE (x); + rtx tem; + + switch (code) + { + case ASHIFT: + /* This is the shift itself. If it is wide enough, we will return + either the value being shifted if the shift count is equal to + COUNT or a shift for the difference. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= count) + return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (x, 0), + INTVAL (XEXP (x, 1)) - count); + break; + + case NEG: case NOT: + if ((tem = extract_left_shift (XEXP (x, 0), count)) != 0) + return gen_unary (code, mode, mode, tem); + + break; + + case PLUS: case IOR: case XOR: case AND: + /* If we can safely shift this constant and we find the inner shift, + make a new operation. */ + if (GET_CODE (XEXP (x,1)) == CONST_INT + && (INTVAL (XEXP (x, 1)) & (((HOST_WIDE_INT) 1 << count)) - 1) == 0 + && (tem = extract_left_shift (XEXP (x, 0), count)) != 0) + return gen_binary (code, mode, tem, + GEN_INT (INTVAL (XEXP (x, 1)) >> count)); + + break; + } + + return 0; +} + +/* Look at the expression rooted at X. Look for expressions + equivalent to ZERO_EXTRACT, SIGN_EXTRACT, ZERO_EXTEND, SIGN_EXTEND. + Form these expressions. + + Return the new rtx, usually just X. + + Also, for machines like the Vax that don't have logical shift insns, + try to convert logical to arithmetic shift operations in cases where + they are equivalent. This undoes the canonicalizations to logical + shifts done elsewhere. + + We try, as much as possible, to re-use rtl expressions to save memory. + + IN_CODE says what kind of expression we are processing. Normally, it is + SET. In a memory address (inside a MEM, PLUS or minus, the latter two + being kludges), it is MEM. When processing the arguments of a comparison + or a COMPARE against zero, it is COMPARE. */ + +static rtx +make_compound_operation (x, in_code) + rtx x; + enum rtx_code in_code; +{ + enum rtx_code code = GET_CODE (x); + enum machine_mode mode = GET_MODE (x); + int mode_width = GET_MODE_BITSIZE (mode); + rtx rhs, lhs; + enum rtx_code next_code; + int i; + rtx new = 0; + rtx tem; + char *fmt; + + /* Select the code to be used in recursive calls. Once we are inside an + address, we stay there. If we have a comparison, set to COMPARE, + but once inside, go back to our default of SET. */ + + next_code = (code == MEM || code == PLUS || code == MINUS ? MEM + : ((code == COMPARE || GET_RTX_CLASS (code) == '<') + && XEXP (x, 1) == const0_rtx) ? COMPARE + : in_code == COMPARE ? SET : in_code); + + /* Process depending on the code of this operation. If NEW is set + non-zero, it will be returned. */ + + switch (code) + { + case ASHIFT: + /* Convert shifts by constants into multiplications if inside + an address. */ + if (in_code == MEM && GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT + && INTVAL (XEXP (x, 1)) >= 0) + { + new = make_compound_operation (XEXP (x, 0), next_code); + new = gen_rtx_combine (MULT, mode, new, + GEN_INT ((HOST_WIDE_INT) 1 + << INTVAL (XEXP (x, 1)))); + } + break; + + case AND: + /* If the second operand is not a constant, we can't do anything + with it. */ + if (GET_CODE (XEXP (x, 1)) != CONST_INT) + break; + + /* If the constant is a power of two minus one and the first operand + is a logical right shift, make an extraction. */ + if (GET_CODE (XEXP (x, 0)) == LSHIFTRT + && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0) + { + new = make_compound_operation (XEXP (XEXP (x, 0), 0), next_code); + new = make_extraction (mode, new, 0, XEXP (XEXP (x, 0), 1), i, 1, + 0, in_code == COMPARE); + } + + /* Same as previous, but for (subreg (lshiftrt ...)) in first op. */ + else if (GET_CODE (XEXP (x, 0)) == SUBREG + && subreg_lowpart_p (XEXP (x, 0)) + && GET_CODE (SUBREG_REG (XEXP (x, 0))) == LSHIFTRT + && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0) + { + new = make_compound_operation (XEXP (SUBREG_REG (XEXP (x, 0)), 0), + next_code); + new = make_extraction (GET_MODE (SUBREG_REG (XEXP (x, 0))), new, 0, + XEXP (SUBREG_REG (XEXP (x, 0)), 1), i, 1, + 0, in_code == COMPARE); + } + /* Same as previous, but for (xor/ior (lshiftrt...) (lshiftrt...)). */ + else if ((GET_CODE (XEXP (x, 0)) == XOR + || GET_CODE (XEXP (x, 0)) == IOR) + && GET_CODE (XEXP (XEXP (x, 0), 0)) == LSHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == LSHIFTRT + && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0) + { + /* Apply the distributive law, and then try to make extractions. */ + new = gen_rtx_combine (GET_CODE (XEXP (x, 0)), mode, + gen_rtx (AND, mode, XEXP (XEXP (x, 0), 0), + XEXP (x, 1)), + gen_rtx (AND, mode, XEXP (XEXP (x, 0), 1), + XEXP (x, 1))); + new = make_compound_operation (new, in_code); + } + + /* If we are have (and (rotate X C) M) and C is larger than the number + of bits in M, this is an extraction. */ + + else if (GET_CODE (XEXP (x, 0)) == ROTATE + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && (i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0 + && i <= INTVAL (XEXP (XEXP (x, 0), 1))) + { + new = make_compound_operation (XEXP (XEXP (x, 0), 0), next_code); + new = make_extraction (mode, new, + (GET_MODE_BITSIZE (mode) + - INTVAL (XEXP (XEXP (x, 0), 1))), + NULL_RTX, i, 1, 0, in_code == COMPARE); + } + + /* On machines without logical shifts, if the operand of the AND is + a logical shift and our mask turns off all the propagated sign + bits, we can replace the logical shift with an arithmetic shift. */ + else if (ashr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing + && (lshr_optab->handlers[(int) mode].insn_code + == CODE_FOR_nothing) + && GET_CODE (XEXP (x, 0)) == LSHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0 + && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT + && mode_width <= HOST_BITS_PER_WIDE_INT) + { + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode); + + mask >>= INTVAL (XEXP (XEXP (x, 0), 1)); + if ((INTVAL (XEXP (x, 1)) & ~mask) == 0) + SUBST (XEXP (x, 0), + gen_rtx_combine (ASHIFTRT, mode, + make_compound_operation (XEXP (XEXP (x, 0), 0), + next_code), + XEXP (XEXP (x, 0), 1))); + } + + /* If the constant is one less than a power of two, this might be + representable by an extraction even if no shift is present. + If it doesn't end up being a ZERO_EXTEND, we will ignore it unless + we are in a COMPARE. */ + else if ((i = exact_log2 (INTVAL (XEXP (x, 1)) + 1)) >= 0) + new = make_extraction (mode, + make_compound_operation (XEXP (x, 0), + next_code), + 0, NULL_RTX, i, 1, 0, in_code == COMPARE); + + /* If we are in a comparison and this is an AND with a power of two, + convert this into the appropriate bit extract. */ + else if (in_code == COMPARE + && (i = exact_log2 (INTVAL (XEXP (x, 1)))) >= 0) + new = make_extraction (mode, + make_compound_operation (XEXP (x, 0), + next_code), + i, NULL_RTX, 1, 1, 0, 1); + + break; + + case LSHIFTRT: + /* If the sign bit is known to be zero, replace this with an + arithmetic shift. */ + if (ashr_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing + && lshr_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing + && mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (x, 0), mode) & (1 << (mode_width - 1))) == 0) + { + new = gen_rtx_combine (ASHIFTRT, mode, + make_compound_operation (XEXP (x, 0), + next_code), + XEXP (x, 1)); + break; + } + + /* ... fall through ... */ + + case ASHIFTRT: + lhs = XEXP (x, 0); + rhs = XEXP (x, 1); + + /* If we have (ashiftrt (ashift foo C1) C2) with C2 >= C1, + this is a SIGN_EXTRACT. */ + if (GET_CODE (rhs) == CONST_INT + && GET_CODE (lhs) == ASHIFT + && GET_CODE (XEXP (lhs, 1)) == CONST_INT + && INTVAL (rhs) >= INTVAL (XEXP (lhs, 1))) + { + new = make_compound_operation (XEXP (lhs, 0), next_code); + new = make_extraction (mode, new, + INTVAL (rhs) - INTVAL (XEXP (lhs, 1)), + NULL_RTX, mode_width - INTVAL (rhs), + code == LSHIFTRT, 0, in_code == COMPARE); + } + + /* See if we have operations between an ASHIFTRT and an ASHIFT. + If so, try to merge the shifts into a SIGN_EXTEND. We could + also do this for some cases of SIGN_EXTRACT, but it doesn't + seem worth the effort; the case checked for occurs on Alpha. */ + + if (GET_RTX_CLASS (GET_CODE (lhs)) != 'o' + && ! (GET_CODE (lhs) == SUBREG + && (GET_RTX_CLASS (GET_CODE (SUBREG_REG (lhs))) == 'o')) + && GET_CODE (rhs) == CONST_INT + && INTVAL (rhs) < HOST_BITS_PER_WIDE_INT + && (new = extract_left_shift (lhs, INTVAL (rhs))) != 0) + new = make_extraction (mode, make_compound_operation (new, next_code), + 0, NULL_RTX, mode_width - INTVAL (rhs), + code == LSHIFTRT, 0, in_code == COMPARE); + + break; + + case SUBREG: + /* Call ourselves recursively on the inner expression. If we are + narrowing the object and it has a different RTL code from + what it originally did, do this SUBREG as a force_to_mode. */ + + tem = make_compound_operation (SUBREG_REG (x), in_code); + if (GET_CODE (tem) != GET_CODE (SUBREG_REG (x)) + && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (tem)) + && subreg_lowpart_p (x)) + { + rtx newer = force_to_mode (tem, mode, + GET_MODE_MASK (mode), NULL_RTX, 0); + + /* If we have something other than a SUBREG, we might have + done an expansion, so rerun outselves. */ + if (GET_CODE (newer) != SUBREG) + newer = make_compound_operation (newer, in_code); + + return newer; + } + } + + if (new) + { + x = gen_lowpart_for_combine (mode, new); + code = GET_CODE (x); + } + + /* Now recursively process each operand of this operation. */ + fmt = GET_RTX_FORMAT (code); + for (i = 0; i < GET_RTX_LENGTH (code); i++) + if (fmt[i] == 'e') + { + new = make_compound_operation (XEXP (x, i), next_code); + SUBST (XEXP (x, i), new); + } + + return x; +} + +/* Given M see if it is a value that would select a field of bits + within an item, but not the entire word. Return -1 if not. + Otherwise, return the starting position of the field, where 0 is the + low-order bit. + + *PLEN is set to the length of the field. */ + +static int +get_pos_from_mask (m, plen) + unsigned HOST_WIDE_INT m; + int *plen; +{ + /* Get the bit number of the first 1 bit from the right, -1 if none. */ + int pos = exact_log2 (m & - m); + + if (pos < 0) + return -1; + + /* Now shift off the low-order zero bits and see if we have a power of + two minus 1. */ + *plen = exact_log2 ((m >> pos) + 1); + + if (*plen <= 0) + return -1; + + return pos; +} + +/* See if X can be simplified knowing that we will only refer to it in + MODE and will only refer to those bits that are nonzero in MASK. + If other bits are being computed or if masking operations are done + that select a superset of the bits in MASK, they can sometimes be + ignored. + + Return a possibly simplified expression, but always convert X to + MODE. If X is a CONST_INT, AND the CONST_INT with MASK. + + Also, if REG is non-zero and X is a register equal in value to REG, + replace X with REG. + + If JUST_SELECT is nonzero, don't optimize by noticing that bits in MASK + are all off in X. This is used when X will be complemented, by either + NOT, NEG, or XOR. */ + +static rtx +force_to_mode (x, mode, mask, reg, just_select) + rtx x; + enum machine_mode mode; + unsigned HOST_WIDE_INT mask; + rtx reg; + int just_select; +{ + enum rtx_code code = GET_CODE (x); + int next_select = just_select || code == XOR || code == NOT || code == NEG; + enum machine_mode op_mode; + unsigned HOST_WIDE_INT fuller_mask, nonzero; + rtx op0, op1, temp; + + /* If this is a CALL, don't do anything. Some of the code below + will do the wrong thing since the mode of a CALL is VOIDmode. */ + if (code == CALL) + return x; + + /* We want to perform the operation is its present mode unless we know + that the operation is valid in MODE, in which case we do the operation + in MODE. */ + op_mode = ((GET_MODE_CLASS (mode) == GET_MODE_CLASS (GET_MODE (x)) + && code_to_optab[(int) code] != 0 + && (code_to_optab[(int) code]->handlers[(int) mode].insn_code + != CODE_FOR_nothing)) + ? mode : GET_MODE (x)); + + /* It is not valid to do a right-shift in a narrower mode + than the one it came in with. */ + if ((code == LSHIFTRT || code == ASHIFTRT) + && GET_MODE_BITSIZE (mode) < GET_MODE_BITSIZE (GET_MODE (x))) + op_mode = GET_MODE (x); + + /* Truncate MASK to fit OP_MODE. */ + if (op_mode) + mask &= GET_MODE_MASK (op_mode); + + /* When we have an arithmetic operation, or a shift whose count we + do not know, we need to assume that all bit the up to the highest-order + bit in MASK will be needed. This is how we form such a mask. */ + if (op_mode) + fuller_mask = (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT + ? GET_MODE_MASK (op_mode) + : ((HOST_WIDE_INT) 1 << (floor_log2 (mask) + 1)) - 1); + else + fuller_mask = ~ (HOST_WIDE_INT) 0; + + /* Determine what bits of X are guaranteed to be (non)zero. */ + nonzero = nonzero_bits (x, mode); + + /* If none of the bits in X are needed, return a zero. */ + if (! just_select && (nonzero & mask) == 0) + return const0_rtx; + + /* If X is a CONST_INT, return a new one. Do this here since the + test below will fail. */ + if (GET_CODE (x) == CONST_INT) + { + HOST_WIDE_INT cval = INTVAL (x) & mask; + int width = GET_MODE_BITSIZE (mode); + + /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative + number, sign extend it. */ + if (width > 0 && width < HOST_BITS_PER_WIDE_INT + && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0) + cval |= (HOST_WIDE_INT) -1 << width; + + return GEN_INT (cval); + } + + /* If X is narrower than MODE and we want all the bits in X's mode, just + get X in the proper mode. */ + if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode) + && (GET_MODE_MASK (GET_MODE (x)) & ~ mask) == 0) + return gen_lowpart_for_combine (mode, x); + + /* If we aren't changing the mode, X is not a SUBREG, and all zero bits in + MASK are already known to be zero in X, we need not do anything. */ + if (GET_MODE (x) == mode && code != SUBREG && (~ mask & nonzero) == 0) + return x; + + switch (code) + { + case CLOBBER: + /* If X is a (clobber (const_int)), return it since we know we are + generating something that won't match. */ + return x; + + case USE: + /* X is a (use (mem ..)) that was made from a bit-field extraction that + spanned the boundary of the MEM. If we are now masking so it is + within that boundary, we don't need the USE any more. */ + if (! BITS_BIG_ENDIAN + && (mask & ~ GET_MODE_MASK (GET_MODE (XEXP (x, 0)))) == 0) + return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select); + break; + + case SIGN_EXTEND: + case ZERO_EXTEND: + case ZERO_EXTRACT: + case SIGN_EXTRACT: + x = expand_compound_operation (x); + if (GET_CODE (x) != code) + return force_to_mode (x, mode, mask, reg, next_select); + break; + + case REG: + if (reg != 0 && (rtx_equal_p (get_last_value (reg), x) + || rtx_equal_p (reg, get_last_value (x)))) + x = reg; + break; + + case SUBREG: + if (subreg_lowpart_p (x) + /* We can ignore the effect of this SUBREG if it narrows the mode or + if the constant masks to zero all the bits the mode doesn't + have. */ + && ((GET_MODE_SIZE (GET_MODE (x)) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) + || (0 == (mask + & GET_MODE_MASK (GET_MODE (x)) + & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (x))))))) + return force_to_mode (SUBREG_REG (x), mode, mask, reg, next_select); + break; + + case AND: + /* If this is an AND with a constant, convert it into an AND + whose constant is the AND of that constant with MASK. If it + remains an AND of MASK, delete it since it is redundant. */ + + if (GET_CODE (XEXP (x, 1)) == CONST_INT) + { + x = simplify_and_const_int (x, op_mode, XEXP (x, 0), + mask & INTVAL (XEXP (x, 1))); + + /* If X is still an AND, see if it is an AND with a mask that + is just some low-order bits. If so, and it is MASK, we don't + need it. */ + + if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) == mask) + x = XEXP (x, 0); + + /* If it remains an AND, try making another AND with the bits + in the mode mask that aren't in MASK turned on. If the + constant in the AND is wide enough, this might make a + cheaper constant. */ + + if (GET_CODE (x) == AND && GET_CODE (XEXP (x, 1)) == CONST_INT + && GET_MODE_MASK (GET_MODE (x)) != mask + && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT) + { + HOST_WIDE_INT cval = (INTVAL (XEXP (x, 1)) + | (GET_MODE_MASK (GET_MODE (x)) & ~ mask)); + int width = GET_MODE_BITSIZE (GET_MODE (x)); + rtx y; + + /* If MODE is narrower that HOST_WIDE_INT and CVAL is a negative + number, sign extend it. */ + if (width > 0 && width < HOST_BITS_PER_WIDE_INT + && (cval & ((HOST_WIDE_INT) 1 << (width - 1))) != 0) + cval |= (HOST_WIDE_INT) -1 << width; + + y = gen_binary (AND, GET_MODE (x), XEXP (x, 0), GEN_INT (cval)); + if (rtx_cost (y, SET) < rtx_cost (x, SET)) + x = y; + } + + break; + } + + goto binop; + + case PLUS: + /* In (and (plus FOO C1) M), if M is a mask that just turns off + low-order bits (as in an alignment operation) and FOO is already + aligned to that boundary, mask C1 to that boundary as well. + This may eliminate that PLUS and, later, the AND. */ + + { + int width = GET_MODE_BITSIZE (mode); + unsigned HOST_WIDE_INT smask = mask; + + /* If MODE is narrower than HOST_WIDE_INT and mask is a negative + number, sign extend it. */ + + if (width < HOST_BITS_PER_WIDE_INT + && (smask & ((HOST_WIDE_INT) 1 << (width - 1))) != 0) + smask |= (HOST_WIDE_INT) -1 << width; + + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && exact_log2 (- smask) >= 0 + && (nonzero_bits (XEXP (x, 0), mode) & ~ mask) == 0 + && (INTVAL (XEXP (x, 1)) & ~ mask) != 0) + return force_to_mode (plus_constant (XEXP (x, 0), + INTVAL (XEXP (x, 1)) & mask), + mode, mask, reg, next_select); + } + + /* ... fall through ... */ + + case MINUS: + case MULT: + /* For PLUS, MINUS and MULT, we need any bits less significant than the + most significant bit in MASK since carries from those bits will + affect the bits we are interested in. */ + mask = fuller_mask; + goto binop; + + case IOR: + case XOR: + /* If X is (ior (lshiftrt FOO C1) C2), try to commute the IOR and + LSHIFTRT so we end up with an (and (lshiftrt (ior ...) ...) ...) + operation which may be a bitfield extraction. Ensure that the + constant we form is not wider than the mode of X. */ + + if (GET_CODE (XEXP (x, 0)) == LSHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0 + && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT + && GET_CODE (XEXP (x, 1)) == CONST_INT + && ((INTVAL (XEXP (XEXP (x, 0), 1)) + + floor_log2 (INTVAL (XEXP (x, 1)))) + < GET_MODE_BITSIZE (GET_MODE (x))) + && (INTVAL (XEXP (x, 1)) + & ~ nonzero_bits (XEXP (x, 0), GET_MODE (x)) == 0)) + { + temp = GEN_INT ((INTVAL (XEXP (x, 1)) & mask) + << INTVAL (XEXP (XEXP (x, 0), 1))); + temp = gen_binary (GET_CODE (x), GET_MODE (x), + XEXP (XEXP (x, 0), 0), temp); + x = gen_binary (LSHIFTRT, GET_MODE (x), temp, XEXP (x, 1)); + return force_to_mode (x, mode, mask, reg, next_select); + } + + binop: + /* For most binary operations, just propagate into the operation and + change the mode if we have an operation of that mode. */ + + op0 = gen_lowpart_for_combine (op_mode, + force_to_mode (XEXP (x, 0), mode, mask, + reg, next_select)); + op1 = gen_lowpart_for_combine (op_mode, + force_to_mode (XEXP (x, 1), mode, mask, + reg, next_select)); + + /* If OP1 is a CONST_INT and X is an IOR or XOR, clear bits outside + MASK since OP1 might have been sign-extended but we never want + to turn on extra bits, since combine might have previously relied + on them being off. */ + if (GET_CODE (op1) == CONST_INT && (code == IOR || code == XOR) + && (INTVAL (op1) & mask) != 0) + op1 = GEN_INT (INTVAL (op1) & mask); + + if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0) || op1 != XEXP (x, 1)) + x = gen_binary (code, op_mode, op0, op1); + break; + + case ASHIFT: + /* For left shifts, do the same, but just for the first operand. + However, we cannot do anything with shifts where we cannot + guarantee that the counts are smaller than the size of the mode + because such a count will have a different meaning in a + wider mode. */ + + if (! (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0 + && INTVAL (XEXP (x, 1)) < GET_MODE_BITSIZE (mode)) + && ! (GET_MODE (XEXP (x, 1)) != VOIDmode + && (nonzero_bits (XEXP (x, 1), GET_MODE (XEXP (x, 1))) + < (unsigned HOST_WIDE_INT) GET_MODE_BITSIZE (mode)))) + break; + + /* If the shift count is a constant and we can do arithmetic in + the mode of the shift, refine which bits we need. Otherwise, use the + conservative form of the mask. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0 + && INTVAL (XEXP (x, 1)) < GET_MODE_BITSIZE (op_mode) + && GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT) + mask >>= INTVAL (XEXP (x, 1)); + else + mask = fuller_mask; + + op0 = gen_lowpart_for_combine (op_mode, + force_to_mode (XEXP (x, 0), op_mode, + mask, reg, next_select)); + + if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0)) + x = gen_binary (code, op_mode, op0, XEXP (x, 1)); + break; + + case LSHIFTRT: + /* Here we can only do something if the shift count is a constant, + this shift constant is valid for the host, and we can do arithmetic + in OP_MODE. */ + + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT + && GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT) + { + rtx inner = XEXP (x, 0); + + /* Select the mask of the bits we need for the shift operand. */ + mask <<= INTVAL (XEXP (x, 1)); + + /* We can only change the mode of the shift if we can do arithmetic + in the mode of the shift and MASK is no wider than the width of + OP_MODE. */ + if (GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT + || (mask & ~ GET_MODE_MASK (op_mode)) != 0) + op_mode = GET_MODE (x); + + inner = force_to_mode (inner, op_mode, mask, reg, next_select); + + if (GET_MODE (x) != op_mode || inner != XEXP (x, 0)) + x = gen_binary (LSHIFTRT, op_mode, inner, XEXP (x, 1)); + } + + /* If we have (and (lshiftrt FOO C1) C2) where the combination of the + shift and AND produces only copies of the sign bit (C2 is one less + than a power of two), we can do this with just a shift. */ + + if (GET_CODE (x) == LSHIFTRT + && GET_CODE (XEXP (x, 1)) == CONST_INT + && ((INTVAL (XEXP (x, 1)) + + num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0)))) + >= GET_MODE_BITSIZE (GET_MODE (x))) + && exact_log2 (mask + 1) >= 0 + && (num_sign_bit_copies (XEXP (x, 0), GET_MODE (XEXP (x, 0))) + >= exact_log2 (mask + 1))) + x = gen_binary (LSHIFTRT, GET_MODE (x), XEXP (x, 0), + GEN_INT (GET_MODE_BITSIZE (GET_MODE (x)) + - exact_log2 (mask + 1))); + break; + + case ASHIFTRT: + /* If we are just looking for the sign bit, we don't need this shift at + all, even if it has a variable count. */ + if (GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT + && (mask == ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (x)) - 1)))) + return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select); + + /* If this is a shift by a constant, get a mask that contains those bits + that are not copies of the sign bit. We then have two cases: If + MASK only includes those bits, this can be a logical shift, which may + allow simplifications. If MASK is a single-bit field not within + those bits, we are requesting a copy of the sign bit and hence can + shift the sign bit to the appropriate location. */ + + if (GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) >= 0 + && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT) + { + int i = -1; + + /* If the considered data is wider then HOST_WIDE_INT, we can't + represent a mask for all its bits in a single scalar. + But we only care about the lower bits, so calculate these. */ + + if (GET_MODE_BITSIZE (GET_MODE (x)) > HOST_BITS_PER_WIDE_INT) + { + nonzero = ~(HOST_WIDE_INT)0; + + /* GET_MODE_BITSIZE (GET_MODE (x)) - INTVAL (XEXP (x, 1)) + is the number of bits a full-width mask would have set. + We need only shift if these are fewer than nonzero can + hold. If not, we must keep all bits set in nonzero. */ + + if (GET_MODE_BITSIZE (GET_MODE (x)) - INTVAL (XEXP (x, 1)) + < HOST_BITS_PER_WIDE_INT) + nonzero >>= INTVAL (XEXP (x, 1)) + + HOST_BITS_PER_WIDE_INT + - GET_MODE_BITSIZE (GET_MODE (x)) ; + } + else + { + nonzero = GET_MODE_MASK (GET_MODE (x)); + nonzero >>= INTVAL (XEXP (x, 1)); + } + + if ((mask & ~ nonzero) == 0 + || (i = exact_log2 (mask)) >= 0) + { + x = simplify_shift_const + (x, LSHIFTRT, GET_MODE (x), XEXP (x, 0), + i < 0 ? INTVAL (XEXP (x, 1)) + : GET_MODE_BITSIZE (GET_MODE (x)) - 1 - i); + + if (GET_CODE (x) != ASHIFTRT) + return force_to_mode (x, mode, mask, reg, next_select); + } + } + + /* If MASK is 1, convert this to a LSHIFTRT. This can be done + even if the shift count isn't a constant. */ + if (mask == 1) + x = gen_binary (LSHIFTRT, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)); + + /* If this is a sign-extension operation that just affects bits + we don't care about, remove it. Be sure the call above returned + something that is still a shift. */ + + if ((GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ASHIFTRT) + && GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0 + && (INTVAL (XEXP (x, 1)) + <= GET_MODE_BITSIZE (GET_MODE (x)) - (floor_log2 (mask) + 1)) + && GET_CODE (XEXP (x, 0)) == ASHIFT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (x, 0), 1)) == INTVAL (XEXP (x, 1))) + return force_to_mode (XEXP (XEXP (x, 0), 0), mode, mask, + reg, next_select); + + break; + + case ROTATE: + case ROTATERT: + /* If the shift count is constant and we can do computations + in the mode of X, compute where the bits we care about are. + Otherwise, we can't do anything. Don't change the mode of + the shift or propagate MODE into the shift, though. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0) + { + temp = simplify_binary_operation (code == ROTATE ? ROTATERT : ROTATE, + GET_MODE (x), GEN_INT (mask), + XEXP (x, 1)); + if (temp && GET_CODE(temp) == CONST_INT) + SUBST (XEXP (x, 0), + force_to_mode (XEXP (x, 0), GET_MODE (x), + INTVAL (temp), reg, next_select)); + } + break; + + case NEG: + /* If we just want the low-order bit, the NEG isn't needed since it + won't change the low-order bit. */ + if (mask == 1) + return force_to_mode (XEXP (x, 0), mode, mask, reg, just_select); + + /* We need any bits less significant than the most significant bit in + MASK since carries from those bits will affect the bits we are + interested in. */ + mask = fuller_mask; + goto unop; + + case NOT: + /* (not FOO) is (xor FOO CONST), so if FOO is an LSHIFTRT, we can do the + same as the XOR case above. Ensure that the constant we form is not + wider than the mode of X. */ + + if (GET_CODE (XEXP (x, 0)) == LSHIFTRT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (x, 0), 1)) >= 0 + && (INTVAL (XEXP (XEXP (x, 0), 1)) + floor_log2 (mask) + < GET_MODE_BITSIZE (GET_MODE (x))) + && INTVAL (XEXP (XEXP (x, 0), 1)) < HOST_BITS_PER_WIDE_INT) + { + temp = GEN_INT (mask << INTVAL (XEXP (XEXP (x, 0), 1))); + temp = gen_binary (XOR, GET_MODE (x), XEXP (XEXP (x, 0), 0), temp); + x = gen_binary (LSHIFTRT, GET_MODE (x), temp, XEXP (XEXP (x, 0), 1)); + + return force_to_mode (x, mode, mask, reg, next_select); + } + + unop: + op0 = gen_lowpart_for_combine (op_mode, + force_to_mode (XEXP (x, 0), mode, mask, + reg, next_select)); + if (op_mode != GET_MODE (x) || op0 != XEXP (x, 0)) + x = gen_unary (code, op_mode, op_mode, op0); + break; + + case NE: + /* (and (ne FOO 0) CONST) can be (and FOO CONST) if CONST is included + in STORE_FLAG_VALUE and FOO has no bits that might be nonzero not + in CONST. */ + if ((mask & ~ STORE_FLAG_VALUE) == 0 && XEXP (x, 0) == const0_rtx + && (nonzero_bits (XEXP (x, 0), mode) & ~ mask) == 0) + return force_to_mode (XEXP (x, 0), mode, mask, reg, next_select); + + break; + + case IF_THEN_ELSE: + /* We have no way of knowing if the IF_THEN_ELSE can itself be + written in a narrower mode. We play it safe and do not do so. */ + + SUBST (XEXP (x, 1), + gen_lowpart_for_combine (GET_MODE (x), + force_to_mode (XEXP (x, 1), mode, + mask, reg, next_select))); + SUBST (XEXP (x, 2), + gen_lowpart_for_combine (GET_MODE (x), + force_to_mode (XEXP (x, 2), mode, + mask, reg,next_select))); + break; + } + + /* Ensure we return a value of the proper mode. */ + return gen_lowpart_for_combine (mode, x); +} + +/* Return nonzero if X is an expression that has one of two values depending on + whether some other value is zero or nonzero. In that case, we return the + value that is being tested, *PTRUE is set to the value if the rtx being + returned has a nonzero value, and *PFALSE is set to the other alternative. + + If we return zero, we set *PTRUE and *PFALSE to X. */ + +static rtx +if_then_else_cond (x, ptrue, pfalse) + rtx x; + rtx *ptrue, *pfalse; +{ + enum machine_mode mode = GET_MODE (x); + enum rtx_code code = GET_CODE (x); + int size = GET_MODE_BITSIZE (mode); + rtx cond0, cond1, true0, true1, false0, false1; + unsigned HOST_WIDE_INT nz; + + /* If this is a unary operation whose operand has one of two values, apply + our opcode to compute those values. */ + if (GET_RTX_CLASS (code) == '1' + && (cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0)) != 0) + { + *ptrue = gen_unary (code, mode, GET_MODE (XEXP (x, 0)), true0); + *pfalse = gen_unary (code, mode, GET_MODE (XEXP (x, 0)), false0); + return cond0; + } + + /* If this is a COMPARE, do nothing, since the IF_THEN_ELSE we would + make can't possibly match and would suppress other optimizations. */ + else if (code == COMPARE) + ; + + /* If this is a binary operation, see if either side has only one of two + values. If either one does or if both do and they are conditional on + the same value, compute the new true and false values. */ + else if (GET_RTX_CLASS (code) == 'c' || GET_RTX_CLASS (code) == '2' + || GET_RTX_CLASS (code) == '<') + { + cond0 = if_then_else_cond (XEXP (x, 0), &true0, &false0); + cond1 = if_then_else_cond (XEXP (x, 1), &true1, &false1); + + if ((cond0 != 0 || cond1 != 0) + && ! (cond0 != 0 && cond1 != 0 && ! rtx_equal_p (cond0, cond1))) + { + *ptrue = gen_binary (code, mode, true0, true1); + *pfalse = gen_binary (code, mode, false0, false1); + return cond0 ? cond0 : cond1; + } + +#if STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1 + + /* See if we have PLUS, IOR, XOR, MINUS or UMAX, where one of the + operands is zero when the other is non-zero, and vice-versa. */ + + if ((code == PLUS || code == IOR || code == XOR || code == MINUS + || code == UMAX) + && GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == MULT) + { + rtx op0 = XEXP (XEXP (x, 0), 1); + rtx op1 = XEXP (XEXP (x, 1), 1); + + cond0 = XEXP (XEXP (x, 0), 0); + cond1 = XEXP (XEXP (x, 1), 0); + + if (GET_RTX_CLASS (GET_CODE (cond0)) == '<' + && GET_RTX_CLASS (GET_CODE (cond1)) == '<' + && reversible_comparison_p (cond1) + && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1)) + && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0)) + && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1))) + || ((swap_condition (GET_CODE (cond0)) + == reverse_condition (GET_CODE (cond1))) + && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1)) + && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0)))) + && ! side_effects_p (x)) + { + *ptrue = gen_binary (MULT, mode, op0, const_true_rtx); + *pfalse = gen_binary (MULT, mode, + (code == MINUS + ? gen_unary (NEG, mode, mode, op1) : op1), + const_true_rtx); + return cond0; + } + } + + /* Similarly for MULT, AND and UMIN, execpt that for these the result + is always zero. */ + if ((code == MULT || code == AND || code == UMIN) + && GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == MULT) + { + cond0 = XEXP (XEXP (x, 0), 0); + cond1 = XEXP (XEXP (x, 1), 0); + + if (GET_RTX_CLASS (GET_CODE (cond0)) == '<' + && GET_RTX_CLASS (GET_CODE (cond1)) == '<' + && reversible_comparison_p (cond1) + && ((GET_CODE (cond0) == reverse_condition (GET_CODE (cond1)) + && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 0)) + && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 1))) + || ((swap_condition (GET_CODE (cond0)) + == reverse_condition (GET_CODE (cond1))) + && rtx_equal_p (XEXP (cond0, 0), XEXP (cond1, 1)) + && rtx_equal_p (XEXP (cond0, 1), XEXP (cond1, 0)))) + && ! side_effects_p (x)) + { + *ptrue = *pfalse = const0_rtx; + return cond0; + } + } +#endif + } + + else if (code == IF_THEN_ELSE) + { + /* If we have IF_THEN_ELSE already, extract the condition and + canonicalize it if it is NE or EQ. */ + cond0 = XEXP (x, 0); + *ptrue = XEXP (x, 1), *pfalse = XEXP (x, 2); + if (GET_CODE (cond0) == NE && XEXP (cond0, 1) == const0_rtx) + return XEXP (cond0, 0); + else if (GET_CODE (cond0) == EQ && XEXP (cond0, 1) == const0_rtx) + { + *ptrue = XEXP (x, 2), *pfalse = XEXP (x, 1); + return XEXP (cond0, 0); + } + else + return cond0; + } + + /* If X is a normal SUBREG with both inner and outer modes integral, + we can narrow both the true and false values of the inner expression, + if there is a condition. */ + else if (code == SUBREG && GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_CLASS (GET_MODE (SUBREG_REG (x))) == MODE_INT + && GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) + && 0 != (cond0 = if_then_else_cond (SUBREG_REG (x), + &true0, &false0))) + { + *ptrue = force_to_mode (true0, mode, GET_MODE_MASK (mode), NULL_RTX, 0); + *pfalse + = force_to_mode (false0, mode, GET_MODE_MASK (mode), NULL_RTX, 0); + + return cond0; + } + + /* If X is a constant, this isn't special and will cause confusions + if we treat it as such. Likewise if it is equivalent to a constant. */ + else if (CONSTANT_P (x) + || ((cond0 = get_last_value (x)) != 0 && CONSTANT_P (cond0))) + ; + + /* If X is known to be either 0 or -1, those are the true and + false values when testing X. */ + else if (num_sign_bit_copies (x, mode) == size) + { + *ptrue = constm1_rtx, *pfalse = const0_rtx; + return x; + } + + /* Likewise for 0 or a single bit. */ + else if (exact_log2 (nz = nonzero_bits (x, mode)) >= 0) + { + *ptrue = GEN_INT (nz), *pfalse = const0_rtx; + return x; + } + + /* Otherwise fail; show no condition with true and false values the same. */ + *ptrue = *pfalse = x; + return 0; +} + +/* Return the value of expression X given the fact that condition COND + is known to be true when applied to REG as its first operand and VAL + as its second. X is known to not be shared and so can be modified in + place. + + We only handle the simplest cases, and specifically those cases that + arise with IF_THEN_ELSE expressions. */ + +static rtx +known_cond (x, cond, reg, val) + rtx x; + enum rtx_code cond; + rtx reg, val; +{ + enum rtx_code code = GET_CODE (x); + rtx temp; + char *fmt; + int i, j; + + if (side_effects_p (x)) + return x; + + if (cond == EQ && rtx_equal_p (x, reg)) + return val; + + /* If X is (abs REG) and we know something about REG's relationship + with zero, we may be able to simplify this. */ + + if (code == ABS && rtx_equal_p (XEXP (x, 0), reg) && val == const0_rtx) + switch (cond) + { + case GE: case GT: case EQ: + return XEXP (x, 0); + case LT: case LE: + return gen_unary (NEG, GET_MODE (XEXP (x, 0)), GET_MODE (XEXP (x, 0)), + XEXP (x, 0)); + } + + /* The only other cases we handle are MIN, MAX, and comparisons if the + operands are the same as REG and VAL. */ + + else if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c') + { + if (rtx_equal_p (XEXP (x, 0), val)) + cond = swap_condition (cond), temp = val, val = reg, reg = temp; + + if (rtx_equal_p (XEXP (x, 0), reg) && rtx_equal_p (XEXP (x, 1), val)) + { + if (GET_RTX_CLASS (code) == '<') + return (comparison_dominates_p (cond, code) ? const_true_rtx + : (comparison_dominates_p (cond, + reverse_condition (code)) + ? const0_rtx : x)); + + else if (code == SMAX || code == SMIN + || code == UMIN || code == UMAX) + { + int unsignedp = (code == UMIN || code == UMAX); + + if (code == SMAX || code == UMAX) + cond = reverse_condition (cond); + + switch (cond) + { + case GE: case GT: + return unsignedp ? x : XEXP (x, 1); + case LE: case LT: + return unsignedp ? x : XEXP (x, 0); + case GEU: case GTU: + return unsignedp ? XEXP (x, 1) : x; + case LEU: case LTU: + return unsignedp ? XEXP (x, 0) : x; + } + } + } + } + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'e') + SUBST (XEXP (x, i), known_cond (XEXP (x, i), cond, reg, val)); + else if (fmt[i] == 'E') + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + SUBST (XVECEXP (x, i, j), known_cond (XVECEXP (x, i, j), + cond, reg, val)); + } + + return x; +} + +/* See if X, a SET operation, can be rewritten as a bit-field assignment. + Return that assignment if so. + + We only handle the most common cases. */ + +static rtx +make_field_assignment (x) + rtx x; +{ + rtx dest = SET_DEST (x); + rtx src = SET_SRC (x); + rtx assign; + HOST_WIDE_INT c1; + int pos, len; + rtx other; + enum machine_mode mode; + + /* If SRC was (and (not (ashift (const_int 1) POS)) DEST), this is + a clear of a one-bit field. We will have changed it to + (and (rotate (const_int -2) POS) DEST), so check for that. Also check + for a SUBREG. */ + + if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == ROTATE + && GET_CODE (XEXP (XEXP (src, 0), 0)) == CONST_INT + && INTVAL (XEXP (XEXP (src, 0), 0)) == -2 + && (rtx_equal_p (dest, XEXP (src, 1)) + || rtx_equal_p (dest, get_last_value (XEXP (src, 1))) + || rtx_equal_p (get_last_value (dest), XEXP (src, 1)))) + { + assign = make_extraction (VOIDmode, dest, 0, XEXP (XEXP (src, 0), 1), + 1, 1, 1, 0); + return gen_rtx (SET, VOIDmode, assign, const0_rtx); + } + + else if (GET_CODE (src) == AND && GET_CODE (XEXP (src, 0)) == SUBREG + && subreg_lowpart_p (XEXP (src, 0)) + && (GET_MODE_SIZE (GET_MODE (XEXP (src, 0))) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (XEXP (src, 0))))) + && GET_CODE (SUBREG_REG (XEXP (src, 0))) == ROTATE + && INTVAL (XEXP (SUBREG_REG (XEXP (src, 0)), 0)) == -2 + && (rtx_equal_p (dest, XEXP (src, 1)) + || rtx_equal_p (dest, get_last_value (XEXP (src, 1))) + || rtx_equal_p (get_last_value (dest), XEXP (src, 1)))) + { + assign = make_extraction (VOIDmode, dest, 0, + XEXP (SUBREG_REG (XEXP (src, 0)), 1), + 1, 1, 1, 0); + return gen_rtx (SET, VOIDmode, assign, const0_rtx); + } + + /* If SRC is (ior (ashift (const_int 1) POS DEST)), this is a set of a + one-bit field. */ + else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == ASHIFT + && XEXP (XEXP (src, 0), 0) == const1_rtx + && (rtx_equal_p (dest, XEXP (src, 1)) + || rtx_equal_p (dest, get_last_value (XEXP (src, 1))) + || rtx_equal_p (get_last_value (dest), XEXP (src, 1)))) + { + assign = make_extraction (VOIDmode, dest, 0, XEXP (XEXP (src, 0), 1), + 1, 1, 1, 0); + return gen_rtx (SET, VOIDmode, assign, const1_rtx); + } + + /* The other case we handle is assignments into a constant-position + field. They look like (ior (and DEST C1) OTHER). If C1 represents + a mask that has all one bits except for a group of zero bits and + OTHER is known to have zeros where C1 has ones, this is such an + assignment. Compute the position and length from C1. Shift OTHER + to the appropriate position, force it to the required mode, and + make the extraction. Check for the AND in both operands. */ + + if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 0)) == AND + && GET_CODE (XEXP (XEXP (src, 0), 1)) == CONST_INT + && (rtx_equal_p (XEXP (XEXP (src, 0), 0), dest) + || rtx_equal_p (XEXP (XEXP (src, 0), 0), get_last_value (dest)) + || rtx_equal_p (get_last_value (XEXP (XEXP (src, 0), 1)), dest))) + c1 = INTVAL (XEXP (XEXP (src, 0), 1)), other = XEXP (src, 1); + else if (GET_CODE (src) == IOR && GET_CODE (XEXP (src, 1)) == AND + && GET_CODE (XEXP (XEXP (src, 1), 1)) == CONST_INT + && (rtx_equal_p (XEXP (XEXP (src, 1), 0), dest) + || rtx_equal_p (XEXP (XEXP (src, 1), 0), get_last_value (dest)) + || rtx_equal_p (get_last_value (XEXP (XEXP (src, 1), 0)), + dest))) + c1 = INTVAL (XEXP (XEXP (src, 1), 1)), other = XEXP (src, 0); + else + return x; + + pos = get_pos_from_mask (c1 ^ GET_MODE_MASK (GET_MODE (dest)), &len); + if (pos < 0 || pos + len > GET_MODE_BITSIZE (GET_MODE (dest)) + || (GET_MODE_BITSIZE (GET_MODE (other)) <= HOST_BITS_PER_WIDE_INT + && (c1 & nonzero_bits (other, GET_MODE (other))) != 0)) + return x; + + assign = make_extraction (VOIDmode, dest, pos, NULL_RTX, len, 1, 1, 0); + + /* The mode to use for the source is the mode of the assignment, or of + what is inside a possible STRICT_LOW_PART. */ + mode = (GET_CODE (assign) == STRICT_LOW_PART + ? GET_MODE (XEXP (assign, 0)) : GET_MODE (assign)); + + /* Shift OTHER right POS places and make it the source, restricting it + to the proper length and mode. */ + + src = force_to_mode (simplify_shift_const (NULL_RTX, LSHIFTRT, + GET_MODE (src), other, pos), + mode, + GET_MODE_BITSIZE (mode) >= HOST_BITS_PER_WIDE_INT + ? GET_MODE_MASK (mode) + : ((HOST_WIDE_INT) 1 << len) - 1, + dest, 0); + + return gen_rtx_combine (SET, VOIDmode, assign, src); +} + +/* See if X is of the form (+ (* a c) (* b c)) and convert to (* (+ a b) c) + if so. */ + +static rtx +apply_distributive_law (x) + rtx x; +{ + enum rtx_code code = GET_CODE (x); + rtx lhs, rhs, other; + rtx tem; + enum rtx_code inner_code; + + /* Distributivity is not true for floating point. + It can change the value. So don't do it. + -- rms and moshier@world.std.com. */ + if (FLOAT_MODE_P (GET_MODE (x))) + return x; + + /* The outer operation can only be one of the following: */ + if (code != IOR && code != AND && code != XOR + && code != PLUS && code != MINUS) + return x; + + lhs = XEXP (x, 0), rhs = XEXP (x, 1); + + /* If either operand is a primitive we can't do anything, so get out fast. */ + if (GET_RTX_CLASS (GET_CODE (lhs)) == 'o' + || GET_RTX_CLASS (GET_CODE (rhs)) == 'o') + return x; + + lhs = expand_compound_operation (lhs); + rhs = expand_compound_operation (rhs); + inner_code = GET_CODE (lhs); + if (inner_code != GET_CODE (rhs)) + return x; + + /* See if the inner and outer operations distribute. */ + switch (inner_code) + { + case LSHIFTRT: + case ASHIFTRT: + case AND: + case IOR: + /* These all distribute except over PLUS. */ + if (code == PLUS || code == MINUS) + return x; + break; + + case MULT: + if (code != PLUS && code != MINUS) + return x; + break; + + case ASHIFT: + /* This is also a multiply, so it distributes over everything. */ + break; + + case SUBREG: + /* Non-paradoxical SUBREGs distributes over all operations, provided + the inner modes and word numbers are the same, this is an extraction + of a low-order part, we don't convert an fp operation to int or + vice versa, and we would not be converting a single-word + operation into a multi-word operation. The latter test is not + required, but it prevents generating unneeded multi-word operations. + Some of the previous tests are redundant given the latter test, but + are retained because they are required for correctness. + + We produce the result slightly differently in this case. */ + + if (GET_MODE (SUBREG_REG (lhs)) != GET_MODE (SUBREG_REG (rhs)) + || SUBREG_WORD (lhs) != SUBREG_WORD (rhs) + || ! subreg_lowpart_p (lhs) + || (GET_MODE_CLASS (GET_MODE (lhs)) + != GET_MODE_CLASS (GET_MODE (SUBREG_REG (lhs)))) + || (GET_MODE_SIZE (GET_MODE (lhs)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs)))) + || GET_MODE_SIZE (GET_MODE (SUBREG_REG (lhs))) > UNITS_PER_WORD) + return x; + + tem = gen_binary (code, GET_MODE (SUBREG_REG (lhs)), + SUBREG_REG (lhs), SUBREG_REG (rhs)); + return gen_lowpart_for_combine (GET_MODE (x), tem); + + default: + return x; + } + + /* Set LHS and RHS to the inner operands (A and B in the example + above) and set OTHER to the common operand (C in the example). + These is only one way to do this unless the inner operation is + commutative. */ + if (GET_RTX_CLASS (inner_code) == 'c' + && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 0))) + other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 1); + else if (GET_RTX_CLASS (inner_code) == 'c' + && rtx_equal_p (XEXP (lhs, 0), XEXP (rhs, 1))) + other = XEXP (lhs, 0), lhs = XEXP (lhs, 1), rhs = XEXP (rhs, 0); + else if (GET_RTX_CLASS (inner_code) == 'c' + && rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 0))) + other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 1); + else if (rtx_equal_p (XEXP (lhs, 1), XEXP (rhs, 1))) + other = XEXP (lhs, 1), lhs = XEXP (lhs, 0), rhs = XEXP (rhs, 0); + else + return x; + + /* Form the new inner operation, seeing if it simplifies first. */ + tem = gen_binary (code, GET_MODE (x), lhs, rhs); + + /* There is one exception to the general way of distributing: + (a ^ b) | (a ^ c) -> (~a) & (b ^ c) */ + if (code == XOR && inner_code == IOR) + { + inner_code = AND; + other = gen_unary (NOT, GET_MODE (x), GET_MODE (x), other); + } + + /* We may be able to continuing distributing the result, so call + ourselves recursively on the inner operation before forming the + outer operation, which we return. */ + return gen_binary (inner_code, GET_MODE (x), + apply_distributive_law (tem), other); +} + +/* We have X, a logical `and' of VAROP with the constant CONSTOP, to be done + in MODE. + + Return an equivalent form, if different from X. Otherwise, return X. If + X is zero, we are to always construct the equivalent form. */ + +static rtx +simplify_and_const_int (x, mode, varop, constop) + rtx x; + enum machine_mode mode; + rtx varop; + unsigned HOST_WIDE_INT constop; +{ + unsigned HOST_WIDE_INT nonzero; + int width = GET_MODE_BITSIZE (mode); + int i; + + /* Simplify VAROP knowing that we will be only looking at some of the + bits in it. */ + varop = force_to_mode (varop, mode, constop, NULL_RTX, 0); + + /* If VAROP is a CLOBBER, we will fail so return it; if it is a + CONST_INT, we are done. */ + if (GET_CODE (varop) == CLOBBER || GET_CODE (varop) == CONST_INT) + return varop; + + /* See what bits may be nonzero in VAROP. Unlike the general case of + a call to nonzero_bits, here we don't care about bits outside + MODE. */ + + nonzero = nonzero_bits (varop, mode) & GET_MODE_MASK (mode); + + /* If this would be an entire word for the target, but is not for + the host, then sign-extend on the host so that the number will look + the same way on the host that it would on the target. + + For example, when building a 64 bit alpha hosted 32 bit sparc + targeted compiler, then we want the 32 bit unsigned value -1 to be + represented as a 64 bit value -1, and not as 0x00000000ffffffff. + The later confuses the sparc backend. */ + + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width + && (nonzero & ((HOST_WIDE_INT) 1 << (width - 1)))) + nonzero |= ((HOST_WIDE_INT) (-1) << width); + + /* Turn off all bits in the constant that are known to already be zero. + Thus, if the AND isn't needed at all, we will have CONSTOP == NONZERO_BITS + which is tested below. */ + + constop &= nonzero; + + /* If we don't have any bits left, return zero. */ + if (constop == 0) + return const0_rtx; + + /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is + a power of two, we can replace this with a ASHIFT. */ + if (GET_CODE (varop) == NEG && nonzero_bits (XEXP (varop, 0), mode) == 1 + && (i = exact_log2 (constop)) >= 0) + return simplify_shift_const (NULL_RTX, ASHIFT, mode, XEXP (varop, 0), i); + + /* If VAROP is an IOR or XOR, apply the AND to both branches of the IOR + or XOR, then try to apply the distributive law. This may eliminate + operations if either branch can be simplified because of the AND. + It may also make some cases more complex, but those cases probably + won't match a pattern either with or without this. */ + + if (GET_CODE (varop) == IOR || GET_CODE (varop) == XOR) + return + gen_lowpart_for_combine + (mode, + apply_distributive_law + (gen_binary (GET_CODE (varop), GET_MODE (varop), + simplify_and_const_int (NULL_RTX, GET_MODE (varop), + XEXP (varop, 0), constop), + simplify_and_const_int (NULL_RTX, GET_MODE (varop), + XEXP (varop, 1), constop)))); + + /* Get VAROP in MODE. Try to get a SUBREG if not. Don't make a new SUBREG + if we already had one (just check for the simplest cases). */ + if (x && GET_CODE (XEXP (x, 0)) == SUBREG + && GET_MODE (XEXP (x, 0)) == mode + && SUBREG_REG (XEXP (x, 0)) == varop) + varop = XEXP (x, 0); + else + varop = gen_lowpart_for_combine (mode, varop); + + /* If we can't make the SUBREG, try to return what we were given. */ + if (GET_CODE (varop) == CLOBBER) + return x ? x : varop; + + /* If we are only masking insignificant bits, return VAROP. */ + if (constop == nonzero) + x = varop; + + /* Otherwise, return an AND. See how much, if any, of X we can use. */ + else if (x == 0 || GET_CODE (x) != AND || GET_MODE (x) != mode) + x = gen_binary (AND, mode, varop, GEN_INT (constop)); + + else + { + if (GET_CODE (XEXP (x, 1)) != CONST_INT + || INTVAL (XEXP (x, 1)) != constop) + SUBST (XEXP (x, 1), GEN_INT (constop)); + + SUBST (XEXP (x, 0), varop); + } + + return x; +} + +/* Given an expression, X, compute which bits in X can be non-zero. + We don't care about bits outside of those defined in MODE. + + For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is + a shift, AND, or zero_extract, we can do better. */ + +static unsigned HOST_WIDE_INT +nonzero_bits (x, mode) + rtx x; + enum machine_mode mode; +{ + unsigned HOST_WIDE_INT nonzero = GET_MODE_MASK (mode); + unsigned HOST_WIDE_INT inner_nz; + enum rtx_code code; + int mode_width = GET_MODE_BITSIZE (mode); + rtx tem; + + /* For floating-point values, assume all bits are needed. */ + if (FLOAT_MODE_P (GET_MODE (x)) || FLOAT_MODE_P (mode)) + return nonzero; + + /* If X is wider than MODE, use its mode instead. */ + if (GET_MODE_BITSIZE (GET_MODE (x)) > mode_width) + { + mode = GET_MODE (x); + nonzero = GET_MODE_MASK (mode); + mode_width = GET_MODE_BITSIZE (mode); + } + + if (mode_width > HOST_BITS_PER_WIDE_INT) + /* Our only callers in this case look for single bit values. So + just return the mode mask. Those tests will then be false. */ + return nonzero; + +#ifndef WORD_REGISTER_OPERATIONS + /* If MODE is wider than X, but both are a single word for both the host + and target machines, we can compute this from which bits of the + object might be nonzero in its own mode, taking into account the fact + that on many CISC machines, accessing an object in a wider mode + causes the high-order bits to become undefined. So they are + not known to be zero. */ + + if (GET_MODE (x) != VOIDmode && GET_MODE (x) != mode + && GET_MODE_BITSIZE (GET_MODE (x)) <= BITS_PER_WORD + && GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT + && GET_MODE_BITSIZE (mode) > GET_MODE_BITSIZE (GET_MODE (x))) + { + nonzero &= nonzero_bits (x, GET_MODE (x)); + nonzero |= GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x)); + return nonzero; + } +#endif + + code = GET_CODE (x); + switch (code) + { + case REG: +#ifdef POINTERS_EXTEND_UNSIGNED + /* If pointers extend unsigned and this is a pointer in Pmode, say that + all the bits above ptr_mode are known to be zero. */ + if (POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode + && REGNO_POINTER_FLAG (REGNO (x))) + nonzero &= GET_MODE_MASK (ptr_mode); +#endif + +#ifdef STACK_BOUNDARY + /* If this is the stack pointer, we may know something about its + alignment. If PUSH_ROUNDING is defined, it is possible for the + stack to be momentarily aligned only to that amount, so we pick + the least alignment. */ + + if (x == stack_pointer_rtx) + { + int sp_alignment = STACK_BOUNDARY / BITS_PER_UNIT; + +#ifdef PUSH_ROUNDING + sp_alignment = MIN (PUSH_ROUNDING (1), sp_alignment); +#endif + + /* We must return here, otherwise we may get a worse result from + one of the choices below. There is nothing useful below as + far as the stack pointer is concerned. */ + return nonzero &= ~ (sp_alignment - 1); + } +#endif + + /* If X is a register whose nonzero bits value is current, use it. + Otherwise, if X is a register whose value we can find, use that + value. Otherwise, use the previously-computed global nonzero bits + for this register. */ + + if (reg_last_set_value[REGNO (x)] != 0 + && reg_last_set_mode[REGNO (x)] == mode + && (reg_n_sets[REGNO (x)] == 1 + || reg_last_set_label[REGNO (x)] == label_tick) + && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid) + return reg_last_set_nonzero_bits[REGNO (x)]; + + tem = get_last_value (x); + + if (tem) + { +#ifdef SHORT_IMMEDIATES_SIGN_EXTEND + /* If X is narrower than MODE and TEM is a non-negative + constant that would appear negative in the mode of X, + sign-extend it for use in reg_nonzero_bits because some + machines (maybe most) will actually do the sign-extension + and this is the conservative approach. + + ??? For 2.5, try to tighten up the MD files in this regard + instead of this kludge. */ + + if (GET_MODE_BITSIZE (GET_MODE (x)) < mode_width + && GET_CODE (tem) == CONST_INT + && INTVAL (tem) > 0 + && 0 != (INTVAL (tem) + & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (x)) - 1)))) + tem = GEN_INT (INTVAL (tem) + | ((HOST_WIDE_INT) (-1) + << GET_MODE_BITSIZE (GET_MODE (x)))); +#endif + return nonzero_bits (tem, mode); + } + else if (nonzero_sign_valid && reg_nonzero_bits[REGNO (x)]) + return reg_nonzero_bits[REGNO (x)] & nonzero; + else + return nonzero; + + case CONST_INT: +#ifdef SHORT_IMMEDIATES_SIGN_EXTEND + /* If X is negative in MODE, sign-extend the value. */ + if (INTVAL (x) > 0 && mode_width < BITS_PER_WORD + && 0 != (INTVAL (x) & ((HOST_WIDE_INT) 1 << (mode_width - 1)))) + return (INTVAL (x) | ((HOST_WIDE_INT) (-1) << mode_width)); +#endif + + return INTVAL (x); + + case MEM: +#ifdef LOAD_EXTEND_OP + /* In many, if not most, RISC machines, reading a byte from memory + zeros the rest of the register. Noticing that fact saves a lot + of extra zero-extends. */ + if (LOAD_EXTEND_OP (GET_MODE (x)) == ZERO_EXTEND) + nonzero &= GET_MODE_MASK (GET_MODE (x)); +#endif + break; + + case EQ: case NE: + case GT: case GTU: + case LT: case LTU: + case GE: case GEU: + case LE: case LEU: + + /* If this produces an integer result, we know which bits are set. + Code here used to clear bits outside the mode of X, but that is + now done above. */ + + if (GET_MODE_CLASS (mode) == MODE_INT + && mode_width <= HOST_BITS_PER_WIDE_INT) + nonzero = STORE_FLAG_VALUE; + break; + + case NEG: + if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x)) + == GET_MODE_BITSIZE (GET_MODE (x))) + nonzero = 1; + + if (GET_MODE_SIZE (GET_MODE (x)) < mode_width) + nonzero |= (GET_MODE_MASK (mode) & ~ GET_MODE_MASK (GET_MODE (x))); + break; + + case ABS: + if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x)) + == GET_MODE_BITSIZE (GET_MODE (x))) + nonzero = 1; + break; + + case TRUNCATE: + nonzero &= (nonzero_bits (XEXP (x, 0), mode) & GET_MODE_MASK (mode)); + break; + + case ZERO_EXTEND: + nonzero &= nonzero_bits (XEXP (x, 0), mode); + if (GET_MODE (XEXP (x, 0)) != VOIDmode) + nonzero &= GET_MODE_MASK (GET_MODE (XEXP (x, 0))); + break; + + case SIGN_EXTEND: + /* If the sign bit is known clear, this is the same as ZERO_EXTEND. + Otherwise, show all the bits in the outer mode but not the inner + may be non-zero. */ + inner_nz = nonzero_bits (XEXP (x, 0), mode); + if (GET_MODE (XEXP (x, 0)) != VOIDmode) + { + inner_nz &= GET_MODE_MASK (GET_MODE (XEXP (x, 0))); + if (inner_nz & + (((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) - 1)))) + inner_nz |= (GET_MODE_MASK (mode) + & ~ GET_MODE_MASK (GET_MODE (XEXP (x, 0)))); + } + + nonzero &= inner_nz; + break; + + case AND: + nonzero &= (nonzero_bits (XEXP (x, 0), mode) + & nonzero_bits (XEXP (x, 1), mode)); + break; + + case XOR: case IOR: + case UMIN: case UMAX: case SMIN: case SMAX: + nonzero &= (nonzero_bits (XEXP (x, 0), mode) + | nonzero_bits (XEXP (x, 1), mode)); + break; + + case PLUS: case MINUS: + case MULT: + case DIV: case UDIV: + case MOD: case UMOD: + /* We can apply the rules of arithmetic to compute the number of + high- and low-order zero bits of these operations. We start by + computing the width (position of the highest-order non-zero bit) + and the number of low-order zero bits for each value. */ + { + unsigned HOST_WIDE_INT nz0 = nonzero_bits (XEXP (x, 0), mode); + unsigned HOST_WIDE_INT nz1 = nonzero_bits (XEXP (x, 1), mode); + int width0 = floor_log2 (nz0) + 1; + int width1 = floor_log2 (nz1) + 1; + int low0 = floor_log2 (nz0 & -nz0); + int low1 = floor_log2 (nz1 & -nz1); + HOST_WIDE_INT op0_maybe_minusp + = (nz0 & ((HOST_WIDE_INT) 1 << (mode_width - 1))); + HOST_WIDE_INT op1_maybe_minusp + = (nz1 & ((HOST_WIDE_INT) 1 << (mode_width - 1))); + int result_width = mode_width; + int result_low = 0; + + switch (code) + { + case PLUS: + result_width = MAX (width0, width1) + 1; + result_low = MIN (low0, low1); + break; + case MINUS: + result_low = MIN (low0, low1); + break; + case MULT: + result_width = width0 + width1; + result_low = low0 + low1; + break; + case DIV: + if (! op0_maybe_minusp && ! op1_maybe_minusp) + result_width = width0; + break; + case UDIV: + result_width = width0; + break; + case MOD: + if (! op0_maybe_minusp && ! op1_maybe_minusp) + result_width = MIN (width0, width1); + result_low = MIN (low0, low1); + break; + case UMOD: + result_width = MIN (width0, width1); + result_low = MIN (low0, low1); + break; + } + + if (result_width < mode_width) + nonzero &= ((HOST_WIDE_INT) 1 << result_width) - 1; + + if (result_low > 0) + nonzero &= ~ (((HOST_WIDE_INT) 1 << result_low) - 1); + } + break; + + case ZERO_EXTRACT: + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT) + nonzero &= ((HOST_WIDE_INT) 1 << INTVAL (XEXP (x, 1))) - 1; + break; + + case SUBREG: + /* If this is a SUBREG formed for a promoted variable that has + been zero-extended, we know that at least the high-order bits + are zero, though others might be too. */ + + if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x)) + nonzero = (GET_MODE_MASK (GET_MODE (x)) + & nonzero_bits (SUBREG_REG (x), GET_MODE (x))); + + /* If the inner mode is a single word for both the host and target + machines, we can compute this from which bits of the inner + object might be nonzero. */ + if (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) <= BITS_PER_WORD + && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) + <= HOST_BITS_PER_WIDE_INT)) + { + nonzero &= nonzero_bits (SUBREG_REG (x), mode); + +#ifndef WORD_REGISTER_OPERATIONS + /* On many CISC machines, accessing an object in a wider mode + causes the high-order bits to become undefined. So they are + not known to be zero. */ + if (GET_MODE_SIZE (GET_MODE (x)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) + nonzero |= (GET_MODE_MASK (GET_MODE (x)) + & ~ GET_MODE_MASK (GET_MODE (SUBREG_REG (x)))); +#endif + } + break; + + case ASHIFTRT: + case LSHIFTRT: + case ASHIFT: + case ROTATE: + /* The nonzero bits are in two classes: any bits within MODE + that aren't in GET_MODE (x) are always significant. The rest of the + nonzero bits are those that are significant in the operand of + the shift when shifted the appropriate number of bits. This + shows that high-order bits are cleared by the right shift and + low-order bits by left shifts. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0 + && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT) + { + enum machine_mode inner_mode = GET_MODE (x); + int width = GET_MODE_BITSIZE (inner_mode); + int count = INTVAL (XEXP (x, 1)); + unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (inner_mode); + unsigned HOST_WIDE_INT op_nonzero = nonzero_bits (XEXP (x, 0), mode); + unsigned HOST_WIDE_INT inner = op_nonzero & mode_mask; + unsigned HOST_WIDE_INT outer = 0; + + if (mode_width > width) + outer = (op_nonzero & nonzero & ~ mode_mask); + + if (code == LSHIFTRT) + inner >>= count; + else if (code == ASHIFTRT) + { + inner >>= count; + + /* If the sign bit may have been nonzero before the shift, we + need to mark all the places it could have been copied to + by the shift as possibly nonzero. */ + if (inner & ((HOST_WIDE_INT) 1 << (width - 1 - count))) + inner |= (((HOST_WIDE_INT) 1 << count) - 1) << (width - count); + } + else if (code == ASHIFT) + inner <<= count; + else + inner = ((inner << (count % width) + | (inner >> (width - (count % width)))) & mode_mask); + + nonzero &= (outer | inner); + } + break; + + case FFS: + /* This is at most the number of bits in the mode. */ + nonzero = ((HOST_WIDE_INT) 1 << (floor_log2 (mode_width) + 1)) - 1; + break; + + case IF_THEN_ELSE: + nonzero &= (nonzero_bits (XEXP (x, 1), mode) + | nonzero_bits (XEXP (x, 2), mode)); + break; + } + + return nonzero; +} + +/* Return the number of bits at the high-order end of X that are known to + be equal to the sign bit. X will be used in mode MODE; if MODE is + VOIDmode, X will be used in its own mode. The returned value will always + be between 1 and the number of bits in MODE. */ + +static int +num_sign_bit_copies (x, mode) + rtx x; + enum machine_mode mode; +{ + enum rtx_code code = GET_CODE (x); + int bitwidth; + int num0, num1, result; + unsigned HOST_WIDE_INT nonzero; + rtx tem; + + /* If we weren't given a mode, use the mode of X. If the mode is still + VOIDmode, we don't know anything. Likewise if one of the modes is + floating-point. */ + + if (mode == VOIDmode) + mode = GET_MODE (x); + + if (mode == VOIDmode || FLOAT_MODE_P (mode) || FLOAT_MODE_P (GET_MODE (x))) + return 1; + + bitwidth = GET_MODE_BITSIZE (mode); + + /* For a smaller object, just ignore the high bits. */ + if (bitwidth < GET_MODE_BITSIZE (GET_MODE (x))) + return MAX (1, (num_sign_bit_copies (x, GET_MODE (x)) + - (GET_MODE_BITSIZE (GET_MODE (x)) - bitwidth))); + +#ifndef WORD_REGISTER_OPERATIONS + /* If this machine does not do all register operations on the entire + register and MODE is wider than the mode of X, we can say nothing + at all about the high-order bits. */ + if (GET_MODE (x) != VOIDmode && bitwidth > GET_MODE_BITSIZE (GET_MODE (x))) + return 1; +#endif + + switch (code) + { + case REG: + +#ifdef POINTERS_EXTEND_UNSIGNED + /* If pointers extend signed and this is a pointer in Pmode, say that + all the bits above ptr_mode are known to be sign bit copies. */ + if (! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode && mode == Pmode + && REGNO_POINTER_FLAG (REGNO (x))) + return GET_MODE_BITSIZE (Pmode) - GET_MODE_BITSIZE (ptr_mode) + 1; +#endif + + if (reg_last_set_value[REGNO (x)] != 0 + && reg_last_set_mode[REGNO (x)] == mode + && (reg_n_sets[REGNO (x)] == 1 + || reg_last_set_label[REGNO (x)] == label_tick) + && INSN_CUID (reg_last_set[REGNO (x)]) < subst_low_cuid) + return reg_last_set_sign_bit_copies[REGNO (x)]; + + tem = get_last_value (x); + if (tem != 0) + return num_sign_bit_copies (tem, mode); + + if (nonzero_sign_valid && reg_sign_bit_copies[REGNO (x)] != 0) + return reg_sign_bit_copies[REGNO (x)]; + break; + + case MEM: +#ifdef LOAD_EXTEND_OP + /* Some RISC machines sign-extend all loads of smaller than a word. */ + if (LOAD_EXTEND_OP (GET_MODE (x)) == SIGN_EXTEND) + return MAX (1, bitwidth - GET_MODE_BITSIZE (GET_MODE (x)) + 1); +#endif + break; + + case CONST_INT: + /* If the constant is negative, take its 1's complement and remask. + Then see how many zero bits we have. */ + nonzero = INTVAL (x) & GET_MODE_MASK (mode); + if (bitwidth <= HOST_BITS_PER_WIDE_INT + && (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0) + nonzero = (~ nonzero) & GET_MODE_MASK (mode); + + return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1); + + case SUBREG: + /* If this is a SUBREG for a promoted object that is sign-extended + and we are looking at it in a wider mode, we know that at least the + high-order bits are known to be sign bit copies. */ + + if (SUBREG_PROMOTED_VAR_P (x) && ! SUBREG_PROMOTED_UNSIGNED_P (x)) + return MAX (bitwidth - GET_MODE_BITSIZE (GET_MODE (x)) + 1, + num_sign_bit_copies (SUBREG_REG (x), mode)); + + /* For a smaller object, just ignore the high bits. */ + if (bitwidth <= GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))) + { + num0 = num_sign_bit_copies (SUBREG_REG (x), VOIDmode); + return MAX (1, (num0 + - (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) + - bitwidth))); + } + +#ifdef WORD_REGISTER_OPERATIONS +#ifdef LOAD_EXTEND_OP + /* For paradoxical SUBREGs on machines where all register operations + affect the entire register, just look inside. Note that we are + passing MODE to the recursive call, so the number of sign bit copies + will remain relative to that mode, not the inner mode. */ + + /* This works only if loads sign extend. Otherwise, if we get a + reload for the inner part, it may be loaded from the stack, and + then we lose all sign bit copies that existed before the store + to the stack. */ + + if ((GET_MODE_SIZE (GET_MODE (x)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) + && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND) + return num_sign_bit_copies (SUBREG_REG (x), mode); +#endif +#endif + break; + + case SIGN_EXTRACT: + if (GET_CODE (XEXP (x, 1)) == CONST_INT) + return MAX (1, bitwidth - INTVAL (XEXP (x, 1))); + break; + + case SIGN_EXTEND: + return (bitwidth - GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) + + num_sign_bit_copies (XEXP (x, 0), VOIDmode)); + + case TRUNCATE: + /* For a smaller object, just ignore the high bits. */ + num0 = num_sign_bit_copies (XEXP (x, 0), VOIDmode); + return MAX (1, (num0 - (GET_MODE_BITSIZE (GET_MODE (XEXP (x, 0))) + - bitwidth))); + + case NOT: + return num_sign_bit_copies (XEXP (x, 0), mode); + + case ROTATE: case ROTATERT: + /* If we are rotating left by a number of bits less than the number + of sign bit copies, we can just subtract that amount from the + number. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) >= 0 && INTVAL (XEXP (x, 1)) < bitwidth) + { + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1)) + : bitwidth - INTVAL (XEXP (x, 1)))); + } + break; + + case NEG: + /* In general, this subtracts one sign bit copy. But if the value + is known to be positive, the number of sign bit copies is the + same as that of the input. Finally, if the input has just one bit + that might be nonzero, all the bits are copies of the sign bit. */ + nonzero = nonzero_bits (XEXP (x, 0), mode); + if (nonzero == 1) + return bitwidth; + + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + if (num0 > 1 + && bitwidth <= HOST_BITS_PER_WIDE_INT + && (((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero)) + num0--; + + return num0; + + case IOR: case AND: case XOR: + case SMIN: case SMAX: case UMIN: case UMAX: + /* Logical operations will preserve the number of sign-bit copies. + MIN and MAX operations always return one of the operands. */ + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + num1 = num_sign_bit_copies (XEXP (x, 1), mode); + return MIN (num0, num1); + + case PLUS: case MINUS: + /* For addition and subtraction, we can have a 1-bit carry. However, + if we are subtracting 1 from a positive number, there will not + be such a carry. Furthermore, if the positive number is known to + be 0 or 1, we know the result is either -1 or 0. */ + + if (code == PLUS && XEXP (x, 1) == constm1_rtx + && bitwidth <= HOST_BITS_PER_WIDE_INT) + { + nonzero = nonzero_bits (XEXP (x, 0), mode); + if ((((HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero) == 0) + return (nonzero == 1 || nonzero == 0 ? bitwidth + : bitwidth - floor_log2 (nonzero) - 1); + } + + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + num1 = num_sign_bit_copies (XEXP (x, 1), mode); + return MAX (1, MIN (num0, num1) - 1); + + case MULT: + /* The number of bits of the product is the sum of the number of + bits of both terms. However, unless one of the terms if known + to be positive, we must allow for an additional bit since negating + a negative number can remove one sign bit copy. */ + + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + num1 = num_sign_bit_copies (XEXP (x, 1), mode); + + result = bitwidth - (bitwidth - num0) - (bitwidth - num1); + if (result > 0 + && bitwidth <= HOST_BITS_PER_WIDE_INT + && ((nonzero_bits (XEXP (x, 0), mode) + & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0) + && (nonzero_bits (XEXP (x, 1), mode) + & ((HOST_WIDE_INT) 1 << (bitwidth - 1)) != 0)) + result--; + + return MAX (1, result); + + case UDIV: + /* The result must be <= the first operand. */ + return num_sign_bit_copies (XEXP (x, 0), mode); + + case UMOD: + /* The result must be <= the scond operand. */ + return num_sign_bit_copies (XEXP (x, 1), mode); + + case DIV: + /* Similar to unsigned division, except that we have to worry about + the case where the divisor is negative, in which case we have + to add 1. */ + result = num_sign_bit_copies (XEXP (x, 0), mode); + if (result > 1 + && bitwidth <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (x, 1), mode) + & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0) + result --; + + return result; + + case MOD: + result = num_sign_bit_copies (XEXP (x, 1), mode); + if (result > 1 + && bitwidth <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (x, 1), mode) + & ((HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0) + result --; + + return result; + + case ASHIFTRT: + /* Shifts by a constant add to the number of bits equal to the + sign bit. */ + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) > 0) + num0 = MIN (bitwidth, num0 + INTVAL (XEXP (x, 1))); + + return num0; + + case ASHIFT: + /* Left shifts destroy copies. */ + if (GET_CODE (XEXP (x, 1)) != CONST_INT + || INTVAL (XEXP (x, 1)) < 0 + || INTVAL (XEXP (x, 1)) >= bitwidth) + return 1; + + num0 = num_sign_bit_copies (XEXP (x, 0), mode); + return MAX (1, num0 - INTVAL (XEXP (x, 1))); + + case IF_THEN_ELSE: + num0 = num_sign_bit_copies (XEXP (x, 1), mode); + num1 = num_sign_bit_copies (XEXP (x, 2), mode); + return MIN (num0, num1); + +#if STORE_FLAG_VALUE == -1 + case EQ: case NE: case GE: case GT: case LE: case LT: + case GEU: case GTU: case LEU: case LTU: + return bitwidth; +#endif + } + + /* If we haven't been able to figure it out by one of the above rules, + see if some of the high-order bits are known to be zero. If so, + count those bits and return one less than that amount. If we can't + safely compute the mask for this mode, always return BITWIDTH. */ + + if (bitwidth > HOST_BITS_PER_WIDE_INT) + return 1; + + nonzero = nonzero_bits (x, mode); + return (nonzero & ((HOST_WIDE_INT) 1 << (bitwidth - 1)) + ? 1 : bitwidth - floor_log2 (nonzero) - 1); +} + +/* Return the number of "extended" bits there are in X, when interpreted + as a quantity in MODE whose signedness is indicated by UNSIGNEDP. For + unsigned quantities, this is the number of high-order zero bits. + For signed quantities, this is the number of copies of the sign bit + minus 1. In both case, this function returns the number of "spare" + bits. For example, if two quantities for which this function returns + at least 1 are added, the addition is known not to overflow. + + This function will always return 0 unless called during combine, which + implies that it must be called from a define_split. */ + +int +extended_count (x, mode, unsignedp) + rtx x; + enum machine_mode mode; + int unsignedp; +{ + if (nonzero_sign_valid == 0) + return 0; + + return (unsignedp + ? (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT + && (GET_MODE_BITSIZE (mode) - 1 + - floor_log2 (nonzero_bits (x, mode)))) + : num_sign_bit_copies (x, mode) - 1); +} + +/* This function is called from `simplify_shift_const' to merge two + outer operations. Specifically, we have already found that we need + to perform operation *POP0 with constant *PCONST0 at the outermost + position. We would now like to also perform OP1 with constant CONST1 + (with *POP0 being done last). + + Return 1 if we can do the operation and update *POP0 and *PCONST0 with + the resulting operation. *PCOMP_P is set to 1 if we would need to + complement the innermost operand, otherwise it is unchanged. + + MODE is the mode in which the operation will be done. No bits outside + the width of this mode matter. It is assumed that the width of this mode + is smaller than or equal to HOST_BITS_PER_WIDE_INT. + + If *POP0 or OP1 are NIL, it means no operation is required. Only NEG, PLUS, + IOR, XOR, and AND are supported. We may set *POP0 to SET if the proper + result is simply *PCONST0. + + If the resulting operation cannot be expressed as one operation, we + return 0 and do not change *POP0, *PCONST0, and *PCOMP_P. */ + +static int +merge_outer_ops (pop0, pconst0, op1, const1, mode, pcomp_p) + enum rtx_code *pop0; + HOST_WIDE_INT *pconst0; + enum rtx_code op1; + HOST_WIDE_INT const1; + enum machine_mode mode; + int *pcomp_p; +{ + enum rtx_code op0 = *pop0; + HOST_WIDE_INT const0 = *pconst0; + int width = GET_MODE_BITSIZE (mode); + + const0 &= GET_MODE_MASK (mode); + const1 &= GET_MODE_MASK (mode); + + /* If OP0 is an AND, clear unimportant bits in CONST1. */ + if (op0 == AND) + const1 &= const0; + + /* If OP0 or OP1 is NIL, this is easy. Similarly if they are the same or + if OP0 is SET. */ + + if (op1 == NIL || op0 == SET) + return 1; + + else if (op0 == NIL) + op0 = op1, const0 = const1; + + else if (op0 == op1) + { + switch (op0) + { + case AND: + const0 &= const1; + break; + case IOR: + const0 |= const1; + break; + case XOR: + const0 ^= const1; + break; + case PLUS: + const0 += const1; + break; + case NEG: + op0 = NIL; + break; + } + } + + /* Otherwise, if either is a PLUS or NEG, we can't do anything. */ + else if (op0 == PLUS || op1 == PLUS || op0 == NEG || op1 == NEG) + return 0; + + /* If the two constants aren't the same, we can't do anything. The + remaining six cases can all be done. */ + else if (const0 != const1) + return 0; + + else + switch (op0) + { + case IOR: + if (op1 == AND) + /* (a & b) | b == b */ + op0 = SET; + else /* op1 == XOR */ + /* (a ^ b) | b == a | b */ + ; + break; + + case XOR: + if (op1 == AND) + /* (a & b) ^ b == (~a) & b */ + op0 = AND, *pcomp_p = 1; + else /* op1 == IOR */ + /* (a | b) ^ b == a & ~b */ + op0 = AND, *pconst0 = ~ const0; + break; + + case AND: + if (op1 == IOR) + /* (a | b) & b == b */ + op0 = SET; + else /* op1 == XOR */ + /* (a ^ b) & b) == (~a) & b */ + *pcomp_p = 1; + break; + } + + /* Check for NO-OP cases. */ + const0 &= GET_MODE_MASK (mode); + if (const0 == 0 + && (op0 == IOR || op0 == XOR || op0 == PLUS)) + op0 = NIL; + else if (const0 == 0 && op0 == AND) + op0 = SET; + else if (const0 == GET_MODE_MASK (mode) && op0 == AND) + op0 = NIL; + + /* If this would be an entire word for the target, but is not for + the host, then sign-extend on the host so that the number will look + the same way on the host that it would on the target. + + For example, when building a 64 bit alpha hosted 32 bit sparc + targeted compiler, then we want the 32 bit unsigned value -1 to be + represented as a 64 bit value -1, and not as 0x00000000ffffffff. + The later confuses the sparc backend. */ + + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width + && (const0 & ((HOST_WIDE_INT) 1 << (width - 1)))) + const0 |= ((HOST_WIDE_INT) (-1) << width); + + *pop0 = op0; + *pconst0 = const0; + + return 1; +} + +/* Simplify a shift of VAROP by COUNT bits. CODE says what kind of shift. + The result of the shift is RESULT_MODE. X, if non-zero, is an expression + that we started with. + + The shift is normally computed in the widest mode we find in VAROP, as + long as it isn't a different number of words than RESULT_MODE. Exceptions + are ASHIFTRT and ROTATE, which are always done in their original mode, */ + +static rtx +simplify_shift_const (x, code, result_mode, varop, count) + rtx x; + enum rtx_code code; + enum machine_mode result_mode; + rtx varop; + int count; +{ + enum rtx_code orig_code = code; + int orig_count = count; + enum machine_mode mode = result_mode; + enum machine_mode shift_mode, tmode; + int mode_words + = (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD; + /* We form (outer_op (code varop count) (outer_const)). */ + enum rtx_code outer_op = NIL; + HOST_WIDE_INT outer_const = 0; + rtx const_rtx; + int complement_p = 0; + rtx new; + + /* If we were given an invalid count, don't do anything except exactly + what was requested. */ + + if (count < 0 || count > GET_MODE_BITSIZE (mode)) + { + if (x) + return x; + + return gen_rtx (code, mode, varop, GEN_INT (count)); + } + + /* Unless one of the branches of the `if' in this loop does a `continue', + we will `break' the loop after the `if'. */ + + while (count != 0) + { + /* If we have an operand of (clobber (const_int 0)), just return that + value. */ + if (GET_CODE (varop) == CLOBBER) + return varop; + + /* If we discovered we had to complement VAROP, leave. Making a NOT + here would cause an infinite loop. */ + if (complement_p) + break; + + /* Convert ROTATERT to ROTATE. */ + if (code == ROTATERT) + code = ROTATE, count = GET_MODE_BITSIZE (result_mode) - count; + + /* We need to determine what mode we will do the shift in. If the + shift is a right shift or a ROTATE, we must always do it in the mode + it was originally done in. Otherwise, we can do it in MODE, the + widest mode encountered. */ + shift_mode + = (code == ASHIFTRT || code == LSHIFTRT || code == ROTATE + ? result_mode : mode); + + /* Handle cases where the count is greater than the size of the mode + minus 1. For ASHIFT, use the size minus one as the count (this can + occur when simplifying (lshiftrt (ashiftrt ..))). For rotates, + take the count modulo the size. For other shifts, the result is + zero. + + Since these shifts are being produced by the compiler by combining + multiple operations, each of which are defined, we know what the + result is supposed to be. */ + + if (count > GET_MODE_BITSIZE (shift_mode) - 1) + { + if (code == ASHIFTRT) + count = GET_MODE_BITSIZE (shift_mode) - 1; + else if (code == ROTATE || code == ROTATERT) + count %= GET_MODE_BITSIZE (shift_mode); + else + { + /* We can't simply return zero because there may be an + outer op. */ + varop = const0_rtx; + count = 0; + break; + } + } + + /* Negative counts are invalid and should not have been made (a + programmer-specified negative count should have been handled + above). */ + else if (count < 0) + abort (); + + /* An arithmetic right shift of a quantity known to be -1 or 0 + is a no-op. */ + if (code == ASHIFTRT + && (num_sign_bit_copies (varop, shift_mode) + == GET_MODE_BITSIZE (shift_mode))) + { + count = 0; + break; + } + + /* If we are doing an arithmetic right shift and discarding all but + the sign bit copies, this is equivalent to doing a shift by the + bitsize minus one. Convert it into that shift because it will often + allow other simplifications. */ + + if (code == ASHIFTRT + && (count + num_sign_bit_copies (varop, shift_mode) + >= GET_MODE_BITSIZE (shift_mode))) + count = GET_MODE_BITSIZE (shift_mode) - 1; + + /* We simplify the tests below and elsewhere by converting + ASHIFTRT to LSHIFTRT if we know the sign bit is clear. + `make_compound_operation' will convert it to a ASHIFTRT for + those machines (such as Vax) that don't have a LSHIFTRT. */ + if (GET_MODE_BITSIZE (shift_mode) <= HOST_BITS_PER_WIDE_INT + && code == ASHIFTRT + && ((nonzero_bits (varop, shift_mode) + & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (shift_mode) - 1))) + == 0)) + code = LSHIFTRT; + + switch (GET_CODE (varop)) + { + case SIGN_EXTEND: + case ZERO_EXTEND: + case SIGN_EXTRACT: + case ZERO_EXTRACT: + new = expand_compound_operation (varop); + if (new != varop) + { + varop = new; + continue; + } + break; + + case MEM: + /* If we have (xshiftrt (mem ...) C) and C is MODE_WIDTH + minus the width of a smaller mode, we can do this with a + SIGN_EXTEND or ZERO_EXTEND from the narrower memory location. */ + if ((code == ASHIFTRT || code == LSHIFTRT) + && ! mode_dependent_address_p (XEXP (varop, 0)) + && ! MEM_VOLATILE_P (varop) + && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count, + MODE_INT, 1)) != BLKmode) + { + if (BYTES_BIG_ENDIAN) + new = gen_rtx (MEM, tmode, XEXP (varop, 0)); + else + new = gen_rtx (MEM, tmode, + plus_constant (XEXP (varop, 0), + count / BITS_PER_UNIT)); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (varop); + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (varop); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (varop); + varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND + : ZERO_EXTEND, mode, new); + count = 0; + continue; + } + break; + + case USE: + /* Similar to the case above, except that we can only do this if + the resulting mode is the same as that of the underlying + MEM and adjust the address depending on the *bits* endianness + because of the way that bit-field extract insns are defined. */ + if ((code == ASHIFTRT || code == LSHIFTRT) + && (tmode = mode_for_size (GET_MODE_BITSIZE (mode) - count, + MODE_INT, 1)) != BLKmode + && tmode == GET_MODE (XEXP (varop, 0))) + { + if (BITS_BIG_ENDIAN) + new = XEXP (varop, 0); + else + { + new = copy_rtx (XEXP (varop, 0)); + SUBST (XEXP (new, 0), + plus_constant (XEXP (new, 0), + count / BITS_PER_UNIT)); + } + + varop = gen_rtx_combine (code == ASHIFTRT ? SIGN_EXTEND + : ZERO_EXTEND, mode, new); + count = 0; + continue; + } + break; + + case SUBREG: + /* If VAROP is a SUBREG, strip it as long as the inner operand has + the same number of words as what we've seen so far. Then store + the widest mode in MODE. */ + if (subreg_lowpart_p (varop) + && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop))) + > GET_MODE_SIZE (GET_MODE (varop))) + && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop))) + + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) + == mode_words)) + { + varop = SUBREG_REG (varop); + if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode)) + mode = GET_MODE (varop); + continue; + } + break; + + case MULT: + /* Some machines use MULT instead of ASHIFT because MULT + is cheaper. But it is still better on those machines to + merge two shifts into one. */ + if (GET_CODE (XEXP (varop, 1)) == CONST_INT + && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0) + { + varop = gen_binary (ASHIFT, GET_MODE (varop), XEXP (varop, 0), + GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1)))));; + continue; + } + break; + + case UDIV: + /* Similar, for when divides are cheaper. */ + if (GET_CODE (XEXP (varop, 1)) == CONST_INT + && exact_log2 (INTVAL (XEXP (varop, 1))) >= 0) + { + varop = gen_binary (LSHIFTRT, GET_MODE (varop), XEXP (varop, 0), + GEN_INT (exact_log2 (INTVAL (XEXP (varop, 1))))); + continue; + } + break; + + case ASHIFTRT: + /* If we are extracting just the sign bit of an arithmetic right + shift, that shift is not needed. */ + if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1) + { + varop = XEXP (varop, 0); + continue; + } + + /* ... fall through ... */ + + case LSHIFTRT: + case ASHIFT: + case ROTATE: + /* Here we have two nested shifts. The result is usually the + AND of a new shift with a mask. We compute the result below. */ + if (GET_CODE (XEXP (varop, 1)) == CONST_INT + && INTVAL (XEXP (varop, 1)) >= 0 + && INTVAL (XEXP (varop, 1)) < GET_MODE_BITSIZE (GET_MODE (varop)) + && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) + { + enum rtx_code first_code = GET_CODE (varop); + int first_count = INTVAL (XEXP (varop, 1)); + unsigned HOST_WIDE_INT mask; + rtx mask_rtx; + + /* We have one common special case. We can't do any merging if + the inner code is an ASHIFTRT of a smaller mode. However, if + we have (ashift:M1 (subreg:M1 (ashiftrt:M2 FOO C1) 0) C2) + with C2 == GET_MODE_BITSIZE (M1) - GET_MODE_BITSIZE (M2), + we can convert it to + (ashiftrt:M1 (ashift:M1 (and:M1 (subreg:M1 FOO 0 C2) C3) C1). + This simplifies certain SIGN_EXTEND operations. */ + if (code == ASHIFT && first_code == ASHIFTRT + && (GET_MODE_BITSIZE (result_mode) + - GET_MODE_BITSIZE (GET_MODE (varop))) == count) + { + /* C3 has the low-order C1 bits zero. */ + + mask = (GET_MODE_MASK (mode) + & ~ (((HOST_WIDE_INT) 1 << first_count) - 1)); + + varop = simplify_and_const_int (NULL_RTX, result_mode, + XEXP (varop, 0), mask); + varop = simplify_shift_const (NULL_RTX, ASHIFT, result_mode, + varop, count); + count = first_count; + code = ASHIFTRT; + continue; + } + + /* If this was (ashiftrt (ashift foo C1) C2) and FOO has more + than C1 high-order bits equal to the sign bit, we can convert + this to either an ASHIFT or a ASHIFTRT depending on the + two counts. + + We cannot do this if VAROP's mode is not SHIFT_MODE. */ + + if (code == ASHIFTRT && first_code == ASHIFT + && GET_MODE (varop) == shift_mode + && (num_sign_bit_copies (XEXP (varop, 0), shift_mode) + > first_count)) + { + count -= first_count; + if (count < 0) + count = - count, code = ASHIFT; + varop = XEXP (varop, 0); + continue; + } + + /* There are some cases we can't do. If CODE is ASHIFTRT, + we can only do this if FIRST_CODE is also ASHIFTRT. + + We can't do the case when CODE is ROTATE and FIRST_CODE is + ASHIFTRT. + + If the mode of this shift is not the mode of the outer shift, + we can't do this if either shift is a right shift or ROTATE. + + Finally, we can't do any of these if the mode is too wide + unless the codes are the same. + + Handle the case where the shift codes are the same + first. */ + + if (code == first_code) + { + if (GET_MODE (varop) != result_mode + && (code == ASHIFTRT || code == LSHIFTRT + || code == ROTATE)) + break; + + count += first_count; + varop = XEXP (varop, 0); + continue; + } + + if (code == ASHIFTRT + || (code == ROTATE && first_code == ASHIFTRT) + || GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT + || (GET_MODE (varop) != result_mode + && (first_code == ASHIFTRT || first_code == LSHIFTRT + || first_code == ROTATE + || code == ROTATE))) + break; + + /* To compute the mask to apply after the shift, shift the + nonzero bits of the inner shift the same way the + outer shift will. */ + + mask_rtx = GEN_INT (nonzero_bits (varop, GET_MODE (varop))); + + mask_rtx + = simplify_binary_operation (code, result_mode, mask_rtx, + GEN_INT (count)); + + /* Give up if we can't compute an outer operation to use. */ + if (mask_rtx == 0 + || GET_CODE (mask_rtx) != CONST_INT + || ! merge_outer_ops (&outer_op, &outer_const, AND, + INTVAL (mask_rtx), + result_mode, &complement_p)) + break; + + /* If the shifts are in the same direction, we add the + counts. Otherwise, we subtract them. */ + if ((code == ASHIFTRT || code == LSHIFTRT) + == (first_code == ASHIFTRT || first_code == LSHIFTRT)) + count += first_count; + else + count -= first_count; + + /* If COUNT is positive, the new shift is usually CODE, + except for the two exceptions below, in which case it is + FIRST_CODE. If the count is negative, FIRST_CODE should + always be used */ + if (count > 0 + && ((first_code == ROTATE && code == ASHIFT) + || (first_code == ASHIFTRT && code == LSHIFTRT))) + code = first_code; + else if (count < 0) + code = first_code, count = - count; + + varop = XEXP (varop, 0); + continue; + } + + /* If we have (A << B << C) for any shift, we can convert this to + (A << C << B). This wins if A is a constant. Only try this if + B is not a constant. */ + + else if (GET_CODE (varop) == code + && GET_CODE (XEXP (varop, 1)) != CONST_INT + && 0 != (new + = simplify_binary_operation (code, mode, + XEXP (varop, 0), + GEN_INT (count)))) + { + varop = gen_rtx_combine (code, mode, new, XEXP (varop, 1)); + count = 0; + continue; + } + break; + + case NOT: + /* Make this fit the case below. */ + varop = gen_rtx_combine (XOR, mode, XEXP (varop, 0), + GEN_INT (GET_MODE_MASK (mode))); + continue; + + case IOR: + case AND: + case XOR: + /* If we have (xshiftrt (ior (plus X (const_int -1)) X) C) + with C the size of VAROP - 1 and the shift is logical if + STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1, + we have an (le X 0) operation. If we have an arithmetic shift + and STORE_FLAG_VALUE is 1 or we have a logical shift with + STORE_FLAG_VALUE of -1, we have a (neg (le X 0)) operation. */ + + if (GET_CODE (varop) == IOR && GET_CODE (XEXP (varop, 0)) == PLUS + && XEXP (XEXP (varop, 0), 1) == constm1_rtx + && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1) + && (code == LSHIFTRT || code == ASHIFTRT) + && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1 + && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1))) + { + count = 0; + varop = gen_rtx_combine (LE, GET_MODE (varop), XEXP (varop, 1), + const0_rtx); + + if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT) + varop = gen_rtx_combine (NEG, GET_MODE (varop), varop); + + continue; + } + + /* If we have (shift (logical)), move the logical to the outside + to allow it to possibly combine with another logical and the + shift to combine with another shift. This also canonicalizes to + what a ZERO_EXTRACT looks like. Also, some machines have + (and (shift)) insns. */ + + if (GET_CODE (XEXP (varop, 1)) == CONST_INT + && (new = simplify_binary_operation (code, result_mode, + XEXP (varop, 1), + GEN_INT (count))) != 0 + && GET_CODE(new) == CONST_INT + && merge_outer_ops (&outer_op, &outer_const, GET_CODE (varop), + INTVAL (new), result_mode, &complement_p)) + { + varop = XEXP (varop, 0); + continue; + } + + /* If we can't do that, try to simplify the shift in each arm of the + logical expression, make a new logical expression, and apply + the inverse distributive law. */ + { + rtx lhs = simplify_shift_const (NULL_RTX, code, shift_mode, + XEXP (varop, 0), count); + rtx rhs = simplify_shift_const (NULL_RTX, code, shift_mode, + XEXP (varop, 1), count); + + varop = gen_binary (GET_CODE (varop), shift_mode, lhs, rhs); + varop = apply_distributive_law (varop); + + count = 0; + } + break; + + case EQ: + /* convert (lshiftrt (eq FOO 0) C) to (xor FOO 1) if STORE_FLAG_VALUE + says that the sign bit can be tested, FOO has mode MODE, C is + GET_MODE_BITSIZE (MODE) - 1, and FOO has only its low-order bit + that may be nonzero. */ + if (code == LSHIFTRT + && XEXP (varop, 1) == const0_rtx + && GET_MODE (XEXP (varop, 0)) == result_mode + && count == GET_MODE_BITSIZE (result_mode) - 1 + && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT + && ((STORE_FLAG_VALUE + & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (result_mode) - 1)))) + && nonzero_bits (XEXP (varop, 0), result_mode) == 1 + && merge_outer_ops (&outer_op, &outer_const, XOR, + (HOST_WIDE_INT) 1, result_mode, + &complement_p)) + { + varop = XEXP (varop, 0); + count = 0; + continue; + } + break; + + case NEG: + /* (lshiftrt (neg A) C) where A is either 0 or 1 and C is one less + than the number of bits in the mode is equivalent to A. */ + if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1 + && nonzero_bits (XEXP (varop, 0), result_mode) == 1) + { + varop = XEXP (varop, 0); + count = 0; + continue; + } + + /* NEG commutes with ASHIFT since it is multiplication. Move the + NEG outside to allow shifts to combine. */ + if (code == ASHIFT + && merge_outer_ops (&outer_op, &outer_const, NEG, + (HOST_WIDE_INT) 0, result_mode, + &complement_p)) + { + varop = XEXP (varop, 0); + continue; + } + break; + + case PLUS: + /* (lshiftrt (plus A -1) C) where A is either 0 or 1 and C + is one less than the number of bits in the mode is + equivalent to (xor A 1). */ + if (code == LSHIFTRT && count == GET_MODE_BITSIZE (result_mode) - 1 + && XEXP (varop, 1) == constm1_rtx + && nonzero_bits (XEXP (varop, 0), result_mode) == 1 + && merge_outer_ops (&outer_op, &outer_const, XOR, + (HOST_WIDE_INT) 1, result_mode, + &complement_p)) + { + count = 0; + varop = XEXP (varop, 0); + continue; + } + + /* If we have (xshiftrt (plus FOO BAR) C), and the only bits + that might be nonzero in BAR are those being shifted out and those + bits are known zero in FOO, we can replace the PLUS with FOO. + Similarly in the other operand order. This code occurs when + we are computing the size of a variable-size array. */ + + if ((code == ASHIFTRT || code == LSHIFTRT) + && count < HOST_BITS_PER_WIDE_INT + && nonzero_bits (XEXP (varop, 1), result_mode) >> count == 0 + && (nonzero_bits (XEXP (varop, 1), result_mode) + & nonzero_bits (XEXP (varop, 0), result_mode)) == 0) + { + varop = XEXP (varop, 0); + continue; + } + else if ((code == ASHIFTRT || code == LSHIFTRT) + && count < HOST_BITS_PER_WIDE_INT + && GET_MODE_BITSIZE (result_mode) <= HOST_BITS_PER_WIDE_INT + && 0 == (nonzero_bits (XEXP (varop, 0), result_mode) + >> count) + && 0 == (nonzero_bits (XEXP (varop, 0), result_mode) + & nonzero_bits (XEXP (varop, 1), + result_mode))) + { + varop = XEXP (varop, 1); + continue; + } + + /* (ashift (plus foo C) N) is (plus (ashift foo N) C'). */ + if (code == ASHIFT + && GET_CODE (XEXP (varop, 1)) == CONST_INT + && (new = simplify_binary_operation (ASHIFT, result_mode, + XEXP (varop, 1), + GEN_INT (count))) != 0 + && GET_CODE(new) == CONST_INT + && merge_outer_ops (&outer_op, &outer_const, PLUS, + INTVAL (new), result_mode, &complement_p)) + { + varop = XEXP (varop, 0); + continue; + } + break; + + case MINUS: + /* If we have (xshiftrt (minus (ashiftrt X C)) X) C) + with C the size of VAROP - 1 and the shift is logical if + STORE_FLAG_VALUE is 1 and arithmetic if STORE_FLAG_VALUE is -1, + we have a (gt X 0) operation. If the shift is arithmetic with + STORE_FLAG_VALUE of 1 or logical with STORE_FLAG_VALUE == -1, + we have a (neg (gt X 0)) operation. */ + + if (GET_CODE (XEXP (varop, 0)) == ASHIFTRT + && count == GET_MODE_BITSIZE (GET_MODE (varop)) - 1 + && (STORE_FLAG_VALUE == 1 || STORE_FLAG_VALUE == -1) + && (code == LSHIFTRT || code == ASHIFTRT) + && GET_CODE (XEXP (XEXP (varop, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (varop, 0), 1)) == count + && rtx_equal_p (XEXP (XEXP (varop, 0), 0), XEXP (varop, 1))) + { + count = 0; + varop = gen_rtx_combine (GT, GET_MODE (varop), XEXP (varop, 1), + const0_rtx); + + if (STORE_FLAG_VALUE == 1 ? code == ASHIFTRT : code == LSHIFTRT) + varop = gen_rtx_combine (NEG, GET_MODE (varop), varop); + + continue; + } + break; + } + + break; + } + + /* We need to determine what mode to do the shift in. If the shift is + a right shift or ROTATE, we must always do it in the mode it was + originally done in. Otherwise, we can do it in MODE, the widest mode + encountered. The code we care about is that of the shift that will + actually be done, not the shift that was originally requested. */ + shift_mode + = (code == ASHIFTRT || code == LSHIFTRT || code == ROTATE + ? result_mode : mode); + + /* We have now finished analyzing the shift. The result should be + a shift of type CODE with SHIFT_MODE shifting VAROP COUNT places. If + OUTER_OP is non-NIL, it is an operation that needs to be applied + to the result of the shift. OUTER_CONST is the relevant constant, + but we must turn off all bits turned off in the shift. + + If we were passed a value for X, see if we can use any pieces of + it. If not, make new rtx. */ + + if (x && GET_RTX_CLASS (GET_CODE (x)) == '2' + && GET_CODE (XEXP (x, 1)) == CONST_INT + && INTVAL (XEXP (x, 1)) == count) + const_rtx = XEXP (x, 1); + else + const_rtx = GEN_INT (count); + + if (x && GET_CODE (XEXP (x, 0)) == SUBREG + && GET_MODE (XEXP (x, 0)) == shift_mode + && SUBREG_REG (XEXP (x, 0)) == varop) + varop = XEXP (x, 0); + else if (GET_MODE (varop) != shift_mode) + varop = gen_lowpart_for_combine (shift_mode, varop); + + /* If we can't make the SUBREG, try to return what we were given. */ + if (GET_CODE (varop) == CLOBBER) + return x ? x : varop; + + new = simplify_binary_operation (code, shift_mode, varop, const_rtx); + if (new != 0) + x = new; + else + { + if (x == 0 || GET_CODE (x) != code || GET_MODE (x) != shift_mode) + x = gen_rtx_combine (code, shift_mode, varop, const_rtx); + + SUBST (XEXP (x, 0), varop); + SUBST (XEXP (x, 1), const_rtx); + } + + /* If we have an outer operation and we just made a shift, it is + possible that we could have simplified the shift were it not + for the outer operation. So try to do the simplification + recursively. */ + + if (outer_op != NIL && GET_CODE (x) == code + && GET_CODE (XEXP (x, 1)) == CONST_INT) + x = simplify_shift_const (x, code, shift_mode, XEXP (x, 0), + INTVAL (XEXP (x, 1))); + + /* If we were doing a LSHIFTRT in a wider mode than it was originally, + turn off all the bits that the shift would have turned off. */ + if (orig_code == LSHIFTRT && result_mode != shift_mode) + x = simplify_and_const_int (NULL_RTX, shift_mode, x, + GET_MODE_MASK (result_mode) >> orig_count); + + /* Do the remainder of the processing in RESULT_MODE. */ + x = gen_lowpart_for_combine (result_mode, x); + + /* If COMPLEMENT_P is set, we have to complement X before doing the outer + operation. */ + if (complement_p) + x = gen_unary (NOT, result_mode, result_mode, x); + + if (outer_op != NIL) + { + if (GET_MODE_BITSIZE (result_mode) < HOST_BITS_PER_WIDE_INT) + { + int width = GET_MODE_BITSIZE (result_mode); + + outer_const &= GET_MODE_MASK (result_mode); + + /* If this would be an entire word for the target, but is not for + the host, then sign-extend on the host so that the number will + look the same way on the host that it would on the target. + + For example, when building a 64 bit alpha hosted 32 bit sparc + targeted compiler, then we want the 32 bit unsigned value -1 to be + represented as a 64 bit value -1, and not as 0x00000000ffffffff. + The later confuses the sparc backend. */ + + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width + && (outer_const & ((HOST_WIDE_INT) 1 << (width - 1)))) + outer_const |= ((HOST_WIDE_INT) (-1) << width); + } + + if (outer_op == AND) + x = simplify_and_const_int (NULL_RTX, result_mode, x, outer_const); + else if (outer_op == SET) + /* This means that we have determined that the result is + equivalent to a constant. This should be rare. */ + x = GEN_INT (outer_const); + else if (GET_RTX_CLASS (outer_op) == '1') + x = gen_unary (outer_op, result_mode, result_mode, x); + else + x = gen_binary (outer_op, result_mode, x, GEN_INT (outer_const)); + } + + return x; +} + +/* Like recog, but we receive the address of a pointer to a new pattern. + We try to match the rtx that the pointer points to. + If that fails, we may try to modify or replace the pattern, + storing the replacement into the same pointer object. + + Modifications include deletion or addition of CLOBBERs. + + PNOTES is a pointer to a location where any REG_UNUSED notes added for + the CLOBBERs are placed. + + PADDED_SCRATCHES is set to the number of (clobber (scratch)) patterns + we had to add. + + The value is the final insn code from the pattern ultimately matched, + or -1. */ + +static int +recog_for_combine (pnewpat, insn, pnotes, padded_scratches) + rtx *pnewpat; + rtx insn; + rtx *pnotes; + int *padded_scratches; +{ + register rtx pat = *pnewpat; + int insn_code_number; + int num_clobbers_to_add = 0; + int i; + rtx notes = 0; + + *padded_scratches = 0; + + /* If PAT is a PARALLEL, check to see if it contains the CLOBBER + we use to indicate that something didn't match. If we find such a + thing, force rejection. */ + if (GET_CODE (pat) == PARALLEL) + for (i = XVECLEN (pat, 0) - 1; i >= 0; i--) + if (GET_CODE (XVECEXP (pat, 0, i)) == CLOBBER + && XEXP (XVECEXP (pat, 0, i), 0) == const0_rtx) + return -1; + + /* Is the result of combination a valid instruction? */ + insn_code_number = recog (pat, insn, &num_clobbers_to_add); + + /* If it isn't, there is the possibility that we previously had an insn + that clobbered some register as a side effect, but the combined + insn doesn't need to do that. So try once more without the clobbers + unless this represents an ASM insn. */ + + if (insn_code_number < 0 && ! check_asm_operands (pat) + && GET_CODE (pat) == PARALLEL) + { + int pos; + + for (pos = 0, i = 0; i < XVECLEN (pat, 0); i++) + if (GET_CODE (XVECEXP (pat, 0, i)) != CLOBBER) + { + if (i != pos) + SUBST (XVECEXP (pat, 0, pos), XVECEXP (pat, 0, i)); + pos++; + } + + SUBST_INT (XVECLEN (pat, 0), pos); + + if (pos == 1) + pat = XVECEXP (pat, 0, 0); + + insn_code_number = recog (pat, insn, &num_clobbers_to_add); + } + + /* If we had any clobbers to add, make a new pattern than contains + them. Then check to make sure that all of them are dead. */ + if (num_clobbers_to_add) + { + rtx newpat = gen_rtx (PARALLEL, VOIDmode, + gen_rtvec (GET_CODE (pat) == PARALLEL + ? XVECLEN (pat, 0) + num_clobbers_to_add + : num_clobbers_to_add + 1)); + + if (GET_CODE (pat) == PARALLEL) + for (i = 0; i < XVECLEN (pat, 0); i++) + XVECEXP (newpat, 0, i) = XVECEXP (pat, 0, i); + else + XVECEXP (newpat, 0, 0) = pat; + + add_clobbers (newpat, insn_code_number); + + for (i = XVECLEN (newpat, 0) - num_clobbers_to_add; + i < XVECLEN (newpat, 0); i++) + { + if (GET_CODE (XEXP (XVECEXP (newpat, 0, i), 0)) == REG + && ! reg_dead_at_p (XEXP (XVECEXP (newpat, 0, i), 0), insn)) + return -1; + else if (GET_CODE (XEXP (XVECEXP (newpat, 0, i), 0)) == SCRATCH) + (*padded_scratches)++; + notes = gen_rtx (EXPR_LIST, REG_UNUSED, + XEXP (XVECEXP (newpat, 0, i), 0), notes); + } + pat = newpat; + } + + *pnewpat = pat; + *pnotes = notes; + + return insn_code_number; +} + +/* Like gen_lowpart but for use by combine. In combine it is not possible + to create any new pseudoregs. However, it is safe to create + invalid memory addresses, because combine will try to recognize + them and all they will do is make the combine attempt fail. + + If for some reason this cannot do its job, an rtx + (clobber (const_int 0)) is returned. + An insn containing that will not be recognized. */ + +#undef gen_lowpart + +static rtx +gen_lowpart_for_combine (mode, x) + enum machine_mode mode; + register rtx x; +{ + rtx result; + + if (GET_MODE (x) == mode) + return x; + + /* We can only support MODE being wider than a word if X is a + constant integer or has a mode the same size. */ + + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD + && ! ((GET_MODE (x) == VOIDmode + && (GET_CODE (x) == CONST_INT + || GET_CODE (x) == CONST_DOUBLE)) + || GET_MODE_SIZE (GET_MODE (x)) == GET_MODE_SIZE (mode))) + return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx); + + /* X might be a paradoxical (subreg (mem)). In that case, gen_lowpart + won't know what to do. So we will strip off the SUBREG here and + process normally. */ + if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) + { + x = SUBREG_REG (x); + if (GET_MODE (x) == mode) + return x; + } + + result = gen_lowpart_common (mode, x); + if (result != 0 + && GET_CODE (result) == SUBREG + && GET_CODE (SUBREG_REG (result)) == REG + && REGNO (SUBREG_REG (result)) >= FIRST_PSEUDO_REGISTER + && (GET_MODE_SIZE (GET_MODE (result)) + != GET_MODE_SIZE (GET_MODE (SUBREG_REG (result))))) + reg_changes_size[REGNO (SUBREG_REG (result))] = 1; + + if (result) + return result; + + if (GET_CODE (x) == MEM) + { + register int offset = 0; + rtx new; + + /* Refuse to work on a volatile memory ref or one with a mode-dependent + address. */ + if (MEM_VOLATILE_P (x) || mode_dependent_address_p (XEXP (x, 0))) + return gen_rtx (CLOBBER, GET_MODE (x), const0_rtx); + + /* If we want to refer to something bigger than the original memref, + generate a perverse subreg instead. That will force a reload + of the original memref X. */ + if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode)) + return gen_rtx (SUBREG, mode, x, 0); + + if (WORDS_BIG_ENDIAN) + offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); + if (BYTES_BIG_ENDIAN) + { + /* Adjust the address so that the address-after-the-data is + unchanged. */ + offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) + - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))); + } + new = gen_rtx (MEM, mode, plus_constant (XEXP (x, 0), offset)); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x); + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x); + return new; + } + + /* If X is a comparison operator, rewrite it in a new mode. This + probably won't match, but may allow further simplifications. */ + else if (GET_RTX_CLASS (GET_CODE (x)) == '<') + return gen_rtx_combine (GET_CODE (x), mode, XEXP (x, 0), XEXP (x, 1)); + + /* If we couldn't simplify X any other way, just enclose it in a + SUBREG. Normally, this SUBREG won't match, but some patterns may + include an explicit SUBREG or we may simplify it further in combine. */ + else + { + int word = 0; + + if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) + word = ((GET_MODE_SIZE (GET_MODE (x)) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)) + / UNITS_PER_WORD); + return gen_rtx (SUBREG, mode, x, word); + } +} + +/* Make an rtx expression. This is a subset of gen_rtx and only supports + expressions of 1, 2, or 3 operands, each of which are rtx expressions. + + If the identical expression was previously in the insn (in the undobuf), + it will be returned. Only if it is not found will a new expression + be made. */ + +/*VARARGS2*/ +static rtx +gen_rtx_combine VPROTO((enum rtx_code code, enum machine_mode mode, ...)) +{ +#ifndef __STDC__ + enum rtx_code code; + enum machine_mode mode; +#endif + va_list p; + int n_args; + rtx args[3]; + int i, j; + char *fmt; + rtx rt; + + VA_START (p, mode); + +#ifndef __STDC__ + code = va_arg (p, enum rtx_code); + mode = va_arg (p, enum machine_mode); +#endif + + n_args = GET_RTX_LENGTH (code); + fmt = GET_RTX_FORMAT (code); + + if (n_args == 0 || n_args > 3) + abort (); + + /* Get each arg and verify that it is supposed to be an expression. */ + for (j = 0; j < n_args; j++) + { + if (*fmt++ != 'e') + abort (); + + args[j] = va_arg (p, rtx); + } + + /* See if this is in undobuf. Be sure we don't use objects that came + from another insn; this could produce circular rtl structures. */ + + for (i = previous_num_undos; i < undobuf.num_undo; i++) + if (!undobuf.undo[i].is_int + && GET_CODE (undobuf.undo[i].old_contents.r) == code + && GET_MODE (undobuf.undo[i].old_contents.r) == mode) + { + for (j = 0; j < n_args; j++) + if (XEXP (undobuf.undo[i].old_contents.r, j) != args[j]) + break; + + if (j == n_args) + return undobuf.undo[i].old_contents.r; + } + + /* Otherwise make a new rtx. We know we have 1, 2, or 3 args. + Use rtx_alloc instead of gen_rtx because it's faster on RISC. */ + rt = rtx_alloc (code); + PUT_MODE (rt, mode); + XEXP (rt, 0) = args[0]; + if (n_args > 1) + { + XEXP (rt, 1) = args[1]; + if (n_args > 2) + XEXP (rt, 2) = args[2]; + } + return rt; +} + +/* These routines make binary and unary operations by first seeing if they + fold; if not, a new expression is allocated. */ + +static rtx +gen_binary (code, mode, op0, op1) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; +{ + rtx result; + rtx tem; + + if (GET_RTX_CLASS (code) == 'c' + && (GET_CODE (op0) == CONST_INT + || (CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT))) + tem = op0, op0 = op1, op1 = tem; + + if (GET_RTX_CLASS (code) == '<') + { + enum machine_mode op_mode = GET_MODE (op0); + + /* Strip the COMPARE from (REL_OP (compare X Y) 0) to get + just (REL_OP X Y). */ + if (GET_CODE (op0) == COMPARE && op1 == const0_rtx) + { + op1 = XEXP (op0, 1); + op0 = XEXP (op0, 0); + op_mode = GET_MODE (op0); + } + + if (op_mode == VOIDmode) + op_mode = GET_MODE (op1); + result = simplify_relational_operation (code, op_mode, op0, op1); + } + else + result = simplify_binary_operation (code, mode, op0, op1); + + if (result) + return result; + + /* Put complex operands first and constants second. */ + if (GET_RTX_CLASS (code) == 'c' + && ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT) + || (GET_RTX_CLASS (GET_CODE (op0)) == 'o' + && GET_RTX_CLASS (GET_CODE (op1)) != 'o') + || (GET_CODE (op0) == SUBREG + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o' + && GET_RTX_CLASS (GET_CODE (op1)) != 'o'))) + return gen_rtx_combine (code, mode, op1, op0); + + return gen_rtx_combine (code, mode, op0, op1); +} + +static rtx +gen_unary (code, mode, op0_mode, op0) + enum rtx_code code; + enum machine_mode mode, op0_mode; + rtx op0; +{ + rtx result = simplify_unary_operation (code, mode, op0, op0_mode); + + if (result) + return result; + + return gen_rtx_combine (code, mode, op0); +} + +/* Simplify a comparison between *POP0 and *POP1 where CODE is the + comparison code that will be tested. + + The result is a possibly different comparison code to use. *POP0 and + *POP1 may be updated. + + It is possible that we might detect that a comparison is either always + true or always false. However, we do not perform general constant + folding in combine, so this knowledge isn't useful. Such tautologies + should have been detected earlier. Hence we ignore all such cases. */ + +static enum rtx_code +simplify_comparison (code, pop0, pop1) + enum rtx_code code; + rtx *pop0; + rtx *pop1; +{ + rtx op0 = *pop0; + rtx op1 = *pop1; + rtx tem, tem1; + int i; + enum machine_mode mode, tmode; + + /* Try a few ways of applying the same transformation to both operands. */ + while (1) + { +#ifndef WORD_REGISTER_OPERATIONS + /* The test below this one won't handle SIGN_EXTENDs on these machines, + so check specially. */ + if (code != GTU && code != GEU && code != LTU && code != LEU + && GET_CODE (op0) == ASHIFTRT && GET_CODE (op1) == ASHIFTRT + && GET_CODE (XEXP (op0, 0)) == ASHIFT + && GET_CODE (XEXP (op1, 0)) == ASHIFT + && GET_CODE (XEXP (XEXP (op0, 0), 0)) == SUBREG + && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SUBREG + && (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0))) + == GET_MODE (SUBREG_REG (XEXP (XEXP (op1, 0), 0)))) + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (XEXP (op1, 1)) == CONST_INT + && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT + && GET_CODE (XEXP (XEXP (op1, 0), 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (op1, 1)) + && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op0, 0), 1)) + && INTVAL (XEXP (op0, 1)) == INTVAL (XEXP (XEXP (op1, 0), 1)) + && (INTVAL (XEXP (op0, 1)) + == (GET_MODE_BITSIZE (GET_MODE (op0)) + - (GET_MODE_BITSIZE + (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0)))))))) + { + op0 = SUBREG_REG (XEXP (XEXP (op0, 0), 0)); + op1 = SUBREG_REG (XEXP (XEXP (op1, 0), 0)); + } +#endif + + /* If both operands are the same constant shift, see if we can ignore the + shift. We can if the shift is a rotate or if the bits shifted out of + this shift are known to be zero for both inputs and if the type of + comparison is compatible with the shift. */ + if (GET_CODE (op0) == GET_CODE (op1) + && GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT + && ((GET_CODE (op0) == ROTATE && (code == NE || code == EQ)) + || ((GET_CODE (op0) == LSHIFTRT || GET_CODE (op0) == ASHIFT) + && (code != GT && code != LT && code != GE && code != LE)) + || (GET_CODE (op0) == ASHIFTRT + && (code != GTU && code != LTU + && code != GEU && code != GEU))) + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) >= 0 + && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT + && XEXP (op0, 1) == XEXP (op1, 1)) + { + enum machine_mode mode = GET_MODE (op0); + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode); + int shift_count = INTVAL (XEXP (op0, 1)); + + if (GET_CODE (op0) == LSHIFTRT || GET_CODE (op0) == ASHIFTRT) + mask &= (mask >> shift_count) << shift_count; + else if (GET_CODE (op0) == ASHIFT) + mask = (mask & (mask << shift_count)) >> shift_count; + + if ((nonzero_bits (XEXP (op0, 0), mode) & ~ mask) == 0 + && (nonzero_bits (XEXP (op1, 0), mode) & ~ mask) == 0) + op0 = XEXP (op0, 0), op1 = XEXP (op1, 0); + else + break; + } + + /* If both operands are AND's of a paradoxical SUBREG by constant, the + SUBREGs are of the same mode, and, in both cases, the AND would + be redundant if the comparison was done in the narrower mode, + do the comparison in the narrower mode (e.g., we are AND'ing with 1 + and the operand's possibly nonzero bits are 0xffffff01; in that case + if we only care about QImode, we don't need the AND). This case + occurs if the output mode of an scc insn is not SImode and + STORE_FLAG_VALUE == 1 (e.g., the 386). + + Similarly, check for a case where the AND's are ZERO_EXTEND + operations from some narrower mode even though a SUBREG is not + present. */ + + else if (GET_CODE (op0) == AND && GET_CODE (op1) == AND + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (XEXP (op1, 1)) == CONST_INT) + { + rtx inner_op0 = XEXP (op0, 0); + rtx inner_op1 = XEXP (op1, 0); + HOST_WIDE_INT c0 = INTVAL (XEXP (op0, 1)); + HOST_WIDE_INT c1 = INTVAL (XEXP (op1, 1)); + int changed = 0; + + if (GET_CODE (inner_op0) == SUBREG && GET_CODE (inner_op1) == SUBREG + && (GET_MODE_SIZE (GET_MODE (inner_op0)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (inner_op0)))) + && (GET_MODE (SUBREG_REG (inner_op0)) + == GET_MODE (SUBREG_REG (inner_op1))) + && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) + <= HOST_BITS_PER_WIDE_INT) + && (0 == (~c0) & nonzero_bits (SUBREG_REG (inner_op0), + GET_MODE (SUBREG_REG (op0)))) + && (0 == (~c1) & nonzero_bits (SUBREG_REG (inner_op1), + GET_MODE (SUBREG_REG (inner_op1))))) + { + op0 = SUBREG_REG (inner_op0); + op1 = SUBREG_REG (inner_op1); + + /* The resulting comparison is always unsigned since we masked + off the original sign bit. */ + code = unsigned_condition (code); + + changed = 1; + } + + else if (c0 == c1) + for (tmode = GET_CLASS_NARROWEST_MODE + (GET_MODE_CLASS (GET_MODE (op0))); + tmode != GET_MODE (op0); tmode = GET_MODE_WIDER_MODE (tmode)) + if (c0 == GET_MODE_MASK (tmode)) + { + op0 = gen_lowpart_for_combine (tmode, inner_op0); + op1 = gen_lowpart_for_combine (tmode, inner_op1); + code = unsigned_condition (code); + changed = 1; + break; + } + + if (! changed) + break; + } + + /* If both operands are NOT, we can strip off the outer operation + and adjust the comparison code for swapped operands; similarly for + NEG, except that this must be an equality comparison. */ + else if ((GET_CODE (op0) == NOT && GET_CODE (op1) == NOT) + || (GET_CODE (op0) == NEG && GET_CODE (op1) == NEG + && (code == EQ || code == NE))) + op0 = XEXP (op0, 0), op1 = XEXP (op1, 0), code = swap_condition (code); + + else + break; + } + + /* If the first operand is a constant, swap the operands and adjust the + comparison code appropriately. */ + if (CONSTANT_P (op0)) + { + tem = op0, op0 = op1, op1 = tem; + code = swap_condition (code); + } + + /* We now enter a loop during which we will try to simplify the comparison. + For the most part, we only are concerned with comparisons with zero, + but some things may really be comparisons with zero but not start + out looking that way. */ + + while (GET_CODE (op1) == CONST_INT) + { + enum machine_mode mode = GET_MODE (op0); + int mode_width = GET_MODE_BITSIZE (mode); + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (mode); + int equality_comparison_p; + int sign_bit_comparison_p; + int unsigned_comparison_p; + HOST_WIDE_INT const_op; + + /* We only want to handle integral modes. This catches VOIDmode, + CCmode, and the floating-point modes. An exception is that we + can handle VOIDmode if OP0 is a COMPARE or a comparison + operation. */ + + if (GET_MODE_CLASS (mode) != MODE_INT + && ! (mode == VOIDmode + && (GET_CODE (op0) == COMPARE + || GET_RTX_CLASS (GET_CODE (op0)) == '<'))) + break; + + /* Get the constant we are comparing against and turn off all bits + not on in our mode. */ + const_op = INTVAL (op1); + if (mode_width <= HOST_BITS_PER_WIDE_INT) + const_op &= mask; + + /* If we are comparing against a constant power of two and the value + being compared can only have that single bit nonzero (e.g., it was + `and'ed with that bit), we can replace this with a comparison + with zero. */ + if (const_op + && (code == EQ || code == NE || code == GE || code == GEU + || code == LT || code == LTU) + && mode_width <= HOST_BITS_PER_WIDE_INT + && exact_log2 (const_op) >= 0 + && nonzero_bits (op0, mode) == const_op) + { + code = (code == EQ || code == GE || code == GEU ? NE : EQ); + op1 = const0_rtx, const_op = 0; + } + + /* Similarly, if we are comparing a value known to be either -1 or + 0 with -1, change it to the opposite comparison against zero. */ + + if (const_op == -1 + && (code == EQ || code == NE || code == GT || code == LE + || code == GEU || code == LTU) + && num_sign_bit_copies (op0, mode) == mode_width) + { + code = (code == EQ || code == LE || code == GEU ? NE : EQ); + op1 = const0_rtx, const_op = 0; + } + + /* Do some canonicalizations based on the comparison code. We prefer + comparisons against zero and then prefer equality comparisons. + If we can reduce the size of a constant, we will do that too. */ + + switch (code) + { + case LT: + /* < C is equivalent to <= (C - 1) */ + if (const_op > 0) + { + const_op -= 1; + op1 = GEN_INT (const_op); + code = LE; + /* ... fall through to LE case below. */ + } + else + break; + + case LE: + /* <= C is equivalent to < (C + 1); we do this for C < 0 */ + if (const_op < 0) + { + const_op += 1; + op1 = GEN_INT (const_op); + code = LT; + } + + /* If we are doing a <= 0 comparison on a value known to have + a zero sign bit, we can replace this with == 0. */ + else if (const_op == 0 + && mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (op0, mode) + & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0) + code = EQ; + break; + + case GE: + /* >= C is equivalent to > (C - 1). */ + if (const_op > 0) + { + const_op -= 1; + op1 = GEN_INT (const_op); + code = GT; + /* ... fall through to GT below. */ + } + else + break; + + case GT: + /* > C is equivalent to >= (C + 1); we do this for C < 0*/ + if (const_op < 0) + { + const_op += 1; + op1 = GEN_INT (const_op); + code = GE; + } + + /* If we are doing a > 0 comparison on a value known to have + a zero sign bit, we can replace this with != 0. */ + else if (const_op == 0 + && mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (op0, mode) + & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0) + code = NE; + break; + + case LTU: + /* < C is equivalent to <= (C - 1). */ + if (const_op > 0) + { + const_op -= 1; + op1 = GEN_INT (const_op); + code = LEU; + /* ... fall through ... */ + } + + /* (unsigned) < 0x80000000 is equivalent to >= 0. */ + else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1)) + { + const_op = 0, op1 = const0_rtx; + code = GE; + break; + } + else + break; + + case LEU: + /* unsigned <= 0 is equivalent to == 0 */ + if (const_op == 0) + code = EQ; + + /* (unsigned) <= 0x7fffffff is equivalent to >= 0. */ + else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1) + { + const_op = 0, op1 = const0_rtx; + code = GE; + } + break; + + case GEU: + /* >= C is equivalent to < (C - 1). */ + if (const_op > 1) + { + const_op -= 1; + op1 = GEN_INT (const_op); + code = GTU; + /* ... fall through ... */ + } + + /* (unsigned) >= 0x80000000 is equivalent to < 0. */ + else if (const_op == (HOST_WIDE_INT) 1 << (mode_width - 1)) + { + const_op = 0, op1 = const0_rtx; + code = LT; + break; + } + else + break; + + case GTU: + /* unsigned > 0 is equivalent to != 0 */ + if (const_op == 0) + code = NE; + + /* (unsigned) > 0x7fffffff is equivalent to < 0. */ + else if (const_op == ((HOST_WIDE_INT) 1 << (mode_width - 1)) - 1) + { + const_op = 0, op1 = const0_rtx; + code = LT; + } + break; + } + + /* Compute some predicates to simplify code below. */ + + equality_comparison_p = (code == EQ || code == NE); + sign_bit_comparison_p = ((code == LT || code == GE) && const_op == 0); + unsigned_comparison_p = (code == LTU || code == LEU || code == GTU + || code == LEU); + + /* If this is a sign bit comparison and we can do arithmetic in + MODE, say that we will only be needing the sign bit of OP0. */ + if (sign_bit_comparison_p + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) + op0 = force_to_mode (op0, mode, + ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (mode) - 1)), + NULL_RTX, 0); + + /* Now try cases based on the opcode of OP0. If none of the cases + does a "continue", we exit this loop immediately after the + switch. */ + + switch (GET_CODE (op0)) + { + case ZERO_EXTRACT: + /* If we are extracting a single bit from a variable position in + a constant that has only a single bit set and are comparing it + with zero, we can convert this into an equality comparison + between the position and the location of the single bit. We can't + do this if bit endian and we don't have an extzv since we then + can't know what mode to use for the endianness adjustment. */ + + if (GET_CODE (XEXP (op0, 0)) == CONST_INT + && XEXP (op0, 1) == const1_rtx + && equality_comparison_p && const_op == 0 + && (i = exact_log2 (INTVAL (XEXP (op0, 0)))) >= 0 + && (! BITS_BIG_ENDIAN +#ifdef HAVE_extzv + || HAVE_extzv +#endif + )) + { +#ifdef HAVE_extzv + if (BITS_BIG_ENDIAN) + i = (GET_MODE_BITSIZE + (insn_operand_mode[(int) CODE_FOR_extzv][1]) - 1 - i); +#endif + + op0 = XEXP (op0, 2); + op1 = GEN_INT (i); + const_op = i; + + /* Result is nonzero iff shift count is equal to I. */ + code = reverse_condition (code); + continue; + } + + /* ... fall through ... */ + + case SIGN_EXTRACT: + tem = expand_compound_operation (op0); + if (tem != op0) + { + op0 = tem; + continue; + } + break; + + case NOT: + /* If testing for equality, we can take the NOT of the constant. */ + if (equality_comparison_p + && (tem = simplify_unary_operation (NOT, mode, op1, mode)) != 0) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + + /* If just looking at the sign bit, reverse the sense of the + comparison. */ + if (sign_bit_comparison_p) + { + op0 = XEXP (op0, 0); + code = (code == GE ? LT : GE); + continue; + } + break; + + case NEG: + /* If testing for equality, we can take the NEG of the constant. */ + if (equality_comparison_p + && (tem = simplify_unary_operation (NEG, mode, op1, mode)) != 0) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + + /* The remaining cases only apply to comparisons with zero. */ + if (const_op != 0) + break; + + /* When X is ABS or is known positive, + (neg X) is < 0 if and only if X != 0. */ + + if (sign_bit_comparison_p + && (GET_CODE (XEXP (op0, 0)) == ABS + || (mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (op0, 0), mode) + & ((HOST_WIDE_INT) 1 << (mode_width - 1))) == 0))) + { + op0 = XEXP (op0, 0); + code = (code == LT ? NE : EQ); + continue; + } + + /* If we have NEG of something whose two high-order bits are the + same, we know that "(-a) < 0" is equivalent to "a > 0". */ + if (num_sign_bit_copies (op0, mode) >= 2) + { + op0 = XEXP (op0, 0); + code = swap_condition (code); + continue; + } + break; + + case ROTATE: + /* If we are testing equality and our count is a constant, we + can perform the inverse operation on our RHS. */ + if (equality_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT + && (tem = simplify_binary_operation (ROTATERT, mode, + op1, XEXP (op0, 1))) != 0) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + + /* If we are doing a < 0 or >= 0 comparison, it means we are testing + a particular bit. Convert it to an AND of a constant of that + bit. This will be converted into a ZERO_EXTRACT. */ + if (const_op == 0 && sign_bit_comparison_p + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && mode_width <= HOST_BITS_PER_WIDE_INT) + { + op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0), + ((HOST_WIDE_INT) 1 + << (mode_width - 1 + - INTVAL (XEXP (op0, 1))))); + code = (code == LT ? NE : EQ); + continue; + } + + /* ... fall through ... */ + + case ABS: + /* ABS is ignorable inside an equality comparison with zero. */ + if (const_op == 0 && equality_comparison_p) + { + op0 = XEXP (op0, 0); + continue; + } + break; + + + case SIGN_EXTEND: + /* Can simplify (compare (zero/sign_extend FOO) CONST) + to (compare FOO CONST) if CONST fits in FOO's mode and we + are either testing inequality or have an unsigned comparison + with ZERO_EXTEND or a signed comparison with SIGN_EXTEND. */ + if (! unsigned_comparison_p + && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))) + <= HOST_BITS_PER_WIDE_INT) + && ((unsigned HOST_WIDE_INT) const_op + < (((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))) - 1))))) + { + op0 = XEXP (op0, 0); + continue; + } + break; + + case SUBREG: + /* Check for the case where we are comparing A - C1 with C2, + both constants are smaller than 1/2 the maximum positive + value in MODE, and the comparison is equality or unsigned. + In that case, if A is either zero-extended to MODE or has + sufficient sign bits so that the high-order bit in MODE + is a copy of the sign in the inner mode, we can prove that it is + safe to do the operation in the wider mode. This simplifies + many range checks. */ + + if (mode_width <= HOST_BITS_PER_WIDE_INT + && subreg_lowpart_p (op0) + && GET_CODE (SUBREG_REG (op0)) == PLUS + && GET_CODE (XEXP (SUBREG_REG (op0), 1)) == CONST_INT + && INTVAL (XEXP (SUBREG_REG (op0), 1)) < 0 + && (- INTVAL (XEXP (SUBREG_REG (op0), 1)) + < GET_MODE_MASK (mode) / 2) + && (unsigned HOST_WIDE_INT) const_op < GET_MODE_MASK (mode) / 2 + && (0 == (nonzero_bits (XEXP (SUBREG_REG (op0), 0), + GET_MODE (SUBREG_REG (op0))) + & ~ GET_MODE_MASK (mode)) + || (num_sign_bit_copies (XEXP (SUBREG_REG (op0), 0), + GET_MODE (SUBREG_REG (op0))) + > (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) + - GET_MODE_BITSIZE (mode))))) + { + op0 = SUBREG_REG (op0); + continue; + } + + /* If the inner mode is narrower and we are extracting the low part, + we can treat the SUBREG as if it were a ZERO_EXTEND. */ + if (subreg_lowpart_p (op0) + && GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) < mode_width) + /* Fall through */ ; + else + break; + + /* ... fall through ... */ + + case ZERO_EXTEND: + if ((unsigned_comparison_p || equality_comparison_p) + && (GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0))) + <= HOST_BITS_PER_WIDE_INT) + && ((unsigned HOST_WIDE_INT) const_op + < GET_MODE_MASK (GET_MODE (XEXP (op0, 0))))) + { + op0 = XEXP (op0, 0); + continue; + } + break; + + case PLUS: + /* (eq (plus X A) B) -> (eq X (minus B A)). We can only do + this for equality comparisons due to pathological cases involving + overflows. */ + if (equality_comparison_p + && 0 != (tem = simplify_binary_operation (MINUS, mode, + op1, XEXP (op0, 1)))) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + + /* (plus (abs X) (const_int -1)) is < 0 if and only if X == 0. */ + if (const_op == 0 && XEXP (op0, 1) == constm1_rtx + && GET_CODE (XEXP (op0, 0)) == ABS && sign_bit_comparison_p) + { + op0 = XEXP (XEXP (op0, 0), 0); + code = (code == LT ? EQ : NE); + continue; + } + break; + + case MINUS: + /* (eq (minus A B) C) -> (eq A (plus B C)) or + (eq B (minus A C)), whichever simplifies. We can only do + this for equality comparisons due to pathological cases involving + overflows. */ + if (equality_comparison_p + && 0 != (tem = simplify_binary_operation (PLUS, mode, + XEXP (op0, 1), op1))) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + + if (equality_comparison_p + && 0 != (tem = simplify_binary_operation (MINUS, mode, + XEXP (op0, 0), op1))) + { + op0 = XEXP (op0, 1); + op1 = tem; + continue; + } + + /* The sign bit of (minus (ashiftrt X C) X), where C is the number + of bits in X minus 1, is one iff X > 0. */ + if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == ASHIFTRT + && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (op0, 0), 1)) == mode_width - 1 + && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1))) + { + op0 = XEXP (op0, 1); + code = (code == GE ? LE : GT); + continue; + } + break; + + case XOR: + /* (eq (xor A B) C) -> (eq A (xor B C)). This is a simplification + if C is zero or B is a constant. */ + if (equality_comparison_p + && 0 != (tem = simplify_binary_operation (XOR, mode, + XEXP (op0, 1), op1))) + { + op0 = XEXP (op0, 0); + op1 = tem; + continue; + } + break; + + case EQ: case NE: + case LT: case LTU: case LE: case LEU: + case GT: case GTU: case GE: case GEU: + /* We can't do anything if OP0 is a condition code value, rather + than an actual data value. */ + if (const_op != 0 +#ifdef HAVE_cc0 + || XEXP (op0, 0) == cc0_rtx +#endif + || GET_MODE_CLASS (GET_MODE (XEXP (op0, 0))) == MODE_CC) + break; + + /* Get the two operands being compared. */ + if (GET_CODE (XEXP (op0, 0)) == COMPARE) + tem = XEXP (XEXP (op0, 0), 0), tem1 = XEXP (XEXP (op0, 0), 1); + else + tem = XEXP (op0, 0), tem1 = XEXP (op0, 1); + + /* Check for the cases where we simply want the result of the + earlier test or the opposite of that result. */ + if (code == NE + || (code == EQ && reversible_comparison_p (op0)) + || (GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT + && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT + && (STORE_FLAG_VALUE + & (((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1)))) + && (code == LT + || (code == GE && reversible_comparison_p (op0))))) + { + code = (code == LT || code == NE + ? GET_CODE (op0) : reverse_condition (GET_CODE (op0))); + op0 = tem, op1 = tem1; + continue; + } + break; + + case IOR: + /* The sign bit of (ior (plus X (const_int -1)) X) is non-zero + iff X <= 0. */ + if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 0)) == PLUS + && XEXP (XEXP (op0, 0), 1) == constm1_rtx + && rtx_equal_p (XEXP (XEXP (op0, 0), 0), XEXP (op0, 1))) + { + op0 = XEXP (op0, 1); + code = (code == GE ? GT : LE); + continue; + } + break; + + case AND: + /* Convert (and (xshift 1 X) Y) to (and (lshiftrt Y X) 1). This + will be converted to a ZERO_EXTRACT later. */ + if (const_op == 0 && equality_comparison_p + && GET_CODE (XEXP (op0, 0)) == ASHIFT + && XEXP (XEXP (op0, 0), 0) == const1_rtx) + { + op0 = simplify_and_const_int + (op0, mode, gen_rtx_combine (LSHIFTRT, mode, + XEXP (op0, 1), + XEXP (XEXP (op0, 0), 1)), + (HOST_WIDE_INT) 1); + continue; + } + + /* If we are comparing (and (lshiftrt X C1) C2) for equality with + zero and X is a comparison and C1 and C2 describe only bits set + in STORE_FLAG_VALUE, we can compare with X. */ + if (const_op == 0 && equality_comparison_p + && mode_width <= HOST_BITS_PER_WIDE_INT + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (XEXP (op0, 0)) == LSHIFTRT + && GET_CODE (XEXP (XEXP (op0, 0), 1)) == CONST_INT + && INTVAL (XEXP (XEXP (op0, 0), 1)) >= 0 + && INTVAL (XEXP (XEXP (op0, 0), 1)) < HOST_BITS_PER_WIDE_INT) + { + mask = ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode)) + << INTVAL (XEXP (XEXP (op0, 0), 1))); + if ((~ STORE_FLAG_VALUE & mask) == 0 + && (GET_RTX_CLASS (GET_CODE (XEXP (XEXP (op0, 0), 0))) == '<' + || ((tem = get_last_value (XEXP (XEXP (op0, 0), 0))) != 0 + && GET_RTX_CLASS (GET_CODE (tem)) == '<'))) + { + op0 = XEXP (XEXP (op0, 0), 0); + continue; + } + } + + /* If we are doing an equality comparison of an AND of a bit equal + to the sign bit, replace this with a LT or GE comparison of + the underlying value. */ + if (equality_comparison_p + && const_op == 0 + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && mode_width <= HOST_BITS_PER_WIDE_INT + && ((INTVAL (XEXP (op0, 1)) & GET_MODE_MASK (mode)) + == (HOST_WIDE_INT) 1 << (mode_width - 1))) + { + op0 = XEXP (op0, 0); + code = (code == EQ ? GE : LT); + continue; + } + + /* If this AND operation is really a ZERO_EXTEND from a narrower + mode, the constant fits within that mode, and this is either an + equality or unsigned comparison, try to do this comparison in + the narrower mode. */ + if ((equality_comparison_p || unsigned_comparison_p) + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && (i = exact_log2 ((INTVAL (XEXP (op0, 1)) + & GET_MODE_MASK (mode)) + + 1)) >= 0 + && const_op >> i == 0 + && (tmode = mode_for_size (i, MODE_INT, 1)) != BLKmode) + { + op0 = gen_lowpart_for_combine (tmode, XEXP (op0, 0)); + continue; + } + break; + + case ASHIFT: + /* If we have (compare (ashift FOO N) (const_int C)) and + the high order N bits of FOO (N+1 if an inequality comparison) + are known to be zero, we can do this by comparing FOO with C + shifted right N bits so long as the low-order N bits of C are + zero. */ + if (GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) >= 0 + && ((INTVAL (XEXP (op0, 1)) + ! equality_comparison_p) + < HOST_BITS_PER_WIDE_INT) + && ((const_op + & (((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1)) == 0) + && mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (op0, 0), mode) + & ~ (mask >> (INTVAL (XEXP (op0, 1)) + + ! equality_comparison_p))) == 0) + { + const_op >>= INTVAL (XEXP (op0, 1)); + op1 = GEN_INT (const_op); + op0 = XEXP (op0, 0); + continue; + } + + /* If we are doing a sign bit comparison, it means we are testing + a particular bit. Convert it to the appropriate AND. */ + if (sign_bit_comparison_p && GET_CODE (XEXP (op0, 1)) == CONST_INT + && mode_width <= HOST_BITS_PER_WIDE_INT) + { + op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0), + ((HOST_WIDE_INT) 1 + << (mode_width - 1 + - INTVAL (XEXP (op0, 1))))); + code = (code == LT ? NE : EQ); + continue; + } + + /* If this an equality comparison with zero and we are shifting + the low bit to the sign bit, we can convert this to an AND of the + low-order bit. */ + if (const_op == 0 && equality_comparison_p + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) == mode_width - 1) + { + op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0), + (HOST_WIDE_INT) 1); + continue; + } + break; + + case ASHIFTRT: + /* If this is an equality comparison with zero, we can do this + as a logical shift, which might be much simpler. */ + if (equality_comparison_p && const_op == 0 + && GET_CODE (XEXP (op0, 1)) == CONST_INT) + { + op0 = simplify_shift_const (NULL_RTX, LSHIFTRT, mode, + XEXP (op0, 0), + INTVAL (XEXP (op0, 1))); + continue; + } + + /* If OP0 is a sign extension and CODE is not an unsigned comparison, + do the comparison in a narrower mode. */ + if (! unsigned_comparison_p + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && GET_CODE (XEXP (op0, 0)) == ASHIFT + && XEXP (op0, 1) == XEXP (XEXP (op0, 0), 1) + && (tmode = mode_for_size (mode_width - INTVAL (XEXP (op0, 1)), + MODE_INT, 1)) != BLKmode + && ((unsigned HOST_WIDE_INT) const_op <= GET_MODE_MASK (tmode) + || ((unsigned HOST_WIDE_INT) - const_op + <= GET_MODE_MASK (tmode)))) + { + op0 = gen_lowpart_for_combine (tmode, XEXP (XEXP (op0, 0), 0)); + continue; + } + + /* ... fall through ... */ + case LSHIFTRT: + /* If we have (compare (xshiftrt FOO N) (const_int C)) and + the low order N bits of FOO are known to be zero, we can do this + by comparing FOO with C shifted left N bits so long as no + overflow occurs. */ + if (GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) >= 0 + && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT + && mode_width <= HOST_BITS_PER_WIDE_INT + && (nonzero_bits (XEXP (op0, 0), mode) + & (((HOST_WIDE_INT) 1 << INTVAL (XEXP (op0, 1))) - 1)) == 0 + && (const_op == 0 + || (floor_log2 (const_op) + INTVAL (XEXP (op0, 1)) + < mode_width))) + { + const_op <<= INTVAL (XEXP (op0, 1)); + op1 = GEN_INT (const_op); + op0 = XEXP (op0, 0); + continue; + } + + /* If we are using this shift to extract just the sign bit, we + can replace this with an LT or GE comparison. */ + if (const_op == 0 + && (equality_comparison_p || sign_bit_comparison_p) + && GET_CODE (XEXP (op0, 1)) == CONST_INT + && INTVAL (XEXP (op0, 1)) == mode_width - 1) + { + op0 = XEXP (op0, 0); + code = (code == NE || code == GT ? LT : GE); + continue; + } + break; + } + + break; + } + + /* Now make any compound operations involved in this comparison. Then, + check for an outmost SUBREG on OP0 that isn't doing anything or is + paradoxical. The latter case can only occur when it is known that the + "extra" bits will be zero. Therefore, it is safe to remove the SUBREG. + We can never remove a SUBREG for a non-equality comparison because the + sign bit is in a different place in the underlying object. */ + + op0 = make_compound_operation (op0, op1 == const0_rtx ? COMPARE : SET); + op1 = make_compound_operation (op1, SET); + + if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0) + && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT + && (code == NE || code == EQ) + && ((GET_MODE_SIZE (GET_MODE (op0)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0)))))) + { + op0 = SUBREG_REG (op0); + op1 = gen_lowpart_for_combine (GET_MODE (op0), op1); + } + + else if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0) + && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT + && (code == NE || code == EQ) + && (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (op0))) + <= HOST_BITS_PER_WIDE_INT) + && (nonzero_bits (SUBREG_REG (op0), GET_MODE (SUBREG_REG (op0))) + & ~ GET_MODE_MASK (GET_MODE (op0))) == 0 + && (tem = gen_lowpart_for_combine (GET_MODE (SUBREG_REG (op0)), + op1), + (nonzero_bits (tem, GET_MODE (SUBREG_REG (op0))) + & ~ GET_MODE_MASK (GET_MODE (op0))) == 0)) + op0 = SUBREG_REG (op0), op1 = tem; + + /* We now do the opposite procedure: Some machines don't have compare + insns in all modes. If OP0's mode is an integer mode smaller than a + word and we can't do a compare in that mode, see if there is a larger + mode for which we can do the compare. There are a number of cases in + which we can use the wider mode. */ + + mode = GET_MODE (op0); + if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_SIZE (mode) < UNITS_PER_WORD + && cmp_optab->handlers[(int) mode].insn_code == CODE_FOR_nothing) + for (tmode = GET_MODE_WIDER_MODE (mode); + (tmode != VOIDmode + && GET_MODE_BITSIZE (tmode) <= HOST_BITS_PER_WIDE_INT); + tmode = GET_MODE_WIDER_MODE (tmode)) + if (cmp_optab->handlers[(int) tmode].insn_code != CODE_FOR_nothing) + { + /* If the only nonzero bits in OP0 and OP1 are those in the + narrower mode and this is an equality or unsigned comparison, + we can use the wider mode. Similarly for sign-extended + values, in which case it is true for all comparisons. */ + if (((code == EQ || code == NE + || code == GEU || code == GTU || code == LEU || code == LTU) + && (nonzero_bits (op0, tmode) & ~ GET_MODE_MASK (mode)) == 0 + && (nonzero_bits (op1, tmode) & ~ GET_MODE_MASK (mode)) == 0) + || ((num_sign_bit_copies (op0, tmode) + > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode)) + && (num_sign_bit_copies (op1, tmode) + > GET_MODE_BITSIZE (tmode) - GET_MODE_BITSIZE (mode)))) + { + op0 = gen_lowpart_for_combine (tmode, op0); + op1 = gen_lowpart_for_combine (tmode, op1); + break; + } + + /* If this is a test for negative, we can make an explicit + test of the sign bit. */ + + if (op1 == const0_rtx && (code == LT || code == GE) + && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) + { + op0 = gen_binary (AND, tmode, + gen_lowpart_for_combine (tmode, op0), + GEN_INT ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (mode) - 1))); + code = (code == LT) ? NE : EQ; + break; + } + } + +#ifdef CANONICALIZE_COMPARISON + /* If this machine only supports a subset of valid comparisons, see if we + can convert an unsupported one into a supported one. */ + CANONICALIZE_COMPARISON (code, op0, op1); +#endif + + *pop0 = op0; + *pop1 = op1; + + return code; +} + +/* Return 1 if we know that X, a comparison operation, is not operating + on a floating-point value or is EQ or NE, meaning that we can safely + reverse it. */ + +static int +reversible_comparison_p (x) + rtx x; +{ + if (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || flag_fast_math + || GET_CODE (x) == NE || GET_CODE (x) == EQ) + return 1; + + switch (GET_MODE_CLASS (GET_MODE (XEXP (x, 0)))) + { + case MODE_INT: + case MODE_PARTIAL_INT: + case MODE_COMPLEX_INT: + return 1; + + case MODE_CC: + /* If the mode of the condition codes tells us that this is safe, + we need look no further. */ + if (REVERSIBLE_CC_MODE (GET_MODE (XEXP (x, 0)))) + return 1; + + /* Otherwise try and find where the condition codes were last set and + use that. */ + x = get_last_value (XEXP (x, 0)); + return (x && GET_CODE (x) == COMPARE + && ! FLOAT_MODE_P (GET_MODE (XEXP (x, 0)))); + } + + return 0; +} + +/* Utility function for following routine. Called when X is part of a value + being stored into reg_last_set_value. Sets reg_last_set_table_tick + for each register mentioned. Similar to mention_regs in cse.c */ + +static void +update_table_tick (x) + rtx x; +{ + register enum rtx_code code = GET_CODE (x); + register char *fmt = GET_RTX_FORMAT (code); + register int i; + + if (code == REG) + { + int regno = REGNO (x); + int endregno = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); + + for (i = regno; i < endregno; i++) + reg_last_set_table_tick[i] = label_tick; + + return; + } + + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + /* Note that we can't have an "E" in values stored; see + get_last_value_validate. */ + if (fmt[i] == 'e') + update_table_tick (XEXP (x, i)); +} + +/* Record that REG is set to VALUE in insn INSN. If VALUE is zero, we + are saying that the register is clobbered and we no longer know its + value. If INSN is zero, don't update reg_last_set; this is only permitted + with VALUE also zero and is used to invalidate the register. */ + +static void +record_value_for_reg (reg, insn, value) + rtx reg; + rtx insn; + rtx value; +{ + int regno = REGNO (reg); + int endregno = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (reg)) : 1); + int i; + + /* If VALUE contains REG and we have a previous value for REG, substitute + the previous value. */ + if (value && insn && reg_overlap_mentioned_p (reg, value)) + { + rtx tem; + + /* Set things up so get_last_value is allowed to see anything set up to + our insn. */ + subst_low_cuid = INSN_CUID (insn); + tem = get_last_value (reg); + + if (tem) + value = replace_rtx (copy_rtx (value), reg, tem); + } + + /* For each register modified, show we don't know its value, that + we don't know about its bitwise content, that its value has been + updated, and that we don't know the location of the death of the + register. */ + for (i = regno; i < endregno; i ++) + { + if (insn) + reg_last_set[i] = insn; + reg_last_set_value[i] = 0; + reg_last_set_mode[i] = 0; + reg_last_set_nonzero_bits[i] = 0; + reg_last_set_sign_bit_copies[i] = 0; + reg_last_death[i] = 0; + } + + /* Mark registers that are being referenced in this value. */ + if (value) + update_table_tick (value); + + /* Now update the status of each register being set. + If someone is using this register in this block, set this register + to invalid since we will get confused between the two lives in this + basic block. This makes using this register always invalid. In cse, we + scan the table to invalidate all entries using this register, but this + is too much work for us. */ + + for (i = regno; i < endregno; i++) + { + reg_last_set_label[i] = label_tick; + if (value && reg_last_set_table_tick[i] == label_tick) + reg_last_set_invalid[i] = 1; + else + reg_last_set_invalid[i] = 0; + } + + /* The value being assigned might refer to X (like in "x++;"). In that + case, we must replace it with (clobber (const_int 0)) to prevent + infinite loops. */ + if (value && ! get_last_value_validate (&value, + reg_last_set_label[regno], 0)) + { + value = copy_rtx (value); + if (! get_last_value_validate (&value, reg_last_set_label[regno], 1)) + value = 0; + } + + /* For the main register being modified, update the value, the mode, the + nonzero bits, and the number of sign bit copies. */ + + reg_last_set_value[regno] = value; + + if (value) + { + subst_low_cuid = INSN_CUID (insn); + reg_last_set_mode[regno] = GET_MODE (reg); + reg_last_set_nonzero_bits[regno] = nonzero_bits (value, GET_MODE (reg)); + reg_last_set_sign_bit_copies[regno] + = num_sign_bit_copies (value, GET_MODE (reg)); + } +} + +/* Used for communication between the following two routines. */ +static rtx record_dead_insn; + +/* Called via note_stores from record_dead_and_set_regs to handle one + SET or CLOBBER in an insn. */ + +static void +record_dead_and_set_regs_1 (dest, setter) + rtx dest, setter; +{ + if (GET_CODE (dest) == SUBREG) + dest = SUBREG_REG (dest); + + if (GET_CODE (dest) == REG) + { + /* If we are setting the whole register, we know its value. Otherwise + show that we don't know the value. We can handle SUBREG in + some cases. */ + if (GET_CODE (setter) == SET && dest == SET_DEST (setter)) + record_value_for_reg (dest, record_dead_insn, SET_SRC (setter)); + else if (GET_CODE (setter) == SET + && GET_CODE (SET_DEST (setter)) == SUBREG + && SUBREG_REG (SET_DEST (setter)) == dest + && GET_MODE_BITSIZE (GET_MODE (dest)) <= BITS_PER_WORD + && subreg_lowpart_p (SET_DEST (setter))) + record_value_for_reg (dest, record_dead_insn, + gen_lowpart_for_combine (GET_MODE (dest), + SET_SRC (setter))); + else + record_value_for_reg (dest, record_dead_insn, NULL_RTX); + } + else if (GET_CODE (dest) == MEM + /* Ignore pushes, they clobber nothing. */ + && ! push_operand (dest, GET_MODE (dest))) + mem_last_set = INSN_CUID (record_dead_insn); +} + +/* Update the records of when each REG was most recently set or killed + for the things done by INSN. This is the last thing done in processing + INSN in the combiner loop. + + We update reg_last_set, reg_last_set_value, reg_last_set_mode, + reg_last_set_nonzero_bits, reg_last_set_sign_bit_copies, reg_last_death, + and also the similar information mem_last_set (which insn most recently + modified memory) and last_call_cuid (which insn was the most recent + subroutine call). */ + +static void +record_dead_and_set_regs (insn) + rtx insn; +{ + register rtx link; + int i; + + for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) + { + if (REG_NOTE_KIND (link) == REG_DEAD + && GET_CODE (XEXP (link, 0)) == REG) + { + int regno = REGNO (XEXP (link, 0)); + int endregno + = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (XEXP (link, 0))) + : 1); + + for (i = regno; i < endregno; i++) + reg_last_death[i] = insn; + } + else if (REG_NOTE_KIND (link) == REG_INC) + record_value_for_reg (XEXP (link, 0), insn, NULL_RTX); + } + + if (GET_CODE (insn) == CALL_INSN) + { + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if (call_used_regs[i]) + { + reg_last_set_value[i] = 0; + reg_last_set_mode[i] = 0; + reg_last_set_nonzero_bits[i] = 0; + reg_last_set_sign_bit_copies[i] = 0; + reg_last_death[i] = 0; + } + + last_call_cuid = mem_last_set = INSN_CUID (insn); + } + + record_dead_insn = insn; + note_stores (PATTERN (insn), record_dead_and_set_regs_1); +} + +/* Utility routine for the following function. Verify that all the registers + mentioned in *LOC are valid when *LOC was part of a value set when + label_tick == TICK. Return 0 if some are not. + + If REPLACE is non-zero, replace the invalid reference with + (clobber (const_int 0)) and return 1. This replacement is useful because + we often can get useful information about the form of a value (e.g., if + it was produced by a shift that always produces -1 or 0) even though + we don't know exactly what registers it was produced from. */ + +static int +get_last_value_validate (loc, tick, replace) + rtx *loc; + int tick; + int replace; +{ + rtx x = *loc; + char *fmt = GET_RTX_FORMAT (GET_CODE (x)); + int len = GET_RTX_LENGTH (GET_CODE (x)); + int i; + + if (GET_CODE (x) == REG) + { + int regno = REGNO (x); + int endregno = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); + int j; + + for (j = regno; j < endregno; j++) + if (reg_last_set_invalid[j] + /* If this is a pseudo-register that was only set once, it is + always valid. */ + || (! (regno >= FIRST_PSEUDO_REGISTER && reg_n_sets[regno] == 1) + && reg_last_set_label[j] > tick)) + { + if (replace) + *loc = gen_rtx (CLOBBER, GET_MODE (x), const0_rtx); + return replace; + } + + return 1; + } + + for (i = 0; i < len; i++) + if ((fmt[i] == 'e' + && get_last_value_validate (&XEXP (x, i), tick, replace) == 0) + /* Don't bother with these. They shouldn't occur anyway. */ + || fmt[i] == 'E') + return 0; + + /* If we haven't found a reason for it to be invalid, it is valid. */ + return 1; +} + +/* Get the last value assigned to X, if known. Some registers + in the value may be replaced with (clobber (const_int 0)) if their value + is known longer known reliably. */ + +static rtx +get_last_value (x) + rtx x; +{ + int regno; + rtx value; + + /* If this is a non-paradoxical SUBREG, get the value of its operand and + then convert it to the desired mode. If this is a paradoxical SUBREG, + we cannot predict what values the "extra" bits might have. */ + if (GET_CODE (x) == SUBREG + && subreg_lowpart_p (x) + && (GET_MODE_SIZE (GET_MODE (x)) + <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) + && (value = get_last_value (SUBREG_REG (x))) != 0) + return gen_lowpart_for_combine (GET_MODE (x), value); + + if (GET_CODE (x) != REG) + return 0; + + regno = REGNO (x); + value = reg_last_set_value[regno]; + + /* If we don't have a value or if it isn't for this basic block, return 0. */ + + if (value == 0 + || (reg_n_sets[regno] != 1 + && reg_last_set_label[regno] != label_tick)) + return 0; + + /* If the value was set in a later insn than the ones we are processing, + we can't use it even if the register was only set once, but make a quick + check to see if the previous insn set it to something. This is commonly + the case when the same pseudo is used by repeated insns. + + This does not work if there exists an instruction which is temporarily + not on the insn chain. */ + + if (INSN_CUID (reg_last_set[regno]) >= subst_low_cuid) + { + rtx insn, set; + + /* We can not do anything useful in this case, because there is + an instruction which is not on the insn chain. */ + if (subst_prev_insn) + return 0; + + /* Skip over USE insns. They are not useful here, and they may have + been made by combine, in which case they do not have a INSN_CUID + value. We can't use prev_real_insn, because that would incorrectly + take us backwards across labels. Skip over BARRIERs also, since + they could have been made by combine. If we see one, we must be + optimizing dead code, so it doesn't matter what we do. */ + for (insn = prev_nonnote_insn (subst_insn); + insn && ((GET_CODE (insn) == INSN + && GET_CODE (PATTERN (insn)) == USE) + || GET_CODE (insn) == BARRIER + || INSN_CUID (insn) >= subst_low_cuid); + insn = prev_nonnote_insn (insn)) + ; + + if (insn + && (set = single_set (insn)) != 0 + && rtx_equal_p (SET_DEST (set), x)) + { + value = SET_SRC (set); + + /* Make sure that VALUE doesn't reference X. Replace any + explicit references with a CLOBBER. If there are any remaining + references (rare), don't use the value. */ + + if (reg_mentioned_p (x, value)) + value = replace_rtx (copy_rtx (value), x, + gen_rtx (CLOBBER, GET_MODE (x), const0_rtx)); + + if (reg_overlap_mentioned_p (x, value)) + return 0; + } + else + return 0; + } + + /* If the value has all its registers valid, return it. */ + if (get_last_value_validate (&value, reg_last_set_label[regno], 0)) + return value; + + /* Otherwise, make a copy and replace any invalid register with + (clobber (const_int 0)). If that fails for some reason, return 0. */ + + value = copy_rtx (value); + if (get_last_value_validate (&value, reg_last_set_label[regno], 1)) + return value; + + return 0; +} + +/* Return nonzero if expression X refers to a REG or to memory + that is set in an instruction more recent than FROM_CUID. */ + +static int +use_crosses_set_p (x, from_cuid) + register rtx x; + int from_cuid; +{ + register char *fmt; + register int i; + register enum rtx_code code = GET_CODE (x); + + if (code == REG) + { + register int regno = REGNO (x); + int endreg = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); + +#ifdef PUSH_ROUNDING + /* Don't allow uses of the stack pointer to be moved, + because we don't know whether the move crosses a push insn. */ + if (regno == STACK_POINTER_REGNUM) + return 1; +#endif + for (;regno < endreg; regno++) + if (reg_last_set[regno] + && INSN_CUID (reg_last_set[regno]) > from_cuid) + return 1; + return 0; + } + + if (code == MEM && mem_last_set > from_cuid) + return 1; + + fmt = GET_RTX_FORMAT (code); + + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'E') + { + register int j; + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + if (use_crosses_set_p (XVECEXP (x, i, j), from_cuid)) + return 1; + } + else if (fmt[i] == 'e' + && use_crosses_set_p (XEXP (x, i), from_cuid)) + return 1; + } + return 0; +} + +/* Define three variables used for communication between the following + routines. */ + +static int reg_dead_regno, reg_dead_endregno; +static int reg_dead_flag; + +/* Function called via note_stores from reg_dead_at_p. + + If DEST is within [reg_dead_regno, reg_dead_endregno), set + reg_dead_flag to 1 if X is a CLOBBER and to -1 it is a SET. */ + +static void +reg_dead_at_p_1 (dest, x) + rtx dest; + rtx x; +{ + int regno, endregno; + + if (GET_CODE (dest) != REG) + return; + + regno = REGNO (dest); + endregno = regno + (regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (regno, GET_MODE (dest)) : 1); + + if (reg_dead_endregno > regno && reg_dead_regno < endregno) + reg_dead_flag = (GET_CODE (x) == CLOBBER) ? 1 : -1; +} + +/* Return non-zero if REG is known to be dead at INSN. + + We scan backwards from INSN. If we hit a REG_DEAD note or a CLOBBER + referencing REG, it is dead. If we hit a SET referencing REG, it is + live. Otherwise, see if it is live or dead at the start of the basic + block we are in. Hard regs marked as being live in NEWPAT_USED_REGS + must be assumed to be always live. */ + +static int +reg_dead_at_p (reg, insn) + rtx reg; + rtx insn; +{ + int block, i; + + /* Set variables for reg_dead_at_p_1. */ + reg_dead_regno = REGNO (reg); + reg_dead_endregno = reg_dead_regno + (reg_dead_regno < FIRST_PSEUDO_REGISTER + ? HARD_REGNO_NREGS (reg_dead_regno, + GET_MODE (reg)) + : 1); + + reg_dead_flag = 0; + + /* Check that reg isn't mentioned in NEWPAT_USED_REGS. */ + if (reg_dead_regno < FIRST_PSEUDO_REGISTER) + { + for (i = reg_dead_regno; i < reg_dead_endregno; i++) + if (TEST_HARD_REG_BIT (newpat_used_regs, i)) + return 0; + } + + /* Scan backwards until we find a REG_DEAD note, SET, CLOBBER, label, or + beginning of function. */ + for (; insn && GET_CODE (insn) != CODE_LABEL && GET_CODE (insn) != BARRIER; + insn = prev_nonnote_insn (insn)) + { + note_stores (PATTERN (insn), reg_dead_at_p_1); + if (reg_dead_flag) + return reg_dead_flag == 1 ? 1 : 0; + + if (find_regno_note (insn, REG_DEAD, reg_dead_regno)) + return 1; + } + + /* Get the basic block number that we were in. */ + if (insn == 0) + block = 0; + else + { + for (block = 0; block < n_basic_blocks; block++) + if (insn == basic_block_head[block]) + break; + + if (block == n_basic_blocks) + return 0; + } + + for (i = reg_dead_regno; i < reg_dead_endregno; i++) + if (basic_block_live_at_start[block][i / REGSET_ELT_BITS] + & ((REGSET_ELT_TYPE) 1 << (i % REGSET_ELT_BITS))) + return 0; + + return 1; +} + +/* Note hard registers in X that are used. This code is similar to + that in flow.c, but much simpler since we don't care about pseudos. */ + +static void +mark_used_regs_combine (x) + rtx x; +{ + register RTX_CODE code = GET_CODE (x); + register int regno; + int i; + + switch (code) + { + case LABEL_REF: + case SYMBOL_REF: + case CONST_INT: + case CONST: + case CONST_DOUBLE: + case PC: + case ADDR_VEC: + case ADDR_DIFF_VEC: + case ASM_INPUT: +#ifdef HAVE_cc0 + /* CC0 must die in the insn after it is set, so we don't need to take + special note of it here. */ + case CC0: +#endif + return; + + case CLOBBER: + /* If we are clobbering a MEM, mark any hard registers inside the + address as used. */ + if (GET_CODE (XEXP (x, 0)) == MEM) + mark_used_regs_combine (XEXP (XEXP (x, 0), 0)); + return; + + case REG: + regno = REGNO (x); + /* A hard reg in a wide mode may really be multiple registers. + If so, mark all of them just like the first. */ + if (regno < FIRST_PSEUDO_REGISTER) + { + /* None of this applies to the stack, frame or arg pointers */ + if (regno == STACK_POINTER_REGNUM +#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM + || regno == HARD_FRAME_POINTER_REGNUM +#endif +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + || (regno == ARG_POINTER_REGNUM && fixed_regs[regno]) +#endif + || regno == FRAME_POINTER_REGNUM) + return; + + i = HARD_REGNO_NREGS (regno, GET_MODE (x)); + while (i-- > 0) + SET_HARD_REG_BIT (newpat_used_regs, regno + i); + } + return; + + case SET: + { + /* If setting a MEM, or a SUBREG of a MEM, then note any hard regs in + the address. */ + register rtx testreg = SET_DEST (x); + + while (GET_CODE (testreg) == SUBREG + || GET_CODE (testreg) == ZERO_EXTRACT + || GET_CODE (testreg) == SIGN_EXTRACT + || GET_CODE (testreg) == STRICT_LOW_PART) + testreg = XEXP (testreg, 0); + + if (GET_CODE (testreg) == MEM) + mark_used_regs_combine (XEXP (testreg, 0)); + + mark_used_regs_combine (SET_SRC (x)); + return; + } + } + + /* Recursively scan the operands of this expression. */ + + { + register char *fmt = GET_RTX_FORMAT (code); + + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'e') + mark_used_regs_combine (XEXP (x, i)); + else if (fmt[i] == 'E') + { + register int j; + + for (j = 0; j < XVECLEN (x, i); j++) + mark_used_regs_combine (XVECEXP (x, i, j)); + } + } + } +} + + +/* Remove register number REGNO from the dead registers list of INSN. + + Return the note used to record the death, if there was one. */ + +rtx +remove_death (regno, insn) + int regno; + rtx insn; +{ + register rtx note = find_regno_note (insn, REG_DEAD, regno); + + if (note) + { + reg_n_deaths[regno]--; + remove_note (insn, note); + } + + return note; +} + +/* For each register (hardware or pseudo) used within expression X, if its + death is in an instruction with cuid between FROM_CUID (inclusive) and + TO_INSN (exclusive), put a REG_DEAD note for that register in the + list headed by PNOTES. + + This is done when X is being merged by combination into TO_INSN. These + notes will then be distributed as needed. */ + +static void +move_deaths (x, from_cuid, to_insn, pnotes) + rtx x; + int from_cuid; + rtx to_insn; + rtx *pnotes; +{ + register char *fmt; + register int len, i; + register enum rtx_code code = GET_CODE (x); + + if (code == REG) + { + register int regno = REGNO (x); + register rtx where_dead = reg_last_death[regno]; + register rtx before_dead, after_dead; + + /* WHERE_DEAD could be a USE insn made by combine, so first we + make sure that we have insns with valid INSN_CUID values. */ + before_dead = where_dead; + while (before_dead && INSN_UID (before_dead) > max_uid_cuid) + before_dead = PREV_INSN (before_dead); + after_dead = where_dead; + while (after_dead && INSN_UID (after_dead) > max_uid_cuid) + after_dead = NEXT_INSN (after_dead); + + if (before_dead && after_dead + && INSN_CUID (before_dead) >= from_cuid + && (INSN_CUID (after_dead) < INSN_CUID (to_insn) + || (where_dead != after_dead + && INSN_CUID (after_dead) == INSN_CUID (to_insn)))) + { + rtx note = remove_death (regno, where_dead); + + /* It is possible for the call above to return 0. This can occur + when reg_last_death points to I2 or I1 that we combined with. + In that case make a new note. + + We must also check for the case where X is a hard register + and NOTE is a death note for a range of hard registers + including X. In that case, we must put REG_DEAD notes for + the remaining registers in place of NOTE. */ + + if (note != 0 && regno < FIRST_PSEUDO_REGISTER + && (GET_MODE_SIZE (GET_MODE (XEXP (note, 0))) + != GET_MODE_SIZE (GET_MODE (x)))) + { + int deadregno = REGNO (XEXP (note, 0)); + int deadend + = (deadregno + HARD_REGNO_NREGS (deadregno, + GET_MODE (XEXP (note, 0)))); + int ourend = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); + int i; + + for (i = deadregno; i < deadend; i++) + if (i < regno || i >= ourend) + REG_NOTES (where_dead) + = gen_rtx (EXPR_LIST, REG_DEAD, + gen_rtx (REG, reg_raw_mode[i], i), + REG_NOTES (where_dead)); + } + /* If we didn't find any note, and we have a multi-reg hard + register, then to be safe we must check for REG_DEAD notes + for each register other than the first. They could have + their own REG_DEAD notes lying around. */ + else if (note == 0 && regno < FIRST_PSEUDO_REGISTER + && HARD_REGNO_NREGS (regno, GET_MODE (x)) > 1) + { + int ourend = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); + int i; + rtx oldnotes = 0; + + for (i = regno + 1; i < ourend; i++) + move_deaths (gen_rtx (REG, reg_raw_mode[i], i), + from_cuid, to_insn, &oldnotes); + } + + if (note != 0 && GET_MODE (XEXP (note, 0)) == GET_MODE (x)) + { + XEXP (note, 1) = *pnotes; + *pnotes = note; + } + else + *pnotes = gen_rtx (EXPR_LIST, REG_DEAD, x, *pnotes); + + reg_n_deaths[regno]++; + } + + return; + } + + else if (GET_CODE (x) == SET) + { + rtx dest = SET_DEST (x); + + move_deaths (SET_SRC (x), from_cuid, to_insn, pnotes); + + /* In the case of a ZERO_EXTRACT, a STRICT_LOW_PART, or a SUBREG + that accesses one word of a multi-word item, some + piece of everything register in the expression is used by + this insn, so remove any old death. */ + + if (GET_CODE (dest) == ZERO_EXTRACT + || GET_CODE (dest) == STRICT_LOW_PART + || (GET_CODE (dest) == SUBREG + && (((GET_MODE_SIZE (GET_MODE (dest)) + + UNITS_PER_WORD - 1) / UNITS_PER_WORD) + == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) + + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))) + { + move_deaths (dest, from_cuid, to_insn, pnotes); + return; + } + + /* If this is some other SUBREG, we know it replaces the entire + value, so use that as the destination. */ + if (GET_CODE (dest) == SUBREG) + dest = SUBREG_REG (dest); + + /* If this is a MEM, adjust deaths of anything used in the address. + For a REG (the only other possibility), the entire value is + being replaced so the old value is not used in this insn. */ + + if (GET_CODE (dest) == MEM) + move_deaths (XEXP (dest, 0), from_cuid, to_insn, pnotes); + return; + } + + else if (GET_CODE (x) == CLOBBER) + return; + + len = GET_RTX_LENGTH (code); + fmt = GET_RTX_FORMAT (code); + + for (i = 0; i < len; i++) + { + if (fmt[i] == 'E') + { + register int j; + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + move_deaths (XVECEXP (x, i, j), from_cuid, to_insn, pnotes); + } + else if (fmt[i] == 'e') + move_deaths (XEXP (x, i), from_cuid, to_insn, pnotes); + } +} + +/* Return 1 if X is the target of a bit-field assignment in BODY, the + pattern of an insn. X must be a REG. */ + +static int +reg_bitfield_target_p (x, body) + rtx x; + rtx body; +{ + int i; + + if (GET_CODE (body) == SET) + { + rtx dest = SET_DEST (body); + rtx target; + int regno, tregno, endregno, endtregno; + + if (GET_CODE (dest) == ZERO_EXTRACT) + target = XEXP (dest, 0); + else if (GET_CODE (dest) == STRICT_LOW_PART) + target = SUBREG_REG (XEXP (dest, 0)); + else + return 0; + + if (GET_CODE (target) == SUBREG) + target = SUBREG_REG (target); + + if (GET_CODE (target) != REG) + return 0; + + tregno = REGNO (target), regno = REGNO (x); + if (tregno >= FIRST_PSEUDO_REGISTER || regno >= FIRST_PSEUDO_REGISTER) + return target == x; + + endtregno = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (target)); + endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); + + return endregno > tregno && regno < endtregno; + } + + else if (GET_CODE (body) == PARALLEL) + for (i = XVECLEN (body, 0) - 1; i >= 0; i--) + if (reg_bitfield_target_p (x, XVECEXP (body, 0, i))) + return 1; + + return 0; +} + +/* Given a chain of REG_NOTES originally from FROM_INSN, try to place them + as appropriate. I3 and I2 are the insns resulting from the combination + insns including FROM (I2 may be zero). + + ELIM_I2 and ELIM_I1 are either zero or registers that we know will + not need REG_DEAD notes because they are being substituted for. This + saves searching in the most common cases. + + Each note in the list is either ignored or placed on some insns, depending + on the type of note. */ + +static void +distribute_notes (notes, from_insn, i3, i2, elim_i2, elim_i1) + rtx notes; + rtx from_insn; + rtx i3, i2; + rtx elim_i2, elim_i1; +{ + rtx note, next_note; + rtx tem; + + for (note = notes; note; note = next_note) + { + rtx place = 0, place2 = 0; + + /* If this NOTE references a pseudo register, ensure it references + the latest copy of that register. */ + if (XEXP (note, 0) && GET_CODE (XEXP (note, 0)) == REG + && REGNO (XEXP (note, 0)) >= FIRST_PSEUDO_REGISTER) + XEXP (note, 0) = regno_reg_rtx[REGNO (XEXP (note, 0))]; + + next_note = XEXP (note, 1); + switch (REG_NOTE_KIND (note)) + { + case REG_UNUSED: + /* Any clobbers for i3 may still exist, and so we must process + REG_UNUSED notes from that insn. + + Any clobbers from i2 or i1 can only exist if they were added by + recog_for_combine. In that case, recog_for_combine created the + necessary REG_UNUSED notes. Trying to keep any original + REG_UNUSED notes from these insns can cause incorrect output + if it is for the same register as the original i3 dest. + In that case, we will notice that the register is set in i3, + and then add a REG_UNUSED note for the destination of i3, which + is wrong. However, it is possible to have REG_UNUSED notes from + i2 or i1 for register which were both used and clobbered, so + we keep notes from i2 or i1 if they will turn into REG_DEAD + notes. */ + + /* If this register is set or clobbered in I3, put the note there + unless there is one already. */ + if (reg_set_p (XEXP (note, 0), PATTERN (i3))) + { + if (from_insn != i3) + break; + + if (! (GET_CODE (XEXP (note, 0)) == REG + ? find_regno_note (i3, REG_UNUSED, REGNO (XEXP (note, 0))) + : find_reg_note (i3, REG_UNUSED, XEXP (note, 0)))) + place = i3; + } + /* Otherwise, if this register is used by I3, then this register + now dies here, so we must put a REG_DEAD note here unless there + is one already. */ + else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3)) + && ! (GET_CODE (XEXP (note, 0)) == REG + ? find_regno_note (i3, REG_DEAD, REGNO (XEXP (note, 0))) + : find_reg_note (i3, REG_DEAD, XEXP (note, 0)))) + { + PUT_REG_NOTE_KIND (note, REG_DEAD); + place = i3; + } + break; + + case REG_EQUAL: + case REG_EQUIV: + case REG_NONNEG: + /* These notes say something about results of an insn. We can + only support them if they used to be on I3 in which case they + remain on I3. Otherwise they are ignored. + + If the note refers to an expression that is not a constant, we + must also ignore the note since we cannot tell whether the + equivalence is still true. It might be possible to do + slightly better than this (we only have a problem if I2DEST + or I1DEST is present in the expression), but it doesn't + seem worth the trouble. */ + + if (from_insn == i3 + && (XEXP (note, 0) == 0 || CONSTANT_P (XEXP (note, 0)))) + place = i3; + break; + + case REG_INC: + case REG_NO_CONFLICT: + case REG_LABEL: + /* These notes say something about how a register is used. They must + be present on any use of the register in I2 or I3. */ + if (reg_mentioned_p (XEXP (note, 0), PATTERN (i3))) + place = i3; + + if (i2 && reg_mentioned_p (XEXP (note, 0), PATTERN (i2))) + { + if (place) + place2 = i2; + else + place = i2; + } + break; + + case REG_WAS_0: + /* It is too much trouble to try to see if this note is still + correct in all situations. It is better to simply delete it. */ + break; + + case REG_RETVAL: + /* If the insn previously containing this note still exists, + put it back where it was. Otherwise move it to the previous + insn. Adjust the corresponding REG_LIBCALL note. */ + if (GET_CODE (from_insn) != NOTE) + place = from_insn; + else + { + tem = find_reg_note (XEXP (note, 0), REG_LIBCALL, NULL_RTX); + place = prev_real_insn (from_insn); + if (tem && place) + XEXP (tem, 0) = place; + } + break; + + case REG_LIBCALL: + /* This is handled similarly to REG_RETVAL. */ + if (GET_CODE (from_insn) != NOTE) + place = from_insn; + else + { + tem = find_reg_note (XEXP (note, 0), REG_RETVAL, NULL_RTX); + place = next_real_insn (from_insn); + if (tem && place) + XEXP (tem, 0) = place; + } + break; + + case REG_DEAD: + /* If the register is used as an input in I3, it dies there. + Similarly for I2, if it is non-zero and adjacent to I3. + + If the register is not used as an input in either I3 or I2 + and it is not one of the registers we were supposed to eliminate, + there are two possibilities. We might have a non-adjacent I2 + or we might have somehow eliminated an additional register + from a computation. For example, we might have had A & B where + we discover that B will always be zero. In this case we will + eliminate the reference to A. + + In both cases, we must search to see if we can find a previous + use of A and put the death note there. */ + + if (from_insn + && GET_CODE (from_insn) == CALL_INSN + && find_reg_fusage (from_insn, USE, XEXP (note, 0))) + place = from_insn; + else if (reg_referenced_p (XEXP (note, 0), PATTERN (i3))) + place = i3; + else if (i2 != 0 && next_nonnote_insn (i2) == i3 + && reg_referenced_p (XEXP (note, 0), PATTERN (i2))) + place = i2; + + if (XEXP (note, 0) == elim_i2 || XEXP (note, 0) == elim_i1) + break; + + /* If the register is used in both I2 and I3 and it dies in I3, + we might have added another reference to it. If reg_n_refs + was 2, bump it to 3. This has to be correct since the + register must have been set somewhere. The reason this is + done is because local-alloc.c treats 2 references as a + special case. */ + + if (place == i3 && i2 != 0 && GET_CODE (XEXP (note, 0)) == REG + && reg_n_refs[REGNO (XEXP (note, 0))]== 2 + && reg_referenced_p (XEXP (note, 0), PATTERN (i2))) + reg_n_refs[REGNO (XEXP (note, 0))] = 3; + + if (place == 0) + { + for (tem = prev_nonnote_insn (i3); + place == 0 && tem + && (GET_CODE (tem) == INSN || GET_CODE (tem) == CALL_INSN); + tem = prev_nonnote_insn (tem)) + { + /* If the register is being set at TEM, see if that is all + TEM is doing. If so, delete TEM. Otherwise, make this + into a REG_UNUSED note instead. */ + if (reg_set_p (XEXP (note, 0), PATTERN (tem))) + { + rtx set = single_set (tem); + + /* Verify that it was the set, and not a clobber that + modified the register. */ + + if (set != 0 && ! side_effects_p (SET_SRC (set)) + && (rtx_equal_p (XEXP (note, 0), SET_DEST (set)) + || (GET_CODE (SET_DEST (set)) == SUBREG + && rtx_equal_p (XEXP (note, 0), + XEXP (SET_DEST (set), 0))))) + { + /* Move the notes and links of TEM elsewhere. + This might delete other dead insns recursively. + First set the pattern to something that won't use + any register. */ + + PATTERN (tem) = pc_rtx; + + distribute_notes (REG_NOTES (tem), tem, tem, + NULL_RTX, NULL_RTX, NULL_RTX); + distribute_links (LOG_LINKS (tem)); + + PUT_CODE (tem, NOTE); + NOTE_LINE_NUMBER (tem) = NOTE_INSN_DELETED; + NOTE_SOURCE_FILE (tem) = 0; + } + else + { + PUT_REG_NOTE_KIND (note, REG_UNUSED); + + /* If there isn't already a REG_UNUSED note, put one + here. */ + if (! find_regno_note (tem, REG_UNUSED, + REGNO (XEXP (note, 0)))) + place = tem; + break; + } + } + else if (reg_referenced_p (XEXP (note, 0), PATTERN (tem)) + || (GET_CODE (tem) == CALL_INSN + && find_reg_fusage (tem, USE, XEXP (note, 0)))) + { + place = tem; + + /* If we are doing a 3->2 combination, and we have a + register which formerly died in i3 and was not used + by i2, which now no longer dies in i3 and is used in + i2 but does not die in i2, and place is between i2 + and i3, then we may need to move a link from place to + i2. */ + if (i2 && INSN_UID (place) <= max_uid_cuid + && INSN_CUID (place) > INSN_CUID (i2) + && from_insn && INSN_CUID (from_insn) > INSN_CUID (i2) + && reg_referenced_p (XEXP (note, 0), PATTERN (i2))) + { + rtx links = LOG_LINKS (place); + LOG_LINKS (place) = 0; + distribute_links (links); + } + break; + } + } + + /* If we haven't found an insn for the death note and it + is still a REG_DEAD note, but we have hit a CODE_LABEL, + insert a USE insn for the register at that label and + put the death node there. This prevents problems with + call-state tracking in caller-save.c. */ + if (REG_NOTE_KIND (note) == REG_DEAD && place == 0 && tem != 0) + { + place + = emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (note, 0)), + tem); + + /* If this insn was emitted between blocks, then update + basic_block_head of the current block to include it. */ + if (basic_block_end[this_basic_block - 1] == tem) + basic_block_head[this_basic_block] = place; + } + } + + /* If the register is set or already dead at PLACE, we needn't do + anything with this note if it is still a REG_DEAD note. + + Note that we cannot use just `dead_or_set_p' here since we can + convert an assignment to a register into a bit-field assignment. + Therefore, we must also omit the note if the register is the + target of a bitfield assignment. */ + + if (place && REG_NOTE_KIND (note) == REG_DEAD) + { + int regno = REGNO (XEXP (note, 0)); + + if (dead_or_set_p (place, XEXP (note, 0)) + || reg_bitfield_target_p (XEXP (note, 0), PATTERN (place))) + { + /* Unless the register previously died in PLACE, clear + reg_last_death. [I no longer understand why this is + being done.] */ + if (reg_last_death[regno] != place) + reg_last_death[regno] = 0; + place = 0; + } + else + reg_last_death[regno] = place; + + /* If this is a death note for a hard reg that is occupying + multiple registers, ensure that we are still using all + parts of the object. If we find a piece of the object + that is unused, we must add a USE for that piece before + PLACE and put the appropriate REG_DEAD note on it. + + An alternative would be to put a REG_UNUSED for the pieces + on the insn that set the register, but that can't be done if + it is not in the same block. It is simpler, though less + efficient, to add the USE insns. */ + + if (place && regno < FIRST_PSEUDO_REGISTER + && HARD_REGNO_NREGS (regno, GET_MODE (XEXP (note, 0))) > 1) + { + int endregno + = regno + HARD_REGNO_NREGS (regno, + GET_MODE (XEXP (note, 0))); + int all_used = 1; + int i; + + for (i = regno; i < endregno; i++) + if (! refers_to_regno_p (i, i + 1, PATTERN (place), 0) + && ! find_regno_fusage (place, USE, i)) + { + rtx piece = gen_rtx (REG, reg_raw_mode[i], i); + rtx p; + + /* See if we already placed a USE note for this + register in front of PLACE. */ + for (p = place; + GET_CODE (PREV_INSN (p)) == INSN + && GET_CODE (PATTERN (PREV_INSN (p))) == USE; + p = PREV_INSN (p)) + if (rtx_equal_p (piece, + XEXP (PATTERN (PREV_INSN (p)), 0))) + { + p = 0; + break; + } + + if (p) + { + rtx use_insn + = emit_insn_before (gen_rtx (USE, VOIDmode, + piece), + p); + REG_NOTES (use_insn) + = gen_rtx (EXPR_LIST, REG_DEAD, piece, + REG_NOTES (use_insn)); + } + + all_used = 0; + } + + /* Check for the case where the register dying partially + overlaps the register set by this insn. */ + if (all_used) + for (i = regno; i < endregno; i++) + if (dead_or_set_regno_p (place, i)) + { + all_used = 0; + break; + } + + if (! all_used) + { + /* Put only REG_DEAD notes for pieces that are + still used and that are not already dead or set. */ + + for (i = regno; i < endregno; i++) + { + rtx piece = gen_rtx (REG, reg_raw_mode[i], i); + + if ((reg_referenced_p (piece, PATTERN (place)) + || (GET_CODE (place) == CALL_INSN + && find_reg_fusage (place, USE, piece))) + && ! dead_or_set_p (place, piece) + && ! reg_bitfield_target_p (piece, + PATTERN (place))) + REG_NOTES (place) = gen_rtx (EXPR_LIST, REG_DEAD, + piece, + REG_NOTES (place)); + } + + place = 0; + } + } + } + break; + + default: + /* Any other notes should not be present at this point in the + compilation. */ + abort (); + } + + if (place) + { + XEXP (note, 1) = REG_NOTES (place); + REG_NOTES (place) = note; + } + else if ((REG_NOTE_KIND (note) == REG_DEAD + || REG_NOTE_KIND (note) == REG_UNUSED) + && GET_CODE (XEXP (note, 0)) == REG) + reg_n_deaths[REGNO (XEXP (note, 0))]--; + + if (place2) + { + if ((REG_NOTE_KIND (note) == REG_DEAD + || REG_NOTE_KIND (note) == REG_UNUSED) + && GET_CODE (XEXP (note, 0)) == REG) + reg_n_deaths[REGNO (XEXP (note, 0))]++; + + REG_NOTES (place2) = gen_rtx (GET_CODE (note), REG_NOTE_KIND (note), + XEXP (note, 0), REG_NOTES (place2)); + } + } +} + +/* Similarly to above, distribute the LOG_LINKS that used to be present on + I3, I2, and I1 to new locations. This is also called in one case to + add a link pointing at I3 when I3's destination is changed. */ + +static void +distribute_links (links) + rtx links; +{ + rtx link, next_link; + + for (link = links; link; link = next_link) + { + rtx place = 0; + rtx insn; + rtx set, reg; + + next_link = XEXP (link, 1); + + /* If the insn that this link points to is a NOTE or isn't a single + set, ignore it. In the latter case, it isn't clear what we + can do other than ignore the link, since we can't tell which + register it was for. Such links wouldn't be used by combine + anyway. + + It is not possible for the destination of the target of the link to + have been changed by combine. The only potential of this is if we + replace I3, I2, and I1 by I3 and I2. But in that case the + destination of I2 also remains unchanged. */ + + if (GET_CODE (XEXP (link, 0)) == NOTE + || (set = single_set (XEXP (link, 0))) == 0) + continue; + + reg = SET_DEST (set); + while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == ZERO_EXTRACT + || GET_CODE (reg) == SIGN_EXTRACT + || GET_CODE (reg) == STRICT_LOW_PART) + reg = XEXP (reg, 0); + + /* A LOG_LINK is defined as being placed on the first insn that uses + a register and points to the insn that sets the register. Start + searching at the next insn after the target of the link and stop + when we reach a set of the register or the end of the basic block. + + Note that this correctly handles the link that used to point from + I3 to I2. Also note that not much searching is typically done here + since most links don't point very far away. */ + + for (insn = NEXT_INSN (XEXP (link, 0)); + (insn && (this_basic_block == n_basic_blocks - 1 + || basic_block_head[this_basic_block + 1] != insn)); + insn = NEXT_INSN (insn)) + if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' + && reg_overlap_mentioned_p (reg, PATTERN (insn))) + { + if (reg_referenced_p (reg, PATTERN (insn))) + place = insn; + break; + } + else if (GET_CODE (insn) == CALL_INSN + && find_reg_fusage (insn, USE, reg)) + { + place = insn; + break; + } + + /* If we found a place to put the link, place it there unless there + is already a link to the same insn as LINK at that point. */ + + if (place) + { + rtx link2; + + for (link2 = LOG_LINKS (place); link2; link2 = XEXP (link2, 1)) + if (XEXP (link2, 0) == XEXP (link, 0)) + break; + + if (link2 == 0) + { + XEXP (link, 1) = LOG_LINKS (place); + LOG_LINKS (place) = link; + + /* Set added_links_insn to the earliest insn we added a + link to. */ + if (added_links_insn == 0 + || INSN_CUID (added_links_insn) > INSN_CUID (place)) + added_links_insn = place; + } + } + } +} + +void +dump_combine_stats (file) + FILE *file; +{ + fprintf + (file, + ";; Combiner statistics: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n\n", + combine_attempts, combine_merges, combine_extras, combine_successes); +} + +void +dump_combine_total_stats (file) + FILE *file; +{ + fprintf + (file, + "\n;; Combiner totals: %d attempts, %d substitutions (%d requiring new space),\n;; %d successes.\n", + total_attempts, total_merges, total_extras, total_successes); +} diff --git a/contrib/gcc/conditions.h b/contrib/gcc/conditions.h new file mode 100644 index 00000000000..c92226c14ce --- /dev/null +++ b/contrib/gcc/conditions.h @@ -0,0 +1,116 @@ +/* Definitions for condition code handling in final.c and output routines. + Copyright (C) 1987 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* None of the things in the files exist if we don't use CC0. */ + +#ifdef HAVE_cc0 + +/* The variable cc_status says how to interpret the condition code. + It is set by output routines for an instruction that sets the cc's + and examined by output routines for jump instructions. + + cc_status contains two components named `value1' and `value2' + that record two equivalent expressions for the values that the + condition codes were set from. (Either or both may be null if + there is no useful expression to record.) These fields are + used for eliminating redundant test and compare instructions + in the cases where the condition codes were already set by the + previous instruction. + + cc_status.flags contains flags which say that the condition codes + were set in a nonstandard manner. The output of jump instructions + uses these flags to compensate and produce the standard result + with the nonstandard condition codes. Standard flags are defined here. + The tm.h file can also define other machine-dependent flags. + + cc_status also contains a machine-dependent component `mdep' + whose type, `CC_STATUS_MDEP', may be defined as a macro in the + tm.h file. */ + +#ifndef CC_STATUS_MDEP +#define CC_STATUS_MDEP int +#endif + +#ifndef CC_STATUS_MDEP_INIT +#define CC_STATUS_MDEP_INIT 0 +#endif + +typedef struct {int flags; rtx value1, value2; CC_STATUS_MDEP mdep;} CC_STATUS; + +/* While outputting an insn as assembler code, + this is the status BEFORE that insn. */ +extern CC_STATUS cc_prev_status; + +/* While outputting an insn as assembler code, + this is being altered to the status AFTER that insn. */ +extern CC_STATUS cc_status; + +/* These are the machine-independent flags: */ + +/* Set if the sign of the cc value is inverted: + output a following jump-if-less as a jump-if-greater, etc. */ +#define CC_REVERSED 1 + +/* This bit means that the current setting of the N bit is bogus + and conditional jumps should use the Z bit in its place. + This state obtains when an extraction of a signed single-bit field + or an arithmetic shift right of a byte by 7 bits + is turned into a btst, because btst does not set the N bit. */ +#define CC_NOT_POSITIVE 2 + +/* This bit means that the current setting of the N bit is bogus + and conditional jumps should pretend that the N bit is clear. + Used after extraction of an unsigned bit + or logical shift right of a byte by 7 bits is turned into a btst. + The btst does not alter the N bit, but the result of that shift + or extract is never negative. */ +#define CC_NOT_NEGATIVE 4 + +/* This bit means that the current setting of the overflow flag + is bogus and conditional jumps should pretend there is no overflow. */ +#define CC_NO_OVERFLOW 010 + +/* This bit means that what ought to be in the Z bit + should be tested as the complement of the N bit. */ +#define CC_Z_IN_NOT_N 020 + +/* This bit means that what ought to be in the Z bit + should be tested as the N bit. */ +#define CC_Z_IN_N 040 + +/* Nonzero if we must invert the sense of the following branch, i.e. + change EQ to NE. This is not safe for IEEE floating point operations! + It is intended for use only when a combination of arithmetic + or logical insns can leave the condition codes set in a fortuitous + (though inverted) state. */ +#define CC_INVERTED 0100 + +/* Nonzero if we must convert signed condition operators to unsigned. + This is only used by machine description files. */ +#define CC_NOT_SIGNED 0200 + +/* This is how to initialize the variable cc_status. + final does this at appropriate moments. */ + +#define CC_STATUS_INIT \ + (cc_status.flags = 0, cc_status.value1 = 0, cc_status.value2 = 0, \ + CC_STATUS_MDEP_INIT) + +#endif diff --git a/contrib/gcc/config.guess b/contrib/gcc/config.guess new file mode 100755 index 00000000000..2ff0eba28ac --- /dev/null +++ b/contrib/gcc/config.guess @@ -0,0 +1,565 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Written by Per Bothner . +# The master version of this file is at the FSF in /home/gd/gnu/lib. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit system type (host/target name). +# +# Only a few systems have been added to this list; please add others +# (but try to keep the structure clean). +# + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# (ghazi@noc.rutgers.edu 8/24/94.) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15 + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + alpha:OSF1:V*:*) + # After 1.2, OSF1 uses "V1.3" for uname -r. + echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^V//'` + exit 0 ;; + alpha:OSF1:*:*) + # 1.2 uses "1.2" for uname -r. + echo alpha-dec-osf${UNAME_RELEASE} + exit 0 ;; + 21064:Windows_NT:50:3) + echo alpha-dec-winnt3.5 + exit 0 ;; + amiga:NetBSD:*:*) + echo m68k-cbm-netbsd${UNAME_RELEASE} + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + Pyramid*:OSx*:*:*) + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + sun4*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + i86pc:SunOS:5.*:*) + echo i386-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + atari*:NetBSD:*:*) + echo m68k-atari-netbsd${UNAME_RELEASE} + exit 0 ;; + sun3*:NetBSD:*:*) + echo m68k-sun-netbsd${UNAME_RELEASE} + exit 0 ;; + mac68k:NetBSD:*:*) + echo m68k-apple-netbsd${UNAME_RELEASE} + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + mips:*:4*:UMIPS) + echo mips-mips-riscos4sysv + exit 0 ;; + mips:*:5*:RISCos) + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ + -o ${TARGET_BINARY_INTERFACE}x = x ] ; then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i[34]86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + sed 's/^ //' << EOF >dummy.c + #include + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 + rm -f dummy.c dummy + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:4) + if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` + else + IBM_REV=4.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[3478]??:HP-UX:*:*) + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/7?? | 9000/8?[79] ) HP_ARCH=hppa1.1 ;; + 9000/8?? ) HP_ARCH=hppa1.0 ;; + esac + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + sed 's/^ //' << EOF >dummy.c + #include + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 + rm -f dummy.c dummy + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + parisc*:Lites*:*:*) + echo hppa1.1-hp-lites + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*X-MP:*:*:*) + echo xmp-cray-unicos + exit 0 ;; + CRAY*Y-MP:*:*:*) + echo ymp-cray-unicos${UNAME_RELEASE} + exit 0 ;; + CRAY*C90:*:*:*) + echo c90-cray-unicos${UNAME_RELEASE} + exit 0 ;; + CRAY-2:*:*:*) + echo cray2-cray-unicos + exit 0 ;; + hp3[0-9][05]:NetBSD:*:*) + echo m68k-hp-netbsd${UNAME_RELEASE} + exit 0 ;; + i[34]86:BSD/386:*:* | *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; + *:NetBSD:*:*) + echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + *:GNU:*:*) + echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + *:Linux:*:*) + # The BFD linker knows what the default object file format is, so + # first see if it will tell us. + ld_help_string=`ld --help 2>&1` + if echo $ld_help_string | grep >/dev/null 2>&1 "supported emulations: elf_i[345]86"; then + echo "${UNAME_MACHINE}-unknown-linux" ; exit 0 + elif echo $ld_help_string | grep >/dev/null 2>&1 "supported emulations: i[345]86linux"; then + echo "${UNAME_MACHINE}-unknown-linuxaout" ; exit 0 + elif echo $ld_help_string | grep >/dev/null 2>&1 "supported emulations: i[345]86coff"; then + echo "${UNAME_MACHINE}-unknown-linuxcoff" ; exit 0 + elif test "${UNAME_MACHINE}" = "alpha" ; then + echo alpha-unknown-linux ; exit 0 + else + # Either a pre-BFD a.out linker (linuxoldld) or one that does not give us + # useful --help. Gcc wants to distinguish between linuxoldld and linuxaout. + test ! -d /usr/lib/ldscripts/. \ + && echo "${UNAME_MACHINE}-unknown-linuxoldld" && exit 0 + # Determine whether the default compiler is a.out or elf + cat >dummy.c </dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0 + rm -f dummy.c dummy + fi ;; +# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions +# are messed up and put the nodename in both sysname and nodename. + i[34]86:DYNIX/ptx:4*:*) + echo i386-sequent-sysv4 + exit 0 ;; + i[34]86:*:4.*:* | i[34]86:SYSTEM_V:4.*:*) + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE} + else + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + i[34]86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` + (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 + echo ${UNAME_MACHINE}-unknown-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-unknown-sysv32 + fi + exit 0 ;; + Intel:Mach:3*:*) + echo i386-unknown-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + M680[234]0:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0) + uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3 && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m680[234]0:LynxOS:2.[23]*:*) + echo m68k-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + i[34]86:LynxOS:2.[23]*:*) + echo i386-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + TSUNAMI:LynxOS:2.[23]*:*) + echo sparc-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.[23]*:*) + echo rs6000-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +cat >dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + printf ("%s-next-nextstep%s\n", __ARCHITECTURE__, version==2 ? "2" : "3"); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-unknown-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +#if !defined (ultrix) + printf ("vax-dec-bsd\n"); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0 +rm -f dummy.c dummy + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +#echo '(Unable to guess system type)' 1>&2 + +exit 1 diff --git a/contrib/gcc/config.sub b/contrib/gcc/config.sub new file mode 100755 index 00000000000..e67a800b515 --- /dev/null +++ b/contrib/gcc/config.sub @@ -0,0 +1,867 @@ +#! /bin/sh +# Configuration validation subroutine script, version 1.1. +# Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +if [ x$1 = x ] +then + echo Configuration name missing. 1>&2 + echo "Usage: $0 CPU-MFR-OPSYS" 1>&2 + echo "or $0 ALIAS" 1>&2 + echo where ALIAS is a recognized configuration type. 1>&2 + exit 1 +fi + +# First pass through any local machine types. +case $1 in + *local*) + echo $1 + exit 0 + ;; + *) + ;; +esac + +# Separate what the user gave into CPU-COMPANY and OS (if any). +basic_machine=`echo $1 | sed 's/-[^-]*$//'` +if [ $basic_machine != $1 ] +then os=`echo $1 | sed 's/.*-/-/'` +else os=; fi + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp ) + os= + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + tahoe | i[345]86 | i860 | m68k | m68000 | m88k | ns32k | arm \ + | arme[lb] | pyramid \ + | tron | a29k | 580 | i960 | h8300 | hppa1.0 | hppa1.1 \ + | alpha | we32k | ns16k | clipper | sparclite | i370 | sh \ + | powerpc | powerpcle | sparc64 | 1750a | dsp16xx | mips64 | mipsel \ + | pdp11 | mips64el | mips64orion | mips64orionel \ + | sparc) + basic_machine=$basic_machine-unknown + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + vax-* | tahoe-* | i[345]86-* | i860-* | m68k-* | m68000-* | m88k-* \ + | sparc-* | ns32k-* | fx80-* | arm-* | c[123]* \ + | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* | power-* \ + | none-* | 580-* | cray2-* | h8300-* | i960-* | xmp-* | ymp-* \ + | hppa1.0-* | hppa1.1-* | alpha-* | we32k-* | cydra-* | ns16k-* \ + | pn-* | np1-* | xps100-* | clipper-* | orion-* | sparclite-* \ + | pdp11-* | sh-* | powerpc-* | powerpcle-* | sparc64-* | mips64-* | mipsel-* \ + | mips64el-* | mips64orion-* | mips64orionel-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-cbm + ;; + amigados) + basic_machine=m68k-cbm + os=-amigados + ;; + amigaunix | amix) + basic_machine=m68k-cbm + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | ymp) + basic_machine=ymp-cray + os=-unicos + ;; + cray2) + basic_machine=cray2-cray + os=-unicos + ;; + crds | unos) + basic_machine=m68k-crds + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + os=-mvs + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i[345]86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv32 + ;; + i[345]86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv4 + ;; + i[345]86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv + ;; + i[345]86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-solaris2 + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + miniframe) + basic_machine=m68000-convergent + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + np1) + basic_machine=np1-gould + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium | p5 | p6) + # We don't have specific support for the Intel Pentium (p6) followon yet, so just call it a Pentium + basic_machine=i586-intel + ;; + pentium-* | p5-* | p6-*) + # We don't have specific support for the Intel Pentium (p6) followon yet, so just call it a Pentium + basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + k5) + # We don't have specific support for AMD's K5 yet, so just call it a Pentium + basic_machine=i586-amd + ;; + nexen) + # We don't have specific support for Nexgen yet, so just call it a Pentium + basic_machine=i586-nexgen + ;; + pn) + basic_machine=pn-gould + ;; + power) basic_machine=rs6000-ibm + ;; + ppc) basic_machine=powerpc-unknown + ;; + ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ppcle | powerpclittle | ppc-le | powerpc-little) + basic_machine=powerpcle-unknown + ;; + ppcle-* | powerpclittle-*) + basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + ps2) + basic_machine=i386-ibm + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + os=-vxworks + ;; + xmp) + basic_machine=xmp-cray + os=-unicos + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + mips) + basic_machine=mips-mips + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sparc) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -unixware* | svr4*) + os=-sysv4 + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative MUST END IN A *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[345]* \ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigados* | -msdos* | -newsos* | -unicos* | -aos* \ + | -nindy* | -vxworks* | -ebmon* | -hms* | -mvs* | -clix* \ + | -riscos* | -linux* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -netbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ + | -udi* | -eabi* | -lites* ) + # Remember, each alternative MUST END IN *, to match a version number. + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -ctix* | -uts*) + os=-sysv + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -xenix) + os=-xenix + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + arm*-semi) + os=-aout + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-ibm) + os=-aix + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigados + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -lynxos*) + vendor=lynx + ;; + -aix*) + vendor=ibm + ;; + -hpux*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -vxworks*) + vendor=wrs + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os diff --git a/contrib/gcc/config/README b/contrib/gcc/config/README new file mode 100644 index 00000000000..60328ec5b82 --- /dev/null +++ b/contrib/gcc/config/README @@ -0,0 +1,5 @@ +This directory contains machine-specific files for the GNU C compiler. +It has a subdirectory for each basic CPU type. +The only files in this directory itself +are some .h files that pertain to particular operating systems +and are used for more than one CPU type. diff --git a/contrib/gcc/config/aoutos.h b/contrib/gcc/config/aoutos.h new file mode 100644 index 00000000000..e9caa719905 --- /dev/null +++ b/contrib/gcc/config/aoutos.h @@ -0,0 +1,88 @@ +/* aoutos.h -- operating system specific defines to be used when + targeting GCC for some system that uses a.out file format. + Copyright (C) 1992 Free Software Foundation, Inc. + + Written by Ron Guilmette (rfg@netcom.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* To use this file, make up a file with a name like: + + ?????aout.h + + where ????? is replaced by the name of the basic hardware that you + are targeting for. Then, in the file ?????aout.h, put something + like: + + #include "?????.h" + #include "aoutos.h" + + followed by any really system-specific defines (or overrides of + defines) which you find that you need. Now, modify the configure + or configure.in script to properly use the new ?????aout.h file + when configuring for the system. */ + +/* Define a symbol indicating that we are using aoutos.h. */ +#define USING_AOUTOS_H + +/* A C statement (sans semicolon) to output an element in the table of + global constructors. + If using GNU LD, tell it that this is part of the static destructor set. + This code works for any machine provided you use GNU as/ld. + If not using GNU LD, rely on a "collect" program to look for names defined + in the particular form we choose as global constructor function names. */ + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + if (flag_gnu_linker) \ + { \ + /* Output an N_SETT (0x16, 22.) for the name. */ \ + fprintf (FILE, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP); \ + assemble_name (FILE, NAME); \ + fputc ('\n', FILE); \ + } \ + } while (0) + + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ + +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + if (flag_gnu_linker) \ + { \ + /* Output an N_SETT (0x16, 22.) for the name. */ \ + fprintf (FILE, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP); \ + assemble_name (FILE, NAME); \ + fputc ('\n', FILE); \ + } \ + } while (0) + +/* Likewise for entries we want to record for garbage collection. + Garbage collection is still under development. */ + +#define ASM_OUTPUT_GC_ENTRY(FILE,NAME) \ + do { \ + if (flag_gnu_linker) \ + { \ + /* Output an N_SETT (0x16, 22.) for the name. */ \ + fprintf (FILE, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP); \ + assemble_name (FILE, NAME); \ + fputc ('\n', FILE); \ + } \ + } while (0) diff --git a/contrib/gcc/config/fp-bit.c b/contrib/gcc/config/fp-bit.c new file mode 100644 index 00000000000..4ee08f1629b --- /dev/null +++ b/contrib/gcc/config/fp-bit.c @@ -0,0 +1,1352 @@ +/* This is a software floating point library which can be used instead of + the floating point routines in libgcc1.c for targets without hardware + floating point. */ + +/* Copyright (C) 1994, 1995 Free Software Foundation, Inc. + +This file is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +In addition to the permissions in the GNU General Public License, the +Free Software Foundation gives you unlimited permission to link the +compiled version of this file with other programs, and to distribute +those programs without any restriction coming from the use of this +file. (The General Public License restrictions do apply in other +respects; for example, they cover modification of the file, and +distribution when not linked into another program.) + +This file is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you link this library with other files, + some of which are compiled with GCC, to produce an executable, + this library does not by itself cause the resulting executable + to be covered by the GNU General Public License. + This exception does not however invalidate any other reasons why + the executable file might be covered by the GNU General Public License. */ + +/* This implements IEEE 754 format arithmetic, but does not provide a + mechanism for setting the rounding mode, or for generating or handling + exceptions. + + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim + Wilson, all of Cygnus Support. */ + +/* The intended way to use this file is to make two copies, add `#define FLOAT' + to one copy, then compile both copies and add them to libgcc.a. */ + +/* The following macros can be defined to change the behaviour of this file: + FLOAT: Implement a `float', aka SFmode, fp library. If this is not + defined, then this file implements a `double', aka DFmode, fp library. + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e. + don't include float->double conversion which requires the double library. + This is useful only for machines which can't support doubles, e.g. some + 8-bit processors. + CMPtype: Specify the type that floating point compares should return. + This defaults to SItype, aka int. + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the + US Software goFast library. If this is not defined, the entry points use + the same names as libgcc1.c. + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding + two integers to the FLO_union_type. + NO_NANS: Disable nan and infinity handling + SMALL_MACHINE: Useful when operations on QIs and HIs are faster + than on an SI */ + +typedef SFtype __attribute__ ((mode (SF))); +typedef DFtype __attribute__ ((mode (DF))); + +typedef int HItype __attribute__ ((mode (HI))); +typedef int SItype __attribute__ ((mode (SI))); +typedef int DItype __attribute__ ((mode (DI))); + +/* The type of the result of a fp compare */ +#ifndef CMPtype +#define CMPtype SItype +#endif + +typedef unsigned int UHItype __attribute__ ((mode (HI))); +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); + +#define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1)) +#define MAX_USI_INT ((USItype) ~0) + + +#ifdef FLOAT_ONLY +#define NO_DI_MODE +#endif + +#ifdef FLOAT +# define NGARDS 7L +# define GARDROUND 0x3f +# define GARDMASK 0x7f +# define GARDMSB 0x40 +# define EXPBITS 8 +# define EXPBIAS 127 +# define FRACBITS 23 +# define EXPMAX (0xff) +# define QUIET_NAN 0x100000L +# define FRAC_NBITS 32 +# define FRACHIGH 0x80000000L +# define FRACHIGH2 0xc0000000L +# define pack_d pack_f +# define unpack_d unpack_f + typedef USItype fractype; + typedef UHItype halffractype; + typedef SFtype FLO_type; + typedef SItype intfrac; + +#else +# define PREFIXFPDP dp +# define PREFIXSFDF df +# define NGARDS 8L +# define GARDROUND 0x7f +# define GARDMASK 0xff +# define GARDMSB 0x80 +# define EXPBITS 11 +# define EXPBIAS 1023 +# define FRACBITS 52 +# define EXPMAX (0x7ff) +# define QUIET_NAN 0x8000000000000LL +# define FRAC_NBITS 64 +# define FRACHIGH 0x8000000000000000LL +# define FRACHIGH2 0xc000000000000000LL + typedef UDItype fractype; + typedef USItype halffractype; + typedef DFtype FLO_type; + typedef DItype intfrac; +#endif + +#ifdef US_SOFTWARE_GOFAST +# ifdef FLOAT +# define add fpadd +# define sub fpsub +# define multiply fpmul +# define divide fpdiv +# define compare fpcmp +# define si_to_float sitofp +# define float_to_si fptosi +# define float_to_usi fptoui +# define negate __negsf2 +# define sf_to_df fptodp +# define dptofp dptofp +#else +# define add dpadd +# define sub dpsub +# define multiply dpmul +# define divide dpdiv +# define compare dpcmp +# define si_to_float litodp +# define float_to_si dptoli +# define float_to_usi dptoul +# define negate __negdf2 +# define df_to_sf dptofp +#endif +#else +# ifdef FLOAT +# define add __addsf3 +# define sub __subsf3 +# define multiply __mulsf3 +# define divide __divsf3 +# define compare __cmpsf2 +# define _eq_f2 __eqsf2 +# define _ne_f2 __nesf2 +# define _gt_f2 __gtsf2 +# define _ge_f2 __gesf2 +# define _lt_f2 __ltsf2 +# define _le_f2 __lesf2 +# define si_to_float __floatsisf +# define float_to_si __fixsfsi +# define float_to_usi __fixunssfsi +# define negate __negsf2 +# define sf_to_df __extendsfdf2 +#else +# define add __adddf3 +# define sub __subdf3 +# define multiply __muldf3 +# define divide __divdf3 +# define compare __cmpdf2 +# define _eq_f2 __eqdf2 +# define _ne_f2 __nedf2 +# define _gt_f2 __gtdf2 +# define _ge_f2 __gedf2 +# define _lt_f2 __ltdf2 +# define _le_f2 __ledf2 +# define si_to_float __floatsidf +# define float_to_si __fixdfsi +# define float_to_usi __fixunsdfsi +# define negate __negdf2 +# define df_to_sf __truncdfsf2 +# endif +#endif + + +#define INLINE __inline__ + +/* Preserve the sticky-bit when shifting fractions to the right. */ +#define LSHIFT(a) { a = (a & 1) | (a >> 1); } + +/* numeric parameters */ +/* F_D_BITOFF is the number of bits offset between the MSB of the mantissa + of a float and of a double. Assumes there are only two float types. + (double::FRAC_BITS+double::NGARGS-(float::FRAC_BITS-float::NGARDS)) + */ +#define F_D_BITOFF (52+8-(23+7)) + + +#define NORMAL_EXPMIN (-(EXPBIAS)+1) +#define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS)) +#define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS)) + +/* common types */ + +typedef enum +{ + CLASS_SNAN, + CLASS_QNAN, + CLASS_ZERO, + CLASS_NUMBER, + CLASS_INFINITY +} fp_class_type; + +typedef struct +{ +#ifdef SMALL_MACHINE + char class; + unsigned char sign; + short normal_exp; +#else + fp_class_type class; + unsigned int sign; + int normal_exp; +#endif + + union + { + fractype ll; + halffractype l[2]; + } fraction; +} fp_number_type; + +typedef union +{ + FLO_type value; + fractype value_raw; + +#ifndef FLOAT + halffractype words[2]; +#endif + +#ifdef FLOAT_BIT_ORDER_MISMATCH + struct + { + fractype fraction:FRACBITS __attribute__ ((packed)); + unsigned int exp:EXPBITS __attribute__ ((packed)); + unsigned int sign:1 __attribute__ ((packed)); + } + bits; +#endif + +#ifdef _DEBUG_BITFLOAT + struct + { + unsigned int sign:1 __attribute__ ((packed)); + unsigned int exp:EXPBITS __attribute__ ((packed)); + fractype fraction:FRACBITS __attribute__ ((packed)); + } + bits_big_endian; + + struct + { + fractype fraction:FRACBITS __attribute__ ((packed)); + unsigned int exp:EXPBITS __attribute__ ((packed)); + unsigned int sign:1 __attribute__ ((packed)); + } + bits_little_endian; +#endif +} +FLO_union_type; + + +/* end of header */ + +/* IEEE "special" number predicates */ + +#ifdef NO_NANS + +#define nan() 0 +#define isnan(x) 0 +#define isinf(x) 0 +#else + +INLINE +static fp_number_type * +nan () +{ + static fp_number_type thenan; + + return &thenan; +} + +INLINE +static int +isnan ( fp_number_type * x) +{ + return x->class == CLASS_SNAN || x->class == CLASS_QNAN; +} + +INLINE +static int +isinf ( fp_number_type * x) +{ + return x->class == CLASS_INFINITY; +} + +#endif + +INLINE +static int +iszero ( fp_number_type * x) +{ + return x->class == CLASS_ZERO; +} + +INLINE +static void +flip_sign ( fp_number_type * x) +{ + x->sign = !x->sign; +} + +static FLO_type +pack_d ( fp_number_type * src) +{ + FLO_union_type dst; + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */ + int sign = src->sign; + int exp = 0; + + if (isnan (src)) + { + exp = EXPMAX; + if (src->class == CLASS_QNAN || 1) + { + fraction |= QUIET_NAN; + } + } + else if (isinf (src)) + { + exp = EXPMAX; + fraction = 0; + } + else if (iszero (src)) + { + exp = 0; + fraction = 0; + } + else if (fraction == 0) + { + exp = 0; + sign = 0; + } + else + { + if (src->normal_exp < NORMAL_EXPMIN) + { + /* This number's exponent is too low to fit into the bits + available in the number, so we'll store 0 in the exponent and + shift the fraction to the right to make up for it. */ + + int shift = NORMAL_EXPMIN - src->normal_exp; + + exp = 0; + + if (shift > FRAC_NBITS - NGARDS) + { + /* No point shifting, since it's more that 64 out. */ + fraction = 0; + } + else + { + /* Shift by the value */ + fraction >>= shift; + } + fraction >>= NGARDS; + } + else if (src->normal_exp > EXPBIAS) + { + exp = EXPMAX; + fraction = 0; + } + else + { + exp = src->normal_exp + EXPBIAS; + /* IF the gard bits are the all zero, but the first, then we're + half way between two numbers, choose the one which makes the + lsb of the answer 0. */ + if ((fraction & GARDMASK) == GARDMSB) + { + if (fraction & (1 << NGARDS)) + fraction += GARDROUND + 1; + } + else + { + /* Add a one to the guards to round up */ + fraction += GARDROUND; + } + if (fraction >= IMPLICIT_2) + { + fraction >>= 1; + exp += 1; + } + fraction >>= NGARDS; + } + } + + /* We previously used bitfields to store the number, but this doesn't + handle little/big endian systems conviently, so use shifts and + masks */ +#ifdef FLOAT_BIT_ORDER_MISMATCH + dst.bits.fraction = fraction; + dst.bits.exp = exp; + dst.bits.sign = sign; +#else + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1); + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS; + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS); +#endif + +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT) + { + halffractype tmp = dst.words[0]; + dst.words[0] = dst.words[1]; + dst.words[1] = tmp; + } +#endif + + return dst.value; +} + +static void +unpack_d (FLO_union_type * src, fp_number_type * dst) +{ + /* We previously used bitfields to store the number, but this doesn't + handle little/big endian systems conviently, so use shifts and + masks */ + fractype fraction; + int exp; + int sign; + +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT) + FLO_union_type swapped; + + swapped.words[0] = src->words[1]; + swapped.words[1] = src->words[0]; + src = &swapped; +#endif + +#ifdef FLOAT_BIT_ORDER_MISMATCH + fraction = src->bits.fraction; + exp = src->bits.exp; + sign = src->bits.sign; +#else + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1); + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1); + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1; +#endif + + dst->sign = sign; + if (exp == 0) + { + /* Hmm. Looks like 0 */ + if (fraction == 0) + { + /* tastes like zero */ + dst->class = CLASS_ZERO; + } + else + { + /* Zero exponent with non zero fraction - it's denormalized, + so there isn't a leading implicit one - we'll shift it so + it gets one. */ + dst->normal_exp = exp - EXPBIAS + 1; + fraction <<= NGARDS; + + dst->class = CLASS_NUMBER; +#if 1 + while (fraction < IMPLICIT_1) + { + fraction <<= 1; + dst->normal_exp--; + } +#endif + dst->fraction.ll = fraction; + } + } + else if (exp == EXPMAX) + { + /* Huge exponent*/ + if (fraction == 0) + { + /* Attached to a zero fraction - means infinity */ + dst->class = CLASS_INFINITY; + } + else + { + /* Non zero fraction, means nan */ + if (sign) + { + dst->class = CLASS_SNAN; + } + else + { + dst->class = CLASS_QNAN; + } + /* Keep the fraction part as the nan number */ + dst->fraction.ll = fraction; + } + } + else + { + /* Nothing strange about this number */ + dst->normal_exp = exp - EXPBIAS; + dst->class = CLASS_NUMBER; + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1; + } +} + +static fp_number_type * +_fpadd_parts (fp_number_type * a, + fp_number_type * b, + fp_number_type * tmp) +{ + intfrac tfraction; + + /* Put commonly used fields in local variables. */ + int a_normal_exp; + int b_normal_exp; + fractype a_fraction; + fractype b_fraction; + + if (isnan (a)) + { + return a; + } + if (isnan (b)) + { + return b; + } + if (isinf (a)) + { + /* Adding infinities with opposite signs yields a NaN. */ + if (isinf (b) && a->sign != b->sign) + return nan (); + return a; + } + if (isinf (b)) + { + return b; + } + if (iszero (b)) + { + return a; + } + if (iszero (a)) + { + return b; + } + + /* Got two numbers. shift the smaller and increment the exponent till + they're the same */ + { + int diff; + + a_normal_exp = a->normal_exp; + b_normal_exp = b->normal_exp; + a_fraction = a->fraction.ll; + b_fraction = b->fraction.ll; + + diff = a_normal_exp - b_normal_exp; + + if (diff < 0) + diff = -diff; + if (diff < FRAC_NBITS) + { + /* ??? This does shifts one bit at a time. Optimize. */ + while (a_normal_exp > b_normal_exp) + { + b_normal_exp++; + LSHIFT (b_fraction); + } + while (b_normal_exp > a_normal_exp) + { + a_normal_exp++; + LSHIFT (a_fraction); + } + } + else + { + /* Somethings's up.. choose the biggest */ + if (a_normal_exp > b_normal_exp) + { + b_normal_exp = a_normal_exp; + b_fraction = 0; + } + else + { + a_normal_exp = b_normal_exp; + a_fraction = 0; + } + } + } + + if (a->sign != b->sign) + { + if (a->sign) + { + tfraction = -a_fraction + b_fraction; + } + else + { + tfraction = a_fraction - b_fraction; + } + if (tfraction > 0) + { + tmp->sign = 0; + tmp->normal_exp = a_normal_exp; + tmp->fraction.ll = tfraction; + } + else + { + tmp->sign = 1; + tmp->normal_exp = a_normal_exp; + tmp->fraction.ll = -tfraction; + } + /* and renormalize it */ + + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll) + { + tmp->fraction.ll <<= 1; + tmp->normal_exp--; + } + } + else + { + tmp->sign = a->sign; + tmp->normal_exp = a_normal_exp; + tmp->fraction.ll = a_fraction + b_fraction; + } + tmp->class = CLASS_NUMBER; + /* Now the fraction is added, we have to shift down to renormalize the + number */ + + if (tmp->fraction.ll >= IMPLICIT_2) + { + LSHIFT (tmp->fraction.ll); + tmp->normal_exp++; + } + return tmp; + +} + +FLO_type +add (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + fp_number_type tmp; + fp_number_type *res; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + res = _fpadd_parts (&a, &b, &tmp); + + return pack_d (res); +} + +FLO_type +sub (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + fp_number_type tmp; + fp_number_type *res; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + b.sign ^= 1; + + res = _fpadd_parts (&a, &b, &tmp); + + return pack_d (res); +} + +static fp_number_type * +_fpmul_parts ( fp_number_type * a, + fp_number_type * b, + fp_number_type * tmp) +{ + fractype low = 0; + fractype high = 0; + + if (isnan (a)) + { + a->sign = a->sign != b->sign; + return a; + } + if (isnan (b)) + { + b->sign = a->sign != b->sign; + return b; + } + if (isinf (a)) + { + if (iszero (b)) + return nan (); + a->sign = a->sign != b->sign; + return a; + } + if (isinf (b)) + { + if (iszero (a)) + { + return nan (); + } + b->sign = a->sign != b->sign; + return b; + } + if (iszero (a)) + { + a->sign = a->sign != b->sign; + return a; + } + if (iszero (b)) + { + b->sign = a->sign != b->sign; + return b; + } + + /* Calculate the mantissa by multiplying both 64bit numbers to get a + 128 bit number */ + { + fractype x = a->fraction.ll; + fractype ylow = b->fraction.ll; + fractype yhigh = 0; + int bit; + +#if defined(NO_DI_MODE) + { + /* ??? This does multiplies one bit at a time. Optimize. */ + for (bit = 0; bit < FRAC_NBITS; bit++) + { + int carry; + + if (x & 1) + { + carry = (low += ylow) < ylow; + high += yhigh + carry; + } + yhigh <<= 1; + if (ylow & FRACHIGH) + { + yhigh |= 1; + } + ylow <<= 1; + x >>= 1; + } + } +#elif defined(FLOAT) + { + /* Multiplying two 32 bit numbers to get a 64 bit number on + a machine with DI, so we're safe */ + + DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll); + + high = answer >> 32; + low = answer; + } +#else + /* Doing a 64*64 to 128 */ + { + UDItype nl = a->fraction.ll & 0xffffffff; + UDItype nh = a->fraction.ll >> 32; + UDItype ml = b->fraction.ll & 0xffffffff; + UDItype mh = b->fraction.ll >>32; + UDItype pp_ll = ml * nl; + UDItype pp_hl = mh * nl; + UDItype pp_lh = ml * nh; + UDItype pp_hh = mh * nh; + UDItype res2 = 0; + UDItype res0 = 0; + UDItype ps_hh__ = pp_hl + pp_lh; + if (ps_hh__ < pp_hl) + res2 += 0x100000000LL; + pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL; + res0 = pp_ll + pp_hl; + if (res0 < pp_ll) + res2++; + res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh; + high = res2; + low = res0; + } +#endif + } + + tmp->normal_exp = a->normal_exp + b->normal_exp; + tmp->sign = a->sign != b->sign; +#ifdef FLOAT + tmp->normal_exp += 2; /* ??????????????? */ +#else + tmp->normal_exp += 4; /* ??????????????? */ +#endif + while (high >= IMPLICIT_2) + { + tmp->normal_exp++; + if (high & 1) + { + low >>= 1; + low |= FRACHIGH; + } + high >>= 1; + } + while (high < IMPLICIT_1) + { + tmp->normal_exp--; + + high <<= 1; + if (low & FRACHIGH) + high |= 1; + low <<= 1; + } + /* rounding is tricky. if we only round if it won't make us round later. */ +#if 0 + if (low & FRACHIGH2) + { + if (((high & GARDMASK) != GARDMSB) + && (((high + 1) & GARDMASK) == GARDMSB)) + { + /* don't round, it gets done again later. */ + } + else + { + high++; + } + } +#endif + if ((high & GARDMASK) == GARDMSB) + { + if (high & (1 << NGARDS)) + { + /* half way, so round to even */ + high += GARDROUND + 1; + } + else if (low) + { + /* but we really weren't half way */ + high += GARDROUND + 1; + } + } + tmp->fraction.ll = high; + tmp->class = CLASS_NUMBER; + return tmp; +} + +FLO_type +multiply (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + fp_number_type tmp; + fp_number_type *res; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + res = _fpmul_parts (&a, &b, &tmp); + + return pack_d (res); +} + +static fp_number_type * +_fpdiv_parts (fp_number_type * a, + fp_number_type * b, + fp_number_type * tmp) +{ + fractype low = 0; + fractype high = 0; + fractype r0, r1, y0, y1, bit; + fractype q; + fractype numerator; + fractype denominator; + fractype quotient; + fractype remainder; + + if (isnan (a)) + { + return a; + } + if (isnan (b)) + { + return b; + } + if (isinf (a) || iszero (a)) + { + if (a->class == b->class) + return nan (); + return a; + } + a->sign = a->sign ^ b->sign; + + if (isinf (b)) + { + a->fraction.ll = 0; + a->normal_exp = 0; + return a; + } + if (iszero (b)) + { + a->class = CLASS_INFINITY; + return b; + } + + /* Calculate the mantissa by multiplying both 64bit numbers to get a + 128 bit number */ + { + int carry; + intfrac d0, d1; /* weren't unsigned before ??? */ + + /* quotient = + ( numerator / denominator) * 2^(numerator exponent - denominator exponent) + */ + + a->normal_exp = a->normal_exp - b->normal_exp; + numerator = a->fraction.ll; + denominator = b->fraction.ll; + + if (numerator < denominator) + { + /* Fraction will be less than 1.0 */ + numerator *= 2; + a->normal_exp--; + } + bit = IMPLICIT_1; + quotient = 0; + /* ??? Does divide one bit at a time. Optimize. */ + while (bit) + { + if (numerator >= denominator) + { + quotient |= bit; + numerator -= denominator; + } + bit >>= 1; + numerator *= 2; + } + + if ((quotient & GARDMASK) == GARDMSB) + { + if (quotient & (1 << NGARDS)) + { + /* half way, so round to even */ + quotient += GARDROUND + 1; + } + else if (numerator) + { + /* but we really weren't half way, more bits exist */ + quotient += GARDROUND + 1; + } + } + + a->fraction.ll = quotient; + return (a); + } +} + +FLO_type +divide (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + fp_number_type tmp; + fp_number_type *res; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + res = _fpdiv_parts (&a, &b, &tmp); + + return pack_d (res); +} + +/* according to the demo, fpcmp returns a comparison with 0... thus + a -1 + a==b -> 0 + a>b -> +1 + */ + +static int +_fpcmp_parts (fp_number_type * a, fp_number_type * b) +{ +#if 0 + /* either nan -> unordered. Must be checked outside of this routine. */ + if (isnan (a) && isnan (b)) + { + return 1; /* still unordered! */ + } +#endif + + if (isnan (a) || isnan (b)) + { + return 1; /* how to indicate unordered compare? */ + } + if (isinf (a) && isinf (b)) + { + /* +inf > -inf, but +inf != +inf */ + /* b \a| +inf(0)| -inf(1) + ______\+--------+-------- + +inf(0)| a==b(0)| ab(1) | a==b(0) + -------+--------+-------- + So since unordered must be non zero, just line up the columns... + */ + return b->sign - a->sign; + } + /* but not both... */ + if (isinf (a)) + { + return a->sign ? -1 : 1; + } + if (isinf (b)) + { + return b->sign ? 1 : -1; + } + if (iszero (a) && iszero (b)) + { + return 0; + } + if (iszero (a)) + { + return b->sign ? 1 : -1; + } + if (iszero (b)) + { + return a->sign ? -1 : 1; + } + /* now both are "normal". */ + if (a->sign != b->sign) + { + /* opposite signs */ + return a->sign ? -1 : 1; + } + /* same sign; exponents? */ + if (a->normal_exp > b->normal_exp) + { + return a->sign ? -1 : 1; + } + if (a->normal_exp < b->normal_exp) + { + return a->sign ? 1 : -1; + } + /* same exponents; check size. */ + if (a->fraction.ll > b->fraction.ll) + { + return a->sign ? -1 : 1; + } + if (a->fraction.ll < b->fraction.ll) + { + return a->sign ? 1 : -1; + } + /* after all that, they're equal. */ + return 0; +} + +CMPtype +compare (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + return _fpcmp_parts (&a, &b); +} + +#ifndef US_SOFTWARE_GOFAST + +/* These should be optimized for their specific tasks someday. */ + +CMPtype +_eq_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return 1; /* false, truth == 0 */ + + return _fpcmp_parts (&a, &b) ; +} + +CMPtype +_ne_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return 1; /* true, truth != 0 */ + + return _fpcmp_parts (&a, &b) ; +} + +CMPtype +_gt_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return -1; /* false, truth > 0 */ + + return _fpcmp_parts (&a, &b); +} + +CMPtype +_ge_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return -1; /* false, truth >= 0 */ + return _fpcmp_parts (&a, &b) ; +} + +CMPtype +_lt_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return 1; /* false, truth < 0 */ + + return _fpcmp_parts (&a, &b); +} + +CMPtype +_le_f2 (FLO_type arg_a, FLO_type arg_b) +{ + fp_number_type a; + fp_number_type b; + + unpack_d ((FLO_union_type *) & arg_a, &a); + unpack_d ((FLO_union_type *) & arg_b, &b); + + if (isnan (&a) || isnan (&b)) + return 1; /* false, truth <= 0 */ + + return _fpcmp_parts (&a, &b) ; +} + +#endif /* ! US_SOFTWARE_GOFAST */ + +FLO_type +si_to_float (SItype arg_a) +{ + fp_number_type in; + + in.class = CLASS_NUMBER; + in.sign = arg_a < 0; + if (!arg_a) + { + in.class = CLASS_ZERO; + } + else + { + in.normal_exp = FRACBITS + NGARDS; + if (in.sign) + { + /* Special case for minint, since there is no +ve integer + representation for it */ + if (arg_a == 0x80000000) + { + return -2147483648.0; + } + in.fraction.ll = (-arg_a); + } + else + in.fraction.ll = arg_a; + + while (in.fraction.ll < (1LL << (FRACBITS + NGARDS))) + { + in.fraction.ll <<= 1; + in.normal_exp -= 1; + } + } + return pack_d (&in); +} + +SItype +float_to_si (FLO_type arg_a) +{ + fp_number_type a; + SItype tmp; + + unpack_d ((FLO_union_type *) & arg_a, &a); + if (iszero (&a)) + return 0; + if (isnan (&a)) + return 0; + /* get reasonable MAX_SI_INT... */ + if (isinf (&a)) + return a.sign ? MAX_SI_INT : (-MAX_SI_INT)-1; + /* it is a number, but a small one */ + if (a.normal_exp < 0) + return 0; + if (a.normal_exp > 30) + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT; + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp); + return a.sign ? (-tmp) : (tmp); +} + +#ifdef US_SOFTWARE_GOFAST +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines, + we also define them for GOFAST because the ones in libgcc2.c have the + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's + out of libgcc2.c. We can't define these here if not GOFAST because then + there'd be duplicate copies. */ + +USItype +float_to_usi (FLO_type arg_a) +{ + fp_number_type a; + + unpack_d ((FLO_union_type *) & arg_a, &a); + if (iszero (&a)) + return 0; + if (isnan (&a)) + return 0; + /* get reasonable MAX_USI_INT... */ + if (isinf (&a)) + return a.sign ? MAX_USI_INT : 0; + /* it is a negative number */ + if (a.sign) + return 0; + /* it is a number, but a small one */ + if (a.normal_exp < 0) + return 0; + if (a.normal_exp > 31) + return MAX_USI_INT; + else if (a.normal_exp > (FRACBITS + NGARDS)) + return a.fraction.ll << ((FRACBITS + NGARDS) - a.normal_exp); + else + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp); +} +#endif + +FLO_type +negate (FLO_type arg_a) +{ + fp_number_type a; + + unpack_d ((FLO_union_type *) & arg_a, &a); + flip_sign (&a); + return pack_d (&a); +} + +#ifdef FLOAT + +SFtype +__make_fp(fp_class_type class, + unsigned int sign, + int exp, + USItype frac) +{ + fp_number_type in; + + in.class = class; + in.sign = sign; + in.normal_exp = exp; + in.fraction.ll = frac; + return pack_d (&in); +} + +#ifndef FLOAT_ONLY + +/* This enables one to build an fp library that supports float but not double. + Otherwise, we would get an undefined reference to __make_dp. + This is needed for some 8-bit ports that can't handle well values that + are 8-bytes in size, so we just don't support double for them at all. */ + +extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac); + +DFtype +sf_to_df (SFtype arg_a) +{ + fp_number_type in; + + unpack_d ((FLO_union_type *) & arg_a, &in); + return __make_dp (in.class, in.sign, in.normal_exp, + ((UDItype) in.fraction.ll) << F_D_BITOFF); +} + +#endif +#endif + +#ifndef FLOAT + +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype); + +DFtype +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac) +{ + fp_number_type in; + + in.class = class; + in.sign = sign; + in.normal_exp = exp; + in.fraction.ll = frac; + return pack_d (&in); +} + +SFtype +df_to_sf (DFtype arg_a) +{ + fp_number_type in; + + unpack_d ((FLO_union_type *) & arg_a, &in); + return __make_fp (in.class, in.sign, in.normal_exp, + in.fraction.ll >> F_D_BITOFF); +} + +#endif diff --git a/contrib/gcc/config/gnu.h b/contrib/gcc/config/gnu.h new file mode 100644 index 00000000000..8ea3ead3d67 --- /dev/null +++ b/contrib/gcc/config/gnu.h @@ -0,0 +1,30 @@ +/* Configuration common to all targets running the GNU system. */ + +/* Macro to produce CPP_PREDEFINES for GNU on a given machine. */ +#define GNU_CPP_PREDEFINES(machine) \ +"-D" machine " -Acpu(" machine ") -Amachine(" machine ")" \ +"-Dunix -Asystem(unix) \ +-DMACH -Asystem(mach) \ +-D__GNU__ -Asystem(gnu)" + +/* Provide GCC options for standard feature-test macros. */ +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{bsd:-D_BSD_SOURCE}" + +/* Default C library spec. Use -lbsd-compat for gcc -bsd. */ +#undef LIB_SPEC +#define LIB_SPEC "%{bsd:-lbsd-compat} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" + +/* Standard include directory. In GNU, "/usr" is a four-letter word. */ +#undef STANDARD_INCLUDE_DIR +#define STANDARD_INCLUDE_DIR "/include" + + +/* We have atexit. */ +#define HAVE_ATEXIT + +/* Implicit library calls should use memcpy, not bcopy, etc. */ +#define TARGET_MEM_FUNCTIONS + +/* The system headers under GNU are C++-aware. */ +#define NO_IMPLICIT_EXTERN_C diff --git a/contrib/gcc/config/gofast.h b/contrib/gcc/config/gofast.h new file mode 100644 index 00000000000..84bea516758 --- /dev/null +++ b/contrib/gcc/config/gofast.h @@ -0,0 +1,96 @@ +/* US Software GOFAST floating point library support. + Copyright (C) 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is used by fp-bit.c. */ +#define US_SOFTWARE_GOFAST + +/* The US Software GOFAST library requires special optabs support. + There is no negation libcall, and several others have names different + from gcc. This file consolidates the support in one place. + + The basic plan is to leave gcc proper alone and via some hook fix things + after the optabs have been set up. Our main entry point is + INIT_GOFAST_OPTABS. */ + +#define INIT_GOFAST_OPTABS \ + do { \ + GOFAST_CLEAR_NEG_FLOAT_OPTAB; \ + GOFAST_RENAME_LIBCALLS; \ + } while (0) + +#define GOFAST_CLEAR_NEG_FLOAT_OPTAB \ + do { \ + int mode; \ + for (mode = SFmode; (int) mode <= (int) TFmode; \ + mode = (enum machine_mode) ((int) mode + 1)) \ + neg_optab->handlers[(int) mode].libfunc = NULL_RTX; \ + } while (0) + +#define GOFAST_RENAME_LIBCALLS \ + add_optab->handlers[(int) SFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpadd"); \ + add_optab->handlers[(int) DFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpadd"); \ + sub_optab->handlers[(int) SFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpsub"); \ + sub_optab->handlers[(int) DFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpsub"); \ + smul_optab->handlers[(int) SFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpmul"); \ + smul_optab->handlers[(int) DFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpmul"); \ + flodiv_optab->handlers[(int) SFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpdiv"); \ + flodiv_optab->handlers[(int) DFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpdiv"); \ + cmp_optab->handlers[(int) SFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + cmp_optab->handlers[(int) DFmode].libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ +\ + extendsfdf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fptodp"); \ + truncdfsf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dptofp"); \ +\ + eqsf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + nesf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + gtsf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + gesf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + ltsf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ + lesf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fpcmp"); \ +\ + eqdf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ + nedf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ + gtdf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ + gedf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ + ltdf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ + ledf2_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dpcmp"); \ +\ + eqxf2_libfunc = NULL_RTX; \ + nexf2_libfunc = NULL_RTX; \ + gtxf2_libfunc = NULL_RTX; \ + gexf2_libfunc = NULL_RTX; \ + ltxf2_libfunc = NULL_RTX; \ + lexf2_libfunc = NULL_RTX; \ +\ + eqtf2_libfunc = NULL_RTX; \ + netf2_libfunc = NULL_RTX; \ + gttf2_libfunc = NULL_RTX; \ + getf2_libfunc = NULL_RTX; \ + lttf2_libfunc = NULL_RTX; \ + letf2_libfunc = NULL_RTX; \ +\ + floatsisf_libfunc = gen_rtx (SYMBOL_REF, Pmode, "sitofp"); \ + floatsidf_libfunc = gen_rtx (SYMBOL_REF, Pmode, "litodp"); \ + fixsfsi_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fptosi"); \ + fixdfsi_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dptoli"); \ + fixunssfsi_libfunc = gen_rtx (SYMBOL_REF, Pmode, "fptoui"); \ + fixunsdfsi_libfunc = gen_rtx (SYMBOL_REF, Pmode, "dptoul"); \ + +/* End of GOFAST_RENAME_LIBCALLS */ diff --git a/contrib/gcc/config/i386/386bsd.h b/contrib/gcc/config/i386/386bsd.h new file mode 100644 index 00000000000..cdab5f57c88 --- /dev/null +++ b/contrib/gcc/config/i386/386bsd.h @@ -0,0 +1,81 @@ +/* Configuration for an i386 running 386BSD as the target machine. */ + +/* This is tested by i386gas.h. */ +#define YES_UNDERSCORES + +#include "i386/gstabs.h" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -D____386BSD____ -D__386BSD__ -DBSD_NET2 -Asystem(unix) -Asystem(bsd) -Acpu(i386) -Amachine(i386)" + +/* Like the default, except no -lg. */ +#define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "short unsigned int" + +#define WCHAR_UNSIGNED 1 + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE 16 + +/* 386BSD does have atexit. */ + +#define HAVE_ATEXIT + +/* Redefine this to use %eax instead of %edx. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%eax\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%eax\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* The following macros are stolen from i386v4.h */ +/* These have to be defined to get PIC code correct */ + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ + +#define JUMP_TABLES_IN_TEXT_SECTION + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 diff --git a/contrib/gcc/config/i386/aix386.h b/contrib/gcc/config/i386/aix386.h new file mode 100644 index 00000000000..e0498e79595 --- /dev/null +++ b/contrib/gcc/config/i386/aix386.h @@ -0,0 +1,69 @@ +/* Definitions for IBM PS2 running AIX/386 with gas. + From: Minh Tran-Le + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* + * This configuration file is for gcc with gas-2.x and gnu ld 2.x + * with aix ps/2 1.3.x. + */ + +/* Define USE_GAS if you have the new version of gas that can handle + * multiple segments and .section pseudo op. This will allow gcc to + * use the .init section for g++ ctor/dtor. + * + * If you don't have gas then undefined USE_GAS. You will also have + * to use collect if you want to use g++ + */ +#define USE_GAS + +#include "i386/aix386ng.h" + +/* Use crt1.o as a startup file and crtn.o as a closing file. + And add crtbegin.o and crtend.o for ctors and dtors */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}} crtbegin.o%s" +#undef ENDFILE_SPEC +#define ENDFILE_SPEC \ + "crtend.o%s crtn.o%s" + +/* Removed the -K flags because the gnu ld does not handle it */ +#undef LINK_SPEC +#define LINK_SPEC "%{T*} %{z:-lm}" + +/* Define a few machine-specific details of the implementation of + constructors. */ + +#undef INIT_SECTION_ASM_OP +#define INIT_SECTION_ASM_OP ".section .init,\"x\"" + +#define CTOR_LIST_BEGIN \ + asm (INIT_SECTION_ASM_OP); \ + asm ("pushl $0") +#define CTOR_LIST_END CTOR_LIST_BEGIN + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + init_section (); \ + fprintf (FILE, "\tpushl $"); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) diff --git a/contrib/gcc/config/i386/aix386ng.h b/contrib/gcc/config/i386/aix386ng.h new file mode 100644 index 00000000000..5d09fc30509 --- /dev/null +++ b/contrib/gcc/config/i386/aix386ng.h @@ -0,0 +1,143 @@ +/* Definitions for IBM PS2 running AIX/386. + From: Minh Tran-Le + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "i386/i386.h" + +/* Get the generic definitions for system V.3. */ + +#include "svr3.h" + +/* Use the ATT assembler syntax. + This overrides at least one macro (ASM_OUTPUT_LABELREF) from svr3.h. */ + +#include "i386/att.h" + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#define STARTFILE_SPEC "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}" +#define ENDFILE_SPEC "crtn.o%s" + +#define LIB_SPEC "%{shlib:-lc_s} -lc" + +/* Special flags for the linker. I don't know what they do. */ + +#define LINK_SPEC "%{K} %{!K:-K} %{T*} %{z:-lm}" + +/* Specify predefined symbols in preprocessor. */ + +#define CPP_PREDEFINES "-Dps2 -Dunix -Di386 -Asystem(unix) -Asystem(aix) -Acpu(i386) -Amachine(i386)" + +#define CPP_SPEC \ + "%{posix:-D_POSIX_SOURCE}%{!posix:-DAIX} -D_I386 -D_AIX -D_MBCS" + +/* special flags for the aix assembler to generate the short form for all + qualifying forward reference */ +/* The buggy /bin/as of aix ps/2 1.2.x cannot always handle it. */ +#if 0 +#define ASM_SPEC "-s2" +#endif /* 0 */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { fprintf (FILE, "\t.file\t"); \ + output_quoted_string (FILE, dump_base_name); \ + fprintf (FILE, "\n"); \ + if (optimize) \ + ASM_FILE_START_1 (FILE); \ + else \ + fprintf (FILE, "\t.noopt\n"); \ + } while (0) + +/* This was suggested, but it shouldn't be right for DBX output. -- RMS + #define ASM_OUTPUT_SOURCE_FILENAME(FILE, NAME) */ + +/* Writing `int' for a bitfield forces int alignment for the structure. */ + +#define PCC_BITFIELD_TYPE_MATTERS 1 + +#ifndef USE_GAS +/* Don't write a `.optim' pseudo; this assembler + is said to have a bug when .optim is used. */ + +#undef ASM_FILE_START_1 +#define ASM_FILE_START_1(FILE) fprintf (FILE, "\t.noopt\n") +#endif + +/* Output assembler code to FILE to increment profiler label # LABELNO + for profiling a function entry. */ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ + fprintf (FILE, "\tleal %sP%d,%%eax\n\tcall mcount\n", LPREFIX, (LABELNO)); + +/* Note that using bss_section here caused errors + in building shared libraries on system V.3. + but AIX 1.2 does not have yet shareable libraries on PS2 */ +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ + (bss_section (), \ + ASM_OUTPUT_LABEL ((FILE), (NAME)), \ + fprintf ((FILE), "\t.set .,.+%u\n", (ROUNDED))) + + +/* Undef all the .init and .fini section stuff if we are not using gas and + * gnu ld so that we can use collect because the standard /bin/as and /bin/ld + * cannot handle those. + */ +#ifndef USE_GAS +# undef INIT_SECTION_ASM_OP +# undef FINI_SECTION_ASM_OP +# undef CTORS_SECTION_ASM_OP +# undef DTORS_SECTION_ASM_OP +# undef ASM_OUTPUT_CONSTRUCTOR +# undef ASM_OUTPUT_DESTRUCTOR +# undef DO_GLOBAL_CTORS_BODY + +# undef CTOR_LIST_BEGIN +# define CTOR_LIST_BEGIN +# undef CTOR_LIST_END +# define CTOR_LIST_END +# undef DTOR_LIST_BEGIN +# define DTOR_LIST_BEGIN +# undef DTOR_LIST_END +# define DTOR_LIST_END + +# undef CONST_SECTION_FUNCTION +# define CONST_SECTION_FUNCTION \ +void \ +const_section () \ +{ \ + extern void text_section(); \ + text_section(); \ +} + +# undef EXTRA_SECTION_FUNCTIONS +# define EXTRA_SECTION_FUNCTIONS \ + CONST_SECTION_FUNCTION \ + BSS_SECTION_FUNCTION + +/* for collect2 */ +# define OBJECT_FORMAT_COFF +# define MY_ISCOFF(magic) \ + ((magic) == I386MAGIC || (magic) == I386SVMAGIC) + +#endif /* !USE_GAS */ diff --git a/contrib/gcc/config/i386/att.h b/contrib/gcc/config/i386/att.h new file mode 100644 index 00000000000..f8bbb764306 --- /dev/null +++ b/contrib/gcc/config/i386/att.h @@ -0,0 +1,106 @@ +/* Definitions for AT&T assembler syntax for the Intel 80386. + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Include common aspects of all 386 Unix assemblers. */ +#include "i386/unix.h" + +#define TARGET_VERSION fprintf (stderr, " (80386, ATT syntax)"); + +/* Define the syntax of instructions and addresses. */ + +/* Prefix for internally generated assembler labels. */ +#define LPREFIX ".L" + +/* Assembler pseudos to introduce constants of various size. */ + +/* #define ASM_BYTE_OP "\t.byte" Now in svr3.h or svr4.h. */ +#define ASM_SHORT "\t.value" +#define ASM_LONG "\t.long" +#define ASM_DOUBLE "\t.double" + +/* How to output an ASCII string constant. */ + +#define ASM_OUTPUT_ASCII(FILE, p, size) \ +do \ +{ int i = 0; \ + while (i < (size)) \ + { if (i%10 == 0) { if (i!=0) fprintf ((FILE), "\n"); \ + fprintf ((FILE), "%s ", ASM_BYTE_OP); } \ + else fprintf ((FILE), ","); \ + fprintf ((FILE), "0x%x", ((p)[i++] & 0377)) ;} \ + fprintf ((FILE), "\n"); \ +} while (0) + +/* Do use .optim by default on this machine. */ +#undef ASM_FILE_START_1 +#define ASM_FILE_START_1(FILE) fprintf (FILE, "\t.optim\n") + +/* This is how to output an assembler line + that says to advance the location counter + to a multiple of 2**LOG bytes. */ + +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG)) + +/* This is how to output an assembler line + that says to advance the location counter by SIZE bytes. */ + +#define ASM_OUTPUT_SKIP(FILE,SIZE) \ + fprintf ((FILE), "\t.set .,.+%u\n", (SIZE)) + +/* Can't use ASM_OUTPUT_SKIP in text section; it doesn't leave 0s. */ + +#define ASM_NO_SKIP_IN_TEXT 1 + +#undef BSS_SECTION_FUNCTION /* Override the definition from svr3.h. */ +#define BSS_SECTION_FUNCTION \ +void \ +bss_section () \ +{ \ + if (in_section != in_bss) \ + { \ + fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP); \ + in_section = in_bss; \ + } \ +} + +/* Define the syntax of labels and symbol definitions/declarations. */ + +/* This is how to store into the string BUF + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), ".%s%d", (PREFIX), (NUMBER)) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. */ + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM) + +/* This is how to output a reference to a user-level label named NAME. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) \ + fprintf (FILE, "%s", NAME) diff --git a/contrib/gcc/config/i386/bsd.h b/contrib/gcc/config/i386/bsd.h new file mode 100644 index 00000000000..6bf7399dc31 --- /dev/null +++ b/contrib/gcc/config/i386/bsd.h @@ -0,0 +1,130 @@ +/* Definitions for BSD assembler syntax for Intel 386 + (actually AT&T syntax for insns and operands, + adapted to BSD conventions for symbol names and debugging.) + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Include common aspects of all 386 Unix assemblers. */ +#include "i386/unix.h" + +/* Use the Sequent Symmetry assembler syntax. */ + +#define TARGET_VERSION fprintf (stderr, " (80386, BSD syntax)"); + +/* Define the syntax of pseudo-ops, labels and comments. */ + +/* Prefix for internally generated assembler labels. If we aren't using + underscores, we are using prefix `.'s to identify labels that should + be ignored, as in `i386/gas.h' --karl@cs.umb.edu */ +#ifdef NO_UNDERSCORES +#define LPREFIX ".L" +#else +#define LPREFIX "L" +#endif /* not NO_UNDERSCORES */ + +/* Assembler pseudos to introduce constants of various size. */ + +#define ASM_BYTE_OP "\t.byte" +#define ASM_SHORT "\t.word" +#define ASM_LONG "\t.long" +#define ASM_DOUBLE "\t.double" + +/* Output at beginning of assembler file. + ??? I am skeptical of this -- RMS. */ + +#define ASM_FILE_START(FILE) \ + do { fprintf (FILE, "\t.file\t"); \ + output_quoted_string (FILE, dump_base_name); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* This was suggested, but it shouldn't be right for DBX output. -- RMS + #define ASM_OUTPUT_SOURCE_FILENAME(FILE, NAME) */ + + +/* Define the syntax of labels and symbol definitions/declarations. */ + +/* This is how to output an assembler line + that says to advance the location counter by SIZE bytes. */ + +#define ASM_OUTPUT_SKIP(FILE,SIZE) \ + fprintf (FILE, "\t.space %u\n", (SIZE)) + +/* Define the syntax of labels and symbol definitions/declarations. */ + +/* This says how to output an assembler line + to define a global common symbol. */ + +#define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".comm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (ROUNDED))) + +/* This says how to output an assembler line + to define a local common symbol. */ + +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".lcomm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (ROUNDED))) + +/* This is how to output an assembler line + that says to advance the location counter + to a multiple of 2**LOG bytes. */ + +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", (LOG)) + +/* This is how to store into the string BUF + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. */ + +#ifdef NO_UNDERSCORES +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*.%s%d", (PREFIX), (NUMBER)) +#else +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*%s%d", (PREFIX), (NUMBER)) +#endif + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. */ + +#ifdef NO_UNDERSCORES +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM) +#else +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, "%s%d:\n", PREFIX, NUM) +#endif + +/* This is how to output a reference to a user-level label named NAME. */ + +#ifdef NO_UNDERSCORES +#define ASM_OUTPUT_LABELREF(FILE,NAME) fprintf (FILE, "%s", NAME) +#else +#define ASM_OUTPUT_LABELREF(FILE,NAME) fprintf (FILE, "_%s", NAME) +#endif /* not NO_UNDERSCORES */ + +/* Sequent has some changes in the format of DBX symbols. */ +#define DBX_NO_XREFS 1 + +/* Don't split DBX symbols into continuations. */ +#define DBX_CONTIN_LENGTH 0 diff --git a/contrib/gcc/config/i386/bsd386.h b/contrib/gcc/config/i386/bsd386.h new file mode 100644 index 00000000000..935a2e06404 --- /dev/null +++ b/contrib/gcc/config/i386/bsd386.h @@ -0,0 +1,18 @@ +/* Configuration for an i386 running BSDI's BSD/386 1.1 as the target + machine. */ + +#include "i386/386bsd.h" + +/* We exist mostly to add -Dbsdi and such to the predefines. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -Dbsdi -D__i386__ -D__bsdi__ -D____386BSD____ -D__386BSD__ -DBSD_NET2 -Asystem(unix) -Asystem(bsd) -Acpu(i386) -Amachine(i386)" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "int" + +#undef WCHAR_UNSIGNED +#define WCHAR_UNSIGNED 0 + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE 32 diff --git a/contrib/gcc/config/i386/config-nt.sed b/contrib/gcc/config/i386/config-nt.sed new file mode 100644 index 00000000000..6c86b27e99c --- /dev/null +++ b/contrib/gcc/config/i386/config-nt.sed @@ -0,0 +1,38 @@ +/^Makefile/,/^ rm -f config.run/d +s/rm -f/del/ +s/|| cp/|| copy/ +/^config.status/,/ fi/d +s/config.status//g +s/\/dev\/null/NUL/g +s/$(srcdir)\/c-parse/c-parse/g +s/$(srcdir)\/c-gperf/c-gperf/g +/^multilib.h/ s/multilib/not-multilib/ +/^target=/ c\ +target=winnt3.5 +/^xmake_file=/ d +/^tmake_file=/ d +/^out_file/ c\ +out_file=config/i386/i386.c +/^out_object_file/ c\ +out_object_file=i386.obj +/^md_file/ c\ +md_file=config/i386/i386.md +/^tm_file/ c\ +tm_file=config/i386/win-nt.h +/^build_xm_file/ c\ +build_xm_file=config/i386/xm-winnt.h +/^host_xm_file/ c\ +host_xm_file=config/i386/xm-winnt.h +/^####target/ i\ +CC = cl \ +CLIB = libc.lib kernel32.lib \ +CFLAGS = -Di386 -DWIN32 -D_WIN32 -D_M_IX86=300 -D_X86_=1 \\\ + -DALMOST_STDC -D_MSC_VER=800 \ +LDFLAGS = -align:0x1000 -subsystem:console -entry:mainCRTStartup \\\ + -stack:1000000,1000 \ +\ +EXTRA_OBJS=winnt.obj \ +winnt.obj: $(srcdir)/config/i386/winnt.c \ +\ $(CC) $(CFLAGS) \\\ +\ -I. -I$(srcdir) -I$(srcdir)/config -c $(srcdir)/config/i386/winnt.c \ + diff --git a/contrib/gcc/config/i386/freebsd.h b/contrib/gcc/config/i386/freebsd.h new file mode 100644 index 00000000000..72fcdd13366 --- /dev/null +++ b/contrib/gcc/config/i386/freebsd.h @@ -0,0 +1,256 @@ +/* Definitions of target machine for GNU compiler for Intel 80386 + running FreeBSD. + Copyright (C) 1988, 1992, 1994 Free Software Foundation, Inc. + Contributed by Poul-Henning Kamp + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This goes away when the math-emulator is fixed */ +#define TARGET_CPU_DEFAULT 0400 /* TARGET_NO_FANCY_MATH_387 */ + +/* This is tested by i386gas.h. */ +#define YES_UNDERSCORES + +/* Don't assume anything about the header files. */ +#define NO_IMPLICIT_EXTERN_C + +#include "i386/gstabs.h" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -D__FreeBSD__ -D__386BSD__ -Asystem(unix) -Asystem(FreeBSD) -Acpu(i386) -Amachine(i386)" + +/* Like the default, except no -lg. */ +#define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "short unsigned int" + +#define WCHAR_UNSIGNED 1 + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE 16 + +#define HAVE_ATEXIT + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* The following macros are stolen from i386v4.h */ +/* These have to be defined to get PIC code correct */ + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ + +#define JUMP_TABLES_IN_TEXT_SECTION + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* Profiling routines, partially copied from i386/osfrose.h. */ + +/* Redefine this to use %eax instead of %edx. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%eax\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%eax\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} + +/* + * Some imports from svr4.h in support of shared libraries. + * Currently, we need the DECLARE_OBJECT_SIZE stuff. + */ + +/* Define the strings used for the special svr4 .type and .size directives. + These strings generally do not vary from one system running svr4 to + another, but if a given system (e.g. m88k running svr) needs to use + different pseudo-op names for these, they may be overridden in the + file which includes this one. */ + +#define TYPE_ASM_OP ".type" +#define SIZE_ASM_OP ".size" + +/* This is how we tell the assembler that a symbol is weak. */ + +#define ASM_WEAKEN_LABEL(FILE,NAME) \ + do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ + fputc ('\n', FILE); } while (0) + +/* The following macro defines the format used to output the second + operand of the .type assembler directive. Different svr4 assemblers + expect various different forms for this operand. The one given here + is just a default. You may need to override it in your machine- + specific tm.h file (depending upon the particulars of your assembler). */ + +#define TYPE_OPERAND_FMT "@%s" + +/* Write the extra assembler code needed to declare a function's result. + Most svr4 assemblers don't require any special declaration of the + result value, but there are exceptions. */ + +#ifndef ASM_DECLARE_RESULT +#define ASM_DECLARE_RESULT(FILE, RESULT) +#endif + +/* These macros generate the special .type and .size directives which + are used to set the corresponding fields of the linker symbol table + entries in an ELF object file under SVR4. These macros also output + the starting labels for the relevant functions/objects. */ + +/* Write the extra assembler code needed to declare a function properly. + Some svr4 assemblers need to also have something extra said about the + function's return value. We allow for that here. */ + +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "function"); \ + putc ('\n', FILE); \ + ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Write the extra assembler code needed to declare an object properly. */ + +#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "object"); \ + putc ('\n', FILE); \ + size_directive_output = 0; \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Output the size directive for a decl in rest_of_decl_compilation + in the case where we did not do so before the initializer. + Once we find the error_mark_node, we know that the value of + size_directive_output was set + by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ + +#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ +do { \ + char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \ + && ! AT_END && TOP_LEVEL \ + && DECL_INITIAL (DECL) == error_mark_node \ + && !size_directive_output) \ + { \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, name); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL)));\ + } \ + } while (0) + + +/* This is how to declare the size of a function. */ + +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ + do { \ + if (!flag_inhibit_size_directive) \ + { \ + char label[256]; \ + static int labelno; \ + labelno++; \ + ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, (FNAME)); \ + fprintf (FILE, ","); \ + assemble_name (FILE, label); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, (FNAME)); \ + putc ('\n', FILE); \ + } \ + } while (0) + +#define ASM_SPEC " %| %{fpic:-k} %{fPIC:-k}" +#define LINK_SPEC \ + "%{!nostdlib:%{!r*:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} %{assert*}" + +/* This is defined when gcc is compiled in the BSD-directory-tree, and must + * make up for the gap to all the stuff done in the GNU-makefiles. + */ + +#ifdef FREEBSD_NATIVE + +#define INCLUDE_DEFAULTS { \ + { "/usr/include", 0 }, \ + { "/usr/include/g++", 1 }, \ + { 0, 0} \ + } + +#undef MD_EXEC_PREFIX +#define MD_EXEC_PREFIX "/usr/libexec/" + +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/usr/lib" + +#if 0 /* This is very wrong!!! */ +#define DEFAULT_TARGET_MACHINE "i386-unknown-freebsd_1.0" +#define GPLUSPLUS_INCLUDE_DIR "/usr/local/lib/gcc-lib/i386-unknown-freebsd_1.0/2.5.8/include" +#define TOOL_INCLUDE_DIR "/usr/local/i386-unknown-freebsd_1.0/include" +#define GCC_INCLUDE_DIR "/usr/local/lib/gcc-lib/i386-unknown-freebsd_1.0/2.5.8/include" +#endif + +#endif /* FREEBSD_NATIVE */ diff --git a/contrib/gcc/config/i386/freebsd.h.fixed b/contrib/gcc/config/i386/freebsd.h.fixed new file mode 100644 index 00000000000..72fcdd13366 --- /dev/null +++ b/contrib/gcc/config/i386/freebsd.h.fixed @@ -0,0 +1,256 @@ +/* Definitions of target machine for GNU compiler for Intel 80386 + running FreeBSD. + Copyright (C) 1988, 1992, 1994 Free Software Foundation, Inc. + Contributed by Poul-Henning Kamp + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This goes away when the math-emulator is fixed */ +#define TARGET_CPU_DEFAULT 0400 /* TARGET_NO_FANCY_MATH_387 */ + +/* This is tested by i386gas.h. */ +#define YES_UNDERSCORES + +/* Don't assume anything about the header files. */ +#define NO_IMPLICIT_EXTERN_C + +#include "i386/gstabs.h" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -D__FreeBSD__ -D__386BSD__ -Asystem(unix) -Asystem(FreeBSD) -Acpu(i386) -Amachine(i386)" + +/* Like the default, except no -lg. */ +#define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "short unsigned int" + +#define WCHAR_UNSIGNED 1 + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE 16 + +#define HAVE_ATEXIT + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* The following macros are stolen from i386v4.h */ +/* These have to be defined to get PIC code correct */ + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ + +#define JUMP_TABLES_IN_TEXT_SECTION + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* Profiling routines, partially copied from i386/osfrose.h. */ + +/* Redefine this to use %eax instead of %edx. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%eax\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%eax\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} + +/* + * Some imports from svr4.h in support of shared libraries. + * Currently, we need the DECLARE_OBJECT_SIZE stuff. + */ + +/* Define the strings used for the special svr4 .type and .size directives. + These strings generally do not vary from one system running svr4 to + another, but if a given system (e.g. m88k running svr) needs to use + different pseudo-op names for these, they may be overridden in the + file which includes this one. */ + +#define TYPE_ASM_OP ".type" +#define SIZE_ASM_OP ".size" + +/* This is how we tell the assembler that a symbol is weak. */ + +#define ASM_WEAKEN_LABEL(FILE,NAME) \ + do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ + fputc ('\n', FILE); } while (0) + +/* The following macro defines the format used to output the second + operand of the .type assembler directive. Different svr4 assemblers + expect various different forms for this operand. The one given here + is just a default. You may need to override it in your machine- + specific tm.h file (depending upon the particulars of your assembler). */ + +#define TYPE_OPERAND_FMT "@%s" + +/* Write the extra assembler code needed to declare a function's result. + Most svr4 assemblers don't require any special declaration of the + result value, but there are exceptions. */ + +#ifndef ASM_DECLARE_RESULT +#define ASM_DECLARE_RESULT(FILE, RESULT) +#endif + +/* These macros generate the special .type and .size directives which + are used to set the corresponding fields of the linker symbol table + entries in an ELF object file under SVR4. These macros also output + the starting labels for the relevant functions/objects. */ + +/* Write the extra assembler code needed to declare a function properly. + Some svr4 assemblers need to also have something extra said about the + function's return value. We allow for that here. */ + +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "function"); \ + putc ('\n', FILE); \ + ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Write the extra assembler code needed to declare an object properly. */ + +#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "object"); \ + putc ('\n', FILE); \ + size_directive_output = 0; \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Output the size directive for a decl in rest_of_decl_compilation + in the case where we did not do so before the initializer. + Once we find the error_mark_node, we know that the value of + size_directive_output was set + by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ + +#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ +do { \ + char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \ + && ! AT_END && TOP_LEVEL \ + && DECL_INITIAL (DECL) == error_mark_node \ + && !size_directive_output) \ + { \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, name); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL)));\ + } \ + } while (0) + + +/* This is how to declare the size of a function. */ + +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ + do { \ + if (!flag_inhibit_size_directive) \ + { \ + char label[256]; \ + static int labelno; \ + labelno++; \ + ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, (FNAME)); \ + fprintf (FILE, ","); \ + assemble_name (FILE, label); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, (FNAME)); \ + putc ('\n', FILE); \ + } \ + } while (0) + +#define ASM_SPEC " %| %{fpic:-k} %{fPIC:-k}" +#define LINK_SPEC \ + "%{!nostdlib:%{!r*:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} %{assert*}" + +/* This is defined when gcc is compiled in the BSD-directory-tree, and must + * make up for the gap to all the stuff done in the GNU-makefiles. + */ + +#ifdef FREEBSD_NATIVE + +#define INCLUDE_DEFAULTS { \ + { "/usr/include", 0 }, \ + { "/usr/include/g++", 1 }, \ + { 0, 0} \ + } + +#undef MD_EXEC_PREFIX +#define MD_EXEC_PREFIX "/usr/libexec/" + +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/usr/lib" + +#if 0 /* This is very wrong!!! */ +#define DEFAULT_TARGET_MACHINE "i386-unknown-freebsd_1.0" +#define GPLUSPLUS_INCLUDE_DIR "/usr/local/lib/gcc-lib/i386-unknown-freebsd_1.0/2.5.8/include" +#define TOOL_INCLUDE_DIR "/usr/local/i386-unknown-freebsd_1.0/include" +#define GCC_INCLUDE_DIR "/usr/local/lib/gcc-lib/i386-unknown-freebsd_1.0/2.5.8/include" +#endif + +#endif /* FREEBSD_NATIVE */ diff --git a/contrib/gcc/config/i386/gas.h b/contrib/gcc/config/i386/gas.h new file mode 100644 index 00000000000..d02015723ba --- /dev/null +++ b/contrib/gcc/config/i386/gas.h @@ -0,0 +1,155 @@ +/* Definitions for Intel 386 running system V with gnu tools + Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Note that i386/seq-gas.h is a GAS configuration that does not use this + file. */ + +#include "i386/i386.h" + +#ifndef YES_UNDERSCORES +/* Define this now, because i386/bsd.h tests it. */ +#define NO_UNDERSCORES +#endif + +/* Use the bsd assembler syntax. */ +/* we need to do this because gas is really a bsd style assembler, + * and so doesn't work well this these att-isms: + * + * ASM_OUTPUT_SKIP is .set .,.+N, which isn't implemented in gas + * ASM_OUTPUT_LOCAL is done with .set .,.+N, but that can't be + * used to define bss static space + * + * Next is the question of whether to uses underscores. RMS didn't + * like this idea at first, but since it is now obvious that we + * need this separate tm file for use with gas, at least to get + * dbx debugging info, I think we should also switch to underscores. + * We can keep i386v for real att style output, and the few + * people who want both form will have to compile twice. + */ + +#include "i386/bsd.h" + +/* these come from i386/bsd.h, but are specific to sequent */ +#undef DBX_NO_XREFS +#undef DBX_CONTIN_LENGTH + +/* Ask for COFF symbols. */ + +#define SDB_DEBUGGING_INFO + +/* Specify predefined symbols in preprocessor. */ + +#define CPP_PREDEFINES "-Dunix -Di386 -Asystem(unix) -Acpu(i386) -Amachine(i386)" +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}" + +/* Allow #sccs in preprocessor. */ + +#define SCCS_DIRECTIVE + +/* Output #ident as a .ident. */ + +#define ASM_OUTPUT_IDENT(FILE, NAME) fprintf (FILE, "\t.ident \"%s\"\n", NAME); + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +#if 0 /* People say gas uses the log as the arg to .align. */ +/* When using gas, .align N aligns to an N-byte boundary. */ + +#undef ASM_OUTPUT_ALIGN +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG)) +#endif + +/* Align labels, etc. at 4-byte boundaries. + For the 486, align to 16-byte boundary for sake of cache. */ + +#undef ASM_OUTPUT_ALIGN_CODE +#define ASM_OUTPUT_ALIGN_CODE(FILE) \ + fprintf ((FILE), "\t.align %d,0x90\n", i386_align_jumps) + +/* Align start of loop at 4-byte boundary. */ + +#undef ASM_OUTPUT_LOOP_ALIGN +#define ASM_OUTPUT_LOOP_ALIGN(FILE) \ + fprintf ((FILE), "\t.align %d,0x90\n", i386_align_loops) + + +/* A C statement or statements which output an assembler instruction + opcode to the stdio stream STREAM. The macro-operand PTR is a + variable of type `char *' which points to the opcode name in its + "internal" form--the form that is written in the machine description. + + GAS version 1.38.1 doesn't understand the `repz' opcode mnemonic. + So use `repe' instead. */ + +#define ASM_OUTPUT_OPCODE(STREAM, PTR) \ +{ \ + if ((PTR)[0] == 'r' \ + && (PTR)[1] == 'e' \ + && (PTR)[2] == 'p') \ + { \ + if ((PTR)[3] == 'z') \ + { \ + fprintf (STREAM, "repe"); \ + (PTR) += 4; \ + } \ + else if ((PTR)[3] == 'n' && (PTR)[4] == 'z') \ + { \ + fprintf (STREAM, "repne"); \ + (PTR) += 5; \ + } \ + } \ +} + +/* Define macro used to output shift-double opcodes when the shift + count is in %cl. Some assemblers require %cl as an argument; + some don't. + + GAS requires the %cl argument, so override i386/unix.h. */ + +#undef AS3_SHIFT_DOUBLE +#define AS3_SHIFT_DOUBLE(a,b,c,d) AS3 (a,b,c,d) + +/* Print opcodes the way that GAS expects them. */ +#define GAS_MNEMONICS 1 + +#ifdef NO_UNDERSCORES /* If user-symbols don't have underscores, + then it must take more than `L' to identify + a label that should be ignored. */ + +/* This is how to store into the string BUF + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), ".%s%d", (PREFIX), (NUMBER)) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. */ + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM) + +#endif /* NO_UNDERSCORES */ diff --git a/contrib/gcc/config/i386/gnu.h b/contrib/gcc/config/i386/gnu.h new file mode 100644 index 00000000000..1ad5df991e4 --- /dev/null +++ b/contrib/gcc/config/i386/gnu.h @@ -0,0 +1,20 @@ +/* Configuration for an i386 running GNU with ELF as the target machine. */ + +/* This does it mostly for us. */ +#include + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES GNU_CPP_PREDEFINES("i386") + +#undef LINK_SPEC +#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ + %{!shared: \ + %{!ibcs: \ + %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!dynamic-linker:-dynamic-linker /lib/ld.so} \ + %{!rpath:-rpath /lib/}} %{static:-static}}}" + + +/* Get machine-independent configuration parameters for the GNU system. */ +#include diff --git a/contrib/gcc/config/i386/go32.h b/contrib/gcc/config/i386/go32.h new file mode 100644 index 00000000000..5618a0dd0fb --- /dev/null +++ b/contrib/gcc/config/i386/go32.h @@ -0,0 +1,64 @@ +/* Configuration for an i386 running MS-DOS with djgpp/go32. */ + +/* Don't assume anything about the header files. */ +#define NO_IMPLICIT_EXTERN_C + +#define HANDLE_SYSV_PRAGMA + +#define YES_UNDERSCORES + +#include "i386/gas.h" + +#ifdef CPP_PREDEFINES +#undef CPP_PREDEFINES +#endif +#define CPP_PREDEFINES "-Dunix -Di386 -DGO32 -DMSDOS \ + -Asystem(unix) -Asystem(msdos) -Acpu(i386) -Amachine(i386)" + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_ctor, in_dtor + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CTOR_SECTION_FUNCTION \ + DTOR_SECTION_FUNCTION + +#define CTOR_SECTION_FUNCTION \ +void \ +ctor_section () \ +{ \ + if (in_section != in_ctor) \ + { \ + fprintf (asm_out_file, "\t.section .ctor\n"); \ + in_section = in_ctor; \ + } \ +} + +#define DTOR_SECTION_FUNCTION \ +void \ +dtor_section () \ +{ \ + if (in_section != in_dtor) \ + { \ + fprintf (asm_out_file, "\t.section .dtor\n"); \ + in_section = in_dtor; \ + } \ +} + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + + diff --git a/contrib/gcc/config/i386/gstabs.h b/contrib/gcc/config/i386/gstabs.h new file mode 100644 index 00000000000..5f0ae348f15 --- /dev/null +++ b/contrib/gcc/config/i386/gstabs.h @@ -0,0 +1,9 @@ +#include "i386/gas.h" + +/* We do not want to output SDB debugging information. */ + +#undef SDB_DEBUGGING_INFO + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO diff --git a/contrib/gcc/config/i386/i386-aout.h b/contrib/gcc/config/i386/i386-aout.h new file mode 100644 index 00000000000..e4be8d5dd15 --- /dev/null +++ b/contrib/gcc/config/i386/i386-aout.h @@ -0,0 +1,34 @@ +/* Definitions for "naked" Intel 386 using a.out (or coff encap'd + a.out) object format and stabs debugging info. + + Copyright (C) 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This is tested by gas.h. */ +#define YES_UNDERSCORES + +#include "i386/gstabs.h" + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Di386" + +/* end of i386-aout.h */ diff --git a/contrib/gcc/config/i386/i386-coff.h b/contrib/gcc/config/i386/i386-coff.h new file mode 100644 index 00000000000..915e307d17b --- /dev/null +++ b/contrib/gcc/config/i386/i386-coff.h @@ -0,0 +1,97 @@ +/* Definitions for "naked" Intel 386 using coff object format files + and coff debugging info. + + Copyright (C) 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "i386/gas.h" + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Di386" + +#undef DBX_DEBUGGING_INFO +#define SDB_DEBUGGING_INFO + +/* Support the ctors and dtors sections for g++. */ + +#define CTORS_SECTION_ASM_OP ".section\t.ctors,\"x\"" +#define DTORS_SECTION_ASM_OP ".section\t.dtors,\"x\"" + +/* A list of other sections which the compiler might be "in" at any + given time. */ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_ctors, in_dtors + +/* A list of extra section function definitions. */ + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CTORS_SECTION_FUNCTION \ + DTORS_SECTION_FUNCTION + +#define CTORS_SECTION_FUNCTION \ +void \ +ctors_section () \ +{ \ + if (in_section != in_ctors) \ + { \ + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \ + in_section = in_ctors; \ + } \ +} + +#define DTORS_SECTION_FUNCTION \ +void \ +dtors_section () \ +{ \ + if (in_section != in_dtors) \ + { \ + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \ + in_section = in_dtors; \ + } \ +} + +#define INT_ASM_OP ".long" + +/* A C statement (sans semicolon) to output an element in the table of + global constructors. */ +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + + +/* end of i386-coff.h */ diff --git a/contrib/gcc/config/i386/i386.c b/contrib/gcc/config/i386/i386.c new file mode 100644 index 00000000000..48c58a09d8e --- /dev/null +++ b/contrib/gcc/config/i386/i386.c @@ -0,0 +1,3245 @@ +/* Subroutines for insn-output.c for Intel X86. + Copyright (C) 1988, 1992, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include +#include +#include "config.h" +#include "rtl.h" +#include "regs.h" +#include "hard-reg-set.h" +#include "real.h" +#include "insn-config.h" +#include "conditions.h" +#include "insn-flags.h" +#include "output.h" +#include "insn-attr.h" +#include "tree.h" +#include "flags.h" +#include "function.h" + +#ifdef EXTRA_CONSTRAINT +/* If EXTRA_CONSTRAINT is defined, then the 'S' + constraint in REG_CLASS_FROM_LETTER will no longer work, and various + asm statements that need 'S' for class SIREG will break. */ + error EXTRA_CONSTRAINT conflicts with S constraint letter +/* The previous line used to be #error, but some compilers barf + even if the conditional was untrue. */ +#endif + +#define AT_BP(mode) (gen_rtx (MEM, (mode), frame_pointer_rtx)) + +extern FILE *asm_out_file; +extern char *strcat (); + +char *singlemove_string (); +char *output_move_const_single (); +char *output_fp_cc0_set (); + +char *hi_reg_name[] = HI_REGISTER_NAMES; +char *qi_reg_name[] = QI_REGISTER_NAMES; +char *qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES; + +/* Array of the smallest class containing reg number REGNO, indexed by + REGNO. Used by REGNO_REG_CLASS in i386.h. */ + +enum reg_class regclass_map[FIRST_PSEUDO_REGISTER] = +{ + /* ax, dx, cx, bx */ + AREG, DREG, CREG, BREG, + /* si, di, bp, sp */ + SIREG, DIREG, INDEX_REGS, GENERAL_REGS, + /* FP registers */ + FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS, + FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, + /* arg pointer */ + INDEX_REGS +}; + +/* Test and compare insns in i386.md store the information needed to + generate branch and scc insns here. */ + +struct rtx_def *i386_compare_op0 = NULL_RTX; +struct rtx_def *i386_compare_op1 = NULL_RTX; +struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)(); + +/* Register allocation order */ +char *i386_reg_alloc_order; +static char regs_allocated[FIRST_PSEUDO_REGISTER]; + +/* # of registers to use to pass arguments. */ +char *i386_regparm_string; /* # registers to use to pass args */ +int i386_regparm; /* i386_regparm_string as a number */ + +/* Alignment to use for loops and jumps */ +char *i386_align_loops_string; /* power of two alignment for loops */ +char *i386_align_jumps_string; /* power of two alignment for non-loop jumps */ +char *i386_align_funcs_string; /* power of two alignment for functions */ + +int i386_align_loops; /* power of two alignment for loops */ +int i386_align_jumps; /* power of two alignment for non-loop jumps */ +int i386_align_funcs; /* power of two alignment for functions */ + + +/* Sometimes certain combinations of command options do not make + sense on a particular target machine. You can define a macro + `OVERRIDE_OPTIONS' to take account of this. This macro, if + defined, is executed once just after all the command options have + been parsed. + + Don't use this macro to turn on various extra optimizations for + `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */ + +void +override_options () +{ + int ch, i, regno; + char *p; + int def_align; + +#ifdef SUBTARGET_OVERRIDE_OPTIONS + SUBTARGET_OVERRIDE_OPTIONS; +#endif + + /* Validate registers in register allocation order */ + if (i386_reg_alloc_order) + { + for (i = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++) + { + switch (ch) + { + case 'a': regno = 0; break; + case 'd': regno = 1; break; + case 'c': regno = 2; break; + case 'b': regno = 3; break; + case 'S': regno = 4; break; + case 'D': regno = 5; break; + case 'B': regno = 6; break; + + default: fatal ("Register '%c' is unknown", ch); + } + + if (regs_allocated[regno]) + fatal ("Register '%c' was already specified in the allocation order", ch); + + regs_allocated[regno] = 1; + } + } + + /* Validate -mregparm= value */ + if (i386_regparm_string) + { + i386_regparm = atoi (i386_regparm_string); + if (i386_regparm < 0 || i386_regparm > REGPARM_MAX) + fatal ("-mregparm=%d is not between 0 and %d", i386_regparm, REGPARM_MAX); + } + + def_align = (TARGET_386) ? 2 : 4; + + /* Validate -malign-loops= value, or provide default */ + if (i386_align_loops_string) + { + i386_align_loops = atoi (i386_align_loops_string); + if (i386_align_loops < 0 || i386_align_loops > MAX_CODE_ALIGN) + fatal ("-malign-loops=%d is not between 0 and %d", + i386_align_loops, MAX_CODE_ALIGN); + } + else + i386_align_loops = 2; + + /* Validate -malign-jumps= value, or provide default */ + if (i386_align_jumps_string) + { + i386_align_jumps = atoi (i386_align_jumps_string); + if (i386_align_jumps < 0 || i386_align_jumps > MAX_CODE_ALIGN) + fatal ("-malign-jumps=%d is not between 0 and %d", + i386_align_jumps, MAX_CODE_ALIGN); + } + else + i386_align_jumps = def_align; + + /* Validate -malign-functions= value, or provide default */ + if (i386_align_funcs_string) + { + i386_align_funcs = atoi (i386_align_funcs_string); + if (i386_align_funcs < 0 || i386_align_funcs > MAX_CODE_ALIGN) + fatal ("-malign-functions=%d is not between 0 and %d", + i386_align_funcs, MAX_CODE_ALIGN); + } + else + i386_align_funcs = def_align; +} + +/* A C statement (sans semicolon) to choose the order in which to + allocate hard registers for pseudo-registers local to a basic + block. + + Store the desired register order in the array `reg_alloc_order'. + Element 0 should be the register to allocate first; element 1, the + next register; and so on. + + The macro body should not assume anything about the contents of + `reg_alloc_order' before execution of the macro. + + On most machines, it is not necessary to define this macro. */ + +void +order_regs_for_local_alloc () +{ + int i, ch, order, regno; + + /* User specified the register allocation order */ + if (i386_reg_alloc_order) + { + for (i = order = 0; (ch = i386_reg_alloc_order[i]) != '\0'; i++) + { + switch (ch) + { + case 'a': regno = 0; break; + case 'd': regno = 1; break; + case 'c': regno = 2; break; + case 'b': regno = 3; break; + case 'S': regno = 4; break; + case 'D': regno = 5; break; + case 'B': regno = 6; break; + } + + reg_alloc_order[order++] = regno; + } + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + { + if (!regs_allocated[i]) + reg_alloc_order[order++] = i; + } + } + + /* If users did not specify a register allocation order, favor eax + normally except if DImode variables are used, in which case + favor edx before eax, which seems to cause less spill register + not found messages. */ + else + { + rtx insn; + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + reg_alloc_order[i] = i; + + if (optimize) + { + int use_dca = FALSE; + + for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) + { + if (GET_CODE (insn) == INSN) + { + rtx set = NULL_RTX; + rtx pattern = PATTERN (insn); + + if (GET_CODE (pattern) == SET) + set = pattern; + + else if ((GET_CODE (pattern) == PARALLEL + || GET_CODE (pattern) == SEQUENCE) + && GET_CODE (XVECEXP (pattern, 0, 0)) == SET) + set = XVECEXP (pattern, 0, 0); + + if (set && GET_MODE (SET_SRC (set)) == DImode) + { + use_dca = TRUE; + break; + } + } + } + + if (use_dca) + { + reg_alloc_order[0] = 1; /* edx */ + reg_alloc_order[1] = 2; /* ecx */ + reg_alloc_order[2] = 0; /* eax */ + } + } + } +} + + +/* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific + attribute for DECL. The attributes in ATTRIBUTES have previously been + assigned to DECL. */ + +int +i386_valid_decl_attribute_p (decl, attributes, identifier, args) + tree decl; + tree attributes; + tree identifier; + tree args; +{ + return 0; +} + +/* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific + attribute for TYPE. The attributes in ATTRIBUTES have previously been + assigned to TYPE. */ + +int +i386_valid_type_attribute_p (type, attributes, identifier, args) + tree type; + tree attributes; + tree identifier; + tree args; +{ + if (TREE_CODE (type) != FUNCTION_TYPE + && TREE_CODE (type) != FIELD_DECL + && TREE_CODE (type) != TYPE_DECL) + return 0; + + /* Stdcall attribute says callee is responsible for popping arguments + if they are not variable. */ + if (is_attribute_p ("stdcall", identifier)) + return (args == NULL_TREE); + + /* Cdecl attribute says the callee is a normal C declaration */ + if (is_attribute_p ("cdecl", identifier)) + return (args == NULL_TREE); + + /* Regparm attribute specifies how many integer arguments are to be + passed in registers */ + if (is_attribute_p ("regparm", identifier)) + { + tree cst; + + if (!args || TREE_CODE (args) != TREE_LIST + || TREE_CHAIN (args) != NULL_TREE + || TREE_VALUE (args) == NULL_TREE) + return 0; + + cst = TREE_VALUE (args); + if (TREE_CODE (cst) != INTEGER_CST) + return 0; + + if (TREE_INT_CST_HIGH (cst) != 0 + || TREE_INT_CST_LOW (cst) < 0 + || TREE_INT_CST_LOW (cst) > REGPARM_MAX) + return 0; + + return 1; + } + + return 0; +} + +/* Return 0 if the attributes for two types are incompatible, 1 if they + are compatible, and 2 if they are nearly compatible (which causes a + warning to be generated). */ + +int +i386_comp_type_attributes (type1, type2) + tree type1; + tree type2; +{ + return 1; +} + + +/* Value is the number of bytes of arguments automatically + popped when returning from a subroutine call. + FUNDECL is the declaration node of the function (as a tree), + FUNTYPE is the data type of the function (as a tree), + or for a library call it is an identifier node for the subroutine name. + SIZE is the number of bytes of arguments passed on the stack. + + On the 80386, the RTD insn may be used to pop them if the number + of args is fixed, but if the number is variable then the caller + must pop them all. RTD can't be used for library calls now + because the library is compiled with the Unix compiler. + Use of RTD is a selectable option, since it is incompatible with + standard Unix calling sequences. If the option is not selected, + the caller must always pop the args. + + The attribute stdcall is equivalent to RTD on a per module basis. */ + +int +i386_return_pops_args (fundecl, funtype, size) + tree fundecl; + tree funtype; + int size; +{ + int rtd = TARGET_RTD; + + if (TREE_CODE (funtype) == IDENTIFIER_NODE) + return 0; + + /* Cdecl functions override -mrtd, and never pop the stack */ + if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) + return 0; + + /* Stdcall functions will pop the stack if not variable args */ + if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))) + rtd = 1; + + if (rtd) + { + if (TYPE_ARG_TYPES (funtype) == NULL_TREE + || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype))) == void_type_node)) + return size; + + if (aggregate_value_p (TREE_TYPE (funtype))) + return GET_MODE_SIZE (Pmode); + } + + return 0; +} + + +/* Argument support functions. */ + +/* Initialize a variable CUM of type CUMULATIVE_ARGS + for a call to a function whose data type is FNTYPE. + For a library call, FNTYPE is 0. */ + +void +init_cumulative_args (cum, fntype, libname) + CUMULATIVE_ARGS *cum; /* argument info to initialize */ + tree fntype; /* tree ptr for function decl */ + rtx libname; /* SYMBOL_REF of library name or 0 */ +{ + static CUMULATIVE_ARGS zero_cum; + tree param, next_param; + + if (TARGET_DEBUG_ARG) + { + fprintf (stderr, "\ninit_cumulative_args ("); + if (fntype) + { + tree ret_type = TREE_TYPE (fntype); + fprintf (stderr, "fntype code = %s, ret code = %s", + tree_code_name[ (int)TREE_CODE (fntype) ], + tree_code_name[ (int)TREE_CODE (ret_type) ]); + } + else + fprintf (stderr, "no fntype"); + + if (libname) + fprintf (stderr, ", libname = %s", XSTR (libname, 0)); + } + + *cum = zero_cum; + + /* Set up the number of registers to use for passing arguments. */ + cum->nregs = i386_regparm; + if (fntype) + { + tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype)); + if (attr) + cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))); + } + + /* Determine if this function has variable arguments. This is + indicated by the last argument being 'void_type_mode' if there + are no variable arguments. If there are variable arguments, then + we won't pass anything in registers */ + + if (cum->nregs) + { + for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0; + param != (tree)0; + param = next_param) + { + next_param = TREE_CHAIN (param); + if (next_param == (tree)0 && TREE_VALUE (param) != void_type_node) + cum->nregs = 0; + } + } + + if (TARGET_DEBUG_ARG) + fprintf (stderr, ", nregs=%d )\n", cum->nregs); + + return; +} + +/* Update the data in CUM to advance over an argument + of mode MODE and data type TYPE. + (TYPE is null for libcalls where that information may not be available.) */ + +void +function_arg_advance (cum, mode, type, named) + CUMULATIVE_ARGS *cum; /* current arg information */ + enum machine_mode mode; /* current arg mode */ + tree type; /* type of the argument or 0 if lib support */ + int named; /* whether or not the argument was named */ +{ + int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode); + int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; + + if (TARGET_DEBUG_ARG) + fprintf (stderr, + "function_adv( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d )\n\n", + words, cum->words, cum->nregs, GET_MODE_NAME (mode), named); + + cum->words += words; + cum->nregs -= words; + cum->regno += words; + + if (cum->nregs <= 0) + { + cum->nregs = 0; + cum->regno = 0; + } + + return; +} + +/* Define where to put the arguments to a function. + Value is zero to push the argument on the stack, + or a hard register in which to store the argument. + + MODE is the argument's machine mode. + TYPE is the data type of the argument (as a tree). + This is null for libcalls where that information may + not be available. + CUM is a variable of type CUMULATIVE_ARGS which gives info about + the preceding args and about the function being called. + NAMED is nonzero if this argument is a named parameter + (otherwise it is an extra parameter matching an ellipsis). */ + +struct rtx_def * +function_arg (cum, mode, type, named) + CUMULATIVE_ARGS *cum; /* current arg information */ + enum machine_mode mode; /* current arg mode */ + tree type; /* type of the argument or 0 if lib support */ + int named; /* != 0 for normal args, == 0 for ... args */ +{ + rtx ret = NULL_RTX; + int bytes = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode); + int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; + + switch (mode) + { + default: /* for now, pass fp/complex values on the stack */ + break; + + case BLKmode: + case DImode: + case SImode: + case HImode: + case QImode: + if (words <= cum->nregs) + ret = gen_rtx (REG, mode, cum->regno); + break; + } + + if (TARGET_DEBUG_ARG) + { + fprintf (stderr, + "function_arg( size=%d, words=%2d, nregs=%d, mode=%4s, named=%d", + words, cum->words, cum->nregs, GET_MODE_NAME (mode), named); + + if (ret) + fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]); + else + fprintf (stderr, ", stack"); + + fprintf (stderr, " )\n"); + } + + return ret; +} + +/* For an arg passed partly in registers and partly in memory, + this is the number of registers used. + For args passed entirely in registers or entirely in memory, zero. */ + +int +function_arg_partial_nregs (cum, mode, type, named) + CUMULATIVE_ARGS *cum; /* current arg information */ + enum machine_mode mode; /* current arg mode */ + tree type; /* type of the argument or 0 if lib support */ + int named; /* != 0 for normal args, == 0 for ... args */ +{ + return 0; +} + + +/* Output an insn whose source is a 386 integer register. SRC is the + rtx for the register, and TEMPLATE is the op-code template. SRC may + be either SImode or DImode. + + The template will be output with operands[0] as SRC, and operands[1] + as a pointer to the top of the 386 stack. So a call from floatsidf2 + would look like this: + + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + + where %z0 corresponds to the caller's operands[1], and is used to + emit the proper size suffix. + + ??? Extend this to handle HImode - a 387 can load and store HImode + values directly. */ + +void +output_op_from_reg (src, template) + rtx src; + char *template; +{ + rtx xops[4]; + int size = GET_MODE_SIZE (GET_MODE (src)); + + xops[0] = src; + xops[1] = AT_SP (Pmode); + xops[2] = GEN_INT (size); + xops[3] = stack_pointer_rtx; + + if (size > UNITS_PER_WORD) + { + rtx high; + if (size > 2 * UNITS_PER_WORD) + { + high = gen_rtx (REG, SImode, REGNO (src) + 2); + output_asm_insn (AS1 (push%L0,%0), &high); + } + high = gen_rtx (REG, SImode, REGNO (src) + 1); + output_asm_insn (AS1 (push%L0,%0), &high); + } + output_asm_insn (AS1 (push%L0,%0), &src); + + output_asm_insn (template, xops); + + output_asm_insn (AS2 (add%L3,%2,%3), xops); +} + +/* Output an insn to pop an value from the 387 top-of-stack to 386 + register DEST. The 387 register stack is popped if DIES is true. If + the mode of DEST is an integer mode, a `fist' integer store is done, + otherwise a `fst' float store is done. */ + +void +output_to_reg (dest, dies) + rtx dest; + int dies; +{ + rtx xops[4]; + int size = GET_MODE_SIZE (GET_MODE (dest)); + + xops[0] = AT_SP (Pmode); + xops[1] = stack_pointer_rtx; + xops[2] = GEN_INT (size); + xops[3] = dest; + + output_asm_insn (AS2 (sub%L1,%2,%1), xops); + + if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_INT) + { + if (dies) + output_asm_insn (AS1 (fistp%z3,%y0), xops); + else + output_asm_insn (AS1 (fist%z3,%y0), xops); + } + else if (GET_MODE_CLASS (GET_MODE (dest)) == MODE_FLOAT) + { + if (dies) + output_asm_insn (AS1 (fstp%z3,%y0), xops); + else + { + if (GET_MODE (dest) == XFmode) + { + output_asm_insn (AS1 (fstp%z3,%y0), xops); + output_asm_insn (AS1 (fld%z3,%y0), xops); + } + else + output_asm_insn (AS1 (fst%z3,%y0), xops); + } + } + else + abort (); + + output_asm_insn (AS1 (pop%L0,%0), &dest); + + if (size > UNITS_PER_WORD) + { + dest = gen_rtx (REG, SImode, REGNO (dest) + 1); + output_asm_insn (AS1 (pop%L0,%0), &dest); + if (size > 2 * UNITS_PER_WORD) + { + dest = gen_rtx (REG, SImode, REGNO (dest) + 1); + output_asm_insn (AS1 (pop%L0,%0), &dest); + } + } +} + +char * +singlemove_string (operands) + rtx *operands; +{ + rtx x; + if (GET_CODE (operands[0]) == MEM + && GET_CODE (x = XEXP (operands[0], 0)) == PRE_DEC) + { + if (XEXP (x, 0) != stack_pointer_rtx) + abort (); + return "push%L1 %1"; + } + else if (GET_CODE (operands[1]) == CONST_DOUBLE) + { + return output_move_const_single (operands); + } + else if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == REG) + return AS2 (mov%L0,%1,%0); + else if (CONSTANT_P (operands[1])) + return AS2 (mov%L0,%1,%0); + else + { + output_asm_insn ("push%L1 %1", operands); + return "pop%L0 %0"; + } +} + +/* Return a REG that occurs in ADDR with coefficient 1. + ADDR can be effectively incremented by incrementing REG. */ + +static rtx +find_addr_reg (addr) + rtx addr; +{ + while (GET_CODE (addr) == PLUS) + { + if (GET_CODE (XEXP (addr, 0)) == REG) + addr = XEXP (addr, 0); + else if (GET_CODE (XEXP (addr, 1)) == REG) + addr = XEXP (addr, 1); + else if (CONSTANT_P (XEXP (addr, 0))) + addr = XEXP (addr, 1); + else if (CONSTANT_P (XEXP (addr, 1))) + addr = XEXP (addr, 0); + else + abort (); + } + if (GET_CODE (addr) == REG) + return addr; + abort (); +} + + +/* Output an insn to add the constant N to the register X. */ + +static void +asm_add (n, x) + int n; + rtx x; +{ + rtx xops[2]; + xops[0] = x; + + if (n == -1) + output_asm_insn (AS1 (dec%L0,%0), xops); + else if (n == 1) + output_asm_insn (AS1 (inc%L0,%0), xops); + else if (n < 0) + { + xops[1] = GEN_INT (-n); + output_asm_insn (AS2 (sub%L0,%1,%0), xops); + } + else if (n > 0) + { + xops[1] = GEN_INT (n); + output_asm_insn (AS2 (add%L0,%1,%0), xops); + } +} + + +/* Output assembler code to perform a doubleword move insn + with operands OPERANDS. */ + +char * +output_move_double (operands) + rtx *operands; +{ + enum {REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP } optype0, optype1; + rtx latehalf[2]; + rtx middlehalf[2]; + rtx xops[2]; + rtx addreg0 = 0, addreg1 = 0; + int dest_overlapped_low = 0; + int size = GET_MODE_SIZE (GET_MODE (operands[0])); + + middlehalf[0] = 0; + middlehalf[1] = 0; + + /* First classify both operands. */ + + if (REG_P (operands[0])) + optype0 = REGOP; + else if (offsettable_memref_p (operands[0])) + optype0 = OFFSOP; + else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC) + optype0 = POPOP; + else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) + optype0 = PUSHOP; + else if (GET_CODE (operands[0]) == MEM) + optype0 = MEMOP; + else + optype0 = RNDOP; + + if (REG_P (operands[1])) + optype1 = REGOP; + else if (CONSTANT_P (operands[1])) + optype1 = CNSTOP; + else if (offsettable_memref_p (operands[1])) + optype1 = OFFSOP; + else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC) + optype1 = POPOP; + else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC) + optype1 = PUSHOP; + else if (GET_CODE (operands[1]) == MEM) + optype1 = MEMOP; + else + optype1 = RNDOP; + + /* Check for the cases that the operand constraints are not + supposed to allow to happen. Abort if we get one, + because generating code for these cases is painful. */ + + if (optype0 == RNDOP || optype1 == RNDOP) + abort (); + + /* If one operand is decrementing and one is incrementing + decrement the former register explicitly + and change that operand into ordinary indexing. */ + + if (optype0 == PUSHOP && optype1 == POPOP) + { + /* ??? Can this ever happen on i386? */ + operands[0] = XEXP (XEXP (operands[0], 0), 0); + asm_add (-size, operands[0]); + if (GET_MODE (operands[1]) == XFmode) + operands[0] = gen_rtx (MEM, XFmode, operands[0]); + else if (GET_MODE (operands[0]) == DFmode) + operands[0] = gen_rtx (MEM, DFmode, operands[0]); + else + operands[0] = gen_rtx (MEM, DImode, operands[0]); + optype0 = OFFSOP; + } + + if (optype0 == POPOP && optype1 == PUSHOP) + { + /* ??? Can this ever happen on i386? */ + operands[1] = XEXP (XEXP (operands[1], 0), 0); + asm_add (-size, operands[1]); + if (GET_MODE (operands[1]) == XFmode) + operands[1] = gen_rtx (MEM, XFmode, operands[1]); + else if (GET_MODE (operands[1]) == DFmode) + operands[1] = gen_rtx (MEM, DFmode, operands[1]); + else + operands[1] = gen_rtx (MEM, DImode, operands[1]); + optype1 = OFFSOP; + } + + /* If an operand is an unoffsettable memory ref, find a register + we can increment temporarily to make it refer to the second word. */ + + if (optype0 == MEMOP) + addreg0 = find_addr_reg (XEXP (operands[0], 0)); + + if (optype1 == MEMOP) + addreg1 = find_addr_reg (XEXP (operands[1], 0)); + + /* Ok, we can do one word at a time. + Normally we do the low-numbered word first, + but if either operand is autodecrementing then we + do the high-numbered word first. + + In either case, set up in LATEHALF the operands to use + for the high-numbered word and in some cases alter the + operands in OPERANDS to be suitable for the low-numbered word. */ + + if (size == 12) + { + if (optype0 == REGOP) + { + middlehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1); + latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 2); + } + else if (optype0 == OFFSOP) + { + middlehalf[0] = adj_offsettable_operand (operands[0], 4); + latehalf[0] = adj_offsettable_operand (operands[0], 8); + } + else + { + middlehalf[0] = operands[0]; + latehalf[0] = operands[0]; + } + + if (optype1 == REGOP) + { + middlehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1); + latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 2); + } + else if (optype1 == OFFSOP) + { + middlehalf[1] = adj_offsettable_operand (operands[1], 4); + latehalf[1] = adj_offsettable_operand (operands[1], 8); + } + else if (optype1 == CNSTOP) + { + if (GET_CODE (operands[1]) == CONST_DOUBLE) + { + REAL_VALUE_TYPE r; long l[3]; + + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]); + REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l); + operands[1] = GEN_INT (l[0]); + middlehalf[1] = GEN_INT (l[1]); + latehalf[1] = GEN_INT (l[2]); + } + else if (CONSTANT_P (operands[1])) + /* No non-CONST_DOUBLE constant should ever appear here. */ + abort (); + } + else + { + middlehalf[1] = operands[1]; + latehalf[1] = operands[1]; + } + } + else /* size is not 12: */ + { + if (optype0 == REGOP) + latehalf[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1); + else if (optype0 == OFFSOP) + latehalf[0] = adj_offsettable_operand (operands[0], 4); + else + latehalf[0] = operands[0]; + + if (optype1 == REGOP) + latehalf[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1); + else if (optype1 == OFFSOP) + latehalf[1] = adj_offsettable_operand (operands[1], 4); + else if (optype1 == CNSTOP) + split_double (operands[1], &operands[1], &latehalf[1]); + else + latehalf[1] = operands[1]; + } + + /* If insn is effectively movd N (sp),-(sp) then we will do the + high word first. We should use the adjusted operand 1 + (which is N+4 (sp) or N+8 (sp)) + for the low word and middle word as well, + to compensate for the first decrement of sp. */ + if (optype0 == PUSHOP + && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM + && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1])) + middlehalf[1] = operands[1] = latehalf[1]; + + /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)), + if the upper part of reg N does not appear in the MEM, arrange to + emit the move late-half first. Otherwise, compute the MEM address + into the upper part of N and use that as a pointer to the memory + operand. */ + if (optype0 == REGOP + && (optype1 == OFFSOP || optype1 == MEMOP)) + { + if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)) + && reg_mentioned_p (latehalf[0], XEXP (operands[1], 0))) + { + /* If both halves of dest are used in the src memory address, + compute the address into latehalf of dest. */ +compadr: + xops[0] = latehalf[0]; + xops[1] = XEXP (operands[1], 0); + output_asm_insn (AS2 (lea%L0,%a1,%0), xops); + if( GET_MODE (operands[1]) == XFmode ) + { +/* abort (); */ + operands[1] = gen_rtx (MEM, XFmode, latehalf[0]); + middlehalf[1] = adj_offsettable_operand (operands[1], size-8); + latehalf[1] = adj_offsettable_operand (operands[1], size-4); + } + else + { + operands[1] = gen_rtx (MEM, DImode, latehalf[0]); + latehalf[1] = adj_offsettable_operand (operands[1], size-4); + } + } + else if (size == 12 + && reg_mentioned_p (middlehalf[0], XEXP (operands[1], 0))) + { + /* Check for two regs used by both source and dest. */ + if (reg_mentioned_p (operands[0], XEXP (operands[1], 0)) + || reg_mentioned_p (latehalf[0], XEXP (operands[1], 0))) + goto compadr; + + /* JRV says this can't happen: */ + if (addreg0 || addreg1) + abort(); + + /* Only the middle reg conflicts; simply put it last. */ + output_asm_insn (singlemove_string (operands), operands); + output_asm_insn (singlemove_string (latehalf), latehalf); + output_asm_insn (singlemove_string (middlehalf), middlehalf); + return ""; + } + else if (reg_mentioned_p (operands[0], XEXP (operands[1], 0))) + /* If the low half of dest is mentioned in the source memory + address, the arrange to emit the move late half first. */ + dest_overlapped_low = 1; + } + + /* If one or both operands autodecrementing, + do the two words, high-numbered first. */ + + /* Likewise, the first move would clobber the source of the second one, + do them in the other order. This happens only for registers; + such overlap can't happen in memory unless the user explicitly + sets it up, and that is an undefined circumstance. */ + +/* + if (optype0 == PUSHOP || optype1 == PUSHOP + || (optype0 == REGOP && optype1 == REGOP + && REGNO (operands[0]) == REGNO (latehalf[1])) + || dest_overlapped_low) +*/ + if (optype0 == PUSHOP || optype1 == PUSHOP + || (optype0 == REGOP && optype1 == REGOP + && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1])) + || REGNO (operands[0]) == REGNO (latehalf[1]))) + || dest_overlapped_low) + { + /* Make any unoffsettable addresses point at high-numbered word. */ + if (addreg0) + asm_add (size-4, addreg0); + if (addreg1) + asm_add (size-4, addreg1); + + /* Do that word. */ + output_asm_insn (singlemove_string (latehalf), latehalf); + + /* Undo the adds we just did. */ + if (addreg0) + asm_add (-4, addreg0); + if (addreg1) + asm_add (-4, addreg1); + + if (size == 12) + { + output_asm_insn (singlemove_string (middlehalf), middlehalf); + if (addreg0) + asm_add (-4, addreg0); + if (addreg1) + asm_add (-4, addreg1); + } + + /* Do low-numbered word. */ + return singlemove_string (operands); + } + + /* Normal case: do the two words, low-numbered first. */ + + output_asm_insn (singlemove_string (operands), operands); + + /* Do the middle one of the three words for long double */ + if (size == 12) + { + if (addreg0) + asm_add (4, addreg0); + if (addreg1) + asm_add (4, addreg1); + + output_asm_insn (singlemove_string (middlehalf), middlehalf); + } + + /* Make any unoffsettable addresses point at high-numbered word. */ + if (addreg0) + asm_add (4, addreg0); + if (addreg1) + asm_add (4, addreg1); + + /* Do that word. */ + output_asm_insn (singlemove_string (latehalf), latehalf); + + /* Undo the adds we just did. */ + if (addreg0) + asm_add (4-size, addreg0); + if (addreg1) + asm_add (4-size, addreg1); + + return ""; +} + + +#define MAX_TMPS 2 /* max temporary registers used */ + +/* Output the appropriate code to move push memory on the stack */ + +char * +output_move_pushmem (operands, insn, length, tmp_start, n_operands) + rtx operands[]; + rtx insn; + int length; + int tmp_start; + int n_operands; +{ + + struct { + char *load; + char *push; + rtx xops[2]; + } tmp_info[MAX_TMPS]; + + rtx src = operands[1]; + int max_tmps = 0; + int offset = 0; + int stack_p = reg_overlap_mentioned_p (stack_pointer_rtx, src); + int stack_offset = 0; + int i, num_tmps; + rtx xops[1]; + + if (!offsettable_memref_p (src)) + fatal_insn ("Source is not offsettable", insn); + + if ((length & 3) != 0) + fatal_insn ("Pushing non-word aligned size", insn); + + /* Figure out which temporary registers we have available */ + for (i = tmp_start; i < n_operands; i++) + { + if (GET_CODE (operands[i]) == REG) + { + if (reg_overlap_mentioned_p (operands[i], src)) + continue; + + tmp_info[ max_tmps++ ].xops[1] = operands[i]; + if (max_tmps == MAX_TMPS) + break; + } + } + + if (max_tmps == 0) + for (offset = length - 4; offset >= 0; offset -= 4) + { + xops[0] = adj_offsettable_operand (src, offset + stack_offset); + output_asm_insn (AS1(push%L0,%0), xops); + if (stack_p) + stack_offset += 4; + } + + else + for (offset = length - 4; offset >= 0; ) + { + for (num_tmps = 0; num_tmps < max_tmps && offset >= 0; num_tmps++) + { + tmp_info[num_tmps].load = AS2(mov%L0,%0,%1); + tmp_info[num_tmps].push = AS1(push%L0,%1); + tmp_info[num_tmps].xops[0] = adj_offsettable_operand (src, offset + stack_offset); + offset -= 4; + } + + for (i = 0; i < num_tmps; i++) + output_asm_insn (tmp_info[i].load, tmp_info[i].xops); + + for (i = 0; i < num_tmps; i++) + output_asm_insn (tmp_info[i].push, tmp_info[i].xops); + + if (stack_p) + stack_offset += 4*num_tmps; + } + + return ""; +} + + + +/* Output the appropriate code to move data between two memory locations */ + +char * +output_move_memory (operands, insn, length, tmp_start, n_operands) + rtx operands[]; + rtx insn; + int length; + int tmp_start; + int n_operands; +{ + struct { + char *load; + char *store; + rtx xops[3]; + } tmp_info[MAX_TMPS]; + + rtx dest = operands[0]; + rtx src = operands[1]; + rtx qi_tmp = NULL_RTX; + int max_tmps = 0; + int offset = 0; + int i, num_tmps; + rtx xops[3]; + + if (GET_CODE (dest) == MEM + && GET_CODE (XEXP (dest, 0)) == PRE_INC + && XEXP (XEXP (dest, 0), 0) == stack_pointer_rtx) + return output_move_pushmem (operands, insn, length, tmp_start, n_operands); + + if (!offsettable_memref_p (src)) + fatal_insn ("Source is not offsettable", insn); + + if (!offsettable_memref_p (dest)) + fatal_insn ("Destination is not offsettable", insn); + + /* Figure out which temporary registers we have available */ + for (i = tmp_start; i < n_operands; i++) + { + if (GET_CODE (operands[i]) == REG) + { + if ((length & 1) != 0 && !qi_tmp && QI_REG_P (operands[i])) + qi_tmp = operands[i]; + + if (reg_overlap_mentioned_p (operands[i], dest)) + fatal_insn ("Temporary register overlaps the destination", insn); + + if (reg_overlap_mentioned_p (operands[i], src)) + fatal_insn ("Temporary register overlaps the source", insn); + + tmp_info[ max_tmps++ ].xops[2] = operands[i]; + if (max_tmps == MAX_TMPS) + break; + } + } + + if (max_tmps == 0) + fatal_insn ("No scratch registers were found to do memory->memory moves", insn); + + if ((length & 1) != 0) + { + if (!qi_tmp) + fatal_insn ("No byte register found when moving odd # of bytes.", insn); + } + + while (length > 1) + { + for (num_tmps = 0; num_tmps < max_tmps; num_tmps++) + { + if (length >= 4) + { + tmp_info[num_tmps].load = AS2(mov%L0,%1,%2); + tmp_info[num_tmps].store = AS2(mov%L0,%2,%0); + tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset); + tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset); + offset += 4; + length -= 4; + } + else if (length >= 2) + { + tmp_info[num_tmps].load = AS2(mov%W0,%1,%2); + tmp_info[num_tmps].store = AS2(mov%W0,%2,%0); + tmp_info[num_tmps].xops[0] = adj_offsettable_operand (dest, offset); + tmp_info[num_tmps].xops[1] = adj_offsettable_operand (src, offset); + offset += 2; + length -= 2; + } + else + break; + } + + for (i = 0; i < num_tmps; i++) + output_asm_insn (tmp_info[i].load, tmp_info[i].xops); + + for (i = 0; i < num_tmps; i++) + output_asm_insn (tmp_info[i].store, tmp_info[i].xops); + } + + if (length == 1) + { + xops[0] = adj_offsettable_operand (dest, offset); + xops[1] = adj_offsettable_operand (src, offset); + xops[2] = qi_tmp; + output_asm_insn (AS2(mov%B0,%1,%2), xops); + output_asm_insn (AS2(mov%B0,%2,%0), xops); + } + + return ""; +} + + +int +standard_80387_constant_p (x) + rtx x; +{ +#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) + REAL_VALUE_TYPE d; + jmp_buf handler; + int is0, is1; + + if (setjmp (handler)) + return 0; + + set_float_handler (handler); + REAL_VALUE_FROM_CONST_DOUBLE (d, x); + is0 = REAL_VALUES_EQUAL (d, dconst0); + is1 = REAL_VALUES_EQUAL (d, dconst1); + set_float_handler (NULL_PTR); + + if (is0) + return 1; + + if (is1) + return 2; + + /* Note that on the 80387, other constants, such as pi, + are much slower to load as standard constants + than to load from doubles in memory! */ +#endif + + return 0; +} + +char * +output_move_const_single (operands) + rtx *operands; +{ + if (FP_REG_P (operands[0])) + { + int conval = standard_80387_constant_p (operands[1]); + + if (conval == 1) + return "fldz"; + + if (conval == 2) + return "fld1"; + } + if (GET_CODE (operands[1]) == CONST_DOUBLE) + { + REAL_VALUE_TYPE r; long l; + + if (GET_MODE (operands[1]) == XFmode) + abort (); + + REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]); + REAL_VALUE_TO_TARGET_SINGLE (r, l); + operands[1] = GEN_INT (l); + } + return singlemove_string (operands); +} + +/* Returns 1 if OP is either a symbol reference or a sum of a symbol + reference and a constant. */ + +int +symbolic_operand (op, mode) + register rtx op; + enum machine_mode mode; +{ + switch (GET_CODE (op)) + { + case SYMBOL_REF: + case LABEL_REF: + return 1; + case CONST: + op = XEXP (op, 0); + return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF + || GET_CODE (XEXP (op, 0)) == LABEL_REF) + && GET_CODE (XEXP (op, 1)) == CONST_INT); + default: + return 0; + } +} + +/* Test for a valid operand for a call instruction. + Don't allow the arg pointer register or virtual regs + since they may change into reg + const, which the patterns + can't handle yet. */ + +int +call_insn_operand (op, mode) + rtx op; + enum machine_mode mode; +{ + if (GET_CODE (op) == MEM + && ((CONSTANT_ADDRESS_P (XEXP (op, 0)) + /* This makes a difference for PIC. */ + && general_operand (XEXP (op, 0), Pmode)) + || (GET_CODE (XEXP (op, 0)) == REG + && XEXP (op, 0) != arg_pointer_rtx + && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER + && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER)))) + return 1; + return 0; +} + +/* Like call_insn_operand but allow (mem (symbol_ref ...)) + even if pic. */ + +int +expander_call_insn_operand (op, mode) + rtx op; + enum machine_mode mode; +{ + if (GET_CODE (op) == MEM + && (CONSTANT_ADDRESS_P (XEXP (op, 0)) + || (GET_CODE (XEXP (op, 0)) == REG + && XEXP (op, 0) != arg_pointer_rtx + && !(REGNO (XEXP (op, 0)) >= FIRST_PSEUDO_REGISTER + && REGNO (XEXP (op, 0)) <= LAST_VIRTUAL_REGISTER)))) + return 1; + return 0; +} + +/* Return 1 if OP is a comparison operator that can use the condition code + generated by an arithmetic operation. */ + +int +arithmetic_comparison_operator (op, mode) + register rtx op; + enum machine_mode mode; +{ + enum rtx_code code; + + if (mode != VOIDmode && mode != GET_MODE (op)) + return 0; + code = GET_CODE (op); + if (GET_RTX_CLASS (code) != '<') + return 0; + + return (code != GT && code != LE); +} + +/* Returns 1 if OP contains a symbol reference */ + +int +symbolic_reference_mentioned_p (op) + rtx op; +{ + register char *fmt; + register int i; + + if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF) + return 1; + + fmt = GET_RTX_FORMAT (GET_CODE (op)); + for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--) + { + if (fmt[i] == 'E') + { + register int j; + + for (j = XVECLEN (op, i) - 1; j >= 0; j--) + if (symbolic_reference_mentioned_p (XVECEXP (op, i, j))) + return 1; + } + else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i))) + return 1; + } + + return 0; +} + +/* This function generates the assembly code for function entry. + FILE is an stdio stream to output the code to. + SIZE is an int: how many units of temporary storage to allocate. */ + +void +function_prologue (file, size) + FILE *file; + int size; +{ + register int regno; + int limit; + rtx xops[4]; + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); + + xops[0] = stack_pointer_rtx; + xops[1] = frame_pointer_rtx; + xops[2] = GEN_INT (size); + if (frame_pointer_needed) + { + output_asm_insn ("push%L1 %1", xops); + output_asm_insn (AS2 (mov%L0,%0,%1), xops); + } + + if (size) + output_asm_insn (AS2 (sub%L0,%2,%0), xops); + + /* Note If use enter it is NOT reversed args. + This one is not reversed from intel!! + I think enter is slower. Also sdb doesn't like it. + But if you want it the code is: + { + xops[3] = const0_rtx; + output_asm_insn ("enter %2,%3", xops); + } + */ + limit = (frame_pointer_needed ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); + for (regno = limit - 1; regno >= 0; regno--) + if ((regs_ever_live[regno] && ! call_used_regs[regno]) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) + { + xops[0] = gen_rtx (REG, SImode, regno); + output_asm_insn ("push%L0 %0", xops); + } + + if (pic_reg_used) + { + xops[0] = pic_offset_table_rtx; + xops[1] = (rtx) gen_label_rtx (); + + output_asm_insn (AS1 (call,%P1), xops); + ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (xops[1])); + output_asm_insn (AS1 (pop%L0,%0), xops); + output_asm_insn ("addl $_GLOBAL_OFFSET_TABLE_+[.-%P1],%0", xops); + } +} + +/* Return 1 if it is appropriate to emit `ret' instructions in the + body of a function. Do this only if the epilogue is simple, needing a + couple of insns. Prior to reloading, we can't tell how many registers + must be saved, so return 0 then. + + If NON_SAVING_SETJMP is defined and true, then it is not possible + for the epilogue to be simple, so return 0. This is a special case + since NON_SAVING_SETJMP will not cause regs_ever_live to change until + final, but jump_optimize may need to know sooner if a `return' is OK. */ + +int +simple_386_epilogue () +{ + int regno; + int nregs = 0; + int reglimit = (frame_pointer_needed + ? FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); + +#ifdef NON_SAVING_SETJMP + if (NON_SAVING_SETJMP && current_function_calls_setjmp) + return 0; +#endif + + if (! reload_completed) + return 0; + + for (regno = reglimit - 1; regno >= 0; regno--) + if ((regs_ever_live[regno] && ! call_used_regs[regno]) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) + nregs++; + + return nregs == 0 || ! frame_pointer_needed; +} + + +/* This function generates the assembly code for function exit. + FILE is an stdio stream to output the code to. + SIZE is an int: how many units of temporary storage to deallocate. */ + +void +function_epilogue (file, size) + FILE *file; + int size; +{ + register int regno; + register int nregs, limit; + int offset; + rtx xops[3]; + int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table + || current_function_uses_const_pool); + + /* Compute the number of registers to pop */ + + limit = (frame_pointer_needed + ? FRAME_POINTER_REGNUM + : STACK_POINTER_REGNUM); + + nregs = 0; + + for (regno = limit - 1; regno >= 0; regno--) + if ((regs_ever_live[regno] && ! call_used_regs[regno]) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) + nregs++; + + /* sp is often unreliable so we must go off the frame pointer, + */ + + /* In reality, we may not care if sp is unreliable, because we can + restore the register relative to the frame pointer. In theory, + since each move is the same speed as a pop, and we don't need the + leal, this is faster. For now restore multiple registers the old + way. */ + + offset = -size - (nregs * UNITS_PER_WORD); + + xops[2] = stack_pointer_rtx; + + if (nregs > 1 || ! frame_pointer_needed) + { + if (frame_pointer_needed) + { + xops[0] = adj_offsettable_operand (AT_BP (Pmode), offset); + output_asm_insn (AS2 (lea%L2,%0,%2), xops); + } + + for (regno = 0; regno < limit; regno++) + if ((regs_ever_live[regno] && ! call_used_regs[regno]) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) + { + xops[0] = gen_rtx (REG, SImode, regno); + output_asm_insn ("pop%L0 %0", xops); + } + } + else + for (regno = 0; regno < limit; regno++) + if ((regs_ever_live[regno] && ! call_used_regs[regno]) + || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) + { + xops[0] = gen_rtx (REG, SImode, regno); + xops[1] = adj_offsettable_operand (AT_BP (Pmode), offset); + output_asm_insn (AS2 (mov%L0,%1,%0), xops); + offset += 4; + } + + if (frame_pointer_needed) + { + /* On i486, mov & pop is faster than "leave". */ + + if (!TARGET_386) + { + xops[0] = frame_pointer_rtx; + output_asm_insn (AS2 (mov%L2,%0,%2), xops); + output_asm_insn ("pop%L0 %0", xops); + } + else + output_asm_insn ("leave", xops); + } + else if (size) + { + /* If there is no frame pointer, we must still release the frame. */ + + xops[0] = GEN_INT (size); + output_asm_insn (AS2 (add%L2,%0,%2), xops); + } + + if (current_function_pops_args && current_function_args_size) + { + xops[1] = GEN_INT (current_function_pops_args); + + /* i386 can only pop 32K bytes (maybe 64K? Is it signed?). If + asked to pop more, pop return address, do explicit add, and jump + indirectly to the caller. */ + + if (current_function_pops_args >= 32768) + { + /* ??? Which register to use here? */ + xops[0] = gen_rtx (REG, SImode, 2); + output_asm_insn ("pop%L0 %0", xops); + output_asm_insn (AS2 (add%L2,%1,%2), xops); + output_asm_insn ("jmp %*%0", xops); + } + else + output_asm_insn ("ret %1", xops); + } + else + output_asm_insn ("ret", xops); +} + + +/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression + that is a valid memory address for an instruction. + The MODE argument is the machine mode for the MEM expression + that wants to use this address. + + On x86, legitimate addresses are: + base movl (base),reg + displacement movl disp,reg + base + displacement movl disp(base),reg + index + base movl (base,index),reg + (index + base) + displacement movl disp(base,index),reg + index*scale movl (,index,scale),reg + index*scale + disp movl disp(,index,scale),reg + index*scale + base movl (base,index,scale),reg + (index*scale + base) + disp movl disp(base,index,scale),reg + + In each case, scale can be 1, 2, 4, 8. */ + +/* This is exactly the same as print_operand_addr, except that + it recognizes addresses instead of printing them. + + It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should + convert common non-canonical forms to canonical form so that they will + be recognized. */ + +#define ADDR_INVALID(msg,insn) \ +do { \ + if (TARGET_DEBUG_ADDR) \ + { \ + fprintf (stderr, msg); \ + debug_rtx (insn); \ + } \ +} while (0) + +int +legitimate_address_p (mode, addr, strict) + enum machine_mode mode; + register rtx addr; + int strict; +{ + rtx base = NULL_RTX; + rtx indx = NULL_RTX; + rtx scale = NULL_RTX; + rtx disp = NULL_RTX; + + if (TARGET_DEBUG_ADDR) + { + fprintf (stderr, + "\n==========\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n", + GET_MODE_NAME (mode), strict); + + debug_rtx (addr); + } + + if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG) + base = addr; /* base reg */ + + else if (GET_CODE (addr) == PLUS) + { + rtx op0 = XEXP (addr, 0); + rtx op1 = XEXP (addr, 1); + enum rtx_code code0 = GET_CODE (op0); + enum rtx_code code1 = GET_CODE (op1); + + if (code0 == REG || code0 == SUBREG) + { + if (code1 == REG || code1 == SUBREG) + { + indx = op0; /* index + base */ + base = op1; + } + + else + { + base = op0; /* base + displacement */ + disp = op1; + } + } + + else if (code0 == MULT) + { + indx = XEXP (op0, 0); + scale = XEXP (op0, 1); + + if (code1 == REG || code1 == SUBREG) + base = op1; /* index*scale + base */ + + else + disp = op1; /* index*scale + disp */ + } + + else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT) + { + indx = XEXP (XEXP (op0, 0), 0); /* index*scale + base + disp */ + scale = XEXP (XEXP (op0, 0), 1); + base = XEXP (op0, 1); + disp = op1; + } + + else if (code0 == PLUS) + { + indx = XEXP (op0, 0); /* index + base + disp */ + base = XEXP (op0, 1); + disp = op1; + } + + else + { + ADDR_INVALID ("PLUS subcode is not valid.\n", op0); + return FALSE; + } + } + + else if (GET_CODE (addr) == MULT) + { + indx = XEXP (addr, 0); /* index*scale */ + scale = XEXP (addr, 1); + } + + else + disp = addr; /* displacement */ + + /* Allow arg pointer and stack pointer as index if there is not scaling */ + if (base && indx && !scale + && (indx == arg_pointer_rtx || indx == stack_pointer_rtx)) + { + rtx tmp = base; + base = indx; + indx = tmp; + } + + /* Validate base register */ + /* Don't allow SUBREG's here, it can lead to spill failures when the base + is one word out of a two word structure, which is represented internally + as a DImode int. */ + if (base) + { + if (GET_CODE (base) != REG) + { + ADDR_INVALID ("Base is not a register.\n", base); + return FALSE; + } + + if ((strict && !REG_OK_FOR_BASE_STRICT_P (base)) + || (!strict && !REG_OK_FOR_BASE_NONSTRICT_P (base))) + { + ADDR_INVALID ("Base is not valid.\n", base); + return FALSE; + } + } + + /* Validate index register */ + /* Don't allow SUBREG's here, it can lead to spill failures when the index + is one word out of a two word structure, which is represented internally + as a DImode int. */ + if (indx) + { + if (GET_CODE (indx) != REG) + { + ADDR_INVALID ("Index is not a register.\n", indx); + return FALSE; + } + + if ((strict && !REG_OK_FOR_INDEX_STRICT_P (indx)) + || (!strict && !REG_OK_FOR_INDEX_NONSTRICT_P (indx))) + { + ADDR_INVALID ("Index is not valid.\n", indx); + return FALSE; + } + } + else if (scale) + abort (); /* scale w/o index invalid */ + + /* Validate scale factor */ + if (scale) + { + HOST_WIDE_INT value; + + if (GET_CODE (scale) != CONST_INT) + { + ADDR_INVALID ("Scale is not valid.\n", scale); + return FALSE; + } + + value = INTVAL (scale); + if (value != 1 && value != 2 && value != 4 && value != 8) + { + ADDR_INVALID ("Scale is not a good multiplier.\n", scale); + return FALSE; + } + } + + /* Validate displacement */ + if (disp) + { + if (!CONSTANT_ADDRESS_P (disp)) + { + ADDR_INVALID ("Displacement is not valid.\n", disp); + return FALSE; + } + + if (GET_CODE (disp) == CONST_DOUBLE) + { + ADDR_INVALID ("Displacement is a const_double.\n", disp); + return FALSE; + } + + if (flag_pic && SYMBOLIC_CONST (disp) && base != pic_offset_table_rtx + && (indx != pic_offset_table_rtx || scale != NULL_RTX)) + { + ADDR_INVALID ("Displacement is an invalid pic reference.\n", disp); + return FALSE; + } + + if (HALF_PIC_P () && HALF_PIC_ADDRESS_P (disp) + && (base != NULL_RTX || indx != NULL_RTX)) + { + ADDR_INVALID ("Displacement is an invalid half-pic reference.\n", disp); + return FALSE; + } + } + + if (TARGET_DEBUG_ADDR) + fprintf (stderr, "Address is valid.\n"); + + /* Everything looks valid, return true */ + return TRUE; +} + + +/* Return a legitimate reference for ORIG (an address) using the + register REG. If REG is 0, a new pseudo is generated. + + There are three types of references that must be handled: + + 1. Global data references must load the address from the GOT, via + the PIC reg. An insn is emitted to do this load, and the reg is + returned. + + 2. Static data references must compute the address as an offset + from the GOT, whose base is in the PIC reg. An insn is emitted to + compute the address into a reg, and the reg is returned. Static + data objects have SYMBOL_REF_FLAG set to differentiate them from + global data objects. + + 3. Constant pool addresses must be handled special. They are + considered legitimate addresses, but only if not used with regs. + When printed, the output routines know to print the reference with the + PIC reg, even though the PIC reg doesn't appear in the RTL. + + GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC + reg also appears in the address (except for constant pool references, + noted above). + + "switch" statements also require special handling when generating + PIC code. See comments by the `casesi' insn in i386.md for details. */ + +rtx +legitimize_pic_address (orig, reg) + rtx orig; + rtx reg; +{ + rtx addr = orig; + rtx new = orig; + + if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF) + { + if (GET_CODE (addr) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (addr)) + reg = new = orig; + else + { + if (reg == 0) + reg = gen_reg_rtx (Pmode); + + if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_FLAG (addr)) + || GET_CODE (addr) == LABEL_REF) + new = gen_rtx (PLUS, Pmode, pic_offset_table_rtx, orig); + else + new = gen_rtx (MEM, Pmode, + gen_rtx (PLUS, Pmode, + pic_offset_table_rtx, orig)); + + emit_move_insn (reg, new); + } + current_function_uses_pic_offset_table = 1; + return reg; + } + else if (GET_CODE (addr) == CONST || GET_CODE (addr) == PLUS) + { + rtx base; + + if (GET_CODE (addr) == CONST) + { + addr = XEXP (addr, 0); + if (GET_CODE (addr) != PLUS) + abort (); + } + + if (XEXP (addr, 0) == pic_offset_table_rtx) + return orig; + + if (reg == 0) + reg = gen_reg_rtx (Pmode); + + base = legitimize_pic_address (XEXP (addr, 0), reg); + addr = legitimize_pic_address (XEXP (addr, 1), + base == reg ? NULL_RTX : reg); + + if (GET_CODE (addr) == CONST_INT) + return plus_constant (base, INTVAL (addr)); + + if (GET_CODE (addr) == PLUS && CONSTANT_P (XEXP (addr, 1))) + { + base = gen_rtx (PLUS, Pmode, base, XEXP (addr, 0)); + addr = XEXP (addr, 1); + } + return gen_rtx (PLUS, Pmode, base, addr); + } + return new; +} + + +/* Emit insns to move operands[1] into operands[0]. */ + +void +emit_pic_move (operands, mode) + rtx *operands; + enum machine_mode mode; +{ + rtx temp = reload_in_progress ? operands[0] : gen_reg_rtx (Pmode); + + if (GET_CODE (operands[0]) == MEM && SYMBOLIC_CONST (operands[1])) + operands[1] = (rtx) force_reg (SImode, operands[1]); + else + operands[1] = legitimize_pic_address (operands[1], temp); +} + + +/* Try machine-dependent ways of modifying an illegitimate address + to be legitimate. If we find one, return the new, valid address. + This macro is used in only one place: `memory_address' in explow.c. + + OLDX is the address as it was before break_out_memory_refs was called. + In some cases it is useful to look at this to decide what needs to be done. + + MODE and WIN are passed so that this macro can use + GO_IF_LEGITIMATE_ADDRESS. + + It is always safe for this macro to do nothing. It exists to recognize + opportunities to optimize the output. + + For the 80386, we handle X+REG by loading X into a register R and + using R+REG. R will go in a general reg and indexing will be used. + However, if REG is a broken-out memory address or multiplication, + nothing needs to be done because REG can certainly go in a general reg. + + When -fpic is used, special handling is needed for symbolic references. + See comments by legitimize_pic_address in i386.c for details. */ + +rtx +legitimize_address (x, oldx, mode) + register rtx x; + register rtx oldx; + enum machine_mode mode; +{ + int changed = 0; + unsigned log; + + if (TARGET_DEBUG_ADDR) + { + fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n", GET_MODE_NAME (mode)); + debug_rtx (x); + } + + if (flag_pic && SYMBOLIC_CONST (x)) + return legitimize_pic_address (x, 0); + + /* Canonicalize shifts by 0, 1, 2, 3 into multiply */ + if (GET_CODE (x) == ASHIFT + && GET_CODE (XEXP (x, 1)) == CONST_INT + && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4) + { + changed = 1; + x = gen_rtx (MULT, Pmode, + force_reg (Pmode, XEXP (x, 0)), + GEN_INT (1 << log)); + } + + if (GET_CODE (x) == PLUS) + { + /* Canonicalize shifts by 0, 1, 2, 3 into multiply */ + if (GET_CODE (XEXP (x, 0)) == ASHIFT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4) + { + changed = 1; + XEXP (x, 0) = gen_rtx (MULT, Pmode, + force_reg (Pmode, XEXP (XEXP (x, 0), 0)), + GEN_INT (1 << log)); + } + + if (GET_CODE (XEXP (x, 1)) == ASHIFT + && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT + && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4) + { + changed = 1; + XEXP (x, 1) = gen_rtx (MULT, Pmode, + force_reg (Pmode, XEXP (XEXP (x, 1), 0)), + GEN_INT (1 << log)); + } + + /* Put multiply first if it isn't already */ + if (GET_CODE (XEXP (x, 1)) == MULT) + { + rtx tmp = XEXP (x, 0); + XEXP (x, 0) = XEXP (x, 1); + XEXP (x, 1) = tmp; + changed = 1; + } + + /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const))) + into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be + created by virtual register instantiation, register elimination, and + similar optimizations. */ + if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS) + { + changed = 1; + x = gen_rtx (PLUS, Pmode, + gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)), + XEXP (XEXP (x, 1), 1)); + } + + /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const) + into (plus (plus (mult (reg) (const)) (reg)) (const)). */ + else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT + && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS + && CONSTANT_P (XEXP (x, 1))) + { + rtx constant, other; + + if (GET_CODE (XEXP (x, 1)) == CONST_INT) + { + constant = XEXP (x, 1); + other = XEXP (XEXP (XEXP (x, 0), 1), 1); + } + else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT) + { + constant = XEXP (XEXP (XEXP (x, 0), 1), 1); + other = XEXP (x, 1); + } + else + constant = 0; + + if (constant) + { + changed = 1; + x = gen_rtx (PLUS, Pmode, + gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0), + XEXP (XEXP (XEXP (x, 0), 1), 0)), + plus_constant (other, INTVAL (constant))); + } + } + + if (changed && legitimate_address_p (mode, x, FALSE)) + return x; + + if (GET_CODE (XEXP (x, 0)) == MULT) + { + changed = 1; + XEXP (x, 0) = force_operand (XEXP (x, 0), 0); + } + + if (GET_CODE (XEXP (x, 1)) == MULT) + { + changed = 1; + XEXP (x, 1) = force_operand (XEXP (x, 1), 0); + } + + if (changed + && GET_CODE (XEXP (x, 1)) == REG + && GET_CODE (XEXP (x, 0)) == REG) + return x; + + if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1))) + { + changed = 1; + x = legitimize_pic_address (x, 0); + } + + if (changed && legitimate_address_p (mode, x, FALSE)) + return x; + + if (GET_CODE (XEXP (x, 0)) == REG) + { + register rtx temp = gen_reg_rtx (Pmode); + register rtx val = force_operand (XEXP (x, 1), temp); + if (val != temp) + emit_move_insn (temp, val); + + XEXP (x, 1) = temp; + return x; + } + + else if (GET_CODE (XEXP (x, 1)) == REG) + { + register rtx temp = gen_reg_rtx (Pmode); + register rtx val = force_operand (XEXP (x, 0), temp); + if (val != temp) + emit_move_insn (temp, val); + + XEXP (x, 0) = temp; + return x; + } + } + + return x; +} + + +/* Print an integer constant expression in assembler syntax. Addition + and subtraction are the only arithmetic that may appear in these + expressions. FILE is the stdio stream to write to, X is the rtx, and + CODE is the operand print code from the output string. */ + +static void +output_pic_addr_const (file, x, code) + FILE *file; + rtx x; + int code; +{ + char buf[256]; + + switch (GET_CODE (x)) + { + case PC: + if (flag_pic) + putc ('.', file); + else + abort (); + break; + + case SYMBOL_REF: + case LABEL_REF: + if (GET_CODE (x) == SYMBOL_REF) + assemble_name (file, XSTR (x, 0)); + else + { + ASM_GENERATE_INTERNAL_LABEL (buf, "L", + CODE_LABEL_NUMBER (XEXP (x, 0))); + assemble_name (asm_out_file, buf); + } + + if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x)) + fprintf (file, "@GOTOFF(%%ebx)"); + else if (code == 'P') + fprintf (file, "@PLT"); + else if (GET_CODE (x) == LABEL_REF) + fprintf (file, "@GOTOFF"); + else if (! SYMBOL_REF_FLAG (x)) + fprintf (file, "@GOT"); + else + fprintf (file, "@GOTOFF"); + + break; + + case CODE_LABEL: + ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); + assemble_name (asm_out_file, buf); + break; + + case CONST_INT: + fprintf (file, "%d", INTVAL (x)); + break; + + case CONST: + /* This used to output parentheses around the expression, + but that does not work on the 386 (either ATT or BSD assembler). */ + output_pic_addr_const (file, XEXP (x, 0), code); + break; + + case CONST_DOUBLE: + if (GET_MODE (x) == VOIDmode) + { + /* We can use %d if the number is <32 bits and positive. */ + if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0) + fprintf (file, "0x%x%08x", + CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x)); + else + fprintf (file, "%d", CONST_DOUBLE_LOW (x)); + } + else + /* We can't handle floating point constants; + PRINT_OPERAND must handle them. */ + output_operand_lossage ("floating constant misused"); + break; + + case PLUS: + /* Some assemblers need integer constants to appear last (eg masm). */ + if (GET_CODE (XEXP (x, 0)) == CONST_INT) + { + output_pic_addr_const (file, XEXP (x, 1), code); + if (INTVAL (XEXP (x, 0)) >= 0) + fprintf (file, "+"); + output_pic_addr_const (file, XEXP (x, 0), code); + } + else + { + output_pic_addr_const (file, XEXP (x, 0), code); + if (INTVAL (XEXP (x, 1)) >= 0) + fprintf (file, "+"); + output_pic_addr_const (file, XEXP (x, 1), code); + } + break; + + case MINUS: + output_pic_addr_const (file, XEXP (x, 0), code); + fprintf (file, "-"); + output_pic_addr_const (file, XEXP (x, 1), code); + break; + + default: + output_operand_lossage ("invalid expression as operand"); + } +} + +/* Meaning of CODE: + f -- float insn (print a CONST_DOUBLE as a float rather than in hex). + D,L,W,B,Q,S -- print the opcode suffix for specified size of operand. + R -- print the prefix for register names. + z -- print the opcode suffix for the size of the current operand. + * -- print a star (in certain assembler syntax) + w -- print the operand as if it's a "word" (HImode) even if it isn't. + c -- don't print special prefixes before constant operands. + J -- print the appropriate jump operand. +*/ + +void +print_operand (file, x, code) + FILE *file; + rtx x; + int code; +{ + if (code) + { + switch (code) + { + case '*': + if (USE_STAR) + putc ('*', file); + return; + + case 'L': + PUT_OP_SIZE (code, 'l', file); + return; + + case 'W': + PUT_OP_SIZE (code, 'w', file); + return; + + case 'B': + PUT_OP_SIZE (code, 'b', file); + return; + + case 'Q': + PUT_OP_SIZE (code, 'l', file); + return; + + case 'S': + PUT_OP_SIZE (code, 's', file); + return; + + case 'T': + PUT_OP_SIZE (code, 't', file); + return; + + case 'z': + /* 387 opcodes don't get size suffixes if the operands are + registers. */ + + if (STACK_REG_P (x)) + return; + + /* this is the size of op from size of operand */ + switch (GET_MODE_SIZE (GET_MODE (x))) + { + case 1: + PUT_OP_SIZE ('B', 'b', file); + return; + + case 2: + PUT_OP_SIZE ('W', 'w', file); + return; + + case 4: + if (GET_MODE (x) == SFmode) + { + PUT_OP_SIZE ('S', 's', file); + return; + } + else + PUT_OP_SIZE ('L', 'l', file); + return; + + case 12: + PUT_OP_SIZE ('T', 't', file); + return; + + case 8: + if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT) + { +#ifdef GAS_MNEMONICS + PUT_OP_SIZE ('Q', 'q', file); + return; +#else + PUT_OP_SIZE ('Q', 'l', file); /* Fall through */ +#endif + } + + PUT_OP_SIZE ('Q', 'l', file); + return; + } + + case 'b': + case 'w': + case 'k': + case 'h': + case 'y': + case 'P': + break; + + case 'J': + switch (GET_CODE (x)) + { + /* These conditions are appropriate for testing the result + of an arithmetic operation, not for a compare operation. + Cases GE, LT assume CC_NO_OVERFLOW true. All cases assume + CC_Z_IN_NOT_C false and not floating point. */ + case NE: fputs ("jne", file); return; + case EQ: fputs ("je", file); return; + case GE: fputs ("jns", file); return; + case LT: fputs ("js", file); return; + case GEU: fputs ("jmp", file); return; + case GTU: fputs ("jne", file); return; + case LEU: fputs ("je", file); return; + case LTU: fputs ("#branch never", file); return; + + /* no matching branches for GT nor LE */ + } + abort (); + + default: + { + char str[50]; + + sprintf (str, "invalid operand code `%c'", code); + output_operand_lossage (str); + } + } + } + if (GET_CODE (x) == REG) + { + PRINT_REG (x, code, file); + } + else if (GET_CODE (x) == MEM) + { + PRINT_PTR (x, file); + if (CONSTANT_ADDRESS_P (XEXP (x, 0))) + { + if (flag_pic) + output_pic_addr_const (file, XEXP (x, 0), code); + else + output_addr_const (file, XEXP (x, 0)); + } + else + output_address (XEXP (x, 0)); + } + else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) + { + REAL_VALUE_TYPE r; long l; + REAL_VALUE_FROM_CONST_DOUBLE (r, x); + REAL_VALUE_TO_TARGET_SINGLE (r, l); + PRINT_IMMED_PREFIX (file); + fprintf (file, "0x%x", l); + } + /* These float cases don't actually occur as immediate operands. */ + else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) + { + REAL_VALUE_TYPE r; char dstr[30]; + REAL_VALUE_FROM_CONST_DOUBLE (r, x); + REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr); + fprintf (file, "%s", dstr); + } + else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode) + { + REAL_VALUE_TYPE r; char dstr[30]; + REAL_VALUE_FROM_CONST_DOUBLE (r, x); + REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr); + fprintf (file, "%s", dstr); + } + else + { + if (code != 'P') + { + if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) + PRINT_IMMED_PREFIX (file); + else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF + || GET_CODE (x) == LABEL_REF) + PRINT_OFFSET_PREFIX (file); + } + if (flag_pic) + output_pic_addr_const (file, x, code); + else + output_addr_const (file, x); + } +} + +/* Print a memory operand whose address is ADDR. */ + +void +print_operand_address (file, addr) + FILE *file; + register rtx addr; +{ + register rtx reg1, reg2, breg, ireg; + rtx offset; + + switch (GET_CODE (addr)) + { + case REG: + ADDR_BEG (file); + fprintf (file, "%se", RP); + fputs (hi_reg_name[REGNO (addr)], file); + ADDR_END (file); + break; + + case PLUS: + reg1 = 0; + reg2 = 0; + ireg = 0; + breg = 0; + offset = 0; + if (CONSTANT_ADDRESS_P (XEXP (addr, 0))) + { + offset = XEXP (addr, 0); + addr = XEXP (addr, 1); + } + else if (CONSTANT_ADDRESS_P (XEXP (addr, 1))) + { + offset = XEXP (addr, 1); + addr = XEXP (addr, 0); + } + if (GET_CODE (addr) != PLUS) ; + else if (GET_CODE (XEXP (addr, 0)) == MULT) + { + reg1 = XEXP (addr, 0); + addr = XEXP (addr, 1); + } + else if (GET_CODE (XEXP (addr, 1)) == MULT) + { + reg1 = XEXP (addr, 1); + addr = XEXP (addr, 0); + } + else if (GET_CODE (XEXP (addr, 0)) == REG) + { + reg1 = XEXP (addr, 0); + addr = XEXP (addr, 1); + } + else if (GET_CODE (XEXP (addr, 1)) == REG) + { + reg1 = XEXP (addr, 1); + addr = XEXP (addr, 0); + } + if (GET_CODE (addr) == REG || GET_CODE (addr) == MULT) + { + if (reg1 == 0) reg1 = addr; + else reg2 = addr; + addr = 0; + } + if (offset != 0) + { + if (addr != 0) abort (); + addr = offset; + } + if ((reg1 && GET_CODE (reg1) == MULT) + || (reg2 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg2)))) + { + breg = reg2; + ireg = reg1; + } + else if (reg1 != 0 && REGNO_OK_FOR_BASE_P (REGNO (reg1))) + { + breg = reg1; + ireg = reg2; + } + + if (ireg != 0 || breg != 0) + { + int scale = 1; + + if (addr != 0) + { + if (flag_pic) + output_pic_addr_const (file, addr, 0); + + else if (GET_CODE (addr) == LABEL_REF) + output_asm_label (addr); + + else + output_addr_const (file, addr); + } + + if (ireg != 0 && GET_CODE (ireg) == MULT) + { + scale = INTVAL (XEXP (ireg, 1)); + ireg = XEXP (ireg, 0); + } + + /* The stack pointer can only appear as a base register, + never an index register, so exchange the regs if it is wrong. */ + + if (scale == 1 && ireg && REGNO (ireg) == STACK_POINTER_REGNUM) + { + rtx tmp; + + tmp = breg; + breg = ireg; + ireg = tmp; + } + + /* output breg+ireg*scale */ + PRINT_B_I_S (breg, ireg, scale, file); + break; + } + + case MULT: + { + int scale; + if (GET_CODE (XEXP (addr, 0)) == CONST_INT) + { + scale = INTVAL (XEXP (addr, 0)); + ireg = XEXP (addr, 1); + } + else + { + scale = INTVAL (XEXP (addr, 1)); + ireg = XEXP (addr, 0); + } + output_addr_const (file, const0_rtx); + PRINT_B_I_S ((rtx) 0, ireg, scale, file); + } + break; + + default: + if (GET_CODE (addr) == CONST_INT + && INTVAL (addr) < 0x8000 + && INTVAL (addr) >= -0x8000) + fprintf (file, "%d", INTVAL (addr)); + else + { + if (flag_pic) + output_pic_addr_const (file, addr, 0); + else + output_addr_const (file, addr); + } + } +} + +/* Set the cc_status for the results of an insn whose pattern is EXP. + On the 80386, we assume that only test and compare insns, as well + as SI, HI, & DI mode ADD, SUB, NEG, AND, IOR, XOR, ASHIFT, + ASHIFTRT, and LSHIFTRT instructions set the condition codes usefully. + Also, we assume that jumps, moves and sCOND don't affect the condition + codes. All else clobbers the condition codes, by assumption. + + We assume that ALL integer add, minus, etc. instructions effect the + condition codes. This MUST be consistent with i386.md. + + We don't record any float test or compare - the redundant test & + compare check in final.c does not handle stack-like regs correctly. */ + +void +notice_update_cc (exp) + rtx exp; +{ + if (GET_CODE (exp) == SET) + { + /* Jumps do not alter the cc's. */ + if (SET_DEST (exp) == pc_rtx) + return; + /* Moving register or memory into a register: + it doesn't alter the cc's, but it might invalidate + the RTX's which we remember the cc's came from. + (Note that moving a constant 0 or 1 MAY set the cc's). */ + if (REG_P (SET_DEST (exp)) + && (REG_P (SET_SRC (exp)) || GET_CODE (SET_SRC (exp)) == MEM + || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<')) + { + if (cc_status.value1 + && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value1)) + cc_status.value1 = 0; + if (cc_status.value2 + && reg_overlap_mentioned_p (SET_DEST (exp), cc_status.value2)) + cc_status.value2 = 0; + return; + } + /* Moving register into memory doesn't alter the cc's. + It may invalidate the RTX's which we remember the cc's came from. */ + if (GET_CODE (SET_DEST (exp)) == MEM + && (REG_P (SET_SRC (exp)) + || GET_RTX_CLASS (GET_CODE (SET_SRC (exp))) == '<')) + { + if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM) + cc_status.value1 = 0; + if (cc_status.value2 && GET_CODE (cc_status.value2) == MEM) + cc_status.value2 = 0; + return; + } + /* Function calls clobber the cc's. */ + else if (GET_CODE (SET_SRC (exp)) == CALL) + { + CC_STATUS_INIT; + return; + } + /* Tests and compares set the cc's in predictable ways. */ + else if (SET_DEST (exp) == cc0_rtx) + { + CC_STATUS_INIT; + cc_status.value1 = SET_SRC (exp); + return; + } + /* Certain instructions effect the condition codes. */ + else if (GET_MODE (SET_SRC (exp)) == SImode + || GET_MODE (SET_SRC (exp)) == HImode + || GET_MODE (SET_SRC (exp)) == QImode) + switch (GET_CODE (SET_SRC (exp))) + { + case ASHIFTRT: case LSHIFTRT: + case ASHIFT: + /* Shifts on the 386 don't set the condition codes if the + shift count is zero. */ + if (GET_CODE (XEXP (SET_SRC (exp), 1)) != CONST_INT) + { + CC_STATUS_INIT; + break; + } + /* We assume that the CONST_INT is non-zero (this rtx would + have been deleted if it were zero. */ + + case PLUS: case MINUS: case NEG: + case AND: case IOR: case XOR: + cc_status.flags = CC_NO_OVERFLOW; + cc_status.value1 = SET_SRC (exp); + cc_status.value2 = SET_DEST (exp); + break; + + default: + CC_STATUS_INIT; + } + else + { + CC_STATUS_INIT; + } + } + else if (GET_CODE (exp) == PARALLEL + && GET_CODE (XVECEXP (exp, 0, 0)) == SET) + { + if (SET_DEST (XVECEXP (exp, 0, 0)) == pc_rtx) + return; + if (SET_DEST (XVECEXP (exp, 0, 0)) == cc0_rtx) + { + CC_STATUS_INIT; + if (stack_regs_mentioned_p (SET_SRC (XVECEXP (exp, 0, 0)))) + cc_status.flags |= CC_IN_80387; + else + cc_status.value1 = SET_SRC (XVECEXP (exp, 0, 0)); + return; + } + CC_STATUS_INIT; + } + else + { + CC_STATUS_INIT; + } +} + +/* Split one or more DImode RTL references into pairs of SImode + references. The RTL can be REG, offsettable MEM, integer constant, or + CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to + split and "num" is its length. lo_half and hi_half are output arrays + that parallel "operands". */ + +void +split_di (operands, num, lo_half, hi_half) + rtx operands[]; + int num; + rtx lo_half[], hi_half[]; +{ + while (num--) + { + if (GET_CODE (operands[num]) == REG) + { + lo_half[num] = gen_rtx (REG, SImode, REGNO (operands[num])); + hi_half[num] = gen_rtx (REG, SImode, REGNO (operands[num]) + 1); + } + else if (CONSTANT_P (operands[num])) + { + split_double (operands[num], &lo_half[num], &hi_half[num]); + } + else if (offsettable_memref_p (operands[num])) + { + lo_half[num] = operands[num]; + hi_half[num] = adj_offsettable_operand (operands[num], 4); + } + else + abort(); + } +} + +/* Return 1 if this is a valid binary operation on a 387. + OP is the expression matched, and MODE is its mode. */ + +int +binary_387_op (op, mode) + register rtx op; + enum machine_mode mode; +{ + if (mode != VOIDmode && mode != GET_MODE (op)) + return 0; + + switch (GET_CODE (op)) + { + case PLUS: + case MINUS: + case MULT: + case DIV: + return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT; + + default: + return 0; + } +} + + +/* Return 1 if this is a valid shift or rotate operation on a 386. + OP is the expression matched, and MODE is its mode. */ + +int +shift_op (op, mode) + register rtx op; + enum machine_mode mode; +{ + rtx operand = XEXP (op, 0); + + if (mode != VOIDmode && mode != GET_MODE (op)) + return 0; + + if (GET_MODE (operand) != GET_MODE (op) + || GET_MODE_CLASS (GET_MODE (op)) != MODE_INT) + return 0; + + return (GET_CODE (op) == ASHIFT + || GET_CODE (op) == ASHIFTRT + || GET_CODE (op) == LSHIFTRT + || GET_CODE (op) == ROTATE + || GET_CODE (op) == ROTATERT); +} + +/* Return 1 if OP is COMPARE rtx with mode VOIDmode. + MODE is not used. */ + +int +VOIDmode_compare_op (op, mode) + register rtx op; + enum machine_mode mode; +{ + return GET_CODE (op) == COMPARE && GET_MODE (op) == VOIDmode; +} + +/* Output code to perform a 387 binary operation in INSN, one of PLUS, + MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3] + is the expression of the binary operation. The output may either be + emitted here, or returned to the caller, like all output_* functions. + + There is no guarantee that the operands are the same mode, as they + might be within FLOAT or FLOAT_EXTEND expressions. */ + +char * +output_387_binary_op (insn, operands) + rtx insn; + rtx *operands; +{ + rtx temp; + char *base_op; + static char buf[100]; + + switch (GET_CODE (operands[3])) + { + case PLUS: + if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT + || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) + base_op = "fiadd"; + else + base_op = "fadd"; + break; + + case MINUS: + if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT + || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) + base_op = "fisub"; + else + base_op = "fsub"; + break; + + case MULT: + if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT + || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) + base_op = "fimul"; + else + base_op = "fmul"; + break; + + case DIV: + if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT + || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) + base_op = "fidiv"; + else + base_op = "fdiv"; + break; + + default: + abort (); + } + + strcpy (buf, base_op); + + switch (GET_CODE (operands[3])) + { + case MULT: + case PLUS: + if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2])) + { + temp = operands[2]; + operands[2] = operands[1]; + operands[1] = temp; + } + + if (GET_CODE (operands[2]) == MEM) + return strcat (buf, AS1 (%z2,%2)); + + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1))); + RET; + } + else if (NON_STACK_REG_P (operands[2])) + { + output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1))); + RET; + } + + if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) + return strcat (buf, AS2 (p,%2,%0)); + + if (STACK_TOP_P (operands[0])) + return strcat (buf, AS2C (%y2,%0)); + else + return strcat (buf, AS2C (%2,%0)); + + case MINUS: + case DIV: + if (GET_CODE (operands[1]) == MEM) + return strcat (buf, AS1 (r%z1,%1)); + + if (GET_CODE (operands[2]) == MEM) + return strcat (buf, AS1 (%z2,%2)); + + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], strcat (buf, AS1 (r%z0,%1))); + RET; + } + else if (NON_STACK_REG_P (operands[2])) + { + output_op_from_reg (operands[2], strcat (buf, AS1 (%z0,%1))); + RET; + } + + if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2])) + abort (); + + if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) + return strcat (buf, AS2 (rp,%2,%0)); + + if (find_regno_note (insn, REG_DEAD, REGNO (operands[1]))) + return strcat (buf, AS2 (p,%1,%0)); + + if (STACK_TOP_P (operands[0])) + { + if (STACK_TOP_P (operands[1])) + return strcat (buf, AS2C (%y2,%0)); + else + return strcat (buf, AS2 (r,%y1,%0)); + } + else if (STACK_TOP_P (operands[1])) + return strcat (buf, AS2C (%1,%0)); + else + return strcat (buf, AS2 (r,%2,%0)); + + default: + abort (); + } +} + +/* Output code for INSN to convert a float to a signed int. OPERANDS + are the insn operands. The output may be SFmode or DFmode and the + input operand may be SImode or DImode. As a special case, make sure + that the 387 stack top dies if the output mode is DImode, because the + hardware requires this. */ + +char * +output_fix_trunc (insn, operands) + rtx insn; + rtx *operands; +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + rtx xops[2]; + + if (! STACK_TOP_P (operands[1]) || + (GET_MODE (operands[0]) == DImode && ! stack_top_dies)) + abort (); + + xops[0] = GEN_INT (12); + xops[1] = operands[4]; + + output_asm_insn (AS1 (fnstc%W2,%2), operands); + output_asm_insn (AS2 (mov%L2,%2,%4), operands); + output_asm_insn (AS2 (mov%B1,%0,%h1), xops); + output_asm_insn (AS2 (mov%L4,%4,%3), operands); + output_asm_insn (AS1 (fldc%W3,%3), operands); + + if (NON_STACK_REG_P (operands[0])) + output_to_reg (operands[0], stack_top_dies); + else if (GET_CODE (operands[0]) == MEM) + { + if (stack_top_dies) + output_asm_insn (AS1 (fistp%z0,%0), operands); + else + output_asm_insn (AS1 (fist%z0,%0), operands); + } + else + abort (); + + return AS1 (fldc%W2,%2); +} + +/* Output code for INSN to compare OPERANDS. The two operands might + not have the same mode: one might be within a FLOAT or FLOAT_EXTEND + expression. If the compare is in mode CCFPEQmode, use an opcode that + will not fault if a qNaN is present. */ + +char * +output_float_compare (insn, operands) + rtx insn; + rtx *operands; +{ + int stack_top_dies; + rtx body = XVECEXP (PATTERN (insn), 0, 0); + int unordered_compare = GET_MODE (SET_SRC (body)) == CCFPEQmode; + + if (! STACK_TOP_P (operands[0])) + abort (); + + stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (STACK_REG_P (operands[1]) + && stack_top_dies + && find_regno_note (insn, REG_DEAD, REGNO (operands[1])) + && REGNO (operands[1]) != FIRST_STACK_REG) + { + /* If both the top of the 387 stack dies, and the other operand + is also a stack register that dies, then this must be a + `fcompp' float compare */ + + if (unordered_compare) + output_asm_insn ("fucompp", operands); + else + output_asm_insn ("fcompp", operands); + } + else + { + static char buf[100]; + + /* Decide if this is the integer or float compare opcode, or the + unordered float compare. */ + + if (unordered_compare) + strcpy (buf, "fucom"); + else if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_FLOAT) + strcpy (buf, "fcom"); + else + strcpy (buf, "ficom"); + + /* Modify the opcode if the 387 stack is to be popped. */ + + if (stack_top_dies) + strcat (buf, "p"); + + if (NON_STACK_REG_P (operands[1])) + output_op_from_reg (operands[1], strcat (buf, AS1 (%z0,%1))); + else + output_asm_insn (strcat (buf, AS1 (%z1,%y1)), operands); + } + + /* Now retrieve the condition code. */ + + return output_fp_cc0_set (insn); +} + +/* Output opcodes to transfer the results of FP compare or test INSN + from the FPU to the CPU flags. If TARGET_IEEE_FP, ensure that if the + result of the compare or test is unordered, no comparison operator + succeeds except NE. Return an output template, if any. */ + +char * +output_fp_cc0_set (insn) + rtx insn; +{ + rtx xops[3]; + rtx unordered_label; + rtx next; + enum rtx_code code; + + xops[0] = gen_rtx (REG, HImode, 0); + output_asm_insn (AS1 (fnsts%W0,%0), xops); + + if (! TARGET_IEEE_FP) + return "sahf"; + + next = next_cc0_user (insn); + if (next == NULL_RTX) + abort (); + + if (GET_CODE (next) == JUMP_INSN + && GET_CODE (PATTERN (next)) == SET + && SET_DEST (PATTERN (next)) == pc_rtx + && GET_CODE (SET_SRC (PATTERN (next))) == IF_THEN_ELSE) + { + code = GET_CODE (XEXP (SET_SRC (PATTERN (next)), 0)); + } + else if (GET_CODE (PATTERN (next)) == SET) + { + code = GET_CODE (SET_SRC (PATTERN (next))); + } + else + abort (); + + xops[0] = gen_rtx (REG, QImode, 0); + + switch (code) + { + case GT: + xops[1] = GEN_INT (0x45); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + /* je label */ + break; + + case LT: + xops[1] = GEN_INT (0x45); + xops[2] = GEN_INT (0x01); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* je label */ + break; + + case GE: + xops[1] = GEN_INT (0x05); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + /* je label */ + break; + + case LE: + xops[1] = GEN_INT (0x45); + xops[2] = GEN_INT (0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS1 (dec%B0,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* jb label */ + break; + + case EQ: + xops[1] = GEN_INT (0x45); + xops[2] = GEN_INT (0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (cmp%B0,%2,%h0), xops); + /* je label */ + break; + + case NE: + xops[1] = GEN_INT (0x44); + xops[2] = GEN_INT (0x40); + output_asm_insn (AS2 (and%B0,%1,%h0), xops); + output_asm_insn (AS2 (xor%B0,%2,%h0), xops); + /* jne label */ + break; + + case GTU: + case LTU: + case GEU: + case LEU: + default: + abort (); + } + RET; +} + +#define MAX_386_STACK_LOCALS 2 + +static rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS]; + +/* Define the structure for the machine field in struct function. */ +struct machine_function +{ + rtx i386_stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS]; +}; + +/* Functions to save and restore i386_stack_locals. + These will be called, via pointer variables, + from push_function_context and pop_function_context. */ + +void +save_386_machine_status (p) + struct function *p; +{ + p->machine = (struct machine_function *) xmalloc (sizeof i386_stack_locals); + bcopy ((char *) i386_stack_locals, (char *) p->machine->i386_stack_locals, + sizeof i386_stack_locals); +} + +void +restore_386_machine_status (p) + struct function *p; +{ + bcopy ((char *) p->machine->i386_stack_locals, (char *) i386_stack_locals, + sizeof i386_stack_locals); + free (p->machine); +} + +/* Clear stack slot assignments remembered from previous functions. + This is called from INIT_EXPANDERS once before RTL is emitted for each + function. */ + +void +clear_386_stack_locals () +{ + enum machine_mode mode; + int n; + + for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE; + mode = (enum machine_mode) ((int) mode + 1)) + for (n = 0; n < MAX_386_STACK_LOCALS; n++) + i386_stack_locals[(int) mode][n] = NULL_RTX; + + /* Arrange to save and restore i386_stack_locals around nested functions. */ + save_machine_status = save_386_machine_status; + restore_machine_status = restore_386_machine_status; +} + +/* Return a MEM corresponding to a stack slot with mode MODE. + Allocate a new slot if necessary. + + The RTL for a function can have several slots available: N is + which slot to use. */ + +rtx +assign_386_stack_local (mode, n) + enum machine_mode mode; + int n; +{ + if (n < 0 || n >= MAX_386_STACK_LOCALS) + abort (); + + if (i386_stack_locals[(int) mode][n] == NULL_RTX) + i386_stack_locals[(int) mode][n] + = assign_stack_local (mode, GET_MODE_SIZE (mode), 0); + + return i386_stack_locals[(int) mode][n]; +} diff --git a/contrib/gcc/config/i386/i386.h b/contrib/gcc/config/i386/i386.h new file mode 100644 index 00000000000..b00b0e509c5 --- /dev/null +++ b/contrib/gcc/config/i386/i386.h @@ -0,0 +1,1934 @@ +/* Definitions of target machine for GNU compiler for Intel X86 + (386, 486, Pentium). + Copyright (C) 1988, 1992, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* The purpose of this file is to define the characteristics of the i386, + independent of assembler syntax or operating system. + + Three other files build on this one to describe a specific assembler syntax: + bsd386.h, att386.h, and sun386.h. + + The actual tm.h file for a particular system should include + this file, and then the file for the appropriate assembler syntax. + + Many macros that specify assembler syntax are omitted entirely from + this file because they really belong in the files for particular + assemblers. These include AS1, AS2, AS3, RP, IP, LPREFIX, L_SIZE, + PUT_OP_SIZE, USE_STAR, ADDR_BEG, ADDR_END, PRINT_IREG, PRINT_SCALE, + PRINT_B_I_S, and many that start with ASM_ or end in ASM_OP. */ + +/* Names to predefine in the preprocessor for this target machine. */ + +#define I386 1 + +/* Stubs for half-pic support if not OSF/1 reference platform. */ + +#ifndef HALF_PIC_P +#define HALF_PIC_P() 0 +#define HALF_PIC_NUMBER_PTRS 0 +#define HALF_PIC_NUMBER_REFS 0 +#define HALF_PIC_ENCODE(DECL) +#define HALF_PIC_DECLARE(NAME) +#define HALF_PIC_INIT() error ("half-pic init called on systems that don't support it.") +#define HALF_PIC_ADDRESS_P(X) 0 +#define HALF_PIC_PTR(X) X +#define HALF_PIC_FINISH(STREAM) +#endif + +/* Run-time compilation parameters selecting different hardware subsets. */ + +extern int target_flags; + +/* Macros used in the machine description to test the flags. */ + +/* configure can arrange to make this 2, to force a 486. */ +#ifndef TARGET_CPU_DEFAULT +#define TARGET_CPU_DEFAULT 0 +#endif + +/* Masks for the -m switches */ +#define MASK_80387 000000000001 /* Hardware floating point */ +#define MASK_486 000000000002 /* 80486 specific */ +#define MASK_NOTUSED1 000000000004 /* bit not currently used */ +#define MASK_RTD 000000000010 /* Use ret that pops args */ +#define MASK_ALIGN_DOUBLE 000000000020 /* align doubles to 2 word boundary */ +#define MASK_SVR3_SHLIB 000000000040 /* Uninit locals into bss */ +#define MASK_IEEE_FP 000000000100 /* IEEE fp comparisons */ +#define MASK_FLOAT_RETURNS 000000000200 /* Return float in st(0) */ +#define MASK_NO_FANCY_MATH_387 000000000400 /* Disable sin, cos, sqrt */ + + /* Temporary codegen switches */ +#define MASK_DEBUG_ADDR 000001000000 /* Debug GO_IF_LEGITIMATE_ADDRESS */ +#define MASK_NO_WIDE_MULTIPLY 000002000000 /* Disable 32x32->64 multiplies */ +#define MASK_NO_MOVE 000004000000 /* Don't generate mem->mem */ +#define MASK_DEBUG_ARG 000010000000 /* Debug function_arg */ + +/* Use the floating point instructions */ +#define TARGET_80387 (target_flags & MASK_80387) + +/* Compile using ret insn that pops args. + This will not work unless you use prototypes at least + for all functions that can take varying numbers of args. */ +#define TARGET_RTD (target_flags & MASK_RTD) + +/* Align doubles to a two word boundary. This breaks compatibility with + the published ABI's for structures containing doubles, but produces + faster code on the pentium. */ +#define TARGET_ALIGN_DOUBLE (target_flags & MASK_ALIGN_DOUBLE) + +/* Put uninitialized locals into bss, not data. + Meaningful only on svr3. */ +#define TARGET_SVR3_SHLIB (target_flags & MASK_SVR3_SHLIB) + +/* Use IEEE floating point comparisons. These handle correctly the cases + where the result of a comparison is unordered. Normally SIGFPE is + generated in such cases, in which case this isn't needed. */ +#define TARGET_IEEE_FP (target_flags & MASK_IEEE_FP) + +/* Functions that return a floating point value may return that value + in the 387 FPU or in 386 integer registers. If set, this flag causes + the 387 to be used, which is compatible with most calling conventions. */ +#define TARGET_FLOAT_RETURNS_IN_80387 (target_flags & MASK_FLOAT_RETURNS) + +/* Disable generation of FP sin, cos and sqrt operations for 387. + This is because FreeBSD lacks these in the math-emulator-code */ +#define TARGET_NO_FANCY_MATH_387 (target_flags & MASK_NO_FANCY_MATH_387) + +/* Temporary switches for tuning code generation */ + +/* Disable 32x32->64 bit multiplies that are used for long long multiplies + and division by constants, but sometimes cause reload problems. */ +#define TARGET_NO_WIDE_MULTIPLY (target_flags & MASK_NO_WIDE_MULTIPLY) +#define TARGET_WIDE_MULTIPLY (!TARGET_NO_WIDE_MULTIPLY) + +/* Debug GO_IF_LEGITIMATE_ADDRESS */ +#define TARGET_DEBUG_ADDR (target_flags & MASK_DEBUG_ADDR) + +/* Debug FUNCTION_ARG macros */ +#define TARGET_DEBUG_ARG (target_flags & MASK_DEBUG_ARG) + +/* Hack macros for tuning code generation */ +#define TARGET_MOVE ((target_flags & MASK_NO_MOVE) == 0) /* Don't generate memory->memory */ + +/* Specific hardware switches */ +#define TARGET_486 (target_flags & MASK_486) /* 80486DX, 80486SX, 80486DX[24] */ +#define TARGET_386 (!TARGET_486) /* 80386 */ + +#define TARGET_SWITCHES \ +{ { "80387", MASK_80387 }, \ + { "no-80387", -MASK_80387 }, \ + { "hard-float", MASK_80387 }, \ + { "soft-float", -MASK_80387 }, \ + { "no-soft-float", MASK_80387 }, \ + { "386", -MASK_486 }, \ + { "no-386", MASK_486 }, \ + { "486", MASK_486 }, \ + { "no-486", -MASK_486 }, \ + { "rtd", MASK_RTD }, \ + { "no-rtd", -MASK_RTD }, \ + { "align-double", MASK_ALIGN_DOUBLE }, \ + { "no-align-double", -MASK_ALIGN_DOUBLE }, \ + { "svr3-shlib", MASK_SVR3_SHLIB }, \ + { "no-svr3-shlib", -MASK_SVR3_SHLIB }, \ + { "ieee-fp", MASK_IEEE_FP }, \ + { "no-ieee-fp", -MASK_IEEE_FP }, \ + { "fp-ret-in-387", MASK_FLOAT_RETURNS }, \ + { "no-fp-ret-in-387", -MASK_FLOAT_RETURNS }, \ + { "no-fancy-math-387", MASK_NO_FANCY_MATH_387 }, \ + { "fancy-math-387", -MASK_NO_FANCY_MATH_387 }, \ + { "no-wide-multiply", MASK_NO_WIDE_MULTIPLY }, \ + { "wide-multiply", -MASK_NO_WIDE_MULTIPLY }, \ + { "debug-addr", MASK_DEBUG_ADDR }, \ + { "no-debug-addr", -MASK_DEBUG_ADDR }, \ + { "move", -MASK_NO_MOVE }, \ + { "no-move", MASK_NO_MOVE }, \ + { "debug-arg", MASK_DEBUG_ARG }, \ + { "no-debug-arg", -MASK_DEBUG_ARG }, \ + SUBTARGET_SWITCHES \ + { "", TARGET_DEFAULT | TARGET_CPU_DEFAULT}} + +/* This macro is similar to `TARGET_SWITCHES' but defines names of + command options that have values. Its definition is an + initializer with a subgrouping for each command option. + + Each subgrouping contains a string constant, that defines the + fixed part of the option name, and the address of a variable. The + variable, type `char *', is set to the variable part of the given + option if the fixed part matches. The actual option name is made + by appending `-m' to the specified name. */ +#define TARGET_OPTIONS \ +{ { "reg-alloc=", &i386_reg_alloc_order }, \ + { "regparm=", &i386_regparm_string }, \ + { "align-loops=", &i386_align_loops_string }, \ + { "align-jumps=", &i386_align_jumps_string }, \ + { "align-functions=", &i386_align_funcs_string }, \ + SUBTARGET_OPTIONS \ +} + +/* Sometimes certain combinations of command options do not make + sense on a particular target machine. You can define a macro + `OVERRIDE_OPTIONS' to take account of this. This macro, if + defined, is executed once just after all the command options have + been parsed. + + Don't use this macro to turn on various extra optimizations for + `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */ + +#define OVERRIDE_OPTIONS override_options () + +/* These are meant to be redefined in the host dependent files */ +#define SUBTARGET_SWITCHES +#define SUBTARGET_OPTIONS + + +/* target machine storage layout */ + +/* Define for XFmode extended real floating point support. + This will automatically cause REAL_ARITHMETIC to be defined. */ +#define LONG_DOUBLE_TYPE_SIZE 96 + +/* Define if you don't want extended real, but do want to use the + software floating point emulator for REAL_ARITHMETIC and + decimal <-> binary conversion. */ +/* #define REAL_ARITHMETIC */ + +/* Define this if most significant byte of a word is the lowest numbered. */ +/* That is true on the 80386. */ + +#define BITS_BIG_ENDIAN 0 + +/* Define this if most significant byte of a word is the lowest numbered. */ +/* That is not true on the 80386. */ +#define BYTES_BIG_ENDIAN 0 + +/* Define this if most significant word of a multiword number is the lowest + numbered. */ +/* Not true for 80386 */ +#define WORDS_BIG_ENDIAN 0 + +/* number of bits in an addressable storage unit */ +#define BITS_PER_UNIT 8 + +/* Width in bits of a "word", which is the contents of a machine register. + Note that this is not necessarily the width of data type `int'; + if using 16-bit ints on a 80386, this would still be 32. + But on a machine with 16-bit registers, this would be 16. */ +#define BITS_PER_WORD 32 + +/* Width of a word, in units (bytes). */ +#define UNITS_PER_WORD 4 + +/* Width in bits of a pointer. + See also the macro `Pmode' defined below. */ +#define POINTER_SIZE 32 + +/* Allocation boundary (in *bits*) for storing arguments in argument list. */ +#define PARM_BOUNDARY 32 + +/* Boundary (in *bits*) on which stack pointer should be aligned. */ +#define STACK_BOUNDARY 32 + +/* Allocation boundary (in *bits*) for the code of a function. + For i486, we get better performance by aligning to a cache + line (i.e. 16 byte) boundary. */ +#define FUNCTION_BOUNDARY (1 << (i386_align_funcs + 3)) + +/* Alignment of field after `int : 0' in a structure. */ + +#define EMPTY_FIELD_BOUNDARY 32 + +/* Minimum size in bits of the largest boundary to which any + and all fundamental data types supported by the hardware + might need to be aligned. No data type wants to be aligned + rounder than this. The i386 supports 64-bit floating point + quantities, but these can be aligned on any 32-bit boundary. + The published ABIs say that doubles should be aligned on word + boundaries, but the Pentium gets better performance with them + aligned on 64 bit boundaries. */ +#define BIGGEST_ALIGNMENT (TARGET_ALIGN_DOUBLE ? 64 : 32) + +/* Set this non-zero if move instructions will actually fail to work + when given unaligned data. */ +#define STRICT_ALIGNMENT 0 + +/* If bit field type is int, don't let it cross an int, + and give entire struct the alignment of an int. */ +/* Required on the 386 since it doesn't have bitfield insns. */ +#define PCC_BITFIELD_TYPE_MATTERS 1 + +/* Maximum power of 2 that code can be aligned to. */ +#define MAX_CODE_ALIGN 6 /* 64 byte alignment */ + +/* Align loop starts for optimal branching. */ +#define ASM_OUTPUT_LOOP_ALIGN(FILE) ASM_OUTPUT_ALIGN (FILE, i386_align_loops) + +/* This is how to align an instruction for optimal branching. + On i486 we'll get better performance by aligning on a + cache line (i.e. 16 byte) boundary. */ +#define ASM_OUTPUT_ALIGN_CODE(FILE) ASM_OUTPUT_ALIGN ((FILE), i386_align_jumps) + + +/* Standard register usage. */ + +/* This processor has special stack-like registers. See reg-stack.c + for details. */ + +#define STACK_REGS + +/* Number of actual hardware registers. + The hardware registers are assigned numbers for the compiler + from 0 to just below FIRST_PSEUDO_REGISTER. + All registers that the compiler knows about must be given numbers, + even those that are not normally considered general registers. + + In the 80386 we give the 8 general purpose registers the numbers 0-7. + We number the floating point registers 8-15. + Note that registers 0-7 can be accessed as a short or int, + while only 0-3 may be used with byte `mov' instructions. + + Reg 16 does not correspond to any hardware register, but instead + appears in the RTL as an argument pointer prior to reload, and is + eliminated during reloading in favor of either the stack or frame + pointer. */ + +#define FIRST_PSEUDO_REGISTER 17 + +/* 1 for registers that have pervasive standard uses + and are not available for the register allocator. + On the 80386, the stack pointer is such, as is the arg pointer. */ +#define FIXED_REGISTERS \ +/*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg*/ \ +{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 } + +/* 1 for registers not available across function calls. + These must include the FIXED_REGISTERS and also any + registers that can be used without being saved. + The latter must include the registers where values are returned + and the register where structure-value addresses are passed. + Aside from that, you can include as many other registers as you like. */ + +#define CALL_USED_REGISTERS \ +/*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg*/ \ +{ 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } + +/* Order in which to allocate registers. Each register must be + listed once, even those in FIXED_REGISTERS. List frame pointer + late and fixed registers last. Note that, in general, we prefer + registers listed in CALL_USED_REGISTERS, keeping the others + available for storage of persistent values. + + Three different versions of REG_ALLOC_ORDER have been tried: + + If the order is edx, ecx, eax, ... it produces a slightly faster compiler, + but slower code on simple functions returning values in eax. + + If the order is eax, ecx, edx, ... it causes reload to abort when compiling + perl 4.036 due to not being able to create a DImode register (to hold a 2 + word union). + + If the order is eax, edx, ecx, ... it produces better code for simple + functions, and a slightly slower compiler. Users complained about the code + generated by allocating edx first, so restore the 'natural' order of things. */ + +#define REG_ALLOC_ORDER \ +/*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg*/ \ +{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } + +/* A C statement (sans semicolon) to choose the order in which to + allocate hard registers for pseudo-registers local to a basic + block. + + Store the desired register order in the array `reg_alloc_order'. + Element 0 should be the register to allocate first; element 1, the + next register; and so on. + + The macro body should not assume anything about the contents of + `reg_alloc_order' before execution of the macro. + + On most machines, it is not necessary to define this macro. */ + +#define ORDER_REGS_FOR_LOCAL_ALLOC order_regs_for_local_alloc () + +/* Macro to conditionally modify fixed_regs/call_used_regs. */ +#define CONDITIONAL_REGISTER_USAGE \ + { \ + if (flag_pic) \ + { \ + fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \ + call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \ + } \ + if (! TARGET_80387 && ! TARGET_FLOAT_RETURNS_IN_80387) \ + { \ + int i; \ + HARD_REG_SET x; \ + COPY_HARD_REG_SET (x, reg_class_contents[(int)FLOAT_REGS]); \ + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++ ) \ + if (TEST_HARD_REG_BIT (x, i)) \ + fixed_regs[i] = call_used_regs[i] = 1; \ + } \ + } + +/* Return number of consecutive hard regs needed starting at reg REGNO + to hold something of mode MODE. + This is ordinarily the length in words of a value of mode MODE + but can be less for certain modes in special long registers. + + Actually there are no two word move instructions for consecutive + registers. And only registers 0-3 may have mov byte instructions + applied to them. + */ + +#define HARD_REGNO_NREGS(REGNO, MODE) \ + (FP_REGNO_P (REGNO) ? 1 \ + : ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)) + +/* Value is 1 if hard register REGNO can hold a value of machine-mode MODE. + On the 80386, the first 4 cpu registers can hold any mode + while the floating point registers may hold only floating point. + Make it clear that the fp regs could not hold a 16-byte float. */ + +/* The casts to int placate a compiler on a microvax, + for cross-compiler testing. */ + +#define HARD_REGNO_MODE_OK(REGNO, MODE) \ + ((REGNO) < 2 ? 1 \ + : (REGNO) < 4 ? 1 \ + : FP_REGNO_P (REGNO) \ + ? (((int) GET_MODE_CLASS (MODE) == (int) MODE_FLOAT \ + || (int) GET_MODE_CLASS (MODE) == (int) MODE_COMPLEX_FLOAT) \ + && GET_MODE_UNIT_SIZE (MODE) <= 12) \ + : (int) (MODE) != (int) QImode) + +/* Value is 1 if it is a good idea to tie two pseudo registers + when one has mode MODE1 and one has mode MODE2. + If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2, + for any hard reg, then this must be 0 for correct output. */ + +#define MODES_TIEABLE_P(MODE1, MODE2) ((MODE1) == (MODE2)) + +/* A C expression returning the cost of moving data from a register of class + CLASS1 to one of CLASS2. + + On the i386, copying between floating-point and fixed-point + registers is expensive. */ + +#define REGISTER_MOVE_COST(CLASS1, CLASS2) \ + (((FLOAT_CLASS_P (CLASS1) && ! FLOAT_CLASS_P (CLASS2)) \ + || (! FLOAT_CLASS_P (CLASS1) && FLOAT_CLASS_P (CLASS2))) ? 10 \ + : 2) + +/* Specify the registers used for certain standard purposes. + The values of these macros are register numbers. */ + +/* on the 386 the pc register is %eip, and is not usable as a general + register. The ordinary mov instructions won't work */ +/* #define PC_REGNUM */ + +/* Register to use for pushing function arguments. */ +#define STACK_POINTER_REGNUM 7 + +/* Base register for access to local variables of the function. */ +#define FRAME_POINTER_REGNUM 6 + +/* First floating point reg */ +#define FIRST_FLOAT_REG 8 + +/* First & last stack-like regs */ +#define FIRST_STACK_REG FIRST_FLOAT_REG +#define LAST_STACK_REG (FIRST_FLOAT_REG + 7) + +/* Value should be nonzero if functions must have frame pointers. + Zero means the frame pointer need not be set up (and parms + may be accessed via the stack pointer) in functions that seem suitable. + This is computed in `reload', in reload1.c. */ +#define FRAME_POINTER_REQUIRED 0 + +/* Base register for access to arguments of the function. */ +#define ARG_POINTER_REGNUM 16 + +/* Register in which static-chain is passed to a function. */ +#define STATIC_CHAIN_REGNUM 2 + +/* Register to hold the addressing base for position independent + code access to data items. */ +#define PIC_OFFSET_TABLE_REGNUM 3 + +/* Register in which address to store a structure value + arrives in the function. On the 386, the prologue + copies this from the stack to register %eax. */ +#define STRUCT_VALUE_INCOMING 0 + +/* Place in which caller passes the structure value address. + 0 means push the value on the stack like an argument. */ +#define STRUCT_VALUE 0 + +/* A C expression which can inhibit the returning of certain function + values in registers, based on the type of value. A nonzero value + says to return the function value in memory, just as large + structures are always returned. Here TYPE will be a C expression + of type `tree', representing the data type of the value. + + Note that values of mode `BLKmode' must be explicitly handled by + this macro. Also, the option `-fpcc-struct-return' takes effect + regardless of this macro. On most systems, it is possible to + leave the macro undefined; this causes a default definition to be + used, whose value is the constant 1 for `BLKmode' values, and 0 + otherwise. + + Do not use this macro to indicate that structures and unions + should always be returned in memory. You should instead use + `DEFAULT_PCC_STRUCT_RETURN' to indicate this. */ + +#define RETURN_IN_MEMORY(TYPE) \ + ((TYPE_MODE (TYPE) == BLKmode) || int_size_in_bytes (TYPE) > 12) + + +/* Define the classes of registers for register constraints in the + machine description. Also define ranges of constants. + + One of the classes must always be named ALL_REGS and include all hard regs. + If there is more than one class, another class must be named NO_REGS + and contain no registers. + + The name GENERAL_REGS must be the name of a class (or an alias for + another name such as ALL_REGS). This is the class of registers + that is allowed by "g" or "r" in a register constraint. + Also, registers outside this class are allocated only when + instructions express preferences for them. + + The classes must be numbered in nondecreasing order; that is, + a larger-numbered class must never be contained completely + in a smaller-numbered class. + + For any two classes, it is very desirable that there be another + class that represents their union. + + It might seem that class BREG is unnecessary, since no useful 386 + opcode needs reg %ebx. But some systems pass args to the OS in ebx, + and the "b" register constraint is useful in asms for syscalls. */ + +enum reg_class +{ + NO_REGS, + AREG, DREG, CREG, BREG, + AD_REGS, /* %eax/%edx for DImode */ + Q_REGS, /* %eax %ebx %ecx %edx */ + SIREG, DIREG, + INDEX_REGS, /* %eax %ebx %ecx %edx %esi %edi %ebp */ + GENERAL_REGS, /* %eax %ebx %ecx %edx %esi %edi %ebp %esp */ + FP_TOP_REG, FP_SECOND_REG, /* %st(0) %st(1) */ + FLOAT_REGS, + ALL_REGS, LIM_REG_CLASSES +}; + +#define N_REG_CLASSES (int) LIM_REG_CLASSES + +#define FLOAT_CLASS_P(CLASS) (reg_class_subset_p (CLASS, FLOAT_REGS)) + +/* Give names of register classes as strings for dump file. */ + +#define REG_CLASS_NAMES \ +{ "NO_REGS", \ + "AREG", "DREG", "CREG", "BREG", \ + "AD_REGS", \ + "Q_REGS", \ + "SIREG", "DIREG", \ + "INDEX_REGS", \ + "GENERAL_REGS", \ + "FP_TOP_REG", "FP_SECOND_REG", \ + "FLOAT_REGS", \ + "ALL_REGS" } + +/* Define which registers fit in which classes. + This is an initializer for a vector of HARD_REG_SET + of length N_REG_CLASSES. */ + +#define REG_CLASS_CONTENTS \ +{ 0, \ + 0x1, 0x2, 0x4, 0x8, /* AREG, DREG, CREG, BREG */ \ + 0x3, /* AD_REGS */ \ + 0xf, /* Q_REGS */ \ + 0x10, 0x20, /* SIREG, DIREG */ \ + 0x07f, /* INDEX_REGS */ \ + 0x100ff, /* GENERAL_REGS */ \ + 0x0100, 0x0200, /* FP_TOP_REG, FP_SECOND_REG */ \ + 0xff00, /* FLOAT_REGS */ \ + 0x1ffff } + +/* The same information, inverted: + Return the class number of the smallest class containing + reg number REGNO. This could be a conditional expression + or could index an array. */ + +#define REGNO_REG_CLASS(REGNO) (regclass_map[REGNO]) + +/* When defined, the compiler allows registers explicitly used in the + rtl to be used as spill registers but prevents the compiler from + extending the lifetime of these registers. */ + +#define SMALL_REGISTER_CLASSES + +#define QI_REG_P(X) \ + (REG_P (X) && REGNO (X) < 4) +#define NON_QI_REG_P(X) \ + (REG_P (X) && REGNO (X) >= 4 && REGNO (X) < FIRST_PSEUDO_REGISTER) + +#define FP_REG_P(X) (REG_P (X) && FP_REGNO_P (REGNO (X))) +#define FP_REGNO_P(n) ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) + +#define STACK_REG_P(xop) (REG_P (xop) && \ + REGNO (xop) >= FIRST_STACK_REG && \ + REGNO (xop) <= LAST_STACK_REG) + +#define NON_STACK_REG_P(xop) (REG_P (xop) && ! STACK_REG_P (xop)) + +#define STACK_TOP_P(xop) (REG_P (xop) && REGNO (xop) == FIRST_STACK_REG) + +/* Try to maintain the accuracy of the death notes for regs satisfying the + following. Important for stack like regs, to know when to pop. */ + +/* #define PRESERVE_DEATH_INFO_REGNO_P(x) FP_REGNO_P(x) */ + +/* 1 if register REGNO can magically overlap other regs. + Note that nonzero values work only in very special circumstances. */ + +/* #define OVERLAPPING_REGNO_P(REGNO) FP_REGNO_P (REGNO) */ + +/* The class value for index registers, and the one for base regs. */ + +#define INDEX_REG_CLASS INDEX_REGS +#define BASE_REG_CLASS GENERAL_REGS + +/* Get reg_class from a letter such as appears in the machine description. */ + +#define REG_CLASS_FROM_LETTER(C) \ + ((C) == 'r' ? GENERAL_REGS : \ + (C) == 'q' ? Q_REGS : \ + (C) == 'f' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \ + ? FLOAT_REGS \ + : NO_REGS) : \ + (C) == 't' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \ + ? FP_TOP_REG \ + : NO_REGS) : \ + (C) == 'u' ? (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387 \ + ? FP_SECOND_REG \ + : NO_REGS) : \ + (C) == 'a' ? AREG : \ + (C) == 'b' ? BREG : \ + (C) == 'c' ? CREG : \ + (C) == 'd' ? DREG : \ + (C) == 'A' ? AD_REGS : \ + (C) == 'D' ? DIREG : \ + (C) == 'S' ? SIREG : NO_REGS) + +/* The letters I, J, K, L and M in a register constraint string + can be used to stand for particular ranges of immediate operands. + This macro defines what the ranges are. + C is the letter, and VALUE is a constant value. + Return 1 if VALUE is in the range specified by C. + + I is for non-DImode shifts. + J is for DImode shifts. + K and L are for an `andsi' optimization. + M is for shifts that can be executed by the "lea" opcode. + */ + +#define CONST_OK_FOR_LETTER_P(VALUE, C) \ + ((C) == 'I' ? (VALUE) >= 0 && (VALUE) <= 31 : \ + (C) == 'J' ? (VALUE) >= 0 && (VALUE) <= 63 : \ + (C) == 'K' ? (VALUE) == 0xff : \ + (C) == 'L' ? (VALUE) == 0xffff : \ + (C) == 'M' ? (VALUE) >= 0 && (VALUE) <= 3 : \ + (C) == 'N' ? (VALUE) >= 0 && (VALUE) <= 255 :\ + 0) + +/* Similar, but for floating constants, and defining letters G and H. + Here VALUE is the CONST_DOUBLE rtx itself. We allow constants even if + TARGET_387 isn't set, because the stack register converter may need to + load 0.0 into the function value register. */ + +#define CONST_DOUBLE_OK_FOR_LETTER_P(VALUE, C) \ + ((C) == 'G' ? standard_80387_constant_p (VALUE) : 0) + +/* Place additional restrictions on the register class to use when it + is necessary to be able to hold a value of mode MODE in a reload + register for which class CLASS would ordinarily be used. */ + +#define LIMIT_RELOAD_CLASS(MODE, CLASS) \ + ((MODE) == QImode && ((CLASS) == ALL_REGS || (CLASS) == GENERAL_REGS) \ + ? Q_REGS : (CLASS)) + +/* Given an rtx X being reloaded into a reg required to be + in class CLASS, return the class of reg to actually use. + In general this is just CLASS; but on some machines + in some cases it is preferable to use a more restrictive class. + On the 80386 series, we prevent floating constants from being + reloaded into floating registers (since no move-insn can do that) + and we ensure that QImodes aren't reloaded into the esi or edi reg. */ + +/* Put float CONST_DOUBLE in the constant pool instead of fp regs. + QImode must go into class Q_REGS. + Narrow ALL_REGS to GENERAL_REGS. This supports allowing movsf and + movdf to do mem-to-mem moves through integer regs. */ + +#define PREFERRED_RELOAD_CLASS(X,CLASS) \ + (GET_CODE (X) == CONST_DOUBLE && GET_MODE (X) != VOIDmode ? NO_REGS \ + : GET_MODE (X) == QImode && ! reg_class_subset_p (CLASS, Q_REGS) ? Q_REGS \ + : ((CLASS) == ALL_REGS \ + && GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT) ? GENERAL_REGS \ + : (CLASS)) + +/* If we are copying between general and FP registers, we need a memory + location. */ + +#define SECONDARY_MEMORY_NEEDED(CLASS1,CLASS2,MODE) \ + ((FLOAT_CLASS_P (CLASS1) && ! FLOAT_CLASS_P (CLASS2)) \ + || (! FLOAT_CLASS_P (CLASS1) && FLOAT_CLASS_P (CLASS2))) + +/* Return the maximum number of consecutive registers + needed to represent mode MODE in a register of class CLASS. */ +/* On the 80386, this is the size of MODE in words, + except in the FP regs, where a single reg is always enough. */ +#define CLASS_MAX_NREGS(CLASS, MODE) \ + (FLOAT_CLASS_P (CLASS) ? 1 : \ + ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)) + +/* A C expression whose value is nonzero if pseudos that have been + assigned to registers of class CLASS would likely be spilled + because registers of CLASS are needed for spill registers. + + The default value of this macro returns 1 if CLASS has exactly one + register and zero otherwise. On most machines, this default + should be used. Only define this macro to some other expression + if pseudo allocated by `local-alloc.c' end up in memory because + their hard registers were needed for spill registers. If this + macro returns nonzero for those classes, those pseudos will only + be allocated by `global.c', which knows how to reallocate the + pseudo to another register. If there would not be another + register available for reallocation, you should not change the + definition of this macro since the only effect of such a + definition would be to slow down register allocation. */ + +#define CLASS_LIKELY_SPILLED_P(CLASS) \ + (((CLASS) == AREG) \ + || ((CLASS) == DREG) \ + || ((CLASS) == CREG) \ + || ((CLASS) == BREG) \ + || ((CLASS) == AD_REGS) \ + || ((CLASS) == SIREG) \ + || ((CLASS) == DIREG)) + + +/* Stack layout; function entry, exit and calling. */ + +/* Define this if pushing a word on the stack + makes the stack pointer a smaller address. */ +#define STACK_GROWS_DOWNWARD + +/* Define this if the nominal address of the stack frame + is at the high-address end of the local variables; + that is, each additional local variable allocated + goes at a more negative offset in the frame. */ +#define FRAME_GROWS_DOWNWARD + +/* Offset within stack frame to start allocating local variables at. + If FRAME_GROWS_DOWNWARD, this is the offset to the END of the + first local allocated. Otherwise, it is the offset to the BEGINNING + of the first local allocated. */ +#define STARTING_FRAME_OFFSET 0 + +/* If we generate an insn to push BYTES bytes, + this says how many the stack pointer really advances by. + On 386 pushw decrements by exactly 2 no matter what the position was. + On the 386 there is no pushb; we use pushw instead, and this + has the effect of rounding up to 2. */ + +#define PUSH_ROUNDING(BYTES) (((BYTES) + 1) & (-2)) + +/* Offset of first parameter from the argument pointer register value. */ +#define FIRST_PARM_OFFSET(FNDECL) 0 + +/* Value is the number of bytes of arguments automatically + popped when returning from a subroutine call. + FUNDECL is the declaration node of the function (as a tree), + FUNTYPE is the data type of the function (as a tree), + or for a library call it is an identifier node for the subroutine name. + SIZE is the number of bytes of arguments passed on the stack. + + On the 80386, the RTD insn may be used to pop them if the number + of args is fixed, but if the number is variable then the caller + must pop them all. RTD can't be used for library calls now + because the library is compiled with the Unix compiler. + Use of RTD is a selectable option, since it is incompatible with + standard Unix calling sequences. If the option is not selected, + the caller must always pop the args. + + The attribute stdcall is equivalent to RTD on a per module basis. */ + +#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \ + (i386_return_pops_args (FUNDECL, FUNTYPE, SIZE)) + +/* Define how to find the value returned by a function. + VALTYPE is the data type of the value (as a tree). + If the precise function being called is known, FUNC is its FUNCTION_DECL; + otherwise, FUNC is 0. */ +#define FUNCTION_VALUE(VALTYPE, FUNC) \ + gen_rtx (REG, TYPE_MODE (VALTYPE), \ + VALUE_REGNO (TYPE_MODE (VALTYPE))) + +/* Define how to find the value returned by a library function + assuming the value has mode MODE. */ + +#define LIBCALL_VALUE(MODE) \ + gen_rtx (REG, MODE, VALUE_REGNO (MODE)) + +/* Define the size of the result block used for communication between + untyped_call and untyped_return. The block contains a DImode value + followed by the block used by fnsave and frstor. */ + +#define APPLY_RESULT_SIZE (8+108) + +/* 1 if N is a possible register number for function argument passing. */ +#define FUNCTION_ARG_REGNO_P(N) ((N) >= 0 && (N) < REGPARM_MAX) + +/* Define a data type for recording info about an argument list + during the scan of that argument list. This data type should + hold all necessary information about the function itself + and about the args processed so far, enough to enable macros + such as FUNCTION_ARG to determine where the next arg should go. */ + +typedef struct i386_args { + int words; /* # words passed so far */ + int nregs; /* # registers available for passing */ + int regno; /* next available register number */ +} CUMULATIVE_ARGS; + +/* Initialize a variable CUM of type CUMULATIVE_ARGS + for a call to a function whose data type is FNTYPE. + For a library call, FNTYPE is 0. */ + +#define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME) \ + (init_cumulative_args (&CUM, FNTYPE, LIBNAME)) + +/* Update the data in CUM to advance over an argument + of mode MODE and data type TYPE. + (TYPE is null for libcalls where that information may not be available.) */ + +#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \ + (function_arg_advance (&CUM, MODE, TYPE, NAMED)) + +/* Define where to put the arguments to a function. + Value is zero to push the argument on the stack, + or a hard register in which to store the argument. + + MODE is the argument's machine mode. + TYPE is the data type of the argument (as a tree). + This is null for libcalls where that information may + not be available. + CUM is a variable of type CUMULATIVE_ARGS which gives info about + the preceding args and about the function being called. + NAMED is nonzero if this argument is a named parameter + (otherwise it is an extra parameter matching an ellipsis). */ + +#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \ + (function_arg (&CUM, MODE, TYPE, NAMED)) + +/* For an arg passed partly in registers and partly in memory, + this is the number of registers used. + For args passed entirely in registers or entirely in memory, zero. */ + +#define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) \ + (function_arg_partial_nregs (&CUM, MODE, TYPE, NAMED)) + +/* This macro generates the assembly code for function entry. + FILE is a stdio stream to output the code to. + SIZE is an int: how many units of temporary storage to allocate. + Refer to the array `regs_ever_live' to determine which registers + to save; `regs_ever_live[I]' is nonzero if register number I + is ever used in the function. This macro is responsible for + knowing which registers should not be saved even if used. */ + +#define FUNCTION_PROLOGUE(FILE, SIZE) \ + function_prologue (FILE, SIZE) + +/* Output assembler code to FILE to increment profiler label # LABELNO + for profiling a function entry. */ + +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *_mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall _mcount\n"); \ + } \ +} + +/* A C statement or compound statement to output to FILE some + assembler code to initialize basic-block profiling for the current + object module. This code should call the subroutine + `__bb_init_func' once per object module, passing it as its sole + argument the address of a block allocated in the object module. + + The name of the block is a local symbol made with this statement: + + ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0); + + Of course, since you are writing the definition of + `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you + can take a short cut in the definition of this macro and use the + name that you know will result. + + The first word of this block is a flag which will be nonzero if the + object module has already been initialized. So test this word + first, and do not call `__bb_init_func' if the flag is nonzero. */ + +#undef FUNCTION_BLOCK_PROFILER +#define FUNCTION_BLOCK_PROFILER(STREAM, LABELNO) \ +do \ + { \ + static int num_func = 0; \ + rtx xops[8]; \ + char block_table[80], false_label[80]; \ + \ + ASM_GENERATE_INTERNAL_LABEL (block_table, "LPBX", 0); \ + ASM_GENERATE_INTERNAL_LABEL (false_label, "LPBZ", num_func); \ + \ + xops[0] = const0_rtx; \ + xops[1] = gen_rtx (SYMBOL_REF, VOIDmode, block_table); \ + xops[2] = gen_rtx (MEM, Pmode, gen_rtx (SYMBOL_REF, VOIDmode, false_label)); \ + xops[3] = gen_rtx (MEM, Pmode, gen_rtx (SYMBOL_REF, VOIDmode, "__bb_init_func")); \ + xops[4] = gen_rtx (MEM, Pmode, xops[1]); \ + xops[5] = stack_pointer_rtx; \ + xops[6] = GEN_INT (4); \ + xops[7] = gen_rtx (REG, Pmode, 0); /* eax */ \ + \ + CONSTANT_POOL_ADDRESS_P (xops[1]) = TRUE; \ + CONSTANT_POOL_ADDRESS_P (xops[2]) = TRUE; \ + \ + output_asm_insn (AS2(cmp%L4,%0,%4), xops); \ + output_asm_insn (AS1(jne,%2), xops); \ + \ + if (!flag_pic) \ + output_asm_insn (AS1(push%L1,%1), xops); \ + else \ + { \ + output_asm_insn (AS2 (lea%L7,%a1,%7), xops); \ + output_asm_insn (AS1 (push%L7,%7), xops); \ + } \ + \ + output_asm_insn (AS1(call,%P3), xops); \ + output_asm_insn (AS2(add%L0,%6,%5), xops); \ + ASM_OUTPUT_INTERNAL_LABEL (STREAM, "LPBZ", num_func); \ + num_func++; \ + } \ +while (0) + + +/* A C statement or compound statement to increment the count + associated with the basic block number BLOCKNO. Basic blocks are + numbered separately from zero within each compilation. The count + associated with block number BLOCKNO is at index BLOCKNO in a + vector of words; the name of this array is a local symbol made + with this statement: + + ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 2); + + Of course, since you are writing the definition of + `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you + can take a short cut in the definition of this macro and use the + name that you know will result. */ + +#define BLOCK_PROFILER(STREAM, BLOCKNO) \ +do \ + { \ + rtx xops[1], cnt_rtx; \ + char counts[80]; \ + \ + ASM_GENERATE_INTERNAL_LABEL (counts, "LPBX", 2); \ + cnt_rtx = gen_rtx (SYMBOL_REF, VOIDmode, counts); \ + SYMBOL_REF_FLAG (cnt_rtx) = TRUE; \ + \ + if (BLOCKNO) \ + cnt_rtx = plus_constant (cnt_rtx, (BLOCKNO)*4); \ + \ + if (flag_pic) \ + cnt_rtx = gen_rtx (PLUS, Pmode, pic_offset_table_rtx, cnt_rtx); \ + \ + xops[0] = gen_rtx (MEM, SImode, cnt_rtx); \ + output_asm_insn (AS1(inc%L0,%0), xops); \ + } \ +while (0) + +/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function, + the stack pointer does not matter. The value is tested only in + functions that have frame pointers. + No definition is equivalent to always zero. */ +/* Note on the 386 it might be more efficient not to define this since + we have to restore it ourselves from the frame pointer, in order to + use pop */ + +#define EXIT_IGNORE_STACK 1 + +/* This macro generates the assembly code for function exit, + on machines that need it. If FUNCTION_EPILOGUE is not defined + then individual return instructions are generated for each + return statement. Args are same as for FUNCTION_PROLOGUE. + + The function epilogue should not depend on the current stack pointer! + It should use the frame pointer only. This is mandatory because + of alloca; we also take advantage of it to omit stack adjustments + before returning. + + If the last non-note insn in the function is a BARRIER, then there + is no need to emit a function prologue, because control does not fall + off the end. This happens if the function ends in an "exit" call, or + if a `return' insn is emitted directly into the function. */ + +#define FUNCTION_EPILOGUE(FILE, SIZE) \ +do { \ + rtx last = get_last_insn (); \ + if (last && GET_CODE (last) == NOTE) \ + last = prev_nonnote_insn (last); \ + if (! last || GET_CODE (last) != BARRIER) \ + function_epilogue (FILE, SIZE); \ +} while (0) + +/* Output assembler code for a block containing the constant parts + of a trampoline, leaving space for the variable parts. */ + +/* On the 386, the trampoline contains three instructions: + mov #STATIC,ecx + mov #FUNCTION,eax + jmp @eax */ +#define TRAMPOLINE_TEMPLATE(FILE) \ +{ \ + ASM_OUTPUT_CHAR (FILE, GEN_INT (0xb9)); \ + ASM_OUTPUT_SHORT (FILE, const0_rtx); \ + ASM_OUTPUT_SHORT (FILE, const0_rtx); \ + ASM_OUTPUT_CHAR (FILE, GEN_INT (0xb8)); \ + ASM_OUTPUT_SHORT (FILE, const0_rtx); \ + ASM_OUTPUT_SHORT (FILE, const0_rtx); \ + ASM_OUTPUT_CHAR (FILE, GEN_INT (0xff)); \ + ASM_OUTPUT_CHAR (FILE, GEN_INT (0xe0)); \ +} + +/* Length in units of the trampoline for entering a nested function. */ + +#define TRAMPOLINE_SIZE 12 + +/* Emit RTL insns to initialize the variable parts of a trampoline. + FNADDR is an RTX for the address of the function's pure code. + CXT is an RTX for the static chain value for the function. */ + +#define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \ +{ \ + emit_move_insn (gen_rtx (MEM, SImode, plus_constant (TRAMP, 1)), CXT); \ + emit_move_insn (gen_rtx (MEM, SImode, plus_constant (TRAMP, 6)), FNADDR); \ +} + +/* Definitions for register eliminations. + + This is an array of structures. Each structure initializes one pair + of eliminable registers. The "from" register number is given first, + followed by "to". Eliminations of the same "from" register are listed + in order of preference. + + We have two registers that can be eliminated on the i386. First, the + frame pointer register can often be eliminated in favor of the stack + pointer register. Secondly, the argument pointer register can always be + eliminated; it is replaced with either the stack or frame pointer. */ + +#define ELIMINABLE_REGS \ +{{ ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \ + { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \ + { FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}} + +/* Given FROM and TO register numbers, say whether this elimination is allowed. + Frame pointer elimination is automatically handled. + + For the i386, if frame pointer elimination is being done, we would like to + convert ap into sp, not fp. + + All other eliminations are valid. */ + +#define CAN_ELIMINATE(FROM, TO) \ + ((FROM) == ARG_POINTER_REGNUM && (TO) == STACK_POINTER_REGNUM \ + ? ! frame_pointer_needed \ + : 1) + +/* Define the offset between two registers, one to be eliminated, and the other + its replacement, at the start of a routine. */ + +#define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \ +{ \ + if ((FROM) == ARG_POINTER_REGNUM && (TO) == FRAME_POINTER_REGNUM) \ + (OFFSET) = 8; /* Skip saved PC and previous frame pointer */ \ + else \ + { \ + int regno; \ + int offset = 0; \ + \ + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) \ + if ((regs_ever_live[regno] && ! call_used_regs[regno]) \ + || (current_function_uses_pic_offset_table \ + && regno == PIC_OFFSET_TABLE_REGNUM)) \ + offset += 4; \ + \ + (OFFSET) = offset + get_frame_size (); \ + \ + if ((FROM) == ARG_POINTER_REGNUM && (TO) == STACK_POINTER_REGNUM) \ + (OFFSET) += 4; /* Skip saved PC */ \ + } \ +} + +/* Addressing modes, and classification of registers for them. */ + +/* #define HAVE_POST_INCREMENT */ +/* #define HAVE_POST_DECREMENT */ + +/* #define HAVE_PRE_DECREMENT */ +/* #define HAVE_PRE_INCREMENT */ + +/* Macros to check register numbers against specific register classes. */ + +/* These assume that REGNO is a hard or pseudo reg number. + They give nonzero only if REGNO is a hard reg of the suitable class + or a pseudo reg currently allocated to a suitable hard reg. + Since they use reg_renumber, they are safe only once reg_renumber + has been allocated, which happens in local-alloc.c. */ + +#define REGNO_OK_FOR_INDEX_P(REGNO) \ + ((REGNO) < STACK_POINTER_REGNUM \ + || (unsigned) reg_renumber[REGNO] < STACK_POINTER_REGNUM) + +#define REGNO_OK_FOR_BASE_P(REGNO) \ + ((REGNO) <= STACK_POINTER_REGNUM \ + || (REGNO) == ARG_POINTER_REGNUM \ + || (unsigned) reg_renumber[REGNO] <= STACK_POINTER_REGNUM) + +#define REGNO_OK_FOR_SIREG_P(REGNO) ((REGNO) == 4 || reg_renumber[REGNO] == 4) +#define REGNO_OK_FOR_DIREG_P(REGNO) ((REGNO) == 5 || reg_renumber[REGNO] == 5) + +/* The macros REG_OK_FOR..._P assume that the arg is a REG rtx + and check its validity for a certain class. + We have two alternate definitions for each of them. + The usual definition accepts all pseudo regs; the other rejects + them unless they have been allocated suitable hard regs. + The symbol REG_OK_STRICT causes the latter definition to be used. + + Most source files want to accept pseudo regs in the hope that + they will get allocated to the class that the insn wants them to be in. + Source files for reload pass need to be strict. + After reload, it makes no difference, since pseudo regs have + been eliminated by then. */ + + +/* Non strict versions, pseudos are ok */ +#define REG_OK_FOR_INDEX_NONSTRICT_P(X) \ + (REGNO (X) < STACK_POINTER_REGNUM \ + || REGNO (X) >= FIRST_PSEUDO_REGISTER) + +#define REG_OK_FOR_BASE_NONSTRICT_P(X) \ + (REGNO (X) <= STACK_POINTER_REGNUM \ + || REGNO (X) == ARG_POINTER_REGNUM \ + || REGNO (X) >= FIRST_PSEUDO_REGISTER) + +#define REG_OK_FOR_STRREG_NONSTRICT_P(X) \ + (REGNO (X) == 4 || REGNO (X) == 5 || REGNO (X) >= FIRST_PSEUDO_REGISTER) + +/* Strict versions, hard registers only */ +#define REG_OK_FOR_INDEX_STRICT_P(X) REGNO_OK_FOR_INDEX_P (REGNO (X)) +#define REG_OK_FOR_BASE_STRICT_P(X) REGNO_OK_FOR_BASE_P (REGNO (X)) +#define REG_OK_FOR_STRREG_STRICT_P(X) \ + (REGNO_OK_FOR_DIREG_P (REGNO (X)) || REGNO_OK_FOR_SIREG_P (REGNO (X))) + +#ifndef REG_OK_STRICT +#define REG_OK_FOR_INDEX_P(X) REG_OK_FOR_INDEX_NONSTRICT_P(X) +#define REG_OK_FOR_BASE_P(X) REG_OK_FOR_BASE_NONSTRICT_P(X) +#define REG_OK_FOR_STRREG_P(X) REG_OK_FOR_STRREG_NONSTRICT_P(X) + +#else +#define REG_OK_FOR_INDEX_P(X) REG_OK_FOR_INDEX_STRICT_P(X) +#define REG_OK_FOR_BASE_P(X) REG_OK_FOR_BASE_STRICT_P(X) +#define REG_OK_FOR_STRREG_P(X) REG_OK_FOR_STRREG_STRICT_P(X) +#endif + +/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression + that is a valid memory address for an instruction. + The MODE argument is the machine mode for the MEM expression + that wants to use this address. + + The other macros defined here are used only in GO_IF_LEGITIMATE_ADDRESS, + except for CONSTANT_ADDRESS_P which is usually machine-independent. + + See legitimize_pic_address in i386.c for details as to what + constitutes a legitimate address when -fpic is used. */ + +#define MAX_REGS_PER_ADDRESS 2 + +#define CONSTANT_ADDRESS_P(X) \ + (GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \ + || GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST \ + || GET_CODE (X) == HIGH) + +/* Nonzero if the constant value X is a legitimate general operand. + It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE. */ + +#define LEGITIMATE_CONSTANT_P(X) 1 + +#ifdef REG_OK_STRICT +#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR) \ +{ \ + if (legitimate_address_p (MODE, X, 1)) \ + goto ADDR; \ +} + +#else +#define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR) \ +{ \ + if (legitimate_address_p (MODE, X, 0)) \ + goto ADDR; \ +} + +#endif + +/* Try machine-dependent ways of modifying an illegitimate address + to be legitimate. If we find one, return the new, valid address. + This macro is used in only one place: `memory_address' in explow.c. + + OLDX is the address as it was before break_out_memory_refs was called. + In some cases it is useful to look at this to decide what needs to be done. + + MODE and WIN are passed so that this macro can use + GO_IF_LEGITIMATE_ADDRESS. + + It is always safe for this macro to do nothing. It exists to recognize + opportunities to optimize the output. + + For the 80386, we handle X+REG by loading X into a register R and + using R+REG. R will go in a general reg and indexing will be used. + However, if REG is a broken-out memory address or multiplication, + nothing needs to be done because REG can certainly go in a general reg. + + When -fpic is used, special handling is needed for symbolic references. + See comments by legitimize_pic_address in i386.c for details. */ + +#define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN) \ +{ \ + rtx orig_x = (X); \ + (X) = legitimize_address (X, OLDX, MODE); \ + if (memory_address_p (MODE, X)) \ + goto WIN; \ +} + +/* Nonzero if the constant value X is a legitimate general operand + when generating PIC code. It is given that flag_pic is on and + that X satisfies CONSTANT_P or is a CONST_DOUBLE. */ + +#define LEGITIMATE_PIC_OPERAND_P(X) \ + (! SYMBOLIC_CONST (X) \ + || (GET_CODE (X) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (X))) + +#define SYMBOLIC_CONST(X) \ +(GET_CODE (X) == SYMBOL_REF \ + || GET_CODE (X) == LABEL_REF \ + || (GET_CODE (X) == CONST && symbolic_reference_mentioned_p (X))) + +/* Go to LABEL if ADDR (a legitimate address expression) + has an effect that depends on the machine mode it is used for. + On the 80386, only postdecrement and postincrement address depend thus + (the amount of decrement or increment being the length of the operand). */ +#define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR,LABEL) \ + if (GET_CODE (ADDR) == POST_INC || GET_CODE (ADDR) == POST_DEC) goto LABEL + +/* Define this macro if references to a symbol must be treated + differently depending on something about the variable or + function named by the symbol (such as what section it is in). + + On i386, if using PIC, mark a SYMBOL_REF for a non-global symbol + so that we may access it directly in the GOT. */ + +#define ENCODE_SECTION_INFO(DECL) \ +do \ + { \ + if (flag_pic) \ + { \ + rtx rtl = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + ? TREE_CST_RTL (DECL) : DECL_RTL (DECL)); \ + SYMBOL_REF_FLAG (XEXP (rtl, 0)) \ + = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + || ! TREE_PUBLIC (DECL)); \ + } \ + } \ +while (0) + +/* Initialize data used by insn expanders. This is called from + init_emit, once for each function, before code is generated. + For 386, clear stack slot assignments remembered from previous + functions. */ + +#define INIT_EXPANDERS clear_386_stack_locals () + +/* The `FINALIZE_PIC' macro serves as a hook to emit these special + codes once the function is being compiled into assembly code, but + not before. (It is not done before, because in the case of + compiling an inline function, it would lead to multiple PIC + prologues being included in functions which used inline functions + and were compiled to assembly language.) */ + +#define FINALIZE_PIC \ +do \ + { \ + extern int current_function_uses_pic_offset_table; \ + \ + current_function_uses_pic_offset_table |= profile_flag | profile_block_flag; \ + } \ +while (0) + + +/* If defined, a C expression whose value is nonzero if IDENTIFIER + with arguments ARGS is a valid machine specific attribute for DECL. + The attributes in ATTRIBUTES have previously been assigned to DECL. */ + +#define VALID_MACHINE_DECL_ATTRIBUTE(DECL, ATTRIBUTES, NAME, ARGS) \ + (i386_valid_decl_attribute_p (DECL, ATTRIBUTES, NAME, ARGS)) + +/* If defined, a C expression whose value is nonzero if IDENTIFIER + with arguments ARGS is a valid machine specific attribute for TYPE. + The attributes in ATTRIBUTES have previously been assigned to TYPE. */ + +#define VALID_MACHINE_TYPE_ATTRIBUTE(TYPE, ATTRIBUTES, NAME, ARGS) \ + (i386_valid_type_attribute_p (TYPE, ATTRIBUTES, NAME, ARGS)) + +/* If defined, a C expression whose value is zero if the attributes on + TYPE1 and TYPE2 are incompatible, one if they are compatible, and + two if they are nearly compatible (which causes a warning to be + generated). */ + +#define COMP_TYPE_ATTRIBUTES(TYPE1, TYPE2) \ + (i386_comp_type_attributes (TYPE1, TYPE2)) + +/* If defined, a C statement that assigns default attributes to newly + defined TYPE. */ + +/* #define SET_DEFAULT_TYPE_ATTRIBUTES (TYPE) */ + +/* Max number of args passed in registers. If this is more than 3, we will + have problems with ebx (register #4), since it is a caller save register and + is also used as the pic register in ELF. So for now, don't allow more than + 3 registers to be passed in registers. */ + +#define REGPARM_MAX 3 + + +/* Specify the machine mode that this machine uses + for the index in the tablejump instruction. */ +#define CASE_VECTOR_MODE Pmode + +/* Define this if the tablejump instruction expects the table + to contain offsets from the address of the table. + Do not define this if the table should contain absolute addresses. */ +/* #define CASE_VECTOR_PC_RELATIVE */ + +/* Specify the tree operation to be used to convert reals to integers. + This should be changed to take advantage of fist --wfs ?? + */ +#define IMPLICIT_FIX_EXPR FIX_ROUND_EXPR + +/* This is the kind of divide that is easiest to do in the general case. */ +#define EASY_DIV_EXPR TRUNC_DIV_EXPR + +/* Define this as 1 if `char' should by default be signed; else as 0. */ +#define DEFAULT_SIGNED_CHAR 1 + +/* Max number of bytes we can move from memory to memory + in one reasonably fast instruction. */ +#define MOVE_MAX 4 + +/* MOVE_RATIO is the number of move instructions that is better than a + block move. Make this large on i386, since the block move is very + inefficient with small blocks, and the hard register needs of the + block move require much reload work. */ +#define MOVE_RATIO 5 + +/* Define this if zero-extension is slow (more than one real instruction). */ +/* #define SLOW_ZERO_EXTEND */ + +/* Nonzero if access to memory by bytes is slow and undesirable. */ +#define SLOW_BYTE_ACCESS 0 + +/* Define if shifts truncate the shift count + which implies one can omit a sign-extension or zero-extension + of a shift count. */ +/* One i386, shifts do truncate the count. But bit opcodes don't. */ + +/* #define SHIFT_COUNT_TRUNCATED */ + +/* Value is 1 if truncating an integer of INPREC bits to OUTPREC bits + is done just by pretending it is already truncated. */ +#define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC) 1 + +/* We assume that the store-condition-codes instructions store 0 for false + and some other value for true. This is the value stored for true. */ + +#define STORE_FLAG_VALUE 1 + +/* When a prototype says `char' or `short', really pass an `int'. + (The 386 can't easily push less than an int.) */ + +#define PROMOTE_PROTOTYPES + +/* Specify the machine mode that pointers have. + After generation of rtl, the compiler makes no further distinction + between pointers and any other objects of this machine mode. */ +#define Pmode SImode + +/* A function address in a call instruction + is a byte address (for indexing purposes) + so give the MEM rtx a byte's mode. */ +#define FUNCTION_MODE QImode + +/* Define this if addresses of constant functions + shouldn't be put through pseudo regs where they can be cse'd. + Desirable on the 386 because a CALL with a constant address is + not much slower than one with a register address. On a 486, + it is faster to call with a constant address than indirect. */ +#define NO_FUNCTION_CSE + +/* Provide the costs of a rtl expression. This is in the body of a + switch on CODE. */ + +#define RTX_COSTS(X,CODE,OUTER_CODE) \ + case MULT: \ + return COSTS_N_INSNS (20); \ + case DIV: \ + case UDIV: \ + case MOD: \ + case UMOD: \ + return COSTS_N_INSNS (20); \ + case ASHIFTRT: \ + case LSHIFTRT: \ + case ASHIFT: \ + return (4 + rtx_cost (XEXP (X, 0), OUTER_CODE) \ + + rtx_cost (XEXP (X, 1), OUTER_CODE)); \ + case PLUS: \ + if (GET_CODE (XEXP (X, 0)) == MULT \ + && GET_CODE (XEXP (XEXP (X, 0), 1)) == CONST_INT \ + && (INTVAL (XEXP (XEXP (X, 0), 1)) == 2 \ + || INTVAL (XEXP (XEXP (X, 0), 1)) == 4 \ + || INTVAL (XEXP (XEXP (X, 0), 1)) == 8)) \ + return (2 + rtx_cost (XEXP (XEXP (X, 0), 0), OUTER_CODE) \ + + rtx_cost (XEXP (X, 1), OUTER_CODE)); \ + break; + + +/* Compute the cost of computing a constant rtl expression RTX + whose rtx-code is CODE. The body of this macro is a portion + of a switch statement. If the code is computed here, + return it with a return statement. Otherwise, break from the switch. */ + +#define CONST_COSTS(RTX,CODE,OUTER_CODE) \ + case CONST_INT: \ + case CONST: \ + case LABEL_REF: \ + case SYMBOL_REF: \ + return flag_pic && SYMBOLIC_CONST (RTX) ? 2 : 0; \ + case CONST_DOUBLE: \ + { \ + int code; \ + if (GET_MODE (RTX) == VOIDmode) \ + return 2; \ + code = standard_80387_constant_p (RTX); \ + return code == 1 ? 0 : \ + code == 2 ? 1 : \ + 2; \ + } + +/* Compute the cost of an address. This is meant to approximate the size + and/or execution delay of an insn using that address. If the cost is + approximated by the RTL complexity, including CONST_COSTS above, as + is usually the case for CISC machines, this macro should not be defined. + For aggressively RISCy machines, only one insn format is allowed, so + this macro should be a constant. The value of this macro only matters + for valid addresses. + + For i386, it is better to use a complex address than let gcc copy + the address into a reg and make a new pseudo. But not if the address + requires to two regs - that would mean more pseudos with longer + lifetimes. */ + +#define ADDRESS_COST(RTX) \ + ((CONSTANT_P (RTX) \ + || (GET_CODE (RTX) == PLUS && CONSTANT_P (XEXP (RTX, 1)) \ + && REG_P (XEXP (RTX, 0)))) ? 0 \ + : REG_P (RTX) ? 1 \ + : 2) + +/* Add any extra modes needed to represent the condition code. + + For the i386, we need separate modes when floating-point equality + comparisons are being done. */ + +#define EXTRA_CC_MODES CCFPEQmode + +/* Define the names for the modes specified above. */ +#define EXTRA_CC_NAMES "CCFPEQ" + +/* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE, + return the mode to be used for the comparison. + + For floating-point equality comparisons, CCFPEQmode should be used. + VOIDmode should be used in all other cases. */ + +#define SELECT_CC_MODE(OP,X,Y) \ + (GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT \ + && ((OP) == EQ || (OP) == NE) ? CCFPEQmode : VOIDmode) + +/* Define the information needed to generate branch and scc insns. This is + stored from the compare operation. Note that we can't use "rtx" here + since it hasn't been defined! */ + +extern struct rtx_def *(*i386_compare_gen)(), *(*i386_compare_gen_eq)(); + +/* Tell final.c how to eliminate redundant test instructions. */ + +/* Here we define machine-dependent flags and fields in cc_status + (see `conditions.h'). */ + +/* Set if the cc value is actually in the 80387, so a floating point + conditional branch must be output. */ +#define CC_IN_80387 04000 + +/* Set if the CC value was stored in a nonstandard way, so that + the state of equality is indicated by zero in the carry bit. */ +#define CC_Z_IN_NOT_C 010000 + +/* Store in cc_status the expressions + that the condition codes will describe + after execution of an instruction whose pattern is EXP. + Do not alter them if the instruction would not alter the cc's. */ + +#define NOTICE_UPDATE_CC(EXP, INSN) \ + notice_update_cc((EXP)) + +/* Output a signed jump insn. Use template NORMAL ordinarily, or + FLOAT following a floating point comparison. + Use NO_OV following an arithmetic insn that set the cc's + before a test insn that was deleted. + NO_OV may be zero, meaning final should reinsert the test insn + because the jump cannot be handled properly without it. */ + +#define OUTPUT_JUMP(NORMAL, FLOAT, NO_OV) \ +{ \ + if (cc_prev_status.flags & CC_IN_80387) \ + return FLOAT; \ + if (cc_prev_status.flags & CC_NO_OVERFLOW) \ + return NO_OV; \ + return NORMAL; \ +} + +/* Control the assembler format that we output, to the extent + this does not vary between assemblers. */ + +/* How to refer to registers in assembler output. + This sequence is indexed by compiler's hard-register-number (see above). */ + +/* In order to refer to the first 8 regs as 32 bit regs prefix an "e" + For non floating point regs, the following are the HImode names. + + For float regs, the stack top is sometimes referred to as "%st(0)" + instead of just "%st". PRINT_REG handles this with the "y" code. */ + +#define HI_REGISTER_NAMES \ +{"ax","dx","cx","bx","si","di","bp","sp", \ + "st","st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)","" } + +#define REGISTER_NAMES HI_REGISTER_NAMES + +/* Table of additional register names to use in user input. */ + +#define ADDITIONAL_REGISTER_NAMES \ +{ "eax", 0, "edx", 1, "ecx", 2, "ebx", 3, \ + "esi", 4, "edi", 5, "ebp", 6, "esp", 7, \ + "al", 0, "dl", 1, "cl", 2, "bl", 3, \ + "ah", 0, "dh", 1, "ch", 2, "bh", 3 } + +/* Note we are omitting these since currently I don't know how +to get gcc to use these, since they want the same but different +number as al, and ax. +*/ + +/* note the last four are not really qi_registers, but + the md will have to never output movb into one of them + only a movw . There is no movb into the last four regs */ + +#define QI_REGISTER_NAMES \ +{"al", "dl", "cl", "bl", "si", "di", "bp", "sp",} + +/* These parallel the array above, and can be used to access bits 8:15 + of regs 0 through 3. */ + +#define QI_HIGH_REGISTER_NAMES \ +{"ah", "dh", "ch", "bh", } + +/* How to renumber registers for dbx and gdb. */ + +/* {0,2,1,3,6,7,4,5,12,13,14,15,16,17} */ +#define DBX_REGISTER_NUMBER(n) \ +((n) == 0 ? 0 : \ + (n) == 1 ? 2 : \ + (n) == 2 ? 1 : \ + (n) == 3 ? 3 : \ + (n) == 4 ? 6 : \ + (n) == 5 ? 7 : \ + (n) == 6 ? 4 : \ + (n) == 7 ? 5 : \ + (n) + 4) + +/* This is how to output the definition of a user-level label named NAME, + such as the label on a static function or variable NAME. */ + +#define ASM_OUTPUT_LABEL(FILE,NAME) \ + (assemble_name (FILE, NAME), fputs (":\n", FILE)) + +/* This is how to output an assembler line defining a `double' constant. */ + +#define ASM_OUTPUT_DOUBLE(FILE,VALUE) \ +do { long l[2]; \ + REAL_VALUE_TO_TARGET_DOUBLE (VALUE, l); \ + if (sizeof (int) == sizeof (long)) \ + fprintf (FILE, "%s 0x%x,0x%x\n", ASM_LONG, l[0], l[1]); \ + else \ + fprintf (FILE, "%s 0x%lx,0x%lx\n", ASM_LONG, l[0], l[1]); \ + } while (0) + +/* This is how to output a `long double' extended real constant. */ + +#undef ASM_OUTPUT_LONG_DOUBLE +#define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE) \ +do { long l[3]; \ + REAL_VALUE_TO_TARGET_LONG_DOUBLE (VALUE, l); \ + if (sizeof (int) == sizeof (long)) \ + fprintf (FILE, "%s 0x%x,0x%x,0x%x\n", ASM_LONG, l[0], l[1], l[2]); \ + else \ + fprintf (FILE, "%s 0x%lx,0x%lx,0x%lx\n", ASM_LONG, l[0], l[1], l[2]); \ + } while (0) + +/* This is how to output an assembler line defining a `float' constant. */ + +#define ASM_OUTPUT_FLOAT(FILE,VALUE) \ +do { long l; \ + REAL_VALUE_TO_TARGET_SINGLE (VALUE, l); \ + if (sizeof (int) == sizeof (long)) \ + fprintf ((FILE), "%s 0x%x\n", ASM_LONG, l); \ + else \ + fprintf ((FILE), "%s 0x%lx\n", ASM_LONG, l); \ + } while (0) + +/* Store in OUTPUT a string (made with alloca) containing + an assembler-name for a local static variable named NAME. + LABELNO is an integer which is different for each call. */ + +#define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO) \ +( (OUTPUT) = (char *) alloca (strlen ((NAME)) + 10), \ + sprintf ((OUTPUT), "%s.%d", (NAME), (LABELNO))) + + + +/* This is how to output an assembler line defining an `int' constant. */ + +#define ASM_OUTPUT_INT(FILE,VALUE) \ +( fprintf (FILE, "%s ", ASM_LONG), \ + output_addr_const (FILE,(VALUE)), \ + putc('\n',FILE)) + +/* Likewise for `char' and `short' constants. */ +/* is this supposed to do align too?? */ + +#define ASM_OUTPUT_SHORT(FILE,VALUE) \ +( fprintf (FILE, "%s ", ASM_SHORT), \ + output_addr_const (FILE,(VALUE)), \ + putc('\n',FILE)) + +/* +#define ASM_OUTPUT_SHORT(FILE,VALUE) \ +( fprintf (FILE, "%s ", ASM_BYTE_OP), \ + output_addr_const (FILE,(VALUE)), \ + fputs (",", FILE), \ + output_addr_const (FILE,(VALUE)), \ + fputs (" >> 8\n",FILE)) +*/ + + +#define ASM_OUTPUT_CHAR(FILE,VALUE) \ +( fprintf (FILE, "%s ", ASM_BYTE_OP), \ + output_addr_const (FILE, (VALUE)), \ + putc ('\n', FILE)) + +/* This is how to output an assembler line for a numeric constant byte. */ + +#define ASM_OUTPUT_BYTE(FILE,VALUE) \ + fprintf ((FILE), "%s 0x%x\n", ASM_BYTE_OP, (VALUE)) + +/* This is how to output an insn to push a register on the stack. + It need not be very fast code. */ + +#define ASM_OUTPUT_REG_PUSH(FILE,REGNO) \ + fprintf (FILE, "\tpushl e%s\n", reg_names[REGNO]) + +/* This is how to output an insn to pop a register from the stack. + It need not be very fast code. */ + +#define ASM_OUTPUT_REG_POP(FILE,REGNO) \ + fprintf (FILE, "\tpopl e%s\n", reg_names[REGNO]) + +/* This is how to output an element of a case-vector that is absolute. + */ + +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \ + fprintf (FILE, "%s %s%d\n", ASM_LONG, LPREFIX, VALUE) + +/* This is how to output an element of a case-vector that is relative. + We don't use these on the 386 yet, because the ATT assembler can't do + forward reference the differences. + */ + +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.word %s%d-%s%d\n",LPREFIX, VALUE,LPREFIX, REL) + +/* Define the parentheses used to group arithmetic operations + in assembler code. */ + +#define ASM_OPEN_PAREN "" +#define ASM_CLOSE_PAREN "" + +/* Define results of standard character escape sequences. */ +#define TARGET_BELL 007 +#define TARGET_BS 010 +#define TARGET_TAB 011 +#define TARGET_NEWLINE 012 +#define TARGET_VT 013 +#define TARGET_FF 014 +#define TARGET_CR 015 + +/* Print operand X (an rtx) in assembler syntax to file FILE. + CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified. + The CODE z takes the size of operand from the following digit, and + outputs b,w,or l respectively. + + On the 80386, we use several such letters: + f -- float insn (print a CONST_DOUBLE as a float rather than in hex). + L,W,B,Q,S,T -- print the opcode suffix for specified size of operand. + R -- print the prefix for register names. + z -- print the opcode suffix for the size of the current operand. + * -- print a star (in certain assembler syntax) + w -- print the operand as if it's a "word" (HImode) even if it isn't. + b -- print the operand as if it's a byte (QImode) even if it isn't. + c -- don't print special prefixes before constant operands. */ + +#define PRINT_OPERAND_PUNCT_VALID_P(CODE) \ + ((CODE) == '*') + +/* Print the name of a register based on its machine mode and number. + If CODE is 'w', pretend the mode is HImode. + If CODE is 'b', pretend the mode is QImode. + If CODE is 'k', pretend the mode is SImode. + If CODE is 'h', pretend the reg is the `high' byte register. + If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op. */ + +extern char *hi_reg_name[]; +extern char *qi_reg_name[]; +extern char *qi_high_reg_name[]; + +#define PRINT_REG(X, CODE, FILE) \ + do { if (REGNO (X) == ARG_POINTER_REGNUM) \ + abort (); \ + fprintf (FILE, "%s", RP); \ + switch ((CODE == 'w' ? 2 \ + : CODE == 'b' ? 1 \ + : CODE == 'k' ? 4 \ + : CODE == 'y' ? 3 \ + : CODE == 'h' ? 0 \ + : GET_MODE_SIZE (GET_MODE (X)))) \ + { \ + case 3: \ + if (STACK_TOP_P (X)) \ + { \ + fputs ("st(0)", FILE); \ + break; \ + } \ + case 4: \ + case 8: \ + case 12: \ + if (! FP_REG_P (X)) fputs ("e", FILE); \ + case 2: \ + fputs (hi_reg_name[REGNO (X)], FILE); \ + break; \ + case 1: \ + fputs (qi_reg_name[REGNO (X)], FILE); \ + break; \ + case 0: \ + fputs (qi_high_reg_name[REGNO (X)], FILE); \ + break; \ + } \ + } while (0) + +#define PRINT_OPERAND(FILE, X, CODE) \ + print_operand (FILE, X, CODE) + +#define PRINT_OPERAND_ADDRESS(FILE, ADDR) \ + print_operand_address (FILE, ADDR) + +/* Print the name of a register for based on its machine mode and number. + This macro is used to print debugging output. + This macro is different from PRINT_REG in that it may be used in + programs that are not linked with aux-output.o. */ + +#define DEBUG_PRINT_REG(X, CODE, FILE) \ + do { static char *hi_name[] = HI_REGISTER_NAMES; \ + static char *qi_name[] = QI_REGISTER_NAMES; \ + fprintf (FILE, "%d %s", REGNO (X), RP); \ + if (REGNO (X) == ARG_POINTER_REGNUM) \ + { fputs ("argp", FILE); break; } \ + if (STACK_TOP_P (X)) \ + { fputs ("st(0)", FILE); break; } \ + if (FP_REG_P (X)) \ + { fputs (hi_name[REGNO(X)], FILE); break; } \ + switch (GET_MODE_SIZE (GET_MODE (X))) \ + { \ + default: \ + fputs ("e", FILE); \ + case 2: \ + fputs (hi_name[REGNO (X)], FILE); \ + break; \ + case 1: \ + fputs (qi_name[REGNO (X)], FILE); \ + break; \ + } \ + } while (0) + +/* Output the prefix for an immediate operand, or for an offset operand. */ +#define PRINT_IMMED_PREFIX(FILE) fputs (IP, (FILE)) +#define PRINT_OFFSET_PREFIX(FILE) fputs (IP, (FILE)) + +/* Routines in libgcc that return floats must return them in an fp reg, + just as other functions do which return such values. + These macros make that happen. */ + +#define FLOAT_VALUE_TYPE float +#define INTIFY(FLOATVAL) FLOATVAL + +/* Nonzero if INSN magically clobbers register REGNO. */ + +/* #define INSN_CLOBBERS_REGNO_P(INSN, REGNO) \ + (FP_REGNO_P (REGNO) \ + && (GET_CODE (INSN) == JUMP_INSN || GET_CODE (INSN) == BARRIER)) +*/ + +/* a letter which is not needed by the normal asm syntax, which + we can use for operand syntax in the extended asm */ + +#define ASM_OPERAND_LETTER '#' + +#define RET return "" +#define AT_SP(mode) (gen_rtx (MEM, (mode), stack_pointer_rtx)) + +/* Functions in i386.c */ +extern void override_options (); +extern void order_regs_for_local_alloc (); +extern int i386_valid_decl_attribute_p (); +extern int i386_valid_type_attribute_p (); +extern int i386_return_pops_args (); +extern int i386_comp_type_attributes (); +extern void init_cumulative_args (); +extern void function_arg_advance (); +extern struct rtx_def *function_arg (); +extern int function_arg_partial_nregs (); +extern void output_op_from_reg (); +extern void output_to_reg (); +extern char *singlemove_string (); +extern char *output_move_double (); +extern char *output_move_memory (); +extern char *output_move_pushmem (); +extern int standard_80387_constant_p (); +extern char *output_move_const_single (); +extern int symbolic_operand (); +extern int call_insn_operand (); +extern int expander_call_insn_operand (); +extern int symbolic_reference_mentioned_p (); +extern void emit_pic_move (); +extern void function_prologue (); +extern int simple_386_epilogue (); +extern void function_epilogue (); +extern int legitimate_address_p (); +extern struct rtx_def *legitimize_pic_address (); +extern struct rtx_def *legitimize_address (); +extern void print_operand (); +extern void print_operand_address (); +extern void notice_update_cc (); +extern void split_di (); +extern int binary_387_op (); +extern int shift_op (); +extern int VOIDmode_compare_op (); +extern char *output_387_binary_op (); +extern char *output_fix_trunc (); +extern char *output_float_compare (); +extern char *output_fp_cc0_set (); +extern void save_386_machine_status (); +extern void restore_386_machine_status (); +extern void clear_386_stack_locals (); +extern struct rtx_def *assign_386_stack_local (); + +/* Variables in i386.c */ +extern char *i386_reg_alloc_order; /* register allocation order */ +extern char *i386_regparm_string; /* # registers to use to pass args */ +extern char *i386_align_loops_string; /* power of two alignment for loops */ +extern char *i386_align_jumps_string; /* power of two alignment for non-loop jumps */ +extern char *i386_align_funcs_string; /* power of two alignment for functions */ +extern int i386_regparm; /* i386_regparm_string as a number */ +extern int i386_align_loops; /* power of two alignment for loops */ +extern int i386_align_jumps; /* power of two alignment for non-loop jumps */ +extern int i386_align_funcs; /* power of two alignment for functions */ +extern char *hi_reg_name[]; /* names for 16 bit regs */ +extern char *qi_reg_name[]; /* names for 8 bit regs (low) */ +extern char *qi_high_reg_name[]; /* names for 8 bit regs (high) */ +extern enum reg_class regclass_map[]; /* smalled class containing REGNO */ +extern struct rtx_def *i386_compare_op0; /* operand 0 for comparisons */ +extern struct rtx_def *i386_compare_op1; /* operand 1 for comparisons */ + +/* External variables used */ +extern int optimize; /* optimization level */ +extern int obey_regdecls; /* TRUE if stupid register allocation */ + +/* External functions used */ +extern struct rtx_def *force_operand (); + +/* +Local variables: +version-control: t +End: +*/ diff --git a/contrib/gcc/config/i386/i386.md b/contrib/gcc/config/i386/i386.md new file mode 100644 index 00000000000..ff0119631cb --- /dev/null +++ b/contrib/gcc/config/i386/i386.md @@ -0,0 +1,5775 @@ +;; GCC machine description for Intel X86. +;; Copyright (C) 1988, 1994, 1995 Free Software Foundation, Inc. +;; Mostly by William Schelter. + +;; This file is part of GNU CC. + +;; GNU CC is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; GNU CC is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU CC; see the file COPYING. If not, write to +;; the Free Software Foundation, 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + + +;; The original PO technology requires these to be ordered by speed, +;; so that assigner will pick the fastest. + +;; See file "rtl.def" for documentation on define_insn, match_*, et. al. + +;; Macro #define NOTICE_UPDATE_CC in file i386.h handles condition code +;; updates for most instructions. + +;; Macro REG_CLASS_FROM_LETTER in file i386.h defines the register +;; constraint letters. + +;; the special asm out single letter directives following a '%' are: +;; 'z' mov%z1 would be movl, movw, or movb depending on the mode of +;; operands[1]. +;; 'L' Print the opcode suffix for a 32-bit integer opcode. +;; 'W' Print the opcode suffix for a 16-bit integer opcode. +;; 'B' Print the opcode suffix for an 8-bit integer opcode. +;; 'S' Print the opcode suffix for a 32-bit float opcode. +;; 'Q' Print the opcode suffix for a 64-bit float opcode. +;; 'T' Print the opcode suffix for an 80-bit extended real XFmode float opcode. +;; 'J' Print the appropriate jump operand. + +;; 'b' Print the QImode name of the register for the indicated operand. +;; %b0 would print %al if operands[0] is reg 0. +;; 'w' Likewise, print the HImode name of the register. +;; 'k' Likewise, print the SImode name of the register. +;; 'h' Print the QImode name for a "high" register, either ah, bh, ch or dh. +;; 'y' Print "st(0)" instead of "st" as a register. + +;; UNSPEC usage: +;; 0 This is a `scas' operation. The mode of the UNSPEC is always SImode. +;; operand 0 is the memory address to scan. +;; operand 1 is a register containing the value to scan for. The mode +;; of the scas opcode will be the same as the mode of this operand. +;; operand 2 is the known alignment of operand 0. +;; 1 This is a `sin' operation. The mode of the UNSPEC is MODE_FLOAT. +;; operand 0 is the argument for `sin'. +;; 2 This is a `cos' operation. The mode of the UNSPEC is MODE_FLOAT. +;; operand 0 is the argument for `cos'. + +;; "movl MEM,REG / testl REG,REG" is faster on a 486 than "cmpl $0,MEM". +;; But restricting MEM here would mean that gcc could not remove a redundant +;; test in cases like "incl MEM / je TARGET". +;; +;; We don't want to allow a constant operand for test insns because +;; (set (cc0) (const_int foo)) has no mode information. Such insns will +;; be folded while optimizing anyway. + +;; All test insns have expanders that save the operands away without +;; actually generating RTL. The bCOND or sCOND (emitted immediately +;; after the tstM or cmp) will actually emit the tstM or cmpM. + +(define_insn "tstsi_1" + [(set (cc0) + (match_operand:SI 0 "nonimmediate_operand" "rm"))] + "" + "* +{ + if (REG_P (operands[0])) + return AS2 (test%L0,%0,%0); + + operands[1] = const0_rtx; + return AS2 (cmp%L0,%1,%0); +}") + +(define_expand "tstsi" + [(set (cc0) + (match_operand:SI 0 "nonimmediate_operand" ""))] + "" + " +{ + i386_compare_gen = gen_tstsi_1; + i386_compare_op0 = operands[0]; + DONE; +}") + +(define_insn "tsthi_1" + [(set (cc0) + (match_operand:HI 0 "nonimmediate_operand" "rm"))] + "" + "* +{ + if (REG_P (operands[0])) + return AS2 (test%W0,%0,%0); + + operands[1] = const0_rtx; + return AS2 (cmp%W0,%1,%0); +}") + +(define_expand "tsthi" + [(set (cc0) + (match_operand:HI 0 "nonimmediate_operand" ""))] + "" + " +{ + i386_compare_gen = gen_tsthi_1; + i386_compare_op0 = operands[0]; + DONE; +}") + +(define_insn "tstqi_1" + [(set (cc0) + (match_operand:QI 0 "nonimmediate_operand" "qm"))] + "" + "* +{ + if (REG_P (operands[0])) + return AS2 (test%B0,%0,%0); + + operands[1] = const0_rtx; + return AS2 (cmp%B0,%1,%0); +}") + +(define_expand "tstqi" + [(set (cc0) + (match_operand:QI 0 "nonimmediate_operand" ""))] + "" + " +{ + i386_compare_gen = gen_tstqi_1; + i386_compare_op0 = operands[0]; + DONE; +}") + +(define_insn "tstsf_cc" + [(set (cc0) + (match_operand:SF 0 "register_operand" "f")) + (clobber (match_scratch:HI 1 "=a"))] + "TARGET_80387 && ! TARGET_IEEE_FP" + "* +{ + if (! STACK_TOP_P (operands[0])) + abort (); + + output_asm_insn (\"ftst\", operands); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp,%y0), operands); + + return output_fp_cc0_set (insn); +}") + +;; Don't generate tstsf if generating IEEE code, since the `ftst' opcode +;; isn't IEEE compliant. + +(define_expand "tstsf" + [(parallel [(set (cc0) + (match_operand:SF 0 "register_operand" "")) + (clobber (match_scratch:HI 1 ""))])] + "TARGET_80387 && ! TARGET_IEEE_FP" + " +{ + i386_compare_gen = gen_tstsf_cc; + i386_compare_op0 = operands[0]; + DONE; +}") + +(define_insn "tstdf_cc" + [(set (cc0) + (match_operand:DF 0 "register_operand" "f")) + (clobber (match_scratch:HI 1 "=a"))] + "TARGET_80387 && ! TARGET_IEEE_FP" + "* +{ + if (! STACK_TOP_P (operands[0])) + abort (); + + output_asm_insn (\"ftst\", operands); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp,%y0), operands); + + return output_fp_cc0_set (insn); +}") + +;; Don't generate tstdf if generating IEEE code, since the `ftst' opcode +;; isn't IEEE compliant. + +(define_expand "tstdf" + [(parallel [(set (cc0) + (match_operand:DF 0 "register_operand" "")) + (clobber (match_scratch:HI 1 ""))])] + "TARGET_80387 && ! TARGET_IEEE_FP" + " +{ + i386_compare_gen = gen_tstdf_cc; + i386_compare_op0 = operands[0]; + DONE; +}") + +(define_insn "tstxf_cc" + [(set (cc0) + (match_operand:XF 0 "register_operand" "f")) + (clobber (match_scratch:HI 1 "=a"))] + "TARGET_80387 && ! TARGET_IEEE_FP" + "* +{ + if (! STACK_TOP_P (operands[0])) + abort (); + + output_asm_insn (\"ftst\", operands); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp,%y0), operands); + + return output_fp_cc0_set (insn); +}") + +;; Don't generate tstdf if generating IEEE code, since the `ftst' opcode +;; isn't IEEE compliant. + +(define_expand "tstxf" + [(parallel [(set (cc0) + (match_operand:XF 0 "register_operand" "")) + (clobber (match_scratch:HI 1 ""))])] + "TARGET_80387 && ! TARGET_IEEE_FP" + " +{ + i386_compare_gen = gen_tstxf_cc; + i386_compare_op0 = operands[0]; + DONE; +}") + +;;- compare instructions. See comments above tstM patterns about +;; expansion of these insns. + +(define_insn "cmpsi_1" + [(set (cc0) + (compare (match_operand:SI 0 "nonimmediate_operand" "mr,r") + (match_operand:SI 1 "general_operand" "ri,mr")))] + "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM" + "* +{ + if (CONSTANT_P (operands[0]) || GET_CODE (operands[1]) == MEM) + { + cc_status.flags |= CC_REVERSED; + return AS2 (cmp%L0,%0,%1); + } + return AS2 (cmp%L0,%1,%0); +}") + +(define_expand "cmpsi" + [(set (cc0) + (compare (match_operand:SI 0 "nonimmediate_operand" "") + (match_operand:SI 1 "general_operand" "")))] + "" + " +{ + if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM) + operands[0] = force_reg (SImode, operands[0]); + + i386_compare_gen = gen_cmpsi_1; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +(define_insn "cmphi_1" + [(set (cc0) + (compare (match_operand:HI 0 "nonimmediate_operand" "mr,r") + (match_operand:HI 1 "general_operand" "ri,mr")))] + "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM" + "* +{ + if (CONSTANT_P (operands[0]) || GET_CODE (operands[1]) == MEM) + { + cc_status.flags |= CC_REVERSED; + return AS2 (cmp%W0,%0,%1); + } + return AS2 (cmp%W0,%1,%0); +}") + +(define_expand "cmphi" + [(set (cc0) + (compare (match_operand:HI 0 "nonimmediate_operand" "") + (match_operand:HI 1 "general_operand" "")))] + "" + " +{ + if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM) + operands[0] = force_reg (HImode, operands[0]); + + i386_compare_gen = gen_cmphi_1; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +(define_insn "cmpqi_1" + [(set (cc0) + (compare (match_operand:QI 0 "nonimmediate_operand" "q,mq") + (match_operand:QI 1 "general_operand" "qm,nq")))] + "GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM" + "* +{ + if (CONSTANT_P (operands[0]) || GET_CODE (operands[1]) == MEM) + { + cc_status.flags |= CC_REVERSED; + return AS2 (cmp%B0,%0,%1); + } + return AS2 (cmp%B0,%1,%0); +}") + +(define_expand "cmpqi" + [(set (cc0) + (compare (match_operand:QI 0 "nonimmediate_operand" "") + (match_operand:QI 1 "general_operand" "")))] + "" + " +{ + if (GET_CODE (operands[0]) == MEM && GET_CODE (operands[1]) == MEM) + operands[0] = force_reg (QImode, operands[0]); + + i386_compare_gen = gen_cmpqi_1; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +;; These implement float point compares. For each of DFmode and +;; SFmode, there is the normal insn, and an insn where the second operand +;; is converted to the desired mode. + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:XF 0 "nonimmediate_operand" "f") + (match_operand:XF 1 "nonimmediate_operand" "f")])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387 + && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:XF 0 "register_operand" "f") + (float:XF + (match_operand:SI 1 "nonimmediate_operand" "rm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(float:XF + (match_operand:SI 0 "nonimmediate_operand" "rm")) + (match_operand:XF 1 "register_operand" "f")])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:XF 0 "register_operand" "f") + (float_extend:XF + (match_operand:DF 1 "nonimmediate_operand" "fm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:XF 0 "register_operand" "f") + (float_extend:XF + (match_operand:SF 1 "nonimmediate_operand" "fm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (compare:CCFPEQ (match_operand:XF 0 "register_operand" "f") + (match_operand:XF 1 "register_operand" "f"))) + (clobber (match_scratch:HI 2 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:DF 0 "nonimmediate_operand" "f,fm") + (match_operand:DF 1 "nonimmediate_operand" "fm,f")])) + (clobber (match_scratch:HI 3 "=a,a"))] + "TARGET_80387 + && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:DF 0 "register_operand" "f") + (float:DF + (match_operand:SI 1 "nonimmediate_operand" "rm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(float:DF + (match_operand:SI 0 "nonimmediate_operand" "rm")) + (match_operand:DF 1 "register_operand" "f")])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:DF 0 "register_operand" "f") + (float_extend:DF + (match_operand:SF 1 "nonimmediate_operand" "fm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(float_extend:DF + (match_operand:SF 0 "nonimmediate_operand" "fm")) + (match_operand:DF 1 "register_operand" "f")])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (compare:CCFPEQ (match_operand:DF 0 "register_operand" "f") + (match_operand:DF 1 "register_operand" "f"))) + (clobber (match_scratch:HI 2 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +;; These two insns will never be generated by combine due to the mode of +;; the COMPARE. +;(define_insn "" +; [(set (cc0) +; (compare:CCFPEQ (match_operand:DF 0 "register_operand" "f") +; (float_extend:DF +; (match_operand:SF 1 "register_operand" "f")))) +; (clobber (match_scratch:HI 2 "=a"))] +; "TARGET_80387" +; "* return output_float_compare (insn, operands);") +; +;(define_insn "" +; [(set (cc0) +; (compare:CCFPEQ (float_extend:DF +; (match_operand:SF 0 "register_operand" "f")) +; (match_operand:DF 1 "register_operand" "f"))) +; (clobber (match_scratch:HI 2 "=a"))] +; "TARGET_80387" +; "* return output_float_compare (insn, operands);") + +(define_insn "cmpsf_cc_1" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:SF 0 "nonimmediate_operand" "f,fm") + (match_operand:SF 1 "nonimmediate_operand" "fm,f")])) + (clobber (match_scratch:HI 3 "=a,a"))] + "TARGET_80387 + && (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM)" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(match_operand:SF 0 "register_operand" "f") + (float:SF + (match_operand:SI 1 "nonimmediate_operand" "rm"))])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (match_operator 2 "VOIDmode_compare_op" + [(float:SF + (match_operand:SI 0 "nonimmediate_operand" "rm")) + (match_operand:SF 1 "register_operand" "f")])) + (clobber (match_scratch:HI 3 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_insn "" + [(set (cc0) + (compare:CCFPEQ (match_operand:SF 0 "register_operand" "f") + (match_operand:SF 1 "register_operand" "f"))) + (clobber (match_scratch:HI 2 "=a"))] + "TARGET_80387" + "* return output_float_compare (insn, operands);") + +(define_expand "cmpxf" + [(set (cc0) + (compare (match_operand:XF 0 "register_operand" "") + (match_operand:XF 1 "nonimmediate_operand" "")))] + "TARGET_80387" + " +{ + i386_compare_gen = gen_cmpxf_cc; + i386_compare_gen_eq = gen_cmpxf_ccfpeq; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +(define_expand "cmpdf" + [(set (cc0) + (compare (match_operand:DF 0 "register_operand" "") + (match_operand:DF 1 "nonimmediate_operand" "")))] + "TARGET_80387" + " +{ + i386_compare_gen = gen_cmpdf_cc; + i386_compare_gen_eq = gen_cmpdf_ccfpeq; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +(define_expand "cmpsf" + [(set (cc0) + (compare (match_operand:SF 0 "register_operand" "") + (match_operand:SF 1 "nonimmediate_operand" "")))] + "TARGET_80387" + " +{ + i386_compare_gen = gen_cmpsf_cc; + i386_compare_gen_eq = gen_cmpsf_ccfpeq; + i386_compare_op0 = operands[0]; + i386_compare_op1 = operands[1]; + DONE; +}") + +(define_expand "cmpxf_cc" + [(parallel [(set (cc0) + (compare (match_operand:XF 0 "register_operand" "") + (match_operand:XF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + "") + +(define_expand "cmpxf_ccfpeq" + [(parallel [(set (cc0) + (compare:CCFPEQ (match_operand:XF 0 "register_operand" "") + (match_operand:XF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + " +{ + if (! register_operand (operands[1], XFmode)) + operands[1] = copy_to_mode_reg (XFmode, operands[1]); +}") + +(define_expand "cmpdf_cc" + [(parallel [(set (cc0) + (compare (match_operand:DF 0 "register_operand" "") + (match_operand:DF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + "") + +(define_expand "cmpdf_ccfpeq" + [(parallel [(set (cc0) + (compare:CCFPEQ (match_operand:DF 0 "register_operand" "") + (match_operand:DF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + " +{ + if (! register_operand (operands[1], DFmode)) + operands[1] = copy_to_mode_reg (DFmode, operands[1]); +}") + +(define_expand "cmpsf_cc" + [(parallel [(set (cc0) + (compare (match_operand:SF 0 "register_operand" "") + (match_operand:SF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + "") + +(define_expand "cmpsf_ccfpeq" + [(parallel [(set (cc0) + (compare:CCFPEQ (match_operand:SF 0 "register_operand" "") + (match_operand:SF 1 "register_operand" ""))) + (clobber (match_scratch:HI 2 ""))])] + "TARGET_80387" + " +{ + if (! register_operand (operands[1], SFmode)) + operands[1] = copy_to_mode_reg (SFmode, operands[1]); +}") + +;; logical compare + +(define_insn "" + [(set (cc0) + (and:SI (match_operand:SI 0 "general_operand" "%ro") + (match_operand:SI 1 "general_operand" "ri")))] + "" + "* +{ + /* For small integers, we may actually use testb. */ + if (GET_CODE (operands[1]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])) + && (! REG_P (operands[0]) || QI_REG_P (operands[0]))) + { + /* We may set the sign bit spuriously. */ + + if ((INTVAL (operands[1]) & ~0xff) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + return AS2 (test%B0,%1,%b0); + } + + if ((INTVAL (operands[1]) & ~0xff00) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (INTVAL (operands[1]) >> 8); + + if (QI_REG_P (operands[0])) + return AS2 (test%B0,%1,%h0); + else + { + operands[0] = adj_offsettable_operand (operands[0], 1); + return AS2 (test%B0,%1,%b0); + } + } + + if (GET_CODE (operands[0]) == MEM + && (INTVAL (operands[1]) & ~0xff0000) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (INTVAL (operands[1]) >> 16); + operands[0] = adj_offsettable_operand (operands[0], 2); + return AS2 (test%B0,%1,%b0); + } + + if (GET_CODE (operands[0]) == MEM + && (INTVAL (operands[1]) & ~0xff000000) == 0) + { + operands[1] = GEN_INT ((INTVAL (operands[1]) >> 24) & 0xff); + operands[0] = adj_offsettable_operand (operands[0], 3); + return AS2 (test%B0,%1,%b0); + } + } + + if (CONSTANT_P (operands[1]) || GET_CODE (operands[0]) == MEM) + return AS2 (test%L0,%1,%0); + + return AS2 (test%L1,%0,%1); +}") + +(define_insn "" + [(set (cc0) + (and:HI (match_operand:HI 0 "general_operand" "%ro") + (match_operand:HI 1 "general_operand" "ri")))] + "" + "* +{ + if (GET_CODE (operands[1]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])) + && (! REG_P (operands[0]) || QI_REG_P (operands[0]))) + { + if ((INTVAL (operands[1]) & 0xff00) == 0) + { + /* ??? This might not be necessary. */ + if (INTVAL (operands[1]) & 0xffff0000) + operands[1] = GEN_INT (INTVAL (operands[1]) & 0xff); + + /* We may set the sign bit spuriously. */ + cc_status.flags |= CC_NOT_NEGATIVE; + return AS2 (test%B0,%1,%b0); + } + + if ((INTVAL (operands[1]) & 0xff) == 0) + { + operands[1] = GEN_INT ((INTVAL (operands[1]) >> 8) & 0xff); + + if (QI_REG_P (operands[0])) + return AS2 (test%B0,%1,%h0); + else + { + operands[0] = adj_offsettable_operand (operands[0], 1); + return AS2 (test%B0,%1,%b0); + } + } + } + + if (CONSTANT_P (operands[1]) || GET_CODE (operands[0]) == MEM) + return AS2 (test%W0,%1,%0); + + return AS2 (test%W1,%0,%1); +}") + +(define_insn "" + [(set (cc0) + (and:QI (match_operand:QI 0 "general_operand" "%qm") + (match_operand:QI 1 "general_operand" "qi")))] + "" + "* +{ + if (CONSTANT_P (operands[1]) || GET_CODE (operands[0]) == MEM) + return AS2 (test%B0,%1,%0); + + return AS2 (test%B1,%0,%1); +}") + +;; move instructions. +;; There is one for each machine mode, +;; and each is preceded by a corresponding push-insn pattern +;; (since pushes are not general_operands on the 386). + +(define_insn "" + [(set (match_operand:SI 0 "push_operand" "=<") + (match_operand:SI 1 "general_operand" "g"))] + "TARGET_386" + "push%L0 %1") + +;; On a 486, it is faster to move MEM to a REG and then push, rather than +;; push MEM directly. + +(define_insn "" + [(set (match_operand:SI 0 "push_operand" "=<") + (match_operand:SI 1 "nonmemory_operand" "ri"))] + "!TARGET_386 && TARGET_MOVE" + "push%L0 %1") + +(define_insn "" + [(set (match_operand:SI 0 "push_operand" "=<") + (match_operand:SI 1 "general_operand" "ri"))] + "!TARGET_386 && !TARGET_MOVE" + "push%L0 %1") + +;; General case of fullword move. + +;; If generating PIC code and operands[1] is a symbolic CONST, emit a +;; move to get the address of the symbolic object from the GOT. + +(define_expand "movsi" + [(set (match_operand:SI 0 "general_operand" "") + (match_operand:SI 1 "general_operand" ""))] + "" + " +{ + extern int flag_pic; + + if (flag_pic && SYMBOLIC_CONST (operands[1])) + emit_pic_move (operands, SImode); + + /* Don't generate memory->memory moves, go through a register */ + else if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && GET_CODE (operands[1]) == MEM) + { + operands[1] = force_reg (SImode, operands[1]); + } +}") + +;; On i486, incl reg is faster than movl $1,reg. + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=g,r") + (match_operand:SI 1 "general_operand" "ri,m"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + rtx link; + if (operands[1] == const0_rtx && REG_P (operands[0])) + return AS2 (xor%L0,%0,%0); + + if (operands[1] == const1_rtx + && (link = find_reg_note (insn, REG_WAS_0, 0)) + /* Make sure the insn that stored the 0 is still present. */ + && ! INSN_DELETED_P (XEXP (link, 0)) + && GET_CODE (XEXP (link, 0)) != NOTE + /* Make sure cross jumping didn't happen here. */ + && no_labels_between_p (XEXP (link, 0), insn) + /* Make sure the reg hasn't been clobbered. */ + && ! reg_set_between_p (operands[0], XEXP (link, 0), insn)) + /* Fastest way to change a 0 to a 1. */ + return AS1 (inc%L0,%0); + + if (flag_pic && SYMBOLIC_CONST (operands[1])) + return AS2 (lea%L0,%a1,%0); + + return AS2 (mov%L0,%1,%0); +}") + +(define_insn "" + [(set (match_operand:HI 0 "push_operand" "=<") + (match_operand:HI 1 "general_operand" "g"))] + "TARGET_386" + "push%W0 %1") + +(define_insn "" + [(set (match_operand:HI 0 "push_operand" "=<") + (match_operand:HI 1 "nonmemory_operand" "ri"))] + "!TARGET_386 && TARGET_MOVE" + "push%W0 %1") + +(define_insn "" + [(set (match_operand:HI 0 "push_operand" "=<") + (match_operand:HI 1 "general_operand" "ri"))] + "!TARGET_386 && !TARGET_MOVE" + "push%W0 %1") + +;; On i486, an incl and movl are both faster than incw and movw. + +(define_expand "movhi" + [(set (match_operand:HI 0 "general_operand" "") + (match_operand:HI 1 "general_operand" ""))] + "" + " +{ + /* Don't generate memory->memory moves, go through a register */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && GET_CODE (operands[1]) == MEM) + { + operands[1] = force_reg (HImode, operands[1]); + } +}") + +(define_insn "" + [(set (match_operand:HI 0 "general_operand" "=g,r") + (match_operand:HI 1 "general_operand" "ri,m"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + rtx link; + if (REG_P (operands[0]) && operands[1] == const0_rtx) + return AS2 (xor%L0,%k0,%k0); + + if (REG_P (operands[0]) && operands[1] == const1_rtx + && (link = find_reg_note (insn, REG_WAS_0, 0)) + /* Make sure the insn that stored the 0 is still present. */ + && ! INSN_DELETED_P (XEXP (link, 0)) + && GET_CODE (XEXP (link, 0)) != NOTE + /* Make sure cross jumping didn't happen here. */ + && no_labels_between_p (XEXP (link, 0), insn) + /* Make sure the reg hasn't been clobbered. */ + && ! reg_set_between_p (operands[0], XEXP (link, 0), insn)) + /* Fastest way to change a 0 to a 1. */ + return AS1 (inc%L0,%k0); + + if (REG_P (operands[0])) + { + if (REG_P (operands[1])) + return AS2 (mov%L0,%k1,%k0); + else if (CONSTANT_P (operands[1])) + return AS2 (mov%L0,%1,%k0); + } + + return AS2 (mov%W0,%1,%0); +}") + +(define_expand "movstricthi" + [(set (strict_low_part (match_operand:HI 0 "general_operand" "")) + (match_operand:HI 1 "general_operand" ""))] + "" + " +{ + /* Don't generate memory->memory moves, go through a register */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && GET_CODE (operands[1]) == MEM) + { + operands[1] = force_reg (HImode, operands[1]); + } +}") + +(define_insn "" + [(set (strict_low_part (match_operand:HI 0 "general_operand" "+g,r")) + (match_operand:HI 1 "general_operand" "ri,m"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + rtx link; + if (operands[1] == const0_rtx && REG_P (operands[0])) + return AS2 (xor%W0,%0,%0); + + if (operands[1] == const1_rtx + && (link = find_reg_note (insn, REG_WAS_0, 0)) + /* Make sure the insn that stored the 0 is still present. */ + && ! INSN_DELETED_P (XEXP (link, 0)) + && GET_CODE (XEXP (link, 0)) != NOTE + /* Make sure cross jumping didn't happen here. */ + && no_labels_between_p (XEXP (link, 0), insn) + /* Make sure the reg hasn't been clobbered. */ + && ! reg_set_between_p (operands[0], XEXP (link, 0), insn)) + /* Fastest way to change a 0 to a 1. */ + return AS1 (inc%W0,%0); + + return AS2 (mov%W0,%1,%0); +}") + +;; emit_push_insn when it calls move_by_pieces +;; requires an insn to "push a byte". +;; But actually we use pushw, which has the effect of rounding +;; the amount pushed up to a halfword. +(define_insn "" + [(set (match_operand:QI 0 "push_operand" "=<") + (match_operand:QI 1 "immediate_operand" "n"))] + "" + "* return AS1 (push%W0,%1);") + +(define_insn "" + [(set (match_operand:QI 0 "push_operand" "=<") + (match_operand:QI 1 "nonimmediate_operand" "q"))] + "!TARGET_MOVE" + "* +{ + operands[1] = gen_rtx (REG, HImode, REGNO (operands[1])); + return AS1 (push%W0,%1); +}") + +(define_insn "" + [(set (match_operand:QI 0 "push_operand" "=<") + (match_operand:QI 1 "register_operand" "q"))] + "TARGET_MOVE" + "* +{ + operands[1] = gen_rtx (REG, HImode, REGNO (operands[1])); + return AS1 (push%W0,%1); +}") + +;; On i486, incb reg is faster than movb $1,reg. + +;; ??? Do a recognizer for zero_extract that looks just like this, but reads +;; or writes %ah, %bh, %ch, %dh. + +(define_expand "movqi" + [(set (match_operand:QI 0 "general_operand" "") + (match_operand:QI 1 "general_operand" ""))] + "" + " +{ + /* Don't generate memory->memory moves, go through a register */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && GET_CODE (operands[1]) == MEM) + { + operands[1] = force_reg (QImode, operands[1]); + } +}") + +(define_insn "" + [(set (match_operand:QI 0 "general_operand" "=q,*r,qm") + (match_operand:QI 1 "general_operand" "*g,q,qn"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + rtx link; + if (operands[1] == const0_rtx && REG_P (operands[0])) + return AS2 (xor%B0,%0,%0); + + if (operands[1] == const1_rtx + && (link = find_reg_note (insn, REG_WAS_0, 0)) + /* Make sure the insn that stored the 0 is still present. */ + && ! INSN_DELETED_P (XEXP (link, 0)) + && GET_CODE (XEXP (link, 0)) != NOTE + /* Make sure cross jumping didn't happen here. */ + && no_labels_between_p (XEXP (link, 0), insn) + /* Make sure the reg hasn't been clobbered. */ + && ! reg_set_between_p (operands[0], XEXP (link, 0), insn)) + /* Fastest way to change a 0 to a 1. */ + return AS1 (inc%B0,%0); + + /* If mov%B0 isn't allowed for one of these regs, use mov%L0. */ + if (NON_QI_REG_P (operands[0]) || NON_QI_REG_P (operands[1])) + return (AS2 (mov%L0,%k1,%k0)); + + return (AS2 (mov%B0,%1,%0)); +}") + +;; If it becomes necessary to support movstrictqi into %esi or %edi, +;; use the insn sequence: +;; +;; shrdl $8,srcreg,dstreg +;; rorl $24,dstreg +;; +;; If operands[1] is a constant, then an andl/orl sequence would be +;; faster. + +(define_expand "movstrictqi" + [(set (strict_low_part (match_operand:QI 0 "general_operand" "")) + (match_operand:QI 1 "general_operand" ""))] + "" + " +{ + /* Don't generate memory->memory moves, go through a register */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && GET_CODE (operands[1]) == MEM) + { + operands[1] = force_reg (QImode, operands[1]); + } +}") + +(define_insn "" + [(set (strict_low_part (match_operand:QI 0 "general_operand" "+qm,q")) + (match_operand:QI 1 "general_operand" "*qn,m"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + rtx link; + if (operands[1] == const0_rtx && REG_P (operands[0])) + return AS2 (xor%B0,%0,%0); + + if (operands[1] == const1_rtx + && (link = find_reg_note (insn, REG_WAS_0, 0)) + /* Make sure the insn that stored the 0 is still present. */ + && ! INSN_DELETED_P (XEXP (link, 0)) + && GET_CODE (XEXP (link, 0)) != NOTE + /* Make sure cross jumping didn't happen here. */ + && no_labels_between_p (XEXP (link, 0), insn) + /* Make sure the reg hasn't been clobbered. */ + && ! reg_set_between_p (operands[0], XEXP (link, 0), insn)) + /* Fastest way to change a 0 to a 1. */ + return AS1 (inc%B0,%0); + + /* If mov%B0 isn't allowed for one of these regs, use mov%L0. */ + if (NON_QI_REG_P (operands[0]) || NON_QI_REG_P (operands[1])) + { + abort (); + return (AS2 (mov%L0,%k1,%k0)); + } + + return AS2 (mov%B0,%1,%0); +}") + +(define_expand "movsf" + [(set (match_operand:SF 0 "general_operand" "") + (match_operand:SF 1 "general_operand" ""))] + "" + " +{ + /* Special case memory->memory moves and pushes */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && (GET_CODE (operands[1]) == MEM || push_operand (operands[0], SFmode))) + { + rtx (*genfunc) PROTO((rtx, rtx)) = (push_operand (operands[0], SFmode)) + ? gen_movsf_push + : gen_movsf_mem; + + emit_insn ((*genfunc) (operands[0], operands[1])); + DONE; + } + + /* If we are loading a floating point constant that isn't 0 or 1 into a register, + indicate we need the pic register loaded. This could be optimized into stores + of constants if the target eventually moves to memory, but better safe than + sorry. */ + if (flag_pic + && GET_CODE (operands[0]) != MEM + && GET_CODE (operands[1]) == CONST_DOUBLE + && !standard_80387_constant_p (operands[1])) + { + current_function_uses_pic_offset_table = 1; + } +}") + +(define_insn "movsf_push_nomove" + [(set (match_operand:SF 0 "push_operand" "=<,<") + (match_operand:SF 1 "general_operand" "gF,f"))] + "!TARGET_MOVE" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + if (! STACK_TOP_P (operands[1])) + abort (); + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (4); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp%S0,%0), xops); + else + output_asm_insn (AS1 (fst%S0,%0), xops); + RET; + } + return AS1 (push%L1,%1); +}") + +(define_insn "movsf_push" + [(set (match_operand:SF 0 "push_operand" "=<,<,<,<") + (match_operand:SF 1 "general_operand" "rF,f,m,m")) + (clobber (match_scratch:SI 2 "=X,X,r,X"))] + "" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + if (! STACK_TOP_P (operands[1])) + abort (); + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (4); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp%S0,%0), xops); + else + output_asm_insn (AS1 (fst%S0,%0), xops); + RET; + } + + else if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != REG) + return AS1 (push%L1,%1); + + else + { + output_asm_insn (AS2 (mov%L2,%1,%2), operands); + return AS1 (push%L2,%2); + } +}") + +;; Special memory<->memory pattern that combine will recreate from the +;; moves to pseudos. +(define_insn "movsf_mem" + [(set (match_operand:SF 0 "memory_operand" "=m") + (match_operand:SF 1 "memory_operand" "m")) + (clobber (match_scratch:SI 2 "=&r"))] + "" + "* +{ + output_asm_insn (AS2 (mov%L2,%1,%2), operands); + return AS2 (mov%L0,%2,%0); +}") + +;; For the purposes of regclass, prefer FLOAT_REGS. +(define_insn "movsf_normal" + [(set (match_operand:SF 0 "general_operand" "=*rfm,*rf,f,!*rm") + (match_operand:SF 1 "general_operand" "*rf,*rfm,fG,fF"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + /* First handle a `pop' insn or a `fld %st(0)' */ + + if (STACK_TOP_P (operands[0]) && STACK_TOP_P (operands[1])) + { + if (stack_top_dies) + return AS1 (fstp,%y0); + else + return AS1 (fld,%y0); + } + + /* Handle a transfer between the 387 and a 386 register */ + + if (STACK_TOP_P (operands[0]) && NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (STACK_TOP_P (operands[1]) && NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + /* Handle other kinds of writes from the 387 */ + + if (STACK_TOP_P (operands[1])) + { + if (stack_top_dies) + return AS1 (fstp%z0,%y0); + else + return AS1 (fst%z0,%y0); + } + + /* Handle other kinds of reads to the 387 */ + + if (STACK_TOP_P (operands[0]) && GET_CODE (operands[1]) == CONST_DOUBLE) + return output_move_const_single (operands); + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + /* Handle all SFmode moves not involving the 387 */ + + return singlemove_string (operands); +}") + +(define_insn "swapsf" + [(set (match_operand:SF 0 "register_operand" "f") + (match_operand:SF 1 "register_operand" "f")) + (set (match_dup 1) + (match_dup 0))] + "" + "* +{ + if (STACK_TOP_P (operands[0])) + return AS1 (fxch,%1); + else + return AS1 (fxch,%0); +}") + +(define_expand "movdf" + [(set (match_operand:DF 0 "general_operand" "") + (match_operand:DF 1 "general_operand" ""))] + "" + " +{ + /* Special case memory->memory moves and pushes */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && (GET_CODE (operands[1]) == MEM || push_operand (operands[0], DFmode))) + { + rtx (*genfunc) PROTO((rtx, rtx)) = (push_operand (operands[0], DFmode)) + ? gen_movdf_push + : gen_movdf_mem; + + emit_insn ((*genfunc) (operands[0], operands[1])); + DONE; + } + + /* If we are loading a floating point constant that isn't 0 or 1 into a register, + indicate we need the pic register loaded. This could be optimized into stores + of constants if the target eventually moves to memory, but better safe than + sorry. */ + if (flag_pic + && GET_CODE (operands[0]) != MEM + && GET_CODE (operands[1]) == CONST_DOUBLE + && !standard_80387_constant_p (operands[1])) + { + current_function_uses_pic_offset_table = 1; + } +}") + +(define_insn "movdf_push_nomove" + [(set (match_operand:DF 0 "push_operand" "=<,<") + (match_operand:DF 1 "general_operand" "gF,f"))] + "!TARGET_MOVE" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (8); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp%Q0,%0), xops); + else + output_asm_insn (AS1 (fst%Q0,%0), xops); + + RET; + } + else + return output_move_double (operands); +}") + +(define_insn "movdf_push" + [(set (match_operand:DF 0 "push_operand" "=<,<,<,<,<") + (match_operand:DF 1 "general_operand" "rF,f,o,o,o")) + (clobber (match_scratch:SI 2 "=X,X,&r,&r,X")) + (clobber (match_scratch:SI 3 "=X,X,&r,X,X"))] + "" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (8); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + + if (find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fstp%Q0,%0), xops); + else + output_asm_insn (AS1 (fst%Q0,%0), xops); + + RET; + } + + else if (GET_CODE (operands[1]) != MEM) + return output_move_double (operands); + + else + return output_move_pushmem (operands, insn, GET_MODE_SIZE (DFmode), 2, 4); +}") + +(define_insn "movdf_mem" + [(set (match_operand:DF 0 "memory_operand" "=o,o") + (match_operand:DF 1 "memory_operand" "o,o")) + (clobber (match_scratch:SI 2 "=&r,&r")) + (clobber (match_scratch:SI 3 "=&r,X"))] + "" + "* return output_move_memory (operands, insn, GET_MODE_SIZE (DFmode), 2, 4);") + +;; For the purposes of regclass, prefer FLOAT_REGS. +(define_insn "movdf_normal" + [(set (match_operand:DF 0 "general_operand" "=f,fm,!*rf,!*rm") + (match_operand:DF 1 "general_operand" "fmG,f,*rfm,*rfF"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + /* First handle a `pop' insn or a `fld %st(0)' */ + + if (STACK_TOP_P (operands[0]) && STACK_TOP_P (operands[1])) + { + if (stack_top_dies) + return AS1 (fstp,%y0); + else + return AS1 (fld,%y0); + } + + /* Handle a transfer between the 387 and a 386 register */ + + if (STACK_TOP_P (operands[0]) && NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (STACK_TOP_P (operands[1]) && NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + /* Handle other kinds of writes from the 387 */ + + if (STACK_TOP_P (operands[1])) + { + if (stack_top_dies) + return AS1 (fstp%z0,%y0); + else + return AS1 (fst%z0,%y0); + } + + /* Handle other kinds of reads to the 387 */ + + if (STACK_TOP_P (operands[0]) && GET_CODE (operands[1]) == CONST_DOUBLE) + return output_move_const_single (operands); + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + /* Handle all DFmode moves not involving the 387 */ + + return output_move_double (operands); +}") + +(define_insn "swapdf" + [(set (match_operand:DF 0 "register_operand" "f") + (match_operand:DF 1 "register_operand" "f")) + (set (match_dup 1) + (match_dup 0))] + "" + "* +{ + if (STACK_TOP_P (operands[0])) + return AS1 (fxch,%1); + else + return AS1 (fxch,%0); +}") + +(define_expand "movxf" + [(set (match_operand:XF 0 "general_operand" "") + (match_operand:XF 1 "general_operand" ""))] + "" + " +{ + /* Special case memory->memory moves and pushes */ + if (TARGET_MOVE + && (reload_in_progress | reload_completed) == 0 + && GET_CODE (operands[0]) == MEM + && (GET_CODE (operands[1]) == MEM || push_operand (operands[0], XFmode))) + { + rtx (*genfunc) PROTO((rtx, rtx)) = (push_operand (operands[0], XFmode)) + ? gen_movxf_push + : gen_movxf_mem; + + emit_insn ((*genfunc) (operands[0], operands[1])); + DONE; + } + + /* If we are loading a floating point constant that isn't 0 or 1 into a register, + indicate we need the pic register loaded. This could be optimized into stores + of constants if the target eventually moves to memory, but better safe than + sorry. */ + if (flag_pic + && GET_CODE (operands[0]) != MEM + && GET_CODE (operands[1]) == CONST_DOUBLE + && !standard_80387_constant_p (operands[1])) + { + current_function_uses_pic_offset_table = 1; + } +}") + + +(define_insn "movxf_push_nomove" + [(set (match_operand:XF 0 "push_operand" "=<,<") + (match_operand:XF 1 "general_operand" "gF,f"))] + "!TARGET_MOVE" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (12); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + output_asm_insn (AS1 (fstp%T0,%0), xops); + if (! find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fld%T0,%0), xops); + + RET; + } + else + return output_move_double (operands); + }") + +(define_insn "movxf_push" + [(set (match_operand:XF 0 "push_operand" "=<,<,<,<,<") + (match_operand:XF 1 "general_operand" "rF,f,o,o,o")) + (clobber (match_scratch:SI 2 "=X,X,&r,&r,X")) + (clobber (match_scratch:SI 3 "=X,X,&r,X,X"))] + "" + "* +{ + if (STACK_REG_P (operands[1])) + { + rtx xops[3]; + + xops[0] = AT_SP (SFmode); + xops[1] = GEN_INT (12); + xops[2] = stack_pointer_rtx; + + output_asm_insn (AS2 (sub%L2,%1,%2), xops); + output_asm_insn (AS1 (fstp%T0,%0), xops); + if (! find_regno_note (insn, REG_DEAD, FIRST_STACK_REG)) + output_asm_insn (AS1 (fld%T0,%0), xops); + + RET; + } + + else if (GET_CODE (operands[1]) != MEM + || GET_CODE (operands[2]) != REG) + return output_move_double (operands); + + else + return output_move_pushmem (operands, insn, GET_MODE_SIZE (XFmode), 2, 4); +}") + +(define_insn "movxf_mem" + [(set (match_operand:XF 0 "memory_operand" "=o,o") + (match_operand:XF 1 "memory_operand" "o,o")) + (clobber (match_scratch:SI 2 "=&r,&r")) + (clobber (match_scratch:SI 3 "=&r,X"))] + "" + "* return output_move_memory (operands, insn, GET_MODE_SIZE (XFmode), 2, 4);") + +(define_insn "movxf_normal" + [(set (match_operand:XF 0 "general_operand" "=f,fm,!*rf,!*rm") + (match_operand:XF 1 "general_operand" "fmG,f,*rfm,*rfF"))] + "(!TARGET_MOVE || GET_CODE (operands[0]) != MEM) || (GET_CODE (operands[1]) != MEM)" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + /* First handle a `pop' insn or a `fld %st(0)' */ + + if (STACK_TOP_P (operands[0]) && STACK_TOP_P (operands[1])) + { + if (stack_top_dies) + return AS1 (fstp,%y0); + else + return AS1 (fld,%y0); + } + + /* Handle a transfer between the 387 and a 386 register */ + + if (STACK_TOP_P (operands[0]) && NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (STACK_TOP_P (operands[1]) && NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + /* Handle other kinds of writes from the 387 */ + + if (STACK_TOP_P (operands[1])) + { + output_asm_insn (AS1 (fstp%z0,%y0), operands); + if (! stack_top_dies) + return AS1 (fld%z0,%y0); + + RET; + } + + /* Handle other kinds of reads to the 387 */ + + if (STACK_TOP_P (operands[0]) && GET_CODE (operands[1]) == CONST_DOUBLE) + return output_move_const_single (operands); + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + /* Handle all XFmode moves not involving the 387 */ + + return output_move_double (operands); +}") + +(define_insn "swapxf" + [(set (match_operand:XF 0 "register_operand" "f") + (match_operand:XF 1 "register_operand" "f")) + (set (match_dup 1) + (match_dup 0))] + "" + "* +{ + if (STACK_TOP_P (operands[0])) + return AS1 (fxch,%1); + else + return AS1 (fxch,%0); +}") + +(define_insn "" + [(set (match_operand:DI 0 "push_operand" "=<,<,<,<") + (match_operand:DI 1 "general_operand" "riF,o,o,o")) + (clobber (match_scratch:SI 2 "=X,&r,&r,X")) + (clobber (match_scratch:SI 3 "=X,&r,X,X"))] + "" + "* +{ + if (GET_CODE (operands[1]) != MEM) + return output_move_double (operands); + + else + return output_move_pushmem (operands, insn, GET_MODE_SIZE (DImode), 2, 4); +}") + +(define_insn "movdi" + [(set (match_operand:DI 0 "general_operand" "=o,o,r,rm") + (match_operand:DI 1 "general_operand" "o,o,m,riF")) + (clobber (match_scratch:SI 2 "=&r,&r,X,X")) + (clobber (match_scratch:SI 3 "=&r,X,X,X"))] + "" + "* +{ + rtx low[2], high[2], xop[6]; + + if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != MEM) + return output_move_double (operands); + else + return output_move_memory (operands, insn, GET_MODE_SIZE (DImode), 2, 4); +}") + + +;;- conversion instructions +;;- NONE + +;;- zero extension instructions +;; See comments by `andsi' for when andl is faster than movzx. + +(define_insn "zero_extendhisi2" + [(set (match_operand:SI 0 "general_operand" "=r") + (zero_extend:SI + (match_operand:HI 1 "nonimmediate_operand" "rm")))] + "" + "* +{ + if ((!TARGET_386 || REGNO (operands[0]) == 0) + && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])) + { + rtx xops[2]; + xops[0] = operands[0]; + xops[1] = GEN_INT (0xffff); + output_asm_insn (AS2 (and%L0,%1,%k0), xops); + RET; + } + +#ifdef INTEL_SYNTAX + return AS2 (movzx,%1,%0); +#else + return AS2 (movz%W0%L0,%1,%0); +#endif +}") + +(define_insn "zero_extendqihi2" + [(set (match_operand:HI 0 "general_operand" "=r") + (zero_extend:HI + (match_operand:QI 1 "nonimmediate_operand" "qm")))] + "" + "* +{ + if ((!TARGET_386 || REGNO (operands[0]) == 0) + && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])) + { + rtx xops[2]; + xops[0] = operands[0]; + xops[1] = GEN_INT (0xff); + output_asm_insn (AS2 (and%L0,%1,%k0), xops); + RET; + } + +#ifdef INTEL_SYNTAX + return AS2 (movzx,%1,%0); +#else + return AS2 (movz%B0%W0,%1,%0); +#endif +}") + +(define_insn "zero_extendqisi2" + [(set (match_operand:SI 0 "general_operand" "=r") + (zero_extend:SI + (match_operand:QI 1 "nonimmediate_operand" "qm")))] + "" + "* +{ + if ((!TARGET_386 || REGNO (operands[0]) == 0) + && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])) + { + rtx xops[2]; + xops[0] = operands[0]; + xops[1] = GEN_INT (0xff); + output_asm_insn (AS2 (and%L0,%1,%k0), xops); + RET; + } + +#ifdef INTEL_SYNTAX + return AS2 (movzx,%1,%0); +#else + return AS2 (movz%B0%L0,%1,%0); +#endif +}") + +(define_insn "zero_extendsidi2" + [(set (match_operand:DI 0 "register_operand" "=r") + (zero_extend:DI + (match_operand:SI 1 "register_operand" "0")))] + "" + "* +{ + operands[0] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1); + return AS2 (xor%L0,%0,%0); +}") + +;;- sign extension instructions + +(define_insn "extendsidi2" + [(set (match_operand:DI 0 "register_operand" "=r") + (sign_extend:DI + (match_operand:SI 1 "register_operand" "0")))] + "" + "* +{ + if (REGNO (operands[0]) == 0) + { + /* This used to be cwtl, but that extends HI to SI somehow. */ +#ifdef INTEL_SYNTAX + return \"cdq\"; +#else + return \"cltd\"; +#endif + } + + operands[1] = gen_rtx (REG, SImode, REGNO (operands[0]) + 1); + output_asm_insn (AS2 (mov%L0,%0,%1), operands); + + operands[0] = GEN_INT (31); + return AS2 (sar%L1,%0,%1); +}") + +;; Note that the i386 programmers' manual says that the opcodes +;; are named movsx..., but the assembler on Unix does not accept that. +;; We use what the Unix assembler expects. + +(define_insn "extendhisi2" + [(set (match_operand:SI 0 "general_operand" "=r") + (sign_extend:SI + (match_operand:HI 1 "nonimmediate_operand" "rm")))] + "" + "* +{ + if (REGNO (operands[0]) == 0 + && REG_P (operands[1]) && REGNO (operands[1]) == 0) +#ifdef INTEL_SYNTAX + return \"cwde\"; +#else + return \"cwtl\"; +#endif + +#ifdef INTEL_SYNTAX + return AS2 (movsx,%1,%0); +#else + return AS2 (movs%W0%L0,%1,%0); +#endif +}") + +(define_insn "extendqihi2" + [(set (match_operand:HI 0 "general_operand" "=r") + (sign_extend:HI + (match_operand:QI 1 "nonimmediate_operand" "qm")))] + "" + "* +{ + if (REGNO (operands[0]) == 0 + && REG_P (operands[1]) && REGNO (operands[1]) == 0) + return \"cbtw\"; + +#ifdef INTEL_SYNTAX + return AS2 (movsx,%1,%0); +#else + return AS2 (movs%B0%W0,%1,%0); +#endif +}") + +(define_insn "extendqisi2" + [(set (match_operand:SI 0 "general_operand" "=r") + (sign_extend:SI + (match_operand:QI 1 "nonimmediate_operand" "qm")))] + "" + "* +{ +#ifdef INTEL_SYNTAX + return AS2 (movsx,%1,%0); +#else + return AS2 (movs%B0%L0,%1,%0); +#endif +}") + +;; Conversions between float and double. + +(define_insn "extendsfdf2" + [(set (match_operand:DF 0 "general_operand" "=fm,f") + (float_extend:DF + (match_operand:SF 1 "general_operand" "f,fm")))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + if (GET_CODE (operands[0]) == MEM) + { + if (stack_top_dies) + return AS1 (fstp%z0,%y0); + else + return AS1 (fst%z0,%y0); + } + + abort (); +}") + +(define_insn "extenddfxf2" + [(set (match_operand:XF 0 "general_operand" "=fm,f,f,!*r") + (float_extend:XF + (match_operand:DF 1 "general_operand" "f,fm,!*r,f")))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + if (GET_CODE (operands[0]) == MEM) + { + output_asm_insn (AS1 (fstp%z0,%y0), operands); + if (! stack_top_dies) + return AS1 (fld%z0,%y0); + RET; + } + + abort (); +}") + +(define_insn "extendsfxf2" + [(set (match_operand:XF 0 "general_operand" "=fm,f,f,!*r") + (float_extend:XF + (match_operand:SF 1 "general_operand" "f,fm,!*r,f")))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fld%z0,%y1)); + RET; + } + + if (NON_STACK_REG_P (operands[0])) + { + output_to_reg (operands[0], stack_top_dies); + RET; + } + + if (STACK_TOP_P (operands[0])) + return AS1 (fld%z1,%y1); + + if (GET_CODE (operands[0]) == MEM) + { + output_asm_insn (AS1 (fstp%z0,%y0), operands); + if (! stack_top_dies) + return AS1 (fld%z0,%y0); + RET; + } + + abort (); +}") + +(define_expand "truncdfsf2" + [(parallel [(set (match_operand:SF 0 "nonimmediate_operand" "") + (float_truncate:SF + (match_operand:DF 1 "register_operand" ""))) + (clobber (match_dup 2))])] + "TARGET_80387" + " +{ + operands[2] = (rtx) assign_386_stack_local (SFmode, 0); +}") + +;; This cannot output into an f-reg because there is no way to be sure +;; of truncating in that case. Otherwise this is just like a simple move +;; insn. So we pretend we can output to a reg in order to get better +;; register preferencing, but we really use a stack slot. + +(define_insn "" + [(set (match_operand:SF 0 "nonimmediate_operand" "=f,m") + (float_truncate:SF + (match_operand:DF 1 "register_operand" "0,f"))) + (clobber (match_operand:SF 2 "memory_operand" "m,m"))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (GET_CODE (operands[0]) == MEM) + { + if (stack_top_dies) + return AS1 (fstp%z0,%0); + else + return AS1 (fst%z0,%0); + } + else if (STACK_TOP_P (operands[0])) + { + output_asm_insn (AS1 (fstp%z2,%y2), operands); + return AS1 (fld%z2,%y2); + } + else + abort (); +}") + +(define_insn "truncxfsf2" + [(set (match_operand:SF 0 "general_operand" "=m,!*r") + (float_truncate:SF + (match_operand:XF 1 "register_operand" "f,f")))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (NON_STACK_REG_P (operands[0])) + { + if (stack_top_dies == 0) + { + output_asm_insn (AS1 (fld,%y1), operands); + stack_top_dies = 1; + } + output_to_reg (operands[0], stack_top_dies); + RET; + } + else if (GET_CODE (operands[0]) == MEM) + { + if (stack_top_dies) + return AS1 (fstp%z0,%0); + else + { + output_asm_insn (AS1 (fld,%y1), operands); + return AS1 (fstp%z0,%0); + } + } + else + abort (); +}") + +(define_insn "truncxfdf2" + [(set (match_operand:DF 0 "general_operand" "=m,!*r") + (float_truncate:DF + (match_operand:XF 1 "register_operand" "f,f")))] + "TARGET_80387" + "* +{ + int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; + + if (NON_STACK_REG_P (operands[0])) + { + if (stack_top_dies == 0) + { + output_asm_insn (AS1 (fld,%y1), operands); + stack_top_dies = 1; + } + output_to_reg (operands[0], stack_top_dies); + RET; + } + else if (GET_CODE (operands[0]) == MEM) + { + if (stack_top_dies) + return AS1 (fstp%z0,%0); + else + { + output_asm_insn (AS1 (fld,%y1), operands); + return AS1 (fstp%z0,%0); + } + } + else + abort (); +}") + + +;; The 387 requires that the stack top dies after converting to DImode. + +;; Represent an unsigned conversion from SImode to MODE_FLOAT by first +;; doing a signed conversion to DImode, and then taking just the low +;; part. + +(define_expand "fixuns_truncxfsi2" + [(set (match_dup 4) + (match_operand:XF 1 "register_operand" "")) + (parallel [(set (match_dup 2) + (fix:DI (fix:XF (match_dup 4)))) + (clobber (match_dup 4)) + (clobber (match_dup 5)) + (clobber (match_dup 6)) + (clobber (match_scratch:SI 7 ""))]) + (set (match_operand:SI 0 "general_operand" "") + (match_dup 3))] + "TARGET_80387" + " +{ + operands[2] = gen_reg_rtx (DImode); + operands[3] = gen_lowpart (SImode, operands[2]); + operands[4] = gen_reg_rtx (XFmode); + operands[5] = (rtx) assign_386_stack_local (SImode, 0); + operands[6] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fixuns_truncdfsi2" + [(set (match_dup 4) + (match_operand:DF 1 "register_operand" "")) + (parallel [(set (match_dup 2) + (fix:DI (fix:DF (match_dup 4)))) + (clobber (match_dup 4)) + (clobber (match_dup 5)) + (clobber (match_dup 6)) + (clobber (match_scratch:SI 7 ""))]) + (set (match_operand:SI 0 "general_operand" "") + (match_dup 3))] + "TARGET_80387" + " +{ + operands[2] = gen_reg_rtx (DImode); + operands[3] = gen_lowpart (SImode, operands[2]); + operands[4] = gen_reg_rtx (DFmode); + operands[5] = (rtx) assign_386_stack_local (SImode, 0); + operands[6] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fixuns_truncsfsi2" + [(set (match_dup 4) + (match_operand:SF 1 "register_operand" "")) + (parallel [(set (match_dup 2) + (fix:DI (fix:SF (match_dup 4)))) + (clobber (match_dup 4)) + (clobber (match_dup 5)) + (clobber (match_dup 6)) + (clobber (match_scratch:SI 7 ""))]) + (set (match_operand:SI 0 "general_operand" "") + (match_dup 3))] + "TARGET_80387" + " +{ + operands[2] = gen_reg_rtx (DImode); + operands[3] = gen_lowpart (SImode, operands[2]); + operands[4] = gen_reg_rtx (SFmode); + operands[5] = (rtx) assign_386_stack_local (SImode, 0); + operands[6] = (rtx) assign_386_stack_local (SImode, 1); +}") + +;; Signed conversion to DImode. + +(define_expand "fix_truncxfdi2" + [(set (match_dup 2) + (match_operand:XF 1 "register_operand" "")) + (parallel [(set (match_operand:DI 0 "general_operand" "") + (fix:DI (fix:XF (match_dup 2)))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_dup 4)) + (clobber (match_scratch:SI 5 ""))])] + "TARGET_80387" + " +{ + operands[1] = copy_to_mode_reg (XFmode, operands[1]); + operands[2] = gen_reg_rtx (XFmode); + operands[3] = (rtx) assign_386_stack_local (SImode, 0); + operands[4] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fix_truncdfdi2" + [(set (match_dup 2) + (match_operand:DF 1 "register_operand" "")) + (parallel [(set (match_operand:DI 0 "general_operand" "") + (fix:DI (fix:DF (match_dup 2)))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_dup 4)) + (clobber (match_scratch:SI 5 ""))])] + "TARGET_80387" + " +{ + operands[1] = copy_to_mode_reg (DFmode, operands[1]); + operands[2] = gen_reg_rtx (DFmode); + operands[3] = (rtx) assign_386_stack_local (SImode, 0); + operands[4] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fix_truncsfdi2" + [(set (match_dup 2) + (match_operand:SF 1 "register_operand" "")) + (parallel [(set (match_operand:DI 0 "general_operand" "") + (fix:DI (fix:SF (match_dup 2)))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_dup 4)) + (clobber (match_scratch:SI 5 ""))])] + "TARGET_80387" + " +{ + operands[1] = copy_to_mode_reg (SFmode, operands[1]); + operands[2] = gen_reg_rtx (SFmode); + operands[3] = (rtx) assign_386_stack_local (SImode, 0); + operands[4] = (rtx) assign_386_stack_local (SImode, 1); +}") + +;; These match a signed conversion of either DFmode or SFmode to DImode. + +(define_insn "" + [(set (match_operand:DI 0 "general_operand" "=rm") + (fix:DI (fix:XF (match_operand:XF 1 "register_operand" "f")))) + (clobber (match_dup 1)) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +(define_insn "" + [(set (match_operand:DI 0 "general_operand" "=rm") + (fix:DI (fix:DF (match_operand:DF 1 "register_operand" "f")))) + (clobber (match_dup 1)) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +(define_insn "" + [(set (match_operand:DI 0 "general_operand" "=rm") + (fix:DI (fix:SF (match_operand:SF 1 "register_operand" "f")))) + (clobber (match_dup 1)) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +;; Signed MODE_FLOAT conversion to SImode. + +(define_expand "fix_truncxfsi2" + [(parallel [(set (match_operand:SI 0 "general_operand" "") + (fix:SI + (fix:XF (match_operand:XF 1 "register_operand" "")))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_scratch:SI 4 ""))])] + "TARGET_80387" + " +{ + operands[2] = (rtx) assign_386_stack_local (SImode, 0); + operands[3] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fix_truncdfsi2" + [(parallel [(set (match_operand:SI 0 "general_operand" "") + (fix:SI + (fix:DF (match_operand:DF 1 "register_operand" "")))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_scratch:SI 4 ""))])] + "TARGET_80387" + " +{ + operands[2] = (rtx) assign_386_stack_local (SImode, 0); + operands[3] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_expand "fix_truncsfsi2" + [(parallel [(set (match_operand:SI 0 "general_operand" "") + (fix:SI + (fix:SF (match_operand:SF 1 "register_operand" "")))) + (clobber (match_dup 2)) + (clobber (match_dup 3)) + (clobber (match_scratch:SI 4 ""))])] + "TARGET_80387" + " +{ + operands[2] = (rtx) assign_386_stack_local (SImode, 0); + operands[3] = (rtx) assign_386_stack_local (SImode, 1); +}") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=rm") + (fix:SI (fix:XF (match_operand:XF 1 "register_operand" "f")))) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=rm") + (fix:SI (fix:DF (match_operand:DF 1 "register_operand" "f")))) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=rm") + (fix:SI (fix:SF (match_operand:SF 1 "register_operand" "f")))) + (clobber (match_operand:SI 2 "memory_operand" "m")) + (clobber (match_operand:SI 3 "memory_operand" "m")) + (clobber (match_scratch:SI 4 "=&q"))] + "TARGET_80387" + "* return output_fix_trunc (insn, operands);") + +;; Conversion between fixed point and floating point. +;; The actual pattern that matches these is at the end of this file. + +;; ??? Possibly represent floatunssidf2 here in gcc2. + +(define_expand "floatsisf2" + [(set (match_operand:SF 0 "register_operand" "") + (float:SF (match_operand:SI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "floatdisf2" + [(set (match_operand:SF 0 "register_operand" "") + (float:SF (match_operand:DI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "floatsidf2" + [(set (match_operand:DF 0 "register_operand" "") + (float:DF (match_operand:SI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "floatdidf2" + [(set (match_operand:DF 0 "register_operand" "") + (float:DF (match_operand:DI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "floatsixf2" + [(set (match_operand:XF 0 "register_operand" "") + (float:XF (match_operand:SI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "floatdixf2" + [(set (match_operand:XF 0 "register_operand" "") + (float:XF (match_operand:DI 1 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +;; This will convert from SImode or DImode to MODE_FLOAT. + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (float:XF (match_operand:DI 1 "general_operand" "rm")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (float:DF (match_operand:DI 1 "nonimmediate_operand" "rm")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +(define_insn "" + [(set (match_operand:SF 0 "register_operand" "=f") + (float:SF (match_operand:DI 1 "nonimmediate_operand" "rm")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (float:DF (match_operand:SI 1 "nonimmediate_operand" "rm")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f,f") + (float:XF (match_operand:SI 1 "general_operand" "m,!*r")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +(define_insn "" + [(set (match_operand:SF 0 "register_operand" "=f") + (float:SF (match_operand:SI 1 "nonimmediate_operand" "rm")))] + "TARGET_80387" + "* +{ + if (NON_STACK_REG_P (operands[1])) + { + output_op_from_reg (operands[1], AS1 (fild%z0,%1)); + RET; + } + else if (GET_CODE (operands[1]) == MEM) + return AS1 (fild%z1,%1); + else + abort (); +}") + +;;- add instructions + +(define_insn "adddi3" + [(set (match_operand:DI 0 "general_operand" "=&r,ro,o,&r,ro,o,&r,o,o,o") + (plus:DI (match_operand:DI 1 "general_operand" "%0,0,0,o,riF,o,or,riF,riF,o") + (match_operand:DI 2 "general_operand" "o,riF,o,0,0,0,oriF,riF,o,o"))) + (clobber (match_scratch:SI 3 "=X,X,&r,X,&r,&r,X,&r,&r,&r"))] + "" + "* +{ + rtx low[3], high[3], xops[7], temp; + + CC_STATUS_INIT; + + if (rtx_equal_p (operands[0], operands[2])) + { + temp = operands[1]; + operands[1] = operands[2]; + operands[2] = temp; + } + + split_di (operands, 3, low, high); + if (!rtx_equal_p (operands[0], operands[1])) + { + xops[0] = high[0]; + xops[1] = low[0]; + xops[2] = high[1]; + xops[3] = low[1]; + + if (GET_CODE (operands[0]) != MEM) + { + output_asm_insn (AS2 (mov%L1,%3,%1), xops); + output_asm_insn (AS2 (mov%L0,%2,%0), xops); + } + else + { + xops[4] = high[2]; + xops[5] = low[2]; + xops[6] = operands[3]; + output_asm_insn (AS2 (mov%L6,%3,%6), xops); + output_asm_insn (AS2 (add%L6,%5,%6), xops); + output_asm_insn (AS2 (mov%L1,%6,%1), xops); + output_asm_insn (AS2 (mov%L6,%2,%6), xops); + output_asm_insn (AS2 (adc%L6,%4,%6), xops); + output_asm_insn (AS2 (mov%L0,%6,%0), xops); + RET; + } + } + + if (GET_CODE (operands[3]) == REG && GET_CODE (operands[2]) != REG) + { + xops[0] = high[0]; + xops[1] = low[0]; + xops[2] = high[2]; + xops[3] = low[2]; + xops[4] = operands[3]; + + output_asm_insn (AS2 (mov%L4,%3,%4), xops); + output_asm_insn (AS2 (add%L1,%4,%1), xops); + output_asm_insn (AS2 (mov%L4,%2,%4), xops); + output_asm_insn (AS2 (adc%L0,%4,%0), xops); + } + + else if (GET_CODE (low[2]) != CONST_INT || INTVAL (low[2]) != 0) + { + output_asm_insn (AS2 (add%L0,%2,%0), low); + output_asm_insn (AS2 (adc%L0,%2,%0), high); + } + + else + output_asm_insn (AS2 (add%L0,%2,%0), high); + + RET; +}") + +;; On a 486, it is faster to do movl/addl than to do a single leal if +;; operands[1] and operands[2] are both registers. + +(define_insn "addsi3" + [(set (match_operand:SI 0 "general_operand" "=?r,rm,r") + (plus:SI (match_operand:SI 1 "general_operand" "%r,0,0") + (match_operand:SI 2 "general_operand" "ri,ri,rm")))] + "" + "* +{ + if (REG_P (operands[0]) && REGNO (operands[0]) != REGNO (operands[1])) + { + if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2])) + return AS2 (add%L0,%1,%0); + + if (operands[2] == stack_pointer_rtx) + { + rtx temp; + + temp = operands[1]; + operands[1] = operands[2]; + operands[2] = temp; + } + + if (operands[2] != stack_pointer_rtx) + { + CC_STATUS_INIT; + operands[1] = SET_SRC (PATTERN (insn)); + return AS2 (lea%L0,%a1,%0); + } + + output_asm_insn (AS2 (mov%L0,%1,%0), operands); + } + + if (operands[2] == const1_rtx) + return AS1 (inc%L0,%0); + + if (operands[2] == constm1_rtx) + return AS1 (dec%L0,%0); + + return AS2 (add%L0,%2,%0); +}") + +;; ??? `lea' here, for three operand add? If leaw is used, only %bx, +;; %si and %di can appear in SET_SRC, and output_asm_insn might not be +;; able to handle the operand. But leal always works? + +(define_insn "addhi3" + [(set (match_operand:HI 0 "general_operand" "=rm,r") + (plus:HI (match_operand:HI 1 "general_operand" "%0,0") + (match_operand:HI 2 "general_operand" "ri,rm")))] + "" + "* +{ + /* ??? what about offsettable memory references? */ + if (QI_REG_P (operands[0]) + && GET_CODE (operands[2]) == CONST_INT + && (INTVAL (operands[2]) & 0xff) == 0) + { + int byteval = (INTVAL (operands[2]) >> 8) & 0xff; + CC_STATUS_INIT; + + if (byteval == 1) + return AS1 (inc%B0,%h0); + else if (byteval == 255) + return AS1 (dec%B0,%h0); + + operands[2] = GEN_INT (byteval); + return AS2 (add%B0,%2,%h0); + } + + if (operands[2] == const1_rtx) + return AS1 (inc%W0,%0); + + if (operands[2] == constm1_rtx + || (GET_CODE (operands[2]) == CONST_INT + && INTVAL (operands[2]) == 65535)) + return AS1 (dec%W0,%0); + + return AS2 (add%W0,%2,%0); +}") + +(define_insn "addqi3" + [(set (match_operand:QI 0 "general_operand" "=qm,q") + (plus:QI (match_operand:QI 1 "general_operand" "%0,0") + (match_operand:QI 2 "general_operand" "qn,qmn")))] + "" + "* +{ + if (operands[2] == const1_rtx) + return AS1 (inc%B0,%0); + + if (operands[2] == constm1_rtx + || (GET_CODE (operands[2]) == CONST_INT + && INTVAL (operands[2]) == 255)) + return AS1 (dec%B0,%0); + + return AS2 (add%B0,%2,%0); +}") + +;Lennart Augustsson +;says this pattern just makes slower code: +; pushl %ebp +; addl $-80,(%esp) +;instead of +; leal -80(%ebp),%eax +; pushl %eax +; +;(define_insn "" +; [(set (match_operand:SI 0 "push_operand" "=<") +; (plus:SI (match_operand:SI 1 "general_operand" "%r") +; (match_operand:SI 2 "general_operand" "ri")))] +; "" +; "* +;{ +; rtx xops[4]; +; xops[0] = operands[0]; +; xops[1] = operands[1]; +; xops[2] = operands[2]; +; xops[3] = gen_rtx (MEM, SImode, stack_pointer_rtx); +; output_asm_insn (\"push%z1 %1\", xops); +; output_asm_insn (AS2 (add%z3,%2,%3), xops); +; RET; +;}") + +;; addsi3 is faster, so put this after. + +(define_insn "movsi_lea" + [(set (match_operand:SI 0 "register_operand" "=r") + (match_operand:QI 1 "address_operand" "p"))] + "" + "* +{ + CC_STATUS_INIT; + /* Adding a constant to a register is faster with an add. */ + /* ??? can this ever happen? */ + if (GET_CODE (operands[1]) == PLUS + && GET_CODE (XEXP (operands[1], 1)) == CONST_INT + && rtx_equal_p (operands[0], XEXP (operands[1], 0))) + { + operands[1] = XEXP (operands[1], 1); + + if (operands[1] == const1_rtx) + return AS1 (inc%L0,%0); + + if (operands[1] == constm1_rtx) + return AS1 (dec%L0,%0); + + return AS2 (add%L0,%1,%0); + } + return AS2 (lea%L0,%a1,%0); +}") + +;; The patterns that match these are at the end of this file. + +(define_expand "addxf3" + [(set (match_operand:XF 0 "register_operand" "") + (plus:XF (match_operand:XF 1 "nonimmediate_operand" "") + (match_operand:XF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "adddf3" + [(set (match_operand:DF 0 "register_operand" "") + (plus:DF (match_operand:DF 1 "nonimmediate_operand" "") + (match_operand:DF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "addsf3" + [(set (match_operand:SF 0 "register_operand" "") + (plus:SF (match_operand:SF 1 "nonimmediate_operand" "") + (match_operand:SF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +;;- subtract instructions + +(define_insn "subdi3" + [(set (match_operand:DI 0 "general_operand" "=&r,ro,&r,o,o") + (minus:DI (match_operand:DI 1 "general_operand" "0,0,roiF,riF,o") + (match_operand:DI 2 "general_operand" "o,riF,roiF,riF,o"))) + (clobber (match_scratch:SI 3 "=X,X,X,&r,&r"))] + "" + "* +{ + rtx low[3], high[3], xops[7]; + + CC_STATUS_INIT; + + split_di (operands, 3, low, high); + + if (!rtx_equal_p (operands[0], operands[1])) + { + xops[0] = high[0]; + xops[1] = low[0]; + xops[2] = high[1]; + xops[3] = low[1]; + + if (GET_CODE (operands[0]) != MEM) + { + output_asm_insn (AS2 (mov%L1,%3,%1), xops); + output_asm_insn (AS2 (mov%L0,%2,%0), xops); + } + else + { + xops[4] = high[2]; + xops[5] = low[2]; + xops[6] = operands[3]; + output_asm_insn (AS2 (mov%L6,%3,%6), xops); + output_asm_insn (AS2 (sub%L6,%5,%6), xops); + output_asm_insn (AS2 (mov%L1,%6,%1), xops); + output_asm_insn (AS2 (mov%L6,%2,%6), xops); + output_asm_insn (AS2 (sbb%L6,%4,%6), xops); + output_asm_insn (AS2 (mov%L0,%6,%0), xops); + RET; + } + } + + if (GET_CODE (operands[3]) == REG) + { + xops[0] = high[0]; + xops[1] = low[0]; + xops[2] = high[2]; + xops[3] = low[2]; + xops[4] = operands[3]; + + output_asm_insn (AS2 (mov%L4,%3,%4), xops); + output_asm_insn (AS2 (sub%L1,%4,%1), xops); + output_asm_insn (AS2 (mov%L4,%2,%4), xops); + output_asm_insn (AS2 (sbb%L0,%4,%0), xops); + } + + else if (GET_CODE (low[2]) != CONST_INT || INTVAL (low[2]) != 0) + { + output_asm_insn (AS2 (sub%L0,%2,%0), low); + output_asm_insn (AS2 (sbb%L0,%2,%0), high); + } + + else + output_asm_insn (AS2 (sub%L0,%2,%0), high); + + RET; +}") + +(define_insn "subsi3" + [(set (match_operand:SI 0 "general_operand" "=rm,r") + (minus:SI (match_operand:SI 1 "general_operand" "0,0") + (match_operand:SI 2 "general_operand" "ri,rm")))] + "" + "* return AS2 (sub%L0,%2,%0);") + +(define_insn "subhi3" + [(set (match_operand:HI 0 "general_operand" "=rm,r") + (minus:HI (match_operand:HI 1 "general_operand" "0,0") + (match_operand:HI 2 "general_operand" "ri,rm")))] + "" + "* return AS2 (sub%W0,%2,%0);") + +(define_insn "subqi3" + [(set (match_operand:QI 0 "general_operand" "=qm,q") + (minus:QI (match_operand:QI 1 "general_operand" "0,0") + (match_operand:QI 2 "general_operand" "qn,qmn")))] + "" + "* return AS2 (sub%B0,%2,%0);") + +;; The patterns that match these are at the end of this file. + +(define_expand "subxf3" + [(set (match_operand:XF 0 "register_operand" "") + (minus:XF (match_operand:XF 1 "nonimmediate_operand" "") + (match_operand:XF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "subdf3" + [(set (match_operand:DF 0 "register_operand" "") + (minus:DF (match_operand:DF 1 "nonimmediate_operand" "") + (match_operand:DF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "subsf3" + [(set (match_operand:SF 0 "register_operand" "") + (minus:SF (match_operand:SF 1 "nonimmediate_operand" "") + (match_operand:SF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +;;- multiply instructions + +;(define_insn "mulqi3" +; [(set (match_operand:QI 0 "general_operand" "=a") +; (mult:QI (match_operand:QI 1 "general_operand" "%0") +; (match_operand:QI 2 "general_operand" "qm")))] +; "" +; "imul%B0 %2,%0") + +(define_insn "" + [(set (match_operand:HI 0 "general_operand" "=r") + (mult:HI (match_operand:HI 1 "general_operand" "%0") + (match_operand:HI 2 "general_operand" "r")))] + "GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 0x80" + "* return AS2 (imul%W0,%2,%0);") + +(define_insn "mulhi3" + [(set (match_operand:HI 0 "general_operand" "=r,r") + (mult:HI (match_operand:HI 1 "general_operand" "%0,rm") + (match_operand:HI 2 "general_operand" "g,i")))] + "" + "* +{ + if (GET_CODE (operands[1]) == REG + && REGNO (operands[1]) == REGNO (operands[0]) + && (GET_CODE (operands[2]) == MEM || GET_CODE (operands[2]) == REG)) + /* Assembler has weird restrictions. */ + return AS2 (imul%W0,%2,%0); + return AS3 (imul%W0,%2,%1,%0); +}") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=r") + (mult:SI (match_operand:SI 1 "general_operand" "%0") + (match_operand:SI 2 "general_operand" "r")))] + "GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) == 0x80" + "* return AS2 (imul%L0,%2,%0);") + +(define_insn "mulsi3" + [(set (match_operand:SI 0 "general_operand" "=r,r") + (mult:SI (match_operand:SI 1 "general_operand" "%0,rm") + (match_operand:SI 2 "general_operand" "g,i")))] + "" + "* +{ + if (GET_CODE (operands[1]) == REG + && REGNO (operands[1]) == REGNO (operands[0]) + && (GET_CODE (operands[2]) == MEM || GET_CODE (operands[2]) == REG)) + /* Assembler has weird restrictions. */ + return AS2 (imul%L0,%2,%0); + return AS3 (imul%L0,%2,%1,%0); +}") + +(define_insn "umulqihi3" + [(set (match_operand:HI 0 "general_operand" "=a") + (mult:HI (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "%0")) + (zero_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))] + "" + "mul%B0 %2") + +(define_insn "mulqihi3" + [(set (match_operand:HI 0 "general_operand" "=a") + (mult:HI (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "%0")) + (sign_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))))] + "" + "imul%B0 %2") + +(define_insn "umulsidi3" + [(set (match_operand:DI 0 "register_operand" "=A") + (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%0")) + (zero_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))] + "TARGET_WIDE_MULTIPLY" + "mul%L0 %2") + +(define_insn "mulsidi3" + [(set (match_operand:DI 0 "register_operand" "=A") + (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%0")) + (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))))] + "TARGET_WIDE_MULTIPLY" + "imul%L0 %2") + +(define_insn "umulsi3_highpart" + [(set (match_operand:SI 0 "register_operand" "=d") + (truncate:SI (lshiftrt:DI (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "%a")) + (zero_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))) + (const_int 32)))) + (clobber (match_scratch:SI 3 "=a"))] + "TARGET_WIDE_MULTIPLY" + "mul%L0 %2") + +(define_insn "smulsi3_highpart" + [(set (match_operand:SI 0 "register_operand" "=d") + (truncate:SI (lshiftrt:DI (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "%a")) + (sign_extend:DI (match_operand:SI 2 "nonimmediate_operand" "rm"))) + (const_int 32)))) + (clobber (match_scratch:SI 3 "=a"))] + "TARGET_WIDE_MULTIPLY" + "imul%L0 %2") + +;; The patterns that match these are at the end of this file. + +(define_expand "mulxf3" + [(set (match_operand:XF 0 "register_operand" "") + (mult:XF (match_operand:XF 1 "nonimmediate_operand" "") + (match_operand:XF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "muldf3" + [(set (match_operand:DF 0 "register_operand" "") + (mult:DF (match_operand:DF 1 "nonimmediate_operand" "") + (match_operand:DF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "mulsf3" + [(set (match_operand:SF 0 "register_operand" "") + (mult:SF (match_operand:SF 1 "nonimmediate_operand" "") + (match_operand:SF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +;;- divide instructions + +(define_insn "divqi3" + [(set (match_operand:QI 0 "general_operand" "=a") + (div:QI (match_operand:HI 1 "general_operand" "0") + (match_operand:QI 2 "general_operand" "qm")))] + "" + "idiv%B0 %2") + +(define_insn "udivqi3" + [(set (match_operand:QI 0 "general_operand" "=a") + (udiv:QI (match_operand:HI 1 "general_operand" "0") + (match_operand:QI 2 "general_operand" "qm")))] + "" + "div%B0 %2") + +;; The patterns that match these are at the end of this file. + +(define_expand "divxf3" + [(set (match_operand:XF 0 "register_operand" "") + (div:XF (match_operand:XF 1 "nonimmediate_operand" "") + (match_operand:XF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "divdf3" + [(set (match_operand:DF 0 "register_operand" "") + (div:DF (match_operand:DF 1 "nonimmediate_operand" "") + (match_operand:DF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +(define_expand "divsf3" + [(set (match_operand:SF 0 "register_operand" "") + (div:SF (match_operand:SF 1 "nonimmediate_operand" "") + (match_operand:SF 2 "nonimmediate_operand" "")))] + "TARGET_80387" + "") + +;; Remainder instructions. + +(define_insn "divmodsi4" + [(set (match_operand:SI 0 "register_operand" "=a") + (div:SI (match_operand:SI 1 "register_operand" "0") + (match_operand:SI 2 "general_operand" "rm"))) + (set (match_operand:SI 3 "register_operand" "=&d") + (mod:SI (match_dup 1) (match_dup 2)))] + "" + "* +{ +#ifdef INTEL_SYNTAX + output_asm_insn (\"cdq\", operands); +#else + output_asm_insn (\"cltd\", operands); +#endif + return AS1 (idiv%L0,%2); +}") + +(define_insn "divmodhi4" + [(set (match_operand:HI 0 "register_operand" "=a") + (div:HI (match_operand:HI 1 "register_operand" "0") + (match_operand:HI 2 "general_operand" "rm"))) + (set (match_operand:HI 3 "register_operand" "=&d") + (mod:HI (match_dup 1) (match_dup 2)))] + "" + "cwtd\;idiv%W0 %2") + +;; ??? Can we make gcc zero extend operand[0]? +(define_insn "udivmodsi4" + [(set (match_operand:SI 0 "register_operand" "=a") + (udiv:SI (match_operand:SI 1 "register_operand" "0") + (match_operand:SI 2 "general_operand" "rm"))) + (set (match_operand:SI 3 "register_operand" "=&d") + (umod:SI (match_dup 1) (match_dup 2)))] + "" + "* +{ + output_asm_insn (AS2 (xor%L3,%3,%3), operands); + return AS1 (div%L0,%2); +}") + +;; ??? Can we make gcc zero extend operand[0]? +(define_insn "udivmodhi4" + [(set (match_operand:HI 0 "register_operand" "=a") + (udiv:HI (match_operand:HI 1 "register_operand" "0") + (match_operand:HI 2 "general_operand" "rm"))) + (set (match_operand:HI 3 "register_operand" "=&d") + (umod:HI (match_dup 1) (match_dup 2)))] + "" + "* +{ + output_asm_insn (AS2 (xor%W0,%3,%3), operands); + return AS1 (div%W0,%2); +}") + +/* +;;this should be a valid double division which we may want to add + +(define_insn "" + [(set (match_operand:SI 0 "register_operand" "=a") + (udiv:DI (match_operand:DI 1 "register_operand" "a") + (match_operand:SI 2 "general_operand" "rm"))) + (set (match_operand:SI 3 "register_operand" "=d") + (umod:SI (match_dup 1) (match_dup 2)))] + "" + "div%L0 %2,%0") +*/ + +;;- and instructions + +;; On i386, +;; movzbl %bl,%ebx +;; is faster than +;; andl $255,%ebx +;; +;; but if the reg is %eax, then the "andl" is faster. +;; +;; On i486, the "andl" is always faster than the "movzbl". +;; +;; On both i386 and i486, a three operand AND is as fast with movzbl or +;; movzwl as with andl, if operands[0] != operands[1]. + +;; The `r' in `rm' for operand 3 looks redundant, but it causes +;; optional reloads to be generated if op 3 is a pseudo in a stack slot. + +;; ??? What if we only change one byte of an offsettable memory reference? +(define_insn "andsi3" + [(set (match_operand:SI 0 "general_operand" "=r,r,rm,r") + (and:SI (match_operand:SI 1 "general_operand" "%rm,qm,0,0") + (match_operand:SI 2 "general_operand" "L,K,ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + if (INTVAL (operands[2]) == 0xffff && REG_P (operands[0]) + && (! REG_P (operands[1]) + || REGNO (operands[0]) != 0 || REGNO (operands[1]) != 0) + && (TARGET_386 || ! rtx_equal_p (operands[0], operands[1]))) + { + /* ??? tege: Should forget CC_STATUS only if we clobber a + remembered operand. Fix that later. */ + CC_STATUS_INIT; +#ifdef INTEL_SYNTAX + return AS2 (movzx,%w1,%0); +#else + return AS2 (movz%W0%L0,%w1,%0); +#endif + } + + if (INTVAL (operands[2]) == 0xff && REG_P (operands[0]) + && !(REG_P (operands[1]) && NON_QI_REG_P (operands[1])) + && (! REG_P (operands[1]) + || REGNO (operands[0]) != 0 || REGNO (operands[1]) != 0) + && (TARGET_386 || ! rtx_equal_p (operands[0], operands[1]))) + { + /* ??? tege: Should forget CC_STATUS only if we clobber a + remembered operand. Fix that later. */ + CC_STATUS_INIT; +#ifdef INTEL_SYNTAX + return AS2 (movzx,%b1,%0); +#else + return AS2 (movz%B0%L0,%b1,%0); +#endif + } + + if (QI_REG_P (operands[0]) && ~(INTVAL (operands[2]) | 0xff) == 0) + { + CC_STATUS_INIT; + + if (INTVAL (operands[2]) == 0xffffff00) + { + operands[2] = const0_rtx; + return AS2 (mov%B0,%2,%b0); + } + + operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff); + return AS2 (and%B0,%2,%b0); + } + + if (QI_REG_P (operands[0]) && ~(INTVAL (operands[2]) | 0xff00) == 0) + { + CC_STATUS_INIT; + + if (INTVAL (operands[2]) == 0xffff00ff) + { + operands[2] = const0_rtx; + return AS2 (mov%B0,%2,%h0); + } + + operands[2] = GEN_INT ((INTVAL (operands[2]) >> 8) & 0xff); + return AS2 (and%B0,%2,%h0); + } + + if (GET_CODE (operands[0]) == MEM && INTVAL (operands[2]) == 0xffff0000) + { + operands[2] = const0_rtx; + return AS2 (mov%W0,%2,%w0); + } + } + + return AS2 (and%L0,%2,%0); +}") + +(define_insn "andhi3" + [(set (match_operand:HI 0 "general_operand" "=rm,r") + (and:HI (match_operand:HI 1 "general_operand" "%0,0") + (match_operand:HI 2 "general_operand" "ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + /* Can we ignore the upper byte? */ + if ((! REG_P (operands[0]) || QI_REG_P (operands[0])) + && (INTVAL (operands[2]) & 0xff00) == 0xff00) + { + CC_STATUS_INIT; + + if ((INTVAL (operands[2]) & 0xff) == 0) + { + operands[2] = const0_rtx; + return AS2 (mov%B0,%2,%b0); + } + + operands[2] = GEN_INT (INTVAL (operands[2]) & 0xff); + return AS2 (and%B0,%2,%b0); + } + + /* Can we ignore the lower byte? */ + /* ??? what about offsettable memory references? */ + if (QI_REG_P (operands[0]) && (INTVAL (operands[2]) & 0xff) == 0xff) + { + CC_STATUS_INIT; + + if ((INTVAL (operands[2]) & 0xff00) == 0) + { + operands[2] = const0_rtx; + return AS2 (mov%B0,%2,%h0); + } + + operands[2] = GEN_INT ((INTVAL (operands[2]) >> 8) & 0xff); + return AS2 (and%B0,%2,%h0); + } + } + + return AS2 (and%W0,%2,%0); +}") + +(define_insn "andqi3" + [(set (match_operand:QI 0 "general_operand" "=qm,q") + (and:QI (match_operand:QI 1 "general_operand" "%0,0") + (match_operand:QI 2 "general_operand" "qn,qmn")))] + "" + "* return AS2 (and%B0,%2,%0);") + +/* I am nervous about these two.. add them later.. +;I presume this means that we have something in say op0= eax which is small +;and we want to and it with memory so we can do this by just an +;andb m,%al and have success. +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=r") + (and:SI (zero_extend:SI + (match_operand:HI 1 "nonimmediate_operand" "rm")) + (match_operand:SI 2 "general_operand" "0")))] + "GET_CODE (operands[2]) == CONST_INT + && (unsigned int) INTVAL (operands[2]) < (1 << GET_MODE_BITSIZE (HImode))" + "and%W0 %1,%0") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=q") + (and:SI + (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "qm")) + (match_operand:SI 2 "general_operand" "0")))] + "GET_CODE (operands[2]) == CONST_INT + && (unsigned int) INTVAL (operands[2]) < (1 << GET_MODE_BITSIZE (QImode))" + "and%L0 %1,%0") + +*/ + +;;- Bit set (inclusive or) instructions + +;; ??? What if we only change one byte of an offsettable memory reference? +(define_insn "iorsi3" + [(set (match_operand:SI 0 "general_operand" "=rm,r") + (ior:SI (match_operand:SI 1 "general_operand" "%0,0") + (match_operand:SI 2 "general_operand" "ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + if ((! REG_P (operands[0]) || QI_REG_P (operands[0])) + && (INTVAL (operands[2]) & ~0xff) == 0) + { + CC_STATUS_INIT; + + if (INTVAL (operands[2]) == 0xff) + return AS2 (mov%B0,%2,%b0); + + return AS2 (or%B0,%2,%b0); + } + + if (QI_REG_P (operands[0]) && (INTVAL (operands[2]) & ~0xff00) == 0) + { + CC_STATUS_INIT; + operands[2] = GEN_INT (INTVAL (operands[2]) >> 8); + + if (INTVAL (operands[2]) == 0xff) + return AS2 (mov%B0,%2,%h0); + + return AS2 (or%B0,%2,%h0); + } + } + + return AS2 (or%L0,%2,%0); +}") + +(define_insn "iorhi3" + [(set (match_operand:HI 0 "general_operand" "=rm,r") + (ior:HI (match_operand:HI 1 "general_operand" "%0,0") + (match_operand:HI 2 "general_operand" "ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + /* Can we ignore the upper byte? */ + if ((! REG_P (operands[0]) || QI_REG_P (operands[0])) + && (INTVAL (operands[2]) & 0xff00) == 0) + { + CC_STATUS_INIT; + if (INTVAL (operands[2]) & 0xffff0000) + operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff); + + if (INTVAL (operands[2]) == 0xff) + return AS2 (mov%B0,%2,%b0); + + return AS2 (or%B0,%2,%b0); + } + + /* Can we ignore the lower byte? */ + /* ??? what about offsettable memory references? */ + if (QI_REG_P (operands[0]) + && (INTVAL (operands[2]) & 0xff) == 0) + { + CC_STATUS_INIT; + operands[2] = GEN_INT ((INTVAL (operands[2]) >> 8) & 0xff); + + if (INTVAL (operands[2]) == 0xff) + return AS2 (mov%B0,%2,%h0); + + return AS2 (or%B0,%2,%h0); + } + } + + return AS2 (or%W0,%2,%0); +}") + +(define_insn "iorqi3" + [(set (match_operand:QI 0 "general_operand" "=qm,q") + (ior:QI (match_operand:QI 1 "general_operand" "%0,0") + (match_operand:QI 2 "general_operand" "qn,qmn")))] + "" + "* return AS2 (or%B0,%2,%0);") + +;;- xor instructions + +;; ??? What if we only change one byte of an offsettable memory reference? +(define_insn "xorsi3" + [(set (match_operand:SI 0 "general_operand" "=rm,r") + (xor:SI (match_operand:SI 1 "general_operand" "%0,0") + (match_operand:SI 2 "general_operand" "ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + if ((! REG_P (operands[0]) || QI_REG_P (operands[0])) + && (INTVAL (operands[2]) & ~0xff) == 0) + { + CC_STATUS_INIT; + + if (INTVAL (operands[2]) == 0xff) + return AS1 (not%B0,%b0); + + return AS2 (xor%B0,%2,%b0); + } + + if (QI_REG_P (operands[0]) && (INTVAL (operands[2]) & ~0xff00) == 0) + { + CC_STATUS_INIT; + operands[2] = GEN_INT (INTVAL (operands[2]) >> 8); + + if (INTVAL (operands[2]) == 0xff) + return AS1 (not%B0,%h0); + + return AS2 (xor%B0,%2,%h0); + } + } + + return AS2 (xor%L0,%2,%0); +}") + +(define_insn "xorhi3" + [(set (match_operand:HI 0 "general_operand" "=rm,r") + (xor:HI (match_operand:HI 1 "general_operand" "%0,0") + (match_operand:HI 2 "general_operand" "ri,rm")))] + "" + "* +{ + if (GET_CODE (operands[2]) == CONST_INT + && ! (GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))) + { + /* Can we ignore the upper byte? */ + if ((! REG_P (operands[0]) || QI_REG_P (operands[0])) + && (INTVAL (operands[2]) & 0xff00) == 0) + { + CC_STATUS_INIT; + if (INTVAL (operands[2]) & 0xffff0000) + operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff); + + if (INTVAL (operands[2]) == 0xff) + return AS1 (not%B0,%b0); + + return AS2 (xor%B0,%2,%b0); + } + + /* Can we ignore the lower byte? */ + /* ??? what about offsettable memory references? */ + if (QI_REG_P (operands[0]) + && (INTVAL (operands[2]) & 0xff) == 0) + { + CC_STATUS_INIT; + operands[2] = GEN_INT ((INTVAL (operands[2]) >> 8) & 0xff); + + if (INTVAL (operands[2]) == 0xff) + return AS1 (not%B0,%h0); + + return AS2 (xor%B0,%2,%h0); + } + } + + return AS2 (xor%W0,%2,%0); +}") + +(define_insn "xorqi3" + [(set (match_operand:QI 0 "general_operand" "=qm,q") + (xor:QI (match_operand:QI 1 "general_operand" "%0,0") + (match_operand:QI 2 "general_operand" "qn,qm")))] + "" + "* return AS2 (xor%B0,%2,%0);") + +;;- negation instructions + +(define_insn "negdi2" + [(set (match_operand:DI 0 "general_operand" "=&ro") + (neg:DI (match_operand:DI 1 "general_operand" "0")))] + "" + "* +{ + rtx xops[2], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = const0_rtx; + xops[1] = high[0]; + + output_asm_insn (AS1 (neg%L0,%0), low); + output_asm_insn (AS2 (adc%L1,%0,%1), xops); + output_asm_insn (AS1 (neg%L0,%0), high); + RET; +}") + +(define_insn "negsi2" + [(set (match_operand:SI 0 "general_operand" "=rm") + (neg:SI (match_operand:SI 1 "general_operand" "0")))] + "" + "neg%L0 %0") + +(define_insn "neghi2" + [(set (match_operand:HI 0 "general_operand" "=rm") + (neg:HI (match_operand:HI 1 "general_operand" "0")))] + "" + "neg%W0 %0") + +(define_insn "negqi2" + [(set (match_operand:QI 0 "general_operand" "=qm") + (neg:QI (match_operand:QI 1 "general_operand" "0")))] + "" + "neg%B0 %0") + +(define_insn "negsf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (neg:SF (match_operand:SF 1 "general_operand" "0")))] + "TARGET_80387" + "fchs") + +(define_insn "negdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (neg:DF (match_operand:DF 1 "general_operand" "0")))] + "TARGET_80387" + "fchs") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (neg:DF (float_extend:DF (match_operand:SF 1 "general_operand" "0"))))] + "TARGET_80387" + "fchs") + +(define_insn "negxf2" + [(set (match_operand:XF 0 "register_operand" "=f") + (neg:XF (match_operand:XF 1 "general_operand" "0")))] + "TARGET_80387" + "fchs") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (neg:XF (float_extend:XF (match_operand:DF 1 "general_operand" "0"))))] + "TARGET_80387" + "fchs") + +;; Absolute value instructions + +(define_insn "abssf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (abs:SF (match_operand:SF 1 "general_operand" "0")))] + "TARGET_80387" + "fabs") + +(define_insn "absdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (abs:DF (match_operand:DF 1 "general_operand" "0")))] + "TARGET_80387" + "fabs") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (abs:DF (float_extend:DF (match_operand:SF 1 "general_operand" "0"))))] + "TARGET_80387" + "fabs") + +(define_insn "absxf2" + [(set (match_operand:XF 0 "register_operand" "=f") + (abs:XF (match_operand:XF 1 "general_operand" "0")))] + "TARGET_80387" + "fabs") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (abs:XF (float_extend:XF (match_operand:DF 1 "general_operand" "0"))))] + "TARGET_80387" + "fabs") + +(define_insn "sqrtsf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (sqrt:SF (match_operand:SF 1 "general_operand" "0")))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "sqrtdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (sqrt:DF (match_operand:DF 1 "general_operand" "0")))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (sqrt:DF (float_extend:DF + (match_operand:SF 1 "general_operand" "0"))))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "sqrtxf2" + [(set (match_operand:XF 0 "register_operand" "=f") + (sqrt:XF (match_operand:XF 1 "general_operand" "0")))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (sqrt:XF (float_extend:XF + (match_operand:DF 1 "general_operand" "0"))))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (sqrt:XF (float_extend:XF + (match_operand:SF 1 "general_operand" "0"))))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsqrt") + +(define_insn "sindf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (unspec:DF [(match_operand:DF 1 "register_operand" "0")] 1))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsin") + +(define_insn "sinsf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (unspec:SF [(match_operand:SF 1 "register_operand" "0")] 1))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsin") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (unspec:DF [(float_extend:DF + (match_operand:SF 1 "register_operand" "0"))] 1))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsin") + +(define_insn "sinxf2" + [(set (match_operand:XF 0 "register_operand" "=f") + (unspec:XF [(match_operand:XF 1 "register_operand" "0")] 1))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fsin") + +(define_insn "cosdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (unspec:DF [(match_operand:DF 1 "register_operand" "0")] 2))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fcos") + +(define_insn "cossf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (unspec:SF [(match_operand:SF 1 "register_operand" "0")] 2))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fcos") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (unspec:DF [(float_extend:DF + (match_operand:SF 1 "register_operand" "0"))] 2))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fcos") + +(define_insn "cosxf2" + [(set (match_operand:XF 0 "register_operand" "=f") + (unspec:XF [(match_operand:XF 1 "register_operand" "0")] 2))] + "! TARGET_NO_FANCY_MATH_387 && TARGET_80387 + && (TARGET_IEEE_FP || flag_fast_math) " + "fcos") + +;;- one complement instructions + +(define_insn "one_cmplsi2" + [(set (match_operand:SI 0 "general_operand" "=rm") + (not:SI (match_operand:SI 1 "general_operand" "0")))] + "" + "not%L0 %0") + +(define_insn "one_cmplhi2" + [(set (match_operand:HI 0 "general_operand" "=rm") + (not:HI (match_operand:HI 1 "general_operand" "0")))] + "" + "not%W0 %0") + +(define_insn "one_cmplqi2" + [(set (match_operand:QI 0 "general_operand" "=qm") + (not:QI (match_operand:QI 1 "general_operand" "0")))] + "" + "not%B0 %0") + +;;- arithmetic shift instructions + +;; DImode shifts are implemented using the i386 "shift double" opcode, +;; which is written as "sh[lr]d[lw] imm,reg,reg/mem". If the shift count +;; is variable, then the count is in %cl and the "imm" operand is dropped +;; from the assembler input. + +;; This instruction shifts the target reg/mem as usual, but instead of +;; shifting in zeros, bits are shifted in from reg operand. If the insn +;; is a left shift double, bits are taken from the high order bits of +;; reg, else if the insn is a shift right double, bits are taken from the +;; low order bits of reg. So if %eax is "1234" and %edx is "5678", +;; "shldl $8,%edx,%eax" leaves %edx unchanged and sets %eax to "2345". + +;; Since sh[lr]d does not change the `reg' operand, that is done +;; separately, making all shifts emit pairs of shift double and normal +;; shift. Since sh[lr]d does not shift more than 31 bits, and we wish to +;; support a 63 bit shift, each shift where the count is in a reg expands +;; to three pairs. If the overall shift is by N bits, then the first two +;; pairs shift by N / 2 and the last pair by N & 1. + +;; If the shift count is a constant, we need never emit more than one +;; shift pair, instead using moves and sign extension for counts greater +;; than 31. + +(define_expand "ashldi3" + [(set (match_operand:DI 0 "register_operand" "") + (ashift:DI (match_operand:DI 1 "register_operand" "") + (match_operand:QI 2 "nonmemory_operand" "")))] + "" + " +{ + if (GET_CODE (operands[2]) != CONST_INT + || ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')) + { + operands[2] = copy_to_mode_reg (QImode, operands[2]); + emit_insn (gen_ashldi3_non_const_int (operands[0], operands[1], + operands[2])); + } + else + emit_insn (gen_ashldi3_const_int (operands[0], operands[1], operands[2])); + + DONE; +}") + +(define_insn "ashldi3_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (ashift:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "const_int_operand" "J")))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + if (INTVAL (xops[0]) > 31) + { + output_asm_insn (AS2 (mov%L3,%2,%3), xops); /* Fast shift by 32 */ + output_asm_insn (AS2 (xor%L2,%2,%2), xops); + + if (INTVAL (xops[0]) > 32) + { + xops[0] = GEN_INT (INTVAL (xops[0]) - 32); + output_asm_insn (AS2 (sal%L3,%0,%3), xops); /* Remaining shift */ + } + } + else + { + output_asm_insn (AS3 (shld%L3,%0,%2,%3), xops); + output_asm_insn (AS2 (sal%L2,%0,%2), xops); + } + RET; +}") + +(define_insn "ashldi3_non_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (ashift:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "register_operand" "c"))) + (clobber (match_dup 2))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + output_asm_insn (AS2 (ror%B0,%1,%0), xops); /* shift count / 2 */ + + output_asm_insn (AS3_SHIFT_DOUBLE (shld%L3,%0,%2,%3), xops); + output_asm_insn (AS2 (sal%L2,%0,%2), xops); + output_asm_insn (AS3_SHIFT_DOUBLE (shld%L3,%0,%2,%3), xops); + output_asm_insn (AS2 (sal%L2,%0,%2), xops); + + xops[1] = GEN_INT (7); /* shift count & 1 */ + + output_asm_insn (AS2 (shr%B0,%1,%0), xops); + + output_asm_insn (AS3_SHIFT_DOUBLE (shld%L3,%0,%2,%3), xops); + output_asm_insn (AS2 (sal%L2,%0,%2), xops); + + RET; +}") + +;; On i386 and i486, "addl reg,reg" is faster than "sall $1,reg" +;; On i486, movl/sall appears slightly faster than leal, but the leal +;; is smaller - use leal for now unless the shift count is 1. + +(define_insn "ashlsi3" + [(set (match_operand:SI 0 "general_operand" "=r,rm") + (ashift:SI (match_operand:SI 1 "general_operand" "r,0") + (match_operand:SI 2 "nonmemory_operand" "M,cI")))] + "" + "* +{ + if (REG_P (operands[0]) && REGNO (operands[0]) != REGNO (operands[1])) + { + if (!TARGET_386 && INTVAL (operands[2]) == 1) + { + output_asm_insn (AS2 (mov%L0,%1,%0), operands); + return AS2 (add%L0,%1,%0); + } + else + { + CC_STATUS_INIT; + + if (operands[1] == stack_pointer_rtx) + { + output_asm_insn (AS2 (mov%L0,%1,%0), operands); + operands[1] = operands[0]; + } + operands[1] = gen_rtx (MULT, SImode, operands[1], + GEN_INT (1 << INTVAL (operands[2]))); + return AS2 (lea%L0,%a1,%0); + } + } + + if (REG_P (operands[2])) + return AS2 (sal%L0,%b2,%0); + + if (REG_P (operands[0]) && operands[2] == const1_rtx) + return AS2 (add%L0,%0,%0); + + return AS2 (sal%L0,%2,%0); +}") + +(define_insn "ashlhi3" + [(set (match_operand:HI 0 "general_operand" "=rm") + (ashift:HI (match_operand:HI 1 "general_operand" "0") + (match_operand:HI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (sal%W0,%b2,%0); + + if (REG_P (operands[0]) && operands[2] == const1_rtx) + return AS2 (add%W0,%0,%0); + + return AS2 (sal%W0,%2,%0); +}") + +(define_insn "ashlqi3" + [(set (match_operand:QI 0 "general_operand" "=qm") + (ashift:QI (match_operand:QI 1 "general_operand" "0") + (match_operand:QI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (sal%B0,%b2,%0); + + if (REG_P (operands[0]) && operands[2] == const1_rtx) + return AS2 (add%B0,%0,%0); + + return AS2 (sal%B0,%2,%0); +}") + +;; See comment above `ashldi3' about how this works. + +(define_expand "ashrdi3" + [(set (match_operand:DI 0 "register_operand" "") + (ashiftrt:DI (match_operand:DI 1 "register_operand" "") + (match_operand:QI 2 "nonmemory_operand" "")))] + "" + " +{ + if (GET_CODE (operands[2]) != CONST_INT + || ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')) + { + operands[2] = copy_to_mode_reg (QImode, operands[2]); + emit_insn (gen_ashrdi3_non_const_int (operands[0], operands[1], + operands[2])); + } + else + emit_insn (gen_ashrdi3_const_int (operands[0], operands[1], operands[2])); + + DONE; +}") + +(define_insn "ashrdi3_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (ashiftrt:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "const_int_operand" "J")))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + if (INTVAL (xops[0]) > 31) + { + xops[1] = GEN_INT (31); + output_asm_insn (AS2 (mov%L2,%3,%2), xops); + output_asm_insn (AS2 (sar%L3,%1,%3), xops); /* shift by 32 */ + + if (INTVAL (xops[0]) > 32) + { + xops[0] = GEN_INT (INTVAL (xops[0]) - 32); + output_asm_insn (AS2 (sar%L2,%0,%2), xops); /* Remaining shift */ + } + } + else + { + output_asm_insn (AS3 (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (sar%L3,%0,%3), xops); + } + + RET; +}") + +(define_insn "ashrdi3_non_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (ashiftrt:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "register_operand" "c"))) + (clobber (match_dup 2))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + output_asm_insn (AS2 (ror%B0,%1,%0), xops); /* shift count / 2 */ + + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (sar%L3,%0,%3), xops); + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (sar%L3,%0,%3), xops); + + xops[1] = GEN_INT (7); /* shift count & 1 */ + + output_asm_insn (AS2 (shr%B0,%1,%0), xops); + + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (sar%L3,%0,%3), xops); + + RET; +}") + +(define_insn "ashrsi3" + [(set (match_operand:SI 0 "general_operand" "=rm") + (ashiftrt:SI (match_operand:SI 1 "general_operand" "0") + (match_operand:SI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (sar%L0,%b2,%0); + else + return AS2 (sar%L0,%2,%0); +}") + +(define_insn "ashrhi3" + [(set (match_operand:HI 0 "general_operand" "=rm") + (ashiftrt:HI (match_operand:HI 1 "general_operand" "0") + (match_operand:HI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (sar%W0,%b2,%0); + else + return AS2 (sar%W0,%2,%0); +}") + +(define_insn "ashrqi3" + [(set (match_operand:QI 0 "general_operand" "=qm") + (ashiftrt:QI (match_operand:QI 1 "general_operand" "0") + (match_operand:QI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (sar%B0,%b2,%0); + else + return AS2 (sar%B0,%2,%0); +}") + +;;- logical shift instructions + +;; See comment above `ashldi3' about how this works. + +(define_expand "lshrdi3" + [(set (match_operand:DI 0 "register_operand" "") + (lshiftrt:DI (match_operand:DI 1 "register_operand" "") + (match_operand:QI 2 "nonmemory_operand" "")))] + "" + " +{ + if (GET_CODE (operands[2]) != CONST_INT + || ! CONST_OK_FOR_LETTER_P (INTVAL (operands[2]), 'J')) + { + operands[2] = copy_to_mode_reg (QImode, operands[2]); + emit_insn (gen_lshrdi3_non_const_int (operands[0], operands[1], + operands[2])); + } + else + emit_insn (gen_lshrdi3_const_int (operands[0], operands[1], operands[2])); + + DONE; +}") + +(define_insn "lshrdi3_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (lshiftrt:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "const_int_operand" "J")))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + if (INTVAL (xops[0]) > 31) + { + output_asm_insn (AS2 (mov%L2,%3,%2), xops); /* Fast shift by 32 */ + output_asm_insn (AS2 (xor%L3,%3,%3), xops); + + if (INTVAL (xops[0]) > 32) + { + xops[0] = GEN_INT (INTVAL (xops[0]) - 32); + output_asm_insn (AS2 (shr%L2,%0,%2), xops); /* Remaining shift */ + } + } + else + { + output_asm_insn (AS3 (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (shr%L3,%0,%3), xops); + } + + RET; +}") + +(define_insn "lshrdi3_non_const_int" + [(set (match_operand:DI 0 "register_operand" "=&r") + (lshiftrt:DI (match_operand:DI 1 "register_operand" "0") + (match_operand:QI 2 "register_operand" "c"))) + (clobber (match_dup 2))] + "" + "* +{ + rtx xops[4], low[1], high[1]; + + CC_STATUS_INIT; + + split_di (operands, 1, low, high); + xops[0] = operands[2]; + xops[1] = const1_rtx; + xops[2] = low[0]; + xops[3] = high[0]; + + output_asm_insn (AS2 (ror%B0,%1,%0), xops); /* shift count / 2 */ + + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (shr%L3,%0,%3), xops); + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (shr%L3,%0,%3), xops); + + xops[1] = GEN_INT (7); /* shift count & 1 */ + + output_asm_insn (AS2 (shr%B0,%1,%0), xops); + + output_asm_insn (AS3_SHIFT_DOUBLE (shrd%L2,%0,%3,%2), xops); + output_asm_insn (AS2 (shr%L3,%0,%3), xops); + + RET; +}") + +(define_insn "lshrsi3" + [(set (match_operand:SI 0 "general_operand" "=rm") + (lshiftrt:SI (match_operand:SI 1 "general_operand" "0") + (match_operand:SI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (shr%L0,%b2,%0); + else + return AS2 (shr%L0,%2,%1); +}") + +(define_insn "lshrhi3" + [(set (match_operand:HI 0 "general_operand" "=rm") + (lshiftrt:HI (match_operand:HI 1 "general_operand" "0") + (match_operand:HI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (shr%W0,%b2,%0); + else + return AS2 (shr%W0,%2,%0); +}") + +(define_insn "lshrqi3" + [(set (match_operand:QI 0 "general_operand" "=qm") + (lshiftrt:QI (match_operand:QI 1 "general_operand" "0") + (match_operand:QI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (shr%B0,%b2,%0); + else + return AS2 (shr%B0,%2,%0); +}") + +;;- rotate instructions + +(define_insn "rotlsi3" + [(set (match_operand:SI 0 "general_operand" "=rm") + (rotate:SI (match_operand:SI 1 "general_operand" "0") + (match_operand:SI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (rol%L0,%b2,%0); + else + return AS2 (rol%L0,%2,%0); +}") + +(define_insn "rotlhi3" + [(set (match_operand:HI 0 "general_operand" "=rm") + (rotate:HI (match_operand:HI 1 "general_operand" "0") + (match_operand:HI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (rol%W0,%b2,%0); + else + return AS2 (rol%W0,%2,%0); +}") + +(define_insn "rotlqi3" + [(set (match_operand:QI 0 "general_operand" "=qm") + (rotate:QI (match_operand:QI 1 "general_operand" "0") + (match_operand:QI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (rol%B0,%b2,%0); + else + return AS2 (rol%B0,%2,%0); +}") + +(define_insn "rotrsi3" + [(set (match_operand:SI 0 "general_operand" "=rm") + (rotatert:SI (match_operand:SI 1 "general_operand" "0") + (match_operand:SI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (ror%L0,%b2,%0); + else + return AS2 (ror%L0,%2,%0); +}") + +(define_insn "rotrhi3" + [(set (match_operand:HI 0 "general_operand" "=rm") + (rotatert:HI (match_operand:HI 1 "general_operand" "0") + (match_operand:HI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (ror%W0,%b2,%0); + else + return AS2 (ror%W0,%2,%0); +}") + +(define_insn "rotrqi3" + [(set (match_operand:QI 0 "general_operand" "=qm") + (rotatert:QI (match_operand:QI 1 "general_operand" "0") + (match_operand:QI 2 "nonmemory_operand" "cI")))] + "" + "* +{ + if (REG_P (operands[2])) + return AS2 (ror%B0,%b2,%0); + else + return AS2 (ror%B0,%2,%0); +}") + +/* +;; This usually looses. But try a define_expand to recognize a few case +;; we can do efficiently, such as accessing the "high" QImode registers, +;; %ah, %bh, %ch, %dh. +(define_insn "insv" + [(set (zero_extract:SI (match_operand:SI 0 "register_operand" "+&r") + (match_operand:SI 1 "general_operand" "i") + (match_operand:SI 2 "general_operand" "i")) + (match_operand:SI 3 "general_operand" "ri"))] + "" + "* +{ + if (INTVAL (operands[1]) + INTVAL (operands[2]) > GET_MODE_BITSIZE (SImode)) + abort (); + if (GET_CODE (operands[3]) == CONST_INT) + { + unsigned int mask = (1 << INTVAL (operands[1])) - 1; + operands[1] = GEN_INT (~(mask << INTVAL (operands[2]))); + output_asm_insn (AS2 (and%L0,%1,%0), operands); + operands[3] = GEN_INT (INTVAL (operands[3]) << INTVAL (operands[2])); + output_asm_insn (AS2 (or%L0,%3,%0), operands); + } + else + { + operands[0] = gen_rtx (REG, SImode, REGNO (operands[0])); + if (INTVAL (operands[2])) + output_asm_insn (AS2 (ror%L0,%2,%0), operands); + output_asm_insn (AS3 (shrd%L0,%1,%3,%0), operands); + operands[2] = GEN_INT (BITS_PER_WORD + - INTVAL (operands[1]) - INTVAL (operands[2])); + if (INTVAL (operands[2])) + output_asm_insn (AS2 (ror%L0,%2,%0), operands); + } + RET; +}") +*/ +/* +;; ??? There are problems with the mode of operand[3]. The point of this +;; is to represent an HImode move to a "high byte" register. + +(define_expand "insv" + [(set (zero_extract:SI (match_operand:SI 0 "general_operand" "") + (match_operand:SI 1 "immediate_operand" "") + (match_operand:SI 2 "immediate_operand" "")) + (match_operand:QI 3 "general_operand" "ri"))] + "" + " +{ + if (GET_CODE (operands[1]) != CONST_INT + || GET_CODE (operands[2]) != CONST_INT) + FAIL; + + if (! (INTVAL (operands[1]) == 8 + && (INTVAL (operands[2]) == 8 || INTVAL (operands[2]) == 0)) + && ! INTVAL (operands[1]) == 1) + FAIL; +}") + +;; ??? Are these constraints right? +(define_insn "" + [(set (zero_extract:SI (match_operand:SI 0 "general_operand" "+&qo") + (const_int 8) + (const_int 8)) + (match_operand:QI 1 "general_operand" "qn"))] + "" + "* +{ + if (REG_P (operands[0])) + return AS2 (mov%B0,%1,%h0); + + operands[0] = adj_offsettable_operand (operands[0], 1); + return AS2 (mov%B0,%1,%0); +}") +*/ + +;; On i386, the register count for a bit operation is *not* truncated, +;; so SHIFT_COUNT_TRUNCATED must not be defined. + +;; On i486, the shift & or/and code is faster than bts or btr. If +;; operands[0] is a MEM, the bt[sr] is half as fast as the normal code. + +;; On i386, bts is a little faster if operands[0] is a reg, and a +;; little slower if operands[0] is a MEM, than the shift & or/and code. +;; Use bts & btr, since they reload better. + +;; General bit set and clear. +(define_insn "" + [(set (zero_extract:SI (match_operand:SI 0 "general_operand" "+rm") + (const_int 1) + (match_operand:SI 2 "general_operand" "r")) + (match_operand:SI 3 "const_int_operand" "n"))] + "TARGET_386 && GET_CODE (operands[2]) != CONST_INT" + "* +{ + CC_STATUS_INIT; + + if (INTVAL (operands[3]) == 1) + return AS2 (bts%L0,%2,%0); + else + return AS2 (btr%L0,%2,%0); +}") + +;; Bit complement. See comments on previous pattern. +;; ??? Is this really worthwhile? +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=rm") + (xor:SI (ashift:SI (const_int 1) + (match_operand:SI 1 "general_operand" "r")) + (match_operand:SI 2 "general_operand" "0")))] + "TARGET_386 && GET_CODE (operands[1]) != CONST_INT" + "* +{ + CC_STATUS_INIT; + + return AS2 (btc%L0,%1,%0); +}") + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=rm") + (xor:SI (match_operand:SI 1 "general_operand" "0") + (ashift:SI (const_int 1) + (match_operand:SI 2 "general_operand" "r"))))] + "TARGET_386 && GET_CODE (operands[2]) != CONST_INT" + "* +{ + CC_STATUS_INIT; + + return AS2 (btc%L0,%2,%0); +}") + +;; Recognizers for bit-test instructions. + +;; The bt opcode allows a MEM in operands[0]. But on both i386 and +;; i486, it is faster to copy a MEM to REG and then use bt, than to use +;; bt on the MEM directly. + +;; ??? The first argument of a zero_extract must not be reloaded, so +;; don't allow a MEM in the operand predicate without allowing it in the +;; constraint. + +(define_insn "" + [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "r") + (const_int 1) + (match_operand:SI 1 "general_operand" "r")))] + "GET_CODE (operands[1]) != CONST_INT" + "* +{ + cc_status.flags |= CC_Z_IN_NOT_C; + return AS2 (bt%L0,%1,%0); +}") + +(define_insn "" + [(set (cc0) (zero_extract (match_operand:SI 0 "register_operand" "r") + (match_operand:SI 1 "const_int_operand" "n") + (match_operand:SI 2 "const_int_operand" "n")))] + "" + "* +{ + unsigned int mask; + + mask = ((1 << INTVAL (operands[1])) - 1) << INTVAL (operands[2]); + operands[1] = GEN_INT (mask); + + if (QI_REG_P (operands[0])) + { + if ((mask & ~0xff) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + return AS2 (test%B0,%1,%b0); + } + + if ((mask & ~0xff00) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (mask >> 8); + return AS2 (test%B0,%1,%h0); + } + } + + return AS2 (test%L0,%1,%0); +}") + +;; ??? All bets are off if operand 0 is a volatile MEM reference. +;; The CPU may access unspecified bytes around the actual target byte. + +(define_insn "" + [(set (cc0) (zero_extract (match_operand:QI 0 "general_operand" "rm") + (match_operand:SI 1 "const_int_operand" "n") + (match_operand:SI 2 "const_int_operand" "n")))] + "GET_CODE (operands[0]) != MEM || ! MEM_VOLATILE_P (operands[0])" + "* +{ + unsigned int mask; + + mask = ((1 << INTVAL (operands[1])) - 1) << INTVAL (operands[2]); + operands[1] = GEN_INT (mask); + + if (! REG_P (operands[0]) || QI_REG_P (operands[0])) + { + if ((mask & ~0xff) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + return AS2 (test%B0,%1,%b0); + } + + if ((mask & ~0xff00) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (mask >> 8); + + if (QI_REG_P (operands[0])) + return AS2 (test%B0,%1,%h0); + else + { + operands[0] = adj_offsettable_operand (operands[0], 1); + return AS2 (test%B0,%1,%b0); + } + } + + if (GET_CODE (operands[0]) == MEM && (mask & ~0xff0000) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (mask >> 16); + operands[0] = adj_offsettable_operand (operands[0], 2); + return AS2 (test%B0,%1,%b0); + } + + if (GET_CODE (operands[0]) == MEM && (mask & ~0xff000000) == 0) + { + cc_status.flags |= CC_NOT_NEGATIVE; + operands[1] = GEN_INT (mask >> 24); + operands[0] = adj_offsettable_operand (operands[0], 3); + return AS2 (test%B0,%1,%b0); + } + } + + if (CONSTANT_P (operands[1]) || GET_CODE (operands[0]) == MEM) + return AS2 (test%L0,%1,%0); + + return AS2 (test%L1,%0,%1); +}") + +;; Store-flag instructions. + +;; For all sCOND expanders, also expand the compare or test insn that +;; generates cc0. Generate an equality comparison if `seq' or `sne'. + +;; The 386 sCOND opcodes can write to memory. But a gcc sCOND insn may +;; not have any input reloads. A MEM write might need an input reload +;; for the address of the MEM. So don't allow MEM as the SET_DEST. + +(define_expand "seq" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (eq:QI (cc0) (const_int 0)))] + "" + " +{ + if (TARGET_IEEE_FP + && GET_MODE_CLASS (GET_MODE (i386_compare_op0)) == MODE_FLOAT) + operands[1] = (*i386_compare_gen_eq)(i386_compare_op0, i386_compare_op1); + else + operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1); +}") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (eq:QI (cc0) (const_int 0)))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return AS1 (setnb,%0); + else + return AS1 (sete,%0); +}") + +(define_expand "sne" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (ne:QI (cc0) (const_int 0)))] + "" + " +{ + if (TARGET_IEEE_FP + && GET_MODE_CLASS (GET_MODE (i386_compare_op0)) == MODE_FLOAT) + operands[1] = (*i386_compare_gen_eq)(i386_compare_op0, i386_compare_op1); + else + operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1); +}") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (ne:QI (cc0) (const_int 0)))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return AS1 (setb,%0); + else + return AS1 (setne,%0); +} +") + +(define_expand "sgt" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (gt:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (gt:QI (cc0) (const_int 0)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (sete,%0); + + OUTPUT_JUMP (\"setg %0\", \"seta %0\", NULL_PTR); +}") + +(define_expand "sgtu" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (gtu:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (gtu:QI (cc0) (const_int 0)))] + "" + "* return \"seta %0\"; ") + +(define_expand "slt" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (lt:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (lt:QI (cc0) (const_int 0)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (sete,%0); + + OUTPUT_JUMP (\"setl %0\", \"setb %0\", \"sets %0\"); +}") + +(define_expand "sltu" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (ltu:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (ltu:QI (cc0) (const_int 0)))] + "" + "* return \"setb %0\"; ") + +(define_expand "sge" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (ge:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (ge:QI (cc0) (const_int 0)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (sete,%0); + + OUTPUT_JUMP (\"setge %0\", \"setae %0\", \"setns %0\"); +}") + +(define_expand "sgeu" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (geu:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (geu:QI (cc0) (const_int 0)))] + "" + "* return \"setae %0\"; ") + +(define_expand "sle" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (le:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (le:QI (cc0) (const_int 0)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (setb,%0); + + OUTPUT_JUMP (\"setle %0\", \"setbe %0\", NULL_PTR); +}") + +(define_expand "sleu" + [(match_dup 1) + (set (match_operand:QI 0 "register_operand" "") + (leu:QI (cc0) (const_int 0)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (match_operand:QI 0 "register_operand" "=q") + (leu:QI (cc0) (const_int 0)))] + "" + "* return \"setbe %0\"; ") + +;; Basic conditional jump instructions. +;; We ignore the overflow flag for signed branch instructions. + +;; For all bCOND expanders, also expand the compare or test insn that +;; generates cc0. Generate an equality comparison if `beq' or `bne'. + +(define_expand "beq" + [(match_dup 1) + (set (pc) + (if_then_else (eq (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + " +{ + if (TARGET_IEEE_FP + && GET_MODE_CLASS (GET_MODE (i386_compare_op0)) == MODE_FLOAT) + operands[1] = (*i386_compare_gen_eq)(i386_compare_op0, i386_compare_op1); + else + operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1); +}") + +(define_insn "" + [(set (pc) + (if_then_else (eq (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return \"jnc %l0\"; + else + return \"je %l0\"; +}") + +(define_expand "bne" + [(match_dup 1) + (set (pc) + (if_then_else (ne (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + " +{ + if (TARGET_IEEE_FP + && GET_MODE_CLASS (GET_MODE (i386_compare_op0)) == MODE_FLOAT) + operands[1] = (*i386_compare_gen_eq)(i386_compare_op0, i386_compare_op1); + else + operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1); +}") + +(define_insn "" + [(set (pc) + (if_then_else (ne (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return \"jc %l0\"; + else + return \"jne %l0\"; +}") + +(define_expand "bgt" + [(match_dup 1) + (set (pc) + (if_then_else (gt (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (gt (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (je,%l0); + + OUTPUT_JUMP (\"jg %l0\", \"ja %l0\", NULL_PTR); +}") + +(define_expand "bgtu" + [(match_dup 1) + (set (pc) + (if_then_else (gtu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (gtu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "ja %l0") + +(define_expand "blt" + [(match_dup 1) + (set (pc) + (if_then_else (lt (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (lt (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (je,%l0); + + OUTPUT_JUMP (\"jl %l0\", \"jb %l0\", \"js %l0\"); +}") + +(define_expand "bltu" + [(match_dup 1) + (set (pc) + (if_then_else (ltu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (ltu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "jb %l0") + +(define_expand "bge" + [(match_dup 1) + (set (pc) + (if_then_else (ge (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (ge (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (je,%l0); + + OUTPUT_JUMP (\"jge %l0\", \"jae %l0\", \"jns %l0\"); +}") + +(define_expand "bgeu" + [(match_dup 1) + (set (pc) + (if_then_else (geu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (geu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "jae %l0") + +(define_expand "ble" + [(match_dup 1) + (set (pc) + (if_then_else (le (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (le (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (jb,%l0); + + OUTPUT_JUMP (\"jle %l0\", \"jbe %l0\", NULL_PTR); +}") + +(define_expand "bleu" + [(match_dup 1) + (set (pc) + (if_then_else (leu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "operands[1] = (*i386_compare_gen)(i386_compare_op0, i386_compare_op1);") + +(define_insn "" + [(set (pc) + (if_then_else (leu (cc0) + (const_int 0)) + (label_ref (match_operand 0 "" "")) + (pc)))] + "" + "jbe %l0") + +;; Negated conditional jump instructions. + +(define_insn "" + [(set (pc) + (if_then_else (eq (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return \"jc %l0\"; + else + return \"jne %l0\"; +}") + +(define_insn "" + [(set (pc) + (if_then_else (ne (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (cc_prev_status.flags & CC_Z_IN_NOT_C) + return \"jnc %l0\"; + else + return \"je %l0\"; +}") + +(define_insn "" + [(set (pc) + (if_then_else (gt (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (jne,%l0); + + OUTPUT_JUMP (\"jle %l0\", \"jbe %l0\", NULL_PTR); +}") + +(define_insn "" + [(set (pc) + (if_then_else (gtu (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "jbe %l0") + +(define_insn "" + [(set (pc) + (if_then_else (lt (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (jne,%l0); + + OUTPUT_JUMP (\"jge %l0\", \"jae %l0\", \"jns %l0\"); +}") + +(define_insn "" + [(set (pc) + (if_then_else (ltu (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "jae %l0") + +(define_insn "" + [(set (pc) + (if_then_else (ge (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (jne,%l0); + + OUTPUT_JUMP (\"jl %l0\", \"jb %l0\", \"js %l0\"); +}") + +(define_insn "" + [(set (pc) + (if_then_else (geu (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "jb %l0") + +(define_insn "" + [(set (pc) + (if_then_else (le (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "* +{ + if (TARGET_IEEE_FP && (cc_prev_status.flags & CC_IN_80387)) + return AS1 (jae,%l0); + + OUTPUT_JUMP (\"jg %l0\", \"ja %l0\", NULL_PTR); +}") + +(define_insn "" + [(set (pc) + (if_then_else (leu (cc0) + (const_int 0)) + (pc) + (label_ref (match_operand 0 "" ""))))] + "" + "ja %l0") + +;; Unconditional and other jump instructions + +(define_insn "jump" + [(set (pc) + (label_ref (match_operand 0 "" "")))] + "" + "jmp %l0") + +(define_insn "indirect_jump" + [(set (pc) (match_operand:SI 0 "general_operand" "rm"))] + "" + "* +{ + CC_STATUS_INIT; + + return AS1 (jmp,%*%0); +}") + +;; ??? could transform while(--i > 0) S; to if (--i > 0) do S; while(--i); +;; if S does not change i + +(define_expand "decrement_and_branch_until_zero" + [(parallel [(set (pc) + (if_then_else (ge (plus:SI (match_operand:SI 0 "general_operand" "") + (const_int -1)) + (const_int 0)) + (label_ref (match_operand 1 "" "")) + (pc))) + (set (match_dup 0) + (plus:SI (match_dup 0) + (const_int -1)))])] + "" + "") + +(define_insn "" + [(set (pc) + (if_then_else (match_operator 0 "arithmetic_comparison_operator" + [(plus:SI (match_operand:SI 1 "general_operand" "+r,m") + (match_operand:SI 2 "general_operand" "rmi,ri")) + (const_int 0)]) + (label_ref (match_operand 3 "" "")) + (pc))) + (set (match_dup 1) + (plus:SI (match_dup 1) + (match_dup 2)))] + "" + "* +{ + CC_STATUS_INIT; + if (operands[2] == constm1_rtx) + output_asm_insn (AS1 (dec%L1,%1), operands); + + else if (operands[1] == const1_rtx) + output_asm_insn (AS1 (inc%L1,%1), operands); + + else + output_asm_insn (AS2 (add%L1,%2,%1), operands); + + return AS1 (%J0,%l3); +}") + +(define_insn "" + [(set (pc) + (if_then_else (match_operator 0 "arithmetic_comparison_operator" + [(minus:SI (match_operand:SI 1 "general_operand" "+r,m") + (match_operand:SI 2 "general_operand" "rmi,ri")) + (const_int 0)]) + (label_ref (match_operand 3 "" "")) + (pc))) + (set (match_dup 1) + (minus:SI (match_dup 1) + (match_dup 2)))] + "" + "* +{ + CC_STATUS_INIT; + if (operands[2] == const1_rtx) + output_asm_insn (AS1 (dec%L1,%1), operands); + + else if (operands[1] == constm1_rtx) + output_asm_insn (AS1 (inc%L1,%1), operands); + + else + output_asm_insn (AS2 (sub%L1,%2,%1), operands); + + return AS1 (%J0,%l3); +}") + +;; Implement switch statements when generating PIC code. Switches are +;; implemented by `tablejump' when not using -fpic. + +;; Emit code here to do the range checking and make the index zero based. + +(define_expand "casesi" + [(set (match_dup 5) + (minus:SI (match_operand:SI 0 "general_operand" "") + (match_operand:SI 1 "general_operand" ""))) + (set (cc0) + (compare:CC (match_dup 5) + (match_operand:SI 2 "general_operand" ""))) + (set (pc) + (if_then_else (gtu (cc0) + (const_int 0)) + (label_ref (match_operand 4 "" "")) + (pc))) + (parallel + [(set (pc) + (minus:SI (reg:SI 3) + (mem:SI (plus:SI (mult:SI (match_dup 5) + (const_int 4)) + (label_ref (match_operand 3 "" "")))))) + (clobber (match_scratch:SI 6 ""))])] + "flag_pic" + " +{ + operands[5] = gen_reg_rtx (SImode); + current_function_uses_pic_offset_table = 1; +}") + +;; Implement a casesi insn. + +;; Each entry in the "addr_diff_vec" looks like this as the result of the +;; two rules below: +;; +;; .long _GLOBAL_OFFSET_TABLE_+[.-.L2] +;; +;; 1. An expression involving an external reference may only use the +;; addition operator, and only with an assembly-time constant. +;; The example above satisfies this because ".-.L2" is a constant. +;; +;; 2. The symbol _GLOBAL_OFFSET_TABLE_ is magic, and at link time is +;; given the value of "GOT - .", where GOT is the actual address of +;; the Global Offset Table. Therefore, the .long above actually +;; stores the value "( GOT - . ) + [ . - .L2 ]", or "GOT - .L2". The +;; expression "GOT - .L2" by itself would generate an error from as(1). +;; +;; The pattern below emits code that looks like this: +;; +;; movl %ebx,reg +;; subl TABLE@GOTOFF(%ebx,index,4),reg +;; jmp reg +;; +;; The addr_diff_vec contents may be directly referenced with @GOTOFF, since +;; the addr_diff_vec is known to be part of this module. +;; +;; The subl above calculates "GOT - (( GOT - . ) + [ . - .L2 ])", which +;; evaluates to just ".L2". + +(define_insn "" + [(set (pc) + (minus:SI (reg:SI 3) + (mem:SI (plus:SI + (mult:SI (match_operand:SI 0 "register_operand" "r") + (const_int 4)) + (label_ref (match_operand 1 "" "")))))) + (clobber (match_scratch:SI 2 "=&r"))] + "" + "* +{ + rtx xops[4]; + + xops[0] = operands[0]; + xops[1] = operands[1]; + xops[2] = operands[2]; + xops[3] = pic_offset_table_rtx; + + output_asm_insn (AS2 (mov%L2,%3,%2), xops); + output_asm_insn (\"sub%L2 %l1@GOTOFF(%3,%0,4),%2\", xops); + output_asm_insn (AS1 (jmp,%*%2), xops); + ASM_OUTPUT_ALIGN_CODE (asm_out_file); + RET; +}") + +(define_insn "tablejump" + [(set (pc) (match_operand:SI 0 "general_operand" "rm")) + (use (label_ref (match_operand 1 "" "")))] + "" + "* +{ + CC_STATUS_INIT; + + return AS1 (jmp,%*%0); +}") + +;; Call insns. + +;; If generating PIC code, the predicate indirect_operand will fail +;; for operands[0] containing symbolic references on all of the named +;; call* patterns. Each named pattern is followed by an unnamed pattern +;; that matches any call to a symbolic CONST (ie, a symbol_ref). The +;; unnamed patterns are only used while generating PIC code, because +;; otherwise the named patterns match. + +;; Call subroutine returning no value. + +(define_expand "call_pop" + [(parallel [(call (match_operand:QI 0 "indirect_operand" "") + (match_operand:SI 1 "general_operand" "")) + (set (reg:SI 7) + (plus:SI (reg:SI 7) + (match_operand:SI 3 "immediate_operand" "")))])] + "" + " +{ + rtx addr; + + if (flag_pic) + current_function_uses_pic_offset_table = 1; + + /* With half-pic, force the address into a register. */ + addr = XEXP (operands[0], 0); + if (GET_CODE (addr) != REG && HALF_PIC_P () && !CONSTANT_ADDRESS_P (addr)) + XEXP (operands[0], 0) = force_reg (Pmode, addr); + + if (! expander_call_insn_operand (operands[0], QImode)) + operands[0] + = change_address (operands[0], VOIDmode, + copy_to_mode_reg (Pmode, XEXP (operands[0], 0))); +}") + +(define_insn "" + [(call (match_operand:QI 0 "call_insn_operand" "m") + (match_operand:SI 1 "general_operand" "g")) + (set (reg:SI 7) (plus:SI (reg:SI 7) + (match_operand:SI 3 "immediate_operand" "i")))] + "" + "* +{ + if (GET_CODE (operands[0]) == MEM + && ! CONSTANT_ADDRESS_P (XEXP (operands[0], 0))) + { + operands[0] = XEXP (operands[0], 0); + return AS1 (call,%*%0); + } + else + return AS1 (call,%P0); +}") + +(define_insn "" + [(call (mem:QI (match_operand:SI 0 "symbolic_operand" "")) + (match_operand:SI 1 "general_operand" "g")) + (set (reg:SI 7) (plus:SI (reg:SI 7) + (match_operand:SI 3 "immediate_operand" "i")))] + "!HALF_PIC_P ()" + "call %P0") + +(define_expand "call" + [(call (match_operand:QI 0 "indirect_operand" "") + (match_operand:SI 1 "general_operand" ""))] + ;; Operand 1 not used on the i386. + "" + " +{ + rtx addr; + + if (flag_pic) + current_function_uses_pic_offset_table = 1; + + /* With half-pic, force the address into a register. */ + addr = XEXP (operands[0], 0); + if (GET_CODE (addr) != REG && HALF_PIC_P () && !CONSTANT_ADDRESS_P (addr)) + XEXP (operands[0], 0) = force_reg (Pmode, addr); + + if (! expander_call_insn_operand (operands[0], QImode)) + operands[0] + = change_address (operands[0], VOIDmode, + copy_to_mode_reg (Pmode, XEXP (operands[0], 0))); +}") + +(define_insn "" + [(call (match_operand:QI 0 "call_insn_operand" "m") + (match_operand:SI 1 "general_operand" "g"))] + ;; Operand 1 not used on the i386. + "" + "* +{ + if (GET_CODE (operands[0]) == MEM + && ! CONSTANT_ADDRESS_P (XEXP (operands[0], 0))) + { + operands[0] = XEXP (operands[0], 0); + return AS1 (call,%*%0); + } + else + return AS1 (call,%P0); +}") + +(define_insn "" + [(call (mem:QI (match_operand:SI 0 "symbolic_operand" "")) + (match_operand:SI 1 "general_operand" "g"))] + ;; Operand 1 not used on the i386. + "!HALF_PIC_P ()" + "call %P0") + +;; Call subroutine, returning value in operand 0 +;; (which must be a hard register). + +(define_expand "call_value_pop" + [(parallel [(set (match_operand 0 "" "") + (call (match_operand:QI 1 "indirect_operand" "") + (match_operand:SI 2 "general_operand" ""))) + (set (reg:SI 7) + (plus:SI (reg:SI 7) + (match_operand:SI 4 "immediate_operand" "")))])] + "" + " +{ + rtx addr; + + if (flag_pic) + current_function_uses_pic_offset_table = 1; + + /* With half-pic, force the address into a register. */ + addr = XEXP (operands[1], 0); + if (GET_CODE (addr) != REG && HALF_PIC_P () && !CONSTANT_ADDRESS_P (addr)) + XEXP (operands[1], 0) = force_reg (Pmode, addr); + + if (! expander_call_insn_operand (operands[1], QImode)) + operands[1] + = change_address (operands[1], VOIDmode, + copy_to_mode_reg (Pmode, XEXP (operands[1], 0))); +}") + +(define_insn "" + [(set (match_operand 0 "" "=rf") + (call (match_operand:QI 1 "call_insn_operand" "m") + (match_operand:SI 2 "general_operand" "g"))) + (set (reg:SI 7) (plus:SI (reg:SI 7) + (match_operand:SI 4 "immediate_operand" "i")))] + "" + "* +{ + if (GET_CODE (operands[1]) == MEM + && ! CONSTANT_ADDRESS_P (XEXP (operands[1], 0))) + { + operands[1] = XEXP (operands[1], 0); + output_asm_insn (AS1 (call,%*%1), operands); + } + else + output_asm_insn (AS1 (call,%P1), operands); + + RET; +}") + +(define_insn "" + [(set (match_operand 0 "" "=rf") + (call (mem:QI (match_operand:SI 1 "symbolic_operand" "")) + (match_operand:SI 2 "general_operand" "g"))) + (set (reg:SI 7) (plus:SI (reg:SI 7) + (match_operand:SI 4 "immediate_operand" "i")))] + "!HALF_PIC_P ()" + "call %P1") + +(define_expand "call_value" + [(set (match_operand 0 "" "") + (call (match_operand:QI 1 "indirect_operand" "") + (match_operand:SI 2 "general_operand" "")))] + ;; Operand 2 not used on the i386. + "" + " +{ + rtx addr; + + if (flag_pic) + current_function_uses_pic_offset_table = 1; + + /* With half-pic, force the address into a register. */ + addr = XEXP (operands[1], 0); + if (GET_CODE (addr) != REG && HALF_PIC_P () && !CONSTANT_ADDRESS_P (addr)) + XEXP (operands[1], 0) = force_reg (Pmode, addr); + + if (! expander_call_insn_operand (operands[1], QImode)) + operands[1] + = change_address (operands[1], VOIDmode, + copy_to_mode_reg (Pmode, XEXP (operands[1], 0))); +}") + +(define_insn "" + [(set (match_operand 0 "" "=rf") + (call (match_operand:QI 1 "call_insn_operand" "m") + (match_operand:SI 2 "general_operand" "g")))] + ;; Operand 2 not used on the i386. + "" + "* +{ + if (GET_CODE (operands[1]) == MEM + && ! CONSTANT_ADDRESS_P (XEXP (operands[1], 0))) + { + operands[1] = XEXP (operands[1], 0); + output_asm_insn (AS1 (call,%*%1), operands); + } + else + output_asm_insn (AS1 (call,%P1), operands); + + RET; +}") + +(define_insn "" + [(set (match_operand 0 "" "=rf") + (call (mem:QI (match_operand:SI 1 "symbolic_operand" "")) + (match_operand:SI 2 "general_operand" "g")))] + ;; Operand 2 not used on the i386. + "!HALF_PIC_P ()" + "call %P1") + +;; Call subroutine returning any type. + +(define_expand "untyped_call" + [(parallel [(call (match_operand 0 "" "") + (const_int 0)) + (match_operand 1 "" "") + (match_operand 2 "" "")])] + "" + " +{ + int i; + + /* In order to give reg-stack an easier job in validating two + coprocessor registers as containing a possible return value, + simply pretend the untyped call returns a complex long double + value. */ + emit_call_insn (TARGET_80387 + ? gen_call_value (gen_rtx (REG, XCmode, FIRST_FLOAT_REG), + operands[0], const0_rtx) + : gen_call (operands[0], const0_rtx)); + + for (i = 0; i < XVECLEN (operands[2], 0); i++) + { + rtx set = XVECEXP (operands[2], 0, i); + emit_move_insn (SET_DEST (set), SET_SRC (set)); + } + + /* The optimizer does not know that the call sets the function value + registers we stored in the result block. We avoid problems by + claiming that all hard registers are used and clobbered at this + point. */ + emit_insn (gen_blockage ()); + + DONE; +}") + +;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and +;; all of memory. This blocks insns from being moved across this point. + +(define_insn "blockage" + [(unspec_volatile [(const_int 0)] 0)] + "" + "") + +;; Insn emitted into the body of a function to return from a function. +;; This is only done if the function's epilogue is known to be simple. +;; See comments for simple_386_epilogue in i386.c. + +(define_insn "return" + [(return)] + "simple_386_epilogue ()" + "* +{ + function_epilogue (asm_out_file, get_frame_size ()); + RET; +}") + +(define_insn "nop" + [(const_int 0)] + "" + "nop") + +(define_expand "movstrsi" + [(parallel [(set (match_operand:BLK 0 "memory_operand" "") + (match_operand:BLK 1 "memory_operand" "")) + (use (match_operand:SI 2 "const_int_operand" "")) + (use (match_operand:SI 3 "const_int_operand" "")) + (clobber (match_scratch:SI 4 "")) + (clobber (match_dup 5)) + (clobber (match_dup 6))])] + "" + " +{ + rtx addr0, addr1; + + if (GET_CODE (operands[2]) != CONST_INT) + FAIL; + + addr0 = copy_to_mode_reg (Pmode, XEXP (operands[0], 0)); + addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0)); + + operands[5] = addr0; + operands[6] = addr1; + + operands[0] = gen_rtx (MEM, BLKmode, addr0); + operands[1] = gen_rtx (MEM, BLKmode, addr1); +}") + +;; It might seem that operands 0 & 1 could use predicate register_operand. +;; But strength reduction might offset the MEM expression. So we let +;; reload put the address into %edi & %esi. + +(define_insn "" + [(set (mem:BLK (match_operand:SI 0 "address_operand" "D")) + (mem:BLK (match_operand:SI 1 "address_operand" "S"))) + (use (match_operand:SI 2 "const_int_operand" "n")) + (use (match_operand:SI 3 "immediate_operand" "i")) + (clobber (match_scratch:SI 4 "=&c")) + (clobber (match_dup 0)) + (clobber (match_dup 1))] + "" + "* +{ + rtx xops[2]; + + output_asm_insn (\"cld\", operands); + if (GET_CODE (operands[2]) == CONST_INT) + { + if (INTVAL (operands[2]) & ~0x03) + { + xops[0] = GEN_INT ((INTVAL (operands[2]) >> 2) & 0x3fffffff); + xops[1] = operands[4]; + + output_asm_insn (AS2 (mov%L1,%0,%1), xops); +#ifdef INTEL_SYNTAX + output_asm_insn (\"rep movsd\", xops); +#else + output_asm_insn (\"rep\;movsl\", xops); +#endif + } + if (INTVAL (operands[2]) & 0x02) + output_asm_insn (\"movsw\", operands); + if (INTVAL (operands[2]) & 0x01) + output_asm_insn (\"movsb\", operands); + } + else + abort (); + RET; +}") + +(define_expand "cmpstrsi" + [(parallel [(set (match_operand:SI 0 "general_operand" "") + (compare:SI (match_operand:BLK 1 "general_operand" "") + (match_operand:BLK 2 "general_operand" ""))) + (use (match_operand:SI 3 "general_operand" "")) + (use (match_operand:SI 4 "immediate_operand" "")) + (clobber (match_dup 5)) + (clobber (match_dup 6)) + (clobber (match_dup 3))])] + "" + " +{ + rtx addr1, addr2; + + addr1 = copy_to_mode_reg (Pmode, XEXP (operands[1], 0)); + addr2 = copy_to_mode_reg (Pmode, XEXP (operands[2], 0)); + operands[3] = copy_to_mode_reg (SImode, operands[3]); + + operands[5] = addr1; + operands[6] = addr2; + + operands[1] = gen_rtx (MEM, BLKmode, addr1); + operands[2] = gen_rtx (MEM, BLKmode, addr2); + +}") + +;; memcmp recognizers. The `cmpsb' opcode does nothing if the count is +;; zero. Emit extra code to make sure that a zero-length compare is EQ. + +;; It might seem that operands 0 & 1 could use predicate register_operand. +;; But strength reduction might offset the MEM expression. So we let +;; reload put the address into %edi & %esi. + +;; ??? Most comparisons have a constant length, and it's therefore +;; possible to know that the length is non-zero, and to avoid the extra +;; code to handle zero-length compares. + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=&r") + (compare:SI (mem:BLK (match_operand:SI 1 "address_operand" "S")) + (mem:BLK (match_operand:SI 2 "address_operand" "D")))) + (use (match_operand:SI 3 "register_operand" "c")) + (use (match_operand:SI 4 "immediate_operand" "i")) + (clobber (match_dup 1)) + (clobber (match_dup 2)) + (clobber (match_dup 3))] + "" + "* +{ + rtx xops[4], label; + + label = gen_label_rtx (); + + output_asm_insn (\"cld\", operands); + output_asm_insn (AS2 (xor%L0,%0,%0), operands); + output_asm_insn (\"repz\;cmps%B2\", operands); + output_asm_insn (\"je %l0\", &label); + + xops[0] = operands[0]; + xops[1] = gen_rtx (MEM, QImode, + gen_rtx (PLUS, SImode, operands[1], constm1_rtx)); + xops[2] = gen_rtx (MEM, QImode, + gen_rtx (PLUS, SImode, operands[2], constm1_rtx)); + xops[3] = operands[3]; + + output_asm_insn (AS2 (movz%B1%L0,%1,%0), xops); + output_asm_insn (AS2 (movz%B2%L3,%2,%3), xops); + + output_asm_insn (AS2 (sub%L0,%3,%0), xops); + ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, \"L\", CODE_LABEL_NUMBER (label)); + RET; +}") + +(define_insn "" + [(set (cc0) + (compare:SI (mem:BLK (match_operand:SI 0 "address_operand" "S")) + (mem:BLK (match_operand:SI 1 "address_operand" "D")))) + (use (match_operand:SI 2 "register_operand" "c")) + (use (match_operand:SI 3 "immediate_operand" "i")) + (clobber (match_dup 0)) + (clobber (match_dup 1)) + (clobber (match_dup 2))] + "" + "* +{ + rtx xops[2]; + + cc_status.flags |= CC_NOT_SIGNED; + + xops[0] = gen_rtx (REG, QImode, 0); + xops[1] = CONST0_RTX (QImode); + + output_asm_insn (\"cld\", operands); + output_asm_insn (AS2 (test%B0,%1,%0), xops); + return \"repz\;cmps%B2\"; +}") + +(define_expand "ffssi2" + [(set (match_dup 2) + (plus:SI (ffs:SI (match_operand:SI 1 "general_operand" "")) + (const_int -1))) + (set (match_operand:SI 0 "general_operand" "") + (plus:SI (match_dup 2) (const_int 1)))] + "" + "operands[2] = gen_reg_rtx (SImode);") + +;; Note, you cannot optimize away the branch following the bsfl by assuming +;; that the destination is not modified if the input is 0, since not all +;; x86 implementations do this. + +(define_insn "" + [(set (match_operand:SI 0 "general_operand" "=&r") + (plus:SI (ffs:SI (match_operand:SI 1 "general_operand" "rm")) + (const_int -1)))] + "" + "* +{ + rtx xops[3]; + static int ffssi_label_number; + char buffer[30]; + + xops[0] = operands[0]; + xops[1] = operands[1]; + xops[2] = constm1_rtx; + output_asm_insn (AS2 (bsf%L0,%1,%0), xops); +#ifdef LOCAL_LABEL_PREFIX + sprintf (buffer, \"jnz %sLFFSSI%d\", + LOCAL_LABEL_PREFIX, ffssi_label_number); +#else + sprintf (buffer, \"jnz %sLFFSSI%d\", + \"\", ffssi_label_number); +#endif + output_asm_insn (buffer, xops); + output_asm_insn (AS2 (mov%L0,%2,%0), xops); +#ifdef LOCAL_LABEL_PREFIX + sprintf (buffer, \"%sLFFSSI%d:\", + LOCAL_LABEL_PREFIX, ffssi_label_number); +#else + sprintf (buffer, \"%sLFFSSI%d:\", + \"\", ffssi_label_number); +#endif + output_asm_insn (buffer, xops); + + ffssi_label_number++; + return \"\"; +}") + +(define_expand "ffshi2" + [(set (match_dup 2) + (plus:HI (ffs:HI (match_operand:HI 1 "general_operand" "")) + (const_int -1))) + (set (match_operand:HI 0 "general_operand" "") + (plus:HI (match_dup 2) (const_int 1)))] + "" + "operands[2] = gen_reg_rtx (HImode);") + +(define_insn "" + [(set (match_operand:HI 0 "general_operand" "=&r") + (plus:HI (ffs:HI (match_operand:SI 1 "general_operand" "rm")) + (const_int -1)))] + "" + "* +{ + rtx xops[3]; + static int ffshi_label_number; + char buffer[30]; + + xops[0] = operands[0]; + xops[1] = operands[1]; + xops[2] = constm1_rtx; + output_asm_insn (AS2 (bsf%W0,%1,%0), xops); +#ifdef LOCAL_LABEL_PREFIX + sprintf (buffer, \"jnz %sLFFSHI%d\", + LOCAL_LABEL_PREFIX, ffshi_label_number); +#else + sprintf (buffer, \"jnz %sLFFSHI%d\", + \"\", ffshi_label_number); +#endif + output_asm_insn (buffer, xops); + output_asm_insn (AS2 (mov%W0,%2,%0), xops); +#ifdef LOCAL_LABEL_PREFIX + sprintf (buffer, \"%sLFFSHI%d:\", + LOCAL_LABEL_PREFIX, ffshi_label_number); +#else + sprintf (buffer, \"%sLFFSHI%d:\", + \"\", ffshi_label_number); +#endif + output_asm_insn (buffer, xops); + + ffshi_label_number++; + return \"\"; +}") + +;; These patterns match the binary 387 instructions for addM3, subM3, +;; mulM3 and divM3. There are three patterns for each of DFmode and +;; SFmode. The first is the normal insn, the second the same insn but +;; with one operand a conversion, and the third the same insn but with +;; the other operand a conversion. The conversion may be SFmode or +;; SImode if the target mode DFmode, but only SImode if the target mode +;; is SFmode. + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f,f") + (match_operator:DF 3 "binary_387_op" + [(match_operand:DF 1 "nonimmediate_operand" "0,fm") + (match_operand:DF 2 "nonimmediate_operand" "fm,0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (match_operator:DF 3 "binary_387_op" + [(float:DF (match_operand:SI 1 "general_operand" "rm")) + (match_operand:DF 2 "general_operand" "0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f,f") + (match_operator:XF 3 "binary_387_op" + [(match_operand:XF 1 "nonimmediate_operand" "0,f") + (match_operand:XF 2 "nonimmediate_operand" "f,0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (match_operator:XF 3 "binary_387_op" + [(float:XF (match_operand:SI 1 "general_operand" "rm")) + (match_operand:XF 2 "general_operand" "0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f,f") + (match_operator:XF 3 "binary_387_op" + [(float_extend:XF (match_operand:SF 1 "general_operand" "fm,0")) + (match_operand:XF 2 "general_operand" "0,f")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f") + (match_operator:XF 3 "binary_387_op" + [(match_operand:XF 1 "general_operand" "0") + (float:XF (match_operand:SI 2 "general_operand" "rm"))]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:XF 0 "register_operand" "=f,f") + (match_operator:XF 3 "binary_387_op" + [(match_operand:XF 1 "general_operand" "0,f") + (float_extend:XF + (match_operand:SF 2 "general_operand" "fm,0"))]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f,f") + (match_operator:DF 3 "binary_387_op" + [(float_extend:DF (match_operand:SF 1 "general_operand" "fm,0")) + (match_operand:DF 2 "general_operand" "0,f")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f") + (match_operator:DF 3 "binary_387_op" + [(match_operand:DF 1 "general_operand" "0") + (float:DF (match_operand:SI 2 "general_operand" "rm"))]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:DF 0 "register_operand" "=f,f") + (match_operator:DF 3 "binary_387_op" + [(match_operand:DF 1 "general_operand" "0,f") + (float_extend:DF + (match_operand:SF 2 "general_operand" "fm,0"))]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:SF 0 "register_operand" "=f,f") + (match_operator:SF 3 "binary_387_op" + [(match_operand:SF 1 "nonimmediate_operand" "0,fm") + (match_operand:SF 2 "nonimmediate_operand" "fm,0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:SF 0 "register_operand" "=f") + (match_operator:SF 3 "binary_387_op" + [(float:SF (match_operand:SI 1 "general_operand" "rm")) + (match_operand:SF 2 "general_operand" "0")]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_insn "" + [(set (match_operand:SF 0 "register_operand" "=f") + (match_operator:SF 3 "binary_387_op" + [(match_operand:SF 1 "general_operand" "0") + (float:SF (match_operand:SI 2 "general_operand" "rm"))]))] + "TARGET_80387" + "* return output_387_binary_op (insn, operands);") + +(define_expand "strlensi" + [(parallel [(set (match_dup 4) + (unspec:SI [(mem:BLK (match_operand:BLK 1 "general_operand" "")) + (match_operand:QI 2 "register_operand" "") + (match_operand:SI 3 "immediate_operand" "")] 0)) + (clobber (match_dup 1))]) + (set (match_dup 5) + (not:SI (match_dup 4))) + (set (match_operand:SI 0 "register_operand" "") + (minus:SI (match_dup 5) + (const_int 1)))] + "" + " +{ + operands[1] = copy_to_mode_reg (SImode, XEXP (operands[1], 0)); + operands[4] = gen_reg_rtx (SImode); + operands[5] = gen_reg_rtx (SImode); +}") + +;; It might seem that operands 0 & 1 could use predicate register_operand. +;; But strength reduction might offset the MEM expression. So we let +;; reload put the address into %edi. + +(define_insn "" + [(set (match_operand:SI 0 "register_operand" "=&c") + (unspec:SI [(mem:BLK (match_operand:SI 1 "address_operand" "D")) + (match_operand:QI 2 "register_operand" "a") + (match_operand:SI 3 "immediate_operand" "i")] 0)) + (clobber (match_dup 1))] + "" + "* +{ + rtx xops[2]; + + xops[0] = operands[0]; + xops[1] = constm1_rtx; + output_asm_insn (\"cld\", operands); + output_asm_insn (AS2 (mov%L0,%1,%0), xops); + return \"repnz\;scas%B2\"; +}") diff --git a/contrib/gcc/config/i386/i386iscgas.h b/contrib/gcc/config/i386/i386iscgas.h new file mode 100644 index 00000000000..526fe374e48 --- /dev/null +++ b/contrib/gcc/config/i386/i386iscgas.h @@ -0,0 +1,67 @@ +/* Definitions for Intel 386 running Interactive Unix System V, + producing stabs-in-coff output (using a slightly modified gas). + Specifically, this is for recent versions that support POSIX; + for version 2.0.2, use configuration option i386-sysv instead. */ + +/* Underscores are not used on ISC systems (probably not on any COFF + system), despite the comments in i386/gas.h. If this is not defined, + enquire (for example) will fail to link. --karl@cs.umb.edu */ +#define NO_UNDERSCORES + +/* Mostly like other gas-using systems. */ +#include "i386/gas.h" + +/* But with ISC-specific additions. */ +#include "i386/isc.h" + +/* We do not want to output SDB debugging information. */ + +#undef SDB_DEBUGGING_INFO + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO + + +/* The function `dbxout_init' in dbxout.c omits the first character of + `ltext_label_name' when outputting the main source directory and main + source filename. I don't understand why, but rather than making a + system-independent change there, I override dbxout.c's defaults. + Perhaps it would be better to use ".Ltext0" instead of + `ltext_label_name', but we've already generated the label, so we just + use it here. --karl@cs.umb.edu */ +#define DBX_OUTPUT_MAIN_SOURCE_DIRECTORY(asmfile, cwd) \ + do { fprintf (asmfile, "%s ", ASM_STABS_OP); \ + output_quoted_string (asmfile, cwd); \ + fprintf (asmfile, ",%d,0,0,%s\n", N_SO, ltext_label_name); \ + } while (0) +#define DBX_OUTPUT_MAIN_SOURCE_FILENAME(asmfile, input_file_name) \ + fprintf (asmfile, "%s ", ASM_STABS_OP); \ + output_quoted_string (input_file_name); \ + fprintf (asmfile, ",%d,0,0,%s\n", N_SO, ltext_label_name); \ + text_section (); \ + ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0) + + +/* Because we don't include `svr3.h', we haven't yet defined SIZE_TYPE + and PTRDIFF_TYPE. ISC's definitions don't match GCC's defaults, so: */ + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + + +/* But we can't use crtbegin.o and crtend.o, because gas 1.38.1 doesn't + grok .section. The definitions here are otherwise identical to those + in i386/isc.h. */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!shlib:%{posix:%{pg:mcrtp1.o%s}%{!pg:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}}\ + %{!posix:%{pg:mcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}\ + %{p:-L/lib/libp} %{pg:-L/lib/libp}}}\ + %{shlib:%{posix:crtp1.o%s}%{!posix:crt1.o%s}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtn.o%s" diff --git a/contrib/gcc/config/i386/isc.h b/contrib/gcc/config/i386/isc.h new file mode 100644 index 00000000000..cf8c5f69277 --- /dev/null +++ b/contrib/gcc/config/i386/isc.h @@ -0,0 +1,89 @@ +/* Assembler-independent definitions for an Intel 386 running + Interactive Unix System V. Specifically, this is for recent versions + that support POSIX. */ + +/* Use crt1.o, not crt0.o, as a startup file, and crtn.o as a closing file. */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!shlib:%{posix:%{pg:mcrtp1.o%s}%{!pg:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}}\ + %{Xp:%{pg:mcrtp1.o%s}%{!pg:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}}\ + %{!posix:%{!Xp:%{pg:mcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}\ + %{p:-L/lib/libp} %{pg:-L/lib/libp}}}}\ + %{shlib:%{Xp:crtp1.o%s}%{posix:crtp1.o%s}%{!posix:%{!Xp:crt1.o%s}}}\ + crtbegin.o%s" + +#define ENDFILE_SPEC "crtend.o%s crtn.o%s" + +/* Library spec */ +#undef LIB_SPEC +#define LIB_SPEC "%{shlib:-lc_s} %{posix:-lcposix} %{Xp:-lcposix} -lc -lg" + +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{Xp:-D_POSIX_SOURCE}" + +/* ISC 2.2 uses `char' for `wchar_t'. */ +#undef WCHAR_TYPE +#define WCHAR_TYPE "char" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_UNIT + +#if 0 +/* This is apparently not true: ISC versions up to 3.0, at least, use + the standard calling sequence in which the called function pops the + extra arg. */ +/* caller has to pop the extra argument passed to functions that return + structures. */ + +#undef RETURN_POPS_ARGS +#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \ + (TREE_CODE (FUNTYPE) == IDENTIFIER_NODE ? 0 \ + : (TARGET_RTD \ + && (TYPE_ARG_TYPES (FUNTYPE) == 0 \ + || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (FUNTYPE))) \ + == void_type_node))) ? (SIZE) \ + : 0) +/* On other 386 systems, the last line looks like this: + : (aggregate_value_p (TREE_TYPE (FUNTYPE))) ? GET_MODE_SIZE (Pmode) : 0) */ +#endif + +/* Handle #pragma pack and #pragma weak. */ +#define HANDLE_SYSV_PRAGMA + +/* By default, target has a 80387, uses IEEE compatible arithmetic, + and returns float values in the 387, ie, + (TARGET_80387 | TARGET_FLOAT_RETURNS_IN_80387) + + ISC's software emulation of a 387 fails to handle the `fucomp' + opcode. fucomp is only used when generating IEEE compliant code. + So don't make TARGET_IEEE_FP default for ISC. */ + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT 0201 + +/* The ISC 2.0.2 software FPU emulator apparently can't handle + 80-bit XFmode insns, so don't generate them. */ +#undef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE 64 + +/* The ISC assembler does not like a .file directive with a name + longer than 14 characters. Truncating it will not permit + debugging to work properly, but at least we won't get an error + message. */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { \ + char c; \ + int max = 0; \ + char *string = dump_base_name; \ + \ + fputs ("\t.file\t\"", FILE); \ + \ + while ((c = *string++) != 0 && max++ < 14) { \ + if (c == '\"' || c == '\\') \ + putc ('\\', FILE); \ + putc (c, FILE); \ + } \ + fputs ("\"\n", FILE); \ + } while (0) diff --git a/contrib/gcc/config/i386/isccoff.h b/contrib/gcc/config/i386/isccoff.h new file mode 100644 index 00000000000..383b981328b --- /dev/null +++ b/contrib/gcc/config/i386/isccoff.h @@ -0,0 +1,12 @@ +/* Definitions for Intel 386 running Interactive Unix System V. + Specifically, this is for recent versions that support POSIX; + for version 2.0.2, use configuration option i386-sysv instead. + (But set TARGET_DEFAULT to 0201 if you do that, + if you don't have a real 80387.) */ + +/* Mostly it's like AT&T Unix System V. */ + +#include "i386/sysv3.h" + +/* But with a few changes. */ +#include "i386/isc.h" diff --git a/contrib/gcc/config/i386/iscdbx.h b/contrib/gcc/config/i386/iscdbx.h new file mode 100644 index 00000000000..6c2d42e470d --- /dev/null +++ b/contrib/gcc/config/i386/iscdbx.h @@ -0,0 +1,43 @@ +/* Definitions for Intel 386 running Interactive Unix System V, + using dbx-in-coff encapsulation. + Specifically, this is for recent versions that support POSIX. + Copyright (C) 1992, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Mostly it's like AT&T Unix System V with dbx-in-coff. */ + +#include "i386/svr3dbx.h" + +/* But with a few changes. */ +#undef ENDFILE_SPEC +#include "i386/isc.h" + +/* Overridden defines for ifile usage. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!r:%{!z:svr3.ifile%s}%{z:svr3z.ifile%s}}\ + %{!shlib:%{posix:%{pg:mcrtp1.o%s}%{!pg:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}}\ + %{Xp:%{pg:mcrtp1.o%s}%{!pg:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}}\ + %{!posix:%{!Xp:%{pg:mcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}}}\ + %{p:-L/usr/lib/libp} %{pg:-L/usr/lib/libp}}\ + %{shlib:%{posix:crtp1.o%s}%{Xp:crtp1.o%s}%{!posix:%{!Xp:crt1.o%s}}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtn.o%s" diff --git a/contrib/gcc/config/i386/linux-aout.h b/contrib/gcc/config/i386/linux-aout.h new file mode 100644 index 00000000000..7e46c68b8ec --- /dev/null +++ b/contrib/gcc/config/i386/linux-aout.h @@ -0,0 +1,76 @@ +/* Definitions for Intel 386 running Linux + Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc. + Contributed by H.J. Lu (hjl@nynexst.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is tested by i386/gas.h. */ +#define YES_UNDERSCORES + +#include +#include /* some common stuff */ + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#if TARGET_CPU_DEFAULT == 2 +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!m386:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#else +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m486:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#endif + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* Don't default to pcc-struct-return, because gcc is the only compiler, + and we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +#undef LIB_SPEC + +#if 1 +/* We no longer link with libc_p.a or libg.a by default. If you + * want to profile or debug the Linux C library, please add + * -lc_p or -ggdb to LDFLAGS at the link time, respectively. + */ +#define LIB_SPEC \ +"%{mieee-fp:-lieee} %{p:-lgmon} %{pg:-lgmon} %{!ggdb:-lc} %{ggdb:-lg}" +#else +#define LIB_SPEC \ +"%{mieee-fp:-lieee} %{p:-lgmon -lc_p} %{pg:-lgmon -lc_p} \ + %{!p:%{!pg:%{!g*:-lc} %{g*:-lg -static}}}" +#endif + + +#undef LINK_SPEC +#define LINK_SPEC "-m i386linux" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" diff --git a/contrib/gcc/config/i386/linux-oldld.h b/contrib/gcc/config/i386/linux-oldld.h new file mode 100644 index 00000000000..c3066ba1333 --- /dev/null +++ b/contrib/gcc/config/i386/linux-oldld.h @@ -0,0 +1,76 @@ +/* Definitions for Intel 386 running Linux with pre-BFD a.out linkers + Copyright (C) 1995 Free Software Foundation, Inc. + Contributed by Michael Meissner (meissner@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is tested by i386/gas.h. */ +#define YES_UNDERSCORES + +#include +#include /* some common stuff */ + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#if TARGET_CPU_DEFAULT == 2 +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!m386:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#else +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m486:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#endif + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* Don't default to pcc-struct-return, because gcc is the only compiler, + and we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +#undef LIB_SPEC + +#if 1 +/* We no longer link with libc_p.a or libg.a by default. If you + * want to profile or debug the Linux C library, please add + * -lc_p or -ggdb to LDFLAGS at the link time, respectively. + */ +#define LIB_SPEC \ +"%{mieee-fp:-lieee} %{p:-lgmon} %{pg:-lgmon} %{!ggdb:-lc} %{ggdb:-lg}" +#else +#define LIB_SPEC \ +"%{mieee-fp:-lieee} %{p:-lgmon -lc_p} %{pg:-lgmon -lc_p} \ + %{!p:%{!pg:%{!g*:-lc} %{g*:-lg -static}}}" +#endif + + +#undef LINK_SPEC +#define LINK_SPEC "" + +/* Get perform_* macros to build libgcc.a. */ +#include diff --git a/contrib/gcc/config/i386/linux.h b/contrib/gcc/config/i386/linux.h new file mode 100644 index 00000000000..f077de57efb --- /dev/null +++ b/contrib/gcc/config/i386/linux.h @@ -0,0 +1,212 @@ +/* Definitions for Intel 386 running Linux with ELF format + Copyright (C) 1994, 1995 Free Software Foundation, Inc. + Contributed by Eric Youngdale. + Modified for stabs-in-ELF by H.J. Lu. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define LINUX_DEFAULT_ELF + +/* A lie, I guess, but the general idea behind linux/ELF is that we are + supposed to be outputting something that will assemble under SVr4. + This gets us pretty close. */ +#include /* Base i386 target machine definitions */ +#include /* Use the i386 AT&T assembler syntax */ +#include /* some common stuff */ + +#undef TARGET_VERSION +#define TARGET_VERSION fprintf (stderr, " (i386 Linux/ELF)"); + +/* The svr4 ABI for the i386 says that records and unions are returned + in memory. */ +#undef DEFAULT_PCC_STRUCT_RETURN +#define DEFAULT_PCC_STRUCT_RETURN 1 + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ +#define JUMP_TABLES_IN_TEXT_SECTION + +/* Copy this from the svr4 specifications... */ +/* Define the register numbers to be used in Dwarf debugging information. + The SVR4 reference port C compiler uses the following register numbers + in its Dwarf output code: + 0 for %eax (gnu regno = 0) + 1 for %ecx (gnu regno = 2) + 2 for %edx (gnu regno = 1) + 3 for %ebx (gnu regno = 3) + 4 for %esp (gnu regno = 7) + 5 for %ebp (gnu regno = 6) + 6 for %esi (gnu regno = 4) + 7 for %edi (gnu regno = 5) + The following three DWARF register numbers are never generated by + the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4 + believes these numbers have these meanings. + 8 for %eip (no gnu equivalent) + 9 for %eflags (no gnu equivalent) + 10 for %trapno (no gnu equivalent) + It is not at all clear how we should number the FP stack registers + for the x86 architecture. If the version of SDB on x86/svr4 were + a bit less brain dead with respect to floating-point then we would + have a precedent to follow with respect to DWARF register numbers + for x86 FP registers, but the SDB on x86/svr4 is so completely + broken with respect to FP registers that it is hardly worth thinking + of it as something to strive for compatibility with. + The version of x86/svr4 SDB I have at the moment does (partially) + seem to believe that DWARF register number 11 is associated with + the x86 register %st(0), but that's about all. Higher DWARF + register numbers don't seem to be associated with anything in + particular, and even for DWARF regno 11, SDB only seems to under- + stand that it should say that a variable lives in %st(0) (when + asked via an `=' command) if we said it was in DWARF regno 11, + but SDB still prints garbage when asked for the value of the + variable in question (via a `/' command). + (Also note that the labels SDB prints for various FP stack regs + when doing an `x' command are all wrong.) + Note that these problems generally don't affect the native SVR4 + C compiler because it doesn't allow the use of -O with -g and + because when it is *not* optimizing, it allocates a memory + location for each floating-point variable, and the memory + location is what gets described in the DWARF AT_location + attribute for the variable in question. + Regardless of the severe mental illness of the x86/svr4 SDB, we + do something sensible here and we use the following DWARF + register numbers. Note that these are all stack-top-relative + numbers. + 11 for %st(0) (gnu regno = 8) + 12 for %st(1) (gnu regno = 9) + 13 for %st(2) (gnu regno = 10) + 14 for %st(3) (gnu regno = 11) + 15 for %st(4) (gnu regno = 12) + 16 for %st(5) (gnu regno = 13) + 17 for %st(6) (gnu regno = 14) + 18 for %st(7) (gnu regno = 15) +*/ +#undef DBX_REGISTER_NUMBER +#define DBX_REGISTER_NUMBER(n) \ +((n) == 0 ? 0 \ + : (n) == 1 ? 2 \ + : (n) == 2 ? 1 \ + : (n) == 3 ? 3 \ + : (n) == 4 ? 6 \ + : (n) == 5 ? 7 \ + : (n) == 6 ? 5 \ + : (n) == 7 ? 4 \ + : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \ + : (-1)) + +/* Output assembler code to FILE to increment profiler label # LABELNO + for profiling a function entry. */ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-D__ELF__ -Dunix -Di386 -Dlinux -Asystem(unix) -Asystem(posix) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#if TARGET_CPU_DEFAULT == 2 +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!m386:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#else +#define CPP_SPEC "%{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m486:-D__i486__} %{posix:-D_POSIX_SOURCE}" +#endif + +#undef LIB_SPEC +#if 1 +/* We no longer link with libc_p.a or libg.a by default. If you + * want to profile or debug the Linux C library, please add + * -lc_p or -ggdb to LDFLAGS at the link time, respectively. + */ +#define LIB_SPEC \ + "%{!shared: %{mieee-fp:-lieee} %{p:-lgmon} %{pg:-lgmon} \ + %{!ggdb:-lc} %{ggdb:-lg}}" +#else +#define LIB_SPEC \ + "%{!shared: \ + %{mieee-fp:-lieee} %{p:-lgmon -lc_p} %{pg:-lgmon -lc_p} \ + %{!p:%{!pg:%{!g*:-lc} %{g*:-lg}}}}" +#endif + +/* Provide a LINK_SPEC appropriate for Linux. Here we provide support + for the special GCC options -static and -shared, which allow us to + link things in one of these three modes by applying the appropriate + combinations of options at link-time. We like to support here for + as many of the other GNU linker options as possible. But I don't + have the time to search for those flags. I am sure how to add + support for -soname shared_object_name. H.J. + + I took out %{v:%{!V:-V}}. It is too much :-(. They can use + -Wl,-V. + + When the -shared link option is used a final link is not being + done. */ + +/* If ELF is the default format, we should not use /lib/elf. */ + +#undef LINK_SPEC +#ifndef LINUX_DEFAULT_ELF +#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ + %{!shared: \ + %{!ibcs: \ + %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!dynamic-linker:-dynamic-linker /lib/elf/ld-linux.so.1} \ + %{!rpath:-rpath /lib/elf/}} %{static:-static}}}" +#else +#define LINK_SPEC "-m elf_i386 %{shared:-shared} \ + %{!shared: \ + %{!ibcs: \ + %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!dynamic-linker:-dynamic-linker /lib/ld-linux.so.1}} \ + %{static:-static}}}" +#endif + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" diff --git a/contrib/gcc/config/i386/lynx-ng.h b/contrib/gcc/config/i386/lynx-ng.h new file mode 100644 index 00000000000..ec4e2961692 --- /dev/null +++ b/contrib/gcc/config/i386/lynx-ng.h @@ -0,0 +1,37 @@ +/* Definitions for Intel 386 running LynxOS, using Lynx's old as and ld. + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -DI386 -DLynx -DIBITS32 -Asystem(unix) -Asystem(lynx) -Acpu(i386) -Amachine(i386)" + +/* Provide required defaults for linker switches. */ + +#undef LINK_SPEC +#define LINK_SPEC "-P1000 %{msystem-v:-V} %{mcoff:-k}" + +/* Apparently LynxOS clobbers ebx when you call into the OS. */ + +#undef CALL_USED_REGISTERS +#define CALL_USED_REGISTERS \ +/*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg*/ \ +{ 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } diff --git a/contrib/gcc/config/i386/lynx.h b/contrib/gcc/config/i386/lynx.h new file mode 100644 index 00000000000..4ac00a052ba --- /dev/null +++ b/contrib/gcc/config/i386/lynx.h @@ -0,0 +1,39 @@ +/* Definitions for Intel 386 running LynxOS. + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -DI386 -DLynx -DIBITS32 -Asystem(unix) -Asystem(lynx) -Acpu(i386) -Amachine(i386)" + +/* This is how to output a reference to a user-level label named NAME. */ + +/* Override the svr3 convention of adding a leading underscore. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) fprintf (FILE, "%s", NAME) + +/* Apparently LynxOS clobbers ebx when you call into the OS. */ + +#undef CALL_USED_REGISTERS +#define CALL_USED_REGISTERS \ +/*ax,dx,cx,bx,si,di,bp,sp,st,st1,st2,st3,st4,st5,st6,st7,arg*/ \ +{ 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } diff --git a/contrib/gcc/config/i386/mach.h b/contrib/gcc/config/i386/mach.h new file mode 100644 index 00000000000..4b7cf37e54d --- /dev/null +++ b/contrib/gcc/config/i386/mach.h @@ -0,0 +1,20 @@ +/* Configuration for an i386 running Mach as the target machine. */ + +/* We do want to add an underscore to the front of each user symbol. + i386/gas.h checks this. */ +#define YES_UNDERSCORES + +#include "i386/gstabs.h" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -DMACH -Asystem(unix) -Asystem(mach) -Acpu(i386) -Amachine(i386)" + +/* Specify extra dir to search for include files. */ +#define SYSTEM_INCLUDE_DIR "/usr/mach/include" + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 diff --git a/contrib/gcc/config/i386/netbsd.h b/contrib/gcc/config/i386/netbsd.h new file mode 100644 index 00000000000..180ff3533f7 --- /dev/null +++ b/contrib/gcc/config/i386/netbsd.h @@ -0,0 +1,80 @@ +/* This goes away when the math-emulator is fixed */ +#define TARGET_CPU_DEFAULT 0400 /* TARGET_NO_FANCY_MATH_387 */ + +/* This is tested by i386gas.h. */ +#define YES_UNDERSCORES + +#include + +/* Get perform_* macros to build libgcc.a. */ +#include + +/* Get generic NetBSD definitions. */ +#include + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -D__NetBSD__ -Asystem(unix) -Asystem(NetBSD) -Acpu(i386) -Amachine(i386)" + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "int" + +#undef WCHAR_UNSIGNED +#define WCHAR_UNSIGNED 0 + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE 32 + +#define HANDLE_SYSV_PRAGMA + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* The following macros are stolen from i386v4.h */ +/* These have to be defined to get PIC code correct */ + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ + +#define JUMP_TABLES_IN_TEXT_SECTION + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* Profiling routines, partially copied from i386/osfrose.h. */ + +/* Redefine this to use %eax instead of %edx. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tcall mcount@PLT\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} diff --git a/contrib/gcc/config/i386/next.c b/contrib/gcc/config/i386/next.c new file mode 100644 index 00000000000..f249647ab59 --- /dev/null +++ b/contrib/gcc/config/i386/next.c @@ -0,0 +1,7 @@ +/* next.c: Functions for NeXT as target machine for GNU C compiler. */ + +/* Note that the include below means that we can't debug routines in + i386.c when running on a COFF system. */ + +#include "i386/i386.c" +#include "nextstep.c" diff --git a/contrib/gcc/config/i386/next.h b/contrib/gcc/config/i386/next.h new file mode 100644 index 00000000000..c0d6d7296f1 --- /dev/null +++ b/contrib/gcc/config/i386/next.h @@ -0,0 +1,226 @@ +/* Target definitions for GNU compiler for Intel x86 CPU running NeXTSTEP + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/gas.h" +#include "nextstep.h" + +/* By default, target has a 80387, with IEEE FP. */ + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT (1|0100) + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +/* Machines that use the AT&T assembler syntax + also return floating point values in an FP register. + Define how to find the value returned by a function. + VALTYPE is the data type of the value (as a tree). + If the precise function being called is known, FUNC is its FUNCTION_DECL; + otherwise, FUNC is 0. */ + +#undef VALUE_REGNO +#define VALUE_REGNO(MODE) \ + ((MODE) == SFmode || (MODE) == DFmode || (MODE) == XFmode \ + ? FIRST_FLOAT_REG : 0) + +/* 1 if N is a possible register number for a function value. */ + +#undef FUNCTION_VALUE_REGNO_P +#define FUNCTION_VALUE_REGNO_P(N) ((N) == 0 || (N)== FIRST_FLOAT_REG) + +#ifdef REAL_VALUE_TO_TARGET_LONG_DOUBLE +#undef ASM_OUTPUT_LONG_DOUBLE +#define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE) \ + do { \ + long hex[3]; \ + REAL_VALUE_TO_TARGET_LONG_DOUBLE (VALUE, hex); \ + if (sizeof (int) == sizeof (long)) \ + fprintf (FILE, "\t.long 0x%x\n\t.long 0x%x\n\t.long 0x%x\n", \ + hex[0], hex[1], hex[2]); \ + else \ + fprintf (FILE, "\t.long 0x%lx\n\t.long 0x%lx\n\t.long 0x%lx\n", \ + hex[0], hex[1], hex[2]); \ + } while (0) +#endif + +#ifdef REAL_VALUE_TO_TARGET_DOUBLE +#undef ASM_OUTPUT_DOUBLE +#define ASM_OUTPUT_DOUBLE(FILE,VALUE) \ + do { \ + long hex[2]; \ + REAL_VALUE_TO_TARGET_DOUBLE (VALUE, hex); \ + if (sizeof (int) == sizeof (long)) \ + fprintf (FILE, "\t.long 0x%x\n\t.long 0x%x\n", hex[0], hex[1]); \ + else \ + fprintf (FILE, "\t.long 0x%lx\n\t.long 0x%lx\n", hex[0], hex[1]); \ + } while (0) +#endif + +/* This is how to output an assembler line defining a `float' constant. */ + +#ifdef REAL_VALUE_TO_TARGET_SINGLE +#undef ASM_OUTPUT_FLOAT +#define ASM_OUTPUT_FLOAT(FILE,VALUE) \ + do { \ + long hex; \ + REAL_VALUE_TO_TARGET_SINGLE (VALUE, hex); \ + if (sizeof (int) == sizeof (long)) \ + fprintf (FILE, "\t.long 0x%x\n", hex); \ + else \ + fprintf (FILE, "\t.long 0x%lx\n", hex); \ + } while (0) +#endif + +/* A C statement or statements which output an assembler instruction + opcode to the stdio stream STREAM. The macro-operand PTR is a + variable of type `char *' which points to the opcode name in its + "internal" form--the form that is written in the machine description. + + GAS version 1.38.1 doesn't understand the `repz' opcode mnemonic. + So use `repe' instead. */ + +#undef ASM_OUTPUT_OPCODE +#define ASM_OUTPUT_OPCODE(STREAM, PTR) \ +{ \ + if ((PTR)[0] == 'r' \ + && (PTR)[1] == 'e' \ + && (PTR)[2] == 'p') \ + { \ + if ((PTR)[3] == 'z') \ + { \ + fprintf (STREAM, "repe"); \ + (PTR) += 4; \ + } \ + else if ((PTR)[3] == 'n' && (PTR)[4] == 'z') \ + { \ + fprintf (STREAM, "repne"); \ + (PTR) += 5; \ + } \ + } \ +} + +/* Define macro used to output shift-double opcodes when the shift + count is in %cl. Some assemblers require %cl as an argument; + some don't. + + GAS requires the %cl argument, so override unx386.h. */ + +#undef AS3_SHIFT_DOUBLE +#define AS3_SHIFT_DOUBLE(a,b,c,d) AS3 (a,b,c,d) + +/* Print opcodes the way that GAS expects them. */ +#define GAS_MNEMONICS 1 + +/* Names to predefine in the preprocessor for this target machine. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Di386 -DNeXT -Dunix -D__MACH__ -D__LITTLE_ENDIAN__ -D__ARCHITECTURE__=\"i386\" -Asystem(unix) -Asystem(mach) -Acpu(i386) -Amachine(i386)" + +/* This accounts for the return pc and saved fp on the i386. */ + +#define OBJC_FORWARDING_STACK_OFFSET 8 +#define OBJC_FORWARDING_MIN_OFFSET 8 + +/* We do not want a dot in internal labels. */ + +#undef LPREFIX +#define LPREFIX "L" + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*%s%d", (PREFIX), (NUMBER)) + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, "%s%d:\n", PREFIX, NUM) + +/* Output to assembler file text saying following lines + may contain character constants, extra white space, comments, etc. */ + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +/* Output to assembler file text saying following lines + no longer contain unusual constructs. */ + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +#undef ASM_OUTPUT_REG_PUSH +#define ASM_OUTPUT_REG_PUSH(FILE,REGNO) \ + fprintf (FILE, "\tpushl %se%s\n", "%", reg_names[REGNO]) + +#undef ASM_OUTPUT_REG_POP +#define ASM_OUTPUT_REG_POP(FILE,REGNO) \ + fprintf (FILE, "\tpopl %se%s\n", "%", reg_names[REGNO]) + +/* This is being overridden because the default i386 configuration + generates calls to "_mcount". NeXT system libraries all use + "mcount". */ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +{ \ + if (flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ + LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall *mcount@GOT(%%ebx)\n"); \ + } \ + else \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", LPREFIX, (LABELNO)); \ + fprintf (FILE, "\tcall mcount\n"); \ + } \ +} + +/* BEGIN Calling Convention CHANGES */ + +/* These changes violate the Intel/Unix ABI. Specifically, they + change the way that space for a block return value is passed to a + function. The ABI says that the pointer is passed on the stack. + We change to pass the pointer in %ebx. This makes the NeXT + Objective-C forwarding mechanism possible to implement on an i386. */ + +/* Do NOT pass address of structure values on the stack. */ + +#undef STRUCT_VALUE_INCOMING +#undef STRUCT_VALUE + +/* Pass them in %ebx. */ + +#undef STRUCT_VALUE_REGNUM +#define STRUCT_VALUE_REGNUM 3 + +/* Because we are passing the pointer in a register, we don't need to + rely on the callee to pop it. */ + +#undef RETURN_POPS_ARGS +#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \ + (TREE_CODE (FUNTYPE) == IDENTIFIER_NODE \ + ? 0 \ + : (TARGET_RTD \ + && (TYPE_ARG_TYPES (FUNTYPE) == 0 \ + || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (FUNTYPE))) \ + == void_type_node))) ? (SIZE) : 0) + +/* END Calling Convention CHANGES */ diff --git a/contrib/gcc/config/i386/os2.h b/contrib/gcc/config/i386/os2.h new file mode 100644 index 00000000000..8bbab361f98 --- /dev/null +++ b/contrib/gcc/config/i386/os2.h @@ -0,0 +1,76 @@ +/* Definitions of target machine for GNU compiler + for an Intel i386 or later processor running OS/2 2.x. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Samuel Figueroa (figueroa@cs.nyu.edu) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef DEFAULT_TARGET_MACHINE +#define DEFAULT_TARGET_MACHINE "i386-os2" +#endif +#ifndef LINK_SPEC +#define LINK_SPEC "/st:1048576/pm:vio/noi/a:16/e/bas:65536/nol" +#endif +#ifndef LIB_SPEC +#define LIB_SPEC "libgcc libc" +#endif +#ifndef STARTFILE_SPEC +#define STARTFILE_SPEC "libcrt.lib" +#endif +#ifndef MD_EXEC_PREFIX +#define MD_EXEC_PREFIX "\\gcc\\bin\\" +#endif +#ifndef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "\\gcc\\lib\\" +#endif +#ifndef LOCAL_INCLUDE_DIR +#define LOCAL_INCLUDE_DIR "\\gcc\\include" +#endif + +#define YES_UNDERSCORES +#include "i386/gstabs.h" + +#define USE_COLLECT + +#define BIGGEST_FIELD_ALIGNMENT \ + (maximum_field_alignment ? maximum_field_alignment : 32) + +extern int maximum_field_alignment; + +#undef PCC_BITFIELD_TYPE_MATTERS +#define PCC_BITFIELD_TYPE_MATTERS (maximum_field_alignment == 0) + +/* Define this macro if it is advisable to hold scalars in registers + in a wider mode than that declared by the program. In such cases, + the value is constrained to be within the bounds of the declared + type, but kept valid in the wider mode. The signedness of the + extension may differ from that of the type. */ + +#define PROMOTE_MODE(MODE,UNSIGNEDP,TYPE) \ + if (GET_MODE_CLASS (MODE) == MODE_INT \ + && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \ + (MODE) = SImode; + +/* Define this if function arguments should also be promoted using the above + procedure. */ + +#define PROMOTE_FUNCTION_ARGS + +/* Likewise, if the function return value is promoted. */ + +#define PROMOTE_FUNCTION_RETURN diff --git a/contrib/gcc/config/i386/osfelf.h b/contrib/gcc/config/i386/osfelf.h new file mode 100644 index 00000000000..7e71fe98f6b --- /dev/null +++ b/contrib/gcc/config/i386/osfelf.h @@ -0,0 +1,79 @@ +/* Definitions of target machine for GNU compiler. + Intel 386 (OSF/1 with ELF) version. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config/i386/osfrose.h" + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-DOSF -DOSF1 -Dunix -Di386 -Asystem(unix) -Asystem(xpg4) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC "\ +%{mrose: -D__ROSE__ %{!pic-none: -D__SHARED__}} \ +%{!mrose: -D__ELF__ %{fpic: -D__SHARED__}} \ +%{mno-underscores: -D__NO_UNDERSCORES__} \ +%{!mrose: %{!munderscores: -D__NO_UNDERSCORES__}} \ +%{.S: %{!ansi:%{!traditional:%{!traditional-cpp:%{!ftraditional: -traditional}}}}} \ +%{.S: -D__LANGUAGE_ASSEMBLY %{!ansi:-DLANGUAGE_ASSEMBLY}} \ +%{.cc: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.cxx: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.C: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.m: -D__LANGUAGE_OBJECTIVE_C} \ +%{!.S: -D__LANGUAGE_C %{!ansi:-DLANGUAGE_C}}" + +/* Turn on -pic-extern by default for OSF/rose, -fpic for ELF. */ +#undef CC1_SPEC +#define CC1_SPEC "\ +%{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \ +%{!melf: %{!mrose: -melf }} \ +%{!mrose: %{!munderscores: %{!mno-underscores: -mno-underscores }} \ + %{!mmcount: %{!mno-mcount: %{!mmcount-ptr: -mmcount-ptr }}}} \ +%{mrose: %{!mmcount: %{!mno-mcount: %{!mmcount-ptr: -mmcount }}} \ + %{pic-extern: -mhalf-pic } %{pic-lib: -mhalf-pic } \ + %{!pic-extern: %{!pic-lib: %{pic-none: -mno-half-pic} %{!pic-none: -mhalf-pic}}} \ + %{pic-calls: } %{pic-names*: }}" + +#undef ASM_SPEC +#define ASM_SPEC "%{v*: -v}" + +#undef LINK_SPEC +#define LINK_SPEC "%{v*: -v} \ +%{mrose: %{!noshrlib: %{pic-none: -noshrlib} %{!pic-none: -warn_nopic}} \ + %{nostdlib} %{noshrlib} %{glue}} \ +%{!mrose: %{dy} %{dn} %{glue: } \ + %{h*} %{z*} \ + %{static:-dn -Bstatic} \ + %{shared:-G -dy} \ + %{symbolic:-Bsymbolic -G -dy} \ + %{G:-G} \ + %{!dy: %{!dn: %{!static: %{!shared: %{!symbolic: \ + %{noshrlib: -dn } %{pic-none: -dn } \ + %{!noshrlib: %{!pic-none: -dy}}}}}}}}" + +#undef TARGET_VERSION_INTERNAL +#undef TARGET_VERSION + +#undef I386_VERSION +#define I386_VERSION " 80386, ELF objects" + +#define TARGET_VERSION_INTERNAL(STREAM) fputs (I386_VERSION, STREAM) +#define TARGET_VERSION TARGET_VERSION_INTERNAL (stderr) + +#undef OBJECT_FORMAT_ROSE diff --git a/contrib/gcc/config/i386/osfrose.h b/contrib/gcc/config/i386/osfrose.h new file mode 100644 index 00000000000..3aae1e1b681 --- /dev/null +++ b/contrib/gcc/config/i386/osfrose.h @@ -0,0 +1,923 @@ +/* Definitions of target machine for GNU compiler. + Intel 386 (OSF/1 with OSF/rose) version. + Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "halfpic.h" +#include "i386/gstabs.h" + +/* Get perform_* macros to build libgcc.a. */ +#include "i386/perform.h" + +#define OSF_OS + +#undef WORD_SWITCH_TAKES_ARG +#define WORD_SWITCH_TAKES_ARG(STR) \ + (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) || !strcmp (STR, "pic-names")) + +/* This defines which switch letters take arguments. On svr4, most of + the normal cases (defined in gcc.c) apply, and we also have -h* and + -z* options (for the linker). */ + +#define SWITCH_TAKES_ARG(CHAR) \ + ( (CHAR) == 'D' \ + || (CHAR) == 'U' \ + || (CHAR) == 'o' \ + || (CHAR) == 'e' \ + || (CHAR) == 'T' \ + || (CHAR) == 'u' \ + || (CHAR) == 'I' \ + || (CHAR) == 'm' \ + || (CHAR) == 'L' \ + || (CHAR) == 'A' \ + || (CHAR) == 'h' \ + || (CHAR) == 'z') + +#define MASK_HALF_PIC 010000000000 /* Mask for half-pic code */ +#define MASK_HALF_PIC_DEBUG 004000000000 /* Debug flag */ +#define MASK_ELF 002000000000 /* ELF not rose */ +#define MASK_NO_IDENT 001000000000 /* suppress .ident */ +#define MASK_NO_UNDERSCORES 000400000000 /* suppress leading _ */ +#define MASK_LARGE_ALIGN 000200000000 /* align to >word boundaries */ +#define MASK_NO_MCOUNT 000100000000 /* profiling uses mcount_ptr */ + +#define TARGET_HALF_PIC (target_flags & MASK_HALF_PIC) +#define TARGET_DEBUG (target_flags & MASK_HALF_PIC_DEBUG) +#define HALF_PIC_DEBUG TARGET_DEBUG +#define TARGET_ELF (target_flags & MASK_ELF) +#define TARGET_ROSE ((target_flags & MASK_ELF) == 0) +#define TARGET_IDENT ((target_flags & MASK_NO_IDENT) == 0) +#define TARGET_UNDERSCORES ((target_flags & MASK_NO_UNDERSCORES) == 0) +#define TARGET_LARGE_ALIGN (target_flags & MASK_LARGE_ALIGN) +#define TARGET_MCOUNT ((target_flags & MASK_NO_MCOUNT) == 0) + +#undef SUBTARGET_SWITCHES +#define SUBTARGET_SWITCHES \ + { "half-pic", MASK_HALF_PIC}, \ + { "no-half-pic", -MASK_HALF_PIC}, \ + { "debug-half-pic", MASK_HALF_PIC_DEBUG}, \ + { "debugb", MASK_HALF_PIC_DEBUG}, \ + { "elf", MASK_ELF}, \ + { "rose", -MASK_ELF}, \ + { "ident", -MASK_NO_IDENT}, \ + { "no-ident", MASK_NO_IDENT}, \ + { "underscores", -MASK_NO_UNDERSCORES}, \ + { "no-underscores", MASK_NO_UNDERSCORES}, \ + { "large-align", MASK_LARGE_ALIGN}, \ + { "no-large-align", -MASK_LARGE_ALIGN}, \ + { "mcount", -MASK_NO_MCOUNT}, \ + { "mcount-ptr", MASK_NO_MCOUNT}, \ + { "no-mcount", MASK_NO_MCOUNT}, + +/* OSF/rose uses stabs, not dwarf. */ +#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG + +#ifndef DWARF_DEBUGGING_INFO +#define DWARF_DEBUGGING_INFO /* enable dwarf debugging for testing */ +#endif + +/* Handle #pragma weak and #pragma pack. */ + +#define HANDLE_SYSV_PRAGMA +#define SUPPORTS_WEAK TARGET_ELF + +/* Change default predefines. */ +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-DOSF -DOSF1 -Dunix -Di386 -Asystem(unix) -Asystem(xpg4) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC "\ +%{!melf: -D__ROSE__ %{!pic-none: -D__SHARED__}} \ +%{melf: -D__ELF__ %{fpic: -D__SHARED__}} \ +%{mno-underscores: -D__NO_UNDERSCORES__} \ +%{melf: %{!munderscores: -D__NO_UNDERSCORES__}} \ +%{.S: %{!ansi:%{!traditional:%{!traditional-cpp:%{!ftraditional: -traditional}}}}} \ +%{.S: -D__LANGUAGE_ASSEMBLY %{!ansi:-DLANGUAGE_ASSEMBLY}} \ +%{.cc: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.cxx: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.C: -D__LANGUAGE_C_PLUS_PLUS} \ +%{.m: -D__LANGUAGE_OBJECTIVE_C} \ +%{!.S: -D__LANGUAGE_C %{!ansi:-DLANGUAGE_C}}" + +/* Turn on -pic-extern by default for OSF/rose, -fpic for ELF. */ +#undef CC1_SPEC +#define CC1_SPEC "\ +%{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \ +%{!melf: %{!mrose: -mrose }} \ +%{melf: %{!munderscores: %{!mno-underscores: -mno-underscores }} \ + %{!mmcount: %{!mno-mcount: %{!mmcount-ptr: -mmcount-ptr }}}} \ +%{!melf: %{!munderscores: %{!mno-underscores: -munderscores }} \ + %{!mmcount: %{!mno-mcount: %{!mmcount-ptr: -mmcount }}} \ + %{pic-extern: -mhalf-pic } %{pic-lib: -mhalf-pic } \ + %{!pic-extern: %{!pic-lib: %{pic-none: -mno-half-pic} %{!pic-none: -mhalf-pic}}} \ + %{pic-calls: } %{pic-names*: }}" + +#undef ASM_SPEC +#define ASM_SPEC "%{v*: -v}" + +#undef LINK_SPEC +#define LINK_SPEC "%{v*: -v} \ +%{!melf: %{!noshrlib: %{pic-none: -noshrlib} %{!pic-none: -warn_nopic}} \ + %{nostdlib} %{noshrlib} %{glue}} \ +%{melf: %{dy} %{dn} %{glue: } \ + %{h*} %{z*} \ + %{static:-dn -Bstatic} \ + %{shared:-G -dy} \ + %{symbolic:-Bsymbolic -G -dy} \ + %{G:-G} \ + %{!dy: %{!dn: %{!static: %{!shared: %{!symbolic: \ + %{noshrlib: -dn } %{pic-none: -dn } \ + %{!noshrlib: %{!pic-none: -dy}}}}}}}}" + +#undef LIB_SPEC +#define LIB_SPEC "-lc" + +#undef LIBG_SPEC +#define LIBG_SPEC "" + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}" + +#undef TARGET_VERSION_INTERNAL +#undef TARGET_VERSION + +#define I386_VERSION " 80386, OSF/rose objects" + +#define TARGET_VERSION_INTERNAL(STREAM) fputs (I386_VERSION, STREAM) +#define TARGET_VERSION TARGET_VERSION_INTERNAL (stderr) + +#undef MD_EXEC_PREFIX +#define MD_EXEC_PREFIX "/usr/ccs/gcc/" + +#undef MD_STARTFILE_PREFIX +#define MD_STARTFILE_PREFIX "/usr/ccs/lib/" + +/* Specify size_t, ptrdiff_t, and wchar_t types. */ +#undef SIZE_TYPE +#undef PTRDIFF_TYPE +#undef WCHAR_TYPE +#undef WCHAR_TYPE_SIZE + +#define SIZE_TYPE "long unsigned int" +#define PTRDIFF_TYPE "int" +#define WCHAR_TYPE "unsigned int" +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* Define this macro if the system header files support C++ as well + as C. This macro inhibits the usual method of using system header + files in C++, which is to pretend that the file's contents are + enclosed in `extern "C" {...}'. */ +#define NO_IMPLICIT_EXTERN_C + +/* Turn off long double being 96 bits. */ +#undef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE 64 + +/* This macro generates the assembly code for function entry. + FILE is a stdio stream to output the code to. + SIZE is an int: how many units of temporary storage to allocate. + Refer to the array `regs_ever_live' to determine which registers + to save; `regs_ever_live[I]' is nonzero if register number I + is ever used in the function. This macro is responsible for + knowing which registers should not be saved even if used. + + We override it here to allow for the new profiling code to go before + the prologue and the old mcount code to go after the prologue (and + after %ebx has been set up for ELF shared library support). */ + +#define OSF_PROFILE_BEFORE_PROLOGUE \ + (!TARGET_MCOUNT \ + && !current_function_needs_context \ + && (!flag_pic \ + || !frame_pointer_needed \ + || (!current_function_uses_pic_offset_table \ + && !current_function_uses_const_pool))) + +#undef FUNCTION_PROLOGUE +#define FUNCTION_PROLOGUE(FILE, SIZE) \ +do \ + { \ + char *prefix = (TARGET_UNDERSCORES) ? "_" : ""; \ + char *lprefix = LPREFIX; \ + int labelno = profile_label_no; \ + \ + if (profile_flag && OSF_PROFILE_BEFORE_PROLOGUE) \ + { \ + if (!flag_pic && !HALF_PIC_P ()) \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", lprefix, labelno); \ + fprintf (FILE, "\tcall *%s_mcount_ptr\n", prefix); \ + } \ + \ + else if (HALF_PIC_P ()) \ + { \ + rtx symref; \ + \ + HALF_PIC_EXTERNAL ("_mcount_ptr"); \ + symref = HALF_PIC_PTR (gen_rtx (SYMBOL_REF, Pmode, \ + "_mcount_ptr")); \ + \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", lprefix, labelno); \ + fprintf (FILE, "\tmovl %s%s,%%eax\n", prefix, \ + XSTR (symref, 0)); \ + fprintf (FILE, "\tcall *(%%eax)\n"); \ + } \ + \ + else \ + { \ + static int call_no = 0; \ + \ + fprintf (FILE, "\tcall %sPc%d\n", lprefix, call_no); \ + fprintf (FILE, "%sPc%d:\tpopl %%eax\n", lprefix, call_no); \ + fprintf (FILE, "\taddl $_GLOBAL_OFFSET_TABLE_+[.-%sPc%d],%%eax\n", \ + lprefix, call_no++); \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%eax),%%edx\n", \ + lprefix, labelno); \ + fprintf (FILE, "\tmovl %s_mcount_ptr@GOT(%%eax),%%eax\n", \ + prefix); \ + fprintf (FILE, "\tcall *(%%eax)\n"); \ + } \ + } \ + \ + function_prologue (FILE, SIZE); \ + } \ +while (0) + +/* A C statement or compound statement to output to FILE some assembler code to + call the profiling subroutine `mcount'. Before calling, the assembler code + must load the address of a counter variable into a register where `mcount' + expects to find the address. The name of this variable is `LP' followed by + the number LABELNO, so you would generate the name using `LP%d' in a + `fprintf'. + + The details of how the address should be passed to `mcount' are determined + by your operating system environment, not by GNU CC. To figure them out, + compile a small program for profiling using the system's installed C + compiler and look at the assembler code that results. */ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ +do \ + { \ + if (!OSF_PROFILE_BEFORE_PROLOGUE) \ + { \ + char *prefix = (TARGET_UNDERSCORES) ? "_" : ""; \ + char *lprefix = LPREFIX; \ + int labelno = LABELNO; \ + \ + /* Note that OSF/rose blew it in terms of calling mcount, \ + since OSF/rose prepends a leading underscore, but mcount's \ + doesn't. At present, we keep this kludge for ELF as well \ + to allow old kernels to build profiling. */ \ + \ + if (flag_pic \ + && !current_function_uses_pic_offset_table \ + && !current_function_uses_const_pool) \ + abort (); \ + \ + if (TARGET_MCOUNT && flag_pic) \ + { \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ + lprefix, labelno); \ + fprintf (FILE, "\tcall *%smcount@GOT(%%ebx)\n", prefix); \ + } \ + \ + else if (TARGET_MCOUNT && HALF_PIC_P ()) \ + { \ + rtx symdef; \ + \ + HALF_PIC_EXTERNAL ("mcount"); \ + symdef = HALF_PIC_PTR (gen_rtx (SYMBOL_REF, Pmode, "mcount")); \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", lprefix, labelno); \ + fprintf (FILE, "\tcall *%s%s\n", prefix, XSTR (symdef, 0)); \ + } \ + \ + else if (TARGET_MCOUNT) \ + { \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", lprefix, labelno); \ + fprintf (FILE, "\tcall %smcount\n", prefix); \ + } \ + \ + else if (flag_pic && frame_pointer_needed) \ + { \ + fprintf (FILE, "\tmovl 4(%%ebp),%%ecx\n"); \ + fprintf (FILE, "\tpushl %%ecx\n"); \ + fprintf (FILE, "\tleal %sP%d@GOTOFF(%%ebx),%%edx\n", \ + lprefix, labelno); \ + fprintf (FILE, "\tmovl _mcount_ptr@GOT(%%ebx),%%eax\n"); \ + fprintf (FILE, "\tcall *(%%eax)\n"); \ + fprintf (FILE, "\tpopl %%eax\n"); \ + } \ + \ + else if (frame_pointer_needed) \ + { \ + fprintf (FILE, "\tmovl 4(%%ebp),%%ecx\n"); \ + fprintf (FILE, "\tpushl %%ecx\n"); \ + fprintf (FILE, "\tmovl $%sP%d,%%edx\n", lprefix, labelno); \ + fprintf (FILE, "\tcall *_mcount_ptr\n"); \ + fprintf (FILE, "\tpopl %%eax\n"); \ + } \ + \ + else \ + abort (); \ + } \ + } \ +while (0) + +/* A C function or functions which are needed in the library to + support block profiling. When support goes into libc, undo + the #if 0. */ + +#if 0 +#undef BLOCK_PROFILING_CODE +#define BLOCK_PROFILING_CODE +#endif + +/* Prefix for internally generated assembler labels. If we aren't using + underscores, we are using prefix `.'s to identify labels that should + be ignored, as in `i386/gas.h' --karl@cs.umb.edu */ +#undef LPREFIX +#define LPREFIX ((TARGET_UNDERSCORES) ? "L" : ".L") + +/* This is how to store into the string BUF + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*%s%s%d", (TARGET_UNDERSCORES) ? "" : ".", \ + (PREFIX), (NUMBER)) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. */ + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, "%s%s%d:\n", (TARGET_UNDERSCORES) ? "" : ".", \ + PREFIX, NUM) + +/* This is how to output a reference to a user-level label named NAME. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) \ + fprintf (FILE, "%s%s", (TARGET_UNDERSCORES) ? "_" : "", NAME) + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Output a definition */ +#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ +do \ +{ \ + fprintf ((FILE), "\t%s\t", SET_ASM_OP); \ + assemble_name (FILE, LABEL1); \ + fprintf (FILE, ","); \ + assemble_name (FILE, LABEL2); \ + fprintf (FILE, "\n"); \ + } \ +while (0) + +/* A C expression to output text to align the location counter in the + way that is desirable at a point in the code that is reached only + by jumping. + + This macro need not be defined if you don't want any special + alignment to be done at such a time. Most machine descriptions do + not currently define the macro. */ + +#undef ASM_OUTPUT_ALIGN_CODE +#define ASM_OUTPUT_ALIGN_CODE(STREAM) \ + fprintf (STREAM, "\t.align\t%d\n", \ + (!TARGET_LARGE_ALIGN && i386_align_jumps > 2) ? 2 : i386_align_jumps) + +/* A C expression to output text to align the location counter in the + way that is desirable at the beginning of a loop. + + This macro need not be defined if you don't want any special + alignment to be done at such a time. Most machine descriptions do + not currently define the macro. */ + +#undef ASM_OUTPUT_LOOP_ALIGN +#define ASM_OUTPUT_LOOP_ALIGN(STREAM) \ + fprintf (STREAM, "\t.align\t%d\n", i386_align_loops) + +/* A C statement to output to the stdio stream STREAM an assembler + command to advance the location counter to a multiple of 2 to the + POWER bytes. POWER will be a C expression of type `int'. */ + +#undef ASM_OUTPUT_ALIGN +#define ASM_OUTPUT_ALIGN(STREAM, POWER) \ + fprintf (STREAM, "\t.align\t%d\n", \ + (!TARGET_LARGE_ALIGN && (POWER) > 2) ? 2 : (POWER)) + +/* A C expression that is 1 if the RTX X is a constant which is a + valid address. On most machines, this can be defined as + `CONSTANT_P (X)', but a few machines are more restrictive in + which constant addresses are supported. + + `CONSTANT_P' accepts integer-values expressions whose values are + not explicitly known, such as `symbol_ref', `label_ref', and + `high' expressions and `const' arithmetic expressions, in + addition to `const_int' and `const_double' expressions. */ + +#define CONSTANT_ADDRESS_P_ORIG(X) \ + (GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF \ + || GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST \ + || GET_CODE (X) == HIGH) + +#undef CONSTANT_ADDRESS_P +#define CONSTANT_ADDRESS_P(X) \ + ((CONSTANT_ADDRESS_P_ORIG (X)) && (!HALF_PIC_P () || !HALF_PIC_ADDRESS_P (X))) + +/* Nonzero if the constant value X is a legitimate general operand. + It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE. */ + +#undef LEGITIMATE_CONSTANT_P +#define LEGITIMATE_CONSTANT_P(X) \ + (!HALF_PIC_P () \ + || GET_CODE (X) == CONST_DOUBLE \ + || GET_CODE (X) == CONST_INT \ + || !HALF_PIC_ADDRESS_P (X)) + +/* Sometimes certain combinations of command options do not make sense + on a particular target machine. You can define a macro + `OVERRIDE_OPTIONS' to take account of this. This macro, if + defined, is executed once just after all the command options have + been parsed. */ + +#undef SUBTARGET_OVERRIDE_OPTIONS +#define SUBTARGET_OVERRIDE_OPTIONS \ +{ \ + /* \ + if (TARGET_ELF && TARGET_HALF_PIC) \ + { \ + target_flags &= ~MASK_HALF_PIC; \ + flag_pic = 1; \ + } \ + */ \ + \ + if (TARGET_ROSE && flag_pic) \ + { \ + target_flags |= MASK_HALF_PIC; \ + flag_pic = 0; \ + } \ + \ + if (TARGET_HALF_PIC) \ + half_pic_init (); \ +} + +/* Define this macro if references to a symbol must be treated + differently depending on something about the variable or + function named by the symbol (such as what section it is in). + + The macro definition, if any, is executed immediately after the + rtl for DECL has been created and stored in `DECL_RTL (DECL)'. + The value of the rtl will be a `mem' whose address is a + `symbol_ref'. + + The usual thing for this macro to do is to a flag in the + `symbol_ref' (such as `SYMBOL_REF_FLAG') or to store a modified + name string in the `symbol_ref' (if one bit is not enough + information). + + The best way to modify the name string is by adding text to the + beginning, with suitable punctuation to prevent any ambiguity. + Allocate the new name in `saveable_obstack'. You will have to + modify `ASM_OUTPUT_LABELREF' to remove and decode the added text + and output the name accordingly. + + You can also check the information stored in the `symbol_ref' in + the definition of `GO_IF_LEGITIMATE_ADDRESS' or + `PRINT_OPERAND_ADDRESS'. */ + +#undef ENCODE_SECTION_INFO +#define ENCODE_SECTION_INFO(DECL) \ +do \ + { \ + if (HALF_PIC_P ()) \ + HALF_PIC_ENCODE (DECL); \ + \ + else if (flag_pic) \ + { \ + rtx rtl = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + ? TREE_CST_RTL (DECL) : DECL_RTL (DECL)); \ + SYMBOL_REF_FLAG (XEXP (rtl, 0)) \ + = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + || ! TREE_PUBLIC (DECL)); \ + } \ + } \ +while (0) + + +/* On most machines, read-only variables, constants, and jump tables + are placed in the text section. If this is not the case on your + machine, this macro should be defined to be the name of a function + (either `data_section' or a function defined in `EXTRA_SECTIONS') + that switches to the section to be used for read-only items. + + If these items should be placed in the text section, this macro + should not be defined. */ + +#if 0 +#undef READONLY_DATA_SECTION +#define READONLY_DATA_SECTION() \ +do \ + { \ + if (TARGET_ELF) \ + { \ + if (in_section != in_rodata) \ + { \ + fprintf (asm_out_file, "\t.section \"rodata\"\n"); \ + in_section = in_rodata; \ + } \ + } \ + else \ + text_section (); \ + } \ +while (0) +#endif + +/* A list of names for sections other than the standard two, which are + `in_text' and `in_data'. You need not define this macro on a + system with no other sections (that GCC needs to use). */ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_rodata, in_data1 + +/* Given a decl node or constant node, choose the section to output it in + and select that section. */ + +#undef SELECT_RTX_SECTION +#define SELECT_RTX_SECTION(MODE, RTX) \ +do \ + { \ + if (MODE == Pmode && HALF_PIC_P () && HALF_PIC_ADDRESS_P (RTX)) \ + data_section (); \ + else \ + readonly_data_section (); \ + } \ +while (0) + +#undef SELECT_SECTION +#define SELECT_SECTION(DECL, RELOC) \ +{ \ + if (RELOC && HALF_PIC_P ()) \ + data_section (); \ + \ + else if (TREE_CODE (DECL) == STRING_CST) \ + { \ + if (flag_writable_strings) \ + data_section (); \ + else \ + readonly_data_section (); \ + } \ + \ + else if (TREE_CODE (DECL) != VAR_DECL) \ + readonly_data_section (); \ + \ + else if (!TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \ + || !DECL_INITIAL (DECL) \ + || (DECL_INITIAL (DECL) != error_mark_node \ + && !TREE_CONSTANT (DECL_INITIAL (DECL)))) \ + data_section (); \ + \ + else \ + readonly_data_section (); \ +} + + +/* Define the strings used for the special svr4 .type and .size directives. + These strings generally do not vary from one system running svr4 to + another, but if a given system (e.g. m88k running svr) needs to use + different pseudo-op names for these, they may be overridden in the + file which includes this one. */ + +#define TYPE_ASM_OP ".type" +#define SIZE_ASM_OP ".size" +#define SET_ASM_OP ".set" + +/* This is how we tell the assembler that a symbol is weak. */ + +#define ASM_WEAKEN_LABEL(FILE,NAME) \ + do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ + fputc ('\n', FILE); } while (0) + +/* The following macro defines the format used to output the second + operand of the .type assembler directive. Different svr4 assemblers + expect various different forms for this operand. The one given here + is just a default. You may need to override it in your machine- + specific tm.h file (depending upon the particulars of your assembler). */ + +#define TYPE_OPERAND_FMT "@%s" + +/* A C statement (sans semicolon) to output to the stdio stream + STREAM any text necessary for declaring the name NAME of an + initialized variable which is being defined. This macro must + output the label definition (perhaps using `ASM_OUTPUT_LABEL'). + The argument DECL is the `VAR_DECL' tree node representing the + variable. + + If this macro is not defined, then the variable name is defined + in the usual manner as a label (by means of `ASM_OUTPUT_LABEL'). */ + +#undef ASM_DECLARE_OBJECT_NAME +#define ASM_DECLARE_OBJECT_NAME(STREAM, NAME, DECL) \ +do \ + { \ + ASM_OUTPUT_LABEL(STREAM,NAME); \ + HALF_PIC_DECLARE (NAME); \ + if (TARGET_ELF) \ + { \ + fprintf (STREAM, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (STREAM, NAME); \ + putc (',', STREAM); \ + fprintf (STREAM, TYPE_OPERAND_FMT, "object"); \ + putc ('\n', STREAM); \ + size_directive_output = 0; \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \ + { \ + size_directive_output = 1; \ + fprintf (STREAM, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (STREAM, NAME); \ + fprintf (STREAM, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + } \ + } \ +while (0) + +/* Output the size directive for a decl in rest_of_decl_compilation + in the case where we did not do so before the initializer. + Once we find the error_mark_node, we know that the value of + size_directive_output was set + by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ + +#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ +do { \ + char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ + if (TARGET_ELF \ + && !flag_inhibit_size_directive && DECL_SIZE (DECL) \ + && ! AT_END && TOP_LEVEL \ + && DECL_INITIAL (DECL) == error_mark_node \ + && !size_directive_output) \ + { \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, name); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + } while (0) + +/* This is how to declare a function name. */ + +#undef ASM_DECLARE_FUNCTION_NAME +#define ASM_DECLARE_FUNCTION_NAME(STREAM,NAME,DECL) \ +do \ + { \ + ASM_OUTPUT_LABEL(STREAM,NAME); \ + HALF_PIC_DECLARE (NAME); \ + if (TARGET_ELF) \ + { \ + fprintf (STREAM, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (STREAM, NAME); \ + putc (',', STREAM); \ + fprintf (STREAM, TYPE_OPERAND_FMT, "function"); \ + putc ('\n', STREAM); \ + ASM_DECLARE_RESULT (STREAM, DECL_RESULT (DECL)); \ + } \ + } \ +while (0) + +/* Write the extra assembler code needed to declare a function's result. + Most svr4 assemblers don't require any special declaration of the + result value, but there are exceptions. */ + +#ifndef ASM_DECLARE_RESULT +#define ASM_DECLARE_RESULT(FILE, RESULT) +#endif + +/* This is how to declare the size of a function. */ + +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ +do \ + { \ + if (TARGET_ELF && !flag_inhibit_size_directive) \ + { \ + char label[256]; \ + static int labelno; \ + labelno++; \ + ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, (FNAME)); \ + fprintf (FILE, ","); \ + assemble_name (FILE, label); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, (FNAME)); \ + putc ('\n', FILE); \ + } \ + } \ +while (0) + +/* Attach a special .ident directive to the end of the file to identify + the version of GCC which compiled this code. The format of the + .ident string is patterned after the ones produced by native svr4 + C compilers. */ + +#define IDENT_ASM_OP ".ident" + +/* Allow #sccs in preprocessor. */ + +#define SCCS_DIRECTIVE + +/* This says what to print at the end of the assembly file */ +#define ASM_FILE_END(STREAM) \ +do \ + { \ + if (HALF_PIC_P ()) \ + HALF_PIC_FINISH (STREAM); \ + \ + if (TARGET_IDENT) \ + { \ + char *fstart = main_input_filename; \ + char *fname; \ + \ + if (!fstart) \ + fstart = ""; \ + \ + fname = fstart + strlen (fstart) - 1; \ + while (fname > fstart && *fname != '/') \ + fname--; \ + \ + if (*fname == '/') \ + fname++; \ + \ + fprintf ((STREAM), "\t%s\t\"GCC: (GNU) %s %s -O%d", \ + IDENT_ASM_OP, version_string, fname, optimize); \ + \ + if (write_symbols == PREFERRED_DEBUGGING_TYPE) \ + fprintf ((STREAM), " -g%d", (int)debug_info_level); \ + \ + else if (write_symbols == DBX_DEBUG) \ + fprintf ((STREAM), " -gstabs%d", (int)debug_info_level); \ + \ + else if (write_symbols == DWARF_DEBUG) \ + fprintf ((STREAM), " -gdwarf%d", (int)debug_info_level); \ + \ + else if (write_symbols != NO_DEBUG) \ + fprintf ((STREAM), " -g??%d", (int)debug_info_level); \ + \ + if (flag_omit_frame_pointer) \ + fprintf ((STREAM), " -fomit-frame-pointer"); \ + \ + if (flag_strength_reduce) \ + fprintf ((STREAM), " -fstrength-reduce"); \ + \ + if (flag_unroll_loops) \ + fprintf ((STREAM), " -funroll-loops"); \ + \ + if (flag_schedule_insns) \ + fprintf ((STREAM), " -fschedule-insns"); \ + \ + if (flag_schedule_insns_after_reload) \ + fprintf ((STREAM), " -fschedule-insns2"); \ + \ + if (flag_force_mem) \ + fprintf ((STREAM), " -fforce-mem"); \ + \ + if (flag_force_addr) \ + fprintf ((STREAM), " -fforce-addr"); \ + \ + if (flag_inline_functions) \ + fprintf ((STREAM), " -finline-functions"); \ + \ + if (flag_caller_saves) \ + fprintf ((STREAM), " -fcaller-saves"); \ + \ + if (flag_pic) \ + fprintf ((STREAM), (flag_pic > 1) ? " -fPIC" : " -fpic"); \ + \ + if (flag_inhibit_size_directive) \ + fprintf ((STREAM), " -finhibit-size-directive"); \ + \ + if (flag_gnu_linker) \ + fprintf ((STREAM), " -fgnu-linker"); \ + \ + if (profile_flag) \ + fprintf ((STREAM), " -p"); \ + \ + if (profile_block_flag) \ + fprintf ((STREAM), " -a"); \ + \ + if (TARGET_IEEE_FP) \ + fprintf ((STREAM), " -mieee-fp"); \ + \ + if (TARGET_HALF_PIC) \ + fprintf ((STREAM), " -mhalf-pic"); \ + \ + if (!TARGET_MOVE) \ + fprintf ((STREAM), " -mno-move"); \ + \ + if (TARGET_386) \ + fprintf ((STREAM), " -m386"); \ + \ + else if (TARGET_486) \ + fprintf ((STREAM), " -m486"); \ + \ + else \ + fprintf ((STREAM), " -munknown-machine"); \ + \ + fprintf ((STREAM), (TARGET_ELF) ? " -melf\"\n" : " -mrose\"\n"); \ + } \ + } \ +while (0) + +/* Tell collect that the object format is OSF/rose. */ +#define OBJECT_FORMAT_ROSE + +/* Tell collect where the appropriate binaries are. */ +#define REAL_NM_FILE_NAME "/usr/ccs/gcc/bfd-nm" +#define REAL_STRIP_FILE_NAME "/usr/ccs/bin/strip" + +/* Use atexit for static constructors/destructors, instead of defining + our own exit function. */ +#define HAVE_ATEXIT + +/* Define this macro meaning that gcc should find the library 'libgcc.a' + by hand, rather than passing the argument '-lgcc' to tell the linker + to do the search */ +#define LINK_LIBGCC_SPECIAL + +/* A C statement to output assembler commands which will identify the object + file as having been compile with GNU CC. We don't need or want this for + OSF1. GDB doesn't need it and kdb doesn't like it */ +#define ASM_IDENTIFY_GCC(FILE) + +/* Identify the front-end which produced this file. To keep symbol + space down, and not confuse kdb, only do this if the language is + not C. */ + +#define ASM_IDENTIFY_LANGUAGE(STREAM) \ +{ \ + if (strcmp (lang_identify (), "c") != 0) \ + output_lang_identify (STREAM); \ +} + +/* Generate calls to memcpy, etc., not bcopy, etc. */ +#define TARGET_MEM_FUNCTIONS + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* Map i386 registers to the numbers dwarf expects. Of course this is different + from what stabs expects. */ + +#define DWARF_DBX_REGISTER_NUMBER(n) \ +((n) == 0 ? 0 \ + : (n) == 1 ? 2 \ + : (n) == 2 ? 1 \ + : (n) == 3 ? 3 \ + : (n) == 4 ? 6 \ + : (n) == 5 ? 7 \ + : (n) == 6 ? 5 \ + : (n) == 7 ? 4 \ + : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \ + : (-1)) + +/* Now what stabs expects in the register. */ +#define STABS_DBX_REGISTER_NUMBER(n) \ +((n) == 0 ? 0 : \ + (n) == 1 ? 2 : \ + (n) == 2 ? 1 : \ + (n) == 3 ? 3 : \ + (n) == 4 ? 6 : \ + (n) == 5 ? 7 : \ + (n) == 6 ? 4 : \ + (n) == 7 ? 5 : \ + (n) + 4) + +#undef DBX_REGISTER_NUMBER +#define DBX_REGISTER_NUMBER(n) ((write_symbols == DWARF_DEBUG) \ + ? DWARF_DBX_REGISTER_NUMBER(n) \ + : STABS_DBX_REGISTER_NUMBER(n)) diff --git a/contrib/gcc/config/i386/perform.h b/contrib/gcc/config/i386/perform.h new file mode 100644 index 00000000000..8d6d0b71dfe --- /dev/null +++ b/contrib/gcc/config/i386/perform.h @@ -0,0 +1,98 @@ +/* Definitions for AT&T assembler syntax for the Intel 80386. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Defines to be able to build libgcc.a with GCC. */ + +/* It might seem that these are not important, since gcc 2 will never + call libgcc for these functions. But programs might be linked with + code compiled by gcc 1, and then these will be used. */ + +/* The arg names used to be a and b, but `a' appears inside strings + and that confuses non-ANSI cpp. */ + +#define perform_udivsi3(arg0,arg1) \ +{ \ + register int dx asm("dx"); \ + register int ax asm("ax"); \ + \ + dx = 0; \ + ax = arg0; \ + asm ("divl %3" : "=a" (ax), "=d" (dx) : "a" (ax), "g" (arg1), "d" (dx)); \ + return ax; \ +} + +#define perform_divsi3(arg0,arg1) \ +{ \ + register int dx asm("dx"); \ + register int ax asm("ax"); \ + register int cx asm("cx"); \ + \ + ax = arg0; \ + cx = arg1; \ + asm ("cltd\n\tidivl %3" : "=a" (ax), "=&d" (dx) : "a" (ax), "c" (cx)); \ + return ax; \ +} + +#define perform_umodsi3(arg0,arg1) \ +{ \ + register int dx asm("dx"); \ + register int ax asm("ax"); \ + \ + dx = 0; \ + ax = arg0; \ + asm ("divl %3" : "=a" (ax), "=d" (dx) : "a" (ax), "g" (arg1), "d" (dx)); \ + return dx; \ +} + +#define perform_modsi3(arg0,arg1) \ +{ \ + register int dx asm("dx"); \ + register int ax asm("ax"); \ + register int cx asm("cx"); \ + \ + ax = arg0; \ + cx = arg1; \ + asm ("cltd\n\tidivl %3" : "=a" (ax), "=&d" (dx) : "a" (ax), "c" (cx)); \ + return dx; \ +} + +#define perform_fixdfsi(arg0) \ +{ \ + auto unsigned short ostatus; \ + auto unsigned short nstatus; \ + auto int ret; \ + auto double tmp; \ + \ + &ostatus; /* guarantee these land in memory */ \ + &nstatus; \ + &ret; \ + &tmp; \ + \ + asm volatile ("fnstcw %0" : "=m" (ostatus)); \ + nstatus = ostatus | 0x0c00; \ + asm volatile ("fldcw %0" : /* no outputs */ : "m" (nstatus)); \ + tmp = arg0; \ + asm volatile ("fldl %0" : /* no outputs */ : "m" (tmp)); \ + asm volatile ("fistpl %0" : "=m" (ret)); \ + asm volatile ("fldcw %0" : /* no outputs */ : "m" (ostatus)); \ + \ + return ret; \ +} + diff --git a/contrib/gcc/config/i386/sco.h b/contrib/gcc/config/i386/sco.h new file mode 100644 index 00000000000..37dc0326698 --- /dev/null +++ b/contrib/gcc/config/i386/sco.h @@ -0,0 +1,117 @@ +/* Definitions for Intel 386 running SCO Unix System V. + Copyright (C) 1988, 1992, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Mostly it's like AT&T Unix System V. */ + +#include "i386/sysv3.h" + +/* By default, target has a 80387, uses IEEE compatible arithmetic, + and returns float values in the 387, ie, + (TARGET_80387 | TARGET_FLOAT_RETURNS_IN_80387) + + SCO's software emulation of a 387 fails to handle the `fucomp' + opcode. fucomp is only used when generating IEEE compliant code. + So don't make TARGET_IEEE_FP default for SCO. */ + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT 0201 + +/* Let's guess that the SCO software FPU emulator can't handle + 80-bit XFmode insns, so don't generate them. */ +#undef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE 64 + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}} crtbegin.o%s" + +#define ENDFILE_SPEC "crtend.o%s crtn.o%s" + +/* Library spec, including SCO international language support. */ + +#undef LIB_SPEC +#define LIB_SPEC \ + "%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} %{scointl:libintl.a%s} -lc" + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -DM_UNIX -DM_I386 -DM_COFF -DM_WORDSWAP -Asystem(unix) -Asystem(svr3) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC "%{scointl:-DM_INTERNAT}" + +/* This spec is used for telling cpp whether char is signed or not. */ + +#undef SIGNED_CHAR_SPEC +#if DEFAULT_SIGNED_CHAR +#define SIGNED_CHAR_SPEC \ + "%{funsigned-char:-D__CHAR_UNSIGNED__ -D_CHAR_UNSIGNED}" +#else +#define SIGNED_CHAR_SPEC \ + "%{!fsigned-char:-D__CHAR_UNSIGNED__ -D_CHAR_UNSIGNED}" +#endif + +/* Use atexit for static destructors, instead of defining + our own exit function. */ +#define HAVE_ATEXIT + +/* Specify the size_t type. */ +#define SIZE_TYPE "unsigned int" + +#if 0 /* Not yet certain whether this is needed. */ +/* If no 387, use the general regs to return floating values, + since this system does not emulate the 80387. */ + +#undef VALUE_REGNO +#define VALUE_REGNO(MODE) \ + ((TARGET_80387 + && ((MODE) == SFmode || (MODE) == DFmode || (MODE) == XFmode) + ? FIRST_FLOAT_REG : 0) + +#undef HARD_REGNO_MODE_OK +#define HARD_REGNO_MODE_OK(REGNO, MODE) \ + ((REGNO) < 2 ? 1 \ + : (REGNO) < 4 ? 1 \ + : FP_REGNO_P (REGNO) ? ((GET_MODE_CLASS (MODE) == MODE_FLOAT \ + || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) \ + && TARGET_80387 \ + && GET_MODE_UNIT_SIZE (MODE) <= 8) \ + : (MODE) != QImode) +#endif + +/* caller has to pop the extra argument passed to functions that return + structures. */ + +#undef RETURN_POPS_ARGS +#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \ + (TREE_CODE (FUNTYPE) == IDENTIFIER_NODE ? 0 \ + : (TARGET_RTD \ + && (TYPE_ARG_TYPES (FUNTYPE) == 0 \ + || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (FUNTYPE))) \ + == void_type_node))) ? (SIZE) \ + : 0) +/* On other 386 systems, the last line looks like this: + : (aggregate_value_p (TREE_TYPE (FUNTYPE))) ? GET_MODE_SIZE (Pmode) : 0) */ + +/* Handle #pragma pack. */ +#define HANDLE_SYSV_PRAGMA diff --git a/contrib/gcc/config/i386/sco4.h b/contrib/gcc/config/i386/sco4.h new file mode 100644 index 00000000000..fc389b4d1bc --- /dev/null +++ b/contrib/gcc/config/i386/sco4.h @@ -0,0 +1,86 @@ +/* Definitions for Intel 386 running SCO Unix System V 3.2 Version 4. + Written by Chip Salzenberg. + Copyright (C) 1992, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Mostly it's like earlier SCO UNIX. */ + +#include "i386/sco.h" + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{scoxpg3:%{p:mcrt1X.o%s}%{!p:crt1X.o%s}} \ + %{!scoxpg3:\ + %{posix:%{p:mcrt1P.o%s}%{!p:crt1P.o%s}} \ + %{!posix:\ + %{ansi:%{p:mcrt1A.o%s}%{!p:crt1A.o%s}} \ + %{!ansi:%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}}}} \ + crtbegin.o%s" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC \ + "crtend.o%s \ + %{scoxpg3:crtnX.o%s} \ + %{!scoxpg3:\ + %{posix:crtnP.o%s} \ + %{!posix:\ + %{ansi:crtnA.o%s} \ + %{!ansi:crtn.o%s}}}" + +/* Library spec. */ + +#undef LIB_SPEC +#define LIB_SPEC \ + "%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} \ + %{scoxpg3:-lcX -lcP -lcA} \ + %{!scoxpg3:\ + %{posix:-lcP -lcA} \ + %{!posix:\ + %{ansi:-lcA} \ + %{!ansi:%{scointl:-lintl} -lc}}}" + +/* Macros, macros everywhere: + Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES \ + "-Asystem(unix) -Asystem(svr3) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC \ + "-D_i386 -D_M_I386 -D_M_I86 -D_M_I86SM -D_M_SDATA -D_M_STEXT \ + -D_unix -D_M_UNIX -D_M_XENIX \ + -D_M_SYS5 -D_M_SYSV -D_M_SYS3 -D_M_SYSIII \ + -D_M_COFF -D_M_BITFIELDS -D_M_WORDSWAP \ + %{scoxpg3:-D_XOPEN_SOURCE -D_STRICT_NAMES} \ + %{!scoxpg3:%{posix:-D_POSIX_SOURCE -D_STRICT_NAMES}} \ + %{!scoxpg3:%{!posix:\ + %{ansi:-D_STRICT_NAMES}%{!ansi:\ + -Di386 -DM_I386 -DM_I86 -DM_I86SM -DM_SDATA -DM_STEXT \ + -Dunix -DM_UNIX -DM_XENIX \ + -DM_SYS5 -DM_SYSV -DM_SYS3 -DM_SYSIII \ + -DM_COFF -DM_BITFIELDS -DM_WORDSWAP \ + %{scointl:-D_M_INTERNAT -DM_INTERNAT} \ + %{traditional:-D_KR -D_SVID -D_NO_PROTOTYPE}}}}" + +/* The system headers are C++-aware. */ +#define NO_IMPLICIT_EXTERN_C diff --git a/contrib/gcc/config/i386/sco4dbx.h b/contrib/gcc/config/i386/sco4dbx.h new file mode 100644 index 00000000000..0387c2436c3 --- /dev/null +++ b/contrib/gcc/config/i386/sco4dbx.h @@ -0,0 +1,81 @@ +/* Definitions for Intel 386 running SCO Unix System V 3.2 Version 4.s, + using dbx-in-coff encapsulation. + Copyright (C) 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Mostly it's like earlier SCO UNIX. */ + +#include "i386/scodbx.h" + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!r:%{!z:gcc.ifile%s}%{z:gccz.ifile%s}}\ + %{scoxpg3:%{p:mcrt1X.o%s}%{!p:crt1X.o%s}} \ + %{!scoxpg3:\ + %{posix:%{p:mcrt1P.o%s}%{!p:crt1P.o%s}} \ + %{!posix:\ + %{ansi:%{p:mcrt1A.o%s}%{!p:crt1A.o%s}} \ + %{!ansi:%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}}}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC \ + "%{scoxpg3:crtnX.o%s} \ + %{!scoxpg3:\ + %{posix:crtnP.o%s} \ + %{!posix:\ + %{ansi:crtnA.o%s} \ + %{!ansi:crtn.o%s}}}" + +/* Library spec. */ + +#undef LIB_SPEC +#define LIB_SPEC \ + "%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} \ + %{scoxpg3:-lcX -lcP -lcA} \ + %{!scoxpg3:\ + %{posix:-lcP -lcA} \ + %{!posix:\ + %{ansi:-lcA} \ + %{!ansi:%{scointl:-lintl} -lc}}}" + +/* Macros, macros everywhere: + Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Di386 -Dunix -Asystem(unix) -Asystem(svr3) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC \ + "-D_M_I386 -D_M_I86 -D_M_I86SM -D_M_SDATA -D_M_STEXT \ + -D_M_UNIX -D_M_XENIX \ + -D_M_SYS5 -D_M_SYSV -D_M_SYS3 -D_M_SYSIII \ + -D_M_COFF -D_M_BITFIELDS -D_M_WORDSWAP \ + %{scoxpg3:-D_XOPEN_SOURCE -D_STRICT_NAMES} \ + %{!scoxpg3:%{posix:-D_POSIX_SOURCE -D_STRICT_NAMES}} \ + %{!scoxpg3:%{!posix:\ + %{ansi:-D_STRICT_NAMES}%{!ansi:\ + -DM_I386 -DM_I86 -DM_I86SM -DM_SDATA -DM_STEXT \ + -DM_UNIX -DM_XENIX \ + -DM_SYS5 -DM_SYSV -DM_SYS3 -DM_SYSIII \ + -DM_COFF -DM_BITFIELDS -DM_WORDSWAP \ + %{scointl:-D_M_INTERNAT -DM_INTERNAT} \ + %{traditional:-D_KR -D_SVID -D_NO_PROTOTYPE}}}}" diff --git a/contrib/gcc/config/i386/scodbx.h b/contrib/gcc/config/i386/scodbx.h new file mode 100644 index 00000000000..1309735cf1e --- /dev/null +++ b/contrib/gcc/config/i386/scodbx.h @@ -0,0 +1,92 @@ +/* Definitions for Intel 386 running SCO Unix System V, + using dbx-in-coff encapsulation. + Copyright (C) 1992, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/svr3dbx.h" + +/* Overridden defines for SCO systems from sco.h. */ + +/* By default, target has a 80387, uses IEEE compatible arithmetic, + and returns float values in the 387, ie, + (TARGET_80387 | TARGET_FLOAT_RETURNS_IN_80387) + + SCO's software emulation of a 387 fails to handle the `fucomp' + opcode. fucomp is only used when generating IEEE compliant code. + So don't make TARGET_IEEE_FP default for SCO. */ + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT 0201 + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!r:%{!z:svr3.ifile%s}%{z:svr3z.ifile%s}}\ + %{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}" + +/* Library spec, including SCO international language support. */ + +#undef LIB_SPEC +#define LIB_SPEC \ + "%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} %{scointl:libintl.a%s} -lc" + +/* Specify predefined symbols in preprocessor. */ + +#undef CPP_PREDEFINES +#define CPP_PREDEFINES "-Dunix -Di386 -DM_UNIX -DM_I386 -DM_COFF -DM_WORDSWAP -Asystem(unix) -Asystem(svr3) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC "%{scointl:-DM_INTERNAT}" + +/* This spec is used for telling cpp whether char is signed or not. */ + +#undef SIGNED_CHAR_SPEC +#if DEFAULT_SIGNED_CHAR +#define SIGNED_CHAR_SPEC \ + "%{funsigned-char:-D__CHAR_UNSIGNED__ -D_CHAR_UNSIGNED}" +#else +#define SIGNED_CHAR_SPEC \ + "%{!fsigned-char:-D__CHAR_UNSIGNED__ -D_CHAR_UNSIGNED}" +#endif + +/* Use atexit for static destructors, instead of defining + our own exit function. */ +#define HAVE_ATEXIT + +/* caller has to pop the extra argument passed to functions that return + structures. */ + +#undef RETURN_POPS_ARGS +#define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) \ + (TREE_CODE (FUNTYPE) == IDENTIFIER_NODE ? 0 \ + : (TARGET_RTD \ + && (TYPE_ARG_TYPES (FUNTYPE) == 0 \ + || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (FUNTYPE))) \ + == void_type_node))) ? (SIZE) \ + : 0) +/* On other 386 systems, the last line looks like this: + : (aggregate_value_p (TREE_TYPE (FUNTYPE))) ? GET_MODE_SIZE (Pmode) : 0) */ + +/* Use periods rather than dollar signs in special g++ assembler names. */ + +#define NO_DOLLAR_IN_LABEL + +/* Handle #pragma pack. */ +#define HANDLE_SYSV_PRAGMA diff --git a/contrib/gcc/config/i386/seq-gas.h b/contrib/gcc/config/i386/seq-gas.h new file mode 100644 index 00000000000..2ee071925bc --- /dev/null +++ b/contrib/gcc/config/i386/seq-gas.h @@ -0,0 +1,46 @@ +/* Definitions for Sequent Intel 386 using GAS. + Copyright (C) 1992 Free Software Foundation, Inc. + +/* Mostly it's like a Sequent 386 without GAS. */ + +#include "i386/sequent.h" + +/* A C statement or statements which output an assembler instruction + opcode to the stdio stream STREAM. The macro-operand PTR is a + variable of type `char *' which points to the opcode name in its + "internal" form--the form that is written in the machine description. + + GAS version 1.38.1 doesn't understand the `repz' opcode mnemonic. + So use `repe' instead. */ + +#undef ASM_OUTPUT_OPCODE +#define ASM_OUTPUT_OPCODE(STREAM, PTR) \ +{ \ + if ((PTR)[0] == 'r' \ + && (PTR)[1] == 'e' \ + && (PTR)[2] == 'p') \ + { \ + if ((PTR)[3] == 'z') \ + { \ + fprintf (STREAM, "repe"); \ + (PTR) += 4; \ + } \ + else if ((PTR)[3] == 'n' && (PTR)[4] == 'z') \ + { \ + fprintf (STREAM, "repne"); \ + (PTR) += 5; \ + } \ + } \ +} + +/* Define macro used to output shift-double opcodes when the shift + count is in %cl. Some assemblers require %cl as an argument; + some don't. + + GAS requires the %cl argument, so override i386/unix.h. */ + +#undef AS3_SHIFT_DOUBLE +#define AS3_SHIFT_DOUBLE(a,b,c,d) AS3 (a,b,c,d) + +/* Print opcodes the way that GAS expects them. */ +#define GAS_MNEMONICS 1 diff --git a/contrib/gcc/config/i386/seq-sysv3.h b/contrib/gcc/config/i386/seq-sysv3.h new file mode 100644 index 00000000000..e3182ee1a77 --- /dev/null +++ b/contrib/gcc/config/i386/seq-sysv3.h @@ -0,0 +1,56 @@ +/* Sequent DYNIX/ptx 1.x (SVr3) */ + +#include "i386/sysv3.h" + +/* Sequent Symmetry SVr3 doesn't have crtn.o; crt1.o doesn't work + but crt0.o does. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ +"%{pg:gcrt0.o%s}\ + %{!pg:%{posix:%{p:mcrtp0.o%s}%{!p:crtp0.o%s}}\ + %{!posix:%{p:mcrt0.o%s}%{!p:crt0.o%s}}} crtbegin.o%s\ + %{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp}" + +#undef LIB_SPEC +#define LIB_SPEC \ +"%{posix:-lcposix}\ + %{shlib:-lc_s}\ + %{fshared-data:-lpps -lseq} -lc crtend.o%s" + +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} -D_SEQUENT_=1" + +/* Although the .init section is used, it is not automatically invoked. + This because the _start() function in /lib/crt0.o never calls anything + from the .init section */ +#define INVOKE__main + +/* Assembler pseudo-op for initialized shared variables (.shdata). */ +#undef SHARED_SECTION_ASM_OP +#define SHARED_SECTION_ASM_OP ".section .shdata, \"ws\"" + +/* Assembler pseudo-op for uninitialized shared global variables (.shbss). */ +#undef ASM_OUTPUT_SHARED_COMMON +#define ASM_OUTPUT_SHARED_COMMON(FILE, NAME, SIZE, ROUNDED) \ +( fputs(".comm ", (FILE)), \ + assemble_name((FILE), (NAME)), \ + fprintf((FILE), ",%u,-3\n", (SIZE))) + +/* Assembler pseudo-op for uninitialized shared local variables (.shbss). */ +#undef SHARED_BSS_SECTION_ASM_OP +#define SHARED_BSS_SECTION_ASM_OP ".section .shbss, \"bs\"" +#undef BSS_SECTION_FUNCTION +#define BSS_SECTION_FUNCTION \ +void \ +bss_section () \ +{ \ + if (in_section != in_bss) \ + { \ + if (flag_shared_data) \ + fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP); \ + else \ + fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP); \ + in_section = in_bss; \ + } \ +} diff --git a/contrib/gcc/config/i386/seq2-sysv3.h b/contrib/gcc/config/i386/seq2-sysv3.h new file mode 100644 index 00000000000..763c5f0adcc --- /dev/null +++ b/contrib/gcc/config/i386/seq2-sysv3.h @@ -0,0 +1,8 @@ +/* Sequent DYNIX/ptx 2.x (SVr3) */ + +#include "i386/seq-sysv3.h" + +/* Use atexit for static destructors, instead of defining + our own exit function. */ +#define HAVE_ATEXIT + diff --git a/contrib/gcc/config/i386/sequent.h b/contrib/gcc/config/i386/sequent.h new file mode 100644 index 00000000000..4d76c389b6a --- /dev/null +++ b/contrib/gcc/config/i386/sequent.h @@ -0,0 +1,152 @@ +/* Definitions for Sequent Intel 386. + Copyright (C) 1988, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/i386.h" + +/* Use the BSD assembler syntax. */ + +#include "i386/bsd.h" + +/* By default, don't use IEEE compatible arithmetic comparisons + because the assembler can't handle the fucom insn. + Return float values in the 387. + (TARGET_80387 | TARGET_FLOAT_RETURNS_IN_80387) */ + +#undef TARGET_DEFAULT +#define TARGET_DEFAULT 0201 + +/* Specify predefined symbols in preprocessor. */ + +#define CPP_PREDEFINES "-Dunix -Di386 -Dsequent -Asystem(unix) -Acpu(i386) -Amachine(i386)" + +/* Pass -Z and -ZO options to the linker. */ + +#define LINK_SPEC "%{Z*}" + +#if 0 /* Dynix 3.1 is said to accept -L. */ +/* Dynix V3.0.12 doesn't accept -L at all. */ + +#define LINK_LIBGCC_SPECIAL +#endif + +/* Link with libg.a when debugging, for dbx's sake. */ + +#define LIB_SPEC "%{g:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p} " + +/* We don't want to output SDB debugging information. */ + +#undef SDB_DEBUGGING_INFO + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO + +/* Sequent Symmetry has size_t defined as int in /usr/include/sys/types.h */ +#define SIZE_TYPE "int" + +/* gcc order is ax, dx, cx, bx, si, di, bp, sp, st, st. + * dbx order is ax, dx, cx, st(0), st(1), bx, si, di, st(2), st(3), + * st(4), st(5), st(6), st(7), sp, bp */ + +/* ??? The right thing would be to change the ordering of the + registers to correspond to the conventions of this system, + and get rid of DBX_REGISTER_NUMBER. */ + +#undef DBX_REGISTER_NUMBER +#define DBX_REGISTER_NUMBER(n) \ +((n) < 3 ? (n) : (n) < 6 ? (n) + 2 \ + : (n) == 6 ? 15 : (n) == 7 ? 14 : 3) + +/* malcolmp@hydra.maths.unsw.EDU.AU says these two definitions + fix trouble in dbx. */ +#undef DBX_OUTPUT_LBRAC +#define DBX_OUTPUT_LBRAC(file,name) \ + fprintf (asmfile, "%s %d,0,%d,", ASM_STABN_OP, N_LBRAC, depth); \ + assemble_name (asmfile, buf); \ + fprintf (asmfile, "\n"); + +#undef DBX_OUTPUT_RBRAC +#define DBX_OUTPUT_RBRAC(file,name) \ + fprintf (asmfile, "%s %d,0,%d,", ASM_STABN_OP, N_RBRAC, depth); \ + assemble_name (asmfile, buf); \ + fprintf (asmfile, "\n"); + +/* Prevent anything from being allocated in the register pair cx/bx, + since that would confuse GDB. */ + +#undef HARD_REGNO_MODE_OK +#define HARD_REGNO_MODE_OK(REGNO, MODE) \ + (((REGNO) < 2 ? 1 \ + : (REGNO) < 4 ? 1 \ + : FP_REGNO_P (REGNO) ? (GET_MODE_CLASS (MODE) == MODE_FLOAT \ + || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) \ + : (MODE) != QImode) \ + && ! (REGNO == 2 && GET_MODE_UNIT_SIZE (MODE) > 4)) + +/* Output assembler code to FILE to increment profiler label # LABELNO + for profiling a function entry. */ + +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(FILE, LABELNO) \ + fprintf (FILE, "\tmovl $.LP%d,%%eax\n\tcall mcount\n", (LABELNO)); + +/* Assembler pseudo-op for shared data segment. */ +#define SHARED_SECTION_ASM_OP ".shdata" + +/* A C statement or statements which output an assembler instruction + opcode to the stdio stream STREAM. The macro-operand PTR is a + variable of type `char *' which points to the opcode name in its + "internal" form--the form that is written in the machine description. + + The Sequent assembler (identified as "Balance 8000 Assembler + 07/17/85 3.90" by "as -v") does not understand the `movs[bwl]' string + move mnemonics - it uses `smov[bwl]' instead. Change "movs" into + "smov", carefully avoiding the sign-extend opcodes. */ + +#define ASM_OUTPUT_OPCODE(STREAM, PTR) \ +{ \ + if ((PTR)[0] == 'm' \ + && (PTR)[1] == 'o' \ + && (PTR)[2] == 'v' \ + && (PTR)[3] == 's' \ + && ((PTR)[4] == 'b' || (PTR)[4] == 'w' || (PTR)[4] == 'l') \ + && ((PTR)[5] == ' ' || (PTR)[5] == '\t'|| (PTR)[5] == '\0')) \ + { \ + fprintf (STREAM, "smov"); \ + (PTR) += 4; \ + } \ +} + +/* 10-Aug-92 pes Local labels are prefixed with ".L" */ +#undef LPREFIX +#define LPREFIX ".L" + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER)\ + sprintf ((BUF), "*.%s%d", (PREFIX), (NUMBER)) + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)\ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM) + +/* The native compiler passes the address of the returned structure in eax. */ +#undef STRUCT_VALUE +#undef STRUCT_VALUE_INCOMING +#define STRUCT_VALUE_REGNUM 0 diff --git a/contrib/gcc/config/i386/sol2-c1.asm b/contrib/gcc/config/i386/sol2-c1.asm new file mode 100644 index 00000000000..72fdfb87cc2 --- /dev/null +++ b/contrib/gcc/config/i386/sol2-c1.asm @@ -0,0 +1,156 @@ +! crt1.s for Solaris 2, x86 + +! Copyright (C) 1993 Free Software Foundation, Inc. +! Written By Fred Fish, Nov 1992 +! +! This file is free software; you can redistribute it and/or modify it +! under the terms of the GNU General Public License as published by the +! Free Software Foundation; either version 2, or (at your option) any +! later version. +! +! In addition to the permissions in the GNU General Public License, the +! Free Software Foundation gives you unlimited permission to link the +! compiled version of this file with other programs, and to distribute +! those programs without any restriction coming from the use of this +! file. (The General Public License restrictions do apply in other +! respects; for example, they cover modification of the file, and +! distribution when not linked into another program.) +! +! This file is distributed in the hope that it will be useful, but +! WITHOUT ANY WARRANTY; without even the implied warranty of +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +! General Public License for more details. +! +! You should have received a copy of the GNU General Public License +! along with this program; see the file COPYING. If not, write to +! the Free Software Foundation, 59 Temple Place - Suite 330, +! Boston, MA 02111-1307, USA. +! +! As a special exception, if you link this library with files +! compiled with GCC to produce an executable, this does not cause +! the resulting executable to be covered by the GNU General Public License. +! This exception does not however invalidate any other reasons why +! the executable file might be covered by the GNU General Public License. +! + +! This file takes control of the process from the kernel, as specified +! in section 3 of the System V Application Binary Interface, Intel386 +! Processor Supplement. It has been constructed from information obtained +! from the ABI, information obtained from single stepping existing +! Solaris executables through their startup code with gdb, and from +! information obtained by single stepping executables on other i386 SVR4 +! implementations. This file is the first thing linked into any executable. + + .file "crt1.s" + .ident "GNU C crt1.s" + .weak _cleanup + .weak _DYNAMIC + .text + +! Start creating the initial frame by pushing a NULL value for the return +! address of the initial frame, and mark the end of the stack frame chain +! (the innermost stack frame) with a NULL value, per page 3-32 of the ABI. +! Initialize the first stack frame pointer in %ebp (the contents of which +! are unspecified at process initialization). + + .globl _start +_start: + pushl $0x0 + pushl $0x0 + movl %esp,%ebp + +! As specified per page 3-32 of the ABI, %edx contains a function +! pointer that should be registered with atexit(), for proper +! shared object termination. Just push it onto the stack for now +! to preserve it. We want to register _cleanup() first. + + pushl %edx + +! Check to see if there is an _cleanup() function linked in, and if +! so, register it with atexit() as the last thing to be run by +! atexit(). + + movl $_cleanup,%eax + testl %eax,%eax + je .L1 + pushl $_cleanup + call atexit + addl $0x4,%esp +.L1: + +! Now check to see if we have an _DYNAMIC table, and if so then +! we need to register the function pointer previously in %edx, but +! now conveniently saved on the stack as the argument to pass to +! atexit(). + + movl $_DYNAMIC,%eax + testl %eax,%eax + je .L2 + call atexit +.L2: + +! Register _fini() with atexit(). We will take care of calling _init() +! directly. + + pushl $_fini + call atexit + +! Compute the address of the environment vector on the stack and load +! it into the global variable _environ. Currently argc is at 8 off +! the frame pointer. Fetch the argument count into %eax, scale by the +! size of each arg (4 bytes) and compute the address of the environment +! vector which is 16 bytes (the two zero words we pushed, plus argc, +! plus the null word terminating the arg vector) further up the stack, +! off the frame pointer (whew!). + + movl 8(%ebp),%eax + leal 16(%ebp,%eax,4),%edx + movl %edx,_environ + +! Push the environment vector pointer, the argument vector pointer, +! and the argument count on to the stack to set up the arguments +! for _init(), _fpstart(), and main(). Note that the environment +! vector pointer and the arg count were previously loaded into +! %edx and %eax respectively. The only new value we need to compute +! is the argument vector pointer, which is at a fixed address off +! the initial frame pointer. + + pushl %edx + leal 12(%ebp),%edx + pushl %edx + pushl %eax + +! Call _init(argc, argv, environ), _fpstart(argc, argv, environ), and +! main(argc, argv, environ). + + call _init + call __fpstart + call main + +! Pop the argc, argv, and environ arguments off the stack, push the +! value returned from main(), and call exit(). + + addl $12,%esp + pushl %eax + call exit + +! An inline equivalent of _exit, as specified in Figure 3-26 of the ABI. + + pushl $0x0 + movl $0x1,%eax + lcall $7,$0 + +! If all else fails, just try a halt! + + hlt + .type _start,@function + .size _start,.-_start + +! A dummy profiling support routine for non-profiling executables, +! in case we link in some objects that have been compiled for profiling. + + .globl _mcount +_mcount: + ret + .type _mcount,@function + .size _mcount,.-_mcount diff --git a/contrib/gcc/config/i386/sol2-ci.asm b/contrib/gcc/config/i386/sol2-ci.asm new file mode 100644 index 00000000000..439c709ba68 --- /dev/null +++ b/contrib/gcc/config/i386/sol2-ci.asm @@ -0,0 +1,51 @@ +! crti.s for Solaris 2, x86. + +! Copyright (C) 1993 Free Software Foundation, Inc. +! Written By Fred Fish, Nov 1992 +! +! This file is free software; you can redistribute it and/or modify it +! under the terms of the GNU General Public License as published by the +! Free Software Foundation; either version 2, or (at your option) any +! later version. +! +! In addition to the permissions in the GNU General Public License, the +! Free Software Foundation gives you unlimited permission to link the +! compiled version of this file with other programs, and to distribute +! those programs without any restriction coming from the use of this +! file. (The General Public License restrictions do apply in other +! respects; for example, they cover modification of the file, and +! distribution when not linked into another program.) +! +! This file is distributed in the hope that it will be useful, but +! WITHOUT ANY WARRANTY; without even the implied warranty of +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +! General Public License for more details. +! +! You should have received a copy of the GNU General Public License +! along with this program; see the file COPYING. If not, write to +! the Free Software Foundation, 59 Temple Place - Suite 330, +! Boston, MA 02111-1307, USA. +! +! As a special exception, if you link this library with files +! compiled with GCC to produce an executable, this does not cause +! the resulting executable to be covered by the GNU General Public License. +! This exception does not however invalidate any other reasons why +! the executable file might be covered by the GNU General Public License. +! + +! This file just supplies labeled starting points for the .init and .fini +! sections. It is linked in before the values-Xx.o files and also before +! crtbegin.o. + + .file "crti.s" + .ident "GNU C crti.s" + + .section .init + .globl _init + .type _init,@function +_init: + + .section .fini + .globl _fini + .type _fini,@function +_fini: diff --git a/contrib/gcc/config/i386/sol2-cn.asm b/contrib/gcc/config/i386/sol2-cn.asm new file mode 100644 index 00000000000..3f3bad93300 --- /dev/null +++ b/contrib/gcc/config/i386/sol2-cn.asm @@ -0,0 +1,46 @@ +! crtn.s for Solaris 2, x86. + +! Copyright (C) 1993 Free Software Foundation, Inc. +! Written By Fred Fish, Nov 1992 +! +! This file is free software; you can redistribute it and/or modify it +! under the terms of the GNU General Public License as published by the +! Free Software Foundation; either version 2, or (at your option) any +! later version. +! +! In addition to the permissions in the GNU General Public License, the +! Free Software Foundation gives you unlimited permission to link the +! compiled version of this file with other programs, and to distribute +! those programs without any restriction coming from the use of this +! file. (The General Public License restrictions do apply in other +! respects; for example, they cover modification of the file, and +! distribution when not linked into another program.) +! +! This file is distributed in the hope that it will be useful, but +! WITHOUT ANY WARRANTY; without even the implied warranty of +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +! General Public License for more details. +! +! You should have received a copy of the GNU General Public License +! along with this program; see the file COPYING. If not, write to +! the Free Software Foundation, 59 Temple Place - Suite 330, +! Boston, MA 02111-1307, USA. +! +! As a special exception, if you link this library with files +! compiled with GCC to produce an executable, this does not cause +! the resulting executable to be covered by the GNU General Public License. +! This exception does not however invalidate any other reasons why +! the executable file might be covered by the GNU General Public License. +! + +! This file just supplies returns for the .init and .fini sections. It is +! linked in after all other files. + + .file "crtn.o" + .ident "GNU C crtn.o" + + .section .init + ret $0x0 + + .section .fini + ret $0x0 diff --git a/contrib/gcc/config/i386/sol2.h b/contrib/gcc/config/i386/sol2.h new file mode 100644 index 00000000000..cc5ebca7d7e --- /dev/null +++ b/contrib/gcc/config/i386/sol2.h @@ -0,0 +1,91 @@ +/* Target definitions for GNU compiler for Intel 80386 running Solaris 2 + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + + Written by Fred Fish (fnf@cygnus.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/sysv4.h" + +/* The Solaris 2.0 x86 linker botches alignment of code sections. + It tries to align to a 16 byte boundary by padding with 0x00000090 + ints, rather than 0x90 bytes (nop). This generates trash in the + ".init" section since the contribution from crtbegin.o is only 7 + bytes. The linker pads it to 16 bytes with a single 0x90 byte, and + two 0x00000090 ints, which generates a segmentation violation when + executed. This macro forces the assembler to do the padding, since + it knows what it is doing. */ + +#define FORCE_INIT_SECTION_ALIGN do { asm (ALIGN_ASM_OP ## " 16"); } while (0) +#define FORCE_FINI_SECTION_ALIGN FORCE_INIT_SECTION_ALIGN + +/* Add "sun" to the list of symbols defined for SVR4. */ +#undef CPP_PREDEFINES +#define CPP_PREDEFINES \ + "-Di386 -Dunix -D__svr4__ -D__SVR4 -Dsun \ + -Asystem(unix) -Asystem(svr4) -Acpu(i386) -Amachine(i386)" + +#undef CPP_SPEC +#define CPP_SPEC "\ + %{compat-bsd:-iwithprefixbefore ucbinclude -I/usr/ucbinclude}" + +#undef LIB_SPEC +#define LIB_SPEC \ + "%{compat-bsd:-lucb -lsocket -lnsl -lelf -laio} %{!shared:%{!symbolic:-lc}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtend.o%s %{pg:crtn.o%s}%{!pg:crtn.o%s}" + +/* This should be the same as in svr4.h, except with -R added. */ +#undef LINK_SPEC +#define LINK_SPEC \ + "%{h*} %{V} %{v:%{!V:-V}} \ + %{b} %{Wl,*:%*} \ + %{static:-dn -Bstatic} \ + %{shared:-G -dy -z text} \ + %{symbolic:-Bsymbolic -G -dy -z text} \ + %{G:-G} \ + %{YP,*} \ + %{R*} \ + %{compat-bsd: \ + %{!YP,*:%{p:-Y P,/usr/ucblib:/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \ + %{!p:-Y P,/usr/ucblib:/usr/ccs/lib:/usr/lib}} \ + -R /usr/ucblib} \ + %{!compat-bsd: \ + %{!YP,*:%{p:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \ + %{!p:-Y P,/usr/ccs/lib:/usr/lib}}} \ + %{Qy:} %{!Qn:-Qy}" + +/* This defines which switch letters take arguments. + It is as in svr4.h but with -R added. */ + +#undef SWITCH_TAKES_ARG +#define SWITCH_TAKES_ARG(CHAR) \ + ( (CHAR) == 'D' \ + || (CHAR) == 'U' \ + || (CHAR) == 'o' \ + || (CHAR) == 'e' \ + || (CHAR) == 'u' \ + || (CHAR) == 'I' \ + || (CHAR) == 'm' \ + || (CHAR) == 'L' \ + || (CHAR) == 'R' \ + || (CHAR) == 'A' \ + || (CHAR) == 'h' \ + || (CHAR) == 'z') + diff --git a/contrib/gcc/config/i386/sun.h b/contrib/gcc/config/i386/sun.h new file mode 100644 index 00000000000..ecc0e8294d2 --- /dev/null +++ b/contrib/gcc/config/i386/sun.h @@ -0,0 +1,83 @@ +/* Definitions for Intel 386 running SunOS 4.0. + Copyright (C) 1988, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "i386/i386.h" + +/* Use the Sun assembler syntax. */ + +#include "i386/sun386.h" + +/* Use crt0.o as a startup file. */ + +#define STARTFILE_SPEC \ + "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}" + +#define LIB_SPEC "%{g:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p} \ +%{g:-lg} %{sun386:}" +/* That last item is just to prevent a spurious error. */ + +#undef LINK_SPEC +#define LINK_SPEC \ + "%{!nostdlib:%{!r*:%{!e*:-e _start}}} -dc -dp %{static:-Bstatic}" + +/* Extra switches to give the assembler. */ + +#define ASM_SPEC "%{R} -i386 %{keep-local-as-symbols:-L}" + +/* Specify predefined symbols in preprocessor. */ + +#define CPP_PREDEFINES "-Dunix -Di386 -Dsun386 -Dsun -Asystem(unix) -Asystem(bsd) -Acpu(i386) -Amachine(i386)" + +/* Allow #sccs in preprocessor. */ + +#define SCCS_DIRECTIVE + +/* Output #ident as a .ident. */ + +#define ASM_OUTPUT_IDENT(FILE, NAME) fprintf (FILE, "\t.ident \"%s\"\n", NAME); + +/* We don't want to output SDB debugging information. */ + +#undef SDB_DEBUGGING_INFO + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +/* Force structure alignment to the type used for a bitfield. */ + +#define PCC_BITFIELD_TYPE_MATTERS 1 + +/* This is partly guess. */ + +#undef DBX_REGISTER_NUMBER +#define DBX_REGISTER_NUMBER(n) \ + ((n) == 0 ? 11 : (n) == 1 ? 9 : (n) == 2 ? 10 : (n) == 3 ? 8 \ + : (n) == 4 ? 5 : (n) == 5 ? 4 : (n) == 6 ? 6 : (n)) + +/* Every debugger symbol must be in the text section. + Otherwise the assembler or the linker screws up. */ + +#define DEBUG_SYMS_TEXT diff --git a/contrib/gcc/config/i386/sun386.h b/contrib/gcc/config/i386/sun386.h new file mode 100644 index 00000000000..6e2680789bd --- /dev/null +++ b/contrib/gcc/config/i386/sun386.h @@ -0,0 +1,143 @@ +/* Definitions for Sun assembler syntax for the Intel 80386. + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Include common aspects of all 386 Unix assemblers. */ +#include "i386/unix.h" + +#define TARGET_VERSION fprintf (stderr, " (80386, Sun syntax)"); + +/* Define the syntax of instructions and addresses. */ + +/* Prefix for internally generated assembler labels. */ +#define LPREFIX ".L" + +/* Define the syntax of pseudo-ops, labels and comments. */ + +/* Assembler pseudos to introduce constants of various size. */ + +#define ASM_BYTE_OP "\t.byte" +#define ASM_SHORT "\t.value" +#define ASM_LONG "\t.long" +#define ASM_DOUBLE "\t.double" + +/* How to output an ASCII string constant. */ + +#define ASM_OUTPUT_ASCII(FILE, p, size) \ +do \ +{ int i = 0; \ + while (i < (size)) \ + { if (i%10 == 0) { if (i!=0) fprintf ((FILE), "\n"); \ + fprintf ((FILE), "%s ", ASM_BYTE_OP); } \ + else fprintf ((FILE), ","); \ + fprintf ((FILE), "0x%x", ((p)[i++] & 0377)) ;} \ + fprintf ((FILE), "\n"); \ +} while (0) + +/* Output at beginning of assembler file. */ +/* The .file command should always begin the output. */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { \ + extern char *version_string, *language_string; \ + { \ + int len = strlen (dump_base_name); \ + char *na = dump_base_name + len; \ + char shorter[15]; \ + /* NA gets DUMP_BASE_NAME sans directory names. */\ + while (na > dump_base_name) \ + { \ + if (na[-1] == '/') \ + break; \ + na--; \ + } \ + strncpy (shorter, na, 14); \ + shorter[14] = 0; \ + fprintf (FILE, "\t.file\t"); \ + output_quoted_string (FILE, shorter); \ + fprintf (FILE, "\n"); \ + } \ + fprintf (FILE, "\t.version\t\"%s %s\"\n", \ + language_string, version_string); \ + if (optimize) ASM_FILE_START_1 (FILE); \ + } while (0) + +#define ASM_FILE_START_1(FILE) fprintf (FILE, "\t.optim\n") + +/* This is how to output an assembler line + that says to advance the location counter + to a multiple of 2**LOG bytes. */ + +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG)) + +/* This is how to output an assembler line + that says to advance the location counter by SIZE bytes. */ + +#define ASM_OUTPUT_SKIP(FILE,SIZE) \ + fprintf ((FILE), "\t.set\t.,.+%u\n", (SIZE)) + +/* Output before read-only data. */ + +#undef TEXT_SECTION_ASM_OP +#define TEXT_SECTION_ASM_OP ".text" + +/* Output before writable data. */ + +#undef DATA_SECTION_ASM_OP +#define DATA_SECTION_ASM_OP ".data" + +/* Define the syntax of labels and symbol definitions/declarations. */ + +/* This says how to output an assembler line + to define a global common symbol. */ + +#define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".comm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (ROUNDED))) + +/* This says how to output an assembler line + to define a local common symbol. */ + +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".lcomm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (ROUNDED))) + +/* This is how to store into the string BUF + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. */ + +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*.%s%d", (PREFIX), (NUMBER)) + +/* This is how to output a reference to a user-level label named NAME. */ + +#define ASM_OUTPUT_LABELREF(FILE,NAME) \ + fprintf (FILE, "%s", NAME) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. */ + +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM) diff --git a/contrib/gcc/config/i386/svr3.ifile b/contrib/gcc/config/i386/svr3.ifile new file mode 100644 index 00000000000..f0bb3a0f8dc --- /dev/null +++ b/contrib/gcc/config/i386/svr3.ifile @@ -0,0 +1,45 @@ +/* + * svr3.ifile - for collectless G++ on i386 System V. + * Leaves memory configured at address 0. + * + * Install this file as $prefix/gcc-lib/TARGET/VERSION/gcc.ifile + * + * BLOCK to an offset that leaves room for many headers ( the value + * here allows for a file header, an outheader, and up to 11 section + * headers on most systems. + * BIND to an address that includes page 0 in mapped memory. The value + * used for BLOCK should be or'd into this value. Here I'm setting BLOCK + * to 0x200 and BIND to ( value_used_for(BLOCK) ) + * If you are using shared libraries, watch that you don't overlap the + * address ranges assigned for shared libs. + * + * GROUP BIND to a location in the next segment. Here, the only value + * that you should change (I think) is that within NEXT, which I've set + * to my hardware segment size. You can always use a larger size, but not + * a smaller one. + */ +SECTIONS +{ + .text BIND(0x000200) BLOCK (0x200) : + { + /* plenty for room for headers */ + *(.init) + *(.text) + vfork = fork; /* I got tired of editing peoples sloppy code */ + *(.fini) + } + GROUP BIND( NEXT(0x400000) + (ADDR(.text) + (SIZEOF(.text)) % 0x1000)): + { + .data : { + __CTOR_LIST__ = . ; + . += 4 ; /* leading NULL */ + *(.ctor) + . += 4 ; /* trailing NULL */ + __DTOR_LIST__ = . ; + . += 4 ; /* leading NULL */ + *(.dtor) + . += 4 ; /* trailing NULL */ + } + .bss : { } + } +} diff --git a/contrib/gcc/config/i386/svr3dbx.h b/contrib/gcc/config/i386/svr3dbx.h new file mode 100644 index 00000000000..d3348d55292 --- /dev/null +++ b/contrib/gcc/config/i386/svr3dbx.h @@ -0,0 +1,97 @@ +/* Definitions for Intel 386 running system V, using dbx-in-coff encapsulation. + Copyright (C) 1992, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/svr3gas.h" + +/* We do not want to output SDB debugging information. */ + +#undef SDB_DEBUGGING_INFO + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO + +/* Compensate for botch in dbxout_init/dbxout_source_file which + unconditionally drops the first character from ltext_label_name */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \ + sprintf ((BUF), "*.%s%d", (PREFIX), (NUMBER)) + +/* With the current gas, .align N aligns to an N-byte boundary. + This is done to be compatible with the system assembler. + You must specify -DOTHER_ALIGN when building gas-1.38.1. */ + +#undef ASM_OUTPUT_ALIGN +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG)!=0) fprintf ((FILE), "\t.align %d\n", 1<<(LOG)) + +/* Align labels, etc. at 4-byte boundaries. + For the 486, align to 16-byte boundary for sake of cache. */ + +#undef ASM_OUTPUT_ALIGN_CODE +#define ASM_OUTPUT_ALIGN_CODE(FILE) \ + fprintf ((FILE), "\t.align %d,0x90\n", \ + 1 << i386_align_jumps) + +/* Align start of loop at 4-byte boundary. */ + +#undef ASM_OUTPUT_LOOP_ALIGN +#define ASM_OUTPUT_LOOP_ALIGN(FILE) \ + fprintf ((FILE), "\t.align %d,0x90\n", 1 << i386_align_loops); + + +/* Additional overrides needed for dbx-in-coff gas, mostly taken from pbb.h */ + +/* Although the gas we use can create .ctor and .dtor sections from N_SETT + stabs, it does not support section directives, so we need to have the loader + define the lists. + */ +#define CTOR_LISTS_DEFINED_EXTERNALLY + +/* similar to default, but allows for the table defined by ld with svr3.ifile. + nptrs is always 0. So we need to instead check that __DTOR_LIST__[1] != 0. + The old check is left in so that the same macro can be used if and when + a future version of gas does support section directives. */ + +#define DO_GLOBAL_DTORS_BODY {int nptrs = *(int *)__DTOR_LIST__; int i; \ + if (nptrs == -1 || (__DTOR_LIST__[0] == 0 && __DTOR_LIST__[1] != 0)) \ + for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++); \ + for (i = nptrs; i >= 1; i--) \ + __DTOR_LIST__[i] (); } + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ +/* + * The loader directive file svr3.ifile defines how to merge the constructor + * sections into the data section. Also, since gas only puts out those + * sections in response to N_SETT stabs, and does not (yet) have a + * ".sections" directive, svr3.ifile also defines the list symbols + * __DTOR_LIST__ and __CTOR_LIST__. + */ +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!r:%{!z:svr3.ifile%s}%{z:svr3z.ifile%s}}\ + %{pg:gcrt1.o%s}%{!pg:%{posix:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}%{!posix:%{p:mcrt1.o%s}%{!p:crt1.o%s}}} \ + %{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp}" + +#define ENDFILE_SPEC "crtn.o%s" + +#undef LIB_SPEC +#define LIB_SPEC "%{posix:-lcposix} %{shlib:-lc_s} -lc -lg" diff --git a/contrib/gcc/config/i386/svr3gas.h b/contrib/gcc/config/i386/svr3gas.h new file mode 100644 index 00000000000..401c7661e27 --- /dev/null +++ b/contrib/gcc/config/i386/svr3gas.h @@ -0,0 +1,305 @@ +/* Definitions for Intel 386 running system V, using gas. + Copyright (C) 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/gas.h" + +/* Add stuff that normally comes from i386/sysv3.h */ + +/* longjmp may fail to restore the registers if called from the same + function that called setjmp. To compensate, the compiler avoids + putting variables in registers in functions that use both setjmp + and longjmp. */ + +#define NON_SAVING_SETJMP \ + (current_function_calls_setjmp && current_function_calls_longjmp) + +/* longjmp may fail to restore the stack pointer if the saved frame + pointer is the same as the caller's frame pointer. Requiring a frame + pointer in any function that calls setjmp or longjmp avoids this + problem, unless setjmp and longjmp are called from the same function. + Since a frame pointer will be required in such a function, it is OK + that the stack pointer is not restored. */ + +#undef FRAME_POINTER_REQUIRED +#define FRAME_POINTER_REQUIRED \ + (current_function_calls_setjmp || current_function_calls_longjmp) + +/* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib, adapted to gas */ +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ + do { \ + int align = exact_log2 (ROUNDED); \ + if (align > 2) align = 2; \ + if (TARGET_SVR3_SHLIB) \ + { \ + data_section (); \ + ASM_OUTPUT_ALIGN ((FILE), align == -1 ? 2 : align); \ + ASM_OUTPUT_LABEL ((FILE), (NAME)); \ + fprintf ((FILE), "\t.set .,.+%u\n", (ROUNDED)); \ + } \ + else \ + { \ + fputs (".lcomm ", (FILE)); \ + assemble_name ((FILE), (NAME)); \ + fprintf ((FILE), ",%u\n", (ROUNDED)); \ + } \ + } while (0) + +/* Add stuff that normally comes from i386/sysv3.h via svr3.h */ + +/* Define the actual types of some ANSI-mandated types. These + definitions should work for most SVR3 systems. */ + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* ??? This stuff is copied from config/svr3.h. In the future, + this file should be rewritten to include config/svr3.h + and override what isn't right. */ + +/* Support const sections and the ctors and dtors sections for g++. + Note that there appears to be two different ways to support const + sections at the moment. You can either #define the symbol + READONLY_DATA_SECTION (giving it some code which switches to the + readonly data section) or else you can #define the symbols + EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and + SELECT_RTX_SECTION. We do both here just to be on the safe side. + However, use of the const section is turned off by default + unless the specific tm.h file turns it on by defining + USE_CONST_SECTION as 1. */ + +/* Define a few machine-specific details of the implementation of + constructors. + + The __CTORS_LIST__ goes in the .init section. Define CTOR_LIST_BEGIN + and CTOR_LIST_END to contribute to the .init section an instruction to + push a word containing 0 (or some equivalent of that). + + Define ASM_OUTPUT_CONSTRUCTOR to push the address of the constructor. */ + +#define USE_CONST_SECTION 0 + +#define INIT_SECTION_ASM_OP ".section\t.init" +#define FINI_SECTION_ASM_OP ".section .fini,\"x\"" +#define CONST_SECTION_ASM_OP ".section\t.rodata, \"x\"" +#define CTORS_SECTION_ASM_OP INIT_SECTION_ASM_OP +#define DTORS_SECTION_ASM_OP FINI_SECTION_ASM_OP + +/* CTOR_LIST_BEGIN and CTOR_LIST_END are machine-dependent + because they push on the stack. */ + +#ifdef STACK_GROWS_DOWNWARD + +/* Constructor list on stack is in reverse order. Go to the end of the + list and go backwards to call constructors in the right order. */ +#define DO_GLOBAL_CTORS_BODY \ +do { \ + func_ptr *p, *beg = alloca (0); \ + for (p = beg; *p; p++) \ + ; \ + while (p != beg) \ + (*--p) (); \ +} while (0) + +#else + +/* Constructor list on stack is in correct order. Just call them. */ +#define DO_GLOBAL_CTORS_BODY \ +do { \ + func_ptr *p, *beg = alloca (0); \ + for (p = beg; *p; ) \ + (*p++) (); \ +} while (0) + +#endif /* STACK_GROWS_DOWNWARD */ + +/* Add extra sections .init and .fini, in addition to .bss from att386.h. */ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_const, in_bss, in_init, in_fini + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CONST_SECTION_FUNCTION \ + BSS_SECTION_FUNCTION \ + INIT_SECTION_FUNCTION \ + FINI_SECTION_FUNCTION + +#define BSS_SECTION_FUNCTION \ +void \ +bss_section () \ +{ \ + if (in_section != in_bss) \ + { \ + fprintf (asm_out_file, "\t%s\n", BSS_SECTION_ASM_OP); \ + in_section = in_bss; \ + } \ +} + +#define INIT_SECTION_FUNCTION \ +void \ +init_section () \ +{ \ + if (in_section != in_init) \ + { \ + fprintf (asm_out_file, "\t%s\n", INIT_SECTION_ASM_OP); \ + in_section = in_init; \ + } \ +} + +#define FINI_SECTION_FUNCTION \ +void \ +fini_section () \ +{ \ + if (in_section != in_fini) \ + { \ + fprintf (asm_out_file, "\t%s\n", FINI_SECTION_ASM_OP); \ + in_section = in_fini; \ + } \ +} + +#define READONLY_DATA_SECTION() const_section () + +#define CONST_SECTION_FUNCTION \ +void \ +const_section () \ +{ \ + extern void text_section(); \ + if (!USE_CONST_SECTION) \ + text_section(); \ + else if (in_section != in_const) \ + { \ + fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP); \ + in_section = in_const; \ + } \ +} + +/* The ctors and dtors sections are not normally put into use + by EXTRA_SECTIONS and EXTRA_SECTION_FUNCTIONS as defined in svr3.h, + but it can't hurt to define these macros for whatever systems use them. */ +#define CTORS_SECTION_FUNCTION \ +void \ +ctors_section () \ +{ \ + if (in_section != in_ctors) \ + { \ + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \ + in_section = in_ctors; \ + } \ +} + +#define DTORS_SECTION_FUNCTION \ +void \ +dtors_section () \ +{ \ + if (in_section != in_dtors) \ + { \ + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \ + in_section = in_dtors; \ + } \ +} + +/* This is machine-dependent + because it needs to push something on the stack. */ +#undef ASM_OUTPUT_CONSTRUCTOR + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + fini_section (); \ + fprintf (FILE, "%s\t ", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement or statements to switch to the appropriate + section for output of DECL. DECL is either a `VAR_DECL' node + or a constant of some sort. RELOC indicates whether forming + the initial value of DECL requires link-time relocations. */ + +#define SELECT_SECTION(DECL,RELOC) \ +{ \ + if (TREE_CODE (DECL) == STRING_CST) \ + { \ + if (! flag_writable_strings) \ + const_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (DECL) == VAR_DECL) \ + { \ + if ((0 && RELOC) /* should be (flag_pic && RELOC) */ \ + || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \ + || !DECL_INITIAL (DECL) \ + || (DECL_INITIAL (DECL) != error_mark_node \ + && !TREE_CONSTANT (DECL_INITIAL (DECL)))) \ + data_section (); \ + else \ + const_section (); \ + } \ + else \ + const_section (); \ +} + +/* A C statement or statements to switch to the appropriate + section for output of RTX in mode MODE. RTX is some kind + of constant in RTL. The argument MODE is redundant except + in the case of a `const_int' rtx. Currently, these always + go into the const section. */ + +#define SELECT_RTX_SECTION(MODE,RTX) const_section() + +/* This is copied from i386/sysv3.h. */ + +/* Define a few machine-specific details of the implementation of + constructors. + + The __CTORS_LIST__ goes in the .init section. Define CTOR_LIST_BEGIN + and CTOR_LIST_END to contribute to the .init section an instruction to + push a word containing 0 (or some equivalent of that). + + ASM_OUTPUT_CONSTRUCTOR should be defined to push the address of the + constructor. */ + +#undef INIT_SECTION_ASM_OP +#define INIT_SECTION_ASM_OP ".section .init,\"x\"" + +#define CTOR_LIST_BEGIN \ + asm (INIT_SECTION_ASM_OP); \ + asm ("pushl $0") +#define CTOR_LIST_END CTOR_LIST_BEGIN + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + init_section (); \ + fprintf (FILE, "\tpushl $"); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) diff --git a/contrib/gcc/config/i386/svr3z.ifile b/contrib/gcc/config/i386/svr3z.ifile new file mode 100644 index 00000000000..4fdbb937c57 --- /dev/null +++ b/contrib/gcc/config/i386/svr3z.ifile @@ -0,0 +1,45 @@ +/* + * svr3z.ifile - for collectless G++ on i386 System V. + * Leaves memory unconfigured at address 0. + * + * Install this file as $prefix/gcc-lib/TARGET/VERSION/gccz.ifile + * + * BLOCK to an offset that leaves room for many headers ( the value + * here allows for a file header, an outheader, and up to 11 section + * headers on most systems. + * BIND to an address that excludes page 0 from being mapped. The value + * used for BLOCK should be or'd into this value. Here I'm setting BLOCK + * to 0x200 and BIND to ( 0x400000 | value_used_for(BLOCK) ) + * If you are using shared libraries, watch that you don't overlap the + * address ranges assigned for shared libs. + * + * GROUP BIND to a location in the next segment. Here, the only value + * that you should change (I think) is that within NEXT, which I've set + * to my hardware segment size. You can always use a larger size, but not + * a smaller one. + */ +SECTIONS +{ + .text BIND(0x400200) BLOCK (0x200) : + { + /* plenty for room for headers */ + *(.init) + *(.text) + vfork = fork; /* I got tired of editing peoples sloppy code */ + *(.fini) + } + GROUP BIND( NEXT(0x400000) + (ADDR(.text) + (SIZEOF(.text)) % 0x1000)): + { + .data : { + __CTOR_LIST__ = . ; + . += 4 ; /* leading NULL */ + *(.ctor) + . += 4 ; /* trailing NULL */ + __DTOR_LIST__ = . ; + . += 4 ; /* leading NULL */ + *(.dtor) + . += 4 ; /* trailing NULL */ + } + .bss : { } + } +} diff --git a/contrib/gcc/config/i386/sysv3.h b/contrib/gcc/config/i386/sysv3.h new file mode 100644 index 00000000000..8c5cfc41587 --- /dev/null +++ b/contrib/gcc/config/i386/sysv3.h @@ -0,0 +1,124 @@ +/* Definitions for Intel 386 running system V. + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "i386/i386.h" + +/* Use default settings for system V.3. */ + +#include "svr3.h" + +/* Use the ATT assembler syntax. + This overrides at least one macro (ASM_OUTPUT_LABELREF) from svr3.h. */ + +#include "i386/att.h" + +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#define STARTFILE_SPEC \ + "%{pg:gcrt1.o%s}%{!pg:%{posix:%{p:mcrtp1.o%s}%{!p:crtp1.o%s}}%{!posix:%{p:mcrt1.o%s}%{!p:crt1.o%s}}} crtbegin.o%s\ + %{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp}" + +/* ??? There is a suggestion that -lg is needed here. + Does anyone know whether this is right? */ +#define LIB_SPEC "%{posix:-lcposix} %{shlib:-lc_s} -lc crtend.o%s crtn.o%s" + +/* Specify predefined symbols in preprocessor. */ + +#define CPP_PREDEFINES "-Dunix -Di386 -Asystem(unix) -Asystem(svr3) -Acpu(i386) -Amachine(i386)" + +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}" + +/* Writing `int' for a bitfield forces int alignment for the structure. */ + +#define PCC_BITFIELD_TYPE_MATTERS 1 + +/* Don't write a `.optim' pseudo; this assembler doesn't handle them. */ + +#undef ASM_FILE_START_1 +#define ASM_FILE_START_1(FILE) + +/* We want to be able to get DBX debugging information via -gstabs. */ + +#undef DBX_DEBUGGING_INFO +#define DBX_DEBUGGING_INFO + +#undef PREFERRED_DEBUGGING_TYPE +#define PREFERRED_DEBUGGING_TYPE SDB_DEBUG + +/* longjmp may fail to restore the registers if called from the same + function that called setjmp. To compensate, the compiler avoids + putting variables in registers in functions that use both setjmp + and longjmp. */ + +#define NON_SAVING_SETJMP \ + (current_function_calls_setjmp && current_function_calls_longjmp) + +/* longjmp may fail to restore the stack pointer if the saved frame + pointer is the same as the caller's frame pointer. Requiring a frame + pointer in any function that calls setjmp or longjmp avoids this + problem, unless setjmp and longjmp are called from the same function. + Since a frame pointer will be required in such a function, it is OK + that the stack pointer is not restored. */ + +#undef FRAME_POINTER_REQUIRED +#define FRAME_POINTER_REQUIRED \ + (current_function_calls_setjmp || current_function_calls_longjmp) + +/* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib. */ +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ + do { \ + int align = exact_log2 (ROUNDED); \ + if (align > 2) align = 2; \ + if (TARGET_SVR3_SHLIB) \ + data_section (); \ + else \ + bss_section (); \ + ASM_OUTPUT_ALIGN ((FILE), align == -1 ? 2 : align); \ + ASM_OUTPUT_LABEL ((FILE), (NAME)); \ + fprintf ((FILE), "\t.set .,.+%u\n", (ROUNDED)); \ + } while (0) + +/* Define a few machine-specific details of the implementation of + constructors. + + The __CTORS_LIST__ goes in the .init section. Define CTOR_LIST_BEGIN + and CTOR_LIST_END to contribute to the .init section an instruction to + push a word containing 0 (or some equivalent of that). + + ASM_OUTPUT_CONSTRUCTOR should be defined to push the address of the + constructor. */ + +#undef INIT_SECTION_ASM_OP +#define INIT_SECTION_ASM_OP ".section .init,\"x\"" + +#define CTOR_LIST_BEGIN \ + asm (INIT_SECTION_ASM_OP); \ + asm ("pushl $0") +#define CTOR_LIST_END CTOR_LIST_BEGIN + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + init_section (); \ + fprintf (FILE, "\tpushl $"); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) diff --git a/contrib/gcc/config/i386/sysv4.h b/contrib/gcc/config/i386/sysv4.h new file mode 100644 index 00000000000..92fcada03d5 --- /dev/null +++ b/contrib/gcc/config/i386/sysv4.h @@ -0,0 +1,245 @@ +/* Target definitions for GNU compiler for Intel 80386 running System V.4 + Copyright (C) 1991 Free Software Foundation, Inc. + + Written by Ron Guilmette (rfg@netcom.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "i386/i386.h" /* Base i386 target machine definitions */ +#include "i386/att.h" /* Use the i386 AT&T assembler syntax */ +#include "svr4.h" /* Definitions common to all SVR4 targets */ + +#undef TARGET_VERSION +#define TARGET_VERSION fprintf (stderr, " (i386 System V Release 4)"); + +/* The svr4 ABI for the i386 says that records and unions are returned + in memory. */ + +#undef RETURN_IN_MEMORY +#define RETURN_IN_MEMORY(TYPE) \ + (TYPE_MODE (TYPE) == BLKmode) + +/* Define which macros to predefine. __svr4__ is our extension. */ +/* This used to define X86, but james@bigtex.cactus.org says that + is supposed to be defined optionally by user programs--not by default. */ +#define CPP_PREDEFINES \ + "-Di386 -Dunix -D__svr4__ -Asystem(unix) -Asystem(svr4) -Acpu(i386) -Amachine(i386)" + +/* This is how to output assembly code to define a `float' constant. + We always have to use a .long pseudo-op to do this because the native + SVR4 ELF assembler is buggy and it generates incorrect values when we + try to use the .float pseudo-op instead. */ + +#undef ASM_OUTPUT_FLOAT +#define ASM_OUTPUT_FLOAT(FILE,VALUE) \ +do { long value; \ + REAL_VALUE_TO_TARGET_SINGLE ((VALUE), value); \ + if (sizeof (int) == sizeof (long)) \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value); \ + else \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value); \ + } while (0) + +/* This is how to output assembly code to define a `double' constant. + We always have to use a pair of .long pseudo-ops to do this because + the native SVR4 ELF assembler is buggy and it generates incorrect + values when we try to use the the .double pseudo-op instead. */ + +#undef ASM_OUTPUT_DOUBLE +#define ASM_OUTPUT_DOUBLE(FILE,VALUE) \ +do { long value[2]; \ + REAL_VALUE_TO_TARGET_DOUBLE ((VALUE), value); \ + if (sizeof (int) == sizeof (long)) \ + { \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[0]); \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[1]); \ + } \ + else \ + { \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[0]); \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[1]); \ + } \ + } while (0) + + +#undef ASM_OUTPUT_LONG_DOUBLE +#define ASM_OUTPUT_LONG_DOUBLE(FILE,VALUE) \ +do { long value[3]; \ + REAL_VALUE_TO_TARGET_LONG_DOUBLE ((VALUE), value); \ + if (sizeof (int) == sizeof (long)) \ + { \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[0]); \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[1]); \ + fprintf((FILE), "%s\t0x%x\n", ASM_LONG, value[2]); \ + } \ + else \ + { \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[0]); \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[1]); \ + fprintf((FILE), "%s\t0x%lx\n", ASM_LONG, value[2]); \ + } \ + } while (0) + +/* Output at beginning of assembler file. */ +/* The .file command should always begin the output. */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { \ + output_file_directive (FILE, main_input_filename); \ + fprintf (FILE, "\t.version\t\"01.01\"\n"); \ + } while (0) + +/* Define the register numbers to be used in Dwarf debugging information. + The SVR4 reference port C compiler uses the following register numbers + in its Dwarf output code: + + 0 for %eax (gnu regno = 0) + 1 for %ecx (gnu regno = 2) + 2 for %edx (gnu regno = 1) + 3 for %ebx (gnu regno = 3) + 4 for %esp (gnu regno = 7) + 5 for %ebp (gnu regno = 6) + 6 for %esi (gnu regno = 4) + 7 for %edi (gnu regno = 5) + + The following three DWARF register numbers are never generated by + the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4 + believes these numbers have these meanings. + + 8 for %eip (no gnu equivalent) + 9 for %eflags (no gnu equivalent) + 10 for %trapno (no gnu equivalent) + + It is not at all clear how we should number the FP stack registers + for the x86 architecture. If the version of SDB on x86/svr4 were + a bit less brain dead with respect to floating-point then we would + have a precedent to follow with respect to DWARF register numbers + for x86 FP registers, but the SDB on x86/svr4 is so completely + broken with respect to FP registers that it is hardly worth thinking + of it as something to strive for compatibility with. + + The version of x86/svr4 SDB I have at the moment does (partially) + seem to believe that DWARF register number 11 is associated with + the x86 register %st(0), but that's about all. Higher DWARF + register numbers don't seem to be associated with anything in + particular, and even for DWARF regno 11, SDB only seems to under- + stand that it should say that a variable lives in %st(0) (when + asked via an `=' command) if we said it was in DWARF regno 11, + but SDB still prints garbage when asked for the value of the + variable in question (via a `/' command). + + (Also note that the labels SDB prints for various FP stack regs + when doing an `x' command are all wrong.) + + Note that these problems generally don't affect the native SVR4 + C compiler because it doesn't allow the use of -O with -g and + because when it is *not* optimizing, it allocates a memory + location for each floating-point variable, and the memory + location is what gets described in the DWARF AT_location + attribute for the variable in question. + + Regardless of the severe mental illness of the x86/svr4 SDB, we + do something sensible here and we use the following DWARF + register numbers. Note that these are all stack-top-relative + numbers. + + 11 for %st(0) (gnu regno = 8) + 12 for %st(1) (gnu regno = 9) + 13 for %st(2) (gnu regno = 10) + 14 for %st(3) (gnu regno = 11) + 15 for %st(4) (gnu regno = 12) + 16 for %st(5) (gnu regno = 13) + 17 for %st(6) (gnu regno = 14) + 18 for %st(7) (gnu regno = 15) +*/ + +#undef DBX_REGISTER_NUMBER +#define DBX_REGISTER_NUMBER(n) \ +((n) == 0 ? 0 \ + : (n) == 1 ? 2 \ + : (n) == 2 ? 1 \ + : (n) == 3 ? 3 \ + : (n) == 4 ? 6 \ + : (n) == 5 ? 7 \ + : (n) == 6 ? 5 \ + : (n) == 7 ? 4 \ + : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \ + : (-1)) + +/* The routine used to output sequences of byte values. We use a special + version of this for most svr4 targets because doing so makes the + generated assembly code more compact (and thus faster to assemble) + as well as more readable. Note that if we find subparts of the + character sequence which end with NUL (and which are shorter than + STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */ + +#undef ASM_OUTPUT_ASCII +#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \ + do \ + { \ + register unsigned char *_ascii_bytes = (unsigned char *) (STR); \ + register unsigned char *limit = _ascii_bytes + (LENGTH); \ + register unsigned bytes_in_chunk = 0; \ + for (; _ascii_bytes < limit; _ascii_bytes++) \ + { \ + register unsigned char *p; \ + if (bytes_in_chunk >= 64) \ + { \ + fputc ('\n', (FILE)); \ + bytes_in_chunk = 0; \ + } \ + for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \ + continue; \ + if (p < limit && (p - _ascii_bytes) <= STRING_LIMIT) \ + { \ + if (bytes_in_chunk > 0) \ + { \ + fputc ('\n', (FILE)); \ + bytes_in_chunk = 0; \ + } \ + ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \ + _ascii_bytes = p; \ + } \ + else \ + { \ + if (bytes_in_chunk == 0) \ + fprintf ((FILE), "\t.byte\t"); \ + else \ + fputc (',', (FILE)); \ + fprintf ((FILE), "0x%02x", *_ascii_bytes); \ + bytes_in_chunk += 5; \ + } \ + } \ + if (bytes_in_chunk > 0) \ + fprintf ((FILE), "\n"); \ + } \ + while (0) + +/* This is how to output an element of a case-vector that is relative. + This is only used for PIC code. See comments by the `casesi' insn in + i386.md for an explanation of the expression this outputs. */ + +#undef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ + fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE) + +/* Indicate that jump tables go in the text section. This is + necessary when compiling PIC code. */ + +#define JUMP_TABLES_IN_TEXT_SECTION diff --git a/contrib/gcc/config/i386/sysv4gdb.h b/contrib/gcc/config/i386/sysv4gdb.h new file mode 100644 index 00000000000..dd1e8f256f3 --- /dev/null +++ b/contrib/gcc/config/i386/sysv4gdb.h @@ -0,0 +1,7 @@ +/* Target definitions for GNU compiler for Intel 80386 running System V.4 + with gas and gdb. */ + +/* Use stabs instead of DWARF debug format. */ +#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG + +#include "i386/sysv4.h" diff --git a/contrib/gcc/config/i386/t-crtpic b/contrib/gcc/config/i386/t-crtpic new file mode 100644 index 00000000000..f5dd073a664 --- /dev/null +++ b/contrib/gcc/config/i386/t-crtpic @@ -0,0 +1,9 @@ +# The pushl in CTOR initialization interferes with frame pointer elimination. + +# We need to use -fPIC when we are using gcc to compile the routines in +# crtstuff.c. This is only really needed when we are going to use gcc/g++ +# to produce a shared library, but since we don't know ahead of time when +# we will be doing that, we just always use -fPIC when compiling the +# routines in crtstuff.c. + +CRTSTUFF_T_CFLAGS = -fPIC -fno-omit-frame-pointer diff --git a/contrib/gcc/config/i386/t-crtstuff b/contrib/gcc/config/i386/t-crtstuff new file mode 100644 index 00000000000..a202df6653f --- /dev/null +++ b/contrib/gcc/config/i386/t-crtstuff @@ -0,0 +1,2 @@ +# The pushl in CTOR initialization interferes with frame pointer elimination. +CRTSTUFF_T_CFLAGS = -fno-omit-frame-pointer diff --git a/contrib/gcc/config/i386/t-i386bare b/contrib/gcc/config/i386/t-i386bare new file mode 100644 index 00000000000..2970fa71415 --- /dev/null +++ b/contrib/gcc/config/i386/t-i386bare @@ -0,0 +1,3 @@ +# The i386 md has all of these taken care of, according to sef. +LIBGCC1 = +CROSS_LIBGCC1 = diff --git a/contrib/gcc/config/i386/t-iscscodbx b/contrib/gcc/config/i386/t-iscscodbx new file mode 100644 index 00000000000..928a7589f8c --- /dev/null +++ b/contrib/gcc/config/i386/t-iscscodbx @@ -0,0 +1,2 @@ +# The one that comes with the system is POSIX-compliant. +LIMITS_H = diff --git a/contrib/gcc/config/i386/t-next b/contrib/gcc/config/i386/t-next new file mode 100644 index 00000000000..ec6373f9cea --- /dev/null +++ b/contrib/gcc/config/i386/t-next @@ -0,0 +1,9 @@ +# libgcc1.c is not needed, since the standard library has these functions. +LIBGCC1=libgcc1.null +CROSS_LIBGCC1=libgcc1.null + +# Specify other dirs of system header files to be fixed. +OTHER_FIXINCLUDES_DIRS= /LocalDeveloper/Headers + +# is sometimes in /usr/include/ansi/limits.h. +LIMITS_H_TEST = [ -f $(SYSTEM_HEADER_DIR)/limits.h -o -f $(SYSTEM_HEADER_DIR)/ansi/limits.h ] diff --git a/contrib/gcc/config/i386/t-sol2 b/contrib/gcc/config/i386/t-sol2 new file mode 100644 index 00000000000..f79f6ca05fb --- /dev/null +++ b/contrib/gcc/config/i386/t-sol2 @@ -0,0 +1,32 @@ +# we need to supply our own assembly versions of libgcc1.c files, +# since the user may not have native 'cc' available + +LIBGCC1 = libgcc1.null +CROSS_LIBGCC1 = libgcc1.null + +# gmon build rule: +gmon.o: $(srcdir)/config/i386/gmon-sol2.c $(GCC_PASSES) $(CONFIG_H) + $(GCC_FOR_TARGET) $(GCC_CFLAGS) $(INCLUDES) \ + -c $(srcdir)/config/i386/gmon-sol2.c -o gmon.o + +# Assemble startup files. +# Apparently Sun believes that assembler files don't need comments, because no +# single ASCII character is valid (tried them all). So we manually strip out +# the comments with sed. This bug may only be in the Early Access releases. +crt1.o: $(srcdir)/config/i386/sol2-c1.asm + sed -e '/^!/d' <$(srcdir)/config/i386/sol2-c1.asm >crt1.s + $(AS) -o crt1.o crt1.s +crti.o: $(srcdir)/config/i386/sol2-ci.asm + sed -e '/^!/d' <$(srcdir)/config/i386/sol2-ci.asm >crti.s + $(AS) -o crti.o crti.s +crtn.o: $(srcdir)/config/i386/sol2-cn.asm + sed -e '/^!/d' <$(srcdir)/config/i386/sol2-cn.asm >crtn.s + $(AS) -o crtn.o crtn.s + +# We need to use -fPIC when we are using gcc to compile the routines in +# crtstuff.c. This is only really needed when we are going to use gcc/g++ +# to produce a shared library, but since we don't know ahead of time when +# we will be doing that, we just always use -fPIC when compiling the +# routines in crtstuff.c. + +CRTSTUFF_T_CFLAGS = -fPIC diff --git a/contrib/gcc/config/i386/t-svr3dbx b/contrib/gcc/config/i386/t-svr3dbx new file mode 100644 index 00000000000..51711379191 --- /dev/null +++ b/contrib/gcc/config/i386/t-svr3dbx @@ -0,0 +1,7 @@ +# gas 1.38.1 supporting dbx-in-coff requires a link script. + +svr3.ifile: $(srcdir)/config/i386/svr3.ifile + rm -f svr3.ifile; cp $(srcdir)/config/i386/svr3.ifile . + +svr3z.ifile: $(srcdir)/config/i386/svr3z.ifile + rm -f svr3z.ifile; cp $(srcdir)/config/i386/svr3z.ifile . diff --git a/contrib/gcc/config/i386/t-vsta b/contrib/gcc/config/i386/t-vsta new file mode 100644 index 00000000000..6160b7ec945 --- /dev/null +++ b/contrib/gcc/config/i386/t-vsta @@ -0,0 +1,2 @@ +LIBGCC1 = libgcc1.null +CROSS_LIBGCC1 = libgcc1.null diff --git a/contrib/gcc/config/i386/t-winnt b/contrib/gcc/config/i386/t-winnt new file mode 100644 index 00000000000..e8e1a0af050 --- /dev/null +++ b/contrib/gcc/config/i386/t-winnt @@ -0,0 +1,2 @@ +winnt.o: $(srcdir)/config/i386/winnt.c + $(CC) -I. -I$(srcdir) -I$(srcdir)/config -c $(srcdir)/config/i386/winnt.c diff --git a/contrib/gcc/config/i386/unix.h b/contrib/gcc/config/i386/unix.h new file mode 100644 index 00000000000..f38fe270d89 --- /dev/null +++ b/contrib/gcc/config/i386/unix.h @@ -0,0 +1,148 @@ +/* Definitions for Unix assembler syntax for the Intel 80386. + Copyright (C) 1988, 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines the aspects of assembler syntax + that are the same for all the i386 Unix systems + (though they may differ in non-Unix systems). */ + +/* Define some concatenation macros to concatenate an opcode + and one, two or three operands. In other assembler syntaxes + they may alter the order of ther operands. */ + +/* Note that the other files fail to use these + in some of the places where they should. */ + +#if defined(__STDC__) || defined(ALMOST_STDC) +#define AS2(a,b,c) #a " " #b "," #c +#define AS2C(b,c) " " #b "," #c +#define AS3(a,b,c,d) #a " " #b "," #c "," #d +#define AS1(a,b) #a " " #b +#else +#define AS1(a,b) "a b" +#define AS2(a,b,c) "a b,c" +#define AS2C(b,c) " b,c" +#define AS3(a,b,c,d) "a b,c,d" +#endif + +/* Define macro used to output shift-double opcodes when the shift + count is in %cl. Some assemblers require %cl as an argument; + some don't. This macro controls what to do: by default, don't + print %cl. */ +#define AS3_SHIFT_DOUBLE(a,b,c,d) AS2 (a,c,d) + +/* Output the size-letter for an opcode. + CODE is the letter used in an operand spec (L, B, W, S or Q). + CH is the corresponding lower case letter + (except if CODE is `Q' then CH is `l', unless GAS_MNEMONICS). */ +#define PUT_OP_SIZE(CODE,CH,FILE) putc (CH,(FILE)) + +/* Opcode suffix for fullword insn. */ +#define L_SIZE "l" + +/* Prefix for register names in this syntax. */ +#define RP "%" + +/* Prefix for immediate operands in this syntax. */ +#define IP "$" + +/* Indirect call instructions should use `*'. */ +#define USE_STAR 1 + +/* Prefix for a memory-operand X. */ +#define PRINT_PTR(X, FILE) + +/* Delimiters that surround base reg and index reg. */ +#define ADDR_BEG(FILE) putc('(', (FILE)) +#define ADDR_END(FILE) putc(')', (FILE)) + +/* Print an index register (whose rtx is IREG). */ +#define PRINT_IREG(FILE,IREG) \ + do \ + { fputs (",", (FILE)); PRINT_REG ((IREG), 0, (FILE)); } \ + while (0) + +/* Print an index scale factor SCALE. */ +#define PRINT_SCALE(FILE,SCALE) \ + if ((SCALE) != 1) fprintf ((FILE), ",%d", (SCALE)) + +/* Print a base/index combination. + BREG is the base reg rtx, IREG is the index reg rtx, + and SCALE is the index scale factor (an integer). */ + +#define PRINT_B_I_S(BREG,IREG,SCALE,FILE) \ + { ADDR_BEG (FILE); \ + if (BREG) PRINT_REG ((BREG), 0, (FILE)); \ + if ((IREG) != 0) \ + { PRINT_IREG ((FILE), (IREG)); \ + PRINT_SCALE ((FILE), (SCALE)); } \ + ADDR_END (FILE); } + +/* Define the syntax of pseudo-ops, labels and comments. */ + +/* String containing the assembler's comment-starter. */ + +#define ASM_COMMENT_START "/" +#define COMMENT_BEGIN "/" + +/* Output to assembler file text saying following lines + may contain character constants, extra white space, comments, etc. */ + +#define ASM_APP_ON "/APP\n" + +/* Output to assembler file text saying following lines + no longer contain unusual constructs. */ + +#define ASM_APP_OFF "/NO_APP\n" + +/* Output before read-only data. */ + +#define TEXT_SECTION_ASM_OP ".text" + +/* Output before writable (initialized) data. */ + +#define DATA_SECTION_ASM_OP ".data" + +/* Output before writable (uninitialized) data. */ + +#define BSS_SECTION_ASM_OP ".bss" + +/* This is how to output a command to make the user-level label named NAME + defined for reference from other files. */ + +#define ASM_GLOBALIZE_LABEL(FILE,NAME) \ + (fputs (".globl ", FILE), assemble_name (FILE, NAME), fputs ("\n", FILE)) + +/* By default, target has a 80387, uses IEEE compatible arithmetic, + and returns float values in the 387, ie, + (TARGET_80387 | TARGET_IEEE_FP | TARGET_FLOAT_RETURNS_IN_80387) */ + +#define TARGET_DEFAULT 0301 + +/* Floating-point return values come in the FP register. */ + +#define VALUE_REGNO(MODE) \ + (GET_MODE_CLASS (MODE) == MODE_FLOAT \ + && TARGET_FLOAT_RETURNS_IN_80387 ? FIRST_FLOAT_REG : 0) + +/* 1 if N is a possible register number for a function value. */ + +#define FUNCTION_VALUE_REGNO_P(N) \ + ((N) == 0 || ((N)== FIRST_FLOAT_REG && TARGET_FLOAT_RETURNS_IN_80387)) + diff --git a/contrib/gcc/config/i386/v3gas.h b/contrib/gcc/config/i386/v3gas.h new file mode 100644 index 00000000000..fe558d265b4 --- /dev/null +++ b/contrib/gcc/config/i386/v3gas.h @@ -0,0 +1,80 @@ +/* Definitions for Intel 386 running system V, using gas. + Copyright (C) 1992, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include + +/* Add stuff that normally comes from i386v.h */ + +/* longjmp may fail to restore the registers if called from the same + function that called setjmp. To compensate, the compiler avoids + putting variables in registers in functions that use both setjmp + and longjmp. */ + +#define NON_SAVING_SETJMP \ + (current_function_calls_setjmp && current_function_calls_longjmp) + +/* longjmp may fail to restore the stack pointer if the saved frame + pointer is the same as the caller's frame pointer. Requiring a frame + pointer in any function that calls setjmp or longjmp avoids this + problem, unless setjmp and longjmp are called from the same function. + Since a frame pointer will be required in such a function, it is OK + that the stack pointer is not restored. */ + +#undef FRAME_POINTER_REQUIRED +#define FRAME_POINTER_REQUIRED \ + (current_function_calls_setjmp || current_function_calls_longjmp) + +/* Modify ASM_OUTPUT_LOCAL slightly to test -msvr3-shlib, adapted to gas */ +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ + do { \ + int align = exact_log2 (ROUNDED); \ + if (align > 2) align = 2; \ + if (TARGET_SVR3_SHLIB) \ + { \ + data_section (); \ + ASM_OUTPUT_ALIGN ((FILE), align == -1 ? 2 : align); \ + ASM_OUTPUT_LABEL ((FILE), (NAME)); \ + fprintf ((FILE), "\t.set .,.+%u\n", (ROUNDED)); \ + } \ + else \ + { \ + fputs (".lcomm ", (FILE)); \ + assemble_name ((FILE), (NAME)); \ + fprintf ((FILE), ",%u\n", (ROUNDED)); \ + } \ + } while (0) + +/* Add stuff that normally comes from i386v.h via svr3.h */ + +/* Define the actual types of some ANSI-mandated types. These + definitions should work for most SVR3 systems. */ + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD diff --git a/contrib/gcc/config/i386/vsta.h b/contrib/gcc/config/i386/vsta.h new file mode 100644 index 00000000000..ee7fab9173f --- /dev/null +++ b/contrib/gcc/config/i386/vsta.h @@ -0,0 +1,78 @@ +/* Configuration for an i386 running VSTa micro-kernel. + Copyright (C) 1994 Free Software Foundation, Inc. + Contributed by Rob Savoye (rob@cygnus.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define YES_UNDERSCORES + +#include "i386/gas.h" + +#ifdef CPP_PREDEFINES +#undef CPP_PREDEFINES +#endif +#define CPP_PREDEFINES "-Dunix -Di386 -DVSTA \ + -Asystem(unix) -Asystem(vsta) -Acpu(i386) -Amachine(i386)" + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_ctor, in_dtor + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CTOR_SECTION_FUNCTION \ + DTOR_SECTION_FUNCTION + +#define CTOR_SECTION_FUNCTION \ +void \ +ctor_section () \ +{ \ + if (in_section != in_ctor) \ + { \ + fprintf (asm_out_file, "\t.section .ctor\n"); \ + in_section = in_ctor; \ + } \ +} + +#define DTOR_SECTION_FUNCTION \ +void \ +dtor_section () \ +{ \ + if (in_section != in_dtor) \ + { \ + fprintf (asm_out_file, "\t.section .dtor\n"); \ + in_section = in_dtor; \ + } \ +} + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + + diff --git a/contrib/gcc/config/i386/win-nt.h b/contrib/gcc/config/i386/win-nt.h new file mode 100644 index 00000000000..60c0bb6a1f6 --- /dev/null +++ b/contrib/gcc/config/i386/win-nt.h @@ -0,0 +1,152 @@ +/* Operating system specific defines to be used when targeting GCC for + Windows NT 3.x on an i386. + Copyright (C) 1994, 1995 Free Software Foundation, Inc. + Contributed by Douglas B. Rupp (drupp@cs.washington.edu). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define YES_UNDERSCORES + +#include "i386/gas.h" + +#ifdef CPP_PREDEFINES +#undef CPP_PREDEFINES +#endif +#define CPP_PREDEFINES "-Dunix -Di386 -DWIN32 -D_WIN32 \ + -DWINNT -D_M_IX86=300 -D_X86_=1 -D__STDC__=0 -DALMOST_STDC -D_MSC_VER=800 \ + -D__stdcall=__attribute__((__stdcall__)) \ + -D__cdecl=__attribute__((__cdecl__)) \ + -D_cdecl=__attribute__((__cdecl__)) \ + -Asystem(unix) -Asystem(winnt) -Acpu(i386) -Amachine(i386)" + +#define SIZE_TYPE "unsigned int" +#define PTRDIFF_TYPE "int" +#define WCHAR_UNSIGNED 1 +#define WCHAR_TYPE_SIZE 16 +#define WCHAR_TYPE "short unsigned int" +#undef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE 64 +#define HAVE_ATEXIT 1 + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_ctor, in_dtor + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CTOR_SECTION_FUNCTION \ + DTOR_SECTION_FUNCTION + +#define CTOR_SECTION_FUNCTION \ +void \ +ctor_section () \ +{ \ + if (in_section != in_ctor) \ + { \ + fprintf (asm_out_file, "\t.section .ctor\n"); \ + in_section = in_ctor; \ + } \ +} + +#define DTOR_SECTION_FUNCTION \ +void \ +dtor_section () \ +{ \ + if (in_section != in_dtor) \ + { \ + fprintf (asm_out_file, "\t.section .dtor\n"); \ + in_section = in_dtor; \ + } \ +} + +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtor_section (); \ + fprintf (FILE, "%s\t", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* Define this macro if references to a symbol must be treated + differently depending on something about the variable or + function named by the symbol (such as what section it is in). + + On i386, if using PIC, mark a SYMBOL_REF for a non-global symbol + so that we may access it directly in the GOT. + + On i386 running Windows NT, modify the assembler name with a suffix + consisting of an atsign (@) followed by string of digits that represents + the number of bytes of arguments passed to the function, if it has the + attribute STDCALL. */ + +#ifdef ENCODE_SECTION_INFO +#undef ENCODE_SECTION_INFO +#define ENCODE_SECTION_INFO(DECL) \ +do \ + { \ + if (flag_pic) \ + { \ + rtx rtl = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + ? TREE_CST_RTL (DECL) : DECL_RTL (DECL)); \ + SYMBOL_REF_FLAG (XEXP (rtl, 0)) \ + = (TREE_CODE_CLASS (TREE_CODE (DECL)) != 'd' \ + || ! TREE_PUBLIC (DECL)); \ + } \ + if (TREE_CODE (DECL) == FUNCTION_DECL) \ + if (lookup_attribute ("stdcall", \ + TYPE_ATTRIBUTES (TREE_TYPE (DECL)))) \ + XEXP (DECL_RTL (DECL), 0) = \ + gen_rtx (SYMBOL_REF, Pmode, gen_stdcall_suffix (DECL)); \ + } \ +while (0) +#endif + +/* The global __fltused is necessary to cause the printf/scanf routines + for outputting/inputting floating point numbers to be loaded. Since this + is kind of hard to detect, we just do it all the time. */ + +#ifdef ASM_FILE_START +#undef ASM_FILE_START +#endif +#define ASM_FILE_START(FILE) \ + do { fprintf (FILE, "\t.file\t"); \ + output_quoted_string (FILE, dump_base_name); \ + fprintf (FILE, "\n"); \ + fprintf (FILE, ".global\t__fltused\n"); \ + } while (0) + +/* if the switch "-mwindows" is passed to ld, then specify to the Microsoft + linker the proper switches and libraries to build a graphical program */ + +#undef LIB_SPEC +#define LIB_SPEC "%{mwindows:-subsystem windows -e _WinMainCRTStartup \ + USER32.LIB%s GDI32.LIB%s COMDLG32.LIB%s WINSPOOL.LIB%s} \ + %{!mwindows:-subsystem console -e _mainCRTStartup} \ + %{mcrtmt:LIBCMT.LIB%s KERNEL32.LIB%s ADVAPI32.LIB%s} \ + %{!mcrtmt:LIBC.LIB%s KERNEL32.LIB%s ADVAPI32.LIB%s} \ + %{v}" + +#include "winnt/win-nt.h" + diff --git a/contrib/gcc/config/i386/winnt.c b/contrib/gcc/config/i386/winnt.c new file mode 100644 index 00000000000..3a7ebf1ba5d --- /dev/null +++ b/contrib/gcc/config/i386/winnt.c @@ -0,0 +1,60 @@ +/* Subroutines for insn-output.c for Windows NT. + Contributed by Douglas Rupp (drupp@cs.washington.edu) + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include "config.h" +#include "rtl.h" +#include "regs.h" +#include "hard-reg-set.h" +#include "output.h" +#include "tree.h" +#include "flags.h" + +/* Return string which is the former assembler name modified with a + suffix consisting of an atsign (@) followed by the number of bytes of + arguments */ + +char * +gen_stdcall_suffix (decl) + tree decl; +{ + int total = 0; + char *asmname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + char *newsym; + + if (TYPE_ARG_TYPES (TREE_TYPE (decl))) + if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (decl)))) + == void_type_node) + { + tree formal_type = TYPE_ARG_TYPES (TREE_TYPE (decl)); + + while (TREE_VALUE (formal_type) != void_type_node) + { + total += TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type))); + formal_type = TREE_CHAIN (formal_type); + } + } + + newsym = xmalloc (strlen (asmname) + 10); + sprintf (newsym, "%s@%d", asmname, total/BITS_PER_UNIT); + return IDENTIFIER_POINTER (get_identifier (newsym)); +} + diff --git a/contrib/gcc/config/i386/x-aix b/contrib/gcc/config/i386/x-aix new file mode 100644 index 00000000000..b191e48fd0f --- /dev/null +++ b/contrib/gcc/config/i386/x-aix @@ -0,0 +1,12 @@ +# There is an alloca in -lbsd, but it is limited to 32K +ALLOCA = alloca.o + +# If you are running out of memory while compiling gcc, with the standard +# /bin/cc uncomment MALLOCLIB line. That version of malloc is slower but +# has less overhead than the one in libc. +#MALLOCLIB = -lmalloc + +# Uncomment out the next line if you want to link with the shareable libc_s. +#CLIB_S = -lc_s + +CLIB = -lld $(MALLOCLIB) $(CLIB_S) diff --git a/contrib/gcc/config/i386/x-freebsd b/contrib/gcc/config/i386/x-freebsd new file mode 100644 index 00000000000..a9b13ba5c81 --- /dev/null +++ b/contrib/gcc/config/i386/x-freebsd @@ -0,0 +1,3 @@ +# Don't run fixproto +STMP_FIXPROTO = +CLIB=-lgnumalloc diff --git a/contrib/gcc/config/i386/x-isc b/contrib/gcc/config/i386/x-isc new file mode 100644 index 00000000000..ea65ec888a3 --- /dev/null +++ b/contrib/gcc/config/i386/x-isc @@ -0,0 +1,3 @@ +CLIB = -lPW -lcposix +X_CFLAGS = -D_POSIX_SOURCE +ENQUIRE_LDFLAGS = -posix $(LDFLAGS) diff --git a/contrib/gcc/config/i386/x-isc3 b/contrib/gcc/config/i386/x-isc3 new file mode 100644 index 00000000000..527cca8132b --- /dev/null +++ b/contrib/gcc/config/i386/x-isc3 @@ -0,0 +1,4 @@ +CLIB = -lPW +# One person said it needs -DPOSIX_JC, but daa@CERF.NET says no. +X_CFLAGS = -D_SYSV3 -Xp +ENQUIRE_LDFLAGS = $(LDFLAGS) diff --git a/contrib/gcc/config/i386/x-ncr3000 b/contrib/gcc/config/i386/x-ncr3000 new file mode 100644 index 00000000000..4ae168b1fe5 --- /dev/null +++ b/contrib/gcc/config/i386/x-ncr3000 @@ -0,0 +1,34 @@ +# Makefile additions for the NCR3000 as host system. + +# Using -O with the AT&T compiler fails, with a message about a missing +# /usr/ccs/lib/optim pass. So override the default in Makefile.in + +CCLIBFLAGS= + +## Supposedly not needed now that xm-sysv4.h includes alloc.h for Metaware. +### NCR3000 ships with a MetaWare compiler installed as CC, which chokes and +### dies all over the place on GCC source. However, the AT&T compiler, +### crusty as it is, can be used to bootstrap GCC. It can be found in +### /usr/ccs/ATT/cc. It is also used to compile the things that should +### not be compiled with GCC. +## +##CC = /usr/ccs/ATT/cc +##OLDCC = /usr/ccs/ATT/cc + +# The rest is just x-i386v4. + +# Some versions of SVR4 have an alloca in /usr/ucblib/libucb.a, and if we are +# careful to link that in after libc we can use it, but since newer versions of +# SVR4 are dropping libucb, it is better to just use the portable C version for +# bootstrapping. Do this by defining ALLOCA. + +ALLOCA = alloca.o + +# We used to build all stages *without* shared libraries because that may make +# debugging the compiler easier (until there is a GDB which supports +# both Dwarf *and* svr4 shared libraries). + +# But james@bigtex.cactus.org says that redefining GCC_CFLAGS causes trouble, +# and that it is easy enough to debug using shared libraries. +# CCLIBFLAGS=-Bstatic -dn -g +# GCC_CFLAGS=-static -g -O2 -B./ diff --git a/contrib/gcc/config/i386/x-next b/contrib/gcc/config/i386/x-next new file mode 100644 index 00000000000..a16b918e2d3 --- /dev/null +++ b/contrib/gcc/config/i386/x-next @@ -0,0 +1,3 @@ +# Make assignments for compiling on NeXT with their compiler version. +CC=cc -traditional-cpp +OLDCC=cc -traditional-cpp diff --git a/contrib/gcc/config/i386/x-osfrose b/contrib/gcc/config/i386/x-osfrose new file mode 100644 index 00000000000..a419bdb7822 --- /dev/null +++ b/contrib/gcc/config/i386/x-osfrose @@ -0,0 +1,31 @@ +# Define CC and OLDCC as the same, so that the tests: +# if [ x"$(OLDCC)" = x"$(CC)" ] ... +# +# will succeed (if OLDCC != CC, it is assumed that GCC is +# being used in secondary stage builds). + +BUILD = +CC = $(OLDCC) +CLIB = -lld +X_CFLAGS = $(DEB_OPT) $(MSTATS) $(SHLIB) $(X_DEFINES) +X_CFLAGS_NODEBUG = $(NO_DEBUG) $(MSTATS) $(OPT) $(PROFILE) $(SHLIB) $(X_DEFINES) $(XCFLAGS) +CPP_ABORT = # -Dabort=fancy_abort +CPPFLAGS = $(CPP_ABORT) $(SYSTEM_INCLUDES) +DEB_OPT = $(OPT) $(DEBUG) $(PROFILE) +DEBUG = +DEBUG_COLLECT = # -DDEBUG +CCLIBFLAGS = -O -DNO_HALF_PIC +GCC_CFLAGS = $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) -B./ -DPOSIX -DNO_HALF_PIC +INSTALL = installbsd -c +LDFLAGS = +MSTATS = # -mstats +OLDCC = /usr/ccs/gcc/gcc +OPT = -O +PROFILE = +SHLIB = -pic-none +SYSTEM_INCLUDES = # -I${BUILD}/usr/include +X_DEFINES = -Dvfork=fork + +libdir = /usr/ccs +mandir = /usr/ccs/gcc/$(target)/$(version) +bindir = /usr/ccs/gcc/$(target)/$(version) diff --git a/contrib/gcc/config/i386/x-sco b/contrib/gcc/config/i386/x-sco new file mode 100644 index 00000000000..f7f14e9f7c0 --- /dev/null +++ b/contrib/gcc/config/i386/x-sco @@ -0,0 +1,7 @@ +RANLIB = : +RANLIB_TEST = false +CC = rcc $(RCCFLAGS) +OLDCC = rcc $(RCCFLAGS) +RCCFLAGS = -Dunix -Di386 -DM_UNIX -DM_I386 -DNULL=0 +CCLIBFLAGS = +CLIB = -lmalloc -lPW diff --git a/contrib/gcc/config/i386/x-sco4 b/contrib/gcc/config/i386/x-sco4 new file mode 100644 index 00000000000..be6080f8893 --- /dev/null +++ b/contrib/gcc/config/i386/x-sco4 @@ -0,0 +1,10 @@ +RANLIB = : +RANLIB_TEST = false +CC = rcc $(RCCFLAGS) +OLDCC = rcc $(RCCFLAGS) +RCCFLAGS = -Dunix -Di386 -DM_UNIX -DM_I386 -DNULL=0 +CCLIBFLAGS = +CLIB = -lmalloc -lPW + +# See all the declarations. +FIXPROTO_DEFINES = -D_XOPEN_SOURCE diff --git a/contrib/gcc/config/i386/x-sysv3 b/contrib/gcc/config/i386/x-sysv3 new file mode 100644 index 00000000000..a1391df851c --- /dev/null +++ b/contrib/gcc/config/i386/x-sysv3 @@ -0,0 +1 @@ +CLIB=-lPW diff --git a/contrib/gcc/config/i386/x-vsta b/contrib/gcc/config/i386/x-vsta new file mode 100644 index 00000000000..e2279a4b59a --- /dev/null +++ b/contrib/gcc/config/i386/x-vsta @@ -0,0 +1 @@ +CLIB=-lm diff --git a/contrib/gcc/config/i386/xm-aix.h b/contrib/gcc/config/i386/xm-aix.h new file mode 100644 index 00000000000..5e5d40281a1 --- /dev/null +++ b/contrib/gcc/config/i386/xm-aix.h @@ -0,0 +1,37 @@ +/* Configuration for GNU C-compiler for IBM PS/2 running AIX/386. + Copyright (C) 1988, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define USG + +#undef TRUE +#undef FALSE + +#include "i386/xm-i386.h" + +#define bcopy(a,b,c) memcpy (b,a,c) +#define bzero(a,b) memset (a,0,b) +#define bcmp(a,b,c) memcmp (a,b,c) + +/* If not compiled with GNU C, use the portable alloca. */ +#ifndef __GNUC__ +#define USE_C_ALLOCA +#endif + +#define HAVE_PUTENV diff --git a/contrib/gcc/config/i386/xm-bsd386.h b/contrib/gcc/config/i386/xm-bsd386.h new file mode 100644 index 00000000000..9deb7ef6c65 --- /dev/null +++ b/contrib/gcc/config/i386/xm-bsd386.h @@ -0,0 +1,6 @@ +/* Configuration for GCC for Intel i386 running BSDI's BSD/386 as host. */ + +#include "i386/xm-i386.h" + +#define HAVE_STRERROR + diff --git a/contrib/gcc/config/i386/xm-dos.h b/contrib/gcc/config/i386/xm-dos.h new file mode 100644 index 00000000000..1dd0c013b1d --- /dev/null +++ b/contrib/gcc/config/i386/xm-dos.h @@ -0,0 +1,20 @@ +#include "i386/xm-i386.h" + +/* Inhibit cccp.c's definition of putenv. */ +#define HAVE_PUTENV + +/* Use semicolons to separate elements of a path. */ +#define PATH_SEPARATOR ';' + +/* Use backslashs to separate levels of directory. */ +#define DIR_SEPARATOR '\\' + +/* Suffix for executable file names. */ +#define EXECUTABLE_SUFFIX ".exe" + +#define MKTEMP_EACH_FILE 1 + +#define NO_PRECOMPILES 1 + +/* sys_errlist proto in cccp.c doesn't match djgpp */ +#define HAVE_STRERROR diff --git a/contrib/gcc/config/i386/xm-freebsd.h b/contrib/gcc/config/i386/xm-freebsd.h new file mode 100644 index 00000000000..007a609f263 --- /dev/null +++ b/contrib/gcc/config/i386/xm-freebsd.h @@ -0,0 +1,4 @@ +/* Configuration for GCC for Intel i386 running FreeBSD as host. */ + +#include +#include diff --git a/contrib/gcc/config/i386/xm-gnu.h b/contrib/gcc/config/i386/xm-gnu.h new file mode 100644 index 00000000000..0b5985f9065 --- /dev/null +++ b/contrib/gcc/config/i386/xm-gnu.h @@ -0,0 +1,5 @@ +/* Configuration for GCC for Intel i386 running GNU as host. */ + +#include +#include + diff --git a/contrib/gcc/config/i386/xm-i386.h b/contrib/gcc/config/i386/xm-i386.h new file mode 100644 index 00000000000..acc16576709 --- /dev/null +++ b/contrib/gcc/config/i386/xm-i386.h @@ -0,0 +1,43 @@ +/* Configuration for GNU C-compiler for Intel 80386. + Copyright (C) 1988, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef i386 +#define i386 +#endif + +/* #defines that need visibility everywhere. */ +#define FALSE 0 +#define TRUE 1 + +/* This describes the machine the compiler is hosted on. */ +#define HOST_BITS_PER_CHAR 8 +#define HOST_BITS_PER_SHORT 16 +#define HOST_BITS_PER_INT 32 +#define HOST_BITS_PER_LONG 32 +#define HOST_BITS_PER_LONGLONG 64 + +/* Arguments to use with `exit'. */ +#define SUCCESS_EXIT_CODE 0 +#define FATAL_EXIT_CODE 33 + +/* target machine dependencies. + tm.h is a symbolic link to the actual target specific file. */ + +#include "tm.h" diff --git a/contrib/gcc/config/i386/xm-isc.h b/contrib/gcc/config/i386/xm-isc.h new file mode 100644 index 00000000000..7a0a47c4df5 --- /dev/null +++ b/contrib/gcc/config/i386/xm-isc.h @@ -0,0 +1,6 @@ +#include "i386/xm-sysv3.h" + +#ifndef REAL_ARITHMETIC +#define REAL_VALUE_ATOF(x, mode) strtod ((x), (char **)0) +extern double strtod (); +#endif diff --git a/contrib/gcc/config/i386/xm-linux.h b/contrib/gcc/config/i386/xm-linux.h new file mode 100644 index 00000000000..42f097ddc6c --- /dev/null +++ b/contrib/gcc/config/i386/xm-linux.h @@ -0,0 +1,24 @@ +/* Configuration for GCC for Intel i386 running Linux. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by H.J. Lu (hjl@nynexst.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include +#include + diff --git a/contrib/gcc/config/i386/xm-lynx.h b/contrib/gcc/config/i386/xm-lynx.h new file mode 100644 index 00000000000..359e41bbe24 --- /dev/null +++ b/contrib/gcc/config/i386/xm-lynx.h @@ -0,0 +1,33 @@ +/* Configuration for GNU C-compiler for i386 platforms running LynxOS. + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include + +/* This describes the machine the compiler is hosted on. */ +#define HOST_BITS_PER_CHAR 8 +#define HOST_BITS_PER_SHORT 16 +#define HOST_BITS_PER_INT 32 +#define HOST_BITS_PER_LONG 32 +#define HOST_BITS_PER_LONGLONG 64 + +/* target machine dependencies. + tm.h is a symbolic link to the actual target specific file. */ + +#include "tm.h" diff --git a/contrib/gcc/config/i386/xm-netbsd.h b/contrib/gcc/config/i386/xm-netbsd.h new file mode 100644 index 00000000000..3a9f3241990 --- /dev/null +++ b/contrib/gcc/config/i386/xm-netbsd.h @@ -0,0 +1,4 @@ +/* Configuration for GCC for Intel i386 running NetBSD as host. */ + +#include +#include diff --git a/contrib/gcc/config/i386/xm-next.h b/contrib/gcc/config/i386/xm-next.h new file mode 100644 index 00000000000..bf903281a0d --- /dev/null +++ b/contrib/gcc/config/i386/xm-next.h @@ -0,0 +1,5 @@ +#include "i386/xm-i386.h" + +/* malloc does better with chunks the size of a page. */ + +#define OBSTACK_CHUNK_SIZE (getpagesize ()) diff --git a/contrib/gcc/config/i386/xm-os2.h b/contrib/gcc/config/i386/xm-os2.h new file mode 100644 index 00000000000..5ff2899cfd5 --- /dev/null +++ b/contrib/gcc/config/i386/xm-os2.h @@ -0,0 +1,57 @@ +/* Configuration for GNU compiler + for an Intel i386 or later processor running OS/2 2.x. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Samuel Figueroa (figueroa@cs.nyu.edu) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef OS2 +#define OS2 +#endif + +#ifdef __IBMC__ +#include /* this defines alloca */ +#define USG +#define ONLY_INT_FIELDS +#define HAVE_PUTENV +#define USE_PROTOTYPES 1 +#define bcmp(a,b,c) memcmp (a,b,c) +#define bcopy(a,b,c) memcpy (b,a,c) +#define bzero(a,b) memset (a,0,b) +#define index strchr +#define rindex strrchr +#define strcasecmp stricmp +#define kill(a,b) raise(b) +#define mktemp tmpnam +#else +#define ____386BSD____ +int spawnv (int modeflag, char *path, char *argv[]); +int spawnvp (int modeflag, char *path, char *argv[]); +#endif /* __IBMC__ */ + +#ifndef PATH_SEPARATOR +#define PATH_SEPARATOR ';' +#endif +#ifndef DIR_SEPARATOR +#define DIR_SEPARATOR '\\' +#endif + +#define EXECUTABLE_SUFFIX ".exe" +#define OBJECT_SUFFIX ".obj" + +#include "i386/xm-i386.h" diff --git a/contrib/gcc/config/i386/xm-osf.h b/contrib/gcc/config/i386/xm-osf.h new file mode 100644 index 00000000000..fda50d98f55 --- /dev/null +++ b/contrib/gcc/config/i386/xm-osf.h @@ -0,0 +1,32 @@ +/* Configuration for GNU C-compiler for 386 running OSF/1 + Copyright (C) 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#undef TRUE +#undef FALSE + +#include "i386/xm-i386.h" + +#define bcopy(a,b,c) memcpy (b,a,c) +#define bzero(a,b) memset (a,0,b) +#define bcmp(a,b,c) memcmp (a,b,c) + +#define HAVE_PUTENV +#define HAVE_VPRINTF + diff --git a/contrib/gcc/config/i386/xm-sco.h b/contrib/gcc/config/i386/xm-sco.h new file mode 100644 index 00000000000..01a63d90e00 --- /dev/null +++ b/contrib/gcc/config/i386/xm-sco.h @@ -0,0 +1,22 @@ +/* Configuration for GCC for Intel i386 running SCO. */ + +#include "i386/xm-sysv3.h" + +/* On SCO 3.2.1, ldexp rejects values outside [0.5, 1). */ + +#define BROKEN_LDEXP + +/* Big buffers improve performance. */ + +#define IO_BUFFER_SIZE (0x8000 - 1024) + +/* SCO has a very small ARG_MAX. */ +#define SMALL_ARG_MAX + +#ifndef __GNUC__ +/* The SCO compiler gets it wrong, and treats enumerated bitfields + as signed quantities, making it impossible to use an 8-bit enum + for compiling GNU C++. */ +#define ONLY_INT_FIELDS 1 +#define CODE_FIELD_BUG 1 +#endif diff --git a/contrib/gcc/config/i386/xm-sun.h b/contrib/gcc/config/i386/xm-sun.h new file mode 100644 index 00000000000..d2e714ecf5c --- /dev/null +++ b/contrib/gcc/config/i386/xm-sun.h @@ -0,0 +1,27 @@ +/* Configuration for GNU C-compiler for Intel 80386 running SunOS 4.0. + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define USG + +#include "i386/xm-i386.h" + +#define bcopy(a,b,c) memcpy (b,a,c) +#define bzero(a,b) memset (a,0,b) +#define bcmp(a,b,c) memcmp (a,b,c) diff --git a/contrib/gcc/config/i386/xm-sysv3.h b/contrib/gcc/config/i386/xm-sysv3.h new file mode 100644 index 00000000000..72078bb1feb --- /dev/null +++ b/contrib/gcc/config/i386/xm-sysv3.h @@ -0,0 +1,4 @@ +/* Configuration for GCC for Intel i386 running System V Release 3. */ + +#include "i386/xm-i386.h" +#include "xm-svr3.h" diff --git a/contrib/gcc/config/i386/xm-sysv4.h b/contrib/gcc/config/i386/xm-sysv4.h new file mode 100644 index 00000000000..49d52b4e7f3 --- /dev/null +++ b/contrib/gcc/config/i386/xm-sysv4.h @@ -0,0 +1,16 @@ +/* Configuration for GCC for Intel i386 running System V Release 4. */ + +#include "i386/xm-i386.h" +#include "xm-svr4.h" + +/* If not compiled with GNU C, use the portable alloca. */ +#ifndef __GNUC__ +#define USE_C_ALLOCA +#endif +#ifdef __HIGHC__ +#include /* for MetaWare High-C on NCR System 3000 */ +#endif + +/* Univel, at least, has a small ARG_MAX. Defining this is harmless + except for causing extra stat calls in the driver program. */ +#define SMALL_ARG_MAX diff --git a/contrib/gcc/config/i386/xm-vsta.h b/contrib/gcc/config/i386/xm-vsta.h new file mode 100644 index 00000000000..bb333aeae67 --- /dev/null +++ b/contrib/gcc/config/i386/xm-vsta.h @@ -0,0 +1,26 @@ +/* Configuration for GNU C-compiler for Intel 80386. + Copyright (C) 1994 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define NO_STAB_H + +#include "i386/xm-i386.h" + +/* Use semicolons to separate elements of a path. */ +#define PATH_SEPARATOR ';' diff --git a/contrib/gcc/config/i386/xm-winnt.h b/contrib/gcc/config/i386/xm-winnt.h new file mode 100644 index 00000000000..d36d2cdb11e --- /dev/null +++ b/contrib/gcc/config/i386/xm-winnt.h @@ -0,0 +1,24 @@ +/* Configuration for GNU compiler + for an Intel i386 or later processor running Windows NT 3.x. + Copyright (C) 1994 Free Software Foundation, Inc. + Contributed by Douglas B. Rupp (drupp@cs.washington.edu) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "winnt/xm-winnt.h" +#include "i386/xm-i386.h" diff --git a/contrib/gcc/config/linux-aout.h b/contrib/gcc/config/linux-aout.h new file mode 100644 index 00000000000..29fb8e9e132 --- /dev/null +++ b/contrib/gcc/config/linux-aout.h @@ -0,0 +1,51 @@ +/* Definitions for Linux + Copyright (C) 1995 Free Software Foundation, Inc. + Contributed by H.J. Lu (hjl@nynexst.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Don't assume anything about the header files. */ +#define NO_IMPLICIT_EXTERN_C + +#undef HAVE_ATEXIT +#define HAVE_ATEXIT + +/* Linux uses ctype from glibc.a. I am not sure how complete it is. + For now, we play safe. It may change later. */ + +#if 0 +#undef MULTIBYTE_CHARS +#define MULTIBYTE_CHARS 1 +#endif + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "%{pg:gcrt0.o%s} %{!pg:%{p:gcrt0.o%s} %{!p:crt0.o%s}} %{static:-static}" + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* We need that too. */ +#define HANDLE_SYSV_PRAGMA diff --git a/contrib/gcc/config/linux.h b/contrib/gcc/config/linux.h new file mode 100644 index 00000000000..c82cfe2dd09 --- /dev/null +++ b/contrib/gcc/config/linux.h @@ -0,0 +1,88 @@ +/* Definitions for Linux with ELF format + Copyright (C) 1995 Free Software Foundation, Inc. + Contributed by Eric Youngdale. + Modified for stabs-in-ELF by H.J. Lu. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Don't assume anything about the header files. */ +#define NO_IMPLICIT_EXTERN_C + +#undef HAVE_ATEXIT +#define HAVE_ATEXIT + +/* Linux uses ctype from glibc.a. I am not sure how complete it is. + For now, we play safe. It may change later. */ + +#if 0 +#undef MULTIBYTE_CHARS +#define MULTIBYTE_CHARS 1 +#endif + +/* There are conflicting reports about whether this system uses + a different assembler syntax. wilson@cygnus.com says # is right. */ +#undef COMMENT_BEGIN +#define COMMENT_BEGIN "#" + +#undef ASM_APP_ON +#define ASM_APP_ON "#APP\n" + +#undef ASM_APP_OFF +#define ASM_APP_OFF "#NO_APP\n" + +/* Use stabs instead of DWARF debug format. */ +#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG +#include "svr4.h" + +#undef MD_EXEC_PREFIX +#undef MD_STARTFILE_PREFIX + +/* Output at beginning of assembler file. */ +/* The .file command should always begin the output. */ +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { \ + output_file_directive (FILE, main_input_filename); \ + fprintf (FILE, "\t.version\t\"01.01\"\n"); \ + } while (0) + +#undef LIBGCC_SPEC +#define LIBGCC_SPEC \ + "%{!shared:-lgcc}" + + +/* Provide a STARTFILE_SPEC appropriate for Linux. Here we add + the Linux magical crtbegin.o file (see crtstuff.c) which + provides part of the support for getting C++ file-scope static + object constructed before entering `main'. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!shared: \ + %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\ + crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}" + +/* Provide a ENDFILE_SPEC appropriate for Linux. Here we tack on + the Linux magical crtend.o file (see crtstuff.c) which + provides part of the support for getting C++ file-scope static + object constructed before entering `main', followed by a normal + Linux "finalizer" file, `crtn.o'. */ + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC \ + "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s" diff --git a/contrib/gcc/config/lynx-ng.h b/contrib/gcc/config/lynx-ng.h new file mode 100644 index 00000000000..a3a9c3799d4 --- /dev/null +++ b/contrib/gcc/config/lynx-ng.h @@ -0,0 +1,118 @@ +/* Target independent definitions for LynxOS, using Lynx's old as and ld. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is for backwards compatibility with older Lynx tools, which use + a version of a.out format. */ + +#undef ASM_SPEC +#define ASM_SPEC "%{mcoff:-C}" + +#undef CPP_SPEC +#define CPP_SPEC "%{mthreads:-D_MULTITHREADED} \ + %{mposix:-D_POSIX_SOURCE} \ + %{msystem-v:-I/usr/include_v}" + +/* Provide required defaults for linker switches. */ + +#undef LINK_SPEC +#define LINK_SPEC "%{msystem-v:-V} %{mcoff:-k}" + +#undef LIB_SPEC +#define LIB_SPEC "%{mthreads:-L/lib/thread/}%{msystem-v:-lc_v}%{!msystem-v:%{mposix:-lc_p} -lc}" + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "%{p:%{mcoff:pinit1.o%s}%{!mcoff:pinit.o%s}}%{!p:%{msystem-v:%{mcoff:vinit1.o%s}%{!mcoff:vinit.o%s}}%{!msystem-v:%{mcoff:init1.o%s}%{!mcoff:init.o%s}}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "%{mcoff:initn.o%s} %{p:_etext.o%s}" + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" + +/* We want to output DBX debugging information. */ + +#define DBX_DEBUGGING_INFO +#undef PREFERRED_DEBUGGING_TYPE +#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG + +/* We optionally want to be able to produce SDB debugging output so that + we can create debuggable SDB/coff files. This won't be needed when + stabs-in-coff works. */ + +#define SDB_DEBUGGING_INFO + +/* Generate calls to memcpy, memcmp and memset. */ + +#define TARGET_MEM_FUNCTIONS + +/* Handle #pragma pack and sometimes #pragma weak. */ + +#define HANDLE_SYSV_PRAGMA + +#define TARGET_THREADS (target_flags & MASK_THREADS) +#define MASK_THREADS 0x40000000 + +#define TARGET_POSIX (target_flags & MASK_POSIX) +#define MASK_POSIX 0x20000000 + +#define TARGET_SYSTEM_V (target_flags & MASK_SYSTEM_V) +#define MASK_SYSTEM_V 0x10000000 + +#define TARGET_COFF (target_flags & MASK_COFF) +#define MASK_COFF 0x08000000 + +#undef SUBTARGET_SWITCHES +#define SUBTARGET_SWITCHES \ + {"threads", MASK_THREADS}, \ + {"posix", MASK_POSIX}, \ + {"system-v", MASK_SYSTEM_V}, \ + {"coff", MASK_COFF}, + +#undef SUBTARGET_OVERRIDE_OPTIONS +#define SUBTARGET_OVERRIDE_OPTIONS \ +{ if (TARGET_SYSTEM_V && profile_flag) \ + warning ("-msystem-v and -p are incompatible"); \ + if (TARGET_SYSTEM_V && TARGET_THREADS) \ + warning ("-msystem-v and -mthreads are incompatible"); } + +/* Define this so that C++ destructors will use atexit. */ + +#define HAVE_ATEXIT + +/* This is defined only so that we can find the assembler. Everything else + is in /bin. */ + +#define MD_EXEC_PREFIX "/usr/local/lib/gcc-" + +/* This is needed because /bin/ld does not handle -L options correctly. */ + +#define LINK_LIBGCC_SPECIAL_1 + +/* The Lynx linker considers __main to be a possible entry point, so we + must use a different name. */ + +#define NAME__MAIN "____main" +#define SYMBOL__MAIN ____main diff --git a/contrib/gcc/config/lynx.h b/contrib/gcc/config/lynx.h new file mode 100644 index 00000000000..04919d4cc9b --- /dev/null +++ b/contrib/gcc/config/lynx.h @@ -0,0 +1,180 @@ +/* Target independent definitions for LynxOS. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* LynxOS is a multi-platform Unix, similar to SVR3, but not identical. + We can get quite a bit from generic svr3, but have to do some overrides. */ + +#include "svr3.h" + +/* Define various macros, depending on the combination of flags. */ + +#undef CPP_SPEC +#define CPP_SPEC "%{mthreads:-D_MULTITHREADED} \ + %{mposix:-D_POSIX_SOURCE} \ + %{msystem-v:-I/usr/include_v}" + +/* No asm spec needed, since using GNU assembler always. */ + +/* No linker spec needed, since using GNU linker always. */ + +#undef LIB_SPEC +#define LIB_SPEC "%{mthreads:-L/lib/thread/} \ + %{msystem-v:-lc_v} \ + %{!msystem-v:%{mposix:-lc_p} -lc -lm}" + +/* Set the appropriate names for the Lynx startfiles. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "%{p:%{mthreads:thread/pinit1.o%s}%{!mthreads:pinit1.o%s}}%{!p:%{msystem-v:vinit1.o%s -e_start}%{!msystem-v:%{mthreads:thread/init1.o%s}%{!mthreads:init1.o%s}}}" + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "%{p:_etext.o%s}%{!p:initn.o%s}" + +/* Override the svr3 versions. */ + +#undef WCHAR_TYPE +#define WCHAR_TYPE "int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" + +/* We want to output DBX (stabs) debugging information normally. */ + +#define DBX_DEBUGGING_INFO +#undef PREFERRED_DEBUGGING_TYPE +#define PREFERRED_DEBUGGING_TYPE DBX_DEBUG + +/* It is convenient to be able to generate standard coff debugging + if requested via -gcoff. */ + +#define SDB_DEBUGGING_INFO + +/* Be function-relative for block and source line stab directives. */ + +#define DBX_BLOCKS_FUNCTION_RELATIVE 1 + +/* but, to make this work, functions must appear prior to line info */ + +#define DBX_FUNCTION_FIRST + +/* Generate a blank trailing N_SO to mark the end of the .o file, since + we can't depend upon the linker to mark .o file boundaries with + embedded stabs. */ + +#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \ + fprintf (FILE, \ + "\t.text\n\t.stabs \"\",%d,0,0,Letext\nLetext:\n", N_SO) + +#undef ASM_OUTPUT_SOURCE_LINE +#define ASM_OUTPUT_SOURCE_LINE(file, line) \ + { static int sym_lineno = 1; \ + fprintf (file, ".stabn 68,0,%d,.LM%d-", \ + line, sym_lineno); \ + assemble_name (file, \ + XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \ + fprintf (file, "\n.LM%d:\n", sym_lineno); \ + sym_lineno += 1; } + +/* Handle #pragma pack and sometimes #pragma weak. */ + +#define HANDLE_SYSV_PRAGMA + +/* Some additional command-line options. */ + +#define TARGET_THREADS (target_flags & MASK_THREADS) +#define MASK_THREADS 0x40000000 + +#define TARGET_POSIX (target_flags & MASK_POSIX) +#define MASK_POSIX 0x20000000 + +#define TARGET_SYSTEM_V (target_flags & MASK_SYSTEM_V) +#define MASK_SYSTEM_V 0x10000000 + +#undef SUBTARGET_SWITCHES +#define SUBTARGET_SWITCHES \ + {"threads", MASK_THREADS}, \ + {"posix", MASK_POSIX}, \ + {"system-v", MASK_SYSTEM_V}, + +#undef SUBTARGET_OVERRIDE_OPTIONS +#define SUBTARGET_OVERRIDE_OPTIONS \ +do { \ + if (TARGET_SYSTEM_V && profile_flag) \ + warning ("-msystem-v and -p are incompatible"); \ + if (TARGET_SYSTEM_V && TARGET_THREADS) \ + warning ("-msystem-v and -mthreads are incompatible"); \ +} while (0) + +/* Define this so that C++ destructors will use atexit, since LynxOS + calls exit after main returns. */ + +#define HAVE_ATEXIT + +/* Since init.o et al put all sorts of stuff into the init section, + we can't use the standard init section support in crtbegin.o. */ + +#undef INIT_SECTION_ASM_OP + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_const, in_bss, in_ctors, in_dtors, in_fini, + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CONST_SECTION_FUNCTION \ + BSS_SECTION_FUNCTION \ + CTORS_SECTION_FUNCTION \ + DTORS_SECTION_FUNCTION \ + FINI_SECTION_FUNCTION + +#undef CTORS_SECTION_ASM_OP +#define CTORS_SECTION_ASM_OP ".section\t.ctors" +#undef DTORS_SECTION_ASM_OP +#define DTORS_SECTION_ASM_OP ".section\t.dtors" + +#define INT_ASM_OP ".long" + +/* A C statement (sans semicolon) to output an element in the table of + global constructors. */ +#undef ASM_OUTPUT_CONSTRUCTOR +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#undef ASM_OUTPUT_DESTRUCTOR +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +#undef DO_GLOBAL_CTORS_BODY +#undef DO_GLOBAL_DTORS_BODY + +/* LynxOS doesn't have mcount. */ +#undef FUNCTION_PROFILER +#define FUNCTION_PROFILER(file, profile_label_no) diff --git a/contrib/gcc/config/netbsd.h b/contrib/gcc/config/netbsd.h new file mode 100644 index 00000000000..8c0974ade4d --- /dev/null +++ b/contrib/gcc/config/netbsd.h @@ -0,0 +1,196 @@ +/* NETBSD_NATIVE is defined when gcc is integrated into the NetBSD + source tree so it can be configured appropriately without using + the GNU configure/build mechanism. */ + +#ifdef NETBSD_NATIVE + +/* Look for the include files in the system-defined places. */ + +#undef GPLUSPLUS_INCLUDE_DIR +#define GPLUSPLUS_INCLUDE_DIR "/usr/include/g++" + +#undef GCC_INCLUDE_DIR +#define GCC_INCLUDE_DIR "/usr/include" + +#undef INCLUDE_DEFAULTS +#define INCLUDE_DEFAULTS \ + { \ + { GPLUSPLUS_INCLUDE_DIR, 1, 1 }, \ + { GCC_INCLUDE_DIR, 0, 0 }, \ + { 0, 0, 0 } \ + } + +/* Under NetBSD, the normal location of the compiler back ends is the + /usr/libexec directory. */ + +#undef STANDARD_EXEC_PREFIX +#define STANDARD_EXEC_PREFIX "/usr/libexec/" + +/* Under NetBSD, the normal location of the various *crt*.o files is the + /usr/lib directory. */ + +#undef STANDARD_STARTFILE_PREFIX +#define STANDARD_STARTFILE_PREFIX "/usr/lib/" + +#endif + + +/* Provide a CPP_SPEC appropriate for NetBSD. Current we just deal with + the GCC option `-posix'. */ + +#undef CPP_SPEC +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE}" + +/* Provide an ASM_SPEC appropriate for NetBSD. Currently we only deal + with the options for generating PIC code. */ + +#undef ASM_SPEC +#define ASM_SPEC " %| %{fpic:-k} %{fPIC:-k -K}" + +/* Provide a LIB_SPEC appropriate for NetBSD. Just select the appropriate + libc, depending on whether we're doing profiling. */ + +#undef LIB_SPEC +#define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}" + +/* Provide a LINK_SPEC appropriate for NetBSD. Here we provide support + for the special GCC options -static, -assert, and -nostdlib. */ + +#undef LINK_SPEC +#define LINK_SPEC \ + "%{!nostdlib:%{!r*:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} %{assert*}" + + +/* We have atexit(3). */ + +#define HAVE_ATEXIT + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +/* + * Some imports from svr4.h in support of shared libraries. + * Currently, we need the DECLARE_OBJECT_SIZE stuff. + */ + +/* Define the strings used for the special svr4 .type and .size directives. + These strings generally do not vary from one system running svr4 to + another, but if a given system (e.g. m88k running svr) needs to use + different pseudo-op names for these, they may be overridden in the + file which includes this one. */ + +#undef TYPE_ASM_OP +#undef SIZE_ASM_OP +#define TYPE_ASM_OP ".type" +#define SIZE_ASM_OP ".size" + +/* This is how we tell the assembler that a symbol is weak. */ + +#undef ASM_WEAKEN_LABEL +#define ASM_WEAKEN_LABEL(FILE,NAME) \ + do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ + fputc ('\n', FILE); } while (0) + +/* The following macro defines the format used to output the second + operand of the .type assembler directive. Different svr4 assemblers + expect various different forms for this operand. The one given here + is just a default. You may need to override it in your machine- + specific tm.h file (depending upon the particulars of your assembler). */ + +#undef TYPE_OPERAND_FMT +#define TYPE_OPERAND_FMT "@%s" + +/* Write the extra assembler code needed to declare a function's result. + Most svr4 assemblers don't require any special declaration of the + result value, but there are exceptions. */ + +#ifndef ASM_DECLARE_RESULT +#define ASM_DECLARE_RESULT(FILE, RESULT) +#endif + +/* These macros generate the special .type and .size directives which + are used to set the corresponding fields of the linker symbol table + entries in an ELF object file under SVR4. These macros also output + the starting labels for the relevant functions/objects. */ + +/* Write the extra assembler code needed to declare a function properly. + Some svr4 assemblers need to also have something extra said about the + function's return value. We allow for that here. */ + +#undef ASM_DECLARE_FUNCTION_NAME +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "function"); \ + putc ('\n', FILE); \ + ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Write the extra assembler code needed to declare an object properly. */ + +#undef ASM_DECLARE_OBJECT_NAME +#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "object"); \ + putc ('\n', FILE); \ + size_directive_output = 0; \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Output the size directive for a decl in rest_of_decl_compilation + in the case where we did not do so before the initializer. + Once we find the error_mark_node, we know that the value of + size_directive_output was set + by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ + +#undef ASM_FINISH_DECLARE_OBJECT +#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ +do { \ + char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \ + && ! AT_END && TOP_LEVEL \ + && DECL_INITIAL (DECL) == error_mark_node \ + && !size_directive_output) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, name); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + } while (0) + +/* This is how to declare the size of a function. */ + +#undef ASM_DECLARE_FUNCTION_SIZE +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ + do { \ + if (!flag_inhibit_size_directive) \ + { \ + char label[256]; \ + static int labelno; \ + labelno++; \ + ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, (FNAME)); \ + fprintf (FILE, ","); \ + assemble_name (FILE, label); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, (FNAME)); \ + putc ('\n', FILE); \ + } \ + } while (0) diff --git a/contrib/gcc/config/nextstep.c b/contrib/gcc/config/nextstep.c new file mode 100644 index 00000000000..823bceeffe3 --- /dev/null +++ b/contrib/gcc/config/nextstep.c @@ -0,0 +1,84 @@ +/* Functions for generic NeXT as target machine for GNU C compiler. + Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Make everything that used to go in the text section really go there. */ + +int flag_no_mach_text_sections = 0; + +#define OPT_STRCMP(opt) (!strncmp (opt, p, sizeof (opt)-1)) + +/* 1 if handle_pragma has been called yet. */ + +static int pragma_initialized; + +/* Initial setting of `optimize'. */ + +static int initial_optimize_flag; + +extern char *get_directive_line (); + +/* Called from check_newline via the macro HANDLE_PRAGMA. + FINPUT is the source file input stream. */ + +void +handle_pragma (finput, get_line_function) + FILE *finput; + char *(*get_line_function) (); +{ + register char *p = (*get_line_function) (finput); + + /* Record initial setting of optimize flag, so we can restore it. */ + if (!pragma_initialized) + { + pragma_initialized = 1; + initial_optimize_flag = optimize; + } + + if (OPT_STRCMP ("CC_OPT_ON")) + { + optimize = 1, obey_regdecls = 0; + warning ("optimization turned on"); + } + else if (OPT_STRCMP ("CC_OPT_OFF")) + { + optimize = 0, obey_regdecls = 1; + warning ("optimization turned off"); + } + else if (OPT_STRCMP ("CC_OPT_RESTORE")) + { + extern int initial_optimize_flag; + + if (optimize != initial_optimize_flag) + { + if (initial_optimize_flag) + obey_regdecls = 0; + else + obey_regdecls = 1; + optimize = initial_optimize_flag; + } + warning ("optimization level restored"); + } + else if (OPT_STRCMP ("CC_WRITABLE_STRINGS")) + flag_writable_strings = 1; + else if (OPT_STRCMP ("CC_NON_WRITABLE_STRINGS")) + flag_writable_strings = 0; + else if (OPT_STRCMP ("CC_NO_MACH_TEXT_SECTIONS")) + flag_no_mach_text_sections = 1; +} diff --git a/contrib/gcc/config/nextstep.h b/contrib/gcc/config/nextstep.h new file mode 100644 index 00000000000..6e2e986713e --- /dev/null +++ b/contrib/gcc/config/nextstep.h @@ -0,0 +1,567 @@ +/* nextstep.h -- operating system specific defines to be used when + targeting GCC for NeXTSTEP. + Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Use new NeXT include file search path. + In a cross compiler with NeXT as target, don't expect + the host to use Next's directory scheme. */ + +#ifndef CROSS_COMPILE +#undef INCLUDE_DEFAULTS +#define INCLUDE_DEFAULTS \ + { \ + { GPLUSPLUS_INCLUDE_DIR, 1, 1 }, \ + { LOCAL_INCLUDE_DIR, 0, 1 }, \ + { TOOL_INCLUDE_DIR, 0, 1 }, \ + { GCC_INCLUDE_DIR, 0, 0 }, \ + /* These are for fixincludes-fixed ansi/bsd headers \ + which wouldn't be found otherwise. \ + (The use of string catenation here is OK since \ + NeXT's native compiler is derived from GCC.) */ \ + { GCC_INCLUDE_DIR "/ansi", 0, 0 }, \ + { GCC_INCLUDE_DIR "/bsd", 0, 0 }, \ + { "/NextDeveloper/Headers", 0, 0 }, \ + { "/NextDeveloper/Headers/ansi", 0, 0 }, \ + { "/NextDeveloper/Headers/bsd", 0, 0 }, \ + { "/LocalDeveloper/Headers", 0, 0 }, \ + { "/LocalDeveloper/Headers/ansi", 0, 0 }, \ + { "/LocalDeveloper/Headers/bsd", 0, 0 }, \ + { "/NextDeveloper/2.0CompatibleHeaders", 0, 0 }, \ + { STANDARD_INCLUDE_DIR, 0, 0 }, \ + { "/usr/include/bsd", 0, 0 }, \ + { 0, 0, 0 } \ + } +#endif /* CROSS_COMPILE */ + +#undef EXTRA_FORMAT_FUNCTIONS +#define EXTRA_FORMAT_FUNCTIONS \ + "NXPrintf", FALSE, 2, FALSE, \ + "NXScanf", TRUE, 2, FALSE, \ + "NXVPrintf", FALSE, 2, TRUE, \ + "NXVScanf", TRUE, 2, TRUE, \ + "DPSPrintf", FALSE, 2, FALSE, \ + "bsd_sprintf", FALSE, 2, FALSE, \ + "bsd_vsprintf", FALSE, 2, TRUE, + +/* Make -fnext-runtime the default. */ + +#define NEXT_OBJC_RUNTIME + +/* We have atexit. */ + +#define HAVE_ATEXIT + +/* Enable recent gcc to compile under the old gcc in Next release 1.0. */ + +#define __inline inline + +/* wchar_t is unsigned short */ + +#undef WCHAR_TYPE +#define WCHAR_TYPE "short unsigned int" +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE (BITS_PER_WORD / 2) + +/* Don't default to pcc-struct-return, because gcc is the only compiler, and + we want to retain compatibility with older gcc versions. */ + +#undef DEFAULT_PCC_STRUCT_RETURN +#define DEFAULT_PCC_STRUCT_RETURN 0 + +/* These compiler options take n arguments. */ + +#undef WORD_SWITCH_TAKES_ARG +#define WORD_SWITCH_TAKES_ARG(STR) \ + (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) ? 1 : \ + !strcmp (STR, "segalign") ? 1 : \ + !strcmp (STR, "seg1addr") ? 1 : \ + !strcmp (STR, "segaddr") ? 2 : \ + !strcmp (STR, "sectobjectsymbols") ? 2 : \ + !strcmp (STR, "segprot") ? 3 : \ + !strcmp (STR, "sectcreate") ? 3 : \ + !strcmp (STR, "sectalign") ? 3 : \ + !strcmp (STR, "segcreate") ? 3 : \ + !strcmp (STR, "sectorder") ? 3 : \ + !strcmp (STR, "siff-mask") ? 1 : \ + !strcmp (STR, "siff-filter") ? 1 : \ + !strcmp (STR, "siff-warning") ? 1 : \ + !strcmp (STR, "arch") ? 1 : \ + !strcmp (STR, "pagezero_size") ? 1 : \ + 0) + +#undef WORD_SWITCH +#define WORD_SWITCH(STR) \ + (WORD_SWITCH_TAKES_ARG (STR) \ + || !strcmp (STR, "bsd") \ + || !strcmp (STR, "object") \ + || !strcmp (STR, "ObjC") \ + || !strcmp (STR, "all_load")) + +/* Machine dependent ccp options. */ + +#undef CPP_SPEC +#define CPP_SPEC "%{!traditional: -D__STDC__} \ + %{posixstrict:-D_POSIX_SOURCE} \ + %{!posixstrict:%{bsd:-D__STRICT_BSD__} \ + %{posix:-D_POSIX_SOURCE} \ + %{!ansi:-D_NEXT_SOURCE}} \ + %{MD:-MD %M} %{MMD:-MMD %M}" + +/* Machine dependent ld options. */ + +#undef LINK_SPEC +#define LINK_SPEC "%{Z} %{M} \ +%{execute*} %{preload*} %{fvmlib*} \ +%{segalign*} %{seg1addr*} %{segaddr*} %{segprot*} \ +%{pagezero_size*} \ +%{seglinkedit*} %{noseglinkedit*} \ +%{sectcreate*} %{sectalign*} %{sectobjectsymbols}\ +%{segcreate*} %{Mach*} %{whyload} %{w} \ +%{sectorder*} %{whatsloaded} %{ObjC} %{all_load} %{object}" + +/* Machine dependent libraries. */ + +#undef LIB_SPEC +#define LIB_SPEC "%{!posix*:-lsys_s} %{posix*:-lposix}" + +/* We specify crt0.o as -lcrt0.o so that ld will search the library path. */ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC \ + "%{!posix*:%{pg:-lgcrt0.o}%{!pg: \ + %{p:%e-p profiling is no longer supported. Use -pg instead.} \ + %{!p:-lcrt0.o}}}\ + %{posix*:%{pg:-lgposixcrt0.o}%{!pg: \ + %{p:%e-p profiling is no longer supported. Use -pg instead.} \ + %{!p:-lposixcrt0.o}}}" + +/* Why not? */ + +#undef DOLLARS_IN_IDENTIFIERS +#define DOLLARS_IN_IDENTIFIERS 2 + +/* Allow #sscs (but don't do anything). */ + +#define SCCS_DIRECTIVE + +/* We use Dbx symbol format. */ + +#undef SDB_DEBUGGING_INFO +#undef XCOFF_DEBUGGING_INFO +#define DBX_DEBUGGING_INFO + +/* This saves a fair amount of space. */ + +#undef DBX_CONTIN_LENGTH +#define DBX_CONTIN_LENGTH 0 + +/* These screw up NeXT's gdb at the moment, so don't use them. */ + +#undef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY +#define DBX_OUTPUT_MAIN_SOURCE_DIRECTORY(FILE, FILENAME) + +/* These come from bsd386.h, but are specific to sequent, so make sure + they don't bite us. */ + +#undef DBX_NO_XREFS +#undef DBX_CONTIN_LENGTH + +/* gdb needs a null N_SO at the end of each file for scattered loading. */ + +#undef DBX_OUTPUT_MAIN_SOURCE_FILE_END +#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \ + fprintf (FILE, \ + "\t.text\n\t.stabs \"%s\",%d,0,0,Letext\nLetext:\n", \ + "" , N_SO) + +/* Don't use .gcc_compiled symbols to communicate with GDB; + They interfere with numerically sorted symbol lists. */ + +#undef ASM_IDENTIFY_GCC +#define ASM_IDENTIFY_GCC(asm_out_file) +#undef INIT_SECTION_ASM_OP +#define INIT_SECTION_ASM_OP +#undef INVOKE__main + +#undef ASM_OUTPUT_CONSTRUCTOR +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { constructor_section (); \ + ASM_OUTPUT_ALIGN (FILE, 1); \ + fprintf (FILE, "\t.long "); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + fprintf (FILE, ".reference .constructors_used\n"); \ + } while (0) + +#undef ASM_OUTPUT_DESTRUCTOR +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { destructor_section (); \ + ASM_OUTPUT_ALIGN (FILE, 1); \ + fprintf (FILE, "\t.long "); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + fprintf (FILE, ".reference .destructors_used\n"); \ + } while (0) + +/* Don't output a .file directive. That is only used by the assembler for + error reporting. */ +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) + +#undef ASM_FILE_END +#define ASM_FILE_END(FILE) \ + do { \ + extern char *language_string; \ + if (strcmp (language_string, "GNU C++") == 0) \ + { \ + constructor_section (); \ + destructor_section (); \ + ASM_OUTPUT_ALIGN (FILE, 1); \ + } \ + } while (0) + +/* How to parse #pragma's */ + +#undef HANDLE_PRAGMA +#define HANDLE_PRAGMA(finput) handle_pragma (finput, &get_directive_line) + +/* Give methods pretty symbol names on NeXT. */ + +#undef OBJC_GEN_METHOD_LABEL +#define OBJC_GEN_METHOD_LABEL(BUF,IS_INST,CLASS_NAME,CAT_NAME,SEL_NAME,NUM) \ + do { if (CAT_NAME) \ + sprintf (BUF, "%c[%s(%s) %s]", (IS_INST) ? '-' : '+', \ + (CLASS_NAME), (CAT_NAME), (SEL_NAME)); \ + else \ + sprintf (BUF, "%c[%s %s]", (IS_INST) ? '-' : '+', \ + (CLASS_NAME), (SEL_NAME)); \ + } while (0) + +/* Wrap new method names in quotes so the assembler doesn't gag. + Make Objective-C internal symbols local. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) \ + do { if (NAME[0] == '+' || NAME[0] == '-') fprintf (FILE, "\"%s\"", NAME); \ + else if (!strncmp (NAME, "_OBJC_", 6)) fprintf (FILE, "L%s", NAME); \ + else if (!strncmp (NAME, ".objc_class_name_", 17)) \ + fprintf (FILE, "%s", NAME); \ + else fprintf (FILE, "_%s", NAME); } while (0) + +#undef ALIGN_ASM_OP +#define ALIGN_ASM_OP ".align" + +#undef ASM_OUTPUT_ALIGN +#define ASM_OUTPUT_ALIGN(FILE,LOG) \ + if ((LOG) != 0) \ + fprintf (FILE, "\t%s %d\n", ALIGN_ASM_OP, (LOG)) + +/* Ensure correct alignment of bss data. */ + +#undef ASM_OUTPUT_ALIGNED_LOCAL +#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \ +( fputs (".lcomm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u,%u\n", (SIZE), floor_log2 ((ALIGN) / BITS_PER_UNIT))) + +/* Output #ident as a .ident. */ + +#undef ASM_OUTPUT_IDENT +#define ASM_OUTPUT_IDENT(FILE, NAME) fprintf (FILE, "\t.ident \"%s\"\n", NAME); + +/* The maximum alignment which the object file format can support. + For NeXT's Mach-O format, this is 2^15. */ + +#undef MAX_OFILE_ALIGNMENT +#define MAX_OFILE_ALIGNMENT 0x8000 + +/* Create new Mach-O sections. */ + +#undef SECTION_FUNCTION +#define SECTION_FUNCTION(FUNCTION, SECTION, DIRECTIVE, WAS_TEXT, OBJC) \ +void \ +FUNCTION () \ +{ \ + extern void text_section (); \ + extern void objc_section_init (); \ + extern int flag_no_mach_text_sections; \ + \ + if (WAS_TEXT && flag_no_mach_text_sections) \ + text_section (); \ + else if (in_section != SECTION) \ + { \ + if (OBJC) \ + objc_section_init (); \ + fprintf (asm_out_file, "%s\n", DIRECTIVE); \ + in_section = SECTION; \ + } \ +} \ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS \ + in_const, in_cstring, in_literal4, in_literal8, \ + in_constructor, in_destructor, \ + in_objc_class, in_objc_meta_class, in_objc_category, \ + in_objc_class_vars, in_objc_instance_vars, \ + in_objc_cls_meth, in_objc_inst_meth, \ + in_objc_cat_cls_meth, in_objc_cat_inst_meth, \ + in_objc_selector_refs, \ + in_objc_symbols, in_objc_module_info, \ + in_objc_protocol, in_objc_string_object, \ + in_objc_class_names, in_objc_meth_var_names, \ + in_objc_meth_var_types, in_objc_cls_refs + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ +SECTION_FUNCTION (const_section, \ + in_const, \ + ".const", 1, 0) \ +SECTION_FUNCTION (cstring_section, \ + in_cstring, \ + ".cstring", 1, 0) \ +SECTION_FUNCTION (literal4_section, \ + in_literal4, \ + ".literal4", 1, 0) \ +SECTION_FUNCTION (literal8_section, \ + in_literal8, \ + ".literal8", 1, 0) \ +SECTION_FUNCTION (constructor_section, \ + in_constructor, \ + ".constructor", 0, 0) \ +SECTION_FUNCTION (destructor_section, \ + in_destructor, \ + ".destructor", 0, 0) \ +SECTION_FUNCTION (objc_class_section, \ + in_objc_class, \ + ".objc_class", 0, 1) \ +SECTION_FUNCTION (objc_meta_class_section, \ + in_objc_meta_class, \ + ".objc_meta_class", 0, 1) \ +SECTION_FUNCTION (objc_category_section, \ + in_objc_category, \ + ".objc_category", 0, 1) \ +SECTION_FUNCTION (objc_class_vars_section, \ + in_objc_class_vars, \ + ".objc_class_vars", 0, 1) \ +SECTION_FUNCTION (objc_instance_vars_section, \ + in_objc_instance_vars, \ + ".objc_instance_vars", 0, 1) \ +SECTION_FUNCTION (objc_cls_meth_section, \ + in_objc_cls_meth, \ + ".objc_cls_meth", 0, 1) \ +SECTION_FUNCTION (objc_inst_meth_section, \ + in_objc_inst_meth, \ + ".objc_inst_meth", 0, 1) \ +SECTION_FUNCTION (objc_cat_cls_meth_section, \ + in_objc_cat_cls_meth, \ + ".objc_cat_cls_meth", 0, 1) \ +SECTION_FUNCTION (objc_cat_inst_meth_section, \ + in_objc_cat_inst_meth, \ + ".objc_cat_inst_meth", 0, 1) \ +SECTION_FUNCTION (objc_selector_refs_section, \ + in_objc_selector_refs, \ + ".objc_message_refs", 0, 1) \ +SECTION_FUNCTION (objc_symbols_section, \ + in_objc_symbols, \ + ".objc_symbols", 0, 1) \ +SECTION_FUNCTION (objc_module_info_section, \ + in_objc_module_info, \ + ".objc_module_info", 0, 1) \ +SECTION_FUNCTION (objc_protocol_section, \ + in_objc_protocol, \ + ".objc_protocol", 0, 1) \ +SECTION_FUNCTION (objc_string_object_section, \ + in_objc_string_object, \ + ".objc_string_object", 0, 1) \ +SECTION_FUNCTION (objc_class_names_section, \ + in_objc_class_names, \ + ".objc_class_names", 0, 1) \ +SECTION_FUNCTION (objc_meth_var_names_section, \ + in_objc_meth_var_names, \ + ".objc_meth_var_names", 0, 1) \ +SECTION_FUNCTION (objc_meth_var_types_section, \ + in_objc_meth_var_types, \ + ".objc_meth_var_types", 0, 1) \ +SECTION_FUNCTION (objc_cls_refs_section, \ + in_objc_cls_refs, \ + ".objc_cls_refs", 0, 1) \ + \ +void \ +objc_section_init () \ +{ \ + static int been_here = 0; \ + \ + if (been_here == 0) \ + { \ + been_here = 1; \ + objc_class_section (); \ + objc_meta_class_section (); \ + objc_cat_cls_meth_section (); \ + objc_cat_inst_meth_section (); \ + objc_cls_meth_section (); \ + objc_inst_meth_section (); \ + objc_selector_refs_section (); \ + objc_symbols_section (); \ + objc_category_section (); \ + objc_protocol_section (); \ + objc_class_vars_section (); \ + objc_instance_vars_section (); \ + objc_module_info_section (); \ + objc_string_object_section (); \ + objc_class_names_section (); \ + objc_meth_var_names_section (); \ + objc_meth_var_types_section (); \ + objc_cls_refs_section (); \ + } \ +} + +#undef READONLY_DATA_SECTION +#define READONLY_DATA_SECTION const_section + +#undef SELECT_SECTION +#define SELECT_SECTION(exp,reloc) \ + do \ + { \ + if (TREE_CODE (exp) == STRING_CST) \ + { \ + if (flag_writable_strings) \ + data_section (); \ + else if (TREE_STRING_LENGTH (exp) != \ + strlen (TREE_STRING_POINTER (exp)) + 1) \ + readonly_data_section (); \ + else \ + cstring_section (); \ + } \ + else if (TREE_CODE (exp) == INTEGER_CST \ + || TREE_CODE (exp) == REAL_CST) \ + { \ + tree size = TYPE_SIZE (TREE_TYPE (exp)); \ + \ + if (TREE_CODE (size) == INTEGER_CST && \ + TREE_INT_CST_LOW (size) == 4 && \ + TREE_INT_CST_HIGH (size) == 0) \ + literal4_section (); \ + else if (TREE_CODE (size) == INTEGER_CST && \ + TREE_INT_CST_LOW (size) == 8 && \ + TREE_INT_CST_HIGH (size) == 0) \ + literal8_section (); \ + else \ + readonly_data_section (); \ + } \ + else if (TREE_CODE (exp) == CONSTRUCTOR \ + && TREE_TYPE (exp) \ + && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE \ + && TYPE_NAME (TREE_TYPE (exp)) \ + && TREE_CODE (TYPE_NAME (TREE_TYPE (exp))) == IDENTIFIER_NODE \ + && IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (exp)))) \ + { \ + if (!strcmp (IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (exp))), \ + "NXConstantString")) \ + objc_string_object_section (); \ + else if ((TREE_READONLY (exp) || TREE_CONSTANT (exp)) \ + && !TREE_SIDE_EFFECTS (exp)) \ + readonly_data_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (exp) == VAR_DECL && \ + DECL_NAME (exp) && \ + TREE_CODE (DECL_NAME (exp)) == IDENTIFIER_NODE && \ + IDENTIFIER_POINTER (DECL_NAME (exp)) && \ + !strncmp (IDENTIFIER_POINTER (DECL_NAME (exp)), "_OBJC_", 6)) \ + { \ + const char *name = IDENTIFIER_POINTER (DECL_NAME (exp)); \ + \ + if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20)) \ + objc_cls_meth_section (); \ + else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23)) \ + objc_inst_meth_section (); \ + else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20)) \ + objc_cat_cls_meth_section (); \ + else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23)) \ + objc_cat_inst_meth_section (); \ + else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22)) \ + objc_class_vars_section (); \ + else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25)) \ + objc_instance_vars_section (); \ + else if (!strncmp (name, "_OBJC_CLASS_PROTOCOLS_", 22)) \ + objc_cat_cls_meth_section (); \ + else if (!strncmp (name, "_OBJC_CLASS_NAME_", 17)) \ + objc_class_names_section (); \ + else if (!strncmp (name, "_OBJC_METH_VAR_NAME_", 20)) \ + objc_meth_var_names_section (); \ + else if (!strncmp (name, "_OBJC_METH_VAR_TYPE_", 20)) \ + objc_meth_var_types_section (); \ + else if (!strncmp (name, "_OBJC_CLASS_REFERENCES", 22)) \ + objc_cls_refs_section (); \ + else if (!strncmp (name, "_OBJC_CLASS_", 12)) \ + objc_class_section (); \ + else if (!strncmp (name, "_OBJC_METACLASS_", 16)) \ + objc_meta_class_section (); \ + else if (!strncmp (name, "_OBJC_CATEGORY_", 15)) \ + objc_category_section (); \ + else if (!strncmp (name, "_OBJC_SELECTOR_REFERENCES", 25)) \ + objc_selector_refs_section (); \ + else if (!strncmp (name, "_OBJC_SYMBOLS", 13)) \ + objc_symbols_section (); \ + else if (!strncmp (name, "_OBJC_MODULES", 13)) \ + objc_module_info_section (); \ + else if (!strncmp (name, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32)) \ + objc_cat_inst_meth_section (); \ + else if (!strncmp (name, "_OBJC_PROTOCOL_CLASS_METHODS_", 29)) \ + objc_cat_cls_meth_section (); \ + else if (!strncmp (name, "_OBJC_PROTOCOL_REFS_", 20)) \ + objc_cat_cls_meth_section (); \ + else if (!strncmp (name, "_OBJC_PROTOCOL_", 15)) \ + objc_protocol_section (); \ + else if ((TREE_READONLY (exp) || TREE_CONSTANT (exp)) \ + && !TREE_SIDE_EFFECTS (exp)) \ + readonly_data_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (exp) == VAR_DECL) \ + { \ + if ((flag_pic && reloc) \ + || !TREE_READONLY (exp) || TREE_SIDE_EFFECTS (exp) \ + || !DECL_INITIAL (exp) \ + || (DECL_INITIAL (exp) != error_mark_node \ + && !TREE_CONSTANT (DECL_INITIAL (exp)))) \ + data_section (); \ + else \ + readonly_data_section (); \ + } \ + else \ + readonly_data_section (); \ + } \ + while (0) + +#undef SELECT_RTX_SECTION +#define SELECT_RTX_SECTION(mode, rtx) \ + do \ + { \ + if (GET_MODE_SIZE(mode) == 8) \ + literal8_section(); \ + else if (GET_MODE_SIZE(mode) == 4) \ + literal4_section(); \ + else \ + const_section (); \ + } \ + while (0) diff --git a/contrib/gcc/config/nextstep21.h b/contrib/gcc/config/nextstep21.h new file mode 100644 index 00000000000..8009571672b --- /dev/null +++ b/contrib/gcc/config/nextstep21.h @@ -0,0 +1,65 @@ +/* nextstep.h -- operating system specific defines to be used when + targeting GCC for NeXTSTEP. + Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* changed for NeXTStep 2.1, Ch. Kranz, 2/94, 3/94 */ +#include "nextstep.h" + +/* set flag_gnu_linker=0, use collect2 for linking */ +#undef USE_COLLECT2 +#define USE_COLLECT2 + +/* use this until a newer gdb for NeXTStep21 is available */ +#define DEFAULT_GDB_EXTENSIONS 0 + +/* we need the call to __main to start all global destructors and constructors + correctly, so undef INIT_SECTION_ASM_OP, (see libgcc2.c line 1965) + and define INVOKE_main */ +#undef INIT_SECTION_ASM_OP +#define INVOKE__main + +/* We call the global destructors, constructors from __main */ +#undef ASM_OUTPUT_CONSTRUCTOR +#undef ASM_OUTPUT_DESTRUCTOR + +#undef ASM_FILE_END +#define ASM_FILE_END(FILE) \ + do { \ + extern char *language_string; \ + if (strcmp (language_string, "GNU C++") == 0) \ + { \ + ASM_OUTPUT_ALIGN (FILE, 1); \ + } \ + } while (0) +/* deleted: destructor_section (); \ */ +/* deleted: constructor_section (); \ */ + +/* Ensure correct alignment of bss data. */ +/* ASM_OUTPUT_ALIGNED_LOCAL not needed */ +/* need ASM_OUTPUT_LOCAL instead for old NeXT-as */ +/* look in varasm.c, line 1062 and 1476 */ +#undef ASM_OUTPUT_ALIGNED_LOCAL +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".lcomm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (ROUNDED))) + diff --git a/contrib/gcc/config/svr3.h b/contrib/gcc/config/svr3.h new file mode 100644 index 00000000000..fc6e262b7b5 --- /dev/null +++ b/contrib/gcc/config/svr3.h @@ -0,0 +1,385 @@ +/* svr3.h -- operating system specific defines to be used when + targeting GCC for some generic System V Release 3 system. + Copyright (C) 1991 Free Software Foundation, Inc. + + Written by Ron Guilmette (rfg@netcom.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + To use this file, make up a file with a name like: + + ?????svr3.h + + where ????? is replaced by the name of the basic hardware that you + are targeting for. Then, in the file ?????svr3.h, put something + like: + + #include "?????.h" + #include "svr3.h" + + followed by any really system-specific defines (or overrides of + defines) which you find that you need. For example, CPP_PREDEFINES + is defined here with only the defined -Dunix and -DSVR3. You should + probably override that in your target-specific ?????svr3.h file + with a set of defines that includes these, but also contains an + appropriate define for the type of hardware that you are targeting. +*/ + +/* Define a symbol indicating that we are using svr3.h. */ +#define USING_SVR3_H + +/* Define a symbol so that libgcc* can know what sort of operating + environment and assembler syntax we are targeting for. */ +#define SVR3_target + +/* Cpp, assembler, linker, library, and startfile spec's. */ + +/* You should redefine CPP_PREDEFINES in any file which includes this one. + The definition should be appropriate for the type of target system + involved, and it should include any -A (assertion) options which are + appropriate for the given target system. */ + +#undef CPP_PREDEFINES + +/* Output at beginning of assembler file. */ +/* The .file command should always begin the output. */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + do { output_file_directive ((FILE), main_input_filename); \ + if (optimize) ASM_FILE_START_1 (FILE); \ + } while (0) + +/* By default, do nothing: a few machines support .optim, but not most. */ +#undef ASM_FILE_START_1 +#define ASM_FILE_START_1(FILE) + +/* This says how to output an assembler line + to define a global common symbol. */ +/* We don't use ROUNDED because the standard compiler doesn't, + and the linker gives error messages if a common symbol + has more than one length value. */ + +#undef ASM_OUTPUT_COMMON +#define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED) \ +( fputs (".comm ", (FILE)), \ + assemble_name ((FILE), (NAME)), \ + fprintf ((FILE), ",%u\n", (SIZE))) + +/* This says how to output an assembler line + to define a local common symbol. */ + +/* Note that using bss_section here caused errors + in building shared libraries on system V.3. */ +#undef ASM_OUTPUT_LOCAL +#define ASM_OUTPUT_LOCAL(FILE, NAME, SIZE, ROUNDED) \ + do { \ + int align = exact_log2 (ROUNDED); \ + if (align > 2) align = 2; \ + data_section (); \ + ASM_OUTPUT_ALIGN ((FILE), align == -1 ? 2 : align); \ + ASM_OUTPUT_LABEL ((FILE), (NAME)); \ + fprintf ((FILE), "\t.set .,.+%u\n", (ROUNDED)); \ + } while (0) + +#if 0 /* For now, let's leave these machine-specific. */ +/* Use crt1.o as a startup file and crtn.o as a closing file. */ + +#define STARTFILE_SPEC \ + "%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}" + +#define LIB_SPEC "%{p:-L/usr/lib/libp}%{pg:-L/usr/lib/libp} -lc crtn.o%s" + +/* Special flags for the linker. I don't know what they do. */ + +#define LINK_SPEC "%{T*} %{z:-lm}" +#endif + +/* Allow #sccs in preprocessor. */ + +#define SCCS_DIRECTIVE + +/* Output #ident as a .ident. */ + +#define ASM_OUTPUT_IDENT(FILE, NAME) \ + fprintf (FILE, "\t.ident \"%s\"\n", NAME); + +/* Use periods rather than dollar signs in special g++ assembler names. */ + +#define NO_DOLLAR_IN_LABEL + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +/* System V Release 3 uses COFF debugging info. */ + +#define SDB_DEBUGGING_INFO + +/* We don't want to output DBX debugging information. */ + +#undef DBX_DEBUGGING_INFO + +/* Define the actual types of some ANSI-mandated types. These + definitions should work for most SVR3 systems. */ + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* Assembler pseudos to introduce constants of various size. These + definitions should work for most svr3 systems. */ + +#undef ASM_BYTE_OP +#define ASM_BYTE_OP "\t.byte" + +/* This is how to output a reference to a user-level label named NAME. + `assemble_name' uses this. + + For System V Release 3 the convention is to prepend a leading + underscore onto user-level symbol names. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) fprintf (FILE, "_%s", NAME) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + + For most svr3 systems, the convention is that any symbol which begins + with a period is not put into the linker symbol table by the assembler. */ + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \ + asm_fprintf (FILE, "%0L%s%d:\n", PREFIX, NUM) + +/* This is how to store into the string LABEL + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. + + For most svr3 systems, the convention is that any symbol which begins + with a period is not put into the linker symbol table by the assembler. */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \ + sprintf (LABEL, "*%s%s%d", LOCAL_LABEL_PREFIX, PREFIX, NUM) + +/* We want local labels to start with period if made with asm_fprintf. */ +#undef LOCAL_LABEL_PREFIX +#define LOCAL_LABEL_PREFIX "." + +/* Support const sections and the ctors and dtors sections for g++. + Note that there appears to be two different ways to support const + sections at the moment. You can either #define the symbol + READONLY_DATA_SECTION (giving it some code which switches to the + readonly data section) or else you can #define the symbols + EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and + SELECT_RTX_SECTION. We do both here just to be on the safe side. + However, use of the const section is turned off by default + unless the specific tm.h file turns it on by defining + USE_CONST_SECTION as 1. */ + +/* Define a few machine-specific details of the implementation of + constructors. + + The __CTORS_LIST__ goes in the .init section. Define CTOR_LIST_BEGIN + and CTOR_LIST_END to contribute to the .init section an instruction to + push a word containing 0 (or some equivalent of that). + + Define ASM_OUTPUT_CONSTRUCTOR to push the address of the constructor. */ + +#define USE_CONST_SECTION 0 + +#define INIT_SECTION_ASM_OP ".section\t.init" +#define FINI_SECTION_ASM_OP ".section .fini,\"x\"" +#define CONST_SECTION_ASM_OP ".section\t.rodata, \"x\"" +#define CTORS_SECTION_ASM_OP INIT_SECTION_ASM_OP +#define DTORS_SECTION_ASM_OP FINI_SECTION_ASM_OP + +/* CTOR_LIST_BEGIN and CTOR_LIST_END are machine-dependent + because they push on the stack. */ + +#ifndef STACK_GROWS_DOWNWARD + +/* Constructor list on stack is in reverse order. Go to the end of the + list and go backwards to call constructors in the right order. */ +#define DO_GLOBAL_CTORS_BODY \ +do { \ + func_ptr *p, *beg = alloca (0); \ + for (p = beg; *p; p++) \ + ; \ + while (p != beg) \ + (*--p) (); \ +} while (0) + +#else + +/* Constructor list on stack is in correct order. Just call them. */ +#define DO_GLOBAL_CTORS_BODY \ +do { \ + func_ptr *p, *beg = alloca (0); \ + for (p = beg; *p; ) \ + (*p++) (); \ +} while (0) + +#endif /* STACK_GROWS_DOWNWARD */ + +/* Add extra sections .init and .fini, in addition to .bss from att386.h. */ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_const, in_bss, in_init, in_fini + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CONST_SECTION_FUNCTION \ + BSS_SECTION_FUNCTION \ + INIT_SECTION_FUNCTION \ + FINI_SECTION_FUNCTION + +#define BSS_SECTION_FUNCTION \ +void \ +bss_section () \ +{ \ + if (in_section != in_bss) \ + { \ + fprintf (asm_out_file, "\t%s\n", BSS_SECTION_ASM_OP); \ + in_section = in_bss; \ + } \ +} + +#define INIT_SECTION_FUNCTION \ +void \ +init_section () \ +{ \ + if (in_section != in_init) \ + { \ + fprintf (asm_out_file, "\t%s\n", INIT_SECTION_ASM_OP); \ + in_section = in_init; \ + } \ +} + +#define FINI_SECTION_FUNCTION \ +void \ +fini_section () \ +{ \ + if (in_section != in_fini) \ + { \ + fprintf (asm_out_file, "\t%s\n", FINI_SECTION_ASM_OP); \ + in_section = in_fini; \ + } \ +} + +#define READONLY_DATA_SECTION() const_section () + +#define CONST_SECTION_FUNCTION \ +void \ +const_section () \ +{ \ + extern void text_section(); \ + if (!USE_CONST_SECTION) \ + text_section(); \ + else if (in_section != in_const) \ + { \ + fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP); \ + in_section = in_const; \ + } \ +} + +/* The ctors and dtors sections are not normally put into use + by EXTRA_SECTIONS and EXTRA_SECTION_FUNCTIONS as defined in svr3.h, + but it can't hurt to define these macros for whatever systems use them. */ +#define CTORS_SECTION_FUNCTION \ +void \ +ctors_section () \ +{ \ + if (in_section != in_ctors) \ + { \ + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \ + in_section = in_ctors; \ + } \ +} + +#define DTORS_SECTION_FUNCTION \ +void \ +dtors_section () \ +{ \ + if (in_section != in_dtors) \ + { \ + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \ + in_section = in_dtors; \ + } \ +} + +/* This is machine-dependent + because it needs to push something on the stack. */ +#undef ASM_OUTPUT_CONSTRUCTOR + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + fini_section (); \ + fprintf (FILE, "%s\t ", ASM_LONG); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement or statements to switch to the appropriate + section for output of DECL. DECL is either a `VAR_DECL' node + or a constant of some sort. RELOC indicates whether forming + the initial value of DECL requires link-time relocations. */ + +#define SELECT_SECTION(DECL,RELOC) \ +{ \ + if (TREE_CODE (DECL) == STRING_CST) \ + { \ + if (! flag_writable_strings) \ + const_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (DECL) == VAR_DECL) \ + { \ + if ((0 && RELOC) /* should be (flag_pic && RELOC) */ \ + || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \ + || !DECL_INITIAL (DECL) \ + || (DECL_INITIAL (DECL) != error_mark_node \ + && !TREE_CONSTANT (DECL_INITIAL (DECL)))) \ + data_section (); \ + else \ + const_section (); \ + } \ + else \ + const_section (); \ +} + +/* A C statement or statements to switch to the appropriate + section for output of RTX in mode MODE. RTX is some kind + of constant in RTL. The argument MODE is redundant except + in the case of a `const_int' rtx. Currently, these always + go into the const section. */ + +#define SELECT_RTX_SECTION(MODE,RTX) const_section() diff --git a/contrib/gcc/config/svr4.h b/contrib/gcc/config/svr4.h new file mode 100644 index 00000000000..bc80297359d --- /dev/null +++ b/contrib/gcc/config/svr4.h @@ -0,0 +1,887 @@ +/* Operating system specific defines to be used when targeting GCC for some + generic System V Release 4 system. + Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. + Contributed by Ron Guilmette (rfg@segfault.us.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + To use this file, make up a file with a name like: + + ?????svr4.h + + where ????? is replaced by the name of the basic hardware that you + are targeting for. Then, in the file ?????svr4.h, put something + like: + + #include "?????.h" + #include "svr4.h" + + followed by any really system-specific defines (or overrides of + defines) which you find that you need. For example, CPP_PREDEFINES + is defined here with only the defined -Dunix and -DSVR4. You should + probably override that in your target-specific ?????svr4.h file + with a set of defines that includes these, but also contains an + appropriate define for the type of hardware that you are targeting. +*/ + +/* Define a symbol indicating that we are using svr4.h. */ +#define USING_SVR4_H + +/* For the sake of libgcc2.c, indicate target supports atexit. */ +#define HAVE_ATEXIT + +/* Cpp, assembler, linker, library, and startfile spec's. */ + +/* This defines which switch letters take arguments. On svr4, most of + the normal cases (defined in gcc.c) apply, and we also have -h* and + -z* options (for the linker). Note however that there is no such + thing as a -T option for svr4. */ + +#define SWITCH_TAKES_ARG(CHAR) \ + ( (CHAR) == 'D' \ + || (CHAR) == 'U' \ + || (CHAR) == 'o' \ + || (CHAR) == 'e' \ + || (CHAR) == 'u' \ + || (CHAR) == 'I' \ + || (CHAR) == 'm' \ + || (CHAR) == 'L' \ + || (CHAR) == 'A' \ + || (CHAR) == 'h' \ + || (CHAR) == 'z') + +/* This defines which multi-letter switches take arguments. On svr4, + there are no such switches except those implemented by GCC itself. */ + +#define WORD_SWITCH_TAKES_ARG(STR) \ + (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) \ + && strcmp (STR, "Tdata") && strcmp (STR, "Ttext") \ + && strcmp (STR, "Tbss")) + +/* You should redefine CPP_PREDEFINES in any file which includes this one. + The definition should be appropriate for the type of target system + involved, and it should include any -A (assertion) options which are + appropriate for the given target system. */ +#undef CPP_PREDEFINES + +/* Provide an ASM_SPEC appropriate for svr4. Here we try to support as + many of the specialized svr4 assembler options as seems reasonable, + given that there are certain options which we can't (or shouldn't) + support directly due to the fact that they conflict with other options + for other svr4 tools (e.g. ld) or with other options for GCC itself. + For example, we don't support the -o (output file) or -R (remove + input file) options because GCC already handles these things. We + also don't support the -m (run m4) option for the assembler because + that conflicts with the -m (produce load map) option of the svr4 + linker. We do however allow passing arbitrary options to the svr4 + assembler via the -Wa, option. + + Note that gcc doesn't allow a space to follow -Y in a -Ym,* or -Yd,* + option. +*/ + +#undef ASM_SPEC +#define ASM_SPEC \ + "%{V} %{v:%{!V:-V}} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}" + +/* svr4 assemblers need the `-' (indicating input from stdin) to come after + the -o option (and its argument) for some reason. If we try to put it + before the -o option, the assembler will try to read the file named as + the output file in the -o option as an input file (after it has already + written some stuff to it) and the binary stuff contained therein will + cause totally confuse the assembler, resulting in many spurious error + messages. */ + +#undef ASM_FINAL_SPEC +#define ASM_FINAL_SPEC "%{pipe:-}" + +/* Under svr4, the normal location of the `ld' and `as' programs is the + /usr/ccs/bin directory. */ + +#undef MD_EXEC_PREFIX +#define MD_EXEC_PREFIX "/usr/ccs/bin/" + +/* Under svr4, the normal location of the various *crt*.o files is the + /usr/ccs/lib directory. */ + +#undef MD_STARTFILE_PREFIX +#define MD_STARTFILE_PREFIX "/usr/ccs/lib/" + +/* Provide a LIB_SPEC appropriate for svr4. Here we tack on the default + standard C library (unless we are building a shared library). */ + +#undef LIB_SPEC +#define LIB_SPEC "%{!shared:%{!symbolic:-lc}}" + +/* Provide a LIBGCC_SPEC appropriate for svr4. We also want to exclude + libgcc when -symbolic. */ + +#undef LIBGCC_SPEC +#define LIBGCC_SPEC "%{!shared:%{!symbolic:-lgcc}}" + +/* Provide an ENDFILE_SPEC appropriate for svr4. Here we tack on our own + magical crtend.o file (see crtstuff.c) which provides part of the + support for getting C++ file-scope static object constructed before + entering `main', followed by the normal svr3/svr4 "finalizer" file, + which is either `gcrtn.o' or `crtn.o'. */ + +#undef ENDFILE_SPEC +#define ENDFILE_SPEC "crtend.o%s %{pg:gcrtn.o}%{!pg:crtn.o%s}" + +/* Provide a LINK_SPEC appropriate for svr4. Here we provide support + for the special GCC options -static, -shared, and -symbolic which + allow us to link things in one of these three modes by applying the + appropriate combinations of options at link-time. We also provide + support here for as many of the other svr4 linker options as seems + reasonable, given that some of them conflict with options for other + svr4 tools (e.g. the assembler). In particular, we do support the + -h*, -z*, -V, -b, -t, -Qy, -Qn, and -YP* options here, and the -e*, + -l*, -o*, -r, -s, -u*, and -L* options are directly supported + by gcc.c itself. We don't directly support the -m (generate load + map) option because that conflicts with the -m (run m4) option of + the svr4 assembler. We also don't directly support the svr4 linker's + -I* or -M* options because these conflict with existing GCC options. + We do however allow passing arbitrary options to the svr4 linker + via the -Wl, option. We don't support the svr4 linker's -a option + at all because it is totally useless and because it conflicts with + GCC's own -a option. + + Note that gcc doesn't allow a space to follow -Y in a -YP,* option. + + When the -G link option is used (-shared and -symbolic) a final link is + not being done. */ + +#undef LINK_SPEC +#define LINK_SPEC "%{h*} %{V} %{v:%{!V:-V}} \ + %{b} %{Wl,*:%*} \ + %{static:-dn -Bstatic} \ + %{shared:-G -dy -z text %{!h*:%{o*:-h %*}}} \ + %{symbolic:-Bsymbolic -G -dy -z text %{!h*:%{o*:-h %*}}} \ + %{G:-G} \ + %{YP,*} \ + %{!YP,*:%{p:-Y P,/usr/ccs/lib/libp:/usr/lib/libp:/usr/ccs/lib:/usr/lib} \ + %{!p:-Y P,/usr/ccs/lib:/usr/lib}} \ + %{Qy:} %{!Qn:-Qy}" + +/* Gcc automatically adds in one of the files /usr/ccs/lib/values-Xc.o, + /usr/ccs/lib/values-Xa.o, or /usr/ccs/lib/values-Xt.o for each final + link step (depending upon the other gcc options selected, such as + -traditional and -ansi). These files each contain one (initialized) + copy of a special variable called `_lib_version'. Each one of these + files has `_lib_version' initialized to a different (enum) value. + The SVR4 library routines query the value of `_lib_version' at run + to decide how they should behave. Specifically, they decide (based + upon the value of `_lib_version') if they will act in a strictly ANSI + conforming manner or not. +*/ + +#undef STARTFILE_SPEC +#define STARTFILE_SPEC "%{!shared: \ + %{!symbolic: \ + %{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s}%{!p:crt1.o%s}}}}\ + %{pg:gcrti.o%s}%{!pg:crti.o%s} \ + %{ansi:values-Xc.o%s} \ + %{!ansi: \ + %{traditional:values-Xt.o%s} \ + %{!traditional:values-Xa.o%s}} \ + crtbegin.o%s" + +/* Attach a special .ident directive to the end of the file to identify + the version of GCC which compiled this code. The format of the + .ident string is patterned after the ones produced by native svr4 + C compilers. */ + +#define IDENT_ASM_OP ".ident" + +#define ASM_FILE_END(FILE) \ +do { \ + fprintf ((FILE), "\t%s\t\"GCC: (GNU) %s\"\n", \ + IDENT_ASM_OP, version_string); \ + } while (0) + +/* Allow #sccs in preprocessor. */ + +#define SCCS_DIRECTIVE + +/* Output #ident as a .ident. */ + +#define ASM_OUTPUT_IDENT(FILE, NAME) \ + fprintf (FILE, "\t%s\t\"%s\"\n", IDENT_ASM_OP, NAME); + +/* Use periods rather than dollar signs in special g++ assembler names. */ + +#define NO_DOLLAR_IN_LABEL + +/* Writing `int' for a bitfield forces int alignment for the structure. */ + +#define PCC_BITFIELD_TYPE_MATTERS 1 + +/* Implicit library calls should use memcpy, not bcopy, etc. */ + +#define TARGET_MEM_FUNCTIONS + +/* Handle #pragma weak and #pragma pack. */ + +#define HANDLE_SYSV_PRAGMA + +/* System V Release 4 uses DWARF debugging info. */ + +#define DWARF_DEBUGGING_INFO + +/* The numbers used to denote specific machine registers in the System V + Release 4 DWARF debugging information are quite likely to be totally + different from the numbers used in BSD stabs debugging information + for the same kind of target machine. Thus, we undefine the macro + DBX_REGISTER_NUMBER here as an extra inducement to get people to + provide proper machine-specific definitions of DBX_REGISTER_NUMBER + (which is also used to provide DWARF registers numbers in dwarfout.c) + in their tm.h files which include this file. */ + +#undef DBX_REGISTER_NUMBER + +/* gas on SVR4 supports the use of .stabs. Permit -gstabs to be used + in general, although it will only work when using gas. */ + +#define DBX_DEBUGGING_INFO + +/* Use DWARF debugging info by default. */ + +#ifndef PREFERRED_DEBUGGING_TYPE +#define PREFERRED_DEBUGGING_TYPE DWARF_DEBUG +#endif + +/* Make LBRAC and RBRAC addresses relative to the start of the + function. The native Solaris stabs debugging format works this + way, gdb expects it, and it reduces the number of relocation + entries. */ + +#define DBX_BLOCKS_FUNCTION_RELATIVE 1 + +/* When using stabs, gcc2_compiled must be a stabs entry, not an + ordinary symbol, or gdb won't see it. The stabs entry must be + before the N_SO in order for gdb to find it. */ + +#define ASM_IDENTIFY_GCC(FILE) \ +do \ + { \ + if (write_symbols != DBX_DEBUG) \ + fputs ("gcc2_compiled.:\n", FILE); \ + else \ + fputs ("\t.stabs\t\"gcc2_compiled.\", 0x3c, 0, 0, 0\n", FILE); \ + } \ +while (0) + +/* Like block addresses, stabs line numbers are relative to the + current function. */ + +#define ASM_OUTPUT_SOURCE_LINE(file, line) \ +do \ + { \ + static int sym_lineno = 1; \ + fprintf (file, ".stabn 68,0,%d,.LM%d-", \ + line, sym_lineno); \ + assemble_name (file, \ + XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));\ + fprintf (file, "\n.LM%d:\n", sym_lineno); \ + sym_lineno += 1; \ + } \ +while (0) + +/* In order for relative line numbers to work, we must output the + stabs entry for the function name first. */ + +#define DBX_FUNCTION_FIRST + +/* Generate a blank trailing N_SO to mark the end of the .o file, since + we can't depend upon the linker to mark .o file boundaries with + embedded stabs. */ + +#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \ + fprintf (FILE, \ + "\t.text\n\t.stabs \"\",%d,0,0,.Letext\n.Letext:\n", N_SO) + +/* Define the actual types of some ANSI-mandated types. (These + definitions should work for most SVR4 systems). */ + +#undef SIZE_TYPE +#define SIZE_TYPE "unsigned int" + +#undef PTRDIFF_TYPE +#define PTRDIFF_TYPE "int" + +#undef WCHAR_TYPE +#define WCHAR_TYPE "long int" + +#undef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE BITS_PER_WORD + +/* This causes trouble, because it requires the host machine + to support ANSI C. */ +/* #define MULTIBYTE_CHARS */ + +#undef ASM_BYTE_OP +#define ASM_BYTE_OP ".byte" + +#undef SET_ASM_OP +#define SET_ASM_OP ".set" + +/* This is how to begin an assembly language file. Most svr4 assemblers want + at least a .file directive to come first, and some want to see a .version + directive come right after that. Here we just establish a default + which generates only the .file directive. If you need a .version + directive for any specific target, you should override this definition + in the target-specific file which includes this one. */ + +#undef ASM_FILE_START +#define ASM_FILE_START(FILE) \ + output_file_directive ((FILE), main_input_filename) + +/* This is how to allocate empty space in some section. The .zero + pseudo-op is used for this on most svr4 assemblers. */ + +#define SKIP_ASM_OP ".zero" + +#undef ASM_OUTPUT_SKIP +#define ASM_OUTPUT_SKIP(FILE,SIZE) \ + fprintf (FILE, "\t%s\t%u\n", SKIP_ASM_OP, (SIZE)) + +/* This is how to output a reference to a user-level label named NAME. + `assemble_name' uses this. + + For System V Release 4 the convention is *not* to prepend a leading + underscore onto user-level symbol names. */ + +#undef ASM_OUTPUT_LABELREF +#define ASM_OUTPUT_LABELREF(FILE,NAME) fprintf (FILE, "%s", NAME) + +/* This is how to output an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + + For most svr4 systems, the convention is that any symbol which begins + with a period is not put into the linker symbol table by the assembler. */ + +#undef ASM_OUTPUT_INTERNAL_LABEL +#define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM) \ +do { \ + fprintf (FILE, ".%s%d:\n", PREFIX, NUM); \ +} while (0) + +/* This is how to store into the string LABEL + the symbol_ref name of an internal numbered label where + PREFIX is the class of label and NUM is the number within the class. + This is suitable for output with `assemble_name'. + + For most svr4 systems, the convention is that any symbol which begins + with a period is not put into the linker symbol table by the assembler. */ + +#undef ASM_GENERATE_INTERNAL_LABEL +#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \ +do { \ + sprintf (LABEL, "*.%s%d", PREFIX, NUM); \ +} while (0) + +/* Output the label which precedes a jumptable. Note that for all svr4 + systems where we actually generate jumptables (which is to say every + svr4 target except i386, where we use casesi instead) we put the jump- + tables into the .rodata section and since other stuff could have been + put into the .rodata section prior to any given jumptable, we have to + make sure that the location counter for the .rodata section gets pro- + perly re-aligned prior to the actual beginning of the jump table. */ + +#define ALIGN_ASM_OP ".align" + +#ifndef ASM_OUTPUT_BEFORE_CASE_LABEL +#define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE,PREFIX,NUM,TABLE) \ + ASM_OUTPUT_ALIGN ((FILE), 2); +#endif + +#undef ASM_OUTPUT_CASE_LABEL +#define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,JUMPTABLE) \ + do { \ + ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM); \ + } while (0) + +/* The standard SVR4 assembler seems to require that certain builtin + library routines (e.g. .udiv) be explicitly declared as .globl + in each assembly file where they are referenced. */ + +#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \ + ASM_GLOBALIZE_LABEL (FILE, XSTR (FUN, 0)) + +/* This says how to output assembler code to declare an + uninitialized external linkage data object. Under SVR4, + the linker seems to want the alignment of data objects + to depend on their types. We do exactly that here. */ + +#define COMMON_ASM_OP ".comm" + +#undef ASM_OUTPUT_ALIGNED_COMMON +#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \ +do { \ + fprintf ((FILE), "\t%s\t", COMMON_ASM_OP); \ + assemble_name ((FILE), (NAME)); \ + fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \ +} while (0) + +/* This says how to output assembler code to declare an + uninitialized internal linkage data object. Under SVR4, + the linker seems to want the alignment of data objects + to depend on their types. We do exactly that here. */ + +#define LOCAL_ASM_OP ".local" + +#undef ASM_OUTPUT_ALIGNED_LOCAL +#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \ +do { \ + fprintf ((FILE), "\t%s\t", LOCAL_ASM_OP); \ + assemble_name ((FILE), (NAME)); \ + fprintf ((FILE), "\n"); \ + ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \ +} while (0) + +/* This is the pseudo-op used to generate a 32-bit word of data with a + specific value in some section. This is the same for all known svr4 + assemblers. */ + +#define INT_ASM_OP ".long" + +/* This is the pseudo-op used to generate a contiguous sequence of byte + values from a double-quoted string WITHOUT HAVING A TERMINATING NUL + AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */ + +#undef ASCII_DATA_ASM_OP +#define ASCII_DATA_ASM_OP ".ascii" + +/* Support const sections and the ctors and dtors sections for g++. + Note that there appears to be two different ways to support const + sections at the moment. You can either #define the symbol + READONLY_DATA_SECTION (giving it some code which switches to the + readonly data section) or else you can #define the symbols + EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and + SELECT_RTX_SECTION. We do both here just to be on the safe side. */ + +#define USE_CONST_SECTION 1 + +#define CONST_SECTION_ASM_OP ".section\t.rodata" + +/* Define the pseudo-ops used to switch to the .ctors and .dtors sections. + + Note that we want to give these sections the SHF_WRITE attribute + because these sections will actually contain data (i.e. tables of + addresses of functions in the current root executable or shared library + file) and, in the case of a shared library, the relocatable addresses + will have to be properly resolved/relocated (and then written into) by + the dynamic linker when it actually attaches the given shared library + to the executing process. (Note that on SVR4, you may wish to use the + `-z text' option to the ELF linker, when building a shared library, as + an additional check that you are doing everything right. But if you do + use the `-z text' option when building a shared library, you will get + errors unless the .ctors and .dtors sections are marked as writable + via the SHF_WRITE attribute.) */ + +#define CTORS_SECTION_ASM_OP ".section\t.ctors,\"aw\"" +#define DTORS_SECTION_ASM_OP ".section\t.dtors,\"aw\"" + +/* On svr4, we *do* have support for the .init and .fini sections, and we + can put stuff in there to be executed before and after `main'. We let + crtstuff.c and other files know this by defining the following symbols. + The definitions say how to change sections to the .init and .fini + sections. This is the same for all known svr4 assemblers. */ + +#define INIT_SECTION_ASM_OP ".section\t.init" +#define FINI_SECTION_ASM_OP ".section\t.fini" + +/* A default list of other sections which we might be "in" at any given + time. For targets that use additional sections (e.g. .tdesc) you + should override this definition in the target-specific file which + includes this file. */ + +#undef EXTRA_SECTIONS +#define EXTRA_SECTIONS in_const, in_ctors, in_dtors + +/* A default list of extra section function definitions. For targets + that use additional sections (e.g. .tdesc) you should override this + definition in the target-specific file which includes this file. */ + +#undef EXTRA_SECTION_FUNCTIONS +#define EXTRA_SECTION_FUNCTIONS \ + CONST_SECTION_FUNCTION \ + CTORS_SECTION_FUNCTION \ + DTORS_SECTION_FUNCTION + +#define READONLY_DATA_SECTION() const_section () + +extern void text_section (); + +#define CONST_SECTION_FUNCTION \ +void \ +const_section () \ +{ \ + if (!USE_CONST_SECTION) \ + text_section(); \ + else if (in_section != in_const) \ + { \ + fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP); \ + in_section = in_const; \ + } \ +} + +#define CTORS_SECTION_FUNCTION \ +void \ +ctors_section () \ +{ \ + if (in_section != in_ctors) \ + { \ + fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP); \ + in_section = in_ctors; \ + } \ +} + +#define DTORS_SECTION_FUNCTION \ +void \ +dtors_section () \ +{ \ + if (in_section != in_dtors) \ + { \ + fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP); \ + in_section = in_dtors; \ + } \ +} + +/* Switch into a generic section. + This is currently only used to support section attributes. + + We make the section read-only and executable for a function decl, + read-only for a const data decl, and writable for a non-const data decl. */ +#define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \ + fprintf (FILE, ".section\t%s,\"%s\",@progbits\n", NAME, \ + (DECL) && TREE_CODE (DECL) == FUNCTION_DECL ? "ax" : \ + (DECL) && TREE_READONLY (DECL) ? "a" : "aw") + + +/* A C statement (sans semicolon) to output an element in the table of + global constructors. */ +#define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \ + do { \ + ctors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement (sans semicolon) to output an element in the table of + global destructors. */ +#define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \ + do { \ + dtors_section (); \ + fprintf (FILE, "\t%s\t ", INT_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, "\n"); \ + } while (0) + +/* A C statement or statements to switch to the appropriate + section for output of DECL. DECL is either a `VAR_DECL' node + or a constant of some sort. RELOC indicates whether forming + the initial value of DECL requires link-time relocations. */ + +#define SELECT_SECTION(DECL,RELOC) \ +{ \ + if (TREE_CODE (DECL) == STRING_CST) \ + { \ + if (! flag_writable_strings) \ + const_section (); \ + else \ + data_section (); \ + } \ + else if (TREE_CODE (DECL) == VAR_DECL) \ + { \ + if ((flag_pic && RELOC) \ + || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL) \ + || !DECL_INITIAL (DECL) \ + || (DECL_INITIAL (DECL) != error_mark_node \ + && !TREE_CONSTANT (DECL_INITIAL (DECL)))) \ + data_section (); \ + else \ + const_section (); \ + } \ + else \ + const_section (); \ +} + +/* A C statement or statements to switch to the appropriate + section for output of RTX in mode MODE. RTX is some kind + of constant in RTL. The argument MODE is redundant except + in the case of a `const_int' rtx. Currently, these always + go into the const section. */ + +#undef SELECT_RTX_SECTION +#define SELECT_RTX_SECTION(MODE,RTX) const_section() + +/* Define the strings used for the special svr4 .type and .size directives. + These strings generally do not vary from one system running svr4 to + another, but if a given system (e.g. m88k running svr) needs to use + different pseudo-op names for these, they may be overridden in the + file which includes this one. */ + +#define TYPE_ASM_OP ".type" +#define SIZE_ASM_OP ".size" + +/* This is how we tell the assembler that a symbol is weak. */ + +#define ASM_WEAKEN_LABEL(FILE,NAME) \ + do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \ + fputc ('\n', FILE); } while (0) + +/* The following macro defines the format used to output the second + operand of the .type assembler directive. Different svr4 assemblers + expect various different forms for this operand. The one given here + is just a default. You may need to override it in your machine- + specific tm.h file (depending upon the particulars of your assembler). */ + +#define TYPE_OPERAND_FMT "@%s" + +/* Write the extra assembler code needed to declare a function's result. + Most svr4 assemblers don't require any special declaration of the + result value, but there are exceptions. */ + +#ifndef ASM_DECLARE_RESULT +#define ASM_DECLARE_RESULT(FILE, RESULT) +#endif + +/* These macros generate the special .type and .size directives which + are used to set the corresponding fields of the linker symbol table + entries in an ELF object file under SVR4. These macros also output + the starting labels for the relevant functions/objects. */ + +/* Write the extra assembler code needed to declare a function properly. + Some svr4 assemblers need to also have something extra said about the + function's return value. We allow for that here. */ + +#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "function"); \ + putc ('\n', FILE); \ + ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Write the extra assembler code needed to declare an object properly. */ + +#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ + do { \ + fprintf (FILE, "\t%s\t ", TYPE_ASM_OP); \ + assemble_name (FILE, NAME); \ + putc (',', FILE); \ + fprintf (FILE, TYPE_OPERAND_FMT, "object"); \ + putc ('\n', FILE); \ + size_directive_output = 0; \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL)) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, NAME); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + ASM_OUTPUT_LABEL(FILE, NAME); \ + } while (0) + +/* Output the size directive for a decl in rest_of_decl_compilation + in the case where we did not do so before the initializer. + Once we find the error_mark_node, we know that the value of + size_directive_output was set + by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ + +#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END) \ +do { \ + char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ + if (!flag_inhibit_size_directive && DECL_SIZE (DECL) \ + && ! AT_END && TOP_LEVEL \ + && DECL_INITIAL (DECL) == error_mark_node \ + && !size_directive_output) \ + { \ + size_directive_output = 1; \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, name); \ + fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL))); \ + } \ + } while (0) + +/* This is how to declare the size of a function. */ + +#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ + do { \ + if (!flag_inhibit_size_directive) \ + { \ + char label[256]; \ + static int labelno; \ + labelno++; \ + ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno); \ + fprintf (FILE, "\t%s\t ", SIZE_ASM_OP); \ + assemble_name (FILE, (FNAME)); \ + fprintf (FILE, ","); \ + assemble_name (FILE, label); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, (FNAME)); \ + putc ('\n', FILE); \ + } \ + } while (0) + +/* A table of bytes codes used by the ASM_OUTPUT_ASCII and + ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table + corresponds to a particular byte value [0..255]. For any + given byte value, if the value in the corresponding table + position is zero, the given character can be output directly. + If the table value is 1, the byte must be output as a \ooo + octal escape. If the tables value is anything else, then the + byte value should be output as a \ followed by the value + in the table. Note that we can use standard UN*X escape + sequences for many control characters, but we don't use + \a to represent BEL because some svr4 assemblers (e.g. on + the i386) don't know about that. Also, we don't use \v + since some versions of gas, such as 2.2 did not accept it. */ + +#define ESCAPES \ +"\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ +\0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ +\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\ +\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\ +\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ +\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ +\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ +\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1" + +/* Some svr4 assemblers have a limit on the number of characters which + can appear in the operand of a .string directive. If your assembler + has such a limitation, you should define STRING_LIMIT to reflect that + limit. Note that at least some svr4 assemblers have a limit on the + actual number of bytes in the double-quoted string, and that they + count each character in an escape sequence as one byte. Thus, an + escape sequence like \377 would count as four bytes. + + If your target assembler doesn't support the .string directive, you + should define this to zero. +*/ + +#define STRING_LIMIT ((unsigned) 256) + +#define STRING_ASM_OP ".string" + +/* The routine used to output NUL terminated strings. We use a special + version of this for most svr4 targets because doing so makes the + generated assembly code more compact (and thus faster to assemble) + as well as more readable, especially for targets like the i386 + (where the only alternative is to output character sequences as + comma separated lists of numbers). */ + +#define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \ + do \ + { \ + register unsigned char *_limited_str = (unsigned char *) (STR); \ + register unsigned ch; \ + fprintf ((FILE), "\t%s\t\"", STRING_ASM_OP); \ + for (; ch = *_limited_str; _limited_str++) \ + { \ + register int escape; \ + switch (escape = ESCAPES[ch]) \ + { \ + case 0: \ + putc (ch, (FILE)); \ + break; \ + case 1: \ + fprintf ((FILE), "\\%03o", ch); \ + break; \ + default: \ + putc ('\\', (FILE)); \ + putc (escape, (FILE)); \ + break; \ + } \ + } \ + fprintf ((FILE), "\"\n"); \ + } \ + while (0) + +/* The routine used to output sequences of byte values. We use a special + version of this for most svr4 targets because doing so makes the + generated assembly code more compact (and thus faster to assemble) + as well as more readable. Note that if we find subparts of the + character sequence which end with NUL (and which are shorter than + STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */ + +#undef ASM_OUTPUT_ASCII +#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \ + do \ + { \ + register unsigned char *_ascii_bytes = (unsigned char *) (STR); \ + register unsigned char *limit = _ascii_bytes + (LENGTH); \ + register unsigned bytes_in_chunk = 0; \ + for (; _ascii_bytes < limit; _ascii_bytes++) \ + { \ + register unsigned char *p; \ + if (bytes_in_chunk >= 60) \ + { \ + fprintf ((FILE), "\"\n"); \ + bytes_in_chunk = 0; \ + } \ + for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \ + continue; \ + if (p < limit && (p - _ascii_bytes) <= STRING_LIMIT) \ + { \ + if (bytes_in_chunk > 0) \ + { \ + fprintf ((FILE), "\"\n"); \ + bytes_in_chunk = 0; \ + } \ + ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \ + _ascii_bytes = p; \ + } \ + else \ + { \ + register int escape; \ + register unsigned ch; \ + if (bytes_in_chunk == 0) \ + fprintf ((FILE), "\t%s\t\"", ASCII_DATA_ASM_OP); \ + switch (escape = ESCAPES[ch = *_ascii_bytes]) \ + { \ + case 0: \ + putc (ch, (FILE)); \ + bytes_in_chunk++; \ + break; \ + case 1: \ + fprintf ((FILE), "\\%03o", ch); \ + bytes_in_chunk += 4; \ + break; \ + default: \ + putc ('\\', (FILE)); \ + putc (escape, (FILE)); \ + bytes_in_chunk += 2; \ + break; \ + } \ + } \ + } \ + if (bytes_in_chunk > 0) \ + fprintf ((FILE), "\"\n"); \ + } \ + while (0) + +/* All SVR4 targets use the ELF object file format. */ +#define OBJECT_FORMAT_ELF diff --git a/contrib/gcc/config/t-libc-ok b/contrib/gcc/config/t-libc-ok new file mode 100644 index 00000000000..712a4ca128d --- /dev/null +++ b/contrib/gcc/config/t-libc-ok @@ -0,0 +1,2 @@ +LIBGCC1=libgcc1.null +CROSS_LIBGCC1=libgcc1.null diff --git a/contrib/gcc/config/t-svr4 b/contrib/gcc/config/t-svr4 new file mode 100644 index 00000000000..d4abf488905 --- /dev/null +++ b/contrib/gcc/config/t-svr4 @@ -0,0 +1,7 @@ +# We need to use -fPIC when we are using gcc to compile the routines in +# crtstuff.c. This is only really needed when we are going to use gcc/g++ +# to produce a shared library, but since we don't know ahead of time when +# we will be doing that, we just always use -fPIC when compiling the +# routines in crtstuff.c. + +CRTSTUFF_T_CFLAGS = -fPIC diff --git a/contrib/gcc/config/x-linux b/contrib/gcc/config/x-linux new file mode 100644 index 00000000000..ea2a5f270b3 --- /dev/null +++ b/contrib/gcc/config/x-linux @@ -0,0 +1,14 @@ +# It is defined in config/xm-linux.h. +# X_CFLAGS = -DPOSIX + +# The following is needed when compiling stages 2 and 3 because gcc's +# limits.h must be picked up before /usr/include/limits.h. This is because +# each does an #include_next of the other if the other hasn't been included. +# /usr/include/limits.h loses if it gets found first because /usr/include is +# at the end of the search order. When a new version of gcc is released, +# gcc's limits.h hasn't been installed yet and hence isn't found. + +BOOT_CFLAGS = -O $(CFLAGS) -Iinclude + +# Don't run fixproto +STMP_FIXPROTO = diff --git a/contrib/gcc/config/x-lynx b/contrib/gcc/config/x-lynx new file mode 100644 index 00000000000..0be03e453e1 --- /dev/null +++ b/contrib/gcc/config/x-lynx @@ -0,0 +1,6 @@ +# /bin/cc is hopelessly broken, so we must use /bin/gcc instead. +CC = $(OLDCC) +OLDCC = /bin/gcc + +# /bin/sh is too buggy, so use /bin/bash instead. +SHELL = /bin/bash diff --git a/contrib/gcc/config/x-netbsd b/contrib/gcc/config/x-netbsd new file mode 100644 index 00000000000..1c272f5a8dc --- /dev/null +++ b/contrib/gcc/config/x-netbsd @@ -0,0 +1,6 @@ +# Don't run fixproto +STMP_FIXPROTO = + +# We don't need GCC's own include files. +USER_H = +INSTALL_ASSERT_H = diff --git a/contrib/gcc/config/x-svr4 b/contrib/gcc/config/x-svr4 new file mode 100644 index 00000000000..9c705434cc9 --- /dev/null +++ b/contrib/gcc/config/x-svr4 @@ -0,0 +1,9 @@ +# Some versions of SVR4 have an alloca in /usr/ucblib/libucb.a, and if we are +# careful to link that in after libc we can use it, but since newer versions of +# SVR4 are dropping libucb, it is better to just use the portable C version for +# bootstrapping. Do this by defining ALLOCA. + +ALLOCA = alloca.o + +# See all the declarations. +FIXPROTO_DEFINES = -D_XOPEN_SOURCE diff --git a/contrib/gcc/config/xm-freebsd.h b/contrib/gcc/config/xm-freebsd.h new file mode 100644 index 00000000000..f73c9aa60fa --- /dev/null +++ b/contrib/gcc/config/xm-freebsd.h @@ -0,0 +1,33 @@ +/* Configuration for GNU C-compiler for hosts running FreeBSD. + Copyright (C) 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines machine-independent things specific to a host + running FreeBSD. This file should not be specified as $xm_file itself; + instead $xm_file should be CPU/xm-freebsd.h, which should include both + CPU/xm-CPU.h and this file xm-freebsd.h. */ + +/* FreeBSD has strerror. */ +#define HAVE_STRERROR + +/* We have _sys_siglist, but the declaration in conflicts with + the declarations in collect2.c and mips-tfile.c, so disable the declarations + in those files. */ + +#define DONT_DECLARE_SYS_SIGLIST diff --git a/contrib/gcc/config/xm-gnu.h b/contrib/gcc/config/xm-gnu.h new file mode 100644 index 00000000000..57e74f23018 --- /dev/null +++ b/contrib/gcc/config/xm-gnu.h @@ -0,0 +1,31 @@ +/* Configuration for GNU C-compiler for hosts running GNU. + Copyright (C) 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines machine-independent things specific to a host + running GNU. This file should not be specified as $xm_file itself; + instead $xm_file should be CPU/xm-gnu.h, which should include both + CPU/xm-CPU.h and this file xm-gnu.h. */ + +#define HAVE_STRERROR /* GNU has strerror. */ +#define POSIX /* GNU complies to POSIX.1. */ + +/* Get a definition of O_RDONLY; some of the GCC files don't include this + properly and will define it themselves to be zero. */ +#include diff --git a/contrib/gcc/config/xm-linux.h b/contrib/gcc/config/xm-linux.h new file mode 100644 index 00000000000..5ffb0f2a56d --- /dev/null +++ b/contrib/gcc/config/xm-linux.h @@ -0,0 +1,40 @@ +/* Configuration for GCC for Intel i386 running Linux. + Copyright (C) 1995 Free Software Foundation, Inc. + Contributed by H.J. Lu (hjl@nynexst.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define HAVE_VPRINTF + +#define HAVE_STRERROR + +#define POSIX + +#define DONT_DECLARE_SYS_SIGLIST + +/* We do have one, but I'd like to use the one come with gcc since + we have been doing that for a long time with USG defined. H.J. */ +#define NO_STAB_H + +#undef BSTRING +#define BSTRING +#undef bcmp +#undef bcopy +#undef bzero +#undef index +#undef rindex diff --git a/contrib/gcc/config/xm-lynx.h b/contrib/gcc/config/xm-lynx.h new file mode 100644 index 00000000000..009f8445eab --- /dev/null +++ b/contrib/gcc/config/xm-lynx.h @@ -0,0 +1,51 @@ +/* Configuration for GNU C-compiler for Lynx. + Copyright (C) 1993, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines machine-independent things specific to a host + running Lynx. This file should not be specified as $xm_file itself; + instead $xm_file should be CPU/xm-lynx.h, which should include this one. */ + +/* #defines that need visibility everywhere. */ +#define FALSE 0 +#define TRUE 1 + +/* Arguments to use with `exit'. */ +#define SUCCESS_EXIT_CODE 0 +#define FATAL_EXIT_CODE 33 + +/* Lynx has no vfork system call. */ +#define vfork fork + +/* Lynx has a non-standard mktemp function. */ +/* ??? This is simpler than creating YATM: Yet Another Target Macro. */ +#define mktemp lynx_mktemp + +#define lynx_mktemp(template) \ +do { \ + int pid = getpid (); \ + char *t = template; \ + char *p; \ + p = t + strlen (t); \ + while (*--p == 'X') \ + { \ + *p = (pid % 10) + '0'; \ + pid /= 10; \ + } \ +} while (0) diff --git a/contrib/gcc/config/xm-netbsd.h b/contrib/gcc/config/xm-netbsd.h new file mode 100644 index 00000000000..00000ce9706 --- /dev/null +++ b/contrib/gcc/config/xm-netbsd.h @@ -0,0 +1,27 @@ +/* Configuration for GNU C-compiler for hosts running NetBSD. + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file defines machine-independent things specific to a host + running NetBSD. This file should not be specified as $xm_file itself; + instead $xm_file should be CPU/xm-netbsd.h, which should include both + CPU/xm-CPU.h and this file xm-netbsd.h. */ + +#define HAVE_STRERROR +#define HAVE_VPRINTF diff --git a/contrib/gcc/config/xm-svr3.h b/contrib/gcc/config/xm-svr3.h new file mode 100644 index 00000000000..ac1000fb1cb --- /dev/null +++ b/contrib/gcc/config/xm-svr3.h @@ -0,0 +1,33 @@ +/* Configuration for GNU C-compiler for hosts running System V Release 3 + Copyright (C) 1991, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define bcopy(src,dst,len) memcpy ((dst),(src),(len)) +#define bzero(dst,len) memset ((dst),0,(len)) +#define bcmp(left,right,len) memcmp ((left),(right),(len)) + +#define rindex strrchr +#define index strchr + +#define USG +#define HAVE_VPRINTF + +#ifndef SVR3 +#define SVR3 +#endif diff --git a/contrib/gcc/config/xm-svr4.h b/contrib/gcc/config/xm-svr4.h new file mode 100644 index 00000000000..30084322510 --- /dev/null +++ b/contrib/gcc/config/xm-svr4.h @@ -0,0 +1,35 @@ +/* Configuration for GNU C-compiler for hosts running System V Release 4 + Copyright (C) 1988 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#define bcopy(src,dst,len) memcpy ((dst),(src),(len)) +#define bzero(dst,len) memset ((dst),0,(len)) +#define bcmp(left,right,len) memcmp ((left),(right),(len)) + +#define rindex strrchr +#define index strchr + +#define USG +#define HAVE_VPRINTF + +#define POSIX + +/* SVR4 provides no sys_siglist, + but does offer the same data under another name. */ +#define sys_siglist _sys_siglist diff --git a/contrib/gcc/configure b/contrib/gcc/configure new file mode 100755 index 00000000000..1be333cc0f5 --- /dev/null +++ b/contrib/gcc/configure @@ -0,0 +1,3080 @@ +#!/bin/sh +# Configuration script for GNU CC +# Copyright (C) 1988, 90, 91, 92, 93, 94, 1995 Free Software Foundation, Inc. + +#This file is part of GNU CC. + +#GNU CC is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2, or (at your option) +#any later version. + +#GNU CC is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with GNU CC; see the file COPYING. If not, write to +#the Free Software Foundation, 59 Temple Place - Suite 330, +#Boston, MA 02111-1307, USA. + +# +# Shell script to create proper links to machine-dependent files in +# preparation for compiling gcc. +# +# Options: --srcdir=DIR specifies directory where sources are. +# --host=HOST specifies host configuration. +# --target=TARGET specifies target configuration. +# --build=TARGET specifies configuration of machine you are +# using to compile GCC. +# --prefix=DIR specifies directory to install in. +# --local-prefix=DIR specifies directory to put local ./include in. +# --gxx-include-dir=DIR specifies directory to put g++ header files in. +# --exec-prefix=DIR specifies directory to install executables in. +# --with-gnu-ld arrange to work with GNU ld. +# --with-gnu-as arrange to work with GAS. +# --with-stabs arrange to use stabs instead of host debug format. +# --with-elf arrange to use elf instead of host debug format. +# --enable-FOO, --enable-FOO=BAR include feature FOO (parameter BAR) +# --disable-FOO do not include feature FOO +# --nfp assume system has no FPU. +# --program-prefix=PREFIX specifies prefix for executable names. +# --program-suffix=SUFFIX specifies suffix for executable names. +# --program-transform-name=SED-EXPR specifies `sed' expression to +# apply to executable names. +# +# If configure succeeds, it leaves its status in config.status. +# If configure fails after disturbing the status quo, +# config.status is removed. +# + +progname=$0 + +# Default --srcdir to the directory where the script is found, +# if a directory was specified. +# The second sed call is to convert `.//configure' to `./configure'. +srcdir=`echo $0 | sed 's|//|/|' | sed 's|/[^/]*$||'` +if [ x$srcdir = x$0 ] +then +srcdir= +fi + +host= + +# Default prefix to /usr/local. +prefix=/usr/local + +# On systems where GCC is the native compiler, $prefix should be +# /usr. But the user can change it with configure --prefix=/foo/bar +native_prefix=/usr + +# local_prefix specifies where to find the directory /usr/local/include +# We don't use $(prefix) for this +# because we always want GCC to search /usr/local/include +# even if GCC is installed somewhere other than /usr/local. +# Think THREE TIMES before specifying any other value for this! +# DO NOT make this use $prefix! +local_prefix=/usr/local +# Default is to let the Makefile set exec_prefix from $(prefix) +exec_prefix='$(prefix)' +# +# The default g++ include directory is $(libdir)/g++-include. +gxx_include_dir='$(libdir)/g++-include' + +# Default --program-transform-name to nothing. +program_transform_name= +program_transform_set= + +remove=rm +hard_link=ln +symbolic_link='ln -s' +copy=cp + +# Record all the arguments, to write them in config.status. +arguments=$* + +#for Test +#remove="echo rm" +#hard_link="echo ln" +#symbolic_link="echo ln -s" + +target= +host= +build= +name1= +name2= + +for arg in $*; +do + case $next_arg in + --srcdir) + srcdir=$arg + next_arg= + ;; + --host) + host=$arg + next_arg= + ;; + --target) + target=$arg + next_arg= + ;; + --build) + build=$arg + next_arg= + ;; + --prefix) + prefix=$arg + native_prefix=$prefix + next_arg= + ;; + --local-prefix) + local_prefix=$arg + next_arg= + ;; + --gxx-include-dir) + gxx_include_dir=$arg + next_arg= + ;; + --exec-prefix) + exec_prefix=$arg + next_arg= + ;; + --program-transform-name) + # Double any backslashes or dollar signs in the argument. + if [ -n "${arg}" ] ; then + program_transform_name="${program_transform_name} -e `echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`" + fi + program_transform_set=yes + next_arg= + ;; + --program-prefix) + if [ -n "${arg}" ]; then + program_transform_name="${program_transform_name} -e s,^,`echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`," + fi + program_transform_set=yes + next_arg= + ;; + --program-suffix) + if [ -n "${arg}" ]; then + program_transform_name="${program_transform_name} -e s,\$\$,`echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`," + fi + program_transform_set=yes + next_arg= + ;; + --x-*) + next_arg= + ;; + *) + case $arg in + -*) + if [ x$name1 != x ] + then + echo "Positional arguments must be last." 1>&2 + exit 1 + fi + ;; + esac + + case $arg in + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + next_arg=--srcdir + ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=`echo $arg | sed 's/-*s[a-z]*=//'` + ;; + -host | --host | --hos | --ho) + next_arg=--host + ;; + -host=* | --host=* | --hos=* | --ho=*) + host=`echo $arg | sed 's/-*h[a-z]*=//'` + ;; + -target | --target | --targe | --targ | --tar | --ta | --t) + next_arg=--target + ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target=`echo $arg | sed 's/-*t[a-z]*=//'` + ;; + -build | --build | --buil | --bui | --bu | --b) + next_arg=--build + ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=* | --b=*) + build=`echo $arg | sed 's/-*b[a-z]*=//'` + ;; + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + next_arg=--prefix + ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=`echo $arg | sed 's/-*p[a-z]*=//'` + native_prefix=$prefix + ;; + -local-prefix | --local-prefix | --local-prefi | --local-pref | --local-pre \ + | --local-pr | --local-p | --local- | --local | --loc | --lo | --l) + next_arg=--local-prefix + ;; + -local-prefix=* | --local-prefix=* | --local-prefi=* | --local-pref=* \ + | --local-pre=* | --local-pr=* | --local-p=* | --local-=* | --local=* \ + | --loc=* | --lo=* | --l=*) + local_prefix=`echo $arg | sed 's/-*l[-a-z]*=//'` + ;; + -gxx-include-dir | --gxx-include-dir | --gxx-include \ + | --gxx-incl | --gxx-inc | --gxx-in | --gxx-i | --gxx- \ + | --gxx | --gxx | --gx | --g) + next_arg=--gxx-include-dir + ;; + -gxx-include-dir=* | --gxx-include-dir=* | --gxx-include=* \ + | --gxx-incl=* | --gxx-inc=* | --gxx-in=* | --gxx-i=* \ + | --gxx-=* | --gxx=* | --gxx=* | --gxx=* | --g=*) + gxx_include_dir=`echo $arg | sed 's/-*g[-a-z]*=//'` + ;; + -exec-prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre \ + | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e) + next_arg=--exec-prefix + ;; + -exec-prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* \ + | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* \ + | --exe=* | --ex=* | --e=*) + exec_prefix=`echo $arg | sed 's/-*e[-a-z]*=//'` + ;; + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- | --program-transform \ + | --program-transfor | --program-transfo | --program-transf \ + | --program-trans | --program-tran | --program-tra \ + | --program-tr | --program-t) + next_arg=--program-transform-name + ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* | --program-transfo=* \ + | --program-transf=* | --program-trans=* | --program-tran=* \ + | --program-tra=* | --program-tr=* | --program-t=*) + arg=`echo ${arg} | sed -e 's/^[-a-z_]*=//'` + # Double any \ or $ in the argument. + if [ -n "${arg}" ] ; then + program_transform_name="${program_transform_name} -e `echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`" + fi + program_transform_set=yes + ;; + -program-prefix | --program-prefix | --program-prefi \ + | --program-pref | --program-pre | --program-pr \ + | --program-p) + next_arg=--program-prefix + ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* \ + | --program-p=*) + arg=`echo ${arg} | sed -e 's/^[-a-z_]*=//'` + if [ -n "${arg}" ]; then + program_transform_name="${program_transform_name} -e s,^,`echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`," + fi + program_transform_set=yes + ;; + -program-suffix | --program-suffix | --program-suffi \ + | --program-suff | --program-suf | --program-su \ + | --program-s) + next_arg=--program-suffix + ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* \ + | --program-s=*) + arg=`echo ${arg} | sed -e 's/^[-a-z_]*=//'` + if [ -n "${arg}" ]; then + program_transform_name="${program_transform_name} -e s,\$\$,`echo ${arg} | sed -e 's/\\\\/\\\\\\\\/g' -e 's/\\\$/$$/g'`," + fi + program_transform_set=yes + ;; + -with-gnu-ld | --with-gnu-ld | --with-gnu-l) + gnu_ld=yes + ;; + -gas | --gas | --ga | --g | -with-gnu-as | --with-gnu-as | -with-gnu-a) + gas=yes + ;; + -nfp | --nfp | --nf | --n) + nfp=yes + ;; + -with-stabs | -with-stab | -with-sta | -with-st | -with-s \ + | --with-stabs | --with-stab | --with-sta | --with-st | --with-s \ + | -stabs | -stab | -sta | -st \ + | --stabs | --stab | --sta | --st) + stabs=yes + ;; + -with-elf | -with-el | -with-se \ + | --with-elf | --with-el | --with-e \ + | -elf | -el | -e \ + |--elf | --el | --e) + elf=yes + ;; + -with-* | --with-*) ;; #ignored + -without-* | --without-*) ;; #ignored + -disable-* | --disable-*) + enableopt=`echo ${arg} | sed 's:^-*disable-:enable_:;s:-:_:g'` + eval $enableopt=no + ;; + -enable-* | --enable-*) + case "$arg" in + *=*) optarg=`echo $arg | sed 's:^[^=]*=::;s:-:_:g'` ;; + *) optarg=yes ;; + esac + enableopt=`echo ${arg} | sed 's:^-*::;s:=.*$::;s:-:_:g'` + eval $enableopt="$optarg" + ;; + -x | --x) ;; # ignored + -x-*=* | --x-*=*) ;; # ignored + -x-* | --x-*) + next_arg=--x-ignored # ignored + ;; + --he*) ;; # ignored for now (--help) + --vers*) ;; # ignored for now (--version) + -v | -verb* | --verb*) ;; # ignored for now (--verbose) + --program-*) ;; #ignored (--program-prefix, --program-suffix) + --c*) ;; #ignored (--cache-file) + --q*) ;; #ignored (--quiet) + --si*) ;; #ignored (--silent) + -*) + echo "Invalid option \`$arg'" 1>&2 + exit 1 + ;; + *) +# Allow configure HOST TARGET. If just one name is given, it is used +# as both unless a host was previously given, in which case it is +# just the target. + if [ x$name1 != x ] + then + if [ x$name2 != x ] + then + echo "More than two configuration names." 1>&2 + exit 1 + fi + name2=$arg + elif [ x$host != x ] + then + name1=$host + name2=$arg + host= + else + name1=$arg + fi + ;; + esac + esac +done + +if [ x$name1 != x ] +then + if [ x$name2 = x ] + then + name2=$name1 + fi + + if [ x$host != x ] + then + echo "Duplicate specification of host." 1>&2 + exit 1 + fi + + if [ x$target != x ] + then + echo "Duplicate specification of target." 1>&2 + exit 1 + fi + + host=$name1 + build=$name1 + target=$name2 +fi + +# Find the source files, if location was not specified. +if [ x$srcdir = x ] +then + srcdirdefaulted=1 + srcdir=. + if [ ! -r tree.c ] + then + srcdir=.. + fi +fi + +if [ ! -r ${srcdir}/tree.c ] +then + if [ x$srcdirdefaulted = x ] + then + echo "$progname: Can't find compiler sources in \`${srcdir}'" 1>&2 + else + echo "$progname: Can't find compiler sources in \`.' or \`..'" 1>&2 + fi + exit 1 +fi + +if [ -r ${srcdir}/config.status ] && [ x$srcdir != x. ] +then + echo "$progname: \`configure' has been run in \`${srcdir}'" 1>&2 + exit 1 +fi + +# Complain if an arg is missing +if [ x$build = x ] +then + # If host was specified, always use it for build also to avoid + # confusion. If someone wants a cross compiler where build != host, + # then they must specify build explicitly. Since this case is + # extremely rare, it does not matter that it is slightly inconvenient. + if [ x$host != x ] + then + build=$host + + # This way of testing the result of a command substitution is + # defined by Posix.2 (section 3.9.1) as well as traditional shells. + elif build=`${srcdir}/config.guess` + then + echo "This appears to be a ${build} system." 1>&2 + + elif [ x$target != x ] + then + echo 'Config.guess failed to determine the host type. Defaulting to target.' + build=$target + else + echo 'Config.guess failed to determine the host type. You need to specify one.' 1>&2 + echo "\ +Usage: `basename $progname` [--host=HOST] [--build=BUILD] + [--prefix=DIR] [--gxx-include-dir=DIR] [--local-pref=DIR] [--exec-pref=DIR] + [--with-gnu-as] [--with-gnu-ld] [--with-stabs] [--with-elf] [--nfp] TARGET" 1>&2 + echo "Where HOST, TARGET and BUILD are three-part configuration names " 1>&2 + if [ -r config.status ] + then + tail +2 config.status 1>&2 + fi + exit 1 + fi +fi + +# If $host was not specified, use $build. +if [ x$host = x ] +then + host=$build +fi + +# If $target was not specified, use $host. +if [ x$target = x ] +then + target=$host +fi + +build_xm_file= +host_xm_file= +host_xmake_file= +host_broken_install= +host_install_headers_dir=install-headers-tar +host_truncate_target= + +# Validate the specs, and canonicalize them. +canon_build=`/bin/sh $srcdir/config.sub $build` || exit 1 +canon_host=`/bin/sh $srcdir/config.sub $host` || exit 1 +canon_target=`/bin/sh $srcdir/config.sub $target` || exit 1 + +# Decode the host machine, then the target machine. +# For the host machine, we save the xm_file variable as host_xm_file; +# then we decode the target machine and forget everything else +# that came from the host machine. +for machine in $canon_build $canon_host $canon_target; do + + cpu_type= + xm_file= + tm_file= + out_file= + xmake_file= + tmake_file= + extra_headers= + extra_passes= + extra_parts= + extra_programs= + extra_objs= + extra_gcc_objs= + # Set this to force installation and use of collect2. + use_collect2= + # Set this to override the default target model. + target_cpu_default= + # Set this to force use of install.sh. + broken_install= + # Set this to control which fixincludes program to use. + fixincludes=fixincludes + # Set this to control how the header file directory is installed. + install_headers_dir=install-headers-tar + # Set this to a non-empty list of args to pass to cpp if the target + # wants its .md file passed through cpp. + md_cppflags= + # Set this if directory names should be truncated to 14 characters. + truncate_target= + # Set this if gdb needs a dir command with `dirname $out_file` + gdb_needs_out_file_path= + + case $machine in + # Support site-specific machine types. + *local*) + cpu_type=`echo $machine | sed -e 's/-.*//'` + rest=`echo $machine | sed -e "s/$cpu_type-//"` + xm_file=${cpu_type}/xm-$rest.h + tm_file=${cpu_type}/$rest.h + if [ -f $srcdir/config/${cpu_type}/x-$rest ] ; \ + then xmake_file=${cpu_type}/x-$rest; \ + else true; \ + fi + if [ -f $srcdir/config/${cpu_type}/t-$rest ] ; \ + then tmake_file=${cpu_type}/t-$rest; \ + else true; \ + fi + ;; + 1750a-*-*) + ;; + a29k-*-bsd* | a29k-*-sym1*) + tm_file=a29k/unix.h + xm_file=a29k/xm-unix.h + xmake_file=a29k/x-unix + tmake_file=a29k/t-a29k + use_collect2=yes + ;; + a29k-*-udi | a29k-*-coff) + tmake_file=a29k/t-a29kbare + tm_file=a29k/a29k-udi.h + ;; + a29k-*-vxworks*) + tmake_file=a29k/t-vx29k + tm_file=a29k/vx29k.h + extra_parts="crtbegin.o crtend.o" + ;; + a29k-*-*) # Default a29k environment. + use_collect2=yes + ;; + alpha-dec-osf[23456789]*) + tm_file=alpha/osf2.h + if [ x$stabs = xyes ] + then + tm_file=alpha/gdb-osf2.h + fi + if [ x$gas != xyes ] + then + extra_passes="mips-tfile mips-tdump" + fi + broken_install=yes + use_collect2=yes + ;; + alpha-dec-osf1.2) + tm_file=alpha/osf12.h + if [ x$stabs = xyes ] + then + tm_file=alpha/gdb-osf12.h + fi + if [ x$gas != xyes ] + then + extra_passes="mips-tfile mips-tdump" + fi + broken_install=yes + use_collect2=yes + ;; + alpha-*-osf*) + if [ x$stabs = xyes ] + then + tm_file=alpha/gdb.h + fi + if [ x$gas != xyes ] + then + extra_passes="mips-tfile mips-tdump" + fi + broken_install=yes + use_collect2=yes + ;; + alpha-*-winnt3*) + tm_file=alpha/win-nt.h + xm_file=alpha/xm-winnt.h + tmake_file=t-libc-ok + xmake_file=winnt/x-winnt + extra_objs=oldnames.o + extra_gcc_objs="spawnv.o oldnames.o" + fixincludes=fixinc.winnt + if [ x$gnu_ld != xyes ] + then + extra_programs=ld.exe + fi + ;; + arm-*-riscix1.[01]*) # Acorn RISC machine (early versions) + tm_file=arm/riscix1-1.h + use_collect2=yes + ;; + arm-*-riscix*) # Acorn RISC machine + if [ x$gas = xyes ] + then + tm_file=arm/rix-gas.h + else + tm_file=arm/riscix.h + fi + xmake_file=arm/x-riscix + tmake_file=arm/t-riscix + use_collect2=yes + ;; + arm-semi-aout | armel-semi-aout) + cpu_type=arm + tm_file=arm/semi.h + tmake_file=arm/t-semi + fixincludes=Makefile.in # There is nothing to fix + ;; + arm-*-*) # generic version + ;; + c1-convex-*) # Convex C1 + cpu_type=convex + tm_file=convex/convex1.h + use_collect2=yes + fixincludes=Makefile.in + ;; + c2-convex-*) # Convex C2 + cpu_type=convex + tm_file=convex/convex2.h + use_collect2=yes + fixincludes=Makefile.in + ;; + c32-convex-*) + cpu_type=convex + tm_file=convex/convex32.h # Convex C32xx + use_collect2=yes + fixincludes=Makefile.in + ;; + c34-convex-*) + cpu_type=convex + tm_file=convex/convex34.h # Convex C34xx + use_collect2=yes + fixincludes=Makefile.in + ;; + c38-convex-*) + cpu_type=convex + tm_file=convex/convex38.h # Convex C38xx + use_collect2=yes + fixincludes=Makefile.in + ;; + clipper-intergraph-clix*) + broken_install=yes + cpu_type=clipper + xm_file=clipper/xm-clix.h + tm_file=clipper/clix.h + extra_headers=va-clipper.h + extra_parts="crtbegin.o crtend.o" + xmake_file=clipper/x-clix + install_headers_dir=install-headers-cpio + ;; + dsp16xx-*) + ;; + elxsi-elxsi-*) + use_collect2=yes + ;; +# This hasn't been upgraded to GCC 2. +# fx80-alliant-*) # Alliant FX/80 +# ;; + h8300-*-*) + cpu_type=h8300 + ;; + hppa1.1-*-osf*) + cpu_type=pa + tm_file=pa/pa1-osf.h + use_collect2=yes + fixincludes=Makefile.in + ;; + hppa1.0-*-osf*) + cpu_type=pa + tm_file=pa/pa-osf.h + use_collect2=yes + fixincludes=Makefile.in + ;; + hppa1.1-*-bsd*) + cpu_type=pa + tm_file=pa/pa1.h + use_collect2=yes + fixincludes=Makefile.in + ;; + hppa1.0-*-bsd*) + cpu_type=pa + use_collect2=yes + fixincludes=Makefile.in + ;; + hppa1.0-*-hpux7*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa-gux7.h + else + tm_file=pa/pa-hpux7.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.0-*-hpux8.0[0-2]*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa-ghpux.h + else + tm_file=pa/pa-oldas.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.1-*-hpux8.0[0-2]*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa1-ghpux.h + else + tm_file=pa/pa1-oldas.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.1-*-hpux9* | \ + hppa1.1-*-hpux10*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa1-ghpux9.h + else + tm_file=pa/pa1-hpux9.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.0-*-hpux9* | \ + hppa1.0-*-hpux10*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa-ghpux9.h + else + tm_file=pa/pa-hpux9.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.1-*-hpux*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa1-ghpux.h + else + tm_file=pa/pa1-hpux.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.0-*-hpux*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa-ghpux.h + else + tm_file=pa/pa-hpux.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.1-*-hiux*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa1-ghiux.h + else + tm_file=pa/pa1-hiux.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa1.0-*-hiux*) + cpu_type=pa + xm_file=pa/xm-pahpux.h + xmake_file=pa/x-pa-hpux + tmake_file=pa/t-pa + if [ x$gas = xyes ] + then + tm_file=pa/pa-ghiux.h + else + tm_file=pa/pa-hiux.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + ;; + hppa*-*-lites*) + cpu_type=pa + tm_file=pa/pa1.h + use_collect2=yes + fixincludes=Makefile.in + ;; + i370-*-mvs*) + cpu_type=i370 + tm_file=i370/mvs.h + xm_file=i370/xm-mvs.h + out_file=i370/mvs370.c + ;; + i[345]86-ibm-aix*) # IBM PS/2 running AIX + cpu_type=i386 + if [ x$gas = xyes ] + then + tm_file=i386/aix386.h + extra_parts="crtbegin.o crtend.o" + tmake_file=i386/t-crtstuff + else + tm_file=i386/aix386ng.h + use_collect2=yes + fi + xm_file=i386/xm-aix.h + xmake_file=i386/x-aix + broken_install=yes + ;; + i486-ncr-sysv4*) # NCR 3000 - i486 running system V.4 + cpu_type=i386 + xm_file=i386/xm-sysv4.h + xmake_file=i386/x-ncr3000 + tm_file=i386/sysv4.h + extra_parts="crtbegin.o crtend.o" + tmake_file=i386/t-crtpic + ;; + i[345]86-next-*) + cpu_type=i386 + tm_file=i386/next.h + out_file=i386/next.c + xm_file=i386/xm-next.h + tmake_file=i386/t-next + xmake_file=i386/x-next + ;; + i[345]86-sequent-bsd*) # 80386 from Sequent + cpu_type=i386 + use_collect2=yes + if [ x$gas = xyes ] + then + tm_file=i386/seq-gas.h + else + tm_file=i386/sequent.h + fi + ;; + i[345]86-sequent-ptx1*) + cpu_type=i386 + xm_file=i386/xm-sysv3.h + xmake_file=i386/x-sysv3 + tm_file=i386/seq-sysv3.h + tmake_file=i386/t-crtstuff + fixincludes=fixinc.ptx + extra_parts="crtbegin.o crtend.o" + install_headers_dir=install-headers-cpio + broken_install=yes + ;; + i[345]86-sequent-ptx2* | i[345]86-sequent-sysv*) + cpu_type=i386 + xm_file=i386/xm-sysv3.h + xmake_file=i386/x-sysv3 + tm_file=i386/seq2-sysv3.h + tmake_file=i386/t-crtstuff + extra_parts="crtbegin.o crtend.o" + fixincludes=fixinc.ptx + install_headers_dir=install-headers-cpio + broken_install=yes + ;; + i386-sun-sunos*) # Sun i386 roadrunner + xm_file=i386/xm-sun.h + tm_file=i386/sun.h + use_collect2=yes + ;; + i[345]86-*-aout*) + cpu_type=i386 + tm_file=i386/i386-aout.h + tmake_file=i386/t-i386bare + ;; + i[345]86-*-bsdi* | i[345]86-*-bsd386*) + cpu_type=i386 + tm_file=i386/bsd386.h + xm_file=i386/xm-bsd386.h +# tmake_file=t-libc-ok + ;; + i[345]86-*-bsd*) + cpu_type=i386 + tm_file=i386/386bsd.h + xm_file=i386/xm-bsd386.h +# tmake_file=t-libc-ok +# Next line turned off because both 386BSD and BSD/386 use GNU ld. +# use_collect2=yes + ;; + i[345]86-*-freebsd*) + cpu_type=i386 + tm_file=i386/freebsd.h + xm_file=i386/xm-freebsd.h + # On FreeBSD, the headers are already ok. + fixincludes=Makefile.in + xmake_file=i386/x-freebsd + ;; + i[345]86-*-netbsd*) + cpu_type=i386 + tm_file=i386/netbsd.h + xm_file=i386/xm-netbsd.h + # On NetBSD, the headers are already okay. + fixincludes=Makefile.in + tmake_file=t-libc-ok + xmake_file=x-netbsd + ;; + i[345]86-*-coff*) + cpu_type=i386 + tm_file=i386/i386-coff.h + tmake_file=i386/t-i386bare + ;; + i[345]86-*-gnu*) + cpu_type=i386 # GNU supports this CPU; rest done below. + ;; + i[345]86-*-isc*) # 80386 running ISC system + cpu_type=i386 + xm_file=i386/xm-isc.h + case $machine in + i[345]86-*-isc[34]*) + xmake_file=i386/x-isc3 + ;; + *) + xmake_file=i386/x-isc + ;; + esac + echo $xmake_file + if [ x$gas = xyes -a x$stabs = xyes ] + then + tm_file=i386/iscdbx.h + tmake_file=i386/t-svr3dbx + extra_parts="crtbegin.o crtend.o svr3.ifile svr3z.ifile" + else + tm_file=i386/isccoff.h + tmake_file=i386/t-crtstuff + extra_parts="crtbegin.o crtend.o" + fi + install_headers_dir=install-headers-cpio + broken_install=yes + ;; + i[345]86-*-linux*oldld*) # Intel 80386's running Linux + cpu_type=i386 # with a.out format using pre BFD linkers + xm_file=i386/xm-linux.h + xmake_file=x-linux + tm_file=i386/linux-oldld.h + fixincludes=Makefile.in #On Linux, the headers are ok already. + broken_install=yes + gnu_ld=yes + ;; + i[345]86-*-linux*aout*) # Intel 80386's running Linux + cpu_type=i386 # with a.out format + xm_file=i386/xm-linux.h + xmake_file=x-linux + tm_file=i386/linux-aout.h + fixincludes=Makefile.in #On Linux, the headers are ok already. + broken_install=yes + gnu_ld=yes + ;; + i[345]86-*-linux*) # Intel 80386's running Linux + cpu_type=i386 # with ELF format + xm_file=i386/xm-linux.h + xmake_file=x-linux + tm_file=i386/linux.h + fixincludes=Makefile.in #On Linux, the headers are ok already. + broken_install=yes + gnu_ld=yes + # Don't use it. Linux uses a slightly different one. + # The real one comes with the Linux C library. + #extra_parts="crtbegin.o crtend.o" + ;; + i[345]86-go32-msdos | i[345]86-*-go32) + cpu_type=i386 + tm_file=i386/go32.h + ;; + i[345]86-*-lynxos*) + cpu_type=i386 + if [ x$gas = xyes ] + then + tm_file=i386/lynx.h + else + tm_file=i386/lynx-ng.h + fi + xm_file=i386/xm-lynx.h + tmake_file=i386/t-i386bare + xmake_file=x-lynx + ;; + i[345]86-*-mach*) + cpu_type=i386 + tm_file=i386/mach.h +# tmake_file=t-libc-ok + use_collect2=yes + ;; + i[345]86-*-osfrose*) # 386 using OSF/rose + cpu_type=i386 + if [ x$elf = xyes ] + then + tm_file=i386/osfelf.h + use_collect2= + else + tm_file=i386/osfrose.h + use_collect2=yes + fi + xm_file=i386/xm-osf.h + xmake_file=i386/x-osfrose + extra_objs=halfpic.o + ;; + i[345]86-*-sco3.2v4*) # 80386 running SCO 3.2v4 system + cpu_type=i386 + xm_file=i386/xm-sco.h + xmake_file=i386/x-sco4 + fixincludes=fixinc.sco + broken_install=yes + install_headers_dir=install-headers-cpio + if [ x$stabs = xyes ] + then + tm_file=i386/sco4dbx.h + tmake_file=i386/t-svr3dbx + extra_parts="svr3.ifile svr3z.rfile" + else + tm_file=i386/sco4.h + tmake_file=i386/t-crtstuff + extra_parts="crtbegin.o crtend.o" + fi + ;; + i[345]86-*-sco*) # 80386 running SCO system + cpu_type=i386 + xm_file=i386/xm-sco.h + xmake_file=i386/x-sco + broken_install=yes + install_headers_dir=install-headers-cpio + if [ x$stabs = xyes ] + then + tm_file=i386/scodbx.h + tmake_file=i386/t-svr3dbx + extra_parts="svr3.ifile svr3z.rfile" + else + tm_file=i386/sco.h + extra_parts="crtbegin.o crtend.o" + tmake_file=i386/t-crtstuff + fi + truncate_target=yes + ;; + i[345]86-*-solaris2* | i[345]86-*-sunos5*) + cpu_type=i386 + xm_file=i386/xm-sysv4.h + tm_file=i386/sol2.h + tmake_file=i386/t-sol2 + extra_parts="crt1.o crti.o crtn.o crtbegin.o crtend.o" + xmake_file=x-svr4 + fixincludes=fixinc.svr4 + broken_install=yes + ;; + i[345]86-*-sysv4*) # Intel 80386's running system V.4 + cpu_type=i386 + xm_file=i386/xm-sysv4.h + if [ x$stabs = xyes ] + then + tm_file=i386/sysv4gdb.h + else + tm_file=i386/sysv4.h + fi + tmake_file=i386/t-crtpic + xmake_file=x-svr4 + extra_parts="crtbegin.o crtend.o" + ;; + i[345]86-*-sysv*) # Intel 80386's running system V + cpu_type=i386 + xm_file=i386/xm-sysv3.h + xmake_file=i386/x-sysv3 + if [ x$gas = xyes ] + then + if [ x$stabs = xyes ] + then + tm_file=i386/svr3dbx.h + tmake_file=i386/t-svr3dbx + extra_parts="svr3.ifile svr3z.rfile" + else + tm_file=i386/svr3gas.h + extra_parts="crtbegin.o crtend.o" + tmake_file=i386/t-crtstuff + fi + else + tm_file=i386/sysv3.h + extra_parts="crtbegin.o crtend.o" + tmake_file=i386/t-crtstuff + fi + ;; + i386-*-vsta) # Intel 80386's running VSTa kernel + xm_file=i386/xm-vsta.h + tm_file=i386/vsta.h + tmake_file=i386/t-vsta + xmake_file=i386/x-vsta + ;; + i[345]86-*-winnt3*) + cpu_type=i386 + tm_file=i386/win-nt.h + out_file=i386/i386.c + xm_file=i386/xm-winnt.h + xmake_file=winnt/x-winnt + tmake_file=i386/t-winnt + extra_objs="winnt.o oldnames.o" + extra_gcc_objs="spawnv.o oldnames.o" + fixincludes=fixinc.winnt + if [ x$gnu_ld != xyes ] + then + extra_programs=ld.exe + fi + ;; + i860-alliant-*) # Alliant FX/2800 + xm_file=i860/xm-fx2800.h + xmake_file=i860/x-fx2800 + tm_file=i860/fx2800.h + tmake_file=i860/t-fx2800 + extra_parts="crtbegin.o crtend.o" + ;; + i860-*-bsd*) + if [ x$gas = xyes ] + then + tm_file=i860/bsd-gas.h + else + tm_file=i860/bsd.h + fi + use_collect2=yes + ;; + i860-*-mach*) + xm_file=i860/xm-i860.h + tm_file=i860/mach.h + tmake_file=t-libc-ok + ;; + i860-*-osf*) # Intel Paragon XP/S, OSF/1AD + xm_file=i860/xm-paragon.h + tm_file=i860/paragon.h + tmake_file=t-osf + broken_install=yes + ;; + i860-*-sysv3*) + xm_file=i860/xm-sysv3.h + xmake_file=i860/x-sysv3 + tm_file=i860/sysv3.h + extra_parts="crtbegin.o crtend.o" + ;; + i860-*-sysv4*) + xm_file=i860/xm-sysv4.h + xmake_file=i860/x-sysv4 + tm_file=i860/sysv4.h + tmake_file=t-svr4 + extra_parts="crtbegin.o crtend.o" + ;; + i960-wrs-vxworks5 | i960-wrs-vxworks5.0*) + tmake_file=i960/t-vxworks960 + tm_file=i960/vx960.h + use_collect2=yes + ;; + i960-wrs-vxworks5*) + tmake_file=i960/t-vxworks960 + tm_file=i960/vx960-coff.h + use_collect2=yes + ;; + i960-wrs-vxworks*) + tmake_file=i960/t-vxworks960 + tm_file=i960/vx960.h + use_collect2=yes + ;; + i960-*-coff*) + tmake_file=i960/t-960bare + tm_file=i960/i960-coff.h + use_collect2=yes + ;; + i960-*-*) # Default i960 environment. + use_collect2=yes + ;; + m68000-convergent-sysv*) + cpu_type=m68k + xm_file=m68k/xm-3b1.h + tm_file=m68k/ctix.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68000-hp-bsd*) # HP 9000/200 running BSD + cpu_type=m68k + tm_file=m68k/hp2bsd.h + xmake_file=m68k/x-hp2bsd + use_collect2=yes + extra_headers=math-68881.h + ;; + m68000-hp-hpux*) # HP 9000 series 300 + cpu_type=m68k + xm_file=m68k/xm-hp320.h + if [ x$gas = xyes ] + then + xmake_file=m68k/x-hp320g + tm_file=m68k/hp310g.h + else + xmake_file=m68k/x-hp320 + tm_file=m68k/hp310.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + extra_headers=math-68881.h + ;; + m68000-sun-sunos3*) + cpu_type=m68k + tm_file=m68k/sun2.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68000-sun-sunos4*) + cpu_type=m68k + tm_file=m68k/sun2o4.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68000-att-sysv*) + cpu_type=m68k + xm_file=m68k/xm-3b1.h + if [ x$gas = xyes ] + then + tm_file=m68k/3b1g.h + else + tm_file=m68k/3b1.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-apollo-*) + xmake_file=m68k/x-apollo68 + tm_file=m68k/apollo68.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-altos-sysv*) # Altos 3068 + if [ x$gas = xyes ] + then + xm_file=m68k/xm-altos3068.h + tm_file=m68k/altos3068.h + else + echo "The Altos is supported only with the GNU assembler" 1>&2 + exit 1 + fi + extra_headers=math-68881.h + ;; + m68k-bull-sysv*) # Bull DPX/2 + if [ x$gas = xyes ] + then + if [ x$stabs = xyes ] + then + tm_file=m68k/dpx2cdbx.h + else + tm_file=m68k/dpx2g.h + fi + else + tm_file=m68k/dpx2.h + fi + xm_file=m68k/xm-m68kv.h + xmake_file=m68k/x-dpx2 + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-atari-sysv4*) # Atari variant of V.4. + tm_file=m68k/atari.h + xm_file=m68k/xm-atari.h + tmake_file=t-svr4 + extra_parts="crtbegin.o crtend.o" + extra_headers=math-68881.h + ;; + m68k-motorola-sysv*) + xm_file=m68k/xm-mot3300.h + xmake_file=m68k/x-mot3300 + if [ x$gas = xyes ] + then + tm_file=m68k/mot3300g.h + else + tm_file=m68k/mot3300.h + gdb_needs_out_file_path=yes + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-ncr-sysv*) # NCR Tower 32 SVR3 + tm_file=m68k/tower-as.h + xm_file=m68k/xm-tower.h + xmake_file=m68k/x-tower + extra_parts="crtbegin.o crtend.o" + extra_headers=math-68881.h + ;; + m68k-plexus-sysv*) + tm_file=m68k/plexus.h + xm_file=m68k/xm-plexus.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-tti-*) + tm_file=m68k/pbb.h + xm_file=m68k/xm-m68kv.h + extra_headers=math-68881.h + ;; + m68k-crds-unos*) + xm_file=m68k/xm-crds.h + xmake_file=m68k/x-crds + tm_file=m68k/crds.h + broken_install=yes + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-cbm-sysv4*) # Commodore variant of V.4. + tm_file=m68k/amix.h + xm_file=m68k/xm-amix.h + xmake_file=m68k/x-amix + tmake_file=t-svr4 + extra_parts="crtbegin.o crtend.o" + extra_headers=math-68881.h + ;; + m68k-ccur-rtu) + tm_file=m68k/ccur-GAS.h + xmake_file=m68k/x-ccur + extra_headers=math-68881.h + use_collect2=yes + broken_install=yes + ;; + m68k-hp-bsd4.4*) # HP 9000/3xx running 4.4bsd + tm_file=m68k/hp3bsd44.h + xmake_file=m68k/x-hp3bsd44 + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-hp-bsd*) # HP 9000/3xx running Berkeley Unix + tm_file=m68k/hp3bsd.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-isi-bsd*) + if [ x$nfp = xyes ] + then + tm_file=m68k/isi-nfp.h + else + tm_file=m68k/isi.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-hp-hpux7*) # HP 9000 series 300 running HPUX version 7. + xm_file=m68k/xm-hp320.h + if [ x$gas = xyes ] + then + xmake_file=m68k/x-hp320g + tm_file=m68k/hp320g.h + else + xmake_file=m68k/x-hp320 + tm_file=m68k/hpux7.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-hp-hpux*) # HP 9000 series 300 + xm_file=m68k/xm-hp320.h + if [ x$gas = xyes ] + then + xmake_file=m68k/x-hp320g + tm_file=m68k/hp320g.h + else + xmake_file=m68k/x-hp320 + tm_file=m68k/hp320.h + fi + broken_install=yes + install_headers_dir=install-headers-cpio + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-sun-mach*) + tm_file=m68k/sun3mach.h + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-sony-newsos3*) + if [ x$gas = xyes ] + then + tm_file=m68k/news3gas.h + else + tm_file=m68k/news3.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-sony-bsd* | m68k-sony-newsos*) + if [ x$gas = xyes ] + then + tm_file=m68k/newsgas.h + else + tm_file=m68k/news.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-next-nextstep2*) + tm_file=m68k/next21.h + out_file=m68k/next.c + xm_file=m68k/xm-next.h + tmake_file=m68k/t-next + xmake_file=m68k/x-next + extra_headers=math-68881.h + use_collect2=yes + ;; + m68k-next-nextstep3*) + tm_file=m68k/next.h + out_file=m68k/next.c + xm_file=m68k/xm-next.h + tmake_file=m68k/t-next + xmake_file=m68k/x-next + extra_headers=math-68881.h + ;; + m68k-sun-sunos3*) + if [ x$nfp = xyes ] + then + tm_file=m68k/sun3n3.h + else + tm_file=m68k/sun3o3.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-sun-sunos*) # For SunOS 4 (the default). + if [ x$nfp = xyes ] + then + tm_file=m68k/sun3n.h + else + tm_file=m68k/sun3.h + fi + use_collect2=yes + extra_headers=math-68881.h + ;; + m68k-wrs-vxworks*) + tm_file=m68k/vxm68k.h + tmake_file=m68k/t-vxworks68 + extra_headers=math-68881.h + ;; + m68k-*-aout*) + tmake_file=m68k/t-m68kbare + tm_file=m68k/m68k-aout.h + extra_headers=math-68881.h + ;; + m68k-*-coff*) + tmake_file=m68k/t-m68kbare + tm_file=m68k/m68k-coff.h + extra_headers=math-68881.h + ;; + m68k-*-lynxos*) + if [ x$gas = xyes ] + then + tm_file=m68k/lynx.h + else + tm_file=m68k/lynx-ng.h + fi + xm_file=m68k/xm-lynx.h + xmake_file=x-lynx + tmake_file=m68k/t-lynx + extra_headers=math-68881.h + ;; + m68k-*-netbsd*) + cpu_type=m68k + tm_file=m68k/netbsd.h + xm_file=m68k/xm-netbsd.h + # On NetBSD, the headers are already okay. + fixincludes=Makefile.in + tmake_file=t-libc-ok + xmake_file=x-netbsd + ;; + m68k-*-sysv3*) # Motorola m68k's running system V.3 + xm_file=m68k/xm-m68kv.h + xmake_file=m68k/x-m68kv + extra_parts="crtbegin.o crtend.o" + extra_headers=math-68881.h + ;; + m68k-*-sysv4*) # Motorola m68k's running system V.4 + tm_file=m68k/m68kv4.h + xm_file=m68k/xm-m68kv.h + tmake_file=t-svr4 + extra_parts="crtbegin.o crtend.o" + extra_headers=math-68881.h + ;; + m68k-*-linux*aout*) # Motorola m68k's running Linux + xm_file=m68k/xm-linux.h # with a.out format + xmake_file=x-linux + tm_file=m68k/linux-aout.h + tmake_file=m68k/t-linux + fixincludes=Makefile.in #On Linux, the headers are ok already. + extra_headers=math-68881.h + gnu_ld=yes + ;; + m68k-*-linux*) # Motorola m68k's running Linux + xm_file=m68k/xm-linux.h # with ELF format + xmake_file=x-linux + tm_file=m68k/linux.h + tmake_file=m68k/t-linux + fixincludes=Makefile.in #On Linux, the headers are ok already. + extra_headers=math-68881.h + gnu_ld=yes + # Don't use it. Linux uses a slightly different one. + # The real one comes with the Linux C library. + #extra_parts="crtbegin.o crtend.o" + ;; + m88k-dg-dgux*) + case $machine in + m88k-dg-dguxbcs*) + tm_file=m88k/dguxbcs.h + xmake_file=m88k/x-dguxbcs + ;; + *) + tm_file=m88k/dgux.h + xmake_file=m88k/x-dgux + ;; + esac + extra_parts="crtbegin.o bcscrtbegin.o crtend.o m88kdgux.ld" + broken_install=yes + if [ x$gas = xyes ] + then + tmake_file=m88k/t-dgux-gas + else + tmake_file=m88k/t-dgux + fi + fixincludes=fixinc.dgux + ;; + m88k-dolphin-sysv3*) + tm_file=m88k/dolph.h + extra_parts="crtbegin.o crtend.o" + xm_file=m88k/xm-sysv3.h + xmake_file=m88k/x-dolph + if [ x$gas = xyes ] + then + tmake_file=m88k/t-m88k-gas + fi + ;; + m88k-tektronix-sysv3) + tm_file=m88k/tekXD88.h + extra_parts="crtbegin.o crtend.o" + xm_file=m88k/xm-sysv3.h + xmake_file=m88k/x-tekXD88 + if [ x$gas = xyes ] + then + tmake_file=m88k/t-m88k-gas + fi + ;; + m88k-*-aout*) + cpu_type=m88k + tm_file=m88k/m88k-aout.h + ;; + m88k-*-coff*) + cpu_type=m88k + tm_file=m88k/m88k-coff.h + tmake_file=m88k/t-bug + ;; + m88k-*-luna*) + tm_file=m88k/luna.h + extra_parts="crtbegin.o crtend.o" + if [ x$gas = xyes ] + then + tmake_file=m88k/t-luna-gas + else + tmake_file=m88k/t-luna + fi + ;; + m88k-*-sysv3*) + tm_file=m88k/sysv3.h + extra_parts="crtbegin.o crtend.o" + xm_file=m88k/xm-sysv3.h + xmake_file=m88k/x-sysv3 + if [ x$gas = xyes ] + then + tmake_file=m88k/t-m88k-gas + fi + ;; + m88k-*-sysv4*) + tm_file=m88k/sysv4.h + extra_parts="crtbegin.o crtend.o" + xmake_file=m88k/x-sysv4 + tmake_file=m88k/t-sysv4 + ;; + mips-sgi-irix6*) # SGI System V.4., IRIX 6 + tm_file=mips/iris6.h + xm_file=mips/xm-iris6.h + broken_install=yes + fixincludes=Makefile.in + xmake_file=mips/x-iris6 + tmake_file=mips/t-iris6 + # See comment in mips/iris[56].h files. + use_collect2=yes + ;; + mips-sgi-irix5cross64) # Irix5 host, Irix 6 target, cross64 + tm_file=mips/cross64.h + xm_file=mips/xm-iris5.h + broken_install=yes + fixincludes=Makefile.in + xmake_file=mips/x-iris + tmake_file=mips/t-cross64 + # See comment in mips/iris[56].h files. + use_collect2=yes + ;; + mips-sgi-irix5*) # SGI System V.4., IRIX 5 + if [ x$gas = xyes ] + then + if [ x$stabs = xyes ] + then + tm_file=mips/iris5gdb.h + else + tm_file=mips/iris5gas.h + fi + else + tm_file=mips/iris5.h + fi + xm_file=mips/xm-iris5.h + broken_install=yes + fixincludes=Makefile.in + xmake_file=mips/x-iris + # mips-tfile doesn't work yet + tmake_file=mips/t-mips-gas + # See comment in mips/iris5.h file. + use_collect2=yes + ;; + mips-sgi-irix4loser*) # Mostly like a MIPS. + if [ x$stabs = xyes ]; then + tm_file=mips/iris4gl.h + else + tm_file=mips/iris4loser.h + fi + xm_file=mips/xm-iris4.h + broken_install=yes + xmake_file=mips/x-iris + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-sgi-irix4*) # Mostly like a MIPS. + if [ x$stabs = xyes ]; then + tm_file=mips/iris4-gdb.h + else + tm_file=mips/iris4.h + fi + xm_file=mips/xm-iris4.h + broken_install=yes + xmake_file=mips/x-iris + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-sgi-*) # Mostly like a MIPS. + if [ x$stabs = xyes ]; then + tm_file=mips/iris3-gdb.h + else + tm_file=mips/iris3.h + fi + xm_file=mips/xm-iris3.h + broken_install=yes + xmake_file=mips/x-iris3 + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-dec-osfrose*) # Decstation running OSF/1 reference port with OSF/rose. + tm_file=mips/osfrose.h + xmake_file=mips/x-osfrose + tmake_file=mips/t-osfrose + extra_objs=halfpic.o + use_collect2=yes + ;; + mips-dec-osf*) # Decstation running OSF/1 as shipped by DIGITAL + if [ x$stabs = xyes ]; then + tm_file=mips/dec-gosf1.h + else + tm_file=mips/dec-osf1.h + fi + xmake_file=mips/x-dec-osf1 + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + tmake_file=mips/t-ultrix + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-dec-bsd*) # Decstation running 4.4 BSD + tm_file=mips/dec-bsd.h + xmake_file= + tmake_file= + fixincludes= + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + tmake_file=mips/t-ultrix + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-dec-netbsd*) # Decstation running NetBSD + tm_file=mips/netbsd.h + xm_file=mips/xm-netbsd.h + xmake_file=x-netbsd + tmake_file=t-libc-ok + fixincludes=Makefile.in + prefix=$native_prefix + ;; + mips-sony-bsd* | mips-sony-newsos*) # Sony NEWS 3600 or risc/news. + if [ x$stabs = xyes ]; then + tm_file=mips/news4-gdb.h + else + tm_file=mips/news4.h + fi + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + xmake_file=mips/x-sony + ;; + mips-sony-sysv*) # Sony NEWS 3800 with NEWSOS5.0. + # That is based on svr4. + # t-svr4 is not right because this system doesn't use ELF. + if [ x$stabs = xyes ]; then + tm_file=mips/news5-gdb.h + else + tm_file=mips/news5.h + fi + xm_file=mips/xm-news.h + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-tandem-sysv4*) # Tandem S2 running NonStop UX + if [ x$stabs = xyes ]; then + tm_file=mips/svr4-t-gdb.h + else + tm_file=mips/svr4-t.h + fi + xm_file=mips/xm-sysv4.h + xmake_file=mips/x-sysv + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + extra_parts="crtbegin.o crtend.o" + else + tmake_file=mips/t-mips + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-ultrix* | mips-dec-mach3) # Decstation. + if [ x$stabs = xyes ]; then + tm_file=mips/ultrix-gdb.h + else + tm_file=mips/ultrix.h + fi + xmake_file=mips/x-ultrix + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + tmake_file=mips/t-ultrix + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + mips-*-riscos[56789]bsd*) + if [ x$stabs = xyes ]; then # MIPS BSD 4.3, RISC-OS 5.0 + tm_file=mips/bsd-5-gdb.h + else + tm_file=mips/bsd-5.h + fi + if [ x$gas = xyes ] + then + tmake_file=mips/t-bsd-gas + else + tmake_file=mips/t-bsd + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-bsd* | mips-*-riscosbsd* | mips-*-riscos[1234]bsd*) + if [ x$stabs = xyes ]; then # MIPS BSD 4.3, RISC-OS 4.0 + tm_file=mips/bsd-4-gdb.h + else + tm_file=mips/bsd-4.h + fi + if [ x$gas = xyes ] + then + tmake_file=mips/t-bsd-gas + else + tmake_file=mips/t-bsd + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-riscos[56789]sysv4*) + if [ x$stabs = xyes ]; then # MIPS System V.4., RISC-OS 5.0 + tm_file=mips/svr4-5-gdb.h + else + tm_file=mips/svr4-5.h + fi + xm_file=mips/xm-sysv4.h + xmake_file=mips/x-sysv + if [ x$gas = xyes ] + then + tmake_file=mips/t-svr4-gas + else + tmake_file=mips/t-svr4 + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-sysv4* | mips-*-riscos[1234]sysv4* | mips-*-riscossysv4*) + if [ x$stabs = xyes ]; then # MIPS System V.4. RISC-OS 4.0 + tm_file=mips/svr4-4-gdb.h + else + tm_file=mips/svr4-4.h + fi + xm_file=mips/xm-sysv.h + xmake_file=mips/x-sysv + if [ x$gas = xyes ] + then + tmake_file=mips/t-svr4-gas + else + tmake_file=mips/t-svr4 + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-riscos[56789]sysv*) + if [ x$stabs = xyes ]; then # MIPS System V.3, RISC-OS 5.0 + tm_file=mips/svr3-5-gdb.h + else + tm_file=mips/svr3-5.h + fi + xm_file=mips/xm-sysv.h + xmake_file=mips/x-sysv + if [ x$gas = xyes ] + then + tmake_file=mips/t-svr3-gas + else + tmake_file=mips/t-svr3 + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-sysv* | mips-*-riscos*sysv*) + if [ x$stabs = xyes ]; then # MIPS System V.3, RISC-OS 4.0 + tm_file=mips/svr3-4-gdb.h + else + tm_file=mips/svr3-4.h + fi + xm_file=mips/xm-sysv.h + xmake_file=mips/x-sysv + if [ x$gas = xyes ] + then + tmake_file=mips/t-svr3-gas + else + tmake_file=mips/t-svr3 + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-riscos[56789]*) # Default MIPS RISC-OS 5.0. + if [ x$stabs = xyes ]; then + tm_file=mips/mips-5-gdb.h + else + tm_file=mips/mips-5.h + fi + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + broken_install=yes + ;; + mips-*-gnu*) + cpu_type=mips # GNU supports this CPU; rest done below. + ;; + mipsel-*-ecoff*) + cpu_type=mips + if [ x$stabs = xyes ]; then + tm_file=mips/ecoffl-gdb.h + else + tm_file=mips/ecoffl.h + fi + tmake_file=mips/t-ecoff + ;; + mips-*-ecoff*) + if [ x$stabs = xyes ]; then + tm_file=mips/ecoff-gdb.h + else + tm_file=mips/ecoff.h + fi + tmake_file=mips/t-ecoff + broken_install=yes + ;; + mipsel-*-elf*) + cpu_type=mips + tm_file=mips/elfl.h + tmake_file=mips/t-ecoff + ;; + mips-*-elf*) + cpu_type=mips + tm_file=mips/elf.h + tmake_file=mips/t-ecoff + ;; + mips64el-*-elf*) + cpu_type=mips + tm_file=mips/elfl64.h + tmake_file=mips/t-ecoff + ;; + mips64orionel-*-elf*) + cpu_type=mips + tm_file=mips/elflorion.h + tmake_file=mips/t-ecoff + ;; + mips64-*-elf*) + cpu_type=mips + tm_file=mips/elf64.h + tmake_file=mips/t-ecoff + ;; + mips64orion-*-elf*) + cpu_type=mips + tm_file=mips/elforion.h + tmake_file=mips/t-ecoff + ;; + mips-*-*) # Default MIPS RISC-OS 4.0. + if [ x$stabs = xyes ]; then + tm_file=mips/mips-4-gdb.h + else + tm_file=mips/mips.h + fi + if [ x$gas = xyes ] + then + tmake_file=mips/t-mips-gas + else + extra_passes="mips-tfile mips-tdump" + fi + if [ x$gnu_ld != xyes ] + then + use_collect2=yes + fi + ;; + ns32k-encore-bsd*) + tm_file=ns32k/encore.h + use_collect2=yes + ;; + ns32k-sequent-bsd*) + tm_file=ns32k/sequent.h + use_collect2=yes + ;; + ns32k-tek6100-bsd*) + tm_file=ns32k/tek6100.h + broken_install=yes + use_collect2=yes + ;; + ns32k-tek6200-bsd*) + tm_file=ns32k/tek6200.h + broken_install=yes + use_collect2=yes + ;; +# This has not been updated to GCC 2. +# ns32k-ns-genix*) +# xm_file=ns32k/xm-genix.h +# xmake_file=ns32k/x-genix +# tm_file=ns32k/genix.h +# broken_install=yes +# use_collect2=yes +# ;; + ns32k-merlin-*) + tm_file=ns32k/merlin.h + use_collect2=yes + ;; + ns32k-pc532-mach*) + tm_file=ns32k/pc532-mach.h + use_collect2=yes + ;; + ns32k-pc532-minix*) + tm_file=ns32k/pc532-min.h + xm_file=ns32k/xm-pc532-min.h + use_collect2=yes + ;; + ns32k-pc532-netbsd*) + tm_file=ns32k/netbsd.h + xm_file=ns32k/xm-netbsd.h + tmake_file=t-libc-ok + # On NetBSD, the headers are already okay. + fixincludes=Makefile.in + xmake_file=x-netbsd + ;; + pyramid-*-*) + cpu_type=pyr + xmake_file=pyr/x-pyr + use_collect2=yes + ;; + romp-*-aos*) + use_collect2=yes + ;; + romp-*-mach*) + xmake_file=romp/x-mach + use_collect2=yes + ;; + powerpc-ibm-aix[456789].*) + cpu_type=rs6000 + tm_file=rs6000/aix41ppc.h + tmake_file=rs6000/t-newas + use_collect2=yes + ;; + powerpc-ibm-aix*) + cpu_type=rs6000 + tm_file=rs6000/powerpc.h + tmake_file=rs6000/t-rs6000 + use_collect2=yes + ;; + powerpc-*-sysv4* | powerpc-*-elf*) + cpu_type=rs6000 + xm_file=rs6000/xm-sysv4.h + tm_file=rs6000/sysv4.h + if [ x$gas = xyes ] + then + tmake_file=rs6000/t-ppcgas + else + tmake_file=rs6000/t-ppc + fi + xmake_file=rs6000/x-sysv4 + ;; + powerpc-*-eabiaix*) + cpu_type=rs6000 + tm_file=rs6000/eabiaix.h + tmake_file=rs6000/t-eabiaix + fixincludes=Makefile.in + ;; + powerpc-*-eabisim*) + cpu_type=rs6000 + tm_file=rs6000/eabisim.h + tmake_file=rs6000/t-eabisim + fixincludes=Makefile.in + ;; + powerpc-*-eabi*) + cpu_type=rs6000 + tm_file=rs6000/eabi.h + if [ x$gas = xyes ] + then + tmake_file=rs6000/t-eabigas + else + tmake_file=rs6000/t-eabi + fi + fixincludes=Makefile.in + ;; + powerpcle-*-sysv4* | powerpcle-*-elf*) + cpu_type=rs6000 + xm_file=rs6000/xm-sysv4.h + tm_file=rs6000/sysv4le.h + if [ x$gas = xyes ] + then + tmake_file=rs6000/t-ppclegas + else + tmake_file=rs6000/t-ppc + fi + xmake_file=rs6000/x-sysv4 + ;; + powerpcle-*-eabisim*) + cpu_type=rs6000 + tm_file=rs6000/eabilesim.h + tmake_file=rs6000/t-eabisim + fixincludes=Makefile.in + ;; + powerpcle-*-eabi*) + cpu_type=rs6000 + tm_file=rs6000/eabile.h + if [ x$gas = xyes ] + then + tmake_file=rs6000/t-eabilegas + else + tmake_file=rs6000/t-eabi + fi + fixincludes=Makefile.in + ;; + rs6000-ibm-aix3.[01]*) + tm_file=rs6000/aix31.h + tmake_file=rs6000/t-rs6000 + xmake_file=rs6000/x-aix31 + use_collect2=yes + ;; + rs6000-ibm-aix3.2.[456789]*) + tm_file=rs6000/aix3newas.h + tmake_file=rs6000/t-newas + use_collect2=yes + ;; + rs6000-ibm-aix[456789].*) + tm_file=rs6000/aix41.h + tmake_file=rs6000/t-newas + xmake_file=rs6000/x-aix31 + use_collect2=yes + ;; + rs6000-ibm-aix*) + use_collect2=yes + tmake_file=rs6000/t-rs6000 + ;; + rs6000-bull-bosx) + tmake_file=rs6000/t-rs6000 + use_collect2=yes + ;; + rs6000-*-mach*) + xm_file=rs6000/xm-mach.h + tm_file=rs6000/mach.h + tmake_file=rs6000/t-rs6000 + xmake_file=rs6000/x-mach + use_collect2=yes + ;; + rs6000-*-lynxos*) + xmake_file=rs6000/x-lynx + xm_file=rs6000/xm-lynx.h + tm_file=rs6000/lynx.h + tmake_file=rs6000/t-rs6000 + use_collect2=yes + ;; + sh-*-*) + cpu_type=sh + ;; + sparc-tti-*) + tm_file=sparc/pbd.h + xm_file=sparc/xm-pbd.h + ;; + sparc-wrs-vxworks* | sparclite-wrs-vxworks*) + cpu_type=sparc + tm_file=sparc/vxsparc.h + tmake_file=sparc/t-vxsparc + use_collect2=yes + ;; + sparc-*-aout*) + tmake_file=sparc/t-sparcbare + tm_file=sparc/sparc-aout.h + ;; + sparc-*-netbsd*) + tm_file=sparc/netbsd.h + xm_file=sparc/xm-netbsd.h + # On NetBSD, the headers are already okay. + fixincludes=Makefile.in + tmake_file=t-libc-ok + xmake_file=x-netbsd + ;; + sparc-*-bsd*) + tm_file=sparc/bsd.h + ;; + sparc-*-lynxos*) + if [ x$gas = xyes ] + then + tm_file=sparc/lynx.h + else + tm_file=sparc/lynx-ng.h + fi + xm_file=sparc/xm-lynx.h + tmake_file=sparc/t-sunos41 + xmake_file=x-lynx + ;; + sparc-*-solaris2* | sparc-*-sunos5*) + xm_file=sparc/xm-sol2.h + tm_file=sparc/sol2.h + tmake_file=sparc/t-sol2 + xmake_file=sparc/x-sysv4 + extra_parts="crt1.o crti.o crtn.o gmon.o crtbegin.o crtend.o" + fixincludes=fixinc.svr4 + broken_install=yes + ;; + sparc-*-sunos4.0*) + tm_file=sparc/sunos4.h + tmake_file=sparc/t-sunos40 + use_collect2=yes + ;; + sparc-*-sunos4*) + tm_file=sparc/sunos4.h + tmake_file=sparc/t-sunos41 + use_collect2=yes + ;; + sparc-*-sunos3*) + tm_file=sparc/sun4o3.h + use_collect2=yes + ;; + sparc-*-sysv4*) + xm_file=sparc/xm-sysv4.h + tm_file=sparc/sysv4.h + tmake_file=t-svr4 + xmake_file=sparc/x-sysv4 + extra_parts="crtbegin.o crtend.o" + ;; + sparclite-*-coff*) + cpu_type=sparc + tm_file=sparc/litecoff.h + tmake_file=sparc/t-sparclite + ;; + sparclite-*-*) + cpu_type=sparc + tm_file=sparc/lite.h + tmake_file=sparc/t-sparclite + use_collect2=yes + ;; + sparc64-*-aout*) + cpu_type=sparc + tmake_file=sparc/t-sp64 + tm_file=sparc/sp64-aout.h + ;; + sparc64-*-elf*) + cpu_type=sparc + tmake_file=sparc/t-sp64 + tm_file=sparc/sp64-elf.h + extra_parts="crtbegin.o crtend.o" + ;; +# This hasn't been upgraded to GCC 2. +# tahoe-harris-*) # Harris tahoe, using COFF. +# tm_file=tahoe/harris.h +# ;; +# tahoe-*-bsd*) # tahoe running BSD +# ;; +# This hasn't been upgraded to GCC 2. +# tron-*-*) +# cpu_type=gmicro +# use_collect2=yes +# ;; + vax-*-bsd*) # vaxen running BSD + use_collect2=yes + ;; + vax-*-sysv*) # vaxen running system V + xm_file=vax/xm-vaxv.h + tm_file=vax/vaxv.h + ;; + vax-*-netbsd*) + tm_file=vax/netbsd.h + xm_file=vax/xm-netbsd.h + tmake_file=t-libc-ok + # On NetBSD, the headers are already okay. + fixincludes=Makefile.in + xmake_file=x-netbsd + ;; + vax-*-ultrix*) # vaxen running ultrix + tm_file=vax/ultrix.h + use_collect2=yes + ;; + vax-*-vms*) # vaxen running VMS + xm_file=vax/xm-vms.h + tm_file=vax/vms.h + ;; + pdp11-*-bsd) + xm_file=pdp11/xm-pdp11.h + tm_file=pdp11/2bsd.h + tmake_file=pdp11/t-pdp11 + ;; + pdp11-*-*) + xm_file=pdp11/xm-pdp11.h + tm_file=pdp11/pdp11.h + tmake_file=pdp11/t-pdp11 + ;; + we32k-att-sysv*) + cpu_type=we32k + use_collect2=yes + ;; + *) + echo "Configuration $machine not supported" 1>&2 + exit 1 + ;; + esac + + case $machine in + *-*-gnu*) + # On the GNU system, the setup is just about the same on + # each different CPU. The specific machines that GNU + # supports are matched above and just set $cpu_type. + xm_file=${cpu_type}/xm-gnu.h + tm_file=${cpu_type}/gnu.h + extra_parts="crtbegin.o crtbeginS.o crtend.o crtendS.o" + # GNU always uses ELF. + elf=yes + # GNU tools are the only tools. + gnu_ld=yes + gas=yes + # On GNU, the headers are already okay. + fixincludes=Makefile.in + # Don't build libgcc1.c, because there is no non-GNU + # compiler to build it with. The GNU system C library will + # include assembly versions of any needed functions. + tmake_file=t-libc-ok + ;; + *-*-sysv4*) + fixincludes=fixinc.svr4 + xmake_try_sysv=x-sysv + broken_install=yes + install_headers_dir=install-headers-cpio + ;; + *-*-sysv*) + broken_install=yes + install_headers_dir=install-headers-cpio + ;; + esac + + # Distinguish i386 from i486/i586. + # ??? For the moment we treat i586 as an i486. + # Also, do not run mips-tfile on MIPS if using gas. + case $machine in + i[45]86-*-*) + target_cpu_default=2 + ;; + mips*-*-*) + if [ x$gas = xyes ] + then + target_cpu_default=16 + fi + ;; + alpha-*-*) + if [ x$gas = xyes ] + then + target_cpu_default=4 + fi + ;; + esac + + # No need for collect2 if we have the GNU linker. + case x$gnu_ld in + xyes) + use_collect2= + ;; + esac + +# Default certain vars that apply to both host and target in turn. + if [ x$cpu_type = x ] + then cpu_type=`echo $machine | sed 's/-.*$//'` + fi + +# Save data on machine being used to compile GCC in build_xm_file. +# Save data on host machine in vars host_xm_file and host_xmake_file. + if [ x$pass1done = x ] + then + if [ x$xm_file = x ] + then build_xm_file=$cpu_type/xm-$cpu_type.h + else build_xm_file=$xm_file + fi + pass1done=yes + else + if [ x$pass2done = x ] + then + if [ x$xm_file = x ] + then host_xm_file=$cpu_type/xm-$cpu_type.h + else host_xm_file=$xm_file + fi + if [ x$xmake_file = x ] + then xmake_file=$cpu_type/x-$cpu_type + fi + host_xmake_file=$xmake_file + host_broken_install=$broken_install + host_install_headers_dir=$install_headers_dir + host_truncate_target=$truncate_target + pass2done=yes + fi + fi +done + +# Default the target-machine variables that were not explicitly set. +if [ x$tm_file = x ] +then tm_file=$cpu_type/$cpu_type.h; fi + +if [ x$extra_headers = x ] +then extra_headers=; fi + +if [ x$xm_file = x ] +then xm_file=$cpu_type/xm-$cpu_type.h; fi + +md_file=$cpu_type/$cpu_type.md + +if [ x$out_file = x ] +then out_file=$cpu_type/$cpu_type.c; fi + +if [ x$tmake_file = x ] +then tmake_file=$cpu_type/t-$cpu_type +fi + +# Say what files are being used for the output code and MD file. +echo "Using \`$srcdir/config/$out_file' to output insns." +echo "Using \`$srcdir/config/$md_file' as machine description file." +echo "Using \`$srcdir/config/$tm_file' as target machine macro file." +echo "Using \`$srcdir/config/$host_xm_file' as host machine macro file." +if [ $host_xm_file != $build_xm_file ]; then + echo "Using \`$srcdir/config/$build_xm_file' as build machine macro file." +fi + +# Set up the list of links to be made. +# $links is the list of link names, and $files is the list of names to link to. +files="$host_xm_file $tm_file $xm_file $build_xm_file" +links="config.h tm.h tconfig.h hconfig.h" + +rm -f config.bak +if [ -f config.status ]; then mv -f config.status config.bak; fi + +# Make the links. +while [ -n "$files" ] +do + # set file to car of files, files to cdr of files + set $files; file=$1; shift; files=$* + set $links; link=$1; shift; links=$* + + rm -f $link + echo "#include \"$file\"" >$link +done + +# Truncate the target if necessary +if [ x$host_truncate_target != x ]; then + target=`echo $target | sed -e 's/\(..............\).*/\1/'` +fi + +# Get the version number from the toplevel +version=`sed -e 's/.*\"\([^ \"]*\)[ \"].*/\1/' < ${srcdir}/version.c` + +# For the current directory and all of the language subdirectories, +# do the rest of the script ... + +subdirs= +for lang in ${srcdir}/*/config-lang.in .. +do + case $lang in + ..) ;; + # The odd quoting in the next line works around + # an apparent bug in bash 1.12 on linux. + ${srcdir}/[*]/config-lang.in) ;; + *) subdirs="$subdirs `echo $lang | sed -e 's,^.*/\([^/]*\)/config-lang.in$,\1,'`" ;; + esac +done + +# Are we using gcc as the native compiler? +case $canon_host in +*linux*) # All Linux's use gcc as the native compiler. + prefix=$native_prefix + ;; +esac + +# Make empty files to contain the specs and options for each language. +# Then add #include lines to for a compiler that has specs and/or options. + +lang_specs_files= +lang_options_files= +rm -f specs.h options.h +touch specs.h options.h +for subdir in . $subdirs +do + if [ -f $srcdir/$subdir/lang-specs.h ]; then + echo "#include \"$subdir/lang-specs.h\"" >>specs.h + lang_specs_files="$lang_specs_files $srcdir/$subdir/lang-specs.h" + fi + if [ -f $srcdir/$subdir/lang-options.h ]; then + echo "#include \"$subdir/lang-options.h\"" >>options.h + lang_options_files="$lang_options_files $srcdir/$subdir/lang-options.h" + fi +done + +# Define SET_MAKE if this old version of `make' doesn't define $(MAKE). +rm -f Makefile.xx +(echo 'all:'; echo ' @echo maketemp=$(MAKE)') >Makefile.xx +case `${MAKE-make} -f Makefile.xx 2>/dev/null | grep maketemp=` in +'maketemp=') + SET_MAKE="MAKE = ${MAKE-make}" + ;; +*) + SET_MAKE= + ;; +esac +rm -f Makefile.xx + +savesrcdir=$srcdir +for subdir in . $subdirs +do + oldsrcdir=$savesrcdir + + # Re-adjust the path + case $oldsrcdir in + /*) + srcdir=$oldsrcdir/$subdir + ;; + *) + case $subdir in + .) + ;; + *) + oldsrcdir=../${oldsrcdir} + srcdir=$oldsrcdir/$subdir + ;; + esac + ;; + esac + mainsrcdir=$oldsrcdir + STARTDIR=`pwd` + test -d $subdir || mkdir $subdir + cd $subdir + + # Create Makefile.tem from Makefile.in. + # Make it set VPATH if necessary so that the sources are found. + # Also change its value of srcdir. + # Also create a .gdbinit file which runs the one in srcdir + # and tells GDB to look there for source files. + case $srcdir in + . | ./$subdir | .././$subdir) + rm -f Makefile.tem + cp Makefile.in Makefile.tem + chmod +w Makefile.tem + ;; + *) + rm -f Makefile.tem + echo "VPATH = ${srcdir}" \ + | cat - ${srcdir}/Makefile.in \ + | sed "s@^srcdir = \.@srcdir = ${srcdir}@" > Makefile.tem + rm -f .gdbinit + echo "dir ." > .gdbinit + echo "dir ${srcdir}" >> .gdbinit + if [ x$gdb_needs_out_file_path = xyes ] + then + echo "dir ${srcdir}/config/"`dirname ${out_file}` >> .gdbinit + fi + if [ "x$subdirs" != x ]; then + for s in $subdirs + do + echo "dir ${srcdir}/$s" >> .gdbinit + done + fi + echo "source ${srcdir}/.gdbinit" >> .gdbinit + ;; + esac + + # Conditionalize the makefile for this host machine. + if [ -f ${mainsrcdir}/config/${host_xmake_file} ] + then + rm -f Makefile.xx + sed -e "/####host/ r ${mainsrcdir}/config/${host_xmake_file}" Makefile.tem > Makefile.xx + echo "Merged ${host_xmake_file}." + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + dep_host_xmake_file=${host_xmake_file} + else + # Say in the makefile that there is no host_xmake_file, + # by using a name which (when interpreted relative to $srcdir/config) + # will duplicate another dependency: $srcdir/Makefile.in. + dep_host_xmake_file=../Makefile.in + fi + + # Add a definition for MAKE if system wants one. + case "$SET_MAKE" in + ?*) + rm -f Makefile.xx + (echo "$SET_MAKE"; cat Makefile.tem) >Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + esac + + # Add a definition for INSTALL if system wants one. + # This substitutes for lots of x-* files. + if [ x$host_broken_install = x ] + then true + else + rm -f Makefile.xx + abssrcdir=`cd ${srcdir}; pwd` + sed "s|^INSTALL = .*|INSTALL = ${abssrcdir}/install.sh -c|" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Some of the following don't make sense in the language makefiles, + # but rather than introduce another level of nesting, we leave them + # as is. + + # Set EXTRA_HEADERS according to extra_headers. + # This substitutes for lots of t-* files. + if [ "x$extra_headers" = x ] + then true + else + # Prepend ${srcdir}/ginclude/ to every entry in extra_headers. + list= + for file in $extra_headers; + do + list="${list} ${srcdir}/ginclude/${file}" + done + rm -f Makefile.xx + sed "s|^EXTRA_HEADERS =|EXTRA_HEADERS = ${list}|" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set EXTRA_PASSES according to extra_passes. + # This substitutes for lots of t-* files. + if [ "x$extra_passes" = x ] + then true + else + rm -f Makefile.xx + sed "s/^EXTRA_PASSES =/EXTRA_PASSES = $extra_passes/" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set EXTRA_PARTS according to extra_parts. + # This substitutes for lots of t-* files. + if [ "x$extra_parts" = x ] + then true + else + rm -f Makefile.xx + sed "s/^EXTRA_PARTS =/EXTRA_PARTS = $extra_parts/" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set EXTRA_PROGRAMS according to extra_programs. + if [ "x$extra_programs" = x ] + then true + else + rm -f Makefile.xx + sed "s/^EXTRA_PROGRAMS =/EXTRA_PROGRAMS = $extra_programs/" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set EXTRA_OBJS according to extra_objs. + # This substitutes for lots of t-* files. + if [ "x$extra_objs" = x ] + then true + else + rm -f Makefile.xx + sed "s|^EXTRA_OBJS =|EXTRA_OBJS = $extra_objs|" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set EXTRA_GCC_OBJS according to extra_gcc_objs. + # This substitutes for lots of t-* files. + if [ "x$extra_gcc_objs" = x ] + then true + else + rm -f Makefile.xx + sed "s|^EXTRA_GCC_OBJS =|EXTRA_GCC_OBJS = $extra_gcc_objs|" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Add a definition of USE_COLLECT2 if system wants one. + # Also tell toplev.c what to do. + # This substitutes for lots of t-* files. + if [ x$use_collect2 = x ] + then true + else + rm -f Makefile.xx + (echo "USE_COLLECT2 = ld"; echo "MAYBE_USE_COLLECT2 = -DUSE_COLLECT2")\ + | cat - Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Add -DTARGET_CPU_DEFAULT for toplev.c if system wants one. + # This substitutes for lots of *.h files. + if [ x$target_cpu_default = x ] + then true + else + rm -f Makefile.xx + # This used cat, but rfg@netcom.com said that ran into NFS bugs. + sed -e "/^# Makefile for GNU C compiler./c\\ +MAYBE_TARGET_DEFAULT = -DTARGET_CPU_DEFAULT=$target_cpu_default\\ +\# Makefile for GNU C compiler." Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Set MD_DEPS if the real md file is in md.pre-cpp. + # Set MD_CPP to the cpp to pass the md file through. Md files use ';' + # for line oriented comments, so we must always use a GNU cpp. If + # building gcc with a cross compiler, use the cross compiler just + # built. Otherwise, we can use the cpp just built. + if [ "x$md_cppflags" = x ] + then + md_file=$srcdir/config/$md_file + else + rm -f Makefile.xx + (if [ x$host = x$build ] ; then + echo "MD_DEPS = $(md_file) cpp" ; echo "MD_CPP = ./cpp" + else + echo "MD_DEPS = md.pre-cpp" ; echo "MD_CPP = \$(HOST_CC) -x c -E" + fi + md_file=md + echo "MD_CPPFLAGS = $md_cppflags") | \ + cat - Makefile.tem | sed -e "s|^MD_FILE[ ]*=.*|MD_FILE = md|" > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # If we have gas in the build tree, make a link to it. + if [ -f ../gas/Makefile ]; then + rm -f as; $symbolic_link ../gas/as.new as 2>/dev/null + fi + + # If we have ld in the build tree, make a link to it. + if [ -f ../ld/Makefile ]; then + if [ x$use_collect2 = x ]; then + rm -f ld; $symbolic_link ../ld/ld.new ld 2>/dev/null + else + rm -f collect-ld; $symbolic_link ../ld/ld.new collect-ld 2>/dev/null + fi + fi + + # If using -program-transform-name, override the installation names. + if [ "x${program_transform_set}" = "xyes" ] ; then + sed -e "s/^program_transform_name[ ]*=.*$/program_transform_name = $program_transform_name/" \ + -e "s/^program_transform_cross_name[ ]*=.*$/program_transform_cross_name = $program_transform_name/" \ + Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + fi + + # Conditionalize the makefile for this target machine. + if [ -f ${mainsrcdir}/config/${tmake_file} ] + then + rm -f Makefile.xx + sed -e "/####target/ r ${mainsrcdir}/config/${tmake_file}" Makefile.tem > Makefile.xx + echo "Merged ${tmake_file}." + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + dep_tmake_file=${tmake_file} + else + # Say in the makefile that there is no tmake_file, + # by using a name which (when interpreted relative to $srcdir/config) + # will duplicate another dependency: $srcdir/Makefile.in. + dep_tmake_file=../Makefile.in + fi + + # If this is the top level Makefile, add the language fragments. + # Languages are added via two mechanisms. Some information must be + # recorded in makefile variables, these are defined in config-lang.in. + # We accumulate them and plug them into the main Makefile. + # The other mechanism is a set of hooks for each of the main targets + # like `clean', `install', etc. + if [ $subdir = . ] + then + # These (without "all_") are set in each config-lang.in. + # `language' must be a single word so is spelled singularly. + all_languages= + all_compilers= + all_stagestuff= + all_diff_excludes= + # List of language makefile fragments. + all_lang_makefiles= + + rm -f Makefile.xx Makefile.ll + touch Makefile.ll + for s in .. $subdirs + do + if [ $s != ".." ] + then + language= + compilers= + stagestuff= + diff_excludes= + . ${mainsrcdir}/$s/config-lang.in + if [ "x$language" = x ] + then + echo "${mainsrcdir}/$s/config-lang.in doesn't set \$language." 1>&2 + exit 1 + fi + all_lang_makefiles="$all_lang_makefiles ${mainsrcdir}/$s/Make-lang.in ${mainsrcdir}/$s/Makefile.in" + all_languages="$all_languages $language" + all_compilers="$all_compilers $compilers" + all_stagestuff="$all_stagestuff $stagestuff" + all_diff_excludes="$all_diff_excludes $diff_excludes" + + cat ${mainsrcdir}/$s/Make-lang.in >> Makefile.ll + fi + done + sed -e "/####language fragments/ r Makefile.ll" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + sed -e "s|^SUBDIRS[ ]*=.*$|SUBDIRS = $subdirs|" \ + -e "s|^LANGUAGES[ ]*=[ ]*\(.*\)$|LANGUAGES = \1 $all_languages|" \ + -e "s|^COMPILERS[ ]*=[ ]*\(.*\)$|COMPILERS = \1 $all_compilers|" \ + -e "s|^LANG_MAKEFILES[ ]*=.*$|LANG_MAKEFILES = $all_lang_makefiles|" \ + -e "s|^LANG_STAGESTUFF[ ]*=.*$|LANG_STAGESTUFF = $all_stagestuff|" \ + -e "s|^LANG_DIFF_EXCLUDES[ ]*=.*$|LANG_DIFF_EXCLUDES = $all_diff_excludes|" \ + Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + + # Since we can't use `::' targets, we link each language in + # with a set of hooks, reached indirectly via lang.${target}. + + target_list="all.build all.cross start.encap rest.encap \ + info dvi \ + install-normal install-common install-info install-man \ + uninstall distdir \ + mostlyclean clean distclean extraclean maintainer-clean \ + stage1 stage2 stage3 stage4" + rm -f Makefile.ll + for t in $target_list + do + x= + for l in .. $all_languages + do + if [ $l != ".." ]; then + x="$x $l.$t" + fi + done + echo "lang.$t: $x" >> Makefile.ll + done + sed -e "/####language hooks/ r Makefile.ll" Makefile.tem > Makefile.xx + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + rm -f Makefile.ll + + # If the host doesn't support symlinks, modify CC in + # FLAGS_TO_PASS so CC="stage1/xgcc -Bstage1/" works. + # Otherwise, we can use "CC=$(CC)". + rm -f symtest.tem + if $symbolic_link symtest1.tem symtest.tem 2>/dev/null + then + sed -e 's,CC=set-by-configure,CC=$(CC),' \ + Makefile.tem > Makefile.xx + else + sed -e "s,CC=set-by-configure,CC=\`case '$(CC)' in stage*) echo '$(CC)' | sed -e 's|stage|../stage|g';; *) echo '$(CC)';; esac\`," \ + Makefile.tem > Makefile.xx + fi + rm -f Makefile.tem + mv Makefile.xx Makefile.tem + rm -f symtest.tem + + if [ "x$all_languages" != x ] + then + # Missing space after `Merged' is intentional. + echo "Merged$all_languages fragment(s)." + fi + + # Otherwise, this is a language subdirectory. If the host supports + # symlinks, point stage[123] at ../stage[123] so bootstrapping and the + # installation procedure can still use CC="stage1/xgcc -Bstage1/". + # If the host doesn't support symlinks, FLAGS_TO_PASS has been + # modified to solve the problem there. + else + for t in stage1 stage2 stage3 stage4 include + do + rm -f $t + $symbolic_link ../$t $t 2>/dev/null + done + fi + + out_object_file=`basename $out_file .c`.o + + # Remove all formfeeds, since some Makes get confused by them. + # Also arrange to give the variables `target', `host_xmake_file', + # `tmake_file', `prefix', `local_prefix', `exec_prefix', `FIXINCLUDES' + # `out_file', `out_object', `md_file', `lang_specs_files', + # `lang_options_files', and `INSTALL_HEADERS_DIR' values in the + # Makefile from the values they have in this script. + rm -f Makefile.xx + rm -f aux-output.c aux-output.o md + # Create an empty Makefile.sed first, to work around a Nextstep 3.3 bug. + echo 's| ||' > Makefile.sed + rm Makefile.sed + echo 's| ||' > Makefile.sed + echo "s|^target=.*$|target=${target}|" >> Makefile.sed + echo "s|^xmake_file=.*$|xmake_file=${dep_host_xmake_file}|" >> Makefile.sed + echo "s|^tmake_file=.*$|tmake_file=${dep_tmake_file}|" >> Makefile.sed + echo "s|^version=.*$|version=${version}|" >> Makefile.sed + echo "s|^version=.*$|version=${version}|" >> Makefile.sed + echo "s|^out_file=.*$|out_file=${srcdir}/config/${out_file}|" >> Makefile.sed + echo "s|^out_object_file=.*$|out_object_file=${out_object_file}|" >> Makefile.sed + echo "s|^md_file=.*$|md_file=${md_file}|" >> Makefile.sed + echo "s|^tm_file=.*$|tm_file=${srcdir}/config/${tm_file}|" >> Makefile.sed + echo "s|^host_xm_file=.*$|host_xm_file=${srcdir}/config/${host_xm_file}|" >> Makefile.sed + echo "s|^build_xm_file=.*$|build_xm_file=${srcdir}/config/${build_xm_file}|" >> Makefile.sed + echo "s|^lang_specs_files=.*$|lang_specs_files=${lang_specs_files}|" >> Makefile.sed + echo "s|^lang_options_files=.*$|lang_options_files=${lang_options_files}|" >> Makefile.sed + echo "s|^prefix[ ]*=.*|prefix = $prefix|" >> Makefile.sed + echo "s|^gxx_include_dir[ ]*=.*|gxx_include_dir = $gxx_include_dir|" >> Makefile.sed + echo "s|^local_prefix[ ]*=.*|local_prefix = $local_prefix|" >> Makefile.sed + echo "s|^exec_prefix[ ]*=.*|exec_prefix = $exec_prefix|" >> Makefile.sed + echo "s|^FIXINCLUDES[ ]*=.*|FIXINCLUDES = $fixincludes|" >> Makefile.sed + echo "s|^INSTALL_HEADERS_DIR[ ]*=.*$|INSTALL_HEADERS_DIR = ${host_install_headers_dir}|" >> Makefile.sed + sed -f Makefile.sed Makefile.tem > Makefile.xx + rm -f Makefile.tem Makefile.sed + mv Makefile.xx Makefile.tem + + # Install Makefile for real, after making final changes. + # Define macro CROSS_COMPILE in compilation if this is a cross-compiler. + # Also use all.cross instead of all.internal, and add cross-make to Makefile. + if [ x$canon_host = x$canon_target ] + then + rm -f Makefile + if [ x$canon_host = x$canon_build ] + then + mv Makefile.tem Makefile + else + # When building gcc with a cross-compiler, we need to fix a + # few things. + echo "build= $build" > Makefile + sed -e "s|objc-runtime$||" \ + -e "/####build/ r ${mainsrcdir}/build-make" Makefile.tem >> Makefile + rm -f Makefile.tem Makefile.xx + fi + else + rm -f Makefile + echo "CROSS=-DCROSS_COMPILE" > Makefile + sed -e "/####cross/ r ${mainsrcdir}/cross-make" Makefile.tem >> Makefile + rm -f Makefile.tem Makefile.xx + fi + + echo "Created \`$subdir/Makefile'." + + # If a subdirectory has a configure script, run it. + if [ x$subdir != x. ] + then + if [ -f $srcdir/configure ] + then + ${CONFIG_SHELL-sh} $srcdir/configure $arguments --srcdir=$srcdir + fi + fi + + cd $STARTDIR +done # end of current-dir SUBDIRS loop + +srcdir=$savesrcdir + +# Describe the chosen configuration in config.status. +# Make that file a shellscript which will reestablish the same configuration. +echo "#!/bin/sh +# GCC was configured as follows: +${srcdir}/configure" $arguments > config.new +echo echo host=$canon_host target=$canon_target build=$canon_build >> config.new +chmod a+x config.new +if [ -f config.bak ] && cmp config.bak config.new >/dev/null 2>/dev/null; +then + mv -f config.bak config.status + rm -f config.new +else + mv -f config.new config.status + rm -f config.bak +fi + +str2= +str3= +str4=. + +if [ x$canon_host = x$canon_target ] +then + str1="native " +else + str1="cross-" + str2=" from $canon_host" +fi + +if [ x$canon_host != x$canon_build ] +then + str3=" on a $canon_build system" +fi + +if [ "x$str2" != x ] || [ "x$str3" != x ] +then + str4= +fi + +echo "Links are now set up to build a ${str1}compiler for ${canon_target}$str4" 1>&2 + +if [ "x$str2" != x ] || [ "x$str3" != x ] +then + echo " ${str2}${str3}." 1>&2 +fi + +exit 0 diff --git a/contrib/gcc/convert.c b/contrib/gcc/convert.c new file mode 100644 index 00000000000..17e755243af --- /dev/null +++ b/contrib/gcc/convert.c @@ -0,0 +1,472 @@ +/* Utility routines for data type conversion for GNU C. + Copyright (C) 1987, 88, 91, 92, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU C. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* These routines are somewhat language-independent utility function + intended to be called by the language-specific convert () functions. */ + +#include "config.h" +#include "tree.h" +#include "flags.h" +#include "convert.h" + +/* Convert EXPR to some pointer or reference type TYPE. + + EXPR must be pointer, reference, integer, enumeral, or literal zero; + in other cases error is called. */ + +tree +convert_to_pointer (type, expr) + tree type, expr; +{ + register tree intype = TREE_TYPE (expr); + register enum tree_code form = TREE_CODE (intype); + + if (integer_zerop (expr)) + { + expr = build_int_2 (0, 0); + TREE_TYPE (expr) = type; + return expr; + } + + if (form == POINTER_TYPE || form == REFERENCE_TYPE) + return build1 (NOP_EXPR, type, expr); + + + if (form == INTEGER_TYPE || form == ENUMERAL_TYPE) + { + if (type_precision (intype) == POINTER_SIZE) + return build1 (CONVERT_EXPR, type, expr); + expr = convert (type_for_size (POINTER_SIZE, 0), expr); + /* Modes may be different but sizes should be the same. */ + if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr))) + != GET_MODE_SIZE (TYPE_MODE (type))) + /* There is supposed to be some integral type + that is the same width as a pointer. */ + abort (); + return convert_to_pointer (type, expr); + } + + error ("cannot convert to a pointer type"); + + expr = build_int_2 (0, 0); + TREE_TYPE (expr) = type; + return expr; +} + +/* Convert EXPR to some floating-point type TYPE. + + EXPR must be float, integer, or enumeral; + in other cases error is called. */ + +tree +convert_to_real (type, expr) + tree type, expr; +{ + register enum tree_code form = TREE_CODE (TREE_TYPE (expr)); + + if (form == REAL_TYPE) + return build1 (flag_float_store ? CONVERT_EXPR : NOP_EXPR, + type, expr); + + if (INTEGRAL_TYPE_P (TREE_TYPE (expr))) + return build1 (FLOAT_EXPR, type, expr); + + if (form == COMPLEX_TYPE) + return convert (type, fold (build1 (REALPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), expr))); + + if (form == POINTER_TYPE || form == REFERENCE_TYPE) + error ("pointer value used where a floating point value was expected"); + else + error ("aggregate value used where a float was expected"); + + { + register tree tem = make_node (REAL_CST); + TREE_TYPE (tem) = type; + TREE_REAL_CST (tem) = REAL_VALUE_ATOF ("0.0", TYPE_MODE (type)); + return tem; + } +} + +/* Convert EXPR to some integer (or enum) type TYPE. + + EXPR must be pointer, integer, discrete (enum, char, or bool), or float; + in other cases error is called. + + The result of this is always supposed to be a newly created tree node + not in use in any existing structure. */ + +tree +convert_to_integer (type, expr) + tree type, expr; +{ + register tree intype = TREE_TYPE (expr); + register enum tree_code form = TREE_CODE (intype); + + if (form == POINTER_TYPE || form == REFERENCE_TYPE) + { + if (integer_zerop (expr)) + expr = integer_zero_node; + else + expr = fold (build1 (CONVERT_EXPR, + type_for_size (POINTER_SIZE, 0), expr)); + intype = TREE_TYPE (expr); + form = TREE_CODE (intype); + if (intype == type) + return expr; + } + + if (form == INTEGER_TYPE || form == ENUMERAL_TYPE + || form == BOOLEAN_TYPE || form == CHAR_TYPE) + { + register unsigned outprec = TYPE_PRECISION (type); + register unsigned inprec = TYPE_PRECISION (intype); + register enum tree_code ex_form = TREE_CODE (expr); + + /* If we are widening the type, put in an explicit conversion. + Similarly if we are not changing the width. However, if this is + a logical operation that just returns 0 or 1, we can change the + type of the expression. For logical operations, we must + also change the types of the operands to maintain type + correctness. */ + + if (TREE_CODE_CLASS (ex_form) == '<') + { + TREE_TYPE (expr) = type; + return expr; + } + else if (ex_form == TRUTH_AND_EXPR || ex_form == TRUTH_ANDIF_EXPR + || ex_form == TRUTH_OR_EXPR || ex_form == TRUTH_ORIF_EXPR + || ex_form == TRUTH_XOR_EXPR) + { + TREE_OPERAND (expr, 0) = convert (type, TREE_OPERAND (expr, 0)); + TREE_OPERAND (expr, 1) = convert (type, TREE_OPERAND (expr, 1)); + TREE_TYPE (expr) = type; + return expr; + } + else if (ex_form == TRUTH_NOT_EXPR) + { + TREE_OPERAND (expr, 0) = convert (type, TREE_OPERAND (expr, 0)); + TREE_TYPE (expr) = type; + return expr; + } + else if (outprec >= inprec) + return build1 (NOP_EXPR, type, expr); + + /* If TYPE is an enumeral type or a type with a precision less + than the number of bits in its mode, do the conversion to the + type corresponding to its mode, then do a nop conversion + to TYPE. */ + else if (TREE_CODE (type) == ENUMERAL_TYPE + || outprec != GET_MODE_BITSIZE (TYPE_MODE (type))) + return build1 (NOP_EXPR, type, + convert (type_for_mode (TYPE_MODE (type), + TREE_UNSIGNED (type)), + expr)); + + /* Here detect when we can distribute the truncation down past some + arithmetic. For example, if adding two longs and converting to an + int, we can equally well convert both to ints and then add. + For the operations handled here, such truncation distribution + is always safe. + It is desirable in these cases: + 1) when truncating down to full-word from a larger size + 2) when truncating takes no work. + 3) when at least one operand of the arithmetic has been extended + (as by C's default conversions). In this case we need two conversions + if we do the arithmetic as already requested, so we might as well + truncate both and then combine. Perhaps that way we need only one. + + Note that in general we cannot do the arithmetic in a type + shorter than the desired result of conversion, even if the operands + are both extended from a shorter type, because they might overflow + if combined in that type. The exceptions to this--the times when + two narrow values can be combined in their narrow type even to + make a wider result--are handled by "shorten" in build_binary_op. */ + + switch (ex_form) + { + case RSHIFT_EXPR: + /* We can pass truncation down through right shifting + when the shift count is a nonpositive constant. */ + if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST + && tree_int_cst_lt (TREE_OPERAND (expr, 1), + convert (TREE_TYPE (TREE_OPERAND (expr, 1)), + integer_one_node))) + goto trunc1; + break; + + case LSHIFT_EXPR: + /* We can pass truncation down through left shifting + when the shift count is a nonnegative constant. */ + if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST + && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) >= 0 + && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) + { + /* If shift count is less than the width of the truncated type, + really shift. */ + if (tree_int_cst_lt (TREE_OPERAND (expr, 1), TYPE_SIZE (type))) + /* In this case, shifting is like multiplication. */ + goto trunc1; + else + { + /* If it is >= that width, result is zero. + Handling this with trunc1 would give the wrong result: + (int) ((long long) a << 32) is well defined (as 0) + but (int) a << 32 is undefined and would get a + warning. */ + + tree t = convert_to_integer (type, integer_zero_node); + + /* If the original expression had side-effects, we must + preserve it. */ + if (TREE_SIDE_EFFECTS (expr)) + return build (COMPOUND_EXPR, type, expr, t); + else + return t; + } + } + break; + + case MAX_EXPR: + case MIN_EXPR: + case MULT_EXPR: + { + tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), type); + tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type); + + /* Don't distribute unless the output precision is at least as big + as the actual inputs. Otherwise, the comparison of the + truncated values will be wrong. */ + if (outprec >= TYPE_PRECISION (TREE_TYPE (arg0)) + && outprec >= TYPE_PRECISION (TREE_TYPE (arg1)) + /* If signedness of arg0 and arg1 don't match, + we can't necessarily find a type to compare them in. */ + && (TREE_UNSIGNED (TREE_TYPE (arg0)) + == TREE_UNSIGNED (TREE_TYPE (arg1)))) + goto trunc1; + break; + } + + case PLUS_EXPR: + case MINUS_EXPR: + case BIT_AND_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + case BIT_ANDTC_EXPR: + trunc1: + { + tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), type); + tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type); + + if (outprec >= BITS_PER_WORD + || TRULY_NOOP_TRUNCATION (outprec, inprec) + || inprec > TYPE_PRECISION (TREE_TYPE (arg0)) + || inprec > TYPE_PRECISION (TREE_TYPE (arg1))) + { + /* Do the arithmetic in type TYPEX, + then convert result to TYPE. */ + register tree typex = type; + + /* Can't do arithmetic in enumeral types + so use an integer type that will hold the values. */ + if (TREE_CODE (typex) == ENUMERAL_TYPE) + typex = type_for_size (TYPE_PRECISION (typex), + TREE_UNSIGNED (typex)); + + /* But now perhaps TYPEX is as wide as INPREC. + In that case, do nothing special here. + (Otherwise would recurse infinitely in convert. */ + if (TYPE_PRECISION (typex) != inprec) + { + /* Don't do unsigned arithmetic where signed was wanted, + or vice versa. + Exception: if either of the original operands were + unsigned then can safely do the work as unsigned. + And we may need to do it as unsigned + if we truncate to the original size. */ + typex = ((TREE_UNSIGNED (TREE_TYPE (expr)) + || TREE_UNSIGNED (TREE_TYPE (arg0)) + || TREE_UNSIGNED (TREE_TYPE (arg1))) + ? unsigned_type (typex) : signed_type (typex)); + return convert (type, + fold (build (ex_form, typex, + convert (typex, arg0), + convert (typex, arg1), + 0))); + } + } + } + break; + + case NEGATE_EXPR: + case BIT_NOT_EXPR: + /* This is not correct for ABS_EXPR, + since we must test the sign before truncation. */ + { + register tree typex = type; + + /* Can't do arithmetic in enumeral types + so use an integer type that will hold the values. */ + if (TREE_CODE (typex) == ENUMERAL_TYPE) + typex = type_for_size (TYPE_PRECISION (typex), + TREE_UNSIGNED (typex)); + + /* But now perhaps TYPEX is as wide as INPREC. + In that case, do nothing special here. + (Otherwise would recurse infinitely in convert. */ + if (TYPE_PRECISION (typex) != inprec) + { + /* Don't do unsigned arithmetic where signed was wanted, + or vice versa. */ + typex = (TREE_UNSIGNED (TREE_TYPE (expr)) + ? unsigned_type (typex) : signed_type (typex)); + return convert (type, + fold (build1 (ex_form, typex, + convert (typex, + TREE_OPERAND (expr, 0))))); + } + } + + case NOP_EXPR: + /* If truncating after truncating, might as well do all at once. + If truncating after extending, we may get rid of wasted work. */ + return convert (type, get_unwidened (TREE_OPERAND (expr, 0), type)); + + case COND_EXPR: + /* Can treat the two alternative values like the operands + of an arithmetic expression. */ + { + tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type); + tree arg2 = get_unwidened (TREE_OPERAND (expr, 2), type); + + if (outprec >= BITS_PER_WORD + || TRULY_NOOP_TRUNCATION (outprec, inprec) + || inprec > TYPE_PRECISION (TREE_TYPE (arg1)) + || inprec > TYPE_PRECISION (TREE_TYPE (arg2))) + { + /* Do the arithmetic in type TYPEX, + then convert result to TYPE. */ + register tree typex = type; + + /* Can't do arithmetic in enumeral types + so use an integer type that will hold the values. */ + if (TREE_CODE (typex) == ENUMERAL_TYPE) + typex = type_for_size (TYPE_PRECISION (typex), + TREE_UNSIGNED (typex)); + + /* But now perhaps TYPEX is as wide as INPREC. + In that case, do nothing special here. + (Otherwise would recurse infinitely in convert. */ + if (TYPE_PRECISION (typex) != inprec) + { + /* Don't do unsigned arithmetic where signed was wanted, + or vice versa. */ + typex = (TREE_UNSIGNED (TREE_TYPE (expr)) + ? unsigned_type (typex) : signed_type (typex)); + return convert (type, + fold (build (COND_EXPR, typex, + TREE_OPERAND (expr, 0), + convert (typex, arg1), + convert (typex, arg2)))); + } + else + /* It is sometimes worthwhile + to push the narrowing down through the conditional. */ + return fold (build (COND_EXPR, type, + TREE_OPERAND (expr, 0), + convert (type, TREE_OPERAND (expr, 1)), + convert (type, TREE_OPERAND (expr, 2)))); + } + } + + } + + return build1 (NOP_EXPR, type, expr); + } + + if (form == REAL_TYPE) + return build1 (FIX_TRUNC_EXPR, type, expr); + + if (form == COMPLEX_TYPE) + return convert (type, fold (build1 (REALPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), expr))); + + error ("aggregate value used where an integer was expected"); + + { + register tree tem = build_int_2 (0, 0); + TREE_TYPE (tem) = type; + return tem; + } +} + +/* Convert EXPR to the complex type TYPE in the usual ways. */ + +tree +convert_to_complex (type, expr) + tree type, expr; +{ + register enum tree_code form = TREE_CODE (TREE_TYPE (expr)); + tree subtype = TREE_TYPE (type); + + if (form == REAL_TYPE || form == INTEGER_TYPE || form == ENUMERAL_TYPE) + { + expr = convert (subtype, expr); + return build (COMPLEX_EXPR, type, expr, + convert (subtype, integer_zero_node)); + } + + if (form == COMPLEX_TYPE) + { + tree elt_type = TREE_TYPE (TREE_TYPE (expr)); + if (TYPE_MAIN_VARIANT (elt_type) == TYPE_MAIN_VARIANT (subtype)) + return expr; + else if (TREE_CODE (expr) == COMPLEX_EXPR) + return fold (build (COMPLEX_EXPR, + type, + convert (subtype, TREE_OPERAND (expr, 0)), + convert (subtype, TREE_OPERAND (expr, 1)))); + else + { + expr = save_expr (expr); + return fold (build (COMPLEX_EXPR, + type, + convert (subtype, + fold (build1 (REALPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr))), + convert (subtype, + fold (build1 (IMAGPART_EXPR, + TREE_TYPE (TREE_TYPE (expr)), + expr))))); + } + } + + if (form == POINTER_TYPE || form == REFERENCE_TYPE) + error ("pointer value used where a complex was expected"); + else + error ("aggregate value used where a complex was expected"); + + return build (COMPLEX_EXPR, type, + convert (subtype, integer_zero_node), + convert (subtype, integer_zero_node)); +} diff --git a/contrib/gcc/convert.h b/contrib/gcc/convert.h new file mode 100644 index 00000000000..4123874fbb3 --- /dev/null +++ b/contrib/gcc/convert.h @@ -0,0 +1,24 @@ +/* Definition of functions in convert.c. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +extern tree convert_to_integer PROTO ((tree, tree)); +extern tree convert_to_pointer PROTO ((tree, tree)); +extern tree convert_to_real PROTO ((tree, tree)); +extern tree convert_to_complex PROTO ((tree, tree)); diff --git a/contrib/gcc/cp/ChangeLog b/contrib/gcc/cp/ChangeLog new file mode 100644 index 00000000000..d2ef74f206f --- /dev/null +++ b/contrib/gcc/cp/ChangeLog @@ -0,0 +1,9459 @@ +Mon Nov 20 14:06:28 1995 Mike Stump + + * Version 2.7.2 released. + +Mon Nov 20 14:05:00 1995 Mike Stump + + * g++.c (pfatal_with_name): Add missing third argument to concat. + +Thu Oct 26 13:59:54 1995 Mike Stump + + * init.c (expand_aggr_init): Handle cv qualifiers on the object's + type. + +Sun Nov 12 18:09:35 1995 Mike Stump + + * Version 2.7.1 released. + +Thu Nov 2 17:02:47 1995 Jason Merrill + + * call.c (convert_harshness): Handle references to arrays. + +Fri Oct 27 14:20:21 1995 Jason Merrill + + * typeck.c (comp_target_types): Check multi-level pointer + conversions in both directions. + +Tue Oct 17 21:39:05 1995 Jason Merrill + + * parse.y (explicit_instantiation): Fix 'extern template' with no + return type. + +Mon Oct 16 14:35:20 1995 Jason Merrill + + * parse.y (explicit_instantiation): Support automatic instantiation + of constructors. + (named_class_head_*): Support out-of-class definition of nested + types. + +Wed Oct 11 12:20:56 1995 Mike Stump + + * search.c (envelope_add_decl): New routine. Fix so that + methods are hidden in the same way that other members are. + (dfs_pushdecls): Cleanup and move functionality out of line, + into envelope_add_decl. + +Tue Oct 10 15:46:01 1995 Mike Stump + + * typeck.c (mark_addressable): Only call assemble_external if we + have started the output file. + +Tue Oct 10 11:27:18 1995 Jason Merrill + + * decl.c (start_function): Fix earlier cv-quals change. + +Mon Oct 9 23:53:05 1995 Mike Stump + + * parse.y (complex_direct_notype_declarator): Only push the class if + we are not already in the class. + +Mon Oct 9 11:22:03 1995 Doug Evans + + * decl.c (duplicate_decls): Call merge_machine_decl_attributes. + Update olddecl's attributes too. + (grokdeclarator): #if 0 out call to build_decl_attribute_variant. + * typeck.c (common_type): Call merge_machine_type_attributes. + +Fri Oct 6 14:44:27 1995 Mike Stump + + * typeck.c (mark_addressable): Add missing call to + assemble_external. + +Wed Oct 4 22:05:23 1995 Jeff Law (law@hurl.cygnus.com + + * cp/decl.c (deplicate_decls): Merge in deferred output + status for variables. + * cp/tree.c (tree_copy_lang_decl_for_deferred_output): New + function to copy the g++ specific parts of a DECL node. + (tree_copy_lang_type_for_deferred_output): Similarly for + TYPE nodes. + +Wed Oct 4 15:06:39 1995 Mike Stump + + * decl.c (store_parm_decls): Make sure the unwinder start comes + before the exception specification start. + * except.c (expand_exception_blocks): Make sure the unwinder end + comes after the terminate protected catch clause region and after + the end of the exception specification region. + +Wed Oct 4 12:47:02 1995 Jason Merrill + + * lex.c (real_yylex): Fix identifier case for linemode. + (handle_sysv_pragma): Don't abort when we see a pragma we don't + recognize. + +Tue Oct 3 14:09:46 1995 Mike Stump + + * decl.c (store_parm_decls): Add a call to start_eh_unwinder. + * except.c (init_exception_processing): __throw doesn't take any + arguments. + (expand_builtin_throw): Ditto. Always use Pmode, instead of SImode + for all pointers. Use expand_builtin_return_addr to unwind the + first level off the stack. + (do_unwind): Always use Pmode, instead of SImode for all pointers. + (expand_exception_blocks): Add a call to end_eh_unwinder. + (start_eh_unwinder, end_eh_unwinder): New routines to build machine + independent stack unwinders for function/method calls. + +Mon Oct 2 17:20:42 1995 Mike Stump + + * tree.c (unsave_expr_now): Make sure we process the argument list + of any called functions. Fixes incorrect code generation for + cleanups. + +Mon Oct 2 13:04:16 1995 Mike Stump + + * typeck.c (get_member_function_from_ptrfunc): Save function if it + needs it. Cures core dump on things like (this->*(f()))(). + +Sat Sep 23 22:51:25 1995 Jason Merrill + + * decl.c (start_function): Conform to gcc cv-quals convention (no + expression has a cv-qualified type) in RESULT_DECLs. + * method.c (make_thunk): Ditto. + +Fri Sep 22 10:21:13 1995 Mike Stump + + * decl.c (pushtag): Add in the namespace name for the tag. + +Thu Sep 21 13:11:13 1995 Mike Stump + + * parse.y (maybe_base_class_list, base_class_list, base_class, + base_class_access_list): Make sure we see the typenames for base + classes. + * lex.c (see_typename): Instead of failing to see a typename when + there is no next token, perfer a typename, and get the next token. + +Wed Sep 20 12:35:27 1995 Michael Meissner + + * decl.c (init_decl_processing): Add __builtin_expect. + +Tue Sep 19 16:48:11 1995 Mike Stump + + * cvt.c (cp_convert_to_pointer): Don't allow leftover conversions to + or from pointer to member functions, they must all be handled before + this point. + +Fri Sep 15 17:14:47 1995 Brendan Kehoe + + * init.c (resolve_offset_ref): Fix wording of non-static member + being referenced as a static. + +Fri Sep 15 12:39:11 1995 Jason Merrill + + * typeck.c (build_indirect_ref): Only bash pointer if we actually + call build_expr_type_conversion. + +Thu Sep 14 18:24:56 1995 Jason Merrill + + * cvt.c (build_expr_type_conversion): Handle conversion from + reference. + * typeck.c (build_indirect_ref): Avoid infinite recursion. + +Thu Sep 14 17:23:28 1995 Mike Stump + + * decl.c (expand_start_early_try_stmts): New routine to start a try + block at the start of the function, for function-try-blocks. + * cp-tree.h (expand_start_early_try_stmts): Declare it. + * parse.y (function_try_block): Use it, instead of doing it here, as + we don't want to include rtl.h here, as that conflicts with RETURN + in the parser. + +Wed Sep 13 18:32:24 1995 Mike Stump + + * lex.c (reinit_parse_for_block): Support saving inline + function-try-blocks, uses peekyylex. + * parse.y (eat_saved_input): New rule, permit the parser to see that + END_OF_SAVED_INPUT is ok, as it can see this when parsing the + handlers of a function-try-block. + (fndef): Use it. + (component_decl): Make sure TRY and RETURN can come after fn.def2. + * spew.c (peekyylex): New routine to peek at what will come next. + +Wed Sep 13 16:52:06 1995 Jason Merrill + + * typeck.c (comptypes): Tighten up comparisons of template type + parms. + + * decl.c (duplicate_decls): Turn off whining about virtual functions + redeclared inline for now. + +Wed Sep 13 11:13:40 1995 Mike Stump + + * decl.c (store_in_parms): New routine to put things before we + put base inits. + * cp-tree.h (store_in_parms): Declare it. + * decl.c (store_parm_decls): Use it to makr sure the starting of the + eh spec comes before base inits. + (finish_function): Use sequences instead of the obsolete + reorder_insns. + * parse.y (fndef): Enhance readability and maintainability. Update + to include function_try_block syntax. + (function_try_block): Add. + +Tue Sep 12 17:43:07 1995 Brendan Kehoe + + * call.c (convert_harshness): Use comptypes, not ==, to check if + TYPE and PARMTYPE are equivalent on a function type. + +Tue Sep 12 17:31:33 1995 Douglas Rupp (drupp@cs.washington.edu) + + * Make-lang.in (cc1plus) : Removed unnecessary $(exeext). + +Mon Sep 11 23:24:07 1995 Mike Stump + + * except.c (expand_throw): Never allocate storage for thrown pointer + to objects. + +Mon Sep 11 19:36:45 1995 Mike Stump + + * except.c (expand_start_catch_block): Pointers to objects come + back from catch matching already dereferenced, don't dereference + again. + +Mon Sep 11 15:46:28 1995 Mike Stump + + * except.c (expand_throw): Only decay the throw expression, don't do + any default conversions. This is so that one can throw and catch + characters, and not have them match integers. + +Mon Sep 11 13:46:45 1995 Mike Stump + + * error.c (dump_aggr_type): Deal with anonymous unions that don't + have a TYPE_NAME. + +Fri Sep 8 20:40:27 1995 Brendan Kehoe + + * lex.c (handle_sysv_pragma): Deal with getting a comma from yylex. + +Fri Sep 8 15:51:41 1995 Mike Stump + + * except.c (expand_end_eh_spec): Handle empty EH specifications. + +Fri Sep 8 15:27:22 1995 Mike Stump + + * cp-tree.h (expand_start_eh_spec): Declare new routine. + (expand_end_eh_spec): Ditto. + * decl.c (store_parm_decls): Call expand_start_eh_spec to process + exception specifications. + * except.c (expand_leftover_cleanups): Remove unused parameter. + (expand_end_catch_block): Ditto. + (expand_exception_blocks): Ditto. + (expand_start_eh_spec): New routine to mark the start of an + exception specification region. + (expand_end_eh_spec): New routine to mark the end of an exception + specification region. + (expand_exception_blocks): Call expand_end_eh_spec to process + exception specifications. + +Fri Sep 8 14:40:48 1995 Per Bothner + + * lex.c (do_identifier): Use global binding in preference of + dead for local variable. + +Wed Sep 6 19:32:59 1995 Mike Stump + + * cp-tree.h (build_exception_variant): Remove used first argument. + * decl.c (duplicate_decls): Ditto. + (grokfndecl): Ditto. + (revert_static_member_fn): Ditto. + * decl2.c (grok_method_quals): Ditto. + * tree.c (build_exception_variant): Ditto. + * typeck.c (common_type): Ditto. + * decl2.c (grokclassfn): After changing the type, call + build_exception_variant, if necessary. + +Tue Sep 5 15:56:27 1995 Mike Stump + + * except.c (expand_throw): Run cleanups for the throw expression. + +Wed Aug 30 15:24:38 1995 Stephen L. Favor (sfavor@tigger.intecom.com) + + * except.c (expand_builtin_throw): Moved gen_label_rtx calls beyond + the store_parm_decls call which does initialization in the emit_* + code concerning label numbering. + +Thu Aug 31 09:01:07 1995 Mike Stump + + * except.c (expand_internal_throw): Let the frontend be responsible + for managing all frontend EH parameters, the backend routine only + needs to deal with backend values. type and value are no longer + passed to __throw. + (init_exception_processing): Ditto. + (expand_start_all_catch): Ditto. + (expand_end_all_catch): Ditto. + (expand_leftover_cleanups): Ditto. + (expand_end_catch_block): Ditto. + (expand_builtin_throw): Ditto. + (expand_throw): Ditto. + +Tue Aug 29 15:04:36 1995 Jason Merrill + + * cp-tree.h (DECL_REAL_CONTEXT): Give the real declaration context + for a decl. + * decl.c (cp_finish_decl): Use it. + +Tue Aug 29 10:30:27 1995 Mike Stump + + * except.c (expand_internal_throw): Oops, almost forgot type and + value are now trees. + +Mon Aug 28 17:57:45 1995 Brendan Kehoe + + Fix the attribute handling to make sure they get noted before we + create the function's RTL, in case they can affect that. + * decl.c (grokfndecl): New arg ATTRLIST. Run + cplus_decl_attributes before creating the decl's rtl. + (grokdeclarator): New arg ATTRLIST, passed down into grokfndecl. + (shadow_tag, groktypename, start_decl, start_method): Pass a + NULL_TREE to grokdeclarator's new last arg. + * decl2.c (grokfield): New arg ATTRLIST, passed into grokdeclarator. + (grokbitfield, grokoptypename): Pass a NULL_TREE to + grokdeclarator's new last arg. + * except.c (expand_start_catch_block): Likewise. + * pt.c (process_template_parm, end_template_decl, + do_function_instantiation): Likewise. + * cp-tree.h (grokfield): Add arg. + (grokdeclarator): Move the prototype from here... + * decl.h: ...to here. + * lex.c (cons_up_default_function): Pass NULL_TREE to grokfield + ATTRLIST argument. + * parse.y: Create a list for the grokfield arg where appropriate, + and pass it down instead of calling cplus_decl_attributes. + +Mon Aug 28 15:07:24 1995 Mike Stump + + * except.c: Always allow turning on exception handling. Allow cross + compilations to use EH. + +Thu Aug 24 17:39:24 1995 Mike Stump + + * except.c (saved_pc, saved_throw_type, saved_throw_value): Use + trees, instead of rtxs, and don't depend on using special machine + dependent registers. + (expand_internal_throw): Ditto. + (init_exception_processing): Ditto. + (expand_start_all_catch): Ditto. + (expand_end_all_catch): Ditto. + (expand_start_catch_block): Ditto. + (expand_leftover_cleanups): Ditto. + (expand_end_catch_block): Ditto. + (expand_builtin_throw): Ditto. + (expand_throw): Ditto. + +Wed Aug 23 17:25:51 1995 Jason Merrill + + * cvt.c (build_expr_type_conversion): Handle conversions to + reference types. + +Wed Aug 23 15:33:59 1995 Mike Stump + + * except.c (do_unwind): Work around backend bug with -fpic. + +Tue Aug 22 17:20:07 1995 Per Bothner + + * decl2.c (flag_new_for_scope): Add a new mode that follows ANSI + for-scoping, but supports (and warns about) old programs. + Make the new mode (with value 1) the default. + (lang_f_options): The on-value for flag_new_for_scope is now 2. + * cp-tree.h (DECL_DEAD_FOR_LOCAL, DECL_ERROR_REPORTED): New macros + (DECL_SHADOWED_FOR_VAR): Likewise. + * decl.c (struct binding_level): New fields dead_vars_from_for + and is_for_scope. + (note_level_for_for): New function. + (poplevel): Special processing if is_for_scope. + (pushdecl): Warn if for-scope variable shadows local. + * lex.c (do_identifier): Handle old (non-ANSI) for scoping, + and warn if conflicts. + * parse.y (FOR): Call note_level_for_for. + +Mon Aug 21 10:28:31 1995 Jason Merrill + + * decl2.c (import_export_inline): Class interface hackery does not + apply to synthesized methods. + +Sun Aug 20 16:29:00 1995 Mike Stump + + * search.c (virtual_context): Find the right context more often. + Solves a `recoverable compiler error, fixups for virtual function' + problem. + +Sun Aug 20 13:53:24 1995 Mike Stump + + * except.c (expand_start_all_catch): Ensure that we always transfer + control to the right EH handler, by rethrowing the end label on the + region, instead of hoping we are nested and falling through. + (expand_leftover_cleanups): Ditto. + (end_protect): Since we now rethrow the end label, put a + nop after it, so that outer regions are recognized. + * init.c (build_vec_delete_1): New routine to handle most of vector + deleting, all code moved here from build_vec_delete. + (build_array_eh_cleanup): Use build_vec_delete_1 to do all the real + work. + (expand_vec_init): If the array needs partial destructing, setup an + EH region to handle it. + (build_vec_delete): Move lots of code to build_vec_delete_1, use + build_vec_delete_1 to do the grunt work. + +Sat Aug 19 14:25:33 1995 Brendan Kehoe + + Handle decl attributes properly for function definitions without + previous attribute-loaded declarations. + * decl.c (start_function): New arg ATTRS. Add a call to + cplus_decl_attributes with it before we create the RTL. + * cp-tree.h (start_function): Update prototype. + * parse.y (fn.def1): Pass ATTRS into start_function instead of + trying to call cplus_decl_attributes too late. Pass a NULL_TREE + for other use. + * decl2.c (finish_file): Pass NULL_TREE as fourth arg to + start_function. + * method.c (synthesize_method): Likewise. + * except.c (expand_builtin_throw): Likewise for start on __throw. + +Sat Aug 19 13:36:08 1995 Mike Stump + + * class.c (set_rtti_entry): Turn on -fvtable-thunk -frtti support. + This changes -fvtable-thunks vtable layout, so a recompile will be + necessary, if you use -fvtable-thunks. + (get_vtable_entry): Use n, instead of i to be consistent with the + rest of the compiler. + (get_vtable_entry_n): Ditto. + (add_virtual_function): Add a slot for the tdesc, if -fvtable-thunks + are being used. + (finish_struct_1): Ditto. + (skip_rtti_stuff): New routine to collapse similar code from many + different parts of the compiler. I think I got them all. + (modify_one_vtable): Use it. + (fixup_vtable_deltas1): Ditto. + (override_one_vtable): Ditto. + * decl2.c (mark_vtable_entries): Ditto. + * tree.c (debug_binfo): Ditto. + * search.c (expand_upcast_fixups): Ditto. + (get_abstract_virtuals_1): Ditto. Use virtuals, instead of tmp to + consistent with the rest of the compiler. + (get_abstract_virtuals): Ditto. + * cp-tree.h (skip_rtti_stuff): New routine, declare it. + * gc.c (build_headof): Support -fvtable-thunk and -frtti together. + (build_typeid): Ditto. + (build_classof): Remove old style way of doing rtti. Remove support + for `classof' and `headof'. + * gxx.gperf: Ditto. + * hash.h: Ditto. + * parse.y: Ditto. + +Fri Aug 18 17:31:58 1995 Jason Merrill + + * decl.c (start_function): Clear ctor_label and dtor_label. + + * class.c (finish_struct_1): Fix handling of access decls. + +Tue Aug 15 19:21:54 1995 Jason Merrill + + * class.c (finish_struct): Only do minimal processing here, so it + can be used for class template definitions, as well. + (finish_struct_1): New function with the rest of the code. + +Tue Aug 15 09:46:16 1995 Mike Stump + + * class.c (prepare_fresh_vtable): On second though, always build the + offset (see Aug 10 change), unless -fvtable-thunks is given. It + does this by calling the new routine set_rtti_entry. + (finish_struct): Ditto. + (set_rtti_entry): New routine to update the rtti information at the + start of the vtable. + +Mon Aug 14 12:21:22 1995 Brendan Kehoe + + * error.c (dump_decl, case IDENTIFIER_NODE): Only work on a dtor + if it's declared in the C++ language spec. + (dump_function_decl): Likewise. + (dump_function_name): Likewise. + (ident_fndecl): Make sure we got something back from lookup_name. + * decl.c (start_function): Likewise. + +Fri Aug 11 16:52:15 1995 Jason Merrill + + * call.c (build_method_call): Don't call build_new when calling a + constructor without an instance. + +Thu Aug 10 20:00:17 1995 Mike Stump + + * class.c (prepare_fresh_vtable): Always build the offset to the + complete object, as it doesn't cost much. This allows dynamic_cast + to void * to work when -frtti isn't given. + (finish_struct): Ditto. + +Thu Aug 10 16:31:28 1995 Mike Stump + + * except.c (build_eh_type): Split out some functionality to new + routine named build_eh_type_type. + (build_eh_type_type): New routine. + (expand_start_catch_block): Use build_eh_type_type, as we never want + the dynamic type of the catch parameter, just the static type. + Fixes core dumps when -frtti is used and one catchs pointers to + classes. + +Thu Aug 10 14:55:29 1995 Mike Stump + + * except.c (expand_builtin_throw): Since we now use normal calling + conventions for __throw, we have to remove the first layer off the + stack, so that the next context we search for handlers is the outer + context instead of the context that had the call to __throw, if we + don't immediately find the desired context. + +Tue Aug 8 17:44:23 1995 Jason Merrill + + * tree.c (cp_expand_decl_cleanup): Returns int, not tree. + * cp-tree.h: Update. + + * parse.y (template_type_parm): Add support for `typename'. + +Tue Aug 8 12:06:31 1995 Mike Stump + + * except.c (expand_internal_throw): New internal routine to throw a + value. + (expand_end_all_catch, expand_leftover_cleanups): All throwers + changed to use `expand_internal_throw' instead of jumping to throw + label. + (expand_end_catch_block, expand_throw): Ditto. + (throw_label): Removed. + (expand_builtin_throw): Changed so that EH parameters are passed by + normal function call conventions. Completes Aug 4th work. + +Fri Aug 4 17:17:08 1995 Mike Stump + + * cp-tree.h (expand_builtin_throw): Declare it. + * decl2.c (finish_file): Call expand_builtin_throw. + * except.c (make_first_label): Remove. + (init_exception_processing): Don't use a LABEL_REF for throw_label, + instead use a SYMBOL_REF, this is so that we don't use LABEL_REFs in + other functions that don't really appear in those functions. This + solves a problem where cc1plus consumed exponential amounts of + memory when -Wall was used. + (expand_end_all_catch, expand_leftover_cleanups, + expand_end_catch_block, expand_throw): Change all uses of + throw_label to match new style. + (do_unwind): Rename parameter to inner_throw_label, as it is now + different from throw_label. Also, assume that our caller will wrap + the passed label with a LABEL_REF, if needed. + (expand_builtin_throw): Make external, change so that the generated + throw is now a real function. + (expand_exception_blocks): Never generate throw code inside another + function. + +Fri Aug 4 12:20:02 1995 Mike Stump + + * decl.c (grokdeclarator): Move checking of mutable const objects + and mutable static objects down, as we might decide during parsing + to unset staticp or constp (for example, when const is part of the + object being pointed to). + +Thu Aug 3 17:13:43 1995 Mike Stump + + * except.c (output_exception_table_entry): Enhance portability to + weird machines. + (emit_exception_table): Ditto. + +Thu Aug 3 16:41:38 1995 Mike Stump + + * typeck.c (build_ptrmemfunc): Handle casting of pointer to + non-virtual member functions. + +Wed Aug 2 11:58:25 1995 Mike Stump + + * gc.c (build_typeid): Strip cv qualifiers so that const T&, T&, T + and const T all match. + +Wed Aug 2 11:25:33 1995 Mike Stump + + * except.c (build_eh_type): Strip cv qualifiers so that const T&, + T&, T and const T all match. + +Tue Aug 1 14:20:16 1995 Mike Stump + + * except.c: Fix up comments, cleanup code and eliminate exceptNode, + exceptStack, exceptstack, push_except_stmts, pop_except_stmts, + new_except_stack, push_last_insn, pop_last_insn, insn_save_node and + InsnSave. Also, numerous speed improvements, and correctness + improvements. Double faulting in all situations should now be + handled correctly. + (expand_start_all_catch): Instead of having many terminate protected + regions, just have one. + (expand_start_catch_block): No longer have to protect + false_label_rtx, as it isn't used for EH region marking. + (expand_end_catch_block): Expand out EH cleanups here by using + expand_leftover_cleanups. + (expand_end_all_catch): Use sequences instead of playing with insn + links directly. + (expand_exception_blocks): Ditto. Also protect all catch clauses + with one terminate region. + +Mon Jul 31 13:24:30 1995 Jason Merrill + + * method.c (report_type_mismatch): Don't talk about an object + parameter for non-methods. + +Sun Jul 30 13:13:02 1995 Jason Merrill + + * class.c (finish_struct): Catch private and protected members of + anonymous unions here. + * decl2.c (finish_anon_union): And here. + * parse.y: Instead of here. + + * errfn.c (ARGSLIST): Support passing four args. + * error.c (cv_as_string): New function. + (cp_printers): Add it. + * call.c (build_method_call): Report 'const' at end of pseudo-decl. + + * method.c (report_type_mismatch): Deal with a bad_arg of 0. + + * init.c (expand_aggr_init): Handle volatile objects, too. + +Sat Jul 29 13:42:03 1995 Jason Merrill + + * decl.c (struct binding_level): Keep list of incomplete decls. + (print_binding_level): Use list_length to count them. + (pushdecl): Build up the list. + (hack_incomplete_structures): Walk it and prune completed decls. + +Fri Jul 28 15:26:44 1995 Jason Merrill + + * typeck.c (comp_target_types): Don't check const and volatile for + function types. + (comp_ptr_ttypes_real): Ditto. + +Thu Jul 27 15:40:48 1995 Jason Merrill + + * typeck.c (comp_target_types): Fix. + +Thu Jul 27 15:10:48 1995 Mike Stump + + * cp-tree.h (unsave_expr_now, build_unsave_expr, + cp_expand_decl_cleanup): Declare new routines. + * decl.c (cp_finish_decl, store_parm_decls, + hack_incomplete_structures): Change all cals from + expand_decl_cleanup to cp_expand_decl_cleanup. + * gc.c (protect_value_from_gc): Ditto. + * expr.c (cplus_expand_expr): Handle UNSAVE_EXPRs. + * tree.c (unsave_expr): New routine to build an UNSAVE_EXPR. + (unsave_expr_now): Backend routine used by tree expander. + (cp_expand_decl_cleanup): Wrap second argument in an UNSAVE_EXPR to + work around a limitation in the backend. The backend uses the + cleanups multiple times, on disjoint control flows, so we cannot + pass unsaved SAVE_EXPRs to the backend. + * tree.def (UNSAVE_EXPR): New tree code. + * typeck.c (c_expand_return): Move goto/return code up inside + conditional, as we don't always want to do this, we only want to do + this when we don't otherwise finish with this control flow. + +Thu Jul 27 10:38:43 1995 Brendan Kehoe + + * parse.y (typespec): Only complain about typeof if we're not + getting it from a system header. + +Thu Jul 27 10:26:23 1995 Doug Evans + + Clean up prefix attribute handling. + * parse.y (reserved_declspecs): Link prefix attributes with declspecs. + (declmods): Likewise. + (all rules that reference typed_declspecs and declmods): Call + split_specs_attrs or strip_attrs to separate declspecs and attrs. + (lang_extdef): Delete resetting of prefix_attributes. + (template_def, notype_declarator rule): Use NULL_TREE for + prefix_attributes. + (condition): Use NULL_TREE for prefix_attributes. + (setattrs): Deleted. + (nomods_initdcl0): Set prefix_attributes to NULL_TREE. + (component_decl): Delete resetting of prefix_attributes. + (component_decl_1, notype_components rule): Use NULL_TREE for + prefix_attributes. + (simple_stmt): Delete resetting of prefix_attributes. + +Mon Jul 24 13:37:53 1995 Jason Merrill + + * call.c (convert_harshness): Deal with reference conversions before + others. Actually do array->pointer decay. Call comp_target_types + with pointer types rather than their targets. + + * typeck.c (comp_target_types): Avoid assigning D const * to B *. + +Mon Jul 24 08:54:46 1995 Brendan Kehoe + + * pt.c (to_be_restored): Move decl to global scope. + +Sat Jul 22 12:22:11 1995 Jason Merrill + + * decl.c (start_decl): Put back clearing of DECL_IN_AGGR_P. + +Fri Jul 21 17:09:02 1995 Jason Merrill + + * decl.c (grokdeclarator): Downgrade error about 'extern int A::i' + to pedwarn. + + * pt.c (instantiate_template): Also avoid instantiation if the + function has already been declared to be a specialization. + + * decl2.c (check_classfn): Ignore cname argument, and return the + matching function. + + * decl.c (start_decl): Handle declarations of member functions + outside of the class (i.e. specialization declarations). + +Thu Jul 20 10:34:48 1995 Jason Merrill + + * class.c (finish_struct): Don't mess with the type of bitfields. + + * various.c: s/TYPE_POINTER_TO/build_pointer_type/. + +Thu Jul 20 01:43:10 1995 Mike Stump + + * init.c (expand_aggr_init): Assume LOOKUP_ONLYCONVERTING if init + is not a parameter list (TREE_LIST). + (expand_default_init): If LOOKUP_ONLYCONVERTING is set, then set + LOOKUP_NO_CONVERSION so that we don't allow two-level conversions, + but don't set it otherwise. + +Wed Jul 19 20:32:01 1995 Mike Stump + + * init.c (expand_default_init): Don't allow two-level conversions + during construction. + +Wed Jul 19 18:06:37 1995 Mike Stump + + * gc.c (build_headof): The type of dyncasting to a pointer to cv + void, should be pointer to cv void. + +Wed Jul 19 17:25:43 1995 Mike Stump + + * gc.c (build_dynamic_cast): Allow casting in const. + +Wed Jul 19 16:34:27 1995 Mike Stump + + * typeck.c (build_const_cast): If we are passed error_mark_node, + return it. + +Wed Jul 19 15:24:48 1995 Brendan Kehoe + + * class.c (push_nested_class): Make sure TYPE is non-nil. + + * cvt.c (type_promotes_to): Watch for error_mark_node on the + incoming TYPE. + +Wed Jul 19 13:23:12 1995 Gerald Baumgartner + + * cp-tree.h (SIGTABLE_VT_OFF_NAME): Renamed from SIGTABLE_OFFSET_NAME. + (SIGTABLE_VB_OFF_NAME): New macro. + (vt_off_identifier): Renamed from offset_identifier. + (vb_off_identifier): Added extern declaration. + + * decl.c (vt_off_identifier): Renamed from offset identifier. + (vb_off_identifier): New variable to hold the identifier for the + sigtable field vb_off. + (init_decl_processing): Initialize vb_off_identifier. + Renamed vt_off_identifier from offset_identifier. + * sig.c (build_signature_method_call): Renamed offset_identifier and + local variable offset to vt_off_identifer and vt_off, respecitively. + * sig.c (build_signature_table_constructor): Renamed offset to vt_off. + + * decl.c (init_decl_processing): Add vb_off field to + sigtable_entry_type. Reorder fields so that pfn gets properly + aligned at a 64 bit boundary on the Alpha. + * sig.c (build_signature_table_constructor): Build the constructor + according to the new layout. Set the vb_off field to -1 for now. + + * decl.c (init_decl_processing): Align sigtable_entry_type on word + boundaries instead of double word boundaries to save space. + +Tue Jul 18 16:58:37 1995 Mike Stump + + * cvt.c (cp_convert): Always call build_cplus_new for a ctor. + +Tue Jul 18 14:24:53 1995 Brendan Kehoe + + * parse.y (opt.component_decl_list): Only forbid private/protected + in anonymous unions. We need to make this know when the type is + defined for an object, to not give the error. + +Mon Jul 17 14:22:44 1995 Brendan Kehoe + + * parse.y (opt.component_decl_list): Don't allow access control + as private or protected for union members. + +Sun Jul 16 14:01:00 1995 Jim Wilson + + * lex.c (check_newline): For 'p' case, move goto skipline line to + before end brace for 'pragma'. + +Fri Jul 7 13:55:58 1995 Mike Stump + + * g++.1: Tiny updates. + +Fri Jul 7 13:05:20 1995 Mike Stump + + * decl.c (cp_finish_decl): Only destruct local static variables if + they are constructed, and only construct the first time control + passes completely through its declaration (if not initialized with a + constant-expression). + (expand_static_init): Ditto. + +Wed Jul 5 14:05:04 1995 Brendan Kehoe + + * typeck.c (comptypes, case OFFSET_REF): If either offset basetype + is a TEMPLATE_TYPE_PARM, give a match. + +Mon Jul 3 15:17:20 1995 Steve Chamberlain + + * g++.c (sys/file.h): Remove change of Jun 28. + +Fri Jun 30 15:42:57 1995 Mike Stump + + * method.c (build_overload_value): Handle encoding of null pointer + constants (or any pointer with a constant numeric value) for + templates. + +Fri Jun 30 13:45:51 1995 Brendan Kehoe + + * call.c (convert_harshness): Add QUAL_CODE when we're faced with + const vs non-const for void conversions. + +Fri Jun 30 10:19:52 1995 Mike Stump + + * except.c (expand_start_all_catch): Fix problem with finding an + outer nested try block when there is no code to separate it from an + inner try block. + +Fri Jun 30 02:22:26 1995 Mike Stump + + * search.c (dfs_pushdecls): Consume 2 or 3 orders of magnitude less + memory please when virtual bases are used. + +Thu Jun 29 19:03:47 1995 Mike Stump + + * class.c (build_vbase_path): Avoid testing things that cannot be + null to see if they are null. + * cvt.c (convert_pointer_to_vbase): Remove code that doesn't work. + * decl.c (finish_function): Pass a type into the new + convert_pointer_to_vbase instead of a binfo. + * search.c (convert_pointer_to_vbase): Rewritten to use get_vbase + and convert_pointer_to_real. + (expand_indirect_vtbls_init): Use convert_pointer_to_vbase instead + of the more cryptic call to get_vbase. + +Thu Jun 29 09:35:05 1995 Mike Stump + + * decl.c (BOOL_TYPE_SIZE): Fix broken SLOW_BYTE_ACCESS check. + +Thu Jun 29 03:43:55 1995 Jason Merrill + + * pt.c (instantiate_template): Don't strip 'this' twice. + + * pt.c (coerce_template_parms): Allow null pointer constants. + + * decl.c (revert_static_member_fn): But only if DECL_ARGUMENTS is + set. + +Wed Jun 28 23:34:58 1995 Steve Chamberlain + + * g++.c (pfatal_with_name): Use my_strerror to get error + string. + (sys/file.h): Include if HAVE_FILE_H defined. + +Wed Jun 28 18:39:03 1995 Jason Merrill + + * decl.c (revert_static_member_fn): Also remove 'this' from + DECL_ARGUMENTS. + * decl2.c (check_classfn): Don't revert this function until we get a + match. + +Wed Jun 28 14:07:27 1995 Brendan Kehoe + + * parse.y (component_decl): Clear PREFIX_ATTRIBUTES here. + +Wed Jun 28 11:05:13 1995 Mike Stump + + * decl2.c (finish_file): Handle global vector news. + * init.c (build_new): Encode vector news so that later we will know + how many elements there are. + +Mon Jun 26 13:38:06 1995 Jason Merrill + + * expr.c (cplus_expand_expr): Don't mess with temp slots. + + * decl2.c (warn_if_unknown_interface): Don't crash if tinst_for_decl + returns null. + + * decl2.c (check_classfn): Use revert_static_member_fn. + * decl.c (revert_static_member_fn): Diagnose static member functions + declared const or volatile. + + * decl2.c (grokfield): Check for missing default args here, too. + (check_default_args): Function to do the checking. + * decl.c (pushdecl): Use it. + + * decl.c (pushdecl): Don't warn about shadowing a member of `this' + if there is no `this'. + +Sun Jun 25 11:34:25 1995 Jason Merrill + + * call.c (build_method_call): Downgrade 'called before definition' + to a warning, as it ought to go away after Monterey. + +Sat Jun 24 14:18:42 1995 Jason Merrill + + * pt.c (coerce_template_parms): Don't do extra checking on pointer + to member arguments. + + * class.c (finish_struct): const and reference members don't prevent + a class from being an aggregate. + + * class.c (finish_struct): Signatures are always aggregates. + +Fri Jun 23 17:20:29 1995 Jason Merrill + + * decl2.c (check_classfn): Improve error message. + + * pt.c (tsubst): Handle PROMOTE_PROTOTYPES. + +Thu Jun 22 01:50:42 1995 Jason Merrill + + * typeck.c (comptypes): Don't ignore method quals. + + * class.c (finish_struct): Non-abstract virtuals are always USED. + + * decl.c (build_ptrmemfunc_type): The underlying union type isn't + IS_AGGR_TYPE, either. + * class.c (finish_struct): Use CLASSTYPE_NON_AGGREGATE instead. + * cp-tree.h: Ditto. + + * cp-tree.h (lang_type): Add aggregate. + (CLASSTYPE_AGGREGATE): New macro. + (TYPE_NON_AGGREGATE_CLASS): Ditto. + * class.c (finish_struct): Determine whether a class is an + aggregate. + * decl.c (cp_finish_decl): Check TYPE_NON_AGGREGATE_CLASS instead of + TYPE_NEEDS_CONSTRUCTING. + * typeck2.c (digest_init): Check TYPE_NON_AGGREGATE_CLASS for + subobjects, too. + + * pt.c (tsubst, PARM_TYPE): Propagate DECL_ARTIFICIAL. + + * decl.c (start_function): For pre-parsed functions, layout all of + the parm decls again. + (grokvardecl): TREE_PUBLIC depends on DECL_THIS_EXTERN, not + DECL_EXTERNAL. + + * pt.c (coerce_template_parms): Improve checking for invalid + template parms. + +Wed Jun 21 12:01:16 1995 Brendan Kehoe + + * decl.c (grokdeclarator): Forbid declaration of a static member + with the same name as its enclosing class. + +Mon Jun 19 10:28:14 1995 Jason Merrill + + * decl.c (finish_function): Clear current_class_decl. + + * typeck.c (build_conditional_expr): Use convert (boolean_type_node + instead of truthvalue_conversion. + + * class.c (finish_struct): A data member with the same name as the + class doesn't suppress constructors. + +Fri Jun 16 18:11:39 1995 Gerald Baumgartner (gb@alexander.cs.purdue.edu) + + * decl.c (start_function): If current_class_decl is a signature + pointer, don't dereference it but set C_C_D to current_class_decl. + +Fri Jun 16 17:06:28 1995 Jason Merrill + + * decl.c (duplicate_decls): Complain about virtual functions + redeclared to be inline. + +Fri Jun 16 13:20:38 1995 Mike Stump + + * decl.c (get_unique_name): New routine to name unnamed namespaces. + (push_namespace): Use get_unique_name for naming unnamed namespaces. + +Fri Jun 16 15:07:29 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Make-lang.in (DEMANGLER_PROG): Add LIBS. + +Thu Jun 15 15:00:41 1995 Jason Merrill + + * decl.c (define_function): Don't set DECL_INTERFACE_KNOWN. + + * parse.y: Call cplus_decl_attributes with prefix_attributes where + appropriate. + +Wed Jun 14 19:24:49 1995 Mike Stump + + * search.c (get_vbase): New routine to switch hierarchies from the + CLASSTYPE_VBASECLASSES to the normal one. + (expand_indirect_vtbls_init): Use get_vbase to figure out how we + want to convert to a vbase pointer. + +Mon Jun 12 17:50:30 1995 Jason Merrill + + * pt.c (instantiate_class_template): Add the new instantiation to + template_classes. + (do_pending_expansions): Call instantiate_member_templates on all of + the classes in template_classes. + +Mon Jun 12 12:36:59 1995 Mike Stump + + * decl.c (complete_array_type): Fill in the TYPE_DOMAIN of our + TYPE_MAIN_VARIANT if it is not filled in. + * init.c (build_delete): If the TYPE_DOMAIN is not set, give an + error instead of core dumping. + +Mon Jun 12 10:41:40 1995 Jason Merrill + + * call.c (can_convert): Also check for distance > 0. + (can_convert_arg): Ditto. + (user_harshness): Ditto. + +Fri Jun 9 19:17:21 1995 Jason Merrill + + * g++.c (MATH_LIBRARY): Provide default. + (main): Always link with the math library if we link with libstdc++. + + * decl.c (start_function): Complain about redefinition of a function + even when the pending_inline version is compiled after the other + version. + +Thu Jun 8 15:44:38 1995 Jason Merrill + + * gc.c (build_dynamic_cast): Build up a reference to a parameter of + aggregate type. + +Wed Jun 7 20:00:31 1995 Mike Stump + + * *.[chy]: Change all callers of finish_decl to cp_finish_decl. + * decl.c (finish_decl): New routine to handle call backs from the + mid end (declare_hidden_char_array). + +Wed Jun 7 19:02:50 1995 Jason Merrill + + * decl.c (start_function): Handle setting C_C_D here. + (set_C_C_D): Removed. + (struct saved_scope): Remove class_decl. + (push_to_top_level): Don't save current_class_decl. + (pop_from_top_level): Don't restore current_class_decl or C_C_D. + (struct cp_function): Add C_C_D. + (push_cp_function_context): Save C_C_D. + (pop_cp_function_context): Restore C_C_D. + +Wed Jun 7 15:31:57 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * init.c (build_vec_delete): Resolve an offset ref before we try to + use it. + +Wed Jun 7 14:19:32 1995 Jason Merrill + + * typeck.c (build_modify_expr): If the class lacks a constructor or + assignment operator, return error_mark_node. + (common_type): Use build_cplus_array_type. + +Tue Jun 6 09:41:27 1995 Mike Stump + + * class.c (dont_allow_type_definitions): New variable set when types + cannot be defined. + (finish_struct): Use it. + * cp-tree.h (dont_allow_type_definitions): Define it. + * parse.y (primary, handler_seq): Set it. + +Mon Jun 5 18:49:38 1995 Mike Stump + + * method.c (build_opfncall): Use DECL_CHAIN, not TREE_CHAIN for + results from lookup_fnfields. Always give warning/error on bad + code. + +Mon Jun 5 11:39:37 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * init.c (member_init_ok_or_else): Don't allow initialization of + an ancestor's member from within a constructor. + +Mon Jun 5 11:20:34 1995 Gerald Baumgartner (gb@alexander.cs.purdue.edu) + + * sig.c (build_signature_table_constructor): Use DECL_CONTEXT + instead of DECL_CLASS_CONTEXT for calculating the vfield offset so + abstract virtual functions are handled correctly. + + * sig.c (build_signature_table_constructor): Store the correct + delta in signature table entries. It does not yet work for + classes with virtual base classes as implementations of signatures. + (build_signature_method_call): Add the delta to the object_ptr + before generating the function call. + + * call.c (build_method_call): Make instance_ptr the signature + pointer itself instead of dereferencing the optr. + * sig.c (build_signature_method_call): Dereference the optr for the + direct and virtual calls. + + * sig.c (build_signature_table_constructor): Make the tag for + default implementations -1 instead of 2. + (build_signature_method_call): Change the generated conditional + expression correspondingly. + + * sig.c (build_signature_pointer_constructor): Deleted the sorry + message that said we can't handle multiple inheritance for + implementations of signatures + (build_signature_method_call): Use the offset from the sigtable + entry instead of the vptr field from the signature pointer for + building a virtual function call. + + * class.c (build_vfn_ref): Deleted signature specific code, we don't + call this function anymore from build_signature_method_call. + + * cp-tree.h (SIGNATURE_VPTR_NAME): Deleted. We use the right vptr + field in the object now instead of in the signature pointer/ref. + (build_vptr_ref): Deleted extern declaration. + * sig.c (build_vptr_ref): Deleted. + (build_signature_pointer_or_reference_type): Deleted construction of + the vptr field. + (build_signature_pointer_constructor): Deleted initialization of/ + assignment to the vptr field. + + * sig.c (build_signature_table_constructor): Convert the signature + table entry fields to their correct types. + + * sig.c (build_signature_table_constructor): Don't call digest_init + for the fields of a sigtable entry, it's wasted time. + + * sig.c (build_signature_table_constructor): Correctly set the + offset and index fields of a sigtable entry. Build the constructor + the way digest_init does, digest_init can't handle initializing an + anonymous union inside a struct. + (build_signature_method_call): Use the index field instead of the + delta field to get the vtable index. + + * decl.c (init_decl_processing): Fix number of fields for building + sigtable_entry_type. + + * cp-tree.h (tag_identifier, offset_identifier): Added extern decls. + (SIGTABLE_CODE_NAME): Renamed to SIGTABLE_TAG_NAME. + (SIGTABLE_PFN_NAME): Deleted, we'll use VTABLE_PFN_NAME instead. + * decl.c (tag_identifier, offset_identifier): New variables to + hold the identifiers for the sigtable fields tag and offset. + (init_decl_processing): Initialize these variables. + (init_decl_processing): Use these variables to build the + sigtable_entry_type structure. Rename the code and offset fields + to tag and delta, respectively; add offset and index fields. Changed + types of fields from short_integer_type_node to delta_type_node. + * sig.c (build_signature_table_constructor): Rename code and offset + to tag and delta, respectively. + (build_signature_method_call): Ditto. Use above variables. + +Fri Jun 2 11:05:58 1995 Jason Merrill + + * decl.c (set_C_C_D): New function. suspend_momentary before + building C_C_D. + (pop_from_top_level): Call it. + (start_function): Ditto. + (pop_cp_function_context): Ditto. + + * class.c, cp-tree.h, decl.c, decl2.c, parse.y: Lose all references + to current_vtable_decl, CLASSTYPE_INST_VAR and CLASSTYPE_VTBL_PTR. + + * decl.c (push_cp_function_context): Save current_class_decl. + (pop_cp_function_context): Restore current_class_decl and set C_C_D. + (pop_from_top_level): Don't use CLASSTYPE_INST_VAR to set C_C_D. + (start_function): Ditto. + + * class.c (popclass): Don't mess with current_class_decl, + current_vtable_decl, or C_C_D. + +Mon May 29 12:45:10 1995 Paul Eggert + + * Make-lang.in (c++.mostlyclean): Remove $(DEMANGLER_PROG). + +Thu Jun 1 17:03:51 1995 Jason Merrill + + * decl.c (lookup_name_real): Don't try to look anything up in an + erroneous object. + +Fri Jun 2 10:30:14 1995 Mike Stump + + * method.c (build_overload_int): New routine. Break out + functionality from build_overload_value so we can reuse it. + (build_overload_value): Handle pointer to member functions as value + parameters for templates. + (build_overload_identifier): Since template parameters are shared + among all instantiations, we have to substitute in the real types + in TREE_TYPE (parm). + pt.c (coerce_template_parms): Ditto. + (push_template_decls): Ditto. + (grok_template_type): Deleted as template parameters are shared + among all instantiations. + +Wed May 31 19:10:32 1995 Mike Stump + + * decl.c (grokdeclarator): Always give errors on constant overflow + for array indices. + +Wed May 31 11:39:43 1995 Jason Merrill + + * typeck.c (commonparms): Don't abort if simple_cst_equal returns < 0. + (build_c_cast): Don't tack on a NON_LVALUE_EXPR when casting to + reference type. + (build_indirect_ref): Fix check for *&. + +Wed May 24 15:55:18 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * decl.c (duplicate_decls): Check simple_cst_equal result against 0. + * decl2.c (finish_anon_union): Likewise. + * method.c (largest_union_member): Likewise. + +Wed May 24 14:41:11 1995 H.J. Lu (hjl@nynexst.com) + + * Make-lang.in (cxxmain.o): Replace single quotes with backslashes. + +Mon May 22 17:38:48 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Make-lang.in (g++, g++-cross, cc1plus, DEMANGLER_PROG): + Use $@ instead of output name so works even if have .exe. + (cxxmain.o): Use cp if ln -s fails. + (c++.install-man): Use $(exeext) in executable names. + (c++.mostlyclean, stage[1-4]): Use $(objext) in object file names. + * Makefile.in (../cc1plus): Use $(exeext) in name of executable. + +Wed May 24 01:39:03 1995 Jason Merrill + + * call.c (build_method_call): parms can be null, duh. + +Tue May 23 01:32:09 1995 Jason Merrill + + * call.c (build_method_call): If convert_arguments failed, just bail. + +Fri May 19 10:31:11 1995 Jason Merrill + + * cvt.c (convert_force): Pass LOOKUP_NORMAL to cp_convert. + + * tree.c (copy_to_permanent): Oops. + +Fri May 19 10:01:07 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-tree.h (break_out_target_exprs): Add decl. + +Thu May 18 13:02:30 1995 Jason Merrill + + * decl.c (start_function): Move *all* interface handling stuff after + the pushdecl. + + * tree.c (mapcar): Renamed from make_deep_copy and generalized. + (perm_manip): Return t if permanent, otherwise 0. + (copy_to_permanent): Use them. + (bot_manip): Helper for break_out_target_exprs. + (break_out_target_exprs): New function. Uses mapcar. + + * typeck.c (convert_arguments): Use it. + + * method.c (hack_identifier): Use convert_from_reference to + dereference a reference. + +Wed May 17 17:54:54 1995 Mike Stump + + * call.c (convert_harshness): Move reference bashing before pointer + to member bashing. + +Wed May 17 16:57:53 1995 Mike Stump + + * cvt.c (convert_to_reference): Only complain, if complaints are + wanted. + * typeck.c (build_function_call_real): Ditto. If LOOKUP_SPECULATIVELY + is set and something won't work, return NULL_TREE. + * cvt.c (cp_convert): Ditto. Pass flags down to build_method_call. + (convert): Pass LOOKUP_NORMAL to cp_convert. + * typeck.c (convert_for_assignment): Ditto. + (convert_force): Pass LOOKUP_COMPLAIN to cp_convert. + (convert_arguments): Get out early if we get an error_mark_node. + (convert_for_initialization): Use cp_convert instead of convert so + that we can pass flags down. + * cp-tree.h (LOOKUP_SPECULATIVELY): Added documentation. + +Wed May 17 01:43:58 1995 Jason Merrill + + * typeck2.c (store_init_value): Don't take the MAIN_VARIANT of the + decl type. + + * class.c (finish_struct): Don't complain about a class with no + user-defined constructors but with a member that has no default + constructor, as this is OK for aggregates. + + * expr.c (cplus_expand_expr, NEW_EXPR): If this is an explicit + constructor call, mark slot addressable. + +Tue May 16 18:37:51 1995 Douglas Rupp (drupp@cs.washington.edu) + + * g++.c: Changed WINNT to _WIN32. + +Tue May 16 12:40:16 1995 Jason Merrill + + * lex.c (handle_sysv_pragma): Don't use token_buffer. + +Tue May 16 12:05:26 1995 Mike Stump + + * call.c (resolve_scope_to_name): Add initial semantic support for + namespaces. + * class.c (finish_struct): Ditto. + * cp-tree.h (NAMESPACE_LEVEL): Ditto. + * cvt.c (build_up_reference, convert_to_reference): Ditto. + * decl.c (binding_level::namespace_p, suspend_binding_level): Ditto. + (resume_binding_level, toplevel_bindings_p): Ditto + (namespace_bindings_p, declare_namespace_level): Ditto. + (resume_level, push_namespace, pop_namespace): Ditto. + (pop_everything, pushtag, duplicate_decls, pushdecl): Ditto. + (implicitly_declare, lookup_namespace_name, lookup_name_real): Ditto. + (start_decl, make_temporary_for_reference), Ditto. + (obscure_complex_init, finish_decl, expand_static_init): Ditto. + (grokvardecl, grokdeclarator, parmlist_is_exprlist): Ditto. + (store_parm_decls, hack_incomplete_structures): Ditto. + * decl2.c (get_temp_name, finish_anon_union, current_namespace): Ditto. + (push_namespace, pop_namespace, do_namespace_alias): Ditto. + (do_toplevel_using_decl, do_class_using_decl): Ditto. + * error.c (dump_decl): Ditto. + * init.c (build_member_call, build_offset_ref): Ditto. + * lex.c (identifier_type): Ditto. + * parse.y (lang_extdef, using_decl, extdef, component_decl_1): Ditto. + (nested_name_specifier_1): Ditto. + * spew.c (yylex): Ditto. + * tree.def (NAMESPACE_DECL): Ditto. + +Tue May 16 11:55:35 1995 Jason Merrill + + * decl.c (push_overloaded_decl): Return the new decl even if it + can't be pushed. + +Tue May 16 11:00:37 1995 Jason Merrill + + * typeck.c (decay_conversion): Split out from default_conversion. + (default_conversion): Call it. + (build_binary_op): Ditto. + (build_binary_op_nodefault): Use decay_conversion for truth ops. + +Mon May 15 12:47:56 1995 Jason Merrill + + * decl.c (warn_extern_redeclared_static): This is a pedwarn. + (duplicate_decls): Always use the old decl's linkage info. Don't + play with linkage of consts. + (pushdecl): Don't play with linkage of consts. + (redeclaration_error_message): Don't complain about an old public + decl and a new non-public decl here. + (grokvardecl): Handle linkage of consts here. + (grokdeclarator): An 'extern inline' is public. Pass constp to + grokvardecl. + (start_function): Wait until after the pushdecl to do some linkage + stuff. + + * decl2.c (import_export_vtable): Make duplicates weak rather than + static if supported. + (import_export_inline): Ditto. + * pt.c (do_pending_expansions): Ditto. + + * class.c (build_vbase_path): flag_assume_nonnull_objects only + affects reference conversion. + + * init.c (emit_base_init): Build up an RTL_EXPR and add it to + rtl_expr_chain. + * decl.c, decl2.c: s/base_init_insns/base_init_expr/. + +Tue May 16 07:06:28 1995 Paul Eggert + + * method.c (numeric_output_need_bar): Renamed from misspelling. + + * typeck.c (build_ptrmemfunc): Fix misspellings in messages. + +Sun May 14 10:26:22 1995 Richard Kenner + + * lang-options.h, lang-specs.h: New files. + +Thu May 11 00:31:48 1995 Jason Merrill + + * typeck.c (default_conversion): Don't check for BLKmode before + pulling out the decl_constant_value. + + * decl.c (start_function): Clear named_labels and shadowed_labels. + + * typeck.c (build_function_call_real): Also synthesize methods here. + +Wed May 10 00:55:59 1995 Jason Merrill + + * decl2.c (finish_file): Synthesize exported methods before the + reconsider loop. + + * parse.y: Move declaration of flag_new_for_scope to file scope. + +Tue May 9 19:10:33 1995 Mike Stump + + * decl2.c: Add flag_new_for_scope for new -ffor-scope flag. + * parse.y (FOR): Conditionalize the pushing and poping of scope for + the for-init-statement upon the new flag_new_for_scope. + * parse.y (try_block): Simplify and use compstmt. + +Mon May 8 12:41:52 1995 Jason Merrill + + * decl.c (define_function): Mark function decl artificial. + +Sun May 7 00:51:28 1995 Jason Merrill + + * parse.y (simple_stmt, FOR): Put back push/pop for condition scope. + + * decl2.c (grokclassfn): DECLs don't have cv-qualified types. + * tree.c (build_cplus_method_type): Ditto. + + * cp-tree.h (SET_DECL_ARTIFICIAL): Just set DECL_ARTIFICIAL to 1. + + * typeck.c (build_function_call_real): If convert_arguments failed, + just bail. + (convert_arguments): If one of the arguments is error_mark_node, + just bail. + +Sat May 6 02:39:41 1995 Jason Merrill + + * decl.c (duplicate_decls): Don't check DECL_NOT_REALLY_EXTERN for + decls that don't include it. + +Fri May 5 14:23:30 1995 Jason Merrill + + * decl.c (duplicate_decls): Decls that have DECL_INTERFACE_KNOWN or + DECL_NOT_REALLY_EXTERN set aren't extern decls. + + * typeck.c (build_indirect_ref): Don't call default_conversion for a + parameter of reference_type. + * cvt.c (convert_from_reference): Just use build_indirect_ref. + + * pt.c (do_type_instantiation): Only instantiate member functions + that actually come from templates. + +Fri May 5 09:46:05 1995 Mike Stump + + * parse.y: Generalized cleanup of poplevels, and compound statements + and compound statements in try blocks. Rewritten `for' rule so that + the scope of variables declared in the for clause is shortened to + span just to the end of the statement, instead of the whole + containing block. + +Fri May 5 00:37:14 1995 Jason Merrill + + * call.c (convert_harshness): Handle pointers to members better. + +Thu May 4 16:00:26 1995 Jason Merrill + + * decl2.c (delete_sanity): Do access control here. + * init.c (build_delete): Instead of here. + + * Make-lang.in: Build c++filt. + +Wed May 3 02:59:53 1995 Jason Merrill + + * decl2.c (cplus_decl_attributes): If we just modified a TYPE_DECL, + update our IDENTIFIER_TYPE_VALUE. + +Fri Apr 28 07:58:41 1995 Jason Merrill + + * lex.c (cons_up_default_function): Fix linkage of #pragma + implemented functions. + +Thu Apr 27 16:56:24 1995 Jason Merrill + + * method.c (build_overload_name): Simplify and fix repeated type + folding. + + * decl.c (grokdeclarator): Prohibit pointers to void or reference + members. + +Thu Apr 27 09:49:07 1995 Mike Stump + + * typeck2.c (process_init_constructor): Make sure initializers are + fully digested. + +Thu Apr 27 01:11:55 1995 Jason Merrill + + * lex.c (cons_up_default_function): Always defer synthesis. + +Thu Apr 27 00:20:37 1995 Jason Merrill + + * decl2.c (mark_inline_for_output): Don't play with pending_inline + stuff. + +Wed Apr 26 17:48:24 1995 Jason Merrill + + * call.c (user_harshness): New function; like build_type_conversion, + but doesn't actually build anything. + (compute_conversion_costs): Use it instead of build_type_conversion. + +Wed Apr 26 17:11:25 1995 Jason Merrill + + * typeck.c (build_function_call_real): Improve error message for + calling a non-function. + + * method.c (hack_identifier): Lose check for calling a data member. + +Wed Apr 26 16:59:13 1995 Mike Stump + + * typeck2.c (build_functional_cast): Remove very old cruft. + Seems like good code is generated without it. + +Wed Apr 26 00:47:16 1995 Jason Merrill + + * method.c (do_build_assign_ref): Fix handling of anonymous unions. + (do_build_copy_constructor): Ditto. + + * parse.y (simple_stmt, SWITCH): Call {push,pop}_switch. + + * decl.c (push_switch): New function. + (pop_switch): Ditto. + (define_case_label): Check for jumping over initialization. + + * call.c (build_method_call): Check for an inline function being + called before its definition has been seen. + * typeck.c (build_function_call_real): Ditto. + + * decl.c (duplicate_decls): Check for a function being redeclared + inline after its address has been taken. + + * typeck.c (build_conditional_expr): Handle related class lvalues. + +Tue Apr 25 13:20:45 1995 Jason Merrill + + * pt.c (do_pending_expansions): Don't expand unused templates. + + * parse.y (component_decl): Accept a lone semicolon. + +Tue Apr 25 00:25:56 1995 Jason Merrill + + * call.c (build_method_call): Don't allow an RTL_EXPR to serve as the + object parameter anymore. + + * expr.c (cplus_expand_expr): Don't create RTL_EXPRs with no insns. + +Mon Apr 24 12:35:48 1995 Jason Merrill + + * parse.y (simple_stmt, decl case): Clear prefix_attributes. + (lang_extdef): Ditto. + + * parse.y (maybe_parmlist): New rule for use in declarators where + this could either be a list of expressions or parameters. Calls + suspend_momentary before deciding which. + (direct_after_type_declarator): Use it. + (complex_direct_notype_declarator): Use it. + + * pt.c (tsubst): Propagate attributes const and noreturn. + + * typeck.c (build_modify_expr): If warn_synth, call build_opfncall + before doing the default thing. + +Thu Apr 27 21:49:36 1995 Doug Evans + + * typeck.c (common_type): Call lookup_attribute instead of + value_member. + +Tue Apr 25 18:07:43 1995 Richard Kenner (kenner@vlsi1.ultra.nyu.edu) + + * Make-lang.in: Change "realclean" to "maintainer-clean". + +Sun Apr 23 12:32:38 1995 Mike Stump + + * decl2.c (finish_file): Fix broken linked list handling. + +Fri Apr 21 18:08:43 1995 Jason Merrill + + * class.c (finish_base_struct): Don't set TYPE_HAS_COMPLEX_*_REF + as often. + (finish_struct): Ditto. + + * various: Use TYPE_HAS_TRIVIAL_* instead of TYPE_HAS_COMPLEX_*. + + * cp-tree.h (TYPE_HAS_TRIVIAL_INIT_REF): New macro. + (TYPE_HAS_TRIVIAL_ASSIGN_REF): New macro. + +Fri Apr 21 15:52:22 1995 Jason Merrill + + * typeck.c (c_expand_return): Only expand a returned TARGET_EXPR if + it is of the same type as the return value. + +Fri Apr 21 03:01:46 1995 Jason Merrill + + * decl2.c (finish_file): Reconsider if synthesizing a method wrote + out its assembly. + + * typeck.c (convert_for_initialization): Don't call a trivial copy + constructor. + + * typeck2.c (store_init_value): Only abort if the type has a + non-trivial copy constructor. + + * typeck.c (c_expand_return): If we're returning in a register and + the return value is a TARGET_EXPR, expand it. Only do + expand_aggr_init if we're returning in memory. + (expand_target_expr): Function to expand a TARGET_EXPR. + (build_modify_expr): Use it. + + * tree.c (build_cplus_new): Layout the slot. + + * expr.c (cplus_expand_expr): Use expand_call to expand the call + under a NEW_EXPR, so the target is not discarded. + +Thu Apr 20 14:59:31 1995 Mike Stump + + * gc.c (build_dynamic_cast): Tighten error checking. + +Thu Apr 20 11:23:54 1995 Jason Merrill + + * expr.c (cplus_expand_expr): Only abort if the returned target is + different from what we expected if the type has a non-trivial copy + constructor. + + * decl2.c (cplus_decl_attributes): Attributes applied to a template + really apply to the template's result. + + * tree.c (lvalue_p): Check IS_AGGR_TYPE instead of TREE_ADDRESSABLE + to decide whether to consider a CALL_EXPR an lvalue. + + * class.c (finish_struct_bits): Only set TREE_ADDRESSABLE if the + type has a non-trivial copy constructor. + + * decl.c (start_function): If interface_known, unset + DECL_NOT_REALLY_EXTERN on the function. + +Wed Apr 19 16:53:13 1995 Jason Merrill + + * pt.c (do_function_instantiation): Handle explicit instantiation of + member functions. + (do_type_instantiation): Handle 'inline template class foo', + meaning just spit out the vtable. + + * lex.c (cons_up_default_function): Set DECL_NOT_REALLY_EXTERN on + the consed functions. + + * decl2.c (import_export_inline): Set DECL_INTERFACE_KNOWN. + +Wed Apr 19 16:28:17 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * call.c, class.c, decl2.c, gc.c, init.c, parse.y, pt.c, search.c, + typeck.c: Include output.h. + +Wed Apr 19 14:57:21 1995 Gerald Baumgartner (gb@alexander.cs.purdue.edu) + + * call.c (build_method_call): Allow a signature member functions to + be called from a default implementation. + +Wed Apr 19 10:21:17 1995 Jason Merrill + + * repo.c (finish_repo): Remember what directory we are in. + + * search.c (expand_upcast_fixups): Don't mess with abort_fndecl. + + * repo.c: Use obstacks instead of fixed-size buffers. Don't spit + out the second copy of the symbol name. Don't remember COLLECT_GCC. + +Wed Apr 19 02:32:40 1995 Mike Stump + + * search.c (virtual_context): New function to get the virtual + context of a function. + (expand_upcast_fixups): New function to generate runtime vtables. + (fixup_virtual_upcast_offsets): Ditto. + (expand_indirect_vtbls_init): Use fixup_virtual_upcast_offsets to + ensure that the this offsets for upcasts from virtual bases into + other virtual bases or non-virtual bases are correct at construction + time and destruction time. + * class.c (fixup_vtable_deltas): Modify to fixup all offsets in all + vtables in all virtual bases, instead of just one vtable in each + virtual base. + (fixup_vtable_deltas1): Ditto. + +Tue Apr 18 03:57:35 1995 Michael Meissner (meissner@cygnus.com) + + * Makefile.in (lex.o): Add dependency on c-pragma.h. + + * lex.c (handle_sysv_pragma): Use NULL_PTR and NULL_TREE as + appropriate, instead of 0. + +Mon Apr 17 12:28:42 1995 Jason Merrill + + * decl.c (pushdecl): Use decls_match, not duplicate_decls, for + comparing local and global decls. + +Fri Apr 14 01:46:52 1995 Jason Merrill + + * typeck.c (convert_arguments): Only prohibit passing to ... of + types with non-trivial copy constructors. + + * repo.c (repo_template_used): Don't try to mess with no id. + +Fri Apr 14 23:32:50 1995 Per Bothner + + * decl.c (duplicate_decls): Use cp_warning_at for redundant-decls. + +Thu Apr 13 15:37:42 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-tree.h (current_tinst_level): Delete declaration, since it's + static inside pt.c. + + * typeck.c (build_modify_expr): Catch incompatible array assignment. + + * parse.y (attribute_list, attrib): Rewrite actions to feed the + right stuff to decl_attributes. + +Thu Apr 13 11:24:10 1995 Jason Merrill + + * search.c (dfs_debug_mark): Check for magic virtual like + import_export_vtable. + + * typeck.c (build_binary_op_nodefault): Don't call cp_pedwarn with + four args. + +Wed Apr 12 12:02:57 1995 Jason Merrill + + * decl2.c (finish_file): Move prevtable pass before needs_messing_up + decision. + +Tue Apr 11 11:20:27 1995 Jason Merrill + + * decl.c (finish_decl): If we're writing out a static data member of + a class, we want the debug info for that class. + + * gc.c (build_t_desc): Check linkage of a class properly. + + * class.c (finish_struct): Set the 'headof' offset for the main + vtable properly. + (prepare_fresh_vtable): Fix typeinfo pointer here. + (modify_one_vtable): Instead of here. + +Mon Apr 10 12:15:59 1995 Jason Merrill + + * repo.c (repo_get_id): New function to return the interesting + identifier for a repo entity. + (repo_template_used): Use it. + (repo_template_instantiated): Mark the id as chosen. + (init_repo): Record whether or not the id was chosen. + (finish_repo): Note if an id was newly chosen. + + * pt.c (do_function_instantiation): Call repo_template_instantiated. + (do_type_instantiation): Ditto. Don't diagnose multiple + instantiation. + + * decl2.c (finish_file): Use DECL_NOT_REALLY_EXTERN when deciding + whether or not to synthesize a method. + + Undo these changes: + * class.c (finish_vtbls): build more vtables if flag_rtti is on. + * class.c (modify_all_direct_vtables): ditto. + * init.c (expand_direct_vtbls_init): expand more vtables if + flag_rtti is on. + +Sat Apr 8 17:45:41 1995 Mike Stump + + * gc.c (build_headof): Use ptrdiff_type_node instead of + integer_type_node on pointer arithmetic. + +Sat Apr 8 11:57:04 1995 Jason Merrill + + * typeck.c (build_modify_expr): Undo previous change. + +Thu Apr 6 01:23:50 1995 Jason Merrill + + * Makefile.in (compiler): Remove ../cc1plus before rebuilding it. + + * repo.c (get_base_filename): Put the .rpo file in the directory + with the object file, not the source. + + * typeck.c (build_conditional_expr): Handle pmf's better. + + * repo.c (finish_repo): Also use ASM_OUTPUT_LABELREF to print out + the name of the symbol. + +Wed Apr 5 15:24:12 1995 Jason Merrill + + * repo.c (open_repo_file): Make repo filename DOS-compliant. + (*): Also write a new repo file if some previously-used + templates are no longer used. Only remember the identifier. + + * lex.c (cons_up_default_function): If this function belongs to a + template class, call repo_template_used for it. + + * repo.c (repo_template_used): Using a class means using its vtable, + if any. + (finish_repo): Ditto. + + * typeck.c (build_modify_expr): Only wrap TARGET_EXPRs in RTL_EXPRs + if the type has a complex copy constructor. + + * decl2.c (lang_decode_option): -frepo implies + -fno-implicit-templates. + + * decl.c (start_function): Clear current_{base,member}_init_list. + + * lex.c (init_lex): Also unset *_eq if ! flag_operator_names. + +Tue Apr 4 16:11:08 1995 Jason Merrill + + * decl.c (struct cp_function): Add {base,member}_init_list. + (push_cp_function_context): Save current_{base,member}_init_list. + (pop_cp_function_context): Restore them. + +Mon Apr 3 16:55:08 1995 Jason Merrill + + * repo.c (get_base_filename): Take filename parm, fix logic bug. + + * typeck.c (build_compound_expr): Do not warn about a compound expr + in which the first expression has no side effects. + (build_x_compound_expr): Warn here instead. + (build_conditional_expr): Don't warn about a conditional expression + between an enum and the type it promotes to. + + * init.c (build_new): Handle initialization of arrays of builtins + properly. + +Mon Apr 3 15:08:04 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * repo.c: Include config.h to get definitions of bcopy and rindex + on systems that don't have them (e.g., SVR4). + +Mon Apr 3 14:41:55 1995 Mike Stump + + * decl2.c (finish_table): Pass NULL_TREE instead of init to + finish_decl so that it won't try and do error checking on the + initializer. + +Mon Apr 3 10:45:50 1995 Jason Merrill + + * repo.c (get_base_filename): Analyze COLLECT_GCC_OPTIONS to + determine whether this compile used -c -o. + (open_repo_file): Use get_base_filename. Remove the extension. + (finish_repo): Spit out the values of main_input_filename, + COLLECT_GCC and COLLECT_GCC_OPTIONS. + + * parse.y (structsp): Add TYPENAME_KEYWORD complex_type_name. + +Sun Apr 2 23:43:51 1995 Jason Merrill + + * search.c (compute_access): Don't try to do access control on + nested types. + +Fri Mar 31 10:14:23 1995 Jason Merrill + + * repo.c: New file to handle things repo. + + * pt.c (instantiate_template): Call repo_template_used if the + definition is accessible. + (mark_function_instantiated): Split out from + do_function_instantiation. + (mark_class_instantiated): Split out from do_type_instantiation. + + * parse.y (template_instantiate_once): Call repo_template_used. + + * lex.c (lang_init): Call init_repo. + + * decl2.c: Handle flag_use_repository. + (finish_file): Call finish_repo. + + * decl.c (start_method): Call repo_template_used if this is a + template method. + + * Makefile.in (CXX_OBJS): Add repo.o. + (repo.o): Add dependencies. + + * Make-lang.in (CXX_SRCS): Add repo.c. + + * decl.c (start_function): If DECL_INTERFACE_KNOWN and + DECL_NOT_REALLY_EXTERN are both set, unset DECL_EXTERNAL. + + * typeck.c (build_binary_op_nodefault): Identify the invalid operand + types used. + + * decl.c (duplicate_decls): Propagate DECL_NOT_REALLY_EXTERN. + +Thu Mar 30 17:54:42 1995 Jason Merrill + + * typeck.c (build_binary_op_nodefault): Tidy up use of build_type + and result_type. When checking for comparison between signed + and unsigned, use result_type rather than the (possibly shortened) + type of op0. Also, don't warn about equality comparison of a + signed operand to an unsigned constant that fits in the signed + type. + + * method.c (do_build_copy_constructor): Reverse + current_base_init_list after we've built it up. + +Thu Mar 30 14:35:18 1995 Mike Stump + + * except.c (build_throw): Never warn about the value of throw not + being used. + +Thu Mar 30 13:16:54 1995 Mike Stump + + * except.c (expand_start_catch_block): Check for bad catch parameter + declarations. + +Thu Mar 30 13:06:11 1995 Jason Merrill + + * decl.c (finish_function): Only set DECL_NOT_REALLY_EXTERN if + DECL_EXTERNAL is not already set. + +Thu Mar 30 11:26:24 1995 Mike Stump + + * method.c (emit_thunk): Let poplevel know that the last level is + for a function so it can create a BLOCK_NODE and set DECL_INITIAL. + +Thu Mar 30 11:15:06 1995 Jason Merrill + + * decl2.c (import_export_inline): Don't set DECL_NOT_REALLY_EXTERN + here. + + * decl.c (grokdeclarator): OK, don't abort if we see a decl with + METHOD_TYPE. + (finish_function): Set DECL_EXTERNAL and DECL_NOT_REALLY_EXTERN on + all deferred inlines. + +Wed Mar 29 19:35:02 1995 Jason Merrill + + * cp-tree.h (DECL_THIS_INLINE): New macro. + (DECL_NOT_REALLY_EXTERN): New macro. + (DECL_THIS_STATIC): New macro. + + * decl.c: Lose all references to current_extern_inline. Break + inline semantics into DECL_INLINE for actual inlining and + DECL_THIS_INLINE for the linkage wierdness. Use DECL_THIS_STATIC. + * decl2.c: Use DECL_NOT_REALLY_EXTERN to indicate that we want to + emit an inline here. Associated changes. + * lex.c: Ditto. + * pt.c: Ditto. + * typeck.c: Ditto. + + * call.c (build_method_call): Don't bother trying to handle inlines + specially. + * cvt.c (convert_to_aggr): Ditto. + + * pt.c (do_function_instantiation): Handle instantiation of + public inlines, too. + +Wed Mar 29 16:04:25 1995 Mike Stump + + * except.c (init_exception_processing): Change the interface for + __throw_type_match and add decl for new rtti matching routine + __throw_type_match_rtti. + (build_eh_type): New routine to build a run time descriptor for the + expression given. + (expand_start_catch_block): Update to use new calling convention for + the matcher. + (expand_throw): Update to use build_eh_type. + +Mon Mar 27 07:14:33 1995 Warner Losh + + * g++.c: Removed __NetBSD__ from conditional. + Declare strerror if HAVE_STRERROR is defined; otherwise + declare sys_errlist and sys_nerr. + (my_strerror): New function. + +Tue Mar 28 14:16:35 1995 Jason Merrill + + * search.c (get_binfo): Don't try to be so clever. + + * tree.c (copy_to_permanent): Also suspend_momentary(). + + * cvt.c (cp_convert_to_pointer): Hand off to convert_fn_pointer even + if the types are the same. + + * decl.c (start_function): Handle extern inlines more like C++ says + we should. + + * init.c (build_member_call): Hand constructor calls off to + build_functional_cast. + + * typeck2.c (build_functional_cast): Use DECL_NESTED_TYPENAME to get + the name of the type. + +Tue Mar 28 13:13:56 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Check for the decl returned by + grokfndecl to be null before using build_decl_attribute_variant. + +Mon Mar 27 18:04:41 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * init.c (build_new): Use build_pointer_type instead of + TYPE_POINTER_TO. + +Fri Mar 24 12:11:24 1995 Jason Merrill + + * typeck.c (build_conditional_expr): Handle pmfs. + (convert_for_assignment): Fix pmf support. + + * cvt.c (convert_fn_ptr): Support !flag_vtable_thunks. + (cp_convert_to_pointer): Handle pmfs. + (cp_convert): Pass pmfs to cp_convert_to_pointer. + + * typeck.c (common_type): Handle inheritance for pmfs. + + * typeck2.c (build_m_component_ref): Do access control. + + * typeck.c (comp_target_types): Check for conversion to void * + before checking trickier conversions. + + * decl.c (duplicate_decls): Propagate DECL_ABSTRACT_VIRTUAL_P. + + * pt.c (push_tinst_level): Complain if template instantiation depth + is greater than max_tinst_depth. + + * typeck.c (common_type): Assume that we can call common_type to + unify the target type of a pointer. + +Thu Mar 23 00:48:44 1995 Jason Merrill + + * decl2.c (finish_file): Don't synthesize methods at + finish_vtable_prevardecl time. Do synthesize methods that are not + used, but are public and not external. + + * cvt.c (build_type_conversion): Only give an error if for_sure. + + * typeck.c (comp_target_types): Only support pointer conversions if + nptrs > 0. + +Wed Mar 22 19:30:15 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * init.c (build_new): Catch use of an initializer list where it + shouldn't be. + +Wed Mar 22 16:21:07 1995 Jason Merrill + + * init.c (build_new): Wrap alloc_expr in an RTL_EXPR if nelts is + non-constant. + + * decl2.c: temp_name_counter is now public. + + * decl.c (struct cp_function): Add temp_name_counter field. + (push_cp_function_context): Save it. + (pop_cp_function_context): Restore it. + + * typeck.c (common_type): Handle unifying function types, and unify + unmatched things to void* with a compiler_error, rather than + silently like before. + +Wed Mar 22 15:10:34 1995 Mike Stump + + * decl2.c (finish_prevtable_vardecl, finish_vtable_vardecl): Revert + Brendan's last change and fix latent problem that causes TD entries + to not come out when the things that need them has yet to be + expanded. + +Wed Mar 22 15:12:00 1995 Jason Merrill + + * typeck.c (build_binary_op_nodefault, comparison ops): Update type0 + and type1, since we might have changed op0 or op1. + +Wed Mar 22 13:33:45 1995 Jason Merrill + + * typeck.c (common_type): Don't mess up templates. + +Wed Mar 22 04:56:00 1995 Jason Merrill + + * typeck.c (common_type): Handle ptms properly. Also handle + T* -> void*. + (build_binary_op_nodefault): New variable build_type controls what + type is given to the expression when it is created. Set this to + boolean_type_node for comparison ops instead of using result_type. + (comp_target_types): Allow T * -> void *. + + * cvt.c (cp_convert_to_pointer): Do access control when converting + ptms, too. + +Tue Mar 21 17:25:06 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y (extern_lang_string): Catch use of linkage specs that + aren't all naming the same language. + + * class.c (finish_struct): Delete accidental duplicate code. + +Tue Mar 21 14:00:57 1995 Jason Merrill + + * typeck.c (build_binary_op_nodefault): Disable pedwarns about + comparing functions and incomplete types. + + * decl.c (finish_function): Only unset current_function_decl if + !nested. + (duplicate_decls): Last change went too far; we only want to stop + checking for value/reference ambiguity. + +Tue Mar 21 01:26:39 1995 Mike Stump + + * gc.c (build_generic_desc): Zap the DECL_SIZE so that we can lay it + out fresh, as the new type may be larger. + +Mon Mar 20 19:01:10 1995 Jason Merrill + + * expr.c (extract_init): Try to expand the RTL for the + initialization and figure out what it will look like so we can avoid + run-time initialization. Disabled for now. + (extract_scalar_init): Helper for scalar initialization. + (extract_aggr_init): Helper for aggregate initialization. + + * decl.c (duplicate_decls): Don't complain about ambiguous + declarations. + (obscure_complex_init): Now returns a tree. Call extract_init if + we're optimizing and this is a toplevel decl. + (finish_decl): Update accordingly. + + * lex.c (check_newline): If we're just changing files (not pushing + or popping), update input_file_stack->name. + +Mon Mar 20 17:55:04 1995 Mike Stump + + * pt.c (type_unification): Only TEMPLATE_DECLs are handled right now + in the transitive unification code. + +Mon Mar 20 16:07:50 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (shadow_tag): Don't allow inline, virtual, or explicit on + non-functions. + (grokdeclarator): Don't allow friends to be defined in local classes. + +Sat Mar 18 04:03:33 1995 Jason Merrill + + * decl2.c (finish_prevtable_vardecl): Use DECL_DECLARED_STATIC + rather than DECL_SAVED_INSNS to decide whether or not this method + was declared inline. + + * method.c (synthesize_method): Turn off DECL_INLINE if + function_cannot_inline_p thinks we're too large. + + * typeck.c (build_indirect_ref): Use build_expr_type_conversion. + +Fri Mar 17 17:47:36 1995 Jason Merrill + + * class.c (instantiate_type): Handle pmfs. + + * typeck.c (convert_for_assignment): Check types when assigning one + pmf to another. + + * decl.c (define_label): Fix logic for printing out the name of the + label in an error message. + + * error.c (dump_expr): Support ARRAY_REF. + +Fri Mar 17 17:43:02 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl2.c (finish_vtable_vardecl): Call build_t_desc here. + (finish_prevtable_vardecl): Instead of here. + +Fri Mar 17 14:40:45 1995 Jason Merrill + + * decl.c (expand_static_init): Also use expand_aggr_init if the + initializer is a TREE_LIST. + (grokdeclarator): Only pedwarn about extra qualification if -pedantic. + + * pt.c (unify): Fix unification of return type. + + * expr.c (fixup_result_decl): Use store_expr, rather than + emit_move_insn, to move the return value into the place where + callers will expect it. + +Thu Mar 16 22:05:25 1995 Jason Merrill + + * init.c (build_offset_ref): Call assmble_external on functions. + * typeck.c (build_component_ref): Ditto. + +Thu Mar 16 20:28:16 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (struct saved_scope): Add members base_init_list and + member_init_list. + (push_to_top_level): Save current_base_init_list and + current_member_init_list to them. + (pop_from_top_level): Put it back. + +Thu Mar 16 19:21:14 1995 Jason Merrill + + * pt.c (instantiate_template): Call assemble_external. + +Thu Mar 16 18:07:54 1995 Brendan Kehoe (brendan@phydeaux.cygnus.com) + + * class.c: Include rtl.h, to get NULL_RTX. + (finish_struct): Also zero out DECL_SAVED_INSNS, to avoid problems + on hosts with different sizes for each part of the union. + * tree.c: Also include rtl.h. + (layout_basetypes): Same change for DECL_SAVED_INSNS. + +Thu Mar 16 13:57:36 1995 Jason Merrill + + * pt.c (unify): Fix array domain unification for 64-bit targets. + + * decl2.c (finish_file): Push bizarre type decl before walking the + vtables the first time. + (walk_vtables): OK, don't set prev to vars if the vardecl_fn messed + with TREE_CHAIN (prev). + + * init.c (emit_base_init): Use convert_pointer_to_real instead of + convert_pointer_to when converting to a direct base. + +Wed Mar 15 20:26:29 1995 Mike Stump + + * pt.c (type_unification): Handle transitive unification better. + +Wed Mar 15 13:56:16 1995 Jason Merrill + + * decl2.c (walk_vtables): Always set prev to vars. + (mark_vtable_entries): Call assemble_external on the vtable entries. + + * class.c (finish_struct): Set the vtable's size to NULL_TREE before + calling layout_decl, so that it gets updated properly. + + Finally re-enable dynamic synthesis. This time it works. + * method.c (synthesize_method): Pass decl_function_context (fndecl) + to {push,pop}_cp_function_context. + * decl.c (push_cp_function_context): Now takes a tree argument. + (pop_cp_function_context): Ditto. + * call.c (build_method_call): Enable synthesis. + * lex.c (cons_up_default_function): Ditto. + +Tue Mar 14 19:14:19 1995 Doug Evans + + * parse.y (setattrs): Chain onto prefix_attributes rather than + setting it. + +Wed Mar 15 13:00:00 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (pushdecl): Check if the type of the VAR_DECL is an + error_mark_node before trying to read TYPE_LANG_SPECIFIC. + +Mon Mar 13 21:00:28 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator, case ARRAY_REF): Wrap the exp with fold, + and convert the size and integer_one_node to the index type. + +Mon Mar 13 08:01:02 1995 Jason Merrill + + * typeck.c (get_member_function_from_ptrfunc): Save the instance + argument, and tack it onto the front of the COND_EXPR to make the + semantics come out right. Grab the instance argument from + '*instance_ptrptr', rather than having it passed in separately. + + * various: Change various consed-up comparison operations to have + boolean type. Remove the instance argument in calls to + get_member_function_from_ptrfunc. + + * error.c (dump_expr): Dump true and false as "true" and "false". + + * decl2.c (finish_file): Also set DECL_STATIC_FUNCTION_P on the + global init function. + + * decl.c (finish_function): Only set DECL_EXTERNAL here if the + inline function is public. + +Sat Mar 11 00:58:03 1995 Jason Merrill + + * init.c (is_friend): Be more careful about checking + DECL_CLASS_CONTEXT on non-member functions. + + * decl2.c (finish_vtable_vardecl): Don't bother calling + assemble_external here. + (prune_vtable_vardecl): New function that just splices out the + vtable decl from the top-level decls. + (import_export_inline): Unset DECL_EXTERNAL at first. + (finish_file): Don't bother calling assemble_external here. Do + splice out all of the vtables. + +Fri Mar 10 14:42:29 1995 Jason Merrill + + * decl.c (finish_function): If we're not emitting the function yet, + call assemble_external for it. + + * decl2.c (finish_prevtable_vardecl): Don't call mark_vtable_entries + here. + (finish_vtable_vardecl): Don't do the linkage deduction thing here. + Also don't splice out the current vtable if it is unused. + (finish_file): Move the second walk_vtables and the synthesis check + inside the 'reconsider' loop. Move thunk emission after the + 'reconsider' loop. + +Thu Mar 9 16:28:16 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * pt.c (tsubst): Don't bother calling cp_build_type_variant, since it + was passing bogus values for readonly and volatile from the original + template decl, not the resultant type of the tsubst call. + + * class.c (duplicate_tag_error): Use cp_error_at to point out the + previous definition of the tag. + +Thu Mar 9 10:46:17 1995 Jason Merrill + + * decl.c (start_function): Clear base_init_insns and protect_list. + (struct cp_function): Add base_init_insns field. + (push_cp_function_context): Also save base_init_insns. + (pop_cp_function_context): Also restore base_init_insns. + +Wed Mar 8 13:31:44 1995 Jason Merrill + + * init.c (member_init_ok_or_else): Check for initializing a static + member here. + (emit_base_init): Instead of here. + +Tue Mar 7 16:03:26 1995 Jason Merrill + + * call.c (build_method_call): Disable synthesis as needed. + * lex.c (cons_up_default_function): Ditto. + +Tue Mar 7 10:14:29 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y: New rules to allow attributes in a prefix position. + (prefix_attributes): New variable. Pass it into cplus_decl_attributes. + (setattr): New rule. + (reserved_declspecs, declmods): Catch attributes here. + * decl2.c (cplus_decl_attributes): Add PREFIX_ATTRIBUTES argument. + * decl.c (duplicate_decls): Pass DECL_MACHINE_ATTRIBUTES to + descendent typedef. + (grokdeclarator): Added code to support machine attributes. + * Makefile.in (stamp-parse): Expect 5 shift/reduce failures. + +Mon Mar 6 15:07:02 1995 Jason Merrill + + * call.c (build_method_call): Don't synthesize methods outside of a + function. + + Make base initialization more re-entrant so that synthesis on the + fly will work (and, eventually, template instantation on the fly). + * init.c (sort_member_init): Don't bother with members that can't be + initialized. Reorganize a bit. Don't initialize base members here. + (sort_base_init): New function, like sort_member_init, but for base + classes. Steals some code from emit_base_init. + (emit_base_init): Simplify. Call sort_{member,base}_init before + doing any initialization, so we don't have to save + current_{member,base}_init_list in push_cp_function_context. + (expand_aggr_vbase_init_1): Adjust for sort_base_init. + (expand_aggr_vbase_init): Simplify. + * decl.c (struct cp_function): Add protect_list field. + (push_cp_function_context): Also save protect_list. + (pop_cp_function_context): Also restore protect_list. + * call.c (build_method_call): Enable synthesis at point of call. + * lex.c (cons_up_default_function): Ditto. + + * parse.y: Turn -ansi checks back into -pedantic checks. + + * init.c (build_new): Fix -fcheck-new for array new. + +Sat Mar 4 15:55:42 1995 Fergus Henderson + + * typeck.c (build_compound_expr): warn if left-hand operand of + comma expression has no side-effects. + +Fri Mar 3 15:16:45 1995 Jason Merrill + + * parse.y (primary): Change 'object qualified_id *' rules to 'object + overqualified_id *'. + +Fri Mar 3 12:48:17 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y (unary_expr): Catch doing sizeof an overloaded function. + Make the error look the same as the one we issue in c_sizeof. + + * typeck.c (build_binary_op_nodefault): Give an error for trying + to compare a pointer-to-member to `void *'. + +Fri Mar 3 11:28:50 1995 Jason Merrill + + * typeck.c (build_unary_op): Handle bool increment with smoke and + mirrors here, rather than in expand_increment where it belongs, + because Kenner doesn't agree with me. + +Fri Mar 3 00:08:10 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokparms): Catch a PARM_DECL being used for a default + argument as well. + +Thu Mar 2 20:05:54 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * init.c (build_new): Don't allow new on a function type. + + * parse.y (primary): Avoid a crash when seeing if the arg is of + the same type as that given for the typespec in an explicit dtor call. + +Thu Mar 2 00:49:38 1995 Jason Merrill + + * decl.c (finish_function): Change test for calling + mark_inline_for_output. + +Wed Mar 1 11:23:46 1995 Jason Merrill + + * typeck.c (build_modify_expr): Complain if + build_default_binary_type_conversion fails. + + * init.c (expand_default_init): Handle arguments of unknown type + properly. + + * cvt.c (build_expr_type_conversion): Only complain about ambiguity + if 'complain'. + * various: Pass 'complain'. + + * typeck.c (comptypes): Be more picky about comparing UPTs. + +Wed Mar 1 11:03:41 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): If declarator is null, say that the + type used has an incomplete type. + +Wed Mar 1 10:06:20 1995 Jason Merrill + + * pt.c (instantiate_template): Copy the template arguments to the + permanent_obstack. Also use simple_cst_equal to compare them when + looking for a previous instantiation. + + * tree.c (make_deep_copy): Support copying INTEGER_TYPEs (assuming + they are array domain types). + +Tue Feb 28 23:24:55 1995 Jason Merrill + + * cp-tree.h: Define WANT_* constants for passing to + build_expr_type_conversion. + * cvt.c (build_expr_type_conversion): New function to build + conversion to one of a group of suitable types. + (build_default_binary_type_conversion): Use it. + * decl2.c (grok_array_decl): Ditto. + * typeck.c (build_unary_op): Ditto. + (build_array_ref): Tidy up a bit. + (build_binary_op): Ditto. + +Tue Feb 28 19:57:31 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Don't allow decl of an argument as `void'. + +Tue Feb 28 17:23:36 1995 Jason Merrill + + * parse.y (typed_declspecs1): Add 'typespec reserved_typespecquals + reserved_declspecs' rule. + + * parse.y (expr_or_declarator): Remove notype_qualified_id rule. + (direct_notype_declarator): Ditto. + (complex_direct_notype_declarator): Add notype_qualified_id rule. + + * lex.c (real_yylex): Handle :> digraph properly. + +Tue Feb 28 12:26:29 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Check if it's a friend, not if it's + non-virtual, that's being initialized. Move the check up to + before FRIENDP would get cleared. Catch an unnamed var/field + being declared void. Say just `field' instead of `structure field' + in the error message. Only go for the operator name if DECLARATOR + is non-null. + +Tue Feb 28 00:08:01 1995 Jason Merrill + + * decl.c (start_function): Complain about abstract return type. + (grokdeclarator): Complain about declaring constructors and + destructors to be const or volatile. Complain about declaring + destructors to be static. + + * pt.c (uses_template_parms): Handle pmfs. + + * decl.c (grokdeclarator): Don't call variable_size for array bounds + that only depend on template constant parameters. + +Mon Feb 27 15:38:16 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * error.c (dump_decl): Only look to see if it's a vtable if we + actually have a name to check out. + +Mon Feb 27 13:37:53 1995 Jason Merrill + + * cvt.c (convert_to_aggr): Lose misleading shortcut. + +Sun Feb 26 17:27:32 1995 Doug Evans + + * decl.c (set_nested_typename): Always set DECL_IGNORED_P, + not just for dwarf. + +Sun Feb 26 00:10:18 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Don't allow a static member to be + declared `register'. + + * init.c (make_friend_class): Move up to a pedwarn for the warning + about a class declaring friends with itself. + + * decl.c (grokdeclarator): You can't do `volatile friend class foo' + or `inline friend class foo'. Only try to make a friend out of + TYPE if we didn't already reset it to integer_type_node. + +Sat Feb 25 22:32:03 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Don't allow initialization of a + non-virtual function. + + * decl.c (start_function): Do a pedwarn if we're changing `main' + to have an int return type. + +Sat Feb 25 00:02:05 1995 Jason Merrill + + * typeck.c (build_modify_expr): Handle simple assignment from + TARGET_EXPRs by building up an RTL_EXPR to force expansion. Whew. + +Fri Feb 24 18:27:14 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Also don't allow virtual outside of a + class decl for a scope method definition performed at global binding. + + * init.c (build_offset_ref): Don't allow creation of an OFFSET_REF + of a bitfield. + + * decl.c (grokdeclarator): Don't allow a const to be declared mutable. + + * typeck.c (build_binary_op): Return an error_mark_node if either + one of the args turned into an error_mark_node when we tried to + use default_conversion. + + * typeck.c (build_unary_op): Forbid using postfix -- on a bool. + + * decl.c (grokdeclarator): Allow `signed' and `unsigned' to be + used on `__wchar_t'. + +Fri Feb 24 13:59:53 1995 Mike Stump + + * except.c (end_protect_partials): Do it the right way. + +Wed Feb 22 15:42:56 1995 Jason Merrill + + * typeck.c (build_binary_op_nodefault): Upgrade warning about + comparing distinct pointer types to pedwarn. + + * typeck2.c (digest_init): Cope with extra braces. + + * typeck.c (build_binary_op_nodefault): Use tree_int_cst_sgn instead + of INT_CST_LT (..., interger_zero_node). + +Wed Feb 22 14:45:52 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * except.c [!TRY_NEW_EH] (end_protect_partials): Define dummy + function for systems that don't have EH. + +Tue Feb 21 19:18:31 1995 Jason Merrill + + * call.c (can_convert_arg): Like can_convert, but takes an arg as + well. + + * pt.c (type_unification): Allow implicit conversions for parameters + that do not depend on template parameters. + +Tue Feb 21 18:43:48 1995 Douglas Rupp (drupp@cs.washington.edu) + + * Make-lang.in, config-lang.in: ($exeext): New macro. + * Make-lang.in: Try a "cp" if "ln" fails. + * cp-tree.h (decl_attributes): Added argument. + * decl2.c (cplus_decl_attribute): Add arg to decl_attributes. + * cp/g++.c: Added #ifdefs for sys/file.h and process.h for NT. + Modified spawnvp to have to correct number of arguments for OS/2, NT. + +Tue Feb 21 18:36:55 1995 Mike Stump + + * decl.c (finish_function): Add calls to end_protect_partials to end + the exception region that protects constructors so that partially + constructed objects can be partially destructed when the constructor + throws an exception. + * init.c (perform_member_init, sort_member_init, emit_base_init): + Added support for partially constructed objects. + * init.c (build_partial_cleanup_for): New routine to do partial + cleanups of a base class. + * decl2.c (finish_file): Move the emitting of the exception table + down, after we emit all code that might have exception regions in + them. + * except.c (end_protect_partials, might_have_exceptions_p): New + routines. + (emit_exception_table): Always output table if called. + * cp-tree.h (protect_list, end_protect_partials, + might_have_exceptions_p, emit_exception_table): Added. + +Tue Feb 21 16:05:59 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * gc.c (build_typeid): Pass a NULL_TREE, not the bogus, unused + address of a local variable. + * class.c (build_vfn_ref): Only try to build the PLUS_EXPR if we + were given a non-null PTR_TO_INSTPTR. + +Tue Feb 21 01:53:18 1995 Jason Merrill + + * decl.c (duplicate_decls): Always lay out the merged decl. + + * decl2.c (finish_vtable_vardecl): Don't do vtable hack on templates. + (finish_prevtable_vardecl): Ditto. + + * method.c (synthesize_method): Set interface_{unknown,only} + according to the settings for our class, not the file where it comes + from. + +Sat Feb 18 12:26:48 1995 Mike Stump + + * except.c: Handle systems that define __i386__ but not __i386. + +Fri Feb 17 15:31:31 1995 Jason Merrill + + * decl2.c (reparse_decl_as_expr): Support being called without a + type argument. + + * parse.y (primary): Add '(' expr_or_declarator ')'. Adds 4 r/r + conflicts. Sigh. + +Fri Feb 17 12:02:06 1995 Mike Stump + + * parse.y (template_def, fndef, fn.def1, return_init, condition, + initdcl0, initdcl, notype_initdcl0, nomods_initdcl0, + component_decl_1, after_type_component_declarator0, + notype_component_declarator0, after_type_component_declarator, + notype_component_declarator, after_type_component_declarator, + full_parm, maybe_raises, exception_specification_opt): Fix up, + include exception_specification_opt maybeasm maybe_attribute and + maybe_init if missing. Rename maybe_raises to + exception_specification_opt to match draft wording. Use maybe_init + to simplify rules. + +Fri Feb 17 01:54:46 1995 Jason Merrill + + * init.c (build_new): Set TREE_NO_UNUSED_WARNING on COMPOUND_EXPRs + built for news of scalar types. + +Thu Feb 16 17:48:28 1995 Jason Merrill + + * typeck.c (build_binary_op_nodefault): Update code for warning + about signed/unsigned comparisons from C frontend. Realize that the + code in the C frontend is, if anything, even more bogus. Fix it. + (build_binary_op): Undo default_conversion if it wasn't useful. + + * typeck.c (build_unary_op, ADDR_EXPR): Lose bogus special case for + PRE*CREMENT_EXPR. + + * decl2.c (import_export_vtable): Don't try the vtable hack + if the class doesn't have any real non-inline virtual functions. + (finish_vtable_vardecl): Don't bother trying to find a non-inline + virtual function in a non-polymorphic class. + (finish_prevtable_vardecl): Ditto. + + * decl2.c (import_export_vtable): Use and set DECL_INTERFACE_KNOWN. + + * cp-tree.h (DECL_INTERFACE_KNOWN): Use DECL_LANG_FLAG_5. + + * init.c (expand_virtual_init): Always call assemble_external. + + * class.c (build_vfn_ref): Always call assemble_external. + (build_vtable): Always call import_export_vtable. + (prepare_fresh_vtable): Ditto. + (add_virtual_function): Don't bother setting TREE_ADDRESSABLE. + +Thu Feb 16 03:28:49 1995 Jason Merrill + + * class.c (finish_struct): Use TYPE_{MIN,MAX}_VALUE to determine + whether an enumerated type fits in a bitfield. + +Wed Feb 15 15:38:12 1995 Jason Merrill + + * class.c (grow_method): Update method_vec after growing the class + obstack. + +Wed Feb 15 13:42:59 1995 Mike Stump + + * parse.y (handler_seq): Push a level for the catch parameters. + +Wed Feb 15 12:42:57 1995 Jason Merrill + + * init.c (emit_base_init): Update BINFO_INHERITANCE_CHAIN on my + bases, in case they've been clobbered. + +Wed Feb 15 12:07:29 1995 Mike Stump + + * class.c (finish_base_struct): Set up BINFO_INHERITANCE_CHAIN here, + so that one day it will always be valid. + * tree.c (propagate_binfo_offsets, layout_vbasetypes): Ditto. + + * cp-tree.h (copy_binfo): Removed, unused. + * tree.c (copy_binfo): Ditto. + +Wed Feb 15 00:05:30 1995 Jason Merrill + + * init.c (build_new): Save the allocation before calling + expand_vec_init on it. + + * decl.c (finish_enum): The TYPE_PRECISION of the enum type mush + match the TYPE_PRECISION of the underlying type for constant folding + to work. + +Tue Feb 14 15:31:25 1995 Mike Stump + + * except.c (push_eh_entry, expand_start_all_catch, + expand_leftover_cleanups, expand_end_catch_block): Keep track of + the context in which the exception region occurs. + (build_exception_table): If the region was not output, don't output + the entry in the eh table for it. + +Tue Feb 14 02:15:43 1995 Jason Merrill + + * init.c (expand_default_init): Only use a previous constructor call + if it's a call to our constructor. Does the word "Duh" mean + anything to you? + + * decl.c (grokparms): Fine, just don't call + convert_for_initialization at all. OK? Happy now? + +Mon Feb 13 02:23:44 1995 Jason Merrill + + * cp-tree.h (CLASSTYPE_FIRST_CONVERSION): Make sure that the class + method vector has a second element before returning it. + + * decl.c (grokparms): Don't strip REFERENCE_TYPE before calling + convert_for_initialization. + +Sun Feb 12 03:57:06 1995 Jason Merrill + + * typeck.c (build_modify_expr): Compare function name to + constructor_name (current_class_type) instead of current_class_name. + + * decl.c (grokparms): Don't do anything with the return value of + convert_for_initialization. + + * error.c (dump_decl): Also dump_readonly_or_volatile on the decl. + + * decl.c (duplicate_decls): Tweak error message. + + * typeck.c (build_const_cast): Implement checking. + (build_reinterpret_cast): Implement some checking. + + * cp-tree.h (CONV_FORCE_TEMP): Require a new temporary when + converting to the same aggregate type. + (CONV_STATIC_CAST): Include it. + (CONV_C_CAST): Ditto. + * cvt.c (convert_force): Use CONV_C_CAST instead of CONV_OLD_CONVERT. + (cp_convert): Only force a new temporary if CONV_FORCE_TEMP. + +Fri Feb 10 16:18:52 1995 Jason Merrill + + * typeck.c (build_c_cast): Use non_lvalue to tack something on + where necessary. + + * decl.c (auto_function): Now a function. + * except.c (init_exception_processing): terminate, unexpected, + set_terminate, and set_unexpected have C++ linkage. + + * typeck.c (build_unary_op, TRUTH_NOT_EXPR): Use convert instead of + truthvalue_conversion for converting to bool, as it handles + user-defined conversions properly. + (condition_conversion): Ditto. + + * except.c (expand_throw): Don't call convert_to_reference. + Pass the correct parameters to build_new. + + * method.c (do_build_assign_ref): Don't use access control when + converting to a base reference here. + (do_build_copy_constructor): Or here. + + * init.c (build_new): Unset TREE_READONLY on the dereferenced + pointer before assigning to it. + + * decl.c (maybe_build_cleanup): Don't bother stripping const here. + + * decl2.c (delete_sanity): You can now delete pointer to const. + +Fri Feb 10 13:28:38 1995 Jason Merrill + + * decl.c (finish_function): Don't rely on actual parameters being + evaluated left-to-right. + * except.c (expand_end_catch_block): Ditto. + +Fri Feb 10 00:52:04 1995 Jason Merrill + + * tree.c (real_lvalue_p): Like lvalue_p, but class temps aren't + considered lvalues. + * cvt.c (convert_to_reference): Use real_lvalue_p instead of + lvalue_p. + + * cvt.c (build_type_conversion_1): Don't call convert on aggregate + types. + (convert_to_reference): Fix erroneous text substitution. + + * typeck2.c (initializer_constant_valid_p): Update from C frontend. + Add new argument to all callers. + + * typeck.c (convert_arguments): Check for error_mark_node before + trying to do anything with the actual parameter. + + * typeck.c (condition_conversion): Build up a CLEANUP_POINT_EXPR and + fold it. + (bool_truthvalue_conversion): Remove. Fix all callers to call + truthvalue_conversion instead. + (various): Fold CLEANUP_POINT_EXPRs. + + * parse.y (conditions): Call condition_conversion rather than + building up a CLEANUP_POINT_EXPR. + + * pt.c (end_template_decl): Don't warn_if_unknown_interface here + under -falt-external-templates. + +Thu Feb 9 05:24:10 1995 Jason Merrill + + * init.c (build_new): Complain about new of const type without + initializer. Other cleanup. + + * call.c (compute_conversion_costs): Don't call + build_type_conversion with a reference type; convert to the target + type and check its lvaluetude. + * cvt.c (convert_to_reference): Ditto. + + * cvt.c (build_type_conversion_1): There will never be any need to + dereference references here now. + +Thu Feb 9 00:37:47 1995 Mike Stump + + * except.c (expand_builtin_throw): Make sure we only `use' the + value of return_val_rtx. + +Wed Feb 8 15:45:55 1995 Jason Merrill + + * parse.y (structsp): Don't complain about declaring a type being + defined to be a friend. + + * decl2.c (warn_if_unknown_interface): Note the template in question + and the point of instantiation, for -falt-external-templates. + * lex.c (reinit_parse_for_method): Pass the decl to + warn_if_unknown_interface. + * pt.c (instantiate_template): Ditto. + (end_template_decl): Ditto. + + * decl.c (set_nested_typename): Set IDENTIFIER_TYPE_VALUE on the + nested name again, to make local classes work a bit better. + + * typeck.c (build_function_call_real): Dereference reference after + checking for incomplete type. + + * init.c (build_new): Accept new of const and volatile types. + +Wed Feb 8 14:04:16 1995 Jason Merrill + + * decl.c (grokdeclarator): Fix error message. + +Wed Feb 8 03:16:15 1995 Jason Merrill + + * typeck.c (convert_for_initialization): Do bash arrays when + converting to a reference to non-array. + +Tue Feb 7 15:50:33 1995 Jason Merrill + + * cvt.c (cp_convert): Don't call convert_to_reference, or + automatically dereference references. Do pass reference conversions + to cp_convert_to_pointer. + (cp_convert_to_pointer): Support references. + + * call.c (build_method_call): Don't build up a reference to the + parameter here; let build_overload_call handle that. + + * typeck.c (build_c_cast): Call convert_to_reference directly if + converting to a reference type. + * method.c (do_build_copy_constructor): Ditto. + * method.c (do_build_copy_constructor): Ditto. + (do_build_assign_ref): Ditto. + + * call.c (build_method_call): Dereference a returned reference. + * typeck.c (build_function_call_real): Ditto. + + * decl.c (xref_basetypes): Check for unions with basetypes here. + (xref_tag): Instead of here. + + * pt.c (process_template_parm): Template type parm decls are + artificial. + +Mon Feb 6 04:32:09 1995 Jason Merrill + + * parse.y (typed_declspecs): Add missing semicolon. + (do_xref_defn): Resurrect. + (named_class_head_sans_basetype): Move template specialization + definition cases to named_class_head_sans_basetype_defn. + + * decl2.c (grokfield): Call pushdecl_class_level after setting the + TYPE_NAME, not before. + +Sun Feb 5 02:50:45 1995 Jason Merrill + + * call.c (convert_harshness): Don't call sorry here. Don't allow + conversions between function pointer types if pedantic. + + * pt.c (overload_template_name): Pass globalize=1 to xref_tag. + + * lex.c (cons_up_default_function): Use the full name for the return + type of op=. + + * decl.c (set_nested_typename): Don't worry about anonymous types, + as they already have a unique name. + (pushdecl): Remove redundant set_nested_typename + (xref_tag): Split out base handling into xref_basetypes. + + * cp-tree.h (TYPE_INCOMPLETE): New macro; TEMPLATE_TYPE_PARMs are + not considered incomplete even though their definition is unknown. + + * decl.c (xref_defn_tag): Lose. + (xref_tag): xref_next_defn = ! globalize. + (pushdecl): Don't set DECL_NESTED_TYPENAME on artificial decls. The + ones that should have it set will have it set by pushtag. + (pushdecl_class_level): Ditto. + (pushtag): Tidy up a bit. + (set_nested_typename): Push a decl for the nested typename from + here, rather than from xref_defn_tag. + + * parse.y (do_xref): Lose. + (named_class_head): If we see 'class foo:' we know it's a + definition, so don't worry about base lists for non-definitions. + + * pt.c (push_template_decls): Template parm decls are artificial. + + * decl.c (duplicate_decls): Restore check for qualifier + disagreement for non-functions. + (decls_match): Remove check for qualifier disagreement. + +Fri Feb 3 14:58:58 1995 Jason Merrill + + * decl.c (grok_reference_init): Convert initializer from + reference. + * typeck.c (convert_for_initialization): Ditto. + + * decl.c (duplicate_decls): Propagate DECL_NESTED_TYPENAME. + + * cvt.c (cp_convert): Don't convert to the same class type by just + tacking on a NOP_EXPR. + (convert_to_reference): Use comp_target_types instead of comptypes + so that we don't allow conversions two levels down. + +Thu Feb 2 15:07:58 1995 Jason Merrill + + * class.c (build_vbase_path): Bash types to make the backend happy. + * cvt.c (build_up_reference): Bash the types bashed by + build_vbase_path to be reference types instead of pointer types. + (convert_to_reference): Ditto. + + * typeck.c (build_c_cast): Don't strip NOPs if we're converting to a + reference type. + + * parse.y (structsp): Put back error for 'struct B: public A;'. + +Wed Feb 1 23:02:06 1995 Mike Stump + + * except.c: Add support for mips systems that don't define __mips + but do define mips, like Ultrix. + +Wed Feb 1 22:39:07 1995 Mike Stump + + * except.c: Add support for exception handling on the Alpha. + +Wed Feb 1 10:12:14 1995 Mike Stump + + * decl2.c (finish_file): Fix bug in Jan 31st change. + +Tue Jan 31 16:59:15 1995 Gerald Baumgartner (gb@lorenzo.cs.purdue.edu) + + * sig.c (build_signature_pointer_or_reference_type): Don't set + IS_AGGR_TYPE for signature pointers/reference so expand_default_init + doesn't expect to find a copy constructor. + * call.c (build_method_call): Treat signature pointers/reference + as if IS_AGGR_TYPE were set. + +Tue Jan 31 13:28:56 1995 Mike Stump + + * gc.c (get_typeid): Pawn off error messages to build_t_desc. + (build_t_desc): Inform the user here if they try and build + with -frtti and don't include . + + * decl2.c (finish_prevtable_vardecl): Support rescanning. + (finish_file): Move finish_prevtable_vardecl up to before the global + initializers are done as tdecls are initialized in the global + initializer. Also Pick up any new tdecls or vtables needed by + synthesized methods. + + * class.c (finish_struct): Simplify. We have to do rtti scanning at + end, so we might as well do all of it there. + +Tue Jan 31 05:35:02 1995 Jason Merrill + + * call.c (build_method_call): Fix -fthis-is-variable for 32-bit + targets, too. + +Tue Jan 31 00:11:04 1995 Mike Stump + + * decl2.c (finish_prevtable_vardecl): New routine, mostly split from + finish_vtable_vardecl. It has the first half functionality from + that routine. + * decl2.c (finish_vtable_vardecl): Update to not include stuff not + in finish_prevtable_vardecl. + * decl2.c (finish_file): Call finish_prevtable_vardecl. + * gc.c (build_generic_desc): Allow it to be called when not at the + global binding layer, but behave as if we were. + (build_t_desc): Rearrange a bit so that it really works and is + easier to follow. + * class.c (finish_struct): Don't decide on tdecls here, as we have + to wait until the end of the file in general to decide whether or + not they come out. + +Mon Jan 30 01:00:40 1995 Jason Merrill + + * init.c (build_delete): Check access to operator delete before + calling the destructor. + * method.c (build_opfncall, DELETE_EXPR): build_method is allowed to + return error_mark_node. + * call.c (build_method_call): Use the one-argument op delete even if + it's an error. + + * init.c (build_new): Fix -fthis-is-variable support. + * call.c (build_method_call): Ditto. + + * call.c (convert_harshness): Make conversion from a pointer to bool + worse than conversion to another pointer. + +Sat Jan 28 16:46:10 1995 Jason Merrill + + * init.c (build_new): Check new return value if -fcheck-new. + + * lex.c (check_newline): Clear end_of_file when we're done, too. + +Sat Jan 28 10:38:39 1995 Mike Stump + + * decl2.c (finish_vtable_vardecl): Make rtti TD tables follow + vtables whereever they go. + + * gc.c (build_t_desc): Remove old way of setting it up, as it wasn't + right. + +Sat Jan 28 09:10:44 1995 Mike Stump + + * decl2.c (finish_vtable_vardecl): Now set the + interface/implementation of vtables on the first virtual function, + if one exists, otherwise we use the old method. This is a major win + in terms of cutting down the size of objects and executables in + terms of text space and data space. Now most of the savings that + #pragma interface/implementation gives is automatic in a fair number + of cases. + +Sat Jan 28 04:57:33 1995 Jason Merrill + + * decl.c (grokdeclarator): Discard the template parameters in a + template constructor declaration so that the function is always + named constructor_name (ctype). + + * lex.c (check_newline): Use ungetc to put back the character before + calling HANDLE_PRAGMA. + +Fri Jan 27 17:23:47 1995 Mike Stump + + * decl2.c (check_classfn): If the cname is T and fn_name is T, + make sure we still match them. + +Fri Jan 27 16:32:10 1995 Jason Merrill + + * parse.y: Add END_OF_LINE token. + + * lex.c (check_newline): Set linemode when we see a # directive, and + unset it when we're done. Turn all 'return's into 'goto skipline'. + Fix all uses of '\n', since we won't see it anymore. Put back the + character we read before checking for a sysv or target pragma. + (real_yylex): If we see an EOF in linemode, return END_OF_LINE. + (handle_sysv_pragma): Don't look at the input stream; quit when we + see an END_OF_LINE token. + + * input.c (getch): Return EOF if we're in line mode and at the end + of a line. + (put_back): Don't put back an EOF. + +Thu Jan 26 19:26:34 1995 Mike Stump + + * except.c (expand_throw): Do the newing of the exception object + before we load the type descriptor or the address so that we don't + wipe any of the values out. + +Thu Jan 26 19:20:00 1995 Mike Stump + + * except.c (init_exception_processing): Don't use r12 on the rs6000. + +Tue Jan 24 16:36:31 1995 Jason Merrill + + * decl.c (grokparms): Don't try to build up a reference at this point. + + * typeck2.c (build_functional_cast): Don't assume that a NOP_EXPR + will suffice to convert from integer_zero_node. + +Wed Jan 25 15:02:09 1995 David S. Miller (davem@nadzieja.rutgers.edu) + + * class.c (instantiate_type): Change error message text. + * typeck2.c (store_init_value): Likewise. + +Mon Jan 23 21:57:14 1995 Mike Stump + + * pt.c (tsubst): When we copy a node, don't forget to copy + TREE_CHAIN, we use it later. + +Mon Jan 23 03:33:47 1995 Jason Merrill + + * typeck.c (convert_for_assignment): Initialize variable before use. + +Fri Jan 20 01:17:59 1995 Jason Merrill + + * g++.c (main): Link with both libstdc++ and libg++ if called as + something ending with "g++", otherwise only libstdc++. Move -lm to + the end of the line. + +Thu Jan 19 15:43:11 1995 Jason Merrill + + * call.c (build_method_call): Don't mess with 'this' before calling + compute_conversion_costs. + +Wed Jan 18 15:40:55 1995 Jason Merrill + + * search.c (get_matching_virtual): Give line number for previous + declaration. + + * call.c (convert_harshness): Handle conversions to references + better. + + * cvt.c (build_up_reference): OK, handle {MIN,MAX}_EXPR *properly*. + +Wed Jan 18 15:21:38 1995 Mike Stump + + * class.c (instantiate_type): Use DECL_CHAIN to walk lists instead, + as the TREE_CHAIN for methods will take us to the next differently + named function, DECL_CHAIN won't. + +Wed Jan 18 14:26:59 1995 Jason Merrill + + * tree.c (lvalue_p): Handle {MIN,MAX}_EXPR. + + * decl2.c (lang_decode_option): -Wall implies -Wparentheses. + warn_parentheses defaults to 0. + + * decl.c (grokparms): Put back call to require_instantiated_type. + +Tue Jan 17 19:56:15 1995 Mike Stump + + * except.c (exception_section): Use the data section on the rs6000. + Change calling convention for named_section. + +Wed Jan 17 18:20:57 1994 Fergus Henderson + + * cp-tree.h : Make if (x=0) warn with wall + * parse.y : Make if (x=0) warn with wall + +Tue Jan 17 14:12:00 1995 Jason Merrill + + * decl.c (BOOL_TYPE_SIZE): BITS_PER_WORD if SLOW_BYTE_ACCESS, + BITS_PER_UNIT otherwise. + + * search.c (get_matching_virtual): Don't check the binfo if the + types are the same. + + * cvt.c (cp_convert): Just call truthvalue_conversion to convert to + bool. + +Mon Jan 16 13:28:48 1995 Jason Merrill + + * various: Use boolean_type_node, boolean_true_node, + boolean_false_node. + + * search.c (get_matching_virtual): Allow covariant returns that + don't require pointer adjustment. + + * typeck.c (build_conditional_expr): Don't call default_conversion + on ifexp. + + * cvt.c (build_up_reference): Handle MIN_EXPR and MAX_EXPR. + + * decl.c (grokdeclarator): Upgrade warning about &const to pedwarn. + +Sun Jan 15 22:17:32 1995 dcb@lovat.fmrco.COM (David Binderman) + + * pt.c (do_function_instantiation): Free targs once we're done. + +Sun Jan 15 22:17:32 1995 Jason Merrill + + * decl.c (BOOL_TYPE_SIZE): Defaults to BITS_PER_WORD. + (init_decl_processing): Use BOOL_TYPE_SIZE instead of CHAR_TYPE_SIZE + for bool. + +Sat Jan 14 05:33:55 1995 Jason Merrill + + * decl2.c (finish_file): We need to mess up if there are any + variables in the list, not just if there is one with a constructor. + +Fri Jan 13 14:42:55 1995 Jason Merrill + + * decl.c (duplicate_decls): Propagate DECL_STATIC_{CON,DE}STRUCTOR. + (finish_function): Handle DECL_STATIC_{CON,DE}STRUCTOR. + (finish_function): Trust rest_of_compilation. + + * decl2.c (finish_file): Also call functions designated as static + constructors/destructors. + + * decl.c (grokdeclarator): Allow access decls of operator functions. + (grokparms): Only do convert_for_initialization if the initializer + has a type. + (duplicate_decls): Put back push_obstacks_nochange call. + + * lex.c (real_yylex): Downgrade complaint about the escape sequence + being too large from pedwarn to warning. + + * decl.c (grokdeclarator): Don't complain about long long in system + headers. + + * lex.c (real_yylex): Handle digraphs. + +Thu Jan 12 12:17:24 1995 Jason Merrill + + * decl.c (init_decl_processing): -f{no-,}strict-prototype only + affects C linkage declarations now. + + * typeck.c (comp_target_types): Grok simple contravariant conversions. + (common_type): t1 and t2 are interchangeable. + + * various: Test return value of comp_target_types differently in + different places; it now returns -1 for a contravariant conversion + (which is fine in symmetric cases). + + (common_type): Prefer long double to double even when + they have the same precision. + + * decl.c (grokparms): Call convert_for_initialization to check + default arguments. + + * init.c (build_new): void_type_node has a size (of 0). + + * decl.c (decls_match): Also check for agreement of TREE_READONLY + and TREE_THIS_VOLATILE. + (push_class_level_binding): Properly handle shadowing of + nested tags by fields. + + * search.c (dfs_pushdecls): Ditto. + + * decl2.c (finish_file): Don't second-guess self-initialization. + + * cvt.c (convert_to_reference): Work with expr directly, rather than + a copy. + + * decl.c (push_overloaded_decl): Only shadow artificial TYPE_DECLs. + + * init.c (add_friend): Downgrade duplicate friend message from + pedwarn to warning. + + * decl.c (duplicate_decls): Push obstacks before calling common_type. + +Thu Jan 12 17:15:21 1995 Michael Ben-Gershon + + * except.c (push_eh_entry): set LABEL_PRESERVE_P flag for + exception table labels. + (expand_start_all_catch): Ditto. + (expand_leftover_cleanups): Ditto. + (expand_end_catch_block): Ditto. + * except.c (make_first_label): new function. + (expand_start_all_catch): add a call to make_first_label() before + using a label as a jump destination. + (expand_end_all_catch): Ditto. + (expand_leftover_cleanups): Ditto. + (expand_end_catch_block): Ditto. + (expand_builtin_throw): Ditto. + (expand_throw): Ditto. + * except.c: Add ARM processor support for exception handling. + +Thu Jan 12 12:17:24 1995 Jason Merrill + + (complete_array_type): Copy code from C frontend. + + * lex.c (real_yylex): Don't multiply the length of a wide string + literal by WCHAR_BYTES. + + * decl.c (pushdecl): Check for redeclaration of wchar_t here. + (duplicate_decls): Instead of here. + (define_label): Complain about a label named wchar_t. + (grokdeclarator): Complain about declarations of + operator-function-ids as non-functions. + + * typeck.c (unary_complex_lvalue): Also wrap prefix -- and ++ in + COMPOUND_EXPRs. + (build_unary_op): Wrap unary plus in a NON_LVALUE_EXPR. + + * lex.c (real_yylex): Don't skip whitespace when reading the next + character after ->. + +Wed Jan 11 16:32:49 1995 Mike Stump + + * except.c: Allow cc1plus to be built with native compiler on rs6000. + (expand_start_all_catch): Add assemble_external calls for various + routines we call. + (expand_leftover_cleanups): Ditto. + (expand_start_catch_block): Ditto. + (do_unwind): Ditto. + (expand_builtin_throw): Ditto. + +Wed Jan 11 01:05:42 1995 Jason Merrill + + * decl.c (pushtag): Only look for a previous decl in the current + binding level. Use explicit global scope in DECL_NESTED_TYPENAME. + + * gxx.gperf: Add __signature__ and __sigof__ keywords. + + * decl2.c (lang_decode_option): -ansi does not set flag_no_asm. It + does set flag_no_gnu_keywords and flag_operator_names. + + * lex.c (init_lex): 'overload' is not a keyword unless -traditional. + Unset extension keywords if -fno-gnu-keywords. + Allow operator names ('bitand') if -foperator-names. + Never unset 'asm'; -fno-asm only affects 'typeof'. + + * decl.c (lookup_name_real): The got_object special lookup only + applies to types. + +Tue Jan 10 18:07:51 1995 Jason Merrill + + * spew.c (yylex): Also use DECL_NESTED_TYPENAME if got_object is set. + + * parse.y (primary): Unset got_object after all rules that use the + 'object' nonterminal. + (object): Set got_object. + + * lex.h: Declare got_object. + + * decl.c (lookup_name_real): Also lookup names in the context of an + object specified. + +Tue Jan 10 14:30:30 1995 Mike Stump + + * typeck.c (get_member_function_from_ptrfunc): Use ptrdiff_type_node + for things that have to be added to pointers, not size_type. Cures + problems with pointer to members on Alphas. + (build_binary_op_nodefault): Ditto. + (get_delta_difference_: Ditto. + (build_ptrmemfunc): Ditto. + +Tue Jan 10 01:49:25 1995 Jason Merrill + + * decl.c (pushtag): Stick the new decl in TYPE_NAME before pushing + it. + + * typeck.c (build_component_ref): Don't build up a COMPONENT_REF + when dealing with overloaded member functions; just act like + build_offset_ref. + (commonparms): Remove misleading comment. + + * decl.c (duplicate_decls): Complain about repeated default + arguments here. + (redeclaration_error_message): Instead of here. + (pushdecl): Complain about missing default arguments here. + (grokparms): Instead of here. + (lookup_name_current_level): Also match on DECL_ASSEMBLER_NAME. + (grok_reference_init): Do not complain about missing initializer if + declared 'extern'. + + * search.c (lookup_field): Don't return a TYPE_DECL if there is a + function alternative and want_type is not set. + +Mon Jan 9 18:16:23 1995 Jason Merrill + + * decl.c (pushtag): Don't set TYPE_NAME to an identifier. Do push + the decl when the type has no TYPE_NAME. + (lookup_nested_type): Don't assume that type has TYPE_NAME set. + (lookup_name_real): Call lookup_field with want_type = + prefer_type. + + * search.c (lookup_field): Handle want_type properly in the presence + of fields with the same name. + + * decl.c (set_nested_typename): Set nested name for file-scope types + to include leading ::. + (pushdecl): Set the nested typename if the decl doesn't have one, + rather than if the type's canonical decl doesn't have one. + +Mon Jan 9 16:48:16 1995 Steve Chamberlain (sac@jonny.cygnus.com) + + * typeck.c (pointer_int_sum): Use offset size when calculating + index expression. + +Mon Jan 9 03:44:33 1995 Jason Merrill + + * typeck.c (convert_for_assignment): Complain about contravariance + violation here. + (comp_target_types): Instead of here. + (build_unary_op): resolve_offset_ref before checking for a valid + type. + + * spew.c (yylex): Decrement looking_for_typename after we see a + _DEFN. + + * decl.c (pushdecl): Don't install an artificial TYPE_DECL in + IDENTIFIER_LOCAL_VALUE if we already have a decl with that name. + + * typeck.c (convert_for_assignment): Converting pointers to bool + does not need a cast. + +Sun Jan 8 18:16:45 1995 Jason Merrill + + * class.c (instantiate_type): Initialize nsubsts parm. + + * pt.c (do_function_instantiation): Ditto. + +Sat Jan 7 14:37:05 1995 Jason Merrill + + * pt.c (tsubst): Use TREE_STATIC instead of DECL_INLINE && + DECL_SAVED_INSNS to determine whether or not we've seen a definition + of this function. + (instantiate_template): Ditto. + + * call.c (convert_harshness): Allow const reference binding when + called from the overloading code, but not when called from + can_convert (since it isn't a conversion). + (convert_harshness): Put back some disabled code. + +Fri Jan 6 14:10:57 1995 Jason Merrill + + * call.c (convert_harshness): There is no implicit conversion from + void* to other pointer types (unless the parameter is (void*)0). + (convert_harshness): Non-lvalues do not convert to reference types. + + * class.c (finish_struct_methods): Still set + TYPE_HAS_{INT,REAL}_CONVERSION. + + * call.c (can_convert): Don't use aggregate initialization. + + * cp-tree.h: Declare lookup_conversions. + +Thu Jan 5 21:08:00 1995 Mike Stump + + * parse.y (simple_stmt): Fix duplicate case value error messages to + be more readable. + +Wed Jan 4 16:44:19 1995 Jason Merrill + + * cvt.c (build_type_conversion): Total rewrite to use + convert_harshness instead of reproducing conversion logic here. Now + much shorter. + + * call.c (convert_harshness): Support conversions to bool. + (can_convert): Checks whether a conversion is less harsh + than USER_CODE, for build_type_conversion. + + * search.c (add_conversions): Function for passing to dfs_walk which + adds all the type conversion operators in the current type to a list. + (lookup_conversions): Calls dfs_walk with add_conversions and return + the list. + (dfs_walk): Don't require a qfn. + + * cp-tree.h: Lose CLASSTYPE_CONVERSIONS hackery. + (CLASSTYPE_FIRST_CONVERSION): Points to elt 1 of CLASSTYPE_METHOD_VEC. + + * class.c (finish_struct_bits): Lose CLASSTYPE_CONVERSIONS hackery. + (grow_method): A separate function for building onto the growing + method vector. + (finish_struct_methods): Use it. Put all type conversion operators + right after the constructors. Perhaps we should sort the methods + alphabetically? + +Mon Jan 2 14:42:58 1995 Jason Merrill + + * call.c (build_method_call): Lose another misleading shortcut. + +Fri Dec 30 17:57:30 1994 Mike Stump + + * gc.c (build_bltn_desc): Handle bool as a built-in type. + +Fri Dec 30 14:20:21 1994 Mike Stump + + * tree.c (layout_vbasetypes): Ensure that we don't loose alignment + on the complete type because of small virtual bases. + +Fri Dec 30 12:22:29 1994 Mike Stump + + * decl.c (n_incomplete): Bump n_incomplete up to int to match C + front end. + (pushdecl): Also count decls pushed that are of a type being defined + as incomplete things. + * class.c (finish_struct): Move hack_incomplete_structures up to + just after we set it as not being defined, so that the decls we + build for RTTI don't count as incomplete. + +Thu Dec 29 18:20:57 1994 Mike Stump + + * pt.c (tsubst): Fix problem with defining constructors in templated + classes with virtual bases. + +Wed Dec 28 08:31:00 1994 Mike Stump + + * parse.y (TYPEID): Strip top-level cv-qualifiers on typeid + expressions. + * gc.c (build_typeid): Ditto. + +Thu Dec 22 17:26:33 1994 Mike Stump + + * cvt.c (build_up_reference): Fix breakage introduced on Nov 29, + don't assert on complex AGGR inits. + +Thu Dec 22 14:32:31 1994 Mike Stump + + * method.c (build_overload_value): Handle pointer to members as + template arguments. + +Thu Dec 22 13:09:07 1994 Mike Stump + + * typeck.c (unary_complex_lvalue): Don't call sorry if we know how + to do take the address of a data member for a pointer to data + member. + +Thu Dec 22 10:04:19 1994 Mike Stump + + * decl.c (grokdeclarator): Use the typedef name for linkage if the + type doesn't otherwise have a name. + + * decl2.c (grokfield): Ditto. + + * class.c (finish_struct): Since we reuse the TYPE_DECL for the + DECL_NAME of enums, structs and classes, we have to avoid trying to + put it in the TYPE_FIELDS again. + +Wed Dec 21 11:07:05 1994 Mike Stump + + * decl2.c (check_classfn): Ignore this parameter on static functions + when checking to see if we match. + +Tue Dec 20 17:47:02 1994 Mike Stump + + * typeck.c (unary_complex_lvalue): Handle address of non-left most + pointers to members by calling get_delta_difference. + +Mon Dec 19 22:40:53 1994 Mike Stump + + * decl2.c (check_classfn): Don't use decls_match yet, as it modifies + static functions to early. + +Thu Dec 19 22:37:48 1994 Mike Stump + + * method.c (make_thunk): Handle encoding of positive thunk offsets. + +Sat Dec 17 13:29:50 1994 Doug Evans + + * Make-lang.in (.PHONY): Tell GNU make C++ and c++ are phony targets. + +Thu Dec 15 16:32:12 1994 Mike Stump + + * decl2.c (check_classfn): Use decls_match to check if this has + already been declared, as the DECL_ASSEMBLER_NAME may have been + changed via asm("new_name"). + * decl.c (decls_match): Make public. + +Thu Dec 15 15:17:55 1994 Mike Stump + + * *.[chy] (expand_aggr_init) Add fourth argument to handle + distinction between = init and (init) style of initializations. + * *.[chy] (finish_decl): Add fifth argument to to handle + distinction between = init and (init) style of initializations. + +Tue Dec 13 19:16:05 1994 Mike Stump + + Fix some random `explicit' bugs. + + * cvt.c (convert_to_reference): Add third parameter to + convert_force. + (convert_force): Ditto. + * call.c (build_method_call): Ditto. + * decl2.c (setup_vtbl_ptr): Ditto. + * init.c (expand_virtual_init): Ditto. + (build_member_call): Ditto. + (build_delete): Ditto. + (build_vbase_delete): Ditto. + * typeck.c (build_component_addr): Ditto. + (build_c_cast): Ditto. + (build_modify_expr): Ditto. + * cp-tree.h (CONV_NONCONVERTING): Ditto. Add so that we can + distinguish the context in which the conversion appears. Add thrid + argument to build_c_cast. + * cvt.c (cp_convert): Pass whether or not we want to consider + non-converting constructors down to build_method_call. + * decl2.c (reparse_absdcl_as_casts): Add third argument to + build_c_cast. + * gc.c (build_m_desc): Ditto. + * init.c (build_new): Ditto. + * parse.y (expr_no_commas): Ditto. + (primary): Ditto. + * typeck.c (build_x_function_call): Ditto. + (build_static_cast): Ditto. + (build_reinterpret_cast): Ditto. + (build_const_cast): Ditto. + (build_c_cast): Ditto. + (build_ptrmemfunc): Ditto. + * typeck2.c (build_functional_cast): Ditto. + * init.c (expand_aggr_init): Added LOOKUP_ONLYCONVERTING to + expand_aggr_init_1 as inits are converted to the destination type. + +Tue Dec 13 16:18:57 1994 Jason Merrill + + * Make-lang.in (cc1plus): Depends on c-pragma.o. + + * Makefile.in (OBJ{DEP,}S): Add ../c-pragma.o. + + * lex.c (check_newline): If the #pragma is not recognized by g++, + try machine-specific ones too. + (handle_sysv_pragma): Copied from c-lex.c. + +Mon Dec 12 23:53:06 1994 Mike Stump + + * except.c (expand_throw): Fix Dec 6th change, build_new likes a + reference better. + +Mon Dec 12 18:01:00 1994 Jason Merrill + + * typeck.c (build_binary_op): Lose checks on TYPE_PTRMEMFUNC_P with + IS_AGGR_TYPE, since now they will not both be set on the same type. + + * pt.c (do_pending_expansions): Don't clear TREE_PUBLIC on + instantiations controlled by -fexternal-templates. + + * decl.c (duplicate_decls): Don't complain about different values of + __attribute__ ((const)) and ((noreturn)). + +Fri Dec 9 18:17:37 1994 Doug Evans + + * Makefile.in (BISONFLAGS): Delete --yacc. + (PARSE_H): Depend on $(PARSE_C), for parallel makes. + (PARSE_C): Undo last patch. + +Fri Dec 2 10:44:36 1994 Mike Stump (mrs@wombat.gnu.ai.mit.edu) + + * Makefile.in (BISONFLAGS): Add --yacc so that output winds up in + y.tab.c. + +Thu Dec 8 17:39:46 1994 Jason Merrill + + * decl.c (finish_decl): Don't call obscure_complex_init for decls + of indeterminate size. + +Wed Dec 7 16:49:22 1994 Jason Merrill + + * decl.c (obscure_complex_init): Function to tweak the decl to + prevent expand_decl from tring to initialize it. + (finish_decl): Use it rather than writing the same code in three + different places. + + * parse.y (bad_parm): Stop trying to support parms without types. + +Wed Dec 7 12:06:56 1994 Mike Stump + + * decl2.c (grokfield): Make asm specs on static member functions + work. + +Tue Dec 6 15:43:20 1994 Mike Stump + + * except.c (expand_throw): Make a copy of the thrown object. + +Tue Dec 6 14:16:34 1994 Jason Merrill + + * parse.y: : has lower precedence than =. + +Tue Dec 6 12:46:17 1994 Mike Stump + + * decl.c (pushdecl): Use DECL_NAME of VAR_DECLs to avoid namespace + manglings. + (grokvardecl): Add namespace into variable name. + +Tue Dec 6 11:26:55 1994 Mike Stump + + * decl2.c (current_namespace_id): New routine to transform a simple + name into a name in a namespace. + * decl.c (grokdeclarator): Use it. + * decl2.c (get_namespace_id): Find the name of the current + namespace. + (push_namespace, pop_namespace): Complete out missing + functionality. + +Mon Dec 5 17:11:51 1994 Jason Merrill + + * class.c (finish_struct): Don't use LONG_LONG_TYPE_SIZE, as it may + not be defined. Fix warning message for enums and restore warning + for non-enums. + + * decl2.c (push_namespace): Dummy function. + (pop_namespace): Ditto. + (do_namespace_alias): Ditto. + (do_using_decl): Ditto. + (do_using_directive): Ditto. + + * parse.y: New token NSNAME for namespace names. + (extdef): Add namespace, using definitions. + (using_decl): New rule for using declarations. + (any_id): New rule for identifiers with any degree of scoping. + (identifier): Add NSNAME. + (notype_identifier): Ditto. + (component_decl): Add using_decl. + (nested_name_specifier): Add NSNAME SCOPE. + + * typeck.c (convert_for_assignment): Handle conversions between + enums and bool. + + * decl.c (duplicate_decls): Only propagate DECL_MAIN_VARIANT on + FUNCTION_DECLs. + +Mon Dec 5 13:03:16 1994 Mike Stump + + * class.c (finish_struct): Give an error if one tries to declare a + bit-field's size greater than a long long, as the backend will dump. + It is not an error to declare an enum bit-field greater than its + precision. Warn if an enum bit-field is too small to hold all + its values. + +Mon Dec 5 11:41:50 1994 Mike Stump + + * typeck.c (convert_for_assignment): Use cp_convert instead of + convert so that we don't get static casts. + +Sun Dec 4 11:59:01 1994 Mike Stump + + * cvt.c (cp_convert): Don't complain about int->enum conversion if + we are doing static casts. + +Fri Dec 2 18:32:41 1994 Mike Stump + + * error.c (dump_expr): Do something more intelligent with SAVE_EXPRs + when dumping expressions in error messages. + +Fri Dec 2 17:04:27 1994 Mike Stump + + * gc.c (build_dynamic_cast): Change interface to libg++, ensure that + the return type is the right type, and make references work. + +Fri Dec 2 16:36:43 1994 Jason Merrill + + * decl.c (poplevel): Don't be confused by function-scope + declarations of non-nested functions. + (duplicate_decls): Propagate DECL_MAIN_VARIANT. + (pushdecl): Use duplicate_decls to copy info from old decl into new + function-scope one rather than doing it here. + + * decl2.c (mark_inline_for_output): Deal with the DECL_MAIN_VARIANT + of this decl, in case this is a function-scope declaration. + + * decl.c (finish_enum): Make sure that the type has the right + precision when we call fixup_*_type. + +Tue Nov 29 19:12:07 1994 Jason Merrill + + * cvt.c (build_up_reference): Strip superfluous NOP_EXPRs; we do + want to build up references to rvalues if possible. + (cp_convert): Stick on a NOP_EXPR when converting to the same type. + +Tue Nov 29 11:28:59 1994 Mike Stump + + * parse.y (maybe_raises): Handle throw (). + * parse.y (ansi_raise_identifier): grok type-ids in exception + specifications. + * tree.c (build_exception_variant): Use list compare to check if + two exception specifications match. + * decl.c (duplicate_decls, bad_specifiers): Enhance wording on error + messages. + * call.c (build_method_call): Remove TREE_RAISES. + * cvt.c (convert_to_aggr): Ditto. + * typeck.c (build_function_call_real, convert_arguments): Ditto. + * init.c (expand_aggr_init_1): Ditto. + +Tue Nov 29 09:50:39 1994 Mike Stump + + * except.c: Add support for m68k and mips exception handling + support. + +Tue Nov 29 08:48:33 1994 Mike Stump + + * except.c (expand_end_all_catch): Throw into outer context, if we + fall off end of catch handlers. + +Mon Nov 28 16:44:41 1994 Mike Stump + + * Makefile.in: Make is easier to decide where parse.[ch] will be + built. + +Thu Nov 17 20:11:24 1994 Doug Evans + + * cp/Make-lang.in (CXX_INSTALL_NAME) Use program_transform_name. + (GXX_INSTALL_NAME) Likewise. + (CXX_CROSS_NAME) Use program_transform_cross_name. + (GXX_CROSS_NAME) Likewise. + (c++.install-man): Use program_transform_name on g++.1. + (c++.uninstall): Likewise. + +Thu Nov 3 18:48:19 1994 Paul Eggert + + * Makefile.in (spew.o, lex.o, pt.o): + Depend on $(srcdir)/parse.h, not parse.h. + +Mon Nov 28 13:53:03 1994 Mike Stump + + * parse.y (THROW): Fix precedence of throw expressions. + +Mon Nov 28 13:15:16 1994 Mike Stump + + * typeck.c (build_unary_op): Allow promotions from bool to int on + unary ~. + +Sun Nov 27 00:16:21 1994 Jason Merrill + + * method.c (build_overload_name): Use DECL_ASSEMBLER_NAME for + classes when appropriate. + (build_overload_nested_name): When dealing with a function context, + use ASM_FORMAT_PRIVATE_NAME to tweak the name of the function to + avoid conflicts between local classes of the same name. + +Wed Nov 23 17:59:42 1994 Mike Stump + + * gxx.gperf, parse.y, lex.h, hash.h, lex.c (init_lex), delc.c + (duplicate_decls, grokdeclarator), cp-tree.h: Add support for + `explicit'. + * cvt.c (convert_to_reference, cp_convert, build_type_conversion_1, + build_type_conversion): Use LOOKUP_ONLYCONVERTING in + build_method_calls so that non-converting constructors are not used. + * call.c (build_method_call): If we shouldn't use a non-converting + constructor, then don't. + +Wed Nov 23 14:46:56 1994 Jason Merrill + + * call.c (build_method_call): Don't try to synthesize methods yet. + +Tue Nov 22 12:45:21 1994 Jason Merrill + + * pt.c (push_template_decls): Create CONST_DECLs for template + constant parameters, not VAR_DECLs. + +Sat Nov 19 15:28:31 1994 Jim Wilson (wilson@chestnut.cygnus.com) + + * typeck.c (build_binary_op_nodefault): Can shorten shift only if + shift count is less than size in bits of arg0. + +Thu Nov 17 15:30:50 1994 Mike Stump + + * gxx.gperf, hash.h, lex.c (init_lex, real_yylex), parse.y: Add new + ANSI keywords and, and_eq, bitand, bitor, explicit, namespace, not, + not_eq, or, or_eq, typename, using, xor, xor_eq to g++. Still need + to add support for explicit, namespace, typename, and using, support + for the rest is already in. + +Thu Nov 17 10:56:50 1994 Jason Merrill + + * typeck2.c (build_m_component_ref): Check the basetype of the + member pointer against the main variant of the object type. + +Mon Nov 14 14:21:52 1994 Jason Merrill + + * cvt.c (convert_to_reference): Make sure that the original expr + gets its type back when converting a reference. + + * method.c (build_overload_name): Clear numeric_outputed_need_bar here. + (build_decl_overload): Instead of here. + +Tue Nov 8 17:11:24 1994 Jason Merrill + + * cvt.c (cp_convert): Don't build a TARGET_EXPR if we're not in a + function. + + * typeck.c (convert_for_initialization): Handle initialization from + a TARGET_EXPR. + +Sun Nov 6 01:34:24 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * pt.c (lookup_nested_type_by_name): Fix list-walking logic. + (tsubst): When replacing a TEMPLATE_TYPE_PARM, propagate + TYPE_READONLY and TYPE_VOLATILE from the argument. + (unify): When unifying with a TEMPLATE_TYPE_PARM, remove cv-quals + present in parm from arg. + (type_unification): Strip REFERENCE_TYPE from the argument type. + (unify): Don't strip REFERENCE_TYPE from the argument type. + +Sat Nov 5 22:42:15 1994 Greg McGary (gkm@magilla.cichlid.com) + + * pt.c (do_type_instantiation): Check to see if there's a + IDENTIFIER_TEMPLATE on a class before calling + instantiate_member_templates(). + +Fri Nov 4 19:04:18 1994 Mike Stump + + * gc.c (get_bad_cast_node): New routine to support compile time + throws of bad_cast. + * gc.c (build_dynamic_cast): Support throwing of bad_cast at compile + time. + +Fri Nov 4 11:12:00 1994 Mike Stump + + * except.c: Add hppa support. + +Fri Nov 4 10:50:50 1994 Mike Stump + + * except.c: Add rs6000 support. + +Thu Nov 3 14:24:23 1994 Mike Stump + + * except.c (do_unwind): Add i[34]86 support. + +Thu Nov 3 00:10:46 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * pt.c (do_pending_expansions): Unset TREE_PUBLIC on implicit + instantiations. + +Wed Nov 2 15:08:24 1994 Kung Hsu (kung@mexican.cygnus.com) + + * decl.c (finish_function): emit types used in method parameters + into symbol table. + +Wed Nov 2 15:05:47 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * pt.c (process_template_parm): Allow pointer to member function + template parameter types. + (uses_template_parms): Handle pointer to member function + CONSTRUCTORs. + + * g++.c (main): Cast first argument of bzero to (char *). + Pass -lstdc++ instead of -lg++ unless we are invoked as 'g++'. + +Mon Oct 31 14:50:48 1994 Kung Hsu (kung@mexican.cygnus.com) + + * gc.c (build_dynamic_cast): rewrite to make it work. + * class.c (finish_vtbls): build more vtables if flag_rtti is on. + * class.c (modify_all_direct_vtables): ditto. + * init.c (expand_direct_vtbls_init): expand more vtables if + flag_rtti is on. + * decl.c (init_type_desc): add default return. + +Tue Oct 25 17:13:09 1994 Kung Hsu (kung@mexican.cygnus.com) + + * tree.c (debug_binfo): get rid of the initial size entry of + vtable. + * cp-tree.h: change flag_dossier to flag rtti, define type + descriptor type nodes. + * decl.c (init_type_desc): new function to initialize type + descriptor type nodes. + * decl.c (record_builtin_type): change flag_dossier to flag_rtti. + * lex.c (init_lex): ditto. + * decl.c : change variable flag_dossier to flag_rtti. + * decl.c (duplicate_decls): get rid initial size entry of vtable. + * decl.c (hack_incomplete_structures): take out assert 164. + * search.c (get_abstract_virtuals_1): ditto. + * search.c (dfs_init_vbase_pointers): change CLASSTYPE_DOSSIER to + CLASSTYPE_RTTI. + * parse.y: ditto. + * class.c (prepare_fresh_vtable): for virtual bases, get right + offset. + * class.c (add_virtual_function): change flag_dossier to + flag_rtti. + * class.c (modify_one_vtable): modify the right rtti entry. + * class.c (override_one_vtable): get rid of size entry. + * class.c (finish_struct): change flag_dossier to flag_rtti, and + build extra vtables, build type descriptors for polymorphic + classes. + * gc.c (build_headof): make headof() works correctly with new + rtti. + * gc.c (build_typeid): make this function work with new rtti. + * gc.c (get_typeid): make this function work with new rtti. + * gc.c (build_bltn_desc): new function for new rtti. + * gc.c (build_user_desc): ditto. + * gc.c (build_class_desc): ditto. + * gc.c (build_ptr_desc): ditto. + * gc.c (build_attr_desc): ditto. + * gc.c (build_func_desc): ditto. + * gc.c (build_ptmf_desc): ditto. + * gc.c (build_ptmd_desc): ditto. + * gc.c (build_t_desc): ditto. + * gc.c : comment out old build_t_desc, build_i_desc, build_m_desc. + +Tue Oct 25 13:37:41 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * call.c (convert_harshness): Check for TREE_UNSIGNED differences + after checking for integral conversions. + +Sun Oct 23 13:19:55 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * decl2.c: Declare flag_access_control. + (struct lang_f_options): Add access-control. + * expr.c (cplus_expand_expr, NEW_EXPR): Unset flag_access_control + for the call to expand_aggr_init to copy the object out of the + pcc_struct_return slot. + * search.c (compute_access): if (!flag_access_control) return + access_public. + +Fri Oct 21 00:32:54 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * lex.c (cons_up_default_function): Don't try to defer method + synthesis now. + + * decl.c (init_decl_processing): Use __pure_virtual for abort_fndecl + instead of abort, since the OSF/1 dynamic linker doesn't like to see + relocation entries for abort. + + * tree.c (array_type_nelts_total): Use sizetype, not + integer_type_node. + (array_type_nelts_top): Ditto. + +Thu Oct 20 15:48:27 1994 Mike Stump + + * decl.c (grokdeclarator): Added handling for catch parameters + (CATCHPARM). + * except.c (expand_start_catch_block): Use the new CATCHPARM context + instead of NORMAL. + * except.c (expand_throw): Don't let convert_to_reference complain + about what we are doing. + +Thu Oct 20 12:55:24 1994 Jim Wilson (wilson@cygnus.com) + + * method.c (emit_thunk): Call instantiate_virtual_regs. + +Wed Oct 19 14:15:33 1994 Mike Stump + + * except.c (expand_exception_blocks): Make sure throw code doesn't + get put in function that won't be output. + +Mon Oct 17 18:03:15 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * decl.c (init_decl_processing): Make alloca a builtin. + +Thu Oct 27 21:10:25 1994 Craig Burley (craig@burley) + + * g++.c (main): Only decrement "added" and set "library" to + NULL when "library" != NULL (just like 940829 fix). + +Mon Oct 17 15:56:11 1994 Mike Stump + + * except.c (expand_start_catch_block): Make sure the false label + gets onto the permanent obstack, as it is used for the exception + table. + +Fri Oct 14 18:54:48 1994 Mike Stump + + * class.c (modify_one_vtable): Since the DECL_CONTEXT of fndecl can + be set just below, use current_fndecl instead. + +Fri Oct 14 15:12:22 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * init.c (expand_aggr_vbase_init_1): Don't call expand_aggr_init_1 + with LOOKUP_SPECULATIVELY. + (expand_default_init): Abort if build_method_call returns NULL_TREE. + + * typeck.c (build_modify_expr): Don't just build a MODIFY_EXPR if + the rhs is a TARGET_EXPR. + + * parse.y (left_curly): Anonymous types are not affected by #pragma + interface/implementation. + + * method.c (synthesize_method): Don't call setup_vtbl_ptr for the + default constructor if it isn't needed. + + * lex.c (cons_up_default_function): Do synthesize methods for + anonymous types if necessary. + +Thu Oct 13 17:44:55 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * method.c (build_decl_overload): Set numeric_outputed_need_bar to 0. + +Wed Oct 12 13:27:57 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * typeck.c (build_modify_expr): Understand how to copy an aggregate. + + * init.c (expand_default_init): Ditto. Also remove some of the + crufty code that assumes methods will not be synthesized properly. + + * lex.c (cons_up_default_function): If the containing type has no + name, these functions should never need to be called, so just + declare them. + + * lex.c (real_yylex): Use HOST_BITS_PER_WIDE_INT to determine the + bitmask for lexing character constants. + + * call.c (build_method_call): Disable code that tries to do tricky + stuff with a default parameter that is a constructor call, but + actually does other tricky stuff that breaks things. + +Wed Oct 12 16:14:01 1994 Benoit Belley + + * decl.c (finish_enum): Disable code which forces enums to be signed, + since this conflicts with their use as bitfields. type_promotes_to + handles promotion of enums of underlying unsigned types to signed + integer types. + +Wed Oct 12 13:24:03 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * cvt.c (type_promotes_to): Also promote enums to long if + appropriate. + + * typeck.c (default_conversion): Don't expect type_promotes_to to + return a main variant. + +Wed Oct 12 12:19:45 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * call.c (build_scoped_method_call): Don't lose side effects in the + object expression when calling a non-existent destructor. + +Fri Sep 2 19:05:21 1994 Rohan Lenard (rjl@iassf.easams.com.au) + + * call.c (build_scoped_method_call): Remove erroneous error message + when destructor call is written as a scoped call. + +Tue Oct 11 23:48:31 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * various: Cast pointer arguments to bzero and bcopy to char *. + +Tue Oct 11 19:34:32 1994 Mike Stump + + * class.c (get_derived_offset): Added a type parameter to limit how + far up the CLASSTYPE_VFIELD_PARENT chain we search. + * class.c (modify_one_vtable, fixup_vtable_deltas): When forming the + offset to put into the vtable for the this parameter, make sure we + don't offset from a parent of the DECL_CONTEXT of the function. + +Tue Oct 11 16:10:52 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * pt.c (do_function_instantiation): Set DECL_EXTERNAL and + TREE_STATIC when setting DECL_INTERFACE_KNOWN. + (do_type_instantiation): Ditto. + + * lex.c (cons_up_default_function): Set DECL_INTERFACE_KNOWN, + DECL_EXTERNAL and TREE_STATIC as appropriate. + + * decl2.c (finish_file): Also synthesize methods that don't have + DECL_EXTERNAL set. Set interface_unknown before doing so. + + * decl.c (start_function): If DECL_INTERFACE_KNOWN is set on the + function decl, don't muck with TREE_PUBLIC and DECL_EXTERNAL. + +Mon Oct 10 00:56:53 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * lex.c (cons_up_default_function): Mark methods in a template class + as template instances. Store the values of interface_unknown and + interface_only for do_pending_inlines. + (do_pending_inlines): Use them. + + * decl2.c (finish_file): If we haven't seen a definition of a + function declared static, make the decl non-PUBLIC so compile_file + can give an error. + +Sun Oct 9 02:42:29 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * method.c (do_build_copy_constructor): Handle anonymous unions. + (do_build_assign_ref): Ditto. + (largest_union_member): Move from lex.c. + +Sat Oct 8 14:59:43 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + Re-implement g++'s vague linkage independent of TREE_PUBLIC. + * pt.c (instantiate_member_templates): Lose redundant + -fexternal-templates handling. + (tsubst): Set TREE_PUBLIC and DECL_EXTERNAL on new decls. Don't set + TREE_STATIC or DECL_INTERFACE_KNOWN. + (do_pending_expansions): Predicate on DECL_INTERFACE_KNOWN instead + of DECL_EXTERNAL for explicit instantiations. + (do_function_instantiation): Do the new thing. + (do_type_instantiation): Ditto. + (instantiate_template): Deal with member templates defined in a .cc + file with -fexternal-templates. + * except.c (expand_exception_blocks): Use DECL_LINKAGE_KNOWN to + decide whether to stick builtin_throw here. + * decl2.c (import_export_inline): Predicate on DECL_INTERFACE_KNOWN + rather than TREE_PUBLIC. Generally fix rules. + (finish_file): Use DECL_INITIAL to determine whether or not a method + has been synthesized, rather than TREE_ASM_WRITTEN. + * decl.c (warn_extern_redeclared_static): Use DECL_PUBLIC instead of + TREE_PUBLIC. + (pushdecl): Ditto. + (duplicate_decls): Ditto. Deal with DECL_DECLARED_STATIC and + DECL_INTERFACE_KNOWN. + (redeclaration_error_message): Fix checking for conflicting linkage. + (define_function): Set DECL_INTERFACE_KNOWN. + (grokfndecl): Function decls are PUBLIC until we are sure about + their linkage. Set DECL_DECLARED_STATIC as needed. + (start_function): Deal with linkage. Move pushdecl after linkage + magic. + (finish_function): Don't set TREE_ASM_WRITTEN on discarded inlines. + * cp-tree.h (lang_decl_flags): Add interface_known and + declared_static. + (DECL_INTERFACE_KNOWN): New macro. + (DECL_DECLARED_STATIC): New macro. + (DECL_PUBLIC): New macro. + + Clean up bogus use of TREE_PUBLIC. + * class.c (alter_access): Fix mistaken use of TREE_PUBLIC (it + doesn't correspond to TREE_PROTECTED and TREE_PRIVATE). + * init.c (do_friend): Don't arbitrarily set TREE_PUBLIC. + +Wed Oct 5 13:44:41 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * call.c (build_overload_call_real): Don't immediately do + array->pointer conversion. + + * pt.c (type_unification): If not passing to a reference, strip + cv-quals. Also handle array->pointer conversion. + +Tue Oct 4 17:45:37 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * decl.c (grokdeclarator): Don't warn about applying const to a + const typedef or template type parameter. + + * decl2.c (finish_file): Also synthesize methods after walking the + vtables. Ugly ugly ugly. + +Mon Oct 3 15:02:41 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * various: Remove lingering remnants of old exception handling code. + + * decl2.c (finish_file): Synthesize methods before walking the + vtables, so that the vtables get emitted as needed. + + * decl.c (shadow_tag): Remove obsolete code for pushing tags and + dealing with exceptions. + +Mon Oct 3 13:05:27 1994 Ian Lance Taylor + + * Make-lang.in (g++-cross): Depend upon version.o and $(LIBDEPS). + +Mon Oct 3 02:59:28 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * decl2.c (finish_file): Fix inline handling. + +Sun Oct 2 00:21:56 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + * decl.c (grokdeclarator): Handle redundant scope even better. + ({push,pop}_cp_function_context): Take toplev parameter. + + * method.c (synthesize_method): Pass toplev parameter to + {push,pop}_cp_function_context depending on decl_function_context + (fndecl). + + * typeck.c (build_x_unary_op): Unary & on OFFSET_REFs is always the + built-in version. + + * method.c (synthesize_method): Don't be confused by __in_chrg + parameter. + + * class.c (popclass): Set C_C_D like start_function does. + + * decl.c (grokdeclarator): Handle redundant scope better. + + * parse.y (expr_or_declarator): Add '(' expr_or_declarator ')' rule. + (direct_notype_declarator): Ditto. + (complex_direct_notype_declarator): Remove it here. + +Sat Oct 1 21:42:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (resolve_offset_ref): Fix types used in resolving .* + expressions. + +Sat Oct 1 15:18:49 1994 Jason Merrill (jason@phydeaux.cygnus.com) + + Beginnings of work to synthesize methods only when needed. + * call.c (build_method_call): Synthesize methods as necessary + (currently never necessary). + * class.c (popclass): Don't try to set C_C_D here, as it'll end up + on the wrong obstack. + * decl.c (push_cp_function_context): Mostly copied from + push_c_function_context. + (pop_cp_function_context): Similarly. + (finish_function): Reverse order of poplevel and pop_nested_class so + that current_class_decl is restored properly. + (start_function): Ditto. + (finish_function): Add parameter 'nested'. Don't call + permanent_allocation if (nested). + * various: Pass extra parameter to finish_function. + * decl2.c (finish_file): Reorganize end-of-file inline handling, + synthesizing methods as necessary. + * lex.c (cons_up_default_function): Call mark_inline_for_output. + Only synthesize methods immediately if #pragma implementation + (currently disabled). + (do_pending_inlines): Call synthesize_method. + * method.c (synthesize_method): New function; all method synthesis + goes through here. Calls do_build_assign_ref and + do_build_copy_constructor. + (build_default_constructor): Remove. + (build_dtor): Ditto. + (build_assign_ref): Rename to do_build_assign_ref and remove stuff + done by synthesize_method. + (build_copy_constructor): Similarly. + +Thu Sep 29 16:58:52 1994 Mike Stump + + * typeck.c (c_expand_return): Use magic so the backend can fixup the + assignment into the return register, so cleanups won't clobber it. + +Thu Sep 29 13:08:50 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (hack_identifier): Don't call assemble_external for + template decls. + + * decl.c (finish_decl): Also end temporary allocation if the decl in + question has a type of error_mark_node. + +Wed Sep 28 21:45:00 1994 Mike Stump + + * typeck.c (build_modify_expr): When optimizing ?: on lhs, make sure + that if the ?: was a reference type, that the subparts will be also. + +Wed Sep 28 16:14:04 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * except.c (register_exception_table): Use Pmode, not PTRmode. + +Fri Sep 23 13:54:27 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (do_pending_inlines): Do method synthesis after the + pending_inlines have been reversed. + +Thu Sep 22 12:53:03 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl2.c (finish_file): Fix Brendan's fix: Only call + register_exception_table if there is a non-empty exception table. + +Thu Sep 22 12:03:46 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl2.c (finish_file): Only do register_exception_table if + -fhandle-exceptions is being used. + +Wed Sep 21 19:01:51 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * except.c (output_exception_table_entry): Simplify + by using assemble_integer. + (build_exception_table): Change to return a count. + Cleanup to use standard macros, instead of hard-wired + sparc asm format. Don't make __EXCEPTION_TABLE__ global. + (register_exception_table): New function. Generate call to builtin. + * decl2.c (finish_file): Call register_exception_table. + * cp-tree.h (build_exception_table): Fix prototype. + +Wed Sep 21 13:20:42 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * tree.c (break_out_calls): Don't try to duplicate the DECL_INITIAL. + + * decl2.c (delete_sanity): Give an error at trying to delete a + function. + +Wed Sep 21 11:47:10 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (cons_up_default_function): Mark synthesized destructors + inline. + + * decl.c (duplicate_decls): Ignore redeclarations of wchar_t as + something other than __wchar_t, complaining if -pedantic and not in + a system header. + +Tue Sep 20 09:43:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (xref_tag): Set up BINFO_INHERITANCE_CHAIN on base binfos + here. + + * typeck.c (build_modify_expr): Require complete type after checking + for error_mark_node. + + * call.c (build_method_call): Print parmtypes when complaining of + ambiguous call. + + * typeck.c (build_modify_expr): Handle assignment to array from + non-array. + + * decl.c (lookup_name_real): Deal with got_scope == error_mark_node. + + * call.c (build_method_call): Don't bother with the exact match. + +Mon Sep 19 00:51:39 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (expand_aggr_init): If we munge the type of the variable, + also munge the type of the initializer. + + * decl.c (grokdeclarator): Use <= when comparing to RID_LAST_MODIFIER. + (init_decl_processing): Push artificial declaration of wchar_t so + people don't have to declare it before they can use it. + + * error.c (cp_line_of): return lineno in lieu of 0. + + * typeck.c (convert_for_assignment): Handle conversion of pmfs to + int and bool. + (build_component_ref): Fold the COMPONENT_REF in case it can be + reduced. + + * typeck2.c (store_init_value): Don't pedwarn about non-constant + bracketed initializers for automatic variables. + +Sun Sep 18 10:12:12 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_decl): Don't say `typedef enum foo foo'. + + * decl.c (start_decl): Don't set TREE_PUBLIC on template decls just + because they're affected by #pragma i/i. We'll deal with that when + they get instantiated. + + * typeck.c (build_unary_op): Clean up cruft in ADDR_EXPR case. + + * class.c (instantiate_type): Set TREE_CONSTANT on instantiated + ADDR_EXPRs if appropriate. + + * decl.c (build_ptrmemfunc_type): Unset IS_AGGR_TYPE on pmf types. + + * typeck.c (build_ptrmemfunc): Handle &overloaded_method as an + initializer properly. + * typeck2.c (digest_init): Ditto. + + * tree.c (cp_build_type_variant): Like c_build_type_variant, except + it uses build_cplus_array_type. + * *.c: Use cp_build_type_variant instead of c_build_type_variant. + + * pt.c (do_type_instantiation): Don't try to instantiate nested + enums. + +Tue Sep 13 10:56:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (build_up_reference): Handle preincrement and predecrement + properly. + +Tue Sep 13 09:51:59 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (finish_decl): Only lay out the rtl for DECL if it is, in + fact, static. + +Mon Sep 12 14:40:30 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (finish_decl): Lay out the rtl for DECL before doing + grok_reference_init, in case it's static. + +Mon Sep 12 12:45:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Don't synthesize constructors if the + class has a field with the same name as the class. Don't die on + classes with no constructors or destructors. Don't die if the head + and tail of the class are in different files. + + * decl.c (grokdeclarator): Don't treat a function pointer field + with the same name as the class as a constructor. + +Fri Sep 9 13:17:00 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_c_cast): Pull constant values out of their + variables here. + + * decl.c (duplicate_decls): Only propagate DECL_CHAIN in + FUNCTION_DECLs and TEMPLATE_DECLs. + +Thu Sep 8 10:07:48 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (duplicate_decls): Propagate DECL_CHAIN in all DECLs that + have it. + + * pt.c (unify): REALs and INTEGERs only unify with their own genus. + (instantiate_member_templates): Don't muck with DECL_EXTERNAL and + TREE_PUBLIC unless -fexternal-templates. + +Wed Sep 7 13:17:10 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (do_type_instantiation): Call instantiate_member_templates. + Deal with specializations. + (tsubst): Don't stick the mangled name in DECL_NAME for function + instantiations. Don't push them, either. + + * decl2.c (grokfield): Move code for generating the + DECL_ASSEMBLER_NAME for static members from here. + * method.c (build_static_name): To here. + * decl.c (grokvardecl): Call build_static_name. + (duplicate_decls): Keep old DECL_ASSEMBLER_NAME. + +Mon Sep 5 12:49:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): if -Wsynth, warn when selecting + synthesized op= over user-supplied one cfront would select. + * decl2.c (lang_decode_option): Handle -Wsynth. + +Fri Sep 2 15:11:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (finish_enum): Overhaul to fix several bugs. + (start_enum): Disable useless code. + +Thu Sep 1 16:04:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (c_expand_return): Warn about returning a reference to a + temporary. + (convert_arguments): Increment argument counter when using default + arguments, too. + +Wed Aug 31 14:29:22 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (finish_decl): If the type of decl is error_mark_node, + don't bother trying to do anything. + + * typeck.c (convert_for_initialization): If the rhs contains a + constructor call, pretend the lhs type needs to be constructed. + + * init.c (expand_default_init): If we stick the object inside the + initializer, mark the initializer used. + +Tue Aug 30 13:50:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (build_assign_ref): return *this; + (build_assign_ref): Fix base assignment order. + (build_copy_constructor): Fix member init order. + +Mon Aug 29 13:54:39 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * g++.c (main): Remember to clear out SAW_SPECLANG after we see + its argument. + +Sat Aug 27 09:36:03 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (build_copy_constructor): Also copy virtual bases. + +Fri Aug 26 17:05:15 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (do_pending_inlines): Clear out pending_inlines before doing + any synthesis. Also first set deja_vu on all pending_inlines. + + * method.c (build_assign_ref): Use build_member_call to invoke base + operator=, rather than build_modify_expr. And use + build_reference_type instead of TYPE_REFERENCE_TO. + (build_copy_constructor): Use TYPE_NESTED_NAME to identify the + basetype. + + * decl2.c (grokfield): Don't complain about undefined local class + methods. + + * class.c (finish_struct): Don't try to synthesize methods here. + * lex.c (do_pending_inlines): Instead, synthesize them here. + (init_lex): Initialize synth_obstack. + (cons_up_default_function): Stick synthesis request on + pending_inlines. + +Fri Aug 26 12:24:14 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * call.c (build_method_call) [PCC_STATIC_STRUCT_RETURN]: Also + accept an RTL_EXPR in what we're about to use for the instance, + since anything which would end up with pcc_struct_return set + inside cplus_expand_expr. + + * cp-tree.h (cons_up_default_function): Note change of prototype. + +Thu Aug 25 23:05:30 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * class.c (finish_struct): Undid change from Aug 21 testing + CLASSTYPE_INTERFACE and CLASSTYPE_VTABLE_NEEDS_WRITING. + * parse.y (left_curly): Ditto, undid change from Aug 21. + * decl.c (xref_tag): Undid change from Aug 21, set + CLASSTYPE_INTERFACE correctly, and added comments. + +Thu Aug 25 00:36:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + Rework approach to synthesized methods; don't go through the parser + anymore. + * class.c (finish_struct): Use new synthesis approach. + * lex.c (cons_up_default_function): Now just creates declaration, + not code. + (largest_union_member): #if 0 out. + (default_assign_ref_body): Ditto. + (default_copy_constructor_body): Ditto. + * method.c (build_default_constructor): New function to synthesize X(). + (build_copy_constructor): Synthesize X(X&). + (build_assign_ref): Synthesize X::operator=(X&). + (build_dtor): Synthesize ~X(). + + * error.c (cp_line_of): If we're dealing with an artificial + TYPE_DECL, look at the type instead. + +Wed Aug 24 11:11:50 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (sort_member_init): Check warn_reorder. + * decl2.c (lang_decode_option): Handle -W{no-,}reorder. + + * cp-tree.h (CLASSTYPE_SOURCE_LINE): New macro. + * error.c (cp_line_of): Use CLASSTYPE_SOURCE_LINE for aggregates. + * class.c (finish_struct): Set CLASSTYPE_SOURCE_LINE. + +Tue Aug 23 09:28:35 1994 Mike Stump + + * error.c (dump_decl): Improve wording, so that error messages + dont't read template<, class foo>... + +Mon Aug 22 15:30:51 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y (label_colon): Also match a TYPENAME as a label name, + since they may have declared a class by that name but have also + tried to have a local label under the same name. + + * pt.c (coerce_template_parms): Call cp_error, not cp_error_at, + for the message so they know at what point it was instantiated. + +Sun Aug 21 23:07:35 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * class.c (finish_struct): Move setting of CLASSTYPE_INTERFACE and + CLASSTYPE_VTABLE_NEEDS_WRITING for signatures up to left_curly time. + * decl.c (xref_tag): Move setting of CLASSTYPE_INTERFACE and + CLASSTYPE_VTABLE_NEEDS_WRITING for signatures down to left_curly time. + * parse.y (left_curly): New final resting place for setting + CLASSTYPE_INTERFACE and CLASSTYPE_VTABLE_NEEDS_WRITING for signatures. + + * class.c (finish_struct): Don't test for function/field name + conflicts in signatures, since all the fields are compiler-constructed. + +Fri Aug 19 14:04:47 1994 Kung Hsu (kung@mexican.cygnus.com) + + * method.c (build_overload_nested_name): in qualified name + mangling, the template with value instantiation will have numeric + at end and may mixed with the name length of next nested level. + Add a '_' in between. + * method.c (build_overload_name): ditto. + * method.c (build_overload_identifier): ditto. + +Thu Aug 18 16:24:43 1994 Mike Stump + + * error.c (dump_decl): Handle NULL args. + +Thu Sep 29 16:15:36 1994 Michael I Bushnell + + * g++.c: Rework last change so it's done like collect.c (and + gcc.c). + +Wed Sep 14 10:17:27 1994 Michael I Bushnell + + * g++.c: Include in case `errno' is a macro + as permitted by ANSI C. + +Thu Aug 18 12:48:09 1994 Mike Stump + + * class.c (finish_struct): Move setting of CLASSTYPE_INTERFACE and + CLASSTYPE_VTABLE_NEEDS_WRITING up to left_curly time. + * decl.c (xref_tag): Move setting of CLASSTYPE_INTERFACE and + CLASSTYPE_VTABLE_NEEDS_WRITING down to left_curly time. + * parse.y (left_curly): New final resting place for setting + CLASSTYPE_INTERFACE and CLASSTYPE_VTABLE_NEEDS_WRITING. + +Thu Aug 11 11:32:42 1994 H.J. Lu (hjl@nynexst.com) + + * g++.c (main): Only decrement "added" and set "library" to + NULL when "library" != NULL. + +Sat Aug 13 00:14:52 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Don't set TREE_PUBLIC on a function decl + just because its class has a known interface. + (decls_match): Deal with new format of template parms. + + * lex.c (cons_up_default_function): Don't play with TREE_PUBLIC and + DECL_EXTERNAL here. + +Fri Aug 12 01:55:15 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (pushtag): SET_DECL_ARTIFICIAL on gratuitous typedefs. + (xref_defn_tag): Ditto. + (pushdecl): Only allow artificial typedefs to be shadowed. + + * init.c (emit_base_init): Pass the right binfos to + expand_aggr_init_1. + + * class.c (delete_duplicate_fields_1): Make it work right. + (finish_struct): Catch function/field name conflict. + + * decl2.c (check_classfn): Pass the function to cp_error, not just + the name. + + * init.c (sort_member_init): Warn when order of member initializers + does not match order of member declarations. + (emit_base_init): Call expand_aggr_init_1 with LOOKUP_PROTECT. + + * error.c (dump_expr): Handle lists of functions. + + * decl.c (start_function): #pragma interface only affects functions + that would otherwise be static. + (finish_decl): Don't warn about an unused variable if it has both + constructor and destructor, since the 'resource allocation is + initialization' idiom is relatively common. + + * typeck.c (comp_target_types): Don't handle TEMPLATE_TYPE_PARMs. + (comp_target_parms): Ditto. + (compparms): Never consider default parms. + (common_base_type): Don't choose a virtual baseclass if there is a + more derived class in common. + (build_conditional_expr): If pedantic, pedwarn about conversion to + common base in conditional expr. + + * class.c (instantiate_type): Handle template instantiation better. + + * typeck.c (convert_arguments): Don't try to get tricky and convert + to int directly when PROMOTE_PROTOTYPES is set, as it breaks + user-defined conversions. + + * lex.c (check_for_missing_semicolon): Also give error at end of + file. + + * call.c (build_method_call): Don't promote arrays to pointers here. + + * typeck.c (convert_arguments): Don't require the actual parameter + to be of a complete type if the formal parameter is a reference. + +Thu Aug 11 15:21:40 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Soften 'static' on member function error + to pedwarn. + + * init.c (build_new): Don't automatically save rval. + (build_offset_ref): Do field lookup with proper basetype_path. + +Thu Aug 11 12:46:54 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * errfn.c (cp_silent): Declare to mark when we should avoid + emitting warnings and errors. + (cp_error): Check it. + (cp_warning): Likewise. + (cp_pedwarn): Likewise. + (cp_compiler_error): Likewise. + (cp_error_at): Likewise. + (cp_warning_at): Likewise. + (cp_pedwarn_at): Likewise. + * call.c (compute_conversion_costs): Set CP_SILENT when we start + out, and make sure we turn it off before we leave. + +Thu Aug 11 00:02:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (grok_array_decl): Try computing *(A+B) if neither + argument is obviously an array. + +Wed Aug 10 15:32:04 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (c_expand_start_case): Do cleanups here. + + * parse.y (xcond): Do bool conversion here, too. + (simple_stmt, SWITCH case): Don't do cleanups here. + + * decl.c (duplicate_decls): Don't treat builtins that have been + explicitly declared specially. + +Tue Aug 9 01:16:09 1994 Jason Merrill (jason@deneb.cygnus.com) + + * tree.c (make_deep_copy): Support copying pointer, reference, + function, array, offset and method types. + + * decl.c (init_decl_processing): Mark exit and abort as + BUILT_IN_NONANSI so that duplicate_decls is kinder about + redeclaration. + (duplicate_decls): Don't give two errors for redeclaring a C + function with the same parms but a different return type. + + * parse.y (paren_cond_or_null): Do cleanup and bool conversion here. + (condition): Instead of here. + (simple_stmt, SWITCH case): Also do cleanup here. + + * decl2.c (finish_anon_union): Only break out FIELD_DECLs. + + * call.c (build_method_call): Don't throw away the side effects of + the object in a call to a non-existent constructor. + * parse.y (primary): Ditto. + + * method.c (build_decl_overload): Oop. + + * decl2.c (lang_decode_option): Deal with flag_no_nonansi_builtin, + warn about uselessness of specifying -fansi-overloading. + + * method.c (build_decl_overload): Treat any non-member new with one + parameter as __builtin_new. + + * decl.c (init_decl_processing): Setup built-in meanings of exit, + _exit and abort. + +Mon Aug 8 15:03:30 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_readonly_or_volatile): Put a space between const and + volatile if both apply. + + * init.c (perform_member_init): Clean up after this initialization. + (emit_base_init): Clean up after each base init, not after all have + been done. + (expand_aggr_vbase_init_1): Clean up after this init. + +Sun Aug 7 14:55:05 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Deal with destroying references. + + * parse.y (condition): Do bool_truthvalue_conversion here. + (paren_expr_or_null): And here. + (simple_if): Not here. + (simple_stmt): Or here. + +Sat Aug 6 22:29:45 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (paren_expr_or_null): Wrap the expression in a + CLEANUP_POINT_EXPR. + (condition): Ditto. + +Sat Aug 6 19:46:37 1994 Rohan Lenard (rjl@easams.com.au) + + * call.c (build_scoped_method_call): Fix error message when + destructor call refers to a nonexistent type. + +Sat Apr 16 22:43:30 1993 Gerald Baumgartner (gb@cs.purdue.edu) + + * lex.h (rid): Deleted RID_RAISES, it's never used. + Moved RID_PUBLIC, RID_PRIVATE, RID_PROTECTED, RID_EXCEPTION, + RID_TEMPLATE and RID_SIGNATURE to the end of the enumeration, + they don't need to be touched in `grokdeclarator.' + (RID_LAST_MODIFIER): Defined macro to be RID_MUTABLE. + + * decl.c (grokdeclarator): Use RID_LAST_MODIFIER instead of + RID_MAX as loop limit for finding declaration specifiers. + +Sat Apr 3 21:59:07 1993 Gerald Baumgartner (gb@cs.purdue.edu) + + * lex.c (debug_yytranslate): Moved to parse.y since it needs to + access `yytname,' which is static in parse.c. + +Fri Apr 2 23:36:57 1993 Gerald Baumgarnter (gb@cs.purdue.edu) + + * cp-tree.h (GNU_xref_ref): Fixed typo in extern declaration, it + was `GNU_xref_def' instead of `GNU_xref_ref.' + +Fri Aug 5 14:20:16 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (do_function_instantiation): Don't set TREE_PUBLIC and + DECL_EXTERNAL on 'extern' instantiations; wait until EOF to do that. + (do_type_instantiation): Ditto. + + * decl2.c (import_export_inline): Decides at EOF what an inline's + linkage should be. + (finish_file): Call it. + + * decl.c (start_function): Don't rely on the settings of TREE_PUBLIC + and DECL_EXTERNAL from do_*_instantiation. Only set + DECL_DEFER_OUTPUT on inlines whose linkage might actually change. + (finish_function): Use DECL_DEFER_OUTPUT to decide which inlines to + mark for later consideration, rather than DECL_FUNCTION_MEMBER_P. + +Fri Aug 5 01:12:20 1994 Mike Stump + + * class.c (get_class_offset_1, get_class_offset): New routine to + find the offset of the class where a virtual function is defined, + from the complete type. + * class.c (modify_one_vtable, fixup_vtable_deltas): Use + get_class_offset instead of virtual_offset as get_class_offset will + always provide the right answer. + * tree.c (virtual_offset): Remove. It only ever worked some of the + time. + +Tue Aug 2 12:44:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Put back unary_complex_lvalue call + that I thought was redundant. + + * typeck.c (c_expand_return): Fix a case I missed before. + +Sun Jul 31 17:54:02 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (unify): Strip cv-quals from template type arguments (when + 'const T*' is matched to 'const char*', that does not mean that T is + 'const char'). + +Fri Jul 29 01:03:06 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (do_type_instantiation): Instantiate nested TAGS, not + typedefs. Third time's the charm? + + * parse.y (template_parm): Support default template parms. + * pt.c (process_template_parm): Ditto. + (end_template_parm_list): Ditto. + (coerce_template_parms): Ditto. + (mangle_class_name_for_template): Ditto. + (push_template_decls): Ditto. + (unify): Ditto. + * method.c (build_overload_identifier): Ditto. + * error.c (dump_decl): Ditto. + +Wed Jul 27 17:47:00 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (do_type_instantiation): Only instantiate nested *classes*. + +Tue Jul 26 13:22:40 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (note_debug_info_needed): Also emit debugging information + for the types of fields. + +Mon Jul 25 00:34:44 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (lookup_template_class): Pass 'template' to + coerce_template_parms instead of 'in_decl', since it's a more + meaningful context. + + * typeck.c (c_expand_return): Make sure any cleanups for the return + expression get run. + (build_c_cast): Use CONVERT_EXPR for conversion to void. + + * pt.c (do_type_instantiation): Also instantiate nested types. + + * typeck.c (convert_for_assignment): Don't die when comparing + pointers with different levels of indirection. + + * decl.c (grokdeclarator): The sub-call to grokdeclarator for + class-local typedefs sets DECL_ARGUMENTS, so we need to clear it + out. + + * decl2.c (finish_anon_union): Don't die if the union has no + members. + + * decl.c (grokdeclarator): Undo changes to declspecs when we're done + so that 'typedef int foo, bar;' will work. + + * decl2.c (finish_file): Don't call expand_aggr_init for + non-aggregates. + +Mon Jul 25 00:03:10 1994 Teemu Torma (tot@trema.fi) + + * decl.c (finish_function): We can't inline constructors and + destructors under some conditions with -fpic, but don't unset + DECL_INLINE. + +Mon Jul 25 00:03:10 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_object_ref): Make sure 'datum' is a valid object. + +Sun Jul 24 14:19:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Don't set DECL_FIELD_BITPOS on + non-fields. + (finish_struct_methods): Use copy_assignment_arg_p. + + * cvt.c (cp_convert): If expr is an OFFSET_REF, resolve it instead + of giving an error. + + * typeck.c (build_binary_op_nodefault): Don't set result_type if we + don't know how to compare the operands. + + * decl.c (grokdeclarator): Avoid seg fault when someone uses '__op' + as a declarator-id in their program. Like the Linux headers do. + Arrgh. + + * tree.c (lvalue_p): Treat calls to functions returning objects by + value as lvalues again. + + * typeck.c (build_component_addr): Use convert_force to convert the + pointer in case the component type is also a private base class. + + * search.c (get_matching_virtual): Fix bogus warning of overloaded + virtual. + + * pt.c (overload_template_name): Set DECL_ARTIFICIAL on the created + TYPE_DECL to fix bogus shadowing warnings. + +Fri Jul 22 01:15:32 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (expand_aggr_init_1): const and volatile mismatches do not + prevent a TARGET_EXPR from initializing an object directly. + +Tue Jul 19 17:55:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (build_up_reference): Allow building up references to + `this', don't warn about making references to artificial variables + (like `this'). + + * tree.c (lvalue_p): `this' is not an lvalue. + + * call.c (build_method_call): Accept using a typedef name (or + template type parameter) for explicit destructor calls. + +Wed Jul 13 03:57:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (hack_identifier): Put back old code so lists of + non-functions will be handled properly. + + * cp-tree.h (TYPE_NEEDS_CONSTRUCTING): #if 0 out; this macro is now + defined in the language-independent tree.h. + + * tree.c (count_functions): Avoid bogus warning when compiling this + function. + +Mon Jul 11 18:37:20 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_reference_init): Always save the initializer of a + reference. + +Fri Jul 8 17:41:46 1994 Mike Stump + + * decl.c (cplus_expand_expr_stmt): Wrap statement expressions inside + CLEANUP_POINT_EXPRs so that the stack slots can be reused. + (disabled for now) + +Fri Jul 8 12:59:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (hack_identifier): Fix for new overloading. + + * typeck.c (build_binary_op_nodefault): Don't mess with division by + zero. + +Fri Jul 8 13:20:28 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * decl2.c (finish_file): Only call walk_sigtables, if + flag_handle_signatures is turned on, don't waste time otherwise. + +Fri Jul 8 02:27:41 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (push_overloaded_decl): Don't create overloads of one when + shadowing a class type. + * typeck.c (build_x_function_call): Complain about overloads of one. + + * decl.c (grokdeclarator): Don't try to treat a char* as a tree. + (grokdeclarator): Fix setting of TREE_STATIC. + (start_decl): Clear DECL_IN_AGGR_P after calling duplicate_decls. + +Thu Jul 7 22:20:46 1994 Gerald Baumgartner (gb@andros.cygnus.com) + + * cp-tree.h (walk_sigtables): Created extern declaration. + * decl2.c (walk_sigtables): Created function, patterned after + walk_vtables, even though we only need it to write out sigtables. + (finish_sigtable_vardecl): Created function. + (finish_vtable_vardecl): Changed 0 to NULL_PTR. + (finish_file): Call walk_sigtables. + + * sig.c (build_signature_table_constructor): Mark class member + function pointed to from signature table entry as addressable. + +Thu Jul 7 13:39:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (start_decl): Check new decl of static member variable + against the declaration in the class here. + (grokvardecl): Instead of here. + + * class.c (prepare_fresh_vtable): Call import_export_vtable if not + -fvtable-thunks. + (build_vtable): Ditto. + + * decl2.c (import_export_vtable): Move logic for deciding the + interface of a template class from here. + (import_export_template): To here. + (finish_vtable_vardecl): Call import_export_template before + import_export_vtable. + +Wed Jul 6 20:25:48 1994 Mike Stump + + * except.c (init_exception_processing): Setup interim_eh_hook to + call lang_interim_eh. + * except.c (do_unwind): Propagate throw object value across + stack unwinding. + * except.c (saved_throw_value): Used to hold the value of the object + being thrown. It is always a reference to the real value. + * except.c (expand_start_catch_block): Add handling for the + value of the exception object. + * except.c (expand_start_catch_block): Add handler for the handler, + so that throws inside the handler go to the outer block. + * except.c (expand_end_catch_block): Ditto. + * parse.y (handler_args): Use parm instead, as the other doesn't yet + handle references correctly. + +Wed Jul 6 17:55:32 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl2.c (mark_vtable_entries): If -ftable-thunks, set the + vtable entry properly to abort. + +Tue Jul 5 14:07:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_binary_op_nodefault): Downgrade division by zero + errors to warnings. + + * call.c (build_overload_call_real): Handle fnname being a list of + functions. + * typeck.c (build_x_function_call): Pass list of functions to + build_overload_call, not just the name. + * tree.c (count_functions): Complain when called for invalid + argument. + + * decl.c (grokdeclarator): Fix settings of TREE_STATIC, TREE_PUBLIC + and DECL_EXTERNAL on static members and initialized const members. + * decl2.c (grokfield): Reflect this change. + +Fri Jul 1 09:35:51 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (init): ANSI C++ does not forbid { }. + +Thu Jun 30 00:35:22 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (lang_decode_option): Set warn_nonvdtor along with -Wall. + warn_nonvdtor defaults to off. + + * class.c (instantiate_type): Use comptypes rather than relying on + types to satisfy ==. + + * decl.c (start_function): Set DECL_DEFER_OUTPUT on all inlines that + might be static. + + * tree.c (build_cplus_new): Never build WITH_CLEANUP_EXPRs. + + * decl.c (grok_reference_init): Deal with ADDR_EXPRs of TARGET_EXPRs. + + * cvt.c (cp_convert): Pass 0 to with_cleanup_p arg of + build_cplus_new. + +Wed Jun 29 22:31:09 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (finish_file): Maybe consider static inlines multiple + times, in case they reference each other. + +Tue Jun 28 11:58:38 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * class.c (finish_struct): Don't `cons_up_default_function's + for signatures. + (finish_struct): Handle an empty method_vec correctly. + + * decl.c (grokdeclarator): Don't warn about a signature being + empty in a signature pointer declaration if we only saw a + forward declaration of the signature. Changed `warning's into + `cp_warning's. + + * sig.c (build_sigtable): Don't die if a null signature table + constructor is returned. + (build_signature_pointer_constructor): If the signature table + constructor is null, the _sptr field is set to a null pointer + and cast to the appropriate type. Make copies of all null + pointers so that the type null_pointer_node doesn't get changed. + (build_signature_table_constructor): Added comments. + + * sig.c (build_signature_pointer_constructor): Complain if we + try to assign to/initialize a signature pointer/reference of + an undefined signature. + +Mon Jun 27 14:05:16 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * typeck2.c (store_init_value): Don't be pedantic about + non-constant initializers of signature tables/pointers/references. + +Fri Jun 24 16:49:41 1994 Gerald Baumgartner (gb@cs.purdue.edu) + + * decl.c (grokdeclarator): If we are grokking an opaque typedef + in a signature, don't complain about it begin static. + +Wed Jun 29 16:44:45 1994 Mike Stump + + Fixes a problem of the this pointer being wrong in virtual calls to + methods that are not overridden in more derived classes. + + * class.c (fixup_vtable_delta): New routine. It will fixup the + delta entries in vtables, wheever they need updating. + * class.c (finish_struct): Call the new routine for all virtual + bases, as they can have different offsets, than those used in base + classes that we derive our vtable from. + +Tue Jun 28 23:49:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_binary_op): Use the types before default + conversions in the error message. + + * *.c: Use c_build_type_variant instead of build_type_variant where + the type might be an array. + + * call.c (build_method_call): Call build_type_variant and + build_reference_type in the right order. + * decl.c (record_builtin_type): Ditto. + +Wed Jun 29 16:58:53 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Call build_type_variant and + build_reference_type in the right order. + * decl.c (record_builtin_type): Ditto. + +Tue Jun 28 23:49:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_binary_op): Use the types before default + conversions in the error message. + + * *.c: Use c_build_type_variant instead of build_type_variant where + the type might be an array. + +Sat Jun 25 11:50:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): Try UDC's before doing the + reinterpret_cast thang, though. + +Fri Jun 24 01:24:01 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (c_expand_return): Don't USE the return value location + after we've expanded the jump. + + * decl2.c (finish_file): Make sure DECL_SAVED_INSNS is not 0 before + trying to write out an inline. + + * cvt.c (build_up_reference): Also do address adjustment when the + target type uses MI. + (convert_to_reference): Try UDCs only after built-in conversions. + (build_type_conversion_1): Don't play games with the argument to the + method. + (build_type_conversion): #if 0 out code for binding to reference. + +Thu Jun 23 00:22:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (finish_file): Use TREE_SYMBOL_REFERENCED to decide + whether to emit inlines. + + * decl.c (grokdeclarator): Set explicit_int for decls that just + specify, say, 'long'. + + * init.c (do_friend): Do overload C functions (or call pushdecl, + anyaway). + +Wed Jun 22 13:40:49 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (build_up_reference): Don't call readonly_error. + (convert_to_reference): Propagate const and volatile from expr to + its type. + + * tree.c (lvalue_p): Random CALL_EXPRs are not lvalues. + + * cvt.c (build_up_reference): Break out WITH_CLEANUP_EXPR when + creating a temporary. + (convert_to_reference): Lose excessive and incorrect trickiness. + (cp_convert): Call build_cplus_new with with_cleanup_p set. + + * typeck2.c (build_functional_cast): Ditto. + +Tue Jun 21 17:38:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): signed, unsigned, long and short all + imply 'int'. + + * decl.c (grokdeclarator): Allow "this is a type" syntax. + (grok_reference_init): Simplify and fix. + +Sun Jun 19 17:08:48 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): pedwarn about a typedef that specifies no + type. + +Sat Jun 18 04:16:50 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (start_function): Move TREE_PUBLIC and DECL_EXTERNAL + tinkering to after call to pushdecl. + +Fri Jun 17 14:48:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Handle destructors for non-aggregate + types properly. + +Thu Jun 16 16:48:05 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Make sure that the name given for the + destructor matches the constructor_name of the instance. + + * pt.c (do_function_instantiation): A non-extern instantiation + overrides a later extern one. + (do_type_instantiation): Ditto. + +Wed Jun 15 19:34:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (expand_aggr_init): Use TYPE_MAIN_VARIANT to get the + unqualified array type. + + * cp-tree.h (EMPTY_CONSTRUCTOR_P): Tests whether NODE is a + CONSTRUCTOR with no elements. + + * decl.c (various): Lose empty_init_node. + (finish_decl): Use EMPTY_CONSTRUCTOR_P, do the empty CONSTRUCTOR + thing depending on the value of DECL_COMMON instead of + flag_conserve_space, do the empty CONSTRUCTOR thing for types that + don't have constructors, don't treat a real empty CONSTRUCTOR + specially. + + * typeck2.c (process_init_constructor): Don't treat empty_init_node + specially. + +Wed Jun 15 19:05:25 1994 Mike Stump + + * class.c (override_one_vtable): Don't forget to merge in an old + overrider when we wanted to reuse a vtable, but couldn't. + +Wed Jun 15 15:03:16 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (start_decl): Put statics in common again. + + * decl.c (grokdeclarator): Return NULL_TREE for an error rather than + setting the type to error_mark_node. + + * typeck.c (build_modify_expr): Build up a COMPOUND_EXPR for enum + bitfield assignments. + +Tue Jun 14 12:23:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_op_properties): Const objects can be passed by value. + +Mon Jun 13 03:10:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (import_export_vtable): Force implicit instantiations to + be interface_only when -fno-implicit-templates. + + * decl.c (duplicate_decls): Redeclaring a class template name is an + error. + + * pt.c (end_template_decl): Call GNU_xref_decl for class templates. + * xref.c (GNU_xref_decl): Support templates. + +Sat Jun 11 17:09:05 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_op_properties): Split out checking for whether this + function should suppress the default assignment operator. + * decl2.c (grok_function_init): Ditto. + (copy_assignment_arg_p): New function do do just that. + Now considers virtual assignment operators that take a base as an + argument to count as copy assignment operators. + + * search.c (dfs_debug_mark): Lose checks for DWARF_DEBUG and + TREE_ASM_WRITTEN, as they are redundant. + + * pt.c (end_template_decl): Don't try to set DECL_CLASS_CONTEXT on a + decl that has no LANG_SPECIFIC part. + (do_type_instantiation): Force the debugging information for this + type to be emitted. + + * decl.c (start_decl): Clear up uses of various types of templates + (say sorry for static data members, rather than "invalid template"). + (expand_static_init): Fix initialization of static data members of + template classes. + +Fri Jun 10 00:41:19 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Set DECL_CONTEXT on static data members. + + * g++.c (main): Use -xc++-cpp-output for .i files. + + * pt.c (tsubst): Give meaningful error about declaring template for + a copy constructor which was not declared in the class template. + (do_type_instantiation): Explicit instantiation before the class + template is an error. + (instantiate_template): Don't die if tsubst returns error_mark_node. + +Thu Jun 9 19:04:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + Don't synthesize the copy assignment operator if the one in a base + class is pure virtual. + * cp-tree.h (TYPE_HAS_ABSTRACT_ASSIGN_REF): New macro to indicate + whether the type has a pure virtual copy assignment operator. + * class.c (finish_base_struct): Don't generate the copy assignment + operator if a base class has a pure virtual one. + * decl.c (grok_op_properties): Add disabled code to set + TYPE_HAS_ABSTRACT_ASSIGN_REF with comment pointing to where it is + actually set. + * decl2.c (grok_function_init): Set TYPE_HAS_ABSTRACT_ASSIGN_REF. + + * decl2.c (import_export_vtable): Always treat template + instantiations as if write_virtuals >= 2, and treat implicit + instantiations as external if -fno-implicit-templates. + (finish_file): Output all pending inlines if + flag_keep_inline_functions. + +Wed Jun 8 20:48:02 1994 Mike Stump + + * tree.c (layout_vbasetypes): Align virtual base classes inside + complete objects, so that we don't core dump on machines such as + SPARCs when we access members that require larger than normal + alignments, such as a double. Also, we bump up the total alignment + on the complete type, as necessary. + +Wed Jun 8 16:18:14 1994 Jason Merrill (jason@deneb.cygnus.com) + + * gxxint.texi (Free Store): New section with code for examining + cookie. + (Limitations of g++): Remove operator delete entry, since it is no + longer accurate. Fix access control entry. + + * typeck.c (build_unary_op): Pedwarn about taking the address of or + incrementing a cast to non-reference type. + (build_modify_expr): Use convert instead of convert_force again. + + * search.c (get_base_distance): Use IS_AGGR_TYPE_CODE to check for + class type, not == RECORD_TYPE. + + * decl.c (grokdeclarator): Cope with grokfndecl returning NULL_TREE. + + * typeck2.c (report_case_error): #if 0 out. + * lex.c (real_yylex): Lose RANGE. + * parse.y: Ditto. + +Tue Jun 7 18:17:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (simple_stmt, case ranges): Use ELLIPSIS instead of RANGE. + +Mon Jun 6 19:39:57 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_c_cast): Don't shortcut conversions to the same + type. Don't replace consts with their values here, since that's now + done in cp_convert. + + * cvt.c (cp_convert): When converting to bool, take + integer_zero_node to false_node and all other INTEGER_CSTs to + true_node. + (build_type_conversion): Don't complain about multiple conversions + to float if we're not really converting. + +Fri Jun 3 02:10:56 1994 Jason Merrill (jason@deneb.cygnus.com) + + Implement 'extern template class A;' syntax for suppressing + specific implicit instantiations. + * cp-tree.h: Update prototypes for do_*_instantiation. + * pt.c (do_pending_expansions): Don't compile 'extern' explicit + instantiations. + (do_function_instantiation): Set DECL_EXTERNAL on 'extern' explicit + instantiations. + (do_type_instantiation): Ditto. + * parse.y (explicit_instantiation): Support 'extern template class + A;' syntax. + * decl.c (start_function): Don't modify the settings of TREE_PUBLIC + and DECL_EXTERNAL on explicit instantiations. + + * cvt.c (cp_convert): Replace constants with their values before + converting. + (cp_convert): Consistently use 'e' instead of 'expr'. + +Thu Jun 2 03:53:30 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck2.c (build_x_arrow): Resolve OFFSET_REFs first. + +Wed Jun 1 18:57:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck2.c (digest_init): Handle initializing a pmf with an + overloaded method. + * typeck.c (build_ptrmemfunc): Handle overloaded methods. + + * decl.c (pushtag): Use build_decl to make TYPE_DECLs. + (xref_defn_tag): Ditto. + * pt.c (process_template_parm): Ditto. + (lookup_template_class): Ditto. + (push_template_decls): Ditto. + (instantiate_class_template): Ditto. + (create_nested_upt): Ditto. + * class.c (finish_struct): Don't try to set DECL_CLASS_CONTEXT on + TYPE_DECLs. + + * typeck.c (convert_arguments): Make sure type is not NULL before + checking its TREE_CODE. + +Wed Jun 1 17:40:39 1994 Mike Stump + + * class.c (get_derived_offset): New routine. + * class.c (finish_base_struct): Make sure we set BINFO_VTABLE and + BINFO_VIRTUALS when we choose a new base class to inherit from. + * class.c (modify_one_vtable): Use get_derived_offset to get the + offset to the most base class subobject that we derived this binfo + from. + * class.c (finish_struct): Move code to calculate the + DECL_FIELD_BITPOS of the vfield up, as we need might need it for + new calls to get_derived_offset in modify_one_vtable. + +Wed Jun 1 16:50:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_member_call): Use build_pointer_type instead of + TYPE_POINTER_TO. + +Wed Jun 1 11:11:15 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (grokdeclarator): Make sure we have a DNAME set before we + try to use it in an error. + +Wed Jun 1 09:48:49 1994 Mike Stump + + * typeck.c (convert_arguments, convert_for_initialization): Don't + strip NOP_EXPRs, when we are converting to a reference. + +Wed Jun 1 01:11:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_modify_expr): Don't dereference references when + initializing them. + + * decl2.c (grokfield): Don't check for grokdeclarator returning + error_mark_node any more. + + * decl.c (grokfndecl): Return NULL_TREE instead of error_mark_node. + (start_method): Return void_type_node instead of error_mark_node. + + * typeck.c (build_modify_expr): Resolve offset refs earlier. + +Tue May 31 16:06:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Resolve OFFSET_REFs in the object. + + * typeck.c (build_modify_expr): Dereference references before trying + to assign to them. + + * call.c (build_method_call): Don't confuse type conversion + operators with constructors. + * typeck2.c (build_functional_cast): Just call build_c_cast if there + was only one parameter. + * method.c (build_typename_overload): Don't set + IDENTIFIER_GLOBAL_VALUE on these identifiers. + * decl.c (grok_op_properties): Warn about defining a type conversion + operator that converts to a base class (or reference to it). + * cvt.c (cp_convert): Don't try to use a type conversion operator + when converting to a base class. + (build_type_conversion_1): Don't call constructor_name_full on an + identifier. + * cp-tree.h (DERIVED_FROM_P): Should be self-explanatory. + + * decl.c (start_decl): Don't complain that error_mark_node is an + incomplete type. + (finish_decl): Check for type == error_mark_node. + +Mon May 30 23:38:55 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (start_function): Set DECL_DEFER_OUTPUT on implicit + instantiations and inline members. + + * spew.c (yylex): Set looking_for_template if the next token is a '<'. + + * lex.h: Declare looking_for_template. + + * decl.c (lookup_name_real): Use looking_for_template to arbitrate + between type and template interpretations of an identifier. + +Sat May 28 04:07:40 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (instantiate_template): Zero out p if we found a + specialization. + + * decl.c (grokdeclarator): Elucidate warning. + (grokdeclarator): If pedantic AND -ansi, complain about long long. + + Make explicit instantiation work reasonably. It is now appropriate + to deprecate the use of -fexternal-templates. + * pt.c (instantiate_template): Set DECL_TEMPLATE_SPECIALIZATION or + DECL_IMPLICIT_INSTANTIATION on fndecl as appropriate. + (end_template_instantiation): Reflect changes in USE_TEMPLATE + semantics. + (do_pending_expansions): if (!flag_implicit_templates) DECIDE(0); + (do_function_instantiation): Don't set EXPLICIT_INST if + flag_external_templates is set. Do set TREE_PUBLIC and DECL_EXTERN + appropriately otherwise. + (do_type_instantiation): Set interface info for class. Set + TREE_PUBLIC and DECL_EXTERN for methods. Do none of this if + flag_external_templates is set. + * parse.y: Reflect changes in USE_TEMPLATE semantics. + * decl2.c: New flag flag_implicit_templates determines whether or + not implicit instantiations get emitted. This flag currently + defaults to true, and must be true for -fexternal-templates to work. + (finish_file): Consider flag_implement_inlines when + setting DECL_EXTERNAL. Consider flag_implicit_templates when + deciding whether or not to emit a static copy. + * decl.c (start_function): Set TREE_PUBLIC and DECL_EXTERNAL + properly for template instantiations. + (start_method): Set DECL_IMPLICIT_INSTANTIATION on methods of a + template class. + * cp-tree.h (CLASSTYPE_USE_TEMPLATE): Change semantics. + (DECL_USE_TEMPLATE): Parallel macro for FUNCTION and VAR_DECLs. + (various others): Accessor macros for the above. + +Fri May 27 13:57:40 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_binary_op_nodefault): Division by constant zero is + an error. + +Fri May 27 13:50:15 1994 Mike Stump + + * class.c (override_one_vtable): Don't modify things we don't own. + +Fri May 27 01:42:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (finish_decl): Don't postpone processing the initializer of + a decl with DECL_EXTERNAL set, and do call rest_of_compilation for a + PUBLIC const at toplevel. + (grokdeclarator): pedwarn about initializing non-const or + non-integral statics in the class body. + + * decl.c (pushtag): Don't try to set DECL_CLASS_CONTEXT on a + TYPE_DECL. + + * call.c (convert_harshness): Dereference reference on rhs before + proceeding, properly grok passing const things to non-const + references. + + * typeck.c (build_unary_op): Soften error about taking the address + of main() to a pedwarn. + + * lex.c (default_copy_constructor_body): Unambiguously specify base + classes (i.e. A((const class ::A&)_ctor_arg) ). + (default_assign_ref_body): Ditto. + +Thu May 26 13:13:55 1994 Gerald Baumgartner (gb@mexican.cygnus.com) + + * decl2.c (grokfield): Don't complain about local signature + method declaration without definition. + + * call.c (convert_harshness): If `type' is a signature pointer + and `parmtype' is a pointer to a signature, just return 0. We + don't really convert in this case; it's a result of making the + `this' parameter of a signature method a signature pointer. + + * call.c (build_method_call): Distinguish calling the default copy + constructor of a signature pointer/reference from a signature + member function call. + +Thu May 26 12:56:25 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (grokfield): Don't set TREE_PUBLIC on member function + declarations. + + * decl.c (duplicate_decls): A previous function declaration as + static overrides a subsequent non-static definition. + (grokdeclarator): Don't set TREE_PUBLIC on inline method + declarations. + +Wed May 25 14:36:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Handle initialization of static const + members. + (finish_decl): Ditto. + + * decl2.c (grokfield): Allow initialization of static const members + even when pedantic. + + * decl2.c (grokfield): Deal with grokdeclarator returning + error_mark_node. + + * decl.c (grok_ctor_properties): Return 0 for A(A) constructor. + (grokfndecl): Check the return value of grok_ctor_properties. + (start_method): Ditto. + + * parse.y (absdcl): Expand type_quals inline. + +Tue May 24 19:10:32 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (pushtag): Use IS_AGGR_TYPE rather than checking for a + RECORD_TYPE. + +Tue May 24 18:09:16 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * cp-tree.h (VTABLE_NAME_FORMAT): If flag_vtable_thunks, + always use "__vt_%s". + * decl2.c (finish_vtable_vardecl): Don't consider abstract virtuals + when looking for a "sentinal" method (to decide on emitting vtables). + * decl2.c (finish_file): Scan all decls for thunks that need + to be emitted. + * decl2.c (finish_vtable_vardecl): Don't bother calling emit_thunk. + * method.c (make_thunk): Use a more meaningful label. If there + exists a matching top-level THUNK_DECL re-use it; otherwise + create a new THUNK_DECL (and declare it). + * method.c (emit_thunk): Make thunk external/public depending + on the underlying method. + +Tue May 24 00:22:04 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (tsubst): Use lookup_name_nonclass to find guiding decls, not + lookup_name. + + * call.c (build_overload_call_real): Don't immediately pick a + function which matches perfectly. + + * decl.c (grokdeclarator): Use c_build_type_variant for arrays. + (grokdeclarator): Warn about, and throw away, cv-quals attached to a + reference (like 'int &const j'). + + * typeck.c (convert_arguments): Don't mess with i for methods. + * call.c (build_method_call): Pass the function decl to + convert_arguments. + + * typeck.c (comp_ptr_ttypes_real): New function. Implements the + checking for which multi-level pointer conversions are allowed. + (comp_target_types): Call it. + (convert_for_assignment): Check const parity on the ultimate target + type, too. And make those warnings pedwarns. + +Mon May 23 14:11:24 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_char): Use TARGET_* for character constants. + +Mon May 23 13:03:03 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * tree.c (debug_no_list_hash): Make static. + + * decl.c (decls_match): Say the types don't match if newdecl ends up + with a null type, after we've checked if olddecl does. + (pushdecl): Check if the decls themselves match before looking for + an extern redeclared as static, to avoid inappropriate and incorrect + warnings. + +Fri May 20 14:04:34 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Make warning about duplicate short, etc. + a pedwarn. + + * typeck.c (build_c_cast): Casting to function or method type is an + error. + + * class.c (finish_struct): Make warning for anonymous class with no + instances a pedwarn. + + * Makefile.in (stamp-parse): Expect a s/r conflict. + + * typeck.c (build_modify_expr): pedwarn about using a non-lvalue + cast as an lvalue. + +Thu May 19 12:08:48 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (type_promotes_to): Make sure bool promotes to int rather + than unsigned on platforms where sizeof(char)==sizeof(int). + +Wed May 18 14:27:06 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_c_cast): Tack on a NOP_EXPR when casting to + another variant. + (build_modify_expr): Don't strip NOP_EXPRs, and don't get tricky + and treat them as lvalues. + + * decl.c (shadow_tag): Do complain about forward declarations of + enums and empty declarations. + * parse.y: Don't complain about forward declarations of enums and + empty declarations. + + * typeck.c (convert_for_assignment): Complain about changing + the signedness of a pointer's target type. + + * parse.y (stmt): Move duplicated code for checking case values from + here. + * decl2.c (check_cp_case_value): To here. And add a call to + constant_expression_warning. + + * typeck.c (convert_for_assignment): Don't complain about assigning + a negative value to bool. + + * decl.c (init_decl_processing): Make bool unsigned. + + * class.c (finish_struct): Allow bool bitfields. + +Wed May 18 12:35:27 1994 Ian Lance Taylor (ian@tweedledumb.cygnus.com) + + * Make-lang.in (c++.install-man): Get g++.1 from $(srcdir)/cp. + +Wed May 18 03:28:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (build_type_conversion): Lose special handling of + truthvalues. + + * search.c (dfs_pushdecls): Improve shadowing warning. + +Tue May 17 13:34:46 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_delete): Throw away const and volatile on `this'. + + * decl.c (finish_enum): Put the constants in TYPE_VALUES again, + rather than the enumerators. + (pushtag): s/cdecl/c_decl/g + +Mon May 16 23:04:01 1994 Stephen R. van den Berg (berg@pool.informatik.rwth-aachen.de) + + * cp/typeck.c (common_type): Attribute merging. + (comp_types): Utilise COMP_TYPE_ATTRIBUTES macro. + + * cp/parse.y: Revamp attribute parsing. + +Mon May 16 01:40:34 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (shadow_tag): Also check for inappropriate use of auto and + register. + + * method.c (build_overload_name): Clarify that the illegal case is a + pointer or reference to array of unknown bound. + + * error.c (dump_type_prefix): Print references to arrays properly. + + * typeck.c (various): Be more helpful in pointer + comparison diagnostics. + + * tree.c (lvalue_p): MODIFY_EXPRs are lvalues again. Isn't this + fun? + + * parse.y: Also catch an error after valid stmts. + + * search.c (dfs_init_vbase_pointers): Don't abort because `this' is + const. + + * typeck.c (convert_for_initialization): If call to + convert_to_reference generated a diagnostic, print out the parm + number and function decl if any. + + * errfn.c (cp_thing): Check atarg1 to determine whether or not we're + specifying a line, not atarg. + + * tree.c (build_cplus_method_type): Always make `this' const. + + * decl2.c (grokclassfn): If -fthis-is-variable and this function is + a constructor or destructor, make `this' non-const. + + * typeck.c (build_modify_expr): Don't warn specially about + assignment to `this' here anymore, since it will be caught by the + usual machinery. + + * various: Disallow specific GNU extensions (variable-size arrays, + etc.) when flag_ansi is set, not necessarily when pedantic is set, + so that people can compile with -pedantic-errors for tighter const + checking and such without losing desirable extensions. + + * typeck2.c (build_functional_cast): Call build_method_call with + LOOKUP_PROTECT. + (process_init_constructor): Only process FIELD_DECLs. + + * decl.c (finish_decl): Also force static consts with no explicit + initializer that need constructing into the data segment. + + * init.c (build_delete): Undo last patch, as it interferes with + automatic cleanups. + +Sat May 14 01:59:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c, class.h, cp-tree.h, cvt.c, decl2.c: Lose old overloading + code. + + * init.c (build_delete): pedwarn about using plain delete to delete + an array. + +Fri May 13 16:45:07 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (comp_target_types): Be more helpful in contravariance + warnings, and make them pedwarns. + + * decl.c (grokdeclarator): Use decl_context to decide whether or not + this is an access declaration. + + * class.c (finish_struct_bits): Set TYPE_HAS_INT_CONVERSION if it + has a conversion to enum or bool, too. + +Fri May 13 16:31:27 1994 Mike Stump + + * method.c (emit_thunk): Make declaration for + current_call_is_indirect local (needed for hppa). + +Fri May 13 16:16:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (uses_template_parms): Grok BOOLEAN_TYPE. + (tsubst): Ditto. + +Fri May 13 16:23:32 1994 Mike Stump + + * pt.c (tsubst): If there is already a function for this expansion, + use it. + * pt.c (instantiate_template): Ditto. + +Fri May 13 10:30:42 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * parse.y (implicitly_scoped_stmt, simple_stmt case): Use + kept_level_p for MARK_ENDS argument to expand_end_bindings, to avoid + generating debug info for unemitted symbols on some systems. + + * cp-tree.h (build_static_cast, build_reinterpret_cast, + build_const_cast): Add declarations. + +Fri May 13 09:50:31 1994 Mike Stump + + * search.c (expand_indirect_vtbls_init): Fix breakage from Apr 27 + fix. We now try get_binfo, and if that doesn't find what we want, + we go back to the old method, which still sometimes fails. + +Fri May 13 01:43:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (initdcl): Call cplus_decl_attributes on the right + variable. + * decl2.c (cplus_decl_attributes): Don't call decl_attributes for + void_type_node. + + * typeck.c (build_binary_op_nodefault): Change result_type for + comparison ops to bool. + (build_binary_op): Convert args of && and || to bool. + * cvt.c (build_default_binary_type_conversion): Convert args of && + and || to bool. + (build_default_unary_type_conversion): Convert arg of ! to bool. + (type_promotes_to): bool promotes to int. + +Fri May 13 01:43:18 1994 Mike Stump + + Implement the new builtin `bool' type. + * typeck.c (build_binary_op_nodefault): Convert args of && and || to + bool. + (build_unary_op): Convert arg of ! to bool. + * parse.y: Know true and false. Use bool_truthvalue_conversion. + * method.c (build_overload_value): Know bool. + (build_overload_name): Ditto. + * lex.c (init_lex): Set up RID_BOOL. + * gxx.gperf: Add bool, true, false. + * error.c (*): Know bool. + * decl.c (init_decl_processing): Set up bool, true, false. + * cvt.c (cp_convert): Handle conversion to bool. + (build_type_conversion): Ditto. + * *.c: Accept bool where integers and enums are accepted (use + INTEGRAL_CODE_P macro). + +Thu May 12 19:13:54 1994 Richard Earnshaw (rwe11@cl.cam.ac.uk) + + * g++.c: Use #ifdef for __MSDOS__, not #if. + +Thu May 12 18:05:18 1994 Mike Stump + + * decl2.c (lang_f_options): Handle -fshort-temps. -fshort-temps + gives old behavior , and destroys temporaries earlier. Default + behavior now conforms to the ANSI working paper. + +Thu May 12 14:45:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_modify_expr): Understand MODIFY_EXPR as an lvalue. + Use convert_force to convert the result of a recursive call when we + are dealing with a NOP_EXPR. Don't automatically wrap MODIFY_EXPRs + in COMPOUND_EXPRs any more. + (various): Lose pedantic_lvalue_warning. + (unary_complex_lvalue): Understand MODIFY_EXPR. + + * cvt.c (convert_to_reference): Allow DECL to be error_mark_node if + we don't know what we're initializing. + +Wed May 11 01:59:36 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): Modify to use convtype parameter. + Only create temporaries when initializing a reference, not when + casting. + (cp_convert): New main function. + (convert): Call cp_convert. + * cvt.c, decl.c, typeck.c: Fix calls to convert_to_reference. + * cp-tree.h (CONV_*): New constants used by conversion code for + selecting conversions to perform. + + * tree.c (lvalue_p): MODIFY_EXPRs are no longer lvalues. + + * typeck.c (build_{static,reinterpret,const_cast): Stubs that just + call build_c_cast. + * parse.y: Add {static,reinterpret,const}_cast. + * gxx.gperf: Ditto. + + * typeck.c (common_type): Allow methods with basetypes of different + UPTs. + (comptypes): Deal with UPTs. + (build_modify_expr): Wrap all MODIFY_EXPRs in a COMPOUND_EXPR. + + * pt.c (end_template_decl): Check for multiple definitions of member + templates. + + * call.c (build_method_call): Complain about calling an abstract + virtual from a constructor. + + * typeck.c (pointer_int_sum): Check for the integer operand being 0 + after checking the validity of the pointer operand. + + * typeck2.c (digest_init): Pedwarn about string initializer being + too long. + +Tue May 10 12:10:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (push_overloaded_decl): Only throw away a builtin if the + decl in question is the artificial one. + + * parse.y (simple_stmt, switch): Use implicitly_scoped_stmt because + expand_{start,end}_case cannot happen in the middle of a block. + + * cvt.c (build_type_conversion_1): Use convert again. + +Tue May 10 11:52:04 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * typeck2.c (digest_init): Make sure we check for signed and + unsigned chars as well when warning about string initializers. + + * init.c (emit_base_init): Check if there's a DECL_NAME on the + member before trying to do an initialization for it. + +Tue May 10 11:34:37 1994 Mike Stump + + * except.c: Don't do anything useful when cross compiling. + +Tue May 10 03:04:13 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (duplicate_decls): Fix up handling of builtins yet again. + (push_overloaded_decl): Ditto. + + * cvt.c (convert): Don't look for void type conversion. + +Mon May 9 18:05:41 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (do_friend): Only do a pushdecl for friends, not + pushdecl_top_level. + +Mon May 9 13:36:34 1994 Jim Wilson (wilson@sphagnum.cygnus.com) + + * decl.c (lookup_name_current_level): Put empty statement after + the label OUT to make the code valid C. + +Mon May 9 12:20:57 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_binary_op_nodefault): Only complain about + comparing void * and a function pointer if void * is smaller. + +Sun May 8 01:29:13 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (lookup_name_current_level): Move through temporary binding + levels. + + * parse.y (already_scoped_stmt): Revive. + (simple_stmt): Use it again. + + * decl.c (poplevel): Always call poplevel recursively if we're + dealing with a temporary binding level. + +Sat May 7 10:52:28 1994 Mike Stump + + * decl.c (finish_decl): Make sure we run cleanups for initial values + of decls. Cures memory leak. + * decl.c (expand_static_init): Ditto for static variables. + * decl2.c (finish_file): Ditto for globals. + +Sat May 7 03:57:44 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (commonparms): Don't complain about redefining default + args. + + * decl.c (duplicate_decls): Don't complain twice about conflicting + function decls. + (decls_match): Don't look at default args. + (redeclaration_error_message): Complain about redefining default + args. + + * call.c (build_overload_call_real): Also deal with guiding + declarations coming BEFORE the template decl. + + * pt.c (unify): Allow different parms to have different + cv-qualifiers. + (unify): Allow trivial conversions on non-template parms. + +Fri May 6 03:53:23 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (tsubst): Support OFFSET_TYPEs. + (unify): Ditto. + + * decl2.c (finish_decl_parsing): Call push_nested_class with a type. + + * init.c (build_offset_ref): Fix error message. + * search.c (lookup_field): Ditto. + + * call.c (build_scoped_method_call): Pass binfo to + build_method_call. + * typeck.c (build_object_ref): Ditto. + + * typeck2.c (binfo_or_else): Don't return a _TYPE. + + * class.c (finish_struct): Don't complain about re-use of inherited + names or shadowing of type decls. + * decl.c (pushdecl_class_level): Ditto. + + * decl.c (finish_enum): Set the type of all the enums. + + * class.c (finish_struct): Don't get confused by access decls. + + * cp-tree.h (TYPE_MAIN_DECL): New macro to get the _DECL for a + _TYPE. You can stop using TYPE_NAME for that now. + + * parse.y: Lose doing_explicit (check $0 instead). + * gxx.gperf: 'template' now has a RID. + * lex.h (rid): Ditto. + * lex.c (init_lex): Set up the RID for 'template'. + + * parse.y (type_specifier_seq): typed_typespecs or + nonempty_type_quals. Use it. + (handler_args): Fix bogus syntax. + (raise_identifier{,s}, optional_identifier): Lose. + * except.c (expand_start_catch_block): Use grokdeclarator to parse + the catch variable. + (init_exception_processing): The second argument to + __throw_type_match is ptr_type_node. + + Fri May 6 07:18:54 1994 Chip Salzenberg (chip@fin) + + [ change propagated from c-decl.c of snapshot 940429 ] + * cp/decl.c (finish_decl): Setting asmspec_tree should not + zero out the old RTL. + +Fri May 6 01:25:38 1994 Mike Stump + + Add alpha exception handling support to the compiler. + Quick and dirty backend in except.c. + + * cp/*: Remove most remnants of old exception handling support. + * decl.c (finish_function): Call expand_exception_blocks to put + the exception hanlding blocks at the end of the function. + * dec.c (hack_incomplete_structures): Make sure expand_decl_cleanup + comes after expand_decl_init. + * except.c: Reimplementation. + * expr.c (cplus_expand_expr): Handle THROW_EXPRs. + * lex.c (init_lex): Always have catch, try and throw be reserved + words, so that we may always parse exception handling. + * parse.y: Cleanup to support new interface into exception handling. + * tree.def (THROW_EXPR): Add. + +Thu May 5 17:35:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (simple_stmt, for loops): Use implicitly_scoped_stmt. + (various): Lose .kindof_pushlevel and partially_scoped_stmt. + +Thu May 5 16:17:27 1994 Kung Hsu (kung@mexican.cygnus.com) + + * parse.y (already_scoped_stmt): move expand_end_binding() to + fix the unmatched LBB/LBE in stabs. + +Thu May 5 14:36:17 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (set_nested_typename): Set TREE_MANGLED on the new + identifiers. + (pushdecl): Check TREE_MANGLED. + (xref_tag): Ditto. + * cp-tree.h (TREE_MANGLED): This identifier is a + DECL_NESTED_TYPENAME (named to allow for future use to denote + mangled function names as well). + + Implement inconsistency checking specified in [class.scope0]. + * decl.c (lookup_name_real): Don't set ICV here after all. + (finish_enum): Also set the type of the enumerators themselves. + (build_enumerator): Put the CONST_DECL in the list instead of its + initial value. + (pushdecl_class_level): Check inconsistent use of a name in the + class body. + * class.c (finish_struct): Check inconsistent use of a name in the + class body. Don't set DECL_CONTEXT on types here anymore. + * parse.y (qualified_type_name): Note that the identifier has now + been used (as a type) in the class body. + * lex.c (do_identifier): Note that the identifier has now been used + (as a constant) in the class body. + * error.c (dump_decl): Print type and enum decls better. + +Thu May 5 09:35:35 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * typeck.c (build_modify_expr): Warn about assignment to `this'. + +Wed May 4 15:55:49 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_delete): Use the global operator delete when + requested. + + * decl.c (lookup_name_real): If we find the type we're looking in a + base class while defining a class, set IDENTIFIER_CLASS_VALUE for + the type. + + * class.c (finish_struct): Remove a couple of dependencies on + language linkage. + + * decl.c (pushtag): Classes do nest in extern "C" blocks. + (pushdecl): Only set DECL_NESTED_TYPENAME on the canonical one for + the type. + (pushtag): Remove another dependency on the language linkage. + + * lex.c (cons_up_default_function): Don't set DECL_CLASS_CONTEXT to + a const-qualified type. + + * decl.c (push_overloaded_decl): Throw away built-in decls here. + (duplicate_decls): Instead of here. + +Wed May 4 15:27:40 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * typeck.c (get_member_function_from_ptrfunc): Do The Right + Thing (I hope) if we're using thunks. + +Wed May 4 13:52:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (specialization): aggr template_type_name ';'. + (named_class_head_sans_basetype): Use it. + (explicit_instantiation): Ditto. + (tmpl.2): Revert. + + * cvt.c (build_type_conversion_1): Use convert_for_initialization, + rather than convert, to do conversions after the UDC. + + * cp-tree.h (SHARED_MEMBER_P): This member is shared between all + instances of the class. + + * search.c (lookup_field): If the entity found by two routes is the + same, it's not ambiguous. + +Wed May 4 12:10:00 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (lookup_name_real): Check for a NULL TREE_VALUE, + to prevent the compiler from crashing ... + +Wed May 4 11:19:45 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): If we don't have an object, check + basetype_path to figure out where to look up the function. + + * typeck.c (convert_for_initialization): Pass TYPE_BINFO (type) to + build_method_call in case exp is NULL_TREE. + +Tue May 3 16:02:53 1994 Per Bothner (bothner@kalessin.cygnus.com) + + Give a vtable entries a unique named type, for the sake of gdb. + * class.c (build_vtable_entry): The addres of a thunk now has + type vtable_entry_type, not ptr_type_node. + * method.c (make_thunk): Fix type of THUNK_DECL. + * class.c (add_virtual_function, override_one_vtable): Use + vfunc_ptr_type_node, instead of ptr_type_node. + * cp-tree.h (vfunc_ptr_type_node): New macro. + * decl.c (init_decl_processing): Make vtable_entry_type + be a unique type of pointer to a unique function type. + +Tue May 3 09:20:44 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (do_explicit): Sets doing_explicit to 1. + (explicit_instantiation): Use do_explicit rather than TEMPLATE + directly, add "do_explicit error" rule. + (datadef): Set doing_explicit to 0 after an explicit instantiation. + (tmpl.2): Don't instantiate if we see a ';' unless we're doing an + explicit instantiation. + (named_class_head_sans_basetype): Remove aggr template_type_name + ';' again. + +Mon May 2 23:17:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (lookup_nested_tag): Lose. + + * decl2.c (grokfield): Set DECL_CONTEXT on TYPE_DECLs. + (lookup_name_nonclass): Lose. + + * decl.c (poplevel_class): Add force parameter. + (lookup_name_real): Fix handling of explicit scoping which specifies + a class currently being defined. Add 'nonclass' argument. + (lookup_name, lookup_name_nonclass): Shells for lookup_name_real. + + * class.c (finish_struct): Don't unset IDENTIFIER_CLASS_VALUEs here. + (popclass): Force clearing of IDENTIFIER_CLASS_VALUEs if we're being + called from finish_struct. + +Mon May 2 19:06:21 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (init_decl_processing), cp-tree.h: Removed memptr_type. + (It seeems redundant, given build_ptrmemfunc_type.) + * typeck.c (get_member_function_from_ptrfunc), gc.c (build_headof, + build_classof): Use vtable_entry_type instead of memptr_type. + * method.c (emit_thunk): Call poplevel with functionbody==0 + to prevent DECL_INITIAL being set to a BLOCK. + +Mon May 2 15:02:11 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (named_class_head_sans_basetype): Add "aggr + template_type_name ';'" rule for forward declaration of + specializations. + +Mon May 2 15:02:11 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (instantiate_type): Deal with pmf's. + + * Make-lang.in (cc1plus): Don't depend on OBJS or BC_OBJS, since + stamp-objlist does. + + * Makefile.in (../cc1plus): Depend on OBJDEPS. + (OBJDEPS): Dependency version of OBJS. + +Mon May 2 12:51:31 1994 Kung Hsu (kung@mexican.cygnus.com) + + * search.c (dfs_debug_mark): unmark TYPE_DECL_SUPPRESS_DEBUG, not + DECL_IGNORED_P. + +Fri Apr 29 12:29:56 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Clear out memory of local tags. And + typedefs. + + * decl2.c (grokclassfn): Don't set DECL_CONTEXT to a cv-qualified + type. + * search.c (get_matching_virtual): Be more helpful in error message. + + * *: Use DECL_ARTIFICIAL (renamed from DECL_SYNTHESIZED). + + * lex.c (default_assign_ref_body): Expect TYPE_NESTED_NAME to work. + (default_copy_constructor_body): Ditto. + + * class.c (finish_struct): Don't gratuitously create multiple decls + for nested classes. + +Thu Apr 28 23:39:38 1994 Jason Merrill (jason@deneb.cygnus.com) + + Avoid clobbering the arg types of other functions when reverting + static member functions. + * decl.c (revert_static_member_fn): Rearrange arguments, don't + require values for 'fn' and 'argtypes', add warning to comment + above. + (decls_match): Rearrange arguments in call to rsmf. + (grok_op_properties): Don't pass values for fn and argtypes. + * pt.c (instantiate_template): Don't pass values for fn and argtypes. + +Thu Apr 28 16:29:11 1994 Doug Evans (dje@canuck.cygnus.com) + + * Make-lang.in (cc1plus): Depend on stamp-objlist. + * Makefile.in (BC_OBJS): Delete. + (OBJS): Cat ../stamp-objlist to get language independent files. + Include ../c-common.o. + (../cc1plus): Delete reference to BC_OBJS. + +Thu Apr 28 02:12:08 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (compute_access): No really, deal with static members + properly. Would I lie to you? + + Implement lexical hiding of function declarations. + * pt.c (tsubst): Use lookup_name to look for function decls to guide + instantiation. + * method.c (build_opfncall): Use lookup_name_nonclass to look for + non-member functions. + * init.c (do_friend): Use lookup_name_nonclass to look for + functions. + * error.c (ident_fndecl): Use lookup_name to look for functions. + * decl2.c (lookup_name_nonclass): New function, skips over + CLASS_VALUE. + * decl.c (struct binding_level): Lose overloads_shadowed field. + (poplevel): Don't deal with overloads_shadowed. + (push_overloaded_decl): Do lexical hiding for functions. + * class.c (instantiate_type): Don't check non-members if we have + members with the same name. + * call.c (build_method_call): Use lookup_name_nonclass instead of + IDENTIFIER_GLOBAL_VALUE to check for non-member functions. + (build_overload_call_real): Ditto. + + * decl.c (duplicate_decls): Check for ambiguous overloads here. + (push_overloaded_decl): Instead of here. + + * decl.c (pushdecl): Back out Chip's last change. + + * decl.c (grok_op_properties): operators cannot be static members. + + * cp-tree.h (DECL_SYNTHESIZED): DECL_SOURCE_LINE == 0 + (SET_DECL_SYNTHESIZED): DECL_SOURCE_LINE = 0 + * lex.c (cons_up_default_function): Use SET_DECL_SYNTHESIZED. + + * method.c (do_inline_function_hair): Don't put friends of local + classes into global scope, either. + + * typeck2.c (build_functional_cast): Don't look for a function call + interpretation. + +Thu Apr 28 15:19:46 1994 Mike Stump + + * cp-tree.h: disable use of backend EH. + +Wed Apr 27 21:01:24 1994 Doug Evans (dje@canuck.cygnus.com) + + * Make-lang.in (c++.distdir): mkdir tmp/cp first. + * Makefile.in (INCLUDES): Move definition to same place as + parent makefile. + (ALLOCA): Define. + (OLDAR_FLAGS): Delete. + (OLDCC): Define. + (DIR): Delete. + (CLIB): Define. + (####site): Delete. + (SUBDIR_USE_ALLOCA): Don't use ALLOCA if compiling with gcc. + +Wed Apr 27 19:10:04 1994 Kung Hsu (kung@mexican.cygnus.com) + + * decl.c (xref_tag): not to use strstr(), it's not available on + all platforms. + +Wed Apr 27 18:10:12 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Resolve yet another class/pmf confusion. + + * call.c (build_overload_call_real): Don't take the single-function + shortcut if we're dealing with an overloaded operator. + +Wed Apr 27 17:35:37 1994 Mike Stump + + * search.c (get_base_distance): Search the virtual base class + binfos, incase someone wants to convert to a real virtual base + class. + * search.c (expand_indirect_vtbls_init): Use convert_pointer_to_real + instead of convert_pointer_to, as it now will work. + +Wed Apr 27 15:36:49 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): Don't complain about casting away + const and volatile. + + * typeck.c (build_unary_op): References are too lvalues. + +Wed Apr 27 13:58:05 1994 Mike Stump + + * class.c (override_one_vtable): We have to prepare_fresh_vtable + before we modify it, not after, also, we cannot reuse an old vtable, + once we commit to a new vtable. Implement ambiguous overrides in + virtual bases as abstract. Hack until we make the class + ill-formed. + +Wed Apr 27 01:17:08 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (unary_expr): Expand new_placement[opt] and + new_initializer[opt] inline. + + * search.c (lookup_fnfields): Don't throw away the inheritance + information here, either. + (compute_access): Handle static members properly. + + * init.c (build_member_call): Always set basetype_path, and pass it + to lookup_fnfields. + + * search.c (lookup_field): Deal properly with the case where + xbasetype is a chain of binfos; don't throw away the inheritance + information. + (compute_access): protected_ok always starts out at 0. + + * init.c (resolve_offset_ref): Don't cast `this' to the base type + until we've got our basetype_path. + + * cp-tree.h (IS_OVERLOAD_TYPE): aggregate or enum. + + * cvt.c (build_up_reference): Use build_pointer_type rather than + TYPE_POINTER_TO. + + * call.c (convert_harshness_ansi): Call type_promotes_to for reals + as well. + + * cvt.c (type_promotes_to): Retain const and volatile, add + float->double promotion. + + * decl.c (grokdeclarator): Don't bash references to arrays into + references to pointers in function parms. Use type_promotes_to. + +Tue Apr 26 23:44:36 1994 Mike Stump + + Finish off Apr 19th work. + + * class.c (finish_struct_bits): Rename has_abstract_virtuals to + might_have_abstract_virtuals. + * class.c (strictly_overrides, override_one_vtable, + merge_overrides): New routines to handle virtual base overrides. + * class.c (finish_struct): Call merge_overrides to handle overrides + in virtual bases. + +Tue Apr 26 12:45:53 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_function_call): Call build_function_call_real with + LOOKUP_NORMAL. + + * *: Don't deal with TYPE_EXPRs. + + * tree.c (lvalue_p): If the type of the expression is a reference, + it's an lvalue. + + * cvt.c (convert_to_reference): Complain about passing const + lvalues to non-const references. + (convert_from_reference): Don't arbitrarily throw away const and + volatile on the target type. + + * parse.y: Simplify and fix rules for `new'. + + * decl.c (grok_op_properties): operator void is illegal. + +Mon Apr 25 02:36:28 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (components): Anonymous bitfields can still have declspecs. + + * decl.c (pushdecl): Postpone handling of function templates like we + do C functions. + + * search.c (expand_indirect_vtbls_init): Fix infinite loop when + convert_pointer_to fails. + + * call.c (compute_conversion_costs_ansi): A user-defined conversion + by itself is better than that UDC followed by standard conversions. + Don't treat integers and reals specially. + + * cp-tree.h: Declare flag_ansi. + + * typeck.c (c_expand_return): pedwarn on return in void function + even if the expression is of type void. + (build_c_cast): Don't do as much checking for casts to void. + (build_modify_expr): pedwarn about array assignment if this code + wasn't generated by the compiler. + + * tree.c (lvalue_p): A comma expression is an lvalue if its second + operand is. + + * typeck.c (default_conversion): Move code for promoting enums and + ints from here. + * cvt.c (type_promotes_to): To here. + * call.c (convert_harshness_ansi): Use type_promotes_to. Also fix + promotion semantics for reals. + +Sun Apr 24 16:52:51 1994 Doug Evans (dje@canuck.cygnus.com) + + * Make-lang.in (c++.install-common): Check for g++-cross. + * Makefile.in: Remove Cygnus cruft. + (config.status): Delete. + (RTL_H): Define. + (TREE_H): Use complete pathname, some native makes have minimal + VPATH support. + (*.o): Use complete pathname to headers in parent dir. + (doc, info, dvi): Delete. + +Sun Apr 24 16:52:51 1994 Doug Evans (dje@canuck.cygnus.com) + + * Make-lang.in (c++.install-common): Check for g++-cross. + * Makefile.in: Remove Cygnus cruft. + (config.status): Delete. + (RTL_H): Define. + (TREE_H): Use complete pathname, some native makes have minimal + VPATH support. + (*.o): Use complete pathname to headers in parent dir. + (doc, info, dvi): Delete. + +Sun Apr 24 00:47:49 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (pushdecl): Avoid redundant warning on redeclaring function + with different return type. + (decls_match): Compare return types strictly. + +Fri Apr 22 12:55:42 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (build_type_conversion): Do try to convert through other + pointers. This will fail if the class defines multiple pointer + conversions. + + * error.c (dump_type_prefix): Print out pointers to arrays properly. + (dump_type_suffix): Ditto. (was 'int *[]', now 'int (*)[]') + + * typeck.c (build_unary_op): Disallow ++/-- on pointers to + incomplete type. + + * decl.c (duplicate_decls): Check mismatched TREE_CODES after + checking for shadowing a builtin. If we're redeclaring a builtin + function, bash the old decl to avoid an ambiguous overload. + + * cvt.c (convert_to_reference): Don't force arrays to decay here. + + * tree.c (lvalue_p): A MODIFY_EXPR is an lvalue. + + * decl.c (duplicate_decls): Don't assume that the decls will have + types. + + Mon Apr 18 11:35:32 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940318 snapshot ] + * c-decl.c (pushdecl): Warn if type mismatch with another external decl + in a global scope. + + Fri Apr 22 06:38:56 1994 Chip Salzenberg (chip@fin.uucp) + + * cp/typeck2.c (signature_error): Use cp_error for "%T". + + Mon Apr 18 11:59:59 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940415 snapshot ] + * cp/decl.c (duplicate_decls, pushdecl, builtin_function): + Use DECL_FUNCTION_CODE instead of DECL_SET_FUNCTION_CODE. + + Mon Apr 18 11:55:18 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940409 snapshot ] + * cp/decl.c (duplicate_decls): Put new type in same obstack as + old ones, or permanent if old ones in different obstacks. + + Mon Apr 18 11:48:49 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940401 snapshot ] + * cp/parse.y (attrib): Handle string args as expressions, + merging the two rules. `mode' attribute now takes a string arg. + Delete the rule for an identifier as arg. + + Mon Apr 18 11:24:00 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940312 snapshot ] + * cp/typeck.c (pointer_int_sum): Multiplication should be done signed. + (pointer_diff): Likewise the division. + + Sun Mar 6 19:43:39 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940304 snapshot ] + * cp/decl.c (finish_decl): Issue warning for large objects, + if requested. + + Sat Feb 19 22:20:32 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940218 snapshot ] + * cp/parse.y (attrib): Handle attribute ((section ("string"))). + * cp/decl.c (duplicate_decls): Merge section name into new decl. + + Tue Feb 8 09:49:17 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp/* changes propagated from c-* changes in 940206 snapshot ] + * cp/typeck.c (signed_or_unsigned_type): Check for any + INTEGRAL_TYPE_P not just INTEGER_TYPE. + + Mon Dec 6 13:35:31 1993 Norbert Kiesel (norbert@i3.INformatik.rwth-aachen.DE) + + * cp/decl.c (finish_enum): Start from 0 when determining precision + for short enums. + + Fri Dec 3 17:07:58 1993 Ralph Campbell (ralphc@pyramid.COM) + + * cp/parse.y (unary_expr): Look at $1 for tree_code rather than + casting $$. + + Wed Nov 17 19:22:09 1993 Chip Salzenberg (chip@fin.uucp) + + * cp/typeck.c (build_binary_op_nodefault): Propagate code + from C front-end to optimize unsigned short division. + (build_conditional_expr): Fix bug in "1 ? 42 : (void *) 8". + + Wed Nov 17 19:17:18 1993 Chip Salzenberg (chip@fin.uucp) + + * cp/call.c (convert_harshness_ansi): Given an (e.g.) char + constant, prefer 'const char &' to 'int'. + + Wed Feb 3 13:11:48 1993 Chip Salzenberg (chip@fin.uucp) + + * cp/class.c (finish_struct_methods): Handle multiple + constructors in fn_fields list. + +Fri Apr 22 12:48:10 1994 Kung Hsu (kung@mexican.cygnus.com) + + * class.c (finish_struct): use TYPE_DECL_SUPPRESS_DEBUG to flag + types not to be dumped in stabs, like types in #pragma interface. + * decl.c (init_decl_processing): use TYPE_DECL_SUPPRESS_DEBUG to + mark unknown type. + +Fri Apr 22 03:27:26 1994 Doug Evans (dje@cygnus.com) + + * Language directory reorganization. + See parent makefile. + +Thu Apr 21 18:27:57 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * cp-tree.h (THUNK_DELTA): It is normally negative, so + use signed .i variant of frame_size rather than unsigned .u. + * cp-tree.h (VTABLE_NAME_FORMAT): If flag_vtable_thunks, + use "VT" rather than "vt" due to binary incompatibility. + * class.c (get_vtable_name): Use strlen of VTABLE_NAME_FORMAT, + rather than sizeof, since it is now an expression. + * class.c (modify_one_vtable): Modify to skip initial element + containing a count of the vtable. + +Thu Apr 21 00:09:02 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (check_newline): Force interface_unknown on main input file. + + * pt.c (do_pending_expansions): Always emit functions that have been + explicitly instantiated. + (do_function_instantiation): Set DECL_EXPLICITLY_INSTANTIATED. + (do_type_instantiation): Set CLASSTYPE_VTABLE_NEEDS_WRITING and + DECL_EXPLICITLY_INSTANTIATED on all my methods. + * parse.y (explicit_instantiation): Call do_type_instantiation for + types. + * decl2.c (finish_vtable_vardecl): Call import_export_vtable. + * decl.c (start_function): Don't set DECL_EXTERNAL on a function + that has been explicitly instantiated. + * cp-tree.h (DECL_EXPLICITLY_INSTANTIATED): Alias for + DECL_LANG_FLAG_4. + * class.c: Move import_export_vtable to decl2.c, and comment out all + uses. + +Wed Apr 20 16:51:06 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (process_next_inline): Don't muck with DECL_INLINE. + (do_pending_inlines): Ditto. + +Tue Apr 19 22:25:41 1994 Mike Stump + + Reimplement vtable building, and most vtable pointer setting. + Allows for earier maintenance, easier understandability, and most + importantly, correct semantics. + + * class.c (build_vtable): Removed unneeded + SET_BINFO_VTABLE_PATH_MARKED. + * class.c (prepare_fresh_vtable): Ditto. Added argument. + * class.c (modify_vtable_entry): General cleanup. + * class.c (related_vslot, is_normal, modify_other_vtable_entries, + modify_vtable_entries): Removed. + * class.c (add_virtual_function): General cleanup. + * class.c (finish_base_struct): Setup BINFO_VTABLE and + BINFO_VIRTUALS as early as we can, so that modify_all_vtables can + work. + * class.c (finish_vtbls): New routine, mostly from + unmark_finished_struct. + * class.c (overrides): New routine. + * class.c (modify_one_vtable): New routine, mostly from + modify_other_vtable_entries and modify_vtable_entries. + * class.c (modify_all_direct_vtables, modify_all_indirect_vtables, + modify_all_vtables): New routines. + * class.c (finish_struct): Added arguemnt to prepare_fresh_vtable + call. General cleanup on how pending_hard_virtuals are handled. + General cleanup on modifying vtables. Use finish_vtbls, instead of + unmark_finished_struct. + * cp-tree.h (init_vtbl_ptrs, expand_direct_vtbls_init, + get_first_matching_virtual, get_matching_virtual, + expand_vbase_vtables_init, expand_indirect_vtbls_init): Update. + * cvt.c (convert_pointer_to_real): cleanup error message. + * decl.c (grokfndecl): General cleanup. + * decl.c (finish_function): Change init_vtbl_ptrs call to + expand_direct_vtbls_init. Change expand_vbase_vtables_init call to + expand_indirect_vtbls_init. + * init.c (expand_virtual_init): Remove unneeded argument. + * init.c (init_vtbl_ptrs): Rename to expand_direct_vtbls_init, added + two arguments to make more general. Made more general. Now can be + used for vtable pointer initialization from virtual bases. + * init.c (emit_base_init): Change expand_vbase_vtables_init call to + expand_indirect_vtbls_init. Change init_vtbl_ptrs call to + expand_direct_vtbls_init. + * init.c (expand_virtual_init): General cleanup. + * init.c (expand_default_init): Change expand_vbase_vtables_init + call to expand_indirect_vtbls_init. + * init.c (expand_recursive_init_1): Change expand_vbase_vtables_init + call to expand_indirect_vtbls_init. + * init.c (expand_recursive_init): Change expand_vbase_vtables_init + call to expand_indirect_vtbls_init. + * search.c (get_first_matching_virtual): Rename to + get_matching_virtual. General cleanup and remove setting of + DECL_CONTEXT. That is now done in a cleaner way in + modify_vtable_entry and add_virtual_function. + * search.c (expand_vbase_vtables_init): Rename to + expand_indirect_vtbls_init. General cleanup. Use + expand_direct_vtbls_init to do hard work. Ensures that _all_ vtable + pointers from virtual bases are set up. + * search.c (bfs_unmark_finished_struct, unmark_finished_struct): + Removed. + + * *.[chy]: Remove support for VTABLE_USES_MASK. + +Tue Apr 19 12:51:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): Use NOP_EXPRs to switch between + reference and pointer types instead of bashing the types directly. + + * call.c (build_overload_call_real): Use the TREE_CODE to determine + whether the function is overloaded or not, rather than + TREE_OVERLOADED. + * *: Remove all uses of TREE_OVERLOADED. + + * decl.c (grokdeclarator): Only complain about initializing const + fields when -ansi or -pedantic. + +Tue Apr 19 12:42:42 1994 Doug Evans (dje@canuck.cygnus.com) + + * cp-tree.h (THUNK_DELTA): frame_size is now a union. + +Mon Apr 18 00:17:13 1994 Jason Merrill (jason@deneb.cygnus.com) + + Do overloading on a block-by-block basis, not function-by-function. + * decl.c: Lose overloads_to_forget. + (struct binding_level): Add overloads_shadowed field. + (poplevel): Restore overloads_shadowed. + (push_overloaded_decl): Use overloads_shadowed instead of + overloads_to_forget. + (finish_function): Don't look at overloads_to_forget. + + Copy enum_overflow logic from c-decl.c. + * decl.c (start_enum): Initialize enum_overflow. + (build_enumerator): Use enum_overflow. Also use current_scope(). + + * search.c (current_scope): Move Brendan's comment from + build_enumerator here. + + * typeck.c (convert_for_assignment): Change warnings to pedwarns for + discarding const/volatile. + +Sat Apr 16 01:18:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (comp_target_parms): Accept TEMPLATE_TYPE_PARMs on the rhs. + (comp_target_types): Ditto. + + * decl.c (lookup_name): Don't unset got_scope here. + + * spew.c (yylex): Only replace yylval with the TYPE_NESTED_NAME if + got_scope != NULL_TREE. + +Fri Apr 15 16:36:33 1994 Jason Merrill (jason@deneb.cygnus.com) + + Horrible kludge to prevent templates from being instantiated by + their base classes. + * parse.y (template_instantiate_once): Unset TYPE_BEING_DEFINED + before we get to left_curly. + * pt.c (instantiate_class_template): Set TYPE_BEING_DEFINED. + + * error.c (dump_decl): If it's a typedef, print out the name of the + decl, not just the underlying type. + + * decl.c (pushdecl): If the old duplicate decl was a TYPE_DECL, + update the IDENTIFIER_TYPE_VALUE of its name. + + * decl2.c (finish_file): When processing the initializer for a + static member, pretend that the dummy function is a member of the + same class. + +Fri Apr 15 15:56:35 1994 Kung Hsu (kung@mexican.cygnus.com) + + * class.c (build_vtable_entry): revert Apr 4 change. + * decl2.c (mark_vtable_entries): replace pure virtual function + decl with abort's. + +Fri Apr 15 13:49:33 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_conditional_expr): Pedwarn on pointer/integer + mismatch, and don't pedwarn on 0/function pointer mismatch. + + * typeck2.c (digest_init): Lose code for special handling of unions. + (process_init_constructor): Since they're handled just fine here. + Pedwarn on excess elements. + + * decl2.c (grokfield): Complain about local class method declaration + without definition. + +Fri Apr 15 13:19:40 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * method.c (emit_thunk): Add extern declaration for + current_call_is_indirect (needed for hppa). + +Thu Apr 14 16:12:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + Improve local class support; allow classes in different blocks to + have the same name. + * decl.c (pushtag): Support local classes better. + (pushdecl_nonclass_level): New function for pushing mangled decls of + nested types into the appropriate scope. + (xref_defn_tag): Use pushdecl_nonclass_level instead of + pushdecl_top_level. + (grokfndecl): Don't mess with IDENTIFIER_GLOBAL_VALUE for local + class methods. + * method.c (do_inline_function_hair): Ditto. + + * class.c (finish_struct): It is legal for a class with no + constructors to have nonstatic const and reference members. + +Thu Apr 14 07:15:11 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * decl.c (push_overloaded_decl): Avoid giving errors about + built-ins, since duplicate_decls will have given warnings/errors + for them. + +Thu Apr 14 03:45:12 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): Warn about casting pointer type to + reference type when this is probably not what they wanted. + +Wed Apr 13 13:12:35 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (finish_decl): Don't mindlessly set TREE_USED for + static consts any more (toplev.c has now been modified to + not emit warnings if they are unused). + +Wed Apr 13 00:22:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_op_properties): If op new/delete get here with + METHOD_TYPEs, do a revert_static_member_fn. + + * cp-tree.h (IDENTIFIER_CLASS_TYPE_VALUE): Lose. + * init.c (is_aggr_typedef): Don't look at + IDENTIFIER_CLASS_TYPE_VALUE. + (get_aggr_from_typedef): Ditto. + (get_type_value): Ditto. + * call.c (build_scoped_method_call): Don't rely on overloaded + template names having IDENTIFIER_CLASS_VALUE set. + + * parse.y (component_decl_1, fn.def2): Revert rules for + constructors. + (component_decl_1, fn.def2): Use $1 instead of $$, since $$ is being + clobbered. + + * decl.c (start_function): Only warn about `void main()' if pedantic + || warn_return_type. + +Tue Apr 12 02:14:17 1994 Jason Merrill (jason@deneb.cygnus.com) + + Clean up overloading of the template name. + * class.c (pushclass): overload the template name whenever pushing + into the scope of a template class, not just if it is + uninstantiated. + (popclass): Correspondingly. + * search.c (push_class_decls): Don't overload_template_name. + * pt.c (overload_template_name): Don't set IDENTIFIER_LOCAL_VALUE or + DECL_CONTEXT on things. + * parse.y (left_curly): Don't overload_template_name. + * class.c (finish_struct): Don't undo_template_name_overload. + + * method.c (build_opfncall): Only pass one argument to global op + delete. + + * call.c (build_method_call): Use TYPE_VEC_DELETE_TAKES_SIZE to + decide how many arguments to use for vec delete. + + * decl.c (grok_op_properties): Be consistent in modifying + current_class_type. + (grokdeclarator): Only complain about function decls with no return + type if we're being pedantic. + +Mon Apr 11 00:10:53 1994 Jason Merrill (jason@deneb.cygnus.com) + + Add support for operator new [] and operator delete []. + + * tree.def: Add VEC_NEW_EXPR and VEC_DELETE_EXPR. + * ptree.c (print_lang_type): Indicate vec new/delete. + * parse.y: Support vec new/delete. + * method.c (build_decl_overload): Deal with vec new/delete. + (build_opfncall): Ditto. + * lex.c (init_lex): Set up values of ansi_opname and opname_tab for + vec new/delete. vec new uses "__vn", and vec delete uses "__vd". + * init.c (init_init_processing): Set up BIVN and BIVD. + (do_friend): Don't clean up after mistaken setting of TREE_GETS_NEW, + since it doesn't happen any more. + (build_new): Support vec new. Always call something. + (build_x_delete): Support vec delete. + (build_vec_delete): Lose dtor_dummy argument, add use_global_delete, + and pass it to build_x_delete. + * decl2.c (delete_sanity): Don't change behavior by whether or not + the type has a destructor. Pass use_global_delete to + build_vec_delete. + (coerce_delete_type): Make sure that the type returned has a first + argument of ptr_type_node. + * decl.c (init_decl_processing): Also declare the global vec + new/delete. + (grokdeclarator): Also force vec new/delete to be static. + (grok_op_properties): Note presence of vec new/delete, and play with + their args. If vec delete takes the optional size_t argument, set + TYPE_VEC_DELETE_TAKES_SIZE. + * cp-tree.h (TYPE_GETS_{REG,VEC}_DELETE): New macros to simplify + checking for one delete or the other. + (lang_type): gets_new and gets_delete are now two bits long. The + low bit is for the non-array version. Lose gets_placed_new. + (TYPE_VEC_DELETE_TAKES_SIZE): New macro indicating that the vec + delete defined by this class wants to know how much space it is + deleting. + (TYPE_VEC_NEW_USES_COOKIE): New macro to indicate when vec new must + add a header containing the number of elements in the vector; i.e. + when the elements need to be destroyed or vec delete wants to know + the size. + * class.c (finish_struct_methods): Also check for overloading vec + delete. + * call.c (build_method_call): Also delete second argument for vec + delete. + + * decl.c (grokdeclarator): Correct complaints again. + (grokdeclarator): Fix segfault on null declarator. + (decls_match): Also accept redeclaration with no arguments if both + declarations were in C context. Bash TREE_TYPE (newdecl) here. + (duplicate_decls): Instead of here. + + * parse.y (nested_name_specifier_1): Lose rules for dealing with + syntax errors nicely, since they break parsing of 'const i;'. + + * decl.c (lookup_name): if (got_scope == current_class_type) + val = IDENTIFIER_CLASS_VALUE (name). + + * search.c (lookup_nested_tag): Look in enclosing classes, too. + + * spew.c (yylex): Only look one character ahead when checking for a + SCOPE. + + * lex.c (check_newline): Read first nonwhite char before + incrementing lineno. + + * decl.c (grokdeclarator): Don't claim that typedefs are variables + in warning. + + * parse.y: Divide up uses of unqualified_id into + notype_unqualified_id and unqualified_id, so that TYPENAME can be + used as an identifier after an object. + + * class.c (push_nested_class): Don't push into non-class scope. + + * decl.c (grokdeclarator): If an identifier could be a type + conversion operator, but has no associated type, it's not a type + conversion operator. + + * pt.c (unify): Check for equality of constants better. + + * decl.c (grokdeclarator): Don't complain about access decls. + +Sun Apr 10 02:39:55 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): pedwarn about data definitions without + types here. + + * parse.y (datadef): Don't pedwarn about decls without types here, + since that is valid for functions. + (fn.def2, component_decl): Support constructors with declmods again. + (nomods_initdecls): For decls without any mods, so that we don't try + to get declspecs from some arbitrary $0. + + * search.c (lookup_field): Use cp_error. + + * parse.y (nested_name_specifier_1): Don't check aggr/non-aggr type + here; it breaks destructors for non-aggr types. + + * decl.c (lookup_name): Only look for TYPE_DECLs in base classes of + a type being defined, like the comment says. + If got_scope is not an aggregate, just return NULL_TREE. + + * pt.c (create_nested_upt): Kung's code for creating types nested + within uninstantiated templates now lives here (it used to live in + hack_more_ids). It needs to be expanded. + + * parse.y: Stop calling see_typename so much. + + * decl.c (lookup_name): Deal with TTPs and UPTs. + + * lex.c (real_yylex): Don't set looking_for_typename just because we + saw a 'new'. + (dont_see_typename): #if 0 out. + + * spew.c (yylex): Increment looking_for_typename if the next + character is SCOPE, rather than setting it to 1; this way, the value + from seeing an aggr specifier will not be lost. This kinda relies + on looking_for_typename never being < 0, which is now true. + + * parse.y (nested_name_specifier_1): Accept TEMPLATE_TYPE_PARMs, + too. + (named_class_head_sans_basetype): Accept template types, too. Oops. + +Fri Apr 8 16:39:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (reparse_decl_as_expr1): Handle SCOPE_REFs. + + * parse.y: Lose START_DECLARATOR. + + * search.c (lookup_nested_tag): New function to scan CLASSTYPE_TAGS + for a class. + + * parse.y: Simplify fn.def2 and component_decl. Support 'enum + A::foo' syntax. Catch invalid scopes better. + + * parse.y, lex.c: lose TYPENAME_COLON. + + * decl2.c (groktypefield): #if 0 out. + + * decl.c (lookup_name): If the type denoted by got_scope is + currently being defined, look in CLASSTYPE_TAGS rather than FIELDS. + + * class.c (push_nested_class): Don't try to push into + error_mark_node. + +Fri Apr 8 07:26:36 1994 Brendan Kehoe (brendan@lisa.cygnus.com) + + * Makefile.in (stamp-parse): Update count of conflicts to 33. + +Thu Apr 7 17:47:53 1994 Jason Merrill (jason@deneb.cygnus.com) + + A saner implementation of nested types that treats template types + no differently from non-template types. There are still some + shortcomings of our system; most notably, it is difficult to look + for a nested type that is hidden by another name, because of the way + we keep track of hidden types. But this shouldn't be a problem for + just about anyone. Perhaps lookup_field should be fixed up a bit. + + * spew.c: Moved handling of nested types/scoping from the lexer + into the parser. Removed variable template_type_seen_before_scope. + Removed functions frob_identifier, hack_more_ids, and various cruft + that was #if 0'd out in the past, reducing the size of the file from + 1146 lines to 450 lines. We can't quite do away with spew.c yet, + though; we still need it for do_aggr () and checking for SCOPE after + the current identifier. And setting lastiddecl. + + * parse.y: Moved handling of nested types/scoping from the lexer + into the parser, using a new global variable `got_scope'. Reduced + the number of states by 53. Implemented all uses of explicit global + scope. Removed terminals SCOPED_TYPENAME and SCOPED_NAME. Removed + nonterminals tmpl.1, scoped_base_class, id_scope, typename_scope, + scoped_typename. Added nonterminals nested_type, + qualified_type_name, complete_type_name, qualified_id, ptr_to_mem, + nested_name_specifier, global_scope, overqualified_id, type_name. + Changed many others. Added 9 new reduce/reduce conflicts, which are + nested type parallels of 9 that were already in the grammar for + non-nested types. Eight of the now 33 conflicts should be removed + in the process of resolving the late binding between variable and + function decls. + + * gxxint.texi (Parser): Update. + + * cp-tree.h (IS_AGGR_TYPE_CODE): Add UNINSTANTIATED_P_TYPE. + + * lex.h: Add decl for got_scope. + + * lex.c (see_typename): Claim to be the lexer when calling + lookup_name. + + * decl.c (lookup_name): When called from the lexer, look at + got_scope and looking_at_typename; otherwise don't. + +Thu Apr 7 22:05:47 1994 Mike Stump + + 31th Cygnus<->FSF merge. + +Thu Apr 7 17:47:53 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (mark_vtable_entries): Call this to mark all the + entries in the vtable addressable. + (finish_decl_parsing): Handle SCOPE_REFs. + + * decl.c (decls_match): Always call compparms with strict == 1. + Handle the special case of C function redecl here. + (duplicate_decls): Only keep the old type if the new decl takes no + arguments. + + * typeck.c (compparms): Also allow t1 to be ... if strict == 0. + +Thu Apr 7 16:17:50 1994 Mike Stump + + * class.c (build_vtable_entry): Fix breakage introduced Apr 5 + 17:48:41. + +Wed Apr 6 16:05:10 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * init.c (build_virtual_init), search.c (build_vbase_vtables_init), + ch-tree.h: Every place these functions were called, the result was + immediately passed to expand_expr_stmt. Reduce redundancy by + calling expand_expr_init *inside* these functions. These + makes for a simpler interface, and we don't have to build + compound expressions. Hence, rename these function to: + expand_virtual_init and expand_vbase_vtables_init respectively. + * init.c, decl.c: Change callers of these functions. + * init.c, cp-tree.h (expand_virtual_init): Make static. + + * decl2.c (finish_file): Check TREE_PUBLIC||TREE_ADDRESSABLE + rather than DECL_SAVED_INSNS before emitting inlines. + +Wed Apr 6 13:06:39 1994 Jason Merrill (jason@deneb.cygnus.com) + + * spew.c (init_spew): #if 0 out stuff used by arbitrate_lookup. + + * decl.c (duplicate_decls): If this is a new declaration of an + extern "C" function, keep the type (for the argtypes). + (redeclaration_error_message): Don't check DECL_LANGUAGE here. + (decls_match): Call compparms with a value of strict dependent on + the value of strict_prototypes for DECL_LANGUAGE (oldecl). + + * typeck.c (compparms): ... is only equivalent to non-promoting + parms if we're not being strict. + + * parse.y (empty_parms): Don't check flag_ansi || pedantic here. + + * decl.c (init_decl_processing): if (flag_ansi || pedantic) + strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; + + * decl2.c (grok_function_init): Don't set DECL_INITIAL on pure + virtuals. + +Tue Apr 5 17:48:41 1994 Per Bothner (bothner@kalessin.cygnus.com) + + Support for implementing vtables with thunks. + * tree.def (THUNK_DECL): New TREE_CODE. + * cp-tree.h (FNADDR_FROM_VTABLE_ENTRY), tree.c + (fnaddr_from_vtable_entry): Handle flag_vtable_thunks case. + * cp-tree.h (memptr_type): New variable. + * class.c (build_vtable_entry): Build thunk if necessary. + * class.c (build_vfn_ref): If using thunks, don't need + to add delta field from vtable (there is none!). + * decl.c: Add memptr_type as well as vtable_entry_type. + If using thunks, the latter is just ptr_type_node. + * gc.c, typeck.c: Use memptr_typeChange, not vtable_entry_type. + * decl2.c (finish_vtable_vardecl): Handle thunks. + * expr.c (cplus_expand_expr): Support THUNK_DECL. + + * decl.c (grokdeclarator): Set DECL_THIS_EXTERN if "extern". + * decl.c (start_function): Set current_extern_inline based on + DECL_THIS_EXTERN, not TREE_PUBLIC. + * decl.c (finish_function): Call mark_inline_for_output if needed, + + Improve intelligence about when to emit inlines. + * cp-tree.h (lang_decl_flags): New field saved_inline. + * cp-tree.h (DECL_SAVED_INLINE): New macro. + * class.c (add_virtual_function): Don't set TREE_ADDRESSABLE. + * decl.h, decl.c (pending_addressable_inlines): Removed. + * decl2.c (pending_addressable_inlines): Renamed to saved_inlines. + * decl2.c (mark_inline_for_output): Do nothing if + DECL_SAVED_INLINE; otherwise set it (and add to saved_inlines list). + * decl2.c (finish_vtable_vardecl): SET_CLASSTYPE_INTERFACE_KNOWN + and set CLASSTYPE_INTERFACE_ONLY if there is a non-inline virtual. + * decl2.c (finish_file): Writing out inlines later, so we can + also handle the ones needed for vtbales. + * decl2.c (write_vtable_entries, finish_vtable_typedecl): Removed. + + * cp-tree.h, class.c, decl2.c, search.c: Remove -fvtable-hack + and flag_vtable_hack. Use -fvtable-thunks and flag_vtable_thunks + instead. (The rationale is that these optimizations both break binary + compatibility, but should become the default in a future release.) + +Wed Apr 6 10:53:56 1994 Mike Stump + + * class.c (modify_vtable_entries): Never reset the DECL_CONTEXT + of a fndecl, as we might not be from that vfield. + +Tue Apr 5 17:43:35 1994 Kung Hsu (kung@mexican.cygnus.com) + + * class.c (add_virtual_function): fix bug for pure virtual, so + that DECL_VINDEX of the dummy decl copied won't be error. + (see also Apr 4 change) + +Tue Apr 5 17:23:45 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * typeck.c (c_expand_return): Before checking that we're not + returning the address of a local, make sure it's a VAR_DECL. + (And don't worry about it being a TREE_LIST.) + +Tue Apr 5 13:26:42 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (YYDEBUG): Always define. + * lex.c (YYDEBUG): Ditto. + +Mon Apr 4 11:28:17 1994 Kung Hsu (kung@mexican.cygnus.com) + + * class.c (finish_struct): backup out the change below, put the + new change for the same purpose. The change below breaks code. + + * class.c (finish_struct): if pure virtual, copy node and make + RTL point to abort, then put in virtual table. + * decl2.c (grok_function_iit): reinstate Mar 31 change. + +Sat Apr 2 03:12:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_new): pedwarn about newing const and volatile + types. + + * tree.c (get_identifier_list): Only do the special handling + thing if we're dealing with the main variant of the record type. + + * cvt.c (convert_to_reference): When converting between + compatible reference types, use the pointer conversion machinery. + Don't just blindly overwrite the old type. + +Fri Apr 1 17:14:42 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): When looking at global functions, + be sure to use instance_ptr for the first argument, not some version + of it that has been cast to a base class. Also do this before + comparing candidates. + +Thu Mar 31 19:50:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Constructors can be called for + const objects. + +Thu Mar 31 16:20:16 1994 Kung Hsu (kung@mexican.cygnus.com) + + * decl2.c (grok_func_init): do not abort as rtl for pur virtual + fucntions. They can be defined somewhere else. + +Sat Jan 23 23:23:26 1994 Stephen R. van den Berg (berg@pool.informatik.rwth-aachen.de) + + * decl.c (init_decl_processing): Declare __builtin_return_address + and __builtin_frame_address for C++ as well. + +Thu Mar 31 12:35:49 1994 Mike Stump + + * typeck2.c (store_init_value): Integral constant variables are + always constant, even when doing -fpic. + +Sat Jan 23 23:23:26 1994 Stephen R. van den Berg (berg@pool.informatik.rwth-aachen.de) + + * decl.c (redeclaration_error_message): Pass the types to + comptypes. + +Wed Mar 30 21:29:25 1994 Mike Stump + + Cures incorrect errors about pure virtuals in a class, when they + have been overridden in a derived class. + + * search.c (get_abstract_virtuals): Reimplement. + * search.c (get_abstract_virtuals_1): New routine. + +Wed Mar 30 14:10:04 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (push_template_decls): Make the pushed level pseudo + global. + + * parse.y (extdefs): Don't pop everything if the current binding + level is pseudo_global. + + * decl.c (pop_everything): Stop on reaching a pseudo-global + binding level. + + * cp-tree.h (DECL_FUNCTION_MEMBER_P): Change to more reliable test. + + * decl.c (duplicate_decls): Only copy DECL_SOURCE_{FILE_LINE} if + the old decl actually had an initializer. + + * {various}: Clean up gcc -W complaints. + + * cp-tree.h (DECL_FUNCTION_MEMBER_P): Currently defined to be + (DECL_CONTEXT (NODE) != NULL_TREE). + + * parse.y (lang_extdef): Call pop_everything if necessary. + + * decl.c (pop_everything): New function for popping binding + levels left over after a syntax error. + (pushdecl): Use DECL_FUNCTION_MEMBER_P to decide whether or not + a function is a member. + +Wed Mar 30 14:20:50 1994 Mike Stump + + Cures calling a more base base class function, when a more derived + base class member should be called in some MI situations. + + * search.c (make_binfo): Use more the more specialized base + binfos from the binfo given as the second argument to make_binfo, + instead of the unspecialized ones from the TYPE_BINFO. + * class.c (finish_base_struct): Ditto, update callers. + * search.c (dfs_get_vbase_types): Ditto. + * tree.c (propagate_binfo_offsets, layout_vbasetypes): Ditto. + * decl.c (xref_tag): Use NULL_TREE instead of 0. + * lex.c (make_lang_type): Ditto. + +Wed Mar 30 14:10:04 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (pushdecl): If pushing a C-linkage function, only do a + push_overloaded_decl. + (duplicate_decls): Standard overloading does not shadow built-ins. + +Tue Mar 29 00:54:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (end_template_decl): Don't call push_overloaded_decl. + + * init.c (do_friend): Don't call push_overloaded_decl. + + * decl.c (pushdecl): Call push_overloaded_decl for functions and + function templates. + (duplicate_decls): functions and function templates are not + duplicates, but don't complain about calling this function to + compare them. + (push_overloaded_decl): Don't deal with linkage. Call + duplicate_decls. + (redeclaration_error_message): Deal with linkage. + + * decl.c (start_function): If push_overloaded_decl returns an + older version of the function, deal with it. + + * decl.c (start_function): Be sure only to push_overloaded_decl + for non-members. + + * decl.c (grokfndecl): Put back clearing of DECL_CHAIN for + methods. + (start_function): Lose broken and redundant code for checking old + decl. + + * init.c (add_friend): Give line numbers of both friend decls + when warning about re-friending. + + * pt.c (tsubst): Use comptypes rather than == to compare the + types of the method as declared and as defined, since default + parameters may be different. + + * call.c (build_method_call): Use brendan's candidate printing + routine. + + * decl.c (start_method): Methods defined in the class body are + inline whether or not it's a template class. + +Mon Mar 28 16:39:26 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (initdcl0): Add "extern" to current_declspecs if + have_extern_spec && ! used_extern_spcec. + + * tree.c (really_overloaded_fn): A fn with more than one + overload. + + * pt.c (end_template_decl): Use really_overloaded_fn. + + * decl.c (duplicate_decls): When smashing a decl into a previous + definition, keep the old file and line. + Don't deal with overloaded functions. + Lose old code for checking arg types of functions. + Check for overloaded C functions. + (pushdecl): Deal with overloaded functions. + (start_decl): Expect pushdecl to return an appropriate function decl. + (start_function): Ditto. + (push_overloaded_decl): Don't check for overloaded C functions. + + * *.c: Stop using DECL_OVERLOADED, it being archaic. + TREE_OVERLOADED should probably go, too. + +Mon Mar 28 14:00:45 1994 Ron Guilmette (rfg@netcom.com) + + * typeck.c (comp_target_types): Call comp_target_parms with + strict == 1. + +Sun Mar 27 00:07:45 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (empty_parms): Don't parse () as (...) in extern "C" + sections if we're compiling with -ansi or -pedantic. + + * decl.c (decls_match): Don't treat (int) and (int&) as matching. + + * decl2.c (grokfield): Don't pedwarn twice about initializing + field. + + * decl.c (push_overloaded_decl): Warn about shadowing + constructor. + (redeclaration_error_message): Don't allow 'int a; int a;' + + * cvt.c (build_up_reference): Only check for valid upcast if + LOOKUP_PROTECT is set, not just any flag. + +Fri Mar 25 01:22:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (check_newline): When we see a #pragma implementation, + also set it for the main input file. + + * init.c (build_new): Convert array size argument to size_t. + + * parse.y (primary): If we're doing a parenthesized type-id, call + groktypename before passing it to build_new. + + * call.c (build_method_call): Deal properly with const and + volatile for instances of reference type. + + * decl.c (store_return_init): Change 'if (pedantic) error' to 'if + (pedantic) pedwarn'. + + * decl.c (grokdeclarator): Don't complain about putting `static' + and `inline' on template function decls. + +Thu Mar 24 23:18:19 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Preserve const & volatile on + `this'. + +Thu Mar 24 16:21:52 1994 Mike Stump + + * init.c (build_new, build_vec_delete): Use global new and delete + for arrays. + * decl2.c (delete_sanity): Ditto. + +Thu Mar 24 02:10:46 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): If i is an lvalue, + (int &)i -> *(int*)&i, as per 5.2.8p9 of the latest WP. + (convert_force): Call convert_to_reference with LOOKUP_COMPLAIN. + +Wed Mar 23 17:45:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (duplicate_decls): Also propagate DECL_TEMPLATE_MEMBERS + and DECL_TEMPLATE_INSTANTIATIONS. + + * init.c (build_new): Handle array typedefs properly. + +Wed Mar 23 18:23:33 1994 Mike Stump + + 30th Cygnus<->FSF merge. + +Wed Mar 23 00:46:24 1994 Mike Stump + + * class.c (modify_vtable_entries): Avoid running off the end of the + virtuals list when processing a virtual destructor. + * class.c (get_vtable_entry): Ditto. + +Wed Mar 23 00:23:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (duplicate_decls): If two template decls don't match, + just return 0. + +Tue Mar 22 23:49:41 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (convert_for_assignment): Don't pedwarn about + converting function pointer to void *. + +Tue Mar 22 22:23:19 1994 Mike Stump + + Major revamp of pointer to member functions. Cures major + nonfunctionality when used in casts, and MI situations. + + * cvt.c (convert_force): Update call site of build_ptrmemfunc. + * typeck.c (convert_for_assignment): Ditto. + * typeck2.c (digest_init): Ditto. + * typeck2.c (process_init_constructor): Simplify by moving code into + digest_init. + * typeck2.c (digest_init): Do default_conversions on init value, if + we are processing pointer to member functions. + * class.c (get_vfield_offset): Now non-static. Convert bit offset + into byte offset. + * cp-tree.h (get_vfield_offset): Ditto. + * typeck.c (get_member_function_from_ptrfunc): Convert down to right + instance, before fetching vtable pointer. + * typeck.c (get_delta_difference): New routine. + * typeck.c (build_ptrmemfunc): Revamp to handle casting better, also + get vtable pointer out of right subobject. + +Tue Mar 22 17:56:48 1994 Mike Stump + + * search.c (get_binfo): Return NULL instead of aborting, when + passed a UNION_TYPE. + +Tue Mar 22 12:44:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + These patches implement handling of redefinition/redeclaration of + templates. + + * typeck.c (comptypes): Simplify. All TEMPLATE_TYPE_PARMs are + considered compatible. + + * parse.y (template_def): Pass defn argument to end_template_decl. + + * pt.c (end_template_decl): Add defn argument. Check for + redefinition. Simplify. + + * error.c (OB_UNPUT): New macro, to remove mistakes. + (aggr_variety): Subroutine of dump_aggr_type. + + * decl.c (decls_match): Support templates. + (duplicate_decls): No longer static. Don't try to lay out template + decls. + (pushdecl): Simplify. + + * cp-tree.h (DECL_TEMPLATE_MEMBERS): Use DECL_SIZE instead of + DECL_INITIAL. + +Mon Mar 21 11:46:55 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_decl): Support class template decls. + (dump_type): Don't adorn template type parms. + + * decl.c (duplicate_decls): Save DECL_TEMPLATE_INFO from old decl + if it was a definition. + (redeclaration_error_message): Do the cp_error thang, and reject + redefinition of templates. + +Mon Mar 21 19:36:06 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (grokdeclarator): Set TREE_PUBLIC for METHOD_TYPE + in FIELD context, when appropriate. Also, + CLASSTYPE_INTERFACE_ONLY is irrelevant to setting TREE_PUBLIC. + Also, simplify check for bogus return specifiers. + +Mon Mar 21 11:46:55 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (after_type_declarator1): Expand type_quals. + (notype_declarator1): Ditto. + (absdcl1): Ditto. + +Sat Mar 19 01:05:17 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Treat class-local typedefs like static + members; i.e. 'typedef int f();' means that f is a function type, + not a method type. + + * parse.y (decl): Change direct_* back to *. + (type_id): Change direct_abstract_declarator to absdcl. + (direct_declarator, direct_initdecls, direct_initdcl0): Remove again. + +Fri Mar 18 12:47:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + These two patches fix crashes on instantiating a template inside a + function with C linkage or containing labels. + + * class.c (current_lang_stacksize): No longer static. + + * decl.c (struct saved_scope): Add lang_base, lang_stack, + lang_name, lang_stacksize, and named_labels. + (push_to_top_level): Save them. + (pop_from_top_level): Restore them. + + * gxxint.texi (Parser): Update. + + These two patches finish moving the task of expr/declarator + ambiguity resolution from the lexer to the parser, and add one more + r/r conflict. START_DECLARATOR can now be nuked. + + * parse.y (decl): Add "direct_" in typespec X rules. + (direct_declarator): New nonterminal for + direct_after_type_declarator and direct_notype_declarator. + (direct_initdecls): Like initdecls, but uses direct_initdcl0. + (direct_initdcl0): Like initdcl0, but uses direct_declarator. + (named_parm): Add typespec direct_declarator rule. + + * spew.c (yylex): #if 0 out START_DECLARATOR insertion. + + These two patches disable some excessive cleverness on the part of + g++; a non-class declaration always hides a class declaration in the + same scope, and g++ was trying to unhide it depending on the + enclosing expression. + + * spew.c (arbitrate_lookup): #if 0 out. + + * decl.c (lookup_name): Never call arbitrate_lookup. + + * parse.y (complex_notype_declarator1): Add '*' + complex_notype_declarator1 and '&' complex_notype_declarator1 rules. + + * parse.y (complex_direct_notype_declarator): Restore id_scope + see_typename TYPENAME rule, remove all other rules beginning with + those tokens. + (notype_unqualified_id): Add '~' see_typename IDENTIFIER rule. + +Thu Mar 17 17:30:01 1994 Jason Merrill (jason@deneb.cygnus.com) + + These changes fix the compiler's handling of the functional cast/ + object declaration ambiguities in section 6.8 of the ARM. They also + add 11 reduce/reduce conflicts. Sigh. + + * parse.y: Add precedence decls for OPERATOR and '~'. + (notype_unqualified_id): New nonterminal, encompasses all of the + ANSI unqualified-id nonterminal except TYPENAMEs. + (expr_or_declarator): New nonterminal to delay parsing of code like + `int (*a)'. + (primary): Use notype_unqualified_id. + (decl): Add typespec initdecls ';' and typespec declarator ';' + rules. + (initdcl0): Deal with the above. + (complex_notype_declarator1): A notype_declarator that is not also + an expr_or_declarator. + (complex_direct_notype_declarator): A direct_notype_declarator that + doesn't conflict with expr_or_declarator. Use + notype_unqualified_id. Remove id_scope see_typename TYPENAME rule. + (functional_cast): New nonterminal, for the three functional cast + rules. So that they can be moved after + complex_direct_notype_declarator. + (see_typename): Don't accept type_quals any more. + + * decl2.c (reparse_decl_as_expr): New function to deal with parse + nodes for code like `int (*a)++;'. + (reparse_decl_as_expr1): Recursive subroutine of the above. + (finish_decl_parsing): New function to deal with parse nodes for + code like `int (*a);'. See the difference? + +Thu Mar 17 12:16:10 1994 Mike Stump + + These changes break binary compatibility in code with classes + that use virtual bases. + + * search.c (dfs_get_vbase_types): Simplify and correct to make + sure virtual bases are initialized in dfs ordering. + * search.c (get_vbase_types): Simplify and make readable. + +Thu Mar 17 12:01:10 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y: s/ typename / type_id /g + +Wed Mar 16 17:42:52 1994 Kung Hsu (kung@mexican.cygnus.com) + + * parse.y (typespec): add SCOPE TYPENAME for global scoped + type. e.g. ::B x. + + * decl.c (complete_array_type): fix a bug that in -pendantic + mode even there's no initializer, it will continue to build + default index. + +Wed Mar 16 17:43:07 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (direct_notype_declarator): Add PTYPENAME rule, remove + all of the scoped PTYPENAME rules. + +Wed Mar 16 16:39:02 1994 Mike Stump + + * init.c (build_offset_ref): The value of A::typedef_name is + always the TYPE_DECL, and never an error. + +Tue Mar 15 20:02:35 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (get_base_distance_recursive): Two binfos can only + represent the same object if they are both via_virtual. + + * class.c (finish_base_struct): Check vbases for ambiguity, too. + + * search.c (get_vbase_types): Accept binfo argument, too. + +Tue Mar 15 19:22:05 1994 Kung Hsu (kung@mexican.cygnus.com) + + * decl.c (complete_array_type): complete TYPE_DOMAIN of the + initializer also, because back-end requires it. + +Tue Mar 15 15:33:31 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_expr): Support member functions (which show up as + OFFSET_REFs). + +Mon Mar 14 16:24:36 1994 Mike Stump + + * init.c (build_new): Set the return type of multidimensional + news correctly. + +Fri Mar 11 15:35:39 1994 Kung Hsu (kung@mexican.cygnus.com) + + * call.c (build_method_call): if basetype not equal to type + of the instance, use the type of the instance in building + destructor. + +Thu Mar 10 17:07:10 1994 Kung Hsu (kung@mexican.cygnus.com) + + * parse.y (direct_notype_declarator): add push_nested_type for + 'template_type SCOPED_NAME' rule. + +Tue Mar 8 00:19:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (parm): Add typed_declspec1 {absdcl, epsilon} rules. + +Sat Mar 5 04:47:48 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (regcast_or_absdcl): New nonterminal to implement late + reduction of constructs like `int ((int)(int)(int))'. + (cast_expr): Use it. + (sub_cast_expr): Everything that can come after a cast. + (typed_declspecs1): typed_declspecs that are not typed_typespecs. + (direct_after_type_declarator): Lose PAREN_STAR_PAREN rule. + (direct_abstract_declarator): Replace '(' parmlist ')' rule with + '(' complex_parmlist ')' and regcast_or_absdcl. + (parmlist): Split + (complex_parmlist): Parmlists that are not also typenames. + (parms_comma): Enabler. + (named_parm): A parm that is not also a typename. Use declarator + rather than dont_see_typename abs_or_notype_decl. Expand + typed_declspecs inline. + (abs_or_notype_decl): Lose. + (dont_see_typename): Comment out. + (bad_parm): Break out abs_or_notype_decl into two rules. + +Fri Mar 4 18:22:39 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl2.c (reparse_decl_as_casts): New function to change parse + nodes for `(int)(int)(int)' from "function taking int and returning + function taking int and returning function taking int" to "... cast + to int, cast to int, cast to int". + + * decl2.c (reparse_decl_as_expr): Recursive function to change + parse nodes for `A()()' from "function returning function returning + A" to "A().operator()". + + * parse.y (primary): Replace `typespec LEFT_RIGHT' rule with + `typespec fcast_or_absdcl' rule. + (fcast_or_absdcl): New nonterminal to implement late reduction of + constructs like `A()()()()'. + (typename): Replace `typespec absdcl1' rule with + `typespec direct_abstract_declarator' rule. + (direct_abstract_declarator): Replace `LEFT_RIGHT type_quals' rule + with `fcast_or_absdcl type_quals' rule. + +Fri Mar 4 16:18:03 1994 Mike Stump + + * tree.c (lvalue_p): Improve OFFSET_REF handling, so that it + matches Section 5.5. + +Fri Mar 4 14:01:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * error.c (dump_type_prefix): Don't print basetype twice for + pmfs. + +Fri Mar 4 13:24:33 1994 Mike Stump + + * typeck.c (convert_arguments): Handle setHandler(A::handlerFn) + so that it is like setHandler(&A::handlerFn). Cures an `invalid + lvalue in unary `&''. + +Fri Mar 4 11:15:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * gxxint.texi (Copying Objects): New section discussing default + op= problems with virtual inheritance. + + * decl2.c (grokoptypename): Just does grokdeclarator and + build_typename_overload, since the parser can't call grokdeclarator + directly. + + * method.c (build_typename_overload): Set IDENTIFIER_GLOBAL_VALUE + and TREE_TYPE on generated identifiers. + + * decl.c (grokdeclarator): Don't deal with TYPE_EXPRs anymore. + + * parse.y (parm): Convert `const char *' to `__opPCc' here. + + * error.c (dump_decl): Say sorry rather than my_friendly_aborting + if we can't figure out what to do. + (dump_type*): Ditto. + + * typeck2.c (build_m_component_ref): 'component' is an expr, not + a decl. Also move the IS_AGGR_TYPE check after the stripping of + REFERENCE_TYPE. + +Fri Mar 4 04:46:05 1994 Mike Stump + + * call.c (build_method_call): Handle b->setHandler(A::handlerFn) + so that it is like b->setHandler(&A::handlerFn). Cures an `invalid + lvalue in unary `&''. + +Thu Mar 3 12:38:15 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y: Add precedence specification for START_DECLARATOR. + (type_quals): Move before primary. + (typename): Move before typed_declspecs, add 'typespec absdcl1' rule. + + * decl2.c (grokoptypename): Lose. + + * decl.c (grokdeclarator): Parse TYPE_EXPRs in the initial scan, + rather than waiting until later. + +Wed Mar 2 14:12:23 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (unary_expr): Use 'typename' in 'new' rules, rather + than expanding it inline. + (typename): Expand empty option of (former) absdcl inline. + (abs_or_notype_decl): Ditto. + (absdcl): Lose empty rule. + (conversion_declarator): New nonterminal for 'typename' of 'operator + typename'. + (operator_name): Use it instead of absdcl. + + * parse.y: Add precedence declarations for SCOPED_TYPENAME, + TYPEOF, and SIGOF. + (typed_declspecs): Accept typed_typespecs, rather than typespec + directly. Add rules with reserved_typespecquals. + (reserved_declspecs): Don't accept typespecqual_reserved at the + beginning of the list. The typed_declspecs rule will deal with this + omission. + (declmods): Accept nonempty_type_quals, rather than TYPE_QUAL + directly. + + * parse.y (direct_notype_declarator, + direct_after_type_declarator, direct_abstract_declarator): Split up + the declarator1 nonterminals to match the draft standard and avoid + ambiguities. + (new_type_id, new_declarator, direct_new_declarator, + new_member_declarator): New nonterminals to implement the subset of + 'typename' allowed in new expressions. + (unary_expr): Use new_type_id instead of typename. + (after_type_declarator1, absdcl1): Fix semantics of member pointers. + (abs_member_declarator, after_type_member_declarator): Lose. + + * parse.y (absdcl1): Don't require parens around + abs_member_declarator. + (abs_member_declarator): Lose see_typename from rules. + (after_type_member_declarator): Ditto. + + * tree.c (get_identifier_list): New function, containing code + previously duplicated in get_decl_list and list_hash_lookup_or_cons. + (get_decl_list): Use it. + (list_hash_lookup_or_cons): Ditto. + + * parse.y (typed_declspecs, declmods): It's not necessary to hash + the declspecs on class_obstack, so don't. This way typed_typespecs + can reduce to typed_declspecs. + +Wed Mar 2 14:29:18 1994 Jason Merrill (jason@cygnus.com) + + * cvt.c (build_up_reference): If we aren't checking visibility, + also allow base->derived conversions. + +Mon Feb 28 15:14:29 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * typeck.c (build_c_cast): Remove bogus hack when converting + to a reference type. + + * cp-tree.h (lang_decl::vbase_init_list, DECL_VBASE_INIT_LIST): + Removed, not used. + (lang_stype::methods, lang_decl::next_method): New fields. + (CLASSTYPE_METHODS, DECL_NEXT_METHOD): New macros. + * decl.c (duplicate_decls): Preserve DECL_NEXT_METHOD. + + * cp-tree.h, decl2.c (flag_vtable_hack): New flag. + * decl2.c (finish_vtable_vardecl): If flag_vtable_hack, + and !CLASSTYPE_INTERFACE_KNOWN, try to use the presence of + a non-inline virtual function to control emitting of vtables. + * class.c (finish_struct): Build CLASSTYPE_METHODS list. + * search.c (build_vbase_vtables_init): Don't assemble_external + (yet) if flag_vtable_hack. + * class.c (build_vfn_ref): Ditto. + +Mon Feb 28 14:54:13 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (component_decl): Don't include "typed_declspecs + declarator ';'" speedup, since it breaks enums. + +Fri Feb 25 15:43:44 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * class.c (finish_struct): Minor optimization for building + fn_fields list. + +Fri Feb 25 15:23:42 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (start_function): Fix detection of function overloading. + +Thu Feb 24 22:26:19 1994 Mike Stump + + * lex.c (check_newline): #pragma interface can take a string + argument, just like #pragma implementation. #pragma implementation + checks for garbage on the line, line #pragma interface does. Main + input files do not auto implement like named files, #pragma + implementation must be used explicitly. + +Thu Feb 24 17:09:01 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y (components): Handle list of one again. + (notype_components): Ditto. + (after_type_declarator1): Take maybe_raises out again. + + * gxxint.texi (Parser): Document additional r/r conflict. + +Wed Feb 23 14:42:55 1994 Jason Merrill (jason@deneb.cygnus.com) + + * gxxint.texi (Parser): Add node. + + * Makefile.in (stamp-parse): Update expected conflict count. + + * parse.y (various): Replace "declmods declarator" with "declmods + notype_declarator". The comment saying that "declmods declarator ';'" + corresponds to "int i;" was wrong; it corresponds to "const i;". + (component_decl): Add "typed_declspecs declarator ';'" rule; this + *does* correspond to "int i;". Change "declmods components" to + "declmods notype_components". + (components): Don't deal with a list of one anymore. + (notype_components): New nonterminal, corresponds to notype_declarator. + ({after_,no}type_component_decl{,0}): More new nonterminals. + ({after_,no}type_declarator): Fold in START_DECLARATOR token. + Eliminates four reduce/reduce conflicts. + + (expr): Depend on nontrivial_exprlist instead of nonnull_exprlist. + (nontrivial_exprlist): New nonterminal: A list of at least two + expr_no_commas's. + (nonnull_exprlist): Depend on nontrival_exprlist. + Eliminates four reduce/reduce conflicts. + + (named_class_head): Move intermediate code block into separate + nonterminal so that we can stick %prec EMPTY on it. + + Add more %prec EMPTY's to eliminate remaining shift/reduce + conflicts. + + (after_type_declarator): Add maybe_raises to fndecl rules. + (after_type_declarator_no_typename): Remove. + For correctness. + + Document remaining reduce/reduce conflicts. + +Tue Feb 22 12:10:32 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (get_base_distance): Only bash BINFO_INHERITANCE_CHAIN + (TYPE_BINFO (type)) if we care about the path. + + * tree.c (lvalue_p): A COND_EXPR is an lvalue if both of the + options are. + +Mon Feb 21 19:59:40 1994 Mike Stump + + * Makefile.in (mostlyclean): lex.c is a source file, don't + remove. + +Sat Feb 19 01:27:14 1994 Jason Merrill (jason@deneb.cygnus.com) + + * parse.y: Eliminate 20 shift/reduce conflicts. + +Fri Feb 18 11:49:42 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (type_unification): Add subr argument; if set, it means + that we are calling ourselves recursively, so a partial match is OK. + (unify): Support pointers to methods and functions. + (tsubst): Support method pointers. + * decl.c (build_ptrmemfunc_type): No longer static, so that + tsubst can get at it. + + * init.c (is_aggr_typedef): Pretend template type parms are + aggregates. + * decl2.c (build_push_scope): If cname refers to a template type + parm, just grin and nod. + + * call.c (build_overload_call_real): Pass subr argument to + type_unification. + * pt.c (do_function_instantiation): Ditto. + * class.c (instantiate_type): Ditto. + + * search.c (get_base_distance): If BINFO is a binfo, use it and + don't mess with its BINFO_INHERITANCE_CHAIN. + + * cvt.c (convert_to_reference): Fix temporary generation. + If ambiguous, return error_mark_node. + + * init.c (build_new): Put back some necessary code. + +Thu Feb 17 15:39:47 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_new): Deal with array types properly. + + * search.c (get_binfo): Become a shell for get_base_distance. + (get_binfo_recursive): Lose. + (get_base_distance_recursive): Find the path to the via_virtual base + that provides the most access. + (get_base_distance): Ditto. + + * parse.y (explicit_instantiation): Syntax is 'template class + A', not 'template A'. + + * typeck.c (convert_for_initialization): Remove bogus warning. + + * parse.y (datadef): Revert patch of Oct 27. + +Thu Feb 17 15:12:29 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * class.c (build_vfn_ref): Cast delta field to ptrdiff_type_node, + rather than integer_type_node. Does wonders for the Alpha. + +Thu Feb 17 13:36:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (build_ptrmemfunc_type): Make sure that the pmf type + goes onto the same obstack as its target type. + +Wed Feb 16 00:34:46 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cvt.c (convert_to_reference): If converting via constructor + on local level, go back to build_cplus_new approach. + + * tree.c (build_cplus_new): If with_cleanup_p, set cleanup slot + to error_mark_node to prevent expand_expr from building a cleanup + for this variable. + + * lex.c (default_assign_ref_body): Return *this from the memcpy + version, too. + + * decl.c (grok_reference_init): Just return if called with + error_mark_node, don't worry about initializing non-const reference + with temporary. + + * cvt.c (convert_to_reference): Do the right thing for + non-aggregate reference conversions, pedwarn when generating a + non-const reference to a temporary. + + * class.c (finish_struct): TYPE_HAS_COMPLEX_{INIT,ASSIGN}_REF and + TYPE_NEEDS_CONSTRUCTING all depend on TYPE_USES_VIRTUAL_BASECLASSES + again. + +Tue Feb 15 19:47:19 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_reference_init): Pawn off a lot of the work on + convert_to_reference. Generally do the right thing. + + * cvt.c (convert_to_reference): Conform to the initial comment; + i.e. don't create temps if decl != error_mark_node. Handle + cleanups better for temps that do get created. Don't pretend + that we can use an 'A' to initialize a 'const double &' just by + tacking on a NOP_EXPR. Support LOOKUP_SPECULATIVELY. + + * call.c (build_method_call): Set TREE_HAS_CONSTRUCTOR on + constructor calls. + +Mon Feb 14 14:50:17 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grok_reference_init): Make a temporary for initializing + const reference from constant expression. + +Mon Feb 14 11:31:31 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * cp-tree.h, decl.c (set_identifier_local_value): Deleted function. + * decl.c (pushdecl): Define decl in correct binding_level + (which isn't always the inner_binding_level). + + * cvt.c (build_up_reference): Don't ever call expand_aggr_init. + It's ugly, and I don't think it's the right thing to do. + + * cp-tree.h, class.c, decl.c, decl2.c, sp/search.c: + Remove NEW_CLASS_SCOPING, assuming it is always 1. + * decl.c (pop_decl_level): Removed; manually inlined. + +Sun Feb 13 19:04:56 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.h (candidate): Add basetypes field. + + * call.c (build_method_call): Do access checking after choosing a + function, not before. + + * Makefile.in (cvt.o, call.o, method.o): Depend on class.h. + (mostlyclean): Remove ../cc1plus. + +Fri Feb 11 11:52:26 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Don't allow adjusting access to a field + of a base class if a local field has the same name. + + * error.c (dump_type_prefix): Output basetype for METHOD_TYPEs. + +hu Jan 13 17:55:51 EST 1994 Gnanasekaran Swaminathan (gs4t@virginia.edu) + + * cp-tree.h (DESTRUCTOR_NAME_P): do not confuse AUTO_TEMP names + with destructor names when either NO_DOLLAR_IN_LABEL or + NO_DOT_IN_LABEL are not defined. + + Now `template class A {...}' works. + + * pt.c (grok_template_type): substitute template parm types + with actual types in complex type as well. + (coerce_template_parms): update the grok_template_type () + function call. + + * pt.c (tsubst): Traverse method list using DECL_CHAIN. + + * decl.c (grok_op_properties): Allow operator++/-- to have + default arguments. + + * typeck2.c (store_init_value): Don't abort when called to + initialize a type that needs constructing with a CONSTRUCTOR. + + * init.c (expand_aggr_init_1, CONSTRUCTOR case): If + store_init_value fails, build and expand an INIT_EXPR. If + store_init_value succeeds, call expand_decl_init. + +Fri Feb 11 02:49:23 1994 Mike Stump + + * class.c (build_vbase_path): Use complete_type_p instead of + resolves_to_fixed_type_p to determine if the virtual bases are in + their right place for the type of expr. Cures problem of thinking a + virtual base class is one place, when it is in fact someplace else. + +Fri Feb 11 00:26:46 1994 Mike Stump + + * init.c (resolve_offset_ref): Make sure we first convert to + intermediate type, if given, when dealing with members off `this'. + Solves an incorrrect `type `foo' is not a base type for type + `multiple'' when it is infact, a base type. + +Thu Feb 10 21:49:35 1994 Mike Stump + + * class.c (modify_other_vtable_entries): Use get_binfo, instead + of binfo_value. Solves problem with compiler giving a `base class + `B' ambiguous in binfo_value (compiler error)' on complex MI + herarchies, when a virtual function is first defied in a virtual + base class. + +Thu Feb 10 17:19:32 1994 Mike Stump + + * class.c (build_vbase_path): Don't complain about ambiguous + intermediate conversion when converting down to a virtual base + class, even if they might seem to be ambiguous. + +Thu Feb 10 12:18:26 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck2.c (build_functional_cast): #if 0 out constructor + inheritance code, improve error messages. + + * class.c (finish_base_struct): Complain about base with only + non-default constructors in derived class with no constructors. + + * decl.c (grokdeclarator): Fix detection of virtual new/delete. + +Wed Feb 9 22:02:32 1994 Mike Stump + + * search.c (build_mi_virtuals, add_mi_virtuals, + report_ambiguous_mi_virtuals): Removed unneeded code. + * class.c (finish_struct_bits): Ditto. + +Wed Feb 9 11:27:17 1994 Jason Merrill (jason@deneb.cygnus.com) + + * pt.c (end_template_instantiation): Push decl before + pop_from_top_level. + + * typeck2.c (build_m_component_ref): Make sure datum is of + aggregate type. + + * init.c (get_type_value): New function, returns + IDENTIFIER_TYPE_VALUE or IDENTIFIER_CLASS_TYPE_VALUE or NULL_TREE. + + * call.c (build_method_call): Don't die on call to destructor for + non-type. + + * decl.c (grokdeclarator): Complain about virtual op new and op + delete, make static virtuals unvirtual instead of unstatic. + + * typeck.c (build_c_cast): Also call default_conversion on + methods. + + * decl.c (grokdeclarator): Don't complain about anonymous + bitfields. + + * parse.y (simple_stmt, for loops): Move the continue point after + the cleanups. + + * class.c (finish_struct): Fix setting of + TYPE_HAS_COMPLEX_INIT_REF. + +Tue Feb 8 13:21:40 1994 Jason Merrill (jason@deneb.cygnus.com) + + * init.c (build_new): Deal with `new double (1)'. + + * class.c (finish_struct): TYPE_HAS_COMPLEX_*_REF are supersets of + TYPE_HAS_REAL_*_REF, but TYPE_HAS_COMPLEX_INIT_REF is independent of + TYPE_NEEDS_CONSTRUCTING. + + * decl.c (duplicate_decls): Propagate access decls. + + * typeck2.c (process_init_constructor): Accept empty_init_node + for initializing unions. + + * class.c, lex.c, cp-tree.h: Use + TYPE_HAS_COMPLEX_ASSIGN_REF where TYPE_HAS_REAL_ASSIGN_REF was used + before, use TYPE_HAS_COMPLEX_INIT_REF for TYPE_NEEDS_CONSTRUCTING in + some places. + + * decl.c (finish_decl): Don't complain about uninitialized const + if it was initialized before. + +Mon Feb 7 18:12:34 1994 Jason Merrill (jason@deneb.cygnus.com) + + * lex.c (default_assign_ref_body): Don't deal with vbases for + now. + + * decl.c (finish_decl): Fix reversed logic for objects and other + things that need to be constructed but have no initializer. + + * class.c (finish_struct): Don't set TYPE_HAS_* flags that are + set by grok_op_properties or finish_decl. + + * decl.c: Don't warn about extern redeclared inline unless + -Wextern-inline is given. + * decl2.c (lang_decode_option): Ditto. + * cp-tree.h: Ditto. + +Mon Feb 7 17:29:24 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (pushdecl_with_scope): Fix thinko. Add forward + declaration. + + * decl.c (pushdecl_with_scope): New function. + * decl.c (pushdecl_top_level): Use new function. + * decl.c (pushtag): Initialize newdecl. + * decl.c (pushtag): Push new type decl into correct scope. + +Mon Feb 7 14:42:03 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c, cvt.c, init.c, search.c, cp-tree.h: + Eradicate LOOKUP_PROTECTED_OK. + +Mon Feb 7 13:57:19 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * decl.c (pushtag, xref_tag), cp-tree.h: Add extra parameter + 'globalize' to signify implicit declarations. + * decl.c (globalize_nested_type, maybe_globalize_type): Removed. + * decl.c (set_identifier_type_value_with_scope): New function. + * decl.c (set_identifier_local_value): Simplify. + * spew.c (yylex, do_addr): Modify to return a _DEFN if a + forward declaration (followed by ';' and not preceded by 'friend'). + * class.c, decl.c, except.c, init.c, parse.y, + pt.c, search.c: Add new argument to calls to xref_tag and + pushtag. + +Mon Feb 7 00:22:59 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.h (ACCESSIBLY_UNIQUELY_DERIVED_P): New macro, means what + ACCESSIBLY_DERIVED_FROM_P meant before. + (ACCESSIBLY_DERIVED_FROM_P): Now disregards ambiguity. + + * cvt.c (build_up_reference): Call get_binfo with PROTECT == 1. + + * search.c (get_base_distance_recursive): Members and friends of + a class X can implicitly convert an X* to a pointer to a private or + protected immediate base class of X. + (get_binfo_recursive): Ditto. + (get_base_distance): Ignore ambiguity if PROTECT < 0. + (get_binfo): Lose multiple values of PROTECT. + (compute_access): Protected is OK if the start of the + search is an accessible base class of current_class_type. + + * method.c (build_opfncall): Do check access on operator new here. + + * decl.c (finish_function): Don't check access on operator new + here. + +Sun Feb 6 14:06:58 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (xref_tag): The base of a derived struct is NOT always + public. Duh. + + * pt.c (do_explicit_instantiation): New function, called from + parser to do explicit function instantiation. + (type_unification): Allow the args list to be terminated with + void_list_node. + (do_pending_expansions): Look at i->interface for non-member + templates. + + * parse.y (datadef): Move explicit_instantiation here. + (structsp): From here. + (datadef): Complain about `int;'. + +Sun Feb 6 12:33:18 1994 Per Bothner (bothner@kalessin.cygnus.com) + + * pt.c (end_template_instantiation), cp-tree.h: Remove unused + second parameter, and simplify first from a TREE_LIST where + we only care about its TREE_VALUE to just the value (an IDENTIFIER). + * pt.c (instantiate_member_templates): Simplify argument list + from a TREE_LIST to just an IDENTIFIER. + * lex.c (yyprint): PRE_PARSED_CLASS_DECL is now just an IDENTIFIER. + * parse.y (template_instantiate_once): Simplify accordingly. + * decl.c (inner_binding_level): New. Use various places to + simplify. + +Sun Feb 6 02:49:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck2.c (build_functional_cast): int() -> int(0). + +Sat Feb 5 00:53:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Don't do a bitwise copy for op= if the + class has a virtual function table. + + * typeck.c (convert_for_initialization): Restore warnings about + not using defined op=. Should really be my_friendly_aborts, I + s'pose. + +Fri Feb 4 14:21:00 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Tidy up conditions for doing bitwise + copies of objects. + + * decl.c (build_default_constructor): #if 0 out. + + * *: Eradicate TYPE_GETS_{ASSIGNMENT,ASSIGN_REF,CONST_ASSIGN_REF, + CONST_INIT_REF}, TYPE_HAS_REAL_CONSTRUCTOR. + + * decl.c (grokdeclarator): Don't return void_type_node for + friends being defined here. + + * init.c (perform_member_init): Only do the init if it's useful. + + * lex.c (default_copy_constructor_body): If we don't need to do + memberwise init, just call __builtin_memcpy. + (default_assign_ref_body): Ditto. + + * decl.c (grokdeclarator): If friendp && virtualp, friendp = 0. + +Fri Feb 4 13:02:56 1994 Mike Stump + + * lex.c (reinit_parse_for_method, cons_up_default_function): + Don't give warn_if_unknown_interface warning when it came from a + system header file. + * pt.c (end_template_decl, instantiate_template): Ditto. + * decl.c (start_decl): Ditto. + +Fri Feb 4 00:41:21 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Don't try to set TYPE_WAS_ANONYMOUS on + enums. + + * decl2.c (constructor_name_full): Use IS_AGGR_TYPE_CODE instead of + IS_AGGR_TYPE, since we don't know it's a type. + +Thu Feb 3 11:36:46 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokdeclarator): Don't complain about anonymous unions. + + * cp-tree.h (TYPE_WAS_ANONYMOUS): This struct was originally + anonymous, but had a name given to it by a typedef. + + * decl.c (grokdeclarator): When renaming an anonymous struct, set + TYPE_WAS_ANONYMOUS. + + * decl2.c (constructor_name_full): Use TYPE_WAS_ANONYMOUS. + + * cp-tree.h (DECL_UNDEFINED_FRIENDS): #if 0 out. + + * init.c (xref_friend): Don't set up DECL_UNDEFINED_FRIENDS. + (embrace_waiting_friends): Don't use DECL_UNDEFINED_FRIENDS. + + * decl.c (grokdeclarator): Set TYPE_NESTED_NAME properly on nested + anonymous structs that get typedef'd. + + * decl.c (grokdeclarator): Always return void_type_node for + friends. + + * error.c (dump_function_decl): Don't use DECL_CLASS_CONTEXT for + friends. + (dump_function_decl): Don't print out default args for + a function used in an expression. + + * decl.c (grokdeclarator): Give error on abstract declarator used + in an invalid context (i.e. `void (*)();'). + + * error.c (cp_line_of): Support _TYPE nodes. + (cp_file_of): Ditto. + + * cvt.c (build_up_reference): Don't abort if passed a SAVE_EXPR; + it can happen for the RHS of an assignment stmt where the LHS is + a COND_EXPR. + + * init.c (expand_aggr_init_1): Deal with bracketed initializer + lists properly. + + * class.c (finish_struct): Deal with enumerators and typedefs + again. + +Wed Feb 2 11:30:22 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Tidy up loop over fields. + + * errfn.c (cp_thing): Don't advance twice after a format. + + * class.c (finish_struct): Complain about needing a constructor + if a member has only non-default constructors, and don't try to + generate a default constructor. + + * decl.c (finish_decl): Also do the constructor thing if + TYPE_NEEDS_CONSTRUCTING is set (for arrays). + + * search.c (unuse_fields): New function: mark all fields in this + type unused. + (dfs_unuse_fields): Helper function. + + * class.c (pushclass): If the new class is the same as the old + class, still unuse the fields. + (unuse_fields): Move to search.c. + + * decl.c (grok_op_properties): Add friendp argument. + (grokfndecl): Pass it. + (start_method): Ditto. + + * decl2.c (delete_sanity): Add use_global_delete parameter to catch + ::delete calls. + + * parse.y (unary_expr): Pass new parameter to delete_sanity. + + * lex.c (default_copy_constructor_body): Don't choke if the union + has no fields. + (default_assign_ref_body): Ditto. + + * call.c (compute_conversion_costs_ansi): Do the right thing for + ellipsis matches. + + * decl.c (push_to_top_level): Optimize. + + * decl.c (start_function): Look for the lexical scope of a friend + in DECL_CLASS_CONTEXT. + + * init.c (do_friend): Set DECL_CLASS_CONTEXT on global friends. + +Tue Feb 1 15:59:24 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.h (TREE_GETS_PLACED_NEW): New macro. + + * init.c (init_init_processing): Don't assign BIN/BID to the + IDENTIFIER_GLOBAL_VALUEs of their respective operators. + (build_new): Check TREE_GETS_PLACED_NEW. + + * decl.c (grok_op_properties): Don't set TREE_GETS_NEW for a decl of + op new with placement, set TREE_GETS_PLACED_NEW. + + * cp-tree.h (ANON_UNION_P): New macro. Applies to decls. + + * class.c (finish_struct): Don't treat anonymous unions like + other aggregate members. Do synthesize methods for unions without + a name, since they may or may not be "anonymous unions". + + * decl2.c (grok_x_components): Wipe out memory of synthesized methods + in anonymous unions. + + * lex.c (default_copy_constructor_body): Support unions. + (default_assign_ref_body): Ditto. + +Mon Jan 31 12:07:30 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.h: Fix documentation of LOOKUP_GLOBAL, add prototypes. + + * error.c (args_as_string): New function (%A), like type_as_string + except NULL_TREE -> "..." + + * call.c (build_overload_call_real): Fix for new overloading. + + * decl.c (grok_op_properties): Set all of the TYPE_OVERLOADS_* flags + here. + + * parse.y (operator_name): Instead of here. + + * typeck2.c (build_functional_cast): Treat a TREE_LIST as a list + of functions. + + * call.c (build_overload_call_real): Support LOOKUP_SPECULATIVELY. + + * method.c (build_opfncall): Don't need to massage return value + any more, call build_overload_call with all flags. + + * typeck.c (build_x_binary_op): Put back speculative call to + build_opfncall. + (build_x_unary_op): Ditto. + (build_x_conditional_expr): Ditto. + +Mon Jan 31 10:00:30 1994 Mike Stump + + * cvt.c (build_type_conversion_1): Change call to pedwarn into + warning, and conditionalize upon warn_cast_qual. + +Fri Jan 28 11:48:15 1994 Jason Merrill (jason@deneb.cygnus.com) + + * search.c (lookup_field): If xbasetype is a binfo, copy it to + avoid clobbering its inheritance info. + + * call.c (build_method_call): Don't overwrite basetype_path with + TYPE_BINFO (inst_ptr_basetype) if they have the same type. + + * search.c (compute_access): Fix handling of protected inheritance + and friendship with the enclosing class. + + * typeck2.c (store_init_value): Allow passing of TREE_CHAIN for + initialization of arbitrary variable. + + * typeck2.c (build_functional_cast): Only try calling a method if + one exists. + + * decl.c (grokdeclarator): Move handling of constructor syntax + initialization into first loop for generality. + (parmlist_is_random): Lose. + + * lex.c (cons_up_default_function): Set TREE_PARMLIST on arguments + to default function. + +Thu Jan 27 19:26:51 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (grokparms): Abort if we get called with something we don't + expect. + +Thu Jan 27 17:37:25 1994 Mike Stump + + * call.c (build_overload_call_real): Change argument complain to + flags to match style of rest of code. Pass it down to + build_function_call_real as necessary. + * call.c (build_overload_call, build_overload_call_maybe): Change + argument complain to flags to match style of rest of code. + * cp-tree.h (build_function_call_real): Added fourth flags + argument. + * cvt.c (convert_to_reference): Only give warning messages, if + LOOKUP_COMPLAIN is set. + * typeck.c (build_x_function_call): Change simple complain + argument to build_overload_call_maybe and build_overload_call, to + LOOKUP_COMPLAIN to match style of rest of code. + * typeck2.c (build_functional_cast): Ditto. + * typeck.c (build_function_call_real): Add flags, so that we can + not complain, if we don't want to complain. Complain about + arguments, if we are complaining, otherwise don't. + * typeck.c (build_function_call, build_function_call_maybe): + Stick in flags argument. + * typeck.c (build_x_binary_op, build_x_unary_op, + build_x_conditional_expr, build_x_compound_expr): Follow style of + build_x_indirect_ref, as it is more correct and more common. + +Thu Jan 27 14:36:20 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (build_method_call): Don't check for being called with + a pointer. + + * decl2.c (finish_file): Don't play with DECL_CLASS_CONTEXT for the + static initializer function. + + * init.c (build_member_call): Use convert_force here, too. + + * search.c (compute_access): Only treat static members specially + if they are referenced directly. + +Wed Jan 26 18:28:14 1994 Jason Merrill (jason@deneb.cygnus.com) + + * gxxint.texi (Access Control): New node. + + * search.c (current_scope): New function; returns whichever of + current_class_type and current_function_decl is the most nested. + (compute_access): Total overhaul to make it clearer and more + correct. Don't use the cache for now; in the only situation where + it was used before, it gained nothing. This frees up three of the + DECL_LANG_FLAGs for possible other use! + + * cp-tree.h: #if 0 out DECL_PUBLIC & friends. + + * typeck.c (build_component_ref_1): Don't check DECL_PUBLIC. + + * call.c (build_method_call): Use convert_force to cast `this' -- + rely on the access checking for the method itself. + + * init.c (is_friend): Do the nesting thing, handle types. I am + my own friend. + (is_friend_type): Become a shell for is_friend. + (add_friend): Never stick in ctype. + Why are the friendship functions in init.c, anyway? + +Wed Jan 26 17:50:00 1994 Mike Stump + + * cvt.c (build_type_conversion_1): Don't conditionalize call to + pedwarn upon pedantic. + +Wed Jan 26 17:20:46 1994 Mike Stump + + * cvt.c (convert_to_reference): Add 8.4.3 checking so that one + gets a warning if one tries to initialize a non-const & from a + non-lvalue. + * cvt.c (convert_to_reference): Use %P format for argument + numbers in warnings. + +Wed Jan 26 14:35:06 1994 Mike Stump + + * init.c (build_delete): Follow style in call.c to construct the + virtual call to the desctructor, as that code is right. Fixes a + problem of the compiler saying a pointer conversion is ambiguous. + +Wed Jan 26 11:28:14 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.h (VTABLE_NAME_P): Change other occurrence of + VTABLE_NAME_FORMAT to VTABLE_NAME. + + * *: s/visibility/access/g + +Tue Jan 25 18:39:12 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_modify_expr): Don't smash references if INIT_EXPR. + +Tue Jan 25 13:54:29 1994 Mike Stump + + * init.c (build_delete): Back out Jan 17th & 18th pacthes, as + they break libg++. + +Tue Jan 25 13:11:45 1994 Jason Merrill (jason@deneb.cygnus.com) + + * decl.c (duplicate_decls): Fix pointer arithmetic. + +Mon Jan 24 15:50:06 1994 Chip Salzenberg (chip@fin.uucp) + + [ cp-* changes propagated from c-* changes in 940114 snapshot ] + * cp-parse.y (maybe_attribute): Allow multiple __attribute__ + clauses on a declaration. + +Mon Jan 24 17:06:23 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Do synthesize methods for anon + structs, just not unions. + +Mon Jan 24 13:50:13 1994 Kung Hsu (kung@mexican.cygnus.com) + + * decl.c (xref_tag): handle anonymous nested type. + * decl.c (globalize_nested_type): add no globalize bit check. + * spew.c (hack_more_ids) : templated nested decl not push top + level. + + * parse.y : get rid of 'goto do_components'. It is much better + for debugging. + + * decl.c (is_anon_name): get rid of the function and use the + macro ANON_AGGRNAME_P. + * pt.c : ditto. + +Fri Jan 21 14:06:02 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct): Don't synthesize any methods for + anonymous structs/unions. + + * typeck.c (build_modify_expr): Don't treat pmf's as class objects. + +Thu Jan 20 18:56:46 1994 Jason Merrill (jason@deneb.cygnus.com) + + * method.c (build_opfncall): Call build_indirect_ref on + synthesized instance for operator delete. + + * pt.c (type_unification): Don't abort if called with a list of + types in ARGS. + + * class.c (instantiate_type): Deal with function templates. + +Thu Jan 20 16:55:35 1994 Jim Wilson (wilson@sphagnum.cygnus.com) + + * Makefile.in (CC): Default to cc not gcc. + +Thu Jan 20 13:47:54 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_modify_expr): Call constructor if appropriate. + + * decl.c (push_to_top_level): Clear out class-level bindings cache. + +Wed Jan 19 13:51:22 1994 Jason Merrill (jason@deneb.cygnus.com) + + * call.c (resolve_scope_to_name): Work recursively (previously only + looked down one level). + + * lex.c (do_pending_inlines): If we're still dealing with the last + batch of inlines, don't start working on a new one. + + * Makefile.in (stamp-parse): Update conflict count. + (TAGS): Fix. + + * parse.y (explicit_instantiation): New rule; implements + 'template A' syntax (though not 'template foo(int)' yet). + (structsp): Add explicit_instantiation. + +Tue Jan 18 13:53:05 1994 Jason Merrill (jason@deneb.cygnus.com) + + * class.c (finish_struct, etc.): Simplify decision to synthesize + a destructor. + + * call.c, class.c, cp-tree.h, decl.c, init.c, + ptree.c, search.c, typeck.c, typeck2.c: Nuke + TYPE_NEEDS_CONSTRUCTOR (change all calls to TYPE_NEEDS_CONSTRUCTING). + * init.c (expand_aggr_init_1): Don't try non-constructor methods + of initializing objects. + (build_new): Don't try other methods if the constructor lookup fails. + + * class.c (finish_base_struct): Set cant_have_default_ctor and + cant_synth_copy_ctor properly. + (finish_struct): Ditto. + +Mon Jan 17 13:58:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * typeck.c (build_modify_expr_1): #if 0 out again. + (build_modify_expr): #if 0 out memberwise init code again. + + * lex.c (default_copy_constructor_body): Be const-correct. + (default_assign_ref_body): Ditto. + + * init.c (perform_member_init): Use TYPE_HAS_CONSTRUCTOR to decide + whether or not to use it, rather than TYPE_NEEDS_CONSTRUCTING. + (expand_aggr_init): Disable silent conversion from initializer list + to list of args for a constructor. + + * class.c (base_info): Lose needs_default_ctor. + (finish_base_struct): Ditto. + (finish_struct): Ditto. + + * decl.c (init_decl_processing): Don't turn off flag_default_inline + just because flag_no_inline is on. + (finish_decl): Use TYPE_HAS_CONSTRUCTOR to decide to use + constructor. + + * class.c (finish_struct): Synthesize default ctor whenever + allowed. + + * Makefile.in (TAGS): Don't try to run etags on cp-parse.y. + +Sat Jan 15 18:34:33 1994 Mike Stump + + * Makefile.in, configure: Handle the C++ front-end in a + subdirectory. + * cp-*: Move C++ front-end to cp/*. + +Fri Jan 14 14:09:37 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-typeck.c (build_function_call_real): Modify to match other + instances of taking the address of the function. + + * cp-class.c (finish_struct): Set TYPE_HAS_REAL_CONSTRUCTOR to 1 if + there are non-synthesized constructors. + Only set TYPE_NEEDS_CONSTRUCTOR if TYPE_HAS_REAL_CONSTRUCTOR. + Always generate copy constructor if possible. + + * cp-tree.h (lang_type): Add has_real_constructor bitfield. + (TYPE_HAS_REAL_CONSTRUCTOR): Define. + + * cp-lex.c (default_copy_constructor_body): Use init syntax + for all bases. + + * cp-type2.c (store_init_value): Only give error for initializer list + if TYPE_HAS_REAL_CONSTRUCTOR. + +Thu Jan 13 15:38:29 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.h (DECL_SYNTHESIZED): Add defn. + (lang_decl): Add synthesized bitfield to decl_flags. + + * cp-lex.c (cons_up_default_function): Use DECL_SYNTHESIZED to mark + artificial methods, rather than a line # of 0. + +Fri Jan 14 18:25:29 1994 Kung Hsu (kung@mexican.cygnus.com) + + * cp-decl (xref_tag): fix a bug in conflict type. + * cp-parse.y : add SCOPED_NAME for uninstantiated template nested + type reference. + * cp-spew.c (yylex) : generated SCOPED_NAME token. + * cp-lex.c (yyprint): handle SCOPED_NAME. + +Fri Jan 14 17:00:29 1994 Mike Stump + + * cp-decl.c (pushdecl): Revert patch from Jan 11 19:33:03, as it is + not right. + +Thu Jan 13 14:00:35 1994 Kung Hsu (kung@mexican.cygnus.com) + + * cp-decl2.c (grok_x_components): fix a bug that enum type does not + have type_flags. + +Thu Jan 13 11:39:34 1994 Mike Stump + + Ensure that all vtable pointers are initialized with all the right + values. + + * cp-class.c (is_normal): Changed to reflect new meaning of + CLASSTYPE_VFIELD_PARENT. + * cp-class.c (maybe_fixup_vptrs): Use of + CLASSTYPE_NEEDS_VIRTUAL_REINIT here is misguided. Use + BINFO_MODIFIED instead. + * cp-class.c (finish_struct): Changed to reflect new meaning of + CLASSTYPE_VFIELD_PARENT. + * cp-decl.c (get_binfo_from_vfield): Removed, unneeded now. + * cp-decl.c (finish_function): Use init_vtbl_ptrs, instead of open + coding it here. + * cp-init.c (init_vfields): Changed name to init_vtbl_ptrs, and + re-implement. + * cp-init.c (emit_base_init): Use new name init_vtbl_ptrs. + * cp-tree.h (vfield_parent): Changed to integer. + * cp-tree.h (CLASSTYPE_VFIELD_PARENT): Changed docs to reflect new + meaning. + * cp-tree.h (init_vtbl_ptrs): Added init_vtbl_ptrs. + +Wed Jan 12 18:24:16 1994 Kung Hsu (kung@mexican.cygnus.com) + + * cp-decl.c (xref_tag): re-implement globalize nested type. + * cp-decl2.c (grok_x_components): ditto. + * cp-parse.y: ditto. + * cp-tree.h (lang_type): add no_globalize bit in type_flags. + +Wed Jan 12 14:08:09 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (grokdeclarator): Don't set TREE_PUBLIC on friend + decls with a definition attached. + + * cp-typeck.c (build_modify_expr): Undo previous change in the case + of INIT_EXPRs. + +Tue Jan 11 19:33:03 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-typeck.c (build_modify_expr): Replace code for generating + assignment semantics for classes with an error. + (build_modify_expr_1): #if 0 out. + + * cp-decl.c (pushdecl): Patch bogus design of pushdecl + behavior for overloaded functions (it doesn't push anything). + + * cp-class.c (finish_struct): When generating default op=, + set TYPE_HAS_ASSIGNMENT. + +Mon Jan 10 18:48:06 1994 Mike Stump + + * cp-cvt.c (convert): Make {double, clashing enum} -> enum + invalid. + * cp-typeck.c (convert_for_assignment): Simplify. + * cp-decl2.c (warn_enum_clash): Removed. + * invoke.texi (-Wenum-clash): Removed. + * toplev.c (-Wenum-clash): Removed. + +Mon Jan 10 17:48:37 1994 Kung Hsu (kung@mexican.cygnus.com) + + * cp-decl.c (finish_decl): fix incorrect popclass call. + + * cp-decl.c (is_anon_name): new function, check whether the name + is anonymous name generated by compiler. + * cp-decl.c (grokdeclarator): allow nested SCOPE_REF + * cp-spew.c (hack_more_ids): handle nested type in template. + * cp-parse.y : handle nested type reference in uninstantiated + template. + * cp-call.c (build_method_call): handle uninstantiated template + case. + * cp-pt.c (search_nested_type_in_tmpl): new function, search nested + type in template. + * cp-pt.c (lookup_nested_type_by_name): new function, lookup nested + type by name. + * cp-pt.c (tsubst): handle nested type search by name. + +Mon Jan 10 14:32:18 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-init.c (build_member_call): Propagate qualifiers to new type. + + * cp-call.c (build_method_call): Count functions the new way. + +Fri Jan 7 19:03:26 1994 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (pushtag): Set DECL_ASSEMBLER_NAME for nested classes, + too. + +Tue Jan 4 16:45:51 1994 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-parse.y: change to handle whether to globalize nested class. + * cp-decl.c(xref_tag, maybe_globalize_type): Ditto. + +Mon Jan 3 22:22:32 1994 Gerald Baumgartner (gb@cygnus.com) + + * Makefile.in cp-call.c cp-class.c cp-cvt.c cp-decl.c cp-decl2.c + cp-error.c cp-init.c cp-lex.c cp-lex.h cp-method.c cp-parse.y + cp-spew.c cp-tree.c cp-tree.h cp-type2.c cp-typeck.c cp-xref.c + gplus.gperf toplev.c: Incorporated C++ signature extension. + * cp-sig.c: New file, contains most of signature processing. + * cp-hash.h: Regenerated from gplus.gperf. + + * gcc.1 g++.1: Added explanation for the `-fhandle-signatures' + and `-fno-handle-signatures' command line flags. + + * gcc.texi: Changed the last-modification date. + * invoke.texi: Added `-fhandle-signatures' in the list of + C++ language options. Added explanation for this option. + +Tue Dec 28 21:10:03 1993 Mike Stump + + * cp-init.c (expand_vec_init): Remove comptypes test, as it is too + harsh here. + +Tue Dec 28 13:42:22 1993 Mike Stump + + * cp-pt.c (do_pending_expansions): Decide to expand a template + member function, based upon it's class type, not the class type of + the first place it was declared. + +Tue Dec 28 05:42:31 1993 Mike Stump + + * cp-class.c (is_normal): New routine, use to determine when the + given binfo is the normal one. (The one that should have the simple + vtable name.) + * cp-class.c (modify_other_vtable_entries): Use DECL_ASSEMBLER_NAME + to check if two fndecls are `the same'. Sometimes this routine can + modify the main vtable, and normal should be 1, in that case, so use + is_normal() to determine if this is the main vtable for the class. + Don't recurse down virtual bases, as they are shared, and we take + care of them elsewhere. + * cp-class.c (modify_vtable_entries): If we have already updated the + vtable with the new virtual, don't do it again. + * cp-class.c (finish_struct): Set CLASSTYPE_VFIELD_PARENT as + appropriate. Do virtual function overriding in virtual bases, after + normal overriding, so that the base function list in DECL_VINDEX is + not overridden, before we have a chance to run through the list. + Use DECL_ASSEMBLER_NAME to check if two fndecls are `the same'. + Make sure we pass the right address into modify_vtable_entries. + * cp-tree.h (CLASSTYPE_VFIELD_PARENT): New field to indicate which + binfo is the one that has the vtable that we based our vtable on. + +Fri Dec 24 09:40:52 1993 Michael Tiemann (tiemann@blues.cygnus.com) + + * cp-typeck.c (c_expand_start_case): Use default_conversion to + convert expression from reference type if necessary. + +Wed Dec 22 17:58:43 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-typeck.c (build_unary_op): Make sure that it's a TREE_LIST before + trying to read its TREE_VALUE. + + * cp-class.c (finish_struct_methods): Clear DECL_IN_AGGR_P here. + (finish_struct): Instead of here. + +Tue Dec 21 14:34:25 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-tree.c (list_hash_lookup_or_cons): Make sure the type doesn't + have TYPE_PTRMEMFUNC_P set before we try to build its + CLASSTYPE_ID_AS_LIST. + (get_decl_list): Likewise, when trying to read it. + + * cp-tree.h (VTABLE_NAME): No def with NO_{DOLLAR,DOT} defined. + (VTABLE_NAME_P): Use it instead of VTABLE_NAME_FORMAT. + +Mon Dec 20 13:35:03 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-typeck.c (rationalize_conditional_expr): New function. + (unary_complex_lvalue): Use it. + (build_modify_expr): Use it, since trying to do an ADDR_EXPR of it + with build_unary_op won't cut it. Don't wrap the COND_EXPR with a + SAVE_EXPR either. + + * cp-decl2.c (explicit_warn_return_type): Deleted variable. + (lang_decode_option): Set warn_return_type, not explicit_*, for + -Wreturn-type and -Wall. This is what rest_of_compilation uses to + decide if it should go into jump_optimize or not. + * cp-tree.h (explicit_warn_return_type): Deleted. + * cp-decl.c (grokdeclarator): Use warn_return_type, not explicit_*. + (finish_function): Also complain about no return in a non-void fn if + we're being pedantic (don't rely on use of -Wreturn-type). + +Fri Dec 17 15:45:46 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-decl.c (grokdeclarator): Forbid declaration of a function as + static if it's being done inside another function. + + * cp-search.c (compute_visibility): Check for friendship both ways. + +Fri Dec 17 14:28:25 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-cvt.c (build_default_binary_type_conversion): Make error + messages more helpful. + + * cp-error.c (op_as_string): New function, returns "operator ==" + given EQ_EXPR or suchlike. + +Fri Dec 17 13:28:11 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-call.c (print_n_candidates): New function. + (build_overload_call_real): Use it when we complain about a call + being ambiguous. + +Fri Dec 17 12:41:17 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-call.c (build_method_call): Fix checking for static call + context. + + * cp-method.c (build_opfncall): Call build_indirect_ref on argument + to operator new. + + * cp-init.c (build_new): Don't mess with rval when building + indirect ref. + +Thu Dec 16 16:48:05 1993 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-lex.c (default_assign_ref_body): add check when TYPE_NESTED_ + NAME(type) may not be exist. It's not a problem for old compiler. + +Thu Dec 16 14:46:06 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-tree.h (CLASSTYPE_ALTERS_VISIBILITIES_P): Delete macro, it's + never used for anything. + (struct lang_type, member type_flags): Delete field + `alters_visibility', and up `dummy' by 1. + * cp-class.c (finish_base_struct): Delete code that copies the + setting of CLASSTYPE_ALTERS_VISIBILITIES_P. + (finish_struct): Delete code that sets it. + +Thu Dec 16 14:44:39 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c, cp-init.c, cp-typeck.c: Fix arguments to + build_method_call that I messed up before. + + * cp-search.c (get_base_distance): If protect > 1, allow immediate + private base. + + * cp-class.c (finish_base_struct): Set cant_synth_* correctly. + (finish_struct): Ditto. Well, nigh-correctly; it won't deal + properly with the case where a class contains an object of an + ambiguous base class which has a protected op=. Should be fixed + when the access control code gets overhauled. + (finish_struct_methods): Set TYPE_HAS_NONPUBLIC_* correctly. + +Thu Dec 16 12:17:06 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-lex.c (real_yylex): Turn the code back on that deals with + __FUNCTION__ and __PRETTY_FUNCTION__. Don't use lookup_name, to + avoid the ambiguity problems that led to it being turned off in the + first place. + + * cp-method.c (hack_identifier): Also check for a TYPE_PTRMEMFUNC_P + to see if something is a method. + +Wed Dec 15 18:35:58 1993 Mike Stump + + * cp-typeck.c (build_modify_expr): Avoid error messages on small + enum bit fields. + * cp-typeck.c (convert_for_assignment): Add missing argument to + cp_warning and cp_pedwarn calls. + +Wed Dec 15 18:25:32 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-parse.y (member_init): ANSI C++ doesn't forbid old-style base + initializers; it's just anachronistic. + + * cp-decl.c (finish_decl): Don't require external-linkage arrays + to have a complete type at declaration time when pedantic. + +Tue Dec 14 11:37:23 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (pushdecl): Don't set DECL_CONTEXT if it's already set. + + * cp-call.c (build_method_call): Don't dereference pointer given + as instance. + + * cp-decl.c (finish_function): Don't pass pointer to + build_method_call. + (finish_function): Ditto. + + * cp-typeck.c (build_x_function_call): Ditto. + + * cp-method.c (build_component_type_expr): Ditto. + + * cp-init.c (build_member_call): Ditto. + (build_new): Ditto. + +Mon Dec 13 18:04:33 1993 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-decl.c (xref_tag): fix regression created by changes made + in Dec. 7 1993. + * cp-decl.c (xref_defn_tag): fix parallel nested class problem. + +Fri Dec 10 12:40:25 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-call.c (compute_conversion_costs_ansi) [DEBUG_MATCHING]: Print + out the final evaluation of the function, so we can see if ELLIPSIS, + USER, and EVIL were set at the end. + + * cp-call.c (convert_harshness_ansi): When the parm isn't an lvalue, + only go for setting TRIVIAL_CODE if we are dealing with types that + are compatible. + +Thu Dec 9 18:27:22 1993 Mike Stump + + * cp-decl.c (flag_huge_objects): New flag to allow large objects. + * toplev.c (lang_options): Ditto. + * cp-decl2.c (flag_huge_objects, lang_f_options): Ditto. + * cp-decl.c (delta_type_node): New type for delta entries. + * cp-tree.h (delta_type_node): Ditto. + * cp-decl.c (init_decl_processing): Setup delta_type_node. + * cp-decl.c (init_decl_processing, build_ptrmemfunc_type): Use + delta_type_node instead of short_integer_type_node. + * cp-class.c (build_vtable_entry): Ditto. + +Thu Dec 9 16:19:05 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-tree.h (OPERATOR_TYPENAME_P): Define outside of + NO_{DOLLAR,DOT} macro checks, so it always gets defined. + (VTABLE_NAME_P): Define for NO_DOT && NO_DOLLAR_IN_LABEL. + +Wed Dec 8 17:38:06 1993 Mike Stump + + * cp-decl.c (finish_decl): Make sure things that can go into + "common", do go into common, if -fcommon is given. + +Wed Dec 8 13:01:54 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-call.c (print_harshness) [DEBUG_MATCHING]: New function. + (compute_conversion_costs_ansi) [DEBUG_MATCHING]: Print out + argument matching diagnostics to make instantly clear what the + compiler is doing. + + * cp-call.c (convert_harshness_ansi): If the parm isn't an lvalue, + then check to see if the penalty was increased due to + signed/unsigned mismatch, and use a TRIVIAL_CODE if it wasn't. + +Tue Dec 7 18:29:14 1993 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-decl.c (xref_tag, pushtag): Fix nested class search/resolution + problem. + +Tue Dec 7 16:09:34 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-class.c (finish_struct): Before synthesizing methods, if no + methods have yet been declared then set nonprivate_method. Don't + set non_private method after synthesizing a method. + + * cp-lex.c (extract_interface_info): If flag_alt_external_templates + is set, tie emitted code to the location of template instantiation, + rather than definition. + + * cp-tree.h: Declare flag_alt_external_templates. + + * cp-decl2.c (lang_decode_option): Support -falt-external-templates. + + * toplev.c (lang_options): Ditto. + + Mon Oct 4 12:50:02 1993 Chip Salzenberg (chip@fin.uucp) + + [changes propagated from 930810 snapshot] + * cp-decl.c (init_decl_processing): Make long long available for use + as SIZE_TYPE and PTRDIFF_TYPE. + (finish_decl): Allow file-scope static incomplete array. + (grokdeclarator): Don't pass on const and volatile fron function + value type to function type. + Warn here for volatile fn returning non-void type. + * cp-parse.y (attrib): Accept attributes `volatile' with alias + `noreturn', and `const'. + * cp-typeck.c (default_conversion): Don't lose const and volatile. + (build_binary_op_nodefault): Generate pedantic warning for comparison + of complete pointer type with incomplete pointer type. + (build_c_cast): Be careful that null pointer constant be INTEGER_CST. + +Tue Dec 7 10:46:48 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-init.c (expand_vec_init): When creating a temporary for copying + arrays, use the type of the source, not the target. + + * cp-cvt.c (convert): Pass an argument for errtype to + convert_to_reference. + + * cp-error.c (dump_expr, COMPONENT_REF & CALL_EXPR): Deal with + methods, -> and `this'. + +Mon Dec 6 17:12:33 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-error.c (parm_as_string): New function; returns `this' or arg + number. Corresponds to %P. + (dump_expr): Deal with method calls. + + * cp-cvt.c (convert_to_reference): Stop using warn_for_assignment. + * cp-typeck.c (convert_for_assignment): Ditto. + (warn_for_assignment): Lose. + +Mon Dec 6 11:33:35 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-call.c (ideal_candidate_ansi): Delete code that was never + doing anything useful. Instead, sort once, and DO NOT wipe + out any codes with EVIL_CODE, since that's what we use as a + marker for the end of the list of candidates. + + * cp-cvt.c (convert_to_aggr): Make sure to always set H_LEN. + +Mon Dec 6 12:49:17 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-init.c (get_aggr_from_typedef): New function, like + is_aggr_typedef but returns the _TYPE. + + * cp-call.c, cp-init.c, cp-method.c: Eradicate err_name. + +Sun Dec 5 18:12:48 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-lex.c (readescape): Pedwarn when a hex escape is out of range. + +Thu Nov 25 23:50:19 1993 Chip Salzenberg (chip@fin.uucp) + + Delay language context change until beginning of next decl. + + * cp-lex.h (c_header_level): Removed. + (pending_lang_change): Declared. + * cp-lex.c (c_header_level): Renamed from in_c_header, made static. + (pending_lang_change): Defined. + (check_newline): Rework code that recognizes line number and + filename changes. Instead of pushing and popping lang context, + increment and decrement pending_lang_change. + (do_pending_lang_change): Push and pop lang context according + to value of pending_lang_change. + * cp-parse.y (extdefs): Use lang_extdef instead of extdef. + (extdef): Same as extdef, but call do_pending_lang_change() first. + +Mon Nov 15 15:39:15 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-typeck.c (build_binary_op_nodefault): Warn for ordered + compare of ptr with 0 only if pedantic in both cases. + +Thu Nov 25 13:31:37 1993 Chip Salzenberg (chip@fin.uucp) + + Reinstate the below patch, which got lost in the Cygnus merge: + Tue Nov 23 13:59:24 1993 Hallvard B Furuseth (hbf@durin.uio.no) + * cp-parse.y (maybe_type_qual): Don't fail to set $$. + +Wed Nov 17 19:03:30 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-parse.y (attrib): Allow "ident(ident)" like the C front end. + +Fri Oct 22 20:43:37 1993 Paul Eggert (eggert@twinsun.com) + + * cp-lex.c (real_yylex): Diagnose floating point constants + that are too large. + +Wed Nov 17 19:10:37 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-type2.c (build_functional_cast): ARM page 16: When a class + and an object, function or enumerator are declared in the same + scope with the same name, the class name is hidden. + +Wed Nov 17 19:07:18 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-call.c (convert_harshness_ansi): Distinguish float, double, + and long double from each other when overloading. + (compute_conversion_costs_{ansi,old}, build_method_call, + build_overlay_call_real, convert_to_aggr): Always set and + always use H_LEN member of candidate structure. + +Mon Oct 11 23:10:53 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-decl.c (duplicate_decls): Note redeclarations of library + functions, and generate distinct warnings for them. + +Mon Oct 4 12:26:49 1993 Chip Salzenberg (chip@fin.uucp) + + Support format warnings in G++. + + * cp-tree.h: Protect against multiple inclusion. + Declare all public functions in c-common.c (copy from c-tree.h). + (STDIO_PROTO): Define. + (warn_format): Declare. + (record_format_info): Remove declaration. + * cp-decl.c (init_decl_processing): Call init_function_format_info. + * cp-decl2.c (lang_decode_option): Make "-Wall" include warn_format. + * cp-typeck.c (build_function_call_real): Call check_function_format. + (record_format_info): Remove -- obsolete stub. + +Sat Jul 24 12:04:29 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-decl.c (duplicate_decls): Don't warn for non-extern var decl + following an extern one (for -Wredundant-decls). + * cp-parse.y (primary): In statement expression case, if compstmt + returns something other than a BLOCK, return it unchanged. + +Thu Dec 2 20:44:58 1993 Chip Salzenberg (chip@fin.uucp) + + * cp-decl.c (warn_extern_redeclared_static): New function made + from code extracted from pushdecl. + (duplicate_decls, pushdecl): Call new function. + (lookup_name_current_level): Allow for IDENTIFIER_GLOBAL_VALUE + to be a TREE_LIST when function is declared in 'extern "C" {}'. + +Fri Dec 3 16:01:10 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-class.c (duplicate_tag_error): Use cp_error. + (finish_base_struct): Check for ambiguity with direct base, and don't + generate op= or copy ctor if it exists. + +Fri Dec 3 15:32:34 1993 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-init.c (expand_member_init): when initializer name is null, + don't try to build it now because emit_base_init will handle it. + +Fri Dec 3 12:28:59 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-lex.c (init_lex): Initialize input_filename to "" for + code such as ExceptionHandler::operator=. + +Fri Dec 3 10:32:08 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (grokdeclarator): Don't try to print out dname when + complaining about arrays of references if decl_context==TYPENAME, + since it will be null. + + * cp-decl2.c: Default to flag_ansi_overloading. + +Thu Dec 2 18:05:56 1993 Kung Hsu (kung@cirdan.cygnus.com) + + * cp-call.c (build_method_call): use binfo from instance if it's + different from binfo (basetype_path) passed from above. + +Thu Dec 2 12:48:36 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + +Wed Nov 17 19:14:29 1993 Chip Salzenberg (chip@fin.uucp) + + cp-error.c (dump_expr): Use unsigned chars to output a + TREE_REAL_CST in hex. + +Thu Dec 2 11:05:48 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-class.c (finish_struct): Fix typo in setting + cant_synth_asn_ref. + + * cp-tree.h (TYPE_NESTED_NAME): New macro, does + DECL_NESTED_TYPENAME (TYPE_NAME (NODE)). + + * cp-lex.c (default_copy_constructor_body): Change + DECL_NAME (TYPE_NAME (btype)) to TYPE_NESTED_NAME (btype). + (default_assign_ref_body): Ditto. + (default_copy_constructor_body): Call operator= explicitly for + base classes that have no constructor. + +Thu Dec 2 10:47:15 1993 Michael Tiemann (tiemann@blues.cygnus.com) + + * cp-call.c (build_method_call): If the instance variable is + converted to error_mark_node when we're trying to convert it to the + base type of a method we're looking up, return error_mark_node. + +Thu Dec 2 10:41:16 1993 Torbjorn Granlund (tege@cygnus.com) + + * cp-typeck.c (build_binary_op_nodefault): In *_DIV_EXPR *_MOD_EXPR + cases, tests for unsigned operands by peeking inside a NOP_EXPR. + +Wed Dec 1 13:33:34 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-call.c (compute_conversion_costs_ansi): Use the size of struct + harshness_code, not the size of short, for clearing out the + ansi_harshness. + + * cp-call.c (print_candidates): New function. + (build_method_call): When we had some candidates, but didn't get a + usable match, don't report that we got an error with the first + candidate. Instead, say there were no matches, and list the + candidates with print_candidates. In the second pass, make sure we + clear out ever_seen, so we can accurately count the number of + functions that qualified. + +Wed Dec 1 09:53:59 1993 Torbjorn Granlund (tege@cygnus.com) + + * cp-typeck.c (build_binary_op_nodefault): Shorten for *_MOD_EXPR + only if op1 is known to be != -1. + (build_binary_op_nodefault): Handle *_DIV_EXPR likewise. + +Tue Nov 30 14:07:26 1993 Brendan Kehoe (brendan@lisa.cygnus.com) + + * cp-method.c (hack_identifier): If the field itself is private, and + not from a private base class, say so. + +Mon Nov 29 03:00:56 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (grokdeclarator): Always warn on initialization of + const member. + +Wed Nov 24 00:49:35 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-class.c (finish_struct): Set TYPE_GETS_CONST_* properly. + (finish_base_struct): Set cant_synth_asn_ref properly. + + * cp-lex.c (cons_up_default_function): Add section for operator=. + (default_assign_ref_body): New function, mostly cribbed from + default_copy_constructor_body. + + * cp-class.c (base_info): Add members cant_synth_copy_ctor, + cant_synth_asn_ref, no_const_asn_ref. + (finish_base_struct): Update no_const_asn_ref, note that you should + update cant_synth_*, propagate TYPE_GETS_ASSIGN_REF. + (finish_struct): Add decls for cant_synth_*, no_const_asn_ref, and + initialize them properly. Set no_const_asn_ref properly. Set + cant_synth_* in some of the situations where they should be set. + Propagate TYPE_GETS_ASSIGN_REF. Use cant_synth_copy_ctor. Add call + to cons_up_default_function for operator=. + +Tue Nov 23 20:24:58 1993 Mike Stump + + * cp-cvt.c (convert_force): Add code to perform casting of pointer + to member function types. + * cp-typeck.c (build_ptrmemfunc): Add FORCE parameter to indicate + when the conversion should be done, regardless. + * cp-tree.h (build_ptrmemfunc): Ditto. + * cp-type2.c (digest_init): Ditto. + * cp-typeck.c (convert_for_assignment): Ditto. + +Tue Nov 23 18:06:58 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-error.c (dump_expr): Do the right thing for variables of + reference type. + + * cp-decl.c (grok_op_properties): Set TYPE_HAS_ASSIGN_REF + and its kin properly. + (xref_tag): Propagate TYPE_GETS_ASSIGN_REF. + +Tue Nov 23 12:26:13 1993 Mike Stump + + * cp-method.c (build_opfncall): Don't count pointer to member + functions as aggregates here, as we don't want to look up methods in + them. The compiler would core dump if we did, as they don't have + normal names. + * cp-typeck.c (build_indirect_ref): Improve wording on error + message. + +Mon Nov 22 14:22:23 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c (grok_op_properties): Allow operator?: with pedwarn + (since it's supported in other compiler bits). + + * cp-method.c (report_type_mismatch): Use cp_error; ignore err_name + argument. + + * cp-error.c (dump_function_decl): Don't print return type for + constructors and destructors. + + * cp-cvt.c (cp_convert_to_pointer): Import code from + convert_to_pointer so we can return error_mark_node in the case of an + error, and to allow more meaningful error messages. + (build_type_conversion): Don't go through void* when trying + to convert to a pointer type. + + * cp-decl.c (grokfndecl): Move call to grok_op_properties back + after grokclassfn so that it's dealing with the right decl. + (grok_op_properties): Don't assert !methodp for op new and op delete. + + * cp-init.c (build_delete): Don't use TYPE_BUILT_IN (there are now + no uses of it in the compiler). + + * cp-call.c (build_scoped_method_call): Fix for destructors of simple + types. + (build_method_call): Ditto. + +Fri Nov 19 12:59:38 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.c (count_functions): Abstraction function. + + * cp-call.c (build_overload_call_real): Deal with new overloading + properly, remove dead code. + + * gcc.c (default_compilers): Generate and use .ii files in the + intermediate stage of compiling C++ source. + +Fri Nov 19 11:26:09 1993 Jim Wilson (wilson@sphagnum.cygnus.com) + + * cp-expr.c (cplus_expand_expr): Make call_target a valid memory + address before using it, so it can be later safely compared. + +Fri Nov 12 15:30:27 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-pt.c (tsubst): Deal with new overloading. + + * cp-typeck.c (fntype_p): is the arg function type? + (comp_target_parms): pedwarn on conversion from (anything) to (...). + (build_x_function_call): Deal with new overloading. + + * cp-tree.c (decl_list_length): Deal with new overloading. + (decl_value_member): Like value_member, but for DECL_CHAINs. + + * cp-decl.c (duplicate_decls): Deal with new overloading. + (start_decl): Ditto. + + * cp-class.c (instantiate_type): Deal with new overloading. + + * cp-call.c (convert_harshness_ansi): Deal with new overloading. + (convert_harshness_old): Deal with new overloading. + (build_overload_call_real): Ditto. + +Mon Nov 8 13:50:49 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-tree.c (get_unique_fn): New function; returns FUNCTION_DECL + if unambiguous, NULL_TREE otherwise. + (get_first_fn): Returns the first appropriate FUNCTION_DECL. + (is_overloaded_fn): Returns whether or not the passed tree is + a function or list of functions. + + * cp-init.c (init_init_processing): use `get_first_fn' to find + the FUNCTION_DEFN for new and delete. + + * cp-decl.c (push_overloaded_decl): Use new overloading strategy, cut + code size in half (I spit on special cases). + +Tue Sep 7 20:03:33 1993 Jason Merrill (jason@deneb.cygnus.com) + + * cp-decl.c: Allow references and template type parameters as well + +Local Variables: +eval: (auto-fill-mode) +left-margin: 8 +fill-column: 76 +End: diff --git a/contrib/gcc/cp/Make-lang.in b/contrib/gcc/cp/Make-lang.in new file mode 100644 index 00000000000..c9d0a39dde2 --- /dev/null +++ b/contrib/gcc/cp/Make-lang.in @@ -0,0 +1,197 @@ +# Top level makefile fragment for GNU C++. +# Copyright (C) 1994, 1995 Free Software Foundation, Inc. + +#This file is part of GNU CC. + +#GNU CC is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2, or (at your option) +#any later version. + +#GNU CC is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with GNU CC; see the file COPYING. If not, write to +#the Free Software Foundation, 59 Temple Place - Suite 330, +#Boston, MA 02111-1307, USA. + +# This file provides the language dependent support in the main Makefile. +# Each language makefile fragment must provide the following targets: +# +# foo.all.build, foo.all.cross, foo.start.encap, foo.rest.encap, +# foo.info, foo.dvi, +# foo.install-normal, foo.install-common, foo.install-info, foo.install-man, +# foo.uninstall, foo.distdir, +# foo.mostlyclean, foo.clean, foo.distclean, foo.extraclean, +# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4 +# +# where `foo' is the name of the language. +# +# It should also provide rules for: +# +# - making any compiler driver (eg: g++) +# - the compiler proper (eg: cc1plus) +# - define the names for selecting the language in LANGUAGES. + +# Extra flags to pass to recursive makes. +CXX_FLAGS_TO_PASS = \ + "CXX_FOR_BUILD=$(CXX_FOR_BUILD)" \ + "CXXFLAGS=$(CXXFLAGS)" \ + "CXX_FOR_TARGET=$(CXX_FOR_TARGET)" + +# Actual names to use when installing a native compiler. +CXX_INSTALL_NAME = `t='$(program_transform_name)'; echo c++ | sed $$t` +GXX_INSTALL_NAME = `t='$(program_transform_name)'; echo g++ | sed $$t` + +# Actual names to use when installing a cross-compiler. +CXX_CROSS_NAME = `t='$(program_transform_cross_name)'; echo c++ | sed $$t` +GXX_CROSS_NAME = `t='$(program_transform_cross_name)'; echo g++ | sed $$t` + +# The name to use for the demangler program. +DEMANGLER_PROG = c++filt + +# Define the names for selecting c++ in LANGUAGES. +# Note that it would be nice to move the dependency on g++ +# into the C++ rule, but that needs a little bit of work +# to do the right thing within all.cross. +C++ c++: cc1plus + +# Tell GNU make to ignore these if they exist. +.PHONY: C++ c++ + +# Create the compiler driver for g++. +g++: $(srcdir)/cp/g++.c $(CONFIG_H) $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $(srcdir)/cp/g++.c $(LIBS) + +# Create a version of the g++ driver which calls the cross-compiler. +g++-cross: $(srcdir)/cp/g++.c version.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ \ + -DGCC_NAME=\"$(GCC_CROSS_NAME)\" $(srcdir)/cp/g++.c version.o $(LIBS) + +cxxmain.o: cplus-dem.c demangle.h + rm -f cxxmain.c + ln -s $(srcdir)/cplus-dem.c cxxmain.c > /dev/null 2>&1 \ + || cp $(srcdir)/cplus-dem.c cxxmain.c + $(CC) -c -DMAIN $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ + -DVERSION=\"$(version)\" cxxmain.c + rm -f cxxmain.c + +$(DEMANGLER_PROG): cxxmain.o underscore.o getopt.o getopt1.o $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) $(LIBS) -o $@ \ + cxxmain.o underscore.o getopt.o getopt1.o + +CXX_SRCS = $(srcdir)/cp/call.c $(srcdir)/cp/decl2.c \ + $(srcdir)/cp/except.c $(srcdir)/cp/input.c $(srcdir)/cp/pt.c \ + $(srcdir)/cp/spew.c $(srcdir)/cp/xref.c $(srcdir)/cp/class.c \ + $(srcdir)/cp/edsel.c $(srcdir)/cp/expr.c $(srcdir)/cp/lex.c \ + $(srcdir)/cp/ptree.c $(srcdir)/cp/tree.c $(srcdir)/cp/cvt.c \ + $(srcdir)/cp/errfn.c $(srcdir)/cp/gc.c $(srcdir)/cp/method.c \ + $(srcdir)/cp/search.c $(srcdir)/cp/typeck.c $(srcdir)/cp/decl.c \ + $(srcdir)/cp/error.c $(srcdir)/cp/init.c $(srcdir)/cp/parse.y \ + $(srcdir)/cp/sig.c $(srcdir)/cp/typeck2.c $(srcdir)/cp/repo.c + +cc1plus: $(P) $(CXX_SRCS) $(LIBDEPS) stamp-objlist c-common.o c-pragma.o + cd cp; $(MAKE) $(FLAGS_TO_PASS) $(CXX_FLAGS_TO_PASS) ../cc1plus + +# Build hooks: + +c++.all.build: g++ $(DEMANGLER_PROG) +c++.all.cross: g++-cross $(DEMANGLER_PROG) +c++.start.encap: g++ +c++.rest.encap: $(DEMANGLER_PROG) + +c++.info: +c++.dvi: + +# Install hooks: +# cc1plus is installed elsewhere as part of $(COMPILERS). + +# Nothing to do here. +c++.install-normal: + +# Install the driver program as $(target)-g++ +# and also as either g++ (if native) or $(tooldir)/bin/g++. +c++.install-common: + -if [ -f cc1plus$(exeext) ] ; then \ + if [ -f g++-cross$(exeext) ] ; then \ + rm -f $(bindir)/$(GXX_CROSS_NAME)$(exeext); \ + $(INSTALL_PROGRAM) g++-cross$(exeext) $(bindir)/$(GXX_CROSS_NAME)$(exeext); \ + chmod a+x $(bindir)/$(GXX_CROSS_NAME)$(exeext); \ + rm -f $(bindir)/$(CXX_CROSS_NAME)$(exeext); \ + ln $(bindir)/$(GXX_CROSS_NAME)$(exeext) $(bindir)/$(CXX_CROSS_NAME)$(exeext) \ + > /dev/null 2>&1 \ + || cp $(bindir)/$(GXX_CROSS_NAME)$(exeext) $(bindir)/$(CXX_CROSS_NAME)$(exeext) ; \ + else \ + rm -f $(bindir)/$(GXX_INSTALL_NAME)$(exeext); \ + $(INSTALL_PROGRAM) g++$(exeext) $(bindir)/$(GXX_INSTALL_NAME)$(exeext); \ + chmod a+x $(bindir)/$(GXX_INSTALL_NAME)$(exeext); \ + rm -f $(bindir)/$(CXX_INSTALL_NAME)$(exeext); \ + ln $(bindir)/$(GXX_INSTALL_NAME)$(exeext) $(bindir)/$(CXX_INSTALL_NAME)$(exeext) \ + > /dev/null 2>&1 \ + || cp $(bindir)/$(GXX_INSTALL_NAME)$(exeext) $(bindir)/$(CXX_INSTALL_NAME)$(exeext) ; \ + fi ; \ + fi + +c++.install-info: + +c++.install-man: $(srcdir)/cp/g++.1 + -if [ -f cc1plus$(exeext) ] ; then \ + if [ -f g++-cross$(exeext) ] ; then \ + rm -f $(mandir)/$(GXX_CROSS_NAME)$(manext); \ + $(INSTALL_DATA) $(srcdir)/cp/g++.1 $(mandir)/$(GXX_CROSS_NAME)$(manext); \ + chmod a-x $(mandir)/$(GXX_CROSS_NAME)$(manext); \ + else \ + rm -f $(mandir)/$(GXX_INSTALL_NAME)$(manext); \ + $(INSTALL_DATA) $(srcdir)/cp/g++.1 $(mandir)/$(GXX_INSTALL_NAME)$(manext); \ + chmod a-x $(mandir)/$(GXX_INSTALL_NAME)$(manext); \ + fi; \ + else true; fi + +c++.uninstall: + -rm -rf $(bindir)/$(CXX_INSTALL_NAME)$(exeext) + -rm -rf $(bindir)/$(CXX_CROSS_NAME)$(exeext) + -rm -rf $(bindir)/$(GXX_INSTALL_NAME)$(exeext) + -rm -rf $(bindir)/$(GXX_CROSS_NAME)$(exeext) + -rm -rf $(mandir)/$(GXX_INSTALL_NAME)$(manext) + -rm -rf $(mandir)/$(GXX_CROSS_NAME)$(manext) + +# Clean hooks: +# A lot of the ancillary files are deleted by the main makefile. +# We just have to delete files specific to us. + +c++.mostlyclean: + -rm -f cp/*$(objext) $(DEMANGLER_PROG) +c++.clean: +c++.distclean: + -rm -f cp/config.status cp/Makefile + -rm -f cp/parse.output +c++.extraclean: +c++.maintainer-clean: + -rm -f cp/parse.c cp/parse.h + +# Stage hooks: +# The main makefile has already created stage?/cp. + +c++.stage1: + -mv cp/*$(objext) stage1/cp +c++.stage2: + -mv cp/*$(objext) stage2/cp +c++.stage3: + -mv cp/*$(objext) stage3/cp +c++.stage4: + -mv cp/*$(objext) stage4/cp + +# Maintenance hooks: + +# This target creates the files that can be rebuilt, but go in the +# distribution anyway. It then copies the files to the distdir directory. +c++.distdir: + mkdir tmp/cp + cd cp ; $(MAKE) $(FLAGS_TO_PASS) $(CXX_FLAGS_TO_PASS) parse.c hash.h + cd cp; \ + for file in *[0-9a-zA-Z+]; do \ + ln $$file ../tmp/cp >/dev/null 2>&1 || cp $$file ../tmp/cp; \ + done diff --git a/contrib/gcc/cp/Makefile.in b/contrib/gcc/cp/Makefile.in new file mode 100644 index 00000000000..11466b24a42 --- /dev/null +++ b/contrib/gcc/cp/Makefile.in @@ -0,0 +1,265 @@ +# Makefile for GNU C++ compiler. +# Copyright (C) 1987, 88, 90-4, 1995 Free Software Foundation, Inc. + +#This file is part of GNU CC. + +#GNU CC is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2, or (at your option) +#any later version. + +#GNU CC is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with GNU CC; see the file COPYING. If not, write to +#the Free Software Foundation, 59 Temple Place - Suite 330, +#Boston, MA 02111-1307, USA. + +# The makefile built from this file lives in the language subdirectory. +# Its purpose is to provide support for: +# +# 1) recursion where necessary, and only then (building .o's), and +# 2) building and debugging cc1 from the language subdirectory, and +# 3) nothing else. +# +# The parent makefile handles all other chores, with help from the +# language makefile fragment, of course. +# +# The targets for external use are: +# all, TAGS, ???mostlyclean, ???clean. + +# Suppress smart makes who think they know how to automake Yacc files +.y.c: + +# Variables that exist for you to override. +# See below for how to change them for certain systems. + +ALLOCA = + +# Various ways of specifying flags for compilations: +# CFLAGS is for the user to override to, e.g., do a bootstrap with -O2. +# BOOT_CFLAGS is the value of CFLAGS to pass +# to the stage2 and stage3 compilations +# XCFLAGS is used for most compilations but not when using the GCC just built. +XCFLAGS = +CFLAGS = -g +BOOT_CFLAGS = -O $(CFLAGS) +# These exists to be overridden by the x-* and t-* files, respectively. +X_CFLAGS = +T_CFLAGS = + +X_CPPFLAGS = +T_CPPFLAGS = + +CC = cc +BISON = bison +BISONFLAGS = +LEX = flex +LEXFLAGS = +AR = ar +AR_FLAGS = rc +SHELL = /bin/sh +MAKEINFO = makeinfo +TEXI2DVI = texi2dvi + +# Define this as & to perform parallel make on a Sequent. +# Note that this has some bugs, and it seems currently necessary +# to compile all the gen* files first by hand to avoid erroneous results. +P = + +# This is used in the definition of SUBDIR_USE_ALLOCA. +# ??? Perhaps it would be better if it just looked for *gcc*. +OLDCC = cc + +# This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET. +# It omits XCFLAGS, and specifies -B./. +# It also specifies -B$(tooldir)/ to find as and ld for a cross compiler. +GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) + +# Tools to use when building a cross-compiler. +# These are used because `configure' appends `cross-make' +# to the makefile when making a cross-compiler. + +target= ... `configure' substitutes actual target name here. +xmake_file= ... `configure' substitutes actual x- file name here. +tmake_file= ... `configure' substitutes actual t- file name here. +#version=`sed -e 's/.*\"\([^ \"]*\)[ \"].*/\1/' < $(srcdir)/version.c` +#mainversion=`sed -e 's/.*\"\([0-9]*\.[0-9]*\).*/\1/' < $(srcdir)/version.c` + +# Directory where sources are, from where we are. +srcdir = . + +# Additional system libraries to link with. +CLIB= + +# Change this to a null string if obstacks are installed in the +# system library. +OBSTACK=obstack.o + +# Choose the real default target. +ALL=all + +# End of variables for you to override. + +# Definition of `all' is here so that new rules inserted by sed +# do not specify the default target. +all: all.indirect + +# This tells GNU Make version 3 not to put all variables in the environment. +.NOEXPORT: + +# sed inserts variable overrides after the following line. +####target overrides +####host overrides +####cross overrides +####build overrides + +# Now figure out from those variables how to compile and link. + +all.indirect: Makefile ../cc1plus + +# IN_GCC tells obstack.h that we are using gcc's file. +INTERNAL_CFLAGS = $(CROSS) -DIN_GCC + +# This is the variable actually used when we compile. +ALL_CFLAGS = $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) $(XCFLAGS) + +# Likewise. +ALL_CPPFLAGS = $(CPPFLAGS) $(X_CPPFLAGS) $(T_CPPFLAGS) + +# Even if ALLOCA is set, don't use it if compiling with GCC. + +SUBDIR_OBSTACK = `if [ x$(OBSTACK) != x ]; then echo ../$(OBSTACK); else true; fi` +SUBDIR_USE_ALLOCA = `case "${CC}" in "${OLDCC}") if [ x$(ALLOCA) != x ]; then echo ../$(ALLOCA); else true; fi ;; esac` +SUBDIR_MALLOC = `if [ x$(MALLOC) != x ]; then echo ../$(MALLOC); else true; fi` + +# How to link with both our special library facilities +# and the system's installed libraries. +LIBS = $(SUBDIR_OBSTACK) $(SUBDIR_USE_ALLOCA) $(SUBDIR_MALLOC) $(CLIB) + +# Specify the directories to be searched for header files. +# Both . and srcdir are used, in that order, +# so that tm.h and config.h will be found in the compilation +# subdirectory rather than in the source directory. +INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config + +# Always use -I$(srcdir)/config when compiling. +.c.o: + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< + +# This tells GNU make version 3 not to export all the variables +# defined in this file into the environment. +.NOEXPORT: + +# Lists of files for various purposes. + +# Language-specific object files for g++ + +CXX_OBJS = call.o decl.o errfn.o expr.o pt.o sig.o typeck2.o \ + class.o decl2.o error.o gc.o lex.o parse.o ptree.o spew.o typeck.o cvt.o \ + edsel.o except.o init.o method.o search.o tree.o xref.o repo.o + +# Language-independent object files. +OBJS = `cat ../stamp-objlist` ../c-common.o ../c-pragma.o +OBJDEPS = ../stamp-objlist ../c-common.o ../c-pragma.o + +compiler: ../cc1plus +../cc1plus: $(P) $(CXX_OBJS) $(OBJDEPS) $(LIBDEPS) + rm -f ../cc1plus$(exeext) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \ + $(CXX_OBJS) $(OBJS) $(LIBS) + +Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure + cd ..; $(SHELL) config.status + +native: config.status ../cc1plus + +# Compiling object files from source files. + +# Note that dependencies on obstack.h are not written +# because that file is not part of GCC. + +# C++ language specific files. + +RTL_H = $(srcdir)/../rtl.h $(srcdir)/../rtl.def \ + $(srcdir)/../machmode.h $(srcdir)/../machmode.def +TREE_H = $(srcdir)/../tree.h $(srcdir)/../real.h $(srcdir)/../tree.def \ + $(srcdir)/../machmode.h $(srcdir)/../machmode.def +CXX_TREE_H = $(TREE_H) cp-tree.h tree.def +PARSE_H = $(srcdir)/parse.h +PARSE_C = $(srcdir)/parse.c + +parse.o : $(PARSE_C) $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h lex.h + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \ + `echo $(PARSE_C) | sed 's,^\./,,'` + +CONFLICTS = expect 5 shift/reduce conflicts and 38 reduce/reduce conflicts. +$(PARSE_H) : $(PARSE_C) +$(PARSE_C) : $(srcdir)/parse.y + @echo $(CONFLICTS) + cd $(srcdir); $(BISON) $(BISONFLAGS) -d -o parse.c parse.y + cd $(srcdir); grep '^#define[ ]*YYEMPTY' parse.c >>parse.h +#$(PARSE_C) $(PARSE_H) : stamp-parse ; @true +#stamp-parse: $(srcdir)/parse.y +# @echo $(CONFLICTS) +# $(BISON) $(BISONFLAGS) -d $(srcdir)/parse.y +# grep '^#define[ ]*YYEMPTY' y.tab.c >>y.tab.h +# $(srcdir)/../move-if-change y.tab.c $(PARSE_C) +# $(srcdir)/../move-if-change y.tab.h $(PARSE_H) +# cp $(PARSE_C) y.tab.c +# touch stamp-parse + +# hash.h really depends on $(srcdir)/gxx.gperf. +# But this would screw things for people that don't have gperf, +# if gxx.gpref got touched, say. +# Thus you have to remove hash.h to force it to be re-made. +$(srcdir)/hash.h: + gperf -p -j1 -g -o -t -N is_reserved_word '-k1,4,7,$$' \ + $(srcdir)/gxx.gperf >$(srcdir)/hash.h + +spew.o : spew.c $(CONFIG_H) $(CXX_TREE_H) \ + $(PARSE_H) $(srcdir)/../flags.h lex.h +lex.o : lex.c $(CONFIG_H) $(CXX_TREE_H) \ + $(PARSE_H) input.c $(srcdir)/../flags.h hash.h lex.h $(srcdir)/../c-pragma.h +decl.o : decl.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h \ + lex.h decl.h $(srcdir)/../stack.h +decl2.o : decl2.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h \ + lex.h decl.h +typeck2.o : typeck2.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h +typeck.o : typeck.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h $(RTL_H) +class.o : class.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h +call.o : call.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h class.h +init.o : init.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h $(RTL_H) +method.o : method.c $(CONFIG_H) $(CXX_TREE_H) class.h +cvt.o : cvt.c $(CONFIG_H) $(CXX_TREE_H) class.h +search.o : search.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../stack.h $(srcdir)/../flags.h +tree.o : tree.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h +ptree.o : ptree.c $(CONFIG_H) $(CXX_TREE_H) +gc.o : gc.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h +except.o : except.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h $(RTL_H) +expr.o : expr.c $(CONFIG_H) $(CXX_TREE_H) $(RTL_H) $(srcdir)/../flags.h \ + $(srcdir)/../expr.h ../insn-codes.h +edsel.o : edsel.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../stack.h $(srcdir)/../flags.h +xref.o : xref.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../input.h +pt.o : pt.c $(CONFIG_H) $(CXX_TREE_H) decl.h $(PARSE_H) +error.o : error.c $(CONFIG_H) $(CXX_TREE_H) +errfn.o : errfn.c $(CONFIG_H) $(CXX_TREE_H) +sig.o : sig.c $(CONFIG_H) $(CXX_TREE_H) $(srcdir)/../flags.h +repo.o : repo.c $(CONFIG_H) $(CXX_TREE_H) + +# These exist for maintenance purposes. + +# Update the tags table. +TAGS: force + cd $(srcdir) ; \ + etags *.c *.h ; \ + echo 'l' | tr 'l' '\f' >> TAGS ; \ + echo 'parse.y,0' >> TAGS ; \ + etags -a ../*.h ../*.c; + +.PHONY: TAGS + +force: diff --git a/contrib/gcc/cp/call.c b/contrib/gcc/cp/call.c new file mode 100644 index 00000000000..3f293ac809b --- /dev/null +++ b/contrib/gcc/cp/call.c @@ -0,0 +1,2993 @@ +/* Functions related to invoking methods and overloaded functions. + Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) and + hacked by Brendan Kehoe (brendan@cygnus.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "class.h" +#include "output.h" +#include "flags.h" + +#include "obstack.h" +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +extern void sorry (); + +extern int inhibit_warnings; +extern int flag_assume_nonnull_objects; +extern tree ctor_label, dtor_label; + +/* From typeck.c: */ +extern tree unary_complex_lvalue (); + +/* Compute the ease with which a conversion can be performed + between an expected and the given type. */ +static struct harshness_code convert_harshness (); + +#define EVIL_RETURN(ARG) ((ARG).code = EVIL_CODE, (ARG)) +#define STD_RETURN(ARG) ((ARG).code = STD_CODE, (ARG)) +#define QUAL_RETURN(ARG) ((ARG).code = QUAL_CODE, (ARG)) +#define TRIVIAL_RETURN(ARG) ((ARG).code = TRIVIAL_CODE, (ARG)) +#define ZERO_RETURN(ARG) ((ARG).code = 0, (ARG)) + +/* Ordering function for overload resolution. Compare two candidates + by gross quality. */ +int +rank_for_overload (x, y) + struct candidate *x, *y; +{ + if (y->h.code & (EVIL_CODE|ELLIPSIS_CODE|USER_CODE)) + return y->h.code - x->h.code; + if (x->h.code & (EVIL_CODE|ELLIPSIS_CODE|USER_CODE)) + return -1; + + /* This is set by compute_conversion_costs, for calling a non-const + member function from a const member function. */ + if ((y->harshness[0].code & CONST_CODE) ^ (x->harshness[0].code & CONST_CODE)) + return y->harshness[0].code - x->harshness[0].code; + + if (y->h.code & STD_CODE) + { + if (x->h.code & STD_CODE) + return y->h.distance - x->h.distance; + return 1; + } + if (x->h.code & STD_CODE) + return -1; + + return y->h.code - x->h.code; +} + +/* Compare two candidates, argument by argument. */ +int +rank_for_ideal (x, y) + struct candidate *x, *y; +{ + int i; + + if (x->h_len != y->h_len) + abort (); + + for (i = 0; i < x->h_len; i++) + { + if (y->harshness[i].code - x->harshness[i].code) + return y->harshness[i].code - x->harshness[i].code; + if ((y->harshness[i].code & STD_CODE) + && (y->harshness[i].distance - x->harshness[i].distance)) + return y->harshness[i].distance - x->harshness[i].distance; + + /* They're both the same code. Now see if we're dealing with an + integral promotion that needs a finer grain of accuracy. */ + if (y->harshness[0].code & PROMO_CODE + && (y->harshness[i].int_penalty ^ x->harshness[i].int_penalty)) + return y->harshness[i].int_penalty - x->harshness[i].int_penalty; + } + return 0; +} + +/* TYPE is the type we wish to convert to. PARM is the parameter + we have to work with. We use a somewhat arbitrary cost function + to measure this conversion. */ +static struct harshness_code +convert_harshness (type, parmtype, parm) + register tree type, parmtype; + tree parm; +{ + struct harshness_code h; + register enum tree_code codel; + register enum tree_code coder; + int lvalue; + + h.code = 0; + h.distance = 0; + h.int_penalty = 0; + +#ifdef GATHER_STATISTICS + n_convert_harshness++; +#endif + + if (TREE_CODE (parmtype) == REFERENCE_TYPE) + { + if (parm) + parm = convert_from_reference (parm); + parmtype = TREE_TYPE (parmtype); + lvalue = 1; + } + else if (parm) + lvalue = lvalue_p (parm); + else + lvalue = 0; + + if (TYPE_PTRMEMFUNC_P (type)) + type = TYPE_PTRMEMFUNC_FN_TYPE (type); + if (TYPE_PTRMEMFUNC_P (parmtype)) + parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype); + + codel = TREE_CODE (type); + coder = TREE_CODE (parmtype); + + if (TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (type)) + return ZERO_RETURN (h); + + if (coder == ERROR_MARK) + return EVIL_RETURN (h); + + if (codel == REFERENCE_TYPE) + { + tree ttl, ttr; + int constp = parm ? TREE_READONLY (parm) : TYPE_READONLY (parmtype); + int volatilep = (parm ? TREE_THIS_VOLATILE (parm) + : TYPE_VOLATILE (parmtype)); + register tree intype = TYPE_MAIN_VARIANT (parmtype); + register enum tree_code form = TREE_CODE (intype); + int penalty = 0; + + ttl = TREE_TYPE (type); + + /* Only allow const reference binding if we were given a parm to deal + with, since it isn't really a conversion. This is a hack to + prevent build_type_conversion from finding this conversion, but + still allow overloading to find it. */ + if (! lvalue && ! (parm && TYPE_READONLY (ttl))) + return EVIL_RETURN (h); + + if (TYPE_READONLY (ttl) < constp + || TYPE_VOLATILE (ttl) < volatilep) + return EVIL_RETURN (h); + + /* When passing a non-const argument into a const reference, dig it a + little, so a non-const reference is preferred over this one. */ + penalty = ((TYPE_READONLY (ttl) > constp) + + (TYPE_VOLATILE (ttl) > volatilep)); + + ttl = TYPE_MAIN_VARIANT (ttl); + + if (form == OFFSET_TYPE) + { + intype = TREE_TYPE (intype); + form = TREE_CODE (intype); + } + + ttr = intype; + + if (TREE_CODE (ttl) == ARRAY_TYPE && TREE_CODE (ttr) == ARRAY_TYPE) + { + if (comptypes (ttl, ttr, 1)) + return ZERO_RETURN (h); + return EVIL_RETURN (h); + } + + h = convert_harshness (ttl, ttr, NULL_TREE); + if (penalty && h.code == 0) + { + h.code = QUAL_CODE; + h.int_penalty = penalty; + } + return h; + } + + if (codel == POINTER_TYPE && fntype_p (parmtype)) + { + tree p1, p2; + struct harshness_code h1, h2; + + /* Get to the METHOD_TYPE or FUNCTION_TYPE that this might be. */ + type = TREE_TYPE (type); + + if (coder == POINTER_TYPE) + { + parmtype = TREE_TYPE (parmtype); + coder = TREE_CODE (parmtype); + } + + if (coder != TREE_CODE (type)) + return EVIL_RETURN (h); + + if (type != parmtype && coder == METHOD_TYPE) + { + tree ttl = TYPE_METHOD_BASETYPE (type); + tree ttr = TYPE_METHOD_BASETYPE (parmtype); + + int b_or_d = get_base_distance (ttr, ttl, 0, 0); + if (b_or_d < 0) + { + b_or_d = get_base_distance (ttl, ttr, 0, 0); + if (b_or_d < 0) + return EVIL_RETURN (h); + h.distance = -b_or_d; + } + else + h.distance = b_or_d; + h.code = STD_CODE; + + type = build_function_type + (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type))); + parmtype = build_function_type + (TREE_TYPE (parmtype), TREE_CHAIN (TYPE_ARG_TYPES (parmtype))); + } + + /* We allow the default conversion between function type + and pointer-to-function type for free. */ + if (comptypes (type, parmtype, 1)) + return h; + + if (pedantic) + return EVIL_RETURN (h); + + /* Compare return types. */ + p1 = TREE_TYPE (type); + p2 = TREE_TYPE (parmtype); + h2 = convert_harshness (p1, p2, NULL_TREE); + if (h2.code & EVIL_CODE) + return h2; + + h1.code = TRIVIAL_CODE; + h1.distance = 0; + + if (h2.distance != 0) + { + tree binfo; + + /* This only works for pointers. */ + if (TREE_CODE (p1) != POINTER_TYPE + && TREE_CODE (p1) != REFERENCE_TYPE) + return EVIL_RETURN (h); + + p1 = TREE_TYPE (p1); + p2 = TREE_TYPE (p2); + /* Don't die if we happen to be dealing with void*. */ + if (!IS_AGGR_TYPE (p1) || !IS_AGGR_TYPE (p2)) + return EVIL_RETURN (h); + if (h2.distance < 0) + binfo = get_binfo (p2, p1, 0); + else + binfo = get_binfo (p1, p2, 0); + + if (! BINFO_OFFSET_ZEROP (binfo)) + { +#if 0 + static int explained = 0; + if (h2.distance < 0) + message_2_types (sorry, "cannot cast `%s' to `%s' at function call site", p2, p1); + else + message_2_types (sorry, "cannot cast `%s' to `%s' at function call site", p1, p2); + + if (! explained++) + sorry ("(because pointer values change during conversion)"); +#endif + return EVIL_RETURN (h); + } + } + + h1.code |= h2.code; + if (h2.distance > h1.distance) + h1.distance = h2.distance; + + p1 = TYPE_ARG_TYPES (type); + p2 = TYPE_ARG_TYPES (parmtype); + while (p1 && TREE_VALUE (p1) != void_type_node + && p2 && TREE_VALUE (p2) != void_type_node) + { + h2 = convert_harshness (TREE_VALUE (p1), TREE_VALUE (p2), + NULL_TREE); + if (h2.code & EVIL_CODE) + return h2; + + if (h2.distance) + { + /* This only works for pointers and references. */ + if (TREE_CODE (TREE_VALUE (p1)) != POINTER_TYPE + && TREE_CODE (TREE_VALUE (p1)) != REFERENCE_TYPE) + return EVIL_RETURN (h); + h2.distance = - h2.distance; + } + + h1.code |= h2.code; + if (h2.distance > h1.distance) + h1.distance = h2.distance; + p1 = TREE_CHAIN (p1); + p2 = TREE_CHAIN (p2); + } + if (p1 == p2) + return h1; + if (p2) + { + if (p1) + return EVIL_RETURN (h); + h1.code |= ELLIPSIS_CODE; + return h1; + } + if (p1) + { + if (TREE_PURPOSE (p1) == NULL_TREE) + h1.code |= EVIL_CODE; + return h1; + } + } + else if (codel == POINTER_TYPE && coder == OFFSET_TYPE) + { + tree ttl, ttr; + + /* Get to the OFFSET_TYPE that this might be. */ + type = TREE_TYPE (type); + + if (coder != TREE_CODE (type)) + return EVIL_RETURN (h); + + ttl = TYPE_OFFSET_BASETYPE (type); + ttr = TYPE_OFFSET_BASETYPE (parmtype); + + if (ttl == ttr) + h.code = 0; + else + { + int b_or_d = get_base_distance (ttr, ttl, 0, 0); + if (b_or_d < 0) + { + b_or_d = get_base_distance (ttl, ttr, 0, 0); + if (b_or_d < 0) + return EVIL_RETURN (h); + h.distance = -b_or_d; + } + else + h.distance = b_or_d; + h.code = STD_CODE; + } + + /* Now test the OFFSET_TYPE's target compatibility. */ + type = TREE_TYPE (type); + parmtype = TREE_TYPE (parmtype); + } + + if (coder == UNKNOWN_TYPE) + { + if (codel == FUNCTION_TYPE + || codel == METHOD_TYPE + || (codel == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE))) + return TRIVIAL_RETURN (h); + return EVIL_RETURN (h); + } + + if (coder == VOID_TYPE) + return EVIL_RETURN (h); + + if (codel == BOOLEAN_TYPE) + { + if (INTEGRAL_CODE_P (coder) || coder == REAL_TYPE) + return STD_RETURN (h); + else if (coder == POINTER_TYPE || coder == OFFSET_TYPE) + { + /* Make this worse than any conversion to another pointer. + FIXME this is how I think the language should work, but it may not + end up being how the language is standardized (jason 1/30/95). */ + h.distance = 32767; + return STD_RETURN (h); + } + return EVIL_RETURN (h); + } + + if (INTEGRAL_CODE_P (codel)) + { + /* Control equivalence of ints an enums. */ + + if (codel == ENUMERAL_TYPE + && flag_int_enum_equivalence == 0) + { + /* Enums can be converted to ints, but not vice-versa. */ + if (coder != ENUMERAL_TYPE + || TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (parmtype)) + return EVIL_RETURN (h); + } + + /* else enums and ints (almost) freely interconvert. */ + + if (INTEGRAL_CODE_P (coder)) + { + if (TYPE_MAIN_VARIANT (type) + == TYPE_MAIN_VARIANT (type_promotes_to (parmtype))) + { + h.code = PROMO_CODE; +#if 0 /* What purpose does this serve? -jason */ + /* A char, short, wchar_t, etc., should promote to an int if + it can handle it, otherwise to an unsigned. So we'll make + an unsigned. */ + if (type != integer_type_node) + h.int_penalty = 1; +#endif + } + else + h.code = STD_CODE; + + return h; + } + else if (coder == REAL_TYPE) + { + h.code = STD_CODE; + h.distance = 0; + return h; + } + } + + if (codel == REAL_TYPE) + { + if (coder == REAL_TYPE) + { + if (TYPE_MAIN_VARIANT (type) + == TYPE_MAIN_VARIANT (type_promotes_to (parmtype))) + h.code = PROMO_CODE; + else + h.code = STD_CODE; + + return h; + } + else if (INTEGRAL_CODE_P (coder)) + { + h.code = STD_CODE; + h.distance = 0; + return h; + } + } + + /* Convert arrays which have not previously been converted. */ +#if 0 + if (codel == ARRAY_TYPE) + codel = POINTER_TYPE; +#endif + if (coder == ARRAY_TYPE) + { + coder = POINTER_TYPE; + if (parm) + { + parm = decay_conversion (parm); + parmtype = TREE_TYPE (parm); + } + else + parmtype = build_pointer_type (TREE_TYPE (parmtype)); + } + + /* Conversions among pointers */ + if (codel == POINTER_TYPE && coder == POINTER_TYPE) + { + register tree ttl = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + register tree ttr = TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)); + int penalty = 4 * (ttl != ttr); + + /* Anything converts to void *. Since this may be `const void *' + (etc.) use VOID_TYPE instead of void_type_node. Otherwise, the + targets must be the same, except that we do allow (at some cost) + conversion between signed and unsigned pointer types. */ + + if ((TREE_CODE (ttl) == METHOD_TYPE + || TREE_CODE (ttl) == FUNCTION_TYPE) + && TREE_CODE (ttl) == TREE_CODE (ttr)) + { + if (comptypes (ttl, ttr, -1)) + { + h.code = penalty ? STD_CODE : 0; + h.distance = 0; + } + else + h.code = EVIL_CODE; + return h; + } + +#if 1 + if (TREE_CODE (ttl) != VOID_TYPE + && (TREE_CODE (ttr) != VOID_TYPE || !parm || !integer_zerop (parm))) + { + if (TREE_UNSIGNED (ttl) != TREE_UNSIGNED (ttr)) + { + ttl = unsigned_type (ttl); + ttr = unsigned_type (ttr); + penalty = 10; + } + if (comp_target_types (type, parmtype, 1) <= 0) + return EVIL_RETURN (h); + } +#else + if (!(TREE_CODE (ttl) == VOID_TYPE + || TREE_CODE (ttr) == VOID_TYPE + || (TREE_UNSIGNED (ttl) ^ TREE_UNSIGNED (ttr) + && (ttl = unsigned_type (ttl), + ttr = unsigned_type (ttr), + penalty = 10, 0)) + || (comp_target_types (ttl, ttr, 0) > 0))) + return EVIL_RETURN (h); +#endif + + if (penalty == 10 || ttr == ttl) + { + tree tmp1 = TREE_TYPE (type), tmp2 = TREE_TYPE (parmtype); + + /* If one was unsigned but the other wasn't, then we need to + do a standard conversion from T to unsigned T. */ + if (penalty == 10) + h.code = PROMO_CODE; /* was STD_CODE */ + else + h.code = 0; + + /* Note conversion from `T*' to `const T*', + or `T*' to `volatile T*'. */ + if (ttl == ttr + && ((TYPE_READONLY (tmp1) != TREE_READONLY (tmp2)) + || (TYPE_VOLATILE (tmp1) != TYPE_VOLATILE (tmp2)))) + h.code |= QUAL_CODE; + + h.distance = 0; + return h; + } + + + if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE) + { + int b_or_d = get_base_distance (ttl, ttr, 0, 0); + if (b_or_d < 0) + { + b_or_d = get_base_distance (ttr, ttl, 0, 0); + if (b_or_d < 0) + return EVIL_RETURN (h); + h.distance = -b_or_d; + } + else + h.distance = b_or_d; + h.code = STD_CODE; + return h; + } + + /* If converting from a `class*' to a `void*', make it + less favorable than any inheritance relationship. */ + if (TREE_CODE (ttl) == VOID_TYPE && IS_AGGR_TYPE (ttr)) + { + h.code = STD_CODE; + h.distance = CLASSTYPE_MAX_DEPTH (ttr)+1; + return h; + } + + h.code = penalty ? STD_CODE : PROMO_CODE; + /* Catch things like `const char *' -> `const void *' + vs `const char *' -> `void *'. */ + if (ttl != ttr) + { + tree tmp1 = TREE_TYPE (type), tmp2 = TREE_TYPE (parmtype); + if ((TYPE_READONLY (tmp1) != TREE_READONLY (tmp2)) + || (TYPE_VOLATILE (tmp1) != TYPE_VOLATILE (tmp2))) + h.code |= QUAL_CODE; + } + return h; + } + + if (codel == POINTER_TYPE && coder == INTEGER_TYPE) + { + /* This is not a bad match, but don't let it beat + integer-enum combinations. */ + if (parm && integer_zerop (parm)) + { + h.code = STD_CODE; + h.distance = 0; + return h; + } + } + + /* C++: Since the `this' parameter of a signature member function + is represented as a signature pointer to handle default implementations + correctly, we can have the case that `type' is a signature pointer + while `parmtype' is a pointer to a signature table. We don't really + do any conversions in this case, so just return 0. */ + + if (codel == RECORD_TYPE && coder == POINTER_TYPE + && IS_SIGNATURE_POINTER (type) && IS_SIGNATURE (TREE_TYPE (parmtype))) + return ZERO_RETURN (h); + + if (codel == RECORD_TYPE && coder == RECORD_TYPE) + { + int b_or_d = get_base_distance (type, parmtype, 0, 0); + if (b_or_d < 0) + { + b_or_d = get_base_distance (parmtype, type, 0, 0); + if (b_or_d < 0) + return EVIL_RETURN (h); + h.distance = -b_or_d; + } + else + h.distance = b_or_d; + h.code = STD_CODE; + return h; + } + return EVIL_RETURN (h); +} + +/* A clone of build_type_conversion for checking user-defined conversions in + overload resolution. */ + +int +user_harshness (type, parmtype, parm) + register tree type, parmtype; + tree parm; +{ + tree conv; + tree winner = NULL_TREE; + int code; + + { + tree typename = build_typename_overload (type); + if (lookup_fnfields (TYPE_BINFO (parmtype), typename, 0)) + return 0; + } + + for (conv = lookup_conversions (parmtype); conv; conv = TREE_CHAIN (conv)) + { + struct harshness_code tmp; + + if (winner && TREE_PURPOSE (winner) == TREE_PURPOSE (conv)) + continue; + + if (tmp = convert_harshness (type, TREE_VALUE (conv), NULL_TREE), + tmp.code < USER_CODE && tmp.distance >= 0) + { + if (winner) + return EVIL_CODE; + else + { + winner = conv; + code = tmp.code; + } + } + } + + if (winner) + return code; + + return -1; +} + +int +can_convert (to, from) + tree to, from; +{ + struct harshness_code h; + h = convert_harshness (to, from, NULL_TREE); + return h.code < USER_CODE && h.distance >= 0; +} + +int +can_convert_arg (to, from, arg) + tree to, from, arg; +{ + struct harshness_code h; + h = convert_harshness (to, from, arg); + return h.code < USER_CODE && h.distance >= 0; +} + +#ifdef DEBUG_MATCHING +static char * +print_harshness (h) + struct harshness_code *h; +{ + static char buf[1024]; + char tmp[1024]; + + bzero (buf, 1024 * sizeof (char)); + strcat (buf, "codes=["); + if (h->code & EVIL_CODE) + strcat (buf, "EVIL"); + if (h->code & CONST_CODE) + strcat (buf, " CONST"); + if (h->code & ELLIPSIS_CODE) + strcat (buf, " ELLIPSIS"); + if (h->code & USER_CODE) + strcat (buf, " USER"); + if (h->code & STD_CODE) + strcat (buf, " STD"); + if (h->code & PROMO_CODE) + strcat (buf, " PROMO"); + if (h->code & QUAL_CODE) + strcat (buf, " QUAL"); + if (h->code & TRIVIAL_CODE) + strcat (buf, " TRIVIAL"); + if (buf[0] == '\0') + strcat (buf, "0"); + + sprintf (tmp, "] distance=%d int_penalty=%d", h->distance, h->int_penalty); + + strcat (buf, tmp); + + return buf; +} +#endif + +/* Algorithm: For each argument, calculate how difficult it is to + make FUNCTION accept that argument. If we can easily tell that + FUNCTION won't be acceptable to one of the arguments, then we + don't need to compute the ease of converting the other arguments, + since it will never show up in the intersection of all arguments' + favorite functions. + + Conversions between builtin and user-defined types are allowed, but + no function involving such a conversion is preferred to one which + does not require such a conversion. Furthermore, such conversions + must be unique. */ + +void +compute_conversion_costs (function, tta_in, cp, arglen) + tree function; + tree tta_in; + struct candidate *cp; + int arglen; +{ + tree ttf_in = TYPE_ARG_TYPES (TREE_TYPE (function)); + tree ttf = ttf_in; + tree tta = tta_in; + + /* Start out with no strikes against. */ + int evil_strikes = 0; + int ellipsis_strikes = 0; + int user_strikes = 0; + int b_or_d_strikes = 0; + int easy_strikes = 0; + + int strike_index = 0, win; + struct harshness_code lose; + extern int cp_silent; + +#ifdef GATHER_STATISTICS + n_compute_conversion_costs++; +#endif + +#ifndef DEBUG_MATCHING + /* We don't emit any warnings or errors while trying out each candidate. */ + cp_silent = 1; +#endif + + cp->function = function; + cp->arg = tta ? TREE_VALUE (tta) : NULL_TREE; + cp->u.bad_arg = 0; /* optimistic! */ + + cp->h.code = 0; + cp->h.distance = 0; + cp->h.int_penalty = 0; + bzero ((char *) cp->harshness, + (cp->h_len + 1) * sizeof (struct harshness_code)); + + while (ttf && tta) + { + struct harshness_code h; + + if (ttf == void_list_node) + break; + + if (type_unknown_p (TREE_VALUE (tta))) + { + /* Must perform some instantiation here. */ + tree rhs = TREE_VALUE (tta); + tree lhstype = TREE_VALUE (ttf); + + /* Keep quiet about possible contravariance violations. */ + int old_inhibit_warnings = inhibit_warnings; + inhibit_warnings = 1; + + /* @@ This is to undo what `grokdeclarator' does to + parameter types. It really should go through + something more general. */ + + TREE_TYPE (tta) = unknown_type_node; + rhs = instantiate_type (lhstype, rhs, 0); + inhibit_warnings = old_inhibit_warnings; + + if (TREE_CODE (rhs) == ERROR_MARK) + h.code = EVIL_CODE; + else + h = convert_harshness (lhstype, TREE_TYPE (rhs), rhs); + } + else + { +#ifdef DEBUG_MATCHING + static tree old_function = NULL_TREE; + + if (!old_function || function != old_function) + { + cp_error ("trying %D", function); + old_function = function; + } + + cp_error (" doing (%T) %E against arg %T", + TREE_TYPE (TREE_VALUE (tta)), TREE_VALUE (tta), + TREE_VALUE (ttf)); +#endif + + h = convert_harshness (TREE_VALUE (ttf), + TREE_TYPE (TREE_VALUE (tta)), + TREE_VALUE (tta)); + +#ifdef DEBUG_MATCHING + cp_error (" evaluated %s", print_harshness (&h)); +#endif + } + + cp->harshness[strike_index] = h; + if ((h.code & EVIL_CODE) + || ((h.code & STD_CODE) && h.distance < 0)) + { + cp->u.bad_arg = strike_index; + evil_strikes = 1; + } + else if (h.code & ELLIPSIS_CODE) + ellipsis_strikes += 1; +#if 0 + /* This is never set by `convert_harshness'. */ + else if (h.code & USER_CODE) + { + user_strikes += 1; + } +#endif + else + { + if ((h.code & STD_CODE) && h.distance) + { + if (h.distance > b_or_d_strikes) + b_or_d_strikes = h.distance; + } + else + easy_strikes += (h.code & (STD_CODE|PROMO_CODE|TRIVIAL_CODE)); + cp->h.code |= h.code; + /* Make sure we communicate this. */ + cp->h.int_penalty += h.int_penalty; + } + + ttf = TREE_CHAIN (ttf); + tta = TREE_CHAIN (tta); + strike_index += 1; + } + + if (tta) + { + /* ran out of formals, and parmlist is fixed size. */ + if (ttf /* == void_type_node */) + { + cp->h.code = EVIL_CODE; + cp->u.bad_arg = -1; + cp_silent = 0; + return; + } + else + { + struct harshness_code h; + int l = list_length (tta); + ellipsis_strikes += l; + h.code = ELLIPSIS_CODE; + h.distance = 0; + h.int_penalty = 0; + for (; l; --l) + cp->harshness[strike_index++] = h; + } + } + else if (ttf && ttf != void_list_node) + { + /* ran out of actuals, and no defaults. */ + if (TREE_PURPOSE (ttf) == NULL_TREE) + { + cp->h.code = EVIL_CODE; + cp->u.bad_arg = -2; + cp_silent = 0; + return; + } + /* Store index of first default. */ + cp->harshness[arglen].distance = strike_index+1; + } + else + cp->harshness[arglen].distance = 0; + + /* Argument list lengths work out, so don't need to check them again. */ + if (evil_strikes) + { + /* We do not check for derived->base conversions here, since in + no case would they give evil strike counts, unless such conversions + are somehow ambiguous. */ + + /* See if any user-defined conversions apply. + But make sure that we do not loop. */ + static int dont_convert_types = 0; + + if (dont_convert_types) + { + cp->h.code = EVIL_CODE; + cp_silent = 0; + return; + } + + win = 0; /* Only get one chance to win. */ + ttf = TYPE_ARG_TYPES (TREE_TYPE (function)); + tta = tta_in; + strike_index = 0; + evil_strikes = 0; + + while (ttf && tta) + { + if (ttf == void_list_node) + break; + + lose = cp->harshness[strike_index]; + if ((lose.code & EVIL_CODE) + || ((lose.code & STD_CODE) && lose.distance < 0)) + { + tree actual_type = TREE_TYPE (TREE_VALUE (tta)); + tree formal_type = TREE_VALUE (ttf); + int extra_conversions = 0; + + dont_convert_types = 1; + + if (TREE_CODE (formal_type) == REFERENCE_TYPE) + formal_type = TREE_TYPE (formal_type); + if (TREE_CODE (actual_type) == REFERENCE_TYPE) + actual_type = TREE_TYPE (actual_type); + + if (formal_type != error_mark_node + && actual_type != error_mark_node) + { + formal_type = TYPE_MAIN_VARIANT (formal_type); + actual_type = TYPE_MAIN_VARIANT (actual_type); + + if (TYPE_HAS_CONSTRUCTOR (formal_type)) + { + /* If it has a constructor for this type, + try to use it. */ + /* @@ There is no way to save this result yet, so + success is a NULL_TREE for now. */ + if (convert_to_aggr (formal_type, TREE_VALUE (tta), 0, 1) + != error_mark_node) + win++; + } + if (TYPE_LANG_SPECIFIC (actual_type) + && TYPE_HAS_CONVERSION (actual_type)) + { + int extra = user_harshness (formal_type, actual_type); + + if (extra == EVIL_CODE) + win += 2; + else if (extra >= 0) + { + win++; + extra_conversions = extra; + } + } + } + dont_convert_types = 0; + + if (win == 1) + { + user_strikes += 1; + cp->harshness[strike_index].code + = USER_CODE | (extra_conversions ? STD_CODE : 0); + win = 0; + } + else + { + if (cp->u.bad_arg > strike_index) + cp->u.bad_arg = strike_index; + + evil_strikes = win ? 2 : 1; + break; + } + } + + ttf = TREE_CHAIN (ttf); + tta = TREE_CHAIN (tta); + strike_index += 1; + } + } + + /* Const member functions get a small penalty because defaulting + to const is less useful than defaulting to non-const. */ + /* This is bogus, it does not correspond to anything in the ARM. + This code will be fixed when this entire section is rewritten + to conform to the ARM. (mrs) */ + if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) + { + tree this_parm = TREE_VALUE (ttf_in); + + if (TREE_CODE (this_parm) == RECORD_TYPE /* Is `this' a sig ptr? */ + ? TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (this_parm)))) + : TYPE_READONLY (TREE_TYPE (this_parm))) + { + cp->harshness[0].code |= TRIVIAL_CODE; + ++easy_strikes; + } + else + { + /* Calling a non-const member function from a const member function + is probably invalid, but for now we let it only draw a warning. + We indicate that such a mismatch has occurred by setting the + harshness to a maximum value. */ + if (TREE_CODE (TREE_TYPE (TREE_VALUE (tta_in))) == POINTER_TYPE + && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (TREE_VALUE (tta_in)))))) + cp->harshness[0].code |= CONST_CODE; + } + } + + if (evil_strikes) + cp->h.code = EVIL_CODE; + if (ellipsis_strikes) + cp->h.code |= ELLIPSIS_CODE; + if (user_strikes) + cp->h.code |= USER_CODE; + cp_silent = 0; +#ifdef DEBUG_MATCHING + cp_error ("final eval %s", print_harshness (&cp->h)); +#endif +} + +/* Subroutine of ideal_candidate. See if X or Y is a better match + than the other. */ +static int +strictly_better (x, y) + unsigned short x, y; +{ + unsigned short xor; + + if (x == y) + return 0; + + xor = x ^ y; + if (xor >= x || xor >= y) + return 1; + return 0; +} + +/* When one of several possible overloaded functions and/or methods + can be called, choose the best candidate for overloading. + + BASETYPE is the context from which we start method resolution + or NULL if we are comparing overloaded functions. + CANDIDATES is the array of candidates we have to choose from. + N_CANDIDATES is the length of CANDIDATES. + PARMS is a TREE_LIST of parameters to the function we'll ultimately + choose. It is modified in place when resolving methods. It is not + modified in place when resolving overloaded functions. + LEN is the length of the parameter list. */ + +static struct candidate * +ideal_candidate (basetype, candidates, n_candidates, parms, len) + tree basetype; + struct candidate *candidates; + int n_candidates; + tree parms; + int len; +{ + struct candidate *cp = candidates+n_candidates; + int i, j = -1, best_code; + + /* For each argument, sort the functions from best to worst for the arg. + For each function that's not best for this arg, set its overall + harshness to EVIL so that other args won't like it. The candidate + list for the last argument is the intersection of all the best-liked + functions. */ + +#if 0 + for (i = 0; i < len; i++) + { + qsort (candidates, n_candidates, sizeof (struct candidate), + rank_for_overload); + best_code = cp[-1].h.code; + + /* To find out functions that are worse than that represented + by BEST_CODE, we can't just do a comparison like h.code>best_code. + The total harshness for the "best" fn may be 8|8 for two args, and + the harshness for the next-best may be 8|2. If we just compared, + that would be checking 8>10, which would lead to the next-best + being disqualified. What we actually want to do is get rid + of functions that are definitely worse than that represented + by best_code, i.e. those which have bits set higher than the + highest in best_code. Sooooo, what we do is clear out everything + represented by best_code, and see if we still come up with something + higher. If so (e.g., 8|8 vs 8|16), it'll disqualify it properly. */ + for (j = n_candidates-2; j >= 0; j--) + if ((candidates[j].h.code & ~best_code) > best_code) + candidates[j].h.code = EVIL_CODE; + } + + if (cp[-1].h.code & EVIL_CODE) + return NULL; +#else + qsort (candidates, n_candidates, sizeof (struct candidate), + rank_for_overload); + best_code = cp[-1].h.code; +#endif + + /* If they're at least as good as each other, do an arg-by-arg check. */ + if (! strictly_better (cp[-1].h.code, cp[-2].h.code)) + { + int better = 0; + int worse = 0; + + for (j = 0; j < n_candidates; j++) + if (! strictly_better (candidates[j].h.code, best_code)) + break; + + qsort (candidates+j, n_candidates-j, sizeof (struct candidate), + rank_for_ideal); + for (i = 0; i < len; i++) + { + if (cp[-1].harshness[i].code < cp[-2].harshness[i].code) + better = 1; + else if (cp[-1].harshness[i].code > cp[-2].harshness[i].code) + worse = 1; + else if (cp[-1].harshness[i].code & STD_CODE) + { + /* If it involves a standard conversion, let the + inheritance lattice be the final arbiter. */ + if (cp[-1].harshness[i].distance > cp[-2].harshness[i].distance) + worse = 1; + else if (cp[-1].harshness[i].distance < cp[-2].harshness[i].distance) + better = 1; + } + else if (cp[-1].harshness[i].code & PROMO_CODE) + { + /* For integral promotions, take into account a finer + granularity for determining which types should be favored + over others in such promotions. */ + if (cp[-1].harshness[i].int_penalty > cp[-2].harshness[i].int_penalty) + worse = 1; + else if (cp[-1].harshness[i].int_penalty < cp[-2].harshness[i].int_penalty) + better = 1; + } + } + + if (! better || worse) + return NULL; + } + return cp-1; +} + +/* Assume that if the class referred to is not in the + current class hierarchy, that it may be remote. + PARENT is assumed to be of aggregate type here. */ +static int +may_be_remote (parent) + tree parent; +{ + if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent) == 0) + return 0; + + if (current_class_type == NULL_TREE) + return 0; + + if (parent == current_class_type) + return 0; + + if (UNIQUELY_DERIVED_FROM_P (parent, current_class_type)) + return 0; + return 1; +} + +tree +build_vfield_ref (datum, type) + tree datum, type; +{ + tree rval; + int old_assume_nonnull_objects = flag_assume_nonnull_objects; + + if (datum == error_mark_node) + return error_mark_node; + + /* Vtable references are always made from non-null objects. */ + flag_assume_nonnull_objects = 1; + if (TREE_CODE (TREE_TYPE (datum)) == REFERENCE_TYPE) + datum = convert_from_reference (datum); + + if (! TYPE_USES_COMPLEX_INHERITANCE (type)) + rval = build (COMPONENT_REF, TREE_TYPE (CLASSTYPE_VFIELD (type)), + datum, CLASSTYPE_VFIELD (type)); + else + rval = build_component_ref (datum, DECL_NAME (CLASSTYPE_VFIELD (type)), 0, 0); + flag_assume_nonnull_objects = old_assume_nonnull_objects; + + return rval; +} + +/* Build a call to a member of an object. I.e., one that overloads + operator ()(), or is a pointer-to-function or pointer-to-method. */ +static tree +build_field_call (basetype_path, instance_ptr, name, parms) + tree basetype_path, instance_ptr, name, parms; +{ + tree field, instance; + + if (instance_ptr == current_class_decl) + { + /* Check to see if we really have a reference to an instance variable + with `operator()()' overloaded. */ + field = IDENTIFIER_CLASS_VALUE (name); + + if (field == NULL_TREE) + { + cp_error ("`this' has no member named `%D'", name); + return error_mark_node; + } + + if (TREE_CODE (field) == FIELD_DECL) + { + /* If it's a field, try overloading operator (), + or calling if the field is a pointer-to-function. */ + instance = build_component_ref_1 (C_C_D, field, 0); + if (instance == error_mark_node) + return error_mark_node; + + if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance)) + && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance))) + return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, instance, parms, NULL_TREE); + + if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE) + { + if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE) + return build_function_call (instance, parms); + else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == METHOD_TYPE) + return build_function_call (instance, tree_cons (NULL_TREE, current_class_decl, parms)); + } + } + return NULL_TREE; + } + + /* Check to see if this is not really a reference to an instance variable + with `operator()()' overloaded. */ + field = lookup_field (basetype_path, name, 1, 0); + + /* This can happen if the reference was ambiguous or for access + violations. */ + if (field == error_mark_node) + return error_mark_node; + + if (field) + { + tree basetype; + tree ftype = TREE_TYPE (field); + + if (TREE_CODE (ftype) == REFERENCE_TYPE) + ftype = TREE_TYPE (ftype); + + if (TYPE_LANG_SPECIFIC (ftype) && TYPE_OVERLOADS_CALL_EXPR (ftype)) + { + /* Make the next search for this field very short. */ + basetype = DECL_FIELD_CONTEXT (field); + instance_ptr = convert_pointer_to (basetype, instance_ptr); + + instance = build_indirect_ref (instance_ptr, NULL_PTR); + return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, + build_component_ref_1 (instance, field, 0), + parms, NULL_TREE); + } + if (TREE_CODE (ftype) == POINTER_TYPE) + { + if (TREE_CODE (TREE_TYPE (ftype)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (ftype)) == METHOD_TYPE) + { + /* This is a member which is a pointer to function. */ + tree ref + = build_component_ref_1 (build_indirect_ref (instance_ptr, + NULL_PTR), + field, LOOKUP_COMPLAIN); + if (ref == error_mark_node) + return error_mark_node; + return build_function_call (ref, parms); + } + } + else if (TREE_CODE (ftype) == METHOD_TYPE) + { + error ("invalid call via pointer-to-member function"); + return error_mark_node; + } + else + return NULL_TREE; + } + return NULL_TREE; +} + +tree +find_scoped_type (type, inner_name, inner_types) + tree type, inner_name, inner_types; +{ + tree tags = CLASSTYPE_TAGS (type); + + while (tags) + { + /* The TREE_PURPOSE of an enum tag (which becomes a member of the + enclosing class) is set to the name for the enum type. So, if + inner_name is `bar', and we strike `baz' for `enum bar { baz }', + then this test will be true. */ + if (TREE_PURPOSE (tags) == inner_name) + { + if (inner_types == NULL_TREE) + return DECL_NESTED_TYPENAME (TYPE_NAME (TREE_VALUE (tags))); + return resolve_scope_to_name (TREE_VALUE (tags), inner_types); + } + tags = TREE_CHAIN (tags); + } + +#if 0 + /* XXX This needs to be fixed better. */ + if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + { + sorry ("nested class lookup in template type"); + return NULL_TREE; + } +#endif + + /* Look for a TYPE_DECL. */ + for (tags = TYPE_FIELDS (type); tags; tags = TREE_CHAIN (tags)) + if (TREE_CODE (tags) == TYPE_DECL && DECL_NAME (tags) == inner_name) + { + /* Code by raeburn. */ + if (inner_types == NULL_TREE) + return DECL_NESTED_TYPENAME (tags); + return resolve_scope_to_name (TREE_TYPE (tags), inner_types); + } + + return NULL_TREE; +} + +/* Resolve an expression NAME1::NAME2::...::NAMEn to + the name that names the above nested type. INNER_TYPES + is a chain of nested type names (held together by SCOPE_REFs); + OUTER_TYPE is the type we know to enclose INNER_TYPES. + Returns NULL_TREE if there is an error. */ +tree +resolve_scope_to_name (outer_type, inner_stuff) + tree outer_type, inner_stuff; +{ + register tree tmp; + tree inner_name, inner_type; + + if (outer_type == NULL_TREE && current_class_type != NULL_TREE) + { + /* We first try to look for a nesting in our current class context, + then try any enclosing classes. */ + tree type = current_class_type; + + while (type && (TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE)) + { + tree rval = resolve_scope_to_name (type, inner_stuff); + + if (rval != NULL_TREE) + return rval; + type = DECL_CONTEXT (TYPE_NAME (type)); + } + } + + if (TREE_CODE (inner_stuff) == SCOPE_REF) + { + inner_name = TREE_OPERAND (inner_stuff, 0); + inner_type = TREE_OPERAND (inner_stuff, 1); + } + else + { + inner_name = inner_stuff; + inner_type = NULL_TREE; + } + + if (outer_type == NULL_TREE) + { + tree x; + /* If we have something that's already a type by itself, + use that. */ + if (IDENTIFIER_HAS_TYPE_VALUE (inner_name)) + { + if (inner_type) + return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name), + inner_type); + return inner_name; + } + + x = lookup_name (inner_name, 0); + + if (x && TREE_CODE (x) == NAMESPACE_DECL) + { + x = lookup_namespace_name (x, inner_type); + return x; + } + return NULL_TREE; + } + + if (! IS_AGGR_TYPE (outer_type)) + return NULL_TREE; + + /* Look for member classes or enums. */ + tmp = find_scoped_type (outer_type, inner_name, inner_type); + + /* If it's not a type in this class, then go down into the + base classes and search there. */ + if (! tmp && TYPE_BINFO (outer_type)) + { + tree binfos = TYPE_BINFO_BASETYPES (outer_type); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tmp = resolve_scope_to_name (BINFO_TYPE (base_binfo), inner_stuff); + if (tmp) + return tmp; + } + tmp = NULL_TREE; + } + + return tmp; +} + +/* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'. + This is how virtual function calls are avoided. */ +tree +build_scoped_method_call (exp, scopes, name, parms) + tree exp, scopes, name, parms; +{ + /* Because this syntactic form does not allow + a pointer to a base class to be `stolen', + we need not protect the derived->base conversion + that happens here. + + @@ But we do have to check access privileges later. */ + tree basename = resolve_scope_to_name (NULL_TREE, scopes); + tree basetype, binfo, decl; + tree type = TREE_TYPE (exp); + + if (type == error_mark_node + || basename == NULL_TREE) + return error_mark_node; + + basetype = IDENTIFIER_TYPE_VALUE (basename); + + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note + that explicit ~int is caught in the parser; this deals with typedefs + and template parms. */ + if (TREE_CODE (name) == BIT_NOT_EXPR && ! is_aggr_typedef (basename, 0)) + { + if (type != basetype) + cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')", + exp, basetype, type); + name = TREE_OPERAND (name, 0); + if (basetype != get_type_value (name)) + cp_error ("qualified type `%T' does not match destructor name `~%T'", + basetype, name); + return convert (void_type_node, exp); + } + + if (! is_aggr_typedef (basename, 1)) + return error_mark_node; + + if (! IS_AGGR_TYPE (type)) + { + cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'", + exp, type); + return error_mark_node; + } + + if ((binfo = binfo_or_else (basetype, type))) + { + if (binfo == error_mark_node) + return error_mark_node; + if (TREE_CODE (exp) == INDIRECT_REF) + decl = build_indirect_ref (convert_pointer_to (binfo, + build_unary_op (ADDR_EXPR, exp, 0)), NULL_PTR); + else + decl = build_scoped_ref (exp, scopes); + + /* Call to a destructor. */ + if (TREE_CODE (name) == BIT_NOT_EXPR) + { + /* Explicit call to destructor. */ + name = TREE_OPERAND (name, 0); + if (! (name == constructor_name (TREE_TYPE (decl)) + || TREE_TYPE (decl) == get_type_value (name))) + { + cp_error + ("qualified type `%T' does not match destructor name `~%T'", + TREE_TYPE (decl), name); + return error_mark_node; + } + if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl))) + return convert (void_type_node, exp); + + return build_delete (TREE_TYPE (decl), decl, integer_two_node, + LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, + 0); + } + + /* Call to a method. */ + return build_method_call (decl, name, parms, binfo, + LOOKUP_NORMAL|LOOKUP_NONVIRTUAL); + } + return error_mark_node; +} + +static void +print_candidates (candidates) + tree candidates; +{ + cp_error_at ("candidates are: %D", TREE_VALUE (candidates)); + candidates = TREE_CHAIN (candidates); + + while (candidates) + { + cp_error_at (" %D", TREE_VALUE (candidates)); + candidates = TREE_CHAIN (candidates); + } +} + +static void +print_n_candidates (candidates, n) + struct candidate *candidates; + int n; +{ + int i; + + cp_error_at ("candidates are: %D", candidates[0].function); + for (i = 1; i < n; i++) + cp_error_at (" %D", candidates[i].function); +} + +/* Build something of the form ptr->method (args) + or object.method (args). This can also build + calls to constructors, and find friends. + + Member functions always take their class variable + as a pointer. + + INSTANCE is a class instance. + + NAME is the name of the method desired, usually an IDENTIFIER_NODE. + + PARMS help to figure out what that NAME really refers to. + + BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE + down to the real instance type to use for access checking. We need this + information to get protected accesses correct. This parameter is used + by build_member_call. + + FLAGS is the logical disjunction of zero or more LOOKUP_ + flags. See cp-tree.h for more info. + + If this is all OK, calls build_function_call with the resolved + member function. + + This function must also handle being called to perform + initialization, promotion/coercion of arguments, and + instantiation of default parameters. + + Note that NAME may refer to an instance variable name. If + `operator()()' is defined for the type of that field, then we return + that result. */ +tree +build_method_call (instance, name, parms, basetype_path, flags) + tree instance, name, parms, basetype_path; + int flags; +{ + register tree function, fntype, value_type; + register tree basetype, save_basetype; + register tree baselink, result, method_name, parmtypes, parm; + tree last; + int pass; + enum access_type access = access_public; + + /* Range of cases for vtable optimization. */ + enum vtable_needs { not_needed, maybe_needed, unneeded, needed }; + enum vtable_needs need_vtbl = not_needed; + + char *name_kind; + int ever_seen = 0; + tree instance_ptr = NULL_TREE; + int all_virtual = flag_all_virtual; + int static_call_context = 0; + tree found_fns = NULL_TREE; + + /* Keep track of `const' and `volatile' objects. */ + int constp, volatilep; + +#ifdef GATHER_STATISTICS + n_build_method_call++; +#endif + + if (instance == error_mark_node + || name == error_mark_node + || parms == error_mark_node + || (instance != NULL_TREE && TREE_TYPE (instance) == error_mark_node)) + return error_mark_node; + + /* This is the logic that magically deletes the second argument to + operator delete, if it is not needed. */ + if (name == ansi_opname[(int) DELETE_EXPR] && list_length (parms)==2) + { + tree save_last = TREE_CHAIN (parms); + tree result; + /* get rid of unneeded argument */ + TREE_CHAIN (parms) = NULL_TREE; + result = build_method_call (instance, name, parms, basetype_path, + (LOOKUP_SPECULATIVELY|flags) + &~LOOKUP_COMPLAIN); + /* If it finds a match, return it. */ + if (result) + return build_method_call (instance, name, parms, basetype_path, flags); + /* If it doesn't work, two argument delete must work */ + TREE_CHAIN (parms) = save_last; + } + /* We already know whether it's needed or not for vec delete. */ + else if (name == ansi_opname[(int) VEC_DELETE_EXPR] + && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance))) + TREE_CHAIN (parms) = NULL_TREE; + + if (TREE_CODE (name) == BIT_NOT_EXPR) + { + flags |= LOOKUP_DESTRUCTOR; + name = TREE_OPERAND (name, 0); + if (parms) + error ("destructors take no parameters"); + basetype = TREE_TYPE (instance); + if (TREE_CODE (basetype) == REFERENCE_TYPE) + basetype = TREE_TYPE (basetype); + if (! ((IS_AGGR_TYPE (basetype) + && name == constructor_name (basetype)) + || basetype == get_type_value (name))) + { + cp_error ("destructor name `~%D' does not match type `%T' of expression", + name, basetype); + return convert (void_type_node, instance); + } + + if (! TYPE_HAS_DESTRUCTOR (basetype)) + return convert (void_type_node, instance); + instance = default_conversion (instance); + instance_ptr = build_unary_op (ADDR_EXPR, instance, 0); + return build_delete (build_pointer_type (basetype), + instance_ptr, integer_two_node, + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0); + } + + { + char *xref_name; + + /* Initialize name for error reporting. */ + if (IDENTIFIER_OPNAME_P (name) && ! IDENTIFIER_TYPENAME_P (name)) + { + char *p = operator_name_string (name); + xref_name = (char *)alloca (strlen (p) + 10); + sprintf (xref_name, "operator %s", p); + } + else if (TREE_CODE (name) == SCOPE_REF) + xref_name = IDENTIFIER_POINTER (TREE_OPERAND (name, 1)); + else + xref_name = IDENTIFIER_POINTER (name); + + GNU_xref_call (current_function_decl, xref_name); + } + + if (instance == NULL_TREE) + { + basetype = NULL_TREE; + /* Check cases where this is really a call to raise + an exception. */ + if (current_class_type && TREE_CODE (name) == IDENTIFIER_NODE) + { + basetype = purpose_member (name, CLASSTYPE_TAGS (current_class_type)); + if (basetype) + basetype = TREE_VALUE (basetype); + } + else if (TREE_CODE (name) == SCOPE_REF + && TREE_CODE (TREE_OPERAND (name, 0)) == IDENTIFIER_NODE) + { + if (! is_aggr_typedef (TREE_OPERAND (name, 0), 1)) + return error_mark_node; + basetype = purpose_member (TREE_OPERAND (name, 1), + CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name, 0)))); + if (basetype) + basetype = TREE_VALUE (basetype); + } + + if (basetype != NULL_TREE) + ; + /* call to a constructor... */ + else if (basetype_path) + basetype = BINFO_TYPE (basetype_path); + else if (IDENTIFIER_HAS_TYPE_VALUE (name)) + { + basetype = IDENTIFIER_TYPE_VALUE (name); + name = constructor_name_full (basetype); + } + else + { + tree typedef_name = lookup_name (name, 1); + if (typedef_name && TREE_CODE (typedef_name) == TYPE_DECL) + { + /* Canonicalize the typedef name. */ + basetype = TREE_TYPE (typedef_name); + name = TYPE_IDENTIFIER (basetype); + } + else + { + cp_error ("no constructor named `%T' in scope", + name); + return error_mark_node; + } + } + + if (! IS_AGGR_TYPE (basetype)) + { + non_aggr_error: + if ((flags & LOOKUP_COMPLAIN) && TREE_CODE (basetype) != ERROR_MARK) + cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'", + name, instance, basetype); + + return error_mark_node; + } + } + else if (instance == C_C_D || instance == current_class_decl) + { + /* When doing initialization, we side-effect the TREE_TYPE of + C_C_D, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE. */ + basetype = TREE_TYPE (C_C_D); + + /* Anything manifestly `this' in constructors and destructors + has a known type, so virtual function tables are not needed. */ + if (TYPE_VIRTUAL_P (basetype) + && !(flags & LOOKUP_NONVIRTUAL)) + need_vtbl = (dtor_label || ctor_label) + ? unneeded : maybe_needed; + + /* If `this' is a signature pointer and `name' is not a constructor, + we are calling a signature member function. In that case, set the + `basetype' to the signature type and dereference the `optr' field. */ + if (IS_SIGNATURE_POINTER (basetype) + && TYPE_IDENTIFIER (basetype) != name) + { + basetype = SIGNATURE_TYPE (basetype); + instance_ptr = build_optr_ref (instance); + instance_ptr = convert (build_pointer_type (basetype), instance_ptr); + basetype_path = TYPE_BINFO (basetype); + } + else + { + instance = C_C_D; + instance_ptr = current_class_decl; + basetype_path = TYPE_BINFO (current_class_type); + } + result = build_field_call (basetype_path, instance_ptr, name, parms); + + if (result) + return result; + } + else if (TREE_CODE (instance) == RESULT_DECL) + { + basetype = TREE_TYPE (instance); + /* Should we ever have to make a virtual function reference + from a RESULT_DECL, know that it must be of fixed type + within the scope of this function. */ + if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype)) + need_vtbl = maybe_needed; + instance_ptr = build1 (ADDR_EXPR, build_pointer_type (basetype), instance); + } + else + { + /* The MAIN_VARIANT of the type that `instance_ptr' winds up being. */ + tree inst_ptr_basetype; + + static_call_context = + (TREE_CODE (instance) == INDIRECT_REF + && TREE_CODE (TREE_OPERAND (instance, 0)) == NOP_EXPR + && TREE_OPERAND (TREE_OPERAND (instance, 0), 0) == error_mark_node); + + if (TREE_CODE (instance) == OFFSET_REF) + instance = resolve_offset_ref (instance); + + /* the base type of an instance variable is pointer to class */ + basetype = TREE_TYPE (instance); + + if (TREE_CODE (basetype) == REFERENCE_TYPE) + { + basetype = TREE_TYPE (basetype); + if (! IS_AGGR_TYPE (basetype)) + goto non_aggr_error; + /* Call to convert not needed because we are remaining + within the same type. */ + instance_ptr = build1 (NOP_EXPR, build_pointer_type (basetype), + instance); + inst_ptr_basetype = TYPE_MAIN_VARIANT (basetype); + } + else + { + if (! IS_AGGR_TYPE (basetype) + && ! (TYPE_LANG_SPECIFIC (basetype) + && (IS_SIGNATURE_POINTER (basetype) + || IS_SIGNATURE_REFERENCE (basetype)))) + goto non_aggr_error; + + /* If `instance' is a signature pointer/reference and `name' is + not a constructor, we are calling a signature member function. + In that case set the `basetype' to the signature type. */ + if ((IS_SIGNATURE_POINTER (basetype) + || IS_SIGNATURE_REFERENCE (basetype)) + && TYPE_IDENTIFIER (basetype) != name) + basetype = SIGNATURE_TYPE (basetype); + + if ((IS_SIGNATURE (basetype) + && (instance_ptr = instance)) + || (lvalue_p (instance) + && (instance_ptr = build_unary_op (ADDR_EXPR, instance, 0))) + || (instance_ptr = unary_complex_lvalue (ADDR_EXPR, instance))) + { + if (instance_ptr == error_mark_node) + return error_mark_node; + } + else if (TREE_CODE (instance) == NOP_EXPR + || TREE_CODE (instance) == CONSTRUCTOR) + { + /* A cast is not an lvalue. Initialize a fresh temp + with the value we are casting from, and proceed with + that temporary. We can't cast to a reference type, + so that simplifies the initialization to something + we can manage. */ + tree temp = get_temp_name (TREE_TYPE (instance), 0); + if (IS_AGGR_TYPE (TREE_TYPE (instance))) + expand_aggr_init (temp, instance, 0, flags); + else + { + store_init_value (temp, instance); + expand_decl_init (temp); + } + instance = temp; + instance_ptr = build_unary_op (ADDR_EXPR, instance, 0); + } + else + { + if (TREE_CODE (instance) != CALL_EXPR) + my_friendly_abort (125); + if (TYPE_NEEDS_CONSTRUCTING (basetype)) + instance = build_cplus_new (basetype, instance, 0); + else + { + instance = get_temp_name (basetype, 0); + TREE_ADDRESSABLE (instance) = 1; + } + instance_ptr = build_unary_op (ADDR_EXPR, instance, 0); + } + /* @@ Should we call comp_target_types here? */ + if (IS_SIGNATURE (basetype)) + inst_ptr_basetype = basetype; + else + inst_ptr_basetype = TREE_TYPE (TREE_TYPE (instance_ptr)); + if (TYPE_MAIN_VARIANT (basetype) == TYPE_MAIN_VARIANT (inst_ptr_basetype)) + basetype = inst_ptr_basetype; + else + { + instance_ptr = convert (build_pointer_type (basetype), instance_ptr); + if (instance_ptr == error_mark_node) + return error_mark_node; + } + } + + /* After converting `instance_ptr' above, `inst_ptr_basetype' was + not updated, so we use `basetype' instead. */ + if (basetype_path == NULL_TREE + && IS_SIGNATURE (basetype)) + basetype_path = TYPE_BINFO (basetype); + else if (basetype_path == NULL_TREE || + BINFO_TYPE (basetype_path) != TYPE_MAIN_VARIANT (inst_ptr_basetype)) + basetype_path = TYPE_BINFO (inst_ptr_basetype); + + result = build_field_call (basetype_path, instance_ptr, name, parms); + if (result) + return result; + + if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype)) + { + if (TREE_SIDE_EFFECTS (instance_ptr)) + { + /* This action is needed because the instance is needed + for providing the base of the virtual function table. + Without using a SAVE_EXPR, the function we are building + may be called twice, or side effects on the instance + variable (such as a post-increment), may happen twice. */ + instance_ptr = save_expr (instance_ptr); + instance = build_indirect_ref (instance_ptr, NULL_PTR); + } + else if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE) + { + /* This happens when called for operator new (). */ + instance = build_indirect_ref (instance, NULL_PTR); + } + + need_vtbl = maybe_needed; + } + } + + if (TYPE_SIZE (basetype) == 0) + { + /* This is worth complaining about, I think. */ + cp_error ("cannot lookup method in incomplete type `%T'", basetype); + return error_mark_node; + } + + save_basetype = TYPE_MAIN_VARIANT (basetype); + +#if 0 + if (all_virtual == 1 + && (! strncmp (IDENTIFIER_POINTER (name), OPERATOR_METHOD_FORMAT, + OPERATOR_METHOD_LENGTH) + || instance_ptr == NULL_TREE + || (TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype) == 0))) + all_virtual = 0; +#endif + + last = NULL_TREE; + for (parmtypes = NULL_TREE, parm = parms; parm; parm = TREE_CHAIN (parm)) + { + tree t = TREE_TYPE (TREE_VALUE (parm)); + if (TREE_CODE (t) == OFFSET_TYPE) + { + /* Convert OFFSET_TYPE entities to their normal selves. */ + TREE_VALUE (parm) = resolve_offset_ref (TREE_VALUE (parm)); + t = TREE_TYPE (TREE_VALUE (parm)); + } + if (TREE_CODE (TREE_VALUE (parm)) == OFFSET_REF + && TREE_CODE (t) == METHOD_TYPE) + { + TREE_VALUE (parm) = build_unary_op (ADDR_EXPR, TREE_VALUE (parm), 0); + } +#if 0 + /* This breaks reference-to-array parameters. */ + if (TREE_CODE (t) == ARRAY_TYPE) + { + /* Perform the conversion from ARRAY_TYPE to POINTER_TYPE in place. + This eliminates needless calls to `compute_conversion_costs'. */ + TREE_VALUE (parm) = default_conversion (TREE_VALUE (parm)); + t = TREE_TYPE (TREE_VALUE (parm)); + } +#endif + if (t == error_mark_node) + return error_mark_node; + last = build_tree_list (NULL_TREE, t); + parmtypes = chainon (parmtypes, last); + } + + if (instance && IS_SIGNATURE (basetype)) + { + /* @@ Should this be the constp/volatilep flags for the optr field + of the signature pointer? */ + constp = TYPE_READONLY (basetype); + volatilep = TYPE_VOLATILE (basetype); + parms = tree_cons (NULL_TREE, instance_ptr, parms); + } + else if (instance) + { + /* TREE_READONLY (instance) fails for references. */ + constp = TYPE_READONLY (TREE_TYPE (TREE_TYPE (instance_ptr))); + volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (instance_ptr))); + parms = tree_cons (NULL_TREE, instance_ptr, parms); + } + else + { + /* Raw constructors are always in charge. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (basetype) + && ! (flags & LOOKUP_HAS_IN_CHARGE)) + { + flags |= LOOKUP_HAS_IN_CHARGE; + parms = tree_cons (NULL_TREE, integer_one_node, parms); + parmtypes = tree_cons (NULL_TREE, integer_type_node, parmtypes); + } + + constp = 0; + volatilep = 0; + instance_ptr = build_int_2 (0, 0); + TREE_TYPE (instance_ptr) = build_pointer_type (basetype); + parms = tree_cons (NULL_TREE, instance_ptr, parms); + } + + parmtypes = tree_cons (NULL_TREE, TREE_TYPE (instance_ptr), parmtypes); + + if (last == NULL_TREE) + last = parmtypes; + + /* Look up function name in the structure type definition. */ + + if ((IDENTIFIER_HAS_TYPE_VALUE (name) + && ! IDENTIFIER_OPNAME_P (name) + && IS_AGGR_TYPE (IDENTIFIER_TYPE_VALUE (name)) + && TREE_CODE (IDENTIFIER_TYPE_VALUE (name)) != UNINSTANTIATED_P_TYPE) + || name == constructor_name (basetype)) + { + tree tmp = NULL_TREE; + if (IDENTIFIER_TYPE_VALUE (name) == basetype + || name == constructor_name (basetype)) + tmp = TYPE_BINFO (basetype); + else + tmp = get_binfo (IDENTIFIER_TYPE_VALUE (name), basetype, 0); + + if (tmp != NULL_TREE) + { + name_kind = "constructor"; + + if (TYPE_USES_VIRTUAL_BASECLASSES (basetype) + && ! (flags & LOOKUP_HAS_IN_CHARGE)) + { + /* Constructors called for initialization + only are never in charge. */ + tree tmplist; + + flags |= LOOKUP_HAS_IN_CHARGE; + tmplist = tree_cons (NULL_TREE, integer_zero_node, + TREE_CHAIN (parms)); + TREE_CHAIN (parms) = tmplist; + tmplist = tree_cons (NULL_TREE, integer_type_node, TREE_CHAIN (parmtypes)); + TREE_CHAIN (parmtypes) = tmplist; + } + basetype = BINFO_TYPE (tmp); + } + else + name_kind = "method"; + } + else + name_kind = "method"; + + if (basetype_path == NULL_TREE + || BINFO_TYPE (basetype_path) != TYPE_MAIN_VARIANT (basetype)) + basetype_path = TYPE_BINFO (basetype); + result = lookup_fnfields (basetype_path, name, + (flags & LOOKUP_COMPLAIN)); + if (result == error_mark_node) + return error_mark_node; + + +#if 0 + /* Now, go look for this method name. We do not find destructors here. + + Putting `void_list_node' on the end of the parmtypes + fakes out `build_decl_overload' into doing the right thing. */ + TREE_CHAIN (last) = void_list_node; + method_name = build_decl_overload (name, parmtypes, + 1 + (name == constructor_name (save_basetype) + || name == constructor_name_full (save_basetype))); + TREE_CHAIN (last) = NULL_TREE; +#endif + + for (pass = 0; pass < 2; pass++) + { + struct candidate *candidates; + struct candidate *cp; + int len; + unsigned best = 1; + + /* This increments every time we go up the type hierarchy. + The idea is to prefer a function of the derived class if possible. */ + int b_or_d = 0; + + baselink = result; + + if (pass > 0) + { + candidates + = (struct candidate *) alloca ((ever_seen+1) + * sizeof (struct candidate)); + bzero ((char *) candidates, (ever_seen + 1) * sizeof (struct candidate)); + cp = candidates; + len = list_length (parms); + ever_seen = 0; + + /* First see if a global function has a shot at it. */ + if (flags & LOOKUP_GLOBAL) + { + tree friend_parms; + tree parm = instance_ptr; + + if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE) + parm = convert_from_reference (parm); + else if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE) + parm = build_indirect_ref (parm, "friendifying parms (compiler error)"); + else + my_friendly_abort (167); + + friend_parms = tree_cons (NULL_TREE, parm, TREE_CHAIN (parms)); + + cp->h_len = len; + cp->harshness = (struct harshness_code *) + alloca ((len + 1) * sizeof (struct harshness_code)); + + result = build_overload_call (name, friend_parms, 0, cp); + /* If it turns out to be the one we were actually looking for + (it was probably a friend function), the return the + good result. */ + if (TREE_CODE (result) == CALL_EXPR) + return result; + + while ((cp->h.code & EVIL_CODE) == 0) + { + /* non-standard uses: set the field to 0 to indicate + we are using a non-member function. */ + cp->u.field = 0; + if (cp->harshness[len].distance == 0 + && cp->h.code < best) + best = cp->h.code; + cp += 1; + } + } + } + + while (baselink) + { + /* We have a hit (of sorts). If the parameter list is + "error_mark_node", or some variant thereof, it won't + match any methods. Since we have verified that the is + some method vaguely matching this one (in name at least), + silently return. + + Don't stop for friends, however. */ + basetype_path = TREE_PURPOSE (baselink); + + function = TREE_VALUE (baselink); + if (TREE_CODE (basetype_path) == TREE_LIST) + basetype_path = TREE_VALUE (basetype_path); + basetype = BINFO_TYPE (basetype_path); + +#if 0 + /* Cast the instance variable if necessary. */ + if (basetype != TYPE_MAIN_VARIANT + (TREE_TYPE (TREE_TYPE (TREE_VALUE (parms))))) + { + if (basetype == save_basetype) + TREE_VALUE (parms) = instance_ptr; + else + { + tree type = build_pointer_type + (build_type_variant (basetype, constp, volatilep)); + TREE_VALUE (parms) = convert_force (type, instance_ptr, 0); + } + } + + /* FIXME: this is the wrong place to get an error. Hopefully + the access-control rewrite will make this change more cleanly. */ + if (TREE_VALUE (parms) == error_mark_node) + return error_mark_node; +#endif + + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function))) + function = DECL_CHAIN (function); + + for (; function; function = DECL_CHAIN (function)) + { +#ifdef GATHER_STATISTICS + n_inner_fields_searched++; +#endif + ever_seen++; + if (pass > 0) + found_fns = tree_cons (NULL_TREE, function, found_fns); + + /* Not looking for friends here. */ + if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE + && ! DECL_STATIC_FUNCTION_P (function)) + continue; + +#if 0 + if (pass == 0 + && DECL_ASSEMBLER_NAME (function) == method_name) + goto found; +#endif + + if (pass > 0) + { + tree these_parms = parms; + +#ifdef GATHER_STATISTICS + n_inner_fields_searched++; +#endif + cp->h_len = len; + cp->harshness = (struct harshness_code *) + alloca ((len + 1) * sizeof (struct harshness_code)); + + if (DECL_STATIC_FUNCTION_P (function)) + these_parms = TREE_CHAIN (these_parms); + compute_conversion_costs (function, these_parms, cp, len); + + if ((cp->h.code & EVIL_CODE) == 0) + { + cp->u.field = function; + cp->function = function; + cp->basetypes = basetype_path; + + /* Don't allow non-converting constructors to convert. */ + if (flags & LOOKUP_ONLYCONVERTING + && DECL_LANG_SPECIFIC (function) + && DECL_NONCONVERTING_P (function)) + continue; + + /* No "two-level" conversions. */ + if (flags & LOOKUP_NO_CONVERSION + && (cp->h.code & USER_CODE)) + continue; + + cp++; + } + } + } + /* Now we have run through one link's member functions. + arrange to head-insert this link's links. */ + baselink = next_baselink (baselink); + b_or_d += 1; + /* Don't grab functions from base classes. lookup_fnfield will + do the work to get us down into the right place. */ + baselink = NULL_TREE; + } + if (pass == 0) + { + tree igv = lookup_name_nonclass (name); + + /* No exact match could be found. Now try to find match + using default conversions. */ + if ((flags & LOOKUP_GLOBAL) && igv) + { + if (TREE_CODE (igv) == FUNCTION_DECL) + ever_seen += 1; + else if (TREE_CODE (igv) == TREE_LIST) + ever_seen += count_functions (igv); + } + + if (ever_seen == 0) + { + if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN)) + == LOOKUP_SPECULATIVELY) + return NULL_TREE; + + TREE_CHAIN (last) = void_list_node; + if (flags & LOOKUP_GLOBAL) + cp_error ("no global or member function `%D(%A)' defined", + name, parmtypes); + else + cp_error ("no member function `%T::%D(%A)' defined", + save_basetype, name, TREE_CHAIN (parmtypes)); + return error_mark_node; + } + continue; + } + + if (cp - candidates != 0) + { + /* Rank from worst to best. Then cp will point to best one. + Private fields have their bits flipped. For unsigned + numbers, this should make them look very large. + If the best alternate has a (signed) negative value, + then all we ever saw were private members. */ + if (cp - candidates > 1) + { + int n_candidates = cp - candidates; + extern int warn_synth; + TREE_VALUE (parms) = instance_ptr; + cp = ideal_candidate (save_basetype, candidates, + n_candidates, parms, len); + if (cp == (struct candidate *)0) + { + if (flags & LOOKUP_COMPLAIN) + { + TREE_CHAIN (last) = void_list_node; + cp_error ("call of overloaded %s `%D(%A)' is ambiguous", + name_kind, name, TREE_CHAIN (parmtypes)); + print_n_candidates (candidates, n_candidates); + } + return error_mark_node; + } + if (cp->h.code & EVIL_CODE) + return error_mark_node; + if (warn_synth + && DECL_NAME (cp->function) == ansi_opname[MODIFY_EXPR] + && DECL_ARTIFICIAL (cp->function) + && n_candidates == 2) + { + cp_warning ("using synthesized `%#D' for copy assignment", + cp->function); + cp_warning_at (" where cfront would use `%#D'", + candidates->function); + } + } + else if (cp[-1].h.code & EVIL_CODE) + { + if (flags & LOOKUP_COMPLAIN) + cp_error ("ambiguous type conversion requested for %s `%D'", + name_kind, name); + return error_mark_node; + } + else + cp--; + + /* The global function was the best, so use it. */ + if (cp->u.field == 0) + { + /* We must convert the instance pointer into a reference type. + Global overloaded functions can only either take + aggregate objects (which come for free from references) + or reference data types anyway. */ + TREE_VALUE (parms) = copy_node (instance_ptr); + TREE_TYPE (TREE_VALUE (parms)) = build_reference_type (TREE_TYPE (TREE_TYPE (instance_ptr))); + return build_function_call (cp->function, parms); + } + + function = cp->function; + basetype_path = cp->basetypes; + if (! DECL_STATIC_FUNCTION_P (function)) + TREE_VALUE (parms) = cp->arg; + goto found_and_maybe_warn; + } + + if (flags & (LOOKUP_COMPLAIN|LOOKUP_SPECULATIVELY)) + { + if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN)) + == LOOKUP_SPECULATIVELY) + return NULL_TREE; + + if (DECL_STATIC_FUNCTION_P (cp->function)) + parms = TREE_CHAIN (parms); + if (ever_seen) + { + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + if (static_call_context + && TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE) + cp_error ("object missing in call to `%D'", cp->function); + else if (ever_seen > 1) + { + TREE_CHAIN (last) = void_list_node; + cp_error ("no matching function for call to `%T::%D (%A)%V'", + TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (instance_ptr))), + name, TREE_CHAIN (parmtypes), + TREE_TYPE (TREE_TYPE (instance_ptr))); + TREE_CHAIN (last) = NULL_TREE; + print_candidates (found_fns); + } + else + report_type_mismatch (cp, parms, name_kind); + return error_mark_node; + } + + if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN)) + == LOOKUP_COMPLAIN) + { + cp_error ("%T has no method named %D", save_basetype, name); + return error_mark_node; + } + return NULL_TREE; + } + continue; + + found_and_maybe_warn: + if ((cp->harshness[0].code & CONST_CODE) + /* 12.1p2: Constructors can be called for const objects. */ + && ! DECL_CONSTRUCTOR_P (cp->function)) + { + if (flags & LOOKUP_COMPLAIN) + { + cp_error_at ("non-const member function `%D'", cp->function); + error ("called for const object at this point in file"); + } + /* Not good enough for a match. */ + else + return error_mark_node; + } + goto found; + } + /* Silently return error_mark_node. */ + return error_mark_node; + + found: + if (flags & LOOKUP_PROTECT) + access = compute_access (basetype_path, function); + + if (access == access_private) + { + if (flags & LOOKUP_COMPLAIN) + { + cp_error_at ("%s `%+#D' is %s", name_kind, function, + TREE_PRIVATE (function) ? "private" + : "from private base class"); + error ("within this context"); + } + return error_mark_node; + } + else if (access == access_protected) + { + if (flags & LOOKUP_COMPLAIN) + { + cp_error_at ("%s `%+#D' %s", name_kind, function, + TREE_PROTECTED (function) ? "is protected" + : "has protected accessibility"); + error ("within this context"); + } + return error_mark_node; + } + + /* From here on down, BASETYPE is the type that INSTANCE_PTR's + type (if it exists) is a pointer to. */ + + if (DECL_ABSTRACT_VIRTUAL_P (function) + && instance == C_C_D + && DECL_CONSTRUCTOR_P (current_function_decl) + && ! (flags & LOOKUP_NONVIRTUAL) + && value_member (function, get_abstract_virtuals (basetype))) + cp_error ("abstract virtual `%#D' called from constructor", function); + + if (IS_SIGNATURE (basetype) && static_call_context) + { + cp_error ("cannot call signature member function `%T::%D' without signature pointer/reference", + basetype, name); + return error_mark_node; + } + else if (IS_SIGNATURE (basetype)) + return build_signature_method_call (basetype, instance, function, parms); + + function = DECL_MAIN_VARIANT (function); + /* Declare external function if necessary. */ + assemble_external (function); + +#if 1 + /* Is it a synthesized method that needs to be synthesized? */ + if (DECL_ARTIFICIAL (function) && ! flag_no_inline + && ! DECL_INITIAL (function) + /* Kludge: don't synthesize for default args. */ + && current_function_decl) + synthesize_method (function); +#endif + + if (pedantic && DECL_THIS_INLINE (function) && ! DECL_ARTIFICIAL (function) + && ! DECL_INITIAL (function) && ! DECL_PENDING_INLINE_INFO (function)) + cp_warning ("inline function `%#D' called before definition", function); + + fntype = TREE_TYPE (function); + if (TREE_CODE (fntype) == POINTER_TYPE) + fntype = TREE_TYPE (fntype); + basetype = DECL_CLASS_CONTEXT (function); + + /* If we are referencing a virtual function from an object + of effectively static type, then there is no need + to go through the virtual function table. */ + if (need_vtbl == maybe_needed) + { + int fixed_type = resolves_to_fixed_type_p (instance, 0); + + if (all_virtual == 1 + && DECL_VINDEX (function) + && may_be_remote (basetype)) + need_vtbl = needed; + else if (DECL_VINDEX (function)) + need_vtbl = fixed_type ? unneeded : needed; + else + need_vtbl = not_needed; + } + + if (TREE_CODE (fntype) == METHOD_TYPE && static_call_context + && !DECL_CONSTRUCTOR_P (function)) + { + /* Let's be nice to the user for now, and give reasonable + default behavior. */ + instance_ptr = current_class_decl; + if (instance_ptr) + { + if (basetype != current_class_type) + { + tree binfo = get_binfo (basetype, current_class_type, 1); + if (binfo == NULL_TREE) + { + error_not_base_type (function, current_class_type); + return error_mark_node; + } + else if (basetype == error_mark_node) + return error_mark_node; + } + } + /* Only allow a static member function to call another static member + function. */ + else if (DECL_LANG_SPECIFIC (function) + && !DECL_STATIC_FUNCTION_P (function)) + { + cp_error ("cannot call member function `%D' without object", + function); + return error_mark_node; + } + } + + value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node; + + if (TYPE_SIZE (value_type) == 0) + { + if (flags & LOOKUP_COMPLAIN) + incomplete_type_error (0, value_type); + return error_mark_node; + } + + if (DECL_STATIC_FUNCTION_P (function)) + parms = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype), + TREE_CHAIN (parms), function, LOOKUP_NORMAL); + else if (need_vtbl == unneeded) + { + int sub_flags = DECL_CONSTRUCTOR_P (function) ? flags : LOOKUP_NORMAL; + basetype = TREE_TYPE (instance); + if (TYPE_METHOD_BASETYPE (TREE_TYPE (function)) != TYPE_MAIN_VARIANT (basetype) + && TYPE_USES_COMPLEX_INHERITANCE (basetype)) + { + basetype = DECL_CLASS_CONTEXT (function); + instance_ptr = convert_pointer_to (basetype, instance_ptr); + instance = build_indirect_ref (instance_ptr, NULL_PTR); + } + parms = tree_cons (NULL_TREE, instance_ptr, + convert_arguments (NULL_TREE, TREE_CHAIN (TYPE_ARG_TYPES (fntype)), TREE_CHAIN (parms), function, sub_flags)); + } + else + { + if ((flags & LOOKUP_NONVIRTUAL) == 0) + basetype = DECL_CONTEXT (function); + + /* First parm could be integer_zerop with casts like + ((Object*)0)->Object::IsA() */ + if (!integer_zerop (TREE_VALUE (parms))) + { + /* Since we can't have inheritance with a union, doing get_binfo + on it won't work. We do all the convert_pointer_to_real + stuff to handle MI correctly...for unions, that's not + an issue, so we must short-circuit that extra work here. */ + tree tmp = TREE_TYPE (TREE_TYPE (TREE_VALUE (parms))); + if (tmp != NULL_TREE && TREE_CODE (tmp) == UNION_TYPE) + instance_ptr = TREE_VALUE (parms); + else + { + tree binfo = get_binfo (basetype, + TREE_TYPE (TREE_TYPE (TREE_VALUE (parms))), + 0); + instance_ptr = convert_pointer_to_real (binfo, TREE_VALUE (parms)); + } + instance_ptr + = convert_pointer_to (build_type_variant (basetype, + constp, volatilep), + instance_ptr); + + if (TREE_CODE (instance_ptr) == COND_EXPR) + { + instance_ptr = save_expr (instance_ptr); + instance = build_indirect_ref (instance_ptr, NULL_PTR); + } + else if (TREE_CODE (instance_ptr) == NOP_EXPR + && TREE_CODE (TREE_OPERAND (instance_ptr, 0)) == ADDR_EXPR + && TREE_OPERAND (TREE_OPERAND (instance_ptr, 0), 0) == instance) + ; + /* The call to `convert_pointer_to' may return error_mark_node. */ + else if (TREE_CODE (instance_ptr) == ERROR_MARK) + return instance_ptr; + else if (instance == NULL_TREE + || TREE_CODE (instance) != INDIRECT_REF + || TREE_OPERAND (instance, 0) != instance_ptr) + instance = build_indirect_ref (instance_ptr, NULL_PTR); + } + parms = tree_cons (NULL_TREE, instance_ptr, + convert_arguments (NULL_TREE, TREE_CHAIN (TYPE_ARG_TYPES (fntype)), TREE_CHAIN (parms), function, LOOKUP_NORMAL)); + } + +#if 0 + /* Constructors do not overload method calls. */ + else if (TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype) + && name != TYPE_IDENTIFIER (basetype) + && (TREE_CODE (function) != FUNCTION_DECL + || strncmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)), + OPERATOR_METHOD_FORMAT, + OPERATOR_METHOD_LENGTH)) + && (may_be_remote (basetype) || instance != C_C_D)) + { + tree fn_as_int; + + parms = TREE_CHAIN (parms); + + if (!all_virtual && TREE_CODE (function) == FUNCTION_DECL) + fn_as_int = build_unary_op (ADDR_EXPR, function, 0); + else + fn_as_int = convert (TREE_TYPE (default_conversion (function)), DECL_VINDEX (function)); + if (all_virtual == 1) + fn_as_int = convert (integer_type_node, fn_as_int); + + result = build_opfncall (METHOD_CALL_EXPR, LOOKUP_NORMAL, instance, fn_as_int, parms); + + if (result == NULL_TREE) + { + compiler_error ("could not overload `operator->()(...)'"); + return error_mark_node; + } + else if (result == error_mark_node) + return error_mark_node; + +#if 0 + /* Do this if we want the result of operator->() to inherit + the type of the function it is subbing for. */ + TREE_TYPE (result) = value_type; +#endif + + return result; + } +#endif + + if (parms == error_mark_node + || (parms && TREE_CHAIN (parms) == error_mark_node)) + return error_mark_node; + + if (need_vtbl == needed) + { + function = build_vfn_ref (&TREE_VALUE (parms), instance, + DECL_VINDEX (function)); + TREE_TYPE (function) = build_pointer_type (fntype); + } + + if (TREE_CODE (function) == FUNCTION_DECL) + GNU_xref_call (current_function_decl, + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function))); + + { + int is_constructor; + + if (TREE_CODE (function) == FUNCTION_DECL) + { + is_constructor = DECL_CONSTRUCTOR_P (function); + TREE_USED (function) = 1; + function = default_conversion (function); + } + else + { + is_constructor = 0; + function = default_conversion (function); + } + + result = build_nt (CALL_EXPR, function, parms, NULL_TREE); + + TREE_TYPE (result) = value_type; + TREE_SIDE_EFFECTS (result) = 1; + TREE_HAS_CONSTRUCTOR (result) = is_constructor; + result = convert_from_reference (result); + return result; + } +} + +/* Similar to `build_method_call', but for overloaded non-member functions. + The name of this function comes through NAME. The name depends + on PARMS. + + Note that this function must handle simple `C' promotions, + as well as variable numbers of arguments (...), and + default arguments to boot. + + If the overloading is successful, we return a tree node which + contains the call to the function. + + If overloading produces candidates which are probable, but not definite, + we hold these candidates. If FINAL_CP is non-zero, then we are free + to assume that final_cp points to enough storage for all candidates that + this function might generate. The `harshness' array is preallocated for + the first candidate, but not for subsequent ones. + + Note that the DECL_RTL of FUNCTION must be made to agree with this + function's new name. */ + +tree +build_overload_call_real (fnname, parms, flags, final_cp, buildxxx) + tree fnname, parms; + int flags; + struct candidate *final_cp; + int buildxxx; +{ + /* must check for overloading here */ + tree overload_name, functions, function, parm; + tree parmtypes = NULL_TREE, last = NULL_TREE; + register tree outer; + int length; + int parmlength = list_length (parms); + + struct candidate *candidates, *cp; + + if (final_cp) + { + final_cp[0].h.code = 0; + final_cp[0].h.distance = 0; + final_cp[0].function = 0; + /* end marker. */ + final_cp[1].h.code = EVIL_CODE; + } + + for (parm = parms; parm; parm = TREE_CHAIN (parm)) + { + register tree t = TREE_TYPE (TREE_VALUE (parm)); + + if (t == error_mark_node) + { + if (final_cp) + final_cp->h.code = EVIL_CODE; + return error_mark_node; + } + if (TREE_CODE (t) == OFFSET_TYPE) +#if 0 + /* This breaks reference-to-array parameters. */ + || TREE_CODE (t) == ARRAY_TYPE +#endif + { + /* Perform the conversion from ARRAY_TYPE to POINTER_TYPE in place. + Also convert OFFSET_TYPE entities to their normal selves. + This eliminates needless calls to `compute_conversion_costs'. */ + TREE_VALUE (parm) = default_conversion (TREE_VALUE (parm)); + t = TREE_TYPE (TREE_VALUE (parm)); + } + last = build_tree_list (NULL_TREE, t); + parmtypes = chainon (parmtypes, last); + } + if (last) + TREE_CHAIN (last) = void_list_node; + else + parmtypes = void_list_node; + + if (is_overloaded_fn (fnname)) + { + functions = fnname; + if (TREE_CODE (fnname) == TREE_LIST) + fnname = TREE_PURPOSE (functions); + else if (TREE_CODE (fnname) == FUNCTION_DECL) + fnname = DECL_NAME (functions); + } + else + functions = lookup_name_nonclass (fnname); + + if (functions == NULL_TREE) + { + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + if (flags & LOOKUP_COMPLAIN) + error ("only member functions apply"); + if (final_cp) + final_cp->h.code = EVIL_CODE; + return error_mark_node; + } + + if (TREE_CODE (functions) == FUNCTION_DECL && ! IDENTIFIER_OPNAME_P (fnname)) + { + functions = DECL_MAIN_VARIANT (functions); + if (final_cp) + { + /* We are just curious whether this is a viable alternative or + not. */ + compute_conversion_costs (functions, parms, final_cp, parmlength); + return functions; + } + else + return build_function_call_real (functions, parms, 1, flags); + } + + if (TREE_CODE (functions) == TREE_LIST + && TREE_VALUE (functions) == NULL_TREE) + { + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + + if (flags & LOOKUP_COMPLAIN) + cp_error ("function `%D' declared overloaded, but no instances of that function declared", + TREE_PURPOSE (functions)); + if (final_cp) + final_cp->h.code = EVIL_CODE; + return error_mark_node; + } + + length = count_functions (functions); + + if (final_cp) + candidates = final_cp; + else + { + candidates + = (struct candidate *)alloca ((length+1) * sizeof (struct candidate)); + bzero ((char *) candidates, (length + 1) * sizeof (struct candidate)); + } + + cp = candidates; + + my_friendly_assert (is_overloaded_fn (functions), 169); + + functions = get_first_fn (functions); + + /* OUTER is the list of FUNCTION_DECLS, in a TREE_LIST. */ + for (outer = functions; outer; outer = DECL_CHAIN (outer)) + { + int template_cost = 0; + function = outer; + if (TREE_CODE (function) != FUNCTION_DECL + && ! (TREE_CODE (function) == TEMPLATE_DECL + && ! DECL_TEMPLATE_IS_CLASS (function) + && TREE_CODE (DECL_TEMPLATE_RESULT (function)) == FUNCTION_DECL)) + { + enum tree_code code = TREE_CODE (function); + if (code == TEMPLATE_DECL) + code = TREE_CODE (DECL_TEMPLATE_RESULT (function)); + if (code == CONST_DECL) + cp_error_at + ("enumeral value `%D' conflicts with function of same name", + function); + else if (code == VAR_DECL) + { + if (TREE_STATIC (function)) + cp_error_at + ("variable `%D' conflicts with function of same name", + function); + else + cp_error_at + ("constant field `%D' conflicts with function of same name", + function); + } + else if (code == TYPE_DECL) + continue; + else + my_friendly_abort (2); + error ("at this point in file"); + continue; + } + if (TREE_CODE (function) == TEMPLATE_DECL) + { + int ntparms = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (function)); + tree *targs = (tree *) alloca (sizeof (tree) * ntparms); + int i; + + i = type_unification (DECL_TEMPLATE_PARMS (function), targs, + TYPE_ARG_TYPES (TREE_TYPE (function)), + parms, &template_cost, 0); + if (i == 0) + function = instantiate_template (function, targs); + } + + if (TREE_CODE (function) == TEMPLATE_DECL) + { + /* Unconverted template -- failed match. */ + cp->function = function; + cp->u.bad_arg = -4; + cp->h.code = EVIL_CODE; + } + else + { + struct candidate *cp2; + + /* Check that this decl is not the same as a function that's in + the list due to some template instantiation. */ + cp2 = candidates; + while (cp2 != cp) + if (cp2->function == function) + break; + else + cp2 += 1; + if (cp2->function == function) + continue; + + function = DECL_MAIN_VARIANT (function); + + /* Can't use alloca here, since result might be + passed to calling function. */ + cp->h_len = parmlength; + cp->harshness = (struct harshness_code *) + oballoc ((parmlength + 1) * sizeof (struct harshness_code)); + + compute_conversion_costs (function, parms, cp, parmlength); + + /* Make sure this is clear as well. */ + cp->h.int_penalty += template_cost; + + if ((cp[0].h.code & EVIL_CODE) == 0) + { + cp[1].h.code = EVIL_CODE; + cp++; + } + } + } + + if (cp - candidates) + { + tree rval = error_mark_node; + + /* Leave marker. */ + cp[0].h.code = EVIL_CODE; + if (cp - candidates > 1) + { + struct candidate *best_cp + = ideal_candidate (NULL_TREE, candidates, + cp - candidates, parms, parmlength); + if (best_cp == (struct candidate *)0) + { + if (flags & LOOKUP_COMPLAIN) + { + cp_error ("call of overloaded `%D' is ambiguous", fnname); + print_n_candidates (candidates, cp - candidates); + } + return error_mark_node; + } + else + rval = best_cp->function; + } + else + { + cp -= 1; + if (cp->h.code & EVIL_CODE) + { + if (flags & LOOKUP_COMPLAIN) + error ("type conversion ambiguous"); + } + else + rval = cp->function; + } + + if (final_cp) + return rval; + + return buildxxx ? build_function_call_real (rval, parms, 0, flags) + : build_function_call_real (rval, parms, 1, flags); + } + + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + + if (flags & LOOKUP_COMPLAIN) + report_type_mismatch (cp, parms, "function", + decl_as_string (cp->function, 1)); + + return error_mark_node; +} + +tree +build_overload_call (fnname, parms, flags, final_cp) + tree fnname, parms; + int flags; + struct candidate *final_cp; +{ + return build_overload_call_real (fnname, parms, flags, final_cp, 0); +} + +tree +build_overload_call_maybe (fnname, parms, flags, final_cp) + tree fnname, parms; + int flags; + struct candidate *final_cp; +{ + return build_overload_call_real (fnname, parms, flags, final_cp, 1); +} diff --git a/contrib/gcc/cp/class.c b/contrib/gcc/cp/class.c new file mode 100644 index 00000000000..e2893044f75 --- /dev/null +++ b/contrib/gcc/cp/class.c @@ -0,0 +1,5086 @@ +/* Functions related to building classes and their related objects. + Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "flags.h" +#include "rtl.h" +#include "output.h" + +#include "obstack.h" +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +extern struct obstack permanent_obstack; + +/* This is how we tell when two virtual member functions are really the + same. */ +#define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL)) + +extern void set_class_shadows PROTO ((tree)); + +/* Way of stacking class types. */ +static tree *current_class_base, *current_class_stack; +static int current_class_stacksize; +int current_class_depth; + +struct class_level +{ + /* The previous class level. */ + struct class_level *level_chain; + + /* The class instance variable, as a PARM_DECL. */ + tree decl; + /* The class instance variable, as an object. */ + tree object; + /* The virtual function table pointer + for the class instance variable. */ + tree vtable_decl; + + /* Name of the current class. */ + tree name; + /* Type of the current class. */ + tree type; + + /* Flags for this class level. */ + int this_is_variable; + int memoized_lookups; + int save_memoized; + int unused; +}; + +tree current_class_decl, C_C_D; /* PARM_DECL: the class instance variable */ + +/* The following two can be derived from the previous one */ +tree current_class_name; /* IDENTIFIER_NODE: name of current class */ +tree current_class_type; /* _TYPE: the type of the current class */ +tree previous_class_type; /* _TYPE: the previous type that was a class */ +tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list + when leaving an outermost class scope. */ +static tree get_vfield_name PROTO((tree)); +tree the_null_vtable_entry; + +/* Way of stacking language names. */ +tree *current_lang_base, *current_lang_stack; +int current_lang_stacksize; + +/* Names of languages we recognize. */ +tree lang_name_c, lang_name_cplusplus; +tree current_lang_name; + +char *dont_allow_type_definitions; + +/* When layout out an aggregate type, the size of the + basetypes (virtual and non-virtual) is passed to layout_record + via this node. */ +static tree base_layout_decl; + +/* Variables shared between class.c and call.c. */ + +int n_vtables = 0; +int n_vtable_entries = 0; +int n_vtable_searches = 0; +int n_vtable_elems = 0; +int n_convert_harshness = 0; +int n_compute_conversion_costs = 0; +int n_build_method_call = 0; +int n_inner_fields_searched = 0; + +/* Virtual baseclass things. */ +tree +build_vbase_pointer (exp, type) + tree exp, type; +{ + char *name; + + name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1); + sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type)); + return build_component_ref (exp, get_identifier (name), 0, 0); +} + +/* Is the type of the EXPR, the complete type of the object? + If we are going to be wrong, we must be conservative, and return 0. */ +int +complete_type_p (expr) + tree expr; +{ + tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); + while (1) + { + switch (TREE_CODE (expr)) + { + case SAVE_EXPR: + case INDIRECT_REF: + case ADDR_EXPR: + case NOP_EXPR: + case CONVERT_EXPR: + expr = TREE_OPERAND (expr, 0); + continue; + + case CALL_EXPR: + if (! TREE_HAS_CONSTRUCTOR (expr)) + break; + /* fall through... */ + case VAR_DECL: + case FIELD_DECL: + if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE + && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr))) + && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type) + return 1; + /* fall through... */ + case TARGET_EXPR: + case PARM_DECL: + if (IS_AGGR_TYPE (TREE_TYPE (expr)) + && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type) + return 1; + /* fall through... */ + case PLUS_EXPR: + default: + break; + } + break; + } + return 0; +} + +/* Build multi-level access to EXPR using hierarchy path PATH. + CODE is PLUS_EXPR if we are going with the grain, + and MINUS_EXPR if we are not (in which case, we cannot traverse + virtual baseclass links). + + TYPE is the type we want this path to have on exit. + + ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */ +tree +build_vbase_path (code, type, expr, path, alias_this) + enum tree_code code; + tree type, expr, path; + int alias_this; +{ + register int changed = 0; + tree last = NULL_TREE, last_virtual = NULL_TREE; + int nonnull = 0; + int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull); + tree null_expr = 0, nonnull_expr; + tree basetype; + tree offset = integer_zero_node; + + if (nonnull == 0 && (alias_this && flag_this_is_variable <= 0)) + nonnull = 1; + + /* We need additional logic to convert back to the unconverted type + (the static type of the complete object), and then convert back + to the type we want. Until that is done, or until we can + recognize when that is, we cannot do the short cut logic. (mrs) */ + /* Do this, until we can undo any previous conversions. See net35.C + for a testcase. */ + fixed_type_p = complete_type_p (expr); + + if (!fixed_type_p && TREE_SIDE_EFFECTS (expr)) + expr = save_expr (expr); + nonnull_expr = expr; + + if (BINFO_INHERITANCE_CHAIN (path)) + { + tree reverse_path = NULL_TREE; + + while (path) + { + tree r = copy_node (path); + BINFO_INHERITANCE_CHAIN (r) = reverse_path; + reverse_path = r; + path = BINFO_INHERITANCE_CHAIN (path); + } + path = reverse_path; + } + + basetype = BINFO_TYPE (path); + + while (path) + { + if (TREE_VIA_VIRTUAL (path)) + { + last_virtual = BINFO_TYPE (path); + if (code == PLUS_EXPR) + { + changed = ! fixed_type_p; + + if (changed) + { + extern int flag_assume_nonnull_objects; + tree ind; + + /* We already check for ambiguous things in the caller, just + find a path. */ + if (last) + { + tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0); + nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr); + } + ind = build_indirect_ref (nonnull_expr, NULL_PTR); + nonnull_expr = build_vbase_pointer (ind, last_virtual); + if (nonnull == 0 + && (TREE_CODE (type) == POINTER_TYPE + || !flag_assume_nonnull_objects) + && null_expr == NULL_TREE) + { + null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node); + expr = build (COND_EXPR, build_pointer_type (last_virtual), + build (EQ_EXPR, boolean_type_node, expr, + integer_zero_node), + null_expr, nonnull_expr); + } + } + /* else we'll figure out the offset below. */ + + /* Happens in the case of parse errors. */ + if (nonnull_expr == error_mark_node) + return error_mark_node; + } + else + { + cp_error ("cannot cast up from virtual baseclass `%T'", + last_virtual); + return error_mark_node; + } + } + last = path; + path = BINFO_INHERITANCE_CHAIN (path); + } + /* LAST is now the last basetype assoc on the path. */ + + /* A pointer to a virtual base member of a non-null object + is non-null. Therefore, we only need to test for zeroness once. + Make EXPR the canonical expression to deal with here. */ + if (null_expr) + { + TREE_OPERAND (expr, 2) = nonnull_expr; + TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr); + } + else + expr = nonnull_expr; + + /* If we go through any virtual base pointers, make sure that + casts to BASETYPE from the last virtual base class use + the right value for BASETYPE. */ + if (changed) + { + tree intype = TREE_TYPE (TREE_TYPE (expr)); + if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last)) + { + tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0); + offset = BINFO_OFFSET (binfo); + } + } + else + { + if (last_virtual) + { + offset = BINFO_OFFSET (binfo_member (last_virtual, + CLASSTYPE_VBASECLASSES (basetype))); + offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last)); + } + else + offset = BINFO_OFFSET (last); + } + + if (TREE_INT_CST_LOW (offset)) + { + /* Bash types to make the backend happy. */ + offset = convert (type, offset); + expr = build1 (NOP_EXPR, type, expr); + + /* For multiple inheritance: if `this' can be set by any + function, then it could be 0 on entry to any function. + Preserve such zeroness here. Otherwise, only in the + case of constructors need we worry, and in those cases, + it will be zero, or initialized to some valid value to + which we may add. */ + if (nonnull == 0) + { + if (null_expr) + TREE_TYPE (null_expr) = type; + else + null_expr = build1 (NOP_EXPR, type, integer_zero_node); + if (TREE_SIDE_EFFECTS (expr)) + expr = save_expr (expr); + + return build (COND_EXPR, type, + build (EQ_EXPR, boolean_type_node, expr, integer_zero_node), + null_expr, + build (code, type, expr, offset)); + } + else return build (code, type, expr, offset); + } + + /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may + be used multiple times in initialization of multiple inheritance. */ + if (null_expr) + { + TREE_TYPE (expr) = type; + return expr; + } + else + return build1 (NOP_EXPR, type, expr); +} + +/* Virtual function things. */ + +/* Virtual functions to be dealt with after laying out our base + classes. We do all overrides after we layout virtual base classes. + */ +static tree pending_hard_virtuals; +static int doing_hard_virtuals; + +/* Build an entry in the virtual function table. + DELTA is the offset for the `this' pointer. + PFN is an ADDR_EXPR containing a pointer to the virtual function. + Note that the index (DELTA2) in the virtual function table + is always 0. */ +tree +build_vtable_entry (delta, pfn) + tree delta, pfn; +{ + + if (flag_vtable_thunks) + { + HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta); + extern tree make_thunk (); + if (idelta) + { + pfn = build1 (ADDR_EXPR, vtable_entry_type, + make_thunk (pfn, idelta)); + TREE_READONLY (pfn) = 1; + TREE_CONSTANT (pfn) = 1; + } +#ifdef GATHER_STATISTICS + n_vtable_entries += 1; +#endif + return pfn; + } + else + { + extern int flag_huge_objects; + tree elems = tree_cons (NULL_TREE, delta, + tree_cons (NULL_TREE, integer_zero_node, + build_tree_list (NULL_TREE, pfn))); + tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems); + + /* DELTA is constructed by `size_int', which means it may be an + unsigned quantity on some platforms. Therefore, we cannot use + `int_fits_type_p', because when DELTA is really negative, + `force_fit_type' will make it look like a very large number. */ + + if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node)) + < TREE_INT_CST_LOW (delta)) + || (TREE_INT_CST_LOW (delta) + < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node)))) + if (flag_huge_objects) + sorry ("object size exceeds built-in limit for virtual function table implementation"); + else + sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects"); + + TREE_CONSTANT (entry) = 1; + TREE_STATIC (entry) = 1; + TREE_READONLY (entry) = 1; + +#ifdef GATHER_STATISTICS + n_vtable_entries += 1; +#endif + + return entry; + } +} + +/* Given an object INSTANCE, return an expression which yields the + virtual function corresponding to INDEX. There are many special + cases for INSTANCE which we take care of here, mainly to avoid + creating extra tree nodes when we don't have to. */ +tree +build_vfn_ref (ptr_to_instptr, instance, idx) + tree *ptr_to_instptr, instance; + tree idx; +{ + extern int building_cleanup; + tree vtbl, aref; + tree basetype = TREE_TYPE (instance); + + if (TREE_CODE (basetype) == REFERENCE_TYPE) + basetype = TREE_TYPE (basetype); + + if (instance == C_C_D) + vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), + NULL_PTR); + else + { + if (optimize) + { + /* Try to figure out what a reference refers to, and + access its virtual function table directly. */ + tree ref = NULL_TREE; + + if (TREE_CODE (instance) == INDIRECT_REF + && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE) + ref = TREE_OPERAND (instance, 0); + else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) + ref = instance; + + if (ref && TREE_CODE (ref) == VAR_DECL + && DECL_INITIAL (ref)) + { + tree init = DECL_INITIAL (ref); + + while (TREE_CODE (init) == NOP_EXPR + || TREE_CODE (init) == NON_LVALUE_EXPR) + init = TREE_OPERAND (init, 0); + if (TREE_CODE (init) == ADDR_EXPR) + { + init = TREE_OPERAND (init, 0); + if (IS_AGGR_TYPE (TREE_TYPE (init)) + && (TREE_CODE (init) == PARM_DECL + || TREE_CODE (init) == VAR_DECL)) + instance = init; + } + } + } + + if (IS_AGGR_TYPE (TREE_TYPE (instance)) + && (TREE_CODE (instance) == RESULT_DECL + || TREE_CODE (instance) == PARM_DECL + || TREE_CODE (instance) == VAR_DECL)) + vtbl = TYPE_BINFO_VTABLE (basetype); + else + vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), + NULL_PTR); + } + assemble_external (vtbl); + aref = build_array_ref (vtbl, idx); + + /* Save the intermediate result in a SAVE_EXPR so we don't have to + compute each component of the virtual function pointer twice. */ + if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF) + TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0)); + + if (flag_vtable_thunks) + return aref; + else + { + if (ptr_to_instptr) + *ptr_to_instptr + = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr), + *ptr_to_instptr, + convert (ptrdiff_type_node, + build_component_ref (aref, delta_identifier, 0, 0))); + return build_component_ref (aref, pfn_identifier, 0, 0); + } +} + +/* Return the name of the virtual function table (as an IDENTIFIER_NODE) + for the given TYPE. */ +static tree +get_vtable_name (type) + tree type; +{ + tree type_id = build_typename_overload (type); + char *buf = (char *)alloca (strlen (VTABLE_NAME_FORMAT) + + IDENTIFIER_LENGTH (type_id) + 2); + char *ptr = IDENTIFIER_POINTER (type_id); + int i; + for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ; +#if 0 + /* We don't take off the numbers; prepare_fresh_vtable uses the + DECL_ASSEMBLER_NAME for the type, which includes the number + in `3foo'. If we were to pull them off here, we'd end up with + something like `_vt.foo.3bar', instead of a uniform definition. */ + while (ptr[i] >= '0' && ptr[i] <= '9') + i += 1; +#endif + sprintf (buf, VTABLE_NAME_FORMAT, ptr+i); + return get_identifier (buf); +} + +/* Build a virtual function for type TYPE. + If BINFO is non-NULL, build the vtable starting with the initial + approximation that it is the same as the one which is the head of + the association list. */ +static tree +build_vtable (binfo, type) + tree binfo, type; +{ + tree name = get_vtable_name (type); + tree virtuals, decl; + + if (binfo) + { + virtuals = copy_list (BINFO_VIRTUALS (binfo)); + decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo))); + } + else + { + virtuals = NULL_TREE; + decl = build_decl (VAR_DECL, name, void_type_node); + } + +#ifdef GATHER_STATISTICS + n_vtables += 1; + n_vtable_elems += list_length (virtuals); +#endif + + /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */ + import_export_vtable (decl, type, 0); + + IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl); + /* Initialize the association list for this type, based + on our first approximation. */ + TYPE_BINFO_VTABLE (type) = decl; + TYPE_BINFO_VIRTUALS (type) = virtuals; + + TREE_STATIC (decl) = 1; +#ifndef WRITABLE_VTABLES + /* Make them READONLY by default. (mrs) */ + TREE_READONLY (decl) = 1; +#endif + /* At one time the vtable info was grabbed 2 words at a time. This + fails on sparc unless you have 8-byte alignment. (tiemann) */ + DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node), + DECL_ALIGN (decl)); + + /* Why is this conditional? (mrs) */ + if (binfo && write_virtuals >= 0) + DECL_VIRTUAL_P (decl) = 1; + DECL_CONTEXT (decl) = type; + + binfo = TYPE_BINFO (type); + SET_BINFO_NEW_VTABLE_MARKED (binfo); + return decl; +} + +/* Given a base type PARENT, and a derived type TYPE, build + a name which distinguishes exactly the PARENT member of TYPE's type. + + FORMAT is a string which controls how sprintf formats the name + we have generated. + + For example, given + + class A; class B; class C : A, B; + + it is possible to distinguish "A" from "C's A". And given + + class L; + class A : L; class B : L; class C : A, B; + + it is possible to distinguish "L" from "A's L", and also from + "C's L from A". + + Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the + type, as template have DECL_NAMEs like: X, whereas the + DECL_ASSEMBLER_NAME is set to be something the assembler can handle. + */ +static tree +build_type_pathname (format, parent, type) + char *format; + tree parent, type; +{ + extern struct obstack temporary_obstack; + char *first, *base, *name; + int i; + tree id; + + parent = TYPE_MAIN_VARIANT (parent); + + /* Remember where to cut the obstack to. */ + first = obstack_base (&temporary_obstack); + + /* Put on TYPE+PARENT. */ + obstack_grow (&temporary_obstack, + TYPE_ASSEMBLER_NAME_STRING (type), + TYPE_ASSEMBLER_NAME_LENGTH (type)); +#ifdef JOINER + obstack_1grow (&temporary_obstack, JOINER); +#else + obstack_1grow (&temporary_obstack, '_'); +#endif + obstack_grow0 (&temporary_obstack, + TYPE_ASSEMBLER_NAME_STRING (parent), + TYPE_ASSEMBLER_NAME_LENGTH (parent)); + i = obstack_object_size (&temporary_obstack); + base = obstack_base (&temporary_obstack); + obstack_finish (&temporary_obstack); + + /* Put on FORMAT+TYPE+PARENT. */ + obstack_blank (&temporary_obstack, strlen (format) + i + 1); + name = obstack_base (&temporary_obstack); + sprintf (name, format, base); + id = get_identifier (name); + obstack_free (&temporary_obstack, first); + + return id; +} + +/* Update the rtti info for this class. */ +static void +set_rtti_entry (virtuals, offset, type) + tree virtuals, offset, type; +{ + if (! flag_vtable_thunks) + TREE_VALUE (virtuals) + = build_vtable_entry (offset, + (flag_rtti + ? build_t_desc (type, 0) + : integer_zero_node)); + else + { + tree vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, offset); + TREE_CONSTANT (vfn) = 1; + + TREE_VALUE (virtuals) + = build_vtable_entry (integer_zero_node, vfn); + /* The second slot is for the tdesc pointer when thunks are used. */ + vfn = flag_rtti + ? build_t_desc (type, 0) + : integer_zero_node; + vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, vfn); + TREE_CONSTANT (vfn) = 1; + + TREE_VALUE (TREE_CHAIN (virtuals)) + = build_vtable_entry (integer_zero_node, vfn); + } +} + +/* Give TYPE a new virtual function table which is initialized + with a skeleton-copy of its original initialization. The only + entry that changes is the `delta' entry, so we can really + share a lot of structure. + + FOR_TYPE is the derived type which caused this table to + be needed. + + BINFO is the type association which provided TYPE for FOR_TYPE. */ +static void +prepare_fresh_vtable (binfo, for_type) + tree binfo, for_type; +{ + tree basetype = BINFO_TYPE (binfo); + tree orig_decl = BINFO_VTABLE (binfo); + /* This name is too simplistic. We can have multiple basetypes for + for_type, and we really want different names. (mrs) */ + tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type); + tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl)); + tree path, offset; + int result; + + /* Remember which class this vtable is really for. */ + DECL_CONTEXT (new_decl) = for_type; + + TREE_STATIC (new_decl) = 1; + BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl); + DECL_VIRTUAL_P (new_decl) = 1; +#ifndef WRITABLE_VTABLES + /* Make them READONLY by default. (mrs) */ + TREE_READONLY (new_decl) = 1; +#endif + DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl); + + /* Make fresh virtual list, so we can smash it later. */ + BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo)); + + if (TREE_VIA_VIRTUAL (binfo)) + offset = BINFO_OFFSET (binfo_member (BINFO_TYPE (binfo), + CLASSTYPE_VBASECLASSES (for_type))); + else + offset = BINFO_OFFSET (binfo); + + set_rtti_entry (BINFO_VIRTUALS (binfo), + size_binop (MINUS_EXPR, integer_zero_node, offset), + for_type); + +#ifdef GATHER_STATISTICS + n_vtables += 1; + n_vtable_elems += list_length (BINFO_VIRTUALS (binfo)); +#endif + + /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */ + import_export_vtable (new_decl, for_type, 0); + + if (TREE_VIA_VIRTUAL (binfo)) + my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo), + CLASSTYPE_VBASECLASSES (current_class_type)), + 170); + SET_BINFO_NEW_VTABLE_MARKED (binfo); +} + +/* Access the virtual function table entry that logically + contains BASE_FNDECL. VIRTUALS is the virtual function table's + initializer. We can run off the end, when dealing with virtual + destructors in MI situations, return NULL_TREE in that case. */ +static tree +get_vtable_entry (virtuals, base_fndecl) + tree virtuals, base_fndecl; +{ + unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD + ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)) + & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1)) + : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))); + +#ifdef GATHER_STATISTICS + n_vtable_searches += n; +#endif + + while (n > 0 && virtuals) + { + --n; + virtuals = TREE_CHAIN (virtuals); + } + return virtuals; +} + +/* Put new entry ENTRY into virtual function table initializer + VIRTUALS. + + Also update DECL_VINDEX (FNDECL). */ + +static void +modify_vtable_entry (old_entry_in_list, new_entry, fndecl) + tree old_entry_in_list, new_entry, fndecl; +{ + tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0); + +#ifdef NOTQUITE + cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl), + DECL_ASSEMBLER_NAME (fndecl)); +#endif + TREE_VALUE (old_entry_in_list) = new_entry; + + /* Now assign virtual dispatch information, if unset. */ + /* We can dispatch this, through any overridden base function. */ + if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST) + { + DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl); + DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl); + } +} + +/* Access the virtual function table entry i. VIRTUALS is the virtual + function table's initializer. */ +static tree +get_vtable_entry_n (virtuals, n) + tree virtuals; + unsigned HOST_WIDE_INT n; +{ + while (n > 0) + { + --n; + virtuals = TREE_CHAIN (virtuals); + } + return virtuals; +} + +/* Add a virtual function to all the appropriate vtables for the class + T. DECL_VINDEX(X) should be error_mark_node, if we want to + allocate a new slot in our table. If it is error_mark_node, we + know that no other function from another vtable is overridden by X. + HAS_VIRTUAL keeps track of how many virtuals there are in our main + vtable for the type, and we build upon the PENDING_VIRTUALS list + and return it. */ +static tree +add_virtual_function (pending_virtuals, has_virtual, fndecl, t) + tree pending_virtuals; + int *has_virtual; + tree fndecl; + tree t; /* Structure type. */ +{ + /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely + convert to void *. Make such a conversion here. */ + tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl); + TREE_CONSTANT (vfn) = 1; + +#ifndef DUMB_USER + if (current_class_type == 0) + cp_warning ("internal problem, current_class_type is zero when adding `%D', please report", + fndecl); + if (current_class_type && t != current_class_type) + cp_warning ("internal problem, current_class_type differs when adding `%D', please report", + fndecl); +#endif + + /* If the virtual function is a redefinition of a prior one, + figure out in which base class the new definition goes, + and if necessary, make a fresh virtual function table + to hold that entry. */ + if (DECL_VINDEX (fndecl) == error_mark_node) + { + tree entry; + + if (flag_rtti && *has_virtual == 0) + { + /* CLASSTYPE_RTTI is only used as a Boolean (NULL or not). */ + CLASSTYPE_RTTI (t) = integer_one_node; + } + + /* If we are using thunks, use two slots at the front, one + for the offset pointer, one for the tdesc pointer. */ + if (*has_virtual == 0 && flag_vtable_thunks) + { + *has_virtual = 1; + } + + /* Build a new INT_CST for this DECL_VINDEX. */ + { + static tree index_table[256]; + tree index; + /* We skip a slot for the offset/tdesc entry. */ + int i = ++(*has_virtual); + + if (i >= 256 || index_table[i] == 0) + { + index = build_int_2 (i, 0); + if (i < 256) + index_table[i] = index; + } + else + index = index_table[i]; + + /* Now assign virtual dispatch information. */ + DECL_VINDEX (fndecl) = index; + DECL_CONTEXT (fndecl) = t; + } + entry = build_vtable_entry (integer_zero_node, vfn); + pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals); + } + /* Might already be INTEGER_CST if declared twice in class. We will + give error later or we've already given it. */ + else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST) + { + /* Need an entry in some other virtual function table. + Deal with this after we have laid out our virtual base classes. */ + pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals); + } + return pending_virtuals; +} + +/* Obstack on which to build the vector of class methods. */ +struct obstack class_obstack; +extern struct obstack *current_obstack; + +/* Add method METHOD to class TYPE. This is used when a method + has been defined which did not initially appear in the class definition, + and helps cut down on spurious error messages. + + FIELDS is the entry in the METHOD_VEC vector entry of the class type where + the method should be added. */ +void +add_method (type, fields, method) + tree type, *fields, method; +{ + /* We must make a copy of METHOD here, since we must be sure that + we have exclusive title to this method's DECL_CHAIN. */ + tree decl; + + push_obstacks (&permanent_obstack, &permanent_obstack); + { + decl = copy_node (method); + if (DECL_RTL (decl) == 0 + && (!processing_template_decl + || !uses_template_parms (decl))) + { + make_function_rtl (decl); + DECL_RTL (method) = DECL_RTL (decl); + } + } + + if (fields && *fields) + { + /* Take care not to hide destructor. */ + DECL_CHAIN (decl) = DECL_CHAIN (*fields); + DECL_CHAIN (*fields) = decl; + } + else if (CLASSTYPE_METHOD_VEC (type) == 0) + { + tree method_vec = make_node (TREE_VEC); + if (TYPE_IDENTIFIER (type) == DECL_NAME (decl)) + { + TREE_VEC_ELT (method_vec, 0) = decl; + TREE_VEC_LENGTH (method_vec) = 1; + } + else + { + /* ??? Is it possible for there to have been enough room in the + current chunk for the tree_vec structure but not a tree_vec + plus a tree*? Will this work in that case? */ + obstack_free (current_obstack, method_vec); + obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *)); + TREE_VEC_ELT (method_vec, 1) = decl; + TREE_VEC_LENGTH (method_vec) = 2; + obstack_finish (current_obstack); + } + CLASSTYPE_METHOD_VEC (type) = method_vec; + } + else + { + tree method_vec = CLASSTYPE_METHOD_VEC (type); + int len = TREE_VEC_LENGTH (method_vec); + + /* Adding a new ctor or dtor. This is easy because our + METHOD_VEC always has a slot for such entries. */ + if (TYPE_IDENTIFIER (type) == DECL_NAME (decl)) + { + /* TREE_VEC_ELT (method_vec, 0) = decl; */ + if (decl != TREE_VEC_ELT (method_vec, 0)) + { + DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0); + TREE_VEC_ELT (method_vec, 0) = decl; + } + } + else + { + /* This is trickier. We try to extend the TREE_VEC in-place, + but if that does not work, we copy all its data to a new + TREE_VEC that's large enough. */ + struct obstack *ob = &class_obstack; + tree *end = (tree *)obstack_next_free (ob); + + if (end != TREE_VEC_END (method_vec)) + { + ob = current_obstack; + TREE_VEC_LENGTH (method_vec) += 1; + TREE_VEC_ELT (method_vec, len) = NULL_TREE; + method_vec = copy_node (method_vec); + TREE_VEC_LENGTH (method_vec) -= 1; + } + else + { + tree tmp_vec = (tree) obstack_base (ob); + if (obstack_room (ob) < sizeof (tree)) + { + obstack_blank (ob, sizeof (struct tree_common) + + tree_code_length[(int) TREE_VEC] + * sizeof (char *) + + len * sizeof (tree)); + tmp_vec = (tree) obstack_base (ob); + bcopy ((char *) method_vec, (char *) tmp_vec, + (sizeof (struct tree_common) + + tree_code_length[(int) TREE_VEC] * sizeof (char *) + + (len-1) * sizeof (tree))); + method_vec = tmp_vec; + } + else + obstack_blank (ob, sizeof (tree)); + } + + obstack_finish (ob); + TREE_VEC_ELT (method_vec, len) = decl; + TREE_VEC_LENGTH (method_vec) = len + 1; + CLASSTYPE_METHOD_VEC (type) = method_vec; + + if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type)) + { + /* ??? May be better to know whether these can be extended? */ + tree baselink_vec = CLASSTYPE_BASELINK_VEC (type); + + TREE_VEC_LENGTH (baselink_vec) += 1; + CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec); + TREE_VEC_LENGTH (baselink_vec) -= 1; + + TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0; + } + } + } + DECL_CONTEXT (decl) = type; + DECL_CLASS_CONTEXT (decl) = type; + + pop_obstacks (); +} + +/* Subroutines of finish_struct. */ + +/* Look through the list of fields for this struct, deleting + duplicates as we go. This must be recursive to handle + anonymous unions. + + FIELD is the field which may not appear anywhere in FIELDS. + FIELD_PTR, if non-null, is the starting point at which + chained deletions may take place. + The value returned is the first acceptable entry found + in FIELDS. + + Note that anonymous fields which are not of UNION_TYPE are + not duplicates, they are just anonymous fields. This happens + when we have unnamed bitfields, for example. */ +static tree +delete_duplicate_fields_1 (field, fields) + tree field, fields; +{ + tree x; + tree prev = 0; + if (DECL_NAME (field) == 0) + { + if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE) + return fields; + + for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x)) + fields = delete_duplicate_fields_1 (x, fields); + return fields; + } + else + { + for (x = fields; x; prev = x, x = TREE_CHAIN (x)) + { + if (DECL_NAME (x) == 0) + { + if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE) + continue; + TYPE_FIELDS (TREE_TYPE (x)) + = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x))); + if (TYPE_FIELDS (TREE_TYPE (x)) == 0) + { + if (prev == 0) + fields = TREE_CHAIN (fields); + else + TREE_CHAIN (prev) = TREE_CHAIN (x); + } + } + else + { + if (DECL_NAME (field) == DECL_NAME (x)) + { + if (TREE_CODE (field) == CONST_DECL + && TREE_CODE (x) == CONST_DECL) + cp_error_at ("duplicate enum value `%D'", x); + else if (TREE_CODE (field) == CONST_DECL + || TREE_CODE (x) == CONST_DECL) + cp_error_at ("duplicate field `%D' (as enum and non-enum)", + x); + else if (TREE_CODE (field) == TYPE_DECL + && TREE_CODE (x) == TYPE_DECL) + cp_error_at ("duplicate nested type `%D'", x); + else if (TREE_CODE (field) == TYPE_DECL + || TREE_CODE (x) == TYPE_DECL) + cp_error_at ("duplicate field `%D' (as type and non-type)", + x); + else + cp_error_at ("duplicate member `%D'", x); + if (prev == 0) + fields = TREE_CHAIN (fields); + else + TREE_CHAIN (prev) = TREE_CHAIN (x); + } + } + } + } + return fields; +} + +static void +delete_duplicate_fields (fields) + tree fields; +{ + tree x; + for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x)) + TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x)); +} + +/* Change the access of FDECL to ACCESS in T. + Return 1 if change was legit, otherwise return 0. */ +static int +alter_access (t, fdecl, access) + tree t; + tree fdecl; + enum access_type access; +{ + tree elem = purpose_member (t, DECL_ACCESS (fdecl)); + if (elem && TREE_VALUE (elem) != (tree)access) + { + if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL) + { + cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl)); + } + else + error ("conflicting access specifications for field `%s', ignored", + IDENTIFIER_POINTER (DECL_NAME (fdecl))); + } + else if (TREE_PRIVATE (fdecl)) + { + if (access != access_private) + cp_error_at ("cannot make private `%D' non-private", fdecl); + goto alter; + } + else if (TREE_PROTECTED (fdecl)) + { + if (access != access_protected) + cp_error_at ("cannot make protected `%D' non-protected", fdecl); + goto alter; + } + /* ARM 11.3: an access declaration may not be used to restrict access + to a member that is accessible in the base class. */ + else if (access != access_public) + cp_error_at ("cannot reduce access of public member `%D'", fdecl); + else if (elem == NULL_TREE) + { + alter: + DECL_ACCESS (fdecl) = tree_cons (t, (tree)access, + DECL_ACCESS (fdecl)); + return 1; + } + return 0; +} + +/* Return the offset to the main vtable for a given base BINFO. */ +tree +get_vfield_offset (binfo) + tree binfo; +{ + return size_binop (PLUS_EXPR, + size_binop (FLOOR_DIV_EXPR, + DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))), + size_int (BITS_PER_UNIT)), + BINFO_OFFSET (binfo)); +} + +/* Get the offset to the start of the original binfo that we derived + this binfo from. If we find TYPE first, return the offset only + that far. The shortened search is useful because the this pointer + on method calling is expected to point to a DECL_CONTEXT (fndecl) + object, and not a baseclass of it. */ +static tree +get_derived_offset (binfo, type) + tree binfo, type; +{ + tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo))); + tree offset2; + int i; + while (BINFO_BASETYPES (binfo) + && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1) + { + tree binfos = BINFO_BASETYPES (binfo); + if (BINFO_TYPE (binfo) == type) + break; + binfo = TREE_VEC_ELT (binfos, i); + } + offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo))); + return size_binop (MINUS_EXPR, offset1, offset2); +} + +/* If FOR_TYPE needs to reinitialize virtual function table pointers + for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST. + Returns BASE_INIT_LIST appropriately modified. */ + +static tree +maybe_fixup_vptrs (for_type, binfo, base_init_list) + tree for_type, binfo, base_init_list; +{ + /* Now reinitialize any slots that don't fall under our virtual + function table pointer. */ + tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)); + while (vfields) + { + tree basetype = VF_NORMAL_VALUE (vfields) + ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields)) + : VF_BASETYPE_VALUE (vfields); + + tree base_binfo = get_binfo (basetype, for_type, 0); + /* Punt until this is implemented. */ + if (1 /* BINFO_MODIFIED (base_binfo) */) + { + tree base_offset = get_vfield_offset (base_binfo); + if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type))) + && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo))) + base_init_list = tree_cons (error_mark_node, base_binfo, + base_init_list); + } + vfields = TREE_CHAIN (vfields); + } + return base_init_list; +} + +/* If TYPE does not have a constructor, then the compiler must + manually deal with all of the initialization this type requires. + + If a base initializer exists only to fill in the virtual function + table pointer, then we mark that fact with the TREE_VIRTUAL bit. + This way, we avoid multiple initializations of the same field by + each virtual function table up the class hierarchy. + + Virtual base class pointers are not initialized here. They are + initialized only at the "top level" of object creation. If we + initialized them here, we would have to skip a lot of work. */ + +static void +build_class_init_list (type) + tree type; +{ + tree base_init_list = NULL_TREE; + tree member_init_list = NULL_TREE; + + /* Since we build member_init_list and base_init_list using + tree_cons, backwards fields the all through work. */ + tree x; + tree binfos = BINFO_BASETYPES (TYPE_BINFO (type)); + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x)) + { + if (TREE_CODE (x) != FIELD_DECL) + continue; + + if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x)) + || DECL_INITIAL (x) != NULL_TREE) + member_init_list = tree_cons (x, type, member_init_list); + } + member_init_list = nreverse (member_init_list); + + /* We will end up doing this last. Need special marker + to avoid infinite regress. */ + if (TYPE_VIRTUAL_P (type)) + { + base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type)); + if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0) + TREE_VALUE (base_init_list) = NULL_TREE; + TREE_ADDRESSABLE (base_init_list) = 1; + } + + /* Each base class which needs to have initialization + of some kind gets to make such requests known here. */ + for (i = n_baseclasses-1; i >= 0; i--) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree blist; + + /* Don't initialize virtual baseclasses this way. */ + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + + if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo))) + { + /* ...and the last shall come first... */ + base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list); + base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list); + continue; + } + + if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE) + /* Nothing to initialize. */ + continue; + + /* ...ditto... */ + base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list); + + /* This is normally true for single inheritance. + The win is we can shrink the chain of initializations + to be done by only converting to the actual type + we are interested in. */ + if (TREE_VALUE (blist) + && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC + && tree_int_cst_equal (BINFO_OFFSET (base_binfo), + BINFO_OFFSET (TREE_VALUE (blist)))) + { + if (base_init_list) + { + /* Does it do more than just fill in a + virtual function table pointer? */ + if (! TREE_ADDRESSABLE (blist)) + base_init_list = build_tree_list (blist, base_init_list); + /* Can we get by just with the virtual function table + pointer that it fills in? */ + else if (TREE_ADDRESSABLE (base_init_list) + && TREE_VALUE (base_init_list) == 0) + base_init_list = blist; + /* Maybe, but it is not obvious as the previous case. */ + else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type)) + { + tree last = tree_last (base_init_list); + while (TREE_VALUE (last) + && TREE_CODE (TREE_VALUE (last)) == TREE_LIST) + last = tree_last (TREE_VALUE (last)); + if (TREE_VALUE (last) == 0) + base_init_list = build_tree_list (blist, base_init_list); + } + } + else + base_init_list = blist; + } + else + { + /* The function expand_aggr_init knows how to do the + initialization of `basetype' without getting + an explicit `blist'. */ + if (base_init_list) + base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list); + else + base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo)); + } + } + + if (base_init_list) + if (member_init_list) + CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list); + else + CLASSTYPE_BASE_INIT_LIST (type) = base_init_list; + else if (member_init_list) + CLASSTYPE_BASE_INIT_LIST (type) = member_init_list; +} + +struct base_info +{ + int has_virtual; + int max_has_virtual; + int n_ancestors; + tree vfield; + tree vfields; + char cant_have_default_ctor; + char cant_have_const_ctor; + char cant_synth_copy_ctor; + char cant_synth_asn_ref; + char no_const_asn_ref; + char needs_virtual_dtor; +}; + +/* Record information about type T derived from its base classes. + Store most of that information in T itself, and place the + remaining information in the struct BASE_INFO. + + Propagate basetype offsets throughout the lattice. Note that the + lattice topped by T is really a pair: it's a DAG that gives the + structure of the derivation hierarchy, and it's a list of the + virtual baseclasses that appear anywhere in the DAG. When a vbase + type appears in the DAG, it's offset is 0, and it's children start + their offsets from that point. When a vbase type appears in the list, + its offset is the offset it has in the hierarchy, and its children's + offsets include that offset in theirs. + + Returns the index of the first base class to have virtual functions, + or -1 if no such base class. + + Note that at this point TYPE_BINFO (t) != t_binfo. */ + +static int +finish_base_struct (t, b, t_binfo) + tree t; + struct base_info *b; + tree t_binfo; +{ + tree binfos = BINFO_BASETYPES (t_binfo); + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + int first_vfn_base_index = -1; + bzero ((char *) b, sizeof (struct base_info)); + + for (i = 0; i < n_baseclasses; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree basetype = BINFO_TYPE (base_binfo); + + /* If the type of basetype is incomplete, then + we already complained about that fact + (and we should have fixed it up as well). */ + if (TYPE_SIZE (basetype) == 0) + { + int j; + /* The base type is of incomplete type. It is + probably best to pretend that it does not + exist. */ + if (i == n_baseclasses-1) + TREE_VEC_ELT (binfos, i) = NULL_TREE; + TREE_VEC_LENGTH (binfos) -= 1; + n_baseclasses -= 1; + for (j = i; j+1 < n_baseclasses; j++) + TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1); + } + + if (TYPE_HAS_INIT_REF (basetype) + && !TYPE_HAS_CONST_INIT_REF (basetype)) + b->cant_have_const_ctor = 1; + if (! TYPE_HAS_INIT_REF (basetype) + || (TYPE_HAS_NONPUBLIC_CTOR (basetype) == 2 + && ! is_friend_type (t, basetype))) + b->cant_synth_copy_ctor = 1; + + if (TYPE_HAS_CONSTRUCTOR (basetype) + && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)) + { + b->cant_have_default_ctor = 1; + if (! TYPE_HAS_CONSTRUCTOR (t)) + { + cp_pedwarn ("base `%T' with only non-default constructor", + basetype); + cp_pedwarn ("in class without a constructor"); + } + } + + if (TYPE_HAS_ASSIGN_REF (basetype) + && !TYPE_HAS_CONST_ASSIGN_REF (basetype)) + b->no_const_asn_ref = 1; + if (! TYPE_HAS_ASSIGN_REF (basetype) + || TYPE_HAS_ABSTRACT_ASSIGN_REF (basetype) + || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype) == 2 + && ! is_friend_type (t, basetype))) + b->cant_synth_asn_ref = 1; + + b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype); + TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype); + TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype); + TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype); + TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype); + + TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype); + TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype); + TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype); + + if (! TREE_VIA_VIRTUAL (base_binfo) +#if 0 + /* This cannot be done, as prepare_fresh_vtable wants to modify + binfos associated with vfields anywhere in the hierarchy, not + just immediate base classes. Due to unsharing, the compiler + might consume 3% more memory on a real program. + */ + && ! BINFO_OFFSET_ZEROP (base_binfo) +#endif + && BINFO_BASETYPES (base_binfo)) + { + tree base_binfos = BINFO_BASETYPES (base_binfo); + tree chain = NULL_TREE; + int j; + + /* Now unshare the structure beneath BASE_BINFO. */ + for (j = TREE_VEC_LENGTH (base_binfos)-1; + j >= 0; j--) + { + tree base_base_binfo = TREE_VEC_ELT (base_binfos, j); + if (! TREE_VIA_VIRTUAL (base_base_binfo)) + TREE_VEC_ELT (base_binfos, j) + = make_binfo (BINFO_OFFSET (base_base_binfo), + base_base_binfo, + BINFO_VTABLE (base_base_binfo), + BINFO_VIRTUALS (base_base_binfo), + chain); + chain = TREE_VEC_ELT (base_binfos, j); + TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo); + TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo); + BINFO_INHERITANCE_CHAIN (chain) = base_binfo; + } + + /* Completely unshare potentially shared data, and + update what is ours. */ + propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo)); + } + + if (! TREE_VIA_VIRTUAL (base_binfo)) + CLASSTYPE_N_SUPERCLASSES (t) += 1; + + if (TYPE_VIRTUAL_P (basetype)) + { + /* If there's going to be a destructor needed, make + sure it will be virtual. */ + b->needs_virtual_dtor = 1; + + /* Don't borrow virtuals from virtual baseclasses. */ + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + + if (first_vfn_base_index < 0) + { + tree vfields; + first_vfn_base_index = i; + + /* Update these two, now that we know what vtable we are + going to extend. This is so that we can add virtual + functions, and override them properly. */ + BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype); + BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype); + b->has_virtual = CLASSTYPE_VSIZE (basetype); + b->vfield = CLASSTYPE_VFIELD (basetype); + b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype)); + vfields = b->vfields; + while (vfields) + { + if (VF_BINFO_VALUE (vfields) == NULL_TREE + || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields))) + { + tree value = VF_BASETYPE_VALUE (vfields); + if (DECL_NAME (CLASSTYPE_VFIELD (value)) + == DECL_NAME (CLASSTYPE_VFIELD (basetype))) + VF_NORMAL_VALUE (b->vfields) = basetype; + else + VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields); + } + vfields = TREE_CHAIN (vfields); + } + CLASSTYPE_VFIELD (t) = b->vfield; + } + else + { + /* Only add unique vfields, and flatten them out as we go. */ + tree vfields = CLASSTYPE_VFIELDS (basetype); + while (vfields) + { + if (VF_BINFO_VALUE (vfields) == NULL_TREE + || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields))) + { + tree value = VF_BASETYPE_VALUE (vfields); + b->vfields = tree_cons (base_binfo, value, b->vfields); + if (DECL_NAME (CLASSTYPE_VFIELD (value)) + == DECL_NAME (CLASSTYPE_VFIELD (basetype))) + VF_NORMAL_VALUE (b->vfields) = basetype; + else + VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields); + } + vfields = TREE_CHAIN (vfields); + } + + if (b->has_virtual == 0) + { + first_vfn_base_index = i; + + /* Update these two, now that we know what vtable we are + going to extend. This is so that we can add virtual + functions, and override them properly. */ + BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype); + BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype); + b->has_virtual = CLASSTYPE_VSIZE (basetype); + b->vfield = CLASSTYPE_VFIELD (basetype); + CLASSTYPE_VFIELD (t) = b->vfield; + /* When we install the first one, set the VF_NORMAL_VALUE + to be the current class, as this it is the most derived + class. Hopefully, this is not set to something else + later. (mrs) */ + vfields = b->vfields; + while (vfields) + { + if (DECL_NAME (CLASSTYPE_VFIELD (t)) + == DECL_NAME (CLASSTYPE_VFIELD (basetype))) + { + VF_NORMAL_VALUE (vfields) = t; + /* There should only be one of them! And it should + always be found, if we get into here. (mrs) */ + break; + } + vfields = TREE_CHAIN (vfields); + } + } + } + } + } + + /* Must come after offsets are fixed for all bases. */ + for (i = 0; i < n_baseclasses; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree basetype = BINFO_TYPE (base_binfo); + + if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2) + { + cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity", + basetype, t); + b->cant_synth_asn_ref = 1; + b->cant_synth_copy_ctor = 1; + } + } + { + tree v = get_vbase_types (t_binfo); + + for (; v; v = TREE_CHAIN (v)) + { + tree basetype = BINFO_TYPE (v); + if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2) + { + if (extra_warnings) + cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity", + basetype, t); + b->cant_synth_asn_ref = 1; + b->cant_synth_copy_ctor = 1; + } + } + } + + { + tree vfields; + /* Find the base class with the largest number of virtual functions. */ + for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields)) + { + if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual) + b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)); + if (VF_DERIVED_VALUE (vfields) + && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual) + b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)); + } + } + + if (b->vfield == 0) + /* If all virtual functions come only from virtual baseclasses. */ + return -1; + return first_vfn_base_index; +} + +static int +typecode_p (type, code) + tree type; + enum tree_code code; +{ + return (TREE_CODE (type) == code + || (TREE_CODE (type) == REFERENCE_TYPE + && TREE_CODE (TREE_TYPE (type)) == code)); +} + +/* Set memoizing fields and bits of T (and its variants) for later use. + MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */ +static void +finish_struct_bits (t, max_has_virtual) + tree t; + int max_has_virtual; +{ + int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); + tree method_vec = CLASSTYPE_METHOD_VEC (t); + + /* Fix up variants (if any). */ + tree variants = TYPE_NEXT_VARIANT (t); + while (variants) + { + /* These fields are in the _TYPE part of the node, not in + the TYPE_LANG_SPECIFIC component, so they are not shared. */ + TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t); + TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t); + TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t); + TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t); + + TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t); + TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t); + TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t); + /* Copy whatever these are holding today. */ + TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t); + TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t); + variants = TYPE_NEXT_VARIANT (variants); + } + + if (n_baseclasses && max_has_virtual) + { + /* Done by `finish_struct' for classes without baseclasses. */ + int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0; + tree binfos = TYPE_BINFO_BASETYPES (t); + for (i = n_baseclasses-1; i >= 0; i--) + { + might_have_abstract_virtuals + |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0); + if (might_have_abstract_virtuals) + break; + } + if (might_have_abstract_virtuals) + { + /* We use error_mark_node from override_one_vtable to signal + an artificial abstract. */ + if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node) + CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE; + CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t); + } + } + + if (n_baseclasses) + { + /* Notice whether this class has type conversion functions defined. */ + tree binfo = TYPE_BINFO (t); + tree binfos = BINFO_BASETYPES (binfo); + tree basetype; + + for (i = n_baseclasses-1; i >= 0; i--) + { + basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); + + if (TYPE_HAS_CONVERSION (basetype)) + { + TYPE_HAS_CONVERSION (t) = 1; + TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype); + TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype); + } + if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t)) + CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1; + } + } + + /* If this type has a copy constructor, force its mode to be BLKmode, and + force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to + be passed by invisible reference and prevent it from being returned in + a register. */ + if (! TYPE_HAS_TRIVIAL_INIT_REF (t)) + { + tree variants; + if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL) + DECL_MODE (TYPE_NAME (t)) = BLKmode; + for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants)) + { + TYPE_MODE (variants) = BLKmode; + TREE_ADDRESSABLE (variants) = 1; + } + } +} + +/* Add FN to the method_vec growing on the class_obstack. Used by + finish_struct_methods. */ +static void +grow_method (fn, method_vec_ptr) + tree fn; + tree *method_vec_ptr; +{ + tree method_vec = (tree)obstack_base (&class_obstack); + tree *testp = &TREE_VEC_ELT (method_vec, 0); + if (*testp == NULL_TREE) + testp++; + while (((HOST_WIDE_INT) testp + < (HOST_WIDE_INT) obstack_next_free (&class_obstack)) + && DECL_NAME (*testp) != DECL_NAME (fn)) + testp++; + if ((HOST_WIDE_INT) testp + < (HOST_WIDE_INT) obstack_next_free (&class_obstack)) + { + tree x, prev_x; + + for (x = *testp; x; x = DECL_CHAIN (x)) + { + if (DECL_NAME (fn) == ansi_opname[(int) DELETE_EXPR] + || DECL_NAME (fn) == ansi_opname[(int) VEC_DELETE_EXPR]) + { + /* ANSI C++ June 5 1992 WP 12.5.5.1 */ + cp_error_at ("`%D' overloaded", fn); + cp_error_at ("previous declaration as `%D' here", x); + } + if (DECL_ASSEMBLER_NAME (fn)==DECL_ASSEMBLER_NAME (x)) + { + /* We complain about multiple destructors on sight, + so we do not repeat the warning here. Friend-friend + ambiguities are warned about outside this loop. */ + if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn))) + cp_error_at ("ambiguous method `%#D' in structure", fn); + break; + } + prev_x = x; + } + if (x == 0) + { + if (*testp) + DECL_CHAIN (prev_x) = fn; + else + *testp = fn; + } + } + else + { + obstack_ptr_grow (&class_obstack, fn); + *method_vec_ptr = (tree)obstack_base (&class_obstack); + } +} + +/* Warn about duplicate methods in fn_fields. Also compact method + lists so that lookup can be made faster. + + Algorithm: Outer loop builds lists by method name. Inner loop + checks for redundant method names within a list. + + Data Structure: List of method lists. The outer list is a + TREE_LIST, whose TREE_PURPOSE field is the field name and the + TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN + links the entire list of methods for TYPE_METHODS. Friends are + chained in the same way as member functions (? TREE_CHAIN or + DECL_CHAIN), but they live in the TREE_TYPE field of the outer + list. That allows them to be quickly deleted, and requires no + extra storage. + + If there are any constructors/destructors, they are moved to the + front of the list. This makes pushclass more efficient. + + We also link each field which has shares a name with its baseclass + to the head of the list of fields for that base class. This allows + us to reduce search time in places like `build_method_call' to + consider only reasonably likely functions. */ + +static tree +finish_struct_methods (t, fn_fields, nonprivate_method) + tree t; + tree fn_fields; + int nonprivate_method; +{ + tree method_vec; + tree save_fn_fields = tree_cons (NULL_TREE, NULL_TREE, fn_fields); + tree lastp; + tree name = constructor_name (t); + int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); + + /* Now prepare to gather fn_fields into vector. */ + struct obstack *ambient_obstack = current_obstack; + current_obstack = &class_obstack; + method_vec = make_node (TREE_VEC); + /* Room has been saved for constructors and destructors. */ + current_obstack = ambient_obstack; + /* Now make this a live vector. */ + obstack_free (&class_obstack, method_vec); + obstack_blank (&class_obstack, sizeof (struct tree_vec)); + + /* First fill in entry 0 with the constructors, and the next few with + type conversion operators (if any). */ + + for (lastp = save_fn_fields; fn_fields; fn_fields = TREE_CHAIN (lastp)) + { + tree fn_name = DECL_NAME (fn_fields); + if (fn_name == NULL_TREE) + fn_name = name; + + /* Clear out this flag. + + @@ Doug may figure out how to break + @@ this with nested classes and friends. */ + DECL_IN_AGGR_P (fn_fields) = 0; + + /* Note here that a copy ctor is private, so we don't dare generate + a default copy constructor for a class that has a member + of this type without making sure they have access to it. */ + if (fn_name == name) + { + tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields); + tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; + + if (TREE_CODE (parmtype) == REFERENCE_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t) + { + if (TREE_CHAIN (parmtypes) == NULL_TREE + || TREE_CHAIN (parmtypes) == void_list_node + || TREE_PURPOSE (TREE_CHAIN (parmtypes))) + { + if (TREE_PROTECTED (fn_fields)) + TYPE_HAS_NONPUBLIC_CTOR (t) = 1; + else if (TREE_PRIVATE (fn_fields)) + TYPE_HAS_NONPUBLIC_CTOR (t) = 2; + } + } + /* Constructors are handled easily in search routines. */ + DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0); + TREE_VEC_ELT (method_vec, 0) = fn_fields; + } + else if (IDENTIFIER_TYPENAME_P (fn_name)) + { + tree return_type = TREE_TYPE (TREE_TYPE (fn_fields)); + + if (typecode_p (return_type, INTEGER_TYPE) + || typecode_p (return_type, BOOLEAN_TYPE) + || typecode_p (return_type, ENUMERAL_TYPE)) + TYPE_HAS_INT_CONVERSION (t) = 1; + else if (typecode_p (return_type, REAL_TYPE)) + TYPE_HAS_REAL_CONVERSION (t) = 1; + + grow_method (fn_fields, &method_vec); + } + else + { + lastp = fn_fields; + continue; + } + + TREE_CHAIN (lastp) = TREE_CHAIN (fn_fields); + TREE_CHAIN (fn_fields) = NULL_TREE; + } + + fn_fields = TREE_CHAIN (save_fn_fields); + while (fn_fields) + { + tree nextp; + tree fn_name = DECL_NAME (fn_fields); + if (fn_name == NULL_TREE) + fn_name = name; + + nextp = TREE_CHAIN (fn_fields); + TREE_CHAIN (fn_fields) = NULL_TREE; + + if (fn_name == ansi_opname[(int) MODIFY_EXPR]) + { + tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields)); + + if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields))) + { + if (TREE_PROTECTED (fn_fields)) + TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1; + else if (TREE_PRIVATE (fn_fields)) + TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2; + } + } + + grow_method (fn_fields, &method_vec); + fn_fields = nextp; + } + + TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack) + - (&TREE_VEC_ELT (method_vec, 0)); + obstack_finish (&class_obstack); + CLASSTYPE_METHOD_VEC (t) = method_vec; + + if (nonprivate_method == 0 + && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE + && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE) + { + tree binfos = BINFO_BASETYPES (TYPE_BINFO (t)); + for (i = 0; i < n_baseclasses; i++) + if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i)) + || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i))) + { + nonprivate_method = 1; + break; + } + if (nonprivate_method == 0) + cp_warning ("all member functions in class `%T' are private", t); + } + + /* If there are constructors (and destructors), they are at the + front. Place destructors at very front. Also warn if all + constructors and/or destructors are private (in which case this + class is effectively unusable. */ + if (TYPE_HAS_DESTRUCTOR (t)) + { + tree dtor, prev; + + for (dtor = TREE_VEC_ELT (method_vec, 0); + dtor; + prev = dtor, dtor = DECL_CHAIN (dtor)) + { + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor))) + { + if (TREE_PRIVATE (dtor) + && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE + && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE + && warn_ctor_dtor_privacy) + cp_warning ("`%#T' only defines a private destructor and has no friends", + t); + break; + } + } + + /* Wild parse errors can cause this to happen. */ + if (dtor == NULL_TREE) + TYPE_HAS_DESTRUCTOR (t) = 0; + else if (dtor != TREE_VEC_ELT (method_vec, 0)) + { + DECL_CHAIN (prev) = DECL_CHAIN (dtor); + DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0); + TREE_VEC_ELT (method_vec, 0) = dtor; + } + } + + /* Now for each member function (except for constructors and + destructors), compute where member functions of the same + name reside in base classes. */ + if (n_baseclasses != 0 + && TREE_VEC_LENGTH (method_vec) > 1) + { + int len = TREE_VEC_LENGTH (method_vec); + tree baselink_vec = make_tree_vec (len); + int any_links = 0; + tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t)); + + for (i = 1; i < len; i++) + { + TREE_VEC_ELT (baselink_vec, i) + = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i))); + if (TREE_VEC_ELT (baselink_vec, i) != 0) + any_links = 1; + } + if (any_links != 0) + CLASSTYPE_BASELINK_VEC (t) = baselink_vec; + else + obstack_free (current_obstack, baselink_vec); + } + + /* Now add the methods to the TYPE_METHODS of T, arranged in a chain. */ + { + tree x, last_x = NULL_TREE; + int limit = TREE_VEC_LENGTH (method_vec); + + for (i = 1; i < limit; i++) + { + for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x)) + { + if (last_x != NULL_TREE) + TREE_CHAIN (last_x) = x; + last_x = x; + } + } + + /* Put ctors and dtors at the front of the list. */ + x = TREE_VEC_ELT (method_vec, 0); + if (x) + { + while (DECL_CHAIN (x)) + { + /* Let's avoid being circular about this. */ + if (x == DECL_CHAIN (x)) + break; + TREE_CHAIN (x) = DECL_CHAIN (x); + x = DECL_CHAIN (x); + } + if (TREE_VEC_LENGTH (method_vec) > 1) + TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1); + else + TREE_CHAIN (x) = NULL_TREE; + } + } + + TYPE_METHODS (t) = method_vec; + + return method_vec; +} + +/* Emit error when a duplicate definition of a type is seen. Patch up. */ + +void +duplicate_tag_error (t) + tree t; +{ + cp_error ("redefinition of `%#T'", t); + cp_error_at ("previous definition here", t); + + /* Pretend we haven't defined this type. */ + + /* All of the component_decl's were TREE_CHAINed together in the parser. + finish_struct_methods walks these chains and assembles all methods with + the same base name into DECL_CHAINs. Now we don't need the parser chains + anymore, so we unravel them. + */ + /* + * This used to be in finish_struct, but it turns out that the + * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things... + */ + if (CLASSTYPE_METHOD_VEC(t)) + { + tree tv = CLASSTYPE_METHOD_VEC(t); + int i, len = TREE_VEC_LENGTH (tv); + for (i = 0; i < len; i++) + { + tree unchain = TREE_VEC_ELT (tv, i); + while (unchain != NULL_TREE) + { + TREE_CHAIN (unchain) = NULL_TREE; + unchain = DECL_CHAIN(unchain); + } + } + } + + if (TYPE_LANG_SPECIFIC (t)) + { + tree as_list = CLASSTYPE_AS_LIST (t); + tree binfo = TYPE_BINFO (t); + tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t); + int interface_only = CLASSTYPE_INTERFACE_ONLY (t); + int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t); + + bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type)); + BINFO_BASETYPES(binfo) = NULL_TREE; + + CLASSTYPE_AS_LIST (t) = as_list; + TYPE_BINFO (t) = binfo; + CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list; + CLASSTYPE_INTERFACE_ONLY (t) = interface_only; + SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); + CLASSTYPE_VBASE_SIZE (t) = integer_zero_node; + TYPE_REDEFINED (t) = 1; + } + TYPE_SIZE (t) = NULL_TREE; + TYPE_MODE (t) = VOIDmode; + TYPE_FIELDS (t) = NULL_TREE; + TYPE_METHODS (t) = NULL_TREE; + TYPE_VFIELD (t) = NULL_TREE; + TYPE_CONTEXT (t) = NULL_TREE; +} + +/* finish up all new vtables. */ +static void +finish_vtbls (binfo, do_self, t) + tree binfo, t; + int do_self; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + if (BINFO_NEW_VTABLE_MARKED (binfo)) + { + tree decl, context; + + decl = BINFO_VTABLE (binfo); + context = DECL_CONTEXT (decl); + DECL_CONTEXT (decl) = 0; + if (write_virtuals >= 0 + && DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo)) + DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE, + BINFO_VIRTUALS (binfo)); + cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0); + DECL_CONTEXT (decl) = context; + } + CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); + } + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (TREE_VIA_VIRTUAL (base_binfo)) + { + base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t)); + } + finish_vtbls (base_binfo, is_not_base_vtable, t); + } +} + +/* True if we should override the given BASE_FNDECL with the given + FNDECL. */ +static int +overrides (fndecl, base_fndecl) + tree fndecl, base_fndecl; +{ + /* Destructors have special names. */ + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) && + DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) + return 1; + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) || + DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) + return 0; + if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)) + { + tree rettype, base_rettype, types, base_types; +#if 0 + retypes = TREE_TYPE (TREE_TYPE (fndecl)); + base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl)); +#endif + types = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl)); + if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types))) + == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types)))) + && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types), 3)) + return 1; + } + return 0; +} + +static tree +get_class_offset_1 (parent, binfo, context, t, fndecl) + tree parent, binfo, context, t, fndecl; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + tree rval = NULL_TREE; + + if (binfo == parent) + return error_mark_node; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree nrval; + + if (TREE_VIA_VIRTUAL (base_binfo)) + base_binfo = binfo_member (BINFO_TYPE (base_binfo), + CLASSTYPE_VBASECLASSES (t)); + nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl); + /* See if we have a new value */ + if (nrval && (nrval != error_mark_node || rval==0)) + { + /* Only compare if we have two offsets */ + if (rval && rval != error_mark_node + && ! tree_int_cst_equal (nrval, rval)) + { + /* Only give error if the two offsets are different */ + error ("every virtual function must have a unique final overrider"); + cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t); + cp_error (" with virtual `%D' from virtual base class", fndecl); + return rval; + } + rval = nrval; + } + + if (rval && BINFO_TYPE (binfo) == context) + { + my_friendly_assert (rval == error_mark_node + || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999); + rval = BINFO_OFFSET (binfo); + } + } + return rval; +} + +/* Get the offset to the CONTEXT subobject that is related to the + given BINFO. */ +static tree +get_class_offset (context, t, binfo, fndecl) + tree context, t, binfo, fndecl; +{ + tree first_binfo = binfo; + tree offset; + int i; + + if (context == t) + return integer_zero_node; + + if (BINFO_TYPE (binfo) == context) + return BINFO_OFFSET (binfo); + + /* Check less derived binfos first. */ + while (BINFO_BASETYPES (binfo) + && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1) + { + tree binfos = BINFO_BASETYPES (binfo); + binfo = TREE_VEC_ELT (binfos, i); + if (BINFO_TYPE (binfo) == context) + return BINFO_OFFSET (binfo); + } + + /* Ok, not found in the less derived binfos, now check the more + derived binfos. */ + offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl); + if (offset==0 || TREE_CODE (offset) != INTEGER_CST) + my_friendly_abort (999); /* we have to find it. */ + return offset; +} + +/* Skip RTTI information at the front of the virtual list. */ +unsigned HOST_WIDE_INT +skip_rtti_stuff (virtuals) + tree *virtuals; +{ + int n; + + n = 0; + if (*virtuals) + { + /* We always reserve a slot for the offset/tdesc entry. */ + ++n; + *virtuals = TREE_CHAIN (*virtuals); + } + if (flag_vtable_thunks && *virtuals) + { + /* The second slot is reserved for the tdesc pointer when thunks + are used. */ + ++n; + *virtuals = TREE_CHAIN (*virtuals); + } + return n; +} + +static void +modify_one_vtable (binfo, t, fndecl, pfn) + tree binfo, t, fndecl, pfn; +{ + tree virtuals = BINFO_VIRTUALS (binfo); + tree old_rtti; + unsigned HOST_WIDE_INT n; + + /* update rtti entry */ + if (flag_rtti) + { + if (binfo == TYPE_BINFO (t)) + { + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t); + } + else + { + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + prepare_fresh_vtable (binfo, t); + } + } + if (fndecl == NULL_TREE) + return; + + n = skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree current_fndecl = TREE_VALUE (virtuals); + current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl); + current_fndecl = TREE_OPERAND (current_fndecl, 0); + if (current_fndecl && overrides (fndecl, current_fndecl)) + { + tree base_offset, offset; + tree context = DECL_CLASS_CONTEXT (fndecl); + tree vfield = CLASSTYPE_VFIELD (t); + tree this_offset; + + offset = get_class_offset (context, t, binfo, fndecl); + + /* Find the right offset for the this pointer based on the + base class we just found. We have to take into + consideration the virtual base class pointers that we + stick in before the virtual function table pointer. + + Also, we want just the delta between the most base class + that we derived this vfield from and us. */ + base_offset = size_binop (PLUS_EXPR, + get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)), + BINFO_OFFSET (binfo)); + this_offset = size_binop (MINUS_EXPR, offset, base_offset); + + /* Make sure we can modify the derived association with immunity. */ + if (TREE_USED (binfo)) + my_friendly_assert (0, 999); + + if (binfo == TYPE_BINFO (t)) + { + /* In this case, it is *type*'s vtable we are modifying. + We start with the approximation that it's vtable is that + of the immediate base class. */ + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t); + } + else + { + /* This is our very own copy of `basetype' to play with. + Later, we will fill in all the virtual functions + that override the virtual functions in these base classes + which are not defined by the current type. */ + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + prepare_fresh_vtable (binfo, t); + } + +#ifdef NOTQUITE + cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo))); +#endif + modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n), + build_vtable_entry (this_offset, pfn), + fndecl); + } + ++n; + virtuals = TREE_CHAIN (virtuals); + } +} + +/* These are the ones that are not through virtual base classes. */ +static void +modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn) + tree binfo, t, fndecl, pfn; + int do_self; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + modify_one_vtable (binfo, t, fndecl, pfn); + } + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (! TREE_VIA_VIRTUAL (base_binfo)) + modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn); + } +} + +/* Fixup all the delta entries in this one vtable that need updating. */ +static void +fixup_vtable_deltas1 (binfo, t) + tree binfo, t; +{ + tree virtuals = BINFO_VIRTUALS (binfo); + unsigned HOST_WIDE_INT n; + + n = skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree fndecl = TREE_VALUE (virtuals); + tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl); + tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl); + fndecl = TREE_OPERAND (pfn, 0); + if (fndecl) + { + tree base_offset, offset; + tree context = DECL_CLASS_CONTEXT (fndecl); + tree vfield = CLASSTYPE_VFIELD (t); + tree this_offset; + + offset = get_class_offset (context, t, binfo, fndecl); + + /* Find the right offset for the this pointer based on the + base class we just found. We have to take into + consideration the virtual base class pointers that we + stick in before the virtual function table pointer. + + Also, we want just the delta between the most base class + that we derived this vfield from and us. */ + base_offset = size_binop (PLUS_EXPR, + get_derived_offset (binfo, DECL_CONTEXT (fndecl)), + BINFO_OFFSET (binfo)); + this_offset = size_binop (MINUS_EXPR, offset, base_offset); + + if (! tree_int_cst_equal (this_offset, delta)) + { + /* Make sure we can modify the derived association with immunity. */ + if (TREE_USED (binfo)) + my_friendly_assert (0, 999); + + if (binfo == TYPE_BINFO (t)) + { + /* In this case, it is *type*'s vtable we are modifying. + We start with the approximation that it's vtable is that + of the immediate base class. */ + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t); + } + else + { + /* This is our very own copy of `basetype' to play with. + Later, we will fill in all the virtual functions + that override the virtual functions in these base classes + which are not defined by the current type. */ + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + prepare_fresh_vtable (binfo, t); + } + + modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n), + build_vtable_entry (this_offset, pfn), + fndecl); + } + } + ++n; + virtuals = TREE_CHAIN (virtuals); + } +} + +/* Fixup all the delta entries in all the direct vtables that need updating. + This happens when we have non-overridden virtual functions from a + virtual base class, that are at a different offset, in the new + hierarchy, because the layout of the virtual bases has changed. */ +static void +fixup_vtable_deltas (binfo, init_self, t) + tree binfo, t; + int init_self; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (! TREE_VIA_VIRTUAL (base_binfo)) + fixup_vtable_deltas (base_binfo, is_not_base_vtable, t); + } + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + fixup_vtable_deltas1 (binfo, t); + } +} + +/* These are the ones that are through virtual base classes. */ +static void +modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn) + tree binfo, t, fndecl, pfn; + int do_self, via_virtual; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + modify_one_vtable (binfo, t, fndecl, pfn); + } + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (TREE_VIA_VIRTUAL (base_binfo)) + { + via_virtual = 1; + base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t)); + } + modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn); + } +} + +static void +modify_all_vtables (t, fndecl, vfn) + tree t, fndecl, vfn; +{ + /* Do these first, so that we will make use of any non-virtual class's + vtable, over a virtual classes vtable. */ + modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn); + if (TYPE_USES_VIRTUAL_BASECLASSES (t)) + modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn); +} + +/* Here, we already know that they match in every respect. + All we have to check is where they had their declarations. */ +static int +strictly_overrides (fndecl1, fndecl2) + tree fndecl1, fndecl2; +{ + int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2), + DECL_CLASS_CONTEXT (fndecl1), + 0, (tree *)0); + if (distance == -2 || distance > 0) + return 1; + return 0; +} + +/* Merge overrides for one vtable. + If we want to merge in same function, we are fine. + else + if one has a DECL_CLASS_CONTEXT that is a parent of the + other, than choose the more derived one + else + potentially ill-formed (see 10.3 [class.virtual]) + we have to check later to see if there was an + override in this class. If there was ok, if not + then it is ill-formed. (mrs) + + We take special care to reuse a vtable, if we can. */ +static void +override_one_vtable (binfo, old, t) + tree binfo, old, t; +{ + tree virtuals = BINFO_VIRTUALS (binfo); + tree old_virtuals = BINFO_VIRTUALS (old); + enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED; + + /* If we have already committed to modifying it, then don't try and + reuse another vtable. */ + if (BINFO_NEW_VTABLE_MARKED (binfo)) + choose = NEITHER; + + skip_rtti_stuff (&virtuals); + skip_rtti_stuff (&old_virtuals); + + while (virtuals) + { + tree fndecl = TREE_VALUE (virtuals); + tree old_fndecl = TREE_VALUE (old_virtuals); + fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl); + old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl); + fndecl = TREE_OPERAND (fndecl, 0); + old_fndecl = TREE_OPERAND (old_fndecl, 0); + /* First check to see if they are the same. */ + if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl)) + { + /* No need to do anything. */ + } + else if (strictly_overrides (fndecl, old_fndecl)) + { + if (choose == UNDECIDED) + choose = REUSE_NEW; + else if (choose == REUSE_OLD) + { + choose = NEITHER; + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + { + prepare_fresh_vtable (binfo, t); + override_one_vtable (binfo, old, t); + return; + } + } + } + else if (strictly_overrides (old_fndecl, fndecl)) + { + if (choose == UNDECIDED) + choose = REUSE_OLD; + else if (choose == REUSE_NEW) + { + choose = NEITHER; + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + { + prepare_fresh_vtable (binfo, t); + override_one_vtable (binfo, old, t); + return; + } + TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals); + } + else if (choose == NEITHER) + { + TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals); + } + } + else + { + choose = NEITHER; + if (! BINFO_NEW_VTABLE_MARKED (binfo)) + { + prepare_fresh_vtable (binfo, t); + override_one_vtable (binfo, old, t); + return; + } + { + /* This MUST be overridden, or the class is ill-formed. */ + /* For now, we just make it abstract. */ + tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0); + tree vfn; + + fndecl = copy_node (fndecl); + copy_lang_decl (fndecl); + DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1; + /* Make sure we search for it later. */ + if (! CLASSTYPE_ABSTRACT_VIRTUALS (t)) + CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node; + + vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl); + TREE_CONSTANT (vfn) = 1; + + /* We can use integer_zero_node, as we will will core dump + if this is used anyway. */ + TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn); + } + } + virtuals = TREE_CHAIN (virtuals); + old_virtuals = TREE_CHAIN (old_virtuals); + } + + /* Let's reuse the old vtable. */ + if (choose == REUSE_OLD) + { + BINFO_VTABLE (binfo) = BINFO_VTABLE (old); + BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old); + } +} + +/* Merge in overrides for virtual bases. + BINFO is the hierarchy we want to modify, and OLD has the potential + overrides. */ +static void +merge_overrides (binfo, old, do_self, t) + tree binfo, old, t; + int do_self; +{ + tree binfos = BINFO_BASETYPES (binfo); + tree old_binfos = BINFO_BASETYPES (old); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + override_one_vtable (binfo, old, t); + } + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree old_base_binfo = TREE_VEC_ELT (old_binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (! TREE_VIA_VIRTUAL (base_binfo)) + merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t); + } +} + +extern int interface_only, interface_unknown; + +/* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration + (or C++ class declaration). + + For C++, we must handle the building of derived classes. + Also, C++ allows static class members. The way that this is + handled is to keep the field name where it is (as the DECL_NAME + of the field), and place the overloaded decl in the DECL_FIELD_BITPOS + of the field. layout_record and layout_union will know about this. + + More C++ hair: inline functions have text in their + DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into + meaningful tree structure. After the struct has been laid out, set + things up so that this can happen. + + And still more: virtual functions. In the case of single inheritance, + when a new virtual function is seen which redefines a virtual function + from the base class, the new virtual function is placed into + the virtual function table at exactly the same address that + it had in the base class. When this is extended to multiple + inheritance, the same thing happens, except that multiple virtual + function tables must be maintained. The first virtual function + table is treated in exactly the same way as in the case of single + inheritance. Additional virtual function tables have different + DELTAs, which tell how to adjust `this' to point to the right thing. + + LIST_OF_FIELDLISTS is just that. The elements of the list are + TREE_LIST elements, whose TREE_PURPOSE field tells what access + the list has, and the TREE_VALUE slot gives the actual fields. + + If flag_all_virtual == 1, then we lay all functions into + the virtual function table, as though they were declared + virtual. Constructors do not lay down in the virtual function table. + + If flag_all_virtual == 2, then we lay all functions into + the virtual function table, such that virtual functions + occupy a space by themselves, and then all functions + of the class occupy a space by themselves. This is illustrated + in the following diagram: + + class A; class B : A; + + Class A's vtbl: Class B's vtbl: + -------------------------------------------------------------------- + | A's virtual functions| | B's virtual functions | + | | | (may inherit some from A). | + -------------------------------------------------------------------- + | All of A's functions | | All of A's functions | + | (such as a->A::f). | | (such as b->A::f) | + -------------------------------------------------------------------- + | B's new virtual functions | + | (not defined in A.) | + ------------------------------- + | All of B's functions | + | (such as b->B::f) | + ------------------------------- + + this allows the program to make references to any function, virtual + or otherwise in a type-consistent manner. */ + +tree +finish_struct_1 (t, warn_anon) + tree t; + int warn_anon; +{ + int old; + int round_up_size = 1; + + tree name = TYPE_IDENTIFIER (t); + enum tree_code code = TREE_CODE (t); + tree fields = TYPE_FIELDS (t); + tree fn_fields = CLASSTYPE_METHODS (t); + tree x, last_x, method_vec; + int needs_virtual_dtor; + int all_virtual; + int has_virtual; + int max_has_virtual; + tree pending_virtuals = NULL_TREE; + tree abstract_virtuals = NULL_TREE; + tree vfield; + tree vfields; + int cant_have_default_ctor; + int cant_have_const_ctor; + int cant_synth_copy_ctor; + int cant_synth_asn_ref; + int no_const_asn_ref; + + /* The index of the first base class which has virtual + functions. Only applied to non-virtual baseclasses. */ + int first_vfn_base_index; + + int n_baseclasses; + int any_default_members = 0; + int const_sans_init = 0; + int ref_sans_init = 0; + int nonprivate_method = 0; + tree t_binfo = TYPE_BINFO (t); + tree access_decls = NULL_TREE; + int aggregate = 1; + + if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) + pedwarn ("anonymous class type not used to declare any objects"); + + if (TYPE_SIZE (t)) + { + if (IS_AGGR_TYPE (t)) + cp_error ("redefinition of `%#T'", t); + else + my_friendly_abort (172); + popclass (0); + return t; + } + + if (dont_allow_type_definitions) + { + pedwarn ("types cannot be defined %s", + dont_allow_type_definitions); + } + + GNU_xref_decl (current_function_decl, t); + + /* If this type was previously laid out as a forward reference, + make sure we lay it out again. */ + + TYPE_SIZE (t) = NULL_TREE; + CLASSTYPE_GOT_SEMICOLON (t) = 0; + +#if 0 + /* This is in general too late to do this. I moved the main case up to + left_curly, what else needs to move? */ + if (! IS_SIGNATURE (t)) + { + my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999); + my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999); + } +#endif + +#if 0 + if (flag_rtti) + build_t_desc (t, 0); +#endif + + TYPE_BINFO (t) = NULL_TREE; + + old = suspend_momentary (); + + /* Install struct as DECL_FIELD_CONTEXT of each field decl. + Also process specified field sizes. + Set DECL_FIELD_SIZE to the specified size, or 0 if none specified. + The specified size is found in the DECL_INITIAL. + Store 0 there, except for ": 0" fields (so we can find them + and delete them, below). */ + + if (t_binfo && BINFO_BASETYPES (t_binfo)) + n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo)); + else + n_baseclasses = 0; + + if (n_baseclasses > 0) + { + struct base_info base_info; + + /* If using multiple inheritance, this may cause variants of our + basetypes to be used (instead of their canonical forms). */ + tree vf = layout_basetypes (t, BINFO_BASETYPES (t_binfo)); + last_x = tree_last (vf); + fields = chainon (vf, fields); + + first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo); + /* Remember where we got our vfield from */ + CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index; + has_virtual = base_info.has_virtual; + max_has_virtual = base_info.max_has_virtual; + CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors; + vfield = base_info.vfield; + vfields = base_info.vfields; + cant_have_default_ctor = base_info.cant_have_default_ctor; + cant_have_const_ctor = base_info.cant_have_const_ctor; + cant_synth_copy_ctor = base_info.cant_synth_copy_ctor; + cant_synth_asn_ref = base_info.cant_synth_asn_ref; + no_const_asn_ref = base_info.no_const_asn_ref; + needs_virtual_dtor = base_info.needs_virtual_dtor; + n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo)); + aggregate = 0; + } + else + { + first_vfn_base_index = -1; + has_virtual = 0; + max_has_virtual = has_virtual; + vfield = NULL_TREE; + vfields = NULL_TREE; + last_x = NULL_TREE; + cant_have_default_ctor = 0; + cant_have_const_ctor = 0; + cant_synth_copy_ctor = 0; + cant_synth_asn_ref = 0; + no_const_asn_ref = 0; + needs_virtual_dtor = 0; + } + +#if 0 + /* Both of these should be done before now. */ + if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t) + && ! IS_SIGNATURE (t)) + { + my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999); + my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999); + } +#endif + + /* The three of these are approximations which may later be + modified. Needed at this point to make add_virtual_function + and modify_vtable_entries work. */ + TREE_CHAIN (t_binfo) = TYPE_BINFO (t); + TYPE_BINFO (t) = t_binfo; + CLASSTYPE_VFIELDS (t) = vfields; + CLASSTYPE_VFIELD (t) = vfield; + + if (IS_SIGNATURE (t)) + all_virtual = 0; + else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t)) + all_virtual = 1; + else + all_virtual = 0; + + for (x = CLASSTYPE_METHODS (t); x; x = TREE_CHAIN (x)) + { + GNU_xref_member (current_class_name, x); + + nonprivate_method |= ! TREE_PRIVATE (x); + + /* If this was an evil function, don't keep it in class. */ + if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x))) + continue; + + DECL_CLASS_CONTEXT (x) = t; + + /* Do both of these, even though they're in the same union; + if the insn `r' member and the size `i' member are + different sizes, as on the alpha, the larger of the two + will end up with garbage in it. */ + DECL_SAVED_INSNS (x) = NULL_RTX; + DECL_FIELD_SIZE (x) = 0; + + /* The name of the field is the original field name + Save this in auxiliary field for later overloading. */ + if (DECL_VINDEX (x) + || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x))) + { + pending_virtuals = add_virtual_function (pending_virtuals, + &has_virtual, x, t); + if (DECL_ABSTRACT_VIRTUAL_P (x)) + abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals); + else + TREE_USED (x) = 1; + } + } + + for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x)) + { + GNU_xref_member (current_class_name, x); + + /* Handle access declarations. */ + if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF) + { + tree fdecl = TREE_OPERAND (DECL_NAME (x), 1); + enum access_type access + = TREE_PRIVATE (x) ? access_private : + TREE_PROTECTED (x) ? access_protected : access_public; + + if (last_x) + TREE_CHAIN (last_x) = TREE_CHAIN (x); + else + fields = TREE_CHAIN (x); + + access_decls = tree_cons ((tree) access, fdecl, access_decls); + continue; + } + + last_x = x; + + if (TREE_CODE (x) == TYPE_DECL) + continue; + + /* If we've gotten this far, it's a data member, possibly static, + or an enumerator. */ + + DECL_FIELD_CONTEXT (x) = t; + + /* ``A local class cannot have static data members.'' ARM 9.4 */ + if (current_function_decl && TREE_STATIC (x)) + cp_error_at ("field `%D' in local class cannot be static", x); + + /* Perform error checking that did not get done in + grokdeclarator. */ + if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE) + { + cp_error_at ("field `%D' invalidly declared function type", + x); + TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); + } + else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE) + { + cp_error_at ("field `%D' invalidly declared method type", x); + TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); + } + else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE) + { + cp_error_at ("field `%D' invalidly declared offset type", x); + TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); + } + +#if 0 + if (DECL_NAME (x) == constructor_name (t)) + cant_have_default_ctor = cant_synth_copy_ctor = 1; +#endif + + if (TREE_TYPE (x) == error_mark_node) + continue; + + DECL_SAVED_INSNS (x) = NULL_RTX; + DECL_FIELD_SIZE (x) = 0; + + /* When this goes into scope, it will be a non-local reference. */ + DECL_NONLOCAL (x) = 1; + + if (TREE_CODE (x) == CONST_DECL) + continue; + + if (TREE_CODE (x) == VAR_DECL) + { + if (TREE_CODE (t) == UNION_TYPE) + /* Unions cannot have static members. */ + cp_error_at ("field `%D' declared static in union", x); + + continue; + } + + /* Now it can only be a FIELD_DECL. */ + + if (TREE_PRIVATE (x) || TREE_PROTECTED (x)) + aggregate = 0; + + /* If this is of reference type, check if it needs an init. + Also do a little ANSI jig if necessary. */ + if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE) + { + if (DECL_INITIAL (x) == NULL_TREE) + ref_sans_init = 1; + + /* ARM $12.6.2: [A member initializer list] (or, for an + aggregate, initialization by a brace-enclosed list) is the + only way to initialize nonstatic const and reference + members. */ + cant_synth_asn_ref = 1; + cant_have_default_ctor = 1; + + if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings) + { + if (DECL_NAME (x)) + cp_warning_at ("non-static reference `%#D' in class without a constructor", x); + else + cp_warning_at ("non-static reference in class without a constructor", x); + } + } + + /* If any field is const, the structure type is pseudo-const. */ + if (TREE_READONLY (x)) + { + C_TYPE_FIELDS_READONLY (t) = 1; + if (DECL_INITIAL (x) == NULL_TREE) + const_sans_init = 1; + + /* ARM $12.6.2: [A member initializer list] (or, for an + aggregate, initialization by a brace-enclosed list) is the + only way to initialize nonstatic const and reference + members. */ + cant_synth_asn_ref = 1; + cant_have_default_ctor = 1; + + if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t) + && extra_warnings) + { + if (DECL_NAME (x)) + cp_warning_at ("non-static const member `%#D' in class without a constructor", x); + else + cp_warning_at ("non-static const member in class without a constructor", x); + } + } + else + { + /* A field that is pseudo-const makes the structure + likewise. */ + tree t1 = TREE_TYPE (x); + while (TREE_CODE (t1) == ARRAY_TYPE) + t1 = TREE_TYPE (t1); + if (IS_AGGR_TYPE (t1)) + { + if (C_TYPE_FIELDS_READONLY (t1)) + C_TYPE_FIELDS_READONLY (t) = 1; + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1)) + const_sans_init = 1; + } + } + + /* We set DECL_BIT_FIELD tentatively in grokbitfield. + If the type and width are valid, we'll keep it set. + Otherwise, the flag is cleared. */ + if (DECL_BIT_FIELD (x)) + { + DECL_BIT_FIELD (x) = 0; + /* Invalid bit-field size done by grokfield. */ + /* Detect invalid bit-field type. */ + if (DECL_INITIAL (x) + && ! INTEGRAL_TYPE_P (TREE_TYPE (x))) + { + cp_error_at ("bit-field `%#D' with non-integral type", x); + DECL_INITIAL (x) = NULL; + } + + /* Detect and ignore out of range field width. */ + if (DECL_INITIAL (x)) + { + register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); + + if (width < 0) + { + DECL_INITIAL (x) = NULL; + cp_error_at ("negative width in bit-field `%D'", x); + } + else if (width == 0 && DECL_NAME (x) != 0) + { + DECL_INITIAL (x) = NULL; + cp_error_at ("zero width for bit-field `%D'", x); + } + else if (width + > TYPE_PRECISION (long_long_unsigned_type_node)) + { + /* The backend will dump if you try to use something + too big; avoid that. */ + DECL_INITIAL (x) = NULL; + sorry ("bit-fields larger than %d bits", + TYPE_PRECISION (long_long_unsigned_type_node)); + cp_error_at (" in declaration of `%D'", x); + } + else if (width > TYPE_PRECISION (TREE_TYPE (x)) + && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) + { + cp_warning_at ("width of `%D' exceeds its type", x); + } + else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE + && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)), + TREE_UNSIGNED (TREE_TYPE (x))) > width) + || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)), + TREE_UNSIGNED (TREE_TYPE (x))) > width))) + { + cp_warning_at ("`%D' is too small to hold all values of `%#T'", + x, TREE_TYPE (x)); + } + } + + /* Process valid field width. */ + if (DECL_INITIAL (x)) + { + register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); + + if (width == 0) + { +#ifdef EMPTY_FIELD_BOUNDARY + /* field size 0 => mark following field as "aligned" */ + if (TREE_CHAIN (x)) + DECL_ALIGN (TREE_CHAIN (x)) + = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY); + /* field of size 0 at the end => round up the size. */ + else + round_up_size = EMPTY_FIELD_BOUNDARY; +#endif +#ifdef PCC_BITFIELD_TYPE_MATTERS + DECL_ALIGN (x) = MAX (DECL_ALIGN (x), + TYPE_ALIGN (TREE_TYPE (x))); +#endif + } + else + { + DECL_INITIAL (x) = NULL_TREE; + DECL_FIELD_SIZE (x) = width; + DECL_BIT_FIELD (x) = 1; + /* Traditionally a bit field is unsigned + even if declared signed. */ + if (flag_traditional + && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE) + TREE_TYPE (x) = unsigned_type_node; + } + } + else + /* Non-bit-fields are aligned for their type. */ + DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x))); + } + else + { + tree type = TREE_TYPE (x); + + if (TREE_CODE (type) == ARRAY_TYPE) + type = TREE_TYPE (type); + + if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x) + && ! TYPE_PTRMEMFUNC_P (type)) + { + /* Never let anything with uninheritable virtuals + make it through without complaint. */ + if (CLASSTYPE_ABSTRACT_VIRTUALS (type)) + abstract_virtuals_error (x, type); + + /* Don't let signatures make it through either. */ + if (IS_SIGNATURE (type)) + signature_error (x, type); + + if (code == UNION_TYPE) + { + char *fie = NULL; + if (TYPE_NEEDS_CONSTRUCTING (type)) + fie = "constructor"; + else if (TYPE_NEEDS_DESTRUCTOR (type)) + fie = "destructor"; + else if (TYPE_HAS_REAL_ASSIGNMENT (type)) + fie = "assignment operator"; + if (fie) + cp_error_at ("member `%#D' with %s not allowed in union", x, + fie); + } + else + { + TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type); + TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type); + TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type); + TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type); + } + + if (! TYPE_HAS_INIT_REF (type) + || (TYPE_HAS_NONPUBLIC_CTOR (type) + && ! is_friend (t, type))) + cant_synth_copy_ctor = 1; + else if (!TYPE_HAS_CONST_INIT_REF (type)) + cant_have_const_ctor = 1; + + if (! TYPE_HAS_ASSIGN_REF (type) + || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type) + && ! is_friend (t, type))) + cant_synth_asn_ref = 1; + else if (!TYPE_HAS_CONST_ASSIGN_REF (type)) + no_const_asn_ref = 1; + + if (TYPE_HAS_CONSTRUCTOR (type) + && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type)) + { + cant_have_default_ctor = 1; +#if 0 + /* This is wrong for aggregates. */ + if (! TYPE_HAS_CONSTRUCTOR (t)) + { + if (DECL_NAME (x)) + cp_pedwarn_at ("member `%#D' with only non-default constructor", x); + else + cp_pedwarn_at ("member with only non-default constructor", x); + cp_pedwarn_at ("in class without a constructor", + x); + } +#endif + } + } + if (DECL_INITIAL (x) != NULL_TREE) + { + /* `build_class_init_list' does not recognize + non-FIELD_DECLs. */ + if (code == UNION_TYPE && any_default_members != 0) + cp_error_at ("multiple fields in union `%T' initialized"); + any_default_members = 1; + } + } + } + + /* If this type has any constant members which did not come + with their own initialization, mark that fact here. It is + not an error here, since such types can be saved either by their + constructors, or by fortuitous initialization. */ + CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init; + CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init; + CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals; + + /* Synthesize any needed methods. Note that methods will be synthesized + for anonymous unions; grok_x_components undoes that. */ + + if (! fn_fields) + nonprivate_method = 1; + + if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t) + && !IS_SIGNATURE (t)) + { + /* Here we must cons up a destructor on the fly. */ + tree dtor = cons_up_default_function (t, name, needs_virtual_dtor != 0); + + /* If we couldn't make it work, then pretend we didn't need it. */ + if (dtor == void_type_node) + TYPE_NEEDS_DESTRUCTOR (t) = 0; + else + { + /* Link dtor onto end of fn_fields. */ + + TREE_CHAIN (dtor) = fn_fields; + fn_fields = dtor; + + if (DECL_VINDEX (dtor) == NULL_TREE + && (needs_virtual_dtor + || pending_virtuals != NULL_TREE + || pending_hard_virtuals != NULL_TREE)) + DECL_VINDEX (dtor) = error_mark_node; + if (DECL_VINDEX (dtor)) + pending_virtuals = add_virtual_function (pending_virtuals, + &has_virtual, dtor, t); + nonprivate_method = 1; + } + } + + TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t); + if (flag_rtti && (max_has_virtual > 0 || needs_virtual_dtor) && + has_virtual == 0) + has_virtual = 1; + + TYPE_HAS_COMPLEX_INIT_REF (t) + |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) + || any_default_members); + TYPE_NEEDS_CONSTRUCTING (t) + |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) + || has_virtual || any_default_members || first_vfn_base_index >= 0); + if (! IS_SIGNATURE (t)) + CLASSTYPE_NON_AGGREGATE (t) + = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t); + + /* ARM $12.1: A default constructor will be generated for a class X + only if no constructor has been declared for class X. So we + check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate + one if they declared a constructor in this class. */ + if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor + && ! IS_SIGNATURE (t)) + { + tree default_fn = cons_up_default_function (t, name, 2); + TREE_CHAIN (default_fn) = fn_fields; + fn_fields = default_fn; + } + + /* Create default copy constructor, if needed. */ + if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor + && ! IS_SIGNATURE (t)) + { + /* ARM 12.18: You get either X(X&) or X(const X&), but + not both. --Chip */ + tree default_fn = cons_up_default_function (t, name, + 3 + cant_have_const_ctor); + TREE_CHAIN (default_fn) = fn_fields; + fn_fields = default_fn; + } + + TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t); + TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t); + TYPE_HAS_COMPLEX_ASSIGN_REF (t) + |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t); + + if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref + && ! IS_SIGNATURE (t)) + { + tree default_fn = cons_up_default_function (t, name, + 5 + no_const_asn_ref); + TREE_CHAIN (default_fn) = fn_fields; + fn_fields = default_fn; + } + + if (fn_fields) + { + method_vec = finish_struct_methods (t, fn_fields, nonprivate_method); + + if (TYPE_HAS_CONSTRUCTOR (t) + && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE + && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE) + { + int nonprivate_ctor = 0; + tree ctor; + + for (ctor = TREE_VEC_ELT (method_vec, 0); + ctor; + ctor = DECL_CHAIN (ctor)) + if (! TREE_PRIVATE (ctor)) + { + nonprivate_ctor = 1; + break; + } + + if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy) + cp_warning ("`%#T' only defines private constructors and has no friends", + t); + } + } + else + { + method_vec = 0; + + /* Just in case these got accidentally + filled in by syntax errors. */ + TYPE_HAS_CONSTRUCTOR (t) = 0; + TYPE_HAS_DESTRUCTOR (t) = 0; + } + + { + int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0; + + for (access_decls = nreverse (access_decls); access_decls; + access_decls = TREE_CHAIN (access_decls)) + { + tree fdecl = TREE_VALUE (access_decls); + tree flist = NULL_TREE; + tree name; + enum access_type access = (enum access_type)TREE_PURPOSE(access_decls); + int i = TREE_VEC_ELT (method_vec, 0) ? 0 : 1; + tree tmp; + + if (TREE_CODE (fdecl) == TREE_LIST) + { + flist = fdecl; + fdecl = TREE_VALUE (flist); + } + + name = DECL_NAME (fdecl); + + for (; i < n_methods; i++) + if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name) + { + cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t); + cp_error_at (" because of local method `%#D' with same name", + TREE_VEC_ELT (method_vec, i)); + fdecl = NULL_TREE; + break; + } + + if (! fdecl) + continue; + + for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp)) + if (DECL_NAME (tmp) == name) + { + cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t); + cp_error_at (" because of local field `%#D' with same name", tmp); + fdecl = NULL_TREE; + break; + } + + if (!fdecl) + continue; + + /* Make type T see field decl FDECL with access ACCESS.*/ + if (flist) + { + fdecl = TREE_VALUE (flist); + while (fdecl) + { + if (alter_access (t, fdecl, access) == 0) + break; + fdecl = DECL_CHAIN (fdecl); + } + } + else + alter_access (t, fdecl, access); + } + + } + + if (vfield == NULL_TREE && has_virtual) + { + /* We build this decl with ptr_type_node, and + change the type when we know what it should be. */ + vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t), + ptr_type_node); + /* If you change any of the below, take a look at all the + other VFIELD_BASEs and VTABLE_BASEs in the code, and change + them too. */ + DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE); + CLASSTYPE_VFIELD (t) = vfield; + DECL_VIRTUAL_P (vfield) = 1; + DECL_FIELD_CONTEXT (vfield) = t; + DECL_CLASS_CONTEXT (vfield) = t; + DECL_FCONTEXT (vfield) = t; + DECL_SAVED_INSNS (vfield) = NULL_RTX; + DECL_FIELD_SIZE (vfield) = 0; + DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node); + if (CLASSTYPE_RTTI (t)) + { + /* vfield is always first entry in structure. */ + TREE_CHAIN (vfield) = fields; + fields = vfield; + } + else if (last_x) + { + my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175); + TREE_CHAIN (last_x) = vfield; + last_x = vfield; + } + else + fields = vfield; + vfields = chainon (vfields, CLASSTYPE_AS_LIST (t)); + } + + /* Now DECL_INITIAL is null on all members except for zero-width bit-fields. + And they have already done their work. + + C++: maybe we will support default field initialization some day... */ + + /* Delete all zero-width bit-fields from the front of the fieldlist */ + while (fields && DECL_BIT_FIELD (fields) + && DECL_INITIAL (fields)) + fields = TREE_CHAIN (fields); + /* Delete all such fields from the rest of the fields. */ + for (x = fields; x;) + { + if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x)) + && DECL_INITIAL (TREE_CHAIN (x))) + TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); + else + x = TREE_CHAIN (x); + } + /* Delete all duplicate fields from the fields */ + delete_duplicate_fields (fields); + + /* Catch function/field name conflict. We don't need to do this for a + signature, since it can only contain the fields constructed in + append_signature_fields. */ + if (! IS_SIGNATURE (t)) + { + int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0; + for (x = fields; x; x = TREE_CHAIN (x)) + { + tree name = DECL_NAME (x); + int i = /*TREE_VEC_ELT (method_vec, 0) ? 0 : */ 1; + for (; i < n_methods; ++i) + if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name) + { + cp_error_at ("data member `%#D' conflicts with", x); + cp_error_at ("function member `%#D'", + TREE_VEC_ELT (method_vec, i)); + break; + } + } + } + + /* Now we have the final fieldlist for the data fields. Record it, + then lay out the structure or union (including the fields). */ + + TYPE_FIELDS (t) = fields; + + /* If there's a :0 field at the end, round the size to the + EMPTY_FIELD_BOUNDARY. */ + TYPE_ALIGN (t) = round_up_size; + + /* Pass layout information about base classes to layout_type, if any. */ + if (n_baseclasses) + { + tree pseudo_basetype = TREE_TYPE (base_layout_decl); + + TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t); + TYPE_FIELDS (t) = base_layout_decl; + + TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t); + TYPE_MODE (pseudo_basetype) = TYPE_MODE (t); + TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t); + DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype); + /* Don't re-use old size. */ + DECL_SIZE (base_layout_decl) = NULL_TREE; + } + + layout_type (t); + + { + tree field; + for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field)) + { + if (TREE_STATIC (field)) + continue; + if (TREE_CODE (field) != FIELD_DECL) + continue; + + /* If this field is an anonymous union, + give each union-member the same position as the union has. + + ??? This is a real kludge because it makes the structure + of the types look strange. This feature is only used by + C++, which should have build_component_ref build two + COMPONENT_REF operations, one for the union and one for + the inner field. We set the offset of this field to zero + so that either the old or the correct method will work. + Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are + moved into the type of this field, but nothing seems to break + by doing this. */ + + if (DECL_NAME (field) == NULL_TREE + && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + { + tree uelt = TYPE_FIELDS (TREE_TYPE (field)); + for (; uelt; uelt = TREE_CHAIN (uelt)) + { + if (TREE_CODE (uelt) != FIELD_DECL) + continue; + + if (TREE_PRIVATE (uelt)) + cp_pedwarn_at ("private member `%#D' in anonymous union", + uelt); + else if (TREE_PROTECTED (uelt)) + cp_pedwarn_at ("protected member `%#D' in anonymous union", + uelt); + + DECL_FIELD_CONTEXT (uelt) = DECL_FIELD_CONTEXT (field); + DECL_FIELD_BITPOS (uelt) = DECL_FIELD_BITPOS (field); + } + + DECL_FIELD_BITPOS (field) = integer_zero_node; + } + } + } + + if (n_baseclasses) + TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t)); + + /* C++: do not let empty structures exist. */ + if (integer_zerop (TYPE_SIZE (t))) + TYPE_SIZE (t) = TYPE_SIZE (char_type_node); + + /* Set the TYPE_DECL for this type to contain the right + value for DECL_OFFSET, so that we can use it as part + of a COMPONENT_REF for multiple inheritance. */ + + if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL) + layout_decl (TYPE_NAME (t), 0); + + /* Now fix up any virtual base class types that we left lying + around. We must get these done before we try to lay out the + virtual function table. */ + doing_hard_virtuals = 1; + pending_hard_virtuals = nreverse (pending_hard_virtuals); + + if (TYPE_USES_VIRTUAL_BASECLASSES (t)) + { + tree vbases; + + max_has_virtual = layout_vbasetypes (t, max_has_virtual); + vbases = CLASSTYPE_VBASECLASSES (t); + CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases); + + /* The rtti code should do this. (mrs) */ +#if 0 + while (vbases) + { + /* Update rtti info with offsets for virtual baseclasses. */ + if (flag_rtti && ! BINFO_NEW_VTABLE_MARKED (vbases)) + prepare_fresh_vtable (vbases, t); + vbases = TREE_CHAIN (vbases); + } +#endif + + { + /* Now fixup overrides of all functions in vtables from all + direct or indirect virtual base classes. */ + tree binfos = BINFO_BASETYPES (TYPE_BINFO (t)); + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baseclasses; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree basetype = BINFO_TYPE (base_binfo); + tree vbases; + + vbases = CLASSTYPE_VBASECLASSES (basetype); + while (vbases) + { + merge_overrides (binfo_member (BINFO_TYPE (vbases), + CLASSTYPE_VBASECLASSES (t)), + vbases, 1, t); + vbases = TREE_CHAIN (vbases); + } + } + } + + /* Now fixup any virtual function entries from virtual bases + that have different deltas. */ + vbases = CLASSTYPE_VBASECLASSES (t); + while (vbases) + { + /* We might be able to shorten the amount of work we do by + only doing this for vtables that come from virtual bases + that have differing offsets, but don't want to miss any + entries. */ + fixup_vtable_deltas (vbases, 1, t); + vbases = TREE_CHAIN (vbases); + } + } + + /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we + might need to know it for setting up the offsets in the vtable + (or in thunks) below. */ + if (vfield != NULL_TREE + && DECL_FIELD_CONTEXT (vfield) != t) + { + tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0); + tree offset = BINFO_OFFSET (binfo); + + vfield = copy_node (vfield); + copy_lang_decl (vfield); + + if (! integer_zerop (offset)) + offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT)); + DECL_FIELD_CONTEXT (vfield) = t; + DECL_CLASS_CONTEXT (vfield) = t; + DECL_FIELD_BITPOS (vfield) + = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield)); + CLASSTYPE_VFIELD (t) = vfield; + } + +#ifdef NOTQUITE + cp_warning ("Doing hard virtuals for %T...", t); +#endif + + if (has_virtual > max_has_virtual) + max_has_virtual = has_virtual; + if (max_has_virtual > 0) + TYPE_VIRTUAL_P (t) = 1; + + if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals) + modify_all_vtables (t, NULL_TREE, NULL_TREE); + + while (pending_hard_virtuals) + { + modify_all_vtables (t, + TREE_PURPOSE (pending_hard_virtuals), + TREE_VALUE (pending_hard_virtuals)); + pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals); + } + doing_hard_virtuals = 0; + + /* Under our model of GC, every C++ class gets its own virtual + function table, at least virtually. */ + if (pending_virtuals || (flag_rtti && TYPE_VIRTUAL_P (t))) + { + pending_virtuals = nreverse (pending_virtuals); + /* We must enter these virtuals into the table. */ + if (first_vfn_base_index < 0) + { + /* The first slot is for the rtti offset. */ + pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals); + + /* The second slot is for the tdesc pointer when thunks are used. */ + if (flag_vtable_thunks) + pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals); + + set_rtti_entry (pending_virtuals, integer_zero_node, t); + build_vtable (NULL_TREE, t); + } + else + { + tree offset; + /* Here we know enough to change the type of our virtual + function table, but we will wait until later this function. */ + + if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t))) + build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t); + + offset = get_derived_offset (TYPE_BINFO (t), NULL_TREE); + offset = size_binop (MINUS_EXPR, integer_zero_node, offset); + set_rtti_entry (TYPE_BINFO_VIRTUALS (t), offset, t); + } + + /* If this type has basetypes with constructors, then those + constructors might clobber the virtual function table. But + they don't if the derived class shares the exact vtable of the base + class. */ + + CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1; + } + else if (first_vfn_base_index >= 0) + { + tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index); + /* This class contributes nothing new to the virtual function + table. However, it may have declared functions which + went into the virtual function table "inherited" from the + base class. If so, we grab a copy of those updated functions, + and pretend they are ours. */ + + /* See if we should steal the virtual info from base class. */ + if (TYPE_BINFO_VTABLE (t) == NULL_TREE) + TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo); + if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE) + TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo); + if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo)) + CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1; + } + + if (max_has_virtual || first_vfn_base_index >= 0) + { + CLASSTYPE_VSIZE (t) = has_virtual; + if (first_vfn_base_index >= 0) + { + if (pending_virtuals) + TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t), + pending_virtuals); + } + else if (has_virtual) + { + TYPE_BINFO_VIRTUALS (t) = pending_virtuals; + if (write_virtuals >= 0) + DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1; + } + } + + /* Now lay out the virtual function table. */ + if (has_virtual) + { + tree atype, itype; + + if (TREE_TYPE (vfield) == ptr_type_node) + { + /* We must create a pointer to this table because + the one inherited from base class does not exist. + We will fill in the type when we know what it + should really be. Use `size_int' so values are memoized + in common cases. */ + itype = build_index_type (size_int (has_virtual)); + atype = build_array_type (vtable_entry_type, itype); + layout_type (atype); + TREE_TYPE (vfield) = build_pointer_type (atype); + } + else + { + atype = TREE_TYPE (TREE_TYPE (vfield)); + + if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))) + { + /* We must extend (or create) the boundaries on this array, + because we picked up virtual functions from multiple + base classes. */ + itype = build_index_type (size_int (has_virtual)); + atype = build_array_type (vtable_entry_type, itype); + layout_type (atype); + vfield = copy_node (vfield); + TREE_TYPE (vfield) = build_pointer_type (atype); + } + } + + CLASSTYPE_VFIELD (t) = vfield; + if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype) + { + TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype; + DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0; + layout_decl (TYPE_BINFO_VTABLE (t), 0); + /* At one time the vtable info was grabbed 2 words at a time. This + fails on sparc unless you have 8-byte alignment. (tiemann) */ + DECL_ALIGN (TYPE_BINFO_VTABLE (t)) + = MAX (TYPE_ALIGN (double_type_node), + DECL_ALIGN (TYPE_BINFO_VTABLE (t))); + } + } + else if (first_vfn_base_index >= 0) + CLASSTYPE_VFIELD (t) = vfield; + CLASSTYPE_VFIELDS (t) = vfields; + + finish_struct_bits (t, max_has_virtual); + + /* Complete the rtl for any static member objects of the type we're + working on. */ + for (x = fields; x; x = TREE_CHAIN (x)) + { + if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x) + && TREE_TYPE (x) == t) + { + DECL_MODE (x) = TYPE_MODE (t); + make_decl_rtl (x, NULL, 0); + } + } + + /* Now add the tags, if any, to the list of TYPE_DECLs + defined for this type. */ + if (CLASSTYPE_TAGS (t)) + { + x = CLASSTYPE_TAGS (t); + last_x = tree_last (TYPE_FIELDS (t)); + while (x) + { + tree tag = TYPE_NAME (TREE_VALUE (x)); + + /* Check to see if it is already there. This will be the case if + was do enum { red; } color; */ + if (chain_member (tag, TYPE_FIELDS (t))) + { + x = TREE_CHAIN (x); + continue; + } + +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG) + { + /* Notify dwarfout.c that this TYPE_DECL node represent a + gratuitous typedef. */ + DECL_IGNORED_P (tag) = 1; + } +#endif /* DWARF_DEBUGGING_INFO */ + + TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0; + x = TREE_CHAIN (x); + last_x = chainon (last_x, tag); + } + if (TYPE_FIELDS (t) == NULL_TREE) + TYPE_FIELDS (t) = last_x; + CLASSTYPE_LOCAL_TYPEDECLS (t) = 1; + } + + if (TYPE_HAS_CONSTRUCTOR (t)) + { + tree vfields = CLASSTYPE_VFIELDS (t); + + while (vfields) + { + /* Mark the fact that constructor for T + could affect anybody inheriting from T + who wants to initialize vtables for VFIELDS's type. */ + if (VF_DERIVED_VALUE (vfields)) + TREE_ADDRESSABLE (vfields) = 1; + vfields = TREE_CHAIN (vfields); + } + if (any_default_members != 0) + build_class_init_list (t); + } + else if (TYPE_NEEDS_CONSTRUCTING (t)) + build_class_init_list (t); + + if (! IS_SIGNATURE (t)) + embrace_waiting_friends (t); + + /* Write out inline function definitions. */ + do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t)); + CLASSTYPE_INLINE_FRIENDS (t) = 0; + + if (CLASSTYPE_VSIZE (t) != 0) + { +#if 0 + /* This is now done above. */ + if (DECL_FIELD_CONTEXT (vfield) != t) + { + tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0); + tree offset = BINFO_OFFSET (binfo); + + vfield = copy_node (vfield); + copy_lang_decl (vfield); + + if (! integer_zerop (offset)) + offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT)); + DECL_FIELD_CONTEXT (vfield) = t; + DECL_CLASS_CONTEXT (vfield) = t; + DECL_FIELD_BITPOS (vfield) + = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield)); + CLASSTYPE_VFIELD (t) = vfield; + } +#endif + + /* In addition to this one, all the other vfields should be listed. */ + /* Before that can be done, we have to have FIELD_DECLs for them, and + a place to find them. */ + TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield); + + if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t) + && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE) + cp_warning ("`%#T' has virtual functions but non-virtual destructor", + t); + } + + /* Make the rtl for any new vtables we have created, and unmark + the base types we marked. */ + finish_vtbls (TYPE_BINFO (t), 1, t); + TYPE_BEING_DEFINED (t) = 0; + hack_incomplete_structures (t); + +#if 0 + if (TYPE_NAME (t) && TYPE_IDENTIFIER (t)) + undo_template_name_overload (TYPE_IDENTIFIER (t), 1); +#endif + if (current_class_type) + popclass (0); + else + error ("trying to finish struct, but kicked out due to previous parse errors."); + + resume_momentary (old); + + if (flag_cadillac) + cadillac_finish_struct (t); + +#if 0 + /* This has to be done after we have sorted out what to do with + the enclosing type. */ + if (write_symbols != DWARF_DEBUG) + { + /* Be smarter about nested classes here. If a type is nested, + only output it if we would output the enclosing type. */ + if (DECL_CONTEXT (TYPE_NAME (t)) + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t)))) == 't') + DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t)); + } +#endif + + if (write_symbols != DWARF_DEBUG) + { + /* If the type has methods, we want to think about cutting down + the amount of symbol table stuff we output. The value stored in + the TYPE_DECL's DECL_IGNORED_P slot is a first approximation. + For example, if a member function is seen and we decide to + write out that member function, then we can change the value + of the DECL_IGNORED_P slot, and the type will be output when + that member function's debug info is written out. */ + if (CLASSTYPE_METHOD_VEC (t)) + { + extern tree pending_vtables; + + /* Don't output full info about any type + which does not have its implementation defined here. */ + if (TYPE_VIRTUAL_P (t) && write_virtuals == 2) + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) + = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0); + else if (CLASSTYPE_INTERFACE_ONLY (t)) + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; + else if (CLASSTYPE_INTERFACE_UNKNOWN (t)) + /* Only a first approximation! */ + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; + } + else if (CLASSTYPE_INTERFACE_ONLY (t)) + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; + } + + /* Finish debugging output for this type. */ + rest_of_type_compilation (t, toplevel_bindings_p ()); + + return t; +} + +tree +finish_struct (t, list_of_fieldlists, warn_anon) + tree t; + tree list_of_fieldlists; + int warn_anon; +{ + tree fields = NULL_TREE, fn_fields, *tail; + tree *tail_user_methods = &CLASSTYPE_METHODS (t); + tree name = TYPE_NAME (t); + tree x, last_x = NULL_TREE; + enum access_type access; + + if (TREE_CODE (name) == TYPE_DECL) + { + extern int lineno; + + DECL_SOURCE_FILE (name) = input_filename; + /* For TYPE_DECL that are not typedefs (those marked with a line + number of zero, we don't want to mark them as real typedefs. + If this fails one needs to make sure real typedefs have a + previous line number, even if it is wrong, that way the below + will fill in the right line number. (mrs) */ + if (DECL_SOURCE_LINE (name)) + DECL_SOURCE_LINE (name) = lineno; + CLASSTYPE_SOURCE_LINE (t) = lineno; + name = DECL_NAME (name); + } + + /* Append the fields we need for constructing signature tables. */ + if (IS_SIGNATURE (t)) + append_signature_fields (list_of_fieldlists); + + tail = &fn_fields; + if (last_x && list_of_fieldlists) + TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists); + + /* For signatures, we made all methods `public' in the parser and + reported an error if a access specifier was used. */ + if (CLASSTYPE_DECLARED_CLASS (t) == 0) + { + if (list_of_fieldlists + && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default) + TREE_PURPOSE (list_of_fieldlists) = (tree)access_public; + } + else if (list_of_fieldlists + && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default) + TREE_PURPOSE (list_of_fieldlists) = (tree)access_private; + + while (list_of_fieldlists) + { + access = (enum access_type)TREE_PURPOSE (list_of_fieldlists); + + for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x)) + { + TREE_PRIVATE (x) = access == access_private; + TREE_PROTECTED (x) = access == access_protected; + + /* Check for inconsistent use of this name in the class body. + Enums, types and static vars have already been checked. */ + if (TREE_CODE (x) != TYPE_DECL + && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL) + { + tree name = DECL_NAME (x); + tree icv; + + /* Don't get confused by access decls. */ + if (name && TREE_CODE (name) == IDENTIFIER_NODE) + icv = IDENTIFIER_CLASS_VALUE (name); + else + icv = NULL_TREE; + + if (icv + /* Don't complain about constructors. */ + && name != constructor_name (current_class_type) + /* Or inherited names. */ + && id_in_current_class (name) + /* Or shadowed tags. */ + && !(TREE_CODE (icv) == TYPE_DECL + && DECL_CONTEXT (icv) == t)) + { + cp_error_at ("declaration of identifier `%D' as `%+#D'", + name, x); + cp_error_at ("conflicts with other use in class as `%#D'", + icv); + } + } + + if (TREE_CODE (x) == FUNCTION_DECL) + { + if (last_x) + TREE_CHAIN (last_x) = TREE_CHAIN (x); + /* Link x onto end of fn_fields and CLASSTYPE_METHODS. */ + *tail = x; + tail = &TREE_CHAIN (x); + *tail_user_methods = x; + tail_user_methods = &DECL_NEXT_METHOD (x); + continue; + } + +#if 0 + /* Handle access declarations. */ + if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF) + { + tree n = DECL_NAME (x); + x = build_decl + (USING_DECL, DECL_NAME (TREE_OPERAND (n, 1)), TREE_TYPE (x)); + DECL_RESULT (x) = n; + } +#endif + + if (! fields) + fields = x; + last_x = x; + } + list_of_fieldlists = TREE_CHAIN (list_of_fieldlists); + /* link the tail while we have it! */ + if (last_x) + { + TREE_CHAIN (last_x) = NULL_TREE; + + if (list_of_fieldlists + && TREE_VALUE (list_of_fieldlists) + && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL) + TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists); + } + } + + *tail = NULL_TREE; + *tail_user_methods = NULL_TREE; + TYPE_FIELDS (t) = fields; + + if (0 && processing_template_defn) + { + CLASSTYPE_METHOD_VEC (t) = finish_struct_methods (t, fn_fields, 1); + return t; + } + else + return finish_struct_1 (t, warn_anon); +} + +/* Return non-zero if the effective type of INSTANCE is static. + Used to determine whether the virtual function table is needed + or not. + + *NONNULL is set iff INSTANCE can be known to be nonnull, regardless + of our knowledge of its type. */ +int +resolves_to_fixed_type_p (instance, nonnull) + tree instance; + int *nonnull; +{ + switch (TREE_CODE (instance)) + { + case INDIRECT_REF: + /* Check that we are not going through a cast of some sort. */ + if (TREE_TYPE (instance) + == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0)))) + instance = TREE_OPERAND (instance, 0); + /* fall through... */ + case CALL_EXPR: + /* This is a call to a constructor, hence it's never zero. */ + if (TREE_HAS_CONSTRUCTOR (instance)) + { + if (nonnull) + *nonnull = 1; + return 1; + } + return 0; + + case SAVE_EXPR: + /* This is a call to a constructor, hence it's never zero. */ + if (TREE_HAS_CONSTRUCTOR (instance)) + { + if (nonnull) + *nonnull = 1; + return 1; + } + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + + case RTL_EXPR: + /* This is a call to `new', hence it's never zero. */ + if (TREE_CALLS_NEW (instance)) + { + if (nonnull) + *nonnull = 1; + return 1; + } + return 0; + + case PLUS_EXPR: + case MINUS_EXPR: + if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST) + /* Propagate nonnull. */ + resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + return 0; + + case NOP_EXPR: + case CONVERT_EXPR: + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + + case ADDR_EXPR: + if (nonnull) + *nonnull = 1; + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + + case COMPONENT_REF: + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull); + + case WITH_CLEANUP_EXPR: + if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) + return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); + /* fall through... */ + case VAR_DECL: + case FIELD_DECL: + if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE + && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance)))) + { + if (nonnull) + *nonnull = 1; + return 1; + } + /* fall through... */ + case TARGET_EXPR: + case PARM_DECL: + if (IS_AGGR_TYPE (TREE_TYPE (instance))) + { + if (nonnull) + *nonnull = 1; + return 1; + } + else if (nonnull) + { + if (instance == current_class_decl + && flag_this_is_variable <= 0) + { + /* Some people still use `this = 0' inside destructors. */ + *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl)); + /* In a constructor, we know our type. */ + if (flag_this_is_variable < 0) + return 1; + } + else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) + /* Reference variables should be references to objects. */ + *nonnull = 1; + } + return 0; + + default: + return 0; + } +} + +void +init_class_processing () +{ + current_class_depth = 0; + current_class_stacksize = 10; + current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree)); + current_class_stack = current_class_base; + + current_lang_stacksize = 10; + current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree)); + current_lang_stack = current_lang_base; + + /* Keep these values lying around. */ + the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node); + base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node); + TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE); + + gcc_obstack_init (&class_obstack); +} + +/* Set current scope to NAME. CODE tells us if this is a + STRUCT, UNION, or ENUM environment. + + NAME may end up being NULL_TREE if this is an anonymous or + late-bound struct (as in "struct { ... } foo;") */ + +/* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to + appropriate values, found by looking up the type definition of + NAME (as a CODE). + + If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names + which can be seen locally to the class. They are shadowed by + any subsequent local declaration (including parameter names). + + If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names + which have static meaning (i.e., static members, static + member functions, enum declarations, etc). + + If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names + which can be seen locally to the class (as in 1), but + know that we are doing this for declaration purposes + (i.e. friend foo::bar (int)). + + So that we may avoid calls to lookup_name, we cache the _TYPE + nodes of local TYPE_DECLs in the TREE_TYPE field of the name. + + For multiple inheritance, we perform a two-pass depth-first search + of the type lattice. The first pass performs a pre-order search, + marking types after the type has had its fields installed in + the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely + unmarks the marked types. If a field or member function name + appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of + that name becomes `error_mark_node'. */ + +void +pushclass (type, modify) + tree type; + int modify; +{ + push_memoized_context (type, modify); + + current_class_depth++; + *current_class_stack++ = current_class_name; + *current_class_stack++ = current_class_type; + if (current_class_stack >= current_class_base + current_class_stacksize) + { + current_class_base = + (tree *)xrealloc (current_class_base, + sizeof (tree) * (current_class_stacksize + 10)); + current_class_stack = current_class_base + current_class_stacksize; + current_class_stacksize += 10; + } + + current_class_name = TYPE_NAME (type); + if (TREE_CODE (current_class_name) == TYPE_DECL) + current_class_name = DECL_NAME (current_class_name); + current_class_type = type; + + if (previous_class_type != NULL_TREE + && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE) + && current_class_depth == 1) + { + /* Forcibly remove any old class remnants. */ + popclass (-1); + previous_class_type = NULL_TREE; + } + + pushlevel_class (); + + if (modify) + { + tree tags; + tree this_fndecl = current_function_decl; + + if (current_function_decl + && DECL_CONTEXT (current_function_decl) + && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL) + current_function_decl = DECL_CONTEXT (current_function_decl); + else + current_function_decl = NULL_TREE; + + if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + declare_uninstantiated_type_level (); + else if (type != previous_class_type || current_class_depth > 1) + { + build_mi_matrix (type); + push_class_decls (type); + free_mi_matrix (); + if (current_class_depth == 1) + previous_class_type = type; + } + else + { + tree item; + + /* Hooray, we successfully cached; let's just install the + cached class_shadowed list, and walk through it to get the + IDENTIFIER_TYPE_VALUEs correct. */ + set_class_shadows (previous_class_values); + for (item = previous_class_values; item; item = TREE_CHAIN (item)) + { + tree id = TREE_PURPOSE (item); + tree decl = IDENTIFIER_CLASS_VALUE (id); + + if (TREE_CODE (decl) == TYPE_DECL) + set_identifier_type_value (id, TREE_TYPE (decl)); + } + unuse_fields (type); + } + + if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (type))) + overload_template_name (current_class_name, 0); + + for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags)) + { + TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1; + if (! TREE_PURPOSE (tags)) + continue; + pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0); + } + + current_function_decl = this_fndecl; + } + + if (flag_cadillac) + cadillac_push_class (type); +} + +/* Get out of the current class scope. If we were in a class scope + previously, that is the one popped to. The flag MODIFY tells whether + the current scope declarations needs to be modified as a result of + popping to the previous scope. 0 is used for class definitions. */ +void +popclass (modify) + int modify; +{ + if (flag_cadillac) + cadillac_pop_class (); + + if (modify < 0) + { + /* Back this old class out completely. */ + tree tags = CLASSTYPE_TAGS (previous_class_type); + tree t; + + /* This code can be seen as a cache miss. When we've cached a + class' scope's bindings and we can't use them, we need to reset + them. This is it! */ + for (t = previous_class_values; t; t = TREE_CHAIN (t)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE; + while (tags) + { + TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0; + tags = TREE_CHAIN (tags); + } + goto ret; + } + + if (modify) + { + /* Just remove from this class what didn't make + it into IDENTIFIER_CLASS_VALUE. */ + tree tags = CLASSTYPE_TAGS (current_class_type); + + while (tags) + { + TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0; + tags = TREE_CHAIN (tags); + } + if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type))) + undo_template_name_overload (current_class_name, 0); + } + + /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition, + since not all class decls make it there currently. */ + poplevel_class (! modify); + + /* Since poplevel_class does the popping of class decls nowadays, + this really only frees the obstack used for these decls. + That's why it had to be moved down here. */ + if (modify) + pop_class_decls (current_class_type); + + current_class_depth--; + current_class_type = *--current_class_stack; + current_class_name = *--current_class_stack; + + pop_memoized_context (modify); + + ret: + ; +} + +/* When entering a class scope, all enclosing class scopes' names with + static meaning (static variables, static functions, types and enumerators) + have to be visible. This recursive function calls pushclass for all + enclosing class contexts until global or a local scope is reached. + TYPE is the enclosed class and MODIFY is equivalent with the pushclass + formal of the same name. */ + +void +push_nested_class (type, modify) + tree type; + int modify; +{ + tree context; + + if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)) + return; + + context = DECL_CONTEXT (TYPE_NAME (type)); + + if (context && TREE_CODE (context) == RECORD_TYPE) + push_nested_class (context, 2); + pushclass (type, modify); +} + +/* Undoes a push_nested_class call. MODIFY is passed on to popclass. */ + +void +pop_nested_class (modify) + int modify; +{ + tree context = DECL_CONTEXT (TYPE_NAME (current_class_type)); + + popclass (modify); + if (context && TREE_CODE (context) == RECORD_TYPE) + pop_nested_class (modify); +} + +/* Set global variables CURRENT_LANG_NAME to appropriate value + so that behavior of name-mangling machinery is correct. */ + +void +push_lang_context (name) + tree name; +{ + *current_lang_stack++ = current_lang_name; + if (current_lang_stack >= current_lang_base + current_lang_stacksize) + { + current_lang_base = + (tree *)xrealloc (current_lang_base, + sizeof (tree) * (current_lang_stacksize + 10)); + current_lang_stack = current_lang_base + current_lang_stacksize; + current_lang_stacksize += 10; + } + + if (name == lang_name_cplusplus) + { + strict_prototype = strict_prototypes_lang_cplusplus; + current_lang_name = name; + } + else if (name == lang_name_c) + { + strict_prototype = strict_prototypes_lang_c; + current_lang_name = name; + } + else + error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name)); + + if (flag_cadillac) + cadillac_push_lang (name); +} + +/* Get out of the current language scope. */ +void +pop_lang_context () +{ + if (flag_cadillac) + cadillac_pop_lang (); + + current_lang_name = *--current_lang_stack; + if (current_lang_name == lang_name_cplusplus) + strict_prototype = strict_prototypes_lang_cplusplus; + else if (current_lang_name == lang_name_c) + strict_prototype = strict_prototypes_lang_c; +} + +int +root_lang_context_p () +{ + return current_lang_stack == current_lang_base; +} + +/* Type instantiation routines. */ + +/* This function will instantiate the type of the expression given + in RHS to match the type of LHSTYPE. If LHSTYPE is NULL_TREE, + or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE. + + This function is used in build_modify_expr, convert_arguments, + build_c_cast, and compute_conversion_costs. */ +tree +instantiate_type (lhstype, rhs, complain) + tree lhstype, rhs; + int complain; +{ + if (TREE_CODE (lhstype) == UNKNOWN_TYPE) + { + if (complain) + error ("not enough type information"); + return error_mark_node; + } + + if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs))) + return rhs; + + /* This should really only be used when attempting to distinguish + what sort of a pointer to function we have. For now, any + arithmetic operation which is not supported on pointers + is rejected as an error. */ + + switch (TREE_CODE (rhs)) + { + case TYPE_EXPR: + case CONVERT_EXPR: + case SAVE_EXPR: + case CONSTRUCTOR: + case BUFFER_REF: + my_friendly_abort (177); + return error_mark_node; + + case INDIRECT_REF: + case ARRAY_REF: + TREE_TYPE (rhs) = lhstype; + lhstype = build_pointer_type (lhstype); + TREE_OPERAND (rhs, 0) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); + if (TREE_OPERAND (rhs, 0) == error_mark_node) + return error_mark_node; + + return rhs; + + case NOP_EXPR: + rhs = copy_node (TREE_OPERAND (rhs, 0)); + TREE_TYPE (rhs) = unknown_type_node; + return instantiate_type (lhstype, rhs, complain); + + case COMPONENT_REF: + { + tree field = TREE_OPERAND (rhs, 1); + if (TREE_CODE (field) == TREE_LIST) + { + tree function = instantiate_type (lhstype, field, complain); + if (function == error_mark_node) + return error_mark_node; + my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185); + if (DECL_VINDEX (function)) + { + tree base = TREE_OPERAND (rhs, 0); + tree base_ptr = build_unary_op (ADDR_EXPR, base, 0); + if (base_ptr == error_mark_node) + return error_mark_node; + base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr); + if (base_ptr == error_mark_node) + return error_mark_node; + return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function)); + } + return function; + } + + my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178); + my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE), + 179); + + TREE_TYPE (rhs) = lhstype; + /* First look for an exact match */ + + while (field && TREE_TYPE (field) != lhstype) + field = DECL_CHAIN (field); + if (field) + { + TREE_OPERAND (rhs, 1) = field; + return rhs; + } + + /* No exact match found, look for a compatible function. */ + field = TREE_OPERAND (rhs, 1); + while (field && ! comptypes (lhstype, TREE_TYPE (field), 0)) + field = DECL_CHAIN (field); + if (field) + { + TREE_OPERAND (rhs, 1) = field; + field = DECL_CHAIN (field); + while (field && ! comptypes (lhstype, TREE_TYPE (field), 0)) + field = DECL_CHAIN (field); + if (field) + { + if (complain) + error ("ambiguous overload for COMPONENT_REF requested"); + return error_mark_node; + } + } + else + { + if (complain) + error ("no appropriate overload exists for COMPONENT_REF"); + return error_mark_node; + } + return rhs; + } + + case TREE_LIST: + { + tree elem, baselink, name; + int globals = overloaded_globals_p (rhs); + +#if 0 /* obsolete */ + /* If there's only one function we know about, return that. */ + if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE) + return TREE_VALUE (rhs); +#endif + + /* First look for an exact match. Search either overloaded + functions or member functions. May have to undo what + `default_conversion' might do to lhstype. */ + + if (TYPE_PTRMEMFUNC_P (lhstype)) + lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype); + + if (TREE_CODE (lhstype) == POINTER_TYPE) + if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE) + lhstype = TREE_TYPE (lhstype); + else + { + if (complain) + error ("invalid type combination for overload"); + return error_mark_node; + } + + if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0) + { + if (complain) + cp_error ("cannot resolve overloaded function `%D' based on non-function type", + TREE_PURPOSE (rhs)); + return error_mark_node; + } + + if (globals > 0) + { + elem = get_first_fn (rhs); + while (elem) + if (! comptypes (lhstype, TREE_TYPE (elem), 1)) + elem = DECL_CHAIN (elem); + else + return elem; + + /* No exact match found, look for a compatible template. */ + { + tree save_elem = 0; + for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem)) + if (TREE_CODE (elem) == TEMPLATE_DECL) + { + int n = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (elem)); + tree *t = (tree *) alloca (sizeof (tree) * n); + int i, d = 0; + i = type_unification (DECL_TEMPLATE_PARMS (elem), t, + TYPE_ARG_TYPES (TREE_TYPE (elem)), + TYPE_ARG_TYPES (lhstype), &d, 0); + if (i == 0) + { + if (save_elem) + { + cp_error ("ambiguous template instantiation converting to `%#T'", lhstype); + return error_mark_node; + } + save_elem = instantiate_template (elem, t); + /* Check the return type. */ + if (! comptypes (TREE_TYPE (lhstype), + TREE_TYPE (TREE_TYPE (save_elem)), 1)) + save_elem = 0; + } + } + if (save_elem) + return save_elem; + } + + /* No match found, look for a compatible function. */ + elem = get_first_fn (rhs); + while (elem && comp_target_types (lhstype, + TREE_TYPE (elem), 1) <= 0) + elem = DECL_CHAIN (elem); + if (elem) + { + tree save_elem = elem; + elem = DECL_CHAIN (elem); + while (elem && comp_target_types (lhstype, + TREE_TYPE (elem), 0) <= 0) + elem = DECL_CHAIN (elem); + if (elem) + { + if (complain) + { + cp_error ("cannot resolve overload to target type `%#T'", + lhstype); + cp_error_at (" ambiguity between `%#D'", save_elem); + cp_error_at (" and `%#D', at least", elem); + } + return error_mark_node; + } + return save_elem; + } + if (complain) + { + cp_error ("cannot resolve overload to target type `%#T'", + lhstype); + cp_error (" because no suitable overload of function `%D' exists", + TREE_PURPOSE (rhs)); + } + return error_mark_node; + } + + if (TREE_NONLOCAL_FLAG (rhs)) + { + /* Got to get it as a baselink. */ + rhs = lookup_fnfields (TYPE_BINFO (current_class_type), + TREE_PURPOSE (rhs), 0); + } + else + { + my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181); + if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST) + rhs = TREE_VALUE (rhs); + my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL, + 182); + } + + for (baselink = rhs; baselink; + baselink = next_baselink (baselink)) + { + elem = TREE_VALUE (baselink); + while (elem) + if (comptypes (lhstype, TREE_TYPE (elem), 1)) + return elem; + else + elem = DECL_CHAIN (elem); + } + + /* No exact match found, look for a compatible method. */ + for (baselink = rhs; baselink; + baselink = next_baselink (baselink)) + { + elem = TREE_VALUE (baselink); + while (elem && comp_target_types (lhstype, + TREE_TYPE (elem), 1) <= 0) + elem = DECL_CHAIN (elem); + if (elem) + { + tree save_elem = elem; + elem = DECL_CHAIN (elem); + while (elem && comp_target_types (lhstype, + TREE_TYPE (elem), 0) <= 0) + elem = DECL_CHAIN (elem); + if (elem) + { + if (complain) + error ("ambiguous overload for overloaded method requested"); + return error_mark_node; + } + return save_elem; + } + name = DECL_NAME (TREE_VALUE (rhs)); +#if 0 + if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0) + { + /* Try to instantiate from non-member functions. */ + rhs = lookup_name_nonclass (name); + if (rhs && TREE_CODE (rhs) == TREE_LIST) + { + /* This code seems to be missing a `return'. */ + my_friendly_abort (4); + instantiate_type (lhstype, rhs, complain); + } + } +#endif + } + if (complain) + cp_error ("no compatible member functions named `%D'", name); + return error_mark_node; + } + + case CALL_EXPR: + /* This is too hard for now. */ + my_friendly_abort (183); + return error_mark_node; + + case PLUS_EXPR: + case MINUS_EXPR: + case COMPOUND_EXPR: + TREE_OPERAND (rhs, 0) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); + if (TREE_OPERAND (rhs, 0) == error_mark_node) + return error_mark_node; + TREE_OPERAND (rhs, 1) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); + if (TREE_OPERAND (rhs, 1) == error_mark_node) + return error_mark_node; + + TREE_TYPE (rhs) = lhstype; + return rhs; + + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case FLOOR_DIV_EXPR: + case CEIL_DIV_EXPR: + case ROUND_DIV_EXPR: + case RDIV_EXPR: + case TRUNC_MOD_EXPR: + case FLOOR_MOD_EXPR: + case CEIL_MOD_EXPR: + case ROUND_MOD_EXPR: + case FIX_ROUND_EXPR: + case FIX_FLOOR_EXPR: + case FIX_CEIL_EXPR: + case FIX_TRUNC_EXPR: + case FLOAT_EXPR: + case NEGATE_EXPR: + case ABS_EXPR: + case MAX_EXPR: + case MIN_EXPR: + case FFS_EXPR: + + case BIT_AND_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case LROTATE_EXPR: + case RROTATE_EXPR: + + case PREINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + case POSTDECREMENT_EXPR: + if (complain) + error ("invalid operation on uninstantiated type"); + return error_mark_node; + + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + case TRUTH_XOR_EXPR: + case LT_EXPR: + case LE_EXPR: + case GT_EXPR: + case GE_EXPR: + case EQ_EXPR: + case NE_EXPR: + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case TRUTH_NOT_EXPR: + if (complain) + error ("not enough type information"); + return error_mark_node; + + case COND_EXPR: + if (type_unknown_p (TREE_OPERAND (rhs, 0))) + { + if (complain) + error ("not enough type information"); + return error_mark_node; + } + TREE_OPERAND (rhs, 1) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); + if (TREE_OPERAND (rhs, 1) == error_mark_node) + return error_mark_node; + TREE_OPERAND (rhs, 2) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain); + if (TREE_OPERAND (rhs, 2) == error_mark_node) + return error_mark_node; + + TREE_TYPE (rhs) = lhstype; + return rhs; + + case MODIFY_EXPR: + TREE_OPERAND (rhs, 1) + = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); + if (TREE_OPERAND (rhs, 1) == error_mark_node) + return error_mark_node; + + TREE_TYPE (rhs) = lhstype; + return rhs; + + case ADDR_EXPR: + if (TYPE_PTRMEMFUNC_P (lhstype)) + lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype); + else if (TREE_CODE (lhstype) != POINTER_TYPE) + { + if (complain) + error ("type for resolving address of overloaded function must be pointer type"); + return error_mark_node; + } + TREE_TYPE (rhs) = lhstype; + lhstype = TREE_TYPE (lhstype); + { + tree fn = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); + if (fn == error_mark_node) + return error_mark_node; + mark_addressable (fn); + TREE_OPERAND (rhs, 0) = fn; + TREE_CONSTANT (rhs) = staticp (fn); + } + return rhs; + + case ENTRY_VALUE_EXPR: + my_friendly_abort (184); + return error_mark_node; + + case ERROR_MARK: + return error_mark_node; + + default: + my_friendly_abort (185); + return error_mark_node; + } +} + +/* Return the name of the virtual function pointer field + (as an IDENTIFIER_NODE) for the given TYPE. Note that + this may have to look back through base types to find the + ultimate field name. (For single inheritance, these could + all be the same name. Who knows for multiple inheritance). */ +static tree +get_vfield_name (type) + tree type; +{ + tree binfo = TYPE_BINFO (type); + char *buf; + + while (BINFO_BASETYPES (binfo) + && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0))) + && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0))) + binfo = BINFO_BASETYPE (binfo, 0); + + type = BINFO_TYPE (binfo); + buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT) + + TYPE_NAME_LENGTH (type) + 2); + sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type)); + return get_identifier (buf); +} + +void +print_class_statistics () +{ +#ifdef GATHER_STATISTICS + fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness); + fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs); + fprintf (stderr, "build_method_call = %d (inner = %d)\n", + n_build_method_call, n_inner_fields_searched); + if (n_vtables) + { + fprintf (stderr, "vtables = %d; vtable searches = %d\n", + n_vtables, n_vtable_searches); + fprintf (stderr, "vtable entries = %d; vtable elems = %d\n", + n_vtable_entries, n_vtable_elems); + } +#endif +} + +/* Push an obstack which is sufficiently long-lived to hold such class + decls that may be cached in the previous_class_values list. For now, let's + use the permanent obstack, later we may create a dedicated obstack just + for this purpose. The effect is undone by pop_obstacks. */ +void +maybe_push_cache_obstack () +{ + push_obstacks_nochange (); + if (current_class_depth == 1) + current_obstack = &permanent_obstack; +} diff --git a/contrib/gcc/cp/class.h b/contrib/gcc/cp/class.h new file mode 100644 index 00000000000..f2c21735cc4 --- /dev/null +++ b/contrib/gcc/cp/class.h @@ -0,0 +1,117 @@ +/* Variables and structures for overloading rules. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* The following structure is used when comparing various alternatives + for overloading. The unsigned quantity `strikes.i' is used + for fast comparison of two possibilities. This number is an + aggregate of four constituents: + + EVIL: if this is non-zero, then the candidate should not be considered + ELLIPSIS: if this is non-zero, then some actual argument has been matched + against an ellipsis + USER: if this is non-zero, then a user-defined type conversion is needed + B_OR_D: if this is non-zero, then use a base pointer instead of the + type of the pointer we started with. + EASY: if this is non-zero, then we have a builtin conversion + (such as int to long, int to float, etc) to do. + + If two candidates require user-defined type conversions, and the + type conversions are not identical, then an ambiguity error + is reported. + + If two candidates agree on user-defined type conversions, + and one uses pointers of strictly higher type (derived where + another uses base), then that alternative is silently chosen. + + Note that this technique really only works for 255 arguments. Perhaps + this is not enough. */ + +/* These macros and harshness_code are used by the NEW METHOD. */ +#define EVIL_CODE (1<<7) +#define CONST_CODE (1<<6) +#define ELLIPSIS_CODE (1<<5) +#define USER_CODE (1<<4) +#define STD_CODE (1<<3) +#define PROMO_CODE (1<<2) +#define QUAL_CODE (1<<1) +#define TRIVIAL_CODE (1<<0) + +struct harshness_code +{ + /* What kind of conversion is involved. */ + unsigned short code; + + /* The inheritance distance. */ + short distance; + + /* For a PROMO_CODE, Any special penalties involved in integral conversions. + This exists because $4.1 of the ARM states that something like + `short unsigned int' should promote to `int', not `unsigned int'. + If, for example, it tries to match two fns, f(int) and f(unsigned), + f(int) should be a better match than f(unsigned) by this rule. Without + this extra metric, they both only appear as "integral promotions", which + will lead to an ambiguity. + For a TRIVIAL_CODE, This is also used by build_overload_call_real and + convert_harshness to keep track of other information we need. */ + unsigned short int_penalty; +}; + +struct candidate +{ + struct harshness_code h; /* Used for single-argument conversions. */ + + int h_len; /* The length of the harshness vector. */ + + tree function; /* A FUNCTION_DECL */ + tree basetypes; /* The path to function. */ + tree arg; /* first parm to function. */ + + /* Indexed by argument number, encodes evil, user, d_to_b, and easy + strikes for that argument. At end of array, we store the index+1 + of where we started using default parameters, or 0 if there are + none. */ + struct harshness_code *harshness; + + union + { + tree field; /* If no evil strikes, the FUNCTION_DECL of + the function (if a member function). */ + int bad_arg; /* the index of the first bad argument: + 0 if no bad arguments + > 0 is first bad argument + -1 if extra actual arguments + -2 if too few actual arguments. + -3 if const/non const method mismatch. + -4 if type unification failed. + -5 if contravariance violation. */ + } u; +}; +int rank_for_overload (); + +/* Variables shared between class.c and call.c. */ + +extern int n_vtables; +extern int n_vtable_entries; +extern int n_vtable_searches; +extern int n_vtable_elems; +extern int n_convert_harshness; +extern int n_compute_conversion_costs; +extern int n_build_method_call; +extern int n_inner_fields_searched; diff --git a/contrib/gcc/cp/config-lang.in b/contrib/gcc/cp/config-lang.in new file mode 100644 index 00000000000..7a9a5c558c7 --- /dev/null +++ b/contrib/gcc/cp/config-lang.in @@ -0,0 +1,35 @@ +# Top level configure fragment for GNU C++. +# Copyright (C) 1994, 1995 Free Software Foundation, Inc. + +#This file is part of GNU CC. + +#GNU CC is free software; you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation; either version 2, or (at your option) +#any later version. + +#GNU CC is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with GNU CC; see the file COPYING. If not, write to +#the Free Software Foundation, 59 Temple Place - Suite 330, +#Boston, MA 02111-1307, USA. + +# Configure looks for the existence of this file to auto-config each language. +# We define several parameters used by configure: +# +# language - name of language as it would appear in $(LANGUAGES) +# compilers - value to add to $(COMPILERS) +# stagestuff - files to add to $(STAGESTUFF) +# diff_excludes - files to ignore when building diffs between two versions. + +language="c++" + +compilers="cc1plus\$(exeext)" + +stagestuff="g++\$(exeext) g++-cross\$(exeext) cc1plus\$(exeext)" + +diff_excludes="-x cp/parse.c -x cp/parse.h" diff --git a/contrib/gcc/cp/cp-tree.h b/contrib/gcc/cp/cp-tree.h new file mode 100644 index 00000000000..fe9855d8ca0 --- /dev/null +++ b/contrib/gcc/cp/cp-tree.h @@ -0,0 +1,2496 @@ +/* Definitions for C++ parsing and type checking. + Copyright (C) 1987, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifndef _CP_TREE_H +#define _CP_TREE_H + +/* Borrow everything that is C from c-tree.h, + but do so by copy, not by inclusion, since c-tree.h defines + lang_identifier. */ + +#ifndef STDIO_PROTO +#ifdef BUFSIZ +#define STDIO_PROTO(ARGS) PROTO(ARGS) +#else +#define STDIO_PROTO(ARGS) () +#endif +#endif + +/* Language-dependent contents of an identifier. */ + +struct lang_identifier +{ + struct tree_identifier ignore; + tree global_value, local_value; + tree class_value; + tree class_template_info; + struct lang_id2 *x; +}; + +struct lang_id2 +{ + tree label_value, implicit_decl; + tree type_desc, as_list, error_locus; +}; + +/* To identify to the debug emitters if it should pay attention to the + flag `-Wtemplate-debugging'. */ +#define HAVE_TEMPLATES 1 + +/* Macros for access to language-specific slots in an identifier. */ + +#define IDENTIFIER_GLOBAL_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->global_value) +#define IDENTIFIER_CLASS_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->class_value) +#define IDENTIFIER_LOCAL_VALUE(NODE) \ + (((struct lang_identifier *)(NODE))->local_value) +#define IDENTIFIER_TEMPLATE(NODE) \ + (((struct lang_identifier *)(NODE))->class_template_info) + +#define IDENTIFIER_TYPE_VALUE(NODE) (TREE_TYPE (NODE)) +#define SET_IDENTIFIER_TYPE_VALUE(NODE,TYPE) (TREE_TYPE (NODE) = TYPE) +#define IDENTIFIER_HAS_TYPE_VALUE(NODE) (TREE_TYPE (NODE) ? 1 : 0) + +#define LANG_ID_FIELD(NAME,NODE) \ + (((struct lang_identifier *)(NODE))->x \ + ? ((struct lang_identifier *)(NODE))->x->NAME : 0) +#define SET_LANG_ID(NODE,VALUE,NAME) \ + (((struct lang_identifier *)(NODE))->x == 0 \ + ? ((struct lang_identifier *)(NODE))->x \ + = (struct lang_id2 *)perm_calloc (1, sizeof (struct lang_id2)) : 0, \ + ((struct lang_identifier *)(NODE))->x->NAME = (VALUE)) + +#define IDENTIFIER_LABEL_VALUE(NODE) LANG_ID_FIELD(label_value, NODE) +#define SET_IDENTIFIER_LABEL_VALUE(NODE,VALUE) \ + SET_LANG_ID(NODE, VALUE, label_value) + +#define IDENTIFIER_IMPLICIT_DECL(NODE) LANG_ID_FIELD(implicit_decl, NODE) +#define SET_IDENTIFIER_IMPLICIT_DECL(NODE,VALUE) \ + SET_LANG_ID(NODE, VALUE, implicit_decl) + +#define IDENTIFIER_AS_DESC(NODE) LANG_ID_FIELD(type_desc, NODE) +#define SET_IDENTIFIER_AS_DESC(NODE,DESC) \ + SET_LANG_ID(NODE, DESC, type_desc) + +#define IDENTIFIER_AS_LIST(NODE) LANG_ID_FIELD(as_list, NODE) +#define SET_IDENTIFIER_AS_LIST(NODE,LIST) \ + SET_LANG_ID(NODE, LIST, as_list) + +#define IDENTIFIER_ERROR_LOCUS(NODE) LANG_ID_FIELD(error_locus, NODE) +#define SET_IDENTIFIER_ERROR_LOCUS(NODE,VALUE) \ + SET_LANG_ID(NODE, VALUE, error_locus) + + +#define IDENTIFIER_VIRTUAL_P(NODE) TREE_LANG_FLAG_1(NODE) + +/* Nonzero if this identifier is the prefix for a mangled C++ operator name. */ +#define IDENTIFIER_OPNAME_P(NODE) TREE_LANG_FLAG_2(NODE) + +#define IDENTIFIER_TYPENAME_P(NODE) \ + (! strncmp (IDENTIFIER_POINTER (NODE), \ + IDENTIFIER_POINTER (ansi_opname[(int) TYPE_EXPR]), \ + IDENTIFIER_LENGTH (ansi_opname[(int) TYPE_EXPR]))) + +/* Nonzero means reject anything that ANSI standard C forbids. */ +extern int pedantic; + +/* In a RECORD_TYPE or UNION_TYPE, nonzero if any component is read-only. */ +#define C_TYPE_FIELDS_READONLY(type) TYPE_LANG_FLAG_0 (type) + +/* Record in each node resulting from a binary operator + what operator was specified for it. */ +#define C_EXP_ORIGINAL_CODE(exp) ((enum tree_code) TREE_COMPLEXITY (exp)) + +/* Store a value in that field. */ +#define C_SET_EXP_ORIGINAL_CODE(exp, code) \ + (TREE_COMPLEXITY (exp) = (int)(code)) + +/* If non-zero, a VAR_DECL whose cleanup will cause a throw to the + next exception handler. */ +extern tree exception_throw_decl; + +extern tree double_type_node, long_double_type_node, float_type_node; +extern tree char_type_node, unsigned_char_type_node, signed_char_type_node; +extern tree ptrdiff_type_node; + +extern tree short_integer_type_node, short_unsigned_type_node; +extern tree long_integer_type_node, long_unsigned_type_node; +extern tree long_long_integer_type_node, long_long_unsigned_type_node; +extern tree unsigned_type_node; +extern tree string_type_node, char_array_type_node, int_array_type_node; +extern tree wchar_array_type_node; +extern tree wchar_type_node, signed_wchar_type_node, unsigned_wchar_type_node; +extern tree intQI_type_node, unsigned_intQI_type_node; +extern tree intHI_type_node, unsigned_intHI_type_node; +extern tree intSI_type_node, unsigned_intSI_type_node; +extern tree intDI_type_node, unsigned_intDI_type_node; + +extern int current_function_returns_value; +extern int current_function_returns_null; +extern tree current_function_return_value; + +extern tree ridpointers[]; +extern tree ansi_opname[]; +extern tree ansi_assopname[]; + +/* Nonzero means `$' can be in an identifier. */ + +extern int dollars_in_ident; + +/* Nonzero means allow type mismatches in conditional expressions; + just make their values `void'. */ + +extern int flag_cond_mismatch; + +/* Nonzero means don't recognize the keyword `asm'. */ + +extern int flag_no_asm; + +/* For cross referencing. */ + +extern int flag_gnu_xref; + +/* For environments where you can use GNU binutils (as, ld in particular). */ + +extern int flag_gnu_binutils; + +/* Nonzero means ignore `#ident' directives. */ + +extern int flag_no_ident; + +/* Nonzero means warn about implicit declarations. */ + +extern int warn_implicit; + +/* Nonzero means warn when all ctors or dtors are private, and the class + has no friends. */ + +extern int warn_ctor_dtor_privacy; + +/* Nonzero means warn about function definitions that default the return type + or that use a null return and have a return-type other than void. */ + +extern int warn_return_type; + +/* Nonzero means give string constants the type `const char *' + to get extra warnings from them. These warnings will be too numerous + to be useful, except in thoroughly ANSIfied programs. */ + +extern int warn_write_strings; + +/* Nonzero means warn about sizeof(function) or addition/subtraction + of function pointers. */ + +extern int warn_pointer_arith; + +/* Nonzero means warn for all old-style non-prototype function decls. */ + +extern int warn_strict_prototypes; + +/* Nonzero means warn about suggesting putting in ()'s. */ + +extern int warn_parentheses; + +/* Nonzero means warn about multiple (redundant) decls for the same single + variable or function. */ + +extern int warn_redundant_decls; + +/* Warn if initializer is not completely bracketed. */ + +extern int warn_missing_braces; + +/* Warn about a subscript that has type char. */ + +extern int warn_char_subscripts; + +/* Nonzero means warn about pointer casts that can drop a type qualifier + from the pointer target type. */ + +extern int warn_cast_qual; + +/* Warn about traditional constructs whose meanings changed in ANSI C. */ + +extern int warn_traditional; + +/* Warn about *printf or *scanf format/argument anomalies. */ + +extern int warn_format; + +/* Nonzero means warn about non virtual destructors in classes that have + virtual functions. */ + +extern int warn_nonvdtor; + +/* Non-zero means warn when a function is declared extern and later inline. */ +extern int warn_extern_inline; + +/* Nonzero means do some things the same way PCC does. */ + +extern int flag_traditional; + +/* Nonzero means to treat bitfields as unsigned unless they say `signed'. */ + +extern int flag_signed_bitfields; + +/* 3 means write out only virtuals function tables `defined' + in this implementation file. + 2 means write out only specific virtual function tables + and give them (C) public access. + 1 means write out virtual function tables and give them + (C) public access. + 0 means write out virtual function tables and give them + (C) static access (default). + -1 means declare virtual function tables extern. */ + +extern int write_virtuals; + +/* True for more efficient but incompatible (not not fully tested) + vtable implementation (using thunks). + 0 is old behavior; 1 is new behavior. */ +extern int flag_vtable_thunks; + +/* INTERFACE_ONLY nonzero means that we are in an "interface" + section of the compiler. INTERFACE_UNKNOWN nonzero means + we cannot trust the value of INTERFACE_ONLY. If INTERFACE_UNKNOWN + is zero and INTERFACE_ONLY is zero, it means that we are responsible + for exporting definitions that others might need. */ +extern int interface_only, interface_unknown; + +/* Nonzero means we should attempt to elide constructors when possible. */ + +extern int flag_elide_constructors; + +/* Nonzero means enable obscure ANSI features and disable GNU extensions + that might cause ANSI-compliant code to be miscompiled. */ + +extern int flag_ansi; + +/* Nonzero means recognize and handle ansi-style exception handling + constructs. */ + +extern int flag_handle_exceptions; + +/* Nonzero means recognize and handle signature language constructs. */ + +extern int flag_handle_signatures; + +/* Nonzero means that member functions defined in class scope are + inline by default. */ + +extern int flag_default_inline; + +/* Nonzero means emit cadillac protocol. */ + +extern int flag_cadillac; + +/* C++ language-specific tree codes. */ +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM, +enum cplus_tree_code { + __DUMMY = LAST_AND_UNUSED_TREE_CODE, +#include "tree.def" + LAST_CPLUS_TREE_CODE +}; +#undef DEFTREECODE + +/* Override OFFSET_REFs from the back-end, as we want our very own. */ +/* Allow complex pointer to members to work correctly. */ +#define OFFSET_REF CP_OFFSET_REF + +enum languages { lang_c, lang_cplusplus }; + +/* Macros to make error reporting functions' lives easier. */ +#define TYPE_IDENTIFIER(NODE) (DECL_NAME (TYPE_NAME (NODE))) +#define TYPE_NAME_STRING(NODE) (IDENTIFIER_POINTER (TYPE_IDENTIFIER (NODE))) +#define TYPE_NAME_LENGTH(NODE) (IDENTIFIER_LENGTH (TYPE_IDENTIFIER (NODE))) + +#define TYPE_ASSEMBLER_NAME_STRING(NODE) (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (TYPE_NAME (NODE)))) +#define TYPE_ASSEMBLER_NAME_LENGTH(NODE) (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (TYPE_NAME (NODE)))) + +/* The _DECL for this _TYPE. */ +#define TYPE_MAIN_DECL(NODE) (TYPE_NAME (NODE)) + +#define IS_AGGR_TYPE(t) (TYPE_LANG_FLAG_5 (t)) +#define IS_AGGR_TYPE_CODE(t) (t == RECORD_TYPE || t == UNION_TYPE || t == UNINSTANTIATED_P_TYPE) +#define IS_AGGR_TYPE_2(TYPE1,TYPE2) \ + (TREE_CODE (TYPE1) == TREE_CODE (TYPE2) \ + && IS_AGGR_TYPE (TYPE1)&IS_AGGR_TYPE (TYPE2)) +#define IS_OVERLOAD_TYPE_CODE(t) (IS_AGGR_TYPE_CODE (t) || t == ENUMERAL_TYPE) +#define IS_OVERLOAD_TYPE(t) (IS_OVERLOAD_TYPE_CODE (TREE_CODE (t))) + +/* In a *_TYPE, nonzero means a built-in type. */ +#define TYPE_BUILT_IN(NODE) TYPE_LANG_FLAG_6(NODE) + +/* Macros which might want to be replaced by function calls. */ + +#define DELTA_FROM_VTABLE_ENTRY(ENTRY) \ + (!flag_vtable_thunks ? \ + TREE_VALUE (CONSTRUCTOR_ELTS (ENTRY)) \ + : TREE_CODE (TREE_OPERAND ((ENTRY), 0)) != THUNK_DECL ? integer_zero_node \ + : build_int_2 (THUNK_DELTA (TREE_OPERAND ((ENTRY), 0)), 0)) +#if 1 +/* Virtual function addresses can be gotten from a virtual function + table entry using this macro. */ +#define FNADDR_FROM_VTABLE_ENTRY(ENTRY) \ + (!flag_vtable_thunks ? \ + TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (ENTRY)))) \ + : TREE_CODE (TREE_OPERAND ((ENTRY), 0)) != THUNK_DECL ? (ENTRY) \ + : DECL_INITIAL (TREE_OPERAND ((ENTRY), 0))) +#define SET_FNADDR_FROM_VTABLE_ENTRY(ENTRY,VALUE) \ + (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (ENTRY)))) = (VALUE)) +#define FUNCTION_ARG_CHAIN(NODE) (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (NODE)))) +#define PROMOTES_TO_AGGR_TYPE(NODE,CODE) \ + (((CODE) == TREE_CODE (NODE) \ + && IS_AGGR_TYPE (TREE_TYPE (NODE))) \ + || IS_AGGR_TYPE (NODE)) + +#else +#define FNADDR_FROM_VTABLE_ENTRY(ENTRY) (fnaddr_from_vtable_entry (ENTRY)) +#define SET_FNADDR_FROM_VTABLE_ENTRY(ENTRY,VALUE) \ + (set_fnaddr_from_vtable_entry (ENTRY, VALUE)) +/* #define TYPE_NAME_STRING(NODE) (type_name_string (NODE)) */ +#define FUNCTION_ARG_CHAIN(NODE) (function_arg_chain (NODE)) +#define PROMOTES_TO_AGGR_TYPE(NODE,CODE) (promotes_to_aggr_type (NODE, CODE)) +/* #define IS_AGGR_TYPE_2(TYPE1, TYPE2) (is_aggr_type_2 (TYPE1, TYPE2)) */ +#endif +/* Nonzero iff TYPE is uniquely derived from PARENT. Under MI, PARENT can + be an ambiguous base class of TYPE, and this macro will be false. */ +#define UNIQUELY_DERIVED_FROM_P(PARENT, TYPE) (get_base_distance (PARENT, TYPE, 0, (tree *)0) >= 0) +#define ACCESSIBLY_DERIVED_FROM_P(PARENT, TYPE) (get_base_distance (PARENT, TYPE, -1, (tree *)0) >= 0) +#define ACCESSIBLY_UNIQUELY_DERIVED_P(PARENT, TYPE) (get_base_distance (PARENT, TYPE, 1, (tree *)0) >= 0) +#define DERIVED_FROM_P(PARENT, TYPE) (get_base_distance (PARENT, TYPE, 0, (tree *)0) != -1) + +/* Statistics show that while the GNU C++ compiler may generate + thousands of different types during a compilation run, it + generates relatively few (tens) of classtypes. Because of this, + it is not costly to store a generous amount of information + in classtype nodes. This struct must fill out to a multiple of 4 bytes. */ +struct lang_type +{ + struct + { + unsigned has_type_conversion : 1; + unsigned has_int_conversion : 1; + unsigned has_float_conversion : 1; + unsigned has_init_ref : 1; + unsigned gets_init_aggr : 1; + unsigned has_assignment : 1; + unsigned has_default_ctor : 1; + unsigned uses_multiple_inheritance : 1; + + unsigned has_nonpublic_ctor : 2; + unsigned has_nonpublic_assign_ref : 2; + unsigned const_needs_init : 1; + unsigned ref_needs_init : 1; + unsigned has_const_assign_ref : 1; + unsigned vtable_needs_writing : 1; + + unsigned has_assign_ref : 1; + unsigned gets_new : 2; + unsigned gets_delete : 2; + unsigned has_call_overloaded : 1; + unsigned has_array_ref_overloaded : 1; + unsigned has_arrow_overloaded : 1; + + unsigned local_typedecls : 1; + unsigned interface_only : 1; + unsigned interface_unknown : 1; + unsigned needs_virtual_reinit : 1; + unsigned vec_delete_takes_size : 1; + unsigned declared_class : 1; + unsigned being_defined : 1; + unsigned redefined : 1; + + unsigned no_globalize : 1; + unsigned marked : 1; + unsigned marked2 : 1; + unsigned marked3 : 1; + unsigned marked4 : 1; + unsigned marked5 : 1; + unsigned marked6 : 1; + + unsigned use_template : 2; + unsigned debug_requested : 1; + unsigned has_method_call_overloaded : 1; + unsigned private_attr : 1; + unsigned got_semicolon : 1; + unsigned ptrmemfunc_flag : 1; + unsigned is_signature : 1; + unsigned is_signature_pointer : 1; + + unsigned is_signature_reference : 1; + unsigned has_default_implementation : 1; + unsigned grokking_typedef : 1; + unsigned has_opaque_typedecls : 1; + unsigned sigtable_has_been_generated : 1; + unsigned was_anonymous : 1; + unsigned has_real_assignment : 1; + unsigned has_real_assign_ref : 1; + + unsigned has_const_init_ref : 1; + unsigned has_complex_init_ref : 1; + unsigned has_complex_assign_ref : 1; + unsigned has_abstract_assign_ref : 1; + unsigned non_aggregate : 1; + + /* The MIPS compiler gets it wrong if this struct also + does not fill out to a multiple of 4 bytes. Add a + member `dummy' with new bits if you go over the edge. */ + unsigned dummy : 19; + + unsigned n_vancestors : 16; + } type_flags; + + int cid; + int n_ancestors; + int vsize; + int max_depth; + int vfield_parent; + + union tree_node *vbinfo[2]; + union tree_node *baselink_vec; + union tree_node *vfields; + union tree_node *vbases; + union tree_node *vbase_size; + + union tree_node *tags; + char *memoized_table_entry; + + char *search_slot; + +#ifdef ONLY_INT_FIELDS + unsigned int mode : 8; +#else + enum machine_mode mode : 8; +#endif + + unsigned char size_unit; + unsigned char align; + unsigned char sep_unit; + + union tree_node *sep; + union tree_node *size; + + union tree_node *base_init_list; + union tree_node *abstract_virtuals; + union tree_node *as_list; + union tree_node *id_as_list; + union tree_node *binfo_as_list; + union tree_node *friend_classes; + + char *mi_matrix; + + union tree_node *rtti; + + union tree_node *methods; + + union tree_node *signature; + union tree_node *signature_pointer_to; + union tree_node *signature_reference_to; + + int linenum; +}; + +#define CLASSTYPE_SOURCE_LINE(NODE) (TYPE_LANG_SPECIFIC(NODE)->linenum) + +/* Indicates whether or not (and how) a template was expanded for this class. + 0=no information yet/non-template class + 1=implicit template instantiation + 2=explicit template specialization + 3=explicit template instantiation */ +#define CLASSTYPE_USE_TEMPLATE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.use_template) + +/* Fields used for storing information before the class is defined. + After the class is defined, these fields hold other information. */ + +/* List of friends which were defined inline in this class definition. */ +#define CLASSTYPE_INLINE_FRIENDS(NODE) (TYPE_NONCOPIED_PARTS (NODE)) + +/* Nonzero for _CLASSTYPE means that the _CLASSTYPE either has + a special meaning for the assignment operator ("operator="), + or one of its fields (or base members) has a special meaning + defined. */ +#define TYPE_HAS_ASSIGNMENT(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_assignment) +#define TYPE_HAS_REAL_ASSIGNMENT(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_real_assignment) + +/* Nonzero for _CLASSTYPE means that operator new and delete are defined, + respectively. */ +#define TYPE_GETS_NEW(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_new) +#define TYPE_GETS_DELETE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_delete) +#define TYPE_GETS_REG_DELETE(NODE) (TYPE_GETS_DELETE (NODE) & 1) + +/* Nonzero for _CLASSTYPE means that operator vec delete is defined and + takes the optional size_t argument. */ +#define TYPE_VEC_DELETE_TAKES_SIZE(NODE) \ + (TYPE_LANG_SPECIFIC(NODE)->type_flags.vec_delete_takes_size) +#define TYPE_VEC_NEW_USES_COOKIE(NODE) \ + (TYPE_NEEDS_DESTRUCTOR (NODE) \ + || (TYPE_LANG_SPECIFIC (NODE) && TYPE_VEC_DELETE_TAKES_SIZE (NODE))) + +/* Nonzero for TREE_LIST or _TYPE node means that this node is class-local. */ +#define TREE_NONLOCAL_FLAG(NODE) (TREE_LANG_FLAG_0 (NODE)) + +/* Nonzero for a _CLASSTYPE node which we know to be private. */ +#define TYPE_PRIVATE_P(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.private_attr) + +/* Nonzero means that this _CLASSTYPE node defines ways of converting + itself to other types. */ +#define TYPE_HAS_CONVERSION(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_type_conversion) + +/* Nonzero means that this _CLASSTYPE node can convert itself to an + INTEGER_TYPE. */ +#define TYPE_HAS_INT_CONVERSION(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_int_conversion) + +/* Nonzero means that this _CLASSTYPE node can convert itself to an + REAL_TYPE. */ +#define TYPE_HAS_REAL_CONVERSION(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_float_conversion) + +/* Nonzero means that this _CLASSTYPE node overloads operator=(X&). */ +#define TYPE_HAS_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_assign_ref) +#define TYPE_HAS_CONST_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_const_assign_ref) + +/* Nonzero means that this _CLASSTYPE node has an X(X&) constructor. */ +#define TYPE_HAS_INIT_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_init_ref) +#define TYPE_HAS_CONST_INIT_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_const_init_ref) + +/* Nonzero means that this _CLASSTYPE node has an X(X ...) constructor. + Note that there must be other arguments, or this constructor is flagged + as being erroneous. */ +#define TYPE_GETS_INIT_AGGR(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_init_aggr) + +/* Nonzero means that this type is being defined. I.e., the left brace + starting the definition of this type has been seen. */ +#define TYPE_BEING_DEFINED(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.being_defined) +/* Nonzero means that this type has been redefined. In this case, if + convenient, don't reprocess any methods that appear in its redefinition. */ +#define TYPE_REDEFINED(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.redefined) + +/* Nonzero means that this _CLASSTYPE node overloads the method call + operator. In this case, all method calls go through `operator->()(...). */ +#define TYPE_OVERLOADS_METHOD_CALL_EXPR(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_method_call_overloaded) + +/* Nonzero means that this type is a signature. */ +# define IS_SIGNATURE(NODE) (TYPE_LANG_SPECIFIC(NODE)?TYPE_LANG_SPECIFIC(NODE)->type_flags.is_signature:0) +# define SET_SIGNATURE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.is_signature=1) +# define CLEAR_SIGNATURE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.is_signature=0) + +/* Nonzero means that this type is a signature pointer type. */ +# define IS_SIGNATURE_POINTER(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.is_signature_pointer) + +/* Nonzero means that this type is a signature reference type. */ +# define IS_SIGNATURE_REFERENCE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.is_signature_reference) + +/* Nonzero means that this signature type has a default implementation. */ +# define HAS_DEFAULT_IMPLEMENTATION(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_default_implementation) + +/* Nonzero means that grokdeclarator works on a signature-local typedef. */ +#define SIGNATURE_GROKKING_TYPEDEF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.grokking_typedef) + +/* Nonzero means that this signature contains opaque type declarations. */ +#define SIGNATURE_HAS_OPAQUE_TYPEDECLS(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_opaque_typedecls) + +/* Nonzero means that a signature table has been generated + for this signature. */ +#define SIGTABLE_HAS_BEEN_GENERATED(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.sigtable_has_been_generated) + +/* If NODE is a class, this is the signature type that contains NODE's + signature after it has been computed using sigof(). */ +#define CLASSTYPE_SIGNATURE(NODE) (TYPE_LANG_SPECIFIC(NODE)->signature) + +/* If NODE is a signature pointer or signature reference, this is the + signature type the pointer/reference points to. */ +#define SIGNATURE_TYPE(NODE) (TYPE_LANG_SPECIFIC(NODE)->signature) + +/* If NODE is a signature, this is a vector of all methods defined + in the signature or in its base types together with their default + implementations. */ +#define SIGNATURE_METHOD_VEC(NODE) (TYPE_LANG_SPECIFIC(NODE)->signature) + +/* If NODE is a signature, this is the _TYPE node that contains NODE's + signature pointer type. */ +#define SIGNATURE_POINTER_TO(NODE) (TYPE_LANG_SPECIFIC(NODE)->signature_pointer_to) + +/* If NODE is a signature, this is the _TYPE node that contains NODE's + signature reference type. */ +#define SIGNATURE_REFERENCE_TO(NODE) (TYPE_LANG_SPECIFIC(NODE)->signature_reference_to) + +/* The is the VAR_DECL that contains NODE's rtti. */ +#define CLASSTYPE_RTTI(NODE) (TYPE_LANG_SPECIFIC(NODE)->rtti) + +/* List of all explicit methods (chained using DECL_NEXT_METHOD), + in order they were parsed. */ +#define CLASSTYPE_METHODS(NODE) (TYPE_LANG_SPECIFIC(NODE)->methods) + +/* Nonzero means that this _CLASSTYPE node overloads operator(). */ +#define TYPE_OVERLOADS_CALL_EXPR(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_call_overloaded) + +/* Nonzero means that this _CLASSTYPE node overloads operator[]. */ +#define TYPE_OVERLOADS_ARRAY_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_array_ref_overloaded) + +/* Nonzero means that this _CLASSTYPE node overloads operator->. */ +#define TYPE_OVERLOADS_ARROW(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_arrow_overloaded) + +/* Nonzero means that this _CLASSTYPE (or one of its ancestors) uses + multiple inheritance. If this is 0 for the root of a type + hierarchy, then we can use more efficient search techniques. */ +#define TYPE_USES_MULTIPLE_INHERITANCE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.uses_multiple_inheritance) + +/* Nonzero means that this _CLASSTYPE (or one of its ancestors) uses + virtual base classes. If this is 0 for the root of a type + hierarchy, then we can use more efficient search techniques. */ +#define TYPE_USES_VIRTUAL_BASECLASSES(NODE) (TREE_LANG_FLAG_3(NODE)) + +/* List of lists of member functions defined in this class. */ +#define CLASSTYPE_METHOD_VEC(NODE) TYPE_METHODS(NODE) + +/* The first type conversion operator in the class (the others can be + searched with TREE_CHAIN), or the first non-constructor function if + there are no type conversion operators. */ +#define CLASSTYPE_FIRST_CONVERSION(NODE) \ + TREE_VEC_LENGTH (CLASSTYPE_METHOD_VEC (NODE)) > 1 \ + ? TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (NODE), 1) \ + : NULL_TREE; + +/* Pointer from any member function to the head of the list of + member functions of the type that member function belongs to. */ +#define CLASSTYPE_BASELINK_VEC(NODE) (TYPE_LANG_SPECIFIC(NODE)->baselink_vec) + +/* Mark bits for depth-first and breath-first searches. */ +#define CLASSTYPE_MARKED(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked) +#define CLASSTYPE_MARKED2(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked2) +#define CLASSTYPE_MARKED3(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked3) +#define CLASSTYPE_MARKED4(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked4) +#define CLASSTYPE_MARKED5(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked5) +#define CLASSTYPE_MARKED6(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.marked6) +/* Macros to modify the above flags */ +#define SET_CLASSTYPE_MARKED(NODE) (CLASSTYPE_MARKED(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED(NODE) (CLASSTYPE_MARKED(NODE) = 0) +#define SET_CLASSTYPE_MARKED2(NODE) (CLASSTYPE_MARKED2(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED2(NODE) (CLASSTYPE_MARKED2(NODE) = 0) +#define SET_CLASSTYPE_MARKED3(NODE) (CLASSTYPE_MARKED3(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED3(NODE) (CLASSTYPE_MARKED3(NODE) = 0) +#define SET_CLASSTYPE_MARKED4(NODE) (CLASSTYPE_MARKED4(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED4(NODE) (CLASSTYPE_MARKED4(NODE) = 0) +#define SET_CLASSTYPE_MARKED5(NODE) (CLASSTYPE_MARKED5(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED5(NODE) (CLASSTYPE_MARKED5(NODE) = 0) +#define SET_CLASSTYPE_MARKED6(NODE) (CLASSTYPE_MARKED6(NODE) = 1) +#define CLEAR_CLASSTYPE_MARKED6(NODE) (CLASSTYPE_MARKED6(NODE) = 0) + +#define CLASSTYPE_TAGS(NODE) (TYPE_LANG_SPECIFIC(NODE)->tags) + +/* If this class has any bases, this is the number of the base class from + which our VFIELD is based, -1 otherwise. If this class has no base + classes, this is not used. + In D : B1, B2, PARENT would be 0, if D's vtable came from B1, + 1, if D's vtable came from B2. */ +#define CLASSTYPE_VFIELD_PARENT(NODE) (TYPE_LANG_SPECIFIC(NODE)->vfield_parent) + +/* Remove when done merging. */ +#define CLASSTYPE_VFIELD(NODE) TYPE_VFIELD(NODE) + +/* The number of virtual functions defined for this + _CLASSTYPE node. */ +#define CLASSTYPE_VSIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->vsize) +/* The virtual base classes that this type uses. */ +#define CLASSTYPE_VBASECLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->vbases) +/* The virtual function pointer fields that this type contains. */ +#define CLASSTYPE_VFIELDS(NODE) (TYPE_LANG_SPECIFIC(NODE)->vfields) + +/* Number of baseclasses defined for this type. + 0 means no base classes. */ +#define CLASSTYPE_N_BASECLASSES(NODE) \ + (TYPE_BINFO_BASETYPES (NODE) ? TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES(NODE)) : 0) + +/* Memoize the number of super classes (base classes) tha this node + has. That way we can know immediately (albeit conservatively how + large a multiple-inheritance matrix we need to build to find + derivation information. */ +#define CLASSTYPE_N_SUPERCLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->n_ancestors) +#define CLASSTYPE_N_VBASECLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.n_vancestors) + +/* Record how deep the inheritance is for this class so `void*' conversions + are less favorable than a conversion to the most base type. */ +#define CLASSTYPE_MAX_DEPTH(NODE) (TYPE_LANG_SPECIFIC(NODE)->max_depth) + +/* Used for keeping search-specific information. Any search routine + which uses this must define what exactly this slot is used for. */ +#define CLASSTYPE_SEARCH_SLOT(NODE) (TYPE_LANG_SPECIFIC(NODE)->search_slot) + +/* Entry for keeping memoization tables for this type to + hopefully speed up search routines. Since it is a pointer, + it can mean almost anything. */ +#define CLASSTYPE_MTABLE_ENTRY(NODE) (TYPE_LANG_SPECIFIC(NODE)->memoized_table_entry) + +/* This is the total size of the baseclasses defined for this type. + Needed because it is desirable to layout such information + before beginning to process the class itself, and we + don't want to compute it second time when actually laying + out the type for real. */ +#define CLASSTYPE_SIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->size) +#define CLASSTYPE_SIZE_UNIT(NODE) (TYPE_LANG_SPECIFIC(NODE)->size_unit) +#define CLASSTYPE_MODE(NODE) (TYPE_LANG_SPECIFIC(NODE)->mode) +#define CLASSTYPE_ALIGN(NODE) (TYPE_LANG_SPECIFIC(NODE)->align) + +/* This is the space needed for virtual base classes. NULL if + there are no virtual basetypes. */ +#define CLASSTYPE_VBASE_SIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->vbase_size) + +/* A cons list of structure elements which either have constructors + to be called, or virtual function table pointers which + need initializing. Depending on what is being initialized, + the TREE_PURPOSE and TREE_VALUE fields have different meanings: + + Member initialization: + Base class construction: + Base class initialization: + Whole type: . */ +#define CLASSTYPE_BASE_INIT_LIST(NODE) (TYPE_LANG_SPECIFIC(NODE)->base_init_list) + +/* A cons list of virtual functions which cannot be inherited by + derived classes. When deriving from this type, the derived + class must provide its own definition for each of these functions. */ +#define CLASSTYPE_ABSTRACT_VIRTUALS(NODE) (TYPE_LANG_SPECIFIC(NODE)->abstract_virtuals) + +/* Nonzero means that this aggr type has been `closed' by a semicolon. */ +#define CLASSTYPE_GOT_SEMICOLON(NODE) (TYPE_LANG_SPECIFIC (NODE)->type_flags.got_semicolon) + +/* Nonzero means that the main virtual function table pointer needs to be + set because base constructors have placed the wrong value there. + If this is zero, it means that they placed the right value there, + and there is no need to change it. */ +#define CLASSTYPE_NEEDS_VIRTUAL_REINIT(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.needs_virtual_reinit) + +/* Nonzero means that if this type has virtual functions, that + the virtual function table will be written out. */ +#define CLASSTYPE_VTABLE_NEEDS_WRITING(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.vtable_needs_writing) + +/* Nonzero means that this type defines its own local type declarations. */ +#define CLASSTYPE_LOCAL_TYPEDECLS(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.local_typedecls) + +/* Nonzero means that this type has an X() constructor. */ +#define TYPE_HAS_DEFAULT_CONSTRUCTOR(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_default_ctor) + +/* Nonzero means the type declared a ctor as private or protected. We + use this to make sure we don't try to generate a copy ctor for a + class that has a member of type NODE. */ +#define TYPE_HAS_NONPUBLIC_CTOR(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_nonpublic_ctor) + +/* Ditto, for operator=. */ +#define TYPE_HAS_NONPUBLIC_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_nonpublic_assign_ref) + +/* Many routines need to cons up a list of basetypes for access + checking. This field contains a TREE_LIST node whose TREE_VALUE + is the main variant of the type, and whose TREE_VIA_PUBLIC + and TREE_VIA_VIRTUAL bits are correctly set. */ +#define CLASSTYPE_AS_LIST(NODE) (TYPE_LANG_SPECIFIC(NODE)->as_list) +/* Same, but cache a list whose value is the name of this type. */ +#define CLASSTYPE_ID_AS_LIST(NODE) (TYPE_LANG_SPECIFIC(NODE)->id_as_list) +/* Same, but cache a list whose value is the binfo of this type. */ +#define CLASSTYPE_BINFO_AS_LIST(NODE) (TYPE_LANG_SPECIFIC(NODE)->binfo_as_list) + +/* A list of class types with which this type is a friend. */ +#define CLASSTYPE_FRIEND_CLASSES(NODE) (TYPE_LANG_SPECIFIC(NODE)->friend_classes) + +/* Keep an inheritance lattice around so we can quickly tell whether + a type is derived from another or not. */ +#define CLASSTYPE_MI_MATRIX(NODE) (TYPE_LANG_SPECIFIC(NODE)->mi_matrix) + +/* Say whether this node was declared as a "class" or a "struct". */ +#define CLASSTYPE_DECLARED_CLASS(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.declared_class) +/* whether this can be globalized. */ +#define CLASSTYPE_NO_GLOBALIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.no_globalize) + +/* Nonzero if this class has const members which have no specified initialization. */ +#define CLASSTYPE_READONLY_FIELDS_NEED_INIT(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.const_needs_init) + +/* Nonzero if this class has ref members which have no specified initialization. */ +#define CLASSTYPE_REF_FIELDS_NEED_INIT(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.ref_needs_init) + +/* Nonzero if this class is included from a header file which employs + `#pragma interface', and it is not included in its implementation file. */ +#define CLASSTYPE_INTERFACE_ONLY(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_only) + +/* Same as above, but for classes whose purpose we do not know. */ +#define CLASSTYPE_INTERFACE_UNKNOWN(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_unknown) +#define CLASSTYPE_INTERFACE_KNOWN(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_unknown == 0) +#define SET_CLASSTYPE_INTERFACE_UNKNOWN_X(NODE,X) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_unknown = !!(X)) +#define SET_CLASSTYPE_INTERFACE_UNKNOWN(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_unknown = 1) +#define SET_CLASSTYPE_INTERFACE_KNOWN(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.interface_unknown = 0) + +/* Nonzero if a _DECL node requires us to output debug info for this class. */ +#define CLASSTYPE_DEBUG_REQUESTED(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.debug_requested) + +#define TYPE_INCOMPLETE(NODE) \ + (TYPE_SIZE (NODE) == NULL_TREE && TREE_CODE (NODE) != TEMPLATE_TYPE_PARM) + +/* Additional macros for inheritance information. */ + +#define CLASSTYPE_VBINFO(NODE,VIA_PUBLIC) \ + (TYPE_LANG_SPECIFIC (NODE)->vbinfo[VIA_PUBLIC]) + +/* When following an binfo-specific chain, this is the cumulative + via-public flag. */ +#define BINFO_VIA_PUBLIC(NODE) TREE_LANG_FLAG_5 (NODE) + +/* When building a matrix to determine by a single lookup + whether one class is derived from another or not, + this field is the index of the class in the table. */ +#define CLASSTYPE_CID(NODE) (TYPE_LANG_SPECIFIC(NODE)->cid) +#define BINFO_CID(NODE) CLASSTYPE_CID(BINFO_TYPE(NODE)) + +/* Nonzero means marked by DFS or BFS search, including searches + by `get_binfo' and `get_base_distance'. */ +#define BINFO_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLASSTYPE_MARKED(BINFO_TYPE(NODE)):TREE_LANG_FLAG_0(NODE)) +/* Macros needed because of C compilers that don't allow conditional + expressions to be lvalues. Grr! */ +#define SET_BINFO_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?SET_CLASSTYPE_MARKED(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_0(NODE)=1)) +#define CLEAR_BINFO_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLEAR_CLASSTYPE_MARKED(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_0(NODE)=0)) + +/* Nonzero means marked in building initialization list. */ +#define BINFO_BASEINIT_MARKED(NODE) CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) +/* Modifier macros */ +#define SET_BINFO_BASEINIT_MARKED(NODE) SET_CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) +#define CLEAR_BINFO_BASEINIT_MARKED(NODE) CLEAR_CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) + +/* Nonzero means marked in search through virtual inheritance hierarchy. */ +#define BINFO_VBASE_MARKED(NODE) CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) +/* Modifier macros */ +#define SET_BINFO_VBASE_MARKED(NODE) SET_CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) +#define CLEAR_BINFO_VBASE_MARKED(NODE) CLEAR_CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)) + +/* Nonzero means marked in search for members or member functions. */ +#define BINFO_FIELDS_MARKED(NODE) \ + (TREE_VIA_VIRTUAL(NODE)?CLASSTYPE_MARKED2 (BINFO_TYPE (NODE)):TREE_LANG_FLAG_2(NODE)) +#define SET_BINFO_FIELDS_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?SET_CLASSTYPE_MARKED2(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_2(NODE)=1)) +#define CLEAR_BINFO_FIELDS_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLEAR_CLASSTYPE_MARKED2(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_2(NODE)=0)) + +/* Nonzero means that this class is on a path leading to a new vtable. */ +#define BINFO_VTABLE_PATH_MARKED(NODE) \ + (TREE_VIA_VIRTUAL(NODE)?CLASSTYPE_MARKED3(BINFO_TYPE(NODE)):TREE_LANG_FLAG_3(NODE)) +#define SET_BINFO_VTABLE_PATH_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?SET_CLASSTYPE_MARKED3(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_3(NODE)=1)) +#define CLEAR_BINFO_VTABLE_PATH_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLEAR_CLASSTYPE_MARKED3(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_3(NODE)=0)) + +/* Nonzero means that this class has a new vtable. */ +#define BINFO_NEW_VTABLE_MARKED(NODE) \ + (TREE_VIA_VIRTUAL(NODE)?CLASSTYPE_MARKED4(BINFO_TYPE(NODE)):TREE_LANG_FLAG_4(NODE)) +#define SET_BINFO_NEW_VTABLE_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?SET_CLASSTYPE_MARKED4(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_4(NODE)=1)) +#define CLEAR_BINFO_NEW_VTABLE_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLEAR_CLASSTYPE_MARKED4(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_4(NODE)=0)) + +/* Nonzero means this class has initialized its virtual baseclasses. */ +#define BINFO_VBASE_INIT_MARKED(NODE) \ + (TREE_VIA_VIRTUAL(NODE)?CLASSTYPE_MARKED5(BINFO_TYPE(NODE)):TREE_LANG_FLAG_5(NODE)) +#define SET_BINFO_VBASE_INIT_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?SET_CLASSTYPE_MARKED5(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_5(NODE)=1)) +#define CLEAR_BINFO_VBASE_INIT_MARKED(NODE) (TREE_VIA_VIRTUAL(NODE)?CLEAR_CLASSTYPE_MARKED5(BINFO_TYPE(NODE)):(TREE_LANG_FLAG_5(NODE)=0)) + +/* Accessor macros for the vfield slots in structures. */ + +/* Get the assoc info that caused this vfield to exist. */ +#define VF_BINFO_VALUE(NODE) TREE_PURPOSE (NODE) + +/* Get that same information as a _TYPE. */ +#define VF_BASETYPE_VALUE(NODE) TREE_VALUE (NODE) + +/* Get the value of the top-most type dominating the non-`normal' vfields. */ +#define VF_DERIVED_VALUE(NODE) (VF_BINFO_VALUE (NODE) ? BINFO_TYPE (VF_BINFO_VALUE (NODE)) : NULL_TREE) + +/* Get the value of the top-most type that's `normal' for the vfield. */ +#define VF_NORMAL_VALUE(NODE) TREE_TYPE (NODE) + +/* Nonzero for TREE_LIST node means that this list of things + is a list of parameters, as opposed to a list of expressions. */ +#define TREE_PARMLIST(NODE) ((NODE)->common.unsigned_flag) /* overloaded! */ + +/* For FUNCTION_TYPE or METHOD_TYPE, a list of the exceptions that + this type can raise. */ +#define TYPE_RAISES_EXCEPTIONS(NODE) TYPE_NONCOPIED_PARTS (NODE) + +/* The binding level associated with the namespace. */ +#define NAMESPACE_LEVEL(NODE) ((NODE)->decl.arguments) + +struct lang_decl_flags +{ +#ifdef ONLY_INT_FIELDS + int language : 8; +#else + enum languages language : 8; +#endif + + unsigned operator_attr : 1; + unsigned constructor_attr : 1; + unsigned returns_first_arg : 1; + unsigned preserves_first_arg : 1; + unsigned friend_attr : 1; + unsigned static_function : 1; + unsigned const_memfunc : 1; + unsigned volatile_memfunc : 1; + + unsigned abstract_virtual : 1; + unsigned permanent_attr : 1 ; + unsigned constructor_for_vbase_attr : 1; + unsigned mutable_flag : 1; + unsigned is_default_implementation : 1; + unsigned saved_inline : 1; + unsigned use_template : 2; + + unsigned c_static : 1; + unsigned nonconverting : 1; + unsigned declared_inline : 1; + unsigned not_really_extern : 1; + unsigned dummy : 4; + + tree access; + tree context; + tree memfunc_pointer_to; +}; + +struct lang_decl +{ + struct lang_decl_flags decl_flags; + + struct template_info *template_info; + tree main_decl_variant; + struct pending_inline *pending_inline_info; + tree next_method; + tree chain; +}; + +/* Non-zero if NODE is a _DECL with TREE_READONLY set. */ +#define TREE_READONLY_DECL_P(NODE) \ + (TREE_READONLY (NODE) && TREE_CODE_CLASS (TREE_CODE (NODE)) == 'd') + +/* For FUNCTION_DECLs: return the language in which this decl + was declared. */ +#define DECL_LANGUAGE(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.language) + +/* For FUNCTION_DECLs: nonzero means that this function is a constructor. */ +#define DECL_CONSTRUCTOR_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.constructor_attr) +/* For FUNCTION_DECLs: nonzero means that this function is a constructor + for an object with virtual baseclasses. */ +#define DECL_CONSTRUCTOR_FOR_VBASE_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.constructor_for_vbase_attr) + +/* For FUNCTION_DECLs: nonzero means that this function is a default + implementation of a signature method. */ +#define IS_DEFAULT_IMPLEMENTATION(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.is_default_implementation) + +/* For FUNCTION_DECLs: nonzero means that the constructor + is known to return a non-zero `this' unchanged. */ +#define DECL_RETURNS_FIRST_ARG(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.returns_first_arg) + +/* Nonzero for FUNCTION_DECL means that this constructor is known to + not make any assignment to `this', and therefore can be trusted + to return it unchanged. Otherwise, we must re-assign `current_class_decl' + after performing base initializations. */ +#define DECL_PRESERVES_THIS(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.preserves_first_arg) + +/* Nonzero for _DECL means that this decl appears in (or will appear + in) as a member in a RECORD_TYPE or UNION_TYPE node. It is also for + detecting circularity in case members are multiply defined. In the + case of a VAR_DECL, it is also used to determine how program storage + should be allocated. */ +#define DECL_IN_AGGR_P(NODE) (DECL_LANG_FLAG_3(NODE)) + +/* Nonzero for FUNCTION_DECL means that this decl is just a + friend declaration, and should not be added to the list of + member functions for this class. */ +#define DECL_FRIEND_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.friend_attr) + +/* Nonzero for FUNCTION_DECL means that this decl is a static + member function. */ +#define DECL_STATIC_FUNCTION_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.static_function) + +/* Nonzero for a class member means that it is shared between all objects + of that class. */ +#define SHARED_MEMBER_P(NODE) \ + (TREE_CODE (NODE) == VAR_DECL || TREE_CODE (NODE) == TYPE_DECL \ + || TREE_CODE (NODE) == CONST_DECL) + +/* Nonzero for FUNCTION_DECL means that this decl is a member function + (static or non-static). */ +#define DECL_FUNCTION_MEMBER_P(NODE) \ + (TREE_CODE (TREE_TYPE (NODE)) == METHOD_TYPE || DECL_STATIC_FUNCTION_P (NODE)) + +/* Nonzero for FUNCTION_DECL means that this member function + has `this' as const X *const. */ +#define DECL_CONST_MEMFUNC_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.const_memfunc) + +/* Nonzero for FUNCTION_DECL means that this member function + has `this' as volatile X *const. */ +#define DECL_VOLATILE_MEMFUNC_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.volatile_memfunc) + +/* Nonzero for _DECL means that this member object type + is mutable. */ +#define DECL_MUTABLE_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.mutable_flag) + +/* Nonzero for _DECL means that this constructor is a non-converting + constructor. */ +#define DECL_NONCONVERTING_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.nonconverting) + +/* Nonzero for FUNCTION_DECL means that this member function + exists as part of an abstract class's interface. */ +#define DECL_ABSTRACT_VIRTUAL_P(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.abstract_virtual) + +/* Nonzero if allocated on permanent_obstack. */ +#define LANG_DECL_PERMANENT(LANGDECL) ((LANGDECL)->decl_flags.permanent_attr) + +/* The _TYPE context in which this _DECL appears. This field holds the + class where a virtual function instance is actually defined, and the + lexical scope of a friend function defined in a class body. */ +#define DECL_CLASS_CONTEXT(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.context) +#define DECL_REAL_CONTEXT(NODE) \ + ((TREE_CODE (NODE) == FUNCTION_DECL && DECL_FUNCTION_MEMBER_P (NODE)) \ + ? DECL_CLASS_CONTEXT (NODE) : DECL_CONTEXT (NODE)) + +/* For a FUNCTION_DECL: the chain through which the next method + in the method chain is found. We now use TREE_CHAIN to + link into the FIELD_DECL chain. */ +#if 1 +#define DECL_CHAIN(NODE) (DECL_LANG_SPECIFIC(NODE)->chain) +#else +#define DECL_CHAIN(NODE) (TREE_CHAIN (NODE)) +#endif + +/* Next method in CLASSTYPE_METHODS list. */ +#define DECL_NEXT_METHOD(NODE) (DECL_LANG_SPECIFIC(NODE)->next_method) + +/* In a VAR_DECL for a variable declared in a for statement, + this is the shadowed variable. */ +#define DECL_SHADOWED_FOR_VAR(NODE) DECL_RESULT(NODE) + +/* Points back to the decl which caused this lang_decl to be allocated. */ +#define DECL_MAIN_VARIANT(NODE) (DECL_LANG_SPECIFIC(NODE)->main_decl_variant) + +/* For a FUNCTION_DECL: if this function was declared inline inside of + a class declaration, this is where the text for the function is + squirreled away. */ +#define DECL_PENDING_INLINE_INFO(NODE) (DECL_LANG_SPECIFIC(NODE)->pending_inline_info) + +/* True if on the saved_inlines (see decl2.c) list. */ +#define DECL_SAVED_INLINE(DECL) \ + (DECL_LANG_SPECIFIC(DECL)->decl_flags.saved_inline) + +/* For a FUNCTION_DECL: if this function was declared inside a signature + declaration, this is the corresponding member function pointer that was + created for it. */ +#define DECL_MEMFUNC_POINTER_TO(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.memfunc_pointer_to) + +/* For a FIELD_DECL: this points to the signature member function from + which this signature member function pointer was created. */ +#define DECL_MEMFUNC_POINTING_TO(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.memfunc_pointer_to) + +/* For a TEMPLATE_DECL: template-specific information. */ +#define DECL_TEMPLATE_INFO(NODE) (DECL_LANG_SPECIFIC(NODE)->template_info) + +/* Nonzero in INT_CST means that this int is negative by dint of + using a twos-complement negated operand. */ +#define TREE_NEGATED_INT(NODE) (TREE_LANG_FLAG_0 (NODE)) + +/* Nonzero in any kind of _EXPR or _REF node means that it is a call + to a storage allocation routine. If, later, alternate storage + is found to hold the object, this call can be ignored. */ +#define TREE_CALLS_NEW(NODE) (TREE_LANG_FLAG_1 (NODE)) + +/* Nonzero in any kind of _TYPE that uses multiple inheritance + or virtual baseclasses. */ +#define TYPE_USES_COMPLEX_INHERITANCE(NODE) (TREE_LANG_FLAG_1 (NODE)) + +/* Nonzero in IDENTIFIER_NODE means that this name is not the name the user + gave; it's a DECL_NESTED_TYPENAME. Someone may want to set this on + mangled function names, too, but it isn't currently. */ +#define TREE_MANGLED(NODE) (TREE_LANG_FLAG_0 (NODE)) + +#if 0 /* UNUSED */ +/* Nonzero in IDENTIFIER_NODE means that this name is overloaded, and + should be looked up in a non-standard way. */ +#define DECL_OVERLOADED(NODE) (DECL_LANG_FLAG_4 (NODE)) +#endif + +/* Nonzero if this (non-TYPE)_DECL has its virtual attribute set. + For a FUNCTION_DECL, this is when the function is a virtual function. + For a VAR_DECL, this is when the variable is a virtual function table. + For a FIELD_DECL, when the field is the field for the virtual function table. + For an IDENTIFIER_NODE, nonzero if any function with this name + has been declared virtual. + + For a _TYPE if it uses virtual functions (or is derived from + one that does). */ +#define TYPE_VIRTUAL_P(NODE) (TREE_LANG_FLAG_2 (NODE)) + +#if 0 +/* Same, but tells if this field is private in current context. */ +#define DECL_PRIVATE(NODE) (FOO) + +/* Same, but tells if this field is private in current context. */ +#define DECL_PROTECTED(NODE) (DECL_LANG_FLAG_6 (NODE)) + +#define DECL_PUBLIC(NODE) (DECL_LANG_FLAG_7 (NODE)) +#endif + +extern int flag_new_for_scope; + +/* This flag is true of a local VAR_DECL if it was declared in a for + statement, but we are no longer in the scope of the for. */ +#define DECL_DEAD_FOR_LOCAL(NODE) DECL_LANG_FLAG_7 (NODE) + +/* This flag is set on a VAR_DECL that is a DECL_DEAD_FOR_LOCAL + if we already emitted a warning about using it. */ +#define DECL_ERROR_REPORTED(NODE) DECL_LANG_FLAG_0 (NODE) + +/* This _DECL represents a compiler-generated entity. */ +#define SET_DECL_ARTIFICIAL(NODE) (DECL_ARTIFICIAL (NODE) = 1) + +/* Record whether a typedef for type `int' was actually `signed int'. */ +#define C_TYPEDEF_EXPLICITLY_SIGNED(exp) DECL_LANG_FLAG_1 ((exp)) + +/* Nonzero if the type T promotes to itself. + ANSI C states explicitly the list of types that promote; + in particular, short promotes to int even if they have the same width. */ +#define C_PROMOTING_INTEGER_TYPE_P(t) \ + (TREE_CODE ((t)) == INTEGER_TYPE \ + && (TYPE_MAIN_VARIANT (t) == char_type_node \ + || TYPE_MAIN_VARIANT (t) == signed_char_type_node \ + || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node \ + || TYPE_MAIN_VARIANT (t) == short_integer_type_node \ + || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node)) + +#define INTEGRAL_CODE_P(CODE) \ + (CODE == INTEGER_TYPE || CODE == ENUMERAL_TYPE || CODE == BOOLEAN_TYPE) +#define ARITHMETIC_TYPE_P(TYPE) (INTEGRAL_TYPE_P (TYPE) || FLOAT_TYPE_P (TYPE)) + +/* Mark which labels are explicitly declared. + These may be shadowed, and may be referenced from nested functions. */ +#define C_DECLARED_LABEL_FLAG(label) TREE_LANG_FLAG_1 (label) + +/* Record whether a type or decl was written with nonconstant size. + Note that TYPE_SIZE may have simplified to a constant. */ +#define C_TYPE_VARIABLE_SIZE(type) TREE_LANG_FLAG_4 (type) +#define C_DECL_VARIABLE_SIZE(type) DECL_LANG_FLAG_8 (type) + +/* Nonzero for _TYPE means that the _TYPE defines + at least one constructor. */ +#define TYPE_HAS_CONSTRUCTOR(NODE) (TYPE_LANG_FLAG_1(NODE)) + +/* When appearing in an INDIRECT_REF, it means that the tree structure + underneath is actually a call to a constructor. This is needed + when the constructor must initialize local storage (which can + be automatically destroyed), rather than allowing it to allocate + space from the heap. + + When appearing in a SAVE_EXPR, it means that underneath + is a call to a constructor. + + When appearing in a CONSTRUCTOR, it means that it was + a GNU C constructor expression. + + When appearing in a FIELD_DECL, it means that this field + has been duly initialized in its constructor. */ +#define TREE_HAS_CONSTRUCTOR(NODE) (TREE_LANG_FLAG_4(NODE)) + +#define EMPTY_CONSTRUCTOR_P(NODE) (TREE_CODE (NODE) == CONSTRUCTOR \ + && CONSTRUCTOR_ELTS (NODE) == NULL_TREE) + +/* Indicates that a NON_LVALUE_EXPR came from a C++ reference. + Used to generate more helpful error message in case somebody + tries to take its address. */ +#define TREE_REFERENCE_EXPR(NODE) (TREE_LANG_FLAG_3(NODE)) + +/* Nonzero for _TYPE means that the _TYPE defines a destructor. */ +#define TYPE_HAS_DESTRUCTOR(NODE) (TYPE_LANG_FLAG_2(NODE)) + +#if 0 +/* Nonzero for _TYPE node means that creating an object of this type + will involve a call to a constructor. This can apply to objects + of ARRAY_TYPE if the type of the elements needs a constructor. */ +#define TYPE_NEEDS_CONSTRUCTING(NODE) (TYPE_LANG_FLAG_3(NODE)) +#endif + +/* Nonzero means that an object of this type can not be initialized using + an initializer list. */ +#define CLASSTYPE_NON_AGGREGATE(NODE) \ + (TYPE_LANG_SPECIFIC (NODE)->type_flags.non_aggregate) +#define TYPE_NON_AGGREGATE_CLASS(NODE) \ + (IS_AGGR_TYPE (NODE) && CLASSTYPE_NON_AGGREGATE (NODE)) + +/* Nonzero if there is a user-defined X::op=(x&) for this class. */ +#define TYPE_HAS_REAL_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_real_assign_ref) +#define TYPE_HAS_COMPLEX_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_complex_assign_ref) +#define TYPE_HAS_ABSTRACT_ASSIGN_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_abstract_assign_ref) +#define TYPE_HAS_COMPLEX_INIT_REF(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.has_complex_init_ref) + +/* Nonzero for _TYPE node means that destroying an object of this type + will involve a call to a destructor. This can apply to objects + of ARRAY_TYPE is the type of the elements needs a destructor. */ +#define TYPE_NEEDS_DESTRUCTOR(NODE) (TYPE_LANG_FLAG_4(NODE)) + +/* Nonzero for class type means that initialization of this type can use + a bitwise copy. */ +#define TYPE_HAS_TRIVIAL_INIT_REF(NODE) \ + (TYPE_HAS_INIT_REF (NODE) && ! TYPE_HAS_COMPLEX_INIT_REF (NODE)) + +/* Nonzero for class type means that assignment of this type can use + a bitwise copy. */ +#define TYPE_HAS_TRIVIAL_ASSIGN_REF(NODE) \ + (TYPE_HAS_ASSIGN_REF (NODE) && ! TYPE_HAS_COMPLEX_ASSIGN_REF (NODE)) + +/* Nonzero for _TYPE node means that this type is a pointer to member + function type. */ +#define TYPE_PTRMEMFUNC_P(NODE) (TREE_CODE(NODE) == RECORD_TYPE && TYPE_LANG_SPECIFIC(NODE)->type_flags.ptrmemfunc_flag) +#define TYPE_PTRMEMFUNC_FLAG(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.ptrmemfunc_flag) +/* Get the POINTER_TYPE to the METHOD_TYPE associated with this + pointer to member function. TYPE_PTRMEMFUNC_P _must_ be true, + before using this macro. */ +#define TYPE_PTRMEMFUNC_FN_TYPE(NODE) (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (NODE))))))) +/* These are use to manipulate the the canonical RECORD_TYPE from the + hashed POINTER_TYPE, and can only be used on the POINTER_TYPE. */ +#define TYPE_GET_PTRMEMFUNC_TYPE(NODE) ((tree)TYPE_LANG_SPECIFIC(NODE)) +#define TYPE_SET_PTRMEMFUNC_TYPE(NODE, VALUE) (TYPE_LANG_SPECIFIC(NODE) = ((struct lang_type *)(void*)(VALUE))) +/* These are to get the delta2 and pfn fields from a TYPE_PTRMEMFUNC_P. */ +#define DELTA2_FROM_PTRMEMFUNC(NODE) (build_component_ref (build_component_ref ((NODE), pfn_or_delta2_identifier, 0, 0), delta2_identifier, 0, 0)) +#define PFN_FROM_PTRMEMFUNC(NODE) (build_component_ref (build_component_ref ((NODE), pfn_or_delta2_identifier, 0, 0), pfn_identifier, 0, 0)) + +/* Nonzero for VAR_DECL and FUNCTION_DECL node means that `extern' was + specified in its declaration. */ +#define DECL_THIS_EXTERN(NODE) (DECL_LANG_FLAG_2(NODE)) + +/* Nonzero for VAR_DECL and FUNCTION_DECL node means that `static' was + specified in its declaration. */ +#define DECL_THIS_STATIC(NODE) (DECL_LANG_FLAG_6(NODE)) + +/* Nonzero for SAVE_EXPR if used to initialize a PARM_DECL. */ +#define PARM_DECL_EXPR(NODE) (TREE_LANG_FLAG_2(NODE)) + +/* Nonzero in FUNCTION_DECL means it is really an operator. + Just used to communicate formatting information to dbxout.c. */ +#define DECL_OPERATOR(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.operator_attr) + +#define ANON_UNION_P(NODE) (DECL_NAME (NODE) == 0) + +#define UNKNOWN_TYPE LANG_TYPE + +/* Define fields and accessors for nodes representing declared names. */ + +#if 0 +/* C++: A derived class may be able to directly use the virtual + function table of a base class. When it does so, it may + still have a decl node used to access the virtual function + table (so that variables of this type can initialize their + virtual function table pointers by name). When such thievery + is committed, know exactly which base class's virtual function + table is the one being stolen. This effectively computes the + transitive closure. */ +#define DECL_VPARENT(NODE) ((NODE)->decl.arguments) +#endif + +/* Make a slot so we can implement nested types. This slot holds + the IDENTIFIER_NODE that uniquely names the nested type. This + is for TYPE_DECLs only. */ +#define DECL_NESTED_TYPENAME(NODE) ((NODE)->decl.arguments) +#define TYPE_NESTED_NAME(NODE) (DECL_NESTED_TYPENAME (TYPE_NAME (NODE))) + +#define TYPE_WAS_ANONYMOUS(NODE) (TYPE_LANG_SPECIFIC (NODE)->type_flags.was_anonymous) + +/* C++: all of these are overloaded! These apply only to TYPE_DECLs. */ +#define DECL_FRIENDLIST(NODE) (DECL_INITIAL (NODE)) +#if 0 +#define DECL_UNDEFINED_FRIENDS(NODE) ((NODE)->decl.result) +#endif +#define DECL_WAITING_FRIENDS(NODE) ((tree)(NODE)->decl.rtl) +#define SET_DECL_WAITING_FRIENDS(NODE,VALUE) \ + ((NODE)->decl.rtl=(struct rtx_def*)VALUE) + +/* The DECL_ACCESS is used to record under which context + special access rules apply. */ +#define DECL_ACCESS(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.access) + +/* C++: all of these are overloaded! + These apply to PARM_DECLs and VAR_DECLs. */ +#define DECL_REFERENCE_SLOT(NODE) ((tree)(NODE)->decl.arguments) +#define SET_DECL_REFERENCE_SLOT(NODE,VAL) ((NODE)->decl.arguments=VAL) + +/* For local VAR_DECLs, holds index into gc-protected obstack. */ +#define DECL_GC_OFFSET(NODE) ((NODE)->decl.result) + +/* Accessor macros for C++ template decl nodes. */ +#define DECL_TEMPLATE_IS_CLASS(NODE) (DECL_RESULT(NODE) == NULL_TREE) +#define DECL_TEMPLATE_PARMS(NODE) DECL_ARGUMENTS(NODE) +/* For class templates. */ +#define DECL_TEMPLATE_MEMBERS(NODE) DECL_SIZE(NODE) +/* For function, method, class-data templates. */ +#define DECL_TEMPLATE_RESULT(NODE) DECL_RESULT(NODE) +#define DECL_TEMPLATE_INSTANTIATIONS(NODE) DECL_VINDEX(NODE) + +/* Indicates whether or not (and how) a template was expanded for this + FUNCTION_DECL or VAR_DECL. + 0=normal declaration, e.g. int min (int, int); + 1=implicit template instantiation + 2=explicit template specialization, e.g. int min (int, int); + 3=explicit template instantiation, e.g. template int min (int, int); + */ +#define DECL_USE_TEMPLATE(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.use_template) + +#define DECL_TEMPLATE_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) & 1) +#define CLASSTYPE_TEMPLATE_INSTANTIATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE (NODE) & 1) + +#define DECL_TEMPLATE_SPECIALIZATION(NODE) (DECL_USE_TEMPLATE (NODE) == 2) +#define SET_DECL_TEMPLATE_SPECIALIZATION(NODE) (DECL_USE_TEMPLATE (NODE) = 2) +#define CLASSTYPE_TEMPLATE_SPECIALIZATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE (NODE) == 2) +#define SET_CLASSTYPE_TEMPLATE_SPECIALIZATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE (NODE) = 2) + +#define DECL_IMPLICIT_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) == 1) +#define SET_DECL_IMPLICIT_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) = 1) +#define CLASSTYPE_IMPLICIT_INSTANTIATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE(NODE) == 1) +#define SET_CLASSTYPE_IMPLICIT_INSTANTIATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE(NODE) = 1) + +#define DECL_EXPLICIT_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) == 3) +#define SET_DECL_EXPLICIT_INSTANTIATION(NODE) (DECL_USE_TEMPLATE (NODE) = 3) +#define CLASSTYPE_EXPLICIT_INSTANTIATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE(NODE) == 3) +#define SET_CLASSTYPE_EXPLICIT_INSTANTIATION(NODE) \ + (CLASSTYPE_USE_TEMPLATE(NODE) = 3) + +/* We know what we're doing with this decl now. */ +#define DECL_INTERFACE_KNOWN(NODE) DECL_LANG_FLAG_5 (NODE) + +/* This decl was declared or deduced to have internal linkage. This is + only meaningful if TREE_PUBLIC is set. */ +#define DECL_C_STATIC(NODE) \ + (DECL_LANG_SPECIFIC (NODE)->decl_flags.c_static) + +/* This function was declared inline. This flag controls the linkage + semantics of 'inline'; whether or not the function is inlined is + controlled by DECL_INLINE. */ +#define DECL_THIS_INLINE(NODE) \ + (DECL_LANG_SPECIFIC (NODE)->decl_flags.declared_inline) + +/* DECL_EXTERNAL must be set on a decl until the decl is actually emitted, + so that assemble_external will work properly. So we have this flag to + tell us whether the decl is really not external. */ +#define DECL_NOT_REALLY_EXTERN(NODE) \ + (DECL_LANG_SPECIFIC (NODE)->decl_flags.not_really_extern) + +#define DECL_PUBLIC(NODE) \ + (TREE_CODE (NODE) == FUNCTION_DECL \ + ? ! DECL_C_STATIC (NODE) : TREE_PUBLIC (NODE)) + +#define THUNK_DELTA(DECL) ((DECL)->decl.frame_size.i) + +/* ...and for unexpanded-parameterized-type nodes. */ +#define UPT_TEMPLATE(NODE) TREE_PURPOSE(TYPE_VALUES(NODE)) +#define UPT_PARMS(NODE) TREE_VALUE(TYPE_VALUES(NODE)) + +/* An enumeration of the kind of tags that C++ accepts. */ +enum tag_types { record_type, class_type, union_type, enum_type, + signature_type }; + +/* Zero means prototype weakly, as in ANSI C (no args means nothing). + Each language context defines how this variable should be set. */ +extern int strict_prototype; +extern int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus; + +/* Non-zero means that if a label exists, and no other identifier + applies, use the value of the label. */ +extern int flag_labels_ok; + +/* Non-zero means to collect statistics which might be expensive + and to print them when we are done. */ +extern int flag_detailed_statistics; + +/* Non-zero means warn in function declared in derived class has the + same name as a virtual in the base class, but fails to match the + type signature of any virtual function in the base class. */ +extern int warn_overloaded_virtual; + +/* in c-common.c */ +extern void declare_function_name PROTO((void)); +extern void decl_attributes PROTO((tree, tree, tree)); +extern void init_function_format_info PROTO((void)); +extern void record_function_format PROTO((tree, tree, int, int, int)); +extern void check_function_format PROTO((tree, tree, tree)); +/* Print an error message for invalid operands to arith operation CODE. + NOP_EXPR is used as a special case (see truthvalue_conversion). */ +extern void binary_op_error PROTO((enum tree_code)); +extern tree cp_build_type_variant PROTO((tree, int, int)); +extern void c_expand_expr_stmt PROTO((tree)); +/* Validate the expression after `case' and apply default promotions. */ +extern tree check_case_value PROTO((tree)); +/* Concatenate a list of STRING_CST nodes into one STRING_CST. */ +extern tree combine_strings PROTO((tree)); +extern void constant_expression_warning PROTO((tree)); +extern tree convert_and_check PROTO((tree, tree)); +extern void overflow_warning PROTO((tree)); +extern void unsigned_conversion_warning PROTO((tree, tree)); +/* Read the rest of the current #-directive line. */ +extern char *get_directive_line STDIO_PROTO((FILE *)); +/* Subroutine of build_binary_op, used for comparison operations. + See if the operands have both been converted from subword integer types + and, if so, perhaps change them both back to their original type. */ +extern tree shorten_compare PROTO((tree *, tree *, tree *, enum tree_code *)); +/* Prepare expr to be an argument of a TRUTH_NOT_EXPR, + or validate its data type for an `if' or `while' statement or ?..: exp. */ +extern tree truthvalue_conversion PROTO((tree)); +extern tree type_for_mode PROTO((enum machine_mode, int)); +extern tree type_for_size PROTO((unsigned, int)); + +/* in decl{2}.c */ +extern tree void_list_node; +extern tree void_zero_node; +extern tree default_function_type; +extern tree vtable_entry_type; +extern tree sigtable_entry_type; +extern tree __t_desc_type_node; +extern tree __tp_desc_type_node; +extern tree __access_mode_type_node; +extern tree __bltn_desc_type_node, __user_desc_type_node; +extern tree __class_desc_type_node, __attr_desc_type_node; +extern tree __ptr_desc_type_node, __func_desc_type_node; +extern tree __ptmf_desc_type_node, __ptmd_desc_type_node; +extern tree type_info_type_node; +extern tree class_star_type_node; +extern tree this_identifier; +extern tree pfn_identifier; +extern tree index_identifier; +extern tree delta_identifier; +extern tree delta2_identifier; +extern tree pfn_or_delta2_identifier; +extern tree tag_identifier; +extern tree vb_off_identifier; +extern tree vt_off_identifier; + +/* A node that is a list (length 1) of error_mark_nodes. */ +extern tree error_mark_list; + +extern tree ptr_type_node, const_ptr_type_node; +extern tree class_type_node, record_type_node, union_type_node, enum_type_node; +extern tree unknown_type_node; +extern tree opaque_type_node, signature_type_node; + +/* Node for "pointer to (virtual) function". + This may be distinct from ptr_type_node so gdb can distinguish them. */ +#define vfunc_ptr_type_node \ + (flag_vtable_thunks ? vtable_entry_type : ptr_type_node) + +/* Array type `(void *)[]' */ +extern tree vtbl_type_node; +extern tree delta_type_node; + +extern tree long_long_integer_type_node, long_long_unsigned_type_node; +/* For building calls to `delete'. */ +extern tree integer_two_node, integer_three_node; +extern tree boolean_type_node, boolean_true_node, boolean_false_node; + +/* in pt.c */ +/* PARM_VEC is a vector of template parameters, either IDENTIFIER_NODEs or + PARM_DECLs. BINDINGS, if non-null, is a vector of bindings for those + parameters. */ +struct template_info { + /* Vector of template parameters, either PARM_DECLs or IDENTIFIER_NODEs. */ + tree parm_vec; + /* If non-null, a vector of bindings for the template parms. */ + tree bindings; + + /* Text of template, and length. */ + char *text; + int length; + /* Where it came from. */ + char *filename; + int lineno; + + /* What kind of aggregate -- struct, class, or null. */ + tree aggr; +}; +extern int processing_template_decl, processing_template_defn; + +/* The template currently being instantiated, and where the instantiation + was triggered. */ +struct tinst_level +{ + tree classname; + int line; + char *file; + struct tinst_level *next; +}; + +/* in class.c */ +extern tree current_class_name; +extern tree current_class_type; +extern tree previous_class_type; + +extern tree current_lang_name, lang_name_cplusplus, lang_name_c; + +/* Points to the name of that function. May not be the DECL_NAME + of CURRENT_FUNCTION_DECL due to overloading */ +extern tree original_function_name; + +extern tree current_class_name, current_class_type, current_class_decl, C_C_D; + +/* in init.c */ +extern tree global_base_init_list; +extern tree current_base_init_list, current_member_init_list; + +extern int current_function_assigns_this; +extern int current_function_just_assigned_this; +extern int current_function_parms_stored; + +/* Here's where we control how name mangling takes place. */ + +#define OPERATOR_ASSIGN_FORMAT "__a%s" +#define OPERATOR_FORMAT "__%s" +#define OPERATOR_TYPENAME_FORMAT "__op" +#define OPERATOR_TYPENAME_P(ID_NODE) \ + (IDENTIFIER_POINTER (ID_NODE)[0] == '_' \ + && IDENTIFIER_POINTER (ID_NODE)[1] == '_' \ + && IDENTIFIER_POINTER (ID_NODE)[2] == 'o' \ + && IDENTIFIER_POINTER (ID_NODE)[3] == 'p') + + +/* Cannot use '$' up front, because this confuses gdb + (names beginning with '$' are gdb-local identifiers). + + Note that all forms in which the '$' is significant are long enough + for direct indexing (meaning that if we know there is a '$' + at a particular location, we can index into the string at + any other location that provides distinguishing characters). */ + +/* Define NO_DOLLAR_IN_LABEL in your favorite tm file if your assembler + doesn't allow '$' in symbol names. */ +#ifndef NO_DOLLAR_IN_LABEL + +#define JOINER '$' + +#define VPTR_NAME "$v" +#define THROW_NAME "$eh_throw" +#define DESTRUCTOR_DECL_PREFIX "_$_" +#define AUTO_VTABLE_NAME "__vtbl$me__" +#define AUTO_TEMP_NAME "_$tmp_" +#define AUTO_TEMP_FORMAT "_$tmp_%d" +#define VTABLE_BASE "$vb" +#define VTABLE_NAME_FORMAT (flag_vtable_thunks ? "__vt_%s" : "_vt$%s") +#define VFIELD_BASE "$vf" +#define VFIELD_NAME "_vptr$" +#define VFIELD_NAME_FORMAT "_vptr$%s" +#define VBASE_NAME "_vb$" +#define VBASE_NAME_FORMAT "_vb$%s" +#define STATIC_NAME_FORMAT "_%s$%s" +#define ANON_AGGRNAME_FORMAT "$_%d" + +#else /* NO_DOLLAR_IN_LABEL */ + +#ifndef NO_DOT_IN_LABEL + +#define JOINER '.' + +#define VPTR_NAME ".v" +#define THROW_NAME ".eh_throw" +#define DESTRUCTOR_DECL_PREFIX "_._" +#define AUTO_VTABLE_NAME "__vtbl.me__" +#define AUTO_TEMP_NAME "_.tmp_" +#define AUTO_TEMP_FORMAT "_.tmp_%d" +#define VTABLE_BASE ".vb" +#define VTABLE_NAME_FORMAT (flag_vtable_thunks ? "__vt_%s" : "_vt.%s") +#define VFIELD_BASE ".vf" +#define VFIELD_NAME "_vptr." +#define VFIELD_NAME_FORMAT "_vptr.%s" +#define VBASE_NAME "_vb." +#define VBASE_NAME_FORMAT "_vb.%s" +#define STATIC_NAME_FORMAT "_%s.%s" + +#define ANON_AGGRNAME_FORMAT "._%d" + +#else /* NO_DOT_IN_LABEL */ + +#define VPTR_NAME "__vptr" +#define VPTR_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), VPTR_NAME, sizeof (VPTR_NAME) - 1)) +#define THROW_NAME "__eh_throw" +#define DESTRUCTOR_DECL_PREFIX "__destr_" +#define DESTRUCTOR_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), DESTRUCTOR_DECL_PREFIX, \ + sizeof (DESTRUCTOR_DECL_PREFIX) - 1)) +#define IN_CHARGE_NAME "__in_chrg" +#define AUTO_VTABLE_NAME "__vtbl_me__" +#define AUTO_TEMP_NAME "__tmp_" +#define TEMP_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), AUTO_TEMP_NAME, \ + sizeof (AUTO_TEMP_NAME) - 1)) +#define AUTO_TEMP_FORMAT "__tmp_%d" +#define VTABLE_BASE "__vtb" +#define VTABLE_NAME "__vt_" +#define VTABLE_NAME_FORMAT (flag_vtable_thunks ? "__vt_%s" : "_vt_%s") +#define VTABLE_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), VTABLE_NAME, \ + sizeof (VTABLE_NAME) - 1)) +#define VFIELD_BASE "__vfb" +#define VFIELD_NAME "__vptr_" +#define VFIELD_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), VFIELD_NAME, \ + sizeof (VFIELD_NAME) - 1)) +#define VFIELD_NAME_FORMAT "_vptr_%s" +#define VBASE_NAME "__vb_" +#define VBASE_NAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), VBASE_NAME, \ + sizeof (VBASE_NAME) - 1)) +#define VBASE_NAME_FORMAT "__vb_%s" +#define STATIC_NAME_FORMAT "__static_%s_%s" + +#define ANON_AGGRNAME_PREFIX "__anon_" +#define ANON_AGGRNAME_P(ID_NODE) \ + (!strncmp (IDENTIFIER_POINTER (ID_NODE), ANON_AGGRNAME_PREFIX, \ + sizeof (ANON_AGGRNAME_PREFIX) - 1)) +#define ANON_AGGRNAME_FORMAT "__anon_%d" +#define ANON_PARMNAME_FORMAT "__%d" +#define ANON_PARMNAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[0] == '_' \ + && IDENTIFIER_POINTER (ID_NODE)[1] == '_' \ + && IDENTIFIER_POINTER (ID_NODE)[2] <= '9') + +#endif /* NO_DOT_IN_LABEL */ +#endif /* NO_DOLLAR_IN_LABEL */ + +#define THIS_NAME "this" +#define DESTRUCTOR_NAME_FORMAT "~%s" +#define FILE_FUNCTION_PREFIX_LEN 9 + +#define IN_CHARGE_NAME "__in_chrg" + +#define VTBL_PTR_TYPE "__vtbl_ptr_type" +#define VTABLE_DELTA_NAME "__delta" +#define VTABLE_INDEX_NAME "__index" +#define VTABLE_PFN_NAME "__pfn" +#define VTABLE_DELTA2_NAME "__delta2" + +#define SIGNATURE_FIELD_NAME "__s_" +#define SIGNATURE_FIELD_NAME_FORMAT "__s_%s" +#define SIGNATURE_OPTR_NAME "__optr" +#define SIGNATURE_SPTR_NAME "__sptr" +#define SIGNATURE_POINTER_NAME "__sp_" +#define SIGNATURE_POINTER_NAME_FORMAT "__%s%ssp_%s" +#define SIGNATURE_REFERENCE_NAME "__sr_" +#define SIGNATURE_REFERENCE_NAME_FORMAT "__%s%ssr_%s" + +#define SIGTABLE_PTR_TYPE "__sigtbl_ptr_type" +#define SIGTABLE_NAME_FORMAT "__st_%s_%s" +#define SIGTABLE_NAME_FORMAT_LONG "__st_%s_%s_%d" +#define SIGTABLE_TAG_NAME "__tag" +#define SIGTABLE_VB_OFF_NAME "__vb_off" +#define SIGTABLE_VT_OFF_NAME "__vt_off" +#define EXCEPTION_CLEANUP_NAME "exception cleanup" + +#define THIS_NAME_P(ID_NODE) (strcmp(IDENTIFIER_POINTER (ID_NODE), "this") == 0) + +#if !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL) + +#define VPTR_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[0] == JOINER \ + && IDENTIFIER_POINTER (ID_NODE)[1] == 'v') +#define DESTRUCTOR_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == JOINER \ + && IDENTIFIER_POINTER (ID_NODE)[2] == '_') + +#define VTABLE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \ + && IDENTIFIER_POINTER (ID_NODE)[2] == 't' \ + && IDENTIFIER_POINTER (ID_NODE)[3] == JOINER) + +#define VBASE_NAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[1] == 'v' \ + && IDENTIFIER_POINTER (ID_NODE)[2] == 'b' \ + && IDENTIFIER_POINTER (ID_NODE)[3] == JOINER) + +#define TEMP_NAME_P(ID_NODE) (!strncmp (IDENTIFIER_POINTER (ID_NODE), AUTO_TEMP_NAME, sizeof (AUTO_TEMP_NAME)-1)) +#define VFIELD_NAME_P(ID_NODE) (!strncmp (IDENTIFIER_POINTER (ID_NODE), VFIELD_NAME, sizeof(VFIELD_NAME)-1)) + +/* For anonymous aggregate types, we need some sort of name to + hold on to. In practice, this should not appear, but it should + not be harmful if it does. */ +#define ANON_AGGRNAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[0] == JOINER \ + && IDENTIFIER_POINTER (ID_NODE)[1] == '_') +#define ANON_PARMNAME_FORMAT "_%d" +#define ANON_PARMNAME_P(ID_NODE) (IDENTIFIER_POINTER (ID_NODE)[0] == '_' \ + && IDENTIFIER_POINTER (ID_NODE)[1] <= '9') +#endif /* !defined(NO_DOLLAR_IN_LABEL) || !defined(NO_DOT_IN_LABEL) */ + +/* Define the sets of attributes that member functions and baseclasses + can have. These are sensible combinations of {public,private,protected} + cross {virtual,non-virtual}. */ + +enum access_type { + access_default, + access_public, + access_protected, + access_private, + access_default_virtual, + access_public_virtual, + access_private_virtual +}; + +/* in lex.c */ +extern tree current_unit_name, current_unit_language; + +/* Things for handling inline functions. */ + +struct pending_inline +{ + struct pending_inline *next; /* pointer to next in chain */ + int lineno; /* line number we got the text from */ + char *filename; /* name of file we were processing */ + tree fndecl; /* FUNCTION_DECL that brought us here */ + int token; /* token we were scanning */ + int token_value; /* value of token we were scanning (YYSTYPE) */ + + char *buf; /* pointer to character stream */ + int len; /* length of stream */ + tree parm_vec, bindings; /* in case this is derived from a template */ + unsigned int can_free : 1; /* free this after we're done with it? */ + unsigned int deja_vu : 1; /* set iff we don't want to see it again. */ + unsigned int interface : 2; /* 0=interface 1=unknown 2=implementation */ +}; + +/* in method.c */ +extern struct pending_inline *pending_inlines; + +/* 1 for -fall-virtual: make every member function (except + constructors) lay down in the virtual function table. + Calls can then either go through the virtual function table or not, + depending on whether we know what function will actually be called. */ + +extern int flag_all_virtual; + +/* Positive values means that we cannot make optimizing assumptions about + `this'. Negative values means we know `this' to be of static type. */ + +extern int flag_this_is_variable; + +/* Controls whether enums and ints freely convert. + 1 means with complete freedom. + 0 means enums can convert to ints, but not vice-versa. */ + +extern int flag_int_enum_equivalence; + +/* Nonzero means layout structures so that we can do garbage collection. */ + +extern int flag_gc; + +/* Nonzero means generate 'rtti' that give run-time type information. */ + +extern int flag_rtti; + +/* Nonzero means do emit exported implementations of functions even if + they can be inlined. */ + +extern int flag_implement_inlines; + +/* Nonzero means templates obey #pragma interface and implementation. */ + +extern int flag_external_templates; + +/* Nonzero means templates are emitted where they are instantiated. */ + +extern int flag_alt_external_templates; + +/* Nonzero means implicit template instantiations are emitted. */ + +extern int flag_implicit_templates; + +/* Current end of entries in the gc obstack for stack pointer variables. */ + +extern int current_function_obstack_index; + +/* Flag saying whether we have used the obstack in this function or not. */ + +extern int current_function_obstack_usage; + +enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, OP_FLAG, TYPENAME_FLAG }; + +extern tree current_class_decl, C_C_D; /* PARM_DECL: the class instance variable */ + +/* The following two can be derived from the previous one */ +extern tree current_class_name; /* IDENTIFIER_NODE: name of current class */ +extern tree current_class_type; /* _TYPE: the type of the current class */ + +/* Some macros for char-based bitfields. */ +#define B_SET(a,x) (a[x>>3] |= (1 << (x&7))) +#define B_CLR(a,x) (a[x>>3] &= ~(1 << (x&7))) +#define B_TST(a,x) (a[x>>3] & (1 << (x&7))) + +/* These are uses as bits in flags passed to build_method_call + to control its error reporting behavior. + + LOOKUP_PROTECT means flag access violations. + LOOKUP_COMPLAIN mean complain if no suitable member function + matching the arguments is found. + LOOKUP_NORMAL is just a combination of these two. + LOOKUP_AGGR requires the instance to be of aggregate type. + LOOKUP_NONVIRTUAL means make a direct call to the member function found + LOOKUP_GLOBAL means search through the space of overloaded functions, + as well as the space of member functions. + LOOKUP_HAS_IN_CHARGE means that the "in charge" variable is already + in the parameter list. + LOOKUP_ONLYCONVERTING means that non-conversion constructors are not tried. + LOOKUP_SPECULATIVELY means return NULL_TREE if we cannot find what we are + after. Note, LOOKUP_COMPLAIN is checked and error messages printed + before LOOKUP_SPECULATIVELY is checked. + LOOKUP_NO_CONVERSION means that user-defined conversions are not + permitted. Built-in conversions are permitted. + LOOKUP_DESTRUCTOR means explicit call to destructor. */ + +#define LOOKUP_PROTECT (1) +#define LOOKUP_COMPLAIN (2) +#define LOOKUP_NORMAL (3) +#define LOOKUP_AGGR (4) +#define LOOKUP_NONVIRTUAL (8) +#define LOOKUP_GLOBAL (16) +#define LOOKUP_HAS_IN_CHARGE (32) +#define LOOKUP_SPECULATIVELY (64) +#define LOOKUP_ONLYCONVERTING (128) +/* 256 is free */ +#define LOOKUP_NO_CONVERSION (512) +#define LOOKUP_DESTRUCTOR (512) + +/* These flags are used by the conversion code. + CONV_IMPLICIT : Perform implicit conversions (standard and user-defined). + CONV_STATIC : Perform the explicit conversions for static_cast. + CONV_CONST : Perform the explicit conversions for const_cast. + CONV_REINTERPRET: Perform the explicit conversions for reinterpret_cast. + CONV_PRIVATE : Perform upcasts to private bases. + CONV_NONCONVERTING : Allow non-converting constructors to be used. + CONV_FORCE_TEMP : Require a new temporary when converting to the same + aggregate type. */ + +#define CONV_IMPLICIT 1 +#define CONV_STATIC 2 +#define CONV_CONST 4 +#define CONV_REINTERPRET 8 +#define CONV_PRIVATE 16 +#define CONV_NONCONVERTING 32 +#define CONV_FORCE_TEMP 64 +#define CONV_STATIC_CAST (CONV_IMPLICIT | CONV_STATIC | CONV_FORCE_TEMP) +#define CONV_OLD_CONVERT (CONV_IMPLICIT | CONV_STATIC | CONV_CONST \ + | CONV_REINTERPRET) +#define CONV_C_CAST (CONV_IMPLICIT | CONV_STATIC | CONV_CONST \ + | CONV_REINTERPRET | CONV_PRIVATE | CONV_FORCE_TEMP) + +/* Used by build_expr_type_conversion to indicate which types are + acceptable as arguments to the expression under consideration. */ + +#define WANT_INT 1 /* integer types, including bool */ +#define WANT_FLOAT 2 /* floating point types */ +#define WANT_ENUM 4 /* enumerated types */ +#define WANT_POINTER 8 /* pointer types */ +#define WANT_NULL 16 /* null pointer constant */ + +#define WANT_ARITH (WANT_INT | WANT_FLOAT) + +/* Anatomy of a DECL_FRIENDLIST (which is a TREE_LIST): + purpose = friend name (IDENTIFIER_NODE); + value = TREE_LIST of FUNCTION_DECLS; + chain, type = EMPTY; */ +#define FRIEND_NAME(LIST) (TREE_PURPOSE (LIST)) +#define FRIEND_DECLS(LIST) (TREE_VALUE (LIST)) + +/* These macros are for accessing the fields of TEMPLATE...PARM nodes. */ +#define TEMPLATE_TYPE_TPARMLIST(NODE) TREE_PURPOSE (TYPE_FIELDS (NODE)) +#define TEMPLATE_TYPE_IDX(NODE) TREE_INT_CST_LOW (TREE_VALUE (TYPE_FIELDS (NODE))) +#define TEMPLATE_TYPE_SET_INFO(NODE,P,I) \ + (TYPE_FIELDS (NODE) = build_tree_list (P, build_int_2 (I, 0))) +#define TEMPLATE_CONST_TPARMLIST(NODE) (*(tree*)&TREE_INT_CST_LOW(NODE)) +#define TEMPLATE_CONST_IDX(NODE) (TREE_INT_CST_HIGH(NODE)) +#define TEMPLATE_CONST_SET_INFO(NODE,P,I) \ + (TEMPLATE_CONST_TPARMLIST (NODE) = saved_parmlist, \ + TEMPLATE_CONST_IDX (NODE) = I) + +/* in lex.c */ +/* Indexed by TREE_CODE, these tables give C-looking names to + operators represented by TREE_CODES. For example, + opname_tab[(int) MINUS_EXPR] == "-". */ +extern char **opname_tab, **assignop_tab; + +/* in c-common.c */ +extern tree convert_and_check PROTO((tree, tree)); +extern void overflow_warning PROTO((tree)); +extern void unsigned_conversion_warning PROTO((tree, tree)); + +/* in call.c */ +extern struct candidate *ansi_c_bullshit; + +extern int rank_for_overload PROTO((struct candidate *, struct candidate *)); +extern void compute_conversion_costs PROTO((tree, tree, struct candidate *, int)); +extern int get_arglist_len_in_bytes PROTO((tree)); +extern tree build_vfield_ref PROTO((tree, tree)); +extern tree find_scoped_type PROTO((tree, tree, tree)); +extern tree resolve_scope_to_name PROTO((tree, tree)); +extern tree build_scoped_method_call PROTO((tree, tree, tree, tree)); +extern tree build_method_call PROTO((tree, tree, tree, tree, int)); +extern tree build_overload_call_real PROTO((tree, tree, int, struct candidate *, int)); +extern tree build_overload_call PROTO((tree, tree, int, struct candidate *)); +extern tree build_overload_call_maybe PROTO((tree, tree, int, struct candidate *)); + +/* in class.c */ +extern char *dont_allow_type_definitions; +extern tree build_vbase_pointer PROTO((tree, tree)); +extern tree build_vbase_path PROTO((enum tree_code, tree, tree, tree, int)); +extern tree build_vtable_entry PROTO((tree, tree)); +extern tree build_vfn_ref PROTO((tree *, tree, tree)); +extern void add_method PROTO((tree, tree *, tree)); +extern tree get_vfield_offset PROTO((tree)); +extern void duplicate_tag_error PROTO((tree)); +extern tree finish_struct PROTO((tree, tree, int)); +extern int resolves_to_fixed_type_p PROTO((tree, int *)); +extern void init_class_processing PROTO((void)); +extern void pushclass PROTO((tree, int)); +extern void popclass PROTO((int)); +extern void push_nested_class PROTO((tree, int)); +extern void pop_nested_class PROTO((int)); +extern void push_lang_context PROTO((tree)); +extern void pop_lang_context PROTO((void)); +extern int root_lang_context_p PROTO((void)); +extern tree instantiate_type PROTO((tree, tree, int)); +extern void print_class_statistics PROTO((void)); +extern void maybe_push_cache_obstack PROTO((void)); +extern unsigned HOST_WIDE_INT skip_rtti_stuff PROTO((tree *)); + +/* in cvt.c */ +extern tree convert_to_reference PROTO((tree, tree, int, int, tree)); +extern tree convert_from_reference PROTO((tree)); +extern tree convert_to_aggr PROTO((tree, tree, char **, int)); +extern tree convert_pointer_to PROTO((tree, tree)); +extern tree convert_pointer_to_real PROTO((tree, tree)); +extern tree convert_pointer_to_vbase PROTO((tree, tree)); +extern tree convert PROTO((tree, tree)); +extern tree cp_convert PROTO((tree, tree, int, int)); +extern tree convert_force PROTO((tree, tree, int)); +extern tree build_type_conversion PROTO((enum tree_code, tree, tree, int)); +extern tree build_expr_type_conversion PROTO((int, tree, int)); +extern int build_default_binary_type_conversion PROTO((enum tree_code, tree *, tree *)); +extern tree type_promotes_to PROTO((tree)); + +/* decl.c */ +extern int global_bindings_p PROTO((void)); +extern int toplevel_bindings_p PROTO((void)); +extern void keep_next_level PROTO((void)); +extern int kept_level_p PROTO((void)); +extern void declare_parm_level PROTO((void)); +extern void declare_implicit_exception PROTO((void)); +extern int have_exceptions_p PROTO((void)); +extern void declare_uninstantiated_type_level PROTO((void)); +extern int uninstantiated_type_level_p PROTO((void)); +extern void declare_pseudo_global_level PROTO((void)); +extern int pseudo_global_level_p PROTO((void)); +extern void pushlevel PROTO((int)); +extern void pushlevel_temporary PROTO((int)); +extern tree poplevel PROTO((int, int, int)); +extern void delete_block PROTO((tree)); +extern void insert_block PROTO((tree)); +extern void add_block_current_level PROTO((tree)); +extern void set_block PROTO((tree)); +extern void pushlevel_class PROTO((void)); +extern tree poplevel_class PROTO((int)); +/* skip print_other_binding_stack and print_binding_level */ +extern void print_binding_stack PROTO((void)); +extern void push_to_top_level PROTO((void)); +extern void pop_from_top_level PROTO((void)); +extern void set_identifier_type_value PROTO((tree, tree)); +extern void pop_everything PROTO((void)); +extern tree make_type_decl PROTO((tree, tree)); +extern void pushtag PROTO((tree, tree, int)); +extern tree make_anon_name PROTO((void)); +extern void clear_anon_tags PROTO((void)); +extern tree pushdecl PROTO((tree)); +extern tree pushdecl_top_level PROTO((tree)); +extern void push_class_level_binding PROTO((tree, tree)); +extern void push_overloaded_decl_top_level PROTO((tree, int)); +extern tree pushdecl_class_level PROTO((tree)); +extern tree pushdecl_nonclass_level PROTO((tree)); +extern int overloaded_globals_p PROTO((tree)); +extern tree push_overloaded_decl PROTO((tree, int)); +extern tree implicitly_declare PROTO((tree)); +extern tree lookup_label PROTO((tree)); +extern tree shadow_label PROTO((tree)); +extern tree define_label PROTO((char *, int, tree)); +extern void define_case_label PROTO((tree)); +extern tree getdecls PROTO((void)); +extern tree gettags PROTO((void)); +extern void set_current_level_tags_transparency PROTO((int)); +extern tree typedecl_for_tag PROTO((tree)); +extern tree lookup_name PROTO((tree, int)); +extern tree lookup_namespace_name PROTO((tree, tree)); +extern tree lookup_name_current_level PROTO((tree)); +extern void init_decl_processing PROTO((void)); +/* skipped define_function */ +extern void shadow_tag PROTO((tree)); +extern int grok_ctor_properties PROTO((tree, tree)); +extern tree groktypename PROTO((tree)); +extern tree start_decl PROTO((tree, tree, int, tree)); +extern void cp_finish_decl PROTO((tree, tree, tree, int, int)); +extern void expand_static_init PROTO((tree, tree)); +extern int complete_array_type PROTO((tree, tree, int)); +extern tree build_ptrmemfunc_type PROTO((tree)); +/* the grokdeclarator prototype is in decl.h */ +extern int parmlist_is_exprlist PROTO((tree)); +extern tree xref_tag PROTO((tree, tree, tree, int)); +extern void xref_basetypes PROTO((tree, tree, tree, tree)); +extern tree start_enum PROTO((tree)); +extern tree finish_enum PROTO((tree, tree)); +extern tree build_enumerator PROTO((tree, tree)); +extern tree grok_enum_decls PROTO((tree, tree)); +extern int start_function PROTO((tree, tree, tree, tree, int)); +extern void store_parm_decls PROTO((void)); +extern void expand_start_early_try_stmts PROTO((void)); +extern void store_in_parms PROTO((struct rtx_def *)); +extern void store_return_init PROTO((tree, tree)); +extern void finish_function PROTO((int, int, int)); +extern tree start_method PROTO((tree, tree, tree)); +extern tree finish_method PROTO((tree)); +extern void hack_incomplete_structures PROTO((tree)); +extern tree maybe_build_cleanup PROTO((tree)); +extern void cplus_expand_expr_stmt PROTO((tree)); +extern void finish_stmt PROTO((void)); +extern void pop_implicit_try_blocks PROTO((tree)); +extern void push_exception_cleanup PROTO((tree)); +extern void revert_static_member_fn PROTO((tree *, tree *, tree *)); + +/* in decl2.c */ +extern int lang_decode_option PROTO((char *)); +extern tree grok_method_quals PROTO((tree, tree, tree)); +extern void grokclassfn PROTO((tree, tree, tree, enum overload_flags, tree)); +extern tree grok_alignof PROTO((tree)); +extern tree grok_array_decl PROTO((tree, tree)); +extern tree delete_sanity PROTO((tree, tree, int, int)); +extern tree check_classfn PROTO((tree, tree, tree)); +extern tree grokfield PROTO((tree, tree, tree, tree, tree, tree)); +extern tree grokbitfield PROTO((tree, tree, tree)); +extern tree groktypefield PROTO((tree, tree)); +extern tree grokoptypename PROTO((tree, tree)); +extern tree build_push_scope PROTO((tree, tree)); +extern void cplus_decl_attributes PROTO((tree, tree, tree)); +extern tree constructor_name_full PROTO((tree)); +extern tree constructor_name PROTO((tree)); +extern void setup_vtbl_ptr PROTO((void)); +extern void mark_inline_for_output PROTO((tree)); +extern void clear_temp_name PROTO((void)); +extern tree get_temp_name PROTO((tree, int)); +extern tree get_temp_regvar PROTO((tree, tree)); +extern void finish_anon_union PROTO((tree)); +extern tree finish_table PROTO((tree, tree, tree, int)); +extern void finish_builtin_type PROTO((tree, char *, tree *, int, tree)); +extern tree coerce_new_type PROTO((tree)); +extern tree coerce_delete_type PROTO((tree)); +extern void walk_vtables PROTO((void (*)(), void (*)())); +extern void walk_sigtables PROTO((void (*)(), void (*)())); +extern void finish_file PROTO((void)); +extern void warn_if_unknown_interface PROTO((tree)); +extern tree grok_x_components PROTO((tree, tree)); +extern tree reparse_absdcl_as_expr PROTO((tree, tree)); +extern tree reparse_absdcl_as_casts PROTO((tree, tree)); +extern tree reparse_decl_as_expr PROTO((tree, tree)); +extern tree finish_decl_parsing PROTO((tree)); +extern tree lookup_name_nonclass PROTO((tree)); +extern tree check_cp_case_value PROTO((tree)); +extern tree do_toplevel_using_decl PROTO((tree)); +extern tree do_class_using_decl PROTO((tree)); +extern tree current_namespace_id PROTO((tree)); +extern tree get_namespace_id PROTO((void)); +extern void check_default_args PROTO((tree)); + +/* in edsel.c */ + +/* in except.c */ +extern tree protect_list; +extern void start_protect PROTO((void)); +extern void end_protect PROTO((tree)); +extern void end_protect_partials (); +extern void expand_exception_blocks PROTO((void)); +extern void expand_start_try_stmts PROTO((void)); +extern void expand_end_try_stmts PROTO((void)); +extern void expand_start_all_catch PROTO((void)); +extern void expand_end_all_catch PROTO((void)); +extern void start_catch_block PROTO((tree, tree)); +extern void end_catch_block PROTO((void)); +extern void expand_throw PROTO((tree)); +extern int might_have_exceptions_p PROTO((void)); +extern void emit_exception_table PROTO((void)); +extern tree build_throw PROTO((tree)); +extern void init_exception_processing PROTO((void)); +extern void expand_builtin_throw PROTO((void)); +extern void expand_start_eh_spec PROTO((void)); +extern void expand_end_eh_spec PROTO((tree)); + +/* in expr.c */ +/* skip cplus_expand_expr */ +extern void init_cplus_expand PROTO((void)); +extern void fixup_result_decl PROTO((tree, struct rtx_def *)); +extern int decl_in_memory_p PROTO((tree)); +extern tree unsave_expr_now PROTO((tree)); + +/* in gc.c */ +extern int type_needs_gc_entry PROTO((tree)); +extern int value_safe_from_gc PROTO((tree, tree)); +extern void build_static_gc_entry PROTO((tree, tree)); +extern tree protect_value_from_gc PROTO((tree, tree)); +extern tree build_headof PROTO((tree)); +extern tree build_classof PROTO((tree)); +extern tree build_t_desc PROTO((tree, int)); +extern tree build_i_desc PROTO((tree)); +extern tree build_m_desc PROTO((tree)); +extern void expand_gc_prologue_and_epilogue PROTO((void)); +extern void lang_expand_end_bindings PROTO((struct rtx_def *, struct rtx_def *)); +extern void init_gc_processing PROTO((void)); +extern tree build_typeid PROTO((tree)); +extern tree get_typeid PROTO((tree)); +extern tree build_dynamic_cast PROTO((tree, tree)); + +/* in init.c */ +extern void emit_base_init PROTO((tree, int)); +extern void check_base_init PROTO((tree)); +extern void expand_direct_vtbls_init PROTO((tree, tree, int, int, tree)); +extern void do_member_init PROTO((tree, tree, tree)); +extern void expand_member_init PROTO((tree, tree, tree)); +extern void expand_aggr_init PROTO((tree, tree, int, int)); +extern int is_aggr_typedef PROTO((tree, int)); +extern tree get_aggr_from_typedef PROTO((tree, int)); +extern tree get_type_value PROTO((tree)); +extern tree build_member_call PROTO((tree, tree, tree)); +extern tree build_offset_ref PROTO((tree, tree)); +extern tree get_member_function PROTO((tree *, tree, tree)); +extern tree get_member_function_from_ptrfunc PROTO((tree *, tree)); +extern tree resolve_offset_ref PROTO((tree)); +extern tree decl_constant_value PROTO((tree)); +extern int is_friend_type PROTO((tree, tree)); +extern int is_friend PROTO((tree, tree)); +extern void make_friend_class PROTO((tree, tree)); +extern tree do_friend PROTO((tree, tree, tree, tree, enum overload_flags, tree)); +extern void embrace_waiting_friends PROTO((tree)); +extern tree build_builtin_call PROTO((tree, tree, tree)); +extern tree build_new PROTO((tree, tree, tree, int)); +extern tree expand_vec_init PROTO((tree, tree, tree, tree, int)); +extern tree build_x_delete PROTO((tree, tree, int, tree)); +extern tree build_delete PROTO((tree, tree, tree, int, int)); +extern tree build_vbase_delete PROTO((tree, tree)); +extern tree build_vec_delete PROTO((tree, tree, tree, tree, tree, int)); + +/* in input.c */ + +/* in lex.c */ +extern tree make_pointer_declarator PROTO((tree, tree)); +extern tree make_reference_declarator PROTO((tree, tree)); +extern char *operator_name_string PROTO((tree)); +extern void lang_init PROTO((void)); +extern void lang_finish PROTO((void)); +extern void init_filename_times PROTO((void)); +extern void reinit_lang_specific PROTO((void)); +extern void init_lex PROTO((void)); +extern void reinit_parse_for_function PROTO((void)); +extern int *init_parse PROTO((void)); +extern void print_parse_statistics PROTO((void)); +extern void extract_interface_info PROTO((void)); +extern void set_vardecl_interface_info PROTO((tree, tree)); +extern void do_pending_inlines PROTO((void)); +extern void process_next_inline PROTO((tree)); +/* skip restore_pending_input */ +extern void yyungetc PROTO((int, int)); +extern void reinit_parse_for_method PROTO((int, tree)); +#if 0 +extern void reinit_parse_for_block PROTO((int, struct obstack *, int)); +#endif +extern tree cons_up_default_function PROTO((tree, tree, int)); +extern void check_for_missing_semicolon PROTO((tree)); +extern void note_got_semicolon PROTO((tree)); +extern void note_list_got_semicolon PROTO((tree)); +extern int check_newline PROTO((void)); +extern void dont_see_typename PROTO((void)); +extern int identifier_type PROTO((tree)); +extern void see_typename PROTO((void)); +extern tree do_identifier PROTO((tree)); +extern tree identifier_typedecl_value PROTO((tree)); +extern int real_yylex PROTO((void)); +extern tree build_lang_decl PROTO((enum tree_code, tree, tree)); +extern tree build_lang_field_decl PROTO((enum tree_code, tree, tree)); +extern void copy_lang_decl PROTO((tree)); +extern tree make_lang_type PROTO((enum tree_code)); +extern void copy_decl_lang_specific PROTO((tree)); +extern void dump_time_statistics PROTO((void)); +/* extern void compiler_error PROTO((char *, HOST_WIDE_INT, HOST_WIDE_INT)); */ +extern void compiler_error_with_decl PROTO((tree, char *)); +extern void yyerror PROTO((char *)); + +/* in errfn.c */ +extern void cp_error (); +extern void cp_error_at (); +extern void cp_warning (); +extern void cp_warning_at (); +extern void cp_pedwarn (); +extern void cp_pedwarn_at (); +extern void cp_compiler_error (); +extern void cp_sprintf (); + +/* in error.c */ +extern void init_error PROTO((void)); +extern char *fndecl_as_string PROTO((tree, tree, int)); +extern char *type_as_string PROTO((tree, int)); +extern char *args_as_string PROTO((tree, int)); +extern char *decl_as_string PROTO((tree, int)); +extern char *expr_as_string PROTO((tree, int)); +extern char *code_as_string PROTO((enum tree_code, int)); +extern char *language_as_string PROTO((enum languages, int)); +extern char *parm_as_string PROTO((int, int)); +extern char *op_as_string PROTO((enum tree_code, int)); +extern char *cv_as_string PROTO((tree, int)); + +/* in method.c */ +extern void init_method PROTO((void)); +extern tree make_anon_parm_name PROTO((void)); +extern void clear_anon_parm_name PROTO((void)); +extern void do_inline_function_hair PROTO((tree, tree)); +/* skip report_type_mismatch */ +extern char *build_overload_name PROTO((tree, int, int)); +extern tree build_static_name PROTO((tree, tree)); +extern tree cplus_exception_name PROTO((tree)); +extern tree build_decl_overload PROTO((tree, tree, int)); +extern tree build_typename_overload PROTO((tree)); +extern tree build_t_desc_overload PROTO((tree)); +extern void declare_overloaded PROTO((tree)); +#ifdef NO_AUTO_OVERLOAD +extern int is_overloaded PROTO((tree)); +#endif +extern tree build_opfncall PROTO((enum tree_code, int, tree, tree, tree)); +extern tree hack_identifier PROTO((tree, tree, int)); +extern tree build_component_type_expr PROTO((tree, tree, tree, int)); + +/* in pt.c */ +extern tree tsubst PROTO ((tree, tree*, int, tree)); +extern void begin_template_parm_list PROTO((void)); +extern tree process_template_parm PROTO((tree, tree)); +extern tree end_template_parm_list PROTO((tree)); +extern void end_template_decl PROTO((tree, tree, tree, int)); +extern tree lookup_template_class PROTO((tree, tree, tree)); +extern void push_template_decls PROTO((tree, tree, int)); +extern void pop_template_decls PROTO((tree, tree, int)); +extern int uses_template_parms PROTO((tree)); +extern void instantiate_member_templates PROTO((tree)); +extern tree instantiate_class_template PROTO((tree, int)); +extern tree instantiate_template PROTO((tree, tree *)); +extern void undo_template_name_overload PROTO((tree, int)); +extern void overload_template_name PROTO((tree, int)); +extern void end_template_instantiation PROTO((tree)); +extern void reinit_parse_for_template PROTO((int, tree, tree)); +extern int type_unification PROTO((tree, tree *, tree, tree, int *, int)); +extern int do_pending_expansions PROTO((void)); +extern void do_pending_templates PROTO((void)); +struct tinst_level *tinst_for_decl PROTO((void)); +extern void do_function_instantiation PROTO((tree, tree, tree)); +extern void do_type_instantiation PROTO((tree, tree)); +extern tree create_nested_upt PROTO((tree, tree)); + +/* in search.c */ +extern tree make_memoized_table_entry PROTO((tree, tree, int)); +extern void push_memoized_context PROTO((tree, int)); +extern void pop_memoized_context PROTO((int)); +extern tree get_binfo PROTO((tree, tree, int)); +extern int get_base_distance PROTO((tree, tree, int, tree *)); +extern enum access_type compute_access PROTO((tree, tree)); +extern tree lookup_field PROTO((tree, tree, int, int)); +extern tree lookup_nested_field PROTO((tree, int)); +extern tree lookup_fnfields PROTO((tree, tree, int)); +extern tree lookup_nested_tag PROTO((tree, tree)); +extern HOST_WIDE_INT breadth_first_search PROTO((tree, int (*)(), int (*)())); +extern int tree_needs_constructor_p PROTO((tree, int)); +extern int tree_has_any_destructor_p PROTO((tree, int)); +extern tree get_matching_virtual PROTO((tree, tree, int)); +extern tree get_abstract_virtuals PROTO((tree)); +extern tree get_baselinks PROTO((tree, tree, tree)); +extern tree next_baselink PROTO((tree)); +extern tree init_vbase_pointers PROTO((tree, tree)); +extern void expand_indirect_vtbls_init PROTO((tree, tree, tree, int)); +extern void clear_search_slots PROTO((tree)); +extern tree get_vbase_types PROTO((tree)); +extern void build_mi_matrix PROTO((tree)); +extern void free_mi_matrix PROTO((void)); +extern void build_mi_virtuals PROTO((int, int)); +extern void add_mi_virtuals PROTO((int, tree)); +extern void report_ambiguous_mi_virtuals PROTO((int, tree)); +extern void note_debug_info_needed PROTO((tree)); +extern void push_class_decls PROTO((tree)); +extern void pop_class_decls PROTO((tree)); +extern void unuse_fields PROTO((tree)); +extern void unmark_finished_struct PROTO((tree)); +extern void print_search_statistics PROTO((void)); +extern void init_search_processing PROTO((void)); +extern void reinit_search_statistics PROTO((void)); +extern tree current_scope PROTO((void)); +extern tree lookup_conversions PROTO((tree)); + +/* in sig.c */ +extern tree build_signature_pointer_type PROTO((tree, int, int)); +extern tree build_signature_reference_type PROTO((tree, int, int)); +extern tree build_signature_pointer_constructor PROTO((tree, tree)); +extern tree build_signature_method_call PROTO((tree, tree, tree, tree)); +extern tree build_optr_ref PROTO((tree)); +extern tree build_sptr_ref PROTO((tree)); + +/* in spew.c */ +extern void init_spew PROTO((void)); +extern int yylex PROTO((void)); +extern tree arbitrate_lookup PROTO((tree, tree, tree)); + +/* in tree.c */ +extern int lvalue_p PROTO((tree)); +extern int lvalue_or_else PROTO((tree, char *)); +extern tree build_cplus_new PROTO((tree, tree, int)); +extern tree break_out_cleanups PROTO((tree)); +extern tree break_out_calls PROTO((tree)); +extern tree build_cplus_method_type PROTO((tree, tree, tree)); +extern tree build_cplus_staticfn_type PROTO((tree, tree, tree)); +extern tree build_cplus_array_type PROTO((tree, tree)); +extern void propagate_binfo_offsets PROTO((tree, tree)); +extern int layout_vbasetypes PROTO((tree, int)); +extern tree layout_basetypes PROTO((tree, tree)); +extern int list_hash PROTO((tree)); +extern tree list_hash_lookup PROTO((int, tree)); +extern void list_hash_add PROTO((int, tree)); +extern tree list_hash_canon PROTO((int, tree)); +extern tree hash_tree_cons PROTO((int, int, int, tree, tree, tree)); +extern tree hash_tree_chain PROTO((tree, tree)); +extern tree hash_chainon PROTO((tree, tree)); +extern tree get_decl_list PROTO((tree)); +extern tree list_hash_lookup_or_cons PROTO((tree)); +extern tree make_binfo PROTO((tree, tree, tree, tree, tree)); +extern tree binfo_value PROTO((tree, tree)); +extern tree reverse_path PROTO((tree)); +extern tree virtual_member PROTO((tree, tree)); +extern void debug_binfo PROTO((tree)); +extern int decl_list_length PROTO((tree)); +extern int count_functions PROTO((tree)); +extern tree decl_value_member PROTO((tree, tree)); +extern int is_overloaded_fn PROTO((tree)); +extern tree get_first_fn PROTO((tree)); +extern tree fnaddr_from_vtable_entry PROTO((tree)); +extern void set_fnaddr_from_vtable_entry PROTO((tree, tree)); +extern tree function_arg_chain PROTO((tree)); +extern int promotes_to_aggr_type PROTO((tree, enum tree_code)); +extern int is_aggr_type_2 PROTO((tree, tree)); +extern void message_2_types PROTO((void (*)(), char *, tree, tree)); +extern char *lang_printable_name PROTO((tree)); +extern tree build_exception_variant PROTO((tree, tree)); +extern tree copy_to_permanent PROTO((tree)); +extern void print_lang_statistics PROTO((void)); +/* skip __eprintf */ +extern tree array_type_nelts_total PROTO((tree)); +extern tree array_type_nelts_top PROTO((tree)); +extern tree break_out_target_exprs PROTO((tree)); +extern tree build_unsave_expr PROTO((tree)); +extern int cp_expand_decl_cleanup PROTO((tree, tree)); + +/* in typeck.c */ +extern tree condition_conversion PROTO((tree)); +extern tree target_type PROTO((tree)); +extern tree require_complete_type PROTO((tree)); +extern int type_unknown_p PROTO((tree)); +extern int fntype_p PROTO((tree)); +extern tree require_instantiated_type PROTO((tree, tree, tree)); +extern tree commonparms PROTO((tree, tree)); +extern tree common_type PROTO((tree, tree)); +extern int compexcepttypes PROTO((tree, tree, int)); +extern int comptypes PROTO((tree, tree, int)); +extern int comp_target_types PROTO((tree, tree, int)); +extern tree common_base_types PROTO((tree, tree)); +extern int compparms PROTO((tree, tree, int)); +extern int comp_target_types PROTO((tree, tree, int)); +extern int self_promoting_args_p PROTO((tree)); +extern tree unsigned_type PROTO((tree)); +extern tree signed_type PROTO((tree)); +extern tree signed_or_unsigned_type PROTO((int, tree)); +extern tree c_sizeof PROTO((tree)); +extern tree c_sizeof_nowarn PROTO((tree)); +extern tree c_alignof PROTO((tree)); +extern tree decay_conversion PROTO((tree)); +extern tree default_conversion PROTO((tree)); +extern tree build_object_ref PROTO((tree, tree, tree)); +extern tree build_component_ref_1 PROTO((tree, tree, int)); +extern tree build_component_ref PROTO((tree, tree, tree, int)); +extern tree build_x_indirect_ref PROTO((tree, char *)); +extern tree build_indirect_ref PROTO((tree, char *)); +extern tree build_x_array_ref PROTO((tree, tree)); +extern tree build_array_ref PROTO((tree, tree)); +extern tree build_x_function_call PROTO((tree, tree, tree)); +extern tree build_function_call_real PROTO((tree, tree, int, int)); +extern tree build_function_call PROTO((tree, tree)); +extern tree build_function_call_maybe PROTO((tree, tree)); +extern tree convert_arguments PROTO((tree, tree, tree, tree, int)); +extern tree build_x_binary_op PROTO((enum tree_code, tree, tree)); +extern tree build_binary_op PROTO((enum tree_code, tree, tree, int)); +extern tree build_binary_op_nodefault PROTO((enum tree_code, tree, tree, enum tree_code)); +extern tree build_component_addr PROTO((tree, tree, char *)); +extern tree build_x_unary_op PROTO((enum tree_code, tree)); +extern tree build_unary_op PROTO((enum tree_code, tree, int)); +extern tree unary_complex_lvalue PROTO((enum tree_code, tree)); +extern int mark_addressable PROTO((tree)); +extern tree build_x_conditional_expr PROTO((tree, tree, tree)); +extern tree build_conditional_expr PROTO((tree, tree, tree)); +extern tree build_x_compound_expr PROTO((tree)); +extern tree build_compound_expr PROTO((tree)); +extern tree build_static_cast PROTO((tree, tree)); +extern tree build_reinterpret_cast PROTO((tree, tree)); +extern tree build_const_cast PROTO((tree, tree)); +extern tree build_c_cast PROTO((tree, tree, int)); +extern tree build_modify_expr PROTO((tree, enum tree_code, tree)); +extern int language_lvalue_valid PROTO((tree)); +extern void warn_for_assignment PROTO((char *, char *, char *, tree, int, int)); +extern tree convert_for_initialization PROTO((tree, tree, tree, int, char *, tree, int)); +extern void c_expand_asm_operands PROTO((tree, tree, tree, tree, int, char *, int)); +extern void c_expand_return PROTO((tree)); +extern tree c_expand_start_case PROTO((tree)); +extern tree build_component_ref PROTO((tree, tree, tree, int)); +extern tree build_ptrmemfunc PROTO((tree, tree, int)); + +/* in typeck2.c */ +extern tree error_not_base_type PROTO((tree, tree)); +extern tree binfo_or_else PROTO((tree, tree)); +extern void error_with_aggr_type (); /* PROTO((tree, char *, HOST_WIDE_INT)); */ +extern void readonly_error PROTO((tree, char *, int)); +extern void abstract_virtuals_error PROTO((tree, tree)); +extern void incomplete_type_error PROTO((tree, tree)); +extern void my_friendly_abort PROTO((int)); +extern void my_friendly_assert PROTO((int, int)); +extern tree store_init_value PROTO((tree, tree)); +extern tree digest_init PROTO((tree, tree, tree *)); +extern tree build_scoped_ref PROTO((tree, tree)); +extern tree build_x_arrow PROTO((tree)); +extern tree build_m_component_ref PROTO((tree, tree)); +extern tree build_functional_cast PROTO((tree, tree)); +extern char *enum_name_string PROTO((tree, tree)); +extern void report_case_error PROTO((int, tree, tree, tree)); + +/* in xref.c */ +extern void GNU_xref_begin PROTO((char *)); +extern void GNU_xref_end PROTO((int)); +extern void GNU_xref_file PROTO((char *)); +extern void GNU_xref_start_scope PROTO((HOST_WIDE_INT)); +extern void GNU_xref_end_scope PROTO((HOST_WIDE_INT, HOST_WIDE_INT, int, int, int)); +extern void GNU_xref_ref PROTO((tree, char *)); +extern void GNU_xref_decl PROTO((tree, tree)); +extern void GNU_xref_call PROTO((tree, char *)); +extern void GNU_xref_function PROTO((tree, tree)); +extern void GNU_xref_assign PROTO((tree)); +extern void GNU_xref_hier PROTO((char *, char *, int, int, int)); +extern void GNU_xref_member PROTO((tree, tree)); + +/* -- end of C++ */ + +#endif /* not _CP_TREE_H */ diff --git a/contrib/gcc/cp/cvt.c b/contrib/gcc/cp/cvt.c new file mode 100644 index 00000000000..56508c1cd30 --- /dev/null +++ b/contrib/gcc/cp/cvt.c @@ -0,0 +1,1820 @@ +/* Language-level data type conversion for GNU C++. + Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file contains the functions for converting C expressions + to different data types. The only entry point is `convert'. + Every language front end must have a `convert' function + but what kind of conversions it does will depend on the language. */ + +#include "config.h" +#include "tree.h" +#include "flags.h" +#include "cp-tree.h" +#include "class.h" +#include "convert.h" + +#undef NULL +#define NULL (char *)0 + +/* Change of width--truncation and extension of integers or reals-- + is represented with NOP_EXPR. Proper functioning of many things + assumes that no other conversions can be NOP_EXPRs. + + Conversion between integer and pointer is represented with CONVERT_EXPR. + Converting integer to real uses FLOAT_EXPR + and real to integer uses FIX_TRUNC_EXPR. + + Here is a list of all the functions that assume that widening and + narrowing is always done with a NOP_EXPR: + In convert.c, convert_to_integer. + In c-typeck.c, build_binary_op_nodefault (boolean ops), + and truthvalue_conversion. + In expr.c: expand_expr, for operands of a MULT_EXPR. + In fold-const.c: fold. + In tree.c: get_narrower and get_unwidened. + + C++: in multiple-inheritance, converting between pointers may involve + adjusting them by a delta stored within the class definition. */ + +/* Subroutines of `convert'. */ + +/* Build a thunk. What it is, is an entry point that when called will + adjust the this pointer (the first argument) by offset, and then + goto the real address of the function given by REAL_ADDR that we + would like called. What we return is the address of the thunk. */ +static tree +build_thunk (offset, real_addr) + tree offset, real_addr; +{ + if (TREE_CODE (real_addr) != ADDR_EXPR + || TREE_CODE (TREE_OPERAND (real_addr, 0)) != FUNCTION_DECL) + { + sorry ("MI pointer to member conversion too complex"); + return error_mark_node; + } + sorry ("MI pointer to member conversion too complex"); + return error_mark_node; +} + +/* Convert a `pointer to member' (POINTER_TYPE to METHOD_TYPE) into + another `pointer to method'. This may involved the creation of + a thunk to handle the this offset calculation. */ +static tree +convert_fn_ptr (type, expr) + tree type, expr; +{ + if (flag_vtable_thunks) + { + tree intype = TREE_TYPE (expr); + tree binfo = get_binfo (TYPE_METHOD_BASETYPE (TREE_TYPE (intype)), + TYPE_METHOD_BASETYPE (TREE_TYPE (type)), 1); + if (binfo == error_mark_node) + { + error (" in pointer to member conversion"); + return error_mark_node; + } + if (binfo == NULL_TREE) + { + /* ARM 4.8 restriction. */ + error ("invalid pointer to member conversion"); + return error_mark_node; + } + + if (BINFO_OFFSET_ZEROP (binfo)) + return build1 (NOP_EXPR, type, expr); + return build1 (NOP_EXPR, type, build_thunk (BINFO_OFFSET (binfo), expr)); + } + else + return build_ptrmemfunc (type, expr, 1); +} + +/* if converting pointer to pointer + if dealing with classes, check for derived->base or vice versa + else if dealing with method pointers, delegate + else convert blindly + else if converting class, pass off to build_type_conversion + else try C-style pointer conversion */ +static tree +cp_convert_to_pointer (type, expr) + tree type, expr; +{ + register tree intype = TREE_TYPE (expr); + register enum tree_code form; + + if (TYPE_PTRMEMFUNC_P (type)) + type = TYPE_PTRMEMFUNC_FN_TYPE (type); + if (TYPE_PTRMEMFUNC_P (intype)) + intype = TYPE_PTRMEMFUNC_FN_TYPE (intype); + + form = TREE_CODE (intype); + + if (form == POINTER_TYPE || form == REFERENCE_TYPE) + { + intype = TYPE_MAIN_VARIANT (intype); + + if (TYPE_MAIN_VARIANT (type) != intype + && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE + && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE) + { + enum tree_code code = PLUS_EXPR; + tree binfo = get_binfo (TREE_TYPE (type), TREE_TYPE (intype), 1); + if (binfo == error_mark_node) + return error_mark_node; + if (binfo == NULL_TREE) + { + binfo = get_binfo (TREE_TYPE (intype), TREE_TYPE (type), 1); + if (binfo == error_mark_node) + return error_mark_node; + code = MINUS_EXPR; + } + if (binfo) + { + if (TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (type)) + || TYPE_USES_VIRTUAL_BASECLASSES (TREE_TYPE (intype)) + || ! BINFO_OFFSET_ZEROP (binfo)) + { + /* Need to get the path we took. */ + tree path; + + if (code == PLUS_EXPR) + get_base_distance (TREE_TYPE (type), TREE_TYPE (intype), 0, &path); + else + get_base_distance (TREE_TYPE (intype), TREE_TYPE (type), 0, &path); + return build_vbase_path (code, type, expr, path, 0); + } + } + } + if (TREE_CODE (TREE_TYPE (intype)) == METHOD_TYPE + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE) + return convert_fn_ptr (type, expr); + + if (TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE + && TREE_CODE (TREE_TYPE (intype)) == OFFSET_TYPE) + { + tree b1 = TYPE_OFFSET_BASETYPE (TREE_TYPE (type)); + tree b2 = TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)); + tree binfo = get_binfo (b1, b2, 1); + if (binfo == NULL_TREE) + binfo = get_binfo (b2, b1, 1); + if (binfo == error_mark_node) + return error_mark_node; + } + + if (TREE_CODE (TREE_TYPE (intype)) == METHOD_TYPE + || (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)) + { + cp_error ("cannot convert `%E' from type `%T' to type `%T'", + expr, intype, type); + return error_mark_node; + } + + return build1 (NOP_EXPR, type, expr); + } + + my_friendly_assert (form != OFFSET_TYPE, 186); + + if (TYPE_LANG_SPECIFIC (intype) + && (IS_SIGNATURE_POINTER (intype) || IS_SIGNATURE_REFERENCE (intype))) + return convert_to_pointer (type, build_optr_ref (expr)); + + if (IS_AGGR_TYPE (intype)) + { + tree rval; + rval = build_type_conversion (CONVERT_EXPR, type, expr, 1); + if (rval) + { + if (rval == error_mark_node) + cp_error ("conversion of `%E' from `%T' to `%T' is ambiguous", + expr, intype, type); + return rval; + } + } + + if (integer_zerop (expr)) + { + if (type == TREE_TYPE (null_pointer_node)) + return null_pointer_node; + expr = build_int_2 (0, 0); + TREE_TYPE (expr) = type; + return expr; + } + + if (INTEGRAL_CODE_P (form)) + { + if (type_precision (intype) == POINTER_SIZE) + return build1 (CONVERT_EXPR, type, expr); + expr = convert (type_for_size (POINTER_SIZE, 0), expr); + /* Modes may be different but sizes should be the same. */ + if (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (expr))) + != GET_MODE_SIZE (TYPE_MODE (type))) + /* There is supposed to be some integral type + that is the same width as a pointer. */ + abort (); + return convert_to_pointer (type, expr); + } + + cp_error ("cannot convert `%E' from type `%T' to type `%T'", + expr, intype, type); + return error_mark_node; +} + +/* Like convert, except permit conversions to take place which + are not normally allowed due to access restrictions + (such as conversion from sub-type to private super-type). */ +static tree +convert_to_pointer_force (type, expr) + tree type, expr; +{ + register tree intype = TREE_TYPE (expr); + register enum tree_code form = TREE_CODE (intype); + + if (integer_zerop (expr)) + { + if (type == TREE_TYPE (null_pointer_node)) + return null_pointer_node; + expr = build_int_2 (0, 0); + TREE_TYPE (expr) = type; + return expr; + } + + /* Convert signature pointer/reference to `void *' first. */ + if (form == RECORD_TYPE + && (IS_SIGNATURE_POINTER (intype) || IS_SIGNATURE_REFERENCE (intype))) + { + expr = build_optr_ref (expr); + intype = TREE_TYPE (expr); + form = TREE_CODE (intype); + } + + if (form == POINTER_TYPE) + { + intype = TYPE_MAIN_VARIANT (intype); + + if (TYPE_MAIN_VARIANT (type) != intype + && TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE + && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE) + { + enum tree_code code = PLUS_EXPR; + tree path; + int distance = get_base_distance (TREE_TYPE (type), + TREE_TYPE (intype), 0, &path); + if (distance == -2) + { + ambig: + cp_error ("type `%T' is ambiguous baseclass of `%s'", TREE_TYPE (type), + TYPE_NAME_STRING (TREE_TYPE (intype))); + return error_mark_node; + } + if (distance == -1) + { + distance = get_base_distance (TREE_TYPE (intype), + TREE_TYPE (type), 0, &path); + if (distance == -2) + goto ambig; + if (distance < 0) + /* Doesn't need any special help from us. */ + return build1 (NOP_EXPR, type, expr); + + code = MINUS_EXPR; + } + return build_vbase_path (code, type, expr, path, 0); + } + return build1 (NOP_EXPR, type, expr); + } + + return cp_convert_to_pointer (type, expr); +} + +/* We are passing something to a function which requires a reference. + The type we are interested in is in TYPE. The initial + value we have to begin with is in ARG. + + FLAGS controls how we manage access checking. + CHECKCONST controls if we report error messages on const subversion. */ +static tree +build_up_reference (type, arg, flags, checkconst) + tree type, arg; + int flags, checkconst; +{ + tree rval, targ; + int literal_flag = 0; + tree argtype = TREE_TYPE (arg); + tree target_type = TREE_TYPE (type); + tree binfo = NULL_TREE; + + my_friendly_assert (TREE_CODE (type) == REFERENCE_TYPE, 187); + if ((flags & LOOKUP_PROTECT) + && TYPE_MAIN_VARIANT (argtype) != TYPE_MAIN_VARIANT (target_type) + && IS_AGGR_TYPE (argtype) + && IS_AGGR_TYPE (target_type)) + { + binfo = get_binfo (target_type, argtype, 1); + if (binfo == error_mark_node) + return error_mark_node; + if (binfo == NULL_TREE) + return error_not_base_type (target_type, argtype); + } + + /* Pass along const and volatile down into the type. */ + if (TYPE_READONLY (type) || TYPE_VOLATILE (type)) + target_type = cp_build_type_variant (target_type, TYPE_READONLY (type), + TYPE_VOLATILE (type)); + targ = arg; + if (TREE_CODE (targ) == SAVE_EXPR) + targ = TREE_OPERAND (targ, 0); + while (TREE_CODE (targ) == NOP_EXPR + && (TYPE_MAIN_VARIANT (argtype) + == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (targ, 0))))) + targ = TREE_OPERAND (targ, 0); + + switch (TREE_CODE (targ)) + { + case INDIRECT_REF: + /* This is a call to a constructor which did not know what it was + initializing until now: it needs to initialize a temporary. */ + if (TREE_HAS_CONSTRUCTOR (targ)) + { + tree temp = build_cplus_new (argtype, TREE_OPERAND (targ, 0), 1); + TREE_HAS_CONSTRUCTOR (targ) = 0; + return build_up_reference (type, temp, flags, 1); + } + /* Let &* cancel out to simplify resulting code. + Also, throw away intervening NOP_EXPRs. */ + arg = TREE_OPERAND (targ, 0); + if (TREE_CODE (arg) == NOP_EXPR || TREE_CODE (arg) == NON_LVALUE_EXPR + || (TREE_CODE (arg) == CONVERT_EXPR && TREE_REFERENCE_EXPR (arg))) + arg = TREE_OPERAND (arg, 0); + + /* in doing a &*, we have to get rid of the const'ness on the pointer + value. Haven't thought about volatile here. Pointers come to mind + here. */ + if (TREE_READONLY (arg)) + { + arg = copy_node (arg); + TREE_READONLY (arg) = 0; + } + + rval = build1 (CONVERT_EXPR, type, arg); + TREE_REFERENCE_EXPR (rval) = 1; + + /* propagate the const flag on something like: + + class Base { + public: + int foo; + }; + + class Derived : public Base { + public: + int bar; + }; + + void func(Base&); + + void func2(const Derived& d) { + func(d); + } + + on the d parameter. The below could have been avoided, if the flags + were down in the tree, not sure why they are not. (mrs) */ + /* The below code may have to be propagated to other parts of this + switch. */ + if (TREE_READONLY (targ) && !TREE_READONLY (arg) + && (TREE_CODE (arg) == PARM_DECL || TREE_CODE (arg) == VAR_DECL) + && TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE + && (TYPE_READONLY (target_type) && checkconst)) + { + arg = copy_node (arg); + TREE_READONLY (arg) = TREE_READONLY (targ); + } + literal_flag = TREE_CONSTANT (arg); + + goto done; + + /* Get this out of a register if we happened to be in one by accident. + Also, build up references to non-lvalues it we must. */ + /* For &x[y], return (&) x+y */ + case ARRAY_REF: + if (mark_addressable (TREE_OPERAND (targ, 0)) == 0) + return error_mark_node; + rval = build_binary_op (PLUS_EXPR, TREE_OPERAND (targ, 0), + TREE_OPERAND (targ, 1), 1); + TREE_TYPE (rval) = type; + if (TREE_CONSTANT (TREE_OPERAND (targ, 1)) + && staticp (TREE_OPERAND (targ, 0))) + TREE_CONSTANT (rval) = 1; + goto done; + + case SCOPE_REF: + /* Could be a reference to a static member. */ + { + tree field = TREE_OPERAND (targ, 1); + if (TREE_STATIC (field)) + { + rval = build1 (ADDR_EXPR, type, field); + literal_flag = 1; + goto done; + } + } + + /* We should have farmed out member pointers above. */ + my_friendly_abort (188); + + case COMPONENT_REF: + rval = build_component_addr (targ, build_pointer_type (argtype), + "attempt to make a reference to bit-field structure member `%s'"); + TREE_TYPE (rval) = type; + literal_flag = staticp (TREE_OPERAND (targ, 0)); + + goto done; + + /* Anything not already handled and not a true memory reference + needs to have a reference built up. Do so silently for + things like integers and return values from function, + but complain if we need a reference to something declared + as `register'. */ + + case RESULT_DECL: + if (staticp (targ)) + literal_flag = 1; + TREE_ADDRESSABLE (targ) = 1; + put_var_into_stack (targ); + break; + + case PARM_DECL: +#if 0 + if (targ == current_class_decl) + { + error ("address of `this' not available"); +/* #if 0 */ + /* This code makes the following core dump the compiler on a sun4, + if the code below is used. + + class e_decl; + class a_decl; + typedef a_decl* a_ref; + + class a_s { + public: + a_s(); + void* append(a_ref& item); + }; + class a_decl { + public: + a_decl (e_decl *parent); + a_s generic_s; + a_s decls; + e_decl* parent; + }; + + class e_decl { + public: + e_decl(); + a_s implementations; + }; + + void foobar(void *); + + a_decl::a_decl(e_decl *parent) { + parent->implementations.append(this); + } + */ + + TREE_ADDRESSABLE (targ) = 1; /* so compiler doesn't die later */ + put_var_into_stack (targ); + break; +/* #else */ + return error_mark_node; +/* #endif */ + } +#endif + /* Fall through. */ + case VAR_DECL: + case CONST_DECL: + if (DECL_REGISTER (targ) && !TREE_ADDRESSABLE (targ) + && !DECL_ARTIFICIAL (targ)) + cp_warning ("address needed to build reference for `%D', which is declared `register'", + targ); + else if (staticp (targ)) + literal_flag = 1; + + TREE_ADDRESSABLE (targ) = 1; + put_var_into_stack (targ); + break; + + case COMPOUND_EXPR: + { + tree real_reference = build_up_reference (type, TREE_OPERAND (targ, 1), + LOOKUP_PROTECT, checkconst); + rval = build (COMPOUND_EXPR, type, TREE_OPERAND (targ, 0), real_reference); + TREE_CONSTANT (rval) = staticp (TREE_OPERAND (targ, 1)); + return rval; + } + + case PREINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case MODIFY_EXPR: + case INIT_EXPR: + { + tree real_reference = build_up_reference (type, TREE_OPERAND (targ, 0), + LOOKUP_PROTECT, checkconst); + rval = build (COMPOUND_EXPR, type, arg, real_reference); + TREE_CONSTANT (rval) = staticp (TREE_OPERAND (targ, 0)); + return rval; + } + + case COND_EXPR: + return build (COND_EXPR, type, + TREE_OPERAND (targ, 0), + build_up_reference (type, TREE_OPERAND (targ, 1), + LOOKUP_PROTECT, checkconst), + build_up_reference (type, TREE_OPERAND (targ, 2), + LOOKUP_PROTECT, checkconst)); + + /* Undo the folding... */ + case MIN_EXPR: + case MAX_EXPR: + return build (COND_EXPR, type, + build (TREE_CODE (targ) == MIN_EXPR ? LT_EXPR : GT_EXPR, + boolean_type_node, TREE_OPERAND (targ, 0), + TREE_OPERAND (targ, 1)), + build_up_reference (type, TREE_OPERAND (targ, 0), + LOOKUP_PROTECT, checkconst), + build_up_reference (type, TREE_OPERAND (targ, 1), + LOOKUP_PROTECT, checkconst)); + + case WITH_CLEANUP_EXPR: + return build (WITH_CLEANUP_EXPR, type, + build_up_reference (type, TREE_OPERAND (targ, 0), + LOOKUP_PROTECT, checkconst), + 0, TREE_OPERAND (targ, 2)); + + case BIND_EXPR: + arg = TREE_OPERAND (targ, 1); + if (arg == NULL_TREE) + { + compiler_error ("({ ... }) expression not expanded when needed for reference"); + return error_mark_node; + } + rval = build1 (ADDR_EXPR, type, arg); + TREE_REFERENCE_EXPR (rval) = 1; + return rval; + + default: + break; + } + + if (TREE_ADDRESSABLE (targ) == 0) + { + tree temp; + + if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (argtype)) + { + temp = build_cplus_new (argtype, targ, 1); + if (TREE_CODE (temp) == WITH_CLEANUP_EXPR) + rval = build (WITH_CLEANUP_EXPR, type, + build1 (ADDR_EXPR, type, TREE_OPERAND (temp, 0)), + 0, TREE_OPERAND (temp, 2)); + else + rval = build1 (ADDR_EXPR, type, temp); + goto done; + } + else + { + temp = get_temp_name (argtype, 0); + if (toplevel_bindings_p ()) + { + /* Give this new temp some rtl and initialize it. */ + DECL_INITIAL (temp) = targ; + TREE_STATIC (temp) = 1; + cp_finish_decl (temp, targ, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + /* Do this after declaring it static. */ + rval = build_unary_op (ADDR_EXPR, temp, 0); + TREE_TYPE (rval) = type; + literal_flag = TREE_CONSTANT (rval); + goto done; + } + else + { + rval = build_unary_op (ADDR_EXPR, temp, 0); + if (binfo && !BINFO_OFFSET_ZEROP (binfo)) + rval = convert_pointer_to (target_type, rval); + else + TREE_TYPE (rval) = type; + + temp = build (MODIFY_EXPR, argtype, temp, arg); + TREE_SIDE_EFFECTS (temp) = 1; + return build (COMPOUND_EXPR, type, temp, rval); + } + } + } + else + rval = build1 (ADDR_EXPR, type, arg); + + done: + if (TYPE_USES_COMPLEX_INHERITANCE (argtype) + || TYPE_USES_COMPLEX_INHERITANCE (target_type)) + { + TREE_TYPE (rval) = build_pointer_type (argtype); + if (flags & LOOKUP_PROTECT) + rval = convert_pointer_to (target_type, rval); + else + rval + = convert_to_pointer_force (build_pointer_type (target_type), rval); + TREE_TYPE (rval) = type; + if (TREE_CODE (rval) == PLUS_EXPR || TREE_CODE (rval) == MINUS_EXPR) + TREE_TYPE (TREE_OPERAND (rval, 0)) + = TREE_TYPE (TREE_OPERAND (rval, 1)) = type; + } + TREE_CONSTANT (rval) = literal_flag; + return rval; +} + +/* For C++: Only need to do one-level references, but cannot + get tripped up on signed/unsigned differences. + + DECL is either NULL_TREE or the _DECL node for a reference that is being + initialized. It can be error_mark_node if we don't know the _DECL but + we know it's an initialization. */ + +tree +convert_to_reference (reftype, expr, convtype, flags, decl) + tree reftype, expr; + int convtype, flags; + tree decl; +{ + register tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); + register tree intype = TREE_TYPE (expr); + tree rval = NULL_TREE; + tree rval_as_conversion = NULL_TREE; + int i; + + if (TREE_CODE (intype) == REFERENCE_TYPE) + my_friendly_abort (364); + + intype = TYPE_MAIN_VARIANT (intype); + + i = comp_target_types (type, intype, 0); + + if (i <= 0 && (convtype & CONV_IMPLICIT) && IS_AGGR_TYPE (intype) + && ! (flags & LOOKUP_NO_CONVERSION)) + { + /* Look for a user-defined conversion to lvalue that we can use. */ + + rval_as_conversion = build_type_conversion (CONVERT_EXPR, type, expr, 1); + + if (rval_as_conversion && rval_as_conversion != error_mark_node + && real_lvalue_p (rval_as_conversion)) + { + expr = rval_as_conversion; + rval_as_conversion = NULL_TREE; + intype = type; + i = 1; + } + } + + if (((convtype & CONV_STATIC) && i == -1) + || ((convtype & CONV_IMPLICIT) && i == 1)) + { + if (flags & LOOKUP_COMPLAIN) + { + tree ttl = TREE_TYPE (reftype); + tree ttr; + + { + int r = TREE_READONLY (expr); + int v = TREE_THIS_VOLATILE (expr); + ttr = cp_build_type_variant (TREE_TYPE (expr), r, v); + } + + if (! real_lvalue_p (expr) && + (decl == NULL_TREE || ! TYPE_READONLY (ttl))) + { + if (decl) + /* Ensure semantics of [dcl.init.ref] */ + cp_pedwarn ("initialization of non-const `%T' from rvalue `%T'", + reftype, intype); + else + cp_pedwarn ("conversion to `%T' from rvalue `%T'", + reftype, intype); + } + else if (! (convtype & CONV_CONST)) + { + if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + cp_pedwarn ("conversion from `%T' to `%T' discards const", + ttr, reftype); + else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + cp_pedwarn ("conversion from `%T' to `%T' discards volatile", + ttr, reftype); + } + } + + return build_up_reference (reftype, expr, flags, + ! (convtype & CONV_CONST)); + } + else if ((convtype & CONV_REINTERPRET) && lvalue_p (expr)) + { + /* When casting an lvalue to a reference type, just convert into + a pointer to the new type and deference it. This is allowed + by San Diego WP section 5.2.9 paragraph 12, though perhaps it + should be done directly (jason). (int &)ri ---> *(int*)&ri */ + + /* B* bp; A& ar = (A&)bp; is valid, but it's probably not what they + meant. */ + if (TREE_CODE (intype) == POINTER_TYPE + && (comptypes (TREE_TYPE (intype), type, -1))) + cp_warning ("casting `%T' to `%T' does not dereference pointer", + intype, reftype); + + rval = build_unary_op (ADDR_EXPR, expr, 0); + if (rval != error_mark_node) + rval = convert_force (build_pointer_type (TREE_TYPE (reftype)), rval, 0); + if (rval != error_mark_node) + rval = build1 (NOP_EXPR, reftype, rval); + } + else if (decl) + { + tree rval_as_ctor = NULL_TREE; + + if (rval_as_conversion) + { + if (rval_as_conversion == error_mark_node) + { + cp_error ("conversion from `%T' to `%T' is ambiguous", + intype, reftype); + return error_mark_node; + } + rval_as_conversion = build_up_reference (reftype, rval_as_conversion, + flags, 1); + } + + /* Definitely need to go through a constructor here. */ + if (TYPE_HAS_CONSTRUCTOR (type) + && ! CLASSTYPE_ABSTRACT_VIRTUALS (type) + && (rval = build_method_call + (NULL_TREE, constructor_name_full (type), + build_tree_list (NULL_TREE, expr), TYPE_BINFO (type), + LOOKUP_NO_CONVERSION|LOOKUP_SPECULATIVELY + | LOOKUP_ONLYCONVERTING))) + { + tree init; + + if (toplevel_bindings_p ()) + { + extern tree static_aggregates; + tree t = get_temp_name (type, toplevel_bindings_p ()); + init = build_method_call (t, constructor_name_full (type), + build_tree_list (NULL_TREE, expr), + TYPE_BINFO (type), + LOOKUP_NORMAL|LOOKUP_NO_CONVERSION + | LOOKUP_ONLYCONVERTING); + + if (init == error_mark_node) + return error_mark_node; + + make_decl_rtl (t, NULL_PTR, 1); + static_aggregates = perm_tree_cons (expr, t, static_aggregates); + rval = build_unary_op (ADDR_EXPR, t, 0); + } + else + { + init = build_method_call (NULL_TREE, constructor_name_full (type), + build_tree_list (NULL_TREE, expr), + TYPE_BINFO (type), + LOOKUP_NORMAL|LOOKUP_NO_CONVERSION + |LOOKUP_ONLYCONVERTING); + + if (init == error_mark_node) + return error_mark_node; + + rval = build_cplus_new (type, init, 1); + rval = build_up_reference (reftype, rval, flags, 1); + } + rval_as_ctor = rval; + } + + if (rval_as_ctor && rval_as_conversion) + { + cp_error ("ambiguous conversion from `%T' to `%T'; both user-defined conversion and constructor apply", + intype, reftype); + return error_mark_node; + } + else if (rval_as_ctor) + rval = rval_as_ctor; + else if (rval_as_conversion) + rval = rval_as_conversion; + else if (! IS_AGGR_TYPE (type) && ! IS_AGGR_TYPE (intype)) + { + rval = convert (type, expr); + if (rval == error_mark_node) + return error_mark_node; + + rval = build_up_reference (reftype, rval, flags, 1); + } + + if (rval && ! TYPE_READONLY (TREE_TYPE (reftype))) + cp_pedwarn ("initializing non-const `%T' with `%T' will use a temporary", + reftype, intype); + } + + if (rval) + { + /* If we found a way to convert earlier, then use it. */ + return rval; + } + + my_friendly_assert (TREE_CODE (intype) != OFFSET_TYPE, 189); + + if (flags & LOOKUP_COMPLAIN) + cp_error ("cannot convert type `%T' to type `%T'", intype, reftype); + + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + + return error_mark_node; +} + +/* We are using a reference VAL for its value. Bash that reference all the + way down to its lowest form. */ +tree +convert_from_reference (val) + tree val; +{ + tree type = TREE_TYPE (val); + + if (TREE_CODE (type) == OFFSET_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == REFERENCE_TYPE) + return build_indirect_ref (val, NULL_PTR); + return val; +} + +/* See if there is a constructor of type TYPE which will convert + EXPR. The reference manual seems to suggest (8.5.6) that we need + not worry about finding constructors for base classes, then converting + to the derived class. + + MSGP is a pointer to a message that would be an appropriate error + string. If MSGP is NULL, then we are not interested in reporting + errors. */ +tree +convert_to_aggr (type, expr, msgp, protect) + tree type, expr; + char **msgp; + int protect; +{ + tree basetype = type; + tree name = TYPE_IDENTIFIER (basetype); + tree function, fndecl, fntype, parmtypes, parmlist, result; + tree method_name; + enum access_type access; + int can_be_private, can_be_protected; + + if (! TYPE_HAS_CONSTRUCTOR (basetype)) + { + if (msgp) + *msgp = "type `%s' does not have a constructor"; + return error_mark_node; + } + + access = access_public; + can_be_private = 0; + can_be_protected = IDENTIFIER_CLASS_VALUE (name) || name == current_class_name; + + parmlist = build_tree_list (NULL_TREE, expr); + parmtypes = tree_cons (NULL_TREE, TREE_TYPE (expr), void_list_node); + + if (TYPE_USES_VIRTUAL_BASECLASSES (basetype)) + { + parmtypes = tree_cons (NULL_TREE, integer_type_node, parmtypes); + parmlist = tree_cons (NULL_TREE, integer_one_node, parmlist); + } + + /* The type of the first argument will be filled in inside the loop. */ + parmlist = tree_cons (NULL_TREE, integer_zero_node, parmlist); + parmtypes = tree_cons (NULL_TREE, build_pointer_type (basetype), parmtypes); + +#if 0 + method_name = build_decl_overload (name, parmtypes, 1); + + /* constructors are up front. */ + fndecl = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0); + if (TYPE_HAS_DESTRUCTOR (basetype)) + fndecl = DECL_CHAIN (fndecl); + + while (fndecl) + { + if (DECL_ASSEMBLER_NAME (fndecl) == method_name) + { + function = fndecl; + if (protect) + { + if (TREE_PRIVATE (fndecl)) + { + can_be_private = + (basetype == current_class_type + || is_friend (basetype, current_function_decl) + || purpose_member (basetype, DECL_ACCESS (fndecl))); + if (! can_be_private) + goto found; + } + else if (TREE_PROTECTED (fndecl)) + { + if (! can_be_protected) + goto found; + } + } + goto found_and_ok; + } + fndecl = DECL_CHAIN (fndecl); + } +#endif + + /* No exact conversion was found. See if an approximate + one will do. */ + fndecl = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0); + if (TYPE_HAS_DESTRUCTOR (basetype)) + fndecl = DECL_CHAIN (fndecl); + + { + int saw_private = 0; + int saw_protected = 0; + struct candidate *candidates = + (struct candidate *) alloca ((decl_list_length (fndecl)+1) * sizeof (struct candidate)); + struct candidate *cp = candidates; + + while (fndecl) + { + function = fndecl; + cp->h_len = 2; + cp->harshness = (struct harshness_code *) + alloca (3 * sizeof (struct harshness_code)); + + compute_conversion_costs (fndecl, parmlist, cp, 2); + if ((cp->h.code & EVIL_CODE) == 0) + { + cp->u.field = fndecl; + if (protect) + { + if (TREE_PRIVATE (fndecl)) + access = access_private; + else if (TREE_PROTECTED (fndecl)) + access = access_protected; + else + access = access_public; + } + else + access = access_public; + + if (access == access_private + ? (basetype == current_class_type + || is_friend (basetype, cp->function) + || purpose_member (basetype, DECL_ACCESS (fndecl))) + : access == access_protected + ? (can_be_protected + || purpose_member (basetype, DECL_ACCESS (fndecl))) + : 1) + { + if (cp->h.code <= TRIVIAL_CODE) + goto found_and_ok; + cp++; + } + else + { + if (access == access_private) + saw_private = 1; + else + saw_protected = 1; + } + } + fndecl = DECL_CHAIN (fndecl); + } + if (cp - candidates) + { + /* Rank from worst to best. Then cp will point to best one. + Private fields have their bits flipped. For unsigned + numbers, this should make them look very large. + If the best alternate has a (signed) negative value, + then all we ever saw were private members. */ + if (cp - candidates > 1) + qsort (candidates, /* char *base */ + cp - candidates, /* int nel */ + sizeof (struct candidate), /* int width */ + rank_for_overload); /* int (*compar)() */ + + --cp; + if (cp->h.code & EVIL_CODE) + { + if (msgp) + *msgp = "ambiguous type conversion possible for `%s'"; + return error_mark_node; + } + + function = cp->function; + fndecl = cp->u.field; + goto found_and_ok; + } + else if (msgp) + { + if (saw_private) + if (saw_protected) + *msgp = "only private and protected conversions apply"; + else + *msgp = "only private conversions apply"; + else if (saw_protected) + *msgp = "only protected conversions apply"; + else + *msgp = "no appropriate conversion to type `%s'"; + } + return error_mark_node; + } + /* NOTREACHED */ + + found: + if (access == access_private) + if (! can_be_private) + { + if (msgp) + *msgp = TREE_PRIVATE (fndecl) + ? "conversion to type `%s' is private" + : "conversion to type `%s' is from private base class"; + return error_mark_node; + } + if (access == access_protected) + if (! can_be_protected) + { + if (msgp) + *msgp = TREE_PRIVATE (fndecl) + ? "conversion to type `%s' is protected" + : "conversion to type `%s' is from protected base class"; + return error_mark_node; + } + function = fndecl; + found_and_ok: + + /* It will convert, but we don't do anything about it yet. */ + if (msgp == 0) + return NULL_TREE; + + fntype = TREE_TYPE (function); + function = default_conversion (function); + + result = build_nt (CALL_EXPR, function, + convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype), + parmlist, NULL_TREE, LOOKUP_NORMAL), + NULL_TREE); + TREE_TYPE (result) = TREE_TYPE (fntype); + TREE_SIDE_EFFECTS (result) = 1; + return result; +} + +/* Call this when we know (for any reason) that expr is not, in fact, + zero. This routine is like convert_pointer_to, but it pays + attention to which specific instance of what type we want to + convert to. This routine should eventually become + convert_to_pointer after all references to convert_to_pointer + are removed. */ +tree +convert_pointer_to_real (binfo, expr) + tree binfo, expr; +{ + register tree intype = TREE_TYPE (expr); + tree ptr_type; + tree type, rval; + + if (TREE_CODE (binfo) == TREE_VEC) + type = BINFO_TYPE (binfo); + else if (IS_AGGR_TYPE (binfo)) + { + type = binfo; + } + else + { + type = binfo; + binfo = NULL_TREE; + } + + ptr_type = build_pointer_type (type); + if (ptr_type == TYPE_MAIN_VARIANT (intype)) + return expr; + + if (intype == error_mark_node) + return error_mark_node; + + my_friendly_assert (!integer_zerop (expr), 191); + + if (TREE_CODE (type) == RECORD_TYPE + && TREE_CODE (TREE_TYPE (intype)) == RECORD_TYPE + && type != TYPE_MAIN_VARIANT (TREE_TYPE (intype))) + { + tree path; + int distance + = get_base_distance (binfo, TYPE_MAIN_VARIANT (TREE_TYPE (intype)), + 0, &path); + + /* This function shouldn't be called with unqualified arguments + but if it is, give them an error message that they can read. */ + if (distance < 0) + { + cp_error ("cannot convert a pointer of type `%T' to a pointer of type `%T'", + TREE_TYPE (intype), type); + + if (distance == -2) + cp_error ("because `%T' is an ambiguous base class", type); + return error_mark_node; + } + + return build_vbase_path (PLUS_EXPR, ptr_type, expr, path, 1); + } + rval = build1 (NOP_EXPR, ptr_type, + TREE_CODE (expr) == NOP_EXPR ? TREE_OPERAND (expr, 0) : expr); + TREE_CONSTANT (rval) = TREE_CONSTANT (expr); + return rval; +} + +/* Call this when we know (for any reason) that expr is + not, in fact, zero. This routine gets a type out of the first + argument and uses it to search for the type to convert to. If there + is more than one instance of that type in the expr, the conversion is + ambiguous. This routine should eventually go away, and all + callers should use convert_to_pointer_real. */ +tree +convert_pointer_to (binfo, expr) + tree binfo, expr; +{ + tree type; + + if (TREE_CODE (binfo) == TREE_VEC) + type = BINFO_TYPE (binfo); + else if (IS_AGGR_TYPE (binfo)) + type = binfo; + else + type = binfo; + return convert_pointer_to_real (type, expr); +} + +/* Conversion... + + FLAGS indicates how we should behave. */ + +tree +cp_convert (type, expr, convtype, flags) + tree type, expr; + int convtype, flags; +{ + register tree e = expr; + register enum tree_code code = TREE_CODE (type); + + if (TREE_CODE (e) == ERROR_MARK + || TREE_CODE (TREE_TYPE (e)) == ERROR_MARK) + return error_mark_node; + + if (IS_AGGR_TYPE (type) && (convtype & CONV_FORCE_TEMP)) + /* We need a new temporary; don't take this shortcut. */; + else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (e))) + /* Trivial conversion: cv-qualifiers do not matter on rvalues. */ + return fold (build1 (NOP_EXPR, type, e)); + + if (code == VOID_TYPE && (convtype & CONV_STATIC)) + return build1 (CONVERT_EXPR, type, e); + +#if 0 + /* This is incorrect. A truncation can't be stripped this way. + Extensions will be stripped by the use of get_unwidened. */ + if (TREE_CODE (e) == NOP_EXPR) + return convert (type, TREE_OPERAND (e, 0)); +#endif + + /* Just convert to the type of the member. */ + if (code == OFFSET_TYPE) + { + type = TREE_TYPE (type); + code = TREE_CODE (type); + } + +#if 0 + if (code == REFERENCE_TYPE) + return fold (convert_to_reference (type, e, convtype, flags, NULL_TREE)); + else if (TREE_CODE (TREE_TYPE (e)) == REFERENCE_TYPE) + e = convert_from_reference (e); +#endif + + if (TREE_CODE (e) == OFFSET_REF) + e = resolve_offset_ref (e); + + if (TREE_READONLY_DECL_P (e)) + e = decl_constant_value (e); + + if (INTEGRAL_CODE_P (code)) + { + tree intype = TREE_TYPE (e); + enum tree_code form = TREE_CODE (intype); + /* enum = enum, enum = int, enum = float are all errors. */ + if (flag_int_enum_equivalence == 0 + && TREE_CODE (type) == ENUMERAL_TYPE + && ARITHMETIC_TYPE_P (intype) + && ! (convtype & CONV_STATIC)) + { + cp_pedwarn ("conversion from `%#T' to `%#T'", intype, type); + + if (flag_pedantic_errors) + return error_mark_node; + } + if (IS_AGGR_TYPE (intype)) + { + tree rval; + rval = build_type_conversion (CONVERT_EXPR, type, e, 1); + if (rval) + return rval; + if (flags & LOOKUP_COMPLAIN) + cp_error ("`%#T' used where a `%T' was expected", intype, type); + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + return error_mark_node; + } + if (code == BOOLEAN_TYPE) + return truthvalue_conversion (e); + return fold (convert_to_integer (type, e)); + } + if (code == POINTER_TYPE || code == REFERENCE_TYPE + || TYPE_PTRMEMFUNC_P (type)) + return fold (cp_convert_to_pointer (type, e)); + if (code == REAL_TYPE) + { + if (IS_AGGR_TYPE (TREE_TYPE (e))) + { + tree rval; + rval = build_type_conversion (CONVERT_EXPR, type, e, 1); + if (rval) + return rval; + else + if (flags & LOOKUP_COMPLAIN) + cp_error ("`%#T' used where a floating point value was expected", + TREE_TYPE (e)); + } + return fold (convert_to_real (type, e)); + } + + /* New C++ semantics: since assignment is now based on + memberwise copying, if the rhs type is derived from the + lhs type, then we may still do a conversion. */ + if (IS_AGGR_TYPE_CODE (code)) + { + tree dtype = TREE_TYPE (e); + tree ctor = NULL_TREE; + tree conversion = NULL_TREE; + + dtype = TYPE_MAIN_VARIANT (dtype); + + /* Conversion of object pointers or signature pointers/references + to signature pointers/references. */ + + if (TYPE_LANG_SPECIFIC (type) + && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))) + { + tree constructor = build_signature_pointer_constructor (type, expr); + tree sig_ty = SIGNATURE_TYPE (type); + tree sig_ptr; + + if (constructor == error_mark_node) + return error_mark_node; + + sig_ptr = get_temp_name (type, 1); + DECL_INITIAL (sig_ptr) = constructor; + CLEAR_SIGNATURE (sig_ty); + cp_finish_decl (sig_ptr, constructor, NULL_TREE, 0, 0); + SET_SIGNATURE (sig_ty); + TREE_READONLY (sig_ptr) = 1; + + return sig_ptr; + } + + /* Conversion between aggregate types. New C++ semantics allow + objects of derived type to be cast to objects of base type. + Old semantics only allowed this between pointers. + + There may be some ambiguity between using a constructor + vs. using a type conversion operator when both apply. */ + + if (IS_AGGR_TYPE (dtype) && ! DERIVED_FROM_P (type, dtype) + && TYPE_HAS_CONVERSION (dtype)) + conversion = build_type_conversion (CONVERT_EXPR, type, e, 1); + + if (conversion == error_mark_node) + { + if (flags & LOOKUP_COMPLAIN) + error ("ambiguous pointer conversion"); + return conversion; + } + + if (TYPE_HAS_CONSTRUCTOR (type)) + ctor = build_method_call (NULL_TREE, constructor_name_full (type), + build_tree_list (NULL_TREE, e), + TYPE_BINFO (type), + (flags & LOOKUP_NORMAL) | LOOKUP_SPECULATIVELY + | (convtype&CONV_NONCONVERTING ? 0 : LOOKUP_ONLYCONVERTING) + | (conversion ? LOOKUP_NO_CONVERSION : 0)); + + if (ctor == error_mark_node) + { + if (flags & LOOKUP_COMPLAIN) + cp_error ("in conversion to type `%T'", type); + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + return error_mark_node; + } + + if (conversion && ctor) + { + if (flags & LOOKUP_COMPLAIN) + error ("both constructor and type conversion operator apply"); + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + return error_mark_node; + } + else if (conversion) + return conversion; + else if (ctor) + { + ctor = build_cplus_new (type, ctor, 0); + return ctor; + } + } + + /* If TYPE or TREE_TYPE (E) is not on the permanent_obstack, + then the it won't be hashed and hence compare as not equal, + even when it is. */ + if (code == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (e)) == TREE_TYPE (type) + && index_type_equal (TYPE_DOMAIN (TREE_TYPE (e)), TYPE_DOMAIN (type))) + return e; + + if (flags & LOOKUP_COMPLAIN) + cp_error ("conversion from `%T' to non-scalar type `%T' requested", + TREE_TYPE (expr), type); + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + return error_mark_node; +} + +/* Create an expression whose value is that of EXPR, + converted to type TYPE. The TREE_TYPE of the value + is always TYPE. This function implements all reasonable + conversions; callers should filter out those that are + not permitted by the language being compiled. */ + +tree +convert (type, expr) + tree type, expr; +{ + return cp_convert (type, expr, CONV_OLD_CONVERT, LOOKUP_NORMAL); +} + +/* Like convert, except permit conversions to take place which + are not normally allowed due to access restrictions + (such as conversion from sub-type to private super-type). */ +tree +convert_force (type, expr, convtype) + tree type; + tree expr; + int convtype; +{ + register tree e = expr; + register enum tree_code code = TREE_CODE (type); + + if (code == REFERENCE_TYPE) + return fold (convert_to_reference (type, e, CONV_C_CAST, LOOKUP_COMPLAIN, + NULL_TREE)); + else if (TREE_CODE (TREE_TYPE (e)) == REFERENCE_TYPE) + e = convert_from_reference (e); + + if (code == POINTER_TYPE) + return fold (convert_to_pointer_force (type, e)); + + /* From typeck.c convert_for_assignment */ + if (((TREE_CODE (TREE_TYPE (e)) == POINTER_TYPE && TREE_CODE (e) == ADDR_EXPR + && TREE_CODE (TREE_TYPE (e)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (e))) == METHOD_TYPE) + || integer_zerop (e) + || TYPE_PTRMEMFUNC_P (TREE_TYPE (e))) + && TYPE_PTRMEMFUNC_P (type)) + { + /* compatible pointer to member functions. */ + return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), e, 1); + } + + return cp_convert (type, e, CONV_C_CAST|convtype, LOOKUP_NORMAL); +} + +/* Subroutine of build_type_conversion. */ +static tree +build_type_conversion_1 (xtype, basetype, expr, typename, for_sure) + tree xtype, basetype; + tree expr; + tree typename; + int for_sure; +{ + tree rval; + int flags; + + if (for_sure == 0) + flags = LOOKUP_PROTECT|LOOKUP_ONLYCONVERTING; + else + flags = LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING; + + rval = build_method_call (expr, typename, NULL_TREE, NULL_TREE, flags); + if (rval == error_mark_node) + { + if (for_sure == 0) + return NULL_TREE; + return error_mark_node; + } + + if (IS_AGGR_TYPE (TREE_TYPE (rval))) + return rval; + + if (warn_cast_qual + && TREE_TYPE (xtype) + && (TREE_READONLY (TREE_TYPE (TREE_TYPE (rval))) + > TREE_READONLY (TREE_TYPE (xtype)))) + warning ("user-defined conversion casting away `const'"); + return convert (xtype, rval); +} + +/* Convert an aggregate EXPR to type XTYPE. If a conversion + exists, return the attempted conversion. This may + return ERROR_MARK_NODE if the conversion is not + allowed (references private members, etc). + If no conversion exists, NULL_TREE is returned. + + If (FOR_SURE & 1) is non-zero, then we allow this type conversion + to take place immediately. Otherwise, we build a SAVE_EXPR + which can be evaluated if the results are ever needed. + + Changes to this functions should be mirrored in user_harshness. + + FIXME: Ambiguity checking is wrong. Should choose one by the implicit + object parameter, or by the second standard conversion sequence if + that doesn't do it. This will probably wait for an overloading rewrite. + (jason 8/9/95) */ + +tree +build_type_conversion (code, xtype, expr, for_sure) + enum tree_code code; + tree xtype, expr; + int for_sure; +{ + /* C++: check to see if we can convert this aggregate type + into the required type. */ + tree basetype; + tree conv; + tree winner = NULL_TREE; + + if (expr == error_mark_node) + return error_mark_node; + + basetype = TREE_TYPE (expr); + if (TREE_CODE (basetype) == REFERENCE_TYPE) + basetype = TREE_TYPE (basetype); + + basetype = TYPE_MAIN_VARIANT (basetype); + if (! TYPE_LANG_SPECIFIC (basetype) || ! TYPE_HAS_CONVERSION (basetype)) + return NULL_TREE; + + /* Do we have an exact match? */ + { + tree typename = build_typename_overload (xtype); + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + return build_type_conversion_1 (xtype, basetype, expr, typename, + for_sure); + } + + /* Nope; try looking for others. */ + for (conv = lookup_conversions (basetype); conv; conv = TREE_CHAIN (conv)) + { + if (winner && TREE_PURPOSE (winner) == TREE_PURPOSE (conv)) + continue; + + if (can_convert (xtype, TREE_VALUE (conv))) + { + if (winner) + { + if (for_sure) + { + cp_error ("ambiguous conversion from `%T' to `%T'", basetype, + xtype); + cp_error (" candidate conversions include `%T' and `%T'", + TREE_VALUE (winner), TREE_VALUE (conv)); + } + return NULL_TREE; + } + else + winner = conv; + } + } + + if (winner) + return build_type_conversion_1 (xtype, basetype, expr, + TREE_PURPOSE (winner), for_sure); + + return NULL_TREE; +} + +/* Convert the given EXPR to one of a group of types suitable for use in an + expression. DESIRES is a combination of various WANT_* flags (q.v.) + which indicates which types are suitable. If COMPLAIN is 1, complain + about ambiguity; otherwise, the caller will deal with it. */ + +tree +build_expr_type_conversion (desires, expr, complain) + int desires; + tree expr; + int complain; +{ + tree basetype = TREE_TYPE (expr); + tree conv; + tree winner = NULL_TREE; + + if (TREE_CODE (basetype) == OFFSET_TYPE) + expr = resolve_offset_ref (expr); + expr = convert_from_reference (expr); + basetype = TREE_TYPE (expr); + + if (! IS_AGGR_TYPE (basetype)) + switch (TREE_CODE (basetype)) + { + case INTEGER_TYPE: + if ((desires & WANT_NULL) && TREE_CODE (expr) == INTEGER_CST + && integer_zerop (expr)) + return expr; + /* else fall through... */ + + case BOOLEAN_TYPE: + return (desires & WANT_INT) ? expr : NULL_TREE; + case ENUMERAL_TYPE: + return (desires & WANT_ENUM) ? expr : NULL_TREE; + case REAL_TYPE: + return (desires & WANT_FLOAT) ? expr : NULL_TREE; + case POINTER_TYPE: + return (desires & WANT_POINTER) ? expr : NULL_TREE; + + case FUNCTION_TYPE: + case ARRAY_TYPE: + return (desires & WANT_POINTER) ? default_conversion (expr) + : NULL_TREE; + default: + return NULL_TREE; + } + + if (! TYPE_HAS_CONVERSION (basetype)) + return NULL_TREE; + + for (conv = lookup_conversions (basetype); conv; conv = TREE_CHAIN (conv)) + { + int win = 0; + tree candidate; + + if (winner && TREE_PURPOSE (winner) == TREE_PURPOSE (conv)) + continue; + + candidate = TREE_VALUE (conv); + if (TREE_CODE (candidate) == REFERENCE_TYPE) + candidate = TREE_TYPE (candidate); + + switch (TREE_CODE (candidate)) + { + case BOOLEAN_TYPE: + case INTEGER_TYPE: + win = (desires & WANT_INT); break; + case ENUMERAL_TYPE: + win = (desires & WANT_ENUM); break; + case REAL_TYPE: + win = (desires & WANT_FLOAT); break; + case POINTER_TYPE: + win = (desires & WANT_POINTER); break; + } + + if (win) + { + if (winner) + { + if (complain) + { + cp_error ("ambiguous default type conversion from `%T'", + basetype); + cp_error (" candidate conversions include `%T' and `%T'", + TREE_VALUE (winner), TREE_VALUE (conv)); + } + return error_mark_node; + } + else + winner = conv; + } + } + + if (winner) + return build_type_conversion_1 (TREE_VALUE (winner), basetype, expr, + TREE_PURPOSE (winner), 1); + + return NULL_TREE; +} + +/* Must convert two aggregate types to non-aggregate type. + Attempts to find a non-ambiguous, "best" type conversion. + + Return 1 on success, 0 on failure. + + @@ What are the real semantics of this supposed to be??? */ +int +build_default_binary_type_conversion (code, arg1, arg2) + enum tree_code code; + tree *arg1, *arg2; +{ + switch (code) + { + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case CEIL_DIV_EXPR: + case FLOOR_DIV_EXPR: + case ROUND_DIV_EXPR: + case EXACT_DIV_EXPR: + *arg1 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg1, 0); + *arg2 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg2, 0); + break; + + case TRUNC_MOD_EXPR: + case FLOOR_MOD_EXPR: + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case BIT_AND_EXPR: + case BIT_XOR_EXPR: + case BIT_IOR_EXPR: + *arg1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, *arg1, 0); + *arg2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, *arg2, 0); + break; + + case PLUS_EXPR: + { + tree a1, a2, p1, p2; + int wins; + + a1 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg1, 0); + a2 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg2, 0); + p1 = build_expr_type_conversion (WANT_POINTER, *arg1, 0); + p2 = build_expr_type_conversion (WANT_POINTER, *arg2, 0); + + wins = (a1 && a2) + (a1 && p2) + (p1 && a2); + + if (wins > 1) + error ("ambiguous default type conversion for `operator +'"); + + if (a1 && a2) + *arg1 = a1, *arg2 = a2; + else if (a1 && p2) + *arg1 = a1, *arg2 = p2; + else + *arg1 = p1, *arg2 = a2; + break; + } + + case MINUS_EXPR: + { + tree a1, a2, p1, p2; + int wins; + + a1 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg1, 0); + a2 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg2, 0); + p1 = build_expr_type_conversion (WANT_POINTER, *arg1, 0); + p2 = build_expr_type_conversion (WANT_POINTER, *arg2, 0); + + wins = (a1 && a2) + (p1 && p2) + (p1 && a2); + + if (wins > 1) + error ("ambiguous default type conversion for `operator -'"); + + if (a1 && a2) + *arg1 = a1, *arg2 = a2; + else if (p1 && p2) + *arg1 = p1, *arg2 = p2; + else + *arg1 = p1, *arg2 = a2; + break; + } + + case GT_EXPR: + case LT_EXPR: + case GE_EXPR: + case LE_EXPR: + case EQ_EXPR: + case NE_EXPR: + { + tree a1, a2, p1, p2; + int wins; + + a1 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg1, 0); + a2 = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, *arg2, 0); + p1 = build_expr_type_conversion (WANT_POINTER | WANT_NULL, *arg1, 0); + p2 = build_expr_type_conversion (WANT_POINTER | WANT_NULL, *arg2, 0); + + wins = (a1 && a2) + (p1 && p2); + + if (wins > 1) + cp_error ("ambiguous default type conversion for `%O'", code); + + if (a1 && a2) + *arg1 = a1, *arg2 = a2; + else + *arg1 = p1, *arg2 = p2; + break; + } + + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + *arg1 = convert (boolean_type_node, *arg1); + *arg2 = convert (boolean_type_node, *arg2); + break; + + default: + *arg1 = NULL_TREE; + *arg2 = NULL_TREE; + } + + if (*arg1 == error_mark_node || *arg2 == error_mark_node) + cp_error ("ambiguous default type conversion for `%O'", code); + + if (*arg1 && *arg2) + return 1; + + return 0; +} + +/* Implements integral promotion (4.1) and float->double promotion. */ +tree +type_promotes_to (type) + tree type; +{ + int constp, volatilep; + + if (type == error_mark_node) + return error_mark_node; + + constp = TYPE_READONLY (type); + volatilep = TYPE_VOLATILE (type); + type = TYPE_MAIN_VARIANT (type); + + /* bool always promotes to int (not unsigned), even if it's the same + size. */ + if (type == boolean_type_node) + type = integer_type_node; + + /* Normally convert enums to int, but convert wide enums to something + wider. */ + else if (TREE_CODE (type) == ENUMERAL_TYPE + || type == wchar_type_node) + { + int precision = MAX (TYPE_PRECISION (type), + TYPE_PRECISION (integer_type_node)); + tree totype = type_for_size (precision, 0); + if (TREE_UNSIGNED (type) + && ! int_fits_type_p (TYPE_MAX_VALUE (type), totype)) + type = type_for_size (precision, 1); + else + type = totype; + } + else if (C_PROMOTING_INTEGER_TYPE_P (type)) + { + /* Traditionally, unsignedness is preserved in default promotions. + Otherwise, retain unsignedness if really not getting bigger. */ + if (TREE_UNSIGNED (type) + && (flag_traditional + || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))) + type = unsigned_type_node; + else + type = integer_type_node; + } + else if (type == float_type_node) + type = double_type_node; + + return cp_build_type_variant (type, constp, volatilep); +} diff --git a/contrib/gcc/cp/decl.c b/contrib/gcc/cp/decl.c new file mode 100644 index 00000000000..103cb0de2c5 --- /dev/null +++ b/contrib/gcc/cp/decl.c @@ -0,0 +1,12878 @@ +/* Process declarations and variables for C compiler. + Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Process declarations and symbol lookup for C front end. + Also constructs types; the standard scalar types at initialization, + and structure, union, array and enum types when they are declared. */ + +/* ??? not all decl nodes are given the most useful possible + line numbers. For example, the CONST_DECLs for enum values. */ + +#include +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "flags.h" +#include "cp-tree.h" +#include "decl.h" +#include "lex.h" +#include +#include +#include "obstack.h" + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +extern tree builtin_return_address_fndecl; + +extern struct obstack permanent_obstack; + +extern int current_class_depth; + +extern tree cleanups_this_call; + +extern tree static_ctors, static_dtors; + +/* Stack of places to restore the search obstack back to. */ + +/* Obstack used for remembering local class declarations (like + enums and static (const) members. */ +#include "stack.h" +static struct obstack decl_obstack; +static struct stack_level *decl_stack; + +#ifndef CHAR_TYPE_SIZE +#define CHAR_TYPE_SIZE BITS_PER_UNIT +#endif + +#ifndef SHORT_TYPE_SIZE +#define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) +#endif + +#ifndef INT_TYPE_SIZE +#define INT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_TYPE_SIZE +#define LONG_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_LONG_TYPE_SIZE +#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef WCHAR_UNSIGNED +#define WCHAR_UNSIGNED 0 +#endif + +#ifndef FLOAT_TYPE_SIZE +#define FLOAT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef DOUBLE_TYPE_SIZE +#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef BOOL_TYPE_SIZE +#ifdef SLOW_BYTE_ACCESS +#define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT)) +#else +#define BOOL_TYPE_SIZE BITS_PER_UNIT +#endif +#endif + +/* We let tm.h override the types used here, to handle trivial differences + such as the choice of unsigned int or long unsigned int for size_t. + When machines start needing nontrivial differences in the size type, + it would be best to do something here to figure out automatically + from other information what type to use. */ + +#ifndef SIZE_TYPE +#define SIZE_TYPE "long unsigned int" +#endif + +#ifndef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" +#endif + +#ifndef WCHAR_TYPE +#define WCHAR_TYPE "int" +#endif + +static tree grokparms PROTO((tree, int)); +static tree lookup_nested_type PROTO((tree, tree)); +static char *redeclaration_error_message PROTO((tree, tree)); +static void grok_op_properties PROTO((tree, int, int)); + +tree define_function + PROTO((char *, tree, enum built_in_function, void (*)(), char *)); + +/* a node which has tree code ERROR_MARK, and whose type is itself. + All erroneous expressions are replaced with this node. All functions + that accept nodes as arguments should avoid generating error messages + if this node is one of the arguments, since it is undesirable to get + multiple error messages from one error in the input. */ + +tree error_mark_node; + +/* Erroneous argument lists can use this *IFF* they do not modify it. */ +tree error_mark_list; + +/* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ + +tree short_integer_type_node; +tree integer_type_node; +tree long_integer_type_node; +tree long_long_integer_type_node; + +tree short_unsigned_type_node; +tree unsigned_type_node; +tree long_unsigned_type_node; +tree long_long_unsigned_type_node; + +tree ptrdiff_type_node; + +tree unsigned_char_type_node; +tree signed_char_type_node; +tree char_type_node; +tree wchar_type_node; +tree signed_wchar_type_node; +tree unsigned_wchar_type_node; + +tree wchar_decl_node; + +tree float_type_node; +tree double_type_node; +tree long_double_type_node; + +tree intQI_type_node; +tree intHI_type_node; +tree intSI_type_node; +tree intDI_type_node; + +tree unsigned_intQI_type_node; +tree unsigned_intHI_type_node; +tree unsigned_intSI_type_node; +tree unsigned_intDI_type_node; + +/* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ + +tree void_type_node, void_list_node; +tree void_zero_node; + +/* Nodes for types `void *' and `const void *'. */ + +tree ptr_type_node, const_ptr_type_node; + +/* Nodes for types `char *' and `const char *'. */ + +tree string_type_node, const_string_type_node; + +/* Type `char[256]' or something like it. + Used when an array of char is needed and the size is irrelevant. */ + +tree char_array_type_node; + +/* Type `int[256]' or something like it. + Used when an array of int needed and the size is irrelevant. */ + +tree int_array_type_node; + +/* Type `wchar_t[256]' or something like it. + Used when a wide string literal is created. */ + +tree wchar_array_type_node; + +/* The bool data type, and constants */ +tree boolean_type_node, boolean_true_node, boolean_false_node; + +/* type `int ()' -- used for implicit declaration of functions. */ + +tree default_function_type; + +/* function types `double (double)' and `double (double, double)', etc. */ + +tree double_ftype_double, double_ftype_double_double; +tree int_ftype_int, long_ftype_long; + +/* Function type `void (void *, void *, int)' and similar ones. */ + +tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; + +/* Function type `char *(char *, char *)' and similar ones */ +tree string_ftype_ptr_ptr, int_ftype_string_string; + +/* Function type `size_t (const char *)' */ +tree sizet_ftype_string; + +/* Function type `int (const void *, const void *, size_t)' */ +tree int_ftype_cptr_cptr_sizet; + +/* C++ extensions */ +tree vtable_entry_type; +tree delta_type_node; +#if 0 +/* Old rtti stuff. */ +tree __baselist_desc_type_node; +tree __i_desc_type_node, __m_desc_type_node; +tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; +#endif +tree __t_desc_type_node, __tp_desc_type_node; +tree __access_mode_type_node; +tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; +tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; +tree __ptmf_desc_type_node, __ptmd_desc_type_node; +#if 0 +/* Not needed yet? May be needed one day? */ +tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; +tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; +tree __ptmf_desc_array_type, __ptmd_desc_array_type; +#endif + +tree class_star_type_node; +tree class_type_node, record_type_node, union_type_node, enum_type_node; +tree unknown_type_node; +tree opaque_type_node, signature_type_node; +tree sigtable_entry_type; +tree maybe_gc_cleanup; + +/* Array type `vtable_entry_type[]' */ +tree vtbl_type_node; + +/* In a destructor, the point at which all derived class destroying + has been done, just before any base class destroying will be done. */ + +tree dtor_label; + +/* In a constructor, the point at which we are ready to return + the pointer to the initialized object. */ + +tree ctor_label; + +/* A FUNCTION_DECL which can call `abort'. Not necessarily the + one that the user will declare, but sufficient to be called + by routines that want to abort the program. */ + +tree abort_fndecl; + +extern rtx cleanup_label, return_label; + +/* If original DECL_RESULT of current function was a register, + but due to being an addressable named return value, would up + on the stack, this variable holds the named return value's + original location. */ +rtx original_result_rtx; + +/* Sequence of insns which represents base initialization. */ +tree base_init_expr; + +/* C++: Keep these around to reduce calls to `get_identifier'. + Identifiers for `this' in member functions and the auto-delete + parameter for destructors. */ +tree this_identifier, in_charge_identifier; +/* Used in pointer to member functions, in vtables, and in sigtables. */ +tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; +tree pfn_or_delta2_identifier, tag_identifier; +tree vb_off_identifier, vt_off_identifier; + +/* A list (chain of TREE_LIST nodes) of named label uses. + The TREE_PURPOSE field is the list of variables defined + the the label's scope defined at the point of use. + The TREE_VALUE field is the LABEL_DECL used. + The TREE_TYPE field holds `current_binding_level' at the + point of the label's use. + + Used only for jumps to as-yet undefined labels, since + jumps to defined labels can have their validity checked + by stmt.c. */ + +static tree named_label_uses; + +/* A list of objects which have constructors or destructors + which reside in the global scope. The decl is stored in + the TREE_VALUE slot and the initializer is stored + in the TREE_PURPOSE slot. */ +tree static_aggregates; + +/* -- end of C++ */ + +/* Two expressions that are constants with value zero. + The first is of type `int', the second of type `void *'. */ + +tree integer_zero_node; +tree null_pointer_node; + +/* A node for the integer constants 1, 2, and 3. */ + +tree integer_one_node, integer_two_node, integer_three_node; + +/* Nonzero if we have seen an invalid cross reference + to a struct, union, or enum, but not yet printed the message. */ + +tree pending_invalid_xref; +/* File and line to appear in the eventual error message. */ +char *pending_invalid_xref_file; +int pending_invalid_xref_line; + +/* While defining an enum type, this is 1 plus the last enumerator + constant value. */ + +static tree enum_next_value; + +/* Nonzero means that there was overflow computing enum_next_value. */ + +static int enum_overflow; + +/* Parsing a function declarator leaves a list of parameter names + or a chain or parameter decls here. */ + +tree last_function_parms; + +/* Parsing a function declarator leaves here a chain of structure + and enum types declared in the parmlist. */ + +static tree last_function_parm_tags; + +/* After parsing the declarator that starts a function definition, + `start_function' puts here the list of parameter names or chain of decls. + `store_parm_decls' finds it here. */ + +static tree current_function_parms; + +/* Similar, for last_function_parm_tags. */ +static tree current_function_parm_tags; + +/* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function + that have names. Here so we can clear out their names' definitions + at the end of the function. */ + +static tree named_labels; + +/* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ + +static tree shadowed_labels; + +#if 0 /* Not needed by C++ */ +/* Nonzero when store_parm_decls is called indicates a varargs function. + Value not meaningful after store_parm_decls. */ + +static int c_function_varargs; +#endif + +/* The FUNCTION_DECL for the function currently being compiled, + or 0 if between functions. */ +tree current_function_decl; + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement that specifies a return value is seen. */ + +int current_function_returns_value; + +/* Set to 0 at beginning of a function definition, set to 1 if + a return statement with no argument is seen. */ + +int current_function_returns_null; + +/* Set to 0 at beginning of a function definition, and whenever + a label (case or named) is defined. Set to value of expression + returned from function when that value can be transformed into + a named return value. */ + +tree current_function_return_value; + +/* Set to nonzero by `grokdeclarator' for a function + whose return type is defaulted, if warnings for this are desired. */ + +static int warn_about_return_type; + +/* Nonzero means give `double' the same size as `float'. */ + +extern int flag_short_double; + +/* Nonzero means don't recognize any builtin functions. */ + +extern int flag_no_builtin; + +/* Nonzero means don't recognize the non-ANSI builtin functions. + -ansi sets this. */ + +extern int flag_no_nonansi_builtin; + +/* Nonzero means enable obscure ANSI features and disable GNU extensions + that might cause ANSI-compliant code to be miscompiled. */ + +extern int flag_ansi; + +/* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) + objects. */ +extern int flag_huge_objects; + +/* Nonzero if we want to conserve space in the .o files. We do this + by putting uninitialized data and runtime initialized data into + .common instead of .data at the expense of not flagging multiple + definitions. */ +extern int flag_conserve_space; + +/* Pointers to the base and current top of the language name stack. */ + +extern tree *current_lang_base, *current_lang_stack; + +/* C and C++ flags are in decl2.c. */ + +/* Set to 0 at beginning of a constructor, set to 1 + if that function does an allocation before referencing its + instance variable. */ +int current_function_assigns_this; +int current_function_just_assigned_this; + +/* Set to 0 at beginning of a function. Set non-zero when + store_parm_decls is called. Don't call store_parm_decls + if this flag is non-zero! */ +int current_function_parms_stored; + +/* Current end of entries in the gc obstack for stack pointer variables. */ + +int current_function_obstack_index; + +/* Flag saying whether we have used the obstack in this function or not. */ + +int current_function_obstack_usage; + +/* Flag used when debugging spew.c */ + +extern int spew_debug; + +/* This is a copy of the class_shadowed list of the previous class binding + contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs + when entering another class scope (i.e. a cache miss). */ +extern tree previous_class_values; + + +/* Allocate a level of searching. */ +struct stack_level * +push_decl_level (stack, obstack) + struct stack_level *stack; + struct obstack *obstack; +{ + struct stack_level tem; + tem.prev = stack; + + return push_stack_level (obstack, (char *)&tem, sizeof (tem)); +} + +/* For each binding contour we allocate a binding_level structure + * which records the names defined in that contour. + * Contours include: + * 0) the global one + * 1) one for each function definition, + * where internal declarations of the parameters appear. + * 2) one for each compound statement, + * to record its declarations. + * + * The current meaning of a name can be found by searching the levels from + * the current one out to the global one. + * + * Off to the side, may be the class_binding_level. This exists + * only to catch class-local declarations. It is otherwise + * nonexistent. + * + * Also there may be binding levels that catch cleanups that + * must be run when exceptions occur. + */ + +/* Note that the information in the `names' component of the global contour + is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ + +struct binding_level + { + /* A chain of _DECL nodes for all variables, constants, functions, + * and typedef types. These are in the reverse of the order supplied. + */ + tree names; + + /* A list of structure, union and enum definitions, + * for looking up tag names. + * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, + * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, + * or ENUMERAL_TYPE node. + * + * C++: the TREE_VALUE nodes can be simple types for component_bindings. + * + */ + tree tags; + + /* For each level, a list of shadowed outer-level local definitions + to be restored when this level is popped. + Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and + whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ + tree shadowed; + + /* Same, for IDENTIFIER_CLASS_VALUE. */ + tree class_shadowed; + + /* Same, for IDENTIFIER_TYPE_VALUE. */ + tree type_shadowed; + + /* For each level (except not the global one), + a chain of BLOCK nodes for all the levels + that were entered and exited one level down. */ + tree blocks; + + /* The BLOCK node for this level, if one has been preallocated. + If 0, the BLOCK is allocated (if needed) when the level is popped. */ + tree this_block; + + /* The binding level which this one is contained in (inherits from). */ + struct binding_level *level_chain; + + /* List of decls in `names' that have incomplete + structure or union types. */ + tree incomplete; + + /* List of VAR_DECLS saved from a previous for statement. + These would be dead in ANSI-conforming code, but might + be referenced in traditional code. */ + tree dead_vars_from_for; + + /* 1 for the level that holds the parameters of a function. + 2 for the level that holds a class declaration. + 3 for levels that hold parameter declarations. */ + unsigned parm_flag : 4; + + /* 1 means make a BLOCK for this level regardless of all else. + 2 for temporary binding contours created by the compiler. */ + unsigned keep : 3; + + /* Nonzero if this level "doesn't exist" for tags. */ + unsigned tag_transparent : 1; + + /* Nonzero if this level can safely have additional + cleanup-needing variables added to it. */ + unsigned more_cleanups_ok : 1; + unsigned have_cleanups : 1; + + /* Nonzero if we should accept any name as an identifier in + this scope. This happens in some template definitions. */ + unsigned accept_any : 1; + + /* Nonzero if this level is for completing a template class definition + inside a binding level that temporarily binds the parameters. This + means that definitions here should not be popped off when unwinding + this binding level. (Not actually implemented this way, + unfortunately.) */ + unsigned pseudo_global : 1; + + /* This is set for a namespace binding level. */ + unsigned namespace_p : 1; + + /* True if this level is that of a for-statement. */ + unsigned is_for_scope : 1; + + /* One bit left for this word. */ + +#if defined(DEBUG_CP_BINDING_LEVELS) + /* Binding depth at which this level began. */ + unsigned binding_depth; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + }; + +#define NULL_BINDING_LEVEL ((struct binding_level *) NULL) + +/* The (non-class) binding level currently in effect. */ + +static struct binding_level *current_binding_level; + +/* The binding level of the current class, if any. */ + +static struct binding_level *class_binding_level; + +/* The current (class or non-class) binding level currently in effect. */ + +#define inner_binding_level \ + (class_binding_level ? class_binding_level : current_binding_level) + +/* A chain of binding_level structures awaiting reuse. */ + +static struct binding_level *free_binding_level; + +/* The outermost binding level, for names of file scope. + This is created when the compiler is started and exists + through the entire run. */ + +static struct binding_level *global_binding_level; + +/* Binding level structures are initialized by copying this one. */ + +static struct binding_level clear_binding_level; + +/* Nonzero means unconditionally make a BLOCK for the next level pushed. */ + +static int keep_next_level_flag; + +#if defined(DEBUG_CP_BINDING_LEVELS) +static int binding_depth = 0; +static int is_class_level = 0; + +static void +indent () +{ + register unsigned i; + + for (i = 0; i < binding_depth*2; i++) + putc (' ', stderr); +} +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + +static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); + +static void +push_binding_level (newlevel, tag_transparent, keep) + struct binding_level *newlevel; + int tag_transparent, keep; +{ + /* Add this level to the front of the chain (stack) of levels that + are active. */ + *newlevel = clear_binding_level; + if (class_binding_level) + { + newlevel->level_chain = class_binding_level; + class_binding_level = (struct binding_level *)0; + } + else + { + newlevel->level_chain = current_binding_level; + } + current_binding_level = newlevel; + newlevel->tag_transparent = tag_transparent; + newlevel->more_cleanups_ok = 1; + newlevel->keep = keep; +#if defined(DEBUG_CP_BINDING_LEVELS) + newlevel->binding_depth = binding_depth; + indent (); + fprintf (stderr, "push %s level 0x%08x line %d\n", + (is_class_level) ? "class" : "block", newlevel, lineno); + is_class_level = 0; + binding_depth++; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ +} + +static void +pop_binding_level () +{ + if (class_binding_level) + current_binding_level = class_binding_level; + + if (global_binding_level) + { + /* cannot pop a level, if there are none left to pop. */ + if (current_binding_level == global_binding_level) + my_friendly_abort (123); + } + /* Pop the current level, and free the structure for reuse. */ +#if defined(DEBUG_CP_BINDING_LEVELS) + binding_depth--; + indent (); + fprintf (stderr, "pop %s level 0x%08x line %d\n", + (is_class_level) ? "class" : "block", + current_binding_level, lineno); + if (is_class_level != (current_binding_level == class_binding_level)) +#if 0 /* XXX Don't abort when we're watching how things are being managed. */ + abort (); +#else + { + indent (); + fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); + } +#endif + is_class_level = 0; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + { + register struct binding_level *level = current_binding_level; + current_binding_level = current_binding_level->level_chain; + level->level_chain = free_binding_level; +#if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ + if (level->binding_depth != binding_depth) + abort (); +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + free_binding_level = level; + + class_binding_level = current_binding_level; + if (class_binding_level->parm_flag != 2) + class_binding_level = 0; + while (current_binding_level->parm_flag == 2) + current_binding_level = current_binding_level->level_chain; + } +} + +static void +suspend_binding_level () +{ + if (class_binding_level) + current_binding_level = class_binding_level; + + if (global_binding_level) + { + /* cannot suspend a level, if there are none left to suspend. */ + if (current_binding_level == global_binding_level) + my_friendly_abort (123); + } + /* Suspend the current level. */ +#if defined(DEBUG_CP_BINDING_LEVELS) + binding_depth--; + indent (); + fprintf (stderr, "suspend %s level 0x%08x line %d\n", + (is_class_level) ? "class" : "block", + current_binding_level, lineno); + if (is_class_level != (current_binding_level == class_binding_level)) +#if 0 /* XXX Don't abort when we're watching how things are being managed. */ + abort (); +#else + { + indent (); + fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); + } +#endif + is_class_level = 0; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + { + register struct binding_level *level = current_binding_level; + current_binding_level = current_binding_level->level_chain; +#if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ + if (level->binding_depth != binding_depth) + abort (); +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + + class_binding_level = current_binding_level; + if (class_binding_level->parm_flag != 2) + class_binding_level = 0; + while (current_binding_level->parm_flag == 2) + current_binding_level = current_binding_level->level_chain; + } +} + +void +resume_binding_level (b) + struct binding_level *b; +{ + if (class_binding_level) + { +#if 1 + /* These are here because we cannot deal with shadows yet. */ + sorry ("cannot resume a namespace inside class"); + return; +#else + b->level_chain = class_binding_level; + class_binding_level = (struct binding_level *)0; +#endif + } + else + { +#if 1 + /* These are here because we cannot deal with shadows yet. */ + if (b->level_chain != current_binding_level) + { + sorry ("cannot resume a namespace inside a different namespace"); + return; + } +#endif + b->level_chain = current_binding_level; + } + current_binding_level = b; +#if defined(DEBUG_CP_BINDING_LEVELS) + b->binding_depth = binding_depth; + indent (); + fprintf (stderr, "resume %s level 0x%08x line %d\n", + (is_class_level) ? "class" : "block", b, lineno); + is_class_level = 0; + binding_depth++; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ +} + +/* Nonzero if we are currently in the global binding level. */ + +int +global_bindings_p () +{ + return current_binding_level == global_binding_level; +} + +/* Nonzero if we are currently in a toplevel binding level. This + means either the global binding level or a namespace in a toplevel + binding level. */ + +int +toplevel_bindings_p () +{ + struct binding_level *b = current_binding_level; + + while (1) + { + if (b == global_binding_level) + return 1; + if (! b->namespace_p) + return 0; + b=b->level_chain; + } +} + +/* Nonzero if this is a namespace scope. */ + +int +namespace_bindings_p () +{ + return current_binding_level->namespace_p; +} + +void +keep_next_level () +{ + keep_next_level_flag = 1; +} + +/* Nonzero if the current level needs to have a BLOCK made. */ + +int +kept_level_p () +{ + return (current_binding_level->blocks != NULL_TREE + || current_binding_level->keep + || current_binding_level->names != NULL_TREE + || (current_binding_level->tags != NULL_TREE + && !current_binding_level->tag_transparent)); +} + +/* Identify this binding level as a level of parameters. */ + +void +declare_parm_level () +{ + current_binding_level->parm_flag = 1; +} + +void +declare_uninstantiated_type_level () +{ + current_binding_level->accept_any = 1; +} + +int +uninstantiated_type_level_p () +{ + return current_binding_level->accept_any; +} + +void +declare_pseudo_global_level () +{ + current_binding_level->pseudo_global = 1; +} + +void +declare_namespace_level () +{ + current_binding_level->namespace_p = 1; +} + +int +pseudo_global_level_p () +{ + return current_binding_level->pseudo_global; +} + +void +set_class_shadows (shadows) + tree shadows; +{ + class_binding_level->class_shadowed = shadows; +} + +/* Enter a new binding level. + If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, + not for that of tags. */ + +void +pushlevel (tag_transparent) + int tag_transparent; +{ + register struct binding_level *newlevel = NULL_BINDING_LEVEL; + + /* If this is the top level of a function, + just make sure that NAMED_LABELS is 0. + They should have been set to 0 at the end of the previous function. */ + + if (current_binding_level == global_binding_level) + my_friendly_assert (named_labels == NULL_TREE, 134); + + /* Reuse or create a struct for this binding level. */ + +#if defined(DEBUG_CP_BINDING_LEVELS) + if (0) +#else /* !defined(DEBUG_CP_BINDING_LEVELS) */ + if (free_binding_level) +#endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ + { + newlevel = free_binding_level; + free_binding_level = free_binding_level->level_chain; + } + else + { + /* Create a new `struct binding_level'. */ + newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); + } + push_binding_level (newlevel, tag_transparent, keep_next_level_flag); + GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); + keep_next_level_flag = 0; +} + +int +note_level_for_for () +{ + current_binding_level->is_for_scope = 1; +} + +void +pushlevel_temporary (tag_transparent) + int tag_transparent; +{ + pushlevel (tag_transparent); + current_binding_level->keep = 2; + clear_last_expr (); + + /* Note we don't call push_momentary() here. Otherwise, it would cause + cleanups to be allocated on the momentary obstack, and they will be + overwritten by the next statement. */ + + expand_start_bindings (0); +} + +/* Exit a binding level. + Pop the level off, and restore the state of the identifier-decl mappings + that were in effect when this level was entered. + + If KEEP == 1, this level had explicit declarations, so + and create a "block" (a BLOCK node) for the level + to record its declarations and subblocks for symbol table output. + + If KEEP == 2, this level's subblocks go to the front, + not the back of the current binding level. This happens, + for instance, when code for constructors and destructors + need to generate code at the end of a function which must + be moved up to the front of the function. + + If FUNCTIONBODY is nonzero, this level is the body of a function, + so create a block as if KEEP were set and also clear out all + label names. + + If REVERSE is nonzero, reverse the order of decls before putting + them into the BLOCK. */ + +tree +poplevel (keep, reverse, functionbody) + int keep; + int reverse; + int functionbody; +{ + register tree link; + /* The chain of decls was accumulated in reverse order. + Put it into forward order, just for cleanliness. */ + tree decls; + int tmp = functionbody; + int implicit_try_block = current_binding_level->parm_flag == 3; + int real_functionbody = current_binding_level->keep == 2 + ? ((functionbody = 0), tmp) : functionbody; + tree tags = functionbody >= 0 ? current_binding_level->tags : 0; + tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; + tree block = NULL_TREE; + tree decl; + int block_previously_created; + + GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, + (HOST_WIDE_INT) current_binding_level->level_chain, + current_binding_level->parm_flag, + current_binding_level->keep, + current_binding_level->tag_transparent); + + if (current_binding_level->keep == 1) + keep = 1; + + /* This warning is turned off because it causes warnings for + declarations like `extern struct foo *x'. */ +#if 0 + /* Warn about incomplete structure types in this level. */ + for (link = tags; link; link = TREE_CHAIN (link)) + if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE) + { + tree type = TREE_VALUE (link); + char *errmsg; + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + errmsg = "`struct %s' incomplete in scope ending here"; + break; + case UNION_TYPE: + errmsg = "`union %s' incomplete in scope ending here"; + break; + case ENUMERAL_TYPE: + errmsg = "`enum %s' incomplete in scope ending here"; + break; + } + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); + else + /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ + error (errmsg, TYPE_NAME_STRING (type)); + } +#endif /* 0 */ + + /* Get the decls in the order they were written. + Usually current_binding_level->names is in reverse order. + But parameter decls were previously put in forward order. */ + + if (reverse) + current_binding_level->names + = decls = nreverse (current_binding_level->names); + else + decls = current_binding_level->names; + + /* Output any nested inline functions within this block + if they weren't already output. */ + + for (decl = decls; decl; decl = TREE_CHAIN (decl)) + if (TREE_CODE (decl) == FUNCTION_DECL + && ! TREE_ASM_WRITTEN (decl) + && DECL_INITIAL (decl) != NULL_TREE + && TREE_ADDRESSABLE (decl) + && decl_function_context (decl) == current_function_decl) + { + /* If this decl was copied from a file-scope decl + on account of a block-scope extern decl, + propagate TREE_ADDRESSABLE to the file-scope decl. */ + if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) + TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; + else + { + push_function_context (); + output_inline_function (decl); + pop_function_context (); + } + } + + /* If there were any declarations or structure tags in that level, + or if this level is a function body, + create a BLOCK to record them for the life of this function. */ + + block = NULL_TREE; + block_previously_created = (current_binding_level->this_block != NULL_TREE); + if (block_previously_created) + block = current_binding_level->this_block; + else if (keep == 1 || functionbody) + block = make_node (BLOCK); + if (block != NULL_TREE) + { + BLOCK_VARS (block) = decls; + BLOCK_TYPE_TAGS (block) = tags; + BLOCK_SUBBLOCKS (block) = subblocks; + /* If we created the block earlier on, and we are just diddling it now, + then it already should have a proper BLOCK_END_NOTE value associated + with it, so avoid trashing that. Otherwise, for a new block, install + a new BLOCK_END_NOTE value. */ + if (! block_previously_created) + remember_end_note (block); + } + + /* In each subblock, record that this is its superior. */ + + if (keep >= 0) + for (link = subblocks; link; link = TREE_CHAIN (link)) + BLOCK_SUPERCONTEXT (link) = block; + + /* Clear out the meanings of the local variables of this level. */ + + for (link = current_binding_level->dead_vars_from_for; + link != NULL_TREE; link = TREE_CHAIN (link)) + { + if (DECL_DEAD_FOR_LOCAL (link)) + { + tree id = DECL_NAME (link); + if (IDENTIFIER_LOCAL_VALUE (id) == link) + IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); + } + } + + if (current_binding_level->is_for_scope && flag_new_for_scope == 1) + { + for (link = decls; link; link = TREE_CHAIN (link)) + { + if (TREE_CODE (link) == VAR_DECL) + DECL_DEAD_FOR_LOCAL (link) = 1; + } + } + else + { + for (link = decls; link; link = TREE_CHAIN (link)) + { + if (DECL_NAME (link) != NULL_TREE) + { + /* If the ident. was used or addressed via a local extern decl, + don't forget that fact. */ + if (DECL_EXTERNAL (link)) + { + if (TREE_USED (link)) + TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; + if (TREE_ADDRESSABLE (link)) + TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; + } + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; + } + } + } + + /* Restore all name-meanings of the outer levels + that were shadowed by this level. */ + + if (current_binding_level->is_for_scope && flag_new_for_scope == 1) + { + struct binding_level *outer = current_binding_level->level_chain; + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + { + tree id = TREE_PURPOSE (link); + tree decl = IDENTIFIER_LOCAL_VALUE (id); + if (DECL_DEAD_FOR_LOCAL (decl)) + DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); + else + IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); + } + + /* Save declarations made in a 'for' statement so we can support pre-ANSI + 'for' scoping semantics. */ + + /* We append the current names of for-variables to those from previous + declarations, so that when we get around to do an poplevel + on the OUTER level, we restore the any shadowed readl bindings. + Note that the new names are put first on the combined list, + so they get to be restored first. This is important if there are + two for-loops using the same for-variable in the same block. + The binding we really want restored is whatever binding was shadowed + by the *first* for-variable, not the binding shadowed by the + second for-variable (which would be the first for-variable). */ + outer->dead_vars_from_for + = chainon (current_binding_level->names, outer->dead_vars_from_for); + } + else + { + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + } + for (link = current_binding_level->class_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->type_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + + /* If the level being exited is the top level of a function, + check over all the labels. */ + + if (functionbody) + { + /* If this is the top level block of a function, + the vars are the function's parameters. + Don't leave them in the BLOCK because they are + found in the FUNCTION_DECL instead. */ + + BLOCK_VARS (block) = 0; + + /* Clear out the definitions of all label names, + since their scopes end here. */ + + for (link = named_labels; link; link = TREE_CHAIN (link)) + { + register tree label = TREE_VALUE (link); + + if (DECL_INITIAL (label) == NULL_TREE) + { + cp_error_at ("label `%D' used but not defined", label); + /* Avoid crashing later. */ + define_label (input_filename, 1, DECL_NAME (label)); + } + else if (warn_unused && !TREE_USED (label)) + cp_warning_at ("label `%D' defined but not used", label); + SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); + + /* Put the labels into the "variables" of the + top-level block, so debugger can see them. */ + TREE_CHAIN (label) = BLOCK_VARS (block); + BLOCK_VARS (block) = label; + } + + named_labels = NULL_TREE; + } + + /* Any uses of undefined labels now operate under constraints + of next binding contour. */ + { + struct binding_level *level_chain; + level_chain = current_binding_level->level_chain; + if (level_chain) + { + tree labels; + for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels)) + if (TREE_TYPE (labels) == (tree)current_binding_level) + { + TREE_TYPE (labels) = (tree)level_chain; + TREE_PURPOSE (labels) = level_chain->names; + } + } + } + + tmp = current_binding_level->keep; + + pop_binding_level (); + if (functionbody) + DECL_INITIAL (current_function_decl) = block; + else if (block) + { + if (!block_previously_created) + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); + } + /* If we did not make a block for the level just exited, + any blocks made for inner levels + (since they cannot be recorded as subblocks in that level) + must be carried forward so they will later become subblocks + of something else. */ + else if (subblocks) + { + if (keep == 2) + current_binding_level->blocks + = chainon (subblocks, current_binding_level->blocks); + else + current_binding_level->blocks + = chainon (current_binding_level->blocks, subblocks); + } + + /* Take care of compiler's internal binding structures. */ + if (tmp == 2) + { +#if 0 + /* We did not call push_momentary for this + binding contour, so there is nothing to pop. */ + pop_momentary (); +#endif + expand_end_bindings (getdecls (), keep, 1); + /* Each and every BLOCK node created here in `poplevel' is important + (e.g. for proper debugging information) so if we created one + earlier, mark it as "used". */ + if (block) + TREE_USED (block) = 1; + block = poplevel (keep, reverse, real_functionbody); + } + + /* Each and every BLOCK node created here in `poplevel' is important + (e.g. for proper debugging information) so if we created one + earlier, mark it as "used". */ + if (block) + TREE_USED (block) = 1; + return block; +} + +/* Resume a binding level for a namespace. */ +void +resume_level (b) + struct binding_level *b; +{ + tree decls, link; + + resume_binding_level (b); + + /* Resume the variable caches. */ + decls = current_binding_level->names; + + /* Restore the meanings of the local variables of this level. */ + + for (link = decls; link; link = TREE_CHAIN (link)) + { + if (DECL_NAME (link) != NULL_TREE) + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; + + /* If this is a TYPE_DECL, push it into the type value slot. */ + if (TREE_CODE (link) == TYPE_DECL) + SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); + } +} + +/* Delete the node BLOCK from the current binding level. + This is used for the block inside a stmt expr ({...}) + so that the block can be reinserted where appropriate. */ + +void +delete_block (block) + tree block; +{ + tree t; + if (current_binding_level->blocks == block) + current_binding_level->blocks = TREE_CHAIN (block); + for (t = current_binding_level->blocks; t;) + { + if (TREE_CHAIN (t) == block) + TREE_CHAIN (t) = TREE_CHAIN (block); + else + t = TREE_CHAIN (t); + } + TREE_CHAIN (block) = NULL_TREE; + /* Clear TREE_USED which is always set by poplevel. + The flag is set again if insert_block is called. */ + TREE_USED (block) = 0; +} + +/* Insert BLOCK at the end of the list of subblocks of the + current binding level. This is used when a BIND_EXPR is expanded, + to handle the BLOCK node inside the BIND_EXPR. */ + +void +insert_block (block) + tree block; +{ + TREE_USED (block) = 1; + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); +} + +/* Add BLOCK to the current list of blocks for this binding contour. */ +void +add_block_current_level (block) + tree block; +{ + current_binding_level->blocks + = chainon (current_binding_level->blocks, block); +} + +/* Set the BLOCK node for the innermost scope + (the one we are currently in). */ + +void +set_block (block) + register tree block; +{ + current_binding_level->this_block = block; +} + +/* Do a pushlevel for class declarations. */ +void +pushlevel_class () +{ + register struct binding_level *newlevel; + + /* Reuse or create a struct for this binding level. */ +#if defined(DEBUG_CP_BINDING_LEVELS) + if (0) +#else /* !defined(DEBUG_CP_BINDING_LEVELS) */ + if (free_binding_level) +#endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ + { + newlevel = free_binding_level; + free_binding_level = free_binding_level->level_chain; + } + else + { + /* Create a new `struct binding_level'. */ + newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); + } + +#if defined(DEBUG_CP_BINDING_LEVELS) + is_class_level = 1; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + + push_binding_level (newlevel, 0, 0); + + decl_stack = push_decl_level (decl_stack, &decl_obstack); + class_binding_level = current_binding_level; + class_binding_level->parm_flag = 2; + /* We have just pushed into a new binding level. Now, fake out the rest + of the compiler. Set the `current_binding_level' back to point to + the most closely containing non-class binding level. */ + do + { + current_binding_level = current_binding_level->level_chain; + } + while (current_binding_level->parm_flag == 2); +} + +/* ...and a poplevel for class declarations. FORCE is used to force + clearing out of CLASS_VALUEs after a class definition. */ +tree +poplevel_class (force) + int force; +{ + register struct binding_level *level = class_binding_level; + tree block = NULL_TREE; + tree shadowed; + + my_friendly_assert (level != 0, 354); + + decl_stack = pop_stack_level (decl_stack); + for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); + /* If we're leaving a toplevel class, don't bother to do the setting + of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot + shouldn't even be used when current_class_type isn't set, and second, + if we don't touch it here, we're able to use the cache effect if the + next time we're entering a class scope, it is the same class. */ + if (current_class_depth != 1 || force) + for (shadowed = level->class_shadowed; + shadowed; + shadowed = TREE_CHAIN (shadowed)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); + else + /* Remember to save what IDENTIFIER's were bound in this scope so we + can recover from cache misses. */ + previous_class_values = class_binding_level->class_shadowed; + for (shadowed = level->type_shadowed; + shadowed; + shadowed = TREE_CHAIN (shadowed)) + IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); + + GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, + (HOST_WIDE_INT) class_binding_level->level_chain, + class_binding_level->parm_flag, + class_binding_level->keep, + class_binding_level->tag_transparent); + + if (class_binding_level->parm_flag != 2) + class_binding_level = (struct binding_level *)0; + + /* Now, pop out of the the binding level which we created up in the + `pushlevel_class' routine. */ +#if defined(DEBUG_CP_BINDING_LEVELS) + is_class_level = 1; +#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ + + pop_binding_level (); + + return block; +} + +/* For debugging. */ +int no_print_functions = 0; +int no_print_builtins = 0; + +void +print_binding_level (lvl) + struct binding_level *lvl; +{ + tree t; + int i = 0, len; + fprintf (stderr, " blocks="); + fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); + fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", + list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); + if (lvl->tag_transparent) + fprintf (stderr, " tag-transparent"); + if (lvl->more_cleanups_ok) + fprintf (stderr, " more-cleanups-ok"); + if (lvl->have_cleanups) + fprintf (stderr, " have-cleanups"); + fprintf (stderr, "\n"); + if (lvl->names) + { + fprintf (stderr, " names:\t"); + /* We can probably fit 3 names to a line? */ + for (t = lvl->names; t; t = TREE_CHAIN (t)) + { + if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) + continue; + if (no_print_builtins + && (TREE_CODE(t) == TYPE_DECL) + && (!strcmp(DECL_SOURCE_FILE(t),""))) + continue; + + /* Function decls tend to have longer names. */ + if (TREE_CODE (t) == FUNCTION_DECL) + len = 3; + else + len = 2; + i += len; + if (i > 6) + { + fprintf (stderr, "\n\t"); + i = len; + } + print_node_brief (stderr, "", t, 0); + if (TREE_CODE (t) == ERROR_MARK) + break; + } + if (i) + fprintf (stderr, "\n"); + } + if (lvl->tags) + { + fprintf (stderr, " tags:\t"); + i = 0; + for (t = lvl->tags; t; t = TREE_CHAIN (t)) + { + if (TREE_PURPOSE (t) == NULL_TREE) + len = 3; + else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) + len = 2; + else + len = 4; + i += len; + if (i > 5) + { + fprintf (stderr, "\n\t"); + i = len; + } + if (TREE_PURPOSE (t) == NULL_TREE) + { + print_node_brief (stderr, ""); + } + else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) + print_node_brief (stderr, "", TREE_VALUE (t), 0); + else + { + print_node_brief (stderr, ""); + } + } + if (i) + fprintf (stderr, "\n"); + } + if (lvl->shadowed) + { + fprintf (stderr, " shadowed:"); + for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) + { + fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); + } + fprintf (stderr, "\n"); + } + if (lvl->class_shadowed) + { + fprintf (stderr, " class-shadowed:"); + for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) + { + fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); + } + fprintf (stderr, "\n"); + } + if (lvl->type_shadowed) + { + fprintf (stderr, " type-shadowed:"); + for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) + { +#if 0 + fprintf (stderr, "\n\t"); + print_node_brief (stderr, "<", TREE_PURPOSE (t), 0); + if (TREE_VALUE (t)) + print_node_brief (stderr, " ", TREE_VALUE (t), 0); + else + fprintf (stderr, " (none)"); + fprintf (stderr, ">"); +#else + fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); +#endif + } + fprintf (stderr, "\n"); + } +} + +void +print_other_binding_stack (stack) + struct binding_level *stack; +{ + struct binding_level *level; + for (level = stack; level != global_binding_level; level = level->level_chain) + { + fprintf (stderr, "binding level "); + fprintf (stderr, HOST_PTR_PRINTF, level); + fprintf (stderr, "\n"); + print_binding_level (level); + } +} + +void +print_binding_stack () +{ + struct binding_level *b; + fprintf (stderr, "current_binding_level="); + fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); + fprintf (stderr, "\nclass_binding_level="); + fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); + fprintf (stderr, "\nglobal_binding_level="); + fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); + fprintf (stderr, "\n"); + if (class_binding_level) + { + for (b = class_binding_level; b; b = b->level_chain) + if (b == current_binding_level) + break; + if (b) + b = class_binding_level; + else + b = current_binding_level; + } + else + b = current_binding_level; + print_other_binding_stack (b); + fprintf (stderr, "global:\n"); + print_binding_level (global_binding_level); +} + +extern char * first_global_object_name; + +/* Get a unique name for each call to this routine for unnamed namespaces. + Mostly copied from get_file_function_name. */ +static tree +get_unique_name () +{ + static int temp_name_counter = 0; + char *buf; + register char *p; + + if (first_global_object_name) + p = first_global_object_name; + else if (main_input_filename) + p = main_input_filename; + else + p = input_filename; + +#define UNNAMED_NAMESPACE_FORMAT "__%s_%d" + + buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); + + sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); + + /* Don't need to pull weird characters out of global names. */ + if (p != first_global_object_name) + { + for (p = buf+11; *p; p++) + if (! ((*p >= '0' && *p <= '9') +#if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */ +#ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */ + || *p == '.' +#endif +#endif +#ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ + || *p == '$' +#endif +#ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ + || *p == '.' +#endif + || (*p >= 'A' && *p <= 'Z') + || (*p >= 'a' && *p <= 'z'))) + *p = '_'; + } + + return get_identifier (buf); +} + +/* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we + select a name that is unique to this compilation unit. */ +void +push_namespace (name) + tree name; +{ + extern tree current_namespace; + tree old_id = get_namespace_id (); + char *buf; + tree d = make_node (NAMESPACE_DECL); + + if (! name) + { + /* Create a truly ugly name! */ + name = get_unique_name (); + } + + DECL_NAME (d) = name; + DECL_ASSEMBLER_NAME (d) = name; + /* pushdecl wants to check the size of it to see if it is incomplete... */ + TREE_TYPE (d) = void_type_node; + /* Mark them as external, so redeclaration_error_message doesn't think + they are duplicates. */ + DECL_EXTERNAL (d) = 1; + d = pushdecl (d); + + if (NAMESPACE_LEVEL (d) == 0) + { + /* This is new for this compilation unit. */ + pushlevel (0); + declare_namespace_level (); + NAMESPACE_LEVEL (d) = (tree)current_binding_level; + } + else + { + resume_level ((struct binding_level*)NAMESPACE_LEVEL (d)); + } + + /* This code is just is bit old now... */ + current_namespace = tree_cons (NULL_TREE, name, current_namespace); + buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) + + IDENTIFIER_LENGTH (name)); + sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", + IDENTIFIER_POINTER (name)); + TREE_PURPOSE (current_namespace) = get_identifier (buf); +} + +/* Pop from the scope of the current namespace. */ +void +pop_namespace () +{ + extern tree current_namespace; + tree decls, link; + current_namespace = TREE_CHAIN (current_namespace); + + /* Just in case we get out of sync. */ + if (! namespace_bindings_p ()) + poplevel (0, 0, 0); + + decls = current_binding_level->names; + + /* Clear out the meanings of the local variables of this level. */ + + for (link = decls; link; link = TREE_CHAIN (link)) + { + if (DECL_NAME (link) != NULL_TREE) + { + /* If the ident. was used or addressed via a local extern decl, + don't forget that fact. */ + if (DECL_EXTERNAL (link)) + { + if (TREE_USED (link)) + TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; + if (TREE_ADDRESSABLE (link)) + TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; + } + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; + } + } + + /* Restore all name-meanings of the outer levels + that were shadowed by this level. */ + + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->class_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->type_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + + /* suspend a level. */ + suspend_binding_level (); +} + +/* Subroutines for reverting temporarily to top-level for instantiation + of templates and such. We actually need to clear out the class- and + local-value slots of all identifiers, so that only the global values + are at all visible. Simply setting current_binding_level to the global + scope isn't enough, because more binding levels may be pushed. */ +struct saved_scope { + struct binding_level *old_binding_level; + tree old_bindings; + struct saved_scope *prev; + tree class_name, class_type, function_decl; + tree base_init_list, member_init_list; + struct binding_level *class_bindings; + tree previous_class_type; + tree *lang_base, *lang_stack, lang_name; + int lang_stacksize; + tree named_labels; +}; +static struct saved_scope *current_saved_scope; +extern tree prev_class_type; + +void +push_to_top_level () +{ + extern int current_lang_stacksize; + struct saved_scope *s = + (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); + struct binding_level *b = current_binding_level; + tree old_bindings = NULL_TREE; + + /* Have to include global_binding_level, because class-level decls + aren't listed anywhere useful. */ + for (; b; b = b->level_chain) + { + tree t; + + if (b == global_binding_level) + continue; + + for (t = b->names; t; t = TREE_CHAIN (t)) + { + tree binding, t1, t2 = t; + tree id = DECL_ASSEMBLER_NAME (t2); + + if (!id + || (!IDENTIFIER_LOCAL_VALUE (id) + && !IDENTIFIER_CLASS_VALUE (id))) + continue; + + for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) + if (TREE_VEC_ELT (t1, 0) == id) + goto skip_it; + + binding = make_tree_vec (4); + if (id) + { + my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); + TREE_VEC_ELT (binding, 0) = id; + TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); + TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); + TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); + IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; + IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; + } + TREE_CHAIN (binding) = old_bindings; + old_bindings = binding; + skip_it: + ; + } + /* Unwind type-value slots back to top level. */ + for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) + SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); + } + /* Clear out class-level bindings cache. */ + if (current_binding_level == global_binding_level + && previous_class_type != NULL_TREE) + { + popclass (-1); + previous_class_type = NULL_TREE; + } + + s->old_binding_level = current_binding_level; + current_binding_level = global_binding_level; + + s->class_name = current_class_name; + s->class_type = current_class_type; + s->function_decl = current_function_decl; + s->base_init_list = current_base_init_list; + s->member_init_list = current_member_init_list; + s->class_bindings = class_binding_level; + s->previous_class_type = previous_class_type; + s->lang_stack = current_lang_stack; + s->lang_base = current_lang_base; + s->lang_stacksize = current_lang_stacksize; + s->lang_name = current_lang_name; + s->named_labels = named_labels; + current_class_name = current_class_type = NULL_TREE; + current_function_decl = NULL_TREE; + class_binding_level = (struct binding_level *)0; + previous_class_type = NULL_TREE; + current_lang_stacksize = 10; + current_lang_stack = current_lang_base + = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); + current_lang_name = lang_name_cplusplus; + strict_prototype = strict_prototypes_lang_cplusplus; + named_labels = NULL_TREE; + + s->prev = current_saved_scope; + s->old_bindings = old_bindings; + current_saved_scope = s; +} + +void +pop_from_top_level () +{ + extern int current_lang_stacksize; + struct saved_scope *s = current_saved_scope; + tree t; + + if (previous_class_type) + previous_class_type = NULL_TREE; + + current_binding_level = s->old_binding_level; + current_saved_scope = s->prev; + for (t = s->old_bindings; t; t = TREE_CHAIN (t)) + { + tree id = TREE_VEC_ELT (t, 0); + if (id) + { + IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); + IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); + IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); + } + } + current_class_name = s->class_name; + current_class_type = s->class_type; + current_base_init_list = s->base_init_list; + current_member_init_list = s->member_init_list; + current_function_decl = s->function_decl; + class_binding_level = s->class_bindings; + previous_class_type = s->previous_class_type; + free (current_lang_base); + current_lang_base = s->lang_base; + current_lang_stack = s->lang_stack; + current_lang_name = s->lang_name; + current_lang_stacksize = s->lang_stacksize; + if (current_lang_name == lang_name_cplusplus) + strict_prototype = strict_prototypes_lang_cplusplus; + else if (current_lang_name == lang_name_c) + strict_prototype = strict_prototypes_lang_c; + named_labels = s->named_labels; + + free (s); +} + +/* Push a definition of struct, union or enum tag "name". + into binding_level "b". "type" should be the type node, + We assume that the tag "name" is not already defined. + + Note that the definition may really be just a forward reference. + In that case, the TYPE_SIZE will be a NULL_TREE. + + C++ gratuitously puts all these tags in the name space. */ + +/* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, + record the shadowed value for this binding contour. TYPE is + the type that ID maps to. */ + +static void +set_identifier_type_value_with_scope (id, type, b) + tree id; + tree type; + struct binding_level *b; +{ + if (b != global_binding_level) + { + tree old_type_value = IDENTIFIER_TYPE_VALUE (id); + b->type_shadowed + = tree_cons (id, old_type_value, b->type_shadowed); + } + SET_IDENTIFIER_TYPE_VALUE (id, type); +} + +/* As set_identifier_type_value_with_scope, but using inner_binding_level. */ + +void +set_identifier_type_value (id, type) + tree id; + tree type; +{ + set_identifier_type_value_with_scope (id, type, inner_binding_level); +} + +/* Subroutine "set_nested_typename" builds the nested-typename of + the type decl in question. (Argument CLASSNAME can actually be + a function as well, if that's the smallest containing scope.) */ + +static void +set_nested_typename (decl, classname, name, type) + tree decl, classname, name, type; +{ + char *buf; + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); + + /* No need to do this for anonymous names, since they're unique. */ + if (ANON_AGGRNAME_P (name)) + { + DECL_NESTED_TYPENAME (decl) = name; + return; + } + + if (classname == NULL_TREE) + classname = get_identifier (""); + + my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137); + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138); + buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname) + + IDENTIFIER_LENGTH (name)); + sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname), + IDENTIFIER_POINTER (name)); + DECL_NESTED_TYPENAME (decl) = get_identifier (buf); + TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1; + + /* Create an extra decl so that the nested name will have a type value + where appropriate. */ + { + tree nested, type_decl; + nested = DECL_NESTED_TYPENAME (decl); + type_decl = build_decl (TYPE_DECL, nested, type); + DECL_NESTED_TYPENAME (type_decl) = nested; + SET_DECL_ARTIFICIAL (type_decl); + /* Mark the TYPE_DECL node created just above as a gratuitous one so that + dwarfout.c will know not to generate a TAG_typedef DIE for it, and + sdbout.c won't try to output a .def for "::foo". */ + DECL_IGNORED_P (type_decl) = 1; + + /* Remove this when local classes are fixed. */ + SET_IDENTIFIER_TYPE_VALUE (nested, type); + + pushdecl_nonclass_level (type_decl); + } +} + +/* Pop off extraneous binding levels left over due to syntax errors. + + We don't pop past namespaces, as they might be valid. */ +void +pop_everything () +{ +#ifdef DEBUG_CP_BINDING_LEVELS + fprintf (stderr, "XXX entering pop_everything ()\n"); +#endif + while (! toplevel_bindings_p () && ! pseudo_global_level_p ()) + { + if (class_binding_level) + pop_nested_class (1); + else + poplevel (0, 0, 0); + } +#ifdef DEBUG_CP_BINDING_LEVELS + fprintf (stderr, "XXX leaving pop_everything ()\n"); +#endif +} + +#if 0 /* not yet, should get fixed properly later */ +/* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME. + Other routines shouldn't use build_decl directly; they'll produce + incorrect results with `-g' unless they duplicate this code. + + This is currently needed mainly for dbxout.c, but we can make + use of it in method.c later as well. */ +tree +make_type_decl (name, type) + tree name, type; +{ + tree decl, id; + decl = build_decl (TYPE_DECL, name, type); + if (TYPE_NAME (type) == name) + /* Class/union/enum definition, or a redundant typedef for same. */ + { + id = get_identifier (build_overload_name (type, 1, 1)); + DECL_ASSEMBLER_NAME (decl) = id; + } + else if (TYPE_NAME (type) != NULL_TREE) + /* Explicit typedef, or implicit typedef for template expansion. */ + DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); + else + { + /* XXX: Typedef for unnamed struct; some other situations. + TYPE_NAME is null; what's right here? */ + } + return decl; +} +#endif + +/* Push a tag name NAME for struct/class/union/enum type TYPE. + Normally put into into the inner-most non-tag-transparent scope, + but if GLOBALIZE is true, put it in the inner-most non-class scope. + The latter is needed for implicit declarations. */ + +void +pushtag (name, type, globalize) + tree name, type; + int globalize; +{ + register struct binding_level *b; + tree context = 0; + tree c_decl = 0; + + b = inner_binding_level; + while (b->tag_transparent + || (globalize && b->parm_flag == 2)) + b = b->level_chain; + + if (toplevel_bindings_p ()) + b->tags = perm_tree_cons (name, type, b->tags); + else + b->tags = saveable_tree_cons (name, type, b->tags); + + if (name) + { + context = type ? TYPE_CONTEXT (type) : NULL_TREE; + if (! context && ! globalize) + context = current_scope (); + if (context) + c_decl = TREE_CODE (context) == FUNCTION_DECL + ? context : TYPE_MAIN_DECL (context); + +#if 0 + /* Record the identifier as the type's name if it has none. */ + if (TYPE_NAME (type) == NULL_TREE) + TYPE_NAME (type) = name; +#endif + + /* Do C++ gratuitous typedefing. */ + if (IDENTIFIER_TYPE_VALUE (name) != type) + { + register tree d; + int newdecl = 0; + + if (b->parm_flag != 2 + || TYPE_SIZE (current_class_type) != NULL_TREE) + { + d = lookup_nested_type (type, c_decl); + + if (d == NULL_TREE) + { + newdecl = 1; +#if 0 /* not yet, should get fixed properly later */ + d = make_type_decl (name, type); +#else + d = build_decl (TYPE_DECL, name, type); + DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d)); +#endif + SET_DECL_ARTIFICIAL (d); +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG) + { + /* Mark the TYPE_DECL node we created just above as an + gratuitous one. We need to do this so that dwarfout.c + will understand that it is not supposed to output a + TAG_typedef DIE for it. */ + DECL_IGNORED_P (d) = 1; + } +#endif /* DWARF_DEBUGGING_INFO */ + set_identifier_type_value_with_scope (name, type, b); + } + else + d = TYPE_NAME (d); + + TYPE_NAME (type) = d; + + /* If it is anonymous, then we are called from pushdecl, + and we don't want to infinitely recurse. */ + if (! ANON_AGGRNAME_P (name)) + { + if (b->parm_flag == 2) + d = pushdecl_class_level (d); + else + d = pushdecl_with_scope (d, b); + } + } + else + { + /* Make nested declarations go into class-level scope. */ + newdecl = 1; + d = build_decl (TYPE_DECL, name, type); + SET_DECL_ARTIFICIAL (d); +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG) + { + /* Mark the TYPE_DECL node we created just above as an + gratuitous one. We need to do this so that dwarfout.c + will understand that it is not supposed to output a + TAG_typedef DIE for it. */ + DECL_IGNORED_P (d) = 1; + } +#endif /* DWARF_DEBUGGING_INFO */ + + TYPE_MAIN_DECL (type) = d; + + /* Make sure we're in this type's scope when we push the + decl for a template, otherwise class_binding_level will + be NULL and we'll end up dying inside of + push_class_level_binding. */ + if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + pushclass (type, 0); + d = pushdecl_class_level (d); + if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + popclass (0); + } + if (newdecl) + { + if (write_symbols != DWARF_DEBUG) + { + if (ANON_AGGRNAME_P (name)) + DECL_IGNORED_P (d) = 1; + } + + if (context == NULL_TREE) + /* Non-nested class. */ + set_nested_typename (d, NULL_TREE, name, type); + else if (context && TREE_CODE (context) == FUNCTION_DECL) + /* Function-nested class. */ + set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl), + name, type); + else /* if (context && IS_AGGR_TYPE (context)) */ + /* Class-nested class. */ + set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl), + name, type); + + DECL_CONTEXT (d) = context; + TYPE_CONTEXT (type) = DECL_CONTEXT (d); + DECL_ASSEMBLER_NAME (d) + = get_identifier (build_overload_name (type, 1, 1)); + } + } + if (b->parm_flag == 2) + { + TREE_NONLOCAL_FLAG (type) = 1; + if (TYPE_SIZE (current_class_type) == NULL_TREE) + CLASSTYPE_TAGS (current_class_type) = b->tags; + } + } + + if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) + /* Use the canonical TYPE_DECL for this node. */ + TYPE_STUB_DECL (type) = TYPE_NAME (type); + else + { + /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE + will be the tagged type we just added to the current + binding level. This fake NULL-named TYPE_DECL node helps + dwarfout.c to know when it needs to output a + representation of a tagged type, and it also gives us a + convenient place to record the "scope start" address for + the tagged type. */ + +#if 0 /* not yet, should get fixed properly later */ + tree d = make_type_decl (NULL_TREE, type); +#else + tree d = build_decl (TYPE_DECL, NULL_TREE, type); +#endif + TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); + } +} + +/* Counter used to create anonymous type names. */ +static int anon_cnt = 0; + +/* Return an IDENTIFIER which can be used as a name for + anonymous structs and unions. */ +tree +make_anon_name () +{ + char buf[32]; + + sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); + return get_identifier (buf); +} + +/* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. + This keeps dbxout from getting confused. */ +void +clear_anon_tags () +{ + register struct binding_level *b; + register tree tags; + static int last_cnt = 0; + + /* Fast out if no new anon names were declared. */ + if (last_cnt == anon_cnt) + return; + + b = current_binding_level; + while (b->tag_transparent) + b = b->level_chain; + tags = b->tags; + while (tags) + { + /* A NULL purpose means we have already processed all tags + from here to the end of the list. */ + if (TREE_PURPOSE (tags) == NULL_TREE) + break; + if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) + TREE_PURPOSE (tags) = NULL_TREE; + tags = TREE_CHAIN (tags); + } + last_cnt = anon_cnt; +} + +/* Subroutine of duplicate_decls: return truthvalue of whether + or not types of these decls match. + + For C++, we must compare the parameter list so that `int' can match + `int&' in a parameter position, but `int&' is not confused with + `const int&'. */ +int +decls_match (newdecl, olddecl) + tree newdecl, olddecl; +{ + int types_match; + + if (TREE_CODE (newdecl) == FUNCTION_DECL + && TREE_CODE (olddecl) == FUNCTION_DECL) + { + tree f1 = TREE_TYPE (newdecl); + tree f2 = TREE_TYPE (olddecl); + tree p1 = TYPE_ARG_TYPES (f1); + tree p2 = TYPE_ARG_TYPES (f2); + + /* When we parse a static member function definition, + we put together a FUNCTION_DECL which thinks its type + is METHOD_TYPE. Change that to FUNCTION_TYPE, and + proceed. */ + if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) + revert_static_member_fn (&newdecl, &f1, &p1); + else if (TREE_CODE (f2) == METHOD_TYPE + && DECL_STATIC_FUNCTION_P (newdecl)) + revert_static_member_fn (&olddecl, &f2, &p2); + + /* Here we must take care of the case where new default + parameters are specified. Also, warn if an old + declaration becomes ambiguous because default + parameters may cause the two to be ambiguous. */ + if (TREE_CODE (f1) != TREE_CODE (f2)) + { + if (TREE_CODE (f1) == OFFSET_TYPE) + cp_compiler_error ("`%D' redeclared as member function", newdecl); + else + cp_compiler_error ("`%D' redeclared as non-member function", newdecl); + return 0; + } + + if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1)) + { + if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c + && p2 == NULL_TREE) + { + types_match = self_promoting_args_p (p1); + if (p1 == void_list_node) + TREE_TYPE (newdecl) = TREE_TYPE (olddecl); + } + else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c + && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) + { + types_match = self_promoting_args_p (p2); + TREE_TYPE (newdecl) = TREE_TYPE (olddecl); + } + else + types_match = compparms (p1, p2, 3); + } + else + types_match = 0; + } + else if (TREE_CODE (newdecl) == TEMPLATE_DECL + && TREE_CODE (olddecl) == TEMPLATE_DECL) + { + tree newargs = DECL_TEMPLATE_PARMS (newdecl); + tree oldargs = DECL_TEMPLATE_PARMS (olddecl); + int i, len = TREE_VEC_LENGTH (newargs); + + if (TREE_VEC_LENGTH (oldargs) != len) + return 0; + + for (i = 0; i < len; i++) + { + tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i)); + tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i)); + if (TREE_CODE (newarg) != TREE_CODE (oldarg)) + return 0; + else if (TREE_CODE (newarg) == TYPE_DECL) + /* continue */; + else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1)) + return 0; + } + + if (DECL_TEMPLATE_IS_CLASS (newdecl) + != DECL_TEMPLATE_IS_CLASS (olddecl)) + types_match = 0; + else if (DECL_TEMPLATE_IS_CLASS (newdecl)) + types_match = 1; + else + types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), + DECL_TEMPLATE_RESULT (newdecl)); + } + else + { + if (TREE_TYPE (newdecl) == error_mark_node) + types_match = TREE_TYPE (olddecl) == error_mark_node; + else if (TREE_TYPE (olddecl) == NULL_TREE) + types_match = TREE_TYPE (newdecl) == NULL_TREE; + else if (TREE_TYPE (newdecl) == NULL_TREE) + types_match = 0; + else + types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1); + } + + return types_match; +} + +/* If NEWDECL is `static' and an `extern' was seen previously, + warn about it. (OLDDECL may be NULL_TREE; NAME contains + information about previous usage as an `extern'.) + + Note that this does not apply to the C++ case of declaring + a variable `extern const' and then later `const'. + + Don't complain if -traditional, since traditional compilers + don't complain. + + Don't complain about built-in functions, since they are beyond + the user's control. */ + +static void +warn_extern_redeclared_static (newdecl, olddecl) + tree newdecl, olddecl; +{ + tree name; + + static char *explicit_extern_static_warning + = "`%D' was declared `extern' and later `static'"; + static char *implicit_extern_static_warning + = "`%D' was declared implicitly `extern' and later `static'"; + + if (flag_traditional + || TREE_CODE (newdecl) == TYPE_DECL) + return; + + name = DECL_ASSEMBLER_NAME (newdecl); + if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) + { + /* It's okay to redeclare an ANSI built-in function as static, + or to declare a non-ANSI built-in function as anything. */ + if (! (TREE_CODE (newdecl) == FUNCTION_DECL + && olddecl != NULL_TREE + && TREE_CODE (olddecl) == FUNCTION_DECL + && (DECL_BUILT_IN (olddecl) + || DECL_BUILT_IN_NONANSI (olddecl)))) + { + cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) + ? implicit_extern_static_warning + : explicit_extern_static_warning, newdecl); + if (olddecl != NULL_TREE) + cp_pedwarn_at ("previous declaration of `%D'", olddecl); + } + } +} + +/* Handle when a new declaration NEWDECL has the same name as an old + one OLDDECL in the same binding contour. Prints an error message + if appropriate. + + If safely possible, alter OLDDECL to look like NEWDECL, and return 1. + Otherwise, return 0. */ + +int +duplicate_decls (newdecl, olddecl) + register tree newdecl, olddecl; +{ + extern struct obstack permanent_obstack; + unsigned olddecl_uid = DECL_UID (olddecl); + int olddecl_friend = 0, types_match = 0; + int new_defines_function; + tree previous_c_decl = NULL_TREE; + + if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') + DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); + + types_match = decls_match (newdecl, olddecl); + + if (TREE_CODE (olddecl) != TREE_LIST) + olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); + + /* If either the type of the new decl or the type of the old decl is an + error_mark_node, then that implies that we have already issued an + error (earlier) for some bogus type specification, and in that case, + it is rather pointless to harass the user with yet more error message + about the same declaration, so well just pretent the types match here. */ + if ((TREE_TYPE (newdecl) + && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK) + || (TREE_TYPE (olddecl) + && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)) + types_match = 1; + + if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL + && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl) + /* If -traditional, avoid error for redeclaring fcn + after implicit decl. */ + ; + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_ARTIFICIAL (olddecl) + && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) + { + /* If you declare a built-in or predefined function name as static, + the old definition is overridden, but optionally warn this was a + bad choice of name. Ditto for overloads. */ + if (! DECL_PUBLIC (newdecl) + || (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) + { + if (warn_shadow) + cp_warning ("shadowing %s function `%#D'", + DECL_BUILT_IN (olddecl) ? "built-in" : "library", + olddecl); + /* Discard the old built-in function. */ + return 0; + } + else if (! types_match) + { + if (TREE_CODE (newdecl) != FUNCTION_DECL) + { + /* If the built-in is not ansi, then programs can override + it even globally without an error. */ + if (! DECL_BUILT_IN (olddecl)) + cp_warning ("library function `%#D' redeclared as non-function `%#D'", + olddecl, newdecl); + else + { + cp_error ("declaration of `%#D'", newdecl); + cp_error ("conflicts with built-in declaration `%#D'", + olddecl); + } + return 0; + } + + cp_warning ("declaration of `%#D'", newdecl); + cp_warning ("conflicts with built-in declaration `%#D'", + olddecl); + } + } + else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) + { + if ((TREE_CODE (newdecl) == FUNCTION_DECL + && TREE_CODE (olddecl) == TEMPLATE_DECL + && ! DECL_TEMPLATE_IS_CLASS (olddecl)) + || (TREE_CODE (olddecl) == FUNCTION_DECL + && TREE_CODE (newdecl) == TEMPLATE_DECL + && ! DECL_TEMPLATE_IS_CLASS (newdecl))) + return 0; + + cp_error ("`%#D' redeclared as different kind of symbol", newdecl); + if (TREE_CODE (olddecl) == TREE_LIST) + olddecl = TREE_VALUE (olddecl); + cp_error_at ("previous declaration of `%#D'", olddecl); + + /* New decl is completely inconsistent with the old one => + tell caller to replace the old one. */ + + return 0; + } + else if (!types_match) + { + if (TREE_CODE (newdecl) == TEMPLATE_DECL) + { + /* The name of a class template may not be declared to refer to + any other template, class, function, object, namespace, value, + or type in the same scope. */ + if (DECL_TEMPLATE_IS_CLASS (olddecl) + || DECL_TEMPLATE_IS_CLASS (newdecl)) + { + cp_error ("declaration of template `%#D'", newdecl); + cp_error_at ("conflicts with previous declaration `%#D'", + olddecl); + } + return 0; + } + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + if (DECL_LANGUAGE (newdecl) == lang_c + && DECL_LANGUAGE (olddecl) == lang_c) + { + cp_error ("declaration of C function `%#D' conflicts with", + newdecl); + cp_error_at ("previous declaration `%#D' here", olddecl); + } + else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), + TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3)) + { + cp_error ("new declaration `%#D'", newdecl); + cp_error_at ("ambiguates old declaration `%#D'", olddecl); + } + else + return 0; + } + + /* Already complained about this, so don't do so again. */ + else if (current_class_type == NULL_TREE + || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) + { + cp_error ("conflicting types for `%#D'", newdecl); + cp_error_at ("previous declaration as `%#D'", olddecl); + } + } + else + { + char *errmsg = redeclaration_error_message (newdecl, olddecl); + if (errmsg) + { + cp_error (errmsg, newdecl); + if (DECL_NAME (olddecl) != NULL_TREE) + cp_error_at ((DECL_INITIAL (olddecl) + && current_binding_level == global_binding_level) + ? "`%#D' previously defined here" + : "`%#D' previously declared here", olddecl); + } + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_INITIAL (olddecl) != NULL_TREE + && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE + && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) + { + /* Prototype decl follows defn w/o prototype. */ + cp_warning_at ("prototype for `%#D'", newdecl); + cp_warning_at ("follows non-prototype definition here", olddecl); + } + else if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) + { + /* extern "C" int foo (); + int foo () { bar (); } + is OK. */ + if (current_lang_stack == current_lang_base) + DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); + else + { + cp_error_at ("previous declaration of `%#D' with %L linkage", + olddecl, DECL_LANGUAGE (olddecl)); + cp_error ("conflicts with new declaration with %L linkage", + DECL_LANGUAGE (newdecl)); + } + } + + if (TREE_CODE (olddecl) == FUNCTION_DECL) + { + tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); + tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); + int i = 1; + + if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) + t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); + + for (; t1 && t1 != void_list_node; + t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) + if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) + { + if (1 == simple_cst_equal (TREE_PURPOSE (t1), + TREE_PURPOSE (t2))) + { + if (pedantic) + { + cp_pedwarn ("default argument given for parameter %d of `%#D'", + i, newdecl); + cp_pedwarn_at ("after previous specification in `%#D'", + olddecl); + } + } + else + { + cp_error ("default argument given for parameter %d of `%#D'", + i, newdecl); + cp_error_at ("conflicts with previous specification in `%#D'", + olddecl); + } + } + + if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl)) + { +#if 0 /* I think this will be correct, but it's really annoying. We should + fix the compiler to find vtables by indirection so it isn't + necessary. (jason 8/25/95) */ + if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl)) + { + cp_pedwarn ("virtual function `%#D' redeclared inline", + newdecl); + cp_pedwarn_at ("previous non-inline declaration here", + olddecl); + } + else +#endif + if (TREE_ADDRESSABLE (olddecl)) + { + cp_pedwarn ("`%#D' was used before it was declared inline", + newdecl); + cp_pedwarn_at ("previous non-inline declaration here", + olddecl); + } + } + } + /* These bits are logically part of the type for non-functions. */ + else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) + || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) + { + cp_pedwarn ("type qualifiers for `%#D'", newdecl); + cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl); + } + } + + /* If new decl is `static' and an `extern' was seen previously, + warn about it. */ + warn_extern_redeclared_static (newdecl, olddecl); + + /* We have committed to returning 1 at this point. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + /* Now that functions must hold information normally held + by field decls, there is extra work to do so that + declaration information does not get destroyed during + definition. */ + if (DECL_VINDEX (olddecl)) + DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); + if (DECL_CONTEXT (olddecl)) + DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); + if (DECL_CLASS_CONTEXT (olddecl)) + DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); + if (DECL_CHAIN (newdecl) == NULL_TREE) + DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); + if (DECL_NEXT_METHOD (newdecl) == NULL_TREE) + DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl); + if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) + DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); + DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); + DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); + DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); + } + + /* Deal with C++: must preserve virtual function table size. */ + if (TREE_CODE (olddecl) == TYPE_DECL) + { + register tree newtype = TREE_TYPE (newdecl); + register tree oldtype = TREE_TYPE (olddecl); + + DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl); + + if (newtype != error_mark_node && oldtype != error_mark_node + && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) + { + CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); + CLASSTYPE_FRIEND_CLASSES (newtype) + = CLASSTYPE_FRIEND_CLASSES (oldtype); + } +#if 0 + /* why assert here? Just because debugging information is + messed up? (mrs) */ + /* it happens on something like: + typedef struct Thing { + Thing(); + int x; + } Thing; + */ + my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), + 139); +#endif + } + + /* Special handling ensues if new decl is a function definition. */ + new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_INITIAL (newdecl) != NULL_TREE); + + /* Optionally warn about more than one declaration for the same name, + but don't warn about a function declaration followed by a definition. */ + if (warn_redundant_decls + && ! DECL_ARTIFICIAL (olddecl) + && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) + /* Don't warn about extern decl followed by (tentative) definition. */ + && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) + { + cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); + cp_warning_at ("previous declaration of `%D'", olddecl); + } + + /* Copy all the DECL_... slots specified in the new decl + except for any that we copy here from the old type. */ + + if (types_match) + { + /* Automatically handles default parameters. */ + tree oldtype = TREE_TYPE (olddecl); + tree newtype; + + /* Make sure we put the new type in the same obstack as the old one. */ + if (oldtype) + push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); + else + { + push_obstacks_nochange (); + end_temporary_allocation (); + } + + /* Merge the data types specified in the two decls. */ + newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); + + if (TREE_CODE (newdecl) == VAR_DECL) + DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); + /* Do this after calling `common_type' so that default + parameters don't confuse us. */ + else if (TREE_CODE (newdecl) == FUNCTION_DECL + && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) + != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) + { + tree ctype = NULL_TREE; + ctype = DECL_CLASS_CONTEXT (newdecl); + TREE_TYPE (newdecl) = build_exception_variant (newtype, + TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); + TREE_TYPE (olddecl) = build_exception_variant (newtype, + TYPE_RAISES_EXCEPTIONS (oldtype)); + + if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) + { + cp_error ("declaration of `%D' throws different exceptions...", + newdecl); + cp_error_at ("...from previous declaration here", olddecl); + } + } + TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; + + /* Lay the type out, unless already done. */ + if (oldtype != TREE_TYPE (newdecl) + && TREE_TYPE (newdecl) != error_mark_node) + layout_type (TREE_TYPE (newdecl)); + + if (TREE_CODE (newdecl) == VAR_DECL + || TREE_CODE (newdecl) == PARM_DECL + || TREE_CODE (newdecl) == RESULT_DECL + || TREE_CODE (newdecl) == FIELD_DECL + || TREE_CODE (newdecl) == TYPE_DECL) + layout_decl (newdecl, 0); + + /* Merge the type qualifiers. */ + if (TREE_READONLY (newdecl)) + TREE_READONLY (olddecl) = 1; + if (TREE_THIS_VOLATILE (newdecl)) + TREE_THIS_VOLATILE (olddecl) = 1; + + /* Merge the initialization information. */ + if (DECL_INITIAL (newdecl) == NULL_TREE + && DECL_INITIAL (olddecl) != NULL_TREE) + { + DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); + DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); + DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); + } + + /* Merge the section attribute. + We want to issue an error if the sections conflict but that must be + done later in decl_attributes since we are called before attributes + are assigned. */ + if (DECL_SECTION_NAME (newdecl) == NULL_TREE) + DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); + + /* Keep the old rtl since we can safely use it, unless it's the + call to abort() used for abstract virtuals. */ + if ((DECL_LANG_SPECIFIC (olddecl) + && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) + || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) + DECL_RTL (newdecl) = DECL_RTL (olddecl); + + pop_obstacks (); + } + /* If cannot merge, then use the new type and qualifiers, + and don't preserve the old rtl. */ + else + { + /* Clean out any memory we had of the old declaration. */ + tree oldstatic = value_member (olddecl, static_aggregates); + if (oldstatic) + TREE_VALUE (oldstatic) = error_mark_node; + + TREE_TYPE (olddecl) = TREE_TYPE (newdecl); + TREE_READONLY (olddecl) = TREE_READONLY (newdecl); + TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); + TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); + } + + /* Merge the storage class information. */ + DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); + TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); + TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); + if (! DECL_EXTERNAL (olddecl)) + DECL_EXTERNAL (newdecl) = 0; + + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + DECL_C_STATIC (newdecl) = DECL_C_STATIC (olddecl); + DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); + DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); + } + + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); + + /* If either decl says `inline', this fn is inline, unless its + definition was passed already. */ + if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) + DECL_INLINE (olddecl) = 1; + DECL_INLINE (newdecl) = DECL_INLINE (olddecl); + + if (! types_match) + { + DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); + DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); + DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); + DECL_RESULT (olddecl) = DECL_RESULT (newdecl); + DECL_RTL (olddecl) = DECL_RTL (newdecl); + } + if (new_defines_function) + /* If defining a function declared with other language + linkage, use the previously declared language linkage. */ + DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); + else + { + /* If redeclaring a builtin function, and not a definition, + it stays built in. */ + if (DECL_BUILT_IN (olddecl)) + { + DECL_BUILT_IN (newdecl) = 1; + DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); + /* If we're keeping the built-in definition, keep the rtl, + regardless of declaration matches. */ + DECL_RTL (newdecl) = DECL_RTL (olddecl); + } + else + DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); + + DECL_RESULT (newdecl) = DECL_RESULT (olddecl); + if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) + /* Previously saved insns go together with + the function's previous definition. */ + DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); + /* Don't clear out the arguments if we're redefining a function. */ + if (DECL_ARGUMENTS (olddecl)) + DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); + } + if (DECL_LANG_SPECIFIC (olddecl)) + DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); + } + + if (TREE_CODE (newdecl) == NAMESPACE_DECL) + { + NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); + } + + if (TREE_CODE (newdecl) == TEMPLATE_DECL) + { + if (DECL_TEMPLATE_INFO (olddecl)->length) + DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); + DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl); + DECL_TEMPLATE_INSTANTIATIONS (newdecl) + = DECL_TEMPLATE_INSTANTIATIONS (olddecl); + if (DECL_CHAIN (newdecl) == NULL_TREE) + DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); + } + + /* Now preserve various other info from the definition. */ + TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); + TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); + DECL_COMMON (newdecl) = DECL_COMMON (olddecl); + DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); + + /* Don't really know how much of the language-specific + values we should copy from old to new. */ + if (DECL_LANG_SPECIFIC (olddecl)) + { + DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); + DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); + DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); + } + + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + int function_size; + struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); + struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); + + function_size = sizeof (struct tree_decl); + + bcopy ((char *) newdecl + sizeof (struct tree_common), + (char *) olddecl + sizeof (struct tree_common), + function_size - sizeof (struct tree_common)); + + /* Can we safely free the storage used by newdecl? */ + +#define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ + & ~ obstack_alignment_mask (&permanent_obstack)) + + if ((char *)newdecl + ROUND (function_size) + + ROUND (sizeof (struct lang_decl)) + == obstack_next_free (&permanent_obstack)) + { + DECL_MAIN_VARIANT (newdecl) = olddecl; + DECL_LANG_SPECIFIC (olddecl) = ol; + bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); + + obstack_free (&permanent_obstack, newdecl); + } + else if (LANG_DECL_PERMANENT (ol)) + { + if (DECL_MAIN_VARIANT (olddecl) == olddecl) + { + /* Save these lang_decls that would otherwise be lost. */ + extern tree free_lang_decl_chain; + tree free_lang_decl = (tree) ol; + TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; + free_lang_decl_chain = free_lang_decl; + } + else + { + /* Storage leak. */ + } + } + } + else + { + bcopy ((char *) newdecl + sizeof (struct tree_common), + (char *) olddecl + sizeof (struct tree_common), + sizeof (struct tree_decl) - sizeof (struct tree_common) + + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); + } + + DECL_UID (olddecl) = olddecl_uid; + if (olddecl_friend) + DECL_FRIEND_P (olddecl) = 1; + + return 1; +} + +/* Record a decl-node X as belonging to the current lexical scope. + Check for errors (such as an incompatible declaration for the same + name already seen in the same scope). + + Returns either X or an old decl for the same name. + If an old decl is returned, it may have been smashed + to agree with what X says. */ + +tree +pushdecl (x) + tree x; +{ + register tree t; +#if 0 /* not yet, should get fixed properly later */ + register tree name; +#else + register tree name = DECL_ASSEMBLER_NAME (x); +#endif + register struct binding_level *b = current_binding_level; + +#if 0 + static int nglobals; int len; + + len = list_length (global_binding_level->names); + if (len < nglobals) + my_friendly_abort (8); + else if (len > nglobals) + nglobals = len; +#endif + + if (x != current_function_decl + /* Don't change DECL_CONTEXT of virtual methods. */ + && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) + && ! DECL_CONTEXT (x)) + DECL_CONTEXT (x) = current_function_decl; + /* A local declaration for a function doesn't constitute nesting. */ + if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) + DECL_CONTEXT (x) = 0; + +#if 0 /* not yet, should get fixed properly later */ + /* For functions and class static data, we currently look up the encoded + form of the name. For types, we want the real name. The former will + probably be changed soon, according to MDT. */ + if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) + name = DECL_ASSEMBLER_NAME (x); + else + name = DECL_NAME (x); +#else + /* Type are looked up using the DECL_NAME, as that is what the rest of the + compiler wants to use. */ + if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL + || TREE_CODE (x) == NAMESPACE_DECL) + name = DECL_NAME (x); +#endif + + if (name) + { + char *file; + int line; + + t = lookup_name_current_level (name); + if (t == error_mark_node) + { + /* error_mark_node is 0 for a while during initialization! */ + t = NULL_TREE; + cp_error_at ("`%#D' used prior to declaration", x); + } + + else if (t != NULL_TREE) + { + file = DECL_SOURCE_FILE (t); + line = DECL_SOURCE_LINE (t); + if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x)) + ; /* This is OK. */ + else if (TREE_CODE (t) == PARM_DECL) + { + if (DECL_CONTEXT (t) == NULL_TREE) + fatal ("parse errors have confused me too much"); + } + else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) + || (TREE_CODE (x) == TEMPLATE_DECL + && ! DECL_TEMPLATE_IS_CLASS (x))) + && is_overloaded_fn (t)) + /* don't do anything just yet */; + else if (t == wchar_decl_node) + { + if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) + cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); + + /* Throw away the redeclaration. */ + return t; + } + else if (TREE_CODE (t) != TREE_CODE (x)) + { + if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)) + || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))) + { + /* We do nothing special here, because C++ does such nasty + things with TYPE_DECLs. Instead, just let the TYPE_DECL + get shadowed, and know that if we need to find a TYPE_DECL + for a given name, we can look in the IDENTIFIER_TYPE_VALUE + slot of the identifier. */ + ; + } + else if (duplicate_decls (x, t)) + return t; + } + else if (duplicate_decls (x, t)) + { +#if 0 + /* This is turned off until I have time to do it right (bpk). */ + + /* Also warn if they did a prototype with `static' on it, but + then later left the `static' off. */ + if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) + { + if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) + return t; + + if (extra_warnings) + { + cp_warning ("`static' missing from declaration of `%D'", + t); + warning_with_file_and_line (file, line, + "previous declaration of `%s'", + decl_as_string (t, 0)); + } + + /* Now fix things so it'll do what they expect. */ + if (current_function_decl) + TREE_PUBLIC (current_function_decl) = 0; + } + /* Due to interference in memory reclamation (X may be + obstack-deallocated at this point), we must guard against + one really special case. [jason: This should be handled + by start_function] */ + if (current_function_decl == x) + current_function_decl = t; +#endif + if (TREE_CODE (t) == TYPE_DECL) + SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); + else if (TREE_CODE (t) == FUNCTION_DECL) + check_default_args (t); + + return t; + } + } + + if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) + { + t = push_overloaded_decl (x, 1); + if (t != x || DECL_LANGUAGE (x) == lang_c) + return t; + } + else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x)) + return push_overloaded_decl (x, 0); + + /* If declaring a type as a typedef, and the type has no known + typedef name, install this TYPE_DECL as its typedef name. */ + if (TREE_CODE (x) == TYPE_DECL) + { + tree type = TREE_TYPE (x); + tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; + + if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) + { + /* If these are different names, and we're at the global + binding level, make two equivalent definitions. */ + name = x; + if (global_bindings_p ()) + TYPE_NAME (type) = x; + } + else + { + tree tname = DECL_NAME (name); + + /* This is a disgusting kludge for dealing with UPTs. */ + if (global_bindings_p () && ANON_AGGRNAME_P (tname)) + { + /* do gratuitous C++ typedefing, and make sure that + we access this type either through TREE_TYPE field + or via the tags list. */ + TYPE_NAME (TREE_TYPE (x)) = x; + pushtag (tname, TREE_TYPE (x), 0); + } + } + my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); + + /* Don't set nested_typename on template type parms, for instance. + Any artificial decls that need DECL_NESTED_TYPENAME will have it + set in pushtag. */ + if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) + set_nested_typename (x, current_class_name, DECL_NAME (x), type); + + if (type != error_mark_node + && TYPE_NAME (type) + && TYPE_IDENTIFIER (type)) + set_identifier_type_value_with_scope (DECL_NAME (x), type, b); + } + + /* Multiple external decls of the same identifier ought to match. + + We get warnings about inline functions where they are defined. + We get warnings about other functions from push_overloaded_decl. + + Avoid duplicate warnings where they are used. */ + if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) + { + tree decl; + + if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE + && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) + || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) + decl = IDENTIFIER_GLOBAL_VALUE (name); + else + decl = NULL_TREE; + + if (decl + /* If different sort of thing, we already gave an error. */ + && TREE_CODE (decl) == TREE_CODE (x) + && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)) + { + cp_pedwarn ("type mismatch with previous external decl", x); + cp_pedwarn_at ("previous external decl of `%#D'", decl); + } + } + + /* In PCC-compatibility mode, extern decls of vars with no current decl + take effect at top level no matter where they are. */ + if (flag_traditional && DECL_EXTERNAL (x) + && lookup_name (name, 0) == NULL_TREE) + b = global_binding_level; + + /* This name is new in its binding level. + Install the new declaration and return it. */ + if (b == global_binding_level) + { + /* Install a global value. */ + + /* If the first global decl has external linkage, + warn if we later see static one. */ + if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x)) + TREE_PUBLIC (name) = 1; + + /* Don't install an artificial TYPE_DECL if we already have + another _DECL with that name. */ + if (TREE_CODE (x) != TYPE_DECL + || t == NULL_TREE + || ! DECL_ARTIFICIAL (x)) + IDENTIFIER_GLOBAL_VALUE (name) = x; + + /* Don't forget if the function was used via an implicit decl. */ + if (IDENTIFIER_IMPLICIT_DECL (name) + && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) + TREE_USED (x) = 1; + + /* Don't forget if its address was taken in that way. */ + if (IDENTIFIER_IMPLICIT_DECL (name) + && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) + TREE_ADDRESSABLE (x) = 1; + + /* Warn about mismatches against previous implicit decl. */ + if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE + /* If this real decl matches the implicit, don't complain. */ + && ! (TREE_CODE (x) == FUNCTION_DECL + && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) + cp_warning + ("`%D' was previously implicitly declared to return `int'", x); + + /* If new decl is `static' and an `extern' was seen previously, + warn about it. */ + if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) + warn_extern_redeclared_static (x, t); + } + else + { + /* Here to install a non-global value. */ + tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); + tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); + + /* Don't install an artificial TYPE_DECL if we already have + another _DECL with that name. */ + if (TREE_CODE (x) != TYPE_DECL + || t == NULL_TREE + || ! DECL_ARTIFICIAL (x)) + { + b->shadowed = tree_cons (name, oldlocal, b->shadowed); + IDENTIFIER_LOCAL_VALUE (name) = x; + } + + /* If this is a TYPE_DECL, push it into the type value slot. */ + if (TREE_CODE (x) == TYPE_DECL) + set_identifier_type_value_with_scope (name, TREE_TYPE (x), b); + + /* Clear out any TYPE_DECL shadowed by a namespace so that + we won't think this is a type. The C struct hack doesn't + go through namespaces. */ + if (TREE_CODE (x) == NAMESPACE_DECL) + set_identifier_type_value_with_scope (name, NULL_TREE, b); + + /* If this is an extern function declaration, see if we + have a global definition or declaration for the function. */ + if (oldlocal == NULL_TREE + && DECL_EXTERNAL (x) + && oldglobal != NULL_TREE + && TREE_CODE (x) == FUNCTION_DECL + && TREE_CODE (oldglobal) == FUNCTION_DECL) + { + /* We have one. Their types must agree. */ + if (decls_match (x, oldglobal)) + /* OK */; + else + { + cp_warning ("extern declaration of `%#D' doesn't match", x); + cp_warning_at ("global declaration `%#D'", oldglobal); + } + } + /* If we have a local external declaration, + and no file-scope declaration has yet been seen, + then if we later have a file-scope decl it must not be static. */ + if (oldlocal == NULL_TREE + && oldglobal == NULL_TREE + && DECL_EXTERNAL (x) + && TREE_PUBLIC (x)) + { + TREE_PUBLIC (name) = 1; + } + + if (DECL_FROM_INLINE (x)) + /* Inline decls shadow nothing. */; + + /* Warn if shadowing an argument at the top level of the body. */ + else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) + && TREE_CODE (oldlocal) == PARM_DECL + && TREE_CODE (x) != PARM_DECL) + { + /* Go to where the parms should be and see if we + find them there. */ + struct binding_level *b = current_binding_level->level_chain; + + if (cleanup_label) + b = b->level_chain; + + /* ARM $8.3 */ + if (b->parm_flag == 1) + cp_error ("declaration of `%#D' shadows a parameter", name); + } + else if (oldlocal != NULL_TREE && b->is_for_scope + && !DECL_DEAD_FOR_LOCAL (oldlocal)) + { + warning ("variable `%s' shadows local", + IDENTIFIER_POINTER (name)); + cp_warning_at (" this is the shadowed declaration", oldlocal); + } + /* Maybe warn if shadowing something else. */ + else if (warn_shadow && !DECL_EXTERNAL (x) + /* No shadow warnings for internally generated vars. */ + && ! DECL_ARTIFICIAL (x) + /* No shadow warnings for vars made for inlining. */ + && ! DECL_FROM_INLINE (x)) + { + char *warnstring = NULL; + + if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) + warnstring = "declaration of `%s' shadows a parameter"; + else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE + && current_class_decl + && !TREE_STATIC (name)) + warnstring = "declaration of `%s' shadows a member of `this'"; + else if (oldlocal != NULL_TREE) + warnstring = "declaration of `%s' shadows previous local"; + else if (oldglobal != NULL_TREE) + warnstring = "declaration of `%s' shadows global declaration"; + + if (warnstring) + warning (warnstring, IDENTIFIER_POINTER (name)); + } + } + + if (TREE_CODE (x) == FUNCTION_DECL) + check_default_args (x); + + /* Keep count of variables in this level with incomplete type. */ + if (TREE_CODE (x) == VAR_DECL + && TREE_TYPE (x) != error_mark_node + && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) + /* RTTI TD entries are created while defining the type_info. */ + || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) + && TYPE_BEING_DEFINED (TREE_TYPE (x))))) + b->incomplete = tree_cons (NULL_TREE, x, b->incomplete); + } + + /* Put decls on list in reverse order. + We will reverse them later if necessary. */ + TREE_CHAIN (x) = b->names; + b->names = x; + if (! (b != global_binding_level || TREE_PERMANENT (x))) + my_friendly_abort (124); + + return x; +} + +/* Same as pushdecl, but define X in binding-level LEVEL. */ + +static tree +pushdecl_with_scope (x, level) + tree x; + struct binding_level *level; +{ + register struct binding_level *b = current_binding_level; + + current_binding_level = level; + x = pushdecl (x); + current_binding_level = b; + return x; +} + +/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, + if appropriate. */ +tree +pushdecl_top_level (x) + tree x; +{ + register struct binding_level *b = inner_binding_level; + register tree t = pushdecl_with_scope (x, global_binding_level); + + /* Now, the type_shadowed stack may screw us. Munge it so it does + what we want. */ + if (TREE_CODE (x) == TYPE_DECL) + { + tree name = DECL_NAME (x); + tree newval; + tree *ptr = (tree *)0; + for (; b != global_binding_level; b = b->level_chain) + { + tree shadowed = b->type_shadowed; + for (; shadowed; shadowed = TREE_CHAIN (shadowed)) + if (TREE_PURPOSE (shadowed) == name) + { + ptr = &TREE_VALUE (shadowed); + /* Can't break out of the loop here because sometimes + a binding level will have duplicate bindings for + PT names. It's gross, but I haven't time to fix it. */ + } + } + newval = TREE_TYPE (x); + if (ptr == (tree *)0) + { + /* @@ This shouldn't be needed. My test case "zstring.cc" trips + up here if this is changed to an assertion. --KR */ + SET_IDENTIFIER_TYPE_VALUE (name, newval); + } + else + { +#if 0 + /* Disabled this 11/10/92, since there are many cases which + behave just fine when *ptr doesn't satisfy either of these. + For example, nested classes declared as friends of their enclosing + class will not meet this criteria. (bpk) */ + my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141); +#endif + *ptr = newval; + } + } + return t; +} + +/* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, + if appropriate. */ +void +push_overloaded_decl_top_level (x, forget) + tree x; + int forget; +{ + struct binding_level *b = current_binding_level; + + current_binding_level = global_binding_level; + push_overloaded_decl (x, forget); + current_binding_level = b; +} + +/* Make the declaration of X appear in CLASS scope. */ +tree +pushdecl_class_level (x) + tree x; +{ + /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class + scope looks for the pre-mangled name. */ + register tree name = DECL_NAME (x); + + if (name) + { + if (TYPE_BEING_DEFINED (current_class_type)) + { + /* Check for inconsistent use of this name in the class body. + Types, enums, and static vars are checked here; other + members are checked in finish_struct. */ + tree icv = IDENTIFIER_CLASS_VALUE (name); + + if (icv + /* Don't complain about inherited names. */ + && id_in_current_class (name) + /* Or shadowed tags. */ + && !(TREE_CODE (icv) == TYPE_DECL + && DECL_CONTEXT (icv) == current_class_type)) + { + cp_error ("declaration of identifier `%D' as `%#D'", name, x); + cp_error_at ("conflicts with previous use in class as `%#D'", + icv); + } + } + + push_class_level_binding (name, x); + if (TREE_CODE (x) == TYPE_DECL) + { + set_identifier_type_value (name, TREE_TYPE (x)); + + /* Don't set nested_typename on template type parms, for instance. + Any artificial decls that need DECL_NESTED_TYPENAME will have it + set in pushtag. */ + if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) + set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); + } + } + return x; +} + +/* This function is used to push the mangled decls for nested types into + the appropriate scope. Previously pushdecl_top_level was used, but that + is incorrect for members of local classes. */ +tree +pushdecl_nonclass_level (x) + tree x; +{ + struct binding_level *b = current_binding_level; + +#if 0 + /* Get out of class scope -- this isn't necessary, because class scope + doesn't make it into current_binding_level. */ + while (b->parm_flag == 2) + b = b->level_chain; +#else + my_friendly_assert (b->parm_flag != 2, 180); +#endif + + /* Get out of template binding levels */ + while (b->pseudo_global) + b = b->level_chain; + + pushdecl_with_scope (x, b); +} + +/* Make the declaration(s) of X appear in CLASS scope + under the name NAME. */ +void +push_class_level_binding (name, x) + tree name; + tree x; +{ + if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) + && purpose_member (name, class_binding_level->class_shadowed)) + return; + + maybe_push_cache_obstack (); + class_binding_level->class_shadowed + = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), + class_binding_level->class_shadowed); + pop_obstacks (); + IDENTIFIER_CLASS_VALUE (name) = x; + obstack_ptr_grow (&decl_obstack, x); +} + +/* Tell caller how to interpret a TREE_LIST which contains + chains of FUNCTION_DECLS. */ +int +overloaded_globals_p (list) + tree list; +{ + my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); + + /* Don't commit caller to seeing them as globals. */ + if (TREE_NONLOCAL_FLAG (list)) + return -1; + /* Do commit caller to seeing them as globals. */ + if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE) + return 1; + /* Do commit caller to not seeing them as globals. */ + return 0; +} + +/* DECL is a FUNCTION_DECL which may have other definitions already in + place. We get around this by making the value of the identifier point + to a list of all the things that want to be referenced by that name. It + is then up to the users of that name to decide what to do with that + list. + + DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT + slot. It is dealt with the same way. + + The value returned may be a previous declaration if we guessed wrong + about what language DECL should belong to (C or C++). Otherwise, + it's always DECL (and never something that's not a _DECL). */ +tree +push_overloaded_decl (decl, forgettable) + tree decl; + int forgettable; +{ + tree orig_name = DECL_NAME (decl); + tree old; + int doing_global = (global_bindings_p () || ! forgettable + || flag_traditional || pseudo_global_level_p ()); + + if (doing_global) + { + old = IDENTIFIER_GLOBAL_VALUE (orig_name); + if (old && TREE_CODE (old) == FUNCTION_DECL + && DECL_ARTIFICIAL (old) + && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) + { + if (duplicate_decls (decl, old)) + return old; + old = NULL_TREE; + } + } + else + { + old = IDENTIFIER_LOCAL_VALUE (orig_name); + + if (! purpose_member (orig_name, current_binding_level->shadowed)) + { + current_binding_level->shadowed + = tree_cons (orig_name, old, current_binding_level->shadowed); + old = NULL_TREE; + } + } + + if (old) + { +#if 0 + /* We cache the value of builtin functions as ADDR_EXPRs + in the name space. Convert it to some kind of _DECL after + remembering what to forget. */ + if (TREE_CODE (old) == ADDR_EXPR) + old = TREE_OPERAND (old, 0); + else +#endif + if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) + { + tree t = TREE_TYPE (old); + if (IS_AGGR_TYPE (t) && warn_shadow) + cp_warning ("`%#D' hides constructor for `%#T'", decl, t); + old = NULL_TREE; + } + else if (is_overloaded_fn (old)) + { + tree tmp; + + for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) + if (decl == tmp || duplicate_decls (decl, tmp)) + return tmp; + } + else + { + cp_error_at ("previous non-function declaration `%#D'", old); + cp_error ("conflicts with function declaration `%#D'", decl); + return decl; + } + } + + if (old || TREE_CODE (decl) == TEMPLATE_DECL) + { + if (old && is_overloaded_fn (old)) + DECL_CHAIN (decl) = get_first_fn (old); + else + DECL_CHAIN (decl) = NULL_TREE; + old = tree_cons (orig_name, decl, NULL_TREE); + TREE_TYPE (old) = unknown_type_node; + } + else + /* orig_name is not ambiguous. */ + old = decl; + + if (doing_global) + IDENTIFIER_GLOBAL_VALUE (orig_name) = old; + else + IDENTIFIER_LOCAL_VALUE (orig_name) = old; + + return decl; +} + +/* Generate an implicit declaration for identifier FUNCTIONID + as a function of type int (). Print a warning if appropriate. */ + +tree +implicitly_declare (functionid) + tree functionid; +{ + register tree decl; + int temp = allocation_temporary_p (); + + push_obstacks_nochange (); + + /* Save the decl permanently so we can warn if definition follows. + In ANSI C, warn_implicit is usually false, so the saves little space. + But in C++, it's usually true, hence the extra code. */ + if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ())) + end_temporary_allocation (); + + /* We used to reuse an old implicit decl here, + but this loses with inline functions because it can clobber + the saved decl chains. */ + decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); + + DECL_EXTERNAL (decl) = 1; + TREE_PUBLIC (decl) = 1; + + /* ANSI standard says implicit declarations are in the innermost block. + So we record the decl in the standard fashion. + If flag_traditional is set, pushdecl does it top-level. */ + pushdecl (decl); + rest_of_decl_compilation (decl, NULL_PTR, 0, 0); + + if (warn_implicit + /* Only one warning per identifier. */ + && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) + { + cp_pedwarn ("implicit declaration of function `%#D'", decl); + } + + SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); + + pop_obstacks (); + + return decl; +} + +/* Return zero if the declaration NEWDECL is valid + when the declaration OLDDECL (assumed to be for the same name) + has already been seen. + Otherwise return an error message format string with a %s + where the identifier should go. */ + +static char * +redeclaration_error_message (newdecl, olddecl) + tree newdecl, olddecl; +{ + if (TREE_CODE (newdecl) == TYPE_DECL) + { + /* Because C++ can put things into name space for free, + constructs like "typedef struct foo { ... } foo" + would look like an erroneous redeclaration. */ + if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) + return 0; + else + return "redefinition of `%#D'"; + } + else if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + /* If this is a pure function, its olddecl will actually be + the original initialization to `0' (which we force to call + abort()). Don't complain about redefinition in this case. */ + if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) + return 0; + + /* We'll complain about linkage mismatches in + warn_extern_redeclared_static. */ + + /* defining the same name twice is no good. */ + if (DECL_INITIAL (olddecl) != NULL_TREE + && DECL_INITIAL (newdecl) != NULL_TREE) + { + if (DECL_NAME (olddecl) == NULL_TREE) + return "`%#D' not declared in class"; + else + return "redefinition of `%#D'"; + } + return 0; + } + else if (TREE_CODE (newdecl) == TEMPLATE_DECL) + { + if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl)) + return "redefinition of `%#D'"; + return 0; + } + else if (current_binding_level == global_binding_level) + { + /* Objects declared at top level: */ + /* If at least one is a reference, it's ok. */ + if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) + return 0; + /* Reject two definitions. */ + return "redefinition of `%#D'"; + } + else + { + /* Objects declared with block scope: */ + /* Reject two definitions, and reject a definition + together with an external reference. */ + if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) + return "redeclaration of `%#D'"; + return 0; + } +} + +/* Get the LABEL_DECL corresponding to identifier ID as a label. + Create one if none exists so far for the current function. + This function is called for both label definitions and label references. */ + +tree +lookup_label (id) + tree id; +{ + register tree decl = IDENTIFIER_LABEL_VALUE (id); + + if (current_function_decl == NULL_TREE) + { + error ("label `%s' referenced outside of any function", + IDENTIFIER_POINTER (id)); + return NULL_TREE; + } + + if ((decl == NULL_TREE + || DECL_SOURCE_LINE (decl) == 0) + && (named_label_uses == NULL_TREE + || TREE_PURPOSE (named_label_uses) != current_binding_level->names + || TREE_VALUE (named_label_uses) != decl)) + { + named_label_uses + = tree_cons (current_binding_level->names, decl, named_label_uses); + TREE_TYPE (named_label_uses) = (tree)current_binding_level; + } + + /* Use a label already defined or ref'd with this name. */ + if (decl != NULL_TREE) + { + /* But not if it is inherited and wasn't declared to be inheritable. */ + if (DECL_CONTEXT (decl) != current_function_decl + && ! C_DECLARED_LABEL_FLAG (decl)) + return shadow_label (id); + return decl; + } + + decl = build_decl (LABEL_DECL, id, void_type_node); + + /* A label not explicitly declared must be local to where it's ref'd. */ + DECL_CONTEXT (decl) = current_function_decl; + + DECL_MODE (decl) = VOIDmode; + + /* Say where one reference is to the label, + for the sake of the error if it is not defined. */ + DECL_SOURCE_LINE (decl) = lineno; + DECL_SOURCE_FILE (decl) = input_filename; + + SET_IDENTIFIER_LABEL_VALUE (id, decl); + + named_labels = tree_cons (NULL_TREE, decl, named_labels); + TREE_VALUE (named_label_uses) = decl; + + return decl; +} + +/* Make a label named NAME in the current function, + shadowing silently any that may be inherited from containing functions + or containing scopes. + + Note that valid use, if the label being shadowed + comes from another scope in the same function, + requires calling declare_nonlocal_label right away. */ + +tree +shadow_label (name) + tree name; +{ + register tree decl = IDENTIFIER_LABEL_VALUE (name); + + if (decl != NULL_TREE) + { + shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); + SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); + SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); + } + + return lookup_label (name); +} + +/* Define a label, specifying the location in the source file. + Return the LABEL_DECL node for the label, if the definition is valid. + Otherwise return 0. */ + +tree +define_label (filename, line, name) + char *filename; + int line; + tree name; +{ + tree decl = lookup_label (name); + + /* After labels, make any new cleanups go into their + own new (temporary) binding contour. */ + current_binding_level->more_cleanups_ok = 0; + + /* If label with this name is known from an outer context, shadow it. */ + if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) + { + shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); + SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); + decl = lookup_label (name); + } + + if (name == get_identifier ("wchar_t")) + cp_pedwarn ("label named wchar_t"); + + if (DECL_INITIAL (decl) != NULL_TREE) + { + cp_error ("duplicate label `%D'", decl); + return 0; + } + else + { + tree uses, prev; + int identified = 0; + + /* Mark label as having been defined. */ + DECL_INITIAL (decl) = error_mark_node; + /* Say where in the source. */ + DECL_SOURCE_FILE (decl) = filename; + DECL_SOURCE_LINE (decl) = line; + + for (prev = NULL_TREE, uses = named_label_uses; + uses; + prev = uses, uses = TREE_CHAIN (uses)) + if (TREE_VALUE (uses) == decl) + { + struct binding_level *b = current_binding_level; + while (b) + { + tree new_decls = b->names; + tree old_decls = ((tree)b == TREE_TYPE (uses) + ? TREE_PURPOSE (uses) : NULL_TREE); + while (new_decls != old_decls) + { + if (TREE_CODE (new_decls) == VAR_DECL + /* Don't complain about crossing initialization + of internal entities. They can't be accessed, + and they should be cleaned up + by the time we get to the label. */ + && ! DECL_ARTIFICIAL (new_decls) + && ((DECL_INITIAL (new_decls) != NULL_TREE + && DECL_INITIAL (new_decls) != error_mark_node) + || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) + { + if (! identified) + cp_error ("jump to label `%D'", decl); + identified = 1; + cp_error_at (" crosses initialization of `%#D'", + new_decls); + } + new_decls = TREE_CHAIN (new_decls); + } + if ((tree)b == TREE_TYPE (uses)) + break; + b = b->level_chain; + } + + if (prev) + TREE_CHAIN (prev) = TREE_CHAIN (uses); + else + named_label_uses = TREE_CHAIN (uses); + } + current_function_return_value = NULL_TREE; + return decl; + } +} + +struct cp_switch +{ + struct binding_level *level; + struct cp_switch *next; +}; + +static struct cp_switch *switch_stack; + +void +push_switch () +{ + struct cp_switch *p + = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); + p->level = current_binding_level; + p->next = switch_stack; + switch_stack = p; +} + +void +pop_switch () +{ + switch_stack = switch_stack->next; +} + +/* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ +/* XXX Note decl is never actually used. (bpk) */ +void +define_case_label (decl) + tree decl; +{ + tree cleanup = last_cleanup_this_contour (); + struct binding_level *b = current_binding_level; + int identified = 0; + + if (cleanup) + { + static int explained = 0; + cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); + warning ("where case label appears here"); + if (!explained) + { + warning ("(enclose actions of previous case statements requiring"); + warning ("destructors in their own binding contours.)"); + explained = 1; + } + } + + for (; b && b != switch_stack->level; b = b->level_chain) + { + tree new_decls = b->names; + for (; new_decls; new_decls = TREE_CHAIN (new_decls)) + { + if (TREE_CODE (new_decls) == VAR_DECL + /* Don't complain about crossing initialization + of internal entities. They can't be accessed, + and they should be cleaned up + by the time we get to the label. */ + && ! DECL_ARTIFICIAL (new_decls) + && ((DECL_INITIAL (new_decls) != NULL_TREE + && DECL_INITIAL (new_decls) != error_mark_node) + || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) + { + if (! identified) + error ("jump to case label"); + identified = 1; + cp_error_at (" crosses initialization of `%#D'", + new_decls); + } + } + } + + /* After labels, make any new cleanups go into their + own new (temporary) binding contour. */ + + current_binding_level->more_cleanups_ok = 0; + current_function_return_value = NULL_TREE; +} + +/* Return the list of declarations of the current level. + Note that this list is in reverse order unless/until + you nreverse it; and when you do nreverse it, you must + store the result back using `storedecls' or you will lose. */ + +tree +getdecls () +{ + return current_binding_level->names; +} + +/* Return the list of type-tags (for structs, etc) of the current level. */ + +tree +gettags () +{ + return current_binding_level->tags; +} + +/* Store the list of declarations of the current level. + This is done for the parameter declarations of a function being defined, + after they are modified in the light of any missing parameters. */ + +static void +storedecls (decls) + tree decls; +{ + current_binding_level->names = decls; +} + +/* Similarly, store the list of tags of the current level. */ + +static void +storetags (tags) + tree tags; +{ + current_binding_level->tags = tags; +} + +/* Given NAME, an IDENTIFIER_NODE, + return the structure (or union or enum) definition for that name. + Searches binding levels from BINDING_LEVEL up to the global level. + If THISLEVEL_ONLY is nonzero, searches only the specified context + (but skips any tag-transparent contexts to find one that is + meaningful for tags). + FORM says which kind of type the caller wants; + it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. + If the wrong kind of type is found, and it's not a template, an error is + reported. */ + +static tree +lookup_tag (form, name, binding_level, thislevel_only) + enum tree_code form; + struct binding_level *binding_level; + tree name; + int thislevel_only; +{ + register struct binding_level *level; + + for (level = binding_level; level; level = level->level_chain) + { + register tree tail; + if (ANON_AGGRNAME_P (name)) + for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) + { + /* There's no need for error checking here, because + anon names are unique throughout the compilation. */ + if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) + return TREE_VALUE (tail); + } + else + for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) + { + if (TREE_PURPOSE (tail) == name) + { + enum tree_code code = TREE_CODE (TREE_VALUE (tail)); + /* Should tighten this up; it'll probably permit + UNION_TYPE and a struct template, for example. */ + if (code != form + && !(form != ENUMERAL_TYPE + && (code == TEMPLATE_DECL + || code == UNINSTANTIATED_P_TYPE))) + + { + /* Definition isn't the kind we were looking for. */ + cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), + form); + } + return TREE_VALUE (tail); + } + } + if (thislevel_only && ! level->tag_transparent) + return NULL_TREE; + if (current_class_type && level->level_chain == global_binding_level) + { + /* Try looking in this class's tags before heading into + global binding level. */ + tree context = current_class_type; + while (context) + { + switch (TREE_CODE_CLASS (TREE_CODE (context))) + { + tree these_tags; + case 't': + these_tags = CLASSTYPE_TAGS (context); + if (ANON_AGGRNAME_P (name)) + while (these_tags) + { + if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) + == name) + return TREE_VALUE (tail); + these_tags = TREE_CHAIN (these_tags); + } + else + while (these_tags) + { + if (TREE_PURPOSE (these_tags) == name) + { + if (TREE_CODE (TREE_VALUE (these_tags)) != form) + { + cp_error ("`%#D' redeclared as %C in class scope", + TREE_VALUE (tail), form); + } + return TREE_VALUE (tail); + } + these_tags = TREE_CHAIN (these_tags); + } + /* If this type is not yet complete, then don't + look at its context. */ + if (TYPE_SIZE (context) == NULL_TREE) + goto no_context; + /* Go to next enclosing type, if any. */ + context = DECL_CONTEXT (TYPE_NAME (context)); + break; + case 'd': + context = DECL_CONTEXT (context); + break; + default: + my_friendly_abort (10); + } + continue; + no_context: + break; + } + } + } + return NULL_TREE; +} + +void +set_current_level_tags_transparency (tags_transparent) + int tags_transparent; +{ + current_binding_level->tag_transparent = tags_transparent; +} + +/* Given a type, find the tag that was defined for it and return the tag name. + Otherwise return 0. However, the value can never be 0 + in the cases in which this is used. + + C++: If NAME is non-zero, this is the new name to install. This is + done when replacing anonymous tags with real tag names. */ + +static tree +lookup_tag_reverse (type, name) + tree type; + tree name; +{ + register struct binding_level *level; + + for (level = current_binding_level; level; level = level->level_chain) + { + register tree tail; + for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) + { + if (TREE_VALUE (tail) == type) + { + if (name) + TREE_PURPOSE (tail) = name; + return TREE_PURPOSE (tail); + } + } + } + return NULL_TREE; +} + +/* Given type TYPE which was not declared in C++ language context, + attempt to find a name by which it is referred. */ +tree +typedecl_for_tag (tag) + tree tag; +{ + struct binding_level *b = current_binding_level; + + if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL) + return TYPE_NAME (tag); + + while (b) + { + tree decls = b->names; + while (decls) + { + if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag) + break; + decls = TREE_CHAIN (decls); + } + if (decls) + return decls; + b = b->level_chain; + } + return NULL_TREE; +} + +/* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). + Return the type value, or NULL_TREE if not found. */ +static tree +lookup_nested_type (type, context) + tree type; + tree context; +{ + if (context == NULL_TREE) + return NULL_TREE; + while (context) + { + switch (TREE_CODE (context)) + { + case TYPE_DECL: + { + tree ctype = TREE_TYPE (context); + tree match = value_member (type, CLASSTYPE_TAGS (ctype)); + if (match) + return TREE_VALUE (match); + context = DECL_CONTEXT (context); + + /* When we have a nested class whose member functions have + local types (e.g., a set of enums), we'll arrive here + with the DECL_CONTEXT as the actual RECORD_TYPE node for + the enclosing class. Instead, we want to make sure we + come back in here with the TYPE_DECL, not the RECORD_TYPE. */ + if (context && TREE_CODE (context) == RECORD_TYPE) + context = TREE_CHAIN (context); + } + break; + case FUNCTION_DECL: + if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) + return lookup_name (TYPE_IDENTIFIER (type), 1); + return NULL_TREE; + default: + my_friendly_abort (12); + } + } + return NULL_TREE; +} + +/* Look up NAME in the NAMESPACE. */ +tree +lookup_namespace_name (namespace, name) + tree namespace, name; +{ + struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); + tree x; + + for (x = NULL_TREE; b && !x; b = b->level_chain) + { + for (x = b->names; x; x = TREE_CHAIN (x)) + if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) + break; + /* Must find directly in the namespace. */ + break; + } + return x; +} + +/* Look up NAME in the current binding level and its superiors in the + namespace of variables, functions and typedefs. Return a ..._DECL + node of some kind representing its definition if there is only one + such declaration, or return a TREE_LIST with all the overloaded + definitions if there are many, or return 0 if it is undefined. + + If PREFER_TYPE is > 0, we prefer TYPE_DECLs. + If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) + Otherwise we prefer non-TYPE_DECLs. */ + +tree +lookup_name_real (name, prefer_type, nonclass) + tree name; + int prefer_type, nonclass; +{ + register tree val; + int yylex = 0; + tree from_obj = NULL_TREE; + + if (prefer_type == -2) + { + extern int looking_for_typename; + tree type; + + yylex = 1; + prefer_type = looking_for_typename; + + if (got_scope) + type = got_scope; + else if (got_object != error_mark_node) + type = got_object; + + if (type) + { + if (type == error_mark_node) + return error_mark_node; + else if (type == void_type_node) + val = IDENTIFIER_GLOBAL_VALUE (name); + else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM + /* TFIXME -- don't do this for UPTs in new model. */ + || TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + { + if (prefer_type > 0) + val = create_nested_upt (type, name); + else + val = NULL_TREE; + } + else if (TREE_CODE (type) == NAMESPACE_DECL) + { + val = lookup_namespace_name (type, name); + } + else if (! IS_AGGR_TYPE (type)) + /* Someone else will give an error about this if needed. */ + val = NULL_TREE; + else if (TYPE_BEING_DEFINED (type)) + { + val = IDENTIFIER_CLASS_VALUE (name); + if (val && DECL_CONTEXT (val) != type) + { + struct binding_level *b = class_binding_level; + for (val = NULL_TREE; b; b = b->level_chain) + { + tree t = purpose_member (name, b->class_shadowed); + if (t && TREE_VALUE (t) + && DECL_CONTEXT (TREE_VALUE (t)) == type) + { + val = TREE_VALUE (t); + break; + } + } + } + if (val == NULL_TREE + && CLASSTYPE_LOCAL_TYPEDECLS (type)) + val = lookup_field (type, name, 0, 1); + } + else if (type == current_class_type) + val = IDENTIFIER_CLASS_VALUE (name); + else + val = lookup_field (type, name, 0, prefer_type); + } + else + val = NULL_TREE; + + if (got_scope) + goto done; + + /* This special lookup only applies to types. */ + else if (got_object && val && TREE_CODE (val) == TYPE_DECL) + from_obj = val; + } + + if (current_binding_level != global_binding_level + && IDENTIFIER_LOCAL_VALUE (name)) + val = IDENTIFIER_LOCAL_VALUE (name); + /* In C++ class fields are between local and global scope, + just before the global scope. */ + else if (current_class_type && ! nonclass) + { + val = IDENTIFIER_CLASS_VALUE (name); + if (val == NULL_TREE + && TYPE_BEING_DEFINED (current_class_type) + && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type)) + /* Try to find values from base classes if we are presently + defining a type. We are presently only interested in + TYPE_DECLs. */ + val = lookup_field (current_class_type, name, 0, 1); + + /* yylex() calls this with -2, since we should never start digging for + the nested name at the point where we haven't even, for example, + created the COMPONENT_REF or anything like that. */ + if (val == NULL_TREE) + val = lookup_nested_field (name, ! yylex); + + if (val == NULL_TREE) + val = IDENTIFIER_GLOBAL_VALUE (name); + } + else + val = IDENTIFIER_GLOBAL_VALUE (name); + + done: + if (val) + { + if (from_obj && from_obj != val) + cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope", + got_object); + + if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) + || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) + ; + else if (IDENTIFIER_HAS_TYPE_VALUE (name)) + val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); + else if (TREE_TYPE (val) == error_mark_node) + val = error_mark_node; + } + else if (from_obj) + val = from_obj; + + return val; +} + +tree +lookup_name_nonclass (name) + tree name; +{ + return lookup_name_real (name, 0, 1); +} + +tree +lookup_name (name, prefer_type) + tree name; + int prefer_type; +{ + return lookup_name_real (name, prefer_type, 0); +} + +/* Similar to `lookup_name' but look only at current binding level. */ + +tree +lookup_name_current_level (name) + tree name; +{ + register tree t = NULL_TREE; + + if (current_binding_level == global_binding_level) + { + t = IDENTIFIER_GLOBAL_VALUE (name); + + /* extern "C" function() */ + if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) + t = TREE_VALUE (t); + } + else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE) + { + struct binding_level *b = current_binding_level; + while (1) + { + for (t = b->names; t; t = TREE_CHAIN (t)) + if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) + goto out; + if (b->keep == 2) + b = b->level_chain; + else + break; + } + out: + ; + } + + return t; +} + +/* Arrange for the user to get a source line number, even when the + compiler is going down in flames, so that she at least has a + chance of working around problems in the compiler. We used to + call error(), but that let the segmentation fault continue + through; now, it's much more passive by asking them to send the + maintainers mail about the problem. */ + +static void +signal_catch (sig) + int sig; +{ + signal (SIGSEGV, SIG_DFL); +#ifdef SIGIOT + signal (SIGIOT, SIG_DFL); +#endif +#ifdef SIGILL + signal (SIGILL, SIG_DFL); +#endif +#ifdef SIGABRT + signal (SIGABRT, SIG_DFL); +#endif +#ifdef SIGBUS + signal (SIGBUS, SIG_DFL); +#endif + my_friendly_abort (0); +} + +/* Array for holding types considered "built-in". These types + are output in the module in which `main' is defined. */ +static tree *builtin_type_tdescs_arr; +static int builtin_type_tdescs_len, builtin_type_tdescs_max; + +/* Push the declarations of builtin types into the namespace. + RID_INDEX, if < RID_MAX is the index of the builtin type + in the array RID_POINTERS. NAME is the name used when looking + up the builtin type. TYPE is the _TYPE node for the builtin type. */ + +static void +record_builtin_type (rid_index, name, type) + enum rid rid_index; + char *name; + tree type; +{ + tree rname = NULL_TREE, tname = NULL_TREE; + tree tdecl; + + if ((int) rid_index < (int) RID_MAX) + rname = ridpointers[(int) rid_index]; + if (name) + tname = get_identifier (name); + + TYPE_BUILT_IN (type) = 1; + + if (tname) + { +#if 0 /* not yet, should get fixed properly later */ + tdecl = pushdecl (make_type_decl (tname, type)); +#else + tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); +#endif + set_identifier_type_value (tname, NULL_TREE); + if ((int) rid_index < (int) RID_MAX) + IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; + } + if (rname != NULL_TREE) + { + if (tname != NULL_TREE) + { + set_identifier_type_value (rname, NULL_TREE); + IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; + } + else + { +#if 0 /* not yet, should get fixed properly later */ + tdecl = pushdecl (make_type_decl (rname, type)); +#else + tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); +#endif + set_identifier_type_value (rname, NULL_TREE); + } + } + + if (flag_rtti) + { + if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max) + { + builtin_type_tdescs_max *= 2; + builtin_type_tdescs_arr + = (tree *)xrealloc (builtin_type_tdescs_arr, + builtin_type_tdescs_max * sizeof (tree)); + } + builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type; + if (TREE_CODE (type) != POINTER_TYPE) + { + builtin_type_tdescs_arr[builtin_type_tdescs_len++] + = build_pointer_type (type); + builtin_type_tdescs_arr[builtin_type_tdescs_len++] + = build_pointer_type (build_type_variant (type, 1, 0)); + } + if (TREE_CODE (type) != VOID_TYPE) + { + builtin_type_tdescs_arr[builtin_type_tdescs_len++] + = build_reference_type (type); + builtin_type_tdescs_arr[builtin_type_tdescs_len++] + = build_reference_type (build_type_variant (type, 1, 0)); + } + } +} + +static void +output_builtin_tdesc_entries () +{ + extern struct obstack permanent_obstack; + + /* If there's more than one main in this file, don't crash. */ + if (builtin_type_tdescs_arr == 0) + return; + + push_obstacks (&permanent_obstack, &permanent_obstack); + while (builtin_type_tdescs_len > 0) + { + tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len]; + tree tdesc = build_t_desc (type, 0); + TREE_ASM_WRITTEN (tdesc) = 0; + build_t_desc (type, 2); + } + free (builtin_type_tdescs_arr); + builtin_type_tdescs_arr = 0; + pop_obstacks (); +} + +/* Push overloaded decl, in global scope, with one argument so it + can be used as a callback from define_function. */ +static void +push_overloaded_decl_1 (x) + tree x; +{ + push_overloaded_decl (x, 0); +} + +#define builtin_function(NAME, TYPE, CODE, LIBNAME) \ + define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) + +#ifdef __GNUC__ +__inline +#endif +tree auto_function (name, type, code) + tree name, type; + enum built_in_function code; +{ + return define_function + (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1, + IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), + 0))); +} + +/* Create the predefined scalar types of C, + and some nodes representing standard constants (0, 1, (void *)0). + Initialize the global binding level. + Make definitions for built-in primitive functions. */ + +void +init_decl_processing () +{ + tree decl; + register tree endlink, int_endlink, double_endlink, ptr_endlink; + tree fields[20]; + /* Either char* or void*. */ + tree traditional_ptr_type_node; + /* Data type of memcpy. */ + tree memcpy_ftype; +#if 0 /* Not yet. */ + /* Data type of strncpy. */ + tree strncpy_ftype; +#endif + int wchar_type_size; + tree temp; + tree array_domain_type; + extern int flag_strict_prototype; + + /* Have to make these distinct before we try using them. */ + lang_name_cplusplus = get_identifier ("C++"); + lang_name_c = get_identifier ("C"); + + if (flag_strict_prototype == 2) + { + if (pedantic) + strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; + } + else + strict_prototypes_lang_c = flag_strict_prototype; + + /* Initially, C. */ + current_lang_name = lang_name_c; + + current_function_decl = NULL_TREE; + named_labels = NULL_TREE; + named_label_uses = NULL_TREE; + current_binding_level = NULL_BINDING_LEVEL; + free_binding_level = NULL_BINDING_LEVEL; + + /* Because most segmentation signals can be traced back into user + code, catch them and at least give the user a chance of working + around compiler bugs. */ + signal (SIGSEGV, signal_catch); + + /* We will also catch aborts in the back-end through signal_catch and + give the user a chance to see where the error might be, and to defeat + aborts in the back-end when there have been errors previously in their + code. */ +#ifdef SIGIOT + signal (SIGIOT, signal_catch); +#endif +#ifdef SIGILL + signal (SIGILL, signal_catch); +#endif +#ifdef SIGABRT + signal (SIGABRT, signal_catch); +#endif +#ifdef SIGBUS + signal (SIGBUS, signal_catch); +#endif + + gcc_obstack_init (&decl_obstack); + if (flag_rtti) + { + builtin_type_tdescs_max = 100; + builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree)); + } + + /* Must lay these out before anything else gets laid out. */ + error_mark_node = make_node (ERROR_MARK); + TREE_PERMANENT (error_mark_node) = 1; + TREE_TYPE (error_mark_node) = error_mark_node; + error_mark_list = build_tree_list (error_mark_node, error_mark_node); + TREE_TYPE (error_mark_list) = error_mark_node; + + /* Make the binding_level structure for global names. */ + pushlevel (0); + global_binding_level = current_binding_level; + + this_identifier = get_identifier (THIS_NAME); + in_charge_identifier = get_identifier (IN_CHARGE_NAME); + pfn_identifier = get_identifier (VTABLE_PFN_NAME); + index_identifier = get_identifier (VTABLE_INDEX_NAME); + delta_identifier = get_identifier (VTABLE_DELTA_NAME); + delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); + pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); + if (flag_handle_signatures) + { + tag_identifier = get_identifier (SIGTABLE_TAG_NAME); + vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); + vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); + } + + /* Define `int' and `char' first so that dbx will output them first. */ + + integer_type_node = make_signed_type (INT_TYPE_SIZE); + record_builtin_type (RID_INT, NULL_PTR, integer_type_node); + + /* Define `char', which is like either `signed char' or `unsigned char' + but not the same as either. */ + + char_type_node = + (flag_signed_char + ? make_signed_type (CHAR_TYPE_SIZE) + : make_unsigned_type (CHAR_TYPE_SIZE)); + record_builtin_type (RID_CHAR, "char", char_type_node); + + long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); + record_builtin_type (RID_LONG, "long int", long_integer_type_node); + + unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); + record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); + + long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); + record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); + record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); + + long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); + record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); + + long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); + record_builtin_type (RID_MAX, "long long unsigned int", + long_long_unsigned_type_node); + record_builtin_type (RID_MAX, "long long unsigned", + long_long_unsigned_type_node); + + /* `unsigned long' is the standard type for sizeof. + Traditionally, use a signed type. + Note that stddef.h uses `unsigned long', + and this must agree, even of long and int are the same size. */ + sizetype + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); + if (flag_traditional && TREE_UNSIGNED (sizetype)) + sizetype = signed_type (sizetype); + + ptrdiff_type_node + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); + + TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; + TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; + + short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); + record_builtin_type (RID_SHORT, "short int", short_integer_type_node); + short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); + record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); + record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); + + /* Define both `signed char' and `unsigned char'. */ + signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); + record_builtin_type (RID_MAX, "signed char", signed_char_type_node); + unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); + record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); + + /* These are types that type_for_size and type_for_mode use. */ + intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); + intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); + intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); + intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); + unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); + unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); + unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); + unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); + + float_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; + record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); + layout_type (float_type_node); + + double_type_node = make_node (REAL_TYPE); + if (flag_short_double) + TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; + else + TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; + record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); + layout_type (double_type_node); + + long_double_type_node = make_node (REAL_TYPE); + TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; + record_builtin_type (RID_MAX, "long double", long_double_type_node); + layout_type (long_double_type_node); + + integer_zero_node = build_int_2 (0, 0); + TREE_TYPE (integer_zero_node) = integer_type_node; + integer_one_node = build_int_2 (1, 0); + TREE_TYPE (integer_one_node) = integer_type_node; + integer_two_node = build_int_2 (2, 0); + TREE_TYPE (integer_two_node) = integer_type_node; + integer_three_node = build_int_2 (3, 0); + TREE_TYPE (integer_three_node) = integer_type_node; + + boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); + TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); + record_builtin_type (RID_BOOL, "bool", boolean_type_node); + boolean_false_node = build_int_2 (0, 0); + TREE_TYPE (boolean_false_node) = boolean_type_node; + boolean_true_node = build_int_2 (1, 0); + TREE_TYPE (boolean_true_node) = boolean_type_node; + + /* These are needed by stor-layout.c. */ + size_zero_node = size_int (0); + size_one_node = size_int (1); + + void_type_node = make_node (VOID_TYPE); + record_builtin_type (RID_VOID, NULL_PTR, void_type_node); + layout_type (void_type_node); /* Uses integer_zero_node. */ + void_list_node = build_tree_list (NULL_TREE, void_type_node); + TREE_PARMLIST (void_list_node) = 1; + + null_pointer_node = build_int_2 (0, 0); + TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); + layout_type (TREE_TYPE (null_pointer_node)); + + /* Used for expressions that do nothing, but are not errors. */ + void_zero_node = build_int_2 (0, 0); + TREE_TYPE (void_zero_node) = void_type_node; + + string_type_node = build_pointer_type (char_type_node); + const_string_type_node = + build_pointer_type (build_type_variant (char_type_node, 1, 0)); + record_builtin_type (RID_MAX, NULL_PTR, string_type_node); + + /* Make a type to be the domain of a few array types + whose domains don't really matter. + 200 is small enough that it always fits in size_t + and large enough that it can hold most function names for the + initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ + array_domain_type = build_index_type (build_int_2 (200, 0)); + + /* make a type for arrays of characters. + With luck nothing will ever really depend on the length of this + array type. */ + char_array_type_node + = build_array_type (char_type_node, array_domain_type); + /* Likewise for arrays of ints. */ + int_array_type_node + = build_array_type (integer_type_node, array_domain_type); + + /* This is just some anonymous class type. Nobody should ever + need to look inside this envelope. */ + class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); + + default_function_type + = build_function_type (integer_type_node, NULL_TREE); + build_pointer_type (default_function_type); + + ptr_type_node = build_pointer_type (void_type_node); + const_ptr_type_node = + build_pointer_type (build_type_variant (void_type_node, 1, 0)); + record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); + endlink = void_list_node; + int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); + double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); + ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink); + + double_ftype_double + = build_function_type (double_type_node, double_endlink); + + double_ftype_double_double + = build_function_type (double_type_node, + tree_cons (NULL_TREE, double_type_node, + double_endlink)); + + int_ftype_int + = build_function_type (integer_type_node, int_endlink); + + long_ftype_long + = build_function_type (long_integer_type_node, + tree_cons (NULL_TREE, long_integer_type_node, + endlink)); + + void_ftype_ptr_ptr_int + = build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + int_endlink))); + + int_ftype_cptr_cptr_sizet + = build_function_type (integer_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)))); + + void_ftype_ptr_int_int + = build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, integer_type_node, + int_endlink))); + + string_ftype_ptr_ptr /* strcpy prototype */ + = build_function_type (string_type_node, + tree_cons (NULL_TREE, string_type_node, + tree_cons (NULL_TREE, + const_string_type_node, + endlink))); + +#if 0 + /* Not yet. */ + strncpy_ftype /* strncpy prototype */ + = build_function_type (string_type_node, + tree_cons (NULL_TREE, string_type_node, + tree_cons (NULL_TREE, const_string_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)))); +#endif + + int_ftype_string_string /* strcmp prototype */ + = build_function_type (integer_type_node, + tree_cons (NULL_TREE, const_string_type_node, + tree_cons (NULL_TREE, + const_string_type_node, + endlink))); + + sizet_ftype_string /* strlen prototype */ + = build_function_type (sizetype, + tree_cons (NULL_TREE, const_string_type_node, + endlink)); + + traditional_ptr_type_node + = (flag_traditional ? string_type_node : ptr_type_node); + + memcpy_ftype /* memcpy prototype */ + = build_function_type (traditional_ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, const_ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)))); + + if (flag_huge_objects) + delta_type_node = long_integer_type_node; + else + delta_type_node = short_integer_type_node; + + builtin_function ("__builtin_constant_p", int_ftype_int, + BUILT_IN_CONSTANT_P, NULL_PTR); + + builtin_return_address_fndecl = + builtin_function ("__builtin_return_address", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + unsigned_type_node, + endlink)), + BUILT_IN_RETURN_ADDRESS, NULL_PTR); + + builtin_function ("__builtin_frame_address", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + unsigned_type_node, + endlink)), + BUILT_IN_FRAME_ADDRESS, NULL_PTR); + + + builtin_function ("__builtin_alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, "alloca"); + /* Define alloca, ffs as builtins. + Declare _exit just to mark it as volatile. */ + if (! flag_no_builtin && !flag_no_nonansi_builtin) + { + temp = builtin_function ("alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, NULL_PTR); + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + temp = builtin_function ("_exit", build_function_type (void_type_node, + int_endlink), + NOT_BUILT_IN, NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + /* Suppress error if redefined as a non-function. */ + DECL_BUILT_IN_NONANSI (temp) = 1; + } + + builtin_function ("__builtin_abs", int_ftype_int, + BUILT_IN_ABS, NULL_PTR); + builtin_function ("__builtin_fabs", double_ftype_double, + BUILT_IN_FABS, NULL_PTR); + builtin_function ("__builtin_labs", long_ftype_long, + BUILT_IN_LABS, NULL_PTR); + builtin_function ("__builtin_ffs", int_ftype_int, + BUILT_IN_FFS, NULL_PTR); + builtin_function ("__builtin_fsqrt", double_ftype_double, + BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("__builtin_sin", double_ftype_double, + BUILT_IN_SIN, "sin"); + builtin_function ("__builtin_cos", double_ftype_double, + BUILT_IN_COS, "cos"); + builtin_function ("__builtin_saveregs", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_SAVEREGS, NULL_PTR); +/* EXPAND_BUILTIN_VARARGS is obsolete. */ +#if 0 + builtin_function ("__builtin_varargs", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)), + BUILT_IN_VARARGS, NULL_PTR); +#endif + builtin_function ("__builtin_classify_type", default_function_type, + BUILT_IN_CLASSIFY_TYPE, NULL_PTR); + builtin_function ("__builtin_next_arg", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_NEXT_ARG, NULL_PTR); + builtin_function ("__builtin_args_info", + build_function_type (integer_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink)), + BUILT_IN_ARGS_INFO, NULL_PTR); + + /* Untyped call and return. */ + builtin_function ("__builtin_apply_args", + build_function_type (ptr_type_node, NULL_TREE), + BUILT_IN_APPLY_ARGS, NULL_PTR); + + temp = tree_cons (NULL_TREE, + build_pointer_type (build_function_type (void_type_node, + NULL_TREE)), + tree_cons (NULL_TREE, + ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink))); + builtin_function ("__builtin_apply", + build_function_type (ptr_type_node, temp), + BUILT_IN_APPLY, NULL_PTR); + builtin_function ("__builtin_return", + build_function_type (void_type_node, + tree_cons (NULL_TREE, + ptr_type_node, + endlink)), + BUILT_IN_RETURN, NULL_PTR); + + /* Currently under experimentation. */ + builtin_function ("__builtin_memcpy", memcpy_ftype, + BUILT_IN_MEMCPY, "memcpy"); + builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, + BUILT_IN_MEMCMP, "memcmp"); + builtin_function ("__builtin_strcmp", int_ftype_string_string, + BUILT_IN_STRCMP, "strcmp"); + builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, + BUILT_IN_STRCPY, "strcpy"); +#if 0 + /* Not yet. */ + builtin_function ("__builtin_strncpy", strncpy_ftype, + BUILT_IN_STRNCPY, "strncpy"); +#endif + builtin_function ("__builtin_strlen", sizet_ftype_string, + BUILT_IN_STRLEN, "strlen"); + + if (!flag_no_builtin) + { +#if 0 /* These do not work well with libg++. */ + builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); + builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); + builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); +#endif + builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); + builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, + NULL_PTR); + builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); + builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, + NULL_PTR); +#if 0 + /* Not yet. */ + builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR); +#endif + builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR); + builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); + builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); + + /* Declare these functions volatile + to avoid spurious "control drops through" warnings. */ + temp = builtin_function ("abort", + build_function_type (void_type_node, endlink), + NOT_BUILT_IN, NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on + them... */ + DECL_BUILT_IN_NONANSI (temp) = 1; + temp = builtin_function ("exit", build_function_type (void_type_node, + int_endlink), + NOT_BUILT_IN, NULL_PTR); + TREE_THIS_VOLATILE (temp) = 1; + TREE_SIDE_EFFECTS (temp) = 1; + DECL_BUILT_IN_NONANSI (temp) = 1; + } + +#if 0 + /* Support for these has not been written in either expand_builtin + or build_function_call. */ + builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0); + builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0); + builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, + 0); + builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0); + builtin_function ("__builtin_fmod", double_ftype_double_double, + BUILT_IN_FMOD, 0); + builtin_function ("__builtin_frem", double_ftype_double_double, + BUILT_IN_FREM, 0); + builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, + 0); + builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, + 0); + builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, + 0); +#endif + + /* C++ extensions */ + + unknown_type_node = make_node (UNKNOWN_TYPE); +#if 0 /* not yet, should get fixed properly later */ + pushdecl (make_type_decl (get_identifier ("unknown type"), + unknown_type_node)); +#else + decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), + unknown_type_node)); + /* Make sure the "unknown type" typedecl gets ignored for debug info. */ + DECL_IGNORED_P (decl) = 1; + TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; +#endif + TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); + TYPE_ALIGN (unknown_type_node) = 1; + TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); + /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ + TREE_TYPE (unknown_type_node) = unknown_type_node; + /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ + TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; + TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; + + /* This is for handling opaque types in signatures. */ + opaque_type_node = copy_node (ptr_type_node); + TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; + record_builtin_type (RID_MAX, 0, opaque_type_node); + + /* This is special for C++ so functions can be overloaded. */ + wchar_type_node + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); + wchar_type_size = TYPE_PRECISION (wchar_type_node); + signed_wchar_type_node = make_signed_type (wchar_type_size); + unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); + wchar_type_node + = TREE_UNSIGNED (wchar_type_node) + ? unsigned_wchar_type_node + : signed_wchar_type_node; + record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); + + /* Artificial declaration of wchar_t -- can be bashed */ + wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), + wchar_type_node); + pushdecl (wchar_decl_node); + + /* This is for wide string constants. */ + wchar_array_type_node + = build_array_type (wchar_type_node, array_domain_type); + + /* This is a hack that should go away when we deliver the + real gc code. */ + if (flag_gc) + { + builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0); + pushdecl (lookup_name (get_identifier ("__gc_main"), 0)); + } + + if (flag_vtable_thunks) + { + /* Make sure we get a unique function type, so we can give + its pointer type a name. (This wins for gdb.) */ + tree vfunc_type = make_node (FUNCTION_TYPE); + TREE_TYPE (vfunc_type) = integer_type_node; + TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; + layout_type (vfunc_type); + + vtable_entry_type = build_pointer_type (vfunc_type); + } + else + { + vtable_entry_type = make_lang_type (RECORD_TYPE); + fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, + delta_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, + delta_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, + ptr_type_node); + finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, + double_type_node); + + /* Make this part of an invisible union. */ + fields[3] = copy_node (fields[2]); + TREE_TYPE (fields[3]) = delta_type_node; + DECL_NAME (fields[3]) = delta2_identifier; + DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); + DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); + TREE_UNSIGNED (fields[3]) = 0; + TREE_CHAIN (fields[2]) = fields[3]; + vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); + } + record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); + + vtbl_type_node + = build_array_type (vtable_entry_type, NULL_TREE); + layout_type (vtbl_type_node); + vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0); + record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); + + /* Simplify life by making a "sigtable_entry_type". Give its + fields names so that the debugger can use them. */ + + if (flag_handle_signatures) + { + sigtable_entry_type = make_lang_type (RECORD_TYPE); + fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, + delta_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, + delta_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, + delta_type_node); + fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, + delta_type_node); + fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, + ptr_type_node); + + /* Set the alignment to the max of the alignment of ptr_type_node and + delta_type_node. Double alignment wastes a word on the Sparc. */ + finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, + (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) + ? ptr_type_node + : delta_type_node); + + /* Make this part of an invisible union. */ + fields[5] = copy_node (fields[4]); + TREE_TYPE (fields[5]) = delta_type_node; + DECL_NAME (fields[5]) = vt_off_identifier; + DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); + DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); + TREE_UNSIGNED (fields[5]) = 0; + TREE_CHAIN (fields[4]) = fields[5]; + + sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); + record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); + } + +#if 0 + if (flag_rtti) + { + /* Must build __t_desc type. Currently, type descriptors look like this: + + struct __t_desc + { + const char *name; + int size; + int bits; + struct __t_desc *points_to; + int ivars_count, meths_count; + struct __i_desc *ivars[]; + struct __m_desc *meths[]; + struct __t_desc *parents[]; + struct __t_desc *vbases[]; + int offsets[]; + }; + + ...as per Linton's paper. */ + + __t_desc_type_node = make_lang_type (RECORD_TYPE); + __i_desc_type_node = make_lang_type (RECORD_TYPE); + __m_desc_type_node = make_lang_type (RECORD_TYPE); + __t_desc_array_type = + build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE); + __i_desc_array_type = + build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE); + __m_desc_array_type = + build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE); + + fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), + string_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), + unsigned_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), + unsigned_type_node); + fields[3] = build_lang_field_decl (FIELD_DECL, + get_identifier ("points_to"), + build_pointer_type (__t_desc_type_node)); + fields[4] = build_lang_field_decl (FIELD_DECL, + get_identifier ("ivars_count"), + integer_type_node); + fields[5] = build_lang_field_decl (FIELD_DECL, + get_identifier ("meths_count"), + integer_type_node); + fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), + build_pointer_type (__i_desc_array_type)); + fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), + build_pointer_type (__m_desc_array_type)); + fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), + build_pointer_type (__t_desc_array_type)); + fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), + build_pointer_type (__t_desc_array_type)); + fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), + build_pointer_type (integer_type_node)); + finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); + + /* ivar descriptors look like this: + + struct __i_desc + { + const char *name; + int offset; + struct __t_desc *type; + }; + */ + + fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), + string_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), + integer_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), + build_pointer_type (__t_desc_type_node)); + finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, + integer_type_node); + + /* method descriptors look like this: + + struct __m_desc + { + const char *name; + int vindex; + struct __t_desc *vcontext; + struct __t_desc *return_type; + void (*address)(); + short parm_count; + short required_parms; + struct __t_desc *parm_types[]; + }; + */ + + fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), + string_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), + integer_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), + build_pointer_type (__t_desc_type_node)); + fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), + build_pointer_type (__t_desc_type_node)); + fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), + build_pointer_type (default_function_type)); + fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), + short_integer_type_node); + fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), + short_integer_type_node); + fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), + build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE))); + finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, + integer_type_node); + } + + if (flag_rtti) + { + int i = builtin_type_tdescs_len; + while (i > 0) + { + tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0); + TREE_ASM_WRITTEN (tdesc) = 1; + TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1; + } + } +#endif /*flag_rtti*/ + + /* Now, C++. */ + current_lang_name = lang_name_cplusplus; + + auto_function (ansi_opname[(int) NEW_EXPR], + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, sizetype, + void_list_node)), + NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_NEW_EXPR], + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, sizetype, + void_list_node)), + NOT_BUILT_IN); + auto_function (ansi_opname[(int) DELETE_EXPR], + build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + void_list_node)), + NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_DELETE_EXPR], + build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + void_list_node)), + NOT_BUILT_IN); + + abort_fndecl + = define_function ("__pure_virtual", + build_function_type (void_type_node, void_list_node), + NOT_BUILT_IN, 0, 0); + + /* Perform other language dependent initializations. */ + init_class_processing (); + init_init_processing (); + init_search_processing (); + + if (flag_handle_exceptions) + init_exception_processing (); + if (flag_gc) + init_gc_processing (); + if (flag_no_inline) + { + flag_inline_functions = 0; +#if 0 + /* This causes unnecessary emission of inline functions. */ + flag_default_inline = 0; +#endif + } + if (flag_cadillac) + init_cadillac (); + + /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ + declare_function_name (); + + /* Prepare to check format strings against argument lists. */ + init_function_format_info (); +} + +/* initialize type descriptor type node of various rtti type. */ + +int +init_type_desc() +{ + tree tdecl; + + tdecl = lookup_name (get_identifier ("type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __t_desc_type_node = TREE_TYPE(tdecl); + __tp_desc_type_node = build_pointer_type (__t_desc_type_node); + +#if 0 + tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __baselist_desc_type_node = TREE_TYPE (tdecl); +#endif + + tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __bltn_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__user_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __user_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__class_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __class_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_field (__class_desc_type_node, + get_identifier ("access_mode"), 0, 0); + if (tdecl == NULL_TREE) + return 0; + __access_mode_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__attr_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __attr_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __ptr_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__func_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __func_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __ptmf_desc_type_node = TREE_TYPE (tdecl); + + tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0); + if (tdecl == NULL_TREE) + return 0; + __ptmd_desc_type_node = TREE_TYPE (tdecl); + + return 1; +} +/* Make a definition for a builtin function named NAME and whose data type + is TYPE. TYPE should be a function type with argument types. + FUNCTION_CODE tells later passes how to compile calls to this function. + See tree.h for its possible values. + + If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, + the name to be called if we can't opencode the function. */ + +tree +define_function (name, type, function_code, pfn, library_name) + char *name; + tree type; + enum built_in_function function_code; + void (*pfn)(); + char *library_name; +{ + tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); + DECL_EXTERNAL (decl) = 1; + TREE_PUBLIC (decl) = 1; + DECL_ARTIFICIAL (decl) = 1; + + /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, + we cannot change DECL_ASSEMBLER_NAME until we have installed this + function in the namespace. */ + if (pfn) (*pfn) (decl); + if (library_name) + DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); + make_function_rtl (decl); + if (function_code != NOT_BUILT_IN) + { + DECL_BUILT_IN (decl) = 1; + DECL_FUNCTION_CODE (decl) = function_code; + } + return decl; +} + +/* Called when a declaration is seen that contains no names to declare. + If its type is a reference to a structure, union or enum inherited + from a containing scope, shadow that tag name for the current scope + with a forward reference. + If its type defines a new named structure or union + or defines an enum, it is valid but we need not do anything here. + Otherwise, it is an error. + + C++: may have to grok the declspecs to learn about static, + complain for anonymous unions. */ + +void +shadow_tag (declspecs) + tree declspecs; +{ + int found_tag = 0; + tree ob_modifier = NULL_TREE; + register tree link; + register enum tree_code code, ok_code = ERROR_MARK; + register tree t = NULL_TREE; + + for (link = declspecs; link; link = TREE_CHAIN (link)) + { + register tree value = TREE_VALUE (link); + + code = TREE_CODE (value); + if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) + { + my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261); + + if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0) + cp_error ("forward declaration of `%#T'", value); + + t = value; + ok_code = code; + found_tag++; + } + else if (value == ridpointers[(int) RID_STATIC] + || value == ridpointers[(int) RID_EXTERN] + || value == ridpointers[(int) RID_AUTO] + || value == ridpointers[(int) RID_REGISTER] + || value == ridpointers[(int) RID_INLINE] + || value == ridpointers[(int) RID_VIRTUAL] + || value == ridpointers[(int) RID_EXPLICIT]) + ob_modifier = value; + } + + /* This is where the variables in an anonymous union are + declared. An anonymous union declaration looks like: + union { ... } ; + because there is no declarator after the union, the parser + sends that declaration here. */ + if (ok_code == UNION_TYPE + && t != NULL_TREE + && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE + && ANON_AGGRNAME_P (TYPE_NAME (t))) + || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) + { + /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have + function members. */ + if (TYPE_FIELDS (t)) + { + tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, + NULL_TREE, NULL_TREE); + finish_anon_union (decl); + } + else + error ("anonymous union cannot have a function member"); + } + else + { + /* Anonymous unions are objects, that's why we only check for + inappropriate specifiers in this branch. */ + + if (ob_modifier) + { + if (ob_modifier == ridpointers[(int) RID_INLINE] + || ob_modifier == ridpointers[(int) RID_VIRTUAL]) + cp_error ("`%D' can only be specified for functions", ob_modifier); + else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) + cp_error ("`%D' can only be specified for constructors", + ob_modifier); + else + cp_error ("`%D' can only be specified for objects and functions", + ob_modifier); + } + + if (found_tag == 0) + pedwarn ("abstract declarator used as declaration"); + else if (found_tag > 1) + pedwarn ("multiple types in one declaration"); + } +} + +/* Decode a "typename", such as "int **", returning a ..._TYPE node. */ + +tree +groktypename (typename) + tree typename; +{ + if (TREE_CODE (typename) != TREE_LIST) + return typename; + return grokdeclarator (TREE_VALUE (typename), + TREE_PURPOSE (typename), + TYPENAME, 0, NULL_TREE, NULL_TREE); +} + +/* Decode a declarator in an ordinary declaration or data definition. + This is called as soon as the type information and variable name + have been parsed, before parsing the initializer if any. + Here we create the ..._DECL node, fill in its type, + and put it on the list of decls for the current context. + The ..._DECL node is returned as the value. + + Exception: for arrays where the length is not specified, + the type is left null, to be filled in by `cp_finish_decl'. + + Function definitions do not come here; they go to start_function + instead. However, external and forward declarations of functions + do go through here. Structure field declarations are done by + grokfield and not through here. */ + +/* Set this to zero to debug not using the temporary obstack + to parse initializers. */ +int debug_temp_inits = 1; + +tree +start_decl (declarator, declspecs, initialized, raises) + tree declarator, declspecs; + int initialized; + tree raises; +{ + register tree decl; + register tree type, tem; + tree context; + extern int have_extern_spec; + extern int used_extern_spec; + + int init_written = initialized; + + /* This should only be done once on the top most decl. */ + if (have_extern_spec && !used_extern_spec) + { + declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), + declspecs); + used_extern_spec = 1; + } + + decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises, + NULL_TREE); + if (decl == NULL_TREE || decl == void_type_node) + return NULL_TREE; + + type = TREE_TYPE (decl); + + /* Don't lose if destructors must be executed at file-level. */ + if (TREE_STATIC (decl) + && TYPE_NEEDS_DESTRUCTOR (type) + && !TREE_PERMANENT (decl)) + { + push_obstacks (&permanent_obstack, &permanent_obstack); + decl = copy_node (decl); + if (TREE_CODE (type) == ARRAY_TYPE) + { + tree itype = TYPE_DOMAIN (type); + if (itype && ! TREE_PERMANENT (itype)) + { + itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); + type = build_cplus_array_type (TREE_TYPE (type), itype); + TREE_TYPE (decl) = type; + } + } + pop_obstacks (); + } + + /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ + push_obstacks_nochange (); + + context + = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) + ? DECL_CLASS_CONTEXT (decl) + : DECL_CONTEXT (decl); + + if (processing_template_decl) + { + tree d; + if (TREE_CODE (decl) == FUNCTION_DECL) + { + /* Declarator is a call_expr; extract arguments from it, since + grokdeclarator didn't do it. */ + tree args; + args = copy_to_permanent (last_function_parms); + if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) + { + tree t = TREE_TYPE (decl); + + t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */ + if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE) + { + t = build_pointer_type (t); /* base type of `this' */ +#if 1 + /* I suspect this is wrong. */ + t = build_type_variant (t, flag_this_is_variable <= 0, + 0); /* type of `this' */ +#else + t = build_type_variant (t, 0, 0); /* type of `this' */ +#endif + t = build (PARM_DECL, t, this_identifier); + TREE_CHAIN (t) = args; + args = t; + } + } + DECL_ARGUMENTS (decl) = args; + } + d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl)); + TREE_PUBLIC (d) = TREE_PUBLIC (decl); + TREE_STATIC (d) = TREE_STATIC (decl); + DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) + && !(context && !DECL_THIS_EXTERN (decl))); + DECL_TEMPLATE_RESULT (d) = decl; + decl = d; + } + + /* If this type of object needs a cleanup, and control may + jump past it, make a new binding level so that it is cleaned + up only when it is initialized first. */ + if (TYPE_NEEDS_DESTRUCTOR (type) + && current_binding_level->more_cleanups_ok == 0) + pushlevel_temporary (1); + + if (initialized) + /* Is it valid for this decl to have an initializer at all? + If not, set INITIALIZED to zero, which will indirectly + tell `cp_finish_decl' to ignore the initializer once it is parsed. */ + switch (TREE_CODE (decl)) + { + case TYPE_DECL: + /* typedef foo = bar means give foo the same type as bar. + We haven't parsed bar yet, so `cp_finish_decl' will fix that up. + Any other case of an initialization in a TYPE_DECL is an error. */ + if (pedantic || list_length (declspecs) > 1) + { + cp_error ("typedef `%D' is initialized", decl); + initialized = 0; + } + break; + + case FUNCTION_DECL: + cp_error ("function `%#D' is initialized like a variable", decl); + initialized = 0; + break; + + default: + /* Don't allow initializations for incomplete types except for + arrays which might be completed by the initialization. */ + if (type == error_mark_node) + ; /* Don't complain again. */ + else if (TYPE_SIZE (type) != NULL_TREE) + ; /* A complete type is ok. */ + else if (TREE_CODE (type) != ARRAY_TYPE) + { + cp_error ("variable `%#D' has initializer but incomplete type", + decl); + initialized = 0; + } + else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE) + { + cp_error ("elements of array `%#D' have incomplete type", decl); + initialized = 0; + } + } + + if (!initialized + && TREE_CODE (decl) != TYPE_DECL + && TREE_CODE (decl) != TEMPLATE_DECL + && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) + { + if (TYPE_SIZE (type) == NULL_TREE) + { + cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", + decl); + /* Change the type so that assemble_variable will give + DECL an rtl we can live with: (mem (const_int 0)). */ + TREE_TYPE (decl) = error_mark_node; + type = error_mark_node; + } + else + { + /* If any base type in the hierarchy of TYPE needs a constructor, + then we set initialized to 1. This way any nodes which are + created for the purposes of initializing this aggregate + will live as long as it does. This is necessary for global + aggregates which do not have their initializers processed until + the end of the file. */ + initialized = TYPE_NEEDS_CONSTRUCTING (type); + } + } + + if (initialized) + { + if (! toplevel_bindings_p () + && DECL_EXTERNAL (decl)) + cp_warning ("declaration of `%#D' has `extern' and is initialized", + decl); + DECL_EXTERNAL (decl) = 0; + if ( toplevel_bindings_p ()) + TREE_STATIC (decl) = 1; + + /* Tell `pushdecl' this is an initialized decl + even though we don't yet have the initializer expression. + Also tell `cp_finish_decl' it may store the real initializer. */ + DECL_INITIAL (decl) = error_mark_node; + } + + if (context && TYPE_SIZE (context) != NULL_TREE) + { + if (TREE_CODE (decl) == VAR_DECL) + { + tree field = lookup_field (context, DECL_NAME (decl), 0, 0); + if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) + cp_error ("`%#D' is not a static member of `%#T'", decl, context); + else if (duplicate_decls (decl, field)) + decl = field; + } + else + { + tree field = check_classfn (context, NULL_TREE, decl); + if (field && duplicate_decls (decl, field)) + decl = field; + } + + /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ + if (DECL_LANG_SPECIFIC (decl)) + DECL_IN_AGGR_P (decl) = 0; + if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) + SET_DECL_TEMPLATE_SPECIALIZATION (decl); + + /* Stupid stupid stupid stupid (jason 7/21/95) */ + if (pedantic && DECL_EXTERNAL (decl) + && ! DECL_TEMPLATE_SPECIALIZATION (decl)) + cp_pedwarn ("declaration of `%#D' outside of class is not definition", + decl); + + pushclass (context, 2); + } + + /* Add this decl to the current binding level, but not if it + comes from another scope, e.g. a static member variable. + TEM may equal DECL or it may be a previous decl of the same name. */ + + if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) + || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) + || TREE_CODE (type) == LANG_TYPE) + tem = decl; + else + tem = pushdecl (decl); + + /* Tell the back-end to use or not use .common as appropriate. If we say + -fconserve-space, we want this to save space, at the expense of wrong + semantics. If we say -fno-conserve-space, we want this to produce + errors about redefs; to do this we force variables into the data + segment. Common storage is okay for non-public uninitialized data; + the linker can't match it with storage from other files, and we may + save some disk space. */ + DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); + +#if 0 + /* We don't do this yet for GNU C++. */ + /* For a local variable, define the RTL now. */ + if (! toplevel_bindings_p () + /* But not if this is a duplicate decl + and we preserved the rtl from the previous one + (which may or may not happen). */ + && DECL_RTL (tem) == NULL_RTX) + { + if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) + expand_decl (tem); + else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE + && DECL_INITIAL (tem) != NULL_TREE) + expand_decl (tem); + } +#endif + + if (TREE_CODE (decl) == TEMPLATE_DECL) + { + tree result = DECL_TEMPLATE_RESULT (decl); + if (DECL_CONTEXT (result) != NULL_TREE) + { + tree type; + type = DECL_CONTEXT (result); + + if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE) + { + cp_error ("declaration of `%D' in non-template type `%T'", + decl, type); + return NULL_TREE; + } + + if (TREE_CODE (result) == FUNCTION_DECL) + return tem; + else if (TREE_CODE (result) == VAR_DECL) + { +#if 0 + tree tmpl = UPT_TEMPLATE (type); + + fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__); + print_node_brief (stderr, "", DECL_NAME (tem), 0); + fprintf (stderr, " to class %s\n", + IDENTIFIER_POINTER (DECL_NAME (tmpl))); + DECL_TEMPLATE_MEMBERS (tmpl) + = perm_tree_cons (DECL_NAME (tem), tem, + DECL_TEMPLATE_MEMBERS (tmpl)); + return tem; +#else + sorry ("static data member templates"); + return NULL_TREE; +#endif + } + else + my_friendly_abort (13); + } + else if (TREE_CODE (result) == FUNCTION_DECL) + /*tem = push_overloaded_decl (tem, 0)*/; + else if (TREE_CODE (result) == VAR_DECL) + { + cp_error ("data template `%#D' must be member of a class template", + result); + return NULL_TREE; + } + else if (TREE_CODE (result) == TYPE_DECL) + { + cp_error ("invalid template `%#D'", result); + return NULL_TREE; + } + else + my_friendly_abort (14); + } + + if (init_written + && ! (TREE_CODE (tem) == PARM_DECL + || (TREE_READONLY (tem) + && (TREE_CODE (tem) == VAR_DECL + || TREE_CODE (tem) == FIELD_DECL)))) + { + /* When parsing and digesting the initializer, + use temporary storage. Do this even if we will ignore the value. */ + if (toplevel_bindings_p () && debug_temp_inits) + { + if (TYPE_NEEDS_CONSTRUCTING (type) + || TREE_CODE (type) == REFERENCE_TYPE) + /* In this case, the initializer must lay down in permanent + storage, since it will be saved until `finish_file' is run. */ + ; + else + temporary_allocation (); + } + } + + if (flag_cadillac) + cadillac_start_decl (tem); + + return tem; +} + +#if 0 /* unused */ +static void +make_temporary_for_reference (decl, ctor_call, init, cleanupp) + tree decl, ctor_call, init; + tree *cleanupp; +{ + tree type = TREE_TYPE (decl); + tree target_type = TREE_TYPE (type); + tree tmp, tmp_addr; + + if (ctor_call) + { + tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1)); + if (TREE_CODE (tmp_addr) == NOP_EXPR) + tmp_addr = TREE_OPERAND (tmp_addr, 0); + my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146); + tmp = TREE_OPERAND (tmp_addr, 0); + } + else + { + tmp = get_temp_name (target_type, toplevel_bindings_p ()); + tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); + } + + TREE_TYPE (tmp_addr) = build_pointer_type (target_type); + DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr); + TREE_TYPE (DECL_INITIAL (decl)) = type; + if (TYPE_NEEDS_CONSTRUCTING (target_type)) + { + if (toplevel_bindings_p ()) + { + /* lay this variable out now. Otherwise `output_addressed_constants' + gets confused by its initializer. */ + make_decl_rtl (tmp, NULL_PTR, 1); + static_aggregates = perm_tree_cons (init, tmp, static_aggregates); + } + else + { + if (ctor_call != NULL_TREE) + init = ctor_call; + else + init = build_method_call (tmp, constructor_name_full (target_type), + build_tree_list (NULL_TREE, init), + NULL_TREE, LOOKUP_NORMAL); + DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, + DECL_INITIAL (decl)); + *cleanupp = maybe_build_cleanup (tmp); + } + } + else + { + DECL_INITIAL (tmp) = init; + TREE_STATIC (tmp) = toplevel_bindings_p (); + cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + } + if (TREE_STATIC (tmp)) + preserve_initializer (); +} +#endif + +/* Handle initialization of references. + These three arguments from from `cp_finish_decl', and have the + same meaning here that they do there. */ +/* quotes on semantics can be found in ARM 8.4.3. */ +static void +grok_reference_init (decl, type, init, cleanupp) + tree decl, type, init; + tree *cleanupp; +{ + tree tmp; + + if (init == NULL_TREE) + { + if ((DECL_LANG_SPECIFIC (decl) == 0 + || DECL_IN_AGGR_P (decl) == 0) + && ! DECL_THIS_EXTERN (decl)) + { + cp_error ("`%D' declared as reference but not initialized", decl); + if (TREE_CODE (decl) == VAR_DECL) + SET_DECL_REFERENCE_SLOT (decl, error_mark_node); + } + return; + } + + if (init == error_mark_node) + return; + + if (TREE_CODE (type) == REFERENCE_TYPE + && TREE_CODE (init) == CONSTRUCTOR) + { + cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); + return; + } + + if (TREE_CODE (init) == TREE_LIST) + init = build_compound_expr (init); + + if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) + init = convert_from_reference (init); + + if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE + && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) + { + /* Note: default conversion is only called in very special cases. */ + init = default_conversion (init); + } + + tmp = convert_to_reference + (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl); + + if (tmp == error_mark_node) + goto fail; + else if (tmp != NULL_TREE) + { + tree subtype = TREE_TYPE (type); + init = tmp; + + /* Associate the cleanup with the reference so that we + don't get burned by "aggressive" cleanup policy. */ + if (TYPE_NEEDS_DESTRUCTOR (subtype)) + { + if (TREE_CODE (init) == WITH_CLEANUP_EXPR) + { + *cleanupp = TREE_OPERAND (init, 2); + TREE_OPERAND (init, 2) = error_mark_node; + } + else + { + if (TREE_CODE (tmp) == ADDR_EXPR) + tmp = TREE_OPERAND (tmp, 0); + if (TREE_CODE (tmp) == TARGET_EXPR) + { + *cleanupp = build_delete + (build_pointer_type (subtype), + build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0), + integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0); + TREE_OPERAND (tmp, 2) = error_mark_node; + } + } + } + + DECL_INITIAL (decl) = save_expr (init); + } + else + { + cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); + goto fail; + } + + /* ?? Can this be optimized in some cases to + hand back the DECL_INITIAL slot?? */ + if (TYPE_SIZE (TREE_TYPE (type))) + { + init = convert_from_reference (decl); + if (TREE_PERMANENT (decl)) + init = copy_to_permanent (init); + SET_DECL_REFERENCE_SLOT (decl, init); + } + + if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) + { + expand_static_init (decl, DECL_INITIAL (decl)); + DECL_INITIAL (decl) = NULL_TREE; + } + return; + + fail: + if (TREE_CODE (decl) == VAR_DECL) + SET_DECL_REFERENCE_SLOT (decl, error_mark_node); + return; +} + +/* Fill in DECL_INITIAL with some magical value to prevent expand_decl from + mucking with forces it does not comprehend (i.e. initialization with a + constructor). If we are at global scope and won't go into COMMON, fill + it in with a dummy CONSTRUCTOR to force the variable into .data; + otherwise we can use error_mark_node. */ + +static tree +obscure_complex_init (decl, init) + tree decl, init; +{ + if (! flag_no_inline && TREE_STATIC (decl)) + { + if (extract_init (decl, init)) + return NULL_TREE; + } + + if (toplevel_bindings_p () && ! DECL_COMMON (decl)) + DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, + NULL_TREE); + else + DECL_INITIAL (decl) = error_mark_node; + + return init; +} + +/* Finish processing of a declaration; + install its line number and initial value. + If the length of an array type is not known before, + it must be determined now, from the initial value, or it is an error. + + Call `pop_obstacks' iff NEED_POP is nonzero. + + For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers + for aggregates that have constructors alive on the permanent obstack, + so that the global initializing functions can be written at the end. + + INIT0 holds the value of an initializer that should be allowed to escape + the normal rules. + + FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 + if the (init) syntax was used. + + For functions that take default parameters, DECL points to its + "maximal" instantiation. `cp_finish_decl' must then also declared its + subsequently lower and lower forms of instantiation, checking for + ambiguity as it goes. This can be sped up later. */ + +void +cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) + tree decl, init; + tree asmspec_tree; + int need_pop; + int flags; +{ + register tree type; + tree cleanup = NULL_TREE, ttype; + int was_incomplete; + int temporary = allocation_temporary_p (); + char *asmspec = NULL; + int was_readonly = 0; + + /* If this is 0, then we did not change obstacks. */ + if (! decl) + { + if (init) + error ("assignment (not initialization) in declaration"); + return; + } + + /* If a name was specified, get the string. */ + if (asmspec_tree) + asmspec = TREE_STRING_POINTER (asmspec_tree); + + /* If the type of the thing we are declaring either has + a constructor, or has a virtual function table pointer, + AND its initialization was accepted by `start_decl', + then we stayed on the permanent obstack through the + declaration, otherwise, changed obstacks as GCC would. */ + + type = TREE_TYPE (decl); + + if (type == error_mark_node) + { + if (toplevel_bindings_p () && temporary) + end_temporary_allocation (); + + return; + } + + was_incomplete = (DECL_SIZE (decl) == NULL_TREE); + + /* Take care of TYPE_DECLs up front. */ + if (TREE_CODE (decl) == TYPE_DECL) + { + if (init && DECL_INITIAL (decl)) + { + /* typedef foo = bar; store the type of bar as the type of foo. */ + TREE_TYPE (decl) = type = TREE_TYPE (init); + DECL_INITIAL (decl) = init = NULL_TREE; + } + if (type != error_mark_node + && IS_AGGR_TYPE (type) && DECL_NAME (decl)) + { + if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) + cp_warning ("shadowing previous type declaration of `%#D'", decl); + set_identifier_type_value (DECL_NAME (decl), type); + CLASSTYPE_GOT_SEMICOLON (type) = 1; + } + GNU_xref_decl (current_function_decl, decl); + rest_of_decl_compilation (decl, NULL_PTR, + DECL_CONTEXT (decl) == NULL_TREE, 0); + goto finish_end; + } + if (TREE_CODE (decl) != FUNCTION_DECL) + { + ttype = target_type (type); +#if 0 /* WTF? -KR + Leave this out until we can figure out why it was + needed/desirable in the first place. Then put a comment + here explaining why. Or just delete the code if no ill + effects arise. */ + if (TYPE_NAME (ttype) + && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype))) + { + tree old_id = TYPE_IDENTIFIER (ttype); + char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2); + /* Need to preserve template data for UPT nodes. */ + tree old_template = IDENTIFIER_TEMPLATE (old_id); + newname[0] = '_'; + bcopy (IDENTIFIER_POINTER (old_id), newname + 1, + IDENTIFIER_LENGTH (old_id) + 1); + old_id = get_identifier (newname); + lookup_tag_reverse (ttype, old_id); + TYPE_IDENTIFIER (ttype) = old_id; + IDENTIFIER_TEMPLATE (old_id) = old_template; + } +#endif + } + + if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) + && TYPE_NEEDS_CONSTRUCTING (type)) + { + + /* Currently, GNU C++ puts constants in text space, making them + impossible to initialize. In the future, one would hope for + an operating system which understood the difference between + initialization and the running of a program. */ + was_readonly = 1; + TREE_READONLY (decl) = 0; + } + + if (TREE_CODE (decl) == FIELD_DECL) + { + if (init && init != error_mark_node) + my_friendly_assert (TREE_PERMANENT (init), 147); + + if (asmspec) + { + /* This must override the asm specifier which was placed + by grokclassfn. Lay this out fresh. */ + DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; + DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); + make_decl_rtl (decl, asmspec, 0); + } + } + /* If `start_decl' didn't like having an initialization, ignore it now. */ + else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) + init = NULL_TREE; + else if (DECL_EXTERNAL (decl)) + ; + else if (TREE_CODE (type) == REFERENCE_TYPE + || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) + { + if (TREE_STATIC (decl)) + make_decl_rtl (decl, NULL_PTR, + toplevel_bindings_p () + || pseudo_global_level_p ()); + grok_reference_init (decl, type, init, &cleanup); + init = NULL_TREE; + } + + GNU_xref_decl (current_function_decl, decl); + + if (TREE_CODE (decl) == FIELD_DECL) + ; + else if (TREE_CODE (decl) == CONST_DECL) + { + my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); + + DECL_INITIAL (decl) = init; + + /* This will keep us from needing to worry about our obstacks. */ + my_friendly_assert (init != NULL_TREE, 149); + init = NULL_TREE; + } + else if (init) + { + if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) + { + if (TREE_CODE (type) == ARRAY_TYPE) + init = digest_init (type, init, (tree *) 0); + else if (TREE_CODE (init) == CONSTRUCTOR) + { + if (TYPE_NON_AGGREGATE_CLASS (type)) + { + cp_error ("`%D' must be initialized by constructor, not by `{...}'", + decl); + init = error_mark_node; + } + else + goto dont_use_constructor; + } + } + else + { + dont_use_constructor: + if (TREE_CODE (init) != TREE_VEC) + init = store_init_value (decl, init); + } + + if (init) + /* We must hide the initializer so that expand_decl + won't try to do something it does not understand. */ + init = obscure_complex_init (decl, init); + } + else if (DECL_EXTERNAL (decl)) + ; + else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' + && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) + { + tree ctype = type; + while (TREE_CODE (ctype) == ARRAY_TYPE) + ctype = TREE_TYPE (ctype); + if (! TYPE_NEEDS_CONSTRUCTING (ctype)) + { + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) + cp_error ("structure `%D' with uninitialized const members", decl); + if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) + cp_error ("structure `%D' with uninitialized reference members", + decl); + } + + if (TREE_CODE (decl) == VAR_DECL + && !DECL_INITIAL (decl) + && !TYPE_NEEDS_CONSTRUCTING (type) + && (TYPE_READONLY (type) || TREE_READONLY (decl))) + cp_error ("uninitialized const `%D'", decl); + + if (TYPE_SIZE (type) != NULL_TREE + && TYPE_NEEDS_CONSTRUCTING (type)) + init = obscure_complex_init (decl, NULL_TREE); + } + else if (TREE_CODE (decl) == VAR_DECL + && TREE_CODE (type) != REFERENCE_TYPE + && (TYPE_READONLY (type) || TREE_READONLY (decl))) + { + /* ``Unless explicitly declared extern, a const object does not have + external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 + However, if it's `const int foo = 1; const int foo;', don't complain + about the second decl, since it does have an initializer before. + We deliberately don't complain about arrays, because they're + supposed to be initialized by a constructor. */ + if (! DECL_INITIAL (decl) + && TREE_CODE (type) != ARRAY_TYPE + && (!pedantic || !current_class_type)) + cp_error ("uninitialized const `%#D'", decl); + } + + /* For top-level declaration, the initial value was read in + the temporary obstack. MAXINDEX, rtl, etc. to be made below + must go in the permanent obstack; but don't discard the + temporary data yet. */ + + if (toplevel_bindings_p () && temporary) + end_temporary_allocation (); + + /* Deduce size of array from initialization, if not already known. */ + + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == NULL_TREE + && TREE_CODE (decl) != TYPE_DECL) + { + int do_default + = (TREE_STATIC (decl) + /* Even if pedantic, an external linkage array + may have incomplete type at first. */ + ? pedantic && ! DECL_EXTERNAL (decl) + : !DECL_EXTERNAL (decl)); + tree initializer = init ? init : DECL_INITIAL (decl); + int failure = complete_array_type (type, initializer, do_default); + + if (failure == 1) + cp_error ("initializer fails to determine size of `%D'", decl); + + if (failure == 2) + { + if (do_default) + cp_error ("array size missing in `%D'", decl); + /* If a `static' var's size isn't known, make it extern as + well as static, so it does not get allocated. If it's not + `static', then don't mark it extern; finish_incomplete_decl + will give it a default size and it will get allocated. */ + else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) + DECL_EXTERNAL (decl) = 1; + } + + if (pedantic && TYPE_DOMAIN (type) != NULL_TREE + && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), + integer_zero_node)) + cp_error ("zero-size array `%D'", decl); + + layout_decl (decl, 0); + } + + if (TREE_CODE (decl) == VAR_DECL) + { + if (DECL_SIZE (decl) == NULL_TREE + && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE) + layout_decl (decl, 0); + + if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) + { + /* A static variable with an incomplete type: + that is an error if it is initialized. + Otherwise, let it through, but if it is not `extern' + then it may cause an error message later. */ + if (DECL_INITIAL (decl) != NULL_TREE) + cp_error ("storage size of `%D' isn't known", decl); + init = NULL_TREE; + } + else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) + { + /* An automatic variable with an incomplete type: that is an error. + Don't talk about array types here, since we took care of that + message in grokdeclarator. */ + cp_error ("storage size of `%D' isn't known", decl); + TREE_TYPE (decl) = error_mark_node; + } + else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) + /* Let debugger know it should output info for this type. */ + note_debug_info_needed (ttype); + + if (TREE_STATIC (decl) && DECL_CONTEXT (decl) + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') + note_debug_info_needed (DECL_CONTEXT (decl)); + + if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) + && DECL_SIZE (decl) != NULL_TREE + && ! TREE_CONSTANT (DECL_SIZE (decl))) + { + if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) + constant_expression_warning (DECL_SIZE (decl)); + else + cp_error ("storage size of `%D' isn't constant", decl); + } + + if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)) + { + int yes = suspend_momentary (); + + /* If INIT comes from a functional cast, use the cleanup + we built for that. Otherwise, make our own cleanup. */ + if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR + && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1)) + { + cleanup = TREE_OPERAND (init, 2); + init = TREE_OPERAND (init, 0); + current_binding_level->have_cleanups = 1; + } + else + cleanup = maybe_build_cleanup (decl); + resume_momentary (yes); + } + } + /* PARM_DECLs get cleanups, too. */ + else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) + { + if (temporary) + end_temporary_allocation (); + cleanup = maybe_build_cleanup (decl); + if (temporary) + resume_temporary_allocation (); + } + + /* Output the assembler code and/or RTL code for variables and functions, + unless the type is an undefined structure or union. + If not, it will get done when the type is completed. */ + + if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL + || TREE_CODE (decl) == RESULT_DECL) + { + /* ??? FIXME: What about nested classes? */ + int toplev = toplevel_bindings_p () || pseudo_global_level_p (); + int was_temp + = ((flag_traditional + || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type))) + && allocation_temporary_p ()); + + if (was_temp) + end_temporary_allocation (); + + if (TREE_CODE (decl) == VAR_DECL + && ! toplevel_bindings_p () + && ! TREE_STATIC (decl) + && type_needs_gc_entry (type)) + DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); + + if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) + make_decl_rtl (decl, NULL_PTR, toplev); + else if (TREE_CODE (decl) == VAR_DECL + && TREE_READONLY (decl) + && DECL_INITIAL (decl) != NULL_TREE + && DECL_INITIAL (decl) != error_mark_node + && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) + { + DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); + + if (asmspec) + DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); + + if (! toplev + && TREE_STATIC (decl) + && ! TREE_SIDE_EFFECTS (decl) + && ! TREE_PUBLIC (decl) + && ! DECL_EXTERNAL (decl) + && ! TYPE_NEEDS_DESTRUCTOR (type) + && DECL_MODE (decl) != BLKmode) + { + /* If this variable is really a constant, then fill its DECL_RTL + slot with something which won't take up storage. + If something later should take its address, we can always give + it legitimate RTL at that time. */ + DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); + store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); + TREE_ASM_WRITTEN (decl) = 1; + } + else if (toplev && ! TREE_PUBLIC (decl)) + { + /* If this is a static const, change its apparent linkage + if it belongs to a #pragma interface. */ + if (!interface_unknown) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = interface_only; + } + make_decl_rtl (decl, asmspec, toplev); + } + else + rest_of_decl_compilation (decl, asmspec, toplev, 0); + } + else if (TREE_CODE (decl) == VAR_DECL + && DECL_LANG_SPECIFIC (decl) + && DECL_IN_AGGR_P (decl)) + { + if (TREE_STATIC (decl)) + { + if (init == NULL_TREE +#ifdef DEFAULT_STATIC_DEFS + /* If this code is dead, then users must + explicitly declare static member variables + outside the class def'n as well. */ + && TYPE_NEEDS_CONSTRUCTING (type) +#endif + ) + { + DECL_EXTERNAL (decl) = 1; + make_decl_rtl (decl, asmspec, 1); + } + else + rest_of_decl_compilation (decl, asmspec, toplev, 0); + } + else + /* Just a constant field. Should not need any rtl. */ + goto finish_end0; + } + else + rest_of_decl_compilation (decl, asmspec, toplev, 0); + + if (was_temp) + resume_temporary_allocation (); + + if (type != error_mark_node + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_ABSTRACT_VIRTUALS (type)) + abstract_virtuals_error (decl, type); + else if ((TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) + && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) + abstract_virtuals_error (decl, TREE_TYPE (type)); + + if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) + signature_error (decl, type); + else if ((TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) + && IS_SIGNATURE (TREE_TYPE (type))) + signature_error (decl, TREE_TYPE (type)); + + if (TREE_CODE (decl) == FUNCTION_DECL) + ; + else if (DECL_EXTERNAL (decl)) + ; + else if (TREE_STATIC (decl) && type != error_mark_node) + { + /* Cleanups for static variables are handled by `finish_file'. */ + if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE + || TYPE_NEEDS_DESTRUCTOR (type)) + expand_static_init (decl, init); + + /* Make entry in appropriate vector. */ + if (flag_gc && type_needs_gc_entry (type)) + build_static_gc_entry (decl, type); + } + else if (! toplev) + { + tree old_cleanups = cleanups_this_call; + /* This is a declared decl which must live until the + end of the binding contour. It may need a cleanup. */ + + /* Recompute the RTL of a local array now + if it used to be an incomplete type. */ + if (was_incomplete && ! TREE_STATIC (decl)) + { + /* If we used it already as memory, it must stay in memory. */ + TREE_ADDRESSABLE (decl) = TREE_USED (decl); + /* If it's still incomplete now, no init will save it. */ + if (DECL_SIZE (decl) == NULL_TREE) + DECL_INITIAL (decl) = NULL_TREE; + expand_decl (decl); + } + else if (! TREE_ASM_WRITTEN (decl) + && (TYPE_SIZE (type) != NULL_TREE + || TREE_CODE (type) == ARRAY_TYPE)) + { + /* Do this here, because we did not expand this decl's + rtl in start_decl. */ + if (DECL_RTL (decl) == NULL_RTX) + expand_decl (decl); + else if (cleanup) + { + /* XXX: Why don't we use decl here? */ + /* Ans: Because it was already expanded? */ + if (! cp_expand_decl_cleanup (NULL_TREE, cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", + decl); + /* Cleanup used up here. */ + cleanup = NULL_TREE; + } + } + + if (DECL_SIZE (decl) && type != error_mark_node) + { + /* Compute and store the initial value. */ + expand_decl_init (decl); + + if (init || TYPE_NEEDS_CONSTRUCTING (type)) + { + emit_line_note (DECL_SOURCE_FILE (decl), + DECL_SOURCE_LINE (decl)); + expand_aggr_init (decl, init, 0, flags); + } + + /* Set this to 0 so we can tell whether an aggregate which + was initialized was ever used. Don't do this if it has a + destructor, so we don't complain about the 'resource + allocation is initialization' idiom. */ + if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE) + TREE_USED (decl) = 0; + + /* Store the cleanup, if there was one. */ + if (cleanup) + { + if (! cp_expand_decl_cleanup (decl, cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", + decl); + } + } + /* Cleanup any temporaries needed for the initial value. */ + expand_cleanups_to (old_cleanups); + } + finish_end0: + + /* Undo call to `pushclass' that was done in `start_decl' + due to initialization of qualified member variable. + I.e., Foo::x = 10; */ + { + tree context = DECL_REAL_CONTEXT (decl); + if (context + && TREE_CODE_CLASS (TREE_CODE (context)) == 't' + && (TREE_CODE (decl) == VAR_DECL + /* We also have a pushclass done that we need to undo here + if we're at top level and declare a method. */ + || (TREE_CODE (decl) == FUNCTION_DECL + /* If size hasn't been set, we're still defining it, + and therefore inside the class body; don't pop + the binding level.. */ + && TYPE_SIZE (context) != NULL_TREE + /* The binding level gets popped elsewhere for a + friend declaration inside another class. */ + /* + && TYPE_IDENTIFIER (context) == current_class_name + */ + && context == current_class_type + ))) + popclass (1); + } + } + + finish_end: + + /* If requested, warn about definitions of large data objects. */ + + if (warn_larger_than + && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) + && !DECL_EXTERNAL (decl)) + { + register tree decl_size = DECL_SIZE (decl); + + if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) + { + unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; + + if (units > larger_than_size) + warning_with_decl (decl, "size of `%s' is %u bytes", units); + } + } + + if (need_pop) + { + /* Resume permanent allocation, if not within a function. */ + /* The corresponding push_obstacks_nochange is in start_decl, + start_method, groktypename, and in grokfield. */ + pop_obstacks (); + } + + if (was_readonly) + TREE_READONLY (decl) = 1; + + if (flag_cadillac) + cadillac_finish_decl (decl); +} + +/* This is here for a midend callback from c-common.c */ +void +finish_decl (decl, init, asmspec_tree) + tree decl, init; + tree asmspec_tree; +{ + cp_finish_decl (decl, init, asmspec_tree, 1, 0); +} + +void +expand_static_init (decl, init) + tree decl; + tree init; +{ + tree oldstatic = value_member (decl, static_aggregates); + tree old_cleanups; + + if (oldstatic) + { + if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) + cp_error ("multiple initializations given for `%D'", decl); + } + else if (! toplevel_bindings_p () && ! pseudo_global_level_p ()) + { + /* Emit code to perform this initialization but once. */ + tree temp; + + /* Remember this information until end of file. */ + push_obstacks (&permanent_obstack, &permanent_obstack); + + /* Emit code to perform this initialization but once. */ + temp = get_temp_name (integer_type_node, 1); + rest_of_decl_compilation (temp, NULL_PTR, 0, 0); + expand_start_cond (build_binary_op (EQ_EXPR, temp, + integer_zero_node, 1), 0); + old_cleanups = cleanups_this_call; + expand_assignment (temp, integer_one_node, 0, 0); + if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) + || (init && TREE_CODE (init) == TREE_LIST)) + { + expand_aggr_init (decl, init, 0, 0); + do_pending_stack_adjust (); + } + else if (init) + expand_assignment (decl, init, 0, 0); + + /* Cleanup any temporaries needed for the initial value. */ + expand_cleanups_to (old_cleanups); + expand_end_cond (); + if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) + { + static_aggregates = perm_tree_cons (temp, decl, static_aggregates); + TREE_STATIC (static_aggregates) = 1; + } + + /* Resume old (possibly temporary) allocation. */ + pop_obstacks (); + } + else + { + /* This code takes into account memory allocation + policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING + does not hold for this object, then we must make permanent + the storage currently in the temporary obstack. */ + if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) + preserve_initializer (); + static_aggregates = perm_tree_cons (init, decl, static_aggregates); + } +} + +/* Make TYPE a complete type based on INITIAL_VALUE. + Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, + 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ + +int +complete_array_type (type, initial_value, do_default) + tree type, initial_value; + int do_default; +{ + register tree maxindex = NULL_TREE; + int value = 0; + + if (initial_value) + { + /* Note MAXINDEX is really the maximum index, + one less than the size. */ + if (TREE_CODE (initial_value) == STRING_CST) + { + int eltsize + = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); + maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) + / eltsize) - 1, 0); + } + else if (TREE_CODE (initial_value) == CONSTRUCTOR) + { + tree elts = CONSTRUCTOR_ELTS (initial_value); + maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); + for (; elts; elts = TREE_CHAIN (elts)) + { + if (TREE_PURPOSE (elts)) + maxindex = TREE_PURPOSE (elts); + else + maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); + } + maxindex = copy_node (maxindex); + } + else + { + /* Make an error message unless that happened already. */ + if (initial_value != error_mark_node) + value = 1; + + /* Prevent further error messages. */ + maxindex = build_int_2 (0, 0); + } + } + + if (!maxindex) + { + if (do_default) + maxindex = build_int_2 (0, 0); + value = 2; + } + + if (maxindex) + { + tree itype; + + TYPE_DOMAIN (type) = build_index_type (maxindex); + if (! TREE_TYPE (maxindex)) + TREE_TYPE (maxindex) = TYPE_DOMAIN (type); + if (initial_value) + itype = TREE_TYPE (initial_value); + else + itype = NULL; + if (itype && !TYPE_DOMAIN (itype)) + TYPE_DOMAIN (itype) = TYPE_DOMAIN (type); + /* The type of the main variant should never be used for arrays + of different sizes. It should only ever be completed with the + size of the array. */ + if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) + TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type); + } + + /* Lay out the type now that we can get the real answer. */ + + layout_type (type); + + return value; +} + +/* Return zero if something is declared to be a member of type + CTYPE when in the context of CUR_TYPE. STRING is the error + message to print in that case. Otherwise, quietly return 1. */ +static int +member_function_or_else (ctype, cur_type, string) + tree ctype, cur_type; + char *string; +{ + if (ctype && ctype != cur_type) + { + error (string, TYPE_NAME_STRING (ctype)); + return 0; + } + return 1; +} + +/* Subroutine of `grokdeclarator'. */ + +/* Generate errors possibly applicable for a given set of specifiers. + This is for ARM $7.1.2. */ +static void +bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) + tree object; + char *type; + int virtualp, quals, friendp, raises, inlinep; +{ + if (virtualp) + cp_error ("`%D' declared as a `virtual' %s", object, type); + if (inlinep) + cp_error ("`%D' declared as an `inline' %s", object, type); + if (quals) + cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", + object, type); + if (friendp) + cp_error_at ("invalid friend declaration", object); + if (raises) + cp_error_at ("invalid exception specifications", object); +} + +/* CTYPE is class type, or null if non-class. + TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE + or METHOD_TYPE. + DECLARATOR is the function's name. + VIRTUALP is truthvalue of whether the function is virtual or not. + FLAGS are to be passed through to `grokclassfn'. + QUALS are qualifiers indicating whether the function is `const' + or `volatile'. + RAISES is a list of exceptions that this function can raise. + CHECK is 1 if we must find this method in CTYPE, 0 if we should + not look, and -1 if we should not call `grokclassfn' at all. */ +static tree +grokfndecl (ctype, type, declarator, virtualp, flags, quals, + raises, attrlist, check, publicp, inlinep) + tree ctype, type; + tree declarator; + int virtualp; + enum overload_flags flags; + tree quals, raises, attrlist; + int check, publicp, inlinep; +{ + tree cname, decl; + int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; + + if (ctype) + cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL + ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); + else + cname = NULL_TREE; + + if (raises) + { + type = build_exception_variant (type, raises); + raises = TYPE_RAISES_EXCEPTIONS (type); + } + decl = build_lang_decl (FUNCTION_DECL, declarator, type); + /* propagate volatile out from type to decl */ + if (TYPE_VOLATILE (type)) + TREE_THIS_VOLATILE (decl) = 1; + + /* Should probably propagate const out from type to decl I bet (mrs). */ + if (staticp) + { + DECL_STATIC_FUNCTION_P (decl) = 1; + DECL_CONTEXT (decl) = ctype; + DECL_CLASS_CONTEXT (decl) = ctype; + } + + /* All function decls start out public; we'll fix their linkage later (at + definition or EOF) if appropriate. */ + TREE_PUBLIC (decl) = 1; + + if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) + { + if (inlinep) + error ("cannot declare `main' to be inline"); + else if (! publicp) + error ("cannot declare `main' to be static"); + inlinep = 0; + publicp = 1; + } + + if (! publicp) + DECL_C_STATIC (decl) = 1; + + if (inlinep) + DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; + + DECL_EXTERNAL (decl) = 1; + if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) + { + cp_error ("%smember function `%D' cannot have `%T' method qualifier", + (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); + quals = NULL_TREE; + } + + if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) + grok_op_properties (decl, virtualp, check < 0); + + /* Caller will do the rest of this. */ + if (check < 0) + return decl; + + if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) + { + tree tmp; + /* Just handle constructors here. We could do this + inside the following if stmt, but I think + that the code is more legible by breaking this + case out. See comments below for what each of + the following calls is supposed to do. */ + DECL_CONSTRUCTOR_P (decl) = 1; + + grokclassfn (ctype, declarator, decl, flags, quals); + if (check) + check_classfn (ctype, declarator, decl); + if (! grok_ctor_properties (ctype, decl)) + return NULL_TREE; + + if (check == 0 && ! current_function_decl) + { + /* FIXME: this should only need to look at + IDENTIFIER_GLOBAL_VALUE. */ + tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); + if (tmp == NULL_TREE) + IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; + else if (TREE_CODE (tmp) != TREE_CODE (decl)) + cp_error ("inconsistent declarations for `%D'", decl); + else + { + duplicate_decls (decl, tmp); + decl = tmp; + /* avoid creating circularities. */ + DECL_CHAIN (decl) = NULL_TREE; + } + make_decl_rtl (decl, NULL_PTR, 1); + } + } + else + { + tree tmp; + + /* Function gets the ugly name, field gets the nice one. + This call may change the type of the function (because + of default parameters)! */ + if (ctype != NULL_TREE) + grokclassfn (ctype, cname, decl, flags, quals); + + if (ctype != NULL_TREE && check) + check_classfn (ctype, cname, decl); + + if (ctype == NULL_TREE || check) + return decl; + + /* Now install the declaration of this function so that others may + find it (esp. its DECL_FRIENDLIST). Don't do this for local class + methods, though. */ + if (! current_function_decl) + { + /* FIXME: this should only need to look at + IDENTIFIER_GLOBAL_VALUE. */ + tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); + if (tmp == NULL_TREE) + IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; + else if (TREE_CODE (tmp) != TREE_CODE (decl)) + cp_error ("inconsistent declarations for `%D'", decl); + else + { + duplicate_decls (decl, tmp); + decl = tmp; + /* avoid creating circularities. */ + DECL_CHAIN (decl) = NULL_TREE; + } + + if (attrlist) + cplus_decl_attributes (decl, TREE_PURPOSE (attrlist), + TREE_VALUE (attrlist)); + make_decl_rtl (decl, NULL_PTR, 1); + } + + /* If this declaration supersedes the declaration of + a method declared virtual in the base class, then + mark this field as being virtual as well. */ + { + tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype)); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) + || flag_all_virtual == 1) + { + tmp = get_matching_virtual (base_binfo, decl, + flags == DTOR_FLAG); + if (tmp) + { + /* If this function overrides some virtual in some base + class, then the function itself is also necessarily + virtual, even if the user didn't explicitly say so. */ + DECL_VIRTUAL_P (decl) = 1; + + /* The TMP we really want is the one from the deepest + baseclass on this path, taking care not to + duplicate if we have already found it (via another + path to its virtual baseclass. */ + if (staticp) + { + cp_error ("method `%D' may not be declared static", + decl); + cp_error_at ("(since `%D' declared virtual in base class.)", + tmp); + break; + } + virtualp = 1; + + { + /* The argument types may have changed... */ + tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); + tree base_variant = TREE_TYPE (TREE_VALUE (argtypes)); + + argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))), + TREE_CHAIN (argtypes)); + /* But the return type has not. */ + type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes); + if (raises) + { + type = build_exception_variant (type, raises); + raises = TYPE_RAISES_EXCEPTIONS (type); + } + TREE_TYPE (decl) = type; + DECL_VINDEX (decl) + = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); + } + break; + } + } + } + } + if (virtualp) + { + if (DECL_VINDEX (decl) == NULL_TREE) + DECL_VINDEX (decl) = error_mark_node; + IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; + if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) + /* If this function is derived from a template, don't + make it public. This shouldn't be here, but there's + no good way to override the interface pragmas for one + function or class only. Bletch. */ + && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE + && (write_virtuals == 2 + || (write_virtuals == 3 + && CLASSTYPE_INTERFACE_KNOWN (ctype)))) + TREE_PUBLIC (decl) = 1; + } + } + return decl; +} + +static tree +grokvardecl (type, declarator, specbits, initialized, constp) + tree type; + tree declarator; + RID_BIT_TYPE specbits; + int initialized; + int constp; +{ + tree decl; + + if (TREE_CODE (type) == OFFSET_TYPE) + { + /* If you declare a static member so that it + can be initialized, the code will reach here. */ + tree basetype = TYPE_OFFSET_BASETYPE (type); + type = TREE_TYPE (type); + decl = build_lang_field_decl (VAR_DECL, declarator, type); + DECL_CONTEXT (decl) = basetype; + DECL_CLASS_CONTEXT (decl) = basetype; + DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); + } + else + decl = build_decl (VAR_DECL, declarator, type); + + DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl)); + + if (RIDBIT_SETP (RID_EXTERN, specbits)) + { + DECL_THIS_EXTERN (decl) = 1; + DECL_EXTERNAL (decl) = !initialized; + } + + /* In class context, static means one per class, + public access, and static storage. */ + if (DECL_FIELD_CONTEXT (decl) != NULL_TREE + && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) + { + TREE_PUBLIC (decl) = 1; + TREE_STATIC (decl) = 1; + DECL_EXTERNAL (decl) = 0; + } + /* At top level, either `static' or no s.c. makes a definition + (perhaps tentative), and absence of `static' makes it public. */ + else if (toplevel_bindings_p ()) + { + TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) + && (DECL_THIS_EXTERN (decl) || ! constp)); + TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); + } + /* Not at top level, only `static' makes a static definition. */ + else + { + TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); + TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); + } + return decl; +} + +/* Create a canonical pointer to member function type. */ + +tree +build_ptrmemfunc_type (type) + tree type; +{ + tree fields[4]; + tree t; + tree u; + + /* If a canonical type already exists for this type, use it. We use + this method instead of type_hash_canon, because it only does a + simple equality check on the list of field members. */ + + if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) + return t; + + push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); + + u = make_lang_type (UNION_TYPE); + IS_AGGR_TYPE (u) = 0; + fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); + fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, + delta_type_node); + finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); + TYPE_NAME (u) = NULL_TREE; + + t = make_lang_type (RECORD_TYPE); + + /* Let the front-end know this is a pointer to member function. */ + TYPE_PTRMEMFUNC_FLAG (t) = 1; + /* and not really an aggregate. */ + IS_AGGR_TYPE (t) = 0; + + fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, + delta_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, + delta_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); + finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); + + pop_obstacks (); + + /* Zap out the name so that the back-end will give us the debugging + information for this anonymous RECORD_TYPE. */ + TYPE_NAME (t) = NULL_TREE; + + TYPE_SET_PTRMEMFUNC_TYPE (type, t); + + /* Seems to be wanted. */ + CLASSTYPE_GOT_SEMICOLON (t) = 1; + return t; +} + +/* Given declspecs and a declarator, + determine the name and type of the object declared + and construct a ..._DECL node for it. + (In one case we can return a ..._TYPE node instead. + For invalid input we sometimes return 0.) + + DECLSPECS is a chain of tree_list nodes whose value fields + are the storage classes and type specifiers. + + DECL_CONTEXT says which syntactic context this declaration is in: + NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. + FUNCDEF for a function definition. Like NORMAL but a few different + error messages in each case. Return value may be zero meaning + this definition is too screwy to try to parse. + MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to + handle member functions (which have FIELD context). + Return value may be zero meaning this definition is too screwy to + try to parse. + PARM for a parameter declaration (either within a function prototype + or before a function body). Make a PARM_DECL, or return void_type_node. + CATCHPARM for a parameter declaration before a catch clause. + TYPENAME if for a typename (in a cast or sizeof). + Don't make a DECL node; just return the ..._TYPE node. + FIELD for a struct or union field; make a FIELD_DECL. + BITFIELD for a field with specified width. + INITIALIZED is 1 if the decl has an initializer. + + In the TYPENAME case, DECLARATOR is really an absolute declarator. + It may also be so in the PARM case, for a prototype where the + argument type is specified but not the name. + + This function is where the complicated C meanings of `static' + and `extern' are interpreted. + + For C++, if there is any monkey business to do, the function which + calls this one must do it, i.e., prepending instance variables, + renaming overloaded function names, etc. + + Note that for this C++, it is an error to define a method within a class + which does not belong to that class. + + Except in the case where SCOPE_REFs are implicitly known (such as + methods within a class being redundantly qualified), + declarations which involve SCOPE_REFs are returned as SCOPE_REFs + (class_name::decl_name). The caller must also deal with this. + + If a constructor or destructor is seen, and the context is FIELD, + then the type gains the attribute TREE_HAS_x. If such a declaration + is erroneous, NULL_TREE is returned. + + QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member + function, these are the qualifiers to give to the `this' pointer. + + May return void_type_node if the declarator turned out to be a friend. + See grokfield for details. */ + +enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; + +tree +grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist) + tree declspecs; + tree declarator; + enum decl_context decl_context; + int initialized; + tree raises, attrlist; +{ + RID_BIT_TYPE specbits; + int nclasses = 0; + tree spec; + tree type = NULL_TREE; + int longlong = 0; + int constp; + int volatilep; + int virtualp, explicitp, friendp, inlinep, staticp; + int explicit_int = 0; + int explicit_char = 0; + int opaque_typedef = 0; + tree typedef_decl = NULL_TREE; + char *name; + tree typedef_type = NULL_TREE; + int funcdef_flag = 0; + enum tree_code innermost_code = ERROR_MARK; + int bitfield = 0; + int size_varies = 0; + tree decl_machine_attr = NULL_TREE; + /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. + All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ + tree init = NULL_TREE; + + /* Keep track of what sort of function is being processed + so that we can warn about default return values, or explicit + return values which do not match prescribed defaults. */ + enum return_types return_type = return_normal; + + tree dname = NULL_TREE; + tree ctype = current_class_type; + tree ctor_return_type = NULL_TREE; + enum overload_flags flags = NO_SPECIAL; + tree quals = NULL_TREE; + + RIDBIT_RESET_ALL (specbits); + if (decl_context == FUNCDEF) + funcdef_flag = 1, decl_context = NORMAL; + else if (decl_context == MEMFUNCDEF) + funcdef_flag = -1, decl_context = FIELD; + else if (decl_context == BITFIELD) + bitfield = 1, decl_context = FIELD; + + if (flag_traditional && allocation_temporary_p ()) + end_temporary_allocation (); + + /* Look inside a declarator for the name being declared + and get it as a string, for an error message. */ + { + tree last = NULL_TREE; + register tree decl = declarator; + name = NULL; + + while (decl) + switch (TREE_CODE (decl)) + { + case COND_EXPR: + ctype = NULL_TREE; + decl = TREE_OPERAND (decl, 0); + break; + + case BIT_NOT_EXPR: /* for C++ destructors! */ + { + tree name = TREE_OPERAND (decl, 0); + tree rename = NULL_TREE; + + my_friendly_assert (flags == NO_SPECIAL, 152); + flags = DTOR_FLAG; + return_type = return_dtor; + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); + if (ctype == NULL_TREE) + { + if (current_class_type == NULL_TREE) + { + error ("destructors must be member functions"); + flags = NO_SPECIAL; + } + else + { + tree t = constructor_name (current_class_name); + if (t != name) + rename = t; + } + } + else + { + tree t = constructor_name (ctype); + if (t != name) + rename = t; + } + + if (rename) + { + error ("destructor `%s' must match class name `%s'", + IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (rename)); + TREE_OPERAND (decl, 0) = rename; + } + decl = name; + } + break; + + case ADDR_EXPR: /* C++ reference declaration */ + /* fall through */ + case ARRAY_REF: + case INDIRECT_REF: + ctype = NULL_TREE; + innermost_code = TREE_CODE (decl); + last = decl; + decl = TREE_OPERAND (decl, 0); + break; + + case CALL_EXPR: + if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) + { + /* This is actually a variable declaration using constructor + syntax. We need to call start_decl and cp_finish_decl so we + can get the variable initialized... */ + + if (last) + /* We need to insinuate ourselves into the declarator in place + of the CALL_EXPR. */ + TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0); + else + declarator = TREE_OPERAND (decl, 0); + + init = TREE_OPERAND (decl, 1); + + decl = start_decl (declarator, declspecs, 1, NULL_TREE); + finish_decl (decl, init, NULL_TREE); + return 0; + } + innermost_code = TREE_CODE (decl); + if (decl_context == FIELD && ctype == NULL_TREE) + ctype = current_class_type; + if (ctype + && TREE_OPERAND (decl, 0) == constructor_name_full (ctype)) + TREE_OPERAND (decl, 0) = constructor_name (ctype); + decl = TREE_OPERAND (decl, 0); + if (ctype != NULL_TREE + && decl != NULL_TREE && flags != DTOR_FLAG + && decl == constructor_name (ctype)) + { + return_type = return_ctor; + ctor_return_type = ctype; + } + ctype = NULL_TREE; + break; + + case IDENTIFIER_NODE: + dname = decl; + decl = NULL_TREE; + + if (! IDENTIFIER_OPNAME_P (dname) + /* Linux headers use '__op'. Arrgh. */ + || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname)) + name = IDENTIFIER_POINTER (dname); + else + { + if (IDENTIFIER_TYPENAME_P (dname)) + { + my_friendly_assert (flags == NO_SPECIAL, 154); + flags = TYPENAME_FLAG; + ctor_return_type = TREE_TYPE (dname); + return_type = return_conversion; + } + name = operator_name_string (dname); + } + break; + + case RECORD_TYPE: + case UNION_TYPE: + case ENUMERAL_TYPE: + /* Parse error puts this typespec where + a declarator should go. */ + error ("declarator name missing"); + dname = TYPE_NAME (decl); + if (dname && TREE_CODE (dname) == TYPE_DECL) + dname = DECL_NAME (dname); + name = dname ? IDENTIFIER_POINTER (dname) : ""; + declspecs = temp_tree_cons (NULL_TREE, decl, declspecs); + decl = NULL_TREE; + break; + + /* C++ extension */ + case SCOPE_REF: + { + /* Perform error checking, and convert class names to types. + We may call grokdeclarator multiple times for the same + tree structure, so only do the conversion once. In this + case, we have exactly what we want for `ctype'. */ + tree cname = TREE_OPERAND (decl, 0); + if (cname == NULL_TREE) + ctype = NULL_TREE; + /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */ + else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)) + || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE) + ctype = cname; + else if (! is_aggr_typedef (cname, 1)) + { + TREE_OPERAND (decl, 0) = NULL_TREE; + } + /* Must test TREE_OPERAND (decl, 1), in case user gives + us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ + else if (TREE_OPERAND (decl, 1) + && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) + { + TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname); + } + else if (ctype == NULL_TREE) + { + ctype = IDENTIFIER_TYPE_VALUE (cname); + TREE_OPERAND (decl, 0) = ctype; + } + else if (TREE_COMPLEXITY (decl) == current_class_depth) + TREE_OPERAND (decl, 0) = ctype; + else + { + if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), + ctype)) + { + cp_error ("type `%T' is not derived from type `%T'", + IDENTIFIER_TYPE_VALUE (cname), ctype); + TREE_OPERAND (decl, 0) = NULL_TREE; + } + else + { + ctype = IDENTIFIER_TYPE_VALUE (cname); + TREE_OPERAND (decl, 0) = ctype; + } + } + + if (ctype + && TREE_OPERAND (decl, 1) == constructor_name_full (ctype)) + TREE_OPERAND (decl, 1) = constructor_name (ctype); + decl = TREE_OPERAND (decl, 1); + if (ctype) + { + if (TREE_CODE (decl) == IDENTIFIER_NODE + && constructor_name (ctype) == decl) + { + return_type = return_ctor; + ctor_return_type = ctype; + } + else if (TREE_CODE (decl) == BIT_NOT_EXPR + && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE + && (constructor_name (ctype) == TREE_OPERAND (decl, 0) + || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) + { + return_type = return_dtor; + ctor_return_type = ctype; + flags = DTOR_FLAG; + decl = TREE_OPERAND (decl, 0) = constructor_name (ctype); + } + } + } + break; + + case ERROR_MARK: + decl = NULL_TREE; + break; + + default: + return 0; /* We used to do a 155 abort here. */ + } + if (name == NULL) + name = "type name"; + } + + /* A function definition's declarator must have the form of + a function declarator. */ + + if (funcdef_flag && innermost_code != CALL_EXPR) + return 0; + + if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) + && innermost_code != CALL_EXPR + && ! (ctype && declspecs == NULL_TREE)) + { + cp_error ("declaration of `%D' as non-function", dname); + return void_type_node; + } + + /* Anything declared one level down from the top level + must be one of the parameters of a function + (because the body is at least two levels down). */ + + /* This heuristic cannot be applied to C++ nodes! Fixed, however, + by not allowing C++ class definitions to specify their parameters + with xdecls (must be spec.d in the parmlist). + + Since we now wait to push a class scope until we are sure that + we are in a legitimate method context, we must set oldcname + explicitly (since current_class_name is not yet alive). + + We also want to avoid calling this a PARM if it is in a namespace. */ + + if (decl_context == NORMAL && ! namespace_bindings_p ()) + { + struct binding_level *b = current_binding_level; + current_binding_level = b->level_chain; + if (current_binding_level != 0 && toplevel_bindings_p ()) + decl_context = PARM; + current_binding_level = b; + } + + /* Look through the decl specs and record which ones appear. + Some typespecs are defined as built-in typenames. + Others, the ones that are modifiers of other types, + are represented by bits in SPECBITS: set the bits for + the modifiers that appear. Storage class keywords are also in SPECBITS. + + If there is a typedef name or a type, store the type in TYPE. + This includes builtin typedefs such as `int'. + + Set EXPLICIT_INT if the type is `int' or `char' and did not + come from a user typedef. + + Set LONGLONG if `long' is mentioned twice. + + For C++, constructors and destructors have their own fast treatment. */ + + for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) + { + register int i; + register tree id; + + /* Certain parse errors slip through. For example, + `int class;' is not caught by the parser. Try + weakly to recover here. */ + if (TREE_CODE (spec) != TREE_LIST) + return 0; + + id = TREE_VALUE (spec); + + if (TREE_CODE (id) == IDENTIFIER_NODE) + { + if (id == ridpointers[(int) RID_INT] + || id == ridpointers[(int) RID_CHAR] + || id == ridpointers[(int) RID_BOOL] + || id == ridpointers[(int) RID_WCHAR]) + { + if (type) + { + if (id == ridpointers[(int) RID_BOOL]) + error ("`bool' is now a keyword"); + else + cp_error ("extraneous `%T' ignored", id); + } + else + { + if (id == ridpointers[(int) RID_INT]) + explicit_int = 1; + else if (id == ridpointers[(int) RID_CHAR]) + explicit_char = 1; + type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); + } + goto found; + } + /* C++ aggregate types. */ + if (IDENTIFIER_HAS_TYPE_VALUE (id)) + { + if (type) + cp_error ("multiple declarations `%T' and `%T'", type, id); + else + type = IDENTIFIER_TYPE_VALUE (id); + goto found; + } + + for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) + { + if (ridpointers[i] == id) + { + if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) + { + if (pedantic && ! in_system_header) + pedwarn ("ANSI C++ does not support `long long'"); + else if (longlong) + error ("`long long long' is too long for GCC"); + else + longlong = 1; + } + else if (RIDBIT_SETP (i, specbits)) + pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); + RIDBIT_SET (i, specbits); + goto found; + } + } + } + if (type) + error ("two or more data types in declaration of `%s'", name); + else if (TREE_CODE (id) == IDENTIFIER_NODE) + { + register tree t = lookup_name (id, 1); + if (!t || TREE_CODE (t) != TYPE_DECL) + error ("`%s' fails to be a typedef or built in type", + IDENTIFIER_POINTER (id)); + else + { + type = TREE_TYPE (t); + decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); + typedef_decl = t; + } + } + else if (TREE_CODE (id) != ERROR_MARK) + /* Can't change CLASS nodes into RECORD nodes here! */ + type = id; + + found: ; + } + + typedef_type = type; + + /* No type at all: default to `int', and set EXPLICIT_INT + because it was not a user-defined typedef. + Except when we have a `typedef' inside a signature, in + which case the type defaults to `unknown type' and is + instantiated when assigning to a signature pointer or ref. */ + + if (type == NULL_TREE + && (RIDBIT_SETP (RID_SIGNED, specbits) + || RIDBIT_SETP (RID_UNSIGNED, specbits) + || RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits))) + { + /* These imply 'int'. */ + type = integer_type_node; + explicit_int = 1; + } + + if (type == NULL_TREE) + { + explicit_int = -1; + if (return_type == return_dtor) + type = void_type_node; + else if (return_type == return_ctor) + type = build_pointer_type (ctor_return_type); + else if (return_type == return_conversion) + type = ctor_return_type; + else if (current_class_type + && IS_SIGNATURE (current_class_type) + && (RIDBIT_SETP (RID_TYPEDEF, specbits) + || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + && (decl_context == FIELD || decl_context == NORMAL)) + { + explicit_int = 0; + opaque_typedef = 1; + type = copy_node (opaque_type_node); + } + /* access declaration */ + else if (decl_context == FIELD && declarator + && TREE_CODE (declarator) == SCOPE_REF) + type = void_type_node; + else + { + if (funcdef_flag) + { + if (warn_return_type + && return_type == return_normal) + /* Save warning until we know what is really going on. */ + warn_about_return_type = 1; + } + else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + pedwarn ("ANSI C++ forbids typedef which does not specify a type"); + else if (declspecs == NULL_TREE && + (innermost_code != CALL_EXPR || pedantic)) + cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class", + dname); + type = integer_type_node; + } + } + else if (return_type == return_dtor) + { + error ("return type specification for destructor invalid"); + type = void_type_node; + } + else if (return_type == return_ctor) + { + error ("return type specification for constructor invalid"); + type = build_pointer_type (ctor_return_type); + } + else if (return_type == return_conversion) + { + if (comptypes (type, ctor_return_type, 1) == 0) + cp_error ("operator `%T' declared to return `%T'", + ctor_return_type, type); + else + cp_pedwarn ("return type specified for `operator %T'", + ctor_return_type); + + type = ctor_return_type; + } + /* Catch typedefs that only specify a type, like 'typedef int;'. */ + else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE) + { + /* Template "this is a type" syntax; just ignore for now. */ + if (processing_template_defn) + return void_type_node; + } + + ctype = NULL_TREE; + + /* Now process the modifiers that were specified + and check for invalid combinations. */ + + /* Long double is a special combination. */ + + if (RIDBIT_SETP (RID_LONG, specbits) + && TYPE_MAIN_VARIANT (type) == double_type_node) + { + RIDBIT_RESET (RID_LONG, specbits); + type = build_type_variant (long_double_type_node, TYPE_READONLY (type), + TYPE_VOLATILE (type)); + } + + /* Check all other uses of type modifiers. */ + + if (RIDBIT_SETP (RID_UNSIGNED, specbits) + || RIDBIT_SETP (RID_SIGNED, specbits) + || RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits)) + { + int ok = 0; + + if (TREE_CODE (type) == REAL_TYPE) + error ("short, signed or unsigned invalid for `%s'", name); + else if (TREE_CODE (type) != INTEGER_TYPE) + error ("long, short, signed or unsigned invalid for `%s'", name); + else if (RIDBIT_SETP (RID_LONG, specbits) + && RIDBIT_SETP (RID_SHORT, specbits)) + error ("long and short specified together for `%s'", name); + else if ((RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits)) + && explicit_char) + error ("long or short specified with char for `%s'", name); + else if ((RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits)) + && TREE_CODE (type) == REAL_TYPE) + error ("long or short specified with floating type for `%s'", name); + else if (RIDBIT_SETP (RID_SIGNED, specbits) + && RIDBIT_SETP (RID_UNSIGNED, specbits)) + error ("signed and unsigned given together for `%s'", name); + else + { + ok = 1; + if (!explicit_int && !explicit_char && pedantic) + { + pedwarn ("long, short, signed or unsigned used invalidly for `%s'", + name); + if (flag_pedantic_errors) + ok = 0; + } + } + + /* Discard the type modifiers if they are invalid. */ + if (! ok) + { + RIDBIT_RESET (RID_UNSIGNED, specbits); + RIDBIT_RESET (RID_SIGNED, specbits); + RIDBIT_RESET (RID_LONG, specbits); + RIDBIT_RESET (RID_SHORT, specbits); + longlong = 0; + } + } + + /* Decide whether an integer type is signed or not. + Optionally treat bitfields as signed by default. */ + if (RIDBIT_SETP (RID_UNSIGNED, specbits) + /* Traditionally, all bitfields are unsigned. */ + || (bitfield && flag_traditional) + || (bitfield && ! flag_signed_bitfields + && (explicit_int || explicit_char + /* A typedef for plain `int' without `signed' + can be controlled just like plain `int'. */ + || ! (typedef_decl != NULL_TREE + && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) + && TREE_CODE (type) != ENUMERAL_TYPE + && RIDBIT_NOTSETP (RID_SIGNED, specbits))) + { + if (longlong) + type = long_long_unsigned_type_node; + else if (RIDBIT_SETP (RID_LONG, specbits)) + type = long_unsigned_type_node; + else if (RIDBIT_SETP (RID_SHORT, specbits)) + type = short_unsigned_type_node; + else if (type == char_type_node) + type = unsigned_char_type_node; + else if (typedef_decl) + type = unsigned_type (type); + else + type = unsigned_type_node; + } + else if (RIDBIT_SETP (RID_SIGNED, specbits) + && type == char_type_node) + type = signed_char_type_node; + else if (longlong) + type = long_long_integer_type_node; + else if (RIDBIT_SETP (RID_LONG, specbits)) + type = long_integer_type_node; + else if (RIDBIT_SETP (RID_SHORT, specbits)) + type = short_integer_type_node; + + /* Set CONSTP if this declaration is `const', whether by + explicit specification or via a typedef. + Likewise for VOLATILEP. */ + + constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); + volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); + staticp = 0; + inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); +#if 0 + /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */ + if (constp > 1) + warning ("duplicate `const'"); + if (volatilep > 1) + warning ("duplicate `volatile'"); +#endif + virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); + RIDBIT_RESET (RID_VIRTUAL, specbits); + explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; + RIDBIT_RESET (RID_EXPLICIT, specbits); + + if (RIDBIT_SETP (RID_STATIC, specbits)) + staticp = 1 + (decl_context == FIELD); + + if (virtualp && staticp == 2) + { + cp_error ("member `%D' cannot be declared both virtual and static", + dname); + staticp = 0; + } + friendp = RIDBIT_SETP (RID_FRIEND, specbits); + RIDBIT_RESET (RID_FRIEND, specbits); + + if (RIDBIT_SETP (RID_MUTABLE, specbits)) + { + if (decl_context == PARM) + { + error ("non-member `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + else if (friendp || decl_context == TYPENAME) + { + error ("non-object member `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } +#if 0 + if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + { + error ("non-object member `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + /* Because local typedefs are parsed twice, we don't want this + message here. */ + else if (decl_context != FIELD) + { + error ("non-member `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } +#endif + } + + /* Warn if two storage classes are given. Default to `auto'. */ + + if (RIDBIT_ANY_SET (specbits)) + { + if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; + if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; + if (decl_context == PARM && nclasses > 0) + error ("storage class specifiers invalid in parameter declarations"); + if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + { + if (decl_context == PARM) + error ("typedef declaration invalid in parameter declaration"); + nclasses++; + } + if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; + if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; + } + + /* Give error if `virtual' is used outside of class declaration. */ + if (virtualp + && (current_class_name == NULL_TREE || decl_context != FIELD)) + { + error ("virtual outside class declaration"); + virtualp = 0; + } + if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) + { + error ("only members can be declared mutable"); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + + /* Static anonymous unions are dealt with here. */ + if (staticp && decl_context == TYPENAME + && TREE_CODE (declspecs) == TREE_LIST + && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) + decl_context = FIELD; + + /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' + is used in a signature member function declaration. */ + if (decl_context == FIELD + && IS_SIGNATURE (current_class_type) + && RIDBIT_NOTSETP(RID_TYPEDEF, specbits) + && !SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + { + if (constp) + { + error ("`const' specified for signature member function `%s'", name); + constp = 0; + } + if (volatilep) + { + error ("`volatile' specified for signature member function `%s'", + name); + volatilep = 0; + } + if (inlinep) + { + error ("`inline' specified for signature member function `%s'", name); + /* Later, we'll make signature member functions inline. */ + inlinep = 0; + } + if (friendp) + { + error ("`friend' declaration in signature definition"); + friendp = 0; + } + if (virtualp) + { + error ("`virtual' specified for signature member function `%s'", + name); + /* Later, we'll make signature member functions virtual. */ + virtualp = 0; + } + } + + /* Warn about storage classes that are invalid for certain + kinds of declarations (parameters, typenames, etc.). */ + + if (nclasses > 1) + error ("multiple storage classes in declaration of `%s'", name); + else if (decl_context != NORMAL && nclasses > 0) + { + if ((decl_context == PARM || decl_context == CATCHPARM) + && (RIDBIT_SETP (RID_REGISTER, specbits) + || RIDBIT_SETP (RID_AUTO, specbits))) + ; + else if (decl_context == FIELD + && RIDBIT_SETP (RID_TYPEDEF, specbits)) + { + /* Processing a typedef declaration nested within a class type + definition. */ + register tree scanner; + register tree previous_declspec; + tree loc_typedecl; + + if (initialized) + error ("typedef declaration includes an initializer"); + + /* To process a class-local typedef declaration, we descend down + the chain of declspecs looking for the `typedef' spec. When + we find it, we replace it with `static', and then recursively + call `grokdeclarator' with the original declarator and with + the newly adjusted declspecs. This call should return a + FIELD_DECL node with the TREE_TYPE (and other parts) set + appropriately. We can then just change the TREE_CODE on that + from FIELD_DECL to TYPE_DECL and we're done. */ + + for (previous_declspec = NULL_TREE, scanner = declspecs; + scanner; + previous_declspec = scanner, scanner = TREE_CHAIN (scanner)) + { + if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF]) + break; + } + + if (previous_declspec) + TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner); + else + declspecs = TREE_CHAIN (scanner); + + declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC], + declspecs); + + /* In the recursive call to grokdeclarator we need to know + whether we are working on a signature-local typedef. */ + if (IS_SIGNATURE (current_class_type)) + SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1; + + loc_typedecl = + grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE); + + if (previous_declspec) + TREE_CHAIN (previous_declspec) = scanner; + + if (loc_typedecl != error_mark_node) + { + register int i = sizeof (struct lang_decl_flags) / sizeof (int); + register int *pi; + + TREE_SET_CODE (loc_typedecl, TYPE_DECL); + /* This is the same field as DECL_ARGUMENTS, which is set for + function typedefs by the above grokdeclarator. */ + DECL_NESTED_TYPENAME (loc_typedecl) = 0; + + pi = (int *) permalloc (sizeof (struct lang_decl_flags)); + while (i > 0) + pi[--i] = 0; + DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi; + } + + if (IS_SIGNATURE (current_class_type)) + { + SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0; + if (loc_typedecl != error_mark_node && opaque_typedef) + SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; + } + + return loc_typedecl; + } + else if (decl_context == FIELD + && (! IS_SIGNATURE (current_class_type) + || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + /* C++ allows static class elements */ + && RIDBIT_SETP (RID_STATIC, specbits)) + /* C++ also allows inlines and signed and unsigned elements, + but in those cases we don't come in here. */ + ; + else + { + if (decl_context == FIELD) + { + tree tmp = NULL_TREE; + register int op = 0; + + if (declarator) + { + tmp = TREE_OPERAND (declarator, 0); + op = IDENTIFIER_OPNAME_P (tmp); + } + error ("storage class specified for %s `%s'", + IS_SIGNATURE (current_class_type) + ? (op + ? "signature member operator" + : "signature member function") + : (op ? "member operator" : "field"), + op ? operator_name_string (tmp) : name); + } + else + error (((decl_context == PARM || decl_context == CATCHPARM) + ? "storage class specified for parameter `%s'" + : "storage class specified for typename"), name); + RIDBIT_RESET (RID_REGISTER, specbits); + RIDBIT_RESET (RID_AUTO, specbits); + RIDBIT_RESET (RID_EXTERN, specbits); + + if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) + { + RIDBIT_RESET (RID_STATIC, specbits); + staticp = 0; + } + } + } + else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) + { + if (toplevel_bindings_p ()) + { + /* It's common practice (and completely valid) to have a const + be initialized and declared extern. */ + if (! constp) + warning ("`%s' initialized and declared `extern'", name); + } + else + error ("`%s' has both `extern' and initializer", name); + } + else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag + && ! toplevel_bindings_p ()) + error ("nested function `%s' declared `extern'", name); + else if (toplevel_bindings_p ()) + { + if (RIDBIT_SETP (RID_AUTO, specbits)) + error ("top-level declaration of `%s' specifies `auto'", name); +#if 0 + if (RIDBIT_SETP (RID_REGISTER, specbits)) + error ("top-level declaration of `%s' specifies `register'", name); +#endif +#if 0 + /* I'm not sure under what circumstances we should turn + on the extern bit, and under what circumstances we should + warn if other bits are turned on. */ + if (decl_context == NORMAL + && RIDBIT_NOSETP (RID_EXTERN, specbits) + && ! root_lang_context_p ()) + { + RIDBIT_SET (RID_EXTERN, specbits); + } +#endif + } + + /* Now figure out the structure of the declarator proper. + Descend through it, creating more complex types, until we reach + the declared identifier (or NULL_TREE, in an absolute declarator). */ + + while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) + { + /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), + an INDIRECT_REF (for *...), + a CALL_EXPR (for ...(...)), + an identifier (for the name being declared) + or a null pointer (for the place in an absolute declarator + where the name was omitted). + For the last two cases, we have just exited the loop. + + For C++ it could also be + a SCOPE_REF (for class :: ...). In this case, we have converted + sensible names to types, and those are the values we use to + qualify the member name. + an ADDR_EXPR (for &...), + a BIT_NOT_EXPR (for destructors) + + At this point, TYPE is the type of elements of an array, + or for a function to return, or for a pointer to point to. + After this sequence of ifs, TYPE is the type of the + array or function or pointer, and DECLARATOR has had its + outermost layer removed. */ + + if (TREE_CODE (type) == ERROR_MARK) + { + if (TREE_CODE (declarator) == SCOPE_REF) + declarator = TREE_OPERAND (declarator, 1); + else + declarator = TREE_OPERAND (declarator, 0); + continue; + } + if (quals != NULL_TREE + && (declarator == NULL_TREE + || TREE_CODE (declarator) != SCOPE_REF)) + { + if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) + ctype = TYPE_METHOD_BASETYPE (type); + if (ctype != NULL_TREE) + { +#if 0 /* not yet, should get fixed properly later */ + tree dummy = make_type_decl (NULL_TREE, type); +#else + tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); +#endif + ctype = grok_method_quals (ctype, dummy, quals); + type = TREE_TYPE (dummy); + quals = NULL_TREE; + } + } + switch (TREE_CODE (declarator)) + { + case ARRAY_REF: + { + register tree itype = NULL_TREE; + register tree size = TREE_OPERAND (declarator, 1); + /* The index is a signed object `sizetype' bits wide. */ + tree index_type = signed_type (sizetype); + + declarator = TREE_OPERAND (declarator, 0); + + /* Check for some types that there cannot be arrays of. */ + + if (TYPE_MAIN_VARIANT (type) == void_type_node) + { + cp_error ("declaration of `%D' as array of voids", dname); + type = error_mark_node; + } + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + cp_error ("declaration of `%D' as array of functions", dname); + type = error_mark_node; + } + + /* ARM $8.4.3: Since you can't have a pointer to a reference, + you can't have arrays of references. If we allowed them, + then we'd be saying x[i] is valid for an array x, but + then you'd have to ask: what does `*(x + i)' mean? */ + if (TREE_CODE (type) == REFERENCE_TYPE) + { + if (decl_context == TYPENAME) + cp_error ("cannot make arrays of references"); + else + cp_error ("declaration of `%D' as array of references", + dname); + type = error_mark_node; + } + + if (TREE_CODE (type) == OFFSET_TYPE) + { + cp_error ("declaration of `%D' as array of data members", + dname); + type = error_mark_node; + } + + if (TREE_CODE (type) == METHOD_TYPE) + { + cp_error ("declaration of `%D' as array of function members", + dname); + type = error_mark_node; + } + + if (size == error_mark_node) + type = error_mark_node; + + if (type == error_mark_node) + continue; + + if (size) + { + /* Must suspend_momentary here because the index + type may need to live until the end of the function. + For example, it is used in the declaration of a + variable which requires destructing at the end of + the function; then build_vec_delete will need this + value. */ + int yes = suspend_momentary (); + /* might be a cast */ + if (TREE_CODE (size) == NOP_EXPR + && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) + size = TREE_OPERAND (size, 0); + + /* If this is a template parameter, it'll be constant, but + we don't know what the value is yet. */ + if (TREE_CODE (size) == TEMPLATE_CONST_PARM) + goto dont_grok_size; + + if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE + && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) + { + cp_error ("size of array `%D' has non-integer type", + dname); + size = integer_one_node; + } + if (TREE_READONLY_DECL_P (size)) + size = decl_constant_value (size); + if (pedantic && integer_zerop (size)) + cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); + if (TREE_CONSTANT (size)) + { + int old_flag_pedantic_errors = flag_pedantic_errors; + int old_pedantic = pedantic; + pedantic = flag_pedantic_errors = 1; + /* Always give overflow errors on array subscripts. */ + constant_expression_warning (size); + pedantic = old_pedantic; + flag_pedantic_errors = old_flag_pedantic_errors; + if (INT_CST_LT (size, integer_zero_node)) + { + cp_error ("size of array `%D' is negative", dname); + size = integer_one_node; + } + } + else + { + if (pedantic) + { + if (dname) + cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", + dname); + else + cp_pedwarn ("ANSI C++ forbids variable-size array"); + } + /* Make sure the array size remains visibly nonconstant + even if it is (eg) a const variable with known value. */ + size_varies = 1; + } + + dont_grok_size: + itype = + fold (build_binary_op (MINUS_EXPR, + convert (index_type, size), + convert (index_type, + integer_one_node), 1)); + if (! TREE_CONSTANT (itype)) + itype = variable_size (itype); + itype = build_index_type (itype); + resume_momentary (yes); + } + + /* Build the array type itself, then merge any constancy or + volatility into the target type. We must do it in this order + to ensure that the TYPE_MAIN_VARIANT field of the array type + is set correctly. */ + + type = build_cplus_array_type (type, itype); + if (constp || volatilep) + type = cp_build_type_variant (type, constp, volatilep); + + ctype = NULL_TREE; + } + break; + + case CALL_EXPR: + { + tree arg_types; + int funcdecl_p; + tree inner_parms = TREE_OPERAND (declarator, 1); + tree inner_decl = TREE_OPERAND (declarator, 0); + + /* Declaring a function type. + Make sure we have a valid type for the function to return. */ +#if 0 + /* Is this an error? Should they be merged into TYPE here? */ + if (pedantic && (constp || volatilep)) + pedwarn ("function declared to return const or volatile result"); +#else + /* Merge any constancy or volatility into the function return + type. */ + + if (constp || volatilep) + { + type = cp_build_type_variant (type, constp, volatilep); + if (IS_AGGR_TYPE (type)) + build_pointer_type (type); + constp = 0; + volatilep = 0; + } +#endif + + /* Warn about some types functions can't return. */ + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("`%s' declared as function returning a function", name); + type = integer_type_node; + } + if (TREE_CODE (type) == ARRAY_TYPE) + { + error ("`%s' declared as function returning an array", name); + type = integer_type_node; + } + + if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) + inner_decl = TREE_OPERAND (inner_decl, 1); + + /* Pick up type qualifiers which should be applied to `this'. */ + quals = TREE_OPERAND (declarator, 2); + + /* Say it's a definition only for the CALL_EXPR + closest to the identifier. */ + funcdecl_p = + inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE + || TREE_CODE (inner_decl) == BIT_NOT_EXPR); + + if (ctype == NULL_TREE + && decl_context == FIELD + && funcdecl_p + && (friendp == 0 || dname == current_class_name)) + ctype = current_class_type; + + if (ctype && return_type == return_conversion) + TYPE_HAS_CONVERSION (ctype) = 1; + if (ctype && constructor_name (ctype) == dname) + { + /* We are within a class's scope. If our declarator name + is the same as the class name, and we are defining + a function, then it is a constructor/destructor, and + therefore returns a void type. */ + + if (flags == DTOR_FLAG) + { + /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may + not be declared const or volatile. A destructor + may not be static. */ + if (staticp == 2) + error ("destructor cannot be static member function"); + if (quals) + { + error ("destructors cannot be declared `const' or `volatile'"); + return void_type_node; + } + if (decl_context == FIELD) + { + if (! member_function_or_else (ctype, current_class_type, + "destructor for alien class `%s' cannot be a member")) + return void_type_node; + } + } + else /* it's a constructor. */ + { + if (explicitp == 1) + explicitp = 2; + /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may + not be declared const or volatile. A constructor may + not be virtual. A constructor may not be static. */ + if (staticp == 2) + error ("constructor cannot be static member function"); + if (virtualp) + { + pedwarn ("constructors cannot be declared virtual"); + virtualp = 0; + } + if (quals) + { + error ("constructors cannot be declared `const' or `volatile'"); + return void_type_node; + } + { + RID_BIT_TYPE tmp_bits; + bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE)); + RIDBIT_RESET (RID_INLINE, tmp_bits); + RIDBIT_RESET (RID_STATIC, tmp_bits); + if (RIDBIT_ANY_SET (tmp_bits)) + error ("return value type specifier for constructor ignored"); + } + type = build_pointer_type (ctype); + if (decl_context == FIELD && + IS_SIGNATURE (current_class_type)) + { + error ("constructor not allowed in signature"); + return void_type_node; + } + else if (decl_context == FIELD) + { + if (! member_function_or_else (ctype, current_class_type, + "constructor for alien class `%s' cannot be member")) + return void_type_node; + TYPE_HAS_CONSTRUCTOR (ctype) = 1; + if (return_type != return_ctor) + return NULL_TREE; + } + } + if (decl_context == FIELD) + staticp = 0; + } + else if (friendp) + { + if (initialized) + error ("can't initialize friend function `%s'", name); + if (virtualp) + { + /* Cannot be both friend and virtual. */ + error ("virtual functions cannot be friends"); + RIDBIT_RESET (RID_FRIEND, specbits); + friendp = 0; + } + if (decl_context == NORMAL) + error ("friend declaration not in class definition"); + if (current_function_decl && funcdef_flag) + cp_error ("can't define friend function `%s' in a local class definition", + name); + } + + /* Traditionally, declaring return type float means double. */ + + if (flag_traditional + && TYPE_MAIN_VARIANT (type) == float_type_node) + { + type = build_type_variant (double_type_node, + TYPE_READONLY (type), + TYPE_VOLATILE (type)); + } + + /* Construct the function type and go to the next + inner layer of declarator. */ + + declarator = TREE_OPERAND (declarator, 0); + + /* FIXME: This is where default args should be fully + processed. */ + + arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); + + if (declarator) + { + /* Get past destructors, etc. + We know we have one because FLAGS will be non-zero. + + Complain about improper parameter lists here. */ + if (TREE_CODE (declarator) == BIT_NOT_EXPR) + { + declarator = TREE_OPERAND (declarator, 0); + + if (strict_prototype == 0 && arg_types == NULL_TREE) + arg_types = void_list_node; + else if (arg_types == NULL_TREE + || arg_types != void_list_node) + { + error ("destructors cannot be specified with parameters"); + arg_types = void_list_node; + } + } + } + + /* ANSI seems to say that `const int foo ();' + does not make the function foo const. */ + type = build_function_type (type, + flag_traditional ? 0 : arg_types); + } + break; + + case ADDR_EXPR: + case INDIRECT_REF: + /* Filter out pointers-to-references and references-to-references. + We can get these if a TYPE_DECL is used. */ + + if (TREE_CODE (type) == REFERENCE_TYPE) + { + error ("cannot declare %s to references", + TREE_CODE (declarator) == ADDR_EXPR + ? "references" : "pointers"); + declarator = TREE_OPERAND (declarator, 0); + continue; + } + + if (TREE_CODE (type) == OFFSET_TYPE + && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE + || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) + { + cp_error ("cannot declare pointer to `%#T' member", + TREE_TYPE (type)); + type = TREE_TYPE (type); + } + + /* Merge any constancy or volatility into the target type + for the pointer. */ + + if (constp || volatilep) + { + /* A const or volatile signature pointer/reference is + pointing to a const or volatile object, i.e., the + `optr' is const or volatile, respectively, not the + signature pointer/reference itself. */ + if (! IS_SIGNATURE (type)) + { + type = cp_build_type_variant (type, constp, volatilep); + if (IS_AGGR_TYPE (type)) + build_pointer_type (type); + constp = 0; + volatilep = 0; + } + } + + if (IS_SIGNATURE (type)) + { + if (TREE_CODE (declarator) == ADDR_EXPR) + { + if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE + && TYPE_SIZE (type)) + cp_warning ("empty signature `%T' used in signature reference declaration", + type); +#if 0 + type = build_signature_reference_type (type, + constp, volatilep); +#else + sorry ("signature reference"); + return NULL_TREE; +#endif + } + else + { + if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE + && TYPE_SIZE (type)) + cp_warning ("empty signature `%T' used in signature pointer declaration", + type); + type = build_signature_pointer_type (type, + constp, volatilep); + } + constp = 0; + volatilep = 0; + } + else if (TREE_CODE (declarator) == ADDR_EXPR) + { + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("cannot declare references to functions; use pointer to function instead"); + type = build_pointer_type (type); + } + else + { + if (TYPE_MAIN_VARIANT (type) == void_type_node) + error ("invalid type: `void &'"); + else + type = build_reference_type (type); + } + } + else if (TREE_CODE (type) == METHOD_TYPE) + { + type = build_ptrmemfunc_type (build_pointer_type (type)); + } + else + type = build_pointer_type (type); + + /* Process a list of type modifier keywords (such as + const or volatile) that were given inside the `*' or `&'. */ + + if (TREE_TYPE (declarator)) + { + register tree typemodlist; + int erred = 0; + for (typemodlist = TREE_TYPE (declarator); typemodlist; + typemodlist = TREE_CHAIN (typemodlist)) + { + if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) + constp++; + else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) + volatilep++; + else if (!erred) + { + erred = 1; + error ("invalid type modifier within %s declarator", + TREE_CODE (declarator) == ADDR_EXPR + ? "reference" : "pointer"); + } + } + if (constp > 1) + pedwarn ("duplicate `const'"); + if (volatilep > 1) + pedwarn ("duplicate `volatile'"); + if (TREE_CODE (declarator) == ADDR_EXPR + && (constp || volatilep)) + { + if (constp) + pedwarn ("discarding `const' applied to a reference"); + if (volatilep) + pedwarn ("discarding `volatile' applied to a reference"); + constp = volatilep = 0; + } + } + declarator = TREE_OPERAND (declarator, 0); + ctype = NULL_TREE; + break; + + case SCOPE_REF: + { + /* We have converted type names to NULL_TREE if the + name was bogus, or to a _TYPE node, if not. + + The variable CTYPE holds the type we will ultimately + resolve to. The code here just needs to build + up appropriate member types. */ + tree sname = TREE_OPERAND (declarator, 1); + /* Destructors can have their visibilities changed as well. */ + if (TREE_CODE (sname) == BIT_NOT_EXPR) + sname = TREE_OPERAND (sname, 0); + + if (TREE_COMPLEXITY (declarator) == 0) + /* This needs to be here, in case we are called + multiple times. */ ; + else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) + /* don't fall out into global scope. Hides real bug? --eichin */ ; + else if (TREE_COMPLEXITY (declarator) == current_class_depth) + { + /* This pop_nested_class corresponds to the + push_nested_class used to push into class scope for + parsing the argument list of a function decl, in + qualified_id. */ + pop_nested_class (1); + TREE_COMPLEXITY (declarator) = current_class_depth; + } + else + my_friendly_abort (16); + + if (TREE_OPERAND (declarator, 0) == NULL_TREE) + { + /* We had a reference to a global decl, or + perhaps we were given a non-aggregate typedef, + in which case we cleared this out, and should just + keep going as though it wasn't there. */ + declarator = sname; + continue; + } + ctype = TREE_OPERAND (declarator, 0); + + if (sname == NULL_TREE) + goto done_scoping; + + if (TREE_CODE (sname) == IDENTIFIER_NODE) + { + /* This is the `standard' use of the scoping operator: + basetype :: member . */ + + if (ctype == current_class_type) + { + /* class A { + void A::f (); + }; + + Is this ill-formed? */ + + if (pedantic) + cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", + ctype, name); + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + if (current_class_type == NULL_TREE + || friendp) + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), + TREE_TYPE (type), TYPE_ARG_TYPES (type)); + else + { + cp_error ("cannot declare member function `%T::%s' within `%T'", + ctype, name, current_class_type); + return void_type_node; + } + } + else if (TYPE_SIZE (ctype) != NULL_TREE + || (RIDBIT_SETP (RID_TYPEDEF, specbits))) + { + tree t; + /* have to move this code elsewhere in this function. + this code is used for i.e., typedef int A::M; M *pm; + + It is? How? jason 10/2/94 */ + + if (explicit_int == -1 && decl_context == FIELD + && funcdef_flag == 0) + { + /* The code in here should only be used to build + stuff that will be grokked as access decls. */ + t = lookup_field (ctype, sname, 0, 0); + if (t) + { + t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); + DECL_INITIAL (t) = init; + return t; + } + /* No such field, try member functions. */ + t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0); + if (t) + { + if (flags == DTOR_FLAG) + t = TREE_VALUE (t); + else if (CLASSTYPE_METHOD_VEC (ctype) + && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0)) + { + /* Don't include destructor with constructors. */ + t = DECL_CHAIN (TREE_VALUE (t)); + if (t == NULL_TREE) + cp_error ("`%T' does not have any constructors", + ctype); + t = build_tree_list (NULL_TREE, t); + } + t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); + DECL_INITIAL (t) = init; + return t; + } + + cp_error + ("field `%D' is not a member of structure `%T'", + sname, ctype); + } + + if (current_class_type) + { + cp_error ("cannot declare member `%T::%s' within `%T'", + ctype, name, current_class_type); + return void_type_node; + } + type = build_offset_type (ctype, type); + } + else if (uses_template_parms (ctype)) + { + enum tree_code c; + if (TREE_CODE (type) == FUNCTION_TYPE) + { + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), + TREE_TYPE (type), + TYPE_ARG_TYPES (type)); + c = FUNCTION_DECL; + } + } + else + { + cp_error ("structure `%T' not yet defined", ctype); + return error_mark_node; + } + + declarator = sname; + } + else if (TREE_CODE (sname) == SCOPE_REF) + my_friendly_abort (17); + else + { + done_scoping: + declarator = TREE_OPERAND (declarator, 1); + if (declarator && TREE_CODE (declarator) == CALL_EXPR) + /* In this case, we will deal with it later. */ + ; + else + { + if (TREE_CODE (type) == FUNCTION_TYPE) + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); + else + type = build_offset_type (ctype, type); + } + } + } + break; + + case BIT_NOT_EXPR: + declarator = TREE_OPERAND (declarator, 0); + break; + + case RECORD_TYPE: + case UNION_TYPE: + case ENUMERAL_TYPE: + declarator = NULL_TREE; + break; + + case ERROR_MARK: + declarator = NULL_TREE; + break; + + default: + my_friendly_abort (158); + } + } + + if (explicitp == 1) + { + error ("only constructors can be declared `explicit'"); + explicitp = 0; + } + + /* Now TYPE has the actual type. */ + + /* If this is declaring a typedef name, return a TYPE_DECL. */ + + if (RIDBIT_SETP (RID_MUTABLE, specbits)) + { + if (constp) + { + error ("const `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + else if (staticp) + { + error ("static `%s' cannot be declared `mutable'", name); + RIDBIT_RESET (RID_MUTABLE, specbits); + } + } + + if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + { + tree decl; + + /* Note that the grammar rejects storage classes + in typenames, fields or parameters. */ + if (constp || volatilep) + type = cp_build_type_variant (type, constp, volatilep); + + /* If the user declares "struct {...} foo" then `foo' will have + an anonymous name. Fill that name in now. Nothing can + refer to it, so nothing needs know about the name change. + The TYPE_NAME field was filled in by build_struct_xref. */ + if (type != error_mark_node + && TYPE_NAME (type) + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) + { + /* replace the anonymous name with the real name everywhere. */ + lookup_tag_reverse (type, declarator); + TYPE_IDENTIFIER (type) = declarator; + + if (TYPE_LANG_SPECIFIC (type)) + TYPE_WAS_ANONYMOUS (type) = 1; + + { + tree d = TYPE_NAME (type), c = DECL_CONTEXT (d); + + if (!c) + set_nested_typename (d, 0, declarator, type); + else if (TREE_CODE (c) == FUNCTION_DECL) + set_nested_typename (d, DECL_ASSEMBLER_NAME (c), + declarator, type); + else + set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type); + + DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); + DECL_ASSEMBLER_NAME (d) + = get_identifier (build_overload_name (type, 1, 1)); + } + } + +#if 0 /* not yet, should get fixed properly later */ + decl = make_type_decl (declarator, type); +#else + decl = build_decl (TYPE_DECL, declarator, type); +#endif + if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) + { + cp_error_at ("typedef name may not be class-qualified", decl); + return NULL_TREE; + } + else if (quals) + { + if (ctype == NULL_TREE) + { + if (TREE_CODE (type) != METHOD_TYPE) + cp_error_at ("invalid type qualifier for non-method type", decl); + else + ctype = TYPE_METHOD_BASETYPE (type); + } + if (ctype != NULL_TREE) + grok_method_quals (ctype, decl, quals); + } + + if (RIDBIT_SETP (RID_SIGNED, specbits) + || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) + C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; + + if (RIDBIT_SETP (RID_MUTABLE, specbits)) + { + error ("non-object member `%s' cannot be declared mutable", name); + } + + return decl; + } + + /* Detect the case of an array type of unspecified size + which came, as such, direct from a typedef name. + We must copy the type, so that each identifier gets + a distinct type, so that each identifier's size can be + controlled separately by its own initializer. */ + + if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE + && TYPE_DOMAIN (type) == NULL_TREE) + { + type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); + } + + /* If this is a type name (such as, in a cast or sizeof), + compute the type and return it now. */ + + if (decl_context == TYPENAME) + { + /* Note that the grammar rejects storage classes + in typenames, fields or parameters. */ + if (constp || volatilep) + if (IS_SIGNATURE (type)) + error ("`const' or `volatile' specified with signature type"); + else + type = cp_build_type_variant (type, constp, volatilep); + + /* Special case: "friend class foo" looks like a TYPENAME context. */ + if (friendp) + { + if (volatilep) + { + cp_error ("`volatile' specified for friend class declaration"); + volatilep = 0; + } + if (inlinep) + { + cp_error ("`inline' specified for friend class declaration"); + inlinep = 0; + } + + /* Only try to do this stuff if we didn't already give up. */ + if (type != integer_type_node) + { + /* A friendly class? */ + if (current_class_type) + make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); + else + error ("trying to make class `%s' a friend of global scope", + TYPE_NAME_STRING (type)); + type = void_type_node; + } + } + else if (quals) + { +#if 0 /* not yet, should get fixed properly later */ + tree dummy = make_type_decl (declarator, type); +#else + tree dummy = build_decl (TYPE_DECL, declarator, type); +#endif + if (ctype == NULL_TREE) + { + my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); + ctype = TYPE_METHOD_BASETYPE (type); + } + grok_method_quals (ctype, dummy, quals); + type = TREE_TYPE (dummy); + } + + return type; + } + else if (declarator == NULL_TREE && decl_context != PARM + && decl_context != CATCHPARM + && TREE_CODE (type) != UNION_TYPE + && ! bitfield) + { + cp_error ("abstract declarator `%T' used as declaration", type); + declarator = make_anon_name (); + } + + /* `void' at top level (not within pointer) + is allowed only in typedefs or type names. + We don't complain about parms either, but that is because + a better error message can be made later. */ + + if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) + { + if (! declarator) + error ("unnamed variable or field declared void"); + else if (TREE_CODE (declarator) == IDENTIFIER_NODE) + { + if (IDENTIFIER_OPNAME_P (declarator)) +#if 0 /* How could this happen? */ + error ("operator `%s' declared void", + operator_name_string (declarator)); +#else + my_friendly_abort (356); +#endif + else + error ("variable or field `%s' declared void", name); + } + else + error ("variable or field declared void"); + type = integer_type_node; + } + + /* Now create the decl, which may be a VAR_DECL, a PARM_DECL + or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ + + { + register tree decl; + + if (decl_context == PARM) + { + if (ctype) + error ("cannot use `::' in parameter declaration"); + + /* A parameter declared as an array of T is really a pointer to T. + One declared as a function is really a pointer to a function. + One declared as a member is really a pointer to member. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Transfer const-ness of array into that of type pointed to. */ + type = build_pointer_type + (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); + volatilep = constp = 0; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + type = build_pointer_type (type); + else if (TREE_CODE (type) == OFFSET_TYPE) + type = build_pointer_type (type); + else if (type == void_type_node && declarator) + { + error ("declaration of `%s' as void", name); + return NULL_TREE; + } + + decl = build_decl (PARM_DECL, declarator, type); + + bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, + inlinep, friendp, raises != NULL_TREE); + if (current_class_type + && IS_SIGNATURE (current_class_type)) + { + if (inlinep) + error ("parameter of signature member function declared `inline'"); + if (RIDBIT_SETP (RID_AUTO, specbits)) + error ("parameter of signature member function declared `auto'"); + if (RIDBIT_SETP (RID_REGISTER, specbits)) + error ("parameter of signature member function declared `register'"); + } + + /* Compute the type actually passed in the parmlist, + for the case where there is no prototype. + (For example, shorts and chars are passed as ints.) + When there is a prototype, this is overridden later. */ + + DECL_ARG_TYPE (decl) = type_promotes_to (type); + } + else if (decl_context == FIELD) + { + if (type == error_mark_node) + { + /* Happens when declaring arrays of sizes which + are error_mark_node, for example. */ + decl = NULL_TREE; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + { + int publicp = 0; + + if (friendp == 0) + { + if (ctype == NULL_TREE) + ctype = current_class_type; + + if (ctype == NULL_TREE) + { + cp_error ("can't make `%D' into a method -- not in a class", + declarator); + return void_type_node; + } + + /* ``A union may [ ... ] not [ have ] virtual functions.'' + ARM 9.5 */ + if (virtualp && TREE_CODE (ctype) == UNION_TYPE) + { + cp_error ("function `%D' declared virtual inside a union", + declarator); + return void_type_node; + } + + if (declarator == ansi_opname[(int) NEW_EXPR] + || declarator == ansi_opname[(int) VEC_NEW_EXPR] + || declarator == ansi_opname[(int) DELETE_EXPR] + || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) + { + if (virtualp) + { + cp_error ("`%D' cannot be declared virtual, since it is always static", + declarator); + virtualp = 0; + } + } + else if (staticp < 2) + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), + TREE_TYPE (type), TYPE_ARG_TYPES (type)); + } + + /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ + publicp = (! friendp + || RIDBIT_SETP (RID_EXTERN, specbits) + || ! (funcdef_flag < 0 || inlinep)); + decl = grokfndecl (ctype, type, declarator, + virtualp, flags, quals, raises, attrlist, + friendp ? -1 : 0, publicp, inlinep); + if (decl == NULL_TREE) + return NULL_TREE; + decl = build_decl_attribute_variant (decl, decl_machine_attr); + + if (explicitp == 2) + DECL_NONCONVERTING_P (decl) = 1; + } + else if (TREE_CODE (type) == METHOD_TYPE) + { + /* We only get here for friend declarations of + members of other classes. */ + /* All method decls are public, so tell grokfndecl to set + TREE_PUBLIC, also. */ + decl = grokfndecl (ctype, type, declarator, + virtualp, flags, quals, raises, attrlist, + friendp ? -1 : 0, 1, 0); + if (decl == NULL_TREE) + return NULL_TREE; + } + else if (TYPE_SIZE (type) == NULL_TREE && !staticp + && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) + { + if (declarator) + cp_error ("field `%D' has incomplete type", declarator); + else + cp_error ("name `%T' has incomplete type", type); + + /* If we're instantiating a template, tell them which + instantiation made the field's type be incomplete. */ + if (current_class_type + && TYPE_NAME (current_class_type) + && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type))) + && declspecs && TREE_VALUE (declspecs) + && TREE_TYPE (TREE_VALUE (declspecs)) == type) + cp_error (" in instantiation of template `%T'", + current_class_type); + + type = error_mark_node; + decl = NULL_TREE; + } + else + { + if (friendp) + { + error ("`%s' is neither function nor method; cannot be declared friend", + IDENTIFIER_POINTER (declarator)); + friendp = 0; + } + decl = NULL_TREE; + } + + if (friendp) + { + /* Friends are treated specially. */ + if (ctype == current_class_type) + warning ("member functions are implicitly friends of their class"); + else + { + tree t = NULL_TREE; + if (decl && DECL_NAME (decl)) + t = do_friend (ctype, declarator, decl, + last_function_parms, flags, quals); + if (t && funcdef_flag) + return t; + + return void_type_node; + } + } + + /* Structure field. It may not be a function, except for C++ */ + + if (decl == NULL_TREE) + { + if (initialized) + { + /* Motion 10 at San Diego: If a static const integral data + member is initialized with an integral constant + expression, the initializer may appear either in the + declaration (within the class), or in the definition, + but not both. If it appears in the class, the member is + a member constant. The file-scope definition is always + required. */ + if (staticp) + { + if (pedantic) + { + if (! constp) + cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'", + declarator); + + else if (! INTEGRAL_TYPE_P (type)) + cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type); + } + } + + /* Note that initialization of const members is prohibited + by the draft ANSI standard, though it appears to be in + common practice. 12.6.2: The argument list is used to + initialize the named nonstatic member.... This (or an + initializer list) is the only way to initialize + nonstatic const and reference members. */ + else if (pedantic || ! constp) + cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", + constp ? "const member" : "member", declarator); + } + + if (staticp || (constp && initialized)) + { + /* ANSI C++ Apr '95 wp 9.2 */ + if (staticp && declarator == current_class_name) + cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", + declarator); + + /* C++ allows static class members. + All other work for this is done by grokfield. + This VAR_DECL is built by build_lang_field_decl. + All other VAR_DECLs are built by build_decl. */ + decl = build_lang_field_decl (VAR_DECL, declarator, type); + TREE_STATIC (decl) = 1; + /* In class context, 'static' means public access. */ + TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp; + } + else + { + decl = build_lang_field_decl (FIELD_DECL, declarator, type); + if (RIDBIT_SETP (RID_MUTABLE, specbits)) + { + DECL_MUTABLE_P (decl) = 1; + RIDBIT_RESET (RID_MUTABLE, specbits); + } + } + + bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, + inlinep, friendp, raises != NULL_TREE); + } + } + else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) + { + tree original_name = declarator; + int publicp = 0; + + if (! declarator) + return NULL_TREE; + + if (RIDBIT_SETP (RID_AUTO, specbits)) + error ("storage class `auto' invalid for function `%s'", name); + else if (RIDBIT_SETP (RID_REGISTER, specbits)) + error ("storage class `register' invalid for function `%s'", name); + + /* Function declaration not at top level. + Storage classes other than `extern' are not allowed + and `extern' makes no difference. */ + if (! toplevel_bindings_p () + && ! processing_template_decl + && (RIDBIT_SETP (RID_STATIC, specbits) + || RIDBIT_SETP (RID_INLINE, specbits)) + && pedantic) + { + if (RIDBIT_SETP (RID_STATIC, specbits)) + pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); + else + pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); + } + + if (ctype == NULL_TREE) + { + if (virtualp) + { + error ("virtual non-class function `%s'", name); + virtualp = 0; + } + + if (current_lang_name == lang_name_cplusplus + && ! (IDENTIFIER_LENGTH (original_name) == 4 + && IDENTIFIER_POINTER (original_name)[0] == 'm' + && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) + && ! (IDENTIFIER_LENGTH (original_name) > 10 + && IDENTIFIER_POINTER (original_name)[0] == '_' + && IDENTIFIER_POINTER (original_name)[1] == '_' + && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) + /* Plain overloading: will not be grok'd by grokclassfn. */ + declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); + } + else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), + TREE_TYPE (type), TYPE_ARG_TYPES (type)); + + /* Record presence of `static'. In C++, `inline' implies `static'. */ + publicp = (ctype != NULL_TREE + || RIDBIT_SETP (RID_EXTERN, specbits) + || (!RIDBIT_SETP (RID_STATIC, specbits) + && !RIDBIT_SETP (RID_INLINE, specbits))); + + decl = grokfndecl (ctype, type, original_name, + virtualp, flags, quals, raises, attrlist, + processing_template_decl ? 0 : friendp ? 2 : 1, + publicp, inlinep); + if (decl == NULL_TREE) + return NULL_TREE; + + if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c) + DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); + + if (staticp == 1) + { + int illegal_static = 0; + + /* Don't allow a static member function in a class, and forbid + declaring main to be static. */ + if (TREE_CODE (type) == METHOD_TYPE) + { + cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); + illegal_static = 1; + } + else if (current_function_decl) + { + /* FIXME need arm citation */ + error ("cannot declare static function inside another function"); + illegal_static = 1; + } + + if (illegal_static) + { + staticp = 0; + RIDBIT_RESET (RID_STATIC, specbits); + } + } + } + else + { + /* It's a variable. */ + + if (decl_context == CATCHPARM) + { + if (ctype) + { + ctype = NULL_TREE; + error ("cannot use `::' in parameter declaration"); + } + + /* A parameter declared as an array of T is really a pointer to T. + One declared as a function is really a pointer to a function. + One declared as a member is really a pointer to member. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Transfer const-ness of array into that of type pointed to. */ + type = build_pointer_type + (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); + volatilep = constp = 0; + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + type = build_pointer_type (type); + else if (TREE_CODE (type) == OFFSET_TYPE) + type = build_pointer_type (type); + } + + /* An uninitialized decl with `extern' is a reference. */ + decl = grokvardecl (type, declarator, specbits, initialized, constp); + bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, + inlinep, friendp, raises != NULL_TREE); + + if (ctype) + { + DECL_CONTEXT (decl) = ctype; + if (staticp == 1) + { + cp_pedwarn ("static member `%D' re-declared as static", decl); + staticp = 0; + RIDBIT_RESET (RID_STATIC, specbits); + } + if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) + { + cp_error ("static member `%D' declared `register'", decl); + RIDBIT_RESET (RID_REGISTER, specbits); + } + if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) + { + cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", + decl); + RIDBIT_RESET (RID_EXTERN, specbits); + } + } + } + + if (RIDBIT_SETP (RID_MUTABLE, specbits)) + { + error ("`%s' cannot be declared mutable", name); + } + + /* Record `register' declaration for warnings on & + and in case doing stupid register allocation. */ + + if (RIDBIT_SETP (RID_REGISTER, specbits)) + DECL_REGISTER (decl) = 1; + + if (RIDBIT_SETP (RID_EXTERN, specbits)) + DECL_THIS_EXTERN (decl) = 1; + + if (RIDBIT_SETP (RID_STATIC, specbits)) + DECL_THIS_STATIC (decl) = 1; + + /* Record constancy and volatility. */ + + if (constp) + TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; + if (volatilep) + { + TREE_SIDE_EFFECTS (decl) = 1; + TREE_THIS_VOLATILE (decl) = 1; + } + + return decl; + } +} + +/* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. + An empty exprlist is a parmlist. An exprlist which + contains only identifiers at the global level + is a parmlist. Otherwise, it is an exprlist. */ +int +parmlist_is_exprlist (exprs) + tree exprs; +{ + if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) + return 0; + + if (toplevel_bindings_p ()) + { + /* At the global level, if these are all identifiers, + then it is a parmlist. */ + while (exprs) + { + if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) + return 1; + exprs = TREE_CHAIN (exprs); + } + return 0; + } + return 1; +} + +/* Subroutine of `grokparms'. In a fcn definition, arg types must + be complete. + + C++: also subroutine of `start_function'. */ +static void +require_complete_types_for_parms (parms) + tree parms; +{ + while (parms) + { + tree type = TREE_TYPE (parms); + if (TYPE_SIZE (type) == NULL_TREE) + { + if (DECL_NAME (parms)) + error ("parameter `%s' has incomplete type", + IDENTIFIER_POINTER (DECL_NAME (parms))); + else + error ("parameter has incomplete type"); + TREE_TYPE (parms) = error_mark_node; + } +#if 0 + /* If the arg types are incomplete in a declaration, + they must include undefined tags. + These tags can never be defined in the scope of the declaration, + so the types can never be completed, + and no call can be compiled successfully. */ + /* This is not the right behavior for C++, but not having + it is also probably wrong. */ + else + { + /* Now warn if is a pointer to an incomplete type. */ + while (TREE_CODE (type) == POINTER_TYPE + || TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + type = TYPE_MAIN_VARIANT (type); + if (TYPE_SIZE (type) == NULL_TREE) + { + if (DECL_NAME (parm) != NULL_TREE) + warning ("parameter `%s' points to incomplete type", + IDENTIFIER_POINTER (DECL_NAME (parm))); + else + warning ("parameter points to incomplete type"); + } + } +#endif + parms = TREE_CHAIN (parms); + } +} + +/* Decode the list of parameter types for a function type. + Given the list of things declared inside the parens, + return a list of types. + + The list we receive can have three kinds of elements: + an IDENTIFIER_NODE for names given without types, + a TREE_LIST node for arguments given as typespecs or names with typespecs, + or void_type_node, to mark the end of an argument list + when additional arguments are not permitted (... was not used). + + FUNCDEF_FLAG is nonzero for a function definition, 0 for + a mere declaration. A nonempty identifier-list gets an error message + when FUNCDEF_FLAG is zero. + If FUNCDEF_FLAG is 1, then parameter types must be complete. + If FUNCDEF_FLAG is -1, then parameter types may be incomplete. + + If all elements of the input list contain types, + we return a list of the types. + If all elements contain no type (except perhaps a void_type_node + at the end), we return a null list. + If some have types and some do not, it is an error, and we + return a null list. + + Also set last_function_parms to either + a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. + A list of names is converted to a chain of PARM_DECLs + by store_parm_decls so that ultimately it is always a chain of decls. + + Note that in C++, parameters can take default values. These default + values are in the TREE_PURPOSE field of the TREE_LIST. It is + an error to specify default values which are followed by parameters + that have no default values, or an ELLIPSES. For simplicities sake, + only parameters which are specified with their types can take on + default values. */ + +static tree +grokparms (first_parm, funcdef_flag) + tree first_parm; + int funcdef_flag; +{ + tree result = NULL_TREE; + tree decls = NULL_TREE; + + if (first_parm != NULL_TREE + && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) + { + if (! funcdef_flag) + pedwarn ("parameter names (without types) in function declaration"); + last_function_parms = first_parm; + return NULL_TREE; + } + else if (first_parm != NULL_TREE + && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST + && TREE_VALUE (first_parm) != void_type_node) + my_friendly_abort (145); + else + { + /* Types were specified. This is a list of declarators + each represented as a TREE_LIST node. */ + register tree parm, chain; + int any_init = 0, any_error = 0, saw_void = 0; + + if (first_parm != NULL_TREE) + { + tree last_result = NULL_TREE; + tree last_decl = NULL_TREE; + + for (parm = first_parm; parm != NULL_TREE; parm = chain) + { + tree type, list_node = parm; + register tree decl = TREE_VALUE (parm); + tree init = TREE_PURPOSE (parm); + + chain = TREE_CHAIN (parm); + /* @@ weak defense against parse errors. */ + if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) + { + /* Give various messages as the need arises. */ + if (TREE_CODE (decl) == STRING_CST) + error ("invalid string constant `%s'", + TREE_STRING_POINTER (decl)); + else if (TREE_CODE (decl) == INTEGER_CST) + error ("invalid integer constant in parameter list, did you forget to give parameter name?"); + continue; + } + + if (decl != void_type_node) + { + /* @@ May need to fetch out a `raises' here. */ + decl = grokdeclarator (TREE_VALUE (decl), + TREE_PURPOSE (decl), + PARM, init != NULL_TREE, + NULL_TREE, NULL_TREE); + if (! decl) + continue; + type = TREE_TYPE (decl); + if (TYPE_MAIN_VARIANT (type) == void_type_node) + decl = void_type_node; + else if (TREE_CODE (type) == METHOD_TYPE) + { + if (DECL_NAME (decl)) + /* Cannot use `error_with_decl' here because + we don't have DECL_CONTEXT set up yet. */ + error ("parameter `%s' invalidly declared method type", + IDENTIFIER_POINTER (DECL_NAME (decl))); + else + error ("parameter invalidly declared method type"); + type = build_pointer_type (type); + TREE_TYPE (decl) = type; + } + else if (TREE_CODE (type) == OFFSET_TYPE) + { + if (DECL_NAME (decl)) + error ("parameter `%s' invalidly declared offset type", + IDENTIFIER_POINTER (DECL_NAME (decl))); + else + error ("parameter invalidly declared offset type"); + type = build_pointer_type (type); + TREE_TYPE (decl) = type; + } + else if (TREE_CODE (type) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_ABSTRACT_VIRTUALS (type)) + { + abstract_virtuals_error (decl, type); + any_error = 1; /* seems like a good idea */ + } + else if (TREE_CODE (type) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (type) + && IS_SIGNATURE (type)) + { + signature_error (decl, type); + any_error = 1; /* seems like a good idea */ + } + } + + if (decl == void_type_node) + { + if (result == NULL_TREE) + { + result = void_list_node; + last_result = result; + } + else + { + TREE_CHAIN (last_result) = void_list_node; + last_result = void_list_node; + } + saw_void = 1; + if (chain + && (chain != void_list_node || TREE_CHAIN (chain))) + error ("`void' in parameter list must be entire list"); + break; + } + + /* Since there is a prototype, args are passed in their own types. */ + DECL_ARG_TYPE (decl) = TREE_TYPE (decl); +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (decl) = integer_type_node; +#endif + if (!any_error) + { + if (init) + { + any_init++; + if (TREE_CODE (init) == SAVE_EXPR) + PARM_DECL_EXPR (init) = 1; + else if (TREE_CODE (init) == VAR_DECL + || TREE_CODE (init) == PARM_DECL) + { + if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) + { + /* ``Local variables may not be used in default + argument expressions.'' dpANSI C++ 8.2.6 */ + /* If extern int i; within a function is not + considered a local variable, then this code is + wrong. */ + cp_error ("local variable `%D' may not be used as a default argument", init); + any_error = 1; + } + else if (TREE_READONLY_DECL_P (init)) + init = decl_constant_value (init); + } + else + init = require_instantiated_type (type, init, integer_zero_node); + } +#if 0 /* This is too early to check; trailing parms might be merged in by + duplicate_decls. */ + else if (any_init) + { + error ("all trailing parameters must have default arguments"); + any_error = 1; + } +#endif + } + else + init = NULL_TREE; + + if (decls == NULL_TREE) + { + decls = decl; + last_decl = decls; + } + else + { + TREE_CHAIN (last_decl) = decl; + last_decl = decl; + } + if (TREE_PERMANENT (list_node)) + { + TREE_PURPOSE (list_node) = init; + TREE_VALUE (list_node) = type; + TREE_CHAIN (list_node) = NULL_TREE; + } + else + list_node = saveable_tree_cons (init, type, NULL_TREE); + if (result == NULL_TREE) + { + result = list_node; + last_result = result; + } + else + { + TREE_CHAIN (last_result) = list_node; + last_result = list_node; + } + } + if (last_result) + TREE_CHAIN (last_result) = NULL_TREE; + /* If there are no parameters, and the function does not end + with `...', then last_decl will be NULL_TREE. */ + if (last_decl != NULL_TREE) + TREE_CHAIN (last_decl) = NULL_TREE; + } + } + + last_function_parms = decls; + + /* In a fcn definition, arg types must be complete. */ + if (funcdef_flag > 0) + require_complete_types_for_parms (last_function_parms); + + return result; +} + +/* These memoizing functions keep track of special properties which + a class may have. `grok_ctor_properties' notices whether a class + has a constructor of the form X(X&), and also complains + if the class has a constructor of the form X(X). + `grok_op_properties' takes notice of the various forms of + operator= which are defined, as well as what sorts of type conversion + may apply. Both functions take a FUNCTION_DECL as an argument. */ +int +grok_ctor_properties (ctype, decl) + tree ctype, decl; +{ + tree parmtypes = FUNCTION_ARG_CHAIN (decl); + tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; + + /* When a type has virtual baseclasses, a magical first int argument is + added to any ctor so we can tell if the class has been initialized + yet. This could screw things up in this function, so we deliberately + ignore the leading int if we're in that situation. */ + if (parmtypes + && TREE_VALUE (parmtypes) == integer_type_node + && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) + { + parmtypes = TREE_CHAIN (parmtypes); + parmtype = TREE_VALUE (parmtypes); + } + + if (TREE_CODE (parmtype) == REFERENCE_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) + { + if (TREE_CHAIN (parmtypes) == NULL_TREE + || TREE_CHAIN (parmtypes) == void_list_node + || TREE_PURPOSE (TREE_CHAIN (parmtypes))) + { + TYPE_HAS_INIT_REF (ctype) = 1; + if (TYPE_READONLY (TREE_TYPE (parmtype))) + TYPE_HAS_CONST_INIT_REF (ctype) = 1; + } + else + TYPE_GETS_INIT_AGGR (ctype) = 1; + } + else if (TYPE_MAIN_VARIANT (parmtype) == ctype) + { + if (TREE_CHAIN (parmtypes) != NULL_TREE + && TREE_CHAIN (parmtypes) == void_list_node) + { + cp_error ("invalid constructor; you probably meant `%T (%T&)'", + ctype, ctype); + SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); + + return 0; + } + else + TYPE_GETS_INIT_AGGR (ctype) = 1; + } + else if (TREE_CODE (parmtype) == VOID_TYPE + || TREE_PURPOSE (parmtypes) != NULL_TREE) + TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; + + return 1; +} + +/* An operator with this name can be either unary or binary. */ +static int +ambi_op_p (name) + tree name; +{ + return (name == ansi_opname [(int) INDIRECT_REF] + || name == ansi_opname [(int) ADDR_EXPR] + || name == ansi_opname [(int) NEGATE_EXPR] + || name == ansi_opname[(int) POSTINCREMENT_EXPR] + || name == ansi_opname[(int) POSTDECREMENT_EXPR] + || name == ansi_opname [(int) CONVERT_EXPR]); +} + +/* An operator with this name can only be unary. */ +static int +unary_op_p (name) + tree name; +{ + return (name == ansi_opname [(int) TRUTH_NOT_EXPR] + || name == ansi_opname [(int) BIT_NOT_EXPR] + || name == ansi_opname [(int) COMPONENT_REF] + || OPERATOR_TYPENAME_P (name)); +} + +/* Do a little sanity-checking on how they declared their operator. */ +static void +grok_op_properties (decl, virtualp, friendp) + tree decl; + int virtualp, friendp; +{ + tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); + int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); + tree name = DECL_NAME (decl); + + if (current_class_type == NULL_TREE) + friendp = 1; + + if (! friendp) + { + if (name == ansi_opname[(int) MODIFY_EXPR]) + TYPE_HAS_ASSIGNMENT (current_class_type) = 1; + else if (name == ansi_opname[(int) CALL_EXPR]) + TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; + else if (name == ansi_opname[(int) ARRAY_REF]) + TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; + else if (name == ansi_opname[(int) COMPONENT_REF] + || name == ansi_opname[(int) MEMBER_REF]) + TYPE_OVERLOADS_ARROW (current_class_type) = 1; + else if (name == ansi_opname[(int) NEW_EXPR]) + TYPE_GETS_NEW (current_class_type) |= 1; + else if (name == ansi_opname[(int) DELETE_EXPR]) + TYPE_GETS_DELETE (current_class_type) |= 1; + else if (name == ansi_opname[(int) VEC_NEW_EXPR]) + TYPE_GETS_NEW (current_class_type) |= 2; + else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) + TYPE_GETS_DELETE (current_class_type) |= 2; + } + + if (name == ansi_opname[(int) NEW_EXPR] + || name == ansi_opname[(int) VEC_NEW_EXPR]) + { + /* When the compiler encounters the definition of A::operator new, it + doesn't look at the class declaration to find out if it's static. */ + if (methodp) + revert_static_member_fn (&decl, NULL, NULL); + + /* Take care of function decl if we had syntax errors. */ + if (argtypes == NULL_TREE) + TREE_TYPE (decl) = + build_function_type (ptr_type_node, + hash_tree_chain (integer_type_node, + void_list_node)); + else + TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); + } + else if (name == ansi_opname[(int) DELETE_EXPR] + || name == ansi_opname[(int) VEC_DELETE_EXPR]) + { + if (methodp) + revert_static_member_fn (&decl, NULL, NULL); + + if (argtypes == NULL_TREE) + TREE_TYPE (decl) = + build_function_type (void_type_node, + hash_tree_chain (ptr_type_node, + void_list_node)); + else + { + TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); + + if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] + && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) + != void_list_node)) + TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; + } + } + else + { + /* An operator function must either be a non-static member function + or have at least one parameter of a class, a reference to a class, + an enumeration, or a reference to an enumeration. 13.4.0.6 */ + if (! methodp || DECL_STATIC_FUNCTION_P (decl)) + { + if (OPERATOR_TYPENAME_P (name) + || name == ansi_opname[(int) CALL_EXPR] + || name == ansi_opname[(int) MODIFY_EXPR] + || name == ansi_opname[(int) COMPONENT_REF] + || name == ansi_opname[(int) ARRAY_REF]) + cp_error ("`%D' must be a nonstatic member function", decl); + else + { + tree p = argtypes; + + if (DECL_STATIC_FUNCTION_P (decl)) + cp_error ("`%D' must be either a non-static member function or a non-member function", decl); + + if (p) + for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) + { + tree arg = TREE_VALUE (p); + if (TREE_CODE (arg) == REFERENCE_TYPE) + arg = TREE_TYPE (arg); + + /* This lets bad template code slip through. */ + if (IS_AGGR_TYPE (arg) + || TREE_CODE (arg) == ENUMERAL_TYPE + || TREE_CODE (arg) == TEMPLATE_TYPE_PARM) + goto foundaggr; + } + cp_error + ("`%D' must have an argument of class or enumerated type", + decl); + foundaggr: + ; + } + } + + if (name == ansi_opname[(int) CALL_EXPR] + || name == ansi_opname[(int) METHOD_CALL_EXPR]) + return; /* no restrictions on args */ + + if (IDENTIFIER_TYPENAME_P (name)) + { + tree t = TREE_TYPE (name); + if (TREE_CODE (t) == VOID_TYPE) + pedwarn ("void is not a valid type conversion operator"); + else if (! friendp) + { + int ref = (TREE_CODE (t) == REFERENCE_TYPE); + char *what = 0; + if (ref) + t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); + + if (t == current_class_type) + what = "the same type"; + else if (IS_AGGR_TYPE (t) + && DERIVED_FROM_P (t, current_class_type)) + what = "a base class"; + + if (what) + warning ("conversion to %s%s will never use a type conversion operator", + ref ? "a reference to " : "", what); + } + } + + if (name == ansi_opname[(int) MODIFY_EXPR]) + { + tree parmtype; + + if (list_length (argtypes) != 3 && methodp) + { + cp_error ("`%D' must take exactly one argument", decl); + return; + } + parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); + + if (copy_assignment_arg_p (parmtype, virtualp) + && ! friendp) + { + TYPE_HAS_ASSIGN_REF (current_class_type) = 1; + if (TREE_CODE (parmtype) != REFERENCE_TYPE + || TYPE_READONLY (TREE_TYPE (parmtype))) + TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; +#if 0 /* Too soon; done in grok_function_init */ + if (DECL_ABSTRACT_VIRTUAL_P (decl)) + TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; +#endif + } + } + else if (name == ansi_opname[(int) COND_EXPR]) + { + /* 13.4.0.3 */ + pedwarn ("ANSI C++ prohibits overloading operator ?:"); + if (list_length (argtypes) != 4) + cp_error ("`%D' must take exactly three arguments", decl); + } + else if (ambi_op_p (name)) + { + if (list_length (argtypes) == 2) + /* prefix */; + else if (list_length (argtypes) == 3) + { + if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] + || name == ansi_opname[(int) POSTDECREMENT_EXPR]) + && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) + { + if (methodp) + cp_error ("postfix `%D' must take `int' as its argument", + decl); + else + cp_error + ("postfix `%D' must take `int' as its second argument", + decl); + } + } + else + { + if (methodp) + cp_error ("`%D' must take either zero or one argument", decl); + else + cp_error ("`%D' must take either one or two arguments", decl); + } + } + else if (unary_op_p (name)) + { + if (list_length (argtypes) != 2) + { + if (methodp) + cp_error ("`%D' must take `void'", decl); + else + cp_error ("`%D' must take exactly one argument", decl); + } + } + else /* if (binary_op_p (name)) */ + { + if (list_length (argtypes) != 3) + { + if (methodp) + cp_error ("`%D' must take exactly one argument", decl); + else + cp_error ("`%D' must take exactly two arguments", decl); + } + } + + /* 13.4.0.8 */ + if (argtypes) + for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) + if (TREE_PURPOSE (argtypes)) + { + TREE_PURPOSE (argtypes) = NULL_TREE; + if (name == ansi_opname[(int) POSTINCREMENT_EXPR] + || name == ansi_opname[(int) POSTDECREMENT_EXPR]) + { + if (pedantic) + cp_pedwarn ("`%D' cannot have default arguments", decl); + } + else + cp_error ("`%D' cannot have default arguments", decl); + } + } +} + +/* Get the struct, enum or union (CODE says which) with tag NAME. + Define the tag as a forward-reference if it is not defined. + + C++: If a class derivation is given, process it here, and report + an error if multiple derivation declarations are not identical. + + If this is a definition, come in through xref_tag and only look in + the current frame for the name (since C++ allows new names in any + scope.) */ + +tree +xref_tag (code_type_node, name, binfo, globalize) + tree code_type_node; + tree name, binfo; + int globalize; +{ + enum tag_types tag_code; + enum tree_code code; + int temp = 0; + int i; + register tree ref, t; + struct binding_level *b = inner_binding_level; + + tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); + switch (tag_code) + { + case record_type: + case class_type: + case signature_type: + code = RECORD_TYPE; + break; + case union_type: + code = UNION_TYPE; + break; + case enum_type: + code = ENUMERAL_TYPE; + break; + default: + my_friendly_abort (18); + } + + /* If a cross reference is requested, look up the type + already defined for this tag and return it. */ + t = IDENTIFIER_TYPE_VALUE (name); + if (t && TREE_CODE (t) != code) + t = NULL_TREE; + + if (! globalize) + { + /* If we know we are defining this tag, only look it up in this scope + * and don't try to find it as a type. */ + if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name)) + ref = t; + else + ref = lookup_tag (code, name, b, 1); + } + else + { + if (t) + ref = t; + else + ref = lookup_tag (code, name, b, 0); + + if (! ref) + { + /* Try finding it as a type declaration. If that wins, use it. */ + ref = lookup_name (name, 1); + if (ref && TREE_CODE (ref) == TYPE_DECL + && TREE_CODE (TREE_TYPE (ref)) == code) + ref = TREE_TYPE (ref); + else + ref = NULL_TREE; + } + } + + push_obstacks_nochange (); + + if (! ref) + { + /* If no such tag is yet defined, create a forward-reference node + and record it as the "definition". + When a real declaration of this type is found, + the forward-reference will be altered into a real type. */ + + /* In C++, since these migrate into the global scope, we must + build them on the permanent obstack. */ + + temp = allocation_temporary_p (); + if (temp) + end_temporary_allocation (); + + if (code == ENUMERAL_TYPE) + { + ref = make_node (ENUMERAL_TYPE); + + /* Give the type a default layout like unsigned int + to avoid crashing if it does not get defined. */ + TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); + TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); + TREE_UNSIGNED (ref) = 1; + TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); + TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); + TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); + + /* Enable us to recognize when a type is created in class context. + To do nested classes correctly, this should probably be cleared + out when we leave this classes scope. Currently this in only + done in `start_enum'. */ + + pushtag (name, ref, globalize); + if (flag_cadillac) + cadillac_start_enum (ref); + } + else + { + struct binding_level *old_b = class_binding_level; + + ref = make_lang_type (code); + + if (tag_code == signature_type) + { + SET_SIGNATURE (ref); + /* Since a signature type will be turned into the type + of signature tables, it's not only an interface. */ + CLASSTYPE_INTERFACE_ONLY (ref) = 0; + SET_CLASSTYPE_INTERFACE_KNOWN (ref); + /* A signature doesn't have a vtable. */ + CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; + } + +#ifdef NONNESTED_CLASSES + /* Class types don't nest the way enums do. */ + class_binding_level = (struct binding_level *)0; +#endif + pushtag (name, ref, globalize); + class_binding_level = old_b; + + if (flag_cadillac) + cadillac_start_struct (ref); + } + } + else + { + /* If it no longer looks like a nested type, make sure it's + in global scope. */ + if (b == global_binding_level && !class_binding_level + && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) + IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); + +#if 0 + if (binfo) + { + tree tt1 = binfo; + tree tt2 = TYPE_BINFO_BASETYPES (ref); + + if (TYPE_BINFO_BASETYPES (ref)) + for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1)) + if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i)))) + { + cp_error ("redeclaration of derivation chain of type `%#T'", + ref); + break; + } + + if (tt1 == NULL_TREE) + /* The user told us something we already knew. */ + goto just_return; + + /* In C++, since these migrate into the global scope, we must + build them on the permanent obstack. */ + end_temporary_allocation (); + } +#endif + } + + if (binfo) + xref_basetypes (code_type_node, name, ref, binfo); + + just_return: + + /* Until the type is defined, tentatively accept whatever + structure tag the user hands us. */ + if (TYPE_SIZE (ref) == NULL_TREE + && ref != current_class_type + /* Have to check this, in case we have contradictory tag info. */ + && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) + { + if (tag_code == class_type) + CLASSTYPE_DECLARED_CLASS (ref) = 1; + else if (tag_code == record_type || tag_code == signature_type) + CLASSTYPE_DECLARED_CLASS (ref) = 0; + } + + pop_obstacks (); + + return ref; +} + +void +xref_basetypes (code_type_node, name, ref, binfo) + tree code_type_node; + tree name, ref; + tree binfo; +{ + /* In the declaration `A : X, Y, ... Z' we mark all the types + (A, X, Y, ..., Z) so we can check for duplicates. */ + tree binfos; + int i, len; + enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); + + if (tag_code == union_type) + { + cp_error ("derived union `%T' invalid", ref); + return; + } + + len = list_length (binfo); + push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); + + SET_CLASSTYPE_MARKED (ref); + BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); + + for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) + { + /* The base of a derived struct is public by default. */ + int via_public + = (TREE_PURPOSE (binfo) == (tree)access_public + || TREE_PURPOSE (binfo) == (tree)access_public_virtual + || (tag_code != class_type + && (TREE_PURPOSE (binfo) == (tree)access_default + || TREE_PURPOSE (binfo) == (tree)access_default_virtual))); + int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected; + int via_virtual + = (TREE_PURPOSE (binfo) == (tree)access_private_virtual + || TREE_PURPOSE (binfo) == (tree)access_public_virtual + || TREE_PURPOSE (binfo) == (tree)access_default_virtual); + tree basetype = TREE_TYPE (TREE_VALUE (binfo)); + tree base_binfo; + + GNU_xref_hier (IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (TREE_VALUE (binfo)), + via_public, via_virtual, 0); + + if (basetype && TREE_CODE (basetype) == TYPE_DECL) + basetype = TREE_TYPE (basetype); + if (!basetype || TREE_CODE (basetype) != RECORD_TYPE) + { + cp_error ("base type `%T' fails to be a struct or class type", + TREE_VALUE (binfo)); + continue; + } +#if 1 + /* This code replaces similar code in layout_basetypes. */ + else if (TYPE_INCOMPLETE (basetype)) + { + cp_error ("base class `%T' has incomplete type", basetype); + continue; + } +#endif + else + { + if (CLASSTYPE_MARKED (basetype)) + { + if (basetype == ref) + cp_error ("recursive type `%T' undefined", basetype); + else + cp_error ("duplicate base type `%T' invalid", basetype); + continue; + } + + /* Note that the BINFO records which describe individual + inheritances are *not* shared in the lattice! They + cannot be shared because a given baseclass may be + inherited with different `accessibility' by different + derived classes. (Each BINFO record describing an + individual inheritance contains flags which say what + the `accessibility' of that particular inheritance is.) */ + + base_binfo = make_binfo (integer_zero_node, basetype, + TYPE_BINFO_VTABLE (basetype), + TYPE_BINFO_VIRTUALS (basetype), NULL_TREE); + + TREE_VEC_ELT (binfos, i) = base_binfo; + TREE_VIA_PUBLIC (base_binfo) = via_public; + TREE_VIA_PROTECTED (base_binfo) = via_protected; + TREE_VIA_VIRTUAL (base_binfo) = via_virtual; + BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); + + SET_CLASSTYPE_MARKED (basetype); +#if 0 + /* XYZZY TEST VIRTUAL BASECLASSES */ + if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE + && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) + && via_virtual == 0) + { + warning ("making type `%s' a virtual baseclass", + TYPE_NAME_STRING (basetype)); + via_virtual = 1; + } +#endif + /* We are free to modify these bits because they are meaningless + at top level, and BASETYPE is a top-level type. */ + if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) + { + TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; + TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; + } + + TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); + TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); + TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); + CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); + i += 1; + } + } + if (i) + TREE_VEC_LENGTH (binfos) = i; + else + BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; + + if (i > 1) + TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; + else if (i == 1) + TYPE_USES_MULTIPLE_INHERITANCE (ref) + = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); + if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) + TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; + + /* Unmark all the types. */ + while (--i >= 0) + CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); + CLEAR_CLASSTYPE_MARKED (ref); + + pop_obstacks (); +} + + +static tree current_local_enum = NULL_TREE; + +/* Begin compiling the definition of an enumeration type. + NAME is its name (or null if anonymous). + Returns the type object, as yet incomplete. + Also records info about it so that build_enumerator + may be used to declare the individual values as they are read. */ + +tree +start_enum (name) + tree name; +{ + register tree enumtype = NULL_TREE; + struct binding_level *b = inner_binding_level; + + /* If this is the real definition for a previous forward reference, + fill in the contents in the same object that used to be the + forward reference. */ + + if (name != NULL_TREE) + enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); + + if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) + cp_error ("multiple definition of enum `%T'", enumtype); + else + { + enumtype = make_node (ENUMERAL_TYPE); + pushtag (name, enumtype, 0); + } + + if (current_class_type) + TREE_ADDRESSABLE (b->tags) = 1; + current_local_enum = NULL_TREE; + +#if 0 /* This stuff gets cleared in finish_enum anyway. */ + if (TYPE_VALUES (enumtype) != NULL_TREE) + /* Completely replace its old definition. + The old enumerators remain defined, however. */ + TYPE_VALUES (enumtype) = NULL_TREE; + + /* Initially, set up this enum as like `int' + so that we can create the enumerators' declarations and values. + Later on, the precision of the type may be changed and + it may be laid out again. */ + + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + TYPE_SIZE (enumtype) = NULL_TREE; + fixup_signed_type (enumtype); +#endif + + /* We copy this value because enumerated type constants + are really of the type of the enumerator, not integer_type_node. */ + enum_next_value = copy_node (integer_zero_node); + enum_overflow = 0; + + GNU_xref_decl (current_function_decl, enumtype); + return enumtype; +} + +/* After processing and defining all the values of an enumeration type, + install their decls in the enumeration type and finish it off. + ENUMTYPE is the type object and VALUES a list of name-value pairs. + Returns ENUMTYPE. */ + +tree +finish_enum (enumtype, values) + register tree enumtype, values; +{ + register tree minnode, maxnode; + /* Calculate the maximum value of any enumerator in this type. */ + + if (values) + { + register tree pair; + register tree value = DECL_INITIAL (TREE_VALUE (values)); + + /* Speed up the main loop by performing some precalculations */ + TREE_TYPE (TREE_VALUE (values)) = enumtype; + TREE_TYPE (value) = enumtype; + TREE_VALUE (values) = value; + minnode = maxnode = value; + + for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) + { + value = DECL_INITIAL (TREE_VALUE (pair)); + TREE_TYPE (TREE_VALUE (pair)) = enumtype; + TREE_TYPE (value) = enumtype; + TREE_VALUE (pair) = value; + if (tree_int_cst_lt (maxnode, value)) + maxnode = value; + else if (tree_int_cst_lt (value, minnode)) + minnode = value; + } + } + else + maxnode = minnode = integer_zero_node; + + TYPE_VALUES (enumtype) = values; + + { + int unsignedp = tree_int_cst_sgn (minnode) >= 0; + int lowprec = min_precision (minnode, unsignedp); + int highprec = min_precision (maxnode, unsignedp); + int precision = MAX (lowprec, highprec); + + TYPE_SIZE (enumtype) = NULL_TREE; + + /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ + + TYPE_PRECISION (enumtype) = precision; + if (unsignedp) + fixup_unsigned_type (enumtype); + else + fixup_signed_type (enumtype); + + if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node)) + /* Use the width of the narrowest normal C type which is wide enough. */ + TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size + (precision, 1)); + else + TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); + + TYPE_SIZE (enumtype) = 0; + layout_type (enumtype); + } + + if (flag_cadillac) + cadillac_finish_enum (enumtype); + + { + register tree tem; + + /* Fix up all variant types of this enum type. */ + for (tem = TYPE_MAIN_VARIANT (enumtype); tem; + tem = TYPE_NEXT_VARIANT (tem)) + { + TYPE_VALUES (tem) = TYPE_VALUES (enumtype); + TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); + TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); + TYPE_SIZE (tem) = TYPE_SIZE (enumtype); + TYPE_MODE (tem) = TYPE_MODE (enumtype); + TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); + TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); + TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); + } + } + + /* Finish debugging output for this type. */ +#if 0 + /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging + information should *not* be generated? I think not. */ + if (! DECL_IGNORED_P (TYPE_NAME (enumtype))) +#endif + rest_of_type_compilation (enumtype, global_bindings_p ()); + + return enumtype; +} + +/* Build and install a CONST_DECL for one value of the + current enumeration type (one that was begun with start_enum). + Return a tree-list containing the name and its value. + Assignment of sequential values by default is handled here. */ + +tree +build_enumerator (name, value) + tree name, value; +{ + tree decl, result; + /* Change this to zero if we find VALUE is not shareable. */ + int shareable = 1; + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); + + /* Validate and default VALUE. */ + if (value != NULL_TREE) + { + if (TREE_READONLY_DECL_P (value)) + { + value = decl_constant_value (value); + shareable = 0; + } + + if (TREE_CODE (value) == INTEGER_CST) + { + value = default_conversion (value); + constant_expression_warning (value); + } + else + { + cp_error ("enumerator value for `%D' not integer constant", name); + value = NULL_TREE; + } + } + + /* The order of things is reversed here so that we + can check for possible sharing of enum values, + to keep that from happening. */ + /* Default based on previous value. */ + if (value == NULL_TREE) + { + value = enum_next_value; + if (enum_overflow) + cp_error ("overflow in enumeration values at `%D'", name); + } + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); + + /* Make up for hacks in lex.c. */ + if (value == integer_zero_node) + value = build_int_2 (0, 0); + else if (value == integer_one_node) + value = build_int_2 (1, 0); + else if (TREE_CODE (value) == INTEGER_CST + && (shareable == 0 + || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)) + { + value = copy_node (value); + TREE_TYPE (value) = integer_type_node; + } + + /* C++ associates enums with global, function, or class declarations. */ + + decl = current_scope (); + if (decl && decl == current_class_type) + { + /* This enum declaration is local to the class, so we must put + it in that class's list of decls. */ + decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); + DECL_INITIAL (decl) = value; + TREE_READONLY (decl) = 1; + pushdecl_class_level (decl); + TREE_CHAIN (decl) = current_local_enum; + current_local_enum = decl; + } + else + { + /* It's a global enum, or it's local to a function. (Note local to + a function could mean local to a class method. */ + decl = build_decl (CONST_DECL, name, integer_type_node); + DECL_INITIAL (decl) = value; + + pushdecl (decl); + GNU_xref_decl (current_function_decl, decl); + } + + /* Set basis for default for next value. */ + enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, + integer_one_node, PLUS_EXPR); + enum_overflow = tree_int_cst_lt (enum_next_value, value); + + if (enum_next_value == integer_one_node) + enum_next_value = copy_node (enum_next_value); + + result = saveable_tree_cons (name, decl, NULL_TREE); + return result; +} + +tree +grok_enum_decls (type, decl) + tree type, decl; +{ + tree d = current_local_enum; + + if (d == NULL_TREE) + return decl; + + while (1) + { + TREE_TYPE (d) = type; + if (TREE_CHAIN (d) == NULL_TREE) + { + TREE_CHAIN (d) = decl; + break; + } + d = TREE_CHAIN (d); + } + + decl = current_local_enum; + current_local_enum = NULL_TREE; + + return decl; +} + +/* Create the FUNCTION_DECL for a function definition. + DECLSPECS and DECLARATOR are the parts of the declaration; + they describe the function's name and the type it returns, + but twisted together in a fashion that parallels the syntax of C. + + This function creates a binding context for the function body + as well as setting up the FUNCTION_DECL in current_function_decl. + + Returns 1 on success. If the DECLARATOR is not suitable for a function + (it defines a datum instead), we return 0, which tells + yyparse to report a parse error. + + For C++, we must first check whether that datum makes any sense. + For example, "class A local_a(1,2);" means that variable local_a + is an aggregate of type A, which should have a constructor + applied to it with the argument list [1, 2]. + + @@ There is currently no way to retrieve the storage + @@ allocated to FUNCTION (or all of its parms) if we return + @@ something we had previously. */ + +int +start_function (declspecs, declarator, raises, attrs, pre_parsed_p) + tree declspecs, declarator, raises, attrs; + int pre_parsed_p; +{ + tree decl1, olddecl; + tree ctype = NULL_TREE; + tree fntype; + tree restype; + extern int have_extern_spec; + extern int used_extern_spec; + int doing_friend = 0; + + /* Sanity check. */ + my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); + my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); + + /* Assume, until we see it does. */ + current_function_returns_value = 0; + current_function_returns_null = 0; + warn_about_return_type = 0; + named_labels = 0; + shadowed_labels = 0; + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + current_function_parms_stored = 0; + original_result_rtx = NULL_RTX; + current_function_obstack_index = 0; + current_function_obstack_usage = 0; + base_init_expr = NULL_TREE; + protect_list = NULL_TREE; + current_base_init_list = NULL_TREE; + current_member_init_list = NULL_TREE; + ctor_label = dtor_label = NULL_TREE; + + clear_temp_name (); + + /* This should only be done once on the top most decl. */ + if (have_extern_spec && !used_extern_spec) + { + declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); + used_extern_spec = 1; + } + + if (pre_parsed_p) + { + decl1 = declarator; + + if (! DECL_ARGUMENTS (decl1) + && !DECL_STATIC_FUNCTION_P (decl1) + && DECL_CONTEXT (decl1) + && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))) + && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))))) + { + cp_error ("redeclaration of `%#D'", decl1); + if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) + cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); + else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))) + cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))); + } + + /* This can happen if a template class is instantiated as part of the + specialization of a member function which is defined in the class + template. We should just use the specialization, but for now give an + error. */ + if (DECL_INITIAL (decl1) != NULL_TREE) + { + cp_error_at ("specialization of `%#D' not supported", decl1); + cp_error ("when defined in the class template body", decl1); + } + + last_function_parms = DECL_ARGUMENTS (decl1); + last_function_parm_tags = NULL_TREE; + fntype = TREE_TYPE (decl1); + if (TREE_CODE (fntype) == METHOD_TYPE) + ctype = TYPE_METHOD_BASETYPE (fntype); + + /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a + class is in the (lexical) scope of the class in which it is + defined. */ + if (!ctype && DECL_FRIEND_P (decl1)) + { + ctype = DECL_CLASS_CONTEXT (decl1); + + /* CTYPE could be null here if we're dealing with a template; + for example, `inline friend float foo()' inside a template + will have no CTYPE set. */ + if (ctype && TREE_CODE (ctype) != RECORD_TYPE) + ctype = NULL_TREE; + else + doing_friend = 1; + } + + raises = TYPE_RAISES_EXCEPTIONS (fntype); + + /* In a fcn definition, arg types must be complete. */ + require_complete_types_for_parms (last_function_parms); + + /* In case some arg types were completed since the declaration was + parsed, fix up the decls. */ + { + tree t = last_function_parms; + for (; t; t = TREE_CHAIN (t)) + layout_decl (t, 0); + } + } + else + { + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises, + NULL_TREE); + /* If the declarator is not suitable for a function definition, + cause a syntax error. */ + if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; + + fntype = TREE_TYPE (decl1); + + restype = TREE_TYPE (fntype); + if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) + && ! CLASSTYPE_GOT_SEMICOLON (restype)) + { + cp_error ("semicolon missing after declaration of `%#T'", restype); + shadow_tag (build_tree_list (NULL_TREE, restype)); + CLASSTYPE_GOT_SEMICOLON (restype) = 1; + if (TREE_CODE (fntype) == FUNCTION_TYPE) + fntype = build_function_type (integer_type_node, + TYPE_ARG_TYPES (fntype)); + else + fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), + integer_type_node, + TYPE_ARG_TYPES (fntype)); + TREE_TYPE (decl1) = fntype; + } + + if (TREE_CODE (fntype) == METHOD_TYPE) + ctype = TYPE_METHOD_BASETYPE (fntype); + else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 + && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") + && DECL_CONTEXT (decl1) == NULL_TREE) + { + /* If this doesn't return integer_type, complain. */ + if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) + { + if (pedantic || warn_return_type) + pedwarn ("return type for `main' changed to integer type"); + TREE_TYPE (decl1) = fntype = default_function_type; + } + warn_about_return_type = 0; + } + } + + /* Warn if function was previously implicitly declared + (but not if we warned then). */ + if (! warn_implicit + && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) + cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); + + current_function_decl = decl1; + + if (flag_cadillac) + cadillac_start_function (decl1); + else + announce_function (decl1); + + if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE) + { + if (IS_AGGR_TYPE (TREE_TYPE (fntype))) + error_with_aggr_type (TREE_TYPE (fntype), + "return-type `%s' is an incomplete type"); + else + error ("return-type is an incomplete type"); + + /* Make it return void instead, but don't change the + type of the DECL_RESULT, in case we have a named return value. */ + if (ctype) + TREE_TYPE (decl1) + = build_cplus_method_type (build_type_variant (ctype, + TREE_READONLY (decl1), + TREE_SIDE_EFFECTS (decl1)), + void_type_node, + FUNCTION_ARG_CHAIN (decl1)); + else + TREE_TYPE (decl1) + = build_function_type (void_type_node, + TYPE_ARG_TYPES (TREE_TYPE (decl1))); + DECL_RESULT (decl1) + = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); + TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); + TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); + } + + if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) + && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) + abstract_virtuals_error (decl1, TREE_TYPE (fntype)); + + if (warn_about_return_type) + warning ("return-type defaults to `int'"); + + /* Make the init_value nonzero so pushdecl knows this is not tentative. + error_mark_node is replaced below (in poplevel) with the BLOCK. */ + DECL_INITIAL (decl1) = error_mark_node; + + /* Didn't get anything from C. */ + olddecl = NULL_TREE; + + /* This function exists in static storage. + (This does not mean `static' in the C sense!) */ + TREE_STATIC (decl1) = 1; + + /* Record the decl so that the function name is defined. + If we already have a decl for this name, and it is a FUNCTION_DECL, + use the old decl. */ + + if (pre_parsed_p == 0) + { + current_function_decl = decl1 = pushdecl (decl1); + DECL_MAIN_VARIANT (decl1) = decl1; + fntype = TREE_TYPE (decl1); + } + else + current_function_decl = decl1; + + if (DECL_INTERFACE_KNOWN (decl1)) + { + if (DECL_NOT_REALLY_EXTERN (decl1)) + DECL_EXTERNAL (decl1) = 0; + } + /* If this function belongs to an interface, it is public. + If it belongs to someone else's interface, it is also external. + It doesn't matter whether it's inline or not. */ + else if (interface_unknown == 0) + { + if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) + DECL_EXTERNAL (decl1) + = (interface_only + || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); + else + DECL_EXTERNAL (decl1) = 0; + DECL_NOT_REALLY_EXTERN (decl1) = 0; + DECL_INTERFACE_KNOWN (decl1) = 1; + } + else + { + /* This is a definition, not a reference. + So clear DECL_EXTERNAL. */ + DECL_EXTERNAL (decl1) = 0; + + if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1)) + DECL_DEFER_OUTPUT (decl1) = 1; + else + { + DECL_INTERFACE_KNOWN (decl1) = 1; + if (DECL_C_STATIC (decl1)) + TREE_PUBLIC (decl1) = 0; + } + } + + if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) + { + if (TREE_CODE (fntype) == METHOD_TYPE) + TREE_TYPE (decl1) = fntype + = build_function_type (TREE_TYPE (fntype), + TREE_CHAIN (TYPE_ARG_TYPES (fntype))); + last_function_parms = TREE_CHAIN (last_function_parms); + DECL_ARGUMENTS (decl1) = last_function_parms; + ctype = NULL_TREE; + } + restype = TREE_TYPE (fntype); + + if (ctype) + { + push_nested_class (ctype, 1); + + /* If we're compiling a friend function, neither of the variables + current_class_decl nor current_class_type will have values. */ + if (! doing_friend) + { + /* We know that this was set up by `grokclassfn'. + We do not wait until `store_parm_decls', since evil + parse errors may never get us to that point. Here + we keep the consistency between `current_class_type' + and `current_class_decl'. */ + tree t = last_function_parms; + + my_friendly_assert (t != NULL_TREE + && TREE_CODE (t) == PARM_DECL, 162); + + if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) + { + int i = suspend_momentary (); + + /* Fool build_indirect_ref. */ + current_class_decl = NULL_TREE; + C_C_D = build_indirect_ref (t, NULL_PTR); + current_class_decl = t; + resume_momentary (i); + } + else + /* We're having a signature pointer here. */ + C_C_D = current_class_decl = t; + + } + } + else + { + if (DECL_STATIC_FUNCTION_P (decl1)) + push_nested_class (DECL_CONTEXT (decl1), 2); + else + push_memoized_context (0, 1); + current_class_decl = C_C_D = NULL_TREE; + } + + pushlevel (0); + current_binding_level->parm_flag = 1; + + /* Save the parm names or decls from this function's declarator + where store_parm_decls will find them. */ + current_function_parms = last_function_parms; + current_function_parm_tags = last_function_parm_tags; + + GNU_xref_function (decl1, current_function_parms); + + if (attrs) + cplus_decl_attributes (decl1, NULL_TREE, attrs); + make_function_rtl (decl1); + + /* Allocate further tree nodes temporarily during compilation + of this function only. Tiemann moved up here from bottom of fn. */ + temporary_allocation (); + + /* Promote the value to int before returning it. */ + if (C_PROMOTING_INTEGER_TYPE_P (restype)) + { + /* It retains unsignedness if traditional or if it isn't + really getting wider. */ + if (TREE_UNSIGNED (restype) + && (flag_traditional + || TYPE_PRECISION (restype) + == TYPE_PRECISION (integer_type_node))) + restype = unsigned_type_node; + else + restype = integer_type_node; + } + if (DECL_RESULT (decl1) == NULL_TREE) + { + DECL_RESULT (decl1) + = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); + TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype); + TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); + } + + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) + && DECL_LANGUAGE (decl1) == lang_cplusplus) + { + dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + ctor_label = NULL_TREE; + } + else + { + dtor_label = NULL_TREE; + if (DECL_CONSTRUCTOR_P (decl1)) + ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + } + + /* If this fcn was already referenced via a block-scope `extern' decl + (or an implicit decl), propagate certain information about the usage. */ + if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) + TREE_ADDRESSABLE (decl1) = 1; + + return 1; +} + +void +expand_start_early_try_stmts () +{ + rtx insns; + start_sequence (); + expand_start_try_stmts (); + insns = get_insns (); + end_sequence (); + store_in_parms (insns); +} + +void +store_in_parms (insns) + rtx insns; +{ + rtx last_parm_insn; + + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + emit_insns (insns); + else + emit_insns_before (insns, previous_insn (last_parm_insn)); +} + +/* Store the parameter declarations into the current function declaration. + This is called after parsing the parameter declarations, before + digesting the body of the function. + + Also install to binding contour return value identifier, if any. */ + +void +store_parm_decls () +{ + register tree fndecl = current_function_decl; + register tree parm; + int parms_have_cleanups = 0; + + /* This is either a chain of PARM_DECLs (when a prototype is used). */ + tree specparms = current_function_parms; + + /* This is a list of types declared among parms in a prototype. */ + tree parmtags = current_function_parm_tags; + + /* This is a chain of any other decls that came in among the parm + declarations. If a parm is declared with enum {foo, bar} x; + then CONST_DECLs for foo and bar are put here. */ + tree nonparms = NULL_TREE; + + if (toplevel_bindings_p ()) + fatal ("parse errors have confused me too much"); + + /* Initialize RTL machinery. */ + init_function_start (fndecl, input_filename, lineno); + + /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ + declare_function_name (); + + /* Create a binding level for the parms. */ + expand_start_bindings (0); + + if (specparms != NULL_TREE) + { + /* This case is when the function was defined with an ANSI prototype. + The parms already have decls, so we need not do anything here + except record them as in effect + and complain if any redundant old-style parm decls were written. */ + + register tree next; + + /* Must clear this because it might contain TYPE_DECLs declared + at class level. */ + storedecls (NULL_TREE); + for (parm = nreverse (specparms); parm; parm = next) + { + next = TREE_CHAIN (parm); + if (TREE_CODE (parm) == PARM_DECL) + { + tree cleanup = maybe_build_cleanup (parm); + if (DECL_NAME (parm) == NULL_TREE) + { +#if 0 + cp_error_at ("parameter name omitted", parm); +#else + /* for C++, this is not an error. */ + pushdecl (parm); +#endif + } + else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) + cp_error ("parameter `%D' declared void", parm); + else + { + /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. + A parameter is assumed not to have any side effects. + If this should change for any reason, then this + will have to wrap the bashed reference type in a save_expr. + + Also, if the parameter type is declared to be an X + and there is an X(X&) constructor, we cannot lay it + into the stack (any more), so we make this parameter + look like it is really of reference type. Functions + which pass parameters to this function will know to + create a temporary in their frame, and pass a reference + to that. */ + + if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE + && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) + SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); + + pushdecl (parm); + } + if (cleanup) + { + expand_decl (parm); + if (! cp_expand_decl_cleanup (parm, cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", + parm); + parms_have_cleanups = 1; + } + } + else + { + /* If we find an enum constant or a type tag, + put it aside for the moment. */ + TREE_CHAIN (parm) = NULL_TREE; + nonparms = chainon (nonparms, parm); + } + } + + /* Get the decls in their original chain order + and record in the function. This is all and only the + PARM_DECLs that were pushed into scope by the loop above. */ + DECL_ARGUMENTS (fndecl) = getdecls (); + + storetags (chainon (parmtags, gettags ())); + } + else + DECL_ARGUMENTS (fndecl) = NULL_TREE; + + /* Now store the final chain of decls for the arguments + as the decl-chain of the current lexical scope. + Put the enumerators in as well, at the front so that + DECL_ARGUMENTS is not modified. */ + + storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); + + /* Initialize the RTL code for the function. */ + DECL_SAVED_INSNS (fndecl) = NULL_RTX; + expand_function_start (fndecl, parms_have_cleanups); + + /* Create a binding contour which can be used to catch + cleanup-generated temporaries. Also, if the return value needs or + has initialization, deal with that now. */ + if (parms_have_cleanups) + { + pushlevel (0); + expand_start_bindings (0); + } + + current_function_parms_stored = 1; + + if (flag_gc) + { + maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node); + if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", fndecl); + } + + /* If this function is `main', emit a call to `__main' + to run global initializers, etc. */ + if (DECL_NAME (fndecl) + && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 + && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 + && DECL_CONTEXT (fndecl) == NULL_TREE) + { + expand_main_function (); + + if (flag_gc) + expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE), + 0, VOIDmode, 0); +#if 0 + /* done at a different time */ + if (flag_rtti) + output_builtin_tdesc_entries (); +#endif + } + + /* Take care of exception handling things. */ + if (flag_handle_exceptions) + { + rtx insns; + start_sequence (); + + /* Mark the start of a stack unwinder if we need one. */ + start_eh_unwinder (); + + /* Do the starting of the exception specifications, if we have any. */ + if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) + expand_start_eh_spec (); + + insns = get_insns (); + end_sequence (); + + if (insns) + store_in_parms (insns); + } +} + +/* Bind a name and initialization to the return value of + the current function. */ +void +store_return_init (return_id, init) + tree return_id, init; +{ + tree decl = DECL_RESULT (current_function_decl); + + if (pedantic) + /* Give this error as many times as there are occurrences, + so that users can use Emacs compilation buffers to find + and fix all such places. */ + pedwarn ("ANSI C++ does not permit named return values"); + + if (return_id != NULL_TREE) + { + if (DECL_NAME (decl) == NULL_TREE) + { + DECL_NAME (decl) = return_id; + DECL_ASSEMBLER_NAME (decl) = return_id; + } + else + error ("return identifier `%s' already in place", + IDENTIFIER_POINTER (DECL_NAME (decl))); + } + + /* Can't let this happen for constructors. */ + if (DECL_CONSTRUCTOR_P (current_function_decl)) + { + error ("can't redefine default return value for constructors"); + return; + } + + /* If we have a named return value, put that in our scope as well. */ + if (DECL_NAME (decl) != NULL_TREE) + { + /* If this named return value comes in a register, + put it in a pseudo-register. */ + if (DECL_REGISTER (decl)) + { + original_result_rtx = DECL_RTL (decl); + DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); + } + + /* Let `cp_finish_decl' know that this initializer is ok. */ + DECL_INITIAL (decl) = init; + pushdecl (decl); + cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + } +} + + +/* Finish up a function declaration and compile that function + all the way to assembler language output. The free the storage + for the function definition. + + This is called after parsing the body of the function definition. + LINENO is the current line number. + + C++: CALL_POPLEVEL is non-zero if an extra call to poplevel + (and expand_end_bindings) must be made to take care of the binding + contour for the base initializers. This is only relevant for + constructors. */ + +void +finish_function (lineno, call_poplevel, nested) + int lineno; + int call_poplevel; + int nested; +{ + register tree fndecl = current_function_decl; + tree fntype, ctype = NULL_TREE; + rtx last_parm_insn, insns; + /* Label to use if this function is supposed to return a value. */ + tree no_return_label = NULL_TREE; + tree decls = NULL_TREE; + + /* When we get some parse errors, we can end up without a + current_function_decl, so cope. */ + if (fndecl == NULL_TREE) + return; + + fntype = TREE_TYPE (fndecl); + +/* TREE_READONLY (fndecl) = 1; + This caused &foo to be of type ptr-to-const-function + which then got a warning when stored in a ptr-to-function variable. */ + + /* This happens on strange parse errors. */ + if (! current_function_parms_stored) + { + call_poplevel = 0; + store_parm_decls (); + } + + if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) + { + tree ttype = target_type (fntype); + tree parmdecl; + + if (IS_AGGR_TYPE (ttype)) + /* Let debugger know it should output info for this type. */ + note_debug_info_needed (ttype); + + for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) + { + ttype = target_type (TREE_TYPE (parmdecl)); + if (IS_AGGR_TYPE (ttype)) + /* Let debugger know it should output info for this type. */ + note_debug_info_needed (ttype); + } + } + + /* Clean house because we will need to reorder insns here. */ + do_pending_stack_adjust (); + + if (dtor_label) + { + tree binfo = TYPE_BINFO (current_class_type); + tree cond = integer_one_node; + tree exprstmt, vfields; + tree in_charge_node = lookup_name (in_charge_identifier, 0); + tree virtual_size; + int ok_to_optimize_dtor = 0; + + if (current_function_assigns_this) + cond = build (NE_EXPR, boolean_type_node, + current_class_decl, integer_zero_node); + else + { + int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); + + /* If this destructor is empty, then we don't need to check + whether `this' is NULL in some cases. */ + if ((flag_this_is_variable & 1) == 0) + ok_to_optimize_dtor = 1; + else if (get_last_insn () == get_first_nonparm_insn ()) + ok_to_optimize_dtor + = (n_baseclasses == 0 + || (n_baseclasses == 1 + && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); + } + + /* These initializations might go inline. Protect + the binding level of the parms. */ + pushlevel (0); + expand_start_bindings (0); + + if (current_function_assigns_this) + { + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + } + + /* Generate the code to call destructor on base class. + If this destructor belongs to a class with virtual + functions, then set the virtual function table + pointer to represent the type of our base class. */ + + /* This side-effect makes call to `build_delete' generate the + code we have to have at the end of this destructor. */ + TYPE_HAS_DESTRUCTOR (current_class_type) = 0; + + /* These are two cases where we cannot delegate deletion. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) + || TYPE_GETS_REG_DELETE (current_class_type)) + exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); + else + exprstmt = build_delete (current_class_type, C_C_D, in_charge_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); + + /* If we did not assign to this, then `this' is non-zero at + the end of a destructor. As a special optimization, don't + emit test if this is an empty destructor. If it does nothing, + it does nothing. If it calls a base destructor, the base + destructor will perform the test. */ + + if (exprstmt != error_mark_node + && (TREE_CODE (exprstmt) != NOP_EXPR + || TREE_OPERAND (exprstmt, 0) != integer_zero_node + || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) + { + expand_label (dtor_label); + if (cond != integer_one_node) + expand_start_cond (cond, 0); + if (exprstmt != void_zero_node) + /* Don't call `expand_expr_stmt' if we're not going to do + anything, since -Wall will give a diagnostic. */ + expand_expr_stmt (exprstmt); + + /* Run destructor on all virtual baseclasses. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + { + tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); + expand_start_cond (build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_two_node), 0); + while (vbases) + { + if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) + { + tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl); + expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)), + ptr, integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0)); + } + vbases = TREE_CHAIN (vbases); + } + expand_end_cond (); + } + + do_pending_stack_adjust (); + if (cond != integer_one_node) + expand_end_cond (); + } + + TYPE_HAS_DESTRUCTOR (current_class_type) = 1; + + virtual_size = c_sizeof (current_class_type); + + /* At the end, call delete if that's what's requested. */ + if (TYPE_GETS_REG_DELETE (current_class_type)) + /* This NOP_EXPR means we are in a static call context. */ + exprstmt = + build_method_call + (build_indirect_ref + (build1 (NOP_EXPR, build_pointer_type (current_class_type), + error_mark_node), + NULL_PTR), + ansi_opname[(int) DELETE_EXPR], + tree_cons (NULL_TREE, current_class_decl, + build_tree_list (NULL_TREE, virtual_size)), + NULL_TREE, LOOKUP_NORMAL); + else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0, + virtual_size); + else + exprstmt = NULL_TREE; + + if (exprstmt) + { + cond = build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_one_node); + expand_start_cond (cond, 0); + expand_expr_stmt (exprstmt); + expand_end_cond (); + } + + /* End of destructor. */ + expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0); + poplevel (2, 0, 0); /* XXX change to 1 */ + + /* Back to the top of destructor. */ + /* Dont execute destructor code if `this' is NULL. */ + + start_sequence (); + + /* Make all virtual function table pointers in non-virtual base + classes point to CURRENT_CLASS_TYPE's virtual function + tables. */ + expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl); + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0); + if (! ok_to_optimize_dtor) + { + cond = build_binary_op (NE_EXPR, + current_class_decl, integer_zero_node, 1); + expand_start_cond (cond, 0); + } + + insns = get_insns (); + end_sequence (); + + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + last_parm_insn = get_last_insn (); + else + last_parm_insn = previous_insn (last_parm_insn); + + emit_insns_after (insns, last_parm_insn); + + if (! ok_to_optimize_dtor) + expand_end_cond (); + } + else if (current_function_assigns_this) + { + /* Does not need to call emit_base_init, because + that is done (if needed) just after assignment to this + is seen. */ + + if (DECL_CONSTRUCTOR_P (current_function_decl)) + { + end_protect_partials (); + expand_label (ctor_label); + ctor_label = NULL_TREE; + + if (call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 0, 0); + } + c_expand_return (current_class_decl); + } + else if (TYPE_MAIN_VARIANT (TREE_TYPE ( + DECL_RESULT (current_function_decl))) != void_type_node + && return_label != NULL_RTX) + no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + base_init_expr = NULL_TREE; + } + else if (DECL_CONSTRUCTOR_P (fndecl)) + { + tree allocated_this; + tree cond, thenclause; + /* Allow constructor for a type to get a new instance of the object + using `build_new'. */ + tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; + + DECL_RETURNS_FIRST_ARG (fndecl) = 1; + + if (flag_this_is_variable > 0) + { + cond = build_binary_op (EQ_EXPR, + current_class_decl, integer_zero_node, 1); + thenclause = build_modify_expr (current_class_decl, NOP_EXPR, + build_new (NULL_TREE, current_class_type, void_type_node, 0)); + } + + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; + + start_sequence (); + + if (flag_this_is_variable > 0) + { + expand_start_cond (cond, 0); + expand_expr_stmt (thenclause); + expand_end_cond (); + } + +#if 0 + if (DECL_NAME (fndecl) == NULL_TREE + && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE) + build_default_constructor (fndecl); +#endif + + /* Emit insns from `emit_base_init' which sets up virtual + function table pointer(s). */ + if (base_init_expr) + { + expand_expr_stmt (base_init_expr); + base_init_expr = NULL_TREE; + } + + insns = get_insns (); + end_sequence (); + + /* This is where the body of the constructor begins. + If there were no insns in this function body, then the + last_parm_insn is also the last insn. + + If optimization is enabled, last_parm_insn may move, so + we don't hold on to it (across emit_base_init). */ + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + last_parm_insn = get_last_insn (); + else + last_parm_insn = previous_insn (last_parm_insn); + + emit_insns_after (insns, last_parm_insn); + + end_protect_partials (); + + /* This is where the body of the constructor ends. */ + expand_label (ctor_label); + ctor_label = NULL_TREE; + + if (call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 1, 0); + } + + c_expand_return (current_class_decl); + + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + } + else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 + && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") + && DECL_CONTEXT (fndecl) == NULL_TREE) + { + /* Make it so that `main' always returns 0 by default. */ +#ifdef VMS + c_expand_return (integer_one_node); +#else + c_expand_return (integer_zero_node); +#endif + } + else if (return_label != NULL_RTX + && current_function_return_value == NULL_TREE + && ! DECL_NAME (DECL_RESULT (current_function_decl))) + no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + if (flag_gc) + expand_gc_prologue_and_epilogue (); + + /* If this function is supposed to return a value, ensure that + we do not fall into the cleanups by mistake. The end of our + function will look like this: + + user code (may have return stmt somewhere) + goto no_return_label + cleanup_label: + cleanups + goto return_label + no_return_label: + NOTE_INSN_FUNCTION_END + return_label: + things for return + + If the user omits a return stmt in the USER CODE section, we + will have a control path which reaches NOTE_INSN_FUNCTION_END. + Otherwise, we won't. */ + if (no_return_label) + { + DECL_CONTEXT (no_return_label) = fndecl; + DECL_INITIAL (no_return_label) = error_mark_node; + DECL_SOURCE_FILE (no_return_label) = input_filename; + DECL_SOURCE_LINE (no_return_label) = lineno; + expand_goto (no_return_label); + } + + if (cleanup_label) + { + /* remove the binding contour which is used + to catch cleanup-generated temporaries. */ + expand_end_bindings (0, 0, 0); + poplevel (0, 0, 0); + } + + if (cleanup_label) + /* Emit label at beginning of cleanup code for parameters. */ + emit_label (cleanup_label); + + /* Get return value into register if that's where it's supposed to be. */ + if (original_result_rtx) + fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); + + /* Finish building code that will trigger warnings if users forget + to make their functions return values. */ + if (no_return_label || cleanup_label) + emit_jump (return_label); + if (no_return_label) + { + /* We don't need to call `expand_*_return' here because we + don't need any cleanups here--this path of code is only + for error checking purposes. */ + expand_label (no_return_label); + } + + /* Generate rtl for function exit. */ + expand_function_end (input_filename, lineno, 1); + + if (flag_handle_exceptions) + expand_exception_blocks (); + + /* This must come after expand_function_end because cleanups might + have declarations (from inline functions) that need to go into + this function's blocks. */ + if (current_binding_level->parm_flag != 1) + my_friendly_abort (122); + poplevel (1, 0, 1); + + /* reset scope for C++: if we were in the scope of a class, + then when we finish this function, we are not longer so. + This cannot be done until we know for sure that no more + class members will ever be referenced in this function + (i.e., calls to destructors). */ + if (current_class_name) + { + ctype = current_class_type; + pop_nested_class (1); + } + else + pop_memoized_context (1); + + /* Must mark the RESULT_DECL as being in this function. */ + DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl); + + /* Obey `register' declarations if `setjmp' is called in this fn. */ + if (flag_traditional && current_function_calls_setjmp) + setjmp_protect (DECL_INITIAL (fndecl)); + + /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point + to the FUNCTION_DECL node itself. */ + BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; + + /* So we can tell if jump_optimize sets it to 1. */ + can_reach_end = 0; + + /* Run the optimizers and output the assembler code for this function. */ + rest_of_compilation (fndecl); + + if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) + { + /* Set DECL_EXTERNAL so that assemble_external will be called as + necessary. We'll clear it again in finish_file. */ + if (! DECL_EXTERNAL (fndecl)) + DECL_NOT_REALLY_EXTERN (fndecl) = 1; + DECL_EXTERNAL (fndecl) = 1; + mark_inline_for_output (fndecl); + } + + if (ctype && TREE_ASM_WRITTEN (fndecl)) + note_debug_info_needed (ctype); + + current_function_returns_null |= can_reach_end; + + /* Since we don't normally go through c_expand_return for constructors, + this normally gets the wrong value. + Also, named return values have their return codes emitted after + NOTE_INSN_FUNCTION_END, confusing jump.c. */ + if (DECL_CONSTRUCTOR_P (fndecl) + || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) + current_function_returns_null = 0; + + if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) + cp_warning ("`noreturn' function `%D' does return", fndecl); + else if ((warn_return_type || pedantic) + && current_function_returns_null + && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) + { + /* If this function returns non-void and control can drop through, + complain. */ + cp_pedwarn ("control reaches end of non-void function `%D'", fndecl); + } + /* With just -W, complain only if function returns both with + and without a value. */ + else if (extra_warnings + && current_function_returns_value && current_function_returns_null) + warning ("this function may return with or without a value"); + + /* Free all the tree nodes making up this function. */ + /* Switch back to allocating nodes permanently + until we start another function. */ + if (! nested) + permanent_allocation (1); + + if (flag_cadillac) + cadillac_finish_function (fndecl); + + if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) + { + /* Stop pointing to the local nodes about to be freed. */ + /* But DECL_INITIAL must remain nonzero so we know this + was an actual function definition. */ + DECL_INITIAL (fndecl) = error_mark_node; + if (! DECL_CONSTRUCTOR_P (fndecl) + || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype))) + DECL_ARGUMENTS (fndecl) = NULL_TREE; + } + + if (DECL_STATIC_CONSTRUCTOR (fndecl)) + static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); + if (DECL_STATIC_DESTRUCTOR (fndecl)) + static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); + + if (! nested) + { + /* Let the error reporting routines know that we're outside a + function. For a nested function, this value is used in + pop_cp_function_context and then reset via pop_function_context. */ + current_function_decl = NULL_TREE; + } + + named_label_uses = NULL_TREE; + current_class_decl = NULL_TREE; +} + +/* Create the FUNCTION_DECL for a function definition. + LINE1 is the line number that the definition absolutely begins on. + LINE2 is the line number that the name of the function appears on. + DECLSPECS and DECLARATOR are the parts of the declaration; + they describe the return type and the name of the function, + but twisted together in a fashion that parallels the syntax of C. + + This function creates a binding context for the function body + as well as setting up the FUNCTION_DECL in current_function_decl. + + Returns a FUNCTION_DECL on success. + + If the DECLARATOR is not suitable for a function (it defines a datum + instead), we return 0, which tells yyparse to report a parse error. + + May return void_type_node indicating that this method is actually + a friend. See grokfield for more details. + + Came here with a `.pushlevel' . + + DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING + CHANGES TO CODE IN `grokfield'. */ +tree +start_method (declspecs, declarator, raises) + tree declarator, declspecs, raises; +{ + tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises, + NULL_TREE); + + /* Something too ugly to handle. */ + if (fndecl == NULL_TREE) + return NULL_TREE; + + /* Pass friends other than inline friend functions back. */ + if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) + return fndecl; + + if (TREE_CODE (fndecl) != FUNCTION_DECL) + /* Not a function, tell parser to report parse error. */ + return NULL_TREE; + + if (IS_SIGNATURE (current_class_type)) + { + IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; + /* In case we need this info later. */ + HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1; + } + + if (DECL_IN_AGGR_P (fndecl)) + { + if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) + { + if (DECL_CONTEXT (fndecl)) + cp_error ("`%D' is already defined in class %s", fndecl, + TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); + } + return void_type_node; + } + + DECL_THIS_INLINE (fndecl) = 1; + + if (flag_default_inline) + DECL_INLINE (fndecl) = 1; + + if (processing_template_defn) + { + SET_DECL_IMPLICIT_INSTANTIATION (fndecl); + repo_template_used (fndecl); + } + + /* We read in the parameters on the maybepermanent_obstack, + but we won't be getting back to them until after we + may have clobbered them. So the call to preserve_data + will keep them safe. */ + preserve_data (); + + if (! DECL_FRIEND_P (fndecl)) + { + if (DECL_CHAIN (fndecl) != NULL_TREE) + { + /* Need a fresh node here so that we don't get circularity + when we link these together. If FNDECL was a friend, then + `pushdecl' does the right thing, which is nothing wrt its + current value of DECL_CHAIN. */ + fndecl = copy_node (fndecl); + } + if (TREE_CHAIN (fndecl)) + { + fndecl = copy_node (fndecl); + TREE_CHAIN (fndecl) = NULL_TREE; + } + + if (DECL_CONSTRUCTOR_P (fndecl)) + { + if (! grok_ctor_properties (current_class_type, fndecl)) + return void_type_node; + } + else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) + grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); + } + + cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); + + /* Make a place for the parms */ + pushlevel (0); + current_binding_level->parm_flag = 1; + + DECL_IN_AGGR_P (fndecl) = 1; + return fndecl; +} + +/* Go through the motions of finishing a function definition. + We don't compile this method until after the whole class has + been processed. + + FINISH_METHOD must return something that looks as though it + came from GROKFIELD (since we are defining a method, after all). + + This is called after parsing the body of the function definition. + STMTS is the chain of statements that makes up the function body. + + DECL is the ..._DECL that `start_method' provided. */ + +tree +finish_method (decl) + tree decl; +{ + register tree fndecl = decl; + tree old_initial; + + register tree link; + + if (TYPE_MAIN_VARIANT (decl) == void_type_node) + return decl; + + old_initial = DECL_INITIAL (fndecl); + + /* Undo the level for the parms (from start_method). + This is like poplevel, but it causes nothing to be + saved. Saving information here confuses symbol-table + output routines. Besides, this information will + be correctly output when this method is actually + compiled. */ + + /* Clear out the meanings of the local variables of this level; + also record in each decl which block it belongs to. */ + + for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) + { + if (DECL_NAME (link) != NULL_TREE) + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; + my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); + DECL_CONTEXT (link) = NULL_TREE; + } + + /* Restore all name-meanings of the outer levels + that were shadowed by this level. */ + + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->class_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->type_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + + GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, + (HOST_WIDE_INT) current_binding_level->level_chain, + current_binding_level->parm_flag, + current_binding_level->keep, + current_binding_level->tag_transparent); + + poplevel (0, 0, 0); + + DECL_INITIAL (fndecl) = old_initial; + + /* We used to check if the context of FNDECL was different from + current_class_type as another way to get inside here. This didn't work + for String.cc in libg++. */ + if (DECL_FRIEND_P (fndecl)) + { + CLASSTYPE_INLINE_FRIENDS (current_class_type) + = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); + decl = void_type_node; + } + + return decl; +} + +/* Called when a new struct TYPE is defined. + If this structure or union completes the type of any previous + variable declaration, lay it out and output its rtl. */ + +void +hack_incomplete_structures (type) + tree type; +{ + tree *list; + + if (current_binding_level->incomplete == NULL_TREE) + return; + + if (!type) /* Don't do this for class templates. */ + return; + + for (list = ¤t_binding_level->incomplete; *list; ) + { + tree decl = TREE_VALUE (*list); + if (decl && TREE_TYPE (decl) == type + || (TREE_TYPE (decl) + && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (decl)) == type)) + { + int toplevel = toplevel_bindings_p (); + if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (decl)) == type) + layout_type (TREE_TYPE (decl)); + layout_decl (decl, 0); + rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); + if (! toplevel) + { + tree cleanup; + expand_decl (decl); + cleanup = maybe_build_cleanup (decl); + expand_decl_init (decl); + if (! cp_expand_decl_cleanup (decl, cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", + decl); + } + *list = TREE_CHAIN (*list); + } + else + list = &TREE_CHAIN (*list); + } +} + +/* Nonzero if presently building a cleanup. Needed because + SAVE_EXPRs are not the right things to use inside of cleanups. + They are only ever evaluated once, where the cleanup + might be evaluated several times. In this case, a later evaluation + of the cleanup might fill in the SAVE_EXPR_RTL, and it will + not be valid for an earlier cleanup. */ + +int building_cleanup; + +/* If DECL is of a type which needs a cleanup, build that cleanup here. + We don't build cleanups if just going for syntax checking, since + fixup_cleanups does not know how to not handle them. + + Don't build these on the momentary obstack; they must live + the life of the binding contour. */ +tree +maybe_build_cleanup (decl) + tree decl; +{ + tree type = TREE_TYPE (decl); + if (TYPE_NEEDS_DESTRUCTOR (type)) + { + int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; + tree rval; + int old_building_cleanup = building_cleanup; + building_cleanup = 1; + + if (TREE_CODE (decl) != PARM_DECL) + temp = suspend_momentary (); + + if (TREE_CODE (type) == ARRAY_TYPE) + rval = decl; + else + { + mark_addressable (decl); + rval = build_unary_op (ADDR_EXPR, decl, 0); + } + + /* Optimize for space over speed here. */ + if (! TYPE_USES_VIRTUAL_BASECLASSES (type) + || flag_expensive_optimizations) + flags |= LOOKUP_NONVIRTUAL; + + rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0); + + if (TYPE_USES_VIRTUAL_BASECLASSES (type) + && ! TYPE_HAS_DESTRUCTOR (type)) + rval = build_compound_expr (tree_cons (NULL_TREE, rval, + build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); + + if (TREE_CODE (decl) != PARM_DECL) + resume_momentary (temp); + + building_cleanup = old_building_cleanup; + + return rval; + } + return 0; +} + +/* Expand a C++ expression at the statement level. + This is needed to ferret out nodes which have UNKNOWN_TYPE. + The C++ type checker should get all of these out when + expressions are combined with other, type-providing, expressions, + leaving only orphan expressions, such as: + + &class::bar; / / takes its address, but does nothing with it. + + */ +void +cplus_expand_expr_stmt (exp) + tree exp; +{ + if (TREE_TYPE (exp) == unknown_type_node) + { + if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) + error ("address of overloaded function with no contextual type information"); + else if (TREE_CODE (exp) == COMPONENT_REF) + warning ("useless reference to a member function name, did you forget the ()?"); + } + else + { + int remove_implicit_immediately = 0; + + if (TREE_CODE (exp) == FUNCTION_DECL) + { + cp_warning ("reference, not call, to function `%D'", exp); + warning ("at this point in file"); + } + +#if 0 + /* We should do this eventually, but right now this causes regex.o from + libg++ to miscompile, and tString to core dump. */ + exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); +#endif + expand_expr_stmt (break_out_cleanups (exp)); + } + + /* Clean up any pending cleanups. This happens when a function call + returns a cleanup-needing value that nobody uses. */ + expand_cleanups_to (NULL_TREE); +} + +/* When a stmt has been parsed, this function is called. + + Currently, this function only does something within a + constructor's scope: if a stmt has just assigned to this, + and we are in a derived class, we call `emit_base_init'. */ + +void +finish_stmt () +{ + extern struct nesting *cond_stack, *loop_stack, *case_stack; + + + if (current_function_assigns_this + || ! current_function_just_assigned_this) + return; + if (DECL_CONSTRUCTOR_P (current_function_decl)) + { + /* Constructors must wait until we are out of control + zones before calling base constructors. */ + if (cond_stack || loop_stack || case_stack) + return; + expand_expr_stmt (base_init_expr); + check_base_init (current_class_type); + } + current_function_assigns_this = 1; + + if (flag_cadillac) + cadillac_finish_stmt (); +} + +/* Change a static member function definition into a FUNCTION_TYPE, instead + of the METHOD_TYPE that we create when it's originally parsed. + + WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES + (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of + other decls. Either pass the addresses of local variables or NULL. */ + +void +revert_static_member_fn (decl, fn, argtypes) + tree *decl, *fn, *argtypes; +{ + tree tmp; + tree function = fn ? *fn : TREE_TYPE (*decl); + tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); + + if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args)))) + cp_error ("static member function `%#D' declared const", *decl); + if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args)))) + cp_error ("static member function `%#D' declared volatile", *decl); + + args = TREE_CHAIN (args); + tmp = build_function_type (TREE_TYPE (function), args); + tmp = build_type_variant (tmp, TYPE_READONLY (function), + TYPE_VOLATILE (function)); + tmp = build_exception_variant (tmp, + TYPE_RAISES_EXCEPTIONS (function)); + TREE_TYPE (*decl) = tmp; + if (DECL_ARGUMENTS (*decl)) + DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); + DECL_STATIC_FUNCTION_P (*decl) = 1; + if (fn) + *fn = tmp; + if (argtypes) + *argtypes = args; +} + +int +id_in_current_class (id) + tree id; +{ + return !!purpose_member (id, class_binding_level->class_shadowed); +} + +struct cp_function +{ + int returns_value; + int returns_null; + int warn_about_return_type; + int assigns_this; + int just_assigned_this; + int parms_stored; + int temp_name_counter; + tree named_labels; + tree shadowed_labels; + tree ctor_label; + tree dtor_label; + tree protect_list; + tree base_init_list; + tree member_init_list; + tree base_init_expr; + tree class_decl; + tree C_C_D; + rtx result_rtx; + struct cp_function *next; + struct binding_level *binding_level; +}; + +struct cp_function *cp_function_chain; + +extern int temp_name_counter; + +/* Save and reinitialize the variables + used during compilation of a C++ function. */ + +void +push_cp_function_context (context) + tree context; +{ + struct cp_function *p + = (struct cp_function *) xmalloc (sizeof (struct cp_function)); + + push_function_context_to (context); + + p->next = cp_function_chain; + cp_function_chain = p; + + p->named_labels = named_labels; + p->shadowed_labels = shadowed_labels; + p->returns_value = current_function_returns_value; + p->returns_null = current_function_returns_null; + p->warn_about_return_type = warn_about_return_type; + p->binding_level = current_binding_level; + p->ctor_label = ctor_label; + p->dtor_label = dtor_label; + p->assigns_this = current_function_assigns_this; + p->just_assigned_this = current_function_just_assigned_this; + p->parms_stored = current_function_parms_stored; + p->result_rtx = original_result_rtx; + p->base_init_expr = base_init_expr; + p->protect_list = protect_list; + p->temp_name_counter = temp_name_counter; + p->base_init_list = current_base_init_list; + p->member_init_list = current_member_init_list; + p->class_decl = current_class_decl; + p->C_C_D = C_C_D; +} + +/* Restore the variables used during compilation of a C++ function. */ + +void +pop_cp_function_context (context) + tree context; +{ + struct cp_function *p = cp_function_chain; + tree link; + + /* Bring back all the labels that were shadowed. */ + for (link = shadowed_labels; link; link = TREE_CHAIN (link)) + if (DECL_NAME (TREE_VALUE (link)) != 0) + SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), + TREE_VALUE (link)); + +#if 0 + if (DECL_SAVED_INSNS (current_function_decl) == 0) + { + /* Stop pointing to the local nodes about to be freed. */ + /* But DECL_INITIAL must remain nonzero so we know this + was an actual function definition. */ + DECL_INITIAL (current_function_decl) = error_mark_node; + DECL_ARGUMENTS (current_function_decl) = 0; + } +#endif + + pop_function_context_from (context); + + cp_function_chain = p->next; + + named_labels = p->named_labels; + shadowed_labels = p->shadowed_labels; + current_function_returns_value = p->returns_value; + current_function_returns_null = p->returns_null; + warn_about_return_type = p->warn_about_return_type; + current_binding_level = p->binding_level; + ctor_label = p->ctor_label; + dtor_label = p->dtor_label; + protect_list = p->protect_list; + current_function_assigns_this = p->assigns_this; + current_function_just_assigned_this = p->just_assigned_this; + current_function_parms_stored = p->parms_stored; + original_result_rtx = p->result_rtx; + base_init_expr = p->base_init_expr; + temp_name_counter = p->temp_name_counter; + current_base_init_list = p->base_init_list; + current_member_init_list = p->member_init_list; + current_class_decl = p->class_decl; + C_C_D = p->C_C_D; + + free (p); +} + +/* FSF LOCAL dje prefix attributes */ +/* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two + lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE). + + The head of the declspec list is stored in DECLSPECS. + The head of the attribute list is stored in PREFIX_ATTRIBUTES. + + Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of + the list elements. We drop the containing TREE_LIST nodes and link the + resulting attributes together the way decl_attributes expects them. */ + +void +split_specs_attrs (specs_attrs, declspecs, prefix_attributes) + tree specs_attrs; + tree *declspecs, *prefix_attributes; +{ + tree t, s, a, next, specs, attrs; + + /* This can happen in c++ (eg: decl: typespec initdecls ';'). */ + if (specs_attrs != NULL_TREE + && TREE_CODE (specs_attrs) != TREE_LIST) + { + *declspecs = specs_attrs; + *prefix_attributes = NULL_TREE; + return; + } + + /* Remember to keep the lists in the same order, element-wise. */ + + specs = s = NULL_TREE; + attrs = a = NULL_TREE; + for (t = specs_attrs; t; t = next) + { + next = TREE_CHAIN (t); + /* Declspecs have a non-NULL TREE_VALUE. */ + if (TREE_VALUE (t) != NULL_TREE) + { + if (specs == NULL_TREE) + specs = s = t; + else + { + TREE_CHAIN (s) = t; + s = t; + } + } + else + { + if (attrs == NULL_TREE) + attrs = a = TREE_PURPOSE (t); + else + { + TREE_CHAIN (a) = TREE_PURPOSE (t); + a = TREE_PURPOSE (t); + } + } + } + + /* Terminate the lists. */ + if (s != NULL_TREE) + TREE_CHAIN (s) = NULL_TREE; + if (a != NULL_TREE) + TREE_CHAIN (a) = NULL_TREE; + + /* All done. */ + *declspecs = specs; + *prefix_attributes = attrs; +} + +/* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes. + This function is used by the parser when a rule will accept attributes + in a particular position, but we don't want to support that just yet. + + A warning is issued for every ignored attribute. */ + +tree +strip_attrs (specs_attrs) + tree specs_attrs; +{ + tree specs, attrs; + + split_specs_attrs (specs_attrs, &specs, &attrs); + + while (attrs) + { + warning ("`%s' attribute ignored", + IDENTIFIER_POINTER (TREE_PURPOSE (attrs))); + attrs = TREE_CHAIN (attrs); + } + + return specs; +} +/* END FSF LOCAL */ + diff --git a/contrib/gcc/cp/decl.h b/contrib/gcc/cp/decl.h new file mode 100644 index 00000000000..0824c13d673 --- /dev/null +++ b/contrib/gcc/cp/decl.h @@ -0,0 +1,59 @@ +/* Variables and structures for declaration processing. + Copyright (C) 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* In grokdeclarator, distinguish syntactic contexts of declarators. */ +enum decl_context +{ NORMAL, /* Ordinary declaration */ + FUNCDEF, /* Function definition */ + PARM, /* Declaration of parm before function body */ + CATCHPARM, /* Declaration of catch parm */ + FIELD, /* Declaration inside struct or union */ + BITFIELD, /* Likewise but with specified width */ + TYPENAME, /* Typename (inside cast or sizeof) */ + MEMFUNCDEF /* Member function definition */ +}; + +/* We need this in here to get the decl_context definition. */ +extern tree grokdeclarator PROTO((tree, tree, enum decl_context, int, tree, tree)); + +/* C++: Keep these around to reduce calls to `get_identifier'. + Identifiers for `this' in member functions and the auto-delete + parameter for destructors. */ +extern tree this_identifier, in_charge_identifier; + +/* Parsing a function declarator leaves a list of parameter names + or a chain or parameter decls here. */ +extern tree last_function_parms; + +/* A list of static class variables. This is needed, because a + static class variable can be declared inside the class without + an initializer, and then initialized, staticly, outside the class. */ +extern tree pending_statics; + +/* A list of objects which have constructors or destructors + which reside in the global scope. The decl is stored in + the TREE_VALUE slot and the initializer is stored + in the TREE_PURPOSE slot. */ +extern tree static_aggregates; + +#ifdef DEBUG_CP_BINDING_LEVELS +/* Purely for debugging purposes. */ +extern int debug_bindings_indentation; +#endif diff --git a/contrib/gcc/cp/decl2.c b/contrib/gcc/cp/decl2.c new file mode 100644 index 00000000000..7a3f7d5e094 --- /dev/null +++ b/contrib/gcc/cp/decl2.c @@ -0,0 +1,3511 @@ +/* Process declarations and variables for C compiler. + Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Process declarations and symbol lookup for C front end. + Also constructs types; the standard scalar types at initialization, + and structure, union, array and enum types when they are declared. */ + +/* ??? not all decl nodes are given the most useful possible + line numbers. For example, the CONST_DECLs for enum values. */ + +#include "config.h" +#include +#include "tree.h" +#include "rtl.h" +#include "flags.h" +#include "cp-tree.h" +#include "decl.h" +#include "lex.h" +#include "output.h" +#include "defaults.h" + +extern tree get_file_function_name (); +extern tree cleanups_this_call; +static void grok_function_init (); + +/* A list of virtual function tables we must make sure to write out. */ +tree pending_vtables; + +/* A list of static class variables. This is needed, because a + static class variable can be declared inside the class without + an initializer, and then initialized, staticly, outside the class. */ +tree pending_statics; + +/* A list of functions which were declared inline, but which we + may need to emit outline anyway. */ +static tree saved_inlines; + +/* Used to help generate temporary names which are unique within + a function. Reset to 0 by start_function. */ + +int temp_name_counter; + +/* Same, but not reset. Local temp variables and global temp variables + can have the same name. */ +static int global_temp_name_counter; + +/* Flag used when debugging spew.c */ + +extern int spew_debug; + +/* Functions called along with real static constructors and destructors. */ + +tree static_ctors, static_dtors; + +/* C (and C++) language-specific option variables. */ + +/* Nonzero means allow type mismatches in conditional expressions; + just make their values `void'. */ + +int flag_cond_mismatch; + +/* Nonzero means give `double' the same size as `float'. */ + +int flag_short_double; + +/* Nonzero means don't recognize the keyword `asm'. */ + +int flag_no_asm; + +/* Nonzero means don't recognize any extension keywords. */ + +int flag_no_gnu_keywords; + +/* Nonzero means don't recognize the non-ANSI builtin functions. */ + +int flag_no_builtin; + +/* Nonzero means don't recognize the non-ANSI builtin functions. + -ansi sets this. */ + +int flag_no_nonansi_builtin; + +/* Nonzero means do some things the same way PCC does. */ + +int flag_traditional; + +/* Nonzero means to treat bitfields as unsigned unless they say `signed'. */ + +int flag_signed_bitfields = 1; + +/* Nonzero means handle `#ident' directives. 0 means ignore them. */ + +int flag_no_ident; + +/* Nonzero means enable obscure ANSI features and disable GNU extensions + that might cause ANSI-compliant code to be miscompiled. */ + +int flag_ansi; + +/* Nonzero means do emit exported implementations of functions even if + they can be inlined. */ + +int flag_implement_inlines = 1; + +/* Nonzero means do emit exported implementations of templates, instead of + multiple static copies in each file that needs a definition. */ + +int flag_external_templates; + +/* Nonzero means that the decision to emit or not emit the implementation of a + template depends on where the template is instantiated, rather than where + it is defined. */ + +int flag_alt_external_templates; + +/* Nonzero means that implicit instantiations will be emitted if needed. */ + +int flag_implicit_templates = 1; + +/* Nonzero means warn about implicit declarations. */ + +int warn_implicit = 1; + +/* Nonzero means warn when all ctors or dtors are private, and the class + has no friends. */ + +int warn_ctor_dtor_privacy = 1; + +/* True if we want to implement vtbvales using "thunks". + The default is off now, but will be on later. */ + +int flag_vtable_thunks; + +/* True if we want to deal with repository information. */ + +int flag_use_repository; + +/* Nonzero means give string constants the type `const char *' + to get extra warnings from them. These warnings will be too numerous + to be useful, except in thoroughly ANSIfied programs. */ + +int warn_write_strings; + +/* Nonzero means warn about pointer casts that can drop a type qualifier + from the pointer target type. */ + +int warn_cast_qual; + +/* Nonzero means warn that dbx info for template class methods isn't fully + supported yet. */ + +int warn_template_debugging; + +/* Warn about traditional constructs whose meanings changed in ANSI C. */ + +int warn_traditional; + +/* Nonzero means warn about sizeof(function) or addition/subtraction + of function pointers. */ + +int warn_pointer_arith; + +/* Nonzero means warn for non-prototype function decls + or non-prototyped defs without previous prototype. */ + +int warn_strict_prototypes; + +/* Nonzero means warn for any function def without prototype decl. */ + +int warn_missing_prototypes; + +/* Nonzero means warn about multiple (redundant) decls for the same single + variable or function. */ + +int warn_redundant_decls; + +/* Warn if initializer is not completely bracketed. */ + +int warn_missing_braces; + +/* Warn about *printf or *scanf format/argument anomalies. */ + +int warn_format; + +/* Warn about a subscript that has type char. */ + +int warn_char_subscripts; + +/* Warn if a type conversion is done that might have confusing results. */ + +int warn_conversion; + +/* Warn if adding () is suggested. */ + +int warn_parentheses; + +/* Non-zero means warn in function declared in derived class has the + same name as a virtual in the base class, but fails to match the + type signature of any virtual function in the base class. */ +int warn_overloaded_virtual; + +/* Non-zero means warn when declaring a class that has a non virtual + destructor, when it really ought to have a virtual one. */ +int warn_nonvdtor; + +/* Non-zero means warn when a function is declared extern and later inline. */ +int warn_extern_inline; + +/* Non-zero means warn when the compiler will reorder code. */ +int warn_reorder; + +/* Non-zero means warn when synthesis behavior differs from Cfront's. */ +int warn_synth; + +/* Nonzero means `$' can be in an identifier. + See cccp.c for reasons why this breaks some obscure ANSI C programs. */ + +#ifndef DOLLARS_IN_IDENTIFIERS +#define DOLLARS_IN_IDENTIFIERS 1 +#endif +int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; + +/* Nonzero for -fno-strict-prototype switch: do not consider empty + argument prototype to mean function takes no arguments. */ + +int flag_strict_prototype = 2; +int strict_prototype = 1; +int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1; + +/* Nonzero means that labels can be used as first-class objects */ + +int flag_labels_ok; + +/* Non-zero means to collect statistics which might be expensive + and to print them when we are done. */ +int flag_detailed_statistics; + +/* C++ specific flags. */ +/* Nonzero for -fall-virtual: make every member function (except + constructors) lay down in the virtual function table. Calls + can then either go through the virtual function table or not, + depending. */ + +int flag_all_virtual; + +/* Zero means that `this' is a *const. This gives nice behavior in the + 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior. + -2 means we're constructing an object and it has fixed type. */ + +int flag_this_is_variable; + +/* Nonzero means memoize our member lookups. */ + +int flag_memoize_lookups; int flag_save_memoized_contexts; + +/* 3 means write out only virtuals function tables `defined' + in this implementation file. + 2 means write out only specific virtual function tables + and give them (C) public access. + 1 means write out virtual function tables and give them + (C) public access. + 0 means write out virtual function tables and give them + (C) static access (default). + -1 means declare virtual function tables extern. */ + +int write_virtuals; + +/* Nonzero means we should attempt to elide constructors when possible. */ + +int flag_elide_constructors; + +/* Nonzero means recognize and handle exception handling constructs. + Use ansi syntax and semantics. WORK IN PROGRESS! */ + +int flag_handle_exceptions; + +/* Nonzero means recognize and handle signature language constructs. */ + +int flag_handle_signatures; + +/* Nonzero means that member functions defined in class scope are + inline by default. */ + +int flag_default_inline = 1; + +/* Controls whether enums and ints freely convert. + 1 means with complete freedom. + 0 means enums can convert to ints, but not vice-versa. */ +int flag_int_enum_equivalence; + +/* Controls whether compiler is operating under LUCID's Cadillac + system. 1 means yes, 0 means no. */ +int flag_cadillac; + +/* Controls whether compiler generates code to build objects + that can be collected when they become garbage. */ +int flag_gc; + +/* Controls whether compiler generates 'type descriptor' that give + run-time type information. */ +int flag_rtti; + +/* Nonzero if we wish to output cross-referencing information + for the GNU class browser. */ +extern int flag_gnu_xref; + +/* Nonzero if compiler can make `reasonable' assumptions about + references and objects. For example, the compiler must be + conservative about the following and not assume that `a' is nonnull: + + obj &a = g (); + a.f (2); + + In general, it is `reasonable' to assume that for many programs, + and better code can be generated in that case. */ + +int flag_assume_nonnull_objects = 1; + +/* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) + objects. */ + +int flag_huge_objects; + +/* Nonzero if we want to conserve space in the .o files. We do this + by putting uninitialized data and runtime initialized data into + .common instead of .data at the expense of not flagging multiple + definitions. */ + +int flag_conserve_space; + +/* Nonzero if we want to obey access control semantics. */ + +int flag_access_control = 1; + +/* Nonzero if we want to understand the operator names, i.e. 'bitand'. */ + +int flag_operator_names; + +/* Nonzero if we want to check the return value of new and avoid calling + constructors if it is a null pointer. */ + +int flag_check_new; + +/* Nonzero if we want the new ANSI rules for pushing a new scope for `for' + initialization variables. + 0: Old rules, set by -fno-for-scope. + 2: New ANSI rules, set by -ffor-scope. + 1: Try to implement new ANSI rules, but with backup compatibility + (and warnings). This is the default, for now. */ + +int flag_new_for_scope = 1; + +/* Table of language-dependent -f options. + STRING is the option name. VARIABLE is the address of the variable. + ON_VALUE is the value to store in VARIABLE + if `-fSTRING' is seen as an option. + (If `-fno-STRING' is seen as an option, the opposite value is stored.) */ + +static struct { char *string; int *variable; int on_value;} lang_f_options[] = +{ + {"signed-char", &flag_signed_char, 1}, + {"unsigned-char", &flag_signed_char, 0}, + {"signed-bitfields", &flag_signed_bitfields, 1}, + {"unsigned-bitfields", &flag_signed_bitfields, 0}, + {"short-enums", &flag_short_enums, 1}, + {"short-double", &flag_short_double, 1}, + {"cond-mismatch", &flag_cond_mismatch, 1}, + {"asm", &flag_no_asm, 0}, + {"builtin", &flag_no_builtin, 0}, + {"ident", &flag_no_ident, 0}, + {"labels-ok", &flag_labels_ok, 1}, + {"stats", &flag_detailed_statistics, 1}, + {"this-is-variable", &flag_this_is_variable, 1}, + {"strict-prototype", &flag_strict_prototype, 1}, + {"all-virtual", &flag_all_virtual, 1}, + {"memoize-lookups", &flag_memoize_lookups, 1}, + {"elide-constructors", &flag_elide_constructors, 1}, + {"handle-exceptions", &flag_handle_exceptions, 1}, + {"handle-signatures", &flag_handle_signatures, 1}, + {"default-inline", &flag_default_inline, 1}, + {"dollars-in-identifiers", &dollars_in_ident, 1}, + {"enum-int-equiv", &flag_int_enum_equivalence, 1}, + {"gc", &flag_gc, 1}, + {"rtti", &flag_rtti, 1}, + {"xref", &flag_gnu_xref, 1}, + {"nonnull-objects", &flag_assume_nonnull_objects, 1}, + {"implement-inlines", &flag_implement_inlines, 1}, + {"external-templates", &flag_external_templates, 1}, + {"implicit-templates", &flag_implicit_templates, 1}, + {"huge-objects", &flag_huge_objects, 1}, + {"conserve-space", &flag_conserve_space, 1}, + {"vtable-thunks", &flag_vtable_thunks, 1}, + {"short-temps", &flag_short_temps, 1}, + {"access-control", &flag_access_control, 1}, + {"nonansi-builtins", &flag_no_nonansi_builtin, 0}, + {"gnu-keywords", &flag_no_gnu_keywords, 0}, + {"operator-names", &flag_operator_names, 1}, + {"check-new", &flag_check_new, 1}, + {"repo", &flag_use_repository, 1}, + {"for-scope", &flag_new_for_scope, 2} +}; + +/* Decode the string P as a language-specific option. + Return 1 if it is recognized (and handle it); + return 0 if not recognized. */ + +int +lang_decode_option (p) + char *p; +{ + if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) + flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1, + flag_this_is_variable = 1, flag_new_for_scope = 0; + /* The +e options are for cfront compatibility. They come in as + `-+eN', to kludge around gcc.c's argument handling. */ + else if (p[0] == '-' && p[1] == '+' && p[2] == 'e') + { + int old_write_virtuals = write_virtuals; + if (p[3] == '1') + write_virtuals = 1; + else if (p[3] == '0') + write_virtuals = -1; + else if (p[3] == '2') + write_virtuals = 2; + else error ("invalid +e option"); + if (old_write_virtuals != 0 + && write_virtuals != old_write_virtuals) + error ("conflicting +e options given"); + } + else if (p[0] == '-' && p[1] == 'f') + { + /* Some kind of -f option. + P's value is the option sans `-f'. + Search for it in the table of options. */ + int found = 0, j; + + p += 2; + /* Try special -f options. */ + + if (!strcmp (p, "save-memoized")) + { + flag_memoize_lookups = 1; + flag_save_memoized_contexts = 1; + found = 1; + } + if (!strcmp (p, "no-save-memoized")) + { + flag_memoize_lookups = 0; + flag_save_memoized_contexts = 0; + found = 1; + } + else if (! strncmp (p, "cadillac", 8)) + { + flag_cadillac = atoi (p+9); + found = 1; + } + else if (! strncmp (p, "no-cadillac", 11)) + { + flag_cadillac = 0; + found = 1; + } + else if (! strcmp (p, "gc")) + { + flag_gc = 1; + /* This must come along for the ride. */ + flag_rtti = 1; + found = 1; + } + else if (! strcmp (p, "no-gc")) + { + flag_gc = 0; + /* This must come along for the ride. */ + flag_rtti = 0; + found = 1; + } + else if (! strcmp (p, "alt-external-templates")) + { + flag_external_templates = 1; + flag_alt_external_templates = 1; + found = 1; + } + else if (! strcmp (p, "no-alt-external-templates")) + { + flag_alt_external_templates = 0; + found = 1; + } + else if (!strcmp (p, "ansi-overloading")) + { + warning ("-fansi-overloading is no longer meaningful"); + found = 1; + } + else if (!strcmp (p, "repo")) + { + flag_use_repository = 1; + flag_implicit_templates = 0; + found = 1; + } + else for (j = 0; + !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]); + j++) + { + if (!strcmp (p, lang_f_options[j].string)) + { + *lang_f_options[j].variable = lang_f_options[j].on_value; + /* A goto here would be cleaner, + but breaks the vax pcc. */ + found = 1; + } + if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' + && ! strcmp (p+3, lang_f_options[j].string)) + { + *lang_f_options[j].variable = ! lang_f_options[j].on_value; + found = 1; + } + } + return found; + } + else if (p[0] == '-' && p[1] == 'W') + { + int setting = 1; + + /* The -W options control the warning behavior of the compiler. */ + p += 2; + + if (p[0] == 'n' && p[1] == 'o' && p[2] == '-') + setting = 0, p += 3; + + if (!strcmp (p, "implicit")) + warn_implicit = setting; + else if (!strcmp (p, "return-type")) + warn_return_type = setting; + else if (!strcmp (p, "ctor-dtor-privacy")) + warn_ctor_dtor_privacy = setting; + else if (!strcmp (p, "write-strings")) + warn_write_strings = setting; + else if (!strcmp (p, "cast-qual")) + warn_cast_qual = setting; + else if (!strcmp (p, "traditional")) + warn_traditional = setting; + else if (!strcmp (p, "char-subscripts")) + warn_char_subscripts = setting; + else if (!strcmp (p, "pointer-arith")) + warn_pointer_arith = setting; + else if (!strcmp (p, "strict-prototypes")) + warn_strict_prototypes = setting; + else if (!strcmp (p, "missing-prototypes")) + warn_missing_prototypes = setting; + else if (!strcmp (p, "redundant-decls")) + warn_redundant_decls = setting; + else if (!strcmp (p, "missing-braces")) + warn_missing_braces = setting; + else if (!strcmp (p, "format")) + warn_format = setting; + else if (!strcmp (p, "conversion")) + warn_conversion = setting; + else if (!strcmp (p, "parentheses")) + warn_parentheses = setting; + else if (!strcmp (p, "non-virtual-dtor")) + warn_nonvdtor = setting; + else if (!strcmp (p, "extern-inline")) + warn_extern_inline = setting; + else if (!strcmp (p, "reorder")) + warn_reorder = setting; + else if (!strcmp (p, "synth")) + warn_synth = setting; + else if (!strcmp (p, "comment")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "comments")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "trigraphs")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "import")) + ; /* cpp handles this one. */ + else if (!strcmp (p, "all")) + { + extra_warnings = setting; + warn_return_type = setting; + warn_unused = setting; + warn_implicit = setting; + warn_ctor_dtor_privacy = setting; + warn_switch = setting; + warn_format = setting; + warn_parentheses = setting; + warn_missing_braces = setting; + warn_extern_inline = setting; + warn_nonvdtor = setting; + /* We save the value of warn_uninitialized, since if they put + -Wuninitialized on the command line, we need to generate a + warning about not using it without also specifying -O. */ + if (warn_uninitialized != 1) + warn_uninitialized = (setting ? 2 : 0); + warn_template_debugging = setting; + warn_reorder = setting; + } + + else if (!strcmp (p, "overloaded-virtual")) + warn_overloaded_virtual = setting; + else return 0; + } + else if (!strcmp (p, "-ansi")) + dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1, + flag_no_gnu_keywords = 1, flag_operator_names = 1; +#ifdef SPEW_DEBUG + /* Undocumented, only ever used when you're invoking cc1plus by hand, since + it's probably safe to assume no sane person would ever want to use this + under normal circumstances. */ + else if (!strcmp (p, "-spew-debug")) + spew_debug = 1; +#endif + else + return 0; + + return 1; +} + +/* Incorporate `const' and `volatile' qualifiers for member functions. + FUNCTION is a TYPE_DECL or a FUNCTION_DECL. + QUALS is a list of qualifiers. */ +tree +grok_method_quals (ctype, function, quals) + tree ctype, function, quals; +{ + tree fntype = TREE_TYPE (function); + tree raises = TYPE_RAISES_EXCEPTIONS (fntype); + + do + { + extern tree ridpointers[]; + + if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST]) + { + if (TYPE_READONLY (ctype)) + error ("duplicate `%s' %s", + IDENTIFIER_POINTER (TREE_VALUE (quals)), + (TREE_CODE (function) == FUNCTION_DECL + ? "for member function" : "in type declaration")); + ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype)); + build_pointer_type (ctype); + } + else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE]) + { + if (TYPE_VOLATILE (ctype)) + error ("duplicate `%s' %s", + IDENTIFIER_POINTER (TREE_VALUE (quals)), + (TREE_CODE (function) == FUNCTION_DECL + ? "for member function" : "in type declaration")); + ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1); + build_pointer_type (ctype); + } + else + my_friendly_abort (20); + quals = TREE_CHAIN (quals); + } + while (quals); + fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype), + (TREE_CODE (fntype) == METHOD_TYPE + ? TREE_CHAIN (TYPE_ARG_TYPES (fntype)) + : TYPE_ARG_TYPES (fntype))); + if (raises) + fntype = build_exception_variant (fntype, raises); + + TREE_TYPE (function) = fntype; + return ctype; +} + +#if 0 /* Not used. */ +/* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs. + It leaves DECL_ASSEMBLER_NAMEs with the correct value. */ +/* This does not yet work with user defined conversion operators + It should. */ +static void +substitute_nice_name (decl) + tree decl; +{ + if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE) + { + char *n = decl_as_string (DECL_NAME (decl), 1); + if (n[strlen (n) - 1] == ' ') + n[strlen (n) - 1] = 0; + DECL_NAME (decl) = get_identifier (n); + } +} +#endif + +/* Warn when -fexternal-templates is used and #pragma + interface/implementation is not used all the times it should be, + inform the user. */ +void +warn_if_unknown_interface (decl) + tree decl; +{ + static int already_warned = 0; + if (already_warned++) + return; + + if (flag_alt_external_templates) + { + struct tinst_level *til = tinst_for_decl (); + int sl = lineno; + char *sf = input_filename; + + if (til) + { + lineno = til->line; + input_filename = til->file; + } + cp_warning ("template `%#D' instantiated in file without #pragma interface", + decl); + lineno = sl; + input_filename = sf; + } + else + cp_warning_at ("template `%#D' defined in file without #pragma interface", + decl); +} + +/* A subroutine of the parser, to handle a component list. */ +tree +grok_x_components (specs, components) + tree specs, components; +{ + register tree t, x, tcode; + + /* We just got some friends. They have been recorded elsewhere. */ + if (components == void_type_node) + return NULL_TREE; + + if (components == NULL_TREE) + { + t = groktypename (build_decl_list (specs, NULL_TREE)); + + if (t == NULL_TREE) + { + error ("error in component specification"); + return NULL_TREE; + } + + switch (TREE_CODE (t)) + { + case VAR_DECL: + /* Static anonymous unions come out as VAR_DECLs. */ + if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t)))) + return t; + + /* We return SPECS here, because in the parser it was ending + up with not doing anything to $$, which is what SPECS + represents. */ + return specs; + break; + + case RECORD_TYPE: + /* This code may be needed for UNION_TYPEs as + well. */ + tcode = record_type_node; + if (CLASSTYPE_DECLARED_CLASS(t)) + tcode = class_type_node; + else if (IS_SIGNATURE(t)) + tcode = signature_type_node; + + t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0); + if (TYPE_CONTEXT(t)) + CLASSTYPE_NO_GLOBALIZE(t) = 1; + return NULL_TREE; + break; + + case UNION_TYPE: + case ENUMERAL_TYPE: + if (TREE_CODE(t) == UNION_TYPE) + tcode = union_type_node; + else + tcode = enum_type_node; + + t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0); + if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t)) + CLASSTYPE_NO_GLOBALIZE(t) = 1; + if (TREE_CODE (t) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) + { + struct pending_inline **p; + x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t); + + /* Wipe out memory of synthesized methods */ + TYPE_HAS_CONSTRUCTOR (t) = 0; + TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; + TYPE_HAS_INIT_REF (t) = 0; + TYPE_HAS_CONST_INIT_REF (t) = 0; + TYPE_HAS_ASSIGN_REF (t) = 0; + TYPE_HAS_ASSIGNMENT (t) = 0; + TYPE_HAS_CONST_ASSIGN_REF (t) = 0; + + p = &pending_inlines; + for (; *p; *p = (*p)->next) + if (DECL_CONTEXT ((*p)->fndecl) != t) + break; + } + else if (TREE_CODE (t) == ENUMERAL_TYPE) + x = grok_enum_decls (t, NULL_TREE); + else + x = NULL_TREE; + return x; + break; + + default: + if (t != void_type_node) + error ("empty component declaration"); + return NULL_TREE; + } + } + else + { + t = TREE_TYPE (components); + if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t)) + return grok_enum_decls (t, components); + else + return components; + } +} + +/* Classes overload their constituent function names automatically. + When a function name is declared in a record structure, + its name is changed to it overloaded name. Since names for + constructors and destructors can conflict, we place a leading + '$' for destructors. + + CNAME is the name of the class we are grokking for. + + FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'. + + FLAGS contains bits saying what's special about today's + arguments. 1 == DESTRUCTOR. 2 == OPERATOR. + + If FUNCTION is a destructor, then we must add the `auto-delete' field + as a second parameter. There is some hair associated with the fact + that we must "declare" this variable in the manner consistent with the + way the rest of the arguments were declared. + + QUALS are the qualifiers for the this pointer. */ + +void +grokclassfn (ctype, cname, function, flags, quals) + tree ctype, cname, function; + enum overload_flags flags; + tree quals; +{ + tree fn_name = DECL_NAME (function); + tree arg_types; + tree parm; + tree qualtype; + tree fntype = TREE_TYPE (function); + tree raises = TYPE_RAISES_EXCEPTIONS (fntype); + + if (fn_name == NULL_TREE) + { + error ("name missing for member function"); + fn_name = get_identifier (""); + DECL_NAME (function) = fn_name; + } + + if (quals) + qualtype = grok_method_quals (ctype, function, quals); + else + qualtype = ctype; + + arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); + if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) + { + /* Must add the class instance variable up front. */ + /* Right now we just make this a pointer. But later + we may wish to make it special. */ + tree type = TREE_VALUE (arg_types); + int constp = 1; + + if ((flag_this_is_variable > 0) + && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function))) + constp = 0; + + if (DECL_CONSTRUCTOR_P (function)) + { + if (TYPE_USES_VIRTUAL_BASECLASSES (ctype)) + { + DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1; + /* In this case we need "in-charge" flag saying whether + this constructor is responsible for initialization + of virtual baseclasses or not. */ + parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); + /* Mark the artificial `__in_chrg' parameter as "artificial". */ + SET_DECL_ARTIFICIAL (parm); + DECL_ARG_TYPE (parm) = integer_type_node; + DECL_REGISTER (parm) = 1; + TREE_CHAIN (parm) = last_function_parms; + last_function_parms = parm; + } + } + + parm = build_decl (PARM_DECL, this_identifier, type); + /* Mark the artificial `this' parameter as "artificial". */ + SET_DECL_ARTIFICIAL (parm); + DECL_ARG_TYPE (parm) = type; + /* We can make this a register, so long as we don't + accidentally complain if someone tries to take its address. */ + DECL_REGISTER (parm) = 1; + if (constp) + TREE_READONLY (parm) = 1; + TREE_CHAIN (parm) = last_function_parms; + last_function_parms = parm; + } + + if (flags == DTOR_FLAG) + { + char *buf, *dbuf; + tree const_integer_type = build_type_variant (integer_type_node, 1, 0); + int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1; + + arg_types = hash_tree_chain (const_integer_type, void_list_node); + TREE_SIDE_EFFECTS (arg_types) = 1; + /* Build the overload name. It will look like `7Example'. */ + if (IDENTIFIER_TYPE_VALUE (cname)) + dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1); + else if (IDENTIFIER_LOCAL_VALUE (cname)) + dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1); + else + /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when + it's defined out of the class definition, since poplevel_class wipes + it out. This used to be internal error 346. */ + dbuf = build_overload_name (ctype, 1, 1); + buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX)); + bcopy (DESTRUCTOR_DECL_PREFIX, buf, len); + buf[len] = '\0'; + strcat (buf, dbuf); + DECL_ASSEMBLER_NAME (function) = get_identifier (buf); + parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type); + /* Mark the artificial `__in_chrg' parameter as "artificial". */ + SET_DECL_ARTIFICIAL (parm); + TREE_USED (parm) = 1; +#if 0 + /* We don't need to mark the __in_chrg parameter itself as `const' + since its type is already `const int'. In fact we MUST NOT mark + it as `const' cuz that will screw up the debug info (causing it + to say that the type of __in_chrg is `const const int'). */ + TREE_READONLY (parm) = 1; +#endif + DECL_ARG_TYPE (parm) = const_integer_type; + /* This is the same chain as DECL_ARGUMENTS (...). */ + TREE_CHAIN (last_function_parms) = parm; + + fntype = build_cplus_method_type (qualtype, void_type_node, + arg_types); + if (raises) + { + fntype = build_exception_variant (fntype, raises); + } + TREE_TYPE (function) = fntype; + TYPE_HAS_DESTRUCTOR (ctype) = 1; + } + else + { + tree these_arg_types; + + if (DECL_CONSTRUCTOR_FOR_VBASE_P (function)) + { + arg_types = hash_tree_chain (integer_type_node, + TREE_CHAIN (arg_types)); + fntype = build_cplus_method_type (qualtype, + TREE_TYPE (TREE_TYPE (function)), + arg_types); + if (raises) + { + fntype = build_exception_variant (fntype, raises); + } + TREE_TYPE (function) = fntype; + arg_types = TYPE_ARG_TYPES (TREE_TYPE (function)); + } + + these_arg_types = arg_types; + + if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE) + /* Only true for static member functions. */ + these_arg_types = hash_tree_chain (build_pointer_type (qualtype), + arg_types); + + DECL_ASSEMBLER_NAME (function) + = build_decl_overload (fn_name, these_arg_types, + 1 + DECL_CONSTRUCTOR_P (function)); + +#if 0 + /* This code is going into the compiler, but currently, it makes + libg++/src/Integer.cc not compile. The problem is that the nice name + winds up going into the symbol table, and conversion operations look + for the manged name. */ + substitute_nice_name (function); +#endif + } + + DECL_ARGUMENTS (function) = last_function_parms; + /* First approximations. */ + DECL_CONTEXT (function) = ctype; + DECL_CLASS_CONTEXT (function) = ctype; +} + +/* Work on the expr used by alignof (this is only called by the parser). */ +tree +grok_alignof (expr) + tree expr; +{ + tree best, t; + int bestalign; + + if (TREE_CODE (expr) == COMPONENT_REF + && DECL_BIT_FIELD (TREE_OPERAND (expr, 1))) + error ("`__alignof__' applied to a bit-field"); + + if (TREE_CODE (expr) == INDIRECT_REF) + { + best = t = TREE_OPERAND (expr, 0); + bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); + + while (TREE_CODE (t) == NOP_EXPR + && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE) + { + int thisalign; + t = TREE_OPERAND (t, 0); + thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t))); + if (thisalign > bestalign) + best = t, bestalign = thisalign; + } + return c_alignof (TREE_TYPE (TREE_TYPE (best))); + } + else + { + /* ANSI says arrays and fns are converted inside comma. + But we can't convert them in build_compound_expr + because that would break commas in lvalues. + So do the conversion here if operand was a comma. */ + if (TREE_CODE (expr) == COMPOUND_EXPR + && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)) + expr = default_conversion (expr); + return c_alignof (TREE_TYPE (expr)); + } +} + +/* Create an ARRAY_REF, checking for the user doing things backwards + along the way. */ +tree +grok_array_decl (array_expr, index_exp) + tree array_expr, index_exp; +{ + tree type = TREE_TYPE (array_expr); + tree p1, p2, i1, i2; + + if (type == error_mark_node || index_exp == error_mark_node) + return error_mark_node; + if (type == NULL_TREE) + { + /* Something has gone very wrong. Assume we are mistakenly reducing + an expression instead of a declaration. */ + error ("parser may be lost: is there a '{' missing somewhere?"); + return NULL_TREE; + } + + if (TREE_CODE (type) == OFFSET_TYPE + || TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* If they have an `operator[]', use that. */ + if (TYPE_LANG_SPECIFIC (type) + && TYPE_OVERLOADS_ARRAY_REF (type)) + return build_opfncall (ARRAY_REF, LOOKUP_NORMAL, + array_expr, index_exp, NULL_TREE); + + /* Otherwise, create an ARRAY_REF for a pointer or array type. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + p1 = array_expr; + else + p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0); + + if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE) + p2 = index_exp; + else + p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0); + + i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0); + i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0); + + if ((p1 && i2) && (i1 && p2)) + error ("ambiguous conversion for array subscript"); + + if (p1 && i2) + array_expr = p1, index_exp = i2; + else if (i1 && p2) + array_expr = p2, index_exp = i1; + else + { + cp_error ("invalid types `%T[%T]' for array subscript", + type, TREE_TYPE (index_exp)); + return error_mark_node; + } + + if (array_expr == error_mark_node || index_exp == error_mark_node) + error ("ambiguous conversion for array subscript"); + + return build_array_ref (array_expr, index_exp); +} + +/* Given the cast expression EXP, checking out its validity. Either return + an error_mark_node if there was an unavoidable error, return a cast to + void for trying to delete a pointer w/ the value 0, or return the + call to delete. If DOING_VEC is 1, we handle things differently + for doing an array delete. If DOING_VEC is 2, they gave us the + array size as an argument to delete. + Implements ARM $5.3.4. This is called from the parser. */ +tree +delete_sanity (exp, size, doing_vec, use_global_delete) + tree exp, size; + int doing_vec, use_global_delete; +{ + tree t = stabilize_reference (convert_from_reference (exp)); + tree type = TREE_TYPE (t); + enum tree_code code = TREE_CODE (type); + /* For a regular vector delete (aka, no size argument) we will pass + this down as a NULL_TREE into build_vec_delete. */ + tree maxindex = NULL_TREE; + /* This is used for deleting arrays. */ + tree elt_size; + + switch (doing_vec) + { + case 2: + maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1); + if (! flag_traditional) + pedwarn ("anachronistic use of array size in vector delete"); + /* Fall through. */ + case 1: + elt_size = c_sizeof (type); + break; + default: + if (code != POINTER_TYPE) + { + cp_error ("type `%#T' argument given to `delete', expected pointer", + type); + return error_mark_node; + } + + /* Deleting a pointer with the value zero is valid and has no effect. */ + if (integer_zerop (t)) + return build1 (NOP_EXPR, void_type_node, t); + } + + if (code == POINTER_TYPE) + { +#if 0 + /* As of Valley Forge, you can delete a pointer to constant. */ + /* You can't delete a pointer to constant. */ + if (TREE_READONLY (TREE_TYPE (type))) + { + error ("`const *' cannot be deleted"); + return error_mark_node; + } +#endif + /* You also can't delete functions. */ + if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + { + error ("cannot delete a function"); + return error_mark_node; + } + } + +#if 0 + /* If the type has no destructor, then we should build a regular + delete, instead of a vector delete. Otherwise, we would end + up passing a bogus offset into __builtin_delete, which is + not expecting it. */ + if (doing_vec + && TREE_CODE (type) == POINTER_TYPE + && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type))) + { + doing_vec = 0; + use_global_delete = 1; + } +#endif + + if (doing_vec) + return build_vec_delete (t, maxindex, elt_size, integer_one_node, + integer_two_node, use_global_delete); + else + { + if (IS_AGGR_TYPE (TREE_TYPE (type)) + && TYPE_GETS_REG_DELETE (TREE_TYPE (type))) + { + /* Only do access checking here; we'll be calling op delete + from the destructor. */ + tree tmp = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, t, + size_zero_node, NULL_TREE); + if (tmp == error_mark_node) + return error_mark_node; + } + + return build_delete (type, t, integer_three_node, + LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, + use_global_delete); + } +} + +/* Sanity check: report error if this function FUNCTION is not + really a member of the class (CTYPE) it is supposed to belong to. + CNAME is the same here as it is for grokclassfn above. */ + +tree +check_classfn (ctype, cname, function) + tree ctype, cname, function; +{ + tree fn_name = DECL_NAME (function); + tree fndecl; + tree method_vec = CLASSTYPE_METHOD_VEC (ctype); + tree *methods = 0; + tree *end = 0; + + if (method_vec != 0) + { + methods = &TREE_VEC_ELT (method_vec, 0); + end = TREE_VEC_END (method_vec); + + /* First suss out ctors and dtors. */ + if (*methods && fn_name == DECL_NAME (*methods)) + goto got_it; + + while (++methods != end) + { + if (fn_name == DECL_NAME (*methods)) + { + got_it: + fndecl = *methods; + while (fndecl) + { + if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl)) + return fndecl; +#if 0 + /* This should work, but causes libg++ to fail + make check-tFix. */ + /* We have to do more extensive argument checking here, as + the name may have been changed by asm("new_name"). */ + if (decls_match (function, fndecl)) + return fndecl; +#else + if (DECL_NAME (function) == DECL_NAME (fndecl)) + { + tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function)); + tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + + /* Get rid of the this parameter on functions that become + static. */ + if (DECL_STATIC_FUNCTION_P (fndecl) + && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) + p1 = TREE_CHAIN (p1); + + if (comptypes (TREE_TYPE (TREE_TYPE (function)), + TREE_TYPE (TREE_TYPE (fndecl)), 1) + && compparms (p1, p2, 3)) + { + if (DECL_STATIC_FUNCTION_P (fndecl) + && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE) + revert_static_member_fn (&function, NULL, NULL); + return fndecl; + } + } +#endif + fndecl = DECL_CHAIN (fndecl); + } + break; /* loser */ + } + } + } + + if (methods != end) + { + tree fndecl = *methods; + cp_error ("prototype for `%#D' does not match any in class `%T'", + function, ctype); + cp_error_at ("candidate%s: %+#D", DECL_CHAIN (fndecl) ? "s are" : " is", + fndecl); + while (fndecl = DECL_CHAIN (fndecl), fndecl) + cp_error_at (" %#D", fndecl); + } + else + { + methods = 0; + cp_error ("no `%#D' member function declared in class `%T'", + function, ctype); + } + + /* If we did not find the method in the class, add it to + avoid spurious errors. */ + add_method (ctype, methods, function); + return NULL_TREE; +} + +/* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) + of a structure component, returning a FIELD_DECL node. + QUALS is a list of type qualifiers for this decl (such as for declaring + const member functions). + + This is done during the parsing of the struct declaration. + The FIELD_DECL nodes are chained together and the lot of them + are ultimately passed to `build_struct' to make the RECORD_TYPE node. + + C++: + + If class A defines that certain functions in class B are friends, then + the way I have set things up, it is B who is interested in permission + granted by A. However, it is in A's context that these declarations + are parsed. By returning a void_type_node, class A does not attempt + to incorporate the declarations of the friends within its structure. + + DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING + CHANGES TO CODE IN `start_method'. */ + +tree +grokfield (declarator, declspecs, raises, init, asmspec_tree, attrlist) + tree declarator, declspecs, raises, init, asmspec_tree, attrlist; +{ + register tree value; + char *asmspec = 0; + int flags = LOOKUP_ONLYCONVERTING; + + /* Convert () initializers to = initializers. */ + if (init == NULL_TREE && declarator != NULL_TREE + && TREE_CODE (declarator) == CALL_EXPR + && TREE_OPERAND (declarator, 0) + && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE + || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF) + && parmlist_is_exprlist (TREE_OPERAND (declarator, 1))) + { + init = TREE_OPERAND (declarator, 1); + declarator = TREE_OPERAND (declarator, 0); + flags = 0; + } + + if (init + && TREE_CODE (init) == TREE_LIST + && TREE_VALUE (init) == error_mark_node + && TREE_CHAIN (init) == NULL_TREE) + init = NULL_TREE; + + value = grokdeclarator (declarator, declspecs, FIELD, init != 0, + raises, attrlist); + if (! value) + return value; /* friend or constructor went bad. */ + + /* Pass friendly classes back. */ + if (TREE_CODE (value) == VOID_TYPE) + return void_type_node; + + if (DECL_NAME (value) != NULL_TREE + && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_' + && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr")) + cp_error ("member `%D' conflicts with virtual function table field name", value); + + /* Stash away type declarations. */ + if (TREE_CODE (value) == TYPE_DECL) + { + DECL_NONLOCAL (value) = 1; + DECL_CONTEXT (value) = current_class_type; + DECL_CLASS_CONTEXT (value) = current_class_type; + CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1; + + /* If we declare a typedef name for something that has no name, + the typedef name is used for linkage. See 7.1.3 p4 94/0158. */ + if (TYPE_NAME (TREE_TYPE (value)) + && TREE_CODE (TYPE_NAME (TREE_TYPE (value))) == TYPE_DECL + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value)))) + { + TYPE_NAME (TREE_TYPE (value)) = value; + TYPE_STUB_DECL (TREE_TYPE (value)) = value; + } + + pushdecl_class_level (value); + return value; + } + + if (IS_SIGNATURE (current_class_type) + && TREE_CODE (value) != FUNCTION_DECL) + { + error ("field declaration not allowed in signature"); + return void_type_node; + } + + if (DECL_IN_AGGR_P (value)) + { + cp_error ("`%D' is already defined in the class %T", value, + DECL_CONTEXT (value)); + return void_type_node; + } + + if (flag_cadillac) + cadillac_start_decl (value); + + if (asmspec_tree) + asmspec = TREE_STRING_POINTER (asmspec_tree); + + if (init) + { + if (IS_SIGNATURE (current_class_type) + && TREE_CODE (value) == FUNCTION_DECL) + { + error ("function declarations cannot have initializers in signature"); + init = NULL_TREE; + } + else if (TREE_CODE (value) == FUNCTION_DECL) + { + grok_function_init (value, init); + init = NULL_TREE; + } + else if (pedantic && TREE_CODE (value) != VAR_DECL) + /* Already complained in grokdeclarator. */ + init = NULL_TREE; + else + { + /* We allow initializers to become parameters to base + initializers. */ + if (TREE_CODE (init) == TREE_LIST) + { + if (TREE_CHAIN (init) == NULL_TREE) + init = TREE_VALUE (init); + else + init = digest_init (TREE_TYPE (value), init, (tree *)0); + } + + if (TREE_CODE (init) == CONST_DECL) + init = DECL_INITIAL (init); + else if (TREE_READONLY_DECL_P (init)) + init = decl_constant_value (init); + else if (TREE_CODE (init) == CONSTRUCTOR) + init = digest_init (TREE_TYPE (value), init, (tree *)0); + my_friendly_assert (TREE_PERMANENT (init), 192); + if (init == error_mark_node) + /* We must make this look different than `error_mark_node' + because `decl_const_value' would mis-interpret it + as only meaning that this VAR_DECL is defined. */ + init = build1 (NOP_EXPR, TREE_TYPE (value), init); + else if (! TREE_CONSTANT (init)) + { + /* We can allow references to things that are effectively + static, since references are initialized with the address. */ + if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE + || (TREE_STATIC (init) == 0 + && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd' + || DECL_EXTERNAL (init) == 0))) + { + error ("field initializer is not constant"); + init = error_mark_node; + } + } + } + } + + /* The corresponding pop_obstacks is in cp_finish_decl. */ + push_obstacks_nochange (); + + if (TREE_CODE (value) == VAR_DECL) + { + /* We cannot call pushdecl here, because that would + fill in the value of our TREE_CHAIN. Instead, we + modify cp_finish_decl to do the right thing, namely, to + put this decl out straight away. */ + if (TREE_PUBLIC (value)) + { + /* current_class_type can be NULL_TREE in case of error. */ + if (asmspec == 0 && current_class_type) + { + TREE_PUBLIC (value) = 1; + DECL_INITIAL (value) = error_mark_node; + DECL_ASSEMBLER_NAME (value) + = build_static_name (current_class_type, DECL_NAME (value)); + } + pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics); + + /* Static consts need not be initialized in the class definition. */ + if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value))) + { + static int explanation = 0; + + error ("initializer invalid for static member with constructor"); + if (explanation++ == 0) + error ("(you really want to initialize it separately)"); + init = 0; + } + /* Force the compiler to know when an uninitialized static + const member is being used. */ + if (TYPE_READONLY (value) && init == 0) + TREE_USED (value) = 1; + } + DECL_INITIAL (value) = init; + DECL_IN_AGGR_P (value) = 1; + + cp_finish_decl (value, init, asmspec_tree, 1, flags); + pushdecl_class_level (value); + return value; + } + if (TREE_CODE (value) == FIELD_DECL) + { + if (asmspec) + { + /* This must override the asm specifier which was placed + by grokclassfn. Lay this out fresh. */ + DECL_RTL (value) = NULL_RTX; + DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); + } + if (DECL_INITIAL (value) == error_mark_node) + init = error_mark_node; + cp_finish_decl (value, init, asmspec_tree, 1, flags); + DECL_INITIAL (value) = init; + DECL_IN_AGGR_P (value) = 1; + return value; + } + if (TREE_CODE (value) == FUNCTION_DECL) + { + check_default_args (value); + if (DECL_CHAIN (value) != NULL_TREE) + { + /* Need a fresh node here so that we don't get circularity + when we link these together. */ + value = copy_node (value); + /* When does this happen? */ + my_friendly_assert (init == NULL_TREE, 193); + } + if (asmspec) + { + /* This must override the asm specifier which was placed + by grokclassfn. Lay this out fresh. */ + DECL_RTL (value) = NULL_RTX; + DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); + } + cp_finish_decl (value, init, asmspec_tree, 1, flags); + + /* Pass friends back this way. */ + if (DECL_FRIEND_P (value)) + return void_type_node; + +#if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */ + if (current_function_decl && ! IS_SIGNATURE (current_class_type)) + cp_error ("method `%#D' of local class must be defined in class body", + value); +#endif + + DECL_IN_AGGR_P (value) = 1; + return value; + } + my_friendly_abort (21); + /* NOTREACHED */ + return NULL_TREE; +} + +/* Like `grokfield', but for bitfields. + WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */ + +tree +grokbitfield (declarator, declspecs, width) + tree declarator, declspecs, width; +{ + register tree value = grokdeclarator (declarator, declspecs, BITFIELD, + 0, NULL_TREE, NULL_TREE); + + if (! value) return NULL_TREE; /* friends went bad. */ + + /* Pass friendly classes back. */ + if (TREE_CODE (value) == VOID_TYPE) + return void_type_node; + + if (TREE_CODE (value) == TYPE_DECL) + { + cp_error ("cannot declare `%D' to be a bitfield type", value); + return NULL_TREE; + } + + if (IS_SIGNATURE (current_class_type)) + { + error ("field declaration not allowed in signature"); + return void_type_node; + } + + if (DECL_IN_AGGR_P (value)) + { + cp_error ("`%D' is already defined in the class %T", value, + DECL_CONTEXT (value)); + return void_type_node; + } + + GNU_xref_member (current_class_name, value); + + if (TREE_STATIC (value)) + { + cp_error ("static member `%D' cannot be a bitfield", value); + return NULL_TREE; + } + cp_finish_decl (value, NULL_TREE, NULL_TREE, 0, 0); + + if (width != error_mark_node) + { + /* detect invalid field size. */ + if (TREE_CODE (width) == CONST_DECL) + width = DECL_INITIAL (width); + else if (TREE_READONLY_DECL_P (width)) + width = decl_constant_value (width); + if (TREE_CODE (width) != INTEGER_CST) + { + cp_error ("structure field `%D' width not an integer constant", + value); + DECL_INITIAL (value) = NULL_TREE; + } + else + { + constant_expression_warning (width); + DECL_INITIAL (value) = width; + DECL_BIT_FIELD (value) = 1; + } + } + + DECL_IN_AGGR_P (value) = 1; + return value; +} + +#if 0 +/* Like GROKFIELD, except that the declarator has been + buried in DECLSPECS. Find the declarator, and + return something that looks like it came from + GROKFIELD. */ +tree +groktypefield (declspecs, parmlist) + tree declspecs; + tree parmlist; +{ + tree spec = declspecs; + tree prev = NULL_TREE; + + tree type_id = NULL_TREE; + tree quals = NULL_TREE; + tree lengths = NULL_TREE; + tree decl = NULL_TREE; + + while (spec) + { + register tree id = TREE_VALUE (spec); + + if (TREE_CODE (spec) != TREE_LIST) + /* Certain parse errors slip through. For example, + `int class ();' is not caught by the parser. Try + weakly to recover here. */ + return NULL_TREE; + + if (TREE_CODE (id) == TYPE_DECL + || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id))) + { + /* We have a constructor/destructor or + conversion operator. Use it. */ + if (prev) + TREE_CHAIN (prev) = TREE_CHAIN (spec); + else + declspecs = TREE_CHAIN (spec); + + type_id = id; + goto found; + } + prev = spec; + spec = TREE_CHAIN (spec); + } + + /* Nope, we have a conversion operator to a scalar type or something + else, that includes things like constructor declarations for + templates. */ + spec = declspecs; + while (spec) + { + tree id = TREE_VALUE (spec); + + if (TREE_CODE (id) == IDENTIFIER_NODE) + { + if (id == ridpointers[(int)RID_INT] + || id == ridpointers[(int)RID_DOUBLE] + || id == ridpointers[(int)RID_FLOAT] + || id == ridpointers[(int)RID_WCHAR]) + { + if (type_id) + error ("extra `%s' ignored", + IDENTIFIER_POINTER (id)); + else + type_id = id; + } + else if (id == ridpointers[(int)RID_LONG] + || id == ridpointers[(int)RID_SHORT] + || id == ridpointers[(int)RID_CHAR]) + { + lengths = tree_cons (NULL_TREE, id, lengths); + } + else if (id == ridpointers[(int)RID_VOID]) + { + if (type_id) + error ("spurious `void' type ignored"); + else + error ("conversion to `void' type invalid"); + } + else if (id == ridpointers[(int)RID_AUTO] + || id == ridpointers[(int)RID_REGISTER] + || id == ridpointers[(int)RID_TYPEDEF] + || id == ridpointers[(int)RID_CONST] + || id == ridpointers[(int)RID_VOLATILE]) + { + error ("type specifier `%s' used invalidly", + IDENTIFIER_POINTER (id)); + } + else if (id == ridpointers[(int)RID_FRIEND] + || id == ridpointers[(int)RID_VIRTUAL] + || id == ridpointers[(int)RID_INLINE] + || id == ridpointers[(int)RID_UNSIGNED] + || id == ridpointers[(int)RID_SIGNED] + || id == ridpointers[(int)RID_STATIC] + || id == ridpointers[(int)RID_EXTERN]) + { + quals = tree_cons (NULL_TREE, id, quals); + } + else + { + /* Happens when we have a global typedef + and a class-local member function with + the same name. */ + type_id = id; + goto found; + } + } + else if (TREE_CODE (id) == RECORD_TYPE) + { + type_id = TYPE_NAME (id); + if (TREE_CODE (type_id) == TYPE_DECL) + type_id = DECL_NAME (type_id); + if (type_id == NULL_TREE) + error ("identifier for aggregate type conversion omitted"); + } + else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't') + error ("`operator' missing on conversion operator or tag missing from type"); + else + my_friendly_abort (194); + spec = TREE_CHAIN (spec); + } + + if (type_id) + declspecs = chainon (lengths, quals); + else if (lengths) + { + if (TREE_CHAIN (lengths)) + error ("multiple length specifiers"); + type_id = ridpointers[(int)RID_INT]; + declspecs = chainon (lengths, quals); + } + else if (quals) + { + error ("no type given, defaulting to `operator int ...'"); + type_id = ridpointers[(int)RID_INT]; + declspecs = quals; + } + else + return NULL_TREE; + + found: + decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE), + declspecs, FIELD, 0, NULL_TREE, NULL_TREE); + if (decl == NULL_TREE) + return NULL_TREE; + + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE) + { + /* Need a fresh node here so that we don't get circularity + when we link these together. */ + decl = copy_node (decl); + } + + if (decl == void_type_node + || (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE)) + /* bunch of friends. */ + return decl; + + if (DECL_IN_AGGR_P (decl)) + { + cp_error ("`%D' already defined in the class ", decl); + return void_type_node; + } + + cp_finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0); + + /* If this declaration is common to another declaration + complain about such redundancy, and return NULL_TREE + so that we don't build a circular list. */ + if (DECL_CHAIN (decl)) + { + cp_error ("function `%D' declared twice in class %T", decl, + DECL_CONTEXT (decl)); + return NULL_TREE; + } + DECL_IN_AGGR_P (decl) = 1; + return decl; +} +#endif + +tree +grokoptypename (declspecs, declarator) + tree declspecs, declarator; +{ + tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, + NULL_TREE, NULL_TREE); + return build_typename_overload (t); +} + +/* When a function is declared with an initializer, + do the right thing. Currently, there are two possibilities: + + class B + { + public: + // initialization possibility #1. + virtual void f () = 0; + int g (); + }; + + class D1 : B + { + public: + int d1; + // error, no f (); + }; + + class D2 : B + { + public: + int d2; + void f (); + }; + + class D3 : B + { + public: + int d3; + // initialization possibility #2 + void f () = B::f; + }; + +*/ + +int +copy_assignment_arg_p (parmtype, virtualp) + tree parmtype; + int virtualp; +{ + if (TREE_CODE (parmtype) == REFERENCE_TYPE) + parmtype = TREE_TYPE (parmtype); + + if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type) + || (virtualp && DERIVED_FROM_P (parmtype, current_class_type))) + return 1; + + return 0; +} + +static void +grok_function_init (decl, init) + tree decl; + tree init; +{ + /* An initializer for a function tells how this function should + be inherited. */ + tree type = TREE_TYPE (decl); + + if (TREE_CODE (type) == FUNCTION_TYPE) + cp_error ("initializer specified for non-member function `%D'", decl); + else if (DECL_VINDEX (decl) == NULL_TREE) + cp_error ("initializer specified for non-virtual method `%D'", decl); + else if (integer_zerop (init)) + { +#if 0 + /* Mark this function as being "defined". */ + DECL_INITIAL (decl) = error_mark_node; + /* pure virtual destructors must be defined. */ + /* pure virtual needs to be defined (as abort) only when put in + vtbl. For wellformed call, it should be itself. pr4737 */ + if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))) + { + extern tree abort_fndecl; + /* Give this node rtl from `abort'. */ + DECL_RTL (decl) = DECL_RTL (abort_fndecl); + } +#endif + DECL_ABSTRACT_VIRTUAL_P (decl) = 1; + if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR]) + { + tree parmtype + = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))); + + if (copy_assignment_arg_p (parmtype, 1)) + TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; + } + } + else if (TREE_CODE (init) == OFFSET_REF + && TREE_OPERAND (init, 0) == NULL_TREE + && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE) + { + tree basetype = DECL_CLASS_CONTEXT (init); + tree basefn = TREE_OPERAND (init, 1); + if (TREE_CODE (basefn) != FUNCTION_DECL) + cp_error ("non-method initializer invalid for method `%D'", decl); + else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn)))) + sorry ("base member function from other than first base class"); + else + { + tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1); + if (binfo == error_mark_node) + ; + else if (binfo == 0) + error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)), + TYPE_METHOD_BASETYPE (type)); + else + { + /* Mark this function as being defined, + and give it new rtl. */ + DECL_INITIAL (decl) = error_mark_node; + DECL_RTL (decl) = DECL_RTL (basefn); + } + } + } + else + cp_error ("invalid initializer for virtual method `%D'", decl); +} + +/* When we get a declaration of the form + + type cname::fname ... + + the node for `cname::fname' gets built here in a special way. + Namely, we push into `cname's scope. When this declaration is + processed, we pop back out. */ +tree +build_push_scope (cname, name) + tree cname; + tree name; +{ + extern int current_class_depth; + tree ctype, rval; + int is_ttp = 0; + + if (cname == error_mark_node) + return error_mark_node; + + ctype = IDENTIFIER_TYPE_VALUE (cname); + + if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM) + is_ttp = 1; + else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype)) + { + cp_error ("`%T' not defined as aggregate type", cname); + return name; + } + else if (IS_SIGNATURE (ctype)) + { + error ("cannot push into signature scope, scope resolution operator ignored"); + return name; + } + + rval = build_parse_node (SCOPE_REF, cname, name); + + /* Don't need to push the scope if we're already in it. + We also don't need to push the scope for a ptr-to-member/method. */ + + if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE + || is_ttp) + return rval; + + /* We do need to push the scope in this case, since CTYPE helps + determine subsequent initializers (i.e., Foo::Bar x = foo_enum_1;). */ + + push_nested_class (ctype, 3); + TREE_COMPLEXITY (rval) = current_class_depth; + return rval; +} + +void +cplus_decl_attributes (decl, attributes, prefix_attributes) + tree decl, attributes, prefix_attributes; +{ + if (decl == NULL_TREE || decl == void_type_node) + return; + + if (TREE_CODE (decl) == TEMPLATE_DECL) + decl = DECL_TEMPLATE_RESULT (decl); + + decl_attributes (decl, attributes, prefix_attributes); + + if (TREE_CODE (decl) == TYPE_DECL) + SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), TREE_TYPE (decl)); +} + +/* CONSTRUCTOR_NAME: + Return the name for the constructor (or destructor) for the + specified class. Argument can be RECORD_TYPE, TYPE_DECL, or + IDENTIFIER_NODE. When given a template, this routine doesn't + lose the specialization. */ +tree +constructor_name_full (thing) + tree thing; +{ + if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE) + return DECL_NAME (UPT_TEMPLATE (thing)); + if (IS_AGGR_TYPE_CODE (TREE_CODE (thing))) + { + if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing)) + thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0)); + else + thing = TYPE_NAME (thing); + } + if (TREE_CODE (thing) == TYPE_DECL + || (TREE_CODE (thing) == TEMPLATE_DECL + && DECL_TEMPLATE_IS_CLASS (thing))) + thing = DECL_NAME (thing); + my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197); + return thing; +} + +/* CONSTRUCTOR_NAME: + Return the name for the constructor (or destructor) for the + specified class. Argument can be RECORD_TYPE, TYPE_DECL, or + IDENTIFIER_NODE. When given a template, return the plain + unspecialized name. */ +tree +constructor_name (thing) + tree thing; +{ + tree t; + thing = constructor_name_full (thing); + t = IDENTIFIER_TEMPLATE (thing); + if (!t) + return thing; + t = TREE_PURPOSE (t); + return DECL_NAME (t); +} + +/* Cache the value of this class's main virtual function table pointer + in a register variable. This will save one indirection if a + more than one virtual function call is made this function. */ +void +setup_vtbl_ptr () +{ + extern tree base_init_expr; + + if (base_init_expr == 0 + && DECL_CONSTRUCTOR_P (current_function_decl)) + emit_base_init (current_class_type, 0); +} + +/* Record the existence of an addressable inline function. */ +void +mark_inline_for_output (decl) + tree decl; +{ + decl = DECL_MAIN_VARIANT (decl); + if (DECL_SAVED_INLINE (decl)) + return; + my_friendly_assert (TREE_PERMANENT (decl), 363); + DECL_SAVED_INLINE (decl) = 1; +#if 0 + if (DECL_PENDING_INLINE_INFO (decl) != 0 + && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu) + { + struct pending_inline *t = pending_inlines; + my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198); + while (t) + { + if (t == DECL_PENDING_INLINE_INFO (decl)) + break; + t = t->next; + } + if (t == 0) + { + t = DECL_PENDING_INLINE_INFO (decl); + t->next = pending_inlines; + pending_inlines = t; + } + DECL_PENDING_INLINE_INFO (decl) = 0; + } +#endif + saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines); +} + +void +clear_temp_name () +{ + temp_name_counter = 0; +} + +/* Hand off a unique name which can be used for variable we don't really + want to know about anyway, for example, the anonymous variables which + are needed to make references work. Declare this thing so we can use it. + The variable created will be of type TYPE. + + STATICP is nonzero if this variable should be static. */ + +tree +get_temp_name (type, staticp) + tree type; + int staticp; +{ + char buf[sizeof (AUTO_TEMP_FORMAT) + 20]; + tree decl; + int toplev = toplevel_bindings_p (); + + push_obstacks_nochange (); + if (toplev || staticp) + { + end_temporary_allocation (); + sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++); + decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type)); + } + else + { + sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++); + decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type)); + } + TREE_USED (decl) = 1; + TREE_STATIC (decl) = staticp; + + /* If this is a local variable, then lay out its rtl now. + Otherwise, callers of this function are responsible for dealing + with this variable's rtl. */ + if (! toplev) + { + expand_decl (decl); + expand_decl_init (decl); + } + pop_obstacks (); + + return decl; +} + +/* Get a variable which we can use for multiple assignments. + It is not entered into current_binding_level, because + that breaks things when it comes time to do final cleanups + (which take place "outside" the binding contour of the function). */ +tree +get_temp_regvar (type, init) + tree type, init; +{ + static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' }; + tree decl; + + sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++); + decl = build_decl (VAR_DECL, get_identifier (buf), type); + TREE_USED (decl) = 1; + DECL_REGISTER (decl) = 1; + + if (init) + store_init_value (decl, init); + + /* We can expand these without fear, since they cannot need + constructors or destructors. */ + expand_decl (decl); + expand_decl_init (decl); + + if (type_needs_gc_entry (type)) + DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); + + return decl; +} + +/* Make the macro TEMP_NAME_P available to units which do not + include c-tree.h. */ +int +temp_name_p (decl) + tree decl; +{ + return TEMP_NAME_P (decl); +} + +/* Finish off the processing of a UNION_TYPE structure. + If there are static members, then all members are + static, and must be laid out together. If the + union is an anonymous union, we arrange for that + as well. PUBLIC_P is nonzero if this union is + not declared static. */ +void +finish_anon_union (anon_union_decl) + tree anon_union_decl; +{ + tree type = TREE_TYPE (anon_union_decl); + tree field, main_decl = NULL_TREE; + tree elems = NULL_TREE; + int public_p = TREE_PUBLIC (anon_union_decl); + int static_p = TREE_STATIC (anon_union_decl); + int external_p = DECL_EXTERNAL (anon_union_decl); + + if ((field = TYPE_FIELDS (type)) == NULL_TREE) + return; + + if (public_p) + { + error ("global anonymous unions must be declared static"); + return; + } + + for (; field; field = TREE_CHAIN (field)) + { + tree decl; + if (TREE_CODE (field) != FIELD_DECL) + continue; + + if (TREE_PRIVATE (field)) + cp_pedwarn_at ("private member `%#D' in anonymous union", field); + else if (TREE_PROTECTED (field)) + cp_pedwarn_at ("protected member `%#D' in anonymous union", field); + + decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field)); + /* tell `pushdecl' that this is not tentative. */ + DECL_INITIAL (decl) = error_mark_node; + TREE_PUBLIC (decl) = public_p; + TREE_STATIC (decl) = static_p; + DECL_EXTERNAL (decl) = external_p; + decl = pushdecl (decl); + + /* Only write out one anon union element--choose the one that + can hold them all. */ + if (main_decl == NULL_TREE + && 1 == simple_cst_equal (DECL_SIZE (decl), + DECL_SIZE (anon_union_decl))) + { + main_decl = decl; + } + else + { + /* ??? This causes there to be no debug info written out + about this decl. */ + TREE_ASM_WRITTEN (decl) = 1; + } + + DECL_INITIAL (decl) = NULL_TREE; + /* If there's a cleanup to do, it belongs in the + TREE_PURPOSE of the following TREE_LIST. */ + elems = tree_cons (NULL_TREE, decl, elems); + TREE_TYPE (elems) = type; + } + if (static_p) + { + if (main_decl) + { + make_decl_rtl (main_decl, 0, toplevel_bindings_p ()); + DECL_RTL (anon_union_decl) = DECL_RTL (main_decl); + } + else + { + warning ("anonymous union with no members"); + return; + } + } + + /* The following call assumes that there are never any cleanups + for anonymous unions--a reasonable assumption. */ + expand_anon_union_decl (anon_union_decl, NULL_TREE, elems); + + if (flag_cadillac) + cadillac_finish_anon_union (anon_union_decl); +} + +/* Finish and output a table which is generated by the compiler. + NAME is the name to give the table. + TYPE is the type of the table entry. + INIT is all the elements in the table. + PUBLICP is non-zero if this table should be given external access. */ +tree +finish_table (name, type, init, publicp) + tree name, type, init; + int publicp; +{ + tree itype, atype, decl; + static tree empty_table; + int is_empty = 0; + tree asmspec; + + itype = build_index_type (size_int (list_length (init) - 1)); + atype = build_cplus_array_type (type, itype); + layout_type (atype); + + if (TREE_VALUE (init) == integer_zero_node + && TREE_CHAIN (init) == NULL_TREE) + { +#if 0 + if (empty_table == NULL_TREE) +#endif + { + empty_table = get_temp_name (atype, 1); + init = build (CONSTRUCTOR, atype, NULL_TREE, init); + TREE_CONSTANT (init) = 1; + TREE_STATIC (init) = 1; + DECL_INITIAL (empty_table) = init; + asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)), + IDENTIFIER_POINTER (DECL_NAME (empty_table))); + cp_finish_decl (empty_table, NULL_TREE, asmspec, 0, 0); + } + is_empty = 1; + } + + if (name == NULL_TREE) + { + if (is_empty) + return empty_table; + decl = get_temp_name (atype, 1); + } + else + { + decl = build_decl (VAR_DECL, name, atype); + decl = pushdecl (decl); + TREE_STATIC (decl) = 1; + } + + if (is_empty == 0) + { + TREE_PUBLIC (decl) = publicp; + init = build (CONSTRUCTOR, atype, NULL_TREE, init); + TREE_CONSTANT (init) = 1; + TREE_STATIC (init) = 1; + DECL_INITIAL (decl) = init; + asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)), + IDENTIFIER_POINTER (DECL_NAME (decl))); + } + else + { + /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */ + DECL_EXTERNAL (decl) = 1; + TREE_STATIC (decl) = 0; + init = 0; + asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)), + IDENTIFIER_POINTER (DECL_NAME (empty_table))); + } + + cp_finish_decl (decl, NULL_TREE, asmspec, 0, 0); + return decl; +} + +/* Finish processing a builtin type TYPE. It's name is NAME, + its fields are in the array FIELDS. LEN is the number of elements + in FIELDS minus one, or put another way, it is the maximum subscript + used in FIELDS. + + It is given the same alignment as ALIGN_TYPE. */ +void +finish_builtin_type (type, name, fields, len, align_type) + tree type; + char *name; + tree fields[]; + int len; + tree align_type; +{ + register int i; + + TYPE_FIELDS (type) = fields[0]; + for (i = 0; i < len; i++) + { + layout_type (TREE_TYPE (fields[i])); + DECL_FIELD_CONTEXT (fields[i]) = type; + TREE_CHAIN (fields[i]) = fields[i+1]; + } + DECL_FIELD_CONTEXT (fields[i]) = type; + DECL_CLASS_CONTEXT (fields[i]) = type; + TYPE_ALIGN (type) = TYPE_ALIGN (align_type); + layout_type (type); +#if 0 /* not yet, should get fixed properly later */ + TYPE_NAME (type) = make_type_decl (get_identifier (name), type); +#else + TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type); +#endif + layout_decl (TYPE_NAME (type), 0); +} + +/* Auxiliary functions to make type signatures for + `operator new' and `operator delete' correspond to + what compiler will be expecting. */ + +extern tree sizetype; + +tree +coerce_new_type (type) + tree type; +{ + int e1 = 0, e2 = 0; + + if (TREE_CODE (type) == METHOD_TYPE) + type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type))); + if (TREE_TYPE (type) != ptr_type_node) + e1 = 1, error ("`operator new' must return type `void *'"); + + /* Technically the type must be `size_t', but we may not know + what that is. */ + if (TYPE_ARG_TYPES (type) == NULL_TREE) + e1 = 1, error ("`operator new' takes type `size_t' parameter"); + else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE + || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype)) + e2 = 1, error ("`operator new' takes type `size_t' as first parameter"); + if (e2) + type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type)))); + else if (e1) + type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type)); + return type; +} + +tree +coerce_delete_type (type) + tree type; +{ + int e1 = 0, e2 = 0, e3 = 0; + tree arg_types = TYPE_ARG_TYPES (type); + + if (TREE_CODE (type) == METHOD_TYPE) + { + type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types)); + arg_types = TREE_CHAIN (arg_types); + } + if (TREE_TYPE (type) != void_type_node) + e1 = 1, error ("`operator delete' must return type `void'"); + if (arg_types == NULL_TREE + || TREE_VALUE (arg_types) != ptr_type_node) + e2 = 1, error ("`operator delete' takes type `void *' as first parameter"); + + if (arg_types + && TREE_CHAIN (arg_types) + && TREE_CHAIN (arg_types) != void_list_node) + { + /* Again, technically this argument must be `size_t', but again + we may not know what that is. */ + tree t2 = TREE_VALUE (TREE_CHAIN (arg_types)); + if (TREE_CODE (t2) != INTEGER_TYPE + || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype)) + e3 = 1, error ("second argument to `operator delete' must be of type `size_t'"); + else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node) + { + e3 = 1; + if (TREE_CHAIN (TREE_CHAIN (arg_types))) + error ("too many arguments in declaration of `operator delete'"); + else + error ("`...' invalid in specification of `operator delete'"); + } + } + if (e3) + arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype)); + else if (e3 |= e2) + { + if (arg_types == NULL_TREE) + arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node); + else + arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types)); + } + else e3 |= e1; + + if (e3) + type = build_function_type (void_type_node, arg_types); + + return type; +} + +static void +mark_vtable_entries (decl) + tree decl; +{ + tree entries = CONSTRUCTOR_ELTS (DECL_INITIAL (decl)); + + skip_rtti_stuff (&entries); + + for (; entries; entries = TREE_CHAIN (entries)) + { + tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)); + tree fn = TREE_OPERAND (fnaddr, 0); + TREE_ADDRESSABLE (fn) = 1; + if (DECL_ABSTRACT_VIRTUAL_P (fn)) + { + extern tree abort_fndecl; + if (flag_vtable_thunks) + fnaddr = TREE_VALUE (entries); + TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl; + } + assemble_external (fn); + } +} + +/* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL, + based on TYPE and other static flags. + + Note that anything public is tagged TREE_PUBLIC, whether + it's public in this file or in another one. */ + +void +import_export_vtable (decl, type, final) + tree decl, type; + int final; +{ + if (DECL_INTERFACE_KNOWN (decl)) + return; + + /* +e0 or +e1 */ + if (write_virtuals < 2 && write_virtuals != 0) + { + TREE_PUBLIC (decl) = 1; + if (write_virtuals < 0) + DECL_EXTERNAL (decl) = 1; + DECL_INTERFACE_KNOWN (decl) = 1; + } + else if (CLASSTYPE_INTERFACE_KNOWN (type)) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type); + DECL_INTERFACE_KNOWN (decl) = 1; + } + else + { + /* We can only wait to decide if we have real non-inline virtual + functions in our class, or if we come from a template. */ + + int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type); + + if (! found && ! final) + { + tree method; + for (method = CLASSTYPE_METHODS (type); method != NULL_TREE; + method = DECL_NEXT_METHOD (method)) + if (DECL_VINDEX (method) != NULL_TREE + && ! DECL_THIS_INLINE (method) + && ! DECL_ABSTRACT_VIRTUAL_P (method)) + { + found = 1; + break; + } + } + + if (final || ! found) + { +#ifdef ASSEMBLE_EXTERNAL + if (TREE_PUBLIC (decl)) + cp_error ("all virtual functions redeclared inline"); +#endif + if (SUPPORTS_WEAK) + DECL_WEAK (decl) = 1; + else + TREE_PUBLIC (decl) = 0; + DECL_EXTERNAL (decl) = 0; + } + else + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = 1; + } + } +} + +static void +import_export_template (type) + tree type; +{ + if (CLASSTYPE_IMPLICIT_INSTANTIATION (type) + && ! flag_implicit_templates + && CLASSTYPE_INTERFACE_UNKNOWN (type)) + { + SET_CLASSTYPE_INTERFACE_KNOWN (type); + CLASSTYPE_INTERFACE_ONLY (type) = 1; + CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0; + } +} + +static void +finish_prevtable_vardecl (prev, vars) + tree prev, vars; +{ + tree ctype = DECL_CONTEXT (vars); + import_export_template (ctype); + + if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype) + && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype)) + { + tree method; + for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE; + method = DECL_NEXT_METHOD (method)) + { + if (DECL_VINDEX (method) != NULL_TREE + && !DECL_THIS_INLINE (method) + && !DECL_ABSTRACT_VIRTUAL_P (method)) + { + SET_CLASSTYPE_INTERFACE_KNOWN (ctype); + CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method); + CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method); + break; + } + } + } + + import_export_vtable (vars, ctype, 1); + + /* We cannot use TREE_USED here, as it may be set by the expanding of a + ctor that is used to build a global object. The long term plan is to + make the TD entries statically initialized and move this to + finish_vtable_vardecl time. */ + if (flag_rtti && write_virtuals >= 0 + && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || 1 || TREE_USED (vars))) + { + /* Kick out the type descriptor before we dump out global + initializers, as they are initialized at run time and + we have to find them when we scan for things that need initialized + at the top level. */ + build_t_desc (ctype, 1); + } +} + +static void +finish_vtable_vardecl (prev, vars) + tree prev, vars; +{ + if (write_virtuals >= 0 + && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars))) + { +#if 0 + /* The long term plan it to make the TD entries statically initialized, + have the entries built and emitted here. When that happens, this + can be enabled, and the other call to build_t_desc removed. */ + /* Kick out the type descriptor before writing out the vtable. */ + if (flag_rtti) + build_t_desc (DECL_CONTEXT (vars), 1); +#endif + + /* Write it out. */ + mark_vtable_entries (vars); + if (TREE_TYPE (DECL_INITIAL (vars)) == 0) + store_init_value (vars, DECL_INITIAL (vars)); + +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG) + { + /* Mark the VAR_DECL node representing the vtable itself as a + "gratuitous" one, thereby forcing dwarfout.c to ignore it. + It is rather important that such things be ignored because + any effort to actually generate DWARF for them will run + into trouble when/if we encounter code like: + + #pragma interface + struct S { virtual void member (); }; + + because the artificial declaration of the vtable itself (as + manufactured by the g++ front end) will say that the vtable + is a static member of `S' but only *after* the debug output + for the definition of `S' has already been output. This causes + grief because the DWARF entry for the definition of the vtable + will try to refer back to an earlier *declaration* of the + vtable as a static member of `S' and there won't be one. + We might be able to arrange to have the "vtable static member" + attached to the member list for `S' before the debug info for + `S' get written (which would solve the problem) but that would + require more intrusive changes to the g++ front end. */ + + DECL_IGNORED_P (vars) = 1; + } +#endif /* DWARF_DEBUGGING_INFO */ + + rest_of_decl_compilation (vars, NULL_PTR, 1, 1); + } + else if (! TREE_USED (vars)) + /* We don't know what to do with this one yet. */ + return; + + /* We know that PREV must be non-zero here. */ + TREE_CHAIN (prev) = TREE_CHAIN (vars); +} + +static void +prune_vtable_vardecl (prev, vars) + tree prev, vars; +{ + /* We know that PREV must be non-zero here. */ + TREE_CHAIN (prev) = TREE_CHAIN (vars); +} + +void +walk_vtables (typedecl_fn, vardecl_fn) + register void (*typedecl_fn)(); + register void (*vardecl_fn)(); +{ + tree prev, vars; + + for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) + { + register tree type = TREE_TYPE (vars); + + if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars)) + { + if (vardecl_fn) (*vardecl_fn) (prev, vars); + + if (prev && TREE_CHAIN (prev) != vars) + continue; + } + else if (TREE_CODE (vars) == TYPE_DECL + && type != error_mark_node + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_VSIZE (type)) + { + if (typedecl_fn) (*typedecl_fn) (prev, vars); + } + + prev = vars; + } +} + +static void +finish_sigtable_vardecl (prev, vars) + tree prev, vars; +{ + /* We don't need to mark sigtable entries as addressable here as is done + for vtables. Since sigtables, unlike vtables, are always written out, + that was already done in build_signature_table_constructor. */ + + rest_of_decl_compilation (vars, NULL_PTR, 1, 1); + + /* We know that PREV must be non-zero here. */ + TREE_CHAIN (prev) = TREE_CHAIN (vars); +} + +void +walk_sigtables (typedecl_fn, vardecl_fn) + register void (*typedecl_fn)(); + register void (*vardecl_fn)(); +{ + tree prev, vars; + + for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars)) + { + register tree type = TREE_TYPE (vars); + + if (TREE_CODE (vars) == TYPE_DECL + && type != error_mark_node + && IS_SIGNATURE (type)) + { + if (typedecl_fn) (*typedecl_fn) (prev, vars); + } + else if (TREE_CODE (vars) == VAR_DECL + && TREE_TYPE (vars) != error_mark_node + && IS_SIGNATURE (TREE_TYPE (vars))) + { + if (vardecl_fn) (*vardecl_fn) (prev, vars); + } + else + prev = vars; + } +} + +/* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an + inline function at end-of-file. */ + +void +import_export_inline (decl) + tree decl; +{ + if (DECL_INTERFACE_KNOWN (decl)) + return; + + if (DECL_TEMPLATE_INSTANTIATION (decl)) + { + if (DECL_IMPLICIT_INSTANTIATION (decl) && flag_implicit_templates) + { + if (SUPPORTS_WEAK) + DECL_WEAK (decl) = 1; + else + TREE_PUBLIC (decl) = 0; + } + else + DECL_NOT_REALLY_EXTERN (decl) = 0; + } + else if (DECL_FUNCTION_MEMBER_P (decl)) + { + tree ctype = DECL_CLASS_CONTEXT (decl); + if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl)) + { + DECL_NOT_REALLY_EXTERN (decl) + = ! (CLASSTYPE_INTERFACE_ONLY (ctype) + || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines)); + } + else if (SUPPORTS_WEAK) + DECL_WEAK (decl) = 1; + else + TREE_PUBLIC (decl) = 0; + } + else if (DECL_C_STATIC (decl)) + TREE_PUBLIC (decl) = 0; + else if (SUPPORTS_WEAK) + DECL_WEAK (decl) = 1; + else + TREE_PUBLIC (decl) = 0; + + DECL_INTERFACE_KNOWN (decl) = 1; +} + +extern int parse_time, varconst_time; + +#define TIMEVAR(VAR, BODY) \ +do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0) + +/* This routine is called from the last rule in yyparse (). + Its job is to create all the code needed to initialize and + destroy the global aggregates. We do the destruction + first, since that way we only need to reverse the decls once. */ + +void +finish_file () +{ + extern int lineno; + int start_time, this_time; + + tree fnname; + tree vars; + int needs_cleaning = 0, needs_messing_up = 0; + + if (flag_detailed_statistics) + dump_tree_statistics (); + + /* Bad parse errors. Just forget about it. */ + if (! global_bindings_p () || current_class_type) + return; + + start_time = get_run_time (); + + /* Push into C language context, because that's all + we'll need here. */ + push_lang_context (lang_name_c); + + /* Otherwise, GDB can get confused, because in only knows + about source for LINENO-1 lines. */ + lineno -= 1; + + interface_unknown = 1; + interface_only = 0; + +#if 1 + /* The reason for pushing garbage onto the global_binding_level is to + ensure that we can slice out _DECLs which pertain to virtual function + tables. If the last thing pushed onto the global_binding_level was a + virtual function table, then slicing it out would slice away all the + decls (i.e., we lose the head of the chain). + + There are several ways of getting the same effect, from changing the + way that iterators over the chain treat the elements that pertain to + virtual function tables, moving the implementation of this code to + decl.c (where we can manipulate global_binding_level directly), + popping the garbage after pushing it and slicing away the vtable + stuff, or just leaving it alone. */ + + /* Make last thing in global scope not be a virtual function table. */ +#if 0 /* not yet, should get fixed properly later */ + vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node); +#else + vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node); +#endif + DECL_IGNORED_P (vars) = 1; + SET_DECL_ARTIFICIAL (vars); + pushdecl (vars); +#endif + + /* Walk to mark the inline functions we need, then output them so + that we can pick up any other tdecls that those routines need. */ + walk_vtables ((void (*)())0, finish_prevtable_vardecl); + + vars = static_aggregates; + + if (static_ctors || vars || might_have_exceptions_p ()) + needs_messing_up = 1; + if (static_dtors) + needs_cleaning = 1; + + /* See if we really need the hassle. */ + while (vars && needs_cleaning == 0) + { + tree decl = TREE_VALUE (vars); + tree type = TREE_TYPE (decl); + if (TYPE_NEEDS_DESTRUCTOR (type)) + { + needs_cleaning = 1; + needs_messing_up = 1; + break; + } + else + needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type); + vars = TREE_CHAIN (vars); + } + + if (needs_cleaning == 0) + goto mess_up; + + fnname = get_file_function_name ('D'); + start_function (void_list_node, + build_parse_node (CALL_EXPR, fnname, void_list_node, + NULL_TREE), + NULL_TREE, NULL_TREE, 0); + fnname = DECL_ASSEMBLER_NAME (current_function_decl); + store_parm_decls (); + + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); + + /* These must be done in backward order to destroy, + in which they happen to be! */ + for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars)) + { + tree decl = TREE_VALUE (vars); + tree type = TREE_TYPE (decl); + tree temp = TREE_PURPOSE (vars); + + if (TYPE_NEEDS_DESTRUCTOR (type)) + { + if (TREE_STATIC (vars)) + expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0); + if (TREE_CODE (type) == ARRAY_TYPE) + temp = decl; + else + { + mark_addressable (decl); + temp = build1 (ADDR_EXPR, build_pointer_type (type), decl); + } + temp = build_delete (TREE_TYPE (temp), temp, + integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); + expand_expr_stmt (temp); + + if (TREE_STATIC (vars)) + expand_end_cond (); + } + } + + for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors)) + expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors), + NULL_TREE)); + + expand_end_bindings (getdecls(), 1, 0); + poplevel (1, 0, 0); + pop_momentary (); + + finish_function (lineno, 0, 0); + + assemble_destructor (IDENTIFIER_POINTER (fnname)); + + /* if it needed cleaning, then it will need messing up: drop through */ + + mess_up: + /* Must do this while we think we are at the top level. */ + vars = nreverse (static_aggregates); + if (needs_messing_up) + { + fnname = get_file_function_name ('I'); + start_function (void_list_node, + build_parse_node (CALL_EXPR, fnname, + void_list_node, NULL_TREE), + NULL_TREE, NULL_TREE, 0); + fnname = DECL_ASSEMBLER_NAME (current_function_decl); + store_parm_decls (); + + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); + + if (might_have_exceptions_p ()) + register_exception_table (); + + while (vars) + { + tree decl = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + tree old_cleanups = cleanups_this_call; + + /* If this was a static attribute within some function's scope, + then don't initialize it here. Also, don't bother + with initializers that contain errors. */ + if (TREE_STATIC (vars) + || (init && TREE_CODE (init) == TREE_LIST + && value_member (error_mark_node, init))) + { + vars = TREE_CHAIN (vars); + continue; + } + + if (TREE_CODE (decl) == VAR_DECL) + { + /* Set these global variables so that GDB at least puts + us near the declaration which required the initialization. */ + input_filename = DECL_SOURCE_FILE (decl); + lineno = DECL_SOURCE_LINE (decl); + emit_note (input_filename, lineno); + + /* 9.5p5: The initializer of a static member of a class has + the same access rights as a member function. */ + DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl); + DECL_STATIC_FUNCTION_P (current_function_decl) = 1; + + if (IS_AGGR_TYPE (TREE_TYPE (decl)) + || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) + expand_aggr_init (decl, init, 0, 0); + else if (TREE_CODE (init) == TREE_VEC) + { + expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0), + TREE_VEC_ELT (init, 1), + TREE_VEC_ELT (init, 2), 0), + const0_rtx, VOIDmode, 0); + free_temp_slots (); + } + else + expand_assignment (decl, init, 0, 0); + + DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE; + } + else if (TREE_CODE (decl) == SAVE_EXPR) + { + if (! PARM_DECL_EXPR (decl)) + { + /* a `new' expression at top level. */ + expand_expr (decl, const0_rtx, VOIDmode, 0); + free_temp_slots (); + if (TREE_CODE (init) == TREE_VEC) + { + expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0), + TREE_VEC_ELT (init, 1), + TREE_VEC_ELT (init, 2), 0), + const0_rtx, VOIDmode, 0); + free_temp_slots (); + } + else + expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0, 0); + } + } + else if (decl == error_mark_node) + ; + else my_friendly_abort (22); + vars = TREE_CHAIN (vars); + /* Cleanup any temporaries needed for the initial value. */ + expand_cleanups_to (old_cleanups); + } + + for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors)) + expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors), + NULL_TREE)); + + expand_end_bindings (getdecls(), 1, 0); + poplevel (1, 0, 0); + pop_momentary (); + + finish_function (lineno, 0, 0); + assemble_constructor (IDENTIFIER_POINTER (fnname)); + } + + expand_builtin_throw (); + + permanent_allocation (1); + + /* Done with C language context needs. */ + pop_lang_context (); + + /* Now write out any static class variables (which may have since + learned how to be initialized). */ + while (pending_statics) + { + tree decl = TREE_VALUE (pending_statics); + if (TREE_USED (decl) == 1 + || TREE_READONLY (decl) == 0 + || DECL_INITIAL (decl) == 0) + rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1); + pending_statics = TREE_CHAIN (pending_statics); + } + + this_time = get_run_time (); + parse_time -= this_time - start_time; + varconst_time += this_time - start_time; + + start_time = get_run_time (); + + if (flag_handle_signatures) + walk_sigtables ((void (*)())0, finish_sigtable_vardecl); + + for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname)) + { + tree decl = TREE_VALUE (fnname); + import_export_inline (decl); + if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl) + && TREE_PUBLIC (decl) && ! DECL_WEAK (decl) + && DECL_NOT_REALLY_EXTERN (decl)) + synthesize_method (decl); + } + + /* Now write out inline functions which had their addresses taken and + which were not declared virtual and which were not declared `extern + inline'. */ + { + int reconsider = 1; /* More may be referenced; check again */ + + while (reconsider) + { + tree last = saved_inlines = tree_cons (NULL_TREE, NULL_TREE, + saved_inlines); + tree last_head = last; + tree place = TREE_CHAIN (saved_inlines); + reconsider = 0; + + walk_vtables ((void (*)())0, finish_vtable_vardecl); + + for (; place; place = TREE_CHAIN (place)) + { + tree decl = TREE_VALUE (place); + + /* Slice out the empty elements put in just above in the + previous reconsidering. */ + if (decl == NULL_TREE) + { + TREE_CHAIN (last) = TREE_CHAIN (place); + continue; + } + + if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)) + { + if (TREE_USED (decl)) + { + synthesize_method (decl); + if (TREE_ASM_WRITTEN (decl)) + reconsider = 1; + } + else + { + last = place; + continue; + } + } + + if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0) + { + TREE_CHAIN (last) = TREE_CHAIN (place); + continue; + } + + if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)) + || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) + || flag_keep_inline_functions) + { + TREE_CHAIN (last) = TREE_CHAIN (place); + + if (DECL_NOT_REALLY_EXTERN (decl)) + { + DECL_EXTERNAL (decl) = 0; + reconsider = 1; + temporary_allocation (); + output_inline_function (decl); + permanent_allocation (1); + } + + continue; + } + + last = place; + } + } + } + + /* Now delete from the chain of variables all virtual function tables. + We output them all ourselves, because each will be treated specially. */ + + walk_vtables ((void (*)())0, prune_vtable_vardecl); + + for (vars = getdecls (); vars; vars = TREE_CHAIN (vars)) + { + if (TREE_CODE (vars) == THUNK_DECL) + emit_thunk (vars); + else if (TREE_CODE (vars) == FUNCTION_DECL + && ! DECL_INTERFACE_KNOWN (vars) + && DECL_C_STATIC (vars)) + TREE_PUBLIC (vars) = 0; + } + + if (might_have_exceptions_p ()) + emit_exception_table (); + + if (write_virtuals == 2) + { + /* Now complain about an virtual function tables promised + but not delivered. */ + while (pending_vtables) + { + if (TREE_PURPOSE (pending_vtables) == NULL_TREE) + error ("virtual function table for `%s' not defined", + IDENTIFIER_POINTER (TREE_VALUE (pending_vtables))); + pending_vtables = TREE_CHAIN (pending_vtables); + } + } + + finish_repo (); + + this_time = get_run_time (); + parse_time -= this_time - start_time; + varconst_time += this_time - start_time; + + if (flag_detailed_statistics) + dump_time_statistics (); +} + +/* This is something of the form 'A()()()()()+1' that has turned out to be an + expr. Since it was parsed like a type, we need to wade through and fix + that. Unfortunately, since operator() is left-associative, we can't use + tail recursion. In the above example, TYPE is `A', and DECL is + `()()()()()'. + + Maybe this shouldn't be recursive, but how often will it actually be + used? (jason) */ +tree +reparse_absdcl_as_expr (type, decl) + tree type, decl; +{ + /* do build_functional_cast (type, NULL_TREE) at bottom */ + if (TREE_OPERAND (decl, 0) == NULL_TREE) + return build_functional_cast (type, NULL_TREE); + + /* recurse */ + decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0)); + + decl = build_x_function_call (decl, NULL_TREE, current_class_decl); + + if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node) + decl = require_complete_type (decl); + + return decl; +} + +/* This is something of the form `int ((int)(int)(int)1)' that has turned + out to be an expr. Since it was parsed like a type, we need to wade + through and fix that. Since casts are right-associative, we are + reversing the order, so we don't have to recurse. + + In the above example, DECL is the `(int)(int)(int)', and EXPR is the + `1'. */ +tree +reparse_absdcl_as_casts (decl, expr) + tree decl, expr; +{ + tree type; + + if (TREE_CODE (expr) == CONSTRUCTOR) + { + type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); + decl = TREE_OPERAND (decl, 0); + + if (IS_SIGNATURE (type)) + { + error ("cast specifies signature type"); + return error_mark_node; + } + + expr = digest_init (type, expr, (tree *) 0); + if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0) + { + int failure = complete_array_type (type, expr, 1); + if (failure) + my_friendly_abort (78); + } + } + + while (decl) + { + type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1))); + decl = TREE_OPERAND (decl, 0); + expr = build_c_cast (type, expr, 0); + } + + return expr; +} + +/* Recursive helper function for reparse_decl_as_expr. It may be a good + idea to reimplement this using an explicit stack, rather than recursion. */ +static tree +reparse_decl_as_expr1 (decl) + tree decl; +{ + switch (TREE_CODE (decl)) + { + case IDENTIFIER_NODE: + return do_identifier (decl); + case INDIRECT_REF: + return build_x_indirect_ref + (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *"); + case ADDR_EXPR: + return build_x_unary_op (ADDR_EXPR, + reparse_decl_as_expr1 (TREE_OPERAND (decl, 0))); + case BIT_NOT_EXPR: + return build_x_unary_op (BIT_NOT_EXPR, + reparse_decl_as_expr1 (TREE_OPERAND (decl, 0))); + case SCOPE_REF: + return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1)); + case ARRAY_REF: + return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), + TREE_OPERAND (decl, 1)); + default: + my_friendly_abort (5); + return NULL_TREE; + } +} + +/* This is something of the form `int (*a)++' that has turned out to be an + expr. It was only converted into parse nodes, so we need to go through + and build up the semantics. Most of the work is done by + reparse_decl_as_expr1, above. + + In the above example, TYPE is `int' and DECL is `*a'. */ +tree +reparse_decl_as_expr (type, decl) + tree type, decl; +{ + decl = reparse_decl_as_expr1 (decl); + if (type) + return build_functional_cast (type, build_tree_list (NULL_TREE, decl)); + else + return decl; +} + +/* This is something of the form `int (*a)' that has turned out to be a + decl. It was only converted into parse nodes, so we need to do the + checking that make_{pointer,reference}_declarator do. */ + +tree +finish_decl_parsing (decl) + tree decl; +{ + extern int current_class_depth; + + switch (TREE_CODE (decl)) + { + case IDENTIFIER_NODE: + return decl; + case INDIRECT_REF: + return make_pointer_declarator + (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); + case ADDR_EXPR: + return make_reference_declarator + (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0))); + case BIT_NOT_EXPR: + TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); + return decl; + case SCOPE_REF: + push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3); + TREE_COMPLEXITY (decl) = current_class_depth; + return decl; + case ARRAY_REF: + TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0)); + return decl; + default: + my_friendly_abort (5); + return NULL_TREE; + } +} + +tree +check_cp_case_value (value) + tree value; +{ + if (value == NULL_TREE) + return value; + + /* build_c_cast puts on a NOP_EXPR to make a non-lvalue. + Strip such NOP_EXPRs. */ + if (TREE_CODE (value) == NOP_EXPR + && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0))) + value = TREE_OPERAND (value, 0); + + if (TREE_READONLY_DECL_P (value)) + { + value = decl_constant_value (value); + /* build_c_cast puts on a NOP_EXPR to make a non-lvalue. + Strip such NOP_EXPRs. */ + if (TREE_CODE (value) == NOP_EXPR + && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0))) + value = TREE_OPERAND (value, 0); + } + value = fold (value); + + if (TREE_CODE (value) != INTEGER_CST + && value != error_mark_node) + { + cp_error ("case label `%E' does not reduce to an integer constant", + value); + value = error_mark_node; + } + else + /* Promote char or short to int. */ + value = default_conversion (value); + + constant_expression_warning (value); + + return value; +} + +tree current_namespace; + +/* Get the inner part of a namespace id. It doesn't have any prefix, nor + postfix. Returns 0 if in global namespace. */ +tree +get_namespace_id () +{ + tree x = current_namespace; + if (x) + x = TREE_PURPOSE (x); + return x; +} + +/* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */ +tree +current_namespace_id (name) + tree name; +{ + tree old_id = get_namespace_id (); + char *buf; + + /* Global names retain old encoding. */ + if (! old_id) + return name; + + buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id) + + IDENTIFIER_LENGTH (name)); + sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id), + IDENTIFIER_POINTER (name)); + return get_identifier (buf); +} + +void +do_namespace_alias (alias, namespace) + tree alias, namespace; +{ +} + +tree +do_toplevel_using_decl (decl) + tree decl; +{ + if (decl == NULL_TREE || decl == error_mark_node) + return; + + if (TREE_CODE (decl) == SCOPE_REF) + decl = resolve_scope_to_name (NULL_TREE, decl); + + /* Is this the right way to do an id list? */ + if (TREE_CODE (decl) != TREE_LIST) + { + pushdecl (decl); + } + else + while (decl) + { + pushdecl (TREE_VALUE (decl)); + decl = TREE_CHAIN (decl); + } +} + +tree +do_class_using_decl (decl) + tree decl; +{ + tree type; + + /* Ignore for now, unimplemented. */ + return NULL_TREE; +} + +void +do_using_directive (namespace) + tree namespace; +{ +} + +void +check_default_args (x) + tree x; +{ + tree arg = TYPE_ARG_TYPES (TREE_TYPE (x)); + int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE); + for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i) + { + if (TREE_PURPOSE (arg)) + saw_def = 1; + else if (saw_def) + { + cp_error ("default argument missing for parameter %P of `%#D'", + i, x); + break; + } + } +} diff --git a/contrib/gcc/cp/edsel.c b/contrib/gcc/cp/edsel.c new file mode 100644 index 00000000000..35099d523f7 --- /dev/null +++ b/contrib/gcc/cp/edsel.c @@ -0,0 +1,928 @@ +/* Interface to LUCID Cadillac system for GNU compiler. + Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" + +#include "tree.h" +#include "flags.h" +#include +#include "cp-tree.h" +#include "obstack.h" + +#ifdef CADILLAC +#include +#include +#include +#include +#include +#include + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +void init_cadillac (); + +extern char *input_filename; +extern int lineno; + +/* Put random information we might want to get back from + Cadillac here. */ +typedef struct +{ + /* The connection to the Cadillac kernel. */ + Connection *conn; + + /* Input and output file descriptors for Cadillac. */ + short fd_input, fd_output; + + /* #include nesting of current file. */ + short depth; + + /* State variables for the connection. */ + char messages; + char conversion; + char emission; + char process_until; + + /* #if level of current file. */ + int iflevel; + + /* Line number that starts current source file. */ + int lineno; + + /* Name of current file. */ + char *filename; + + /* Where to stop processing (if process_until is set). */ + char *end_filename; + int end_position; + +} cadillac_struct; +static cadillac_struct cadillacObj; + +/* Nonzero if in the process of exiting. */ +static int exiting; + +void cadillac_note_source (); +static void CWriteLanguageDecl (); +static void CWriteLanguageType (); +static void CWriteTopLevel (); +static void cadillac_note_filepos (); +static void cadillac_process_request (), cadillac_process_requests (); +static void cadillac_switch_source (); +static void exit_cadillac (); + +/* Blocking test. */ +static int +readable_p (fd) + int fd; +{ + fd_set f; + + FD_ZERO (&f); + FD_SET (fd, &f); + + return select (32, &f, NULL, NULL, 0) == 1; +} + +static CObjectType *tree_to_cadillac_map; +struct obstack cadillac_obstack; + + +#include "stack.h" + +struct context_level +{ + struct stack_level base; + + tree context; +}; + +/* Stack for maintaining contexts (in case functions or types are nested). + When defining a struct type, the `context' field is the RECORD_TYPE. + When defining a function, the `context' field is the FUNCTION_DECL. */ + +static struct context_level *context_stack; + +static struct context_level * +push_context_level (stack, obstack) + struct stack_level *stack; + struct obstack *obstack; +{ + struct context_level tem; + + tem.base.prev = stack; + return (struct context_level *)push_stack_level (obstack, &tem, sizeof (tem)); +} + +/* Discard a level of search allocation. */ + +static struct context_level * +pop_context_level (stack) + struct context_level *stack; +{ + stack = (struct context_level *)pop_stack_level (stack); + return stack; +} + +void +init_cadillac () +{ + extern FILE *finput; + extern int errno; + CCompilerMessage* req; + cadillac_struct *cp = &cadillacObj; + int i; + + if (! flag_cadillac) + return; + + tree_to_cadillac_map = (CObjectType*) xmalloc (sizeof (CObjectType) * LAST_CPLUS_TREE_CODE); + for (i = 0; i < LAST_CPLUS_TREE_CODE; i++) + tree_to_cadillac_map[i] = MiscOType; + tree_to_cadillac_map[RECORD_TYPE] = StructOType; + tree_to_cadillac_map[UNION_TYPE] = UnionOType; + tree_to_cadillac_map[ENUMERAL_TYPE] = EnumTypeOType; + tree_to_cadillac_map[TYPE_DECL] = TypedefOType; + tree_to_cadillac_map[VAR_DECL] = VariableOType; + tree_to_cadillac_map[CONST_DECL] = EnumConstantOType; + tree_to_cadillac_map[FUNCTION_DECL] = FunctionOType; + tree_to_cadillac_map[FIELD_DECL] = FieldOType; + +#ifdef sun + on_exit (&exit_cadillac, 0); +#endif + + gcc_obstack_init (&cadillac_obstack); + + /* Yow! This is the way Cadillac was designed to deal with + Oregon C++ compiler! */ + cp->fd_input = flag_cadillac; + cp->fd_output = flag_cadillac; + + /* Start in "turned-on" state. */ + cp->messages = 1; + cp->conversion = 1; + cp->emission = 1; + + /* Establish a connection with Cadillac here. */ + cp->conn = NewConnection (cp, cp->fd_input, cp->fd_output); + + CWriteHeader (cp->conn, WaitingMType, 0); + CWriteRequestBuffer (cp->conn); + + if (!readable_p (cp->fd_input)) + ; + + req = CReadCompilerMessage (cp->conn); + + if (!req) + switch (errno) + { + case EWOULDBLOCK: + sleep (5); + return; + + case 0: + fatal ("init_cadillac: EOF on connection to kernel, exiting\n"); + break; + + default: + perror ("Editor to kernel connection"); + exit (0); + } +} + +static void +cadillac_process_requests (conn) + Connection *conn; +{ + CCompilerMessage *req; + while (req = (CCompilerMessage*) CPeekNextRequest (conn)) + { + req = CReadCompilerMessage (conn); + cadillac_process_request (&cadillacObj, req); + } +} + +static void +cadillac_process_request (cp, req) + cadillac_struct *cp; + CCompilerMessage *req; +{ + if (! req) + return; + + switch (req->reqType) + { + case ProcessUntilMType: + if (cp->process_until) + my_friendly_abort (23); + cp->process_until = 1; + /* This is not really right. */ + cp->end_position = ((CCompilerCommand*)req)->processuntil.position; +#if 0 + cp->end_filename = req->processuntil.filename; +#endif + break; + + case CommandMType: + switch (req->header.data) + { + case MessagesOnCType: + cp->messages = 1; + break; + case MessagesOffCType: + cp->messages = 0; + break; + case ConversionOnCType: + cp->conversion = 1; + break; + case ConversionOffCType: + cp->conversion = 0; + break; + case EmissionOnCType: + cp->emission = 1; + break; + case EmissionOffCType: + cp->emission = 0; + break; + + case FinishAnalysisCType: + return; + + case PuntAnalysisCType: + case ContinueAnalysisCType: + case GotoFileposCType: + case OpenSucceededCType: + case OpenFailedCType: + fprintf (stderr, "request type %d not implemented\n", req->reqType); + return; + + case DieCType: + if (! exiting) + my_friendly_abort (24); + return; + + } + break; + + default: + fatal ("unknown request type %d", req->reqType); + } +} + +void +cadillac_start () +{ + Connection *conn = cadillacObj.conn; + CCompilerMessage *req; + + /* Let Cadillac know that we start in C++ language scope. */ + CWriteHeader (conn, ForeignLinkageMType, LinkCPlus); + CWriteLength (conn); + CWriteRequestBuffer (conn); + + cadillac_process_requests (conn); +} + +static void +cadillac_printf (msg, name) +{ + if (cadillacObj.messages) + printf ("[%s,%4d] %s `%s'\n", input_filename, lineno, msg, name); +} + +void +cadillac_start_decl (decl) + tree decl; +{ + Connection *conn = cadillacObj.conn; + CObjectType object_type = tree_to_cadillac_map [TREE_CODE (decl)]; + + if (context_stack) + switch (TREE_CODE (context_stack->context)) + { + case FUNCTION_DECL: + /* Currently, cadillac only implements top-level forms. */ + return; + case RECORD_TYPE: + case UNION_TYPE: + cadillac_printf ("start class-level decl", IDENTIFIER_POINTER (DECL_NAME (decl))); + break; + default: + my_friendly_abort (25); + } + else + { + cadillac_printf ("start top-level decl", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); + CWriteTopLevel (conn, StartMType); + } + + CWriteLanguageDecl (conn, decl, tree_to_cadillac_map[TREE_CODE (decl)]); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_finish_decl (decl) + tree decl; +{ + Connection *conn = cadillacObj.conn; + + if (context_stack) + switch (TREE_CODE (context_stack->context)) + { + case FUNCTION_DECL: + return; + case RECORD_TYPE: + case UNION_TYPE: + cadillac_printf ("end class-level decl", IDENTIFIER_POINTER (DECL_NAME (decl))); + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + break; + default: + my_friendly_abort (26); + } + else + { + cadillac_printf ("end top-level decl", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + CWriteTopLevel (conn, StopMType); + } + + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_start_function (fndecl) + tree fndecl; +{ + Connection *conn = cadillacObj.conn; + + if (context_stack) + /* nested functions not yet handled. */ + my_friendly_abort (27); + + cadillac_printf ("start top-level function", lang_printable_name (fndecl)); + context_stack = push_context_level (context_stack, &cadillac_obstack); + context_stack->context = fndecl; + + CWriteTopLevel (conn, StartMType); + my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 202); + CWriteLanguageDecl (conn, fndecl, + (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE + ? MemberFnOType : FunctionOType)); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_finish_function (fndecl) + tree fndecl; +{ + Connection *conn = cadillacObj.conn; + + cadillac_printf ("end top-level function", lang_printable_name (fndecl)); + context_stack = pop_context_level (context_stack); + + if (context_stack) + /* nested functions not yet implemented. */ + my_friendly_abort (28); + + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + CWriteTopLevel (conn, StopMType); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_finish_anon_union (decl) + tree decl; +{ + Connection *conn = cadillacObj.conn; + + if (! global_bindings_p ()) + return; + cadillac_printf ("finish top-level anon union", ""); + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + CWriteTopLevel (conn, StopMType); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_start_enum (type) + tree type; +{ + Connection *conn = cadillacObj.conn; + + tree name = TYPE_NAME (type); + + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + if (context_stack) + switch (TREE_CODE (context_stack->context)) + { + case FUNCTION_DECL: + return; + case RECORD_TYPE: + case UNION_TYPE: + break; + default: + my_friendly_abort (29); + } + else + { + cadillac_printf ("start top-level enum", IDENTIFIER_POINTER (name)); + CWriteTopLevel (conn, StartMType); + } + + CWriteLanguageType (conn, type, tree_to_cadillac_map[ENUMERAL_TYPE]); +} + +void +cadillac_finish_enum (type) + tree type; +{ + Connection *conn = cadillacObj.conn; + tree name = TYPE_NAME (type); + + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + if (context_stack) + switch (TREE_CODE (context_stack->context)) + { + case FUNCTION_DECL: + return; + case RECORD_TYPE: + case UNION_TYPE: + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + break; + default: + my_friendly_abort (30); + } + else + { + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + cadillac_printf ("finish top-level enum", IDENTIFIER_POINTER (name)); + CWriteTopLevel (conn, StopMType); + } + + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_start_struct (type) + tree type; +{ + Connection *conn = cadillacObj.conn; + tree name = TYPE_NAME (type); + + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + if (context_stack) + switch (TREE_CODE (context_stack->context)) + { + case FUNCTION_DECL: + return; + case RECORD_TYPE: + case UNION_TYPE: + return; + default: + my_friendly_abort (31); + } + else + { + cadillac_printf ("start struct", IDENTIFIER_POINTER (name)); + CWriteTopLevel (conn, StartMType); + } + + context_stack = push_context_level (context_stack, &cadillac_obstack); + context_stack->context = type; + + CWriteLanguageType (conn, type, + TYPE_LANG_SPECIFIC (type) && CLASSTYPE_DECLARED_CLASS (type) ? ClassOType : tree_to_cadillac_map[TREE_CODE (type)]); +} + +void +cadillac_finish_struct (type) + tree type; +{ + Connection *conn = cadillacObj.conn; + tree name = TYPE_NAME (type); + + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + context_stack = pop_context_level (context_stack); + if (context_stack) + return; + + cadillac_printf ("finish struct", IDENTIFIER_POINTER (name)); + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + CWriteTopLevel (conn, StopMType); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_finish_exception (type) + tree type; +{ + Connection *conn = cadillacObj.conn; + + fatal ("cadillac_finish_exception"); + CWriteHeader (conn, EndDefMType, 0); + CWriteLength (conn); + CWriteTopLevel (conn, StopMType); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_push_class (type) + tree type; +{ +} + +void +cadillac_pop_class () +{ +} + +void +cadillac_push_lang (name) + tree name; +{ + Connection *conn = cadillacObj.conn; + CLinkLanguageType m; + + if (name == lang_name_cplusplus) + m = LinkCPlus; + else if (name == lang_name_c) + m = LinkC; + else + my_friendly_abort (32); + CWriteHeader (conn, ForeignLinkageMType, m); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_pop_lang () +{ + Connection *conn = cadillacObj.conn; + + CWriteHeader (conn, ForeignLinkageMType, LinkPop); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_finish_stmt () +{ +} + +void +cadillac_note_source () +{ + cadillacObj.lineno = lineno; + cadillacObj.filename = input_filename; +} + +static void +CWriteTopLevel (conn, m) + Connection *conn; + CMessageSubType m; +{ + static context_id = 0; + CWriteHeader (conn, TopLevelFormMType, m); + cadillac_note_filepos (); + + /* Eventually, this will point somewhere into the digest file. */ + context_id += 1; + CWriteSomething (conn, &context_id, sizeof (BITS32)); + + CWriteSomething (conn, &cadillacObj.iflevel, sizeof (BITS32)); + CWriteLength (conn); +} + +static void +cadillac_note_filepos () +{ + extern FILE *finput; + int pos = ftell (finput); + CWriteSomething (cadillacObj.conn, &pos, sizeof (BITS32)); +} + +void +cadillac_switch_source (startflag) + int startflag; +{ + Connection *conn = cadillacObj.conn; + /* Send out the name of the source file being compiled. */ + + CWriteHeader (conn, SourceFileMType, startflag ? StartMType : StopMType); + CWriteSomething (conn, &cadillacObj.depth, sizeof (BITS16)); + CWriteVstring0 (conn, input_filename); + CWriteLength (conn); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +void +cadillac_push_source () +{ + cadillacObj.depth += 1; + cadillac_switch_source (1); +} + +void +cadillac_pop_source () +{ + cadillacObj.depth -= 1; + cadillac_switch_source (0); +} + +struct cadillac_mdep +{ + short object_type; + char linkage; + char access; + short length; +}; + +static void +CWriteLanguageElem (conn, p, name) + Connection *conn; + struct cadillac_mdep *p; + char *name; +{ + CWriteSomething (conn, &p->object_type, sizeof (BITS16)); + CWriteSomething (conn, &p->linkage, sizeof (BITS8)); + CWriteSomething (conn, &p->access, sizeof (BITS8)); + CWriteSomething (conn, &p->length, sizeof (BITS16)); + CWriteVstring0 (conn, name); + +#if 0 + /* Don't write date_type. */ + CWriteVstring0 (conn, ""); +#endif + CWriteLength (conn); +} + +static void +CWriteLanguageDecl (conn, decl, object_type) + Connection *conn; + tree decl; + CObjectType object_type; +{ + struct cadillac_mdep foo; + tree name; + + CWriteHeader (conn, LanguageElementMType, StartDefineMType); + foo.object_type = object_type; + if (decl_type_context (decl)) + { + foo.linkage = ParentLinkage; + if (TREE_PRIVATE (decl)) + foo.access = PrivateAccess; + else if (TREE_PROTECTED (decl)) + foo.access = ProtectedAccess; + else + foo.access = PublicAccess; + } + else + { + if (TREE_PUBLIC (decl)) + foo.linkage = GlobalLinkage; + else + foo.linkage = FileLinkage; + foo.access = PublicAccess; + } + name = DECL_NAME (decl); + foo.length = IDENTIFIER_LENGTH (name); + + CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name)); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +static void +CWriteLanguageType (conn, type, object_type) + Connection *conn; + tree type; + CObjectType object_type; +{ + struct cadillac_mdep foo; + tree name = TYPE_NAME (type); + + CWriteHeader (conn, LanguageElementMType, StartDefineMType); + foo.object_type = object_type; + if (current_class_type) + { + foo.linkage = ParentLinkage; + if (TREE_PRIVATE (type)) + foo.access = PrivateAccess; + else if (TREE_PROTECTED (type)) + foo.access = ProtectedAccess; + else + foo.access = PublicAccess; + } + else + { + foo.linkage = NoLinkage; + foo.access = PublicAccess; + } + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + foo.length = IDENTIFIER_LENGTH (name); + + CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name)); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +static void +CWriteUseObject (conn, type, object_type, use) + Connection *conn; + tree type; + CObjectType object_type; + CMessageSubType use; +{ + struct cadillac_mdep foo; + tree name = NULL_TREE; + + CWriteHeader (conn, LanguageElementMType, use); + foo.object_type = object_type; + if (current_class_type) + { + foo.linkage = ParentLinkage; + if (TREE_PRIVATE (type)) + foo.access = PrivateAccess; + else if (TREE_PROTECTED (type)) + foo.access = ProtectedAccess; + else + foo.access = PublicAccess; + } + else + { + foo.linkage = NoLinkage; + foo.access = PublicAccess; + } + switch (TREE_CODE (type)) + { + case VAR_DECL: + case FIELD_DECL: + case TYPE_DECL: + case CONST_DECL: + case FUNCTION_DECL: + name = DECL_NAME (type); + break; + + default: + my_friendly_abort (33); + } + + foo.length = IDENTIFIER_LENGTH (name); + + CWriteLanguageElem (conn, &foo, IDENTIFIER_POINTER (name)); + CWriteRequestBuffer (conn); + cadillac_process_requests (conn); +} + +/* Here's how we exit under cadillac. */ + +static void +exit_cadillac () +{ + extern int errorcount; + + Connection *conn = cadillacObj.conn; + + if (flag_cadillac) + { + CCompilerMessage *req; + + CWriteHeader (conn, FinishedMType, + errorcount ? 0 : CsObjectWritten | CsComplete); + /* Bye, bye! */ + CWriteRequestBuffer (conn); + + /* Block on read. */ + while (! readable_p (cadillacObj.fd_input)) + { + if (exiting) + my_friendly_abort (34); + exiting = 1; + } + exiting = 1; + + req = CReadCompilerMessage (conn); + cadillac_process_request (&cadillacObj, req); + } +} + +#else +/* Stubs. */ +void init_cadillac () {} +void cadillac_start () {} +void cadillac_start_decl (decl) + tree decl; +{} +void +cadillac_finish_decl (decl) + tree decl; +{} +void +cadillac_start_function (fndecl) + tree fndecl; +{} +void +cadillac_finish_function (fndecl) + tree fndecl; +{} +void +cadillac_finish_anon_union (decl) + tree decl; +{} +void +cadillac_start_enum (type) + tree type; +{} +void +cadillac_finish_enum (type) + tree type; +{} +void +cadillac_start_struct (type) + tree type; +{} +void +cadillac_finish_struct (type) + tree type; +{} +void +cadillac_finish_exception (type) + tree type; +{} +void +cadillac_push_class (type) + tree type; +{} +void +cadillac_pop_class () +{} +void +cadillac_push_lang (name) + tree name; +{} +void +cadillac_pop_lang () +{} +void +cadillac_note_source () +{} +void +cadillac_finish_stmt () +{} +void +cadillac_switch_source () +{} +void +cadillac_push_source () +{} +void +cadillac_pop_source () +{} +#endif diff --git a/contrib/gcc/cp/errfn.c b/contrib/gcc/cp/errfn.c new file mode 100644 index 00000000000..f36b0e1e1f9 --- /dev/null +++ b/contrib/gcc/cp/errfn.c @@ -0,0 +1,230 @@ +/* Provide a call-back mechanism for handling error output. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Jason Merrill (jason@cygnus.com) + + This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "tree.h" +#include + +/* cp_printer is the type of a function which converts an argument into + a string for digestion by printf. The cp_printer function should deal + with all memory management; the functions in this file will not free + the char*s returned. See error.c for an example use of this code. */ + +typedef char* cp_printer PROTO((HOST_WIDE_INT, int)); +extern cp_printer * cp_printers[256]; + +/* Whether or not we should try to be quiet for errors and warnings; this is + used to avoid being too talkative about problems with tentative choices + when we're computing the conversion costs for a method call. */ +int cp_silent = 0; + +typedef void errorfn (); /* deliberately vague */ + +extern char* cp_file_of PROTO((tree)); +extern int cp_line_of PROTO((tree)); + +#define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap) + +#define NARGS 4 +#define arglist a1, a2, a3, a4 +#define arglist_dcl HOST_WIDE_INT a1, a2, a3, a4; +#define ARGSINIT args[0] = a1; args[1] = a2; args[2] = a3; args[3] = a4; +#define ARGSLIST args[0], args[1], args[2], args[3] + +static void +cp_thing (errfn, atarg1, format, arglist) + errorfn *errfn; + int atarg1; + char *format; + arglist_dcl +{ + char *fmt; + char *f; + char *ap; + int arg; + HOST_WIDE_INT atarg = atarg1 ? a1 : 0; + HOST_WIDE_INT args[NARGS]; + ARGSINIT + + fmt = STRDUP(format); + + for (f = fmt, arg = 0; *f; ++f) + { + cp_printer * function; + int alternate; + int maybe_here; + + /* ignore text */ + if (*f != '%') continue; + + ++f; + + alternate = 0; + maybe_here = 0; + + /* ignore most flags */ + while (*f == ' ' || *f == '-' || *f == '+' || *f == '#') + { + if (*f == '+') + maybe_here = 1; + else if (*f == '#') + alternate = 1; + ++f; + } + + /* ignore field width */ + if (*f == '*') + { + ++f; + ++arg; + } + else + while (isdigit (*f)) + ++f; + + /* ignore precision */ + if (*f == '.') + { + ++f; + if (*f == '*') + { + ++f; + ++arg; + } + else + while (isdigit (*f)) + ++f; + } + + /* ignore "long" */ + if (*f == 'l') + ++f; + + function = cp_printers[(int)*f]; + + if (function) + { + char *p; + + if (arg >= NARGS) abort (); + + if (maybe_here && atarg1) + atarg = args[arg]; + + /* Must use a temporary to avoid calling *function twice */ + p = (*function) (args[arg], alternate); + args[arg] = (HOST_WIDE_INT) STRDUP(p); + *f = 's'; + } + + ++arg; /* Assume valid format string */ + + } + + if (atarg) + { + char *file = cp_file_of ((tree) atarg); + int line = cp_line_of ((tree) atarg); + (*errfn) (file, line, fmt, ARGSLIST); + } + else + (*errfn) (fmt, ARGSLIST); + +} + +void +cp_error (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn error; + if (! cp_silent) + cp_thing (error, 0, format, arglist); +} + +void +cp_warning (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn warning; + if (! cp_silent) + cp_thing (warning, 0, format, arglist); +} + +void +cp_pedwarn (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn pedwarn; + if (! cp_silent) + cp_thing (pedwarn, 0, format, arglist); +} + +void +cp_compiler_error (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn compiler_error; + if (! cp_silent) + cp_thing (compiler_error, 0, format, arglist); +} + +void +cp_sprintf (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn sprintf; + cp_thing (sprintf, 0, format, arglist); +} + +void +cp_error_at (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn error_with_file_and_line; + if (! cp_silent) + cp_thing (error_with_file_and_line, 1, format, arglist); +} + +void +cp_warning_at (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn warning_with_file_and_line; + if (! cp_silent) + cp_thing (warning_with_file_and_line, 1, format, arglist); +} + +void +cp_pedwarn_at (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn pedwarn_with_file_and_line; + if (! cp_silent) + cp_thing (pedwarn_with_file_and_line, 1, format, arglist); +} diff --git a/contrib/gcc/cp/error.c b/contrib/gcc/cp/error.c new file mode 100644 index 00000000000..4eb196e3add --- /dev/null +++ b/contrib/gcc/cp/error.c @@ -0,0 +1,1482 @@ +/* Call-backs for C++ error reporting. + This code is non-reentrant. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + + This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include "tree.h" +#include "cp-tree.h" +#include "obstack.h" +#include + +typedef char* cp_printer (); + +#define A args_as_string +#define C code_as_string +#define D decl_as_string +#define E expr_as_string +#define L language_as_string +#define O op_as_string +#define P parm_as_string +#define T type_as_string +#define V cv_as_string + +#define _ (cp_printer *) 0 +cp_printer * cp_printers[256] = +{ +/*0 1 2 3 4 5 6 7 8 9 A B C D E F */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x00 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x10 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x20 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x30 */ + _, A, _, C, D, E, _, _, _, _, _, _, L, _, _, O, /* 0x40 */ + P, _, _, _, T, _, V, _, _, _, _, _, _, _, _, _, /* 0x50 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */ +}; +#undef C +#undef D +#undef E +#undef L +#undef O +#undef P +#undef T +#undef V +#undef _ + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +/* Obstack where we build text strings for overloading, etc. */ +static struct obstack scratch_obstack; +static char *scratch_firstobj; + +# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) +# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) +# define OB_PUTC2(C1,C2) \ + (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) +# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) +# define OB_PUTID(ID) \ + (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ + IDENTIFIER_LENGTH (ID))) +# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S))) +# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0')) +# define OB_PUTI(CST) do { sprintf (digit_buffer, "%d", (CST)); \ + OB_PUTCP (digit_buffer); } while (0) +# define OB_UNPUT(N) obstack_blank (&scratch_obstack, - (N)); + +# define NEXT_CODE(t) (TREE_CODE (TREE_TYPE (t))) + +static void dump_type (), dump_decl (), dump_function_decl (); +static void dump_expr (), dump_unary_op (), dump_binary_op (); +static void dump_aggr_type (), dump_type_prefix (), dump_type_suffix (); +static void dump_function_name (); + +void +init_error () +{ + gcc_obstack_init (&scratch_obstack); + scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0); +} + +enum pad { none, before, after }; + +static void +dump_readonly_or_volatile (t, p) + tree t; + enum pad p; +{ + if (TYPE_READONLY (t) || TYPE_VOLATILE (t)) + { + if (p == before) OB_PUTC (' '); + if (TYPE_READONLY (t)) + OB_PUTS ("const"); + if (TYPE_READONLY (t) && TYPE_VOLATILE (t)) + OB_PUTC (' '); + if (TYPE_VOLATILE (t)) + OB_PUTS ("volatile"); + if (p == after) OB_PUTC (' '); + } +} + +/* This must be large enough to hold any printed integer or floating-point + value. */ +static char digit_buffer[128]; + +/* Dump into the obstack a human-readable equivalent of TYPE. */ +static void +dump_type (t, v) + tree t; + int v; /* verbose? */ +{ + if (t == NULL_TREE) + return; + + if (TYPE_PTRMEMFUNC_P (t)) + goto offset_type; + + switch (TREE_CODE (t)) + { + case ERROR_MARK: + OB_PUTS ("{error}"); + break; + + case UNKNOWN_TYPE: + OB_PUTS ("{unknown type}"); + break; + + case TREE_LIST: + /* i.e. function taking no arguments */ + if (t != void_list_node) + { + dump_type (TREE_VALUE (t), v); + /* Can this happen other than for default arguments? */ + if (TREE_PURPOSE (t) && v) + { + OB_PUTS (" = "); + dump_expr (TREE_PURPOSE (t)); + } + if (TREE_CHAIN (t)) + { + if (TREE_CHAIN (t) != void_list_node) + { + OB_PUTC2 (',', ' '); + dump_type (TREE_CHAIN (t), v); + } + } + else OB_PUTS (" ..."); + } + break; + + case IDENTIFIER_NODE: + OB_PUTID (t); + break; + + case TREE_VEC: + dump_type (BINFO_TYPE (t), v); + break; + + case RECORD_TYPE: + case UNION_TYPE: + case ENUMERAL_TYPE: + if (TYPE_LANG_SPECIFIC (t) + && (IS_SIGNATURE_POINTER (t) || IS_SIGNATURE_REFERENCE (t))) + { + if (TYPE_READONLY (t) | TYPE_VOLATILE (t)) + dump_readonly_or_volatile (t); + dump_type (SIGNATURE_TYPE (t), v); + if (IS_SIGNATURE_POINTER (t)) + OB_PUTC ('*'); + else + OB_PUTC ('&'); + } + else + dump_aggr_type (t, v); + break; + + case TYPE_DECL: + dump_decl (t, v); + break; + + case INTEGER_TYPE: + if (!TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && TREE_UNSIGNED (t)) + OB_PUTS ("unsigned "); + else if (TREE_UNSIGNED (TYPE_MAIN_VARIANT (t)) && !TREE_UNSIGNED (t)) + OB_PUTS ("signed "); + + /* fall through. */ + case REAL_TYPE: + case VOID_TYPE: + case BOOLEAN_TYPE: + dump_readonly_or_volatile (t, after); + OB_PUTID (TYPE_IDENTIFIER (t)); + break; + + case TEMPLATE_TYPE_PARM: + OB_PUTID (TYPE_IDENTIFIER (t)); + break; + + case UNINSTANTIATED_P_TYPE: + OB_PUTID (DECL_NAME (UPT_TEMPLATE (t))); + OB_PUTS ("<...>"); + break; + + /* This is not always necessary for pointers and such, but doing this + reduces code size. */ + case ARRAY_TYPE: + case POINTER_TYPE: + case REFERENCE_TYPE: + case OFFSET_TYPE: + offset_type: + case FUNCTION_TYPE: + case METHOD_TYPE: + dump_type_prefix (t, v); + dump_type_suffix (t, v); + break; + + default: + sorry ("`%s' not supported by dump_type", + tree_code_name[(int) TREE_CODE (t)]); + } +} + +static char * +aggr_variety (t) + tree t; +{ + if (TREE_CODE (t) == ENUMERAL_TYPE) + return "enum"; + else if (TREE_CODE (t) == UNION_TYPE) + return "union"; + else if (TYPE_LANG_SPECIFIC (t) && CLASSTYPE_DECLARED_CLASS (t)) + return "class"; + else if (TYPE_LANG_SPECIFIC (t) && IS_SIGNATURE (t)) + return "signature"; + else + return "struct"; +} + +/* Print out a class declaration, in the form `class foo'. */ +static void +dump_aggr_type (t, v) + tree t; + int v; /* verbose? */ +{ + tree name; + char *variety = aggr_variety (t); + + dump_readonly_or_volatile (t, after); + + if (v > 0) + { + OB_PUTCP (variety); + OB_PUTC (' '); + } + + name = TYPE_NAME (t); + + if (name && DECL_CONTEXT (name)) + { + /* FUNCTION_DECL or RECORD_TYPE */ + dump_decl (DECL_CONTEXT (name), 0); + OB_PUTC2 (':', ':'); + } + + /* kludge around weird behavior on g++.brendan/line1.C */ + if (name && TREE_CODE (name) != IDENTIFIER_NODE) + name = DECL_NAME (name); + + if (name == 0 || ANON_AGGRNAME_P (name)) + { + OB_PUTS ("{anonymous"); + if (!v) + { + OB_PUTC (' '); + OB_PUTCP (variety); + } + OB_PUTC ('}'); + } + else + OB_PUTID (name); +} + +/* Dump into the obstack the initial part of the output for a given type. + This is necessary when dealing with things like functions returning + functions. Examples: + + return type of `int (* fee ())()': pointer -> function -> int. Both + pointer (and reference and offset) and function (and member) types must + deal with prefix and suffix. + + Arrays must also do this for DECL nodes, like int a[], and for things like + int *[]&. */ + +static void +dump_type_prefix (t, v) + tree t; + int v; /* verbosity */ +{ + if (TYPE_PTRMEMFUNC_P (t)) + { + t = TYPE_PTRMEMFUNC_FN_TYPE (t); + goto offset_type; + } + + switch (TREE_CODE (t)) + { + case POINTER_TYPE: + { + tree sub = TREE_TYPE (t); + + dump_type_prefix (sub, v); + /* A tree for a member pointer looks like pointer to offset, + so let the OFFSET_TYPE case handle it. */ + if (TREE_CODE (sub) != OFFSET_TYPE) + { + switch (TREE_CODE (sub)) + { + /* We don't want int ( *)() */ + case FUNCTION_TYPE: + case METHOD_TYPE: + break; + + case ARRAY_TYPE: + OB_PUTC2 (' ', '('); + break; + + case POINTER_TYPE: + /* We don't want "char * *" */ + if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub))) + break; + /* But we do want "char *const *" */ + + default: + OB_PUTC (' '); + } + OB_PUTC ('*'); + dump_readonly_or_volatile (t, none); + } + } + break; + + case REFERENCE_TYPE: + { + tree sub = TREE_TYPE (t); + dump_type_prefix (sub, v); + + switch (TREE_CODE (sub)) + { + case ARRAY_TYPE: + OB_PUTC2 (' ', '('); + break; + + case POINTER_TYPE: + /* We don't want "char * &" */ + if (! (TYPE_READONLY (sub) || TYPE_VOLATILE (sub))) + break; + /* But we do want "char *const &" */ + + default: + OB_PUTC (' '); + } + } + OB_PUTC ('&'); + dump_readonly_or_volatile (t, none); + break; + + case OFFSET_TYPE: + offset_type: + dump_type_prefix (TREE_TYPE (t), v); + if (TREE_CODE (t) == OFFSET_TYPE) /* pmfs deal with this in d_t_p */ + { + OB_PUTC (' '); + dump_type (TYPE_OFFSET_BASETYPE (t), 0); + OB_PUTC2 (':', ':'); + } + OB_PUTC ('*'); + dump_readonly_or_volatile (t, none); + break; + + /* Can only be reached through function pointer -- this would not be + correct if FUNCTION_DECLs used it. */ + case FUNCTION_TYPE: + dump_type_prefix (TREE_TYPE (t), v); + OB_PUTC2 (' ', '('); + break; + + case METHOD_TYPE: + dump_type_prefix (TREE_TYPE (t), v); + OB_PUTC2 (' ', '('); + dump_aggr_type (TYPE_METHOD_BASETYPE (t), 0); + OB_PUTC2 (':', ':'); + break; + + case ARRAY_TYPE: + dump_type_prefix (TREE_TYPE (t), v); + break; + + case ENUMERAL_TYPE: + case ERROR_MARK: + case IDENTIFIER_NODE: + case INTEGER_TYPE: + case BOOLEAN_TYPE: + case REAL_TYPE: + case RECORD_TYPE: + case TEMPLATE_TYPE_PARM: + case TREE_LIST: + case TYPE_DECL: + case TREE_VEC: + case UNINSTANTIATED_P_TYPE: + case UNION_TYPE: + case UNKNOWN_TYPE: + case VOID_TYPE: + dump_type (t, v); + break; + + default: + sorry ("`%s' not supported by dump_type_prefix", + tree_code_name[(int) TREE_CODE (t)]); + } +} + +static void +dump_type_suffix (t, v) + tree t; + int v; /* verbose? */ +{ + if (TYPE_PTRMEMFUNC_P (t)) + t = TYPE_PTRMEMFUNC_FN_TYPE (t); + + switch (TREE_CODE (t)) + { + case POINTER_TYPE: + case REFERENCE_TYPE: + case OFFSET_TYPE: + if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) + OB_PUTC (')'); + dump_type_suffix (TREE_TYPE (t), v); + break; + + /* Can only be reached through function pointer */ + case FUNCTION_TYPE: + case METHOD_TYPE: + { + tree arg; + OB_PUTC2 (')', '('); + arg = TYPE_ARG_TYPES (t); + if (TREE_CODE (t) == METHOD_TYPE) + arg = TREE_CHAIN (arg); + + if (arg) + dump_type (arg, v); + else + OB_PUTS ("..."); + OB_PUTC (')'); + if (TREE_CODE (t) == METHOD_TYPE) + dump_readonly_or_volatile + (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), before); + dump_type_suffix (TREE_TYPE (t), v); + break; + } + + case ARRAY_TYPE: + OB_PUTC ('['); + if (TYPE_DOMAIN (t)) + OB_PUTI (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (t))) + 1); + OB_PUTC (']'); + dump_type_suffix (TREE_TYPE (t), v); + break; + + case ENUMERAL_TYPE: + case ERROR_MARK: + case IDENTIFIER_NODE: + case INTEGER_TYPE: + case BOOLEAN_TYPE: + case REAL_TYPE: + case RECORD_TYPE: + case TEMPLATE_TYPE_PARM: + case TREE_LIST: + case TYPE_DECL: + case TREE_VEC: + case UNINSTANTIATED_P_TYPE: + case UNION_TYPE: + case UNKNOWN_TYPE: + case VOID_TYPE: + break; + + default: + sorry ("`%s' not supported by dump_type_suffix", + tree_code_name[(int) TREE_CODE (t)]); + } +} + +/* Return a function declaration which corresponds to the IDENTIFIER_NODE + argument. */ +tree +ident_fndecl (t) + tree t; +{ + tree n = lookup_name (t, 0); + + if (n == NULL_TREE) + return NULL_TREE; + + if (TREE_CODE (n) == FUNCTION_DECL) + return n; + else if (TREE_CODE (n) == TREE_LIST + && TREE_CODE (TREE_VALUE (n)) == FUNCTION_DECL) + return TREE_VALUE (n); + + my_friendly_abort (66); + return NULL_TREE; +} + +#ifndef NO_DOLLAR_IN_LABEL +# define GLOBAL_THING "_GLOBAL_$" +#else +# ifndef NO_DOT_IN_LABEL +# define GLOBAL_THING "_GLOBAL_." +# else +# define GLOBAL_THING "_GLOBAL__" +# endif +#endif + +#define GLOBAL_IORD_P(NODE) \ + !strncmp(IDENTIFIER_POINTER(NODE),GLOBAL_THING,sizeof(GLOBAL_THING)-1) + +void +dump_global_iord (t) + tree t; +{ + char *name = IDENTIFIER_POINTER (t); + + OB_PUTS ("(static "); + if (name [sizeof (GLOBAL_THING) - 1] == 'I') + OB_PUTS ("initializers"); + else if (name [sizeof (GLOBAL_THING) - 1] == 'D') + OB_PUTS ("destructors"); + else + my_friendly_abort (352); + + OB_PUTS (" for "); + OB_PUTCP (input_filename); + OB_PUTC (')'); +} + +static void +dump_decl (t, v) + tree t; + int v; /* verbosity */ +{ + if (t == NULL_TREE) + return; + + switch (TREE_CODE (t)) + { + case ERROR_MARK: + OB_PUTS (" /* decl error */ "); + break; + + case TYPE_DECL: + { + /* Don't say 'typedef class A' */ + tree type = TREE_TYPE (t); + if (((IS_AGGR_TYPE (type) && ! TYPE_PTRMEMFUNC_P (type)) + || TREE_CODE (type) == ENUMERAL_TYPE) + && type == TYPE_MAIN_VARIANT (type)) + { + dump_type (type, v); + break; + } + } + if (v > 0) + OB_PUTS ("typedef "); + goto general; + break; + + case VAR_DECL: + if (DECL_NAME (t) && VTABLE_NAME_P (DECL_NAME (t))) + { + OB_PUTS ("vtable for "); + dump_type (DECL_CONTEXT (t), v); + break; + } + /* else fall through */ + case FIELD_DECL: + case PARM_DECL: + general: + if (v > 0) + { + dump_type_prefix (TREE_TYPE (t), v); + OB_PUTC (' '); + dump_readonly_or_volatile (t, after); + } + /* DECL_CLASS_CONTEXT isn't being set in some cases. Hmm... */ + if (DECL_CONTEXT (t) + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't') + { + dump_type (DECL_CONTEXT (t), 0); + OB_PUTC2 (':', ':'); + } + if (DECL_NAME (t)) + dump_decl (DECL_NAME (t), v); + else + OB_PUTS ("{anon}"); + if (v > 0) + dump_type_suffix (TREE_TYPE (t), v); + break; + + case NAMESPACE_DECL: + OB_PUTID (DECL_NAME (t)); + break; + + case ARRAY_REF: + dump_decl (TREE_OPERAND (t, 0), v); + OB_PUTC ('['); + dump_decl (TREE_OPERAND (t, 1), v); + OB_PUTC (']'); + break; + + /* So that we can do dump_decl in dump_aggr_type and have it work for + both class and function scope. */ + case RECORD_TYPE: + case UNION_TYPE: + case ENUMERAL_TYPE: + dump_type (t, v); + break; + + case TYPE_EXPR: + my_friendly_abort (69); + break; + + /* These special cases are duplicated here so that other functions + can feed identifiers to cp_error and get them demangled properly. */ + case IDENTIFIER_NODE: + { tree f; + if (DESTRUCTOR_NAME_P (t) + && (f = ident_fndecl (t)) + && DECL_LANGUAGE (f) == lang_cplusplus) + { + OB_PUTC ('~'); + dump_decl (DECL_NAME (f), 0); + } + else if (IDENTIFIER_TYPENAME_P (t)) + { + OB_PUTS ("operator "); + /* Not exactly IDENTIFIER_TYPE_VALUE. */ + dump_type (TREE_TYPE (t), 0); + break; + } + else if (IDENTIFIER_OPNAME_P (t)) + { + char *name_string = operator_name_string (t); + OB_PUTS ("operator "); + OB_PUTCP (name_string); + } + else + OB_PUTID (t); + } + break; + + case FUNCTION_DECL: + if (GLOBAL_IORD_P (DECL_ASSEMBLER_NAME (t))) + dump_global_iord (DECL_ASSEMBLER_NAME (t)); + else + dump_function_decl (t, v); + break; + + case TEMPLATE_DECL: + { + tree args = DECL_TEMPLATE_PARMS (t); + int i, len = args ? TREE_VEC_LENGTH (args) : 0; + OB_PUTS ("template <"); + for (i = 0; i < len; i++) + { + tree arg = TREE_VEC_ELT (args, i); + tree defval = TREE_PURPOSE (arg); + arg = TREE_VALUE (arg); + if (TREE_CODE (arg) == TYPE_DECL) + { + OB_PUTS ("class "); + OB_PUTID (DECL_NAME (arg)); + } + else + dump_decl (arg, 1); + + if (defval) + { + OB_PUTS (" = "); + dump_decl (defval, 1); + } + + OB_PUTC2 (',', ' '); + } + if (len != 0) + OB_UNPUT (2); + OB_PUTC2 ('>', ' '); + + if (DECL_TEMPLATE_IS_CLASS (t)) + { + OB_PUTS ("class "); + OB_PUTID (DECL_NAME (t)); + } + else switch (NEXT_CODE (t)) + { + case METHOD_TYPE: + case FUNCTION_TYPE: + dump_function_decl (t, v); + break; + + default: + my_friendly_abort (353); + } + } + break; + + case LABEL_DECL: + OB_PUTID (DECL_NAME (t)); + break; + + case CONST_DECL: + if (NEXT_CODE (t) == ENUMERAL_TYPE) + goto general; + else + dump_expr (DECL_INITIAL (t), 0); + break; + + default: + sorry ("`%s' not supported by dump_decl", + tree_code_name[(int) TREE_CODE (t)]); + } +} + +/* Pretty printing for announce_function. T is the declaration of the + function we are interested in seeing. V is non-zero if we should print + the type that this function returns. */ + +static void +dump_function_decl (t, v) + tree t; + int v; +{ + tree name = DECL_ASSEMBLER_NAME (t); + tree fntype = TREE_TYPE (t); + tree parmtypes = TYPE_ARG_TYPES (fntype); + tree cname = NULL_TREE; + + /* Friends have DECL_CLASS_CONTEXT set, but not DECL_CONTEXT. */ + if (DECL_CONTEXT (t)) + cname = DECL_CLASS_CONTEXT (t); + /* this is for partially instantiated template methods */ + else if (TREE_CODE (fntype) == METHOD_TYPE) + cname = TREE_TYPE (TREE_VALUE (parmtypes)); + + v = (v > 0); + + if (v) + { + if (DECL_STATIC_FUNCTION_P (t)) + OB_PUTS ("static "); + + if (! IDENTIFIER_TYPENAME_P (name) + && ! DECL_CONSTRUCTOR_P (t) + && ! DESTRUCTOR_NAME_P (name)) + { + dump_type_prefix (TREE_TYPE (fntype), 1); + OB_PUTC (' '); + } + } + + if (cname) + { + dump_type (cname, 0); + OB_PUTC2 (':', ':'); + if (TREE_CODE (fntype) == METHOD_TYPE && parmtypes) + parmtypes = TREE_CHAIN (parmtypes); + if (DECL_CONSTRUCTOR_FOR_VBASE_P (t)) + /* Skip past "in_charge" identifier. */ + parmtypes = TREE_CHAIN (parmtypes); + } + + if (DESTRUCTOR_NAME_P (name) && DECL_LANGUAGE (t) == lang_cplusplus) + parmtypes = TREE_CHAIN (parmtypes); + + dump_function_name (t); + + OB_PUTC ('('); + + if (parmtypes) + dump_type (parmtypes, v); + else + OB_PUTS ("..."); + + OB_PUTC (')'); + + if (v && ! IDENTIFIER_TYPENAME_P (name)) + dump_type_suffix (TREE_TYPE (fntype), 1); + + if (TREE_CODE (fntype) == METHOD_TYPE) + { + if (IS_SIGNATURE (cname)) + /* We look at the type pointed to by the `optr' field of `this.' */ + dump_readonly_or_volatile + (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (TYPE_ARG_TYPES (fntype))))), before); + else + dump_readonly_or_volatile + (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))), before); + } +} + +/* Handle the function name for a FUNCTION_DECL node, grokking operators + and destructors properly. */ +static void +dump_function_name (t) + tree t; +{ + tree name = DECL_NAME (t); + + /* There ought to be a better way to find out whether or not something is + a destructor. */ + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (t)) + && DECL_LANGUAGE (t) == lang_cplusplus) + { + OB_PUTC ('~'); + dump_decl (name, 0); + } + else if (IDENTIFIER_TYPENAME_P (name)) + { + /* This cannot use the hack that the operator's return + type is stashed off of its name because it may be + used for error reporting. In the case of conflicting + declarations, both will have the same name, yet + the types will be different, hence the TREE_TYPE field + of the first name will be clobbered by the second. */ + OB_PUTS ("operator "); + dump_type (TREE_TYPE (TREE_TYPE (t)), 0); + } + else if (IDENTIFIER_OPNAME_P (name)) + { + char *name_string = operator_name_string (name); + OB_PUTS ("operator "); + OB_PUTCP (name_string); + } + else + dump_decl (name, 0); +} + +static void +dump_char (c) + char c; +{ + switch (c) + { + case TARGET_NEWLINE: + OB_PUTS ("\\n"); + break; + case TARGET_TAB: + OB_PUTS ("\\t"); + break; + case TARGET_VT: + OB_PUTS ("\\v"); + break; + case TARGET_BS: + OB_PUTS ("\\b"); + break; + case TARGET_CR: + OB_PUTS ("\\r"); + break; + case TARGET_FF: + OB_PUTS ("\\f"); + break; + case TARGET_BELL: + OB_PUTS ("\\a"); + break; + case '\\': + OB_PUTS ("\\\\"); + break; + case '\'': + OB_PUTS ("\\'"); + break; + case '\"': + OB_PUTS ("\\\""); + break; + default: + if (isprint (c)) + OB_PUTC (c); + else + { + sprintf (digit_buffer, "\\%03o", (int) c); + OB_PUTCP (digit_buffer); + } + } +} + +/* Print out a list of initializers (subr of dump_expr) */ +static void +dump_expr_list (l) + tree l; +{ + while (l) + { + dump_expr (TREE_VALUE (l), 0); + if (TREE_CHAIN (l)) + OB_PUTC2 (',', ' '); + l = TREE_CHAIN (l); + } +} + +/* Print out an expression */ +static void +dump_expr (t, nop) + tree t; + int nop; /* suppress parens */ +{ + switch (TREE_CODE (t)) + { + case VAR_DECL: + case PARM_DECL: + case FIELD_DECL: + case CONST_DECL: + case FUNCTION_DECL: + dump_decl (t, -1); + break; + + case INTEGER_CST: + { + tree type = TREE_TYPE (t); + my_friendly_assert (type != 0, 81); + + /* If it's an enum, output its tag, rather than its value. */ + if (TREE_CODE (type) == ENUMERAL_TYPE) + { + char *p = enum_name_string (t, type); + OB_PUTCP (p); + } + else if (type == boolean_type_node) + { + if (t == boolean_false_node) + OB_PUTS ("false"); + else if (t == boolean_true_node) + OB_PUTS ("true"); + else + my_friendly_abort (366); + } + else if (type == char_type_node) + { + OB_PUTC ('\''); + dump_char (TREE_INT_CST_LOW (t)); + OB_PUTC ('\''); + } + else if (TREE_INT_CST_HIGH (t) + != (TREE_INT_CST_LOW (t) >> (HOST_BITS_PER_WIDE_INT - 1))) + { + tree val = t; + if (TREE_INT_CST_HIGH (val) < 0) + { + OB_PUTC ('-'); + val = build_int_2 (~TREE_INT_CST_LOW (val), + -TREE_INT_CST_HIGH (val)); + } + /* Would "%x%0*x" or "%x%*0x" get zero-padding on all + systems? */ + { + static char format[10]; /* "%x%09999x\0" */ + if (!format[0]) + sprintf (format, "%%x%%0%dx", HOST_BITS_PER_INT / 4); + sprintf (digit_buffer, format, TREE_INT_CST_HIGH (val), + TREE_INT_CST_LOW (val)); + OB_PUTCP (digit_buffer); + } + } + else + OB_PUTI (TREE_INT_CST_LOW (t)); + } + break; + + case REAL_CST: +#ifndef REAL_IS_NOT_DOUBLE + sprintf (digit_buffer, "%g", TREE_REAL_CST (t)); +#else + { + unsigned char *p = (unsigned char *) &TREE_REAL_CST (t); + int i; + strcpy (digit_buffer, "0x"); + for (i = 0; i < sizeof TREE_REAL_CST (t); i++) + sprintf (digit_buffer + 2 + 2*i, "%02x", *p++); + } +#endif + OB_PUTCP (digit_buffer); + break; + + case STRING_CST: + { + char *p = TREE_STRING_POINTER (t); + int len = TREE_STRING_LENGTH (t) - 1; + int i; + + OB_PUTC ('\"'); + for (i = 0; i < len; i++) + dump_char (p[i]); + OB_PUTC ('\"'); + } + break; + + case COMPOUND_EXPR: + dump_binary_op (",", t); + break; + + case COND_EXPR: + OB_PUTC ('('); + dump_expr (TREE_OPERAND (t, 0), 0); + OB_PUTS (" ? "); + dump_expr (TREE_OPERAND (t, 1), 0); + OB_PUTS (" : "); + dump_expr (TREE_OPERAND (t, 2), 0); + OB_PUTC (')'); + break; + + case SAVE_EXPR: + if (TREE_HAS_CONSTRUCTOR (t)) + { + OB_PUTS ("new "); + dump_type (TREE_TYPE (TREE_TYPE (t)), 0); + PARM_DECL_EXPR (t) = 1; + } + else + { + dump_expr (TREE_OPERAND (t, 0), 0); + } + break; + + case NEW_EXPR: + OB_PUTID (TYPE_IDENTIFIER (TREE_TYPE (t))); + OB_PUTC ('('); + dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1))); + OB_PUTC (')'); + break; + + case CALL_EXPR: + { + tree fn = TREE_OPERAND (t, 0); + tree args = TREE_OPERAND (t, 1); + + if (TREE_CODE (fn) == ADDR_EXPR) + fn = TREE_OPERAND (fn, 0); + + if (NEXT_CODE (fn) == METHOD_TYPE) + { + tree ob = TREE_VALUE (args); + if (TREE_CODE (ob) == ADDR_EXPR) + { + dump_expr (TREE_OPERAND (ob, 0), 0); + OB_PUTC ('.'); + } + else if (TREE_CODE (ob) != PARM_DECL + || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")) + { + dump_expr (ob, 0); + OB_PUTC2 ('-', '>'); + } + args = TREE_CHAIN (args); + } + dump_expr (fn, 0); + OB_PUTC('('); + dump_expr_list (args); + OB_PUTC (')'); + } + break; + + case WITH_CLEANUP_EXPR: + /* Note that this only works for G++ cleanups. If somebody + builds a general cleanup, there's no way to represent it. */ + dump_expr (TREE_OPERAND (t, 0), 0); + break; + + case TARGET_EXPR: + /* Note that this only works for G++ target exprs. If somebody + builds a general TARGET_EXPR, there's no way to represent that + it initializes anything other that the parameter slot for the + default argument. Note we may have cleared out the first + operand in expand_expr, so don't go killing ourselves. */ + if (TREE_OPERAND (t, 1)) + dump_expr (TREE_OPERAND (t, 1), 0); + break; + + case MODIFY_EXPR: + case PLUS_EXPR: + case MINUS_EXPR: + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + case MIN_EXPR: + case MAX_EXPR: + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + case BIT_AND_EXPR: + case BIT_ANDTC_EXPR: + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case LT_EXPR: + case LE_EXPR: + case GT_EXPR: + case GE_EXPR: + case EQ_EXPR: + case NE_EXPR: + dump_binary_op (opname_tab[(int) TREE_CODE (t)], t); + break; + + case CEIL_DIV_EXPR: + case FLOOR_DIV_EXPR: + case ROUND_DIV_EXPR: + dump_binary_op ("/", t); + break; + + case CEIL_MOD_EXPR: + case FLOOR_MOD_EXPR: + case ROUND_MOD_EXPR: + dump_binary_op ("%", t); + break; + + case COMPONENT_REF: + { + tree ob = TREE_OPERAND (t, 0); + if (TREE_CODE (ob) == INDIRECT_REF) + { + ob = TREE_OPERAND (ob, 0); + if (TREE_CODE (ob) != PARM_DECL + || strcmp (IDENTIFIER_POINTER (DECL_NAME (ob)), "this")) + { + dump_expr (ob, 0); + OB_PUTC2 ('-', '>'); + } + } + else + { + dump_expr (ob, 0); + OB_PUTC ('.'); + } + dump_expr (TREE_OPERAND (t, 1), 1); + } + break; + + case ARRAY_REF: + dump_expr (TREE_OPERAND (t, 0), 0); + OB_PUTC ('['); + dump_expr (TREE_OPERAND (t, 1), 0); + OB_PUTC (']'); + break; + + case CONVERT_EXPR: + dump_unary_op ("+", t, nop); + break; + + case ADDR_EXPR: + if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL + || TREE_CODE (TREE_OPERAND (t, 0)) == STRING_CST) + dump_expr (TREE_OPERAND (t, 0), 0); + else + dump_unary_op ("&", t, nop); + break; + + case INDIRECT_REF: + if (TREE_HAS_CONSTRUCTOR (t)) + { + t = TREE_OPERAND (t, 0); + my_friendly_assert (TREE_CODE (t) == CALL_EXPR, 237); + dump_expr (TREE_OPERAND (t, 0), 0); + OB_PUTC ('('); + dump_expr_list (TREE_CHAIN (TREE_OPERAND (t, 1))); + OB_PUTC (')'); + } + else + { + if (NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE) + dump_expr (TREE_OPERAND (t, 0), nop); + else + dump_unary_op ("*", t, nop); + } + break; + + case NEGATE_EXPR: + case BIT_NOT_EXPR: + case TRUTH_NOT_EXPR: + case PREDECREMENT_EXPR: + case PREINCREMENT_EXPR: + dump_unary_op (opname_tab [(int)TREE_CODE (t)], t, nop); + break; + + case POSTDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + OB_PUTC ('('); + dump_expr (TREE_OPERAND (t, 0), 0); + OB_PUTCP (opname_tab[(int)TREE_CODE (t)]); + OB_PUTC (')'); + break; + + case NON_LVALUE_EXPR: + /* FIXME: This is a KLUDGE workaround for a parsing problem. There + should be another level of INDIRECT_REF so that I don't have to do + this. */ + if (NEXT_CODE (t) == POINTER_TYPE) + { + tree next = TREE_TYPE (TREE_TYPE (t)); + + while (TREE_CODE (next) == POINTER_TYPE) + next = TREE_TYPE (next); + + if (TREE_CODE (next) == FUNCTION_TYPE) + { + if (!nop) OB_PUTC ('('); + OB_PUTC ('*'); + dump_expr (TREE_OPERAND (t, 0), 1); + if (!nop) OB_PUTC (')'); + break; + } + /* else FALLTHRU */ + } + dump_expr (TREE_OPERAND (t, 0), 0); + break; + + case NOP_EXPR: + dump_expr (TREE_OPERAND (t, 0), nop); + break; + + case CONSTRUCTOR: + OB_PUTC ('{'); + dump_expr_list (CONSTRUCTOR_ELTS (t), 0); + OB_PUTC ('}'); + break; + + case OFFSET_REF: + { + tree ob = TREE_OPERAND (t, 0); + if (TREE_CODE (ob) == NOP_EXPR + && TREE_OPERAND (ob, 0) == error_mark_node + && TREE_CODE (TREE_OPERAND (t, 1)) == FUNCTION_DECL) + /* A::f */ + dump_expr (TREE_OPERAND (t, 1), 0); + else + { + sorry ("operand of OFFSET_REF not understood"); + goto error; + } + break; + } + + case TREE_LIST: + if (TREE_VALUE (t) && TREE_CODE (TREE_VALUE (t)) == FUNCTION_DECL) + { + OB_PUTID (DECL_NAME (TREE_VALUE (t))); + break; + } + /* else fall through */ + + /* This list is incomplete, but should suffice for now. + It is very important that `sorry' does not call + `report_error_function'. That could cause an infinite loop. */ + default: + sorry ("`%s' not supported by dump_expr", + tree_code_name[(int) TREE_CODE (t)]); + + /* fall through to ERROR_MARK... */ + case ERROR_MARK: + error: + OB_PUTCP ("{error}"); + break; + } +} + +static void +dump_binary_op (opstring, t) + char *opstring; + tree t; +{ + OB_PUTC ('('); + dump_expr (TREE_OPERAND (t, 0), 1); + OB_PUTC (' '); + OB_PUTCP (opstring); + OB_PUTC (' '); + dump_expr (TREE_OPERAND (t, 1), 1); + OB_PUTC (')'); +} + +static void +dump_unary_op (opstring, t, nop) + char *opstring; + tree t; + int nop; +{ + if (!nop) OB_PUTC ('('); + OB_PUTCP (opstring); + dump_expr (TREE_OPERAND (t, 0), 1); + if (!nop) OB_PUTC (')'); +} + +char * +fndecl_as_string (cname, fndecl, print_ret_type_p) + tree cname, fndecl; + int print_ret_type_p; +{ + return decl_as_string (fndecl, print_ret_type_p); +} + +/* Same, but handtype a _TYPE. + Called from convert_to_reference, mangle_class_name_for_template, + build_unary_op, and GNU_xref_decl. */ +char * +type_as_string (typ, v) + tree typ; + int v; +{ + OB_INIT (); + + dump_type (typ, v); + + OB_FINISH (); + + return (char *)obstack_base (&scratch_obstack); +} + +char * +expr_as_string (decl, v) + tree decl; + int v; +{ + OB_INIT (); + + dump_expr (decl, 1); + + OB_FINISH (); + + return (char *)obstack_base (&scratch_obstack); +} + +/* A cross between type_as_string and fndecl_as_string. + Only called from substitute_nice_name. */ +char * +decl_as_string (decl, v) + tree decl; + int v; +{ + OB_INIT (); + + dump_decl (decl, v); + + OB_FINISH (); + + return (char *)obstack_base (&scratch_obstack); +} + +char * +cp_file_of (t) + tree t; +{ + if (TREE_CODE (t) == PARM_DECL) + return DECL_SOURCE_FILE (DECL_CONTEXT (t)); + else if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') + return DECL_SOURCE_FILE (TYPE_NAME (t)); + else + return DECL_SOURCE_FILE (t); +} + +int +cp_line_of (t) + tree t; +{ + int line = 0; + if (TREE_CODE (t) == PARM_DECL) + line = DECL_SOURCE_LINE (DECL_CONTEXT (t)); + if (TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)) + t = TREE_TYPE (t); + + if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') + { + if (IS_AGGR_TYPE (t)) + line = CLASSTYPE_SOURCE_LINE (t); + else + line = DECL_SOURCE_LINE (TYPE_NAME (t)); + } + else + line = DECL_SOURCE_LINE (t); + + if (line == 0) + return lineno; + + return line; +} + +char * +code_as_string (c, v) + enum tree_code c; + int v; +{ + return tree_code_name [c]; +} + +char * +language_as_string (c, v) + enum languages c; + int v; +{ + switch (c) + { + case lang_c: + return "C"; + + case lang_cplusplus: + return "C++"; + + default: + my_friendly_abort (355); + return 0; + } +} + +/* Return the proper printed version of a parameter to a C++ function. */ +char * +parm_as_string (p, v) + int p, v; +{ + if (p < 0) + return "`this'"; + + sprintf (digit_buffer, "%d", p+1); + return digit_buffer; +} + +char * +op_as_string (p, v) + enum tree_code p; + int v; +{ + static char buf[] = "operator "; + + if (p == 0) + return "{unknown}"; + + strcpy (buf + 9, opname_tab [p]); + return buf; +} + +char * +args_as_string (p, v) + tree p; + int v; +{ + if (p == NULL_TREE) + return "..."; + + return type_as_string (p, v); +} + +char * +cv_as_string (p, v) + tree p; + int v; +{ + OB_INIT (); + + dump_readonly_or_volatile (p, before); + + OB_FINISH (); + + return (char *)obstack_base (&scratch_obstack); +} diff --git a/contrib/gcc/cp/except.c b/contrib/gcc/cp/except.c new file mode 100644 index 00000000000..51577f85afa --- /dev/null +++ b/contrib/gcc/cp/except.c @@ -0,0 +1,1690 @@ +/* Handle exceptional things in C++. + Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann + Rewritten by Mike Stump , based upon an + initial re-implementation courtesy Tad Hunt. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "cp-tree.h" +#include "flags.h" +#include "obstack.h" +#include "expr.h" + +tree protect_list; + +extern void (*interim_eh_hook) PROTO((tree)); +rtx expand_builtin_return_addr PROTO((enum built_in_function, int, rtx)); + +/* holds the fndecl for __builtin_return_address () */ +tree builtin_return_address_fndecl; +tree throw_fndecl; + +static int +doing_eh (do_warn) + int do_warn; +{ + if (! flag_handle_exceptions) + { + static int warned = 0; + if (! warned && do_warn) + { + error ("exception handling disabled, use -fhandle-exceptions to enable."); + warned = 1; + } + return 0; + } + return 1; +} + + +/* +NO GNEWS IS GOOD GNEWS WITH GARRY GNUS: This version is much closer +to supporting exception handling as per ANSI C++ working draft. +It is a complete rewrite of all the EH stuff that was here before + Shortcomings: + 1. Throw specifications of functions still don't work. + Cool Things: + 1. Destructors are called properly :-) + 2. No overhead for the non-exception thrown case. + 3. Fixing shortcoming 1 is simple. + -Tad Hunt (tad@mail.csh.rit.edu) + +*/ + +/* A couple of backend routines from m88k.c */ + +/* used to cache a call to __builtin_return_address () */ +static tree BuiltinReturnAddress; + + +#include + +/* XXX - Tad: for EH */ +/* output an exception table entry */ + +static void +output_exception_table_entry (file, start_label, end_label, eh_label) + FILE *file; + rtx start_label, end_label, eh_label; +{ + char label[100]; + + assemble_integer (start_label, GET_MODE_SIZE (Pmode), 1); + assemble_integer (end_label, GET_MODE_SIZE (Pmode), 1); + assemble_integer (eh_label, GET_MODE_SIZE (Pmode), 1); + putc ('\n', file); /* blank line */ +} + +static void +easy_expand_asm (str) + char *str; +{ + expand_asm (build_string (strlen (str)+1, str)); +} + + +#if 0 +/* This is the startup, and finish stuff per exception table. */ + +/* XXX - Tad: exception handling section */ +#ifndef EXCEPT_SECTION_ASM_OP +#define EXCEPT_SECTION_ASM_OP "section\t.gcc_except_table,\"a\",@progbits" +#endif + +#ifdef EXCEPT_SECTION_ASM_OP +typedef struct { + void *start_protect; + void *end_protect; + void *exception_handler; + } exception_table; +#endif /* EXCEPT_SECTION_ASM_OP */ + +#ifdef EXCEPT_SECTION_ASM_OP + + /* on machines which support it, the exception table lives in another section, + but it needs a label so we can reference it... This sets up that + label! */ +asm (EXCEPT_SECTION_ASM_OP); +exception_table __EXCEPTION_TABLE__[1] = { (void*)0, (void*)0, (void*)0 }; +asm (TEXT_SECTION_ASM_OP); + +#endif /* EXCEPT_SECTION_ASM_OP */ + +#ifdef EXCEPT_SECTION_ASM_OP + + /* we need to know where the end of the exception table is... so this + is how we do it! */ + +asm (EXCEPT_SECTION_ASM_OP); +exception_table __EXCEPTION_END__[1] = { (void*)-1, (void*)-1, (void*)-1 }; +asm (TEXT_SECTION_ASM_OP); + +#endif /* EXCEPT_SECTION_ASM_OP */ + +#endif + +void +exception_section () +{ +#ifdef ASM_OUTPUT_SECTION_NAME + named_section (NULL_TREE, ".gcc_except_table"); +#else + if (flag_pic) + data_section (); + else +#if defined(TARGET_POWERPC) /* are we on a __rs6000? */ + data_section (); +#else + readonly_data_section (); +#endif +#endif +} + + + + +/* from: my-cp-except.c */ + +/* VI: ":set ts=4" */ +#if 0 +#include */ +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "cp-tree.h" +#endif +#include "decl.h" +#if 0 +#include "flags.h" +#endif +#include "insn-flags.h" +#include "obstack.h" +#if 0 +#include "expr.h" +#endif + +/* ====================================================================== + Briefly the algorithm works like this: + + When a constructor or start of a try block is encountered, + push_eh_entry (&eh_stack) is called. Push_eh_entry () creates a + new entry in the unwind protection stack and returns a label to + output to start the protection for that block. + + When a destructor or end try block is encountered, pop_eh_entry + (&eh_stack) is called. Pop_eh_entry () returns the ehEntry it + created when push_eh_entry () was called. The ehEntry structure + contains three things at this point. The start protect label, + the end protect label, and the exception handler label. The end + protect label should be output before the call to the destructor + (if any). If it was a destructor, then its parse tree is stored + in the finalization variable in the ehEntry structure. Otherwise + the finalization variable is set to NULL to reflect the fact that + is the the end of a try block. Next, this modified ehEntry node + is enqueued in the finalizations queue by calling + enqueue_eh_entry (&queue,entry). + + +---------------------------------------------------------------+ + |XXX: Will need modification to deal with partially | + | constructed arrays of objects | + | | + | Basically, this consists of keeping track of how many | + | of the objects have been constructed already (this | + | should be in a register though, so that shouldn't be a | + | problem. | + +---------------------------------------------------------------+ + + When a catch block is encountered, there is a lot of work to be + done. + + Since we don't want to generate the catch block inline with the + regular flow of the function, we need to have some way of doing + so. Luckily, we can use sequences to defer the catch sections. + When the start of a catch block is encountered, we start the + sequence. After the catch block is generated, we end the + sequence. + + Next we must insure that when the catch block is executed, all + finalizations for the matching try block have been completed. If + any of those finalizations throw an exception, we must call + terminate according to the ARM (section r.15.6.1). What this + means is that we need to dequeue and emit finalizations for each + entry in the ehQueue until we get to an entry with a NULL + finalization field. For any of the finalization entries, if it + is not a call to terminate (), we must protect it by giving it + another start label, end label, and exception handler label, + setting its finalization tree to be a call to terminate (), and + enqueue'ing this new ehEntry to be output at an outer level. + Finally, after all that is done, we can get around to outputting + the catch block which basically wraps all the "catch (...) {...}" + statements in a big if/then/else construct that matches the + correct block to call. + + ===================================================================== */ + +extern rtx emit_insn PROTO((rtx)); +extern rtx gen_nop PROTO(()); + +/* local globals for function calls + ====================================================================== */ + +/* used to cache "terminate ()", "unexpected ()", "set_terminate ()", and + "set_unexpected ()" after default_conversion. (lib-except.c) */ +static tree Terminate, Unexpected, SetTerminate, SetUnexpected, CatchMatch, Throw; + +/* used to cache __find_first_exception_table_match () + for throw (lib-except.c) */ +static tree FirstExceptionMatch; + +/* used to cache a call to __unwind_function () (lib-except.c) */ +static tree Unwind; + +/* holds a ready to emit call to "terminate ()". */ +static tree TerminateFunctionCall; + +/* ====================================================================== */ + + + +/* data structures for my various quick and dirty stacks and queues + Eventually, most of this should go away, because I think it can be + integrated with stuff already built into the compiler. */ + +/* =================================================================== */ + +struct labelNode { + rtx label; + struct labelNode *chain; +}; + + +/* this is the most important structure here. Basically this is how I store + an exception table entry internally. */ +struct ehEntry { + rtx start_label; + rtx end_label; + rtx exception_handler_label; + + tree finalization; + tree context; +}; + +struct ehNode { + struct ehEntry *entry; + struct ehNode *chain; +}; + +struct ehStack { + struct ehNode *top; +}; + +struct ehQueue { + struct ehNode *head; + struct ehNode *tail; +}; +/* ========================================================================= */ + + + +/* local globals - these local globals are for storing data necessary for + generating the exception table and code in the correct order. + + ========================================================================= */ + +/* Holds the pc for doing "throw" */ +tree saved_pc; +/* Holds the type of the thing being thrown. */ +tree saved_throw_type; +/* Holds the value being thrown. */ +tree saved_throw_value; + +int throw_used; + +static rtx catch_clauses; +static first_catch_label; + +static struct ehStack ehstack; +static struct ehQueue ehqueue; +static struct ehQueue eh_table_output_queue; +static struct labelNode *false_label_stack = NULL; +static struct labelNode *caught_return_label_stack = NULL; +/* ========================================================================= */ + +/* function prototypes */ +static struct ehEntry *pop_eh_entry PROTO((struct ehStack *stack)); +static void enqueue_eh_entry PROTO((struct ehQueue *queue, struct ehEntry *entry)); +static rtx push_eh_entry PROTO((struct ehStack *stack)); +static struct ehEntry *dequeue_eh_entry PROTO((struct ehQueue *queue)); +static void new_eh_queue PROTO((struct ehQueue *queue)); +static void new_eh_stack PROTO((struct ehStack *stack)); +static void push_label_entry PROTO((struct labelNode **labelstack, rtx label)); +static rtx pop_label_entry PROTO((struct labelNode **labelstack)); +static rtx top_label_entry PROTO((struct labelNode **labelstack)); +static struct ehEntry *copy_eh_entry PROTO((struct ehEntry *entry)); + + + +/* All my cheesy stack/queue/misc data structure handling routines + + ========================================================================= */ + +static void +push_label_entry (labelstack, label) + struct labelNode **labelstack; + rtx label; +{ + struct labelNode *newnode=(struct labelNode*)xmalloc (sizeof (struct labelNode)); + + newnode->label = label; + newnode->chain = *labelstack; + *labelstack = newnode; +} + +static rtx +pop_label_entry (labelstack) + struct labelNode **labelstack; +{ + rtx label; + struct labelNode *tempnode; + + if (! *labelstack) return NULL_RTX; + + tempnode = *labelstack; + label = tempnode->label; + *labelstack = (*labelstack)->chain; + free (tempnode); + + return label; +} + +static rtx +top_label_entry (labelstack) + struct labelNode **labelstack; +{ + if (! *labelstack) return NULL_RTX; + + return (*labelstack)->label; +} + +/* Push to permanent obstack for rtl generation. + One level only! */ +static struct obstack *saved_rtl_obstack; +void +push_rtl_perm () +{ + extern struct obstack permanent_obstack; + extern struct obstack *rtl_obstack; + + saved_rtl_obstack = rtl_obstack; + rtl_obstack = &permanent_obstack; +} + +/* Pop back to normal rtl handling. */ +static void +pop_rtl_from_perm () +{ + extern struct obstack permanent_obstack; + extern struct obstack *rtl_obstack; + + rtl_obstack = saved_rtl_obstack; +} + +static rtx +push_eh_entry (stack) + struct ehStack *stack; +{ + struct ehNode *node = (struct ehNode*)xmalloc (sizeof (struct ehNode)); + struct ehEntry *entry = (struct ehEntry*)xmalloc (sizeof (struct ehEntry)); + + if (stack == NULL) { + free (node); + free (entry); + return NULL_RTX; + } + + /* These are saved for the exception table. */ + push_rtl_perm (); + entry->start_label = gen_label_rtx (); + entry->end_label = gen_label_rtx (); + entry->exception_handler_label = gen_label_rtx (); + pop_rtl_from_perm (); + + LABEL_PRESERVE_P (entry->start_label) = 1; + LABEL_PRESERVE_P (entry->end_label) = 1; + LABEL_PRESERVE_P (entry->exception_handler_label) = 1; + + entry->finalization = NULL_TREE; + entry->context = current_function_decl; + + node->entry = entry; + node->chain = stack->top; + stack->top = node; + + enqueue_eh_entry (&eh_table_output_queue, copy_eh_entry (entry)); + + return entry->start_label; +} + +static struct ehEntry * +pop_eh_entry (stack) + struct ehStack *stack; +{ + struct ehNode *tempnode; + struct ehEntry *tempentry; + + if (stack && (tempnode = stack->top)) { + tempentry = tempnode->entry; + stack->top = stack->top->chain; + free (tempnode); + + return tempentry; + } + + return NULL; +} + +static struct ehEntry * +copy_eh_entry (entry) + struct ehEntry *entry; +{ + struct ehEntry *newentry; + + newentry = (struct ehEntry*)xmalloc (sizeof (struct ehEntry)); + memcpy ((void*)newentry, (void*)entry, sizeof (struct ehEntry)); + + return newentry; +} + +static void +enqueue_eh_entry (queue, entry) + struct ehQueue *queue; + struct ehEntry *entry; +{ + struct ehNode *node = (struct ehNode*)xmalloc (sizeof (struct ehNode)); + + node->entry = entry; + node->chain = NULL; + + if (queue->head == NULL) + { + queue->head = node; + } + else + { + queue->tail->chain = node; + } + queue->tail = node; +} + +static struct ehEntry * +dequeue_eh_entry (queue) + struct ehQueue *queue; +{ + struct ehNode *tempnode; + struct ehEntry *tempentry; + + if (queue->head == NULL) + return NULL; + + tempnode = queue->head; + queue->head = queue->head->chain; + + tempentry = tempnode->entry; + free (tempnode); + + return tempentry; +} + +static void +new_eh_queue (queue) + struct ehQueue *queue; +{ + queue->head = queue->tail = NULL; +} + +static void +new_eh_stack (stack) + struct ehStack *stack; +{ + stack->top = NULL; +} + +/* cheesyness to save some typing. returns the return value rtx */ +rtx +do_function_call (func, params, return_type) + tree func, params, return_type; +{ + tree func_call; + func_call = build_function_call (func, params); + expand_call (func_call, NULL_RTX, 0); + if (return_type != NULL_TREE) + return hard_function_value (return_type, func_call); + return NULL_RTX; +} + +static void +expand_internal_throw (pc) + rtx pc; +{ + tree params; + + emit_move_insn (DECL_RTL (saved_pc), pc); +#ifdef JUMP_TO_THROW + emit_indirect_jump (gen_rtx (SYMBOL_REF, Pmode, "__throw")); +#else + do_function_call (Throw, NULL_TREE, NULL_TREE); +#endif + throw_used = 1; +} + +/* ========================================================================= */ + +void +lang_interim_eh (finalization) + tree finalization; +{ + if (finalization) + end_protect (finalization); + else + start_protect (); +} + +extern tree auto_function PROTO((tree, tree, enum built_in_function)); + +/* sets up all the global eh stuff that needs to be initialized at the + start of compilation. + + This includes: + - Setting up all the function call trees + - Initializing the ehqueue + - Initializing the eh_table_output_queue + - Initializing the ehstack +*/ + +void +init_exception_processing () +{ + extern tree define_function (); + tree unexpected_fndecl, terminate_fndecl; + tree set_unexpected_fndecl, set_terminate_fndecl; + tree catch_match_fndecl; + tree find_first_exception_match_fndecl; + tree unwind_fndecl; + tree declspecs; + tree d; + + /* void (*)() */ + tree PFV = build_pointer_type (build_function_type + (void_type_node, void_list_node)); + + /* arg list for the build_function_type call for set_terminate () and + set_unexpected () */ + tree pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); + + /* void (*pfvtype (void (*) ()))() */ + tree pfvtype = build_function_type (PFV, pfvlist); + + /* void vtype () */ + tree vtype = build_function_type (void_type_node, void_list_node); + + set_terminate_fndecl = auto_function (get_identifier ("set_terminate"), + pfvtype, NOT_BUILT_IN); + set_unexpected_fndecl = auto_function (get_identifier ("set_unexpected"), + pfvtype, NOT_BUILT_IN); + unexpected_fndecl = auto_function (get_identifier ("unexpected"), + vtype, NOT_BUILT_IN); + terminate_fndecl = auto_function (get_identifier ("terminate"), + vtype, NOT_BUILT_IN); + + interim_eh_hook = lang_interim_eh; + + push_lang_context (lang_name_c); + + catch_match_fndecl = + define_function (flag_rtti + ? "__throw_type_match_rtti" + : "__throw_type_match", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + void_list_node)))), + NOT_BUILT_IN, + pushdecl, + 0); + find_first_exception_match_fndecl = + define_function ("__find_first_exception_table_match", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, ptr_type_node, + void_list_node)), + NOT_BUILT_IN, + pushdecl, + 0); + unwind_fndecl = + define_function ("__unwind_function", + build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, + void_list_node)), + NOT_BUILT_IN, + pushdecl, + 0); + throw_fndecl = + define_function ("__throw", + build_function_type (void_type_node, void_list_node), + NOT_BUILT_IN, + pushdecl, + 0); + DECL_EXTERNAL (throw_fndecl) = 0; + TREE_PUBLIC (throw_fndecl) = 0; + + Unexpected = default_conversion (unexpected_fndecl); + Terminate = default_conversion (terminate_fndecl); + SetTerminate = default_conversion (set_terminate_fndecl); + SetUnexpected = default_conversion (set_unexpected_fndecl); + CatchMatch = default_conversion (catch_match_fndecl); + FirstExceptionMatch = default_conversion (find_first_exception_match_fndecl); + Unwind = default_conversion (unwind_fndecl); + Throw = default_conversion (throw_fndecl); + BuiltinReturnAddress = default_conversion (builtin_return_address_fndecl); + + TerminateFunctionCall = build_function_call (Terminate, NULL_TREE); + + pop_lang_context (); + + new_eh_queue (&ehqueue); + new_eh_queue (&eh_table_output_queue); + new_eh_stack (&ehstack); + + declspecs = tree_cons (NULL_TREE, get_identifier ("void"), NULL_TREE); + d = build_parse_node (INDIRECT_REF, get_identifier ("__eh_pc")); + d = start_decl (d, declspecs, 0, NULL_TREE); + DECL_COMMON (d) = 1; + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + saved_pc = lookup_name (get_identifier ("__eh_pc"), 0); + + declspecs = tree_cons (NULL_TREE, get_identifier ("void"), NULL_TREE); + d = build_parse_node (INDIRECT_REF, get_identifier ("__eh_type")); + d = start_decl (d, declspecs, 0, NULL_TREE); + DECL_COMMON (d) = 1; + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + saved_throw_type = lookup_name (get_identifier ("__eh_type"), 0); + + declspecs = tree_cons (NULL_TREE, get_identifier ("void"), NULL_TREE); + d = build_parse_node (INDIRECT_REF, get_identifier ("__eh_value")); + d = start_decl (d, declspecs, 0, NULL_TREE); + DECL_COMMON (d) = 1; + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + saved_throw_value = lookup_name (get_identifier ("__eh_value"), 0); +} + +/* call this to begin a block of unwind protection (ie: when an object is + constructed) */ +void +start_protect () +{ + if (! doing_eh (0)) + return; + + emit_label (push_eh_entry (&ehstack)); +} + +/* call this to end a block of unwind protection. the finalization tree is + the finalization which needs to be run in order to cleanly unwind through + this level of protection. (ie: call this when a scope is exited)*/ +void +end_protect (finalization) + tree finalization; +{ + struct ehEntry *entry; + + if (! doing_eh (0)) + return; + + entry = pop_eh_entry (&ehstack); + + emit_label (entry->end_label); + /* Put in something that takes up space, as otherwise the end + address for the EH region could have the exact same address as + the outer region, causing us to miss the fact that resuming + exception handling with this PC value would be inside the outer + region. */ + emit_insn (gen_nop ()); + + entry->finalization = finalization; + + enqueue_eh_entry (&ehqueue, entry); +} + +/* call this on start of a try block. */ +void +expand_start_try_stmts () +{ + if (! doing_eh (1)) + return; + + start_protect (); +} + +void +expand_end_try_stmts () +{ + end_protect (integer_zero_node); +} + + +/* call this to start processing of all the catch blocks. */ +void +expand_start_all_catch () +{ + struct ehEntry *entry; + rtx label; + + if (! doing_eh (1)) + return; + + emit_line_note (input_filename, lineno); + label = gen_label_rtx (); + + /* The label for the exception handling block we will save. This is + Lresume, in the documention. */ + emit_label (label); + + /* Put in something that takes up space, as otherwise the end + address for the EH region could have the exact same address as + the outer region, causing us to miss the fact that resuming + exception handling with this PC value would be inside the outer + region. */ + emit_insn (gen_nop ()); + + push_label_entry (&caught_return_label_stack, label); + + /* Start a new sequence for all the catch blocks. We will add this + to the gloabl sequence catch_clauses, when we have completed all + the handlers in this handler-seq. */ + start_sequence (); + + while (1) + { + entry = dequeue_eh_entry (&ehqueue); + emit_label (entry->exception_handler_label); + + expand_expr (entry->finalization, const0_rtx, VOIDmode, 0); + + /* When we get down to the matching entry, stop. */ + if (entry->finalization == integer_zero_node) + break; + + /* The below can be optimized away, and we could just fall into the + next EH handler, if we are certain they are nested. */ + /* Code to throw out to outer context, if we fall off end of the + handler. */ + expand_internal_throw (gen_rtx (LABEL_REF, + Pmode, + entry->end_label)); + free (entry); + } +} + +/* call this to end processing of all the catch blocks. */ +void +expand_end_all_catch () +{ + rtx new_catch_clause; + + if (! doing_eh (1)) + return; + + /* Code to throw out to outer context, if we fall off end of catch + handlers. This is rethrow (Lresume, same id, same obj); in the + documentation. */ + expand_internal_throw (gen_rtx (LABEL_REF, + Pmode, + top_label_entry (&caught_return_label_stack))); + + /* Now we have the complete catch sequence. */ + new_catch_clause = get_insns (); + end_sequence (); + + /* this level of catch blocks is done, so set up the successful catch jump + label for the next layer of catch blocks. */ + pop_label_entry (&caught_return_label_stack); + + /* Add the new sequence of catchs to the main one for this + function. */ + push_to_sequence (catch_clauses); + emit_insns (new_catch_clause); + catch_clauses = get_insns (); + end_sequence (); + + /* Here we fall through into the continuation code. */ +} + +/* Build a type value for use at runtime for a type that is matched + against by the exception handling system. */ +static tree +build_eh_type_type (type) + tree type; +{ + char *typestring; + tree exp; + + if (type == error_mark_node) + return error_mark_node; + + /* peel back references, so they match. */ + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* Peel off cv qualifiers. */ + type = TYPE_MAIN_VARIANT (type); + + if (flag_rtti) + { + return build1 (ADDR_EXPR, ptr_type_node, get_typeid (type)); + } + + typestring = build_overload_name (type, 1, 1); + exp = combine_strings (build_string (strlen (typestring)+1, typestring)); + return build1 (ADDR_EXPR, ptr_type_node, exp); +} + +/* Build a type value for use at runtime for a exp that is thrown or + matched against by the exception handling system. */ +static tree +build_eh_type (exp) + tree exp; +{ + if (flag_rtti) + { + exp = build_typeid (exp); + return build1 (ADDR_EXPR, ptr_type_node, exp); + } + return build_eh_type_type (TREE_TYPE (exp)); +} + +/* call this to start a catch block. Typename is the typename, and identifier + is the variable to place the object in or NULL if the variable doesn't + matter. If typename is NULL, that means its a "catch (...)" or catch + everything. In that case we don't need to do any type checking. + (ie: it ends up as the "else" clause rather than an "else if" clause) */ +void +expand_start_catch_block (declspecs, declarator) + tree declspecs, declarator; +{ + rtx false_label_rtx; + rtx protect_label_rtx; + tree decl = NULL_TREE; + tree init; + + if (! doing_eh (1)) + return; + + /* Create a binding level for the parm. */ + expand_start_bindings (0); + + false_label_rtx = gen_label_rtx (); + /* This is saved for the exception table. */ + push_rtl_perm (); + protect_label_rtx = gen_label_rtx (); + pop_rtl_from_perm (); + push_label_entry (&false_label_stack, false_label_rtx); + push_label_entry (&false_label_stack, protect_label_rtx); + + if (declspecs) + { + tree exp; + rtx call_rtx, return_value_rtx; + tree init_type; + + decl = grokdeclarator (declarator, declspecs, CATCHPARM, 1, + NULL_TREE, NULL_TREE); + + if (decl == NULL_TREE) + { + error ("invalid catch parameter"); + return; + } + + /* Figure out the type that the initializer is. */ + init_type = TREE_TYPE (decl); + if (TREE_CODE (init_type) != REFERENCE_TYPE + && TREE_CODE (init_type) != POINTER_TYPE) + init_type = build_reference_type (init_type); + + exp = saved_throw_value; + exp = tree_cons (NULL_TREE, + build_eh_type_type (TREE_TYPE (decl)), + tree_cons (NULL_TREE, + saved_throw_type, + tree_cons (NULL_TREE, exp, NULL_TREE))); + exp = build_function_call (CatchMatch, exp); + call_rtx = expand_call (exp, NULL_RTX, 0); + assemble_external (TREE_OPERAND (CatchMatch, 0)); + + return_value_rtx = hard_function_value (ptr_type_node, exp); + + /* did the throw type match function return TRUE? */ + emit_cmp_insn (return_value_rtx, const0_rtx, EQ, NULL_RTX, + GET_MODE (return_value_rtx), 0, 0); + + /* if it returned FALSE, jump over the catch block, else fall into it */ + emit_jump_insn (gen_beq (false_label_rtx)); + + init = convert_from_reference (save_expr (make_tree (init_type, call_rtx))); + + /* Do we need the below two lines? */ + /* Let `cp_finish_decl' know that this initializer is ok. */ + DECL_INITIAL (decl) = init; + decl = pushdecl (decl); + cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + } + else + { + /* Fall into the catch all section. */ + } + + /* This is the starting of something to protect. */ + emit_label (protect_label_rtx); + + emit_line_note (input_filename, lineno); +} + + +/* this is called from expand_exception_blocks and + expand_end_catch_block to expand the toplevel finalizations for a + function. We return the first label emitted, if any, otherwise + return NULL_RTX. */ +static rtx +expand_leftover_cleanups () +{ + struct ehEntry *entry; + rtx first_label = NULL_RTX; + + while ((entry = dequeue_eh_entry (&ehqueue)) != 0) + { + if (! first_label) + first_label = entry->exception_handler_label; + emit_label (entry->exception_handler_label); + + expand_expr (entry->finalization, const0_rtx, VOIDmode, 0); + + /* The below can be optimized away, and we could just fall into the + next EH handler, if we are certain they are nested. */ + /* Code to throw out to outer context, if we fall off end of the + handler. */ + expand_internal_throw (gen_rtx (LABEL_REF, + Pmode, + entry->end_label)); + + /* leftover try block, opps. */ + if (entry->finalization == integer_zero_node) + abort (); + + free (entry); + } + + return first_label; +} + +/* Call this to end a catch block. Its responsible for emitting the + code to handle jumping back to the correct place, and for emitting + the label to jump to if this catch block didn't match. */ +void expand_end_catch_block () +{ + rtx start_protect_label_rtx; + rtx end_protect_label_rtx; + tree decls; + struct ehEntry entry; + + if (! doing_eh (1)) + return; + + /* fall to outside the try statement when done executing handler and + we fall off end of handler. This is jump Lresume in the + documentation. */ + emit_jump (top_label_entry (&caught_return_label_stack)); + + /* We end the rethrow protection region as soon as we hit a label. */ + end_protect_label_rtx = expand_leftover_cleanups (); + + /* Code to throw out to outer context, if we get a throw from within + our catch handler. */ + /* These are saved for the exception table. */ + push_rtl_perm (); + entry.exception_handler_label = gen_label_rtx (); + pop_rtl_from_perm (); + /* This label is Lhandler in the documentation. */ + emit_label (entry.exception_handler_label); + expand_internal_throw (gen_rtx (LABEL_REF, + Pmode, + top_label_entry (&caught_return_label_stack))); + + /* No associated finalization. */ + entry.finalization = NULL_TREE; + entry.context = current_function_decl; + + if (end_protect_label_rtx == NULL_RTX) + end_protect_label_rtx = entry.exception_handler_label; + + /* Because we are emitted out of line, we have to protect this. */ + /* label for the start of the protection region. */ + start_protect_label_rtx = pop_label_entry (&false_label_stack); + + /* Cleanup the EH parameter. */ + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + + /* label we emit to jump to if this catch block didn't match. */ + /* This the closing } in the `if (eq) {' of the documentation. */ + emit_label (pop_label_entry (&false_label_stack)); + + /* Because we are reordered out of line, we have to protect this. */ + entry.start_label = start_protect_label_rtx; + entry.end_label = end_protect_label_rtx; + + LABEL_PRESERVE_P (entry.start_label) = 1; + LABEL_PRESERVE_P (entry.end_label) = 1; + LABEL_PRESERVE_P (entry.exception_handler_label) = 1; + + /* These set up a call to throw the caught exception into the outer + context. */ + enqueue_eh_entry (&eh_table_output_queue, copy_eh_entry (&entry)); +} + +/* unwind the stack. */ +static void +do_unwind (inner_throw_label) + rtx inner_throw_label; +{ +#if defined(SPARC_STACK_ALIGN) /* was sparc */ + tree fcall; + tree params; + rtx return_val_rtx; + rtx temp; + + /* call to __builtin_return_address () */ + params = tree_cons (NULL_TREE, integer_zero_node, NULL_TREE); + fcall = build_function_call (BuiltinReturnAddress, params); + return_val_rtx = expand_expr (fcall, NULL_RTX, Pmode, 0); + /* In the return, the new pc is pc+8, as the value coming in is + really the address of the call insn, not the next insn. */ + temp = gen_reg_rtx (Pmode); + emit_move_insn (temp, inner_throw_label); + emit_move_insn (return_val_rtx, plus_constant (temp, -8)); + easy_expand_asm ("ret"); + easy_expand_asm ("restore"); + emit_barrier (); +#endif +#if defined(ARM_FRAME_RTX) /* was __arm */ + if (flag_omit_frame_pointer) + sorry ("this implementation of exception handling requires a frame pointer"); + + emit_move_insn (stack_pointer_rtx, + gen_rtx (MEM, Pmode, plus_constant (hard_frame_pointer_rtx, -8))); + emit_move_insn (hard_frame_pointer_rtx, + gen_rtx (MEM, Pmode, plus_constant (hard_frame_pointer_rtx, -12))); +#endif +#if defined(TARGET_88000) /* was m88k */ + rtx temp_frame = frame_pointer_rtx; + + temp_frame = memory_address (Pmode, temp_frame); + temp_frame = copy_to_reg (gen_rtx (MEM, Pmode, temp_frame)); + + /* hopefully this will successfully pop the frame! */ + emit_move_insn (frame_pointer_rtx, temp_frame); + emit_move_insn (stack_pointer_rtx, frame_pointer_rtx); + emit_move_insn (arg_pointer_rtx, frame_pointer_rtx); + emit_insn (gen_add2_insn (stack_pointer_rtx, gen_rtx (CONST_INT, VOIDmode, + (HOST_WIDE_INT)m88k_debugger_offset (stack_pointer_rtx, 0)))); + +#if 0 + emit_insn (gen_add2_insn (arg_pointer_rtx, gen_rtx (CONST_INT, VOIDmode, + -(HOST_WIDE_INT)m88k_debugger_offset (arg_pointer_rtx, 0)))); + + emit_move_insn (stack_pointer_rtx, arg_pointer_rtx); + + emit_insn (gen_add2_insn (stack_pointer_rtx, gen_rtx (CONST_INT, VOIDmode, + (HOST_WIDE_INT)m88k_debugger_offset (arg_pointer_rtx, 0)))); +#endif +#endif +#if !defined(TARGET_88000) && !defined(ARM_FRAME_RTX) && !defined(SPARC_STACK_ALIGN) + tree fcall; + tree params; + rtx return_val_rtx; + + /* call to __builtin_return_address () */ + params = tree_cons (NULL_TREE, integer_zero_node, NULL_TREE); + fcall = build_function_call (BuiltinReturnAddress, params); + return_val_rtx = expand_expr (fcall, NULL_RTX, Pmode, 0); +#if 0 + /* I would like to do this here, but doesn't seem to work. */ + emit_move_insn (return_val_rtx, inner_throw_label); + /* So, for now, just pass throw label to stack unwinder. */ +#endif + params = tree_cons (NULL_TREE, make_tree (ptr_type_node, + inner_throw_label), NULL_TREE); + + do_function_call (Unwind, params, NULL_TREE); + assemble_external (TREE_OPERAND (Unwind, 0)); + emit_barrier (); +#endif +} + + +/* is called from expand_exception_blocks () to generate the code in a function + to "throw" if anything in the function needs to perform a throw. + + expands "throw" as the following pseudo code: + + throw: + eh = find_first_exception_match (saved_pc); + if (!eh) goto gotta_rethrow_it; + goto eh; + + gotta_rethrow_it: + saved_pc = __builtin_return_address (0); + pop_to_previous_level (); + goto throw; + + */ +void +expand_builtin_throw () +{ + tree fcall; + tree params; + rtx return_val_rtx; + rtx gotta_rethrow_it; + rtx gotta_call_terminate; + rtx unwind_and_throw; + rtx goto_unwind_and_throw; + rtx top_of_loop; + rtx unwind_first; + tree t; + + if (! doing_eh (0)) + return; + + if (! throw_used) + return; + + params = void_list_node; + t = build_parse_node (CALL_EXPR, get_identifier ("__throw"), params, NULL_TREE); + start_function (decl_tree_cons (NULL_TREE, get_identifier ("static"), + void_list_node), + t, NULL_TREE, NULL_TREE, 0); + store_parm_decls (); + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); + + gotta_rethrow_it = gen_label_rtx (); + gotta_call_terminate = gen_label_rtx (); + unwind_and_throw = gen_label_rtx (); + goto_unwind_and_throw = gen_label_rtx (); + top_of_loop = gen_label_rtx (); + unwind_first = gen_label_rtx (); + + emit_jump (unwind_first); + + emit_label (top_of_loop); + + /* search for an exception handler for the saved_pc */ + return_val_rtx = do_function_call (FirstExceptionMatch, + tree_cons (NULL_TREE, saved_pc, NULL_TREE), + ptr_type_node); + assemble_external (TREE_OPERAND (FirstExceptionMatch, 0)); + + /* did we find one? */ + emit_cmp_insn (return_val_rtx, const0_rtx, EQ, NULL_RTX, + GET_MODE (return_val_rtx), 0, 0); + + /* if not, jump to gotta_rethrow_it */ + emit_jump_insn (gen_beq (gotta_rethrow_it)); + + /* we found it, so jump to it */ + emit_indirect_jump (return_val_rtx); + + /* code to deal with unwinding and looking for it again */ + emit_label (gotta_rethrow_it); + + /* call to __builtin_return_address () */ +#if defined(ARM_FRAME_RTX) /* was __arm */ +/* This replaces a 'call' to __builtin_return_address */ + return_val_rtx = gen_reg_rtx (Pmode); + emit_move_insn (return_val_rtx, gen_rtx (MEM, Pmode, plus_constant (hard_frame_pointer_rtx, -4))); +#else + params = tree_cons (NULL_TREE, integer_zero_node, NULL_TREE); + fcall = build_function_call (BuiltinReturnAddress, params); + return_val_rtx = expand_expr (fcall, NULL_RTX, Pmode, 0); +#endif + + /* did __builtin_return_address () return a valid address? */ + emit_cmp_insn (return_val_rtx, const0_rtx, EQ, NULL_RTX, + GET_MODE (return_val_rtx), 0, 0); + + emit_jump_insn (gen_beq (gotta_call_terminate)); + +#if defined(ARM_FRAME_RTX) /* was __arm */ + /* On the ARM, '__builtin_return_address', must have 4 + subtracted from it. */ + emit_insn (gen_add2_insn (return_val_rtx, GEN_INT (-4))); + + /* If we are generating code for an ARM2/ARM3 machine or for an ARM6 in 26 bit + mode, the condition codes must be masked out of the return value, or else + they will confuse BuiltinReturnAddress. This does not apply to ARM6 and + later processors when running in 32 bit mode. */ + if (!TARGET_6) + emit_insn (gen_rtx (SET, Pmode, return_val_rtx, gen_rtx (AND, Pmode, return_val_rtx, GEN_INT (0x03fffffc)))); +#else +#if !defined(SPARC_STACK_ALIGN) /* was sparc */ + /* On the SPARC, __builtin_return_address is already -8, no need to + subtract any more from it. */ + return_val_rtx = plus_constant (return_val_rtx, -1); +#endif +#endif + + /* yes it did */ + t = build_modify_expr (saved_pc, NOP_EXPR, make_tree (ptr_type_node, return_val_rtx)); + expand_expr (t, const0_rtx, VOIDmode, 0); + + do_unwind (gen_rtx (LABEL_REF, Pmode, top_of_loop)); + emit_jump (top_of_loop); + + /* no it didn't --> therefore we need to call terminate */ + emit_label (gotta_call_terminate); + do_function_call (Terminate, NULL_TREE, NULL_TREE); + assemble_external (TREE_OPERAND (Terminate, 0)); + + { + rtx ret_val, return_val_rtx; + emit_label (unwind_first); + ret_val = expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, + 0, hard_frame_pointer_rtx); + + /* Set it up so that we continue inside, at the top of the loop. */ + emit_move_insn (ret_val, gen_rtx (LABEL_REF, Pmode, top_of_loop)); +#ifdef NORMAL_RETURN_ADDR_OFFSET + return_val_rtx = plus_constant (ret_val, -NORMAL_RETURN_ADDR_OFFSET); + if (return_val_rtx != ret_val) + emit_move_insn (ret_val, return_val_rtx); +#endif + + /* Fall into epilogue to unwind prologue. */ + } + + expand_end_bindings (getdecls(), 1, 0); + poplevel (1, 0, 0); + pop_momentary (); + + finish_function (lineno, 0, 0); +} + + +void +expand_start_eh_spec () +{ + start_protect (); +} + +void +expand_end_eh_spec (raises) + tree raises; +{ + tree expr, second_try; + rtx check = gen_label_rtx (); + rtx cont; + rtx ret = gen_reg_rtx (Pmode); + rtx flag = gen_reg_rtx (TYPE_MODE (integer_type_node)); + rtx end = gen_label_rtx (); + + expr = make_node (RTL_EXPR); + TREE_TYPE (expr) = void_type_node; + RTL_EXPR_RTL (expr) = const0_rtx; + TREE_SIDE_EFFECTS (expr) = 1; + start_sequence_for_rtl_expr (expr); + cont = gen_label_rtx (); + emit_move_insn (ret, gen_rtx (LABEL_REF, Pmode, cont)); + emit_jump (check); + emit_label (cont); + jumpif (make_tree (integer_type_node, flag), end); + do_function_call (Terminate, NULL_TREE, NULL_TREE); + assemble_external (TREE_OPERAND (Terminate, 0)); + emit_barrier (); + RTL_EXPR_SEQUENCE (expr) = get_insns (); + end_sequence (); + + second_try = expr; + + expr = make_node (RTL_EXPR); + TREE_TYPE (expr) = void_type_node; + RTL_EXPR_RTL (expr) = const0_rtx; + TREE_SIDE_EFFECTS (expr) = 1; + start_sequence_for_rtl_expr (expr); + + cont = gen_label_rtx (); + emit_move_insn (ret, gen_rtx (LABEL_REF, Pmode, cont)); + emit_jump (check); + emit_label (cont); + jumpif (make_tree (integer_type_node, flag), end); + start_protect (); + do_function_call (Unexpected, NULL_TREE, NULL_TREE); + assemble_external (TREE_OPERAND (Unexpected, 0)); + emit_barrier (); + end_protect (second_try); + + emit_label (check); + emit_move_insn (flag, const1_rtx); + cont = gen_label_rtx (); + while (raises) + { + tree exp; + tree match_type = TREE_VALUE (raises); + + if (match_type) + { + /* check TREE_VALUE (raises) here */ + exp = saved_throw_value; + exp = tree_cons (NULL_TREE, + build_eh_type_type (match_type), + tree_cons (NULL_TREE, + saved_throw_type, + tree_cons (NULL_TREE, exp, NULL_TREE))); + exp = build_function_call (CatchMatch, exp); + assemble_external (TREE_OPERAND (CatchMatch, 0)); + + jumpif (exp, cont); + } + + raises = TREE_CHAIN (raises); + } + emit_move_insn (flag, const0_rtx); + emit_label (cont); + emit_indirect_jump (ret); + emit_label (end); + + RTL_EXPR_SEQUENCE (expr) = get_insns (); + end_sequence (); + + end_protect (expr); +} + +/* This is called to expand all the toplevel exception handling + finalization for a function. It should only be called once per + function. */ +void +expand_exception_blocks () +{ + static rtx funcend; + rtx insns; + + start_sequence (); + + funcend = gen_label_rtx (); + emit_jump (funcend); + /* expand_null_return (); */ + + start_sequence (); + + /* Add all the catch clauses here. */ + emit_insns (catch_clauses); + catch_clauses = NULL_RTX; + + expand_leftover_cleanups (); + + insns = get_insns (); + end_sequence (); + + /* Do this after we expand leftover cleanups, so that the end_protect + that expand_end_eh_spec does will match the right start_protect, + and make sure it comes out before the terminate protected region. */ + if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) + { + expand_end_eh_spec (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))); + push_to_sequence (insns); + + /* Now expand any new ones. */ + expand_leftover_cleanups (); + + insns = get_insns (); + end_sequence (); + } + + if (insns) + { + struct ehEntry entry; + + /* These are saved for the exception table. */ + push_rtl_perm (); + entry.start_label = gen_label_rtx (); + entry.end_label = gen_label_rtx (); + entry.exception_handler_label = gen_label_rtx (); + entry.finalization = TerminateFunctionCall; + entry.context = current_function_decl; + assemble_external (TREE_OPERAND (Terminate, 0)); + pop_rtl_from_perm (); + + LABEL_PRESERVE_P (entry.start_label) = 1; + LABEL_PRESERVE_P (entry.end_label) = 1; + LABEL_PRESERVE_P (entry.exception_handler_label) = 1; + + emit_label (entry.start_label); + emit_insns (insns); + + enqueue_eh_entry (&eh_table_output_queue, copy_eh_entry (&entry)); + + emit_label (entry.exception_handler_label); + expand_expr (entry.finalization, const0_rtx, VOIDmode, 0); + emit_label (entry.end_label); + emit_barrier (); + } + + { + /* Mark the end of the stack unwinder. */ + rtx unwind_insns; + start_sequence (); + end_eh_unwinder (funcend); + expand_leftover_cleanups (); + unwind_insns = get_insns (); + end_sequence (); + if (unwind_insns) + { + insns = unwind_insns; + emit_insns (insns); + } + } + + emit_label (funcend); + + /* Only if we had previous insns do we want to emit the jump around + them. If there weren't any, then insns will remain NULL_RTX. */ + if (insns) + insns = get_insns (); + end_sequence (); + + emit_insns (insns); +} + + +/* call this to expand a throw statement. This follows the following + algorithm: + + 1. Allocate space to save the current PC onto the stack. + 2. Generate and emit a label and save its address into the + newly allocated stack space since we can't save the pc directly. + 3. If this is the first call to throw in this function: + generate a label for the throw block + 4. jump to the throw block label. */ +void +expand_throw (exp) + tree exp; +{ + rtx label; + + if (! doing_eh (1)) + return; + + /* This is the label that represents where in the code we were, when + we got an exception. This needs to be updated when we rethrow an + exception, so that the matching routine knows to search out. */ + label = gen_label_rtx (); + emit_label (label); + + if (exp) + { + tree throw_type; + tree e; + + /* throw expression */ + /* First, decay it. */ + exp = decay_conversion (exp); + + if (TREE_CODE (TREE_TYPE (exp)) == POINTER_TYPE) + { + throw_type = build_eh_type (exp); + exp = build_reinterpret_cast (ptr_type_node, exp); + } + else + { + /* Make a copy of the thrown object. WP 15.1.5 */ + exp = build_new (NULL_TREE, TREE_TYPE (exp), + build_tree_list (NULL_TREE, exp), + 0); + + if (exp == error_mark_node) + error (" in thrown expression"); + + throw_type = build_eh_type (build_indirect_ref (exp, NULL_PTR)); + } + + e = build_modify_expr (saved_throw_type, NOP_EXPR, throw_type); + expand_expr (e, const0_rtx, VOIDmode, 0); + e = build_modify_expr (saved_throw_value, NOP_EXPR, exp); + e = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (e), e); + expand_expr (e, const0_rtx, VOIDmode, 0); + } + else + { + /* rethrow current exception */ + /* This part is easy, as we don't have to do anything else. */ + } + + expand_internal_throw (gen_rtx (LABEL_REF, Pmode, label)); +} + +void +end_protect_partials () { + while (protect_list) + { + end_protect (TREE_VALUE (protect_list)); + protect_list = TREE_CHAIN (protect_list); + } +} + +int +might_have_exceptions_p () +{ + if (eh_table_output_queue.head) + return 1; + return 0; +} + +/* Output the exception table. + Return the number of handlers. */ +void +emit_exception_table () +{ + int count = 0; + extern FILE *asm_out_file; + struct ehEntry *entry; + tree eh_node_decl; + + if (! doing_eh (0)) + return; + + exception_section (); + + /* Beginning marker for table. */ + assemble_align (GET_MODE_ALIGNMENT (Pmode)); + assemble_label ("__EXCEPTION_TABLE__"); + output_exception_table_entry (asm_out_file, + const0_rtx, const0_rtx, const0_rtx); + + while (entry = dequeue_eh_entry (&eh_table_output_queue)) + { + tree context = entry->context; + + if (context && ! TREE_ASM_WRITTEN (context)) + continue; + + count++; + output_exception_table_entry (asm_out_file, + entry->start_label, entry->end_label, + entry->exception_handler_label); + } + + /* Ending marker for table. */ + assemble_label ("__EXCEPTION_END__"); + output_exception_table_entry (asm_out_file, + constm1_rtx, constm1_rtx, constm1_rtx); +} + +void +register_exception_table () +{ + emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__register_exceptions"), 0, + VOIDmode, 1, + gen_rtx (SYMBOL_REF, Pmode, "__EXCEPTION_TABLE__"), + Pmode); +} + +/* Build a throw expression. */ +tree +build_throw (e) + tree e; +{ + if (e != error_mark_node) + { + e = build1 (THROW_EXPR, void_type_node, e); + TREE_SIDE_EFFECTS (e) = 1; + TREE_USED (e) = 1; + } + return e; +} + +start_eh_unwinder () +{ + start_protect (); +} + +end_eh_unwinder (end) + rtx end; +{ + tree expr; + rtx return_val_rtx, ret_val, label; + + if (! doing_eh (0)) + return; + + expr = make_node (RTL_EXPR); + TREE_TYPE (expr) = void_type_node; + RTL_EXPR_RTL (expr) = const0_rtx; + TREE_SIDE_EFFECTS (expr) = 1; + start_sequence_for_rtl_expr (expr); + + ret_val = expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, + 0, hard_frame_pointer_rtx); + return_val_rtx = copy_to_reg (ret_val); +#ifdef NORMAL_RETURN_ADDR_OFFSET + return_val_rtx = plus_constant (return_val_rtx, NORMAL_RETURN_ADDR_OFFSET-1); +#else + return_val_rtx = plus_constant (return_val_rtx, -1); +#endif + emit_move_insn (DECL_RTL (saved_pc), return_val_rtx); + +#ifdef JUMP_TO_THROW + emit_move_insn (ret_val, gen_rtx (SYMBOL_REF, Pmode, "__throw")); +#else + label = gen_label_rtx (); + emit_move_insn (ret_val, gen_rtx (LABEL_REF, Pmode, label)); +#endif + +#ifdef NORMAL_RETURN_ADDR_OFFSET + return_val_rtx = plus_constant (ret_val, -NORMAL_RETURN_ADDR_OFFSET); + if (return_val_rtx != ret_val) + emit_move_insn (ret_val, return_val_rtx); +#endif + + emit_jump (end); + +#ifndef JUMP_TO_THROW + emit_label (label); + do_function_call (Throw, NULL_TREE, NULL_TREE); +#endif + + RTL_EXPR_SEQUENCE (expr) = get_insns (); + end_sequence (); + end_protect (expr); +} diff --git a/contrib/gcc/cp/expr.c b/contrib/gcc/cp/expr.c new file mode 100644 index 00000000000..99a611e6971 --- /dev/null +++ b/contrib/gcc/cp/expr.c @@ -0,0 +1,372 @@ +/* Convert language-specific tree expression to rtl instructions, + for GNU compiler. + Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "rtl.h" +#include "tree.h" +#include "flags.h" +#include "expr.h" +#include "cp-tree.h" + +#undef NULL +#define NULL 0 + +/* Hook used by expand_expr to expand language-specific tree codes. */ + +rtx +cplus_expand_expr (exp, target, tmode, modifier) + tree exp; + rtx target; + enum machine_mode tmode; + enum expand_modifier modifier; +{ + tree type = TREE_TYPE (exp); + register enum machine_mode mode = TYPE_MODE (type); + register enum tree_code code = TREE_CODE (exp); + rtx original_target = target; + int ignore = target == const0_rtx; + + if (ignore) + target = 0, original_target = 0; + + /* No sense saving up arithmetic to be done + if it's all in the wrong mode to form part of an address. + And force_operand won't know whether to sign-extend or zero-extend. */ + + if (mode != Pmode && modifier == EXPAND_SUM) + modifier = EXPAND_NORMAL; + + switch (code) + { + case NEW_EXPR: + { + /* Something needs to be initialized, but we didn't know + where that thing was when building the tree. For example, + it could be the return value of a function, or a parameter + to a function which lays down in the stack, or a temporary + variable which must be passed by reference. + + Cleanups are handled in a language-specific way: they + might be run by the called function (true in GNU C++ + for parameters with cleanups), or they might be + run by the caller, after the call (true in GNU C++ + for other cleanup needs). */ + + tree func = TREE_OPERAND (exp, 0); + tree args = TREE_OPERAND (exp, 1); + tree type = TREE_TYPE (exp), slot; + tree fn_type = TREE_TYPE (TREE_TYPE (func)); + tree return_type = TREE_TYPE (fn_type); + tree call_exp; + rtx call_target, return_target; + int pcc_struct_return = 0; + + /* The expression `init' wants to initialize what + `target' represents. SLOT holds the slot for TARGET. */ + slot = TREE_OPERAND (exp, 2); + + if (target == 0) + { + /* Should always be called with a target in BLKmode case. */ + my_friendly_assert (mode != BLKmode, 205); + my_friendly_assert (DECL_RTL (slot) != 0, 206); + + target = gen_reg_rtx (mode); + } + + /* The target the initializer will initialize (CALL_TARGET) + must now be directed to initialize the target we are + supposed to initialize (TARGET). The semantics for + choosing what CALL_TARGET is is language-specific, + as is building the call which will perform the + initialization. It is left here to show the choices that + exist for C++. */ + + if (TREE_CODE (func) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (func, 0)) == FUNCTION_DECL + && DECL_CONSTRUCTOR_P (TREE_OPERAND (func, 0))) + { + type = build_pointer_type (type); + /* Don't clobber a value that might be part of a default + parameter value. */ + mark_addressable (slot); + if (TREE_PERMANENT (args)) + args = tree_cons (0, build1 (ADDR_EXPR, type, slot), + TREE_CHAIN (args)); + else + TREE_VALUE (args) = build1 (ADDR_EXPR, type, slot); + call_target = 0; + } + else if (TREE_CODE (return_type) == REFERENCE_TYPE) + { + type = return_type; + call_target = 0; + } + else + { +#ifdef PCC_STATIC_STRUCT_RETURN + pcc_struct_return = 1; + call_target = 0; +#else + call_target = target; +#endif + } + if (call_target) + { + /* Make this a valid memory address now. The code below assumes + that it can compare rtx and make assumptions based on the + result. The assumptions are true only if the address was + valid to begin with. */ + call_target = validize_mem (call_target); + } + + call_exp = build (CALL_EXPR, type, func, args, 0); + TREE_SIDE_EFFECTS (call_exp) = 1; + return_target = expand_call (call_exp, call_target, ignore); + if (call_target == 0) + { + if (pcc_struct_return) + { + extern int flag_access_control; + int old_ac = flag_access_control; + + tree init = build_decl (VAR_DECL, 0, type); + TREE_ADDRESSABLE (init) = 1; + DECL_RTL (init) = return_target; + + flag_access_control = 0; + expand_aggr_init (slot, init, 0, LOOKUP_ONLYCONVERTING); + flag_access_control = old_ac; + + if (TYPE_NEEDS_DESTRUCTOR (type)) + { + init = build_decl (VAR_DECL, 0, + build_reference_type (type)); + DECL_RTL (init) = XEXP (return_target, 0); + + init = maybe_build_cleanup (convert_from_reference (init)); + if (init != NULL_TREE) + expand_expr (init, 0, 0, 0); + } + call_target = return_target = DECL_RTL (slot); + } + else + call_target = return_target; + } + + if (call_target != return_target) + { + my_friendly_assert (TYPE_HAS_TRIVIAL_INIT_REF (type), 317); + if (GET_MODE (return_target) == BLKmode) + emit_block_move (call_target, return_target, expr_size (exp), + TYPE_ALIGN (type) / BITS_PER_UNIT); + else + emit_move_insn (call_target, return_target); + } + + if (TREE_CODE (return_type) == REFERENCE_TYPE) + { + tree init; + + if (GET_CODE (call_target) == REG + && REGNO (call_target) < FIRST_PSEUDO_REGISTER) + my_friendly_abort (39); + + type = TREE_TYPE (exp); + + init = build (RTL_EXPR, return_type, 0, call_target); + /* We got back a reference to the type we want. Now initialize + target with that. */ + expand_aggr_init (slot, init, 0, LOOKUP_ONLYCONVERTING); + } + + if (DECL_RTL (slot) != target) + emit_move_insn (DECL_RTL (slot), target); + return DECL_RTL (slot); + } + + case OFFSET_REF: + { +#if 1 + return expand_expr (default_conversion (resolve_offset_ref (exp)), + target, tmode, EXPAND_NORMAL); +#else + /* This is old crusty code, and does not handle all that the + resolve_offset_ref function does. (mrs) */ + tree base = build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 0), 0); + tree offset = build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0); + return expand_expr (build (PLUS_EXPR, TREE_TYPE (exp), base, offset), + target, tmode, EXPAND_NORMAL); +#endif + } + + case THUNK_DECL: + return DECL_RTL (exp); + + case THROW_EXPR: + expand_throw (TREE_OPERAND (exp, 0)); + return NULL; + + case UNSAVE_EXPR: + { + rtx temp; + temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier); + TREE_OPERAND (exp, 0) = unsave_expr_now (TREE_OPERAND (exp, 0)); + return temp; + } + + default: + break; + } + my_friendly_abort (40); + /* NOTREACHED */ + return NULL; +} + +void +init_cplus_expand () +{ + lang_expand_expr = cplus_expand_expr; +} + +/* If DECL had its rtl moved from where callers expect it + to be, fix it up. RESULT is the nominal rtl for the RESULT_DECL, + which may be a pseudo instead of a hard register. */ + +void +fixup_result_decl (decl, result) + tree decl; + rtx result; +{ + if (REG_P (result)) + { + if (REGNO (result) >= FIRST_PSEUDO_REGISTER) + { + rtx real_decl_result; + +#ifdef FUNCTION_OUTGOING_VALUE + real_decl_result + = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl), current_function_decl); +#else + real_decl_result + = FUNCTION_VALUE (TREE_TYPE (decl), current_function_decl); +#endif + REG_FUNCTION_VALUE_P (real_decl_result) = 1; + result = real_decl_result; + } + store_expr (decl, result, 0); + emit_insn (gen_rtx (USE, VOIDmode, result)); + } +} + +/* Return nonzero iff DECL is memory-based. The DECL_RTL of + certain const variables might be a CONST_INT, or a REG + in some cases. We cannot use `memory_operand' as a test + here because on most RISC machines, a variable's address + is not, by itself, a legitimate address. */ + +int +decl_in_memory_p (decl) + tree decl; +{ + return DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == MEM; +} + +/* Expand this initialization inline and see if it's simple enough that + it can be done at compile-time. */ + +static tree +extract_aggr_init (decl, init) + tree decl, init; +{ + return 0; +} + +static tree +extract_scalar_init (decl, init) + tree decl, init; +{ + rtx value, insns, insn; + extern struct obstack temporary_obstack; + tree t = NULL_TREE; + + push_obstacks (&temporary_obstack, &temporary_obstack); + start_sequence (); + value = expand_expr (init, NULL_RTX, VOIDmode, 0); + insns = get_insns (); + end_sequence (); + reg_scan (insns, max_reg_num (), 0); + jump_optimize (insns, 0, 0, 1); + pop_obstacks (); + + for (insn = insns; insn; insn = NEXT_INSN (insn)) + { + rtx r, to; + + if (GET_CODE (insn) == NOTE) + continue; + else if (GET_CODE (insn) != INSN) + return 0; + + r = PATTERN (insn); + if (GET_CODE (r) != SET) + return 0; + + to = XEXP (r, 0); + + if (! (to == value || + (GET_CODE (to) == SUBREG && XEXP (to, 0) == value))) + return 0; + + r = XEXP (r, 1); + + switch (GET_CODE (r)) + { + case CONST_INT: + t = build_int_2 (XEXP (r, 0), 0); + break; + default: + return 0; + } + } + + return t; +} + +int +extract_init (decl, init) + tree decl, init; +{ + return 0; + + if (IS_AGGR_TYPE (TREE_TYPE (decl)) + || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) + init = extract_aggr_init (decl, init); + else + init = extract_scalar_init (decl, init); + + if (init == NULL_TREE) + return 0; + + DECL_INITIAL (decl) = init; + return 1; +} diff --git a/contrib/gcc/cp/g++.1 b/contrib/gcc/cp/g++.1 new file mode 100644 index 00000000000..ae016fad082 --- /dev/null +++ b/contrib/gcc/cp/g++.1 @@ -0,0 +1,674 @@ +.\" Copyright (c) 1991, 1992 Free Software Foundation -*-Text-*- +.\" See section COPYING for conditions for redistribution +.\" FIXME: no info here on predefines. Should there be? extra for C++... +.TH G++ 1 "30apr1993" "GNU Tools" "GNU Tools" +.de BP +.sp +.ti \-.2i +\(** +.. +.SH NAME +g++ \- GNU project C++ Compiler +.SH SYNOPSIS +.RB g++ " [" \c +.IR option " | " filename " ].\|.\|. +.SH DESCRIPTION +The C and C++ compilers are integrated; +.B g++ +is a script to call +.B gcc with options to recognize C++. +.B gcc +processes input files +through one or more of four stages: preprocessing, compilation, +assembly, and linking. This man page contains full descriptions for +.I only +C++ specific aspects of the compiler, though it also contains +summaries of some general-purpose options. For a fuller explanation +of the compiler, see +.BR gcc ( 1 ). + +C++ source files use one of the suffixes `\|\c +.B .C\c +\&\|', `\|\c +.B .cc\c +\&\|', `\|\c +.B .cxx\c +\&\|', `\|\c +.B .cpp\c +\&\|', or `\|\c +.B .c++\c +\&\|'; preprocessed C++ files use the suffix `\|\c +.B .ii\c +\&\|'. +.SH OPTIONS +There are many command-line options, including options to control +details of optimization, warnings, and code generation, which are +common to both +.B gcc +and +.B g++\c +\&. For full information on all options, see +.BR gcc ( 1 ). + +Options must be separate: `\|\c +.B \-dr\c +\&\|' is quite different from `\|\c +.B \-d \-r +\&\|'. + +Most `\|\c +.B \-f\c +\&\|' and `\|\c +.B \-W\c +\&\|' options have two contrary forms: +.BI \-f name +and +.BI \-fno\- name\c +\& (or +.BI \-W name +and +.BI \-Wno\- name\c +\&). Only the non-default forms are shown here. + +.TP +.B \-c +Compile or assemble the source files, but do not link. The compiler +output is an object file corresponding to each source file. +.TP +.BI \-D macro +Define macro \c +.I macro\c +\& with the string `\|\c +.B 1\c +\&\|' as its definition. +.TP +.BI \-D macro = defn +Define macro \c +.I macro\c +\& as \c +.I defn\c +\&. +.TP +.B \-E +Stop after the preprocessing stage; do not run the compiler proper. The +output is preprocessed source code, which is sent to the +standard output. +.TP +.B \-fall\-virtual +Treat all possible member functions as virtual, implicitly. All +member functions (except for constructor functions and +.B new +or +.B delete +member operators) are treated as virtual functions of the class where +they appear. + +This does not mean that all calls to these member functions will be +made through the internal table of virtual functions. Under some +circumstances, the compiler can determine that a call to a given +virtual function can be made directly; in these cases the calls are +direct in any case. +.TP +.B \-fdollars\-in\-identifiers +Permit the use of `\|\c +.B $\c +\&\|' in identifiers. +Traditional C allowed the character `\|\c +.B $\c +\&\|' to form part of identifiers; by default, GNU C also +allows this. However, ANSI C forbids `\|\c +.B $\c +\&\|' in identifiers, and GNU C++ also forbids it by default on most +platforms (though on some platforms it's enabled by default for GNU +C++ as well). +.TP +.B \-felide\-constructors +Use this option to instruct the compiler to be smarter about when it can +elide constructors. Without this flag, GNU C++ and cfront both +generate effectively the same code for: +.sp +.br +A\ foo\ (); +.br +A\ x\ (foo\ ());\ \ \ //\ x\ initialized\ by\ `foo\ ()',\ no\ ctor\ called +.br +A\ y\ =\ foo\ ();\ \ \ //\ call\ to\ `foo\ ()'\ heads\ to\ temporary, +.br +\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ //\ y\ is\ initialized\ from\ the\ temporary. +.br +.sp +Note the difference! With this flag, GNU C++ initializes `\|\c +.B y\c +\&\|' directly +from the call to +.B foo () +without going through a temporary. +.TP +.B \-fenum\-int\-equiv +Normally GNU C++ allows conversion of +.B enum +to +.B int\c +\&, but not the other way around. Use this option if you want GNU C++ +to allow conversion of +.B int +to +.B enum +as well. +.TP +.B \-fexternal\-templates +Produce smaller code for template declarations, by generating only a +single copy of each template function where it is defined. +To use this option successfully, you must also mark all files that +use templates with either `\|\c +.B #pragma implementation\c +\&\|' (the definition) or +`\|\c +.B #pragma interface\c +\&\|' (declarations). + +When your code is compiled with `\|\c +.B \-fexternal\-templates\c +\&\|', all +template instantiations are external. You must arrange for all +necessary instantiations to appear in the implementation file; you can +do this with a \c +.B typedef\c +\& that references each instantiation needed. +Conversely, when you compile using the default option +`\|\c +.B \-fno\-external\-templates\c +\&\|', all template instantiations are +explicitly internal. +.TP +.B \-fno\-gnu\-linker +Do not output global initializations (such as C++ constructors and +destructors) in the form used by the GNU linker (on systems where the GNU +linker is the standard method of handling them). Use this option when +you want to use a non-GNU linker, which also requires using the +.B collect2 +program to make sure the system linker includes +constructors and destructors. (\c +.B collect2 +is included in the GNU CC distribution.) For systems which +.I must +use +.B collect2\c +\&, the compiler driver +.B gcc +is configured to do this automatically. +.TP +.B \-fmemoize\-lookups +.TP +.B \-fsave\-memoized +These flags are used to get the compiler to compile programs faster +using heuristics. They are not on by default since they are only effective +about half the time. The other half of the time programs compile more +slowly (and take more memory). + +The first time the compiler must build a call to a member function (or +reference to a data member), it must (1) determine whether the class +implements member functions of that name; (2) resolve which member +function to call (which involves figuring out what sorts of type +conversions need to be made); and (3) check the visibility of the member +function to the caller. All of this adds up to slower compilation. +Normally, the second time a call is made to that member function (or +reference to that data member), it must go through the same lengthy +process again. This means that code like this +.sp +.br +\ \ cout\ <<\ "This\ "\ <<\ p\ <<\ "\ has\ "\ <<\ n\ <<\ "\ legs.\en"; +.br +.sp +makes six passes through all three steps. By using a software cache, +a ``hit'' significantly reduces this cost. Unfortunately, using the +cache introduces another layer of mechanisms which must be implemented, +and so incurs its own overhead. `\|\c +.B \-fmemoize\-lookups\c +\&\|' enables +the software cache. + +Because access privileges (visibility) to members and member functions +may differ from one function context to the next, +.B g++ +may need to flush the cache. With the `\|\c +.B \-fmemoize\-lookups\c +\&\|' flag, the cache is flushed after every +function that is compiled. The `\|\c +\-fsave\-memoized\c +\&\|' flag enables the same software cache, but when the compiler +determines that the context of the last function compiled would yield +the same access privileges of the next function to compile, it +preserves the cache. +This is most helpful when defining many member functions for the same +class: with the exception of member functions which are friends of +other classes, each member function has exactly the same access +privileges as every other, and the cache need not be flushed. +.TP +.B \-fno\-default\-inline +Do not make member functions inline by default merely because they are +defined inside the class scope. Otherwise, when you specify +.B \-O\c +\&, member functions defined inside class scope are compiled +inline by default; i.e., you don't need to add `\|\c +.B inline\c +\&\|' in front of +the member function name. +.TP +.B \-fno\-strict\-prototype +Consider the declaration \c +.B int foo ();\c +\&. In C++, this means that the +function \c +.B foo\c +\& takes no arguments. In ANSI C, this is declared +.B int foo(void);\c +\&. With the flag `\|\c +.B \-fno\-strict\-prototype\c +\&\|', +declaring functions with no arguments is equivalent to declaring its +argument list to be untyped, i.e., \c +.B int foo ();\c +\& is equivalent to +saying \c +.B int foo (...);\c +\&. +.TP +.B \-fnonnull\-objects +Normally, GNU C++ makes conservative assumptions about objects reached +through references. For example, the compiler must check that `\|\c +.B a\c +\&\|' is not null in code like the following: +.br +\ \ \ \ obj\ &a\ =\ g\ (); +.br +\ \ \ \ a.f\ (2); +.br +Checking that references of this sort have non-null values requires +extra code, however, and it is unnecessary for many programs. You can +use `\|\c +.B \-fnonnull\-objects\c +\&\|' to omit the checks for null, if your program doesn't require the +default checking. +.TP +.B \-fhandle\-signatures +.TP +.B \-fno\-handle\-signatures +These options control the recognition of the \c +.B signature\c +\& and \c +.B sigof\c +\& constructs for specifying abstract types. By default, these +constructs are not recognized. +.TP +.B \-fthis\-is\-variable +The incorporation of user-defined free store management into C++ has +made assignment to \c +.B this\c +\& an anachronism. Therefore, by default GNU +C++ treats the type of \c +.B this\c +\& in a member function of \c +.B class X\c +\& +to be \c +.B X *const\c +\&. In other words, it is illegal to assign to +\c +.B this\c +\& within a class member function. However, for backwards +compatibility, you can invoke the old behavior by using +\&`\|\c +.B \-fthis\-is\-variable\c +\&\|'. +.TP +.B \-g +Produce debugging information in the operating system's native format +(for DBX or SDB or DWARF). GDB also can work with this debugging +information. On most systems that use DBX format, `\|\c +.B \-g\c +\&\|' enables use +of extra debugging information that only GDB can use. + +Unlike most other C compilers, GNU CC allows you to use `\|\c +.B \-g\c +\&\|' with +`\|\c +.B \-O\c +\&\|'. The shortcuts taken by optimized code may occasionally +produce surprising results: some variables you declared may not exist +at all; flow of control may briefly move where you did not expect it; +some statements may not be executed because they compute constant +results or their values were already at hand; some statements may +execute in different places because they were moved out of loops. + +Nevertheless it proves possible to debug optimized output. This makes +it reasonable to use the optimizer for programs that might have bugs. +.TP +.BI "\-I" "dir"\c +\& +Append directory \c +.I dir\c +\& to the list of directories searched for include files. +.TP +.BI "\-L" "dir"\c +\& +Add directory \c +.I dir\c +\& to the list of directories to be searched +for `\|\c +.B \-l\c +\&\|'. +.TP +.BI \-l library\c +\& +Use the library named \c +.I library\c +\& when linking. (C++ programs often require `\|\c +\-lg++\c +\&\|' for successful linking.) +.TP +.B \-nostdinc +Do not search the standard system directories for header files. Only +the directories you have specified with +.B \-I +options (and the current directory, if appropriate) are searched. +.TP +.B \-nostdinc++ +Do not search for header files in the standard directories specific to +C++, but do still search the other standard directories. (This option +is used when building libg++.) +.TP +.B \-O +Optimize. Optimizing compilation takes somewhat more time, and a lot +more memory for a large function. +.TP +.BI "\-o " file\c +\& +Place output in file \c +.I file\c +\&. +.TP +.B \-S +Stop after the stage of compilation proper; do not assemble. The output +is an assembler code file for each non-assembler input +file specified. +.TP +.B \-traditional +Attempt to support some aspects of traditional C compilers. + +Specifically, for both C and C++ programs: +.TP +\ \ \ \(bu +In the preprocessor, comments convert to nothing at all, rather than +to a space. This allows traditional token concatenation. +.TP +\ \ \ \(bu +In the preprocessor, macro arguments are recognized within string +constants in a macro definition (and their values are stringified, +though without additional quote marks, when they appear in such a +context). The preprocessor always considers a string constant to end +at a newline. +.TP +\ \ \ \(bu +The preprocessor does not predefine the macro \c +.B __STDC__\c +\& when you use +`\|\c +.B \-traditional\c +\&\|', but still predefines\c +.B __GNUC__\c +\& (since the GNU extensions indicated by +.B __GNUC__\c +\& are not affected by +`\|\c +.B \-traditional\c +\&\|'). If you need to write header files that work +differently depending on whether `\|\c +.B \-traditional\c +\&\|' is in use, by +testing both of these predefined macros you can distinguish four +situations: GNU C, traditional GNU C, other ANSI C compilers, and +other old C compilers. +.TP +\ \ \ \(bu +In the preprocessor, comments convert to nothing at all, rather than +to a space. This allows traditional token concatenation. +.TP +\ \ \ \(bu +In the preprocessor, macro arguments are recognized within string +constants in a macro definition (and their values are stringified, +though without additional quote marks, when they appear in such a +context). The preprocessor always considers a string constant to end +at a newline. +.TP +\ \ \ \(bu +The preprocessor does not predefine the macro \c +.B __STDC__\c +\& when you use +`\|\c +.B \-traditional\c +\&\|', but still predefines\c +.B __GNUC__\c +\& (since the GNU extensions indicated by +.B __GNUC__\c +\& are not affected by +`\|\c +.B \-traditional\c +\&\|'). If you need to write header files that work +differently depending on whether `\|\c +.B \-traditional\c +\&\|' is in use, by +testing both of these predefined macros you can distinguish four +situations: GNU C, traditional GNU C, other ANSI C compilers, and +other old C compilers. +.PP +.TP +\ \ \ \(bu +String ``constants'' are not necessarily constant; they are stored in +writable space, and identical looking constants are allocated +separately. + +For C++ programs only (not C), `\|\c +.B \-traditional\c +\&\|' has one additional effect: assignment to +.B this +is permitted. This is the same as the effect of `\|\c +.B \-fthis\-is\-variable\c +\&\|'. +.TP +.BI \-U macro +Undefine macro \c +.I macro\c +\&. +.TP +.B \-Wall +Issue warnings for conditions which pertain to usage that we recommend +avoiding and that we believe is easy to avoid, even in conjunction +with macros. +.TP +.B \-Wenum\-clash +Warn when converting between different enumeration types. +.TP +.B \-Woverloaded\-virtual +In a derived class, the definitions of virtual functions must match +the type signature of a virtual function declared in the base class. +Use this option to request warnings when a derived class declares a +function that may be an erroneous attempt to define a virtual +function: that is, warn when a function with the same name as a +virtual function in the base class, but with a type signature that +doesn't match any virtual functions from the base class. +.TP +.B \-Wtemplate\-debugging +When using templates in a C++ program, warn if debugging is not yet +fully available. +.TP +.B \-w +Inhibit all warning messages. +.TP +.BI +e N +Control how virtual function definitions are used, in a fashion +compatible with +.B cfront +1.x. +.PP + +.SH PRAGMAS +Two `\|\c +.B #pragma\c +\&\|' directives are supported for GNU C++, to permit using the same +header file for two purposes: as a definition of interfaces to a given +object class, and as the full definition of the contents of that object class. +.TP +.B #pragma interface +Use this directive in header files that define object classes, to save +space in most of the object files that use those classes. Normally, +local copies of certain information (backup copies of inline member +functions, debugging information, and the internal tables that +implement virtual functions) must be kept in each object file that +includes class definitions. You can use this pragma to avoid such +duplication. When a header file containing `\|\c +.B #pragma interface\c +\&\|' is included in a compilation, this auxiliary information +will not be generated (unless the main input source file itself uses +`\|\c +.B #pragma implementation\c +\&\|'). Instead, the object files will contain references to be +resolved at link time. +.tr !" +.TP +.B #pragma implementation +.TP +.BI "#pragma implementation !" objects .h! +Use this pragma in a main input file, when you want full output from +included header files to be generated (and made globally visible). +The included header file, in turn, should use `\|\c +.B #pragma interface\c +\&\|'. +Backup copies of inline member functions, debugging information, and +the internal tables used to implement virtual functions are all +generated in implementation files. + +If you use `\|\c +.B #pragma implementation\c +\&\|' with no argument, it applies to an include file with the same +basename as your source file; for example, in `\|\c +.B allclass.cc\c +\&\|', `\|\c +.B #pragma implementation\c +\&\|' by itself is equivalent to `\|\c +.B +#pragma implementation "allclass.h"\c +\&\|'. Use the string argument if you want a single implementation +file to include code from multiple header files. + +There is no way to split up the contents of a single header file into +multiple implementation files. +.SH FILES +.ta \w'LIBDIR/g++\-include 'u +file.h C header (preprocessor) file +.br +file.i preprocessed C source file +.br +file.C C++ source file +.br +file.cc C++ source file +.br +file.cxx C++ source file +.br +file.s assembly language file +.br +file.o object file +.br +a.out link edited output +.br +\fITMPDIR\fR/cc\(** temporary files +.br +\fILIBDIR\fR/cpp preprocessor +.br +\fILIBDIR\fR/cc1plus compiler +.br +\fILIBDIR\fR/collect linker front end needed on some machines +.br +\fILIBDIR\fR/libgcc.a GCC subroutine library +.br +/lib/crt[01n].o start-up routine +.br +\fILIBDIR\fR/ccrt0 additional start-up routine for C++ +.br +/lib/libc.a standard C library, see +.IR intro (3) +.br +/usr/include standard directory for +.B #include +files +.br +\fILIBDIR\fR/include standard gcc directory for +.B #include +files +.br +\fILIBDIR\fR/g++\-include additional g++ directory for +.B #include +.sp +.I LIBDIR +is usually +.B /usr/local/lib/\c +.IR machine / version . +.br +.I TMPDIR +comes from the environment variable +.B TMPDIR +(default +.B /usr/tmp +if available, else +.B /tmp\c +\&). +.SH "SEE ALSO" +gcc(1), cpp(1), as(1), ld(1), gdb(1), adb(1), dbx(1), sdb(1). +.br +.RB "`\|" gcc "\|', `\|" cpp \|', +.RB `\| as \|', `\| ld \|', +and +.RB `\| gdb \|' +entries in +.B info\c +\&. +.br +.I +Using and Porting GNU CC (for version 2.0)\c +, Richard M. Stallman; +.I +The C Preprocessor\c +, Richard M. Stallman; +.I +Debugging with GDB: the GNU Source-Level Debugger\c +, Richard M. Stallman and Roland H. Pesch; +.I +Using as: the GNU Assembler\c +, Dean Elsner, Jay Fenlason & friends; +.I +gld: the GNU linker\c +, Steve Chamberlain and Roland Pesch. + +.SH BUGS +For instructions on how to report bugs, see the GCC manual. + +.SH COPYING +Copyright (c) 1991, 1992, 1993 Free Software Foundation, Inc. +.PP +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. +.PP +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. +.PP +Permission is granted to copy and distribute translations of this +manual into another language, under the above conditions for modified +versions, except that this permission notice may be included in +translations approved by the Free Software Foundation instead of in +the original English. +.SH AUTHORS +See the GNU CC Manual for the contributors to GNU CC. diff --git a/contrib/gcc/cp/g++.c b/contrib/gcc/cp/g++.c new file mode 100644 index 00000000000..f694898fa96 --- /dev/null +++ b/contrib/gcc/cp/g++.c @@ -0,0 +1,582 @@ +/* G++ preliminary semantic processing for the compiler driver. + Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Brendan Kehoe (brendan@cygnus.com). + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This program is a wrapper to the main `gcc' driver. For GNU C++, + we need to do two special things: a) append `-lg++' in situations + where it's appropriate, to link in libg++, and b) add `-xc++'..`-xnone' + around file arguments named `foo.c' or `foo.i'. So, we do all of + this semantic processing then just exec gcc with the new argument + list. + + We used to do all of this in a small shell script, but many users + found the performance of this as a shell script to be unacceptable. + In situations where your PATH has a lot of NFS-mounted directories, + using a script that runs sed and other things would be a nasty + performance hit. With this program, we never search the PATH at all. */ + +#include "config.h" +#ifdef __STDC__ +#include +#else +#include +#endif +#include +#include +#if !defined(_WIN32) +#include /* May get R_OK, etc. on some systems. */ +#else +#include +#endif +#include + +/* Defined to the name of the compiler; if using a cross compiler, the + Makefile should compile this file with the proper name + (e.g., "i386-aout-gcc"). */ +#ifndef GCC_NAME +#define GCC_NAME "gcc" +#endif + +/* This bit is set if we saw a `-xfoo' language specification. */ +#define LANGSPEC (1<<1) +/* This bit is set if they did `-lm' or `-lmath'. */ +#define MATHLIB (1<<2) + +#ifndef MATH_LIBRARY +#define MATH_LIBRARY "-lm" +#endif + +/* On MSDOS, write temp files in current dir + because there's no place else we can expect to use. */ +#ifdef __MSDOS__ +#ifndef P_tmpdir +#define P_tmpdir "." +#endif +#ifndef R_OK +#define R_OK 4 +#define W_OK 2 +#define X_OK 1 +#endif +#endif + +#ifndef VPROTO +#ifdef __STDC__ +#define PVPROTO(ARGS) ARGS +#define VPROTO(ARGS) ARGS +#define VA_START(va_list,var) va_start(va_list,var) +#else +#define PVPROTO(ARGS) () +#define VPROTO(ARGS) (va_alist) va_dcl +#define VA_START(va_list,var) va_start(va_list) +#endif +#endif + +#ifndef errno +extern int errno; +#endif + +extern int sys_nerr; +#ifndef HAVE_STRERROR +#if defined(bsd4_4) +extern const char *const sys_errlist[]; +#else +extern char *sys_errlist[]; +#endif +#else +extern char *strerror(); +#endif + +/* Name with which this program was invoked. */ +static char *programname; + +char * +my_strerror(e) + int e; +{ + +#ifdef HAVE_STRERROR + return strerror(e); + +#else + + static char buffer[30]; + if (!e) + return ""; + + if (e > 0 && e < sys_nerr) + return sys_errlist[e]; + + sprintf (buffer, "Unknown error %d", e); + return buffer; +#endif +} + +#ifdef HAVE_VPRINTF +/* Output an error message and exit */ + +static void +fatal VPROTO((char *format, ...)) +{ +#ifndef __STDC__ + char *format; +#endif + va_list ap; + + VA_START (ap, format); + +#ifndef __STDC__ + format = va_arg (ap, char*); +#endif + + fprintf (stderr, "%s: ", programname); + vfprintf (stderr, format, ap); + va_end (ap); + fprintf (stderr, "\n"); +#if 0 + /* XXX Not needed for g++ driver. */ + delete_temp_files (); +#endif + exit (1); +} + +static void +error VPROTO((char *format, ...)) +{ +#ifndef __STDC__ + char *format; +#endif + va_list ap; + + VA_START (ap, format); + +#ifndef __STDC__ + format = va_arg (ap, char*); +#endif + + fprintf (stderr, "%s: ", programname); + vfprintf (stderr, format, ap); + va_end (ap); + + fprintf (stderr, "\n"); +} + +#else /* not HAVE_VPRINTF */ + +static void +error (msg, arg1, arg2) + char *msg, *arg1, *arg2; +{ + fprintf (stderr, "%s: ", programname); + fprintf (stderr, msg, arg1, arg2); + fprintf (stderr, "\n"); +} + +static void +fatal (msg, arg1, arg2) + char *msg, *arg1, *arg2; +{ + error (msg, arg1, arg2); +#if 0 + /* XXX Not needed for g++ driver. */ + delete_temp_files (); +#endif + exit (1); +} + +#endif /* not HAVE_VPRINTF */ + +/* More 'friendly' abort that prints the line and file. + config.h can #define abort fancy_abort if you like that sort of thing. */ + +void +fancy_abort () +{ + fatal ("Internal g++ abort."); +} + +char * +xmalloc (size) + unsigned size; +{ + register char *value = (char *) malloc (size); + if (value == 0) + fatal ("virtual memory exhausted"); + return value; +} + +/* Return a newly-allocated string whose contents concatenate those + of s1, s2, s3. */ +static char * +concat (s1, s2, s3) + char *s1, *s2, *s3; +{ + int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); + char *result = xmalloc (len1 + len2 + len3 + 1); + + strcpy (result, s1); + strcpy (result + len1, s2); + strcpy (result + len1 + len2, s3); + *(result + len1 + len2 + len3) = 0; + + return result; +} + +static void +pfatal_with_name (name) + char *name; +{ + fatal (concat ("%s: ", my_strerror (errno), ""), name); +} + +#ifdef __MSDOS__ +/* This is the common prefix we use to make temp file names. */ +char *temp_filename; + +/* Length of the prefix. */ +int temp_filename_length; + +/* Compute a string to use as the base of all temporary file names. */ +static char * +choose_temp_base_try (try, base) +char *try; +char *base; +{ + char *rv; + if (base) + rv = base; + else if (try == (char *)0) + rv = 0; + else if (access (try, R_OK | W_OK) != 0) + rv = 0; + else + rv = try; + return rv; +} + +static void +choose_temp_base () +{ + char *base = 0; + int len; + + base = choose_temp_base_try (getenv ("TMPDIR"), base); + base = choose_temp_base_try (getenv ("TMP"), base); + base = choose_temp_base_try (getenv ("TEMP"), base); + +#ifdef P_tmpdir + base = choose_temp_base_try (P_tmpdir, base); +#endif + + base = choose_temp_base_try ("/usr/tmp", base); + base = choose_temp_base_try ("/tmp", base); + + /* If all else fails, use the current directory! */ + if (base == (char *)0) + base = "./"; + + len = strlen (base); + temp_filename = xmalloc (len + sizeof("/ccXXXXXX")); + strcpy (temp_filename, base); + if (len > 0 && temp_filename[len-1] != '/') + temp_filename[len++] = '/'; + strcpy (temp_filename + len, "ccXXXXXX"); + + mktemp (temp_filename); + temp_filename_length = strlen (temp_filename); + if (temp_filename_length == 0) + abort (); +} + +static void +perror_exec (name) + char *name; +{ + char *s; + + if (errno < sys_nerr) + s = concat ("installation problem, cannot exec %s: ", + my_strerror( errno ), ""); + else + s = "installation problem, cannot exec %s"; + error (s, name); +} + +/* This is almost exactly what's in gcc.c:pexecute for MSDOS. */ +void +run_dos (program, argv) + char *program; + char *argv[]; +{ + char *scmd, *rf; + FILE *argfile; + int i; + + choose_temp_base (); /* not in gcc.c */ + + scmd = (char *) malloc (strlen (program) + strlen (temp_filename) + 10); + rf = scmd + strlen (program) + 6; + sprintf (scmd, "%s.exe @%s.gp", program, temp_filename); + + argfile = fopen (rf, "w"); + if (argfile == 0) + pfatal_with_name (rf); + + for (i=1; argv[i]; i++) + { + char *cp; + for (cp = argv[i]; *cp; cp++) + { + if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp)) + fputc ('\\', argfile); + fputc (*cp, argfile); + } + fputc ('\n', argfile); + } + fclose (argfile); + + i = system (scmd); + + remove (rf); + + if (i == -1) + perror_exec (program); +} +#endif /* __MSDOS__ */ + +int +main (argc, argv) + int argc; + char **argv; +{ + register int i, j = 0; + register char *p; + int verbose = 0; + + /* This will be 0 if we encounter a situation where we should not + link in libstdc++, or 2 if we should link in libg++ as well. */ + int library = 1; + + /* Used to track options that take arguments, so we don't go wrapping + those with -xc++/-xnone. */ + char *quote = NULL; + + /* The new argument list will be contained in this. */ + char **arglist; + + /* The name of the compiler we will want to run---by default, it + will be the definition of `GCC_NAME', e.g., `gcc'. */ + char *gcc = GCC_NAME; + + /* Non-zero if we saw a `-xfoo' language specification on the + command line. Used to avoid adding our own -xc++ if the user + already gave a language for the file. */ + int saw_speclang = 0; + + /* Non-zero if we saw `-lm' or `-lmath' on the command line. */ + char *saw_math = 0; + + /* The number of arguments being added to what's in argv, other than + libraries. We use this to track the number of times we've inserted + -xc++/-xnone. */ + int added = 0; + + /* An array used to flag each argument that needs a bit set for + LANGSPEC or MATHLIB. */ + int *args; + + p = argv[0] + strlen (argv[0]); + + /* If we're called as g++ (or i386-aout-g++), link in libg++ as well. */ + + if (strcmp (p - 3, "g++") == 0) + { + library = 2; + } + + while (p != argv[0] && p[-1] != '/') + --p; + programname = p; + + if (argc == 1) + fatal ("No input files specified.\n"); + +#ifndef __MSDOS__ + /* We do a little magic to find out where the main gcc executable + is. If they ran us as /usr/local/bin/g++, then we will look + for /usr/local/bin/gcc; similarly, if they just ran us as `g++', + we'll just look for `gcc'. */ + if (p != argv[0]) + { + *--p = '\0'; + gcc = (char *) malloc ((strlen (argv[0]) + 1 + strlen (GCC_NAME) + 1) + * sizeof (char)); + sprintf (gcc, "%s/%s", argv[0], GCC_NAME); + } +#endif + + args = (int *) malloc (argc * sizeof (int)); + bzero ((char *) args, argc * sizeof (int)); + + for (i = 1; i < argc; i++) + { + /* If the previous option took an argument, we swallow it here. */ + if (quote) + { + quote = NULL; + continue; + } + + if (argv[i][0] == '\0' || argv[i][1] == '\0') + continue; + + if (argv[i][0] == '-') + { + if (library != 0 && strcmp (argv[i], "-nostdlib") == 0) + { + library = 0; + } + else if (strcmp (argv[i], "-lm") == 0 + || strcmp (argv[i], "-lmath") == 0) + args[i] |= MATHLIB; + else if (strcmp (argv[i], "-v") == 0) + { + verbose = 1; + if (argc == 2) + { + /* If they only gave us `-v', don't try to link + in libg++. */ + library = 0; + } + } + else if (strncmp (argv[i], "-x", 2) == 0) + saw_speclang = 1; + else if (((argv[i][2] == '\0' + && (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL) + || strcmp (argv[i], "-Tdata") == 0)) + quote = argv[i]; + else if (library != 0 && ((argv[i][2] == '\0' + && (char *) strchr ("cSEM", argv[i][1]) != NULL) + || strcmp (argv[i], "-MM") == 0)) + { + /* Don't specify libraries if we won't link, since that would + cause a warning. */ + library = 0; + } + else + /* Pass other options through. */ + continue; + } + else + { + int len; + + if (saw_speclang) + { + saw_speclang = 0; + continue; + } + + /* If the filename ends in .c or .i, put options around it. + But not if a specified -x option is currently active. */ + len = strlen (argv[i]); + if (len > 2 + && (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i') + && argv[i][len - 2] == '.') + { + args[i] |= LANGSPEC; + added += 2; + } + } + } + + if (quote) + fatal ("argument to `%s' missing\n", quote); + + if (added || library) + { + arglist = (char **) malloc ((argc + added + 4) * sizeof (char *)); + + for (i = 1, j = 1; i < argc; i++, j++) + { + arglist[j] = argv[i]; + + /* Make sure -lg++ is before the math library, since libg++ + itself uses those math routines. */ + if (!saw_math && (args[i] & MATHLIB) && library) + { + --j; + saw_math = argv[i]; + } + + /* Wrap foo.c and foo.i files in a language specification to + force the gcc compiler driver to run cc1plus on them. */ + if (args[i] & LANGSPEC) + { + int len = strlen (argv[i]); + if (argv[i][len - 1] == 'i') + arglist[j++] = "-xc++-cpp-output"; + else + arglist[j++] = "-xc++"; + arglist[j++] = argv[i]; + arglist[j] = "-xnone"; + } + } + + /* Add `-lg++' if we haven't already done so. */ + if (library == 2) + arglist[j++] = "-lg++"; + if (library) + arglist[j++] = "-lstdc++"; + if (saw_math) + arglist[j++] = saw_math; + else if (library) + arglist[j++] = MATH_LIBRARY; + + arglist[j] = NULL; + } + else + /* No need to copy 'em all. */ + arglist = argv; + + arglist[0] = gcc; + + if (verbose) + { + if (j == 0) + j = argc; + + for (i = 0; i < j; i++) + fprintf (stderr, " %s", arglist[i]); + fprintf (stderr, "\n"); + } +#if !defined(OS2) && !defined (_WIN32) +#ifdef __MSDOS__ + run_dos (gcc, arglist); +#else /* !__MSDOS__ */ + if (execvp (gcc, arglist) < 0) + pfatal_with_name (gcc); +#endif /* __MSDOS__ */ +#else /* OS2 or _WIN32 */ + if (spawnvp (1, gcc, arglist) < 0) + pfatal_with_name (gcc); +#endif + + return 0; +} diff --git a/contrib/gcc/cp/gc.c b/contrib/gcc/cp/gc.c new file mode 100644 index 00000000000..cff1635f53a --- /dev/null +++ b/contrib/gcc/cp/gc.c @@ -0,0 +1,1550 @@ +/* Garbage collection primitives for GNU C++. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "tree.h" +#include "cp-tree.h" +#include "flags.h" +#include "output.h" + +#undef NULL +#define NULL 0 + +extern tree define_function (); +extern tree build_t_desc_overload (); +extern struct obstack *permanent_obstack; + +/* This is the function decl for the (pseudo-builtin) __gc_protect + function. Args are (class *value, int index); Returns value. */ +tree gc_protect_fndecl; + +/* This is the function decl for the (pseudo-builtin) __gc_unprotect + function. Args are (int index); void return. */ +tree gc_unprotect_fndecl; + +/* This is the function decl for the (pseudo-builtin) __gc_push + function. Args are (int length); void return. */ +tree gc_push_fndecl; + +/* This is the function decl for the (pseudo-builtin) __gc_pop + function. Args are void; void return. */ +tree gc_pop_fndecl; + +/* Special integers that are used to represent bits in gc-safe objects. */ +tree gc_nonobject; +tree gc_visible; +tree gc_white; +tree gc_offwhite; +tree gc_grey; +tree gc_black; + +/* in c-common.c */ +extern tree combine_strings PROTO((tree)); + +/* Predicate that returns non-zero if TYPE needs some kind of + entry for the GC. Returns zero otherwise. */ +int +type_needs_gc_entry (type) + tree type; +{ + tree ttype = type; + + if (! flag_gc || type == error_mark_node) + return 0; + + /* Aggregate types need gc entries if any of their members + need gc entries. */ + if (IS_AGGR_TYPE (type)) + { + tree binfos; + tree fields = TYPE_FIELDS (type); + int i; + + /* We don't care about certain pointers. Pointers + to virtual baseclasses are always up front. We also + cull out virtual function table pointers because it's + easy, and it simplifies the logic.*/ + while (fields + && (DECL_NAME (fields) == NULL_TREE + || VFIELD_NAME_P (DECL_NAME (fields)) + || VBASE_NAME_P (DECL_NAME (fields)) + || !strcmp (IDENTIFIER_POINTER (DECL_NAME (fields)), "__bits"))) + fields = TREE_CHAIN (fields); + + while (fields) + { + if (type_needs_gc_entry (TREE_TYPE (fields))) + return 1; + fields = TREE_CHAIN (fields); + } + + binfos = TYPE_BINFO_BASETYPES (type); + if (binfos) + for (i = TREE_VEC_LENGTH (binfos)-1; i >= 0; i--) + if (type_needs_gc_entry (BINFO_TYPE (TREE_VEC_ELT (binfos, i)))) + return 1; + + return 0; + } + + while (TREE_CODE (ttype) == ARRAY_TYPE + && TREE_CODE (TREE_TYPE (ttype)) == ARRAY_TYPE) + ttype = TREE_TYPE (ttype); + if ((TREE_CODE (ttype) == POINTER_TYPE + || TREE_CODE (ttype) == ARRAY_TYPE + || TREE_CODE (ttype) == REFERENCE_TYPE) + && IS_AGGR_TYPE (TREE_TYPE (ttype)) + && CLASSTYPE_RTTI (TREE_TYPE (ttype))) + return 1; + + return 0; +} + +/* Predicate that returns non-zero iff FROM is safe from the GC. + + If TO is nonzero, it means we know that FROM is being stored + in TO, which make make it safe. */ +int +value_safe_from_gc (to, from) + tree to, from; +{ + /* First, return non-zero for easy cases: parameters, + static variables. */ + if (TREE_CODE (from) == PARM_DECL + || (TREE_CODE (from) == VAR_DECL + && TREE_STATIC (from))) + return 1; + + /* If something has its address taken, it cannot be + in the heap, so it doesn't need to be protected. */ + if (TREE_CODE (from) == ADDR_EXPR || TREE_REFERENCE_EXPR (from)) + return 1; + + /* If we are storing into a static variable, then what + we store will be safe from the gc. */ + if (to && TREE_CODE (to) == VAR_DECL + && TREE_STATIC (to)) + return 1; + + /* Now recurse on structure of FROM. */ + switch (TREE_CODE (from)) + { + case COMPONENT_REF: + /* These guys are special, and safe. */ + if (TREE_CODE (TREE_OPERAND (from, 1)) == FIELD_DECL + && (VFIELD_NAME_P (DECL_NAME (TREE_OPERAND (from, 1))) + || VBASE_NAME_P (DECL_NAME (TREE_OPERAND (from, 1))))) + return 1; + /* fall through... */ + case NOP_EXPR: + case CONVERT_EXPR: + case NON_LVALUE_EXPR: + case WITH_CLEANUP_EXPR: + case SAVE_EXPR: + case PREDECREMENT_EXPR: + case PREINCREMENT_EXPR: + case POSTDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + if (value_safe_from_gc (to, TREE_OPERAND (from, 0))) + return 1; + break; + + case VAR_DECL: + case PARM_DECL: + /* We can safely pass these things as parameters to functions. */ + if (to == 0) + return 1; + + case ARRAY_REF: + case INDIRECT_REF: + case RESULT_DECL: + case OFFSET_REF: + case CALL_EXPR: + case METHOD_CALL_EXPR: + break; + + case COMPOUND_EXPR: + case TARGET_EXPR: + if (value_safe_from_gc (to, TREE_OPERAND (from, 1))) + return 1; + break; + + case COND_EXPR: + if (value_safe_from_gc (to, TREE_OPERAND (from, 1)) + && value_safe_from_gc (to, TREE_OPERAND (from, 2))) + return 1; + break; + + case PLUS_EXPR: + case MINUS_EXPR: + if ((type_needs_gc_entry (TREE_TYPE (TREE_OPERAND (from, 0))) + || value_safe_from_gc (to, TREE_OPERAND (from, 0))) + && (type_needs_gc_entry (TREE_TYPE (TREE_OPERAND (from, 1))) == 0 + || value_safe_from_gc (to, TREE_OPERAND (from, 1)))) + return 1; + break; + + case RTL_EXPR: + /* Every time we build an RTL_EXPR in the front-end, we must + ensure that everything in it is safe from the garbage collector. + ??? This has only been done for `build_new'. */ + return 1; + + default: + my_friendly_abort (41); + } + + if (to == 0) + return 0; + + /* FROM wasn't safe. But other properties of TO might make it safe. */ + switch (TREE_CODE (to)) + { + case VAR_DECL: + case PARM_DECL: + /* We already culled out static VAR_DECLs above. */ + return 0; + + case COMPONENT_REF: + /* These guys are special, and safe. */ + if (TREE_CODE (TREE_OPERAND (to, 1)) == FIELD_DECL + && (VFIELD_NAME_P (DECL_NAME (TREE_OPERAND (to, 1))) + || VBASE_NAME_P (DECL_NAME (TREE_OPERAND (to, 1))))) + return 1; + /* fall through... */ + + case NOP_EXPR: + case NON_LVALUE_EXPR: + case WITH_CLEANUP_EXPR: + case SAVE_EXPR: + case PREDECREMENT_EXPR: + case PREINCREMENT_EXPR: + case POSTDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + return value_safe_from_gc (TREE_OPERAND (to, 0), from); + + case COMPOUND_EXPR: + case TARGET_EXPR: + return value_safe_from_gc (TREE_OPERAND (to, 1), from); + + case COND_EXPR: + return (value_safe_from_gc (TREE_OPERAND (to, 1), from) + && value_safe_from_gc (TREE_OPERAND (to, 2), from)); + + case INDIRECT_REF: + case ARRAY_REF: + /* This used to be 0, but our current restricted model + allows this to be 1. We'll never get arrays this way. */ + return 1; + + default: + my_friendly_abort (42); + } + + /* Catch-all case is that TO/FROM is not safe. */ + return 0; +} + +/* Function to build a static GC entry for DECL. TYPE is DECL's type. + + For objects of type `class *', this is just an entry in the + static vector __PTR_LIST__. + + For objects of type `class[]', this requires building an entry + in the static vector __ARR_LIST__. + + For aggregates, this records all fields of type `class *' + and `class[]' in the respective lists above. */ +void +build_static_gc_entry (decl, type) + tree decl; + tree type; +{ + /* Now, figure out what sort of entry to build. */ + if (TREE_CODE (type) == POINTER_TYPE + || TREE_CODE (type) == REFERENCE_TYPE) + assemble_gc_entry (IDENTIFIER_POINTER (DECL_NAME (decl))); + else if (TREE_CODE (type) == RECORD_TYPE) + { + tree ref = get_temp_name (build_reference_type (type), 1); + DECL_INITIAL (ref) = build1 (ADDR_EXPR, TREE_TYPE (ref), decl); + TREE_CONSTANT (DECL_INITIAL (ref)) = 1; + cp_finish_decl (ref, DECL_INITIAL (ref), NULL_TREE, 0, 0); + } + else + { + /* Not yet implemented. + + Cons up a static variable that holds address and length info + and add that to ___ARR_LIST__. */ + my_friendly_abort (43); + } +} + +/* Protect FROM from the GC, assuming FROM is going to be + stored into TO. We handle three cases for TO here: + + case 1: TO is a stack variable. + case 2: TO is zero (which means it is a parameter). + case 3: TO is a return value. */ + +tree +protect_value_from_gc (to, from) + tree to, from; +{ + if (to == 0) + { + tree cleanup; + + to = get_temp_regvar (TREE_TYPE (from), from); + + /* Convert from integer to list form since we'll use it twice. */ + DECL_GC_OFFSET (to) = build_tree_list (NULL_TREE, DECL_GC_OFFSET (to)); + cleanup = build_function_call (gc_unprotect_fndecl, + DECL_GC_OFFSET (to)); + + if (! cp_expand_decl_cleanup (to, cleanup)) + { + compiler_error ("cannot unprotect parameter in this scope"); + return error_mark_node; + } + } + + /* Should never need to protect a value that's headed for static storage. */ + if (TREE_STATIC (to)) + my_friendly_abort (44); + + switch (TREE_CODE (to)) + { + case COMPONENT_REF: + case INDIRECT_REF: + return protect_value_from_gc (TREE_OPERAND (to, 0), from); + + case VAR_DECL: + case PARM_DECL: + { + tree rval; + if (DECL_GC_OFFSET (to) == NULL_TREE) + { + /* Because of a cast or a conversion, we might stick + a value into a variable that would not normally + have a GC entry. */ + DECL_GC_OFFSET (to) = size_int (++current_function_obstack_index); + } + + if (TREE_CODE (DECL_GC_OFFSET (to)) != TREE_LIST) + { + DECL_GC_OFFSET (to) + = build_tree_list (NULL_TREE, DECL_GC_OFFSET (to)); + } + + current_function_obstack_usage = 1; + rval = build_function_call (gc_protect_fndecl, + tree_cons (NULL_TREE, from, + DECL_GC_OFFSET (to))); + TREE_TYPE (rval) = TREE_TYPE (from); + return rval; + } + } + + /* If we fall through the switch, assume we lost. */ + my_friendly_abort (45); + /* NOTREACHED */ + return NULL_TREE; +} + +/* Given the expression EXP of type `class *', return the head + of the object pointed to by EXP. */ +tree +build_headof (exp) + tree exp; +{ + tree type = TREE_TYPE (exp); + tree vptr, offset; + + if (TREE_CODE (type) != POINTER_TYPE) + { + error ("`headof' applied to non-pointer type"); + return error_mark_node; + } + type = TREE_TYPE (type); + + if (!TYPE_VIRTUAL_P (type) || CLASSTYPE_VFIELD (type) == NULL_TREE) + return exp; + + vptr = fold (size_binop (PLUS_EXPR, + size_binop (FLOOR_DIV_EXPR, + DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (type)), + size_int (BITS_PER_UNIT)), + exp)); + vptr = build1 (INDIRECT_REF, build_pointer_type (vtable_entry_type), vptr); + + if (flag_vtable_thunks) + offset = build_array_ref (vptr, integer_zero_node); + else + offset = build_component_ref (build_array_ref (vptr, integer_zero_node), + delta_identifier, + NULL_TREE, 0); + + type = build_type_variant (ptr_type_node, TREE_READONLY (exp), + TREE_THIS_VOLATILE (exp)); + return build (PLUS_EXPR, type, exp, + convert (ptrdiff_type_node, offset)); +} + +/* Return the type_info node associated with the expression EXP. If EXP is + a reference to a polymorphic class, return the dynamic type; otherwise + return the static type of the expression. */ +tree +build_typeid (exp) + tree exp; +{ + tree type; + + if (!flag_rtti) + cp_error ("cannot take typeid of object when -frtti is not specified"); + + if (exp == error_mark_node) + return error_mark_node; + + type = TREE_TYPE (exp); + + /* Strip top-level cv-qualifiers. */ + type = TYPE_MAIN_VARIANT (type); + + /* if b is an instance of B, typeid(b) == typeid(B). Do this before + reference trickiness. */ + if (TREE_CODE (exp) == VAR_DECL && TREE_CODE (type) == RECORD_TYPE) + return get_typeid (type); + + /* peel back references, so they match. */ + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* Peel off cv qualifiers. */ + type = TYPE_MAIN_VARIANT (type); + + /* Apply trivial conversion T -> T& for dereferenced ptrs. */ + if (TREE_CODE (type) == RECORD_TYPE) + type = build_reference_type (type); + + /* If exp is a reference to polymorphic type, get the real type_info. */ + if (TREE_CODE (type) == REFERENCE_TYPE && TYPE_VIRTUAL_P (TREE_TYPE (type))) + { + /* build reference to type_info from vtable. */ + tree t; + + if (flag_vtable_thunks) + t = build_vfn_ref ((tree *) NULL_TREE, exp, integer_one_node); + else + t = build_vfn_ref ((tree *) NULL_TREE, exp, integer_zero_node); + + TREE_TYPE (t) = build_pointer_type (__class_desc_type_node); + t = build_indirect_ref (t, NULL); + return t; + } + + /* otherwise return the type_info for the static type of the expr. */ + return get_typeid (type); +} + +/* Return the type_info object for TYPE, creating it if necessary. */ +tree +get_typeid (type) + tree type; +{ + tree t, td; + + if (type == error_mark_node) + return error_mark_node; + + /* Is it useful (and/or correct) to have different typeids for `T &' + and `T'? */ + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + td = build_t_desc (type, 1); + if (td == error_mark_node) + return error_mark_node; + + t = TREE_OPERAND (td, 0); + return t; +} + +/* Get a bad_cast node for the program to throw... + + See libstdc++::exception{,.cc} for __bad_cast_object */ +tree +get_bad_cast_node () +{ + static tree t; + if (t == NULL_TREE + && (t = lookup_name (get_identifier ("__bad_cast_object"), 0)) + == NULL_TREE) + { + error ("you must #include "); + return error_mark_node; + } + return t; +} + +/* Execute a dynamic cast, as described in section 5.2.6 of the 9/93 working + paper. */ +tree +build_dynamic_cast (type, expr) + tree type, expr; +{ + enum tree_code tc = TREE_CODE (type); + tree exprtype = TREE_TYPE (expr); + enum tree_code ec = TREE_CODE (exprtype); + tree retval; + + if (type == error_mark_node || expr == error_mark_node) + return error_mark_node; + + switch (tc) + { + case POINTER_TYPE: + if (ec == REFERENCE_TYPE) + { + expr = convert_from_reference (expr); + exprtype = TREE_TYPE (expr); + ec = TREE_CODE (exprtype); + } + if (ec != POINTER_TYPE) + goto fail; + if (TREE_CODE (TREE_TYPE (exprtype)) != RECORD_TYPE) + goto fail; + if (TYPE_SIZE (TREE_TYPE (exprtype)) == 0) + goto fail; + if (TREE_READONLY (TREE_TYPE (exprtype)) && + ! TYPE_READONLY (TREE_TYPE (type))) + goto fail; + if (TYPE_MAIN_VARIANT (TREE_TYPE (type)) == void_type_node) + break; + /* else fall through */ + case REFERENCE_TYPE: + if (TREE_CODE (TREE_TYPE (type)) == RECORD_TYPE + && TYPE_SIZE (TREE_TYPE (type)) != NULL_TREE) + break; + /* else fall through */ + default: + goto fail; + } + + /* Apply trivial conversion T -> T& for dereferenced ptrs. */ + if (ec == RECORD_TYPE) + { + exprtype = build_type_variant (exprtype, TREE_READONLY (expr), + TREE_THIS_VOLATILE (expr)); + exprtype = build_reference_type (exprtype); + expr = convert_to_reference (exprtype, expr, CONV_IMPLICIT, + LOOKUP_NORMAL, NULL_TREE); + ec = REFERENCE_TYPE; + } + + if (tc == REFERENCE_TYPE) + { + if (ec != REFERENCE_TYPE) + goto fail; + if (TREE_CODE (TREE_TYPE (exprtype)) != RECORD_TYPE) + goto fail; + if (TYPE_SIZE (TREE_TYPE (exprtype)) == 0) + goto fail; + } + + /* If *type is an unambiguous accessible base class of *exprtype, + convert statically. */ + { + int distance; + tree path; + + distance = get_base_distance (TREE_TYPE (type), TREE_TYPE (exprtype), 1, + &path); + if (distance >= 0) + return build_vbase_path (PLUS_EXPR, type, expr, path, 0); + } + + /* Otherwise *exprtype must be a polymorphic class (have a vtbl). */ + if (TYPE_VIRTUAL_P (TREE_TYPE (exprtype))) + { + /* if TYPE is `void *', return pointer to complete object. */ + if (tc == POINTER_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (type)) == void_type_node) + { + /* if b is an object, dynamic_cast(&b) == (void *)&b. */ + if (TREE_CODE (expr) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (expr, 0)) == VAR_DECL + && TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == RECORD_TYPE) + return build1 (NOP_EXPR, type, expr); + + return build_headof (expr); + } + else + { + tree retval; + tree result, td1, td2, elems, tmp1, expr1; + + /* If we got here, we can't convert statically. Therefore, + dynamic_cast(b) (b an object) cannot succeed. */ + if (ec == REFERENCE_TYPE) + { + if (TREE_CODE (expr) == VAR_DECL + && TREE_CODE (TREE_TYPE (expr)) == RECORD_TYPE) + { + cp_warning ("dynamic_cast of `%#D' to `%#T' can never succeed", + expr, type); + return build_throw (get_bad_cast_node ()); + } + } + /* Ditto for dynamic_cast(&b). */ + else if (TREE_CODE (expr) == ADDR_EXPR) + { + tree op = TREE_OPERAND (expr, 0); + if (TREE_CODE (op) == VAR_DECL + && TREE_CODE (TREE_TYPE (op)) == RECORD_TYPE) + { + cp_warning ("dynamic_cast of `%#D' to `%#T' can never succeed", + expr, type); + retval = build_int_2 (0, 0); + TREE_TYPE (retval) = type; + return retval; + } + } + + expr1 = expr; + if (tc == REFERENCE_TYPE) + expr1 = build_unary_op (ADDR_EXPR, expr1, 0); + + /* Build run-time conversion. */ + expr1 = build_headof (expr1); + + if (ec == POINTER_TYPE) + td1 = build_typeid (build_indirect_ref (expr, NULL_PTR)); + else + td1 = build_typeid (expr); + + if (tc == POINTER_TYPE) + td2 = get_typeid (TREE_TYPE (type)); + else + td2 = get_typeid (type); + + elems = tree_cons (NULL_TREE, td2, + tree_cons (NULL_TREE, build_int_2 (1, 0), + tree_cons (NULL_TREE, expr1, NULL_TREE))); + result = build_method_call (td1, + get_identifier ("__rtti_match"), elems, NULL_TREE, LOOKUP_NORMAL); + + if (tc == REFERENCE_TYPE) + { + expr1 = build_throw (get_bad_cast_node ()); + expr1 = build_compound_expr (tree_cons (NULL_TREE, expr1, + build_tree_list (NULL_TREE, convert (type, integer_zero_node)))); + TREE_TYPE (expr1) = type; + return build (COND_EXPR, type, result, result, expr1); + } + + /* Now back to the type we want from a void*. */ + result = convert (type, result); + return result; + } + } + + fail: + cp_error ("cannot dynamic_cast `%E' (of type `%#T') to type `%#T'", + expr, exprtype, type); + return error_mark_node; +} + +/* Build and initialize various sorts of descriptors. Every descriptor + node has a name associated with it (the name created by mangling). + For this reason, we use the identifier as our access to the __*_desc + nodes, instead of sticking them directly in the types. Otherwise we + would burden all built-in types (and pointer types) with slots that + we don't necessarily want to use. + + For each descriptor we build, we build a variable that contains + the descriptor's information. When we need this info at runtime, + all we need is access to these variables. + + Note: these constructors always return the address of the descriptor + info, since that is simplest for their mutual interaction. */ + +static tree +build_generic_desc (tdecl, type, elems) + tree tdecl; + tree type; + tree elems; +{ + tree init = elems; + int toplev = global_bindings_p (); + + TREE_CONSTANT (init) = 1; + TREE_STATIC (init) = 1; + TREE_READONLY (init) = 1; + + TREE_TYPE (tdecl) = type; + DECL_INITIAL (tdecl) = init; + TREE_STATIC (tdecl) = 1; + DECL_SIZE (tdecl) = NULL_TREE; + layout_decl (tdecl, 0); + if (! toplev) + push_to_top_level (); + cp_finish_decl (tdecl, init, NULL_TREE, 0, 0); + if (! toplev) + pop_from_top_level (); + + if (! TREE_USED (tdecl)) + { + assemble_external (tdecl); + TREE_USED (tdecl) = 1; + } + + return IDENTIFIER_AS_DESC (DECL_NAME (tdecl)); +} + +/* Build an initializer for a __bltn_desc node. */ +static tree +build_bltn_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree elems, t; + + if (type == boolean_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_BOOL"), + 0, 0); + else if (type == char_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_CHAR"), + 0, 0); + else if (type == short_integer_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_SHORT"), + 0, 0); + else if (type == integer_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_INT"), + 0, 0); + else if (type == long_integer_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_LONG"), + 0, 0); + else if (type == long_long_integer_type_node) + t = lookup_field (__bltn_desc_type_node, + get_identifier("_RTTI_BI_LONGLONG"), 0, 0); + else if (type == float_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_FLOAT"), + 0, 0); + else if (type == double_type_node) + t = lookup_field (__bltn_desc_type_node, + get_identifier("_RTTI_BI_DOUBLE"), 0, 0); + else if (type == long_double_type_node) + t = lookup_field (__bltn_desc_type_node, + get_identifier("_RTTI_BI_LDOUBLE"), 0, 0); + else if (type == unsigned_char_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_UCHAR"), + 0, 0); + else if (type == short_unsigned_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_USHORT"), + 0, 0); + else if (type == unsigned_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_UINT"), + 0, 0); + else if (type == long_unsigned_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_ULONG"), + 0, 0); + else if (type == long_long_unsigned_type_node) + t = lookup_field (__bltn_desc_type_node, + get_identifier("_RTTI_BI_ULONGLONG"), 0, 0); + else if (type == signed_char_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_SCHAR"), + 0, 0); + else if (type == wchar_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_WCHAR"), + 0, 0); + else if (type == void_type_node) + t = lookup_field (__bltn_desc_type_node, get_identifier("_RTTI_BI_VOID"), + 0, 0); + else + { + cp_compiler_error ("type `%T' not handled as a built-in type"); + } + + elems = tree_cons (NULL_TREE, t, NULL_TREE); + return build_generic_desc (tdecl, __bltn_desc_type_node, elems); +} + +/* Build an initializer for a __user_desc node. */ +static tree +build_user_desc (tdecl) + tree tdecl; +{ + tree elems, name_string, t; + tree tname = DECL_NAME (tdecl); + + name_string = combine_strings (build_string + (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname))); + elems = name_string; + return build_generic_desc (tdecl, __user_desc_type_node, elems); +} + +/* Build an initializer for a __class_type_info node. */ +static tree +build_class_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree tname = DECL_NAME (tdecl); + tree name_string; + + int i = CLASSTYPE_N_BASECLASSES (type); + int n_base = i; + int base_cnt = 0; + tree binfos = TYPE_BINFO_BASETYPES (type); + tree vb = CLASSTYPE_VBASECLASSES (type); + tree base, elems, access, offset, isvir; + tree base_list, off_list, acc_list, isvir_list; + tree t; + static tree acc_pub = NULL_TREE; + static tree acc_pro = NULL_TREE; + static tree acc_pri = NULL_TREE; + + if (acc_pub == NULL_TREE) + { + acc_pub = lookup_field (__class_desc_type_node, + get_identifier("_RTTI_ACCESS_PUBLIC"), 0, 0); + acc_pro = lookup_field (__class_desc_type_node, + get_identifier("_RTTI_ACCESS_PROTECTED"), 0, 0); + acc_pri = lookup_field (__class_desc_type_node, + get_identifier("_RTTI_ACCESS_PRIVATE"), 0, 0); + } + + base_list = build_tree_list (NULL_TREE, integer_zero_node); + off_list = build_tree_list (NULL_TREE, integer_zero_node); + acc_list = build_tree_list (NULL_TREE, integer_zero_node); + isvir_list = build_tree_list (NULL_TREE, integer_zero_node); + while (--i >= 0) + { + tree binfo = TREE_VEC_ELT (binfos, i); + + base = build_t_desc (BINFO_TYPE (binfo), 1); + if (TREE_VIA_VIRTUAL (binfo)) + { + tree t = BINFO_TYPE (binfo); + char *name; + tree field; + int off; + + name = (char *) alloca (TYPE_NAME_LENGTH (t)+sizeof (VBASE_NAME)+1); + sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (t)); + field = lookup_field (type, get_identifier (name), 0, 0); + offset = size_binop (FLOOR_DIV_EXPR, + DECL_FIELD_BITPOS (field), size_int (BITS_PER_UNIT)); + } + else + offset = BINFO_OFFSET (binfo); + + if (TREE_VIA_PUBLIC (binfo)) + access = acc_pub; + else if (TREE_VIA_PROTECTED (binfo)) + access = acc_pro; + else + access = acc_pri; + if (TREE_VIA_VIRTUAL (binfo)) + isvir = build_int_2 (1, 0); + else + isvir = build_int_2 (0, 0); + + base_list = tree_cons (NULL_TREE, base, base_list); + isvir_list = tree_cons (NULL_TREE, isvir, isvir_list); + acc_list = tree_cons (NULL_TREE, access, acc_list); + off_list = tree_cons (NULL_TREE, offset, off_list); + base_cnt++; + } +#if 0 + i = n_base; + while (vb) + { + tree b; + access = acc_pub; + while (--i >= 0) + { + b = TREE_VEC_ELT (binfos, i); + if (BINFO_TYPE (vb) == BINFO_TYPE (b) && TREE_VIA_VIRTUAL (b)) + { + if (TREE_VIA_PUBLIC (b)) + access = acc_pub; + else if (TREE_VIA_PROTECTED (b)) + access = acc_pro; + else + access = acc_pri; + break; + } + } + base = build_t_desc (BINFO_TYPE (vb), 1); + offset = BINFO_OFFSET (vb); + isvir = build_int_2 (1, 0); + + base_list = tree_cons (NULL_TREE, base, base_list); + isvir_list = tree_cons (NULL_TREE, isvir, isvir_list); + acc_list = tree_cons (NULL_TREE, access, acc_list); + off_list = tree_cons (NULL_TREE, offset, off_list); + + base_cnt++; + vb = TREE_CHAIN (vb); + } +#endif + base_list = finish_table (NULL_TREE, build_pointer_type (__t_desc_type_node), + base_list, 0); + off_list = finish_table (NULL_TREE, integer_type_node, + off_list, 0); + isvir_list = finish_table (NULL_TREE, integer_type_node, + isvir_list, 0); + acc_list = finish_table (NULL_TREE, __access_mode_type_node, + acc_list, 0); + + + name_string = combine_strings (build_string (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname))); + + elems = tree_cons (NULL_TREE, name_string, + tree_cons (NULL_TREE, default_conversion (base_list), + tree_cons (NULL_TREE, default_conversion (off_list), + tree_cons (NULL_TREE, default_conversion (isvir_list), + tree_cons (NULL_TREE, default_conversion (acc_list), + tree_cons (NULL_TREE, build_int_2 (base_cnt, 0), NULL_TREE)))))); + + return build_generic_desc (tdecl, __class_desc_type_node, elems); +} + +/* Build an initializer for a __pointer_type_info node. */ +static tree +build_ptr_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree t, elems; + + t = TREE_TYPE (type); + t = build_t_desc (t, 1); + t = build_indirect_ref (t, NULL); + elems = tree_cons (NULL_TREE, t, NULL_TREE); + return build_generic_desc (tdecl, __ptr_desc_type_node, elems); +} + +/* Build an initializer for a __attr_type_info node. */ +static tree +build_attr_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree elems, t, attrval; + + if (TYPE_READONLY (type)) + { + if (TYPE_VOLATILE (type)) + attrval = lookup_field (__attr_desc_type_node, + get_identifier("_RTTI_ATTR_CONSTVOL"), 0, 0); + else + attrval = lookup_field (__attr_desc_type_node, + get_identifier("_RTTI_ATTR_CONST"), 0, 0); + } + else + { + if (TYPE_VOLATILE (type)) + attrval = lookup_field (__attr_desc_type_node, + get_identifier("_RTTI_ATTR_VOLATILE"), 0, 0); + } + t = build_t_desc (TYPE_MAIN_VARIANT (type), 1); + t = build_indirect_ref (t , NULL); + elems = tree_cons (NULL_TREE, attrval, tree_cons (NULL_TREE, t, NULL_TREE)); + return build_generic_desc (tdecl, __attr_desc_type_node, elems); +} + +/* Build an initializer for a __func_type_info node. */ +static tree +build_func_desc (tdecl) + tree tdecl; +{ + tree elems, name_string; + tree tname = DECL_NAME (tdecl); + + name_string = combine_strings (build_string + (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname))); + elems = name_string; + return build_generic_desc (tdecl, __func_desc_type_node, elems); +} + +/* Build an initializer for a __ptmf_type_info node. */ +static tree +build_ptmf_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree elems, name_string; + tree tname = DECL_NAME (tdecl); + + name_string = combine_strings (build_string + (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname))); + elems = name_string; + return build_generic_desc (tdecl, __ptmf_desc_type_node, elems); +} + +/* Build an initializer for a __ptmd_type_info node. */ +static tree +build_ptmd_desc (tdecl, type) + tree tdecl; + tree type; +{ + tree tc, t, elems; + tc = build_t_desc (TYPE_OFFSET_BASETYPE (type), 1); + tc = build_indirect_ref (tc , NULL); + t = build_t_desc (TREE_TYPE (type), 1); + t = build_indirect_ref (t , NULL); + elems = tree_cons (NULL_TREE, tc, + tree_cons (NULL_TREE, t, NULL_TREE)); + return build_generic_desc (tdecl, __ptmd_desc_type_node, elems); +} + +struct uninst_st { + tree type; + struct uninst_st *next; +}; +typedef struct uninst_st uninst_node; +static uninst_node * uninst_desc = (uninst_node *)NULL; + +static void +add_uninstantiated_desc (type) + tree type; +{ + uninst_node *t; + + t = (uninst_node *) xmalloc (sizeof (struct uninst_st)); + t->type = type; + t->next = uninst_desc; + uninst_desc = t; +} + +/* We may choose to link the emitting of certain high use TDs for certain + objects, we do that here. Return the type to link against if such a + link exists, otherwise just return TYPE. */ + +tree +get_def_to_follow (type) + tree type; +{ +#if 0 + /* For now we don't lay out T&, T* TDs with the main TD for the object. */ + /* Let T* and T& be written only when T is written (if T is an aggr). + We do this for const, but not for volatile, since volatile + is rare and const is not. */ + if (!TYPE_VOLATILE (taggr) + && (TREE_CODE (taggr) == POINTER_TYPE + || TREE_CODE (taggr) == REFERENCE_TYPE) + && IS_AGGR_TYPE (TREE_TYPE (taggr))) + taggr = TREE_TYPE (taggr); +#endif + return type; +} + +/* build a general type_info node. */ +tree +build_t_desc (type, definition) + tree type; + int definition; +{ + tree tdecl; + tree tname, name_string; + tree elems; + tree t, tt, taggr; + + if (__ptmd_desc_type_node == NULL_TREE) + { + init_type_desc(); + if (__ptmd_desc_type_node) + { + for ( ; uninst_desc; uninst_desc = uninst_desc->next ) + build_t_desc (uninst_desc->type, 1); + } + } + if (__t_desc_type_node == NULL_TREE) + { + static int warned = 0; + if (! warned) + { + cp_error ("failed to build type descriptor node of '%T', maybe typeinfo.h not included", type); + } + warned = 1; + return error_mark_node; + } + if (__ptmd_desc_type_node == NULL_TREE) + { + add_uninstantiated_desc (type); + definition = 0; + } + + push_obstacks (&permanent_obstack, &permanent_obstack); + tname = build_t_desc_overload (type); + + if (!IDENTIFIER_AS_DESC (tname)) + { + tdecl = build_decl (VAR_DECL, tname, __t_desc_type_node); + DECL_EXTERNAL (tdecl) = 1; + TREE_PUBLIC (tdecl) = 1; + tdecl = pushdecl_top_level (tdecl); + SET_IDENTIFIER_AS_DESC (tname, build_unary_op (ADDR_EXPR, tdecl, 0)); + if (!definition) + cp_finish_decl (tdecl, NULL_TREE, NULL_TREE, 0, 0); + } + else + tdecl = TREE_OPERAND (IDENTIFIER_AS_DESC (tname), 0); + + /* If it's not a definition, don't do anything more. */ + if (!definition) + return IDENTIFIER_AS_DESC (tname); + + /* If it has already been written, don't to anything more. */ + /* Should this be on tdecl? */ + if (TREE_ASM_WRITTEN (IDENTIFIER_AS_DESC (tname))) + return IDENTIFIER_AS_DESC (tname); + + /* If we previously defined it, return the defined result. */ + if (DECL_INITIAL (tdecl)) + return IDENTIFIER_AS_DESC (tname); + + taggr = get_def_to_follow (type); + + /* If we know that we don't need to write out this type's + vtable, then don't write out it's type_info. Somebody + else will take care of that. */ + if (IS_AGGR_TYPE (taggr) && CLASSTYPE_VFIELD (taggr)) + { + /* Let's play follow the vtable. */ + TREE_PUBLIC (tdecl) = CLASSTYPE_INTERFACE_KNOWN (taggr); + DECL_EXTERNAL (tdecl) = CLASSTYPE_INTERFACE_ONLY (taggr); + } + else + { + DECL_EXTERNAL (tdecl) = 0; + TREE_PUBLIC (tdecl) = (definition > 1); + } + + if (DECL_EXTERNAL (tdecl)) + return IDENTIFIER_AS_DESC (tname); + + /* Show that we are defining the t_desc for this type. */ + DECL_INITIAL (tdecl) = error_mark_node; + t = DECL_CONTEXT (tdecl); + if ( t && TREE_CODE_CLASS (TREE_CODE (t)) == 't') + pushclass (t, 2); + + if (TYPE_VOLATILE (type) || TYPE_READONLY (type)) + t = build_attr_desc (tdecl, type); + else if (TREE_CODE (type) == ARRAY_TYPE) + t = build_ptr_desc (tdecl, type); + else if (TREE_CODE (type) == POINTER_TYPE) + { + if (TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE) + { + type = TREE_TYPE (type); + t = build_ptmd_desc (tdecl, type); + } + else + { + t = build_ptr_desc (tdecl, type); + } + } + else if (TYPE_BUILT_IN (type)) + t = build_bltn_desc (tdecl, type); + else if (IS_AGGR_TYPE (type)) + { + if (TYPE_PTRMEMFUNC_P (type)) + { + t = build_ptmf_desc (tdecl, type); + } + else + { + t = build_class_desc (tdecl, type); + } + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + t = build_func_desc (tdecl); + else + t = build_user_desc (tdecl); + + pop_obstacks (); + return t; +} + +#if 0 +/* This is the old dossier type descriptor generation code, it's much + more extended than rtti. It's reserved for later use. */ +/* Build an initializer for a __t_desc node. So that we can take advantage + of recursion, we accept NULL for TYPE. + DEFINITION is greater than zero iff we must define the type descriptor + (as opposed to merely referencing it). 1 means treat according to + #pragma interface/#pragma implementation rules. 2 means define as + global and public, no matter what. */ +tree +build_t_desc (type, definition) + tree type; + int definition; +{ + tree tdecl; + tree tname, name_string; + tree elems, fields; + tree parents, vbases, offsets, ivars, methods, target_type; + int method_count = 0, field_count = 0; + + if (type == NULL_TREE) + return NULL_TREE; + + tname = build_t_desc_overload (type); + if (IDENTIFIER_AS_DESC (tname) + && (!definition || TREE_ASM_WRITTEN (IDENTIFIER_AS_DESC (tname)))) + return IDENTIFIER_AS_DESC (tname); + + tdecl = lookup_name (tname, 0); + if (tdecl == NULL_TREE) + { + tdecl = build_decl (VAR_DECL, tname, __t_desc_type_node); + DECL_EXTERNAL (tdecl) = 1; + TREE_PUBLIC (tdecl) = 1; + tdecl = pushdecl_top_level (tdecl); + } + /* If we previously defined it, return the defined result. */ + else if (definition && DECL_INITIAL (tdecl)) + return IDENTIFIER_AS_DESC (tname); + + if (definition) + { + tree taggr = type; + /* Let T* and T& be written only when T is written (if T is an aggr). + We do this for const, but not for volatile, since volatile + is rare and const is not. */ + if (!TYPE_VOLATILE (taggr) + && (TREE_CODE (taggr) == POINTER_TYPE + || TREE_CODE (taggr) == REFERENCE_TYPE) + && IS_AGGR_TYPE (TREE_TYPE (taggr))) + taggr = TREE_TYPE (taggr); + + /* If we know that we don't need to write out this type's + vtable, then don't write out it's dossier. Somebody + else will take care of that. */ + if (IS_AGGR_TYPE (taggr) && CLASSTYPE_VFIELD (taggr)) + { + if (CLASSTYPE_VTABLE_NEEDS_WRITING (taggr)) + { + TREE_PUBLIC (tdecl) = ! CLASSTYPE_INTERFACE_ONLY (taggr) + && CLASSTYPE_INTERFACE_KNOWN (taggr); + DECL_EXTERNAL (tdecl) = 0; + } + else + { + if (write_virtuals != 0) + TREE_PUBLIC (tdecl) = 1; + } + } + else + { + DECL_EXTERNAL (tdecl) = 0; + TREE_PUBLIC (tdecl) = (definition > 1); + } + } + SET_IDENTIFIER_AS_DESC (tname, build_unary_op (ADDR_EXPR, tdecl, 0)); + + if (!definition || DECL_EXTERNAL (tdecl)) + { + /* That's it! */ + cp_finish_decl (tdecl, NULL_TREE, NULL_TREE, 0, 0); + return IDENTIFIER_AS_DESC (tname); + } + + /* Show that we are defining the t_desc for this type. */ + DECL_INITIAL (tdecl) = error_mark_node; + + parents = build_tree_list (NULL_TREE, integer_zero_node); + vbases = build_tree_list (NULL_TREE, integer_zero_node); + offsets = build_tree_list (NULL_TREE, integer_zero_node); + methods = NULL_TREE; + ivars = NULL_TREE; + + if (TYPE_LANG_SPECIFIC (type)) + { + int i = CLASSTYPE_N_BASECLASSES (type); + tree method_vec = CLASSTYPE_METHOD_VEC (type); + tree *meth, *end; + tree binfos = TYPE_BINFO_BASETYPES (type); + tree vb = CLASSTYPE_VBASECLASSES (type); + + while (--i >= 0) + parents = tree_cons (NULL_TREE, build_t_desc (BINFO_TYPE (TREE_VEC_ELT (binfos, i)), 0), parents); + + while (vb) + { + vbases = tree_cons (NULL_TREE, build_t_desc (BINFO_TYPE (vb), 0), vbases); + offsets = tree_cons (NULL_TREE, BINFO_OFFSET (vb), offsets); + vb = TREE_CHAIN (vb); + } + + if (method_vec) + for (meth = TREE_VEC_END (method_vec), + end = &TREE_VEC_ELT (method_vec, 0); meth-- != end; ) + if (*meth) + { + methods = tree_cons (NULL_TREE, build_m_desc (*meth), methods); + method_count++; + } + } + + if (IS_AGGR_TYPE (type)) + { + for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) + if (TREE_CODE (fields) == FIELD_DECL + || TREE_CODE (fields) == VAR_DECL) + { + ivars = tree_cons (NULL_TREE, build_i_desc (fields), ivars); + field_count++; + } + ivars = nreverse (ivars); + } + + parents = finish_table (NULL_TREE, build_pointer_type (__t_desc_type_node), parents, 0); + vbases = finish_table (NULL_TREE, build_pointer_type (__t_desc_type_node), vbases, 0); + offsets = finish_table (NULL_TREE, integer_type_node, offsets, 0); + if (methods == NULL_TREE) + methods = null_pointer_node; + else + methods = build_unary_op (ADDR_EXPR, + finish_table (NULL_TREE, __m_desc_type_node, methods, 0), + 0); + if (ivars == NULL_TREE) + ivars = null_pointer_node; + else + ivars = build_unary_op (ADDR_EXPR, + finish_table (NULL_TREE, __i_desc_type_node, ivars, 0), + 0); + if (TREE_TYPE (type)) + target_type = build_t_desc (TREE_TYPE (type), definition); + else + target_type = integer_zero_node; + + name_string = combine_strings (build_string (IDENTIFIER_LENGTH (tname)+1, IDENTIFIER_POINTER (tname))); + + elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0), + tree_cons (NULL_TREE, + TYPE_SIZE(type)? size_in_bytes(type) : integer_zero_node, + /* really should use bitfield initialization here. */ + tree_cons (NULL_TREE, integer_zero_node, + tree_cons (NULL_TREE, target_type, + tree_cons (NULL_TREE, build_int_2 (field_count, 2), + tree_cons (NULL_TREE, build_int_2 (method_count, 2), + tree_cons (NULL_TREE, ivars, + tree_cons (NULL_TREE, methods, + tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, parents, 0), + tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, vbases, 0), + build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, offsets, 0)))))))))))); + return build_generic_desc (tdecl, elems); +} + +/* Build an initializer for a __i_desc node. */ +tree +build_i_desc (decl) + tree decl; +{ + tree elems, name_string; + tree taggr; + + name_string = DECL_NAME (decl); + name_string = combine_strings (build_string (IDENTIFIER_LENGTH (name_string)+1, IDENTIFIER_POINTER (name_string))); + + /* Now decide whether this ivar should cause it's type to get + def'd or ref'd in this file. If the type we are looking at + has a proxy definition, we look at the proxy (i.e., a + `foo *' is equivalent to a `foo'). */ + taggr = TREE_TYPE (decl); + + if ((TREE_CODE (taggr) == POINTER_TYPE + || TREE_CODE (taggr) == REFERENCE_TYPE) + && TYPE_VOLATILE (taggr) == 0) + taggr = TREE_TYPE (taggr); + + elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0), + tree_cons (NULL_TREE, DECL_FIELD_BITPOS (decl), + build_tree_list (NULL_TREE, build_t_desc (TREE_TYPE (decl), + ! IS_AGGR_TYPE (taggr))))); + taggr = build (CONSTRUCTOR, __i_desc_type_node, NULL_TREE, elems); + TREE_CONSTANT (taggr) = 1; + TREE_STATIC (taggr) = 1; + TREE_READONLY (taggr) = 1; + return taggr; +} + +/* Build an initializer for a __m_desc node. */ +tree +build_m_desc (decl) + tree decl; +{ + tree taggr, elems, name_string; + tree parm_count, req_count, vindex, vcontext; + tree parms; + int p_count, r_count; + tree parm_types = NULL_TREE; + + for (parms = TYPE_ARG_TYPES (TREE_TYPE (decl)), p_count = 0, r_count = 0; + parms != NULL_TREE; parms = TREE_CHAIN (parms), p_count++) + { + taggr = TREE_VALUE (parms); + if ((TREE_CODE (taggr) == POINTER_TYPE + || TREE_CODE (taggr) == REFERENCE_TYPE) + && TYPE_VOLATILE (taggr) == 0) + taggr = TREE_TYPE (taggr); + + parm_types = tree_cons (NULL_TREE, build_t_desc (TREE_VALUE (parms), + ! IS_AGGR_TYPE (taggr)), + parm_types); + if (TREE_PURPOSE (parms) == NULL_TREE) + r_count++; + } + + parm_types = finish_table (NULL_TREE, build_pointer_type (__t_desc_type_node), + nreverse (parm_types), 0); + parm_count = build_int_2 (p_count, 0); + req_count = build_int_2 (r_count, 0); + + if (DECL_VINDEX (decl)) + vindex = DECL_VINDEX (decl); + else + vindex = integer_zero_node; + if (DECL_CONTEXT (decl) + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') + vcontext = build_t_desc (DECL_CONTEXT (decl), 0); + else + vcontext = integer_zero_node; + name_string = DECL_NAME (decl); + if (name_string == NULL) + name_string = DECL_ASSEMBLER_NAME (decl); + name_string = combine_strings (build_string (IDENTIFIER_LENGTH (name_string)+1, IDENTIFIER_POINTER (name_string))); + + /* Now decide whether the return type of this mvar + should cause it's type to get def'd or ref'd in this file. + If the type we are looking at has a proxy definition, + we look at the proxy (i.e., a `foo *' is equivalent to a `foo'). */ + taggr = TREE_TYPE (TREE_TYPE (decl)); + + if ((TREE_CODE (taggr) == POINTER_TYPE + || TREE_CODE (taggr) == REFERENCE_TYPE) + && TYPE_VOLATILE (taggr) == 0) + taggr = TREE_TYPE (taggr); + + elems = tree_cons (NULL_TREE, build_unary_op (ADDR_EXPR, name_string, 0), + tree_cons (NULL_TREE, vindex, + tree_cons (NULL_TREE, vcontext, + tree_cons (NULL_TREE, build_t_desc (TREE_TYPE (TREE_TYPE (decl)), + ! IS_AGGR_TYPE (taggr)), + tree_cons (NULL_TREE, build_c_cast (build_pointer_type (default_function_type), build_unary_op (ADDR_EXPR, decl, 0), 0), + tree_cons (NULL_TREE, parm_count, + tree_cons (NULL_TREE, req_count, + build_tree_list (NULL_TREE, build_unary_op (ADDR_EXPR, parm_types, 0))))))))); + + taggr = build (CONSTRUCTOR, __m_desc_type_node, NULL_TREE, elems); + TREE_CONSTANT (taggr) = 1; + TREE_STATIC (taggr) = 1; + TREE_READONLY (taggr) = 1; + return taggr; +} +#endif /* dossier */ + + +/* Conditionally emit code to set up an unwind-protect for the + garbage collector. If this function doesn't do anything that involves + the garbage collector, then do nothing. Otherwise, call __gc_push + at the beginning and __gc_pop at the end. + + NOTE! The __gc_pop function must operate transparently, since + it comes where the logical return label lies. This means that + at runtime *it* must preserve any return value registers. */ + +void +expand_gc_prologue_and_epilogue () +{ + extern tree maybe_gc_cleanup; + struct rtx_def *last_parm_insn, *mark; + extern struct rtx_def *get_last_insn (); + extern struct rtx_def *get_first_nonparm_insn (); + extern struct rtx_def *previous_insn (); + tree action; + + /* If we didn't need the obstack, don't cons any space. */ + if (current_function_obstack_index == 0 + || current_function_obstack_usage == 0) + return; + + mark = get_last_insn (); + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == 0) last_parm_insn = mark; + else last_parm_insn = previous_insn (last_parm_insn); + + action = build_function_call (gc_push_fndecl, + build_tree_list (NULL_TREE, size_int (++current_function_obstack_index))); + expand_expr_stmt (action); + + reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); + + /* This will be expanded as a cleanup. */ + TREE_VALUE (maybe_gc_cleanup) + = build_function_call (gc_pop_fndecl, NULL_TREE); +} + +/* Some day we'll use this function as a call-back and clean + up all the unnecessary gc dribble that we otherwise create. */ +void +lang_expand_end_bindings (first, last) + struct rtx_def *first, *last; +{ +} + +void +init_gc_processing () +{ + tree parmtypes = hash_tree_chain (class_star_type_node, + hash_tree_chain (integer_type_node, NULL_TREE)); + gc_protect_fndecl = define_function ("__gc_protect", + build_function_type (class_star_type_node, parmtypes), + NOT_BUILT_IN, 0, 0); + + parmtypes = hash_tree_chain (integer_type_node, NULL_TREE); + gc_unprotect_fndecl = define_function ("__gc_unprotect", + build_function_type (void_type_node, parmtypes), + NOT_BUILT_IN, 0, 0); + + gc_push_fndecl = define_function ("__gc_push", + TREE_TYPE (gc_unprotect_fndecl), + NOT_BUILT_IN, 0, 0); + + gc_pop_fndecl = define_function ("__gc_pop", + build_function_type (void_type_node, + void_list_node), + NOT_BUILT_IN, 0, 0); + gc_nonobject = build_int_2 (0x80000000, 0); + gc_visible = build_int_2 (0x40000000, 0); + gc_white = integer_zero_node; + gc_offwhite = build_int_2 (0x10000000, 0); + gc_grey = build_int_2 (0x20000000, 0); + gc_black = build_int_2 (0x30000000, 0); +} diff --git a/contrib/gcc/cp/gpcompare.texi b/contrib/gcc/cp/gpcompare.texi new file mode 100644 index 00000000000..7b0d573105b --- /dev/null +++ b/contrib/gcc/cp/gpcompare.texi @@ -0,0 +1,236 @@ +@node ANSI +@chapter @sc{gnu} C++ Conformance to @sc{ansi} C++ + +These changes in the @sc{gnu} C++ compiler were made to comply more +closely with the @sc{ansi} base document, @cite{The Annotated C++ +Reference Manual} (the @sc{arm}). Further reducing the divergences from +@sc{ansi} C++ is a continued goal of the @sc{gnu} C++ Renovation +Project. + +@b{Section 3.4}, @i{Start and Termination}. It is now invalid to take +the address of the function @samp{main()}. + +@b{Section 4.8}, @i{Pointers to Members}. The compiler produces +an error for trying to convert between a pointer to a member and the type +@samp{void *}. + +@b{Section 5.2.5}, @i{Increment and Decrement}. It is an error to use +the increment and decrement operators on an enumerated type. + +@b{Section 5.3.2}, @i{Sizeof}. Doing @code{sizeof} on a function is now +an error. + +@b{Section 5.3.4}, @i{Delete}. The syntax of a @i{cast-expression} is +now more strictly controlled. + +@b{Section 7.1.1}, @i{Storage Class Specifiers}. Using the +@code{static} and @code{extern} specifiers can now only be applied to +names of objects, functions, and anonymous unions. + +@b{Section 7.1.1}, @i{Storage Class Specifiers}. The compiler no longer complains +about taking the address of a variable which has been declared to have @code{register} +storage. + +@b{Section 7.1.2}, @i{Function Specifiers}. The compiler produces an +error when the @code{inline} or @code{virtual} specifiers are +used on anything other than a function. + +@b{Section 8.3}, @i{Function Definitions}. It is now an error to shadow +a parameter name with a local variable; in the past, the compiler only +gave a warning in such a situation. + +@b{Section 8.4.1}, @i{Aggregates}. The rules concerning declaration of +an aggregate are now all checked in the @sc{gnu} C++ compiler; they +include having no private or protected members and no base classes. + +@b{Section 8.4.3}, @i{References}. Declaring an array of references is +now forbidden. Initializing a reference with an initializer list is +also considered an error. + +@b{Section 9.5}, @i{Unions}. Global anonymous unions must be declared +@code{static}. + +@b{Section 11.4}, @i{Friends}. Declaring a member to be a friend of a +type that has not yet been defined is an error. + +@b{Section 12.1}, @i{Constructors}. The compiler generates a +default copy constructor for a class if no constructor has been declared. + +@ignore +@b{Section 12.4}, @i{Destructors}. In accordance with the @sc{ansi} C++ +draft standard working paper, a pure virtual destructor must now be +defined. +@end ignore + +@b{Section 12.6.2}, @i{Special Member Functions}. When using a +@i{mem-initializer} list, the compiler will now initialize class members +in declaration order, not in the order in which you specify them. +Also, the compiler enforces the rule that non-static @code{const} +and reference members must be initialized with a @i{mem-initializer} +list when their class does not have a constructor. + +@b{Section 12.8}, @i{Copying Class Objects}. The compiler generates +default copy constructors correctly, and supplies default assignment +operators compatible with user-defined ones. + +@b{Section 13.4}, @i{Overloaded Operators}. An overloaded operator may +no longer have default arguments. + +@b{Section 13.4.4}, @i{Function Call}. An overloaded @samp{operator ()} +must be a non-static member function. + +@b{Section 13.4.5}, @i{Subscripting}. An overloaded @samp{operator []} +must be a non-static member function. + +@b{Section 13.4.6}, @i{Class Member Access}. An overloaded @samp{operator ->} +must be a non-static member function. + +@b{Section 13.4.7}, @i{Increment and Decrement}. The compiler will now +make sure a postfix @samp{@w{operator ++}} or @samp{@w{operator --}} has an +@code{int} as its second argument. + + +@node Encoding +@chapter Name Encoding in @sc{gnu} C++ + +@c FIXME!! rewrite name encoding section +@c ...to give complete rules rather than diffs from ARM. +@c To avoid plagiarism, invent some different way of structuring the +@c description of the rules than what ARM uses. + +@cindex mangling +@cindex name encoding +@cindex encoding information in names +In order to support its strong typing rules and the ability to provide +function overloading, the C++ programming language @dfn{encodes} +information about functions and objects, so that conflicts across object +files can be detected during linking. @footnote{This encoding is also +sometimes called, whimsically enough, @dfn{mangling}; the corresponding +decoding is sometimes called @dfn{demangling}.} These rules tend to be +unique to each individual implementation of C++. + +The scheme detailed in the commentary for 7.2.1 of @cite{The Annotated +Reference Manual} offers a description of a possible implementation +which happens to closely resemble the @code{cfront} compiler. The +design used in @sc{gnu} C++ differs from this model in a number of ways: + +@itemize @bullet +@item +In addition to the basic types @code{void}, @code{char}, @code{short}, +@code{int}, @code{long}, @code{float}, @code{double}, and @code{long +double}, @sc{gnu} C++ supports two additional types: @code{wchar_t}, the wide +character type, and @code{long long} (if the host supports it). The +encodings for these are @samp{w} and @samp{x} respectively. + +@item +According to the @sc{arm}, qualified names (e.g., @samp{foo::bar::baz}) are +encoded with a leading @samp{Q}. Followed by the number of +qualifications (in this case, three) and the respective names, this +might be encoded as @samp{Q33foo3bar3baz}. @sc{gnu} C++ adds a leading +underscore to the list, producing @samp{_Q33foo3bar3baz}. + +@item +The operator @samp{*=} is encoded as @samp{__aml}, not @samp{__amu}, to +match the normal @samp{*} operator, which is encoded as @samp{__ml}. + +@c XXX left out ->(), __wr +@item +In addition to the normal operators, @sc{gnu} C++ also offers the minimum and +maximum operators @samp{>?} and @samp{ +@c To: mrs@@charlie.secs.csun.edu +@c Cc: g++@@cygnus.com +@c Subject: Re: ARM and GNU C++ incompatabilities +@c +@c Along with that, we should probably describe how g++ differs from +@c cfront, in ways that the users will notice. (E.g., cfront supposedly +@c allows "free (new char[10])"; does g++? How do the template +@c implementations differ? "New" placement syntax?) +@c @end display +@c +@c XXX For next revision. +@c +@c GNU C++: +@c * supports expanding inline functions in many situations, +@c including those which have static objects, use `for' statements, +@c and other situations. Part of this versatility is due to is +@c ability to not always generate temporaries for assignments. +@c * deliberately allows divide by 0 and mod 0, since [according +@c to Wilson] there are actually situations where you'd like to allow +@c such things. Note on most systems it will cause some sort of trap +@c or bus error. Cfront considers it an error. +@c * does [appear to] support nested classes within templates. +@c * conversion functions among baseclasses are all usable by +@c a class that's derived from all of those bases. +@c * sizeof works even when the class is defined within its ()'s +@c * conditional expressions work with member fns and pointers to +@c members. +@c * can handle non-trivial declarations of variables within switch +@c statements. +@c +@c Cfront: diff --git a/contrib/gcc/cp/gxx.gperf b/contrib/gcc/cp/gxx.gperf new file mode 100644 index 00000000000..e5465e89b48 --- /dev/null +++ b/contrib/gcc/cp/gxx.gperf @@ -0,0 +1,102 @@ +%{ +/* Command-line: gperf -p -j1 -g -o -t -N is_reserved_word -k1,4,$,7 gplus.gperf */ +%} +struct resword { char *name; short token; enum rid rid;}; +%% +__alignof, ALIGNOF, NORID +__alignof__, ALIGNOF, NORID +__asm, GCC_ASM_KEYWORD, NORID +__asm__, GCC_ASM_KEYWORD, NORID +__attribute, ATTRIBUTE, NORID +__attribute__, ATTRIBUTE, NORID +__const, TYPE_QUAL, RID_CONST +__const__, TYPE_QUAL, RID_CONST +__extension__, EXTENSION, NORID +__inline, SCSPEC, RID_INLINE +__inline__, SCSPEC, RID_INLINE +__label__, LABEL, NORID +__signature__, AGGR, RID_SIGNATURE /* Extension */, +__signed, TYPESPEC, RID_SIGNED +__signed__, TYPESPEC, RID_SIGNED +__sigof__, SIGOF, NORID /* Extension */, +__typeof, TYPEOF, NORID +__typeof__, TYPEOF, NORID +__volatile, TYPE_QUAL, RID_VOLATILE +__volatile__, TYPE_QUAL, RID_VOLATILE +__wchar_t, TYPESPEC, RID_WCHAR /* Unique to ANSI C++ */, +asm, ASM_KEYWORD, NORID, +and, ANDAND, NORID, +and_eq, ASSIGN, NORID, +auto, SCSPEC, RID_AUTO, +bitand, '&', NORID, +bitor, '|', NORID, +bool, TYPESPEC, RID_BOOL, +break, BREAK, NORID, +case, CASE, NORID, +catch, CATCH, NORID, +char, TYPESPEC, RID_CHAR, +class, AGGR, RID_CLASS, +compl, '~', NORID, +const, TYPE_QUAL, RID_CONST, +const_cast, CONST_CAST, NORID, +continue, CONTINUE, NORID, +default, DEFAULT, NORID, +delete, DELETE, NORID, +do, DO, NORID, +double, TYPESPEC, RID_DOUBLE, +dynamic_cast, DYNAMIC_CAST, NORID, +else, ELSE, NORID, +enum, ENUM, NORID, +explicit, SCSPEC, RID_EXPLICIT, +extern, SCSPEC, RID_EXTERN, +false, CXX_FALSE, NORID, +float, TYPESPEC, RID_FLOAT, +for, FOR, NORID, +friend, SCSPEC, RID_FRIEND, +goto, GOTO, NORID, +if, IF, NORID, +inline, SCSPEC, RID_INLINE, +int, TYPESPEC, RID_INT, +long, TYPESPEC, RID_LONG, +mutable, SCSPEC, RID_MUTABLE, +namespace, NAMESPACE, NORID, +new, NEW, NORID, +not, '!', NORID, +not_eq, EQCOMPARE, NORID, +operator, OPERATOR, NORID, +or, OROR, NORID, +or_eq, ASSIGN, NORID, +overload, OVERLOAD, NORID, +private, VISSPEC, RID_PRIVATE, +protected, VISSPEC, RID_PROTECTED, +public, VISSPEC, RID_PUBLIC, +register, SCSPEC, RID_REGISTER, +reinterpret_cast, REINTERPRET_CAST, NORID, +return, RETURN, NORID, +short, TYPESPEC, RID_SHORT, +signature, AGGR, RID_SIGNATURE /* Extension */, +signed, TYPESPEC, RID_SIGNED, +sigof, SIGOF, NORID /* Extension */, +sizeof, SIZEOF, NORID, +static, SCSPEC, RID_STATIC, +static_cast, STATIC_CAST, NORID, +struct, AGGR, RID_RECORD, +switch, SWITCH, NORID, +template, TEMPLATE, RID_TEMPLATE, +this, THIS, NORID, +throw, THROW, NORID, +true, CXX_TRUE, NORID, +try, TRY, NORID, +typedef, SCSPEC, RID_TYPEDEF, +typename, TYPENAME_KEYWORD, NORID, +typeid, TYPEID, NORID, +typeof, TYPEOF, NORID, +union, AGGR, RID_UNION, +unsigned, TYPESPEC, RID_UNSIGNED, +using, USING, NORID, +virtual, SCSPEC, RID_VIRTUAL, +void, TYPESPEC, RID_VOID, +volatile, TYPE_QUAL, RID_VOLATILE, +while, WHILE, NORID, +xor, '^', NORID, +xor_eq, ASSIGN, NORID, diff --git a/contrib/gcc/cp/gxxint.texi b/contrib/gcc/cp/gxxint.texi new file mode 100644 index 00000000000..015a33c002c --- /dev/null +++ b/contrib/gcc/cp/gxxint.texi @@ -0,0 +1,1585 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename g++int.info +@settitle G++ internals +@setchapternewpage odd +@c %**end of header + +@node Top, Limitations of g++, (dir), (dir) +@chapter Internal Architecture of the Compiler + +This is meant to describe the C++ front-end for gcc in detail. +Questions and comments to mrs@@cygnus.com. + +@menu +* Limitations of g++:: +* Routines:: +* Implementation Specifics:: +* Glossary:: +* Macros:: +* Typical Behavior:: +* Coding Conventions:: +* Templates:: +* Access Control:: +* Error Reporting:: +* Parser:: +* Copying Objects:: +* Exception Handling:: +* Free Store:: +* Concept Index:: +@end menu + +@node Limitations of g++, Routines, Top, Top +@section Limitations of g++ + +@itemize @bullet +@item +Limitations on input source code: 240 nesting levels with the parser +stacksize (YYSTACKSIZE) set to 500 (the default), and requires around +16.4k swap space per nesting level. The parser needs about 2.09 * +number of nesting levels worth of stackspace. + +@cindex pushdecl_class_level +@item +I suspect there are other uses of pushdecl_class_level that do not call +set_identifier_type_value in tandem with the call to +pushdecl_class_level. It would seem to be an omission. + +@cindex access checking +@item +Access checking is unimplemented for nested types. + +@cindex @code{volatile} +@item +@code{volatile} is not implemented in general. + +@cindex pointers to members +@item +Pointers to members are only minimally supported, and there are places +where the grammar doesn't even properly accept them yet. + +@cindex multiple inheritance +@item +@code{this} will be wrong in virtual members functions defined in a +virtual base class, when they are overridden in a derived class, when +called via a non-left most object. + +An example would be: + +@example +extern "C" int printf(const char*, ...); +struct A @{ virtual void f() @{ @} @}; +struct B : virtual A @{ int b; B() : b(0) @{@} void f() @{ b++; @} @}; +struct C : B @{@}; +struct D : B @{@}; +struct E : C, D @{@}; +int main() +@{ + E e; + C& c = e; D& d = e; + c.f(); d.f(); + printf ("C::b = %d, D::b = %d\n", e.C::b, e.D::b); + return 0; +@} +@end example + +This will print out 2, 0, instead of 1,1. + +@end itemize + +@node Routines, Implementation Specifics, Limitations of g++, Top +@section Routines + +This section describes some of the routines used in the C++ front-end. + +@code{build_vtable} and @code{prepare_fresh_vtable} is used only within +the @file{cp-class.c} file, and only in @code{finish_struct} and +@code{modify_vtable_entries}. + +@code{build_vtable}, @code{prepare_fresh_vtable}, and +@code{finish_struct} are the only routines that set @code{DECL_VPARENT}. + +@code{finish_struct} can steal the virtual function table from parents, +this prohibits related_vslot from working. When finish_struct steals, +we know that + +@example +get_binfo (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (t)), t, 0) +@end example + +@noindent +will get the related binfo. + +@code{layout_basetypes} does something with the VIRTUALS. + +Supposedly (according to Tiemann) most of the breadth first searching +done, like in @code{get_base_distance} and in @code{get_binfo} was not +because of any design decision. I have since found out the at least one +part of the compiler needs the notion of depth first binfo searching, I +am going to try and convert the whole thing, it should just work. The +term left-most refers to the depth first left-most node. It uses +@code{MAIN_VARIANT == type} as the condition to get left-most, because +the things that have @code{BINFO_OFFSET}s of zero are shared and will +have themselves as their own @code{MAIN_VARIANT}s. The non-shared right +ones, are copies of the left-most one, hence if it is its own +@code{MAIN_VARIANT}, we know it IS a left-most one, if it is not, it is +a non-left-most one. + +@code{get_base_distance}'s path and distance matters in its use in: + +@itemize @bullet +@item +@code{prepare_fresh_vtable} (the code is probably wrong) +@item +@code{init_vfields} Depends upon distance probably in a safe way, +build_offset_ref might use partial paths to do further lookups, +hack_identifier is probably not properly checking access. + +@item +@code{get_first_matching_virtual} probably should check for +@code{get_base_distance} returning -2. + +@item +@code{resolve_offset_ref} should be called in a more deterministic +manner. Right now, it is called in some random contexts, like for +arguments at @code{build_method_call} time, @code{default_conversion} +time, @code{convert_arguments} time, @code{build_unary_op} time, +@code{build_c_cast} time, @code{build_modify_expr} time, +@code{convert_for_assignment} time, and +@code{convert_for_initialization} time. + +But, there are still more contexts it needs to be called in, one was the +ever simple: + +@example +if (obj.*pmi != 7) + @dots{} +@end example + +Seems that the problems were due to the fact that @code{TREE_TYPE} of +the @code{OFFSET_REF} was not a @code{OFFSET_TYPE}, but rather the type +of the referent (like @code{INTEGER_TYPE}). This problem was fixed by +changing @code{default_conversion} to check @code{TREE_CODE (x)}, +instead of only checking @code{TREE_CODE (TREE_TYPE (x))} to see if it +was @code{OFFSET_TYPE}. + +@end itemize + +@node Implementation Specifics, Glossary, Routines, Top +@section Implementation Specifics + +@itemize @bullet +@item Explicit Initialization + +The global list @code{current_member_init_list} contains the list of +mem-initializers specified in a constructor declaration. For example: + +@example +foo::foo() : a(1), b(2) @{@} +@end example + +@noindent +will initialize @samp{a} with 1 and @samp{b} with 2. +@code{expand_member_init} places each initialization (a with 1) on the +global list. Then, when the fndecl is being processed, +@code{emit_base_init} runs down the list, initializing them. It used to +be the case that g++ first ran down @code{current_member_init_list}, +then ran down the list of members initializing the ones that weren't +explicitly initialized. Things were rewritten to perform the +initializations in order of declaration in the class. So, for the above +example, @samp{a} and @samp{b} will be initialized in the order that +they were declared: + +@example +class foo @{ public: int b; int a; foo (); @}; +@end example + +@noindent +Thus, @samp{b} will be initialized with 2 first, then @samp{a} will be +initialized with 1, regardless of how they're listed in the mem-initializer. + +@item Argument Matching + +In early 1993, the argument matching scheme in @sc{gnu} C++ changed +significantly. The original code was completely replaced with a new +method that will, hopefully, be easier to understand and make fixing +specific cases much easier. + +The @samp{-fansi-overloading} option is used to enable the new code; at +some point in the future, it will become the default behavior of the +compiler. + +The file @file{cp-call.c} contains all of the new work, in the functions +@code{rank_for_overload}, @code{compute_harshness}, +@code{compute_conversion_costs}, and @code{ideal_candidate}. + +Instead of using obscure numerical values, the quality of an argument +match is now represented by clear, individual codes. The new data +structure @code{struct harshness} (it used to be an @code{unsigned} +number) contains: + +@enumerate a +@item the @samp{code} field, to signify what was involved in matching two +arguments; +@item the @samp{distance} field, used in situations where inheritance +decides which function should be called (one is ``closer'' than +another); +@item and the @samp{int_penalty} field, used by some codes as a tie-breaker. +@end enumerate + +The @samp{code} field is a number with a given bit set for each type of +code, OR'd together. The new codes are: + +@itemize @bullet +@item @code{EVIL_CODE} +The argument was not a permissible match. + +@item @code{CONST_CODE} +Currently, this is only used by @code{compute_conversion_costs}, to +distinguish when a non-@code{const} member function is called from a +@code{const} member function. + +@item @code{ELLIPSIS_CODE} +A match against an ellipsis @samp{...} is considered worse than all others. + +@item @code{USER_CODE} +Used for a match involving a user-defined conversion. + +@item @code{STD_CODE} +A match involving a standard conversion. + +@item @code{PROMO_CODE} +A match involving an integral promotion. For these, the +@code{int_penalty} field is used to handle the ARM's rule (XXX cite) +that a smaller @code{unsigned} type should promote to a @code{int}, not +to an @code{unsigned int}. + +@item @code{QUAL_CODE} +Used to mark use of qualifiers like @code{const} and @code{volatile}. + +@item @code{TRIVIAL_CODE} +Used for trivial conversions. The @samp{int_penalty} field is used by +@code{convert_harshness} to communicate further penalty information back +to @code{build_overload_call_real} when deciding which function should +be call. +@end itemize + +The functions @code{convert_to_aggr} and @code{build_method_call} use +@code{compute_conversion_costs} to rate each argument's suitability for +a given candidate function (that's how we get the list of candidates for +@code{ideal_candidate}). + +@end itemize + +@node Glossary, Macros, Implementation Specifics, Top +@section Glossary + +@table @r +@item binfo +The main data structure in the compiler used to represent the +inheritance relationships between classes. The data in the binfo can be +accessed by the BINFO_ accessor macros. + +@item vtable +@itemx virtual function table + +The virtual function table holds information used in virtual function +dispatching. In the compiler, they are usually referred to as vtables, +or vtbls. The first index is not used in the normal way, I believe it +is probably used for the virtual destructor. + +@item vfield + +vfields can be thought of as the base information needed to build +vtables. For every vtable that exists for a class, there is a vfield. +See also vtable and virtual function table pointer. When a type is used +as a base class to another type, the virtual function table for the +derived class can be based upon the vtable for the base class, just +extended to include the additional virtual methods declared in the +derived class. The virtual function table from a virtual base class is +never reused in a derived class. @code{is_normal} depends upon this. + +@item virtual function table pointer + +These are @code{FIELD_DECL}s that are pointer types that point to +vtables. See also vtable and vfield. +@end table + +@node Macros, Typical Behavior, Glossary, Top +@section Macros + +This section describes some of the macros used on trees. The list +should be alphabetical. Eventually all macros should be documented +here. There are some postscript drawings that can be used to better +understand from of the more complex data structures, contact Mike Stump +(@code{mrs@@cygnus.com}) for information about them. + +@table @code +@item BINFO_BASETYPES +A vector of additional binfos for the types inherited by this basetype. +The binfos are fully unshared (except for virtual bases, in which +case the binfo structure is shared). + + If this basetype describes type D as inherited in C, + and if the basetypes of D are E anf F, + then this vector contains binfos for inheritance of E and F by C. + +Has values of: + + TREE_VECs + + +@item BINFO_INHERITANCE_CHAIN +Temporarily used to represent specific inheritances. It usually points +to the binfo associated with the lesser derived type, but it can be +reversed by reverse_path. For example: + +@example + Z ZbY least derived + | + Y YbX + | + X Xb most derived + +TYPE_BINFO (X) == Xb +BINFO_INHERITANCE_CHAIN (Xb) == YbX +BINFO_INHERITANCE_CHAIN (Yb) == ZbY +BINFO_INHERITANCE_CHAIN (Zb) == 0 +@end example + +Not sure is the above is really true, get_base_distance has is point +towards the most derived type, opposite from above. + +Set by build_vbase_path, recursive_bounded_basetype_p, +get_base_distance, lookup_field, lookup_fnfields, and reverse_path. + +What things can this be used on: + + TREE_VECs that are binfos + + +@item BINFO_OFFSET +The offset where this basetype appears in its containing type. +BINFO_OFFSET slot holds the offset (in bytes) from the base of the +complete object to the base of the part of the object that is allocated +on behalf of this `type'. This is always 0 except when there is +multiple inheritance. + +Used on TREE_VEC_ELTs of the binfos BINFO_BASETYPES (...) for example. + + +@item BINFO_VIRTUALS +A unique list of functions for the virtual function table. See also +TYPE_BINFO_VIRTUALS. + +What things can this be used on: + + TREE_VECs that are binfos + + +@item BINFO_VTABLE +Used to find the VAR_DECL that is the virtual function table associated +with this binfo. See also TYPE_BINFO_VTABLE. To get the virtual +function table pointer, see CLASSTYPE_VFIELD. + +What things can this be used on: + + TREE_VECs that are binfos + +Has values of: + + VAR_DECLs that are virtual function tables + + +@item BLOCK_SUPERCONTEXT +In the outermost scope of each function, it points to the FUNCTION_DECL +node. It aids in better DWARF support of inline functions. + + +@item CLASSTYPE_TAGS +CLASSTYPE_TAGS is a linked (via TREE_CHAIN) list of member classes of a +class. TREE_PURPOSE is the name, TREE_VALUE is the type (pushclass scans +these and calls pushtag on them.) + +finish_struct scans these to produce TYPE_DECLs to add to the +TYPE_FIELDS of the type. + +It is expected that name found in the TREE_PURPOSE slot is unique, +resolve_scope_to_name is one such place that depends upon this +uniqueness. + + +@item CLASSTYPE_METHOD_VEC +The following is true after finish_struct has been called (on the +class?) but not before. Before finish_struct is called, things are +different to some extent. Contains a TREE_VEC of methods of the class. +The TREE_VEC_LENGTH is the number of differently named methods plus one +for the 0th entry. The 0th entry is always allocated, and reserved for +ctors and dtors. If there are none, TREE_VEC_ELT(N,0) == NULL_TREE. +Each entry of the TREE_VEC is a FUNCTION_DECL. For each FUNCTION_DECL, +there is a DECL_CHAIN slot. If the FUNCTION_DECL is the last one with a +given name, the DECL_CHAIN slot is NULL_TREE. Otherwise it is the next +method that has the same name (but a different signature). It would +seem that it is not true that because the DECL_CHAIN slot is used in +this way, we cannot call pushdecl to put the method in the global scope +(cause that would overwrite the TREE_CHAIN slot), because they use +different _CHAINs. finish_struct_methods setups up one version of the +TREE_CHAIN slots on the FUNCTION_DECLs. + +friends are kept in TREE_LISTs, so that there's no need to use their +TREE_CHAIN slot for anything. + +Has values of: + + TREE_VECs + + +@item CLASSTYPE_VFIELD +Seems to be in the process of being renamed TYPE_VFIELD. Use on types +to get the main virtual function table pointer. To get the virtual +function table use BINFO_VTABLE (TYPE_BINFO ()). + +Has values of: + + FIELD_DECLs that are virtual function table pointers + +What things can this be used on: + + RECORD_TYPEs + + +@item DECL_CLASS_CONTEXT +Identifies the context that the _DECL was found in. For virtual function +tables, it points to the type associated with the virtual function +table. See also DECL_CONTEXT, DECL_FIELD_CONTEXT and DECL_FCONTEXT. + +The difference between this and DECL_CONTEXT, is that for virtuals +functions like: + +@example +struct A +@{ + virtual int f (); +@}; + +struct B : A +@{ + int f (); +@}; + +DECL_CONTEXT (A::f) == A +DECL_CLASS_CONTEXT (A::f) == A + +DECL_CONTEXT (B::f) == A +DECL_CLASS_CONTEXT (B::f) == B +@end example + +Has values of: + + RECORD_TYPEs, or UNION_TYPEs + +What things can this be used on: + + TYPE_DECLs, _DECLs + + +@item DECL_CONTEXT +Identifies the context that the _DECL was found in. Can be used on +virtual function tables to find the type associated with the virtual +function table, but since they are FIELD_DECLs, DECL_FIELD_CONTEXT is a +better access method. Internally the same as DECL_FIELD_CONTEXT, so +don't us both. See also DECL_FIELD_CONTEXT, DECL_FCONTEXT and +DECL_CLASS_CONTEXT. + +Has values of: + + RECORD_TYPEs + + +What things can this be used on: + +@display +VAR_DECLs that are virtual function tables +_DECLs +@end display + + +@item DECL_FIELD_CONTEXT +Identifies the context that the FIELD_DECL was found in. Internally the +same as DECL_CONTEXT, so don't us both. See also DECL_CONTEXT, +DECL_FCONTEXT and DECL_CLASS_CONTEXT. + +Has values of: + + RECORD_TYPEs + +What things can this be used on: + +@display +FIELD_DECLs that are virtual function pointers +FIELD_DECLs +@end display + + +@item DECL_NESTED_TYPENAME +Holds the fully qualified type name. Example, Base::Derived. + +Has values of: + + IDENTIFIER_NODEs + +What things can this be used on: + + TYPE_DECLs + + +@item DECL_NAME + +Has values of: + +@display +0 for things that don't have names +IDENTIFIER_NODEs for TYPE_DECLs +@end display + +@item DECL_IGNORED_P +A bit that can be set to inform the debug information output routines in +the back-end that a certain _DECL node should be totally ignored. + +Used in cases where it is known that the debugging information will be +output in another file, or where a sub-type is known not to be needed +because the enclosing type is not needed. + +A compiler constructed virtual destructor in derived classes that do not +define an explicit destructor that was defined explicit in a base class +has this bit set as well. Also used on __FUNCTION__ and +__PRETTY_FUNCTION__ to mark they are ``compiler generated.'' c-decl and +c-lex.c both want DECL_IGNORED_P set for ``internally generated vars,'' +and ``user-invisible variable.'' + +Functions built by the C++ front-end such as default destructors, +virtual destructors and default constructors want to be marked that +they are compiler generated, but unsure why. + +Currently, it is used in an absolute way in the C++ front-end, as an +optimization, to tell the debug information output routines to not +generate debugging information that will be output by another separately +compiled file. + + +@item DECL_VIRTUAL_P +A flag used on FIELD_DECLs and VAR_DECLs. (Documentation in tree.h is +wrong.) Used in VAR_DECLs to indicate that the variable is a vtable. +It is also used in FIELD_DECLs for vtable pointers. + +What things can this be used on: + + FIELD_DECLs and VAR_DECLs + + +@item DECL_VPARENT +Used to point to the parent type of the vtable if there is one, else it +is just the type associated with the vtable. Because of the sharing of +virtual function tables that goes on, this slot is not very useful, and +is in fact, not used in the compiler at all. It can be removed. + +What things can this be used on: + + VAR_DECLs that are virtual function tables + +Has values of: + + RECORD_TYPEs maybe UNION_TYPEs + + +@item DECL_FCONTEXT +Used to find the first baseclass in which this FIELD_DECL is defined. +See also DECL_CONTEXT, DECL_FIELD_CONTEXT and DECL_CLASS_CONTEXT. + +How it is used: + + Used when writing out debugging information about vfield and + vbase decls. + +What things can this be used on: + + FIELD_DECLs that are virtual function pointers + FIELD_DECLs + + +@item DECL_REFERENCE_SLOT +Used to hold the initialize for the reference. + +What things can this be used on: + + PARM_DECLs and VAR_DECLs that have a reference type + + +@item DECL_VINDEX +Used for FUNCTION_DECLs in two different ways. Before the structure +containing the FUNCTION_DECL is laid out, DECL_VINDEX may point to a +FUNCTION_DECL in a base class which is the FUNCTION_DECL which this +FUNCTION_DECL will replace as a virtual function. When the class is +laid out, this pointer is changed to an INTEGER_CST node which is +suitable to find an index into the virtual function table. See +get_vtable_entry as to how one can find the right index into the virtual +function table. The first index 0, of a virtual function table it not +used in the normal way, so the first real index is 1. + +DECL_VINDEX may be a TREE_LIST, that would seem to be a list of +overridden FUNCTION_DECLs. add_virtual_function has code to deal with +this when it uses the variable base_fndecl_list, but it would seem that +somehow, it is possible for the TREE_LIST to pursist until method_call, +and it should not. + + +What things can this be used on: + + FUNCTION_DECLs + + +@item DECL_SOURCE_FILE +Identifies what source file a particular declaration was found in. + +Has values of: + + "" on TYPE_DECLs to mean the typedef is built in + + +@item DECL_SOURCE_LINE +Identifies what source line number in the source file the declaration +was found at. + +Has values of: + +@display +0 for an undefined label + +0 for TYPE_DECLs that are internally generated + +0 for FUNCTION_DECLs for functions generated by the compiler + (not yet, but should be) + +0 for ``magic'' arguments to functions, that the user has no + control over +@end display + + +@item TREE_USED + +Has values of: + + 0 for unused labels + + +@item TREE_ADDRESSABLE +A flag that is set for any type that has a constructor. + + +@item TREE_COMPLEXITY +They seem a kludge way to track recursion, poping, and pushing. They only +appear in cp-decl.c and cp-decl2.c, so the are a good candidate for +proper fixing, and removal. + + +@item TREE_PRIVATE +Set for FIELD_DECLs by finish_struct. But not uniformly set. + +The following routines do something with PRIVATE access: +build_method_call, alter_access, finish_struct_methods, +finish_struct, convert_to_aggr, CWriteLanguageDecl, CWriteLanguageType, +CWriteUseObject, compute_access, lookup_field, dfs_pushdecl, +GNU_xref_member, dbxout_type_fields, dbxout_type_method_1 + + +@item TREE_PROTECTED +The following routines do something with PROTECTED access: +build_method_call, alter_access, finish_struct, convert_to_aggr, +CWriteLanguageDecl, CWriteLanguageType, CWriteUseObject, +compute_access, lookup_field, GNU_xref_member, dbxout_type_fields, +dbxout_type_method_1 + + +@item TYPE_BINFO +Used to get the binfo for the type. + +Has values of: + + TREE_VECs that are binfos + +What things can this be used on: + + RECORD_TYPEs + + +@item TYPE_BINFO_BASETYPES +See also BINFO_BASETYPES. + +@item TYPE_BINFO_VIRTUALS +A unique list of functions for the virtual function table. See also +BINFO_VIRTUALS. + +What things can this be used on: + + RECORD_TYPEs + + +@item TYPE_BINFO_VTABLE +Points to the virtual function table associated with the given type. +See also BINFO_VTABLE. + +What things can this be used on: + + RECORD_TYPEs + +Has values of: + + VAR_DECLs that are virtual function tables + + +@item TYPE_NAME +Names the type. + +Has values of: + +@display +0 for things that don't have names. +should be IDENTIFIER_NODE for RECORD_TYPEs UNION_TYPEs and + ENUM_TYPEs. +TYPE_DECL for RECORD_TYPEs, UNION_TYPEs and ENUM_TYPEs, but + shouldn't be. +TYPE_DECL for typedefs, unsure why. +@end display + +What things can one use this on: + +@display +TYPE_DECLs +RECORD_TYPEs +UNION_TYPEs +ENUM_TYPEs +@end display + +History: + + It currently points to the TYPE_DECL for RECORD_TYPEs, + UNION_TYPEs and ENUM_TYPEs, but it should be history soon. + + +@item TYPE_METHODS +Synonym for @code{CLASSTYPE_METHOD_VEC}. Chained together with +@code{TREE_CHAIN}. @file{dbxout.c} uses this to get at the methods of a +class. + + +@item TYPE_DECL +Used to represent typedefs, and used to represent bindings layers. + +Components: + + DECL_NAME is the name of the typedef. For example, foo would + be found in the DECL_NAME slot when @code{typedef int foo;} is + seen. + + DECL_SOURCE_LINE identifies what source line number in the + source file the declaration was found at. A value of 0 + indicates that this TYPE_DECL is just an internal binding layer + marker, and does not correspond to a user supplied typedef. + + DECL_SOURCE_FILE + +@item TYPE_FIELDS +A linked list (via @code{TREE_CHAIN}) of member types of a class. The +list can contain @code{TYPE_DECL}s, but there can also be other things +in the list apparently. See also @code{CLASSTYPE_TAGS}. + + +@item TYPE_VIRTUAL_P +A flag used on a @code{FIELD_DECL} or a @code{VAR_DECL}, indicates it is +a virtual function table or a pointer to one. When used on a +@code{FUNCTION_DECL}, indicates that it is a virtual function. When +used on an @code{IDENTIFIER_NODE}, indicates that a function with this +same name exists and has been declared virtual. + +When used on types, it indicates that the type has virtual functions, or +is derived from one that does. + +Not sure if the above about virtual function tables is still true. See +also info on @code{DECL_VIRTUAL_P}. + +What things can this be used on: + + FIELD_DECLs, VAR_DECLs, FUNCTION_DECLs, IDENTIFIER_NODEs + + +@item VF_BASETYPE_VALUE +Get the associated type from the binfo that caused the given vfield to +exist. This is the least derived class (the most parent class) that +needed a virtual function table. It is probably the case that all uses +of this field are misguided, but they need to be examined on a +case-by-case basis. See history for more information on why the +previous statement was made. + +Set at @code{finish_base_struct} time. + +What things can this be used on: + + TREE_LISTs that are vfields + +History: + + This field was used to determine if a virtual function table's + slot should be filled in with a certain virtual function, by + checking to see if the type returned by VF_BASETYPE_VALUE was a + parent of the context in which the old virtual function existed. + This incorrectly assumes that a given type _could_ not appear as + a parent twice in a given inheritance lattice. For single + inheritance, this would in fact work, because a type could not + possibly appear more than once in an inheritance lattice, but + with multiple inheritance, a type can appear more than once. + + +@item VF_BINFO_VALUE +Identifies the binfo that caused this vfield to exist. If this vfield +is from the first direct base class that has a virtual function table, +then VF_BINFO_VALUE is NULL_TREE, otherwise it will be the binfo of the +direct base where the vfield came from. Can use @code{TREE_VIA_VIRTUAL} +on result to find out if it is a virtual base class. Related to the +binfo found by + +@example +get_binfo (VF_BASETYPE_VALUE (vfield), t, 0) +@end example + +@noindent +where @samp{t} is the type that has the given vfield. + +@example +get_binfo (VF_BASETYPE_VALUE (vfield), t, 0) +@end example + +@noindent +will return the binfo for the the given vfield. + +May or may not be set at @code{modify_vtable_entries} time. Set at +@code{finish_base_struct} time. + +What things can this be used on: + + TREE_LISTs that are vfields + + +@item VF_DERIVED_VALUE +Identifies the type of the most derived class of the vfield, excluding +the the class this vfield is for. + +Set at @code{finish_base_struct} time. + +What things can this be used on: + + TREE_LISTs that are vfields + + +@item VF_NORMAL_VALUE +Identifies the type of the most derived class of the vfield, including +the class this vfield is for. + +Set at @code{finish_base_struct} time. + +What things can this be used on: + + TREE_LISTs that are vfields + + +@item WRITABLE_VTABLES +This is a option that can be defined when building the compiler, that +will cause the compiler to output vtables into the data segment so that +the vtables maybe written. This is undefined by default, because +normally the vtables should be unwritable. People that implement object +I/O facilities may, or people that want to change the dynamic type of +objects may want to have the vtables writable. Another way of achieving +this would be to make a copy of the vtable into writable memory, but the +drawback there is that that method only changes the type for one object. + +@end table + +@node Typical Behavior, Coding Conventions, Macros, Top +@section Typical Behavior + +@cindex parse errors + +Whenever seemingly normal code fails with errors like +@code{syntax error at `\@{'}, it's highly likely that grokdeclarator is +returning a NULL_TREE for whatever reason. + +@node Coding Conventions, Templates, Typical Behavior, Top +@section Coding Conventions + +It should never be that case that trees are modified in-place by the +back-end, @emph{unless} it is guaranteed that the semantics are the same +no matter how shared the tree structure is. @file{fold-const.c} still +has some cases where this is not true, but rms hypothesizes that this +will never be a problem. + +@node Templates, Access Control, Coding Conventions, Top +@section Templates + +A template is represented by a @code{TEMPLATE_DECL}. The specific +fields used are: + +@table @code +@item DECL_TEMPLATE_RESULT +The generic decl on which instantiations are based. This looks just +like any other decl. + +@item DECL_TEMPLATE_PARMS +The parameters to this template. +@end table + +The generic decl is parsed as much like any other decl as possible, +given the parameterization. The template decl is not built up until the +generic decl has been completed. For template classes, a template decl +is generated for each member function and static data member, as well. + +Template members of template classes are represented by a TEMPLATE_DECL +for the class' parameters around another TEMPLATE_DECL for the member's +parameters. + +All declarations that are instantiations or specializations of templates +refer to their template and parameters through DECL_TEMPLATE_INFO. + +How should I handle parsing member functions with the proper param +decls? Set them up again or try to use the same ones? Currently we do +the former. We can probably do this without any extra machinery in +store_pending_inline, by deducing the parameters from the decl in +do_pending_inlines. PRE_PARSED_TEMPLATE_DECL? + +If a base is a parm, we can't check anything about it. If a base is not +a parm, we need to check it for name binding. Do finish_base_struct if +no bases are parameterized (only if none, including indirect, are +parms). Nah, don't bother trying to do any of this until instantiation +-- we only need to do name binding in advance. + +Always set up method vec and fields, inc. synthesized methods. Really? +We can't know the types of the copy folks, or whether we need a +destructor, or can have a default ctor, until we know our bases and +fields. Otherwise, we can assume and fix ourselves later. Hopefully. + +@node Access Control, Error Reporting, Templates, Top +@section Access Control +The function compute_access returns one of three values: + +@table @code +@item access_public +means that the field can be accessed by the current lexical scope. + +@item access_protected +means that the field cannot be accessed by the current lexical scope +because it is protected. + +@item access_private +means that the field cannot be accessed by the current lexical scope +because it is private. +@end table + +DECL_ACCESS is used for access declarations; alter_access creates a list +of types and accesses for a given decl. + +Formerly, DECL_@{PUBLIC,PROTECTED,PRIVATE@} corresponded to the return +codes of compute_access and were used as a cache for compute_access. +Now they are not used at all. + +TREE_PROTECTED and TREE_PRIVATE are used to record the access levels +granted by the containing class. BEWARE: TREE_PUBLIC means something +completely unrelated to access control! + +@node Error Reporting, Parser, Access Control, Top +@section Error Reporting + +The C++ front-end uses a call-back mechanism to allow functions to print +out reasonable strings for types and functions without putting extra +logic in the functions where errors are found. The interface is through +the @code{cp_error} function (or @code{cp_warning}, etc.). The +syntax is exactly like that of @code{error}, except that a few more +conversions are supported: + +@itemize @bullet +@item +%C indicates a value of `enum tree_code'. +@item +%D indicates a *_DECL node. +@item +%E indicates a *_EXPR node. +@item +%L indicates a value of `enum languages'. +@item +%P indicates the name of a parameter (i.e. "this", "1", "2", ...) +@item +%T indicates a *_TYPE node. +@item +%O indicates the name of an operator (MODIFY_EXPR -> "operator ="). + +@end itemize + +There is some overlap between these; for instance, any of the node +options can be used for printing an identifier (though only @code{%D} +tries to decipher function names). + +For a more verbose message (@code{class foo} as opposed to just @code{foo}, +including the return type for functions), use @code{%#c}. +To have the line number on the error message indicate the line of the +DECL, use @code{cp_error_at} and its ilk; to indicate which argument you want, +use @code{%+D}, or it will default to the first. + +@node Parser, Copying Objects, Error Reporting, Top +@section Parser + +Some comments on the parser: + +The @code{after_type_declarator} / @code{notype_declarator} hack is +necessary in order to allow redeclarations of @code{TYPENAME}s, for +instance + +@example +typedef int foo; +class A @{ + char *foo; +@}; +@end example + +In the above, the first @code{foo} is parsed as a @code{notype_declarator}, +and the second as a @code{after_type_declarator}. + +Ambiguities: + +There are currently four reduce/reduce ambiguities in the parser. They are: + +1) Between @code{template_parm} and +@code{named_class_head_sans_basetype}, for the tokens @code{aggr +identifier}. This situation occurs in code looking like + +@example +template class A @{ @}; +@end example + +It is ambiguous whether @code{class T} should be parsed as the +declaration of a template type parameter named @code{T} or an unnamed +constant parameter of type @code{class T}. Section 14.6, paragraph 3 of +the January '94 working paper states that the first interpretation is +the correct one. This ambiguity results in two reduce/reduce conflicts. + +2) Between @code{primary} and @code{type_id} for code like @samp{int()} +in places where both can be accepted, such as the argument to +@code{sizeof}. Section 8.1 of the pre-San Diego working paper specifies +that these ambiguous constructs will be interpreted as @code{typename}s. +This ambiguity results in six reduce/reduce conflicts between +@samp{absdcl} and @samp{functional_cast}. + +3) Between @code{functional_cast} and +@code{complex_direct_notype_declarator}, for various token strings. +This situation occurs in code looking like + +@example +int (*a); +@end example + +This code is ambiguous; it could be a declaration of the variable +@samp{a} as a pointer to @samp{int}, or it could be a functional cast of +@samp{*a} to @samp{int}. Section 6.8 specifies that the former +interpretation is correct. This ambiguity results in 7 reduce/reduce +conflicts. Another aspect of this ambiguity is code like 'int (x[2]);', +which is resolved at the '[' and accounts for 6 reduce/reduce conflicts +between @samp{direct_notype_declarator} and +@samp{primary}/@samp{overqualified_id}. Finally, there are 4 r/r +conflicts between @samp{expr_or_declarator} and @samp{primary} over code +like 'int (a);', which could probably be resolved but would also +probably be more trouble than it's worth. In all, this situation +accounts for 17 conflicts. Ack! + +The second case above is responsible for the failure to parse 'LinppFile +ppfile (String (argv[1]), &outs, argc, argv);' (from Rogue Wave +Math.h++) as an object declaration, and must be fixed so that it does +not resolve until later. + +4) Indirectly between @code{after_type_declarator} and @code{parm}, for +type names. This occurs in (as one example) code like + +@example +typedef int foo, bar; +class A @{ + foo (bar); +@}; +@end example + +What is @code{bar} inside the class definition? We currently interpret +it as a @code{parm}, as does Cfront, but IBM xlC interprets it as an +@code{after_type_declarator}. I believe that xlC is correct, in light +of 7.1p2, which says "The longest sequence of @i{decl-specifiers} that +could possibly be a type name is taken as the @i{decl-specifier-seq} of +a @i{declaration}." However, it seems clear that this rule must be +violated in the case of constructors. This ambiguity accounts for 8 +conflicts. + +Unlike the others, this ambiguity is not recognized by the Working Paper. + +@node Copying Objects, Exception Handling, Parser, Top +@section Copying Objects + +The generated copy assignment operator in g++ does not currently do the +right thing for multiple inheritance involving virtual bases; it just +calls the copy assignment operators for its direct bases. What it +should probably do is: + +1) Split up the copy assignment operator for all classes that have +vbases into "copy my vbases" and "copy everything else" parts. Or do +the trickiness that the constructors do to ensure that vbases don't get +initialized by intermediate bases. + +2) Wander through the class lattice, find all vbases for which no +intermediate base has a user-defined copy assignment operator, and call +their "copy everything else" routines. If not all of my vbases satisfy +this criterion, warn, because this may be surprising behavior. + +3) Call the "copy everything else" routine for my direct bases. + +If we only have one direct base, we can just foist everything off onto +them. + +This issue is currently under discussion in the core reflector +(2/28/94). + +@node Exception Handling, Free Store, Copying Objects, Top +@section Exception Handling + +Note, exception handling in g++ is still under development. + +This section describes the mapping of C++ exceptions in the C++ +front-end, into the back-end exception handling framework. + +The basic mechanism of exception handling in the back-end is +unwind-protect a la elisp. This is a general, robust, and language +independent representation for exceptions. + +The C++ front-end exceptions are mapping into the unwind-protect +semantics by the C++ front-end. The mapping is describe below. + +When -frtti is used, rtti is used to do exception object type checking, +when it isn't used, the encoded name for the type of the object being +thrown is used instead. All code that originates exceptions, even code +that throws exceptions as a side effect, like dynamic casting, and all +code that catches exceptions must be compiled with either -frtti, or +-fno-rtti. It is not possible to mix rtti base exception handling +objects with code that doesn't use rtti. The exceptions to this, are +code that doesn't catch or throw exceptions, catch (...), and code that +just rethrows an exception. + +Currently we use the normal mangling used in building functions names +(int's are "i", const char * is PCc) to build the non-rtti base type +descriptors for exception handling. These descriptors are just plain +NULL terminated strings, and internally they are passed around as char +*. + +In C++, all cleanups should be protected by exception regions. The +region starts just after the reason why the cleanup is created has +ended. For example, with an automatic variable, that has a constructor, +it would be right after the constructor is run. The region ends just +before the finalization is expanded. Since the backend may expand the +cleanup multiple times along different paths, once for normal end of the +region, once for non-local gotos, once for returns, etc, the backend +must take special care to protect the finalization expansion, if the +expansion is for any other reason than normal region end, and it is +`inline' (it is inside the exception region). The backend can either +choose to move them out of line, or it can created an exception region +over the finalization to protect it, and in the handler associated with +it, it would not run the finalization as it otherwise would have, but +rather just rethrow to the outer handler, careful to skip the normal +handler for the original region. + +In Ada, they will use the more runtime intensive approach of having +fewer regions, but at the cost of additional work at run time, to keep a +list of things that need cleanups. When a variable has finished +construction, they add the cleanup to the list, when the come to the end +of the lifetime of the variable, the run the list down. If the take a +hit before the section finishes normally, they examine the list for +actions to perform. I hope they add this logic into the back-end, as it +would be nice to get that alternative approach in C++. + +On an rs6000, xlC stores exception objects on that stack, under the try +block. When is unwinds down into a handler, the frame pointer is +adjusted back to the normal value for the frame in which the handler +resides, and the stack pointer is left unchanged from the time at which +the object was thrown. This is so that there is always someplace for +the exception object, and nothing can overwrite it, once we start +throwing. The only bad part, is that the stack remains large. + +The below points out some things that work in g++'s exception handling. + +All completely constructed temps and local variables are cleaned up in +all unwinded scopes. Completely constructed parts of partially +constructed objects are cleaned up. This includes partially built +arrays. Exception specifications are now handled. + +The below points out some flaws in g++'s exception handling, as it now +stands. + +Only exact type matching or reference matching of throw types works when +-fno-rtti is used. Only works on a SPARC (like Suns), i386, arm and +rs6000 machines. Partial support is in for all other machines, but a +stack unwinder called __unwind_function has to be written, and added to +libgcc2 for them. See below for details on __unwind_function. Don't +expect exception handling to work right if you optimize, in fact the +compiler will probably core dump. RTL_EXPRs for EH cond variables for +&& and || exprs should probably be wrapped in UNSAVE_EXPRs, and +RTL_EXPRs tweaked so that they can be unsaved, and the UNSAVE_EXPR code +should be in the backend, or alternatively, UNSAVE_EXPR should be ripped +out and exactly one finalization allowed to be expanded by the backend. +I talked with kenner about this, and we have to allow multiple +expansions. + +We only do pointer conversions on exception matching a la 15.3 p2 case +3: `A handler with type T, const T, T&, or const T& is a match for a +throw-expression with an object of type E if [3]T is a pointer type and +E is a pointer type that can be converted to T by a standard pointer +conversion (_conv.ptr_) not involving conversions to pointers to private +or protected base classes.' when -frtti is given. + +We don't call delete on new expressions that die because the ctor threw +an exception. See except/18 for a test case. + +15.2 para 13: The exception being handled should be rethrown if control +reaches the end of a handler of the function-try-block of a constructor +or destructor, right now, it is not. + +15.2 para 12: If a return statement appears in a handler of +function-try-block of a constructor, the program is ill-formed, but this +isn't diagnosed. + +15.2 para 11: If the handlers of a function-try-block contain a jump +into the body of a constructor or destructor, the program is ill-formed, +but this isn't diagnosed. + +15.2 para 9: Check that the fully constructed base classes and members +of an object are destroyed before entering the handler of a +function-try-block of a constructor or destructor for that object. + +build_exception_variant should sort the incoming list, so that it +implements set compares, not exact list equality. Type smashing should +smash exception specifications using set union. + +Thrown objects are usually allocated on the heap, in the usual way, but +they are never deleted. They should be deleted by the catch clauses. +If one runs out of heap space, throwing an object will probably never +work. This could be relaxed some by passing an __in_chrg parameter to +track who has control over the exception object. Thrown objects are not +allocated on the heap when they are pointer to object types. + +When the backend returns a value, it can create new exception regions +that need protecting. The new region should rethrow the object in +context of the last associated cleanup that ran to completion. + +The structure of the code that is generated for C++ exception handling +code is shown below: + +@example +Ln: throw value; + copy value onto heap + jump throw (Ln, id, address of copy of value on heap) + + try { ++Lstart: the start of the main EH region +|... ... ++Lend: the end of the main EH region + } catch (T o) { + ...1 + } +Lresume: + nop used to make sure there is something before + the next region ends, if there is one +... ... + + jump Ldone +[ +Lmainhandler: handler for the region Lstart-Lend + cleanup +] zero or more, depending upon automatic vars with dtors ++Lpartial: +| jump Lover ++Lhere: + rethrow (Lhere, same id, same obj); +Lterm: handler for the region Lpartial-Lhere + call terminate +Lover: +[ + [ + call throw_type_match + if (eq) { + ] these lines disappear when there is no catch condition ++Lsregion2: +| ...1 +| jump Lresume +|Lhandler: handler for the region Lsregion2-Leregion2 +| rethrow (Lresume, same id, same obj); ++Leregion2 + } +] there are zero or more of these sections, depending upon how many + catch clauses there are +----------------------------- expand_end_all_catch -------------------------- + here we have fallen off the end of all catch + clauses, so we rethrow to outer + rethrow (Lresume, same id, same obj); +----------------------------- expand_end_all_catch -------------------------- +[ +L1: maybe throw routine +] depending upon if we have expanded it or not +Ldone: + ret + +start_all_catch emits labels: Lresume, + +#end example + +The __unwind_function takes a pointer to the throw handler, and is +expected to pop the stack frame that was built to call it, as well as +the frame underneath and then jump to the throw handler. It must +restore all registers to their proper values as well as all other +machine state as determined by the context in which we are unwinding +into. The way I normally start is to compile: + + void *g; + foo(void* a) { g = a; } + +with -S, and change the thing that alters the PC (return, or ret +usually) to not alter the PC, making sure to leave all other semantics +(like adjusting the stack pointer, or frame pointers) in. After that, +replicate the prologue once more at the end, again, changing the PC +altering instructions, and finally, at the very end, jump to `g'. + +It takes about a week to write this routine, if someone wants to +volunteer to write this routine for any architecture, exception support +for that architecture will be added to g++. Please send in those code +donations. One other thing that needs to be done, is to double check +that __builtin_return_address (0) works. + +@subsection Specific Targets + +For the alpha, the __unwind_function will be something resembling: + +@example +void +__unwind_function(void *ptr) +@{ + /* First frame */ + asm ("ldq $15, 8($30)"); /* get the saved frame ptr; 15 is fp, 30 is sp */ + asm ("bis $15, $15, $30"); /* reload sp with the fp we found */ + + /* Second frame */ + asm ("ldq $15, 8($30)"); /* fp */ + asm ("bis $15, $15, $30"); /* reload sp with the fp we found */ + + /* Return */ + asm ("ret $31, ($16), 1"); /* return to PTR, stored in a0 */ +@} +@end example + +@noindent +However, there are a few problems preventing it from working. First of +all, the gcc-internal function @code{__builtin_return_address} needs to +work given an argument of 0 for the alpha. As it stands as of August +30th, 1995, the code for @code{BUILT_IN_RETURN_ADDRESS} in @file{expr.c} +will definitely not work on the alpha. Instead, we need to define +the macros @code{DYNAMIC_CHAIN_ADDRESS} (maybe), +@code{RETURN_ADDR_IN_PREVIOUS_FRAME}, and definitely need a new +definition for @code{RETURN_ADDR_RTX}. + +In addition (and more importantly), we need a way to reliably find the +frame pointer on the alpha. The use of the value 8 above to restore the +frame pointer (register 15) is incorrect. On many systems, the frame +pointer is consistently offset to a specific point on the stack. On the +alpha, however, the frame pointer is pushed last. First the return +address is stored, then any other registers are saved (e.g., @code{s0}), +and finally the frame pointer is put in place. So @code{fp} could have +an offset of 8, but if the calling function saved any registers at all, +they add to the offset. + +The only places the frame size is noted are with the @samp{.frame} +directive, for use by the debugger and the OSF exception handling model +(useless to us), and in the initial computation of the new value for +@code{sp}, the stack pointer. For example, the function may start with: + +@example +lda $30,-32($30) +.frame $15,32,$26,0 +@end example + +@noindent +The 32 above is exactly the value we need. With this, we can be sure +that the frame pointer is stored 8 bytes less---in this case, at 24(sp)). +The drawback is that there is no way that I (Brendan) have found to let +us discover the size of a previous frame @emph{inside} the definition +of @code{__unwind_function}. + +So to accomplish exception handling support on the alpha, we need two +things: first, a way to figure out where the frame pointer was stored, +and second, a functional @code{__builtin_return_address} implementation +for except.c to be able to use it. + +@subsection Backend Exception Support + +The backend must be extended to fully support exceptions. Right now +there are a few hooks into the alpha exception handling backend that +resides in the C++ frontend from that backend that allows exception +handling to work in g++. An exception region is a segment of generated +code that has a handler associated with it. The exception regions are +denoted in the generated code as address ranges denoted by a starting PC +value and an ending PC value of the region. Some of the limitations +with this scheme are: + +@itemize @bullet +@item +The backend replicates insns for such things as loop unrolling and +function inlining. Right now, there are no hooks into the frontend's +exception handling backend to handle the replication of insns. When +replication happens, a new exception region descriptor needs to be +generated for the new region. + +@item +The backend expects to be able to rearrange code, for things like jump +optimization. Any rearranging of the code needs have exception region +descriptors updated appropriately. + +@item +The backend can eliminate dead code. Any associated exception region +descriptor that refers to fully contained code that has been eliminated +should also be removed, although not doing this is harmless in terms of +semantics. + +#end itemize + +The above is not meant to be exhaustive, but does include all things I +have thought of so far. I am sure other limitations exist. + +Below are some notes on the migration of the exception handling code +backend from the C++ frontend to the backend. + +NOTEs are to be used to denote the start of an exception region, and the +end of the region. I presume that the interface used to generate these +notes in the backend would be two functions, start_exception_region and +end_exception_region (or something like that). The frontends are +required to call them in pairs. When marking the end of a region, an +argument can be passed to indicate the handler for the marked region. +This can be passed in many ways, currently a tree is used. Another +possibility would be insns for the handler, or a label that denotes a +handler. I have a feeling insns might be the the best way to pass it. +Semantics are, if an exception is thrown inside the region, control is +transfered unconditionally to the handler. If control passes through +the handler, then the backend is to rethrow the exception, in the +context of the end of the original region. The handler is protected by +the conventional mechanisms; it is the frontend's responsibility to +protect the handler, if special semantics are required. + +This is a very low level view, and it would be nice is the backend +supported a somewhat higher level view in addition to this view. This +higher level could include source line number, name of the source file, +name of the language that threw the exception and possibly the name of +the exception. Kenner may want to rope you into doing more than just +the basics required by C++. You will have to resolve this. He may want +you to do support for non-local gotos, first scan for exception handler, +if none is found, allow the debugger to be entered, without any cleanups +being done. To do this, the backend would have to know the difference +between a cleanup-rethrower, and a real handler, if would also have to +have a way to know if a handler `matches' a thrown exception, and this +is frontend specific. + +The UNSAVE_EXPR tree code has to be migrated to the backend. Exprs such +as TARGET_EXPRs, WITH_CLEANUP_EXPRs, CALL_EXPRs and RTL_EXPRs have to be +changed to support unsaving. This is meant to be a complete list. +SAVE_EXPRs can be unsaved already. expand_decl_cleanup should be +changed to unsave it's argument, if needed. See +cp/tree.c:cp_expand_decl_cleanup, unsave_expr_now, unsave_expr, and +cp/expr.c:cplus_expand_expr(case UNSAVE_EXPR:) for the UNSAVE_EXPR code. +Now, as to why... because kenner already tripped over the exact same +problem in Ada, we talked about it, he didn't like any of the solution, +but yet, didn't like no solution either. He was willing to live with +the drawbacks of this solution. The drawback is unsave_expr_now. It +should have a callback into the frontend, to allow the unsaveing of +frontend special codes. The callback goes in, inplace of the call to +my_friendly_abort. + +The stack unwinder is one of the hardest parts to do. It is highly +machine dependent. The form that kenner seems to like was a couple of +macros, that would do the machine dependent grunt work. One preexisting +function that might be of some use is __builtin_return_address (). One +macro he seemed to want was __builtin_return_address, and the other +would do the hard work of fixing up the registers, adjusting the stack +pointer, frame pointer, arg pointer and so on. + +The eh archive (~mrs/eh) might be good reading for understanding the Ada +perspective, and some of kenners mindset, and a detailed explanation +(Message-Id: <9308301130.AA10543@vlsi1.ultra.nyu.edu>) of the concepts +involved. + +Here is a guide to existing backend type code. It is all in +cp/except.c. Check out do_unwind, and expand_builtin_throw for current +code on how to figure out what handler matches an exception, +emit_exception_table for code on emitting the PC range table that is +built during compilation, expand_exception_blocks for code that emits +all the handlers at the end of a functions, end_protect to mark the end +of an exception region, start_protect to mark the start of an exception +region, lang_interim_eh is the master hook used by the backend into the +EH backend that now exists in the frontend, and expand_internal_throw to +raise an exception. + + +@node Free Store, Concept Index, Exception Handling, Top +@section Free Store + +operator new [] adds a magic cookie to the beginning of arrays for which +the number of elements will be needed by operator delete []. These are +arrays of objects with destructors and arrays of objects that define +operator delete [] with the optional size_t argument. This cookie can +be examined from a program as follows: + +@example +typedef unsigned long size_t; +extern "C" int printf (const char *, ...); + +size_t nelts (void *p) +@{ + struct cookie @{ + size_t nelts __attribute__ ((aligned (sizeof (double)))); + @}; + + cookie *cp = (cookie *)p; + --cp; + + return cp->nelts; +@} + +struct A @{ + ~A() @{ @} +@}; + +main() +@{ + A *ap = new A[3]; + printf ("%ld\n", nelts (ap)); +@} +@end example + +@section Linkage +The linkage code in g++ is horribly twisted in order to meet two design goals: + +1) Avoid unnecessary emission of inlines and vtables. + +2) Support pedantic assemblers like the one in AIX. + +To meet the first goal, we defer emission of inlines and vtables until +the end of the translation unit, where we can decide whether or not they +are needed, and how to emit them if they are. + +@node Concept Index, , Free Store, Top +@section Concept Index + +@printindex cp + +@bye diff --git a/contrib/gcc/cp/init.c b/contrib/gcc/cp/init.c new file mode 100644 index 00000000000..9752a9bcd1d --- /dev/null +++ b/contrib/gcc/cp/init.c @@ -0,0 +1,4180 @@ +/* Handle initialization things in C++. + Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "cp-tree.h" +#include "flags.h" +#include "output.h" + +#undef NULL +#define NULL 0 + +/* In C++, structures with well-defined constructors are initialized by + those constructors, unasked. CURRENT_BASE_INIT_LIST + holds a list of stmts for a BASE_INIT term in the grammar. + This list has one element for each base class which must be + initialized. The list elements are [basename, init], with + type basetype. This allows the possibly anachronistic form + (assuming d : a, b, c) "d (int a) : c(a+5), b (a-4), a (a+3)" + where each successive term can be handed down the constructor + line. Perhaps this was not intended. */ +tree current_base_init_list, current_member_init_list; + +void emit_base_init (); +void check_base_init (); +static void expand_aggr_vbase_init (); +void expand_member_init (); +void expand_aggr_init (); + +static void expand_aggr_init_1 (); +static void expand_recursive_init_1 (); +static void expand_recursive_init (); +static void expand_virtual_init PROTO((tree, tree)); +tree expand_vec_init (); + +static void add_friend (), add_friends (); + +/* Cache _builtin_new and _builtin_delete exprs. */ +static tree BIN, BID, BIVN, BIVD; + +/* Cache the identifier nodes for the two magic field of a new cookie. */ +static tree nc_nelts_field_id; +#if 0 +static tree nc_ptr_2comp_field_id; +#endif + +static tree minus_one; + +/* Set up local variable for this file. MUST BE CALLED AFTER + INIT_DECL_PROCESSING. */ + +tree BI_header_type, BI_header_size; + +void init_init_processing () +{ + tree fields[1]; + + /* Define implicit `operator new' and `operator delete' functions. */ + BIN = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) NEW_EXPR]))); + TREE_USED (TREE_OPERAND (BIN, 0)) = 0; + BID = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) DELETE_EXPR]))); + TREE_USED (TREE_OPERAND (BID, 0)) = 0; + BIVN = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) VEC_NEW_EXPR]))); + TREE_USED (TREE_OPERAND (BIVN, 0)) = 0; + BIVD = default_conversion (get_first_fn (IDENTIFIER_GLOBAL_VALUE (ansi_opname[(int) VEC_DELETE_EXPR]))); + TREE_USED (TREE_OPERAND (BIVD, 0)) = 0; + minus_one = build_int_2 (-1, -1); + + /* Define the structure that holds header information for + arrays allocated via operator new. */ + BI_header_type = make_lang_type (RECORD_TYPE); + nc_nelts_field_id = get_identifier ("nelts"); + fields[0] = build_lang_field_decl (FIELD_DECL, nc_nelts_field_id, sizetype); + finish_builtin_type (BI_header_type, "__new_cookie", fields, + 0, double_type_node); + BI_header_size = size_in_bytes (BI_header_type); +} + +/* Subroutine of emit_base_init. For BINFO, initialize all the + virtual function table pointers, except those that come from + virtual base classes. Initialize binfo's vtable pointer, if + INIT_SELF is true. CAN_ELIDE is true when we know that all virtual + function table pointers in all bases have been initialized already, + probably because their constructors have just be run. ADDR is the + pointer to the object whos vtables we are going to initialize. + + REAL_BINFO is usually the same as BINFO, except when addr is not of + pointer to the type of the real derived type that we want to + initialize for. This is the case when addr is a pointer to a sub + object of a complete object, and we only want to do part of the + complete object's initialization of vtable pointers. This is done + for all virtual table pointers in virtual base classes. REAL_BINFO + is used to find the BINFO_VTABLE that we initialize with. BINFO is + used for conversions of addr to subobjects. + + BINFO_TYPE (real_binfo) must be BINFO_TYPE (binfo). + + Relies upon binfo being inside TYPE_BINFO (TREE_TYPE (TREE_TYPE + (addr))). */ +void +expand_direct_vtbls_init (real_binfo, binfo, init_self, can_elide, addr) + tree real_binfo, binfo, addr; + int init_self, can_elide; +{ + tree real_binfos = BINFO_BASETYPES (real_binfo); + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree real_base_binfo = TREE_VEC_ELT (real_binfos, i); + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo)); + if (! TREE_VIA_VIRTUAL (real_base_binfo)) + expand_direct_vtbls_init (real_base_binfo, base_binfo, + is_not_base_vtable, can_elide, addr); + } +#if 0 + /* Before turning this on, make sure it is correct. */ + if (can_elide && ! BINFO_MODIFIED (binfo)) + return; +#endif + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo))) + { + tree base_ptr = convert_pointer_to_real (binfo, addr); + expand_virtual_init (real_binfo, base_ptr); + } +} + +/* 348 - 351 */ +/* Subroutine of emit_base_init. */ +static void +perform_member_init (member, name, init, explicit, protect_list) + tree member, name, init, *protect_list; + int explicit; +{ + tree decl; + tree type = TREE_TYPE (member); + + if (TYPE_NEEDS_CONSTRUCTING (type) + || (init && TYPE_HAS_CONSTRUCTOR (type))) + { + /* Since `init' is already a TREE_LIST on the current_member_init_list, + only build it into one if we aren't already a list. */ + if (init != NULL_TREE && TREE_CODE (init) != TREE_LIST) + init = build_tree_list (NULL_TREE, init); + + decl = build_component_ref (C_C_D, name, 0, explicit); + + if (explicit + && TREE_CODE (type) == ARRAY_TYPE + && init != NULL_TREE + && TREE_CHAIN (init) == NULL_TREE + && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE) + { + /* Initialization of one array from another. */ + expand_vec_init (TREE_OPERAND (decl, 1), decl, + array_type_nelts (type), TREE_VALUE (init), 1); + } + else + expand_aggr_init (decl, init, 0, 0); + } + else + { + if (init == NULL_TREE) + { + if (explicit) + { + cp_error ("incomplete initializer for member `%D' of class `%T' which has no constructor", + member, current_class_type); + init = error_mark_node; + } + /* member traversal: note it leaves init NULL */ + else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE) + cp_pedwarn ("uninitialized reference member `%D'", member); + } + else if (TREE_CODE (init) == TREE_LIST) + { + /* There was an explicit member initialization. Do some + work in that case. */ + if (TREE_CHAIN (init)) + { + warning ("initializer list treated as compound expression"); + init = build_compound_expr (init); + } + else + init = TREE_VALUE (init); + } + + /* We only build this with a null init if we got it from the + current_member_init_list. */ + if (init || explicit) + { + decl = build_component_ref (C_C_D, name, 0, explicit); + expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init)); + } + } + expand_cleanups_to (NULL_TREE); + + if (TYPE_NEEDS_DESTRUCTOR (type)) + { + tree expr = build_component_ref (C_C_D, name, 0, explicit); + expr = build_delete (type, expr, integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); + + if (expr != error_mark_node) + { + start_protect (); + *protect_list = tree_cons (NULL_TREE, expr, *protect_list); + } + } +} + +extern int warn_reorder; + +/* Subroutine of emit_member_init. */ +static tree +sort_member_init (t) + tree t; +{ + tree x, member, name, field, init; + tree init_list = NULL_TREE; + tree fields_to_unmark = NULL_TREE; + int last_pos = 0; + tree last_field; + + for (member = TYPE_FIELDS (t); member ; member = TREE_CHAIN (member)) + { + int pos; + + /* member could be, for example, a CONST_DECL for an enumerated + tag; we don't want to try to initialize that, since it already + has a value. */ + if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member)) + continue; + + for (x = current_member_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos) + { + /* If we cleared this out, then pay no attention to it. */ + if (TREE_PURPOSE (x) == NULL_TREE) + continue; + name = TREE_PURPOSE (x); + +#if 0 + field = (TREE_CODE (name) == COMPONENT_REF + ? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name)); +#else + /* Let's find out when this happens. */ + my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 348); + field = IDENTIFIER_CLASS_VALUE (name); +#endif + + /* If one member shadows another, get the outermost one. */ + if (TREE_CODE (field) == TREE_LIST) + field = TREE_VALUE (field); + + if (field == member) + { + if (warn_reorder) + { + if (pos < last_pos) + { + cp_warning_at ("member initializers for `%#D'", last_field); + cp_warning_at (" and `%#D'", field); + warning (" will be re-ordered to match declaration order"); + } + last_pos = pos; + last_field = field; + } + + /* Make sure we won't try to work on this init again. */ + TREE_PURPOSE (x) = NULL_TREE; + x = build_tree_list (name, TREE_VALUE (x)); + goto got_it; + } + } + + /* If we didn't find MEMBER in the list, create a dummy entry + so the two lists (INIT_LIST and the list of members) will be + symmetrical. */ + x = build_tree_list (NULL_TREE, NULL_TREE); + got_it: + init_list = chainon (init_list, x); + } + + /* Initializers for base members go at the end. */ + for (x = current_member_init_list ; x ; x = TREE_CHAIN (x)) + { + name = TREE_PURPOSE (x); + if (name) + { + if (purpose_member (name, init_list)) + { + cp_error ("multiple initializations given for member `%D'", + IDENTIFIER_CLASS_VALUE (name)); + continue; + } + + init_list = chainon (init_list, + build_tree_list (name, TREE_VALUE (x))); + TREE_PURPOSE (x) = NULL_TREE; + } + } + + return init_list; +} + +static void +sort_base_init (t, rbase_ptr, vbase_ptr) + tree t, *rbase_ptr, *vbase_ptr; +{ + tree binfos = BINFO_BASETYPES (TYPE_BINFO (t)); + int n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + int i; + tree x; + tree last; + + /* For warn_reorder. */ + int last_pos = 0; + tree last_base = NULL_TREE; + + tree rbases = NULL_TREE; + tree vbases = NULL_TREE; + + /* First walk through and splice out vbase and invalid initializers. + Also replace names with binfos. */ + + last = tree_cons (NULL_TREE, NULL_TREE, current_base_init_list); + for (x = TREE_CHAIN (last); x; x = TREE_CHAIN (x)) + { + tree basename = TREE_PURPOSE (x); + tree binfo; + + if (basename == NULL_TREE) + { + /* Initializer for single base class. Must not + use multiple inheritance or this is ambiguous. */ + switch (n_baseclasses) + { + case 0: + cp_error ("`%T' does not have a base class to initialize", + current_class_type); + return; + case 1: + break; + default: + cp_error ("unnamed initializer ambiguous for `%T' which uses multiple inheritance", + current_class_type); + return; + } + binfo = TREE_VEC_ELT (binfos, 0); + } + else if (is_aggr_typedef (basename, 1)) + { + binfo = binfo_or_else (IDENTIFIER_TYPE_VALUE (basename), t); + if (binfo == NULL_TREE) + continue; + + /* Virtual base classes are special cases. Their initializers + are recorded with this constructor, and they are used when + this constructor is the top-level constructor called. */ + if (TREE_VIA_VIRTUAL (binfo)) + { + tree v = CLASSTYPE_VBASECLASSES (t); + while (BINFO_TYPE (v) != BINFO_TYPE (binfo)) + v = TREE_CHAIN (v); + + vbases = tree_cons (v, TREE_VALUE (x), vbases); + continue; + } + else + { + /* Otherwise, if it is not an immediate base class, complain. */ + for (i = n_baseclasses-1; i >= 0; i--) + if (BINFO_TYPE (binfo) == BINFO_TYPE (TREE_VEC_ELT (binfos, i))) + break; + if (i < 0) + { + cp_error ("`%T' is not an immediate base class of `%T'", + IDENTIFIER_TYPE_VALUE (basename), + current_class_type); + continue; + } + } + } + else + my_friendly_abort (365); + + TREE_PURPOSE (x) = binfo; + TREE_CHAIN (last) = x; + last = x; + } + TREE_CHAIN (last) = NULL_TREE; + + /* Now walk through our regular bases and make sure they're initialized. */ + + for (i = 0; i < n_baseclasses; ++i) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int pos; + + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + + for (x = current_base_init_list, pos = 0; x; x = TREE_CHAIN (x), ++pos) + { + tree binfo = TREE_PURPOSE (x); + + if (binfo == NULL_TREE) + continue; + + if (binfo == base_binfo) + { + if (warn_reorder) + { + if (pos < last_pos) + { + cp_warning_at ("base initializers for `%#T'", last_base); + cp_warning_at (" and `%#T'", BINFO_TYPE (binfo)); + warning (" will be re-ordered to match inheritance order"); + } + last_pos = pos; + last_base = BINFO_TYPE (binfo); + } + + /* Make sure we won't try to work on this init again. */ + TREE_PURPOSE (x) = NULL_TREE; + x = build_tree_list (binfo, TREE_VALUE (x)); + goto got_it; + } + } + + /* If we didn't find BASE_BINFO in the list, create a dummy entry + so the two lists (RBASES and the list of bases) will be + symmetrical. */ + x = build_tree_list (NULL_TREE, NULL_TREE); + got_it: + rbases = chainon (rbases, x); + } + + *rbase_ptr = rbases; + *vbase_ptr = vbases; +} + +/* Perform partial cleanups for a base for exception handling. */ +static tree +build_partial_cleanup_for (binfo) + tree binfo; +{ + tree expr = convert_pointer_to_real (binfo, + build_unary_op (ADDR_EXPR, C_C_D, 0)); + + return build_delete (TREE_TYPE (expr), + expr, + integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); +} + +/* Perform whatever initializations have yet to be done on the base + class of the class variable. These actions are in the global + variable CURRENT_BASE_INIT_LIST. Such an action could be + NULL_TREE, meaning that the user has explicitly called the base + class constructor with no arguments. + + If there is a need for a call to a constructor, we must surround + that call with a pushlevel/poplevel pair, since we are technically + at the PARM level of scope. + + Argument IMMEDIATELY, if zero, forces a new sequence to be + generated to contain these new insns, so it can be emitted later. + This sequence is saved in the global variable BASE_INIT_EXPR. + Otherwise, the insns are emitted into the current sequence. + + Note that emit_base_init does *not* initialize virtual base + classes. That is done specially, elsewhere. */ + +extern tree base_init_expr, rtl_expr_chain; + +void +emit_base_init (t, immediately) + tree t; + int immediately; +{ + extern tree in_charge_identifier; + + tree member, x; + tree mem_init_list; + tree rbase_init_list, vbase_init_list; + tree t_binfo = TYPE_BINFO (t); + tree binfos = BINFO_BASETYPES (t_binfo); + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + tree expr = NULL_TREE; + + my_friendly_assert (protect_list == NULL_TREE, 999); + + if (! immediately) + { + int momentary; + do_pending_stack_adjust (); + /* Make the RTL_EXPR node temporary, not momentary, + so that rtl_expr_chain doesn't become garbage. */ + momentary = suspend_momentary (); + expr = make_node (RTL_EXPR); + resume_momentary (momentary); + start_sequence_for_rtl_expr (expr); + } + + if (write_symbols == NO_DEBUG) + /* As a matter of principle, `start_sequence' should do this. */ + emit_note (0, -1); + else + /* Always emit a line number note so we can step into constructors. */ + emit_line_note_force (DECL_SOURCE_FILE (current_function_decl), + DECL_SOURCE_LINE (current_function_decl)); + + mem_init_list = sort_member_init (t); + current_member_init_list = NULL_TREE; + + sort_base_init (t, &rbase_init_list, &vbase_init_list); + current_base_init_list = NULL_TREE; + + if (TYPE_USES_VIRTUAL_BASECLASSES (t)) + { + tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl)); + + expand_start_cond (first_arg, 0); + expand_aggr_vbase_init (t_binfo, C_C_D, current_class_decl, + vbase_init_list); + expand_end_cond (); + } + + /* Now, perform initialization of non-virtual base classes. */ + for (i = 0; i < n_baseclasses; i++) + { + tree base = current_class_decl; + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree init = void_list_node; + + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + +#if 0 /* Once unsharing happens soon enough. */ + my_friendly_assert (BINFO_INHERITANCE_CHAIN (base_binfo) == t_binfo); +#else + BINFO_INHERITANCE_CHAIN (base_binfo) = t_binfo; +#endif + + if (TREE_PURPOSE (rbase_init_list)) + init = TREE_VALUE (rbase_init_list); + else if (TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (base_binfo))) + init = NULL_TREE; + + if (init != void_list_node) + { + member = convert_pointer_to_real (base_binfo, current_class_decl); + expand_aggr_init_1 (base_binfo, 0, + build_indirect_ref (member, NULL_PTR), init, + BINFO_OFFSET_ZEROP (base_binfo), LOOKUP_NORMAL); + expand_cleanups_to (NULL_TREE); + } + + if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))) + { + start_protect (); + protect_list = tree_cons (NULL_TREE, + build_partial_cleanup_for (base_binfo), + protect_list); + } + + rbase_init_list = TREE_CHAIN (rbase_init_list); + } + + /* Initialize all the virtual function table fields that + do come from virtual base classes. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (t)) + expand_indirect_vtbls_init (t_binfo, C_C_D, current_class_decl, 0); + + /* Initialize all the virtual function table fields that + do not come from virtual base classes. */ + expand_direct_vtbls_init (t_binfo, t_binfo, 1, 1, current_class_decl); + + for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member)) + { + tree init, name; + int from_init_list; + + /* member could be, for example, a CONST_DECL for an enumerated + tag; we don't want to try to initialize that, since it already + has a value. */ + if (TREE_CODE (member) != FIELD_DECL || !DECL_NAME (member)) + continue; + + /* See if we had a user-specified member initialization. */ + if (TREE_PURPOSE (mem_init_list)) + { + name = TREE_PURPOSE (mem_init_list); + init = TREE_VALUE (mem_init_list); + from_init_list = 1; + + /* Also see if it's ever a COMPONENT_REF here. If it is, we + need to do `expand_assignment (name, init, 0, 0);' and + a continue. */ + my_friendly_assert (TREE_CODE (name) != COMPONENT_REF, 349); + } + else + { + name = DECL_NAME (member); + init = DECL_INITIAL (member); + + from_init_list = 0; + } + + perform_member_init (member, name, init, from_init_list, &protect_list); + mem_init_list = TREE_CHAIN (mem_init_list); + } + + /* Now initialize any members from our bases. */ + while (mem_init_list) + { + tree name, init, field; + + if (TREE_PURPOSE (mem_init_list)) + { + name = TREE_PURPOSE (mem_init_list); + init = TREE_VALUE (mem_init_list); + /* XXX: this may need the COMPONENT_REF operand 0 check if + it turns out we actually get them. */ + field = IDENTIFIER_CLASS_VALUE (name); + + /* If one member shadows another, get the outermost one. */ + if (TREE_CODE (field) == TREE_LIST) + { + field = TREE_VALUE (field); + if (decl_type_context (field) != current_class_type) + cp_error ("field `%D' not in immediate context", field); + } + +#if 0 + /* It turns out if you have an anonymous union in the + class, a member from it can end up not being on the + list of fields (rather, the type is), and therefore + won't be seen by the for loop above. */ + + /* The code in this for loop is derived from a general loop + which had this check in it. Theoretically, we've hit + every initialization for the list of members in T, so + we shouldn't have anything but these left in this list. */ + my_friendly_assert (DECL_FIELD_CONTEXT (field) != t, 351); +#endif + + perform_member_init (field, name, init, 1, &protect_list); + } + mem_init_list = TREE_CHAIN (mem_init_list); + } + + if (! immediately) + { + do_pending_stack_adjust (); + my_friendly_assert (base_init_expr == 0, 207); + base_init_expr = expr; + TREE_TYPE (expr) = void_type_node; + RTL_EXPR_RTL (expr) = const0_rtx; + RTL_EXPR_SEQUENCE (expr) = get_insns (); + rtl_expr_chain = tree_cons (NULL_TREE, expr, rtl_expr_chain); + end_sequence (); + TREE_SIDE_EFFECTS (expr) = 1; + } + + /* All the implicit try blocks we built up will be zapped + when we come to a real binding contour boundary. */ +} + +/* Check that all fields are properly initialized after + an assignment to `this'. */ +void +check_base_init (t) + tree t; +{ + tree member; + for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member)) + if (DECL_NAME (member) && TREE_USED (member)) + cp_error ("field `%D' used before initialized (after assignment to `this')", + member); +} + +/* This code sets up the virtual function tables appropriate for + the pointer DECL. It is a one-ply initialization. + + BINFO is the exact type that DECL is supposed to be. In + multiple inheritance, this might mean "C's A" if C : A, B. */ +static void +expand_virtual_init (binfo, decl) + tree binfo, decl; +{ + tree type = BINFO_TYPE (binfo); + tree vtbl, vtbl_ptr; + tree vtype, vtype_binfo; + + /* This code is crusty. Should be simple, like: + vtbl = BINFO_VTABLE (binfo); + */ + vtype = DECL_CONTEXT (CLASSTYPE_VFIELD (type)); + vtype_binfo = get_binfo (vtype, TREE_TYPE (TREE_TYPE (decl)), 0); + vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (type)), binfo)); + assemble_external (vtbl); + TREE_USED (vtbl) = 1; + vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl); + decl = convert_pointer_to_real (vtype_binfo, decl); + vtbl_ptr = build_vfield_ref (build_indirect_ref (decl, NULL_PTR), vtype); + if (vtbl_ptr == error_mark_node) + return; + + /* Have to convert VTBL since array sizes may be different. */ + vtbl = convert_force (TREE_TYPE (vtbl_ptr), vtbl, 0); + expand_expr_stmt (build_modify_expr (vtbl_ptr, NOP_EXPR, vtbl)); +} + +/* Subroutine of `expand_aggr_vbase_init'. + BINFO is the binfo of the type that is being initialized. + INIT_LIST is the list of initializers for the virtual baseclass. */ +static void +expand_aggr_vbase_init_1 (binfo, exp, addr, init_list) + tree binfo, exp, addr, init_list; +{ + tree init = purpose_member (binfo, init_list); + tree ref = build_indirect_ref (addr, NULL_PTR); + if (init) + init = TREE_VALUE (init); + /* Call constructors, but don't set up vtables. */ + expand_aggr_init_1 (binfo, exp, ref, init, 0, LOOKUP_COMPLAIN); + expand_cleanups_to (NULL_TREE); +} + +/* Initialize this object's virtual base class pointers. This must be + done only at the top-level of the object being constructed. + + INIT_LIST is list of initialization for constructor to perform. */ +static void +expand_aggr_vbase_init (binfo, exp, addr, init_list) + tree binfo; + tree exp; + tree addr; + tree init_list; +{ + tree type = BINFO_TYPE (binfo); + + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + { + tree result = init_vbase_pointers (type, addr); + tree vbases; + + if (result) + expand_expr_stmt (build_compound_expr (result)); + + for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; + vbases = TREE_CHAIN (vbases)) + { + tree tmp = purpose_member (vbases, result); + expand_aggr_vbase_init_1 (vbases, exp, + TREE_OPERAND (TREE_VALUE (tmp), 0), + init_list); + } + } +} + +/* Subroutine to perform parser actions for member initialization. + S_ID is the scoped identifier. + NAME is the name of the member. + INIT is the initializer, or `void_type_node' if none. */ +void +do_member_init (s_id, name, init) + tree s_id, name, init; +{ + tree binfo, base; + + if (current_class_type == NULL_TREE + || ! is_aggr_typedef (s_id, 1)) + return; + binfo = get_binfo (IDENTIFIER_TYPE_VALUE (s_id), + current_class_type, 1); + if (binfo == error_mark_node) + return; + if (binfo == 0) + { + error_not_base_type (IDENTIFIER_TYPE_VALUE (s_id), current_class_type); + return; + } + + base = convert_pointer_to (binfo, current_class_decl); + expand_member_init (build_indirect_ref (base, NULL_PTR), name, init); +} + +/* Function to give error message if member initialization specification + is erroneous. FIELD is the member we decided to initialize. + TYPE is the type for which the initialization is being performed. + FIELD must be a member of TYPE, or the base type from which FIELD + comes must not need a constructor. + + MEMBER_NAME is the name of the member. */ + +static int +member_init_ok_or_else (field, type, member_name) + tree field; + tree type; + char *member_name; +{ + if (field == error_mark_node) + return 0; + if (field == NULL_TREE) + { + cp_error ("class `%T' does not have any field named `%s'", type, + member_name); + return 0; + } + if (DECL_CONTEXT (field) != type + && TYPE_NEEDS_CONSTRUCTING (DECL_CONTEXT (field))) + { + if (current_function_decl && DECL_CONSTRUCTOR_P (current_function_decl)) + cp_error ("initialization of `%D' inside constructor for `%T'", + field, type); + else + cp_error ("member `%D' comes from base class needing constructor", + field); + return 0; + } + if (TREE_STATIC (field)) + { + cp_error ("field `%#D' is static; only point of initialization is its declaration", + field); + return 0; + } + + return 1; +} + +/* If NAME is a viable field name for the aggregate DECL, + and PARMS is a viable parameter list, then expand an _EXPR + which describes this initialization. + + Note that we do not need to chase through the class's base classes + to look for NAME, because if it's in that list, it will be handled + by the constructor for that base class. + + We do not yet have a fixed-point finder to instantiate types + being fed to overloaded constructors. If there is a unique + constructor, then argument types can be got from that one. + + If INIT is non-NULL, then it the initialization should + be placed in `current_base_init_list', where it will be processed + by `emit_base_init'. */ +void +expand_member_init (exp, name, init) + tree exp, name, init; +{ + extern tree ptr_type_node; /* should be in tree.h */ + + tree basetype = NULL_TREE, field; + tree parm; + tree rval, type; + tree actual_name; + + if (exp == NULL_TREE) + return; /* complain about this later */ + + type = TYPE_MAIN_VARIANT (TREE_TYPE (exp)); + + if (name == NULL_TREE && IS_AGGR_TYPE (type)) + switch (CLASSTYPE_N_BASECLASSES (type)) + { + case 0: + error ("base class initializer specified, but no base class to initialize"); + return; + case 1: + basetype = TYPE_BINFO_BASETYPE (type, 0); + break; + default: + error ("initializer for unnamed base class ambiguous"); + cp_error ("(type `%T' uses multiple inheritance)", type); + return; + } + + if (init) + { + /* The grammar should not allow fields which have names + that are TYPENAMEs. Therefore, if the field has + a non-NULL TREE_TYPE, we may assume that this is an + attempt to initialize a base class member of the current + type. Otherwise, it is an attempt to initialize a + member field. */ + + if (init == void_type_node) + init = NULL_TREE; + + if (name == NULL_TREE || IDENTIFIER_HAS_TYPE_VALUE (name)) + { + tree base_init; + + if (name == NULL_TREE) + { +/* + if (basetype) + name = TYPE_IDENTIFIER (basetype); + else + { + error ("no base class to initialize"); + return; + } +*/ + } + else + { + basetype = IDENTIFIER_TYPE_VALUE (name); + if (basetype != type + && ! binfo_member (basetype, TYPE_BINFO (type)) + && ! binfo_member (basetype, CLASSTYPE_VBASECLASSES (type))) + { + if (IDENTIFIER_CLASS_VALUE (name)) + goto try_member; + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + error ("type `%s' is not an immediate or virtual basetype for `%s'", + IDENTIFIER_POINTER (name), + TYPE_NAME_STRING (type)); + else + error ("type `%s' is not an immediate basetype for `%s'", + IDENTIFIER_POINTER (name), + TYPE_NAME_STRING (type)); + return; + } + } + + if (purpose_member (name, current_base_init_list)) + { + error ("base class `%s' already initialized", + IDENTIFIER_POINTER (name)); + return; + } + + base_init = build_tree_list (name, init); + TREE_TYPE (base_init) = basetype; + current_base_init_list = chainon (current_base_init_list, base_init); + } + else + { + tree member_init; + + try_member: + field = lookup_field (type, name, 1, 0); + + if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name))) + return; + + if (purpose_member (name, current_member_init_list)) + { + error ("field `%s' already initialized", IDENTIFIER_POINTER (name)); + return; + } + + member_init = build_tree_list (name, init); + TREE_TYPE (member_init) = TREE_TYPE (field); + current_member_init_list = chainon (current_member_init_list, member_init); + } + return; + } + else if (name == NULL_TREE) + { + compiler_error ("expand_member_init: name == NULL_TREE"); + return; + } + + basetype = type; + field = lookup_field (basetype, name, 0, 0); + + if (! member_init_ok_or_else (field, basetype, IDENTIFIER_POINTER (name))) + return; + + /* now see if there is a constructor for this type + which will take these args. */ + + if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (field))) + { + tree parmtypes, fndecl; + + if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL) + { + /* just know that we've seen something for this node */ + DECL_INITIAL (exp) = error_mark_node; + TREE_USED (exp) = 1; + } + type = TYPE_MAIN_VARIANT (TREE_TYPE (field)); + actual_name = TYPE_IDENTIFIER (type); + parm = build_component_ref (exp, name, 0, 0); + + /* Now get to the constructor. */ + fndecl = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0); + /* Get past destructor, if any. */ + if (TYPE_HAS_DESTRUCTOR (type)) + fndecl = DECL_CHAIN (fndecl); + + if (fndecl) + my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 209); + + /* If the field is unique, we can use the parameter + types to guide possible type instantiation. */ + if (DECL_CHAIN (fndecl) == NULL_TREE) + { + /* There was a confusion here between + FIELD and FNDECL. The following code + should be correct, but abort is here + to make sure. */ + my_friendly_abort (48); + parmtypes = FUNCTION_ARG_CHAIN (fndecl); + } + else + { + parmtypes = NULL_TREE; + fndecl = NULL_TREE; + } + + init = convert_arguments (parm, parmtypes, NULL_TREE, fndecl, LOOKUP_NORMAL); + if (init == NULL_TREE || TREE_TYPE (init) != error_mark_node) + rval = build_method_call (NULL_TREE, actual_name, init, NULL_TREE, LOOKUP_NORMAL); + else + return; + + if (rval != error_mark_node) + { + /* Now, fill in the first parm with our guy */ + TREE_VALUE (TREE_OPERAND (rval, 1)) + = build_unary_op (ADDR_EXPR, parm, 0); + TREE_TYPE (rval) = ptr_type_node; + TREE_SIDE_EFFECTS (rval) = 1; + } + } + else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field))) + { + parm = build_component_ref (exp, name, 0, 0); + expand_aggr_init (parm, NULL_TREE, 0, 0); + rval = error_mark_node; + } + + /* Now initialize the member. It does not have to + be of aggregate type to receive initialization. */ + if (rval != error_mark_node) + expand_expr_stmt (rval); +} + +/* This is like `expand_member_init', only it stores one aggregate + value into another. + + INIT comes in two flavors: it is either a value which + is to be stored in EXP, or it is a parameter list + to go to a constructor, which will operate on EXP. + If INIT is not a parameter list for a constructor, then set + LOOKUP_ONLYCONVERTING. + If FLAGS is LOOKUP_ONLYCONVERTING then it is the = init form of + the initializer, if FLAGS is 0, then it is the (init) form. + If `init' is a CONSTRUCTOR, then we emit a warning message, + explaining that such initializations are invalid. + + ALIAS_THIS is nonzero iff we are initializing something which is + essentially an alias for C_C_D. In this case, the base constructor + may move it on us, and we must keep track of such deviations. + + If INIT resolves to a CALL_EXPR which happens to return + something of the type we are looking for, then we know + that we can safely use that call to perform the + initialization. + + The virtual function table pointer cannot be set up here, because + we do not really know its type. + + Virtual baseclass pointers are also set up here. + + This never calls operator=(). + + When initializing, nothing is CONST. + + A default copy constructor may have to be used to perform the + initialization. + + A constructor or a conversion operator may have to be used to + perform the initialization, but not both, as it would be ambiguous. + */ + +void +expand_aggr_init (exp, init, alias_this, flags) + tree exp, init; + int alias_this; + int flags; +{ + tree type = TREE_TYPE (exp); + int was_const = TREE_READONLY (exp); + int was_volatile = TREE_THIS_VOLATILE (exp); + + if (init == error_mark_node) + return; + + TREE_READONLY (exp) = 0; + TREE_THIS_VOLATILE (exp) = 0; + + if (init && TREE_CODE (init) != TREE_LIST) + flags |= LOOKUP_ONLYCONVERTING; + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Must arrange to initialize each element of EXP + from elements of INIT. */ + tree itype = init ? TREE_TYPE (init) : NULL_TREE; + if (TYPE_READONLY (TREE_TYPE (type)) || TYPE_VOLATILE (TREE_TYPE (type))) + { + TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type); + if (init) + TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype); + } + if (init && TREE_TYPE (init) == NULL_TREE) + { + /* Handle bad initializers like: + class COMPLEX { + public: + double re, im; + COMPLEX(double r = 0.0, double i = 0.0) {re = r; im = i;}; + ~COMPLEX() {}; + }; + + int main(int argc, char **argv) { + COMPLEX zees(1.0, 0.0)[10]; + } + */ + error ("bad array initializer"); + return; + } + expand_vec_init (exp, exp, array_type_nelts (type), init, + init && comptypes (TREE_TYPE (init), TREE_TYPE (exp), 1)); + TREE_READONLY (exp) = was_const; + TREE_THIS_VOLATILE (exp) = was_volatile; + TREE_TYPE (exp) = type; + if (init) + TREE_TYPE (init) = itype; + return; + } + + if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL) + /* just know that we've seen something for this node */ + TREE_USED (exp) = 1; + +#if 0 + /* If initializing from a GNU C CONSTRUCTOR, consider the elts in the + constructor as parameters to an implicit GNU C++ constructor. */ + if (init && TREE_CODE (init) == CONSTRUCTOR + && TYPE_HAS_CONSTRUCTOR (type) + && TREE_TYPE (init) == type) + init = CONSTRUCTOR_ELTS (init); +#endif + + TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type); + expand_aggr_init_1 (TYPE_BINFO (type), exp, exp, + init, alias_this, LOOKUP_NORMAL|flags); + TREE_TYPE (exp) = type; + TREE_READONLY (exp) = was_const; + TREE_THIS_VOLATILE (exp) = was_volatile; +} + +static void +expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags) + tree binfo; + tree true_exp, exp; + tree type; + tree init; + int alias_this; + int flags; +{ + /* It fails because there may not be a constructor which takes + its own type as the first (or only parameter), but which does + take other types via a conversion. So, if the thing initializing + the expression is a unit element of type X, first try X(X&), + followed by initialization by X. If neither of these work + out, then look hard. */ + tree rval; + tree parms; + + if (init == NULL_TREE + || (TREE_CODE (init) == TREE_LIST && ! TREE_TYPE (init))) + { + parms = init; + if (parms) + init = TREE_VALUE (parms); + } + else if (TREE_CODE (init) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (init) + && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (init))) + { + rval = convert_for_initialization (exp, type, init, 0, 0, 0, 0); + TREE_USED (rval) = 1; + expand_expr_stmt (rval); + return; + } + else + parms = build_tree_list (NULL_TREE, init); + + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + { + if (true_exp == exp) + parms = tree_cons (NULL_TREE, integer_one_node, parms); + else + parms = tree_cons (NULL_TREE, integer_zero_node, parms); + flags |= LOOKUP_HAS_IN_CHARGE; + } + + if (init && TREE_CHAIN (parms) == NULL_TREE + && TYPE_HAS_TRIVIAL_INIT_REF (type) + && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (init))) + { + rval = build (INIT_EXPR, type, exp, init); + TREE_SIDE_EFFECTS (rval) = 1; + expand_expr_stmt (rval); + } + else + { + if (flags & LOOKUP_ONLYCONVERTING) + flags |= LOOKUP_NO_CONVERSION; + rval = build_method_call (exp, constructor_name_full (type), + parms, binfo, flags); + + /* Private, protected, or otherwise unavailable. */ + if (rval == error_mark_node) + { + if (flags & LOOKUP_COMPLAIN) + cp_error ("in base initialization for %sclass `%T'", + TREE_VIA_VIRTUAL (binfo) ? "virtual base " : "", + binfo); + } + else if (rval == NULL_TREE) + my_friendly_abort (361); + else + { + /* p. 222: if the base class assigns to `this', then that + value is used in the derived class. */ + if ((flag_this_is_variable & 1) && alias_this) + { + TREE_TYPE (rval) = TREE_TYPE (current_class_decl); + expand_assignment (current_class_decl, rval, 0, 0); + } + else + expand_expr_stmt (rval); + } + } +} + +/* This function is responsible for initializing EXP with INIT + (if any). + + BINFO is the binfo of the type for who we are performing the + initialization. For example, if W is a virtual base class of A and B, + and C : A, B. + If we are initializing B, then W must contain B's W vtable, whereas + were we initializing C, W must contain C's W vtable. + + TRUE_EXP is nonzero if it is the true expression being initialized. + In this case, it may be EXP, or may just contain EXP. The reason we + need this is because if EXP is a base element of TRUE_EXP, we + don't necessarily know by looking at EXP where its virtual + baseclass fields should really be pointing. But we do know + from TRUE_EXP. In constructors, we don't know anything about + the value being initialized. + + ALIAS_THIS serves the same purpose it serves for expand_aggr_init. + + FLAGS is just passes to `build_method_call'. See that function for + its description. */ + +static void +expand_aggr_init_1 (binfo, true_exp, exp, init, alias_this, flags) + tree binfo; + tree true_exp, exp; + tree init; + int alias_this; + int flags; +{ + tree type = TREE_TYPE (exp); + tree init_type = NULL_TREE; + + my_friendly_assert (init != error_mark_node && type != error_mark_node, 211); + + /* Use a function returning the desired type to initialize EXP for us. + If the function is a constructor, and its first argument is + NULL_TREE, know that it was meant for us--just slide exp on + in and expand the constructor. Constructors now come + as TARGET_EXPRs. */ + if (init) + { + tree init_list = NULL_TREE; + + if (TREE_CODE (init) == TREE_LIST) + { + init_list = init; + if (TREE_CHAIN (init) == NULL_TREE) + init = TREE_VALUE (init); + } + + init_type = TREE_TYPE (init); + + if (TREE_CODE (init) != TREE_LIST) + { + if (TREE_CODE (init_type) == ERROR_MARK) + return; + +#if 0 + /* These lines are found troublesome 5/11/89. */ + if (TREE_CODE (init_type) == REFERENCE_TYPE) + init_type = TREE_TYPE (init_type); +#endif + + /* This happens when we use C++'s functional cast notation. + If the types match, then just use the TARGET_EXPR + directly. Otherwise, we need to create the initializer + separately from the object being initialized. */ + if (TREE_CODE (init) == TARGET_EXPR) + { + if (TYPE_MAIN_VARIANT (init_type) == TYPE_MAIN_VARIANT (type)) + { + if (TREE_CODE (exp) == VAR_DECL + || TREE_CODE (exp) == RESULT_DECL) + /* Unify the initialization targets. */ + DECL_RTL (TREE_OPERAND (init, 0)) = DECL_RTL (exp); + else + DECL_RTL (TREE_OPERAND (init, 0)) = expand_expr (exp, NULL_RTX, 0, 0); + + expand_expr_stmt (init); + return; + } + else + { + init = TREE_OPERAND (init, 1); + init = build (CALL_EXPR, init_type, + TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0); + TREE_SIDE_EFFECTS (init) = 1; + if (init_list) + TREE_VALUE (init_list) = init; + } + } + + if (init_type == type && TREE_CODE (init) == CALL_EXPR +#if 0 + /* It is valid to directly initialize from a CALL_EXPR + without going through X(X&), apparently. */ + && ! TYPE_GETS_INIT_REF (type) +#endif + ) + { + /* A CALL_EXPR is a legitimate form of initialization, so + we should not print this warning message. */ +#if 0 + /* Should have gone away due to 5/11/89 change. */ + if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) + init = convert_from_reference (init); +#endif + expand_assignment (exp, init, 0, 0); + if (exp == DECL_RESULT (current_function_decl)) + { + /* Failing this assertion means that the return value + from receives multiple initializations. */ + my_friendly_assert (DECL_INITIAL (exp) == NULL_TREE + || DECL_INITIAL (exp) == error_mark_node, + 212); + DECL_INITIAL (exp) = init; + } + return; + } + else if (init_type == type + && TREE_CODE (init) == COND_EXPR) + { + /* Push value to be initialized into the cond, where possible. + Avoid spurious warning messages when initializing the + result of this function. */ + TREE_OPERAND (init, 1) + = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 1)); + if (exp == DECL_RESULT (current_function_decl)) + DECL_INITIAL (exp) = NULL_TREE; + TREE_OPERAND (init, 2) + = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 2)); + if (exp == DECL_RESULT (current_function_decl)) + DECL_INITIAL (exp) = init; + TREE_SIDE_EFFECTS (init) = 1; + expand_expr (init, const0_rtx, VOIDmode, 0); + free_temp_slots (); + return; + } + } + + /* We did not know what we were initializing before. Now we do. */ + if (TREE_CODE (init) == TARGET_EXPR) + { + tree tmp = TREE_OPERAND (TREE_OPERAND (init, 1), 1); + + if (TREE_CODE (TREE_VALUE (tmp)) == NOP_EXPR + && TREE_OPERAND (TREE_VALUE (tmp), 0) == integer_zero_node) + { + /* In order for this to work for RESULT_DECLs, if their + type has a constructor, then they must be BLKmode + so that they will be meaningfully addressable. */ + tree arg = build_unary_op (ADDR_EXPR, exp, 0); + init = TREE_OPERAND (init, 1); + init = build (CALL_EXPR, build_pointer_type (TREE_TYPE (init)), + TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0); + TREE_SIDE_EFFECTS (init) = 1; + TREE_VALUE (TREE_OPERAND (init, 1)) + = convert_pointer_to (TREE_TYPE (TREE_TYPE (TREE_VALUE (tmp))), arg); + + if (alias_this) + { + expand_assignment (current_function_decl, init, 0, 0); + return; + } + if (exp == DECL_RESULT (current_function_decl)) + { + if (DECL_INITIAL (DECL_RESULT (current_function_decl))) + fatal ("return value from function receives multiple initializations"); + DECL_INITIAL (exp) = init; + } + expand_expr_stmt (init); + return; + } + } + + if (TREE_CODE (exp) == VAR_DECL + && TREE_CODE (init) == CONSTRUCTOR + && TREE_HAS_CONSTRUCTOR (init)) + { + tree t = store_init_value (exp, init); + if (!t) + { + expand_decl_init (exp); + return; + } + t = build (INIT_EXPR, type, exp, init); + TREE_SIDE_EFFECTS (t) = 1; + expand_expr_stmt (t); + return; + } + + /* Handle this case: when calling a constructor: xyzzy foo(bar); + which really means: xyzzy foo = bar; Ugh! + + More useful for this case: xyzzy *foo = new xyzzy (bar); */ + + if (! TYPE_NEEDS_CONSTRUCTING (type) && ! IS_AGGR_TYPE (type)) + { + if (init_list && TREE_CHAIN (init_list)) + { + warning ("initializer list being treated as compound expression"); + init = convert (type, build_compound_expr (init_list)); + if (init == error_mark_node) + return; + } + + expand_assignment (exp, init, 0, 0); + + return; + } + /* See whether we can go through a type conversion operator. + This wins over going through a non-existent constructor. If + there is a constructor, it is ambiguous. */ + if (TREE_CODE (init) != TREE_LIST) + { + tree ttype = TREE_CODE (init_type) == REFERENCE_TYPE + ? TREE_TYPE (init_type) : init_type; + + if (ttype != type && IS_AGGR_TYPE (ttype)) + { + tree rval = build_type_conversion (CONVERT_EXPR, type, init, 0); + + if (rval) + { + /* See if there is a constructor for``type'' that takes a + ``ttype''-typed object. */ + tree parms = build_tree_list (NULL_TREE, init); + tree as_cons = NULL_TREE; + if (TYPE_HAS_CONSTRUCTOR (type)) + as_cons = build_method_call (exp, constructor_name_full (type), + parms, binfo, + LOOKUP_SPECULATIVELY|LOOKUP_NO_CONVERSION); + if (as_cons != NULL_TREE && as_cons != error_mark_node) + /* ANSI C++ June 5 1992 WP 12.3.2.6.1 */ + cp_error ("ambiguity between conversion to `%T' and constructor", + type); + else + expand_assignment (exp, rval, 0, 0); + return; + } + } + } + } + + /* Handle default copy constructors here, does not matter if there is + a constructor or not. */ + if (type == init_type && IS_AGGR_TYPE (type) + && init && TREE_CODE (init) != TREE_LIST) + expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags); + /* Not sure why this is here... */ + else if (TYPE_HAS_CONSTRUCTOR (type)) + expand_default_init (binfo, true_exp, exp, type, init, alias_this, flags); + else if (TREE_CODE (type) == ARRAY_TYPE) + { + if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type))) + expand_vec_init (exp, exp, array_type_nelts (type), init, 0); + else if (TYPE_VIRTUAL_P (TREE_TYPE (type))) + sorry ("arrays of objects with virtual functions but no constructors"); + } + else + expand_recursive_init (binfo, true_exp, exp, init, + CLASSTYPE_BASE_INIT_LIST (type), alias_this); +} + +/* A pointer which holds the initializer. First call to + expand_aggr_init gets this value pointed to, and sets it to init_null. */ +static tree *init_ptr, init_null; + +/* Subroutine of expand_recursive_init: + + ADDR is the address of the expression being initialized. + INIT_LIST is the cons-list of initializations to be performed. + ALIAS_THIS is its same, lovable self. */ +static void +expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this) + tree binfo, true_exp, addr; + tree init_list; + int alias_this; +{ + while (init_list) + { + if (TREE_PURPOSE (init_list)) + { + if (TREE_CODE (TREE_PURPOSE (init_list)) == FIELD_DECL) + { + tree member = TREE_PURPOSE (init_list); + tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), NULL_PTR); + tree member_base = build (COMPONENT_REF, TREE_TYPE (member), subexp, member); + if (IS_AGGR_TYPE (TREE_TYPE (member))) + expand_aggr_init (member_base, DECL_INITIAL (member), 0, 0); + else if (TREE_CODE (TREE_TYPE (member)) == ARRAY_TYPE + && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (member))) + { + member_base = save_expr (default_conversion (member_base)); + expand_vec_init (member, member_base, + array_type_nelts (TREE_TYPE (member)), + DECL_INITIAL (member), 0); + } + else + expand_expr_stmt (build_modify_expr (member_base, INIT_EXPR, DECL_INITIAL (member))); + } + else if (TREE_CODE (TREE_PURPOSE (init_list)) == TREE_LIST) + { + expand_recursive_init_1 (binfo, true_exp, addr, TREE_PURPOSE (init_list), alias_this); + expand_recursive_init_1 (binfo, true_exp, addr, TREE_VALUE (init_list), alias_this); + } + else if (TREE_CODE (TREE_PURPOSE (init_list)) == ERROR_MARK) + { + /* Only initialize the virtual function tables if we + are initializing the ultimate users of those vtables. */ + if (TREE_VALUE (init_list)) + { + /* We have to ensure that the first argment to + expand_virtual_init is in binfo's hierarchy. */ + /* Is it the case that this is exactly the right binfo? */ + /* If it is ok, then fixup expand_virtual_init, to make + it much simpler. */ + expand_virtual_init (get_binfo (TREE_VALUE (init_list), binfo, 0), + addr); + if (TREE_VALUE (init_list) == binfo + && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))) + expand_indirect_vtbls_init (binfo, true_exp, addr, 1); + } + } + else + my_friendly_abort (49); + } + else if (TREE_VALUE (init_list) + && TREE_CODE (TREE_VALUE (init_list)) == TREE_VEC) + { + tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), NULL_PTR); + expand_aggr_init_1 (binfo, true_exp, subexp, *init_ptr, + alias_this && BINFO_OFFSET_ZEROP (TREE_VALUE (init_list)), + LOOKUP_COMPLAIN); + + /* INIT_PTR is used up. */ + init_ptr = &init_null; + } + else + my_friendly_abort (50); + init_list = TREE_CHAIN (init_list); + } +} + +/* Initialize EXP with INIT. Type EXP does not have a constructor, + but it has a baseclass with a constructor or a virtual function + table which needs initializing. + + INIT_LIST is a cons-list describing what parts of EXP actually + need to be initialized. INIT is given to the *unique*, first + constructor within INIT_LIST. If there are multiple first + constructors, such as with multiple inheritance, INIT must + be zero or an ambiguity error is reported. + + ALIAS_THIS is passed from `expand_aggr_init'. See comments + there. */ + +static void +expand_recursive_init (binfo, true_exp, exp, init, init_list, alias_this) + tree binfo, true_exp, exp, init; + tree init_list; + int alias_this; +{ + tree *old_init_ptr = init_ptr; + tree addr = build_unary_op (ADDR_EXPR, exp, 0); + init_ptr = &init; + + if (true_exp == exp && TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (binfo))) + { + expand_aggr_vbase_init (binfo, exp, addr, init_list); + expand_indirect_vtbls_init (binfo, true_exp, addr, 1); + } + expand_recursive_init_1 (binfo, true_exp, addr, init_list, alias_this); + + if (*init_ptr) + { + tree type = TREE_TYPE (exp); + + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + if (IS_AGGR_TYPE (type)) + cp_error ("unexpected argument to constructor `%T'", type); + else + error ("unexpected argument to constructor"); + } + init_ptr = old_init_ptr; +} + +/* Report an error if NAME is not the name of a user-defined, + aggregate type. If OR_ELSE is nonzero, give an error message. */ +int +is_aggr_typedef (name, or_else) + tree name; + int or_else; +{ + tree type; + + if (name == error_mark_node) + return 0; + + if (IDENTIFIER_HAS_TYPE_VALUE (name)) + type = IDENTIFIER_TYPE_VALUE (name); + else + { + if (or_else) + cp_error ("`%T' is not an aggregate typedef", name); + return 0; + } + + if (! IS_AGGR_TYPE (type) + && TREE_CODE (type) != TEMPLATE_TYPE_PARM) + { + if (or_else) + cp_error ("`%T' is not an aggregate type", type); + return 0; + } + return 1; +} + +/* Like is_aggr_typedef, but returns typedef if successful. */ +tree +get_aggr_from_typedef (name, or_else) + tree name; + int or_else; +{ + tree type; + + if (name == error_mark_node) + return NULL_TREE; + + if (IDENTIFIER_HAS_TYPE_VALUE (name)) + type = IDENTIFIER_TYPE_VALUE (name); + else + { + if (or_else) + cp_error ("`%T' fails to be an aggregate typedef", name); + return NULL_TREE; + } + + if (! IS_AGGR_TYPE (type) + && TREE_CODE (type) != TEMPLATE_TYPE_PARM) + { + if (or_else) + cp_error ("type `%T' is of non-aggregate type", type); + return NULL_TREE; + } + return type; +} + +tree +get_type_value (name) + tree name; +{ + if (name == error_mark_node) + return NULL_TREE; + + if (IDENTIFIER_HAS_TYPE_VALUE (name)) + return IDENTIFIER_TYPE_VALUE (name); + else + return NULL_TREE; +} + + +/* This code could just as well go in `class.c', but is placed here for + modularity. */ + +/* For an expression of the form CNAME :: NAME (PARMLIST), build + the appropriate function call. */ +tree +build_member_call (cname, name, parmlist) + tree cname, name, parmlist; +{ + tree type, t; + tree method_name = name; + int dtor = 0; + int dont_use_this = 0; + tree basetype_path, decl; + + if (TREE_CODE (method_name) == BIT_NOT_EXPR) + { + method_name = TREE_OPERAND (method_name, 0); + dtor = 1; + } + + if (TREE_CODE (cname) == SCOPE_REF) + cname = resolve_scope_to_name (NULL_TREE, cname); + + /* This shouldn't be here, and build_member_call shouldn't appear in + parse.y! (mrs) */ + if (cname && get_aggr_from_typedef (cname, 0) == 0 + && TREE_CODE (cname) == IDENTIFIER_NODE) + { + tree ns = lookup_name (cname, 0); + if (ns && TREE_CODE (ns) == NAMESPACE_DECL) + { + return build_x_function_call (build_offset_ref (cname, name), parmlist, current_class_decl); + } + } + + if (cname == NULL_TREE || ! (type = get_aggr_from_typedef (cname, 1))) + return error_mark_node; + + /* An operator we did not like. */ + if (name == NULL_TREE) + return error_mark_node; + + if (dtor) + { +#if 0 + /* Everything can explicitly call a destructor; see 12.4 */ + if (! TYPE_HAS_DESTRUCTOR (type)) + cp_error ("type `%#T' does not have a destructor", type); + else +#endif + cp_error ("cannot call destructor `%T::~%T' without object", type, + method_name); + return error_mark_node; + } + + /* No object? Then just fake one up, and let build_method_call + figure out what to do. */ + if (current_class_type == 0 + || get_base_distance (type, current_class_type, 0, &basetype_path) == -1) + dont_use_this = 1; + + if (dont_use_this) + { + basetype_path = TYPE_BINFO (type); + decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node); + } + else if (current_class_decl == 0) + { + dont_use_this = 1; + decl = build1 (NOP_EXPR, build_pointer_type (type), error_mark_node); + } + else + { + tree olddecl = current_class_decl; + tree oldtype = TREE_TYPE (TREE_TYPE (olddecl)); + if (oldtype != type) + { + tree newtype = build_type_variant (type, TYPE_READONLY (oldtype), + TYPE_VOLATILE (oldtype)); + decl = convert_force (build_pointer_type (newtype), olddecl, 0); + } + else + decl = olddecl; + } + + decl = build_indirect_ref (decl, NULL_PTR); + + if (method_name == constructor_name (type) + || method_name == constructor_name_full (type)) + return build_functional_cast (type, parmlist); + if (t = lookup_fnfields (basetype_path, method_name, 0)) + return build_method_call (decl, method_name, parmlist, basetype_path, + LOOKUP_NORMAL|LOOKUP_NONVIRTUAL); + if (TREE_CODE (name) == IDENTIFIER_NODE + && ((t = lookup_field (TYPE_BINFO (type), name, 1, 0)))) + { + if (t == error_mark_node) + return error_mark_node; + if (TREE_CODE (t) == FIELD_DECL) + { + if (dont_use_this) + { + cp_error ("invalid use of non-static field `%D'", t); + return error_mark_node; + } + decl = build (COMPONENT_REF, TREE_TYPE (t), decl, t); + } + else if (TREE_CODE (t) == VAR_DECL) + decl = t; + else + { + cp_error ("invalid use of member `%D'", t); + return error_mark_node; + } + if (TYPE_LANG_SPECIFIC (TREE_TYPE (decl)) + && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (decl))) + return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl, parmlist, NULL_TREE); + return build_function_call (decl, parmlist); + } + else + { + cp_error ("no method `%T::%D'", type, name); + return error_mark_node; + } +} + +/* Build a reference to a member of an aggregate. This is not a + C++ `&', but really something which can have its address taken, + and then act as a pointer to member, for example CNAME :: FIELD + can have its address taken by saying & CNAME :: FIELD. + + @@ Prints out lousy diagnostics for operator + @@ fields. + + @@ This function should be rewritten and placed in search.c. */ +tree +build_offset_ref (cname, name) + tree cname, name; +{ + tree decl, type, fnfields, fields, t = error_mark_node; + tree basetypes = NULL_TREE; + int dtor = 0; + + if (TREE_CODE (cname) == SCOPE_REF) + cname = resolve_scope_to_name (NULL_TREE, cname); + + /* Handle namespace names fully here. */ + if (TREE_CODE (cname) == IDENTIFIER_NODE + && get_aggr_from_typedef (cname, 0) == 0) + { + tree ns = lookup_name (cname, 0); + tree val; + if (ns && TREE_CODE (ns) == NAMESPACE_DECL) + { + val = lookup_namespace_name (ns, name); + if (val) + return val; + cp_error ("namespace `%D' has no member named `%D'", ns, name); + return error_mark_node; + } + } + + if (cname == NULL_TREE || ! is_aggr_typedef (cname, 1)) + return error_mark_node; + + type = IDENTIFIER_TYPE_VALUE (cname); + + if (TREE_CODE (name) == BIT_NOT_EXPR) + { + dtor = 1; + name = TREE_OPERAND (name, 0); + } + + if (TYPE_SIZE (type) == 0) + { + t = IDENTIFIER_CLASS_VALUE (name); + if (t == 0) + { + cp_error ("incomplete type `%T' does not have member `%D'", type, + name); + return error_mark_node; + } + if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == VAR_DECL + || TREE_CODE (t) == CONST_DECL) + { + TREE_USED (t) = 1; + return t; + } + if (TREE_CODE (t) == FIELD_DECL) + sorry ("use of member in incomplete aggregate type"); + else if (TREE_CODE (t) == FUNCTION_DECL) + sorry ("use of member function in incomplete aggregate type"); + else + my_friendly_abort (52); + return error_mark_node; + } + +#if 0 + if (TREE_CODE (name) == TYPE_EXPR) + /* Pass a TYPE_DECL to build_component_type_expr. */ + return build_component_type_expr (TYPE_NAME (TREE_TYPE (cname)), + name, NULL_TREE, 1); +#endif + + if (current_class_type == 0 + || get_base_distance (type, current_class_type, 0, &basetypes) == -1) + { + basetypes = TYPE_BINFO (type); + decl = build1 (NOP_EXPR, + IDENTIFIER_TYPE_VALUE (cname), + error_mark_node); + } + else if (current_class_decl == 0) + decl = build1 (NOP_EXPR, IDENTIFIER_TYPE_VALUE (cname), + error_mark_node); + else + decl = C_C_D; + + fnfields = lookup_fnfields (basetypes, name, 1); + fields = lookup_field (basetypes, name, 0, 0); + + if (fields == error_mark_node || fnfields == error_mark_node) + return error_mark_node; + + /* A lot of this logic is now handled in lookup_field and + lookup_fnfield. */ + if (fnfields) + { + basetypes = TREE_PURPOSE (fnfields); + + /* Go from the TREE_BASELINK to the member function info. */ + t = TREE_VALUE (fnfields); + + if (fields) + { + if (DECL_FIELD_CONTEXT (fields) == DECL_FIELD_CONTEXT (t)) + { + error ("ambiguous member reference: member `%s' defined as both field and function", + IDENTIFIER_POINTER (name)); + return error_mark_node; + } + if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (fields), DECL_FIELD_CONTEXT (t))) + ; + else if (UNIQUELY_DERIVED_FROM_P (DECL_FIELD_CONTEXT (t), DECL_FIELD_CONTEXT (fields))) + t = fields; + else + { + error ("ambiguous member reference: member `%s' derives from distinct classes in multiple inheritance lattice"); + return error_mark_node; + } + } + + if (t == TREE_VALUE (fnfields)) + { + extern int flag_save_memoized_contexts; + + if (DECL_CHAIN (t) == NULL_TREE || dtor) + { + enum access_type access; + + /* unique functions are handled easily. */ + unique: + access = compute_access (basetypes, t); + if (access == access_protected) + { + cp_error_at ("member function `%#D' is protected", t); + error ("in this context"); + return error_mark_node; + } + if (access == access_private) + { + cp_error_at ("member function `%#D' is private", t); + error ("in this context"); + return error_mark_node; + } + assemble_external (t); + return build (OFFSET_REF, TREE_TYPE (t), decl, t); + } + + /* overloaded functions may need more work. */ + if (cname == name) + { + if (TYPE_HAS_DESTRUCTOR (type) + && DECL_CHAIN (DECL_CHAIN (t)) == NULL_TREE) + { + t = DECL_CHAIN (t); + goto unique; + } + } + /* FNFIELDS is most likely allocated on the search_obstack, + which will go away after this class scope. If we need + to save this value for later (either for memoization + or for use as an initializer for a static variable), then + do so here. + + ??? The smart thing to do for the case of saving initializers + is to resolve them before we're done with this scope. */ + if (!TREE_PERMANENT (fnfields) + && ((flag_save_memoized_contexts && global_bindings_p ()) + || ! allocation_temporary_p ())) + fnfields = copy_list (fnfields); + + for (t = TREE_VALUE (fnfields); t; t = DECL_CHAIN (t)) + assemble_external (t); + + t = build_tree_list (error_mark_node, fnfields); + TREE_TYPE (t) = build_offset_type (type, unknown_type_node); + return t; + } + } + + /* Now that we know we are looking for a field, see if we + have access to that field. Lookup_field will give us the + error message. */ + + t = lookup_field (basetypes, name, 1, 0); + + if (t == error_mark_node) + return error_mark_node; + + if (t == NULL_TREE) + { + cp_error ("`%D' is not a member of type `%T'", name, type); + return error_mark_node; + } + + if (TREE_CODE (t) == TYPE_DECL) + { + TREE_USED (t) = 1; + return t; + } + /* static class members and class-specific enum + values can be returned without further ado. */ + if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL) + { + assemble_external (t); + TREE_USED (t) = 1; + return t; + } + + if (TREE_CODE (t) == FIELD_DECL && DECL_BIT_FIELD (t)) + { + cp_error ("illegal pointer to bit field `%D'", t); + return error_mark_node; + } + + /* static class functions too. */ + if (TREE_CODE (t) == FUNCTION_DECL && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) + my_friendly_abort (53); + + /* In member functions, the form `cname::name' is no longer + equivalent to `this->cname::name'. */ + return build (OFFSET_REF, build_offset_type (type, TREE_TYPE (t)), decl, t); +} + +/* Given an object EXP and a member function reference MEMBER, + return the address of the actual member function. */ +tree +get_member_function (exp_addr_ptr, exp, member) + tree *exp_addr_ptr; + tree exp, member; +{ + tree ctype = TREE_TYPE (exp); + tree function = save_expr (build_unary_op (ADDR_EXPR, member, 0)); + + if (TYPE_VIRTUAL_P (ctype) + || (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (ctype))) + { + tree e0, e1, e3; + tree exp_addr; + + /* Save away the unadulterated `this' pointer. */ + exp_addr = save_expr (*exp_addr_ptr); + + /* Cast function to signed integer. */ + e0 = build1 (NOP_EXPR, integer_type_node, function); + + /* There is a hack here that takes advantage of + twos complement arithmetic, and the fact that + there are more than one UNITS to the WORD. + If the high bit is set for the `function', + then we pretend it is a virtual function, + and the array indexing will knock this bit + out the top, leaving a valid index. */ + if (UNITS_PER_WORD <= 1) + my_friendly_abort (54); + + e1 = build (GT_EXPR, boolean_type_node, e0, integer_zero_node); + e1 = build_compound_expr (tree_cons (NULL_TREE, exp_addr, + build_tree_list (NULL_TREE, e1))); + e1 = save_expr (e1); + + if (TREE_SIDE_EFFECTS (*exp_addr_ptr)) + { + exp = build_indirect_ref (exp_addr, NULL_PTR); + *exp_addr_ptr = exp_addr; + } + + /* This is really hairy: if the function pointer is a pointer + to a non-virtual member function, then we can't go mucking + with the `this' pointer (any more than we already have to + this point). If it is a pointer to a virtual member function, + then we have to adjust the `this' pointer according to + what the virtual function table tells us. */ + + e3 = build_vfn_ref (exp_addr_ptr, exp, e0); + my_friendly_assert (e3 != error_mark_node, 213); + + /* Change this pointer type from `void *' to the + type it is really supposed to be. */ + TREE_TYPE (e3) = TREE_TYPE (function); + + /* If non-virtual, use what we had originally. Otherwise, + use the value we get from the virtual function table. */ + *exp_addr_ptr = build_conditional_expr (e1, exp_addr, *exp_addr_ptr); + + function = build_conditional_expr (e1, function, e3); + } + return build_indirect_ref (function, NULL_PTR); +} + +/* If a OFFSET_REF made it through to here, then it did + not have its address taken. */ + +tree +resolve_offset_ref (exp) + tree exp; +{ + tree type = TREE_TYPE (exp); + tree base = NULL_TREE; + tree member; + tree basetype, addr; + + if (TREE_CODE (exp) == TREE_LIST) + return build_unary_op (ADDR_EXPR, exp, 0); + + if (TREE_CODE (exp) != OFFSET_REF) + { + my_friendly_assert (TREE_CODE (type) == OFFSET_TYPE, 214); + if (TYPE_OFFSET_BASETYPE (type) != current_class_type) + { + error ("object missing in use of pointer-to-member construct"); + return error_mark_node; + } + member = exp; + type = TREE_TYPE (type); + base = C_C_D; + } + else + { + member = TREE_OPERAND (exp, 1); + base = TREE_OPERAND (exp, 0); + } + + if ((TREE_CODE (member) == VAR_DECL + && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (member))) + || TREE_CODE (TREE_TYPE (member)) == FUNCTION_TYPE) + { + /* These were static members. */ + if (mark_addressable (member) == 0) + return error_mark_node; + return member; + } + + /* Syntax error can cause a member which should + have been seen as static to be grok'd as non-static. */ + if (TREE_CODE (member) == FIELD_DECL && C_C_D == NULL_TREE) + { + if (TREE_ADDRESSABLE (member) == 0) + { + cp_error_at ("member `%D' is non-static but referenced as a static member", + member); + error ("at this point in file"); + TREE_ADDRESSABLE (member) = 1; + } + return error_mark_node; + } + + /* The first case is really just a reference to a member of `this'. */ + if (TREE_CODE (member) == FIELD_DECL + && (base == C_C_D + || (TREE_CODE (base) == NOP_EXPR + && TREE_OPERAND (base, 0) == error_mark_node))) + { + tree basetype_path; + enum access_type access; + + if (TREE_CODE (exp) == OFFSET_REF && TREE_CODE (type) == OFFSET_TYPE) + basetype = TYPE_OFFSET_BASETYPE (type); + else + basetype = DECL_CONTEXT (member); + + base = current_class_decl; + + if (get_base_distance (basetype, TREE_TYPE (TREE_TYPE (base)), 0, &basetype_path) < 0) + { + error_not_base_type (basetype, TREE_TYPE (TREE_TYPE (base))); + return error_mark_node; + } + addr = convert_pointer_to (basetype, base); + access = compute_access (basetype_path, member); + if (access == access_public) + return build (COMPONENT_REF, TREE_TYPE (member), + build_indirect_ref (addr, NULL_PTR), member); + if (access == access_protected) + { + cp_error_at ("member `%D' is protected", member); + error ("in this context"); + return error_mark_node; + } + if (access == access_private) + { + cp_error_at ("member `%D' is private", member); + error ("in this context"); + return error_mark_node; + } + my_friendly_abort (55); + } + + /* If this is a reference to a member function, then return + the address of the member function (which may involve going + through the object's vtable), otherwise, return an expression + for the dereferenced pointer-to-member construct. */ + addr = build_unary_op (ADDR_EXPR, base, 0); + + if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE) + { + basetype = DECL_CLASS_CONTEXT (member); + addr = convert_pointer_to (basetype, addr); + return build_unary_op (ADDR_EXPR, get_member_function (&addr, build_indirect_ref (addr, NULL_PTR), member), 0); + } + else if (TREE_CODE (TREE_TYPE (member)) == OFFSET_TYPE) + { + basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (member)); + addr = convert_pointer_to (basetype, addr); + member = convert (ptrdiff_type_node, + build_unary_op (ADDR_EXPR, member, 0)); + return build1 (INDIRECT_REF, type, + build (PLUS_EXPR, build_pointer_type (type), + addr, member)); + } + else if (TYPE_PTRMEMFUNC_P (TREE_TYPE (member))) + { + return get_member_function_from_ptrfunc (&addr, member); + } + my_friendly_abort (56); + /* NOTREACHED */ + return NULL_TREE; +} + +/* Return either DECL or its known constant value (if it has one). */ + +tree +decl_constant_value (decl) + tree decl; +{ + if (! TREE_THIS_VOLATILE (decl) +#if 0 + /* These may be necessary for C, but they break C++. */ + ! TREE_PUBLIC (decl) + /* Don't change a variable array bound or initial value to a constant + in a place where a variable is invalid. */ + && ! pedantic +#endif /* 0 */ + && DECL_INITIAL (decl) != 0 + && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK + /* This is invalid if initial value is not constant. + If it has either a function call, a memory reference, + or a variable, then re-evaluating it could give different results. */ + && TREE_CONSTANT (DECL_INITIAL (decl)) + /* Check for cases where this is sub-optimal, even though valid. */ + && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR +#if 0 + /* We must allow this to work outside of functions so that + static constants can be used for array sizes. */ + && current_function_decl != 0 + && DECL_MODE (decl) != BLKmode +#endif + ) + return DECL_INITIAL (decl); + return decl; +} + +/* Friend handling routines. */ +/* Friend data structures: + + Lists of friend functions come from TYPE_DECL nodes. Since all + aggregate types are automatically typedef'd, these nodes are guaranteed + to exist. + + The TREE_PURPOSE of a friend list is the name of the friend, + and its TREE_VALUE is another list. + + For each element of that list, either the TREE_VALUE or the TREE_PURPOSE + will be filled in, but not both. The TREE_VALUE of that list is an + individual function which is a friend. The TREE_PURPOSE of that list + indicates a type in which all functions by that name are friends. + + Lists of friend classes come from _TYPE nodes. Love that consistency + thang. */ + +int +is_friend_type (type1, type2) + tree type1, type2; +{ + return is_friend (type1, type2); +} + +int +is_friend (type, supplicant) + tree type, supplicant; +{ + int declp; + register tree list; + + if (supplicant == NULL_TREE || type == NULL_TREE) + return 0; + + declp = (TREE_CODE_CLASS (TREE_CODE (supplicant)) == 'd'); + + if (declp) + /* It's a function decl. */ + { + tree list = DECL_FRIENDLIST (TYPE_NAME (type)); + tree name = DECL_NAME (supplicant); + tree ctype; + + if (DECL_FUNCTION_MEMBER_P (supplicant)) + ctype = DECL_CLASS_CONTEXT (supplicant); + else + ctype = NULL_TREE; + + for (; list ; list = TREE_CHAIN (list)) + { + if (name == TREE_PURPOSE (list)) + { + tree friends = TREE_VALUE (list); + name = DECL_ASSEMBLER_NAME (supplicant); + for (; friends ; friends = TREE_CHAIN (friends)) + { + if (ctype == TREE_PURPOSE (friends)) + return 1; + if (name == DECL_ASSEMBLER_NAME (TREE_VALUE (friends))) + return 1; + } + break; + } + } + } + else + /* It's a type. */ + { + if (type == supplicant) + return 1; + + list = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (TYPE_NAME (type))); + for (; list ; list = TREE_CHAIN (list)) + if (supplicant == TREE_VALUE (list)) + return 1; + } + + { + tree context; + + if (! declp) + context = DECL_CONTEXT (TYPE_NAME (supplicant)); + else if (DECL_FUNCTION_MEMBER_P (supplicant)) + context = DECL_CLASS_CONTEXT (supplicant); + else + context = NULL_TREE; + + if (context) + return is_friend (type, context); + } + + return 0; +} + +/* Add a new friend to the friends of the aggregate type TYPE. + DECL is the FUNCTION_DECL of the friend being added. */ +static void +add_friend (type, decl) + tree type, decl; +{ + tree typedecl = TYPE_NAME (type); + tree list = DECL_FRIENDLIST (typedecl); + tree name = DECL_NAME (decl); + + while (list) + { + if (name == TREE_PURPOSE (list)) + { + tree friends = TREE_VALUE (list); + for (; friends ; friends = TREE_CHAIN (friends)) + { + if (decl == TREE_VALUE (friends)) + { + cp_warning ("`%D' is already a friend of class `%T'", + decl, type); + cp_warning_at ("previous friend declaration of `%D'", + TREE_VALUE (friends)); + return; + } + } + TREE_VALUE (list) = tree_cons (error_mark_node, decl, + TREE_VALUE (list)); + return; + } + list = TREE_CHAIN (list); + } + DECL_FRIENDLIST (typedecl) + = tree_cons (DECL_NAME (decl), build_tree_list (error_mark_node, decl), + DECL_FRIENDLIST (typedecl)); + if (DECL_NAME (decl) == ansi_opname[(int) MODIFY_EXPR]) + { + tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); + TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1; + if (parmtypes && TREE_CHAIN (parmtypes)) + { + tree parmtype = TREE_VALUE (TREE_CHAIN (parmtypes)); + if (TREE_CODE (parmtype) == REFERENCE_TYPE + && TREE_TYPE (parmtypes) == TREE_TYPE (typedecl)) + TYPE_HAS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1; + } + } +} + +/* Declare that every member function NAME in FRIEND_TYPE + (which may be NULL_TREE) is a friend of type TYPE. */ +static void +add_friends (type, name, friend_type) + tree type, name, friend_type; +{ + tree typedecl = TYPE_NAME (type); + tree list = DECL_FRIENDLIST (typedecl); + + while (list) + { + if (name == TREE_PURPOSE (list)) + { + tree friends = TREE_VALUE (list); + while (friends && TREE_PURPOSE (friends) != friend_type) + friends = TREE_CHAIN (friends); + if (friends) + if (friend_type) + warning ("method `%s::%s' is already a friend of class", + TYPE_NAME_STRING (friend_type), + IDENTIFIER_POINTER (name)); + else + warning ("function `%s' is already a friend of class `%s'", + IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (DECL_NAME (typedecl))); + else + TREE_VALUE (list) = tree_cons (friend_type, NULL_TREE, + TREE_VALUE (list)); + return; + } + list = TREE_CHAIN (list); + } + DECL_FRIENDLIST (typedecl) = + tree_cons (name, + build_tree_list (friend_type, NULL_TREE), + DECL_FRIENDLIST (typedecl)); + if (! strncmp (IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR]), + strlen (IDENTIFIER_POINTER (ansi_opname[(int) MODIFY_EXPR])))) + { + TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1; + sorry ("declaring \"friend operator =\" will not find \"operator = (X&)\" if it exists"); + } +} + +/* Set up a cross reference so that type TYPE will make member function + CTYPE::DECL a friend when CTYPE is finally defined. For more than + one, set up a cross reference so that functions with the name DECL + and type CTYPE know that they are friends of TYPE. */ +static void +xref_friend (type, decl, ctype) + tree type, decl, ctype; +{ + tree friend_decl = TYPE_NAME (ctype); +#if 0 + tree typedecl = TYPE_NAME (type); + tree t = tree_cons (NULL_TREE, ctype, DECL_UNDEFINED_FRIENDS (typedecl)); + + DECL_UNDEFINED_FRIENDS (typedecl) = t; +#else + tree t = 0; +#endif + SET_DECL_WAITING_FRIENDS (friend_decl, + tree_cons (type, t, + DECL_WAITING_FRIENDS (friend_decl))); + TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = decl; +} + +/* Make FRIEND_TYPE a friend class to TYPE. If FRIEND_TYPE has already + been defined, we make all of its member functions friends of + TYPE. If not, we make it a pending friend, which can later be added + when its definition is seen. If a type is defined, then its TYPE_DECL's + DECL_UNDEFINED_FRIENDS contains a (possibly empty) list of friend + classes that are not defined. If a type has not yet been defined, + then the DECL_WAITING_FRIENDS contains a list of types + waiting to make it their friend. Note that these two can both + be in use at the same time! */ +void +make_friend_class (type, friend_type) + tree type, friend_type; +{ + tree classes; + + if (IS_SIGNATURE (type)) + { + error ("`friend' declaration in signature definition"); + return; + } + if (IS_SIGNATURE (friend_type)) + { + error ("signature type `%s' declared `friend'", + IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (friend_type)))); + return; + } + if (type == friend_type) + { + pedwarn ("class `%s' is implicitly friends with itself", + TYPE_NAME_STRING (type)); + return; + } + + GNU_xref_hier (TYPE_NAME_STRING (type), + TYPE_NAME_STRING (friend_type), 0, 0, 1); + + classes = CLASSTYPE_FRIEND_CLASSES (type); + while (classes && TREE_VALUE (classes) != friend_type) + classes = TREE_CHAIN (classes); + if (classes) + warning ("class `%s' is already friends with class `%s'", + TYPE_NAME_STRING (TREE_VALUE (classes)), TYPE_NAME_STRING (type)); + else + { + CLASSTYPE_FRIEND_CLASSES (type) + = tree_cons (NULL_TREE, friend_type, CLASSTYPE_FRIEND_CLASSES (type)); + } +} + +/* Main friend processor. This is large, and for modularity purposes, + has been removed from grokdeclarator. It returns `void_type_node' + to indicate that something happened, though a FIELD_DECL is + not returned. + + CTYPE is the class this friend belongs to. + + DECLARATOR is the name of the friend. + + DECL is the FUNCTION_DECL that the friend is. + + In case we are parsing a friend which is part of an inline + definition, we will need to store PARM_DECL chain that comes + with it into the DECL_ARGUMENTS slot of the FUNCTION_DECL. + + FLAGS is just used for `grokclassfn'. + + QUALS say what special qualifies should apply to the object + pointed to by `this'. */ +tree +do_friend (ctype, declarator, decl, parmdecls, flags, quals) + tree ctype, declarator, decl, parmdecls; + enum overload_flags flags; + tree quals; +{ + /* Every decl that gets here is a friend of something. */ + DECL_FRIEND_P (decl) = 1; + + if (ctype) + { + tree cname = TYPE_NAME (ctype); + if (TREE_CODE (cname) == TYPE_DECL) + cname = DECL_NAME (cname); + + /* A method friend. */ + if (TREE_CODE (decl) == FUNCTION_DECL) + { + if (flags == NO_SPECIAL && ctype && declarator == cname) + DECL_CONSTRUCTOR_P (decl) = 1; + + /* This will set up DECL_ARGUMENTS for us. */ + grokclassfn (ctype, cname, decl, flags, quals); + if (TYPE_SIZE (ctype) != 0) + check_classfn (ctype, cname, decl); + + if (TREE_TYPE (decl) != error_mark_node) + { + if (TYPE_SIZE (ctype)) + { + /* We don't call pushdecl here yet, or ever on this + actual FUNCTION_DECL. We must preserve its TREE_CHAIN + until the end. */ + make_decl_rtl (decl, NULL_PTR, 1); + add_friend (current_class_type, decl); + } + else + { + register char *classname + = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (ctype))); + + error ("member declared as friend before type `%s' defined", + classname); + } + } + } + else + { + /* Possibly a bunch of method friends. */ + + /* Get the class they belong to. */ + tree ctype = IDENTIFIER_TYPE_VALUE (cname); + + /* This class is defined, use its methods now. */ + if (TYPE_SIZE (ctype)) + { + tree fields = lookup_fnfields (TYPE_BINFO (ctype), declarator, 0); + if (fields) + add_friends (current_class_type, declarator, ctype); + else + error ("method `%s' is not a member of class `%s'", + IDENTIFIER_POINTER (declarator), + IDENTIFIER_POINTER (cname)); + } + else + /* Note: DECLARATOR actually has more than one; in this + case, we're making sure that fns with the name DECLARATOR + and type CTYPE know they are friends of the current + class type. */ + xref_friend (current_class_type, declarator, ctype); + decl = void_type_node; + } + } + else if (TREE_CODE (decl) == FUNCTION_DECL + && ((IDENTIFIER_LENGTH (declarator) == 4 + && IDENTIFIER_POINTER (declarator)[0] == 'm' + && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) + || (IDENTIFIER_LENGTH (declarator) > 10 + && IDENTIFIER_POINTER (declarator)[0] == '_' + && IDENTIFIER_POINTER (declarator)[1] == '_' + && strncmp (IDENTIFIER_POINTER (declarator)+2, + "builtin_", 8) == 0))) + { + /* raw "main", and builtin functions never gets overloaded, + but they can become friends. */ + add_friend (current_class_type, decl); + DECL_FRIEND_P (decl) = 1; + decl = void_type_node; + } + /* A global friend. + @@ or possibly a friend from a base class ?!? */ + else if (TREE_CODE (decl) == FUNCTION_DECL) + { + /* Friends must all go through the overload machinery, + even though they may not technically be overloaded. + + Note that because classes all wind up being top-level + in their scope, their friend wind up in top-level scope as well. */ + DECL_ASSEMBLER_NAME (decl) + = build_decl_overload (declarator, TYPE_ARG_TYPES (TREE_TYPE (decl)), + TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); + DECL_ARGUMENTS (decl) = parmdecls; + DECL_CLASS_CONTEXT (decl) = current_class_type; + + /* We can call pushdecl here, because the TREE_CHAIN of this + FUNCTION_DECL is not needed for other purposes. */ + decl = pushdecl (decl); + + make_decl_rtl (decl, NULL_PTR, 1); + add_friend (current_class_type, decl); + + DECL_FRIEND_P (decl) = 1; +#if 0 + TREE_OVERLOADED (declarator) = 1; +#endif + } + else + { + /* @@ Should be able to ingest later definitions of this function + before use. */ + tree decl = lookup_name_nonclass (declarator); + if (decl == NULL_TREE) + { + warning ("implicitly declaring `%s' as struct", + IDENTIFIER_POINTER (declarator)); + decl = xref_tag (record_type_node, declarator, NULL_TREE, 1); + decl = TYPE_NAME (decl); + } + + /* Allow abbreviated declarations of overloaded functions, + but not if those functions are really class names. */ + if (TREE_CODE (decl) == TREE_LIST && TREE_TYPE (TREE_PURPOSE (decl))) + { + warning ("`friend %s' archaic, use `friend class %s' instead", + IDENTIFIER_POINTER (declarator), + IDENTIFIER_POINTER (declarator)); + decl = TREE_TYPE (TREE_PURPOSE (decl)); + } + + if (TREE_CODE (decl) == TREE_LIST) + add_friends (current_class_type, TREE_PURPOSE (decl), NULL_TREE); + else + make_friend_class (current_class_type, TREE_TYPE (decl)); + decl = void_type_node; + } + return decl; +} + +/* TYPE has now been defined. It may, however, have a number of things + waiting make make it their friend. We resolve these references + here. */ +void +embrace_waiting_friends (type) + tree type; +{ + tree decl = TYPE_NAME (type); + tree waiters; + + if (TREE_CODE (decl) != TYPE_DECL) + return; + + for (waiters = DECL_WAITING_FRIENDS (decl); waiters; + waiters = TREE_CHAIN (waiters)) + { + tree waiter = TREE_PURPOSE (waiters); +#if 0 + tree waiter_prev = TREE_VALUE (waiters); +#endif + tree decl = TREE_TYPE (waiters); + tree name = decl ? (TREE_CODE (decl) == IDENTIFIER_NODE + ? decl : DECL_NAME (decl)) : NULL_TREE; + if (name) + { + /* @@ There may be work to be done since we have not verified + @@ consistency between original and friend declarations + @@ of the functions waiting to become friends. */ + tree field = lookup_fnfields (TYPE_BINFO (type), name, 0); + if (field) + if (decl == name) + add_friends (waiter, name, type); + else + add_friend (waiter, decl); + else + error_with_file_and_line (DECL_SOURCE_FILE (TYPE_NAME (waiter)), + DECL_SOURCE_LINE (TYPE_NAME (waiter)), + "no method `%s' defined in class `%s' to be friend", + IDENTIFIER_POINTER (DECL_NAME (TREE_TYPE (waiters))), + TYPE_NAME_STRING (type)); + } + else + make_friend_class (type, waiter); + +#if 0 + if (TREE_CHAIN (waiter_prev)) + TREE_CHAIN (waiter_prev) = TREE_CHAIN (TREE_CHAIN (waiter_prev)); + else + DECL_UNDEFINED_FRIENDS (TYPE_NAME (waiter)) = NULL_TREE; +#endif + } +} + +/* Common subroutines of build_new and build_vec_delete. */ + +/* Common interface for calling "builtin" functions that are not + really builtin. */ + +tree +build_builtin_call (type, node, arglist) + tree type; + tree node; + tree arglist; +{ + tree rval = build (CALL_EXPR, type, node, arglist, 0); + TREE_SIDE_EFFECTS (rval) = 1; + assemble_external (TREE_OPERAND (node, 0)); + TREE_USED (TREE_OPERAND (node, 0)) = 1; + return rval; +} + +/* Generate a C++ "new" expression. DECL is either a TREE_LIST + (which needs to go through some sort of groktypename) or it + is the name of the class we are newing. INIT is an initialization value. + It is either an EXPRLIST, an EXPR_NO_COMMAS, or something in braces. + If INIT is void_type_node, it means do *not* call a constructor + for this instance. + + For types with constructors, the data returned is initialized + by the appropriate constructor. + + Whether the type has a constructor or not, if it has a pointer + to a virtual function table, then that pointer is set up + here. + + Unless I am mistaken, a call to new () will return initialized + data regardless of whether the constructor itself is private or + not. NOPE; new fails if the constructor is private (jcm). + + Note that build_new does nothing to assure that any special + alignment requirements of the type are met. Rather, it leaves + it up to malloc to do the right thing. Otherwise, folding to + the right alignment cal cause problems if the user tries to later + free the memory returned by `new'. + + PLACEMENT is the `placement' list for user-defined operator new (). */ + +extern int flag_check_new; + +tree +build_new (placement, decl, init, use_global_new) + tree placement; + tree decl, init; + int use_global_new; +{ + tree type, true_type, size, rval; + tree nelts; + tree alloc_expr, alloc_temp; + int has_array = 0; + enum tree_code code = NEW_EXPR; + + tree pending_sizes = NULL_TREE; + + if (decl == error_mark_node) + return error_mark_node; + + if (TREE_CODE (decl) == TREE_LIST) + { + tree absdcl = TREE_VALUE (decl); + tree last_absdcl = NULL_TREE; + int old_immediate_size_expand; + + if (current_function_decl + && DECL_CONSTRUCTOR_P (current_function_decl)) + { + old_immediate_size_expand = immediate_size_expand; + immediate_size_expand = 0; + } + + nelts = integer_one_node; + + if (absdcl && TREE_CODE (absdcl) == CALL_EXPR) + my_friendly_abort (215); + while (absdcl && TREE_CODE (absdcl) == INDIRECT_REF) + { + last_absdcl = absdcl; + absdcl = TREE_OPERAND (absdcl, 0); + } + + if (absdcl && TREE_CODE (absdcl) == ARRAY_REF) + { + /* probably meant to be a vec new */ + tree this_nelts; + + while (TREE_OPERAND (absdcl, 0) + && TREE_CODE (TREE_OPERAND (absdcl, 0)) == ARRAY_REF) + { + last_absdcl = absdcl; + absdcl = TREE_OPERAND (absdcl, 0); + } + + has_array = 1; + this_nelts = TREE_OPERAND (absdcl, 1); + if (this_nelts != error_mark_node) + { + if (this_nelts == NULL_TREE) + error ("new of array type fails to specify size"); + else + { + this_nelts = save_expr (convert (sizetype, this_nelts)); + absdcl = TREE_OPERAND (absdcl, 0); + if (this_nelts == integer_zero_node) + { + warning ("zero size array reserves no space"); + nelts = integer_zero_node; + } + else + nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1); + } + } + else + nelts = integer_zero_node; + } + + if (last_absdcl) + TREE_OPERAND (last_absdcl, 0) = absdcl; + else + TREE_VALUE (decl) = absdcl; + + type = true_type = groktypename (decl); + if (! type || type == error_mark_node) + { + immediate_size_expand = old_immediate_size_expand; + return error_mark_node; + } + + if (current_function_decl + && DECL_CONSTRUCTOR_P (current_function_decl)) + { + pending_sizes = get_pending_sizes (); + immediate_size_expand = old_immediate_size_expand; + } + } + else if (TREE_CODE (decl) == IDENTIFIER_NODE) + { + if (IDENTIFIER_HAS_TYPE_VALUE (decl)) + { + /* An aggregate type. */ + type = IDENTIFIER_TYPE_VALUE (decl); + decl = TYPE_NAME (type); + } + else + { + /* A builtin type. */ + decl = lookup_name (decl, 1); + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 215); + type = TREE_TYPE (decl); + } + true_type = type; + } + else if (TREE_CODE (decl) == TYPE_DECL) + { + type = TREE_TYPE (decl); + true_type = type; + } + else + { + type = decl; + true_type = type; + decl = TYPE_NAME (type); + } + + /* ``A reference cannot be created by the new operator. A reference + is not an object (8.2.2, 8.4.3), so a pointer to it could not be + returned by new.'' ARM 5.3.3 */ + if (TREE_CODE (type) == REFERENCE_TYPE) + { + error ("new cannot be applied to a reference type"); + type = true_type = TREE_TYPE (type); + } + + if (TREE_CODE (type) == FUNCTION_TYPE) + { + error ("new cannot be applied to a function type"); + return error_mark_node; + } + + /* When the object being created is an array, the new-expression yields a + pointer to the initial element (if any) of the array. For example, + both new int and new int[10] return an int*. 5.3.4. */ + if (TREE_CODE (type) == ARRAY_TYPE && has_array == 0) + { + nelts = array_type_nelts_top (type); + has_array = 1; + type = true_type = TREE_TYPE (type); + } + + if (TYPE_READONLY (type) || TYPE_VOLATILE (type)) + type = TYPE_MAIN_VARIANT (type); + + /* If our base type is an array, then make sure we know how many elements + it has. */ + while (TREE_CODE (true_type) == ARRAY_TYPE) + { + tree this_nelts = array_type_nelts_top (true_type); + nelts = build_binary_op (MULT_EXPR, nelts, this_nelts, 1); + true_type = TREE_TYPE (true_type); + } + if (has_array) + size = fold (build_binary_op (MULT_EXPR, size_in_bytes (true_type), + nelts, 1)); + else + size = size_in_bytes (type); + + if (true_type == void_type_node) + { + error ("invalid type `void' for new"); + return error_mark_node; + } + + if (TYPE_SIZE (true_type) == 0) + { + incomplete_type_error (0, true_type); + return error_mark_node; + } + + if (TYPE_LANG_SPECIFIC (true_type) + && CLASSTYPE_ABSTRACT_VIRTUALS (true_type)) + { + abstract_virtuals_error (NULL_TREE, true_type); + return error_mark_node; + } + + if (TYPE_LANG_SPECIFIC (true_type) && IS_SIGNATURE (true_type)) + { + signature_error (NULL_TREE, true_type); + return error_mark_node; + } + + /* Get a little extra space to store a couple of things before the new'ed + array. */ + if (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type)) + { + tree extra = BI_header_size; + + size = size_binop (PLUS_EXPR, size, extra); + } + + if (has_array) + code = VEC_NEW_EXPR; + + /* Allocate the object. */ + if (! use_global_new && TYPE_LANG_SPECIFIC (true_type) + && (TYPE_GETS_NEW (true_type) & (1 << has_array))) + rval = build_opfncall (code, LOOKUP_NORMAL, + build_pointer_type (true_type), size, placement); + else if (placement) + { + rval = build_opfncall (code, LOOKUP_GLOBAL|LOOKUP_COMPLAIN, + ptr_type_node, size, placement); + rval = convert (build_pointer_type (true_type), rval); + } + else if (! has_array && flag_this_is_variable > 0 + && TYPE_NEEDS_CONSTRUCTING (true_type) && init != void_type_node) + { + if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST) + rval = NULL_TREE; + else + { + error ("constructors take parameter lists"); + return error_mark_node; + } + } + else + { + rval = build_builtin_call (build_pointer_type (true_type), + has_array ? BIVN : BIN, + build_tree_list (NULL_TREE, size)); +#if 0 + /* See comment above as to why this is disabled. */ + if (alignment) + { + rval = build (PLUS_EXPR, build_pointer_type (true_type), rval, + alignment); + rval = build (BIT_AND_EXPR, build_pointer_type (true_type), + rval, build1 (BIT_NOT_EXPR, integer_type_node, + alignment)); + } +#endif + TREE_CALLS_NEW (rval) = 1; + } + + if (flag_check_new && rval) + { + /* For array new, we need to make sure that the call to new is + not expanded as part of the RTL_EXPR for the initialization, + so we can't just use save_expr here. */ + + alloc_temp = get_temp_name (TREE_TYPE (rval), 0); + alloc_expr = build (MODIFY_EXPR, TREE_TYPE (rval), alloc_temp, rval); + TREE_SIDE_EFFECTS (alloc_expr) = 1; + rval = alloc_temp; + } + else + alloc_expr = NULL_TREE; + + /* if rval is NULL_TREE I don't have to allocate it, but are we totally + sure we have some extra bytes in that case for the BI_header_size + cookies? And how does that interact with the code below? (mrs) */ + /* Finish up some magic for new'ed arrays */ + if (has_array && TYPE_VEC_NEW_USES_COOKIE (true_type) && rval != NULL_TREE) + { + tree extra = BI_header_size; + tree cookie, exp1; + rval = convert (ptr_type_node, rval); /* convert to void * first */ + rval = convert (string_type_node, rval); /* lets not add void* and ints */ + rval = save_expr (build_binary_op (PLUS_EXPR, rval, extra, 1)); + /* Store header info. */ + cookie = build_indirect_ref (build (MINUS_EXPR, build_pointer_type (BI_header_type), + rval, extra), NULL_PTR); + exp1 = build (MODIFY_EXPR, void_type_node, + build_component_ref (cookie, nc_nelts_field_id, 0, 0), + nelts); + TREE_SIDE_EFFECTS (exp1) = 1; + rval = convert (build_pointer_type (true_type), rval); + TREE_CALLS_NEW (rval) = 1; + TREE_SIDE_EFFECTS (rval) = 1; + rval = build_compound_expr (tree_cons (NULL_TREE, exp1, + build_tree_list (NULL_TREE, rval))); + } + + if (rval == error_mark_node) + return error_mark_node; + + /* Don't call any constructors or do any initialization. */ + if (init == void_type_node) + goto done; + + if (TYPE_NEEDS_CONSTRUCTING (type) || init) + { + if (! TYPE_NEEDS_CONSTRUCTING (type) + && ! IS_AGGR_TYPE (type) && ! has_array) + { + /* New 2.0 interpretation: `new int (10)' means + allocate an int, and initialize it with 10. */ + tree deref; + + rval = save_expr (rval); + deref = build_indirect_ref (rval, NULL_PTR); + TREE_READONLY (deref) = 0; + + if (TREE_CHAIN (init) != NULL_TREE) + pedwarn ("initializer list being treated as compound expression"); + else if (TREE_CODE (init) == CONSTRUCTOR) + { + pedwarn ("initializer list appears where operand should be used"); + init = TREE_OPERAND (init, 1); + } + init = build_compound_expr (init); + + init = convert_for_initialization (deref, type, init, LOOKUP_NORMAL, + "new", NULL_TREE, 0); + rval = build (COMPOUND_EXPR, TREE_TYPE (rval), + build_modify_expr (deref, NOP_EXPR, init), + rval); + TREE_NO_UNUSED_WARNING (rval) = 1; + TREE_SIDE_EFFECTS (rval) = 1; + TREE_CALLS_NEW (rval) = 1; + } + else if (! has_array) + { + tree newrval; + /* Constructors are never virtual. If it has an initialization, we + need to complain if we aren't allowed to use the ctor that took + that argument. */ + int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_COMPLAIN; + + if (rval && TYPE_USES_VIRTUAL_BASECLASSES (true_type)) + { + init = tree_cons (NULL_TREE, integer_one_node, init); + flags |= LOOKUP_HAS_IN_CHARGE; + } + + newrval = rval; + + if (newrval && TREE_CODE (TREE_TYPE (newrval)) == POINTER_TYPE) + newrval = build_indirect_ref (newrval, NULL_PTR); + + newrval = build_method_call (newrval, constructor_name_full (true_type), + init, NULL_TREE, flags); + + if (newrval) + { + rval = newrval; + TREE_HAS_CONSTRUCTOR (rval) = 1; + } + else + rval = error_mark_node; + } + else if (current_function_decl == NULL_TREE) + { + extern tree static_aggregates; + + /* In case of static initialization, SAVE_EXPR is good enough. */ + rval = save_expr (rval); + rval = copy_to_permanent (rval); + init = copy_to_permanent (init); + init = expand_vec_init (decl, rval, + build_binary_op (MINUS_EXPR, nelts, + integer_one_node, 1), + init, 0); + init = copy_to_permanent (init); + static_aggregates = perm_tree_cons (init, rval, static_aggregates); + } + else + { + /* Have to wrap this in RTL_EXPR for two cases: + in base or member initialization and if we + are a branch of a ?: operator. Since we + can't easily know the latter, just do it always. */ + tree xval = make_node (RTL_EXPR); + + /* If we want to check the value of the allocation expression, + and the number of elements in the array is not a constant, we + *must* expand the SAVE_EXPR for nelts in alloc_expr before we + expand it in the actual initialization. So we need to build up + an RTL_EXPR for alloc_expr. Sigh. */ + if (alloc_expr && ! TREE_CONSTANT (nelts)) + { + tree xval = make_node (RTL_EXPR); + rtx rtxval; + TREE_TYPE (xval) = TREE_TYPE (alloc_expr); + do_pending_stack_adjust (); + start_sequence_for_rtl_expr (xval); + emit_note (0, -1); + rtxval = expand_expr (alloc_expr, NULL, VOIDmode, 0); + do_pending_stack_adjust (); + TREE_SIDE_EFFECTS (xval) = 1; + RTL_EXPR_SEQUENCE (xval) = get_insns (); + end_sequence (); + RTL_EXPR_RTL (xval) = rtxval; + TREE_TYPE (xval) = TREE_TYPE (alloc_expr); + alloc_expr = xval; + } + + TREE_TYPE (xval) = TREE_TYPE (rval); + do_pending_stack_adjust (); + start_sequence_for_rtl_expr (xval); + + /* As a matter of principle, `start_sequence' should do this. */ + emit_note (0, -1); + + rval = save_expr (rval); + rval = expand_vec_init (decl, rval, + build_binary_op (MINUS_EXPR, nelts, + integer_one_node, 1), + init, 0); + + do_pending_stack_adjust (); + + TREE_SIDE_EFFECTS (xval) = 1; + TREE_CALLS_NEW (xval) = 1; + RTL_EXPR_SEQUENCE (xval) = get_insns (); + end_sequence (); + + if (TREE_CODE (rval) == SAVE_EXPR) + { + /* Errors may cause this to not get evaluated. */ + if (SAVE_EXPR_RTL (rval) == 0) + SAVE_EXPR_RTL (rval) = const0_rtx; + RTL_EXPR_RTL (xval) = SAVE_EXPR_RTL (rval); + } + else + { + my_friendly_assert (TREE_CODE (rval) == VAR_DECL, 217); + RTL_EXPR_RTL (xval) = DECL_RTL (rval); + } + rval = xval; + } + } + else if (TYPE_READONLY (true_type)) + cp_error ("uninitialized const in `new' of `%#T'", true_type); + + done: + + if (alloc_expr) + { + /* Did we modify the storage? */ + if (rval != alloc_temp) + { + tree ifexp = build_binary_op (NE_EXPR, alloc_expr, + integer_zero_node, 1); + rval = build_conditional_expr (ifexp, rval, alloc_temp); + } + else + rval = alloc_expr; + } + + if (rval && TREE_TYPE (rval) != build_pointer_type (type)) + { + /* The type of new int [3][3] is not int *, but int [3] * */ + rval = build_c_cast (build_pointer_type (type), rval, 0); + } + + if (pending_sizes) + rval = build_compound_expr (chainon (pending_sizes, + build_tree_list (NULL_TREE, rval))); + + if (flag_gc) + { + extern tree gc_visible; + tree objbits; + tree update_expr; + + rval = save_expr (rval); + /* We don't need a `headof' operation to do this because + we know where the object starts. */ + objbits = build1 (INDIRECT_REF, unsigned_type_node, + build (MINUS_EXPR, ptr_type_node, + rval, c_sizeof_nowarn (unsigned_type_node))); + update_expr = build_modify_expr (objbits, BIT_IOR_EXPR, gc_visible); + rval = build_compound_expr (tree_cons (NULL_TREE, rval, + tree_cons (NULL_TREE, update_expr, + build_tree_list (NULL_TREE, rval)))); + } + + return rval; +} + +static tree +build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete, + use_global_delete) + tree base, maxindex, type; + tree auto_delete_vec, auto_delete; + int use_global_delete; +{ + tree virtual_size; + tree ptype = build_pointer_type (type); + tree size_exp = size_in_bytes (type); + + /* Temporary variables used by the loop. */ + tree tbase, tbase_init; + + /* This is the body of the loop that implements the deletion of a + single element, and moves temp variables to next elements. */ + tree body; + + /* This is the LOOP_EXPR that governs the deletion of the elements. */ + tree loop; + + /* This is the thing that governs what to do after the loop has run. */ + tree deallocate_expr = 0; + + /* This is the BIND_EXPR which holds the outermost iterator of the + loop. It is convenient to set this variable up and test it before + executing any other code in the loop. + This is also the containing expression returned by this function. */ + tree controller = NULL_TREE; + + /* This is the BLOCK to record the symbol binding for debugging. */ + tree block; + + if (! IS_AGGR_TYPE (type) || ! TYPE_NEEDS_DESTRUCTOR (type)) + { + loop = integer_zero_node; + goto no_destructor; + } + + /* The below is short by BI_header_size */ + virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex)); + + tbase = build_decl (VAR_DECL, NULL_TREE, ptype); + tbase_init = build_modify_expr (tbase, NOP_EXPR, + fold (build (PLUS_EXPR, ptype, + base, + virtual_size))); + DECL_REGISTER (tbase) = 1; + controller = build (BIND_EXPR, void_type_node, tbase, 0, 0); + TREE_SIDE_EFFECTS (controller) = 1; + block = build_block (tbase, 0, 0, 0, 0); + add_block_current_level (block); + + if (auto_delete != integer_zero_node + && auto_delete != integer_two_node) + { + tree base_tbd = convert (ptype, + build_binary_op (MINUS_EXPR, + convert (ptr_type_node, base), + BI_header_size, + 1)); + /* This is the real size */ + virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size); + body = build_tree_list (NULL_TREE, + build_x_delete (ptype, base_tbd, + 2 | use_global_delete, + virtual_size)); + body = build (COND_EXPR, void_type_node, + build (BIT_AND_EXPR, integer_type_node, + auto_delete, integer_one_node), + body, integer_zero_node); + } + else + body = NULL_TREE; + + body = tree_cons (NULL_TREE, + build_delete (ptype, tbase, auto_delete, + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 1), + body); + + body = tree_cons (NULL_TREE, + build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)), + body); + + body = tree_cons (NULL_TREE, + build (EXIT_EXPR, void_type_node, + build (EQ_EXPR, boolean_type_node, base, tbase)), + body); + + loop = build (LOOP_EXPR, void_type_node, build_compound_expr (body)); + + loop = tree_cons (NULL_TREE, tbase_init, + tree_cons (NULL_TREE, loop, NULL_TREE)); + loop = build_compound_expr (loop); + + no_destructor: + /* If the delete flag is one, or anything else with the low bit set, + delete the storage. */ + if (auto_delete_vec == integer_zero_node + || auto_delete_vec == integer_two_node) + deallocate_expr = integer_zero_node; + else + { + tree base_tbd; + + /* The below is short by BI_header_size */ + virtual_size = fold (size_binop (MULT_EXPR, size_exp, maxindex)); + + if (! TYPE_VEC_NEW_USES_COOKIE (type)) + /* no header */ + base_tbd = base; + else + { + base_tbd = convert (ptype, + build_binary_op (MINUS_EXPR, + convert (string_type_node, base), + BI_header_size, + 1)); + /* True size with header. */ + virtual_size = size_binop (PLUS_EXPR, virtual_size, BI_header_size); + } + deallocate_expr = build_x_delete (ptype, base_tbd, + 2 | use_global_delete, + virtual_size); + if (auto_delete_vec != integer_one_node) + deallocate_expr = build (COND_EXPR, void_type_node, + build (BIT_AND_EXPR, integer_type_node, + auto_delete_vec, integer_one_node), + deallocate_expr, integer_zero_node); + } + + if (loop && deallocate_expr != integer_zero_node) + { + body = tree_cons (NULL_TREE, loop, + tree_cons (NULL_TREE, deallocate_expr, NULL_TREE)); + body = build_compound_expr (body); + } + else + body = loop; + + /* Outermost wrapper: If pointer is null, punt. */ + body = build (COND_EXPR, void_type_node, + build (NE_EXPR, boolean_type_node, base, integer_zero_node), + body, integer_zero_node); + body = build1 (NOP_EXPR, void_type_node, body); + + if (controller) + { + TREE_OPERAND (controller, 1) = body; + return controller; + } + else + return convert (void_type_node, body); +} + +/* Build a tree to cleanup partially built arrays. + BASE is that starting address of the array. + COUNT is the count of objects that have been built, that need destroying. + TYPE is the type of elements in the array. */ +static tree +build_array_eh_cleanup (base, count, type) + tree base, count, type; +{ + tree expr = build_vec_delete_1 (base, count, type, integer_two_node, + integer_zero_node, 0); + return expr; +} + +/* `expand_vec_init' performs initialization of a vector of aggregate + types. + + DECL is passed only for error reporting, and provides line number + and source file name information. + BASE is the space where the vector will be. + MAXINDEX is the maximum index of the array (one less than the + number of elements). + INIT is the (possibly NULL) initializer. + + FROM_ARRAY is 0 if we should init everything with INIT + (i.e., every element initialized from INIT). + FROM_ARRAY is 1 if we should index into INIT in parallel + with initialization of DECL. + FROM_ARRAY is 2 if we should index into INIT in parallel, + but use assignment instead of initialization. */ + +tree +expand_vec_init (decl, base, maxindex, init, from_array) + tree decl, base, maxindex, init; + int from_array; +{ + tree rval; + tree iterator, base2 = NULL_TREE; + tree type = TREE_TYPE (TREE_TYPE (base)); + tree size; + + maxindex = convert (integer_type_node, maxindex); + if (maxindex == error_mark_node) + return error_mark_node; + + if (current_function_decl == NULL_TREE) + { + rval = make_tree_vec (3); + TREE_VEC_ELT (rval, 0) = base; + TREE_VEC_ELT (rval, 1) = maxindex; + TREE_VEC_ELT (rval, 2) = init; + return rval; + } + + size = size_in_bytes (type); + + /* Set to zero in case size is <= 0. Optimizer will delete this if + it is not needed. */ + rval = get_temp_regvar (build_pointer_type (type), + convert (build_pointer_type (type), null_pointer_node)); + base = default_conversion (base); + base = convert (build_pointer_type (type), base); + expand_assignment (rval, base, 0, 0); + base = get_temp_regvar (build_pointer_type (type), base); + + if (init != NULL_TREE + && TREE_CODE (init) == CONSTRUCTOR + && TREE_TYPE (init) == TREE_TYPE (decl)) + { + /* Initialization of array from {...}. */ + tree elts = CONSTRUCTOR_ELTS (init); + tree baseref = build1 (INDIRECT_REF, type, base); + tree baseinc = build (PLUS_EXPR, build_pointer_type (type), base, size); + int host_i = TREE_INT_CST_LOW (maxindex); + + if (IS_AGGR_TYPE (type)) + { + while (elts) + { + host_i -= 1; + expand_aggr_init (baseref, TREE_VALUE (elts), 0, 0); + + expand_assignment (base, baseinc, 0, 0); + elts = TREE_CHAIN (elts); + } + /* Initialize any elements by default if possible. */ + if (host_i >= 0) + { + if (TYPE_NEEDS_CONSTRUCTING (type) == 0) + { + if (obey_regdecls) + use_variable (DECL_RTL (base)); + goto done_init; + } + + iterator = get_temp_regvar (integer_type_node, + build_int_2 (host_i, 0)); + init = NULL_TREE; + goto init_by_default; + } + } + else + while (elts) + { + expand_assignment (baseref, TREE_VALUE (elts), 0, 0); + + expand_assignment (base, baseinc, 0, 0); + elts = TREE_CHAIN (elts); + } + + if (obey_regdecls) + use_variable (DECL_RTL (base)); + } + else + { + tree itype; + + iterator = get_temp_regvar (integer_type_node, maxindex); + + init_by_default: + + /* If initializing one array from another, + initialize element by element. */ + if (from_array) + { + /* We rely upon the below calls the do argument checking */ + if (decl == NULL_TREE) + { + sorry ("initialization of array from dissimilar array type"); + return error_mark_node; + } + if (init) + { + base2 = default_conversion (init); + itype = TREE_TYPE (base2); + base2 = get_temp_regvar (itype, base2); + itype = TREE_TYPE (itype); + } + else if (TYPE_LANG_SPECIFIC (type) + && TYPE_NEEDS_CONSTRUCTING (type) + && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type)) + { + error ("initializer ends prematurely"); + return error_mark_node; + } + } + + expand_start_cond (build (GE_EXPR, boolean_type_node, + iterator, integer_zero_node), 0); + if (TYPE_NEEDS_DESTRUCTOR (type)) + start_protect (); + expand_start_loop_continue_elsewhere (1); + + if (from_array) + { + tree to = build1 (INDIRECT_REF, type, base); + tree from; + + if (base2) + from = build1 (INDIRECT_REF, itype, base2); + else + from = NULL_TREE; + + if (from_array == 2) + expand_expr_stmt (build_modify_expr (to, NOP_EXPR, from)); + else if (TYPE_NEEDS_CONSTRUCTING (type)) + expand_aggr_init (to, from, 0, 0); + else if (from) + expand_assignment (to, from, 0, 0); + else + my_friendly_abort (57); + } + else if (TREE_CODE (type) == ARRAY_TYPE) + { + if (init != 0) + sorry ("cannot initialize multi-dimensional array with initializer"); + expand_vec_init (decl, build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (type)), base), + array_type_nelts (type), 0, 0); + } + else + expand_aggr_init (build1 (INDIRECT_REF, type, base), init, 0, 0); + + expand_assignment (base, + build (PLUS_EXPR, build_pointer_type (type), base, size), + 0, 0); + if (base2) + expand_assignment (base2, + build (PLUS_EXPR, build_pointer_type (type), base2, size), 0, 0); + expand_loop_continue_here (); + expand_exit_loop_if_false (0, build (NE_EXPR, boolean_type_node, + build (PREDECREMENT_EXPR, integer_type_node, iterator, integer_one_node), minus_one)); + + if (obey_regdecls) + { + use_variable (DECL_RTL (base)); + if (base2) + use_variable (DECL_RTL (base2)); + } + expand_end_loop (); + if (TYPE_NEEDS_DESTRUCTOR (type)) + end_protect (build_array_eh_cleanup (rval, + build_binary_op (MINUS_EXPR, + maxindex, + iterator, + 1), + type)); + expand_end_cond (); + if (obey_regdecls) + use_variable (DECL_RTL (iterator)); + } + done_init: + + if (obey_regdecls) + use_variable (DECL_RTL (rval)); + return rval; +} + +/* Free up storage of type TYPE, at address ADDR. + + TYPE is a POINTER_TYPE and can be ptr_type_node for no special type + of pointer. + + VIRTUAL_SIZE is the amount of storage that was allocated, and is + used as the second argument to operator delete. It can include + things like padding and magic size cookies. It has virtual in it, + because if you have a base pointer and you delete through a virtual + destructor, it should be the size of the dynamic object, not the + static object, see Free Store 12.5 ANSI C++ WP. + + This does not call any destructors. */ +tree +build_x_delete (type, addr, which_delete, virtual_size) + tree type, addr; + int which_delete; + tree virtual_size; +{ + int use_global_delete = which_delete & 1; + int use_vec_delete = !!(which_delete & 2); + tree rval; + enum tree_code code = use_vec_delete ? VEC_DELETE_EXPR : DELETE_EXPR; + + if (! use_global_delete && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) + && (TYPE_GETS_DELETE (TREE_TYPE (type)) & (1 << use_vec_delete))) + rval = build_opfncall (code, LOOKUP_NORMAL, addr, virtual_size, NULL_TREE); + else + rval = build_builtin_call (void_type_node, use_vec_delete ? BIVD : BID, + build_tree_list (NULL_TREE, addr)); + return rval; +} + +/* Generate a call to a destructor. TYPE is the type to cast ADDR to. + ADDR is an expression which yields the store to be destroyed. + AUTO_DELETE is nonzero if a call to DELETE should be made or not. + If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the + virtual baseclasses. + If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate. + + FLAGS is the logical disjunction of zero or more LOOKUP_ + flags. See cp-tree.h for more info. + + This function does not delete an object's virtual base classes. */ +tree +build_delete (type, addr, auto_delete, flags, use_global_delete) + tree type, addr; + tree auto_delete; + int flags; + int use_global_delete; +{ + tree function, parms; + tree member; + tree expr; + tree ref; + int ptr; + + if (addr == error_mark_node) + return error_mark_node; + + /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type + set to `error_mark_node' before it gets properly cleaned up. */ + if (type == error_mark_node) + return error_mark_node; + + type = TYPE_MAIN_VARIANT (type); + + if (TREE_CODE (type) == POINTER_TYPE) + { + type = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + if (TYPE_SIZE (type) == 0) + { + incomplete_type_error (0, type); + return error_mark_node; + } + if (TREE_CODE (type) == ARRAY_TYPE) + goto handle_array; + if (! IS_AGGR_TYPE (type)) + { + /* Call the builtin operator delete. */ + return build_builtin_call (void_type_node, BID, + build_tree_list (NULL_TREE, addr)); + } + if (TREE_SIDE_EFFECTS (addr)) + addr = save_expr (addr); + + /* throw away const and volatile on target type of addr */ + addr = convert_force (build_pointer_type (type), addr, 0); + ref = build_indirect_ref (addr, NULL_PTR); + ptr = 1; + } + else if (TREE_CODE (type) == ARRAY_TYPE) + { + handle_array: + if (TREE_SIDE_EFFECTS (addr)) + addr = save_expr (addr); + if (TYPE_DOMAIN (type) == NULL_TREE) + { + error ("unknown array size in delete"); + return error_mark_node; + } + return build_vec_delete (addr, array_type_nelts (type), + c_sizeof_nowarn (TREE_TYPE (type)), + auto_delete, integer_two_node, + use_global_delete); + } + else + { + /* Don't check PROTECT here; leave that decision to the + destructor. If the destructor is accessible, call it, + else report error. */ + addr = build_unary_op (ADDR_EXPR, addr, 0); + if (TREE_SIDE_EFFECTS (addr)) + addr = save_expr (addr); + + if (TREE_CONSTANT (addr)) + addr = convert_pointer_to (type, addr); + else + addr = convert_force (build_pointer_type (type), addr, 0); + + if (TREE_CODE (addr) == NOP_EXPR + && TREE_OPERAND (addr, 0) == current_class_decl) + ref = C_C_D; + else + ref = build_indirect_ref (addr, NULL_PTR); + ptr = 0; + } + + my_friendly_assert (IS_AGGR_TYPE (type), 220); + + if (! TYPE_NEEDS_DESTRUCTOR (type)) + { + if (auto_delete == integer_zero_node) + return void_zero_node; + + /* Pass the size of the object down to the operator delete() in + addition to the ADDR. */ + if (TYPE_GETS_REG_DELETE (type) && !use_global_delete) + { + tree virtual_size = c_sizeof_nowarn (type); + return build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr, + virtual_size, NULL_TREE); + } + + /* Call the builtin operator delete. */ + return build_builtin_call (void_type_node, BID, + build_tree_list (NULL_TREE, addr)); + } + parms = build_tree_list (NULL_TREE, addr); + + /* Below, we will reverse the order in which these calls are made. + If we have a destructor, then that destructor will take care + of the base classes; otherwise, we must do that here. */ + if (TYPE_HAS_DESTRUCTOR (type)) + { + tree dtor = DECL_MAIN_VARIANT (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0)); + tree basetypes = TYPE_BINFO (type); + tree passed_auto_delete; + tree do_delete = NULL_TREE; + + if (use_global_delete) + { + tree cond = fold (build (BIT_AND_EXPR, integer_type_node, + auto_delete, integer_one_node)); + tree call = build_builtin_call + (void_type_node, BID, build_tree_list (NULL_TREE, addr)); + + cond = fold (build (COND_EXPR, void_type_node, cond, + call, void_zero_node)); + if (cond != void_zero_node) + do_delete = cond; + + passed_auto_delete = fold (build (BIT_AND_EXPR, integer_type_node, + auto_delete, integer_two_node)); + } + else + passed_auto_delete = auto_delete; + + if (flags & LOOKUP_PROTECT) + { + enum access_type access = compute_access (basetypes, dtor); + + if (access == access_private) + { + if (flags & LOOKUP_COMPLAIN) + cp_error ("destructor for type `%T' is private in this scope", type); + return error_mark_node; + } + else if (access == access_protected) + { + if (flags & LOOKUP_COMPLAIN) + cp_error ("destructor for type `%T' is protected in this scope", type); + return error_mark_node; + } + } + + /* Once we are in a destructor, try not going through + the virtual function table to find the next destructor. */ + if (DECL_VINDEX (dtor) + && ! (flags & LOOKUP_NONVIRTUAL) + && TREE_CODE (auto_delete) != PARM_DECL + && (ptr == 1 || ! resolves_to_fixed_type_p (ref, 0))) + { + tree binfo, basetype; + /* The code below is probably all broken. See call.c for the + complete right way to do this. this offsets may not be right + in the below. (mrs) */ + /* This destructor must be called via virtual function table. */ + dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (DECL_CONTEXT (dtor)), 0); + basetype = DECL_CLASS_CONTEXT (dtor); + binfo = get_binfo (basetype, + TREE_TYPE (TREE_TYPE (TREE_VALUE (parms))), + 0); + expr = convert_pointer_to_real (binfo, TREE_VALUE (parms)); + if (expr != TREE_VALUE (parms)) + { + expr = fold (expr); + ref = build_indirect_ref (expr, NULL_PTR); + TREE_VALUE (parms) = expr; + } + function = build_vfn_ref (&TREE_VALUE (parms), ref, DECL_VINDEX (dtor)); + if (function == error_mark_node) + return error_mark_node; + TREE_TYPE (function) = build_pointer_type (TREE_TYPE (dtor)); + TREE_CHAIN (parms) = build_tree_list (NULL_TREE, passed_auto_delete); + expr = build_function_call (function, parms); + if (do_delete) + expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete); + if (ptr && (flags & LOOKUP_DESTRUCTOR) == 0) + { + /* Handle the case where a virtual destructor is + being called on an item that is 0. + + @@ Does this really need to be done? */ + tree ifexp = build_binary_op(NE_EXPR, addr, integer_zero_node,1); +#if 0 + if (TREE_CODE (ref) == VAR_DECL + || TREE_CODE (ref) == COMPONENT_REF) + warning ("losing in build_delete"); +#endif + expr = build (COND_EXPR, void_type_node, + ifexp, expr, void_zero_node); + } + } + else + { + tree ifexp; + + if ((flags & LOOKUP_DESTRUCTOR) + || TREE_CODE (ref) == VAR_DECL + || TREE_CODE (ref) == PARM_DECL + || TREE_CODE (ref) == COMPONENT_REF + || TREE_CODE (ref) == ARRAY_REF) + /* These can't be 0. */ + ifexp = integer_one_node; + else + /* Handle the case where a non-virtual destructor is + being called on an item that is 0. */ + ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node, 1); + + /* Used to mean that this destructor was known to be empty, + but that's now obsolete. */ + my_friendly_assert (DECL_INITIAL (dtor) != void_type_node, 221); + + TREE_CHAIN (parms) = build_tree_list (NULL_TREE, passed_auto_delete); + expr = build_function_call (dtor, parms); + if (do_delete) + expr = build (COMPOUND_EXPR, void_type_node, expr, do_delete); + + if (ifexp != integer_one_node) + expr = build (COND_EXPR, void_type_node, + ifexp, expr, void_zero_node); + } + return expr; + } + else + { + /* This can get visibilities wrong. */ + tree binfos = BINFO_BASETYPES (TYPE_BINFO (type)); + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + tree base_binfo = n_baseclasses > 0 ? TREE_VEC_ELT (binfos, 0) : NULL_TREE; + tree exprstmt = NULL_TREE; + tree parent_auto_delete = auto_delete; + tree cond; + + /* If this type does not have a destructor, but does have + operator delete, call the parent parent destructor (if any), + but let this node do the deleting. Otherwise, it is ok + to let the parent destructor do the deleting. */ + if (TYPE_GETS_REG_DELETE (type) && !use_global_delete) + { + parent_auto_delete = integer_zero_node; + if (auto_delete == integer_zero_node) + cond = NULL_TREE; + else + { + tree virtual_size; + + /* This is probably wrong. It should be the size of the + virtual object being deleted. */ + virtual_size = c_sizeof_nowarn (type); + + expr = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr, + virtual_size, NULL_TREE); + if (expr == error_mark_node) + return error_mark_node; + if (auto_delete != integer_one_node) + cond = build (COND_EXPR, void_type_node, + build (BIT_AND_EXPR, integer_type_node, + auto_delete, integer_one_node), + expr, void_zero_node); + else + cond = expr; + } + } + else if (base_binfo == NULL_TREE + || (TREE_VIA_VIRTUAL (base_binfo) == 0 + && ! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)))) + { + tree virtual_size; + + /* This is probably wrong. It should be the size of the virtual + object being deleted. */ + virtual_size = c_sizeof_nowarn (type); + + cond = build (COND_EXPR, void_type_node, + build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node), + build_builtin_call (void_type_node, BID, + build_tree_list (NULL_TREE, addr)), + void_zero_node); + } + else + cond = NULL_TREE; + + if (cond) + exprstmt = build_tree_list (NULL_TREE, cond); + + if (base_binfo + && ! TREE_VIA_VIRTUAL (base_binfo) + && TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo))) + { + tree this_auto_delete; + + if (BINFO_OFFSET_ZEROP (base_binfo)) + this_auto_delete = parent_auto_delete; + else + this_auto_delete = integer_zero_node; + + expr = build_delete (build_pointer_type (BINFO_TYPE (base_binfo)), addr, + this_auto_delete, flags, 0); + exprstmt = tree_cons (NULL_TREE, expr, exprstmt); + } + + /* Take care of the remaining baseclasses. */ + for (i = 1; i < n_baseclasses; i++) + { + base_binfo = TREE_VEC_ELT (binfos, i); + if (! TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (base_binfo)) + || TREE_VIA_VIRTUAL (base_binfo)) + continue; + + /* May be zero offset if other baseclasses are virtual. */ + expr = fold (build (PLUS_EXPR, build_pointer_type (BINFO_TYPE (base_binfo)), + addr, BINFO_OFFSET (base_binfo))); + + expr = build_delete (build_pointer_type (BINFO_TYPE (base_binfo)), expr, + integer_zero_node, + flags, 0); + + exprstmt = tree_cons (NULL_TREE, expr, exprstmt); + } + + for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) + { + if (TREE_CODE (member) != FIELD_DECL) + continue; + if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (member))) + { + tree this_member = build_component_ref (ref, DECL_NAME (member), 0, 0); + tree this_type = TREE_TYPE (member); + expr = build_delete (this_type, this_member, integer_two_node, flags, 0); + exprstmt = tree_cons (NULL_TREE, expr, exprstmt); + } + } + + if (exprstmt) + return build_compound_expr (exprstmt); + /* Virtual base classes make this function do nothing. */ + return void_zero_node; + } +} + +/* For type TYPE, delete the virtual baseclass objects of DECL. */ + +tree +build_vbase_delete (type, decl) + tree type, decl; +{ + tree vbases = CLASSTYPE_VBASECLASSES (type); + tree result = NULL_TREE; + tree addr = build_unary_op (ADDR_EXPR, decl, 0); + + my_friendly_assert (addr != error_mark_node, 222); + + while (vbases) + { + tree this_addr = convert_force (build_pointer_type (BINFO_TYPE (vbases)), + addr, 0); + result = tree_cons (NULL_TREE, + build_delete (TREE_TYPE (this_addr), this_addr, + integer_zero_node, + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0), + result); + vbases = TREE_CHAIN (vbases); + } + return build_compound_expr (nreverse (result)); +} + +/* Build a C++ vector delete expression. + MAXINDEX is the number of elements to be deleted. + ELT_SIZE is the nominal size of each element in the vector. + BASE is the expression that should yield the store to be deleted. + This function expands (or synthesizes) these calls itself. + AUTO_DELETE_VEC says whether the container (vector) should be deallocated. + AUTO_DELETE say whether each item in the container should be deallocated. + + This also calls delete for virtual baseclasses of elements of the vector. + + Update: MAXINDEX is no longer needed. The size can be extracted from the + start of the vector for pointers, and from the type for arrays. We still + use MAXINDEX for arrays because it happens to already have one of the + values we'd have to extract. (We could use MAXINDEX with pointers to + confirm the size, and trap if the numbers differ; not clear that it'd + be worth bothering.) */ +tree +build_vec_delete (base, maxindex, elt_size, auto_delete_vec, auto_delete, + use_global_delete) + tree base, maxindex, elt_size; + tree auto_delete_vec, auto_delete; + int use_global_delete; +{ + tree type; + + if (TREE_CODE (base) == OFFSET_REF) + base = resolve_offset_ref (base); + + type = TREE_TYPE (base); + + base = stabilize_reference (base); + + /* Since we can use base many times, save_expr it. */ + if (TREE_SIDE_EFFECTS (base)) + base = save_expr (base); + + if (TREE_CODE (type) == POINTER_TYPE) + { + /* Step back one from start of vector, and read dimension. */ + tree cookie_addr = build (MINUS_EXPR, build_pointer_type (BI_header_type), + base, BI_header_size); + tree cookie = build_indirect_ref (cookie_addr, NULL_PTR); + maxindex = build_component_ref (cookie, nc_nelts_field_id, 0, 0); + do + type = TREE_TYPE (type); + while (TREE_CODE (type) == ARRAY_TYPE); + } + else if (TREE_CODE (type) == ARRAY_TYPE) + { + /* get the total number of things in the array, maxindex is a bad name */ + maxindex = array_type_nelts_total (type); + while (TREE_CODE (type) == ARRAY_TYPE) + type = TREE_TYPE (type); + base = build_unary_op (ADDR_EXPR, base, 1); + } + else + { + error ("type to vector delete is neither pointer or array type"); + return error_mark_node; + } + + return build_vec_delete_1 (base, maxindex, type, auto_delete_vec, auto_delete, + use_global_delete); +} diff --git a/contrib/gcc/cp/input.c b/contrib/gcc/cp/input.c new file mode 100644 index 00000000000..77a64683f72 --- /dev/null +++ b/contrib/gcc/cp/input.c @@ -0,0 +1,202 @@ +/* Input handling for G++. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* G++ needs to do enough saving and re-parsing of text that it is + necessary to abandon the simple FILE* model and use a mechanism where + we can pre-empt one input stream with another derived from saved text; + we may need to do this arbitrarily often, and cannot depend on having + the GNU library available, so FILE objects just don't cut it. + + This file is written as a separate module, but can be included by + lex.c for very minor efficiency gains (primarily in function + inlining). */ + +#include +#include "obstack.h" + +extern FILE *finput; + +struct pending_input *save_pending_input (); +void restore_pending_input (); + +struct input_source { + /* saved string */ + char *str; + int length; + /* current position, when reading as input */ + int offset; + /* obstack to free this input string from when finished, if any */ + struct obstack *obstack; + /* linked list maintenance */ + struct input_source *next; + /* values to restore after reading all of current string */ + char *filename; + int lineno; + struct pending_input *input; + int putback_char; +}; + +static struct input_source *input, *free_inputs; + +extern char *input_filename; +extern int lineno; + +#ifdef __GNUC__ +#define inline __inline__ +#else +#define inline +#endif + +static inline struct input_source * +allocate_input () +{ + struct input_source *inp; + if (free_inputs) + { + inp = free_inputs; + free_inputs = inp->next; + inp->next = 0; + return inp; + } + inp = (struct input_source *) xmalloc (sizeof (struct input_source)); + inp->next = 0; + inp->obstack = 0; + return inp; +} + +static inline void +free_input (inp) + struct input_source *inp; +{ + if (inp->obstack) + obstack_free (inp->obstack, inp->str); + inp->obstack = 0; + inp->str = 0; + inp->length = 0; + inp->next = free_inputs; + free_inputs = inp; +} + +static int putback_char = -1; + +/* Some of these external functions are declared inline in case this file + is included in lex.c. */ + +inline +void +feed_input (str, len, delete) + char *str; + int len; + struct obstack *delete; +{ + struct input_source *inp = allocate_input (); + + /* This shouldn't be necessary. */ + while (len && !str[len-1]) + len--; + + inp->str = str; + inp->length = len; + inp->obstack = delete; + inp->offset = 0; + inp->next = input; + inp->filename = input_filename; + inp->lineno = lineno; + inp->input = save_pending_input (); + inp->putback_char = putback_char; + putback_char = -1; + input = inp; +} + +struct pending_input *to_be_restored; /* XXX */ +extern int end_of_file; + +static inline int +sub_getch () +{ + if (putback_char != -1) + { + int ch = putback_char; + putback_char = -1; + return ch; + } + if (input) + { + if (input->offset == input->length) + { + struct input_source *inp = input; + my_friendly_assert (putback_char == -1, 223); + to_be_restored = inp->input; + input->offset++; + return EOF; + } + else if (input->offset > input->length) + { + struct input_source *inp = input; + + end_of_file = 0; + input = inp->next; + input_filename = inp->filename; + lineno = inp->lineno; + /* Get interface/implementation back in sync. */ + extract_interface_info (); + putback_char = inp->putback_char; + free_input (inp); + return getch (); + } + if (input) + return input->str[input->offset++]; + } + return getc (finput); +} + +inline +void +put_back (ch) + int ch; +{ + if (ch != EOF) + { + my_friendly_assert (putback_char == -1, 224); + putback_char = ch; + } +} + +extern int linemode; + +int +getch () +{ + int ch = sub_getch (); + if (linemode && ch == '\n') + { + put_back (ch); + ch = EOF; + } + return ch; +} + +inline +int +input_redirected () +{ + return input != 0; +} diff --git a/contrib/gcc/cp/lang-options.h b/contrib/gcc/cp/lang-options.h new file mode 100644 index 00000000000..d551357c09c --- /dev/null +++ b/contrib/gcc/cp/lang-options.h @@ -0,0 +1,107 @@ +/* Definitions for switches for C++. + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is the contribution to the `lang_options' array in gcc.c for + g++. */ + + "-+e0", /* gcc.c tacks the `-' on the front. */ + "-+e1", + "-+e2", + "-faccess-control", + "-fno-access-control", + "-fall-virtual", + "-fno-all-virtual", + "-falt-external-templates", + "-fno-alt-external-templates", + "-fansi-overloading", + "-fno-ansi-overloading", + "-fcadillac", + "-fno-cadillac", + "-fcheck-new", + "-fno-check-new", + "-fconserve-space", + "-fno-conserve-space", + "-fdefault-inline", + "-fno-default-inline", + "-frtti", + "-fno-rtti", + "-felide-constructors", + "-fno-elide-constructors", + "-fenum-int-equiv", + "-fno-enum-int-equiv", + "-fexternal-templates", + "-fno-external-templates", + "-ffor-scope", + "-fno-for-scope", + "-fgc", + "-fno-gc", + "-fgnu-keywords", + "-fno-gnu-keywords", + "-fhandle-exceptions", + "-fno-handle-exceptions", + "-fhandle-signatures", + "-fno-handle-signatures", + "-fhuge-objects", + "-fno-huge-objects", + "-fimplement-inlines", + "-fno-implement-inlines", + "-fimplicit-templates", + "-fno-implicit-templates", + "-flabels-ok", + "-fno-labels-ok", + "-fmemoize-lookups", + "-fno-memoize-lookups", + "-fnonnull-objects", + "-fno-nonnull-objects", + "-foperator-names", + "-fno-operator-names", + "-frepo", + "-fno-repo", + "-fsave-memoized", + "-fno-save-memoized", + "-fshort-temps", + "-fno-short-temps", + "-fstats", + "-fno-stats", + "-fstrict-prototype", + "-fno-strict-prototype", + "-fthis-is-variable", + "-fno-this-is-variable", + "-fvtable-thunks", + "-fno-vtable-thunks", + "-fxref", + "-fno-xref", + + "-Wreturn-type", + "-Wno-return-type", + "-Woverloaded-virtual", + "-Wno-overloaded-virtual", + "-Wtemplate-debugging", + "-Wno-template-debugging", + "-Wctor-dtor-privacy", + "-Wno-ctor-dtor-privacy", + "-Wnon-virtual-dtor", + "-Wno-non-virtual-dtor", + "-Wextern-inline", + "-Wno-extern-inline", + "-Wreorder", + "-Wno-reorder", + "-Wsynth", + "-Wno-synth", diff --git a/contrib/gcc/cp/lang-specs.h b/contrib/gcc/cp/lang-specs.h new file mode 100644 index 00000000000..fbb72c9ed97 --- /dev/null +++ b/contrib/gcc/cp/lang-specs.h @@ -0,0 +1,59 @@ +/* Definitions for specs for C++. + Copyright (C) 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is the contribution to the `default_compilers' array in gcc.c for + g++. */ + + {".cc", "@c++"}, + {".cxx", "@c++"}, + {".cpp", "@c++"}, + {".c++", "@c++"}, + {".C", "@c++"}, + {"@c++", + "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ + %{C:%{!E:%eGNU C++ does not support -C without using -E}}\ + %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ + -undef -D__GNUC__=%v1 -D__GNUG__=%v1 -D__cplusplus -D__GNUC_MINOR__=%v2\ + %{ansi:-trigraphs -$ -D__STRICT_ANSI__} %{!undef:%{!ansi:%p} %P}\ + %c %{O*:%{!O0:-D__OPTIMIZE__}} %{traditional} %{ftraditional:-traditional}\ + %{traditional-cpp:-traditional} %{trigraphs}\ + %{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\ + %i %{!M:%{!MM:%{!E:%{!pipe:%g.ii}}}}%{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}} |\n", + "%{!M:%{!MM:%{!E:cc1plus %{!pipe:%g.ii} %1 %2\ + %{!Q:-quiet} -dumpbase %b.cc %{d*} %{m*} %{a}\ + %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\ + %{traditional} %{v:-version} %{pg:-p} %{p}\ + %{f*} %{+e*} %{aux-info*}\ + %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ + %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}}|\n\ + %{!S:as %a %Y\ + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ + %{!pipe:%g.s} %A\n }}}}"}, + {".ii", "@c++-cpp-output"}, + {"@c++-cpp-output", + "%{!M:%{!MM:%{!E:cc1plus %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\ + %{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\ + %{traditional} %{v:-version} %{pg:-p} %{p}\ + %{f*} %{+e*} %{aux-info*}\ + %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ + %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ + %{!S:as %a %Y\ + %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ + %{!pipe:%g.s} %A\n }}}}"}, diff --git a/contrib/gcc/cp/lex.c b/contrib/gcc/cp/lex.c new file mode 100644 index 00000000000..1861f9ea977 --- /dev/null +++ b/contrib/gcc/cp/lex.c @@ -0,0 +1,4717 @@ +/* Separate lexical analyzer for GNU C++. + Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is the lexical analyzer for GNU C++. */ + +/* Cause the `yydebug' variable to be defined. */ +#define YYDEBUG 1 + +#include +#include +#include +#include +#include "config.h" +#include "input.h" +#include "tree.h" +#include "lex.h" +#include "parse.h" +#include "cp-tree.h" +#include "flags.h" +#include "obstack.h" +#include "c-pragma.h" + +#ifdef MULTIBYTE_CHARS +#include +#include +#endif + +#ifndef errno +extern int errno; /* needed for VAX. */ +#endif +extern jmp_buf toplevel; + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +extern struct obstack *expression_obstack, permanent_obstack; +extern struct obstack *current_obstack, *saveable_obstack; + +extern double atof (); + +extern char *get_directive_line (); /* In c-common.c */ + +/* Given a file name X, return the nondirectory portion. + Keep in mind that X can be computed more than once. */ +#ifndef FILE_NAME_NONDIRECTORY +#define FILE_NAME_NONDIRECTORY(X) \ + (rindex (X, '/') != 0 ? rindex (X, '/') + 1 : X) +#endif + +extern char *index (); +extern char *rindex (); + +void extract_interface_info (); +void yyerror (); + +/* This obstack is needed to hold text. It is not safe to use + TOKEN_BUFFER because `check_newline' calls `yylex'. */ +struct obstack inline_text_obstack; +static char *inline_text_firstobj; + +/* This obstack is used to hold information about methods to be + synthesized. It should go away when synthesized methods are handled + properly (i.e. only when needed). */ +struct obstack synth_obstack; +static char *synth_firstobj; + +int end_of_file; + +/* Pending language change. + Positive is push count, negative is pop count. */ +int pending_lang_change = 0; + +/* Wrap the current header file in extern "C". */ +static int c_header_level = 0; + +extern int first_token; +extern struct obstack token_obstack; + +/* ??? Don't really know where this goes yet. */ +#if 1 +#include "input.c" +#else +extern void put_back (/* int */); +extern int input_redirected (); +extern void feed_input (/* char *, int, struct obstack * */); +#endif + +/* Holds translations from TREE_CODEs to operator name strings, + i.e., opname_tab[PLUS_EXPR] == "+". */ +char **opname_tab; +char **assignop_tab; + +extern int yychar; /* the lookahead symbol */ +extern YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#if 0 +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + + +/* the declaration found for the last IDENTIFIER token read in. + yylex must look this up to detect typedefs, which get token type TYPENAME, + so it is left around in case the identifier is not a typedef but is + used in a context which makes it a reference to a variable. */ +tree lastiddecl; + +/* The elements of `ridpointers' are identifier nodes + for the reserved type names and storage classes. + It is indexed by a RID_... value. */ +tree ridpointers[(int) RID_MAX]; + +/* We may keep statistics about how long which files took to compile. */ +static int header_time, body_time; +static tree get_time_identifier (); +static tree filename_times; +static tree this_filename_time; + +/* For implementing #pragma unit. */ +tree current_unit_name; +tree current_unit_language; + +/* Array for holding counts of the numbers of tokens seen. */ +extern int *token_count; + +/* Textual definition used for default functions. */ +static void default_copy_constructor_body (); +static void default_assign_ref_body (); + +/* Return something to represent absolute declarators containing a *. + TARGET is the absolute declarator that the * contains. + TYPE_QUALS is a list of modifiers such as const or volatile + to apply to the pointer type, represented as identifiers. + + We return an INDIRECT_REF whose "contents" are TARGET + and whose type is the modifier list. */ + +tree +make_pointer_declarator (type_quals, target) + tree type_quals, target; +{ + if (target && TREE_CODE (target) == IDENTIFIER_NODE + && ANON_AGGRNAME_P (target)) + error ("type name expected before `*'"); + target = build_parse_node (INDIRECT_REF, target); + TREE_TYPE (target) = type_quals; + return target; +} + +/* Return something to represent absolute declarators containing a &. + TARGET is the absolute declarator that the & contains. + TYPE_QUALS is a list of modifiers such as const or volatile + to apply to the reference type, represented as identifiers. + + We return an ADDR_EXPR whose "contents" are TARGET + and whose type is the modifier list. */ + +tree +make_reference_declarator (type_quals, target) + tree type_quals, target; +{ + if (target) + { + if (TREE_CODE (target) == ADDR_EXPR) + { + error ("cannot declare references to references"); + return target; + } + if (TREE_CODE (target) == INDIRECT_REF) + { + error ("cannot declare pointers to references"); + return target; + } + if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target)) + error ("type name expected before `&'"); + } + target = build_parse_node (ADDR_EXPR, target); + TREE_TYPE (target) = type_quals; + return target; +} + +/* Build names and nodes for overloaded operators. */ + +tree ansi_opname[LAST_CPLUS_TREE_CODE]; +tree ansi_assopname[LAST_CPLUS_TREE_CODE]; + +char * +operator_name_string (name) + tree name; +{ + char *opname = IDENTIFIER_POINTER (name) + 2; + tree *opname_table; + int i, assign; + + /* Works for builtin and user defined types. */ + if (IDENTIFIER_GLOBAL_VALUE (name) + && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL) + return IDENTIFIER_POINTER (name); + + if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_') + { + opname += 1; + assign = 1; + opname_table = ansi_assopname; + } + else + { + assign = 0; + opname_table = ansi_opname; + } + + for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) + { + if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign] + && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign]) + break; + } + + if (i == LAST_CPLUS_TREE_CODE) + return ""; + + if (assign) + return assignop_tab[i]; + else + return opname_tab[i]; +} + +int interface_only; /* whether or not current file is only for + interface definitions. */ +int interface_unknown; /* whether or not we know this class + to behave according to #pragma interface. */ + +/* lexical analyzer */ + +/* File used for outputting assembler code. */ +extern FILE *asm_out_file; + +#ifndef WCHAR_TYPE_SIZE +#ifdef INT_TYPE_SIZE +#define WCHAR_TYPE_SIZE INT_TYPE_SIZE +#else +#define WCHAR_TYPE_SIZE BITS_PER_WORD +#endif +#endif + +/* Number of bytes in a wide character. */ +#define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT) + +static int maxtoken; /* Current nominal length of token buffer. */ +char *token_buffer; /* Pointer to token buffer. + Actual allocated length is maxtoken + 2. */ + +#include "hash.h" + +int check_newline (); + +/* Nonzero tells yylex to ignore \ in string constants. */ +static int ignore_escape_flag = 0; + +static int skip_white_space (); + +static tree +get_time_identifier (name) + char *name; +{ + tree time_identifier; + int len = strlen (name); + char *buf = (char *) alloca (len + 6); + strcpy (buf, "file "); + bcopy (name, buf+5, len); + buf[len+5] = '\0'; + time_identifier = get_identifier (buf); + if (IDENTIFIER_LOCAL_VALUE (time_identifier) == NULL_TREE) + { + push_obstacks_nochange (); + end_temporary_allocation (); + IDENTIFIER_LOCAL_VALUE (time_identifier) = build_int_2 (0, 0); + IDENTIFIER_CLASS_VALUE (time_identifier) = build_int_2 (0, 1); + IDENTIFIER_GLOBAL_VALUE (time_identifier) = filename_times; + filename_times = time_identifier; + pop_obstacks (); + } + return time_identifier; +} + +#ifdef __GNUC__ +__inline +#endif +static int +my_get_run_time () +{ + int old_quiet_flag = quiet_flag; + int this_time; + quiet_flag = 0; + this_time = get_run_time (); + quiet_flag = old_quiet_flag; + return this_time; +} + +/* Table indexed by tree code giving a string containing a character + classifying the tree code. Possibilities are + t, d, s, c, r, <, 1 and 2. See cp/tree.def for details. */ + +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, + +char *cplus_tree_code_type[] = { + "x", +#include "tree.def" +}; +#undef DEFTREECODE + +/* Table indexed by tree code giving number of expression + operands beyond the fixed part of the node structure. + Not used for types or decls. */ + +#define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, + +int cplus_tree_code_length[] = { + 0, +#include "tree.def" +}; +#undef DEFTREECODE + +/* Names of tree components. + Used for printing out the tree and error messages. */ +#define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, + +char *cplus_tree_code_name[] = { + "@@dummy", +#include "tree.def" +}; +#undef DEFTREECODE + +/* toplev.c needs to call these. */ + +void +lang_init () +{ + /* the beginning of the file is a new line; check for # */ + /* With luck, we discover the real source file's name from that + and put it in input_filename. */ + put_back (check_newline ()); + + if (flag_cadillac) + cadillac_start (); + if (flag_gnu_xref) GNU_xref_begin (input_filename); + init_repo (input_filename); +} + +void +lang_finish () +{ + extern int errorcount, sorrycount; + if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount); +} + +char * +lang_identify () +{ + return "cplusplus"; +} + +void +init_filename_times () +{ + this_filename_time = get_time_identifier (""); + if (flag_detailed_statistics) + { + header_time = 0; + body_time = my_get_run_time (); + TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) = body_time; + } +} + +/* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989. + Stuck this hack in to get the files open correctly; this is called + in place of init_lex if we are an unexec'd binary. */ +void +reinit_lang_specific () +{ + init_filename_times (); + reinit_search_statistics (); +} + +void +init_lex () +{ + extern char *(*decl_printable_name) (); + extern int flag_no_gnu_keywords; + extern int flag_operator_names; + + int i; + + /* Initialize the lookahead machinery. */ + init_spew (); + + /* Make identifier nodes long enough for the language-specific slots. */ + set_identifier_size (sizeof (struct lang_identifier)); + decl_printable_name = lang_printable_name; + + init_cplus_expand (); + + tree_code_type + = (char **) realloc (tree_code_type, + sizeof (char *) * LAST_CPLUS_TREE_CODE); + tree_code_length + = (int *) realloc (tree_code_length, + sizeof (int) * LAST_CPLUS_TREE_CODE); + tree_code_name + = (char **) realloc (tree_code_name, + sizeof (char *) * LAST_CPLUS_TREE_CODE); + bcopy ((char *)cplus_tree_code_type, + (char *)(tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE), + (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *)); + bcopy ((char *)cplus_tree_code_length, + (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE), + (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int)); + bcopy ((char *)cplus_tree_code_name, + (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE), + (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *)); + + opname_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); + bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); + assignop_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *)); + bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *)); + + ansi_opname[0] = get_identifier (""); + for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++) + { + ansi_opname[i] = ansi_opname[0]; + ansi_assopname[i] = ansi_opname[0]; + } + + ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1; + ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR]; + ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1; + ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR]; + ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1; + ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1; + ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; + ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; + ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR]; + ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1; + ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR]; + ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1; + ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR]; + ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1; + ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1; + ansi_opname[(int) NE_EXPR] = get_identifier ("__ne"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1; + ansi_opname[(int) GT_EXPR] = get_identifier ("__gt"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1; + ansi_opname[(int) GE_EXPR] = get_identifier ("__ge"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1; + ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1; + ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1; + ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1; + ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1; + ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1; + ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR]; + ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1; + ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR]; + ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1; + ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1; + ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1; + ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; + ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; + ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; + ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR]; + ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl"); + ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; + ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; + ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; + ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR]; + IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1; + ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1; + ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR]; + ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR]; + ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1; + ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1; + ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1; + ansi_opname[(int) LT_EXPR] = get_identifier ("__lt"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1; + ansi_opname[(int) LE_EXPR] = get_identifier ("__le"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1; + ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1; + ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1; + ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR]; + ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR]; + ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1; + ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer"); + IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1; + ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1; + ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1; + ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1; + ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR]; + ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1; + ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1; + ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1; + ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1; + ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1; + ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1; + ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1; + ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1; + ansi_opname[(int) TYPE_EXPR] = get_identifier ("__op"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1; + + /* This is not true: these operators are not defined in ANSI, + but we need them anyway. */ + ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1; + ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1; + ansi_opname[(int) COND_EXPR] = get_identifier ("__cn"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1; + ansi_opname[(int) METHOD_CALL_EXPR] = get_identifier ("__wr"); + IDENTIFIER_OPNAME_P (ansi_opname[(int) METHOD_CALL_EXPR]) = 1; + + init_method (); + init_error (); + gcc_obstack_init (&inline_text_obstack); + inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0); + gcc_obstack_init (&synth_obstack); + synth_firstobj = (char *) obstack_alloc (&synth_obstack, 0); + + /* Start it at 0, because check_newline is called at the very beginning + and will increment it to 1. */ + lineno = 0; + input_filename = ""; + current_function_decl = NULL; + + maxtoken = 40; + token_buffer = (char *) xmalloc (maxtoken + 2); + + ridpointers[(int) RID_INT] = get_identifier ("int"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INT], + build_tree_list (NULL_TREE, ridpointers[(int) RID_INT])); + ridpointers[(int) RID_BOOL] = get_identifier ("bool"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_BOOL], + build_tree_list (NULL_TREE, ridpointers[(int) RID_BOOL])); + ridpointers[(int) RID_CHAR] = get_identifier ("char"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CHAR], + build_tree_list (NULL_TREE, ridpointers[(int) RID_CHAR])); + ridpointers[(int) RID_VOID] = get_identifier ("void"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOID], + build_tree_list (NULL_TREE, ridpointers[(int) RID_VOID])); + ridpointers[(int) RID_FLOAT] = get_identifier ("float"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FLOAT], + build_tree_list (NULL_TREE, ridpointers[(int) RID_FLOAT])); + ridpointers[(int) RID_DOUBLE] = get_identifier ("double"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_DOUBLE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_DOUBLE])); + ridpointers[(int) RID_SHORT] = get_identifier ("short"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SHORT], + build_tree_list (NULL_TREE, ridpointers[(int) RID_SHORT])); + ridpointers[(int) RID_LONG] = get_identifier ("long"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_LONG], + build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG])); + ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_UNSIGNED], + build_tree_list (NULL_TREE, ridpointers[(int) RID_UNSIGNED])); + ridpointers[(int) RID_SIGNED] = get_identifier ("signed"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SIGNED], + build_tree_list (NULL_TREE, ridpointers[(int) RID_SIGNED])); + ridpointers[(int) RID_INLINE] = get_identifier ("inline"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INLINE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_INLINE])); + ridpointers[(int) RID_CONST] = get_identifier ("const"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CONST], + build_tree_list (NULL_TREE, ridpointers[(int) RID_CONST])); + ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOLATILE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_VOLATILE])); + ridpointers[(int) RID_AUTO] = get_identifier ("auto"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_AUTO], + build_tree_list (NULL_TREE, ridpointers[(int) RID_AUTO])); + ridpointers[(int) RID_STATIC] = get_identifier ("static"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_STATIC], + build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC])); + ridpointers[(int) RID_EXTERN] = get_identifier ("extern"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXTERN], + build_tree_list (NULL_TREE, ridpointers[(int) RID_EXTERN])); + ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TYPEDEF], + build_tree_list (NULL_TREE, ridpointers[(int) RID_TYPEDEF])); + ridpointers[(int) RID_REGISTER] = get_identifier ("register"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_REGISTER], + build_tree_list (NULL_TREE, ridpointers[(int) RID_REGISTER])); + + /* C++ extensions. These are probably not correctly named. */ + ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_WCHAR], + build_tree_list (NULL_TREE, ridpointers[(int) RID_WCHAR])); + class_type_node = build_int_2 (class_type, 0); + TREE_TYPE (class_type_node) = class_type_node; + ridpointers[(int) RID_CLASS] = class_type_node; + + record_type_node = build_int_2 (record_type, 0); + TREE_TYPE (record_type_node) = record_type_node; + ridpointers[(int) RID_RECORD] = record_type_node; + + union_type_node = build_int_2 (union_type, 0); + TREE_TYPE (union_type_node) = union_type_node; + ridpointers[(int) RID_UNION] = union_type_node; + + enum_type_node = build_int_2 (enum_type, 0); + TREE_TYPE (enum_type_node) = enum_type_node; + ridpointers[(int) RID_ENUM] = enum_type_node; + + ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VIRTUAL], + build_tree_list (NULL_TREE, ridpointers[(int) RID_VIRTUAL])); + ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXPLICIT], + build_tree_list (NULL_TREE, ridpointers[(int) RID_EXPLICIT])); + ridpointers[(int) RID_FRIEND] = get_identifier ("friend"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FRIEND], + build_tree_list (NULL_TREE, ridpointers[(int) RID_FRIEND])); + + ridpointers[(int) RID_PUBLIC] = get_identifier ("public"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PUBLIC], + build_tree_list (NULL_TREE, ridpointers[(int) RID_PUBLIC])); + ridpointers[(int) RID_PRIVATE] = get_identifier ("private"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PRIVATE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_PRIVATE])); + ridpointers[(int) RID_PROTECTED] = get_identifier ("protected"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PROTECTED], + build_tree_list (NULL_TREE, ridpointers[(int) RID_PROTECTED])); + ridpointers[(int) RID_TEMPLATE] = get_identifier ("template"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TEMPLATE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_TEMPLATE])); + /* This is for ANSI C++. */ + ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable"); + SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_MUTABLE], + build_tree_list (NULL_TREE, ridpointers[(int) RID_MUTABLE])); + + /* Signature handling extensions. */ + signature_type_node = build_int_2 (signature_type, 0); + TREE_TYPE (signature_type_node) = signature_type_node; + ridpointers[(int) RID_SIGNATURE] = signature_type_node; + + opname_tab[(int) COMPONENT_REF] = "->"; + opname_tab[(int) MEMBER_REF] = "->*"; + opname_tab[(int) METHOD_CALL_EXPR] = "->()"; + opname_tab[(int) INDIRECT_REF] = "(unary *)"; + opname_tab[(int) ARRAY_REF] = "[]"; + opname_tab[(int) MODIFY_EXPR] = "="; + opname_tab[(int) NEW_EXPR] = "new"; + opname_tab[(int) DELETE_EXPR] = "delete"; + opname_tab[(int) VEC_NEW_EXPR] = "new []"; + opname_tab[(int) VEC_DELETE_EXPR] = "delete []"; + opname_tab[(int) COND_EXPR] = "... ? ... : ..."; + opname_tab[(int) CALL_EXPR] = "()"; + opname_tab[(int) PLUS_EXPR] = "+"; + opname_tab[(int) MINUS_EXPR] = "-"; + opname_tab[(int) MULT_EXPR] = "*"; + opname_tab[(int) TRUNC_DIV_EXPR] = "/"; + opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)"; + opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)"; + opname_tab[(int) ROUND_DIV_EXPR] = "(round /)"; + opname_tab[(int) TRUNC_MOD_EXPR] = "%"; + opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)"; + opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)"; + opname_tab[(int) ROUND_MOD_EXPR] = "(round %)"; + opname_tab[(int) NEGATE_EXPR] = "-"; + opname_tab[(int) MIN_EXPR] = "?"; + opname_tab[(int) ABS_EXPR] = "abs"; + opname_tab[(int) FFS_EXPR] = "ffs"; + opname_tab[(int) LSHIFT_EXPR] = "<<"; + opname_tab[(int) RSHIFT_EXPR] = ">>"; + opname_tab[(int) BIT_IOR_EXPR] = "|"; + opname_tab[(int) BIT_XOR_EXPR] = "^"; + opname_tab[(int) BIT_AND_EXPR] = "&"; + opname_tab[(int) BIT_ANDTC_EXPR] = "&~"; + opname_tab[(int) BIT_NOT_EXPR] = "~"; + opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&"; + opname_tab[(int) TRUTH_ORIF_EXPR] = "||"; + opname_tab[(int) TRUTH_AND_EXPR] = "strict &&"; + opname_tab[(int) TRUTH_OR_EXPR] = "strict ||"; + opname_tab[(int) TRUTH_NOT_EXPR] = "!"; + opname_tab[(int) LT_EXPR] = "<"; + opname_tab[(int) LE_EXPR] = "<="; + opname_tab[(int) GT_EXPR] = ">"; + opname_tab[(int) GE_EXPR] = ">="; + opname_tab[(int) EQ_EXPR] = "=="; + opname_tab[(int) NE_EXPR] = "!="; + opname_tab[(int) IN_EXPR] = "in"; + opname_tab[(int) RANGE_EXPR] = ".."; + opname_tab[(int) CONVERT_EXPR] = "(unary +)"; + opname_tab[(int) ADDR_EXPR] = "(unary &)"; + opname_tab[(int) PREDECREMENT_EXPR] = "--"; + opname_tab[(int) PREINCREMENT_EXPR] = "++"; + opname_tab[(int) POSTDECREMENT_EXPR] = "--"; + opname_tab[(int) POSTINCREMENT_EXPR] = "++"; + opname_tab[(int) COMPOUND_EXPR] = ","; + + assignop_tab[(int) NOP_EXPR] = "="; + assignop_tab[(int) PLUS_EXPR] = "+="; + assignop_tab[(int) CONVERT_EXPR] = "+="; + assignop_tab[(int) MINUS_EXPR] = "-="; + assignop_tab[(int) NEGATE_EXPR] = "-="; + assignop_tab[(int) MULT_EXPR] = "*="; + assignop_tab[(int) INDIRECT_REF] = "*="; + assignop_tab[(int) TRUNC_DIV_EXPR] = "/="; + assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)"; + assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)"; + assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)"; + assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)"; + assignop_tab[(int) TRUNC_MOD_EXPR] = "%="; + assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)"; + assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)"; + assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)"; + assignop_tab[(int) MIN_EXPR] = "?="; + assignop_tab[(int) LSHIFT_EXPR] = "<<="; + assignop_tab[(int) RSHIFT_EXPR] = ">>="; + assignop_tab[(int) BIT_IOR_EXPR] = "|="; + assignop_tab[(int) BIT_XOR_EXPR] = "^="; + assignop_tab[(int) BIT_AND_EXPR] = "&="; + assignop_tab[(int) ADDR_EXPR] = "&="; + + init_filename_times (); + + /* Some options inhibit certain reserved words. + Clear those words out of the hash table so they won't be recognized. */ +#define UNSET_RESERVED_WORD(STRING) \ + do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \ + if (s) s->name = ""; } while (0) + +#if 0 + /* let's parse things, and if they use it, then give them an error. */ + if (!flag_handle_exceptions) + { + UNSET_RESERVED_WORD ("throw"); + UNSET_RESERVED_WORD ("try"); + UNSET_RESERVED_WORD ("catch"); + } +#endif + + if (! (flag_gc || flag_rtti) || flag_no_gnu_keywords) + { + UNSET_RESERVED_WORD ("classof"); + UNSET_RESERVED_WORD ("headof"); + } + if (! flag_handle_signatures || flag_no_gnu_keywords) + { + /* Easiest way to not recognize signature + handling extensions... */ + UNSET_RESERVED_WORD ("signature"); + UNSET_RESERVED_WORD ("sigof"); + } + if (flag_no_asm || flag_no_gnu_keywords) + UNSET_RESERVED_WORD ("typeof"); + if (! flag_operator_names) + { + /* These are new ANSI keywords that may break code. */ + UNSET_RESERVED_WORD ("and"); + UNSET_RESERVED_WORD ("and_eq"); + UNSET_RESERVED_WORD ("bitand"); + UNSET_RESERVED_WORD ("bitor"); + UNSET_RESERVED_WORD ("compl"); + UNSET_RESERVED_WORD ("not"); + UNSET_RESERVED_WORD ("not_eq"); + UNSET_RESERVED_WORD ("or"); + UNSET_RESERVED_WORD ("or_eq"); + UNSET_RESERVED_WORD ("xor"); + UNSET_RESERVED_WORD ("xor_eq"); + } + if (! flag_traditional) + UNSET_RESERVED_WORD ("overload"); + + token_count = init_parse (); + interface_unknown = 1; +} + +void +reinit_parse_for_function () +{ + current_base_init_list = NULL_TREE; + current_member_init_list = NULL_TREE; +} + +#ifdef __GNUC__ +__inline +#endif +void +yyprint (file, yychar, yylval) + FILE *file; + int yychar; + YYSTYPE yylval; +{ + tree t; + switch (yychar) + { + case IDENTIFIER: + case TYPENAME: + case TYPESPEC: + case PTYPENAME: + case IDENTIFIER_DEFN: + case TYPENAME_DEFN: + case PTYPENAME_DEFN: + case TYPENAME_ELLIPSIS: + case SCSPEC: + case PRE_PARSED_CLASS_DECL: + t = yylval.ttype; + my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224); + if (IDENTIFIER_POINTER (t)) + fprintf (file, " `%s'", IDENTIFIER_POINTER (t)); + break; + case AGGR: + if (yylval.ttype == class_type_node) + fprintf (file, " `class'"); + else if (yylval.ttype == record_type_node) + fprintf (file, " `struct'"); + else if (yylval.ttype == union_type_node) + fprintf (file, " `union'"); + else if (yylval.ttype == enum_type_node) + fprintf (file, " `enum'"); + else if (yylval.ttype == signature_type_node) + fprintf (file, " `signature'"); + else + my_friendly_abort (80); + break; + } +} + +static int *reduce_count; +int *token_count; + +#define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0])) +#define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0])) + +int * +init_parse () +{ +#ifdef GATHER_STATISTICS + reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1)); + bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1)); + reduce_count += 1; + token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1)); + bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1)); + token_count += 1; +#endif + return token_count; +} + +#ifdef GATHER_STATISTICS +void +yyhook (yyn) + int yyn; +{ + reduce_count[yyn] += 1; +} + +static int +reduce_cmp (p, q) + int *p, *q; +{ + return reduce_count[*q] - reduce_count[*p]; +} + +static int +token_cmp (p, q) + int *p, *q; +{ + return token_count[*q] - token_count[*p]; +} +#endif + +void +print_parse_statistics () +{ +#ifdef GATHER_STATISTICS +#if YYDEBUG != 0 + int i; + int maxlen = REDUCE_LENGTH; + unsigned *sorted; + + if (reduce_count[-1] == 0) + return; + + if (TOKEN_LENGTH > REDUCE_LENGTH) + maxlen = TOKEN_LENGTH; + sorted = (unsigned *) alloca (sizeof (int) * maxlen); + + for (i = 0; i < TOKEN_LENGTH; i++) + sorted[i] = i; + qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp); + for (i = 0; i < TOKEN_LENGTH; i++) + { + int index = sorted[i]; + if (token_count[index] == 0) + break; + if (token_count[index] < token_count[-1]) + break; + fprintf (stderr, "token %d, `%s', count = %d\n", + index, yytname[YYTRANSLATE (index)], token_count[index]); + } + fprintf (stderr, "\n"); + for (i = 0; i < REDUCE_LENGTH; i++) + sorted[i] = i; + qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp); + for (i = 0; i < REDUCE_LENGTH; i++) + { + int index = sorted[i]; + if (reduce_count[index] == 0) + break; + if (reduce_count[index] < reduce_count[-1]) + break; + fprintf (stderr, "rule %d, line %d, count = %d\n", + index, yyrline[index], reduce_count[index]); + } + fprintf (stderr, "\n"); +#endif +#endif +} + +/* Sets the value of the 'yydebug' variable to VALUE. + This is a function so we don't have to have YYDEBUG defined + in order to build the compiler. */ +void +set_yydebug (value) + int value; +{ +#if YYDEBUG != 0 + extern int yydebug; + yydebug = value; +#else + warning ("YYDEBUG not defined."); +#endif +} + + +/* Functions and data structures for #pragma interface. + + `#pragma implementation' means that the main file being compiled + is considered to implement (provide) the classes that appear in + its main body. I.e., if this is file "foo.cc", and class `bar' + is defined in "foo.cc", then we say that "foo.cc implements bar". + + All main input files "implement" themselves automagically. + + `#pragma interface' means that unless this file (of the form "foo.h" + is not presently being included by file "foo.cc", the + CLASSTYPE_INTERFACE_ONLY bit gets set. The effect is that none + of the vtables nor any of the inline functions defined in foo.h + will ever be output. + + There are cases when we want to link files such as "defs.h" and + "main.cc". In this case, we give "defs.h" a `#pragma interface', + and "main.cc" has `#pragma implementation "defs.h"'. */ + +struct impl_files +{ + char *filename; + struct impl_files *next; +}; + +static struct impl_files *impl_file_chain; + +/* Helper function to load global variables with interface + information. */ +void +extract_interface_info () +{ + tree fileinfo = 0; + + if (flag_alt_external_templates) + { + struct tinst_level *til = tinst_for_decl (); + + if (til) + fileinfo = get_time_identifier (til->file); + } + if (!fileinfo) + fileinfo = get_time_identifier (input_filename); + fileinfo = IDENTIFIER_CLASS_VALUE (fileinfo); + interface_only = TREE_INT_CST_LOW (fileinfo); + if (!processing_template_defn || flag_external_templates) + interface_unknown = TREE_INT_CST_HIGH (fileinfo); +} + +/* Return nonzero if S is not considered part of an + INTERFACE/IMPLEMENTATION pair. Otherwise, return 0. */ +static int +interface_strcmp (s) + char *s; +{ + /* Set the interface/implementation bits for this scope. */ + struct impl_files *ifiles; + char *s1; + + for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next) + { + char *t1 = ifiles->filename; + s1 = s; + + if (*s1 != *t1 || *s1 == 0) + continue; + + while (*s1 == *t1 && *s1 != 0) + s1++, t1++; + + /* A match. */ + if (*s1 == *t1) + return 0; + + /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc. */ + if (index (s1, '.') || index (t1, '.')) + continue; + + if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.') + continue; + + /* A match. */ + return 0; + } + + /* No matches. */ + return 1; +} + +void +set_typedecl_interface_info (prev, vars) + tree prev, vars; +{ + tree id = get_time_identifier (DECL_SOURCE_FILE (vars)); + tree fileinfo = IDENTIFIER_CLASS_VALUE (id); + tree type = TREE_TYPE (vars); + + CLASSTYPE_INTERFACE_ONLY (type) = TREE_INT_CST_LOW (fileinfo) + = interface_strcmp (FILE_NAME_NONDIRECTORY (DECL_SOURCE_FILE (vars))); +} + +void +set_vardecl_interface_info (prev, vars) + tree prev, vars; +{ + tree type = DECL_CONTEXT (vars); + + if (CLASSTYPE_INTERFACE_KNOWN (type)) + { + if (CLASSTYPE_INTERFACE_ONLY (type)) + set_typedecl_interface_info (prev, TYPE_NAME (type)); + else + CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 1; + DECL_EXTERNAL (vars) = CLASSTYPE_INTERFACE_ONLY (type); + TREE_PUBLIC (vars) = 1; + } +} + +/* Called from the top level: if there are any pending inlines to + do, set up to process them now. This function sets up the first function + to be parsed; after it has been, the rule for fndef in parse.y will + call process_next_inline to start working on the next one. */ +void +do_pending_inlines () +{ + struct pending_inline *t; + + /* Oops, we're still dealing with the last batch. */ + if (yychar == PRE_PARSED_FUNCTION_DECL) + return; + + /* Reverse the pending inline functions, since + they were cons'd instead of appended. */ + { + struct pending_inline *prev = 0, *tail, *bottom = 0; + t = pending_inlines; + pending_inlines = 0; + + for (; t; t = tail) + { + tail = t->next; + t->next = prev; + t->deja_vu = 1; + prev = t; + } + + /* This kludge should go away when synthesized methods are handled + properly, i.e. only when needed. */ + for (t = prev; t; t = t->next) + { + if (t->lineno <= 0) + { + tree f = t->fndecl; + DECL_PENDING_INLINE_INFO (f) = 0; + interface_unknown = t->interface == 1; + interface_only = t->interface == 0; + synthesize_method (f); + if (tail) + tail->next = t->next; + else + prev = t->next; + if (! bottom) + bottom = t; + } + else + tail = t; + } + if (bottom) + { + obstack_free (&synth_obstack, bottom); + extract_interface_info (); + } + t = prev; + } + + if (t == 0) + return; + + /* Now start processing the first inline function. */ + my_friendly_assert ((t->parm_vec == NULL_TREE) == (t->bindings == NULL_TREE), + 226); + if (t->parm_vec) + push_template_decls (t->parm_vec, t->bindings, 0); + if (t->len > 0) + { + feed_input (t->buf, t->len, t->can_free ? &inline_text_obstack : 0); + lineno = t->lineno; +#if 0 + if (input_filename != t->filename) + { + input_filename = t->filename; + /* Get interface/implementation back in sync. */ + extract_interface_info (); + } +#else + input_filename = t->filename; + interface_unknown = t->interface == 1; + interface_only = t->interface == 0; +#endif + yychar = PRE_PARSED_FUNCTION_DECL; + } + /* Pass back a handle on the rest of the inline functions, so that they + can be processed later. */ + yylval.ttype = build_tree_list ((tree) t, t->fndecl); +#if 0 + if (flag_default_inline && t->fndecl + /* If we're working from a template, don't change + the `inline' state. */ + && t->parm_vec == NULL_TREE) + DECL_INLINE (t->fndecl) = 1; +#endif + DECL_PENDING_INLINE_INFO (t->fndecl) = 0; +} + +extern struct pending_input *to_be_restored; +static int nextchar = -1; + +/* Called from the fndecl rule in the parser when the function just parsed + was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from + do_pending_inlines). */ +void +process_next_inline (t) + tree t; +{ + struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t); + my_friendly_assert ((i->parm_vec == NULL_TREE) == (i->bindings == NULL_TREE), + 227); + if (i->parm_vec) + pop_template_decls (i->parm_vec, i->bindings, 0); + i = i->next; + if (yychar == YYEMPTY) + yychar = yylex (); + if (yychar != END_OF_SAVED_INPUT) + { + error ("parse error at end of saved function text"); + /* restore_pending_input will abort unless yychar is either + * END_OF_SAVED_INPUT or YYEMPTY; since we already know we're + * hosed, feed back YYEMPTY. + * We also need to discard nextchar, since that may have gotten + * set as well. + */ + nextchar = -1; + } + yychar = YYEMPTY; + if (to_be_restored == 0) + my_friendly_abort (123); + restore_pending_input (to_be_restored); + to_be_restored = 0; + if (i && i->fndecl != NULL_TREE) + { + my_friendly_assert ((i->parm_vec == NULL_TREE) == (i->bindings == NULL_TREE), + 228); + if (i->parm_vec) + push_template_decls (i->parm_vec, i->bindings, 0); + feed_input (i->buf, i->len, i->can_free ? &inline_text_obstack : 0); + lineno = i->lineno; + input_filename = i->filename; + yychar = PRE_PARSED_FUNCTION_DECL; + yylval.ttype = build_tree_list ((tree) i, i->fndecl); +#if 0 + if (flag_default_inline + /* If we're working from a template, don't change + the `inline' state. */ + && i->parm_vec == NULL_TREE) + DECL_INLINE (i->fndecl) = 1; +#endif + DECL_PENDING_INLINE_INFO (i->fndecl) = 0; + } + if (i) + { + interface_unknown = i->interface == 1; + interface_only = i->interface == 0; + } + else + extract_interface_info (); +} + +/* Since inline methods can refer to text which has not yet been seen, + we store the text of the method in a structure which is placed in the + DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL. + After parsing the body of the class definition, the FUNCTION_DECL's are + scanned to see which ones have this field set. Those are then digested + one at a time. + + This function's FUNCTION_DECL will have a bit set in its common so + that we know to watch out for it. */ + +static void +consume_string (this_obstack, matching_char) + register struct obstack *this_obstack; + int matching_char; +{ + register int c; + int starting_lineno = lineno; + do + { + c = getch (); + if (c == EOF) + { + int save_lineno = lineno; + lineno = starting_lineno; + if (matching_char == '"') + error ("end of file encountered inside string constant"); + else + error ("end of file encountered inside character constant"); + lineno = save_lineno; + return; + } + if (c == '\\') + { + obstack_1grow (this_obstack, c); + c = getch (); + obstack_1grow (this_obstack, c); + + /* Make sure we continue the loop */ + c = 0; + continue; + } + if (c == '\n') + { + if (pedantic) + pedwarn ("ANSI C++ forbids newline in string constant"); + lineno++; + } + obstack_1grow (this_obstack, c); + } + while (c != matching_char); +} + +static int nextyychar = YYEMPTY; +static YYSTYPE nextyylval; + +struct pending_input { + int nextchar, yychar, nextyychar, eof; + YYSTYPE yylval, nextyylval; + struct obstack token_obstack; + int first_token; +}; + +struct pending_input * +save_pending_input () +{ + struct pending_input *p; + p = (struct pending_input *) xmalloc (sizeof (struct pending_input)); + p->nextchar = nextchar; + p->yychar = yychar; + p->nextyychar = nextyychar; + p->yylval = yylval; + p->nextyylval = nextyylval; + p->eof = end_of_file; + yychar = nextyychar = YYEMPTY; + nextchar = -1; + p->first_token = first_token; + p->token_obstack = token_obstack; + + first_token = 0; + gcc_obstack_init (&token_obstack); + end_of_file = 0; + return p; +} + +void +restore_pending_input (p) + struct pending_input *p; +{ + my_friendly_assert (nextchar == -1, 229); + nextchar = p->nextchar; + my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230); + yychar = p->yychar; + my_friendly_assert (nextyychar == YYEMPTY, 231); + nextyychar = p->nextyychar; + yylval = p->yylval; + nextyylval = p->nextyylval; + first_token = p->first_token; + obstack_free (&token_obstack, (char *) 0); + token_obstack = p->token_obstack; + end_of_file = p->eof; + free (p); +} + +/* Return next non-whitespace input character, which may come + from `finput', or from `nextchar'. */ +static int +yynextch () +{ + int c; + + if (nextchar >= 0) + { + c = nextchar; + nextchar = -1; + } + else c = getch (); + return skip_white_space (c); +} + +/* Unget character CH from the input stream. + If RESCAN is non-zero, then we want to `see' this + character as the next input token. */ +void +yyungetc (ch, rescan) + int ch; + int rescan; +{ + /* Unget a character from the input stream. */ + if (yychar == YYEMPTY || rescan == 0) + { + if (nextchar >= 0) + put_back (nextchar); + nextchar = ch; + } + else + { + my_friendly_assert (nextyychar == YYEMPTY, 232); + nextyychar = yychar; + nextyylval = yylval; + yychar = ch; + } +} + +/* This function stores away the text for an inline function that should + be processed later. It decides how much later, and may need to move + the info between obstacks; therefore, the caller should not refer to + the T parameter after calling this function. + + This function also stores the list of template-parameter bindings that + will be needed for expanding the template, if any. */ + +static void +store_pending_inline (decl, t) + tree decl; + struct pending_inline *t; +{ + extern int processing_template_defn; + int delay_to_eof = 0; + struct pending_inline **inlines; + + t->fndecl = decl; + /* Default: compile right away, and no extra bindings are needed. */ + t->parm_vec = t->bindings = 0; + if (processing_template_defn) + { + tree type = current_class_type; + /* Assumption: In this (possibly) nested class sequence, only + one name will have template parms. */ + while (type && TREE_CODE_CLASS (TREE_CODE (type)) == 't') + { + tree decl = TYPE_NAME (type); + tree tmpl = IDENTIFIER_TEMPLATE (DECL_NAME (decl)); + if (tmpl) + { + t->parm_vec = DECL_TEMPLATE_INFO (TREE_PURPOSE (tmpl))->parm_vec; + t->bindings = TREE_VALUE (tmpl); + } + type = DECL_CONTEXT (decl); + } + if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE + || TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE) + { + if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) + my_friendly_assert (TYPE_MAX_VALUE (TREE_TYPE (decl)) == current_class_type, + 233); + + /* Inline functions can be compiled immediately. Other functions + will be output separately, so if we're in interface-only mode, + punt them now, or output them now if we're doing implementations + and we know no overrides will exist. Otherwise, we delay until + end-of-file, to see if the definition is really required. */ + if (DECL_THIS_INLINE (decl)) + /* delay_to_eof == 0 */; + else if (current_class_type && !interface_unknown) + { + if (interface_only) + { +#if 0 + print_node_brief (stderr, "\ndiscarding text for ", decl, 0); +#endif + if (t->can_free) + obstack_free (&inline_text_obstack, t->buf); + DECL_PENDING_INLINE_INFO (decl) = 0; + return; + } + } + /* Don't delay the processing of virtual functions. */ + else if (DECL_VINDEX (decl) == NULL_TREE) + delay_to_eof = 1; + } + else + my_friendly_abort (58); + } + + if (delay_to_eof) + { + extern struct pending_inline *pending_template_expansions; + + if (t->can_free) + { + char *free_to = t->buf; + t->buf = (char *) obstack_copy (&permanent_obstack, t->buf, + t->len + 1); + t = (struct pending_inline *) obstack_copy (&permanent_obstack, + (char *)t, sizeof (*t)); + obstack_free (&inline_text_obstack, free_to); + } + inlines = &pending_template_expansions; + t->can_free = 0; + } + else + { + inlines = &pending_inlines; + DECL_PENDING_INLINE_INFO (decl) = t; + } + + /* Because we use obstacks, we must process these in precise order. */ + t->next = *inlines; + *inlines = t; +} + +void reinit_parse_for_block (); + +void +reinit_parse_for_method (yychar, decl) + int yychar; + tree decl; +{ + int len; + int starting_lineno = lineno; + char *starting_filename = input_filename; + + reinit_parse_for_block (yychar, &inline_text_obstack, 0); + + len = obstack_object_size (&inline_text_obstack); + current_base_init_list = NULL_TREE; + current_member_init_list = NULL_TREE; + if (decl == void_type_node + || (current_class_type && TYPE_REDEFINED (current_class_type))) + { + /* Happens when we get two declarations of the same + function in the same scope. */ + char *buf = obstack_finish (&inline_text_obstack); + obstack_free (&inline_text_obstack, buf); + return; + } + else + { + struct pending_inline *t; + char *buf = obstack_finish (&inline_text_obstack); + + t = (struct pending_inline *) obstack_alloc (&inline_text_obstack, + sizeof (struct pending_inline)); + t->lineno = starting_lineno; + t->filename = starting_filename; + t->token = YYEMPTY; + t->token_value = 0; + t->buf = buf; + t->len = len; + t->can_free = 1; + t->deja_vu = 0; + if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl)) + warn_if_unknown_interface (decl); + t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2)); + store_pending_inline (decl, t); + } +} + +/* Consume a block -- actually, a method or template definition beginning + with `:' or `{' -- and save it away on the specified obstack. + + Argument IS_TEMPLATE indicates which set of error messages should be + output if something goes wrong. This should really be cleaned up somehow, + without loss of clarity. */ +void +reinit_parse_for_block (pyychar, obstackp, is_template) + int pyychar; + struct obstack *obstackp; + int is_template; +{ + register int c = 0; + int blev = 1; + int starting_lineno = lineno; + char *starting_filename = input_filename; + int len; + int look_for_semicolon = 0; + int look_for_lbrac = 0; + + if (pyychar == '{') + obstack_1grow (obstackp, '{'); + else if (pyychar == '=') + look_for_semicolon = 1; + else if (pyychar == ':') + { + obstack_1grow (obstackp, pyychar); + look_for_lbrac = 1; + blev = 0; + } + else if (pyychar == RETURN && !is_template) + { + obstack_grow (obstackp, "return", 6); + look_for_lbrac = 1; + blev = 0; + } + else if (pyychar == TRY && !is_template) + { + obstack_grow (obstackp, "try", 3); + look_for_lbrac = 1; + blev = 0; + } + else + { + yyerror (is_template + ? "parse error in template specification" + : "parse error in method specification"); + obstack_1grow (obstackp, '{'); + } + + if (nextchar != EOF) + { + c = nextchar; + nextchar = EOF; + } + else + c = getch (); + + while (c != EOF) + { + int this_lineno = lineno; + + c = skip_white_space (c); + + /* Don't lose our cool if there are lots of comments. */ + if (lineno == this_lineno + 1) + obstack_1grow (obstackp, '\n'); + else if (lineno == this_lineno) + ; + else if (lineno - this_lineno < 10) + { + int i; + for (i = lineno - this_lineno; i > 0; i--) + obstack_1grow (obstackp, '\n'); + } + else + { + char buf[16]; + sprintf (buf, "\n# %d \"", lineno); + len = strlen (buf); + obstack_grow (obstackp, buf, len); + + len = strlen (input_filename); + obstack_grow (obstackp, input_filename, len); + obstack_1grow (obstackp, '\"'); + obstack_1grow (obstackp, '\n'); + } + + while (c > ' ') /* ASCII dependent... */ + { + obstack_1grow (obstackp, c); + if (c == '{') + { + look_for_lbrac = 0; + blev++; + } + else if (c == '}') + { + blev--; + if (blev == 0 && !look_for_semicolon) + { + if (pyychar == TRY) + { + if (peekyylex () == CATCH) + { + yylex (); + obstack_grow (obstackp, " catch ", 7); + look_for_lbrac = 1; + } + else + { + yychar = '{'; + goto done; + } + } + else + { + goto done; + } + } + } + else if (c == '\\') + { + /* Don't act on the next character...e.g, doing an escaped + double-quote. */ + c = getch (); + if (c == EOF) + { + error_with_file_and_line (starting_filename, + starting_lineno, + "end of file read inside definition"); + goto done; + } + obstack_1grow (obstackp, c); + } + else if (c == '\"') + consume_string (obstackp, c); + else if (c == '\'') + consume_string (obstackp, c); + else if (c == ';') + { + if (look_for_lbrac) + { + error (is_template + ? "template body missing" + : "function body for constructor missing"); + obstack_1grow (obstackp, '{'); + obstack_1grow (obstackp, '}'); + len += 2; + goto done; + } + else if (look_for_semicolon && blev == 0) + goto done; + } + c = getch (); + } + + if (c == EOF) + { + error_with_file_and_line (starting_filename, + starting_lineno, + "end of file read inside definition"); + goto done; + } + else if (c != '\n') + { + obstack_1grow (obstackp, c); + c = getch (); + } + } + done: + obstack_1grow (obstackp, '\0'); +} + +/* Build a default function named NAME for type TYPE. + KIND says what to build. + + When KIND == 0, build default destructor. + When KIND == 1, build virtual destructor. + When KIND == 2, build default constructor. + When KIND == 3, build default X(const X&) constructor. + When KIND == 4, build default X(X&) constructor. + When KIND == 5, build default operator = (const X&). + When KIND == 6, build default operator = (X&). */ + +tree +cons_up_default_function (type, full_name, kind) + tree type, full_name; + int kind; +{ + extern tree void_list_node; + char *func_buf = NULL; + int func_len = 0; + tree declspecs = NULL_TREE; + tree fn, args; + tree argtype; + int retref = 0; + int complex = 0; + tree name = constructor_name (full_name); + + switch (kind) + { + /* Destructors. */ + case 1: + declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]); + /* Fall through... */ + case 0: + name = build_parse_node (BIT_NOT_EXPR, name); + args = void_list_node; + break; + + case 2: + /* Default constructor. */ + args = void_list_node; + complex = TYPE_NEEDS_CONSTRUCTING (type); + break; + + case 3: + type = build_type_variant (type, 1, 0); + /* Fall through... */ + case 4: + /* According to ARM $12.8, the default copy ctor will be declared, but + not defined, unless it's needed. */ + argtype = build_reference_type (type); + args = tree_cons (NULL_TREE, + build_tree_list (hash_tree_chain (argtype, NULL_TREE), + get_identifier ("_ctor_arg")), + void_list_node); + complex = TYPE_HAS_COMPLEX_INIT_REF (type); + break; + + case 5: + type = build_type_variant (type, 1, 0); + /* Fall through... */ + case 6: + retref = 1; + declspecs = build_decl_list (NULL_TREE, full_name); + + name = ansi_opname [(int) MODIFY_EXPR]; + + argtype = build_reference_type (type); + args = tree_cons (NULL_TREE, + build_tree_list (hash_tree_chain (argtype, NULL_TREE), + get_identifier ("_ctor_arg")), + void_list_node); + complex = TYPE_HAS_COMPLEX_ASSIGN_REF (type); + break; + + default: + my_friendly_abort (59); + } + + declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE], + declspecs); + + TREE_PARMLIST (args) = 1; + + { + tree declarator = build_parse_node (CALL_EXPR, name, args, NULL_TREE); + if (retref) + declarator = build_parse_node (ADDR_EXPR, declarator); + + fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, + NULL_TREE, NULL_TREE); + } + + if (fn == void_type_node) + return fn; + + if (processing_template_defn) + { + SET_DECL_IMPLICIT_INSTANTIATION (fn); + repo_template_used (fn); + } + + if (CLASSTYPE_INTERFACE_KNOWN (type)) + { + DECL_INTERFACE_KNOWN (fn) = 1; + DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type) + && flag_implement_inlines); + } + else + DECL_NOT_REALLY_EXTERN (fn) = 1; + +#if 0 + /* When on-the-fly synthesis works properly, remove the second and third + conditions here. */ + if (flag_keep_inline_functions +#if 0 + || ! flag_no_inline + || complex +#endif + || ! DECL_EXTERNAL (fn)) + { + struct pending_inline *t; + t = (struct pending_inline *) + obstack_alloc (&synth_obstack, sizeof (struct pending_inline)); + t->lineno = -kind; + t->can_free = 0; + t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2)); + store_pending_inline (fn, t); + } + else +#endif + mark_inline_for_output (fn); + +#ifdef DEBUG_DEFAULT_FUNCTIONS + { char *fn_type = NULL; + tree t = name; + switch (kind) + { + case 0: fn_type = "default destructor"; break; + case 1: fn_type = "virtual destructor"; break; + case 2: fn_type = "default constructor"; break; + case 3: fn_type = "default X(const X&)"; break; + case 4: fn_type = "default X(X&)"; break; + } + if (fn_type) + { + if (TREE_CODE (name) == BIT_NOT_EXPR) + t = TREE_OPERAND (name, 0); + fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type, + IDENTIFIER_POINTER (t), func_buf); + } + } +#endif /* DEBUG_DEFAULT_FUNCTIONS */ + + /* Show that this function was generated by the compiler. */ + SET_DECL_ARTIFICIAL (fn); + + return fn; +} + +/* Heuristic to tell whether the user is missing a semicolon + after a struct or enum declaration. Emit an error message + if we know the user has blown it. */ +void +check_for_missing_semicolon (type) + tree type; +{ + if (yychar < 0) + yychar = yylex (); + + if ((yychar > 255 + && yychar != SCSPEC + && yychar != IDENTIFIER + && yychar != TYPENAME) + || end_of_file) + { + if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) + error ("semicolon missing after %s declaration", + TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct"); + else + cp_error ("semicolon missing after declaration of `%T'", type); + shadow_tag (build_tree_list (0, type)); + } + /* Could probably also hack cases where class { ... } f (); appears. */ + clear_anon_tags (); +} + +void +note_got_semicolon (type) + tree type; +{ + if (TREE_CODE_CLASS (TREE_CODE (type)) != 't') + my_friendly_abort (60); + if (IS_AGGR_TYPE (type)) + CLASSTYPE_GOT_SEMICOLON (type) = 1; +} + +void +note_list_got_semicolon (declspecs) + tree declspecs; +{ + tree link; + + for (link = declspecs; link; link = TREE_CHAIN (link)) + { + tree type = TREE_VALUE (link); + if (TREE_CODE_CLASS (TREE_CODE (type)) == 't') + note_got_semicolon (type); + } + clear_anon_tags (); +} + +/* If C is not whitespace, return C. + Otherwise skip whitespace and return first nonwhite char read. */ + +static int +skip_white_space (c) + register int c; +{ + for (;;) + { + switch (c) + { + case '\n': + c = check_newline (); + break; + + case ' ': + case '\t': + case '\f': + case '\r': + case '\v': + case '\b': + do + c = getch (); + while (c == ' ' || c == '\t'); + break; + + case '\\': + c = getch (); + if (c == '\n') + lineno++; + else + error ("stray '\\' in program"); + c = getch (); + break; + + default: + return (c); + } + } +} + + + +/* Make the token buffer longer, preserving the data in it. + P should point to just beyond the last valid character in the old buffer. + The value we return is a pointer to the new buffer + at a place corresponding to P. */ + +static char * +extend_token_buffer (p) + char *p; +{ + int offset = p - token_buffer; + + maxtoken = maxtoken * 2 + 10; + token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2); + + return token_buffer + offset; +} + +static int +get_last_nonwhite_on_line () +{ + register int c; + + /* Is this the last nonwhite stuff on the line? */ + if (nextchar >= 0) + c = nextchar, nextchar = -1; + else + c = getch (); + + while (c == ' ' || c == '\t') + c = getch (); + return c; +} + +/* At the beginning of a line, increment the line number + and process any #-directive on this line. + If the line is a #-directive, read the entire line and return a newline. + Otherwise, return the line's first non-whitespace character. */ + +int linemode; + +int +check_newline () +{ + register int c; + register int token; + + /* Read first nonwhite char on the line. Do this before incrementing the + line number, in case we're at the end of saved text. */ + + do + c = getch (); + while (c == ' ' || c == '\t'); + + lineno++; + + if (c != '#') + { + /* If not #, return it so caller will use it. */ + return c; + } + + /* Don't read beyond this line. */ + linemode = 1; + + /* Read first nonwhite char after the `#'. */ + + do + c = getch (); + while (c == ' ' || c == '\t'); + + /* If a letter follows, then if the word here is `line', skip + it and ignore it; otherwise, ignore the line, with an error + if the word isn't `pragma'. */ + + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + { + if (c == 'p') + { + if (getch () == 'r' + && getch () == 'a' + && getch () == 'g' + && getch () == 'm' + && getch () == 'a') + { + /* Read first nonwhite char after the `#pragma'. */ + + do + c = getch (); + while (c == ' ' || c == '\t'); + + if (c == 'v' + && getch () == 't' + && getch () == 'a' + && getch () == 'b' + && getch () == 'l' + && getch () == 'e' + && ((c = getch ()) == ' ' || c == '\t')) + { + extern tree pending_vtables; + + /* More follows: it must be a string constant (class name). */ + token = real_yylex (); + if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #pragma vtable"); + goto skipline; + } + if (write_virtuals != 2) + { + warning ("use `+e2' option to enable #pragma vtable"); + goto skipline; + } + pending_vtables = perm_tree_cons (NULL_TREE, get_identifier (TREE_STRING_POINTER (yylval.ttype)), pending_vtables); + if (nextchar < 0) + nextchar = getch (); + c = nextchar; + if (c != EOF) + warning ("trailing characters ignored"); + } + else if (c == 'u' + && getch () == 'n' + && getch () == 'i' + && getch () == 't' + && ((c = getch ()) == ' ' || c == '\t')) + { + /* More follows: it must be a string constant (unit name). */ + token = real_yylex (); + if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #pragma unit"); + goto skipline; + } + current_unit_name = get_identifier (TREE_STRING_POINTER (yylval.ttype)); + current_unit_language = current_lang_name; + if (nextchar < 0) + nextchar = getch (); + c = nextchar; + if (c != EOF) + warning ("trailing characters ignored"); + } + else if (c == 'i') + { + tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename)); + c = getch (); + + if (c == 'n' + && getch () == 't' + && getch () == 'e' + && getch () == 'r' + && getch () == 'f' + && getch () == 'a' + && getch () == 'c' + && getch () == 'e' + && ((c = getch ()) == ' ' || c == '\t' || c == EOF)) + { + int warned_already = 0; + char *main_filename = input_filename; + + main_filename = FILE_NAME_NONDIRECTORY (main_filename); + while (c == ' ' || c == '\t') + c = getch (); + if (c != EOF) + { + put_back (c); + token = real_yylex (); + if (token != STRING + || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid `#pragma interface'"); + goto skipline; + } + main_filename = TREE_STRING_POINTER (yylval.ttype); + c = getch(); + put_back (c); + } + + while (c == ' ' || c == '\t') + c = getch (); + + while (c != EOF) + { + if (!warned_already && extra_warnings + && c != ' ' && c != '\t') + { + warning ("garbage after `#pragma interface' ignored"); + warned_already = 1; + } + c = getch (); + } + + write_virtuals = 3; + + if (impl_file_chain == 0) + { + /* If this is zero at this point, then we are + auto-implementing. */ + if (main_input_filename == 0) + main_input_filename = input_filename; + +#ifdef AUTO_IMPLEMENT + filename = FILE_NAME_NONDIRECTORY (main_input_filename); + fi = get_time_identifier (filename); + fi = IDENTIFIER_CLASS_VALUE (fi); + TREE_INT_CST_LOW (fi) = 0; + TREE_INT_CST_HIGH (fi) = 1; + /* Get default. */ + impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files)); + impl_file_chain->filename = filename; + impl_file_chain->next = 0; +#endif + } + + interface_only = interface_strcmp (main_filename); + interface_unknown = 0; + TREE_INT_CST_LOW (fileinfo) = interface_only; + TREE_INT_CST_HIGH (fileinfo) = interface_unknown; + } + else if (c == 'm' + && getch () == 'p' + && getch () == 'l' + && getch () == 'e' + && getch () == 'm' + && getch () == 'e' + && getch () == 'n' + && getch () == 't' + && getch () == 'a' + && getch () == 't' + && getch () == 'i' + && getch () == 'o' + && getch () == 'n' + && ((c = getch ()) == ' ' || c == '\t' || c == EOF)) + { + int warned_already = 0; + char *main_filename = main_input_filename ? main_input_filename : input_filename; + + main_filename = FILE_NAME_NONDIRECTORY (main_filename); + while (c == ' ' || c == '\t') + c = getch (); + if (c != EOF) + { + put_back (c); + token = real_yylex (); + if (token != STRING + || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid `#pragma implementation'"); + goto skipline; + } + main_filename = TREE_STRING_POINTER (yylval.ttype); + c = getch(); + put_back (c); + } + + while (c == ' ' || c == '\t') + c = getch (); + + while (c != EOF) + { + if (!warned_already && extra_warnings + && c != ' ' && c != '\t') + { + warning ("garbage after `#pragma implementation' ignored"); + warned_already = 1; + } + c = getch (); + } + + if (write_virtuals == 3) + { + struct impl_files *ifiles = impl_file_chain; + while (ifiles) + { + if (! strcmp (ifiles->filename, main_filename)) + break; + ifiles = ifiles->next; + } + if (ifiles == 0) + { + ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files)); + ifiles->filename = main_filename; + ifiles->next = impl_file_chain; + impl_file_chain = ifiles; + } + } + else if ((main_input_filename != 0 + && ! strcmp (main_input_filename, input_filename)) + || ! strcmp (input_filename, main_filename)) + { + write_virtuals = 3; + if (impl_file_chain == 0) + { + impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files)); + impl_file_chain->filename = main_filename; + impl_file_chain->next = 0; + } + } + else + error ("`#pragma implementation' can only appear at top-level"); + interface_only = 0; +#if 1 + /* We make this non-zero so that we infer decl linkage + in the impl file only for variables first declared + in the interface file. */ + interface_unknown = 1; +#else + /* We make this zero so that templates in the impl + file will be emitted properly. */ + interface_unknown = 0; +#endif + TREE_INT_CST_LOW (fileinfo) = interface_only; + TREE_INT_CST_HIGH (fileinfo) = interface_unknown; + } + } +#ifdef HANDLE_SYSV_PRAGMA + else + { + put_back (c); + handle_sysv_pragma (); + } +#else +#ifdef HANDLE_PRAGMA + /* FIXME: This will break if we're doing any of the C++ input + tricks. */ + else + { + ungetc (c, finput); + HANDLE_PRAGMA (finput); + } +#endif +#endif + goto skipline; + } + } + else if (c == 'd') + { + if (getch () == 'e' + && getch () == 'f' + && getch () == 'i' + && getch () == 'n' + && getch () == 'e' + && ((c = getch ()) == ' ' || c == '\t')) + { +#ifdef DWARF_DEBUGGING_INFO + if ((debug_info_level == DINFO_LEVEL_VERBOSE) + && (write_symbols == DWARF_DEBUG)) + dwarfout_define (lineno, get_directive_line (finput)); +#endif /* DWARF_DEBUGGING_INFO */ + goto skipline; + } + } + else if (c == 'u') + { + if (getch () == 'n' + && getch () == 'd' + && getch () == 'e' + && getch () == 'f' + && ((c = getch ()) == ' ' || c == '\t')) + { +#ifdef DWARF_DEBUGGING_INFO + if ((debug_info_level == DINFO_LEVEL_VERBOSE) + && (write_symbols == DWARF_DEBUG)) + dwarfout_undef (lineno, get_directive_line (finput)); +#endif /* DWARF_DEBUGGING_INFO */ + goto skipline; + } + } + else if (c == 'l') + { + if (getch () == 'i' + && getch () == 'n' + && getch () == 'e' + && ((c = getch ()) == ' ' || c == '\t')) + goto linenum; + } + else if (c == 'i') + { + if (getch () == 'd' + && getch () == 'e' + && getch () == 'n' + && getch () == 't' + && ((c = getch ()) == ' ' || c == '\t')) + { +#ifdef ASM_OUTPUT_IDENT + extern FILE *asm_out_file; +#endif + /* #ident. The pedantic warning is now in cccp.c. */ + + /* Here we have just seen `#ident '. + A string constant should follow. */ + + while (c == ' ' || c == '\t') + c = getch (); + + /* If no argument, ignore the line. */ + if (c == EOF) + goto skipline; + + put_back (c); + token = real_yylex (); + if (token != STRING + || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #ident"); + goto skipline; + } + + if (! flag_no_ident) + { +#ifdef ASM_OUTPUT_IDENT + ASM_OUTPUT_IDENT (asm_out_file, + TREE_STRING_POINTER (yylval.ttype)); +#endif + } + + /* Skip the rest of this line. */ + goto skipline; + } + } + else if (c == 'n') + { + if (getch () == 'e' + && getch () == 'w' + && getch () == 'w' + && getch () == 'o' + && getch () == 'r' + && getch () == 'l' + && getch () == 'd' + && ((c = getch ()) == ' ' || c == '\t')) + { + /* Used to test incremental compilation. */ + sorry ("#pragma newworld"); + goto skipline; + } + } + error ("undefined or invalid # directive"); + goto skipline; + } + +linenum: + /* Here we have either `#line' or `# '. + In either case, it should be a line number; a digit should follow. */ + + while (c == ' ' || c == '\t') + c = getch (); + + /* If the # is the only nonwhite char on the line, + just ignore it. Check the new newline. */ + if (c == EOF) + goto skipline; + + /* Something follows the #; read a token. */ + + put_back (c); + token = real_yylex (); + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST) + { + int old_lineno = lineno; + enum { act_none, act_push, act_pop } action = act_none; + int entering_system_header = 0; + int entering_c_header = 0; + + /* subtract one, because it is the following line that + gets the specified number */ + + int l = TREE_INT_CST_LOW (yylval.ttype) - 1; + c = get_last_nonwhite_on_line (); + if (c == EOF) + { + /* No more: store the line number and check following line. */ + lineno = l; + goto skipline; + } + put_back (c); + + /* More follows: it must be a string constant (filename). */ + + /* Read the string constant, but don't treat \ as special. */ + ignore_escape_flag = 1; + token = real_yylex (); + ignore_escape_flag = 0; + + if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST) + { + error ("invalid #line"); + goto skipline; + } + + /* Changing files again. This means currently collected time + is charged against header time, and body time starts back + at 0. */ + if (flag_detailed_statistics) + { + int this_time = my_get_run_time (); + tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype)); + header_time += this_time - body_time; + TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) + += this_time - body_time; + this_filename_time = time_identifier; + body_time = this_time; + } + + if (flag_cadillac) + cadillac_note_source (); + + input_filename + = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1); + strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype)); + lineno = l; + GNU_xref_file (input_filename); + + if (main_input_filename == 0) + { + struct impl_files *ifiles = impl_file_chain; + + if (ifiles) + { + while (ifiles->next) + ifiles = ifiles->next; + ifiles->filename = FILE_NAME_NONDIRECTORY (input_filename); + } + + main_input_filename = input_filename; + if (write_virtuals == 3) + walk_vtables (set_typedecl_interface_info, set_vardecl_interface_info); + } + + extract_interface_info (); + + c = get_last_nonwhite_on_line (); + if (c == EOF) + { + /* Update the name in the top element of input_file_stack. */ + if (input_file_stack) + input_file_stack->name = input_filename; + } + else + { + put_back (c); + + token = real_yylex (); + + /* `1' after file name means entering new file. + `2' after file name means just left a file. */ + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST) + { + if (TREE_INT_CST_LOW (yylval.ttype) == 1) + action = act_push; + else if (TREE_INT_CST_LOW (yylval.ttype) == 2) + action = act_pop; + + if (action) + { + c = get_last_nonwhite_on_line (); + if (c != EOF) + { + put_back (c); + token = real_yylex (); + } + } + } + + /* `3' after file name means this is a system header file. */ + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST + && TREE_INT_CST_LOW (yylval.ttype) == 3) + { + entering_system_header = 1; + + c = get_last_nonwhite_on_line (); + if (c != EOF) + { + put_back (c); + token = real_yylex (); + } + } + + /* `4' after file name means this is a C header file. */ + + if (token == CONSTANT + && TREE_CODE (yylval.ttype) == INTEGER_CST + && TREE_INT_CST_LOW (yylval.ttype) == 4) + { + entering_c_header = 1; + + c = get_last_nonwhite_on_line (); + if (c != EOF) + { + put_back (c); + token = real_yylex (); + } + } + + /* Do the actions implied by the preceding numbers. */ + + if (action == act_push) + { + /* Pushing to a new file. */ + struct file_stack *p; + + p = (struct file_stack *) xmalloc (sizeof (struct file_stack)); + input_file_stack->line = old_lineno; + p->next = input_file_stack; + p->name = input_filename; + input_file_stack = p; + input_file_stack_tick++; +#ifdef DWARF_DEBUGGING_INFO + if (debug_info_level == DINFO_LEVEL_VERBOSE + && write_symbols == DWARF_DEBUG) + dwarfout_start_new_source_file (input_filename); +#endif /* DWARF_DEBUGGING_INFO */ + if (flag_cadillac) + cadillac_push_source (); + in_system_header = entering_system_header; + if (c_header_level) + ++c_header_level; + else if (entering_c_header) + { + c_header_level = 1; + ++pending_lang_change; + } + } + else if (action == act_pop) + { + /* Popping out of a file. */ + if (input_file_stack->next) + { + struct file_stack *p; + + if (c_header_level && --c_header_level == 0) + { + if (entering_c_header) + warning ("badly nested C headers from preprocessor"); + --pending_lang_change; + } + if (flag_cadillac) + cadillac_pop_source (); + in_system_header = entering_system_header; + + p = input_file_stack; + input_file_stack = p->next; + free (p); + input_file_stack_tick++; +#ifdef DWARF_DEBUGGING_INFO + if (debug_info_level == DINFO_LEVEL_VERBOSE + && write_symbols == DWARF_DEBUG) + dwarfout_resume_previous_source_file (input_file_stack->line); +#endif /* DWARF_DEBUGGING_INFO */ + } + else + error ("#-lines for entering and leaving files don't match"); + } + else + { + in_system_header = entering_system_header; + if (flag_cadillac) + cadillac_switch_source (-1); + } + } + + /* If NEXTCHAR is not end of line, we don't care what it is. */ + if (nextchar == EOF) + c = EOF; + } + else + error ("invalid #-line"); + + /* skip the rest of this line. */ + skipline: + linemode = 0; + end_of_file = 0; + while ((c = getch ()) != EOF && c != '\n'); + return c; +} + +void +do_pending_lang_change () +{ + for (; pending_lang_change > 0; --pending_lang_change) + push_lang_context (lang_name_c); + for (; pending_lang_change < 0; ++pending_lang_change) + pop_lang_context (); +} + +#if 0 +#define isalnum(char) (char >= 'a' ? char <= 'z' : char >= '0' ? char <= '9' || (char >= 'A' && char <= 'Z') : 0) +#define isdigit(char) (char >= '0' && char <= '9') +#else +#include +#endif + +#define ENDFILE -1 /* token that represents end-of-file */ + +/* Read an escape sequence, returning its equivalent as a character, + or store 1 in *ignore_ptr if it is backslash-newline. */ + +static int +readescape (ignore_ptr) + int *ignore_ptr; +{ + register int c = getch (); + register int code; + register unsigned count; + unsigned firstdig; + int nonnull; + + switch (c) + { + case 'x': + if (warn_traditional) + warning ("the meaning of `\\x' varies with -traditional"); + + if (flag_traditional) + return c; + + code = 0; + count = 0; + nonnull = 0; + while (1) + { + c = getch (); + if (! isxdigit (c)) + { + put_back (c); + break; + } + code *= 16; + if (c >= 'a' && c <= 'f') + code += c - 'a' + 10; + if (c >= 'A' && c <= 'F') + code += c - 'A' + 10; + if (c >= '0' && c <= '9') + code += c - '0'; + if (code != 0 || count != 0) + { + if (count == 0) + firstdig = code; + count++; + } + nonnull = 1; + } + if (! nonnull) + error ("\\x used with no following hex digits"); + else if (count == 0) + /* Digits are all 0's. Ok. */ + ; + else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node) + || (count > 1 + && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4)) + <= firstdig))) + pedwarn ("hex escape out of range"); + return code; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + code = 0; + count = 0; + while ((c <= '7') && (c >= '0') && (count++ < 3)) + { + code = (code * 8) + (c - '0'); + c = getch (); + } + put_back (c); + return code; + + case '\\': case '\'': case '"': + return c; + + case '\n': + lineno++; + *ignore_ptr = 1; + return 0; + + case 'n': + return TARGET_NEWLINE; + + case 't': + return TARGET_TAB; + + case 'r': + return TARGET_CR; + + case 'f': + return TARGET_FF; + + case 'b': + return TARGET_BS; + + case 'a': + if (warn_traditional) + warning ("the meaning of `\\a' varies with -traditional"); + + if (flag_traditional) + return c; + return TARGET_BELL; + + case 'v': + return TARGET_VT; + + case 'e': + case 'E': + if (pedantic) + pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c); + return 033; + + case '?': + return c; + + /* `\(', etc, are used at beginning of line to avoid confusing Emacs. */ + case '(': + case '{': + case '[': + /* `\%' is used to prevent SCCS from getting confused. */ + case '%': + if (pedantic) + pedwarn ("unknown escape sequence `\\%c'", c); + return c; + } + if (c >= 040 && c < 0177) + pedwarn ("unknown escape sequence `\\%c'", c); + else + pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c); + return c; +} + +/* Value is 1 (or 2) if we should try to make the next identifier look like + a typename (when it may be a local variable or a class variable). + Value is 0 if we treat this name in a default fashion. */ +int looking_for_typename = 0; + +#if 0 +/* NO LONGER USED: Value is -1 if we must not see a type name. */ +void +dont_see_typename () +{ + looking_for_typename = -1; + if (yychar == TYPENAME || yychar == PTYPENAME) + { + yychar = IDENTIFIER; + lastiddecl = 0; + } +} +#endif + +#ifdef __GNUC__ +extern __inline int identifier_type (); +__inline +#endif +int +identifier_type (decl) + tree decl; +{ + if (TREE_CODE (decl) == TEMPLATE_DECL + && DECL_TEMPLATE_IS_CLASS (decl)) + return PTYPENAME; + if (TREE_CODE (decl) == NAMESPACE_DECL) + return NSNAME; + if (TREE_CODE (decl) != TYPE_DECL) + return IDENTIFIER; + return TYPENAME; +} + +void +see_typename () +{ + looking_for_typename = 1; + if (yychar < 0) + if ((yychar = yylex()) < 0) yychar = 0; + looking_for_typename = 0; + if (yychar == IDENTIFIER) + { + lastiddecl = lookup_name (yylval.ttype, -2); + if (lastiddecl == 0) + { + if (flag_labels_ok) + lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype); + } + else + yychar = identifier_type (lastiddecl); + } +} + +tree +do_identifier (token) + register tree token; +{ + register tree id = lastiddecl; + + if (yychar == YYEMPTY) + yychar = yylex (); + /* Scope class declarations before global + declarations. */ + if (id == IDENTIFIER_GLOBAL_VALUE (token) + && current_class_type != 0 + && TYPE_SIZE (current_class_type) == 0 + && TREE_CODE (current_class_type) != UNINSTANTIATED_P_TYPE) + { + /* Could be from one of the base classes. */ + tree field = lookup_field (current_class_type, token, 1, 0); + if (field == 0) + ; + else if (field == error_mark_node) + /* We have already generated the error message. + But we still want to return this value. */ + id = lookup_field (current_class_type, token, 0, 0); + else if (TREE_CODE (field) == VAR_DECL + || TREE_CODE (field) == CONST_DECL) + id = field; + else if (TREE_CODE (field) != FIELD_DECL) + my_friendly_abort (61); + else + { + cp_error ("invalid use of member `%D' from base class `%T'", field, + DECL_FIELD_CONTEXT (field)); + id = error_mark_node; + return id; + } + } + + /* Remember that this name has been used in the class definition, as per + [class.scope0] */ + if (id && current_class_type + && TYPE_BEING_DEFINED (current_class_type) + && ! IDENTIFIER_CLASS_VALUE (token)) + pushdecl_class_level (id); + + if (!id || id == error_mark_node) + { + if (id == error_mark_node && current_class_type != NULL_TREE) + { + id = lookup_nested_field (token, 1); + /* In lookup_nested_field(), we marked this so we can gracefully + leave this whole mess. */ + if (id && id != error_mark_node && TREE_TYPE (id) == error_mark_node) + return id; + } + if (yychar == '(' || yychar == LEFT_RIGHT) + { + id = implicitly_declare (token); + } + else if (current_function_decl == 0) + { + cp_error ("`%D' was not declared in this scope", token); + id = error_mark_node; + } + else + { + if (IDENTIFIER_GLOBAL_VALUE (token) != error_mark_node + || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl) + { + static int undeclared_variable_notice; + + cp_error ("`%D' undeclared (first use this function)", token); + + if (! undeclared_variable_notice) + { + error ("(Each undeclared identifier is reported only once"); + error ("for each function it appears in.)"); + undeclared_variable_notice = 1; + } + } + id = error_mark_node; + /* Prevent repeated error messages. */ + IDENTIFIER_GLOBAL_VALUE (token) = error_mark_node; + SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl); + } + } + + if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id)) + { + tree shadowed = DECL_SHADOWED_FOR_VAR (id); + if (shadowed) + { + if (!DECL_ERROR_REPORTED (id)) + { + warning ("name lookup of `%s' changed", + IDENTIFIER_POINTER (token)); + cp_warning_at (" matches this `%D' under current ANSI rules", + shadowed); + cp_warning_at (" matches this `%D' under old rules", id); + DECL_ERROR_REPORTED (id) = 1; + } + id = shadowed; + } + else if (!DECL_ERROR_REPORTED (id)) + { + static char msg[] + = "name lookup of `%s' changed for new ANSI `for' scoping"; + DECL_ERROR_REPORTED (id) = 1; + if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id))) + { + error (msg, IDENTIFIER_POINTER (token)); + cp_error_at (" cannot use obsolete binding at `%D' because it has a destructor", id); + id = error_mark_node; + } + else + { + pedwarn (msg, IDENTIFIER_POINTER (token)); + cp_pedwarn_at (" using obsolete binding at `%D'", id); + } + } + } + /* TREE_USED is set in `hack_identifier'. */ + if (TREE_CODE (id) == CONST_DECL) + { + if (IDENTIFIER_CLASS_VALUE (token) == id) + { + /* Check access. */ + enum access_type access + = compute_access (TYPE_BINFO (current_class_type), id); + if (access == access_private) + cp_error ("enum `%D' is private", id); + /* protected is OK, since it's an enum of `this'. */ + } + id = DECL_INITIAL (id); + } + else + id = hack_identifier (id, token, yychar); + return id; +} + +tree +identifier_typedecl_value (node) + tree node; +{ + tree t, type; + type = IDENTIFIER_TYPE_VALUE (node); + if (type == NULL_TREE) + return NULL_TREE; +#define do(X) \ + { \ + t = (X); \ + if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) \ + return t; \ + } + do (IDENTIFIER_LOCAL_VALUE (node)); + do (IDENTIFIER_CLASS_VALUE (node)); + do (IDENTIFIER_GLOBAL_VALUE (node)); +#undef do + /* Will this one ever happen? */ + if (TYPE_NAME (type)) + return TYPE_NAME (type); + + /* We used to do an internal error of 62 here, but instead we will + handle the return of a null appropriately in the callers. */ + return NULL_TREE; +} + +struct try_type +{ + tree *node_var; + char unsigned_flag; + char long_flag; + char long_long_flag; +}; + +struct try_type type_sequence[] = +{ + { &integer_type_node, 0, 0, 0}, + { &unsigned_type_node, 1, 0, 0}, + { &long_integer_type_node, 0, 1, 0}, + { &long_unsigned_type_node, 1, 1, 0}, + { &long_long_integer_type_node, 0, 1, 1}, + { &long_long_unsigned_type_node, 1, 1, 1} +}; + +int +real_yylex () +{ + register int c; + register int value; + int wide_flag = 0; + int dollar_seen = 0; + int i; + + if (nextchar >= 0) + c = nextchar, nextchar = -1; + else + c = getch (); + + /* Effectively do c = skip_white_space (c) + but do it faster in the usual cases. */ + while (1) + switch (c) + { + case ' ': + case '\t': + case '\f': + case '\v': + case '\b': + c = getch (); + break; + + case '\r': + /* Call skip_white_space so we can warn if appropriate. */ + + case '\n': + case '/': + case '\\': + c = skip_white_space (c); + default: + goto found_nonwhite; + } + found_nonwhite: + + token_buffer[0] = c; + token_buffer[1] = 0; + +/* yylloc.first_line = lineno; */ + + switch (c) + { + case EOF: + token_buffer[0] = '\0'; + end_of_file = 1; + if (input_redirected ()) + value = END_OF_SAVED_INPUT; + else if (linemode) + value = END_OF_LINE; + else if (do_pending_expansions ()) + /* this will set yychar for us */ + return yychar; + else + value = ENDFILE; + break; + + case '$': + if (dollars_in_ident) + { + dollar_seen = 1; + goto letter; + } + value = '$'; + goto done; + + case 'L': + /* Capital L may start a wide-string or wide-character constant. */ + { + register int c = getch (); + if (c == '\'') + { + wide_flag = 1; + goto char_constant; + } + if (c == '"') + { + wide_flag = 1; + goto string_constant; + } + put_back (c); + } + + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case '_': + letter: + { + register char *p; + + p = token_buffer; + if (input == 0) + { + /* We know that `token_buffer' can hold at least on char, + so we install C immediately. + We may have to read the value in `putback_char', so call + `getch' once. */ + *p++ = c; + c = getch (); + + /* Make this run fast. We know that we are reading straight + from FINPUT in this case (since identifiers cannot straddle + input sources. */ + while (isalnum (c) || (c == '_') || c == '$') + { + if (c == '$' && ! dollars_in_ident) + break; + if (p >= token_buffer + maxtoken) + p = extend_token_buffer (p); + + *p++ = c; + c = getc (finput); + } + + if (linemode && c == '\n') + { + put_back (c); + c = EOF; + } + } + else + { + /* We know that `token_buffer' can hold at least on char, + so we install C immediately. */ + *p++ = c; + c = getch (); + + while (isalnum (c) || (c == '_') || c == '$') + { + if (c == '$' && ! dollars_in_ident) + break; + if (p >= token_buffer + maxtoken) + p = extend_token_buffer (p); + + *p++ = c; + c = getch (); + } + } + + *p = 0; + nextchar = c; + + value = IDENTIFIER; + yylval.itype = 0; + + /* Try to recognize a keyword. Uses minimum-perfect hash function */ + + { + register struct resword *ptr; + + if (ptr = is_reserved_word (token_buffer, p - token_buffer)) + { + if (ptr->rid) + { + tree old_ttype = ridpointers[(int) ptr->rid]; + + /* If this provides a type for us, then revert lexical + state to standard state. */ + if (TREE_CODE (old_ttype) == IDENTIFIER_NODE + && IDENTIFIER_GLOBAL_VALUE (old_ttype) != 0 + && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (old_ttype)) == TYPE_DECL) + looking_for_typename = 0; + else if (ptr->token == AGGR || ptr->token == ENUM) + looking_for_typename = 1; + + /* Check if this is a language-type declaration. + Just glimpse the next non-white character. */ + nextchar = skip_white_space (nextchar); + if (nextchar == '"') + { + /* We are looking at a string. Complain + if the token before the string is no `extern'. + + Could cheat some memory by placing this string + on the temporary_, instead of the saveable_ + obstack. */ + + if (ptr->rid != RID_EXTERN) + error ("invalid modifier `%s' for language string", + ptr->name); + real_yylex (); + value = EXTERN_LANG_STRING; + yylval.ttype = get_identifier (TREE_STRING_POINTER (yylval.ttype)); + break; + } + if (ptr->token == VISSPEC) + { + switch (ptr->rid) + { + case RID_PUBLIC: + yylval.itype = access_public; + break; + case RID_PRIVATE: + yylval.itype = access_private; + break; + case RID_PROTECTED: + yylval.itype = access_protected; + break; + default: + my_friendly_abort (63); + } + } + else + yylval.ttype = old_ttype; + } + else if (ptr->token == EQCOMPARE) + { + yylval.code = NE_EXPR; + token_buffer[0] = '!'; + token_buffer[1] = '='; + token_buffer[2] = 0; + } + else if (ptr->token == ASSIGN) + { + if (strcmp ("and_eq", token_buffer) == 0) + { + yylval.code = BIT_AND_EXPR; + token_buffer[0] = '&'; + } + else if (strcmp ("or_eq", token_buffer) == 0) + { + yylval.code = BIT_IOR_EXPR; + token_buffer[0] = '|'; + } + else if (strcmp ("xor_eq", token_buffer) == 0) + { + yylval.code = BIT_XOR_EXPR; + token_buffer[0] = '^'; + } + token_buffer[1] = '='; + token_buffer[2] = 0; + } + else if (ptr->token == '&') + { + yylval.code = BIT_AND_EXPR; + token_buffer[0] = '&'; + token_buffer[1] = 0; + } + else if (ptr->token == '|') + { + yylval.code = BIT_IOR_EXPR; + token_buffer[0] = '|'; + token_buffer[1] = 0; + } + else if (ptr->token == '^') + { + yylval.code = BIT_XOR_EXPR; + token_buffer[0] = '^'; + token_buffer[1] = 0; + } + + value = (int) ptr->token; + } + } + + /* If we did not find a keyword, look for an identifier + (or a typename). */ + + if (strcmp ("catch", token_buffer) == 0 + || strcmp ("throw", token_buffer) == 0 + || strcmp ("try", token_buffer) == 0) + { + static int did_warn = 0; + if (! did_warn && ! flag_handle_exceptions) + { + pedwarn ("`catch', `throw', and `try' are all C++ reserved words"); + did_warn = 1; + } + } + + if (value == IDENTIFIER || value == TYPESPEC) + GNU_xref_ref (current_function_decl, token_buffer); + + if (value == IDENTIFIER) + { + register tree tmp = get_identifier (token_buffer); + +#if !defined(VMS) && defined(JOINER) + /* Make sure that user does not collide with our internal + naming scheme. */ + if (JOINER == '$' + && dollar_seen + && (THIS_NAME_P (tmp) + || VPTR_NAME_P (tmp) + || DESTRUCTOR_NAME_P (tmp) + || VTABLE_NAME_P (tmp) + || TEMP_NAME_P (tmp) + || ANON_AGGRNAME_P (tmp) + || ANON_PARMNAME_P (tmp))) + warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy", + token_buffer); +#endif + + yylval.ttype = tmp; + + /* A user-invisible read-only initialized variable + should be replaced by its value. We only handle strings + since that's the only case used in C (and C++). */ + /* Note we go right after the local value for the identifier + (e.g., __FUNCTION__ or __PRETTY_FUNCTION__). We used to + call lookup_name, but that could result in an error about + ambiguities. */ + tmp = IDENTIFIER_LOCAL_VALUE (yylval.ttype); + if (tmp != NULL_TREE + && TREE_CODE (tmp) == VAR_DECL + && DECL_IGNORED_P (tmp) + && TREE_READONLY (tmp) + && DECL_INITIAL (tmp) != NULL_TREE + && TREE_CODE (DECL_INITIAL (tmp)) == STRING_CST) + { + yylval.ttype = DECL_INITIAL (tmp); + value = STRING; + } + } + if (value == NEW && ! global_bindings_p ()) + { + value = NEW; + goto done; + } + } + break; + + case '.': + { + register int c1 = getch (); + token_buffer[0] = c; + token_buffer[1] = c1; + if (c1 == '*') + { + value = DOT_STAR; + token_buffer[2] = 0; + goto done; + } + if (c1 == '.') + { + c1 = getch (); + if (c1 == '.') + { + token_buffer[2] = c1; + token_buffer[3] = 0; + value = ELLIPSIS; + goto done; + } + error ("parse error at `..'"); + } + if (isdigit (c1)) + { + put_back (c1); + goto resume_numerical_scan; + } + nextchar = c1; + value = '.'; + token_buffer[1] = 0; + goto done; + } + case '0': case '1': + /* Optimize for most frequent case. */ + { + register int c1 = getch (); + if (! isalnum (c1) && c1 != '.') + { + /* Terminate string. */ + token_buffer[0] = c; + token_buffer[1] = 0; + if (c == '0') + yylval.ttype = integer_zero_node; + else + yylval.ttype = integer_one_node; + nextchar = c1; + value = CONSTANT; + goto done; + } + put_back (c1); + } + /* fall through... */ + case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + resume_numerical_scan: + { + register char *p; + int base = 10; + int count = 0; + int largest_digit = 0; + int numdigits = 0; + /* for multi-precision arithmetic, + we actually store only HOST_BITS_PER_CHAR bits in each part. + The number of parts is chosen so as to be sufficient to hold + the enough bits to fit into the two HOST_WIDE_INTs that contain + the integer value (this is always at least as many bits as are + in a target `long long' value, but may be wider). */ +#define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2) + int parts[TOTAL_PARTS]; + int overflow = 0; + + enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag + = NOT_FLOAT; + + p = token_buffer; + *p++ = c; + + for (count = 0; count < TOTAL_PARTS; count++) + parts[count] = 0; + + if (c == '0') + { + *p++ = (c = getch ()); + if ((c == 'x') || (c == 'X')) + { + base = 16; + *p++ = (c = getch ()); + } + /* Leading 0 forces octal unless the 0 is the only digit. */ + else if (c >= '0' && c <= '9') + { + base = 8; + numdigits++; + } + else + numdigits++; + } + + /* Read all the digits-and-decimal-points. */ + + while (c == '.' + || (isalnum (c) && (c != 'l') && (c != 'L') + && (c != 'u') && (c != 'U') + && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F'))))) + { + if (c == '.') + { + if (base == 16) + error ("floating constant may not be in radix 16"); + if (floatflag == AFTER_POINT) + { + error ("malformed floating constant"); + floatflag = TOO_MANY_POINTS; + } + else + floatflag = AFTER_POINT; + + base = 10; + *p++ = c = getch (); + /* Accept '.' as the start of a floating-point number + only when it is followed by a digit. + Otherwise, unread the following non-digit + and use the '.' as a structural token. */ + if (p == token_buffer + 2 && !isdigit (c)) + { + if (c == '.') + { + c = getch (); + if (c == '.') + { + *p++ = '.'; + *p = '\0'; + value = ELLIPSIS; + goto done; + } + error ("parse error at `..'"); + } + nextchar = c; + token_buffer[1] = '\0'; + value = '.'; + goto done; + } + } + else + { + /* It is not a decimal point. + It should be a digit (perhaps a hex digit). */ + + if (isdigit (c)) + { + c = c - '0'; + } + else if (base <= 10) + { + if (c == 'e' || c == 'E') + { + base = 10; + floatflag = AFTER_POINT; + break; /* start of exponent */ + } + error ("nondigits in number and not hexadecimal"); + c = 0; + } + else if (c >= 'a') + { + c = c - 'a' + 10; + } + else + { + c = c - 'A' + 10; + } + if (c >= largest_digit) + largest_digit = c; + numdigits++; + + for (count = 0; count < TOTAL_PARTS; count++) + { + parts[count] *= base; + if (count) + { + parts[count] + += (parts[count-1] >> HOST_BITS_PER_CHAR); + parts[count-1] + &= (1 << HOST_BITS_PER_CHAR) - 1; + } + else + parts[0] += c; + } + + /* If the extra highest-order part ever gets anything in it, + the number is certainly too big. */ + if (parts[TOTAL_PARTS - 1] != 0) + overflow = 1; + + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = (c = getch ()); + } + } + + if (numdigits == 0) + error ("numeric constant with no digits"); + + if (largest_digit >= base) + error ("numeric constant contains digits beyond the radix"); + + /* Remove terminating char from the token buffer and delimit the string */ + *--p = 0; + + if (floatflag != NOT_FLOAT) + { + tree type = double_type_node; + char f_seen = 0; + char l_seen = 0; + int garbage_chars = 0; + REAL_VALUE_TYPE value; + jmp_buf handler; + + /* Read explicit exponent if any, and put it in tokenbuf. */ + + if ((c == 'e') || (c == 'E')) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getch (); + if ((c == '+') || (c == '-')) + { + *p++ = c; + c = getch (); + } + if (! isdigit (c)) + error ("floating constant exponent has no digits"); + while (isdigit (c)) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getch (); + } + } + + *p = 0; + errno = 0; + + /* Convert string to a double, checking for overflow. */ + if (setjmp (handler)) + { + error ("floating constant out of range"); + value = dconst0; + } + else + { + set_float_handler (handler); + /* The second argument, machine_mode, of REAL_VALUE_ATOF + tells the desired precision of the binary result of + decimal-to-binary conversion. */ + + /* Read the suffixes to choose a data type. */ + switch (c) + { + case 'f': case 'F': + type = float_type_node; + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + garbage_chars = -1; + break; + + case 'l': case 'L': + type = long_double_type_node; + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + garbage_chars = -1; + break; + + default: + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + } + set_float_handler (NULL_PTR); + } + if (pedantic + && (REAL_VALUE_ISINF (value) +#ifdef ERANGE + || (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + && errno == ERANGE + /* ERANGE is also reported for underflow, so test the + value to distinguish overflow from that. */ + && (REAL_VALUES_LESS (dconst1, value) + || REAL_VALUES_LESS (value, dconstm1))) +#endif + )) + { + pedwarn ("floating point number exceeds range of `%s'", + IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); + } + /* Note: garbage_chars is -1 if first char is *not* garbage. */ + while (isalnum (c)) + { + if (c == 'f' || c == 'F') + { + if (f_seen) + error ("two `f's in floating constant"); + f_seen = 1; + } + if (c == 'l' || c == 'L') + { + if (l_seen) + error ("two `l's in floating constant"); + l_seen = 1; + } + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getch (); + garbage_chars++; + } + + if (garbage_chars > 0) + error ("garbage at end of number"); + + /* Create a node with determined type and value. */ + yylval.ttype = build_real (type, value); + + put_back (c); + *p = 0; + } + else + { + tree type; + HOST_WIDE_INT high, low; + int spec_unsigned = 0; + int spec_long = 0; + int spec_long_long = 0; + int bytes, warn; + + while (1) + { + if (c == 'u' || c == 'U') + { + if (spec_unsigned) + error ("two `u's in integer constant"); + spec_unsigned = 1; + } + else if (c == 'l' || c == 'L') + { + if (spec_long) + { + if (spec_long_long) + error ("three `l's in integer constant"); + else if (pedantic) + pedwarn ("ANSI C++ forbids long long integer constants"); + spec_long_long = 1; + } + spec_long = 1; + } + else + { + if (isalnum (c)) + { + error ("garbage at end of number"); + while (isalnum (c)) + { + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getch (); + } + } + break; + } + if (p >= token_buffer + maxtoken - 3) + p = extend_token_buffer (p); + *p++ = c; + c = getch (); + } + + put_back (c); + + /* If the constant is not long long and it won't fit in an + unsigned long, or if the constant is long long and won't fit + in an unsigned long long, then warn that the constant is out + of range. */ + + /* ??? This assumes that long long and long integer types are + a multiple of 8 bits. This better than the original code + though which assumed that long was exactly 32 bits and long + long was exactly 64 bits. */ + + if (spec_long_long) + bytes = TYPE_PRECISION (long_long_integer_type_node) / 8; + else + bytes = TYPE_PRECISION (long_integer_type_node) / 8; + + warn = overflow; + for (i = bytes; i < TOTAL_PARTS; i++) + if (parts[i]) + warn = 1; + if (warn) + pedwarn ("integer constant out of range"); + + /* This is simplified by the fact that our constant + is always positive. */ + high = low = 0; + + for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++) + { + high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT + / HOST_BITS_PER_CHAR)] + << (i * HOST_BITS_PER_CHAR)); + low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR); + } + + + yylval.ttype = build_int_2 (low, high); + TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node; + +#if 0 + /* Find the first allowable type that the value fits in. */ + type = 0; + for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]); + i++) + if (!(spec_long && !type_sequence[i].long_flag) + && !(spec_long_long && !type_sequence[i].long_long_flag) + && !(spec_unsigned && !type_sequence[i].unsigned_flag) + /* A hex or octal constant traditionally is unsigned. */ + && !(base != 10 && flag_traditional + && !type_sequence[i].unsigned_flag) + /* A decimal constant can't be unsigned int + unless explicitly specified. */ + && !(base == 10 && !spec_unsigned + && *type_sequence[i].node_var == unsigned_type_node)) + if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var)) + { + type = *type_sequence[i].node_var; + break; + } + if (flag_traditional && type == long_unsigned_type_node + && !spec_unsigned) + type = long_integer_type_node; + + if (type == 0) + { + type = long_long_integer_type_node; + warning ("integer constant out of range"); + } + + /* Warn about some cases where the type of a given constant + changes from traditional C to ANSI C. */ + if (warn_traditional) + { + tree other_type = 0; + + /* This computation is the same as the previous one + except that flag_traditional is used backwards. */ + for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]); + i++) + if (!(spec_long && !type_sequence[i].long_flag) + && !(spec_long_long && !type_sequence[i].long_long_flag) + && !(spec_unsigned && !type_sequence[i].unsigned_flag) + /* A hex or octal constant traditionally is unsigned. */ + && !(base != 10 && !flag_traditional + && !type_sequence[i].unsigned_flag) + /* A decimal constant can't be unsigned int + unless explicitly specified. */ + && !(base == 10 && !spec_unsigned + && *type_sequence[i].node_var == unsigned_type_node)) + if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var)) + { + other_type = *type_sequence[i].node_var; + break; + } + if (!flag_traditional && type == long_unsigned_type_node + && !spec_unsigned) + type = long_integer_type_node; + + if (other_type != 0 && other_type != type) + { + if (flag_traditional) + warning ("type of integer constant would be different without -traditional"); + else + warning ("type of integer constant would be different with -traditional"); + } + } + +#else /* 1 */ + if (!spec_long && !spec_unsigned + && !(flag_traditional && base != 10) + && int_fits_type_p (yylval.ttype, integer_type_node)) + { +#if 0 + if (warn_traditional && base != 10) + warning ("small nondecimal constant becomes signed in ANSI C++"); +#endif + type = integer_type_node; + } + else if (!spec_long && (base != 10 || spec_unsigned) + && int_fits_type_p (yylval.ttype, unsigned_type_node)) + { + /* Nondecimal constants try unsigned even in traditional C. */ + type = unsigned_type_node; + } + + else if (!spec_unsigned && !spec_long_long + && int_fits_type_p (yylval.ttype, long_integer_type_node)) + type = long_integer_type_node; + + else if (! spec_long_long + && int_fits_type_p (yylval.ttype, + long_unsigned_type_node)) + { +#if 0 + if (warn_traditional && !spec_unsigned) + warning ("large integer constant becomes unsigned in ANSI C++"); +#endif + if (flag_traditional && !spec_unsigned) + type = long_integer_type_node; + else + type = long_unsigned_type_node; + } + + else if (! spec_unsigned + /* Verify value does not overflow into sign bit. */ + && TREE_INT_CST_HIGH (yylval.ttype) >= 0 + && int_fits_type_p (yylval.ttype, + long_long_integer_type_node)) + type = long_long_integer_type_node; + + else if (int_fits_type_p (yylval.ttype, + long_long_unsigned_type_node)) + { +#if 0 + if (warn_traditional && !spec_unsigned) + warning ("large nondecimal constant is unsigned in ANSI C++"); +#endif + + if (flag_traditional && !spec_unsigned) + type = long_long_integer_type_node; + else + type = long_long_unsigned_type_node; + } + + else + { + type = long_long_integer_type_node; + warning ("integer constant out of range"); + + if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type)) + warning ("decimal integer constant is so large that it is unsigned"); + } +#endif + + TREE_TYPE (yylval.ttype) = type; + *p = 0; + } + + value = CONSTANT; break; + } + + case '\'': + char_constant: + { + register int result = 0; + register int num_chars = 0; + unsigned width = TYPE_PRECISION (char_type_node); + int max_chars; + + if (wide_flag) + { + width = WCHAR_TYPE_SIZE; +#ifdef MULTIBYTE_CHARS + max_chars = MB_CUR_MAX; +#else + max_chars = 1; +#endif + } + else + max_chars = TYPE_PRECISION (integer_type_node) / width; + + while (1) + { + tryagain: + + c = getch (); + + if (c == '\'' || c == EOF) + break; + + if (c == '\\') + { + int ignore = 0; + c = readescape (&ignore); + if (ignore) + goto tryagain; + if (width < HOST_BITS_PER_INT + && (unsigned) c >= (1 << width)) + warning ("escape sequence out of range for character"); +#ifdef MAP_CHARACTER + if (isprint (c)) + c = MAP_CHARACTER (c); +#endif + } + else if (c == '\n') + { + if (pedantic) + pedwarn ("ANSI C++ forbids newline in character constant"); + lineno++; + } +#ifdef MAP_CHARACTER + else + c = MAP_CHARACTER (c); +#endif + + num_chars++; + if (num_chars > maxtoken - 4) + extend_token_buffer (token_buffer); + + token_buffer[num_chars] = c; + + /* Merge character into result; ignore excess chars. */ + if (num_chars < max_chars + 1) + { + if (width < HOST_BITS_PER_INT) + result = (result << width) | (c & ((1 << width) - 1)); + else + result = c; + } + } + + token_buffer[num_chars + 1] = '\''; + token_buffer[num_chars + 2] = 0; + + if (c != '\'') + error ("malformatted character constant"); + else if (num_chars == 0) + error ("empty character constant"); + else if (num_chars > max_chars) + { + num_chars = max_chars; + error ("character constant too long"); + } + else if (num_chars != 1 && ! flag_traditional) + warning ("multi-character character constant"); + + /* If char type is signed, sign-extend the constant. */ + if (! wide_flag) + { + int num_bits = num_chars * width; + if (num_bits == 0) + /* We already got an error; avoid invalid shift. */ + yylval.ttype = build_int_2 (0, 0); + else if (TREE_UNSIGNED (char_type_node) + || ((result >> (num_bits - 1)) & 1) == 0) + yylval.ttype + = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0 + >> (HOST_BITS_PER_WIDE_INT - num_bits)), + 0); + else + yylval.ttype + = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0 + >> (HOST_BITS_PER_WIDE_INT - num_bits)), + -1); + if (num_chars<=1) + TREE_TYPE (yylval.ttype) = char_type_node; + else + TREE_TYPE (yylval.ttype) = integer_type_node; + } + else + { +#ifdef MULTIBYTE_CHARS + /* Set the initial shift state and convert the next sequence. */ + result = 0; + /* In all locales L'\0' is zero and mbtowc will return zero, + so don't use it. */ + if (num_chars > 1 + || (num_chars == 1 && token_buffer[1] != '\0')) + { + wchar_t wc; + (void) mbtowc (NULL, NULL, 0); + if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars) + result = wc; + else + warning ("Ignoring invalid multibyte character"); + } +#endif + yylval.ttype = build_int_2 (result, 0); + TREE_TYPE (yylval.ttype) = wchar_type_node; + } + + value = CONSTANT; + break; + } + + case '"': + string_constant: + { + register char *p; + + c = getch (); + p = token_buffer + 1; + + while (c != '"' && c >= 0) + { + /* ignore_escape_flag is set for reading the filename in #line. */ + if (!ignore_escape_flag && c == '\\') + { + int ignore = 0; + c = readescape (&ignore); + if (ignore) + goto skipnewline; + if (!wide_flag + && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT + && c >= ((unsigned) 1 << TYPE_PRECISION (char_type_node))) + warning ("escape sequence out of range for character"); + } + else if (c == '\n') + { + if (pedantic) + pedwarn ("ANSI C++ forbids newline in string constant"); + lineno++; + } + + if (p == token_buffer + maxtoken) + p = extend_token_buffer (p); + *p++ = c; + + skipnewline: + c = getch (); + if (c == EOF) { + error("Unterminated string"); + break; + } + } + *p = 0; + + /* We have read the entire constant. + Construct a STRING_CST for the result. */ + + if (wide_flag) + { + /* If this is a L"..." wide-string, convert the multibyte string + to a wide character string. */ + char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES); + int len; + +#ifdef MULTIBYTE_CHARS + len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer); + if (len < 0 || len >= (p - token_buffer)) + { + warning ("Ignoring invalid multibyte string"); + len = 0; + } + bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES); +#else + { + union { long l; char c[sizeof (long)]; } u; + int big_endian; + char *wp, *cp; + + /* Determine whether host is little or big endian. */ + u.l = 1; + big_endian = u.c[sizeof (long) - 1]; + wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0); + + bzero (widep, (p - token_buffer) * WCHAR_BYTES); + for (cp = token_buffer + 1; cp < p; cp++) + *wp = *cp, wp += WCHAR_BYTES; + len = p - token_buffer - 1; + } +#endif + yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep); + TREE_TYPE (yylval.ttype) = wchar_array_type_node; + } + else + { + yylval.ttype = build_string (p - token_buffer, token_buffer + 1); + TREE_TYPE (yylval.ttype) = char_array_type_node; + } + + *p++ = '"'; + *p = 0; + + value = STRING; break; + } + + case '+': + case '-': + case '&': + case '|': + case '<': + case '>': + case '*': + case '/': + case '%': + case '^': + case '!': + case '=': + { + register int c1; + + combine: + + switch (c) + { + case '+': + yylval.code = PLUS_EXPR; break; + case '-': + yylval.code = MINUS_EXPR; break; + case '&': + yylval.code = BIT_AND_EXPR; break; + case '|': + yylval.code = BIT_IOR_EXPR; break; + case '*': + yylval.code = MULT_EXPR; break; + case '/': + yylval.code = TRUNC_DIV_EXPR; break; + case '%': + yylval.code = TRUNC_MOD_EXPR; break; + case '^': + yylval.code = BIT_XOR_EXPR; break; + case LSHIFT: + yylval.code = LSHIFT_EXPR; break; + case RSHIFT: + yylval.code = RSHIFT_EXPR; break; + case '<': + yylval.code = LT_EXPR; break; + case '>': + yylval.code = GT_EXPR; break; + } + + token_buffer[1] = c1 = getch (); + token_buffer[2] = 0; + + if (c1 == '=') + { + switch (c) + { + case '<': + value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done; + case '>': + value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done; + case '!': + value = EQCOMPARE; yylval.code = NE_EXPR; goto done; + case '=': + value = EQCOMPARE; yylval.code = EQ_EXPR; goto done; + } + value = ASSIGN; goto done; + } + else if (c == c1) + switch (c) + { + case '+': + value = PLUSPLUS; goto done; + case '-': + value = MINUSMINUS; goto done; + case '&': + value = ANDAND; goto done; + case '|': + value = OROR; goto done; + case '<': + c = LSHIFT; + goto combine; + case '>': + c = RSHIFT; + goto combine; + } + else if ((c == '-') && (c1 == '>')) + { + nextchar = getch (); + if (nextchar == '*') + { + nextchar = -1; + value = POINTSAT_STAR; + } + else + value = POINTSAT; + goto done; + } + else if (c1 == '?' && (c == '<' || c == '>')) + { + token_buffer[3] = 0; + + c1 = getch (); + yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR); + if (c1 == '=') + { + /* ?= expression. */ + token_buffer[2] = c1; + value = ASSIGN; + } + else + { + value = MIN_MAX; + nextchar = c1; + } + if (pedantic) + pedwarn ("use of `operator %s' is not standard C++", + token_buffer); + goto done; + } + /* digraphs */ + else if (c == '<' && c1 == '%') + { value = '{'; goto done; } + else if (c == '<' && c1 == ':') + { value = '['; goto done; } + else if (c == '%' && c1 == '>') + { value = '}'; goto done; } + else if (c == '%' && c1 == ':') + { value = '#'; goto done; } + + nextchar = c1; + token_buffer[1] = 0; + + value = c; + goto done; + } + + case ':': + c = getch (); + if (c == ':') + { + token_buffer[1] = ':'; + token_buffer[2] = '\0'; + value = SCOPE; + yylval.itype = 1; + } + else if (c == '>') + { + value = ']'; + goto done; + } + else + { + nextchar = c; + value = ':'; + } + break; + + case 0: + /* Don't make yyparse think this is eof. */ + value = 1; + break; + + case '(': + /* try, weakly, to handle casts to pointers to functions. */ + nextchar = skip_white_space (getch ()); + if (nextchar == '*') + { + int next_c = skip_white_space (getch ()); + if (next_c == ')') + { + nextchar = -1; + yylval.ttype = build1 (INDIRECT_REF, 0, 0); + value = PAREN_STAR_PAREN; + } + else + { + put_back (next_c); + value = c; + } + } + else if (nextchar == ')') + { + nextchar = -1; + yylval.ttype = NULL_TREE; + value = LEFT_RIGHT; + } + else value = c; + break; + + default: + value = c; + } + +done: +/* yylloc.last_line = lineno; */ +#ifdef GATHER_STATISTICS + token_count[value] += 1; +#endif + + return value; +} + +typedef enum +{ + d_kind, t_kind, s_kind, r_kind, e_kind, c_kind, + id_kind, op_id_kind, perm_list_kind, temp_list_kind, + vec_kind, x_kind, lang_decl, lang_type, all_kinds +} tree_node_kind; +extern int tree_node_counts[]; +extern int tree_node_sizes[]; +extern char *tree_node_kind_names[]; + +/* Place to save freed lang_decls which were allocated on the + permanent_obstack. @@ Not currently used. */ +tree free_lang_decl_chain; + +tree +build_lang_decl (code, name, type) + enum tree_code code; + tree name; + tree type; +{ + register tree t = build_decl (code, name, type); + struct obstack *obstack = current_obstack; + register int i = sizeof (struct lang_decl) / sizeof (int); + register int *pi; + + if (! TREE_PERMANENT (t)) + obstack = saveable_obstack; + else + /* Could be that saveable is permanent and current is not. */ + obstack = &permanent_obstack; + + if (free_lang_decl_chain && obstack == &permanent_obstack) + { + pi = (int *)free_lang_decl_chain; + free_lang_decl_chain = TREE_CHAIN (free_lang_decl_chain); + } + else + pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl)); + + while (i > 0) + pi[--i] = 0; + + DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi; + LANG_DECL_PERMANENT ((struct lang_decl *) pi) + = obstack == &permanent_obstack; + my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl *) pi) + == TREE_PERMANENT (t), 234); + DECL_MAIN_VARIANT (t) = t; + if (current_lang_name == lang_name_cplusplus) + { + DECL_LANGUAGE (t) = lang_cplusplus; +#if 0 +#ifndef NO_AUTO_OVERLOAD + if (code == FUNCTION_DECL && name != 0 + && ! (IDENTIFIER_LENGTH (name) == 4 + && IDENTIFIER_POINTER (name)[0] == 'm' + && strcmp (IDENTIFIER_POINTER (name), "main") == 0) + && ! (IDENTIFIER_LENGTH (name) > 10 + && IDENTIFIER_POINTER (name)[0] == '_' + && IDENTIFIER_POINTER (name)[1] == '_' + && strncmp (IDENTIFIER_POINTER (name)+2, "builtin_", 8) == 0)) + TREE_OVERLOADED (name) = 1; +#endif +#endif + } + else if (current_lang_name == lang_name_c) + DECL_LANGUAGE (t) = lang_c; + else my_friendly_abort (64); + +#if 0 /* not yet, should get fixed properly later */ + if (code == TYPE_DECL) + { + tree id; + id = get_identifier (build_overload_name (type, 1, 1)); + DECL_ASSEMBLER_NAME (t) = id; + } + +#endif +#ifdef GATHER_STATISTICS + tree_node_counts[(int)lang_decl] += 1; + tree_node_sizes[(int)lang_decl] += sizeof(struct lang_decl); +#endif + + return t; +} + +tree +build_lang_field_decl (code, name, type) + enum tree_code code; + tree name; + tree type; +{ + extern struct obstack *current_obstack, *saveable_obstack; + register tree t = build_decl (code, name, type); + struct obstack *obstack = current_obstack; + register int i = sizeof (struct lang_decl_flags) / sizeof (int); + register int *pi; +#if 0 /* not yet, should get fixed properly later */ + + if (code == TYPE_DECL) + { + tree id; + id = get_identifier (build_overload_name (type, 1, 1)); + DECL_ASSEMBLER_NAME (t) = id; + } +#endif + + if (! TREE_PERMANENT (t)) + obstack = saveable_obstack; + else + my_friendly_assert (obstack == &permanent_obstack, 235); + + pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl_flags)); + while (i > 0) + pi[--i] = 0; + + DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi; + return t; +} + +void +copy_lang_decl (node) + tree node; +{ + int size; + int *pi; + + if (TREE_CODE (node) == FIELD_DECL) + size = sizeof (struct lang_decl_flags); + else + size = sizeof (struct lang_decl); + pi = (int *)obstack_alloc (&permanent_obstack, size); + bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size); + DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi; +} + +tree +make_lang_type (code) + enum tree_code code; +{ + extern struct obstack *current_obstack, *saveable_obstack; + register tree t = make_node (code); + struct obstack *obstack = current_obstack; + register int i = sizeof (struct lang_type) / sizeof (int); + register int *pi; + + /* Set up some flags that give proper default behavior. */ + IS_AGGR_TYPE (t) = 1; + + if (! TREE_PERMANENT (t)) + obstack = saveable_obstack; + else + my_friendly_assert (obstack == &permanent_obstack, 236); + + pi = (int *) obstack_alloc (obstack, sizeof (struct lang_type)); + while (i > 0) + pi[--i] = 0; + + TYPE_LANG_SPECIFIC (t) = (struct lang_type *) pi; + CLASSTYPE_AS_LIST (t) = build_tree_list (NULL_TREE, t); + SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); + CLASSTYPE_INTERFACE_ONLY (t) = interface_only; + CLASSTYPE_VBASE_SIZE (t) = integer_zero_node; + TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE, + NULL_TREE); + CLASSTYPE_BINFO_AS_LIST (t) = build_tree_list (NULL_TREE, TYPE_BINFO (t)); + + /* Make sure this is laid out, for ease of use later. + In the presence of parse errors, the normal was of assuring + this might not ever get executed, so we lay it out *immediately*. */ + build_pointer_type (t); + +#ifdef GATHER_STATISTICS + tree_node_counts[(int)lang_type] += 1; + tree_node_sizes[(int)lang_type] += sizeof(struct lang_type); +#endif + + return t; +} + +void +copy_decl_lang_specific (decl) + tree decl; +{ + extern struct obstack *current_obstack, *saveable_obstack; + register int *old = (int *)DECL_LANG_SPECIFIC (decl); + struct obstack *obstack = current_obstack; + register int i = sizeof (struct lang_decl) / sizeof (int); + register int *pi; + + if (! TREE_PERMANENT (decl)) + obstack = saveable_obstack; + else + my_friendly_assert (obstack == &permanent_obstack, 237); + + pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl)); + while (i-- > 0) + pi[i] = old[i]; + + DECL_LANG_SPECIFIC (decl) = (struct lang_decl *) pi; + +#ifdef GATHER_STATISTICS + tree_node_counts[(int)lang_decl] += 1; + tree_node_sizes[(int)lang_decl] += sizeof(struct lang_decl); +#endif +} + +void +dump_time_statistics () +{ + register tree prev = 0, decl, next; + int this_time = my_get_run_time (); + TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) + += this_time - body_time; + + fprintf (stderr, "\n******\n"); + print_time ("header files (total)", header_time); + print_time ("main file (total)", this_time - body_time); + fprintf (stderr, "ratio = %g : 1\n", + (double)header_time / (double)(this_time - body_time)); + fprintf (stderr, "\n******\n"); + + for (decl = filename_times; decl; decl = next) + { + next = IDENTIFIER_GLOBAL_VALUE (decl); + IDENTIFIER_GLOBAL_VALUE (decl) = prev; + prev = decl; + } + + for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl)) + print_time (IDENTIFIER_POINTER (decl), + TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (decl))); +} + +void +compiler_error (s, v, v2) + char *s; + HOST_WIDE_INT v, v2; /* @@also used as pointer */ +{ + char buf[1024]; + sprintf (buf, s, v, v2); + error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf); +} + +void +compiler_error_with_decl (decl, s) + tree decl; + char *s; +{ + char *name; + count_error (0); + + report_error_function (0); + + if (TREE_CODE (decl) == PARM_DECL) + fprintf (stderr, "%s:%d: ", + DECL_SOURCE_FILE (DECL_CONTEXT (decl)), + DECL_SOURCE_LINE (DECL_CONTEXT (decl))); + else + fprintf (stderr, "%s:%d: ", + DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); + + name = lang_printable_name (decl); + if (name) + fprintf (stderr, s, name); + else + fprintf (stderr, s, "((anonymous))"); + fprintf (stderr, " (compiler error)\n"); +} + +void +yyerror (string) + char *string; +{ + extern int end_of_file; + char buf[200]; + + strcpy (buf, string); + + /* We can't print string and character constants well + because the token_buffer contains the result of processing escapes. */ + if (end_of_file) + strcat (buf, input_redirected () + ? " at end of saved text" + : " at end of input"); + else if (token_buffer[0] == 0) + strcat (buf, " at null character"); + else if (token_buffer[0] == '"') + strcat (buf, " before string constant"); + else if (token_buffer[0] == '\'') + strcat (buf, " before character constant"); + else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177) + sprintf (buf + strlen (buf), " before character 0%o", + (unsigned char) token_buffer[0]); + else + strcat (buf, " before `%s'"); + + error (buf, token_buffer); +} + +#ifdef HANDLE_SYSV_PRAGMA + +/* Handle a #pragma directive. INPUT is the current input stream, + and C is a character to reread. Processes the entire input line + and returns a character for the caller to reread: either \n or EOF. */ + +/* This function has to be in this file, in order to get at + the token types. */ + +handle_sysv_pragma () +{ + for (;;) + { + switch (yylex ()) + { + case IDENTIFIER: + case TYPENAME: + case STRING: + case CONSTANT: + handle_pragma_token ("ignored", yylval.ttype); + break; + case '(': + handle_pragma_token ("(", NULL_TREE); + break; + case ')': + handle_pragma_token (")", NULL_TREE); + break; + case ',': + handle_pragma_token (",", NULL_TREE); + break; + case '=': + handle_pragma_token ("=", NULL_TREE); + break; + case LEFT_RIGHT: + handle_pragma_token ("(", NULL_TREE); + handle_pragma_token (")", NULL_TREE); + break; + case END_OF_LINE: + handle_pragma_token (NULL_PTR, NULL_TREE); + return; + default: + handle_pragma_token (NULL_PTR, NULL_TREE); + while (yylex () != END_OF_LINE) + /* continue */; + return; + } + } +} +#endif /* HANDLE_SYSV_PRAGMA */ diff --git a/contrib/gcc/cp/lex.h b/contrib/gcc/cp/lex.h new file mode 100644 index 00000000000..1cf5687df3f --- /dev/null +++ b/contrib/gcc/cp/lex.h @@ -0,0 +1,135 @@ +/* Define constants and variables for communication with parse.y. + Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + and by Brendan Kehoe (brendan@cygnus.com). + +This file is part of GNU CC. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the GNU CC General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +GNU CC, but only under the conditions described in the +GNU CC General Public License. A copy of this license is +supposed to have been given to you along with GNU CC so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + + +enum rid +{ + RID_UNUSED, + RID_INT, + RID_BOOL, + RID_CHAR, + RID_WCHAR, + RID_FLOAT, + RID_DOUBLE, + RID_VOID, + + /* C++ extension */ + RID_CLASS, + RID_RECORD, + RID_UNION, + RID_ENUM, + RID_LONGLONG, + + /* This is where grokdeclarator starts its search when setting the specbits. + The first seven are in the order of most frequently used, as found + building libg++. */ + + RID_EXTERN, + RID_CONST, + RID_LONG, + RID_TYPEDEF, + RID_UNSIGNED, + RID_SHORT, + RID_INLINE, + + RID_STATIC, + + RID_REGISTER, + RID_VOLATILE, + RID_FRIEND, + RID_VIRTUAL, + RID_EXPLICIT, + RID_SIGNED, + RID_AUTO, + RID_MUTABLE, + + /* This is where grokdeclarator ends its search when setting the specbits. */ + + RID_PUBLIC, + RID_PRIVATE, + RID_PROTECTED, + RID_EXCEPTION, + RID_TEMPLATE, + RID_SIGNATURE, + /* Before adding enough to get up to 64, the RIDBIT_* macros + will have to be changed a little. */ + RID_MAX +}; + +#define NORID RID_UNUSED + +#define RID_FIRST_MODIFIER RID_EXTERN +#define RID_LAST_MODIFIER RID_MUTABLE + +/* The type that can represent all values of RIDBIT. */ +/* We assume that we can stick in at least 32 bits into this. */ +typedef struct { unsigned long idata[2]; } + RID_BIT_TYPE; + +/* Be careful, all these modify N twice. */ +#define RIDBIT_SETP(N, V) (((unsigned long)1 << (int) ((N)%32)) \ + & (V).idata[(N)/32]) +#define RIDBIT_NOTSETP(NN, VV) (! RIDBIT_SETP (NN, VV)) +#define RIDBIT_SET(N, V) do { \ + (V).idata[(N)/32] \ + |= ((unsigned long)1 << (int) ((N)%32)); \ + } while (0) +#define RIDBIT_RESET(N, V) do { \ + (V).idata[(N)/32] \ + &= ~((unsigned long)1 << (int) ((N)%32)); \ + } while (0) +#define RIDBIT_RESET_ALL(V) do { \ + (V).idata[0] = 0; \ + (V).idata[1] = 0; \ + } while (0) +#define RIDBIT_ANY_SET(V) ((V).idata[0] || (V).idata[1]) + +/* The elements of `ridpointers' are identifier nodes + for the reserved type names and storage classes. + It is indexed by a RID_... value. */ +extern tree ridpointers[(int) RID_MAX]; + +/* the declaration found for the last IDENTIFIER token read in. + yylex must look this up to detect typedefs, which get token type TYPENAME, + so it is left around in case the identifier is not a typedef but is + used in a context which makes it a reference to a variable. */ +extern tree lastiddecl; + +extern char *token_buffer; /* Pointer to token buffer. */ + +/* Back-door communication channel to the lexer. */ +extern int looking_for_typename; +extern int looking_for_template; + +/* Tell the lexer where to look for names. */ +extern tree got_scope; +extern tree got_object; + +/* Pending language change. + Positive is push count, negative is pop count. */ +extern int pending_lang_change; + +extern tree make_pointer_declarator (), make_reference_declarator (); +extern void reinit_parse_for_function (); +extern void reinit_parse_for_method (); +extern int yylex (); diff --git a/contrib/gcc/cp/method.c b/contrib/gcc/cp/method.c new file mode 100644 index 00000000000..a0e15275140 --- /dev/null +++ b/contrib/gcc/cp/method.c @@ -0,0 +1,2287 @@ +/* Handle the hair of processing (but not expanding) inline functions. + Also manage function and variable name overloading. + Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + + This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#ifndef PARM_CAN_BE_ARRAY_TYPE +#define PARM_CAN_BE_ARRAY_TYPE 1 +#endif + +/* Handle method declarations. */ +#include +#include "config.h" +#include "tree.h" +#include "cp-tree.h" +#include "class.h" +#include "obstack.h" +#include +#include "rtl.h" +#include "expr.h" +#include "output.h" +#include "hard-reg-set.h" +#include "flags.h" + +/* TREE_LIST of the current inline functions that need to be + processed. */ +struct pending_inline *pending_inlines; + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +/* Obstack where we build text strings for overloading, etc. */ +static struct obstack scratch_obstack; +static char *scratch_firstobj; + +# define OB_INIT() (scratch_firstobj ? (obstack_free (&scratch_obstack, scratch_firstobj), 0) : 0) +# define OB_PUTC(C) (obstack_1grow (&scratch_obstack, (C))) +# define OB_PUTC2(C1,C2) \ + (obstack_1grow (&scratch_obstack, (C1)), obstack_1grow (&scratch_obstack, (C2))) +# define OB_PUTS(S) (obstack_grow (&scratch_obstack, (S), sizeof (S) - 1)) +# define OB_PUTID(ID) \ + (obstack_grow (&scratch_obstack, IDENTIFIER_POINTER (ID), \ + IDENTIFIER_LENGTH (ID))) +# define OB_PUTCP(S) (obstack_grow (&scratch_obstack, (S), strlen (S))) +# define OB_FINISH() (obstack_1grow (&scratch_obstack, '\0')) +# define OB_LAST() (obstack_next_free (&scratch_obstack)[-1]) + +#ifdef NO_AUTO_OVERLOAD +int is_overloaded (); +#endif + +void +init_method () +{ + gcc_obstack_init (&scratch_obstack); + scratch_firstobj = (char *)obstack_alloc (&scratch_obstack, 0); +} + +/* This must be large enough to hold any printed integer or floating-point + value. */ +static char digit_buffer[128]; + +/* Move inline function definitions out of structure so that they + can be processed normally. CNAME is the name of the class + we are working from, METHOD_LIST is the list of method lists + of the structure. We delete friend methods here, after + saving away their inline function definitions (if any). */ + +void +do_inline_function_hair (type, friend_list) + tree type, friend_list; +{ + tree method = TYPE_METHODS (type); + + if (method && TREE_CODE (method) == TREE_VEC) + { + if (TREE_VEC_ELT (method, 0)) + method = TREE_VEC_ELT (method, 0); + else + method = TREE_VEC_ELT (method, 1); + } + + while (method) + { + /* Do inline member functions. */ + struct pending_inline *info = DECL_PENDING_INLINE_INFO (method); + if (info) + { + tree args; + + my_friendly_assert (info->fndecl == method, 238); + args = DECL_ARGUMENTS (method); + while (args) + { + DECL_CONTEXT (args) = method; + args = TREE_CHAIN (args); + } + + /* Allow this decl to be seen in global scope. Don't do this for + local class methods, though. */ + if (! current_function_decl) + IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (method)) = method; + } + method = TREE_CHAIN (method); + } + while (friend_list) + { + tree fndecl = TREE_VALUE (friend_list); + struct pending_inline *info = DECL_PENDING_INLINE_INFO (fndecl); + if (info) + { + tree args; + + my_friendly_assert (info->fndecl == fndecl, 239); + args = DECL_ARGUMENTS (fndecl); + while (args) + { + DECL_CONTEXT (args) = fndecl; + args = TREE_CHAIN (args); + } + + /* Allow this decl to be seen in global scope */ + if (! current_function_decl) + IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (fndecl)) = fndecl; + } + + friend_list = TREE_CHAIN (friend_list); + } +} + +/* Report an argument type mismatch between the best declared function + we could find and the current argument list that we have. */ +void +report_type_mismatch (cp, parmtypes, name_kind) + struct candidate *cp; + tree parmtypes; + char *name_kind; +{ + int i = cp->u.bad_arg; + tree ttf, tta; + char *tmp_firstobj; + + switch (i) + { + case -4: + my_friendly_assert (TREE_CODE (cp->function) == TEMPLATE_DECL, 240); + cp_error ("type unification failed for function template `%#D'", + cp->function); + return; + + case -2: + cp_error ("too few arguments for %s `%#D'", name_kind, cp->function); + return; + case -1: + cp_error ("too many arguments for %s `%#D'", name_kind, cp->function); + return; + case 0: + if (TREE_CODE (TREE_TYPE (cp->function)) != METHOD_TYPE) + break; + case -3: + /* Happens when the implicit object parameter is rejected. */ + my_friendly_assert (! TYPE_READONLY (TREE_TYPE (TREE_VALUE (parmtypes))), + 241); + cp_error ("call to non-const %s `%#D' with const object", + name_kind, cp->function); + return; + } + + ttf = TYPE_ARG_TYPES (TREE_TYPE (cp->function)); + tta = parmtypes; + + while (i-- > 0) + { + ttf = TREE_CHAIN (ttf); + tta = TREE_CHAIN (tta); + } + + OB_INIT (); + OB_PUTS ("bad argument "); + sprintf (digit_buffer, "%d", cp->u.bad_arg + - (TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE) + + 1); + OB_PUTCP (digit_buffer); + + OB_PUTS (" for function `"); + OB_PUTCP (decl_as_string (cp->function, 1)); + OB_PUTS ("' (type was "); + + /* Reset `i' so that type printing routines do the right thing. */ + if (tta) + { + enum tree_code code = TREE_CODE (TREE_TYPE (TREE_VALUE (tta))); + if (code == ERROR_MARK) + OB_PUTS ("(failed type instantiation)"); + else + { + i = (code == FUNCTION_TYPE || code == METHOD_TYPE); + OB_PUTCP (type_as_string (TREE_TYPE (TREE_VALUE (tta)), 1)); + } + } + else OB_PUTS ("void"); + OB_PUTC (')'); + OB_FINISH (); + + tmp_firstobj = (char *)alloca (obstack_object_size (&scratch_obstack)); + bcopy (obstack_base (&scratch_obstack), tmp_firstobj, + obstack_object_size (&scratch_obstack)); + error (tmp_firstobj); +} + +/* Here is where overload code starts. */ + +/* Array of types seen so far in top-level call to `build_overload_name'. + Allocated and deallocated by caller. */ +static tree *typevec; + +/* Number of types interned by `build_overload_name' so far. */ +static int maxtype; + +/* Number of occurrences of last type seen. */ +static int nrepeats; + +/* Nonzero if we should not try folding parameter types. */ +static int nofold; + +#define ALLOCATE_TYPEVEC(PARMTYPES) \ + do { maxtype = 0, nrepeats = 0; \ + typevec = (tree *)alloca (list_length (PARMTYPES) * sizeof (tree)); } while (0) + +#define DEALLOCATE_TYPEVEC(PARMTYPES) \ + do { tree t = (PARMTYPES); \ + while (t) { TREE_USED (TREE_VALUE (t)) = 0; t = TREE_CHAIN (t); } \ + } while (0) + +/* Code to concatenate an asciified integer to a string. */ +static +#ifdef __GNUC__ +__inline +#endif +void +icat (i) + int i; +{ + /* Handle this case first, to go really quickly. For many common values, + the result of i/10 below is 1. */ + if (i == 1) + { + OB_PUTC ('1'); + return; + } + + if (i < 0) + { + OB_PUTC ('m'); + i = -i; + } + if (i < 10) + OB_PUTC ('0' + i); + else + { + icat (i / 10); + OB_PUTC ('0' + (i % 10)); + } +} + +static +#ifdef __GNUC__ +__inline +#endif +void +flush_repeats (type) + tree type; +{ + int tindex = 0; + + while (typevec[tindex] != type) + tindex++; + + if (nrepeats > 1) + { + OB_PUTC ('N'); + icat (nrepeats); + if (nrepeats > 9) + OB_PUTC ('_'); + } + else + OB_PUTC ('T'); + nrepeats = 0; + icat (tindex); + if (tindex > 9) + OB_PUTC ('_'); +} + +static int numeric_output_need_bar; +static void build_overload_identifier (); + +static void +build_overload_nested_name (decl) + tree decl; +{ + if (DECL_CONTEXT (decl)) + { + tree context = DECL_CONTEXT (decl); + if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') + context = TYPE_MAIN_DECL (context); + build_overload_nested_name (context); + } + + if (TREE_CODE (decl) == FUNCTION_DECL) + { + tree name = DECL_ASSEMBLER_NAME (decl); + char *label; + extern int var_labelno; + + ASM_FORMAT_PRIVATE_NAME (label, IDENTIFIER_POINTER (name), var_labelno); + var_labelno++; + + if (numeric_output_need_bar) + { + OB_PUTC ('_'); + numeric_output_need_bar = 0; + } + icat (strlen (label)); + OB_PUTCP (label); + } + else /* TYPE_DECL */ + { + tree name = DECL_NAME (decl); + build_overload_identifier (name); + } +} + +/* Encoding for an INTEGER_CST value. */ +static void +build_overload_int (value) + tree value; +{ + my_friendly_assert (TREE_CODE (value) == INTEGER_CST, 243); + if (TYPE_PRECISION (value) == 2 * HOST_BITS_PER_WIDE_INT) + { + if (tree_int_cst_lt (value, integer_zero_node)) + { + OB_PUTC ('m'); + value = build_int_2 (~ TREE_INT_CST_LOW (value), + - TREE_INT_CST_HIGH (value)); + } + if (TREE_INT_CST_HIGH (value) + != (TREE_INT_CST_LOW (value) >> (HOST_BITS_PER_WIDE_INT - 1))) + { + /* need to print a DImode value in decimal */ + sorry ("conversion of long long as PT parameter"); + } + /* else fall through to print in smaller mode */ + } + /* Wordsize or smaller */ + icat (TREE_INT_CST_LOW (value)); +} + +static void +build_overload_value (type, value) + tree type, value; +{ + while (TREE_CODE (value) == NON_LVALUE_EXPR + || TREE_CODE (value) == NOP_EXPR) + value = TREE_OPERAND (value, 0); + my_friendly_assert (TREE_CODE (type) == PARM_DECL, 242); + type = TREE_TYPE (type); + + if (numeric_output_need_bar) + { + OB_PUTC ('_'); + numeric_output_need_bar = 0; + } + + if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == OFFSET_TYPE) + { + /* Handle a pointer to data member as a template instantiation + parameter, boy, what fun! */ + type = integer_type_node; + if (TREE_CODE (value) != INTEGER_CST) + { + sorry ("unknown pointer to member constant"); + return; + } + } + + if (TYPE_PTRMEMFUNC_P (type)) + type = TYPE_PTRMEMFUNC_FN_TYPE (type); + + switch (TREE_CODE (type)) + { + case INTEGER_TYPE: + case ENUMERAL_TYPE: + case BOOLEAN_TYPE: + { + build_overload_int (value); + numeric_output_need_bar = 1; + return; + } +#ifndef REAL_IS_NOT_DOUBLE + case REAL_TYPE: + { + REAL_VALUE_TYPE val; + char *bufp = digit_buffer; + extern char *index (); + + my_friendly_assert (TREE_CODE (value) == REAL_CST, 244); + val = TREE_REAL_CST (value); + if (val < 0) + { + val = -val; + *bufp++ = 'm'; + } + sprintf (bufp, "%e", val); + bufp = (char *) index (bufp, 'e'); + if (!bufp) + strcat (digit_buffer, "e0"); + else + { + char *p; + bufp++; + if (*bufp == '-') + { + *bufp++ = 'm'; + } + p = bufp; + if (*p == '+') + p++; + while (*p == '0') + p++; + if (*p == 0) + { + *bufp++ = '0'; + *bufp = 0; + } + else if (p != bufp) + { + while (*p) + *bufp++ = *p++; + *bufp = 0; + } + } + OB_PUTCP (digit_buffer); + numeric_output_need_bar = 1; + return; + } +#endif + case POINTER_TYPE: + if (TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE + && TREE_CODE (value) != ADDR_EXPR) + { + if (TREE_CODE (value) == CONSTRUCTOR) + { + /* This is dangerous code, crack built up pointer to members. */ + tree args = CONSTRUCTOR_ELTS (value); + tree a1 = TREE_VALUE (args); + tree a2 = TREE_VALUE (TREE_CHAIN (args)); + tree a3 = CONSTRUCTOR_ELTS (TREE_VALUE (TREE_CHAIN (TREE_CHAIN (args)))); + a3 = TREE_VALUE (a3); + STRIP_NOPS (a3); + if (TREE_CODE (a1) == INTEGER_CST + && TREE_CODE (a2) == INTEGER_CST) + { + build_overload_int (a1); + OB_PUTC ('_'); + build_overload_int (a2); + OB_PUTC ('_'); + if (TREE_CODE (a3) == ADDR_EXPR) + { + a3 = TREE_OPERAND (a3, 0); + if (TREE_CODE (a3) == FUNCTION_DECL) + { + numeric_output_need_bar = 0; + build_overload_identifier (DECL_ASSEMBLER_NAME (a3)); + return; + } + } + else if (TREE_CODE (a3) == INTEGER_CST) + { + OB_PUTC ('i'); + build_overload_int (a3); + numeric_output_need_bar = 1; + return; + } + } + } + sorry ("template instantiation with pointer to method that is too complex"); + return; + } + if (TREE_CODE (value) == INTEGER_CST) + { + build_overload_int (value); + numeric_output_need_bar = 1; + return; + } + value = TREE_OPERAND (value, 0); + if (TREE_CODE (value) == VAR_DECL) + { + my_friendly_assert (DECL_NAME (value) != 0, 245); + build_overload_identifier (DECL_NAME (value)); + return; + } + else if (TREE_CODE (value) == FUNCTION_DECL) + { + my_friendly_assert (DECL_NAME (value) != 0, 246); + build_overload_identifier (DECL_NAME (value)); + return; + } + else + my_friendly_abort (71); + break; /* not really needed */ + + default: + sorry ("conversion of %s as template parameter", + tree_code_name [(int) TREE_CODE (type)]); + my_friendly_abort (72); + } +} + +static void +build_overload_identifier (name) + tree name; +{ + if (IDENTIFIER_TEMPLATE (name)) + { + tree template, parmlist, arglist, tname; + int i, nparms; + template = IDENTIFIER_TEMPLATE (name); + arglist = TREE_VALUE (template); + template = TREE_PURPOSE (template); + tname = DECL_NAME (template); + parmlist = DECL_ARGUMENTS (template); + nparms = TREE_VEC_LENGTH (parmlist); + OB_PUTC ('t'); + icat (IDENTIFIER_LENGTH (tname)); + OB_PUTID (tname); + icat (nparms); + for (i = 0; i < nparms; i++) + { + tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i)); + tree arg = TREE_VEC_ELT (arglist, i); + if (TREE_CODE (parm) == TYPE_DECL) + { + /* This parameter is a type. */ + OB_PUTC ('Z'); + build_overload_name (arg, 0, 0); + } + else + { + parm = tsubst (parm, &TREE_VEC_ELT (arglist, 0), + TREE_VEC_LENGTH (arglist), NULL_TREE); + /* It's a PARM_DECL. */ + build_overload_name (TREE_TYPE (parm), 0, 0); + build_overload_value (parm, arg); + } + } + } + else + { + if (numeric_output_need_bar) + { + OB_PUTC ('_'); + numeric_output_need_bar = 0; + } + icat (IDENTIFIER_LENGTH (name)); + OB_PUTID (name); + } +} + +/* Given a list of parameters in PARMTYPES, create an unambiguous + overload string. Should distinguish any type that C (or C++) can + distinguish. I.e., pointers to functions are treated correctly. + + Caller must deal with whether a final `e' goes on the end or not. + + Any default conversions must take place before this function + is called. + + BEGIN and END control initialization and finalization of the + obstack where we build the string. */ + +char * +build_overload_name (parmtypes, begin, end) + tree parmtypes; + int begin, end; +{ + int just_one; + tree parmtype; + + if (begin) OB_INIT (); + numeric_output_need_bar = 0; + + if ((just_one = (TREE_CODE (parmtypes) != TREE_LIST))) + { + parmtype = parmtypes; + goto only_one; + } + + while (parmtypes) + { + parmtype = TREE_VALUE (parmtypes); + + only_one: + + if (! nofold && ! just_one) + { + /* Every argument gets counted. */ + typevec[maxtype++] = parmtype; + + if (TREE_USED (parmtype) && parmtype == typevec[maxtype-2]) + { + nrepeats++; + goto next; + } + + if (nrepeats) + flush_repeats (typevec[maxtype-2]); + + if (TREE_USED (parmtype)) + { + flush_repeats (parmtype); + goto next; + } + + /* Only cache types which take more than one character. */ + if (parmtype != TYPE_MAIN_VARIANT (parmtype) + || (TREE_CODE (parmtype) != INTEGER_TYPE + && TREE_CODE (parmtype) != REAL_TYPE)) + TREE_USED (parmtype) = 1; + } + + if (TYPE_PTRMEMFUNC_P (parmtype)) + parmtype = TYPE_PTRMEMFUNC_FN_TYPE (parmtype); + + if (TREE_READONLY (parmtype)) + OB_PUTC ('C'); + if (TREE_CODE (parmtype) == INTEGER_TYPE + && TYPE_MAIN_VARIANT (parmtype) == unsigned_type (TYPE_MAIN_VARIANT (parmtype))) + OB_PUTC ('U'); + if (TYPE_VOLATILE (parmtype)) + OB_PUTC ('V'); + + switch (TREE_CODE (parmtype)) + { + case OFFSET_TYPE: + OB_PUTC ('O'); + build_overload_name (TYPE_OFFSET_BASETYPE (parmtype), 0, 0); + OB_PUTC ('_'); + build_overload_name (TREE_TYPE (parmtype), 0, 0); + break; + + case REFERENCE_TYPE: + OB_PUTC ('R'); + goto more; + + case ARRAY_TYPE: +#if PARM_CAN_BE_ARRAY_TYPE + { + tree length; + + OB_PUTC ('A'); + if (TYPE_DOMAIN (parmtype) == NULL_TREE) + error ("pointer or reference to array of unknown bound in parm type"); + else + { + length = array_type_nelts (parmtype); + if (TREE_CODE (length) == INTEGER_CST) + icat (TREE_INT_CST_LOW (length) + 1); + } + OB_PUTC ('_'); + goto more; + } +#else + OB_PUTC ('P'); + goto more; +#endif + + case POINTER_TYPE: + OB_PUTC ('P'); + more: + build_overload_name (TREE_TYPE (parmtype), 0, 0); + break; + + case FUNCTION_TYPE: + case METHOD_TYPE: + { + tree firstarg = TYPE_ARG_TYPES (parmtype); + /* Otherwise have to implement reentrant typevecs, + unmark and remark types, etc. */ + int old_nofold = nofold; + nofold = 1; + + if (nrepeats) + flush_repeats (typevec[maxtype-1]); + + /* @@ It may be possible to pass a function type in + which is not preceded by a 'P'. */ + if (TREE_CODE (parmtype) == FUNCTION_TYPE) + { + OB_PUTC ('F'); + if (firstarg == NULL_TREE) + OB_PUTC ('e'); + else if (firstarg == void_list_node) + OB_PUTC ('v'); + else + build_overload_name (firstarg, 0, 0); + } + else + { + int constp = TYPE_READONLY (TREE_TYPE (TREE_VALUE (firstarg))); + int volatilep = TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (firstarg))); + OB_PUTC ('M'); + firstarg = TREE_CHAIN (firstarg); + + build_overload_name (TYPE_METHOD_BASETYPE (parmtype), 0, 0); + if (constp) + OB_PUTC ('C'); + if (volatilep) + OB_PUTC ('V'); + + /* For cfront 2.0 compatibility. */ + OB_PUTC ('F'); + + if (firstarg == NULL_TREE) + OB_PUTC ('e'); + else if (firstarg == void_list_node) + OB_PUTC ('v'); + else + build_overload_name (firstarg, 0, 0); + } + + /* Separate args from return type. */ + OB_PUTC ('_'); + build_overload_name (TREE_TYPE (parmtype), 0, 0); + nofold = old_nofold; + break; + } + + case INTEGER_TYPE: + parmtype = TYPE_MAIN_VARIANT (parmtype); + if (parmtype == integer_type_node + || parmtype == unsigned_type_node) + OB_PUTC ('i'); + else if (parmtype == long_integer_type_node + || parmtype == long_unsigned_type_node) + OB_PUTC ('l'); + else if (parmtype == short_integer_type_node + || parmtype == short_unsigned_type_node) + OB_PUTC ('s'); + else if (parmtype == signed_char_type_node) + { + OB_PUTC ('S'); + OB_PUTC ('c'); + } + else if (parmtype == char_type_node + || parmtype == unsigned_char_type_node) + OB_PUTC ('c'); + else if (parmtype == wchar_type_node) + OB_PUTC ('w'); + else if (parmtype == long_long_integer_type_node + || parmtype == long_long_unsigned_type_node) + OB_PUTC ('x'); +#if 0 + /* it would seem there is no way to enter these in source code, + yet. (mrs) */ + else if (parmtype == long_long_long_integer_type_node + || parmtype == long_long_long_unsigned_type_node) + OB_PUTC ('q'); +#endif + else + my_friendly_abort (73); + break; + + case BOOLEAN_TYPE: + OB_PUTC ('b'); + break; + + case REAL_TYPE: + parmtype = TYPE_MAIN_VARIANT (parmtype); + if (parmtype == long_double_type_node) + OB_PUTC ('r'); + else if (parmtype == double_type_node) + OB_PUTC ('d'); + else if (parmtype == float_type_node) + OB_PUTC ('f'); + else my_friendly_abort (74); + break; + + case VOID_TYPE: + if (! just_one) + { +#if 0 + extern tree void_list_node; + + /* See if anybody is wasting memory. */ + my_friendly_assert (parmtypes == void_list_node, 247); +#endif + /* This is the end of a parameter list. */ + if (end) OB_FINISH (); + return (char *)obstack_base (&scratch_obstack); + } + OB_PUTC ('v'); + break; + + case ERROR_MARK: /* not right, but nothing is anyway */ + break; + + /* have to do these */ + case UNION_TYPE: + case RECORD_TYPE: + if (! just_one) + /* Make this type signature look incompatible + with AT&T. */ + OB_PUTC ('G'); + goto common; + case ENUMERAL_TYPE: + common: + { + tree name = TYPE_NAME (parmtype); + int i = 1; + + if (TREE_CODE (name) == TYPE_DECL) + { + tree context = name; + + /* If DECL_ASSEMBLER_NAME has been set properly, use it. */ + if (DECL_ASSEMBLER_NAME (context) != DECL_NAME (context)) + { + OB_PUTID (DECL_ASSEMBLER_NAME (context)); + break; + } + while (DECL_CONTEXT (context)) + { + i += 1; + context = DECL_CONTEXT (context); + if (TREE_CODE_CLASS (TREE_CODE (context)) == 't') + context = TYPE_NAME (context); + } + name = DECL_NAME (name); + } + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 248); + if (i > 1) + { + OB_PUTC ('Q'); + if (i > 9) + OB_PUTC ('_'); + icat (i); + if (i > 9) + OB_PUTC ('_'); + numeric_output_need_bar = 0; + build_overload_nested_name (TYPE_MAIN_DECL (parmtype)); + } + else + build_overload_identifier (name); + break; + } + + case UNKNOWN_TYPE: + /* This will take some work. */ + OB_PUTC ('?'); + break; + + case TEMPLATE_TYPE_PARM: + case TEMPLATE_CONST_PARM: + case UNINSTANTIATED_P_TYPE: + /* We don't ever want this output, but it's inconvenient not to + be able to build the string. This should cause assembler + errors we'll notice. */ + { + static int n; + sprintf (digit_buffer, " *%d", n++); + OB_PUTCP (digit_buffer); + } + break; + + default: + my_friendly_abort (75); + } + + next: + if (just_one) break; + parmtypes = TREE_CHAIN (parmtypes); + } + if (! just_one) + { + if (nrepeats) + flush_repeats (typevec[maxtype-1]); + + /* To get here, parms must end with `...'. */ + OB_PUTC ('e'); + } + + if (end) OB_FINISH (); + return (char *)obstack_base (&scratch_obstack); +} + +tree +build_static_name (basetype, name) + tree basetype, name; +{ + char *basename = build_overload_name (basetype, 1, 1); + char *buf = (char *) alloca (IDENTIFIER_LENGTH (name) + + sizeof (STATIC_NAME_FORMAT) + + strlen (basename)); + sprintf (buf, STATIC_NAME_FORMAT, basename, IDENTIFIER_POINTER (name)); + return get_identifier (buf); +} + +/* Generate an identifier that encodes the (ANSI) exception TYPE. */ + +/* This should be part of `ansi_opname', or at least be defined by the std. */ +#define EXCEPTION_NAME_PREFIX "__ex" +#define EXCEPTION_NAME_LENGTH 4 + +tree +cplus_exception_name (type) + tree type; +{ + OB_INIT (); + OB_PUTS (EXCEPTION_NAME_PREFIX); + return get_identifier (build_overload_name (type, 0, 1)); +} + +/* Change the name of a function definition so that it may be + overloaded. NAME is the name of the function to overload, + PARMS is the parameter list (which determines what name the + final function obtains). + + FOR_METHOD is 1 if this overload is being performed + for a method, rather than a function type. It is 2 if + this overload is being performed for a constructor. */ +tree +build_decl_overload (dname, parms, for_method) + tree dname; + tree parms; + int for_method; +{ + char *name = IDENTIFIER_POINTER (dname); + + /* member operators new and delete look like methods at this point. */ + if (! for_method && parms != NULL_TREE && TREE_CODE (parms) == TREE_LIST) + { + if (dname == ansi_opname[(int) DELETE_EXPR]) + return get_identifier ("__builtin_delete"); + else if (dname == ansi_opname[(int) VEC_DELETE_EXPR]) + return get_identifier ("__builtin_vec_delete"); + else if (TREE_CHAIN (parms) == void_list_node) + { + if (dname == ansi_opname[(int) NEW_EXPR]) + return get_identifier ("__builtin_new"); + else if (dname == ansi_opname[(int) VEC_NEW_EXPR]) + return get_identifier ("__builtin_vec_new"); + } + } + + OB_INIT (); + if (for_method != 2) + OB_PUTCP (name); + /* Otherwise, we can divine that this is a constructor, + and figure out its name without any extra encoding. */ + + OB_PUTC2 ('_', '_'); + if (for_method) + { +#if 0 + /* We can get away without doing this. */ + OB_PUTC ('M'); +#endif + { + tree this_type = TREE_VALUE (parms); + + if (TREE_CODE (this_type) == RECORD_TYPE) /* a signature pointer */ + parms = temp_tree_cons (NULL_TREE, SIGNATURE_TYPE (this_type), + TREE_CHAIN (parms)); + else + parms = temp_tree_cons (NULL_TREE, TREE_TYPE (this_type), + TREE_CHAIN (parms)); + } + } + else + OB_PUTC ('F'); + + if (parms == NULL_TREE) + OB_PUTC2 ('e', '\0'); + else if (parms == void_list_node) + OB_PUTC2 ('v', '\0'); + else + { + ALLOCATE_TYPEVEC (parms); + nofold = 0; + if (for_method) + { + build_overload_name (TREE_VALUE (parms), 0, 0); + + typevec[maxtype++] = TREE_VALUE (parms); + TREE_USED (TREE_VALUE (parms)) = 1; + + if (TREE_CHAIN (parms)) + build_overload_name (TREE_CHAIN (parms), 0, 1); + else + OB_PUTC2 ('e', '\0'); + } + else + build_overload_name (parms, 0, 1); + DEALLOCATE_TYPEVEC (parms); + } + { + tree n = get_identifier (obstack_base (&scratch_obstack)); + if (IDENTIFIER_OPNAME_P (dname)) + IDENTIFIER_OPNAME_P (n) = 1; + return n; + } +} + +/* Build an overload name for the type expression TYPE. */ +tree +build_typename_overload (type) + tree type; +{ + tree id; + + OB_INIT (); + OB_PUTID (ansi_opname[(int) TYPE_EXPR]); + nofold = 1; + build_overload_name (type, 0, 1); + id = get_identifier (obstack_base (&scratch_obstack)); + IDENTIFIER_OPNAME_P (id) = 1; +#if 0 + IDENTIFIER_GLOBAL_VALUE (id) = TYPE_NAME (type); +#endif + TREE_TYPE (id) = type; + return id; +} + +#ifndef NO_DOLLAR_IN_LABEL +#define T_DESC_FORMAT "TD$" +#define I_DESC_FORMAT "ID$" +#define M_DESC_FORMAT "MD$" +#else +#if !defined(NO_DOT_IN_LABEL) +#define T_DESC_FORMAT "TD." +#define I_DESC_FORMAT "ID." +#define M_DESC_FORMAT "MD." +#else +#define T_DESC_FORMAT "__t_desc_" +#define I_DESC_FORMAT "__i_desc_" +#define M_DESC_FORMAT "__m_desc_" +#endif +#endif + +/* Build an overload name for the type expression TYPE. */ +tree +build_t_desc_overload (type) + tree type; +{ + OB_INIT (); + OB_PUTS (T_DESC_FORMAT); + nofold = 1; + +#if 0 + /* Use a different format if the type isn't defined yet. */ + if (TYPE_SIZE (type) == NULL_TREE) + { + char *p; + int changed; + + for (p = tname; *p; p++) + if (isupper (*p)) + { + changed = 1; + *p = tolower (*p); + } + /* If there's no change, we have an inappropriate T_DESC_FORMAT. */ + my_friendly_assert (changed != 0, 249); + } +#endif + + build_overload_name (type, 0, 1); + return get_identifier (obstack_base (&scratch_obstack)); +} + +/* Top-level interface to explicit overload requests. Allow NAME + to be overloaded. Error if NAME is already declared for the current + scope. Warning if function is redundantly overloaded. */ + +void +declare_overloaded (name) + tree name; +{ +#ifdef NO_AUTO_OVERLOAD + if (is_overloaded (name)) + warning ("function `%s' already declared overloaded", + IDENTIFIER_POINTER (name)); + else if (IDENTIFIER_GLOBAL_VALUE (name)) + error ("overloading function `%s' that is already defined", + IDENTIFIER_POINTER (name)); + else + { + TREE_OVERLOADED (name) = 1; + IDENTIFIER_GLOBAL_VALUE (name) = build_tree_list (name, NULL_TREE); + TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)) = unknown_type_node; + } +#else + if (current_lang_name == lang_name_cplusplus) + { + if (0) + warning ("functions are implicitly overloaded in C++"); + } + else if (current_lang_name == lang_name_c) + error ("overloading function `%s' cannot be done in C language context"); + else + my_friendly_abort (76); +#endif +} + +#ifdef NO_AUTO_OVERLOAD +/* Check to see if NAME is overloaded. For first approximation, + check to see if its TREE_OVERLOADED is set. This is used on + IDENTIFIER nodes. */ +int +is_overloaded (name) + tree name; +{ + /* @@ */ + return (TREE_OVERLOADED (name) + && (! IDENTIFIER_CLASS_VALUE (name) || current_class_type == 0) + && ! IDENTIFIER_LOCAL_VALUE (name)); +} +#endif + +/* Given a tree_code CODE, and some arguments (at least one), + attempt to use an overloaded operator on the arguments. + + For unary operators, only the first argument need be checked. + For binary operators, both arguments may need to be checked. + + Member functions can convert class references to class pointers, + for one-level deep indirection. More than that is not supported. + Operators [](), ()(), and ->() must be member functions. + + We call function call building calls with LOOKUP_COMPLAIN if they + are our only hope. This is true when we see a vanilla operator + applied to something of aggregate type. If this fails, we are free + to return `error_mark_node', because we will have reported the + error. + + Operators NEW and DELETE overload in funny ways: operator new takes + a single `size' parameter, and operator delete takes a pointer to the + storage being deleted. When overloading these operators, success is + assumed. If there is a failure, report an error message and return + `error_mark_node'. */ + +/* NOSTRICT */ +tree +build_opfncall (code, flags, xarg1, xarg2, arg3) + enum tree_code code; + int flags; + tree xarg1, xarg2, arg3; +{ + tree rval = 0; + tree arg1, arg2; + tree type1, type2, fnname; + tree fields1 = 0, parms = 0; + tree global_fn; + int try_second; + int binary_is_unary; + + if (xarg1 == error_mark_node) + return error_mark_node; + + if (code == COND_EXPR) + { + if (TREE_CODE (xarg2) == ERROR_MARK + || TREE_CODE (arg3) == ERROR_MARK) + return error_mark_node; + } + if (code == COMPONENT_REF) + if (TREE_CODE (TREE_TYPE (xarg1)) == POINTER_TYPE) + return rval; + + /* First, see if we can work with the first argument */ + type1 = TREE_TYPE (xarg1); + + /* Some tree codes have length > 1, but we really only want to + overload them if their first argument has a user defined type. */ + switch (code) + { + case PREINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + case POSTDECREMENT_EXPR: + case COMPONENT_REF: + binary_is_unary = 1; + try_second = 0; + break; + + /* ARRAY_REFs and CALL_EXPRs must overload successfully. + If they do not, return error_mark_node instead of NULL_TREE. */ + case ARRAY_REF: + if (xarg2 == error_mark_node) + return error_mark_node; + case CALL_EXPR: + rval = error_mark_node; + binary_is_unary = 0; + try_second = 0; + break; + + case VEC_NEW_EXPR: + case NEW_EXPR: + { + tree args = tree_cons (NULL_TREE, xarg2, arg3); + fnname = ansi_opname[(int) code]; + if (flags & LOOKUP_GLOBAL) + return build_overload_call (fnname, args, flags & LOOKUP_COMPLAIN, + (struct candidate *)0); + + rval = build_method_call + (build_indirect_ref (build1 (NOP_EXPR, xarg1, error_mark_node), + "new"), + fnname, args, NULL_TREE, flags); + if (rval == error_mark_node) + /* User might declare fancy operator new, but invoke it + like standard one. */ + return rval; + + TREE_TYPE (rval) = xarg1; + TREE_CALLS_NEW (rval) = 1; + return rval; + } + break; + + case VEC_DELETE_EXPR: + case DELETE_EXPR: + { + fnname = ansi_opname[(int) code]; + if (flags & LOOKUP_GLOBAL) + return build_overload_call (fnname, + build_tree_list (NULL_TREE, xarg1), + flags & LOOKUP_COMPLAIN, + (struct candidate *)0); + + rval = build_method_call + (build_indirect_ref (build1 (NOP_EXPR, TREE_TYPE (xarg1), + error_mark_node), + NULL_PTR), + fnname, tree_cons (NULL_TREE, xarg1, + build_tree_list (NULL_TREE, xarg2)), + NULL_TREE, flags); +#if 0 + /* This can happen when operator delete is protected. */ + my_friendly_assert (rval != error_mark_node, 250); + TREE_TYPE (rval) = void_type_node; +#endif + return rval; + } + break; + + default: + binary_is_unary = 0; + try_second = tree_code_length [(int) code] == 2; + if (try_second && xarg2 == error_mark_node) + return error_mark_node; + break; + } + + if (try_second && xarg2 == error_mark_node) + return error_mark_node; + + /* What ever it was, we do not know how to deal with it. */ + if (type1 == NULL_TREE) + return rval; + + if (TREE_CODE (type1) == OFFSET_TYPE) + type1 = TREE_TYPE (type1); + + if (TREE_CODE (type1) == REFERENCE_TYPE) + { + arg1 = convert_from_reference (xarg1); + type1 = TREE_TYPE (arg1); + } + else + { + arg1 = xarg1; + } + + if (!IS_AGGR_TYPE (type1) || TYPE_PTRMEMFUNC_P (type1)) + { + /* Try to fail. First, fail if unary */ + if (! try_second) + return rval; + /* Second, see if second argument is non-aggregate. */ + type2 = TREE_TYPE (xarg2); + if (TREE_CODE (type2) == OFFSET_TYPE) + type2 = TREE_TYPE (type2); + if (TREE_CODE (type2) == REFERENCE_TYPE) + { + arg2 = convert_from_reference (xarg2); + type2 = TREE_TYPE (arg2); + } + else + { + arg2 = xarg2; + } + + if (!IS_AGGR_TYPE (type2)) + return rval; + try_second = 0; + } + + if (try_second) + { + /* First arg may succeed; see whether second should. */ + type2 = TREE_TYPE (xarg2); + if (TREE_CODE (type2) == OFFSET_TYPE) + type2 = TREE_TYPE (type2); + if (TREE_CODE (type2) == REFERENCE_TYPE) + { + arg2 = convert_from_reference (xarg2); + type2 = TREE_TYPE (arg2); + } + else + { + arg2 = xarg2; + } + + if (! IS_AGGR_TYPE (type2)) + try_second = 0; + } + + if (type1 == unknown_type_node + || (try_second && TREE_TYPE (xarg2) == unknown_type_node)) + { + /* This will not be implemented in the foreseeable future. */ + return rval; + } + + if (code == MODIFY_EXPR) + fnname = ansi_assopname[(int) TREE_CODE (arg3)]; + else + fnname = ansi_opname[(int) code]; + + global_fn = lookup_name_nonclass (fnname); + + /* This is the last point where we will accept failure. This + may be too eager if we wish an overloaded operator not to match, + but would rather a normal operator be called on a type-converted + argument. */ + + if (IS_AGGR_TYPE (type1)) + { + fields1 = lookup_fnfields (TYPE_BINFO (type1), fnname, 0); + /* ARM $13.4.7, prefix/postfix ++/--. */ + if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR) + { + xarg2 = integer_zero_node; + binary_is_unary = 0; + + if (fields1) + { + tree t, t2; + int have_postfix = 0; + + /* Look for an `operator++ (int)'. If they didn't have + one, then we fall back to the old way of doing things. */ + for (t = TREE_VALUE (fields1); t ; t = DECL_CHAIN (t)) + { + t2 = TYPE_ARG_TYPES (TREE_TYPE (t)); + if (TREE_CHAIN (t2) != NULL_TREE + && TREE_VALUE (TREE_CHAIN (t2)) == integer_type_node) + { + have_postfix = 1; + break; + } + } + + if (! have_postfix) + { + char *op = POSTINCREMENT_EXPR ? "++" : "--"; + + /* There's probably a LOT of code in the world that + relies upon this old behavior. */ + if (! flag_traditional) + pedwarn ("no `operator%s (int)' declared for postfix `%s', using prefix operator instead", + op, op); + xarg2 = NULL_TREE; + binary_is_unary = 1; + } + } + } + } + + if (fields1 == NULL_TREE && global_fn == NULL_TREE) + return rval; + + /* If RVAL winds up being `error_mark_node', we will return + that... There is no way that normal semantics of these + operators will succeed. */ + + /* This argument may be an uncommitted OFFSET_REF. This is + the case for example when dealing with static class members + which are referenced from their class name rather than + from a class instance. */ + if (TREE_CODE (xarg1) == OFFSET_REF + && TREE_CODE (TREE_OPERAND (xarg1, 1)) == VAR_DECL) + xarg1 = TREE_OPERAND (xarg1, 1); + if (try_second && xarg2 && TREE_CODE (xarg2) == OFFSET_REF + && TREE_CODE (TREE_OPERAND (xarg2, 1)) == VAR_DECL) + xarg2 = TREE_OPERAND (xarg2, 1); + + if (global_fn) + flags |= LOOKUP_GLOBAL; + + if (code == CALL_EXPR) + { + /* This can only be a member function. */ + return build_method_call (xarg1, fnname, xarg2, + NULL_TREE, LOOKUP_NORMAL); + } + else if (tree_code_length[(int) code] == 1 || binary_is_unary) + { + parms = NULL_TREE; + rval = build_method_call (xarg1, fnname, NULL_TREE, NULL_TREE, flags); + } + else if (code == COND_EXPR) + { + parms = tree_cons (0, xarg2, build_tree_list (NULL_TREE, arg3)); + rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags); + } + else if (code == METHOD_CALL_EXPR) + { + /* must be a member function. */ + parms = tree_cons (NULL_TREE, xarg2, arg3); + return build_method_call (xarg1, fnname, parms, NULL_TREE, + LOOKUP_NORMAL); + } + else if (fields1) + { + parms = build_tree_list (NULL_TREE, xarg2); + rval = build_method_call (xarg1, fnname, parms, NULL_TREE, flags); + } + else + { + parms = tree_cons (NULL_TREE, xarg1, + build_tree_list (NULL_TREE, xarg2)); + rval = build_overload_call (fnname, parms, flags, + (struct candidate *)0); + } + + return rval; +} + +/* This function takes an identifier, ID, and attempts to figure out what + it means. There are a number of possible scenarios, presented in increasing + order of hair: + + 1) not in a class's scope + 2) in class's scope, member name of the class's method + 3) in class's scope, but not a member name of the class + 4) in class's scope, member name of a class's variable + + NAME is $1 from the bison rule. It is an IDENTIFIER_NODE. + VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1) + yychar is the pending input character (suitably encoded :-). + + As a last ditch, try to look up the name as a label and return that + address. + + Values which are declared as being of REFERENCE_TYPE are + automatically dereferenced here (as a hack to make the + compiler faster). */ + +tree +hack_identifier (value, name, yychar) + tree value, name; + int yychar; +{ + tree type; + + if (TREE_CODE (value) == ERROR_MARK) + { + if (current_class_name) + { + tree fields = lookup_fnfields (TYPE_BINFO (current_class_type), name, 1); + if (fields == error_mark_node) + return error_mark_node; + if (fields) + { + tree fndecl; + + fndecl = TREE_VALUE (fields); + my_friendly_assert (TREE_CODE (fndecl) == FUNCTION_DECL, 251); + if (DECL_CHAIN (fndecl) == NULL_TREE) + { + warning ("methods cannot be converted to function pointers"); + return fndecl; + } + else + { + error ("ambiguous request for method pointer `%s'", + IDENTIFIER_POINTER (name)); + return error_mark_node; + } + } + } + if (flag_labels_ok && IDENTIFIER_LABEL_VALUE (name)) + { + return IDENTIFIER_LABEL_VALUE (name); + } + return error_mark_node; + } + + type = TREE_TYPE (value); + if (TREE_CODE (value) == FIELD_DECL) + { + if (current_class_decl == NULL_TREE) + { + error ("request for member `%s' in static member function", + IDENTIFIER_POINTER (DECL_NAME (value))); + return error_mark_node; + } + TREE_USED (current_class_decl) = 1; + + /* Mark so that if we are in a constructor, and then find that + this field was initialized by a base initializer, + we can emit an error message. */ + TREE_USED (value) = 1; + return build_component_ref (C_C_D, name, 0, 1); + } + + if (really_overloaded_fn (value)) + { + tree t = get_first_fn (value); + for (; t; t = DECL_CHAIN (t)) + { + if (TREE_CODE (t) == TEMPLATE_DECL) + continue; + + assemble_external (t); + TREE_USED (t) = 1; + } + } + else if (TREE_CODE (value) == TREE_LIST) + { + tree t = value; + while (t && TREE_CODE (t) == TREE_LIST) + { + assemble_external (TREE_VALUE (t)); + TREE_USED (t) = 1; + t = TREE_CHAIN (t); + } + } + else + { + assemble_external (value); + TREE_USED (value) = 1; + } + + if (TREE_CODE_CLASS (TREE_CODE (value)) == 'd' && DECL_NONLOCAL (value)) + { + if (DECL_LANG_SPECIFIC (value) + && DECL_CLASS_CONTEXT (value) != current_class_type) + { + tree path; + enum access_type access; + register tree context + = (TREE_CODE (value) == FUNCTION_DECL && DECL_VIRTUAL_P (value)) + ? DECL_CLASS_CONTEXT (value) + : DECL_CONTEXT (value); + + get_base_distance (context, current_class_type, 0, &path); + if (path) + { + access = compute_access (path, value); + if (access != access_public) + { + if (TREE_CODE (value) == VAR_DECL) + error ("static member `%s' is %s", + IDENTIFIER_POINTER (name), + TREE_PRIVATE (value) ? "private" : + "from a private base class"); + else + error ("enum `%s' is from private base class", + IDENTIFIER_POINTER (name)); + return error_mark_node; + } + } + } + return value; + } + if (TREE_CODE (value) == TREE_LIST && TREE_NONLOCAL_FLAG (value)) + { + if (type == 0) + { + error ("request for member `%s' is ambiguous in multiple inheritance lattice", + IDENTIFIER_POINTER (name)); + return error_mark_node; + } + + return value; + } + + if (TREE_CODE (type) == REFERENCE_TYPE) + { + my_friendly_assert (TREE_CODE (value) == VAR_DECL + || TREE_CODE (value) == PARM_DECL + || TREE_CODE (value) == RESULT_DECL, 252); + return convert_from_reference (value); + } + return value; +} + + +#if 0 +/* Given an object OF, and a type conversion operator COMPONENT + build a call to the conversion operator, if a call is requested, + or return the address (as a pointer to member function) if one is not. + + OF can be a TYPE_DECL or any kind of datum that would normally + be passed to `build_component_ref'. It may also be NULL_TREE, + in which case `current_class_type' and `current_class_decl' + provide default values. + + BASETYPE_PATH, if non-null, is the path of basetypes + to go through before we get the the instance of interest. + + PROTECT says whether we apply C++ scoping rules or not. */ +tree +build_component_type_expr (of, component, basetype_path, protect) + tree of, component, basetype_path; + int protect; +{ + tree cname = NULL_TREE; + tree tmp, last; + tree name; + int flags = protect ? LOOKUP_NORMAL : LOOKUP_COMPLAIN; + + if (of) + my_friendly_assert (IS_AGGR_TYPE (TREE_TYPE (of)), 253); + my_friendly_assert (TREE_CODE (component) == TYPE_EXPR, 254); + + tmp = TREE_OPERAND (component, 0); + last = NULL_TREE; + + while (tmp) + { + switch (TREE_CODE (tmp)) + { + case CALL_EXPR: + if (last) + TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0); + else + TREE_OPERAND (component, 0) = TREE_OPERAND (tmp, 0); + + last = groktypename (build_tree_list (TREE_TYPE (component), + TREE_OPERAND (component, 0))); + name = build_typename_overload (last); + TREE_TYPE (name) = last; + + if (TREE_OPERAND (tmp, 0) + && TREE_OPERAND (tmp, 0) != void_list_node) + { + cp_error ("`operator %T' requires empty parameter list", last); + TREE_OPERAND (tmp, 0) = NULL_TREE; + } + + if (of && TREE_CODE (of) != TYPE_DECL) + return build_method_call (of, name, NULL_TREE, NULL_TREE, flags); + else if (of) + { + tree this_this; + + if (current_class_decl == NULL_TREE) + { + cp_error ("object required for `operator %T' call", + TREE_TYPE (name)); + return error_mark_node; + } + + this_this = convert_pointer_to (TREE_TYPE (of), + current_class_decl); + this_this = build_indirect_ref (this_this, NULL_PTR); + return build_method_call (this_this, name, NULL_TREE, + NULL_TREE, flags | LOOKUP_NONVIRTUAL); + } + else if (current_class_decl) + return build_method_call (tmp, name, NULL_TREE, NULL_TREE, flags); + + cp_error ("object required for `operator %T' call", + TREE_TYPE (name)); + return error_mark_node; + + case INDIRECT_REF: + case ADDR_EXPR: + case ARRAY_REF: + break; + + case SCOPE_REF: + my_friendly_assert (cname == 0, 255); + cname = TREE_OPERAND (tmp, 0); + tmp = TREE_OPERAND (tmp, 1); + break; + + default: + my_friendly_abort (77); + } + last = tmp; + tmp = TREE_OPERAND (tmp, 0); + } + + last = groktypename (build_tree_list (TREE_TYPE (component), TREE_OPERAND (component, 0))); + name = build_typename_overload (last); + TREE_TYPE (name) = last; + if (of && TREE_CODE (of) == TYPE_DECL) + { + if (cname == NULL_TREE) + { + cname = DECL_NAME (of); + of = NULL_TREE; + } + else my_friendly_assert (cname == DECL_NAME (of), 256); + } + + if (of) + { + tree this_this; + + if (current_class_decl == NULL_TREE) + { + cp_error ("object required for `operator %T' call", + TREE_TYPE (name)); + return error_mark_node; + } + + this_this = convert_pointer_to (TREE_TYPE (of), current_class_decl); + return build_component_ref (this_this, name, 0, protect); + } + else if (cname) + return build_offset_ref (cname, name); + else if (current_class_name) + return build_offset_ref (current_class_name, name); + + cp_error ("object required for `operator %T' member reference", + TREE_TYPE (name)); + return error_mark_node; +} +#endif + +static char * +thunk_printable_name (decl) + tree decl; +{ + return ""; +} + +tree +make_thunk (function, delta) + tree function; + int delta; +{ + char buffer[250]; + tree thunk_fndecl, thunk_id; + tree thunk; + char *func_name; + static int thunk_number = 0; + tree func_decl; + if (TREE_CODE (function) != ADDR_EXPR) + abort (); + func_decl = TREE_OPERAND (function, 0); + if (TREE_CODE (func_decl) != FUNCTION_DECL) + abort (); + func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (func_decl)); + if (delta<=0) + sprintf (buffer, "__thunk_%d_%s", -delta, func_name); + else + sprintf (buffer, "__thunk_n%d_%s", delta, func_name); + thunk_id = get_identifier (buffer); + thunk = IDENTIFIER_GLOBAL_VALUE (thunk_id); + if (thunk && TREE_CODE (thunk) != THUNK_DECL) + { + error_with_decl ("implementation-reserved name `%s' used"); + IDENTIFIER_GLOBAL_VALUE (thunk_id) = thunk = NULL_TREE; + } + if (thunk == NULL_TREE) + { + thunk = build_decl (THUNK_DECL, thunk_id, TREE_TYPE (func_decl)); + DECL_RESULT (thunk) + = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (vtable_entry_type))); + TREE_READONLY (thunk) = TYPE_READONLY (TREE_TYPE (vtable_entry_type)); + TREE_THIS_VOLATILE (thunk) = TYPE_VOLATILE (TREE_TYPE (vtable_entry_type)); + make_function_rtl (thunk); + DECL_INITIAL (thunk) = function; + THUNK_DELTA (thunk) = delta; + /* So that finish_file can write out any thunks that need to be: */ + pushdecl_top_level (thunk); + } + return thunk; +} + +void +emit_thunk (thunk_fndecl) + tree thunk_fndecl; +{ + rtx insns; + char *fnname; + char buffer[250]; + tree argp; + struct args_size stack_args_size; + tree function = TREE_OPERAND (DECL_INITIAL (thunk_fndecl), 0); + int delta = THUNK_DELTA (thunk_fndecl); + int tem; + int failure = 0; + int current_call_is_indirect = 0; /* needed for HPPA FUNCTION_ARG */ + + /* Used to remember which regs we need to emit a USE rtx for. */ + rtx need_use[FIRST_PSEUDO_REGISTER]; + int need_use_count = 0; + + /* rtx for the 'this' parameter. */ + rtx this_rtx = 0, this_reg_rtx = 0, fixed_this_rtx; + + char *(*save_decl_printable_name) () = decl_printable_name; + /* Data on reg parms scanned so far. */ + CUMULATIVE_ARGS args_so_far; + + if (TREE_ASM_WRITTEN (thunk_fndecl)) + return; + + TREE_ASM_WRITTEN (thunk_fndecl) = 1; + + if (TREE_PUBLIC (function)) + { + TREE_PUBLIC (thunk_fndecl) = 1; + if (DECL_EXTERNAL (function)) + { + DECL_EXTERNAL (thunk_fndecl) = 1; + assemble_external (thunk_fndecl); + return; + } + } + + decl_printable_name = thunk_printable_name; + if (current_function_decl) + abort (); + current_function_decl = thunk_fndecl; + init_function_start (thunk_fndecl, input_filename, lineno); + pushlevel (0); + expand_start_bindings (1); + + /* Start updating where the next arg would go. */ + INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (function), NULL_RTX); + stack_args_size.constant = 0; + stack_args_size.var = 0; + /* SETUP for possible structure return address FIXME */ + + /* Now look through all the parameters, make sure that we + don't clobber any registers used for parameters. + Also, pick up an rtx for the first "this" parameter. */ + for (argp = TYPE_ARG_TYPES (TREE_TYPE (function)); + argp != NULL_TREE; + argp = TREE_CHAIN (argp)) + + { + tree passed_type = TREE_VALUE (argp); + register rtx entry_parm; + int named = 1; /* FIXME */ + struct args_size stack_offset; + struct args_size arg_size; + + if (passed_type == void_type_node) + break; + + if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST + && contains_placeholder_p (TYPE_SIZE (passed_type))) +#ifdef FUNCTION_ARG_PASS_BY_REFERENCE + || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, + TYPE_MODE (passed_type), + passed_type, named) +#endif + ) + passed_type = build_pointer_type (passed_type); + + entry_parm = FUNCTION_ARG (args_so_far, + TYPE_MODE (passed_type), + passed_type, + named); + if (entry_parm != 0) + need_use[need_use_count++] = entry_parm; + + locate_and_pad_parm (TYPE_MODE (passed_type), passed_type, +#ifdef STACK_PARMS_IN_REG_PARM_AREA + 1, +#else + entry_parm != 0, +#endif + thunk_fndecl, + &stack_args_size, &stack_offset, &arg_size); + +/* REGNO (entry_parm);*/ + if (this_rtx == 0) + { + this_reg_rtx = entry_parm; + if (!entry_parm) + { + rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); + + rtx internal_arg_pointer, stack_parm; + + if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM + || ! (fixed_regs[ARG_POINTER_REGNUM] + || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))) + internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); + else + internal_arg_pointer = virtual_incoming_args_rtx; + + if (offset_rtx == const0_rtx) + entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type), + internal_arg_pointer); + else + entry_parm = gen_rtx (MEM, TYPE_MODE (passed_type), + gen_rtx (PLUS, Pmode, + internal_arg_pointer, + offset_rtx)); + } + + this_rtx = entry_parm; + } + + FUNCTION_ARG_ADVANCE (args_so_far, + TYPE_MODE (passed_type), + passed_type, + named); + } + + fixed_this_rtx = plus_constant (this_rtx, delta); + if (this_rtx != fixed_this_rtx) + emit_move_insn (this_rtx, fixed_this_rtx); + + if (this_reg_rtx) + emit_insn (gen_rtx (USE, VOIDmode, this_reg_rtx)); + + emit_indirect_jump (XEXP (DECL_RTL (function), 0)); + + while (need_use_count > 0) + emit_insn (gen_rtx (USE, VOIDmode, need_use[--need_use_count])); + + expand_end_bindings (NULL, 1, 0); + poplevel (0, 0, 1); + + /* From now on, allocate rtl in current_obstack, not in saveable_obstack. + Note that that may have been done above, in save_for_inline_copying. + The call to resume_temporary_allocation near the end of this function + goes back to the usual state of affairs. */ + + rtl_in_current_obstack (); + + insns = get_insns (); + + /* Copy any shared structure that should not be shared. */ + + unshare_all_rtl (insns); + + /* Instantiate all virtual registers. */ + + instantiate_virtual_regs (current_function_decl, get_insns ()); + + /* We are no longer anticipating cse in this function, at least. */ + + cse_not_expected = 1; + + /* Now we choose between stupid (pcc-like) register allocation + (if we got the -noreg switch and not -opt) + and smart register allocation. */ + + if (optimize > 0) /* Stupid allocation probably won't work */ + obey_regdecls = 0; /* if optimizations being done. */ + + regclass_init (); + + regclass (insns, max_reg_num ()); + if (obey_regdecls) + { + stupid_life_analysis (insns, max_reg_num (), NULL); + failure = reload (insns, 0, NULL); + } + else + { + /* Do control and data flow analysis, + and write some of the results to dump file. */ + + flow_analysis (insns, max_reg_num (), NULL); + local_alloc (); + failure = global_alloc (NULL); + } + + reload_completed = 1; + +#ifdef LEAF_REGISTERS + leaf_function = 0; + if (optimize > 0 && only_leaf_regs_used () && leaf_function_p ()) + leaf_function = 1; +#endif + + /* If a machine dependent reorganization is needed, call it. */ +#ifdef MACHINE_DEPENDENT_REORG + MACHINE_DEPENDENT_REORG (insns); +#endif + + /* Now turn the rtl into assembler code. */ + + { + char *fnname = XSTR (XEXP (DECL_RTL (thunk_fndecl), 0), 0); + assemble_start_function (thunk_fndecl, fnname); + final (insns, asm_out_file, optimize, 0); + assemble_end_function (thunk_fndecl, fnname); + }; + + exit_rest_of_compilation: + + reload_completed = 0; + + /* Cancel the effect of rtl_in_current_obstack. */ + + resume_temporary_allocation (); + + decl_printable_name = save_decl_printable_name; + current_function_decl = 0; +} + +/* Code for synthesizing methods which have default semantics defined. */ + +/* For the anonymous union in TYPE, return the member that is at least as + large as the rest of the members, so we can copy it. */ +static tree +largest_union_member (type) + tree type; +{ + tree f, type_size = TYPE_SIZE (type); + + for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f)) + if (simple_cst_equal (DECL_SIZE (f), type_size) == 1) + return f; + + /* We should always find one. */ + my_friendly_abort (323); + return NULL_TREE; +} + +/* Generate code for default X(X&) constructor. */ +void +do_build_copy_constructor (fndecl) + tree fndecl; +{ + tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); + tree t; + + clear_last_expr (); + push_momentary (); + + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + parm = TREE_CHAIN (parm); + parm = convert_from_reference (parm); + + if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) + { + t = build (INIT_EXPR, void_type_node, C_C_D, parm); + TREE_SIDE_EFFECTS (t) = 1; + cplus_expand_expr_stmt (t); + } + else + { + tree fields = TYPE_FIELDS (current_class_type); + int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); + tree binfos = TYPE_BINFO_BASETYPES (current_class_type); + int i; + + for (t = CLASSTYPE_VBASECLASSES (current_class_type); t; + t = TREE_CHAIN (t)) + { + tree basetype = BINFO_TYPE (t); + tree p = convert_to_reference + (build_reference_type (basetype), parm, + CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); + p = convert_from_reference (p); + current_base_init_list = tree_cons (TYPE_NESTED_NAME (basetype), + p, current_base_init_list); + } + + for (i = 0; i < n_bases; ++i) + { + tree p, basetype = TREE_VEC_ELT (binfos, i); + if (TREE_VIA_VIRTUAL (basetype)) + continue; + + basetype = BINFO_TYPE (basetype); + p = convert_to_reference + (build_reference_type (basetype), parm, + CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); + p = convert_from_reference (p); + current_base_init_list = tree_cons (TYPE_NESTED_NAME (basetype), + p, current_base_init_list); + } + for (; fields; fields = TREE_CHAIN (fields)) + { + tree name, init, t; + tree field = fields; + + if (TREE_CODE (field) != FIELD_DECL) + continue; + if (DECL_NAME (field)) + { + if (VFIELD_NAME_P (DECL_NAME (field))) + continue; + if (VBASE_NAME_P (DECL_NAME (field))) + continue; + + /* True for duplicate members. */ + if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) + continue; + } + else if ((t = TREE_TYPE (field)) != NULL_TREE + && TREE_CODE (t) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)) + && TYPE_FIELDS (t) != NULL_TREE) + field = largest_union_member (t); + else + continue; + + init = build (COMPONENT_REF, TREE_TYPE (field), parm, field); + init = build_tree_list (NULL_TREE, init); + + current_member_init_list + = tree_cons (DECL_NAME (field), init, current_member_init_list); + } + current_member_init_list = nreverse (current_member_init_list); + current_base_init_list = nreverse (current_base_init_list); + setup_vtbl_ptr (); + } + + pop_momentary (); +} + +void +do_build_assign_ref (fndecl) + tree fndecl; +{ + tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); + + clear_last_expr (); + push_momentary (); + + parm = convert_from_reference (parm); + + if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)) + { + tree t = build (MODIFY_EXPR, void_type_node, C_C_D, parm); + TREE_SIDE_EFFECTS (t) = 1; + cplus_expand_expr_stmt (t); + } + else + { + tree fields = TYPE_FIELDS (current_class_type); + int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); + tree binfos = TYPE_BINFO_BASETYPES (current_class_type); + int i; + + for (i = 0; i < n_bases; ++i) + { + tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); + if (TYPE_HAS_ASSIGN_REF (basetype)) + { + tree p = convert_to_reference + (build_reference_type (basetype), parm, + CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE); + p = convert_from_reference (p); + p = build_member_call (TYPE_NESTED_NAME (basetype), + ansi_opname [MODIFY_EXPR], + build_tree_list (NULL_TREE, p)); + expand_expr_stmt (p); + } + } + for (; fields; fields = TREE_CHAIN (fields)) + { + tree comp, init, t; + tree field = fields; + + if (TREE_CODE (field) != FIELD_DECL) + continue; + if (DECL_NAME (field)) + { + if (VFIELD_NAME_P (DECL_NAME (field))) + continue; + if (VBASE_NAME_P (DECL_NAME (field))) + continue; + + /* True for duplicate members. */ + if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) + continue; + } + else if ((t = TREE_TYPE (field)) != NULL_TREE + && TREE_CODE (t) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)) + && TYPE_FIELDS (t) != NULL_TREE) + field = largest_union_member (t); + else + continue; + + comp = build (COMPONENT_REF, TREE_TYPE (field), C_C_D, field); + init = build (COMPONENT_REF, TREE_TYPE (field), parm, field); + + expand_expr_stmt (build_modify_expr (comp, NOP_EXPR, init)); + } + } + c_expand_return (C_C_D); + pop_momentary (); +} + +void push_cp_function_context (); +void pop_cp_function_context (); + +void +synthesize_method (fndecl) + tree fndecl; +{ + int nested = (current_function_decl != NULL_TREE); + tree context = decl_function_context (fndecl); + char *f = input_filename; + tree base = DECL_CLASS_CONTEXT (fndecl); + + if (nested) + push_cp_function_context (context); + + input_filename = DECL_SOURCE_FILE (fndecl); + interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (base); + interface_only = CLASSTYPE_INTERFACE_ONLY (base); + start_function (NULL_TREE, fndecl, NULL_TREE, NULL_TREE, 1); + store_parm_decls (); + + if (DECL_NAME (fndecl) == ansi_opname[MODIFY_EXPR]) + do_build_assign_ref (fndecl); + else if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) + ; + else + { + tree arg_chain = FUNCTION_ARG_CHAIN (fndecl); + if (DECL_CONSTRUCTOR_FOR_VBASE_P (fndecl)) + arg_chain = TREE_CHAIN (arg_chain); + if (arg_chain != void_list_node) + do_build_copy_constructor (fndecl); + else if (TYPE_NEEDS_CONSTRUCTING (current_class_type)) + setup_vtbl_ptr (); + } + + finish_function (lineno, 0, nested); + + /* Do we really *want* to inline this function? */ + if (DECL_INLINE (fndecl)) + { + /* Turn off DECL_INLINE for the moment so function_cannot_inline_p + will check our size. */ + DECL_INLINE (fndecl) = 0; + if (function_cannot_inline_p (fndecl) == 0) + DECL_INLINE (fndecl) = 1; + } + + input_filename = f; + extract_interface_info (); + if (nested) + pop_cp_function_context (context); +} diff --git a/contrib/gcc/cp/parse.y b/contrib/gcc/cp/parse.y new file mode 100644 index 00000000000..fd034af418d --- /dev/null +++ b/contrib/gcc/cp/parse.y @@ -0,0 +1,3906 @@ +/* YACC parser for C++ syntax. + Copyright (C) 1988, 1989, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This grammar is based on the GNU CC grammar. */ + +/* Note: Bison automatically applies a default action of "$$ = $1" for + all derivations; this is applied before the explicit action, if one + is given. Keep this in mind when reading the actions. */ + +%{ +/* Cause the `yydebug' variable to be defined. */ +#define YYDEBUG 1 + +#include "config.h" + +#include +#include + +#include "tree.h" +#include "input.h" +#include "flags.h" +#include "lex.h" +#include "cp-tree.h" +#include "output.h" + +/* Since parsers are distinct for each language, put the language string + definition here. (fnf) */ +char *language_string = "GNU C++"; + +extern tree void_list_node; +extern struct obstack permanent_obstack; + +#ifndef errno +extern int errno; +#endif + +extern int end_of_file; +extern int current_class_depth; + +/* FSF LOCAL dje prefix attributes */ +extern tree strip_attrs PROTO((tree)); +/* END FSF LOCAL */ + +void yyerror (); + +/* Like YYERROR but do call yyerror. */ +#define YYERROR1 { yyerror ("syntax error"); YYERROR; } + +#define OP0(NODE) (TREE_OPERAND (NODE, 0)) +#define OP1(NODE) (TREE_OPERAND (NODE, 1)) + +/* Contains the statement keyword (if/while/do) to include in an + error message if the user supplies an empty conditional expression. */ +static char *cond_stmt_keyword; + +/* Nonzero if we have an `extern "C"' acting as an extern specifier. */ +int have_extern_spec; +int used_extern_spec; + +void yyhook (); + +/* Cons up an empty parameter list. */ +#ifdef __GNUC__ +__inline +#endif +static tree +empty_parms () +{ + tree parms; + + if (strict_prototype) + parms = void_list_node; + else + parms = NULL_TREE; + return parms; +} +%} + +%start program + +%union {long itype; tree ttype; char *strtype; enum tree_code code; } + +/* All identifiers that are not reserved words + and are not declared typedefs in the current block */ +%token IDENTIFIER + +/* All identifiers that are declared typedefs in the current block. + In some contexts, they are treated just like IDENTIFIER, + but they can also serve as typespecs in declarations. */ +%token TYPENAME + +/* Reserved words that specify storage class. + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token SCSPEC + +/* Reserved words that specify type. + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token TYPESPEC + +/* Reserved words that qualify type: "const" or "volatile". + yylval contains an IDENTIFIER_NODE which indicates which one. */ +%token TYPE_QUAL + +/* Character or numeric constants. + yylval is the node for the constant. */ +%token CONSTANT + +/* String constants in raw form. + yylval is a STRING_CST node. */ +%token STRING + +/* "...", used for functions with variable arglists. */ +%token ELLIPSIS + +/* the reserved words */ +/* SCO include files test "ASM", so use something else. */ +%token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT +%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD GCC_ASM_KEYWORD TYPEOF ALIGNOF +%token SIGOF +%token ATTRIBUTE EXTENSION LABEL + +/* the reserved words... C++ extensions */ +%token AGGR +%token VISSPEC +%token DELETE NEW OVERLOAD THIS OPERATOR CXX_TRUE CXX_FALSE +%token NAMESPACE TYPENAME_KEYWORD USING +%token LEFT_RIGHT TEMPLATE +%token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST +%token SCOPE + +/* Define the operator tokens and their precedences. + The value is an integer because, if used, it is the tree code + to use in the expression made from the operator. */ + +%left EMPTY /* used to resolve s/r with epsilon */ + +%left error + +/* Add precedence rules to solve dangling else s/r conflict */ +%nonassoc IF +%nonassoc ELSE + +%left IDENTIFIER TYPENAME PTYPENAME SCSPEC TYPESPEC TYPE_QUAL ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD + +%left '{' ',' ';' + +%nonassoc THROW +%right ':' +%right ASSIGN '=' +%right '?' +%left OROR +%left ANDAND +%left '|' +%left '^' +%left '&' +%left MIN_MAX +%left EQCOMPARE +%left ARITHCOMPARE '<' '>' +%left LSHIFT RSHIFT +%left '+' '-' +%left '*' '/' '%' +%left POINTSAT_STAR DOT_STAR +%right UNARY PLUSPLUS MINUSMINUS '~' +%left HYPERUNARY +%left PAREN_STAR_PAREN LEFT_RIGHT +%left POINTSAT '.' '(' '[' + +%right SCOPE /* C++ extension */ +%nonassoc NEW DELETE TRY CATCH + +%type unop + +%type identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist +%type paren_expr_or_null nontrivial_exprlist +%type expr_no_commas cast_expr unary_expr primary string STRING +%type typed_declspecs reserved_declspecs boolean.literal +%type typed_typespecs reserved_typespecquals +%type declmods typespec typespecqual_reserved +%type SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual +%type initdecls notype_initdecls initdcl /* C++ modification */ +%type init initlist maybeasm maybe_init +%type asm_operands nonnull_asm_operands asm_operand asm_clobbers +%type maybe_attribute attributes attribute attribute_list attrib +%type any_word + +%type compstmt implicitly_scoped_stmt + +%type declarator notype_declarator after_type_declarator +%type direct_notype_declarator direct_after_type_declarator + +%type structsp opt.component_decl_list component_decl_list +%type component_decl component_decl_1 components notype_components +%type component_declarator component_declarator0 +%type notype_component_declarator notype_component_declarator0 +%type after_type_component_declarator after_type_component_declarator0 +%type enumlist enumerator +%type type_id absdcl type_quals +%type direct_abstract_declarator conversion_declarator +%type new_type_id new_declarator direct_new_declarator +%type xexpr parmlist parms parm bad_parm full_parm +%type identifiers_or_typenames +%type fcast_or_absdcl regcast_or_absdcl +%type expr_or_declarator complex_notype_declarator +%type notype_unqualified_id unqualified_id qualified_id +%type overqualified_id notype_qualified_id any_id +%type complex_direct_notype_declarator functional_cast +%type named_parm complex_parmlist typed_declspecs1 parms_comma + +/* C++ extensions */ +%token TYPENAME_ELLIPSIS PTYPENAME +%token PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL +%token PRE_PARSED_CLASS_DECL +%type fn.def1 /* Not really! */ +%type fn.def2 return_id +%type ctor_initializer_opt +%type named_class_head named_class_head_sans_basetype +%type named_complex_class_head_sans_basetype +%type unnamed_class_head +%type class_head base_class_list +%type base_class_access_list +%type base_class maybe_base_class_list base_class.1 +%type exception_specification_opt ansi_raise_identifier ansi_raise_identifiers +%type operator_name +%type object aggr +%type new delete +/* %type primary_no_id */ +%type nonmomentary_expr maybe_parmlist +%type initdcl0 notype_initdcl0 member_init_list +%type template_header template_parm_list template_parm +%type template_type_parm +%type template_type template_arg_list template_arg +%type template_instantiation template_type_name tmpl.2 +%type template_instantiate_once template_instantiate_some +%type fn_tmpl_end +/* %type try_for_typename */ +%type condition xcond paren_cond_or_null +%type type_name nested_name_specifier nested_type ptr_to_mem +%type qualified_type_name complete_type_name notype_identifier +%type complex_type_name nested_name_specifier_1 +%type nomods_initdecls nomods_initdcl0 +%type new_initializer new_placement specialization type_specifier_seq +%type using_decl .poplevel + +/* in order to recognize aggr tags as defining and thus shadowing. */ +%token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN +%type named_class_head_sans_basetype_defn +%type identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN + +%token NSNAME +%type NSNAME + +/* Used in lex.c for parsing pragmas. */ +%token END_OF_LINE + +/* lex.c and pt.c depends on this being the last token. Define + any new tokens before this one! */ +%token END_OF_SAVED_INPUT + +%{ +/* List of types and structure classes of the current declaration. */ +static tree current_declspecs; +/* List of prefix attributes in effect. + Prefix attributes are parsed by the reserved_declspecs and declmods + rules. They create a list that contains *both* declspecs and attrs. */ +/* ??? It is not clear yet that all cases where an attribute can now appear in + a declspec list have been updated. */ +static tree prefix_attributes; + +/* When defining an aggregate, this is the most recent one being defined. */ +static tree current_aggr; + +/* Tell yyparse how to print a token's value, if yydebug is set. */ + +#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL) +extern void yyprint (); +extern tree combine_strings PROTO((tree)); +%} + +%% +program: /* empty */ + | extdefs + { + /* In case there were missing closebraces, + get us back to the global binding level. */ + while (! global_bindings_p ()) + poplevel (0, 0, 0); + finish_file (); + } + ; + +/* the reason for the strange actions in this rule + is so that notype_initdecls when reached via datadef + can find a valid list of type and sc specs in $0. */ + +extdefs: + { $$ = NULL_TREE; } lang_extdef + { $$ = NULL_TREE; } + | extdefs lang_extdef + { $$ = NULL_TREE; } + ; + +extdefs_opt: + extdefs + | /* empty */ + ; + +.hush_warning: + { have_extern_spec = 1; + used_extern_spec = 0; + $$ = NULL_TREE; } + ; +.warning_ok: + { have_extern_spec = 0; } + ; + +asm_keyword: + ASM_KEYWORD + | GCC_ASM_KEYWORD + ; + +lang_extdef: + { if (pending_lang_change) do_pending_lang_change(); } + extdef + { if (! toplevel_bindings_p () && ! pseudo_global_level_p()) + pop_everything (); } + ; + +extdef: + fndef + { if (pending_inlines) do_pending_inlines (); } + | datadef + { if (pending_inlines) do_pending_inlines (); } + | template_def + { if (pending_inlines) do_pending_inlines (); } + | overloaddef + | asm_keyword '(' string ')' ';' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); + assemble_asm ($3); } + | extern_lang_string '{' extdefs_opt '}' + { pop_lang_context (); } + | extern_lang_string .hush_warning fndef .warning_ok + { if (pending_inlines) do_pending_inlines (); + pop_lang_context (); } + | extern_lang_string .hush_warning datadef .warning_ok + { if (pending_inlines) do_pending_inlines (); + pop_lang_context (); } + | NAMESPACE identifier '{' + { push_namespace ($2); } + extdefs_opt '}' + { pop_namespace (); } + | NAMESPACE '{' + { push_namespace (NULL_TREE); } + extdefs_opt '}' + { pop_namespace (); } + | NAMESPACE identifier '=' any_id ';' + { do_namespace_alias ($2, $4); } + | using_decl ';' + { do_toplevel_using_decl ($1); } + | USING NAMESPACE any_id ';' + { do_using_directive ($3); } + ; + +using_decl: + USING qualified_id + { $$ = $2; } + | USING global_scope qualified_id + { $$ = $3; } + | USING global_scope unqualified_id + { $$ = $3; } + ; + +any_id: + unqualified_id + | qualified_id + | global_scope qualified_id + { $$ = $2; } + | global_scope unqualified_id + { $$ = $2; } + ; + +extern_lang_string: + EXTERN_LANG_STRING + { push_lang_context ($1); } + | extern_lang_string EXTERN_LANG_STRING + { if (current_lang_name != $2) + cp_error ("use of linkage spec `%D' is different from previous spec `%D'", $2, current_lang_name); + pop_lang_context (); push_lang_context ($2); } + ; + +template_header: + TEMPLATE '<' + { begin_template_parm_list (); } + template_parm_list '>' + { $$ = end_template_parm_list ($4); } + ; + +template_parm_list: + template_parm + { $$ = process_template_parm (NULL_TREE, $1); } + | template_parm_list ',' template_parm + { $$ = process_template_parm ($1, $3); } + ; + +template_type_parm: + aggr + { + $$ = build_tree_list ($1, NULL_TREE); + ttpa: + if (TREE_PURPOSE ($$) == signature_type_node) + sorry ("signature as template type parameter"); + else if (TREE_PURPOSE ($$) != class_type_node) + pedwarn ("template type parameters must use the keyword `class'"); + } + | aggr identifier + { $$ = build_tree_list ($1, $2); goto ttpa; } + | TYPENAME_KEYWORD + { $$ = build_tree_list (class_type_node, NULL_TREE); } + | TYPENAME_KEYWORD identifier + { $$ = build_tree_list (class_type_node, $2); } + ; + +template_parm: + /* The following rules introduce a new reduce/reduce + conflict on the ',' and '>' input tokens: they are valid + prefixes for a `structsp', which means they could match a + nameless parameter. See 14.6, paragraph 3. + By putting them before the `parm' rule, we get + their match before considering them nameless parameter + declarations. */ + template_type_parm + { $$ = build_tree_list (NULL_TREE, $$); } + | template_type_parm '=' typespec + { $$ = build_tree_list ($3, $$); } + | full_parm + ; + +overloaddef: + OVERLOAD ov_identifiers ';' + { warning ("use of `overload' is an anachronism"); } + ; + +ov_identifiers: IDENTIFIER + { declare_overloaded ($1); } + | ov_identifiers ',' IDENTIFIER + { declare_overloaded ($3); } + ; + +template_def: + /* Class template declarations go here; they aren't normal class + declarations, because we can't process the bodies yet. */ + template_header named_class_head_sans_basetype '{' + { yychar = '{'; goto template1; } + ';' + | template_header named_class_head_sans_basetype_defn '{' + { yychar = '{'; goto template1; } + ';' + | template_header named_class_head_sans_basetype ':' + { yychar = ':'; goto template1; } + ';' + | template_header named_class_head_sans_basetype_defn ':' + { + yychar = ':'; + template1: + if (current_aggr == signature_type_node) + sorry ("template type defining a signature"); + /* Maybe pedantic warning for union? + How about an enum? :-) */ + end_template_decl ($1, $2, current_aggr, 1); + reinit_parse_for_template (yychar, $1, $2); + yychar = YYEMPTY; + } + ';' + | template_header named_class_head_sans_basetype ';' + { + end_template_decl ($1, $2, current_aggr, 0); + /* declare $2 as template name with $1 parm list */ + } + | template_header named_class_head_sans_basetype_defn ';' + { + end_template_decl ($1, $2, current_aggr, 0); + /* declare $2 as template name with $1 parm list */ + } + | template_header /* notype_initdcl0 ';' */ + notype_declarator exception_specification_opt maybeasm maybe_attribute + fn_tmpl_end + { + tree d; + int momentary; + int def = ($6 != ';'); + momentary = suspend_momentary (); + d = start_decl ($2, /*current_declspecs*/NULL_TREE, 0, + $3); + cplus_decl_attributes (d, $5, /*prefix_attributes*/NULL_TREE); + cp_finish_decl (d, NULL_TREE, $4, 0, 0); + end_template_decl ($1, d, 0, def); + if (def) + reinit_parse_for_template ((int) $6, $1, d); + resume_momentary (momentary); + } + | template_header typed_declspecs /*initdcl0*/ + declarator exception_specification_opt maybeasm maybe_attribute + fn_tmpl_end + { + tree d, specs, attrs; + int momentary; + int def = ($7 != ';'); + split_specs_attrs ($2, &specs, &attrs); + momentary = suspend_momentary (); + d = start_decl ($3, specs, 0, $4); + cplus_decl_attributes (d, $6, attrs); + cp_finish_decl (d, NULL_TREE, $5, 0, 0); + end_template_decl ($1, d, 0, def); + if (def) + { + reinit_parse_for_template ((int) $7, $1, d); + yychar = YYEMPTY; + } + note_list_got_semicolon ($2); + resume_momentary (momentary); + } + | template_header declmods notype_declarator fn_tmpl_end + { + tree d, specs, attrs; + int def = ($4 != ';'); + split_specs_attrs ($2, &specs, &attrs); + d = start_decl ($3, specs, 0, NULL_TREE); + cplus_decl_attributes (d, NULL_TREE, attrs); + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + end_template_decl ($1, d, 0, def); + if (def) + reinit_parse_for_template ((int) $4, $1, d); + } + /* Try to recover from syntax errors in templates. */ + | template_header error '}' { end_template_decl ($1, 0, 0, 0); } + | template_header error ';' { end_template_decl ($1, 0, 0, 0); } + ; + +fn_tmpl_end: '{' { $$ = '{'; } + | ':' { $$ = ':'; } + | ';' { $$ = ';'; } + | '=' { $$ = '='; } + | RETURN { $$ = RETURN; } + ; + +datadef: + nomods_initdecls ';' + {} + | declmods notype_initdecls ';' + {} + /* Normal case to make fast: "const i;". */ + | declmods notype_declarator ';' + { tree d, specs, attrs; + split_specs_attrs ($1, &specs, &attrs); + d = start_decl ($2, specs, 0, NULL_TREE); + cplus_decl_attributes (d, NULL_TREE, attrs); + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + } + | typed_declspecs initdecls ';' + { + note_list_got_semicolon ($$); + } + /* Normal case: make this fast. */ + | typed_declspecs declarator ';' + { tree d, specs, attrs; + split_specs_attrs ($1, &specs, &attrs); + d = start_decl ($2, specs, 0, NULL_TREE); + cplus_decl_attributes (d, NULL_TREE, attrs); + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + note_list_got_semicolon ($$); + } + | declmods ';' + { pedwarn ("empty declaration"); } + | explicit_instantiation ';' + | typed_declspecs ';' + { + tree t, attrs; + split_specs_attrs ($1, &t, &attrs); + shadow_tag (t); + if (TREE_CODE (t) == TREE_LIST + && TREE_PURPOSE (t) == NULL_TREE) + { + t = TREE_VALUE (t); + if (IS_AGGR_TYPE (t) + && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (t))) + { + if (CLASSTYPE_USE_TEMPLATE (t) == 0) + SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (t); + else if (CLASSTYPE_TEMPLATE_INSTANTIATION (t)) + error ("override declaration for already-expanded template"); + } + } + note_list_got_semicolon ($$); + } + | error ';' + | error '}' + | ';' + ; + +ctor_initializer_opt: + nodecls + { $$ = 0; } + | base_init + { $$ = 1; } + ; + +maybe_return_init: + /* empty */ + | return_init + | return_init ';' + ; + +eat_saved_input: + /* empty */ + | END_OF_SAVED_INPUT + ; + +fndef: + fn.def1 maybe_return_init ctor_initializer_opt compstmt_or_error + { + finish_function (lineno, (int)$3, 0); + if ($$) process_next_inline ($$); + } + | fn.def1 maybe_return_init function_try_block + { + if ($$) process_next_inline ($$); + } + eat_saved_input + | typed_declspecs declarator error + {} + | declmods notype_declarator error + {} + | notype_declarator error + {} + ; + +fn.def1: + typed_declspecs declarator exception_specification_opt + { tree specs, attrs; + split_specs_attrs ($1, &specs, &attrs); + if (! start_function (specs, $2, $3, attrs, 0)) + YYERROR1; + reinit_parse_for_function (); + $$ = NULL_TREE; } + | declmods notype_declarator exception_specification_opt + { tree specs = strip_attrs ($1); + if (! start_function (specs, $2, $3, NULL_TREE, 0)) + YYERROR1; + reinit_parse_for_function (); + $$ = NULL_TREE; } + | notype_declarator exception_specification_opt + { if (! start_function (NULL_TREE, $$, $2, NULL_TREE, 0)) + YYERROR1; + reinit_parse_for_function (); + $$ = NULL_TREE; } + | PRE_PARSED_FUNCTION_DECL + { start_function (NULL_TREE, TREE_VALUE ($$), + NULL_TREE, NULL_TREE, 1); + reinit_parse_for_function (); } + ; + +/* more C++ complexity. See component_decl for a comment on the + reduce/reduce conflict introduced by these rules. */ +fn.def2: + typed_declspecs '(' parmlist ')' type_quals exception_specification_opt + { tree specs = strip_attrs ($1); + $$ = build_parse_node (CALL_EXPR, TREE_VALUE (specs), $3, $5); + $$ = start_method (TREE_CHAIN (specs), $$, $6); + rest_of_mdef: + if (! $$) + YYERROR1; + if (yychar == YYEMPTY) + yychar = YYLEX; + reinit_parse_for_method (yychar, $$); } + | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt + { tree specs = strip_attrs ($1); + $$ = build_parse_node (CALL_EXPR, TREE_VALUE (specs), + empty_parms (), $3); + $$ = start_method (TREE_CHAIN (specs), $$, $4); + goto rest_of_mdef; + } + | typed_declspecs declarator exception_specification_opt + { tree specs = strip_attrs ($1); + $$ = start_method (specs, $2, $3); goto rest_of_mdef; } + | declmods notype_declarator exception_specification_opt + { tree specs = strip_attrs ($1); + $$ = start_method (specs, $2, $3); goto rest_of_mdef; } + | notype_declarator exception_specification_opt + { $$ = start_method (NULL_TREE, $$, $2); goto rest_of_mdef; } + ; + +return_id: RETURN IDENTIFIER + { + if (! current_function_parms_stored) + store_parm_decls (); + $$ = $2; + } + ; + +return_init: return_id maybe_init + { store_return_init ($$, $2); } + | return_id '(' nonnull_exprlist ')' + { store_return_init ($$, $3); } + | return_id LEFT_RIGHT + { store_return_init ($$, NULL_TREE); } + ; + +base_init: + ':' .set_base_init member_init_list + { + if ($3 == 0) + error ("no base initializers given following ':'"); + setup_vtbl_ptr (); + /* Always keep the BLOCK node associated with the outermost + pair of curley braces of a function. These are needed + for correct operation of dwarfout.c. */ + keep_next_level (); + } + ; + +.set_base_init: + /* empty */ + { + if (! current_function_parms_stored) + store_parm_decls (); + + if (DECL_CONSTRUCTOR_P (current_function_decl)) + { + /* Make a contour for the initializer list. */ + pushlevel (0); + clear_last_expr (); + expand_start_bindings (0); + } + else if (current_class_type == NULL_TREE) + error ("base initializers not allowed for non-member functions"); + else if (! DECL_CONSTRUCTOR_P (current_function_decl)) + error ("only constructors take base initializers"); + } + ; + +member_init_list: + /* empty */ + { $$ = 0; } + | member_init + { $$ = 1; } + | member_init_list ',' member_init + | member_init_list error + ; + +member_init: '(' nonnull_exprlist ')' + { + if (current_class_name && !flag_traditional) + pedwarn ("anachronistic old style base class initializer"); + expand_member_init (C_C_D, NULL_TREE, $2); + } + | LEFT_RIGHT + { + if (current_class_name && !flag_traditional) + pedwarn ("anachronistic old style base class initializer"); + expand_member_init (C_C_D, NULL_TREE, void_type_node); + } + | notype_identifier '(' nonnull_exprlist ')' + { expand_member_init (C_C_D, $$, $3); } + | notype_identifier LEFT_RIGHT + { expand_member_init (C_C_D, $$, void_type_node); } + | complete_type_name '(' nonnull_exprlist ')' + { expand_member_init (C_C_D, $$, $3); } + | complete_type_name LEFT_RIGHT + { expand_member_init (C_C_D, $$, void_type_node); } + /* GNU extension */ + | notype_qualified_id '(' nonnull_exprlist ')' + { + do_member_init (OP0 ($1), OP1 ($1), $3); + } + | notype_qualified_id LEFT_RIGHT + { + do_member_init (OP0 ($1), OP1 ($1), void_type_node); + } + ; + +identifier: + IDENTIFIER + | TYPENAME + | PTYPENAME + | NSNAME + ; + +notype_identifier: + IDENTIFIER + | PTYPENAME + | NSNAME %prec EMPTY + ; + +identifier_defn: + IDENTIFIER_DEFN + | TYPENAME_DEFN + | PTYPENAME_DEFN + ; + +explicit_instantiation: + TEMPLATE specialization template_instantiation + { do_type_instantiation ($3 ? $3 : $2, NULL_TREE); } + | TEMPLATE typed_declspecs declarator + { tree specs = strip_attrs ($2); + do_function_instantiation (specs, $3, NULL_TREE); } + | TEMPLATE notype_declarator + { do_function_instantiation (NULL_TREE, $2, NULL_TREE); } + | SCSPEC TEMPLATE specialization template_instantiation + { do_type_instantiation ($4 ? $4 : $3, $1); } + | SCSPEC TEMPLATE typed_declspecs declarator + { tree specs = strip_attrs ($3); + do_function_instantiation (specs, $4, $1); } + | SCSPEC TEMPLATE notype_declarator + { do_function_instantiation (NULL_TREE, $3, $1); } + ; + +template_type: + template_type_name tmpl.2 template_instantiation + { if ($3) $$ = $3; } + ; + +template_type_name: + PTYPENAME '<' template_arg_list '>' + { $$ = lookup_template_class ($$, $3, NULL_TREE); } + | PTYPENAME '<' '>' + { $$ = lookup_template_class ($$, NULL_TREE, NULL_TREE); } + | TYPENAME '<' template_arg_list '>' + { $$ = lookup_template_class ($$, $3, NULL_TREE); } + ; + +tmpl.2: + /* empty */ %prec EMPTY + { $$ = instantiate_class_template ($0, 1); } + ; + +template_arg_list: + template_arg + { $$ = build_tree_list (NULL_TREE, $$); } + | template_arg_list ',' template_arg + { $$ = chainon ($$, build_tree_list (NULL_TREE, $3)); } + ; + +template_arg: + type_id + { $$ = groktypename ($$); } + | expr_no_commas %prec UNARY + ; + +template_instantiate_once: + PRE_PARSED_CLASS_DECL maybe_base_class_list + { + tree t, decl, tmpl; + + tmpl = TREE_PURPOSE (IDENTIFIER_TEMPLATE ($1)); + t = xref_tag (DECL_TEMPLATE_INFO (tmpl)->aggr, $1, $2, 0); + set_current_level_tags_transparency (1); + my_friendly_assert (TREE_CODE (t) == RECORD_TYPE + || TREE_CODE (t) == UNION_TYPE, 257); + $$ = t; + + /* Now, put a copy of the decl in global scope, to avoid + recursive expansion. */ + decl = IDENTIFIER_LOCAL_VALUE ($1); + if (!decl) + decl = IDENTIFIER_CLASS_VALUE ($1); + /* Now, put a copy of the decl in global scope, to avoid + recursive expansion. */ + if (decl) + { + /* Need to copy it to clear the chain pointer, + and need to get it into permanent storage. */ + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 258); + push_obstacks (&permanent_obstack, &permanent_obstack); + decl = copy_node (decl); + if (DECL_LANG_SPECIFIC (decl)) + copy_lang_decl (decl); + pop_obstacks (); + pushdecl_top_level (decl); + } + /* Kludge; see instantiate_class_template. */ + TYPE_BEING_DEFINED (t) = 0; + } + left_curly opt.component_decl_list '}' + { + tree t = finish_struct ($3, $5, 0); + + pop_obstacks (); + end_template_instantiation ($1); + + repo_template_used (t); + + /* Now go after the methods & class data. */ + instantiate_member_templates ($1); + + pop_tinst_level(); + + CLASSTYPE_GOT_SEMICOLON (t) = 1; + } + ; + +template_instantiation: + /* empty */ + { $$ = NULL_TREE; } + | template_instantiate_once + { $$ = $1; } + ; + +template_instantiate_some: + /* empty */ + { $$ = NULL_TREE; /* never used from here... */} + | template_instantiate_once template_instantiate_some + { $$ = $1; /*???*/ } + ; + +unop: '-' + { $$ = NEGATE_EXPR; } + | '+' + { $$ = CONVERT_EXPR; } + | PLUSPLUS + { $$ = PREINCREMENT_EXPR; } + | MINUSMINUS + { $$ = PREDECREMENT_EXPR; } + | '!' + { $$ = TRUTH_NOT_EXPR; } + ; + +expr: nontrivial_exprlist + { $$ = build_x_compound_expr ($$); } + | expr_no_commas + ; + +paren_expr_or_null: + LEFT_RIGHT + { error ("ANSI C++ forbids an empty condition for `%s'", + cond_stmt_keyword); + $$ = integer_zero_node; } + | '(' expr ')' + { $$ = condition_conversion ($2); } + ; + +paren_cond_or_null: + LEFT_RIGHT + { error ("ANSI C++ forbids an empty condition for `%s'", + cond_stmt_keyword); + $$ = integer_zero_node; } + | '(' condition ')' + { $$ = condition_conversion ($2); } + ; + +xcond: + /* empty */ + { $$ = NULL_TREE; } + | condition + { $$ = condition_conversion ($$); } + | error + { $$ = NULL_TREE; } + ; + +condition: + type_specifier_seq declarator exception_specification_opt maybeasm maybe_attribute '=' + { { + tree d; + for (d = getdecls (); d; d = TREE_CHAIN (d)) + if (TREE_CODE (d) == TYPE_DECL) { + tree s = TREE_TYPE (d); + if (TREE_CODE (s) == RECORD_TYPE) + cp_error ("definition of class `%T' in condition", s); + else if (TREE_CODE (s) == ENUMERAL_TYPE) + cp_error ("definition of enum `%T' in condition", s); + } + } + current_declspecs = $1; + $6 = suspend_momentary (); + $$ = start_decl ($2, current_declspecs, 1, $3); + cplus_decl_attributes ($$, $5, + /*prefix_attributes*/ NULL_TREE); + } + init + { + cp_finish_decl ($7, $8, $5, 0, LOOKUP_ONLYCONVERTING); + resume_momentary ($6); + $$ = $7; + if (TREE_CODE (TREE_TYPE ($$)) == ARRAY_TYPE) + cp_error ("definition of array `%#D' in condition", $$); + } + | expr + ; + +compstmtend: + '}' + | maybe_label_decls stmts '}' + | maybe_label_decls stmts error '}' + | maybe_label_decls error '}' + ; + +already_scoped_stmt: + '{' compstmtend + { finish_stmt (); } + | simple_stmt + ; + + +nontrivial_exprlist: + expr_no_commas ',' expr_no_commas + { $$ = tree_cons (NULL_TREE, $$, + build_tree_list (NULL_TREE, $3)); } + | expr_no_commas ',' error + { $$ = tree_cons (NULL_TREE, $$, + build_tree_list (NULL_TREE, error_mark_node)); } + | nontrivial_exprlist ',' expr_no_commas + { chainon ($$, build_tree_list (NULL_TREE, $3)); } + | nontrivial_exprlist ',' error + { chainon ($$, build_tree_list (NULL_TREE, error_mark_node)); } + ; + +nonnull_exprlist: + expr_no_commas + { $$ = build_tree_list (NULL_TREE, $$); } + | nontrivial_exprlist + ; + +unary_expr: + primary %prec UNARY + { +#if 0 + if (TREE_CODE ($$) == TYPE_EXPR) + $$ = build_component_type_expr (C_C_D, $$, NULL_TREE, 1); +#endif + } + /* __extension__ turns off -pedantic for following primary. */ + | EXTENSION + { $1 = pedantic; + pedantic = 0; } + cast_expr %prec UNARY + { $$ = $3; + pedantic = $1; } + | '*' cast_expr %prec UNARY + { $$ = build_x_indirect_ref ($2, "unary *"); } + | '&' cast_expr %prec UNARY + { $$ = build_x_unary_op (ADDR_EXPR, $2); } + | '~' cast_expr + { $$ = build_x_unary_op (BIT_NOT_EXPR, $2); } + | unop cast_expr %prec UNARY + { $$ = build_x_unary_op ($1, $2); + if ($1 == NEGATE_EXPR && TREE_CODE ($2) == INTEGER_CST) + TREE_NEGATED_INT ($$) = 1; + overflow_warning ($$); + } + /* Refer to the address of a label as a pointer. */ + | ANDAND identifier + { tree label = lookup_label ($2); + if (label == NULL_TREE) + $$ = null_pointer_node; + else + { + TREE_USED (label) = 1; + $$ = build1 (ADDR_EXPR, ptr_type_node, label); + TREE_CONSTANT ($$) = 1; + } + } + | SIZEOF unary_expr %prec UNARY + { if (TREE_CODE ($2) == COMPONENT_REF + && DECL_BIT_FIELD (TREE_OPERAND ($2, 1))) + error ("sizeof applied to a bit-field"); + /* ANSI says arrays and functions are converted inside comma. + But we can't really convert them in build_compound_expr + because that would break commas in lvalues. + So do the conversion here if operand was a comma. */ + if (TREE_CODE ($2) == COMPOUND_EXPR + && (TREE_CODE (TREE_TYPE ($2)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE ($2)) == FUNCTION_TYPE)) + $2 = default_conversion ($2); + else if (TREE_CODE ($2) == TREE_LIST) + { + tree t = TREE_VALUE ($2); + if (t != NULL_TREE + && ((TREE_TYPE (t) + && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE) + || is_overloaded_fn (t))) + pedwarn ("ANSI C++ forbids taking the sizeof a function type"); + } + $$ = c_sizeof (TREE_TYPE ($2)); } + | SIZEOF '(' type_id ')' %prec HYPERUNARY + { $$ = c_sizeof (groktypename ($3)); } + | ALIGNOF unary_expr %prec UNARY + { $$ = grok_alignof ($2); } + | ALIGNOF '(' type_id ')' %prec HYPERUNARY + { $$ = c_alignof (groktypename ($3)); } + + /* The %prec EMPTY's here are required by the = init initializer + syntax extension; see below. */ + | new new_type_id %prec EMPTY + { $$ = build_new (NULL_TREE, $2, NULL_TREE, $1); } + | new new_type_id new_initializer + { $$ = build_new (NULL_TREE, $2, $3, $1); } + | new new_placement new_type_id %prec EMPTY + { $$ = build_new ($2, $3, NULL_TREE, $1); } + | new new_placement new_type_id new_initializer + { $$ = build_new ($2, $3, $4, $1); } + | new '(' type_id ')' %prec EMPTY + { $$ = build_new (NULL_TREE, groktypename($3), + NULL_TREE, $1); } + | new '(' type_id ')' new_initializer + { $$ = build_new (NULL_TREE, groktypename($3), $5, $1); } + | new new_placement '(' type_id ')' %prec EMPTY + { $$ = build_new ($2, groktypename($4), NULL_TREE, $1); } + | new new_placement '(' type_id ')' new_initializer + { $$ = build_new ($2, groktypename($4), $6, $1); } + + | delete cast_expr %prec UNARY + { $$ = delete_sanity ($2, NULL_TREE, 0, $1); } + | delete '[' ']' cast_expr %prec UNARY + { $$ = delete_sanity ($4, NULL_TREE, 1, $1); + if (yychar == YYEMPTY) + yychar = YYLEX; } + | delete '[' expr ']' cast_expr %prec UNARY + { $$ = delete_sanity ($5, $3, 2, $1); + if (yychar == YYEMPTY) + yychar = YYLEX; } + ; + +new_placement: + '(' nonnull_exprlist ')' + { $$ = $2; } + | '{' nonnull_exprlist '}' + { + $$ = $2; + pedwarn ("old style placement syntax, use () instead"); + } + ; + +new_initializer: + '(' nonnull_exprlist ')' + { $$ = $2; } + | LEFT_RIGHT + { $$ = NULL_TREE; } + | '(' typespec ')' + { + cp_error ("`%T' is not a valid expression", $2); + $$ = error_mark_node; + } + /* GNU extension so people can use initializer lists. Note that + this alters the meaning of `new int = 1', which was previously + syntactically valid but semantically invalid. */ + | '=' init + { + if (pedantic) + pedwarn ("ANSI C++ forbids initialization of new expression with `='"); + $$ = $2; + } + ; + +/* This is necessary to postpone reduction of `int ((int)(int)(int))'. */ +regcast_or_absdcl: + '(' type_id ')' %prec EMPTY + { $2 = tree_cons (NULL_TREE, $2, void_list_node); + TREE_PARMLIST ($2) = 1; + $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, + NULL_TREE); } + | regcast_or_absdcl '(' type_id ')' %prec EMPTY + { $3 = tree_cons (NULL_TREE, $3, void_list_node); + TREE_PARMLIST ($3) = 1; + $$ = build_parse_node (CALL_EXPR, $$, $3, NULL_TREE); } + ; + +cast_expr: + unary_expr + | regcast_or_absdcl unary_expr %prec UNARY + { $$ = reparse_absdcl_as_casts ($$, $2); } + | regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY + { + tree init = build_nt (CONSTRUCTOR, NULL_TREE, + nreverse ($3)); + if (pedantic) + pedwarn ("ANSI C++ forbids constructor-expressions"); + /* Indicate that this was a GNU C constructor expression. */ + TREE_HAS_CONSTRUCTOR (init) = 1; + + $$ = reparse_absdcl_as_casts ($$, init); + } + ; + +expr_no_commas: + cast_expr + /* Handle general members. */ + | expr_no_commas POINTSAT_STAR expr_no_commas + { $$ = build_x_binary_op (MEMBER_REF, $$, $3); } + | expr_no_commas DOT_STAR expr_no_commas + { $$ = build_m_component_ref ($$, $3); } + | expr_no_commas '+' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '-' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '*' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '/' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '%' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas LSHIFT expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas RSHIFT expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas ARITHCOMPARE expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '<' expr_no_commas + { $$ = build_x_binary_op (LT_EXPR, $$, $3); } + | expr_no_commas '>' expr_no_commas + { $$ = build_x_binary_op (GT_EXPR, $$, $3); } + | expr_no_commas EQCOMPARE expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas MIN_MAX expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '&' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '|' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas '^' expr_no_commas + { $$ = build_x_binary_op ($2, $$, $3); } + | expr_no_commas ANDAND expr_no_commas + { $$ = build_x_binary_op (TRUTH_ANDIF_EXPR, $$, $3); } + | expr_no_commas OROR expr_no_commas + { $$ = build_x_binary_op (TRUTH_ORIF_EXPR, $$, $3); } + | expr_no_commas '?' xexpr ':' expr_no_commas + { $$ = build_x_conditional_expr ($$, $3, $5); } + | expr_no_commas '=' expr_no_commas + { $$ = build_modify_expr ($$, NOP_EXPR, $3); + C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR); } + | expr_no_commas ASSIGN expr_no_commas + { register tree rval; + if ((rval = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, $$, $3, + make_node ($2)))) + $$ = rval; + else + $$ = build_modify_expr ($$, $2, $3); } + | THROW + { $$ = build_throw (NULL_TREE); } + | THROW expr_no_commas + { $$ = build_throw ($2); } +/* These extensions are not defined. The second arg to build_m_component_ref + is old, build_m_component_ref now does an implicit + build_indirect_ref (x, NULL_PTR) on the second argument. + | object '&' expr_no_commas %prec UNARY + { $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); } + | object unop expr_no_commas %prec UNARY + { $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); } + | object '(' type_id ')' expr_no_commas %prec UNARY + { tree type = groktypename ($3); + $$ = build_m_component_ref ($$, build_c_cast (type, $5, 0)); } + | object primary_no_id %prec UNARY + { $$ = build_m_component_ref ($$, $2); } +*/ + ; + +notype_unqualified_id: + '~' see_typename identifier + { $$ = build_parse_node (BIT_NOT_EXPR, $3); } + | operator_name + | IDENTIFIER + | PTYPENAME + | NSNAME %prec EMPTY + ; + +unqualified_id: + notype_unqualified_id + | TYPENAME + ; + +expr_or_declarator: + notype_unqualified_id + | '*' expr_or_declarator %prec UNARY + { $$ = build_parse_node (INDIRECT_REF, $2); } + | '&' expr_or_declarator %prec UNARY + { $$ = build_parse_node (ADDR_EXPR, $2); } + | '(' expr_or_declarator ')' + { $$ = $2; } + ; + +direct_notype_declarator: + complex_direct_notype_declarator + | notype_unqualified_id + | '(' expr_or_declarator ')' + { $$ = finish_decl_parsing ($2); } + ; + +primary: + notype_unqualified_id + { + if (TREE_CODE ($$) == BIT_NOT_EXPR) + $$ = build_x_unary_op (BIT_NOT_EXPR, TREE_OPERAND ($$, 0)); + else if (IDENTIFIER_OPNAME_P ($$)) + { + tree op = $$; + $$ = lookup_name (op, 0); + if ($$ == NULL_TREE) + { + if (op != ansi_opname[ERROR_MARK]) + error ("operator %s not defined", + operator_name_string (op)); + $$ = error_mark_node; + } + } + else + $$ = do_identifier ($$); + } + | CONSTANT + | boolean.literal + | string + { $$ = combine_strings ($$); } + | '(' expr ')' + { char class; + $$ = $2; + class = TREE_CODE_CLASS (TREE_CODE ($$)); + if (class == 'e' || class == '1' + || class == '2' || class == '<') + /* This inhibits warnings in truthvalue_conversion. */ + C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); } + | '(' expr_or_declarator ')' + { char class; + $$ = reparse_decl_as_expr (NULL_TREE, $2); + class = TREE_CODE_CLASS (TREE_CODE ($$)); + if (class == 'e' || class == '1' + || class == '2' || class == '<') + /* This inhibits warnings in truthvalue_conversion. */ + C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK); } + | '(' error ')' + { $$ = error_mark_node; } + | '(' + { if (current_function_decl == 0) + { + error ("braced-group within expression allowed only inside a function"); + YYERROR; + } + keep_next_level (); + $$ = expand_start_stmt_expr (); } + compstmt ')' + { tree rtl_exp; + if (pedantic) + pedwarn ("ANSI C++ forbids braced-groups within expressions"); + rtl_exp = expand_end_stmt_expr ($2); + /* The statements have side effects, so the group does. */ + TREE_SIDE_EFFECTS (rtl_exp) = 1; + + if (TREE_CODE ($3) == BLOCK) + { + /* Make a BIND_EXPR for the BLOCK already made. */ + $$ = build (BIND_EXPR, TREE_TYPE (rtl_exp), + NULL_TREE, rtl_exp, $3); + /* Remove the block from the tree at this point. + It gets put back at the proper place + when the BIND_EXPR is expanded. */ + delete_block ($3); + } + else + $$ = $3; + } + | primary '(' nonnull_exprlist ')' + { /* [eichin:19911016.1902EST] */ + $$ = build_x_function_call ($1, $3, current_class_decl); + /* here we instantiate_class_template as needed... */ + do_pending_templates (); + } template_instantiate_some { + if (TREE_CODE ($5) == CALL_EXPR + && TREE_TYPE ($5) != void_type_node) + $$ = require_complete_type ($5); + else + $$ = $5; + } + | primary LEFT_RIGHT + { + $$ = build_x_function_call ($$, NULL_TREE, current_class_decl); + if (TREE_CODE ($$) == CALL_EXPR + && TREE_TYPE ($$) != void_type_node) + $$ = require_complete_type ($$); + } + | primary '[' expr ']' + { $$ = grok_array_decl ($$, $3); } + | primary PLUSPLUS + { /* If we get an OFFSET_REF, turn it into what it really + means (e.g., a COMPONENT_REF). This way if we've got, + say, a reference to a static member that's being operated + on, we don't end up trying to find a member operator for + the class it's in. */ + if (TREE_CODE ($$) == OFFSET_REF) + $$ = resolve_offset_ref ($$); + $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); } + | primary MINUSMINUS + { if (TREE_CODE ($$) == OFFSET_REF) + $$ = resolve_offset_ref ($$); + $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); } + /* C++ extensions */ + | THIS + { if (current_class_decl) + { +#ifdef WARNING_ABOUT_CCD + TREE_USED (current_class_decl) = 1; +#endif + $$ = current_class_decl; + } + else if (current_function_decl + && DECL_STATIC_FUNCTION_P (current_function_decl)) + { + error ("`this' is unavailable for static member functions"); + $$ = error_mark_node; + } + else + { + if (current_function_decl) + error ("invalid use of `this' in non-member function"); + else + error ("invalid use of `this' at top level"); + $$ = error_mark_node; + } + } + | TYPE_QUAL '(' nonnull_exprlist ')' + { + tree type; + tree id = $$; + + /* This is a C cast in C++'s `functional' notation. */ + if ($3 == error_mark_node) + { + $$ = error_mark_node; + break; + } +#if 0 + if ($3 == NULL_TREE) + { + error ("cannot cast null list to type `%s'", + IDENTIFIER_POINTER (TYPE_NAME (id))); + $$ = error_mark_node; + break; + } +#endif +#if 0 + /* type is not set! (mrs) */ + if (type == error_mark_node) + $$ = error_mark_node; + else +#endif + { + if (id == ridpointers[(int) RID_CONST]) + type = build_type_variant (integer_type_node, 1, 0); + else if (id == ridpointers[(int) RID_VOLATILE]) + type = build_type_variant (integer_type_node, 0, 1); +#if 0 + /* should not be able to get here (mrs) */ + else if (id == ridpointers[(int) RID_FRIEND]) + { + error ("cannot cast expression to `friend' type"); + $$ = error_mark_node; + break; + } +#endif + else my_friendly_abort (79); + $$ = build_c_cast (type, build_compound_expr ($3), 1); + } + } + | functional_cast + | DYNAMIC_CAST '<' + { dont_allow_type_definitions = "inside dynamic_cast"; } + type_id '>' + { dont_allow_type_definitions = 0; } + '(' expr ')' + { tree type = groktypename ($4); + $$ = build_dynamic_cast (type, $8); } + | STATIC_CAST '<' + { dont_allow_type_definitions = "inside static_cast"; } + type_id '>' + { dont_allow_type_definitions = 0; } + '(' expr ')' + { tree type = groktypename ($4); + $$ = build_static_cast (type, $8); } + | REINTERPRET_CAST '<' + { dont_allow_type_definitions = "inside reinterpret_cast"; } + type_id '>' + { dont_allow_type_definitions = 0; } + '(' expr ')' + { tree type = groktypename ($4); + $$ = build_reinterpret_cast (type, $8); } + | CONST_CAST '<' + { dont_allow_type_definitions = "inside const_cast"; } + type_id '>' + { dont_allow_type_definitions = 0; } + '(' expr ')' + { tree type = groktypename ($4); + $$ = build_const_cast (type, $8); } + | TYPEID '(' expr ')' + { $$ = build_typeid ($3); } + | TYPEID '(' type_id ')' + { tree type = groktypename ($3); + $$ = get_typeid (TYPE_MAIN_VARIANT (type)); } + | global_scope IDENTIFIER + { + do_scoped_id: + $$ = IDENTIFIER_GLOBAL_VALUE ($2); + if (yychar == YYEMPTY) + yychar = YYLEX; + if (! $$) + { + if (yychar == '(' || yychar == LEFT_RIGHT) + $$ = implicitly_declare ($2); + else + { + if (IDENTIFIER_GLOBAL_VALUE ($2) != error_mark_node) + error ("undeclared variable `%s' (first use here)", + IDENTIFIER_POINTER ($2)); + $$ = error_mark_node; + /* Prevent repeated error messages. */ + IDENTIFIER_GLOBAL_VALUE ($2) = error_mark_node; + } + } + else + { + if (TREE_CODE ($$) == ADDR_EXPR) + assemble_external (TREE_OPERAND ($$, 0)); + else + assemble_external ($$); + TREE_USED ($$) = 1; + } + if (TREE_CODE ($$) == CONST_DECL) + { + /* XXX CHS - should we set TREE_USED of the constant? */ + $$ = DECL_INITIAL ($$); + /* This is to prevent an enum whose value is 0 + from being considered a null pointer constant. */ + $$ = build1 (NOP_EXPR, TREE_TYPE ($$), $$); + TREE_CONSTANT ($$) = 1; + } + + } + | global_scope operator_name + { + got_scope = NULL_TREE; + if (TREE_CODE ($2) == IDENTIFIER_NODE) + goto do_scoped_id; + $$ = $2; + } + | overqualified_id %prec HYPERUNARY + { $$ = build_offset_ref (OP0 ($$), OP1 ($$)); } + | overqualified_id '(' nonnull_exprlist ')' + { $$ = build_member_call (OP0 ($$), OP1 ($$), $3); } + | overqualified_id LEFT_RIGHT + { $$ = build_member_call (OP0 ($$), OP1 ($$), NULL_TREE); } + | object unqualified_id %prec UNARY + { got_object = NULL_TREE; + $$ = build_component_ref ($$, $2, NULL_TREE, 1); } + | object overqualified_id %prec UNARY + { got_object = NULL_TREE; + $$ = build_object_ref ($$, OP0 ($2), OP1 ($2)); } + | object unqualified_id '(' nonnull_exprlist ')' + { + got_object = NULL_TREE; +#if 0 + /* This is a future direction of this code, but because + build_x_function_call cannot always undo what is done + in build_component_ref entirely yet, we cannot do this. */ + $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), $4, $$); + if (TREE_CODE ($$) == CALL_EXPR + && TREE_TYPE ($$) != void_type_node) + $$ = require_complete_type ($$); +#else + $$ = build_method_call ($$, $2, $4, NULL_TREE, + (LOOKUP_NORMAL|LOOKUP_AGGR)); +#endif + } + | object unqualified_id LEFT_RIGHT + { + got_object = NULL_TREE; +#if 0 + /* This is a future direction of this code, but because + build_x_function_call cannot always undo what is done + in build_component_ref entirely yet, we cannot do this. */ + $$ = build_x_function_call (build_component_ref ($$, $2, NULL_TREE, 1), NULL_TREE, $$); + if (TREE_CODE ($$) == CALL_EXPR + && TREE_TYPE ($$) != void_type_node) + $$ = require_complete_type ($$); +#else + $$ = build_method_call ($$, $2, NULL_TREE, NULL_TREE, + (LOOKUP_NORMAL|LOOKUP_AGGR)); +#endif + } + | object overqualified_id '(' nonnull_exprlist ')' + { + got_object = NULL_TREE; + if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2)))) + { + warning ("signature name in scope resolution ignored"); + $$ = build_method_call ($$, OP1 ($2), $4, NULL_TREE, + (LOOKUP_NORMAL|LOOKUP_AGGR)); + } + else + $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), $4); + } + | object overqualified_id LEFT_RIGHT + { + got_object = NULL_TREE; + if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (OP0 ($2)))) + { + warning ("signature name in scope resolution ignored"); + $$ = build_method_call ($$, OP1 ($2), NULL_TREE, NULL_TREE, + (LOOKUP_NORMAL|LOOKUP_AGGR)); + } + else + $$ = build_scoped_method_call ($$, OP0 ($2), OP1 ($2), NULL_TREE); + } + /* p->int::~int() is valid -- 12.4 */ + | object '~' TYPESPEC LEFT_RIGHT + { + got_object = NULL_TREE; + if (IDENTIFIER_GLOBAL_VALUE ($3) + && (TREE_CODE (TREE_TYPE ($1)) + != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($3))))) + cp_error ("`%E' is not of type `%T'", $1, $3); + $$ = convert (void_type_node, $1); + } + | object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT + { + got_object = NULL_TREE; + if ($2 != $5) + cp_error ("destructor specifier `%T::~%T()' must have matching names", $2, $5); + if (TREE_CODE (TREE_TYPE ($1)) + != TREE_CODE (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE ($2)))) + cp_error ("`%E' is not of type `%T'", $1, $2); + $$ = convert (void_type_node, $1); + } + | object error + { + got_object = NULL_TREE; + $$ = error_mark_node; + } + ; + +/* Not needed for now. + +primary_no_id: + '(' expr ')' + { $$ = $2; } + | '(' error ')' + { $$ = error_mark_node; } + | '(' + { if (current_function_decl == 0) + { + error ("braced-group within expression allowed only inside a function"); + YYERROR; + } + $$ = expand_start_stmt_expr (); } + compstmt ')' + { if (pedantic) + pedwarn ("ANSI C++ forbids braced-groups within expressions"); + $$ = expand_end_stmt_expr ($2); } + | primary_no_id '(' nonnull_exprlist ')' + { $$ = build_x_function_call ($$, $3, current_class_decl); } + | primary_no_id LEFT_RIGHT + { $$ = build_x_function_call ($$, NULL_TREE, current_class_decl); } + | primary_no_id '[' expr ']' + { goto do_array; } + | primary_no_id PLUSPLUS + { $$ = build_x_unary_op (POSTINCREMENT_EXPR, $$); } + | primary_no_id MINUSMINUS + { $$ = build_x_unary_op (POSTDECREMENT_EXPR, $$); } + | SCOPE IDENTIFIER + { goto do_scoped_id; } + | SCOPE operator_name + { if (TREE_CODE ($2) == IDENTIFIER_NODE) + goto do_scoped_id; + goto do_scoped_operator; + } + ; +*/ + +new: NEW + { $$ = 0; } + | global_scope NEW + { got_scope = NULL_TREE; $$ = 1; } + ; + +delete: DELETE + { $$ = 0; } + | global_scope delete + { got_scope = NULL_TREE; $$ = 1; } + ; + +boolean.literal: + CXX_TRUE + { $$ = boolean_true_node; } + | CXX_FALSE + { $$ = boolean_false_node; } + ; + +/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */ +string: + STRING + | string STRING + { $$ = chainon ($$, $2); } + ; + +nodecls: + /* empty */ + { + if (! current_function_parms_stored) + store_parm_decls (); + setup_vtbl_ptr (); + /* Always keep the BLOCK node associated with the outermost + pair of curley braces of a function. These are needed + for correct operation of dwarfout.c. */ + keep_next_level (); + } + ; + +object: primary '.' + { got_object = TREE_TYPE ($$); } + | primary POINTSAT + { + $$ = build_x_arrow ($$); + got_object = TREE_TYPE ($$); + } + ; + +decl: + /* Normal case: make this fast. */ + typespec declarator ';' + { tree d = get_decl_list ($1); + int yes = suspend_momentary (); + d = start_decl ($2, d, 0, NULL_TREE); + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + resume_momentary (yes); + if (IS_AGGR_TYPE_CODE (TREE_CODE ($1))) + note_got_semicolon ($1); + } + | typed_declspecs declarator ';' + { tree d, specs, attrs; + int yes; + split_specs_attrs ($1, &specs, &attrs); + yes = suspend_momentary (); + d = start_decl ($2, specs, 0, NULL_TREE); + cplus_decl_attributes (d, NULL_TREE, attrs); + cp_finish_decl (d, NULL_TREE, NULL_TREE, 0, 0); + resume_momentary (yes); + note_list_got_semicolon ($1); + } + | typespec initdecls ';' + { + resume_momentary ($2); + if (IS_AGGR_TYPE_CODE (TREE_CODE ($1))) + note_got_semicolon ($1); + } + | typed_declspecs initdecls ';' + { + resume_momentary ($2); + note_list_got_semicolon ($1); + } + | declmods notype_initdecls ';' + { resume_momentary ($2); } + | typed_declspecs ';' + { + shadow_tag ($1); + note_list_got_semicolon ($1); + } + | declmods ';' + { warning ("empty declaration"); } + ; + +/* Any kind of declarator (thus, all declarators allowed + after an explicit typespec). */ + +declarator: + after_type_declarator %prec EMPTY + | notype_declarator %prec EMPTY + ; + +/* This is necessary to postpone reduction of `int()()()()'. */ +fcast_or_absdcl: + LEFT_RIGHT %prec EMPTY + { $$ = build_parse_node (CALL_EXPR, NULL_TREE, empty_parms (), + NULL_TREE); } + | fcast_or_absdcl LEFT_RIGHT %prec EMPTY + { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), + NULL_TREE); } + ; + +/* ANSI type-id (8.1) */ +type_id: + typed_typespecs absdcl + { $$ = build_decl_list ($$, $2); } + | nonempty_type_quals absdcl + { $$ = build_decl_list ($$, $2); } + | typespec absdcl + { $$ = build_decl_list (get_decl_list ($$), $2); } + | typed_typespecs %prec EMPTY + { $$ = build_decl_list ($$, NULL_TREE); } + | nonempty_type_quals %prec EMPTY + { $$ = build_decl_list ($$, NULL_TREE); } + ; + +/* Declspecs which contain at least one type specifier or typedef name. + (Just `const' or `volatile' is not enough.) + A typedef'd name following these is taken as a name to be declared. + In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */ + +typed_declspecs: + typed_typespecs %prec EMPTY + | typed_declspecs1 + ; + +typed_declspecs1: + declmods typespec + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + | typespec reserved_declspecs %prec HYPERUNARY + { $$ = decl_tree_cons (NULL_TREE, $$, $2); } + | typespec reserved_typespecquals reserved_declspecs + { $$ = decl_tree_cons (NULL_TREE, $$, chainon ($2, $3)); } + | declmods typespec reserved_declspecs + { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); } + | declmods typespec reserved_typespecquals + { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); } + | declmods typespec reserved_typespecquals reserved_declspecs + { $$ = decl_tree_cons (NULL_TREE, $2, + chainon ($3, chainon ($4, $$))); } + ; + +reserved_declspecs: + SCSPEC + { if (extra_warnings) + warning ("`%s' is not at beginning of declaration", + IDENTIFIER_POINTER ($$)); + $$ = build_decl_list (NULL_TREE, $$); } + | reserved_declspecs typespecqual_reserved + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + | reserved_declspecs SCSPEC + { if (extra_warnings) + warning ("`%s' is not at beginning of declaration", + IDENTIFIER_POINTER ($2)); + $$ = decl_tree_cons (NULL_TREE, $2, $$); } + | reserved_declspecs attributes + { $$ = decl_tree_cons ($2, NULL_TREE, $1); } + | attributes + { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); } + ; + +/* List of just storage classes and type modifiers. + A declaration can start with just this, but then it cannot be used + to redeclare a typedef-name. + In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */ + +declmods: + nonempty_type_quals %prec EMPTY + { TREE_STATIC ($$) = 1; } + | SCSPEC + { $$ = IDENTIFIER_AS_LIST ($$); } + | declmods TYPE_QUAL + { $$ = decl_tree_cons (NULL_TREE, $2, $$); + TREE_STATIC ($$) = 1; } + | declmods SCSPEC + { if (extra_warnings && TREE_STATIC ($$)) + warning ("`%s' is not at beginning of declaration", + IDENTIFIER_POINTER ($2)); + $$ = decl_tree_cons (NULL_TREE, $2, $$); + TREE_STATIC ($$) = TREE_STATIC ($1); } + | declmods attributes + { $$ = decl_tree_cons ($2, NULL_TREE, $1); } + | attributes + { $$ = decl_tree_cons ($1, NULL_TREE, NULL_TREE); } + ; + +/* Used instead of declspecs where storage classes are not allowed + (that is, for typenames and structure components). + + C++ can takes storage classes for structure components. + Don't accept a typedef-name if anything but a modifier precedes it. */ + +typed_typespecs: + typespec %prec EMPTY + { $$ = get_decl_list ($$); } + | nonempty_type_quals typespec + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + | typespec reserved_typespecquals + { $$ = decl_tree_cons (NULL_TREE, $$, $2); } + | nonempty_type_quals typespec reserved_typespecquals + { $$ = decl_tree_cons (NULL_TREE, $2, chainon ($3, $$)); } + ; + +reserved_typespecquals: + typespecqual_reserved + { $$ = build_decl_list (NULL_TREE, $$); } + | reserved_typespecquals typespecqual_reserved + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + ; + +/* A typespec (but not a type qualifier). + Once we have seen one of these in a declaration, + if a typedef name appears then it is being redeclared. */ + +typespec: structsp + | TYPESPEC %prec EMPTY + | complete_type_name + | TYPEOF '(' expr ')' + { $$ = TREE_TYPE ($3); + if (pedantic && !in_system_header) + pedwarn ("ANSI C++ forbids `typeof'"); } + | TYPEOF '(' type_id ')' + { $$ = groktypename ($3); + if (pedantic && !in_system_header) + pedwarn ("ANSI C++ forbids `typeof'"); } + | SIGOF '(' expr ')' + { tree type = TREE_TYPE ($3); + + if (IS_AGGR_TYPE (type)) + { + sorry ("sigof type specifier"); + $$ = type; + } + else + { + error ("`sigof' applied to non-aggregate expression"); + $$ = error_mark_node; + } + } + | SIGOF '(' type_id ')' + { tree type = groktypename ($3); + + if (IS_AGGR_TYPE (type)) + { + sorry ("sigof type specifier"); + $$ = type; + } + else + { + error("`sigof' applied to non-aggregate type"); + $$ = error_mark_node; + } + } + ; + +/* A typespec that is a reserved word, or a type qualifier. */ + +typespecqual_reserved: TYPESPEC + | TYPE_QUAL + | structsp + ; + +initdecls: + initdcl0 + | initdecls ',' initdcl + ; + +notype_initdecls: + notype_initdcl0 + | notype_initdecls ',' initdcl + ; + +nomods_initdecls: + nomods_initdcl0 + | nomods_initdecls ',' initdcl + ; + +maybeasm: + /* empty */ + { $$ = NULL_TREE; } + | asm_keyword '(' string ')' + { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); $$ = $3; } + ; + +initdcl0: + declarator exception_specification_opt maybeasm maybe_attribute '=' + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + if (TREE_CODE (current_declspecs) != TREE_LIST) + current_declspecs = get_decl_list (current_declspecs); + if (have_extern_spec && !used_extern_spec) + { + current_declspecs = decl_tree_cons + (NULL_TREE, get_identifier ("extern"), + current_declspecs); + used_extern_spec = 1; + } + $5 = suspend_momentary (); + $$ = start_decl ($1, current_declspecs, 1, $2); + cplus_decl_attributes ($$, $4, prefix_attributes); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { cp_finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); + $$ = $5; } + | declarator exception_specification_opt maybeasm maybe_attribute + { tree d; + split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + if (TREE_CODE (current_declspecs) != TREE_LIST) + current_declspecs = get_decl_list (current_declspecs); + if (have_extern_spec && !used_extern_spec) + { + current_declspecs = decl_tree_cons + (NULL_TREE, get_identifier ("extern"), + current_declspecs); + used_extern_spec = 1; + } + $$ = suspend_momentary (); + d = start_decl ($1, current_declspecs, 0, $2); + cplus_decl_attributes (d, $4, prefix_attributes); + cp_finish_decl (d, NULL_TREE, $3, 0, 0); } + ; + +initdcl: + declarator exception_specification_opt maybeasm maybe_attribute '=' + { $$ = start_decl ($1, current_declspecs, 1, $2); + cplus_decl_attributes ($$, $4, prefix_attributes); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { cp_finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); } + | declarator exception_specification_opt maybeasm maybe_attribute + { $$ = start_decl ($1, current_declspecs, 0, $2); + cplus_decl_attributes ($$, $4, prefix_attributes); + cp_finish_decl ($$, NULL_TREE, $3, 0, 0); } + ; + +notype_initdcl0: + notype_declarator exception_specification_opt maybeasm maybe_attribute '=' + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $5 = suspend_momentary (); + $$ = start_decl ($1, current_declspecs, 1, $2); + cplus_decl_attributes ($$, $4, prefix_attributes); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { cp_finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); + $$ = $5; } + | notype_declarator exception_specification_opt maybeasm maybe_attribute + { tree d; + split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $$ = suspend_momentary (); + d = start_decl ($1, current_declspecs, 0, $2); + cplus_decl_attributes (d, $4, prefix_attributes); + cp_finish_decl (d, NULL_TREE, $3, 0, 0); } + ; + +nomods_initdcl0: + notype_declarator exception_specification_opt maybeasm maybe_attribute '=' + { current_declspecs = NULL_TREE; + prefix_attributes = NULL_TREE; + $5 = suspend_momentary (); + $$ = start_decl ($1, current_declspecs, 1, $2); + cplus_decl_attributes ($$, $4, prefix_attributes); } + init +/* Note how the declaration of the variable is in effect while its init is parsed! */ + { cp_finish_decl ($6, $7, $3, 0, LOOKUP_ONLYCONVERTING); + $$ = $5; } + | notype_declarator exception_specification_opt maybeasm maybe_attribute + { tree d; + current_declspecs = NULL_TREE; + prefix_attributes = NULL_TREE; + $$ = suspend_momentary (); + d = start_decl ($1, current_declspecs, 0, $2); + cplus_decl_attributes (d, $4, prefix_attributes); + cp_finish_decl (d, NULL_TREE, $3, 0, 0); } + ; + +/* the * rules are dummies to accept the Apollo extended syntax + so that the header files compile. */ +maybe_attribute: + /* empty */ + { $$ = NULL_TREE; } + | attributes + { $$ = $1; } + ; + +attributes: + attribute + { $$ = $1; } + | attributes attribute + { $$ = chainon ($1, $2); } + ; + +attribute: + ATTRIBUTE '(' '(' attribute_list ')' ')' + { $$ = $4; } + ; + +attribute_list: + attrib + { $$ = $1; } + | attribute_list ',' attrib + { $$ = chainon ($1, $3); } + ; + +attrib: + /* empty */ + { $$ = NULL_TREE; } + | any_word + { $$ = build_tree_list ($1, NULL_TREE); } + | any_word '(' IDENTIFIER ')' + { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); } + | any_word '(' IDENTIFIER ',' nonnull_exprlist ')' + { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); } + | any_word '(' nonnull_exprlist ')' + { $$ = build_tree_list ($1, $3); } + ; + +/* This still leaves out most reserved keywords, + shouldn't we include them? */ + +any_word: + identifier + | SCSPEC + | TYPESPEC + | TYPE_QUAL + ; + +/* A nonempty list of identifiers, including typenames. */ +identifiers_or_typenames: + identifier + { $$ = build_tree_list (NULL_TREE, $1); } + | identifiers_or_typenames ',' identifier + { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); } + ; + +maybe_init: + %prec EMPTY /* empty */ + { $$ = NULL_TREE; } + | '=' init + { $$ = $2; } + +init: + expr_no_commas %prec '=' + | '{' '}' + { $$ = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); + TREE_HAS_CONSTRUCTOR ($$) = 1; } + | '{' initlist '}' + { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); + TREE_HAS_CONSTRUCTOR ($$) = 1; } + | '{' initlist ',' '}' + { $$ = build_nt (CONSTRUCTOR, NULL_TREE, nreverse ($2)); + TREE_HAS_CONSTRUCTOR ($$) = 1; } + | error + { $$ = NULL_TREE; } + ; + +/* This chain is built in reverse order, + and put in forward order where initlist is used. */ +initlist: + init + { $$ = build_tree_list (NULL_TREE, $$); } + | initlist ',' init + { $$ = tree_cons (NULL_TREE, $3, $$); } + /* These are for labeled elements. */ + | '[' expr_no_commas ']' init + { $$ = build_tree_list ($2, $4); } + | initlist ',' CASE expr_no_commas ':' init + { $$ = tree_cons ($4, $6, $$); } + | identifier ':' init + { $$ = build_tree_list ($$, $3); } + | initlist ',' identifier ':' init + { $$ = tree_cons ($3, $5, $$); } + ; + +structsp: + ENUM identifier '{' + { $3 = suspend_momentary (); + $$ = start_enum ($2); } + enumlist maybecomma_warn '}' + { $$ = finish_enum ($4, $5); + resume_momentary ((int) $3); + check_for_missing_semicolon ($4); } + | ENUM identifier '{' '}' + { $$ = finish_enum (start_enum ($2), NULL_TREE); + check_for_missing_semicolon ($$); } + | ENUM '{' + { $2 = suspend_momentary (); + $$ = start_enum (make_anon_name ()); } + enumlist maybecomma_warn '}' + { $$ = finish_enum ($3, $4); + resume_momentary ((int) $1); + check_for_missing_semicolon ($3); } + | ENUM '{' '}' + { $$ = finish_enum (start_enum (make_anon_name()), NULL_TREE); + check_for_missing_semicolon ($$); } + | ENUM identifier + { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); } + | ENUM complex_type_name + { $$ = xref_tag (enum_type_node, $2, NULL_TREE, 1); } + | TYPENAME_KEYWORD complex_type_name + { $$ = $2; } + /* C++ extensions, merged with C to avoid shift/reduce conflicts */ + | class_head left_curly opt.component_decl_list '}' + { + int semi; + tree id; + +#if 0 + /* Need to rework class nesting in the + presence of nested classes, etc. */ + shadow_tag (CLASSTYPE_AS_LIST ($$)); */ +#endif + if (yychar == YYEMPTY) + yychar = YYLEX; + semi = yychar == ';'; + /* finish_struct nukes this anyway; if + finish_exception does too, then it can go. */ + if (semi) + note_got_semicolon ($$); + + if (TREE_CODE ($$) == ENUMERAL_TYPE) + /* $$ = $1 from default rule. */; + else + { + $$ = finish_struct ($$, $3, semi); + if (semi) note_got_semicolon ($$); + } + + pop_obstacks (); + + id = TYPE_IDENTIFIER ($$); + if (id && IDENTIFIER_TEMPLATE (id)) + { + tree decl; + + /* I don't know if the copying of this TYPE_DECL is + * really needed. However, it's such a small per- + * formance penalty that the extra safety is a bargain. + * - niklas@appli.se + */ + push_obstacks (&permanent_obstack, &permanent_obstack); + decl = copy_node (lookup_name (id, 0)); + if (DECL_LANG_SPECIFIC (decl)) + copy_lang_decl (decl); + pop_obstacks (); + undo_template_name_overload (id, 0); + pushdecl_top_level (decl); + } + if (! semi) + check_for_missing_semicolon ($$); } + | class_head %prec EMPTY + { + /* struct B: public A; is not accepted by the WP grammar. */ + if (TYPE_BINFO_BASETYPES ($$) && !TYPE_SIZE ($$) + && ! TYPE_BEING_DEFINED ($$)) + cp_error ("base clause without member specification for `%#T'", + $$); + } + ; + +maybecomma: + /* empty */ + | ',' + ; + +maybecomma_warn: + /* empty */ + | ',' + { if (pedantic) pedwarn ("comma at end of enumerator list"); } + ; + +aggr: AGGR + | aggr SCSPEC + { error ("storage class specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } + | aggr TYPESPEC + { error ("type specifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } + | aggr TYPE_QUAL + { error ("type qualifier `%s' not allowed after struct or class", IDENTIFIER_POINTER ($2)); } + | aggr AGGR + { error ("no body nor ';' separates two class, struct or union declarations"); } + ; + +specialization: + aggr template_type_name ';' + { + yyungetc (';', 1); current_aggr = $$; $$ = $2; + if ($0 == ridpointers[(int) RID_TEMPLATE]) + instantiate_class_template ($$, 2); + } + ; + +named_class_head_sans_basetype: + aggr identifier + { current_aggr = $$; $$ = $2; } + | specialization + ; + +named_class_head_sans_basetype_defn: + aggr identifier_defn %prec EMPTY + { current_aggr = $$; $$ = $2; } + | aggr template_type_name '{' + { yyungetc ('{', 1); + aggr2: + current_aggr = $$; + $$ = $2; + overload_template_name ($$, 0); } + | aggr template_type_name ':' + { yyungetc (':', 1); goto aggr2; } + ; + +named_complex_class_head_sans_basetype: + aggr nested_name_specifier identifier + { current_aggr = $$; $$ = $3; } + | aggr template_type %prec EMPTY + { current_aggr = $$; $$ = $2; } + ; + +do_xref_defn: /* empty */ %prec EMPTY + { $$ = xref_tag (current_aggr, $0, NULL_TREE, 0); } + ; + +named_class_head: + named_class_head_sans_basetype %prec EMPTY + { $$ = xref_tag (current_aggr, $1, NULL_TREE, 1); } + | named_class_head_sans_basetype_defn do_xref_defn + maybe_base_class_list %prec EMPTY + { + $$ = $2; + if ($3) + xref_basetypes (current_aggr, $1, $2, $3); + } + | named_complex_class_head_sans_basetype maybe_base_class_list + { + $$ = TREE_TYPE ($1); + if ($2) + xref_basetypes (current_aggr, $1, TREE_TYPE ($1), $2); + } + ; + +unnamed_class_head: aggr '{' + { $$ = xref_tag ($$, make_anon_name (), NULL_TREE, 0); + yyungetc ('{', 1); } + ; + +class_head: unnamed_class_head | named_class_head ; + +maybe_base_class_list: + %prec EMPTY /* empty */ + { $$ = NULL_TREE; } + | ':' see_typename %prec EMPTY + { yyungetc(':', 1); $$ = NULL_TREE; } + | ':' see_typename base_class_list %prec EMPTY + { $$ = $3; } + ; + +base_class_list: + base_class + | base_class_list ',' see_typename base_class + { $$ = chainon ($$, $4); } + ; + +base_class: + base_class.1 + { + tree type; + type = IDENTIFIER_TYPE_VALUE ($$); + if (! is_aggr_typedef ($$, 1)) + $$ = NULL_TREE; + else if (current_aggr == signature_type_node + && (! type) && (! IS_SIGNATURE (type))) + { + error ("class name not allowed as base signature"); + $$ = NULL_TREE; + } + else if (current_aggr == signature_type_node) + { + sorry ("signature inheritance, base type `%s' ignored", + IDENTIFIER_POINTER ($$)); + $$ = build_tree_list ((tree)access_public, $$); + } + else if (type && IS_SIGNATURE (type)) + { + error ("signature name not allowed as base class"); + $$ = NULL_TREE; + } + else + $$ = build_tree_list ((tree)access_default, $$); + } + | base_class_access_list see_typename base_class.1 + { + tree type; + type = IDENTIFIER_TYPE_VALUE ($3); + if (current_aggr == signature_type_node) + error ("access and source specifiers not allowed in signature"); + if (! is_aggr_typedef ($3, 1)) + $$ = NULL_TREE; + else if (current_aggr == signature_type_node + && (! type) && (! IS_SIGNATURE (type))) + { + error ("class name not allowed as base signature"); + $$ = NULL_TREE; + } + else if (current_aggr == signature_type_node) + { + sorry ("signature inheritance, base type `%s' ignored", + IDENTIFIER_POINTER ($$)); + $$ = build_tree_list ((tree)access_public, $3); + } + else if (type && IS_SIGNATURE (type)) + { + error ("signature name not allowed as base class"); + $$ = NULL_TREE; + } + else + $$ = build_tree_list ((tree) $$, $3); + } + ; + +base_class.1: + complete_type_name + | SIGOF '(' expr ')' + { + if (current_aggr == signature_type_node) + { + if (IS_AGGR_TYPE (TREE_TYPE ($3))) + { + sorry ("`sigof' as base signature specifier"); + /* need to return some dummy signature identifier */ + $$ = $3; + } + else + { + error ("`sigof' applied to non-aggregate expression"); + $$ = error_mark_node; + } + } + else + { + error ("`sigof' in struct or class declaration"); + $$ = error_mark_node; + } + } + | SIGOF '(' type_id ')' + { + if (current_aggr == signature_type_node) + { + if (IS_AGGR_TYPE (groktypename ($3))) + { + sorry ("`sigof' as base signature specifier"); + /* need to return some dummy signature identifier */ + $$ = $3; + } + else + { + error ("`sigof' applied to non-aggregate expression"); + $$ = error_mark_node; + } + } + else + { + error ("`sigof' in struct or class declaration"); + $$ = error_mark_node; + } + } + ; + +base_class_access_list: + VISSPEC see_typename + | SCSPEC see_typename + { if ($$ != ridpointers[(int)RID_VIRTUAL]) + sorry ("non-virtual access"); + $$ = access_default_virtual; } + | base_class_access_list VISSPEC see_typename + { int err = 0; + if ($2 == access_protected) + { + warning ("`protected' access not implemented"); + $2 = access_public; + err++; + } + else if ($2 == access_public) + { + if ($1 == access_private) + { + mixed: + error ("base class cannot be public and private"); + } + else if ($1 == access_default_virtual) + $$ = access_public_virtual; + } + else /* $2 == access_private */ + { + if ($1 == access_public) + goto mixed; + else if ($1 == access_default_virtual) + $$ = access_private_virtual; + } + } + | base_class_access_list SCSPEC see_typename + { if ($2 != ridpointers[(int)RID_VIRTUAL]) + sorry ("non-virtual access"); + if ($$ == access_public) + $$ = access_public_virtual; + else if ($$ == access_private) + $$ = access_private_virtual; } + ; + +left_curly: '{' + { tree t = $0; + push_obstacks_nochange (); + end_temporary_allocation (); + + if (! IS_AGGR_TYPE (t)) + { + t = $0 = make_lang_type (RECORD_TYPE); + TYPE_NAME (t) = get_identifier ("erroneous type"); + } + if (TYPE_SIZE (t)) + duplicate_tag_error (t); + if (TYPE_SIZE (t) || TYPE_BEING_DEFINED (t)) + { + t = make_lang_type (TREE_CODE (t)); + pushtag (TYPE_IDENTIFIER ($0), t, 0); + $0 = t; + } + pushclass (t, 0); + TYPE_BEING_DEFINED (t) = 1; + /* Reset the interface data, at the earliest possible + moment, as it might have been set via a class foo; + before. */ + /* Don't change signatures. */ + if (! IS_SIGNATURE (t)) + { + extern tree pending_vtables; + int needs_writing; + tree name = TYPE_IDENTIFIER (t); + + if (! ANON_AGGRNAME_P (name)) + { + CLASSTYPE_INTERFACE_ONLY (t) = interface_only; + SET_CLASSTYPE_INTERFACE_UNKNOWN_X + (t, interface_unknown); + } + + /* Record how to set the access of this class's + virtual functions. If write_virtuals == 2 or 3, then + inline virtuals are ``extern inline''. */ + switch (write_virtuals) + { + case 0: + case 1: + needs_writing = 1; + break; + case 2: + needs_writing = !! value_member (name, pending_vtables); + break; + case 3: + needs_writing = ! CLASSTYPE_INTERFACE_ONLY (t) + && CLASSTYPE_INTERFACE_KNOWN (t); + break; + default: + needs_writing = 0; + } + CLASSTYPE_VTABLE_NEEDS_WRITING (t) = needs_writing; + } +#if 0 + t = TYPE_IDENTIFIER ($0); + if (t && IDENTIFIER_TEMPLATE (t)) + overload_template_name (t, 1); +#endif + } + ; + +opt.component_decl_list: + /* empty */ + { $$ = NULL_TREE; } + | component_decl_list + { + if (current_aggr == signature_type_node) + $$ = build_tree_list ((tree) access_public, $$); + else + $$ = build_tree_list ((tree) access_default, $$); + } + | opt.component_decl_list VISSPEC ':' component_decl_list + { + tree visspec = (tree) $2; + + if (current_aggr == signature_type_node) + { + error ("access specifier not allowed in signature"); + visspec = (tree) access_public; + } + $$ = chainon ($$, build_tree_list (visspec, $4)); + } + | opt.component_decl_list VISSPEC ':' + { + if (current_aggr == signature_type_node) + error ("access specifier not allowed in signature"); + } + ; + +/* Note: we no longer warn about the semicolon after a component_decl_list. + ARM $9.2 says that the semicolon is optional, and therefore allowed. */ +component_decl_list: + component_decl + { if ($$ == void_type_node) $$ = NULL_TREE; + } + | component_decl_list component_decl + { /* In pushdecl, we created a reverse list of names + in this binding level. Make sure that the chain + of what we're trying to add isn't the item itself + (which can happen with what pushdecl's doing). */ + if ($2 != NULL_TREE && $2 != void_type_node) + { + if (TREE_CHAIN ($2) != $$) + $$ = chainon ($$, $2); + else + $$ = $2; + } + } + ; + +component_decl: + component_decl_1 ';' + { } + | component_decl_1 '}' + { error ("missing ';' before right brace"); + yyungetc ('}', 0); } + /* C++: handle constructors, destructors and inline functions */ + /* note that INLINE is like a TYPESPEC */ + | fn.def2 ':' /* base_init compstmt */ + { $$ = finish_method ($$); } + | fn.def2 TRY /* base_init compstmt */ + { $$ = finish_method ($$); } + | fn.def2 RETURN /* base_init compstmt */ + { $$ = finish_method ($$); } + | fn.def2 '{' /* nodecls compstmt */ + { $$ = finish_method ($$); } + | ';' + { $$ = NULL_TREE; } + ; + +component_decl_1: + /* Do not add a "typed_declspecs declarator" rule here for + speed; we need to call grok_x_components for enums, so the + speedup would be insignificant. */ + typed_declspecs components + { $$ = grok_x_components ($1, $2); } + | declmods notype_components + { $$ = grok_x_components ($1, $2); } + | notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init + { $$ = grokfield ($$, NULL_TREE, $2, $5, $3, + build_tree_list ($4, NULL_TREE)); } + | ':' expr_no_commas + { $$ = grokbitfield (NULL_TREE, NULL_TREE, $2); } + | error + { $$ = NULL_TREE; } + + /* These rules introduce a reduce/reduce conflict; in + typedef int foo, bar; + class A { + foo (bar); + }; + should "A::foo" be declared as a function or "A::bar" as a data + member? In other words, is "bar" an after_type_declarator or a + parmlist? */ + | typed_declspecs '(' parmlist ')' type_quals exception_specification_opt maybeasm maybe_attribute maybe_init + { tree specs, attrs; + split_specs_attrs ($1, &specs, &attrs); + $$ = build_parse_node (CALL_EXPR, TREE_VALUE (specs), + $3, $5); + $$ = grokfield ($$, TREE_CHAIN (specs), $6, $9, $7, + build_tree_list ($8, attrs)); } + | typed_declspecs LEFT_RIGHT type_quals exception_specification_opt maybeasm maybe_attribute maybe_init + { tree specs, attrs; + split_specs_attrs ($1, &specs, &attrs); + $$ = build_parse_node (CALL_EXPR, TREE_VALUE (specs), + empty_parms (), $3); + $$ = grokfield ($$, TREE_CHAIN (specs), $4, $7, $5, + build_tree_list ($6, attrs)); } + | using_decl + { $$ = do_class_using_decl ($1); } + ; + +/* The case of exactly one component is handled directly by component_decl. */ +/* ??? Huh? ^^^ */ +components: + /* empty: possibly anonymous */ + { $$ = NULL_TREE; } + | component_declarator0 + | components ',' component_declarator + { + /* In this context, void_type_node encodes + friends. They have been recorded elsewhere. */ + if ($$ == void_type_node) + $$ = $3; + else + $$ = chainon ($$, $3); + } + ; + +notype_components: + /* empty: possibly anonymous */ + { $$ = NULL_TREE; } + | notype_component_declarator0 + | notype_components ',' notype_component_declarator + { + /* In this context, void_type_node encodes + friends. They have been recorded elsewhere. */ + if ($$ == void_type_node) + $$ = $3; + else + $$ = chainon ($$, $3); + } + ; + +component_declarator0: + after_type_component_declarator0 + | notype_component_declarator0 + ; + +component_declarator: + after_type_component_declarator + | notype_component_declarator + ; + +after_type_component_declarator0: + after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $0 = current_declspecs; + $$ = grokfield ($$, current_declspecs, $2, $5, $3, + build_tree_list ($4, prefix_attributes)); } + | TYPENAME ':' expr_no_commas maybe_attribute + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $0 = current_declspecs; + $$ = grokbitfield ($$, current_declspecs, $3); + cplus_decl_attributes ($$, $4, prefix_attributes); } + ; + +notype_component_declarator0: + notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $0 = current_declspecs; + $$ = grokfield ($$, current_declspecs, $2, $5, $3, + build_tree_list ($4, prefix_attributes)); } + | IDENTIFIER ':' expr_no_commas maybe_attribute + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $0 = current_declspecs; + $$ = grokbitfield ($$, current_declspecs, $3); + cplus_decl_attributes ($$, $4, prefix_attributes); } + | ':' expr_no_commas maybe_attribute + { split_specs_attrs ($0, ¤t_declspecs, + &prefix_attributes); + $0 = current_declspecs; + $$ = grokbitfield (NULL_TREE, current_declspecs, $2); + cplus_decl_attributes ($$, $3, prefix_attributes); } + ; + +after_type_component_declarator: + after_type_declarator exception_specification_opt maybeasm maybe_attribute maybe_init + { $$ = grokfield ($$, current_declspecs, $2, $5, $3, + build_tree_list ($4, prefix_attributes)); } + | TYPENAME ':' expr_no_commas maybe_attribute + { $$ = grokbitfield ($$, current_declspecs, $3); + cplus_decl_attributes ($$, $4, prefix_attributes); } + ; + +notype_component_declarator: + notype_declarator exception_specification_opt maybeasm maybe_attribute maybe_init + { $$ = grokfield ($$, current_declspecs, $2, $5, $3, + build_tree_list ($4, prefix_attributes)); } + | IDENTIFIER ':' expr_no_commas maybe_attribute + { $$ = grokbitfield ($$, current_declspecs, $3); + cplus_decl_attributes ($$, $4, prefix_attributes); } + | ':' expr_no_commas maybe_attribute + { $$ = grokbitfield (NULL_TREE, current_declspecs, $2); + cplus_decl_attributes ($$, $3, prefix_attributes); } + ; + +/* We chain the enumerators in reverse order. + Because of the way enums are built, the order is + insignificant. Take advantage of this fact. */ + +enumlist: + enumerator + | enumlist ',' enumerator + { TREE_CHAIN ($3) = $$; $$ = $3; } + ; + +enumerator: + identifier + { $$ = build_enumerator ($$, NULL_TREE); } + | identifier '=' expr_no_commas + { $$ = build_enumerator ($$, $3); } + ; + +/* ANSI new-type-id (5.3.4) */ +new_type_id: + type_specifier_seq new_declarator + { $$ = build_decl_list ($$, $2); } + | type_specifier_seq %prec EMPTY + { $$ = build_decl_list ($$, NULL_TREE); } + /* GNU extension to allow arrays of arbitrary types with + non-constant dimension. */ + | '(' type_id ')' '[' expr ']' + { + if (pedantic) + pedwarn ("ANSI C++ forbids array dimensions with parenthesized type in new"); + $$ = build_parse_node (ARRAY_REF, TREE_VALUE ($2), $5); + $$ = build_decl_list (TREE_PURPOSE ($2), $$); + } + ; + +type_quals: + /* empty */ %prec EMPTY + { $$ = NULL_TREE; } + | type_quals TYPE_QUAL + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + ; + +nonempty_type_quals: + TYPE_QUAL + { $$ = IDENTIFIER_AS_LIST ($$); } + | nonempty_type_quals TYPE_QUAL + { $$ = decl_tree_cons (NULL_TREE, $2, $$); } + ; + +/* These rules must follow the rules for function declarations + and component declarations. That way, longer rules are preferred. */ + +suspend_mom: + { $$ = suspend_momentary (); } + +/* An expression which will not live on the momentary obstack. */ +nonmomentary_expr: + suspend_mom expr + { resume_momentary ((int) $1); $$ = $2; } + ; + +/* An expression which will not live on the momentary obstack. */ +maybe_parmlist: + suspend_mom '(' nonnull_exprlist ')' + { resume_momentary ((int) $1); $$ = $3; } + | suspend_mom '(' parmlist ')' + { resume_momentary ((int) $1); $$ = $3; } + | suspend_mom LEFT_RIGHT + { resume_momentary ((int) $1); $$ = empty_parms (); } + | suspend_mom '(' error ')' + { resume_momentary ((int) $1); $$ = NULL_TREE; } + ; + +/* A declarator that is allowed only after an explicit typespec. */ +/* may all be followed by prec '.' */ +after_type_declarator: + '*' nonempty_type_quals after_type_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | '&' nonempty_type_quals after_type_declarator %prec UNARY + { $$ = make_reference_declarator ($2, $3); } + | '*' after_type_declarator %prec UNARY + { $$ = make_pointer_declarator (NULL_TREE, $2); } + | '&' after_type_declarator %prec UNARY + { $$ = make_reference_declarator (NULL_TREE, $2); } + | ptr_to_mem type_quals after_type_declarator + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | direct_after_type_declarator + ; + +qualified_type_name: + type_name %prec EMPTY + { + /* Remember that this name has been used in the class + definition, as per [class.scope0] */ + if (current_class_type + && TYPE_BEING_DEFINED (current_class_type) + && ! IDENTIFIER_CLASS_VALUE ($$)) + { + tree t = lookup_name ($$, -2); + if (t) + pushdecl_class_level (t); + } + } + | nested_type + ; + +nested_type: + nested_name_specifier type_name %prec EMPTY + { $$ = $2; } + ; + +direct_after_type_declarator: + direct_after_type_declarator maybe_parmlist type_quals %prec '.' + { $$ = build_parse_node (CALL_EXPR, $$, $2, $3); } + | direct_after_type_declarator '[' nonmomentary_expr ']' + { $$ = build_parse_node (ARRAY_REF, $$, $3); } + | direct_after_type_declarator '[' ']' + { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); } + | '(' after_type_declarator ')' + { $$ = $2; } + | nested_name_specifier type_name %prec EMPTY + { push_nested_class (TREE_TYPE ($$), 3); + $$ = build_parse_node (SCOPE_REF, $$, $2); + TREE_COMPLEXITY ($$) = current_class_depth; } + | type_name %prec EMPTY + ; + +/* A declarator allowed whether or not there has been + an explicit typespec. These cannot redeclare a typedef-name. */ + +notype_declarator: + '*' nonempty_type_quals notype_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | '&' nonempty_type_quals notype_declarator %prec UNARY + { $$ = make_reference_declarator ($2, $3); } + | '*' notype_declarator %prec UNARY + { $$ = make_pointer_declarator (NULL_TREE, $2); } + | '&' notype_declarator %prec UNARY + { $$ = make_reference_declarator (NULL_TREE, $2); } + | ptr_to_mem type_quals notype_declarator + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | direct_notype_declarator + ; + +complex_notype_declarator: + '*' nonempty_type_quals notype_declarator %prec UNARY + { $$ = make_pointer_declarator ($2, $3); } + | '&' nonempty_type_quals notype_declarator %prec UNARY + { $$ = make_reference_declarator ($2, $3); } + | '*' complex_notype_declarator %prec UNARY + { $$ = make_pointer_declarator (NULL_TREE, $2); } + | '&' complex_notype_declarator %prec UNARY + { $$ = make_reference_declarator (NULL_TREE, $2); } + | ptr_to_mem type_quals notype_declarator + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | complex_direct_notype_declarator + ; + +complex_direct_notype_declarator: + direct_notype_declarator maybe_parmlist type_quals %prec '.' + { $$ = build_parse_node (CALL_EXPR, $$, $2, $3); } + | '(' complex_notype_declarator ')' + { $$ = $2; } + | direct_notype_declarator '[' nonmomentary_expr ']' + { $$ = build_parse_node (ARRAY_REF, $$, $3); } + | direct_notype_declarator '[' ']' + { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); } + | notype_qualified_id + { if (TREE_TYPE (OP0 ($$)) != current_class_type) + { + push_nested_class (TREE_TYPE (OP0 ($$)), 3); + TREE_COMPLEXITY ($$) = current_class_depth; + } + } + ; + +qualified_id: + nested_name_specifier unqualified_id + { got_scope = NULL_TREE; + $$ = build_parse_node (SCOPE_REF, $$, $2); } + ; + +notype_qualified_id: + nested_name_specifier notype_unqualified_id + { got_scope = NULL_TREE; + $$ = build_parse_node (SCOPE_REF, $$, $2); } + ; + +overqualified_id: + notype_qualified_id + | global_scope notype_qualified_id + { $$ = $2; } + ; + +functional_cast: + typespec '(' nonnull_exprlist ')' + { $$ = build_functional_cast ($$, $3); } + | typespec '(' expr_or_declarator ')' + { $$ = reparse_decl_as_expr ($$, $3); } + | typespec fcast_or_absdcl %prec EMPTY + { $$ = reparse_absdcl_as_expr ($$, $2); } + ; + +type_name: + TYPENAME + | template_type %prec EMPTY + ; + +nested_name_specifier: + nested_name_specifier_1 + | nested_name_specifier nested_name_specifier_1 + { $$ = $2; } + ; + +/* Why the @#$%^& do type_name and notype_identifier need to be expanded + inline here?!? (jason) */ +nested_name_specifier_1: + TYPENAME SCOPE + { got_scope = TREE_TYPE ($$); } + | NSNAME SCOPE + { got_scope = $$; } + | template_type SCOPE + { got_scope = TREE_TYPE ($$); } +/* These break 'const i;' + | IDENTIFIER SCOPE + { + failed_scope: + cp_error ("`%D' is not an aggregate typedef", + lastiddecl ? lastiddecl : $$); + $$ = error_mark_node; + } + | PTYPENAME SCOPE + { goto failed_scope; } */ + ; + +complete_type_name: + qualified_type_name + | global_scope qualified_type_name + { $$ = $2; } + ; + +complex_type_name: + nested_type + | global_scope qualified_type_name + { $$ = $2; } + ; + +ptr_to_mem: + nested_name_specifier '*' + { got_scope = NULL_TREE; } + | global_scope nested_name_specifier '*' + { $$ = $2; got_scope = NULL_TREE; } + ; + +/* All uses of explicit global scope must go through this nonterminal so + that got_scope will be set before yylex is called to get the next token. */ +global_scope: + SCOPE + { got_scope = void_type_node; } + ; + +/* ANSI new-declarator (5.3.4) */ +new_declarator: + '*' type_quals new_declarator + { $$ = make_pointer_declarator ($2, $3); } + | '*' type_quals %prec EMPTY + { $$ = make_pointer_declarator ($2, NULL_TREE); } + | '&' type_quals new_declarator %prec EMPTY + { $$ = make_reference_declarator ($2, $3); } + | '&' type_quals %prec EMPTY + { $$ = make_reference_declarator ($2, NULL_TREE); } + | ptr_to_mem type_quals %prec EMPTY + { tree arg = make_pointer_declarator ($2, NULL_TREE); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | ptr_to_mem type_quals new_declarator + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | direct_new_declarator %prec EMPTY + ; + +/* ANSI direct-new-declarator (5.3.4) */ +direct_new_declarator: + '[' expr ']' + { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); } + | direct_new_declarator '[' nonmomentary_expr ']' + { $$ = build_parse_node (ARRAY_REF, $$, $3); } + ; + +/* ANSI abstract-declarator (8.1) */ +absdcl: + '*' nonempty_type_quals absdcl + { $$ = make_pointer_declarator ($2, $3); } + | '*' absdcl + { $$ = make_pointer_declarator (NULL_TREE, $2); } + | '*' nonempty_type_quals %prec EMPTY + { $$ = make_pointer_declarator ($2, NULL_TREE); } + | '*' %prec EMPTY + { $$ = make_pointer_declarator (NULL_TREE, NULL_TREE); } + | '&' nonempty_type_quals absdcl + { $$ = make_reference_declarator ($2, $3); } + | '&' absdcl + { $$ = make_reference_declarator (NULL_TREE, $2); } + | '&' nonempty_type_quals %prec EMPTY + { $$ = make_reference_declarator ($2, NULL_TREE); } + | '&' %prec EMPTY + { $$ = make_reference_declarator (NULL_TREE, NULL_TREE); } + | ptr_to_mem type_quals %prec EMPTY + { tree arg = make_pointer_declarator ($2, NULL_TREE); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | ptr_to_mem type_quals absdcl + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + | direct_abstract_declarator %prec EMPTY + ; + +/* ANSI direct-abstract-declarator (8.1) */ +direct_abstract_declarator: + '(' absdcl ')' + { $$ = $2; } + /* `(typedef)1' is `int'. */ + | PAREN_STAR_PAREN + | direct_abstract_declarator '(' parmlist ')' type_quals %prec '.' + { $$ = build_parse_node (CALL_EXPR, $$, $3, $5); } + | direct_abstract_declarator LEFT_RIGHT type_quals %prec '.' + { $$ = build_parse_node (CALL_EXPR, $$, empty_parms (), $3); } + | direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.' + { $$ = build_parse_node (ARRAY_REF, $$, $3); } + | direct_abstract_declarator '[' ']' %prec '.' + { $$ = build_parse_node (ARRAY_REF, $$, NULL_TREE); } + | '(' complex_parmlist ')' type_quals %prec '.' + { $$ = build_parse_node (CALL_EXPR, NULL_TREE, $2, $4); } + | regcast_or_absdcl type_quals %prec '.' + { TREE_OPERAND ($$, 2) = $2; } + | fcast_or_absdcl type_quals %prec '.' + { TREE_OPERAND ($$, 2) = $2; } + | '[' nonmomentary_expr ']' %prec '.' + { $$ = build_parse_node (ARRAY_REF, NULL_TREE, $2); } + | '[' ']' %prec '.' + { $$ = build_parse_node (ARRAY_REF, NULL_TREE, NULL_TREE); } + ; + +/* For C++, decls and stmts can be intermixed, so we don't need to + have a special rule that won't start parsing the stmt section + until we have a stmt that parses without errors. */ + +stmts: + stmt + | errstmt + | stmts stmt + | stmts errstmt + ; + +errstmt: error ';' + ; + +/* build the LET_STMT node before parsing its contents, + so that any LET_STMTs within the context can have their display pointers + set up to point at this one. */ + +.pushlevel: /* empty */ + { emit_line_note (input_filename, lineno); + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); } + ; + +.poplevel: /* empty */ + { expand_end_bindings (getdecls (), kept_level_p (), 1); + $$ = poplevel (kept_level_p (), 1, 0); + pop_momentary (); } + ; + +/* Read zero or more forward-declarations for labels + that nested functions can jump to. */ +maybe_label_decls: + /* empty */ + | label_decls + { if (pedantic) + pedwarn ("ANSI C++ forbids label declarations"); } + ; + +label_decls: + label_decl + | label_decls label_decl + ; + +label_decl: + LABEL identifiers_or_typenames ';' + { tree link; + for (link = $2; link; link = TREE_CHAIN (link)) + { + tree label = shadow_label (TREE_VALUE (link)); + C_DECLARED_LABEL_FLAG (label) = 1; + declare_nonlocal_label (label); + } + } + ; + +/* This is the body of a function definition. + It causes syntax errors to ignore to the next openbrace. */ +compstmt_or_error: + compstmt + {} + | error compstmt + ; + +compstmt: '{' .pushlevel compstmtend .poplevel + { $$ = $4; } + ; + +simple_if: + IF + { cond_stmt_keyword = "if"; } + .pushlevel paren_cond_or_null + { emit_line_note (input_filename, lineno); + expand_start_cond ($4, 0); } + implicitly_scoped_stmt + ; + +implicitly_scoped_stmt: + compstmt + { finish_stmt (); } + | .pushlevel simple_stmt .poplevel + { $$ = $3; } + ; + +stmt: + compstmt + { finish_stmt (); } + | simple_stmt + ; + +simple_stmt: + decl + { finish_stmt (); } + | expr ';' + { + tree expr = $1; + emit_line_note (input_filename, lineno); + /* Do default conversion if safe and possibly important, + in case within ({...}). */ + if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE + && lvalue_p (expr)) + || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE) + expr = default_conversion (expr); + cplus_expand_expr_stmt (expr); + clear_momentary (); + finish_stmt (); } + | simple_if ELSE + { expand_start_else (); } + implicitly_scoped_stmt + { expand_end_cond (); } + .poplevel + { finish_stmt (); } + | simple_if %prec IF + { expand_end_cond (); + expand_end_bindings (getdecls (), kept_level_p (), 1); + poplevel (kept_level_p (), 1, 0); + pop_momentary (); + finish_stmt (); } + | WHILE + { emit_nop (); + emit_line_note (input_filename, lineno); + expand_start_loop (1); + cond_stmt_keyword = "while"; } + .pushlevel paren_cond_or_null + { expand_exit_loop_if_false (0, $4); } + already_scoped_stmt .poplevel + { expand_end_loop (); + finish_stmt (); } + | DO + { emit_nop (); + emit_line_note (input_filename, lineno); + expand_start_loop_continue_elsewhere (1); } + implicitly_scoped_stmt WHILE + { expand_loop_continue_here (); + cond_stmt_keyword = "do"; } + paren_expr_or_null ';' + { emit_line_note (input_filename, lineno); + expand_exit_loop_if_false (0, $6); + expand_end_loop (); + clear_momentary (); + finish_stmt (); } + | FOR + { emit_line_note (input_filename, lineno); + if (flag_new_for_scope > 0) + { + /* Conditionalize .pushlevel */ + pushlevel (0); + note_level_for_for (); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); + } + } + '(' for.init.statement + { emit_nop (); + emit_line_note (input_filename, lineno); + expand_start_loop_continue_elsewhere (1); } + .pushlevel xcond ';' + { emit_line_note (input_filename, lineno); + if ($7) expand_exit_loop_if_false (0, $7); } + xexpr ')' + /* Don't let the tree nodes for $10 be discarded + by clear_momentary during the parsing of the next stmt. */ + { push_momentary (); } + already_scoped_stmt .poplevel + { emit_line_note (input_filename, lineno); + expand_loop_continue_here (); + if ($10) cplus_expand_expr_stmt ($10); + pop_momentary (); + expand_end_loop (); + if (flag_new_for_scope > 0) + { + expand_end_bindings (getdecls (), kept_level_p (), 1); + poplevel (kept_level_p (), 1, 0); + pop_momentary (); + } + finish_stmt (); } + | SWITCH .pushlevel '(' condition ')' + { emit_line_note (input_filename, lineno); + c_expand_start_case ($4); + push_switch (); + /* Don't let the tree nodes for $4 be discarded by + clear_momentary during the parsing of the next stmt. */ + push_momentary (); } + implicitly_scoped_stmt + { expand_end_case ($4); + pop_momentary (); + pop_switch (); } + .poplevel + { finish_stmt (); } + | CASE expr_no_commas ':' + { register tree value = check_cp_case_value ($2); + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + if (value != error_mark_node) + { + tree duplicate; + int success = pushcase (value, convert_and_check, + label, &duplicate); + if (success == 1) + cp_error ("case label `%E' not within a switch statement", $2); + else if (success == 2) + { + cp_error ("duplicate case value `%E'", $2); + cp_error_at ("previously used here", duplicate); + } + else if (success == 3) + warning ("case value out of range"); + else if (success == 5) + cp_error ("case label `%E' within scope of cleanup or variable array", $2); + } + define_case_label (label); + } + stmt + | CASE expr_no_commas ELLIPSIS expr_no_commas ':' + { register tree value1 = check_cp_case_value ($2); + register tree value2 = check_cp_case_value ($4); + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + + if (pedantic) + pedwarn ("ANSI C++ forbids range expressions in switch statement"); + if (value1 != error_mark_node + && value2 != error_mark_node) + { + tree duplicate; + int success = pushcase_range (value1, value2, + convert_and_check, label, + &duplicate); + if (success == 1) + error ("case label not within a switch statement"); + else if (success == 2) + { + error ("duplicate (or overlapping) case value"); + error_with_decl (duplicate, "this is the first entry overlapping that value"); + } + else if (success == 3) + warning ("case value out of range"); + else if (success == 4) + warning ("empty range specified"); + else if (success == 5) + error ("case label within scope of cleanup or variable array"); + } + define_case_label (label); + } + stmt + | DEFAULT ':' + { + tree duplicate; + register tree label + = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + int success = pushcase (NULL_TREE, 0, label, &duplicate); + if (success == 1) + error ("default label not within a switch statement"); + else if (success == 2) + { + error ("multiple default labels in one switch"); + error_with_decl (duplicate, "this is the first default label"); + } + define_case_label (NULL_TREE); + } + stmt + | BREAK ';' + { emit_line_note (input_filename, lineno); + if ( ! expand_exit_something ()) + error ("break statement not within loop or switch"); } + | CONTINUE ';' + { emit_line_note (input_filename, lineno); + if (! expand_continue_loop (0)) + error ("continue statement not within a loop"); } + | RETURN ';' + { emit_line_note (input_filename, lineno); + c_expand_return (NULL_TREE); } + | RETURN expr ';' + { emit_line_note (input_filename, lineno); + c_expand_return ($2); + finish_stmt (); + } + | asm_keyword maybe_type_qual '(' string ')' ';' + { if (TREE_CHAIN ($4)) $4 = combine_strings ($4); + emit_line_note (input_filename, lineno); + expand_asm ($4); + finish_stmt (); + } + /* This is the case with just output operands. */ + | asm_keyword maybe_type_qual '(' string ':' asm_operands ')' ';' + { if (TREE_CHAIN ($4)) $4 = combine_strings ($4); + emit_line_note (input_filename, lineno); + c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); + finish_stmt (); + } + /* This is the case with input operands as well. */ + | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' asm_operands ')' ';' + { if (TREE_CHAIN ($4)) $4 = combine_strings ($4); + emit_line_note (input_filename, lineno); + c_expand_asm_operands ($4, $6, $8, NULL_TREE, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); + finish_stmt (); + } + /* This is the case with clobbered registers as well. */ + | asm_keyword maybe_type_qual '(' string ':' asm_operands ':' + asm_operands ':' asm_clobbers ')' ';' + { if (TREE_CHAIN ($4)) $4 = combine_strings ($4); + emit_line_note (input_filename, lineno); + c_expand_asm_operands ($4, $6, $8, $10, + $2 == ridpointers[(int)RID_VOLATILE], + input_filename, lineno); + finish_stmt (); + } + | GOTO '*' expr ';' + { emit_line_note (input_filename, lineno); + expand_computed_goto ($3); } + | GOTO identifier ';' + { tree decl; + emit_line_note (input_filename, lineno); + decl = lookup_label ($2); + TREE_USED (decl) = 1; + expand_goto (decl); } + | label_colon stmt + { finish_stmt (); } + | label_colon '}' + { error ("label must be followed by statement"); + yyungetc ('}', 0); + finish_stmt (); } + | ';' + { finish_stmt (); } + | try_block + ; + +function_try_block: + TRY + { + if (! current_function_parms_stored) + store_parm_decls (); + expand_start_early_try_stmts (); + } + ctor_initializer_opt compstmt_or_error + { expand_end_try_stmts (); + expand_start_all_catch (); } + handler_seq + { + expand_end_all_catch (); + finish_function (lineno, (int)$3, 0); + } + ; + +try_block: + TRY + { expand_start_try_stmts (); } + compstmt + { expand_end_try_stmts (); + expand_start_all_catch (); } + handler_seq + { expand_end_all_catch (); } + ; + +handler_seq: + /* empty */ + | handler_seq CATCH .pushlevel + { dont_allow_type_definitions = "inside exception declarations"; } + handler_args + { dont_allow_type_definitions = 0; } + compstmt + { expand_end_catch_block (); } + .poplevel + ; + +type_specifier_seq: + typed_typespecs %prec EMPTY + | nonempty_type_quals %prec EMPTY + ; + +handler_args: + '(' ELLIPSIS ')' + { expand_start_catch_block (NULL_TREE, NULL_TREE); } + /* This doesn't allow reference parameters, the below does. + | '(' type_specifier_seq absdcl ')' + { expand_start_catch_block ($2, $3); } + | '(' type_specifier_seq ')' + { expand_start_catch_block ($2, NULL_TREE); } + | '(' type_specifier_seq notype_declarator ')' + { expand_start_catch_block ($2, $3); } + | '(' typed_typespecs after_type_declarator ')' + { expand_start_catch_block ($2, $3); } + This allows reference parameters... */ + | '(' parm ')' + { expand_start_catch_block (TREE_PURPOSE ($2), + TREE_VALUE ($2)); } + ; + +label_colon: + IDENTIFIER ':' + { tree label; + do_label: + label = define_label (input_filename, lineno, $1); + if (label) + expand_label (label); + } + | PTYPENAME ':' + { goto do_label; } + | TYPENAME ':' + { goto do_label; } + ; + +for.init.statement: + xexpr ';' + { if ($1) cplus_expand_expr_stmt ($1); } + | decl + | '{' compstmtend + ; + +/* Either a type-qualifier or nothing. First thing in an `asm' statement. */ + +maybe_type_qual: + /* empty */ + { emit_line_note (input_filename, lineno); + $$ = NULL_TREE; } + | TYPE_QUAL + { emit_line_note (input_filename, lineno); } + ; + +xexpr: + /* empty */ + { $$ = NULL_TREE; } + | expr + | error + { $$ = NULL_TREE; } + ; + +/* These are the operands other than the first string and colon + in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */ +asm_operands: /* empty */ + { $$ = NULL_TREE; } + | nonnull_asm_operands + ; + +nonnull_asm_operands: + asm_operand + | nonnull_asm_operands ',' asm_operand + { $$ = chainon ($$, $3); } + ; + +asm_operand: + STRING '(' expr ')' + { $$ = build_tree_list ($$, $3); } + ; + +asm_clobbers: + STRING + { $$ = tree_cons (NULL_TREE, $$, NULL_TREE); } + | asm_clobbers ',' STRING + { $$ = tree_cons (NULL_TREE, $3, $$); } + ; + +/* This is what appears inside the parens in a function declarator. + Its value is represented in the format that grokdeclarator expects. + + In C++, declaring a function with no parameters + means that that function takes *no* parameters. */ + +parmlist: /* empty */ + { + if (strict_prototype) + $$ = void_list_node; + else + $$ = NULL_TREE; + } + | complex_parmlist + | type_id + { $$ = tree_cons (NULL_TREE, $$, void_list_node); + TREE_PARMLIST ($$) = 1; } + ; + +/* This nonterminal does not include the common sequence '(' type_id ')', + as it is ambiguous and must be disambiguated elsewhere. */ +complex_parmlist: + parms + { + $$ = chainon ($$, void_list_node); + TREE_PARMLIST ($$) = 1; + } + | parms_comma ELLIPSIS + { + TREE_PARMLIST ($$) = 1; + } + /* C++ allows an ellipsis without a separating ',' */ + | parms ELLIPSIS + { + TREE_PARMLIST ($$) = 1; + } + | type_id ELLIPSIS + { + $$ = build_tree_list (NULL_TREE, $$); + TREE_PARMLIST ($$) = 1; + } + | ELLIPSIS + { + /* ARM $8.2.5 has this as a boxed-off comment. */ + if (pedantic) + warning ("use of `...' without a first argument is non-portable"); + $$ = NULL_TREE; + } + | TYPENAME_ELLIPSIS + { + TREE_PARMLIST ($$) = 1; + } + | parms TYPENAME_ELLIPSIS + { + TREE_PARMLIST ($$) = 1; + } + | type_id TYPENAME_ELLIPSIS + { + $$ = build_tree_list (NULL_TREE, $$); + TREE_PARMLIST ($$) = 1; + } + | parms ':' + { + /* This helps us recover from really nasty + parse errors, for example, a missing right + parenthesis. */ + yyerror ("possibly missing ')'"); + $$ = chainon ($$, void_list_node); + TREE_PARMLIST ($$) = 1; + yyungetc (':', 0); + yychar = ')'; + } + | type_id ':' + { + /* This helps us recover from really nasty + parse errors, for example, a missing right + parenthesis. */ + yyerror ("possibly missing ')'"); + $$ = tree_cons (NULL_TREE, $$, void_list_node); + TREE_PARMLIST ($$) = 1; + yyungetc (':', 0); + yychar = ')'; + } + ; + +/* A nonempty list of parameter declarations or type names. */ +parms: + named_parm + { $$ = build_tree_list (NULL_TREE, $$); } + | parm '=' init + { $$ = build_tree_list ($3, $$); } + | parms_comma full_parm + { $$ = chainon ($$, $2); } + | parms_comma bad_parm + { $$ = chainon ($$, build_tree_list (NULL_TREE, $2)); } + | parms_comma bad_parm '=' init + { $$ = chainon ($$, build_tree_list ($4, $2)); } + ; + +parms_comma: + parms ',' + | type_id ',' + { $$ = build_tree_list (NULL_TREE, $$); } + ; + +/* A single parameter declaration or parameter type name, + as found in a parmlist. The first four cases make up for 10% + of the time spent parsing C++. We cannot use them because + of `int id[]' which won't get parsed properly. */ +named_parm: +/* + typed_declspecs dont_see_typename '*' IDENTIFIER + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, build_parse_node (INDIRECT_REF, $4)); + see_typename (); } + | typed_declspecs dont_see_typename '&' IDENTIFIER + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, build_parse_node (ADDR_EXPR, $4)); + see_typename (); } + | TYPENAME IDENTIFIER + { $$ = build_tree_list (get_decl_list ($$), $2); } + | TYPESPEC IDENTIFIER + { $$ = build_tree_list (get_decl_list ($$), $2); } + | */ + /* Here we expand typed_declspecs inline to avoid mis-parsing of + TYPESPEC IDENTIFIER. */ + typed_declspecs1 declarator + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, $2); } + | typed_typespecs declarator + { $$ = build_tree_list ($$, $2); } + | typespec declarator + { $$ = build_tree_list (get_decl_list ($$), $2); } + | typed_declspecs1 absdcl + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, $2); } + | typed_declspecs1 %prec EMPTY + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, NULL_TREE); } + | declmods notype_declarator + { tree specs = strip_attrs ($1); + $$ = build_tree_list (specs, $2); } + ; + +full_parm: + parm maybe_init + { $$ = build_tree_list ($2, $$); } + ; + +parm: + named_parm + | type_id + ; + +see_typename: %prec EMPTY + { see_typename (); } + ; + +/* +dont_see_typename: %prec EMPTY + { dont_see_typename (); } + ; + +try_for_typename: + { + if ($-1 == error_mark_node) + $$ = 0; + else + { + $$ = 1; + pushclass ($-1, 1); + } + } + ; +*/ + +bad_parm: + /* empty */ %prec EMPTY + { + error ("type specifier omitted for parameter"); + $$ = build_tree_list (integer_type_node, NULL_TREE); + } + | notype_declarator + { + error ("type specifier omitted for parameter"); + $$ = build_tree_list (integer_type_node, $$); + } + ; + +exception_specification_opt: + %prec EMPTY /* empty */ + { $$ = NULL_TREE; } + | THROW '(' ansi_raise_identifiers ')' %prec EMPTY + { $$ = $3; } + | THROW LEFT_RIGHT %prec EMPTY + { $$ = build_decl_list (NULL_TREE, NULL_TREE); } + ; + +ansi_raise_identifier: + type_id + { $$ = build_decl_list (NULL_TREE, groktypename($$)); } + ; + +ansi_raise_identifiers: + ansi_raise_identifier + | ansi_raise_identifiers ',' ansi_raise_identifier + { + TREE_CHAIN ($3) = $$; + $$ = $3; + } + ; + +conversion_declarator: + /* empty */ %prec EMPTY + { $$ = NULL_TREE; } + | '*' type_quals conversion_declarator + { $$ = make_pointer_declarator ($2, $3); } + | '&' type_quals conversion_declarator + { $$ = make_reference_declarator ($2, $3); } + | ptr_to_mem type_quals conversion_declarator + { tree arg = make_pointer_declarator ($2, $3); + $$ = build_parse_node (SCOPE_REF, $1, arg); + } + ; + +operator: OPERATOR + { got_scope = NULL_TREE; } + ; + +operator_name: + operator '*' + { $$ = ansi_opname[MULT_EXPR]; } + | operator '/' + { $$ = ansi_opname[TRUNC_DIV_EXPR]; } + | operator '%' + { $$ = ansi_opname[TRUNC_MOD_EXPR]; } + | operator '+' + { $$ = ansi_opname[PLUS_EXPR]; } + | operator '-' + { $$ = ansi_opname[MINUS_EXPR]; } + | operator '&' + { $$ = ansi_opname[BIT_AND_EXPR]; } + | operator '|' + { $$ = ansi_opname[BIT_IOR_EXPR]; } + | operator '^' + { $$ = ansi_opname[BIT_XOR_EXPR]; } + | operator '~' + { $$ = ansi_opname[BIT_NOT_EXPR]; } + | operator ',' + { $$ = ansi_opname[COMPOUND_EXPR]; } + | operator ARITHCOMPARE + { $$ = ansi_opname[$2]; } + | operator '<' + { $$ = ansi_opname[LT_EXPR]; } + | operator '>' + { $$ = ansi_opname[GT_EXPR]; } + | operator EQCOMPARE + { $$ = ansi_opname[$2]; } + | operator ASSIGN + { $$ = ansi_assopname[$2]; } + | operator '=' + { $$ = ansi_opname [MODIFY_EXPR]; } + | operator LSHIFT + { $$ = ansi_opname[$2]; } + | operator RSHIFT + { $$ = ansi_opname[$2]; } + | operator PLUSPLUS + { $$ = ansi_opname[POSTINCREMENT_EXPR]; } + | operator MINUSMINUS + { $$ = ansi_opname[PREDECREMENT_EXPR]; } + | operator ANDAND + { $$ = ansi_opname[TRUTH_ANDIF_EXPR]; } + | operator OROR + { $$ = ansi_opname[TRUTH_ORIF_EXPR]; } + | operator '!' + { $$ = ansi_opname[TRUTH_NOT_EXPR]; } + | operator '?' ':' + { $$ = ansi_opname[COND_EXPR]; } + | operator MIN_MAX + { $$ = ansi_opname[$2]; } + | operator POINTSAT %prec EMPTY + { $$ = ansi_opname[COMPONENT_REF]; } + | operator POINTSAT_STAR %prec EMPTY + { $$ = ansi_opname[MEMBER_REF]; } + | operator LEFT_RIGHT + { $$ = ansi_opname[CALL_EXPR]; } + | operator '[' ']' + { $$ = ansi_opname[ARRAY_REF]; } + | operator NEW %prec EMPTY + { $$ = ansi_opname[NEW_EXPR]; } + | operator DELETE %prec EMPTY + { $$ = ansi_opname[DELETE_EXPR]; } + | operator NEW '[' ']' + { $$ = ansi_opname[VEC_NEW_EXPR]; } + | operator DELETE '[' ']' + { $$ = ansi_opname[VEC_DELETE_EXPR]; } + /* Names here should be looked up in class scope ALSO. */ + | operator type_specifier_seq conversion_declarator + { $$ = grokoptypename ($2, $3); } + | operator error + { $$ = ansi_opname[ERROR_MARK]; } + ; + +%% + +#ifdef SPEW_DEBUG +const char * +debug_yytranslate (value) + int value; +{ + return yytname[YYTRANSLATE (value)]; +} + +#endif diff --git a/contrib/gcc/cp/pt.c b/contrib/gcc/cp/pt.c new file mode 100644 index 00000000000..3ce02248902 --- /dev/null +++ b/contrib/gcc/cp/pt.c @@ -0,0 +1,2694 @@ +/* Handle parameterized types (templates) for GNU C++. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Known bugs or deficiencies include: + * templates for class static data don't work (methods only) + * duplicated method templates can crash the compiler + * interface/impl data is taken from file defining the template + * all methods must be provided in header files; can't use a source + file that contains only the method templates and "just win" + * method templates must be seen before the expansion of the + class template is done + */ + +#include "config.h" +#include +#include "obstack.h" + +#include "tree.h" +#include "flags.h" +#include "cp-tree.h" +#include "decl.h" +#include "parse.h" +#include "lex.h" +#include "output.h" +#include "defaults.h" + +extern struct obstack permanent_obstack; + +extern int lineno; +extern char *input_filename; +struct pending_inline *pending_template_expansions; + +int processing_template_decl; +int processing_template_defn; + +/* This is a kludge to handle instantiation of template methods that are + used before their definition. It should not be necessary after the + template rewrite. */ +static tree template_classes; + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +static int unify (); +static void add_pending_template (); + +void overload_template_name (), pop_template_decls (); + +/* We've got a template header coming up; set obstacks up to save the + nodes created permanently. (There might be cases with nested templates + where we don't have to do this, but they aren't implemented, and it + probably wouldn't be worth the effort.) */ +void +begin_template_parm_list () +{ + pushlevel (0); + push_obstacks (&permanent_obstack, &permanent_obstack); + pushlevel (0); +} + +/* Process information from new template parameter NEXT and append it to the + LIST being built. The rules for use of a template parameter type name + by later parameters are not well-defined for us just yet. However, the + only way to avoid having to parse expressions of unknown complexity (and + with tokens of unknown types) is to disallow it completely. So for now, + that is what is assumed. */ +tree +process_template_parm (list, next) + tree list, next; +{ + tree parm; + tree decl = 0; + tree defval; + int is_type; + parm = next; + my_friendly_assert (TREE_CODE (parm) == TREE_LIST, 259); + defval = TREE_PURPOSE (parm); + parm = TREE_VALUE (parm); + is_type = TREE_PURPOSE (parm) == class_type_node; + if (!is_type) + { + tree tinfo = 0; + my_friendly_assert (TREE_CODE (TREE_PURPOSE (parm)) == TREE_LIST, 260); + /* is a const-param */ + parm = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm), + PARM, 0, NULL_TREE, NULL_TREE); + /* A template parameter is not modifiable. */ + TREE_READONLY (parm) = 1; + if (IS_AGGR_TYPE (TREE_TYPE (parm))) + { + sorry ("aggregate template parameter types"); + TREE_TYPE (parm) = void_type_node; + } + tinfo = make_node (TEMPLATE_CONST_PARM); + my_friendly_assert (TREE_PERMANENT (tinfo), 260.5); + if (TREE_PERMANENT (parm) == 0) + { + parm = copy_node (parm); + TREE_PERMANENT (parm) = 1; + } + TREE_TYPE (tinfo) = TREE_TYPE (parm); + decl = build_decl (CONST_DECL, DECL_NAME (parm), TREE_TYPE (parm)); + DECL_INITIAL (decl) = tinfo; + DECL_INITIAL (parm) = tinfo; + } + else + { + tree t = make_node (TEMPLATE_TYPE_PARM); + decl = build_decl (TYPE_DECL, TREE_VALUE (parm), t); + TYPE_MAIN_DECL (t) = decl; + parm = decl; + if (defval) + { + if (IDENTIFIER_HAS_TYPE_VALUE (defval)) + defval = IDENTIFIER_TYPE_VALUE (defval); + else + defval = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (defval)); + } + } + SET_DECL_ARTIFICIAL (decl); + pushdecl (decl); + parm = build_tree_list (defval, parm); + return chainon (list, parm); +} + +/* The end of a template parameter list has been reached. Process the + tree list into a parameter vector, converting each parameter into a more + useful form. Type parameters are saved as IDENTIFIER_NODEs, and others + as PARM_DECLs. */ + +tree +end_template_parm_list (parms) + tree parms; +{ + int nparms = 0; + int saw_default = 0; + tree saved_parmlist; + tree parm; + for (parm = parms; parm; parm = TREE_CHAIN (parm)) + nparms++; + saved_parmlist = make_tree_vec (nparms); + + for (parm = parms, nparms = 0; parm; parm = TREE_CHAIN (parm), nparms++) + { + tree p = TREE_VALUE (parm); + if (TREE_PURPOSE (parm)) + saw_default = 1; + else if (saw_default) + { + error ("if a default argument is given for one template parameter"); + error ("default arguments must be given for all subsequent"); + error ("parameters as well"); + } + + if (TREE_CODE (p) == TYPE_DECL) + { + tree t = TREE_TYPE (p); + TEMPLATE_TYPE_SET_INFO (t, saved_parmlist, nparms); + } + else + { + tree tinfo = DECL_INITIAL (p); + DECL_INITIAL (p) = NULL_TREE; + TEMPLATE_CONST_SET_INFO (tinfo, saved_parmlist, nparms); + } + TREE_VEC_ELT (saved_parmlist, nparms) = parm; + } + set_current_level_tags_transparency (1); + processing_template_decl++; + return saved_parmlist; +} + +/* end_template_decl is called after a template declaration is seen. + D1 is template header; D2 is class_head_sans_basetype or a + TEMPLATE_DECL with its DECL_RESULT field set. */ +void +end_template_decl (d1, d2, is_class, defn) + tree d1, d2, is_class; + int defn; +{ + tree decl; + struct template_info *tmpl; + + tmpl = (struct template_info *) obstack_alloc (&permanent_obstack, + sizeof (struct template_info)); + tmpl->text = 0; + tmpl->length = 0; + tmpl->aggr = is_class; + + /* cloned from reinit_parse_for_template */ + tmpl->filename = input_filename; + tmpl->lineno = lineno; + tmpl->parm_vec = d1; /* [eichin:19911015.2306EST] */ + + if (d2 == NULL_TREE || d2 == error_mark_node) + { + decl = 0; + goto lose; + } + + if (is_class) + { + decl = build_lang_decl (TEMPLATE_DECL, d2, NULL_TREE); + GNU_xref_decl (current_function_decl, decl); + } + else + { + if (TREE_CODE (d2) == TEMPLATE_DECL) + decl = d2; + else + { + /* Class destructor templates and operator templates are + slipping past as non-template nodes. Process them here, since + I haven't figured out where to catch them earlier. I could + go do that, but it's a choice between getting that done and + staying only N months behind schedule. Sorry.... */ + enum tree_code code; + my_friendly_assert (TREE_CODE (d2) == CALL_EXPR, 263); + code = TREE_CODE (TREE_OPERAND (d2, 0)); + my_friendly_assert (code == BIT_NOT_EXPR + || code == OP_IDENTIFIER + || code == SCOPE_REF, 264); + d2 = grokdeclarator (d2, NULL_TREE, MEMFUNCDEF, 0, NULL_TREE, NULL_TREE); + decl = build_lang_decl (TEMPLATE_DECL, DECL_NAME (d2), + TREE_TYPE (d2)); + DECL_TEMPLATE_RESULT (decl) = d2; + DECL_CONTEXT (decl) = DECL_CONTEXT (d2); + DECL_CLASS_CONTEXT (decl) = DECL_CLASS_CONTEXT (d2); + DECL_NAME (decl) = DECL_NAME (d2); + TREE_TYPE (decl) = TREE_TYPE (d2); + if (interface_unknown && flag_external_templates + && ! flag_alt_external_templates + && ! DECL_IN_SYSTEM_HEADER (decl)) + warn_if_unknown_interface (decl); + TREE_PUBLIC (decl) = TREE_PUBLIC (d2) = flag_external_templates && !interface_unknown; + DECL_EXTERNAL (decl) = (DECL_EXTERNAL (d2) + && !(DECL_CLASS_CONTEXT (d2) + && !DECL_THIS_EXTERN (d2))); + } + + /* All routines creating TEMPLATE_DECL nodes should now be using + build_lang_decl, which will have set this up already. */ + my_friendly_assert (DECL_LANG_SPECIFIC (decl) != 0, 265); + + /* @@ Somewhere, permanent allocation isn't being used. */ + if (! DECL_TEMPLATE_IS_CLASS (decl) + && TREE_CODE (DECL_TEMPLATE_RESULT (decl)) == FUNCTION_DECL) + { + tree result = DECL_TEMPLATE_RESULT (decl); + /* Will do nothing if allocation was already permanent. */ + DECL_ARGUMENTS (result) = copy_to_permanent (DECL_ARGUMENTS (result)); + } + + /* If this is for a method, there's an extra binding level here. */ + if (DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl)) != NULL_TREE) + { + /* @@ Find out where this should be getting set! */ + tree r = DECL_TEMPLATE_RESULT (decl); + if (DECL_LANG_SPECIFIC (r) && DECL_CLASS_CONTEXT (r) == NULL_TREE) + DECL_CLASS_CONTEXT (r) = DECL_CONTEXT (r); + } + } + DECL_TEMPLATE_INFO (decl) = tmpl; + DECL_TEMPLATE_PARMS (decl) = d1; + + /* So that duplicate_decls can do the right thing. */ + if (defn) + DECL_INITIAL (decl) = error_mark_node; + + /* If context of decl is non-null (i.e., method template), add it + to the appropriate class template, and pop the binding levels. */ + if (! is_class && DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl)) != NULL_TREE) + { + tree ctx = DECL_CONTEXT (DECL_TEMPLATE_RESULT (decl)); + tree tmpl, t; + my_friendly_assert (TREE_CODE (ctx) == UNINSTANTIATED_P_TYPE, 266); + tmpl = UPT_TEMPLATE (ctx); + for (t = DECL_TEMPLATE_MEMBERS (tmpl); t; t = TREE_CHAIN (t)) + if (TREE_PURPOSE (t) == DECL_NAME (decl) + && duplicate_decls (decl, TREE_VALUE (t))) + goto already_there; + DECL_TEMPLATE_MEMBERS (tmpl) = + perm_tree_cons (DECL_NAME (decl), decl, DECL_TEMPLATE_MEMBERS (tmpl)); + already_there: + poplevel (0, 0, 0); + poplevel (0, 0, 0); + } + /* Otherwise, go back to top level first, and push the template decl + again there. */ + else + { + poplevel (0, 0, 0); + poplevel (0, 0, 0); + pushdecl (decl); + } + lose: +#if 0 /* It happens sometimes, with syntactic or semantic errors. + + One specific case: + template class Foo { ... }; + template Foo::method (Foo& x) { ... } + Note the missing "A" in the class containing "method". */ + my_friendly_assert (global_bindings_p (), 267); +#else + while (! global_bindings_p ()) + poplevel (0, 0, 0); +#endif + pop_obstacks (); + processing_template_decl--; + (void) get_pending_sizes (); +} + +tree tsubst PROTO ((tree, tree*, int, tree)); + +/* Convert all template arguments to their appropriate types, and return + a vector containing the resulting values. If any error occurs, return + error_mark_node. */ +static tree +coerce_template_parms (parms, arglist, in_decl) + tree parms, arglist; + tree in_decl; +{ + int nparms, nargs, i, lost = 0; + tree vec; + + if (arglist == NULL_TREE) + nargs = 0; + else if (TREE_CODE (arglist) == TREE_VEC) + nargs = TREE_VEC_LENGTH (arglist); + else + nargs = list_length (arglist); + + nparms = TREE_VEC_LENGTH (parms); + + if (nargs > nparms + || (nargs < nparms + && TREE_PURPOSE (TREE_VEC_ELT (parms, nargs)) == NULL_TREE)) + { + error ("incorrect number of parameters (%d, should be %d)", + nargs, nparms); + if (in_decl) + cp_error_at ("in template expansion for decl `%D'", in_decl); + return error_mark_node; + } + + if (arglist && TREE_CODE (arglist) == TREE_VEC) + vec = copy_node (arglist); + else + { + vec = make_tree_vec (nparms); + for (i = 0; i < nparms; i++) + { + tree arg; + + if (arglist) + { + arg = arglist; + arglist = TREE_CHAIN (arglist); + + if (arg == error_mark_node) + lost++; + else + arg = TREE_VALUE (arg); + } + else + arg = TREE_PURPOSE (TREE_VEC_ELT (parms, i)); + + TREE_VEC_ELT (vec, i) = arg; + } + } + for (i = 0; i < nparms; i++) + { + tree arg = TREE_VEC_ELT (vec, i); + tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i)); + tree val = 0; + int is_type, requires_type; + + is_type = TREE_CODE_CLASS (TREE_CODE (arg)) == 't'; + requires_type = TREE_CODE (parm) == TYPE_DECL; + if (is_type != requires_type) + { + if (in_decl) + cp_error ("type/value mismatch in template parameter list for `%D'", + in_decl); + lost++; + TREE_VEC_ELT (vec, i) = error_mark_node; + continue; + } + if (is_type) + val = groktypename (arg); + else + { + tree t = tsubst (TREE_TYPE (parm), &TREE_VEC_ELT (vec, 0), + TREE_VEC_LENGTH (vec), in_decl); + val = digest_init (t, arg, (tree *) 0); + + if (val == error_mark_node) + ; + + /* 14.2: Other template-arguments must be constant-expressions, + addresses of objects or functions with external linkage, or of + static class members. */ + else if (!TREE_CONSTANT (val)) + { + cp_error ("non-const `%E' cannot be used as template argument", + arg); + val = error_mark_node; + } + else if (POINTER_TYPE_P (TREE_TYPE (val)) + && ! integer_zerop (val) + && TREE_CODE (TREE_TYPE (TREE_TYPE (val))) != OFFSET_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (val))) != METHOD_TYPE) + { + t = val; + STRIP_NOPS (t); + if (TREE_CODE (t) == ADDR_EXPR) + { + tree a = TREE_OPERAND (t, 0); + STRIP_NOPS (a); + if (TREE_CODE (a) == STRING_CST) + { + cp_error ("string literal %E is not a valid template argument", a); + error ("because it is the address of an object with static linkage"); + val = error_mark_node; + } + else if (TREE_CODE (a) != VAR_DECL + && TREE_CODE (a) != FUNCTION_DECL) + goto bad; + else if (! DECL_PUBLIC (a)) + { + cp_error ("address of non-extern `%E' cannot be used as template argument", a); + val = error_mark_node; + } + } + else + { + bad: + cp_error ("`%E' is not a valid template argument", t); + error ("it must be %s%s with external linkage", + TREE_CODE (TREE_TYPE (val)) == POINTER_TYPE + ? "a pointer to " : "", + TREE_CODE (TREE_TYPE (TREE_TYPE (val))) == FUNCTION_TYPE + ? "a function" : "an object"); + val = error_mark_node; + } + } + } + + if (val == error_mark_node) + lost++; + + TREE_VEC_ELT (vec, i) = val; + } + if (lost) + return error_mark_node; + return vec; +} + +/* Given class template name and parameter list, produce a user-friendly name + for the instantiation. */ +static char * +mangle_class_name_for_template (name, parms, arglist) + char *name; + tree parms, arglist; +{ + static struct obstack scratch_obstack; + static char *scratch_firstobj; + int i, nparms; + + if (!scratch_firstobj) + { + gcc_obstack_init (&scratch_obstack); + scratch_firstobj = obstack_alloc (&scratch_obstack, 1); + } + else + obstack_free (&scratch_obstack, scratch_firstobj); + +#if 0 +#define buflen sizeof(buf) +#define check if (bufp >= buf+buflen-1) goto too_long +#define ccat(c) *bufp++=(c); check +#define advance bufp+=strlen(bufp); check +#define cat(s) strncpy(bufp, s, buf+buflen-bufp-1); advance +#else +#define check +#define ccat(c) obstack_1grow (&scratch_obstack, (c)); +#define advance +#define cat(s) obstack_grow (&scratch_obstack, (s), strlen (s)) +#endif + + cat (name); + ccat ('<'); + nparms = TREE_VEC_LENGTH (parms); + my_friendly_assert (nparms == TREE_VEC_LENGTH (arglist), 268); + for (i = 0; i < nparms; i++) + { + tree parm = TREE_VALUE (TREE_VEC_ELT (parms, i)); + tree arg = TREE_VEC_ELT (arglist, i); + + if (i) + ccat (','); + + if (TREE_CODE (parm) == TYPE_DECL) + { + cat (type_as_string (arg, 0)); + continue; + } + else + my_friendly_assert (TREE_CODE (parm) == PARM_DECL, 269); + + if (TREE_CODE (arg) == TREE_LIST) + { + /* New list cell was built because old chain link was in + use. */ + my_friendly_assert (TREE_PURPOSE (arg) == NULL_TREE, 270); + arg = TREE_VALUE (arg); + } + /* No need to check arglist against parmlist here; we did that + in coerce_template_parms, called from lookup_template_class. */ + cat (expr_as_string (arg, 0)); + } + { + char *bufp = obstack_next_free (&scratch_obstack); + int offset = 0; + while (bufp[offset - 1] == ' ') + offset--; + obstack_blank_fast (&scratch_obstack, offset); + + /* B >, not B> */ + if (bufp[offset - 1] == '>') + ccat (' '); + } + ccat ('>'); + ccat ('\0'); + return (char *) obstack_base (&scratch_obstack); + +#if 0 + too_long: +#endif + fatal ("out of (preallocated) string space creating template instantiation name"); + /* NOTREACHED */ + return NULL; +} + +/* Given an IDENTIFIER_NODE (type TEMPLATE_DECL) and a chain of + parameters, find the desired type. + + D1 is the PTYPENAME terminal, and ARGLIST is the list of arguments. + Since ARGLIST is build on the decl_obstack, we must copy it here + to keep it from being reclaimed when the decl storage is reclaimed. + + IN_DECL, if non-NULL, is the template declaration we are trying to + instantiate. */ +tree +lookup_template_class (d1, arglist, in_decl) + tree d1, arglist; + tree in_decl; +{ + tree template, parmlist; + char *mangled_name; + tree id; + + my_friendly_assert (TREE_CODE (d1) == IDENTIFIER_NODE, 272); + template = IDENTIFIER_GLOBAL_VALUE (d1); /* XXX */ + if (! template) + template = IDENTIFIER_CLASS_VALUE (d1); + /* With something like `template class X class X { ... };' + we could end up with D1 having nothing but an IDENTIFIER_LOCAL_VALUE. + We don't want to do that, but we have to deal with the situation, so + let's give them some syntax errors to chew on instead of a crash. */ + if (! template) + return error_mark_node; + if (TREE_CODE (template) != TEMPLATE_DECL) + { + cp_error ("non-template type `%T' used as a template", d1); + if (in_decl) + cp_error_at ("for template declaration `%D'", in_decl); + return error_mark_node; + } + parmlist = DECL_TEMPLATE_PARMS (template); + + arglist = coerce_template_parms (parmlist, arglist, template); + if (arglist == error_mark_node) + return error_mark_node; + if (uses_template_parms (arglist)) + { + tree t = make_lang_type (UNINSTANTIATED_P_TYPE); + tree d; + id = make_anon_name (); + d = build_decl (TYPE_DECL, id, t); + TYPE_NAME (t) = d; + TYPE_VALUES (t) = build_tree_list (template, arglist); + pushdecl_top_level (d); + } + else + { + mangled_name = mangle_class_name_for_template (IDENTIFIER_POINTER (d1), + parmlist, arglist); + id = get_identifier (mangled_name); + } + if (!IDENTIFIER_TEMPLATE (id)) + { + arglist = copy_to_permanent (arglist); + IDENTIFIER_TEMPLATE (id) = perm_tree_cons (template, arglist, NULL_TREE); + } + return id; +} + +void +push_template_decls (parmlist, arglist, class_level) + tree parmlist, arglist; + int class_level; +{ + int i, nparms; + + /* Don't want to push values into global context. */ + if (!class_level) + { + pushlevel (1); + declare_pseudo_global_level (); + } + + nparms = TREE_VEC_LENGTH (parmlist); + + for (i = 0; i < nparms; i++) + { + int requires_type, is_type; + tree parm = TREE_VALUE (TREE_VEC_ELT (parmlist, i)); + tree arg = TREE_VEC_ELT (arglist, i); + tree decl = 0; + + requires_type = TREE_CODE (parm) == TYPE_DECL; + is_type = TREE_CODE_CLASS (TREE_CODE (arg)) == 't'; + if (is_type) + { + /* add typename to namespace */ + if (!requires_type) + { + error ("template use error: type provided where value needed"); + continue; + } + decl = arg; + my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 't', 273); + decl = build_decl (TYPE_DECL, DECL_NAME (parm), decl); + } + else + { + /* add const decl to namespace */ + tree val; + tree parmtype; + if (requires_type) + { + error ("template use error: value provided where type needed"); + continue; + } + parmtype = tsubst (TREE_TYPE (parm), &TREE_VEC_ELT (arglist, 0), + TREE_VEC_LENGTH (arglist), NULL_TREE); + val = digest_init (parmtype, arg, (tree *) 0); + if (val != error_mark_node) + { + decl = build_decl (CONST_DECL, DECL_NAME (parm), + parmtype); + DECL_INITIAL (decl) = val; + TREE_READONLY (decl) = 1; + } + } + if (decl != 0) + { + SET_DECL_ARTIFICIAL (decl); + layout_decl (decl, 0); + if (class_level) + pushdecl_class_level (decl); + else + pushdecl (decl); + } + } +} + +void +pop_template_decls (parmlist, arglist, class_level) + tree parmlist, arglist; + int class_level; +{ + if (!class_level) + poplevel (0, 0, 0); +} + +/* Should be defined in parse.h. */ +extern int yychar; + +int +uses_template_parms (t) + tree t; +{ + if (!t) + return 0; + switch (TREE_CODE (t)) + { + case INDIRECT_REF: + case COMPONENT_REF: + /* We assume that the object must be instantiated in order to build + the COMPONENT_REF, so we test only whether the type of the + COMPONENT_REF uses template parms. */ + return uses_template_parms (TREE_TYPE (t)); + + case IDENTIFIER_NODE: + if (!IDENTIFIER_TEMPLATE (t)) + return 0; + return uses_template_parms (TREE_VALUE (IDENTIFIER_TEMPLATE (t))); + + /* aggregates of tree nodes */ + case TREE_VEC: + { + int i = TREE_VEC_LENGTH (t); + while (i--) + if (uses_template_parms (TREE_VEC_ELT (t, i))) + return 1; + return 0; + } + case TREE_LIST: + if (uses_template_parms (TREE_PURPOSE (t)) + || uses_template_parms (TREE_VALUE (t))) + return 1; + return uses_template_parms (TREE_CHAIN (t)); + + /* constructed type nodes */ + case POINTER_TYPE: + case REFERENCE_TYPE: + return uses_template_parms (TREE_TYPE (t)); + case RECORD_TYPE: + if (TYPE_PTRMEMFUNC_FLAG (t)) + return uses_template_parms (TYPE_PTRMEMFUNC_FN_TYPE (t)); + case UNION_TYPE: + if (!TYPE_NAME (t)) + return 0; + if (!TYPE_IDENTIFIER (t)) + return 0; + return uses_template_parms (TYPE_IDENTIFIER (t)); + case FUNCTION_TYPE: + if (uses_template_parms (TYPE_ARG_TYPES (t))) + return 1; + return uses_template_parms (TREE_TYPE (t)); + case ARRAY_TYPE: + if (uses_template_parms (TYPE_DOMAIN (t))) + return 1; + return uses_template_parms (TREE_TYPE (t)); + case OFFSET_TYPE: + if (uses_template_parms (TYPE_OFFSET_BASETYPE (t))) + return 1; + return uses_template_parms (TREE_TYPE (t)); + case METHOD_TYPE: + if (uses_template_parms (TYPE_METHOD_BASETYPE (t))) + return 1; + if (uses_template_parms (TYPE_ARG_TYPES (t))) + return 1; + return uses_template_parms (TREE_TYPE (t)); + + /* decl nodes */ + case TYPE_DECL: + return uses_template_parms (DECL_NAME (t)); + case FUNCTION_DECL: + if (uses_template_parms (TREE_TYPE (t))) + return 1; + /* fall through */ + case VAR_DECL: + case PARM_DECL: + /* ??? What about FIELD_DECLs? */ + /* The type of a decl can't use template parms if the name of the + variable doesn't, because it's impossible to resolve them. So + ignore the type field for now. */ + if (DECL_CONTEXT (t) && uses_template_parms (DECL_CONTEXT (t))) + return 1; + if (uses_template_parms (TREE_TYPE (t))) + { + error ("template parms used where they can't be resolved"); + } + return 0; + + case CALL_EXPR: + return uses_template_parms (TREE_TYPE (t)); + case ADDR_EXPR: + return uses_template_parms (TREE_OPERAND (t, 0)); + + /* template parm nodes */ + case TEMPLATE_TYPE_PARM: + case TEMPLATE_CONST_PARM: + return 1; + + /* simple type nodes */ + case INTEGER_TYPE: + if (uses_template_parms (TYPE_MIN_VALUE (t))) + return 1; + return uses_template_parms (TYPE_MAX_VALUE (t)); + + case REAL_TYPE: + case VOID_TYPE: + case ENUMERAL_TYPE: + case BOOLEAN_TYPE: + return 0; + + /* constants */ + case INTEGER_CST: + case REAL_CST: + case STRING_CST: + return 0; + + case ERROR_MARK: + /* Non-error_mark_node ERROR_MARKs are bad things. */ + my_friendly_assert (t == error_mark_node, 274); + /* NOTREACHED */ + return 0; + + case UNINSTANTIATED_P_TYPE: + return 1; + + case CONSTRUCTOR: + if (TREE_TYPE (t) && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))) + return uses_template_parms (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (t))); + /* else fall through */ + + default: + switch (TREE_CODE_CLASS (TREE_CODE (t))) + { + case '1': + case '2': + case '3': + case '<': + { + int i; + for (i = tree_code_length[(int) TREE_CODE (t)]; --i >= 0;) + if (uses_template_parms (TREE_OPERAND (t, i))) + return 1; + return 0; + } + default: + break; + } + sorry ("testing %s for template parms", + tree_code_name [(int) TREE_CODE (t)]); + my_friendly_abort (82); + /* NOTREACHED */ + return 0; + } +} + +void +instantiate_member_templates (classname) + tree classname; +{ + tree t; + tree id = classname; + tree members = DECL_TEMPLATE_MEMBERS (TREE_PURPOSE (IDENTIFIER_TEMPLATE (id))); + + for (t = members; t; t = TREE_CHAIN (t)) + { + tree parmvec, type, classparms, tdecl, t2; + int nparms, xxx = 0, i; + + my_friendly_assert (TREE_VALUE (t) != NULL_TREE, 275); + my_friendly_assert (TREE_CODE (TREE_VALUE (t)) == TEMPLATE_DECL, 276); + /* @@ Should verify that class parm list is a list of + distinct template parameters, and covers all the template + parameters. */ + tdecl = TREE_VALUE (t); + type = DECL_CONTEXT (DECL_TEMPLATE_RESULT (tdecl)); + classparms = UPT_PARMS (type); + nparms = TREE_VEC_LENGTH (classparms); + parmvec = make_tree_vec (nparms); + for (i = 0; i < nparms; i++) + TREE_VEC_ELT (parmvec, i) = NULL_TREE; + switch (unify (DECL_TEMPLATE_PARMS (tdecl), + &TREE_VEC_ELT (parmvec, 0), nparms, + type, IDENTIFIER_TYPE_VALUE (classname), + &xxx)) + { + case 0: + /* Success -- well, no inconsistency, at least. */ + for (i = 0; i < nparms; i++) + if (TREE_VEC_ELT (parmvec, i) == NULL_TREE) + goto failure; + t2 = instantiate_template (tdecl, + &TREE_VEC_ELT (parmvec, 0)); + type = IDENTIFIER_TYPE_VALUE (id); + my_friendly_assert (type != 0, 277); + break; + case 1: + /* Failure. */ + failure: + cp_error_at ("type unification error instantiating `%D'", tdecl); + cp_error ("while instantiating members of `%T'", classname); + + continue /* loop of members */; + default: + /* Eek, a bug. */ + my_friendly_abort (83); + } + } +} + +static struct tinst_level *current_tinst_level = 0; +static struct tinst_level *free_tinst_level = 0; +static int tinst_depth = 0; +int max_tinst_depth = 17; + +int +push_tinst_level (name) + tree name; +{ + struct tinst_level *new; + tree global = IDENTIFIER_GLOBAL_VALUE (name); + + if (tinst_depth >= max_tinst_depth) + { + error ("template instantiation depth exceeds maximum of %d", + max_tinst_depth); + cp_error (" instantiating `%D'", name); + return 0; + } + + if (free_tinst_level) + { + new = free_tinst_level; + free_tinst_level = new->next; + } + else + new = (struct tinst_level *) xmalloc (sizeof (struct tinst_level)); + + new->classname = name; + if (global) + { + new->line = DECL_SOURCE_LINE (global); + new->file = DECL_SOURCE_FILE (global); + } + else + { + new->line = lineno; + new->file = input_filename; + } + new->next = current_tinst_level; + current_tinst_level = new; + ++tinst_depth; + return 1; +} + +void +pop_tinst_level () +{ + struct tinst_level *old = current_tinst_level; + + current_tinst_level = old->next; + old->next = free_tinst_level; + free_tinst_level = old; + --tinst_depth; +} + +struct tinst_level * +tinst_for_decl () +{ + struct tinst_level *p = current_tinst_level; + + if (p) + for (; p->next ; p = p->next ) + ; + return p; +} + +tree +instantiate_class_template (classname, setup_parse) + tree classname; + int setup_parse; +{ + struct template_info *template_info; + tree template, t1; + + if (classname == error_mark_node) + return error_mark_node; + + my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 278); + template = IDENTIFIER_TEMPLATE (classname); + + if (IDENTIFIER_HAS_TYPE_VALUE (classname)) + { + tree type = IDENTIFIER_TYPE_VALUE (classname); + if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) + return type; + if (TYPE_BEING_DEFINED (type) + || TYPE_SIZE (type) + || CLASSTYPE_USE_TEMPLATE (type) != 0) + return type; + } + + /* If IDENTIFIER_LOCAL_VALUE is already set on this template classname + (it's something like `foo'), that means we're already working on + the instantiation for it. Normally, a classname comes in with nothing + but its IDENTIFIER_TEMPLATE slot set. If we were to try to instantiate + this again, we'd get a redeclaration error. Since we're already working + on it, we'll pass back this classname's TYPE_DECL (it's the value of + the classname's IDENTIFIER_LOCAL_VALUE). Only do this if we're setting + things up for the parser, though---if we're just trying to instantiate + it (e.g., via tsubst) we can trip up cuz it may not have an + IDENTIFIER_TYPE_VALUE when it will need one. */ + if (setup_parse && IDENTIFIER_LOCAL_VALUE (classname)) + return IDENTIFIER_LOCAL_VALUE (classname); + + if (uses_template_parms (classname)) + { + if (!TREE_TYPE (classname)) + { + tree t = make_lang_type (RECORD_TYPE); + tree d = build_decl (TYPE_DECL, classname, t); + DECL_NAME (d) = classname; + TYPE_NAME (t) = d; + pushdecl (d); + } + return NULL_TREE; + } + + t1 = TREE_PURPOSE (template); + my_friendly_assert (TREE_CODE (t1) == TEMPLATE_DECL, 279); + + /* If a template is declared but not defined, accept it; don't crash. + Later uses requiring the definition will be flagged as errors by + other code. Thanks to niklas@appli.se for this bug fix. */ + if (DECL_TEMPLATE_INFO (t1)->text == 0) + setup_parse = 0; + + push_to_top_level (); + template_info = DECL_TEMPLATE_INFO (t1); + if (setup_parse && push_tinst_level (classname)) + { + push_template_decls (DECL_TEMPLATE_PARMS (TREE_PURPOSE (template)), + TREE_VALUE (template), 0); + set_current_level_tags_transparency (1); + feed_input (template_info->text, template_info->length, (struct obstack *)0); + lineno = template_info->lineno; + input_filename = template_info->filename; + /* Get interface/implementation back in sync. */ + extract_interface_info (); + overload_template_name (classname, 0); + /* Kludge so that we don't get screwed by our own base classes. */ + TYPE_BEING_DEFINED (TREE_TYPE (classname)) = 1; + yychar = PRE_PARSED_CLASS_DECL; + yylval.ttype = classname; + processing_template_defn++; + if (!flag_external_templates) + interface_unknown++; + template_classes + = perm_tree_cons (classname, NULL_TREE, template_classes); + } + else + { + tree t, decl, id, tmpl; + + id = classname; + tmpl = TREE_PURPOSE (IDENTIFIER_TEMPLATE (id)); + t = xref_tag (DECL_TEMPLATE_INFO (tmpl)->aggr, id, NULL_TREE, 0); + my_friendly_assert (TREE_CODE (t) == RECORD_TYPE + || TREE_CODE (t) == UNION_TYPE, 280); + + /* Now, put a copy of the decl in global scope, to avoid + * recursive expansion. */ + decl = IDENTIFIER_LOCAL_VALUE (id); + if (!decl) + decl = IDENTIFIER_CLASS_VALUE (id); + if (decl) + { + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 281); + /* We'd better make sure we're on the permanent obstack or else + * we'll get a "friendly" abort 124 in pushdecl. Perhaps a + * copy_to_permanent would be sufficient here, but then a + * sharing problem might occur. I don't know -- niklas@appli.se */ + push_obstacks (&permanent_obstack, &permanent_obstack); + pushdecl_top_level (copy_node (decl)); + pop_obstacks (); + } + pop_from_top_level (); + } + + return NULL_TREE; +} + +static int +list_eq (t1, t2) + tree t1, t2; +{ + if (t1 == NULL_TREE) + return t2 == NULL_TREE; + if (t2 == NULL_TREE) + return 0; + /* Don't care if one declares its arg const and the other doesn't -- the + main variant of the arg type is all that matters. */ + if (TYPE_MAIN_VARIANT (TREE_VALUE (t1)) + != TYPE_MAIN_VARIANT (TREE_VALUE (t2))) + return 0; + return list_eq (TREE_CHAIN (t1), TREE_CHAIN (t2)); +} + +static tree +lookup_nested_type_by_name (ctype, name) + tree ctype, name; +{ + tree t; + + for (t = CLASSTYPE_TAGS (ctype); t; t = TREE_CHAIN (t)) + { + if (name == TREE_PURPOSE (t)) + return TREE_VALUE (t); + } + return NULL_TREE; +} + +static tree +search_nested_type_in_tmpl (tmpl, type) + tree tmpl, type; +{ + tree t; + + if (tmpl == NULL || TYPE_CONTEXT(type) == NULL) + return tmpl; + t = search_nested_type_in_tmpl (tmpl, TYPE_CONTEXT(type)); + if (t == NULL) return t; + t = lookup_nested_type_by_name(t, DECL_NAME(TYPE_NAME(type))); + return t; +} + +tree +tsubst (t, args, nargs, in_decl) + tree t, *args; + int nargs; + tree in_decl; +{ + tree type; + + if (t == NULL_TREE || t == error_mark_node) + return t; + + type = TREE_TYPE (t); + if (type + /* Minor optimization. + ?? Are these really the most frequent cases? Is the savings + significant? */ + && type != integer_type_node + && type != void_type_node + && type != char_type_node) + type = tsubst (type, args, nargs, in_decl); + + switch (TREE_CODE (t)) + { + case RECORD_TYPE: + if (TYPE_PTRMEMFUNC_P (t)) + return build_ptrmemfunc_type + (tsubst (TYPE_PTRMEMFUNC_FN_TYPE (t), args, nargs, in_decl)); + + /* else fall through */ + + case ERROR_MARK: + case IDENTIFIER_NODE: + case OP_IDENTIFIER: + case VOID_TYPE: + case REAL_TYPE: + case ENUMERAL_TYPE: + case BOOLEAN_TYPE: + case INTEGER_CST: + case REAL_CST: + case STRING_CST: + case UNION_TYPE: + return t; + + case INTEGER_TYPE: + if (t == integer_type_node) + return t; + + if (TREE_CODE (TYPE_MIN_VALUE (t)) == INTEGER_CST + && TREE_CODE (TYPE_MAX_VALUE (t)) == INTEGER_CST) + return t; + return build_index_2_type + (tsubst (TYPE_MIN_VALUE (t), args, nargs, in_decl), + tsubst (TYPE_MAX_VALUE (t), args, nargs, in_decl)); + + case TEMPLATE_TYPE_PARM: + { + tree arg = args[TEMPLATE_TYPE_IDX (t)]; + return cp_build_type_variant + (arg, TYPE_READONLY (arg) || TYPE_READONLY (t), + TYPE_VOLATILE (arg) || TYPE_VOLATILE (t)); + } + + case TEMPLATE_CONST_PARM: + return args[TEMPLATE_CONST_IDX (t)]; + + case FUNCTION_DECL: + { + tree r; + tree fnargs, result; + + if (type == TREE_TYPE (t) + && (DECL_CONTEXT (t) == NULL_TREE + || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) != 't')) + return t; + fnargs = tsubst (DECL_ARGUMENTS (t), args, nargs, t); + result = tsubst (DECL_RESULT (t), args, nargs, t); + if (DECL_CONTEXT (t) != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't') + { + /* Look it up in that class, and return the decl node there, + instead of creating a new one. */ + tree ctx, methods, name, method; + int n_methods; + int i, found = 0; + + name = DECL_NAME (t); + ctx = tsubst (DECL_CONTEXT (t), args, nargs, t); + methods = CLASSTYPE_METHOD_VEC (ctx); + if (methods == NULL_TREE) + /* No methods at all -- no way this one can match. */ + goto no_match; + n_methods = TREE_VEC_LENGTH (methods); + + r = NULL_TREE; + + if (!strncmp (OPERATOR_TYPENAME_FORMAT, + IDENTIFIER_POINTER (name), + sizeof (OPERATOR_TYPENAME_FORMAT) - 1)) + { + /* Type-conversion operator. Reconstruct the name, in + case it's the name of one of the template's parameters. */ + name = build_typename_overload (TREE_TYPE (type)); + } + + if (DECL_CONTEXT (t) != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) == 't' + && constructor_name (DECL_CONTEXT (t)) == DECL_NAME (t)) + name = constructor_name (ctx); + + if (DECL_CONSTRUCTOR_P (t) && TYPE_USES_VIRTUAL_BASECLASSES (ctx)) + { + /* Since we didn't know that this class had virtual bases until after + we instantiated it, we have to recreate the arguments to this + constructor, as otherwise it would miss the __in_chrg parameter. */ + tree newtype, parm; + tree parms = TREE_CHAIN (TYPE_ARG_TYPES (type)); + parms = hash_tree_chain (integer_type_node, parms); + newtype = build_cplus_method_type (ctx, + TREE_TYPE (type), + parms); + newtype = build_type_variant (newtype, + TYPE_READONLY (type), + TYPE_VOLATILE (type)); + type = newtype; + + fnargs = copy_node (DECL_ARGUMENTS (t)); + TREE_CHAIN (fnargs) = TREE_CHAIN (DECL_ARGUMENTS (t)); + + /* In this case we need "in-charge" flag saying whether + this constructor is responsible for initialization + of virtual baseclasses or not. */ + parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node); + /* Mark the artificial `__in_chrg' parameter as "artificial". */ + SET_DECL_ARTIFICIAL (parm); + DECL_ARG_TYPE (parm) = integer_type_node; + DECL_REGISTER (parm) = 1; + TREE_CHAIN (parm) = TREE_CHAIN (fnargs); + TREE_CHAIN (fnargs) = parm; + + fnargs = tsubst (fnargs, args, nargs, t); + } +#if 0 + fprintf (stderr, "\nfor function %s in class %s:\n", + IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (TYPE_IDENTIFIER (ctx))); +#endif + for (i = 0; i < n_methods; i++) + { + int pass; + + method = TREE_VEC_ELT (methods, i); + if (method == NULL_TREE || DECL_NAME (method) != name) + continue; + + pass = 0; + maybe_error: + for (; method; method = DECL_CHAIN (method)) + { + my_friendly_assert (TREE_CODE (method) == FUNCTION_DECL, + 282); + if (! comptypes (type, TREE_TYPE (method), 1)) + { + tree mtype = TREE_TYPE (method); + tree t1, t2; + + /* Keep looking for a method that matches + perfectly. This takes care of the problem + where destructors (which have implicit int args) + look like constructors which have an int arg. */ + if (pass == 0) + continue; + + t1 = TYPE_ARG_TYPES (mtype); + t2 = TYPE_ARG_TYPES (type); + if (TREE_CODE (mtype) == FUNCTION_TYPE) + t2 = TREE_CHAIN (t2); + + if (list_eq (t1, t2)) + { + if (TREE_CODE (mtype) == FUNCTION_TYPE) + { + tree newtype; + newtype = build_function_type (TREE_TYPE (type), + TYPE_ARG_TYPES (type)); + newtype = build_type_variant (newtype, + TYPE_READONLY (type), + TYPE_VOLATILE (type)); + type = newtype; + if (TREE_TYPE (type) != TREE_TYPE (mtype)) + goto maybe_bad_return_type; + } + else if (TYPE_METHOD_BASETYPE (mtype) + == TYPE_METHOD_BASETYPE (type)) + { + /* Types didn't match, but arg types and + `this' do match, so the return type is + all that should be messing it up. */ + maybe_bad_return_type: + if (TREE_TYPE (type) != TREE_TYPE (mtype)) + error ("inconsistent return types for method `%s' in class `%s'", + IDENTIFIER_POINTER (name), + IDENTIFIER_POINTER (TYPE_IDENTIFIER (ctx))); + } + r = method; + break; + } + found = 1; + continue; + } +#if 0 + fprintf (stderr, "\tfound %s\n\n", + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (method))); +#endif + if (DECL_ARTIFICIAL (method)) + { + cp_error ("template for method `%D' which has default implementation in class `%T'", name, ctx); + if (in_decl) + cp_error_at ("in attempt to instantiate `%D' declared at this point in file", in_decl); + return error_mark_node; + } + + if (DECL_ARGUMENTS (method) + && ! TREE_PERMANENT (DECL_ARGUMENTS (method))) + /* @@ Is this early enough? Might we want to do + this instead while processing the expansion? */ + DECL_ARGUMENTS (method) + = tsubst (DECL_ARGUMENTS (t), args, nargs, t); + r = method; + break; + } + if (r == NULL_TREE && pass == 0) + { + pass = 1; + method = TREE_VEC_ELT (methods, i); + goto maybe_error; + } + } + if (r == NULL_TREE) + { + no_match: + cp_error + (found + ? "template for method `%D' doesn't match any in class `%T'" + : "method `%D' not found in class `%T'", name, ctx); + if (in_decl) + cp_error_at ("in attempt to instantiate `%D' declared at this point in file", in_decl); + return error_mark_node; + } + } + else + { + r = DECL_NAME (t); + { + tree decls; + int got_it = 0; + + decls = lookup_name_nonclass (r); + if (decls == NULL_TREE) + /* no match */; + else if (TREE_CODE (decls) == TREE_LIST) + for (decls = TREE_VALUE (decls); decls ; + decls = DECL_CHAIN (decls)) + { + if (TREE_CODE (decls) == FUNCTION_DECL + && TREE_TYPE (decls) == type) + { + got_it = 1; + r = decls; + break; + } + } + else + { + tree val = decls; + decls = NULL_TREE; + if (TREE_CODE (val) == FUNCTION_DECL + && TREE_TYPE (val) == type) + { + got_it = 1; + r = val; + } + } + + if (!got_it) + { + tree a = build_decl_overload (r, TYPE_VALUES (type), + DECL_CONTEXT (t) != NULL_TREE); + r = build_lang_decl (FUNCTION_DECL, r, type); + DECL_ASSEMBLER_NAME (r) = a; + } + else if (TREE_STATIC (r)) + { + /* This overrides the template version, use it. */ + return r; + } + } + } + TREE_PUBLIC (r) = 1; + DECL_EXTERNAL (r) = 1; + TREE_STATIC (r) = 0; + DECL_INTERFACE_KNOWN (r) = 0; + DECL_INLINE (r) = DECL_INLINE (t); + DECL_THIS_INLINE (r) = DECL_THIS_INLINE (t); + TREE_READONLY (r) = TREE_READONLY (t); + TREE_THIS_VOLATILE (r) = TREE_THIS_VOLATILE (t); + { +#if 0 /* Maybe later. -jason */ + struct tinst_level *til = tinst_for_decl(); + + /* should always be true under new approach */ + if (til) + { + DECL_SOURCE_FILE (r) = til->file; + DECL_SOURCE_LINE (r) = til->line; + } + else +#endif + { + DECL_SOURCE_FILE (r) = DECL_SOURCE_FILE (t); + DECL_SOURCE_LINE (r) = DECL_SOURCE_LINE (t); + } + } + DECL_CLASS_CONTEXT (r) = tsubst (DECL_CLASS_CONTEXT (t), args, nargs, t); + make_decl_rtl (r, NULL_PTR, 1); + DECL_ARGUMENTS (r) = fnargs; + DECL_RESULT (r) = result; +#if 0 + if (DECL_CONTEXT (t) == NULL_TREE + || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (t))) != 't') + push_overloaded_decl_top_level (r, 0); +#endif + return r; + } + + case PARM_DECL: + { + tree r; + r = build_decl (PARM_DECL, DECL_NAME (t), type); + DECL_INITIAL (r) = TREE_TYPE (r); + DECL_ARTIFICIAL (r) = DECL_ARTIFICIAL (t); +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) + DECL_ARG_TYPE (r) = integer_type_node; +#endif + if (TREE_CHAIN (t)) + TREE_CHAIN (r) = tsubst (TREE_CHAIN (t), args, nargs, TREE_CHAIN (t)); + return r; + } + + case TREE_LIST: + { + tree purpose, value, chain, result; + int via_public, via_virtual, via_protected; + + if (t == void_list_node) + return t; + + via_public = TREE_VIA_PUBLIC (t); + via_protected = TREE_VIA_PROTECTED (t); + via_virtual = TREE_VIA_VIRTUAL (t); + + purpose = TREE_PURPOSE (t); + if (purpose) + purpose = tsubst (purpose, args, nargs, in_decl); + value = TREE_VALUE (t); + if (value) + value = tsubst (value, args, nargs, in_decl); + chain = TREE_CHAIN (t); + if (chain && chain != void_type_node) + chain = tsubst (chain, args, nargs, in_decl); + if (purpose == TREE_PURPOSE (t) + && value == TREE_VALUE (t) + && chain == TREE_CHAIN (t)) + return t; + result = hash_tree_cons (via_public, via_virtual, via_protected, + purpose, value, chain); + TREE_PARMLIST (result) = TREE_PARMLIST (t); + return result; + } + case TREE_VEC: + { + int len = TREE_VEC_LENGTH (t), need_new = 0, i; + tree *elts = (tree *) alloca (len * sizeof (tree)); + bzero ((char *) elts, len * sizeof (tree)); + + for (i = 0; i < len; i++) + { + elts[i] = tsubst (TREE_VEC_ELT (t, i), args, nargs, in_decl); + if (elts[i] != TREE_VEC_ELT (t, i)) + need_new = 1; + } + + if (!need_new) + return t; + + t = make_tree_vec (len); + for (i = 0; i < len; i++) + TREE_VEC_ELT (t, i) = elts[i]; + return t; + } + case POINTER_TYPE: + case REFERENCE_TYPE: + { + tree r; + enum tree_code code; + if (type == TREE_TYPE (t)) + return t; + + code = TREE_CODE (t); + if (code == POINTER_TYPE) + r = build_pointer_type (type); + else + r = build_reference_type (type); + r = cp_build_type_variant (r, TYPE_READONLY (t), TYPE_VOLATILE (t)); + /* Will this ever be needed for TYPE_..._TO values? */ + layout_type (r); + return r; + } + case OFFSET_TYPE: + return build_offset_type + (tsubst (TYPE_OFFSET_BASETYPE (t), args, nargs, in_decl), type); + case FUNCTION_TYPE: + case METHOD_TYPE: + { + tree values = TYPE_ARG_TYPES (t); + tree context = TYPE_CONTEXT (t); + tree new_value; + + /* Don't bother recursing if we know it won't change anything. */ + if (values != void_list_node) + values = tsubst (values, args, nargs, in_decl); + if (context) + context = tsubst (context, args, nargs, in_decl); + /* Could also optimize cases where return value and + values have common elements (e.g., T min(const &T, const T&). */ + + /* If the above parameters haven't changed, just return the type. */ + if (type == TREE_TYPE (t) + && values == TYPE_VALUES (t) + && context == TYPE_CONTEXT (t)) + return t; + + /* Construct a new type node and return it. */ + if (TREE_CODE (t) == FUNCTION_TYPE + && context == NULL_TREE) + { + new_value = build_function_type (type, values); + } + else if (context == NULL_TREE) + { + tree base = tsubst (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t))), + args, nargs, in_decl); + new_value = build_cplus_method_type (base, type, + TREE_CHAIN (values)); + } + else + { + new_value = make_node (TREE_CODE (t)); + TREE_TYPE (new_value) = type; + TYPE_CONTEXT (new_value) = context; + TYPE_VALUES (new_value) = values; + TYPE_SIZE (new_value) = TYPE_SIZE (t); + TYPE_ALIGN (new_value) = TYPE_ALIGN (t); + TYPE_MODE (new_value) = TYPE_MODE (t); + if (TYPE_METHOD_BASETYPE (t)) + TYPE_METHOD_BASETYPE (new_value) = tsubst (TYPE_METHOD_BASETYPE (t), + args, nargs, in_decl); + /* Need to generate hash value. */ + my_friendly_abort (84); + } + new_value = build_type_variant (new_value, + TYPE_READONLY (t), + TYPE_VOLATILE (t)); + return new_value; + } + case ARRAY_TYPE: + { + tree domain = tsubst (TYPE_DOMAIN (t), args, nargs, in_decl); + tree r; + if (type == TREE_TYPE (t) && domain == TYPE_DOMAIN (t)) + return t; + r = build_cplus_array_type (type, domain); + return r; + } + + case UNINSTANTIATED_P_TYPE: + { + int nparms = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (UPT_TEMPLATE (t))); + tree argvec = make_tree_vec (nparms); + tree parmvec = UPT_PARMS (t); + int i; + tree id, rt; + for (i = 0; i < nparms; i++) + TREE_VEC_ELT (argvec, i) = tsubst (TREE_VEC_ELT (parmvec, i), + args, nargs, in_decl); + id = lookup_template_class (DECL_NAME (UPT_TEMPLATE (t)), argvec, NULL_TREE); + if (! IDENTIFIER_HAS_TYPE_VALUE (id)) { + instantiate_class_template(id, 0); + /* set up pending_classes */ + add_pending_template (id); + + TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (id)) = + IDENTIFIER_TYPE_VALUE (id); + } + rt = IDENTIFIER_TYPE_VALUE (id); + + /* kung: this part handles nested type in template definition */ + + if ( !ANON_AGGRNAME_P (DECL_NAME(TYPE_NAME(t)))) + { + rt = search_nested_type_in_tmpl (rt, t); + } + + return build_type_variant (rt, TYPE_READONLY (t), TYPE_VOLATILE (t)); + } + + case MINUS_EXPR: + case PLUS_EXPR: + return fold (build (TREE_CODE (t), TREE_TYPE (t), + tsubst (TREE_OPERAND (t, 0), args, nargs, in_decl), + tsubst (TREE_OPERAND (t, 1), args, nargs, in_decl))); + + case NEGATE_EXPR: + case NOP_EXPR: + return fold (build1 (TREE_CODE (t), TREE_TYPE (t), + tsubst (TREE_OPERAND (t, 0), args, nargs, in_decl))); + + default: + sorry ("use of `%s' in function template", + tree_code_name [(int) TREE_CODE (t)]); + return error_mark_node; + } +} + +tree +instantiate_template (tmpl, targ_ptr) + tree tmpl, *targ_ptr; +{ + tree targs, fndecl; + int i, len; + struct pending_inline *p; + struct template_info *t; + struct obstack *old_fmp_obstack; + extern struct obstack *function_maybepermanent_obstack; + + push_obstacks (&permanent_obstack, &permanent_obstack); + old_fmp_obstack = function_maybepermanent_obstack; + function_maybepermanent_obstack = &permanent_obstack; + + my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 283); + len = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (tmpl)); + + i = len; + while (i--) + targ_ptr[i] = copy_to_permanent (targ_ptr[i]); + + for (fndecl = DECL_TEMPLATE_INSTANTIATIONS (tmpl); + fndecl; fndecl = TREE_CHAIN (fndecl)) + { + tree *t1 = &TREE_VEC_ELT (TREE_PURPOSE (fndecl), 0); + for (i = len - 1; i >= 0; i--) + if (simple_cst_equal (t1[i], targ_ptr[i]) <= 0) + goto no_match; + + /* Here, we have a match. */ + fndecl = TREE_VALUE (fndecl); + goto exit; + + no_match: + ; + } + + targs = make_tree_vec (len); + i = len; + while (i--) + TREE_VEC_ELT (targs, i) = targ_ptr[i]; + + /* substitute template parameters */ + fndecl = tsubst (DECL_RESULT (tmpl), targ_ptr, + TREE_VEC_LENGTH (targs), tmpl); + + if (fndecl == error_mark_node) + goto exit; + + assemble_external (fndecl); + + /* If it's a static member fn in the template, we need to change it + into a FUNCTION_TYPE and chop off its this pointer. */ + if (TREE_CODE (TREE_TYPE (DECL_RESULT (tmpl))) == METHOD_TYPE + && DECL_STATIC_FUNCTION_P (fndecl)) + { + revert_static_member_fn (&DECL_RESULT (tmpl), NULL, NULL); + /* Chop off the this pointer that grokclassfn so kindly added + for us (it didn't know yet if the fn was static or not). */ + DECL_ARGUMENTS (fndecl) = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); + } + + t = DECL_TEMPLATE_INFO (tmpl); + + /* If we have a preexisting version of this function, don't expand + the template version, use the other instead. */ + if (TREE_STATIC (fndecl) || DECL_TEMPLATE_SPECIALIZATION (fndecl)) + { + SET_DECL_TEMPLATE_SPECIALIZATION (fndecl); + p = (struct pending_inline *)0; + } + else if (t->text) + { + SET_DECL_IMPLICIT_INSTANTIATION (fndecl); + repo_template_used (fndecl); + p = (struct pending_inline *) permalloc (sizeof (struct pending_inline)); + p->parm_vec = t->parm_vec; + p->bindings = targs; + p->can_free = 0; + p->deja_vu = 0; + p->buf = t->text; + p->len = t->length; + p->fndecl = fndecl; + { + int l = lineno; + char * f = input_filename; + + lineno = p->lineno = t->lineno; + input_filename = p->filename = t->filename; + + extract_interface_info (); + + if (interface_unknown && flag_external_templates) + { + if (DECL_CLASS_CONTEXT (fndecl) + && CLASSTYPE_INTERFACE_KNOWN (DECL_CLASS_CONTEXT (fndecl))) + { + interface_unknown = 0; + interface_only + = CLASSTYPE_INTERFACE_ONLY (DECL_CLASS_CONTEXT (fndecl)); + } + else if (! DECL_IN_SYSTEM_HEADER (tmpl)) + warn_if_unknown_interface (tmpl); + } + + if (interface_unknown || ! flag_external_templates) + p->interface = 1; /* unknown */ + else + p->interface = interface_only ? 0 : 2; + + lineno = l; + input_filename = f; + + extract_interface_info (); + } + } + else + p = (struct pending_inline *)0; + + DECL_TEMPLATE_INSTANTIATIONS (tmpl) = + tree_cons (targs, fndecl, DECL_TEMPLATE_INSTANTIATIONS (tmpl)); + + if (p == (struct pending_inline *)0) + { + /* do nothing */ + } + else if (DECL_INLINE (fndecl)) + { + DECL_PENDING_INLINE_INFO (fndecl) = p; + p->next = pending_inlines; + pending_inlines = p; + } + else + { + p->next = pending_template_expansions; + pending_template_expansions = p; + } + exit: + function_maybepermanent_obstack = old_fmp_obstack; + pop_obstacks (); + + return fndecl; +} + +/* classlevel should now never be true. jason 4/12/94 */ +void +undo_template_name_overload (id, classlevel) + tree id; + int classlevel; +{ + tree template; + + template = IDENTIFIER_TEMPLATE (id); + if (!template) + return; + +#if 0 /* not yet, should get fixed properly later */ + poplevel (0, 0, 0); +#endif +#if 1 /* XXX */ + /* This was a botch... See `overload_template_name' just below. */ + if (!classlevel) + poplevel (0, 0, 0); +#endif +} + +/* classlevel should now never be true. jason 4/12/94 */ +void +overload_template_name (id, classlevel) + tree id; + int classlevel; +{ + tree template, t, decl; + struct template_info *tinfo; + + my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 284); + template = IDENTIFIER_TEMPLATE (id); + if (!template) + return; + + template = TREE_PURPOSE (template); + tinfo = DECL_TEMPLATE_INFO (template); + template = DECL_NAME (template); + my_friendly_assert (template != NULL_TREE, 285); + +#if 1 /* XXX */ + /* This was a botch... names of templates do not get their own private + scopes. Rather, they should go into the binding level already created + by push_template_decls. Except that there isn't one of those for + specializations. */ + if (!classlevel) + { + pushlevel (1); + declare_pseudo_global_level (); + } +#endif + + t = xref_tag (tinfo->aggr, id, NULL_TREE, 1); + my_friendly_assert (TREE_CODE (t) == RECORD_TYPE + || TREE_CODE (t) == UNION_TYPE + || TREE_CODE (t) == UNINSTANTIATED_P_TYPE, 286); + + decl = build_decl (TYPE_DECL, template, t); + SET_DECL_ARTIFICIAL (decl); + +#if 0 /* fix this later */ + /* We don't want to call here if the work has already been done. */ + t = (classlevel + ? IDENTIFIER_CLASS_VALUE (template) + : IDENTIFIER_LOCAL_VALUE (template)); + if (t + && TREE_CODE (t) == TYPE_DECL + && TREE_TYPE (t) == t) + my_friendly_abort (85); +#endif + + if (classlevel) + pushdecl_class_level (decl); + else + pushdecl (decl); + +#if 0 /* This seems bogus to me; if it isn't, explain why. (jason) */ + /* Fake this for now, just to make dwarfout.c happy. It will have to + be done in a proper way later on. */ + DECL_CONTEXT (decl) = t; +#endif +} + +extern struct pending_input *to_be_restored; + +/* NAME is the IDENTIFIER value of a PRE_PARSED_CLASS_DECL. */ +void +end_template_instantiation (name) + tree name; +{ + tree t, decl; + + processing_template_defn--; + if (!flag_external_templates) + interface_unknown--; + + /* Restore the old parser input state. */ + if (yychar == YYEMPTY) + yychar = yylex (); + if (yychar != END_OF_SAVED_INPUT) + error ("parse error at end of class template"); + else + { + restore_pending_input (to_be_restored); + to_be_restored = 0; + } + + /* Our declarations didn't get stored in the global slot, since + there was a (supposedly tags-transparent) scope in between. */ + t = IDENTIFIER_TYPE_VALUE (name); + my_friendly_assert (t != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (t)) == 't', + 287); + SET_CLASSTYPE_IMPLICIT_INSTANTIATION (t); + /* Make methods of template classes static, unless + -fexternal-templates is given. */ + if (!flag_external_templates) + SET_CLASSTYPE_INTERFACE_UNKNOWN (t); + decl = IDENTIFIER_GLOBAL_VALUE (name); + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 288); + + undo_template_name_overload (name, 0); + t = IDENTIFIER_TEMPLATE (name); + pop_template_decls (DECL_TEMPLATE_PARMS (TREE_PURPOSE (t)), TREE_VALUE (t), + 0); + /* This will fix up the type-value field. */ + pushdecl (decl); + pop_from_top_level (); + +#ifdef DWARF_DEBUGGING_INFO + if (write_symbols == DWARF_DEBUG && TREE_CODE (decl) == TYPE_DECL) + { + /* We just completed the definition of a new file-scope type, + so we can go ahead and output debug-info for it now. */ + TYPE_STUB_DECL (TREE_TYPE (decl)) = decl; + rest_of_type_compilation (TREE_TYPE (decl), 1); + } +#endif /* DWARF_DEBUGGING_INFO */ + + /* Restore interface/implementation settings. */ + extract_interface_info (); +} + +/* Store away the text of an template. */ + +void +reinit_parse_for_template (yychar, d1, d2) + int yychar; + tree d1, d2; +{ + struct template_info *template_info; + extern struct obstack inline_text_obstack; /* see comment in lex.c */ + + if (d2 == NULL_TREE || d2 == error_mark_node) + { + lose: + /* @@ Should use temp obstack, and discard results. */ + reinit_parse_for_block (yychar, &inline_text_obstack, 1); + return; + } + + if (TREE_CODE (d2) == IDENTIFIER_NODE) + d2 = IDENTIFIER_GLOBAL_VALUE (d2); + if (!d2) + goto lose; + template_info = DECL_TEMPLATE_INFO (d2); + if (!template_info) + { + template_info = (struct template_info *) permalloc (sizeof (struct template_info)); + bzero ((char *) template_info, sizeof (struct template_info)); + DECL_TEMPLATE_INFO (d2) = template_info; + } + template_info->filename = input_filename; + template_info->lineno = lineno; + reinit_parse_for_block (yychar, &inline_text_obstack, 1); + template_info->text = obstack_base (&inline_text_obstack); + template_info->length = obstack_object_size (&inline_text_obstack); + obstack_finish (&inline_text_obstack); + template_info->parm_vec = d1; +} + +/* Type unification. + + We have a function template signature with one or more references to + template parameters, and a parameter list we wish to fit to this + template. If possible, produce a list of parameters for the template + which will cause it to fit the supplied parameter list. + + Return zero for success, 2 for an incomplete match that doesn't resolve + all the types, and 1 for complete failure. An error message will be + printed only for an incomplete match. + + TPARMS[NTPARMS] is an array of template parameter types; + TARGS[NTPARMS] is the array of template parameter values. PARMS is + the function template's signature (using TEMPLATE_PARM_IDX nodes), + and ARGS is the argument list we're trying to match against it. + + If SUBR is 1, we're being called recursively (to unify the arguments of + a function or method parameter of a function template), so don't zero + out targs and don't fail on an incomplete match. */ + +int +type_unification (tparms, targs, parms, args, nsubsts, subr) + tree tparms, *targs, parms, args; + int *nsubsts, subr; +{ + tree parm, arg; + int i; + int ntparms = TREE_VEC_LENGTH (tparms); + + my_friendly_assert (TREE_CODE (tparms) == TREE_VEC, 289); + my_friendly_assert (TREE_CODE (parms) == TREE_LIST, 290); + /* ARGS could be NULL (via a call from parse.y to + build_x_function_call). */ + if (args) + my_friendly_assert (TREE_CODE (args) == TREE_LIST, 291); + my_friendly_assert (ntparms > 0, 292); + + if (!subr) + bzero ((char *) targs, sizeof (tree) * ntparms); + + while (parms + && parms != void_list_node + && args + && args != void_list_node) + { + parm = TREE_VALUE (parms); + parms = TREE_CHAIN (parms); + arg = TREE_VALUE (args); + args = TREE_CHAIN (args); + + if (arg == error_mark_node) + return 1; + if (arg == unknown_type_node) + return 1; + + if (! uses_template_parms (parm) + && TREE_CODE_CLASS (TREE_CODE (arg)) != 't') + { + if (can_convert_arg (parm, TREE_TYPE (arg), arg)) + continue; + return 1; + } + +#if 0 + if (TREE_CODE (arg) == VAR_DECL) + arg = TREE_TYPE (arg); + else if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'e') + arg = TREE_TYPE (arg); +#else + if (TREE_CODE_CLASS (TREE_CODE (arg)) != 't') + { + my_friendly_assert (TREE_TYPE (arg) != NULL_TREE, 293); + if (TREE_CODE (arg) == TREE_LIST + && TREE_TYPE (arg) == unknown_type_node + && TREE_CODE (TREE_VALUE (arg)) == TEMPLATE_DECL) + { + int nsubsts, ntparms; + tree *targs; + + /* Have to back unify here */ + arg = TREE_VALUE (arg); + nsubsts = 0; + ntparms = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (arg)); + targs = (tree *) alloca (sizeof (tree) * ntparms); + parm = tree_cons (NULL_TREE, parm, NULL_TREE); + return type_unification (DECL_TEMPLATE_PARMS (arg), targs, + TYPE_ARG_TYPES (TREE_TYPE (arg)), + parm, &nsubsts, 0); + } + arg = TREE_TYPE (arg); + } +#endif + if (TREE_CODE (arg) == REFERENCE_TYPE) + arg = TREE_TYPE (arg); + + if (TREE_CODE (parm) != REFERENCE_TYPE) + { + if (TREE_CODE (arg) == FUNCTION_TYPE + || TREE_CODE (arg) == METHOD_TYPE) + arg = build_pointer_type (arg); + else if (TREE_CODE (arg) == ARRAY_TYPE) + arg = build_pointer_type (TREE_TYPE (arg)); + else + arg = TYPE_MAIN_VARIANT (arg); + } + + switch (unify (tparms, targs, ntparms, parm, arg, nsubsts)) + { + case 0: + break; + case 1: + return 1; + } + } + /* Fail if we've reached the end of the parm list, and more args + are present, and the parm list isn't variadic. */ + if (args && args != void_list_node && parms == void_list_node) + return 1; + /* Fail if parms are left and they don't have default values. */ + if (parms + && parms != void_list_node + && TREE_PURPOSE (parms) == NULL_TREE) + return 1; + if (!subr) + for (i = 0; i < ntparms; i++) + if (!targs[i]) + { + error ("incomplete type unification"); + return 2; + } + return 0; +} + +/* Tail recursion is your friend. */ +static int +unify (tparms, targs, ntparms, parm, arg, nsubsts) + tree tparms, *targs, parm, arg; + int *nsubsts, ntparms; +{ + int idx; + + /* I don't think this will do the right thing with respect to types. + But the only case I've seen it in so far has been array bounds, where + signedness is the only information lost, and I think that will be + okay. */ + while (TREE_CODE (parm) == NOP_EXPR) + parm = TREE_OPERAND (parm, 0); + + if (arg == error_mark_node) + return 1; + if (arg == unknown_type_node) + return 1; + if (arg == parm) + return 0; + + switch (TREE_CODE (parm)) + { + case TEMPLATE_TYPE_PARM: + (*nsubsts)++; + if (TEMPLATE_TYPE_TPARMLIST (parm) != tparms) + { + error ("mixed template headers?!"); + my_friendly_abort (86); + return 1; + } + idx = TEMPLATE_TYPE_IDX (parm); +#if 0 + /* Template type parameters cannot contain cv-quals; i.e. + template void f (T& a, T& b) will not generate + void f (const int& a, const int& b). */ + if (TYPE_READONLY (arg) > TYPE_READONLY (parm) + || TYPE_VOLATILE (arg) > TYPE_VOLATILE (parm)) + return 1; + arg = TYPE_MAIN_VARIANT (arg); +#else + { + int constp = TYPE_READONLY (arg) > TYPE_READONLY (parm); + int volatilep = TYPE_VOLATILE (arg) > TYPE_VOLATILE (parm); + arg = cp_build_type_variant (arg, constp, volatilep); + } +#endif + /* Simple cases: Value already set, does match or doesn't. */ + if (targs[idx] == arg) + return 0; + else if (targs[idx]) + return 1; + /* Check for mixed types and values. */ + if (TREE_CODE (TREE_VALUE (TREE_VEC_ELT (tparms, idx))) != TYPE_DECL) + return 1; + targs[idx] = arg; + return 0; + case TEMPLATE_CONST_PARM: + (*nsubsts)++; + idx = TEMPLATE_CONST_IDX (parm); + if (targs[idx] == arg) + return 0; + else if (targs[idx]) + { + tree t = targs[idx]; + if (TREE_CODE (t) == TREE_CODE (arg)) + switch (TREE_CODE (arg)) + { + case INTEGER_CST: + if (tree_int_cst_equal (t, arg)) + return 0; + break; + case REAL_CST: + if (REAL_VALUES_EQUAL (TREE_REAL_CST (t), TREE_REAL_CST (arg))) + return 0; + break; + /* STRING_CST values are not valid template const parms. */ + default: + ; + } + my_friendly_abort (87); + return 1; + } +/* else if (typeof arg != tparms[idx]) + return 1;*/ + + targs[idx] = copy_to_permanent (arg); + return 0; + + case POINTER_TYPE: + if (TREE_CODE (arg) != POINTER_TYPE) + return 1; + return unify (tparms, targs, ntparms, TREE_TYPE (parm), TREE_TYPE (arg), + nsubsts); + + case REFERENCE_TYPE: + if (TREE_CODE (arg) == REFERENCE_TYPE) + arg = TREE_TYPE (arg); + return unify (tparms, targs, ntparms, TREE_TYPE (parm), arg, nsubsts); + + case ARRAY_TYPE: + if (TREE_CODE (arg) != ARRAY_TYPE) + return 1; + if (unify (tparms, targs, ntparms, TYPE_DOMAIN (parm), TYPE_DOMAIN (arg), + nsubsts) != 0) + return 1; + return unify (tparms, targs, ntparms, TREE_TYPE (parm), TREE_TYPE (arg), + nsubsts); + + case REAL_TYPE: + case INTEGER_TYPE: + if (TREE_CODE (arg) != TREE_CODE (parm)) + return 1; + + if (TREE_CODE (parm) == INTEGER_TYPE) + { + if (TYPE_MIN_VALUE (parm) && TYPE_MIN_VALUE (arg) + && unify (tparms, targs, ntparms, + TYPE_MIN_VALUE (parm), TYPE_MIN_VALUE (arg), nsubsts)) + return 1; + if (TYPE_MAX_VALUE (parm) && TYPE_MAX_VALUE (arg) + && unify (tparms, targs, ntparms, + TYPE_MAX_VALUE (parm), TYPE_MAX_VALUE (arg), nsubsts)) + return 1; + } + /* As far as unification is concerned, this wins. Later checks + will invalidate it if necessary. */ + return 0; + + /* Types INTEGER_CST and MINUS_EXPR can come from array bounds. */ + case INTEGER_CST: + if (TREE_CODE (arg) != INTEGER_CST) + return 1; + return !tree_int_cst_equal (parm, arg); + + case MINUS_EXPR: + { + tree t1, t2; + t1 = TREE_OPERAND (parm, 0); + t2 = TREE_OPERAND (parm, 1); + return unify (tparms, targs, ntparms, t1, + fold (build (PLUS_EXPR, integer_type_node, arg, t2)), + nsubsts); + } + + case TREE_VEC: + { + int i; + if (TREE_CODE (arg) != TREE_VEC) + return 1; + if (TREE_VEC_LENGTH (parm) != TREE_VEC_LENGTH (arg)) + return 1; + for (i = TREE_VEC_LENGTH (parm) - 1; i >= 0; i--) + if (unify (tparms, targs, ntparms, + TREE_VEC_ELT (parm, i), TREE_VEC_ELT (arg, i), + nsubsts)) + return 1; + return 0; + } + + case UNINSTANTIATED_P_TYPE: + { + tree a; + /* Unification of something that is not a class fails. */ + if (! IS_AGGR_TYPE (arg)) + return 1; + a = IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (arg)); + if (a && UPT_TEMPLATE (parm) == TREE_PURPOSE (a)) + return unify (tparms, targs, ntparms, UPT_PARMS (parm), + TREE_VALUE (a), nsubsts); + /* FIXME: Should check base conversions here. */ + return 1; + } + + case RECORD_TYPE: + if (TYPE_PTRMEMFUNC_FLAG (parm)) + return unify (tparms, targs, ntparms, TYPE_PTRMEMFUNC_FN_TYPE (parm), + arg, nsubsts); + + /* Allow trivial conversions. */ + if (TYPE_MAIN_VARIANT (parm) != TYPE_MAIN_VARIANT (arg) + || TYPE_READONLY (parm) < TYPE_READONLY (arg) + || TYPE_VOLATILE (parm) < TYPE_VOLATILE (arg)) + return 1; + return 0; + + case METHOD_TYPE: + if (TREE_CODE (arg) != METHOD_TYPE) + return 1; + goto check_args; + + case FUNCTION_TYPE: + if (TREE_CODE (arg) != FUNCTION_TYPE) + return 1; + check_args: + if (unify (tparms, targs, ntparms, TREE_TYPE (parm), + TREE_TYPE (arg), nsubsts)) + return 1; + return type_unification (tparms, targs, TYPE_ARG_TYPES (parm), + TYPE_ARG_TYPES (arg), nsubsts, 1); + + case OFFSET_TYPE: + if (TREE_CODE (arg) != OFFSET_TYPE) + return 1; + if (unify (tparms, targs, ntparms, TYPE_OFFSET_BASETYPE (parm), + TYPE_OFFSET_BASETYPE (arg), nsubsts)) + return 1; + return unify (tparms, targs, ntparms, TREE_TYPE (parm), + TREE_TYPE (arg), nsubsts); + + default: + sorry ("use of `%s' in template type unification", + tree_code_name [(int) TREE_CODE (parm)]); + return 1; + } +} + + +#undef DEBUG + +int +do_pending_expansions () +{ + struct pending_inline *i, *new_list = 0; + + { + tree t; + for (t = template_classes; t; t = TREE_CHAIN (t)) + instantiate_member_templates (TREE_PURPOSE (t)); + } + + if (!pending_template_expansions) + return 0; + +#ifdef DEBUG + fprintf (stderr, "\n\n\t\t IN DO_PENDING_EXPANSIONS\n\n"); +#endif + + i = pending_template_expansions; + while (i) + { + tree context; + + struct pending_inline *next = i->next; + tree t = i->fndecl; + + int decision = 0; +#define DECIDE(N) do {decision=(N); goto decided;} while(0) + + my_friendly_assert (TREE_CODE (t) == FUNCTION_DECL + || TREE_CODE (t) == VAR_DECL, 294); + if (TREE_ASM_WRITTEN (t)) + DECIDE (0); + + if (DECL_EXPLICIT_INSTANTIATION (t)) + DECIDE (DECL_NOT_REALLY_EXTERN (t)); + else if (! flag_implicit_templates) + DECIDE (0); + + if (i->interface == 1) + /* OK, it was an implicit instantiation. */ + { + if (SUPPORTS_WEAK) + DECL_WEAK (t) = 1; + else + TREE_PUBLIC (t) = 0; + } + + /* If it's a method, let the class type decide it. + @@ What if the method template is in a separate file? + Maybe both file contexts should be taken into account? + Maybe only do this if i->interface == 1 (unknown)? */ + context = DECL_CONTEXT (t); + if (context != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (context)) == 't') + { + /* I'm interested in the context of this version of the function, + not the original virtual declaration. */ + context = DECL_CLASS_CONTEXT (t); + + /* If `unknown', we might want a static copy. + If `implementation', we want a global one. + If `interface', ext ref. */ + if (CLASSTYPE_INTERFACE_KNOWN (context)) + DECIDE (!CLASSTYPE_INTERFACE_ONLY (context)); +#if 1 /* This doesn't get us stuff needed only by the file initializer. */ + DECIDE (TREE_USED (t)); +#else /* This compiles too much stuff, but that's probably better in + most cases than never compiling the stuff we need. */ + DECIDE (1); +#endif + } + + if (i->interface == 1) + DECIDE (TREE_USED (t)); + else + DECIDE (i->interface); + + decided: +#ifdef DEBUG + print_node_brief (stderr, decision ? "yes: " : "no: ", t, 0); + fprintf (stderr, "\t%s\n", + (DECL_ASSEMBLER_NAME (t) + ? IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t)) + : "")); +#endif + if (decision) + { + i->next = pending_inlines; + pending_inlines = i; + } + else + { + i->next = new_list; + new_list = i; + } + i = next; + } + pending_template_expansions = new_list; + if (!pending_inlines) + return 0; + do_pending_inlines (); + return 1; +} + + +struct pending_template { + struct pending_template *next; + tree id; +}; + +static struct pending_template* pending_templates; + +void +do_pending_templates () +{ + struct pending_template* t; + + for ( t = pending_templates; t; t = t->next) + { + instantiate_class_template (t->id, 1); + } + + for ( t = pending_templates; t; t = pending_templates) + { + pending_templates = t->next; + free(t); + } +} + +static void +add_pending_template (pt) + tree pt; +{ + struct pending_template *p; + + p = (struct pending_template *) malloc (sizeof (struct pending_template)); + p->next = pending_templates; + pending_templates = p; + p->id = pt; +} + +void +mark_function_instantiated (result, extern_p) + tree result; + int extern_p; +{ + if (DECL_TEMPLATE_INSTANTIATION (result)) + SET_DECL_EXPLICIT_INSTANTIATION (result); + TREE_PUBLIC (result) = 1; + + if (! extern_p) + { + DECL_INTERFACE_KNOWN (result) = 1; + DECL_NOT_REALLY_EXTERN (result) = 1; + } +} + +/* called from the parser. */ +void +do_function_instantiation (declspecs, declarator, storage) + tree declspecs, declarator, storage; +{ + tree decl = grokdeclarator (declarator, declspecs, NORMAL, 0, + NULL_TREE, NULL_TREE); + tree name; + tree fn; + tree result = NULL_TREE; + int extern_p = 0; + + /* If we've already seen this template instance, use it. */ + if (name = DECL_ASSEMBLER_NAME (decl), + fn = IDENTIFIER_GLOBAL_VALUE (name), + fn && DECL_TEMPLATE_INSTANTIATION (fn)) + result = fn; + else if (name = DECL_NAME (decl), fn = IDENTIFIER_GLOBAL_VALUE (name), fn) + { + for (fn = get_first_fn (fn); fn; fn = DECL_CHAIN (fn)) + if (decls_match (fn, decl) + && DECL_DEFER_OUTPUT (fn)) + { + result = fn; + break; + } + else if (TREE_CODE (fn) == TEMPLATE_DECL) + { + int ntparms = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (fn)); + tree *targs = (tree *) malloc (sizeof (tree) * ntparms); + int i, dummy = 0; + i = type_unification (DECL_TEMPLATE_PARMS (fn), targs, + TYPE_ARG_TYPES (TREE_TYPE (fn)), + TYPE_ARG_TYPES (TREE_TYPE (decl)), + &dummy, 0); + if (i == 0) + { + if (result) + cp_error ("ambiguous template instantiation for `%D' requested", decl); + else + result = instantiate_template (fn, targs); + } + free (targs); + } + } + if (! result) + { + cp_error ("no matching template for `%D' found", decl); + return; + } + + if (flag_external_templates) + return; + + if (storage == NULL_TREE) + ; + else if (storage == ridpointers[(int) RID_EXTERN]) + extern_p = 1; + else + cp_error ("storage class `%D' applied to template instantiation", + storage); + mark_function_instantiated (result, extern_p); + repo_template_instantiated (result, extern_p); +} + +void +mark_class_instantiated (t, extern_p) + tree t; + int extern_p; +{ + SET_CLASSTYPE_EXPLICIT_INSTANTIATION (t); + SET_CLASSTYPE_INTERFACE_KNOWN (t); + CLASSTYPE_INTERFACE_ONLY (t) = extern_p; + CLASSTYPE_VTABLE_NEEDS_WRITING (t) = ! extern_p; + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = extern_p; + if (! extern_p) + { + CLASSTYPE_DEBUG_REQUESTED (t) = 1; + rest_of_type_compilation (t, 1); + } +} + +void +do_type_instantiation (name, storage) + tree name, storage; +{ + tree t = TREE_TYPE (name); + int extern_p = 0; + int nomem_p = 0; + + /* With -fexternal-templates, explicit instantiations are treated the same + as implicit ones. */ + if (flag_external_templates) + return; + + if (TYPE_SIZE (t) == NULL_TREE) + { + cp_error ("explicit instantiation of `%#T' before definition of template", + t); + return; + } + + if (storage == NULL_TREE) + /* OK */; + else if (storage == ridpointers[(int) RID_INLINE]) + nomem_p = 1; + else if (storage == ridpointers[(int) RID_EXTERN]) + extern_p = 1; + else + { + cp_error ("storage class `%D' applied to template instantiation", + storage); + extern_p = 0; + } + + /* We've already instantiated this. */ + if (CLASSTYPE_EXPLICIT_INSTANTIATION (t) && ! CLASSTYPE_INTERFACE_ONLY (t) + && extern_p) + return; + + if (! CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) + { + mark_class_instantiated (t, extern_p); + repo_template_instantiated (t, extern_p); + } + + if (nomem_p) + return; + + { + tree tmp; + /* Classes nested in template classes currently don't have an + IDENTIFIER_TEMPLATE--their out-of-line members are handled + by the enclosing template class. Note that there are name + conflict bugs with this approach. */ + tmp = TYPE_IDENTIFIER (t); + if (IDENTIFIER_TEMPLATE (tmp)) + instantiate_member_templates (tmp); + + /* this should really be done by instantiate_member_templates */ + tmp = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0); + for (; tmp; tmp = TREE_CHAIN (tmp)) + if (DECL_TEMPLATE_INSTANTIATION (tmp)) + { + mark_function_instantiated (tmp, extern_p); + repo_template_instantiated (tmp, extern_p); + } + +#if 0 + for (tmp = TYPE_FIELDS (t); tmp; tmp = TREE_CHAIN (tmp)) + { + if (TREE_CODE (tmp) == VAR_DECL) + /* eventually do something */; + } +#endif + + for (tmp = CLASSTYPE_TAGS (t); tmp; tmp = TREE_CHAIN (tmp)) + if (IS_AGGR_TYPE (TREE_VALUE (tmp))) + do_type_instantiation (TYPE_MAIN_DECL (TREE_VALUE (tmp)), storage); + } +} + +tree +create_nested_upt (scope, name) + tree scope, name; +{ + tree t = make_lang_type (UNINSTANTIATED_P_TYPE); + tree d = build_decl (TYPE_DECL, name, t); + + TYPE_NAME (t) = d; + TYPE_VALUES (t) = TYPE_VALUES (scope); + TYPE_CONTEXT (t) = scope; + + pushdecl (d); + return d; +} diff --git a/contrib/gcc/cp/ptree.c b/contrib/gcc/cp/ptree.c new file mode 100644 index 00000000000..ad1480a1ed9 --- /dev/null +++ b/contrib/gcc/cp/ptree.c @@ -0,0 +1,168 @@ +/* Prints out trees in human readable form. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" + +void +print_lang_decl (file, node, indent) + FILE *file; + tree node; + int indent; +{ + if (!DECL_LANG_SPECIFIC (node)) + return; + /* A FIELD_DECL only has the flags structure, which we aren't displaying + anyways. */ + if (DECL_MUTABLE_P (node)) + { + indent_to (file, indent + 3); + fprintf (file, " mutable "); + } + if (TREE_CODE (node) == FIELD_DECL) + return; + indent_to (file, indent + 3); + if (DECL_MAIN_VARIANT (node)) + { + fprintf (file, " decl-main-variant "); + fprintf (file, HOST_PTR_PRINTF, DECL_MAIN_VARIANT (node)); + } + if (DECL_PENDING_INLINE_INFO (node)) + { + fprintf (file, " pending-inline-info "); + fprintf (file, HOST_PTR_PRINTF, DECL_PENDING_INLINE_INFO (node)); + } + if (DECL_TEMPLATE_INFO (node)) + { + fprintf (file, " template-info "); + fprintf (file, HOST_PTR_PRINTF, DECL_TEMPLATE_INFO (node)); + } +} + +void +print_lang_type (file, node, indent) + FILE *file; + register tree node; + int indent; +{ + if (TREE_CODE (node) == TEMPLATE_TYPE_PARM) + { + print_node (file, "tinfo", TYPE_VALUES (node), indent + 4); + return; + } + + if (TREE_CODE (node) == UNINSTANTIATED_P_TYPE) + { + print_node (file, "template", UPT_TEMPLATE (node), indent + 4); + print_node (file, "parameters", UPT_PARMS (node), indent + 4); + return; + } + + if (! (TREE_CODE (node) == RECORD_TYPE + || TREE_CODE (node) == UNION_TYPE)) + return; + + if (!TYPE_LANG_SPECIFIC (node)) + return; + + indent_to (file, indent + 3); + + if (TYPE_NEEDS_CONSTRUCTING (node)) + fputs ( "needs-constructor", file); + if (TYPE_NEEDS_DESTRUCTOR (node)) + fputs (" needs-destructor", file); + if (TYPE_HAS_DESTRUCTOR (node)) + fputs (" ~X()", file); + if (TYPE_HAS_DEFAULT_CONSTRUCTOR (node)) + fputs (" X()", file); + if (TYPE_HAS_CONVERSION (node)) + fputs (" has-type-conversion", file); + if (TYPE_HAS_INT_CONVERSION (node)) + fputs (" has-int-conversion", file); + if (TYPE_HAS_REAL_CONVERSION (node)) + fputs (" has-float-conversion", file); + if (TYPE_HAS_INIT_REF (node)) + { + if (TYPE_HAS_CONST_INIT_REF (node)) + fputs (" X(constX&)", file); + else + fputs (" X(X&)", file); + } + if (TYPE_GETS_NEW (node) & 1) + fputs (" new", file); + if (TYPE_GETS_NEW (node) & 2) + fputs (" new[]", file); + if (TYPE_GETS_DELETE (node) & 1) + fputs (" delete", file); + if (TYPE_GETS_DELETE (node) & 2) + fputs (" delete[]", file); + if (TYPE_HAS_ASSIGNMENT (node)) + fputs (" has=", file); + if (TYPE_HAS_ASSIGN_REF (node)) + fputs (" this=(X&)", file); + if (TYPE_OVERLOADS_METHOD_CALL_EXPR (node)) + fputs (" op->()", file); + if (TYPE_GETS_INIT_AGGR (node)) + fputs (" gets X(X, ...)", file); + if (TYPE_OVERLOADS_CALL_EXPR (node)) + fputs (" op()", file); + if (TYPE_OVERLOADS_ARRAY_REF (node)) + fputs (" op[]", file); + if (TYPE_OVERLOADS_ARROW (node)) + fputs (" op->", file); + if (TYPE_USES_MULTIPLE_INHERITANCE (node)) + fputs (" uses-multiple-inheritance", file); + + if (TREE_CODE (node) == RECORD_TYPE) + { + fprintf (file, " n_parents %d n_ancestors %d", + CLASSTYPE_N_BASECLASSES (node), + CLASSTYPE_N_SUPERCLASSES (node)); + fprintf (file, " use_template=%d", CLASSTYPE_USE_TEMPLATE (node)); + if (CLASSTYPE_INTERFACE_ONLY (node)) + fprintf (file, " interface-only"); + if (CLASSTYPE_INTERFACE_UNKNOWN (node)) + fprintf (file, " interface-unknown"); + print_node (file, "member-functions", CLASSTYPE_METHOD_VEC (node), + indent + 4); + print_node (file, "baselinks", + TYPE_BINFO_BASETYPES (node) ? CLASSTYPE_BASELINK_VEC (node) : NULL_TREE, + indent + 4); + } +} + +void +print_lang_identifier (file, node, indent) + FILE *file; + tree node; + int indent; +{ + print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); + print_node (file, "class", IDENTIFIER_CLASS_VALUE (node), indent + 4); + print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); + print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); + print_node (file, "template", IDENTIFIER_TEMPLATE (node), indent + 4); + print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); + print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); +} diff --git a/contrib/gcc/cp/reno.texi b/contrib/gcc/cp/reno.texi new file mode 100644 index 00000000000..59c3448a039 --- /dev/null +++ b/contrib/gcc/cp/reno.texi @@ -0,0 +1,752 @@ +\input texinfo @c -*- Texinfo -*- +@setfilename reno-1.info + +@ifinfo +@format +START-INFO-DIR-ENTRY +* Reno 1: (reno-1). The GNU C++ Renovation Project, Phase 1. +END-INFO-DIR-ENTRY +@end format +@end ifinfo + +@ifinfo +Copyright @copyright{} 1992, 1993, 1994 Free Software Foundation, Inc. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +@ignore +Permission is granted to process this file through TeX and print the +results, provided the printed document carries a copying permission +notice identical to this one except for the removal of this paragraph +(this paragraph not being relevant to the printed manual). + +@end ignore + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided also that +the entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions. +@end ifinfo + +@setchapternewpage odd +@settitle GNU C++ Renovation Project +@c @smallbook + +@titlepage +@finalout +@title GNU C++ Renovation Project +@subtitle Phase 1.3 +@author Brendan Kehoe, Jason Merrill, +@author Mike Stump, Michael Tiemann +@page + +Edited March, 1994 by Roland Pesch (@code{pesch@@cygnus.com}) +@vskip 0pt plus 1filll +Copyright @copyright{} 1992, 1993, 1994 Free Software Foundation, Inc. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +@ignore +Permission is granted to process this file through Tex and print the +results, provided the printed document carries copying permission +notice identical to this one except for the removal of this paragraph +(this paragraph not being relevant to the printed manual). +@end ignore + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided also that +the entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions. +@end titlepage + +@ifinfo +@node Top +@top @sc{gnu} C++ Renovation Project + +This file describes the goals of the @sc{gnu} C++ Renovation Project, +and its accomplishments to date (as of Phase 1.3). + +It also discusses the remaining divergences from @sc{gnu} C++, and how the +name encoding in @sc{gnu} C++ differs from the sample encoding in +@cite{The Annotated C++ Reference Manual}. +@c This is not a good place to introduce the acronym ARM because it's +@c info-only. + +@menu +* Introduction:: What is the GNU C++ Renovation Project? +* Changes:: Summary of changes since previous GNU C++ releases. +* Plans:: Plans for Reno-2. +* Templates:: The template implementation. +* ANSI:: GNU C++ conformance to ANSI C++. +* Encoding:: Name encoding in GNU C++. +@end menu + +@end ifinfo + +@node Introduction +@chapter Introduction + +As you may remember, @sc{gnu} C++ was the first native-code C++ +compiler available under Unix (December 1987). In November 1988, it was +judged superior to the AT&T compiler in a Unix World review. In 1990 it +won a Sun Observer ``Best-Of'' award. But now, with new requirements +coming out of the @sc{ansi} C++ committee and a growing backlog of bugs, it's +clear that @sc{gnu} C++ needs an overhaul. + +The C++ language has been under development since 1982. It has +evolved significantly since its original incarnation (C with Classes), +addressing many commercial needs and incorporating many lessons +learned as more and more people started using ``object-oriented'' +programming techniques. In 1989, the first X3J16 committee meeting +was held in Washington DC; in the interest of users, C++ was going to +be standardized. + +As C++ has become more popular, more demands have been placed on its +compilers. Some compilers are up to the demands, others are not. +@sc{gnu} C++ was used to prototype several features which have since +been incorporated into the standard, most notably exception handling. +While @sc{gnu} C++ has been an excellent experimental vehicle, it did +not have the resources that AT&T, Borland, or Microsoft have at their +disposal. + +We believe that @sc{gnu} C++ is an important compiler, providing users with +many of the features that have made @sc{gnu} C so popular: fast compilation, +good error messages, innovative features, and full sources that may be +freely redistributed. The purpose of this overhaul, dubbed the @var{@sc{gnu} +C++ Renovation Project}, is to take advantage of the functionality that +@sc{gnu} C++ offers today, to strengthen its base technology, and put it in a +position to remain---as other @sc{gnu} software currently is---the technical +leader in the field. + +This release represents the latest phase of work in strengthening the +compiler on a variety of points. It includes many months of +work concentrated on fixing many of the more egregious bugs that +presented themselves in the compiler recently. +@ignore +@c FIXME-- update? +Nearly 85% of all bugs reported in the period of February to September +of 1992 were fixed as part of the work in the first phase. +@end ignore +In the coming months, we hope to continue expanding and enhancing the +quality and dependability of the industry's only freely redistributable +C++ compiler. + +@node Changes +@chapter Changes in Behavior in @sc{gnu} C++ + +The @sc{gnu} C++ compiler continues to improve and change. A major goal +of our work has been to continue to bring the compiler into compliance +with the draft @sc{ansi} C++ standard, and with @cite{The Annotated C++ +Reference Manual} (the @sc{arm}). This section outlines most of the +user-noticeable changes that might be encountered during the normal +course of use. + +@menu +* Summary of Phase 1.3:: +* Major changes:: +* New features:: +* Enhancements and bug fixes:: +* Problems with debugging:: +@end menu + +@node Summary of Phase 1.3 +@section Summary of Changes in Phase 1.3 + +The bulk of this note discusses the cumulative effects of the @sc{gnu} C++ +Renovation Project to date. The work during its most recent phase (1.3) +had these major effects: + +@itemize @bullet +@item The standard compiler driver @code{g++} is now the faster compiled +version, rather than a shell script. + +@item Nested types work much better; notably, nesting is no longer +restricted to nine levels. + +@item Better @sc{arm} conformance on member access control. + +@item The compiler now always generates default assignment operators +(@samp{operator =}), copy constructors (@samp{X::X(X&)}), and default +constructors (@samp{X::X()}) whenever they are required. + +@item The new draft @sc{ansi} standard keyword @code{mutable} is supported. + +@item @samp{-fansi-overloading} is the default, to comply better with +the @sc{arm} (at some cost in compatibility to earlier versions of @sc{gnu} C++). + +@item More informative error messages. + +@item System include files are automatically treated as if they were +wrapped in @samp{extern "C" @{ @}}. + +@item The new option @samp{-falt-external-templates} provides alternate +template instantiation semantics. + +@item Operator declarations are now checked more strictly. + +@item You can now use template type arguments in the template parameter list. + +@item You can call the destructor for any type. + +@item The compiler source code is better organized. + +@item You can specify where to instantiate template definitions explicitly. +@end itemize + +Much of the work in Phase 1.3 went to elimination of known bugs, as well +as the major items above. + +During the span of Phase 1.3, there were also two changes associated +with the compiler that, while not specifically part of the C++ +Renovation project, may be of interest: + +@itemize @bullet +@item @code{gcov}, a code coverage tool for @sc{gnu cc}, is now available +from Cygnus Support. (@code{gcov} is free software, but the @sc{fsf} has not +yet accepted it.) @xref{Gcov,, @code{gcov}: a Test Coverage Program, +gcc.info, Using GNU CC}, for more information (in Cygnus releases of +that manual). + +@item @sc{gnu} C++ now supports @dfn{signatures}, a language extension to +provide more flexibility in abstract type definitions. @xref{C++ +Signatures,, Type Abstraction using Signatures, gcc.info, Using GNU CC}. +@end itemize + +@node Major changes +@section Major Changes + +This release includes four wholesale rewrites of certain areas of +compiler functionality: + +@enumerate 1 +@item Argument matching. @sc{gnu} C++ is more compliant with the rules +described in Chapter 13, ``Overloading'', of the @sc{arm}. This behavior is +the default, though you can specify it explicitly with +@samp{-fansi-overloading}. For compatibility with earlier releases of +@sc{gnu} C++, specify @samp{-fno-ansi-overloading}; this makes the compiler +behave as it used to with respect to argument matching and name overloading. + +@item Default constructors/destructors. Section 12.8 of the @sc{arm}, ``Copying +Class Objects'', and Section 12.1, ``Constructors'', state that a +compiler must declare such default functions if the user does not +specify them. @sc{gnu} C++ now declares, and generates when necessary, +the defaults for constructors and destructors you might omit. In +particular, assignment operators (@samp{operator =}) behave the same way +whether you define them, or whether the compiler generates them by +default; taking the address of the default @samp{operator =} is now +guaranteed to work. Default copy constructors (@samp{X::X(X&)}) now +function correctly, rather than calling the copy assignment operator for +the base class. Finally, constructors (@samp{X::X()}), as well as +assignment operators and copy constructors, are now available whenever +they are required. + +@c XXX This may be taken out eventually... +@item Binary incompatibility. There are no new binary incompatibilities +in Phase 1.3, but Phase 1.2 introduced two binary incompatibilities with +earlier releases. First, the functionality of @samp{operator +new} and @samp{operator delete} changed. Name encoding +(``mangling'') of virtual table names changed as well. Libraries +built with versions of the compiler earlier than Phase 1.2 must be +compiled with the new compiler. (This includes the Cygnus Q2 +progressive release and the FSF 2.4.5 release.) + +@item New @code{g++} driver. +A new binary @code{g++} compiler driver replaces the shell script. +The new driver executes faster. +@end enumerate + +@node New features +@section New features + +@itemize @bullet +@item +The compiler warns when a class contains only private constructors +or destructors, and has no friends. At the request of some of our +customers, we have added a new option, @samp{-Wctor-dtor-privacy} (on by +default), and its negation, @samp{-Wno-ctor-dtor-privacy}, to control +the emission of this warning. If, for example, you are working towards +making your code compile warning-free, you can use @w{@samp{-Wall +-Wno-ctor-dtor-privacy}} to find the most common warnings. + +@item +There is now a mechanism which controls exactly when templates are +expanded, so that you can reduce memory usage and program size and also +instantiate them exactly once. You can control this mechanism with the +option @samp{-fexternal-templates} and its corresponding negation +@samp{-fno-external-templates}. Without this feature, space consumed by +template instantiations can grow unacceptably in large-scale projects +with many different source files. The default is +@samp{-fno-external-templates}. + +You do not need to use the @samp{-fexternal-templates} option when +compiling a file that does not define and instantiate templates used in +other files, even if those files @emph{are} compiled with +@samp{-fexternal-templates}. The only side effect is an increase in +object size for each file that was compiled without +@samp{-fexternal-templates}. + +When your code is compiled with @samp{-fexternal-templates}, all +template instantiations are external; this requires that the templates +be under the control of @samp{#pragma interface} and @samp{#pragma +implementation}. All instantiations that will be needed should be in +the implementation file; you can do this with a @code{typedef} that +references the instantiation needed. Conversely, when you compile using +the option @samp{-fno-external-templates}, all template instantiations are +explicitly internal. + +@samp{-fexternal-templates} also allows you to finally separate class +template function definitions from their declarations, thus speeding up +compilation times for every file that includes the template declaration. +Now you can have tens or even hundreds of lines in template +declarations, and thousands or tens of thousands of lines in template +definitions, with the definitions only going through the compiler once +instead of once for each source file. It is important to note that you +must remember to externally instantiate @emph{all} templates that are +used from template declarations in interface files. If you forget to do +this, unresolved externals will occur. + +In the example below, the object file generated (@file{example.o}) will +contain the global instantiation for @samp{Stack}. If other types +of @samp{Stack} are needed, they can be added to @file{example.cc} or +placed in a new file, in the same spirit as @file{example.cc}. + +@code{foo.h}: +@smallexample +@group +#pragma interface "foo.h" +template +class Stack @{ + static int statc; + static T statc2; + Stack() @{ @} + virtual ~Stack() @{ @} + int bar(); +@}; +@end group +@end smallexample + +@code{example.cc}: +@smallexample +@group +#pragma implementation "foo.h" +#include "foo.h" + +typedef Stack t; +int Stack::statc; +int Stack::statc2; +int Stack::bar() @{ @} +@end group +@end smallexample + +Note that using @samp{-fexternal-templates} does not reduce memory usage +from completely different instantiations (@samp{Stack} vs. +@samp{Stack}), but only collapses different occurrences +of @samp{Stack} so that only one @samp{Stack} is generated. + +@samp{-falt-external-templates} selects a slight variation in the +semantics described above (incidentally, you need not specify both +options; @samp{-falt-external-templates} implies +@samp{-fexternal-templates}). + +With @samp{-fexternal-templates}, the compiler emits a definition in the +implementation file that includes the header definition, @emph{even if} +instantiation is triggered from a @emph{different} implementation file +(e.g. with a template that uses another template). + +With @samp{-falt-external-templates}, the definition always goes in the +implementation file that triggers instantiation. + +For instance, with these two header files--- + +@example +@exdent @file{a.h}: +#pragma interface +template class A @{ @dots{} @}; + +@exdent @file{b.h}: +#pragma interface +class B @{ @dots{} @}; +void f (A); +@end example + +Under @samp{-fexternal-templates}, the definition of @samp{A} ends up +in the implementation file that includes @file{a.h}. Under +@samp{-falt-external-templates}, the same definition ends up in the +implementation file that includes @file{b.h}. + +@item +You can control explicitly where a template is instantiated, without +having to @emph{use} the template to get an instantiation. + +To instantiate a class template explicitly, write @samp{template +class @var{name}}, where @var{paramvals} is a list of values +for the template parameters. For example, you might write + +@example +template class A +@end example + +Similarly, to instantiate a function template explicitly, write +@samp{template @var{fnsign}} where @var{fnsign} is the particular +function signature you need. For example, you might write + +@example +template void foo (int, int) +@end example + +This syntax for explicit template instantiation agrees with recent +extensions to the draft @sc{ansi} standard. + +@item +The compiler's actions on @sc{ansi}-related warnings and errors have +been further enhanced. The @samp{-pedantic-errors} option produces +error messages in a number of new situations: using @code{return} in a +non-@code{void} function (one returning a value); declaring a local +variable that shadows a parameter (e.g., the function takes an argument +@samp{a}, and has a local variable @samp{a}); and use of the @samp{asm} +keyword. Finally, the compiler by default now issues a warning when +converting from an @code{int} to an enumerated type. This is likely to +cause many new warnings in code that hadn't triggered them before. For +example, when you compile this code, + +@smallexample +@group +enum boolean @{ false, true @}; +void +f () +@{ + boolean x; + + x = 1; //@i{assigning an @code{int} to an @code{enum} now triggers a warning} +@} +@end group +@end smallexample + +@noindent +you should see the warning ``@code{anachronistic conversion from integer +type to enumeral type `boolean'}''. Instead of assigning the value 1, +assign the original enumerated value @samp{true}. +@end itemize + +@node Enhancements and bug fixes +@section Enhancements and bug fixes + +@itemize @bullet +@cindex nested types in template parameters +@item +You can now use nested types in a template parameter list, even if the nested +type is defined within the same class that attempts to use the template. +For example, given a template @code{list}, the following now works: + +@smallexample +struct glyph @{ + @dots{} + struct stroke @{ @dots{} @}; + list l; + @dots{} +@} +@end smallexample + +@cindex function pointers vs template parameters +@item +Function pointers now work in template parameter lists. For +example, you might want to instantiate a parameterized @code{list} class +in terms of a pointer to a function like this: + +@smallexample +list fnlist; +@end smallexample + +@item +@c FIXME! Really no limit? Jason said "deeper than 9" now OK... +Nested types are now handled correctly. In particular, there is no +longer a limit to how deeply you can nest type definitions. + +@item +@sc{gnu} C++ now conforms to the specifications in Chapter 11 of the +@sc{arm}, ``Member Access Control''. + +@item +The @sc{ansi} C++ committee has introduced a new keyword @code{mutable}. +@sc{gnu} C++ supports it. Use @code{mutable} to specify that some +particular members of a @code{const} class are @emph{not} constant. For +example, you can use this to include a cache in a data structure that +otherwise represents a read-only database. + +@item +Error messages now explicitly specify the declaration, type, or +expression that contains an error. + +@item +To avoid copying and editing all system include files during @sc{gnu} +C++ installation, the compiler now automatically recognizes system +include files as C language definitions, as if they were wrapped in +@samp{extern "C" @{ @dots{} @}}. + +@item +The compiler checks operator declarations more strictly. For example, +you may no longer declare an @samp{operator +} with three arguments. + +@item +You can now use template type arguments in the same template +parameter list where the type argument is specified (as well as in the +template body). For example, you may write + +@example +template class A @{ @dots{} @}; +@end example + +@item +Destructors are now available for all types, even built-in ones; for +example, you can call @samp{int::~int}. (Destructors for types like +@code{int} do not actually do anything, but their existence provides a +level of generality that permits smooth template expansion in more +cases.) + +@item +Enumerated types declared inside a class are now handled correctly. + +@item +An argument list for a function may not use an initializer list for its default +value. For example, @w{@samp{void foo ( T x = @{ 1, 2 @} )}} is not permitted. + +@item +A significant amount of work went into improving the ability of the +compiler to act accurately on multiple inheritance and virtual +functions. Virtual function dispatch has been enhanced as well. + +@item +The warning concerning a virtual inheritance environment with a +non-virtual destructor has been disabled, since it is not clear that +such a warning is warranted. + +@item +Until exception handling is fully implemented in the Reno-2 release, use +of the identifiers @samp{catch}, @samp{throw}, or @samp{try} results +in the warning: + +@smallexample +t.C:1: warning: `catch', `throw', and `try' + are all C++ reserved words +@end smallexample + +@item +When giving a warning or error concerning initialization of a member in a +class, the compiler gives the name of the member if it has one. + +@item +Detecting friendship between classes is more accurately checked. + +@item +The syntaxes of @w{@samp{#pragma implementation "file.h"}} and +@samp{#pragma interface} are now more strictly controlled. The compiler +notices (and warns) when any text follows @file{file.h} in the +implementation pragma, or follows the word @samp{interface}. Any such +text is otherwise ignored. + +@item +Trying to declare a template on a variable or type is now considered an +error, not an unimplemented feature. + +@item +When an error occurs involving a template, the compiler attempts to +tell you at which point of instantiation the error occurred, in +addition to noting the line in the template declaration which had the +actual error. + +@item +The symbol names for function templates in the resulting assembly file +are now encoded according to the arguments, rather than just being +emitted as, for example, two definitions of a function @samp{foo}. + +@item +Template member functions that are declared @code{static} no longer +receive a @code{this} pointer. + +@item +Case labels are no longer allowed to have commas to make up their +expressions. + +@item +Warnings concerning the shift count of a left or right shift now tell +you if it was a @samp{left} or @samp{right} shift. + +@item +The compiler now warns when a decimal constant is so large that it +becomes @code{unsigned}. + +@item +Union initializers which are raw constructors are now handled properly. + +@item +The compiler no longer gives incorrect errors when initializing a +union with an empty initializer list. + +@item +Anonymous unions are now correctly used when nested inside a class. + +@item +Anonymous unions declared as static class members are now handled +properly. + +@item +The compiler now notices when a field in a class is declared both as +a type and a non-type. + +@item +The compiler now warns when a user-defined function shadows a +built-in function, rather than emitting an error. + +@item +A conflict between two function declarations now produces an error +regardless of their language context. + +@item +Duplicate definitions of variables with @samp{extern "C"} linkage are no +longer considered in error. (Note in C++ linkage---the default---you may +not have more than one definition of a variable.) + +@item +Referencing a label that is not defined in any function is now an error. + +@item +The syntax for pointers to methods has been improved; there are still +some minor bugs, but a number of cases should now be accepted by the +compiler. + +@item +In error messages, arguments are now numbered starting at 1, instead of +0. Therefore, in the function @samp{void foo (int a, int b)}, the +argument @samp{a} is argument 1, and @samp{b} is argument 2. There is +no longer an argument 0. + +@item +The tag for an enumerator, rather than its value, used as a default +argument is now shown in all error messages. For example, @w{@samp{void +foo (enum x (= true))}} is shown instead of @w{@samp{void foo (enum x (= +1))}}. + +@item +The @samp{__asm__} keyword is now accepted by the C++ front-end. + +@item +Expressions of the form @samp{foo->~Class()} are now handled properly. + +@item +The compiler now gives better warnings for situations which result in +integer overflows (e.g., in storage sizes, enumerators, unary +expressions, etc). + +@item +@code{unsigned} bitfields are now promoted to @code{signed int} if the +field isn't as wide as an @code{int}. + +@item +Declaration and usage of prefix and postfix @samp{operator ++} and +@samp{operator --} are now handled correctly. For example, + +@smallexample +@group +class foo +@{ +public: + operator ++ (); + operator ++ (int); + operator -- (); + operator -- (int); +@}; + +void +f (foo *f) +@{ + f++; // @i{call @code{f->operator++(int)}} + ++f; // @i{call @code{f->operator++()}} + f--; // @i{call @code{f->operator++(int)}} + --f; // @i{call @code{f->operator++()}} +@} +@end group +@end smallexample + +@item +In accordance with @sc{arm} section 10.1.1, ambiguities and dominance are now +handled properly. The rules described in section 10.1.1 are now fully +implemented. + +@end itemize + +@node Problems with debugging +@section Problems with debugging + +Two problems remain with regard to debugging: + +@itemize @bullet +@item +Debugging of anonymous structures on the IBM RS/6000 host is incorrect. + +@item +Symbol table size is overly large due to redundant symbol information; +this can make @code{gdb} coredump under certain circumstances. This +problem is not host-specific. +@end itemize + +@node Plans +@chapter Plans for Reno-2 + +The overall goal for the second phase of the @sc{gnu} C++ Renovation +Project is to bring @sc{gnu} C++ to a new level of reliability, quality, +and competitiveness. As particular elements of this strategy, we intend +to: + +@enumerate 0 +@item +Fully implement @sc{ansi} exception handling. + +@item +With the exception handling, add Runtime Type Identification +(@sc{rtti}), if the @sc{ansi} committee adopts it into the standard. + +@item +Bring the compiler into closer compliance with the @sc{arm} and the draft +@sc{ansi} standard, and document what points in the @sc{arm} we do not yet comply, +or agree, with. + +@item +Add further support for the @sc{dwarf} debugging format. + +@item +Finish the work to make the compiler compliant with @sc{arm} Section 12.6.2, +initializing base classes in declaration order, rather than in the order +that you specify them in a @var{mem-initializer} list. + +@item +Perform a full coverage analysis on the compiler, and weed out unused +code, for a gain in performance and a reduction in the size of the compiler. + +@item +Further improve the multiple inheritance implementation in the +compiler to make it cleaner and more complete. +@end enumerate + +@noindent +As always, we encourage you to make suggestions and ask questions about +@sc{gnu} C++ as a whole, so we can be sure that the end of this project +will bring a compiler that everyone will find essential for C++ and will +meet the needs of the world's C++ community. + +@include templates.texi + +@include gpcompare.texi + +@contents + +@bye diff --git a/contrib/gcc/cp/repo.c b/contrib/gcc/cp/repo.c new file mode 100644 index 00000000000..50fc9f8b727 --- /dev/null +++ b/contrib/gcc/cp/repo.c @@ -0,0 +1,409 @@ +/* Code to maintain a C++ template repository. + Copyright (C) 1995 Free Software Foundation, Inc. + Contributed by Jason Merrill (jason@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* My strategy here is as follows: + + Everything should be emitted in a translation unit where it is used. + The results of the automatic process should be easily reproducible with + explicit code. */ + +#include +#include "config.h" +#include "tree.h" +#include "cp-tree.h" +#include "input.h" +#include "obstack.h" + +extern char * rindex (); +extern char * getenv (); +extern char * getpwd (); + +static tree pending_repo; +static tree original_repo; +static char *repo_name; +static FILE *repo_file; + +extern int flag_use_repository; +extern int errorcount, sorrycount; +extern struct obstack temporary_obstack; +extern struct obstack permanent_obstack; + +#define IDENTIFIER_REPO_USED(NODE) (TREE_LANG_FLAG_3 (NODE)) +#define IDENTIFIER_REPO_CHOSEN(NODE) (TREE_LANG_FLAG_4 (NODE)) + +/* Record the flags used to compile this translation unit. */ + +void +repo_compile_flags (argc, argv) + int argc; + char **argv; +{ +} + +/* If this template has not been seen before, add a note to the repository + saying where the declaration was. This may be used to find the + definition at link time. */ + +void +repo_template_declared (t) + tree t; +{} + +/* Note where the definition of a template lives so that instantiations can + be generated later. */ + +void +repo_template_defined (t) + tree t; +{} + +/* Note where the definition of a class lives to that template + instantiations can use it. */ + +void +repo_class_defined (t) + tree t; +{} + +tree +repo_get_id (t) + tree t; +{ + if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') + { + t = TYPE_BINFO_VTABLE (t); + if (t == NULL_TREE) + return t; + } + return DECL_ASSEMBLER_NAME (t); +} + +/* Note that a template has been used. If we can see the definition, offer + to emit it. */ + +void +repo_template_used (t) + tree t; +{ + tree id; + + if (! flag_use_repository) + return; + + id = repo_get_id (t); + if (id == NULL_TREE) + return; + + if (TREE_CODE_CLASS (TREE_CODE (t)) == 't') + { + if (IDENTIFIER_REPO_CHOSEN (id)) + mark_class_instantiated (t, 0); + } + else if (TREE_CODE_CLASS (TREE_CODE (t)) == 'd') + { + if (IDENTIFIER_REPO_CHOSEN (id)) + mark_function_instantiated (t, 0); + } + else + my_friendly_abort (1); + + if (! IDENTIFIER_REPO_USED (id)) + { + IDENTIFIER_REPO_USED (id) = 1; + pending_repo = perm_tree_cons (NULL_TREE, id, pending_repo); + } +} + +/* Note that the vtable for a class has been used, and offer to emit it. */ + +void +repo_vtable_used (t) + tree t; +{ + if (! flag_use_repository) + return; + + pending_repo = perm_tree_cons (NULL_TREE, t, pending_repo); +} + +/* Note that an inline with external linkage has been used, and offer to + emit it. */ + +void +repo_inline_used (fn) + tree fn; +{ + if (! flag_use_repository) + return; + + /* Member functions of polymorphic classes go with their vtables. */ + if (DECL_FUNCTION_MEMBER_P (fn) && TYPE_VIRTUAL_P (DECL_CLASS_CONTEXT (fn))) + { + repo_vtable_used (DECL_CLASS_CONTEXT (fn)); + return; + } + + pending_repo = perm_tree_cons (NULL_TREE, fn, pending_repo); +} + +/* Note that a particular typeinfo node has been used, and offer to + emit it. */ + +void +repo_tinfo_used (ti) + tree ti; +{ +} + +void +repo_template_instantiated (t, extern_p) + tree t; + int extern_p; +{ + if (! extern_p) + { + tree id = repo_get_id (t); + if (id) + IDENTIFIER_REPO_CHOSEN (id) = 1; + } +} + +static char * +save_string (s, len) + char *s; + int len; +{ + return obstack_copy0 (&temporary_obstack, s, len); +} + +static char * +get_base_filename (filename) + char *filename; +{ + char *p = getenv ("COLLECT_GCC_OPTIONS"); + char *output = 0; + int compiling = 0; + + if (p) + while (*p) + { + char *q = p; + while (*q && *q != ' ') q++; + if (*p == '-' && p[1] == 'o') + { + p += 2; + if (p == q) + { + p++; q++; + if (*q) + while (*q && *q != ' ') q++; + } + + output = save_string (p, q - p); + } + else if (*p == '-' && p[1] == 'c') + compiling = 1; + if (*q) q++; + p = q; + } + + if (compiling && output) + return output; + + if (p && ! compiling) + { + warning ("-frepo must be used with -c"); + flag_use_repository = 0; + return NULL; + } + + p = rindex (filename, '/'); + if (p) + return p+1; + else + return filename; +} + +static void +open_repo_file (filename) + char *filename; +{ + register char *p, *q; + char *s = get_base_filename (filename); + + if (s == NULL) + return; + + p = rindex (s, '/'); + if (! p) + p = s; + p = rindex (p, '.'); + if (! p) + p = s + strlen (s); + + obstack_grow (&permanent_obstack, s, p - s); + repo_name = obstack_copy0 (&permanent_obstack, ".rpo", 4); + + repo_file = fopen (repo_name, "r"); +} + +static char * +afgets (stream) + FILE *stream; +{ + int c; + while ((c = getc (stream)) != EOF && c != '\n') + obstack_1grow (&temporary_obstack, c); + if (obstack_object_size (&temporary_obstack) == 0) + return NULL; + obstack_1grow (&temporary_obstack, '\0'); + return obstack_finish (&temporary_obstack); +} + +void +init_repo (filename) + char *filename; +{ + char *buf; + + if (! flag_use_repository) + return; + + open_repo_file (filename); + + if (repo_file == 0) + return; + + while (buf = afgets (repo_file)) + { + switch (buf[0]) + { + case 'A': + case 'D': + case 'M': + break; + case 'C': + case 'O': + { + tree id = get_identifier (buf + 2); + tree orig; + + if (buf[0] == 'C') + { + IDENTIFIER_REPO_CHOSEN (id) = 1; + orig = integer_one_node; + } + else + orig = NULL_TREE; + + original_repo = perm_tree_cons (orig, id, original_repo); + } + break; + default: + error ("mysterious repository information in %s", repo_name); + } + obstack_free (&temporary_obstack, buf); + } +} + +static void +reopen_repo_file_for_write () +{ + if (repo_file) + fclose (repo_file); + repo_file = fopen (repo_name, "w"); + + if (repo_file == 0) + { + error ("can't create repository information file `%s'", repo_name); + flag_use_repository = 0; + } +} + +/* Emit any pending repos. */ + +void +finish_repo () +{ + tree t; + char *p; + int repo_changed = 0; + + if (! flag_use_repository) + return; + + /* Do we have to write out a new info file? */ + + /* Are there any old templates that aren't used any longer or that are + newly chosen? */ + + for (t = original_repo; t; t = TREE_CHAIN (t)) + { + if (! IDENTIFIER_REPO_USED (TREE_VALUE (t)) + || (! TREE_PURPOSE (t) && IDENTIFIER_REPO_CHOSEN (TREE_VALUE (t)))) + { + repo_changed = 1; + break; + } + IDENTIFIER_REPO_USED (TREE_VALUE (t)) = 0; + } + + /* Are there any templates that are newly used? */ + + if (! repo_changed) + for (t = pending_repo; t; t = TREE_CHAIN (t)) + { + if (IDENTIFIER_REPO_USED (TREE_VALUE (t))) + { + repo_changed = 1; + break; + } + } + + if (! repo_changed || errorcount || sorrycount) + goto out; + + reopen_repo_file_for_write (); + + if (repo_file == 0) + goto out; + + fprintf (repo_file, "M %s\n", main_input_filename); + + p = getpwd (); + fprintf (repo_file, "D %s\n", p); + + p = getenv ("COLLECT_GCC_OPTIONS"); + if (p != 0) + fprintf (repo_file, "A %s\n", p); + + for (t = pending_repo; t; t = TREE_CHAIN (t)) + { + tree val = TREE_VALUE (t); + char type = IDENTIFIER_REPO_CHOSEN (val) ? 'C' : 'O'; + + fprintf (repo_file, "%c %s\n", type, IDENTIFIER_POINTER (val)); + } + + out: + if (repo_file) + fclose (repo_file); +} diff --git a/contrib/gcc/cp/search.c b/contrib/gcc/cp/search.c new file mode 100644 index 00000000000..0ac50a1369d --- /dev/null +++ b/contrib/gcc/cp/search.c @@ -0,0 +1,3524 @@ +/* Breadth-first and depth-first routines for + searching multiple-inheritance lattice for GNU C++. + Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "obstack.h" +#include "flags.h" +#include "rtl.h" +#include "output.h" + +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + +void init_search (); +extern struct obstack *current_obstack; +extern tree abort_fndecl; + +#include "stack.h" + +/* Obstack used for remembering decision points of breadth-first. */ +static struct obstack search_obstack; + +/* Methods for pushing and popping objects to and from obstacks. */ +struct stack_level * +push_stack_level (obstack, tp, size) + struct obstack *obstack; + char *tp; /* Sony NewsOS 5.0 compiler doesn't like void * here. */ + int size; +{ + struct stack_level *stack; + obstack_grow (obstack, tp, size); + stack = (struct stack_level *) ((char*)obstack_next_free (obstack) - size); + obstack_finish (obstack); + stack->obstack = obstack; + stack->first = (tree *) obstack_base (obstack); + stack->limit = obstack_room (obstack) / sizeof (tree *); + return stack; +} + +struct stack_level * +pop_stack_level (stack) + struct stack_level *stack; +{ + struct stack_level *tem = stack; + struct obstack *obstack = tem->obstack; + stack = tem->prev; + obstack_free (obstack, tem); + return stack; +} + +#define search_level stack_level +static struct search_level *search_stack; + +static tree lookup_field_1 (); +static int lookup_fnfields_1 (); +static void dfs_walk (); +static int markedp (); +static void dfs_unmark (); +static void dfs_init_vbase_pointers (); + +static tree vbase_types; +static tree vbase_decl, vbase_decl_ptr; +static tree vbase_decl_ptr_intermediate; +static tree vbase_init_result; + +/* Allocate a level of searching. */ +static struct search_level * +push_search_level (stack, obstack) + struct stack_level *stack; + struct obstack *obstack; +{ + struct search_level tem; + + tem.prev = stack; + return push_stack_level (obstack, (char *)&tem, sizeof (tem)); +} + +/* Discard a level of search allocation. */ +static struct search_level * +pop_search_level (obstack) + struct stack_level *obstack; +{ + register struct search_level *stack = pop_stack_level (obstack); + + return stack; +} + +/* Search memoization. */ +struct type_level +{ + struct stack_level base; + + /* First object allocated in obstack of entries. */ + char *entries; + + /* Number of types memoized in this context. */ + int len; + + /* Type being memoized; save this if we are saving + memoized contexts. */ + tree type; +}; + +/* Obstack used for memoizing member and member function lookup. */ + +static struct obstack type_obstack, type_obstack_entries; +static struct type_level *type_stack; +static tree _vptr_name; + +/* Make things that look like tree nodes, but allocate them + on type_obstack_entries. */ +static int my_tree_node_counter; +static tree my_tree_cons (), my_build_string (); + +extern int flag_memoize_lookups, flag_save_memoized_contexts; + +/* Variables for gathering statistics. */ +static int my_memoized_entry_counter; +static int memoized_fast_finds[2], memoized_adds[2], memoized_fast_rejects[2]; +static int memoized_fields_searched[2]; +static int n_fields_searched; +static int n_calls_lookup_field, n_calls_lookup_field_1; +static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1; +static int n_calls_get_base_type; +static int n_outer_fields_searched; +static int n_contexts_saved; + +/* Local variables to help save memoization contexts. */ +static tree prev_type_memoized; +static struct type_level *prev_type_stack; + +/* This list is used by push_class_decls to know what decls need to + be pushed into class scope. */ +static tree closed_envelopes = NULL_TREE; + +/* Allocate a level of type memoization context. */ +static struct type_level * +push_type_level (stack, obstack) + struct stack_level *stack; + struct obstack *obstack; +{ + struct type_level tem; + + tem.base.prev = stack; + + obstack_finish (&type_obstack_entries); + tem.entries = (char *) obstack_base (&type_obstack_entries); + tem.len = 0; + tem.type = NULL_TREE; + + return (struct type_level *)push_stack_level (obstack, (char *)&tem, sizeof (tem)); +} + +/* Discard a level of type memoization context. */ + +static struct type_level * +pop_type_level (stack) + struct type_level *stack; +{ + obstack_free (&type_obstack_entries, stack->entries); + return (struct type_level *)pop_stack_level ((struct stack_level *)stack); +} + +/* Make something that looks like a TREE_LIST, but + do it on the type_obstack_entries obstack. */ +static tree +my_tree_cons (purpose, value, chain) + tree purpose, value, chain; +{ + tree p = (tree)obstack_alloc (&type_obstack_entries, sizeof (struct tree_list)); + ++my_tree_node_counter; + TREE_TYPE (p) = NULL_TREE; + ((HOST_WIDE_INT *)p)[3] = 0; + TREE_SET_CODE (p, TREE_LIST); + TREE_PURPOSE (p) = purpose; + TREE_VALUE (p) = value; + TREE_CHAIN (p) = chain; + return p; +} + +static tree +my_build_string (str) + char *str; +{ + tree p = (tree)obstack_alloc (&type_obstack_entries, sizeof (struct tree_string)); + ++my_tree_node_counter; + TREE_TYPE (p) = 0; + ((int *)p)[3] = 0; + TREE_SET_CODE (p, STRING_CST); + TREE_STRING_POINTER (p) = str; + TREE_STRING_LENGTH (p) = strlen (str); + return p; +} + +/* Memoizing machinery to make searches for multiple inheritance + reasonably efficient. */ +#define MEMOIZE_HASHSIZE 8 +typedef struct memoized_entry +{ + struct memoized_entry *chain; + int uid; + tree data_members[MEMOIZE_HASHSIZE]; + tree function_members[MEMOIZE_HASHSIZE]; +} *ME; + +#define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain) +#define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid) +#define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX]) +#define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX]) +/* The following is probably a lousy hash function. */ +#define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1)) + +static struct memoized_entry * +my_new_memoized_entry (chain) + struct memoized_entry *chain; +{ + struct memoized_entry *p = + (struct memoized_entry *)obstack_alloc (&type_obstack_entries, + sizeof (struct memoized_entry)); + bzero ((char *) p, sizeof (struct memoized_entry)); + MEMOIZED_CHAIN (p) = chain; + MEMOIZED_UID (p) = ++my_memoized_entry_counter; + return p; +} + +/* Make an entry in the memoized table for type TYPE + that the entry for NAME is FIELD. */ + +tree +make_memoized_table_entry (type, name, function_p) + tree type, name; + int function_p; +{ + int index = MEMOIZED_HASH_FN (name); + tree entry, *prev_entry; + + memoized_adds[function_p] += 1; + if (CLASSTYPE_MTABLE_ENTRY (type) == 0) + { + obstack_ptr_grow (&type_obstack, type); + obstack_blank (&type_obstack, sizeof (struct memoized_entry *)); + CLASSTYPE_MTABLE_ENTRY (type) = (char *)my_new_memoized_entry ((struct memoized_entry *)0); + type_stack->len++; + if (type_stack->len * 2 >= type_stack->base.limit) + my_friendly_abort (88); + } + if (function_p) + prev_entry = &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type), index); + else + prev_entry = &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), index); + + entry = my_tree_cons (name, NULL_TREE, *prev_entry); + *prev_entry = entry; + + /* Don't know the error message to give yet. */ + TREE_TYPE (entry) = error_mark_node; + + return entry; +} + +/* When a new function or class context is entered, we build + a table of types which have been searched for members. + The table is an array (obstack) of types. When a type is + entered into the obstack, its CLASSTYPE_MTABLE_ENTRY + field is set to point to a new record, of type struct memoized_entry. + + A non-NULL TREE_TYPE of the entry contains an access control error message. + + The slots for the data members are arrays of tree nodes. + These tree nodes are lists, with the TREE_PURPOSE + of this list the known member name, and the TREE_VALUE + as the FIELD_DECL for the member. + + For member functions, the TREE_PURPOSE is again the + name of the member functions for that class, + and the TREE_VALUE of the list is a pairs + whose TREE_PURPOSE is a member functions of this name, + and whose TREE_VALUE is a list of known argument lists this + member function has been called with. The TREE_TYPE of the pair, + if non-NULL, is an error message to print. */ + +/* Tell search machinery that we are entering a new context, and + to update tables appropriately. + + TYPE is the type of the context we are entering, which can + be NULL_TREE if we are not in a class's scope. + + USE_OLD, if nonzero tries to use previous context. */ +void +push_memoized_context (type, use_old) + tree type; + int use_old; +{ + int len; + tree *tem; + + if (prev_type_stack) + { + if (use_old && prev_type_memoized == type) + { +#ifdef GATHER_STATISTICS + n_contexts_saved++; +#endif + type_stack = prev_type_stack; + prev_type_stack = 0; + + tem = &type_stack->base.first[0]; + len = type_stack->len; + while (len--) + CLASSTYPE_MTABLE_ENTRY (tem[len*2]) = (char *)tem[len*2+1]; + return; + } + /* Otherwise, need to pop old stack here. */ + type_stack = pop_type_level (prev_type_stack); + prev_type_memoized = 0; + prev_type_stack = 0; + } + + type_stack = push_type_level ((struct stack_level *)type_stack, + &type_obstack); + type_stack->type = type; +} + +/* Tell search machinery that we have left a context. + We do not currently save these contexts for later use. + If we wanted to, we could not use pop_search_level, since + poping that level allows the data we have collected to + be clobbered; a stack of obstacks would be needed. */ +void +pop_memoized_context (use_old) + int use_old; +{ + int len; + tree *tem = &type_stack->base.first[0]; + + if (! flag_save_memoized_contexts) + use_old = 0; + else if (use_old) + { + len = type_stack->len; + while (len--) + tem[len*2+1] = (tree)CLASSTYPE_MTABLE_ENTRY (tem[len*2]); + + prev_type_stack = type_stack; + prev_type_memoized = type_stack->type; + } + + if (flag_memoize_lookups) + { + len = type_stack->len; + while (len--) + CLASSTYPE_MTABLE_ENTRY (tem[len*2]) + = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem[len*2])); + } + if (! use_old) + type_stack = pop_type_level (type_stack); + else + type_stack = (struct type_level *)type_stack->base.prev; +} + +/* Get a virtual binfo that is found inside BINFO's hierarchy that is + the same type as the type given in PARENT. To be optimal, we want + the first one that is found by going through the least number of + virtual bases. DEPTH should be NULL_PTR. */ +static tree +get_vbase (parent, binfo, depth) + tree parent, binfo; + unsigned int *depth; +{ + tree binfos; + int i, n_baselinks; + tree rval = NULL_TREE; + + if (depth == 0) + { + unsigned int d = (unsigned int)-1; + return get_vbase (parent, binfo, &d); + } + + if (BINFO_TYPE (binfo) == parent && TREE_VIA_VIRTUAL (binfo)) + { + *depth = 0; + return binfo; + } + + *depth = *depth - 1; + + binfos = BINFO_BASETYPES (binfo); + n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Process base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree nrval; + + if (*depth == 0) + break; + + nrval = get_vbase (parent, base_binfo, depth); + if (nrval) + rval = nrval; + } + *depth = *depth+1; + return rval; +} + +/* Convert EXPR to a virtual base class of type TYPE. We know that + EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that + the type of what expr points to has a virtual base of type TYPE. */ +tree +convert_pointer_to_vbase (type, expr) + tree type; + tree expr; +{ + tree vb = get_vbase (type, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr))), NULL_PTR); + return convert_pointer_to_real (vb, expr); +} + +/* This is the newer recursive depth first search routine. */ +#if 0 /* unused */ +/* Return non-zero if PARENT is directly derived from TYPE. By directly + we mean it's only one step up the inheritance lattice. We check this + by walking horizontally across the types that TYPE directly inherits + from, to see if PARENT is among them. This is used by get_binfo and + by compute_access. */ +static int +immediately_derived (parent, type) + tree parent, type; +{ + if (TYPE_BINFO (type)) + { + tree binfos = BINFO_BASETYPES (TYPE_BINFO (type)); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + if (parent == BINFO_TYPE (base_binfo)) + return 1; + } + } + return 0; +} +#endif + +/* Check whether the type given in BINFO is derived from PARENT. If + it isn't, return 0. If it is, but the derivation is MI-ambiguous + AND protect != 0, emit an error message and return error_mark_node. + + Otherwise, if TYPE is derived from PARENT, return the actual base + information, unless a one of the protection violations below + occurs, in which case emit an error message and return error_mark_node. + + If PROTECT is 1, then check if access to a public field of PARENT + would be private. Also check for ambiguity. */ + +tree +get_binfo (parent, binfo, protect) + register tree parent, binfo; + int protect; +{ + tree type; + int dist; + tree rval = NULL_TREE; + + if (TREE_CODE (parent) == TREE_VEC) + parent = BINFO_TYPE (parent); + else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent))) + my_friendly_abort (89); + + if (TREE_CODE (binfo) == TREE_VEC) + type = BINFO_TYPE (binfo); + else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo))) + type = binfo; + else + my_friendly_abort (90); + + dist = get_base_distance (parent, binfo, protect, &rval); + + if (dist == -3) + { + cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance", + parent, type); + return error_mark_node; + } + else if (dist == -2 && protect) + { + cp_error ("type `%T' is ambiguous base class for type `%T'", parent, + type); + return error_mark_node; + } + + return rval; +} + +/* This is the newer depth first get_base_distance routine. */ +static int +get_base_distance_recursive (binfo, depth, is_private, basetype_path, rval, + rval_private_ptr, new_binfo_ptr, parent, path_ptr, + protect, via_virtual_ptr, via_virtual) + tree binfo, basetype_path, *new_binfo_ptr, parent, *path_ptr; + int *rval_private_ptr, depth, is_private, rval, protect, *via_virtual_ptr, + via_virtual; +{ + tree binfos; + int i, n_baselinks; + + if (BINFO_TYPE (binfo) == parent || binfo == parent) + { + if (rval == -1) + { + rval = depth; + *rval_private_ptr = is_private; + *new_binfo_ptr = binfo; + *via_virtual_ptr = via_virtual; + } + else + { + int same_object = (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr), + BINFO_OFFSET (binfo)) + && *via_virtual_ptr && via_virtual); + + if (*via_virtual_ptr && via_virtual==0) + { + *rval_private_ptr = is_private; + *new_binfo_ptr = binfo; + *via_virtual_ptr = via_virtual; + } + else if (same_object) + { + if (*rval_private_ptr && ! is_private) + { + *rval_private_ptr = is_private; + *new_binfo_ptr = binfo; + *via_virtual_ptr = via_virtual; + } + return rval; + } + + rval = -2; + } + return rval; + } + + binfos = BINFO_BASETYPES (binfo); + n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + depth += 1; + + /* Process base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + /* Find any specific instance of a virtual base, when searching with + a binfo... */ + if (BINFO_MARKED (base_binfo) == 0 || TREE_CODE (parent) == TREE_VEC) + { + int via_private + = (protect + && (is_private + || (!TREE_VIA_PUBLIC (base_binfo) + && !is_friend (BINFO_TYPE (binfo), current_scope ())))); + int this_virtual = via_virtual || TREE_VIA_VIRTUAL (base_binfo); + int was; + + /* When searching for a non-virtual, we cannot mark + virtually found binfos. */ + if (! this_virtual) + SET_BINFO_MARKED (base_binfo); + +#define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private) + + was = WATCH_VALUES (rval, *via_virtual_ptr); + rval = get_base_distance_recursive (base_binfo, depth, via_private, + binfo, rval, rval_private_ptr, + new_binfo_ptr, parent, path_ptr, + protect, via_virtual_ptr, + this_virtual); + /* watch for updates; only update if path is good. */ + if (path_ptr && WATCH_VALUES (rval, *via_virtual_ptr) != was) + BINFO_INHERITANCE_CHAIN (base_binfo) = binfo; + if (rval == -2 && *via_virtual_ptr == 0) + return rval; + +#undef WATCH_VALUES + + } + } + + return rval; +} + +/* Return the number of levels between type PARENT and the type given + in BINFO, following the leftmost path to PARENT not found along a + virtual path, if there are no real PARENTs (all come from virtual + base classes), then follow the leftmost path to PARENT. + + Return -1 if TYPE is not derived from PARENT. + Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is + non-negative. + Return -3 if PARENT is private to TYPE, and PROTECT is non-zero. + + If PATH_PTR is non-NULL, then also build the list of types + from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC + set. + + PARENT can also be a binfo, in which case that exact parent is found + and no other. convert_pointer_to_real uses this functionality. + + If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */ + +int +get_base_distance (parent, binfo, protect, path_ptr) + register tree parent, binfo; + int protect; + tree *path_ptr; +{ + int rval; + int rval_private = 0; + tree type; + tree new_binfo = NULL_TREE; + int via_virtual; + int watch_access = protect; + + if (TREE_CODE (parent) != TREE_VEC) + parent = TYPE_MAIN_VARIANT (parent); + + if (TREE_CODE (binfo) == TREE_VEC) + type = BINFO_TYPE (binfo); + else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo))) + { + type = binfo; + binfo = TYPE_BINFO (type); + + if (path_ptr) + BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE; + } + else + my_friendly_abort (92); + + if (parent == type || parent == binfo) + { + /* If the distance is 0, then we don't really need + a path pointer, but we shouldn't let garbage go back. */ + if (path_ptr) + *path_ptr = binfo; + return 0; + } + + if (path_ptr) + watch_access = 1; + + rval = get_base_distance_recursive (binfo, 0, 0, NULL_TREE, -1, + &rval_private, &new_binfo, parent, + path_ptr, watch_access, &via_virtual, 0); + + dfs_walk (binfo, dfs_unmark, markedp); + + /* Access restrictions don't count if we found an ambiguous basetype. */ + if (rval == -2 && protect >= 0) + rval_private = 0; + + if (rval && protect && rval_private) + return -3; + + /* find real virtual base classes. */ + if (rval == -1 && TREE_CODE (parent) == TREE_VEC + && parent == binfo_member (BINFO_TYPE (parent), + CLASSTYPE_VBASECLASSES (type))) + { + BINFO_INHERITANCE_CHAIN (parent) = binfo; + new_binfo = parent; + rval = 1; + } + + if (path_ptr) + *path_ptr = new_binfo; + return rval; +} + +/* Search for a member with name NAME in a multiple inheritance lattice + specified by TYPE. If it does not exist, return NULL_TREE. + If the member is ambiguously referenced, return `error_mark_node'. + Otherwise, return the FIELD_DECL. */ + +/* Do a 1-level search for NAME as a member of TYPE. The caller must + figure out whether it can access this field. (Since it is only one + level, this is reasonable.) */ +static tree +lookup_field_1 (type, name) + tree type, name; +{ + register tree field = TYPE_FIELDS (type); + +#ifdef GATHER_STATISTICS + n_calls_lookup_field_1++; +#endif + while (field) + { +#ifdef GATHER_STATISTICS + n_fields_searched++; +#endif + if (DECL_NAME (field) == NULL_TREE + && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + { + tree temp = lookup_field_1 (TREE_TYPE (field), name); + if (temp) + return temp; + } + if (DECL_NAME (field) == name) + { + if ((TREE_CODE(field) == VAR_DECL || TREE_CODE(field) == CONST_DECL) + && DECL_ASSEMBLER_NAME (field) != NULL) + GNU_xref_ref(current_function_decl, + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field))); + return field; + } + field = TREE_CHAIN (field); + } + /* Not found. */ + if (name == _vptr_name) + { + /* Give the user what s/he thinks s/he wants. */ + if (TYPE_VIRTUAL_P (type)) + return CLASSTYPE_VFIELD (type); + } + return NULL_TREE; +} + +/* There are a number of cases we need to be aware of here: + current_class_type current_function_decl + * global NULL NULL + * fn-local NULL SET + * class-local SET NULL + * class->fn SET SET + * fn->class SET SET + + Those last two make life interesting. If we're in a function which is + itself inside a class, we need decls to go into the fn's decls (our + second case below). But if we're in a class and the class itself is + inside a function, we need decls to go into the decls for the class. To + achieve this last goal, we must see if, when both current_class_decl and + current_function_decl are set, the class was declared inside that + function. If so, we know to put the decls into the class's scope. */ + +tree +current_scope () +{ + if (current_function_decl == NULL_TREE) + return current_class_type; + if (current_class_type == NULL_TREE) + return current_function_decl; + if (DECL_CLASS_CONTEXT (current_function_decl) == current_class_type) + return current_function_decl; + + return current_class_type; +} + +/* Compute the access of FIELD. This is done by computing + the access available to each type in BASETYPES (which comes + as a list of [via_public/basetype] in reverse order, namely base + class before derived class). The first one which defines a + access defines the access for the field. Otherwise, the + access of the field is that which occurs normally. + + Uses global variables CURRENT_CLASS_TYPE and + CURRENT_FUNCTION_DECL to use friend relationships + if necessary. + + This will be static when lookup_fnfield comes into this file. + + access_public means that the field can be accessed by the current lexical + scope. + + access_protected means that the field cannot be accessed by the current + lexical scope because it is protected. + + access_private means that the field cannot be accessed by the current + lexical scope because it is private. */ + +#if 0 +#define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public +#define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected +#define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private +#else +#define PUBLIC_RETURN return access_public +#define PROTECTED_RETURN return access_protected +#define PRIVATE_RETURN return access_private +#endif + +#if 0 +/* Disabled with DECL_PUBLIC &c. */ +static tree previous_scope = NULL_TREE; +#endif + +enum access_type +compute_access (basetype_path, field) + tree basetype_path, field; +{ + enum access_type access; + tree types; + tree context; + int protected_ok, via_protected; + extern int flag_access_control; +#if 1 + /* Replaces static decl above. */ + tree previous_scope; +#endif + int static_mem = + ((TREE_CODE (field) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (field)) + || (TREE_CODE (field) != FUNCTION_DECL && TREE_STATIC (field))); + + if (! flag_access_control) + return access_public; + + /* The field lives in the current class. */ + if (BINFO_TYPE (basetype_path) == current_class_type) + return access_public; + +#if 0 + /* Disabled until pushing function scope clears these out. If ever. */ + /* Make these special cases fast. */ + if (current_scope () == previous_scope) + { + if (DECL_PUBLIC (field)) + return access_public; + if (DECL_PROTECTED (field)) + return access_protected; + if (DECL_PRIVATE (field)) + return access_private; + } +#endif + + /* We don't currently support access control on nested types. */ + if (TREE_CODE (field) == TYPE_DECL) + return access_public; + + previous_scope = current_scope (); + + context = DECL_CLASS_CONTEXT (field); + if (context == NULL_TREE) + context = DECL_CONTEXT (field); + + /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT + slot set to the union type rather than the record type containing + the anonymous union. In this case, DECL_FIELD_CONTEXT is correct. */ + if (context && TREE_CODE (context) == UNION_TYPE + && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context))) + context = DECL_FIELD_CONTEXT (field); + + /* Virtual function tables are never private. But we should know that + we are looking for this, and not even try to hide it. */ + if (DECL_NAME (field) && VFIELD_NAME_P (DECL_NAME (field)) == 1) + PUBLIC_RETURN; + + /* Member found immediately within object. */ + if (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE) + { + /* Are we (or an enclosing scope) friends with the class that has + FIELD? */ + if (is_friend (context, previous_scope)) + PUBLIC_RETURN; + + /* If it's private, it's private, you letch. */ + if (TREE_PRIVATE (field)) + PRIVATE_RETURN; + + /* ARM $11.5. Member functions of a derived class can access the + non-static protected members of a base class only through a + pointer to the derived class, a reference to it, or an object + of it. Also any subsequently derived classes also have + access. */ + else if (TREE_PROTECTED (field)) + { + if (current_class_type + && static_mem + && ACCESSIBLY_DERIVED_FROM_P (context, current_class_type)) + PUBLIC_RETURN; + else + PROTECTED_RETURN; + } + else + PUBLIC_RETURN; + } + + /* must reverse more than one element */ + basetype_path = reverse_path (basetype_path); + types = basetype_path; + via_protected = 0; + access = access_default; + protected_ok = static_mem && current_class_type + && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types), current_class_type); + + while (1) + { + tree member; + tree binfo = types; + tree type = BINFO_TYPE (binfo); + int private_ok = 0; + + /* Friends of a class can see protected members of its bases. + Note that classes are their own friends. */ + if (is_friend (type, previous_scope)) + { + protected_ok = 1; + private_ok = 1; + } + + member = purpose_member (type, DECL_ACCESS (field)); + if (member) + { + access = (enum access_type) TREE_VALUE (member); + break; + } + + types = BINFO_INHERITANCE_CHAIN (types); + + /* If the next type was VIA_PROTECTED, then fields of all remaining + classes past that one are *at least* protected. */ + if (types) + { + if (TREE_VIA_PROTECTED (types)) + via_protected = 1; + else if (! TREE_VIA_PUBLIC (types) && ! private_ok) + { + access = access_private; + break; + } + } + else + break; + } + reverse_path (basetype_path); + + /* No special visibilities apply. Use normal rules. */ + + if (access == access_default) + { + if (is_friend (context, previous_scope)) + access = access_public; + else if (TREE_PRIVATE (field)) + access = access_private; + else if (TREE_PROTECTED (field)) + access = access_protected; + else + access = access_public; + } + + if (access == access_public && via_protected) + access = access_protected; + + if (access == access_protected && protected_ok) + access = access_public; + +#if 0 + if (access == access_public) + DECL_PUBLIC (field) = 1; + else if (access == access_protected) + DECL_PROTECTED (field) = 1; + else if (access == access_private) + DECL_PRIVATE (field) = 1; + else my_friendly_abort (96); +#endif + return access; +} + +/* Routine to see if the sub-object denoted by the binfo PARENT can be + found as a base class and sub-object of the object denoted by + BINFO. This routine relies upon binfos not being shared, except + for binfos for virtual bases. */ +static int +is_subobject_of_p (parent, binfo) + tree parent, binfo; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + if (parent == binfo) + return 1; + + /* Process and/or queue base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + if (TREE_VIA_VIRTUAL (base_binfo)) + base_binfo = TYPE_BINFO (BINFO_TYPE (base_binfo)); + if (is_subobject_of_p (parent, base_binfo)) + return 1; + } + return 0; +} + +/* See if a one FIELD_DECL hides another. This routine is meant to + correspond to ANSI working paper Sept 17, 1992 10p4. The two + binfos given are the binfos corresponding to the particular places + the FIELD_DECLs are found. This routine relies upon binfos not + being shared, except for virtual bases. */ +static int +hides (hider_binfo, hidee_binfo) + tree hider_binfo, hidee_binfo; +{ + /* hider hides hidee, if hider has hidee as a base class and + the instance of hidee is a sub-object of hider. The first + part is always true is the second part is true. + + When hider and hidee are the same (two ways to get to the exact + same member) we consider either one as hiding the other. */ + return is_subobject_of_p (hidee_binfo, hider_binfo); +} + +/* Very similar to lookup_fnfields_1 but it ensures that at least one + function was declared inside the class given by TYPE. It really should + only return functions that match the given TYPE. */ +static int +lookup_fnfields_here (type, name) + tree type, name; +{ + int index = lookup_fnfields_1 (type, name); + tree fndecls; + + if (index <= 0) + return index; + fndecls = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), index); + while (fndecls) + { + if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (fndecls)) + == TYPE_MAIN_VARIANT (type)) + return index; + fndecls = TREE_CHAIN (fndecls); + } + return -1; +} + +/* Look for a field named NAME in an inheritance lattice dominated by + XBASETYPE. PROTECT is zero if we can avoid computing access + information, otherwise it is 1. WANT_TYPE is 1 when we should only + return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE. + + It was not clear what should happen if WANT_TYPE is set, and an + ambiguity is found. At least one use (lookup_name) to not see + the error. */ +tree +lookup_field (xbasetype, name, protect, want_type) + register tree xbasetype, name; + int protect, want_type; +{ + int head = 0, tail = 0; + tree rval, rval_binfo = NULL_TREE, rval_binfo_h; + tree type, basetype_chain, basetype_path; + enum access_type this_v = access_default; + tree entry, binfo, binfo_h; + enum access_type own_access = access_default; + int vbase_name_p = VBASE_NAME_P (name); + + /* rval_binfo is the binfo associated with the found member, note, + this can be set with useful information, even when rval is not + set, because it must deal with ALL members, not just non-function + members. It is used for ambiguity checking and the hidden + checks. Whereas rval is only set if a proper (not hidden) + non-function member is found. */ + + /* rval_binfo_h and binfo_h are binfo values used when we perform the + hiding checks, as virtual base classes may not be shared. The strategy + is we always go into the the binfo hierarchy owned by TYPE_BINFO of + virtual base classes, as we cross virtual base class lines. This way + we know that binfo of a virtual base class will always == itself when + found along any line. (mrs) */ + + char *errstr = 0; + + /* Set this to nonzero if we don't know how to compute + accurate error messages for access control. */ + int index = MEMOIZED_HASH_FN (name); + + /* If we are looking for a constructor in a templated type, use the + unspecialized name, as that is how we store it. */ + if (IDENTIFIER_TEMPLATE (name)) + name = constructor_name (name); + + if (TREE_CODE (xbasetype) == TREE_VEC) + { + type = BINFO_TYPE (xbasetype); + basetype_path = xbasetype; + } + else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype))) + { + type = xbasetype; + basetype_path = TYPE_BINFO (xbasetype); + BINFO_VIA_PUBLIC (basetype_path) = 1; + BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE; + } + else my_friendly_abort (97); + + if (CLASSTYPE_MTABLE_ENTRY (type)) + { + tree tem = MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), index); + + while (tem && TREE_PURPOSE (tem) != name) + { + memoized_fields_searched[0]++; + tem = TREE_CHAIN (tem); + } + if (tem) + { + if (protect && TREE_TYPE (tem)) + { + error (TREE_STRING_POINTER (TREE_TYPE (tem)), + IDENTIFIER_POINTER (name), + TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem)))); + return error_mark_node; + } + if (TREE_VALUE (tem) == NULL_TREE) + memoized_fast_rejects[0] += 1; + else + memoized_fast_finds[0] += 1; + return TREE_VALUE (tem); + } + } + +#ifdef GATHER_STATISTICS + n_calls_lookup_field++; +#endif + if (protect && flag_memoize_lookups && ! global_bindings_p ()) + entry = make_memoized_table_entry (type, name, 0); + else + entry = 0; + + rval = lookup_field_1 (type, name); + + if (rval || lookup_fnfields_here (type, name) >= 0) + { + if (rval) + { + if (want_type) + { + if (TREE_CODE (rval) != TYPE_DECL) + { + rval = purpose_member (name, CLASSTYPE_TAGS (type)); + if (rval) + rval = TYPE_MAIN_DECL (TREE_VALUE (rval)); + } + } + else + { + if (TREE_CODE (rval) == TYPE_DECL + && lookup_fnfields_here (type, name) >= 0) + rval = NULL_TREE; + } + } + + if (protect && rval) + { + if (TREE_PRIVATE (rval) | TREE_PROTECTED (rval)) + this_v = compute_access (basetype_path, rval); + if (TREE_CODE (rval) == CONST_DECL) + { + if (this_v == access_private) + errstr = "enum `%D' is a private value of class `%T'"; + else if (this_v == access_protected) + errstr = "enum `%D' is a protected value of class `%T'"; + } + else + { + if (this_v == access_private) + errstr = "member `%D' is a private member of class `%T'"; + else if (this_v == access_protected) + errstr = "member `%D' is a protected member of class `%T'"; + } + } + + if (entry) + { + if (errstr) + { + /* This depends on behavior of lookup_field_1! */ + tree error_string = my_build_string (errstr); + TREE_TYPE (entry) = error_string; + } + else + { + /* Let entry know there is no problem with this access. */ + TREE_TYPE (entry) = NULL_TREE; + } + TREE_VALUE (entry) = rval; + } + + if (errstr && protect) + { + cp_error (errstr, name, type); + return error_mark_node; + } + return rval; + } + + basetype_chain = build_tree_list (NULL_TREE, basetype_path); + TREE_VIA_PUBLIC (basetype_chain) = TREE_VIA_PUBLIC (basetype_path); + TREE_VIA_PROTECTED (basetype_chain) = TREE_VIA_PROTECTED (basetype_path); + TREE_VIA_VIRTUAL (basetype_chain) = TREE_VIA_VIRTUAL (basetype_path); + + /* The ambiguity check relies upon breadth first searching. */ + + search_stack = push_search_level (search_stack, &search_obstack); + binfo = basetype_path; + binfo_h = binfo; + + while (1) + { + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + tree nval; + + /* Process and/or queue base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + if (BINFO_FIELDS_MARKED (base_binfo) == 0) + { + tree btypes; + + SET_BINFO_FIELDS_MARKED (base_binfo); + btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain); + TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo); + TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo); + TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo); + if (TREE_VIA_VIRTUAL (base_binfo)) + btypes = tree_cons (NULL_TREE, + TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))), + btypes); + else + btypes = tree_cons (NULL_TREE, + TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i), + btypes); + obstack_ptr_grow (&search_obstack, btypes); + tail += 1; + if (tail >= search_stack->limit) + my_friendly_abort (98); + } + } + + /* Process head of queue, if one exists. */ + if (head >= tail) + break; + + basetype_chain = search_stack->first[head++]; + binfo_h = TREE_VALUE (basetype_chain); + basetype_chain = TREE_CHAIN (basetype_chain); + basetype_path = TREE_VALUE (basetype_chain); + if (TREE_CHAIN (basetype_chain)) + BINFO_INHERITANCE_CHAIN (basetype_path) = TREE_VALUE (TREE_CHAIN (basetype_chain)); + else + BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE; + + binfo = basetype_path; + type = BINFO_TYPE (binfo); + + /* See if we can find NAME in TYPE. If RVAL is nonzero, + and we do find NAME in TYPE, verify that such a second + sighting is in fact valid. */ + + nval = lookup_field_1 (type, name); + + if (nval || lookup_fnfields_here (type, name)>=0) + { + if (nval && nval == rval && SHARED_MEMBER_P (nval)) + { + /* This is ok, the member found is the same [class.ambig] */ + } + else if (rval_binfo && hides (rval_binfo_h, binfo_h)) + { + /* This is ok, the member found is in rval_binfo, not + here (binfo). */ + } + else if (rval_binfo==NULL_TREE || hides (binfo_h, rval_binfo_h)) + { + /* This is ok, the member found is here (binfo), not in + rval_binfo. */ + if (nval) + { + rval = nval; + if (entry || protect) + this_v = compute_access (basetype_path, rval); + /* These may look ambiguous, but they really are not. */ + if (vbase_name_p) + break; + } + else + { + /* Undo finding it before, as something else hides it. */ + rval = NULL_TREE; + } + rval_binfo = binfo; + rval_binfo_h = binfo_h; + } + else + { + /* This is ambiguous. */ + errstr = "request for member `%D' is ambiguous"; + protect = 2; + break; + } + } + } + { + tree *tp = search_stack->first; + tree *search_tail = tp + tail; + + if (entry) + TREE_VALUE (entry) = rval; + + if (rval_binfo) + { + type = BINFO_TYPE (rval_binfo); + + if (rval) + { + if (want_type) + { + if (TREE_CODE (rval) != TYPE_DECL) + { + rval = purpose_member (name, CLASSTYPE_TAGS (type)); + if (rval) + rval = TYPE_MAIN_DECL (TREE_VALUE (rval)); + } + } + else + { + if (TREE_CODE (rval) == TYPE_DECL + && lookup_fnfields_here (type, name) >= 0) + rval = NULL_TREE; + } + } + } + + if (rval == NULL_TREE) + errstr = 0; + + /* If this FIELD_DECL defines its own access level, deal with that. */ + if (rval && errstr == 0 + && ((protect&1) || entry) + && DECL_LANG_SPECIFIC (rval) + && DECL_ACCESS (rval)) + { + while (tp < search_tail) + { + /* If is possible for one of the derived types on the path to + have defined special access for this field. Look for such + declarations and report an error if a conflict is found. */ + enum access_type new_v; + + if (this_v != access_default) + new_v = compute_access (TREE_VALUE (TREE_CHAIN (*tp)), rval); + if (this_v != access_default && new_v != this_v) + { + errstr = "conflicting access to member `%D'"; + this_v = access_default; + } + own_access = new_v; + CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp))); + tp += 1; + } + } + else + { + while (tp < search_tail) + { + CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp))); + tp += 1; + } + } + } + search_stack = pop_search_level (search_stack); + + if (errstr == 0) + { + if (own_access == access_private) + errstr = "member `%D' declared private"; + else if (own_access == access_protected) + errstr = "member `%D' declared protected"; + else if (this_v == access_private) + errstr = TREE_PRIVATE (rval) + ? "member `%D' is private" + : "member `%D' is from private base class"; + else if (this_v == access_protected) + errstr = TREE_PROTECTED (rval) + ? "member `%D' is protected" + : "member `%D' is from protected base class"; + } + + if (entry) + { + if (errstr) + { + tree error_string = my_build_string (errstr); + /* Save error message with entry. */ + TREE_TYPE (entry) = error_string; + } + else + { + /* Mark entry as having no error string. */ + TREE_TYPE (entry) = NULL_TREE; + } + } + + if (errstr && protect) + { + cp_error (errstr, name, type); + rval = error_mark_node; + } + return rval; +} + +/* Try to find NAME inside a nested class. */ +tree +lookup_nested_field (name, complain) + tree name; + int complain; +{ + register tree t; + + tree id = NULL_TREE; + if (TREE_CHAIN (current_class_type)) + { + /* Climb our way up the nested ladder, seeing if we're trying to + modify a field in an enclosing class. If so, we should only + be able to modify if it's static. */ + for (t = TREE_CHAIN (current_class_type); + t && DECL_CONTEXT (t); + t = TREE_CHAIN (DECL_CONTEXT (t))) + { + if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE) + break; + + /* N.B.: lookup_field will do the access checking for us */ + id = lookup_field (DECL_CONTEXT (t), name, complain, 0); + if (id == error_mark_node) + { + id = NULL_TREE; + continue; + } + + if (id != NULL_TREE) + { + if (TREE_CODE (id) == FIELD_DECL + && ! TREE_STATIC (id) + && TREE_TYPE (id) != error_mark_node) + { + if (complain) + { + /* At parse time, we don't want to give this error, since + we won't have enough state to make this kind of + decision properly. But there are times (e.g., with + enums in nested classes) when we do need to call + this fn at parse time. So, in those cases, we pass + complain as a 0 and just return a NULL_TREE. */ + error ("assignment to non-static member `%s' of enclosing class `%s'", + lang_printable_name (id), + IDENTIFIER_POINTER (TYPE_IDENTIFIER + (DECL_CONTEXT (t)))); + /* Mark this for do_identifier(). It would otherwise + claim that the variable was undeclared. */ + TREE_TYPE (id) = error_mark_node; + } + else + { + id = NULL_TREE; + continue; + } + } + break; + } + } + } + + return id; +} + +/* TYPE is a class type. Return the index of the fields within + the method vector with name NAME, or -1 is no such field exists. */ +static int +lookup_fnfields_1 (type, name) + tree type, name; +{ + register tree method_vec = CLASSTYPE_METHOD_VEC (type); + + if (method_vec != 0) + { + register tree *methods = &TREE_VEC_ELT (method_vec, 0); + register tree *end = TREE_VEC_END (method_vec); + +#ifdef GATHER_STATISTICS + n_calls_lookup_fnfields_1++; +#endif + if (*methods && name == constructor_name (type)) + return 0; + + while (++methods != end) + { +#ifdef GATHER_STATISTICS + n_outer_fields_searched++; +#endif + if (DECL_NAME (*methods) == name) + break; + } + if (methods != end) + return methods - &TREE_VEC_ELT (method_vec, 0); + } + + return -1; +} + +/* Starting from BASETYPE, return a TREE_BASELINK-like object + which gives the following information (in a list): + + TREE_TYPE: list of basetypes needed to get to... + TREE_VALUE: list of all functions in of given type + which have name NAME. + + No access information is computed by this function, + other then to adorn the list of basetypes with + TREE_VIA_PUBLIC. + + If there are two ways to find a name (two members), if COMPLAIN is + non-zero, then error_mark_node is returned, and an error message is + printed, otherwise, just an error_mark_node is returned. + + As a special case, is COMPLAIN is -1, we don't complain, and we + don't return error_mark_node, but rather the complete list of + virtuals. This is used by get_virtuals_named_this. */ +tree +lookup_fnfields (basetype_path, name, complain) + tree basetype_path, name; + int complain; +{ + int head = 0, tail = 0; + tree type, rval, rval_binfo = NULL_TREE, rvals = NULL_TREE, rval_binfo_h; + tree entry, binfo, basetype_chain, binfo_h; + int find_all = 0; + + /* rval_binfo is the binfo associated with the found member, note, + this can be set with useful information, even when rval is not + set, because it must deal with ALL members, not just function + members. It is used for ambiguity checking and the hidden + checks. Whereas rval is only set if a proper (not hidden) + function member is found. */ + + /* rval_binfo_h and binfo_h are binfo values used when we perform the + hiding checks, as virtual base classes may not be shared. The strategy + is we always go into the the binfo hierarchy owned by TYPE_BINFO of + virtual base classes, as we cross virtual base class lines. This way + we know that binfo of a virtual base class will always == itself when + found along any line. (mrs) */ + + /* For now, don't try this. */ + int protect = complain; + + char *errstr = 0; + + /* Set this to nonzero if we don't know how to compute + accurate error messages for access control. */ + int index = MEMOIZED_HASH_FN (name); + + if (complain == -1) + { + find_all = 1; + protect = complain = 0; + } + + /* If we are looking for a constructor in a templated type, use the + unspecialized name, as that is how we store it. */ + if (IDENTIFIER_TEMPLATE (name)) + name = constructor_name (name); + + binfo = basetype_path; + binfo_h = binfo; + type = BINFO_TYPE (basetype_path); + + /* The memoization code is in need of maintenance. */ + if (!find_all && CLASSTYPE_MTABLE_ENTRY (type)) + { + tree tem = MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type), index); + + while (tem && TREE_PURPOSE (tem) != name) + { + memoized_fields_searched[1]++; + tem = TREE_CHAIN (tem); + } + if (tem) + { + if (protect && TREE_TYPE (tem)) + { + error (TREE_STRING_POINTER (TREE_TYPE (tem)), + IDENTIFIER_POINTER (name), + TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem))))); + return error_mark_node; + } + if (TREE_VALUE (tem) == NULL_TREE) + { + memoized_fast_rejects[1] += 1; + return NULL_TREE; + } + else + { + /* Want to return this, but we must make sure + that access information is consistent. */ + tree baselink = TREE_VALUE (tem); + tree memoized_basetypes = TREE_PURPOSE (baselink); + tree these_basetypes = basetype_path; + while (memoized_basetypes && these_basetypes) + { + memoized_fields_searched[1]++; + if (TREE_VALUE (memoized_basetypes) != these_basetypes) + break; + memoized_basetypes = TREE_CHAIN (memoized_basetypes); + these_basetypes = BINFO_INHERITANCE_CHAIN (these_basetypes); + } + /* The following statement is true only when both are NULL. */ + if (memoized_basetypes == these_basetypes) + { + memoized_fast_finds[1] += 1; + return TREE_VALUE (tem); + } + /* else, we must re-find this field by hand. */ + baselink = tree_cons (basetype_path, TREE_VALUE (baselink), TREE_CHAIN (baselink)); + return baselink; + } + } + } + +#ifdef GATHER_STATISTICS + n_calls_lookup_fnfields++; +#endif + if (protect && flag_memoize_lookups && ! global_bindings_p ()) + entry = make_memoized_table_entry (type, name, 1); + else + entry = 0; + + index = lookup_fnfields_here (type, name); + if (index >= 0 || lookup_field_1 (type, name)) + { + rval_binfo = basetype_path; + rval_binfo_h = rval_binfo; + } + + if (index >= 0) + { + rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), index); + rvals = my_tree_cons (basetype_path, rval, rvals); + if (BINFO_BASETYPES (binfo) && CLASSTYPE_BASELINK_VEC (type)) + TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), index); + + if (entry) + { + TREE_VALUE (entry) = rvals; + TREE_TYPE (entry) = NULL_TREE; + } + + return rvals; + } + rval = NULL_TREE; + + if (basetype_path == TYPE_BINFO (type)) + { + basetype_chain = CLASSTYPE_BINFO_AS_LIST (type); + TREE_VIA_PUBLIC (basetype_chain) = 1; + BINFO_VIA_PUBLIC (basetype_path) = 1; + BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE; + } + else + { + basetype_chain = build_tree_list (NULL_TREE, basetype_path); + TREE_VIA_PUBLIC (basetype_chain) = TREE_VIA_PUBLIC (basetype_path); + TREE_VIA_PROTECTED (basetype_chain) = TREE_VIA_PROTECTED (basetype_path); + TREE_VIA_VIRTUAL (basetype_chain) = TREE_VIA_VIRTUAL (basetype_path); + } + + /* The ambiguity check relies upon breadth first searching. */ + + search_stack = push_search_level (search_stack, &search_obstack); + binfo = basetype_path; + binfo_h = binfo; + + while (1) + { + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + int index; + + /* Process and/or queue base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + if (BINFO_FIELDS_MARKED (base_binfo) == 0) + { + tree btypes; + + SET_BINFO_FIELDS_MARKED (base_binfo); + btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain); + TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo); + TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo); + TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo); + if (TREE_VIA_VIRTUAL (base_binfo)) + btypes = tree_cons (NULL_TREE, + TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))), + btypes); + else + btypes = tree_cons (NULL_TREE, + TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i), + btypes); + obstack_ptr_grow (&search_obstack, btypes); + tail += 1; + if (tail >= search_stack->limit) + my_friendly_abort (99); + } + } + + /* Process head of queue, if one exists. */ + if (head >= tail) + break; + + basetype_chain = search_stack->first[head++]; + binfo_h = TREE_VALUE (basetype_chain); + basetype_chain = TREE_CHAIN (basetype_chain); + basetype_path = TREE_VALUE (basetype_chain); + if (TREE_CHAIN (basetype_chain)) + BINFO_INHERITANCE_CHAIN (basetype_path) = TREE_VALUE (TREE_CHAIN (basetype_chain)); + else + BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE; + + binfo = basetype_path; + type = BINFO_TYPE (binfo); + + /* See if we can find NAME in TYPE. If RVAL is nonzero, + and we do find NAME in TYPE, verify that such a second + sighting is in fact valid. */ + + index = lookup_fnfields_here (type, name); + + if (index >= 0 || (lookup_field_1 (type, name)!=NULL_TREE && !find_all)) + { + if (rval_binfo && !find_all && hides (rval_binfo_h, binfo_h)) + { + /* This is ok, the member found is in rval_binfo, not + here (binfo). */ + } + else if (rval_binfo==NULL_TREE || find_all || hides (binfo_h, rval_binfo_h)) + { + /* This is ok, the member found is here (binfo), not in + rval_binfo. */ + if (index >= 0) + { + rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), index); + /* Note, rvals can only be previously set if find_all is + true. */ + rvals = my_tree_cons (basetype_path, rval, rvals); + if (TYPE_BINFO_BASETYPES (type) + && CLASSTYPE_BASELINK_VEC (type)) + TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), index); + } + else + { + /* Undo finding it before, as something else hides it. */ + rval = NULL_TREE; + rvals = NULL_TREE; + } + rval_binfo = binfo; + rval_binfo_h = binfo_h; + } + else + { + /* This is ambiguous. */ + errstr = "request for method `%D' is ambiguous"; + rvals = error_mark_node; + break; + } + } + } + { + tree *tp = search_stack->first; + tree *search_tail = tp + tail; + + while (tp < search_tail) + { + CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp))); + tp += 1; + } + } + search_stack = pop_search_level (search_stack); + + if (entry) + { + if (errstr) + { + tree error_string = my_build_string (errstr); + /* Save error message with entry. */ + TREE_TYPE (entry) = error_string; + } + else + { + /* Mark entry as having no error string. */ + TREE_TYPE (entry) = NULL_TREE; + TREE_VALUE (entry) = rvals; + } + } + + if (errstr && protect) + { + cp_error (errstr, name); + rvals = error_mark_node; + } + + return rvals; +} + +/* BREADTH-FIRST SEARCH ROUTINES. */ + +/* Search a multiple inheritance hierarchy by breadth-first search. + + TYPE is an aggregate type, possibly in a multiple-inheritance hierarchy. + TESTFN is a function, which, if true, means that our condition has been met, + and its return value should be returned. + QFN, if non-NULL, is a predicate dictating whether the type should + even be queued. */ + +HOST_WIDE_INT +breadth_first_search (binfo, testfn, qfn) + tree binfo; + int (*testfn)(); + int (*qfn)(); +{ + int head = 0, tail = 0; + int rval = 0; + + search_stack = push_search_level (search_stack, &search_obstack); + + while (1) + { + tree binfos = BINFO_BASETYPES (binfo); + int n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + int i; + + /* Process and/or queue base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + if (BINFO_MARKED (base_binfo) == 0 + && (qfn == 0 || (*qfn) (binfo, i))) + { + SET_BINFO_MARKED (base_binfo); + obstack_ptr_grow (&search_obstack, binfo); + obstack_ptr_grow (&search_obstack, (HOST_WIDE_INT) i); + tail += 2; + if (tail >= search_stack->limit) + my_friendly_abort (100); + } + } + /* Process head of queue, if one exists. */ + if (head >= tail) + { + rval = 0; + break; + } + + binfo = search_stack->first[head++]; + i = (HOST_WIDE_INT) search_stack->first[head++]; + if (rval = (*testfn) (binfo, i)) + break; + binfo = BINFO_BASETYPE (binfo, i); + } + { + tree *tp = search_stack->first; + tree *search_tail = tp + tail; + while (tp < search_tail) + { + tree binfo = *tp++; + int i = (HOST_WIDE_INT)(*tp++); + CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo, i)); + } + } + + search_stack = pop_search_level (search_stack); + return rval; +} + +/* Functions to use in breadth first searches. */ +typedef tree (*pft)(); +typedef int (*pfi)(); + +int tree_needs_constructor_p (binfo, i) + tree binfo; + int i; +{ + tree basetype; + my_friendly_assert (i != 0, 296); + basetype = BINFO_TYPE (BINFO_BASETYPE (binfo, i)); + return TYPE_NEEDS_CONSTRUCTING (basetype); +} + +static tree declarator; + +static tree +get_virtuals_named_this (binfo) + tree binfo; +{ + tree fields; + + fields = lookup_fnfields (binfo, declarator, -1); + /* fields cannot be error_mark_node */ + + if (fields == 0) + return 0; + + /* Get to the function decls, and return the first virtual function + with this name, if there is one. */ + while (fields) + { + tree fndecl; + + for (fndecl = TREE_VALUE (fields); fndecl; fndecl = DECL_CHAIN (fndecl)) + if (DECL_VINDEX (fndecl)) + return fields; + fields = next_baselink (fields); + } + return NULL_TREE; +} + +static tree get_virtual_destructor (binfo, i) + tree binfo; + int i; +{ + tree type = BINFO_TYPE (binfo); + if (i >= 0) + type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i)); + if (TYPE_HAS_DESTRUCTOR (type) + && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0))) + return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0); + return 0; +} + +int tree_has_any_destructor_p (binfo, i) + tree binfo; + int i; +{ + tree type = BINFO_TYPE (binfo); + if (i >= 0) + type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i)); + return TYPE_NEEDS_DESTRUCTOR (type); +} + +/* Given a class type TYPE, and a function decl FNDECL, look for a + virtual function in TYPE's hierarchy which FNDECL could match as a + virtual function. It doesn't matter which one we find. + + DTORP is nonzero if we are looking for a destructor. Destructors + need special treatment because they do not match by name. */ +tree +get_matching_virtual (binfo, fndecl, dtorp) + tree binfo, fndecl; + int dtorp; +{ + tree tmp = NULL_TREE; + + /* Breadth first search routines start searching basetypes + of TYPE, so we must perform first ply of search here. */ + if (dtorp) + { + if (tree_has_any_destructor_p (binfo, -1)) + tmp = get_virtual_destructor (binfo, -1); + + if (tmp) + return tmp; + + tmp = (tree) breadth_first_search (binfo, + (pfi) get_virtual_destructor, + tree_has_any_destructor_p); + return tmp; + } + else + { + tree drettype, dtypes, btypes, instptr_type; + tree basetype = DECL_CLASS_CONTEXT (fndecl); + tree baselink, best = NULL_TREE; + tree name = DECL_ASSEMBLER_NAME (fndecl); + + declarator = DECL_NAME (fndecl); + if (IDENTIFIER_VIRTUAL_P (declarator) == 0) + return NULL_TREE; + + baselink = get_virtuals_named_this (binfo); + if (baselink == NULL_TREE) + return NULL_TREE; + + drettype = TREE_TYPE (TREE_TYPE (fndecl)); + dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); + if (DECL_STATIC_FUNCTION_P (fndecl)) + instptr_type = NULL_TREE; + else + instptr_type = TREE_TYPE (TREE_VALUE (dtypes)); + + for (; baselink; baselink = next_baselink (baselink)) + { + for (tmp = TREE_VALUE (baselink); tmp; tmp = DECL_CHAIN (tmp)) + { + if (! DECL_VINDEX (tmp)) + continue; + + btypes = TYPE_ARG_TYPES (TREE_TYPE (tmp)); + if (instptr_type == NULL_TREE) + { + if (compparms (TREE_CHAIN (btypes), dtypes, 3)) + /* Caller knows to give error in this case. */ + return tmp; + return NULL_TREE; + } + + if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes))) + == TYPE_READONLY (instptr_type)) + && compparms (TREE_CHAIN (btypes), TREE_CHAIN (dtypes), 3)) + { + tree brettype = TREE_TYPE (TREE_TYPE (tmp)); + if (comptypes (brettype, drettype, 1)) + /* OK */; + else if + (TREE_CODE (brettype) == TREE_CODE (drettype) + && (TREE_CODE (brettype) == POINTER_TYPE + || TREE_CODE (brettype) == REFERENCE_TYPE) + && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (brettype)), + TYPE_MAIN_VARIANT (TREE_TYPE (drettype)), + 0)) + /* covariant return type */ + { + tree b = TREE_TYPE (brettype), d = TREE_TYPE (drettype); + if (TYPE_MAIN_VARIANT (b) != TYPE_MAIN_VARIANT (d)) + { + tree binfo = get_binfo (b, d, 1); + if (binfo != error_mark_node + && ! BINFO_OFFSET_ZEROP (binfo)) + sorry ("adjusting pointers for covariant returns"); + } + if (TYPE_READONLY (d) > TYPE_READONLY (b)) + { + cp_error ("return type of `%#D' adds const", fndecl); + cp_error_at (" overriding definition as `%#D'", + tmp); + } + else if (TYPE_VOLATILE (d) > TYPE_VOLATILE (b)) + { + cp_error ("return type of `%#D' adds volatile", + fndecl); + cp_error_at (" overriding definition as `%#D'", + tmp); + } + } + else if (IS_AGGR_TYPE_2 (brettype, drettype) + && comptypes (brettype, drettype, 0)) + { + error ("invalid covariant return type (must use pointer or reference)"); + cp_error_at (" overriding `%#D'", tmp); + cp_error (" with `%#D'", fndecl); + } + else if (IDENTIFIER_ERROR_LOCUS (name) == NULL_TREE) + { + cp_error ("conflicting return type specified for virtual function `%#D'", fndecl); + cp_error_at (" overriding definition as `%#D'", tmp); + SET_IDENTIFIER_ERROR_LOCUS (name, basetype); + } + break; + } + } + if (tmp) + { + best = tmp; + break; + } + } + if (best == NULL_TREE && warn_overloaded_virtual) + cp_warning_at ("conflicting specification deriving virtual function `%D'", fndecl); + + return best; + } +} + +/* Return the list of virtual functions which are abstract in type + TYPE that come from non virtual base classes. See + expand_direct_vtbls_init for the style of search we do. */ +static tree +get_abstract_virtuals_1 (binfo, do_self, abstract_virtuals) + tree binfo, abstract_virtuals; + int do_self; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); + if (! TREE_VIA_VIRTUAL (base_binfo)) + abstract_virtuals + = get_abstract_virtuals_1 (base_binfo, is_not_base_vtable, + abstract_virtuals); + } + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) + { + tree virtuals = BINFO_VIRTUALS (binfo); + + skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree base_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)); + tree base_fndecl = TREE_OPERAND (base_pfn, 0); + if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl)) + abstract_virtuals = tree_cons (NULL_TREE, base_fndecl, abstract_virtuals); + virtuals = TREE_CHAIN (virtuals); + } + } + return abstract_virtuals; +} + +/* Return the list of virtual functions which are abstract in type TYPE. + This information is cached, and so must be built on a + non-temporary obstack. */ +tree +get_abstract_virtuals (type) + tree type; +{ + tree vbases; + tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (type); + + /* First get all from non-virtual bases. */ + abstract_virtuals + = get_abstract_virtuals_1 (TYPE_BINFO (type), 1, abstract_virtuals); + + for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases)) + { + tree virtuals = BINFO_VIRTUALS (vbases); + + skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree base_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)); + tree base_fndecl = TREE_OPERAND (base_pfn, 0); + if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl)) + abstract_virtuals = tree_cons (NULL_TREE, base_fndecl, abstract_virtuals); + virtuals = TREE_CHAIN (virtuals); + } + } + return nreverse (abstract_virtuals); +} + +/* For the type TYPE, return a list of member functions available from + base classes with name NAME. The TREE_VALUE of the list is a chain of + member functions with name NAME. The TREE_PURPOSE of the list is a + basetype, or a list of base types (in reverse order) which were + traversed to reach the chain of member functions. If we reach a base + type which provides a member function of name NAME, and which has at + most one base type itself, then we can terminate the search. */ + +tree +get_baselinks (type_as_binfo_list, type, name) + tree type_as_binfo_list; + tree type, name; +{ + int head = 0, tail = 0, index; + tree rval = 0, nval = 0; + tree basetypes = type_as_binfo_list; + tree binfo = TYPE_BINFO (type); + + search_stack = push_search_level (search_stack, &search_obstack); + + while (1) + { + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Process and/or queue base types. */ + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree btypes; + + btypes = hash_tree_cons (TREE_VIA_PUBLIC (base_binfo), + TREE_VIA_VIRTUAL (base_binfo), + TREE_VIA_PROTECTED (base_binfo), + NULL_TREE, base_binfo, + basetypes); + obstack_ptr_grow (&search_obstack, btypes); + search_stack->first = (tree *)obstack_base (&search_obstack); + tail += 1; + } + + dont_queue: + /* Process head of queue, if one exists. */ + if (head >= tail) + break; + + basetypes = search_stack->first[head++]; + binfo = TREE_VALUE (basetypes); + type = BINFO_TYPE (binfo); + index = lookup_fnfields_1 (type, name); + if (index >= 0) + { + nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), index); + rval = hash_tree_cons (0, 0, 0, basetypes, nval, rval); + if (TYPE_BINFO_BASETYPES (type) == 0) + goto dont_queue; + else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)) == 1) + { + if (CLASSTYPE_BASELINK_VEC (type)) + TREE_TYPE (rval) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), index); + goto dont_queue; + } + } + nval = NULL_TREE; + } + + search_stack = pop_search_level (search_stack); + return rval; +} + +tree +next_baselink (baselink) + tree baselink; +{ + tree tmp = TREE_TYPE (baselink); + baselink = TREE_CHAIN (baselink); + while (tmp) + { + /* @@ does not yet add previous base types. */ + baselink = tree_cons (TREE_PURPOSE (tmp), TREE_VALUE (tmp), + baselink); + TREE_TYPE (baselink) = TREE_TYPE (tmp); + tmp = TREE_CHAIN (tmp); + } + return baselink; +} + +/* DEPTH-FIRST SEARCH ROUTINES. */ + +/* Assign unique numbers to _CLASSTYPE members of the lattice + specified by TYPE. The root nodes are marked first; the nodes + are marked depth-fisrt, left-right. */ + +static int cid; + +/* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT. + Relation yields 1 if C1 <= C2, 0 otherwise. */ +typedef char mi_boolean; +static mi_boolean *mi_matrix; + +/* Type for which this matrix is defined. */ +static tree mi_type; + +/* Size of the matrix for indexing purposes. */ +static int mi_size; + +/* Return nonzero if class C2 derives from class C1. */ +#define BINFO_DERIVES_FROM(C1, C2) \ + ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1]) +#define TYPE_DERIVES_FROM(C1, C2) \ + ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1]) +#define BINFO_DERIVES_FROM_STAR(C) \ + (mi_matrix+(BINFO_CID (C)-1)) + +/* This routine converts a pointer to be a pointer of an immediate + base class. The normal convert_pointer_to routine would diagnose + the conversion as ambiguous, under MI code that has the base class + as an ambiguous base class. */ +static tree +convert_pointer_to_single_level (to_type, expr) + tree to_type, expr; +{ + tree binfo_of_derived; + tree last; + + binfo_of_derived = TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr))); + last = get_binfo (to_type, TREE_TYPE (TREE_TYPE (expr)), 0); + BINFO_INHERITANCE_CHAIN (last) = binfo_of_derived; + BINFO_INHERITANCE_CHAIN (binfo_of_derived) = NULL_TREE; + return build_vbase_path (PLUS_EXPR, build_pointer_type (to_type), expr, last, 1); +} + +/* The main function which implements depth first search. + + This routine has to remember the path it walked up, when + dfs_init_vbase_pointers is the work function, as otherwise there + would be no record. */ +static void +dfs_walk (binfo, fn, qfn) + tree binfo; + void (*fn)(); + int (*qfn)(); +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + if (qfn == 0 || (*qfn)(base_binfo)) + { + if (fn == dfs_init_vbase_pointers) + { + /* When traversing an arbitrary MI hierarchy, we need to keep + a record of the path we took to get down to the final base + type, as otherwise there would be no record of it, and just + trying to blindly convert at the bottom would be ambiguous. + + The easiest way is to do the conversions one step at a time, + as we know we want the immediate base class at each step. + + The only special trick to converting one step at a time, + is that when we hit the last virtual base class, we must + use the SLOT value for it, and not use the normal convert + routine. We use the last virtual base class, as in our + implementation, we have pointers to all virtual base + classes in the base object. */ + + tree saved_vbase_decl_ptr_intermediate + = vbase_decl_ptr_intermediate; + + if (TREE_VIA_VIRTUAL (base_binfo)) + { + /* No need for the conversion here, as we know it is the + right type. */ + vbase_decl_ptr_intermediate + = (tree)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo)); + } + else + { + vbase_decl_ptr_intermediate + = convert_pointer_to_single_level (BINFO_TYPE (base_binfo), + vbase_decl_ptr_intermediate); + } + + dfs_walk (base_binfo, fn, qfn); + + vbase_decl_ptr_intermediate = saved_vbase_decl_ptr_intermediate; + } else + dfs_walk (base_binfo, fn, qfn); + } + } + + fn (binfo); +} + +/* Predicate functions which serve for dfs_walk. */ +static int numberedp (binfo) tree binfo; +{ return BINFO_CID (binfo); } +static int unnumberedp (binfo) tree binfo; +{ return BINFO_CID (binfo) == 0; } + +static int markedp (binfo) tree binfo; +{ return BINFO_MARKED (binfo); } +static int bfs_markedp (binfo, i) tree binfo; int i; +{ return BINFO_MARKED (BINFO_BASETYPE (binfo, i)); } +static int unmarkedp (binfo) tree binfo; +{ return BINFO_MARKED (binfo) == 0; } +static int bfs_unmarkedp (binfo, i) tree binfo; int i; +{ return BINFO_MARKED (BINFO_BASETYPE (binfo, i)) == 0; } +static int marked_vtable_pathp (binfo) tree binfo; +{ return BINFO_VTABLE_PATH_MARKED (binfo); } +static int bfs_marked_vtable_pathp (binfo, i) tree binfo; int i; +{ return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo, i)); } +static int unmarked_vtable_pathp (binfo) tree binfo; +{ return BINFO_VTABLE_PATH_MARKED (binfo) == 0; } +static int bfs_unmarked_vtable_pathp (binfo, i) tree binfo; int i; +{ return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo, i)) == 0; } +static int marked_new_vtablep (binfo) tree binfo; +{ return BINFO_NEW_VTABLE_MARKED (binfo); } +static int bfs_marked_new_vtablep (binfo, i) tree binfo; int i; +{ return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo, i)); } +static int unmarked_new_vtablep (binfo) tree binfo; +{ return BINFO_NEW_VTABLE_MARKED (binfo) == 0; } +static int bfs_unmarked_new_vtablep (binfo, i) tree binfo; int i; +{ return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo, i)) == 0; } + +static int dfs_search_slot_nonempty_p (binfo) tree binfo; +{ return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) != 0; } + +static int dfs_debug_unmarkedp (binfo) tree binfo; +{ return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo)) == 0; } + +/* The worker functions for `dfs_walk'. These do not need to + test anything (vis a vis marking) if they are paired with + a predicate function (above). */ + +/* Assign each type within the lattice a number which is unique + in the lattice. The first number assigned is 1. */ + +static void +dfs_number (binfo) + tree binfo; +{ + BINFO_CID (binfo) = ++cid; +} + +static void +dfs_unnumber (binfo) + tree binfo; +{ + BINFO_CID (binfo) = 0; +} + +static void +dfs_mark (binfo) tree binfo; +{ SET_BINFO_MARKED (binfo); } + +static void +dfs_unmark (binfo) tree binfo; +{ CLEAR_BINFO_MARKED (binfo); } + +static void +dfs_mark_vtable_path (binfo) tree binfo; +{ SET_BINFO_VTABLE_PATH_MARKED (binfo); } + +static void +dfs_unmark_vtable_path (binfo) tree binfo; +{ CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); } + +static void +dfs_mark_new_vtable (binfo) tree binfo; +{ SET_BINFO_NEW_VTABLE_MARKED (binfo); } + +static void +dfs_unmark_new_vtable (binfo) tree binfo; +{ CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); } + +static void +dfs_clear_search_slot (binfo) tree binfo; +{ CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) = 0; } + +static void +dfs_debug_mark (binfo) + tree binfo; +{ + tree t = BINFO_TYPE (binfo); + + /* Use heuristic that if there are virtual functions, + ignore until we see a non-inline virtual function. */ + tree methods = CLASSTYPE_METHOD_VEC (t); + + CLASSTYPE_DEBUG_REQUESTED (t) = 1; + + /* If interface info is known, the value of (?@@?) is correct. */ + if (methods == 0 + || CLASSTYPE_INTERFACE_KNOWN (t) + || (write_virtuals == 2 && TYPE_VIRTUAL_P (t))) + return; + + /* If debug info is requested from this context for this type, supply it. + If debug info is requested from another context for this type, + see if some third context can supply it. */ + if (current_function_decl == NULL_TREE + || DECL_CLASS_CONTEXT (current_function_decl) != t) + { + if (TREE_VEC_ELT (methods, 0)) + methods = TREE_VEC_ELT (methods, 0); + else + methods = TREE_VEC_ELT (methods, 1); + while (methods) + { + if (DECL_VINDEX (methods) + && DECL_THIS_INLINE (methods) == 0 + && DECL_ABSTRACT_VIRTUAL_P (methods) == 0) + { + /* Somebody, somewhere is going to have to define this + virtual function. When they do, they will provide + the debugging info. */ + return; + } + methods = TREE_CHAIN (methods); + } + } + /* We cannot rely on some alien method to solve our problems, + so we must write out the debug info ourselves. */ + TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 0; + rest_of_type_compilation (t, global_bindings_p ()); +} + +/* Attach to the type of the virtual base class, the pointer to the + virtual base class, given the global pointer vbase_decl_ptr. + + We use the global vbase_types. ICK! */ +static void +dfs_find_vbases (binfo) + tree binfo; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = n_baselinks-1; i >= 0; i--) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + if (TREE_VIA_VIRTUAL (base_binfo) + && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo)) == 0) + { + tree vbase = BINFO_TYPE (base_binfo); + tree binfo = binfo_member (vbase, vbase_types); + + CLASSTYPE_SEARCH_SLOT (vbase) + = (char *) build (PLUS_EXPR, build_pointer_type (vbase), + vbase_decl_ptr, BINFO_OFFSET (binfo)); + } + } + SET_BINFO_VTABLE_PATH_MARKED (binfo); + SET_BINFO_NEW_VTABLE_MARKED (binfo); +} + +static void +dfs_init_vbase_pointers (binfo) + tree binfo; +{ + tree type = BINFO_TYPE (binfo); + tree fields = TYPE_FIELDS (type); + tree this_vbase_ptr; + + CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); + + /* If there is a rtti, it is the first field, though perhaps from + the base class. Otherwise, the first fields are virtual base class + pointer fields. */ + if (CLASSTYPE_RTTI (type) && VFIELD_NAME_P (DECL_NAME (fields))) + /* Get past vtable for the object. */ + fields = TREE_CHAIN (fields); + + if (fields == NULL_TREE + || DECL_NAME (fields) == NULL_TREE + || ! VBASE_NAME_P (DECL_NAME (fields))) + return; + + this_vbase_ptr = vbase_decl_ptr_intermediate; + + if (build_pointer_type (type) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr))) + my_friendly_abort (125); + + while (fields && DECL_NAME (fields) + && VBASE_NAME_P (DECL_NAME (fields))) + { + tree ref = build (COMPONENT_REF, TREE_TYPE (fields), + build_indirect_ref (this_vbase_ptr, NULL_PTR), fields); + tree init = (tree)CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields))); + vbase_init_result = tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields)), + vbase_types), + build_modify_expr (ref, NOP_EXPR, init), + vbase_init_result); + fields = TREE_CHAIN (fields); + } +} + +/* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other + times, just NEW_VTABLE, but optimizer should make both with equal + efficiency (though it does not currently). */ +static void +dfs_clear_vbase_slots (binfo) + tree binfo; +{ + tree type = BINFO_TYPE (binfo); + CLASSTYPE_SEARCH_SLOT (type) = 0; + CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); + CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); +} + +tree +init_vbase_pointers (type, decl_ptr) + tree type; + tree decl_ptr; +{ + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + { + int old_flag = flag_this_is_variable; + tree binfo = TYPE_BINFO (type); + flag_this_is_variable = -2; + vbase_types = CLASSTYPE_VBASECLASSES (type); + vbase_decl_ptr = decl_ptr; + vbase_decl = build_indirect_ref (decl_ptr, NULL_PTR); + vbase_decl_ptr_intermediate = vbase_decl_ptr; + vbase_init_result = NULL_TREE; + dfs_walk (binfo, dfs_find_vbases, unmarked_vtable_pathp); + dfs_walk (binfo, dfs_init_vbase_pointers, marked_vtable_pathp); + dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep); + flag_this_is_variable = old_flag; + return vbase_init_result; + } + return 0; +} + +/* get the virtual context (the vbase that directly contains the + DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in, + or NULL_TREE if there is none. + + FNDECL must come from a virtual table from a virtual base to ensure that + there is only one possible DECL_CLASS_CONTEXT. + + We know that if there is more than one place (binfo) the fndecl that the + declared, they all refer to the same binfo. See get_class_offset_1 for + the check that ensures this. */ +static tree +virtual_context (fndecl, t, vbase) + tree fndecl, t, vbase; +{ + tree path; + if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), t, 0, &path) < 0) + { + /* DECL_CLASS_CONTEXT can be ambiguous in t. */ + if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), vbase, 0, &path) >= 0) + { + while (path) + { + /* Not sure if checking path == vbase is necessary here, but just in + case it is. */ + if (TREE_VIA_VIRTUAL (path) || path == vbase) + return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t)); + path = BINFO_INHERITANCE_CHAIN (path); + } + } + /* This shouldn't happen, I don't want errors! */ + warning ("recoverable compiler error, fixups for virtual function"); + return vbase; + } + while (path) + { + if (TREE_VIA_VIRTUAL (path)) + return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t)); + path = BINFO_INHERITANCE_CHAIN (path); + } + return 0; +} + +/* Fixups upcast offsets for one vtable. + Entries may stay within the VBASE given, or + they may upcast into a direct base, or + they may upcast into a different vbase. + + We only need to do fixups in case 2 and 3. + + This routine mirrors fixup_vtable_deltas in functionality, though + this one is runtime based, and the other is compile time based. + Conceivably that routine could be removed entirely, and all fixups + done at runtime. + + VBASE_OFFSETS is an association list of virtual bases that contains + offset information, so the offsets are only calculated once. */ +static void +expand_upcast_fixups (binfo, addr, orig_addr, vbase, t, vbase_offsets) + tree binfo, addr, orig_addr, vbase, t, *vbase_offsets; +{ + tree virtuals = BINFO_VIRTUALS (binfo); + tree vc; + tree delta; + unsigned HOST_WIDE_INT n; + + delta = purpose_member (vbase, *vbase_offsets); + if (! delta) + { + delta = (tree)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase)); + delta = build (MINUS_EXPR, ptrdiff_type_node, delta, addr); + delta = save_expr (delta); + delta = tree_cons (vbase, delta, *vbase_offsets); + *vbase_offsets = delta; + } + + n = skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree current_fndecl = TREE_VALUE (virtuals); + current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl); + current_fndecl = TREE_OPERAND (current_fndecl, 0); + if (current_fndecl + && current_fndecl != abort_fndecl + && (vc=virtual_context (current_fndecl, t, vbase)) != vbase) + { + /* This may in fact need a runtime fixup. */ + tree idx = DECL_VINDEX (current_fndecl); + tree vtbl = BINFO_VTABLE (binfo); + tree nvtbl = lookup_name (DECL_NAME (vtbl), 0); + tree aref, ref, naref; + tree old_delta, new_delta; + tree init; + + if (nvtbl == NULL_TREE + || nvtbl == IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl))) + { + /* Dup it if it isn't in local scope yet. */ + nvtbl = build_decl (VAR_DECL, + DECL_NAME (vtbl), + TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo)))); + DECL_ALIGN (nvtbl) = MAX (TYPE_ALIGN (double_type_node), + DECL_ALIGN (nvtbl)); + TREE_READONLY (nvtbl) = 0; + nvtbl = pushdecl (nvtbl); + init = NULL_TREE; + cp_finish_decl (nvtbl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + DECL_VIRTUAL_P (nvtbl) = 1; + DECL_CONTEXT (nvtbl) = t; + init = build (MODIFY_EXPR, TREE_TYPE (nvtbl), + nvtbl, vtbl); + TREE_SIDE_EFFECTS (init) = 1; + expand_expr_stmt (init); + /* Update the vtable pointers as necessary. */ + ref = build_vfield_ref (build_indirect_ref (addr, NULL_PTR), DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo)))); + expand_expr_stmt (build_modify_expr (ref, NOP_EXPR, + build_unary_op (ADDR_EXPR, nvtbl, 0))); + } + assemble_external (vtbl); + aref = build_array_ref (vtbl, idx); + naref = build_array_ref (nvtbl, idx); + old_delta = build_component_ref (aref, delta_identifier, 0, 0); + new_delta = build_component_ref (naref, delta_identifier, 0, 0); + old_delta = build_binary_op (PLUS_EXPR, old_delta, + TREE_VALUE (delta), 0); + if (vc) + { + /* If this is set, we need to add in delta adjustments for + the other virtual base. */ + tree vc_delta = purpose_member (vc, *vbase_offsets); + if (! vc_delta) + { + tree vc_addr = convert_pointer_to_real (vc, orig_addr); + vc_delta = (tree)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc)); + vc_delta = build (MINUS_EXPR, ptrdiff_type_node, + vc_addr, vc_delta); + vc_delta = save_expr (vc_delta); + *vbase_offsets = tree_cons (vc, vc_delta, *vbase_offsets); + } + else + vc_delta = TREE_VALUE (vc_delta); + + old_delta = build_binary_op (PLUS_EXPR, old_delta, vc_delta, 0); + } + + TREE_READONLY (new_delta) = 0; + expand_expr_stmt (build_modify_expr (new_delta, NOP_EXPR, + old_delta)); + } + ++n; + virtuals = TREE_CHAIN (virtuals); + } +} + +/* Fixup upcast offsets for all direct vtables. Patterned after + expand_direct_vtbls_init. */ +static void +fixup_virtual_upcast_offsets (real_binfo, binfo, init_self, can_elide, addr, orig_addr, type, vbase, vbase_offsets) + tree real_binfo, binfo, addr, orig_addr, type, vbase, *vbase_offsets; + int init_self, can_elide; +{ + tree real_binfos = BINFO_BASETYPES (real_binfo); + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0; + + for (i = 0; i < n_baselinks; i++) + { + tree real_base_binfo = TREE_VEC_ELT (real_binfos, i); + tree base_binfo = TREE_VEC_ELT (binfos, i); + int is_not_base_vtable = + i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo)); + if (! TREE_VIA_VIRTUAL (real_base_binfo)) + fixup_virtual_upcast_offsets (real_base_binfo, base_binfo, + is_not_base_vtable, can_elide, addr, + orig_addr, type, vbase, vbase_offsets); + } +#if 0 + /* Before turning this on, make sure it is correct. */ + if (can_elide && ! BINFO_MODIFIED (binfo)) + return; +#endif + /* Should we use something besides CLASSTYPE_VFIELDS? */ + if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo))) + { + addr = convert_pointer_to_real (binfo, addr); + expand_upcast_fixups (real_binfo, addr, orig_addr, vbase, type, vbase_offsets); + } +} + +/* Build a COMPOUND_EXPR which when expanded will generate the code + needed to initialize all the virtual function table slots of all + the virtual baseclasses. MAIN_BINFO is the binfo which determines + the virtual baseclasses to use; TYPE is the type of the object to + which the initialization applies. TRUE_EXP is the true object we + are initializing, and DECL_PTR is the pointer to the sub-object we + are initializing. + + When USE_COMPUTED_OFFSETS is non-zero, we can assume that the + object was laid out by a top-level constructor and the computed + offsets are valid to store vtables. When zero, we must store new + vtables through virtual baseclass pointers. + + We setup and use the globals: vbase_decl, vbase_decl_ptr, vbase_types + ICK! */ + +void +expand_indirect_vtbls_init (binfo, true_exp, decl_ptr, use_computed_offsets) + tree binfo; + tree true_exp, decl_ptr; + int use_computed_offsets; +{ + tree type = BINFO_TYPE (binfo); + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + { + rtx fixup_insns = NULL_RTX; + int old_flag = flag_this_is_variable; + tree vbases = CLASSTYPE_VBASECLASSES (type); + vbase_types = vbases; + vbase_decl_ptr = true_exp ? build_unary_op (ADDR_EXPR, true_exp, 0) : decl_ptr; + vbase_decl = true_exp ? true_exp : build_indirect_ref (decl_ptr, NULL_PTR); + + if (use_computed_offsets) + { + /* This is an object of type IN_TYPE, */ + flag_this_is_variable = -2; + } + + dfs_walk (binfo, dfs_find_vbases, unmarked_new_vtablep); + + /* Initialized with vtables of type TYPE. */ + for (; vbases; vbases = TREE_CHAIN (vbases)) + { + tree addr; + if (use_computed_offsets) + addr = (tree)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbases)); + else + { +#if 1 + addr = convert_pointer_to_vbase (TREE_TYPE (vbases), vbase_decl_ptr); +#else + /* This should should never work better than the above. (mrs) */ + tree vbinfo = get_binfo (TREE_TYPE (vbases), + TREE_TYPE (vbase_decl), + 0); + + /* See is we can get lucky. */ + if (TREE_VIA_VIRTUAL (vbinfo)) + addr = convert_pointer_to_real (vbinfo, vbase_decl_ptr); + else + { + /* We go through all these contortions to avoid this + call, as it will fail when the virtual base type + is ambiguous from here. We don't yet have a way + to search for and find just an instance of the + virtual base class. Searching for the binfo in + vbases won't work, as we don't have the vbase + pointer field, for all vbases in the main class, + only direct vbases. */ + addr = convert_pointer_to_real (TREE_TYPE (vbases), + vbase_decl_ptr); + if (addr == error_mark_node) + continue; + } +#endif + } + + /* Do all vtables from this virtual base. */ + /* This assumes that virtual bases can never serve as parent + binfos. (in the CLASSTPE_VFIELD_PARENT sense) */ + expand_direct_vtbls_init (vbases, TYPE_BINFO (BINFO_TYPE (vbases)), + 1, 0, addr); + + /* If we are using computed offsets we can skip fixups. */ + if (use_computed_offsets) + continue; + + /* Now we adjust the offsets for virtual functions that cross + virtual boundaries on an implicit upcast on vf call so that + the layout of the most complete type is used, instead of + assuming the layout of the virtual bases from our current type. */ + + if (flag_vtable_thunks) + { + /* We don't have dynamic thunks yet! So for now, just fail silently. */ + } + else + { + tree vbase_offsets = NULL_TREE; + push_to_sequence (fixup_insns); + fixup_virtual_upcast_offsets (vbases, + TYPE_BINFO (BINFO_TYPE (vbases)), + 1, 0, addr, vbase_decl_ptr, + type, vbases, &vbase_offsets); + fixup_insns = get_insns (); + end_sequence (); + } + } + + if (fixup_insns) + { + extern tree in_charge_identifier; + tree in_charge_node = lookup_name (in_charge_identifier, 0); + if (! in_charge_node) + { + warning ("recoverable internal compiler error, nobody's in charge!"); + in_charge_node = integer_zero_node; + } + in_charge_node = build_binary_op (EQ_EXPR, in_charge_node, integer_zero_node, 1); + expand_start_cond (in_charge_node, 0); + emit_insns (fixup_insns); + expand_end_cond (); + } + + dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep); + + flag_this_is_variable = old_flag; + } +} + +void +clear_search_slots (type) + tree type; +{ + dfs_walk (TYPE_BINFO (type), + dfs_clear_search_slot, dfs_search_slot_nonempty_p); +} + +/* get virtual base class types. + This adds type to the vbase_types list in reverse dfs order. + Ordering is very important, so don't change it. */ + +static void +dfs_get_vbase_types (binfo) + tree binfo; +{ + if (TREE_VIA_VIRTUAL (binfo) && ! BINFO_VBASE_MARKED (binfo)) + { + vbase_types = make_binfo (integer_zero_node, binfo, + BINFO_VTABLE (binfo), + BINFO_VIRTUALS (binfo), vbase_types); + TREE_VIA_VIRTUAL (vbase_types) = 1; + SET_BINFO_VBASE_MARKED (binfo); + } + SET_BINFO_MARKED (binfo); +} + +/* get a list of virtual base classes in dfs order. */ +tree +get_vbase_types (type) + tree type; +{ + tree vbases; + tree binfo; + + if (TREE_CODE (type) == TREE_VEC) + binfo = type; + else + binfo = TYPE_BINFO (type); + + vbase_types = NULL_TREE; + dfs_walk (binfo, dfs_get_vbase_types, unmarkedp); + dfs_walk (binfo, dfs_unmark, markedp); + /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now + reverse it so that we get normal dfs ordering. */ + vbase_types = nreverse (vbase_types); + + /* unmark marked vbases */ + for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases)) + CLEAR_BINFO_VBASE_MARKED (vbases); + + return vbase_types; +} + +static void +dfs_record_inheritance (binfo) + tree binfo; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + mi_boolean *derived_row = BINFO_DERIVES_FROM_STAR (binfo); + + for (i = n_baselinks-1; i >= 0; i--) + { + int j; + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree baseclass = BINFO_TYPE (base_binfo); + mi_boolean *base_row = BINFO_DERIVES_FROM_STAR (base_binfo); + + /* Don't search if there's nothing there! MI_SIZE can be + zero as a result of parse errors. */ + if (TYPE_BINFO_BASETYPES (baseclass) && mi_size > 0) + for (j = mi_size*(CLASSTYPE_CID (baseclass)-1); j >= 0; j -= mi_size) + derived_row[j] |= base_row[j]; + TYPE_DERIVES_FROM (baseclass, BINFO_TYPE (binfo)) = 1; + } + + SET_BINFO_MARKED (binfo); +} + +/* Given a _CLASSTYPE node in a multiple inheritance lattice, + convert the lattice into a simple relation such that, + given to CIDs, C1 and C2, one can determine if C1 <= C2 + or C2 <= C1 or C1 <> C2. + + Once constructed, we walk the lattice depth fisrt, + applying various functions to elements as they are encountered. + + We use xmalloc here, in case we want to randomly free these tables. */ + +#define SAVE_MI_MATRIX + +void +build_mi_matrix (type) + tree type; +{ + tree binfo = TYPE_BINFO (type); + cid = 0; + +#ifdef SAVE_MI_MATRIX + if (CLASSTYPE_MI_MATRIX (type)) + { + mi_size = CLASSTYPE_N_SUPERCLASSES (type) + CLASSTYPE_N_VBASECLASSES (type); + mi_matrix = CLASSTYPE_MI_MATRIX (type); + mi_type = type; + dfs_walk (binfo, dfs_number, unnumberedp); + return; + } +#endif + + mi_size = CLASSTYPE_N_SUPERCLASSES (type) + CLASSTYPE_N_VBASECLASSES (type); + mi_matrix = (char *)xmalloc ((mi_size + 1) * (mi_size + 1)); + mi_type = type; + bzero (mi_matrix, (mi_size + 1) * (mi_size + 1)); + dfs_walk (binfo, dfs_number, unnumberedp); + dfs_walk (binfo, dfs_record_inheritance, unmarkedp); + dfs_walk (binfo, dfs_unmark, markedp); +} + +void +free_mi_matrix () +{ + dfs_walk (TYPE_BINFO (mi_type), dfs_unnumber, numberedp); + +#ifdef SAVE_MI_MATRIX + CLASSTYPE_MI_MATRIX (mi_type) = mi_matrix; +#else + free (mi_matrix); + mi_size = 0; + cid = 0; +#endif +} + +/* If we want debug info for a type TYPE, make sure all its base types + are also marked as being potentially interesting. This avoids + the problem of not writing any debug info for intermediate basetypes + that have abstract virtual functions. Also mark member types. */ + +void +note_debug_info_needed (type) + tree type; +{ + tree field; + dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp); + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + { + tree ttype; + if (TREE_CODE (field) == FIELD_DECL + && IS_AGGR_TYPE (ttype = target_type (TREE_TYPE (field))) + && dfs_debug_unmarkedp (TYPE_BINFO (ttype))) + note_debug_info_needed (ttype); + } +} + +/* Subroutines of push_class_decls (). */ + +/* Add in a decl to the envelope. */ +static void +envelope_add_decl (type, decl, values) + tree type, decl, *values; +{ + tree context, *tmp; + tree name = DECL_NAME (decl); + int dont_add = 0; + + /* virtual base names are always unique. */ + if (VBASE_NAME_P (name)) + *values = NULL_TREE; + + /* Possible ambiguity. If its defining type(s) + is (are all) derived from us, no problem. */ + else if (*values && TREE_CODE (*values) != TREE_LIST) + { + tree value = *values; + /* Only complain if we shadow something we can access. */ + if (warn_shadow && TREE_CODE (decl) == FUNCTION_DECL + && ((DECL_LANG_SPECIFIC (*values) + && DECL_CLASS_CONTEXT (value) == current_class_type) + || ! TREE_PRIVATE (value))) + /* Should figure out access control more accurately. */ + { + cp_warning_at ("member `%#D' is shadowed", value); + cp_warning_at ("by member function `%#D'", decl); + warning ("in this context"); + } + + context = (TREE_CODE (value) == FUNCTION_DECL + && DECL_VIRTUAL_P (value)) + ? DECL_CLASS_CONTEXT (value) + : DECL_CONTEXT (value); + + if (context == type) + { + if (TREE_CODE (value) == TYPE_DECL + && DECL_ARTIFICIAL (value)) + *values = NULL_TREE; + else + dont_add = 1; + } + else if (context && TYPE_DERIVES_FROM (context, type)) + { + /* Don't add in *values to list */ + *values = NULL_TREE; + } + else + *values = build_tree_list (NULL_TREE, value); + } + else + for (tmp = values; *tmp;) + { + tree value = TREE_VALUE (*tmp); + my_friendly_assert (TREE_CODE (value) != TREE_LIST, 999); + context = (TREE_CODE (value) == FUNCTION_DECL + && DECL_VIRTUAL_P (value)) + ? DECL_CLASS_CONTEXT (value) + : DECL_CONTEXT (value); + + if (context && TYPE_DERIVES_FROM (context, type)) + { + /* remove *tmp from list */ + *tmp = TREE_CHAIN (*tmp); + } + else + tmp = &TREE_CHAIN (*tmp); + } + + if (! dont_add) + { + /* Put the new contents in our envelope. */ + if (TREE_CODE (decl) == FUNCTION_DECL) + { + *values = tree_cons (name, decl, *values); + TREE_NONLOCAL_FLAG (*values) = 1; + TREE_TYPE (*values) = unknown_type_node; + } + else + { + if (*values) + { + *values = tree_cons (NULL_TREE, decl, *values); + /* Mark this as a potentially ambiguous member. */ + /* Leaving TREE_TYPE blank is intentional. + We cannot use `error_mark_node' (lookup_name) + or `unknown_type_node' (all member functions use this). */ + TREE_NONLOCAL_FLAG (*values) = 1; + } + else + *values = decl; + } + } +} + +/* Add the instance variables which this class contributed to the + current class binding contour. When a redefinition occurs, if the + redefinition is strictly within a single inheritance path, we just + overwrite the old declaration with the new. If the fields are not + within a single inheritance path, we must cons them. + + In order to know what decls are new (stemming from the current + invocation of push_class_decls) we enclose them in an "envelope", + which is a TREE_LIST node where the TREE_PURPOSE slot contains the + new decl (or possibly a list of competing ones), the TREE_VALUE slot + points to the old value and the TREE_CHAIN slot chains together all + envelopes which needs to be "opened" in push_class_decls. Opening an + envelope means: push the old value onto the class_shadowed list, + install the new one and if it's a TYPE_DECL do the same to the + IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that + the TREE_PURPOSE slot is non-null, and that it is not an identifier. + Because if it is, it could be a set of overloaded methods from an + outer scope. */ + +static void +dfs_pushdecls (binfo) + tree binfo; +{ + tree type = BINFO_TYPE (binfo); + tree fields, *methods, *end; + tree method_vec; + + for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) + { + /* Unmark so that if we are in a constructor, and then find that + this field was initialized by a base initializer, + we can emit an error message. */ + if (TREE_CODE (fields) == FIELD_DECL) + TREE_USED (fields) = 0; + + /* Recurse into anonymous unions. */ + if (DECL_NAME (fields) == NULL_TREE + && TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) + { + dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields))); + continue; + } + + if (DECL_NAME (fields)) + { + tree name = DECL_NAME (fields); + tree class_value = IDENTIFIER_CLASS_VALUE (name); + + /* If the class value is not an envelope of the kind described in + the comment above, we create a new envelope. */ + if (class_value == NULL_TREE || TREE_CODE (class_value) != TREE_LIST + || TREE_PURPOSE (class_value) == NULL_TREE + || TREE_CODE (TREE_PURPOSE (class_value)) == IDENTIFIER_NODE) + { + /* See comment above for a description of envelopes. */ + closed_envelopes = tree_cons (NULL_TREE, class_value, + closed_envelopes); + IDENTIFIER_CLASS_VALUE (name) = closed_envelopes; + class_value = IDENTIFIER_CLASS_VALUE (name); + } + + envelope_add_decl (type, fields, &TREE_PURPOSE (class_value)); + } + } + + method_vec = CLASSTYPE_METHOD_VEC (type); + if (method_vec != 0) + { + /* Farm out constructors and destructors. */ + methods = &TREE_VEC_ELT (method_vec, 1); + end = TREE_VEC_END (method_vec); + + while (methods != end) + { + /* This will cause lookup_name to return a pointer + to the tree_list of possible methods of this name. */ + tree name = DECL_NAME (*methods); + tree class_value = IDENTIFIER_CLASS_VALUE (name); + + /* If the class value is not an envelope of the kind described in + the comment above, we create a new envelope. */ + if (class_value == NULL_TREE || TREE_CODE (class_value) != TREE_LIST + || TREE_PURPOSE (class_value) == NULL_TREE + || TREE_CODE (TREE_PURPOSE (class_value)) == IDENTIFIER_NODE) + { + /* See comment above for a description of envelopes. */ + closed_envelopes = tree_cons (NULL_TREE, class_value, + closed_envelopes); + IDENTIFIER_CLASS_VALUE (name) = closed_envelopes; + class_value = IDENTIFIER_CLASS_VALUE (name); + } + + /* Here we try to rule out possible ambiguities. + If we can't do that, keep a TREE_LIST with possibly ambiguous + decls in there. */ + maybe_push_cache_obstack (); + envelope_add_decl (type, *methods, &TREE_PURPOSE (class_value)); + pop_obstacks (); + + methods++; + } + } + SET_BINFO_MARKED (binfo); +} + +/* Consolidate unique (by name) member functions. */ +static void +dfs_compress_decls (binfo) + tree binfo; +{ + tree type = BINFO_TYPE (binfo); + tree method_vec = CLASSTYPE_METHOD_VEC (type); + + if (method_vec != 0) + { + /* Farm out constructors and destructors. */ + tree *methods = &TREE_VEC_ELT (method_vec, 1); + tree *end = TREE_VEC_END (method_vec); + + for (; methods != end; methods++) + { + /* This is known to be an envelope of the kind described before + dfs_pushdecls. */ + tree class_value = IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods)); + tree tmp = TREE_PURPOSE (class_value); + + /* This was replaced in scope by somebody else. Just leave it + alone. */ + if (TREE_CODE (tmp) != TREE_LIST) + continue; + + if (TREE_CHAIN (tmp) == NULL_TREE + && TREE_VALUE (tmp) + && DECL_CHAIN (TREE_VALUE (tmp)) == NULL_TREE) + { + TREE_PURPOSE (class_value) = TREE_VALUE (tmp); + } + } + } + CLEAR_BINFO_MARKED (binfo); +} + +/* When entering the scope of a class, we cache all of the + fields that that class provides within its inheritance + lattice. Where ambiguities result, we mark them + with `error_mark_node' so that if they are encountered + without explicit qualification, we can emit an error + message. */ +void +push_class_decls (type) + tree type; +{ + tree id; + struct obstack *ambient_obstack = current_obstack; + + search_stack = push_search_level (search_stack, &search_obstack); + + id = TYPE_IDENTIFIER (type); +#if 0 + if (IDENTIFIER_TEMPLATE (id) != 0) + { + tree tmpl = IDENTIFIER_TEMPLATE (id); + push_template_decls (DECL_ARGUMENTS (TREE_PURPOSE (tmpl)), + TREE_VALUE (tmpl), 1); + overload_template_name (id, 1); + } +#endif + + /* Push class fields into CLASS_VALUE scope, and mark. */ + dfs_walk (TYPE_BINFO (type), dfs_pushdecls, unmarkedp); + + /* Compress fields which have only a single entry + by a given name, and unmark. */ + dfs_walk (TYPE_BINFO (type), dfs_compress_decls, markedp); + + /* Open up all the closed envelopes and push the contained decls into + class scope. */ + while (closed_envelopes) + { + tree new = TREE_PURPOSE (closed_envelopes); + tree id; + + /* This is messy because the class value may be a *_DECL, or a + TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous + *_DECLs. The name is stored at different places in these three + cases. */ + if (TREE_CODE (new) == TREE_LIST) + { + if (TREE_PURPOSE (new) != NULL_TREE) + id = TREE_PURPOSE (new); + else + { + tree node = TREE_VALUE (new); + + while (TREE_CODE (node) == TREE_LIST) + node = TREE_VALUE (node); + id = DECL_NAME (node); + } + } + else + id = DECL_NAME (new); + + /* Install the original class value in order to make + pushdecl_class_level work correctly. */ + IDENTIFIER_CLASS_VALUE (id) = TREE_VALUE (closed_envelopes); + if (TREE_CODE (new) == TREE_LIST) + push_class_level_binding (id, new); + else + pushdecl_class_level (new); + closed_envelopes = TREE_CHAIN (closed_envelopes); + } + current_obstack = ambient_obstack; +} + +/* Here's a subroutine we need because C lacks lambdas. */ +static void +dfs_unuse_fields (binfo) + tree binfo; +{ + tree type = TREE_TYPE (binfo); + tree fields; + + for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) + { + if (TREE_CODE (fields) != FIELD_DECL) + continue; + + TREE_USED (fields) = 0; + if (DECL_NAME (fields) == NULL_TREE + && TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE) + unuse_fields (TREE_TYPE (fields)); + } +} + +void +unuse_fields (type) + tree type; +{ + dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp); +} + +void +pop_class_decls (type) + tree type; +{ + /* We haven't pushed a search level when dealing with cached classes, + so we'd better not try to pop it. */ + if (search_stack) + search_stack = pop_search_level (search_stack); +} + +void +print_search_statistics () +{ +#ifdef GATHER_STATISTICS + if (flag_memoize_lookups) + { + fprintf (stderr, "%d memoized contexts saved\n", + n_contexts_saved); + fprintf (stderr, "%d local tree nodes made\n", my_tree_node_counter); + fprintf (stderr, "%d local hash nodes made\n", my_memoized_entry_counter); + fprintf (stderr, "fields statistics:\n"); + fprintf (stderr, " memoized finds = %d; rejects = %d; (searches = %d)\n", + memoized_fast_finds[0], memoized_fast_rejects[0], + memoized_fields_searched[0]); + fprintf (stderr, " memoized_adds = %d\n", memoized_adds[0]); + fprintf (stderr, "fnfields statistics:\n"); + fprintf (stderr, " memoized finds = %d; rejects = %d; (searches = %d)\n", + memoized_fast_finds[1], memoized_fast_rejects[1], + memoized_fields_searched[1]); + fprintf (stderr, " memoized_adds = %d\n", memoized_adds[1]); + } + fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n", + n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1); + fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n", + n_outer_fields_searched, n_calls_lookup_fnfields); + fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type); +#else + fprintf (stderr, "no search statistics\n"); +#endif +} + +void +init_search_processing () +{ + gcc_obstack_init (&search_obstack); + gcc_obstack_init (&type_obstack); + gcc_obstack_init (&type_obstack_entries); + + /* This gives us room to build our chains of basetypes, + whether or not we decide to memoize them. */ + type_stack = push_type_level (0, &type_obstack); + _vptr_name = get_identifier ("_vptr"); +} + +void +reinit_search_statistics () +{ + my_memoized_entry_counter = 0; + memoized_fast_finds[0] = 0; + memoized_fast_finds[1] = 0; + memoized_adds[0] = 0; + memoized_adds[1] = 0; + memoized_fast_rejects[0] = 0; + memoized_fast_rejects[1] = 0; + memoized_fields_searched[0] = 0; + memoized_fields_searched[1] = 0; + n_fields_searched = 0; + n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0; + n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0; + n_calls_get_base_type = 0; + n_outer_fields_searched = 0; + n_contexts_saved = 0; +} + +static tree conversions; +static void +add_conversions (binfo) + tree binfo; +{ + tree tmp = CLASSTYPE_FIRST_CONVERSION (BINFO_TYPE (binfo)); + for (; tmp && IDENTIFIER_TYPENAME_P (DECL_NAME (tmp)); + tmp = TREE_CHAIN (tmp)) + conversions = tree_cons (DECL_NAME (tmp), TREE_TYPE (TREE_TYPE (tmp)), + conversions); +} + +tree +lookup_conversions (type) + tree type; +{ + conversions = NULL_TREE; + dfs_walk (TYPE_BINFO (type), add_conversions, 0); + return conversions; +} diff --git a/contrib/gcc/cp/sig.c b/contrib/gcc/cp/sig.c new file mode 100644 index 00000000000..135dc6d7794 --- /dev/null +++ b/contrib/gcc/cp/sig.c @@ -0,0 +1,1049 @@ +/* Functions dealing with signatures and signature pointers/references. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Gerald Baumgartner (gb@cs.purdue.edu) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include +#include "obstack.h" +#include "tree.h" +#include "cp-tree.h" +#include "flags.h" +#include "assert.h" + +extern struct obstack *current_obstack; +extern struct obstack permanent_obstack; +extern struct obstack *saveable_obstack; + +extern void error (); +extern void sorry (); +extern void compiler_error (); +extern void make_decl_rtl PROTO((tree, char *, int)); + +/* Used to help generate globally unique names for signature tables. */ + +static int global_sigtable_name_counter; + +/* Build an identifier for a signature pointer or reference, so we + can use it's name in function name mangling. */ + +static tree +build_signature_pointer_or_reference_name (to_type, constp, volatilep, refp) + tree to_type; + int constp, volatilep, refp; +{ + char * sig_name = TYPE_NAME_STRING (to_type); + int name_len = TYPE_NAME_LENGTH (to_type) + constp + volatilep; + char * name; + + if (refp) + { + name = (char *) alloca (name_len + sizeof (SIGNATURE_REFERENCE_NAME) +2); + sprintf (name, SIGNATURE_REFERENCE_NAME_FORMAT, + constp ? "C" : "", volatilep ? "V": "", sig_name); + } + else + { + name = (char *) alloca (name_len + sizeof (SIGNATURE_POINTER_NAME) + 2); + sprintf (name, SIGNATURE_POINTER_NAME_FORMAT, + constp ? "C" : "", volatilep ? "V": "", sig_name); + } + return get_identifier (name); +} + +/* Build a DECL node for a signature pointer or reference, so we can + tell the debugger the structure of signature pointers/references. + This function is called at most eight times for a given signature, + once for each [const] [volatile] signature pointer/reference. */ + +static void +build_signature_pointer_or_reference_decl (type, name) + tree type, name; +{ + tree decl; + + /* We don't enter this declaration in any sort of symbol table. */ + decl = build_decl (TYPE_DECL, name, type); + TYPE_NAME (type) = decl; + TREE_CHAIN (type) = decl; +} + +/* Construct, lay out and return the type of pointers or references + to signature TO_TYPE. If such a type has already been constructed, + reuse it. If CONSTP or VOLATILEP is specified, make the `optr' const + or volatile, respectively. If we are constructing a const/volatile + type variant and the main type variant doesn't exist yet, it is built + as well. If REFP is 1, we construct a signature reference, otherwise + a signature pointer is constructed. + + This function is a subroutine of `build_signature_pointer_type' and + `build_signature_reference_type'. */ + +static tree +build_signature_pointer_or_reference_type (to_type, constp, volatilep, refp) + tree to_type; + int constp, volatilep, refp; +{ + register tree t, m; + register struct obstack *ambient_obstack = current_obstack; + register struct obstack *ambient_saveable_obstack = saveable_obstack; + + m = refp ? SIGNATURE_REFERENCE_TO (to_type) : SIGNATURE_POINTER_TO (to_type); + + /* If we don't have the main variant yet, construct it. */ + if (m == NULL_TREE + && (constp || volatilep)) + m = build_signature_pointer_or_reference_type (to_type, 0, 0, refp); + + /* Treat any nonzero argument as 1. */ + constp = !!constp; + volatilep = !!volatilep; + refp = !!refp; + + /* If not generating auxiliary info, search the chain of variants to see + if there is already one there just like the one we need to have. If so, + use that existing one. + + We don't do this in the case where we are generating aux info because + in that case we want each typedef names to get it's own distinct type + node, even if the type of this new typedef is the same as some other + (existing) type. */ + + if (m && !flag_gen_aux_info) + for (t = m; t; t = TYPE_NEXT_VARIANT (t)) + if (constp == TYPE_READONLY (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (t)))) + && volatilep == TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (t))))) + return t; + + /* We need a new one. If TO_TYPE is permanent, make this permanent too. */ + if (TREE_PERMANENT (to_type)) + { + current_obstack = &permanent_obstack; + saveable_obstack = &permanent_obstack; + } + + /* A signature pointer or reference to a signature `s' looks like this: + + struct { + void * optr; + const s * sptr; + }; + + A `const' signature pointer/reference is a + + struct { + const void * optr; + const s * sptr; + }; + + Similarly, for `volatile' and `const volatile'. + */ + + t = make_lang_type (RECORD_TYPE); + { + tree obj_type = build_type_variant (void_type_node, constp, volatilep); + tree optr_type = build_pointer_type (obj_type); + tree optr, sptr; + + optr = build_lang_field_decl (FIELD_DECL, + get_identifier (SIGNATURE_OPTR_NAME), + optr_type); + DECL_FIELD_CONTEXT (optr) = t; + DECL_CLASS_CONTEXT (optr) = t; + + if (m) + /* We can share the `sptr' field among type variants. */ + sptr = TREE_CHAIN (TYPE_FIELDS (m)); + else + { + tree sig_tbl_type = cp_build_type_variant (to_type, 1, 0); + + sptr = build_lang_field_decl (FIELD_DECL, + get_identifier (SIGNATURE_SPTR_NAME), + build_pointer_type (sig_tbl_type)); + DECL_FIELD_CONTEXT (sptr) = t; + DECL_CLASS_CONTEXT (sptr) = t; + TREE_CHAIN (sptr) = NULL_TREE; + } + + TREE_CHAIN (optr) = sptr; + TYPE_FIELDS (t) = optr; + TYPE_ALIGN (t) = TYPE_ALIGN (optr_type); + + /* A signature pointer/reference type isn't a `real' class type. */ + IS_AGGR_TYPE (t) = 0; + } + + { + tree name = build_signature_pointer_or_reference_name (to_type, constp, + volatilep, refp); + + /* Build a DECL node for this type, so the debugger has access to it. */ + build_signature_pointer_or_reference_decl (t, name); + } + + CLASSTYPE_GOT_SEMICOLON (t) = 1; + IS_SIGNATURE_POINTER (t) = ! refp; + IS_SIGNATURE_REFERENCE (t) = refp; + SIGNATURE_TYPE (t) = to_type; + + if (m) + { + /* Add this type to the chain of variants of TYPE. + Every type has to be its own TYPE_MAIN_VARIANT. */ + TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); + TYPE_NEXT_VARIANT (m) = t; + } + else if (refp) + /* Record this type as the reference to TO_TYPE. */ + SIGNATURE_REFERENCE_TO (to_type) = t; + else + /* Record this type as the pointer to TO_TYPE. */ + SIGNATURE_POINTER_TO (to_type) = t; + + /* Lay out the type. This function has many callers that are concerned + with expression-construction, and this simplifies them all. + Also, it guarantees the TYPE_SIZE is permanent if the type is. */ + layout_type (t); + + current_obstack = ambient_obstack; + saveable_obstack = ambient_saveable_obstack; + + /* Output debug information for this type. */ + rest_of_type_compilation (t, 1); + + return t; +} + +/* Construct, lay out and return the type of pointers to signature TO_TYPE. */ + +tree +build_signature_pointer_type (to_type, constp, volatilep) + tree to_type; + int constp, volatilep; +{ + return + build_signature_pointer_or_reference_type (to_type, constp, volatilep, 0); +} + +/* Construct, lay out and return the type of pointers to signature TO_TYPE. */ + +tree +build_signature_reference_type (to_type, constp, volatilep) + tree to_type; + int constp, volatilep; +{ + return + build_signature_pointer_or_reference_type (to_type, constp, volatilep, 1); +} + +/* Return the name of the signature table (as an IDENTIFIER_NODE) + for the given signature type SIG_TYPE and rhs type RHS_TYPE. */ + +static tree +get_sigtable_name (sig_type, rhs_type) + tree sig_type, rhs_type; +{ + tree sig_type_id = build_typename_overload (sig_type); + tree rhs_type_id = build_typename_overload (rhs_type); + char *buf = (char *) alloca (sizeof (SIGTABLE_NAME_FORMAT_LONG) + + IDENTIFIER_LENGTH (sig_type_id) + + IDENTIFIER_LENGTH (rhs_type_id) + 20); + char *sig_ptr = IDENTIFIER_POINTER (sig_type_id); + char *rhs_ptr = IDENTIFIER_POINTER (rhs_type_id); + int i, j; + + for (i = 0; sig_ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) + /* do nothing */; + while (sig_ptr[i] >= '0' && sig_ptr[i] <= '9') + i += 1; + + for (j = 0; rhs_ptr[j] == OPERATOR_TYPENAME_FORMAT[j]; j++) + /* do nothing */; + while (rhs_ptr[j] >= '0' && rhs_ptr[j] <= '9') + j += 1; + + if (IS_SIGNATURE (rhs_type)) + sprintf (buf, SIGTABLE_NAME_FORMAT_LONG, sig_ptr+i, rhs_ptr+j, + global_sigtable_name_counter++); + else + sprintf (buf, SIGTABLE_NAME_FORMAT, sig_ptr+i, rhs_ptr+j); + return get_identifier (buf); +} + +/* Build a field decl that points to a signature member function. */ + +static tree +build_member_function_pointer (member) + tree member; +{ + char *namstr = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (member)); + int namlen = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (member)); + char *name; + tree entry; + + name = (char *) alloca (namlen + sizeof (SIGNATURE_FIELD_NAME) + 2); + sprintf (name, SIGNATURE_FIELD_NAME_FORMAT, namstr); + + /* @@ Do we really want to xref signature table fields? */ + GNU_xref_ref (current_function_decl, name); + + entry = build_lang_field_decl (FIELD_DECL, get_identifier (name), + TYPE_MAIN_VARIANT (sigtable_entry_type)); + TREE_CONSTANT (entry) = 1; + TREE_READONLY (entry) = 1; + + /* @@ Do we really want to xref signature table fields? */ + GNU_xref_decl (current_function_decl, entry); + + return entry; +} + +/* For each FUNCTION_DECL in a signature we construct a member function + pointer of the appropriate type. We also need two flags to test + whether the member function pointer points to a virtual function or + to a default implementation. Those flags will be the two lower order + bits of the member function pointer (or the two higher order bits, + based on the configuration). + + The new FIELD_DECLs are appended at the end of the last (and only) + sublist of `list_of_fieldlists.' + + As a side effect, each member function in the signature gets the + `decl.ignored' bit turned on, so we don't output debug info for it. */ + +void +append_signature_fields (list_of_fieldlists) + tree list_of_fieldlists; +{ + tree l, x; + tree last_x = NULL_TREE; + tree mfptr; + tree last_mfptr; + tree mfptr_list = NULL_TREE; + + /* For signatures it should actually be only a list with one element. */ + for (l = list_of_fieldlists; l; l = TREE_CHAIN (l)) + { + for (x = TREE_VALUE (l); x; x = TREE_CHAIN (x)) + { + if (TREE_CODE (x) == FUNCTION_DECL) + { + mfptr = build_member_function_pointer (x); + DECL_MEMFUNC_POINTER_TO (x) = mfptr; + DECL_MEMFUNC_POINTING_TO (mfptr) = x; + DECL_IGNORED_P (x) = 1; + DECL_IN_AGGR_P (mfptr) = 1; + if (! mfptr_list) + mfptr_list = last_mfptr = mfptr; + else + { + TREE_CHAIN (last_mfptr) = mfptr; + last_mfptr = mfptr; + } + } + last_x = x; + } + } + + /* Append the lists. */ + if (last_x && mfptr_list) + { + TREE_CHAIN (last_x) = mfptr_list; + TREE_CHAIN (last_mfptr) = NULL_TREE; + } +} + +/* Compare the types of a signature member function and a class member + function. Returns 1 if the types are in the C++ `<=' relationship. + + If we have a signature pointer/reference as argument or return type + we don't want to do a recursive conformance check. The conformance + check only succeeds if both LHS and RHS refer to the same signature + pointer. Otherwise we need to keep information about parameter types + around at run time to initialize the signature table correctly. */ + +static int +match_method_types (sig_mtype, class_mtype) + tree sig_mtype, class_mtype; +{ + tree sig_return_type = TREE_TYPE (sig_mtype); + tree sig_arg_types = TYPE_ARG_TYPES (sig_mtype); + tree class_return_type = TREE_TYPE (class_mtype); + tree class_arg_types = TYPE_ARG_TYPES (class_mtype); + + /* The return types have to be the same. */ + if (! comptypes (sig_return_type, class_return_type, 1)) + return 0; + + /* Compare the first argument `this.' */ + { + /* Get the type of what the `optr' is pointing to. */ + tree sig_this = + TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (sig_arg_types)))); + tree class_this = TREE_VALUE (class_arg_types); + + if (TREE_CODE (class_this) == RECORD_TYPE) /* Is `this' a sig ptr? */ + class_this = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (class_this))); + else + class_this = TREE_TYPE (class_this); + + /* If a signature method's `this' is const or volatile, so has to be + the corresponding class method's `this.' */ + if ((TYPE_READONLY (sig_this) && ! TYPE_READONLY (class_this)) + || (TYPE_VOLATILE (sig_this) && ! TYPE_VOLATILE (class_this))) + return 0; + } + + sig_arg_types = TREE_CHAIN (sig_arg_types); + class_arg_types = TREE_CHAIN (class_arg_types); + + /* The number of arguments and the argument types have to be the same. */ + return compparms (sig_arg_types, class_arg_types, 3); +} + +/* Undo casts of opaque type variables to the RHS types. */ +static void +undo_casts (sig_ty) + tree sig_ty; +{ + tree field = TYPE_FIELDS (sig_ty); + + /* Since all the FIELD_DECLs for the signature table entries are at the end + of the chain (see `append_signature_fields'), we can do it this way. */ + for (; field && TREE_CODE (field) != FIELD_DECL; field = TREE_CHAIN (field)) + if (TYPE_MAIN_VARIANT (TREE_TYPE (field)) == opaque_type_node) + TREE_TYPE (TREE_TYPE (field)) = TREE_TYPE (ptr_type_node); +} + +/* Do the type checking necessary to see whether the `rhs' conforms to + the lhs's `sig_ty'. Depending on the type of `rhs' return a NULL_TREE, + an integer_zero_node, a constructor, or an expression offsetting the + `rhs' signature table. */ + +static tree +build_signature_table_constructor (sig_ty, rhs) + tree sig_ty, rhs; +{ + tree rhstype = TREE_TYPE (rhs); + tree sig_field = TYPE_FIELDS (sig_ty); + tree result = NULL_TREE; + tree first_rhs_field = NULL_TREE; + tree last_rhs_field; + int sig_ptr_p = IS_SIGNATURE (rhstype); + int offset_p = sig_ptr_p; + + rhstype = sig_ptr_p ? rhstype : TREE_TYPE (rhstype); + + if (CLASSTYPE_TAGS (sig_ty)) + { + sorry ("conformance check with signature containing class declarations"); + return error_mark_node; + } + + for (; sig_field; sig_field = TREE_CHAIN (sig_field)) + { + tree basetype_path, baselink, basetypes; + tree sig_method, sig_mname, sig_mtype; + tree rhs_method, tbl_entry; + + if (TREE_CODE (sig_field) == TYPE_DECL) + { + tree sig_field_type = TREE_TYPE (sig_field); + + if (TYPE_MAIN_VARIANT (sig_field_type) == opaque_type_node) + { + /* We've got an opaque type here. */ + tree oty_name = DECL_NAME (sig_field); + tree oty_type = lookup_field (rhstype, oty_name, 1, 1); + + if (oty_type == NULL_TREE || oty_type == error_mark_node) + { + cp_error ("class `%T' does not contain type `%T'", + rhstype, oty_type); + undo_casts (sig_ty); + return error_mark_node; + } + oty_type = TREE_TYPE (oty_type); + + /* Cast `sig_field' to be of type `oty_type'. This will be + undone in `undo_casts' by walking over all the TYPE_DECLs. */ + TREE_TYPE (sig_field_type) = TREE_TYPE (oty_type); + } + /* If we don't have an opaque type, we can ignore the `typedef'. */ + continue; + } + + /* Find the signature method corresponding to `sig_field'. */ + sig_method = DECL_MEMFUNC_POINTING_TO (sig_field); + sig_mname = DECL_NAME (sig_method); + sig_mtype = TREE_TYPE (sig_method); + + basetype_path = TYPE_BINFO (rhstype); + baselink = lookup_fnfields (basetype_path, sig_mname, 0); + if (baselink == NULL_TREE || baselink == error_mark_node) + { + if (! IS_DEFAULT_IMPLEMENTATION (sig_method)) + { + cp_error ("class `%T' does not contain method `%D'", + rhstype, sig_mname); + undo_casts (sig_ty); + return error_mark_node; + } + else + { + /* We use the signature's default implementation. */ + rhs_method = sig_method; + } + } + else + { + /* Find the class method of the correct type. */ + + basetypes = TREE_PURPOSE (baselink); + if (TREE_CODE (basetypes) == TREE_LIST) + basetypes = TREE_VALUE (basetypes); + + rhs_method = TREE_VALUE (baselink); + for (; rhs_method; rhs_method = TREE_CHAIN (rhs_method)) + if (sig_mname == DECL_NAME (rhs_method) + && ! DECL_STATIC_FUNCTION_P (rhs_method) + && match_method_types (sig_mtype, TREE_TYPE (rhs_method))) + break; + + if (rhs_method == NULL_TREE + || (compute_access (basetypes, rhs_method) + != access_public)) + { + error ("class `%s' does not contain a method conforming to `%s'", + TYPE_NAME_STRING (rhstype), + fndecl_as_string (NULL, sig_method, 1)); + undo_casts (sig_ty); + return error_mark_node; + } + } + + if (sig_ptr_p && rhs_method != sig_method) + { + tree rhs_field = DECL_MEMFUNC_POINTER_TO (rhs_method); + + if (first_rhs_field == NULL_TREE) + { + first_rhs_field = rhs_field; + last_rhs_field = rhs_field; + } + else if (TREE_CHAIN (last_rhs_field) == rhs_field) + last_rhs_field = rhs_field; + else + offset_p = 0; + + tbl_entry = build_component_ref (rhs, DECL_NAME (rhs_field), + NULL_TREE, 1); + } + else + { + tree tag, vb_off, delta, index, pfn, vt_off; + tree tag_decl, vb_off_decl, delta_decl, index_decl; + tree pfn_decl, vt_off_decl; + + if (rhs_method == sig_method) + { + /* default implementation */ + tag = build_unary_op (NEGATE_EXPR, integer_one_node, 0); + vb_off = build_unary_op (NEGATE_EXPR, integer_one_node, 0); + delta = integer_zero_node; + index = integer_zero_node; + pfn = build_unary_op (ADDR_EXPR, rhs_method, 0); + TREE_TYPE (pfn) = ptr_type_node; + TREE_ADDRESSABLE (rhs_method) = 1; + offset_p = 0; /* we can't offset the rhs sig table */ + } + else if (DECL_VINDEX (rhs_method)) + { + /* virtual member function */ + tag = integer_one_node; + vb_off = build_unary_op (NEGATE_EXPR, integer_one_node, 0); + delta = BINFO_OFFSET (get_binfo (DECL_CLASS_CONTEXT (rhs_method), + rhstype, 1)); + index = DECL_VINDEX (rhs_method); + vt_off = get_vfield_offset (get_binfo (DECL_CONTEXT (rhs_method), + rhstype, 0)); + } + else + { + /* non-virtual member function */ + tag = integer_zero_node; + vb_off = build_unary_op (NEGATE_EXPR, integer_one_node, 0); + delta = BINFO_OFFSET (get_binfo (DECL_CLASS_CONTEXT (rhs_method), + rhstype, 1)); + index = integer_zero_node; + pfn = build_unary_op (ADDR_EXPR, rhs_method, 0); + TREE_TYPE (pfn) = ptr_type_node; + TREE_ADDRESSABLE (rhs_method) = 1; + } + + /* Since digest_init doesn't handle initializing selected fields + of a struct (i.e., anonymous union), we build the constructor + by hand, without calling digest_init. */ + tag_decl = TYPE_FIELDS (sigtable_entry_type); + vb_off_decl = TREE_CHAIN (tag_decl); + delta_decl = TREE_CHAIN (vb_off_decl); + index_decl = TREE_CHAIN (delta_decl); + pfn_decl = TREE_CHAIN (index_decl); + vt_off_decl = TREE_CHAIN (pfn_decl); + + tag = convert (TREE_TYPE (tag_decl), tag); + vb_off = convert (TREE_TYPE (vb_off_decl), vb_off); + delta = convert (TREE_TYPE (delta_decl), delta); + index = convert (TREE_TYPE (index_decl), index); + + if (DECL_VINDEX (rhs_method)) + { + vt_off = convert (TREE_TYPE (vt_off_decl), vt_off); + + tbl_entry = build_tree_list (vt_off_decl, vt_off); + } + else + { + pfn = convert (TREE_TYPE (pfn_decl), pfn); + + tbl_entry = build_tree_list (pfn_decl, pfn); + } + tbl_entry = tree_cons (delta_decl, delta, + tree_cons (index_decl, index, tbl_entry)); + tbl_entry = tree_cons (tag_decl, tag, + tree_cons (vb_off_decl, vb_off, tbl_entry)); + tbl_entry = build (CONSTRUCTOR, sigtable_entry_type, + NULL_TREE, tbl_entry); + + TREE_CONSTANT (tbl_entry) = 1; + } + + /* Chain those function address expressions together. */ + if (result) + result = tree_cons (NULL_TREE, tbl_entry, result); + else + result = build_tree_list (NULL_TREE, tbl_entry); + } + + if (result == NULL_TREE) + { + /* The signature was empty, we don't need a signature table. */ + undo_casts (sig_ty); + return NULL_TREE; + } + + if (offset_p) + { + if (first_rhs_field == TYPE_FIELDS (rhstype)) + { + /* The sptr field on the lhs can be copied from the rhs. */ + undo_casts (sig_ty); + return integer_zero_node; + } + else + { + /* The sptr field on the lhs will point into the rhs sigtable. */ + undo_casts (sig_ty); + return build_component_ref (rhs, DECL_NAME (first_rhs_field), + NULL_TREE, 0); + } + } + + /* We need to construct a new signature table. */ + result = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (result)); + TREE_HAS_CONSTRUCTOR (result) = 1; + TREE_CONSTANT (result) = !sig_ptr_p; + + undo_casts (sig_ty); + return result; +} + +/* Build a signature table declaration and initialize it or return an + existing one if we built one already. If we don't get a constructor + as initialization expression, we don't need a new signature table + variable and just hand back the init expression. + + The declaration processing is done by hand instead of using `cp_finish_decl' + so that we can make signature pointers global variables instead of + static ones. */ + +static tree +build_sigtable (sig_type, rhs_type, init_from) + tree sig_type, rhs_type, init_from; +{ + tree name = NULL_TREE; + tree decl = NULL_TREE; + tree init_expr; + + push_obstacks_nochange (); + end_temporary_allocation (); + + if (! IS_SIGNATURE (rhs_type)) + { + name = get_sigtable_name (sig_type, rhs_type); + decl = IDENTIFIER_GLOBAL_VALUE (name); + } + if (decl == NULL_TREE) + { + tree init; + + /* We allow only one signature table to be generated for signatures + with opaque types. Otherwise we create a loophole in the type + system since we could cast data from one classes implementation + of the opaque type to that of another class. */ + if (SIGNATURE_HAS_OPAQUE_TYPEDECLS (sig_type) + && SIGTABLE_HAS_BEEN_GENERATED (sig_type)) + { + error ("signature with opaque type implemented by multiple classes"); + return error_mark_node; + } + SIGTABLE_HAS_BEEN_GENERATED (sig_type) = 1; + + init_expr = build_signature_table_constructor (sig_type, init_from); + if (init_expr == NULL_TREE || TREE_CODE (init_expr) != CONSTRUCTOR) + return init_expr; + + if (name == NULL_TREE) + name = get_sigtable_name (sig_type, rhs_type); + { + tree context = current_function_decl; + + /* Make the signature table global, not just static in whichever + function a signature pointer/ref is used for the first time. */ + current_function_decl = NULL_TREE; + decl = pushdecl_top_level (build_decl (VAR_DECL, name, sig_type)); + current_function_decl = context; + } + IDENTIFIER_GLOBAL_VALUE (name) = decl; + store_init_value (decl, init_expr); + if (IS_SIGNATURE (rhs_type)) + { + init = DECL_INITIAL (decl); + DECL_INITIAL (decl) = error_mark_node; + } + + DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node), + DECL_ALIGN (decl)); +#if 0 + /* GDB-4.7 doesn't find the initialization value of a signature table + when it is constant. */ + TREE_READONLY (decl) = 1; +#endif + TREE_STATIC (decl) = 1; + TREE_USED (decl) = 1; + + make_decl_rtl (decl, NULL, 1); + if (IS_SIGNATURE (rhs_type)) + expand_static_init (decl, init); + } + + pop_obstacks (); + + return decl; +} + +/* Create a constructor or modify expression if the LHS of an assignment + is a signature pointer or a signature reference. If LHS is a record + type node, we build a constructor, otherwise a compound expression. */ + +tree +build_signature_pointer_constructor (lhs, rhs) + tree lhs, rhs; +{ + register struct obstack *ambient_obstack = current_obstack; + register struct obstack *ambient_saveable_obstack = saveable_obstack; + int initp = (TREE_CODE (lhs) == RECORD_TYPE); + tree lhstype = initp ? lhs : TREE_TYPE (lhs); + tree rhstype = TREE_TYPE (rhs); + tree sig_ty = SIGNATURE_TYPE (lhstype); + tree sig_tbl, sptr_expr, optr_expr; + tree result; + + if (! ((TREE_CODE (rhstype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (rhstype)) == RECORD_TYPE) + || (TYPE_LANG_SPECIFIC (rhstype) && + (IS_SIGNATURE_POINTER (rhstype) + || IS_SIGNATURE_REFERENCE (rhstype))))) + { + error ("invalid assignment to signature pointer or reference"); + return error_mark_node; + } + + if (TYPE_SIZE (sig_ty) == NULL_TREE) + { + cp_error ("undefined signature `%T' used in signature %s declaration", + sig_ty, + IS_SIGNATURE_POINTER (lhstype) ? "pointer" : "reference"); + return error_mark_node; + } + + /* If SIG_TY is permanent, make the signature table constructor and + the signature pointer/reference constructor permanent too. */ + if (TREE_PERMANENT (sig_ty)) + { + current_obstack = &permanent_obstack; + saveable_obstack = &permanent_obstack; + } + + if (TYPE_LANG_SPECIFIC (rhstype) && + (IS_SIGNATURE_POINTER (rhstype) || IS_SIGNATURE_REFERENCE (rhstype))) + { + if (SIGNATURE_TYPE (rhstype) == sig_ty) + { + /* LHS and RHS are signature pointers/refs of the same signature. */ + optr_expr = build_optr_ref (rhs); + sptr_expr = build_sptr_ref (rhs); + } + else + { + /* We need to create a new signature table and copy + elements from the rhs signature table. */ + tree rhs_sptr_ref = build_sptr_ref (rhs); + tree rhs_tbl = build1 (INDIRECT_REF, SIGNATURE_TYPE (rhstype), + rhs_sptr_ref); + + sig_tbl = build_sigtable (sig_ty, SIGNATURE_TYPE (rhstype), rhs_tbl); + if (sig_tbl == error_mark_node) + return error_mark_node; + + optr_expr = build_optr_ref (rhs); + if (sig_tbl == NULL_TREE) + /* The signature was empty. The signature pointer is + pretty useless, but the user has been warned. */ + sptr_expr = copy_node (null_pointer_node); + else if (sig_tbl == integer_zero_node) + sptr_expr = rhs_sptr_ref; + else + sptr_expr = build_unary_op (ADDR_EXPR, sig_tbl, 0); + TREE_TYPE (sptr_expr) = build_pointer_type (sig_ty); + } + } + else + { + sig_tbl = build_sigtable (sig_ty, TREE_TYPE (rhstype), rhs); + if (sig_tbl == error_mark_node) + return error_mark_node; + + optr_expr = rhs; + if (sig_tbl == NULL_TREE) + /* The signature was empty. The signature pointer is + pretty useless, but the user has been warned. */ + { + sptr_expr = copy_node (null_pointer_node); + TREE_TYPE (sptr_expr) = build_pointer_type (sig_ty); + } + else + sptr_expr = build_unary_op (ADDR_EXPR, sig_tbl, 0); + } + + if (initp) + { + result = tree_cons (NULL_TREE, optr_expr, + build_tree_list (NULL_TREE, sptr_expr)); + result = build_nt (CONSTRUCTOR, NULL_TREE, result); + TREE_HAS_CONSTRUCTOR (result) = 1; + result = digest_init (lhstype, result, 0); + } + else + { + if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)) + readonly_error (lhs, "assignment", 0); + + optr_expr = build_modify_expr (build_optr_ref (lhs), NOP_EXPR, + optr_expr); + sptr_expr = build_modify_expr (build_sptr_ref (lhs), NOP_EXPR, + sptr_expr); + + result = tree_cons (NULL_TREE, optr_expr, + tree_cons (NULL_TREE, sptr_expr, + build_tree_list (NULL_TREE, lhs))); + result = build_compound_expr (result); + } + + current_obstack = ambient_obstack; + saveable_obstack = ambient_saveable_obstack; + return result; +} + +/* Build a temporary variable declaration for the instance of a signature + member function call if it isn't a declaration node already. Simply + using a SAVE_EXPR doesn't work since we need `this' in both branches + of a conditional expression. */ + +static tree +save_this (instance) + tree instance; +{ + tree decl; + + if (TREE_CODE_CLASS (TREE_CODE (instance)) == 'd') + decl = instance; + else + { + decl = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (instance)); + DECL_REGISTER (decl) = 1; + layout_decl (decl, 0); + expand_decl (decl); + } + + return decl; +} + +/* Build a signature member function call. Looks up the signature table + entry corresponding to FUNCTION. Depending on the value of the CODE + field, either call the function in PFN directly, or use OFFSET to + index INSTANCE's virtual function table. */ + +tree +build_signature_method_call (basetype, instance, function, parms) + tree basetype, instance, function, parms; +{ + tree saved_instance = save_this (instance); /* Create temp for `this'. */ + tree object_ptr = build_optr_ref (saved_instance); + tree new_object_ptr, new_parms; + tree signature_tbl_ptr = build_sptr_ref (saved_instance); + tree sig_field_name = DECL_NAME (DECL_MEMFUNC_POINTER_TO (function)); + tree basetype_path = TYPE_BINFO (basetype); + tree tbl_entry = build_component_ref (build1 (INDIRECT_REF, basetype, + signature_tbl_ptr), + sig_field_name, basetype_path, 1); + tree tag, delta, pfn, vt_off, index, vfn; + tree deflt_call = NULL_TREE, direct_call, virtual_call, result; + + tbl_entry = save_expr (tbl_entry); + tag = build_component_ref (tbl_entry, tag_identifier, NULL_TREE, 1); + delta = build_component_ref (tbl_entry, delta_identifier, NULL_TREE, 1); + pfn = build_component_ref (tbl_entry, pfn_identifier, NULL_TREE, 1); + vt_off = build_component_ref (tbl_entry, vt_off_identifier, NULL_TREE, 1); + index = build_component_ref (tbl_entry, index_identifier, NULL_TREE, 1); + TREE_TYPE (pfn) = build_pointer_type (TREE_TYPE (function)); + + if (IS_DEFAULT_IMPLEMENTATION (function)) + { + pfn = save_expr (pfn); + deflt_call = build_function_call (pfn, parms); + } + + new_object_ptr = build (PLUS_EXPR, build_pointer_type (basetype), + convert (ptrdiff_type_node, object_ptr), + convert (ptrdiff_type_node, delta)); + + parms = tree_cons (NULL_TREE, + convert (build_pointer_type (basetype), object_ptr), + TREE_CHAIN (parms)); + new_parms = tree_cons (NULL_TREE, new_object_ptr, TREE_CHAIN (parms)); + + { + /* Cast the signature method to have `this' of a normal pointer type. */ + tree old_this = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn)))); + + TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn)))) = + build_type_variant (build_pointer_type (basetype), + TYPE_READONLY (old_this), + TYPE_VOLATILE (old_this)); + + direct_call = build_function_call (pfn, new_parms); + + { + tree vfld, vtbl, aref; + + vfld = build (PLUS_EXPR, + build_pointer_type (build_pointer_type (vtbl_type_node)), + convert (ptrdiff_type_node, object_ptr), + convert (ptrdiff_type_node, vt_off)); + vtbl = build_indirect_ref (build_indirect_ref (vfld, NULL_PTR), + NULL_PTR); + aref = build_array_ref (vtbl, index); + + if (flag_vtable_thunks) + vfn = aref; + else + vfn = build_component_ref (aref, pfn_identifier, 0, 0); + + TREE_TYPE (vfn) = build_pointer_type (TREE_TYPE (function)); + + if (flag_vtable_thunks) + virtual_call = build_function_call (vfn, parms); + else + virtual_call = build_function_call (vfn, new_parms); + } + + /* Undo the cast, make `this' a signature pointer again. */ + TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (TREE_TYPE (pfn)))) = old_this; + } + + /* Once the function was found, there should be no reason why we + couldn't build the member function pointer call. */ + if (!direct_call || direct_call == error_mark_node + || !virtual_call || virtual_call == error_mark_node + || (IS_DEFAULT_IMPLEMENTATION (function) + && (!deflt_call || deflt_call == error_mark_node))) + { + compiler_error ("cannot build call of signature member function `%s'", + fndecl_as_string (NULL, function, 1)); + return error_mark_node; + } + + if (IS_DEFAULT_IMPLEMENTATION (function)) + { + tree test = build_binary_op_nodefault (LT_EXPR, tag, integer_zero_node, + LT_EXPR); + result = build_conditional_expr (tag, + build_conditional_expr (test, + deflt_call, + virtual_call), + direct_call); + } + else + result = build_conditional_expr (tag, virtual_call, direct_call); + + /* If we created a temporary variable for `this', initialize it first. */ + if (instance != saved_instance) + result = build (COMPOUND_EXPR, TREE_TYPE (result), + build_modify_expr (saved_instance, NOP_EXPR, instance), + result); + + return result; +} + +/* Create a COMPONENT_REF expression for referencing the OPTR field + of a signature pointer or reference. */ + +tree +build_optr_ref (instance) + tree instance; +{ + tree field = get_identifier (SIGNATURE_OPTR_NAME); + + return build_component_ref (instance, field, NULL_TREE, 1); +} + +/* Create a COMPONENT_REF expression for referencing the SPTR field + of a signature pointer or reference. */ + +tree +build_sptr_ref (instance) + tree instance; +{ + tree field = get_identifier (SIGNATURE_SPTR_NAME); + + return build_component_ref (instance, field, NULL_TREE, 1); +} diff --git a/contrib/gcc/cp/spew.c b/contrib/gcc/cp/spew.c new file mode 100644 index 00000000000..4b30b955c46 --- /dev/null +++ b/contrib/gcc/cp/spew.c @@ -0,0 +1,455 @@ +/* Type Analyzer for GNU C++. + Copyright (C) 1987, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked... nay, bludgeoned... by Mark Eichin (eichin@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is the type analyzer for GNU C++. To debug it, define SPEW_DEBUG + when compiling parse.c and spew.c. */ + +#include "config.h" +#include +#include "input.h" +#include "tree.h" +#include "lex.h" +#include "parse.h" +#include "cp-tree.h" +#include "flags.h" +#include "obstack.h" + +/* This takes a token stream that hasn't decided much about types and + tries to figure out as much as it can, with excessive lookahead and + backtracking. */ + +/* fifo of tokens recognized and available to parser. */ +struct token { + /* The values for YYCHAR will fit in a short. */ + short yychar; + short end_of_file; + YYSTYPE yylval; +}; + +static int do_aggr (); + +/* From lex.c: */ +/* the declaration found for the last IDENTIFIER token read in. + yylex must look this up to detect typedefs, which get token type TYPENAME, + so it is left around in case the identifier is not a typedef but is + used in a context which makes it a reference to a variable. */ +extern tree lastiddecl; /* let our brains leak out here too */ +extern int yychar; /* the lookahead symbol */ +extern YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ +extern int end_of_file; + +struct obstack token_obstack; +int first_token; + +#ifdef SPEW_DEBUG +int spew_debug = 0; +static unsigned int yylex_ctr = 0; +static int debug_yychar (); +#endif + +/* Initialize token_obstack. Called once, from init_lex. */ +void +init_spew () +{ + gcc_obstack_init(&token_obstack); +} + +#ifdef SPEW_DEBUG +/* Use functions for debugging... */ + +/* Return the number of tokens available on the fifo. */ +static int +num_tokens () +{ + return (obstack_object_size(&token_obstack)/sizeof(struct token)) + - first_token; +} + +/* Fetch the token N down the line from the head of the fifo. */ +static struct token* +nth_token (n) + int n; +{ + /* could just have this do slurp_ implicitly, but this way is easier + * to debug... */ + my_friendly_assert (n < num_tokens(), 298); + return ((struct token*)obstack_base(&token_obstack))+n+first_token; +} + +/* Add a token to the token fifo. */ +static void +add_token (t) + struct token* t; +{ + obstack_grow(&token_obstack,t,sizeof (struct token)); +} + +/* Consume the next token out of the fifo. */ +static void +consume_token() +{ + if (num_tokens() == 1) + { + obstack_free(&token_obstack, obstack_base (&token_obstack)); + first_token = 0; + } + else + first_token++; +} + +#else +/* ...otherwise use macros. */ + +#define num_tokens() \ + ((obstack_object_size(&token_obstack)/sizeof(struct token)) - first_token) + +#define nth_token(N) \ + (((struct token*)obstack_base(&token_obstack))+(N)+first_token) + +#define add_token(T) obstack_grow(&token_obstack, (T), sizeof (struct token)) + +#define consume_token() \ + (num_tokens() == 1 \ + ? (obstack_free (&token_obstack, obstack_base (&token_obstack)), \ + (first_token = 0)) \ + : first_token++) +#endif + +/* Pull in enough tokens from real_yylex that the queue is N long beyond + the current token. */ + +static void +scan_tokens (n) + int n; +{ + int i; + struct token *tmp; + + /* We cannot read past certain tokens, so make sure we don't. */ + i = num_tokens (); + if (i > n) + return; + while (i-- > 0) + { + tmp = nth_token (i); + /* Never read past these characters: they might separate + the current input stream from one we save away later. */ + if (tmp->yychar == '{' || tmp->yychar == ':' || tmp->yychar == ';') + goto pad_tokens; + } + + while (num_tokens() <= n) + { + obstack_blank(&token_obstack,sizeof (struct token)); + tmp = ((struct token *)obstack_next_free (&token_obstack))-1; + tmp->yychar = real_yylex(); + tmp->end_of_file = end_of_file; + tmp->yylval = yylval; + end_of_file = 0; + if (tmp->yychar == '{' + || tmp->yychar == ':' + || tmp->yychar == ';') + { + pad_tokens: + while (num_tokens () <= n) + { + obstack_blank(&token_obstack,sizeof (struct token)); + tmp = ((struct token *)obstack_next_free (&token_obstack))-1; + tmp->yychar = EMPTY; + tmp->end_of_file = 0; + } + } + } +} + +/* Create room for N tokens at the front of the fifo. This is used + to insert new tokens into the stream ahead of the current token. */ + +static void +shift_tokens (n) + int n; +{ + if (first_token >= n) + first_token -= n; + else + { + int old_token_count = num_tokens (); + char *tmp; + + obstack_blank (&token_obstack, (n-first_token) * sizeof (struct token)); + if (old_token_count) + { + tmp = (char *)alloca ((num_tokens () + (n-first_token)) + * sizeof (struct token)); + /* This move does not rely on the system being able to handle + overlapping moves. */ + bcopy ((char *) nth_token (0), tmp, + old_token_count * sizeof (struct token)); + bcopy (tmp, (char *) nth_token (n), + old_token_count * sizeof (struct token)); + } + first_token = 0; + } +} + +static int +probe_obstack (h, obj, nlevels) + struct obstack *h; + tree obj; + unsigned int nlevels; +{ + register struct _obstack_chunk* lp; /* below addr of any objects in this chunk */ + register struct _obstack_chunk* plp; /* point to previous chunk if any */ + + lp = (h)->chunk; + /* We use >= rather than > since the object cannot be exactly at + the beginning of the chunk but might be an empty object exactly + at the end of an adjacent chunk. */ + for (; nlevels != 0 && lp != 0 && ((tree)lp >= obj || (tree)lp->limit < obj); + nlevels -= 1) + { + plp = lp->prev; + lp = plp; + } + return nlevels != 0 && lp != 0; +} + +/* from lex.c: */ +/* Value is 1 (or 2) if we should try to make the next identifier look like + a typename (when it may be a local variable or a class variable). + Value is 0 if we treat this name in a default fashion. */ +extern int looking_for_typename; +int looking_for_template; + +extern struct obstack *current_obstack, *saveable_obstack; +tree got_scope; +tree got_object; + +int +peekyylex() +{ + scan_tokens (0); + return nth_token (0)->yychar; +} + +int +yylex() +{ + struct token tmp_token; + tree trrr; + + retry: +#ifdef SPEW_DEBUG + if (spew_debug) + { + yylex_ctr ++; + fprintf(stderr, "\t\t## %d ##",yylex_ctr); + } +#endif + + /* if we've got tokens, send them */ + if (num_tokens()) + { + tmp_token= *nth_token(0); + + /* TMP_TOKEN.YYLVAL.TTYPE may have been allocated on the wrong obstack. + If we don't find it in CURRENT_OBSTACK's current or immediately + previous chunk, assume it was and copy it to the current obstack. */ + if ((tmp_token.yychar == CONSTANT + || tmp_token.yychar == STRING) + && ! TREE_PERMANENT (tmp_token.yylval.ttype) + && ! probe_obstack (current_obstack, tmp_token.yylval.ttype, 2) + && ! probe_obstack (saveable_obstack, tmp_token.yylval.ttype, 2)) + tmp_token.yylval.ttype = copy_node (tmp_token.yylval.ttype); + } + else + { + /* if not, grab the next one and think about it */ + tmp_token.yychar = real_yylex (); + tmp_token.yylval = yylval; + tmp_token.end_of_file = end_of_file; + add_token(&tmp_token); + } + + /* many tokens just need to be returned. At first glance, all we + * have to do is send them back up, but some of them are needed to + * figure out local context. */ + switch(tmp_token.yychar) + { + case EMPTY: + /* This is a lexical no-op. */ + consume_token (); +#ifdef SPEW_DEBUG + if (spew_debug) + debug_yychar (tmp_token.yychar); +#endif + goto retry; + + case IDENTIFIER: + scan_tokens (1); + if (nth_token (1)->yychar == SCOPE) + /* Don't interfere with the setting from an 'aggr' prefix. */ + looking_for_typename++; + else if (nth_token (1)->yychar == '<') + looking_for_template = 1; + + trrr = lookup_name (tmp_token.yylval.ttype, -2); + + if (trrr) + { + tmp_token.yychar = identifier_type (trrr); + switch (tmp_token.yychar) + { + case TYPENAME: + lastiddecl = identifier_typedecl_value (tmp_token.yylval.ttype); + if (lastiddecl != trrr) + { + lastiddecl = trrr; + if (got_scope || got_object) + tmp_token.yylval.ttype = DECL_NESTED_TYPENAME (trrr); + } + break; + case IDENTIFIER: + lastiddecl = trrr; + break; + case PTYPENAME: + lastiddecl = NULL_TREE; + break; + case NSNAME: + lastiddecl = trrr; + if (got_scope || got_object) + tmp_token.yylval.ttype = trrr; + break; + default: + my_friendly_abort (101); + } + } + else + lastiddecl = trrr; + got_scope = NULL_TREE; + /* and fall through to... */ + case IDENTIFIER_DEFN: + case TYPENAME: + case TYPENAME_DEFN: + case PTYPENAME: + case PTYPENAME_DEFN: + consume_token (); + if (looking_for_typename > 0) + looking_for_typename--; + looking_for_template = 0; + break; + + case SCSPEC: + /* do_aggr needs to check if the previous token was RID_FRIEND, + so just increment first_token instead of calling consume_token. */ + first_token++; + break; + case TYPESPEC: + consume_token (); + break; + + case AGGR: + *nth_token(0) = tmp_token; + do_aggr (); + /* fall through to output... */ + case ENUM: + /* Set this again, in case we are rescanning. */ + looking_for_typename = 1; + /* fall through... */ + default: + consume_token(); + } + + yylval = tmp_token.yylval; + yychar = tmp_token.yychar; + end_of_file = tmp_token.end_of_file; +#ifdef SPEW_DEBUG + if (spew_debug) + debug_yychar(yychar); +#endif + return yychar; +} + +/* token[0] == AGGR (struct/union/enum) + * Thus, token[1] is either a TYPENAME or a TYPENAME_DEFN. + * If token[2] == '{' or ':' then it's TYPENAME_DEFN. + * It's also a definition if it's a forward declaration (as in 'struct Foo;') + * which we can tell lf token[2] == ';' *and* token[-1] != FRIEND. + */ +static int +do_aggr () +{ + int yc1, yc2; + + scan_tokens (2); + yc1 = nth_token (1)->yychar; + if (yc1 != TYPENAME && yc1 != IDENTIFIER && yc1 != PTYPENAME) + return 0; + yc2 = nth_token (2)->yychar; + if (yc2 == ';') + { + /* It's a forward declaration iff we were not preceded by 'friend'. */ + if (first_token > 0 && nth_token (-1)->yychar == SCSPEC + && nth_token (-1)->yylval.ttype == ridpointers[(int) RID_FRIEND]) + return 0; + } + else if (yc2 != '{' && yc2 != ':') + return 0; + + switch (yc1) + { + case TYPENAME: + nth_token (1)->yychar = TYPENAME_DEFN; + break; + case PTYPENAME: + nth_token (1)->yychar = PTYPENAME_DEFN; + break; + case IDENTIFIER: + nth_token (1)->yychar = IDENTIFIER_DEFN; + break; + default: + my_friendly_abort (102); + } + return 0; +} + +#ifdef SPEW_DEBUG +/* debug_yychar takes a yychar (token number) value and prints its name. */ +static int +debug_yychar (yy) + int yy; +{ + /* In parse.y: */ + extern char *debug_yytranslate (); + + int i; + + if(yy<256) { + fprintf (stderr, "<%d: %c >\n", yy, yy); + return 0; + } + fprintf (stderr, "<%d:%s>\n", yy, debug_yytranslate (yy)); + return 1; +} + +#endif diff --git a/contrib/gcc/cp/templates.texi b/contrib/gcc/cp/templates.texi new file mode 100644 index 00000000000..2a6db07f42b --- /dev/null +++ b/contrib/gcc/cp/templates.texi @@ -0,0 +1,235 @@ +@node Templates +@chapter The Template Implementation + +@cindex templates +@cindex function templates +@cindex class templates +@cindex parameterized types +@cindex types, parameterized +The C++ template@footnote{Class templates are also known as +@dfn{parameterized types}.} facility, which effectively allows use of +variables for types in declarations, is one of the newest features of +the language. + +@sc{gnu} C++ is one of the first compilers to implement many +of the template facilities currently defined by the @sc{ansi} committee. + +Nevertheless, the template implementation is not yet complete. This +chapter maps the current limitations of the @sc{gnu} C++ template +implementation. + +@menu +* Template limitations:: Limitations for function and class templates +* Function templates:: Limitations for function templates +* Class templates:: Limitations for class templates +* Template debugging:: Debugging information for templates +@end menu + +@node Template limitations +@section Limitations for function and class templates + +@cindex template limitations +@cindex template bugs +@cindex bugs, templates +These limitations apply to any use of templates (function templates or +class templates) with @sc{gnu} C++: + +@table @emph +@item Template definitions must be visible +When you compile code with templates, the template definitions must come +first (before the compiler needs to expand them), and template +definitions you use must be visible in the current scope. +@c FIXME! Is this a defined property of templates, rather than a +@c temporary limitation? +@c ANSWER: It's a limitation, but it's hard to say why it's a limitation +@c to someone. We need an infinite link-cycle, in one camp, to +@c accomplish things so you don't need the template definitions around. + +@cindex static data in template classes +@cindex template classes, static data in +@item Individual initializers needed for static data +Templates for static data in template classes do not work. @xref{Class +templates,,Limitations for class templates}. +@end table + +@node Function templates +@section Limitations for function templates + +@cindex function template limitations +Function templates are implemented for the most part. The compiler can +correctly determine template parameter values, and will delay +instantiation of a function that uses templates until the requisite type +information is available. + +@noindent +The following limitations remain: + +@itemize @bullet +@cindex template vs declaration, functions +@cindex declaration vs template, functions +@cindex function declaration vs template +@item +Narrowed specification: function declarations should not prevent +template expansion. When you declare a function, @sc{gnu} C++ +interprets the declaration as an indication that you will provide a +definition for that function. Therefore, @sc{gnu} C++ does not use a +template expansion if there is also an applicable declaration. @sc{gnu} +C++ only expands the template when there is no such declaration. + +The specification in Bjarne Stroustrup's @cite{The C++ Programming +Language, Second Edition} is narrower, and the @sc{gnu} C++ +implementation is now clearly incorrect. With this new specification, a +declaration that corresponds to an instantiation of a function template +only affects whether conversions are needed to use that version of the +function. It should no longer prevent expansion of the template +definition. + +For example, this code fragment must be treated differently: + +@smallexample +template X min (X& x1, X& x2) @{ @dots{} @} +int min (int, int); +@dots{} +int i; short s; +min (i, s); // @r{should call} min(int,int) + // @r{derived from template} +@dots{} +@end smallexample + +@item +The compiler does not yet understand function signatures where types are +nested within template parameters. For example, a function like the +following produces a syntax error on the closing @samp{)} of the +definition of the function @code{f}: + +@smallexample +template class A @{ public: T x; class Y @{@}; @}; +template int f (A::Y y) @{ @dots{} @} +@end smallexample + +@cindex @code{inline} and function templates +@cindex function templates and @code{inline} +@item +If you declare an @code{inline} function using templates, the compiler +can only inline the code @emph{after} the first time you use +that function with whatever particular type signature the template +was instantiated. + +Removing this limitation is akin to supporting nested function +definitions in @sc{gnu} C++; the limitation will probably remain until the +more general problem of nested functions is solved. + +@item +All the @emph{method} templates (templates for member functions) for a +class must be visible to the compiler when the class template is +instantiated. +@end itemize + +@node Class templates +@section Limitations for class templates + +@cindex class template limitations +@ignore +FIXME!! Include a comprehensible version of this if someone can explain it. + (Queried Brendan and Raeburn w/full orig context, 26may1993---pesch) + - [RHP: I don't understand what the following fragment refers to. If it's + the "BIG BUG" section in the original, why does it say "overriding class + declarations" here when the more detailed text refers to *function* + declarations? Here's the fragment I don't understand:] + there are problems with user-supplied overriding class declarations (see + below). +@end ignore + +@itemize @bullet +@ignore +@cindex static data, not working in templates +@item +Templates for static data in template classes do not work. +Currently, you must initialize each case of such data +individually. +@c FIXME!! Brendan to see if still true. +@c ANSWER: This section presumes that it's incorrect to have to +@c initialize for each type you instantiate with. It's not, it's the +@c right way to do it. +@end ignore + +Unfortunately, individual initializations of this sort are likely to be +considered errors eventually; since they're needed now, you might want to +flag places where you use them with comments to mark the need for a +future transition. + +@cindex nested type results vs templates +@item +Member functions in template classes may not have results of nested +type; @sc{gnu} C++ signals a syntax error on the attempt. The following +example illustrates this problem with an @code{enum} type @code{alph}: + +@smallexample +template class list @{ + @dots{} + enum alph @{a,b,c@}; + alph bar(); + @dots{} +@}; + +template +list::alph list::bar() // @i{Syntax error here} +@{ +@dots{} +@} +@end smallexample + +@cindex preprocessor conditionals in templates +@cindex conditionals (preprocessor) in templates +@item +A parsing bug makes it difficult to use preprocessor conditionals within +templates. For example, in this code: + +@smallexample +template +class list @{ + @dots{} +#ifdef SYSWRONG + T x; +#endif + @dots{} +@} +@end smallexample + +The preprocessor output leaves sourcefile line number information (lines +like @samp{# 6 "foo.cc"} when it expands the @code{#ifdef} block. These +lines confuse the compiler while parsing templates, giving a syntax +error. + +If you cannot avoid preprocessor conditionals in templates, you can +suppress the line number information using the @samp{-P} preprocessor +option (but this will make debugging more difficult), by compiling the +affected modules like this: + +@smallexample +g++ -P foo.cc -o foo +@end smallexample + +@cindex parsing errors, templates +@item +Parsing errors are reported when templates are first +@emph{instantiated}---not on the template definition itself. In +particular, if you do not instantiate a template definition at all, the +compiler never reports any parsing errors that may be in the template +definition. +@end itemize + +@node Template debugging +@section Debugging information for templates + +@cindex templates and debugging information +@cindex debugging information and templates +Debugging information for templates works for some object code formats, +but not others. It works for stabs@footnote{Except that insufficient +debugging information for methods of template classes is generated in +stabs.} (used primarily in @sc{a.out} object code, but also in the Solaris 2 +version of @sc{elf}), and the @sc{mips} version of @sc{coff} debugging +format. + +@sc{dwarf} support is currently minimal, and requires further +development. diff --git a/contrib/gcc/cp/tree.c b/contrib/gcc/cp/tree.c new file mode 100644 index 00000000000..7fb688ebd90 --- /dev/null +++ b/contrib/gcc/cp/tree.c @@ -0,0 +1,1995 @@ +/* Language-dependent node constructors for parse phase of GNU compiler. + Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" +#include +#include "obstack.h" +#include "tree.h" +#include "cp-tree.h" +#include "flags.h" +#include "rtl.h" + +#define CEIL(x,y) (((x) + (y) - 1) / (y)) + +/* Return nonzero if REF is an lvalue valid for this language. + Lvalues can be assigned, unless they have TREE_READONLY. + Lvalues can have their address taken, unless they have DECL_REGISTER. */ + +int +real_lvalue_p (ref) + tree ref; +{ + if (! language_lvalue_valid (ref)) + return 0; + + if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) + return 1; + + if (ref == current_class_decl && flag_this_is_variable <= 0) + return 0; + + switch (TREE_CODE (ref)) + { + /* preincrements and predecrements are valid lvals, provided + what they refer to are valid lvals. */ + case PREINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case COMPONENT_REF: + case SAVE_EXPR: + return real_lvalue_p (TREE_OPERAND (ref, 0)); + + case STRING_CST: + return 1; + + case VAR_DECL: + if (TREE_READONLY (ref) && ! TREE_STATIC (ref) + && DECL_LANG_SPECIFIC (ref) + && DECL_IN_AGGR_P (ref)) + return 0; + case INDIRECT_REF: + case ARRAY_REF: + case PARM_DECL: + case RESULT_DECL: + case ERROR_MARK: + if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE + && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) + return 1; + break; + + case WITH_CLEANUP_EXPR: + return real_lvalue_p (TREE_OPERAND (ref, 0)); + + /* A currently unresolved scope ref. */ + case SCOPE_REF: + my_friendly_abort (103); + case OFFSET_REF: + if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL) + return 1; + return real_lvalue_p (TREE_OPERAND (ref, 0)) + && real_lvalue_p (TREE_OPERAND (ref, 1)); + break; + + case COND_EXPR: + return (real_lvalue_p (TREE_OPERAND (ref, 1)) + && real_lvalue_p (TREE_OPERAND (ref, 2))); + + case MODIFY_EXPR: + return 1; + + case COMPOUND_EXPR: + return real_lvalue_p (TREE_OPERAND (ref, 1)); + + case MAX_EXPR: + case MIN_EXPR: + return (real_lvalue_p (TREE_OPERAND (ref, 0)) + && real_lvalue_p (TREE_OPERAND (ref, 1))); + } + + return 0; +} + +int +lvalue_p (ref) + tree ref; +{ + if (! language_lvalue_valid (ref)) + return 0; + + if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) + return 1; + + if (ref == current_class_decl && flag_this_is_variable <= 0) + return 0; + + switch (TREE_CODE (ref)) + { + /* preincrements and predecrements are valid lvals, provided + what they refer to are valid lvals. */ + case PREINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case COMPONENT_REF: + case SAVE_EXPR: + return lvalue_p (TREE_OPERAND (ref, 0)); + + case STRING_CST: + return 1; + + case VAR_DECL: + if (TREE_READONLY (ref) && ! TREE_STATIC (ref) + && DECL_LANG_SPECIFIC (ref) + && DECL_IN_AGGR_P (ref)) + return 0; + case INDIRECT_REF: + case ARRAY_REF: + case PARM_DECL: + case RESULT_DECL: + case ERROR_MARK: + if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE + && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE) + return 1; + break; + + case WITH_CLEANUP_EXPR: + return lvalue_p (TREE_OPERAND (ref, 0)); + + case TARGET_EXPR: + return 1; + + case CALL_EXPR: + if (IS_AGGR_TYPE (TREE_TYPE (ref))) + return 1; + break; + + /* A currently unresolved scope ref. */ + case SCOPE_REF: + my_friendly_abort (103); + case OFFSET_REF: + if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL) + return 1; + return lvalue_p (TREE_OPERAND (ref, 0)) + && lvalue_p (TREE_OPERAND (ref, 1)); + break; + + case COND_EXPR: + return (lvalue_p (TREE_OPERAND (ref, 1)) + && lvalue_p (TREE_OPERAND (ref, 2))); + + case MODIFY_EXPR: + return 1; + + case COMPOUND_EXPR: + return lvalue_p (TREE_OPERAND (ref, 1)); + + case MAX_EXPR: + case MIN_EXPR: + return (lvalue_p (TREE_OPERAND (ref, 0)) + && lvalue_p (TREE_OPERAND (ref, 1))); + } + + return 0; +} + +/* Return nonzero if REF is an lvalue valid for this language; + otherwise, print an error message and return zero. */ + +int +lvalue_or_else (ref, string) + tree ref; + char *string; +{ + int win = lvalue_p (ref); + if (! win) + error ("non-lvalue in %s", string); + return win; +} + +/* INIT is a CALL_EXPR which needs info about its target. + TYPE is the type that this initialization should appear to have. + + Build an encapsulation of the initialization to perform + and return it so that it can be processed by language-independent + and language-specific expression expanders. + + If WITH_CLEANUP_P is nonzero, we build a cleanup for this expression. + Otherwise, cleanups are not built here. For example, when building + an initialization for a stack slot, since the called function handles + the cleanup, we would not want to do it here. */ +tree +build_cplus_new (type, init, with_cleanup_p) + tree type; + tree init; + int with_cleanup_p; +{ + tree slot; + tree rval; + + slot = build (VAR_DECL, type); + layout_decl (slot, 0); + rval = build (NEW_EXPR, type, + TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot); + TREE_SIDE_EFFECTS (rval) = 1; + TREE_ADDRESSABLE (rval) = 1; + rval = build (TARGET_EXPR, type, slot, rval, 0); + TREE_SIDE_EFFECTS (rval) = 1; + TREE_ADDRESSABLE (rval) = 1; + +#if 0 + if (with_cleanup_p && TYPE_NEEDS_DESTRUCTOR (type)) + { + TREE_OPERAND (rval, 2) = error_mark_node; + rval = build (WITH_CLEANUP_EXPR, type, rval, 0, + build_delete (build_pointer_type (type), + build_unary_op (ADDR_EXPR, slot, 0), + integer_two_node, + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0)); + TREE_SIDE_EFFECTS (rval) = 1; + TREE_ADDRESSABLE (rval) = 1; + } +#endif + return rval; +} + +/* Recursively search EXP for CALL_EXPRs that need cleanups and replace + these CALL_EXPRs with tree nodes that will perform the cleanups. */ + +tree +break_out_cleanups (exp) + tree exp; +{ + tree tmp = exp; + + if (TREE_CODE (tmp) == CALL_EXPR + && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp))) + return build_cplus_new (TREE_TYPE (tmp), tmp, 1); + + while (TREE_CODE (tmp) == NOP_EXPR + || TREE_CODE (tmp) == CONVERT_EXPR + || TREE_CODE (tmp) == NON_LVALUE_EXPR) + { + if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR + && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0)))) + { + TREE_OPERAND (tmp, 0) + = build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)), + TREE_OPERAND (tmp, 0), 1); + break; + } + else + tmp = TREE_OPERAND (tmp, 0); + } + return exp; +} + +/* Recursively perform a preorder search EXP for CALL_EXPRs, making + copies where they are found. Returns a deep copy all nodes transitively + containing CALL_EXPRs. */ + +tree +break_out_calls (exp) + tree exp; +{ + register tree t1, t2; + register enum tree_code code; + register int changed = 0; + register int i; + + if (exp == NULL_TREE) + return exp; + + code = TREE_CODE (exp); + + if (code == CALL_EXPR) + return copy_node (exp); + + /* Don't try and defeat a save_expr, as it should only be done once. */ + if (code == SAVE_EXPR) + return exp; + + switch (TREE_CODE_CLASS (code)) + { + default: + abort (); + + case 'c': /* a constant */ + case 't': /* a type node */ + case 'x': /* something random, like an identifier or an ERROR_MARK. */ + return exp; + + case 'd': /* A decl node */ +#if 0 /* This is bogus. jason 9/21/94 */ + + t1 = break_out_calls (DECL_INITIAL (exp)); + if (t1 != DECL_INITIAL (exp)) + { + exp = copy_node (exp); + DECL_INITIAL (exp) = t1; + } +#endif + return exp; + + case 'b': /* A block node */ + { + /* Don't know how to handle these correctly yet. Must do a + break_out_calls on all DECL_INITIAL values for local variables, + and also break_out_calls on all sub-blocks and sub-statements. */ + abort (); + } + return exp; + + case 'e': /* an expression */ + case 'r': /* a reference */ + case 's': /* an expression with side effects */ + for (i = tree_code_length[(int) code] - 1; i >= 0; i--) + { + t1 = break_out_calls (TREE_OPERAND (exp, i)); + if (t1 != TREE_OPERAND (exp, i)) + { + exp = copy_node (exp); + TREE_OPERAND (exp, i) = t1; + } + } + return exp; + + case '<': /* a comparison expression */ + case '2': /* a binary arithmetic expression */ + t2 = break_out_calls (TREE_OPERAND (exp, 1)); + if (t2 != TREE_OPERAND (exp, 1)) + changed = 1; + case '1': /* a unary arithmetic expression */ + t1 = break_out_calls (TREE_OPERAND (exp, 0)); + if (t1 != TREE_OPERAND (exp, 0)) + changed = 1; + if (changed) + { + if (tree_code_length[(int) code] == 1) + return build1 (code, TREE_TYPE (exp), t1); + else + return build (code, TREE_TYPE (exp), t1, t2); + } + return exp; + } + +} + +extern struct obstack *current_obstack; +extern struct obstack permanent_obstack, class_obstack; +extern struct obstack *saveable_obstack; + +/* Here is how primitive or already-canonicalized types' hash + codes are made. MUST BE CONSISTENT WITH tree.c !!! */ +#define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777) + +/* Construct, lay out and return the type of methods belonging to class + BASETYPE and whose arguments are described by ARGTYPES and whose values + are described by RETTYPE. If each type exists already, reuse it. */ +tree +build_cplus_method_type (basetype, rettype, argtypes) + tree basetype, rettype, argtypes; +{ + register tree t; + tree ptype; + int hashcode; + + /* Make a node of the sort we want. */ + t = make_node (METHOD_TYPE); + + TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); + TREE_TYPE (t) = rettype; + if (IS_SIGNATURE (basetype)) + ptype = build_signature_pointer_type (TYPE_MAIN_VARIANT (basetype), + TYPE_READONLY (basetype), + TYPE_VOLATILE (basetype)); + else + ptype = build_pointer_type (basetype); + + /* The actual arglist for this function includes a "hidden" argument + which is "this". Put it into the list of argument types. */ + + argtypes = tree_cons (NULL_TREE, ptype, argtypes); + TYPE_ARG_TYPES (t) = argtypes; + TREE_SIDE_EFFECTS (argtypes) = 1; /* Mark first argtype as "artificial". */ + + /* If we already have such a type, use the old one and free this one. + Note that it also frees up the above cons cell if found. */ + hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes); + t = type_hash_canon (hashcode, t); + + if (TYPE_SIZE (t) == 0) + layout_type (t); + + return t; +} + +tree +build_cplus_staticfn_type (basetype, rettype, argtypes) + tree basetype, rettype, argtypes; +{ + register tree t; + int hashcode; + + /* Make a node of the sort we want. */ + t = make_node (FUNCTION_TYPE); + + TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); + TREE_TYPE (t) = rettype; + + TYPE_ARG_TYPES (t) = argtypes; + + /* If we already have such a type, use the old one and free this one. + Note that it also frees up the above cons cell if found. */ + hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + type_hash_list (argtypes); + t = type_hash_canon (hashcode, t); + + if (TYPE_SIZE (t) == 0) + layout_type (t); + + return t; +} + +tree +build_cplus_array_type (elt_type, index_type) + tree elt_type; + tree index_type; +{ + register struct obstack *ambient_obstack = current_obstack; + register struct obstack *ambient_saveable_obstack = saveable_obstack; + tree t; + + /* We need a new one. If both ELT_TYPE and INDEX_TYPE are permanent, + make this permanent too. */ + if (TREE_PERMANENT (elt_type) + && (index_type == 0 || TREE_PERMANENT (index_type))) + { + current_obstack = &permanent_obstack; + saveable_obstack = &permanent_obstack; + } + + t = build_array_type (elt_type, index_type); + + /* Push these needs up so that initialization takes place + more easily. */ + TYPE_NEEDS_CONSTRUCTING (t) = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type)); + TYPE_NEEDS_DESTRUCTOR (t) = TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type)); + current_obstack = ambient_obstack; + saveable_obstack = ambient_saveable_obstack; + return t; +} + +/* Make a variant type in the proper way for C/C++, propagating qualifiers + down to the element type of an array. */ + +tree +cp_build_type_variant (type, constp, volatilep) + tree type; + int constp, volatilep; +{ + if (TREE_CODE (type) == ARRAY_TYPE) + { + tree real_main_variant = TYPE_MAIN_VARIANT (type); + + push_obstacks (TYPE_OBSTACK (real_main_variant), + TYPE_OBSTACK (real_main_variant)); + type = build_cplus_array_type (cp_build_type_variant (TREE_TYPE (type), + constp, volatilep), + TYPE_DOMAIN (type)); + + /* TYPE must be on same obstack as REAL_MAIN_VARIANT. If not, + make a copy. (TYPE might have come from the hash table and + REAL_MAIN_VARIANT might be in some function's obstack.) */ + + if (TYPE_OBSTACK (type) != TYPE_OBSTACK (real_main_variant)) + { + type = copy_node (type); + TYPE_POINTER_TO (type) = TYPE_REFERENCE_TO (type) = 0; + } + + TYPE_MAIN_VARIANT (type) = real_main_variant; + pop_obstacks (); + } + return build_type_variant (type, constp, volatilep); +} + +/* Add OFFSET to all base types of T. + + OFFSET, which is a type offset, is number of bytes. + + Note that we don't have to worry about having two paths to the + same base type, since this type owns its association list. */ +void +propagate_binfo_offsets (binfo, offset) + tree binfo; + tree offset; +{ + tree binfos = BINFO_BASETYPES (binfo); + int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + for (i = 0; i < n_baselinks; /* note increment is done in the loop. */) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + + if (TREE_VIA_VIRTUAL (base_binfo)) + i += 1; + else + { + int j; + tree base_binfos = BINFO_BASETYPES (base_binfo); + tree delta; + + for (j = i+1; j < n_baselinks; j++) + if (! TREE_VIA_VIRTUAL (TREE_VEC_ELT (binfos, j))) + { + /* The next basetype offset must take into account the space + between the classes, not just the size of each class. */ + delta = size_binop (MINUS_EXPR, + BINFO_OFFSET (TREE_VEC_ELT (binfos, j)), + BINFO_OFFSET (base_binfo)); + break; + } + +#if 0 + if (BINFO_OFFSET_ZEROP (base_binfo)) + BINFO_OFFSET (base_binfo) = offset; + else + BINFO_OFFSET (base_binfo) + = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo), offset); +#else + BINFO_OFFSET (base_binfo) = offset; +#endif + if (base_binfos) + { + int k; + tree chain = NULL_TREE; + + /* Now unshare the structure beneath BASE_BINFO. */ + for (k = TREE_VEC_LENGTH (base_binfos)-1; + k >= 0; k--) + { + tree base_base_binfo = TREE_VEC_ELT (base_binfos, k); + if (! TREE_VIA_VIRTUAL (base_base_binfo)) + TREE_VEC_ELT (base_binfos, k) + = make_binfo (BINFO_OFFSET (base_base_binfo), + base_base_binfo, + BINFO_VTABLE (base_base_binfo), + BINFO_VIRTUALS (base_base_binfo), + chain); + chain = TREE_VEC_ELT (base_binfos, k); + TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo); + TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo); + BINFO_INHERITANCE_CHAIN (chain) = base_binfo; + } + /* Now propagate the offset to the base types. */ + propagate_binfo_offsets (base_binfo, offset); + } + + /* Go to our next class that counts for offset propagation. */ + i = j; + if (i < n_baselinks) + offset = size_binop (PLUS_EXPR, offset, delta); + } + } +} + +/* Compute the actual offsets that our virtual base classes + will have *for this type*. This must be performed after + the fields are laid out, since virtual baseclasses must + lay down at the end of the record. + + Returns the maximum number of virtual functions any of the virtual + baseclasses provide. */ +int +layout_vbasetypes (rec, max) + tree rec; + int max; +{ + /* Get all the virtual base types that this type uses. + The TREE_VALUE slot holds the virtual baseclass type. */ + tree vbase_types = get_vbase_types (rec); + +#ifdef STRUCTURE_SIZE_BOUNDARY + unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec)); +#else + unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec)); +#endif + int desired_align; + + /* Record size so far is CONST_SIZE + VAR_SIZE bits, + where CONST_SIZE is an integer + and VAR_SIZE is a tree expression. + If VAR_SIZE is null, the size is just CONST_SIZE. + Naturally we try to avoid using VAR_SIZE. */ + register unsigned const_size = 0; + register tree var_size = 0; + int nonvirtual_const_size; + tree nonvirtual_var_size; + + CLASSTYPE_VBASECLASSES (rec) = vbase_types; + + if (TREE_CODE (TYPE_SIZE (rec)) == INTEGER_CST) + const_size = TREE_INT_CST_LOW (TYPE_SIZE (rec)); + else + var_size = TYPE_SIZE (rec); + + nonvirtual_const_size = const_size; + nonvirtual_var_size = var_size; + + while (vbase_types) + { + tree basetype = BINFO_TYPE (vbase_types); + tree offset; + + desired_align = TYPE_ALIGN (basetype); + record_align = MAX (record_align, desired_align); + + if (const_size == 0) + offset = integer_zero_node; + else + { + /* Give each virtual base type the alignment it wants. */ + const_size = CEIL (const_size, TYPE_ALIGN (basetype)) + * TYPE_ALIGN (basetype); + offset = size_int (CEIL (const_size, BITS_PER_UNIT)); + } + + if (CLASSTYPE_VSIZE (basetype) > max) + max = CLASSTYPE_VSIZE (basetype); + BINFO_OFFSET (vbase_types) = offset; + + if (TREE_CODE (TYPE_SIZE (basetype)) == INTEGER_CST) + { + /* Every virtual baseclass takes a least a UNIT, so that we can + take it's address and get something different for each base. */ + const_size += MAX (BITS_PER_UNIT, + TREE_INT_CST_LOW (TYPE_SIZE (basetype)) + - TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype))); + } + else if (var_size == 0) + var_size = TYPE_SIZE (basetype); + else + var_size = size_binop (PLUS_EXPR, var_size, TYPE_SIZE (basetype)); + + vbase_types = TREE_CHAIN (vbase_types); + } + + if (const_size) + { + /* Because a virtual base might take a single byte above, + we have to re-adjust the total size to make sure it it + a multiple of the alignment. */ + /* Give the whole object the alignment it wants. */ + const_size = CEIL (const_size, record_align) * record_align; + } + + /* Set the alignment in the complete type. We don't set CLASSTYPE_ALIGN + here, as that is for this class, without any virtual base classes. */ + TYPE_ALIGN (rec) = record_align; + if (const_size != nonvirtual_const_size) + { + CLASSTYPE_VBASE_SIZE (rec) + = size_int (const_size - nonvirtual_const_size); + TYPE_SIZE (rec) = size_int (const_size); + } + + /* Now propagate offset information throughout the lattice + under the vbase type. */ + for (vbase_types = CLASSTYPE_VBASECLASSES (rec); vbase_types; + vbase_types = TREE_CHAIN (vbase_types)) + { + tree base_binfos = BINFO_BASETYPES (vbase_types); + + BINFO_INHERITANCE_CHAIN (vbase_types) = TYPE_BINFO (rec); + + if (base_binfos) + { + tree chain = NULL_TREE; + int j; + /* Now unshare the structure beneath BASE_BINFO. */ + + for (j = TREE_VEC_LENGTH (base_binfos)-1; + j >= 0; j--) + { + tree base_base_binfo = TREE_VEC_ELT (base_binfos, j); + if (! TREE_VIA_VIRTUAL (base_base_binfo)) + TREE_VEC_ELT (base_binfos, j) + = make_binfo (BINFO_OFFSET (base_base_binfo), + base_base_binfo, + BINFO_VTABLE (base_base_binfo), + BINFO_VIRTUALS (base_base_binfo), + chain); + chain = TREE_VEC_ELT (base_binfos, j); + TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo); + TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo); + BINFO_INHERITANCE_CHAIN (chain) = vbase_types; + } + + propagate_binfo_offsets (vbase_types, BINFO_OFFSET (vbase_types)); + } + } + + return max; +} + +/* Lay out the base types of a record type, REC. + Tentatively set the size and alignment of REC + according to the base types alone. + + Offsets for immediate nonvirtual baseclasses are also computed here. + + TYPE_BINFO (REC) should be NULL_TREE on entry, and this routine + creates a list of base_binfos in TYPE_BINFO (REC) from BINFOS. + + Returns list of virtual base classes in a FIELD_DECL chain. */ +tree +layout_basetypes (rec, binfos) + tree rec, binfos; +{ + /* Chain to hold all the new FIELD_DECLs which point at virtual + base classes. */ + tree vbase_decls = NULL_TREE; + +#ifdef STRUCTURE_SIZE_BOUNDARY + unsigned record_align = MAX (STRUCTURE_SIZE_BOUNDARY, TYPE_ALIGN (rec)); +#else + unsigned record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (rec)); +#endif + + /* Record size so far is CONST_SIZE + VAR_SIZE bits, where CONST_SIZE is + an integer and VAR_SIZE is a tree expression. If VAR_SIZE is null, + the size is just CONST_SIZE. Naturally we try to avoid using + VAR_SIZE. And so far, we've been successful. */ +#if 0 + register tree var_size = 0; +#endif + + register unsigned const_size = 0; + int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; + + /* Handle basetypes almost like fields, but record their + offsets differently. */ + + for (i = 0; i < n_baseclasses; i++) + { + int inc, desired_align, int_vbase_size; + register tree base_binfo = TREE_VEC_ELT (binfos, i); + register tree basetype = BINFO_TYPE (base_binfo); + tree decl, offset; + + if (TYPE_SIZE (basetype) == 0) + { +#if 0 + /* This error is now reported in xref_tag, thus giving better + location information. */ + error_with_aggr_type (base_binfo, + "base class `%s' has incomplete type"); + + TREE_VIA_PUBLIC (base_binfo) = 1; + TREE_VIA_PROTECTED (base_binfo) = 0; + TREE_VIA_VIRTUAL (base_binfo) = 0; + + /* Should handle this better so that + + class A; + class B: private A { virtual void F(); }; + + does not dump core when compiled. */ + my_friendly_abort (121); +#endif + continue; + } + + /* All basetypes are recorded in the association list of the + derived type. */ + + if (TREE_VIA_VIRTUAL (base_binfo)) + { + int j; + char *name = (char *)alloca (TYPE_NAME_LENGTH (basetype) + + sizeof (VBASE_NAME) + 1); + + /* The offset for a virtual base class is only used in computing + virtual function tables and for initializing virtual base + pointers. It is built once `get_vbase_types' is called. */ + + /* If this basetype can come from another vbase pointer + without an additional indirection, we will share + that pointer. If an indirection is involved, we + make our own pointer. */ + for (j = 0; j < n_baseclasses; j++) + { + tree other_base_binfo = TREE_VEC_ELT (binfos, j); + if (! TREE_VIA_VIRTUAL (other_base_binfo) + && binfo_member (basetype, + CLASSTYPE_VBASECLASSES (BINFO_TYPE (other_base_binfo)))) + goto got_it; + } + sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (basetype)); + decl = build_lang_decl (FIELD_DECL, get_identifier (name), + build_pointer_type (basetype)); + /* If you change any of the below, take a look at all the + other VFIELD_BASEs and VTABLE_BASEs in the code, and change + them too. */ + DECL_ASSEMBLER_NAME (decl) = get_identifier (VTABLE_BASE); + DECL_VIRTUAL_P (decl) = 1; + DECL_FIELD_CONTEXT (decl) = rec; + DECL_CLASS_CONTEXT (decl) = rec; + DECL_FCONTEXT (decl) = basetype; + DECL_SAVED_INSNS (decl) = NULL_RTX; + DECL_FIELD_SIZE (decl) = 0; + DECL_ALIGN (decl) = TYPE_ALIGN (ptr_type_node); + TREE_CHAIN (decl) = vbase_decls; + BINFO_VPTR_FIELD (base_binfo) = decl; + vbase_decls = decl; + + if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (basetype) + && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0)) == NULL_TREE) + { + warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0), + "destructor `%s' non-virtual"); + warning ("in inheritance relationship `%s: virtual %s'", + TYPE_NAME_STRING (rec), + TYPE_NAME_STRING (basetype)); + } + got_it: + /* The space this decl occupies has already been accounted for. */ + continue; + } + + if (const_size == 0) + offset = integer_zero_node; + else + { + /* Give each base type the alignment it wants. */ + const_size = CEIL (const_size, TYPE_ALIGN (basetype)) + * TYPE_ALIGN (basetype); + offset = size_int ((const_size + BITS_PER_UNIT - 1) / BITS_PER_UNIT); + +#if 0 + /* bpk: Disabled this check until someone is willing to + claim it as theirs and explain exactly what circumstances + warrant the warning. */ + if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (basetype) + && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0)) == NULL_TREE) + { + warning_with_decl (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0), + "destructor `%s' non-virtual"); + warning ("in inheritance relationship `%s:%s %s'", + TYPE_NAME_STRING (rec), + TREE_VIA_VIRTUAL (base_binfo) ? " virtual" : "", + TYPE_NAME_STRING (basetype)); + } +#endif + } + BINFO_OFFSET (base_binfo) = offset; + if (CLASSTYPE_VSIZE (basetype)) + { + BINFO_VTABLE (base_binfo) = TYPE_BINFO_VTABLE (basetype); + BINFO_VIRTUALS (base_binfo) = TYPE_BINFO_VIRTUALS (basetype); + } + TREE_CHAIN (base_binfo) = TYPE_BINFO (rec); + TYPE_BINFO (rec) = base_binfo; + + /* Add only the amount of storage not present in + the virtual baseclasses. */ + + int_vbase_size = TREE_INT_CST_LOW (CLASSTYPE_VBASE_SIZE (basetype)); + if (TREE_INT_CST_LOW (TYPE_SIZE (basetype)) > int_vbase_size) + { + inc = MAX (record_align, + (TREE_INT_CST_LOW (TYPE_SIZE (basetype)) + - int_vbase_size)); + + /* Record must have at least as much alignment as any field. */ + desired_align = TYPE_ALIGN (basetype); + record_align = MAX (record_align, desired_align); + + const_size += inc; + } + } + + if (const_size) + CLASSTYPE_SIZE (rec) = size_int (const_size); + else + CLASSTYPE_SIZE (rec) = integer_zero_node; + CLASSTYPE_ALIGN (rec) = record_align; + + return vbase_decls; +} + +/* Hashing of lists so that we don't make duplicates. + The entry point is `list_hash_canon'. */ + +/* Each hash table slot is a bucket containing a chain + of these structures. */ + +struct list_hash +{ + struct list_hash *next; /* Next structure in the bucket. */ + int hashcode; /* Hash code of this list. */ + tree list; /* The list recorded here. */ +}; + +/* Now here is the hash table. When recording a list, it is added + to the slot whose index is the hash code mod the table size. + Note that the hash table is used for several kinds of lists. + While all these live in the same table, they are completely independent, + and the hash code is computed differently for each of these. */ + +#define TYPE_HASH_SIZE 59 +struct list_hash *list_hash_table[TYPE_HASH_SIZE]; + +/* Compute a hash code for a list (chain of TREE_LIST nodes + with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the + TREE_COMMON slots), by adding the hash codes of the individual entries. */ + +int +list_hash (list) + tree list; +{ + register int hashcode = 0; + + if (TREE_CHAIN (list)) + hashcode += TYPE_HASH (TREE_CHAIN (list)); + + if (TREE_VALUE (list)) + hashcode += TYPE_HASH (TREE_VALUE (list)); + else + hashcode += 1007; + if (TREE_PURPOSE (list)) + hashcode += TYPE_HASH (TREE_PURPOSE (list)); + else + hashcode += 1009; + return hashcode; +} + +/* Look in the type hash table for a type isomorphic to TYPE. + If one is found, return it. Otherwise return 0. */ + +tree +list_hash_lookup (hashcode, list) + int hashcode; + tree list; +{ + register struct list_hash *h; + for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next) + if (h->hashcode == hashcode + && TREE_VIA_VIRTUAL (h->list) == TREE_VIA_VIRTUAL (list) + && TREE_VIA_PUBLIC (h->list) == TREE_VIA_PUBLIC (list) + && TREE_VIA_PROTECTED (h->list) == TREE_VIA_PROTECTED (list) + && TREE_PURPOSE (h->list) == TREE_PURPOSE (list) + && TREE_VALUE (h->list) == TREE_VALUE (list) + && TREE_CHAIN (h->list) == TREE_CHAIN (list)) + { + my_friendly_assert (TREE_TYPE (h->list) == TREE_TYPE (list), 299); + return h->list; + } + return 0; +} + +/* Add an entry to the list-hash-table + for a list TYPE whose hash code is HASHCODE. */ + +void +list_hash_add (hashcode, list) + int hashcode; + tree list; +{ + register struct list_hash *h; + + h = (struct list_hash *) obstack_alloc (&class_obstack, sizeof (struct list_hash)); + h->hashcode = hashcode; + h->list = list; + h->next = list_hash_table[hashcode % TYPE_HASH_SIZE]; + list_hash_table[hashcode % TYPE_HASH_SIZE] = h; +} + +/* Given TYPE, and HASHCODE its hash code, return the canonical + object for an identical list if one already exists. + Otherwise, return TYPE, and record it as the canonical object + if it is a permanent object. + + To use this function, first create a list of the sort you want. + Then compute its hash code from the fields of the list that + make it different from other similar lists. + Then call this function and use the value. + This function frees the list you pass in if it is a duplicate. */ + +/* Set to 1 to debug without canonicalization. Never set by program. */ +static int debug_no_list_hash = 0; + +tree +list_hash_canon (hashcode, list) + int hashcode; + tree list; +{ + tree t1; + + if (debug_no_list_hash) + return list; + + t1 = list_hash_lookup (hashcode, list); + if (t1 != 0) + { + obstack_free (&class_obstack, list); + return t1; + } + + /* If this is a new list, record it for later reuse. */ + list_hash_add (hashcode, list); + + return list; +} + +tree +hash_tree_cons (via_public, via_virtual, via_protected, purpose, value, chain) + int via_public, via_virtual, via_protected; + tree purpose, value, chain; +{ + struct obstack *ambient_obstack = current_obstack; + tree t; + int hashcode; + + current_obstack = &class_obstack; + t = tree_cons (purpose, value, chain); + TREE_VIA_PUBLIC (t) = via_public; + TREE_VIA_PROTECTED (t) = via_protected; + TREE_VIA_VIRTUAL (t) = via_virtual; + hashcode = list_hash (t); + t = list_hash_canon (hashcode, t); + current_obstack = ambient_obstack; + return t; +} + +/* Constructor for hashed lists. */ +tree +hash_tree_chain (value, chain) + tree value, chain; +{ + struct obstack *ambient_obstack = current_obstack; + tree t; + int hashcode; + + current_obstack = &class_obstack; + t = tree_cons (NULL_TREE, value, chain); + hashcode = list_hash (t); + t = list_hash_canon (hashcode, t); + current_obstack = ambient_obstack; + return t; +} + +/* Similar, but used for concatenating two lists. */ +tree +hash_chainon (list1, list2) + tree list1, list2; +{ + if (list2 == 0) + return list1; + if (list1 == 0) + return list2; + if (TREE_CHAIN (list1) == NULL_TREE) + return hash_tree_chain (TREE_VALUE (list1), list2); + return hash_tree_chain (TREE_VALUE (list1), + hash_chainon (TREE_CHAIN (list1), list2)); +} + +static tree +get_identifier_list (value) + tree value; +{ + tree list = IDENTIFIER_AS_LIST (value); + if (list != NULL_TREE + && (TREE_CODE (list) != TREE_LIST + || TREE_VALUE (list) != value)) + list = NULL_TREE; + else if (IDENTIFIER_HAS_TYPE_VALUE (value) + && TREE_CODE (IDENTIFIER_TYPE_VALUE (value)) == RECORD_TYPE + && IDENTIFIER_TYPE_VALUE (value) + == TYPE_MAIN_VARIANT (IDENTIFIER_TYPE_VALUE (value))) + { + tree type = IDENTIFIER_TYPE_VALUE (value); + + if (TYPE_PTRMEMFUNC_P (type)) + list = NULL_TREE; + else if (type == current_class_type) + /* Don't mess up the constructor name. */ + list = tree_cons (NULL_TREE, value, NULL_TREE); + else + { + register tree id; + /* This will return the correct thing for regular types, + nested types, and templates. Yay! */ + if (TYPE_NESTED_NAME (type)) + id = TYPE_NESTED_NAME (type); + else + id = TYPE_IDENTIFIER (type); + + if (CLASSTYPE_ID_AS_LIST (type) == NULL_TREE) + CLASSTYPE_ID_AS_LIST (type) + = perm_tree_cons (NULL_TREE, id, NULL_TREE); + list = CLASSTYPE_ID_AS_LIST (type); + } + } + return list; +} + +tree +get_decl_list (value) + tree value; +{ + tree list = NULL_TREE; + + if (TREE_CODE (value) == IDENTIFIER_NODE) + list = get_identifier_list (value); + else if (TREE_CODE (value) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (value)) + list = CLASSTYPE_AS_LIST (value); + + if (list != NULL_TREE) + { + my_friendly_assert (TREE_CHAIN (list) == NULL_TREE, 301); + return list; + } + + return build_decl_list (NULL_TREE, value); +} + +/* Look in the type hash table for a type isomorphic to + `build_tree_list (NULL_TREE, VALUE)'. + If one is found, return it. Otherwise return 0. */ + +tree +list_hash_lookup_or_cons (value) + tree value; +{ + register int hashcode = TYPE_HASH (value); + register struct list_hash *h; + struct obstack *ambient_obstack; + tree list = NULL_TREE; + + if (TREE_CODE (value) == IDENTIFIER_NODE) + list = get_identifier_list (value); + else if (TREE_CODE (value) == TYPE_DECL + && TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (TREE_TYPE (value))) + list = CLASSTYPE_ID_AS_LIST (TREE_TYPE (value)); + else if (TREE_CODE (value) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (value)) + list = CLASSTYPE_AS_LIST (value); + + if (list != NULL_TREE) + { + my_friendly_assert (TREE_CHAIN (list) == NULL_TREE, 302); + return list; + } + + if (debug_no_list_hash) + return hash_tree_chain (value, NULL_TREE); + + for (h = list_hash_table[hashcode % TYPE_HASH_SIZE]; h; h = h->next) + if (h->hashcode == hashcode + && TREE_VIA_VIRTUAL (h->list) == 0 + && TREE_VIA_PUBLIC (h->list) == 0 + && TREE_VIA_PROTECTED (h->list) == 0 + && TREE_PURPOSE (h->list) == 0 + && TREE_VALUE (h->list) == value) + { + my_friendly_assert (TREE_TYPE (h->list) == 0, 303); + my_friendly_assert (TREE_CHAIN (h->list) == 0, 304); + return h->list; + } + + ambient_obstack = current_obstack; + current_obstack = &class_obstack; + list = build_tree_list (NULL_TREE, value); + list_hash_add (hashcode, list); + current_obstack = ambient_obstack; + return list; +} + +/* Build an association between TYPE and some parameters: + + OFFSET is the offset added to `this' to convert it to a pointer + of type `TYPE *' + + BINFO is the base binfo to use, if we are deriving from one. This + is necessary, as we want specialized parent binfos from base + classes, so that the VTABLE_NAMEs of bases are for the most derived + type, instead of of the simple type. + + VTABLE is the virtual function table with which to initialize + sub-objects of type TYPE. + + VIRTUALS are the virtual functions sitting in VTABLE. + + CHAIN are more associations we must retain. */ + +tree +make_binfo (offset, binfo, vtable, virtuals, chain) + tree offset, binfo; + tree vtable, virtuals; + tree chain; +{ + tree new_binfo = make_tree_vec (6); + tree type; + + if (TREE_CODE (binfo) == TREE_VEC) + type = BINFO_TYPE (binfo); + else + { + type = binfo; + binfo = TYPE_BINFO (binfo); + } + + TREE_CHAIN (new_binfo) = chain; + if (chain) + TREE_USED (new_binfo) = TREE_USED (chain); + + TREE_TYPE (new_binfo) = TYPE_MAIN_VARIANT (type); + BINFO_OFFSET (new_binfo) = offset; + BINFO_VTABLE (new_binfo) = vtable; + BINFO_VIRTUALS (new_binfo) = virtuals; + BINFO_VPTR_FIELD (new_binfo) = NULL_TREE; + + if (binfo && BINFO_BASETYPES (binfo) != NULL_TREE) + BINFO_BASETYPES (new_binfo) = copy_node (BINFO_BASETYPES (binfo)); + return new_binfo; +} + +/* Return the binfo value for ELEM in TYPE. */ + +tree +binfo_value (elem, type) + tree elem; + tree type; +{ + if (get_base_distance (elem, type, 0, (tree *)0) == -2) + compiler_error ("base class `%s' ambiguous in binfo_value", + TYPE_NAME_STRING (elem)); + if (elem == type) + return TYPE_BINFO (type); + if (TREE_CODE (elem) == RECORD_TYPE && TYPE_BINFO (elem) == type) + return type; + return get_binfo (elem, type, 0); +} + +tree +reverse_path (path) + tree path; +{ + register tree prev = 0, tmp, next; + for (tmp = path; tmp; tmp = next) + { + next = BINFO_INHERITANCE_CHAIN (tmp); + BINFO_INHERITANCE_CHAIN (tmp) = prev; + prev = tmp; + } + return prev; +} + +tree +virtual_member (elem, list) + tree elem; + tree list; +{ + tree t; + tree rval, nval; + + for (t = list; t; t = TREE_CHAIN (t)) + if (elem == BINFO_TYPE (t)) + return t; + rval = 0; + for (t = list; t; t = TREE_CHAIN (t)) + { + tree binfos = BINFO_BASETYPES (t); + int i; + + if (binfos != NULL_TREE) + for (i = TREE_VEC_LENGTH (binfos)-1; i >= 0; i--) + { + nval = binfo_value (elem, BINFO_TYPE (TREE_VEC_ELT (binfos, i))); + if (nval) + { + if (rval && BINFO_OFFSET (nval) != BINFO_OFFSET (rval)) + my_friendly_abort (104); + rval = nval; + } + } + } + return rval; +} + +void +debug_binfo (elem) + tree elem; +{ + unsigned HOST_WIDE_INT n; + tree virtuals; + + fprintf (stderr, "type \"%s\"; offset = %d\n", + TYPE_NAME_STRING (BINFO_TYPE (elem)), + TREE_INT_CST_LOW (BINFO_OFFSET (elem))); + fprintf (stderr, "vtable type:\n"); + debug_tree (BINFO_TYPE (elem)); + if (BINFO_VTABLE (elem)) + fprintf (stderr, "vtable decl \"%s\"\n", IDENTIFIER_POINTER (DECL_NAME (BINFO_VTABLE (elem)))); + else + fprintf (stderr, "no vtable decl yet\n"); + fprintf (stderr, "virtuals:\n"); + virtuals = BINFO_VIRTUALS (elem); + + n = skip_rtti_stuff (&virtuals); + + while (virtuals) + { + tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0); + fprintf (stderr, "%s [%d =? %d]\n", + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)), + n, TREE_INT_CST_LOW (DECL_VINDEX (fndecl))); + ++n; + virtuals = TREE_CHAIN (virtuals); + } +} + +/* Return the length of a chain of nodes chained through DECL_CHAIN. + We expect a null pointer to mark the end of the chain. + This is the Lisp primitive `length'. */ + +int +decl_list_length (t) + tree t; +{ + register tree tail; + register int len = 0; + + my_friendly_assert (TREE_CODE (t) == FUNCTION_DECL + || TREE_CODE (t) == TEMPLATE_DECL, 300); + for (tail = t; tail; tail = DECL_CHAIN (tail)) + len++; + + return len; +} + +int +count_functions (t) + tree t; +{ + if (TREE_CODE (t) == FUNCTION_DECL) + return 1; + else if (TREE_CODE (t) == TREE_LIST) + return decl_list_length (TREE_VALUE (t)); + + my_friendly_abort (359); + return 0; +} + +/* Like value_member, but for DECL_CHAINs. */ +tree +decl_value_member (elem, list) + tree elem, list; +{ + while (list) + { + if (elem == list) + return list; + list = DECL_CHAIN (list); + } + return NULL_TREE; +} + +int +is_overloaded_fn (x) + tree x; +{ + if (TREE_CODE (x) == FUNCTION_DECL) + return 1; + + if (TREE_CODE (x) == TREE_LIST + && (TREE_CODE (TREE_VALUE (x)) == FUNCTION_DECL + || TREE_CODE (TREE_VALUE (x)) == TEMPLATE_DECL)) + return 1; + + return 0; +} + +int +really_overloaded_fn (x) + tree x; +{ + if (TREE_CODE (x) == TREE_LIST + && (TREE_CODE (TREE_VALUE (x)) == FUNCTION_DECL + || TREE_CODE (TREE_VALUE (x)) == TEMPLATE_DECL)) + return 1; + + return 0; +} + +tree +get_first_fn (from) + tree from; +{ + if (TREE_CODE (from) == FUNCTION_DECL) + return from; + + my_friendly_assert (TREE_CODE (from) == TREE_LIST, 9); + + return TREE_VALUE (from); +} + +tree +fnaddr_from_vtable_entry (entry) + tree entry; +{ + if (flag_vtable_thunks) + { + tree func = entry; + if (TREE_CODE (func) == ADDR_EXPR) + func = TREE_OPERAND (func, 0); + if (TREE_CODE (func) == THUNK_DECL) + return DECL_INITIAL (func); + else + return entry; + } + else + return TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (entry)))); +} + +void +set_fnaddr_from_vtable_entry (entry, value) + tree entry, value; +{ + if (flag_vtable_thunks) + abort (); + else + TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (entry)))) = value; +} + +tree +function_arg_chain (t) + tree t; +{ + return TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (t))); +} + +int +promotes_to_aggr_type (t, code) + tree t; + enum tree_code code; +{ + if (TREE_CODE (t) == code) + t = TREE_TYPE (t); + return IS_AGGR_TYPE (t); +} + +int +is_aggr_type_2 (t1, t2) + tree t1, t2; +{ + if (TREE_CODE (t1) != TREE_CODE (t2)) + return 0; + return IS_AGGR_TYPE (t1) && IS_AGGR_TYPE (t2); +} + +/* Give message using types TYPE1 and TYPE2 as arguments. + PFN is the function which will print the message; + S is the format string for PFN to use. */ +void +message_2_types (pfn, s, type1, type2) + void (*pfn) (); + char *s; + tree type1, type2; +{ + tree name1 = TYPE_NAME (type1); + tree name2 = TYPE_NAME (type2); + if (TREE_CODE (name1) == TYPE_DECL) + name1 = DECL_NAME (name1); + if (TREE_CODE (name2) == TYPE_DECL) + name2 = DECL_NAME (name2); + (*pfn) (s, IDENTIFIER_POINTER (name1), IDENTIFIER_POINTER (name2)); +} + +#define PRINT_RING_SIZE 4 + +char * +lang_printable_name (decl) + tree decl; +{ + static tree decl_ring[PRINT_RING_SIZE]; + static char *print_ring[PRINT_RING_SIZE]; + static int ring_counter; + int i; + + /* Only cache functions. */ + if (TREE_CODE (decl) != FUNCTION_DECL + || DECL_LANG_SPECIFIC (decl) == 0) + return decl_as_string (decl, 1); + + /* See if this print name is lying around. */ + for (i = 0; i < PRINT_RING_SIZE; i++) + if (decl_ring[i] == decl) + /* yes, so return it. */ + return print_ring[i]; + + if (++ring_counter == PRINT_RING_SIZE) + ring_counter = 0; + + if (current_function_decl != NULL_TREE) + { + if (decl_ring[ring_counter] == current_function_decl) + ring_counter += 1; + if (ring_counter == PRINT_RING_SIZE) + ring_counter = 0; + if (decl_ring[ring_counter] == current_function_decl) + my_friendly_abort (106); + } + + if (print_ring[ring_counter]) + free (print_ring[ring_counter]); + + { + int print_ret_type_p + = (!DECL_CONSTRUCTOR_P (decl) + && !DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))); + + char *name = (char *)decl_as_string (decl, print_ret_type_p); + print_ring[ring_counter] = (char *)malloc (strlen (name) + 1); + strcpy (print_ring[ring_counter], name); + decl_ring[ring_counter] = decl; + } + return print_ring[ring_counter]; +} + +/* Comparison function for sorting identifiers in RAISES lists. + Note that because IDENTIFIER_NODEs are unique, we can sort + them by address, saving an indirection. */ +static int +id_cmp (p1, p2) + tree *p1, *p2; +{ + return (HOST_WIDE_INT)TREE_VALUE (*p1) - (HOST_WIDE_INT)TREE_VALUE (*p2); +} + +/* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions + listed in RAISES. */ +tree +build_exception_variant (type, raises) + tree type; + tree raises; +{ + int i; + tree v = TYPE_MAIN_VARIANT (type); + tree t, t2, cname; + tree *a = (tree *)alloca ((list_length (raises)+1) * sizeof (tree)); + int constp = TYPE_READONLY (type); + int volatilep = TYPE_VOLATILE (type); + + for (v = TYPE_NEXT_VARIANT (v); v; v = TYPE_NEXT_VARIANT (v)) + { + if (TYPE_READONLY (v) != constp + || TYPE_VOLATILE (v) != volatilep) + continue; + + /* @@ This should do set equality, not exact match. */ + if (simple_cst_list_equal (TYPE_RAISES_EXCEPTIONS (v), raises)) + /* List of exceptions raised matches previously found list. + + @@ Nice to free up storage used in consing up the + @@ list of exceptions raised. */ + return v; + } + + /* Need to build a new variant. */ + v = copy_node (type); + TYPE_NEXT_VARIANT (v) = TYPE_NEXT_VARIANT (type); + TYPE_NEXT_VARIANT (type) = v; + if (raises && ! TREE_PERMANENT (raises)) + { + push_obstacks_nochange (); + end_temporary_allocation (); + raises = copy_list (raises); + pop_obstacks (); + } + TYPE_RAISES_EXCEPTIONS (v) = raises; + return v; +} + +/* Subroutine of copy_to_permanent + + Assuming T is a node build bottom-up, make it all exist on + permanent obstack, if it is not permanent already. */ + +tree +mapcar (t, func) + tree t; + tree (*func)(); +{ + enum tree_code code; + tree tmp; + + if (t == NULL_TREE) + return t; + + if (tmp = func (t), tmp != NULL_TREE) + return tmp; + + switch (code = TREE_CODE (t)) + { + case ERROR_MARK: + return error_mark_node; + + case VAR_DECL: + case FUNCTION_DECL: + case CONST_DECL: + break; + + case PARM_DECL: + { + tree chain = TREE_CHAIN (t); + t = copy_node (t); + TREE_CHAIN (t) = mapcar (chain, func); + TREE_TYPE (t) = mapcar (TREE_TYPE (t), func); + DECL_INITIAL (t) = mapcar (DECL_INITIAL (t), func); + DECL_SIZE (t) = mapcar (DECL_SIZE (t), func); + return t; + } + + case TREE_LIST: + { + tree chain = TREE_CHAIN (t); + t = copy_node (t); + TREE_PURPOSE (t) = mapcar (TREE_PURPOSE (t), func); + TREE_VALUE (t) = mapcar (TREE_VALUE (t), func); + TREE_CHAIN (t) = mapcar (chain, func); + return t; + } + + case TREE_VEC: + { + int len = TREE_VEC_LENGTH (t); + + t = copy_node (t); + while (len--) + TREE_VEC_ELT (t, len) = mapcar (TREE_VEC_ELT (t, len), func); + return t; + } + + case INTEGER_CST: + case REAL_CST: + case STRING_CST: + return copy_node (t); + + case COND_EXPR: + case TARGET_EXPR: + case NEW_EXPR: + t = copy_node (t); + TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func); + TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func); + TREE_OPERAND (t, 2) = mapcar (TREE_OPERAND (t, 2), func); + return t; + + case SAVE_EXPR: + t = copy_node (t); + TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func); + return t; + + case MODIFY_EXPR: + case PLUS_EXPR: + case MINUS_EXPR: + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + case MIN_EXPR: + case MAX_EXPR: + case LSHIFT_EXPR: + case RSHIFT_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + case BIT_AND_EXPR: + case BIT_ANDTC_EXPR: + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case LT_EXPR: + case LE_EXPR: + case GT_EXPR: + case GE_EXPR: + case EQ_EXPR: + case NE_EXPR: + case CEIL_DIV_EXPR: + case FLOOR_DIV_EXPR: + case ROUND_DIV_EXPR: + case CEIL_MOD_EXPR: + case FLOOR_MOD_EXPR: + case ROUND_MOD_EXPR: + case COMPOUND_EXPR: + case PREDECREMENT_EXPR: + case PREINCREMENT_EXPR: + case POSTDECREMENT_EXPR: + case POSTINCREMENT_EXPR: + case CALL_EXPR: + t = copy_node (t); + TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func); + TREE_OPERAND (t, 1) = mapcar (TREE_OPERAND (t, 1), func); + return t; + + case CONVERT_EXPR: + case ADDR_EXPR: + case INDIRECT_REF: + case NEGATE_EXPR: + case BIT_NOT_EXPR: + case TRUTH_NOT_EXPR: + case NOP_EXPR: + case COMPONENT_REF: + t = copy_node (t); + TREE_OPERAND (t, 0) = mapcar (TREE_OPERAND (t, 0), func); + return t; + + case POINTER_TYPE: + return build_pointer_type (mapcar (TREE_TYPE (t), func)); + case REFERENCE_TYPE: + return build_reference_type (mapcar (TREE_TYPE (t), func)); + case FUNCTION_TYPE: + return build_function_type (mapcar (TREE_TYPE (t), func), + mapcar (TYPE_ARG_TYPES (t), func)); + case ARRAY_TYPE: + return build_array_type (mapcar (TREE_TYPE (t), func), + mapcar (TYPE_DOMAIN (t), func)); + case INTEGER_TYPE: + return build_index_type (mapcar (TYPE_MAX_VALUE (t), func)); + + case OFFSET_TYPE: + return build_offset_type (mapcar (TYPE_OFFSET_BASETYPE (t), func), + mapcar (TREE_TYPE (t), func)); + case METHOD_TYPE: + return build_method_type + (mapcar (TYPE_METHOD_BASETYPE (t), func), + build_function_type + (mapcar (TREE_TYPE (t), func), + mapcar (TREE_CHAIN (TYPE_ARG_TYPES (t)), func))); + + case RECORD_TYPE: + if (TYPE_PTRMEMFUNC_P (t)) + return build_ptrmemfunc_type + (mapcar (TYPE_PTRMEMFUNC_FN_TYPE (t), func)); + /* else fall through */ + + /* This list is incomplete, but should suffice for now. + It is very important that `sorry' does not call + `report_error_function'. That could cause an infinite loop. */ + default: + sorry ("initializer contains unrecognized tree code"); + return error_mark_node; + + } + my_friendly_abort (107); + /* NOTREACHED */ + return NULL_TREE; +} + +static tree +perm_manip (t) + tree t; +{ + if (TREE_PERMANENT (t)) + return t; + return NULL_TREE; +} + +/* Assuming T is a node built bottom-up, make it all exist on + permanent obstack, if it is not permanent already. */ +tree +copy_to_permanent (t) + tree t; +{ + register struct obstack *ambient_obstack = current_obstack; + register struct obstack *ambient_saveable_obstack = saveable_obstack; + int resume; + + if (t == NULL_TREE || TREE_PERMANENT (t)) + return t; + + saveable_obstack = &permanent_obstack; + current_obstack = saveable_obstack; + resume = suspend_momentary (); + + t = mapcar (t, perm_manip); + + resume_momentary (resume); + current_obstack = ambient_obstack; + saveable_obstack = ambient_saveable_obstack; + + return t; +} + +void +print_lang_statistics () +{ + extern struct obstack maybepermanent_obstack; + print_obstack_statistics ("class_obstack", &class_obstack); + print_obstack_statistics ("permanent_obstack", &permanent_obstack); + print_obstack_statistics ("maybepermanent_obstack", &maybepermanent_obstack); + print_search_statistics (); + print_class_statistics (); +} + +/* This is used by the `assert' macro. It is provided in libgcc.a, + which `cc' doesn't know how to link. Note that the C++ front-end + no longer actually uses the `assert' macro (instead, it calls + my_friendly_assert). But all of the back-end files still need this. */ +void +__eprintf (string, expression, line, filename) +#ifdef __STDC__ + const char *string; + const char *expression; + unsigned line; + const char *filename; +#else + char *string; + char *expression; + unsigned line; + char *filename; +#endif +{ + fprintf (stderr, string, expression, line, filename); + fflush (stderr); + abort (); +} + +/* Return, as an INTEGER_CST node, the number of elements for + TYPE (which is an ARRAY_TYPE). This counts only elements of the top array. */ + +tree +array_type_nelts_top (type) + tree type; +{ + return fold (build (PLUS_EXPR, sizetype, + array_type_nelts (type), + integer_one_node)); +} + +/* Return, as an INTEGER_CST node, the number of elements for + TYPE (which is an ARRAY_TYPE). This one is a recursive count of all + ARRAY_TYPEs that are clumped together. */ + +tree +array_type_nelts_total (type) + tree type; +{ + tree sz = array_type_nelts_top (type); + type = TREE_TYPE (type); + while (TREE_CODE (type) == ARRAY_TYPE) + { + tree n = array_type_nelts_top (type); + sz = fold (build (MULT_EXPR, sizetype, sz, n)); + type = TREE_TYPE (type); + } + return sz; +} + +static +tree +bot_manip (t) + tree t; +{ + if (TREE_CODE (t) != TREE_LIST && ! TREE_SIDE_EFFECTS (t)) + return t; + else if (TREE_CODE (t) == TARGET_EXPR) + return build_cplus_new (TREE_TYPE (t), + break_out_target_exprs (TREE_OPERAND (t, 1)), 0); + return NULL_TREE; +} + +/* Actually, we'll just clean out the target exprs for the moment. */ +tree +break_out_target_exprs (t) + tree t; +{ + return mapcar (t, bot_manip); +} + +tree +unsave_expr (expr) + tree expr; +{ + tree t; + + t = build1 (UNSAVE_EXPR, TREE_TYPE (expr), expr); + TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (expr); + return t; +} + +/* Modify a tree in place so that all the evaluate only once things + are cleared out. Return the EXPR given. */ +tree +unsave_expr_now (expr) + tree expr; +{ + enum tree_code code; + register int i; + + if (expr == NULL_TREE) + return expr; + + code = TREE_CODE (expr); + switch (code) + { + case SAVE_EXPR: + SAVE_EXPR_RTL (expr) = NULL_RTX; + break; + + case TARGET_EXPR: + sorry ("TARGET_EXPR reused inside UNSAVE_EXPR"); + break; + + case RTL_EXPR: + warning ("RTL_EXPR reused inside UNSAVE_EXPR"); + RTL_EXPR_SEQUENCE (expr) = NULL_RTX; + break; + + case CALL_EXPR: + CALL_EXPR_RTL (expr) = NULL_RTX; + if (TREE_OPERAND (expr, 1) + && TREE_CODE (TREE_OPERAND (expr, 1)) == TREE_LIST) + { + tree exp = TREE_OPERAND (expr, 1); + while (exp) + { + unsave_expr_now (TREE_VALUE (exp)); + exp = TREE_CHAIN (exp); + } + } + break; + + case WITH_CLEANUP_EXPR: + warning ("WITH_CLEANUP_EXPR reused inside UNSAVE_EXPR"); + RTL_EXPR_RTL (expr) = NULL_RTX; + break; + } + + switch (TREE_CODE_CLASS (code)) + { + case 'c': /* a constant */ + case 't': /* a type node */ + case 'x': /* something random, like an identifier or an ERROR_MARK. */ + case 'd': /* A decl node */ + case 'b': /* A block node */ + return expr; + + case 'e': /* an expression */ + case 'r': /* a reference */ + case 's': /* an expression with side effects */ + case '<': /* a comparison expression */ + case '2': /* a binary arithmetic expression */ + case '1': /* a unary arithmetic expression */ + for (i = tree_code_length[(int) code] - 1; i >= 0; i--) + unsave_expr_now (TREE_OPERAND (expr, i)); + return expr; + + default: + my_friendly_abort (999); + } +} + +/* Since cleanup may have SAVE_EXPRs in it, we protect it with an + UNSAVE_EXPR as the backend cannot yet handle SAVE_EXPRs in cleanups + by itself. */ +int +cp_expand_decl_cleanup (decl, cleanup) + tree decl, cleanup; +{ + return expand_decl_cleanup (decl, unsave_expr (cleanup)); +} diff --git a/contrib/gcc/cp/tree.def b/contrib/gcc/cp/tree.def new file mode 100644 index 00000000000..82b7954e29c --- /dev/null +++ b/contrib/gcc/cp/tree.def @@ -0,0 +1,116 @@ +/* This file contains the definitions and documentation for the + additional tree codes used in the GNU C++ compiler (see tree.def + for the standard codes). + Copyright (C) 1987, 1988, 1990, 1993 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Reference to the contents of an offset + (a value whose type is an OFFSET_TYPE). + Operand 0 is the object within which the offset is taken. + Operand 1 is the offset. The language independent OFFSET_REF + just won't work for us. */ +DEFTREECODE (CP_OFFSET_REF, "cp_offset_ref", "r", 2) + +/* For DELETE_EXPR, operand 0 is the store to be destroyed. + Operand 1 is the value to pass to the destroying function + saying whether the store should be deallocated as well. */ +DEFTREECODE (DELETE_EXPR, "dl_expr", "e", 2) +DEFTREECODE (VEC_DELETE_EXPR, "vec_dl_expr", "e", 2) + +/* For a UNSAVE_EXPR, operand 0 is the value to unsave. By unsave, we + mean that all _EXPRs such as TARGET_EXPRs, SAVE_EXPRs, + WITH_CLEANUP_EXPRs, CALL_EXPRs and RTL_EXPRs, that are protected + from being evaluated more than once should be reset so that a new + expand_expr call of this expr will cause those to be re-evaluated. + This is useful when we want to reuse a tree in different places, + but where we must re-expand. */ +DEFTREECODE (UNSAVE_EXPR, "unsave_expr", "e", 1) + +/* Value is reference to particular overloaded class method. + Operand 0 is the class name (an IDENTIFIER_NODE); + operand 1 is the field (also an IDENTIFIER_NODE). + The COMPLEXITY field holds the class level (usually 0). */ +DEFTREECODE (SCOPE_REF, "scope_ref", "r", 2) + +/* When composing an object with a member, this is the result. + Operand 0 is the object. Operand 1 is the member (usually + a dereferenced pointer to member). */ +DEFTREECODE (MEMBER_REF, "member_ref", "r", 2) + +/* Type conversion operator in C++. TREE_TYPE is type that this + operator converts to. Operand is expression to be converted. */ +DEFTREECODE (TYPE_EXPR, "type_expr", "e", 1) + +/* For CPLUS_NEW_EXPR, operand 0 is function which performs initialization, + operand 1 is argument list to initialization function, + and operand 2 is the slot which was allocated for this expression. */ +DEFTREECODE (NEW_EXPR, "nw_expr", "e", 3) +DEFTREECODE (VEC_NEW_EXPR, "vec_nw_expr", "e", 3) + +/* A throw expression. operand 0 is the expression, if there was one, + else it is NULL_TREE. */ +DEFTREECODE (THROW_EXPR, "throw_expr", "e", 1) + +/* Template definition. The following fields have the specified uses, + although there are other macros in cp-tree.h that should be used for + accessing this data. + DECL_ARGUMENTS template parm vector + DECL_TEMPLATE_INFO template text &c + DECL_VINDEX list of instantiations already produced; + only done for functions so far + For class template: + DECL_INITIAL associated templates (methods &c) + DECL_RESULT null + For non-class templates: + TREE_TYPE type of object to be constructed + DECL_RESULT decl for object to be created + (e.g., FUNCTION_DECL with tmpl parms used) + */ +DEFTREECODE (TEMPLATE_DECL, "template_decl", "d", 0) + +/* Index into a template parameter list. This parameter must be a type. + Use TYPE_FIELDS to find parmlist and index. */ +DEFTREECODE (TEMPLATE_TYPE_PARM, "template_type_parm", "t", 0) + +/* Index into a template parameter list. This parameter must not be a + type. */ +DEFTREECODE (TEMPLATE_CONST_PARM, "template_const_parm", "c", 2) + +/* For uninstantiated parameterized types. + TYPE_VALUES tree list: + TREE_PURPOSE template decl + TREE_VALUE parm vector + TREE_CHAIN null + Other useful fields to be defined later. */ +DEFTREECODE (UNINSTANTIATED_P_TYPE, "uninstantiated_p_type", "t", 0) + +/* A thunk is a stub function. + + Thunks are used to implement multiple inheritance: + At run-time, such a thunk subtracts THUNK_DELTA (an int, not a tree) + from the this pointer, and then jumps to DECL_INITIAL + (which is an ADDR_EXPR whose operand is a FUNCTION_DECL). + + Other kinds of thunks may be defined later. */ +DEFTREECODE (THUNK_DECL, "thunk_decl", "d", 0) + +/* A namespace declaration. */ +DEFTREECODE (NAMESPACE_DECL, "namespace_decl", "d", 0) diff --git a/contrib/gcc/cp/typeck.c b/contrib/gcc/cp/typeck.c new file mode 100644 index 00000000000..9247bf084d8 --- /dev/null +++ b/contrib/gcc/cp/typeck.c @@ -0,0 +1,7615 @@ +/* Build expressions with type checking for C++ compiler. + Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is part of the C++ front end. + It contains routines to build C++ expressions given their operands, + including computing the types of the result, C and C++ specific error + checks, and some optimization. + + There are also routines to build RETURN_STMT nodes and CASE_STMT nodes, + and to process initializations in declarations (since they work + like a strange sort of assignment). */ + +extern void error (); +extern void warning (); + +#include "config.h" +#include +#include "tree.h" +#include "rtl.h" +#include "cp-tree.h" +#include "flags.h" +#include "output.h" + +int mark_addressable (); +static tree convert_for_assignment (); +/* static */ tree convert_for_initialization (); +extern tree shorten_compare (); +extern void binary_op_error (); +static tree pointer_int_sum (); +static tree pointer_diff (); +static tree convert_sequence (); +/* static */ tree unary_complex_lvalue (); +static tree get_delta_difference PROTO((tree, tree, int)); + +extern rtx original_result_rtx; +extern int warn_synth; + +/* Return the target type of TYPE, which meas return T for: + T*, T&, T[], T (...), and otherwise, just T. */ + +tree +target_type (type) + tree type; +{ + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + while (TREE_CODE (type) == POINTER_TYPE + || TREE_CODE (type) == ARRAY_TYPE + || TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE + || TREE_CODE (type) == OFFSET_TYPE) + type = TREE_TYPE (type); + return type; +} + +/* Do `exp = require_complete_type (exp);' to make sure exp + does not have an incomplete type. (That includes void types.) */ + +tree +require_complete_type (value) + tree value; +{ + tree type = TREE_TYPE (value); + + /* First, detect a valid value with a complete type. */ + if (TYPE_SIZE (type) != 0 + && type != void_type_node + && ! (TYPE_LANG_SPECIFIC (type) + && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)) + && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0)) + return value; + + /* If we see X::Y, we build an OFFSET_TYPE which has + not been laid out. Try to avoid an error by interpreting + it as this->X::Y, if reasonable. */ + if (TREE_CODE (value) == OFFSET_REF + && C_C_D != 0 + && TREE_OPERAND (value, 0) == C_C_D) + { + tree base, member = TREE_OPERAND (value, 1); + tree basetype = TYPE_OFFSET_BASETYPE (type); + my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305); + base = convert_pointer_to (basetype, current_class_decl); + value = build (COMPONENT_REF, TREE_TYPE (member), + build_indirect_ref (base, NULL_PTR), member); + return require_complete_type (value); + } + + incomplete_type_error (value, type); + return error_mark_node; +} + +/* Return truthvalue of whether type of EXP is instantiated. */ +int +type_unknown_p (exp) + tree exp; +{ + return (TREE_CODE (exp) == TREE_LIST + || TREE_TYPE (exp) == unknown_type_node + || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE + && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node)); +} + +/* Return truthvalue of whether T is function (or pfn) type. */ +int +fntype_p (t) + tree t; +{ + return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE + || (TREE_CODE (t) == POINTER_TYPE + && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE))); +} + +/* Do `exp = require_instantiated_type (type, exp);' to make sure EXP + does not have an uninstantiated type. + TYPE is type to instantiate with, if uninstantiated. */ +tree +require_instantiated_type (type, exp, errval) + tree type, exp, errval; +{ + if (TREE_TYPE (exp) == NULL_TREE) + { + error ("argument list may not have an initializer list"); + return errval; + } + + if (TREE_TYPE (exp) == unknown_type_node + || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE + && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node)) + { + exp = instantiate_type (type, exp, 1); + if (TREE_TYPE (exp) == error_mark_node) + return errval; + } + return exp; +} + +/* Return a variant of TYPE which has all the type qualifiers of LIKE + as well as those of TYPE. */ + +static tree +qualify_type (type, like) + tree type, like; +{ + int constflag = TYPE_READONLY (type) || TYPE_READONLY (like); + int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like); + /* @@ Must do member pointers here. */ + return cp_build_type_variant (type, constflag, volflag); +} + +/* Return the common type of two parameter lists. + We assume that comptypes has already been done and returned 1; + if that isn't so, this may crash. + + As an optimization, free the space we allocate if the parameter + lists are already common. */ + +tree +commonparms (p1, p2) + tree p1, p2; +{ + tree oldargs = p1, newargs, n; + int i, len; + int any_change = 0; + char *first_obj = (char *) oballoc (0); + + len = list_length (p1); + newargs = tree_last (p1); + + if (newargs == void_list_node) + i = 1; + else + { + i = 0; + newargs = 0; + } + + for (; i < len; i++) + newargs = tree_cons (NULL_TREE, NULL_TREE, newargs); + + n = newargs; + + for (i = 0; p1; + p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++) + { + if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2)) + { + TREE_PURPOSE (n) = TREE_PURPOSE (p1); + any_change = 1; + } + else if (! TREE_PURPOSE (p1)) + { + if (TREE_PURPOSE (p2)) + { + TREE_PURPOSE (n) = TREE_PURPOSE (p2); + any_change = 1; + } + } + else + { + if (1 != simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2))) + any_change = 1; + TREE_PURPOSE (n) = TREE_PURPOSE (p2); + } + if (TREE_VALUE (p1) != TREE_VALUE (p2)) + { + any_change = 1; + TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2)); + } + else + TREE_VALUE (n) = TREE_VALUE (p1); + } + if (! any_change) + { + obfree (first_obj); + return oldargs; + } + + return newargs; +} + +/* Return the common type of two types. + We assume that comptypes has already been done and returned 1; + if that isn't so, this may crash. + + This is the type for the result of most arithmetic operations + if the operands have the given two types. + + We do not deal with enumeral types here because they have already been + converted to integer types. */ + +tree +common_type (t1, t2) + tree t1, t2; +{ + register enum tree_code code1; + register enum tree_code code2; + tree attributes; + + /* Save time if the two types are the same. */ + + if (t1 == t2) return t1; + + /* If one type is nonsense, use the other. */ + if (t1 == error_mark_node) + return t2; + if (t2 == error_mark_node) + return t1; + + /* Merge the attributes */ + + { register tree a1, a2; + a1 = TYPE_ATTRIBUTES (t1); + a2 = TYPE_ATTRIBUTES (t2); + + /* Either one unset? Take the set one. */ + + if (!(attributes = a1)) + attributes = a2; + + /* One that completely contains the other? Take it. */ + + else if (a2 && !attribute_list_contained (a1, a2)) + if (attribute_list_contained (a2, a1)) + attributes = a2; + else + { + /* Pick the longest list, and hang on the other list. */ + /* ??? For the moment we punt on the issue of attrs with args. */ + + if (list_length (a1) < list_length (a2)) + attributes = a2, a2 = a1; + + for (; a2; a2 = TREE_CHAIN (a2)) + if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)), + attributes) == NULL_TREE) + { + a1 = copy_node (a2); + TREE_CHAIN (a1) = attributes; + attributes = a1; + } + } + } + + /* Treat an enum type as the unsigned integer type of the same width. */ + + if (TREE_CODE (t1) == ENUMERAL_TYPE) + t1 = type_for_size (TYPE_PRECISION (t1), 1); + if (TREE_CODE (t2) == ENUMERAL_TYPE) + t2 = type_for_size (TYPE_PRECISION (t2), 1); + + code1 = TREE_CODE (t1); + code2 = TREE_CODE (t2); + + switch (code1) + { + case INTEGER_TYPE: + case REAL_TYPE: + /* If only one is real, use it as the result. */ + + if (code1 == REAL_TYPE && code2 != REAL_TYPE) + return build_type_attribute_variant (t1, attributes); + + if (code2 == REAL_TYPE && code1 != REAL_TYPE) + return build_type_attribute_variant (t2, attributes); + + /* Both real or both integers; use the one with greater precision. */ + + if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2)) + return build_type_attribute_variant (t1, attributes); + else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1)) + return build_type_attribute_variant (t2, attributes); + + /* Same precision. Prefer longs to ints even when same size. */ + + if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node + || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node) + return build_type_attribute_variant (long_unsigned_type_node, + attributes); + + if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node + || TYPE_MAIN_VARIANT (t2) == long_integer_type_node) + { + /* But preserve unsignedness from the other type, + since long cannot hold all the values of an unsigned int. */ + if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2)) + t1 = long_unsigned_type_node; + else + t1 = long_integer_type_node; + return build_type_attribute_variant (t1, attributes); + } + + if (TYPE_MAIN_VARIANT (t1) == long_double_type_node + || TYPE_MAIN_VARIANT (t2) == long_double_type_node) + return build_type_attribute_variant (long_double_type_node, + attributes); + + /* Otherwise prefer the unsigned one. */ + + if (TREE_UNSIGNED (t1)) + return build_type_attribute_variant (t1, attributes); + else + return build_type_attribute_variant (t2, attributes); + + case POINTER_TYPE: + case REFERENCE_TYPE: + /* For two pointers, do this recursively on the target type, + and combine the qualifiers of the two types' targets. */ + /* This code was turned off; I don't know why. + But ANSI C++ specifies doing this with the qualifiers. + So I turned it on again. */ + { + tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1)); + tree tt2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2)); + int constp + = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2)); + int volatilep + = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2)); + tree target; + + if (tt1 == tt2) + target = tt1; + else if (tt1 == void_type_node || tt2 == void_type_node) + target = void_type_node; + else + target = common_type (tt1, tt2); + + target = cp_build_type_variant (target, constp, volatilep); + if (code1 == POINTER_TYPE) + t1 = build_pointer_type (target); + else + t1 = build_reference_type (target); + t1 = build_type_attribute_variant (t1, attributes); + + if (TREE_CODE (target) == METHOD_TYPE) + t1 = build_ptrmemfunc_type (t1); + + return t1; + } +#if 0 + case POINTER_TYPE: + t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2))); + return build_type_attribute_variant (t1, attributes); + + case REFERENCE_TYPE: + t1 = build_reference_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2))); + return build_type_attribute_variant (t1, attributes); +#endif + + case ARRAY_TYPE: + { + tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2)); + /* Save space: see if the result is identical to one of the args. */ + if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1)) + return build_type_attribute_variant (t1, attributes); + if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2)) + return build_type_attribute_variant (t2, attributes); + /* Merge the element types, and have a size if either arg has one. */ + t1 = build_cplus_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2)); + return build_type_attribute_variant (t1, attributes); + } + + case FUNCTION_TYPE: + /* Function types: prefer the one that specified arg types. + If both do, merge the arg types. Also merge the return types. */ + { + tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2)); + tree p1 = TYPE_ARG_TYPES (t1); + tree p2 = TYPE_ARG_TYPES (t2); + tree rval, raises; + + /* Save space: see if the result is identical to one of the args. */ + if (valtype == TREE_TYPE (t1) && ! p2) + return build_type_attribute_variant (t1, attributes); + if (valtype == TREE_TYPE (t2) && ! p1) + return build_type_attribute_variant (t2, attributes); + + /* Simple way if one arg fails to specify argument types. */ + if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node) + { + rval = build_function_type (valtype, p2); + if ((raises = TYPE_RAISES_EXCEPTIONS (t2))) + rval = build_exception_variant (rval, raises); + return build_type_attribute_variant (rval, attributes); + } + raises = TYPE_RAISES_EXCEPTIONS (t1); + if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node) + { + rval = build_function_type (valtype, p1); + if (raises) + rval = build_exception_variant (rval, raises); + return build_type_attribute_variant (rval, attributes); + } + + rval = build_function_type (valtype, commonparms (p1, p2)); + rval = build_exception_variant (rval, raises); + return build_type_attribute_variant (rval, attributes); + } + + case RECORD_TYPE: + case UNION_TYPE: + my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1 + && TYPE_MAIN_VARIANT (t2) == t2, 306); + + if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2)) + return build_type_attribute_variant (t1, attributes); + else if (binfo_or_else (t2, t1)) + return build_type_attribute_variant (t2, attributes); + else + compiler_error ("common_type called with uncommon aggregate types"); + + case METHOD_TYPE: + if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2))) + { + /* Get this value the long way, since TYPE_METHOD_BASETYPE + is just the main variant of this. */ + tree basetype; + tree raises, t3; + + tree b1 = TYPE_OFFSET_BASETYPE (t1); + tree b2 = TYPE_OFFSET_BASETYPE (t2); + + if (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)) + basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2))); + else + { + if (binfo_or_else (b2, b1) == NULL_TREE) + compiler_error ("common_type called with uncommon method types"); + basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1))); + } + + raises = TYPE_RAISES_EXCEPTIONS (t1); + + /* If this was a member function type, get back to the + original type of type member function (i.e., without + the class instance variable up front. */ + t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1))); + t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2))); + t3 = common_type (t1, t2); + t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3)); + t1 = build_exception_variant (t3, raises); + } + else + compiler_error ("common_type called with uncommon method types"); + + return build_type_attribute_variant (t1, attributes); + + case OFFSET_TYPE: + if (TREE_TYPE (t1) == TREE_TYPE (t2)) + { + tree b1 = TYPE_OFFSET_BASETYPE (t1); + tree b2 = TYPE_OFFSET_BASETYPE (t2); + + if (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2)) + return build_type_attribute_variant (t2, attributes); + else if (binfo_or_else (b2, b1)) + return build_type_attribute_variant (t1, attributes); + } + compiler_error ("common_type called with uncommon member types"); + + default: + return build_type_attribute_variant (t1, attributes); + } +} + +/* Return 1 if TYPE1 and TYPE2 raise the same exceptions. */ +int +compexcepttypes (t1, t2, strict) + tree t1, t2; + int strict; +{ + return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2); +} + +static int +comp_array_types (cmp, t1, t2, strict) + register int (*cmp)(); + tree t1, t2; + int strict; +{ + tree d1 = TYPE_DOMAIN (t1); + tree d2 = TYPE_DOMAIN (t2); + + /* Target types must match incl. qualifiers. */ + if (!(TREE_TYPE (t1) == TREE_TYPE (t2) + || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict))) + return 0; + + /* Sizes must match unless one is missing or variable. */ + if (d1 == 0 || d2 == 0 || d1 == d2 + || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST + || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST + || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST + || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST) + return 1; + + return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1)) + == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2))) + && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1)) + == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2))) + && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1)) + == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2))) + && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1)) + == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2)))); +} + +/* Return 1 if TYPE1 and TYPE2 are compatible types for assignment + or various other operations. This is what ANSI C++ speaks of as + "being the same". + + For C++: argument STRICT says we should be strict about this + comparison: + + 2 : strict, except that if one type is a reference and + the other is not, compare the target type of the + reference to the type that's not a reference (ARM, p308). + This is used for checking for invalid overloading. + 1 : strict (compared according to ANSI C) + This is used for checking whether two function decls match. + 0 : <= (compared according to C++) + -1: <= or >= (relaxed) + + Otherwise, pointers involving base classes and derived classes + can be mixed as valid: i.e. a pointer to a base class may be assigned + to a pointer to one of its derived classes, as per C++. A pointer to + a derived class may be passed as a parameter to a function expecting a + pointer to a base classes. These allowances do not commute. In this + case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to + be the derived class. */ +int +comptypes (type1, type2, strict) + tree type1, type2; + int strict; +{ + register tree t1 = type1; + register tree t2 = type2; + int attrval, val; + + /* Suppress errors caused by previously reported errors */ + + if (t1 == t2) + return 1; + + /* This should never happen. */ + my_friendly_assert (t1 != error_mark_node, 307); + + if (t2 == error_mark_node) + return 0; + + if (strict < 0) + { + /* Treat an enum type as the unsigned integer type of the same width. */ + + if (TREE_CODE (t1) == ENUMERAL_TYPE) + t1 = type_for_size (TYPE_PRECISION (t1), 1); + if (TREE_CODE (t2) == ENUMERAL_TYPE) + t2 = type_for_size (TYPE_PRECISION (t2), 1); + + if (t1 == t2) + return 1; + } + + /* Different classes of types can't be compatible. */ + + if (TREE_CODE (t1) != TREE_CODE (t2)) + { + if (strict == 2 + && ((TREE_CODE (t1) == REFERENCE_TYPE) + ^ (TREE_CODE (t2) == REFERENCE_TYPE))) + { + if (TREE_CODE (t1) == REFERENCE_TYPE) + return comptypes (TREE_TYPE (t1), t2, 1); + return comptypes (t1, TREE_TYPE (t2), 1); + } + + return 0; + } + if (strict > 1) + strict = 1; + + /* Qualifiers must match. */ + + if (TYPE_READONLY (t1) != TYPE_READONLY (t2)) + return 0; + if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2)) + return 0; + + /* Allow for two different type nodes which have essentially the same + definition. Note that we already checked for equality of the type + type qualifiers (just above). */ + + if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)) + return 1; + +#ifdef COMP_TYPE_ATTRIBUTES + if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2))) + return 0; +#else + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + attrval = 1; +#endif + + /* 1 if no need for warning yet, 2 if warning cause has been seen. */ + val = 0; + + switch (TREE_CODE (t1)) + { + case RECORD_TYPE: + case UNION_TYPE: + if (strict <= 0) + goto look_hard; + return 0; + + case OFFSET_TYPE: + val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)), + build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict) + && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)); + break; + + case METHOD_TYPE: + if (! compexcepttypes (t1, t2, strict)) + return 0; + + /* This case is anti-symmetrical! + One can pass a base member (or member function) + to something expecting a derived member (or member function), + but not vice-versa! */ + + val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict) + && compparms (TYPE_ARG_TYPES (t1), + TYPE_ARG_TYPES (t2), strict)); + break; + + case POINTER_TYPE: + case REFERENCE_TYPE: + t1 = TREE_TYPE (t1); + t2 = TREE_TYPE (t2); + if (t1 == t2) + { + val = 1; + break; + } + if (strict <= 0) + { + if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE) + { + int rval; + look_hard: + rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2); + + if (rval) + { + val = 1; + break; + } + if (strict < 0) + { + val = UNIQUELY_DERIVED_FROM_P (t2, t1); + break; + } + } + return 0; + } + else + val = comptypes (t1, t2, strict); + break; + + case FUNCTION_TYPE: + if (! compexcepttypes (t1, t2, strict)) + return 0; + + val = ((TREE_TYPE (t1) == TREE_TYPE (t2) + || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)) + && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict)); + break; + + case ARRAY_TYPE: + /* Target types must match incl. qualifiers. */ + val = comp_array_types (comptypes, t1, t2, strict); + break; + + case TEMPLATE_TYPE_PARM: + return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2); + + case UNINSTANTIATED_P_TYPE: + if (UPT_TEMPLATE (t1) != UPT_TEMPLATE (t2)) + return 0; + { + int i = TREE_VEC_LENGTH (UPT_PARMS (t1)); + tree *p1 = &TREE_VEC_ELT (UPT_PARMS (t1), 0); + tree *p2 = &TREE_VEC_ELT (UPT_PARMS (t2), 0); + + while (i--) + { + if (TREE_CODE_CLASS (TREE_CODE (p1[i])) == 't') + { + if (! comptypes (p1[i], p2[i], 1)) + return 0; + } + else + { + if (simple_cst_equal (p1[i], p2[i]) <= 0) + return 0; + } + } + } + return 1; + } + return attrval == 2 && val == 1 ? 2 : val; +} + +/* Return 1 if TTL and TTR are pointers to types that are equivalent, + ignoring their qualifiers. + + NPTRS is the number of pointers we can strip off and keep cool. + This is used to permit (for aggr A, aggr B) A, B* to convert to A*, + but to not permit B** to convert to A**. */ + +int +comp_target_types (ttl, ttr, nptrs) + tree ttl, ttr; + int nptrs; +{ + ttl = TYPE_MAIN_VARIANT (ttl); + ttr = TYPE_MAIN_VARIANT (ttr); + if (ttl == ttr) + return 1; + + if (TREE_CODE (ttr) != TREE_CODE (ttl)) + return 0; + + if (TREE_CODE (ttr) == POINTER_TYPE) + { + ttl = TREE_TYPE (ttl); + ttr = TREE_TYPE (ttr); + + if (nptrs > 0) + { + if (TREE_CODE (ttl) == VOID_TYPE + && TREE_CODE (ttr) != FUNCTION_TYPE + && TREE_CODE (ttr) != METHOD_TYPE + && TREE_CODE (ttr) != OFFSET_TYPE) + return 1; + else if (TREE_CODE (ttr) == VOID_TYPE + && TREE_CODE (ttl) != FUNCTION_TYPE + && TREE_CODE (ttl) != METHOD_TYPE + && TREE_CODE (ttl) != OFFSET_TYPE) + return -1; + else if (TREE_CODE (ttl) == POINTER_TYPE + || TREE_CODE (ttl) == ARRAY_TYPE) + { + if (comp_ptr_ttypes (ttl, ttr)) + return 1; + else if (comp_ptr_ttypes (ttr, ttl)) + return -1; + return 0; + } + } + + /* Const and volatile mean something different for function types, + so the usual checks are not appropriate. */ + if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE) + return comp_target_types (ttl, ttr, nptrs - 1); + + /* Make sure that the cv-quals change only in the same direction as + the target type. */ + { + int t; + int c = TYPE_READONLY (ttl) - TYPE_READONLY (ttr); + int v = TYPE_VOLATILE (ttl) - TYPE_VOLATILE (ttr); + + if ((c > 0 && v < 0) || (c < 0 && v > 0)) + return 0; + + if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)) + return (c + v < 0) ? -1 : 1; + + t = comp_target_types (ttl, ttr, nptrs - 1); + if ((t == 1 && c + v >= 0) || (t == -1 && c + v <= 0)) + return t; + + return 0; + } + } + + if (TREE_CODE (ttr) == REFERENCE_TYPE) + return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs); + if (TREE_CODE (ttr) == ARRAY_TYPE) + return comp_array_types (comp_target_types, ttl, ttr, 0); + else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE) + if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs)) + switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 1)) + { + case 0: + return 0; + case 1: + return 1; + case 2: + return -1; + default: + my_friendly_abort (112); + } + else + return 0; + + /* for C++ */ + else if (TREE_CODE (ttr) == OFFSET_TYPE) + { + /* Contravariance: we can assign a pointer to base member to a pointer + to derived member. Note difference from simple pointer case, where + we can pass a pointer to derived to a pointer to base. */ + if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0)) + return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs); + else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0) + && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs)) + return -1; + } + else if (IS_AGGR_TYPE (ttl)) + { + if (nptrs < 0) + return 0; + if (comptypes (build_pointer_type (ttl), build_pointer_type (ttr), 0)) + return 1; + if (comptypes (build_pointer_type (ttr), build_pointer_type (ttl), 0)) + return -1; + return 0; + } + + return 0; +} + +/* If two types share a common base type, return that basetype. + If there is not a unique most-derived base type, this function + returns ERROR_MARK_NODE. */ +tree +common_base_type (tt1, tt2) + tree tt1, tt2; +{ + tree best = NULL_TREE, tmp; + int i; + + /* If one is a baseclass of another, that's good enough. */ + if (UNIQUELY_DERIVED_FROM_P (tt1, tt2)) + return tt1; + if (UNIQUELY_DERIVED_FROM_P (tt2, tt1)) + return tt2; + +#if 0 + /* If they share a virtual baseclass, that's good enough. */ + for (tmp = CLASSTYPE_VBASECLASSES (tt1); tmp; tmp = TREE_CHAIN (tmp)) + { + if (binfo_member (BINFO_TYPE (tmp), CLASSTYPE_VBASECLASSES (tt2))) + return BINFO_TYPE (tmp); + } +#endif + + /* Otherwise, try to find a unique baseclass of TT1 + that is shared by TT2, and follow that down. */ + for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--) + { + tree basetype = TYPE_BINFO_BASETYPE (tt1, i); + tree trial = common_base_type (basetype, tt2); + if (trial) + { + if (trial == error_mark_node) + return trial; + if (best == NULL_TREE) + best = trial; + else if (best != trial) + return error_mark_node; + } + } + + /* Same for TT2. */ + for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--) + { + tree basetype = TYPE_BINFO_BASETYPE (tt2, i); + tree trial = common_base_type (tt1, basetype); + if (trial) + { + if (trial == error_mark_node) + return trial; + if (best == NULL_TREE) + best = trial; + else if (best != trial) + return error_mark_node; + } + } + return best; +} + +/* Subroutines of `comptypes'. */ + +/* Return 1 if two parameter type lists PARMS1 and PARMS2 + are equivalent in the sense that functions with those parameter types + can have equivalent types. + If either list is empty, we win. + Otherwise, the two lists must be equivalent, element by element. + + C++: See comment above about TYPE1, TYPE2, STRICT. + If STRICT == 3, it means checking is strict, but do not compare + default parameter values. */ +int +compparms (parms1, parms2, strict) + tree parms1, parms2; + int strict; +{ + register tree t1 = parms1, t2 = parms2; + + /* An unspecified parmlist matches any specified parmlist + whose argument types don't need default promotions. */ + + if (strict <= 0 && t1 == 0) + return self_promoting_args_p (t2); + if (strict < 0 && t2 == 0) + return self_promoting_args_p (t1); + + while (1) + { + if (t1 == 0 && t2 == 0) + return 1; + /* If one parmlist is shorter than the other, + they fail to match, unless STRICT is <= 0. */ + if (t1 == 0 || t2 == 0) + { + if (strict > 0) + return 0; + if (strict < 0) + return 1; + if (strict == 0) + return t1 && TREE_PURPOSE (t1); + } + if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict)) + { + if (strict > 0) + return 0; + if (strict == 0) + return t2 == void_list_node && TREE_PURPOSE (t1); + return TREE_PURPOSE (t1) || TREE_PURPOSE (t2); + } +#if 0 + /* Default parms are not part of the type of a function. */ + if (strict != 3 && TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) + { + int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)); + if (cmp < 0) + my_friendly_abort (113); + if (cmp == 0) + return 0; + } +#endif + + t1 = TREE_CHAIN (t1); + t2 = TREE_CHAIN (t2); + } +} + +/* This really wants return whether or not parameter type lists + would make their owning functions assignment compatible or not. */ +int +comp_target_parms (parms1, parms2, strict) + tree parms1, parms2; + int strict; +{ + register tree t1 = parms1, t2 = parms2; + int warn_contravariance = 0; + + /* An unspecified parmlist matches any specified parmlist + whose argument types don't need default promotions. + @@@ see 13.3.3 for a counterexample... */ + + if (t1 == 0 && t2 != 0) + { + cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'", + parms2); + return self_promoting_args_p (t2); + } + if (t2 == 0) + return self_promoting_args_p (t1); + + for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2)) + { + tree p1, p2; + + /* If one parmlist is shorter than the other, + they fail to match, unless STRICT is <= 0. */ + if (t1 == 0 || t2 == 0) + { + if (strict > 0) + return 0; + if (strict < 0) + return 1 + warn_contravariance; + return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance); + } + p1 = TREE_VALUE (t1); + p2 = TREE_VALUE (t2); + if (p1 == p2) + continue; + + if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE) + || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE)) + { + if (strict <= 0 + && (TYPE_MAIN_VARIANT (TREE_TYPE (p1)) + == TYPE_MAIN_VARIANT (TREE_TYPE (p2)))) + continue; + + /* The following is wrong for contravariance, + but many programs depend on it. */ + if (TREE_TYPE (p1) == void_type_node) + continue; + if (TREE_TYPE (p2) == void_type_node) + { + warn_contravariance = 1; + continue; + } + if (IS_AGGR_TYPE (TREE_TYPE (p1))) + { + if (comptypes (p2, p1, 0) == 0) + { + if (comptypes (p1, p2, 0) != 0) + warn_contravariance = 1; + else + return 0; + } + continue; + } + } + /* Note backwards order due to contravariance. */ + if (comp_target_types (p2, p1, 1) == 0) + { + if (comp_target_types (p1, p2, 1)) + { + warn_contravariance = 1; + continue; + } + if (strict != 0) + return 0; +#if 0 + /* What good do these cases do? */ + if (strict == 0) + return p2 == void_type_node && TREE_PURPOSE (t1); + return TREE_PURPOSE (t1) || TREE_PURPOSE (t2); +#endif + } + /* Target types are compatible--just make sure that if + we use parameter lists, that they are ok as well. */ + if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE) + switch (comp_target_parms (TYPE_ARG_TYPES (p1), + TYPE_ARG_TYPES (p2), + strict)) + { + case 0: + return 0; + case 1: + break; + case 2: + warn_contravariance = 1; + } + + if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) + { + int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)); + if (cmp < 0) + my_friendly_abort (114); + if (cmp == 0) + return 0; + } + } + return 1 + warn_contravariance; +} + +/* Return 1 if PARMS specifies a fixed number of parameters + and none of their types is affected by default promotions. */ + +int +self_promoting_args_p (parms) + tree parms; +{ + register tree t; + for (t = parms; t; t = TREE_CHAIN (t)) + { + register tree type = TREE_VALUE (t); + + if (TREE_CHAIN (t) == 0 && type != void_type_node) + return 0; + + if (TYPE_MAIN_VARIANT (type) == float_type_node) + return 0; + + if (type == 0) + return 0; + + if (C_PROMOTING_INTEGER_TYPE_P (type)) + return 0; + } + return 1; +} + +/* Return an unsigned type the same as TYPE in other respects. + + C++: must make these work for type variants as well. */ + +tree +unsigned_type (type) + tree type; +{ + tree type1 = TYPE_MAIN_VARIANT (type); + if (type1 == signed_char_type_node || type1 == char_type_node) + return unsigned_char_type_node; + if (type1 == integer_type_node) + return unsigned_type_node; + if (type1 == short_integer_type_node) + return short_unsigned_type_node; + if (type1 == long_integer_type_node) + return long_unsigned_type_node; + if (type1 == long_long_integer_type_node) + return long_long_unsigned_type_node; + return type; +} + +/* Return a signed type the same as TYPE in other respects. */ + +tree +signed_type (type) + tree type; +{ + tree type1 = TYPE_MAIN_VARIANT (type); + if (type1 == unsigned_char_type_node || type1 == char_type_node) + return signed_char_type_node; + if (type1 == unsigned_type_node) + return integer_type_node; + if (type1 == short_unsigned_type_node) + return short_integer_type_node; + if (type1 == long_unsigned_type_node) + return long_integer_type_node; + if (type1 == long_long_unsigned_type_node) + return long_long_integer_type_node; + return type; +} + +/* Return a type the same as TYPE except unsigned or + signed according to UNSIGNEDP. */ + +tree +signed_or_unsigned_type (unsignedp, type) + int unsignedp; + tree type; +{ + if (! INTEGRAL_TYPE_P (type)) + return type; + if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node)) + return unsignedp ? unsigned_char_type_node : signed_char_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) + return unsignedp ? unsigned_type_node : integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) + return unsignedp ? short_unsigned_type_node : short_integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) + return unsignedp ? long_unsigned_type_node : long_integer_type_node; + if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) + return (unsignedp ? long_long_unsigned_type_node + : long_long_integer_type_node); + return type; +} + +tree +c_sizeof (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids taking the sizeof a function type"); + return size_int (1); + } + if (code == METHOD_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids taking the sizeof a method type"); + return size_int (1); + } + if (code == VOID_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids taking the sizeof a void type"); + return size_int (1); + } + if (code == ERROR_MARK) + return size_int (1); + + /* ARM $5.3.2: ``When applied to a reference, the result is the size of the + referenced object.'' */ + if (code == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* We couldn't find anything in the ARM or the draft standard that says, + one way or the other, if doing sizeof on something that doesn't have + an object associated with it is correct or incorrect. For example, if + you declare `struct S { char str[16]; };', and in your program do + a `sizeof (S::str)', should we flag that as an error or should we give + the size of it? Since it seems like a reasonable thing to do, we'll go + with giving the value. */ + if (code == OFFSET_TYPE) + type = TREE_TYPE (type); + + /* @@ This also produces an error for a signature ref. + In that case we should be able to do better. */ + if (IS_SIGNATURE (type)) + { + error ("`sizeof' applied to a signature type"); + return size_int (0); + } + + if (TYPE_SIZE (type) == 0) + { + error ("`sizeof' applied to an incomplete type"); + return size_int (0); + } + + /* Convert in case a char is more than one unit. */ + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (TYPE_PRECISION (char_type_node))); + /* size_binop does not put the constant in range, so do it now. */ + if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0)) + TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1; + return t; +} + +tree +c_sizeof_nowarn (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE + || code == METHOD_TYPE + || code == VOID_TYPE + || code == ERROR_MARK) + return size_int (1); + if (code == REFERENCE_TYPE) + type = TREE_TYPE (type); + + if (TYPE_SIZE (type) == 0) + { +#if 0 + /* ??? Tiemann, why have any diagnostic here? + There is none in the corresponding function for C. */ + warning ("sizeof applied to an incomplete type"); +#endif + return size_int (0); + } + + /* Convert in case a char is more than one unit. */ + t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), + size_int (TYPE_PRECISION (char_type_node))); + force_fit_type (t, 0); + return t; +} + +/* Implement the __alignof keyword: Return the minimum required + alignment of TYPE, measured in bytes. */ + +tree +c_alignof (type) + tree type; +{ + enum tree_code code = TREE_CODE (type); + tree t; + + if (code == FUNCTION_TYPE || code == METHOD_TYPE) + return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT); + + if (code == VOID_TYPE || code == ERROR_MARK) + return size_int (1); + + /* C++: this is really correct! */ + if (code == REFERENCE_TYPE) + type = TREE_TYPE (type); + + /* @@ This also produces an error for a signature ref. + In that case we should be able to do better. */ + if (IS_SIGNATURE (type)) + { + error ("`__alignof' applied to a signature type"); + return size_int (1); + } + + t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT); + force_fit_type (t, 0); + return t; +} + +/* Perform default promotions for C data used in expressions. + Arrays and functions are converted to pointers; + enumeral types or short or char, to int. + In addition, manifest constants symbols are replaced by their values. + + C++: this will automatically bash references to their target type. */ + +tree +decay_conversion (exp) + tree exp; +{ + register tree type = TREE_TYPE (exp); + register enum tree_code code = TREE_CODE (type); + + if (code == OFFSET_TYPE /* || TREE_CODE (exp) == OFFSET_REF */ ) + { + if (TREE_CODE (exp) == OFFSET_REF) + return decay_conversion (resolve_offset_ref (exp)); + + type = TREE_TYPE (type); + code = TREE_CODE (type); + } + + if (code == REFERENCE_TYPE) + { + exp = convert_from_reference (exp); + type = TREE_TYPE (exp); + code = TREE_CODE (type); + } + + /* Constants can be used directly unless they're not loadable. */ + if (TREE_CODE (exp) == CONST_DECL) + exp = DECL_INITIAL (exp); + /* Replace a nonvolatile const static variable with its value. */ + else if (TREE_READONLY_DECL_P (exp)) + { + exp = decl_constant_value (exp); + type = TREE_TYPE (exp); + } + + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */ + + if (code == VOID_TYPE) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + if (code == FUNCTION_TYPE) + { + return build_unary_op (ADDR_EXPR, exp, 0); + } + if (code == METHOD_TYPE) + { + if (TREE_CODE (exp) == OFFSET_REF) + { + my_friendly_assert (TREE_CODE (TREE_OPERAND (exp, 1)) == FUNCTION_DECL, + 308); + return build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0); + } + return build_unary_op (ADDR_EXPR, exp, 0); + } + if (code == ARRAY_TYPE) + { + register tree adr; + tree restype; + tree ptrtype; + int constp, volatilep; + + if (TREE_CODE (exp) == INDIRECT_REF) + { + /* Stripping away the INDIRECT_REF is not the right + thing to do for references... */ + tree inner = TREE_OPERAND (exp, 0); + if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE) + { + inner = build1 (CONVERT_EXPR, + build_pointer_type (TREE_TYPE (TREE_TYPE (inner))), + inner); + TREE_REFERENCE_EXPR (inner) = 1; + } + return convert (build_pointer_type (TREE_TYPE (type)), inner); + } + + if (TREE_CODE (exp) == COMPOUND_EXPR) + { + tree op1 = decay_conversion (TREE_OPERAND (exp, 1)); + return build (COMPOUND_EXPR, TREE_TYPE (op1), + TREE_OPERAND (exp, 0), op1); + } + + if (!lvalue_p (exp) + && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp))) + { + error ("invalid use of non-lvalue array"); + return error_mark_node; + } + + constp = volatilep = 0; + if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r' + || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd') + { + constp = TREE_READONLY (exp); + volatilep = TREE_THIS_VOLATILE (exp); + } + + restype = TREE_TYPE (type); + if (TYPE_READONLY (type) || TYPE_VOLATILE (type) + || constp || volatilep) + restype = cp_build_type_variant (restype, + TYPE_READONLY (type) || constp, + TYPE_VOLATILE (type) || volatilep); + ptrtype = build_pointer_type (restype); + + if (TREE_CODE (exp) == VAR_DECL) + { + /* ??? This is not really quite correct + in that the type of the operand of ADDR_EXPR + is not the target type of the type of the ADDR_EXPR itself. + Question is, can this lossage be avoided? */ + adr = build1 (ADDR_EXPR, ptrtype, exp); + if (mark_addressable (exp) == 0) + return error_mark_node; + TREE_CONSTANT (adr) = staticp (exp); + TREE_SIDE_EFFECTS (adr) = 0; /* Default would be, same as EXP. */ + return adr; + } + /* This way is better for a COMPONENT_REF since it can + simplify the offset for a component. */ + adr = build_unary_op (ADDR_EXPR, exp, 1); + return convert (ptrtype, adr); + } + + return exp; +} + +tree +default_conversion (exp) + tree exp; +{ + tree type; + enum tree_code code; + + exp = decay_conversion (exp); + + type = TREE_TYPE (exp); + code = TREE_CODE (type); + + if (INTEGRAL_CODE_P (code)) + { + tree t = type_promotes_to (type); + if (t != type) + return convert (t, exp); + } + if (flag_traditional + && TYPE_MAIN_VARIANT (type) == float_type_node) + return convert (double_type_node, exp); + + return exp; +} + +tree +build_object_ref (datum, basetype, field) + tree datum, basetype, field; +{ + tree dtype; + if (datum == error_mark_node) + return error_mark_node; + + dtype = TREE_TYPE (datum); + if (TREE_CODE (dtype) == REFERENCE_TYPE) + dtype = TREE_TYPE (dtype); + if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype))) + { + cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'", + basetype, field, dtype); + return error_mark_node; + } + else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype))) + { + warning ("signature name in scope resolution ignored"); + return build_component_ref (datum, field, NULL_TREE, 1); + } + else if (is_aggr_typedef (basetype, 1)) + { + tree real_basetype = IDENTIFIER_TYPE_VALUE (basetype); + tree binfo = binfo_or_else (real_basetype, TREE_TYPE (datum)); + if (binfo) + return build_component_ref (build_scoped_ref (datum, basetype), + field, binfo, 1); + } + return error_mark_node; +} + +/* Like `build_component_ref, but uses an already found field. + Must compute access for C_C_D. Otherwise, ok. */ +tree +build_component_ref_1 (datum, field, protect) + tree datum, field; + int protect; +{ + register tree basetype = TREE_TYPE (datum); + register enum tree_code code = TREE_CODE (basetype); + register tree ref; + + if (code == REFERENCE_TYPE) + { + datum = convert_from_reference (datum); + basetype = TREE_TYPE (datum); + code = TREE_CODE (basetype); + } + + if (! IS_AGGR_TYPE_CODE (code)) + { + if (code != ERROR_MARK) + cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'", + field, datum, basetype); + return error_mark_node; + } + + if (TYPE_SIZE (basetype) == 0) + { + incomplete_type_error (0, basetype); + return error_mark_node; + } + + /* Look up component name in the structure type definition. */ + + if (field == error_mark_node) + my_friendly_abort (115); + + if (TREE_STATIC (field)) + return field; + + if (datum == C_C_D) + { + enum access_type access + = compute_access (TYPE_BINFO (current_class_type), field); + + if (access == access_private) + { + cp_error ("field `%D' is private", field); + return error_mark_node; + } + else if (access == access_protected) + { + cp_error ("field `%D' is protected", field); + return error_mark_node; + } + } + + ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field); + + if (TREE_READONLY (datum) || TREE_READONLY (field)) + TREE_READONLY (ref) = 1; + if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field)) + TREE_THIS_VOLATILE (ref) = 1; + if (DECL_MUTABLE_P (field)) + TREE_READONLY (ref) = 0; + + return ref; +} + +/* Given a COND_EXPR in T, return it in a form that we can, for + example, use as an lvalue. This code used to be in unary_complex_lvalue, + but we needed it to deal with `a = (d == c) ? b : c' expressions, where + we're dealing with aggregates. So, we now call this in unary_complex_lvalue, + and in build_modify_expr. The case (in particular) that led to this was + with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there. */ +static tree +rationalize_conditional_expr (code, t) + enum tree_code code; + tree t; +{ + return + build_conditional_expr (TREE_OPERAND (t, 0), + build_unary_op (code, TREE_OPERAND (t, 1), 0), + build_unary_op (code, TREE_OPERAND (t, 2), 0)); +} + +tree +build_component_ref (datum, component, basetype_path, protect) + tree datum, component, basetype_path; + int protect; +{ + register tree basetype = TREE_TYPE (datum); + register enum tree_code code = TREE_CODE (basetype); + register tree field = NULL; + register tree ref; + + /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */ + switch (TREE_CODE (datum)) + { + case COMPOUND_EXPR: + { + tree value = build_component_ref (TREE_OPERAND (datum, 1), component, + basetype_path, protect); + return build (COMPOUND_EXPR, TREE_TYPE (value), + TREE_OPERAND (datum, 0), value); + } + case COND_EXPR: + return build_conditional_expr + (TREE_OPERAND (datum, 0), + build_component_ref (TREE_OPERAND (datum, 1), component, + basetype_path, protect), + build_component_ref (TREE_OPERAND (datum, 2), component, + basetype_path, protect)); + } + + if (code == REFERENCE_TYPE) + { +#if 0 + /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'. + @@ Maybe that is not right. */ + if (TREE_REFERENCE_EXPR (datum)) + datum = build1 (INDIRECT_REF, TREE_TYPE (basetype), datum); + else +#endif + datum = convert_from_reference (datum); + basetype = TREE_TYPE (datum); + code = TREE_CODE (basetype); + } + + /* First, see if there is a field or component with name COMPONENT. */ + if (TREE_CODE (component) == TREE_LIST) + { + my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE + && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309); + return build (COMPONENT_REF, TREE_TYPE (component), datum, component); + } +#if 0 + if (TREE_CODE (component) == TYPE_EXPR) + return build_component_type_expr (datum, component, NULL_TREE, protect); +#endif + + if (! IS_AGGR_TYPE_CODE (code)) + { + if (code != ERROR_MARK) + cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'", + component, datum, basetype); + return error_mark_node; + } + + if (TYPE_SIZE (basetype) == 0) + { + incomplete_type_error (0, basetype); + return error_mark_node; + } + + if (TREE_CODE (component) == BIT_NOT_EXPR) + { + if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0)) + { + cp_error ("destructor specifier `%T::~%T' must have matching names", + basetype, TREE_OPERAND (component, 0)); + return error_mark_node; + } + if (! TYPE_HAS_DESTRUCTOR (basetype)) + { + cp_error ("type `%T' has no destructor", basetype); + return error_mark_node; + } + return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0); + } + + /* Look up component name in the structure type definition. */ + if (CLASSTYPE_VFIELD (basetype) + && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component) + /* Special-case this because if we use normal lookups in an ambiguous + hierarchy, the compiler will abort (because vptr lookups are + not supposed to be ambiguous. */ + field = CLASSTYPE_VFIELD (basetype); + else + { + if (basetype_path == NULL_TREE) + basetype_path = TYPE_BINFO (basetype); + field = lookup_field (basetype_path, component, + protect && ! VFIELD_NAME_P (component), 0); + if (field == error_mark_node) + return error_mark_node; + + if (field == NULL_TREE) + { + /* Not found as a data field, look for it as a method. If found, + then if this is the only possible one, return it, else + report ambiguity error. */ + tree fndecls = lookup_fnfields (basetype_path, component, 1); + if (fndecls == error_mark_node) + return error_mark_node; + if (fndecls) + { + if (TREE_CHAIN (fndecls) == NULL_TREE + && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE) + { + enum access_type access; + tree fndecl; + + /* Unique, so use this one now. */ + basetype = TREE_PURPOSE (fndecls); + fndecl = TREE_VALUE (fndecls); + access = compute_access (TREE_PURPOSE (fndecls), fndecl); + if (access == access_public) + { + if (DECL_VINDEX (fndecl) + && ! resolves_to_fixed_type_p (datum, 0)) + { + tree addr = build_unary_op (ADDR_EXPR, datum, 0); + addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr); + datum = build_indirect_ref (addr, NULL_PTR); + my_friendly_assert (datum != error_mark_node, 310); + fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl)); + } + assemble_external (fndecl); + return fndecl; + } + if (access == access_protected) + cp_error ("member function `%D' is protected", fndecl); + else + cp_error ("member function `%D' is private", fndecl); + return error_mark_node; + } + else + { + /* Just act like build_offset_ref, since the object does + not matter unless we're actually calling the function. */ + tree t; + + for (t = TREE_VALUE (fndecls); t; t = DECL_CHAIN (t)) + assemble_external (t); + + t = build_tree_list (error_mark_node, fndecls); + TREE_TYPE (t) = build_offset_type (basetype, + unknown_type_node); + return t; + } + } + +#if 0 + if (component == ansi_opname[(int) TYPE_EXPR]) + cp_error ("`%#T' has no such type conversion operator", basetype); + else +#endif + cp_error ("`%#T' has no member named `%D'", basetype, component); + return error_mark_node; + } + else if (TREE_TYPE (field) == error_mark_node) + return error_mark_node; + + if (TREE_CODE (field) != FIELD_DECL) + { + if (TREE_CODE (field) == TYPE_DECL) + { + cp_error ("invalid use of type decl `%#D' as expression", field); + return error_mark_node; + } + if (DECL_RTL (field) != 0) + assemble_external (field); + TREE_USED (field) = 1; + return field; + } + } + + if (DECL_FIELD_CONTEXT (field) != basetype + && TYPE_USES_COMPLEX_INHERITANCE (basetype)) + { + tree addr = build_unary_op (ADDR_EXPR, datum, 0); + if (integer_zerop (addr)) + { + error ("invalid reference to NULL ptr, use ptr-to-member instead"); + return error_mark_node; + } + addr = convert_pointer_to (DECL_FIELD_CONTEXT (field), addr); + datum = build_indirect_ref (addr, NULL_PTR); + my_friendly_assert (datum != error_mark_node, 311); + } + ref = fold (build (COMPONENT_REF, TREE_TYPE (field), + break_out_cleanups (datum), field)); + + if (TREE_READONLY (datum) || TREE_READONLY (field)) + TREE_READONLY (ref) = 1; + if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field)) + TREE_THIS_VOLATILE (ref) = 1; + if (DECL_MUTABLE_P (field)) + TREE_READONLY (ref) = 0; + + return ref; +} + +/* Given an expression PTR for a pointer, return an expression + for the value pointed to. + ERRORSTRING is the name of the operator to appear in error messages. + + This function may need to overload OPERATOR_FNNAME. + Must also handle REFERENCE_TYPEs for C++. */ + +tree +build_x_indirect_ref (ptr, errorstring) + tree ptr; + char *errorstring; +{ + tree rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE); + if (rval) + return rval; + return build_indirect_ref (ptr, errorstring); +} + +tree +build_indirect_ref (ptr, errorstring) + tree ptr; + char *errorstring; +{ + register tree pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE ? + ptr : default_conversion (ptr)); + register tree type = TREE_TYPE (pointer); + + if (ptr == current_class_decl) + return C_C_D; + + if (IS_AGGR_TYPE (type)) + { + ptr = build_expr_type_conversion (WANT_POINTER, pointer, 1); + + if (ptr) + { + pointer = ptr; + type = TREE_TYPE (pointer); + } + } + + if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE) + { + if (TREE_CODE (pointer) == ADDR_EXPR + && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer, 0))) + == TYPE_MAIN_VARIANT (TREE_TYPE (type))) + && (TREE_READONLY (TREE_OPERAND (pointer, 0)) + == TYPE_READONLY (TREE_TYPE (type))) + && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer, 0)) + == TYPE_VOLATILE (TREE_TYPE (type)))) + return TREE_OPERAND (pointer, 0); + else + { + tree t = TREE_TYPE (type); + register tree ref = build1 (INDIRECT_REF, + TYPE_MAIN_VARIANT (t), pointer); + + TREE_READONLY (ref) = TYPE_READONLY (t); + TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t); + TREE_SIDE_EFFECTS (ref) + = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer); + return ref; + } + } + /* `pointer' won't be an error_mark_node if we were given a + pointer to member, so it's cool to check for this here. */ + else if (TYPE_PTRMEMFUNC_P (type)) + error ("invalid use of `%s' on pointer to member function", errorstring); + else if (TREE_CODE (type) == RECORD_TYPE + && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))) + error ("cannot dereference signature pointer/reference"); + else if (pointer != error_mark_node) + { + if (errorstring) + error ("invalid type argument of `%s'", errorstring); + else + error ("invalid type argument"); + } + return error_mark_node; +} + +/* This handles expressions of the form "a[i]", which denotes + an array reference. + + This is logically equivalent in C to *(a+i), but we may do it differently. + If A is a variable or a member, we generate a primitive ARRAY_REF. + This avoids forcing the array out of registers, and can work on + arrays that are not lvalues (for example, members of structures returned + by functions). + + If INDEX is of some user-defined type, it must be converted to + integer type. Otherwise, to make a compatible PLUS_EXPR, it + will inherit the type of the array, which will be some pointer type. */ + +tree +build_x_array_ref (array, index) + tree array, index; +{ + tree rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, index, NULL_TREE); + if (rval) + return rval; + return build_array_ref (array, index); +} + +tree +build_array_ref (array, idx) + tree array, idx; +{ + tree itype; + + if (idx == 0) + { + error ("subscript missing in array reference"); + return error_mark_node; + } + + if (TREE_TYPE (array) == error_mark_node + || TREE_TYPE (idx) == error_mark_node) + return error_mark_node; + + itype = TREE_TYPE (idx); + + if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE + && TREE_CODE (array) != INDIRECT_REF) + { + tree rval, type; + + /* Subscripting with type char is likely to lose + on a machine where chars are signed. + So warn on any machine, but optionally. + Don't warn for unsigned char since that type is safe. + Don't warn for signed char because anyone who uses that + must have done so deliberately. */ + if (warn_char_subscripts + && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node) + warning ("array subscript has type `char'"); + + /* Apply default promotions *after* noticing character types. */ + idx = default_conversion (idx); + + if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE) + { + error ("array subscript is not an integer"); + return error_mark_node; + } + + /* An array that is indexed by a non-constant + cannot be stored in a register; we must be able to do + address arithmetic on its address. + Likewise an array of elements of variable size. */ + if (TREE_CODE (idx) != INTEGER_CST + || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0 + && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST)) + { + if (mark_addressable (array) == 0) + return error_mark_node; + } + /* An array that is indexed by a constant value which is not within + the array bounds cannot be stored in a register either; because we + would get a crash in store_bit_field/extract_bit_field when trying + to access a non-existent part of the register. */ + if (TREE_CODE (idx) == INTEGER_CST + && TYPE_VALUES (TREE_TYPE (array)) + && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array)))) + { + if (mark_addressable (array) == 0) + return error_mark_node; + } + + if (pedantic && !lvalue_p (array)) + pedwarn ("ANSI C++ forbids subscripting non-lvalue array"); + + /* Note in C++ it is valid to subscript a `register' array, since + it is valid to take the address of something with that + storage specification. */ + if (extra_warnings) + { + tree foo = array; + while (TREE_CODE (foo) == COMPONENT_REF) + foo = TREE_OPERAND (foo, 0); + if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo)) + warning ("subscripting array declared `register'"); + } + + type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array))); + rval = build (ARRAY_REF, type, array, idx); + /* Array ref is const/volatile if the array elements are + or if the array is.. */ + TREE_READONLY (rval) + |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array))) + | TREE_READONLY (array)); + TREE_SIDE_EFFECTS (rval) + |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) + | TREE_SIDE_EFFECTS (array)); + TREE_THIS_VOLATILE (rval) + |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array))) + /* This was added by rms on 16 Nov 91. + It fixes vol struct foo *a; a->elts[1] + in an inline function. + Hope it doesn't break something else. */ + | TREE_THIS_VOLATILE (array)); + return require_complete_type (fold (rval)); + } + + { + tree ar = default_conversion (array); + tree ind = default_conversion (idx); + + /* Put the integer in IND to simplify error checking. */ + if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE) + { + tree temp = ar; + ar = ind; + ind = temp; + } + + if (ar == error_mark_node) + return ar; + + if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE) + { + error ("subscripted value is neither array nor pointer"); + return error_mark_node; + } + if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE) + { + error ("array subscript is not an integer"); + return error_mark_node; + } + + return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR), + "array indexing"); + } +} + +/* Build a function call to function FUNCTION with parameters PARAMS. + PARAMS is a list--a chain of TREE_LIST nodes--in which the + TREE_VALUE of each node is a parameter-expression. + FUNCTION's data type may be a function type or a pointer-to-function. + + For C++: If FUNCTION's data type is a TREE_LIST, then the tree list + is the list of possible methods that FUNCTION could conceivably + be. If the list of methods comes from a class, then it will be + a list of lists (where each element is associated with the class + that produced it), otherwise it will be a simple list (for + functions overloaded in global scope). + + In the first case, TREE_VALUE (function) is the head of one of those + lists, and TREE_PURPOSE is the name of the function. + + In the second case, TREE_PURPOSE (function) is the function's + name directly. + + DECL is the class instance variable, usually CURRENT_CLASS_DECL. */ + +/* + * [eichin:19911015.1726EST] actually return a possibly incomplete + * type + */ +tree +build_x_function_call (function, params, decl) + tree function, params, decl; +{ + tree type; + int is_method; + + if (function == error_mark_node) + return error_mark_node; + + type = TREE_TYPE (function); + is_method = ((TREE_CODE (function) == TREE_LIST + && current_class_type != NULL_TREE + && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function) + || TREE_CODE (function) == IDENTIFIER_NODE + || TREE_CODE (type) == METHOD_TYPE + || TYPE_PTRMEMFUNC_P (type)); + + /* Handle methods, friends, and overloaded functions, respectively. */ + if (is_method) + { + if (TREE_CODE (function) == FUNCTION_DECL) + { + if (DECL_NAME (function)) + function = DECL_NAME (function); + else + function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function)); + } + else if (TREE_CODE (function) == TREE_LIST) + { +#if 0 + if (TREE_CODE (TREE_VALUE (function)) == TREE_LIST) + function = TREE_PURPOSE (TREE_VALUE (function)); + else + function = TREE_PURPOSE (function); +#else + my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312); + function = TREE_PURPOSE (function); +#endif + } + else if (TREE_CODE (function) != IDENTIFIER_NODE) + { + if (TREE_CODE (function) == OFFSET_REF) + { + if (TREE_OPERAND (function, 0)) + decl = TREE_OPERAND (function, 0); + } + /* Call via a pointer to member function. */ + if (decl == NULL_TREE) + { + error ("pointer to member function called, but not in class scope"); + return error_mark_node; + } + /* What other type of POINTER_TYPE could this be? */ + if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE + && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function)) + && TREE_CODE (function) != OFFSET_REF) + function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function); + goto do_x_function; + } + + /* this is an abbreviated method call. + must go through here in case it is a virtual function. + @@ Perhaps this could be optimized. */ + + if (decl == NULL_TREE) + { + if (current_class_type == NULL_TREE) + { + error ("object missing in call to method `%s'", + IDENTIFIER_POINTER (function)); + return error_mark_node; + } + /* Yow: call from a static member function. */ + decl = build1 (NOP_EXPR, build_pointer_type (current_class_type), + error_mark_node); + decl = build_indirect_ref (decl, NULL_PTR); + } + + return build_method_call (decl, function, params, + NULL_TREE, LOOKUP_NORMAL); + } + else if (TREE_CODE (function) == COMPONENT_REF + && type == unknown_type_node) + { + /* Should we undo what was done in build_component_ref? */ + if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC) + /* Get the name that build_component_ref hid. */ + function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1))); + else + function = TREE_PURPOSE (TREE_OPERAND (function, 1)); + return build_method_call (decl, function, params, + NULL_TREE, LOOKUP_NORMAL); + } + else if (TREE_CODE (function) == TREE_LIST) + { + if (TREE_VALUE (function) == NULL_TREE) + { + cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?", + TREE_PURPOSE (function)); + return error_mark_node; + } + else + { + tree val = TREE_VALUE (function); + + if (TREE_CODE (val) == TEMPLATE_DECL) + return build_overload_call_maybe + (function, params, LOOKUP_COMPLAIN, (struct candidate *)0); + else if (DECL_CHAIN (val) != NULL_TREE) + return build_overload_call + (function, params, LOOKUP_COMPLAIN, (struct candidate *)0); + else + my_friendly_abort (360); + } + } + + do_x_function: + if (TREE_CODE (function) == OFFSET_REF) + { + /* If the component is a data element (or a virtual function), we play + games here to make things work. */ + tree decl_addr; + + if (TREE_OPERAND (function, 0)) + decl = TREE_OPERAND (function, 0); + else + decl = C_C_D; + + decl_addr = build_unary_op (ADDR_EXPR, decl, 0); + function = get_member_function_from_ptrfunc (&decl_addr, + TREE_OPERAND (function, 1)); + params = tree_cons (NULL_TREE, decl_addr, params); + return build_function_call (function, params); + } + + type = TREE_TYPE (function); + if (type != error_mark_node) + { + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + if (TYPE_LANG_SPECIFIC (type) && TYPE_OVERLOADS_CALL_EXPR (type)) + return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE); + } + + if (is_method) + { + tree fntype = TREE_TYPE (function); + tree ctypeptr; + + /* Explicitly named method? */ + if (TREE_CODE (function) == FUNCTION_DECL) + ctypeptr = build_pointer_type (DECL_CLASS_CONTEXT (function)); + /* Expression with ptr-to-method type? It could either be a plain + usage, or it might be a case where the ptr-to-method is being + passed in as an argument. */ + else if (TYPE_PTRMEMFUNC_P (fntype)) + { + tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype))); + ctypeptr = build_pointer_type (rec); + } + /* Unexpected node type? */ + else + my_friendly_abort (116); + if (decl == NULL_TREE) + { + if (current_function_decl + && DECL_STATIC_FUNCTION_P (current_function_decl)) + error ("invalid call to member function needing `this' in static member function scope"); + else + error ("pointer to member function called, but not in class scope"); + return error_mark_node; + } + if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE + && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl))) + { + decl = build_unary_op (ADDR_EXPR, decl, 0); + decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl); + } + else + decl = build_c_cast (ctypeptr, decl, 0); + params = tree_cons (NULL_TREE, decl, params); + } + + return build_function_call (function, params); +} + +/* Resolve a pointer to member function. INSTANCE is the object + instance to use, if the member points to a virtual member. */ + +tree +get_member_function_from_ptrfunc (instance_ptrptr, function) + tree *instance_ptrptr; + tree function; +{ + if (TREE_CODE (function) == OFFSET_REF) + { + function = TREE_OPERAND (function, 1); + } + + if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function))) + { + tree fntype, index, e1, delta, delta2, e2, e3, aref, vtbl; + tree instance; + + tree instance_ptr = *instance_ptrptr; + + if (TREE_SIDE_EFFECTS (instance_ptr)) + instance_ptr = save_expr (instance_ptr); + + if (TREE_SIDE_EFFECTS (function)) + function = save_expr (function); + + fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function)); + index = save_expr (build_component_ref (function, + index_identifier, + 0, 0)); + e1 = build (GT_EXPR, boolean_type_node, index, + convert (delta_type_node, integer_zero_node)); + delta = convert (ptrdiff_type_node, + build_component_ref (function, delta_identifier, 0, 0)); + delta2 = DELTA2_FROM_PTRMEMFUNC (function); + + /* convert down to the right base, before using the instance. */ + instance + = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype)), + instance_ptr); + if (instance == error_mark_node) + return instance; + + vtbl = convert_pointer_to (ptr_type_node, instance); + vtbl + = build (PLUS_EXPR, + build_pointer_type (build_pointer_type (vtable_entry_type)), + vtbl, convert (ptrdiff_type_node, delta2)); + vtbl = build_indirect_ref (vtbl, NULL_PTR); + aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR, + index, + integer_one_node, 1)); + if (! flag_vtable_thunks) + { + aref = save_expr (aref); + + /* Save the intermediate result in a SAVE_EXPR so we don't have to + compute each component of the virtual function pointer twice. */ + if (/* !building_cleanup && */ TREE_CODE (aref) == INDIRECT_REF) + TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0)); + + delta = build_binary_op (PLUS_EXPR, + build_conditional_expr (e1, build_component_ref (aref, delta_identifier, 0, 0), integer_zero_node), + delta, 1); + } + + *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr), + instance_ptr, delta); + if (flag_vtable_thunks) + e2 = aref; + else + e2 = build_component_ref (aref, pfn_identifier, 0, 0); + + e3 = PFN_FROM_PTRMEMFUNC (function); + TREE_TYPE (e2) = TREE_TYPE (e3); + function = build_conditional_expr (e1, e2, e3); + + /* Make sure this doesn't get evaluated first inside one of the + branches of the COND_EXPR. */ + if (TREE_CODE (instance_ptr) == SAVE_EXPR) + function = build (COMPOUND_EXPR, TREE_TYPE (function), + instance_ptr, function); + } + return function; +} + +tree +build_function_call_real (function, params, require_complete, flags) + tree function, params; + int require_complete, flags; +{ + register tree fntype, fndecl; + register tree value_type; + register tree coerced_params; + tree name = NULL_TREE, assembler_name = NULL_TREE; + int is_method; + + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context. */ + if (TREE_CODE (function) == NOP_EXPR + && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0))) + function = TREE_OPERAND (function, 0); + + if (TREE_CODE (function) == FUNCTION_DECL) + { + name = DECL_NAME (function); + assembler_name = DECL_ASSEMBLER_NAME (function); + + GNU_xref_call (current_function_decl, + IDENTIFIER_POINTER (name ? name + : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function)))); + assemble_external (function); + fndecl = function; + + /* Convert anything with function type to a pointer-to-function. */ + if (pedantic + && name + && IDENTIFIER_LENGTH (name) == 4 + && ! strcmp (IDENTIFIER_POINTER (name), "main") + && DECL_CONTEXT (function) == NULL_TREE) + { + pedwarn ("ANSI C++ forbids calling `main' from within program"); + } + + if (pedantic && DECL_THIS_INLINE (function) && ! DECL_INITIAL (function) + && ! DECL_ARTIFICIAL (function) + && ! DECL_PENDING_INLINE_INFO (function)) + cp_pedwarn ("inline function `%#D' called before definition", + function); + + /* Differs from default_conversion by not setting TREE_ADDRESSABLE + (because calling an inline function does not mean the function + needs to be separately compiled). */ + + if (DECL_INLINE (function)) + { + /* Is it a synthesized method that needs to be synthesized? */ + if (DECL_ARTIFICIAL (function) && ! flag_no_inline + && ! DECL_INITIAL (function) + /* Kludge: don't synthesize for default args. */ + && current_function_decl) + synthesize_method (function); + + fntype = build_type_variant (TREE_TYPE (function), + TREE_READONLY (function), + TREE_THIS_VOLATILE (function)); + function = build1 (ADDR_EXPR, build_pointer_type (fntype), function); + } + else + { + assemble_external (function); + TREE_USED (function) = 1; + function = default_conversion (function); + } + } + else + { + fndecl = NULL_TREE; + + /* Convert anything with function type to a pointer-to-function. */ + if (function == error_mark_node) + return error_mark_node; + function = default_conversion (function); + } + + fntype = TREE_TYPE (function); + + if (TYPE_PTRMEMFUNC_P (fntype)) + { + tree instance_ptr = build_unary_op (ADDR_EXPR, C_C_D, 0); + fntype = TYPE_PTRMEMFUNC_FN_TYPE (fntype); + function = get_member_function_from_ptrfunc (&instance_ptr, function); + } + + is_method = (TREE_CODE (fntype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE); + + if (!((TREE_CODE (fntype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE) + || is_method)) + { + cp_error ("`%E' cannot be used as a function", function); + return error_mark_node; + } + + /* fntype now gets the type of function pointed to. */ + fntype = TREE_TYPE (fntype); + + /* Convert the parameters to the types declared in the + function prototype, or apply default promotions. */ + + if (flags & LOOKUP_COMPLAIN) + coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype), + params, fndecl, LOOKUP_NORMAL); + else + coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype), + params, fndecl, 0); + + if (coerced_params == error_mark_node) + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + else + return error_mark_node; + + /* Check for errors in format strings. */ + + if (warn_format && (name || assembler_name)) + check_function_format (name, assembler_name, coerced_params); + + /* Recognize certain built-in functions so we can make tree-codes + other than CALL_EXPR. We do this when it enables fold-const.c + to do something useful. */ + + if (TREE_CODE (function) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL + && DECL_BUILT_IN (TREE_OPERAND (function, 0))) + switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0))) + { + case BUILT_IN_ABS: + case BUILT_IN_LABS: + case BUILT_IN_FABS: + if (coerced_params == 0) + return integer_zero_node; + return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0); + } + + /* C++ */ + value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node; + { + register tree result = + build (CALL_EXPR, value_type, + function, coerced_params, NULL_TREE); + + TREE_SIDE_EFFECTS (result) = 1; + + if (! require_complete) + return convert_from_reference (result); + if (value_type == void_type_node) + return result; + result = require_complete_type (result); + return convert_from_reference (result); + } +} + +tree +build_function_call (function, params) + tree function, params; +{ + return build_function_call_real (function, params, 1, LOOKUP_NORMAL); +} + +tree +build_function_call_maybe (function, params) + tree function, params; +{ + return build_function_call_real (function, params, 0, 0); +} + + +/* Convert the actual parameter expressions in the list VALUES + to the types in the list TYPELIST. + If parmdecls is exhausted, or when an element has NULL as its type, + perform the default conversions. + + RETURN_LOC is the location of the return value, if known, NULL_TREE + otherwise. This is useful in the case where we can avoid creating + a temporary variable in the case where we can initialize the return + value directly. If we are not eliding constructors, then we set this + to NULL_TREE to avoid this avoidance. + + NAME is an IDENTIFIER_NODE or 0. It is used only for error messages. + + This is also where warnings about wrong number of args are generated. + + Return a list of expressions for the parameters as converted. + + Both VALUES and the returned value are chains of TREE_LIST nodes + with the elements of the list in the TREE_VALUE slots of those nodes. + + In C++, unspecified trailing parameters can be filled in with their + default arguments, if such were specified. Do so here. */ + +tree +convert_arguments (return_loc, typelist, values, fndecl, flags) + tree return_loc, typelist, values, fndecl; + int flags; +{ + extern tree gc_protect_fndecl; + register tree typetail, valtail; + register tree result = NULL_TREE; + char *called_thing; + int i = 0; + + if (! flag_elide_constructors) + return_loc = 0; + + if (fndecl) + { + if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE) + { + if (DECL_NAME (fndecl) == NULL_TREE + || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl))) + called_thing = "constructor"; + else + called_thing = "member function"; + } + else + called_thing = "function"; + } + + for (valtail = values, typetail = typelist; + valtail; + valtail = TREE_CHAIN (valtail), i++) + { + register tree type = typetail ? TREE_VALUE (typetail) : 0; + register tree val = TREE_VALUE (valtail); + + if (val == error_mark_node) + return error_mark_node; + + if (type == void_type_node) + { + if (fndecl) + { + char *buf = (char *)alloca (40 + strlen (called_thing)); + sprintf (buf, "too many arguments to %s `%%s'", called_thing); + error_with_decl (fndecl, buf); + error ("at this point in file"); + } + else + error ("too many arguments to function"); + /* In case anybody wants to know if this argument + list is valid. */ + if (result) + TREE_TYPE (tree_last (result)) = error_mark_node; + break; + } + + /* The tree type of the parameter being passed may not yet be + known. In this case, its type is TYPE_UNKNOWN, and will + be instantiated by the type given by TYPE. If TYPE + is also NULL, the tree type of VAL is ERROR_MARK_NODE. */ + if (type && type_unknown_p (val)) + val = require_instantiated_type (type, val, integer_zero_node); + else if (type_unknown_p (val)) + { + /* Strip the `&' from an overloaded FUNCTION_DECL. */ + if (TREE_CODE (val) == ADDR_EXPR) + val = TREE_OPERAND (val, 0); + if (TREE_CODE (val) == TREE_LIST + && TREE_CHAIN (val) == NULL_TREE + && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE + && (TREE_TYPE (val) == unknown_type_node + || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE)) + /* Instantiates automatically. */ + val = TREE_VALUE (val); + else + { + error ("insufficient type information in parameter list"); + val = integer_zero_node; + } + } + else if (TREE_CODE (val) == OFFSET_REF + && TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE) + { + /* This is unclean. Should be handled elsewhere. */ + val = build_unary_op (ADDR_EXPR, val, 0); + } + else if (TREE_CODE (val) == OFFSET_REF) + val = resolve_offset_ref (val); + + { +#if 0 + /* This code forces the assumption that if we have a ptr-to-func + type in an arglist, that every routine that wants to check + its validity has done so, and thus we need not do any + more conversion. I don't remember why this is necessary. */ + else if (TREE_CODE (ttype) == FUNCTION_TYPE + && (type == NULL + || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (type)) == VOID_TYPE)) + { + type = build_pointer_type (ttype); + } +#endif + } + + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Strip such NOP_EXPRs, since VAL is used in non-lvalue context. */ + if (TREE_CODE (val) == NOP_EXPR + && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)) + && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)) + val = TREE_OPERAND (val, 0); + + if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE) + { + if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE) + val = default_conversion (val); + + val = require_complete_type (val); + } + + if (val == error_mark_node) + return error_mark_node; + + if (type != 0) + { + /* Formal parm type is specified by a function prototype. */ + tree parmval; + + if (TYPE_SIZE (type) == 0) + { + error ("parameter type of called function is incomplete"); + parmval = val; + } + else + { +#if 0 && defined (PROMOTE_PROTOTYPES) + /* This breaks user-defined conversions. */ + /* Rather than truncating and then reextending, + convert directly to int, if that's the type we will want. */ + if (! flag_traditional + && (TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) + type = integer_type_node; +#endif + parmval = convert_for_initialization (return_loc, type, val, flags, + "argument passing", fndecl, i); +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) + parmval = default_conversion (parmval); +#endif + } + + if (parmval == error_mark_node) + return error_mark_node; + + result = tree_cons (NULL_TREE, parmval, result); + } + else + { + if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE) + val = convert_from_reference (val); + + if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE + && (TYPE_PRECISION (TREE_TYPE (val)) + < TYPE_PRECISION (double_type_node))) + /* Convert `float' to `double'. */ + result = tree_cons (NULL_TREE, convert (double_type_node, val), result); + else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val)) + && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val))) + { + cp_warning ("cannot pass objects of type `%T' through `...'", + TREE_TYPE (val)); + result = tree_cons (NULL_TREE, val, result); + } + else + /* Convert `short' and `char' to full-size `int'. */ + result = tree_cons (NULL_TREE, default_conversion (val), result); + } + + if (flag_gc + /* There are certain functions for which we don't need + to protect our arguments. GC_PROTECT_FNDECL is one. */ + && fndecl != gc_protect_fndecl + && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result))) + && ! value_safe_from_gc (NULL_TREE, TREE_VALUE (result))) + /* This will build a temporary variable whose cleanup is + to clear the obstack entry. */ + TREE_VALUE (result) = protect_value_from_gc (NULL_TREE, + TREE_VALUE (result)); + + if (typetail) + typetail = TREE_CHAIN (typetail); + } + + if (typetail != 0 && typetail != void_list_node) + { + /* See if there are default arguments that can be used */ + if (TREE_PURPOSE (typetail)) + { + for (; typetail != void_list_node; ++i) + { + tree type = TREE_VALUE (typetail); + tree val = break_out_target_exprs (TREE_PURPOSE (typetail)); + tree parmval; + + if (val == NULL_TREE) + parmval = error_mark_node; + else if (TREE_CODE (val) == CONSTRUCTOR) + { + parmval = digest_init (type, val, (tree *)0); + parmval = convert_for_initialization (return_loc, type, parmval, flags, + "default constructor", fndecl, i); + } + else + { + /* This could get clobbered by the following call. */ + if (TREE_HAS_CONSTRUCTOR (val)) + val = copy_node (val); + + parmval = convert_for_initialization (return_loc, type, val, flags, + "default argument", fndecl, i); +#ifdef PROMOTE_PROTOTYPES + if ((TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))) + parmval = default_conversion (parmval); +#endif + } + + if (parmval == error_mark_node) + return error_mark_node; + + if (flag_gc + && type_needs_gc_entry (TREE_TYPE (parmval)) + && ! value_safe_from_gc (NULL_TREE, parmval)) + parmval = protect_value_from_gc (NULL_TREE, parmval); + + result = tree_cons (0, parmval, result); + typetail = TREE_CHAIN (typetail); + /* ends with `...'. */ + if (typetail == NULL_TREE) + break; + } + } + else + { + if (fndecl) + { + char *buf = (char *)alloca (32 + strlen (called_thing)); + sprintf (buf, "too few arguments to %s `%%#D'", called_thing); + cp_error_at (buf, fndecl); + error ("at this point in file"); + } + else + error ("too few arguments to function"); + return error_mark_list; + } + } + + return nreverse (result); +} + +/* Build a binary-operation expression, after performing default + conversions on the operands. CODE is the kind of expression to build. */ + +tree +build_x_binary_op (code, arg1, arg2) + enum tree_code code; + tree arg1, arg2; +{ + tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY, + arg1, arg2, NULL_TREE); + if (rval) + return build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE); + if (code == MEMBER_REF) + return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR), + arg2); + return build_binary_op (code, arg1, arg2, 1); +} + +tree +build_binary_op (code, arg1, arg2, convert_p) + enum tree_code code; + tree arg1, arg2; + int convert_p; +{ + tree args[2]; + + args[0] = arg1; + args[1] = arg2; + + if (convert_p) + { + tree args_save [2]; + tree type0, type1; + args[0] = decay_conversion (args[0]); + args[1] = decay_conversion (args[1]); + + if (args[0] == error_mark_node || args[1] == error_mark_node) + return error_mark_node; + + type0 = TREE_TYPE (args[0]); + type1 = TREE_TYPE (args[1]); + + if (type_unknown_p (args[0])) + { + args[0] = instantiate_type (type1, args[0], 1); + args[0] = decay_conversion (args[0]); + } + else if (type_unknown_p (args[1])) + { + args[1] = require_instantiated_type (type0, args[1], + error_mark_node); + args[1] = decay_conversion (args[1]); + } + + if (IS_AGGR_TYPE (type0) || IS_AGGR_TYPE (type1)) + { + /* Try to convert this to something reasonable. */ + if (! build_default_binary_type_conversion(code, &args[0], &args[1])) + { + cp_error ("no match for `%O(%#T, %#T)'", code, + TREE_TYPE (arg1), TREE_TYPE (arg2)); + return error_mark_node; + } + } + } + return build_binary_op_nodefault (code, args[0], args[1], code); +} + +/* Build a binary-operation expression without default conversions. + CODE is the kind of expression to build. + This function differs from `build' in several ways: + the data type of the result is computed and recorded in it, + warnings are generated if arg data types are invalid, + special handling for addition and subtraction of pointers is known, + and some optimization is done (operations on narrow ints + are done in the narrower type when that gives the same result). + Constant folding is also done before the result is returned. + + ERROR_CODE is the code that determines what to say in error messages. + It is usually, but not always, the same as CODE. + + Note that the operands will never have enumeral types + because either they have just had the default conversions performed + or they have both just been converted to some other type in which + the arithmetic is to be done. + + C++: must do special pointer arithmetic when implementing + multiple inheritance, and deal with pointer to member functions. */ + +tree +build_binary_op_nodefault (code, orig_op0, orig_op1, error_code) + enum tree_code code; + tree orig_op0, orig_op1; + enum tree_code error_code; +{ + tree op0, op1; + register enum tree_code code0, code1; + tree type0, type1; + + /* Expression code to give to the expression when it is built. + Normally this is CODE, which is what the caller asked for, + but in some special cases we change it. */ + register enum tree_code resultcode = code; + + /* Data type in which the computation is to be performed. + In the simplest cases this is the common type of the arguments. */ + register tree result_type = NULL; + + /* Nonzero means operands have already been type-converted + in whatever way is necessary. + Zero means they need to be converted to RESULT_TYPE. */ + int converted = 0; + + /* Nonzero means create the expression with this type, rather than + RESULT_TYPE. */ + tree build_type = 0; + + /* Nonzero means after finally constructing the expression + convert it to this type. */ + tree final_type = 0; + + /* Nonzero if this is an operation like MIN or MAX which can + safely be computed in short if both args are promoted shorts. + Also implies COMMON. + -1 indicates a bitwise operation; this makes a difference + in the exact conditions for when it is safe to do the operation + in a narrower mode. */ + int shorten = 0; + + /* Nonzero if this is a comparison operation; + if both args are promoted shorts, compare the original shorts. + Also implies COMMON. */ + int short_compare = 0; + + /* Nonzero if this is a right-shift operation, which can be computed on the + original short and then promoted if the operand is a promoted short. */ + int short_shift = 0; + + /* Nonzero means set RESULT_TYPE to the common type of the args. */ + int common = 0; + + /* Apply default conversions. */ + if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR + || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR + || code == TRUTH_XOR_EXPR) + { + op0 = decay_conversion (orig_op0); + op1 = decay_conversion (orig_op1); + } + else + { + op0 = default_conversion (orig_op0); + op1 = default_conversion (orig_op1); + } + + type0 = TREE_TYPE (op0); + type1 = TREE_TYPE (op1); + + /* The expression codes of the data types of the arguments tell us + whether the arguments are integers, floating, pointers, etc. */ + code0 = TREE_CODE (type0); + code1 = TREE_CODE (type1); + + /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue. */ + STRIP_TYPE_NOPS (op0); + STRIP_TYPE_NOPS (op1); + + /* If an error was already reported for one of the arguments, + avoid reporting another error. */ + + if (code0 == ERROR_MARK || code1 == ERROR_MARK) + return error_mark_node; + + switch (code) + { + case PLUS_EXPR: + /* Handle the pointer + int case. */ + if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + return pointer_int_sum (PLUS_EXPR, op0, op1); + else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE) + return pointer_int_sum (PLUS_EXPR, op1, op0); + else + common = 1; + break; + + case MINUS_EXPR: + /* Subtraction of two similar pointers. + We must subtract them as integers, then divide by object size. */ + if (code0 == POINTER_TYPE && code1 == POINTER_TYPE + && comp_target_types (type0, type1, 1)) + return pointer_diff (op0, op1); + /* Handle pointer minus int. Just like pointer plus int. */ + else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + return pointer_int_sum (MINUS_EXPR, op0, op1); + else + common = 1; + break; + + case MULT_EXPR: + common = 1; + break; + + case TRUNC_DIV_EXPR: + case CEIL_DIV_EXPR: + case FLOOR_DIV_EXPR: + case ROUND_DIV_EXPR: + case EXACT_DIV_EXPR: + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + { + if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1)) + cp_warning ("division by zero in `%E / 0'", op0); + else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1)) + cp_warning ("division by zero in `%E / 0.'", op0); + + if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)) + resultcode = RDIV_EXPR; + else + /* When dividing two signed integers, we have to promote to int. + unless we divide by a constant != -1. Note that default + conversion will have been performed on the operands at this + point, so we have to dig out the original type to find out if + it was unsigned. */ + shorten = ((TREE_CODE (op0) == NOP_EXPR + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0)))) + || (TREE_CODE (op1) == INTEGER_CST + && (TREE_INT_CST_LOW (op1) != -1 + || TREE_INT_CST_HIGH (op1) != -1))); + common = 1; + } + break; + + case BIT_AND_EXPR: + case BIT_ANDTC_EXPR: + case BIT_IOR_EXPR: + case BIT_XOR_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + shorten = -1; + /* If one operand is a constant, and the other is a short type + that has been converted to an int, + really do the work in the short type and then convert the + result to int. If we are lucky, the constant will be 0 or 1 + in the short type, making the entire operation go away. */ + if (TREE_CODE (op0) == INTEGER_CST + && TREE_CODE (op1) == NOP_EXPR + && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0))) + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0)))) + { + final_type = result_type; + op1 = TREE_OPERAND (op1, 0); + result_type = TREE_TYPE (op1); + } + if (TREE_CODE (op1) == INTEGER_CST + && TREE_CODE (op0) == NOP_EXPR + && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0))) + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0)))) + { + final_type = result_type; + op0 = TREE_OPERAND (op0, 0); + result_type = TREE_TYPE (op0); + } + break; + + case TRUNC_MOD_EXPR: + case FLOOR_MOD_EXPR: + if (code1 == INTEGER_TYPE && integer_zerop (op1)) + cp_warning ("division by zero in `%E % 0'", op0); + else if (code1 == REAL_TYPE && real_zerop (op1)) + cp_warning ("division by zero in `%E % 0.'", op0); + + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + /* Although it would be tempting to shorten always here, that loses + on some targets, since the modulo instruction is undefined if the + quotient can't be represented in the computation mode. We shorten + only if unsigned or if dividing by something we know != -1. */ + shorten = ((TREE_CODE (op0) == NOP_EXPR + && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0)))) + || (TREE_CODE (op1) == INTEGER_CST + && (TREE_INT_CST_LOW (op1) != -1 + || TREE_INT_CST_HIGH (op1) != -1))); + common = 1; + } + break; + + case TRUTH_ANDIF_EXPR: + case TRUTH_ORIF_EXPR: + case TRUTH_AND_EXPR: + case TRUTH_OR_EXPR: + result_type = boolean_type_node; + break; + + /* Shift operations: result has same type as first operand; + always convert second operand to int. + Also set SHORT_SHIFT if shifting rightward. */ + + case RSHIFT_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_lt (op1, integer_zero_node)) + warning ("right shift count is negative"); + else + { + if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1)) + short_shift = 1; + if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("right shift count >= width of type"); + } + } + /* Convert the shift-count to an integer, regardless of + size of value being shifted. */ + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + /* Avoid converting op1 to result_type later. */ + converted = 1; + } + break; + + case LSHIFT_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_lt (op1, integer_zero_node)) + warning ("left shift count is negative"); + else if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("left shift count >= width of type"); + } + /* Convert the shift-count to an integer, regardless of + size of value being shifted. */ + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + /* Avoid converting op1 to result_type later. */ + converted = 1; + } + break; + + case RROTATE_EXPR: + case LROTATE_EXPR: + if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (TREE_CODE (op1) == INTEGER_CST) + { + if (tree_int_cst_lt (op1, integer_zero_node)) + warning ("%s rotate count is negative", + (code == LROTATE_EXPR) ? "left" : "right"); + else if (TREE_INT_CST_HIGH (op1) != 0 + || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1) + >= TYPE_PRECISION (type0))) + warning ("%s rotate count >= width of type", + (code == LROTATE_EXPR) ? "left" : "right"); + } + /* Convert the shift-count to an integer, regardless of + size of value being shifted. */ + if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node) + op1 = convert (integer_type_node, op1); + } + break; + + case EQ_EXPR: + case NE_EXPR: + build_type = boolean_type_node; + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + short_compare = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0)); + register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1)); + + if (comp_target_types (type0, type1, 1)) + result_type = common_type (type0, type1); + else if (tt0 == void_type_node) + { + if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE + && tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1))) + pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer"); + else if (TREE_CODE (tt1) == OFFSET_TYPE) + pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'"); + } + else if (tt1 == void_type_node) + { + if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE + && tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0))) + pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer"); + } + else + cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast", + type0, type1); + + if (result_type == NULL_TREE) + result_type = ptr_type_node; + } + else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST + && integer_zerop (op1)) + result_type = type0; + else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST + && integer_zerop (op0)) + result_type = type1; + else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + error ("ANSI C++ forbids comparison between pointer and integer"); + } + else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + { + result_type = type1; + error ("ANSI C++ forbids comparison between pointer and integer"); + } + else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST + && integer_zerop (op1)) + { + op0 = build_component_ref (op0, index_identifier, 0, 0); + op1 = integer_zero_node; + result_type = TREE_TYPE (op0); + } + else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST + && integer_zerop (op0)) + { + op0 = build_component_ref (op1, index_identifier, 0, 0); + op1 = integer_zero_node; + result_type = TREE_TYPE (op0); + } + else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1) + && (TYPE_PTRMEMFUNC_FN_TYPE (type0) + == TYPE_PTRMEMFUNC_FN_TYPE (type1))) + { + /* The code we generate for the test is: + + (op0.index == op1.index + && ((op1.index != -1 && op0.delta2 == op1.delta2) + || op0.pfn == op1.pfn)) */ + + tree index0 = build_component_ref (op0, index_identifier, 0, 0); + tree index1 = save_expr (build_component_ref (op1, index_identifier, 0, 0)); + tree pfn0 = PFN_FROM_PTRMEMFUNC (op0); + tree pfn1 = PFN_FROM_PTRMEMFUNC (op1); + tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0); + tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1); + tree e1, e2, e3; + tree integer_neg_one_node + = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1); + e1 = build_binary_op (EQ_EXPR, index0, index1, 1); + e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1); + e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1); + e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1); + e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1); + e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1); + if (code == EQ_EXPR) + return e2; + return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1); + } + else if (TYPE_PTRMEMFUNC_P (type0) + && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1) + { + tree index0 = build_component_ref (op0, index_identifier, 0, 0); + tree index1; + tree pfn0 = PFN_FROM_PTRMEMFUNC (op0); + tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0); + tree delta21 = integer_zero_node; + tree e1, e2, e3; + tree integer_neg_one_node + = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1); + if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL + && DECL_VINDEX (TREE_OPERAND (op1, 0))) + { + /* Map everything down one to make room for the null pointer to member. */ + index1 = size_binop (PLUS_EXPR, + DECL_VINDEX (TREE_OPERAND (op1, 0)), + integer_one_node); + op1 = integer_zero_node; + delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1))); + delta21 = DECL_FIELD_BITPOS (delta21); + delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT)); + } + else + index1 = integer_neg_one_node; + { + tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1); + TREE_CONSTANT (nop1) = TREE_CONSTANT (op1); + op1 = nop1; + } + e1 = build_binary_op (EQ_EXPR, index0, index1, 1); + e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1); + e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1); + e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1); + e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1); + e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1); + if (code == EQ_EXPR) + return e2; + return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1); + } + else if (TYPE_PTRMEMFUNC_P (type1) + && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0) + { + return build_binary_op (code, op1, op0, 1); + } + break; + + case MAX_EXPR: + case MIN_EXPR: + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + shorten = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + if (comp_target_types (type0, type1, 1)) + result_type = common_type (type0, type1); + else + { + cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast", + type0, type1); + result_type = ptr_type_node; + } + } + break; + + case LE_EXPR: + case GE_EXPR: + case LT_EXPR: + case GT_EXPR: + build_type = boolean_type_node; + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + short_compare = 1; + else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE) + { + if (comp_target_types (type0, type1, 1)) + result_type = common_type (type0, type1); + else + { + cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast", + type0, type1); + result_type = ptr_type_node; + } + } + else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST + && integer_zerop (op1)) + result_type = type0; + else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST + && integer_zerop (op0)) + result_type = type1; + else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + result_type = type0; + if (pedantic) + pedwarn ("ANSI C++ forbids comparison between pointer and integer"); + else if (! flag_traditional) + warning ("comparison between pointer and integer"); + } + else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE) + { + result_type = type1; + if (pedantic) + pedwarn ("ANSI C++ forbids comparison between pointer and integer"); + else if (! flag_traditional) + warning ("comparison between pointer and integer"); + } + break; + } + + if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE) + && (code1 == INTEGER_TYPE || code1 == REAL_TYPE)) + { + if (shorten || common || short_compare) + result_type = common_type (type0, type1); + + /* For certain operations (which identify themselves by shorten != 0) + if both args were extended from the same smaller type, + do the arithmetic in that type and then extend. + + shorten !=0 and !=1 indicates a bitwise operation. + For them, this optimization is safe only if + both args are zero-extended or both are sign-extended. + Otherwise, we might change the result. + Eg, (short)-1 | (unsigned short)-1 is (int)-1 + but calculated in (unsigned short) it would be (unsigned short)-1. */ + + if (shorten) + { + int unsigned0, unsigned1; + tree arg0 = get_narrower (op0, &unsigned0); + tree arg1 = get_narrower (op1, &unsigned1); + /* UNS is 1 if the operation to be done is an unsigned one. */ + int uns = TREE_UNSIGNED (result_type); + tree type; + + final_type = result_type; + + /* Handle the case that OP0 does not *contain* a conversion + but it *requires* conversion to FINAL_TYPE. */ + + if (op0 == arg0 && TREE_TYPE (op0) != final_type) + unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0)); + if (op1 == arg1 && TREE_TYPE (op1) != final_type) + unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1)); + + /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE. */ + + /* For bitwise operations, signedness of nominal type + does not matter. Consider only how operands were extended. */ + if (shorten == -1) + uns = unsigned0; + + /* Note that in all three cases below we refrain from optimizing + an unsigned operation on sign-extended args. + That would not be valid. */ + + /* Both args variable: if both extended in same way + from same width, do it in that width. + Do it unsigned if args were zero-extended. */ + if ((TYPE_PRECISION (TREE_TYPE (arg0)) + < TYPE_PRECISION (result_type)) + && (TYPE_PRECISION (TREE_TYPE (arg1)) + == TYPE_PRECISION (TREE_TYPE (arg0))) + && unsigned0 == unsigned1 + && (unsigned0 || !uns)) + result_type + = signed_or_unsigned_type (unsigned0, + common_type (TREE_TYPE (arg0), TREE_TYPE (arg1))); + else if (TREE_CODE (arg0) == INTEGER_CST + && (unsigned1 || !uns) + && (TYPE_PRECISION (TREE_TYPE (arg1)) + < TYPE_PRECISION (result_type)) + && (type = signed_or_unsigned_type (unsigned1, + TREE_TYPE (arg1)), + int_fits_type_p (arg0, type))) + result_type = type; + else if (TREE_CODE (arg1) == INTEGER_CST + && (unsigned0 || !uns) + && (TYPE_PRECISION (TREE_TYPE (arg0)) + < TYPE_PRECISION (result_type)) + && (type = signed_or_unsigned_type (unsigned0, + TREE_TYPE (arg0)), + int_fits_type_p (arg1, type))) + result_type = type; + } + + /* Shifts can be shortened if shifting right. */ + + if (short_shift) + { + int unsigned_arg; + tree arg0 = get_narrower (op0, &unsigned_arg); + + final_type = result_type; + + if (arg0 == op0 && final_type == TREE_TYPE (op0)) + unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0)); + + if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type) + /* We can shorten only if the shift count is less than the + number of bits in the smaller type size. */ + && TREE_INT_CST_HIGH (op1) == 0 + && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1) + /* If arg is sign-extended and then unsigned-shifted, + we can simulate this with a signed shift in arg's type + only if the extended result is at least twice as wide + as the arg. Otherwise, the shift could use up all the + ones made by sign-extension and bring in zeros. + We can't optimize that case at all, but in most machines + it never happens because available widths are 2**N. */ + && (!TREE_UNSIGNED (final_type) + || unsigned_arg + || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0)) + <= TYPE_PRECISION (result_type)))) + { + /* Do an unsigned shift if the operand was zero-extended. */ + result_type + = signed_or_unsigned_type (unsigned_arg, + TREE_TYPE (arg0)); + /* Convert value-to-be-shifted to that type. */ + if (TREE_TYPE (op0) != result_type) + op0 = convert (result_type, op0); + converted = 1; + } + } + + /* Comparison operations are shortened too but differently. + They identify themselves by setting short_compare = 1. */ + + if (short_compare) + { + /* Don't write &op0, etc., because that would prevent op0 + from being kept in a register. + Instead, make copies of the our local variables and + pass the copies by reference, then copy them back afterward. */ + tree xop0 = op0, xop1 = op1, xresult_type = result_type; + enum tree_code xresultcode = resultcode; + tree val + = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode); + if (val != 0) + return convert (boolean_type_node, val); + op0 = xop0, op1 = xop1; + converted = 1; + resultcode = xresultcode; + } + + if (short_compare && extra_warnings) + { + int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0)); + int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1)); + + int unsignedp0, unsignedp1; + tree primop0 = get_narrower (op0, &unsignedp0); + tree primop1 = get_narrower (op1, &unsignedp1); + + /* Give warnings for comparisons between signed and unsigned + quantities that may fail. */ + /* Do the checking based on the original operand trees, so that + casts will be considered, but default promotions won't be. */ + + /* Do not warn if the comparison is being done in a signed type, + since the signed type will only be chosen if it can represent + all the values of the unsigned type. */ + if (! TREE_UNSIGNED (result_type)) + /* OK */; + /* Do not warn if both operands are unsigned. */ + else if (op0_signed == op1_signed) + /* OK */; + /* Do not warn if the signed quantity is an unsuffixed + integer literal (or some static constant expression + involving such literals) and it is non-negative. */ + else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST + && tree_int_cst_sgn (orig_op0) >= 0) + || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST + && tree_int_cst_sgn (orig_op1) >= 0)) + /* OK */; + /* Do not warn if the comparison is an equality operation, + the unsigned quantity is an integral constant and it does + not use the most significant bit of result_type. */ + else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR) + && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST + && int_fits_type_p (orig_op1, signed_type (result_type)) + || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST + && int_fits_type_p (orig_op0, signed_type (result_type)))))) + /* OK */; + else + warning ("comparison between signed and unsigned"); + + /* Warn if two unsigned values are being compared in a size + larger than their original size, and one (and only one) is the + result of a `~' operator. This comparison will always fail. + + Also warn if one operand is a constant, and the constant does not + have all bits set that are set in the ~ operand when it is + extended. */ + + if (TREE_CODE (primop0) == BIT_NOT_EXPR + ^ TREE_CODE (primop1) == BIT_NOT_EXPR) + { + if (TREE_CODE (primop0) == BIT_NOT_EXPR) + primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0); + if (TREE_CODE (primop1) == BIT_NOT_EXPR) + primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1); + + if (TREE_CODE (primop0) == INTEGER_CST + || TREE_CODE (primop1) == INTEGER_CST) + { + tree primop; + HOST_WIDE_INT constant, mask; + int unsignedp; + unsigned bits; + + if (TREE_CODE (primop0) == INTEGER_CST) + { + primop = primop1; + unsignedp = unsignedp1; + constant = TREE_INT_CST_LOW (primop0); + } + else + { + primop = primop0; + unsignedp = unsignedp0; + constant = TREE_INT_CST_LOW (primop1); + } + + bits = TYPE_PRECISION (TREE_TYPE (primop)); + if (bits < TYPE_PRECISION (result_type) + && bits < HOST_BITS_PER_LONG && unsignedp) + { + mask = (~ (HOST_WIDE_INT) 0) << bits; + if ((mask & constant) != mask) + warning ("comparison of promoted ~unsigned with constant"); + } + } + else if (unsignedp0 && unsignedp1 + && (TYPE_PRECISION (TREE_TYPE (primop0)) + < TYPE_PRECISION (result_type)) + && (TYPE_PRECISION (TREE_TYPE (primop1)) + < TYPE_PRECISION (result_type))) + warning ("comparison of promoted ~unsigned with unsigned"); + } + } + } + + /* At this point, RESULT_TYPE must be nonzero to avoid an error message. + If CONVERTED is zero, both args will be converted to type RESULT_TYPE. + Then the expression will be built. + It will be given type FINAL_TYPE if that is nonzero; + otherwise, it will be given type RESULT_TYPE. */ + + if (!result_type) + { + cp_error ("invalid operands `%T' and `%T' to binary `%O'", + TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code); + return error_mark_node; + } + + if (! converted) + { + if (TREE_TYPE (op0) != result_type) + op0 = convert (result_type, op0); + if (TREE_TYPE (op1) != result_type) + op1 = convert (result_type, op1); + } + + if (build_type == NULL_TREE) + build_type = result_type; + + { + register tree result = build (resultcode, build_type, op0, op1); + register tree folded; + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1); + if (final_type != 0) + return convert (final_type, folded); + return folded; + } +} + +/* Return a tree for the sum or difference (RESULTCODE says which) + of pointer PTROP and integer INTOP. */ + +static tree +pointer_int_sum (resultcode, ptrop, intop) + enum tree_code resultcode; + register tree ptrop, intop; +{ + tree size_exp; + + register tree result; + register tree folded = fold (intop); + + /* The result is a pointer of the same type that is being added. */ + + register tree result_type = TREE_TYPE (ptrop); + + if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic"); + size_exp = integer_one_node; + } + else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic"); + size_exp = integer_one_node; + } + else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE) + { + if (pedantic || warn_pointer_arith) + pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic"); + size_exp = integer_one_node; + } + else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE) + { + if (pedantic) + pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic"); + size_exp = integer_one_node; + } + else + size_exp = size_in_bytes (TREE_TYPE (result_type)); + + /* Needed to make OOPS V2R3 work. */ + intop = folded; + if (TREE_CODE (intop) == INTEGER_CST + && TREE_INT_CST_LOW (intop) == 0 + && TREE_INT_CST_HIGH (intop) == 0) + return ptrop; + + /* If what we are about to multiply by the size of the elements + contains a constant term, apply distributive law + and multiply that constant term separately. + This helps produce common subexpressions. */ + + if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR) + && ! TREE_CONSTANT (intop) + && TREE_CONSTANT (TREE_OPERAND (intop, 1)) + && TREE_CONSTANT (size_exp)) + { + enum tree_code subcode = resultcode; + if (TREE_CODE (intop) == MINUS_EXPR) + subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR); + ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1); + intop = TREE_OPERAND (intop, 0); + } + + /* Convert the integer argument to a type the same size as a pointer + so the multiply won't overflow spuriously. */ + + if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE) + intop = convert (type_for_size (POINTER_SIZE, 0), intop); + + /* Replace the integer argument with a suitable product by the object size. + Do this multiplication as signed, then convert to the appropriate + pointer type (actually unsigned integral). */ + + intop = convert (result_type, + build_binary_op (MULT_EXPR, intop, + convert (TREE_TYPE (intop), size_exp), 1)); + + /* Create the sum or difference. */ + + result = build (resultcode, result_type, ptrop, intop); + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop); + return folded; +} + +/* Return a tree for the difference of pointers OP0 and OP1. + The resulting tree has type int. */ + +static tree +pointer_diff (op0, op1) + register tree op0, op1; +{ + register tree result, folded; + tree restype = ptrdiff_type_node; + tree target_type = TREE_TYPE (TREE_TYPE (op0)); + + if (pedantic) + { + if (TREE_CODE (target_type) == VOID_TYPE) + pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction"); + if (TREE_CODE (target_type) == FUNCTION_TYPE) + pedwarn ("ANSI C++ forbids using pointer to a function in subtraction"); + if (TREE_CODE (target_type) == METHOD_TYPE) + pedwarn ("ANSI C++ forbids using pointer to a method in subtraction"); + if (TREE_CODE (target_type) == OFFSET_TYPE) + pedwarn ("ANSI C++ forbids using pointer to a member in subtraction"); + } + + /* First do the subtraction as integers; + then drop through to build the divide operator. */ + + op0 = build_binary_op (MINUS_EXPR, + convert (restype, op0), convert (restype, op1), 1); + + /* This generates an error if op1 is a pointer to an incomplete type. */ + if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0) + error ("arithmetic on pointer to an incomplete type"); + + op1 = ((TREE_CODE (target_type) == VOID_TYPE + || TREE_CODE (target_type) == FUNCTION_TYPE + || TREE_CODE (target_type) == METHOD_TYPE + || TREE_CODE (target_type) == OFFSET_TYPE) + ? integer_one_node + : size_in_bytes (target_type)); + + /* Do the division. */ + + result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1)); + + folded = fold (result); + if (folded == result) + TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1); + return folded; +} + +/* Handle the case of taking the address of a COMPONENT_REF. + Called by `build_unary_op' and `build_up_reference'. + + ARG is the COMPONENT_REF whose address we want. + ARGTYPE is the pointer type that this address should have. + MSG is an error message to print if this COMPONENT_REF is not + addressable (such as a bitfield). */ + +tree +build_component_addr (arg, argtype, msg) + tree arg, argtype; + char *msg; +{ + tree field = TREE_OPERAND (arg, 1); + tree basetype = decl_type_context (field); + tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0); + + if (DECL_BIT_FIELD (field)) + { + error (msg, IDENTIFIER_POINTER (DECL_NAME (field))); + return error_mark_node; + } + + if (flag_gc) + cp_warning ("address of `%T::%D' taken", basetype, field); + + if (TREE_CODE (field) == FIELD_DECL + && TYPE_USES_COMPLEX_INHERITANCE (basetype)) + { + /* Can't convert directly to ARGTYPE, since that + may have the same pointer type as one of our + baseclasses. */ + rval = build1 (NOP_EXPR, argtype, + convert_pointer_to (basetype, rval)); + TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0)); + } + else + /* This conversion is harmless. */ + rval = convert_force (argtype, rval, 0); + + if (! integer_zerop (DECL_FIELD_BITPOS (field))) + { + tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field), + size_int (BITS_PER_UNIT)); + int flag = TREE_CONSTANT (rval); + rval = fold (build (PLUS_EXPR, argtype, + rval, convert (argtype, offset))); + TREE_CONSTANT (rval) = flag; + } + return rval; +} + +/* Construct and perhaps optimize a tree representation + for a unary operation. CODE, a tree_code, specifies the operation + and XARG is the operand. */ + +tree +build_x_unary_op (code, xarg) + enum tree_code code; + tree xarg; +{ + /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an + error message. */ + if (code == ADDR_EXPR + && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg))) + && TYPE_SIZE (TREE_TYPE (xarg)) == NULL_TREE) + || (TREE_CODE (xarg) == OFFSET_REF))) + /* don't look for a function */; + else + { + tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY, xarg, + NULL_TREE, NULL_TREE); + if (rval) + return build_opfncall (code, LOOKUP_NORMAL, xarg, + NULL_TREE, NULL_TREE); + } + return build_unary_op (code, xarg, 0); +} + +/* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. */ + +tree +condition_conversion (expr) + tree expr; +{ + tree t = convert (boolean_type_node, expr); + t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t)); + return t; +} + +/* C++: Must handle pointers to members. + + Perhaps type instantiation should be extended to handle conversion + from aggregates to types we don't yet know we want? (Or are those + cases typically errors which should be reported?) + + NOCONVERT nonzero suppresses the default promotions + (such as from short to int). */ +tree +build_unary_op (code, xarg, noconvert) + enum tree_code code; + tree xarg; + int noconvert; +{ + /* No default_conversion here. It causes trouble for ADDR_EXPR. */ + register tree arg = xarg; + register tree argtype = 0; + char *errstring = NULL; + tree val; + + if (arg == error_mark_node) + return error_mark_node; + + switch (code) + { + case CONVERT_EXPR: + /* This is used for unary plus, because a CONVERT_EXPR + is enough to prevent anybody from looking inside for + associativity, but won't generate any code. */ + if (!(arg = build_expr_type_conversion + (WANT_ARITH | WANT_ENUM | WANT_POINTER, arg, 1))) + errstring = "wrong type argument to unary plus"; + else + { + if (!noconvert) + arg = default_conversion (arg); + arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg); + } + break; + + case NEGATE_EXPR: + if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1))) + errstring = "wrong type argument to unary minus"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case BIT_NOT_EXPR: + if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM, arg, 1))) + errstring = "wrong type argument to bit-complement"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case ABS_EXPR: + if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1))) + errstring = "wrong type argument to abs"; + else if (!noconvert) + arg = default_conversion (arg); + break; + + case TRUTH_NOT_EXPR: + arg = convert (boolean_type_node, arg); + val = invert_truthvalue (arg); + if (arg != error_mark_node) + return val; + errstring = "in argument to unary !"; + break; + + case NOP_EXPR: + break; + + case PREINCREMENT_EXPR: + case POSTINCREMENT_EXPR: + case PREDECREMENT_EXPR: + case POSTDECREMENT_EXPR: + /* Handle complex lvalues (when permitted) + by reduction to simpler cases. */ + + val = unary_complex_lvalue (code, arg); + if (val != 0) + return val; + + /* Report invalid types. */ + + if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER, + arg, 1))) + { + if (code == PREINCREMENT_EXPR) + errstring ="no pre-increment operator for type"; + else if (code == POSTINCREMENT_EXPR) + errstring ="no post-increment operator for type"; + else if (code == PREDECREMENT_EXPR) + errstring ="no pre-decrement operator for type"; + else + errstring ="no post-decrement operator for type"; + break; + } + + /* Report something read-only. */ + + if (TYPE_READONLY (TREE_TYPE (arg)) + || TREE_READONLY (arg)) + readonly_error (arg, ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"), + 0); + + { + register tree inc; + tree result_type = TREE_TYPE (arg); + + arg = get_unwidened (arg, 0); + argtype = TREE_TYPE (arg); + + /* ARM $5.2.5 last annotation says this should be forbidden. */ + if (TREE_CODE (argtype) == ENUMERAL_TYPE) + pedwarn ("ANSI C++ forbids %sing an enum", + (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"); + + /* Compute the increment. */ + + if (TREE_CODE (argtype) == POINTER_TYPE) + { + enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype)); + if (TYPE_SIZE (TREE_TYPE (argtype)) == 0) + cp_error ("cannot %s a pointer to incomplete type `%T'", + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"), TREE_TYPE (argtype)); + else if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE + || tmp == VOID_TYPE || tmp == OFFSET_TYPE) + cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'", + ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"), argtype); + inc = c_sizeof_nowarn (TREE_TYPE (argtype)); + } + else + inc = integer_one_node; + + inc = convert (argtype, inc); + + /* Handle incrementing a cast-expression. */ + + switch (TREE_CODE (arg)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + { + tree incremented, modify, value; + if (! lvalue_p (arg) && pedantic) + pedwarn ("cast to non-reference type used as lvalue"); + arg = stabilize_reference (arg); + if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR) + value = arg; + else + value = save_expr (arg); + incremented = build (((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? PLUS_EXPR : MINUS_EXPR), + argtype, value, inc); + TREE_SIDE_EFFECTS (incremented) = 1; + modify = build_modify_expr (arg, NOP_EXPR, incremented); + return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value); + } + } + + /* Complain about anything else that is not a true lvalue. */ + if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR + || code == POSTINCREMENT_EXPR) + ? "increment" : "decrement"))) + return error_mark_node; + + /* Forbid using -- on `bool'. */ + if (TREE_TYPE (arg) == boolean_type_node) + { + if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR) + { + cp_error ("invalid use of `--' on bool variable `%D'", arg); + return error_mark_node; + } +#if 0 + /* This will only work if someone can convince Kenner to accept + my patch to expand_increment. (jason) */ + val = build (code, TREE_TYPE (arg), arg, inc); +#else + if (code == POSTINCREMENT_EXPR) + { + arg = stabilize_reference (arg); + val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, + boolean_true_node); + TREE_SIDE_EFFECTS (val) = 1; + arg = save_expr (arg); + val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg); + val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val); + } + else + val = build (MODIFY_EXPR, TREE_TYPE (arg), arg, + boolean_true_node); +#endif + } + else + val = build (code, TREE_TYPE (arg), arg, inc); + + TREE_SIDE_EFFECTS (val) = 1; + return convert (result_type, val); + } + + case ADDR_EXPR: + /* Note that this operation never does default_conversion + regardless of NOCONVERT. */ + + argtype = TREE_TYPE (arg); + if (TREE_CODE (argtype) == REFERENCE_TYPE) + { + arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg); + TREE_REFERENCE_EXPR (arg) = 1; + return arg; + } + else if (pedantic + && TREE_CODE (arg) == FUNCTION_DECL + && DECL_NAME (arg) + && DECL_CONTEXT (arg) == NULL_TREE + && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4 + && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm' + && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main")) + /* ARM $3.4 */ + pedwarn ("taking address of function `main'"); + + /* Let &* cancel out to simplify resulting code. */ + if (TREE_CODE (arg) == INDIRECT_REF) + { + /* We don't need to have `current_class_decl' wrapped in a + NON_LVALUE_EXPR node. */ + if (arg == C_C_D) + return current_class_decl; + + /* Keep `default_conversion' from converting if + ARG is of REFERENCE_TYPE. */ + arg = TREE_OPERAND (arg, 0); + if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE) + { + if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg) + && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg))) + arg = DECL_INITIAL (arg); + arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg); + TREE_REFERENCE_EXPR (arg) = 1; + TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0)); + } + else if (lvalue_p (arg)) + /* Don't let this be an lvalue. */ + return non_lvalue (arg); + return arg; + } + + /* For &x[y], return x+y */ + if (TREE_CODE (arg) == ARRAY_REF) + { + if (mark_addressable (TREE_OPERAND (arg, 0)) == 0) + return error_mark_node; + return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0), + TREE_OPERAND (arg, 1), 1); + } + + /* Uninstantiated types are all functions. Taking the + address of a function is a no-op, so just return the + argument. */ + + if (TREE_CODE (arg) == IDENTIFIER_NODE + && IDENTIFIER_OPNAME_P (arg)) + { + my_friendly_abort (117); + /* We don't know the type yet, so just work around the problem. + We know that this will resolve to an lvalue. */ + return build1 (ADDR_EXPR, unknown_type_node, arg); + } + + if (TREE_CODE (arg) == TREE_LIST) + { + if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL + && DECL_CHAIN (TREE_VALUE (arg)) == NULL_TREE) + /* Unique overloaded non-member function. */ + return build_unary_op (ADDR_EXPR, TREE_VALUE (arg), 0); + if (TREE_CHAIN (arg) == NULL_TREE + && TREE_CODE (TREE_VALUE (arg)) == TREE_LIST + && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE) + /* Unique overloaded member function. */ + return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)), + 0); + return build1 (ADDR_EXPR, unknown_type_node, arg); + } + + /* Handle complex lvalues (when permitted) + by reduction to simpler cases. */ + val = unary_complex_lvalue (code, arg); + if (val != 0) + return val; + + switch (TREE_CODE (arg)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + if (! lvalue_p (arg) && pedantic) + pedwarn ("taking the address of a cast to non-reference type"); + } + + /* Allow the address of a constructor if all the elements + are constant. */ + if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg)) + ; + /* Anything not already handled and not a true memory reference + is an error. */ + else if (TREE_CODE (argtype) != FUNCTION_TYPE + && TREE_CODE (argtype) != METHOD_TYPE + && !lvalue_or_else (arg, "unary `&'")) + return error_mark_node; + + /* Ordinary case; arg is a COMPONENT_REF or a decl. */ + /* If the lvalue is const or volatile, + merge that into the type that the address will point to. */ + if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd' + || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r') + { + if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg)) + argtype = cp_build_type_variant (argtype, + TREE_READONLY (arg), + TREE_THIS_VOLATILE (arg)); + } + + argtype = build_pointer_type (argtype); + + if (mark_addressable (arg) == 0) + return error_mark_node; + + { + tree addr; + + if (TREE_CODE (arg) == COMPONENT_REF) + addr = build_component_addr (arg, argtype, + "attempt to take address of bit-field structure member `%s'"); + else + addr = build1 (code, argtype, arg); + + /* Address of a static or external variable or + function counts as a constant */ + if (staticp (arg)) + TREE_CONSTANT (addr) = 1; + return addr; + } + } + + if (!errstring) + { + if (argtype == 0) + argtype = TREE_TYPE (arg); + return fold (build1 (code, argtype, arg)); + } + + error (errstring); + return error_mark_node; +} + +/* If CONVERSIONS is a conversion expression or a nested sequence of such, + convert ARG with the same conversions in the same order + and return the result. */ + +static tree +convert_sequence (conversions, arg) + tree conversions; + tree arg; +{ + switch (TREE_CODE (conversions)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + return convert (TREE_TYPE (conversions), + convert_sequence (TREE_OPERAND (conversions, 0), + arg)); + + default: + return arg; + } +} + +/* Apply unary lvalue-demanding operator CODE to the expression ARG + for certain kinds of expressions which are not really lvalues + but which we can accept as lvalues. + + If ARG is not a kind of expression we can handle, return zero. */ + +tree +unary_complex_lvalue (code, arg) + enum tree_code code; + tree arg; +{ + /* Handle (a, b) used as an "lvalue". */ + if (TREE_CODE (arg) == COMPOUND_EXPR) + { + tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0); + return build (COMPOUND_EXPR, TREE_TYPE (real_result), + TREE_OPERAND (arg, 0), real_result); + } + + /* Handle (a ? b : c) used as an "lvalue". */ + if (TREE_CODE (arg) == COND_EXPR) + return rationalize_conditional_expr (code, arg); + + if (TREE_CODE (arg) == MODIFY_EXPR + || TREE_CODE (arg) == PREINCREMENT_EXPR + || TREE_CODE (arg) == PREDECREMENT_EXPR) + return unary_complex_lvalue + (code, build (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (arg, 0)), + arg, TREE_OPERAND (arg, 0))); + + if (code != ADDR_EXPR) + return 0; + + /* Handle (a = b) used as an "lvalue" for `&'. */ + if (TREE_CODE (arg) == MODIFY_EXPR + || TREE_CODE (arg) == INIT_EXPR) + { + tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0); + return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result); + } + + if (TREE_CODE (arg) == WITH_CLEANUP_EXPR) + { + tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0); + real_result = build (WITH_CLEANUP_EXPR, TREE_TYPE (real_result), + real_result, 0, TREE_OPERAND (arg, 2)); + return real_result; + } + + if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE + || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE) + { + /* The representation of something of type OFFSET_TYPE + is really the representation of a pointer to it. + Here give the representation its true type. */ + tree t; + tree offset; + + my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313); + + if (TREE_CODE (arg) != OFFSET_REF) + return 0; + + t = TREE_OPERAND (arg, 1); + + if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */ + return build_unary_op (ADDR_EXPR, t, 0); + if (TREE_CODE (t) == VAR_DECL) + return build_unary_op (ADDR_EXPR, t, 0); + else + { + if (TREE_OPERAND (arg, 0) + && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR + || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node)) + if (TREE_CODE (t) != FIELD_DECL) + { + /* Don't know if this should return address to just + _DECL, or actual address resolved in this expression. */ + sorry ("address of bound pointer-to-member expression"); + return error_mark_node; + } + + offset = get_delta_difference (DECL_FIELD_CONTEXT (t), + TREE_TYPE (TREE_OPERAND (arg, 0)), + 0); + offset = size_binop (PLUS_EXPR, offset, + size_binop (EASY_DIV_EXPR, + DECL_FIELD_BITPOS (t), + size_int (BITS_PER_UNIT))); + return convert (build_pointer_type (TREE_TYPE (arg)), offset); + } + } + + if (TREE_CODE (arg) == OFFSET_REF) + { + tree left = TREE_OPERAND (arg, 0), left_addr; + tree right_addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 1), 0); + + if (left == 0) + if (current_class_decl) + left_addr = current_class_decl; + else + { + error ("no `this' for pointer to member"); + return error_mark_node; + } + else + left_addr = build_unary_op (ADDR_EXPR, left, 0); + + return build (PLUS_EXPR, build_pointer_type (TREE_TYPE (arg)), + build1 (NOP_EXPR, integer_type_node, left_addr), + build1 (NOP_EXPR, integer_type_node, right_addr)); + } + + /* We permit compiler to make function calls returning + objects of aggregate type look like lvalues. */ + { + tree targ = arg; + + if (TREE_CODE (targ) == SAVE_EXPR) + targ = TREE_OPERAND (targ, 0); + + if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ))) + { + if (TREE_CODE (arg) == SAVE_EXPR) + targ = arg; + else + targ = build_cplus_new (TREE_TYPE (arg), arg, 1); + return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ); + } + + if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF) + return build (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)), + TREE_OPERAND (targ, 0), current_function_decl, NULL); + + /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case + we do, here's how to handle it. */ + if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == WITH_CLEANUP_EXPR) + { +#if 0 + /* Not really a bug, but something to turn on when testing. */ + compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR"); +#endif + return unary_complex_lvalue (ADDR_EXPR, targ); + } + } + + /* Don't let anything else be handled specially. */ + return 0; +} + +/* Mark EXP saying that we need to be able to take the + address of it; it should not be allocated in a register. + Value is 1 if successful. + + C++: we do not allow `current_class_decl' to be addressable. */ + +int +mark_addressable (exp) + tree exp; +{ + register tree x = exp; + + if (TREE_ADDRESSABLE (x) == 1) + return 1; + + while (1) + switch (TREE_CODE (x)) + { + case ADDR_EXPR: + case COMPONENT_REF: + case ARRAY_REF: + x = TREE_OPERAND (x, 0); + break; + + case PARM_DECL: + if (x == current_class_decl) + { + error ("address of `this' not available"); + TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */ + put_var_into_stack (x); + return 1; + } + case VAR_DECL: + if (TREE_STATIC (x) + && TREE_READONLY (x) + && DECL_RTL (x) != 0 + && ! decl_in_memory_p (x)) + { + /* We thought this would make a good constant variable, + but we were wrong. */ + push_obstacks_nochange (); + end_temporary_allocation (); + + TREE_ASM_WRITTEN (x) = 0; + DECL_RTL (x) = 0; + rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0); + TREE_ADDRESSABLE (x) = 1; + + pop_obstacks (); + + return 1; + } + /* Caller should not be trying to mark initialized + constant fields addressable. */ + my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0 + || DECL_IN_AGGR_P (x) == 0 + || TREE_STATIC (x) + || DECL_EXTERNAL (x), 314); + + case CONST_DECL: + case RESULT_DECL: + /* For C++, we don't warn about taking the address of a register + variable for CONST_DECLs; ARM p97 explicitly says it's okay. */ + put_var_into_stack (x); + TREE_ADDRESSABLE (x) = 1; + return 1; + + case FUNCTION_DECL: + /* We have to test both conditions here. The first may + be non-zero in the case of processing a default function. + The second may be non-zero in the case of a template function. */ + x = DECL_MAIN_VARIANT (x); + if ((DECL_THIS_INLINE (x) || DECL_PENDING_INLINE_INFO (x)) + && (DECL_CONTEXT (x) == NULL_TREE + || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't' + || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x)))) + { + mark_inline_for_output (x); + if (x == current_function_decl) + DECL_EXTERNAL (x) = 0; + } + TREE_ADDRESSABLE (x) = 1; + TREE_USED (x) = 1; + TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1; + if (asm_out_file) + assemble_external (x); + return 1; + + default: + return 1; + } +} + +/* Build and return a conditional expression IFEXP ? OP1 : OP2. */ + +tree +build_x_conditional_expr (ifexp, op1, op2) + tree ifexp, op1, op2; +{ + tree rval = NULL_TREE; + + /* See comments in `build_x_binary_op'. */ + if (op1 != 0) + rval = build_opfncall (COND_EXPR, LOOKUP_SPECULATIVELY, ifexp, op1, op2); + if (rval) + return build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2); + + return build_conditional_expr (ifexp, op1, op2); +} + +tree +build_conditional_expr (ifexp, op1, op2) + tree ifexp, op1, op2; +{ + register tree type1; + register tree type2; + register enum tree_code code1; + register enum tree_code code2; + register tree result_type = NULL_TREE; + tree orig_op1 = op1, orig_op2 = op2; + + /* If second operand is omitted, it is the same as the first one; + make sure it is calculated only once. */ + if (op1 == 0) + { + if (pedantic) + pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression"); + ifexp = op1 = save_expr (ifexp); + } + + ifexp = convert (boolean_type_node, ifexp); + + if (TREE_CODE (ifexp) == ERROR_MARK) + return error_mark_node; + + op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node); + if (op1 == error_mark_node) + return error_mark_node; + op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node); + if (op2 == error_mark_node) + return error_mark_node; + + /* C++: REFERENCE_TYPES must be dereferenced. */ + type1 = TREE_TYPE (op1); + code1 = TREE_CODE (type1); + type2 = TREE_TYPE (op2); + code2 = TREE_CODE (type2); + + if (code1 == REFERENCE_TYPE) + { + op1 = convert_from_reference (op1); + type1 = TREE_TYPE (op1); + code1 = TREE_CODE (type1); + } + if (code2 == REFERENCE_TYPE) + { + op2 = convert_from_reference (op2); + type2 = TREE_TYPE (op2); + code2 = TREE_CODE (type2); + } + +#if 1 /* Produces wrong result if within sizeof. Sorry. */ + /* Don't promote the operands separately if they promote + the same way. Return the unpromoted type and let the combined + value get promoted if necessary. */ + + if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2) + && code2 != ARRAY_TYPE +#if 0 + /* For C++, let the enumeral type come through. */ + && code2 != ENUMERAL_TYPE +#endif + && code2 != FUNCTION_TYPE + && code2 != METHOD_TYPE) + { + tree result; + + if (TREE_CONSTANT (ifexp) + && (TREE_CODE (ifexp) == INTEGER_CST + || TREE_CODE (ifexp) == ADDR_EXPR)) + return (integer_zerop (ifexp) ? op2 : op1); + + if (TREE_CODE (op1) == CONST_DECL) + op1 = DECL_INITIAL (op1); + else if (TREE_READONLY_DECL_P (op1)) + op1 = decl_constant_value (op1); + if (TREE_CODE (op2) == CONST_DECL) + op2 = DECL_INITIAL (op2); + else if (TREE_READONLY_DECL_P (op2)) + op2 = decl_constant_value (op2); + if (type1 != type2) + type1 = cp_build_type_variant + (type1, + TREE_READONLY (op1) || TREE_READONLY (op2), + TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2)); + /* ??? This is a kludge to deal with the fact that + we don't sort out integers and enums properly, yet. */ + result = fold (build (COND_EXPR, type1, ifexp, op1, op2)); + if (TREE_TYPE (result) != type1) + result = build1 (NOP_EXPR, type1, result); + return result; + } +#endif + + /* They don't match; promote them both and then try to reconcile them. + But don't permit mismatching enum types. */ + if (code1 == ENUMERAL_TYPE) + { + if (code2 == ENUMERAL_TYPE) + { + cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1, type2); + return error_mark_node; + } + else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2) + && type2 != type_promotes_to (type1)) + warning ("enumeral and non-enumeral type in conditional expression"); + } + else if (extra_warnings + && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1) + && type1 != type_promotes_to (type2)) + warning ("enumeral and non-enumeral type in conditional expression"); + + if (code1 != VOID_TYPE) + { + op1 = default_conversion (op1); + type1 = TREE_TYPE (op1); + if (TYPE_PTRMEMFUNC_P (type1)) + type1 = TYPE_PTRMEMFUNC_FN_TYPE (type1); + code1 = TREE_CODE (type1); + } + if (code2 != VOID_TYPE) + { + op2 = default_conversion (op2); + type2 = TREE_TYPE (op2); + if (TYPE_PTRMEMFUNC_P (type2)) + type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2); + code2 = TREE_CODE (type2); + } + + if (code1 == RECORD_TYPE && code2 == RECORD_TYPE + && real_lvalue_p (op1) && real_lvalue_p (op2) + && comptypes (type1, type2, -1)) + { + type1 = build_reference_type (type1); + type2 = build_reference_type (type2); + result_type = common_type (type1, type2); + op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT, + LOOKUP_NORMAL, NULL_TREE); + op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT, + LOOKUP_NORMAL, NULL_TREE); + } + /* Quickly detect the usual case where op1 and op2 have the same type + after promotion. */ + else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)) + { + if (type1 == type2) + result_type = type1; + else + result_type = cp_build_type_variant + (type1, + TREE_READONLY (op1) || TREE_READONLY (op2), + TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2)); + } + else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE) + && (code2 == INTEGER_TYPE || code2 == REAL_TYPE)) + { + result_type = common_type (type1, type2); + } + else if (code1 == VOID_TYPE || code2 == VOID_TYPE) + { + if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE)) + pedwarn ("ANSI C++ forbids conditional expr with only one void side"); + result_type = void_type_node; + } + else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE) + { + if (comp_target_types (type1, type2, 1)) + result_type = common_type (type1, type2); + else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node + && TREE_CODE (orig_op1) != NOP_EXPR) + result_type = qualify_type (type2, type1); + else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node + && TREE_CODE (orig_op2) != NOP_EXPR) + result_type = qualify_type (type1, type2); + else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node) + { + if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE) + pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer"); + result_type = qualify_type (type1, type2); + } + else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node) + { + if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE) + pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer"); + result_type = qualify_type (type2, type1); + } + /* C++ */ + else if (comptypes (type2, type1, 0)) + result_type = type2; + else if (IS_AGGR_TYPE (TREE_TYPE (type1)) + && IS_AGGR_TYPE (TREE_TYPE (type2)) + && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2)))) + { + if (result_type == error_mark_node) + { + cp_error ("common base type of types `%T' and `%T' is ambiguous", + TREE_TYPE (type1), TREE_TYPE (type2)); + result_type = ptr_type_node; + } + else + { + if (pedantic + && result_type != TREE_TYPE (type1) + && result_type != TREE_TYPE (type2)) + cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression", + type1, type2, result_type); + + result_type = build_pointer_type (result_type); + } + } + else + { + pedwarn ("pointer type mismatch in conditional expression"); + result_type = ptr_type_node; + } + } + else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE) + { + if (!integer_zerop (op2)) + pedwarn ("pointer/integer type mismatch in conditional expression"); + else + { + op2 = null_pointer_node; +#if 0 /* Sez who? */ + if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE) + pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer"); +#endif + } + result_type = type1; + } + else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE) + { + if (!integer_zerop (op1)) + pedwarn ("pointer/integer type mismatch in conditional expression"); + else + { + op1 = null_pointer_node; +#if 0 /* Sez who? */ + if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE) + pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer"); +#endif + } + result_type = type2; + } + + if (!result_type) + { + /* The match does not look good. If either is + an aggregate value, try converting to a scalar type. */ + if (code1 == RECORD_TYPE && code2 == RECORD_TYPE) + { + cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1, type2); + return error_mark_node; + } + if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1)) + { + tree tmp = build_type_conversion (CONVERT_EXPR, type2, op1, 0); + if (tmp == NULL_TREE) + { + cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1); + return error_mark_node; + } + if (tmp == error_mark_node) + error ("ambiguous pointer conversion"); + result_type = type2; + op1 = tmp; + } + else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2)) + { + tree tmp = build_type_conversion (CONVERT_EXPR, type1, op2, 0); + if (tmp == NULL_TREE) + { + cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2); + return error_mark_node; + } + if (tmp == error_mark_node) + error ("ambiguous pointer conversion"); + result_type = type1; + op2 = tmp; + } + else if (flag_cond_mismatch) + result_type = void_type_node; + else + { + error ("type mismatch in conditional expression"); + return error_mark_node; + } + } + + if (TREE_CODE (result_type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE) + result_type = build_ptrmemfunc_type (result_type); + + if (result_type != TREE_TYPE (op1)) + op1 = convert_and_check (result_type, op1); + if (result_type != TREE_TYPE (op2)) + op2 = convert_and_check (result_type, op2); + +#if 0 + /* XXX delete me, I've been here for years. */ + if (IS_AGGR_TYPE_CODE (code1)) + { + result_type = TREE_TYPE (op1); + if (TREE_CONSTANT (ifexp)) + return (integer_zerop (ifexp) ? op2 : op1); + + if (TYPE_MODE (result_type) == BLKmode) + { + register tree tempvar + = build_decl (VAR_DECL, NULL_TREE, result_type); + register tree xop1 = build_modify_expr (tempvar, NOP_EXPR, op1); + register tree xop2 = build_modify_expr (tempvar, NOP_EXPR, op2); + register tree result = fold (build (COND_EXPR, result_type, + ifexp, xop1, xop2)); + + layout_decl (tempvar, 0); + /* No way to handle variable-sized objects here. + I fear that the entire handling of BLKmode conditional exprs + needs to be redone. */ + my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar)), 315); + DECL_RTL (tempvar) + = assign_stack_local (DECL_MODE (tempvar), + (TREE_INT_CST_LOW (DECL_SIZE (tempvar)) + + BITS_PER_UNIT - 1) + / BITS_PER_UNIT, + 0); + + TREE_SIDE_EFFECTS (result) + = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1) + | TREE_SIDE_EFFECTS (op2); + return build (COMPOUND_EXPR, result_type, result, tempvar); + } + } +#endif /* 0 */ + + if (TREE_CONSTANT (ifexp)) + return integer_zerop (ifexp) ? op2 : op1; + + return convert_from_reference + (fold (build (COND_EXPR, result_type, ifexp, op1, op2))); +} + +/* Handle overloading of the ',' operator when needed. Otherwise, + this function just builds an expression list. */ +tree +build_x_compound_expr (list) + tree list; +{ + tree rest = TREE_CHAIN (list); + tree result; + + if (rest == NULL_TREE) + return build_compound_expr (list); + + result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL, + TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE); + if (result) + return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest))); + + if (! TREE_SIDE_EFFECTS (TREE_VALUE (list))) + { + /* the left-hand operand of a comma expression is like an expression + statement: we should warn if it doesn't have any side-effects, + unless it was explicitly cast to (void). */ + if ((extra_warnings || warn_unused) + && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR + && TREE_TYPE (TREE_VALUE(list)) == void_type_node)) + warning("left-hand operand of comma expression has no effect"); + } +#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */ + else if (warn_unused) + warn_if_unused_value (TREE_VALUE(list)); +#endif + + return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list), + build_tree_list (NULL_TREE, build_x_compound_expr (rest)))); +} + +/* Given a list of expressions, return a compound expression + that performs them all and returns the value of the last of them. */ + +tree +build_compound_expr (list) + tree list; +{ + register tree rest; + + if (TREE_READONLY_DECL_P (TREE_VALUE (list))) + TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list)); + + if (TREE_CHAIN (list) == 0) + { + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Strip such NOP_EXPRs, since LIST is used in non-lvalue context. */ + if (TREE_CODE (list) == NOP_EXPR + && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0))) + list = TREE_OPERAND (list, 0); + + /* Convert arrays to pointers. */ + if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE) + return default_conversion (TREE_VALUE (list)); + else + return TREE_VALUE (list); + } + + rest = build_compound_expr (TREE_CHAIN (list)); + + /* When pedantic, a compound expression cannot be a constant expression. */ + if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic) + return rest; + + return build (COMPOUND_EXPR, TREE_TYPE (rest), + break_out_cleanups (TREE_VALUE (list)), rest); +} + +#ifdef __GNUC__ +__inline +#endif +int +null_ptr_cst_p (t) + tree t; +{ + return (TREE_CODE (t) == INTEGER_CST && integer_zerop (t)); +} + +tree build_static_cast (type, expr) + tree type, expr; +{ + return build_c_cast (type, expr, 0); +} + +tree build_reinterpret_cast (type, expr) + tree type, expr; +{ + tree intype = TREE_TYPE (expr); + + if (TYPE_PTRMEMFUNC_P (type)) + type = TYPE_PTRMEMFUNC_FN_TYPE (type); + if (TYPE_PTRMEMFUNC_P (intype)) + intype = TYPE_PTRMEMFUNC_FN_TYPE (intype); + + if (! POINTER_TYPE_P (type) && ! TREE_CODE (type) == INTEGER_TYPE) + { + cp_error ("reinterpret_cast cannot convert to type `%T'", type); + return error_mark_node; + } + if (! POINTER_TYPE_P (intype) && ! TREE_CODE (intype) == INTEGER_TYPE) + { + cp_error ("reinterpret_cast cannot convert from type `%T'", type); + return error_mark_node; + } + if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (intype) != POINTER_TYPE) + { + cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'", + intype, type); + return error_mark_node; + } + if (TREE_CODE (intype) == INTEGER_TYPE && TREE_CODE (type) != POINTER_TYPE) + { + cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'", + intype, type); + return error_mark_node; + } + + if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) == POINTER_TYPE) + expr = convert (ptr_type_node, expr); + + return build_c_cast (type, expr, 0); +} + +tree build_const_cast (type, expr) + tree type, expr; +{ + tree intype = TREE_TYPE (expr); + tree t1, t2; + + if (type == error_mark_node || expr == error_mark_node) + return error_mark_node; + + if (TYPE_PTRMEMFUNC_P (type)) + type = TYPE_PTRMEMFUNC_FN_TYPE (type); + if (TYPE_PTRMEMFUNC_P (intype)) + intype = TYPE_PTRMEMFUNC_FN_TYPE (intype); + + if (! POINTER_TYPE_P (type)) + { + cp_error ("const_cast cannot convert to non-pointer type `%T'", type); + return error_mark_node; + } + if (TREE_CODE (type) == REFERENCE_TYPE && ! real_lvalue_p (expr)) + { + cp_error ("const_cast cannot convert rvalue to type `%T'", type); + return error_mark_node; + } + if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) != POINTER_TYPE) + { + cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'", + intype, type); + return error_mark_node; + } + + if (TREE_CODE (type) == REFERENCE_TYPE) + { + t1 = TREE_TYPE (type); + t2 = intype; + } + else + { + t1 = TREE_TYPE (type); + t2 = TREE_TYPE (intype); + + for (; TREE_CODE (t1) == POINTER_TYPE && TREE_CODE (t2) == POINTER_TYPE; + t1 = TREE_TYPE (t1), t2 = TREE_TYPE (t2)) + ; + } + + if (TREE_CODE (t1) == OFFSET_TYPE && TREE_CODE (t2) == OFFSET_TYPE) + { + if (TYPE_OFFSET_BASETYPE (t1) != TYPE_OFFSET_BASETYPE (t2)) + { + cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'", + TYPE_OFFSET_BASETYPE (t2), TYPE_OFFSET_BASETYPE (t1)); + return error_mark_node; + } + t1 = TREE_TYPE (t1); + t2 = TREE_TYPE (t2); + } + + if (TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2)) + { + cp_error ("const_cast cannot convert unrelated type `%T' to `%T'", + t2, t1); + return error_mark_node; + } + + return build_c_cast (type, expr, 0); +} + +/* Build an expression representing a cast to type TYPE of expression EXPR. + + ALLOW_NONCONVERTING is true if we should allow non-converting constructors + when doing the cast. */ + +tree +build_c_cast (type, expr, allow_nonconverting) + register tree type; + tree expr; + int allow_nonconverting; +{ + register tree value = expr; + + if (type == error_mark_node || expr == error_mark_node) + return error_mark_node; + + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Strip such NOP_EXPRs if VALUE is being used in non-lvalue context. */ + if (TREE_CODE (type) != REFERENCE_TYPE + && TREE_CODE (value) == NOP_EXPR + && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0))) + value = TREE_OPERAND (value, 0); + + if (TREE_TYPE (expr) + && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE + && TREE_CODE (type) != OFFSET_TYPE) + value = resolve_offset_ref (value); + + if (TREE_CODE (type) == ARRAY_TYPE) + { + /* Allow casting from T1* to T2[] because Cfront allows it. + NIHCL uses it. It is not valid ANSI C however, and hence, not + valid ANSI C++. */ + if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE) + { + if (pedantic) + pedwarn ("ANSI C++ forbids casting to an array type"); + type = build_pointer_type (TREE_TYPE (type)); + } + else + { + error ("ANSI C++ forbids casting to an array type"); + return error_mark_node; + } + } + + if (TREE_CODE (type) == FUNCTION_TYPE + || TREE_CODE (type) == METHOD_TYPE) + { + cp_error ("casting to function type `%T'", type); + return error_mark_node; + } + + if (IS_SIGNATURE (type)) + { + error ("cast specifies signature type"); + return error_mark_node; + } + + /* If there's only one function in the overloaded space, + just take it. */ + if (TREE_CODE (value) == TREE_LIST + && TREE_CHAIN (value) == NULL_TREE) + value = TREE_VALUE (value); + + if (TREE_CODE (type) == VOID_TYPE) + value = build1 (CONVERT_EXPR, type, value); + else if (TREE_TYPE (value) == NULL_TREE + || type_unknown_p (value)) + { + value = instantiate_type (type, value, 1); + /* Did we lose? */ + if (value == error_mark_node) + return error_mark_node; + } + else + { + tree otype; + int flag; + + /* Convert functions and arrays to pointers and + convert references to their expanded types, + but don't convert any other types. */ + if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE + || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE) + value = default_conversion (value); + otype = TREE_TYPE (value); + + /* Optionally warn about potentially worrisome casts. */ + + if (warn_cast_qual + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == POINTER_TYPE) + { + /* For C++ we make these regular warnings, rather than + softening them into pedwarns. */ + if (TYPE_VOLATILE (TREE_TYPE (otype)) + && ! TYPE_VOLATILE (TREE_TYPE (type))) + warning ("cast discards `volatile' from pointer target type"); + if (TYPE_READONLY (TREE_TYPE (otype)) + && ! TYPE_READONLY (TREE_TYPE (type))) + warning ("cast discards `const' from pointer target type"); + } + + /* Warn about possible alignment problems. */ + if (STRICT_ALIGNMENT && warn_cast_align + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE + && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE + && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) + warning ("cast increases required alignment of target type"); + +#if 0 + if (TREE_CODE (type) == INTEGER_TYPE + && TREE_CODE (otype) == POINTER_TYPE + && TYPE_PRECISION (type) != TYPE_PRECISION (otype)) + warning ("cast from pointer to integer of different size"); + + if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (otype) == INTEGER_TYPE + && TYPE_PRECISION (type) != TYPE_PRECISION (otype) + /* Don't warn about converting 0 to pointer, + provided the 0 was explicit--not cast or made by folding. */ + && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))) + warning ("cast to pointer from integer of different size"); +#endif + + flag = allow_nonconverting ? CONV_NONCONVERTING : 0; + + if (TREE_CODE (type) == REFERENCE_TYPE) + value = (convert_from_reference + (convert_to_reference (type, value, CONV_OLD_CONVERT|flag, + LOOKUP_COMPLAIN, NULL_TREE))); + else + { + tree ovalue; + + if (TREE_READONLY_DECL_P (value)) + value = decl_constant_value (value); + + ovalue = value; + value = convert_force (type, value, flag); + + /* Ignore any integer overflow caused by the cast. */ + if (TREE_CODE (value) == INTEGER_CST) + { + TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue); + TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue); + } + } + } + + /* Always produce some operator for an explicit cast, + so we can tell (for -pedantic) that the cast is no lvalue. + Also, pedantically, don't let (void *) (FOO *) 0 be a null + pointer constant. */ + if (TREE_CODE (type) != REFERENCE_TYPE + && (value == expr + || (pedantic + && TREE_CODE (value) == INTEGER_CST + && TREE_CODE (expr) == INTEGER_CST + && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE))) + value = non_lvalue (value); + + return value; +} + +#if 0 +/* Build an assignment expression of lvalue LHS from value RHS. + + In C++, if the left hand side of the assignment is a REFERENCE_TYPE, + that reference becomes deferenced down to it base type. */ + +/* Return a reference to the BASE_INDEX part of EXPR. TYPE is + the type to which BASE_INDEX applies. */ +static tree +get_base_ref (type, base_index, expr) + tree type; + int base_index; + tree expr; +{ + tree binfos = TYPE_BINFO_BASETYPES (type); + tree base_binfo = TREE_VEC_ELT (binfos, base_index); + tree ref; + + if (TREE_CODE (expr) == ARRAY_REF + || ! BINFO_OFFSET_ZEROP (base_binfo) + || TREE_VIA_VIRTUAL (base_binfo) + || TYPE_MODE (type) != TYPE_MODE (BINFO_TYPE (base_binfo))) + { + tree addr = build_unary_op (ADDR_EXPR, expr, 0); + ref = build_indirect_ref (convert_pointer_to (base_binfo, addr), + NULL_PTR); + } + else + { + ref = copy_node (expr); + TREE_TYPE (ref) = BINFO_TYPE (base_binfo); + } + return ref; +} + +/* Build an assignment expression of lvalue LHS from value RHS. + MODIFYCODE is the code for a binary operator that we use + to combine the old value of LHS with RHS to get the new value. + Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. + + C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. + + `build_modify_expr_1' implements recursive part of memberwise + assignment operation. */ +static tree +build_modify_expr_1 (lhs, modifycode, rhs, basetype_path) + tree lhs, rhs; + enum tree_code modifycode; + tree basetype_path; +{ + register tree result; + tree newrhs = rhs; + tree lhstype = TREE_TYPE (lhs); + tree olhstype = lhstype; + + /* Avoid duplicate error messages from operands that had errors. */ + if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) + return error_mark_node; + + /* If a binary op has been requested, combine the old LHS value with the RHS + producing the value we should actually store into the LHS. */ + + if (modifycode == INIT_EXPR) + ; + else if (modifycode == NOP_EXPR) + { + /* must deal with overloading of `operator=' here. */ + if (TREE_CODE (lhstype) == REFERENCE_TYPE) + lhstype = TREE_TYPE (lhstype); + else + lhstype = olhstype; + } + else + { + lhs = stabilize_reference (lhs); + newrhs = build_binary_op (modifycode, lhs, rhs, 1); + modifycode = NOP_EXPR; + } + + /* If storing into a structure or union member, + it has probably been given type `int'. + Compute the type that would go with + the actual amount of storage the member occupies. */ + + if (TREE_CODE (lhs) == COMPONENT_REF + && (TREE_CODE (lhstype) == INTEGER_TYPE + || TREE_CODE (lhstype) == REAL_TYPE + || TREE_CODE (lhstype) == ENUMERAL_TYPE)) + lhstype = TREE_TYPE (get_unwidened (lhs, 0)); + + /* C++: The semantics of C++ differ from those of C when an + assignment of an aggregate is desired. Assignment in C++ is + now defined as memberwise assignment of non-static members + and base class objects. This rule applies recursively + until a member of a built-in type is found. + + Also, we cannot do a bit-wise copy of aggregates which + contain virtual function table pointers. Those + pointer values must be preserved through the copy. + However, this is handled in expand_expr, and not here. + This is because much better code can be generated at + that stage than this one. */ + if (TREE_CODE (lhstype) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (lhstype) + && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))) + { + register tree elt; + int i; + + /* Perform operation on object. */ + if (modifycode == INIT_EXPR && TYPE_HAS_INIT_REF (lhstype)) + { + result = build_method_call (lhs, constructor_name_full (lhstype), + build_tree_list (NULL_TREE, rhs), + basetype_path, LOOKUP_NORMAL); + return build_indirect_ref (result, NULL_PTR); + } + else if (modifycode == NOP_EXPR) + { + /* `operator=' is not an inheritable operator; see 13.4.3. */ + if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype)) + { + result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, + lhs, rhs, make_node (NOP_EXPR)); + if (result == NULL_TREE) + return error_mark_node; + return result; + } + } + + if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype) + || (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype)) + || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype))) + { + tree binfos = BINFO_BASETYPES (TYPE_BINFO (lhstype)); + result = NULL_TREE; + + if (binfos != NULL_TREE) + /* Perform operation on each member, depth-first, left-right. */ + for (i = 0; i <= TREE_VEC_LENGTH (binfos)-1; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + tree base_lhs, base_rhs; + tree new_result; + + /* Assignments from virtual baseclasses handled elsewhere. */ + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + + base_lhs = get_base_ref (lhstype, i, lhs); + base_rhs = get_base_ref (lhstype, i, newrhs); + + BINFO_INHERITANCE_CHAIN (base_binfo) = basetype_path; + new_result + = build_modify_expr_1 (base_lhs, modifycode, base_rhs, + base_binfo); + + /* We either get back a compound stmt, or a simple one. */ + if (new_result && TREE_CODE (new_result) == TREE_LIST) + new_result = build_compound_expr (new_result); + result = tree_cons (NULL_TREE, new_result, result); + } + + for (elt = TYPE_FIELDS (lhstype); elt; elt = TREE_CHAIN (elt)) + { + tree vbases = NULL_TREE; + tree elt_lhs, elt_rhs; + + if (TREE_CODE (elt) != FIELD_DECL) + continue; + if (DECL_NAME (elt) + && (VFIELD_NAME_P (DECL_NAME (elt)) + || VBASE_NAME_P (DECL_NAME (elt)))) + continue; + + if (TREE_READONLY (elt) + || TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE) + { + cp_error ("cannot generate default `%T::operator ='", + lhstype); + if (TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE) + cp_error_at ("because member `%#D' is a reference", elt); + else + cp_error_at ("because member `%#D' is const", elt); + + return error_mark_node; + } + + if (IS_AGGR_TYPE (TREE_TYPE (elt)) + && TYPE_LANG_SPECIFIC (TREE_TYPE (elt))) + vbases = CLASSTYPE_VBASECLASSES (TREE_TYPE (elt)); + + elt_lhs = build (COMPONENT_REF, TREE_TYPE (elt), lhs, elt); + elt_rhs = build (COMPONENT_REF, TREE_TYPE (elt), newrhs, elt); + /* It is not always safe to go through `build_modify_expr_1' + when performing element-wise copying. This is because + an element may be of ARRAY_TYPE, which will not + be properly copied as a naked element. */ + if (TREE_CODE (TREE_TYPE (elt)) == RECORD_TYPE + && TYPE_LANG_SPECIFIC (TREE_TYPE (elt))) + basetype_path = TYPE_BINFO (TREE_TYPE (elt)); + + while (vbases) + { + tree elt_lhs_addr = build_unary_op (ADDR_EXPR, elt_lhs, 0); + tree elt_rhs_addr = build_unary_op (ADDR_EXPR, elt_rhs, 0); + + elt_lhs_addr = convert_pointer_to (vbases, elt_lhs_addr); + elt_rhs_addr = convert_pointer_to (vbases, elt_rhs_addr); + result + = tree_cons (NULL_TREE, + build_modify_expr_1 + (build_indirect_ref (elt_lhs_addr, NULL_PTR), + modifycode, + build_indirect_ref (elt_rhs_addr, NULL_PTR), + basetype_path), + result); + if (TREE_VALUE (result) == error_mark_node) + return error_mark_node; + vbases = TREE_CHAIN (vbases); + } + elt_lhs = build_modify_expr_1 (elt_lhs, modifycode, elt_rhs, + basetype_path); + result = tree_cons (NULL_TREE, elt_lhs, result); + } + + if (result) + return build_compound_expr (result); + /* No fields to move. */ + return integer_zero_node; + } + else + { + result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR, + void_type_node, lhs, rhs); + TREE_SIDE_EFFECTS (result) = 1; + return result; + } + } + + result = build_modify_expr (lhs, modifycode, newrhs); + /* ARRAY_TYPEs cannot be converted to anything meaningful, + and leaving it there screws up `build_compound_expr' when + it tries to defaultly convert everything. */ + if (TREE_CODE (TREE_TYPE (result)) == ARRAY_TYPE) + TREE_TYPE (result) = void_type_node; + return result; +} +#endif + +/* Taken from expr.c: + Subroutine of expand_expr: + record the non-copied parts (LIST) of an expr (LHS), and return a list + which specifies the initial values of these parts. */ + +static tree +init_noncopied_parts (lhs, list) + tree lhs; + tree list; +{ + tree tail; + tree parts = 0; + + for (tail = list; tail; tail = TREE_CHAIN (tail)) + if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST) + parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail))); + else + { + tree part = TREE_VALUE (tail); + tree part_type = TREE_TYPE (part); + tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part); + parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts); + } + return parts; +} + +tree +expand_target_expr (t) + tree t; +{ + tree xval = make_node (RTL_EXPR); + rtx rtxval; + + do_pending_stack_adjust (); + start_sequence_for_rtl_expr (xval); + emit_note (0, -1); + rtxval = expand_expr (t, NULL, VOIDmode, 0); + do_pending_stack_adjust (); + TREE_SIDE_EFFECTS (xval) = 1; + RTL_EXPR_SEQUENCE (xval) = get_insns (); + end_sequence (); + RTL_EXPR_RTL (xval) = rtxval; + TREE_TYPE (xval) = TREE_TYPE (t); + return xval; +} + +/* Build an assignment expression of lvalue LHS from value RHS. + MODIFYCODE is the code for a binary operator that we use + to combine the old value of LHS with RHS to get the new value. + Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment. + + C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed. +*/ +tree +build_modify_expr (lhs, modifycode, rhs) + tree lhs; + enum tree_code modifycode; + tree rhs; +{ + register tree result; + tree newrhs = rhs; + tree lhstype = TREE_TYPE (lhs); + tree olhstype = lhstype; + tree olhs = lhs; + + /* Avoid duplicate error messages from operands that had errors. */ + if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) + return error_mark_node; + + /* Types that aren't fully specified cannot be used in assignments. */ + lhs = require_complete_type (lhs); + + /* Decide early if we are going to protect RHS from GC + before assigning it to LHS. */ + if (type_needs_gc_entry (TREE_TYPE (rhs)) + && ! value_safe_from_gc (lhs, rhs)) + rhs = protect_value_from_gc (lhs, rhs); + + newrhs = rhs; + + /* Handle assignment to signature pointers/refs. */ + + if (TYPE_LANG_SPECIFIC (lhstype) && + (IS_SIGNATURE_POINTER (lhstype) || IS_SIGNATURE_REFERENCE (lhstype))) + { + return build_signature_pointer_constructor (lhs, rhs); + } + + /* Handle control structure constructs used as "lvalues". */ + + switch (TREE_CODE (lhs)) + { + /* Handle --foo = 5; as these are valid constructs in C++ */ + case PREDECREMENT_EXPR: + case PREINCREMENT_EXPR: + if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0))) + lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs), + stabilize_reference (TREE_OPERAND (lhs, 0))); + return build (COMPOUND_EXPR, lhstype, + lhs, + build_modify_expr (TREE_OPERAND (lhs, 0), + modifycode, rhs)); + + /* Handle (a, b) used as an "lvalue". */ + case COMPOUND_EXPR: + newrhs = build_modify_expr (TREE_OPERAND (lhs, 1), + modifycode, rhs); + if (TREE_CODE (newrhs) == ERROR_MARK) + return error_mark_node; + return build (COMPOUND_EXPR, lhstype, + TREE_OPERAND (lhs, 0), newrhs); + + case MODIFY_EXPR: + newrhs = build_modify_expr (TREE_OPERAND (lhs, 0), modifycode, rhs); + if (TREE_CODE (newrhs) == ERROR_MARK) + return error_mark_node; + return build (COMPOUND_EXPR, lhstype, lhs, newrhs); + + /* Handle (a ? b : c) used as an "lvalue". */ + case COND_EXPR: + rhs = save_expr (rhs); + { + /* Produce (a ? (b = rhs) : (c = rhs)) + except that the RHS goes through a save-expr + so the code to compute it is only emitted once. */ + tree cond + = build_conditional_expr (TREE_OPERAND (lhs, 0), + build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 1)), + modifycode, rhs), + build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 2)), + modifycode, rhs)); + if (TREE_CODE (cond) == ERROR_MARK) + return cond; + /* Make sure the code to compute the rhs comes out + before the split. */ + return build (COMPOUND_EXPR, TREE_TYPE (lhs), + /* Case to void to suppress warning + from warn_if_unused_value. */ + convert (void_type_node, rhs), cond); + } + } + + if (TREE_CODE (lhs) == OFFSET_REF) + { + if (TREE_OPERAND (lhs, 0) == NULL_TREE) + { + /* Static class member? */ + tree member = TREE_OPERAND (lhs, 1); + if (TREE_CODE (member) == VAR_DECL) + lhs = member; + else + { + compiler_error ("invalid static class member"); + return error_mark_node; + } + } + else + lhs = resolve_offset_ref (lhs); + + olhstype = lhstype = TREE_TYPE (lhs); + } + + if (TREE_CODE (lhstype) == REFERENCE_TYPE + && modifycode != INIT_EXPR) + { + lhs = convert_from_reference (lhs); + olhstype = lhstype = TREE_TYPE (lhs); + } + + /* If a binary op has been requested, combine the old LHS value with the RHS + producing the value we should actually store into the LHS. */ + + if (modifycode == INIT_EXPR) + { + if (! IS_AGGR_TYPE (lhstype)) + /* Do the default thing */; + else if (! TYPE_HAS_CONSTRUCTOR (lhstype)) + { + cp_error ("`%T' has no constructors", lhstype); + return error_mark_node; + } + else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype) + && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))) + /* Do the default thing */; + else + { + result = build_method_call (lhs, constructor_name_full (lhstype), + build_tree_list (NULL_TREE, rhs), + NULL_TREE, LOOKUP_NORMAL); + if (result == NULL_TREE) + return error_mark_node; + return result; + } + } + else if (modifycode == NOP_EXPR) + { +#if 1 + /* `operator=' is not an inheritable operator. */ + if (! IS_AGGR_TYPE (lhstype)) + /* Do the default thing */; + else if (! TYPE_HAS_ASSIGNMENT (lhstype)) + { + cp_error ("`%T' does not define operator=", lhstype); + return error_mark_node; + } + else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype) + && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))) + { + if (warn_synth) + /* If we care about this, do overload resolution. */ + build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, + lhs, rhs, make_node (NOP_EXPR)); + + /* Do the default thing */; + } + else + { + result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, + lhs, rhs, make_node (NOP_EXPR)); + if (result == NULL_TREE) + return error_mark_node; + return result; + } +#else + /* Treat `operator=' as an inheritable operator. */ + if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_GETS_ASSIGNMENT (lhstype)) + { + tree orig_lhstype = lhstype; + while (! TYPE_HAS_ASSIGNMENT (lhstype)) + { + int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (lhstype); + tree basetype = NULL_TREE; + for (i = 0; i < n_baseclasses; i++) + if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype, i))) + { + if (basetype != NULL_TREE) + { + message_2_types (error, "base classes `%s' and `%s' both have operator ='", + basetype, + TYPE_BINFO_BASETYPE (lhstype, i)); + return error_mark_node; + } + basetype = TYPE_BINFO_BASETYPE (lhstype, i); + } + lhstype = basetype; + } + if (orig_lhstype != lhstype) + { + lhs = build_indirect_ref (convert_pointer_to (lhstype, + build_unary_op (ADDR_EXPR, lhs, 0)), NULL_PTR); + if (lhs == error_mark_node) + { + cp_error ("conversion to private basetype `%T'", lhstype); + return error_mark_node; + } + } + result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL, + lhs, rhs, make_node (NOP_EXPR)); + if (result == NULL_TREE) + return error_mark_node; + return result; + } +#endif + lhstype = olhstype; + } + else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE)) + { + /* This case must convert to some sort of lvalue that + can participate in an op= operation. */ + tree lhs_tmp = lhs; + tree rhs_tmp = rhs; + if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp)) + { + lhs = stabilize_reference (lhs_tmp); + /* Forget is was ever anything else. */ + olhstype = lhstype = TREE_TYPE (lhs); + newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1); + } + else + { + cp_error ("no match for `%O(%#T, %#T)'", modifycode, + TREE_TYPE (lhs), TREE_TYPE (rhs)); + return error_mark_node; + } + } + else + { + lhs = stabilize_reference (lhs); + newrhs = build_binary_op (modifycode, lhs, rhs, 1); + } + + /* Handle a cast used as an "lvalue". + We have already performed any binary operator using the value as cast. + Now convert the result to the cast type of the lhs, + and then true type of the lhs and store it there; + then convert result back to the cast type to be the value + of the assignment. */ + + switch (TREE_CODE (lhs)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE + || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE) + newrhs = default_conversion (newrhs); + { + tree inner_lhs = TREE_OPERAND (lhs, 0); + tree result; + if (! lvalue_p (lhs) && pedantic) + pedwarn ("cast to non-reference type used as lvalue"); + + result = build_modify_expr (inner_lhs, NOP_EXPR, + convert (TREE_TYPE (inner_lhs), + convert (lhstype, newrhs))); + if (TREE_CODE (result) == ERROR_MARK) + return result; + return convert (TREE_TYPE (lhs), result); + } + } + + /* Now we have handled acceptable kinds of LHS that are not truly lvalues. + Reject anything strange now. */ + + if (!lvalue_or_else (lhs, "assignment")) + return error_mark_node; + + GNU_xref_assign (lhs); + + /* Warn about storing in something that is `const'. */ + /* For C++, don't warn if this is initialization. */ + if (modifycode != INIT_EXPR + /* For assignment to `const' signature pointer/reference fields, + don't warn either, we already printed a better message before. */ + && ! (TREE_CODE (lhs) == COMPONENT_REF + && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0))) + || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0))))) + && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype) + || ((TREE_CODE (lhstype) == RECORD_TYPE + || TREE_CODE (lhstype) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (lhstype)) + || (TREE_CODE (lhstype) == REFERENCE_TYPE + && TYPE_READONLY (TREE_TYPE (lhstype))))) + readonly_error (lhs, "assignment", 0); + + /* If storing into a structure or union member, + it has probably been given type `int'. + Compute the type that would go with + the actual amount of storage the member occupies. */ + + if (TREE_CODE (lhs) == COMPONENT_REF + && (TREE_CODE (lhstype) == INTEGER_TYPE + || TREE_CODE (lhstype) == REAL_TYPE + || TREE_CODE (lhstype) == ENUMERAL_TYPE)) + { + lhstype = TREE_TYPE (get_unwidened (lhs, 0)); + + /* If storing in a field that is in actuality a short or narrower + than one, we must store in the field in its actual type. */ + + if (lhstype != TREE_TYPE (lhs)) + { + lhs = copy_node (lhs); + TREE_TYPE (lhs) = lhstype; + } + } + + /* check to see if there is an assignment to `this' */ + if (lhs == current_class_decl) + { + if (flag_this_is_variable > 0 + && DECL_NAME (current_function_decl) != NULL_TREE + && (DECL_NAME (current_function_decl) + != constructor_name (current_class_type))) + warning ("assignment to `this' not in constructor or destructor"); + current_function_just_assigned_this = 1; + } + + /* The TREE_TYPE of RHS may be TYPE_UNKNOWN. This can happen + when the type of RHS is not yet known, i.e. its type + is inherited from LHS. */ + rhs = require_instantiated_type (lhstype, newrhs, error_mark_node); + if (rhs == error_mark_node) + return error_mark_node; + newrhs = rhs; + + if (modifycode != INIT_EXPR) + { + /* Make modifycode now either a NOP_EXPR or an INIT_EXPR. */ + modifycode = NOP_EXPR; + /* Reference-bashing */ + if (TREE_CODE (lhstype) == REFERENCE_TYPE) + { + tree tmp = convert_from_reference (lhs); + lhstype = TREE_TYPE (tmp); + if (TYPE_SIZE (lhstype) == 0) + { + incomplete_type_error (lhs, lhstype); + return error_mark_node; + } + lhs = tmp; + olhstype = lhstype; + } + if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE) + { + tree tmp = convert_from_reference (newrhs); + if (TYPE_SIZE (TREE_TYPE (tmp)) == 0) + { + incomplete_type_error (newrhs, TREE_TYPE (tmp)); + return error_mark_node; + } + newrhs = tmp; + } + } + + if (TREE_SIDE_EFFECTS (lhs)) + lhs = stabilize_reference (lhs); + if (TREE_SIDE_EFFECTS (newrhs)) + newrhs = stabilize_reference (newrhs); + +#if 0 + /* This is now done by generating X(X&) and operator=(X&). */ + /* C++: The semantics of C++ differ from those of C when an + assignment of an aggregate is desired. Assignment in C++ is + now defined as memberwise assignment of non-static members + and base class objects. This rule applies recursively + until a member of a built-in type is found. + + Also, we cannot do a bit-wise copy of aggregates which + contain virtual function table pointers. Those + pointer values must be preserved through the copy. + However, this is handled in expand_expr, and not here. + This is because much better code can be generated at + that stage than this one. */ + if (TREE_CODE (lhstype) == RECORD_TYPE + && ! TYPE_PTRMEMFUNC_P (lhstype) + && (TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)) + || (TREE_CODE (TREE_TYPE (newrhs)) == RECORD_TYPE + && UNIQUELY_DERIVED_FROM_P (lhstype, TREE_TYPE (newrhs))))) + { + tree vbases = CLASSTYPE_VBASECLASSES (lhstype); + tree lhs_addr = build_unary_op (ADDR_EXPR, lhs, 0); + tree rhs_addr; + + /* Memberwise assignment would cause NEWRHS to be + evaluated for every member that gets assigned. + By wrapping side-effecting exprs in a SAVE_EXPR, + NEWRHS will only be evaluated once. */ + if (IS_AGGR_TYPE (TREE_TYPE (newrhs)) + && TREE_SIDE_EFFECTS (newrhs) + /* This are things we don't have to save. */ + && TREE_CODE (newrhs) != COND_EXPR + && TREE_CODE (newrhs) != TARGET_EXPR + && TREE_CODE (newrhs) != WITH_CLEANUP_EXPR) + /* Call `break_out_cleanups' on NEWRHS in case there are cleanups. + If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so + will result in expand_expr expanding the call without knowing + that it should run the cleanup. */ + newrhs = save_expr (break_out_cleanups (newrhs)); + + if (TREE_CODE (newrhs) == COND_EXPR) + rhs_addr = rationalize_conditional_expr (ADDR_EXPR, newrhs); + else + rhs_addr = build_unary_op (ADDR_EXPR, newrhs, 0); + + result = tree_cons (NULL_TREE, + convert (build_reference_type (lhstype), lhs), + NULL_TREE); + + if (! comptypes (TREE_TYPE (lhs_addr), TREE_TYPE (rhs_addr), 1)) + rhs_addr = convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr)), rhs_addr); + { + tree noncopied_parts = NULL_TREE; + + if (TYPE_NONCOPIED_PARTS (lhstype) != 0) + noncopied_parts = init_noncopied_parts (lhs, + TYPE_NONCOPIED_PARTS (lhstype)); + while (noncopied_parts != 0) + { + result = tree_cons (NULL_TREE, + build_modify_expr (convert (ptr_type_node, TREE_VALUE (noncopied_parts)), + NOP_EXPR, + TREE_PURPOSE (noncopied_parts)), + result); + noncopied_parts = TREE_CHAIN (noncopied_parts); + } + } + /* Once we have our hands on an address, we must change NEWRHS + to work from there. Otherwise we can get multiple evaluations + of NEWRHS. */ + if (TREE_CODE (newrhs) != SAVE_EXPR) + newrhs = build_indirect_ref (rhs_addr, NULL_PTR); + + while (vbases) + { + tree elt_lhs = convert_pointer_to (vbases, lhs_addr); + tree elt_rhs = convert_pointer_to (vbases, rhs_addr); + result + = tree_cons (NULL_TREE, + build_modify_expr_1 (build_indirect_ref (elt_lhs, NULL_PTR), + modifycode, + build_indirect_ref (elt_rhs, NULL_PTR), + TYPE_BINFO (lhstype)), + result); + if (TREE_VALUE (result) == error_mark_node) + return error_mark_node; + vbases = TREE_CHAIN (vbases); + } + result = tree_cons (NULL_TREE, + build_modify_expr_1 (lhs, + modifycode, + newrhs, + TYPE_BINFO (lhstype)), + result); + return build_compound_expr (result); + } +#endif + + /* Convert new value to destination type. */ + + if (TREE_CODE (lhstype) == ARRAY_TYPE) + { + int from_array; + + if (! comptypes (lhstype, TREE_TYPE (rhs), 0)) + { + cp_error ("incompatible types in assignment of `%T' to `%T'", + TREE_TYPE (rhs), lhstype); + return error_mark_node; + } + + /* Allow array assignment in compiler-generated code. */ + if (pedantic && ! DECL_ARTIFICIAL (current_function_decl)) + pedwarn ("ANSI C++ forbids assignment of arrays"); + + /* Have to wrap this in RTL_EXPR for two cases: + in base or member initialization and if we + are a branch of a ?: operator. Since we + can't easily know the latter, just do it always. */ + + result = make_node (RTL_EXPR); + + TREE_TYPE (result) = void_type_node; + do_pending_stack_adjust (); + start_sequence_for_rtl_expr (result); + + /* As a matter of principle, `start_sequence' should do this. */ + emit_note (0, -1); + + from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE + ? 1 + (modifycode != INIT_EXPR): 0; + expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs, + from_array); + + do_pending_stack_adjust (); + + TREE_SIDE_EFFECTS (result) = 1; + RTL_EXPR_SEQUENCE (result) = get_insns (); + RTL_EXPR_RTL (result) = const0_rtx; + end_sequence (); + return result; + } + + if (modifycode == INIT_EXPR) + { + newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL, + "assignment", NULL_TREE, 0); + if (lhs == DECL_RESULT (current_function_decl)) + { + if (DECL_INITIAL (lhs)) + warning ("return value from function receives multiple initializations"); + DECL_INITIAL (lhs) = newrhs; + } + } + else + { +#if 0 + if (IS_AGGR_TYPE (lhstype)) + { + if (result = build_opfncall (MODIFY_EXPR, + LOOKUP_NORMAL, lhs, newrhs, + make_node (NOP_EXPR))) + return result; + } +#endif + /* Avoid warnings on enum bit fields. */ + if (TREE_CODE (olhstype) == ENUMERAL_TYPE + && TREE_CODE (lhstype) == INTEGER_TYPE) + { + newrhs = convert_for_assignment (olhstype, newrhs, "assignment", + NULL_TREE, 0); + newrhs = convert_force (lhstype, newrhs, 0); + } + else + newrhs = convert_for_assignment (lhstype, newrhs, "assignment", + NULL_TREE, 0); + if (TREE_CODE (newrhs) == CALL_EXPR + && TYPE_NEEDS_CONSTRUCTING (lhstype)) + newrhs = build_cplus_new (lhstype, newrhs, 0); + + /* Can't initialize directly from a TARGET_EXPR, since that would + cause the lhs to be constructed twice, and possibly result in + accidental self-initialization. So we force the TARGET_EXPR to be + expanded. expand_expr should really do this by itself. */ + if (TREE_CODE (newrhs) == TARGET_EXPR) + newrhs = expand_target_expr (newrhs); + } + + if (TREE_CODE (newrhs) == ERROR_MARK) + return error_mark_node; + + if (TREE_CODE (newrhs) == COND_EXPR) + { + tree lhs1; + tree cond = TREE_OPERAND (newrhs, 0); + + if (TREE_SIDE_EFFECTS (lhs)) + cond = build_compound_expr (tree_cons + (NULL_TREE, lhs, + build_tree_list (NULL_TREE, cond))); + + /* Cannot have two identical lhs on this one tree (result) as preexpand + calls will rip them out and fill in RTL for them, but when the + rtl is generated, the calls will only be in the first side of the + condition, not on both, or before the conditional jump! (mrs) */ + lhs1 = break_out_calls (lhs); + + if (lhs == lhs1) + /* If there's no change, the COND_EXPR behaves like any other rhs. */ + result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR, + lhstype, lhs, newrhs); + else + { + tree result_type = TREE_TYPE (newrhs); + /* We have to convert each arm to the proper type because the + types may have been munged by constant folding. */ + result + = build (COND_EXPR, result_type, cond, + build_modify_expr (lhs, modifycode, + convert (result_type, + TREE_OPERAND (newrhs, 1))), + build_modify_expr (lhs1, modifycode, + convert (result_type, + TREE_OPERAND (newrhs, 2)))); + } + } + else if (modifycode != INIT_EXPR && TREE_CODE (newrhs) == WITH_CLEANUP_EXPR) + { + tree cleanup = TREE_OPERAND (newrhs, 2); + tree slot; + + /* Finish up by running cleanups and having the "value" of the lhs. */ + tree exprlist = tree_cons (NULL_TREE, cleanup, + build_tree_list (NULL_TREE, lhs)); + newrhs = TREE_OPERAND (newrhs, 0); + if (TREE_CODE (newrhs) == TARGET_EXPR) + slot = TREE_OPERAND (newrhs, 0); + else if (TREE_CODE (newrhs) == ADDR_EXPR) + { + /* Bad but valid. */ + slot = newrhs; + warning ("address taken of temporary object"); + } + else + my_friendly_abort (118); + + /* Copy the value computed in SLOT into LHS. */ + exprlist = tree_cons (NULL_TREE, + build_modify_expr (lhs, modifycode, slot), + exprlist); + /* Evaluate the expression that needs CLEANUP. This will + compute the value into SLOT. */ + exprlist = tree_cons (NULL_TREE, newrhs, exprlist); + result = convert (lhstype, build_compound_expr (exprlist)); + } + else + result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR, + lhstype, lhs, newrhs); + TREE_SIDE_EFFECTS (result) = 1; + + /* If we got the LHS in a different type for storing in, + convert the result back to the nominal type of LHS + so that the value we return always has the same type + as the LHS argument. */ + + if (olhstype == TREE_TYPE (result)) + return result; + /* Avoid warnings converting integral types back into enums + for enum bit fields. */ + if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE + && TREE_CODE (olhstype) == ENUMERAL_TYPE) + { + result = build (COMPOUND_EXPR, olhstype, result, olhs); + TREE_NO_UNUSED_WARNING (result) = 1; + return result; + } + return convert_for_assignment (olhstype, result, "assignment", + NULL_TREE, 0); +} + + +/* Return 0 if EXP is not a valid lvalue in this language + even though `lvalue_or_else' would accept it. */ + +int +language_lvalue_valid (exp) + tree exp; +{ + return 1; +} + +/* Get difference in deltas for different pointer to member function + types. Return integer_zero_node, if FROM cannot be converted to a + TO type. If FORCE is true, then allow reverse conversions as well. */ +static tree +get_delta_difference (from, to, force) + tree from, to; + int force; +{ + tree delta = integer_zero_node; + tree binfo; + + if (to == from) + return delta; + + /* Should get_base_distance here, so we can check if any thing along the + path is virtual, and we need to make sure we stay + inside the real binfos when going through virtual bases. + Maybe we should replace virtual bases with + binfo_member (...CLASSTYPE_VBASECLASSES...)... (mrs) */ + binfo = get_binfo (from, to, 1); + if (binfo == error_mark_node) + { + error (" in pointer to member function conversion"); + return delta; + } + if (binfo == 0) + { + if (!force) + { + error_not_base_type (from, to); + error (" in pointer to member function conversion"); + return delta; + } + binfo = get_binfo (to, from, 1); + if (binfo == error_mark_node) + { + error (" in pointer to member function conversion"); + return delta; + } + if (binfo == 0) + { + error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from, to); + return delta; + } + if (TREE_VIA_VIRTUAL (binfo)) + { + warning ("pointer to member conversion to virtual base class will only work if you are very careful"); + } + return build_binary_op (MINUS_EXPR, + integer_zero_node, + BINFO_OFFSET (binfo), 1); + } + if (TREE_VIA_VIRTUAL (binfo)) + { + warning ("pointer to member conversion from virtual base class will only work if you are very careful"); + } + return BINFO_OFFSET (binfo); +} + +/* Build a constructor for a pointer to member function. It can be + used to initialize global variables, local variable, or used + as a value in expressions. TYPE is the POINTER to METHOD_TYPE we + want to be. + + If FORCE is non-zero, then force this conversion, even if + we would rather not do it. Usually set when using an explicit + cast. + + Return error_mark_node, if something goes wrong. */ + +tree +build_ptrmemfunc (type, pfn, force) + tree type, pfn; + int force; +{ + tree index = integer_zero_node; + tree delta = integer_zero_node; + tree delta2 = integer_zero_node; + tree vfield_offset; + tree npfn; + tree u; + + /* Handle multiple conversions of pointer to member functions. */ + if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn))) + { + tree ndelta, ndelta2, nindex; + /* Is is already the right type? */ +#if 0 + /* Sorry, can't do this, the backend is too stupid. */ + if (TYPE_METHOD_BASETYPE (TREE_TYPE (type)) + == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn))))) + { + if (type != TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn))) + { + npfn = build1 (NOP_EXPR, TYPE_GET_PTRMEMFUNC_TYPE (type), pfn); + TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn); + } + return pfn; + } +#else + if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn))) + return pfn; +#endif + + if (TREE_CODE (pfn) != CONSTRUCTOR) + { + tree e1, e2, e3; + ndelta = convert (ptrdiff_type_node, build_component_ref (pfn, delta_identifier, 0, 0)); + ndelta2 = convert (ptrdiff_type_node, DELTA2_FROM_PTRMEMFUNC (pfn)); + index = build_component_ref (pfn, index_identifier, 0, 0); + delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))), + TYPE_METHOD_BASETYPE (TREE_TYPE (type)), + force); + delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1); + delta2 = build_binary_op (PLUS_EXPR, ndelta2, delta2, 1); + e1 = fold (build (GT_EXPR, boolean_type_node, index, integer_zero_node)); + + u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE)); + u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta, + tree_cons (NULL_TREE, index, + tree_cons (NULL_TREE, u, NULL_TREE)))); + e2 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0); + + pfn = PFN_FROM_PTRMEMFUNC (pfn); + npfn = build1 (NOP_EXPR, type, pfn); + TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn); + + u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE)); + u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta, + tree_cons (NULL_TREE, index, + tree_cons (NULL_TREE, u, NULL_TREE)))); + e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0); + return build_conditional_expr (e1, e2, e3); + } + + ndelta = TREE_VALUE (CONSTRUCTOR_ELTS (pfn)); + nindex = TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn))); + npfn = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn)))); + npfn = TREE_VALUE (CONSTRUCTOR_ELTS (npfn)); + if (integer_zerop (nindex)) + pfn = integer_zero_node; + else if (integer_zerop (fold (size_binop (PLUS_EXPR, nindex, integer_one_node)))) + { + tree e3; + delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))), + TYPE_METHOD_BASETYPE (TREE_TYPE (type)), + force); + delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1); + pfn = build1 (NOP_EXPR, type, npfn); + TREE_CONSTANT (pfn) = TREE_CONSTANT (npfn); + + u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE)); + u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta, + tree_cons (NULL_TREE, nindex, + tree_cons (NULL_TREE, u, NULL_TREE)))); + e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0); + return e3; + } + else + { + sorry ("value casting of variable nonnull pointer to member functions not supported"); + return error_mark_node; + } + } + + /* Handle null pointer to member function conversions. */ + if (integer_zerop (pfn)) + { + pfn = build_c_cast (type, integer_zero_node, 0); + u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE)); + u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, integer_zero_node, + tree_cons (NULL_TREE, integer_zero_node, + tree_cons (NULL_TREE, u, NULL_TREE)))); + return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0); + } + + if (TREE_CODE (pfn) == TREE_LIST + || (TREE_CODE (pfn) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (pfn, 0)) == TREE_LIST)) + { + pfn = instantiate_type (type, pfn, 1); + if (pfn == error_mark_node) + return error_mark_node; + if (TREE_CODE (pfn) != ADDR_EXPR) + pfn = build_unary_op (ADDR_EXPR, pfn, 0); + } + + /* Allow pointer to member conversions here. */ + delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))), + TYPE_METHOD_BASETYPE (TREE_TYPE (type)), + force); + delta2 = build_binary_op (PLUS_EXPR, delta2, delta, 1); + + if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL) + warning ("assuming pointer to member function is non-virtual"); + + if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL + && DECL_VINDEX (TREE_OPERAND (pfn, 0))) + { + /* Find the offset to the vfield pointer in the object. */ + vfield_offset = get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn, 0)), + DECL_CLASS_CONTEXT (TREE_OPERAND (pfn, 0)), + 0); + vfield_offset = get_vfield_offset (vfield_offset); + delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2); + + /* Map everything down one to make room for the null pointer to member. */ + index = size_binop (PLUS_EXPR, + DECL_VINDEX (TREE_OPERAND (pfn, 0)), + integer_one_node); + u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE)); + } + else + { + index = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node); + + npfn = build1 (NOP_EXPR, type, pfn); + TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn); + + u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE)); + } + + u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta, + tree_cons (NULL_TREE, index, + tree_cons (NULL_TREE, u, NULL_TREE)))); + return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0); +} + +/* Convert value RHS to type TYPE as preparation for an assignment + to an lvalue of type TYPE. + The real work of conversion is done by `convert'. + The purpose of this function is to generate error messages + for assignments that are not allowed in C. + ERRTYPE is a string to use in error messages: + "assignment", "return", etc. + + C++: attempts to allow `convert' to find conversions involving + implicit type conversion between aggregate and scalar types + as per 8.5.6 of C++ manual. Does not randomly dereference + pointers to aggregates! */ + +static tree +convert_for_assignment (type, rhs, errtype, fndecl, parmnum) + tree type, rhs; + char *errtype; + tree fndecl; + int parmnum; +{ + register enum tree_code codel = TREE_CODE (type); + register tree rhstype; + register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs)); + + if (coder == UNKNOWN_TYPE) + rhs = instantiate_type (type, rhs, 1); + + if (coder == ERROR_MARK) + return error_mark_node; + + if (codel == OFFSET_TYPE) + { + type = TREE_TYPE (type); + codel = TREE_CODE (type); + } + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + if (TREE_CODE (rhs) == NON_LVALUE_EXPR) + rhs = TREE_OPERAND (rhs, 0); + + if (rhs == error_mark_node) + return error_mark_node; + + if (TREE_VALUE (rhs) == error_mark_node) + return error_mark_node; + + if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE) + { + rhs = resolve_offset_ref (rhs); + if (rhs == error_mark_node) + return error_mark_node; + rhstype = TREE_TYPE (rhs); + coder = TREE_CODE (rhstype); + } + + if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE + || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE) + rhs = default_conversion (rhs); + else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE) + rhs = convert_from_reference (rhs); + + rhstype = TREE_TYPE (rhs); + coder = TREE_CODE (rhstype); + + /* This should no longer change types on us. */ + if (TREE_CODE (rhs) == CONST_DECL) + rhs = DECL_INITIAL (rhs); + else if (TREE_READONLY_DECL_P (rhs)) + rhs = decl_constant_value (rhs); + + if (type == rhstype) + { + overflow_warning (rhs); + return rhs; + } + + if (coder == VOID_TYPE) + { + error ("void value not ignored as it ought to be"); + return error_mark_node; + } + /* Arithmetic types all interconvert. */ + if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == BOOLEAN_TYPE) + && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == BOOLEAN_TYPE)) + { + /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE. */ + if (coder == REAL_TYPE && codel == INTEGER_TYPE) + { + if (fndecl) + cp_warning ("`%T' used for argument %P of `%D'", + rhstype, parmnum, fndecl); + else + cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype); + } + /* And we should warn if assigning a negative value to + an unsigned variable. */ + else if (TREE_UNSIGNED (type) && codel != BOOLEAN_TYPE) + { + if (TREE_CODE (rhs) == INTEGER_CST + && TREE_NEGATED_INT (rhs)) + { + if (fndecl) + cp_warning ("negative value `%E' passed as argument %P of `%D'", + rhs, parmnum, fndecl); + else + cp_warning ("%s of negative value `%E' to `%T'", + errtype, rhs, type); + } + overflow_warning (rhs); + if (TREE_CONSTANT (rhs)) + rhs = fold (rhs); + } + + return convert_and_check (type, rhs); + } + /* Conversions involving enums. */ + else if ((codel == ENUMERAL_TYPE + && (INTEGRAL_CODE_P (coder) || coder == REAL_TYPE)) + || (coder == ENUMERAL_TYPE + && (INTEGRAL_CODE_P (codel) || codel == REAL_TYPE))) + { + return cp_convert (type, rhs, CONV_IMPLICIT, LOOKUP_NORMAL); + } + /* Conversions among pointers */ + else if (codel == POINTER_TYPE + && (coder == POINTER_TYPE + || (coder == RECORD_TYPE + && (IS_SIGNATURE_POINTER (rhstype) + || IS_SIGNATURE_REFERENCE (rhstype))))) + { + register tree ttl = TREE_TYPE (type); + register tree ttr; + int ctt = 0; + + if (coder == RECORD_TYPE) + { + rhs = build_optr_ref (rhs); + rhstype = TREE_TYPE (rhs); + } + ttr = TREE_TYPE (rhstype); + + /* If both pointers are of aggregate type, then we + can give better error messages, and save some work + as well. */ + if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE) + { + tree binfo; + + if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr) + || type == class_star_type_node + || rhstype == class_star_type_node) + binfo = TYPE_BINFO (ttl); + else + binfo = get_binfo (ttl, ttr, 1); + + if (binfo == error_mark_node) + return error_mark_node; + if (binfo == 0) + return error_not_base_type (ttl, ttr); + + if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards const", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards const", + errtype, type, rhstype); + } + if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards volatile", + errtype, type, rhstype); + } + } + + /* Any non-function converts to a [const][volatile] void * + and vice versa; otherwise, targets must be the same. + Meanwhile, the lhs target must have all the qualifiers of the rhs. */ + else if (TYPE_MAIN_VARIANT (ttl) == void_type_node + || TYPE_MAIN_VARIANT (ttr) == void_type_node + || (ctt = comp_target_types (type, rhstype, 1)) + || (unsigned_type (TYPE_MAIN_VARIANT (ttl)) + == unsigned_type (TYPE_MAIN_VARIANT (ttr)))) + { + /* ARM $4.8, commentary on p39. */ + if (TYPE_MAIN_VARIANT (ttl) == void_type_node + && TREE_CODE (ttr) == OFFSET_TYPE) + { + cp_error ("no standard conversion from `%T' to `void *'", ttr); + return error_mark_node; + } + + if (ctt < 0) + cp_pedwarn ("converting `%T' to `%T' is a contravariance violation", + rhstype, type); + + if (TYPE_MAIN_VARIANT (ttl) != void_type_node + && TYPE_MAIN_VARIANT (ttr) == void_type_node + && rhs != null_pointer_node) + { + if (coder == RECORD_TYPE) + cp_pedwarn ("implicit conversion of signature pointer to type `%T'", + type); + else + pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s", + errtype); + } + /* Const and volatile mean something different for function types, + so the usual warnings are not appropriate. */ + else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE) + || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE)) + { + if (TREE_CODE (ttl) == OFFSET_TYPE + && binfo_member (TYPE_OFFSET_BASETYPE (ttr), + CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl)))) + { + sorry ("%s between pointer to members converting across virtual baseclasses", errtype); + return error_mark_node; + } + else if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards const", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards const", + errtype, type, rhstype); + } + else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards volatile", + errtype, type, rhstype); + } + else if (TREE_CODE (ttl) == TREE_CODE (ttr) + && ! comp_target_types (type, rhstype, 1)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' changes signedness", + errtype, type, rhstype); + } + } + } + else if (TREE_CODE (ttr) == OFFSET_TYPE + && TREE_CODE (ttl) != OFFSET_TYPE) + { + /* Normally, pointers to different type codes (other + than void) are not compatible, but we perform + some type instantiation if that resolves the + ambiguity of (X Y::*) and (X *). */ + + if (current_class_decl) + { + if (TREE_CODE (rhs) == INTEGER_CST) + { + rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)), + current_class_decl, rhs); + return convert_for_assignment (type, rhs, + errtype, fndecl, parmnum); + } + } + if (TREE_CODE (ttl) == METHOD_TYPE) + error ("%s between pointer-to-method and pointer-to-member types", + errtype); + else + error ("%s between pointer and pointer-to-member types", errtype); + return error_mark_node; + } + else + { + int add_quals = 0, const_parity = 0, volatile_parity = 0; + int left_const = 1; + int unsigned_parity; + int nptrs = 0; + + /* This code is basically a duplicate of comp_ptr_ttypes_real. */ + for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr)) + { + nptrs -= 1; + const_parity |= TYPE_READONLY (ttl) < TYPE_READONLY (ttr); + volatile_parity |= TYPE_VOLATILE (ttl) < TYPE_VOLATILE (ttr); + + if (! left_const + && (TYPE_READONLY (ttl) > TYPE_READONLY (ttr) + || TYPE_VOLATILE (ttl) > TYPE_VOLATILE (ttr))) + add_quals = 1; + left_const &= TYPE_READONLY (ttl); + + if (TREE_CODE (ttl) != POINTER_TYPE + || TREE_CODE (ttr) != POINTER_TYPE) + break; + } + unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr); + if (unsigned_parity) + { + if (TREE_UNSIGNED (ttl)) + ttr = unsigned_type (ttr); + else + ttl = unsigned_type (ttl); + } + + if (comp_target_types (ttl, ttr, nptrs) > 0) + { + if (add_quals) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'", + errtype, type, rhstype); + } + if (const_parity) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards const", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards const", + errtype, type, rhstype); + } + if (volatile_parity) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards volatile", + errtype, type, rhstype); + } + if (unsigned_parity > 0) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned", + errtype, type, rhstype); + } + else if (unsigned_parity < 0) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed", + errtype, type, rhstype); + } + + /* C++ is not so friendly about converting function and + member function pointers as C. Emit warnings here. */ + if (TREE_CODE (ttl) == FUNCTION_TYPE + || TREE_CODE (ttl) == METHOD_TYPE) + if (! comptypes (ttl, ttr, 0)) + { + warning ("conflicting function types in %s:", errtype); + cp_warning ("\t`%T' != `%T'", type, rhstype); + } + } + else if (TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE) + { + /* When does this happen? */ + my_friendly_abort (119); + /* Conversion of a pointer-to-member type to void *. */ + rhs = build_unary_op (ADDR_EXPR, rhs, 0); + TREE_TYPE (rhs) = type; + return rhs; + } + else if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE) + { + /* When does this happen? */ + my_friendly_abort (120); + /* Conversion of a pointer-to-member type to void *. */ + rhs = build_unary_op (ADDR_EXPR, rhs, 0); + TREE_TYPE (rhs) = type; + return rhs; + } + else + { + if (fndecl) + cp_error ("passing `%T' as argument %P of `%D'", + rhstype, parmnum, fndecl); + else + cp_error ("%s to `%T' from `%T'", errtype, type, rhstype); + return error_mark_node; + } + } + return convert (type, rhs); + } + else if (codel == POINTER_TYPE && coder == INTEGER_TYPE) + { + /* An explicit constant 0 can convert to a pointer, + but not a 0 that results from casting or folding. */ + if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))) + { + if (fndecl) + cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' lacks a cast", + errtype, type, rhstype); + return convert (type, rhs); + } + return null_pointer_node; + } + else if (codel == INTEGER_TYPE + && (coder == POINTER_TYPE + || (coder == RECORD_TYPE + && (IS_SIGNATURE_POINTER (rhstype) + || TYPE_PTRMEMFUNC_FLAG (rhstype) + || IS_SIGNATURE_REFERENCE (rhstype))))) + { + if (fndecl) + cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast", + rhstype, parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' lacks a cast", + errtype, type, rhstype); + return convert (type, rhs); + } + else if (codel == BOOLEAN_TYPE + && (coder == POINTER_TYPE + || (coder == RECORD_TYPE + && (IS_SIGNATURE_POINTER (rhstype) + || TYPE_PTRMEMFUNC_FLAG (rhstype) + || IS_SIGNATURE_REFERENCE (rhstype))))) + return convert (type, rhs); + + /* C++ */ + else if (((coder == POINTER_TYPE + && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE) + || integer_zerop (rhs) + || TYPE_PTRMEMFUNC_P (rhstype)) + && TYPE_PTRMEMFUNC_P (type)) + { + tree ttl = TYPE_PTRMEMFUNC_FN_TYPE (type); + tree ttr = (TREE_CODE (rhstype) == POINTER_TYPE ? rhstype + : TYPE_PTRMEMFUNC_FN_TYPE (type)); + int ctt = comp_target_types (ttl, ttr, 1); + + if (ctt < 0) + cp_pedwarn ("converting `%T' to `%T' is a contravariance violation", + ttr, ttl); + else if (ctt == 0) + cp_error ("%s to `%T' from `%T'", errtype, ttl, ttr); + + /* compatible pointer to member functions. */ + return build_ptrmemfunc (ttl, rhs, 0); + } + else if (codel == ERROR_MARK || coder == ERROR_MARK) + return error_mark_node; + + /* This should no longer happen. References are initialized via + `convert_for_initialization'. They should otherwise be + bashed before coming here. */ + else if (codel == REFERENCE_TYPE) + my_friendly_abort (317); + else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs))) + { + tree nrhs = build1 (NOP_EXPR, type, rhs); + TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs); + return nrhs; + } + else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs))) + return convert (type, rhs); + + cp_error ("%s to `%T' from `%T'", errtype, type, rhstype); + return error_mark_node; +} + +/* Convert RHS to be of type TYPE. If EXP is non-zero, + it is the target of the initialization. + ERRTYPE is a string to use in error messages. + + Two major differences between the behavior of + `convert_for_assignment' and `convert_for_initialization' + are that references are bashed in the former, while + copied in the latter, and aggregates are assigned in + the former (operator=) while initialized in the + latter (X(X&)). + + If using constructor make sure no conversion operator exists, if one does + exist, an ambiguity exists. + + If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything. */ +tree +convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum) + tree exp, type, rhs; + int flags; + char *errtype; + tree fndecl; + int parmnum; +{ + register enum tree_code codel = TREE_CODE (type); + register tree rhstype; + register enum tree_code coder; + + /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. + Strip such NOP_EXPRs, since RHS is used in non-lvalue context. */ + if (TREE_CODE (rhs) == NOP_EXPR + && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0)) + && codel != REFERENCE_TYPE) + rhs = TREE_OPERAND (rhs, 0); + + if (rhs == error_mark_node + || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node)) + return error_mark_node; + + if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE) + { + rhs = resolve_offset_ref (rhs); + if (rhs == error_mark_node) + return error_mark_node; + } + + if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE) + rhs = convert_from_reference (rhs); + + if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE + && TREE_CODE (type) != ARRAY_TYPE + && (TREE_CODE (type) != REFERENCE_TYPE + || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE)) + || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE + || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE) + rhs = default_conversion (rhs); + + rhstype = TREE_TYPE (rhs); + coder = TREE_CODE (rhstype); + + if (coder == UNKNOWN_TYPE) + { + rhs = instantiate_type (type, rhs, 1); + rhstype = TREE_TYPE (rhs); + coder = TREE_CODE (rhstype); + } + + if (coder == ERROR_MARK) + return error_mark_node; + +#if 0 + /* This is *not* the quick way out! It is the way to disaster. */ + if (type == rhstype) + goto converted; +#endif + + /* We accept references to incomplete types, so we can + return here before checking if RHS is of complete type. */ + + if (codel == REFERENCE_TYPE) + { + /* This should eventually happen in convert_arguments. */ + extern int warningcount, errorcount; + int savew, savee; + + if (fndecl) + savew = warningcount, savee = errorcount; + rhs = convert_to_reference (type, rhs, CONV_IMPLICIT, flags, + exp ? exp : error_mark_node); + if (fndecl) + { + if (warningcount > savew) + cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl); + else if (errorcount > savee) + cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl); + } + return rhs; + } + + rhs = require_complete_type (rhs); + if (rhs == error_mark_node) + return error_mark_node; + + if (exp != 0) exp = require_complete_type (exp); + if (exp == error_mark_node) + return error_mark_node; + + if (TREE_CODE (rhstype) == REFERENCE_TYPE) + rhstype = TREE_TYPE (rhstype); + + if (TYPE_LANG_SPECIFIC (type) + && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))) + return build_signature_pointer_constructor (type, rhs); + + if (IS_AGGR_TYPE (type) + && (TYPE_NEEDS_CONSTRUCTING (type) || TREE_HAS_CONSTRUCTOR (rhs))) + { + if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) + { + /* This is sufficient to perform initialization. No need, + apparently, to go through X(X&) to do first-cut + initialization. Return through a TARGET_EXPR so that we get + cleanups if it is used. */ + if (TREE_CODE (rhs) == CALL_EXPR) + { + rhs = build_cplus_new (type, rhs, 0); + return rhs; + } + /* Handle the case of default parameter initialization and + initialization of static variables. */ + else if (TREE_CODE (rhs) == TARGET_EXPR) + return rhs; + else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs)) + { + my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318); + if (exp) + { + my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316); + TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) + = build_unary_op (ADDR_EXPR, exp, 0); + } + else + rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0), 0); + return rhs; + } + else if (TYPE_HAS_TRIVIAL_INIT_REF (type)) + return rhs; + } + if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype) + || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype))) + { + if (TYPE_HAS_INIT_REF (type)) + { + tree init = build_method_call (exp, constructor_name_full (type), + build_tree_list (NULL_TREE, rhs), + TYPE_BINFO (type), LOOKUP_NORMAL); + + if (init == error_mark_node) + return error_mark_node; + + if (exp == 0) + { + exp = build_cplus_new (type, init, 0); + return exp; + } + + return build (COMPOUND_EXPR, type, init, exp); + } + + /* ??? The following warnings are turned off because + this is another place where the default X(X&) constructor + is implemented. */ + if (TYPE_HAS_ASSIGNMENT (type)) + cp_warning ("bitwise copy: `%T' defines operator=", type); + + if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE) + rhs = convert_from_reference (rhs); + if (type != rhstype) + { + tree nrhs = build1 (NOP_EXPR, type, rhs); + TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs); + rhs = nrhs; + } + return rhs; + } + + return cp_convert (type, rhs, CONV_OLD_CONVERT, flags); + } + + if (type == TREE_TYPE (rhs)) + { + if (TREE_READONLY_DECL_P (rhs)) + rhs = decl_constant_value (rhs); + return rhs; + } + + return convert_for_assignment (type, rhs, errtype, fndecl, parmnum); +} + +/* Expand an ASM statement with operands, handling output operands + that are not variables or INDIRECT_REFS by transforming such + cases into cases that expand_asm_operands can handle. + + Arguments are same as for expand_asm_operands. + + We don't do default conversions on all inputs, because it can screw + up operands that are expected to be in memory. */ + +void +c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line) + tree string, outputs, inputs, clobbers; + int vol; + char *filename; + int line; +{ + int noutputs = list_length (outputs); + register int i; + /* o[I] is the place that output number I should be written. */ + register tree *o = (tree *) alloca (noutputs * sizeof (tree)); + register tree tail; + + /* Record the contents of OUTPUTS before it is modified. */ + for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) + o[i] = TREE_VALUE (tail); + + /* Generate the ASM_OPERANDS insn; + store into the TREE_VALUEs of OUTPUTS some trees for + where the values were actually stored. */ + expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line); + + /* Copy all the intermediate outputs into the specified outputs. */ + for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) + { + if (o[i] != TREE_VALUE (tail)) + { + expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)), + const0_rtx, VOIDmode, 0); + free_temp_slots (); + } + /* Detect modification of read-only values. + (Otherwise done by build_modify_expr.) */ + else + { + tree type = TREE_TYPE (o[i]); + if (TYPE_READONLY (type) + || ((TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE) + && C_TYPE_FIELDS_READONLY (type))) + readonly_error (o[i], "modification by `asm'", 1); + } + } + + /* Those MODIFY_EXPRs could do autoincrements. */ + emit_queue (); +} + +/* Expand a C `return' statement. + RETVAL is the expression for what to return, + or a null pointer for `return;' with no value. + + C++: upon seeing a `return', we must call destructors on all + variables in scope which had constructors called on them. + This means that if in a destructor, the base class destructors + must be called before returning. + + The RETURN statement in C++ has initialization semantics. */ + +void +c_expand_return (retval) + tree retval; +{ + extern struct nesting *cond_stack, *loop_stack, *case_stack; + extern tree dtor_label, ctor_label; + tree result = DECL_RESULT (current_function_decl); + tree valtype = TREE_TYPE (result); + register int use_temp = 0; + int returns_value = 1; + + if (TREE_THIS_VOLATILE (current_function_decl)) + warning ("function declared `noreturn' has a `return' statement"); + + if (retval == error_mark_node) + { + current_function_returns_null = 1; + return; + } + + if (retval == NULL_TREE) + { + /* A non-named return value does not count. */ + + /* Can't just return from a destructor. */ + if (dtor_label) + { + expand_goto (dtor_label); + return; + } + + if (DECL_CONSTRUCTOR_P (current_function_decl)) + retval = current_class_decl; + else if (DECL_NAME (result) != NULL_TREE + && TREE_CODE (valtype) != VOID_TYPE) + retval = result; + else + { + current_function_returns_null = 1; + + if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE) + { + if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE) + { + pedwarn ("`return' with no value, in function returning non-void"); + /* Clear this, so finish_function won't say that we + reach the end of a non-void function (which we don't, + we gave a return!). */ + current_function_returns_null = 0; + } + } + + expand_null_return (); + return; + } + } + else if (DECL_CONSTRUCTOR_P (current_function_decl) + && retval != current_class_decl) + { + error ("return from a constructor: use `this = ...' instead"); + retval = current_class_decl; + } + + if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE) + { + current_function_returns_null = 1; + /* We do this here so we'll avoid a warning about how the function + "may or may not return a value" in finish_function. */ + returns_value = 0; + + if (retval) + pedwarn ("`return' with a value, in function returning void"); + expand_return (retval); + } + /* Add some useful error checking for C++. */ + else if (TREE_CODE (valtype) == REFERENCE_TYPE) + { + tree whats_returned; + tree tmp_result = result; + + /* Don't initialize directly into a non-BLKmode retval, since that + could lose when being inlined by another caller. (GCC can't + read the function return register in an inline function when + the return value is being ignored). */ + if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode) + tmp_result = 0; + + /* convert to reference now, so we can give error if we + return an reference to a non-lvalue. */ + retval = convert_for_initialization (tmp_result, valtype, retval, + LOOKUP_NORMAL, "return", + NULL_TREE, 0); + + /* Sort through common things to see what it is + we are returning. */ + whats_returned = retval; + if (TREE_CODE (whats_returned) == COMPOUND_EXPR) + { + whats_returned = TREE_OPERAND (whats_returned, 1); + if (TREE_CODE (whats_returned) == ADDR_EXPR) + whats_returned = TREE_OPERAND (whats_returned, 0); + } + if (TREE_CODE (whats_returned) == ADDR_EXPR) + { + whats_returned = TREE_OPERAND (whats_returned, 0); + while (TREE_CODE (whats_returned) == NEW_EXPR + || TREE_CODE (whats_returned) == TARGET_EXPR + || TREE_CODE (whats_returned) == WITH_CLEANUP_EXPR) + { + /* Get the target. */ + whats_returned = TREE_OPERAND (whats_returned, 0); + warning ("returning reference to temporary"); + } + } + + if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned)) + { + if (TEMP_NAME_P (DECL_NAME (whats_returned))) + warning ("reference to non-lvalue returned"); + else if (! TREE_STATIC (whats_returned) + && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))) + cp_warning_at ("reference to local variable `%D' returned", whats_returned); + } + } + else if (TREE_CODE (retval) == ADDR_EXPR) + { + tree whats_returned = TREE_OPERAND (retval, 0); + + if (TREE_CODE (whats_returned) == VAR_DECL + && DECL_NAME (whats_returned) + && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned)) + && !TREE_STATIC (whats_returned)) + cp_warning_at ("address of local variable `%D' returned", whats_returned); + } + + /* Now deal with possible C++ hair: + (1) Compute the return value. + (2) If there are aggregate values with destructors which + must be cleaned up, clean them (taking care + not to clobber the return value). + (3) If an X(X&) constructor is defined, the return + value must be returned via that. */ + + /* If we're returning in a register, we can't initialize the + return value from a TARGET_EXPR. */ + if (TREE_CODE (retval) == TARGET_EXPR + && TYPE_MAIN_VARIANT (TREE_TYPE (retval)) == TYPE_MAIN_VARIANT (valtype) + && ! current_function_returns_struct) + retval = expand_target_expr (retval); + + if (retval == result + /* Watch out for constructors, which "return" aggregates + via initialization, but which otherwise "return" a pointer. */ + || DECL_CONSTRUCTOR_P (current_function_decl)) + { + /* This is just an error--it's already been reported. */ + if (TYPE_SIZE (valtype) == NULL_TREE) + return; + + if (TYPE_MODE (valtype) != BLKmode + && any_pending_cleanups (1)) + { + retval = get_temp_regvar (valtype, retval); + use_temp = obey_regdecls; + } + } + else if (IS_AGGR_TYPE (valtype) && current_function_returns_struct) + { + expand_aggr_init (result, retval, 0, LOOKUP_ONLYCONVERTING); + expand_cleanups_to (NULL_TREE); + DECL_INITIAL (result) = NULL_TREE; + retval = 0; + } + else + { + if (TYPE_MODE (valtype) == VOIDmode) + { + if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode + && warn_return_type) + warning ("return of void value in function returning non-void"); + expand_expr_stmt (retval); + retval = 0; + result = 0; + } + else if (TYPE_MODE (valtype) != BLKmode + && any_pending_cleanups (1)) + { + retval = get_temp_regvar (valtype, retval); + expand_cleanups_to (NULL_TREE); + use_temp = obey_regdecls; + result = 0; + } + else + { + retval = convert_for_initialization (result, valtype, retval, + LOOKUP_NORMAL, + "return", NULL_TREE, 0); + DECL_INITIAL (result) = NULL_TREE; + } + if (retval == error_mark_node) + return; + } + + emit_queue (); + + if (retval != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd' + && cond_stack == 0 && loop_stack == 0 && case_stack == 0) + current_function_return_value = retval; + + if (result) + { + /* Everything's great--RETVAL is in RESULT. */ + if (original_result_rtx) + { + store_expr (result, original_result_rtx, 0); + expand_cleanups_to (NULL_TREE); + use_variable (DECL_RTL (result)); + if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK) + expand_goto (ctor_label); + else + expand_null_return (); + } + else if (retval && retval != result) + { + /* Clear this out so the later call to decl_function_context + won't end up bombing on us. */ + if (DECL_CONTEXT (result) == error_mark_node) + DECL_CONTEXT (result) = NULL_TREE; + /* Here is where we finally get RETVAL into RESULT. + `expand_return' does the magic of protecting + RESULT from cleanups. */ + retval = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (result), + retval)); + /* This part _must_ come second, because expand_return looks for + the INIT_EXPR as the toplevel node only. :-( */ + retval = build (INIT_EXPR, TREE_TYPE (result), result, retval); + TREE_SIDE_EFFECTS (retval) = 1; + expand_return (retval); + } + else + expand_return (result); + } + else + { + /* We may still need to put RETVAL into RESULT. */ + result = DECL_RESULT (current_function_decl); + if (original_result_rtx) + { + /* Here we have a named return value that went + into memory. We can compute RETVAL into that. */ + if (retval) + expand_assignment (result, retval, 0, 0); + else + store_expr (result, original_result_rtx, 0); + result = make_tree (TREE_TYPE (result), original_result_rtx); + } + else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK) + { + /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do. */ + expand_goto (ctor_label); + } + else if (retval) + { + /* Here is where we finally get RETVAL into RESULT. + `expand_return' does the magic of protecting + RESULT from cleanups. */ + result = build (INIT_EXPR, TREE_TYPE (result), result, retval); + TREE_SIDE_EFFECTS (result) = 1; + expand_return (result); + } + else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode) + expand_return (result); + } + + current_function_returns_value = returns_value; +#if 0 + /* These wind up after the BARRIER, which causes problems for + expand_end_binding. What purpose were they supposed to serve? */ + if (original_result_rtx) + use_variable (original_result_rtx); + if (use_temp) + use_variable (DECL_RTL (DECL_RESULT (current_function_decl))); +#endif + + /* One way to clear out cleanups that EXPR might + generate. Note that this code will really be + dead code, but that is ok--cleanups that were + needed were handled by the magic of `return'. */ + expand_cleanups_to (NULL_TREE); +} + +/* Start a C switch statement, testing expression EXP. + Return EXP if it is valid, an error node otherwise. */ + +tree +c_expand_start_case (exp) + tree exp; +{ + tree type; + register enum tree_code code; + + /* Convert from references, etc. */ + exp = default_conversion (exp); + type = TREE_TYPE (exp); + code = TREE_CODE (type); + + if (IS_AGGR_TYPE_CODE (code)) + exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1); + + if (exp == NULL_TREE) + { + error ("switch quantity not an integer"); + exp = error_mark_node; + } + type = TREE_TYPE (exp); + code = TREE_CODE (type); + + if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK) + { + error ("switch quantity not an integer"); + exp = error_mark_node; + } + else + { + tree index; + + exp = default_conversion (exp); + type = TREE_TYPE (exp); + index = get_unwidened (exp, 0); + /* We can't strip a conversion from a signed type to an unsigned, + because if we did, int_fits_type_p would do the wrong thing + when checking case values for being in range, + and it's too hard to do the right thing. */ + if (TREE_UNSIGNED (TREE_TYPE (exp)) + == TREE_UNSIGNED (TREE_TYPE (index))) + exp = index; + } + + expand_start_case + (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)), + type, "switch statement"); + + return exp; +} + +/* CONSTP remembers whether or not all the intervening pointers in the `to' + type have been const. */ +int +comp_ptr_ttypes_real (to, from, constp) + tree to, from; + int constp; +{ + for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from)) + { + if (TREE_CODE (to) != TREE_CODE (from)) + return 0; + + /* Const and volatile mean something different for function types, + so the usual checks are not appropriate. */ + if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE) + { + if (TYPE_READONLY (from) > TYPE_READONLY (to) + || TYPE_VOLATILE (from) > TYPE_VOLATILE (to)) + return 0; + + if (! constp + && (TYPE_READONLY (to) > TYPE_READONLY (from) + || TYPE_VOLATILE (to) > TYPE_READONLY (from))) + return 0; + constp &= TYPE_READONLY (to); + } + + if (TREE_CODE (to) != POINTER_TYPE) + return comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1); + } +} + +/* When comparing, say, char ** to char const **, this function takes the + 'char *' and 'char const *'. Do not pass non-pointer types to this + function. */ +int +comp_ptr_ttypes (to, from) + tree to, from; +{ + return comp_ptr_ttypes_real (to, from, 1); +} diff --git a/contrib/gcc/cp/typeck2.c b/contrib/gcc/cp/typeck2.c new file mode 100644 index 00000000000..653d6a54dc5 --- /dev/null +++ b/contrib/gcc/cp/typeck2.c @@ -0,0 +1,1681 @@ +/* Report error messages, build initializers, and perform + some front-end optimizations for C++ compiler. + Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Hacked by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* This file is part of the C++ front end. + It contains routines to build C++ expressions given their operands, + including computing the types of the result, C and C++ specific error + checks, and some optimization. + + There are also routines to build RETURN_STMT nodes and CASE_STMT nodes, + and to process initializations in declarations (since they work + like a strange sort of assignment). */ + +#include "config.h" +#include +#include "tree.h" +#include "cp-tree.h" +#include "flags.h" + +static tree process_init_constructor (); +extern void pedwarn (), error (); + +extern int errorcount; +extern int sorrycount; + +/* Print an error message stemming from an attempt to use + BASETYPE as a base class for TYPE. */ +tree +error_not_base_type (basetype, type) + tree basetype, type; +{ + if (TREE_CODE (basetype) == FUNCTION_DECL) + basetype = DECL_CLASS_CONTEXT (basetype); + cp_error ("type `%T' is not a base type for type `%T'", basetype, type); + return error_mark_node; +} + +tree +binfo_or_else (parent_or_type, type) + tree parent_or_type, type; +{ + tree binfo; + if (TYPE_MAIN_VARIANT (parent_or_type) == TYPE_MAIN_VARIANT (type)) + return TYPE_BINFO (parent_or_type); + if ((binfo = get_binfo (parent_or_type, TYPE_MAIN_VARIANT (type), 0))) + { + if (binfo == error_mark_node) + return NULL_TREE; + return binfo; + } + error_not_base_type (parent_or_type, type); + return NULL_TREE; +} + +/* Print an error message stemming from an invalid use of an + aggregate type. + + TYPE is the type or binfo which draws the error. + MSG is the message to print. + ARG is an optional argument which may provide more information. */ +void +error_with_aggr_type (type, msg, arg) + tree type; + char *msg; + HOST_WIDE_INT arg; +{ + tree name; + + if (TREE_CODE (type) == TREE_VEC) + type = BINFO_TYPE (type); + + name = TYPE_NAME (type); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + error (msg, IDENTIFIER_POINTER (name), arg); +} + +/* According to ARM $7.1.6, "A `const' object may be initialized, but its + value may not be changed thereafter. Thus, we emit hard errors for these, + rather than just pedwarns. If `SOFT' is 1, then we just pedwarn. (For + example, conversions to references.) */ +void +readonly_error (arg, string, soft) + tree arg; + char *string; + int soft; +{ + char *fmt; + void (*fn)(); + + if (soft) + fn = pedwarn; + else + fn = error; + + if (TREE_CODE (arg) == COMPONENT_REF) + { + if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0)))) + fmt = "%s of member `%s' in read-only structure"; + else + fmt = "%s of read-only member `%s'"; + (*fn) (fmt, string, lang_printable_name (TREE_OPERAND (arg, 1))); + } + else if (TREE_CODE (arg) == VAR_DECL) + { + if (DECL_LANG_SPECIFIC (arg) + && DECL_IN_AGGR_P (arg) + && !TREE_STATIC (arg)) + fmt = "%s of constant field `%s'"; + else + fmt = "%s of read-only variable `%s'"; + (*fn) (fmt, string, lang_printable_name (arg)); + } + else if (TREE_CODE (arg) == PARM_DECL) + (*fn) ("%s of read-only parameter `%s'", string, + lang_printable_name (arg)); + else if (TREE_CODE (arg) == INDIRECT_REF + && TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))) == REFERENCE_TYPE + && (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL + || TREE_CODE (TREE_OPERAND (arg, 0)) == PARM_DECL)) + (*fn) ("%s of read-only reference `%s'", + string, lang_printable_name (TREE_OPERAND (arg, 0))); + else if (TREE_CODE (arg) == RESULT_DECL) + (*fn) ("%s of read-only named return value `%s'", + string, lang_printable_name (arg)); + else + (*fn) ("%s of read-only location", string); +} + +/* Print an error message for invalid use of a type which declares + virtual functions which are not inheritable. */ +void +abstract_virtuals_error (decl, type) + tree decl; + tree type; +{ + tree u = CLASSTYPE_ABSTRACT_VIRTUALS (type); + + if (decl) + { + if (TREE_CODE (decl) == RESULT_DECL) + return; + + if (TREE_CODE (decl) == VAR_DECL) + cp_error ("cannot declare variable `%D' to be of type `%T'", + decl, type); + else if (TREE_CODE (decl) == PARM_DECL) + cp_error ("cannot declare parameter `%D' to be of type `%T'", + decl, type); + else if (TREE_CODE (decl) == FIELD_DECL) + cp_error ("cannot declare field `%D' to be of type `%T'", + decl, type); + else if (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) + cp_error ("invalid return type for method `%#D'", decl); + else if (TREE_CODE (decl) == FUNCTION_DECL) + cp_error ("invalid return type for function `%#D'", decl); + } + else cp_error ("cannot allocate an object of type `%T'", type); + /* Only go through this once. */ + if (TREE_PURPOSE (u) == NULL_TREE) + { + error (" since the following virtual functions are abstract:"); + TREE_PURPOSE (u) = error_mark_node; + while (u) + { + cp_error ("\t%#D", TREE_VALUE (u)); + u = TREE_CHAIN (u); + } + } + else cp_error (" since type `%T' has abstract virtual functions", type); +} + +/* Print an error message for invalid use of a signature type. + Signatures are treated similar to abstract classes here, they + cannot be instantiated. */ +void +signature_error (decl, type) + tree decl; + tree type; +{ + if (decl) + { + if (TREE_CODE (decl) == RESULT_DECL) + return; + + if (TREE_CODE (decl) == VAR_DECL) + cp_error ("cannot declare variable `%D' to be of signature type `%T'", + decl, type); + else if (TREE_CODE (decl) == PARM_DECL) + cp_error ("cannot declare parameter `%D' to be of signature type `%T'", + decl, type); + else if (TREE_CODE (decl) == FIELD_DECL) + cp_error ("cannot declare field `%D' to be of signature type `%T'", + decl, type); + else if (TREE_CODE (decl) == FUNCTION_DECL + && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) + cp_error ("invalid return type for method `%#D'", decl); + else if (TREE_CODE (decl) == FUNCTION_DECL) + cp_error ("invalid return type for function `%#D'", decl); + } + else + cp_error ("cannot allocate an object of signature type `%T'", type); +} + +/* Print an error message for invalid use of an incomplete type. + VALUE is the expression that was used (or 0 if that isn't known) + and TYPE is the type that was invalid. */ + +void +incomplete_type_error (value, type) + tree value; + tree type; +{ + char *errmsg; + + /* Avoid duplicate error message. */ + if (TREE_CODE (type) == ERROR_MARK) + return; + + if (value != 0 && (TREE_CODE (value) == VAR_DECL + || TREE_CODE (value) == PARM_DECL)) + error ("`%s' has an incomplete type", + IDENTIFIER_POINTER (DECL_NAME (value))); + else + { + retry: + /* We must print an error message. Be clever about what it says. */ + + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + errmsg = "invalid use of undefined type `struct %s'"; + break; + + case UNION_TYPE: + errmsg = "invalid use of undefined type `union %s'"; + break; + + case ENUMERAL_TYPE: + errmsg = "invalid use of undefined type `enum %s'"; + break; + + case VOID_TYPE: + error ("invalid use of void expression"); + return; + + case ARRAY_TYPE: + if (TYPE_DOMAIN (type)) + { + type = TREE_TYPE (type); + goto retry; + } + error ("invalid use of array with unspecified bounds"); + return; + + case OFFSET_TYPE: + error ("invalid use of member type (did you forget the `&' ?)"); + return; + + default: + my_friendly_abort (108); + } + + error_with_aggr_type (type, errmsg); + } +} + +/* Like error(), but don't call report_error_function(). */ +static void +ack (s, v, v2) + char *s; + HOST_WIDE_INT v; + HOST_WIDE_INT v2; +{ + extern char * progname; + + if (input_filename) + fprintf (stderr, "%s:%d: ", input_filename, lineno); + else + fprintf (stderr, "%s: ", progname); + + fprintf (stderr, s, v, v2); + fprintf (stderr, "\n"); +} + +/* There are times when the compiler can get very confused, confused + to the point of giving up by aborting, simply because of previous + input errors. It is much better to have the user go back and + correct those errors first, and see if it makes us happier, than it + is to abort on him. This is because when one has a 10,000 line + program, and the compiler comes back with ``core dump'', the user + is left not knowing even where to begin to fix things and no place + to even try and work around things. + + The parameter is to uniquely identify the problem to the user, so + that they can say, I am having problem 59, and know that fix 7 will + probably solve their problem. Or, we can document what problem + 59 is, so they can understand how to work around it, should they + ever run into it. + + Note, there will be no more calls in the C++ front end to abort, + because the C++ front end is so unreliable still. The C front end + can get away with calling abort, because for most of the calls to + abort on most machines, it, I suspect, can be proven that it is + impossible to ever call abort. The same is not yet true for C++, + one day, maybe it will be. + + We used to tell people to "fix the above error[s] and try recompiling + the program" via a call to fatal, but that message tended to look + silly. So instead, we just do the equivalent of a call to fatal in the + same situation (call exit). */ + +/* First used: 0 (reserved), Last used: 366. Free: */ + +static int abortcount = 0; + +void +my_friendly_abort (i) + int i; +{ + /* if the previous error came through here, i.e. report_error_function + ended up calling us again, don't just exit; we want a diagnostic of + some kind. */ + if (abortcount == 1) + current_function_decl = NULL_TREE; + else if (errorcount > 0 || sorrycount > 0) + { + if (abortcount > 1) + { + if (i == 0) + ack ("Internal compiler error."); + else + ack ("Internal compiler error %d.", i); + ack ("Please submit a full bug report to `bug-g++@prep.ai.mit.edu'."); + } + else + error ("confused by earlier errors, bailing out"); + + exit (34); + } + ++abortcount; + + if (i == 0) + error ("Internal compiler error."); + else + error ("Internal compiler error %d.", i); + + fatal ("Please submit a full bug report to `bug-g++@prep.ai.mit.edu'."); +} + +void +my_friendly_assert (cond, where) + int cond, where; +{ + if (cond == 0) + my_friendly_abort (where); +} + +/* Return nonzero if VALUE is a valid constant-valued expression + for use in initializing a static variable; one that can be an + element of a "constant" initializer. + + Return null_pointer_node if the value is absolute; + if it is relocatable, return the variable that determines the relocation. + We assume that VALUE has been folded as much as possible; + therefore, we do not need to check for such things as + arithmetic-combinations of integers. */ + +tree +initializer_constant_valid_p (value, endtype) + tree value; + tree endtype; +{ + switch (TREE_CODE (value)) + { + case CONSTRUCTOR: + if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE + && TREE_CONSTANT (value)) + return + initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)), + endtype); + + return TREE_STATIC (value) ? null_pointer_node : 0; + + case INTEGER_CST: + case REAL_CST: + case STRING_CST: + case COMPLEX_CST: + return null_pointer_node; + + case ADDR_EXPR: + return TREE_OPERAND (value, 0); + + case NON_LVALUE_EXPR: + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + case CONVERT_EXPR: + case NOP_EXPR: + /* Allow conversions between pointer types. */ + if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow conversions between real types. */ + if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow length-preserving conversions between integer types. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); + + /* Allow conversions between other integer types only if + explicit value. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE) + { + tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + if (inner == null_pointer_node) + return null_pointer_node; + return 0; + } + + /* Allow (int) &foo provided int is as wide as a pointer. */ + if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + + /* Likewise conversions from int to pointers. */ + if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE + && (TYPE_PRECISION (TREE_TYPE (value)) + <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + + /* Allow conversions to union types if the value inside is okay. */ + if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE) + return initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + return 0; + + case PLUS_EXPR: + if (TREE_CODE (endtype) == INTEGER_TYPE + && TYPE_PRECISION (endtype) < POINTER_SIZE) + return 0; + { + tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), + endtype); + /* If either term is absolute, use the other terms relocation. */ + if (valid0 == null_pointer_node) + return valid1; + if (valid1 == null_pointer_node) + return valid0; + return 0; + } + + case MINUS_EXPR: + if (TREE_CODE (endtype) == INTEGER_TYPE + && TYPE_PRECISION (endtype) < POINTER_SIZE) + return 0; + { + tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), + endtype); + tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), + endtype); + /* Win if second argument is absolute. */ + if (valid1 == null_pointer_node) + return valid0; + /* Win if both arguments have the same relocation. + Then the value is absolute. */ + if (valid0 == valid1) + return null_pointer_node; + return 0; + } + } + + return 0; +} + +/* Perform appropriate conversions on the initial value of a variable, + store it in the declaration DECL, + and print any error messages that are appropriate. + If the init is invalid, store an ERROR_MARK. + + C++: Note that INIT might be a TREE_LIST, which would mean that it is + a base class initializer for some aggregate type, hopefully compatible + with DECL. If INIT is a single element, and DECL is an aggregate + type, we silently convert INIT into a TREE_LIST, allowing a constructor + to be called. + + If INIT is a TREE_LIST and there is no constructor, turn INIT + into a CONSTRUCTOR and use standard initialization techniques. + Perhaps a warning should be generated? + + Returns value of initializer if initialization could not be + performed for static variable. In that case, caller must do + the storing. */ + +tree +store_init_value (decl, init) + tree decl, init; +{ + register tree value, type; + + /* If variable's type was invalidly declared, just ignore it. */ + + type = TREE_TYPE (decl); + if (TREE_CODE (type) == ERROR_MARK) + return NULL_TREE; + +#if 0 + /* This breaks arrays, and should not have any effect for other decls. */ + /* Take care of C++ business up here. */ + type = TYPE_MAIN_VARIANT (type); +#endif + + if (IS_AGGR_TYPE (type)) + { + if (! TYPE_HAS_TRIVIAL_INIT_REF (type) + && TREE_CODE (init) != CONSTRUCTOR) + my_friendly_abort (109); + + /* Although we are not allowed to declare variables of signature + type, we complain about a possible constructor call in such a + declaration as well. */ + if (TREE_CODE (init) == TREE_LIST + && IS_SIGNATURE (type)) + { + cp_error ("constructor syntax cannot be used with signature type `%T'", + type); + init = error_mark_node; + } + else if (TREE_CODE (init) == TREE_LIST) + { + cp_error ("constructor syntax used, but no constructor declared for type `%T'", type); + init = build_nt (CONSTRUCTOR, NULL_TREE, nreverse (init)); + } +#if 0 + if (TREE_CODE (init) == CONSTRUCTOR) + { + tree field; + tree funcs; + int func; + + /* Check that we're really an aggregate as ARM 8.4.1 defines it. */ + if (CLASSTYPE_N_BASECLASSES (type)) + cp_error_at ("initializer list construction invalid for derived class object `%D'", decl); + if (CLASSTYPE_VTBL_PTR (type)) + cp_error_at ("initializer list construction invalid for polymorphic class object `%D'", decl); + if (TYPE_NEEDS_CONSTRUCTING (type)) + { + cp_error_at ("initializer list construction invalid for `%D'", decl); + error ("due to the presence of a constructor"); + } + for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field)) + if (TREE_PRIVATE (field) || TREE_PROTECTED (field)) + { + cp_error_at ("initializer list construction invalid for `%D'", decl); + cp_error_at ("due to non-public access of member `%D'", field); + } + funcs = TYPE_METHODS (type); + if (funcs) + for (func = 0; func < TREE_VEC_LENGTH (funcs); func++) + { + field = TREE_VEC_ELT (funcs, func); + if (field && (TREE_PRIVATE (field) || TREE_PROTECTED (field))) + { + cp_error_at ("initializer list construction invalid for `%D'", decl); + cp_error_at ("due to non-public access of member `%D'", field); + } + } + } +#endif + } + else if (TREE_CODE (init) == TREE_LIST + && TREE_TYPE (init) != unknown_type_node) + { + if (TREE_CODE (decl) == RESULT_DECL) + { + if (TREE_CHAIN (init)) + { + warning ("comma expression used to initialize return value"); + init = build_compound_expr (init); + } + else + init = TREE_VALUE (init); + } + else if (TREE_TYPE (init) != 0 + && TREE_CODE (TREE_TYPE (init)) == OFFSET_TYPE) + { + /* Use the type of our variable to instantiate + the type of our initializer. */ + init = instantiate_type (type, init, 1); + } + else if (TREE_CODE (init) == TREE_LIST + && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) + { + error ("cannot initialize arrays using this syntax"); + return NULL_TREE; + } + else + { + /* We get here with code like `int a (2);' */ + + if (TREE_CHAIN (init) != NULL_TREE) + { + pedwarn ("initializer list being treated as compound expression"); + init = build_compound_expr (init); + } + else + init = TREE_VALUE (init); + } + } + + /* End of special C++ code. */ + + /* Digest the specified initializer into an expression. */ + + value = digest_init (type, init, (tree *) 0); + + /* Store the expression if valid; else report error. */ + + if (TREE_CODE (value) == ERROR_MARK) + ; + else if (TREE_STATIC (decl) + && (! TREE_CONSTANT (value) + || ! initializer_constant_valid_p (value, TREE_TYPE (value)) +#if 0 + /* A STATIC PUBLIC int variable doesn't have to be + run time inited when doing pic. (mrs) */ + /* Since ctors and dtors are the only things that can + reference vtables, and they are always written down + the the vtable definition, we can leave the + vtables in initialized data space. + However, other initialized data cannot be initialized + this way. Instead a global file-level initializer + must do the job. */ + || (flag_pic && !DECL_VIRTUAL_P (decl) && TREE_PUBLIC (decl)) +#endif + )) + + return value; +#if 0 /* No, that's C. jason 9/19/94 */ + else + { + if (pedantic && TREE_CODE (value) == CONSTRUCTOR + /* Don't complain about non-constant initializers of + signature tables and signature pointers/references. */ + && ! (TYPE_LANG_SPECIFIC (type) + && (IS_SIGNATURE (type) + || IS_SIGNATURE_POINTER (type) + || IS_SIGNATURE_REFERENCE (type)))) + { + if (! TREE_CONSTANT (value) || ! TREE_STATIC (value)) + pedwarn ("ANSI C++ forbids non-constant aggregate initializer expressions"); + } + } +#endif + DECL_INITIAL (decl) = value; + return NULL_TREE; +} + +/* Digest the parser output INIT as an initializer for type TYPE. + Return a C expression of type TYPE to represent the initial value. + + If TAIL is nonzero, it points to a variable holding a list of elements + of which INIT is the first. We update the list stored there by + removing from the head all the elements that we use. + Normally this is only one; we use more than one element only if + TYPE is an aggregate and INIT is not a constructor. */ + +tree +digest_init (type, init, tail) + tree type, init, *tail; +{ + enum tree_code code = TREE_CODE (type); + tree element = NULL_TREE; + tree old_tail_contents; + /* Nonzero if INIT is a braced grouping, which comes in as a CONSTRUCTOR + tree node which has no TREE_TYPE. */ + int raw_constructor; + + /* By default, assume we use one element from a list. + We correct this later in the sole case where it is not true. */ + + if (tail) + { + old_tail_contents = *tail; + *tail = TREE_CHAIN (*tail); + } + + if (init == error_mark_node || (TREE_CODE (init) == TREE_LIST + && TREE_VALUE (init) == error_mark_node)) + return error_mark_node; + + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + if (TREE_CODE (init) == NON_LVALUE_EXPR) + init = TREE_OPERAND (init, 0); + + if (init && TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (type)) + init = default_conversion (init); + + if (init && TYPE_PTRMEMFUNC_P (type) + && ((TREE_CODE (init) == ADDR_EXPR + && ((TREE_CODE (TREE_TYPE (init)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_TYPE (init))) == METHOD_TYPE) + || TREE_CODE (TREE_OPERAND (init, 0)) == TREE_LIST)) + || TREE_CODE (init) == TREE_LIST + || integer_zerop (init) + || (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init))))) + { + return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), init, 0); + } + + raw_constructor = TREE_CODE (init) == CONSTRUCTOR && TREE_TYPE (init) == 0; + + if (init && raw_constructor + && CONSTRUCTOR_ELTS (init) != 0 + && TREE_CHAIN (CONSTRUCTOR_ELTS (init)) == 0) + { + element = TREE_VALUE (CONSTRUCTOR_ELTS (init)); + /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ + if (element && TREE_CODE (element) == NON_LVALUE_EXPR) + element = TREE_OPERAND (element, 0); + if (element == error_mark_node) + return element; + } + + /* Any type can be initialized from an expression of the same type, + optionally with braces. */ + + if (init && TREE_TYPE (init) + && (TYPE_MAIN_VARIANT (TREE_TYPE (init)) == type + || (code == ARRAY_TYPE && comptypes (TREE_TYPE (init), type, 1)))) + { + if (pedantic && code == ARRAY_TYPE + && TREE_CODE (init) != STRING_CST) + pedwarn ("ANSI C++ forbids initializing array from array expression"); + if (TREE_CODE (init) == CONST_DECL) + init = DECL_INITIAL (init); + else if (TREE_READONLY_DECL_P (init)) + init = decl_constant_value (init); + return init; + } + + if (element && (TREE_TYPE (element) == type + || (code == ARRAY_TYPE && TREE_TYPE (element) + && comptypes (TREE_TYPE (element), type, 1)))) + { + if (pedantic && code == ARRAY_TYPE) + pedwarn ("ANSI C++ forbids initializing array from array expression"); + if (pedantic && (code == RECORD_TYPE || code == UNION_TYPE)) + pedwarn ("ANSI C++ forbids single nonscalar initializer with braces"); + if (TREE_CODE (element) == CONST_DECL) + element = DECL_INITIAL (element); + else if (TREE_READONLY_DECL_P (element)) + element = decl_constant_value (element); + return element; + } + + /* Initialization of an array of chars from a string constant + optionally enclosed in braces. */ + + if (code == ARRAY_TYPE) + { + tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + if ((typ1 == char_type_node + || typ1 == signed_char_type_node + || typ1 == unsigned_char_type_node + || typ1 == unsigned_wchar_type_node + || typ1 == signed_wchar_type_node) + && ((init && TREE_CODE (init) == STRING_CST) + || (element && TREE_CODE (element) == STRING_CST))) + { + tree string = element ? element : init; + + if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string))) + != char_type_node) + && TYPE_PRECISION (typ1) == BITS_PER_UNIT) + { + error ("char-array initialized from wide string"); + return error_mark_node; + } + if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (string))) + == char_type_node) + && TYPE_PRECISION (typ1) != BITS_PER_UNIT) + { + error ("int-array initialized from non-wide string"); + return error_mark_node; + } + + if (pedantic + && typ1 != char_type_node + && typ1 != signed_char_type_node + && typ1 != unsigned_char_type_node) + pedwarn ("ANSI C++ forbids string initializer except for `char' elements"); + TREE_TYPE (string) = type; + if (TYPE_DOMAIN (type) != 0 + && TREE_CONSTANT (TYPE_SIZE (type))) + { + register int size + = TREE_INT_CST_LOW (TYPE_SIZE (type)); + size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT; + /* In C it is ok to subtract 1 from the length of the string + because it's ok to ignore the terminating null char that is + counted in the length of the constant, but in C++ this would + be invalid. */ + if (size < TREE_STRING_LENGTH (string)) + pedwarn ("initializer-string for array of chars is too long"); + } + return string; + } + } + + /* Handle scalar types, including conversions, + and signature pointers and references. */ + + if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE + || code == ENUMERAL_TYPE || code == REFERENCE_TYPE + || code == BOOLEAN_TYPE + || (code == RECORD_TYPE && ! raw_constructor + && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))) + { + if (raw_constructor) + { + if (element == 0) + { + error ("initializer for scalar variable requires one element"); + return error_mark_node; + } + init = element; + } + while (TREE_CODE (init) == CONSTRUCTOR) + { + cp_pedwarn ("braces around scalar initializer for `%T'", type); + init = CONSTRUCTOR_ELTS (init); + if (TREE_CHAIN (init)) + cp_pedwarn ("ignoring extra initializers for `%T'", type); + init = TREE_VALUE (init); + } + + return convert_for_initialization (0, type, init, LOOKUP_NORMAL, + "initialization", NULL_TREE, 0); + } + + /* Come here only for records and arrays (and unions with constructors). */ + + if (TYPE_SIZE (type) && ! TREE_CONSTANT (TYPE_SIZE (type))) + { + cp_error ("variable-sized object of type `%T' may not be initialized", + type); + return error_mark_node; + } + + if (code == ARRAY_TYPE || code == RECORD_TYPE || code == UNION_TYPE) + { + if (raw_constructor && TYPE_NON_AGGREGATE_CLASS (type)) + { + cp_error ("subobject of type `%T' must be initialized by constructor, not by `%E'", + type, init); + return error_mark_node; + } + else if (raw_constructor) + return process_init_constructor (type, init, (tree *)0); + else if (TYPE_NON_AGGREGATE_CLASS (type)) + { + /* This can only be reached when caller is initializing + ARRAY_TYPE. In that case, we don't want to convert + INIT to TYPE. We will let `expand_vec_init' do it. */ + return init; + } + else if (tail != 0) + { + *tail = old_tail_contents; + return process_init_constructor (type, 0, tail); + } + else if (flag_traditional) + /* Traditionally one can say `char x[100] = 0;'. */ + return process_init_constructor (type, + build_nt (CONSTRUCTOR, 0, + tree_cons (0, init, 0)), + 0); + if (code != ARRAY_TYPE) + return convert_for_initialization (0, type, init, LOOKUP_NORMAL, + "initialization", NULL_TREE, 0); + } + + error ("invalid initializer"); + return error_mark_node; +} + +/* Process a constructor for a variable of type TYPE. + The constructor elements may be specified either with INIT or with ELTS, + only one of which should be non-null. + + If INIT is specified, it is a CONSTRUCTOR node which is specifically + and solely for initializing this datum. + + If ELTS is specified, it is the address of a variable containing + a list of expressions. We take as many elements as we need + from the head of the list and update the list. + + In the resulting constructor, TREE_CONSTANT is set if all elts are + constant, and TREE_STATIC is set if, in addition, all elts are simple enough + constants that the assembler and linker can compute them. */ + +static tree +process_init_constructor (type, init, elts) + tree type, init, *elts; +{ + register tree tail; + /* List of the elements of the result constructor, + in reverse order. */ + register tree members = NULL; + tree result; + int allconstant = 1; + int allsimple = 1; + int erroneous = 0; + + /* Make TAIL be the list of elements to use for the initialization, + no matter how the data was given to us. */ + + if (elts) + { + if (warn_missing_braces) + warning ("aggregate has a partly bracketed initializer"); + tail = *elts; + } + else + tail = CONSTRUCTOR_ELTS (init); + + /* Gobble as many elements as needed, and make a constructor or initial value + for each element of this aggregate. Chain them together in result. + If there are too few, use 0 for each scalar ultimate component. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + tree domain = TYPE_DOMAIN (type); + register long len; + register int i; + + if (domain) + len = (TREE_INT_CST_LOW (TYPE_MAX_VALUE (domain)) + - TREE_INT_CST_LOW (TYPE_MIN_VALUE (domain)) + + 1); + else + len = -1; /* Take as many as there are */ + + for (i = 0; (len < 0 || i < len) && tail != 0; i++) + { + register tree next1; + + if (TREE_VALUE (tail) != 0) + { + tree tail1 = tail; + next1 = digest_init (TYPE_MAIN_VARIANT (TREE_TYPE (type)), + TREE_VALUE (tail), &tail1); + if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)) + && TYPE_MAIN_VARIANT (TREE_TYPE (type)) != TYPE_MAIN_VARIANT (TREE_TYPE (next1))) + { + /* The fact this needs to be done suggests this code needs + to be totally rewritten. */ + next1 = convert_for_initialization (NULL_TREE, TREE_TYPE (type), next1, LOOKUP_NORMAL, "initialization", NULL_TREE, 0); + } + my_friendly_assert (tail1 == 0 + || TREE_CODE (tail1) == TREE_LIST, 319); + if (tail == tail1 && len < 0) + { + error ("non-empty initializer for array of empty elements"); + /* Just ignore what we were supposed to use. */ + tail1 = NULL_TREE; + } + tail = tail1; + } + else + { + next1 = error_mark_node; + tail = TREE_CHAIN (tail); + } + + if (next1 == error_mark_node) + erroneous = 1; + else if (!TREE_CONSTANT (next1)) + allconstant = 0; + else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1))) + allsimple = 0; + members = tree_cons (NULL_TREE, next1, members); + } + } + if (TREE_CODE (type) == RECORD_TYPE) + { + register tree field; + + if (tail) + { + if (TYPE_USES_VIRTUAL_BASECLASSES (type)) + { + sorry ("initializer list for object of class with virtual baseclasses"); + return error_mark_node; + } + + if (TYPE_BINFO_BASETYPES (type)) + { + sorry ("initializer list for object of class with baseclasses"); + return error_mark_node; + } + + if (TYPE_VIRTUAL_P (type)) + { + sorry ("initializer list for object using virtual functions"); + return error_mark_node; + } + } + + for (field = TYPE_FIELDS (type); field && tail; + field = TREE_CHAIN (field)) + { + register tree next1; + + if (! DECL_NAME (field)) + { + members = tree_cons (field, integer_zero_node, members); + continue; + } + + if (TREE_CODE (field) != FIELD_DECL) + continue; + + if (TREE_VALUE (tail) != 0) + { + tree tail1 = tail; + + next1 = digest_init (TREE_TYPE (field), + TREE_VALUE (tail), &tail1); + my_friendly_assert (tail1 == 0 + || TREE_CODE (tail1) == TREE_LIST, 320); + tail = tail1; + } + else + { + next1 = error_mark_node; + tail = TREE_CHAIN (tail); + } + + if (next1 == error_mark_node) + erroneous = 1; + else if (!TREE_CONSTANT (next1)) + allconstant = 0; + else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1))) + allsimple = 0; + members = tree_cons (field, next1, members); + } + for (; field; field = TREE_CHAIN (field)) + { + if (TREE_CODE (field) != FIELD_DECL) + continue; + + /* Does this field have a default initialization? */ + if (DECL_INITIAL (field)) + { + register tree next1 = DECL_INITIAL (field); + if (TREE_CODE (next1) == ERROR_MARK) + erroneous = 1; + else if (!TREE_CONSTANT (next1)) + allconstant = 0; + else if (! initializer_constant_valid_p (next1, TREE_TYPE (next1))) + allsimple = 0; + members = tree_cons (field, next1, members); + } + else if (TREE_READONLY (field)) + error ("uninitialized const member `%s'", + IDENTIFIER_POINTER (DECL_NAME (field))); + else if (TYPE_LANG_SPECIFIC (TREE_TYPE (field)) + && CLASSTYPE_READONLY_FIELDS_NEED_INIT (TREE_TYPE (field))) + error ("member `%s' with uninitialized const fields", + IDENTIFIER_POINTER (DECL_NAME (field))); + else if (TREE_CODE (TREE_TYPE (field)) == REFERENCE_TYPE) + error ("member `%s' is uninitialized reference", + IDENTIFIER_POINTER (DECL_NAME (field))); + } + } + + if (TREE_CODE (type) == UNION_TYPE) + { + register tree field = TYPE_FIELDS (type); + register tree next1; + + /* Find the first named field. ANSI decided in September 1990 + that only named fields count here. */ + while (field && DECL_NAME (field) == 0) + field = TREE_CHAIN (field); + + /* If this element specifies a field, initialize via that field. */ + if (TREE_PURPOSE (tail) != NULL_TREE) + { + int win = 0; + + if (TREE_CODE (TREE_PURPOSE (tail)) == FIELD_DECL) + /* Handle the case of a call by build_c_cast. */ + field = TREE_PURPOSE (tail), win = 1; + else if (TREE_CODE (TREE_PURPOSE (tail)) != IDENTIFIER_NODE) + error ("index value instead of field name in union initializer"); + else + { + tree temp; + for (temp = TYPE_FIELDS (type); + temp; + temp = TREE_CHAIN (temp)) + if (DECL_NAME (temp) == TREE_PURPOSE (tail)) + break; + if (temp) + field = temp, win = 1; + else + error ("no field `%s' in union being initialized", + IDENTIFIER_POINTER (TREE_PURPOSE (tail))); + } + if (!win) + TREE_VALUE (tail) = error_mark_node; + } + else if (field == 0) + { + cp_error ("union `%T' with no named members cannot be initialized", + type); + TREE_VALUE (tail) = error_mark_node; + } + + if (TREE_VALUE (tail) != 0) + { + tree tail1 = tail; + + next1 = digest_init (TREE_TYPE (field), + TREE_VALUE (tail), &tail1); + if (tail1 != 0 && TREE_CODE (tail1) != TREE_LIST) + my_friendly_abort (357); + tail = tail1; + } + else + { + next1 = error_mark_node; + tail = TREE_CHAIN (tail); + } + + if (next1 == error_mark_node) + erroneous = 1; + else if (!TREE_CONSTANT (next1)) + allconstant = 0; + else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0) + allsimple = 0; + members = tree_cons (field, next1, members); + } + + /* If arguments were specified as a list, just remove the ones we used. */ + if (elts) + *elts = tail; + /* If arguments were specified as a constructor, + complain unless we used all the elements of the constructor. */ + else if (tail) + pedwarn ("excess elements in aggregate initializer"); + + if (erroneous) + return error_mark_node; + + result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members)); + if (init) + TREE_HAS_CONSTRUCTOR (result) = TREE_HAS_CONSTRUCTOR (init); + if (allconstant) TREE_CONSTANT (result) = 1; + if (allconstant && allsimple) TREE_STATIC (result) = 1; + return result; +} + +/* Given a structure or union value DATUM, construct and return + the structure or union component which results from narrowing + that value by the types specified in TYPES. For example, given the + hierarchy + + class L { int ii; }; + class A : L { ... }; + class B : L { ... }; + class C : A, B { ... }; + + and the declaration + + C x; + + then the expression + + x::C::A::L::ii refers to the ii member of the L part of + of A part of the C object named by X. In this case, + DATUM would be x, and TYPES would be a SCOPE_REF consisting of + + SCOPE_REF + SCOPE_REF + C A + L + + The last entry in the SCOPE_REF is always an IDENTIFIER_NODE. + +*/ + +tree +build_scoped_ref (datum, types) + tree datum; + tree types; +{ + tree ref; + tree type = TREE_TYPE (datum); + + if (datum == error_mark_node) + return error_mark_node; + + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + type = TYPE_MAIN_VARIANT (type); + + if (TREE_CODE (types) == SCOPE_REF) + { + /* We have some work to do. */ + struct type_chain + { tree type; struct type_chain *next; } + *chain = NULL, *head = NULL, scratch; + ref = build_unary_op (ADDR_EXPR, datum, 0); + while (TREE_CODE (types) == SCOPE_REF) + { + tree t = TREE_OPERAND (types, 1); + if (is_aggr_typedef (t, 1)) + { + head = (struct type_chain *)alloca (sizeof (struct type_chain)); + head->type = IDENTIFIER_TYPE_VALUE (t); + head->next = chain; + chain = head; + types = TREE_OPERAND (types, 0); + } + else return error_mark_node; + } + if (! is_aggr_typedef (types, 1)) + return error_mark_node; + + head = &scratch; + head->type = IDENTIFIER_TYPE_VALUE (types); + head->next = chain; + chain = head; + while (chain) + { + tree binfo = chain->type; + type = TREE_TYPE (TREE_TYPE (ref)); + if (binfo != TYPE_BINFO (type)) + { + binfo = get_binfo (binfo, type, 1); + if (binfo == error_mark_node) + return error_mark_node; + if (binfo == 0) + return error_not_base_type (chain->type, type); + ref = convert_pointer_to (binfo, ref); + } + chain = chain->next; + } + return build_indirect_ref (ref, "(compiler error in build_scoped_ref)"); + } + + /* This is an easy conversion. */ + if (is_aggr_typedef (types, 1)) + { + tree binfo = TYPE_BINFO (IDENTIFIER_TYPE_VALUE (types)); + if (binfo != TYPE_BINFO (type)) + { + binfo = get_binfo (binfo, type, 1); + if (binfo == error_mark_node) + return error_mark_node; + if (binfo == 0) + return error_not_base_type (IDENTIFIER_TYPE_VALUE (types), type); + } + + switch (TREE_CODE (datum)) + { + case NOP_EXPR: + case CONVERT_EXPR: + case FLOAT_EXPR: + case FIX_TRUNC_EXPR: + case FIX_FLOOR_EXPR: + case FIX_ROUND_EXPR: + case FIX_CEIL_EXPR: + ref = convert_pointer_to (binfo, + build_unary_op (ADDR_EXPR, TREE_OPERAND (datum, 0), 0)); + break; + default: + ref = convert_pointer_to (binfo, + build_unary_op (ADDR_EXPR, datum, 0)); + } + return build_indirect_ref (ref, "(compiler error in build_scoped_ref)"); + } + return error_mark_node; +} + +/* Build a reference to an object specified by the C++ `->' operator. + Usually this just involves dereferencing the object, but if the + `->' operator is overloaded, then such overloads must be + performed until an object which does not have the `->' operator + overloaded is found. An error is reported when circular pointer + delegation is detected. */ +tree +build_x_arrow (datum) + tree datum; +{ + tree types_memoized = NULL_TREE; + register tree rval = datum; + tree type = TREE_TYPE (rval); + tree last_rval; + + if (type == error_mark_node) + return error_mark_node; + + if (TREE_CODE (rval) == OFFSET_REF) + { + rval = resolve_offset_ref (datum); + type = TREE_TYPE (rval); + } + + if (TREE_CODE (type) == REFERENCE_TYPE) + { + rval = convert_from_reference (rval); + type = TREE_TYPE (rval); + } + + if (IS_AGGR_TYPE (type) && TYPE_OVERLOADS_ARROW (type)) + { + while ((rval = build_opfncall (COMPONENT_REF, LOOKUP_NORMAL, rval, NULL_TREE, NULL_TREE))) + { + if (rval == error_mark_node) + return error_mark_node; + + if (value_member (TREE_TYPE (rval), types_memoized)) + { + error ("circular pointer delegation detected"); + return error_mark_node; + } + else + { + types_memoized = tree_cons (NULL_TREE, TREE_TYPE (rval), + types_memoized); + } + last_rval = rval; + } + if (TREE_CODE (TREE_TYPE (last_rval)) == REFERENCE_TYPE) + last_rval = convert_from_reference (last_rval); + } + else + last_rval = default_conversion (rval); + + /* Signature pointers are not dereferenced. */ + if (TYPE_LANG_SPECIFIC (TREE_TYPE (last_rval)) + && IS_SIGNATURE_POINTER (TREE_TYPE (last_rval))) + return last_rval; + + if (TREE_CODE (TREE_TYPE (last_rval)) == POINTER_TYPE) + return build_indirect_ref (last_rval, NULL_PTR); + + if (types_memoized) + error ("result of `operator->()' yields non-pointer result"); + else + error ("base operand of `->' is not a pointer"); + return error_mark_node; +} + +/* Make an expression to refer to the COMPONENT field of + structure or union value DATUM. COMPONENT is an arbitrary + expression. DATUM has not already been checked out to be of + aggregate type. + + For C++, COMPONENT may be a TREE_LIST. This happens when we must + return an object of member type to a method of the current class, + but there is not yet enough typing information to know which one. + As a special case, if there is only one method by that name, + it is returned. Otherwise we return an expression which other + routines will have to know how to deal with later. */ +tree +build_m_component_ref (datum, component) + tree datum, component; +{ + tree type; + tree objtype = TREE_TYPE (datum); + tree rettype; + tree binfo; + + if (TYPE_PTRMEMFUNC_P (TREE_TYPE (component))) + { + type = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (component))); + rettype = type; + } + else + { + component = build_indirect_ref (component, NULL_PTR); + type = TREE_TYPE (component); + rettype = TREE_TYPE (TREE_TYPE (component)); + } + + if (datum == error_mark_node || component == error_mark_node) + return error_mark_node; + + if (TREE_CODE (type) != OFFSET_TYPE && TREE_CODE (type) != METHOD_TYPE) + { + cp_error ("`%E' cannot be used as a member pointer, since it is of type `%T'", component, type); + return error_mark_node; + } + + if (TREE_CODE (objtype) == REFERENCE_TYPE) + objtype = TREE_TYPE (objtype); + objtype = TYPE_MAIN_VARIANT (objtype); + + if (! IS_AGGR_TYPE (objtype)) + { + cp_error ("cannot apply member pointer `%E' to `%E'", component, datum); + cp_error ("which is of non-aggregate type `%T'", objtype); + return error_mark_node; + } + + binfo = get_binfo (TYPE_METHOD_BASETYPE (type), objtype, 1); + if (binfo == NULL_TREE) + { + cp_error ("member type `%T::' incompatible with object type `%T'", + TYPE_METHOD_BASETYPE (type), objtype); + return error_mark_node; + } + else if (binfo == error_mark_node) + return error_mark_node; + + return build (OFFSET_REF, rettype, datum, component); +} + +/* Return a tree node for the expression TYPENAME '(' PARMS ')'. + + Because we cannot tell whether this construct is really a call to a + constructor or a request for a type conversion, we try both, and + report any ambiguities we find. */ +tree +build_functional_cast (exp, parms) + tree exp; + tree parms; +{ + /* This is either a call to a constructor, + or a C cast in C++'s `functional' notation. */ + tree type, name = NULL_TREE; + tree expr_as_ctor = NULL_TREE; + + if (exp == error_mark_node || parms == error_mark_node) + return error_mark_node; + + if (TREE_CODE (exp) == IDENTIFIER_NODE) + { + name = exp; + + if (IDENTIFIER_HAS_TYPE_VALUE (exp)) + /* Either an enum or an aggregate type. */ + type = IDENTIFIER_TYPE_VALUE (exp); + else + { + type = lookup_name (exp, 1); + if (!type || TREE_CODE (type) != TYPE_DECL) + { + cp_error ("`%T' fails to be a typedef or built-in type", name); + return error_mark_node; + } + type = TREE_TYPE (type); + } + } + else + type = exp; + + if (IS_SIGNATURE (type)) + { + error ("signature type not allowed in cast or constructor expression"); + return error_mark_node; + } + + /* Prepare to evaluate as a call to a constructor. If this expression + is actually used, for example, + + return X (arg1, arg2, ...); + + then the slot being initialized will be filled in. */ + + if (name == NULL_TREE) + { + name = TYPE_NAME (type); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NESTED_TYPENAME (name); + } + + if (! IS_AGGR_TYPE (type)) + { + /* this must build a C cast */ + if (parms == NULL_TREE) + parms = integer_zero_node; + else + { + if (TREE_CHAIN (parms) != NULL_TREE) + pedwarn ("initializer list being treated as compound expression"); + parms = build_compound_expr (parms); + } + + return build_c_cast (type, parms, 1); + } + + if (TYPE_SIZE (type) == NULL_TREE) + { + cp_error ("type `%T' is not yet defined", type); + return error_mark_node; + } + + if (parms && TREE_CHAIN (parms) == NULL_TREE) + return build_c_cast (type, parms, 1); + + expr_as_ctor = build_method_call (NULL_TREE, name, parms, + NULL_TREE, LOOKUP_NORMAL); + + if (expr_as_ctor == error_mark_node) + return error_mark_node; + + return build_cplus_new (type, expr_as_ctor, 1); +} + +/* Return the character string for the name that encodes the + enumeral value VALUE in the domain TYPE. */ +char * +enum_name_string (value, type) + tree value; + tree type; +{ + register tree values = TYPE_VALUES (type); + register HOST_WIDE_INT intval = TREE_INT_CST_LOW (value); + + my_friendly_assert (TREE_CODE (type) == ENUMERAL_TYPE, 324); + while (values + && TREE_INT_CST_LOW (TREE_VALUE (values)) != intval) + values = TREE_CHAIN (values); + if (values == NULL_TREE) + { + char *buf = (char *)oballoc (16 + TYPE_NAME_LENGTH (type)); + + /* Value must have been cast. */ + sprintf (buf, "(enum %s)%d", + TYPE_NAME_STRING (type), intval); + return buf; + } + return IDENTIFIER_POINTER (TREE_PURPOSE (values)); +} + +#if 0 +/* Print out a language-specific error message for + (Pascal) case or (C) switch statements. + CODE tells what sort of message to print. + TYPE is the type of the switch index expression. + NEW is the new value that we were trying to add. + OLD is the old value that stopped us from adding it. */ +void +report_case_error (code, type, new_value, old_value) + int code; + tree type; + tree new_value, old_value; +{ + if (code == 1) + { + if (new_value) + error ("case label not within a switch statement"); + else + error ("default label not within a switch statement"); + } + else if (code == 2) + { + if (new_value == 0) + { + error ("multiple default labels in one switch"); + return; + } + if (TREE_CODE (new_value) == RANGE_EXPR) + if (TREE_CODE (old_value) == RANGE_EXPR) + { + char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); + if (TREE_CODE (type) == ENUMERAL_TYPE) + sprintf (buf, "overlapping ranges [%s..%s], [%s..%s] in case expression", + enum_name_string (TREE_OPERAND (new_value, 0), type), + enum_name_string (TREE_OPERAND (new_value, 1), type), + enum_name_string (TREE_OPERAND (old_value, 0), type), + enum_name_string (TREE_OPERAND (old_value, 1), type)); + else + sprintf (buf, "overlapping ranges [%d..%d], [%d..%d] in case expression", + TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), + TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), + TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), + TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1))); + error (buf); + } + else + { + char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); + if (TREE_CODE (type) == ENUMERAL_TYPE) + sprintf (buf, "range [%s..%s] includes element `%s' in case expression", + enum_name_string (TREE_OPERAND (new_value, 0), type), + enum_name_string (TREE_OPERAND (new_value, 1), type), + enum_name_string (old_value, type)); + else + sprintf (buf, "range [%d..%d] includes (%d) in case expression", + TREE_INT_CST_LOW (TREE_OPERAND (new_value, 0)), + TREE_INT_CST_LOW (TREE_OPERAND (new_value, 1)), + TREE_INT_CST_LOW (old_value)); + error (buf); + } + else if (TREE_CODE (old_value) == RANGE_EXPR) + { + char *buf = (char *)alloca (4 * (8 + TYPE_NAME_LENGTH (type))); + if (TREE_CODE (type) == ENUMERAL_TYPE) + sprintf (buf, "range [%s..%s] includes element `%s' in case expression", + enum_name_string (TREE_OPERAND (old_value, 0), type), + enum_name_string (TREE_OPERAND (old_value, 1), type), + enum_name_string (new_value, type)); + else + sprintf (buf, "range [%d..%d] includes (%d) in case expression", + TREE_INT_CST_LOW (TREE_OPERAND (old_value, 0)), + TREE_INT_CST_LOW (TREE_OPERAND (old_value, 1)), + TREE_INT_CST_LOW (new_value)); + error (buf); + } + else + { + if (TREE_CODE (type) == ENUMERAL_TYPE) + error ("duplicate label `%s' in switch statement", + enum_name_string (new_value, type)); + else + error ("duplicate label (%d) in switch statement", + TREE_INT_CST_LOW (new_value)); + } + } + else if (code == 3) + { + if (TREE_CODE (type) == ENUMERAL_TYPE) + warning ("case value out of range for enum %s", + TYPE_NAME_STRING (type)); + else + warning ("case value out of range"); + } + else if (code == 4) + { + if (TREE_CODE (type) == ENUMERAL_TYPE) + error ("range values `%s' and `%s' reversed", + enum_name_string (new_value, type), + enum_name_string (old_value, type)); + else + error ("range values reversed"); + } +} +#endif diff --git a/contrib/gcc/cp/xref.c b/contrib/gcc/cp/xref.c new file mode 100644 index 00000000000..ec4b174b52c --- /dev/null +++ b/contrib/gcc/cp/xref.c @@ -0,0 +1,840 @@ +/* Code for handling XREF output from GNU C++. + Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "input.h" + +#include + +extern char *getpwd (); + +extern char *index (); +extern char *rindex (); + +/* The character(s) used to join a directory specification (obtained with + getwd or equivalent) with a non-absolute file name. */ + +#ifndef FILE_NAME_JOINER +#define FILE_NAME_JOINER "/" +#endif + +/* Nonzero if NAME as a file name is absolute. */ +#ifndef FILE_NAME_ABSOLUTE_P +#define FILE_NAME_ABSOLUTE_P(NAME) (NAME[0] == '/') +#endif + +/* For cross referencing. */ + +int flag_gnu_xref; + +/************************************************************************/ +/* */ +/* Common definitions */ +/* */ +/************************************************************************/ + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef NULL +#define NULL 0 +#endif + +#define PALLOC(typ) ((typ *) calloc(1,sizeof(typ))) + + +/* Return a malloc'd copy of STR. */ +#define SALLOC(str) \ + ((char *) ((str) == NULL ? NULL \ + : (char *) strcpy ((char *) malloc (strlen ((str)) + 1), (str)))) +#define SFREE(str) (str != NULL && (free(str),0)) + +#define STREQL(s1,s2) (strcmp((s1),(s2)) == 0) +#define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0) +#define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0) +#define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0) +#define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0) +#define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0) + +/************************************************************************/ +/* */ +/* Type definitions */ +/* */ +/************************************************************************/ + + +typedef struct _XREF_FILE * XREF_FILE; +typedef struct _XREF_SCOPE * XREF_SCOPE; + +typedef struct _XREF_FILE +{ + char *name; + char *outname; + XREF_FILE next; +} XREF_FILE_INFO; + +typedef struct _XREF_SCOPE +{ + int gid; + int lid; + XREF_FILE file; + int start; + XREF_SCOPE outer; +} XREF_SCOPE_INFO; + +/************************************************************************/ +/* */ +/* Local storage */ +/* */ +/************************************************************************/ + +static char doing_xref = 0; +static FILE * xref_file = NULL; +static char xref_name[1024]; +static XREF_FILE all_files = NULL; +static char * wd_name = NULL; +static XREF_SCOPE cur_scope = NULL; +static int scope_ctr = 0; +static XREF_FILE last_file = NULL; +static tree last_fndecl = NULL; + +/************************************************************************/ +/* */ +/* Forward definitions */ +/* */ +/************************************************************************/ + +extern void GNU_xref_begin(); +extern void GNU_xref_end(); +extern void GNU_xref_file(); +extern void GNU_xref_start_scope(); +extern void GNU_xref_end_scope(); +extern void GNU_xref_ref(); +extern void GNU_xref_decl(); +extern void GNU_xref_call(); +extern void GNU_xref_function(); +extern void GNU_xref_assign(); +extern void GNU_xref_hier(); +extern void GNU_xref_member(); + +static void gen_assign(); +static XREF_FILE find_file(); +static char * filename(); +static char * fctname(); +static char * declname(); +static void simplify_type(); +static char * fixname(); +static void open_xref_file(); + +extern char * type_as_string(); + +/* Start cross referencing. FILE is the name of the file we xref. */ + +void +GNU_xref_begin (file) + char *file; +{ + doing_xref = 1; + + if (file != NULL && STRNEQ (file,"-")) + { + open_xref_file(file); + GNU_xref_file(file); + } +} + +/* Finish cross-referencing. ERRCNT is the number of errors + we encountered. */ + +void +GNU_xref_end (ect) + int ect; +{ + XREF_FILE xf; + + if (!doing_xref) return; + + xf = find_file (input_filename); + if (xf == NULL) return; + + while (cur_scope != NULL) + GNU_xref_end_scope(cur_scope->gid,0,0,0,0); + + doing_xref = 0; + + if (xref_file == NULL) return; + + fclose (xref_file); + + xref_file = NULL; + all_files = NULL; + + if (ect > 0) unlink (xref_name); +} + +/* Write out xref for file named NAME. */ + +void +GNU_xref_file (name) + char *name; +{ + XREF_FILE xf; + + if (!doing_xref || name == NULL) return; + + if (xref_file == NULL) + { + open_xref_file (name); + if (!doing_xref) return; + } + + if (all_files == NULL) + fprintf(xref_file,"SCP * 0 0 0 0 RESET\n"); + + xf = find_file (name); + if (xf != NULL) return; + + xf = PALLOC (XREF_FILE_INFO); + xf->name = SALLOC (name); + xf->next = all_files; + all_files = xf; + + if (wd_name == NULL) + wd_name = getpwd (); + + if (FILE_NAME_ABSOLUTE_P (name) || ! wd_name) + xf->outname = xf->name; + else + { + char *nmbuf + = (char *) malloc (strlen (wd_name) + strlen (FILE_NAME_JOINER) + + strlen (name) + 1); + sprintf (nmbuf, "%s%s%s", wd_name, FILE_NAME_JOINER, name); + name = nmbuf; + xf->outname = nmbuf; + } + + fprintf (xref_file, "FIL %s %s 0\n", name, wd_name); + + filename (xf); + fctname (NULL); +} + +/* Start a scope identified at level ID. */ + +void +GNU_xref_start_scope (id) + HOST_WIDE_INT id; +{ + XREF_SCOPE xs; + XREF_FILE xf; + + if (!doing_xref) return; + xf = find_file (input_filename); + + xs = PALLOC (XREF_SCOPE_INFO); + xs->file = xf; + xs->start = lineno; + if (xs->start <= 0) xs->start = 1; + xs->gid = id; + xs->lid = ++scope_ctr; + xs->outer = cur_scope; + cur_scope = xs; +} + +/* Finish a scope at level ID. + INID is ??? + PRM is ??? + KEEP is nonzero iff this scope is retained (nonzero if it's + a compiler-generated invisible scope). + TRNS is ??? */ + +void +GNU_xref_end_scope (id,inid,prm,keep,trns) + HOST_WIDE_INT id; + HOST_WIDE_INT inid; + int prm,keep,trns; +{ + XREF_FILE xf; + XREF_SCOPE xs,lxs,oxs; + char *stype; + + if (!doing_xref) return; + xf = find_file (input_filename); + if (xf == NULL) return; + + lxs = NULL; + for (xs = cur_scope; xs != NULL; xs = xs->outer) + { + if (xs->gid == id) break; + lxs = xs; + } + if (xs == NULL) return; + + if (inid != 0) { + for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) { + if (oxs->gid == inid) break; + } + if (oxs == NULL) return; + inid = oxs->lid; + } + + if (prm == 2) stype = "SUE"; + else if (prm != 0) stype = "ARGS"; + else if (keep == 2 || inid != 0) stype = "INTERN"; + else stype = "EXTERN"; + + fprintf (xref_file,"SCP %s %d %d %d %d %s\n", + filename (xf), xs->start, lineno,xs->lid, inid, stype); + + if (lxs == NULL) cur_scope = xs->outer; + else lxs->outer = xs->outer; + + free (xs); +} + +/* Output a reference to NAME in FNDECL. */ + +void +GNU_xref_ref (fndecl,name) + tree fndecl; + char *name; +{ + XREF_FILE xf; + + if (!doing_xref) return; + xf = find_file (input_filename); + if (xf == NULL) return; + + fprintf (xref_file, "REF %s %d %s %s\n", + filename (xf), lineno, fctname (fndecl), name); +} + +/* Output a reference to DECL in FNDECL. */ + +void +GNU_xref_decl (fndecl,decl) + tree fndecl; + tree decl; +{ + XREF_FILE xf,xf1; + char *cls; + char *name; + char buf[10240]; + int uselin; + + if (!doing_xref) return; + xf = find_file (input_filename); + if (xf == NULL) return; + + uselin = FALSE; + + if (TREE_CODE (decl) == TYPE_DECL) cls = "TYPEDEF"; + else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD"; + else if (TREE_CODE (decl) == VAR_DECL) + { + if (fndecl == NULL && TREE_STATIC(decl) + && TREE_READONLY(decl) && DECL_INITIAL(decl) != 0 + && !TREE_PUBLIC(decl) && !DECL_EXTERNAL(decl) + && DECL_MODE(decl) != BLKmode) cls = "CONST"; + else if (DECL_EXTERNAL(decl)) cls = "EXTERN"; + else if (TREE_PUBLIC(decl)) cls = "EXTDEF"; + else if (TREE_STATIC(decl)) cls = "STATIC"; + else if (DECL_REGISTER(decl)) cls = "REGISTER"; + else cls = "AUTO"; + } + else if (TREE_CODE (decl) == PARM_DECL) cls = "PARAM"; + else if (TREE_CODE (decl) == FIELD_DECL) cls = "FIELD"; + else if (TREE_CODE (decl) == CONST_DECL) cls = "CONST"; + else if (TREE_CODE (decl) == FUNCTION_DECL) + { + if (DECL_EXTERNAL (decl)) cls = "EXTERN"; + else if (TREE_PUBLIC (decl)) cls = "EFUNCTION"; + else cls = "SFUNCTION"; + } + else if (TREE_CODE (decl) == LABEL_DECL) cls = "LABEL"; + else if (TREE_CODE (decl) == UNION_TYPE) + { + cls = "UNIONID"; + decl = TYPE_NAME (decl); + uselin = TRUE; + } + else if (TREE_CODE (decl) == RECORD_TYPE) + { + if (CLASSTYPE_DECLARED_CLASS (decl)) cls = "CLASSID"; + else if (IS_SIGNATURE (decl)) cls = "SIGNATUREID"; + else cls = "STRUCTID"; + decl = TYPE_NAME (decl); + uselin = TRUE; + } + else if (TREE_CODE (decl) == ENUMERAL_TYPE) + { + cls = "ENUMID"; + decl = TYPE_NAME (decl); + uselin = TRUE; + } + else if (TREE_CODE (decl) == TEMPLATE_DECL) + { + if (DECL_TEMPLATE_IS_CLASS (decl)) + cls = "CLASSTEMP"; + else if (TREE_CODE (DECL_RESULT (decl)) == FUNCTION_DECL) + cls = "FUNCTEMP"; + else if (TREE_CODE (DECL_RESULT (decl)) == VAR_DECL) + cls = "VARTEMP"; + else + my_friendly_abort (358); + uselin = TRUE; + } + else cls = "UNKNOWN"; + + if (decl == NULL || DECL_NAME (decl) == NULL) return; + + if (uselin && decl->decl.linenum > 0 && decl->decl.filename != NULL) + { + xf1 = find_file (decl->decl.filename); + if (xf1 != NULL) + { + lineno = decl->decl.linenum; + xf = xf1; + } + } + + if (DECL_ASSEMBLER_NAME (decl)) + name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + else + name = IDENTIFIER_POINTER (DECL_NAME (decl)); + + strcpy (buf, type_as_string (TREE_TYPE (decl), 0)); + simplify_type (buf); + + fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n", + filename(xf), lineno, name, + (cur_scope != NULL ? cur_scope->lid : 0), + cls, fctname(fndecl), buf); + + if (STREQL (cls, "STRUCTID") || STREQL (cls, "UNIONID") + || STREQL (cls, "SIGNATUREID")) + { + cls = "CLASSID"; + fprintf (xref_file, "DCL %s %d %s %d %s %s %s\n", + filename(xf), lineno,name, + (cur_scope != NULL ? cur_scope->lid : 0), + cls, fctname(fndecl), buf); + } +} + +/* Output a reference to a call to NAME in FNDECL. */ + +void +GNU_xref_call (fndecl, name) + tree fndecl; + char *name; +{ + XREF_FILE xf; + char buf[1024]; + char *s; + + if (!doing_xref) return; + xf = find_file (input_filename); + if (xf == NULL) return; + name = fixname (name, buf); + + for (s = name; *s != 0; ++s) + if (*s == '_' && s[1] == '_') break; + if (*s != 0) GNU_xref_ref (fndecl, name); + + fprintf (xref_file, "CAL %s %d %s %s\n", + filename (xf), lineno, name, fctname (fndecl)); +} + +/* Output cross-reference info about FNDECL. If non-NULL, + ARGS are the arguments for the function (i.e., before the FUNCTION_DECL + has been fully built). */ + +void +GNU_xref_function (fndecl, args) + tree fndecl; + tree args; +{ + XREF_FILE xf; + int ct; + char buf[1024]; + + if (!doing_xref) return; + xf = find_file (input_filename); + if (xf == NULL) return; + + ct = 0; + buf[0] = 0; + if (args == NULL) args = DECL_ARGUMENTS (fndecl); + + GNU_xref_decl (NULL, fndecl); + + for ( ; args != NULL; args = TREE_CHAIN (args)) + { + GNU_xref_decl (fndecl,args); + if (ct != 0) strcat (buf,","); + strcat (buf, declname (args)); + ++ct; + } + + fprintf (xref_file, "PRC %s %d %s %d %d %s\n", + filename(xf), lineno, declname(fndecl), + (cur_scope != NULL ? cur_scope->lid : 0), + ct, buf); +} + +/* Output cross-reference info about an assignment to NAME. */ + +void +GNU_xref_assign(name) + tree name; +{ + XREF_FILE xf; + + if (!doing_xref) return; + xf = find_file(input_filename); + if (xf == NULL) return; + + gen_assign(xf, name); +} + +static void +gen_assign(xf, name) + XREF_FILE xf; + tree name; +{ + char *s; + + s = NULL; + + switch (TREE_CODE (name)) + { + case IDENTIFIER_NODE : + s = IDENTIFIER_POINTER(name); + break; + case VAR_DECL : + s = declname(name); + break; + case COMPONENT_REF : + gen_assign(xf, TREE_OPERAND(name, 0)); + gen_assign(xf, TREE_OPERAND(name, 1)); + break; + case INDIRECT_REF : + case OFFSET_REF : + case ARRAY_REF : + case BUFFER_REF : + gen_assign(xf, TREE_OPERAND(name, 0)); + break; + case COMPOUND_EXPR : + gen_assign(xf, TREE_OPERAND(name, 1)); + break; + default : + break; + } + + if (s != NULL) + fprintf(xref_file, "ASG %s %d %s\n", filename(xf), lineno, s); +} + +/* Output cross-reference info about a class hierarchy. + CLS is the class type of interest. BASE is a baseclass + for CLS. PUB and VIRT give the access info about + the class derivation. FRND is nonzero iff BASE is a friend + of CLS. + + ??? Needs to handle nested classes. */ +void +GNU_xref_hier(cls, base, pub, virt, frnd) + char *cls; + char *base; + int pub; + int virt; + int frnd; +{ + XREF_FILE xf; + + if (!doing_xref) return; + xf = find_file(input_filename); + if (xf == NULL) return; + + fprintf(xref_file, "HIE %s %d %s %s %d %d %d\n", + filename(xf), lineno, cls, base, pub, virt, frnd); +} + +/* Output cross-reference info about class members. CLS + is the containing type; FLD is the class member. */ + +void +GNU_xref_member(cls, fld) + tree cls; + tree fld; +{ + XREF_FILE xf; + char *prot; + int confg, pure; + char *d; + int i; + char buf[1024], bufa[1024]; + + if (!doing_xref) return; + xf = find_file(fld->decl.filename); + if (xf == NULL) return; + + if (TREE_PRIVATE (fld)) prot = "PRIVATE"; + else if (TREE_PROTECTED(fld)) prot = "PROTECTED"; + else prot = "PUBLIC"; + + confg = 0; + if (TREE_CODE (fld) == FUNCTION_DECL && DECL_CONST_MEMFUNC_P(fld)) + confg = 1; + else if (TREE_CODE (fld) == CONST_DECL) + confg = 1; + + pure = 0; + if (TREE_CODE (fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld)) + pure = 1; + + d = IDENTIFIER_POINTER(cls); + sprintf(buf, "%d%s", strlen(d), d); + i = strlen(buf); + strcpy(bufa, declname(fld)); + +#ifdef XREF_SHORT_MEMBER_NAMES + for (p = &bufa[1]; *p != 0; ++p) + { + if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') { + if (strncmp(&p[2], buf, i) == 0) *p = 0; + break; + } + else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') { + if (strncmp(&p[3], buf, i) == 0) *p = 0; + break; + } + } +#endif + + fprintf(xref_file, "MEM %s %d %s %s %s %d %d %d %d %d %d %d\n", + filename(xf), fld->decl.linenum, d, bufa, prot, + (TREE_CODE (fld) == FUNCTION_DECL ? 0 : 1), + (DECL_INLINE (fld) ? 1 : 0), + (DECL_FRIEND_P(fld) ? 1 : 0), + (DECL_VINDEX(fld) ? 1 : 0), + (TREE_STATIC(fld) ? 1 : 0), + pure, confg); +} + +/* Find file entry given name. */ + +static XREF_FILE +find_file(name) + char *name; +{ + XREF_FILE xf; + + for (xf = all_files; xf != NULL; xf = xf->next) { + if (STREQL(name, xf->name)) break; + } + + return xf; +} + +/* Return filename for output purposes. */ + +static char * +filename(xf) + XREF_FILE xf; +{ + if (xf == NULL) { + last_file = NULL; + return "*"; + } + + if (last_file == xf) return "*"; + + last_file = xf; + + return xf->outname; +} + +/* Return function name for output purposes. */ + +static char * +fctname(fndecl) + tree fndecl; +{ + static char fctbuf[1024]; + char *s; + + if (fndecl == NULL && last_fndecl == NULL) return "*"; + + if (fndecl == NULL) + { + last_fndecl = NULL; + return "*TOP*"; + } + + if (fndecl == last_fndecl) return "*"; + + last_fndecl = fndecl; + + s = declname(fndecl); + s = fixname(s, fctbuf); + + return s; +} + +/* Return decl name for output purposes. */ + +static char * +declname(dcl) + tree dcl; +{ + if (DECL_NAME (dcl) == NULL) return "?"; + + if (DECL_ASSEMBLER_NAME (dcl)) + return IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (dcl)); + else + return IDENTIFIER_POINTER (DECL_NAME (dcl)); +} + +/* Simplify a type string by removing unneeded parenthesis. */ + +static void +simplify_type(typ) + char *typ; +{ + char *s; + int lvl, i; + + i = strlen(typ); + while (i > 0 && isspace(typ[i-1])) typ[--i] = 0; + + if (i > 7 && STREQL(&typ[i-5], "const")) + { + typ[i-5] = 0; + i -= 5; + } + + if (typ[i-1] != ')') return; + + s = &typ[i-2]; + lvl = 1; + while (*s != 0) { + if (*s == ')') ++lvl; + else if (*s == '(') + { + --lvl; + if (lvl == 0) + { + s[1] = ')'; + s[2] = 0; + break; + } + } + --s; + } + + if (*s != 0 && s[-1] == ')') + { + --s; + --s; + if (*s == '(') s[2] = 0; + else if (*s == ':') { + while (*s != '(') --s; + s[1] = ')'; + s[2] = 0; + } + } +} + +/* Fixup a function name (take care of embedded spaces). */ + +static char * +fixname(nam, buf) + char *nam; + char *buf; +{ + char *s, *t; + int fg; + + s = nam; + t = buf; + fg = 0; + + while (*s != 0) + { + if (*s == ' ') + { + *t++ = '\36'; + ++fg; + } + else *t++ = *s; + ++s; + } + *t = 0; + + if (fg == 0) return nam; + + return buf; +} + +/* Open file for xreffing. */ + +static void +open_xref_file(file) + char *file; +{ + char *s, *t; + +#ifdef XREF_FILE_NAME + XREF_FILE_NAME (xref_name, file); +#else + s = rindex (file, '/'); + if (s == NULL) + sprintf (xref_name, ".%s.gxref", file); + else + { + ++s; + strcpy (xref_name, file); + t = rindex (xref_name, '/'); + ++t; + *t++ = '.'; + strcpy (t, s); + strcat (t, ".gxref"); + } +#endif /* no XREF_FILE_NAME */ + + xref_file = fopen(xref_name, "w"); + + if (xref_file == NULL) + { + error("Can't create cross-reference file `%s'", xref_name); + doing_xref = 0; + } +} diff --git a/contrib/gcc/cplus-dem.c b/contrib/gcc/cplus-dem.c new file mode 100644 index 00000000000..3eb27cc9b84 --- /dev/null +++ b/contrib/gcc/cplus-dem.c @@ -0,0 +1,3001 @@ +/* Demangler for GNU C++ + Copyright 1989, 1991, 1994, 1995 Free Software Foundation, Inc. + Written by James Clark (jjc@jclark.uucp) + Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file exports two functions; cplus_mangle_opname and cplus_demangle. + + This file imports xmalloc and xrealloc, which are like malloc and + realloc except that they generate a fatal error if there is no + available memory. */ + +#include +#include +#include + +#include +#undef CURRENT_DEMANGLING_STYLE +#define CURRENT_DEMANGLING_STYLE work->options + +extern char *xmalloc PARAMS((unsigned)); +extern char *xrealloc PARAMS((char *, unsigned)); + +char * +mystrstr (s1, s2) + char *s1, *s2; +{ + register char *p = s1; + register int len = strlen (s2); + + for (; (p = strchr (p, *s2)) != 0; p++) + { + if (strncmp (p, s2, len) == 0) + { + return (p); + } + } + return (0); +} + +/* In order to allow a single demangler executable to demangle strings + using various common values of CPLUS_MARKER, as well as any specific + one set at compile time, we maintain a string containing all the + commonly used ones, and check to see if the marker we are looking for + is in that string. CPLUS_MARKER is usually '$' on systems where the + assembler can deal with that. Where the assembler can't, it's usually + '.' (but on many systems '.' is used for other things). We put the + current defined CPLUS_MARKER first (which defaults to '$'), followed + by the next most common value, followed by an explicit '$' in case + the value of CPLUS_MARKER is not '$'. + + We could avoid this if we could just get g++ to tell us what the actual + cplus marker character is as part of the debug information, perhaps by + ensuring that it is the character that terminates the gcc_compiled + marker symbol (FIXME). */ + +#if !defined (CPLUS_MARKER) +#define CPLUS_MARKER '$' +#endif + +enum demangling_styles current_demangling_style = gnu_demangling; + +static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' }; + +void +set_cplus_marker_for_demangling (ch) + int ch; +{ + cplus_markers[0] = ch; +} + +/* Stuff that is shared between sub-routines. + * Using a shared structure allows cplus_demangle to be reentrant. */ + +struct work_stuff +{ + int options; + char **typevec; + int ntypes; + int typevec_size; + int constructor; + int destructor; + int static_type; /* A static member function */ + int const_type; /* A const member function */ +}; + +#define PRINT_ANSI_QUALIFIERS (work -> options & DMGL_ANSI) +#define PRINT_ARG_TYPES (work -> options & DMGL_PARAMS) + +static const struct optable +{ + const char *in; + const char *out; + int flags; +} optable[] = { + {"nw", " new", DMGL_ANSI}, /* new (1.92, ansi) */ + {"dl", " delete", DMGL_ANSI}, /* new (1.92, ansi) */ + {"new", " new", 0}, /* old (1.91, and 1.x) */ + {"delete", " delete", 0}, /* old (1.91, and 1.x) */ + {"vn", " new []", DMGL_ANSI}, /* GNU, pending ansi */ + {"vd", " delete []", DMGL_ANSI}, /* GNU, pending ansi */ + {"as", "=", DMGL_ANSI}, /* ansi */ + {"ne", "!=", DMGL_ANSI}, /* old, ansi */ + {"eq", "==", DMGL_ANSI}, /* old, ansi */ + {"ge", ">=", DMGL_ANSI}, /* old, ansi */ + {"gt", ">", DMGL_ANSI}, /* old, ansi */ + {"le", "<=", DMGL_ANSI}, /* old, ansi */ + {"lt", "<", DMGL_ANSI}, /* old, ansi */ + {"plus", "+", 0}, /* old */ + {"pl", "+", DMGL_ANSI}, /* ansi */ + {"apl", "+=", DMGL_ANSI}, /* ansi */ + {"minus", "-", 0}, /* old */ + {"mi", "-", DMGL_ANSI}, /* ansi */ + {"ami", "-=", DMGL_ANSI}, /* ansi */ + {"mult", "*", 0}, /* old */ + {"ml", "*", DMGL_ANSI}, /* ansi */ + {"amu", "*=", DMGL_ANSI}, /* ansi (ARM/Lucid) */ + {"aml", "*=", DMGL_ANSI}, /* ansi (GNU/g++) */ + {"convert", "+", 0}, /* old (unary +) */ + {"negate", "-", 0}, /* old (unary -) */ + {"trunc_mod", "%", 0}, /* old */ + {"md", "%", DMGL_ANSI}, /* ansi */ + {"amd", "%=", DMGL_ANSI}, /* ansi */ + {"trunc_div", "/", 0}, /* old */ + {"dv", "/", DMGL_ANSI}, /* ansi */ + {"adv", "/=", DMGL_ANSI}, /* ansi */ + {"truth_andif", "&&", 0}, /* old */ + {"aa", "&&", DMGL_ANSI}, /* ansi */ + {"truth_orif", "||", 0}, /* old */ + {"oo", "||", DMGL_ANSI}, /* ansi */ + {"truth_not", "!", 0}, /* old */ + {"nt", "!", DMGL_ANSI}, /* ansi */ + {"postincrement","++", 0}, /* old */ + {"pp", "++", DMGL_ANSI}, /* ansi */ + {"postdecrement","--", 0}, /* old */ + {"mm", "--", DMGL_ANSI}, /* ansi */ + {"bit_ior", "|", 0}, /* old */ + {"or", "|", DMGL_ANSI}, /* ansi */ + {"aor", "|=", DMGL_ANSI}, /* ansi */ + {"bit_xor", "^", 0}, /* old */ + {"er", "^", DMGL_ANSI}, /* ansi */ + {"aer", "^=", DMGL_ANSI}, /* ansi */ + {"bit_and", "&", 0}, /* old */ + {"ad", "&", DMGL_ANSI}, /* ansi */ + {"aad", "&=", DMGL_ANSI}, /* ansi */ + {"bit_not", "~", 0}, /* old */ + {"co", "~", DMGL_ANSI}, /* ansi */ + {"call", "()", 0}, /* old */ + {"cl", "()", DMGL_ANSI}, /* ansi */ + {"alshift", "<<", 0}, /* old */ + {"ls", "<<", DMGL_ANSI}, /* ansi */ + {"als", "<<=", DMGL_ANSI}, /* ansi */ + {"arshift", ">>", 0}, /* old */ + {"rs", ">>", DMGL_ANSI}, /* ansi */ + {"ars", ">>=", DMGL_ANSI}, /* ansi */ + {"component", "->", 0}, /* old */ + {"pt", "->", DMGL_ANSI}, /* ansi; Lucid C++ form */ + {"rf", "->", DMGL_ANSI}, /* ansi; ARM/GNU form */ + {"indirect", "*", 0}, /* old */ + {"method_call", "->()", 0}, /* old */ + {"addr", "&", 0}, /* old (unary &) */ + {"array", "[]", 0}, /* old */ + {"vc", "[]", DMGL_ANSI}, /* ansi */ + {"compound", ", ", 0}, /* old */ + {"cm", ", ", DMGL_ANSI}, /* ansi */ + {"cond", "?:", 0}, /* old */ + {"cn", "?:", DMGL_ANSI}, /* pseudo-ansi */ + {"max", ">?", 0}, /* old */ + {"mx", ">?", DMGL_ANSI}, /* pseudo-ansi */ + {"min", "*", DMGL_ANSI} /* ansi */ +}; + + +typedef struct string /* Beware: these aren't required to be */ +{ /* '\0' terminated. */ + char *b; /* pointer to start of string */ + char *p; /* pointer after last character */ + char *e; /* pointer after end of allocated space */ +} string; + +#define STRING_EMPTY(str) ((str) -> b == (str) -> p) +#define PREPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ + string_prepend(str, " ");} +#define APPEND_BLANK(str) {if (!STRING_EMPTY(str)) \ + string_append(str, " ");} + +#define ARM_VTABLE_STRING "__vtbl__" /* Lucid/ARM virtual table prefix */ +#define ARM_VTABLE_STRLEN 8 /* strlen (ARM_VTABLE_STRING) */ + +/* Prototypes for local functions */ + +static char * +mop_up PARAMS ((struct work_stuff *, string *, int)); + +#if 0 +static int +demangle_method_args PARAMS ((struct work_stuff *work, const char **, string *)); +#endif + +static int +demangle_template PARAMS ((struct work_stuff *work, const char **, string *, + string *)); + +static int +demangle_qualified PARAMS ((struct work_stuff *, const char **, string *, + int, int)); + +static int +demangle_class PARAMS ((struct work_stuff *, const char **, string *)); + +static int +demangle_fund_type PARAMS ((struct work_stuff *, const char **, string *)); + +static int +demangle_signature PARAMS ((struct work_stuff *, const char **, string *)); + +static int +demangle_prefix PARAMS ((struct work_stuff *, const char **, string *)); + +static int +gnu_special PARAMS ((struct work_stuff *, const char **, string *)); + +static int +arm_special PARAMS ((struct work_stuff *, const char **, string *)); + +static void +string_need PARAMS ((string *, int)); + +static void +string_delete PARAMS ((string *)); + +static void +string_init PARAMS ((string *)); + +static void +string_clear PARAMS ((string *)); + +#if 0 +static int +string_empty PARAMS ((string *)); +#endif + +static void +string_append PARAMS ((string *, const char *)); + +static void +string_appends PARAMS ((string *, string *)); + +static void +string_appendn PARAMS ((string *, const char *, int)); + +static void +string_prepend PARAMS ((string *, const char *)); + +static void +string_prependn PARAMS ((string *, const char *, int)); + +static int +get_count PARAMS ((const char **, int *)); + +static int +consume_count PARAMS ((const char **)); + +static int +demangle_args PARAMS ((struct work_stuff *, const char **, string *)); + +static int +do_type PARAMS ((struct work_stuff *, const char **, string *)); + +static int +do_arg PARAMS ((struct work_stuff *, const char **, string *)); + +static void +demangle_function_name PARAMS ((struct work_stuff *, const char **, string *, + const char *)); + +static void +remember_type PARAMS ((struct work_stuff *, const char *, int)); + +static void +forget_types PARAMS ((struct work_stuff *)); + +static void +string_prepends PARAMS ((string *, string *)); + +/* Translate count to integer, consuming tokens in the process. + Conversion terminates on the first non-digit character. + Trying to consume something that isn't a count results in + no consumption of input and a return of 0. */ + +static int +consume_count (type) + const char **type; +{ + int count = 0; + + while (isdigit (**type)) + { + count *= 10; + count += **type - '0'; + (*type)++; + } + return (count); +} + +int +cplus_demangle_opname (opname, result, options) + char *opname; + char *result; + int options; +{ + int len, i, len1, ret; + string type; + struct work_stuff work[1]; + const char *tem; + + len = strlen(opname); + result[0] = '\0'; + ret = 0; + work->options = options; + + if (opname[0] == '_' && opname[1] == '_' + && opname[2] == 'o' && opname[3] == 'p') + { + /* ANSI. */ + /* type conversion operator. */ + tem = opname + 4; + if (do_type (work, &tem, &type)) + { + strcat (result, "operator "); + strncat (result, type.b, type.p - type.b); + string_delete (&type); + ret = 1; + } + } + else if (opname[0] == '_' && opname[1] == '_' + && opname[2] >= 'a' && opname[2] <= 'z' + && opname[3] >= 'a' && opname[3] <= 'z') + { + if (opname[4] == '\0') + { + /* Operator. */ + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 2 + && memcmp (optable[i].in, opname + 2, 2) == 0) + { + strcat (result, "operator"); + strcat (result, optable[i].out); + ret = 1; + break; + } + } + } + else + { + if (opname[2] == 'a' && opname[5] == '\0') + { + /* Assignment. */ + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 3 + && memcmp (optable[i].in, opname + 2, 3) == 0) + { + strcat (result, "operator"); + strcat (result, optable[i].out); + ret = 1; + break; + } + } + } + } + } + else if (len >= 3 + && opname[0] == 'o' + && opname[1] == 'p' + && strchr (cplus_markers, opname[2]) != NULL) + { + /* see if it's an assignment expression */ + if (len >= 10 /* op$assign_ */ + && memcmp (opname + 3, "assign_", 7) == 0) + { + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + len1 = len - 10; + if (strlen (optable[i].in) == len1 + && memcmp (optable[i].in, opname + 10, len1) == 0) + { + strcat (result, "operator"); + strcat (result, optable[i].out); + strcat (result, "="); + ret = 1; + break; + } + } + } + else + { + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + len1 = len - 3; + if (strlen (optable[i].in) == len1 + && memcmp (optable[i].in, opname + 3, len1) == 0) + { + strcat (result, "operator"); + strcat (result, optable[i].out); + ret = 1; + break; + } + } + } + } + else if (len >= 5 && memcmp (opname, "type", 4) == 0 + && strchr (cplus_markers, opname[4]) != NULL) + { + /* type conversion operator */ + tem = opname + 5; + if (do_type (work, &tem, &type)) + { + strcat (result, "operator "); + strncat (result, type.b, type.p - type.b); + string_delete (&type); + ret = 1; + } + } + return ret; + +} +/* Takes operator name as e.g. "++" and returns mangled + operator name (e.g. "postincrement_expr"), or NULL if not found. + + If OPTIONS & DMGL_ANSI == 1, return the ANSI name; + if OPTIONS & DMGL_ANSI == 0, return the old GNU name. */ + +char * +cplus_mangle_opname (opname, options) + char *opname; + int options; +{ + int i; + int len; + + len = strlen (opname); + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + if (strlen (optable[i].out) == len + && (options & DMGL_ANSI) == (optable[i].flags & DMGL_ANSI) + && memcmp (optable[i].out, opname, len) == 0) + return ((char *)optable[i].in); + } + return (0); +} + +/* check to see whether MANGLED can match TEXT in the first TEXT_LEN + characters. */ + +int cplus_match (mangled, text, text_len) + const char *mangled; + char *text; + int text_len; +{ + if (strncmp (mangled, text, text_len) != 0) { + return(0); /* cannot match either */ + } else { + return(1); /* matches mangled, may match demangled */ + } +} + +/* char *cplus_demangle (const char *mangled, int options) + + If MANGLED is a mangled function name produced by GNU C++, then + a pointer to a malloced string giving a C++ representation + of the name will be returned; otherwise NULL will be returned. + It is the caller's responsibility to free the string which + is returned. + + The OPTIONS arg may contain one or more of the following bits: + + DMGL_ANSI ANSI qualifiers such as `const' and `void' are + included. + DMGL_PARAMS Function parameters are included. + + For example, + + cplus_demangle ("foo__1Ai", DMGL_PARAMS) => "A::foo(int)" + cplus_demangle ("foo__1Ai", DMGL_PARAMS | DMGL_ANSI) => "A::foo(int)" + cplus_demangle ("foo__1Ai", 0) => "A::foo" + + cplus_demangle ("foo__1Afe", DMGL_PARAMS) => "A::foo(float,...)" + cplus_demangle ("foo__1Afe", DMGL_PARAMS | DMGL_ANSI)=> "A::foo(float,...)" + cplus_demangle ("foo__1Afe", 0) => "A::foo" + + Note that any leading underscores, or other such characters prepended by + the compilation system, are presumed to have already been stripped from + MANGLED. */ + +char * +cplus_demangle (mangled, options) + const char *mangled; + int options; +{ + string decl; + int success = 0; + struct work_stuff work[1]; + char *demangled = NULL; + + if ((mangled != NULL) && (*mangled != '\0')) + { + memset ((char *) work, 0, sizeof (work)); + work -> options = options; + if ((work->options & DMGL_STYLE_MASK) == 0) + work->options |= (int)current_demangling_style & DMGL_STYLE_MASK; + + string_init (&decl); + + /* First check to see if gnu style demangling is active and if the + string to be demangled contains a CPLUS_MARKER. If so, attempt to + recognize one of the gnu special forms rather than looking for a + standard prefix. In particular, don't worry about whether there + is a "__" string in the mangled string. Consider "_$_5__foo" for + example. */ + + if ((AUTO_DEMANGLING || GNU_DEMANGLING)) + { + success = gnu_special (work, &mangled, &decl); + } + if (!success) + { + success = demangle_prefix (work, &mangled, &decl); + } + if (success && (*mangled != '\0')) + { + success = demangle_signature (work, &mangled, &decl); + } + if (work->constructor == 2) + { + string_prepend(&decl, "global constructors keyed to "); + work->constructor = 0; + } + else if (work->destructor == 2) + { + string_prepend(&decl, "global destructors keyed to "); + work->destructor = 0; + } + demangled = mop_up (work, &decl, success); + } + return (demangled); +} + +static char * +mop_up (work, declp, success) + struct work_stuff *work; + string *declp; + int success; +{ + char *demangled = NULL; + + /* Discard the remembered types, if any. */ + + forget_types (work); + if (work -> typevec != NULL) + { + free ((char *) work -> typevec); + } + + /* If demangling was successful, ensure that the demangled string is null + terminated and return it. Otherwise, free the demangling decl. */ + + if (!success) + { + string_delete (declp); + } + else + { + string_appendn (declp, "", 1); + demangled = declp -> b; + } + return (demangled); +} + +/* + +LOCAL FUNCTION + + demangle_signature -- demangle the signature part of a mangled name + +SYNOPSIS + + static int + demangle_signature (struct work_stuff *work, const char **mangled, + string *declp); + +DESCRIPTION + + Consume and demangle the signature portion of the mangled name. + + DECLP is the string where demangled output is being built. At + entry it contains the demangled root name from the mangled name + prefix. I.E. either a demangled operator name or the root function + name. In some special cases, it may contain nothing. + + *MANGLED points to the current unconsumed location in the mangled + name. As tokens are consumed and demangling is performed, the + pointer is updated to continuously point at the next token to + be consumed. + + Demangling GNU style mangled names is nasty because there is no + explicit token that marks the start of the outermost function + argument list. +*/ + +static int +demangle_signature (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int success = 1; + int func_done = 0; + int expect_func = 0; + const char *oldmangled = NULL; + string trawname; + string tname; + + while (success && (**mangled != '\0')) + { + switch (**mangled) + { + case 'Q': + oldmangled = *mangled; + success = demangle_qualified (work, mangled, declp, 1, 0); + if (success) + { + remember_type (work, oldmangled, *mangled - oldmangled); + } + if (AUTO_DEMANGLING || GNU_DEMANGLING) + { + expect_func = 1; + } + oldmangled = NULL; + break; + + case 'S': + /* Static member function */ + if (oldmangled == NULL) + { + oldmangled = *mangled; + } + (*mangled)++; + work -> static_type = 1; + break; + + case 'C': + /* a const member function */ + if (oldmangled == NULL) + { + oldmangled = *mangled; + } + (*mangled)++; + work -> const_type = 1; + break; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (oldmangled == NULL) + { + oldmangled = *mangled; + } + success = demangle_class (work, mangled, declp); + if (success) + { + remember_type (work, oldmangled, *mangled - oldmangled); + } + if (AUTO_DEMANGLING || GNU_DEMANGLING) + { + expect_func = 1; + } + oldmangled = NULL; + break; + + case 'F': + /* Function */ + /* ARM style demangling includes a specific 'F' character after + the class name. For GNU style, it is just implied. So we can + safely just consume any 'F' at this point and be compatible + with either style. */ + + oldmangled = NULL; + func_done = 1; + (*mangled)++; + + /* For lucid/ARM style we have to forget any types we might + have remembered up to this point, since they were not argument + types. GNU style considers all types seen as available for + back references. See comment in demangle_args() */ + + if (LUCID_DEMANGLING || ARM_DEMANGLING) + { + forget_types (work); + } + success = demangle_args (work, mangled, declp); + break; + + case 't': + /* G++ Template */ + string_init(&trawname); + string_init(&tname); + if (oldmangled == NULL) + { + oldmangled = *mangled; + } + success = demangle_template (work, mangled, &tname, &trawname); + if (success) + { + remember_type (work, oldmangled, *mangled - oldmangled); + } + string_append(&tname, "::"); + string_prepends(declp, &tname); + if (work -> destructor & 1) + { + string_prepend (&trawname, "~"); + string_appends (declp, &trawname); + work->destructor -= 1; + } + if ((work->constructor & 1) || (work->destructor & 1)) + { + string_appends (declp, &trawname); + work->constructor -= 1; + } + string_delete(&trawname); + string_delete(&tname); + oldmangled = NULL; + expect_func = 1; + break; + + case '_': + /* At the outermost level, we cannot have a return type specified, + so if we run into another '_' at this point we are dealing with + a mangled name that is either bogus, or has been mangled by + some algorithm we don't know how to deal with. So just + reject the entire demangling. */ + success = 0; + break; + + default: + if (AUTO_DEMANGLING || GNU_DEMANGLING) + { + /* Assume we have stumbled onto the first outermost function + argument token, and start processing args. */ + func_done = 1; + success = demangle_args (work, mangled, declp); + } + else + { + /* Non-GNU demanglers use a specific token to mark the start + of the outermost function argument tokens. Typically 'F', + for ARM-demangling, for example. So if we find something + we are not prepared for, it must be an error. */ + success = 0; + } + break; + } +/* + if (AUTO_DEMANGLING || GNU_DEMANGLING) +*/ + { + if (success && expect_func) + { + func_done = 1; + success = demangle_args (work, mangled, declp); + } + } + } + if (success && !func_done) + { + if (AUTO_DEMANGLING || GNU_DEMANGLING) + { + /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and + bar__3fooi is 'foo::bar(int)'. We get here when we find the + first case, and need to ensure that the '(void)' gets added to + the current declp. Note that with ARM, the first case + represents the name of a static data member 'foo::bar', + which is in the current declp, so we leave it alone. */ + success = demangle_args (work, mangled, declp); + } + } + if (success && work -> static_type && PRINT_ARG_TYPES) + { + string_append (declp, " static"); + } + if (success && work -> const_type && PRINT_ARG_TYPES) + { + string_append (declp, " const"); + } + return (success); +} + +#if 0 + +static int +demangle_method_args (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int success = 0; + + if (work -> static_type) + { + string_append (declp, *mangled + 1); + *mangled += strlen (*mangled); + success = 1; + } + else + { + success = demangle_args (work, mangled, declp); + } + return (success); +} + +#endif + +static int +demangle_template (work, mangled, tname, trawname) + struct work_stuff *work; + const char **mangled; + string *tname; + string *trawname; +{ + int i; + int is_pointer; + int is_real; + int is_integral; + int is_char; + int is_bool; + int r; + int need_comma = 0; + int success = 0; + int done; + const char *old_p; + const char *start; + int symbol_len; + string temp; + + (*mangled)++; + start = *mangled; + /* get template name */ + if ((r = consume_count (mangled)) == 0 || strlen (*mangled) < r) + { + return (0); + } + if (trawname) + string_appendn (trawname, *mangled, r); + string_appendn (tname, *mangled, r); + *mangled += r; + string_append (tname, "<"); + /* get size of template parameter list */ + if (!get_count (mangled, &r)) + { + return (0); + } + for (i = 0; i < r; i++) + { + if (need_comma) + { + string_append (tname, ", "); + } + /* Z for type parameters */ + if (**mangled == 'Z') + { + (*mangled)++; + /* temp is initialized in do_type */ + success = do_type (work, mangled, &temp); + if (success) + { + string_appends (tname, &temp); + } + string_delete(&temp); + if (!success) + { + break; + } + } + else + { + /* otherwise, value parameter */ + old_p = *mangled; + is_pointer = 0; + is_real = 0; + is_integral = 0; + is_char = 0; + done = 0; + /* temp is initialized in do_type */ + success = do_type (work, mangled, &temp); +/* + if (success) + { + string_appends (tname, &temp); + } +*/ + string_delete(&temp); + if (!success) + { + break; + } +/* + string_append (tname, "="); +*/ + while (*old_p && !done) + { + switch (*old_p) + { + case 'P': + case 'p': + case 'R': + done = is_pointer = 1; + break; + case 'C': /* const */ + case 'S': /* explicitly signed [char] */ + case 'U': /* unsigned */ + case 'V': /* volatile */ + case 'F': /* function */ + case 'M': /* member function */ + case 'O': /* ??? */ + old_p++; + continue; + case 'Q': /* qualified name */ + done = is_integral = 1; + break; + case 'T': /* remembered type */ + abort (); + break; + case 'v': /* void */ + abort (); + break; + case 'x': /* long long */ + case 'l': /* long */ + case 'i': /* int */ + case 's': /* short */ + case 'w': /* wchar_t */ + done = is_integral = 1; + break; + case 'b': /* bool */ + done = is_bool = 1; + break; + case 'c': /* char */ + done = is_char = 1; + break; + case 'r': /* long double */ + case 'd': /* double */ + case 'f': /* float */ + done = is_real = 1; + break; + default: + /* it's probably user defined type, let's assume + it's integral, it seems hard to figure out + what it really is */ + done = is_integral = 1; + } + } + if (is_integral) + { + if (**mangled == 'm') + { + string_appendn (tname, "-", 1); + (*mangled)++; + } + while (isdigit (**mangled)) + { + string_appendn (tname, *mangled, 1); + (*mangled)++; + } + } + else if (is_char) + { + char tmp[2]; + int val; + if (**mangled == 'm') + { + string_appendn (tname, "-", 1); + (*mangled)++; + } + string_appendn (tname, "'", 1); + val = consume_count(mangled); + if (val == 0) + { + success = 0; + break; + } + tmp[0] = (char)val; + tmp[1] = '\0'; + string_appendn (tname, &tmp[0], 1); + string_appendn (tname, "'", 1); + } + else if (is_bool) + { + int val = consume_count (mangled); + if (val == 0) + string_appendn (tname, "false", 5); + else if (val == 1) + string_appendn (tname, "true", 4); + else + success = 0; + } + else if (is_real) + { + if (**mangled == 'm') + { + string_appendn (tname, "-", 1); + (*mangled)++; + } + while (isdigit (**mangled)) + { + string_appendn (tname, *mangled, 1); + (*mangled)++; + } + if (**mangled == '.') /* fraction */ + { + string_appendn (tname, ".", 1); + (*mangled)++; + while (isdigit (**mangled)) + { + string_appendn (tname, *mangled, 1); + (*mangled)++; + } + } + if (**mangled == 'e') /* exponent */ + { + string_appendn (tname, "e", 1); + (*mangled)++; + while (isdigit (**mangled)) + { + string_appendn (tname, *mangled, 1); + (*mangled)++; + } + } + } + else if (is_pointer) + { + if (!get_count (mangled, &symbol_len)) + { + success = 0; + break; + } + string_appendn (tname, *mangled, symbol_len); + *mangled += symbol_len; + } + } + need_comma = 1; + } + if (tname->p[-1] == '>') + string_append (tname, " "); + string_append (tname, ">"); + +/* + if (work -> static_type) + { + string_append (declp, *mangled + 1); + *mangled += strlen (*mangled); + success = 1; + } + else + { + success = demangle_args (work, mangled, declp); + } + } +*/ + return (success); +} + +static int +arm_pt (work, mangled, n, anchor, args) + struct work_stuff *work; + const char *mangled; + int n; + const char **anchor, **args; +{ + /* ARM template? */ + if (ARM_DEMANGLING && (*anchor = mystrstr (mangled, "__pt__"))) + { + int len; + *args = *anchor + 6; + len = consume_count (args); + if (*args + len == mangled + n && **args == '_') + { + ++*args; + return 1; + } + } + return 0; +} + +static void +demangle_arm_pt (work, mangled, n, declp) + struct work_stuff *work; + const char **mangled; + int n; + string *declp; +{ + const char *p; + const char *args; + const char *e = *mangled + n; + + /* ARM template? */ + if (arm_pt (work, *mangled, n, &p, &args)) + { + string arg; + string_init (&arg); + string_appendn (declp, *mangled, p - *mangled); + string_append (declp, "<"); + /* should do error checking here */ + while (args < e) { + string_clear (&arg); + do_type (work, &args, &arg); + string_appends (declp, &arg); + string_append (declp, ","); + } + string_delete (&arg); + --declp->p; + string_append (declp, ">"); + } + else + { + string_appendn (declp, *mangled, n); + } + *mangled += n; +} + +static int +demangle_class_name (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int n; + int success = 0; + + n = consume_count (mangled); + if (strlen (*mangled) >= n) + { + demangle_arm_pt (work, mangled, n, declp); + success = 1; + } + + return (success); +} + +/* + +LOCAL FUNCTION + + demangle_class -- demangle a mangled class sequence + +SYNOPSIS + + static int + demangle_class (struct work_stuff *work, const char **mangled, + strint *declp) + +DESCRIPTION + + DECLP points to the buffer into which demangling is being done. + + *MANGLED points to the current token to be demangled. On input, + it points to a mangled class (I.E. "3foo", "13verylongclass", etc.) + On exit, it points to the next token after the mangled class on + success, or the first unconsumed token on failure. + + If the CONSTRUCTOR or DESTRUCTOR flags are set in WORK, then + we are demangling a constructor or destructor. In this case + we prepend "class::class" or "class::~class" to DECLP. + + Otherwise, we prepend "class::" to the current DECLP. + + Reset the constructor/destructor flags once they have been + "consumed". This allows demangle_class to be called later during + the same demangling, to do normal class demangling. + + Returns 1 if demangling is successful, 0 otherwise. + +*/ + +static int +demangle_class (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int success = 0; + string class_name; + + string_init (&class_name); + if (demangle_class_name (work, mangled, &class_name)) + { + if ((work->constructor & 1) || (work->destructor & 1)) + { + string_prepends (declp, &class_name); + if (work -> destructor & 1) + { + string_prepend (declp, "~"); + work -> destructor -= 1; + } + else + { + work -> constructor -= 1; + } + } + string_prepend (declp, "::"); + string_prepends (declp, &class_name); + success = 1; + } + string_delete (&class_name); + return (success); +} + +/* + +LOCAL FUNCTION + + demangle_prefix -- consume the mangled name prefix and find signature + +SYNOPSIS + + static int + demangle_prefix (struct work_stuff *work, const char **mangled, + string *declp); + +DESCRIPTION + + Consume and demangle the prefix of the mangled name. + + DECLP points to the string buffer into which demangled output is + placed. On entry, the buffer is empty. On exit it contains + the root function name, the demangled operator name, or in some + special cases either nothing or the completely demangled result. + + MANGLED points to the current pointer into the mangled name. As each + token of the mangled name is consumed, it is updated. Upon entry + the current mangled name pointer points to the first character of + the mangled name. Upon exit, it should point to the first character + of the signature if demangling was successful, or to the first + unconsumed character if demangling of the prefix was unsuccessful. + + Returns 1 on success, 0 otherwise. + */ + +static int +demangle_prefix (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int success = 1; + const char *scan; + int i; + + if (strlen(*mangled) >= 11 && strncmp(*mangled, "_GLOBAL_", 8) == 0) + { + char *marker = strchr (cplus_markers, (*mangled)[8]); + if (marker != NULL && *marker == (*mangled)[10]) + { + if ((*mangled)[9] == 'D') + { + /* it's a GNU global destructor to be executed at program exit */ + (*mangled) += 11; + work->destructor = 2; + if (gnu_special (work, mangled, declp)) + return success; + } + else if ((*mangled)[9] == 'I') + { + /* it's a GNU global constructor to be executed at program init */ + (*mangled) += 11; + work->constructor = 2; + if (gnu_special (work, mangled, declp)) + return success; + } + } + } + else if (ARM_DEMANGLING && strncmp(*mangled, "__std__", 7) == 0) + { + /* it's a ARM global destructor to be executed at program exit */ + (*mangled) += 7; + work->destructor = 2; + } + else if (ARM_DEMANGLING && strncmp(*mangled, "__sti__", 7) == 0) + { + /* it's a ARM global constructor to be executed at program initial */ + (*mangled) += 7; + work->constructor = 2; + } + +/* This block of code is a reduction in strength time optimization + of: + scan = mystrstr (*mangled, "__"); */ + + { + scan = *mangled; + + do { + scan = strchr (scan, '_'); + } while (scan != NULL && *++scan != '_'); + + if (scan != NULL) --scan; + } + + if (scan != NULL) + { + /* We found a sequence of two or more '_', ensure that we start at + the last pair in the sequence. */ + i = strspn (scan, "_"); + if (i > 2) + { + scan += (i - 2); + } + } + + if (scan == NULL) + { + success = 0; + } + else if (work -> static_type) + { + if (!isdigit (scan[0]) && (scan[0] != 't')) + { + success = 0; + } + } + else if ((scan == *mangled) && + (isdigit (scan[2]) || (scan[2] == 'Q') || (scan[2] == 't'))) + { + /* The ARM says nothing about the mangling of local variables. + But cfront mangles local variables by prepending __ + to them. As an extension to ARM demangling we handle this case. */ + if ((LUCID_DEMANGLING || ARM_DEMANGLING) && isdigit (scan[2])) + { + *mangled = scan + 2; + consume_count (mangled); + string_append (declp, *mangled); + *mangled += strlen (*mangled); + success = 1; + } + else + { + /* A GNU style constructor starts with __[0-9Qt]. But cfront uses + names like __Q2_3foo3bar for nested type names. So don't accept + this style of constructor for cfront demangling. */ + if (!(LUCID_DEMANGLING || ARM_DEMANGLING)) + work -> constructor += 1; + *mangled = scan + 2; + } + } + else if ((scan == *mangled) && !isdigit (scan[2]) && (scan[2] != 't')) + { + /* Mangled name starts with "__". Skip over any leading '_' characters, + then find the next "__" that separates the prefix from the signature. + */ + if (!(ARM_DEMANGLING || LUCID_DEMANGLING) + || (arm_special (work, mangled, declp) == 0)) + { + while (*scan == '_') + { + scan++; + } + if ((scan = mystrstr (scan, "__")) == NULL || (*(scan + 2) == '\0')) + { + /* No separator (I.E. "__not_mangled"), or empty signature + (I.E. "__not_mangled_either__") */ + success = 0; + } + else + { + demangle_function_name (work, mangled, declp, scan); + } + } + } + else if (ARM_DEMANGLING && scan[2] == 'p' && scan[3] == 't') + { + /* Cfront-style parameterized type. Handled later as a signature. */ + success = 1; + + /* ARM template? */ + demangle_arm_pt (work, mangled, strlen (*mangled), declp); + } + else if (*(scan + 2) != '\0') + { + /* Mangled name does not start with "__" but does have one somewhere + in there with non empty stuff after it. Looks like a global + function name. */ + demangle_function_name (work, mangled, declp, scan); + } + else + { + /* Doesn't look like a mangled name */ + success = 0; + } + + if (!success && (work->constructor == 2 || work->destructor == 2)) + { + string_append (declp, *mangled); + *mangled += strlen (*mangled); + success = 1; + } + return (success); +} + +/* + +LOCAL FUNCTION + + gnu_special -- special handling of gnu mangled strings + +SYNOPSIS + + static int + gnu_special (struct work_stuff *work, const char **mangled, + string *declp); + + +DESCRIPTION + + Process some special GNU style mangling forms that don't fit + the normal pattern. For example: + + _$_3foo (destructor for class foo) + _vt$foo (foo virtual table) + _vt$foo$bar (foo::bar virtual table) + __vt_foo (foo virtual table, new style with thunks) + _3foo$varname (static data member) + _Q22rs2tu$vw (static data member) + __t6vector1Zii (constructor with template) + __thunk_4__$_7ostream (virtual function thunk) + */ + +static int +gnu_special (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int n; + int success = 1; + const char *p; + + if ((*mangled)[0] == '_' + && strchr (cplus_markers, (*mangled)[1]) != NULL + && (*mangled)[2] == '_') + { + /* Found a GNU style destructor, get past "__" */ + (*mangled) += 3; + work -> destructor += 1; + } + else if ((*mangled)[0] == '_' + && (((*mangled)[1] == '_' + && (*mangled)[2] == 'v' + && (*mangled)[3] == 't' + && (*mangled)[4] == '_') + || ((*mangled)[1] == 'v' + && (*mangled)[2] == 't' + && strchr (cplus_markers, (*mangled)[3]) != NULL))) + { + /* Found a GNU style virtual table, get past "_vt" + and create the decl. Note that we consume the entire mangled + input string, which means that demangle_signature has no work + to do. */ + if ((*mangled)[2] == 'v') + (*mangled) += 5; /* New style, with thunks: "__vt_" */ + else + (*mangled) += 4; /* Old style, no thunks: "_vt" */ + while (**mangled != '\0') + { + p = strpbrk (*mangled, cplus_markers); + switch (**mangled) + { + case 'Q': + success = demangle_qualified (work, mangled, declp, 0, 1); + break; + case 't': + success = demangle_template (work, mangled, declp, 0); + break; + default: + if (isdigit(*mangled[0])) + { + n = consume_count(mangled); + } + else + { + n = strcspn (*mangled, cplus_markers); + } + string_appendn (declp, *mangled, n); + (*mangled) += n; + } + + if (success && ((p == NULL) || (p == *mangled))) + { + if (p != NULL) + { + string_append (declp, "::"); + (*mangled)++; + } + } + else + { + success = 0; + break; + } + } + if (success) + string_append (declp, " virtual table"); + } + else if ((*mangled)[0] == '_' + && (strchr("0123456789Qt", (*mangled)[1]) != NULL) + && (p = strpbrk (*mangled, cplus_markers)) != NULL) + { + /* static data member, "_3foo$varname" for example */ + (*mangled)++; + switch (**mangled) + { + case 'Q': + success = demangle_qualified (work, mangled, declp, 0, 1); + break; + case 't': + success = demangle_template (work, mangled, declp, 0); + break; + default: + n = consume_count (mangled); + string_appendn (declp, *mangled, n); + (*mangled) += n; + } + if (success && (p == *mangled)) + { + /* Consumed everything up to the cplus_marker, append the + variable name. */ + (*mangled)++; + string_append (declp, "::"); + n = strlen (*mangled); + string_appendn (declp, *mangled, n); + (*mangled) += n; + } + else + { + success = 0; + } + } + else if (strncmp (*mangled, "__thunk_", 8) == 0) + { + int delta = ((*mangled) += 8, consume_count (mangled)); + char *method = cplus_demangle (++*mangled, work->options); + if (method) + { + char buf[50]; + sprintf (buf, "virtual function thunk (delta:%d) for ", -delta); + string_append (declp, buf); + string_append (declp, method); + free (method); + n = strlen (*mangled); + (*mangled) += n; + } + else + { + success = 0; + } + } + else + { + success = 0; + } + return (success); +} + +/* + +LOCAL FUNCTION + + arm_special -- special handling of ARM/lucid mangled strings + +SYNOPSIS + + static int + arm_special (struct work_stuff *work, const char **mangled, + string *declp); + + +DESCRIPTION + + Process some special ARM style mangling forms that don't fit + the normal pattern. For example: + + __vtbl__3foo (foo virtual table) + __vtbl__3foo__3bar (bar::foo virtual table) + + */ + +static int +arm_special (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + int n; + int success = 1; + const char *scan; + + if (strncmp (*mangled, ARM_VTABLE_STRING, ARM_VTABLE_STRLEN) == 0) + { + /* Found a ARM style virtual table, get past ARM_VTABLE_STRING + and create the decl. Note that we consume the entire mangled + input string, which means that demangle_signature has no work + to do. */ + scan = *mangled + ARM_VTABLE_STRLEN; + while (*scan != '\0') /* first check it can be demangled */ + { + n = consume_count (&scan); + if (n==0) + { + return (0); /* no good */ + } + scan += n; + if (scan[0] == '_' && scan[1] == '_') + { + scan += 2; + } + } + (*mangled) += ARM_VTABLE_STRLEN; + while (**mangled != '\0') + { + n = consume_count (mangled); + string_prependn (declp, *mangled, n); + (*mangled) += n; + if ((*mangled)[0] == '_' && (*mangled)[1] == '_') + { + string_prepend (declp, "::"); + (*mangled) += 2; + } + } + string_append (declp, " virtual table"); + } + else + { + success = 0; + } + return (success); +} + +/* + +LOCAL FUNCTION + + demangle_qualified -- demangle 'Q' qualified name strings + +SYNOPSIS + + static int + demangle_qualified (struct work_stuff *, const char *mangled, + string *result, int isfuncname, int append); + +DESCRIPTION + + Demangle a qualified name, such as "Q25Outer5Inner" which is + the mangled form of "Outer::Inner". The demangled output is + prepended or appended to the result string according to the + state of the append flag. + + If isfuncname is nonzero, then the qualified name we are building + is going to be used as a member function name, so if it is a + constructor or destructor function, append an appropriate + constructor or destructor name. I.E. for the above example, + the result for use as a constructor is "Outer::Inner::Inner" + and the result for use as a destructor is "Outer::Inner::~Inner". + +BUGS + + Numeric conversion is ASCII dependent (FIXME). + + */ + +static int +demangle_qualified (work, mangled, result, isfuncname, append) + struct work_stuff *work; + const char **mangled; + string *result; + int isfuncname; + int append; +{ + int qualifiers; + int namelength; + int success = 1; + const char *p; + char num[2]; + string temp; + + string_init (&temp); + switch ((*mangled)[1]) + { + case '_': + /* GNU mangled name with more than 9 classes. The count is preceded + by an underscore (to distinguish it from the <= 9 case) and followed + by an underscore. */ + p = *mangled + 2; + qualifiers = atoi (p); + if (!isdigit (*p) || *p == '0') + success = 0; + + /* Skip the digits. */ + while (isdigit (*p)) + ++p; + + if (*p != '_') + success = 0; + + *mangled = p + 1; + break; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + /* The count is in a single digit. */ + num[0] = (*mangled)[1]; + num[1] = '\0'; + qualifiers = atoi (num); + + /* If there is an underscore after the digit, skip it. This is + said to be for ARM-qualified names, but the ARM makes no + mention of such an underscore. Perhaps cfront uses one. */ + if ((*mangled)[2] == '_') + { + (*mangled)++; + } + (*mangled) += 2; + break; + + case '0': + default: + success = 0; + } + + if (!success) + return success; + + /* Pick off the names and collect them in the temp buffer in the order + in which they are found, separated by '::'. */ + + while (qualifiers-- > 0) + { + if (*mangled[0] == '_') + *mangled = *mangled + 1; + if (*mangled[0] == 't') + { + success = demangle_template(work, mangled, &temp, 0); + if (!success) break; + } + else + { + namelength = consume_count (mangled); + if (strlen (*mangled) < namelength) + { + /* Simple sanity check failed */ + success = 0; + break; + } + string_appendn (&temp, *mangled, namelength); + *mangled += namelength; + } + if (qualifiers > 0) + { + string_appendn (&temp, "::", 2); + } + } + + /* If we are using the result as a function name, we need to append + the appropriate '::' separated constructor or destructor name. + We do this here because this is the most convenient place, where + we already have a pointer to the name and the length of the name. */ + + if (isfuncname && (work->constructor & 1 || work->destructor & 1)) + { + string_appendn (&temp, "::", 2); + if (work -> destructor & 1) + { + string_append (&temp, "~"); + } + string_appendn (&temp, (*mangled) - namelength, namelength); + } + + /* Now either prepend the temp buffer to the result, or append it, + depending upon the state of the append flag. */ + + if (append) + { + string_appends (result, &temp); + } + else + { + if (!STRING_EMPTY (result)) + { + string_appendn (&temp, "::", 2); + } + string_prepends (result, &temp); + } + + string_delete (&temp); + return (success); +} + +/* + +LOCAL FUNCTION + + get_count -- convert an ascii count to integer, consuming tokens + +SYNOPSIS + + static int + get_count (const char **type, int *count) + +DESCRIPTION + + Return 0 if no conversion is performed, 1 if a string is converted. +*/ + +static int +get_count (type, count) + const char **type; + int *count; +{ + const char *p; + int n; + + if (!isdigit (**type)) + { + return (0); + } + else + { + *count = **type - '0'; + (*type)++; + if (isdigit (**type)) + { + p = *type; + n = *count; + do + { + n *= 10; + n += *p - '0'; + p++; + } + while (isdigit (*p)); + if (*p == '_') + { + *type = p + 1; + *count = n; + } + } + } + return (1); +} + +/* result will be initialised here; it will be freed on failure */ + +static int +do_type (work, mangled, result) + struct work_stuff *work; + const char **mangled; + string *result; +{ + int n; + int done; + int success; + string decl; + const char *remembered_type; + int constp; + int volatilep; + + string_init (&decl); + string_init (result); + + done = 0; + success = 1; + while (success && !done) + { + int member; + switch (**mangled) + { + + /* A pointer type */ + case 'P': + case 'p': + (*mangled)++; + string_prepend (&decl, "*"); + break; + + /* A reference type */ + case 'R': + (*mangled)++; + string_prepend (&decl, "&"); + break; + + /* An array */ + case 'A': + { + const char *p = ++(*mangled); + + string_prepend (&decl, "("); + string_append (&decl, ")["); + /* Copy anything up until the next underscore (the size of the + array). */ + while (**mangled && **mangled != '_') + ++(*mangled); + if (**mangled == '_') + { + string_appendn (&decl, p, *mangled - p); + string_append (&decl, "]"); + *mangled += 1; + } + else + success = 0; + break; + } + + /* A back reference to a previously seen type */ + case 'T': + (*mangled)++; + if (!get_count (mangled, &n) || n >= work -> ntypes) + { + success = 0; + } + else + { + remembered_type = work -> typevec[n]; + mangled = &remembered_type; + } + break; + + /* A function */ + case 'F': + (*mangled)++; + if (!STRING_EMPTY (&decl) && decl.b[0] == '*') + { + string_prepend (&decl, "("); + string_append (&decl, ")"); + } + /* After picking off the function args, we expect to either find the + function return type (preceded by an '_') or the end of the + string. */ + if (!demangle_args (work, mangled, &decl) + || (**mangled != '_' && **mangled != '\0')) + { + success = 0; + } + if (success && (**mangled == '_')) + { + (*mangled)++; + } + break; + + case 'M': + case 'O': + { + constp = 0; + volatilep = 0; + + member = **mangled == 'M'; + (*mangled)++; + if (!isdigit (**mangled)) + { + success = 0; + break; + } + n = consume_count (mangled); + if (strlen (*mangled) < n) + { + success = 0; + break; + } + string_append (&decl, ")"); + string_prepend (&decl, "::"); + string_prependn (&decl, *mangled, n); + string_prepend (&decl, "("); + *mangled += n; + if (member) + { + if (**mangled == 'C') + { + (*mangled)++; + constp = 1; + } + if (**mangled == 'V') + { + (*mangled)++; + volatilep = 1; + } + if (*(*mangled)++ != 'F') + { + success = 0; + break; + } + } + if ((member && !demangle_args (work, mangled, &decl)) + || **mangled != '_') + { + success = 0; + break; + } + (*mangled)++; + if (! PRINT_ANSI_QUALIFIERS) + { + break; + } + if (constp) + { + APPEND_BLANK (&decl); + string_append (&decl, "const"); + } + if (volatilep) + { + APPEND_BLANK (&decl); + string_append (&decl, "volatile"); + } + break; + } + case 'G': + (*mangled)++; + break; + + case 'C': + (*mangled)++; +/* + if ((*mangled)[1] == 'P') + { +*/ + if (PRINT_ANSI_QUALIFIERS) + { + if (!STRING_EMPTY (&decl)) + { + string_prepend (&decl, " "); + } + string_prepend (&decl, "const"); + } + break; +/* + } +*/ + + /* fall through */ + default: + done = 1; + break; + } + } + + switch (**mangled) + { + /* A qualified name, such as "Outer::Inner". */ + case 'Q': + success = demangle_qualified (work, mangled, result, 0, 1); + break; + + default: + success = demangle_fund_type (work, mangled, result); + break; + } + + if (success) + { + if (!STRING_EMPTY (&decl)) + { + string_append (result, " "); + string_appends (result, &decl); + } + } + else + { + string_delete (result); + } + string_delete (&decl); + return (success); +} + +/* Given a pointer to a type string that represents a fundamental type + argument (int, long, unsigned int, etc) in TYPE, a pointer to the + string in which the demangled output is being built in RESULT, and + the WORK structure, decode the types and add them to the result. + + For example: + + "Ci" => "const int" + "Sl" => "signed long" + "CUs" => "const unsigned short" + + */ + +static int +demangle_fund_type (work, mangled, result) + struct work_stuff *work; + const char **mangled; + string *result; +{ + int done = 0; + int success = 1; + + /* First pick off any type qualifiers. There can be more than one. */ + + while (!done) + { + switch (**mangled) + { + case 'C': + (*mangled)++; + if (PRINT_ANSI_QUALIFIERS) + { + APPEND_BLANK (result); + string_append (result, "const"); + } + break; + case 'U': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "unsigned"); + break; + case 'S': /* signed char only */ + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "signed"); + break; + case 'V': + (*mangled)++; + if (PRINT_ANSI_QUALIFIERS) + { + APPEND_BLANK (result); + string_append (result, "volatile"); + } + break; + default: + done = 1; + break; + } + } + + /* Now pick off the fundamental type. There can be only one. */ + + switch (**mangled) + { + case '\0': + case '_': + break; + case 'v': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "void"); + break; + case 'x': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "long long"); + break; + case 'l': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "long"); + break; + case 'i': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "int"); + break; + case 's': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "short"); + break; + case 'b': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "bool"); + break; + case 'c': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "char"); + break; + case 'w': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "wchar_t"); + break; + case 'r': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "long double"); + break; + case 'd': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "double"); + break; + case 'f': + (*mangled)++; + APPEND_BLANK (result); + string_append (result, "float"); + break; + case 'G': + (*mangled)++; + if (!isdigit (**mangled)) + { + success = 0; + break; + } + /* fall through */ + /* An explicit type, such as "6mytype" or "7integer" */ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + APPEND_BLANK (result); + if (!demangle_class_name (work, mangled, result)) { + --result->p; + success = 0; + } + break; + case 't': + success = demangle_template(work,mangled, result, 0); + break; + default: + success = 0; + break; + } + + return (success); +} + +/* `result' will be initialized in do_type; it will be freed on failure */ + +static int +do_arg (work, mangled, result) + struct work_stuff *work; + const char **mangled; + string *result; +{ + const char *start = *mangled; + + if (!do_type (work, mangled, result)) + { + return (0); + } + else + { + remember_type (work, start, *mangled - start); + return (1); + } +} + +static void +remember_type (work, start, len) + struct work_stuff *work; + const char *start; + int len; +{ + char *tem; + + if (work -> ntypes >= work -> typevec_size) + { + if (work -> typevec_size == 0) + { + work -> typevec_size = 3; + work -> typevec = + (char **) xmalloc (sizeof (char *) * work -> typevec_size); + } + else + { + work -> typevec_size *= 2; + work -> typevec = + (char **) xrealloc ((char *)work -> typevec, + sizeof (char *) * work -> typevec_size); + } + } + tem = xmalloc (len + 1); + memcpy (tem, start, len); + tem[len] = '\0'; + work -> typevec[work -> ntypes++] = tem; +} + +/* Forget the remembered types, but not the type vector itself. */ + +static void +forget_types (work) + struct work_stuff *work; +{ + int i; + + while (work -> ntypes > 0) + { + i = --(work -> ntypes); + if (work -> typevec[i] != NULL) + { + free (work -> typevec[i]); + work -> typevec[i] = NULL; + } + } +} + +/* Process the argument list part of the signature, after any class spec + has been consumed, as well as the first 'F' character (if any). For + example: + + "__als__3fooRT0" => process "RT0" + "complexfunc5__FPFPc_PFl_i" => process "PFPc_PFl_i" + + DECLP must be already initialised, usually non-empty. It won't be freed + on failure. + + Note that g++ differs significantly from ARM and lucid style mangling + with regards to references to previously seen types. For example, given + the source fragment: + + class foo { + public: + foo::foo (int, foo &ia, int, foo &ib, int, foo &ic); + }; + + foo::foo (int, foo &ia, int, foo &ib, int, foo &ic) { ia = ib = ic; } + void foo (int, foo &ia, int, foo &ib, int, foo &ic) { ia = ib = ic; } + + g++ produces the names: + + __3fooiRT0iT2iT2 + foo__FiR3fooiT1iT1 + + while lcc (and presumably other ARM style compilers as well) produces: + + foo__FiR3fooT1T2T1T2 + __ct__3fooFiR3fooT1T2T1T2 + + Note that g++ bases it's type numbers starting at zero and counts all + previously seen types, while lucid/ARM bases it's type numbers starting + at one and only considers types after it has seen the 'F' character + indicating the start of the function args. For lucid/ARM style, we + account for this difference by discarding any previously seen types when + we see the 'F' character, and subtracting one from the type number + reference. + + */ + +static int +demangle_args (work, mangled, declp) + struct work_stuff *work; + const char **mangled; + string *declp; +{ + string arg; + int need_comma = 0; + int r; + int t; + const char *tem; + char temptype; + + if (PRINT_ARG_TYPES) + { + string_append (declp, "("); + if (**mangled == '\0') + { + string_append (declp, "void"); + } + } + + while (**mangled != '_' && **mangled != '\0' && **mangled != 'e') + { + if ((**mangled == 'N') || (**mangled == 'T')) + { + temptype = *(*mangled)++; + + if (temptype == 'N') + { + if (!get_count (mangled, &r)) + { + return (0); + } + } + else + { + r = 1; + } + if (ARM_DEMANGLING && work -> ntypes >= 10) + { + /* If we have 10 or more types we might have more than a 1 digit + index so we'll have to consume the whole count here. This + will lose if the next thing is a type name preceded by a + count but it's impossible to demangle that case properly + anyway. Eg if we already have 12 types is T12Pc "(..., type1, + Pc, ...)" or "(..., type12, char *, ...)" */ + if ((t = consume_count(mangled)) == 0) + { + return (0); + } + } + else + { + if (!get_count (mangled, &t)) + { + return (0); + } + } + if (LUCID_DEMANGLING || ARM_DEMANGLING) + { + t--; + } + /* Validate the type index. Protect against illegal indices from + malformed type strings. */ + if ((t < 0) || (t >= work -> ntypes)) + { + return (0); + } + while (--r >= 0) + { + tem = work -> typevec[t]; + if (need_comma && PRINT_ARG_TYPES) + { + string_append (declp, ", "); + } + if (!do_arg (work, &tem, &arg)) + { + return (0); + } + if (PRINT_ARG_TYPES) + { + string_appends (declp, &arg); + } + string_delete (&arg); + need_comma = 1; + } + } + else + { + if (need_comma & PRINT_ARG_TYPES) + { + string_append (declp, ", "); + } + if (!do_arg (work, mangled, &arg)) + { + return (0); + } + if (PRINT_ARG_TYPES) + { + string_appends (declp, &arg); + } + string_delete (&arg); + need_comma = 1; + } + } + + if (**mangled == 'e') + { + (*mangled)++; + if (PRINT_ARG_TYPES) + { + if (need_comma) + { + string_append (declp, ","); + } + string_append (declp, "..."); + } + } + + if (PRINT_ARG_TYPES) + { + string_append (declp, ")"); + } + return (1); +} + +static void +demangle_function_name (work, mangled, declp, scan) + struct work_stuff *work; + const char **mangled; + string *declp; + const char *scan; +{ + int i; + int len; + string type; + const char *tem; + + string_appendn (declp, (*mangled), scan - (*mangled)); + string_need (declp, 1); + *(declp -> p) = '\0'; + + /* Consume the function name, including the "__" separating the name + from the signature. We are guaranteed that SCAN points to the + separator. */ + + (*mangled) = scan + 2; + + if (LUCID_DEMANGLING || ARM_DEMANGLING) + { + + /* See if we have an ARM style constructor or destructor operator. + If so, then just record it, clear the decl, and return. + We can't build the actual constructor/destructor decl until later, + when we recover the class name from the signature. */ + + if (strcmp (declp -> b, "__ct") == 0) + { + work -> constructor += 1; + string_clear (declp); + return; + } + else if (strcmp (declp -> b, "__dt") == 0) + { + work -> destructor += 1; + string_clear (declp); + return; + } + } + + if (declp->p - declp->b >= 3 + && declp->b[0] == 'o' + && declp->b[1] == 'p' + && strchr (cplus_markers, declp->b[2]) != NULL) + { + /* see if it's an assignment expression */ + if (declp->p - declp->b >= 10 /* op$assign_ */ + && memcmp (declp->b + 3, "assign_", 7) == 0) + { + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + len = declp->p - declp->b - 10; + if (strlen (optable[i].in) == len + && memcmp (optable[i].in, declp->b + 10, len) == 0) + { + string_clear (declp); + string_append (declp, "operator"); + string_append (declp, optable[i].out); + string_append (declp, "="); + break; + } + } + } + else + { + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + int len = declp->p - declp->b - 3; + if (strlen (optable[i].in) == len + && memcmp (optable[i].in, declp->b + 3, len) == 0) + { + string_clear (declp); + string_append (declp, "operator"); + string_append (declp, optable[i].out); + break; + } + } + } + } + else if (declp->p - declp->b >= 5 && memcmp (declp->b, "type", 4) == 0 + && strchr (cplus_markers, declp->b[4]) != NULL) + { + /* type conversion operator */ + tem = declp->b + 5; + if (do_type (work, &tem, &type)) + { + string_clear (declp); + string_append (declp, "operator "); + string_appends (declp, &type); + string_delete (&type); + } + } + else if (declp->b[0] == '_' && declp->b[1] == '_' + && declp->b[2] == 'o' && declp->b[3] == 'p') + { + /* ANSI. */ + /* type conversion operator. */ + tem = declp->b + 4; + if (do_type (work, &tem, &type)) + { + string_clear (declp); + string_append (declp, "operator "); + string_appends (declp, &type); + string_delete (&type); + } + } + else if (declp->b[0] == '_' && declp->b[1] == '_' + && declp->b[2] >= 'a' && declp->b[2] <= 'z' + && declp->b[3] >= 'a' && declp->b[3] <= 'z') + { + if (declp->b[4] == '\0') + { + /* Operator. */ + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 2 + && memcmp (optable[i].in, declp->b + 2, 2) == 0) + { + string_clear (declp); + string_append (declp, "operator"); + string_append (declp, optable[i].out); + break; + } + } + } + else + { + if (declp->b[2] == 'a' && declp->b[5] == '\0') + { + /* Assignment. */ + for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + { + if (strlen (optable[i].in) == 3 + && memcmp (optable[i].in, declp->b + 2, 3) == 0) + { + string_clear (declp); + string_append (declp, "operator"); + string_append (declp, optable[i].out); + break; + } + } + } + } + } +} + +/* a mini string-handling package */ + +static void +string_need (s, n) + string *s; + int n; +{ + int tem; + + if (s->b == NULL) + { + if (n < 32) + { + n = 32; + } + s->p = s->b = xmalloc (n); + s->e = s->b + n; + } + else if (s->e - s->p < n) + { + tem = s->p - s->b; + n += tem; + n *= 2; + s->b = xrealloc (s->b, n); + s->p = s->b + tem; + s->e = s->b + n; + } +} + +static void +string_delete (s) + string *s; +{ + if (s->b != NULL) + { + free (s->b); + s->b = s->e = s->p = NULL; + } +} + +static void +string_init (s) + string *s; +{ + s->b = s->p = s->e = NULL; +} + +static void +string_clear (s) + string *s; +{ + s->p = s->b; +} + +#if 0 + +static int +string_empty (s) + string *s; +{ + return (s->b == s->p); +} + +#endif + +static void +string_append (p, s) + string *p; + const char *s; +{ + int n; + if (s == NULL || *s == '\0') + return; + n = strlen (s); + string_need (p, n); + memcpy (p->p, s, n); + p->p += n; +} + +static void +string_appends (p, s) + string *p, *s; +{ + int n; + + if (s->b != s->p) + { + n = s->p - s->b; + string_need (p, n); + memcpy (p->p, s->b, n); + p->p += n; + } +} + +static void +string_appendn (p, s, n) + string *p; + const char *s; + int n; +{ + if (n != 0) + { + string_need (p, n); + memcpy (p->p, s, n); + p->p += n; + } +} + +static void +string_prepend (p, s) + string *p; + const char *s; +{ + if (s != NULL && *s != '\0') + { + string_prependn (p, s, strlen (s)); + } +} + +static void +string_prepends (p, s) + string *p, *s; +{ + if (s->b != s->p) + { + string_prependn (p, s->b, s->p - s->b); + } +} + +static void +string_prependn (p, s, n) + string *p; + const char *s; + int n; +{ + char *q; + + if (n != 0) + { + string_need (p, n); + for (q = p->p - 1; q >= p->b; q--) + { + q[n] = q[0]; + } + memcpy (p->b, s, n); + p->p += n; + } +} + +/* To generate a standalone demangler program for testing purposes, + just compile and link this file with -DMAIN and libiberty.a. When + run, it demangles each command line arg, or each stdin string, and + prints the result on stdout. */ + +#ifdef MAIN + +static void +demangle_it (mangled_name) + char *mangled_name; +{ + char *result; + + result = cplus_demangle (mangled_name, DMGL_PARAMS | DMGL_ANSI); + if (result == NULL) + { + printf ("%s\n", mangled_name); + } + else + { + printf ("%s\n", result); + free (result); + } +} + +#include "getopt.h" + +static char *program_name; +static char *program_version = VERSION; + +static void +usage (stream, status) + FILE *stream; + int status; +{ + fprintf (stream, "\ +Usage: %s [-_] [-n] [-s {gnu,lucid,arm}] [--strip-underscores]\n\ + [--no-strip-underscores] [--format={gnu,lucid,arm}]\n\ + [--help] [--version] [arg...]\n", + program_name); + exit (status); +} + +#define MBUF_SIZE 512 +char mbuffer[MBUF_SIZE]; + +/* Defined in the automatically-generated underscore.c. */ +extern int prepends_underscore; + +int strip_underscore = 0; + +static struct option long_options[] = { + {"strip-underscores", no_argument, 0, '_'}, + {"format", required_argument, 0, 's'}, + {"help", no_argument, 0, 'h'}, + {"no-strip-underscores", no_argument, 0, 'n'}, + {"version", no_argument, 0, 'v'}, + {0, no_argument, 0, 0} +}; + +int +main (argc, argv) + int argc; + char **argv; +{ + char *result; + int c; + + program_name = argv[0]; + + strip_underscore = prepends_underscore; + + while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF) + { + switch (c) + { + case '?': + usage (stderr, 1); + break; + case 'h': + usage (stdout, 0); + case 'n': + strip_underscore = 0; + break; + case 'v': + printf ("GNU %s version %s\n", program_name, program_version); + exit (0); + case '_': + strip_underscore = 1; + break; + case 's': + if (strcmp (optarg, "gnu") == 0) + { + current_demangling_style = gnu_demangling; + } + else if (strcmp (optarg, "lucid") == 0) + { + current_demangling_style = lucid_demangling; + } + else if (strcmp (optarg, "arm") == 0) + { + current_demangling_style = arm_demangling; + } + else + { + fprintf (stderr, "%s: unknown demangling style `%s'\n", + program_name, optarg); + exit (1); + } + break; + } + } + + if (optind < argc) + { + for ( ; optind < argc; optind++) + { + demangle_it (argv[optind]); + } + } + else + { + for (;;) + { + int i = 0; + c = getchar (); + /* Try to read a label. */ + while (c != EOF && (isalnum(c) || c == '_' || c == '$' || c == '.')) + { + if (i >= MBUF_SIZE-1) + break; + mbuffer[i++] = c; + c = getchar (); + } + if (i > 0) + { + int skip_first = 0; + + if (mbuffer[0] == '.') + ++skip_first; + if (strip_underscore && mbuffer[skip_first] == '_') + ++skip_first; + + if (skip_first > i) + skip_first = i; + + mbuffer[i] = 0; + + result = cplus_demangle (mbuffer + skip_first, + DMGL_PARAMS | DMGL_ANSI); + if (result) + { + if (mbuffer[0] == '.') + putc ('.', stdout); + fputs (result, stdout); + free (result); + } + else + fputs (mbuffer, stdout); + + fflush (stdout); + } + if (c == EOF) + break; + putchar (c); + } + } + + exit (0); +} + +static void +fatal (str) + char *str; +{ + fprintf (stderr, "%s: %s\n", program_name, str); + exit (1); +} + +char * malloc (); +char * realloc (); + +char * +xmalloc (size) + unsigned size; +{ + register char *value = (char *) malloc (size); + if (value == 0) + fatal ("virtual memory exhausted"); + return value; +} + +char * +xrealloc (ptr, size) + char *ptr; + unsigned size; +{ + register char *value = (char *) realloc (ptr, size); + if (value == 0) + fatal ("virtual memory exhausted"); + return value; +} +#endif /* main */ diff --git a/contrib/gcc/cpp.1 b/contrib/gcc/cpp.1 new file mode 100644 index 00000000000..54c4dfb1983 --- /dev/null +++ b/contrib/gcc/cpp.1 @@ -0,0 +1 @@ +.so man1/cccp.1 diff --git a/contrib/gcc/cpp.texi b/contrib/gcc/cpp.texi new file mode 100644 index 00000000000..1de8371701e --- /dev/null +++ b/contrib/gcc/cpp.texi @@ -0,0 +1,2856 @@ +\input texinfo +@setfilename cpp.info +@settitle The C Preprocessor + +@ignore +@ifinfo +@format +START-INFO-DIR-ENTRY +* Cpp: (cpp). The C preprocessor. +END-INFO-DIR-ENTRY +@end format +@end ifinfo +@end ignore + +@c @smallbook +@c @cropmarks +@c @finalout +@setchapternewpage odd +@ifinfo +This file documents the GNU C Preprocessor. + +Copyright 1987, 1989, 1991, 1992, 1993, 1994, 1995 Free Software +Foundation, Inc. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +@ignore +Permission is granted to process this file through Tex and print the +results, provided the printed document carries copying permission +notice identical to this one except for the removal of this paragraph +(this paragraph not being relevant to the printed manual). + +@end ignore +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided also that +the entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions. +@end ifinfo + +@titlepage +@c @finalout +@title The C Preprocessor +@subtitle Last revised July 1992 +@subtitle for GCC version 2 +@author Richard M. Stallman +@page +@vskip 2pc +This booklet is eventually intended to form the first chapter of a GNU +C Language manual. + +@vskip 0pt plus 1filll +Copyright @copyright{} 1987, 1989, 1991, 1992, 1993, 1994, 1995 Free +Software Foundation, Inc. + +Permission is granted to make and distribute verbatim copies of +this manual provided the copyright notice and this permission notice +are preserved on all copies. + +Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided also that +the entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + +Permission is granted to copy and distribute translations of this manual +into another language, under the above conditions for modified versions. +@end titlepage +@page + +@node Top, Global Actions,, (DIR) +@chapter The C Preprocessor + +The C preprocessor is a @dfn{macro processor} that is used automatically by +the C compiler to transform your program before actual compilation. It is +called a macro processor because it allows you to define @dfn{macros}, +which are brief abbreviations for longer constructs. + +The C preprocessor provides four separate facilities that you can use as +you see fit: + +@itemize @bullet +@item +Inclusion of header files. These are files of declarations that can be +substituted into your program. + +@item +Macro expansion. You can define @dfn{macros}, which are abbreviations +for arbitrary fragments of C code, and then the C preprocessor will +replace the macros with their definitions throughout the program. + +@item +Conditional compilation. Using special preprocessing directives, you +can include or exclude parts of the program according to various +conditions. + +@item +Line control. If you use a program to combine or rearrange source files into +an intermediate file which is then compiled, you can use line control +to inform the compiler of where each source line originally came from. +@end itemize + +C preprocessors vary in some details. This manual discusses the GNU C +preprocessor, the C Compatible Compiler Preprocessor. The GNU C +preprocessor provides a superset of the features of ANSI Standard C. + +ANSI Standard C requires the rejection of many harmless constructs commonly +used by today's C programs. Such incompatibility would be inconvenient for +users, so the GNU C preprocessor is configured to accept these constructs +by default. Strictly speaking, to get ANSI Standard C, you must use the +options @samp{-trigraphs}, @samp{-undef} and @samp{-pedantic}, but in +practice the consequences of having strict ANSI Standard C make it +undesirable to do this. @xref{Invocation}. + +@menu +* Global Actions:: Actions made uniformly on all input files. +* Directives:: General syntax of preprocessing directives. +* Header Files:: How and why to use header files. +* Macros:: How and why to use macros. +* Conditionals:: How and why to use conditionals. +* Combining Sources:: Use of line control when you combine source files. +* Other Directives:: Miscellaneous preprocessing directives. +* Output:: Format of output from the C preprocessor. +* Invocation:: How to invoke the preprocessor; command options. +* Concept Index:: Index of concepts and terms. +* Index:: Index of directives, predefined macros and options. +@end menu + +@node Global Actions, Directives, Top, Top +@section Transformations Made Globally + +Most C preprocessor features are inactive unless you give specific directives +to request their use. (Preprocessing directives are lines starting with +@samp{#}; @pxref{Directives}). But there are three transformations that the +preprocessor always makes on all the input it receives, even in the absence +of directives. + +@itemize @bullet +@item +All C comments are replaced with single spaces. + +@item +Backslash-Newline sequences are deleted, no matter where. This +feature allows you to break long lines for cosmetic purposes without +changing their meaning. + +@item +Predefined macro names are replaced with their expansions +(@pxref{Predefined}). +@end itemize + +The first two transformations are done @emph{before} nearly all other parsing +and before preprocessing directives are recognized. Thus, for example, you +can split a line cosmetically with Backslash-Newline anywhere (except +when trigraphs are in use; see below). + +@example +/* +*/ # /* +*/ defi\ +ne FO\ +O 10\ +20 +@end example + +@noindent +is equivalent into @samp{#define FOO 1020}. You can split even an escape +sequence with Backslash-Newline. For example, you can split @code{"foo\bar"} +between the @samp{\} and the @samp{b} to get + +@example +"foo\\ +bar" +@end example + +@noindent +This behavior is unclean: in all other contexts, a Backslash can be +inserted in a string constant as an ordinary character by writing a double +Backslash, and this creates an exception. But the ANSI C standard requires +it. (Strict ANSI C does not allow Newlines in string constants, so they +do not consider this a problem.) + +But there are a few exceptions to all three transformations. + +@itemize @bullet +@item +C comments and predefined macro names are not recognized inside a +@samp{#include} directive in which the file name is delimited with +@samp{<} and @samp{>}. + +@item +C comments and predefined macro names are never recognized within a +character or string constant. (Strictly speaking, this is the rule, +not an exception, but it is worth noting here anyway.) + +@item +Backslash-Newline may not safely be used within an ANSI ``trigraph''. +Trigraphs are converted before Backslash-Newline is deleted. If you +write what looks like a trigraph with a Backslash-Newline inside, the +Backslash-Newline is deleted as usual, but it is then too late to +recognize the trigraph. + +This exception is relevant only if you use the @samp{-trigraphs} +option to enable trigraph processing. @xref{Invocation}. +@end itemize + +@node Directives, Header Files, Global Actions, Top +@section Preprocessing Directives + +@cindex preprocessing directives +@cindex directives +Most preprocessor features are active only if you use preprocessing directives +to request their use. + +Preprocessing directives are lines in your program that start with @samp{#}. +The @samp{#} is followed by an identifier that is the @dfn{directive name}. +For example, @samp{#define} is the directive that defines a macro. +Whitespace is also allowed before and after the @samp{#}. + +The set of valid directive names is fixed. Programs cannot define new +preprocessing directives. + +Some directive names require arguments; these make up the rest of the directive +line and must be separated from the directive name by whitespace. For example, +@samp{#define} must be followed by a macro name and the intended expansion +of the macro. @xref{Simple Macros}. + +A preprocessing directive cannot be more than one line in normal circumstances. +It may be split cosmetically with Backslash-Newline, but that has no effect +on its meaning. Comments containing Newlines can also divide the +directive into multiple lines, but the comments are changed to Spaces +before the directive is interpreted. The only way a significant Newline +can occur in a preprocessing directive is within a string constant or +character constant. Note that +most C compilers that might be applied to the output from the preprocessor +do not accept string or character constants containing Newlines. + +The @samp{#} and the directive name cannot come from a macro expansion. For +example, if @samp{foo} is defined as a macro expanding to @samp{define}, +that does not make @samp{#foo} a valid preprocessing directive. + +@node Header Files, Macros, Directives, Top +@section Header Files + +@cindex header file +A header file is a file containing C declarations and macro definitions +(@pxref{Macros}) to be shared between several source files. You request +the use of a header file in your program with the C preprocessing directive +@samp{#include}. + +@menu +* Header Uses:: What header files are used for. +* Include Syntax:: How to write @samp{#include} directives. +* Include Operation:: What @samp{#include} does. +* Once-Only:: Preventing multiple inclusion of one header file. +* Inheritance:: Including one header file in another header file. +@end menu + +@node Header Uses, Include Syntax, Header Files, Header Files +@subsection Uses of Header Files + +Header files serve two kinds of purposes. + +@itemize @bullet +@item +@findex system header files +System header files declare the interfaces to parts of the operating +system. You include them in your program to supply the definitions and +declarations you need to invoke system calls and libraries. + +@item +Your own header files contain declarations for interfaces between the +source files of your program. Each time you have a group of related +declarations and macro definitions all or most of which are needed in +several different source files, it is a good idea to create a header +file for them. +@end itemize + +Including a header file produces the same results in C compilation as +copying the header file into each source file that needs it. But such +copying would be time-consuming and error-prone. With a header file, the +related declarations appear in only one place. If they need to be changed, +they can be changed in one place, and programs that include the header file +will automatically use the new version when next recompiled. The header +file eliminates the labor of finding and changing all the copies as well as +the risk that a failure to find one copy will result in inconsistencies +within a program. + +The usual convention is to give header files names that end with +@file{.h}. Avoid unusual characters in header file names, as they +reduce portability. + +@node Include Syntax, Include Operation, Header Uses, Header Files +@subsection The @samp{#include} Directive + +@findex #include +Both user and system header files are included using the preprocessing +directive @samp{#include}. It has three variants: + +@table @code +@item #include <@var{file}> +This variant is used for system header files. It searches for a file +named @var{file} in a list of directories specified by you, then in a +standard list of system directories. You specify directories to +search for header files with the command option @samp{-I} +(@pxref{Invocation}). The option @samp{-nostdinc} inhibits searching +the standard system directories; in this case only the directories +you specify are searched. + +The parsing of this form of @samp{#include} is slightly special +because comments are not recognized within the @samp{<@dots{}>}. +Thus, in @samp{#include } the @samp{/*} does not start a comment +and the directive specifies inclusion of a system header file named +@file{x/*y}. Of course, a header file with such a name is unlikely to +exist on Unix, where shell wildcard features would make it hard to +manipulate.@refill + +The argument @var{file} may not contain a @samp{>} character. It may, +however, contain a @samp{<} character. + +@item #include "@var{file}" +This variant is used for header files of your own program. It +searches for a file named @var{file} first in the current directory, +then in the same directories used for system header files. The +current directory is the directory of the current input file. It is +tried first because it is presumed to be the location of the files +that the current input file refers to. (If the @samp{-I-} option is +used, the special treatment of the current directory is inhibited.) + +The argument @var{file} may not contain @samp{"} characters. If +backslashes occur within @var{file}, they are considered ordinary text +characters, not escape characters. None of the character escape +sequences appropriate to string constants in C are processed. Thus, +@samp{#include "x\n\\y"} specifies a filename containing three +backslashes. It is not clear why this behavior is ever useful, but +the ANSI standard specifies it. + +@item #include @var{anything else} +@cindex computed @samp{#include} +This variant is called a @dfn{computed #include}. Any @samp{#include} +directive whose argument does not fit the above two forms is a computed +include. The text @var{anything else} is checked for macro calls, +which are expanded (@pxref{Macros}). When this is done, the result +must fit one of the above two variants---in particular, the expanded +text must in the end be surrounded by either quotes or angle braces. + +This feature allows you to define a macro which controls the file name +to be used at a later point in the program. One application of this is +to allow a site-specific configuration file for your program to specify +the names of the system include files to be used. This can help in +porting the program to various operating systems in which the necessary +system header files are found in different places. +@end table + +@node Include Operation, Once-Only, Include Syntax, Header Files +@subsection How @samp{#include} Works + +The @samp{#include} directive works by directing the C preprocessor to scan +the specified file as input before continuing with the rest of the current +file. The output from the preprocessor contains the output already +generated, followed by the output resulting from the included file, +followed by the output that comes from the text after the @samp{#include} +directive. For example, given a header file @file{header.h} as follows, + +@example +char *test (); +@end example + +@noindent +and a main program called @file{program.c} that uses the header file, +like this, + +@example +int x; +#include "header.h" + +main () +@{ + printf (test ()); +@} +@end example + +@noindent +the output generated by the C preprocessor for @file{program.c} as input +would be + +@example +int x; +char *test (); + +main () +@{ + printf (test ()); +@} +@end example + +Included files are not limited to declarations and macro definitions; those +are merely the typical uses. Any fragment of a C program can be included +from another file. The include file could even contain the beginning of a +statement that is concluded in the containing file, or the end of a +statement that was started in the including file. However, a comment or a +string or character constant may not start in the included file and finish +in the including file. An unterminated comment, string constant or +character constant in an included file is considered to end (with an error +message) at the end of the file. + +It is possible for a header file to begin or end a syntactic unit such +as a function definition, but that would be very confusing, so don't do +it. + +The line following the @samp{#include} directive is always treated as a +separate line by the C preprocessor even if the included file lacks a final +newline. + +@node Once-Only, Inheritance, Include Operation, Header Files +@subsection Once-Only Include Files +@cindex repeated inclusion +@cindex including just once + +Very often, one header file includes another. It can easily result that a +certain header file is included more than once. This may lead to errors, +if the header file defines structure types or typedefs, and is certainly +wasteful. Therefore, we often wish to prevent multiple inclusion of a +header file. + +The standard way to do this is to enclose the entire real contents of the +file in a conditional, like this: + +@example +#ifndef FILE_FOO_SEEN +#define FILE_FOO_SEEN + +@var{the entire file} + +#endif /* FILE_FOO_SEEN */ +@end example + +The macro @code{FILE_FOO_SEEN} indicates that the file has been included +once already. In a user header file, the macro name should not begin +with @samp{_}. In a system header file, this name should begin with +@samp{__} to avoid conflicts with user programs. In any kind of header +file, the macro name should contain the name of the file and some +additional text, to avoid conflicts with other header files. + +The GNU C preprocessor is programmed to notice when a header file uses +this particular construct and handle it efficiently. If a header file +is contained entirely in a @samp{#ifndef} conditional, then it records +that fact. If a subsequent @samp{#include} specifies the same file, +and the macro in the @samp{#ifndef} is already defined, then the file +is entirely skipped, without even reading it. + +@findex #pragma once +There is also an explicit directive to tell the preprocessor that it need +not include a file more than once. This is called @samp{#pragma once}, +and was used @emph{in addition to} the @samp{#ifndef} conditional around +the contents of the header file. @samp{#pragma once} is now obsolete +and should not be used at all. + +@findex #import +In the Objective C language, there is a variant of @samp{#include} +called @samp{#import} which includes a file, but does so at most once. +If you use @samp{#import} @emph{instead of} @samp{#include}, then you +don't need the conditionals inside the header file to prevent multiple +execution of the contents. + +@samp{#import} is obsolete because it is not a well designed feature. +It requires the users of a header file---the applications +programmers---to know that a certain header file should only be included +once. It is much better for the header file's implementor to write the +file so that users don't need to know this. Using @samp{#ifndef} +accomplishes this goal. + +@node Inheritance,, Once-Only, Header Files +@subsection Inheritance and Header Files +@cindex inheritance +@cindex overriding a header file + +@dfn{Inheritance} is what happens when one object or file derives some +of its contents by virtual copying from another object or file. In +the case of C header files, inheritance means that one header file +includes another header file and then replaces or adds something. + +If the inheriting header file and the base header file have different +names, then inheritance is straightforward: simply write @samp{#include +"@var{base}"} in the inheriting file. + +Sometimes it is necessary to give the inheriting file the same name as +the base file. This is less straightforward. + +For example, suppose an application program uses the system header file +@file{sys/signal.h}, but the version of @file{/usr/include/sys/signal.h} +on a particular system doesn't do what the application program expects. +It might be convenient to define a ``local'' version, perhaps under the +name @file{/usr/local/include/sys/signal.h}, to override or add to the +one supplied by the system. + +You can do this by using the option @samp{-I.} for compilation, and +writing a file @file{sys/signal.h} that does what the application +program expects. But making this file include the standard +@file{sys/signal.h} is not so easy---writing @samp{#include +} in that file doesn't work, because it includes your own +version of the file, not the standard system version. Used in that file +itself, this leads to an infinite recursion and a fatal error in +compilation. + +@samp{#include } would find the proper file, +but that is not clean, since it makes an assumption about where the +system header file is found. This is bad for maintenance, since it +means that any change in where the system's header files are kept +requires a change somewhere else. + +@findex #include_next +The clean way to solve this problem is to use +@samp{#include_next}, which means, ``Include the @emph{next} file with +this name.'' This directive works like @samp{#include} except in +searching for the specified file: it starts searching the list of header +file directories @emph{after} the directory in which the current file +was found. + +Suppose you specify @samp{-I /usr/local/include}, and the list of +directories to search also includes @file{/usr/include}; and suppose that +both directories contain a file named @file{sys/signal.h}. Ordinary +@samp{#include } finds the file under +@file{/usr/local/include}. If that file contains @samp{#include_next +}, it starts searching after that directory, and finds the +file in @file{/usr/include}. + +@node Macros, Conditionals, Header Files, Top +@section Macros + +A macro is a sort of abbreviation which you can define once and then +use later. There are many complicated features associated with macros +in the C preprocessor. + +@menu +* Simple Macros:: Macros that always expand the same way. +* Argument Macros:: Macros that accept arguments that are substituted + into the macro expansion. +* Predefined:: Predefined macros that are always available. +* Stringification:: Macro arguments converted into string constants. +* Concatenation:: Building tokens from parts taken from macro arguments. +* Undefining:: Cancelling a macro's definition. +* Redefining:: Changing a macro's definition. +* Macro Pitfalls:: Macros can confuse the unwary. Here we explain + several common problems and strange features. +@end menu + +@node Simple Macros, Argument Macros, Macros, Macros +@subsection Simple Macros +@cindex simple macro +@cindex manifest constant + +A @dfn{simple macro} is a kind of abbreviation. It is a name which +stands for a fragment of code. Some people refer to these as +@dfn{manifest constants}. + +Before you can use a macro, you must @dfn{define} it explicitly with the +@samp{#define} directive. @samp{#define} is followed by the name of the +macro and then the code it should be an abbreviation for. For example, + +@example +#define BUFFER_SIZE 1020 +@end example + +@noindent +defines a macro named @samp{BUFFER_SIZE} as an abbreviation for the text +@samp{1020}. If somewhere after this @samp{#define} directive there comes +a C statement of the form + +@example +foo = (char *) xmalloc (BUFFER_SIZE); +@end example + +@noindent +then the C preprocessor will recognize and @dfn{expand} the macro +@samp{BUFFER_SIZE}, resulting in + +@example +foo = (char *) xmalloc (1020); +@end example + +The use of all upper case for macro names is a standard convention. +Programs are easier to read when it is possible to tell at a glance which +names are macros. + +Normally, a macro definition must be a single line, like all C +preprocessing directives. (You can split a long macro definition +cosmetically with Backslash-Newline.) There is one exception: Newlines +can be included in the macro definition if within a string or character +constant. This is because it is not possible for a macro definition to +contain an unbalanced quote character; the definition automatically +extends to include the matching quote character that ends the string or +character constant. Comments within a macro definition may contain +Newlines, which make no difference since the comments are entirely +replaced with Spaces regardless of their contents. + +Aside from the above, there is no restriction on what can go in a macro +body. Parentheses need not balance. The body need not resemble valid C +code. (But if it does not, you may get error messages from the C +compiler when you use the macro.) + +The C preprocessor scans your program sequentially, so macro definitions +take effect at the place you write them. Therefore, the following input to +the C preprocessor + +@example +foo = X; +#define X 4 +bar = X; +@end example + +@noindent +produces as output + +@example +foo = X; + +bar = 4; +@end example + +After the preprocessor expands a macro name, the macro's definition body is +appended to the front of the remaining input, and the check for macro calls +continues. Therefore, the macro body can contain calls to other macros. +For example, after + +@example +#define BUFSIZE 1020 +#define TABLESIZE BUFSIZE +@end example + +@noindent +the name @samp{TABLESIZE} when used in the program would go through two +stages of expansion, resulting ultimately in @samp{1020}. + +This is not at all the same as defining @samp{TABLESIZE} to be @samp{1020}. +The @samp{#define} for @samp{TABLESIZE} uses exactly the body you +specify---in this case, @samp{BUFSIZE}---and does not check to see whether +it too is the name of a macro. It's only when you @emph{use} @samp{TABLESIZE} +that the result of its expansion is checked for more macro names. +@xref{Cascaded Macros}. + +@node Argument Macros, Predefined, Simple Macros, Macros +@subsection Macros with Arguments +@cindex macros with argument +@cindex arguments in macro definitions +@cindex function-like macro + +A simple macro always stands for exactly the same text, each time it is +used. Macros can be more flexible when they accept @dfn{arguments}. +Arguments are fragments of code that you supply each time the macro is +used. These fragments are included in the expansion of the macro +according to the directions in the macro definition. A macro that +accepts arguments is called a @dfn{function-like macro} because the +syntax for using it looks like a function call. + +@findex #define +To define a macro that uses arguments, you write a @samp{#define} directive +with a list of @dfn{argument names} in parentheses after the name of the +macro. The argument names may be any valid C identifiers, separated by +commas and optionally whitespace. The open-parenthesis must follow the +macro name immediately, with no space in between. + +For example, here is a macro that computes the minimum of two numeric +values, as it is defined in many C programs: + +@example +#define min(X, Y) ((X) < (Y) ? (X) : (Y)) +@end example + +@noindent +(This is not the best way to define a ``minimum'' macro in GNU C. +@xref{Side Effects}, for more information.) + +To use a macro that expects arguments, you write the name of the macro +followed by a list of @dfn{actual arguments} in parentheses, separated by +commas. The number of actual arguments you give must match the number of +arguments the macro expects. Examples of use of the macro @samp{min} +include @samp{min (1, 2)} and @samp{min (x + 28, *p)}. + +The expansion text of the macro depends on the arguments you use. +Each of the argument names of the macro is replaced, throughout the +macro definition, with the corresponding actual argument. Using the +same macro @samp{min} defined above, @samp{min (1, 2)} expands into + +@example +((1) < (2) ? (1) : (2)) +@end example + +@noindent +where @samp{1} has been substituted for @samp{X} and @samp{2} for @samp{Y}. + +Likewise, @samp{min (x + 28, *p)} expands into + +@example +((x + 28) < (*p) ? (x + 28) : (*p)) +@end example + +Parentheses in the actual arguments must balance; a comma within +parentheses does not end an argument. However, there is no requirement +for brackets or braces to balance, and they do not prevent a comma from +separating arguments. Thus, + +@example +macro (array[x = y, x + 1]) +@end example + +@noindent +passes two arguments to @code{macro}: @samp{array[x = y} and @samp{x + +1]}. If you want to supply @samp{array[x = y, x + 1]} as an argument, +you must write it as @samp{array[(x = y, x + 1)]}, which is equivalent C +code. + +After the actual arguments are substituted into the macro body, the entire +result is appended to the front of the remaining input, and the check for +macro calls continues. Therefore, the actual arguments can contain calls +to other macros, either with or without arguments, or even to the same +macro. The macro body can also contain calls to other macros. For +example, @samp{min (min (a, b), c)} expands into this text: + +@example +((((a) < (b) ? (a) : (b))) < (c) + ? (((a) < (b) ? (a) : (b))) + : (c)) +@end example + +@noindent +(Line breaks shown here for clarity would not actually be generated.) + +@cindex blank macro arguments +@cindex space as macro argument +If a macro @code{foo} takes one argument, and you want to supply an +empty argument, you must write at least some whitespace between the +parentheses, like this: @samp{foo ( )}. Just @samp{foo ()} is providing +no arguments, which is an error if @code{foo} expects an argument. But +@samp{foo0 ()} is the correct way to call a macro defined to take zero +arguments, like this: + +@example +#define foo0() @dots{} +@end example + +If you use the macro name followed by something other than an +open-parenthesis (after ignoring any spaces, tabs and comments that +follow), it is not a call to the macro, and the preprocessor does not +change what you have written. Therefore, it is possible for the same name +to be a variable or function in your program as well as a macro, and you +can choose in each instance whether to refer to the macro (if an actual +argument list follows) or the variable or function (if an argument list +does not follow). + +Such dual use of one name could be confusing and should be avoided +except when the two meanings are effectively synonymous: that is, when the +name is both a macro and a function and the two have similar effects. You +can think of the name simply as a function; use of the name for purposes +other than calling it (such as, to take the address) will refer to the +function, while calls will expand the macro and generate better but +equivalent code. For example, you can use a function named @samp{min} in +the same source file that defines the macro. If you write @samp{&min} with +no argument list, you refer to the function. If you write @samp{min (x, +bb)}, with an argument list, the macro is expanded. If you write +@samp{(min) (a, bb)}, where the name @samp{min} is not followed by an +open-parenthesis, the macro is not expanded, so you wind up with a call to +the function @samp{min}. + +You may not define the same name as both a simple macro and a macro with +arguments. + +In the definition of a macro with arguments, the list of argument names +must follow the macro name immediately with no space in between. If there +is a space after the macro name, the macro is defined as taking no +arguments, and all the rest of the line is taken to be the expansion. The +reason for this is that it is often useful to define a macro that takes no +arguments and whose definition begins with an identifier in parentheses. +This rule about spaces makes it possible for you to do either this: + +@example +#define FOO(x) - 1 / (x) +@end example + +@noindent +(which defines @samp{FOO} to take an argument and expand into minus the +reciprocal of that argument) or this: + +@example +#define BAR (x) - 1 / (x) +@end example + +@noindent +(which defines @samp{BAR} to take no argument and always expand into +@samp{(x) - 1 / (x)}). + +Note that the @emph{uses} of a macro with arguments can have spaces before +the left parenthesis; it's the @emph{definition} where it matters whether +there is a space. + +@node Predefined, Stringification, Argument Macros, Macros +@subsection Predefined Macros + +@cindex predefined macros +Several simple macros are predefined. You can use them without giving +definitions for them. They fall into two classes: standard macros and +system-specific macros. + +@menu +* Standard Predefined:: Standard predefined macros. +* Nonstandard Predefined:: Nonstandard predefined macros. +@end menu + +@node Standard Predefined, Nonstandard Predefined, Predefined, Predefined +@subsubsection Standard Predefined Macros +@cindex standard predefined macros + +The standard predefined macros are available with the same meanings +regardless of the machine or operating system on which you are using GNU C. +Their names all start and end with double underscores. Those preceding +@code{__GNUC__} in this table are standardized by ANSI C; the rest are +GNU C extensions. + +@table @code +@item __FILE__ +@findex __FILE__ +This macro expands to the name of the current input file, in the form of +a C string constant. The precise name returned is the one that was +specified in @samp{#include} or as the input file name argument. + +@item __LINE__ +@findex __LINE__ +This macro expands to the current input line number, in the form of a +decimal integer constant. While we call it a predefined macro, it's +a pretty strange macro, since its ``definition'' changes with each +new line of source code. + +This and @samp{__FILE__} are useful in generating an error message to +report an inconsistency detected by the program; the message can state +the source line at which the inconsistency was detected. For example, + +@smallexample +fprintf (stderr, "Internal error: " + "negative string length " + "%d at %s, line %d.", + length, __FILE__, __LINE__); +@end smallexample + +A @samp{#include} directive changes the expansions of @samp{__FILE__} +and @samp{__LINE__} to correspond to the included file. At the end of +that file, when processing resumes on the input file that contained +the @samp{#include} directive, the expansions of @samp{__FILE__} and +@samp{__LINE__} revert to the values they had before the +@samp{#include} (but @samp{__LINE__} is then incremented by one as +processing moves to the line after the @samp{#include}). + +The expansions of both @samp{__FILE__} and @samp{__LINE__} are altered +if a @samp{#line} directive is used. @xref{Combining Sources}. + +@item __DATE__ +@findex __DATE__ +This macro expands to a string constant that describes the date on +which the preprocessor is being run. The string constant contains +eleven characters and looks like @samp{"Jan 29 1987"} or @w{@samp{"Apr +1 1905"}}. + +@item __TIME__ +@findex __TIME__ +This macro expands to a string constant that describes the time at +which the preprocessor is being run. The string constant contains +eight characters and looks like @samp{"23:59:01"}. + +@item __STDC__ +@findex __STDC__ +This macro expands to the constant 1, to signify that this is ANSI +Standard C. (Whether that is actually true depends on what C compiler +will operate on the output from the preprocessor.) + +@item __STDC_VERSION__ +@findex __STDC_VERSION__ +This macro expands to the C Standard's version number, +a long integer constant of the form @samp{@var{yyyy}@var{mm}L} +where @var{yyyy} and @var{mm} are the year and month of the Standard version. +This signifies which version of the C Standard the preprocessor conforms to. +Like @samp{__STDC__}, whether this version number is accurate +for the entire implementation depends on what C compiler +will operate on the output from the preprocessor. + +@item __GNUC__ +@findex __GNUC__ +This macro is defined if and only if this is GNU C. This macro is +defined only when the entire GNU C compiler is in use; if you invoke the +preprocessor directly, @samp{__GNUC__} is undefined. The value +identifies the major version number of GNU CC (@samp{1} for GNU CC +version 1, which is now obsolete, and @samp{2} for version 2). + +@item __GNUC_MINOR__ +@findex __GNUC_MINOR__ +The macro contains the minor version number of the compiler. This can +be used to work around differences between different releases of the +compiler (for example, if gcc 2.6.3 is known to support a feature, you +can test for @code{__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6)}). +The last number, @samp{3} in the +example above, denotes the bugfix level of the compiler; no macro +contains this value. + +@item __GNUG__ +@findex __GNUG__ +The GNU C compiler defines this when the compilation language is +C++; use @samp{__GNUG__} to distinguish between GNU C and GNU +C++. + +@item __cplusplus +@findex __cplusplus +The draft ANSI standard for C++ used to require predefining this +variable. Though it is no longer required, GNU C++ continues to define +it, as do other popular C++ compilers. You can use @samp{__cplusplus} +to test whether a header is compiled by a C compiler or a C++ compiler. + +@item __STRICT_ANSI__ +@findex __STRICT_ANSI__ +This macro is defined if and only if the @samp{-ansi} switch was +specified when GNU C was invoked. Its definition is the null string. +This macro exists primarily to direct certain GNU header files not to +define certain traditional Unix constructs which are incompatible with +ANSI C. + +@item __BASE_FILE__ +@findex __BASE_FILE__ +This macro expands to the name of the main input file, in the form +of a C string constant. This is the source file that was specified +as an argument when the C compiler was invoked. + +@item __INCLUDE_LEVEL__ +@findex __INCLUDE_LEVEL_ +This macro expands to a decimal integer constant that represents the +depth of nesting in include files. The value of this macro is +incremented on every @samp{#include} directive and decremented at every +end of file. For input files specified by command line arguments, +the nesting level is zero. + +@item __VERSION__ +@findex __VERSION__ +This macro expands to a string which describes the version number of +GNU C. The string is normally a sequence of decimal numbers separated +by periods, such as @samp{"2.6.0"}. The only reasonable use of this +macro is to incorporate it into a string constant. + +@item __OPTIMIZE__ +@findex __OPTIMIZE__ +This macro is defined in optimizing compilations. It causes certain +GNU header files to define alternative macro definitions for some +system library functions. It is unwise to refer to or test the +definition of this macro unless you make very sure that programs will +execute with the same effect regardless. + +@item __CHAR_UNSIGNED__ +@findex __CHAR_UNSIGNED__ +This macro is defined if and only if the data type @code{char} is +unsigned on the target machine. It exists to cause the standard +header file @file{limit.h} to work correctly. It is bad practice +to refer to this macro yourself; instead, refer to the standard +macros defined in @file{limit.h}. The preprocessor uses +this macro to determine whether or not to sign-extend large character +constants written in octal; see @ref{#if Directive,,The @samp{#if} Directive}. + +@item __REGISTER_PREFIX__ +@findex __REGISTER_PREFIX__ +This macro expands to a string describing the prefix applied to cpu +registers in assembler code. It can be used to write assembler code +that is usable in multiple environments. For example, in the +@samp{m68k-aout} environment it expands to the string @samp{""}, +but in the @samp{m68k-coff} environment it expands to the string +@samp{"%"}. + +@item __USER_LABEL_PREFIX__ +@findex __USER_LABEL_PREFIX__ +This macro expands to a string describing the prefix applied to +user generated labels in assembler code. It can be used to write +assembler code that is usable in multiple environments. +For example, in the @samp{m68k-aout} environment it expands to the +string @samp{"_"}, but in the @samp{m68k-coff} environment it expands +to the string @samp{""}. +@end table + +@node Nonstandard Predefined,, Standard Predefined, Predefined +@subsubsection Nonstandard Predefined Macros + +The C preprocessor normally has several predefined macros that vary between +machines because their purpose is to indicate what type of system and +machine is in use. This manual, being for all systems and machines, cannot +tell you exactly what their names are; instead, we offer a list of some +typical ones. You can use @samp{cpp -dM} to see the values of +predefined macros; see @ref{Invocation}. + +Some nonstandard predefined macros describe the operating system in use, +with more or less specificity. For example, + +@table @code +@item unix +@findex unix +@samp{unix} is normally predefined on all Unix systems. + +@item BSD +@findex BSD +@samp{BSD} is predefined on recent versions of Berkeley Unix +(perhaps only in version 4.3). +@end table + +Other nonstandard predefined macros describe the kind of CPU, with more or +less specificity. For example, + +@table @code +@item vax +@findex vax +@samp{vax} is predefined on Vax computers. + +@item mc68000 +@findex mc68000 +@samp{mc68000} is predefined on most computers whose CPU is a Motorola +68000, 68010 or 68020. + +@item m68k +@findex m68k +@samp{m68k} is also predefined on most computers whose CPU is a 68000, +68010 or 68020; however, some makers use @samp{mc68000} and some use +@samp{m68k}. Some predefine both names. What happens in GNU C +depends on the system you are using it on. + +@item M68020 +@findex M68020 +@samp{M68020} has been observed to be predefined on some systems that +use 68020 CPUs---in addition to @samp{mc68000} and @samp{m68k}, which +are less specific. + +@item _AM29K +@findex _AM29K +@itemx _AM29000 +@findex _AM29000 +Both @samp{_AM29K} and @samp{_AM29000} are predefined for the AMD 29000 +CPU family. + +@item ns32000 +@findex ns32000 +@samp{ns32000} is predefined on computers which use the National +Semiconductor 32000 series CPU. +@end table + +Yet other nonstandard predefined macros describe the manufacturer of +the system. For example, + +@table @code +@item sun +@findex sun +@samp{sun} is predefined on all models of Sun computers. + +@item pyr +@findex pyr +@samp{pyr} is predefined on all models of Pyramid computers. + +@item sequent +@findex sequent +@samp{sequent} is predefined on all models of Sequent computers. +@end table + +These predefined symbols are not only nonstandard, they are contrary to the +ANSI standard because their names do not start with underscores. +Therefore, the option @samp{-ansi} inhibits the definition of these +symbols. + +This tends to make @samp{-ansi} useless, since many programs depend on the +customary nonstandard predefined symbols. Even system header files check +them and will generate incorrect declarations if they do not find the names +that are expected. You might think that the header files supplied for the +Uglix computer would not need to test what machine they are running on, +because they can simply assume it is the Uglix; but often they do, and they +do so using the customary names. As a result, very few C programs will +compile with @samp{-ansi}. We intend to avoid such problems on the GNU +system. + +What, then, should you do in an ANSI C program to test the type of machine +it will run on? + +GNU C offers a parallel series of symbols for this purpose, whose names +are made from the customary ones by adding @samp{__} at the beginning +and end. Thus, the symbol @code{__vax__} would be available on a Vax, +and so on. + +The set of nonstandard predefined names in the GNU C preprocessor is +controlled (when @code{cpp} is itself compiled) by the macro +@samp{CPP_PREDEFINES}, which should be a string containing @samp{-D} +options, separated by spaces. For example, on the Sun 3, we use the +following definition: + +@example +#define CPP_PREDEFINES "-Dmc68000 -Dsun -Dunix -Dm68k" +@end example + +@noindent +This macro is usually specified in @file{tm.h}. + +@node Stringification, Concatenation, Predefined, Macros +@subsection Stringification + +@cindex stringification +@dfn{Stringification} means turning a code fragment into a string constant +whose contents are the text for the code fragment. For example, +stringifying @samp{foo (z)} results in @samp{"foo (z)"}. + +In the C preprocessor, stringification is an option available when macro +arguments are substituted into the macro definition. In the body of the +definition, when an argument name appears, the character @samp{#} before +the name specifies stringification of the corresponding actual argument +when it is substituted at that point in the definition. The same argument +may be substituted in other places in the definition without +stringification if the argument name appears in those places with no +@samp{#}. + +Here is an example of a macro definition that uses stringification: + +@smallexample +@group +#define WARN_IF(EXP) \ +do @{ if (EXP) \ + fprintf (stderr, "Warning: " #EXP "\n"); @} \ +while (0) +@end group +@end smallexample + +@noindent +Here the actual argument for @samp{EXP} is substituted once as given, +into the @samp{if} statement, and once as stringified, into the +argument to @samp{fprintf}. The @samp{do} and @samp{while (0)} are +a kludge to make it possible to write @samp{WARN_IF (@var{arg});}, +which the resemblance of @samp{WARN_IF} to a function would make +C programmers want to do; see @ref{Swallow Semicolon}. + +The stringification feature is limited to transforming one macro argument +into one string constant: there is no way to combine the argument with +other text and then stringify it all together. But the example above shows +how an equivalent result can be obtained in ANSI Standard C using the +feature that adjacent string constants are concatenated as one string +constant. The preprocessor stringifies the actual value of @samp{EXP} +into a separate string constant, resulting in text like + +@smallexample +@group +do @{ if (x == 0) \ + fprintf (stderr, "Warning: " "x == 0" "\n"); @} \ +while (0) +@end group +@end smallexample + +@noindent +but the C compiler then sees three consecutive string constants and +concatenates them into one, producing effectively + +@smallexample +do @{ if (x == 0) \ + fprintf (stderr, "Warning: x == 0\n"); @} \ +while (0) +@end smallexample + +Stringification in C involves more than putting doublequote characters +around the fragment; it is necessary to put backslashes in front of all +doublequote characters, and all backslashes in string and character +constants, in order to get a valid C string constant with the proper +contents. Thus, stringifying @samp{p = "foo\n";} results in @samp{"p = +\"foo\\n\";"}. However, backslashes that are not inside of string or +character constants are not duplicated: @samp{\n} by itself stringifies to +@samp{"\n"}. + +Whitespace (including comments) in the text being stringified is handled +according to precise rules. All leading and trailing whitespace is ignored. +Any sequence of whitespace in the middle of the text is converted to +a single space in the stringified result. + +@node Concatenation, Undefining, Stringification, Macros +@subsection Concatenation +@cindex concatenation +@cindex @samp{##} +@dfn{Concatenation} means joining two strings into one. In the context +of macro expansion, concatenation refers to joining two lexical units +into one longer one. Specifically, an actual argument to the macro can be +concatenated with another actual argument or with fixed text to produce +a longer name. The longer name might be the name of a function, +variable or type, or a C keyword; it might even be the name of another +macro, in which case it will be expanded. + +When you define a macro, you request concatenation with the special +operator @samp{##} in the macro body. When the macro is called, +after actual arguments are substituted, all @samp{##} operators are +deleted, and so is any whitespace next to them (including whitespace +that was part of an actual argument). The result is to concatenate +the syntactic tokens on either side of the @samp{##}. + +Consider a C program that interprets named commands. There probably needs +to be a table of commands, perhaps an array of structures declared as +follows: + +@example +struct command +@{ + char *name; + void (*function) (); +@}; + +struct command commands[] = +@{ + @{ "quit", quit_command@}, + @{ "help", help_command@}, + @dots{} +@}; +@end example + +It would be cleaner not to have to give each command name twice, once in +the string constant and once in the function name. A macro which takes the +name of a command as an argument can make this unnecessary. The string +constant can be created with stringification, and the function name by +concatenating the argument with @samp{_command}. Here is how it is done: + +@example +#define COMMAND(NAME) @{ #NAME, NAME ## _command @} + +struct command commands[] = +@{ + COMMAND (quit), + COMMAND (help), + @dots{} +@}; +@end example + +The usual case of concatenation is concatenating two names (or a name and a +number) into a longer name. But this isn't the only valid case. It is +also possible to concatenate two numbers (or a number and a name, such as +@samp{1.5} and @samp{e3}) into a number. Also, multi-character operators +such as @samp{+=} can be formed by concatenation. In some cases it is even +possible to piece together a string constant. However, two pieces of text +that don't together form a valid lexical unit cannot be concatenated. For +example, concatenation with @samp{x} on one side and @samp{+} on the other +is not meaningful because those two characters can't fit together in any +lexical unit of C. The ANSI standard says that such attempts at +concatenation are undefined, but in the GNU C preprocessor it is well +defined: it puts the @samp{x} and @samp{+} side by side with no particular +special results. + +Keep in mind that the C preprocessor converts comments to whitespace before +macros are even considered. Therefore, you cannot create a comment by +concatenating @samp{/} and @samp{*}: the @samp{/*} sequence that starts a +comment is not a lexical unit, but rather the beginning of a ``long'' space +character. Also, you can freely use comments next to a @samp{##} in a +macro definition, or in actual arguments that will be concatenated, because +the comments will be converted to spaces at first sight, and concatenation +will later discard the spaces. + +@node Undefining, Redefining, Concatenation, Macros +@subsection Undefining Macros + +@cindex undefining macros +To @dfn{undefine} a macro means to cancel its definition. This is done +with the @samp{#undef} directive. @samp{#undef} is followed by the macro +name to be undefined. + +Like definition, undefinition occurs at a specific point in the source +file, and it applies starting from that point. The name ceases to be a +macro name, and from that point on it is treated by the preprocessor as if +it had never been a macro name. + +For example, + +@example +#define FOO 4 +x = FOO; +#undef FOO +x = FOO; +@end example + +@noindent +expands into + +@example +x = 4; + +x = FOO; +@end example + +@noindent +In this example, @samp{FOO} had better be a variable or function as well +as (temporarily) a macro, in order for the result of the expansion to be +valid C code. + +The same form of @samp{#undef} directive will cancel definitions with +arguments or definitions that don't expect arguments. The @samp{#undef} +directive has no effect when used on a name not currently defined as a macro. + +@node Redefining, Macro Pitfalls, Undefining, Macros +@subsection Redefining Macros + +@cindex redefining macros +@dfn{Redefining} a macro means defining (with @samp{#define}) a name that +is already defined as a macro. + +A redefinition is trivial if the new definition is transparently identical +to the old one. You probably wouldn't deliberately write a trivial +redefinition, but they can happen automatically when a header file is +included more than once (@pxref{Header Files}), so they are accepted +silently and without effect. + +Nontrivial redefinition is considered likely to be an error, so +it provokes a warning message from the preprocessor. However, sometimes it +is useful to change the definition of a macro in mid-compilation. You can +inhibit the warning by undefining the macro with @samp{#undef} before the +second definition. + +In order for a redefinition to be trivial, the new definition must +exactly match the one already in effect, with two possible exceptions: + +@itemize @bullet +@item +Whitespace may be added or deleted at the beginning or the end. + +@item +Whitespace may be changed in the middle (but not inside strings). +However, it may not be eliminated entirely, and it may not be added +where there was no whitespace at all. +@end itemize + +Recall that a comment counts as whitespace. + +@node Macro Pitfalls,, Redefining, Macros +@subsection Pitfalls and Subtleties of Macros +@cindex problems with macros +@cindex pitfalls of macros + +In this section we describe some special rules that apply to macros and +macro expansion, and point out certain cases in which the rules have +counterintuitive consequences that you must watch out for. + +@menu +* Misnesting:: Macros can contain unmatched parentheses. +* Macro Parentheses:: Why apparently superfluous parentheses + may be necessary to avoid incorrect grouping. +* Swallow Semicolon:: Macros that look like functions + but expand into compound statements. +* Side Effects:: Unsafe macros that cause trouble when + arguments contain side effects. +* Self-Reference:: Macros whose definitions use the macros' own names. +* Argument Prescan:: Actual arguments are checked for macro calls + before they are substituted. +* Cascaded Macros:: Macros whose definitions use other macros. +* Newlines in Args:: Sometimes line numbers get confused. +@end menu + +@node Misnesting, Macro Parentheses, Macro Pitfalls, Macro Pitfalls +@subsubsection Improperly Nested Constructs + +Recall that when a macro is called with arguments, the arguments are +substituted into the macro body and the result is checked, together with +the rest of the input file, for more macro calls. + +It is possible to piece together a macro call coming partially from the +macro body and partially from the actual arguments. For example, + +@example +#define double(x) (2*(x)) +#define call_with_1(x) x(1) +@end example + +@noindent +would expand @samp{call_with_1 (double)} into @samp{(2*(1))}. + +Macro definitions do not have to have balanced parentheses. By writing an +unbalanced open parenthesis in a macro body, it is possible to create a +macro call that begins inside the macro body but ends outside of it. For +example, + +@example +#define strange(file) fprintf (file, "%s %d", +@dots{} +strange(stderr) p, 35) +@end example + +@noindent +This bizarre example expands to @samp{fprintf (stderr, "%s %d", p, 35)}! + +@node Macro Parentheses, Swallow Semicolon, Misnesting, Macro Pitfalls +@subsubsection Unintended Grouping of Arithmetic +@cindex parentheses in macro bodies + +You may have noticed that in most of the macro definition examples shown +above, each occurrence of a macro argument name had parentheses around it. +In addition, another pair of parentheses usually surround the entire macro +definition. Here is why it is best to write macros that way. + +Suppose you define a macro as follows, + +@example +#define ceil_div(x, y) (x + y - 1) / y +@end example + +@noindent +whose purpose is to divide, rounding up. (One use for this operation is +to compute how many @samp{int} objects are needed to hold a certain +number of @samp{char} objects.) Then suppose it is used as follows: + +@example +a = ceil_div (b & c, sizeof (int)); +@end example + +@noindent +This expands into + +@example +a = (b & c + sizeof (int) - 1) / sizeof (int); +@end example + +@noindent +which does not do what is intended. The operator-precedence rules of +C make it equivalent to this: + +@example +a = (b & (c + sizeof (int) - 1)) / sizeof (int); +@end example + +@noindent +But what we want is this: + +@example +a = ((b & c) + sizeof (int) - 1)) / sizeof (int); +@end example + +@noindent +Defining the macro as + +@example +#define ceil_div(x, y) ((x) + (y) - 1) / (y) +@end example + +@noindent +provides the desired result. + +However, unintended grouping can result in another way. Consider +@samp{sizeof ceil_div(1, 2)}. That has the appearance of a C expression +that would compute the size of the type of @samp{ceil_div (1, 2)}, but in +fact it means something very different. Here is what it expands to: + +@example +sizeof ((1) + (2) - 1) / (2) +@end example + +@noindent +This would take the size of an integer and divide it by two. The precedence +rules have put the division outside the @samp{sizeof} when it was intended +to be inside. + +Parentheses around the entire macro definition can prevent such problems. +Here, then, is the recommended way to define @samp{ceil_div}: + +@example +#define ceil_div(x, y) (((x) + (y) - 1) / (y)) +@end example + +@node Swallow Semicolon, Side Effects, Macro Parentheses, Macro Pitfalls +@subsubsection Swallowing the Semicolon + +@cindex semicolons (after macro calls) +Often it is desirable to define a macro that expands into a compound +statement. Consider, for example, the following macro, that advances a +pointer (the argument @samp{p} says where to find it) across whitespace +characters: + +@example +#define SKIP_SPACES (p, limit) \ +@{ register char *lim = (limit); \ + while (p != lim) @{ \ + if (*p++ != ' ') @{ \ + p--; break; @}@}@} +@end example + +@noindent +Here Backslash-Newline is used to split the macro definition, which must +be a single line, so that it resembles the way such C code would be +laid out if not part of a macro definition. + +A call to this macro might be @samp{SKIP_SPACES (p, lim)}. Strictly +speaking, the call expands to a compound statement, which is a complete +statement with no need for a semicolon to end it. But it looks like a +function call. So it minimizes confusion if you can use it like a function +call, writing a semicolon afterward, as in @samp{SKIP_SPACES (p, lim);} + +But this can cause trouble before @samp{else} statements, because the +semicolon is actually a null statement. Suppose you write + +@example +if (*p != 0) + SKIP_SPACES (p, lim); +else @dots{} +@end example + +@noindent +The presence of two statements---the compound statement and a null +statement---in between the @samp{if} condition and the @samp{else} +makes invalid C code. + +The definition of the macro @samp{SKIP_SPACES} can be altered to solve +this problem, using a @samp{do @dots{} while} statement. Here is how: + +@example +#define SKIP_SPACES (p, limit) \ +do @{ register char *lim = (limit); \ + while (p != lim) @{ \ + if (*p++ != ' ') @{ \ + p--; break; @}@}@} \ +while (0) +@end example + +Now @samp{SKIP_SPACES (p, lim);} expands into + +@example +do @{@dots{}@} while (0); +@end example + +@noindent +which is one statement. + +@node Side Effects, Self-Reference, Swallow Semicolon, Macro Pitfalls +@subsubsection Duplication of Side Effects + +@cindex side effects (in macro arguments) +@cindex unsafe macros +Many C programs define a macro @samp{min}, for ``minimum'', like this: + +@example +#define min(X, Y) ((X) < (Y) ? (X) : (Y)) +@end example + +When you use this macro with an argument containing a side effect, +as shown here, + +@example +next = min (x + y, foo (z)); +@end example + +@noindent +it expands as follows: + +@example +next = ((x + y) < (foo (z)) ? (x + y) : (foo (z))); +@end example + +@noindent +where @samp{x + y} has been substituted for @samp{X} and @samp{foo (z)} +for @samp{Y}. + +The function @samp{foo} is used only once in the statement as it appears +in the program, but the expression @samp{foo (z)} has been substituted +twice into the macro expansion. As a result, @samp{foo} might be called +two times when the statement is executed. If it has side effects or +if it takes a long time to compute, the results might not be what you +intended. We say that @samp{min} is an @dfn{unsafe} macro. + +The best solution to this problem is to define @samp{min} in a way that +computes the value of @samp{foo (z)} only once. The C language offers no +standard way to do this, but it can be done with GNU C extensions as +follows: + +@example +#define min(X, Y) \ +(@{ typeof (X) __x = (X), __y = (Y); \ + (__x < __y) ? __x : __y; @}) +@end example + +If you do not wish to use GNU C extensions, the only solution is to be +careful when @emph{using} the macro @samp{min}. For example, you can +calculate the value of @samp{foo (z)}, save it in a variable, and use that +variable in @samp{min}: + +@example +#define min(X, Y) ((X) < (Y) ? (X) : (Y)) +@dots{} +@{ + int tem = foo (z); + next = min (x + y, tem); +@} +@end example + +@noindent +(where we assume that @samp{foo} returns type @samp{int}). + +@node Self-Reference, Argument Prescan, Side Effects, Macro Pitfalls +@subsubsection Self-Referential Macros + +@cindex self-reference +A @dfn{self-referential} macro is one whose name appears in its definition. +A special feature of ANSI Standard C is that the self-reference is not +considered a macro call. It is passed into the preprocessor output +unchanged. + +Let's consider an example: + +@example +#define foo (4 + foo) +@end example + +@noindent +where @samp{foo} is also a variable in your program. + +Following the ordinary rules, each reference to @samp{foo} will expand into +@samp{(4 + foo)}; then this will be rescanned and will expand into @samp{(4 ++ (4 + foo))}; and so on until it causes a fatal error (memory full) in the +preprocessor. + +However, the special rule about self-reference cuts this process short +after one step, at @samp{(4 + foo)}. Therefore, this macro definition +has the possibly useful effect of causing the program to add 4 to +the value of @samp{foo} wherever @samp{foo} is referred to. + +In most cases, it is a bad idea to take advantage of this feature. A +person reading the program who sees that @samp{foo} is a variable will +not expect that it is a macro as well. The reader will come across the +identifier @samp{foo} in the program and think its value should be that +of the variable @samp{foo}, whereas in fact the value is four greater. + +The special rule for self-reference applies also to @dfn{indirect} +self-reference. This is the case where a macro @var{x} expands to use a +macro @samp{y}, and the expansion of @samp{y} refers to the macro +@samp{x}. The resulting reference to @samp{x} comes indirectly from the +expansion of @samp{x}, so it is a self-reference and is not further +expanded. Thus, after + +@example +#define x (4 + y) +#define y (2 * x) +@end example + +@noindent +@samp{x} would expand into @samp{(4 + (2 * x))}. Clear? + +But suppose @samp{y} is used elsewhere, not from the definition of @samp{x}. +Then the use of @samp{x} in the expansion of @samp{y} is not a self-reference +because @samp{x} is not ``in progress''. So it does expand. However, +the expansion of @samp{x} contains a reference to @samp{y}, and that +is an indirect self-reference now because @samp{y} is ``in progress''. +The result is that @samp{y} expands to @samp{(2 * (4 + y))}. + +It is not clear that this behavior would ever be useful, but it is specified +by the ANSI C standard, so you may need to understand it. + +@node Argument Prescan, Cascaded Macros, Self-Reference, Macro Pitfalls +@subsubsection Separate Expansion of Macro Arguments +@cindex expansion of arguments +@cindex macro argument expansion +@cindex prescan of macro arguments + +We have explained that the expansion of a macro, including the substituted +actual arguments, is scanned over again for macro calls to be expanded. + +What really happens is more subtle: first each actual argument text is scanned +separately for macro calls. Then the results of this are substituted into +the macro body to produce the macro expansion, and the macro expansion +is scanned again for macros to expand. + +The result is that the actual arguments are scanned @emph{twice} to expand +macro calls in them. + +Most of the time, this has no effect. If the actual argument contained +any macro calls, they are expanded during the first scan. The result +therefore contains no macro calls, so the second scan does not change it. +If the actual argument were substituted as given, with no prescan, +the single remaining scan would find the same macro calls and produce +the same results. + +You might expect the double scan to change the results when a +self-referential macro is used in an actual argument of another macro +(@pxref{Self-Reference}): the self-referential macro would be expanded once +in the first scan, and a second time in the second scan. But this is not +what happens. The self-references that do not expand in the first scan are +marked so that they will not expand in the second scan either. + +The prescan is not done when an argument is stringified or concatenated. +Thus, + +@example +#define str(s) #s +#define foo 4 +str (foo) +@end example + +@noindent +expands to @samp{"foo"}. Once more, prescan has been prevented from +having any noticeable effect. + +More precisely, stringification and concatenation use the argument as +written, in un-prescanned form. The same actual argument would be used in +prescanned form if it is substituted elsewhere without stringification or +concatenation. + +@example +#define str(s) #s lose(s) +#define foo 4 +str (foo) +@end example + +expands to @samp{"foo" lose(4)}. + +You might now ask, ``Why mention the prescan, if it makes no difference? +And why not skip it and make the preprocessor faster?'' The answer is +that the prescan does make a difference in three special cases: + +@itemize @bullet +@item +Nested calls to a macro. + +@item +Macros that call other macros that stringify or concatenate. + +@item +Macros whose expansions contain unshielded commas. +@end itemize + +We say that @dfn{nested} calls to a macro occur when a macro's actual +argument contains a call to that very macro. For example, if @samp{f} +is a macro that expects one argument, @samp{f (f (1))} is a nested +pair of calls to @samp{f}. The desired expansion is made by +expanding @samp{f (1)} and substituting that into the definition of +@samp{f}. The prescan causes the expected result to happen. +Without the prescan, @samp{f (1)} itself would be substituted as +an actual argument, and the inner use of @samp{f} would appear +during the main scan as an indirect self-reference and would not +be expanded. Here, the prescan cancels an undesirable side effect +(in the medical, not computational, sense of the term) of the special +rule for self-referential macros. + +But prescan causes trouble in certain other cases of nested macro calls. +Here is an example: + +@example +#define foo a,b +#define bar(x) lose(x) +#define lose(x) (1 + (x)) + +bar(foo) +@end example + +@noindent +We would like @samp{bar(foo)} to turn into @samp{(1 + (foo))}, which +would then turn into @samp{(1 + (a,b))}. But instead, @samp{bar(foo)} +expands into @samp{lose(a,b)}, and you get an error because @code{lose} +requires a single argument. In this case, the problem is easily solved +by the same parentheses that ought to be used to prevent misnesting of +arithmetic operations: + +@example +#define foo (a,b) +#define bar(x) lose((x)) +@end example + +The problem is more serious when the operands of the macro are not +expressions; for example, when they are statements. Then parentheses +are unacceptable because they would make for invalid C code: + +@example +#define foo @{ int a, b; @dots{} @} +@end example + +@noindent +In GNU C you can shield the commas using the @samp{(@{@dots{}@})} +construct which turns a compound statement into an expression: + +@example +#define foo (@{ int a, b; @dots{} @}) +@end example + +Or you can rewrite the macro definition to avoid such commas: + +@example +#define foo @{ int a; int b; @dots{} @} +@end example + +There is also one case where prescan is useful. It is possible +to use prescan to expand an argument and then stringify it---if you use +two levels of macros. Let's add a new macro @samp{xstr} to the +example shown above: + +@example +#define xstr(s) str(s) +#define str(s) #s +#define foo 4 +xstr (foo) +@end example + +This expands into @samp{"4"}, not @samp{"foo"}. The reason for the +difference is that the argument of @samp{xstr} is expanded at prescan +(because @samp{xstr} does not specify stringification or concatenation of +the argument). The result of prescan then forms the actual argument for +@samp{str}. @samp{str} uses its argument without prescan because it +performs stringification; but it cannot prevent or undo the prescanning +already done by @samp{xstr}. + +@node Cascaded Macros, Newlines in Args, Argument Prescan, Macro Pitfalls +@subsubsection Cascaded Use of Macros + +@cindex cascaded macros +@cindex macro body uses macro +A @dfn{cascade} of macros is when one macro's body contains a reference +to another macro. This is very common practice. For example, + +@example +#define BUFSIZE 1020 +#define TABLESIZE BUFSIZE +@end example + +This is not at all the same as defining @samp{TABLESIZE} to be @samp{1020}. +The @samp{#define} for @samp{TABLESIZE} uses exactly the body you +specify---in this case, @samp{BUFSIZE}---and does not check to see whether +it too is the name of a macro. + +It's only when you @emph{use} @samp{TABLESIZE} that the result of its expansion +is checked for more macro names. + +This makes a difference if you change the definition of @samp{BUFSIZE} +at some point in the source file. @samp{TABLESIZE}, defined as shown, +will always expand using the definition of @samp{BUFSIZE} that is +currently in effect: + +@example +#define BUFSIZE 1020 +#define TABLESIZE BUFSIZE +#undef BUFSIZE +#define BUFSIZE 37 +@end example + +@noindent +Now @samp{TABLESIZE} expands (in two stages) to @samp{37}. (The +@samp{#undef} is to prevent any warning about the nontrivial +redefinition of @code{BUFSIZE}.) + +@node Newlines in Args,, Cascaded Macros, Macro Pitfalls +@subsection Newlines in Macro Arguments +@cindex newlines in macro arguments + +Traditional macro processing carries forward all newlines in macro +arguments into the expansion of the macro. This means that, if some of +the arguments are substituted more than once, or not at all, or out of +order, newlines can be duplicated, lost, or moved around within the +expansion. If the expansion consists of multiple statements, then the +effect is to distort the line numbers of some of these statements. The +result can be incorrect line numbers, in error messages or displayed in +a debugger. + +The GNU C preprocessor operating in ANSI C mode adjusts appropriately +for multiple use of an argument---the first use expands all the +newlines, and subsequent uses of the same argument produce no newlines. +But even in this mode, it can produce incorrect line numbering if +arguments are used out of order, or not used at all. + +Here is an example illustrating this problem: + +@example +#define ignore_second_arg(a,b,c) a; c + +ignore_second_arg (foo (), + ignored (), + syntax error); +@end example + +@noindent +The syntax error triggered by the tokens @samp{syntax error} results +in an error message citing line four, even though the statement text +comes from line five. + +@node Conditionals, Combining Sources, Macros, Top +@section Conditionals + +@cindex conditionals +In a macro processor, a @dfn{conditional} is a directive that allows a part +of the program to be ignored during compilation, on some conditions. +In the C preprocessor, a conditional can test either an arithmetic expression +or whether a name is defined as a macro. + +A conditional in the C preprocessor resembles in some ways an @samp{if} +statement in C, but it is important to understand the difference between +them. The condition in an @samp{if} statement is tested during the execution +of your program. Its purpose is to allow your program to behave differently +from run to run, depending on the data it is operating on. The condition +in a preprocessing conditional directive is tested when your program is compiled. +Its purpose is to allow different code to be included in the program depending +on the situation at the time of compilation. + +@menu +* Uses: Conditional Uses. What conditionals are for. +* Syntax: Conditional Syntax. How conditionals are written. +* Deletion: Deleted Code. Making code into a comment. +* Macros: Conditionals-Macros. Why conditionals are used with macros. +* Assertions:: How and why to use assertions. +* Errors: #error Directive. Detecting inconsistent compilation parameters. +@end menu + +@node Conditional Uses +@subsection Why Conditionals are Used + +Generally there are three kinds of reason to use a conditional. + +@itemize @bullet +@item +A program may need to use different code depending on the machine or +operating system it is to run on. In some cases the code for one +operating system may be erroneous on another operating system; for +example, it might refer to library routines that do not exist on the +other system. When this happens, it is not enough to avoid executing +the invalid code: merely having it in the program makes it impossible +to link the program and run it. With a preprocessing conditional, the +offending code can be effectively excised from the program when it is +not valid. + +@item +You may want to be able to compile the same source file into two +different programs. Sometimes the difference between the programs is +that one makes frequent time-consuming consistency checks on its +intermediate data, or prints the values of those data for debugging, +while the other does not. + +@item +A conditional whose condition is always false is a good way to exclude +code from the program but keep it as a sort of comment for future +reference. +@end itemize + +Most simple programs that are intended to run on only one machine will +not need to use preprocessing conditionals. + +@node Conditional Syntax +@subsection Syntax of Conditionals + +@findex #if +A conditional in the C preprocessor begins with a @dfn{conditional +directive}: @samp{#if}, @samp{#ifdef} or @samp{#ifndef}. +@xref{Conditionals-Macros}, for information on @samp{#ifdef} and +@samp{#ifndef}; only @samp{#if} is explained here. + +@menu +* If: #if Directive. Basic conditionals using @samp{#if} and @samp{#endif}. +* Else: #else Directive. Including some text if the condition fails. +* Elif: #elif Directive. Testing several alternative possibilities. +@end menu + +@node #if Directive +@subsubsection The @samp{#if} Directive + +The @samp{#if} directive in its simplest form consists of + +@example +#if @var{expression} +@var{controlled text} +#endif /* @var{expression} */ +@end example + +The comment following the @samp{#endif} is not required, but it is a good +practice because it helps people match the @samp{#endif} to the +corresponding @samp{#if}. Such comments should always be used, except in +short conditionals that are not nested. In fact, you can put anything at +all after the @samp{#endif} and it will be ignored by the GNU C preprocessor, +but only comments are acceptable in ANSI Standard C. + +@var{expression} is a C expression of integer type, subject to stringent +restrictions. It may contain + +@itemize @bullet +@item +Integer constants, which are all regarded as @code{long} or +@code{unsigned long}. + +@item +Character constants, which are interpreted according to the character +set and conventions of the machine and operating system on which the +preprocessor is running. The GNU C preprocessor uses the C data type +@samp{char} for these character constants; therefore, whether some +character codes are negative is determined by the C compiler used to +compile the preprocessor. If it treats @samp{char} as signed, then +character codes large enough to set the sign bit will be considered +negative; otherwise, no character code is considered negative. + +@item +Arithmetic operators for addition, subtraction, multiplication, +division, bitwise operations, shifts, comparisons, and logical +operations (@samp{&&} and @samp{||}). + +@item +Identifiers that are not macros, which are all treated as zero(!). + +@item +Macro calls. All macro calls in the expression are expanded before +actual computation of the expression's value begins. +@end itemize + +Note that @samp{sizeof} operators and @code{enum}-type values are not allowed. +@code{enum}-type values, like all other identifiers that are not taken +as macro calls and expanded, are treated as zero. + +The @var{controlled text} inside of a conditional can include +preprocessing directives. Then the directives inside the conditional are +obeyed only if that branch of the conditional succeeds. The text can +also contain other conditional groups. However, the @samp{#if} and +@samp{#endif} directives must balance. + +@node #else Directive +@subsubsection The @samp{#else} Directive + +@findex #else +The @samp{#else} directive can be added to a conditional to provide +alternative text to be used if the condition is false. This is what +it looks like: + +@example +#if @var{expression} +@var{text-if-true} +#else /* Not @var{expression} */ +@var{text-if-false} +#endif /* Not @var{expression} */ +@end example + +If @var{expression} is nonzero, and thus the @var{text-if-true} is +active, then @samp{#else} acts like a failing conditional and the +@var{text-if-false} is ignored. Contrariwise, if the @samp{#if} +conditional fails, the @var{text-if-false} is considered included. + +@node #elif Directive +@subsubsection The @samp{#elif} Directive + +@findex #elif +One common case of nested conditionals is used to check for more than two +possible alternatives. For example, you might have + +@example +#if X == 1 +@dots{} +#else /* X != 1 */ +#if X == 2 +@dots{} +#else /* X != 2 */ +@dots{} +#endif /* X != 2 */ +#endif /* X != 1 */ +@end example + +Another conditional directive, @samp{#elif}, allows this to be abbreviated +as follows: + +@example +#if X == 1 +@dots{} +#elif X == 2 +@dots{} +#else /* X != 2 and X != 1*/ +@dots{} +#endif /* X != 2 and X != 1*/ +@end example + +@samp{#elif} stands for ``else if''. Like @samp{#else}, it goes in the +middle of a @samp{#if}-@samp{#endif} pair and subdivides it; it does not +require a matching @samp{#endif} of its own. Like @samp{#if}, the +@samp{#elif} directive includes an expression to be tested. + +The text following the @samp{#elif} is processed only if the original +@samp{#if}-condition failed and the @samp{#elif} condition succeeds. +More than one @samp{#elif} can go in the same @samp{#if}-@samp{#endif} +group. Then the text after each @samp{#elif} is processed only if the +@samp{#elif} condition succeeds after the original @samp{#if} and any +previous @samp{#elif} directives within it have failed. @samp{#else} is +equivalent to @samp{#elif 1}, and @samp{#else} is allowed after any +number of @samp{#elif} directives, but @samp{#elif} may not follow +@samp{#else}. + +@node Deleted Code +@subsection Keeping Deleted Code for Future Reference +@cindex commenting out code + +If you replace or delete a part of the program but want to keep the old +code around as a comment for future reference, the easy way to do this +is to put @samp{#if 0} before it and @samp{#endif} after it. This is +better than using comment delimiters @samp{/*} and @samp{*/} since those +won't work if the code already contains comments (C comments do not +nest). + +This works even if the code being turned off contains conditionals, but +they must be entire conditionals (balanced @samp{#if} and @samp{#endif}). + +Conversely, do not use @samp{#if 0} for comments which are not C code. +Use the comment delimiters @samp{/*} and @samp{*/} instead. The +interior of @samp{#if 0} must consist of complete tokens; in particular, +singlequote characters must balance. But comments often contain +unbalanced singlequote characters (known in English as apostrophes). +These confuse @samp{#if 0}. They do not confuse @samp{/*}. + +@node Conditionals-Macros +@subsection Conditionals and Macros + +Conditionals are useful in connection with macros or assertions, because +those are the only ways that an expression's value can vary from one +compilation to another. A @samp{#if} directive whose expression uses no +macros or assertions is equivalent to @samp{#if 1} or @samp{#if 0}; you +might as well determine which one, by computing the value of the +expression yourself, and then simplify the program. + +For example, here is a conditional that tests the expression +@samp{BUFSIZE == 1020}, where @samp{BUFSIZE} must be a macro. + +@example +#if BUFSIZE == 1020 + printf ("Large buffers!\n"); +#endif /* BUFSIZE is large */ +@end example + +(Programmers often wish they could test the size of a variable or data +type in @samp{#if}, but this does not work. The preprocessor does not +understand @code{sizeof}, or typedef names, or even the type keywords +such as @code{int}.) + +@findex defined +The special operator @samp{defined} is used in @samp{#if} expressions to +test whether a certain name is defined as a macro. Either @samp{defined +@var{name}} or @samp{defined (@var{name})} is an expression whose value +is 1 if @var{name} is defined as macro at the current point in the +program, and 0 otherwise. For the @samp{defined} operator it makes no +difference what the definition of the macro is; all that matters is +whether there is a definition. Thus, for example,@refill + +@example +#if defined (vax) || defined (ns16000) +@end example + +@noindent +would succeed if either of the names @samp{vax} and @samp{ns16000} is +defined as a macro. You can test the same condition using assertions +(@pxref{Assertions}), like this: + +@example +#if #cpu (vax) || #cpu (ns16000) +@end example + +If a macro is defined and later undefined with @samp{#undef}, +subsequent use of the @samp{defined} operator returns 0, because +the name is no longer defined. If the macro is defined again with +another @samp{#define}, @samp{defined} will recommence returning 1. + +@findex #ifdef +@findex #ifndef +Conditionals that test whether just one name is defined are very common, +so there are two special short conditional directives for this case. + +@table @code +@item #ifdef @var{name} +is equivalent to @samp{#if defined (@var{name})}. + +@item #ifndef @var{name} +is equivalent to @samp{#if ! defined (@var{name})}. +@end table + +Macro definitions can vary between compilations for several reasons. + +@itemize @bullet +@item +Some macros are predefined on each kind of machine. For example, on a +Vax, the name @samp{vax} is a predefined macro. On other machines, it +would not be defined. + +@item +Many more macros are defined by system header files. Different +systems and machines define different macros, or give them different +values. It is useful to test these macros with conditionals to avoid +using a system feature on a machine where it is not implemented. + +@item +Macros are a common way of allowing users to customize a program for +different machines or applications. For example, the macro +@samp{BUFSIZE} might be defined in a configuration file for your +program that is included as a header file in each source file. You +would use @samp{BUFSIZE} in a preprocessing conditional in order to +generate different code depending on the chosen configuration. + +@item +Macros can be defined or undefined with @samp{-D} and @samp{-U} +command options when you compile the program. You can arrange to +compile the same source file into two different programs by choosing +a macro name to specify which program you want, writing conditionals +to test whether or how this macro is defined, and then controlling +the state of the macro with compiler command options. +@xref{Invocation}. +@end itemize + +@ifinfo +Assertions are usually predefined, but can be defined with preprocessor +directives or command-line options. +@end ifinfo + +@node Assertions +@subsection Assertions + +@cindex assertions +@dfn{Assertions} are a more systematic alternative to macros in writing +conditionals to test what sort of computer or system the compiled +program will run on. Assertions are usually predefined, but you can +define them with preprocessing directives or command-line options. + +@cindex predicates +The macros traditionally used to describe the type of target are not +classified in any way according to which question they answer; they may +indicate a hardware architecture, a particular hardware model, an +operating system, a particular version of an operating system, or +specific configuration options. These are jumbled together in a single +namespace. In contrast, each assertion consists of a named question and +an answer. The question is usually called the @dfn{predicate}. +An assertion looks like this: + +@example +#@var{predicate} (@var{answer}) +@end example + +@noindent +You must use a properly formed identifier for @var{predicate}. The +value of @var{answer} can be any sequence of words; all characters are +significant except for leading and trailing whitespace, and differences +in internal whitespace sequences are ignored. Thus, @samp{x + y} is +different from @samp{x+y} but equivalent to @samp{x + y}. @samp{)} is +not allowed in an answer. + +@cindex testing predicates +Here is a conditional to test whether the answer @var{answer} is asserted +for the predicate @var{predicate}: + +@example +#if #@var{predicate} (@var{answer}) +@end example + +@noindent +There may be more than one answer asserted for a given predicate. If +you omit the answer, you can test whether @emph{any} answer is asserted +for @var{predicate}: + +@example +#if #@var{predicate} +@end example + +@findex #system +@findex #machine +@findex #cpu +Most of the time, the assertions you test will be predefined assertions. +GNU C provides three predefined predicates: @code{system}, @code{cpu}, +and @code{machine}. @code{system} is for assertions about the type of +software, @code{cpu} describes the type of computer architecture, and +@code{machine} gives more information about the computer. For example, +on a GNU system, the following assertions would be true: + +@example +#system (gnu) +#system (mach) +#system (mach 3) +#system (mach 3.@var{subversion}) +#system (hurd) +#system (hurd @var{version}) +@end example + +@noindent +and perhaps others. The alternatives with +more or less version information let you ask more or less detailed +questions about the type of system software. + +On a Unix system, you would find @code{#system (unix)} and perhaps one of: +@code{#system (aix)}, @code{#system (bsd)}, @code{#system (hpux)}, +@code{#system (lynx)}, @code{#system (mach)}, @code{#system (posix)}, +@code{#system (svr3)}, @code{#system (svr4)}, or @code{#system (xpg4)} +with possible version numbers following. + +Other values for @code{system} are @code{#system (mvs)} +and @code{#system (vms)}. + +@strong{Portability note:} Many Unix C compilers provide only one answer +for the @code{system} assertion: @code{#system (unix)}, if they support +assertions at all. This is less than useful. + +An assertion with a multi-word answer is completely different from several +assertions with individual single-word answers. For example, the presence +of @code{system (mach 3.0)} does not mean that @code{system (3.0)} is true. +It also does not directly imply @code{system (mach)}, but in GNU C, that +last will normally be asserted as well. + +The current list of possible assertion values for @code{cpu} is: +@code{#cpu (a29k)}, @code{#cpu (alpha)}, @code{#cpu (arm)}, @code{#cpu +(clipper)}, @code{#cpu (convex)}, @code{#cpu (elxsi)}, @code{#cpu +(tron)}, @code{#cpu (h8300)}, @code{#cpu (i370)}, @code{#cpu (i386)}, +@code{#cpu (i860)}, @code{#cpu (i960)}, @code{#cpu (m68k)}, @code{#cpu +(m88k)}, @code{#cpu (mips)}, @code{#cpu (ns32k)}, @code{#cpu (hppa)}, +@code{#cpu (pyr)}, @code{#cpu (ibm032)}, @code{#cpu (rs6000)}, +@code{#cpu (sh)}, @code{#cpu (sparc)}, @code{#cpu (spur)}, @code{#cpu +(tahoe)}, @code{#cpu (vax)}, @code{#cpu (we32000)}. + +@findex #assert +You can create assertions within a C program using @samp{#assert}, like +this: + +@example +#assert @var{predicate} (@var{answer}) +@end example + +@noindent +(Note the absence of a @samp{#} before @var{predicate}.) + +@cindex unassert +@cindex assertions, undoing +@cindex retracting assertions +@findex #unassert +Each time you do this, you assert a new true answer for @var{predicate}. +Asserting one answer does not invalidate previously asserted answers; +they all remain true. The only way to remove an assertion is with +@samp{#unassert}. @samp{#unassert} has the same syntax as +@samp{#assert}. You can also remove all assertions about +@var{predicate} like this: + +@example +#unassert @var{predicate} +@end example + +You can also add or cancel assertions using command options +when you run @code{gcc} or @code{cpp}. @xref{Invocation}. + +@node #error Directive +@subsection The @samp{#error} and @samp{#warning} Directives + +@findex #error +The directive @samp{#error} causes the preprocessor to report a fatal +error. The rest of the line that follows @samp{#error} is used as the +error message. + +You would use @samp{#error} inside of a conditional that detects a +combination of parameters which you know the program does not properly +support. For example, if you know that the program will not run +properly on a Vax, you might write + +@smallexample +@group +#ifdef __vax__ +#error Won't work on Vaxen. See comments at get_last_object. +#endif +@end group +@end smallexample + +@noindent +@xref{Nonstandard Predefined}, for why this works. + +If you have several configuration parameters that must be set up by +the installation in a consistent way, you can use conditionals to detect +an inconsistency and report it with @samp{#error}. For example, + +@smallexample +#if HASH_TABLE_SIZE % 2 == 0 || HASH_TABLE_SIZE % 3 == 0 \ + || HASH_TABLE_SIZE % 5 == 0 +#error HASH_TABLE_SIZE should not be divisible by a small prime +#endif +@end smallexample + +@findex #warning +The directive @samp{#warning} is like the directive @samp{#error}, but causes +the preprocessor to issue a warning and continue preprocessing. The rest of +the line that follows @samp{#warning} is used as the warning message. + +You might use @samp{#warning} in obsolete header files, with a message +directing the user to the header file which should be used instead. + +@node Combining Sources, Other Directives, Conditionals, Top +@section Combining Source Files + +@cindex line control +One of the jobs of the C preprocessor is to inform the C compiler of where +each line of C code came from: which source file and which line number. + +C code can come from multiple source files if you use @samp{#include}; +both @samp{#include} and the use of conditionals and macros can cause +the line number of a line in the preprocessor output to be different +from the line's number in the original source file. You will appreciate +the value of making both the C compiler (in error messages) and symbolic +debuggers such as GDB use the line numbers in your source file. + +The C preprocessor builds on this feature by offering a directive by which +you can control the feature explicitly. This is useful when a file for +input to the C preprocessor is the output from another program such as the +@code{bison} parser generator, which operates on another file that is the +true source file. Parts of the output from @code{bison} are generated from +scratch, other parts come from a standard parser file. The rest are copied +nearly verbatim from the source file, but their line numbers in the +@code{bison} output are not the same as their original line numbers. +Naturally you would like compiler error messages and symbolic debuggers to +know the original source file and line number of each line in the +@code{bison} input. + +@findex #line +@code{bison} arranges this by writing @samp{#line} directives into the output +file. @samp{#line} is a directive that specifies the original line number +and source file name for subsequent input in the current preprocessor input +file. @samp{#line} has three variants: + +@table @code +@item #line @var{linenum} +Here @var{linenum} is a decimal integer constant. This specifies that +the line number of the following line of input, in its original source file, +was @var{linenum}. + +@item #line @var{linenum} @var{filename} +Here @var{linenum} is a decimal integer constant and @var{filename} +is a string constant. This specifies that the following line of input +came originally from source file @var{filename} and its line number there +was @var{linenum}. Keep in mind that @var{filename} is not just a +file name; it is surrounded by doublequote characters so that it looks +like a string constant. + +@item #line @var{anything else} +@var{anything else} is checked for macro calls, which are expanded. +The result should be a decimal integer constant followed optionally +by a string constant, as described above. +@end table + +@samp{#line} directives alter the results of the @samp{__FILE__} and +@samp{__LINE__} predefined macros from that point on. @xref{Standard +Predefined}. + +The output of the preprocessor (which is the input for the rest of the +compiler) contains directives that look much like @samp{#line} directives. +They start with just @samp{#} instead of @samp{#line}, but this is +followed by a line number and file name as in @samp{#line}. @xref{Output}. + +@node Other Directives, Output, Combining Sources, Top +@section Miscellaneous Preprocessing Directives + +@cindex null directive +This section describes three additional preprocessing directives. They are +not very useful, but are mentioned for completeness. + +The @dfn{null directive} consists of a @samp{#} followed by a Newline, with +only whitespace (including comments) in between. A null directive is +understood as a preprocessing directive but has no effect on the preprocessor +output. The primary significance of the existence of the null directive is +that an input line consisting of just a @samp{#} will produce no output, +rather than a line of output containing just a @samp{#}. Supposedly +some old C programs contain such lines. + +@findex #pragma +The ANSI standard specifies that the @samp{#pragma} directive has an +arbitrary, implementation-defined effect. In the GNU C preprocessor, +@samp{#pragma} directives are not used, except for @samp{#pragma once} +(@pxref{Once-Only}). However, they are left in the preprocessor output, +so they are available to the compilation pass. + +@findex #ident +The @samp{#ident} directive is supported for compatibility with certain +other systems. It is followed by a line of text. On some systems, the +text is copied into a special place in the object file; on most systems, +the text is ignored and this directive has no effect. Typically +@samp{#ident} is only used in header files supplied with those systems +where it is meaningful. + +@node Output, Invocation, Other Directives, Top +@section C Preprocessor Output + +@cindex output format +The output from the C preprocessor looks much like the input, except +that all preprocessing directive lines have been replaced with blank lines +and all comments with spaces. Whitespace within a line is not altered; +however, a space is inserted after the expansions of most macro calls. + +Source file name and line number information is conveyed by lines of +the form + +@example +# @var{linenum} @var{filename} @var{flags} +@end example + +@noindent +which are inserted as needed into the middle of the input (but never +within a string or character constant). Such a line means that the +following line originated in file @var{filename} at line @var{linenum}. + +After the file name comes zero or more flags, which are @samp{1}, +@samp{2}, @samp{3}, or @samp{4}. If there are multiple flags, spaces separate +them. Here is what the flags mean: + +@table @samp +@item 1 +This indicates the start of a new file. +@item 2 +This indicates returning to a file (after having included another file). +@item 3 +This indicates that the following text comes from a system header file, +so certain warnings should be suppressed. +@item 4 +This indicates that the following text should be treated as C. +@c maybe cross reference NO_IMPLICIT_EXTERN_C +@end table + +@node Invocation, Concept Index, Output, Top +@section Invoking the C Preprocessor +@cindex invocation of the preprocessor + +Most often when you use the C preprocessor you will not have to invoke it +explicitly: the C compiler will do so automatically. However, the +preprocessor is sometimes useful on its own. + +The C preprocessor expects two file names as arguments, @var{infile} and +@var{outfile}. The preprocessor reads @var{infile} together with any other +files it specifies with @samp{#include}. All the output generated by the +combined input files is written in @var{outfile}. + +Either @var{infile} or @var{outfile} may be @samp{-}, which as @var{infile} +means to read from standard input and as @var{outfile} means to write to +standard output. Also, if @var{outfile} or both file names are omitted, +the standard output and standard input are used for the omitted file names. + +@cindex options +Here is a table of command options accepted by the C preprocessor. +These options can also be given when compiling a C program; they are +passed along automatically to the preprocessor when it is invoked by the +compiler. + +@table @samp +@item -P +@findex -P +Inhibit generation of @samp{#}-lines with line-number information in +the output from the preprocessor (@pxref{Output}). This might be +useful when running the preprocessor on something that is not C code +and will be sent to a program which might be confused by the +@samp{#}-lines. + +@item -C +@findex -C +Do not discard comments: pass them through to the output file. +Comments appearing in arguments of a macro call will be copied to the +output before the expansion of the macro call. + +@item -traditional +@findex -traditional +Try to imitate the behavior of old-fashioned C, as opposed to ANSI C. + +@itemize @bullet +@item +Traditional macro expansion pays no attention to singlequote or +doublequote characters; macro argument symbols are replaced by the +argument values even when they appear within apparent string or +character constants. + +@item +Traditionally, it is permissible for a macro expansion to end in the +middle of a string or character constant. The constant continues into +the text surrounding the macro call. + +@item +However, traditionally the end of the line terminates a string or +character constant, with no error. + +@item +In traditional C, a comment is equivalent to no text at all. (In ANSI +C, a comment counts as whitespace.) + +@item +Traditional C does not have the concept of a ``preprocessing number''. +It considers @samp{1.0e+4} to be three tokens: @samp{1.0e}, @samp{+}, +and @samp{4}. + +@item +A macro is not suppressed within its own definition, in traditional C. +Thus, any macro that is used recursively inevitably causes an error. + +@item +The character @samp{#} has no special meaning within a macro definition +in traditional C. + +@item +In traditional C, the text at the end of a macro expansion can run +together with the text after the macro call, to produce a single token. +(This is impossible in ANSI C.) + +@item +Traditionally, @samp{\} inside a macro argument suppresses the syntactic +significance of the following character. +@end itemize + +@item -trigraphs +@findex -trigraphs +Process ANSI standard trigraph sequences. These are three-character +sequences, all starting with @samp{??}, that are defined by ANSI C to +stand for single characters. For example, @samp{??/} stands for +@samp{\}, so @samp{'??/n'} is a character constant for a newline. +Strictly speaking, the GNU C preprocessor does not support all +programs in ANSI Standard C unless @samp{-trigraphs} is used, but if +you ever notice the difference it will be with relief. + +You don't want to know any more about trigraphs. + +@item -pedantic +@findex -pedantic +Issue warnings required by the ANSI C standard in certain cases such +as when text other than a comment follows @samp{#else} or @samp{#endif}. + +@item -pedantic-errors +@findex -pedantic-errors +Like @samp{-pedantic}, except that errors are produced rather than +warnings. + +@item -Wtrigraphs +@findex -Wtrigraphs +Warn if any trigraphs are encountered (assuming they are enabled). + +@item -Wcomment +@findex -Wcomment +@ignore +@c "Not worth documenting" both singular and plural forms of this +@c option, per RMS. But also unclear which is better; hence may need to +@c switch this at some future date. pesch@cygnus.com, 2jan92. +@itemx -Wcomments +(Both forms have the same effect). +@end ignore +Warn whenever a comment-start sequence @samp{/*} appears in a comment. + +@item -Wall +@findex -Wall +Requests both @samp{-Wtrigraphs} and @samp{-Wcomment} (but not +@samp{-Wtraditional}). + +@item -Wtraditional +@findex -Wtraditional +Warn about certain constructs that behave differently in traditional and +ANSI C. + +@item -I @var{directory} +@findex -I +Add the directory @var{directory} to the head of the list of +directories to be searched for header files (@pxref{Include Syntax}). +This can be used to override a system header file, substituting your +own version, since these directories are searched before the system +header file directories. If you use more than one @samp{-I} option, +the directories are scanned in left-to-right order; the standard +system directories come after. + +@item -I- +Any directories specified with @samp{-I} options before the @samp{-I-} +option are searched only for the case of @samp{#include "@var{file}"}; +they are not searched for @samp{#include <@var{file}>}. + +If additional directories are specified with @samp{-I} options after +the @samp{-I-}, these directories are searched for all @samp{#include} +directives. + +In addition, the @samp{-I-} option inhibits the use of the current +directory as the first search directory for @samp{#include "@var{file}"}. +Therefore, the current directory is searched only if it is requested +explicitly with @samp{-I.}. Specifying both @samp{-I-} and @samp{-I.} +allows you to control precisely which directories are searched before +the current one and which are searched after. + +@item -nostdinc +@findex -nostdinc +Do not search the standard system directories for header files. +Only the directories you have specified with @samp{-I} options +(and the current directory, if appropriate) are searched. + +@item -nostdinc++ +@findex -nostdinc++ +Do not search for header files in the C++-specific standard directories, +but do still search the other standard directories. +(This option is used when building libg++.) + +@item -D @var{name} +@findex -D +Predefine @var{name} as a macro, with definition @samp{1}. + +@item -D @var{name}=@var{definition} +Predefine @var{name} as a macro, with definition @var{definition}. +There are no restrictions on the contents of @var{definition}, but if +you are invoking the preprocessor from a shell or shell-like program you +may need to use the shell's quoting syntax to protect characters such as +spaces that have a meaning in the shell syntax. If you use more than +one @samp{-D} for the same @var{name}, the rightmost definition takes +effect. + +@item -U @var{name} +@findex -U +Do not predefine @var{name}. If both @samp{-U} and @samp{-D} are +specified for one name, the @samp{-U} beats the @samp{-D} and the name +is not predefined. + +@item -undef +@findex -undef +Do not predefine any nonstandard macros. + +@item -A @var{predicate}(@var{answer}) +@findex -A +Make an assertion with the predicate @var{predicate} and answer +@var{answer}. @xref{Assertions}. + +@noindent +You can use @samp{-A-} to disable all predefined assertions; it also +undefines all predefined macros that identify the type of target system. + +@item -dM +@findex -dM +Instead of outputting the result of preprocessing, output a list of +@samp{#define} directives for all the macros defined during the +execution of the preprocessor, including predefined macros. This gives +you a way of finding out what is predefined in your version of the +preprocessor; assuming you have no file @samp{foo.h}, the command + +@example +touch foo.h; cpp -dM foo.h +@end example + +@noindent +will show the values of any predefined macros. + +@item -dD +@findex -dD +Like @samp{-dM} except in two respects: it does @emph{not} include the +predefined macros, and it outputs @emph{both} the @samp{#define} +directives and the result of preprocessing. Both kinds of output go to +the standard output file. + +@item -M [-MG] +@findex -M +Instead of outputting the result of preprocessing, output a rule +suitable for @code{make} describing the dependencies of the main +source file. The preprocessor outputs one @code{make} rule containing +the object file name for that source file, a colon, and the names of +all the included files. If there are many included files then the +rule is split into several lines using @samp{\}-newline. + +@samp{-MG} says to treat missing header files as generated files and assume +they live in the same directory as the source file. It must be specified +in addition to @samp{-M}. + +This feature is used in automatic updating of makefiles. + +@item -MM [-MG] +@findex -MM +Like @samp{-M} but mention only the files included with @samp{#include +"@var{file}"}. System header files included with @samp{#include +<@var{file}>} are omitted. + +@item -MD @var{file} +@findex -MD +Like @samp{-M} but the dependency information is written to @var{file}. +This is in addition to compiling the file as specified---@samp{-MD} does +not inhibit ordinary compilation the way @samp{-M} does. + +When invoking gcc, do not specify the @var{file} argument. +Gcc will create file names made by replacing ".c" with ".d" at +the end of the input file names. + +In Mach, you can use the utility @code{md} to merge multiple dependency +files into a single dependency file suitable for using with the @samp{make} +command. + +@item -MMD @var{file} +@findex -MMD +Like @samp{-MD} except mention only user header files, not system +header files. + +@item -H +@findex -H +Print the name of each header file used, in addition to other normal +activities. + +@item -imacros @var{file} +@findex -imacros +Process @var{file} as input, discarding the resulting output, before +processing the regular input file. Because the output generated from +@var{file} is discarded, the only effect of @samp{-imacros @var{file}} +is to make the macros defined in @var{file} available for use in the +main input. + +@item -include @var{file} +@findex -include +Process @var{file} as input, and include all the resulting output, +before processing the regular input file. + +@item -idirafter @var{dir} +@findex -idirafter +@cindex second include path +Add the directory @var{dir} to the second include path. The directories +on the second include path are searched when a header file is not found +in any of the directories in the main include path (the one that +@samp{-I} adds to). + +@item -iprefix @var{prefix} +@findex -iprefix +Specify @var{prefix} as the prefix for subsequent @samp{-iwithprefix} +options. + +@item -iwithprefix @var{dir} +@findex -iwithprefix +Add a directory to the second include path. The directory's name is +made by concatenating @var{prefix} and @var{dir}, where @var{prefix} +was specified previously with @samp{-iprefix}. + +@item -isystem @var{dir} +@findex -isystem +Add a directory to the beginning of the second include path, marking it +as a system directory, so that it gets the same special treatment as +is applied to the standard system directories. + +@item -lang-c +@itemx -lang-c89 +@itemx -lang-c++ +@itemx -lang-objc +@itemx -lang-objc++ +@findex -lang-c +@findex -lang-c89 +@findex -lang-c++ +@findex -lang-objc +@findex -lang-objc++ +Specify the source language. @samp{-lang-c} is the default; it +allows recognition of C++ comments (comments that begin with +@samp{//} and end at end of line), since this is +a common feature and it will most likely be in the next C standard. +@samp{-lang-c89} disables recognition of C++ comments. @samp{-lang-c++} +handles C++ comment syntax and includes extra default include +directories for C++. @samp{-lang-objc} enables the Objective C +@samp{#import} directive. @samp{-lang-objc++} enables both C++ and Objective C +extensions. + +These options are generated by the compiler driver @code{gcc}, but not +passed from the @samp{gcc} command line unless you use the driver's +@samp{-Wp} option. + +@item -lint +Look for commands to the program checker @code{lint} embedded in +comments, and emit them preceded by @samp{#pragma lint}. For example, +the comment @samp{/* NOTREACHED */} becomes @samp{#pragma lint +NOTREACHED}. + +This option is available only when you call @code{cpp} directly; +@code{gcc} will not pass it from its command line. + +@item -$ +@findex -$ +Forbid the use of @samp{$} in identifiers. This is required for ANSI +conformance. @code{gcc} automatically supplies this option to the +preprocessor if you specify @samp{-ansi}, but @code{gcc} doesn't +recognize the @samp{-$} option itself---to use it without the other +effects of @samp{-ansi}, you must call the preprocessor directly. + +@end table + +@node Concept Index, Index, Invocation, Top +@unnumbered Concept Index +@printindex cp + +@node Index,, Concept Index, Top +@unnumbered Index of Directives, Macros and Options +@printindex fn + +@contents +@bye diff --git a/contrib/gcc/cppalloc.c b/contrib/gcc/cppalloc.c new file mode 100644 index 00000000000..f7b6019d460 --- /dev/null +++ b/contrib/gcc/cppalloc.c @@ -0,0 +1,64 @@ +/* Part of CPP library. (memory allocation - xmalloc etc) + Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994. + Based on CCCP program by by Paul Rubin, June 1986 + Adapted to ANSI C, Richard Stallman, Jan 1987 + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#include "config.h" + +static void +memory_full () +{ + fatal ("Memory exhausted."); +} + +char * +xmalloc (size) + unsigned size; +{ + register char *ptr = (char *) malloc (size); + if (ptr != 0) return (ptr); + memory_full (); + /*NOTREACHED*/ + return 0; +} + +char * +xrealloc (old, size) + char *old; + unsigned size; +{ + register char *ptr = (char *) realloc (old, size); + if (ptr == 0) + memory_full (); + return ptr; +} + +char * +xcalloc (number, size) + unsigned number, size; +{ + register unsigned total = number * size; + register char *ptr = (char *) calloc (number, size); + if (ptr == 0) + memory_full (); + return ptr; +} diff --git a/contrib/gcc/cpperror.c b/contrib/gcc/cpperror.c new file mode 100644 index 00000000000..5ba3b78f457 --- /dev/null +++ b/contrib/gcc/cpperror.c @@ -0,0 +1,128 @@ +/* Default error handlers for CPP Library. + Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994. + Based on CCCP program by by Paul Rubin, June 1986 + Adapted to ANSI C, Richard Stallman, Jan 1987 + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#ifndef EMACS +#include "config.h" +#endif /* not EMACS */ + +#include "cpplib.h" +#include + +/* Print the file names and line numbers of the #include + commands which led to the current file. */ + +void +cpp_print_containing_files (pfile) + cpp_reader *pfile; +{ + cpp_buffer *ip; + int i; + int first = 1; + + /* If stack of files hasn't changed since we last printed + this info, don't repeat it. */ + if (pfile->input_stack_listing_current) + return; + + ip = cpp_file_buffer (pfile); + + /* Give up if we don't find a source file. */ + if (ip == NULL) + return; + + /* Find the other, outer source files. */ + while ((ip = CPP_PREV_BUFFER (ip)), ip != CPP_NULL_BUFFER (pfile)) + { + long line, col; + cpp_buf_line_and_col (ip, &line, &col); + if (ip->fname != NULL) + { + if (first) + { + first = 0; + fprintf (stderr, "In file included"); + } + else + fprintf (stderr, ",\n "); + } + + fprintf (stderr, " from %s:%d", ip->nominal_fname, line); + } + if (! first) + fprintf (stderr, ":\n"); + + /* Record we have printed the status as of this time. */ + pfile->input_stack_listing_current = 1; +} + +void +cpp_file_line_for_message (pfile, filename, line, column) + cpp_reader *pfile; + char *filename; + int line, column; +{ + if (column > 0) + fprintf (stderr, "%s:%d:%d: ", filename, line, column); + else + fprintf (stderr, "%s:%d: ", filename, line); +} + +/* IS_ERROR is 1 for error, 0 for warning */ +void cpp_message (pfile, is_error, msg, arg1, arg2, arg3) + int is_error; + cpp_reader *pfile; + char *msg; + char *arg1, *arg2, *arg3; +{ + if (is_error) + pfile->errors++; + else + fprintf (stderr, "warning: "); + fprintf (stderr, msg, arg1, arg2, arg3); + fprintf (stderr, "\n"); +} + +void +fatal (str, arg) + char *str, *arg; +{ + fprintf (stderr, "%s: ", progname); + fprintf (stderr, str, arg); + fprintf (stderr, "\n"); + exit (FATAL_EXIT_CODE); +} + + +void +cpp_pfatal_with_name (pfile, name) + cpp_reader *pfile; + char *name; +{ + cpp_perror_with_name (pfile, name); +#ifdef VMS + exit (vaxc$errno); +#else + exit (FATAL_EXIT_CODE); +#endif +} diff --git a/contrib/gcc/cppexp.c b/contrib/gcc/cppexp.c new file mode 100644 index 00000000000..6b73ad34e4d --- /dev/null +++ b/contrib/gcc/cppexp.c @@ -0,0 +1,997 @@ +/* Parse C expressions for CCCP. + Copyright (C) 1987, 1992, 1994, 1995 Free Software Foundation. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! + +Written by Per Bothner 1994. */ + +/* Parse a C expression from text in a string */ + +#include "config.h" +#include "cpplib.h" + +extern char *xmalloc PARAMS ((unsigned)); +extern char *xrealloc PARAMS ((char *, unsigned)); + +#ifdef MULTIBYTE_CHARS +#include +#include +#endif + +#include + +/* This is used for communicating lists of keywords with cccp.c. */ +struct arglist { + struct arglist *next; + U_CHAR *name; + int length; + int argno; +}; + +/* Define a generic NULL if one hasn't already been defined. */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef GENERIC_PTR +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define GENERIC_PTR void * +#else +#define GENERIC_PTR char * +#endif +#endif + +#ifndef NULL_PTR +#define NULL_PTR ((GENERIC_PTR)0) +#endif + +extern char *xmalloc (); + +#ifndef CHAR_TYPE_SIZE +#define CHAR_TYPE_SIZE BITS_PER_UNIT +#endif + +#ifndef INT_TYPE_SIZE +#define INT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_TYPE_SIZE +#define LONG_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE INT_TYPE_SIZE +#endif + +#ifndef MAX_CHAR_TYPE_SIZE +#define MAX_CHAR_TYPE_SIZE CHAR_TYPE_SIZE +#endif + +#ifndef MAX_INT_TYPE_SIZE +#define MAX_INT_TYPE_SIZE INT_TYPE_SIZE +#endif + +#ifndef MAX_LONG_TYPE_SIZE +#define MAX_LONG_TYPE_SIZE LONG_TYPE_SIZE +#endif + +#ifndef MAX_WCHAR_TYPE_SIZE +#define MAX_WCHAR_TYPE_SIZE WCHAR_TYPE_SIZE +#endif + +/* Yield nonzero if adding two numbers with A's and B's signs can yield a + number with SUM's sign, where A, B, and SUM are all C integers. */ +#define possible_sum_sign(a, b, sum) ((((a) ^ (b)) | ~ ((a) ^ (sum))) < 0) + +static void integer_overflow (); +static long left_shift (); +static long right_shift (); + +#define ERROR 299 +#define OROR 300 +#define ANDAND 301 +#define EQUAL 302 +#define NOTEQUAL 303 +#define LEQ 304 +#define GEQ 305 +#define LSH 306 +#define RSH 307 +#define NAME 308 +#define INT 309 +#define CHAR 310 + +#define LEFT_OPERAND_REQUIRED 1 +#define RIGHT_OPERAND_REQUIRED 2 +#define HAVE_VALUE 4 +/*#define UNSIGNEDP 8*/ + +#ifndef HOST_BITS_PER_WIDE_INT + +#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG +#define HOST_WIDE_INT long +#else +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT +#define HOST_WIDE_INT int +#endif + +#endif + +struct operation { + short op; + char rprio; /* Priority of op (relative to it right operand). */ + char flags; + char unsignedp; /* true if value should be treated as unsigned */ + HOST_WIDE_INT value; /* The value logically "right" of op. */ +}; + +/* Take care of parsing a number (anything that starts with a digit). + LEN is the number of characters in it. */ + +/* maybe needs to actually deal with floating point numbers */ + +struct operation +parse_number (pfile, start, olen) + cpp_reader *pfile; + char *start; + int olen; +{ + struct operation op; + register char *p = start; + register int c; + register unsigned long n = 0, nd, ULONG_MAX_over_base; + register int base = 10; + register int len = olen; + register int overflow = 0; + register int digit, largest_digit = 0; + int spec_long = 0; + + op.unsignedp = 0; + + for (c = 0; c < len; c++) + if (p[c] == '.') { + /* It's a float since it contains a point. */ + cpp_error (pfile, + "floating point numbers not allowed in #if expressions"); + op.op = ERROR; + return op; + } + + if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) { + p += 2; + base = 16; + len -= 2; + } + else if (*p == '0') + base = 8; + + /* Some buggy compilers (e.g. MPW C) seem to need both casts. */ + ULONG_MAX_over_base = ((unsigned long) -1) / ((unsigned long) base); + + for (; len > 0; len--) { + c = *p++; + + if (c >= '0' && c <= '9') + digit = c - '0'; + else if (base == 16 && c >= 'a' && c <= 'f') + digit = c - 'a' + 10; + else if (base == 16 && c >= 'A' && c <= 'F') + digit = c - 'A' + 10; + else { + /* `l' means long, and `u' means unsigned. */ + while (1) { + if (c == 'l' || c == 'L') + { + if (spec_long) + cpp_error (pfile, "two `l's in integer constant"); + spec_long = 1; + } + else if (c == 'u' || c == 'U') + { + if (op.unsignedp) + cpp_error (pfile, "two `u's in integer constant"); + op.unsignedp = 1; + } + else + break; + + if (--len == 0) + break; + c = *p++; + } + /* Don't look for any more digits after the suffixes. */ + break; + } + if (largest_digit < digit) + largest_digit = digit; + nd = n * base + digit; + overflow |= ULONG_MAX_over_base < n | nd < n; + n = nd; + } + + if (len != 0) + { + cpp_error (pfile, "Invalid number in #if expression"); + op.op = ERROR; + return op; + } + + if (base <= largest_digit) + cpp_warning (pfile, "integer constant contains digits beyond the radix"); + + if (overflow) + cpp_warning (pfile, "integer constant out of range"); + + /* If too big to be signed, consider it unsigned. */ + if ((long) n < 0 && ! op.unsignedp) + { + if (base == 10) + cpp_warning (pfile, "integer constant is so large that it is unsigned"); + op.unsignedp = 1; + } + + op.value = n; + op.op = INT; + return op; +} + +struct token { + char *operator; + int token; +}; + +static struct token tokentab2[] = { + {"&&", ANDAND}, + {"||", OROR}, + {"<<", LSH}, + {">>", RSH}, + {"==", EQUAL}, + {"!=", NOTEQUAL}, + {"<=", LEQ}, + {">=", GEQ}, + {"++", ERROR}, + {"--", ERROR}, + {NULL, ERROR} +}; + +/* Read one token. */ + +struct operation +cpp_lex (pfile) +cpp_reader *pfile; +{ + register int c; + register int namelen; + register struct token *toktab; + enum cpp_token token; + struct operation op; + U_CHAR *tok_start, *tok_end; + int old_written; + + retry: + + old_written = CPP_WRITTEN (pfile); + cpp_skip_hspace (pfile); + c = CPP_BUF_PEEK (CPP_BUFFER (pfile)); + if (c == '#') + return parse_number (pfile, + cpp_read_check_assertion (pfile) ? "1" : "0", 1); + + if (c == '\n') + { + op.op = 0; + return op; + } + + token = cpp_get_token (pfile); + tok_start = pfile->token_buffer + old_written; + tok_end = CPP_PWRITTEN (pfile); + pfile->limit = tok_start; + switch (token) + { + case CPP_EOF: /* Should not happen ... */ + op.op = 0; + return op; + case CPP_VSPACE: + case CPP_POP: + if (CPP_BUFFER (pfile)->fname != NULL) + { + op.op = 0; + return op; + } + goto retry; + case CPP_HSPACE: case CPP_COMMENT: + goto retry; + case CPP_NUMBER: + return parse_number (pfile, tok_start, tok_end - tok_start); + case CPP_STRING: + cpp_error (pfile, "string constants not allowed in #if expressions"); + op.op = ERROR; + return op; + case CPP_CHAR: + /* This code for reading a character constant + handles multicharacter constants and wide characters. + It is mostly copied from c-lex.c. */ + { + register int result = 0; + register num_chars = 0; + unsigned width = MAX_CHAR_TYPE_SIZE; + int wide_flag = 0; + int max_chars; + U_CHAR *ptr = tok_start; +#ifdef MULTIBYTE_CHARS + char token_buffer[MAX_LONG_TYPE_SIZE/MAX_CHAR_TYPE_SIZE + MB_CUR_MAX]; +#else + char token_buffer[MAX_LONG_TYPE_SIZE/MAX_CHAR_TYPE_SIZE + 1]; +#endif + + if (*ptr == 'L') + { + ptr++; + wide_flag = 1; + width = MAX_WCHAR_TYPE_SIZE; +#ifdef MULTIBYTE_CHARS + max_chars = MB_CUR_MAX; +#else + max_chars = 1; +#endif + } + else + max_chars = MAX_LONG_TYPE_SIZE / width; + + ++ptr; + while (ptr < tok_end && ((c = *ptr++) != '\'')) + { + if (c == '\\') + { + c = cpp_parse_escape (pfile, &ptr); + if (width < HOST_BITS_PER_INT + && (unsigned) c >= (1 << width)) + cpp_pedwarn (pfile, + "escape sequence out of range for character"); + } + + num_chars++; + + /* Merge character into result; ignore excess chars. */ + if (num_chars < max_chars + 1) + { + if (width < HOST_BITS_PER_INT) + result = (result << width) | (c & ((1 << width) - 1)); + else + result = c; + token_buffer[num_chars - 1] = c; + } + } + + token_buffer[num_chars] = 0; + + if (c != '\'') + cpp_error (pfile, "malformatted character constant"); + else if (num_chars == 0) + cpp_error (pfile, "empty character constant"); + else if (num_chars > max_chars) + { + num_chars = max_chars; + cpp_error (pfile, "character constant too long"); + } + else if (num_chars != 1 && ! CPP_TRADITIONAL (pfile)) + cpp_warning (pfile, "multi-character character constant"); + + /* If char type is signed, sign-extend the constant. */ + if (! wide_flag) + { + int num_bits = num_chars * width; + + if (cpp_lookup (pfile, "__CHAR_UNSIGNED__", + sizeof ("__CHAR_UNSIGNED__")-1, -1) + || ((result >> (num_bits - 1)) & 1) == 0) + op.value + = result & ((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits)); + else + op.value + = result | ~((unsigned long) ~0 >> (HOST_BITS_PER_LONG - num_bits)); + } + else + { +#ifdef MULTIBYTE_CHARS + /* Set the initial shift state and convert the next sequence. */ + result = 0; + /* In all locales L'\0' is zero and mbtowc will return zero, + so don't use it. */ + if (num_chars > 1 + || (num_chars == 1 && token_buffer[0] != '\0')) + { + wchar_t wc; + (void) mbtowc (NULL_PTR, NULL_PTR, 0); + if (mbtowc (& wc, token_buffer, num_chars) == num_chars) + result = wc; + else + cpp_warning (pfile,"Ignoring invalid multibyte character"); + } +#endif + op.value = result; + } + } + + /* This is always a signed type. */ + op.unsignedp = 0; + op.op = CHAR; + + return op; + + case CPP_NAME: + return parse_number (pfile, "0", 0); + + case CPP_OTHER: + /* See if it is a special token of length 2. */ + if (tok_start + 2 == tok_end) + { + for (toktab = tokentab2; toktab->operator != NULL; toktab++) + if (tok_start[0] == toktab->operator[0] + && tok_start[1] == toktab->operator[1]) + break; + if (toktab->token == ERROR) + { + char *buf = (char *) alloca (40); + sprintf (buf, "`%s' not allowed in operand of `#if'", tok_start); + cpp_error (pfile, buf); + } + op.op = toktab->token; + return op; + } + /* fall through */ + default: + op.op = *tok_start; + return op; + } +} + + +/* Parse a C escape sequence. STRING_PTR points to a variable + containing a pointer to the string to parse. That pointer + is updated past the characters we use. The value of the + escape sequence is returned. + + A negative value means the sequence \ newline was seen, + which is supposed to be equivalent to nothing at all. + + If \ is followed by a null character, we return a negative + value and leave the string pointer pointing at the null character. + + If \ is followed by 000, we return 0 and leave the string pointer + after the zeros. A value of 0 does not mean end of string. */ + +int +cpp_parse_escape (pfile, string_ptr) + cpp_reader *pfile; + char **string_ptr; +{ + register int c = *(*string_ptr)++; + switch (c) + { + case 'a': + return TARGET_BELL; + case 'b': + return TARGET_BS; + case 'e': + case 'E': + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "non-ANSI-standard escape sequence, `\\%c'", c); + return 033; + case 'f': + return TARGET_FF; + case 'n': + return TARGET_NEWLINE; + case 'r': + return TARGET_CR; + case 't': + return TARGET_TAB; + case 'v': + return TARGET_VT; + case '\n': + return -2; + case 0: + (*string_ptr)--; + return 0; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + { + register int i = c - '0'; + register int count = 0; + while (++count < 3) + { + c = *(*string_ptr)++; + if (c >= '0' && c <= '7') + i = (i << 3) + c - '0'; + else + { + (*string_ptr)--; + break; + } + } + if ((i & ~((1 << MAX_CHAR_TYPE_SIZE) - 1)) != 0) + { + i &= (1 << MAX_CHAR_TYPE_SIZE) - 1; + cpp_warning (pfile, + "octal character constant does not fit in a byte"); + } + return i; + } + case 'x': + { + register unsigned i = 0, overflow = 0, digits_found = 0, digit; + for (;;) + { + c = *(*string_ptr)++; + if (c >= '0' && c <= '9') + digit = c - '0'; + else if (c >= 'a' && c <= 'f') + digit = c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + digit = c - 'A' + 10; + else + { + (*string_ptr)--; + break; + } + overflow |= i ^ (i << 4 >> 4); + i = (i << 4) + digit; + digits_found = 1; + } + if (!digits_found) + cpp_error (pfile, "\\x used with no following hex digits"); + if (overflow | (i & ~((1 << BITS_PER_UNIT) - 1))) + { + i &= (1 << BITS_PER_UNIT) - 1; + cpp_warning (pfile, + "hex character constant does not fit in a byte"); + } + return i; + } + default: + return c; + } +} + +static void +integer_overflow (pfile) + cpp_reader *pfile; +{ + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "integer overflow in preprocessor expression"); +} + +static long +left_shift (pfile, a, unsignedp, b) + cpp_reader *pfile; + long a; + int unsignedp; + unsigned long b; +{ + if (b >= HOST_BITS_PER_LONG) + { + if (! unsignedp && a != 0) + integer_overflow (pfile); + return 0; + } + else if (unsignedp) + return (unsigned long) a << b; + else + { + long l = a << b; + if (l >> b != a) + integer_overflow (pfile); + return l; + } +} + +static long +right_shift (pfile, a, unsignedp, b) + cpp_reader *pfile; + long a; + int unsignedp; + unsigned long b; +{ + if (b >= HOST_BITS_PER_LONG) + return unsignedp ? 0 : a >> (HOST_BITS_PER_LONG - 1); + else if (unsignedp) + return (unsigned long) a >> b; + else + return a >> b; +} + +/* These priorities are all even, so we can handle associatively. */ +#define PAREN_INNER_PRIO 0 +#define COMMA_PRIO 4 +#define COND_PRIO (COMMA_PRIO+2) +#define OROR_PRIO (COND_PRIO+2) +#define ANDAND_PRIO (OROR_PRIO+2) +#define OR_PRIO (ANDAND_PRIO+2) +#define XOR_PRIO (OR_PRIO+2) +#define AND_PRIO (XOR_PRIO+2) +#define EQUAL_PRIO (AND_PRIO+2) +#define LESS_PRIO (EQUAL_PRIO+2) +#define SHIFT_PRIO (LESS_PRIO+2) +#define PLUS_PRIO (SHIFT_PRIO+2) +#define MUL_PRIO (PLUS_PRIO+2) +#define UNARY_PRIO (MUL_PRIO+2) +#define PAREN_OUTER_PRIO (UNARY_PRIO+2) + +#define COMPARE(OP) \ + top->unsignedp = 0;\ + top->value = (unsigned1 || unsigned2) ? (unsigned long) v1 OP v2 : (v1 OP v2) + +/* Parse and evaluate a C expression, reading from PFILE. + Returns the value of the expression. */ + +HOST_WIDE_INT +cpp_parse_expr (pfile) + cpp_reader *pfile; +{ + /* The implementation is an operator precedence parser, + i.e. a bottom-up parser, using a stack for not-yet-reduced tokens. + + The stack base is 'stack', and the current stack pointer is 'top'. + There is a stack element for each operator (only), + and the most recently pushed operator is 'top->op'. + An operand (value) is stored in the 'value' field of the stack + element of the operator that precedes it. + In that case the 'flags' field has the HAVE_VALUE flag set. */ + +#define INIT_STACK_SIZE 20 + struct operation init_stack[INIT_STACK_SIZE]; + struct operation *stack = init_stack; + struct operation *limit = stack + INIT_STACK_SIZE; + register struct operation *top = stack; + int lprio, rprio; + + top->rprio = 0; + top->flags = 0; + for (;;) + { + struct operation op; + char flags = 0; + + /* Read a token */ + op = cpp_lex (pfile); + + /* See if the token is an operand, in which case go to set_value. + If the token is an operator, figure out its left and right + priorities, and then goto maybe_reduce. */ + + switch (op.op) + { + case NAME: + top->value = 0, top->unsignedp = 0; + goto set_value; + case INT: case CHAR: + top->value = op.value; + top->unsignedp = op.unsignedp; + goto set_value; + case 0: + lprio = 0; goto maybe_reduce; + case '+': case '-': + /* Is this correct if unary ? FIXME */ + flags = RIGHT_OPERAND_REQUIRED; + lprio = PLUS_PRIO; rprio = lprio + 1; goto maybe_reduce; + case '!': case '~': + flags = RIGHT_OPERAND_REQUIRED; + rprio = UNARY_PRIO; lprio = rprio + 1; goto maybe_reduce; + case '*': case '/': case '%': + lprio = MUL_PRIO; goto binop; + case '<': case '>': case LEQ: case GEQ: + lprio = LESS_PRIO; goto binop; + case EQUAL: case NOTEQUAL: + lprio = EQUAL_PRIO; goto binop; + case LSH: case RSH: + lprio = SHIFT_PRIO; goto binop; + case '&': lprio = AND_PRIO; goto binop; + case '^': lprio = XOR_PRIO; goto binop; + case '|': lprio = OR_PRIO; goto binop; + case ANDAND: lprio = ANDAND_PRIO; goto binop; + case OROR: lprio = OROR_PRIO; goto binop; + case ',': + lprio = COMMA_PRIO; goto binop; + case '(': + lprio = PAREN_OUTER_PRIO; rprio = PAREN_INNER_PRIO; + goto maybe_reduce; + case ')': + lprio = PAREN_INNER_PRIO; rprio = PAREN_OUTER_PRIO; + goto maybe_reduce; + case ':': + lprio = COND_PRIO; rprio = COND_PRIO; + goto maybe_reduce; + case '?': + lprio = COND_PRIO + 1; rprio = COND_PRIO; + goto maybe_reduce; + binop: + flags = LEFT_OPERAND_REQUIRED|RIGHT_OPERAND_REQUIRED; + rprio = lprio + 1; + goto maybe_reduce; + default: + cpp_error (pfile, "invalid character in #if"); + goto syntax_error; + } + + set_value: + /* Push a value onto the stack. */ + if (top->flags & HAVE_VALUE) + { + cpp_error (pfile, "syntax error in #if"); + goto syntax_error; + } + top->flags |= HAVE_VALUE; + continue; + + maybe_reduce: + /* Push an operator, and check if we can reduce now. */ + while (top->rprio > lprio) + { + long v1 = top[-1].value, v2 = top[0].value; + int unsigned1 = top[-1].unsignedp, unsigned2 = top[0].unsignedp; + top--; + if ((top[1].flags & LEFT_OPERAND_REQUIRED) + && ! (top[0].flags & HAVE_VALUE)) + { + cpp_error (pfile, "syntax error - missing left operand"); + goto syntax_error; + } + if ((top[1].flags & RIGHT_OPERAND_REQUIRED) + && ! (top[1].flags & HAVE_VALUE)) + { + cpp_error (pfile, "syntax error - missing right operand"); + goto syntax_error; + } + /* top[0].value = (top[1].op)(v1, v2);*/ + switch (top[1].op) + { + case '+': + if (!(top->flags & HAVE_VALUE)) + { /* Unary '+' */ + top->value = v2; + top->unsignedp = unsigned2; + top->flags |= HAVE_VALUE; + } + else + { + top->value = v1 + v2; + top->unsignedp = unsigned1 || unsigned2; + if (! top->unsignedp + && ! possible_sum_sign (v1, v2, top->value)) + integer_overflow (pfile); + } + break; + case '-': + if (!(top->flags & HAVE_VALUE)) + { /* Unary '-' */ + top->value = - v2; + if ((top->value & v2) < 0 && ! unsigned2) + integer_overflow (pfile); + top->unsignedp = unsigned2; + top->flags |= HAVE_VALUE; + } + else + { /* Binary '-' */ + top->value = v1 - v2; + top->unsignedp = unsigned1 || unsigned2; + if (! top->unsignedp + && ! possible_sum_sign (top->value, v2, v1)) + integer_overflow (pfile); + } + break; + case '*': + top->unsignedp = unsigned1 || unsigned2; + if (top->unsignedp) + top->value = (unsigned long) v1 * v2; + else + { + top->value = v1 * v2; + if (v1 + && (top->value / v1 != v2 + || (top->value & v1 & v2) < 0)) + integer_overflow (pfile); + } + break; + case '/': + if (v2 == 0) + { + cpp_error (pfile, "division by zero in #if"); + v2 = 1; + } + top->unsignedp = unsigned1 || unsigned2; + if (top->unsignedp) + top->value = (unsigned long) v1 / v2; + else + { + top->value = v1 / v2; + if ((top->value & v1 & v2) < 0) + integer_overflow (pfile); + } + break; + case '%': + if (v2 == 0) + { + cpp_error (pfile, "division by zero in #if"); + v2 = 1; + } + top->unsignedp = unsigned1 || unsigned2; + if (top->unsignedp) + top->value = (unsigned long) v1 % v2; + else + top->value = v1 % v2; + break; + case '!': + if (top->flags & HAVE_VALUE) + { + cpp_error (pfile, "syntax error"); + goto syntax_error; + } + top->value = ! v2; + top->unsignedp = 0; + top->flags |= HAVE_VALUE; + break; + case '~': + if (top->flags & HAVE_VALUE) + { + cpp_error (pfile, "syntax error"); + goto syntax_error; + } + top->value = ~ v2; + top->unsignedp = unsigned2; + top->flags |= HAVE_VALUE; + break; + case '<': COMPARE(<); break; + case '>': COMPARE(>); break; + case LEQ: COMPARE(<=); break; + case GEQ: COMPARE(>=); break; + case EQUAL: + top->value = (v1 == v2); + top->unsignedp = 0; + break; + case NOTEQUAL: + top->value = (v1 != v2); + top->unsignedp = 0; + break; + case LSH: + top->unsignedp = unsigned1; + if (v2 < 0 && ! unsigned2) + top->value = right_shift (pfile, v1, unsigned1, -v2); + else + top->value = left_shift (pfile, v1, unsigned1, v2); + break; + case RSH: + top->unsignedp = unsigned1; + if (v2 < 0 && ! unsigned2) + top->value = left_shift (pfile, v1, unsigned1, -v2); + else + top->value = right_shift (pfile, v1, unsigned1, v2); + break; +#define LOGICAL(OP) \ + top->value = v1 OP v2;\ + top->unsignedp = unsigned1 || unsigned2; + case '&': LOGICAL(&); break; + case '^': LOGICAL(^); break; + case '|': LOGICAL(|); break; + case ANDAND: + top->value = v1 && v2; top->unsignedp = 0; break; + case OROR: + top->value = v1 || v2; top->unsignedp = 0; break; + case ',': + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "comma operator in operand of `#if'"); + top->value = v2; + top->unsignedp = unsigned2; + break; + case '(': case '?': + cpp_error (pfile, "syntax error in #if"); + goto syntax_error; + case ':': + if (top[0].op != '?') + { + cpp_error (pfile, + "syntax error ':' without preceding '?'"); + goto syntax_error; + } + else if (! (top[1].flags & HAVE_VALUE) + || !(top[-1].flags & HAVE_VALUE) + || !(top[0].flags & HAVE_VALUE)) + { + cpp_error (pfile, "bad syntax for ?: operator"); + goto syntax_error; + } + else + { + top--; + top->value = top->value ? v1 : v2; + top->unsignedp = unsigned1 || unsigned2; + } + break; + case ')': + if ((top[1].flags & HAVE_VALUE) + || ! (top[0].flags & HAVE_VALUE) + || top[0].op != '(' + || (top[-1].flags & HAVE_VALUE)) + { + cpp_error (pfile, "mismatched parentheses in #if"); + goto syntax_error; + } + else + { + top--; + top->value = v1; + top->unsignedp = unsigned1; + top->flags |= HAVE_VALUE; + } + break; + default: + fprintf (stderr, + top[1].op >= ' ' && top[1].op <= '~' + ? "unimplemented operator '%c'\n" + : "unimplemented operator '\\%03o'\n", + top[1].op); + } + } + if (op.op == 0) + { + if (top != stack) + cpp_error (pfile, "internal error in #if expression"); + if (stack != init_stack) + free (stack); + return top->value; + } + top++; + + /* Check for and handle stack overflow. */ + if (top == limit) + { + struct operation *new_stack; + int old_size = (char*)limit - (char*)stack; + int new_size = 2 * old_size; + if (stack != init_stack) + new_stack = (struct operation*) xrealloc (stack, new_size); + else + { + new_stack = (struct operation*) xmalloc (new_size); + bcopy ((char *) stack, (char *) new_stack, old_size); + } + stack = new_stack; + top = (struct operation*)((char*) new_stack + old_size); + limit = (struct operation*)((char*) new_stack + new_size); + } + + top->flags = flags; + top->rprio = rprio; + top->op = op.op; + } + syntax_error: + if (stack != init_stack) + free (stack); + skip_rest_of_line (pfile); + return 0; +} diff --git a/contrib/gcc/cpphash.c b/contrib/gcc/cpphash.c new file mode 100644 index 00000000000..bd06e95387f --- /dev/null +++ b/contrib/gcc/cpphash.c @@ -0,0 +1,214 @@ +/* Part of CPP library. (Macro hash table support.) + Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994. + Based on CCCP program by by Paul Rubin, June 1986 + Adapted to ANSI C, Richard Stallman, Jan 1987 + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#include "cpplib.h" +#include "cpphash.h" + +extern char *xmalloc PARAMS ((unsigned)); + +/* Define a generic NULL if one hasn't already been defined. */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef __STDC__ +#define const +#define volatile +#endif + +/* + * return hash function on name. must be compatible with the one + * computed a step at a time, elsewhere + */ +int +hashf (name, len, hashsize) + register const U_CHAR *name; + register int len; + int hashsize; +{ + register int r = 0; + + while (len--) + r = HASHSTEP (r, *name++); + + return MAKE_POS (r) % hashsize; +} + +/* + * find the most recent hash node for name name (ending with first + * non-identifier char) installed by install + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +HASHNODE * +cpp_lookup (pfile, name, len, hash) + struct parse_file *pfile; + const U_CHAR *name; + int len; + int hash; +{ + register const U_CHAR *bp; + register HASHNODE *bucket; + + if (len < 0) + { + for (bp = name; is_idchar[*bp]; bp++) ; + len = bp - name; + } + + if (hash < 0) + hash = hashf (name, len, HASHSIZE); + + bucket = hashtab[hash]; + while (bucket) { + if (bucket->length == len && strncmp (bucket->name, name, len) == 0) + return bucket; + bucket = bucket->next; + } + return (HASHNODE*) 0; +} + +/* + * Delete a hash node. Some weirdness to free junk from macros. + * More such weirdness will have to be added if you define more hash + * types that need it. + */ + +/* Note that the DEFINITION of a macro is removed from the hash table + but its storage is not freed. This would be a storage leak + except that it is not reasonable to keep undefining and redefining + large numbers of macros many times. + In any case, this is necessary, because a macro can be #undef'd + in the middle of reading the arguments to a call to it. + If #undef freed the DEFINITION, that would crash. */ + +void +delete_macro (hp) + HASHNODE *hp; +{ + + if (hp->prev != NULL) + hp->prev->next = hp->next; + if (hp->next != NULL) + hp->next->prev = hp->prev; + + /* make sure that the bucket chain header that + the deleted guy was on points to the right thing afterwards. */ + if (hp == *hp->bucket_hdr) + *hp->bucket_hdr = hp->next; + + if (hp->type == T_MACRO) + { + DEFINITION *d = hp->value.defn; + struct reflist *ap, *nextap; + + for (ap = d->pattern; ap != NULL; ap = nextap) + { + nextap = ap->next; + free (ap); + } + if (d->nargs >= 0) + free (d->args.argnames); + free (d); + } + + free (hp); +} +/* + * install a name in the main hash table, even if it is already there. + * name stops with first non alphanumeric, except leading '#'. + * caller must check against redefinition if that is desired. + * delete_macro () removes things installed by install () in fifo order. + * this is important because of the `defined' special symbol used + * in #if, and also if pushdef/popdef directives are ever implemented. + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +HASHNODE * +install (name, len, type, ivalue, value, hash) + U_CHAR *name; + int len; + enum node_type type; + int ivalue; + char *value; + int hash; +{ + register HASHNODE *hp; + register int i, bucket; + register U_CHAR *p, *q; + + if (len < 0) { + p = name; + while (is_idchar[*p]) + p++; + len = p - name; + } + + if (hash < 0) + hash = hashf (name, len, HASHSIZE); + + i = sizeof (HASHNODE) + len + 1; + hp = (HASHNODE *) xmalloc (i); + bucket = hash; + hp->bucket_hdr = &hashtab[bucket]; + hp->next = hashtab[bucket]; + hashtab[bucket] = hp; + hp->prev = NULL; + if (hp->next != NULL) + hp->next->prev = hp; + hp->type = type; + hp->length = len; + if (hp->type == T_CONST) + hp->value.ival = ivalue; + else + hp->value.cpval = value; + hp->name = ((U_CHAR *) hp) + sizeof (HASHNODE); + p = hp->name; + q = name; + for (i = 0; i < len; i++) + *p++ = *q++; + hp->name[len] = 0; + return hp; +} + +void +cpp_hash_cleanup (pfile) + cpp_reader *pfile; +{ + register int i; + for (i = HASHSIZE; --i >= 0; ) + { + while (hashtab[i]) + delete_macro (hashtab[i]); + } +} diff --git a/contrib/gcc/cpphash.h b/contrib/gcc/cpphash.h new file mode 100644 index 00000000000..914a12f5b01 --- /dev/null +++ b/contrib/gcc/cpphash.h @@ -0,0 +1,38 @@ +/* different kinds of things that can appear in the value field + of a hash node. Actually, this may be useless now. */ +union hashval { + int ival; + char *cpval; + DEFINITION *defn; +#if 0 + KEYDEF *keydef; +#endif +}; + +struct hashnode { + struct hashnode *next; /* double links for easy deletion */ + struct hashnode *prev; + struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash + chain is kept, in case the node is the head + of the chain and gets deleted. */ + enum node_type type; /* type of special token */ + int length; /* length of token, for quick comparison */ + U_CHAR *name; /* the actual name */ + union hashval value; /* pointer to expansion, or whatever */ +}; + +typedef struct hashnode HASHNODE; + +/* Some definitions for the hash table. The hash function MUST be + computed as shown in hashf () below. That is because the rescan + loop computes the hash value `on the fly' for most tokens, + in order to avoid the overhead of a lot of procedure calls to + the hashf () function. Hashf () only exists for the sake of + politeness, for use when speed isn't so important. */ + +#define HASHSIZE 1403 +static HASHNODE *hashtab[HASHSIZE]; +#define HASHSTEP(old, c) ((old << 2) + c) +#define MAKE_POS(v) (v & 0x7fffffff) /* make number positive */ + +extern HASHNODE* install PARAMS ((U_CHAR*,int,enum node_type, int,char*,int)); diff --git a/contrib/gcc/cpplib.c b/contrib/gcc/cpplib.c new file mode 100644 index 00000000000..8e91a099d81 --- /dev/null +++ b/contrib/gcc/cpplib.c @@ -0,0 +1,7527 @@ +/* CPP Library. + Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994-95. + Based on CCCP program by by Paul Rubin, June 1986 + Adapted to ANSI C, Richard Stallman, Jan 1987 + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#ifdef EMACS +#define NO_SHORTNAMES +#include "../src/config.h" +#ifdef open +#undef open +#undef read +#undef write +#endif /* open */ +#endif /* EMACS */ + +/* The macro EMACS is defined when cpp is distributed as part of Emacs, + for the sake of machines with limited C compilers. */ +#ifndef EMACS +#include "config.h" +#endif /* not EMACS */ + +#ifndef STANDARD_INCLUDE_DIR +#define STANDARD_INCLUDE_DIR "/usr/include" +#endif + +#ifndef LOCAL_INCLUDE_DIR +#define LOCAL_INCLUDE_DIR "/usr/local/include" +#endif + +#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */ +#ifdef __STDC__ +#define PTR_INT_TYPE ptrdiff_t +#else +#define PTR_INT_TYPE long +#endif +#endif /* 0 */ + +#include "cpplib.h" +#include "cpphash.h" + +#ifndef STDC_VALUE +#define STDC_VALUE 1 +#endif + +/* By default, colon separates directories in a path. */ +#ifndef PATH_SEPARATOR +#define PATH_SEPARATOR ':' +#endif + +#include +#include +#include +#ifdef __STDC__ +#include +#endif + +#ifndef VMS +#ifndef USG +#include /* for __DATE__ and __TIME__ */ +#include +#else +#include /* CYGNUS LOCAL: shebs -noquiet */ +#include +#include +#include +#endif /* USG */ +#endif /* not VMS */ + +/* This defines "errno" properly for VMS, and gives us EACCES. */ +#include + +extern char *index (); +extern char *rindex (); + +#ifndef O_RDONLY +#define O_RDONLY 0 +#endif + +#undef MIN +#undef MAX +#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) +#define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) + +/* Find the largest host integer type and set its size and type. */ + +#ifndef HOST_BITS_PER_WIDE_INT + +#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG +#define HOST_WIDE_INT long +#else +#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT +#define HOST_WIDE_INT int +#endif + +#endif + +#ifndef S_ISREG +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif + +#ifndef S_ISDIR +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + +/* Define a generic NULL if one hasn't already been defined. */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef GENERIC_PTR +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define GENERIC_PTR void * +#else +#define GENERIC_PTR char * +#endif +#endif + +#ifndef NULL_PTR +#define NULL_PTR ((GENERIC_PTR)0) +#endif + +#ifndef INCLUDE_LEN_FUDGE +#define INCLUDE_LEN_FUDGE 0 +#endif + +/* Symbols to predefine. */ + +#ifdef CPP_PREDEFINES +static char *predefs = CPP_PREDEFINES; +#else +static char *predefs = ""; +#endif + +/* We let tm.h override the types used here, to handle trivial differences + such as the choice of unsigned int or long unsigned int for size_t. + When machines start needing nontrivial differences in the size type, + it would be best to do something here to figure out automatically + from other information what type to use. */ + +/* The string value for __SIZE_TYPE__. */ + +#ifndef SIZE_TYPE +#define SIZE_TYPE "long unsigned int" +#endif + +/* The string value for __PTRDIFF_TYPE__. */ + +#ifndef PTRDIFF_TYPE +#define PTRDIFF_TYPE "long int" +#endif + +/* The string value for __WCHAR_TYPE__. */ + +#ifndef WCHAR_TYPE +#define WCHAR_TYPE "int" +#endif +#define CPP_WCHAR_TYPE(PFILE) \ + (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE) + +/* The string value for __USER_LABEL_PREFIX__ */ + +#ifndef USER_LABEL_PREFIX +#define USER_LABEL_PREFIX "" +#endif + +/* The string value for __REGISTER_PREFIX__ */ + +#ifndef REGISTER_PREFIX +#define REGISTER_PREFIX "" +#endif + +/* In the definition of a #assert name, this structure forms + a list of the individual values asserted. + Each value is itself a list of "tokens". + These are strings that are compared by name. */ + +struct tokenlist_list { + struct tokenlist_list *next; + struct arglist *tokens; +}; + +struct assertion_hashnode { + struct assertion_hashnode *next; /* double links for easy deletion */ + struct assertion_hashnode *prev; + /* also, a back pointer to this node's hash + chain is kept, in case the node is the head + of the chain and gets deleted. */ + struct assertion_hashnode **bucket_hdr; + int length; /* length of token, for quick comparison */ + U_CHAR *name; /* the actual name */ + /* List of token-sequences. */ + struct tokenlist_list *value; +}; + +#define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0) +#define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0) + +#define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF) +#define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N)) +#define GETC() CPP_BUF_GET (CPP_BUFFER (pfile)) +#define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile)) +/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion. + (Note that it is false while we're expanding marco *arguments*.) */ +#define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup) + +/* Move all backslash-newline pairs out of embarrassing places. + Exchange all such pairs following BP + with any potentially-embarrassing characters that follow them. + Potentially-embarrassing characters are / and * + (because a backslash-newline inside a comment delimiter + would cause it not to be recognized). */ + +#define NEWLINE_FIX \ + do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0) + +/* Same, but assume we've already read the potential '\\' into C. */ +#define NEWLINE_FIX1(C) do { \ + while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\ + } while(0) + +struct cpp_pending { + struct cpp_pending *next; + char *cmd; + char *arg; +}; + +/* Forward declarations. */ + +extern char *xmalloc (); + +static void add_import (); +static void append_include_chain (); +static void make_undef (); +static void make_assertion (); +static void path_include (); +static void initialize_builtins (); +static void initialize_char_syntax (); +static void dump_arg_n (); +static void dump_defn_1 (); +extern void delete_macro (); +static void trigraph_pcp (); +static int finclude (); +static void validate_else (); +static int comp_def_part (); +extern void fancy_abort (); +static void pipe_closed (); +static void print_containing_files (); +static int lookup_import (); +static int redundant_include_p (); +static is_system_include (); +static struct file_name_map *read_name_map (); +static char *read_filename_string (); +static int open_include_file (); +static int check_preconditions (); +static void pcfinclude (); +static void pcstring_used (); +static int check_macro_name (); +static int compare_defs (); +static int compare_token_lists (); +static HOST_WIDE_INT eval_if_expression (); +static int change_newlines (); +extern int hashf (); +static int file_size_and_mode (); +static struct arglist *read_token_list (); +static void free_token_list (); +static int safe_read (); +static void push_macro_expansion PARAMS ((cpp_reader *, + U_CHAR*, int, HASHNODE*)); +static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending*)); +extern char *xrealloc (); +extern char *xcalloc (); +static char *savestring (); + +static void conditional_skip (); +static void skip_if_group (); + +/* Last arg to output_line_command. */ +enum file_change_code {same_file, enter_file, leave_file}; + +/* External declarations. */ + +extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader*)); + +extern char *getenv (); +extern FILE *fdopen (); +extern char *version_string; +extern struct tm *localtime (); + +/* These functions are declared to return int instead of void since they + are going to be placed in a table and some old compilers have trouble with + pointers to functions returning void. */ + +static int do_define (); +static int do_line (); +static int do_include (); +static int do_undef (); +static int do_error (); +static int do_pragma (); +static int do_ident (); +static int do_if (); +static int do_xifdef (); +static int do_else (); +static int do_elif (); +static int do_endif (); +static int do_sccs (); +static int do_once (); +static int do_assert (); +static int do_unassert (); +static int do_warning (); + +struct file_name_list + { + struct file_name_list *next; + char *fname; + /* If the following is nonzero, it is a macro name. + Don't include the file again if that macro is defined. */ + U_CHAR *control_macro; + /* If the following is nonzero, it is a C-language system include + directory. */ + int c_system_include_path; + /* Mapping of file names for this directory. */ + struct file_name_map *name_map; + /* Non-zero if name_map is valid. */ + int got_name_map; + }; + +/* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found + via the same directory as the file that #included it. */ +#define SELF_DIR_DUMMY ((struct file_name_list*)(~0)) + +/* #include "file" looks in source file dir, then stack. */ +/* #include just looks in the stack. */ +/* -I directories are added to the end, then the defaults are added. */ +/* The */ +static struct default_include { + char *fname; /* The name of the directory. */ + int cplusplus; /* Only look here if we're compiling C++. */ + int cxx_aware; /* Includes in this directory don't need to + be wrapped in extern "C" when compiling + C++. */ +} include_defaults_array[] +#ifdef INCLUDE_DEFAULTS + = INCLUDE_DEFAULTS; +#else + = { + /* Pick up GNU C++ specific include files. */ + { GPLUSPLUS_INCLUDE_DIR, 1, 1 }, +#ifdef CROSS_COMPILE + /* This is the dir for fixincludes. Put it just before + the files that we fix. */ + { GCC_INCLUDE_DIR, 0, 0 }, + /* For cross-compilation, this dir name is generated + automatically in Makefile.in. */ + { CROSS_INCLUDE_DIR, 0, 0 }, + /* This is another place that the target system's headers might be. */ + { TOOL_INCLUDE_DIR, 0, 1 }, +#else /* not CROSS_COMPILE */ + /* This should be /usr/local/include and should come before + the fixincludes-fixed header files. */ + { LOCAL_INCLUDE_DIR, 0, 1 }, + /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here. + Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */ + { TOOL_INCLUDE_DIR, 0, 1 }, + /* This is the dir for fixincludes. Put it just before + the files that we fix. */ + { GCC_INCLUDE_DIR, 0, 0 }, + /* Some systems have an extra dir of include files. */ +#ifdef SYSTEM_INCLUDE_DIR + { SYSTEM_INCLUDE_DIR, 0, 0 }, +#endif + { STANDARD_INCLUDE_DIR, 0, 0 }, +#endif /* not CROSS_COMPILE */ + { 0, 0, 0 } + }; +#endif /* no INCLUDE_DEFAULTS */ + +/* `struct directive' defines one #-directive, including how to handle it. */ + +struct directive { + int length; /* Length of name */ + int (*func)(); /* Function to handle directive */ + char *name; /* Name of directive */ + enum node_type type; /* Code which describes which directive. */ + char command_reads_line; /* One if rest of line is read by func. */ + char traditional_comments; /* Nonzero: keep comments if -traditional. */ + char pass_thru; /* Copy preprocessed directive to output file.*/ +}; + +/* Here is the actual list of #-directives, most-often-used first. + The initialize_builtins function assumes #define is the very first. */ + +static struct directive directive_table[] = { + { 6, do_define, "define", T_DEFINE, 0, 1}, + { 5, do_xifdef, "ifdef", T_IFDEF, 1}, + { 6, do_xifdef, "ifndef", T_IFNDEF, 1}, + { 7, do_include, "include", T_INCLUDE, 1}, + { 12, do_include, "include_next", T_INCLUDE_NEXT, 1}, + { 6, do_include, "import", T_IMPORT, 1}, + { 5, do_endif, "endif", T_ENDIF, 1}, + { 4, do_else, "else", T_ELSE, 1}, + { 2, do_if, "if", T_IF, 1}, + { 4, do_elif, "elif", T_ELIF, 1}, + { 5, do_undef, "undef", T_UNDEF}, + { 5, do_error, "error", T_ERROR}, + { 7, do_warning, "warning", T_WARNING}, + { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1}, + { 4, do_line, "line", T_LINE, 1}, + { 5, do_ident, "ident", T_IDENT, 1, 0, 1}, +#ifdef SCCS_DIRECTIVE + { 4, do_sccs, "sccs", T_SCCS}, +#endif + { 6, do_assert, "assert", T_ASSERT, 1}, + { 8, do_unassert, "unassert", T_UNASSERT, 1}, + { -1, 0, "", T_UNUSED}, +}; + +/* table to tell if char can be part of a C identifier. */ +U_CHAR is_idchar[256]; +/* table to tell if char can be first char of a c identifier. */ +U_CHAR is_idstart[256]; +/* table to tell if c is horizontal space. */ +U_CHAR is_hor_space[256]; +/* table to tell if c is horizontal or vertical space. */ +static U_CHAR is_space[256]; + +/* Initialize syntactic classifications of characters. */ + +static void +initialize_char_syntax (opts) + struct cpp_options *opts; +{ + register int i; + + /* + * Set up is_idchar and is_idstart tables. These should be + * faster than saying (is_alpha (c) || c == '_'), etc. + * Set up these things before calling any routines tthat + * refer to them. + */ + for (i = 'a'; i <= 'z'; i++) { + is_idchar[i - 'a' + 'A'] = 1; + is_idchar[i] = 1; + is_idstart[i - 'a' + 'A'] = 1; + is_idstart[i] = 1; + } + for (i = '0'; i <= '9'; i++) + is_idchar[i] = 1; + is_idchar['_'] = 1; + is_idstart['_'] = 1; + is_idchar['$'] = opts->dollars_in_ident; + is_idstart['$'] = opts->dollars_in_ident; + + /* horizontal space table */ + is_hor_space[' '] = 1; + is_hor_space['\t'] = 1; + is_hor_space['\v'] = 1; + is_hor_space['\f'] = 1; + is_hor_space['\r'] = 1; + + is_space[' '] = 1; + is_space['\t'] = 1; + is_space['\v'] = 1; + is_space['\f'] = 1; + is_space['\n'] = 1; + is_space['\r'] = 1; +} + + +/* Place into PFILE a quoted string representing the string SRC. + Caller must reserve enough space in pfile->token_buffer. */ +static void +quote_string (pfile, src) + cpp_reader *pfile; + char *src; +{ + U_CHAR c; + + CPP_PUTC_Q (pfile, '\"'); + for (;;) + switch ((c = *src++)) + { + default: + if (isprint (c)) + CPP_PUTC_Q (pfile, c); + else + { + sprintf (CPP_PWRITTEN (pfile), "\\%03o", c); + CPP_ADJUST_WRITTEN (pfile, 4); + } + break; + + case '\"': + case '\\': + CPP_PUTC_Q (pfile, '\\'); + CPP_PUTC_Q (pfile, c); + break; + + case '\0': + CPP_PUTC_Q (pfile, '\"'); + CPP_NUL_TERMINATE_Q (pfile); + return; + } +} + +/* Make sure PFILE->token_buffer will hold at least N more chars. */ + +void +cpp_grow_buffer (pfile, n) + cpp_reader *pfile; + long n; +{ + long old_written = CPP_WRITTEN (pfile); + pfile->token_buffer_size = n + 2 * pfile->token_buffer_size; + pfile->token_buffer = (U_CHAR*) + xrealloc(pfile->token_buffer, pfile->token_buffer_size); + CPP_SET_WRITTEN (pfile, old_written); +} + + +/* + * process a given definition string, for initialization + * If STR is just an identifier, define it with value 1. + * If STR has anything after the identifier, then it should + * be identifier=definition. + */ + +void +cpp_define (pfile, str) + cpp_reader *pfile; + U_CHAR *str; +{ + U_CHAR *buf, *p; + + buf = str; + p = str; + if (!is_idstart[*p]) + { + cpp_error (pfile, "malformed option `-D %s'", str); + return; + } + while (is_idchar[*++p]) + ; + if (*p == 0) + { + buf = (U_CHAR *) alloca (p - buf + 4); + strcpy ((char *)buf, str); + strcat ((char *)buf, " 1"); + } + else if (*p != '=') + { + cpp_error (pfile, "malformed option `-D %s'", str); + return; + } + else + { + U_CHAR *q; + /* Copy the entire option so we can modify it. */ + buf = (U_CHAR *) alloca (2 * strlen (str) + 1); + strncpy (buf, str, p - str); + /* Change the = to a space. */ + buf[p - str] = ' '; + /* Scan for any backslash-newline and remove it. */ + p++; + q = &buf[p - str]; + while (*p) + { + if (*p == '\\' && p[1] == '\n') + p += 2; + else + *q++ = *p++; + } + *q = 0; + } + + do_define (pfile, NULL, buf, buf + strlen (buf)); +} + +/* Process the string STR as if it appeared as the body of a #assert. + OPTION is the option name for which STR was the argument. */ + +static void +make_assertion (pfile, option, str) + cpp_reader *pfile; + char *option; + U_CHAR *str; +{ + cpp_buffer *ip; + struct directive *kt; + U_CHAR *buf, *p, *q; + + /* Copy the entire option so we can modify it. */ + buf = (U_CHAR *) alloca (strlen (str) + 1); + strcpy ((char *) buf, str); + /* Scan for any backslash-newline and remove it. */ + p = q = buf; + while (*p) { +#if 0 + if (*p == '\\' && p[1] == '\n') + p += 2; + else +#endif + *q++ = *p++; + } + *q = 0; + + p = buf; + if (!is_idstart[*p]) { + cpp_error (pfile, "malformed option `%s %s'", option, str); + return; + } + while (is_idchar[*++p]) + ; + while (*p == ' ' || *p == '\t') p++; + if (! (*p == 0 || *p == '(')) { + cpp_error (pfile, "malformed option `%s %s'", option, str); + return; + } + + ip = cpp_push_buffer (pfile, buf, strlen (buf)); + do_assert (pfile, NULL, NULL, NULL); + cpp_pop_buffer (pfile); +} + +/* Append a chain of `struct file_name_list's + to the end of the main include chain. + FIRST is the beginning of the chain to append, and LAST is the end. */ + +static void +append_include_chain (pfile, first, last) + cpp_reader *pfile; + struct file_name_list *first, *last; +{ + struct cpp_options *opts = CPP_OPTIONS (pfile); + struct file_name_list *dir; + + if (!first || !last) + return; + + if (opts->include == 0) + opts->include = first; + else + opts->last_include->next = first; + + if (opts->first_bracket_include == 0) + opts->first_bracket_include = first; + + for (dir = first; ; dir = dir->next) { + int len = strlen (dir->fname) + INCLUDE_LEN_FUDGE; + if (len > pfile->max_include_len) + pfile->max_include_len = len; + if (dir == last) + break; + } + + last->next = NULL; + opts->last_include = last; +} + +/* Add output to `deps_buffer' for the -M switch. + STRING points to the text to be output. + SPACER is ':' for targets, ' ' for dependencies, zero for text + to be inserted literally. */ + +static void +deps_output (pfile, string, spacer) + cpp_reader *pfile; + char *string; + int spacer; +{ + int size = strlen (string); + + if (size == 0) + return; + +#ifndef MAX_OUTPUT_COLUMNS +#define MAX_OUTPUT_COLUMNS 72 +#endif + if (spacer + && pfile->deps_column > 0 + && (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS) + { + deps_output (pfile, " \\\n ", 0); + pfile->deps_column = 0; + } + + if (pfile->deps_size + size + 8 > pfile->deps_allocated_size) + { + pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2; + pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer, + pfile->deps_allocated_size); + } + if (spacer == ' ' && pfile->deps_column > 0) + pfile->deps_buffer[pfile->deps_size++] = ' '; + bcopy (string, &pfile->deps_buffer[pfile->deps_size], size); + pfile->deps_size += size; + pfile->deps_column += size; + if (spacer == ':') + pfile->deps_buffer[pfile->deps_size++] = ':'; + pfile->deps_buffer[pfile->deps_size] = 0; +} + +/* Given a colon-separated list of file names PATH, + add all the names to the search path for include files. */ + +static void +path_include (pfile, path) + cpp_reader *pfile; + char *path; +{ + char *p; + + p = path; + + if (*p) + while (1) { + char *q = p; + char *name; + struct file_name_list *dirtmp; + + /* Find the end of this name. */ + while (*q != 0 && *q != PATH_SEPARATOR) q++; + if (p == q) { + /* An empty name in the path stands for the current directory. */ + name = (char *) xmalloc (2); + name[0] = '.'; + name[1] = 0; + } else { + /* Otherwise use the directory that is named. */ + name = (char *) xmalloc (q - p + 1); + bcopy (p, name, q - p); + name[q - p] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + dirtmp->fname = name; + dirtmp->got_name_map = 0; + append_include_chain (pfile, dirtmp, dirtmp); + + /* Advance past this name. */ + p = q; + if (*p == 0) + break; + /* Skip the colon. */ + p++; + } +} + +void +init_parse_options (opts) + struct cpp_options *opts; +{ + bzero ((char *) opts, sizeof *opts); + opts->in_fname = NULL; + opts->out_fname = NULL; + + /* Initialize is_idchar to allow $. */ + opts->dollars_in_ident = 1; + initialize_char_syntax (opts); + opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0; + + opts->no_line_commands = 0; + opts->no_trigraphs = 1; + opts->put_out_comments = 0; + opts->print_include_names = 0; + opts->dump_macros = dump_none; + opts->no_output = 0; + opts->cplusplus = 0; + opts->cplusplus_comments = 0; + + opts->verbose = 0; + opts->objc = 0; + opts->lang_asm = 0; + opts->for_lint = 0; + opts->chill = 0; + opts->pedantic_errors = 0; + opts->inhibit_warnings = 0; + opts->warn_comments = 0; + opts->warn_import = 1; + opts->warnings_are_errors = 0; +} + +enum cpp_token +null_underflow (pfile) + cpp_reader *pfile; +{ + return CPP_EOF; +} + +int +null_cleanup (pbuf, pfile) + cpp_buffer *pbuf; + cpp_reader *pfile; +{ + return 0; +} + +int +macro_cleanup (pbuf, pfile) + cpp_buffer *pbuf; + cpp_reader *pfile; +{ + HASHNODE *macro = (HASHNODE*)pbuf->data; + if (macro->type == T_DISABLED) + macro->type = T_MACRO; + if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion) + free (pbuf->buf); + return 0; +} + +int +file_cleanup (pbuf, pfile) + cpp_buffer *pbuf; + cpp_reader *pfile; +{ + if (pbuf->buf) + { + free (pbuf->buf); + pbuf->buf = 0; + } + return 0; +} + +static void +newline_fix (pfile) + cpp_reader *pfile; +{ +#if 1 + NEWLINE_FIX; +#else + register U_CHAR *p = bp; + + /* First count the backslash-newline pairs here. */ + + while (p[0] == '\\' && p[1] == '\n') + p += 2; + + /* What follows the backslash-newlines is not embarrassing. */ + + if (*p != '/' && *p != '*') + return; + + /* Copy all potentially embarrassing characters + that follow the backslash-newline pairs + down to where the pairs originally started. */ + + while (*p == '*' || *p == '/') + *bp++ = *p++; + + /* Now write the same number of pairs after the embarrassing chars. */ + while (bp < p) { + *bp++ = '\\'; + *bp++ = '\n'; + } +#endif +} + +/* Assuming we have read '/'. + If this is the start of a comment (followed by '*' or '/'), + skip to the end of the comment, and return ' '. + Return EOF if we reached the end of file before the end of the comment. + If not the start of a comment, return '/'. */ + +static int +skip_comment (pfile, linep) + cpp_reader *pfile; + long *linep; +{ + int c; + while (PEEKC() == '\\' && PEEKN(1) == '\n') + { + if (linep) + (*linep)++; + FORWARD(2); + } + if (PEEKC() == '*') + { + FORWARD(1); + for (;;) + { + int prev_c = c; + c = GETC (); + if (c == EOF) + return EOF; + while (c == '\\' && PEEKC() == '\n') + { + if (linep) + (*linep)++; + FORWARD(1), c = GETC(); + } + if (prev_c == '*' && c == '/') + return ' '; + if (c == '\n' && linep) + (*linep)++; + } + } + else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments) + { + FORWARD(1); + for (;;) + { + c = GETC (); + if (c == EOF) + return ' '; /* Allow // to be terminated by EOF. */ + while (c == '\\' && PEEKC() == '\n') + { + FORWARD(1); + c = GETC(); + if (linep) + (*linep)++; + } + if (c == '\n') + { + /* Don't consider final '\n' to be part of comment. */ + FORWARD(-1); + return ' '; + } + } + } + else + return '/'; +} + +/* Skip whitespace \-newline and comments. Does not macro-expand. */ +void +cpp_skip_hspace (pfile) + cpp_reader *pfile; +{ + while (1) + { + int c = PEEKC(); + if (c == EOF) + return; /* FIXME */ + if (is_hor_space[c]) + { + if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "%s in preprocessing directive", + c == '\f' ? "formfeed" : "vertical tab"); + FORWARD(1); + } + else if (c == '/') + { + FORWARD (1); + c = skip_comment (pfile, NULL); + if (c == '/') + FORWARD(-1); + if (c == EOF || c == '/') + return; + } + else if (c == '\\' && PEEKN(1) == '\n') { + FORWARD(2); + } + else if (c == '@' && CPP_BUFFER (pfile)->has_escapes + && is_hor_space[PEEKN(1)]) + FORWARD(2); + else return; + } +} + +/* Read the rest of the current line. + The line is appended to PFILE's output buffer. */ + +void +copy_rest_of_line (pfile) + cpp_reader *pfile; +{ + struct cpp_options *opts = CPP_OPTIONS (pfile); + for (;;) + { + int c = GETC(); + int nextc; + switch (c) + { + case EOF: + goto end_directive; + case '\\': + if (PEEKC() == '\n') + { + FORWARD (1); + continue; + } + case '\'': + case '\"': + goto scan_directive_token; + break; + case '/': + nextc = PEEKC(); + if (nextc == '*' || (opts->cplusplus_comments && nextc == '*')) + goto scan_directive_token; + break; + case '\f': + case '\v': + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "%s in preprocessing directive", + c == '\f' ? "formfeed" : "vertical tab"); + break; + + case '\n': + FORWARD(-1); + goto end_directive; + scan_directive_token: + FORWARD(-1); + cpp_get_token (pfile); + continue; + } + CPP_PUTC (pfile, c); + } + end_directive: ; + CPP_NUL_TERMINATE (pfile); +} + +void +skip_rest_of_line (pfile) + cpp_reader *pfile; +{ + long old = CPP_WRITTEN (pfile); + copy_rest_of_line (pfile); + CPP_SET_WRITTEN (pfile, old); +} + +/* Handle a possible # directive. + '#' has already been read. */ + +int +handle_directive (pfile) + cpp_reader *pfile; +{ int c; + register struct directive *kt; + int ident_length; + long after_ident; + U_CHAR *ident, *line_end; + long old_written = CPP_WRITTEN (pfile); + + cpp_skip_hspace (pfile); + + c = PEEKC (); + if (c >= '0' && c <= '9') + { + /* Handle # followed by a line number. */ + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "`#' followed by integer"); + do_line (pfile, NULL); + goto done_a_directive; + } + + /* Now find the directive name. */ + CPP_PUTC (pfile, '#'); + parse_name (pfile, GETC()); + ident = pfile->token_buffer + old_written + 1; + ident_length = CPP_PWRITTEN (pfile) - ident; + if (ident_length == 0 && PEEKC() == '\n') + { + /* A line of just `#' becomes blank. */ + goto done_a_directive; + } + +#if 0 + if (ident_length == 0 || !is_idstart[*ident]) { + U_CHAR *p = ident; + while (is_idchar[*p]) { + if (*p < '0' || *p > '9') + break; + p++; + } + /* Avoid error for `###' and similar cases unless -pedantic. */ + if (p == ident) { + while (*p == '#' || is_hor_space[*p]) p++; + if (*p == '\n') { + if (pedantic && !lang_asm) + cpp_warning (pfile, "invalid preprocessor directive"); + return 0; + } + } + + if (!lang_asm) + cpp_error (pfile, "invalid preprocessor directive name"); + + return 0; + } +#endif + /* + * Decode the keyword and call the appropriate expansion + * routine, after moving the input pointer up to the next line. + */ + for (kt = directive_table; ; kt++) { + if (kt->length <= 0) + goto not_a_directive; + if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length)) + break; + } + + if (! kt->command_reads_line) + { + /* Nonzero means do not delete comments within the directive. + #define needs this when -traditional. */ + int comments = CPP_TRADITIONAL (pfile) && kt->traditional_comments; + int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments; + CPP_OPTIONS (pfile)->put_out_comments = comments; + after_ident = CPP_WRITTEN (pfile); + copy_rest_of_line (pfile); + CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments; + } + + /* For #pragma and #define, we may want to pass through the directive. + Other directives may create output, but we don't want the directive + itself out, so we pop it now. For example #include may write a #line + command (see comment in do_include), and conditionals may emit + #failed ... #endfailed stuff. But note that popping the buffer + means the parameters to kt->func may point after pfile->limit + so these parameters are invalid as soon as something gets appended + to the token_buffer. */ + + line_end = CPP_PWRITTEN (pfile); + if (!kt->pass_thru && kt->type != T_DEFINE) + CPP_SET_WRITTEN (pfile, old_written); + + (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end); + if (kt->pass_thru + || (kt->type == T_DEFINE + && CPP_OPTIONS (pfile)->dump_macros == dump_definitions)) + { + /* Just leave the entire #define in the output stack. */ + } + else if (kt->type == T_DEFINE + && CPP_OPTIONS (pfile)->dump_macros == dump_names) + { + U_CHAR *p = pfile->token_buffer + old_written + 7; /* Skip "#define". */ + SKIP_WHITE_SPACE (p); + while (is_idchar[*p]) p++; + pfile->limit = p; + CPP_PUTC (pfile, '\n'); + } + else if (kt->type == T_DEFINE) + CPP_SET_WRITTEN (pfile, old_written); + done_a_directive: + return 1; + + not_a_directive: + return 0; +} + +/* Pass a directive through to the output file. + BUF points to the contents of the directive, as a contiguous string. + LIMIT points to the first character past the end of the directive. + KEYWORD is the keyword-table entry for the directive. */ + +static void +pass_thru_directive (buf, limit, pfile, keyword) + U_CHAR *buf, *limit; + cpp_reader *pfile; + struct directive *keyword; +{ + register unsigned keyword_length = keyword->length; + + CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf)); + CPP_PUTC_Q (pfile, '#'); + CPP_PUTS_Q (pfile, keyword->name, keyword_length); + if (limit != buf && buf[0] != ' ') + CPP_PUTC_Q (pfile, ' '); + CPP_PUTS_Q (pfile, buf, limit - buf); +#if 0 + CPP_PUTS_Q (pfile, '\n'); + /* Count the line we have just made in the output, + to get in sync properly. */ + pfile->lineno++; +#endif +} + +/* The arglist structure is built by do_define to tell + collect_definition where the argument names begin. That + is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist + would contain pointers to the strings x, y, and z. + Collect_definition would then build a DEFINITION node, + with reflist nodes pointing to the places x, y, and z had + appeared. So the arglist is just convenience data passed + between these two routines. It is not kept around after + the current #define has been processed and entered into the + hash table. */ + +struct arglist { + struct arglist *next; + U_CHAR *name; + int length; + int argno; + char rest_args; +}; + +/* Read a replacement list for a macro with parameters. + Build the DEFINITION structure. + Reads characters of text starting at BUF until END. + ARGLIST specifies the formal parameters to look for + in the text of the definition; NARGS is the number of args + in that list, or -1 for a macro name that wants no argument list. + MACRONAME is the macro name itself (so we can avoid recursive expansion) + and NAMELEN is its length in characters. + + Note that comments, backslash-newlines, and leading white space + have already been deleted from the argument. */ + +static DEFINITION * +collect_expansion (pfile, buf, limit, nargs, arglist) + cpp_reader *pfile; + U_CHAR *buf, *limit; + int nargs; + struct arglist *arglist; +{ + DEFINITION *defn; + register U_CHAR *p, *lastp, *exp_p; + struct reflist *endpat = NULL; + /* Pointer to first nonspace after last ## seen. */ + U_CHAR *concat = 0; + /* Pointer to first nonspace after last single-# seen. */ + U_CHAR *stringify = 0; + int maxsize; + int expected_delimiter = '\0'; + + /* Scan thru the replacement list, ignoring comments and quoted + strings, picking up on the macro calls. It does a linear search + thru the arg list on every potential symbol. Profiling might say + that something smarter should happen. */ + + if (limit < buf) + abort (); + + /* Find the beginning of the trailing whitespace. */ + p = buf; + while (p < limit && is_space[limit[-1]]) limit--; + + /* Allocate space for the text in the macro definition. + Leading and trailing whitespace chars need 2 bytes each. + Each other input char may or may not need 1 byte, + so this is an upper bound. The extra 5 are for invented + leading and trailing newline-marker and final null. */ + maxsize = (sizeof (DEFINITION) + + (limit - p) + 5); + /* Occurrences of '@' get doubled, so allocate extra space for them. */ + while (p < limit) + if (*p++ == '@') + maxsize++; + defn = (DEFINITION *) xcalloc (1, maxsize); + + defn->nargs = nargs; + exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION); + lastp = exp_p; + + p = buf; + + /* Add one initial space escape-marker to prevent accidental + token-pasting (often removed by macroexpand). */ + *exp_p++ = '@'; + *exp_p++ = ' '; + + if (limit - p >= 2 && p[0] == '#' && p[1] == '#') { + cpp_error (pfile, "`##' at start of macro definition"); + p += 2; + } + + /* Process the main body of the definition. */ + while (p < limit) { + int skipped_arg = 0; + register U_CHAR c = *p++; + + *exp_p++ = c; + + if (!CPP_TRADITIONAL (pfile)) { + switch (c) { + case '\'': + case '\"': + if (expected_delimiter != '\0') { + if (c == expected_delimiter) + expected_delimiter = '\0'; + } else + expected_delimiter = c; + break; + + case '\\': + if (p < limit && expected_delimiter) { + /* In a string, backslash goes through + and makes next char ordinary. */ + *exp_p++ = *p++; + } + break; + + case '@': + /* An '@' in a string or character constant stands for itself, + and does not need to be escaped. */ + if (!expected_delimiter) + *exp_p++ = c; + break; + + case '#': + /* # is ordinary inside a string. */ + if (expected_delimiter) + break; + if (p < limit && *p == '#') { + /* ##: concatenate preceding and following tokens. */ + /* Take out the first #, discard preceding whitespace. */ + exp_p--; + while (exp_p > lastp && is_hor_space[exp_p[-1]]) + --exp_p; + /* Skip the second #. */ + p++; + /* Discard following whitespace. */ + SKIP_WHITE_SPACE (p); + concat = p; + if (p == limit) + cpp_error (pfile, "`##' at end of macro definition"); + } else if (nargs >= 0) { + /* Single #: stringify following argument ref. + Don't leave the # in the expansion. */ + exp_p--; + SKIP_WHITE_SPACE (p); + if (p == limit || ! is_idstart[*p]) + cpp_error (pfile, + "`#' operator is not followed by a macro argument name"); + else + stringify = p; + } + break; + } + } else { + /* In -traditional mode, recognize arguments inside strings and + and character constants, and ignore special properties of #. + Arguments inside strings are considered "stringified", but no + extra quote marks are supplied. */ + switch (c) { + case '\'': + case '\"': + if (expected_delimiter != '\0') { + if (c == expected_delimiter) + expected_delimiter = '\0'; + } else + expected_delimiter = c; + break; + + case '\\': + /* Backslash quotes delimiters and itself, but not macro args. */ + if (expected_delimiter != 0 && p < limit + && (*p == expected_delimiter || *p == '\\')) { + *exp_p++ = *p++; + continue; + } + break; + + case '/': + if (expected_delimiter != '\0') /* No comments inside strings. */ + break; + if (*p == '*') { + /* If we find a comment that wasn't removed by handle_directive, + this must be -traditional. So replace the comment with + nothing at all. */ + exp_p--; + p += 1; + while (p < limit && !(p[-2] == '*' && p[-1] == '/')) + p++; +#if 0 + /* Mark this as a concatenation-point, as if it had been ##. */ + concat = p; +#endif + } + break; + } + } + + /* Handle the start of a symbol. */ + if (is_idchar[c] && nargs > 0) { + U_CHAR *id_beg = p - 1; + int id_len; + + --exp_p; + while (p != limit && is_idchar[*p]) p++; + id_len = p - id_beg; + + if (is_idstart[c]) { + register struct arglist *arg; + + for (arg = arglist; arg != NULL; arg = arg->next) { + struct reflist *tpat; + + if (arg->name[0] == c + && arg->length == id_len + && strncmp (arg->name, id_beg, id_len) == 0) { + if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) { + if (CPP_TRADITIONAL (pfile)) { + cpp_warning (pfile, "macro argument `%.*s' is stringified.", + id_len, arg->name); + } else { + cpp_warning (pfile, + "macro arg `%.*s' would be stringified with -traditional.", + id_len, arg->name); + } + } + /* If ANSI, don't actually substitute inside a string. */ + if (!CPP_TRADITIONAL (pfile) && expected_delimiter) + break; + /* make a pat node for this arg and append it to the end of + the pat list */ + tpat = (struct reflist *) xmalloc (sizeof (struct reflist)); + tpat->next = NULL; + tpat->raw_before = concat == id_beg; + tpat->raw_after = 0; + tpat->rest_args = arg->rest_args; + tpat->stringify = (CPP_TRADITIONAL (pfile) + ? expected_delimiter != '\0' + : stringify == id_beg); + + if (endpat == NULL) + defn->pattern = tpat; + else + endpat->next = tpat; + endpat = tpat; + + tpat->argno = arg->argno; + tpat->nchars = exp_p - lastp; + { + register U_CHAR *p1 = p; + SKIP_WHITE_SPACE (p1); + if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#') + tpat->raw_after = 1; + } + lastp = exp_p; /* place to start copying from next time */ + skipped_arg = 1; + break; + } + } + } + + /* If this was not a macro arg, copy it into the expansion. */ + if (! skipped_arg) { + register U_CHAR *lim1 = p; + p = id_beg; + while (p != lim1) + *exp_p++ = *p++; + if (stringify == id_beg) + cpp_error (pfile, + "`#' operator should be followed by a macro argument name"); + } + } + } + + if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0) + { + /* If ANSI, put in a "@ " marker to prevent token pasting. + But not if "inside a string" (which in ANSI mode + happens only for -D option). */ + *exp_p++ = '@'; + *exp_p++ = ' '; + } + + *exp_p = '\0'; + + defn->length = exp_p - defn->expansion; + + /* Crash now if we overrun the allocated size. */ + if (defn->length + 1 > maxsize) + abort (); + +#if 0 +/* This isn't worth the time it takes. */ + /* give back excess storage */ + defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1); +#endif + + return defn; +} + +/* + * special extension string that can be added to the last macro argument to + * allow it to absorb the "rest" of the arguments when expanded. Ex: + * #define wow(a, b...) process (b, a, b) + * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); } + * { wow (one, two); } -> { process (two, one, two); } + * if this "rest_arg" is used with the concat token '##' and if it is not + * supplied then the token attached to with ## will not be outputted. Ex: + * #define wow (a, b...) process (b ## , a, ## b) + * { wow (1, 2); } -> { process (2, 1, 2); } + * { wow (one); } -> { process (one); { + */ +static char rest_extension[] = "..."; +#define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1) + +/* Create a DEFINITION node from a #define directive. Arguments are + as for do_define. */ +static MACRODEF +create_definition (buf, limit, pfile, predefinition) + U_CHAR *buf, *limit; + cpp_reader *pfile; + int predefinition; +{ + U_CHAR *bp; /* temp ptr into input buffer */ + U_CHAR *symname; /* remember where symbol name starts */ + int sym_length; /* and how long it is */ + int rest_args = 0; + long line, col; + char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : ""; + DEFINITION *defn; + int arglengths = 0; /* Accumulate lengths of arg names + plus number of args. */ + MACRODEF mdef; + cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col); + + bp = buf; + + while (is_hor_space[*bp]) + bp++; + + symname = bp; /* remember where it starts */ + + sym_length = check_macro_name (pfile, bp, "macro"); + bp += sym_length; + + /* Lossage will occur if identifiers or control keywords are broken + across lines using backslash. This is not the right place to take + care of that. */ + + if (*bp == '(') { + struct arglist *arg_ptrs = NULL; + int argno = 0; + + bp++; /* skip '(' */ + SKIP_WHITE_SPACE (bp); + + /* Loop over macro argument names. */ + while (*bp != ')') { + struct arglist *temp; + + temp = (struct arglist *) alloca (sizeof (struct arglist)); + temp->name = bp; + temp->next = arg_ptrs; + temp->argno = argno++; + temp->rest_args = 0; + arg_ptrs = temp; + + if (rest_args) + cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension); + + if (!is_idstart[*bp]) + cpp_pedwarn (pfile, "invalid character in macro parameter name"); + + /* Find the end of the arg name. */ + while (is_idchar[*bp]) { + bp++; + /* do we have a "special" rest-args extension here? */ + if (limit - bp > REST_EXTENSION_LENGTH && + strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) { + rest_args = 1; + temp->rest_args = 1; + break; + } + } + temp->length = bp - temp->name; + if (rest_args == 1) + bp += REST_EXTENSION_LENGTH; + arglengths += temp->length + 2; + SKIP_WHITE_SPACE (bp); + if (temp->length == 0 || (*bp != ',' && *bp != ')')) { + cpp_error (pfile, "badly punctuated parameter list in `#define'"); + goto nope; + } + if (*bp == ',') { + bp++; + SKIP_WHITE_SPACE (bp); + } + if (bp >= limit) { + cpp_error (pfile, "unterminated parameter list in `#define'"); + goto nope; + } + { + struct arglist *otemp; + + for (otemp = temp->next; otemp != NULL; otemp = otemp->next) + if (temp->length == otemp->length && + strncmp (temp->name, otemp->name, temp->length) == 0) { + U_CHAR *name; + + name = (U_CHAR *) alloca (temp->length + 1); + (void) strncpy (name, temp->name, temp->length); + name[temp->length] = '\0'; + cpp_error (pfile, + "duplicate argument name `%s' in `#define'", name); + goto nope; + } + } + } + + ++bp; /* skip paren */ + SKIP_WHITE_SPACE (bp); + /* now everything from bp before limit is the definition. */ + defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs); + defn->rest_args = rest_args; + + /* Now set defn->args.argnames to the result of concatenating + the argument names in reverse order + with comma-space between them. */ + defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1); + { + struct arglist *temp; + int i = 0; + for (temp = arg_ptrs; temp; temp = temp->next) { + bcopy (temp->name, &defn->args.argnames[i], temp->length); + i += temp->length; + if (temp->next != 0) { + defn->args.argnames[i++] = ','; + defn->args.argnames[i++] = ' '; + } + } + defn->args.argnames[i] = 0; + } + } else { + /* Simple expansion or empty definition. */ + + if (bp < limit) + { + if (is_hor_space[*bp]) { + bp++; + SKIP_WHITE_SPACE (bp); + } else { + switch (*bp) { + case '!': case '"': case '#': case '%': case '&': case '\'': + case ')': case '*': case '+': case ',': case '-': case '.': + case '/': case ':': case ';': case '<': case '=': case '>': + case '?': case '[': case '\\': case ']': case '^': case '{': + case '|': case '}': case '~': + cpp_warning (pfile, "missing white space after `#define %.*s'", + sym_length, symname); + break; + + default: + cpp_pedwarn (pfile, "missing white space after `#define %.*s'", + sym_length, symname); + break; + } + } + } + /* now everything from bp before limit is the definition. */ + defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR); + defn->args.argnames = (U_CHAR *) ""; + } + + defn->line = line; + defn->file = file; + + /* OP is null if this is a predefinition */ + defn->predefined = predefinition; + mdef.defn = defn; + mdef.symnam = symname; + mdef.symlen = sym_length; + + return mdef; + + nope: + mdef.defn = 0; + return mdef; +} + +/* Check a purported macro name SYMNAME, and yield its length. + USAGE is the kind of name this is intended for. */ + +static int +check_macro_name (pfile, symname, usage) + cpp_reader *pfile; + U_CHAR *symname; + char *usage; +{ + U_CHAR *p; + int sym_length; + + for (p = symname; is_idchar[*p]; p++) + ; + sym_length = p - symname; + if (sym_length == 0) + cpp_error (pfile, "invalid %s name", usage); + else if (!is_idstart[*symname]) { + U_CHAR *msg; /* what pain... */ + msg = (U_CHAR *) alloca (sym_length + 1); + bcopy (symname, msg, sym_length); + msg[sym_length] = 0; + cpp_error (pfile, "invalid %s name `%s'", usage, msg); + } else { + if (! strncmp (symname, "defined", 7) && sym_length == 7) + cpp_error (pfile, "invalid %s name `defined'", usage); + } + return sym_length; +} + +/* + * return zero if two DEFINITIONs are isomorphic + */ +static int +compare_defs (d1, d2) + DEFINITION *d1, *d2; +{ + register struct reflist *a1, *a2; + register U_CHAR *p1 = d1->expansion; + register U_CHAR *p2 = d2->expansion; + int first = 1; + + if (d1->nargs != d2->nargs) + return 1; + if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames)) + return 1; + for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2; + a1 = a1->next, a2 = a2->next) { + if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars)) + || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0)) + || a1->argno != a2->argno + || a1->stringify != a2->stringify + || a1->raw_before != a2->raw_before + || a1->raw_after != a2->raw_after) + return 1; + first = 0; + p1 += a1->nchars; + p2 += a2->nchars; + } + if (a1 != a2) + return 1; + if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion), + p2, d2->length - (p2 - d2->expansion), 1)) + return 1; + return 0; +} + +/* Return 1 if two parts of two macro definitions are effectively different. + One of the parts starts at BEG1 and has LEN1 chars; + the other has LEN2 chars at BEG2. + Any sequence of whitespace matches any other sequence of whitespace. + FIRST means these parts are the first of a macro definition; + so ignore leading whitespace entirely. + LAST means these parts are the last of a macro definition; + so ignore trailing whitespace entirely. */ + +static int +comp_def_part (first, beg1, len1, beg2, len2, last) + int first; + U_CHAR *beg1, *beg2; + int len1, len2; + int last; +{ + register U_CHAR *end1 = beg1 + len1; + register U_CHAR *end2 = beg2 + len2; + if (first) { + while (beg1 != end1 && is_space[*beg1]) beg1++; + while (beg2 != end2 && is_space[*beg2]) beg2++; + } + if (last) { + while (beg1 != end1 && is_space[end1[-1]]) end1--; + while (beg2 != end2 && is_space[end2[-1]]) end2--; + } + while (beg1 != end1 && beg2 != end2) { + if (is_space[*beg1] && is_space[*beg2]) { + while (beg1 != end1 && is_space[*beg1]) beg1++; + while (beg2 != end2 && is_space[*beg2]) beg2++; + } else if (*beg1 == *beg2) { + beg1++; beg2++; + } else break; + } + return (beg1 != end1) || (beg2 != end2); +} + +/* Process a #define command. +BUF points to the contents of the #define command, as a contiguous string. +LIMIT points to the first character past the end of the definition. +KEYWORD is the keyword-table entry for #define, +or NULL for a "predefined" macro. */ + +static int +do_define (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + int hashcode; + MACRODEF mdef; + HASHNODE *hp; + +#if 0 + /* If this is a precompiler run (with -pcp) pass thru #define commands. */ + if (pcp_outfile && keyword) + pass_thru_directive (buf, limit, pfile, keyword); +#endif + + mdef = create_definition (buf, limit, pfile, keyword == NULL); + if (mdef.defn == 0) + goto nope; + + hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE); + + if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL) + { + int ok = 0; + /* Redefining a precompiled key is ok. */ + if (hp->type == T_PCSTRING) + ok = 1; + /* Redefining a macro is ok if the definitions are the same. */ + else if (hp->type == T_MACRO) + ok = ! compare_defs (mdef.defn, hp->value.defn); + /* Redefining a constant is ok with -D. */ + else if (hp->type == T_CONST) + ok = ! CPP_OPTIONS (pfile)->done_initializing; + /* Print the warning if it's not ok. */ + if (!ok) + { + U_CHAR *msg; /* what pain... */ + + /* If we are passing through #define and #undef directives, do + that for this re-definition now. */ + if (CPP_OPTIONS (pfile)->debug_output && keyword) + pass_thru_directive (buf, limit, pfile, keyword); + + msg = (U_CHAR *) alloca (mdef.symlen + 22); + *msg = '`'; + bcopy (mdef.symnam, msg + 1, mdef.symlen); + strcpy ((char *) (msg + mdef.symlen + 1), "' redefined"); + cpp_pedwarn (pfile, msg); + if (hp->type == T_MACRO) + cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line, + "this is the location of the previous definition"); + } + /* Replace the old definition. */ + hp->type = T_MACRO; + hp->value.defn = mdef.defn; + } + else + { + /* If we are passing through #define and #undef directives, do + that for this new definition now. */ + if (CPP_OPTIONS (pfile)->debug_output && keyword) + pass_thru_directive (buf, limit, pfile, keyword); + install (mdef.symnam, mdef.symlen, T_MACRO, 0, + (char *) mdef.defn, hashcode); + } + + return 0; + +nope: + + return 1; +} + +/* This structure represents one parsed argument in a macro call. + `raw' points to the argument text as written (`raw_length' is its length). + `expanded' points to the argument's macro-expansion + (its length is `expand_length'). + `stringified_length' is the length the argument would have + if stringified. + `use_count' is the number of times this macro arg is substituted + into the macro. If the actual use count exceeds 10, + the value stored is 10. */ + +/* raw and expanded are relative to ARG_BASE */ +#define ARG_BASE ((pfile)->token_buffer) + +struct argdata { + /* Strings relative to pfile->token_buffer */ + long raw, expanded, stringified; + int raw_length, expand_length; + int stringified_length; + char newlines; + char use_count; +}; + + +cpp_buffer* +cpp_push_buffer (pfile, buffer, length) + cpp_reader *pfile; + U_CHAR *buffer; + long length; +{ +#ifdef STATIC_BUFFERS + register cpp_buffer *buf = CPP_BUFFER (pfile); + if (buf == pfile->buffer_stack) + fatal ("%s: macro or `#include' recursion too deep", buf->fname); + buf--; + bzero ((char *) buf, sizeof (cpp_buffer)); + CPP_BUFFER (pfile) = buf; +#else + register cpp_buffer *buf = (cpp_buffer*) xmalloc (sizeof(cpp_buffer)); + bzero ((char *) buf, sizeof (cpp_buffer)); + CPP_PREV_BUFFER (buf) = CPP_BUFFER (pfile); + CPP_BUFFER (pfile) = buf; +#endif + buf->if_stack = pfile->if_stack; + buf->cleanup = null_cleanup; + buf->underflow = null_underflow; + buf->buf = buf->cur = buffer; + buf->alimit = buf->rlimit = buffer + length; + + return buf; +} + +cpp_buffer* +cpp_pop_buffer (pfile) + cpp_reader *pfile; +{ + cpp_buffer *buf = CPP_BUFFER (pfile); +#ifdef STATIC_BUFFERS + (*buf->cleanup) (buf, pfile); + return ++CPP_BUFFER (pfile); +#else + cpp_buffer *next_buf = CPP_PREV_BUFFER (buf); + (*buf->cleanup) (buf, pfile); + CPP_BUFFER (pfile) = next_buf; + free (buf); + return next_buf; +#endif +} + +/* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer. + Pop the buffer when done. */ + +void +cpp_scan_buffer (pfile) + cpp_reader *pfile; +{ + cpp_buffer *buffer = CPP_BUFFER (pfile); + for (;;) + { + enum cpp_token token = cpp_get_token (pfile); + if (token == CPP_EOF) /* Should not happen ... */ + break; + if (token == CPP_POP && CPP_BUFFER (pfile) == buffer) + { + cpp_pop_buffer (pfile); + break; + } + } +} + +/* + * Rescan a string (which may have escape marks) into pfile's buffer. + * Place the result in pfile->token_buffer. + * + * The input is copied before it is scanned, so it is safe to pass + * it something from the token_buffer that will get overwritten + * (because it follows CPP_WRITTEN). This is used by do_include. + */ + +static void +cpp_expand_to_buffer (pfile, buf, length) + cpp_reader *pfile; + U_CHAR *buf; + int length; +{ + register cpp_buffer *ip; + cpp_buffer obuf; + U_CHAR *limit = buf + length; + U_CHAR *buf1; +#if 0 + int odepth = indepth; +#endif + + if (length < 0) + abort (); + + /* Set up the input on the input stack. */ + + buf1 = (U_CHAR *) alloca (length + 1); + { + register U_CHAR *p1 = buf; + register U_CHAR *p2 = buf1; + + while (p1 != limit) + *p2++ = *p1++; + } + buf1[length] = 0; + + ip = cpp_push_buffer (pfile, buf1, length); + ip->has_escapes = 1; +#if 0 + ip->lineno = obuf.lineno = 1; +#endif + + /* Scan the input, create the output. */ + cpp_scan_buffer (pfile); + +#if 0 + if (indepth != odepth) + abort (); +#endif + + CPP_NUL_TERMINATE (pfile); +} + + +static void +adjust_position (buf, limit, linep, colp) + U_CHAR *buf; + U_CHAR *limit; + long *linep; + long *colp; +{ + while (buf < limit) + { + U_CHAR ch = *buf++; + if (ch == '\n') + (*linep)++, (*colp) = 1; + else + (*colp)++; + } +} + +/* Move line_base forward, updating lineno and colno. */ + +static void +update_position (pbuf) + register cpp_buffer *pbuf; +{ + unsigned char *old_pos = pbuf->buf + pbuf->line_base; + unsigned char *new_pos = pbuf->cur; + register struct parse_marker *mark; + for (mark = pbuf->marks; mark != NULL; mark = mark->next) + { + if (pbuf->buf + mark->position < new_pos) + new_pos = pbuf->buf + mark->position; + } + pbuf->line_base += new_pos - old_pos; + adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno); +} + +void +cpp_buf_line_and_col (pbuf, linep, colp) + register cpp_buffer *pbuf; + long *linep, *colp; +{ + long dummy; + if (colp == NULL) + colp = &dummy; + if (pbuf) + { + *linep = pbuf->lineno; + *colp = pbuf->colno; + adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp); + } + else + { + *linep = 0; + *colp = 0; + } +} + +/* Return the cpp_buffer that corresponds to a file (not a macro). */ + +cpp_buffer* +cpp_file_buffer (pfile) + cpp_reader *pfile; +{ + cpp_buffer *ip = CPP_BUFFER (pfile); + + for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip)) + if (ip->fname != NULL) + return ip; + return NULL; +} + +static long +count_newlines (buf, limit) + register U_CHAR *buf; + register U_CHAR *limit; +{ + register long count = 0; + while (buf < limit) + { + U_CHAR ch = *buf++; + if (ch == '\n') + count++; + } + return count; +} + +/* + * write out a #line command, for instance, after an #include file. + * If CONDITIONAL is nonzero, we can omit the #line if it would + * appear to be a no-op, and we can output a few newlines instead + * if we want to increase the line number by a small amount. + * FILE_CHANGE says whether we are entering a file, leaving, or neither. + */ + +static void +output_line_command (pfile, conditional, file_change) + cpp_reader *pfile; + int conditional; + enum file_change_code file_change; +{ + int len; + char *line_cmd_buf, *line_end; + long line, col; + cpp_buffer *ip = CPP_BUFFER (pfile); + + if (ip->fname == NULL || CPP_OPTIONS (pfile)->no_output) { + return; + } + + update_position (ip); + line = CPP_BUFFER (pfile)->lineno; + col = CPP_BUFFER (pfile)->colno; + adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col); + + if (CPP_OPTIONS (pfile)->no_line_commands) + return; + + if (conditional) { + if (line == pfile->lineno) + return; + + /* If the inherited line number is a little too small, + output some newlines instead of a #line command. */ + if (line > pfile->lineno && line < pfile->lineno + 8) { + CPP_RESERVE (pfile, 20); + while (line > pfile->lineno) { + CPP_PUTC_Q (pfile, '\n'); + pfile->lineno++; + } + return; + } + } + +#if 0 + /* Don't output a line number of 0 if we can help it. */ + if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length + && *ip->bufp == '\n') { + ip->lineno++; + ip->bufp++; + } +#endif + + CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50); + { +#ifdef OUTPUT_LINE_COMMANDS + static char sharp_line[] = "#line "; +#else + static char sharp_line[] = "# "; +#endif + CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1); + } + + sprintf (CPP_PWRITTEN (pfile), "%d ", line); + CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile))); + + quote_string (pfile, ip->nominal_fname); + if (file_change != same_file) { + CPP_PUTC_Q (pfile, ' '); + CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2'); + } + /* Tell cc1 if following text comes from a system header file. */ + if (ip->system_header_p) { + CPP_PUTC_Q (pfile, ' '); + CPP_PUTC_Q (pfile, '3'); + } +#ifndef NO_IMPLICIT_EXTERN_C + /* Tell cc1plus if following text should be treated as C. */ + if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) { + CPP_PUTC_Q (pfile, ' '); + CPP_PUTC_Q (pfile, '4'); + } +#endif + CPP_PUTC_Q (pfile, '\n'); + pfile->lineno = line; +} + +/* + * Parse a macro argument and append the info on PFILE's token_buffer. + * REST_ARGS means to absorb the rest of the args. + * Return nonzero to indicate a syntax error. + */ + +static enum cpp_token +macarg (pfile, rest_args) + cpp_reader *pfile; + int rest_args; +{ + int paren = 0; + enum cpp_token token; + long arg_start = CPP_WRITTEN (pfile); + char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments; + CPP_OPTIONS (pfile)->put_out_comments = 0; + + /* Try to parse as much of the argument as exists at this + input stack level. */ + pfile->no_macro_expand++; + for (;;) + { + token = cpp_get_token (pfile); + switch (token) + { + case CPP_EOF: + goto done; + case CPP_POP: + /* If we've hit end of file, it's an error (reported by caller). + Ditto if it's the end of cpp_expand_to_buffer text. + If we've hit end of macro, just continue. */ + if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) + goto done; + break; + case CPP_LPAREN: + paren++; + break; + case CPP_RPAREN: + if (--paren < 0) + goto found; + break; + case CPP_COMMA: + /* if we've returned to lowest level and + we aren't absorbing all args */ + if (paren == 0 && rest_args == 0) + goto found; + break; + found: + /* Remove ',' or ')' from argument buffer. */ + CPP_ADJUST_WRITTEN (pfile, -1); + goto done; + default: ; + } + } + + done: + CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments; + pfile->no_macro_expand--; + + return token; +} + +/* Turn newlines to spaces in the string of length LENGTH at START, + except inside of string constants. + The string is copied into itself with its beginning staying fixed. */ + +static int +change_newlines (start, length) + U_CHAR *start; + int length; +{ + register U_CHAR *ibp; + register U_CHAR *obp; + register U_CHAR *limit; + register int c; + + ibp = start; + limit = start + length; + obp = start; + + while (ibp < limit) { + *obp++ = c = *ibp++; + switch (c) { + + case '\'': + case '\"': + /* Notice and skip strings, so that we don't delete newlines in them. */ + { + int quotec = c; + while (ibp < limit) { + *obp++ = c = *ibp++; + if (c == quotec) + break; + if (c == '\n' && quotec == '\'') + break; + } + } + break; + } + } + + return obp - start; +} + + +static struct tm * +timestamp (pfile) + cpp_reader *pfile; +{ + if (!pfile->timebuf) { + time_t t = time ((time_t *)0); + pfile->timebuf = localtime (&t); + } + return pfile->timebuf; +} + +static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + }; + +/* + * expand things like __FILE__. Place the expansion into the output + * buffer *without* rescanning. + */ + +static void +special_symbol (hp, pfile) + HASHNODE *hp; + cpp_reader *pfile; +{ + char *buf; + int i, len; + int true_indepth; + cpp_buffer *ip = NULL; + struct tm *timebuf; + + int paren = 0; /* For special `defined' keyword */ + +#if 0 + if (pcp_outfile && pcp_inside_if + && hp->type != T_SPEC_DEFINED && hp->type != T_CONST) + cpp_error (pfile, + "Predefined macro `%s' used inside `#if' during precompilation", + hp->name); +#endif + + for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip)) + { + if (ip == NULL) + { + cpp_error (pfile, "cccp error: not in any file?!"); + return; /* the show must go on */ + } + if (ip->fname != NULL) + break; + } + + switch (hp->type) + { + case T_FILE: + case T_BASE_FILE: + { + char *string; + if (hp->type == T_BASE_FILE) + { + while (CPP_PREV_BUFFER (ip)) + ip = CPP_PREV_BUFFER (ip); + } + string = ip->nominal_fname; + + if (!string) + string = ""; + CPP_RESERVE (pfile, 3 + 4 * strlen (string)); + quote_string (pfile, string); + return; + } + + case T_INCLUDE_LEVEL: + true_indepth = 0; + for (ip = CPP_BUFFER (pfile); ip != NULL; ip = CPP_PREV_BUFFER (ip)) + if (ip->fname != NULL) + true_indepth++; + + buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */ + sprintf (buf, "%d", true_indepth - 1); + break; + + case T_VERSION: + buf = (char *) alloca (3 + strlen (version_string)); + sprintf (buf, "\"%s\"", version_string); + break; + +#ifndef NO_BUILTIN_SIZE_TYPE + case T_SIZE_TYPE: + buf = SIZE_TYPE; + break; +#endif + +#ifndef NO_BUILTIN_PTRDIFF_TYPE + case T_PTRDIFF_TYPE: + buf = PTRDIFF_TYPE; + break; +#endif + + case T_WCHAR_TYPE: + buf = CPP_WCHAR_TYPE (pfile); + break; + + case T_USER_LABEL_PREFIX_TYPE: + buf = USER_LABEL_PREFIX; + break; + + case T_REGISTER_PREFIX_TYPE: + buf = REGISTER_PREFIX; + break; + + case T_CONST: + buf = (char *) alloca (4 * sizeof (int)); + sprintf (buf, "%d", hp->value.ival); +#if 0 + if (pcp_inside_if && pcp_outfile) + /* Output a precondition for this macro use */ + fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival); +#endif + break; + + case T_SPECLINE: + { + long line = ip->lineno; + long col = ip->colno; + adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col); + + buf = (char *) alloca (10); + sprintf (buf, "%d", line); + } + break; + + case T_DATE: + case T_TIME: + buf = (char *) alloca (20); + timebuf = timestamp (pfile); + if (hp->type == T_DATE) + sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon], + timebuf->tm_mday, timebuf->tm_year + 1900); + else + sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min, + timebuf->tm_sec); + break; + + case T_SPEC_DEFINED: + buf = " 0 "; /* Assume symbol is not defined */ + ip = CPP_BUFFER (pfile); + SKIP_WHITE_SPACE (ip->cur); + if (*ip->cur == '(') + { + paren++; + ip->cur++; /* Skip over the paren */ + SKIP_WHITE_SPACE (ip->cur); + } + + if (!is_idstart[*ip->cur]) + goto oops; + if (hp = cpp_lookup (pfile, ip->cur, -1, -1)) + { +#if 0 + if (pcp_outfile && pcp_inside_if + && (hp->type == T_CONST + || (hp->type == T_MACRO && hp->value.defn->predefined))) + /* Output a precondition for this macro use. */ + fprintf (pcp_outfile, "#define %s\n", hp->name); +#endif + buf = " 1 "; + } +#if 0 + else + if (pcp_outfile && pcp_inside_if) + { + /* Output a precondition for this macro use */ + U_CHAR *cp = ip->bufp; + fprintf (pcp_outfile, "#undef "); + while (is_idchar[*cp]) /* Ick! */ + fputc (*cp++, pcp_outfile); + putc ('\n', pcp_outfile); + } +#endif + while (is_idchar[*ip->cur]) + ++ip->cur; + SKIP_WHITE_SPACE (ip->cur); + if (paren) + { + if (*ip->cur != ')') + goto oops; + ++ip->cur; + } + break; + + oops: + + cpp_error (pfile, "`defined' without an identifier"); + break; + + default: + cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */ + abort (); + } + len = strlen (buf); + CPP_RESERVE (pfile, len + 1); + CPP_PUTS_Q (pfile, buf, len); + CPP_NUL_TERMINATE_Q (pfile); + + return; +} + +/* Initialize the built-in macros. */ + +static void +initialize_builtins (pfile) + cpp_reader *pfile; +{ + install ("__LINE__", -1, T_SPECLINE, 0, 0, -1); + install ("__DATE__", -1, T_DATE, 0, 0, -1); + install ("__FILE__", -1, T_FILE, 0, 0, -1); + install ("__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1); + install ("__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1); + install ("__VERSION__", -1, T_VERSION, 0, 0, -1); +#ifndef NO_BUILTIN_SIZE_TYPE + install ("__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1); +#endif +#ifndef NO_BUILTIN_PTRDIFF_TYPE + install ("__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1); +#endif + install ("__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1); + install ("__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1); + install ("__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1); + install ("__TIME__", -1, T_TIME, 0, 0, -1); + if (!CPP_TRADITIONAL (pfile)) + install ("__STDC__", -1, T_CONST, STDC_VALUE, 0, -1); + if (CPP_OPTIONS (pfile)->objc) + install ("__OBJC__", -1, T_CONST, 1, 0, -1); +/* This is supplied using a -D by the compiler driver + so that it is present only when truly compiling with GNU C. */ +/* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */ + + if (CPP_OPTIONS (pfile)->debug_output) + { + char directive[2048]; + register struct directive *dp = &directive_table[0]; + struct tm *timebuf = timestamp (pfile); + cpp_buffer *pbuffer = CPP_BUFFER (pfile); + + while (CPP_PREV_BUFFER (pbuffer)) + pbuffer = CPP_PREV_BUFFER (pbuffer); + sprintf (directive, " __BASE_FILE__ \"%s\"\n", + pbuffer->nominal_fname); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); + + sprintf (directive, " __VERSION__ \"%s\"\n", version_string); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); + +#ifndef NO_BUILTIN_SIZE_TYPE + sprintf (directive, " __SIZE_TYPE__ %s\n", SIZE_TYPE); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); +#endif + +#ifndef NO_BUILTIN_PTRDIFF_TYPE + sprintf (directive, " __PTRDIFF_TYPE__ %s\n", PTRDIFF_TYPE); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); +#endif + + sprintf (directive, " __WCHAR_TYPE__ %s\n", CPP_WCHAR_TYPE (pfile)); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); + + sprintf (directive, " __DATE__ \"%s %2d %4d\"\n", + monthnames[timebuf->tm_mon], + timebuf->tm_mday, timebuf->tm_year + 1900); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); + + sprintf (directive, " __TIME__ \"%02d:%02d:%02d\"\n", + timebuf->tm_hour, timebuf->tm_min, timebuf->tm_sec); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], pfile, dp); + + if (!CPP_TRADITIONAL (pfile)) + { + sprintf (directive, " __STDC__ 1"); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], + pfile, dp); + } + if (CPP_OPTIONS (pfile)->objc) + { + sprintf (directive, " __OBJC__ 1"); + output_line_command (pfile, 0, same_file); + pass_thru_directive (directive, &directive[strlen (directive)], + pfile, dp); + } + } +} + +/* Return 1 iff a token ending in C1 followed directly by a token C2 + could cause mis-tokenization. */ + +static int +unsafe_chars (c1, c2) + int c1, c2; +{ + switch (c1) + { + case '+': case '-': + if (c2 == c1 || c2 == '=') + return 1; + goto letter; + case '.': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'e': case 'E': + if (c2 == '-' || c2 == '+') + return 1; /* could extend a pre-processing number */ + goto letter; + case 'L': + if (c2 == '\'' || c2 == '\"') + return 1; /* Could turn into L"xxx" or L'xxx'. */ + goto letter; + letter: + case '_': + case 'a': case 'b': case 'c': case 'd': case 'f': + case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': + case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': + case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 'y': case 'z': + case 'A': case 'B': case 'C': case 'D': case 'F': + case 'G': case 'H': case 'I': case 'J': case 'K': + case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + /* We're in the middle of either a name or a pre-processing number. */ + return (is_idchar[c2] || c2 == '.'); + case '<': case '>': case '!': case '%': case '#': case ':': + case '^': case '&': case '|': case '*': case '/': case '=': + return (c2 == c1 || c2 == '='); + } + return 0; +} + +/* Expand a macro call. + HP points to the symbol that is the macro being called. + Put the result of expansion onto the input stack + so that subsequent input by our caller will use it. + + If macro wants arguments, caller has already verified that + an argument list follows; arguments come from the input stack. */ + +static void +macroexpand (pfile, hp) + cpp_reader *pfile; + HASHNODE *hp; +{ + int nargs; + DEFINITION *defn = hp->value.defn; + register U_CHAR *xbuf; + long start_line, start_column; + int xbuf_len; + struct argdata *args; + long old_written = CPP_WRITTEN (pfile); +#if 0 + int start_line = instack[indepth].lineno; +#endif + int rest_args, rest_zero; + register int i; + +#if 0 + CHECK_DEPTH (return;); +#endif + +#if 0 + /* This macro is being used inside a #if, which means it must be */ + /* recorded as a precondition. */ + if (pcp_inside_if && pcp_outfile && defn->predefined) + dump_single_macro (hp, pcp_outfile); +#endif + + pfile->output_escapes++; + cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column); + + nargs = defn->nargs; + + if (nargs >= 0) + { + enum cpp_token token; + + args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata)); + + for (i = 0; i < nargs; i++) + { + args[i].raw = args[i].expanded = 0; + args[i].raw_length = 0; + args[i].expand_length = args[i].stringified_length = -1; + args[i].use_count = 0; + } + + /* Parse all the macro args that are supplied. I counts them. + The first NARGS args are stored in ARGS. + The rest are discarded. If rest_args is set then we assume + macarg absorbed the rest of the args. */ + i = 0; + rest_args = 0; + rest_args = 0; + FORWARD(1); /* Discard the open-parenthesis before the first arg. */ + do + { + if (rest_args) + continue; + if (i < nargs || (nargs == 0 && i == 0)) + { + /* if we are working on last arg which absorbs rest of args... */ + if (i == nargs - 1 && defn->rest_args) + rest_args = 1; + args[i].raw = CPP_WRITTEN (pfile); + token = macarg (pfile, rest_args); + args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw; + args[i].newlines = 0; /* FIXME */ + } + else + token = macarg (pfile, 0); + if (token == CPP_EOF || token == CPP_POP) + { + cpp_error_with_line (pfile, start_line, start_column, + "unterminated macro call"); + return; + } + i++; + } while (token == CPP_COMMA); + + /* If we got one arg but it was just whitespace, call that 0 args. */ + if (i == 1) + { + register U_CHAR *bp = ARG_BASE + args[0].raw; + register U_CHAR *lim = bp + args[0].raw_length; + /* cpp.texi says for foo ( ) we provide one argument. + However, if foo wants just 0 arguments, treat this as 0. */ + if (nargs == 0) + while (bp != lim && is_space[*bp]) bp++; + if (bp == lim) + i = 0; + } + + /* Don't output an error message if we have already output one for + a parse error above. */ + rest_zero = 0; + if (nargs == 0 && i > 0) + { + cpp_error (pfile, "arguments given to macro `%s'", hp->name); + } + else if (i < nargs) + { + /* traditional C allows foo() if foo wants one argument. */ + if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile)) + ; + /* the rest args token is allowed to absorb 0 tokens */ + else if (i == nargs - 1 && defn->rest_args) + rest_zero = 1; + else if (i == 0) + cpp_error (pfile, "macro `%s' used without args", hp->name); + else if (i == 1) + cpp_error (pfile, "macro `%s' used with just one arg", hp->name); + else + cpp_error (pfile, "macro `%s' used with only %d args", + hp->name, i); + } + else if (i > nargs) + { + cpp_error (pfile, + "macro `%s' used with too many (%d) args", hp->name, i); + } + } + + /* If macro wants zero args, we parsed the arglist for checking only. + Read directly from the macro definition. */ + if (nargs <= 0) + { + xbuf = defn->expansion; + xbuf_len = defn->length; + } + else + { + register U_CHAR *exp = defn->expansion; + register int offset; /* offset in expansion, + copied a piece at a time */ + register int totlen; /* total amount of exp buffer filled so far */ + + register struct reflist *ap, *last_ap; + + /* Macro really takes args. Compute the expansion of this call. */ + + /* Compute length in characters of the macro's expansion. + Also count number of times each arg is used. */ + xbuf_len = defn->length; + for (ap = defn->pattern; ap != NULL; ap = ap->next) + { + if (ap->stringify) + { + register struct argdata *arg = &args[ap->argno]; + /* Stringify it it hasn't already been */ + if (arg->stringified_length < 0) + { + int arglen = arg->raw_length; + int escaped = 0; + int in_string = 0; + int c; + /* Initially need_space is -1. Otherwise, 1 means the + previous character was a space, but we suppressed it; + 0 means the previous character was a non-space. */ + int need_space = -1; + i = 0; + arg->stringified = CPP_WRITTEN (pfile); + if (!CPP_TRADITIONAL (pfile)) + CPP_PUTC (pfile, '\"'); /* insert beginning quote */ + for (; i < arglen; i++) + { + c = (ARG_BASE + arg->raw)[i]; + + if (! in_string) + { + /* Internal sequences of whitespace are replaced by + one space except within an string or char token.*/ + if (is_space[c]) + { + if (CPP_WRITTEN (pfile) > arg->stringified + && (CPP_PWRITTEN (pfile))[-1] == '@') + { + /* "@ " escape markers are removed */ + CPP_ADJUST_WRITTEN (pfile, -1); + continue; + } + if (need_space == 0) + need_space = 1; + continue; + } + else if (need_space > 0) + CPP_PUTC (pfile, ' '); + need_space = 0; + } + + if (escaped) + escaped = 0; + else + { + if (c == '\\') + escaped = 1; + if (in_string) + { + if (c == in_string) + in_string = 0; + } + else if (c == '\"' || c == '\'') + in_string = c; + } + + /* Escape these chars */ + if (c == '\"' || (in_string && c == '\\')) + CPP_PUTC (pfile, '\\'); + if (isprint (c)) + CPP_PUTC (pfile, c); + else + { + CPP_RESERVE (pfile, 4); + sprintf (CPP_PWRITTEN (pfile), "\\%03o", + (unsigned int) c); + CPP_ADJUST_WRITTEN (pfile, 4); + } + } + if (!CPP_TRADITIONAL (pfile)) + CPP_PUTC (pfile, '\"'); /* insert ending quote */ + arg->stringified_length + = CPP_WRITTEN (pfile) - arg->stringified; + } + xbuf_len += args[ap->argno].stringified_length; + } + else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile)) + /* Add 4 for two newline-space markers to prevent + token concatenation. */ + xbuf_len += args[ap->argno].raw_length + 4; + else + { + /* We have an ordinary (expanded) occurrence of the arg. + So compute its expansion, if we have not already. */ + if (args[ap->argno].expand_length < 0) + { + args[ap->argno].expanded = CPP_WRITTEN (pfile); + cpp_expand_to_buffer (pfile, + ARG_BASE + args[ap->argno].raw, + args[ap->argno].raw_length); + + args[ap->argno].expand_length + = CPP_WRITTEN (pfile) - args[ap->argno].expanded; + } + + /* Add 4 for two newline-space markers to prevent + token concatenation. */ + xbuf_len += args[ap->argno].expand_length + 4; + } + if (args[ap->argno].use_count < 10) + args[ap->argno].use_count++; + } + + xbuf = (U_CHAR *) xmalloc (xbuf_len + 1); + + /* Generate in XBUF the complete expansion + with arguments substituted in. + TOTLEN is the total size generated so far. + OFFSET is the index in the definition + of where we are copying from. */ + offset = totlen = 0; + for (last_ap = NULL, ap = defn->pattern; ap != NULL; + last_ap = ap, ap = ap->next) + { + register struct argdata *arg = &args[ap->argno]; + int count_before = totlen; + + /* Add chars to XBUF. */ + for (i = 0; i < ap->nchars; i++, offset++) + xbuf[totlen++] = exp[offset]; + + /* If followed by an empty rest arg with concatenation, + delete the last run of nonwhite chars. */ + if (rest_zero && totlen > count_before + && ((ap->rest_args && ap->raw_before) + || (last_ap != NULL && last_ap->rest_args + && last_ap->raw_after))) + { + /* Delete final whitespace. */ + while (totlen > count_before && is_space[xbuf[totlen - 1]]) + totlen--; + + /* Delete the nonwhites before them. */ + while (totlen > count_before && ! is_space[xbuf[totlen - 1]]) + totlen--; + } + + if (ap->stringify != 0) + { + bcopy (ARG_BASE + arg->stringified, + xbuf + totlen, arg->stringified_length); + totlen += arg->stringified_length; + } + else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile)) + { + U_CHAR *p1 = ARG_BASE + arg->raw; + U_CHAR *l1 = p1 + arg->raw_length; + if (ap->raw_before) + { + while (p1 != l1 && is_space[*p1]) p1++; + while (p1 != l1 && is_idchar[*p1]) + xbuf[totlen++] = *p1++; + } + if (ap->raw_after) + { + /* Arg is concatenated after: delete trailing whitespace, + whitespace markers, and no-reexpansion markers. */ + while (p1 != l1) + { + if (is_space[l1[-1]]) l1--; + else if (l1[-1] == '-') + { + U_CHAR *p2 = l1 - 1; + /* If a `-' is preceded by an odd number of newlines then it + and the last newline are a no-reexpansion marker. */ + while (p2 != p1 && p2[-1] == '\n') p2--; + if ((l1 - 1 - p2) & 1) { + l1 -= 2; + } + else break; + } + else break; + } + } + + bcopy (p1, xbuf + totlen, l1 - p1); + totlen += l1 - p1; + } + else + { + U_CHAR *expanded = ARG_BASE + arg->expanded; + if (!ap->raw_before && totlen > 0 && arg->expand_length + && !CPP_TRADITIONAL(pfile) + && unsafe_chars (xbuf[totlen-1], expanded[0])) + { + xbuf[totlen++] = '@'; + xbuf[totlen++] = ' '; + } + + bcopy (expanded, xbuf + totlen, arg->expand_length); + totlen += arg->expand_length; + + if (!ap->raw_after && totlen > 0 && offset < defn->length + && !CPP_TRADITIONAL(pfile) + && unsafe_chars (xbuf[totlen-1], exp[offset])) + { + xbuf[totlen++] = '@'; + xbuf[totlen++] = ' '; + } + + /* If a macro argument with newlines is used multiple times, + then only expand the newlines once. This avoids creating + output lines which don't correspond to any input line, + which confuses gdb and gcov. */ + if (arg->use_count > 1 && arg->newlines > 0) + { + /* Don't bother doing change_newlines for subsequent + uses of arg. */ + arg->use_count = 1; + arg->expand_length + = change_newlines (expanded, arg->expand_length); + } + } + + if (totlen > xbuf_len) + abort (); + } + + /* if there is anything left of the definition + after handling the arg list, copy that in too. */ + + for (i = offset; i < defn->length; i++) + { + /* if we've reached the end of the macro */ + if (exp[i] == ')') + rest_zero = 0; + if (! (rest_zero && last_ap != NULL && last_ap->rest_args + && last_ap->raw_after)) + xbuf[totlen++] = exp[i]; + } + + xbuf[totlen] = 0; + xbuf_len = totlen; + + } + + pfile->output_escapes--; + + /* Now put the expansion on the input stack + so our caller will commence reading from it. */ + push_macro_expansion (pfile, xbuf, xbuf_len, hp); + CPP_BUFFER (pfile)->has_escapes = 1; + + /* Pop the space we've used in the token_buffer for argument expansion. */ + CPP_SET_WRITTEN (pfile, old_written); + + /* Recursive macro use sometimes works traditionally. + #define foo(x,y) bar (x (y,0), y) + foo (foo, baz) */ + + if (!CPP_TRADITIONAL (pfile)) + hp->type = T_DISABLED; +} + +static void +push_macro_expansion (pfile, xbuf, xbuf_len, hp) + cpp_reader *pfile; + register U_CHAR *xbuf; + int xbuf_len; + HASHNODE *hp; +{ + register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len); + mbuf->cleanup = macro_cleanup; + mbuf->data = hp; + + /* The first chars of the expansion should be a "@ " added by + collect_expansion. This is to prevent accidental token-pasting + between the text preceding the macro invocation, and the macro + expansion text. + + We would like to avoid adding unneeded spaces (for the sake of + tools that use cpp, such as imake). In some common cases we can + tell that it is safe to omit the space. + + The character before the macro invocation cannot have been an + idchar (or else it would have been pasted with the idchars of + the macro name). Therefore, if the first non-space character + of the expansion is an idchar, we do not need the extra space + to prevent token pasting. + + Also, we don't need the extra space if the first char is '(', + or some other (less common) characters. */ + + if (xbuf[0] == '@' && xbuf[1] == ' ' + && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\'' + || xbuf[2] == '\"')) + mbuf->cur += 2; +} + +/* Like cpp_get_token, except that it does not read past end-of-line. + Also, horizontal space is skipped, and macros are popped. */ + +static enum cpp_token +get_directive_token (pfile) + cpp_reader *pfile; +{ + for (;;) + { + long old_written = CPP_WRITTEN (pfile); + enum cpp_token token; + cpp_skip_hspace (pfile); + if (PEEKC () == '\n') + return CPP_VSPACE; + token = cpp_get_token (pfile); + switch (token) + { + case CPP_POP: + if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) + return token; + /* ... else fall though ... */ + case CPP_HSPACE: case CPP_COMMENT: + CPP_SET_WRITTEN (pfile, old_written); + break; + default: + return token; + } + } +} + +/* Handle #include and #import. + This function expects to see "fname" or on the input. + + The input is normally in part of the output_buffer following + CPP_WRITTEN, and will get overwritten by output_line_command. + I.e. in input file specification has been popped by handle_directive. + This is safe. */ + +static int +do_include (pfile, keyword, unused1, unused2) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *unused1, *unused2; +{ + int importing = (keyword->type == T_IMPORT); + int skip_dirs = (keyword->type == T_INCLUDE_NEXT); + char *fname; /* Dynamically allocated fname buffer */ + char *pcftry; + char *pcfname; + U_CHAR *fbeg, *fend; /* Beginning and end of fname */ + enum cpp_token token; + + /* Chain of dirs to search */ + struct file_name_list *search_start = CPP_OPTIONS (pfile)->include; + struct file_name_list dsp[1]; /* First in chain, if #include "..." */ + struct file_name_list *searchptr = 0; + long old_written = CPP_WRITTEN (pfile); + + int flen; + + int f; /* file number */ + + int retried = 0; /* Have already tried macro + expanding the include line*/ + int angle_brackets = 0; /* 0 for "...", 1 for <...> */ + int pcf = -1; + char *pcfbuf; + char *pcfbuflimit; + int pcfnum; + f= -1; /* JF we iz paranoid! */ + + if (importing && CPP_OPTIONS (pfile)->warn_import + && !CPP_OPTIONS (pfile)->inhibit_warnings + && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning) + { + pfile->import_warning = 1; + cpp_warning (pfile, "using `#import' is not recommended"); + fprintf (stderr, "The fact that a certain header file need not be processed more than once\n"); + fprintf (stderr, "should be indicated in the header file, not where it is used.\n"); + fprintf (stderr, "The best way to do this is with a conditional of this form:\n\n"); + fprintf (stderr, " #ifndef _FOO_H_INCLUDED\n"); + fprintf (stderr, " #define _FOO_H_INCLUDED\n"); + fprintf (stderr, " ... ...\n"); + fprintf (stderr, " #endif /* Not _FOO_H_INCLUDED */\n\n"); + fprintf (stderr, "Then users can use `#include' any number of times.\n"); + fprintf (stderr, "GNU C automatically avoids processing the file more than once\n"); + fprintf (stderr, "when it is equipped with such a conditional.\n"); + } + + pfile->parsing_include_directive++; + token = get_directive_token (pfile); + pfile->parsing_include_directive--; + + if (token == CPP_STRING) + { + /* FIXME - check no trailing garbage */ + fbeg = pfile->token_buffer + old_written + 1; + fend = CPP_PWRITTEN (pfile) - 1; + if (fbeg[-1] == '<') + { + angle_brackets = 1; + /* If -I-, start with the first -I dir after the -I-. */ + if (CPP_OPTIONS (pfile)->first_bracket_include) + search_start = CPP_OPTIONS (pfile)->first_bracket_include; + } + /* If -I- was specified, don't search current dir, only spec'd ones. */ + else if (! CPP_OPTIONS (pfile)->ignore_srcdir) + { + cpp_buffer *fp; + /* We have "filename". Figure out directory this source + file is coming from and put it on the front of the list. */ + + for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp)) + { + int n; + char *ep,*nam; + + if ((nam = fp->nominal_fname) != NULL) + { + /* Found a named file. Figure out dir of the file, + and put it in front of the search list. */ + dsp[0].next = search_start; + search_start = dsp; +#ifndef VMS + ep = rindex (nam, '/'); +#else /* VMS */ + ep = rindex (nam, ']'); + if (ep == NULL) ep = rindex (nam, '>'); + if (ep == NULL) ep = rindex (nam, ':'); + if (ep != NULL) ep++; +#endif /* VMS */ + if (ep != NULL) + { + n = ep - nam; + dsp[0].fname = (char *) alloca (n + 1); + strncpy (dsp[0].fname, nam, n); + dsp[0].fname[n] = '\0'; + if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len) + pfile->max_include_len = n + INCLUDE_LEN_FUDGE; + } + else + { + dsp[0].fname = 0; /* Current directory */ + } + dsp[0].got_name_map = 0; + break; + } + } + } + } +#ifdef VMS + else if (token == CPP_NAME) + { + /* + * Support '#include xyz' like VAX-C to allow for easy use of all the + * decwindow include files. It defaults to '#include ' (so the + * code from case '<' is repeated here) and generates a warning. + */ + cpp_warning (pfile, + "VAX-C-style include specification found, use '#include ' !"); + angle_brackets = 1; + /* If -I-, start with the first -I dir after the -I-. */ + if (CPP_OPTIONS (pfile)->first_bracket_include) + search_start = CPP_OPTIONS (pfile)->first_bracket_include; + fbeg = pfile->token_buffer + old_written; + fend = CPP_PWRITTEN (pfile); + } +#endif + else + { + cpp_error (pfile, + "`#%s' expects \"FILENAME\" or ", keyword->name); + CPP_SET_WRITTEN (pfile, old_written); + skip_rest_of_line (pfile); + return 0; + } + + *fend = 0; + + token = get_directive_token (pfile); + if (token != CPP_VSPACE) + { + cpp_error (pfile, "junk at end of `#include'"); + while (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) + token = get_directive_token (pfile); + } + + /* For #include_next, skip in the search path + past the dir in which the containing file was found. */ + if (skip_dirs) + { + cpp_buffer *fp; + for (fp = CPP_BUFFER (pfile); fp != NULL; fp = CPP_PREV_BUFFER (fp)) + if (fp->fname != NULL) + { + /* fp->dir is null if the containing file was specified with + an absolute file name. In that case, don't skip anything. */ + if (fp->dir == SELF_DIR_DUMMY) + search_start = CPP_OPTIONS (pfile)->include; + else if (fp->dir) + search_start = fp->dir->next; + break; + } + } + + CPP_SET_WRITTEN (pfile, old_written); + + flen = fend - fbeg; + + if (flen == 0) + { + cpp_error (pfile, "empty file name in `#%s'", keyword->name); + return 0; + } + + /* Allocate this permanently, because it gets stored in the definitions + of macros. */ + fname = (char *) xmalloc (pfile->max_include_len + flen + 4); + /* + 2 above for slash and terminating null. */ + /* + 2 added for '.h' on VMS (to support '#include filename') */ + + /* If specified file name is absolute, just open it. */ + + if (*fbeg == '/') { + strncpy (fname, fbeg, flen); + fname[flen] = 0; + if (redundant_include_p (pfile, fname)) + return 0; + if (importing) + f = lookup_import (pfile, fname, NULL_PTR); + else + f = open_include_file (pfile, fname, NULL_PTR); + if (f == -2) + return 0; /* Already included this file */ + } else { + /* Search directory path, trying to open the file. + Copy each filename tried into FNAME. */ + + for (searchptr = search_start; searchptr; searchptr = searchptr->next) { + if (searchptr->fname) { + /* The empty string in a search path is ignored. + This makes it possible to turn off entirely + a standard piece of the list. */ + if (searchptr->fname[0] == 0) + continue; + strcpy (fname, searchptr->fname); + strcat (fname, "/"); + fname[strlen (fname) + flen] = 0; + } else { + fname[0] = 0; + } + strncat (fname, fbeg, flen); +#ifdef VMS + /* Change this 1/2 Unix 1/2 VMS file specification into a + full VMS file specification */ + if (searchptr->fname && (searchptr->fname[0] != 0)) { + /* Fix up the filename */ + hack_vms_include_specification (fname); + } else { + /* This is a normal VMS filespec, so use it unchanged. */ + strncpy (fname, fbeg, flen); + fname[flen] = 0; + /* if it's '#include filename', add the missing .h */ + if (index(fname,'.')==NULL) { + strcat (fname, ".h"); + } + } +#endif /* VMS */ + /* ??? There are currently 3 separate mechanisms for avoiding processing + of redundant include files: #import, #pragma once, and + redundant_include_p. It would be nice if they were unified. */ + if (redundant_include_p (pfile, fname)) + return 0; + if (importing) + f = lookup_import (pfile, fname, searchptr); + else + f = open_include_file (pfile, fname, searchptr); + if (f == -2) + return 0; /* Already included this file */ +#ifdef EACCES + else if (f == -1 && errno == EACCES) + cpp_warning (pfile, "Header file %s exists, but is not readable", + fname); +#endif + if (f >= 0) + break; + } + } + + if (f < 0) + { + /* A file that was not found. */ + strncpy (fname, fbeg, flen); + fname[flen] = 0; + /* If generating dependencies and -MG was specified, we assume missing + files are leaf files, living in the same directory as the source file + or other similar place; these missing files may be generated from + other files and may not exist yet (eg: y.tab.h). */ + + if (CPP_OPTIONS(pfile)->print_deps_missing_files + && CPP_PRINT_DEPS (pfile) + > (angle_brackets || (pfile->system_include_depth > 0))) + { + /* If it was requested as a system header file, + then assume it belongs in the first place to look for such. */ + if (angle_brackets) + { + for (searchptr = search_start; searchptr; + searchptr = searchptr->next) + { + if (searchptr->fname) + { + char *p; + + if (searchptr->fname[0] == 0) + continue; + p = (char *) alloca (strlen (searchptr->fname) + + strlen (fname) + 2); + strcpy (p, searchptr->fname); + strcat (p, "/"); + strcat (p, fname); + deps_output (pfile, p, ' '); + break; + } + } + } + else + { + /* Otherwise, omit the directory, as if the file existed + in the directory with the source. */ + deps_output (pfile, fname, ' '); + } + } + /* If -M was specified, and this header file won't be added to the + dependency list, then don't count this as an error, because we can + still produce correct output. Otherwise, we can't produce correct + output, because there may be dependencies we need inside the missing + file, and we don't know what directory this missing file exists in.*/ + else if (CPP_PRINT_DEPS (pfile) + && (CPP_PRINT_DEPS (pfile) + <= (angle_brackets || (pfile->system_include_depth > 0)))) + cpp_warning (pfile, "No include path in which to find %s", fname); + else if (search_start) + cpp_error_from_errno (pfile, fname); + else + cpp_error (pfile, "No include path in which to find %s", fname); + } + else { + /* Check to see if this include file is a once-only include file. + If so, give up. */ + + struct file_name_list* ptr; + + for (ptr = pfile->dont_repeat_files; ptr; ptr = ptr->next) { + if (!strcmp (ptr->fname, fname)) { + close (f); + return 0; /* This file was once'd. */ + } + } + + for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) { + if (!strcmp (ptr->fname, fname)) + break; /* This file was included before. */ + } + + if (ptr == 0) { + /* This is the first time for this file. */ + /* Add it to list of files included. */ + + ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + ptr->control_macro = 0; + ptr->c_system_include_path = 0; + ptr->next = pfile->all_include_files; + pfile->all_include_files = ptr; + ptr->fname = savestring (fname); + ptr->got_name_map = 0; + + /* For -M, add this file to the dependencies. */ + if (CPP_PRINT_DEPS (pfile) + > (angle_brackets || (pfile->system_include_depth > 0))) + deps_output (pfile, fname, ' '); + } + + /* Handle -H option. */ + if (CPP_OPTIONS(pfile)->print_include_names) + { + cpp_buffer *buf = CPP_BUFFER (pfile); + while ((buf = CPP_PREV_BUFFER (buf)) != NULL) + putc ('.', stderr); + fprintf (stderr, "%s\n", fname); + } + + if (angle_brackets) + pfile->system_include_depth++; + + /* Actually process the file. */ + + /* Record file on "seen" list for #import. */ + add_import (pfile, f, fname); + + pcftry = (char *) alloca (strlen (fname) + 30); + pcfbuf = 0; + pcfnum = 0; + +#if 0 + if (!no_precomp) + { + struct stat stat_f; + + fstat (f, &stat_f); + + do { + sprintf (pcftry, "%s%d", fname, pcfnum++); + + pcf = open (pcftry, O_RDONLY, 0666); + if (pcf != -1) + { + struct stat s; + + fstat (pcf, &s); + if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino, + sizeof (s.st_ino)) + || stat_f.st_dev != s.st_dev) + { + pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit); + /* Don't need it any more. */ + close (pcf); + } + else + { + /* Don't need it at all. */ + close (pcf); + break; + } + } + } while (pcf != -1 && !pcfbuf); + } +#endif + + /* Actually process the file */ + cpp_push_buffer (pfile, NULL, 0); + if (finclude (pfile, f, fname, is_system_include (pfile, fname), + searchptr != dsp ? searchptr : SELF_DIR_DUMMY)) + { + output_line_command (pfile, 0, enter_file); + pfile->only_seen_white = 2; + } + + if (angle_brackets) + pfile->system_include_depth--; + } + return 0; +} + +/* Return nonzero if there is no need to include file NAME + because it has already been included and it contains a conditional + to make a repeated include do nothing. */ + +static int +redundant_include_p (pfile, name) + cpp_reader *pfile; + char *name; +{ + struct file_name_list *l = pfile->all_include_files; + for (; l; l = l->next) + if (! strcmp (name, l->fname) + && l->control_macro + && cpp_lookup (pfile, l->control_macro, -1, -1)) + return 1; + return 0; +} + +/* Return nonzero if the given FILENAME is an absolute pathname which + designates a file within one of the known "system" include file + directories. We assume here that if the given FILENAME looks like + it is the name of a file which resides either directly in a "system" + include file directory, or within any subdirectory thereof, then the + given file must be a "system" include file. This function tells us + if we should suppress pedantic errors/warnings for the given FILENAME. + + The value is 2 if the file is a C-language system header file + for which C++ should (on most systems) assume `extern "C"'. */ + +static int +is_system_include (pfile, filename) + cpp_reader *pfile; + register char *filename; +{ + struct file_name_list *searchptr; + + for (searchptr = CPP_OPTIONS (pfile)->first_system_include; searchptr; + searchptr = searchptr->next) + if (searchptr->fname) { + register char *sys_dir = searchptr->fname; + register unsigned length = strlen (sys_dir); + + if (! strncmp (sys_dir, filename, length) && filename[length] == '/') + { + if (searchptr->c_system_include_path) + return 2; + else + return 1; + } + } + return 0; +} + + +/* + * Install a name in the assertion hash table. + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ +static ASSERTION_HASHNODE * +assertion_install (pfile, name, len, hash) + cpp_reader *pfile; + U_CHAR *name; + int len; + int hash; +{ + register ASSERTION_HASHNODE *hp; + register int i, bucket; + register U_CHAR *p, *q; + + i = sizeof (ASSERTION_HASHNODE) + len + 1; + hp = (ASSERTION_HASHNODE *) xmalloc (i); + bucket = hash; + hp->bucket_hdr = &pfile->assertion_hashtab[bucket]; + hp->next = pfile->assertion_hashtab[bucket]; + pfile->assertion_hashtab[bucket] = hp; + hp->prev = NULL; + if (hp->next != NULL) + hp->next->prev = hp; + hp->length = len; + hp->value = 0; + hp->name = ((U_CHAR *) hp) + sizeof (ASSERTION_HASHNODE); + p = hp->name; + q = name; + for (i = 0; i < len; i++) + *p++ = *q++; + hp->name[len] = 0; + return hp; +} +/* + * find the most recent hash node for name name (ending with first + * non-identifier char) installed by install + * + * If LEN is >= 0, it is the length of the name. + * Otherwise, compute the length by scanning the entire name. + * + * If HASH is >= 0, it is the precomputed hash code. + * Otherwise, compute the hash code. + */ + +static ASSERTION_HASHNODE * +assertion_lookup (pfile, name, len, hash) + cpp_reader *pfile; + U_CHAR *name; + int len; + int hash; +{ + register ASSERTION_HASHNODE *bucket; + + bucket = pfile->assertion_hashtab[hash]; + while (bucket) { + if (bucket->length == len && strncmp (bucket->name, name, len) == 0) + return bucket; + bucket = bucket->next; + } + return NULL; +} + +static void +delete_assertion (hp) + ASSERTION_HASHNODE *hp; +{ + struct tokenlist_list *tail; + if (hp->prev != NULL) + hp->prev->next = hp->next; + if (hp->next != NULL) + hp->next->prev = hp->prev; + + for (tail = hp->value; tail; ) + { + struct tokenlist_list *next = tail->next; + free_token_list (tail->tokens); + free (tail); + tail = next; + } + + /* make sure that the bucket chain header that + the deleted guy was on points to the right thing afterwards. */ + if (hp == *hp->bucket_hdr) + *hp->bucket_hdr = hp->next; + + free (hp); +} + +/* Convert a character string literal into a nul-terminated string. + The input string is [IN ... LIMIT). + The result is placed in RESULT. RESULT can be the same as IN. + The value returned in the end of the string written to RESULT, + or NULL on error. */ + +static U_CHAR* +convert_string (pfile, result, in, limit, handle_escapes) + cpp_reader *pfile; + register U_CHAR *result, *in, *limit; + int handle_escapes; +{ + U_CHAR c; + c = *in++; + if (c != '\"') + return NULL; + while (in < limit) + { + U_CHAR c = *in++; + switch (c) + { + case '\0': + return NULL; + case '\"': + limit = in; + break; + case '\\': + if (handle_escapes) + { + char *bpc = (char *) in; + int i = (U_CHAR) cpp_parse_escape (pfile, &bpc); + in = (U_CHAR *) bpc; + if (i >= 0) + *result++ = (U_CHAR)c; + break; + } + /* else fall through */ + default: + *result++ = c; + } + } + *result = 0; + return result; +} + +/* + * interpret #line command. Remembers previously seen fnames + * in its very own hash table. + */ +#define FNAME_HASHSIZE 37 + +static int +do_line (pfile, keyword) + cpp_reader *pfile; + struct directive *keyword; +{ + cpp_buffer *ip = CPP_BUFFER (pfile); + int new_lineno; + long old_written = CPP_WRITTEN (pfile); + enum file_change_code file_change = same_file; + enum cpp_token token; + int i; + + token = get_directive_token (pfile); + + if (token != CPP_NUMBER + || !isdigit(pfile->token_buffer[old_written])) + { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } + + /* The Newline at the end of this line remains to be processed. + To put the next line at the specified line number, + we must store a line number now that is one less. */ + new_lineno = atoi (pfile->token_buffer + old_written) - 1; + CPP_SET_WRITTEN (pfile, old_written); + + /* NEW_LINENO is one less than the actual line number here. */ + if (CPP_PEDANTIC (pfile) && new_lineno < 0) + cpp_pedwarn (pfile, "line number out of range in `#line' command"); + +#if 0 /* #line 10"foo.c" is supposed to be allowed. */ + if (PEEKC() && !is_space[PEEKC()]) { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } +#endif + + token = get_directive_token (pfile); + + if (token == CPP_STRING) { + U_CHAR *fname = pfile->token_buffer + old_written; + U_CHAR *end_name; + static HASHNODE *fname_table[FNAME_HASHSIZE]; + HASHNODE *hp, **hash_bucket; + U_CHAR *p; + long num_start; + int fname_length; + + /* Turn the file name, which is a character string literal, + into a null-terminated string. Do this in place. */ + end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1); + if (end_name == NULL) + { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } + + fname_length = end_name - fname; + + num_start = CPP_WRITTEN (pfile); + token = get_directive_token (pfile); + if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) { + p = pfile->token_buffer + num_start; + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "garbage at end of `#line' command"); + + if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0') + { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } + if (*p == '1') + file_change = enter_file; + else if (*p == 2) + file_change = leave_file; + else if (*p == 3) + ip->system_header_p = 1; + else /* if (*p == 4) */ + ip->system_header_p = 2; + + CPP_SET_WRITTEN (pfile, num_start); + token = get_directive_token (pfile); + p = pfile->token_buffer + num_start; + if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) { + ip->system_header_p = *p == 3 ? 1 : 2; + token = get_directive_token (pfile); + } + if (token != CPP_VSPACE) { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } + } + + hash_bucket = + &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)]; + for (hp = *hash_bucket; hp != NULL; hp = hp->next) + if (hp->length == fname_length && + strncmp (hp->value.cpval, fname, fname_length) == 0) { + ip->nominal_fname = hp->value.cpval; + break; + } + if (hp == 0) { + /* Didn't find it; cons up a new one. */ + hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1); + hp->next = *hash_bucket; + *hash_bucket = hp; + + hp->length = fname_length; + ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE); + bcopy (fname, hp->value.cpval, fname_length); + } + } + else if (token != CPP_VSPACE && token != CPP_EOF) { + cpp_error (pfile, "invalid format `#line' command"); + goto bad_line_directive; + } + + ip->lineno = new_lineno; + bad_line_directive: + skip_rest_of_line (pfile); + CPP_SET_WRITTEN (pfile, old_written); + output_line_command (pfile, 0, file_change); + return 0; +} + +/* + * remove the definition of a symbol from the symbol table. + * according to un*x /lib/cpp, it is not an error to undef + * something that has no definitions, so it isn't one here either. + */ + +static int +do_undef (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + int sym_length; + HASHNODE *hp; + U_CHAR *orig_buf = buf; + +#if 0 + /* If this is a precompiler run (with -pcp) pass thru #undef commands. */ + if (pcp_outfile && keyword) + pass_thru_directive (buf, limit, pfile, keyword); +#endif + + SKIP_WHITE_SPACE (buf); + sym_length = check_macro_name (pfile, buf, "macro"); + + while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL) + { + /* If we are generating additional info for debugging (with -g) we + need to pass through all effective #undef commands. */ + if (CPP_OPTIONS (pfile)->debug_output && keyword) + pass_thru_directive (orig_buf, limit, pfile, keyword); + if (hp->type != T_MACRO) + cpp_warning (pfile, "undefining `%s'", hp->name); + delete_macro (hp); + } + + if (CPP_PEDANTIC (pfile)) { + buf += sym_length; + SKIP_WHITE_SPACE (buf); + if (buf != limit) + cpp_pedwarn (pfile, "garbage after `#undef' directive"); + } + return 0; +} + +/* + * Report an error detected by the program we are processing. + * Use the text of the line in the error message. + * (We use error because it prints the filename & line#.) + */ + +static int +do_error (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + int length = limit - buf; + U_CHAR *copy = (U_CHAR *) xmalloc (length + 1); + bcopy (buf, copy, length); + copy[length] = 0; + SKIP_WHITE_SPACE (copy); + cpp_error (pfile, "#error %s", copy); + return 0; +} + +/* + * Report a warning detected by the program we are processing. + * Use the text of the line in the warning message, then continue. + * (We use error because it prints the filename & line#.) + */ + +static int +do_warning (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + int length = limit - buf; + U_CHAR *copy = (U_CHAR *) xmalloc (length + 1); + bcopy (buf, copy, length); + copy[length] = 0; + SKIP_WHITE_SPACE (copy); + cpp_warning (pfile, "#warning %s", copy); + return 0; +} + +/* Remember the name of the current file being read from so that we can + avoid ever including it again. */ + +static int +do_once (pfile) + cpp_reader *pfile; +{ + cpp_buffer *ip = NULL; + struct file_name_list *new; + + for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip)) + { + if (ip == NULL) + return 0; + if (ip->fname != NULL) + break; + } + + + new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + new->next = pfile->dont_repeat_files; + pfile->dont_repeat_files = new; + new->fname = savestring (ip->fname); + new->control_macro = 0; + new->got_name_map = 0; + new->c_system_include_path = 0; + + return 0; +} + +/* #ident has already been copied to the output file, so just ignore it. */ + +static int +do_ident (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ +/* long old_written = CPP_WRITTEN (pfile);*/ + int len; + + /* Allow #ident in system headers, since that's not user's fault. */ + if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p) + cpp_pedwarn (pfile, "ANSI C does not allow `#ident'"); + + /* Leave rest of line to be read by later calls to cpp_get_token. */ + + return 0; +} + +/* #pragma and its argument line have already been copied to the output file. + Just check for some recognized pragmas that need validation here. */ + +static int +do_pragma (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + while (*buf == ' ' || *buf == '\t') + buf++; + if (!strncmp (buf, "once", 4)) { + /* Allow #pragma once in system headers, since that's not the user's + fault. */ + if (!CPP_BUFFER (pfile)->system_header_p) + cpp_warning (pfile, "`#pragma once' is obsolete"); + do_once (pfile); + } + + if (!strncmp (buf, "implementation", 14)) { + /* Be quiet about `#pragma implementation' for a file only if it hasn't + been included yet. */ + struct file_name_list *ptr; + U_CHAR *p = buf + 14, *fname, *inc_fname; + int fname_len; + SKIP_WHITE_SPACE (p); + if (*p == '\n' || *p != '\"') + return 0; + + fname = p + 1; + p = (U_CHAR *) index (fname, '\"'); + fname_len = p != NULL ? p - fname : strlen (fname); + + for (ptr = pfile->all_include_files; ptr; ptr = ptr->next) { + inc_fname = (U_CHAR *) rindex (ptr->fname, '/'); + inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname; + if (inc_fname && !strncmp (inc_fname, fname, fname_len)) + cpp_warning (pfile, + "`#pragma implementation' for `%s' appears after file is included", + fname); + } + } + + return 0; +} + +#if 0 +/* This was a fun hack, but #pragma seems to start to be useful. + By failing to recognize it, we pass it through unchanged to cc1. */ + +/* + * the behavior of the #pragma directive is implementation defined. + * this implementation defines it as follows. + */ + +static int +do_pragma () +{ + close (0); + if (open ("/dev/tty", O_RDONLY, 0666) != 0) + goto nope; + close (1); + if (open ("/dev/tty", O_WRONLY, 0666) != 1) + goto nope; + execl ("/usr/games/hack", "#pragma", 0); + execl ("/usr/games/rogue", "#pragma", 0); + execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0); + execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0); +nope: + fatal ("You are in a maze of twisty compiler features, all different"); +} +#endif + +/* Just ignore #sccs, on systems where we define it at all. */ + +static int +do_sccs (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + if (CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'"); + return 0; +} + +/* + * handle #if command by + * 1) inserting special `defined' keyword into the hash table + * that gets turned into 0 or 1 by special_symbol (thus, + * if the luser has a symbol called `defined' already, it won't + * work inside the #if command) + * 2) rescan the input into a temporary output buffer + * 3) pass the output buffer to the yacc parser and collect a value + * 4) clean up the mess left from steps 1 and 2. + * 5) call conditional_skip to skip til the next #endif (etc.), + * or not, depending on the value from step 3. + */ + +static int +do_if (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf); + conditional_skip (pfile, value == 0, T_IF, NULL_PTR); + return 0; +} + +/* + * handle a #elif directive by not changing if_stack either. + * see the comment above do_else. + */ + +static int +do_elif (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) { + cpp_error (pfile, "`#elif' not within a conditional"); + return 0; + } else { + if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) { + cpp_error (pfile, "`#elif' after `#else'"); +#if 0 + fprintf (stderr, " (matches line %d", pfile->if_stack->lineno); +#endif + if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL + && strcmp (pfile->if_stack->fname, + CPP_BUFFER (pfile)->nominal_fname) != 0) + fprintf (stderr, ", file %s", pfile->if_stack->fname); + fprintf (stderr, ")\n"); + } + pfile->if_stack->type = T_ELIF; + } + + if (pfile->if_stack->if_succeeded) + skip_if_group (pfile, 0); + else { + HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf); + if (value == 0) + skip_if_group (pfile, 0); + else { + ++pfile->if_stack->if_succeeded; /* continue processing input */ + output_line_command (pfile, 1, same_file); + } + } + return 0; +} + +/* + * evaluate a #if expression in BUF, of length LENGTH, + * then parse the result as a C expression and return the value as an int. + */ +static HOST_WIDE_INT +eval_if_expression (pfile, buf, length) + cpp_reader *pfile; + U_CHAR *buf; + int length; +{ + HASHNODE *save_defined; + HOST_WIDE_INT value; + long old_written = CPP_WRITTEN (pfile); + + save_defined = install ("defined", -1, T_SPEC_DEFINED, 0, 0, -1); + pfile->pcp_inside_if = 1; + + value = cpp_parse_expr (pfile); + pfile->pcp_inside_if = 0; + delete_macro (save_defined); /* clean up special symbol */ + + CPP_SET_WRITTEN (pfile, old_written); /* Pop */ + + return value; +} + +/* + * routine to handle ifdef/ifndef. Try to look up the symbol, + * then do or don't skip to the #endif/#else/#elif depending + * on what directive is actually being processed. + */ + +static int +do_xifdef (pfile, keyword, unused1, unused2) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *unused1, *unused2; +{ + int skip; + cpp_buffer *ip = CPP_BUFFER (pfile); + U_CHAR* ident; + int ident_length; + enum cpp_token token; + int start_of_file = 0; + U_CHAR *control_macro = 0; + int old_written = CPP_WRITTEN (pfile); + + /* Detect a #ifndef at start of file (not counting comments). */ + if (ip->fname != 0 && keyword->type == T_IFNDEF) + start_of_file = pfile->only_seen_white == 2; + + pfile->no_macro_expand++; + token = get_directive_token (pfile); + pfile->no_macro_expand--; + + ident = pfile->token_buffer + old_written; + ident_length = CPP_WRITTEN (pfile) - old_written; + CPP_SET_WRITTEN (pfile, old_written); /* Pop */ + + if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF) + { + skip = (keyword->type == T_IFDEF); + if (! CPP_TRADITIONAL (pfile)) + cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name); + } + else if (token == CPP_NAME) + { + HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1); + skip = (hp == NULL) ^ (keyword->type == T_IFNDEF); + if (start_of_file && !skip) + { + control_macro = (U_CHAR *) xmalloc (ident_length + 1); + bcopy (ident, control_macro, ident_length + 1); + } + } + else + { + skip = (keyword->type == T_IFDEF); + if (! CPP_TRADITIONAL (pfile)) + cpp_error (pfile, "`#%s' with invalid argument", keyword->name); + } + + if (!CPP_TRADITIONAL (pfile)) + { int c; + cpp_skip_hspace (pfile); + c = PEEKC (); + if (c != EOF && c != '\n') + cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name); + } + skip_rest_of_line (pfile); + +#if 0 + if (pcp_outfile) { + /* Output a precondition for this macro. */ + if (hp && hp->value.defn->predefined) + fprintf (pcp_outfile, "#define %s\n", hp->name); + else { + U_CHAR *cp = buf; + fprintf (pcp_outfile, "#undef "); + while (is_idchar[*cp]) /* Ick! */ + fputc (*cp++, pcp_outfile); + putc ('\n', pcp_outfile); + } +#endif + + conditional_skip (pfile, skip, T_IF, control_macro); + return 0; +} + +/* Push TYPE on stack; then, if SKIP is nonzero, skip ahead. + If this is a #ifndef starting at the beginning of a file, + CONTROL_MACRO is the macro name tested by the #ifndef. + Otherwise, CONTROL_MACRO is 0. */ + +static void +conditional_skip (pfile, skip, type, control_macro) + cpp_reader *pfile; + int skip; + enum node_type type; + U_CHAR *control_macro; +{ + IF_STACK_FRAME *temp; + + temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME)); + temp->fname = CPP_BUFFER (pfile)->nominal_fname; +#if 0 + temp->lineno = CPP_BUFFER (pfile)->lineno; +#endif + temp->next = pfile->if_stack; + temp->control_macro = control_macro; + pfile->if_stack = temp; + + pfile->if_stack->type = type; + + if (skip != 0) { + skip_if_group (pfile, 0); + return; + } else { + ++pfile->if_stack->if_succeeded; + output_line_command (pfile, 1, same_file); + } +} + +/* + * skip to #endif, #else, or #elif. adjust line numbers, etc. + * leaves input ptr at the sharp sign found. + * If ANY is nonzero, return at next directive of any sort. + */ +static void +skip_if_group (pfile, any) + cpp_reader *pfile; + int any; +{ + int c; + int at_beg_of_line = 1; + struct directive *kt; + IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */ +#if 0 + U_CHAR *beg_of_line = bp; +#endif + register int ident_length; + U_CHAR *ident, *after_ident; + struct parse_marker line_start_mark; + + parse_set_mark (&line_start_mark, pfile); + + if (CPP_OPTIONS (pfile)->output_conditionals) { + static char failed[] = "#failed\n"; + CPP_PUTS (pfile, failed, sizeof(failed)-1); + pfile->lineno++; + output_line_command (pfile, 1, same_file); + } + + beg_of_line: + if (CPP_OPTIONS (pfile)->output_conditionals) + { + cpp_buffer *pbuf = CPP_BUFFER (pfile); + U_CHAR *start_line = pbuf->buf + line_start_mark.position; + CPP_PUTS (pfile, start_line, pbuf->cur - start_line); + } + parse_move_mark (&line_start_mark, pfile); + if (!CPP_TRADITIONAL (pfile)) + cpp_skip_hspace (pfile); + c = GETC(); + if (c == '#') + { + int old_written = CPP_WRITTEN (pfile); + cpp_skip_hspace (pfile); + + parse_name (pfile, GETC()); + ident_length = CPP_WRITTEN (pfile) - old_written; + ident = pfile->token_buffer + old_written; + pfile->limit = ident; +#if 0 + if (ident_length == 0) + goto not_a_directive; + + /* Handle # followed by a line number. */ + + /* Avoid error for `###' and similar cases unless -pedantic. */ +#endif + + for (kt = directive_table; kt->length >= 0; kt++) + { + IF_STACK_FRAME *temp; + if (ident_length == kt->length + && strncmp (ident, kt->name, kt->length) == 0) + { + /* If we are asked to return on next directive, do so now. */ + if (any) + goto done; + + switch (kt->type) + { + case T_IF: + case T_IFDEF: + case T_IFNDEF: + temp + = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME)); + temp->next = pfile->if_stack; + pfile->if_stack = temp; +#if 0 + temp->lineno = CPP_BUFFER(pfile)->lineno; +#endif + temp->fname = CPP_BUFFER(pfile)->nominal_fname; + temp->type = kt->type; + break; + case T_ELSE: + case T_ENDIF: + if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack) + validate_else (pfile, + kt->type == T_ELSE ? "#else" : "#endif"); + case T_ELIF: + if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) + { + cpp_error (pfile, + "`#%s' not within a conditional", kt->name); + break; + } + else if (pfile->if_stack == save_if_stack) + goto done; /* found what we came for */ + + if (kt->type != T_ENDIF) + { + if (pfile->if_stack->type == T_ELSE) + cpp_error (pfile, "`#else' or `#elif' after `#else'"); + pfile->if_stack->type = kt->type; + break; + } + + temp = pfile->if_stack; + pfile->if_stack = temp->next; + free (temp); + break; + default: ; + } + break; + } + /* Don't let erroneous code go by. */ + if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm + && CPP_PEDANTIC (pfile)) + cpp_pedwarn (pfile, "invalid preprocessor directive name"); + } + c = GETC (); + } + /* We're in the middle of a line. Skip the rest of it. */ + for (;;) { + switch (c) + { + long old; + case EOF: + goto done; + case '/': /* possible comment */ + c = skip_comment (pfile, NULL); + if (c == EOF) + goto done; + break; + case '\"': + case '\'': + FORWARD(-1); + old = CPP_WRITTEN (pfile); + cpp_get_token (pfile); + CPP_SET_WRITTEN (pfile, old); + break; + case '\\': + /* Char after backslash loses its special meaning. */ + if (PEEKC() == '\n') + FORWARD (1); + break; + case '\n': + goto beg_of_line; + break; + } + c = GETC (); + } + done: + if (CPP_OPTIONS (pfile)->output_conditionals) { + static char end_failed[] = "#endfailed\n"; + CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1); + pfile->lineno++; + } + pfile->only_seen_white = 1; + parse_goto_mark (&line_start_mark, pfile); + parse_clear_mark (&line_start_mark); +} + +/* + * handle a #else directive. Do this by just continuing processing + * without changing if_stack ; this is so that the error message + * for missing #endif's etc. will point to the original #if. It + * is possible that something different would be better. + */ + +static int +do_else (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + cpp_buffer *ip = CPP_BUFFER (pfile); + + if (CPP_PEDANTIC (pfile)) + validate_else (pfile, "#else"); + skip_rest_of_line (pfile); + + if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) { + cpp_error (pfile, "`#else' not within a conditional"); + return 0; + } else { + /* #ifndef can't have its special treatment for containing the whole file + if it has a #else clause. */ + pfile->if_stack->control_macro = 0; + + if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) { + cpp_error (pfile, "`#else' after `#else'"); + fprintf (stderr, " (matches line %d", pfile->if_stack->lineno); + if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0) + fprintf (stderr, ", file %s", pfile->if_stack->fname); + fprintf (stderr, ")\n"); + } + pfile->if_stack->type = T_ELSE; + } + + if (pfile->if_stack->if_succeeded) + skip_if_group (pfile, 0); + else { + ++pfile->if_stack->if_succeeded; /* continue processing input */ + output_line_command (pfile, 1, same_file); + } + return 0; +} + +/* + * unstack after #endif command + */ + +static int +do_endif (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + if (CPP_PEDANTIC (pfile)) + validate_else (pfile, "#endif"); + skip_rest_of_line (pfile); + + if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) + cpp_error (pfile, "unbalanced `#endif'"); + else + { + IF_STACK_FRAME *temp = pfile->if_stack; + pfile->if_stack = temp->next; + if (temp->control_macro != 0) + { + /* This #endif matched a #ifndef at the start of the file. + See if it is at the end of the file. */ + struct parse_marker start_mark; + int c; + + parse_set_mark (&start_mark, pfile); + + for (;;) + { + cpp_skip_hspace (pfile); + c = GETC (); + if (c != '\n') + break; + } + parse_goto_mark (&start_mark, pfile); + parse_clear_mark (&start_mark); + + if (c == EOF) + { + /* If we get here, this #endif ends a #ifndef + that contains all of the file (aside from whitespace). + Arrange not to include the file again + if the macro that was tested is defined. + + Do not do this for the top-level file in a -include or any + file in a -imacros. */ +#if 0 +FIXME! + if (indepth != 0 + && ! (indepth == 1 && pfile->no_record_file) + && ! (pfile->no_record_file && no_output)) +#endif + { + struct file_name_list *ifile = pfile->all_include_files; + + for ( ; ifile != NULL; ifile = ifile->next) + { + if (!strcmp (ifile->fname, CPP_BUFFER (pfile)->fname)) + { + ifile->control_macro = temp->control_macro; + break; + } + } + } + } + } + free (temp); + output_line_command (pfile, 1, same_file); + } + return 0; +} + +/* When an #else or #endif is found while skipping failed conditional, + if -pedantic was specified, this is called to warn about text after + the command name. P points to the first char after the command name. */ + +static void +validate_else (pfile, directive) + cpp_reader *pfile; + char *directive; +{ + int c; + cpp_skip_hspace (pfile); + c = PEEKC (); + if (c != EOF && c != '\n') + cpp_pedwarn (pfile, + "text following `%s' violates ANSI standard", directive); +} + +/* Get the next token, and add it to the text in pfile->token_buffer. + Return the kind of token we got. */ + + +enum cpp_token +cpp_get_token (pfile) + cpp_reader *pfile; +{ + register int c, c2, c3; + long old_written; + long start_line, start_column; + enum cpp_token token; + struct cpp_options *opts = CPP_OPTIONS (pfile); + CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur; + get_next: + c = GETC(); + if (c == EOF) + { + handle_eof: + if (CPP_BUFFER (pfile)->seen_eof) + { + if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile)) + goto get_next; + else + return CPP_EOF; + } + else + { + cpp_buffer *next_buf + = CPP_PREV_BUFFER (CPP_BUFFER (pfile)); + CPP_BUFFER (pfile)->seen_eof = 1; + if (CPP_BUFFER (pfile)->nominal_fname && next_buf != 0) + { + /* We're about to return from an #include file. + Emit #line information now (as part of the CPP_POP) result. + But the #line refers to the file we will pop to. */ + cpp_buffer *cur_buffer = CPP_BUFFER (pfile); + CPP_BUFFER (pfile) = next_buf; + pfile->input_stack_listing_current = 0; + output_line_command (pfile, 0, leave_file); + CPP_BUFFER (pfile) = cur_buffer; + } + return CPP_POP; + } + } + else + { + switch (c) + { + long newlines; + struct parse_marker start_mark; + case '/': + if (PEEKC () == '=') + goto op2; + if (opts->put_out_comments) + parse_set_mark (&start_mark, pfile); + newlines = 0; + cpp_buf_line_and_col (cpp_file_buffer (pfile), + &start_line, &start_column); + c = skip_comment (pfile, &newlines); + if (opts->put_out_comments && (c == '/' || c == EOF)) + parse_clear_mark (&start_mark); + if (c == '/') + goto randomchar; + if (c == EOF) + { + cpp_error_with_line (pfile, start_line, start_column, + "unterminated comment"); + goto handle_eof; + } + c = '/'; /* Initial letter of comment. */ + return_comment: + /* Comments are equivalent to spaces. + For -traditional, a comment is equivalent to nothing. */ + if (opts->put_out_comments) + { + cpp_buffer *pbuf = CPP_BUFFER (pfile); + long dummy; + U_CHAR *start = pbuf->buf + start_mark.position; + int len = pbuf->cur - start; + CPP_RESERVE(pfile, 1 + len); + CPP_PUTC_Q (pfile, c); + CPP_PUTS_Q (pfile, start, len); + pfile->lineno += newlines; + parse_clear_mark (&start_mark); + return CPP_COMMENT; + } + else if (CPP_TRADITIONAL (pfile)) + { + return CPP_COMMENT; + } + else + { +#if 0 + /* This may not work if cpp_get_token is called recursively, + since many places look for horizontal space. */ + if (newlines) + { + /* Copy the newlines into the output buffer, in order to + avoid the pain of a #line every time a multiline comment + is seen. */ + CPP_RESERVE(pfile, newlines); + while (--newlines >= 0) + { + CPP_PUTC_Q (pfile, '\n'); + pfile->lineno++; + } + return CPP_VSPACE; + } +#endif + CPP_RESERVE(pfile, 1); + CPP_PUTC_Q (pfile, ' '); + return CPP_HSPACE; + } +#if 0 + if (opts->for_lint) { + U_CHAR *argbp; + int cmdlen, arglen; + char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen); + + if (lintcmd != NULL) { + /* I believe it is always safe to emit this newline: */ + obp[-1] = '\n'; + bcopy ("#pragma lint ", (char *) obp, 13); + obp += 13; + bcopy (lintcmd, (char *) obp, cmdlen); + obp += cmdlen; + + if (arglen != 0) { + *(obp++) = ' '; + bcopy (argbp, (char *) obp, arglen); + obp += arglen; + } + + /* OK, now bring us back to the state we were in before we entered + this branch. We need #line b/c the newline for the pragma + could fuck things up. */ + output_line_command (pfile, 0, same_file); + *(obp++) = ' '; /* just in case, if comments are copied thru */ + *(obp++) = '/'; + } + } +#endif + + case '#': +#if 0 + /* If this is expanding a macro definition, don't recognize + preprocessor directives. */ + if (ip->macro != 0) + goto randomchar; + /* If this is expand_into_temp_buffer, recognize them + only after an actual newline at this level, + not at the beginning of the input level. */ + if (ip->fname == 0 && beg_of_line == ip->buf) + goto randomchar; + if (ident_length) + goto specialchar; +#endif + + if (!pfile->only_seen_white) + goto randomchar; + if (handle_directive (pfile)) + return CPP_DIRECTIVE; + pfile->only_seen_white = 0; + return CPP_OTHER; + + case '\"': + case '\'': + /* A single quoted string is treated like a double -- some + programs (e.g., troff) are perverse this way */ + cpp_buf_line_and_col (cpp_file_buffer (pfile), + &start_line, &start_column); + old_written = CPP_WRITTEN (pfile); + string: + CPP_PUTC (pfile, c); + while (1) + { + int cc = GETC(); + if (cc == EOF) + { + if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) + { + /* try harder: this string crosses a macro expansion + boundary. This can happen naturally if -traditional. + Otherwise, only -D can make a macro with an unmatched + quote. */ + cpp_buffer *next_buf + = CPP_PREV_BUFFER (CPP_BUFFER (pfile)); + (*CPP_BUFFER (pfile)->cleanup) + (CPP_BUFFER (pfile), pfile); + CPP_BUFFER (pfile) = next_buf; + continue; + } + if (!CPP_TRADITIONAL (pfile)) + { + cpp_error_with_line (pfile, start_line, start_column, + "unterminated string or character constant"); + if (pfile->multiline_string_line != start_line + && pfile->multiline_string_line != 0) + cpp_error_with_line (pfile, + pfile->multiline_string_line, -1, + "possible real start of unterminated constant"); + pfile->multiline_string_line = 0; + } + break; + } + CPP_PUTC (pfile, cc); + switch (cc) + { + case '\n': + /* Traditionally, end of line ends a string constant with + no error. So exit the loop and record the new line. */ + if (CPP_TRADITIONAL (pfile)) + goto while2end; + if (c == '\'') + { + cpp_error_with_line (pfile, start_line, start_column, + "unterminated character constant"); + goto while2end; + } + if (CPP_PEDANTIC (pfile) + && pfile->multiline_string_line == 0) + { + cpp_pedwarn_with_line (pfile, start_line, start_column, + "string constant runs past end of line"); + } + if (pfile->multiline_string_line == 0) + pfile->multiline_string_line = start_line; + break; + + case '\\': + cc = GETC(); + if (cc == '\n') + { + /* Backslash newline is replaced by nothing at all. */ + CPP_ADJUST_WRITTEN (pfile, -1); + pfile->lineno++; + } + else + { + /* ANSI stupidly requires that in \\ the second \ + is *not* prevented from combining with a newline. */ + NEWLINE_FIX1(cc); + if (cc != EOF) + CPP_PUTC (pfile, cc); + } + break; + + case '\"': + case '\'': + if (cc == c) + goto while2end; + break; + } + } + while2end: + pfile->lineno += count_newlines (pfile->token_buffer + old_written, + CPP_PWRITTEN (pfile)); + pfile->only_seen_white = 0; + return c == '\'' ? CPP_CHAR : CPP_STRING; + + case '$': + if (!opts->dollars_in_ident) + goto randomchar; + goto letter; + + case ':': + if (opts->cplusplus && PEEKC () == ':') + goto op2; + goto randomchar; + + case '&': + case '+': + case '|': + NEWLINE_FIX; + c2 = PEEKC (); + if (c2 == c || c2 == '=') + goto op2; + goto randomchar; + + case '*': + case '!': + case '%': + case '=': + case '^': + NEWLINE_FIX; + if (PEEKC () == '=') + goto op2; + goto randomchar; + + case '-': + NEWLINE_FIX; + c2 = PEEKC (); + if (c2 == '-' && opts->chill) + { + /* Chill style comment */ + if (opts->put_out_comments) + parse_set_mark (&start_mark, pfile); + FORWARD(1); /* Skip second '-'. */ + for (;;) + { + c = GETC (); + if (c == EOF) + break; + if (c == '\n') + { + /* Don't consider final '\n' to be part of comment. */ + FORWARD(-1); + break; + } + } + c = '-'; + goto return_comment; + } + if (c2 == '-' || c2 == '=' || c2 == '>') + goto op2; + goto randomchar; + + case '<': + if (pfile->parsing_include_directive) + { + for (;;) + { + CPP_PUTC (pfile, c); + if (c == '>') + break; + c = GETC (); + NEWLINE_FIX1 (c); + if (c == '\n' || c == EOF) + { + cpp_error (pfile, + "missing '>' in `#include '"); + break; + } + } + return CPP_STRING; + } + /* else fall through */ + case '>': + NEWLINE_FIX; + c2 = PEEKC (); + if (c2 == '=') + goto op2; + if (c2 != c) + goto randomchar; + FORWARD(1); + CPP_RESERVE (pfile, 4); + CPP_PUTC (pfile, c); + CPP_PUTC (pfile, c2); + NEWLINE_FIX; + c3 = PEEKC (); + if (c3 == '=') + CPP_PUTC_Q (pfile, GETC ()); + CPP_NUL_TERMINATE_Q (pfile); + pfile->only_seen_white = 0; + return CPP_OTHER; + + case '@': + if (CPP_BUFFER (pfile)->has_escapes) + { + c = GETC (); + if (c == '-') + { + if (pfile->output_escapes) + CPP_PUTS (pfile, "@-", 2); + parse_name (pfile, GETC ()); + return CPP_NAME; + } + else if (is_space [c]) + { + CPP_RESERVE (pfile, 2); + if (pfile->output_escapes) + CPP_PUTC_Q (pfile, '@'); + CPP_PUTC_Q (pfile, c); + return CPP_HSPACE; + } + } + if (pfile->output_escapes) + { + CPP_PUTS (pfile, "@@", 2); + return CPP_OTHER; + } + goto randomchar; + + case '.': + NEWLINE_FIX; + c2 = PEEKC (); + if (isdigit(c2)) + { + CPP_RESERVE(pfile, 2); + CPP_PUTC_Q (pfile, '.'); + c = GETC (); + goto number; + } + /* FIXME - misses the case "..\\\n." */ + if (c2 == '.' && PEEKN(1) == '.') + { + CPP_RESERVE(pfile, 4); + CPP_PUTC_Q (pfile, '.'); + CPP_PUTC_Q (pfile, '.'); + CPP_PUTC_Q (pfile, '.'); + FORWARD (2); + CPP_NUL_TERMINATE_Q (pfile); + pfile->only_seen_white = 0; + return CPP_3DOTS; + } + goto randomchar; + + op2: + token = CPP_OTHER; + pfile->only_seen_white = 0; + op2any: + CPP_RESERVE(pfile, 3); + CPP_PUTC_Q (pfile, c); + CPP_PUTC_Q (pfile, GETC ()); + CPP_NUL_TERMINATE_Q (pfile); + return token; + + case 'L': + NEWLINE_FIX; + c2 = PEEKC (); + if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile)) + { + CPP_PUTC (pfile, c); + c = GETC (); + goto string; + } + goto letter; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + number: + c2 = '.'; + for (;;) + { + CPP_RESERVE (pfile, 2); + CPP_PUTC_Q (pfile, c); + NEWLINE_FIX; + c = PEEKC (); + if (c == EOF) + break; + if (!is_idchar[c] && c != '.' + && ((c2 != 'e' && c2 != 'E') || (c != '+' && c != '-'))) + break; + FORWARD(1); + c2= c; + } + CPP_NUL_TERMINATE_Q (pfile); + pfile->only_seen_white = 0; + return CPP_NUMBER; + case 'b': case 'c': case 'd': case 'h': case 'o': + case 'B': case 'C': case 'D': case 'H': case 'O': + if (opts->chill && PEEKC () == '\'') + { + pfile->only_seen_white = 0; + CPP_RESERVE (pfile, 2); + CPP_PUTC_Q (pfile, c); + CPP_PUTC_Q (pfile, '\''); + FORWARD(1); + for (;;) + { + c = GETC(); + if (c == EOF) + goto chill_number_eof; + if (!is_idchar[c]) + { + if (c == '\\' && PEEKC() == '\n') + { + FORWARD(2); + continue; + } + break; + } + CPP_PUTC (pfile, c); + } + if (c == '\'') + { + CPP_RESERVE (pfile, 2); + CPP_PUTC_Q (pfile, c); + CPP_NUL_TERMINATE_Q (pfile); + return CPP_STRING; + } + else + { + FORWARD(-1); + chill_number_eof: + CPP_NUL_TERMINATE (pfile); + return CPP_NUMBER; + } + } + else + goto letter; + case '_': + case 'a': case 'e': case 'f': case 'g': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'p': case 'q': + case 'r': case 's': case 't': case 'u': case 'v': case 'w': + case 'x': case 'y': case 'z': + case 'A': case 'E': case 'F': case 'G': case 'I': case 'J': + case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R': + case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'Y': case 'Z': + letter: + { + HASHNODE *hp; + unsigned char *ident; + int before_name_written = CPP_WRITTEN (pfile); + int ident_len; + parse_name (pfile, c); + pfile->only_seen_white = 0; + if (pfile->no_macro_expand) + return CPP_NAME; + ident = pfile->token_buffer + before_name_written; + ident_len = CPP_PWRITTEN (pfile) - ident; + hp = cpp_lookup (pfile, ident, ident_len, -1); + if (!hp) + return CPP_NAME; + if (hp->type == T_DISABLED) + { + if (pfile->output_escapes) + { /* Return "@-IDENT", followed by '\0'. */ + int i; + CPP_RESERVE (pfile, 3); + ident = pfile->token_buffer + before_name_written; + CPP_ADJUST_WRITTEN (pfile, 2); + for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i]; + ident[0] = '@'; + ident[1] = '-'; + } + return CPP_NAME; + } + + /* If macro wants an arglist, verify that a '(' follows. + first skip all whitespace, copying it to the output + after the macro name. Then, if there is no '(', + decide this is not a macro call and leave things that way. */ + if (hp->type == T_MACRO && hp->value.defn->nargs >= 0) + { + struct parse_marker macro_mark; + int is_macro_call; + while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile))) + { + cpp_buffer *next_buf; + cpp_skip_hspace (pfile); + if (PEEKC () != EOF) + break; + next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile)); + (*CPP_BUFFER (pfile)->cleanup) (CPP_BUFFER (pfile), pfile); + CPP_BUFFER (pfile) = next_buf; + } + parse_set_mark (¯o_mark, pfile); + for (;;) + { + cpp_skip_hspace (pfile); + c = PEEKC (); + is_macro_call = c == '('; + if (c != '\n') + break; + FORWARD (1); + } + if (!is_macro_call) + parse_goto_mark (¯o_mark, pfile); + parse_clear_mark (¯o_mark); + if (!is_macro_call) + return CPP_NAME; + } + /* This is now known to be a macro call. */ + + /* it might not actually be a macro. */ + if (hp->type != T_MACRO) { + int xbuf_len; U_CHAR *xbuf; + CPP_SET_WRITTEN (pfile, before_name_written); + special_symbol (hp, pfile); + xbuf_len = CPP_WRITTEN (pfile) - before_name_written; + xbuf = (U_CHAR *) xmalloc (xbuf_len + 1); + CPP_SET_WRITTEN (pfile, before_name_written); + bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1); + push_macro_expansion (pfile, xbuf, xbuf_len, hp); + } + else + { + /* Expand the macro, reading arguments as needed, + and push the expansion on the input stack. */ + macroexpand (pfile, hp); + CPP_SET_WRITTEN (pfile, before_name_written); + } + + /* An extra "@ " is added to the end of a macro expansion + to prevent accidental token pasting. We prefer to avoid + unneeded extra spaces (for the sake of cpp-using tools like + imake). Here we remove the space if it is safe to do so. */ + if (pfile->buffer->rlimit - pfile->buffer->cur >= 3 + && pfile->buffer->rlimit[-2] == '@' + && pfile->buffer->rlimit[-1] == ' ') + { + int c1 = pfile->buffer->rlimit[-3]; + int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile))); + if (c2 == EOF || ! unsafe_chars (c1, c2)) + pfile->buffer->rlimit -= 2; + } + } + goto get_next; + + case ' ': case '\t': case '\v': case '\r': + for (;;) + { + CPP_PUTC (pfile, c); + c = PEEKC (); + if (c == EOF || !is_hor_space[c]) + break; + FORWARD(1); + } + return CPP_HSPACE; + + case '\\': + c2 = PEEKC (); + if (c2 != '\n') + goto randomchar; + token = CPP_HSPACE; + goto op2any; + + case '\n': + CPP_PUTC (pfile, c); + if (pfile->only_seen_white == 0) + pfile->only_seen_white = 1; + pfile->lineno++; + output_line_command (pfile, 1, same_file); + return CPP_VSPACE; + + case '(': token = CPP_LPAREN; goto char1; + case ')': token = CPP_RPAREN; goto char1; + case '{': token = CPP_LBRACE; goto char1; + case '}': token = CPP_RBRACE; goto char1; + case ',': token = CPP_COMMA; goto char1; + case ';': token = CPP_SEMICOLON; goto char1; + + randomchar: + default: + token = CPP_OTHER; + char1: + pfile->only_seen_white = 0; + CPP_PUTC (pfile, c); + return token; + } + } +} + +/* Like cpp_get_token, but skip spaces and comments. */ +enum cpp_token +cpp_get_non_space_token (pfile) + cpp_reader *pfile; +{ + int old_written = CPP_WRITTEN (pfile); + for (;;) + { + enum cpp_token token = cpp_get_token (pfile); + if (token != CPP_COMMENT && token != CPP_POP + && token != CPP_HSPACE && token != CPP_VSPACE) + return token; + CPP_SET_WRITTEN (pfile, old_written); + } +} + +/* Parse an identifier starting with C. */ + +int +parse_name (pfile, c) + cpp_reader *pfile; int c; +{ + for (;;) + { + if (! is_idchar[c]) + { + if (c == '\\' && PEEKC() == '\n') + { + FORWARD(2); + continue; + } + FORWARD (-1); + break; + } + + CPP_RESERVE(pfile, 2); /* One more for final NUL. */ + CPP_PUTC_Q (pfile, c); + c = GETC(); + if (c == EOF) + break; + } + CPP_NUL_TERMINATE_Q (pfile); + return 1; +} + + +/* Maintain and search list of included files, for #import. */ + +/* Hash a file name for import_hash_table. */ + +static int +import_hash (f) + char *f; +{ + int val = 0; + + while (*f) val += *f++; + return (val%IMPORT_HASH_SIZE); +} + +/* Search for file FILENAME in import_hash_table. + Return -2 if found, either a matching name or a matching inode. + Otherwise, open the file and return a file descriptor if successful + or -1 if unsuccessful. */ + +static int +lookup_import (pfile, filename, searchptr) + cpp_reader *pfile; + char *filename; + struct file_name_list *searchptr; +{ + struct import_file *i; + int h; + int hashval; + struct stat sb; + int fd; + + hashval = import_hash (filename); + + /* Attempt to find file in list of already included files */ + i = pfile->import_hash_table[hashval]; + + while (i) { + if (!strcmp (filename, i->name)) + return -2; /* return found */ + i = i->next; + } + /* Open it and try a match on inode/dev */ + fd = open_include_file (pfile, filename, searchptr); + if (fd < 0) + return fd; + fstat (fd, &sb); + for (h = 0; h < IMPORT_HASH_SIZE; h++) { + i = pfile->import_hash_table[h]; + while (i) { + /* Compare the inode and the device. + Supposedly on some systems the inode is not a scalar. */ + if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino)) + && i->dev == sb.st_dev) { + close (fd); + return -2; /* return found */ + } + i = i->next; + } + } + return fd; /* Not found, return open file */ +} + +/* Add the file FNAME, open on descriptor FD, to import_hash_table. */ + +static void +add_import (pfile, fd, fname) + cpp_reader *pfile; + int fd; + char *fname; +{ + struct import_file *i; + int hashval; + struct stat sb; + + hashval = import_hash (fname); + fstat (fd, &sb); + i = (struct import_file *)xmalloc (sizeof (struct import_file)); + i->name = (char *)xmalloc (strlen (fname)+1); + strcpy (i->name, fname); + bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino)); + i->dev = sb.st_dev; + i->next = pfile->import_hash_table[hashval]; + pfile->import_hash_table[hashval] = i; +} + +/* The file_name_map structure holds a mapping of file names for a + particular directory. This mapping is read from the file named + FILE_NAME_MAP_FILE in that directory. Such a file can be used to + map filenames on a file system with severe filename restrictions, + such as DOS. The format of the file name map file is just a series + of lines with two tokens on each line. The first token is the name + to map, and the second token is the actual name to use. */ + +struct file_name_map +{ + struct file_name_map *map_next; + char *map_from; + char *map_to; +}; + +#define FILE_NAME_MAP_FILE "header.gcc" + +/* Read a space delimited string of unlimited length from a stdio + file. */ + +static char * +read_filename_string (ch, f) + int ch; + FILE *f; +{ + char *alloc, *set; + int len; + + len = 20; + set = alloc = xmalloc (len + 1); + if (! is_space[ch]) + { + *set++ = ch; + while ((ch = getc (f)) != EOF && ! is_space[ch]) + { + if (set - alloc == len) + { + len *= 2; + alloc = xrealloc (alloc, len + 1); + set = alloc + len / 2; + } + *set++ = ch; + } + } + *set = '\0'; + ungetc (ch, f); + return alloc; +} + +/* This structure holds a linked list of file name maps, one per directory. */ +struct file_name_map_list +{ + struct file_name_map_list *map_list_next; + char *map_list_name; + struct file_name_map *map_list_map; +}; + +/* Read the file name map file for DIRNAME. */ + +static struct file_name_map * +read_name_map (pfile, dirname) + cpp_reader *pfile; + char *dirname; +{ + register struct file_name_map_list *map_list_ptr; + char *name; + FILE *f; + + for (map_list_ptr = CPP_OPTIONS (pfile)->map_list; map_list_ptr; + map_list_ptr = map_list_ptr->map_list_next) + if (! strcmp (map_list_ptr->map_list_name, dirname)) + return map_list_ptr->map_list_map; + + map_list_ptr = ((struct file_name_map_list *) + xmalloc (sizeof (struct file_name_map_list))); + map_list_ptr->map_list_name = savestring (dirname); + map_list_ptr->map_list_map = NULL; + + name = (char *) alloca (strlen (dirname) + strlen (FILE_NAME_MAP_FILE) + 2); + strcpy (name, dirname); + if (*dirname) + strcat (name, "/"); + strcat (name, FILE_NAME_MAP_FILE); + f = fopen (name, "r"); + if (!f) + map_list_ptr->map_list_map = NULL; + else + { + int ch; + int dirlen = strlen (dirname); + + while ((ch = getc (f)) != EOF) + { + char *from, *to; + struct file_name_map *ptr; + + if (is_space[ch]) + continue; + from = read_filename_string (ch, f); + while ((ch = getc (f)) != EOF && is_hor_space[ch]) + ; + to = read_filename_string (ch, f); + + ptr = ((struct file_name_map *) + xmalloc (sizeof (struct file_name_map))); + ptr->map_from = from; + + /* Make the real filename absolute. */ + if (*to == '/') + ptr->map_to = to; + else + { + ptr->map_to = xmalloc (dirlen + strlen (to) + 2); + strcpy (ptr->map_to, dirname); + ptr->map_to[dirlen] = '/'; + strcpy (ptr->map_to + dirlen + 1, to); + free (to); + } + + ptr->map_next = map_list_ptr->map_list_map; + map_list_ptr->map_list_map = ptr; + + while ((ch = getc (f)) != '\n') + if (ch == EOF) + break; + } + fclose (f); + } + + map_list_ptr->map_list_next = CPP_OPTIONS (pfile)->map_list; + CPP_OPTIONS (pfile)->map_list = map_list_ptr; + + return map_list_ptr->map_list_map; +} + +/* Try to open include file FILENAME. SEARCHPTR is the directory + being tried from the include file search path. This function maps + filenames on file systems based on information read by + read_name_map. */ + +static int +open_include_file (pfile, filename, searchptr) + cpp_reader *pfile; + char *filename; + struct file_name_list *searchptr; +{ + register struct file_name_map *map; + register char *from; + char *p, *dir; + + if (searchptr && ! searchptr->got_name_map) + { + searchptr->name_map = read_name_map (pfile, + searchptr->fname + ? searchptr->fname : "."); + searchptr->got_name_map = 1; + } + + /* First check the mapping for the directory we are using. */ + if (searchptr && searchptr->name_map) + { + from = filename; + if (searchptr->fname) + from += strlen (searchptr->fname) + 1; + for (map = searchptr->name_map; map; map = map->map_next) + { + if (! strcmp (map->map_from, from)) + { + /* Found a match. */ + return open (map->map_to, O_RDONLY, 0666); + } + } + } + + /* Try to find a mapping file for the particular directory we are + looking in. Thus #include will look up sys/types.h + in /usr/include/header.gcc and look up types.h in + /usr/include/sys/header.gcc. */ + p = rindex (filename, '/'); + if (! p) + p = filename; + if (searchptr + && searchptr->fname + && strlen (searchptr->fname) == p - filename + && ! strncmp (searchptr->fname, filename, p - filename)) + { + /* FILENAME is in SEARCHPTR, which we've already checked. */ + return open (filename, O_RDONLY, 0666); + } + + if (p == filename) + { + dir = "."; + from = filename; + } + else + { + dir = (char *) alloca (p - filename + 1); + bcopy (filename, dir, p - filename); + dir[p - filename] = '\0'; + from = p + 1; + } + for (map = read_name_map (pfile, dir); map; map = map->map_next) + if (! strcmp (map->map_from, from)) + return open (map->map_to, O_RDONLY, 0666); + + return open (filename, O_RDONLY, 0666); +} + +/* Process the contents of include file FNAME, already open on descriptor F, + with output to OP. + SYSTEM_HEADER_P is 1 if this file resides in any one of the known + "system" include directories (as decided by the `is_system_include' + function above). + DIRPTR is the link in the dir path through which this file was found, + or 0 if the file name was absolute or via the current directory. + Return 1 on success, 0 on failure. + + The caller is responsible for the cpp_push_buffer. */ + +static int +finclude (pfile, f, fname, system_header_p, dirptr) + cpp_reader *pfile; + int f; + char *fname; + int system_header_p; + struct file_name_list *dirptr; +{ + int st_mode; + long st_size; + long i; + int length; + cpp_buffer *fp; /* For input stack frame */ + int missing_newline = 0; + + if (file_size_and_mode (f, &st_mode, &st_size) < 0) + { + cpp_perror_with_name (pfile, fname); + close (f); + cpp_pop_buffer (pfile); + return 0; + } + + fp = CPP_BUFFER (pfile); + fp->nominal_fname = fp->fname = fname; +#if 0 + fp->length = 0; +#endif + fp->dir = dirptr; + fp->system_header_p = system_header_p; + fp->lineno = 1; + fp->colno = 1; + fp->cleanup = file_cleanup; + + if (S_ISREG (st_mode)) { + fp->buf = (U_CHAR *) xmalloc (st_size + 2); + fp->alimit = fp->buf + st_size + 2; + fp->cur = fp->buf; + + /* Read the file contents, knowing that st_size is an upper bound + on the number of bytes we can read. */ + length = safe_read (f, fp->buf, st_size); + fp->rlimit = fp->buf + length; + if (length < 0) goto nope; + } + else if (S_ISDIR (st_mode)) { + cpp_error (pfile, "directory `%s' specified in #include", fname); + close (f); + return 0; + } else { + /* Cannot count its file size before reading. + First read the entire file into heap and + copy them into buffer on stack. */ + + int bsize = 2000; + + st_size = 0; + fp->buf = (U_CHAR *) xmalloc (bsize + 2); + + for (;;) { + i = safe_read (f, fp->buf + st_size, bsize - st_size); + if (i < 0) + goto nope; /* error! */ + st_size += i; + if (st_size != bsize) + break; /* End of file */ + bsize *= 2; + fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2); + } + fp->cur = fp->buf; + length = st_size; + } + + if ((length > 0 && fp->buf[length - 1] != '\n') + /* Backslash-newline at end is not good enough. */ + || (length > 1 && fp->buf[length - 2] == '\\')) { + fp->buf[length++] = '\n'; +#if 0 + missing_newline = 1; +#endif + } + fp->buf[length] = '\0'; + fp->rlimit = fp->buf + length; + + /* Close descriptor now, so nesting does not use lots of descriptors. */ + close (f); + + /* Must do this before calling trigraph_pcp, so that the correct file name + will be printed in warning messages. */ + + pfile->input_stack_listing_current = 0; + +#if 0 + if (!no_trigraphs) + trigraph_pcp (fp); +#endif + +#if 0 + rescan (op, 0); + + if (missing_newline) + fp->lineno--; + + if (CPP_PEDANTIC (pfile) && missing_newline) + pedwarn ("file does not end in newline"); + + indepth--; + input_file_stack_tick++; + free (fp->buf); +#endif + return 1; + + nope: + + cpp_perror_with_name (pfile, fname); + close (f); + free (fp->buf); + return 1; +} + +int +push_parse_file (pfile, fname) + cpp_reader *pfile; + char *fname; +{ + struct cpp_options *opts = CPP_OPTIONS (pfile); + struct cpp_pending *pend; + char *p; + int f; + cpp_buffer *fp; + + /* The code looks at the defaults through this pointer, rather than through + the constant structure above. This pointer gets changed if an environment + variable specifies other defaults. */ + struct default_include *include_defaults = include_defaults_array; + + /* Add dirs from CPATH after dirs from -I. */ + /* There seems to be confusion about what CPATH should do, + so for the moment it is not documented. */ + /* Some people say that CPATH should replace the standard include dirs, + but that seems pointless: it comes before them, so it overrides them + anyway. */ + p = (char *) getenv ("CPATH"); + if (p != 0 && ! opts->no_standard_includes) + path_include (pfile, p); + + /* Now that dollars_in_ident is known, initialize is_idchar. */ + initialize_char_syntax (opts); + + /* Do partial setup of input buffer for the sake of generating + early #line directives (when -g is in effect). */ + fp = cpp_push_buffer (pfile, NULL, 0); + if (opts->in_fname == NULL) + opts->in_fname = ""; + fp->nominal_fname = fp->fname = opts->in_fname; + fp->lineno = 0; + + /* Install __LINE__, etc. Must follow initialize_char_syntax + and option processing. */ + initialize_builtins (pfile); + + /* Do standard #defines and assertions + that identify system and machine type. */ + + if (!opts->inhibit_predefs) { + char *p = (char *) alloca (strlen (predefs) + 1); + strcpy (p, predefs); + while (*p) { + char *q; + while (*p == ' ' || *p == '\t') + p++; + /* Handle -D options. */ + if (p[0] == '-' && p[1] == 'D') { + q = &p[2]; + while (*p && *p != ' ' && *p != '\t') + p++; + if (*p != 0) + *p++= 0; + if (opts->debug_output) + output_line_command (pfile, 0, same_file); + cpp_define (pfile, q); + while (*p == ' ' || *p == '\t') + p++; + } else if (p[0] == '-' && p[1] == 'A') { + /* Handle -A options (assertions). */ + char *assertion; + char *past_name; + char *value; + char *past_value; + char *termination; + int save_char; + + assertion = &p[2]; + past_name = assertion; + /* Locate end of name. */ + while (*past_name && *past_name != ' ' + && *past_name != '\t' && *past_name != '(') + past_name++; + /* Locate `(' at start of value. */ + value = past_name; + while (*value && (*value == ' ' || *value == '\t')) + value++; + if (*value++ != '(') + abort (); + while (*value && (*value == ' ' || *value == '\t')) + value++; + past_value = value; + /* Locate end of value. */ + while (*past_value && *past_value != ' ' + && *past_value != '\t' && *past_value != ')') + past_value++; + termination = past_value; + while (*termination && (*termination == ' ' || *termination == '\t')) + termination++; + if (*termination++ != ')') + abort (); + if (*termination && *termination != ' ' && *termination != '\t') + abort (); + /* Temporarily null-terminate the value. */ + save_char = *termination; + *termination = '\0'; + /* Install the assertion. */ + make_assertion (pfile, "-A", assertion); + *termination = (char) save_char; + p = termination; + while (*p == ' ' || *p == '\t') + p++; + } else { + abort (); + } + } + } + + /* Now handle the command line options. */ + + /* Do -U's, -D's and -A's in the order they were seen. */ + /* First reverse the list. */ + opts->pending = nreverse_pending (opts->pending); + + for (pend = opts->pending; pend; pend = pend->next) + { + if (pend->cmd != NULL && pend->cmd[0] == '-') + { + switch (pend->cmd[1]) + { + case 'U': + if (opts->debug_output) + output_line_command (pfile, 0, same_file); + do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg)); + break; + case 'D': + if (opts->debug_output) + output_line_command (pfile, 0, same_file); + cpp_define (pfile, pend->arg); + break; + case 'A': + make_assertion (pfile, "-A", pend->arg); + break; + } + } + } + + opts->done_initializing = 1; + + { /* read the appropriate environment variable and if it exists + replace include_defaults with the listed path. */ + char *epath = 0; + switch ((opts->objc << 1) + opts->cplusplus) + { + case 0: + epath = getenv ("C_INCLUDE_PATH"); + break; + case 1: + epath = getenv ("CPLUS_INCLUDE_PATH"); + break; + case 2: + epath = getenv ("OBJC_INCLUDE_PATH"); + break; + case 3: + epath = getenv ("OBJCPLUS_INCLUDE_PATH"); + break; + } + /* If the environment var for this language is set, + add to the default list of include directories. */ + if (epath) { + char *nstore = (char *) alloca (strlen (epath) + 2); + int num_dirs; + char *startp, *endp; + + for (num_dirs = 1, startp = epath; *startp; startp++) + if (*startp == PATH_SEPARATOR) + num_dirs++; + include_defaults + = (struct default_include *) xmalloc ((num_dirs + * sizeof (struct default_include)) + + sizeof (include_defaults_array)); + startp = endp = epath; + num_dirs = 0; + while (1) { + /* Handle cases like c:/usr/lib:d:/gcc/lib */ + if ((*endp == PATH_SEPARATOR) + || *endp == 0) { + strncpy (nstore, startp, endp-startp); + if (endp == startp) + strcpy (nstore, "."); + else + nstore[endp-startp] = '\0'; + + include_defaults[num_dirs].fname = savestring (nstore); + include_defaults[num_dirs].cplusplus = opts->cplusplus; + include_defaults[num_dirs].cxx_aware = 1; + num_dirs++; + if (*endp == '\0') + break; + endp = startp = endp + 1; + } else + endp++; + } + /* Put the usual defaults back in at the end. */ + bcopy ((char *) include_defaults_array, + (char *) &include_defaults[num_dirs], + sizeof (include_defaults_array)); + } + } + + append_include_chain (pfile, opts->before_system, opts->last_before_system); + opts->first_system_include = opts->before_system; + + /* Unless -fnostdinc, + tack on the standard include file dirs to the specified list */ + if (!opts->no_standard_includes) { + struct default_include *p = include_defaults; + char *specd_prefix = opts->include_prefix; + char *default_prefix = savestring (GCC_INCLUDE_DIR); + int default_len = 0; + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) { + default_len = strlen (default_prefix) - 7; + default_prefix[default_len] = 0; + } + /* Search "translated" versions of GNU directories. + These have /usr/local/lib/gcc... replaced by specd_prefix. */ + if (specd_prefix != 0 && default_len != 0) + for (p = include_defaults; p->fname; p++) { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus + || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) { + /* Does this dir start with the prefix? */ + if (!strncmp (p->fname, default_prefix, default_len)) { + /* Yes; change prefix and add to search list. */ + struct file_name_list *new + = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len; + char *str = (char *) xmalloc (this_len + 1); + strcpy (str, specd_prefix); + strcat (str, p->fname + default_len); + new->fname = str; + new->control_macro = 0; + new->c_system_include_path = !p->cxx_aware; + new->got_name_map = 0; + append_include_chain (pfile, new, new); + if (opts->first_system_include == 0) + opts->first_system_include = new; + } + } + } + /* Search ordinary names for GNU include directories. */ + for (p = include_defaults; p->fname; p++) { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus + || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) { + struct file_name_list *new + = (struct file_name_list *) xmalloc (sizeof (struct file_name_list)); + new->control_macro = 0; + new->c_system_include_path = !p->cxx_aware; + new->fname = p->fname; + new->got_name_map = 0; + append_include_chain (pfile, new, new); + if (opts->first_system_include == 0) + opts->first_system_include = new; + } + } + } + + /* Tack the after_include chain at the end of the include chain. */ + append_include_chain (pfile, opts->after_include, opts->last_after_include); + if (opts->first_system_include == 0) + opts->first_system_include = opts->after_include; + + /* With -v, print the list of dirs to search. */ + if (opts->verbose) { + struct file_name_list *p; + fprintf (stderr, "#include \"...\" search starts here:\n"); + for (p = opts->include; p; p = p->next) { + if (p == opts->first_bracket_include) + fprintf (stderr, "#include <...> search starts here:\n"); + fprintf (stderr, " %s\n", p->fname); + } + fprintf (stderr, "End of search list.\n"); + } + + /* Scan the -imacros files before the main input. + Much like #including them, but with no_output set + so that only their macro definitions matter. */ + + opts->no_output++; pfile->no_record_file++; + for (pend = opts->pending; pend; pend = pend->next) + { + if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0) + { + int fd = open (pend->arg, O_RDONLY, 0666); + if (fd < 0) + { + cpp_perror_with_name (pfile, pend->arg); + return FATAL_EXIT_CODE; + } + cpp_push_buffer (pfile, NULL, 0); + finclude (pfile, fd, pend->arg, 0, NULL_PTR); + cpp_scan_buffer (pfile); + } + } + opts->no_output--; pfile->no_record_file--; + + /* Copy the entire contents of the main input file into + the stacked input buffer previously allocated for it. */ + if (fname == NULL || *fname == 0) { + fname = ""; + f = 0; + } else if ((f = open (fname, O_RDONLY, 0666)) < 0) + cpp_pfatal_with_name (pfile, fname); + + /* -MG doesn't select the form of output and must be specified with one of + -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't + inhibit compilation. */ + if (opts->print_deps_missing_files + && (opts->print_deps == 0 || !opts->no_output)) + fatal (pfile, "-MG must be specified with one of -M or -MM"); + + /* Either of two environment variables can specify output of deps. + Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET", + where OUTPUT_FILE is the file to write deps info to + and DEPS_TARGET is the target to mention in the deps. */ + + if (opts->print_deps == 0 + && (getenv ("SUNPRO_DEPENDENCIES") != 0 + || getenv ("DEPENDENCIES_OUTPUT") != 0)) { + char *spec = getenv ("DEPENDENCIES_OUTPUT"); + char *s; + char *output_file; + + if (spec == 0) + { + spec = getenv ("SUNPRO_DEPENDENCIES"); + opts->print_deps = 2; + } + else + opts->print_deps = 1; + + s = spec; + /* Find the space before the DEPS_TARGET, if there is one. */ + /* This should use index. (mrs) */ + while (*s != 0 && *s != ' ') s++; + if (*s != 0) + { + opts->deps_target = s + 1; + output_file = (char *) xmalloc (s - spec + 1); + bcopy (spec, output_file, s - spec); + output_file[s - spec] = 0; + } + else + { + opts->deps_target = 0; + output_file = spec; + } + + opts->deps_file = output_file; + opts->print_deps_append = 1; + } + + /* For -M, print the expected object file name + as the target of this Make-rule. */ + if (opts->print_deps) + { + pfile->deps_allocated_size = 200; + pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size); + pfile->deps_buffer[0] = 0; + pfile->deps_size = 0; + pfile->deps_column = 0; + + if (opts->deps_target) + deps_output (pfile, opts->deps_target, ':'); + else if (*opts->in_fname == 0) + deps_output (pfile, "-", ':'); + else + { + char *p, *q; + int len; + + /* Discard all directory prefixes from filename. */ + if ((q = rindex (opts->in_fname, '/')) != NULL +#ifdef DIR_SEPARATOR + && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL +#endif + ) + ++q; + else + q = opts->in_fname; + + /* Copy remainder to mungable area. */ + p = (char *) alloca (strlen(q) + 8); + strcpy (p, q); + + /* Output P, but remove known suffixes. */ + len = strlen (p); + q = p + len; + if (len >= 2 + && p[len - 2] == '.' + && index("cCsSm", p[len - 1])) + q = p + (len - 2); + else if (len >= 3 + && p[len - 3] == '.' + && p[len - 2] == 'c' + && p[len - 1] == 'c') + q = p + (len - 3); + else if (len >= 4 + && p[len - 4] == '.' + && p[len - 3] == 'c' + && p[len - 2] == 'x' + && p[len - 1] == 'x') + q = p + (len - 4); + else if (len >= 4 + && p[len - 4] == '.' + && p[len - 3] == 'c' + && p[len - 2] == 'p' + && p[len - 1] == 'p') + q = p + (len - 4); + + /* Supply our own suffix. */ +#ifndef VMS + strcpy (q, ".o"); +#else + strcpy (q, ".obj"); +#endif + + deps_output (pfile, p, ':'); + deps_output (pfile, opts->in_fname, ' '); + } + } + +#if 0 + /* Make sure data ends with a newline. And put a null after it. */ + + if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n') + /* Backslash-newline at end is not good enough. */ + || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) { + fp->buf[fp->length++] = '\n'; + missing_newline = 1; + } + fp->buf[fp->length] = '\0'; + + /* Unless inhibited, convert trigraphs in the input. */ + + if (!no_trigraphs) + trigraph_pcp (fp); +#endif + + /* Scan the -include files before the main input. + We push these in reverse order, so that the first one is handled first. */ + + pfile->no_record_file++; + opts->pending = nreverse_pending (opts->pending); + for (pend = opts->pending; pend; pend = pend->next) + { + if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0) + { + int fd = open (pend->arg, O_RDONLY, 0666); + if (fd < 0) + { + cpp_perror_with_name (pfile, pend->arg); + return FATAL_EXIT_CODE; + } + cpp_push_buffer (pfile, NULL, 0); + finclude (pfile, fd, pend->arg, 0, NULL_PTR); + } + } + pfile->no_record_file--; + + /* Free the pending list. */ + for (pend = opts->pending; pend; ) + { + struct cpp_pending *next = pend->next; + free (pend); + pend = next; + } + opts->pending = NULL; + +#if 0 + /* Scan the input, processing macros and directives. */ + + rescan (&outbuf, 0); + + if (missing_newline) + fp->lineno--; + + if (CPP_PEDANTIC (pfile) && missing_newline) + pedwarn ("file does not end in newline"); + +#endif + if (finclude (pfile, f, fname, 0, NULL_PTR)) + output_line_command (pfile, 0, same_file); + return SUCCESS_EXIT_CODE; +} + +void +init_parse_file (pfile) + cpp_reader *pfile; +{ + bzero ((char *) pfile, sizeof (cpp_reader)); + pfile->get_token = cpp_get_token; + + pfile->token_buffer_size = 200; + pfile->token_buffer = (U_CHAR*)xmalloc (pfile->token_buffer_size); + CPP_SET_WRITTEN (pfile, 0); + + pfile->system_include_depth = 0; + pfile->dont_repeat_files = 0; + pfile->all_include_files = 0; + pfile->max_include_len = 0; + pfile->timebuf = NULL; + pfile->only_seen_white = 1; + pfile->buffer = CPP_NULL_BUFFER(pfile); +} + +static struct cpp_pending * +nreverse_pending (list) + struct cpp_pending *list; + +{ + register struct cpp_pending *prev = 0, *next, *pend; + for (pend = list; pend; pend = next) + { + next = pend->next; + pend->next = prev; + prev = pend; + } + return prev; +} + +static void +push_pending (pfile, cmd, arg) + cpp_reader *pfile; + char *cmd; + char *arg; +{ + struct cpp_pending *pend + = (struct cpp_pending*)xmalloc (sizeof (struct cpp_pending)); + pend->cmd = cmd; + pend->arg = arg; + pend->next = CPP_OPTIONS (pfile)->pending; + CPP_OPTIONS (pfile)->pending = pend; +} + +/* Handle command-line options in (argc, argv). + Can be called multiple times, to handle multiple sets of options. + Returns if an unrecognized option is seen. + Returns number of handled arguments. */ + +int +cpp_handle_options (pfile, argc, argv) + cpp_reader *pfile; + int argc; + char **argv; +{ + int i; + struct cpp_options *opts = CPP_OPTIONS (pfile); + for (i = 0; i < argc; i++) { + if (argv[i][0] != '-') { + if (opts->out_fname != NULL) + fatal ("Usage: %s [switches] input output", argv[0]); + else if (opts->in_fname != NULL) + opts->out_fname = argv[i]; + else + opts->in_fname = argv[i]; + } else { + switch (argv[i][1]) { + + case 'i': + if (!strcmp (argv[i], "-include") + || !strcmp (argv[i], "-imacros")) { + if (i + 1 == argc) + fatal ("Filename missing after `%s' option", argv[i]); + else + push_pending (pfile, argv[i], argv[i+1]), i++; + } + if (!strcmp (argv[i], "-iprefix")) { + if (i + 1 == argc) + fatal ("Filename missing after `-iprefix' option"); + else + opts->include_prefix = argv[++i]; + } + if (!strcmp (argv[i], "-ifoutput")) { + opts->output_conditionals = 1; + } + if (!strcmp (argv[i], "-isystem")) { + struct file_name_list *dirtmp; + + if (i + 1 == argc) + fatal ("Filename missing after `-isystem' option"); + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 1; + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + 1); + strcpy (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (opts->before_system == 0) + opts->before_system = dirtmp; + else + opts->last_before_system->next = dirtmp; + opts->last_before_system = dirtmp; /* Tail follows the last one */ + } + /* Add directory to end of path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefix")) { + struct file_name_list *dirtmp; + char *prefix; + + if (opts->include_prefix != 0) + prefix = opts->include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-iwithprefix' option"); + + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + if (opts->after_include == 0) + opts->after_include = dirtmp; + else + opts->last_after_include->next = dirtmp; + opts->last_after_include = dirtmp; /* Tail follows the last one */ + } + /* Add directory to main path for includes, + with the default prefix at the front of its name. */ + if (!strcmp (argv[i], "-iwithprefixbefore")) { + struct file_name_list *dirtmp; + char *prefix; + + if (opts->include_prefix != 0) + prefix = opts->include_prefix; + else { + prefix = savestring (GCC_INCLUDE_DIR); + /* Remove the `include' from /usr/local/lib/gcc.../include. */ + if (!strcmp (prefix + strlen (prefix) - 8, "/include")) + prefix[strlen (prefix) - 7] = 0; + } + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-iwithprefixbefore' option"); + + dirtmp->fname = (char *) xmalloc (strlen (argv[i+1]) + + strlen (prefix) + 1); + strcpy (dirtmp->fname, prefix); + strcat (dirtmp->fname, argv[++i]); + dirtmp->got_name_map = 0; + + append_include_chain (pfile, dirtmp, dirtmp); + } + /* Add directory to end of path for includes. */ + if (!strcmp (argv[i], "-idirafter")) { + struct file_name_list *dirtmp; + + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (i + 1 == argc) + fatal ("Directory name missing after `-idirafter' option"); + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + + if (opts->after_include == 0) + opts->after_include = dirtmp; + else + opts->last_after_include->next = dirtmp; + opts->last_after_include = dirtmp; /* Tail follows the last one */ + } + break; + + case 'o': + if (opts->out_fname != NULL) + fatal ("Output filename specified twice"); + if (i + 1 == argc) + fatal ("Filename missing after -o option"); + opts->out_fname = argv[++i]; + if (!strcmp (opts->out_fname, "-")) + opts->out_fname = ""; + break; + + case 'p': + if (!strcmp (argv[i], "-pedantic")) + CPP_PEDANTIC (pfile) = 1; + else if (!strcmp (argv[i], "-pedantic-errors")) { + CPP_PEDANTIC (pfile) = 1; + opts->pedantic_errors = 1; + } +#if 0 + else if (!strcmp (argv[i], "-pcp")) { + char *pcp_fname = argv[++i]; + pcp_outfile = + ((pcp_fname[0] != '-' || pcp_fname[1] != '\0') + ? fopen (pcp_fname, "w") + : fdopen (dup (fileno (stdout)), "w")); + if (pcp_outfile == 0) + cpp_pfatal_with_name (pfile, pcp_fname); + no_precomp = 1; + } +#endif + break; + + case 't': + if (!strcmp (argv[i], "-traditional")) { + opts->traditional = 1; + if (opts->dollars_in_ident > 0) + opts->dollars_in_ident = 1; + } else if (!strcmp (argv[i], "-trigraphs")) { + if (!opts->chill) + opts->no_trigraphs = 0; + } + break; + + case 'l': + if (! strcmp (argv[i], "-lang-c")) + opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->objc = 0; + if (! strcmp (argv[i], "-lang-c++")) + opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->objc = 0; + if (! strcmp (argv[i], "-lang-c-c++-comments")) + opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->objc = 0; + if (! strcmp (argv[i], "-lang-objc")) + opts->objc = 1, opts->cplusplus = 0, opts->cplusplus_comments = 1; + if (! strcmp (argv[i], "-lang-objc++")) + opts->objc = 1, opts->cplusplus = 1, opts->cplusplus_comments = 1; + if (! strcmp (argv[i], "-lang-asm")) + opts->lang_asm = 1; + if (! strcmp (argv[i], "-lint")) + opts->for_lint = 1; + if (! strcmp (argv[i], "-lang-chill")) + opts->objc = 0, opts->cplusplus = 0, opts->chill = 1, + opts->traditional = 1, opts->no_trigraphs = 1; + break; + + case '+': + opts->cplusplus = 1, opts->cplusplus_comments = 1; + break; + + case 'w': + opts->inhibit_warnings = 1; + break; + + case 'W': + if (!strcmp (argv[i], "-Wtrigraphs")) + opts->warn_trigraphs = 1; + else if (!strcmp (argv[i], "-Wno-trigraphs")) + opts->warn_trigraphs = 0; + else if (!strcmp (argv[i], "-Wcomment")) + opts->warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comment")) + opts->warn_comments = 0; + else if (!strcmp (argv[i], "-Wcomments")) + opts->warn_comments = 1; + else if (!strcmp (argv[i], "-Wno-comments")) + opts->warn_comments = 0; + else if (!strcmp (argv[i], "-Wtraditional")) + opts->warn_stringify = 1; + else if (!strcmp (argv[i], "-Wno-traditional")) + opts->warn_stringify = 0; + else if (!strcmp (argv[i], "-Wimport")) + opts->warn_import = 1; + else if (!strcmp (argv[i], "-Wno-import")) + opts->warn_import = 0; + else if (!strcmp (argv[i], "-Werror")) + opts->warnings_are_errors = 1; + else if (!strcmp (argv[i], "-Wno-error")) + opts->warnings_are_errors = 0; + else if (!strcmp (argv[i], "-Wall")) + { + opts->warn_trigraphs = 1; + opts->warn_comments = 1; + } + break; + + case 'M': + /* The style of the choices here is a bit mixed. + The chosen scheme is a hybrid of keeping all options in one string + and specifying each option in a separate argument: + -M|-MM|-MD file|-MMD file [-MG]. An alternative is: + -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely: + -M[M][G][D file]. This is awkward to handle in specs, and is not + as extensible. */ + /* ??? -MG must be specified in addition to one of -M or -MM. + This can be relaxed in the future without breaking anything. + The converse isn't true. */ + + /* -MG isn't valid with -MD or -MMD. This is checked for later. */ + if (!strcmp (argv[i], "-MG")) + { + opts->print_deps_missing_files = 1; + break; + } + if (!strcmp (argv[i], "-M")) + opts->print_deps = 2; + else if (!strcmp (argv[i], "-MM")) + opts->print_deps = 1; + else if (!strcmp (argv[i], "-MD")) + opts->print_deps = 2; + else if (!strcmp (argv[i], "-MMD")) + opts->print_deps = 1; + /* For -MD and -MMD options, write deps on file named by next arg. */ + if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD")) + { + if (i+1 == argc) + fatal ("Filename missing after %s option", argv[i]); + opts->deps_file = argv[++i]; + } + else + { + /* For -M and -MM, write deps on standard output + and suppress the usual output. */ + opts->no_output = 1; + } + break; + + case 'd': + { + char *p = argv[i] + 2; + char c; + while ((c = *p++) != 0) { + /* Arg to -d specifies what parts of macros to dump */ + switch (c) { + case 'M': + opts->dump_macros = dump_only; + opts->no_output = 1; + break; + case 'N': + opts->dump_macros = dump_names; + break; + case 'D': + opts->dump_macros = dump_definitions; + break; + } + } + } + break; + + case 'g': + if (argv[i][2] == '3') + opts->debug_output = 1; + break; + + case 'v': + fprintf (stderr, "GNU CPP version %s", version_string); +#ifdef TARGET_VERSION + TARGET_VERSION; +#endif + fprintf (stderr, "\n"); + opts->verbose = 1; + break; + + case 'H': + opts->print_include_names = 1; + break; + + case 'D': + if (argv[i][2] != 0) + push_pending (pfile, "-D", argv[i] + 2); + else if (i + 1 == argc) + fatal ("Macro name missing after -D option"); + else + i++, push_pending (pfile, "-D", argv[i]); + break; + + case 'A': + { + char *p; + + if (argv[i][2] != 0) + p = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Assertion missing after -A option"); + else + p = argv[++i]; + + if (!strcmp (p, "-")) { + struct cpp_pending **ptr; + /* -A- eliminates all predefined macros and assertions. + Let's include also any that were specified earlier + on the command line. That way we can get rid of any + that were passed automatically in from GCC. */ + int j; + opts->inhibit_predefs = 1; + for (ptr = &opts->pending; *ptr != NULL; ) + { + struct cpp_pending *pend = *ptr; + if (pend->cmd && pend->cmd[0] == '-' + && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A')) + { + *ptr = pend->next; + free (pend); + } + else + ptr = &pend->next; + } + } else { + push_pending (pfile, "-A", p); + } + } + break; + + case 'U': /* JF #undef something */ + if (argv[i][2] != 0) + push_pending (pfile, "-U", argv[i] + 2); + else if (i + 1 == argc) + fatal ("Macro name missing after -U option"); + else + push_pending (pfile, "-U", argv[i+1]), i++; + break; + + case 'C': + opts->put_out_comments = 1; + break; + + case 'E': /* -E comes from cc -E; ignore it. */ + break; + + case 'P': + opts->no_line_commands = 1; + break; + + case '$': /* Don't include $ in identifiers. */ + opts->dollars_in_ident = 0; + break; + + case 'I': /* Add directory to path for includes. */ + { + struct file_name_list *dirtmp; + + if (! CPP_OPTIONS(pfile)->ignore_srcdir + && !strcmp (argv[i] + 2, "-")) { + CPP_OPTIONS (pfile)->ignore_srcdir = 1; + /* Don't use any preceding -I directories for #include <...>. */ + CPP_OPTIONS (pfile)->first_bracket_include = 0; + } + else { + dirtmp = (struct file_name_list *) + xmalloc (sizeof (struct file_name_list)); + dirtmp->next = 0; /* New one goes on the end */ + dirtmp->control_macro = 0; + dirtmp->c_system_include_path = 0; + if (argv[i][2] != 0) + dirtmp->fname = argv[i] + 2; + else if (i + 1 == argc) + fatal ("Directory name missing after -I option"); + else + dirtmp->fname = argv[++i]; + dirtmp->got_name_map = 0; + append_include_chain (pfile, dirtmp, dirtmp); + } + } + break; + + case 'n': + if (!strcmp (argv[i], "-nostdinc")) + /* -nostdinc causes no default include directories. + You must specify all include-file directories with -I. */ + opts->no_standard_includes = 1; + else if (!strcmp (argv[i], "-nostdinc++")) + /* -nostdinc++ causes no default C++-specific include directories. */ + opts->no_standard_cplusplus_includes = 1; +#if 0 + else if (!strcmp (argv[i], "-noprecomp")) + no_precomp = 1; +#endif + break; + + case 'u': + /* Sun compiler passes undocumented switch "-undef". + Let's assume it means to inhibit the predefined symbols. */ + opts->inhibit_predefs = 1; + break; + + case '\0': /* JF handle '-' as file name meaning stdin or stdout */ + if (opts->in_fname == NULL) { + opts->in_fname = ""; + break; + } else if (opts->out_fname == NULL) { + opts->out_fname = ""; + break; + } /* else fall through into error */ + + default: + return i; + } + } + } + return i; +} + +void +cpp_finish (pfile) + cpp_reader *pfile; +{ + struct cpp_options *opts = CPP_OPTIONS (pfile); + + if (opts->print_deps) + { + /* Stream on which to print the dependency information. */ + FILE *deps_stream; + + /* Don't actually write the deps file if compilation has failed. */ + if (pfile->errors == 0) + { + char *deps_mode = opts->print_deps_append ? "a" : "w"; + if (opts->deps_file == 0) + deps_stream = stdout; + else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0) + cpp_pfatal_with_name (pfile, opts->deps_file); + fputs (pfile->deps_buffer, deps_stream); + putc ('\n', deps_stream); + if (opts->deps_file) + { + if (ferror (deps_stream) || fclose (deps_stream) != 0) + fatal ("I/O error on output"); + } + } + } +} + +/* Free resources used by PFILE. */ + +void +cpp_cleanup (pfile) + cpp_reader *pfile; +{ + int i; + while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile)) + cpp_pop_buffer (pfile); + + if (pfile->token_buffer) + { + free (pfile->token_buffer); + pfile->token_buffer = NULL; + } + + if (pfile->deps_buffer) + { + free (pfile->deps_buffer); + pfile->deps_buffer = NULL; + pfile->deps_allocated_size = 0; + } + + while (pfile->if_stack) + { + IF_STACK_FRAME *temp = pfile->if_stack; + pfile->if_stack = temp->next; + free (temp); + } + + while (pfile->dont_repeat_files) + { + struct file_name_list *temp = pfile->dont_repeat_files; + pfile->dont_repeat_files = temp->next; + free (temp->fname); + free (temp); + } + + while (pfile->all_include_files) + { + struct file_name_list *temp = pfile->all_include_files; + pfile->all_include_files = temp->next; + free (temp->fname); + free (temp); + } + + for (i = IMPORT_HASH_SIZE; --i >= 0; ) + { + register struct import_file *imp = pfile->import_hash_table[i]; + while (imp) + { + struct import_file *next = imp->next; + free (imp->name); + free (imp); + imp = next; + } + pfile->import_hash_table[i] = 0; + } + + for (i = ASSERTION_HASHSIZE; --i >= 0; ) + { + while (pfile->assertion_hashtab[i]) + delete_assertion (pfile->assertion_hashtab[i]); + } + + cpp_hash_cleanup (pfile); +} + +static int +do_assert (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + long symstart; /* remember where symbol name starts */ + int c; + int sym_length; /* and how long it is */ + struct arglist *tokens = NULL; + + if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing + && !CPP_BUFFER (pfile)->system_header_p) + cpp_pedwarn (pfile, "ANSI C does not allow `#assert'"); + + cpp_skip_hspace (pfile); + symstart = CPP_WRITTEN (pfile); /* remember where it starts */ + parse_name (pfile, GETC()); + sym_length = check_macro_name (pfile, pfile->token_buffer + symstart, + "assertion"); + + cpp_skip_hspace (pfile); + if (PEEKC() != '(') { + cpp_error (pfile, "missing token-sequence in `#assert'"); + goto error; + } + + { + int error_flag = 0; + tokens = read_token_list (pfile, &error_flag); + if (error_flag) + goto error; + if (tokens == 0) { + cpp_error (pfile, "empty token-sequence in `#assert'"); + goto error; + } + cpp_skip_hspace (pfile); + c = PEEKC (); + if (c != EOF && c != '\n') + cpp_pedwarn (pfile, "junk at end of `#assert'"); + skip_rest_of_line (pfile); + } + + /* If this name isn't already an assertion name, make it one. + Error if it was already in use in some other way. */ + + { + ASSERTION_HASHNODE *hp; + U_CHAR *symname = pfile->token_buffer + symstart; + int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE); + struct tokenlist_list *value + = (struct tokenlist_list *) xmalloc (sizeof (struct tokenlist_list)); + + hp = assertion_lookup (pfile, symname, sym_length, hashcode); + if (hp == NULL) { + if (sym_length == 7 && ! strncmp (symname, "defined", sym_length)) + cpp_error (pfile, "`defined' redefined as assertion"); + hp = assertion_install (pfile, symname, sym_length, hashcode); + } + + /* Add the spec'd token-sequence to the list of such. */ + value->tokens = tokens; + value->next = hp->value; + hp->value = value; + } + CPP_SET_WRITTEN (pfile, symstart); /* Pop */ + return 0; + error: + CPP_SET_WRITTEN (pfile, symstart); /* Pop */ + skip_rest_of_line (pfile); + return 1; +} + +static int +do_unassert (pfile, keyword, buf, limit) + cpp_reader *pfile; + struct directive *keyword; + U_CHAR *buf, *limit; +{ + long symstart; /* remember where symbol name starts */ + int sym_length; /* and how long it is */ + int c; + + struct arglist *tokens = NULL; + int tokens_specified = 0; + + if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing + && !CPP_BUFFER (pfile)->system_header_p) + cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'"); + + cpp_skip_hspace (pfile); + + symstart = CPP_WRITTEN (pfile); /* remember where it starts */ + parse_name (pfile, GETC()); + sym_length = check_macro_name (pfile, pfile->token_buffer + symstart, + "assertion"); + + cpp_skip_hspace (pfile); + if (PEEKC() == '(') { + int error_flag = 0; + + tokens = read_token_list (pfile, &error_flag); + if (error_flag) + goto error; + if (tokens == 0) { + cpp_error (pfile, "empty token list in `#unassert'"); + goto error; + } + + tokens_specified = 1; + } + + cpp_skip_hspace (pfile); + c = PEEKC (); + if (c != EOF && c != '\n') + cpp_error (pfile, "junk at end of `#unassert'"); + skip_rest_of_line (pfile); + + { + ASSERTION_HASHNODE *hp; + U_CHAR *symname = pfile->token_buffer + symstart; + int hashcode = hashf (symname, sym_length, ASSERTION_HASHSIZE); + struct tokenlist_list *tail, *prev; + + hp = assertion_lookup (pfile, symname, sym_length, hashcode); + if (hp == NULL) + return 1; + + /* If no token list was specified, then eliminate this assertion + entirely. */ + if (! tokens_specified) + delete_assertion (hp); + else { + /* If a list of tokens was given, then delete any matching list. */ + + tail = hp->value; + prev = 0; + while (tail) { + struct tokenlist_list *next = tail->next; + if (compare_token_lists (tail->tokens, tokens)) { + if (prev) + prev->next = next; + else + hp->value = tail->next; + free_token_list (tail->tokens); + free (tail); + } else { + prev = tail; + } + tail = next; + } + } + } + + CPP_SET_WRITTEN (pfile, symstart); /* Pop */ + return 0; + error: + CPP_SET_WRITTEN (pfile, symstart); /* Pop */ + skip_rest_of_line (pfile); + return 1; +} + +/* Test whether there is an assertion named NAME + and optionally whether it has an asserted token list TOKENS. + NAME is not null terminated; its length is SYM_LENGTH. + If TOKENS_SPECIFIED is 0, then don't check for any token list. */ + +int +check_assertion (pfile, name, sym_length, tokens_specified, tokens) + cpp_reader *pfile; + U_CHAR *name; + int sym_length; + int tokens_specified; + struct arglist *tokens; +{ + ASSERTION_HASHNODE *hp; + int hashcode = hashf (name, sym_length, ASSERTION_HASHSIZE); + + if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p) + cpp_pedwarn (pfile, "ANSI C does not allow testing assertions"); + + hp = assertion_lookup (pfile, name, sym_length, hashcode); + if (hp == NULL) + /* It is not an assertion; just return false. */ + return 0; + + /* If no token list was specified, then value is 1. */ + if (! tokens_specified) + return 1; + + { + struct tokenlist_list *tail; + + tail = hp->value; + + /* If a list of tokens was given, + then succeed if the assertion records a matching list. */ + + while (tail) { + if (compare_token_lists (tail->tokens, tokens)) + return 1; + tail = tail->next; + } + + /* Fail if the assertion has no matching list. */ + return 0; + } +} + +/* Compare two lists of tokens for equality including order of tokens. */ + +static int +compare_token_lists (l1, l2) + struct arglist *l1, *l2; +{ + while (l1 && l2) { + if (l1->length != l2->length) + return 0; + if (strncmp (l1->name, l2->name, l1->length)) + return 0; + l1 = l1->next; + l2 = l2->next; + } + + /* Succeed if both lists end at the same time. */ + return l1 == l2; +} + +struct arglist * +reverse_token_list (tokens) + struct arglist *tokens; +{ + register struct arglist *prev = 0, *this, *next; + for (this = tokens; this; this = next) + { + next = this->next; + this->next = prev; + prev = this; + } + return prev; +} + +/* Read a space-separated list of tokens ending in a close parenthesis. + Return a list of strings, in the order they were written. + (In case of error, return 0 and store -1 in *ERROR_FLAG.) */ + +static struct arglist * +read_token_list (pfile, error_flag) + cpp_reader *pfile; + int *error_flag; +{ + struct arglist *token_ptrs = 0; + int depth = 1; + int length; + + *error_flag = 0; + FORWARD (1); /* Skip '(' */ + + /* Loop over the assertion value tokens. */ + while (depth > 0) + { + struct arglist *temp; + long name_written = CPP_WRITTEN (pfile); + int eofp = 0; int c; + + cpp_skip_hspace (pfile); + + c = GETC (); + + /* Find the end of the token. */ + if (c == '(') + { + CPP_PUTC (pfile, c); + depth++; + } + else if (c == ')') + { + depth--; + if (depth == 0) + break; + CPP_PUTC (pfile, c); + } + else if (c == '"' || c == '\'') + { + FORWARD(-1); + cpp_get_token (pfile); + } + else if (c == '\n') + break; + else + { + while (c != EOF && ! is_space[c] && c != '(' && c != ')' + && c != '"' && c != '\'') + { + CPP_PUTC (pfile, c); + c = GETC(); + } + if (c != EOF) FORWARD(-1); + } + + length = CPP_WRITTEN (pfile) - name_written; + temp = (struct arglist *) + xmalloc (sizeof (struct arglist) + length + 1); + temp->name = (U_CHAR *) (temp + 1); + bcopy ((char *) (pfile->token_buffer + name_written), + (char *) temp->name, length); + temp->name[length] = 0; + temp->next = token_ptrs; + token_ptrs = temp; + temp->length = length; + + CPP_ADJUST_WRITTEN (pfile, -length); /* pop */ + + if (c == EOF || c == '\n') + { /* FIXME */ + cpp_error (pfile, + "unterminated token sequence following `#' operator"); + return 0; + } + } + + /* We accumulated the names in reverse order. + Now reverse them to get the proper order. */ + return reverse_token_list (token_ptrs); +} + +static void +free_token_list (tokens) + struct arglist *tokens; +{ + while (tokens) { + struct arglist *next = tokens->next; + free (tokens->name); + free (tokens); + tokens = next; + } +} + +/* Get the file-mode and data size of the file open on FD + and store them in *MODE_POINTER and *SIZE_POINTER. */ + +static int +file_size_and_mode (fd, mode_pointer, size_pointer) + int fd; + int *mode_pointer; + long int *size_pointer; +{ + struct stat sbuf; + + if (fstat (fd, &sbuf) < 0) return (-1); + if (mode_pointer) *mode_pointer = sbuf.st_mode; + if (size_pointer) *size_pointer = sbuf.st_size; + return 0; +} + +/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME, + retrying if necessary. Return a negative value if an error occurs, + otherwise return the actual number of bytes read, + which must be LEN unless end-of-file was reached. */ + +static int +safe_read (desc, ptr, len) + int desc; + char *ptr; + int len; +{ + int left = len; + while (left > 0) { + int nchars = read (desc, ptr, left); + if (nchars < 0) + { +#ifdef EINTR + if (errno == EINTR) + continue; +#endif + return nchars; + } + if (nchars == 0) + break; + ptr += nchars; + left -= nchars; + } + return len - left; +} + +static char * +savestring (input) + char *input; +{ + unsigned size = strlen (input); + char *output = xmalloc (size + 1); + strcpy (output, input); + return output; +} + +/* Initialize PMARK to remember the current position of PFILE. */ +void +parse_set_mark (pmark, pfile) + struct parse_marker *pmark; + cpp_reader *pfile; +{ + cpp_buffer *pbuf = CPP_BUFFER (pfile); + pmark->next = pbuf->marks; + pbuf->marks = pmark; + pmark->buf = pbuf; + pmark->position = pbuf->cur - pbuf->buf; +} + +/* Cleanup PMARK - we no longer need it. */ +void +parse_clear_mark (pmark) + struct parse_marker *pmark; +{ + struct parse_marker **pp = &pmark->buf->marks; + for (; ; pp = &(*pp)->next) { + if (*pp == NULL) fatal ("internal error", "in parse_set_mark"); + if (*pp == pmark) break; + } + *pp = pmark->next; +} + +/* Backup the current position of PFILE to that saved in PMARK. */ + +void +parse_goto_mark (pmark, pfile) + struct parse_marker *pmark; + cpp_reader *pfile; +{ + cpp_buffer *pbuf = CPP_BUFFER (pfile); + if (pbuf != pmark->buf) + fatal ("internal error %s", "parse_goto_mark"); + pbuf->cur = pbuf->buf + pmark->position; +} + +/* Reset PMARK to point to the current position of PFILE. (Same + as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */ + +void +parse_move_mark (pmark, pfile) + struct parse_marker *pmark; + cpp_reader *pfile; +{ + cpp_buffer *pbuf = CPP_BUFFER (pfile); + if (pbuf != pmark->buf) + fatal ("internal error %s", "parse_move_mark"); + pmark->position = pbuf->cur - pbuf->buf; +} + +int +cpp_read_check_assertion (pfile) + cpp_reader *pfile; +{ + int name_start = CPP_WRITTEN (pfile); + int name_length, name_written; + int result; + FORWARD (1); /* Skip '#' */ + cpp_skip_hspace (pfile); + parse_name (pfile, GETC ()); + name_written = CPP_WRITTEN (pfile); + name_length = name_written - name_start; + cpp_skip_hspace (pfile); + if (CPP_BUF_PEEK (CPP_BUFFER (pfile)) == '(') + { + int error_flag; + struct arglist *token_ptrs = read_token_list (pfile, &error_flag); + result = check_assertion (pfile, + pfile->token_buffer + name_start, name_length, + 1, token_ptrs); + } + else + result = check_assertion (pfile, + pfile->token_buffer + name_start, name_length, + 0, NULL_PTR); + CPP_ADJUST_WRITTEN (pfile, - name_length); /* pop */ + return result; +} + +void +cpp_print_file_and_line (pfile) + cpp_reader *pfile; +{ + cpp_buffer *ip = cpp_file_buffer (pfile); + + if (ip != NULL) + { + long line, col; + cpp_buf_line_and_col (ip, &line, &col); + cpp_file_line_for_message (pfile, ip->nominal_fname, + line, pfile->show_column ? col : -1); + } +} + +void +cpp_error (pfile, msg, arg1, arg2, arg3) + cpp_reader *pfile; + char *msg; + char *arg1, *arg2, *arg3; +{ + cpp_print_containing_files (pfile); + cpp_print_file_and_line (pfile); + cpp_message (pfile, 1, msg, arg1, arg2, arg3); +} + +/* Print error message but don't count it. */ + +void +cpp_warning (pfile, msg, arg1, arg2, arg3) + cpp_reader *pfile; + char *msg; + char *arg1, *arg2, *arg3; +{ + if (CPP_OPTIONS (pfile)->inhibit_warnings) + return; + + if (CPP_OPTIONS (pfile)->warnings_are_errors) + pfile->errors++; + + cpp_print_containing_files (pfile); + cpp_print_file_and_line (pfile); + cpp_message (pfile, 0, msg, arg1, arg2, arg3); +} + +/* Print an error message and maybe count it. */ + +void +cpp_pedwarn (pfile, msg, arg1, arg2, arg3) + cpp_reader *pfile; + char *msg; + char *arg1, *arg2, *arg3; +{ + if (CPP_OPTIONS (pfile)->pedantic_errors) + cpp_error (pfile, msg, arg1, arg2, arg3); + else + cpp_warning (pfile, msg, arg1, arg2, arg3); +} + +void +cpp_error_with_line (pfile, line, column, msg, arg1, arg2, arg3) + cpp_reader *pfile; + int line, column; + char *msg; + char *arg1, *arg2, *arg3; +{ + int i; + cpp_buffer *ip = cpp_file_buffer (pfile); + + cpp_print_containing_files (pfile); + + if (ip != NULL) + cpp_file_line_for_message (pfile, ip->nominal_fname, line, column); + + cpp_message (pfile, 1, msg, arg1, arg2, arg3); +} + +static void +cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3) + cpp_reader *pfile; + int line, column; + char *msg; + char *arg1, *arg2, *arg3; +{ + int i; + cpp_buffer *ip; + + if (CPP_OPTIONS (pfile)->inhibit_warnings) + return; + + if (CPP_OPTIONS (pfile)->warnings_are_errors) + pfile->errors++; + + cpp_print_containing_files (pfile); + + ip = cpp_file_buffer (pfile); + + if (ip != NULL) + cpp_file_line_for_message (pfile, ip->nominal_fname, line, column); + + cpp_message (pfile, 0, msg, arg1, arg2, arg3); +} + +void +cpp_pedwarn_with_line (pfile, line, column, msg, arg1, arg2, arg3) + cpp_reader *pfile; + int line; + char *msg; + char *arg1, *arg2, *arg3; +{ + if (CPP_OPTIONS (pfile)->pedantic_errors) + cpp_error_with_line (pfile, column, line, msg, arg1, arg2, arg3); + else + cpp_warning_with_line (pfile, line, column, msg, arg1, arg2, arg3); +} + +/* Report a warning (or an error if pedantic_errors) + giving specified file name and line number, not current. */ + +void +cpp_pedwarn_with_file_and_line (pfile, file, line, msg, arg1, arg2, arg3) + cpp_reader *pfile; + char *file; + int line; + char *msg; + char *arg1, *arg2, *arg3; +{ + if (!CPP_OPTIONS (pfile)->pedantic_errors + && CPP_OPTIONS (pfile)->inhibit_warnings) + return; + if (file != NULL) + cpp_file_line_for_message (pfile, file, line, -1); + cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, + msg, arg1, arg2, arg3); +} + +/* This defines "errno" properly for VMS, and gives us EACCES. */ +#include +#ifndef errno +extern int errno; +#endif + +#ifndef VMS +#ifndef HAVE_STRERROR +extern int sys_nerr; +#if defined(bsd4_4) +extern const char *const sys_errlist[]; +#else +extern char *sys_errlist[]; +#endif +#else /* HAVE_STRERROR */ +char *strerror (); +#endif +#else /* VMS */ +char *strerror (int,...); +#endif + +/* + * my_strerror - return the descriptive text associated with an `errno' code. + */ + +char * +my_strerror (errnum) + int errnum; +{ + char *result; + +#ifndef VMS +#ifndef HAVE_STRERROR + result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0); +#else + result = strerror (errnum); +#endif +#else /* VMS */ + /* VAXCRTL's strerror() takes an optional second argument, which only + matters when the first argument is EVMSERR. However, it's simplest + just to pass it unconditionally. `vaxc$errno' is declared in + , and maintained by the library in parallel with `errno'. + We assume that caller's `errnum' either matches the last setting of + `errno' by the library or else does not have the value `EVMSERR'. */ + + result = strerror (errnum, vaxc$errno); +#endif + + if (!result) + result = "undocumented I/O error"; + + return result; +} + +/* Error including a message from `errno'. */ + +void +cpp_error_from_errno (pfile, name) + cpp_reader *pfile; + char *name; +{ + int i; + cpp_buffer *ip = cpp_file_buffer (pfile); + + cpp_print_containing_files (pfile); + + if (ip != NULL) + cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1); + + cpp_message (pfile, 1, "%s: %s", name, my_strerror (errno)); +} + +void +cpp_perror_with_name (pfile, name) + cpp_reader *pfile; + char *name; +{ + cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno)); +} + +/* TODO: + * No pre-compiled header file support. + * + * Possibly different enum token codes for each C/C++ token. + * + * Should clean up remaining directives to that do_XXX functions + * only take two arguments and all have command_reads_line. + * + * Find and cleanup remaining uses of static variables, + * + * Support for trigraphs. + * + * Support -dM flag (dump_all_macros). + * + * Support for_lint flag. + */ diff --git a/contrib/gcc/cpplib.h b/contrib/gcc/cpplib.h new file mode 100644 index 00000000000..3075b7904d2 --- /dev/null +++ b/contrib/gcc/cpplib.h @@ -0,0 +1,651 @@ +/* Definitions for CPP library. + Copyright (C) 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994-95. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATIC_BUFFERS + +typedef unsigned char U_CHAR; + +struct parse_file; +typedef struct cpp_reader cpp_reader; +typedef struct cpp_buffer cpp_buffer; +typedef struct cpp_options cpp_options; +typedef struct hashnode cpp_hashnode; + +enum cpp_token { + CPP_EOF = -1, + CPP_OTHER = 0, + CPP_COMMENT = 1, + CPP_HSPACE, + CPP_VSPACE, /* newlines and #line directives */ + CPP_NAME, + CPP_NUMBER, + CPP_CHAR, + CPP_STRING, + CPP_DIRECTIVE, + CPP_LPAREN, /* "(" */ + CPP_RPAREN, /* ")" */ + CPP_LBRACE, /* "{" */ + CPP_RBRACE, /* "}" */ + CPP_COMMA, /* "," */ + CPP_SEMICOLON,/* ";" */ + CPP_3DOTS, /* "..." */ +#if 0 + CPP_ANDAND, /* "&&" */ + CPP_OROR, /* "||" */ + CPP_LSH, /* "<<" */ + CPP_RSH, /* ">>" */ + CPP_EQL, /* "==" */ + CPP_NEQ, /* "!=" */ + CPP_LEQ, /* "<=" */ + CPP_GEQ, /* ">=" */ + CPP_PLPL, /* "++" */ + CPP_MINMIN, /* "--" */ +#endif + /* POP_TOKEN is returned when we've popped a cpp_buffer. */ + CPP_POP +}; + +#ifndef PARAMS +#ifdef __STDC +#define PARAMS(P) P +#else +#define PARAMS(P) () +#endif +#endif /* !PARAMS */ + +typedef enum cpp_token (*parse_underflow_t) PARAMS((cpp_reader*)); +typedef int (*parse_cleanup_t) PARAMS((cpp_buffer *, cpp_reader*)); + +/* A parse_marker indicates a previous position, + which we can backtrack to. */ + +struct parse_marker { + cpp_buffer *buf; + struct parse_marker *next; + int position; +}; + +extern void parse_set_mark PARAMS ((struct parse_marker*, cpp_reader*)); +extern void parse_clear_mark PARAMS ((struct parse_marker*)); +extern void parse_goto_mark PARAMS((struct parse_marker*, cpp_reader*)); +extern void parse_move_mark PARAMS((struct parse_marker*, cpp_reader*)); + +extern int cpp_handle_options PARAMS ((cpp_reader*, int, char**)); +extern enum cpp_token cpp_get_token PARAMS ((struct parse_marker*)); +extern void cpp_skip_hspace PARAMS((cpp_reader*)); +extern enum cpp_token cpp_get_non_space_token PARAMS ((cpp_reader *)); + + +/* Maintain and search list of included files, for #import. */ + +#define IMPORT_HASH_SIZE 31 + +struct import_file { + char *name; + ino_t inode; + dev_t dev; + struct import_file *next; +}; + +/* If we have a huge buffer, may need to cache more recent counts */ +#define CPP_LINE_BASE(BUF) ((BUF)->buf + (BUF)->line_base) + +struct cpp_buffer { + unsigned char *buf; + unsigned char *cur; + unsigned char *rlimit; /* end of valid data */ + unsigned char *alimit; /* end of allocated buffer */ + unsigned char *prev; /* start of current token */ + + char *fname; + /* Filename specified with #line command. */ + char *nominal_fname; + + /* Record where in the search path this file was found. + For #include_next. */ + struct file_name_list *dir; + + long line_base; + long lineno; /* Line number at CPP_LINE_BASE. */ + long colno; /* Column number at CPP_LINE_BASE. */ +#ifndef STATIC_BUFFERS + cpp_buffer *chain; +#endif + parse_underflow_t underflow; + parse_cleanup_t cleanup; + void *data; + struct parse_marker *marks; + /* Value of if_stack at start of this file. + Used to prohibit unmatched #endif (etc) in an include file. */ + struct if_stack *if_stack; + + /* True if this is a header file included using . */ + char system_header_p; + char seen_eof; + + /* True if buffer contains escape sequences. + Currently there are are only two kind: + "@-" means following identifier should not be macro-expanded. + "@ " means a token-separator. This turns into " " in final output + if not stringizing and needed to separate tokens; otherwise nothing. + "@@" means a normal '@'. + (An '@' inside a string stands for itself and is never an escape.) */ + char has_escapes; +}; + +struct cpp_pending; /* Forward declaration - for C++. */ +struct file_name_map_list; + +typedef struct assertion_hashnode ASSERTION_HASHNODE; +#define ASSERTION_HASHSIZE 37 + +#ifdef STATIC_BUFFERS +/* Maximum nesting of cpp_buffers. We use a static limit, partly for + efficiency, and partly to limit runaway recursion. */ +#define CPP_STACK_MAX 200 +#endif + +struct cpp_reader { + unsigned char *limit; + parse_underflow_t get_token; + cpp_buffer *buffer; +#ifdef STATIC_BUFFERS + cpp_buffer buffer_stack[CPP_STACK_MAX]; +#endif + + int errors; /* Error counter for exit code */ + void *data; + + U_CHAR *token_buffer; + int token_buffer_size; + + /* Line where a newline was first seen in a string constant. */ + int multiline_string_line; + + /* Current depth in #include directives that use <...>. */ + int system_include_depth; + + /* List of included files that contained #pragma once. */ + struct file_name_list *dont_repeat_files; + + /* List of other included files. + If ->control_macro if nonzero, the file had a #ifndef + around the entire contents, and ->control_macro gives the macro name. */ + struct file_name_list *all_include_files; + + /* Current maximum length of directory names in the search path + for include files. (Altered as we get more of them.) */ + int max_include_len; + + /* Hash table of files already included with #include or #import. */ + struct import_file *import_hash_table[IMPORT_HASH_SIZE]; + + struct if_stack *if_stack; + + /* Nonzero means we are inside an IF during a -pcp run. In this mode + macro expansion is done, and preconditions are output for all macro + uses requiring them. */ + char pcp_inside_if; + + /* Nonzero means we have printed (while error reporting) a list of + containing files that matches the current status. */ + char input_stack_listing_current; + + /* If non-zero, macros are not expanded. */ + char no_macro_expand; + + /* Print column number in error messages. */ + char show_column; + + /* We're printed a warning recommending against using #import. */ + char import_warning; + + /* If true, character between '<' and '>' are a single (string) token. */ + char parsing_include_directive; + + /* True if escape sequences (as described for has_escapes in + parse_buffer) should be emitted. */ + char output_escapes; + + /* 0: Have seen non-white-space on this line. + 1: Only seen white space so far on this line. + 2: Only seen white space so far in this file. */ + char only_seen_white; + + /* Nonzero means this file was included with a -imacros or -include + command line and should not be recorded as an include file. */ + + int no_record_file; + + long lineno; + + struct tm *timebuf; + + ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE]; + + /* Buffer of -M output. */ + char *deps_buffer; + + /* Number of bytes allocated in above. */ + int deps_allocated_size; + + /* Number of bytes used. */ + int deps_size; + + /* Number of bytes since the last newline. */ + int deps_column; +}; + +#define CPP_BUF_PEEK(BUFFER) \ + ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur : EOF) +#define CPP_BUF_GET(BUFFER) \ + ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF) +#define CPP_FORWARD(BUFFER, N) ((BUFFER)->cur += (N)) + +/* Number of characters currently in PFILE's output buffer. */ +#define CPP_WRITTEN(PFILE) ((PFILE)->limit - (PFILE)->token_buffer) +#define CPP_PWRITTEN(PFILE) ((PFILE)->limit) + +/* Make sure PFILE->token_buffer has space for at least N more characters. */ +#define CPP_RESERVE(PFILE, N) \ + (CPP_WRITTEN (PFILE) + N > (PFILE)->token_buffer_size \ + && (cpp_grow_buffer (PFILE, N), 0)) + +/* Append string STR (of length N) to PFILE's output buffer. + Assume there is enough space. */ +#define CPP_PUTS_Q(PFILE, STR, N) \ + (bcopy (STR, (PFILE)->limit, (N)), (PFILE)->limit += (N)) +/* Append string STR (of length N) to PFILE's output buffer. Make space. */ +#define CPP_PUTS(PFILE, STR, N) CPP_RESERVE(PFILE, N), CPP_PUTS_Q(PFILE, STR,N) +/* Append character CH to PFILE's output buffer. Assume sufficient space. */ +#define CPP_PUTC_Q(PFILE, CH) (*(PFILE)->limit++ = (CH)) +/* Append character CH to PFILE's output buffer. Make space if need be. */ +#define CPP_PUTC(PFILE, CH) (CPP_RESERVE (PFILE, 1), CPP_PUTC_Q (PFILE, CH)) +/* Make sure PFILE->limit is followed by '\0'. */ +#define CPP_NUL_TERMINATE_Q(PFILE) (*(PFILE)->limit = 0) +#define CPP_NUL_TERMINATE(PFILE) (CPP_RESERVE(PFILE, 1), *(PFILE)->limit = 0) +#define CPP_ADJUST_WRITTEN(PFILE,DELTA) ((PFILE)->limit += (DELTA)) +#define CPP_SET_WRITTEN(PFILE,N) ((PFILE)->limit = (PFILE)->token_buffer + (N)) + +#define CPP_OPTIONS(PFILE) ((cpp_options*)(PFILE)->data) +#define CPP_BUFFER(PFILE) ((PFILE)->buffer) +#ifdef STATIC_BUFFERS +#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)+1) +#define CPP_NULL_BUFFER(PFILE) (&(PFILE)->buffer_stack[CPP_STACK_MAX]) +#else +#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->chain) +#define CPP_NULL_BUFFER(PFILE) ((cpp_buffer*)0) +#endif + +/* Pointed to by parse_file::data. */ +struct cpp_options { + char *in_fname; + + /* Name of output file, for error messages. */ + char *out_fname; + + struct file_name_map_list *map_list; + + /* Non-0 means -v, so print the full set of include dirs. */ + char verbose; + + /* Nonzero means use extra default include directories for C++. */ + + char cplusplus; + + /* Nonzero means handle cplusplus style comments */ + + char cplusplus_comments; + + /* Nonzero means handle #import, for objective C. */ + + char objc; + + /* Nonzero means this is an assembly file, and allow + unknown directives, which could be comments. */ + + int lang_asm; + + /* Nonzero means turn NOTREACHED into #pragma NOTREACHED etc */ + + char for_lint; + + /* Nonzero means handle CHILL comment syntax + and output CHILL string delimiter for __DATE___ etc. */ + + char chill; + + /* Nonzero means copy comments into the output file. */ + + char put_out_comments; + + /* Nonzero means don't process the ANSI trigraph sequences. */ + + char no_trigraphs; + + /* Nonzero means print the names of included files rather than + the preprocessed output. 1 means just the #include "...", + 2 means #include <...> as well. */ + + char print_deps; + + /* Nonzero if missing .h files in -M output are assumed to be generated + files and not errors. */ + + char print_deps_missing_files; + + /* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */ + char print_deps_append; + + /* Nonzero means print names of header files (-H). */ + + char print_include_names; + + /* Nonzero means try to make failure to fit ANSI C an error. */ + + char pedantic_errors; + + /* Nonzero means don't print warning messages. -w. */ + + char inhibit_warnings; + + /* Nonzero means warn if slash-star appears in a comment. */ + + char warn_comments; + + /* Nonzero means warn if there are any trigraphs. */ + + char warn_trigraphs; + + /* Nonzero means warn if #import is used. */ + + char warn_import; + + /* Nonzero means warn if a macro argument is (or would be) + stringified with -traditional. */ + + char warn_stringify; + + /* Nonzero means turn warnings into errors. */ + + char warnings_are_errors; + + /* Nonzero causes output not to be done, + but directives such as #define that have side effects + are still obeyed. */ + + char no_output; + + /* Nonzero means don't output line number information. */ + + char no_line_commands; + +/* Nonzero means output the text in failing conditionals, + inside #failed ... #endfailed. */ + + char output_conditionals; + + /* Nonzero means -I- has been seen, + so don't look for #include "foo" the source-file directory. */ + char ignore_srcdir; + +/* Zero means dollar signs are punctuation. + -$ stores 0; -traditional may store 1. Default is 1 for VMS, 0 otherwise. + This must be 0 for correct processing of this ANSI C program: + #define foo(a) #a + #define lose(b) foo (b) + #define test$ + lose (test) */ + char dollars_in_ident; +#ifndef DOLLARS_IN_IDENTIFIERS +#define DOLLARS_IN_IDENTIFIERS 1 +#endif + + /* Nonzero means try to imitate old fashioned non-ANSI preprocessor. */ + char traditional; + + /* Nonzero means give all the error messages the ANSI standard requires. */ + char pedantic; + + char done_initializing; + + struct file_name_list *include; /* First dir to search */ + /* First dir to search for */ + /* This is the first element to use for #include <...>. + If it is 0, use the entire chain for such includes. */ + struct file_name_list *first_bracket_include; + /* This is the first element in the chain that corresponds to + a directory of system header files. */ + struct file_name_list *first_system_include; + struct file_name_list *last_include; /* Last in chain */ + + /* Chain of include directories to put at the end of the other chain. */ + struct file_name_list *after_include; + struct file_name_list *last_after_include; /* Last in chain */ + + /* Chain to put at the start of the system include files. */ + struct file_name_list *before_system; + struct file_name_list *last_before_system; /* Last in chain */ + + /* Directory prefix that should replace `/usr' in the standard + include file directories. */ + char *include_prefix; + + char inhibit_predefs; + char no_standard_includes; + char no_standard_cplusplus_includes; + +/* dump_only means inhibit output of the preprocessed text + and instead output the definitions of all user-defined + macros in a form suitable for use as input to cccp. + dump_names means pass #define and the macro name through to output. + dump_definitions means pass the whole definition (plus #define) through +*/ + + enum {dump_none = 0, dump_only, dump_names, dump_definitions} + dump_macros; + +/* Nonzero means pass all #define and #undef directives which we actually + process through to the output stream. This feature is used primarily + to allow cc1 to record the #defines and #undefs for the sake of + debuggers which understand about preprocessor macros, but it may + also be useful with -E to figure out how symbols are defined, and + where they are defined. */ + int debug_output; + + /* Pending -D, -U and -A options, in reverse order. */ + struct cpp_pending *pending; + + /* File name which deps are being written to. + This is 0 if deps are being written to stdout. */ + char *deps_file; + + /* Target-name to write with the dependency information. */ + char *deps_target; +}; + +#define CPP_TRADITIONAL(PFILE) (CPP_OPTIONS(PFILE)-> traditional) +#define CPP_PEDANTIC(PFILE) (CPP_OPTIONS (PFILE)->pedantic) +#define CPP_PRINT_DEPS(PFILE) (CPP_OPTIONS (PFILE)->print_deps) + +/* Name under which this program was invoked. */ + +extern char *progname; + +/* The structure of a node in the hash table. The hash table + has entries for all tokens defined by #define commands (type T_MACRO), + plus some special tokens like __LINE__ (these each have their own + type, and the appropriate code is run when that type of node is seen. + It does not contain control words like "#define", which are recognized + by a separate piece of code. */ + +/* different flavors of hash nodes --- also used in keyword table */ +enum node_type { + T_DEFINE = 1, /* the `#define' keyword */ + T_INCLUDE, /* the `#include' keyword */ + T_INCLUDE_NEXT, /* the `#include_next' keyword */ + T_IMPORT, /* the `#import' keyword */ + T_IFDEF, /* the `#ifdef' keyword */ + T_IFNDEF, /* the `#ifndef' keyword */ + T_IF, /* the `#if' keyword */ + T_ELSE, /* `#else' */ + T_PRAGMA, /* `#pragma' */ + T_ELIF, /* `#elif' */ + T_UNDEF, /* `#undef' */ + T_LINE, /* `#line' */ + T_ERROR, /* `#error' */ + T_WARNING, /* `#warning' */ + T_ENDIF, /* `#endif' */ + T_SCCS, /* `#sccs', used on system V. */ + T_IDENT, /* `#ident', used on system V. */ + T_ASSERT, /* `#assert', taken from system V. */ + T_UNASSERT, /* `#unassert', taken from system V. */ + T_SPECLINE, /* special symbol `__LINE__' */ + T_DATE, /* `__DATE__' */ + T_FILE, /* `__FILE__' */ + T_BASE_FILE, /* `__BASE_FILE__' */ + T_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ + T_VERSION, /* `__VERSION__' */ + T_SIZE_TYPE, /* `__SIZE_TYPE__' */ + T_PTRDIFF_TYPE, /* `__PTRDIFF_TYPE__' */ + T_WCHAR_TYPE, /* `__WCHAR_TYPE__' */ + T_USER_LABEL_PREFIX_TYPE, /* `__USER_LABEL_PREFIX__' */ + T_REGISTER_PREFIX_TYPE, /* `__REGISTER_PREFIX__' */ + T_TIME, /* `__TIME__' */ + T_CONST, /* Constant value, used by `__STDC__' */ + T_MACRO, /* macro defined by `#define' */ + T_DISABLED, /* macro temporarily turned off for rescan */ + T_SPEC_DEFINED, /* special `defined' macro for use in #if statements */ + T_PCSTRING, /* precompiled string (hashval is KEYDEF *) */ + T_UNUSED /* Used for something not defined. */ + }; + +/* Structure returned by create_definition */ +typedef struct macrodef MACRODEF; +struct macrodef +{ + struct definition *defn; + U_CHAR *symnam; + int symlen; +}; + +/* Structure allocated for every #define. For a simple replacement + such as + #define foo bar , + nargs = -1, the `pattern' list is null, and the expansion is just + the replacement text. Nargs = 0 means a functionlike macro with no args, + e.g., + #define getchar() getc (stdin) . + When there are args, the expansion is the replacement text with the + args squashed out, and the reflist is a list describing how to + build the output from the input: e.g., "3 chars, then the 1st arg, + then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg". + The chars here come from the expansion. Whatever is left of the + expansion after the last arg-occurrence is copied after that arg. + Note that the reflist can be arbitrarily long--- + its length depends on the number of times the arguments appear in + the replacement text, not how many args there are. Example: + #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and + pattern list + { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL } + where (x, y) means (nchars, argno). */ + +typedef struct definition DEFINITION; +struct definition { + int nargs; + int length; /* length of expansion string */ + int predefined; /* True if the macro was builtin or */ + /* came from the command line */ + U_CHAR *expansion; + int line; /* Line number of definition */ + char *file; /* File of definition */ + char rest_args; /* Nonzero if last arg. absorbs the rest */ + struct reflist { + struct reflist *next; + char stringify; /* nonzero if this arg was preceded by a + # operator. */ + char raw_before; /* Nonzero if a ## operator before arg. */ + char raw_after; /* Nonzero if a ## operator after arg. */ + char rest_args; /* Nonzero if this arg. absorbs the rest */ + int nchars; /* Number of literal chars to copy before + this arg occurrence. */ + int argno; /* Number of arg to substitute (origin-0) */ + } *pattern; + union { + /* Names of macro args, concatenated in reverse order + with comma-space between them. + The only use of this is that we warn on redefinition + if this differs between the old and new definitions. */ + U_CHAR *argnames; + } args; +}; + +extern U_CHAR is_idchar[256]; + +/* Stack of conditionals currently in progress + (including both successful and failing conditionals). */ + +struct if_stack { + struct if_stack *next; /* for chaining to the next stack frame */ + char *fname; /* copied from input when frame is made */ + int lineno; /* similarly */ + int if_succeeded; /* true if a leg of this if-group + has been passed through rescan */ + U_CHAR *control_macro; /* For #ifndef at start of file, + this is the macro name tested. */ + enum node_type type; /* type of last directive seen in this group */ +}; +typedef struct if_stack IF_STACK_FRAME; + +extern void cpp_buf_line_and_col PARAMS((cpp_buffer*, long*, long*)); +extern cpp_buffer* cpp_file_buffer PARAMS((cpp_reader*)); +extern void cpp_define PARAMS ((cpp_reader*, U_CHAR*)); + +extern void cpp_error (); +extern void cpp_warning (); +extern void cpp_pedwarn (); +extern void cpp_error_with_line (); +extern void cpp_pedwarn_with_line (); +extern void cpp_pedwarn_with_file_and_line (); +extern void fatal (); +extern void cpp_error_from_errno (); +extern void cpp_perror_with_name (); +extern void cpp_pfatal_with_name (); + +extern void cpp_grow_buffer PARAMS ((cpp_reader*, long)); +extern int cpp_parse_escape PARAMS ((cpp_reader*, char**)); +extern cpp_buffer* cpp_push_buffer PARAMS ((cpp_reader *, U_CHAR*, long)); +extern cpp_buffer* cpp_pop_buffer PARAMS ((cpp_reader *)); + +extern cpp_hashnode* cpp_lookup PARAMS ((cpp_reader*, const U_CHAR*, + int, int)); + +#ifdef __cplusplus +} +#endif diff --git a/contrib/gcc/cppmain.c b/contrib/gcc/cppmain.c new file mode 100644 index 00000000000..506ce05f7e8 --- /dev/null +++ b/contrib/gcc/cppmain.c @@ -0,0 +1,100 @@ +/* CPP main program, using CPP Library. + Copyright (C) 1995 Free Software Foundation, Inc. + Written by Per Bothner, 1994-95. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#include "cpplib.h" +#include + +#ifndef EMACS +#include "config.h" +#endif /* not EMACS */ + +extern char *getenv (); + +char *progname; + +cpp_reader parse_in; +cpp_options options; + +/* More 'friendly' abort that prints the line and file. + config.h can #define abort fancy_abort if you like that sort of thing. */ + +void +fancy_abort () +{ + fatal ("Internal gcc abort."); +} + + +int +main (argc, argv) + int argc; + char **argv; +{ + char *p; + int i; + int argi = 1; /* Next argument to handle. */ + struct cpp_options *opts = &options; + + p = argv[0] + strlen (argv[0]); + while (p != argv[0] && p[-1] != '/') --p; + progname = p; + + init_parse_file (&parse_in); + parse_in.data = opts; + + init_parse_options (opts); + + argi += cpp_handle_options (&parse_in, argc - argi , argv + argi); + if (argi < argc) + fatal ("Invalid option `%s'", argv[argi]); + parse_in.show_column = 1; + + i = push_parse_file (&parse_in, opts->in_fname); + if (i != SUCCESS_EXIT_CODE) + return i; + + /* Now that we know the input file is valid, open the output. */ + + if (!opts->out_fname || !strcmp (opts->out_fname, "")) + opts->out_fname = "stdout"; + else if (! freopen (opts->out_fname, "w", stdout)) + cpp_pfatal_with_name (&parse_in, opts->out_fname); + + for (;;) + { + enum cpp_token kind; + if (! opts->no_output) + { + fwrite (parse_in.token_buffer, 1, CPP_WRITTEN (&parse_in), stdout); + } + parse_in.limit = parse_in.token_buffer; + kind = cpp_get_token (&parse_in); + if (kind == CPP_EOF) + break; + } + + cpp_finish (&parse_in); + + if (parse_in.errors) + exit (FATAL_EXIT_CODE); + exit (SUCCESS_EXIT_CODE); +} diff --git a/contrib/gcc/cross-make b/contrib/gcc/cross-make new file mode 100644 index 00000000000..33bf93088df --- /dev/null +++ b/contrib/gcc/cross-make @@ -0,0 +1,27 @@ +# Build libgcc1.a for a cross-compiler. +# By default this expects the user to provide libgcc1.a, +# and gives up immediately if the user has not done so. +LIBGCC1 = $(CROSS_LIBGCC1) + +# Specify tools and options for manipulating libraries for the target machine. +AR = $(AR_FOR_TARGET) +AR_FLAGS = $(AR_FOR_TARGET_FLAGS) +OLDAR = $(AR_FOR_TARGET) +OLDAR_FLAGS = $(AR_FOR_TARGET_FLAGS) +RANLIB = $(RANLIB_FOR_TARGET) +RANLIB_TEST = $(RANLIB_TEST_FOR_TARGET) + +# Dir to search for system headers. Normally /usr/include. +SYSTEM_HEADER_DIR = $(tooldir)/include + +# Don't try to compile the things we can't compile. +ALL = all.cross + +# Use cross-compiler version of float.h. +FLOAT_H = $(CROSS_FLOAT_H) + +# Don't install assert.h in /usr/local/include. +assertdir = $(tooldir)/include + +# Don't run fixproto +STMP_FIXPROTO = diff --git a/contrib/gcc/crtstuff.c b/contrib/gcc/crtstuff.c new file mode 100644 index 00000000000..8bd3b1abf4c --- /dev/null +++ b/contrib/gcc/crtstuff.c @@ -0,0 +1,324 @@ +/* Specialized bits of code needed to support construction and + destruction of file-scope objects in C++ code. + + Written by Ron Guilmette (rfg@netcom.com) with help from Richard Stallman. + +Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* As a special exception, if you link this library with files + compiled with GCC to produce an executable, this does not cause + the resulting executable to be covered by the GNU General Public License. + This exception does not however invalidate any other reasons why + the executable file might be covered by the GNU General Public License. */ + +/* This file is a bit like libgcc1.c/libgcc2.c in that it is compiled + multiple times and yields multiple .o files. + + This file is useful on target machines where the object file format + supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE). On + such systems, this file allows us to avoid running collect (or any + other such slow and painful kludge). Additionally, if the target + system supports a .init section, this file allows us to support the + linking of C++ code with a non-C++ main program. + + Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then + this file *will* make use of the .init section. If that symbol is + not defined however, then the .init section will not be used. + + Currently, only ELF and COFF are supported. It is likely however that + ROSE could also be supported, if someone was willing to do the work to + make whatever (small?) adaptations are needed. (Some work may be + needed on the ROSE assembler and linker also.) + + This file must be compiled with gcc. */ + +/* It is incorrect to include config.h here, because this file is being + compiled for the target, and hence definitions concerning only the host + do not apply. */ + +#include "tm.h" + +/* Provide default definitions for the pseudo-ops used to switch to the + .ctors and .dtors sections. + + Note that we want to give these sections the SHF_WRITE attribute + because these sections will actually contain data (i.e. tables of + addresses of functions in the current root executable or shared library + file) and, in the case of a shared library, the relocatable addresses + will have to be properly resolved/relocated (and then written into) by + the dynamic linker when it actually attaches the given shared library + to the executing process. (Note that on SVR4, you may wish to use the + `-z text' option to the ELF linker, when building a shared library, as + an additional check that you are doing everything right. But if you do + use the `-z text' option when building a shared library, you will get + errors unless the .ctors and .dtors sections are marked as writable + via the SHF_WRITE attribute.) */ + +#ifndef CTORS_SECTION_ASM_OP +#define CTORS_SECTION_ASM_OP ".section\t.ctors,\"aw\"" +#endif +#ifndef DTORS_SECTION_ASM_OP +#define DTORS_SECTION_ASM_OP ".section\t.dtors,\"aw\"" +#endif + +#ifdef OBJECT_FORMAT_ELF + +/* Declare a pointer to void function type. */ +typedef void (*func_ptr) (void); +#define STATIC static + +#else /* OBJECT_FORMAT_ELF */ + +#include "gbl-ctors.h" + +#ifndef ON_EXIT +#define ON_EXIT(a, b) +#endif +#define STATIC + +#endif /* OBJECT_FORMAT_ELF */ + +#ifdef CRT_BEGIN + +#ifdef INIT_SECTION_ASM_OP + +#ifdef OBJECT_FORMAT_ELF + +/* Run all the global destructors on exit from the program. */ + +/* Some systems place the number of pointers in the first word of the + table. On SVR4 however, that word is -1. In all cases, the table is + null-terminated. On SVR4, we start from the beginning of the list and + invoke each per-compilation-unit destructor routine in order + until we find that null. + + Note that this function MUST be static. There will be one of these + functions in each root executable and one in each shared library, but + although they all have the same code, each one is unique in that it + refers to one particular associated `__DTOR_LIST__' which belongs to the + same particular root executable or shared library file. */ + +static func_ptr __DTOR_LIST__[]; +static void +__do_global_dtors_aux () +{ + func_ptr *p; + for (p = __DTOR_LIST__ + 1; *p; p++) + (*p) (); +} + +/* Stick a call to __do_global_dtors_aux into the .fini section. */ +static void +fini_dummy () +{ + asm (FINI_SECTION_ASM_OP); + __do_global_dtors_aux (); +#ifdef FORCE_FINI_SECTION_ALIGN + FORCE_FINI_SECTION_ALIGN; +#endif + asm (TEXT_SECTION_ASM_OP); +} + +#else /* OBJECT_FORMAT_ELF */ + +/* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o + and once in crtend.o). It must be declared static to avoid a link + error. Here, we define __do_global_ctors as an externally callable + function. It is externally callable so that __main can invoke it when + INVOKE__main is defined. This has the additional effect of forcing cc1 + to switch to the .text section. */ +static void __do_global_ctors_aux (); +void __do_global_ctors () +{ +#ifdef INVOKE__main /* If __main won't actually call __do_global_ctors + then it doesn't matter what's inside the function. + The inside of __do_global_ctors_aux is called + automatically in that case. + And the Alliant fx2800 linker crashes + on this reference. So prevent the crash. */ + __do_global_ctors_aux (); +#endif +} + +asm (INIT_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */ + +/* On some svr4 systems, the initial .init section preamble code provided in + crti.o may do something, such as bump the stack, which we have to + undo before we reach the function prologue code for __do_global_ctors + (directly below). For such systems, define the macro INIT_SECTION_PREAMBLE + to expand into the code needed to undo the actions of the crti.o file. */ + +#ifdef INIT_SECTION_PREAMBLE + INIT_SECTION_PREAMBLE; +#endif + +/* A routine to invoke all of the global constructors upon entry to the + program. We put this into the .init section (for systems that have + such a thing) so that we can properly perform the construction of + file-scope static-storage C++ objects within shared libraries. */ + +static void +__do_global_ctors_aux () /* prologue goes in .init section */ +{ +#ifdef FORCE_INIT_SECTION_ALIGN + FORCE_INIT_SECTION_ALIGN; /* Explicit align before switch to .text */ +#endif + asm (TEXT_SECTION_ASM_OP); /* don't put epilogue and body in .init */ + DO_GLOBAL_CTORS_BODY; + ON_EXIT (__do_global_dtors, 0); +} + +#endif /* OBJECT_FORMAT_ELF */ +#endif /* defined(INIT_SECTION_ASM_OP) */ + +/* Force cc1 to switch to .data section. */ +static func_ptr force_to_data[0] = { }; + +/* NOTE: In order to be able to support SVR4 shared libraries, we arrange + to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__, + __DTOR_END__ } per root executable and also one set of these symbols + per shared library. So in any given whole process image, we may have + multiple definitions of each of these symbols. In order to prevent + these definitions from conflicting with one another, and in order to + ensure that the proper lists are used for the initialization/finalization + of each individual shared library (respectively), we give these symbols + only internal (i.e. `static') linkage, and we also make it a point to + refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__ + symbol in crtbegin.o, where they are defined. */ + +/* The -1 is a flag to __do_global_[cd]tors + indicating that this table does not start with a count of elements. */ +#ifdef CTOR_LIST_BEGIN +CTOR_LIST_BEGIN; +#else +asm (CTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */ +STATIC func_ptr __CTOR_LIST__[1] = { (func_ptr) (-1) }; +#endif + +#ifdef DTOR_LIST_BEGIN +DTOR_LIST_BEGIN; +#else +asm (DTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */ +STATIC func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) }; +#endif + +#endif /* defined(CRT_BEGIN) */ + +#ifdef CRT_END + +#ifdef INIT_SECTION_ASM_OP + +#ifdef OBJECT_FORMAT_ELF + +static func_ptr __CTOR_END__[]; +static void +__do_global_ctors_aux () +{ + func_ptr *p; + for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) + (*p) (); +} + +/* Stick a call to __do_global_ctors_aux into the .init section. */ +static void +init_dummy () +{ + asm (INIT_SECTION_ASM_OP); + __do_global_ctors_aux (); +#ifdef FORCE_INIT_SECTION_ALIGN + FORCE_INIT_SECTION_ALIGN; +#endif + asm (TEXT_SECTION_ASM_OP); + +/* This is a kludge. The Linux dynamic linker needs ___brk_addr, __environ + and atexit (). We have to make sure they are in the .dynsym section. We + accomplish it by making a dummy call here. This + code is never reached. */ + +#if defined(__linux__) && defined(__PIC__) + { + extern void *___brk_addr; + extern char **__environ; + + ___brk_addr = __environ; + atexit (); + } +#endif +} + +#else /* OBJECT_FORMAT_ELF */ + +/* Stick the real initialization code, followed by a normal sort of + function epilogue at the very end of the .init section for this + entire root executable file or for this entire shared library file. + + Note that we use some tricks here to get *just* the body and just + a function epilogue (but no function prologue) into the .init + section of the crtend.o file. Specifically, we switch to the .text + section, start to define a function, and then we switch to the .init + section just before the body code. + + Earlier on, we put the corresponding function prologue into the .init + section of the crtbegin.o file (which will be linked in first). + + Note that we want to invoke all constructors for C++ file-scope static- + storage objects AFTER any other possible initialization actions which + may be performed by the code in the .init section contributions made by + other libraries, etc. That's because those other initializations may + include setup operations for very primitive things (e.g. initializing + the state of the floating-point coprocessor, etc.) which should be done + before we start to execute any of the user's code. */ + +static void +__do_global_ctors_aux () /* prologue goes in .text section */ +{ + asm (INIT_SECTION_ASM_OP); + DO_GLOBAL_CTORS_BODY; + ON_EXIT (__do_global_dtors, 0); +} /* epilogue and body go in .init section */ + +#endif /* OBJECT_FORMAT_ELF */ + +#endif /* defined(INIT_SECTION_ASM_OP) */ + +/* Force cc1 to switch to .data section. */ +static func_ptr force_to_data[0] = { }; + +/* Put a word containing zero at the end of each of our two lists of function + addresses. Note that the words defined here go into the .ctors and .dtors + sections of the crtend.o file, and since that file is always linked in + last, these words naturally end up at the very ends of the two lists + contained in these two sections. */ + +#ifdef CTOR_LIST_END +CTOR_LIST_END; +#else +asm (CTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */ +STATIC func_ptr __CTOR_END__[1] = { (func_ptr) 0 }; +#endif + +#ifdef DTOR_LIST_END +DTOR_LIST_END; +#else +asm (DTORS_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */ +STATIC func_ptr __DTOR_END__[1] = { (func_ptr) 0 }; +#endif + +#endif /* defined(CRT_END) */ diff --git a/contrib/gcc/cse.c b/contrib/gcc/cse.c new file mode 100644 index 00000000000..efd05dedaf9 --- /dev/null +++ b/contrib/gcc/cse.c @@ -0,0 +1,8779 @@ +/* Common subexpression elimination for GNU compiler. + Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +#include "config.h" +/* Must precede rtl.h for FFS. */ +#include + +#include "rtl.h" +#include "regs.h" +#include "hard-reg-set.h" +#include "flags.h" +#include "real.h" +#include "insn-config.h" +#include "recog.h" + +#include + +/* The basic idea of common subexpression elimination is to go + through the code, keeping a record of expressions that would + have the same value at the current scan point, and replacing + expressions encountered with the cheapest equivalent expression. + + It is too complicated to keep track of the different possibilities + when control paths merge; so, at each label, we forget all that is + known and start fresh. This can be described as processing each + basic block separately. Note, however, that these are not quite + the same as the basic blocks found by a later pass and used for + data flow analysis and register packing. We do not need to start fresh + after a conditional jump instruction if there is no label there. + + We use two data structures to record the equivalent expressions: + a hash table for most expressions, and several vectors together + with "quantity numbers" to record equivalent (pseudo) registers. + + The use of the special data structure for registers is desirable + because it is faster. It is possible because registers references + contain a fairly small number, the register number, taken from + a contiguously allocated series, and two register references are + identical if they have the same number. General expressions + do not have any such thing, so the only way to retrieve the + information recorded on an expression other than a register + is to keep it in a hash table. + +Registers and "quantity numbers": + + At the start of each basic block, all of the (hardware and pseudo) + registers used in the function are given distinct quantity + numbers to indicate their contents. During scan, when the code + copies one register into another, we copy the quantity number. + When a register is loaded in any other way, we allocate a new + quantity number to describe the value generated by this operation. + `reg_qty' records what quantity a register is currently thought + of as containing. + + All real quantity numbers are greater than or equal to `max_reg'. + If register N has not been assigned a quantity, reg_qty[N] will equal N. + + Quantity numbers below `max_reg' do not exist and none of the `qty_...' + variables should be referenced with an index below `max_reg'. + + We also maintain a bidirectional chain of registers for each + quantity number. `qty_first_reg', `qty_last_reg', + `reg_next_eqv' and `reg_prev_eqv' hold these chains. + + The first register in a chain is the one whose lifespan is least local. + Among equals, it is the one that was seen first. + We replace any equivalent register with that one. + + If two registers have the same quantity number, it must be true that + REG expressions with `qty_mode' must be in the hash table for both + registers and must be in the same class. + + The converse is not true. Since hard registers may be referenced in + any mode, two REG expressions might be equivalent in the hash table + but not have the same quantity number if the quantity number of one + of the registers is not the same mode as those expressions. + +Constants and quantity numbers + + When a quantity has a known constant value, that value is stored + in the appropriate element of qty_const. This is in addition to + putting the constant in the hash table as is usual for non-regs. + + Whether a reg or a constant is preferred is determined by the configuration + macro CONST_COSTS and will often depend on the constant value. In any + event, expressions containing constants can be simplified, by fold_rtx. + + When a quantity has a known nearly constant value (such as an address + of a stack slot), that value is stored in the appropriate element + of qty_const. + + Integer constants don't have a machine mode. However, cse + determines the intended machine mode from the destination + of the instruction that moves the constant. The machine mode + is recorded in the hash table along with the actual RTL + constant expression so that different modes are kept separate. + +Other expressions: + + To record known equivalences among expressions in general + we use a hash table called `table'. It has a fixed number of buckets + that contain chains of `struct table_elt' elements for expressions. + These chains connect the elements whose expressions have the same + hash codes. + + Other chains through the same elements connect the elements which + currently have equivalent values. + + Register references in an expression are canonicalized before hashing + the expression. This is done using `reg_qty' and `qty_first_reg'. + The hash code of a register reference is computed using the quantity + number, not the register number. + + When the value of an expression changes, it is necessary to remove from the + hash table not just that expression but all expressions whose values + could be different as a result. + + 1. If the value changing is in memory, except in special cases + ANYTHING referring to memory could be changed. That is because + nobody knows where a pointer does not point. + The function `invalidate_memory' removes what is necessary. + + The special cases are when the address is constant or is + a constant plus a fixed register such as the frame pointer + or a static chain pointer. When such addresses are stored in, + we can tell exactly which other such addresses must be invalidated + due to overlap. `invalidate' does this. + All expressions that refer to non-constant + memory addresses are also invalidated. `invalidate_memory' does this. + + 2. If the value changing is a register, all expressions + containing references to that register, and only those, + must be removed. + + Because searching the entire hash table for expressions that contain + a register is very slow, we try to figure out when it isn't necessary. + Precisely, this is necessary only when expressions have been + entered in the hash table using this register, and then the value has + changed, and then another expression wants to be added to refer to + the register's new value. This sequence of circumstances is rare + within any one basic block. + + The vectors `reg_tick' and `reg_in_table' are used to detect this case. + reg_tick[i] is incremented whenever a value is stored in register i. + reg_in_table[i] holds -1 if no references to register i have been + entered in the table; otherwise, it contains the value reg_tick[i] had + when the references were entered. If we want to enter a reference + and reg_in_table[i] != reg_tick[i], we must scan and remove old references. + Until we want to enter a new entry, the mere fact that the two vectors + don't match makes the entries be ignored if anyone tries to match them. + + Registers themselves are entered in the hash table as well as in + the equivalent-register chains. However, the vectors `reg_tick' + and `reg_in_table' do not apply to expressions which are simple + register references. These expressions are removed from the table + immediately when they become invalid, and this can be done even if + we do not immediately search for all the expressions that refer to + the register. + + A CLOBBER rtx in an instruction invalidates its operand for further + reuse. A CLOBBER or SET rtx whose operand is a MEM:BLK + invalidates everything that resides in memory. + +Related expressions: + + Constant expressions that differ only by an additive integer + are called related. When a constant expression is put in + the table, the related expression with no constant term + is also entered. These are made to point at each other + so that it is possible to find out if there exists any + register equivalent to an expression related to a given expression. */ + +/* One plus largest register number used in this function. */ + +static int max_reg; + +/* Length of vectors indexed by quantity number. + We know in advance we will not need a quantity number this big. */ + +static int max_qty; + +/* Next quantity number to be allocated. + This is 1 + the largest number needed so far. */ + +static int next_qty; + +/* Indexed by quantity number, gives the first (or last) (pseudo) register + in the chain of registers that currently contain this quantity. */ + +static int *qty_first_reg; +static int *qty_last_reg; + +/* Index by quantity number, gives the mode of the quantity. */ + +static enum machine_mode *qty_mode; + +/* Indexed by quantity number, gives the rtx of the constant value of the + quantity, or zero if it does not have a known value. + A sum of the frame pointer (or arg pointer) plus a constant + can also be entered here. */ + +static rtx *qty_const; + +/* Indexed by qty number, gives the insn that stored the constant value + recorded in `qty_const'. */ + +static rtx *qty_const_insn; + +/* The next three variables are used to track when a comparison between a + quantity and some constant or register has been passed. In that case, we + know the results of the comparison in case we see it again. These variables + record a comparison that is known to be true. */ + +/* Indexed by qty number, gives the rtx code of a comparison with a known + result involving this quantity. If none, it is UNKNOWN. */ +static enum rtx_code *qty_comparison_code; + +/* Indexed by qty number, gives the constant being compared against in a + comparison of known result. If no such comparison, it is undefined. + If the comparison is not with a constant, it is zero. */ + +static rtx *qty_comparison_const; + +/* Indexed by qty number, gives the quantity being compared against in a + comparison of known result. If no such comparison, if it undefined. + If the comparison is not with a register, it is -1. */ + +static int *qty_comparison_qty; + +#ifdef HAVE_cc0 +/* For machines that have a CC0, we do not record its value in the hash + table since its use is guaranteed to be the insn immediately following + its definition and any other insn is presumed to invalidate it. + + Instead, we store below the value last assigned to CC0. If it should + happen to be a constant, it is stored in preference to the actual + assigned value. In case it is a constant, we store the mode in which + the constant should be interpreted. */ + +static rtx prev_insn_cc0; +static enum machine_mode prev_insn_cc0_mode; +#endif + +/* Previous actual insn. 0 if at first insn of basic block. */ + +static rtx prev_insn; + +/* Insn being scanned. */ + +static rtx this_insn; + +/* Index by (pseudo) register number, gives the quantity number + of the register's current contents. */ + +static int *reg_qty; + +/* Index by (pseudo) register number, gives the number of the next (or + previous) (pseudo) register in the chain of registers sharing the same + value. + + Or -1 if this register is at the end of the chain. + + If reg_qty[N] == N, reg_next_eqv[N] is undefined. */ + +static int *reg_next_eqv; +static int *reg_prev_eqv; + +/* Index by (pseudo) register number, gives the number of times + that register has been altered in the current basic block. */ + +static int *reg_tick; + +/* Index by (pseudo) register number, gives the reg_tick value at which + rtx's containing this register are valid in the hash table. + If this does not equal the current reg_tick value, such expressions + existing in the hash table are invalid. + If this is -1, no expressions containing this register have been + entered in the table. */ + +static int *reg_in_table; + +/* A HARD_REG_SET containing all the hard registers for which there is + currently a REG expression in the hash table. Note the difference + from the above variables, which indicate if the REG is mentioned in some + expression in the table. */ + +static HARD_REG_SET hard_regs_in_table; + +/* A HARD_REG_SET containing all the hard registers that are invalidated + by a CALL_INSN. */ + +static HARD_REG_SET regs_invalidated_by_call; + +/* Two vectors of ints: + one containing max_reg -1's; the other max_reg + 500 (an approximation + for max_qty) elements where element i contains i. + These are used to initialize various other vectors fast. */ + +static int *all_minus_one; +static int *consec_ints; + +/* CUID of insn that starts the basic block currently being cse-processed. */ + +static int cse_basic_block_start; + +/* CUID of insn that ends the basic block currently being cse-processed. */ + +static int cse_basic_block_end; + +/* Vector mapping INSN_UIDs to cuids. + The cuids are like uids but increase monotonically always. + We use them to see whether a reg is used outside a given basic block. */ + +static int *uid_cuid; + +/* Highest UID in UID_CUID. */ +static int max_uid; + +/* Get the cuid of an insn. */ + +#define INSN_CUID(INSN) (uid_cuid[INSN_UID (INSN)]) + +/* Nonzero if cse has altered conditional jump insns + in such a way that jump optimization should be redone. */ + +static int cse_jumps_altered; + +/* Nonzero if we put a LABEL_REF into the hash table. Since we may have put + it into an INSN without a REG_LABEL, we have to rerun jump after CSE + to put in the note. */ +static int recorded_label_ref; + +/* canon_hash stores 1 in do_not_record + if it notices a reference to CC0, PC, or some other volatile + subexpression. */ + +static int do_not_record; + +#ifdef LOAD_EXTEND_OP + +/* Scratch rtl used when looking for load-extended copy of a MEM. */ +static rtx memory_extend_rtx; +#endif + +/* canon_hash stores 1 in hash_arg_in_memory + if it notices a reference to memory within the expression being hashed. */ + +static int hash_arg_in_memory; + +/* canon_hash stores 1 in hash_arg_in_struct + if it notices a reference to memory that's part of a structure. */ + +static int hash_arg_in_struct; + +/* The hash table contains buckets which are chains of `struct table_elt's, + each recording one expression's information. + That expression is in the `exp' field. + + Those elements with the same hash code are chained in both directions + through the `next_same_hash' and `prev_same_hash' fields. + + Each set of expressions with equivalent values + are on a two-way chain through the `next_same_value' + and `prev_same_value' fields, and all point with + the `first_same_value' field at the first element in + that chain. The chain is in order of increasing cost. + Each element's cost value is in its `cost' field. + + The `in_memory' field is nonzero for elements that + involve any reference to memory. These elements are removed + whenever a write is done to an unidentified location in memory. + To be safe, we assume that a memory address is unidentified unless + the address is either a symbol constant or a constant plus + the frame pointer or argument pointer. + + The `in_struct' field is nonzero for elements that + involve any reference to memory inside a structure or array. + + The `related_value' field is used to connect related expressions + (that differ by adding an integer). + The related expressions are chained in a circular fashion. + `related_value' is zero for expressions for which this + chain is not useful. + + The `cost' field stores the cost of this element's expression. + + The `is_const' flag is set if the element is a constant (including + a fixed address). + + The `flag' field is used as a temporary during some search routines. + + The `mode' field is usually the same as GET_MODE (`exp'), but + if `exp' is a CONST_INT and has no machine mode then the `mode' + field is the mode it was being used as. Each constant is + recorded separately for each mode it is used with. */ + + +struct table_elt +{ + rtx exp; + struct table_elt *next_same_hash; + struct table_elt *prev_same_hash; + struct table_elt *next_same_value; + struct table_elt *prev_same_value; + struct table_elt *first_same_value; + struct table_elt *related_value; + int cost; + enum machine_mode mode; + char in_memory; + char in_struct; + char is_const; + char flag; +}; + +/* We don't want a lot of buckets, because we rarely have very many + things stored in the hash table, and a lot of buckets slows + down a lot of loops that happen frequently. */ +#define NBUCKETS 31 + +/* Compute hash code of X in mode M. Special-case case where X is a pseudo + register (hard registers may require `do_not_record' to be set). */ + +#define HASH(X, M) \ + (GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER \ + ? (((unsigned) REG << 7) + (unsigned) reg_qty[REGNO (X)]) % NBUCKETS \ + : canon_hash (X, M) % NBUCKETS) + +/* Determine whether register number N is considered a fixed register for CSE. + It is desirable to replace other regs with fixed regs, to reduce need for + non-fixed hard regs. + A reg wins if it is either the frame pointer or designated as fixed, + but not if it is an overlapping register. */ +#ifdef OVERLAPPING_REGNO_P +#define FIXED_REGNO_P(N) \ + (((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \ + || fixed_regs[N] || global_regs[N]) \ + && ! OVERLAPPING_REGNO_P ((N))) +#else +#define FIXED_REGNO_P(N) \ + ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \ + || fixed_regs[N] || global_regs[N]) +#endif + +/* Compute cost of X, as stored in the `cost' field of a table_elt. Fixed + hard registers and pointers into the frame are the cheapest with a cost + of 0. Next come pseudos with a cost of one and other hard registers with + a cost of 2. Aside from these special cases, call `rtx_cost'. */ + +#define CHEAP_REGNO(N) \ + ((N) == FRAME_POINTER_REGNUM || (N) == HARD_FRAME_POINTER_REGNUM \ + || (N) == STACK_POINTER_REGNUM || (N) == ARG_POINTER_REGNUM \ + || ((N) >= FIRST_VIRTUAL_REGISTER && (N) <= LAST_VIRTUAL_REGISTER) \ + || ((N) < FIRST_PSEUDO_REGISTER \ + && FIXED_REGNO_P (N) && REGNO_REG_CLASS (N) != NO_REGS)) + +/* A register is cheap if it is a user variable assigned to the register + or if its register number always corresponds to a cheap register. */ + +#define CHEAP_REG(N) \ + ((REG_USERVAR_P (N) && REGNO (N) < FIRST_PSEUDO_REGISTER) \ + || CHEAP_REGNO (REGNO (N))) + +#define COST(X) \ + (GET_CODE (X) == REG \ + ? (CHEAP_REG (X) ? 0 \ + : REGNO (X) >= FIRST_PSEUDO_REGISTER ? 1 \ + : 2) \ + : rtx_cost (X, SET) * 2) + +/* Determine if the quantity number for register X represents a valid index + into the `qty_...' variables. */ + +#define REGNO_QTY_VALID_P(N) (reg_qty[N] != (N)) + +static struct table_elt *table[NBUCKETS]; + +/* Chain of `struct table_elt's made so far for this function + but currently removed from the table. */ + +static struct table_elt *free_element_chain; + +/* Number of `struct table_elt' structures made so far for this function. */ + +static int n_elements_made; + +/* Maximum value `n_elements_made' has had so far in this compilation + for functions previously processed. */ + +static int max_elements_made; + +/* Surviving equivalence class when two equivalence classes are merged + by recording the effects of a jump in the last insn. Zero if the + last insn was not a conditional jump. */ + +static struct table_elt *last_jump_equiv_class; + +/* Set to the cost of a constant pool reference if one was found for a + symbolic constant. If this was found, it means we should try to + convert constants into constant pool entries if they don't fit in + the insn. */ + +static int constant_pool_entries_cost; + +/* Bits describing what kind of values in memory must be invalidated + for a particular instruction. If all three bits are zero, + no memory refs need to be invalidated. Each bit is more powerful + than the preceding ones, and if a bit is set then the preceding + bits are also set. + + Here is how the bits are set: + Pushing onto the stack invalidates only the stack pointer, + writing at a fixed address invalidates only variable addresses, + writing in a structure element at variable address + invalidates all but scalar variables, + and writing in anything else at variable address invalidates everything. */ + +struct write_data +{ + int sp : 1; /* Invalidate stack pointer. */ + int var : 1; /* Invalidate variable addresses. */ + int nonscalar : 1; /* Invalidate all but scalar variables. */ + int all : 1; /* Invalidate all memory refs. */ +}; + +/* Define maximum length of a branch path. */ + +#define PATHLENGTH 10 + +/* This data describes a block that will be processed by cse_basic_block. */ + +struct cse_basic_block_data { + /* Lowest CUID value of insns in block. */ + int low_cuid; + /* Highest CUID value of insns in block. */ + int high_cuid; + /* Total number of SETs in block. */ + int nsets; + /* Last insn in the block. */ + rtx last; + /* Size of current branch path, if any. */ + int path_size; + /* Current branch path, indicating which branches will be taken. */ + struct branch_path { + /* The branch insn. */ + rtx branch; + /* Whether it should be taken or not. AROUND is the same as taken + except that it is used when the destination label is not preceded + by a BARRIER. */ + enum taken {TAKEN, NOT_TAKEN, AROUND} status; + } path[PATHLENGTH]; +}; + +/* Nonzero if X has the form (PLUS frame-pointer integer). We check for + virtual regs here because the simplify_*_operation routines are called + by integrate.c, which is called before virtual register instantiation. */ + +#define FIXED_BASE_PLUS_P(X) \ + ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx \ + || (X) == arg_pointer_rtx \ + || (X) == virtual_stack_vars_rtx \ + || (X) == virtual_incoming_args_rtx \ + || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \ + && (XEXP (X, 0) == frame_pointer_rtx \ + || XEXP (X, 0) == hard_frame_pointer_rtx \ + || XEXP (X, 0) == arg_pointer_rtx \ + || XEXP (X, 0) == virtual_stack_vars_rtx \ + || XEXP (X, 0) == virtual_incoming_args_rtx))) + +/* Similar, but also allows reference to the stack pointer. + + This used to include FIXED_BASE_PLUS_P, however, we can't assume that + arg_pointer_rtx by itself is nonzero, because on at least one machine, + the i960, the arg pointer is zero when it is unused. */ + +#define NONZERO_BASE_PLUS_P(X) \ + ((X) == frame_pointer_rtx || (X) == hard_frame_pointer_rtx \ + || (X) == virtual_stack_vars_rtx \ + || (X) == virtual_incoming_args_rtx \ + || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \ + && (XEXP (X, 0) == frame_pointer_rtx \ + || XEXP (X, 0) == hard_frame_pointer_rtx \ + || XEXP (X, 0) == arg_pointer_rtx \ + || XEXP (X, 0) == virtual_stack_vars_rtx \ + || XEXP (X, 0) == virtual_incoming_args_rtx)) \ + || (X) == stack_pointer_rtx \ + || (X) == virtual_stack_dynamic_rtx \ + || (X) == virtual_outgoing_args_rtx \ + || (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT \ + && (XEXP (X, 0) == stack_pointer_rtx \ + || XEXP (X, 0) == virtual_stack_dynamic_rtx \ + || XEXP (X, 0) == virtual_outgoing_args_rtx))) + +static void new_basic_block PROTO((void)); +static void make_new_qty PROTO((int)); +static void make_regs_eqv PROTO((int, int)); +static void delete_reg_equiv PROTO((int)); +static int mention_regs PROTO((rtx)); +static int insert_regs PROTO((rtx, struct table_elt *, int)); +static void free_element PROTO((struct table_elt *)); +static void remove_from_table PROTO((struct table_elt *, unsigned)); +static struct table_elt *get_element PROTO((void)); +static struct table_elt *lookup PROTO((rtx, unsigned, enum machine_mode)), + *lookup_for_remove PROTO((rtx, unsigned, enum machine_mode)); +static rtx lookup_as_function PROTO((rtx, enum rtx_code)); +static struct table_elt *insert PROTO((rtx, struct table_elt *, unsigned, + enum machine_mode)); +static void merge_equiv_classes PROTO((struct table_elt *, + struct table_elt *)); +static void invalidate PROTO((rtx, enum machine_mode)); +static void remove_invalid_refs PROTO((int)); +static void rehash_using_reg PROTO((rtx)); +static void invalidate_memory PROTO((struct write_data *)); +static void invalidate_for_call PROTO((void)); +static rtx use_related_value PROTO((rtx, struct table_elt *)); +static unsigned canon_hash PROTO((rtx, enum machine_mode)); +static unsigned safe_hash PROTO((rtx, enum machine_mode)); +static int exp_equiv_p PROTO((rtx, rtx, int, int)); +static void set_nonvarying_address_components PROTO((rtx, int, rtx *, + HOST_WIDE_INT *, + HOST_WIDE_INT *)); +static int refers_to_p PROTO((rtx, rtx)); +static int refers_to_mem_p PROTO((rtx, rtx, HOST_WIDE_INT, + HOST_WIDE_INT)); +static int cse_rtx_addr_varies_p PROTO((rtx)); +static rtx canon_reg PROTO((rtx, rtx)); +static void find_best_addr PROTO((rtx, rtx *)); +static enum rtx_code find_comparison_args PROTO((enum rtx_code, rtx *, rtx *, + enum machine_mode *, + enum machine_mode *)); +static rtx cse_gen_binary PROTO((enum rtx_code, enum machine_mode, + rtx, rtx)); +static rtx simplify_plus_minus PROTO((enum rtx_code, enum machine_mode, + rtx, rtx)); +static rtx fold_rtx PROTO((rtx, rtx)); +static rtx equiv_constant PROTO((rtx)); +static void record_jump_equiv PROTO((rtx, int)); +static void record_jump_cond PROTO((enum rtx_code, enum machine_mode, + rtx, rtx, int)); +static void cse_insn PROTO((rtx, int)); +static void note_mem_written PROTO((rtx, struct write_data *)); +static void invalidate_from_clobbers PROTO((struct write_data *, rtx)); +static rtx cse_process_notes PROTO((rtx, rtx)); +static void cse_around_loop PROTO((rtx)); +static void invalidate_skipped_set PROTO((rtx, rtx)); +static void invalidate_skipped_block PROTO((rtx)); +static void cse_check_loop_start PROTO((rtx, rtx)); +static void cse_set_around_loop PROTO((rtx, rtx, rtx)); +static rtx cse_basic_block PROTO((rtx, rtx, struct branch_path *, int)); +static void count_reg_usage PROTO((rtx, int *, rtx, int)); + +extern int rtx_equal_function_value_matters; + +/* Return an estimate of the cost of computing rtx X. + One use is in cse, to decide which expression to keep in the hash table. + Another is in rtl generation, to pick the cheapest way to multiply. + Other uses like the latter are expected in the future. */ + +/* Return the right cost to give to an operation + to make the cost of the corresponding register-to-register instruction + N times that of a fast register-to-register instruction. */ + +#define COSTS_N_INSNS(N) ((N) * 4 - 2) + +int +rtx_cost (x, outer_code) + rtx x; + enum rtx_code outer_code; +{ + register int i, j; + register enum rtx_code code; + register char *fmt; + register int total; + + if (x == 0) + return 0; + + /* Compute the default costs of certain things. + Note that RTX_COSTS can override the defaults. */ + + code = GET_CODE (x); + switch (code) + { + case MULT: + /* Count multiplication by 2**n as a shift, + because if we are considering it, we would output it as a shift. */ + if (GET_CODE (XEXP (x, 1)) == CONST_INT + && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) + total = 2; + else + total = COSTS_N_INSNS (5); + break; + case DIV: + case UDIV: + case MOD: + case UMOD: + total = COSTS_N_INSNS (7); + break; + case USE: + /* Used in loop.c and combine.c as a marker. */ + total = 0; + break; + case ASM_OPERANDS: + /* We don't want these to be used in substitutions because + we have no way of validating the resulting insn. So assign + anything containing an ASM_OPERANDS a very high cost. */ + total = 1000; + break; + default: + total = 2; + } + + switch (code) + { + case REG: + return ! CHEAP_REG (x); + + case SUBREG: + /* If we can't tie these modes, make this expensive. The larger + the mode, the more expensive it is. */ + if (! MODES_TIEABLE_P (GET_MODE (x), GET_MODE (SUBREG_REG (x)))) + return COSTS_N_INSNS (2 + + GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD); + return 2; +#ifdef RTX_COSTS + RTX_COSTS (x, code, outer_code); +#endif + CONST_COSTS (x, code, outer_code); + } + + /* Sum the costs of the sub-rtx's, plus cost of this operation, + which is already in total. */ + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + if (fmt[i] == 'e') + total += rtx_cost (XEXP (x, i), code); + else if (fmt[i] == 'E') + for (j = 0; j < XVECLEN (x, i); j++) + total += rtx_cost (XVECEXP (x, i, j), code); + + return total; +} + +/* Clear the hash table and initialize each register with its own quantity, + for a new basic block. */ + +static void +new_basic_block () +{ + register int i; + + next_qty = max_reg; + + bzero ((char *) reg_tick, max_reg * sizeof (int)); + + bcopy ((char *) all_minus_one, (char *) reg_in_table, + max_reg * sizeof (int)); + bcopy ((char *) consec_ints, (char *) reg_qty, max_reg * sizeof (int)); + CLEAR_HARD_REG_SET (hard_regs_in_table); + + /* The per-quantity values used to be initialized here, but it is + much faster to initialize each as it is made in `make_new_qty'. */ + + for (i = 0; i < NBUCKETS; i++) + { + register struct table_elt *this, *next; + for (this = table[i]; this; this = next) + { + next = this->next_same_hash; + free_element (this); + } + } + + bzero ((char *) table, sizeof table); + + prev_insn = 0; + +#ifdef HAVE_cc0 + prev_insn_cc0 = 0; +#endif +} + +/* Say that register REG contains a quantity not in any register before + and initialize that quantity. */ + +static void +make_new_qty (reg) + register int reg; +{ + register int q; + + if (next_qty >= max_qty) + abort (); + + q = reg_qty[reg] = next_qty++; + qty_first_reg[q] = reg; + qty_last_reg[q] = reg; + qty_const[q] = qty_const_insn[q] = 0; + qty_comparison_code[q] = UNKNOWN; + + reg_next_eqv[reg] = reg_prev_eqv[reg] = -1; +} + +/* Make reg NEW equivalent to reg OLD. + OLD is not changing; NEW is. */ + +static void +make_regs_eqv (new, old) + register int new, old; +{ + register int lastr, firstr; + register int q = reg_qty[old]; + + /* Nothing should become eqv until it has a "non-invalid" qty number. */ + if (! REGNO_QTY_VALID_P (old)) + abort (); + + reg_qty[new] = q; + firstr = qty_first_reg[q]; + lastr = qty_last_reg[q]; + + /* Prefer fixed hard registers to anything. Prefer pseudo regs to other + hard regs. Among pseudos, if NEW will live longer than any other reg + of the same qty, and that is beyond the current basic block, + make it the new canonical replacement for this qty. */ + if (! (firstr < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (firstr)) + /* Certain fixed registers might be of the class NO_REGS. This means + that not only can they not be allocated by the compiler, but + they cannot be used in substitutions or canonicalizations + either. */ + && (new >= FIRST_PSEUDO_REGISTER || REGNO_REG_CLASS (new) != NO_REGS) + && ((new < FIRST_PSEUDO_REGISTER && FIXED_REGNO_P (new)) + || (new >= FIRST_PSEUDO_REGISTER + && (firstr < FIRST_PSEUDO_REGISTER + || ((uid_cuid[regno_last_uid[new]] > cse_basic_block_end + || (uid_cuid[regno_first_uid[new]] + < cse_basic_block_start)) + && (uid_cuid[regno_last_uid[new]] + > uid_cuid[regno_last_uid[firstr]])))))) + { + reg_prev_eqv[firstr] = new; + reg_next_eqv[new] = firstr; + reg_prev_eqv[new] = -1; + qty_first_reg[q] = new; + } + else + { + /* If NEW is a hard reg (known to be non-fixed), insert at end. + Otherwise, insert before any non-fixed hard regs that are at the + end. Registers of class NO_REGS cannot be used as an + equivalent for anything. */ + while (lastr < FIRST_PSEUDO_REGISTER && reg_prev_eqv[lastr] >= 0 + && (REGNO_REG_CLASS (lastr) == NO_REGS || ! FIXED_REGNO_P (lastr)) + && new >= FIRST_PSEUDO_REGISTER) + lastr = reg_prev_eqv[lastr]; + reg_next_eqv[new] = reg_next_eqv[lastr]; + if (reg_next_eqv[lastr] >= 0) + reg_prev_eqv[reg_next_eqv[lastr]] = new; + else + qty_last_reg[q] = new; + reg_next_eqv[lastr] = new; + reg_prev_eqv[new] = lastr; + } +} + +/* Remove REG from its equivalence class. */ + +static void +delete_reg_equiv (reg) + register int reg; +{ + register int q = reg_qty[reg]; + register int p, n; + + /* If invalid, do nothing. */ + if (q == reg) + return; + + p = reg_prev_eqv[reg]; + n = reg_next_eqv[reg]; + + if (n != -1) + reg_prev_eqv[n] = p; + else + qty_last_reg[q] = p; + if (p != -1) + reg_next_eqv[p] = n; + else + qty_first_reg[q] = n; + + reg_qty[reg] = reg; +} + +/* Remove any invalid expressions from the hash table + that refer to any of the registers contained in expression X. + + Make sure that newly inserted references to those registers + as subexpressions will be considered valid. + + mention_regs is not called when a register itself + is being stored in the table. + + Return 1 if we have done something that may have changed the hash code + of X. */ + +static int +mention_regs (x) + rtx x; +{ + register enum rtx_code code; + register int i, j; + register char *fmt; + register int changed = 0; + + if (x == 0) + return 0; + + code = GET_CODE (x); + if (code == REG) + { + register int regno = REGNO (x); + register int endregno + = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1 + : HARD_REGNO_NREGS (regno, GET_MODE (x))); + int i; + + for (i = regno; i < endregno; i++) + { + if (reg_in_table[i] >= 0 && reg_in_table[i] != reg_tick[i]) + remove_invalid_refs (i); + + reg_in_table[i] = reg_tick[i]; + } + + return 0; + } + + /* If X is a comparison or a COMPARE and either operand is a register + that does not have a quantity, give it one. This is so that a later + call to record_jump_equiv won't cause X to be assigned a different + hash code and not found in the table after that call. + + It is not necessary to do this here, since rehash_using_reg can + fix up the table later, but doing this here eliminates the need to + call that expensive function in the most common case where the only + use of the register is in the comparison. */ + + if (code == COMPARE || GET_RTX_CLASS (code) == '<') + { + if (GET_CODE (XEXP (x, 0)) == REG + && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 0)))) + if (insert_regs (XEXP (x, 0), NULL_PTR, 0)) + { + rehash_using_reg (XEXP (x, 0)); + changed = 1; + } + + if (GET_CODE (XEXP (x, 1)) == REG + && ! REGNO_QTY_VALID_P (REGNO (XEXP (x, 1)))) + if (insert_regs (XEXP (x, 1), NULL_PTR, 0)) + { + rehash_using_reg (XEXP (x, 1)); + changed = 1; + } + } + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + if (fmt[i] == 'e') + changed |= mention_regs (XEXP (x, i)); + else if (fmt[i] == 'E') + for (j = 0; j < XVECLEN (x, i); j++) + changed |= mention_regs (XVECEXP (x, i, j)); + + return changed; +} + +/* Update the register quantities for inserting X into the hash table + with a value equivalent to CLASSP. + (If the class does not contain a REG, it is irrelevant.) + If MODIFIED is nonzero, X is a destination; it is being modified. + Note that delete_reg_equiv should be called on a register + before insert_regs is done on that register with MODIFIED != 0. + + Nonzero value means that elements of reg_qty have changed + so X's hash code may be different. */ + +static int +insert_regs (x, classp, modified) + rtx x; + struct table_elt *classp; + int modified; +{ + if (GET_CODE (x) == REG) + { + register int regno = REGNO (x); + + /* If REGNO is in the equivalence table already but is of the + wrong mode for that equivalence, don't do anything here. */ + + if (REGNO_QTY_VALID_P (regno) + && qty_mode[reg_qty[regno]] != GET_MODE (x)) + return 0; + + if (modified || ! REGNO_QTY_VALID_P (regno)) + { + if (classp) + for (classp = classp->first_same_value; + classp != 0; + classp = classp->next_same_value) + if (GET_CODE (classp->exp) == REG + && GET_MODE (classp->exp) == GET_MODE (x)) + { + make_regs_eqv (regno, REGNO (classp->exp)); + return 1; + } + + make_new_qty (regno); + qty_mode[reg_qty[regno]] = GET_MODE (x); + return 1; + } + + return 0; + } + + /* If X is a SUBREG, we will likely be inserting the inner register in the + table. If that register doesn't have an assigned quantity number at + this point but does later, the insertion that we will be doing now will + not be accessible because its hash code will have changed. So assign + a quantity number now. */ + + else if (GET_CODE (x) == SUBREG && GET_CODE (SUBREG_REG (x)) == REG + && ! REGNO_QTY_VALID_P (REGNO (SUBREG_REG (x)))) + { + insert_regs (SUBREG_REG (x), NULL_PTR, 0); + mention_regs (SUBREG_REG (x)); + return 1; + } + else + return mention_regs (x); +} + +/* Look in or update the hash table. */ + +/* Put the element ELT on the list of free elements. */ + +static void +free_element (elt) + struct table_elt *elt; +{ + elt->next_same_hash = free_element_chain; + free_element_chain = elt; +} + +/* Return an element that is free for use. */ + +static struct table_elt * +get_element () +{ + struct table_elt *elt = free_element_chain; + if (elt) + { + free_element_chain = elt->next_same_hash; + return elt; + } + n_elements_made++; + return (struct table_elt *) oballoc (sizeof (struct table_elt)); +} + +/* Remove table element ELT from use in the table. + HASH is its hash code, made using the HASH macro. + It's an argument because often that is known in advance + and we save much time not recomputing it. */ + +static void +remove_from_table (elt, hash) + register struct table_elt *elt; + unsigned hash; +{ + if (elt == 0) + return; + + /* Mark this element as removed. See cse_insn. */ + elt->first_same_value = 0; + + /* Remove the table element from its equivalence class. */ + + { + register struct table_elt *prev = elt->prev_same_value; + register struct table_elt *next = elt->next_same_value; + + if (next) next->prev_same_value = prev; + + if (prev) + prev->next_same_value = next; + else + { + register struct table_elt *newfirst = next; + while (next) + { + next->first_same_value = newfirst; + next = next->next_same_value; + } + } + } + + /* Remove the table element from its hash bucket. */ + + { + register struct table_elt *prev = elt->prev_same_hash; + register struct table_elt *next = elt->next_same_hash; + + if (next) next->prev_same_hash = prev; + + if (prev) + prev->next_same_hash = next; + else if (table[hash] == elt) + table[hash] = next; + else + { + /* This entry is not in the proper hash bucket. This can happen + when two classes were merged by `merge_equiv_classes'. Search + for the hash bucket that it heads. This happens only very + rarely, so the cost is acceptable. */ + for (hash = 0; hash < NBUCKETS; hash++) + if (table[hash] == elt) + table[hash] = next; + } + } + + /* Remove the table element from its related-value circular chain. */ + + if (elt->related_value != 0 && elt->related_value != elt) + { + register struct table_elt *p = elt->related_value; + while (p->related_value != elt) + p = p->related_value; + p->related_value = elt->related_value; + if (p->related_value == p) + p->related_value = 0; + } + + free_element (elt); +} + +/* Look up X in the hash table and return its table element, + or 0 if X is not in the table. + + MODE is the machine-mode of X, or if X is an integer constant + with VOIDmode then MODE is the mode with which X will be used. + + Here we are satisfied to find an expression whose tree structure + looks like X. */ + +static struct table_elt * +lookup (x, hash, mode) + rtx x; + unsigned hash; + enum machine_mode mode; +{ + register struct table_elt *p; + + for (p = table[hash]; p; p = p->next_same_hash) + if (mode == p->mode && ((x == p->exp && GET_CODE (x) == REG) + || exp_equiv_p (x, p->exp, GET_CODE (x) != REG, 0))) + return p; + + return 0; +} + +/* Like `lookup' but don't care whether the table element uses invalid regs. + Also ignore discrepancies in the machine mode of a register. */ + +static struct table_elt * +lookup_for_remove (x, hash, mode) + rtx x; + unsigned hash; + enum machine_mode mode; +{ + register struct table_elt *p; + + if (GET_CODE (x) == REG) + { + int regno = REGNO (x); + /* Don't check the machine mode when comparing registers; + invalidating (REG:SI 0) also invalidates (REG:DF 0). */ + for (p = table[hash]; p; p = p->next_same_hash) + if (GET_CODE (p->exp) == REG + && REGNO (p->exp) == regno) + return p; + } + else + { + for (p = table[hash]; p; p = p->next_same_hash) + if (mode == p->mode && (x == p->exp || exp_equiv_p (x, p->exp, 0, 0))) + return p; + } + + return 0; +} + +/* Look for an expression equivalent to X and with code CODE. + If one is found, return that expression. */ + +static rtx +lookup_as_function (x, code) + rtx x; + enum rtx_code code; +{ + register struct table_elt *p = lookup (x, safe_hash (x, VOIDmode) % NBUCKETS, + GET_MODE (x)); + if (p == 0) + return 0; + + for (p = p->first_same_value; p; p = p->next_same_value) + { + if (GET_CODE (p->exp) == code + /* Make sure this is a valid entry in the table. */ + && exp_equiv_p (p->exp, p->exp, 1, 0)) + return p->exp; + } + + return 0; +} + +/* Insert X in the hash table, assuming HASH is its hash code + and CLASSP is an element of the class it should go in + (or 0 if a new class should be made). + It is inserted at the proper position to keep the class in + the order cheapest first. + + MODE is the machine-mode of X, or if X is an integer constant + with VOIDmode then MODE is the mode with which X will be used. + + For elements of equal cheapness, the most recent one + goes in front, except that the first element in the list + remains first unless a cheaper element is added. The order of + pseudo-registers does not matter, as canon_reg will be called to + find the cheapest when a register is retrieved from the table. + + The in_memory field in the hash table element is set to 0. + The caller must set it nonzero if appropriate. + + You should call insert_regs (X, CLASSP, MODIFY) before calling here, + and if insert_regs returns a nonzero value + you must then recompute its hash code before calling here. + + If necessary, update table showing constant values of quantities. */ + +#define CHEAPER(X,Y) ((X)->cost < (Y)->cost) + +static struct table_elt * +insert (x, classp, hash, mode) + register rtx x; + register struct table_elt *classp; + unsigned hash; + enum machine_mode mode; +{ + register struct table_elt *elt; + + /* If X is a register and we haven't made a quantity for it, + something is wrong. */ + if (GET_CODE (x) == REG && ! REGNO_QTY_VALID_P (REGNO (x))) + abort (); + + /* If X is a hard register, show it is being put in the table. */ + if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER) + { + int regno = REGNO (x); + int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); + int i; + + for (i = regno; i < endregno; i++) + SET_HARD_REG_BIT (hard_regs_in_table, i); + } + + /* If X is a label, show we recorded it. */ + if (GET_CODE (x) == LABEL_REF + || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)) + recorded_label_ref = 1; + + /* Put an element for X into the right hash bucket. */ + + elt = get_element (); + elt->exp = x; + elt->cost = COST (x); + elt->next_same_value = 0; + elt->prev_same_value = 0; + elt->next_same_hash = table[hash]; + elt->prev_same_hash = 0; + elt->related_value = 0; + elt->in_memory = 0; + elt->mode = mode; + elt->is_const = (CONSTANT_P (x) + /* GNU C++ takes advantage of this for `this' + (and other const values). */ + || (RTX_UNCHANGING_P (x) + && GET_CODE (x) == REG + && REGNO (x) >= FIRST_PSEUDO_REGISTER) + || FIXED_BASE_PLUS_P (x)); + + if (table[hash]) + table[hash]->prev_same_hash = elt; + table[hash] = elt; + + /* Put it into the proper value-class. */ + if (classp) + { + classp = classp->first_same_value; + if (CHEAPER (elt, classp)) + /* Insert at the head of the class */ + { + register struct table_elt *p; + elt->next_same_value = classp; + classp->prev_same_value = elt; + elt->first_same_value = elt; + + for (p = classp; p; p = p->next_same_value) + p->first_same_value = elt; + } + else + { + /* Insert not at head of the class. */ + /* Put it after the last element cheaper than X. */ + register struct table_elt *p, *next; + for (p = classp; (next = p->next_same_value) && CHEAPER (next, elt); + p = next); + /* Put it after P and before NEXT. */ + elt->next_same_value = next; + if (next) + next->prev_same_value = elt; + elt->prev_same_value = p; + p->next_same_value = elt; + elt->first_same_value = classp; + } + } + else + elt->first_same_value = elt; + + /* If this is a constant being set equivalent to a register or a register + being set equivalent to a constant, note the constant equivalence. + + If this is a constant, it cannot be equivalent to a different constant, + and a constant is the only thing that can be cheaper than a register. So + we know the register is the head of the class (before the constant was + inserted). + + If this is a register that is not already known equivalent to a + constant, we must check the entire class. + + If this is a register that is already known equivalent to an insn, + update `qty_const_insn' to show that `this_insn' is the latest + insn making that quantity equivalent to the constant. */ + + if (elt->is_const && classp && GET_CODE (classp->exp) == REG + && GET_CODE (x) != REG) + { + qty_const[reg_qty[REGNO (classp->exp)]] + = gen_lowpart_if_possible (qty_mode[reg_qty[REGNO (classp->exp)]], x); + qty_const_insn[reg_qty[REGNO (classp->exp)]] = this_insn; + } + + else if (GET_CODE (x) == REG && classp && ! qty_const[reg_qty[REGNO (x)]] + && ! elt->is_const) + { + register struct table_elt *p; + + for (p = classp; p != 0; p = p->next_same_value) + { + if (p->is_const && GET_CODE (p->exp) != REG) + { + qty_const[reg_qty[REGNO (x)]] + = gen_lowpart_if_possible (GET_MODE (x), p->exp); + qty_const_insn[reg_qty[REGNO (x)]] = this_insn; + break; + } + } + } + + else if (GET_CODE (x) == REG && qty_const[reg_qty[REGNO (x)]] + && GET_MODE (x) == qty_mode[reg_qty[REGNO (x)]]) + qty_const_insn[reg_qty[REGNO (x)]] = this_insn; + + /* If this is a constant with symbolic value, + and it has a term with an explicit integer value, + link it up with related expressions. */ + if (GET_CODE (x) == CONST) + { + rtx subexp = get_related_value (x); + unsigned subhash; + struct table_elt *subelt, *subelt_prev; + + if (subexp != 0) + { + /* Get the integer-free subexpression in the hash table. */ + subhash = safe_hash (subexp, mode) % NBUCKETS; + subelt = lookup (subexp, subhash, mode); + if (subelt == 0) + subelt = insert (subexp, NULL_PTR, subhash, mode); + /* Initialize SUBELT's circular chain if it has none. */ + if (subelt->related_value == 0) + subelt->related_value = subelt; + /* Find the element in the circular chain that precedes SUBELT. */ + subelt_prev = subelt; + while (subelt_prev->related_value != subelt) + subelt_prev = subelt_prev->related_value; + /* Put new ELT into SUBELT's circular chain just before SUBELT. + This way the element that follows SUBELT is the oldest one. */ + elt->related_value = subelt_prev->related_value; + subelt_prev->related_value = elt; + } + } + + return elt; +} + +/* Given two equivalence classes, CLASS1 and CLASS2, put all the entries from + CLASS2 into CLASS1. This is done when we have reached an insn which makes + the two classes equivalent. + + CLASS1 will be the surviving class; CLASS2 should not be used after this + call. + + Any invalid entries in CLASS2 will not be copied. */ + +static void +merge_equiv_classes (class1, class2) + struct table_elt *class1, *class2; +{ + struct table_elt *elt, *next, *new; + + /* Ensure we start with the head of the classes. */ + class1 = class1->first_same_value; + class2 = class2->first_same_value; + + /* If they were already equal, forget it. */ + if (class1 == class2) + return; + + for (elt = class2; elt; elt = next) + { + unsigned hash; + rtx exp = elt->exp; + enum machine_mode mode = elt->mode; + + next = elt->next_same_value; + + /* Remove old entry, make a new one in CLASS1's class. + Don't do this for invalid entries as we cannot find their + hash code (it also isn't necessary). */ + if (GET_CODE (exp) == REG || exp_equiv_p (exp, exp, 1, 0)) + { + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + hash = HASH (exp, mode); + + if (GET_CODE (exp) == REG) + delete_reg_equiv (REGNO (exp)); + + remove_from_table (elt, hash); + + if (insert_regs (exp, class1, 0)) + { + rehash_using_reg (exp); + hash = HASH (exp, mode); + } + new = insert (exp, class1, hash, mode); + new->in_memory = hash_arg_in_memory; + new->in_struct = hash_arg_in_struct; + } + } +} + +/* Remove from the hash table, or mark as invalid, + all expressions whose values could be altered by storing in X. + X is a register, a subreg, or a memory reference with nonvarying address + (because, when a memory reference with a varying address is stored in, + all memory references are removed by invalidate_memory + so specific invalidation is superfluous). + FULL_MODE, if not VOIDmode, indicates that this much should be invalidated + instead of just the amount indicated by the mode of X. This is only used + for bitfield stores into memory. + + A nonvarying address may be just a register or just + a symbol reference, or it may be either of those plus + a numeric offset. */ + +static void +invalidate (x, full_mode) + rtx x; + enum machine_mode full_mode; +{ + register int i; + register struct table_elt *p; + rtx base; + HOST_WIDE_INT start, end; + + /* If X is a register, dependencies on its contents + are recorded through the qty number mechanism. + Just change the qty number of the register, + mark it as invalid for expressions that refer to it, + and remove it itself. */ + + if (GET_CODE (x) == REG) + { + register int regno = REGNO (x); + register unsigned hash = HASH (x, GET_MODE (x)); + + /* Remove REGNO from any quantity list it might be on and indicate + that it's value might have changed. If it is a pseudo, remove its + entry from the hash table. + + For a hard register, we do the first two actions above for any + additional hard registers corresponding to X. Then, if any of these + registers are in the table, we must remove any REG entries that + overlap these registers. */ + + delete_reg_equiv (regno); + reg_tick[regno]++; + + if (regno >= FIRST_PSEUDO_REGISTER) + { + /* Because a register can be referenced in more than one mode, + we might have to remove more than one table entry. */ + + struct table_elt *elt; + + while (elt = lookup_for_remove (x, hash, GET_MODE (x))) + remove_from_table (elt, hash); + } + else + { + HOST_WIDE_INT in_table + = TEST_HARD_REG_BIT (hard_regs_in_table, regno); + int endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); + int tregno, tendregno; + register struct table_elt *p, *next; + + CLEAR_HARD_REG_BIT (hard_regs_in_table, regno); + + for (i = regno + 1; i < endregno; i++) + { + in_table |= TEST_HARD_REG_BIT (hard_regs_in_table, i); + CLEAR_HARD_REG_BIT (hard_regs_in_table, i); + delete_reg_equiv (i); + reg_tick[i]++; + } + + if (in_table) + for (hash = 0; hash < NBUCKETS; hash++) + for (p = table[hash]; p; p = next) + { + next = p->next_same_hash; + + if (GET_CODE (p->exp) != REG + || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER) + continue; + + tregno = REGNO (p->exp); + tendregno + = tregno + HARD_REGNO_NREGS (tregno, GET_MODE (p->exp)); + if (tendregno > regno && tregno < endregno) + remove_from_table (p, hash); + } + } + + return; + } + + if (GET_CODE (x) == SUBREG) + { + if (GET_CODE (SUBREG_REG (x)) != REG) + abort (); + invalidate (SUBREG_REG (x), VOIDmode); + return; + } + + /* X is not a register; it must be a memory reference with + a nonvarying address. Remove all hash table elements + that refer to overlapping pieces of memory. */ + + if (GET_CODE (x) != MEM) + abort (); + + if (full_mode == VOIDmode) + full_mode = GET_MODE (x); + + set_nonvarying_address_components (XEXP (x, 0), GET_MODE_SIZE (full_mode), + &base, &start, &end); + + for (i = 0; i < NBUCKETS; i++) + { + register struct table_elt *next; + for (p = table[i]; p; p = next) + { + next = p->next_same_hash; + if (refers_to_mem_p (p->exp, base, start, end)) + remove_from_table (p, i); + } + } +} + +/* Remove all expressions that refer to register REGNO, + since they are already invalid, and we are about to + mark that register valid again and don't want the old + expressions to reappear as valid. */ + +static void +remove_invalid_refs (regno) + int regno; +{ + register int i; + register struct table_elt *p, *next; + + for (i = 0; i < NBUCKETS; i++) + for (p = table[i]; p; p = next) + { + next = p->next_same_hash; + if (GET_CODE (p->exp) != REG + && refers_to_regno_p (regno, regno + 1, p->exp, NULL_PTR)) + remove_from_table (p, i); + } +} + +/* Recompute the hash codes of any valid entries in the hash table that + reference X, if X is a register, or SUBREG_REG (X) if X is a SUBREG. + + This is called when we make a jump equivalence. */ + +static void +rehash_using_reg (x) + rtx x; +{ + int i; + struct table_elt *p, *next; + unsigned hash; + + if (GET_CODE (x) == SUBREG) + x = SUBREG_REG (x); + + /* If X is not a register or if the register is known not to be in any + valid entries in the table, we have no work to do. */ + + if (GET_CODE (x) != REG + || reg_in_table[REGNO (x)] < 0 + || reg_in_table[REGNO (x)] != reg_tick[REGNO (x)]) + return; + + /* Scan all hash chains looking for valid entries that mention X. + If we find one and it is in the wrong hash chain, move it. We can skip + objects that are registers, since they are handled specially. */ + + for (i = 0; i < NBUCKETS; i++) + for (p = table[i]; p; p = next) + { + next = p->next_same_hash; + if (GET_CODE (p->exp) != REG && reg_mentioned_p (x, p->exp) + && exp_equiv_p (p->exp, p->exp, 1, 0) + && i != (hash = safe_hash (p->exp, p->mode) % NBUCKETS)) + { + if (p->next_same_hash) + p->next_same_hash->prev_same_hash = p->prev_same_hash; + + if (p->prev_same_hash) + p->prev_same_hash->next_same_hash = p->next_same_hash; + else + table[i] = p->next_same_hash; + + p->next_same_hash = table[hash]; + p->prev_same_hash = 0; + if (table[hash]) + table[hash]->prev_same_hash = p; + table[hash] = p; + } + } +} + +/* Remove from the hash table all expressions that reference memory, + or some of them as specified by *WRITES. */ + +static void +invalidate_memory (writes) + struct write_data *writes; +{ + register int i; + register struct table_elt *p, *next; + int all = writes->all; + int nonscalar = writes->nonscalar; + + for (i = 0; i < NBUCKETS; i++) + for (p = table[i]; p; p = next) + { + next = p->next_same_hash; + if (p->in_memory + && (all + || (nonscalar && p->in_struct) + || cse_rtx_addr_varies_p (p->exp))) + remove_from_table (p, i); + } +} + +/* Remove from the hash table any expression that is a call-clobbered + register. Also update their TICK values. */ + +static void +invalidate_for_call () +{ + int regno, endregno; + int i; + unsigned hash; + struct table_elt *p, *next; + int in_table = 0; + + /* Go through all the hard registers. For each that is clobbered in + a CALL_INSN, remove the register from quantity chains and update + reg_tick if defined. Also see if any of these registers is currently + in the table. */ + + for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) + if (TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)) + { + delete_reg_equiv (regno); + if (reg_tick[regno] >= 0) + reg_tick[regno]++; + + in_table |= (TEST_HARD_REG_BIT (hard_regs_in_table, regno) != 0); + } + + /* In the case where we have no call-clobbered hard registers in the + table, we are done. Otherwise, scan the table and remove any + entry that overlaps a call-clobbered register. */ + + if (in_table) + for (hash = 0; hash < NBUCKETS; hash++) + for (p = table[hash]; p; p = next) + { + next = p->next_same_hash; + + if (GET_CODE (p->exp) != REG + || REGNO (p->exp) >= FIRST_PSEUDO_REGISTER) + continue; + + regno = REGNO (p->exp); + endregno = regno + HARD_REGNO_NREGS (regno, GET_MODE (p->exp)); + + for (i = regno; i < endregno; i++) + if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i)) + { + remove_from_table (p, hash); + break; + } + } +} + +/* Given an expression X of type CONST, + and ELT which is its table entry (or 0 if it + is not in the hash table), + return an alternate expression for X as a register plus integer. + If none can be found, return 0. */ + +static rtx +use_related_value (x, elt) + rtx x; + struct table_elt *elt; +{ + register struct table_elt *relt = 0; + register struct table_elt *p, *q; + HOST_WIDE_INT offset; + + /* First, is there anything related known? + If we have a table element, we can tell from that. + Otherwise, must look it up. */ + + if (elt != 0 && elt->related_value != 0) + relt = elt; + else if (elt == 0 && GET_CODE (x) == CONST) + { + rtx subexp = get_related_value (x); + if (subexp != 0) + relt = lookup (subexp, + safe_hash (subexp, GET_MODE (subexp)) % NBUCKETS, + GET_MODE (subexp)); + } + + if (relt == 0) + return 0; + + /* Search all related table entries for one that has an + equivalent register. */ + + p = relt; + while (1) + { + /* This loop is strange in that it is executed in two different cases. + The first is when X is already in the table. Then it is searching + the RELATED_VALUE list of X's class (RELT). The second case is when + X is not in the table. Then RELT points to a class for the related + value. + + Ensure that, whatever case we are in, that we ignore classes that have + the same value as X. */ + + if (rtx_equal_p (x, p->exp)) + q = 0; + else + for (q = p->first_same_value; q; q = q->next_same_value) + if (GET_CODE (q->exp) == REG) + break; + + if (q) + break; + + p = p->related_value; + + /* We went all the way around, so there is nothing to be found. + Alternatively, perhaps RELT was in the table for some other reason + and it has no related values recorded. */ + if (p == relt || p == 0) + break; + } + + if (q == 0) + return 0; + + offset = (get_integer_term (x) - get_integer_term (p->exp)); + /* Note: OFFSET may be 0 if P->xexp and X are related by commutativity. */ + return plus_constant (q->exp, offset); +} + +/* Hash an rtx. We are careful to make sure the value is never negative. + Equivalent registers hash identically. + MODE is used in hashing for CONST_INTs only; + otherwise the mode of X is used. + + Store 1 in do_not_record if any subexpression is volatile. + + Store 1 in hash_arg_in_memory if X contains a MEM rtx + which does not have the RTX_UNCHANGING_P bit set. + In this case, also store 1 in hash_arg_in_struct + if there is a MEM rtx which has the MEM_IN_STRUCT_P bit set. + + Note that cse_insn knows that the hash code of a MEM expression + is just (int) MEM plus the hash code of the address. */ + +static unsigned +canon_hash (x, mode) + rtx x; + enum machine_mode mode; +{ + register int i, j; + register unsigned hash = 0; + register enum rtx_code code; + register char *fmt; + + /* repeat is used to turn tail-recursion into iteration. */ + repeat: + if (x == 0) + return hash; + + code = GET_CODE (x); + switch (code) + { + case REG: + { + register int regno = REGNO (x); + + /* On some machines, we can't record any non-fixed hard register, + because extending its life will cause reload problems. We + consider ap, fp, and sp to be fixed for this purpose. + On all machines, we can't record any global registers. */ + + if (regno < FIRST_PSEUDO_REGISTER + && (global_regs[regno] +#ifdef SMALL_REGISTER_CLASSES + || (! fixed_regs[regno] + && regno != FRAME_POINTER_REGNUM + && regno != HARD_FRAME_POINTER_REGNUM + && regno != ARG_POINTER_REGNUM + && regno != STACK_POINTER_REGNUM) +#endif + )) + { + do_not_record = 1; + return 0; + } + hash += ((unsigned) REG << 7) + (unsigned) reg_qty[regno]; + return hash; + } + + case CONST_INT: + { + unsigned HOST_WIDE_INT tem = INTVAL (x); + hash += ((unsigned) CONST_INT << 7) + (unsigned) mode + tem; + return hash; + } + + case CONST_DOUBLE: + /* This is like the general case, except that it only counts + the integers representing the constant. */ + hash += (unsigned) code + (unsigned) GET_MODE (x); + if (GET_MODE (x) != VOIDmode) + for (i = 2; i < GET_RTX_LENGTH (CONST_DOUBLE); i++) + { + unsigned tem = XINT (x, i); + hash += tem; + } + else + hash += ((unsigned) CONST_DOUBLE_LOW (x) + + (unsigned) CONST_DOUBLE_HIGH (x)); + return hash; + + /* Assume there is only one rtx object for any given label. */ + case LABEL_REF: + hash + += ((unsigned) LABEL_REF << 7) + (unsigned HOST_WIDE_INT) XEXP (x, 0); + return hash; + + case SYMBOL_REF: + hash + += ((unsigned) SYMBOL_REF << 7) + (unsigned HOST_WIDE_INT) XSTR (x, 0); + return hash; + + case MEM: + if (MEM_VOLATILE_P (x)) + { + do_not_record = 1; + return 0; + } + if (! RTX_UNCHANGING_P (x)) + { + hash_arg_in_memory = 1; + if (MEM_IN_STRUCT_P (x)) hash_arg_in_struct = 1; + } + /* Now that we have already found this special case, + might as well speed it up as much as possible. */ + hash += (unsigned) MEM; + x = XEXP (x, 0); + goto repeat; + + case PRE_DEC: + case PRE_INC: + case POST_DEC: + case POST_INC: + case PC: + case CC0: + case CALL: + case UNSPEC_VOLATILE: + do_not_record = 1; + return 0; + + case ASM_OPERANDS: + if (MEM_VOLATILE_P (x)) + { + do_not_record = 1; + return 0; + } + } + + i = GET_RTX_LENGTH (code) - 1; + hash += (unsigned) code + (unsigned) GET_MODE (x); + fmt = GET_RTX_FORMAT (code); + for (; i >= 0; i--) + { + if (fmt[i] == 'e') + { + rtx tem = XEXP (x, i); + + /* If we are about to do the last recursive call + needed at this level, change it into iteration. + This function is called enough to be worth it. */ + if (i == 0) + { + x = tem; + goto repeat; + } + hash += canon_hash (tem, 0); + } + else if (fmt[i] == 'E') + for (j = 0; j < XVECLEN (x, i); j++) + hash += canon_hash (XVECEXP (x, i, j), 0); + else if (fmt[i] == 's') + { + register unsigned char *p = (unsigned char *) XSTR (x, i); + if (p) + while (*p) + hash += *p++; + } + else if (fmt[i] == 'i') + { + register unsigned tem = XINT (x, i); + hash += tem; + } + else + abort (); + } + return hash; +} + +/* Like canon_hash but with no side effects. */ + +static unsigned +safe_hash (x, mode) + rtx x; + enum machine_mode mode; +{ + int save_do_not_record = do_not_record; + int save_hash_arg_in_memory = hash_arg_in_memory; + int save_hash_arg_in_struct = hash_arg_in_struct; + unsigned hash = canon_hash (x, mode); + hash_arg_in_memory = save_hash_arg_in_memory; + hash_arg_in_struct = save_hash_arg_in_struct; + do_not_record = save_do_not_record; + return hash; +} + +/* Return 1 iff X and Y would canonicalize into the same thing, + without actually constructing the canonicalization of either one. + If VALIDATE is nonzero, + we assume X is an expression being processed from the rtl + and Y was found in the hash table. We check register refs + in Y for being marked as valid. + + If EQUAL_VALUES is nonzero, we allow a register to match a constant value + that is known to be in the register. Ordinarily, we don't allow them + to match, because letting them match would cause unpredictable results + in all the places that search a hash table chain for an equivalent + for a given value. A possible equivalent that has different structure + has its hash code computed from different data. Whether the hash code + is the same as that of the the given value is pure luck. */ + +static int +exp_equiv_p (x, y, validate, equal_values) + rtx x, y; + int validate; + int equal_values; +{ + register int i, j; + register enum rtx_code code; + register char *fmt; + + /* Note: it is incorrect to assume an expression is equivalent to itself + if VALIDATE is nonzero. */ + if (x == y && !validate) + return 1; + if (x == 0 || y == 0) + return x == y; + + code = GET_CODE (x); + if (code != GET_CODE (y)) + { + if (!equal_values) + return 0; + + /* If X is a constant and Y is a register or vice versa, they may be + equivalent. We only have to validate if Y is a register. */ + if (CONSTANT_P (x) && GET_CODE (y) == REG + && REGNO_QTY_VALID_P (REGNO (y)) + && GET_MODE (y) == qty_mode[reg_qty[REGNO (y)]] + && rtx_equal_p (x, qty_const[reg_qty[REGNO (y)]]) + && (! validate || reg_in_table[REGNO (y)] == reg_tick[REGNO (y)])) + return 1; + + if (CONSTANT_P (y) && code == REG + && REGNO_QTY_VALID_P (REGNO (x)) + && GET_MODE (x) == qty_mode[reg_qty[REGNO (x)]] + && rtx_equal_p (y, qty_const[reg_qty[REGNO (x)]])) + return 1; + + return 0; + } + + /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */ + if (GET_MODE (x) != GET_MODE (y)) + return 0; + + switch (code) + { + case PC: + case CC0: + return x == y; + + case CONST_INT: + return INTVAL (x) == INTVAL (y); + + case LABEL_REF: + return XEXP (x, 0) == XEXP (y, 0); + + case SYMBOL_REF: + return XSTR (x, 0) == XSTR (y, 0); + + case REG: + { + int regno = REGNO (y); + int endregno + = regno + (regno >= FIRST_PSEUDO_REGISTER ? 1 + : HARD_REGNO_NREGS (regno, GET_MODE (y))); + int i; + + /* If the quantities are not the same, the expressions are not + equivalent. If there are and we are not to validate, they + are equivalent. Otherwise, ensure all regs are up-to-date. */ + + if (reg_qty[REGNO (x)] != reg_qty[regno]) + return 0; + + if (! validate) + return 1; + + for (i = regno; i < endregno; i++) + if (reg_in_table[i] != reg_tick[i]) + return 0; + + return 1; + } + + /* For commutative operations, check both orders. */ + case PLUS: + case MULT: + case AND: + case IOR: + case XOR: + case NE: + case EQ: + return ((exp_equiv_p (XEXP (x, 0), XEXP (y, 0), validate, equal_values) + && exp_equiv_p (XEXP (x, 1), XEXP (y, 1), + validate, equal_values)) + || (exp_equiv_p (XEXP (x, 0), XEXP (y, 1), + validate, equal_values) + && exp_equiv_p (XEXP (x, 1), XEXP (y, 0), + validate, equal_values))); + } + + /* Compare the elements. If any pair of corresponding elements + fail to match, return 0 for the whole things. */ + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + switch (fmt[i]) + { + case 'e': + if (! exp_equiv_p (XEXP (x, i), XEXP (y, i), validate, equal_values)) + return 0; + break; + + case 'E': + if (XVECLEN (x, i) != XVECLEN (y, i)) + return 0; + for (j = 0; j < XVECLEN (x, i); j++) + if (! exp_equiv_p (XVECEXP (x, i, j), XVECEXP (y, i, j), + validate, equal_values)) + return 0; + break; + + case 's': + if (strcmp (XSTR (x, i), XSTR (y, i))) + return 0; + break; + + case 'i': + if (XINT (x, i) != XINT (y, i)) + return 0; + break; + + case 'w': + if (XWINT (x, i) != XWINT (y, i)) + return 0; + break; + + case '0': + break; + + default: + abort (); + } + } + + return 1; +} + +/* Return 1 iff any subexpression of X matches Y. + Here we do not require that X or Y be valid (for registers referred to) + for being in the hash table. */ + +static int +refers_to_p (x, y) + rtx x, y; +{ + register int i; + register enum rtx_code code; + register char *fmt; + + repeat: + if (x == y) + return 1; + if (x == 0 || y == 0) + return 0; + + code = GET_CODE (x); + /* If X as a whole has the same code as Y, they may match. + If so, return 1. */ + if (code == GET_CODE (y)) + { + if (exp_equiv_p (x, y, 0, 1)) + return 1; + } + + /* X does not match, so try its subexpressions. */ + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + if (fmt[i] == 'e') + { + if (i == 0) + { + x = XEXP (x, 0); + goto repeat; + } + else + if (refers_to_p (XEXP (x, i), y)) + return 1; + } + else if (fmt[i] == 'E') + { + int j; + for (j = 0; j < XVECLEN (x, i); j++) + if (refers_to_p (XVECEXP (x, i, j), y)) + return 1; + } + + return 0; +} + +/* Given ADDR and SIZE (a memory address, and the size of the memory reference), + set PBASE, PSTART, and PEND which correspond to the base of the address, + the starting offset, and ending offset respectively. + + ADDR is known to be a nonvarying address. */ + +/* ??? Despite what the comments say, this function is in fact frequently + passed varying addresses. This does not appear to cause any problems. */ + +static void +set_nonvarying_address_components (addr, size, pbase, pstart, pend) + rtx addr; + int size; + rtx *pbase; + HOST_WIDE_INT *pstart, *pend; +{ + rtx base; + HOST_WIDE_INT start, end; + + base = addr; + start = 0; + end = 0; + + /* Registers with nonvarying addresses usually have constant equivalents; + but the frame pointer register is also possible. */ + if (GET_CODE (base) == REG + && qty_const != 0 + && REGNO_QTY_VALID_P (REGNO (base)) + && qty_mode[reg_qty[REGNO (base)]] == GET_MODE (base) + && qty_const[reg_qty[REGNO (base)]] != 0) + base = qty_const[reg_qty[REGNO (base)]]; + else if (GET_CODE (base) == PLUS + && GET_CODE (XEXP (base, 1)) == CONST_INT + && GET_CODE (XEXP (base, 0)) == REG + && qty_const != 0 + && REGNO_QTY_VALID_P (REGNO (XEXP (base, 0))) + && (qty_mode[reg_qty[REGNO (XEXP (base, 0))]] + == GET_MODE (XEXP (base, 0))) + && qty_const[reg_qty[REGNO (XEXP (base, 0))]]) + { + start = INTVAL (XEXP (base, 1)); + base = qty_const[reg_qty[REGNO (XEXP (base, 0))]]; + } + /* This can happen as the result of virtual register instantiation, + if the initial offset is too large to be a valid address. */ + else if (GET_CODE (base) == PLUS + && GET_CODE (XEXP (base, 0)) == REG + && GET_CODE (XEXP (base, 1)) == REG + && qty_const != 0 + && REGNO_QTY_VALID_P (REGNO (XEXP (base, 0))) + && (qty_mode[reg_qty[REGNO (XEXP (base, 0))]] + == GET_MODE (XEXP (base, 0))) + && qty_const[reg_qty[REGNO (XEXP (base, 0))]] + && REGNO_QTY_VALID_P (REGNO (XEXP (base, 1))) + && (qty_mode[reg_qty[REGNO (XEXP (base, 1))]] + == GET_MODE (XEXP (base, 1))) + && qty_const[reg_qty[REGNO (XEXP (base, 1))]]) + { + rtx tem = qty_const[reg_qty[REGNO (XEXP (base, 1))]]; + base = qty_const[reg_qty[REGNO (XEXP (base, 0))]]; + + /* One of the two values must be a constant. */ + if (GET_CODE (base) != CONST_INT) + { + if (GET_CODE (tem) != CONST_INT) + abort (); + start = INTVAL (tem); + } + else + { + start = INTVAL (base); + base = tem; + } + } + + /* Handle everything that we can find inside an address that has been + viewed as constant. */ + + while (1) + { + /* If no part of this switch does a "continue", the code outside + will exit this loop. */ + + switch (GET_CODE (base)) + { + case LO_SUM: + /* By definition, operand1 of a LO_SUM is the associated constant + address. Use the associated constant address as the base + instead. */ + base = XEXP (base, 1); + continue; + + case CONST: + /* Strip off CONST. */ + base = XEXP (base, 0); + continue; + + case PLUS: + if (GET_CODE (XEXP (base, 1)) == CONST_INT) + { + start += INTVAL (XEXP (base, 1)); + base = XEXP (base, 0); + continue; + } + break; + + case AND: + /* Handle the case of an AND which is the negative of a power of + two. This is used to represent unaligned memory operations. */ + if (GET_CODE (XEXP (base, 1)) == CONST_INT + && exact_log2 (- INTVAL (XEXP (base, 1))) > 0) + { + set_nonvarying_address_components (XEXP (base, 0), size, + pbase, pstart, pend); + + /* Assume the worst misalignment. START is affected, but not + END, so compensate but adjusting SIZE. Don't lose any + constant we already had. */ + + size = *pend - *pstart - INTVAL (XEXP (base, 1)) - 1; + start += *pstart + INTVAL (XEXP (base, 1)) + 1; + end += *pend; + base = *pbase; + } + break; + } + + break; + } + + if (GET_CODE (base) == CONST_INT) + { + start += INTVAL (base); + base = const0_rtx; + } + + end = start + size; + + /* Set the return values. */ + *pbase = base; + *pstart = start; + *pend = end; +} + +/* Return 1 iff any subexpression of X refers to memory + at an address of BASE plus some offset + such that any of the bytes' offsets fall between START (inclusive) + and END (exclusive). + + The value is undefined if X is a varying address (as determined by + cse_rtx_addr_varies_p). This function is not used in such cases. + + When used in the cse pass, `qty_const' is nonzero, and it is used + to treat an address that is a register with a known constant value + as if it were that constant value. + In the loop pass, `qty_const' is zero, so this is not done. */ + +static int +refers_to_mem_p (x, base, start, end) + rtx x, base; + HOST_WIDE_INT start, end; +{ + register HOST_WIDE_INT i; + register enum rtx_code code; + register char *fmt; + + repeat: + if (x == 0) + return 0; + + code = GET_CODE (x); + if (code == MEM) + { + register rtx addr = XEXP (x, 0); /* Get the address. */ + rtx mybase; + HOST_WIDE_INT mystart, myend; + + set_nonvarying_address_components (addr, GET_MODE_SIZE (GET_MODE (x)), + &mybase, &mystart, &myend); + + + /* refers_to_mem_p is never called with varying addresses. + If the base addresses are not equal, there is no chance + of the memory addresses conflicting. */ + if (! rtx_equal_p (mybase, base)) + return 0; + + return myend > start && mystart < end; + } + + /* X does not match, so try its subexpressions. */ + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + if (fmt[i] == 'e') + { + if (i == 0) + { + x = XEXP (x, 0); + goto repeat; + } + else + if (refers_to_mem_p (XEXP (x, i), base, start, end)) + return 1; + } + else if (fmt[i] == 'E') + { + int j; + for (j = 0; j < XVECLEN (x, i); j++) + if (refers_to_mem_p (XVECEXP (x, i, j), base, start, end)) + return 1; + } + + return 0; +} + +/* Nonzero if X refers to memory at a varying address; + except that a register which has at the moment a known constant value + isn't considered variable. */ + +static int +cse_rtx_addr_varies_p (x) + rtx x; +{ + /* We need not check for X and the equivalence class being of the same + mode because if X is equivalent to a constant in some mode, it + doesn't vary in any mode. */ + + if (GET_CODE (x) == MEM + && GET_CODE (XEXP (x, 0)) == REG + && REGNO_QTY_VALID_P (REGNO (XEXP (x, 0))) + && GET_MODE (XEXP (x, 0)) == qty_mode[reg_qty[REGNO (XEXP (x, 0))]] + && qty_const[reg_qty[REGNO (XEXP (x, 0))]] != 0) + return 0; + + if (GET_CODE (x) == MEM + && GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT + && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG + && REGNO_QTY_VALID_P (REGNO (XEXP (XEXP (x, 0), 0))) + && (GET_MODE (XEXP (XEXP (x, 0), 0)) + == qty_mode[reg_qty[REGNO (XEXP (XEXP (x, 0), 0))]]) + && qty_const[reg_qty[REGNO (XEXP (XEXP (x, 0), 0))]]) + return 0; + + /* This can happen as the result of virtual register instantiation, if + the initial constant is too large to be a valid address. This gives + us a three instruction sequence, load large offset into a register, + load fp minus a constant into a register, then a MEM which is the + sum of the two `constant' registers. */ + if (GET_CODE (x) == MEM + && GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG + && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG + && REGNO_QTY_VALID_P (REGNO (XEXP (XEXP (x, 0), 0))) + && (GET_MODE (XEXP (XEXP (x, 0), 0)) + == qty_mode[reg_qty[REGNO (XEXP (XEXP (x, 0), 0))]]) + && qty_const[reg_qty[REGNO (XEXP (XEXP (x, 0), 0))]] + && REGNO_QTY_VALID_P (REGNO (XEXP (XEXP (x, 0), 1))) + && (GET_MODE (XEXP (XEXP (x, 0), 1)) + == qty_mode[reg_qty[REGNO (XEXP (XEXP (x, 0), 1))]]) + && qty_const[reg_qty[REGNO (XEXP (XEXP (x, 0), 1))]]) + return 0; + + return rtx_addr_varies_p (x); +} + +/* Canonicalize an expression: + replace each register reference inside it + with the "oldest" equivalent register. + + If INSN is non-zero and we are replacing a pseudo with a hard register + or vice versa, validate_change is used to ensure that INSN remains valid + after we make our substitution. The calls are made with IN_GROUP non-zero + so apply_change_group must be called upon the outermost return from this + function (unless INSN is zero). The result of apply_change_group can + generally be discarded since the changes we are making are optional. */ + +static rtx +canon_reg (x, insn) + rtx x; + rtx insn; +{ + register int i; + register enum rtx_code code; + register char *fmt; + + if (x == 0) + return x; + + code = GET_CODE (x); + switch (code) + { + case PC: + case CC0: + case CONST: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case LABEL_REF: + case ADDR_VEC: + case ADDR_DIFF_VEC: + return x; + + case REG: + { + register int first; + + /* Never replace a hard reg, because hard regs can appear + in more than one machine mode, and we must preserve the mode + of each occurrence. Also, some hard regs appear in + MEMs that are shared and mustn't be altered. Don't try to + replace any reg that maps to a reg of class NO_REGS. */ + if (REGNO (x) < FIRST_PSEUDO_REGISTER + || ! REGNO_QTY_VALID_P (REGNO (x))) + return x; + + first = qty_first_reg[reg_qty[REGNO (x)]]; + return (first >= FIRST_PSEUDO_REGISTER ? regno_reg_rtx[first] + : REGNO_REG_CLASS (first) == NO_REGS ? x + : gen_rtx (REG, qty_mode[reg_qty[REGNO (x)]], first)); + } + } + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + register int j; + + if (fmt[i] == 'e') + { + rtx new = canon_reg (XEXP (x, i), insn); + + /* If replacing pseudo with hard reg or vice versa, ensure the + insn remains valid. Likewise if the insn has MATCH_DUPs. */ + if (insn != 0 && new != 0 + && GET_CODE (new) == REG && GET_CODE (XEXP (x, i)) == REG + && (((REGNO (new) < FIRST_PSEUDO_REGISTER) + != (REGNO (XEXP (x, i)) < FIRST_PSEUDO_REGISTER)) + || insn_n_dups[recog_memoized (insn)] > 0)) + validate_change (insn, &XEXP (x, i), new, 1); + else + XEXP (x, i) = new; + } + else if (fmt[i] == 'E') + for (j = 0; j < XVECLEN (x, i); j++) + XVECEXP (x, i, j) = canon_reg (XVECEXP (x, i, j), insn); + } + + return x; +} + +/* LOC is a location with INSN that is an operand address (the contents of + a MEM). Find the best equivalent address to use that is valid for this + insn. + + On most CISC machines, complicated address modes are costly, and rtx_cost + is a good approximation for that cost. However, most RISC machines have + only a few (usually only one) memory reference formats. If an address is + valid at all, it is often just as cheap as any other address. Hence, for + RISC machines, we use the configuration macro `ADDRESS_COST' to compare the + costs of various addresses. For two addresses of equal cost, choose the one + with the highest `rtx_cost' value as that has the potential of eliminating + the most insns. For equal costs, we choose the first in the equivalence + class. Note that we ignore the fact that pseudo registers are cheaper + than hard registers here because we would also prefer the pseudo registers. + */ + +static void +find_best_addr (insn, loc) + rtx insn; + rtx *loc; +{ + struct table_elt *elt, *p; + rtx addr = *loc; + int our_cost; + int found_better = 1; + int save_do_not_record = do_not_record; + int save_hash_arg_in_memory = hash_arg_in_memory; + int save_hash_arg_in_struct = hash_arg_in_struct; + int addr_volatile; + int regno; + unsigned hash; + + /* Do not try to replace constant addresses or addresses of local and + argument slots. These MEM expressions are made only once and inserted + in many instructions, as well as being used to control symbol table + output. It is not safe to clobber them. + + There are some uncommon cases where the address is already in a register + for some reason, but we cannot take advantage of that because we have + no easy way to unshare the MEM. In addition, looking up all stack + addresses is costly. */ + if ((GET_CODE (addr) == PLUS + && GET_CODE (XEXP (addr, 0)) == REG + && GET_CODE (XEXP (addr, 1)) == CONST_INT + && (regno = REGNO (XEXP (addr, 0)), + regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM + || regno == ARG_POINTER_REGNUM)) + || (GET_CODE (addr) == REG + && (regno = REGNO (addr), regno == FRAME_POINTER_REGNUM + || regno == HARD_FRAME_POINTER_REGNUM + || regno == ARG_POINTER_REGNUM)) + || CONSTANT_ADDRESS_P (addr)) + return; + + /* If this address is not simply a register, try to fold it. This will + sometimes simplify the expression. Many simplifications + will not be valid, but some, usually applying the associative rule, will + be valid and produce better code. */ + if (GET_CODE (addr) != REG + && validate_change (insn, loc, fold_rtx (addr, insn), 0)) + addr = *loc; + + /* If this address is not in the hash table, we can't look for equivalences + of the whole address. Also, ignore if volatile. */ + + do_not_record = 0; + hash = HASH (addr, Pmode); + addr_volatile = do_not_record; + do_not_record = save_do_not_record; + hash_arg_in_memory = save_hash_arg_in_memory; + hash_arg_in_struct = save_hash_arg_in_struct; + + if (addr_volatile) + return; + + elt = lookup (addr, hash, Pmode); + +#ifndef ADDRESS_COST + if (elt) + { + our_cost = elt->cost; + + /* Find the lowest cost below ours that works. */ + for (elt = elt->first_same_value; elt; elt = elt->next_same_value) + if (elt->cost < our_cost + && (GET_CODE (elt->exp) == REG + || exp_equiv_p (elt->exp, elt->exp, 1, 0)) + && validate_change (insn, loc, + canon_reg (copy_rtx (elt->exp), NULL_RTX), 0)) + return; + } +#else + + if (elt) + { + /* We need to find the best (under the criteria documented above) entry + in the class that is valid. We use the `flag' field to indicate + choices that were invalid and iterate until we can't find a better + one that hasn't already been tried. */ + + for (p = elt->first_same_value; p; p = p->next_same_value) + p->flag = 0; + + while (found_better) + { + int best_addr_cost = ADDRESS_COST (*loc); + int best_rtx_cost = (elt->cost + 1) >> 1; + struct table_elt *best_elt = elt; + + found_better = 0; + for (p = elt->first_same_value; p; p = p->next_same_value) + if (! p->flag + && (GET_CODE (p->exp) == REG + || exp_equiv_p (p->exp, p->exp, 1, 0)) + && (ADDRESS_COST (p->exp) < best_addr_cost + || (ADDRESS_COST (p->exp) == best_addr_cost + && (p->cost + 1) >> 1 > best_rtx_cost))) + { + found_better = 1; + best_addr_cost = ADDRESS_COST (p->exp); + best_rtx_cost = (p->cost + 1) >> 1; + best_elt = p; + } + + if (found_better) + { + if (validate_change (insn, loc, + canon_reg (copy_rtx (best_elt->exp), + NULL_RTX), 0)) + return; + else + best_elt->flag = 1; + } + } + } + + /* If the address is a binary operation with the first operand a register + and the second a constant, do the same as above, but looking for + equivalences of the register. Then try to simplify before checking for + the best address to use. This catches a few cases: First is when we + have REG+const and the register is another REG+const. We can often merge + the constants and eliminate one insn and one register. It may also be + that a machine has a cheap REG+REG+const. Finally, this improves the + code on the Alpha for unaligned byte stores. */ + + if (flag_expensive_optimizations + && (GET_RTX_CLASS (GET_CODE (*loc)) == '2' + || GET_RTX_CLASS (GET_CODE (*loc)) == 'c') + && GET_CODE (XEXP (*loc, 0)) == REG + && GET_CODE (XEXP (*loc, 1)) == CONST_INT) + { + rtx c = XEXP (*loc, 1); + + do_not_record = 0; + hash = HASH (XEXP (*loc, 0), Pmode); + do_not_record = save_do_not_record; + hash_arg_in_memory = save_hash_arg_in_memory; + hash_arg_in_struct = save_hash_arg_in_struct; + + elt = lookup (XEXP (*loc, 0), hash, Pmode); + if (elt == 0) + return; + + /* We need to find the best (under the criteria documented above) entry + in the class that is valid. We use the `flag' field to indicate + choices that were invalid and iterate until we can't find a better + one that hasn't already been tried. */ + + for (p = elt->first_same_value; p; p = p->next_same_value) + p->flag = 0; + + while (found_better) + { + int best_addr_cost = ADDRESS_COST (*loc); + int best_rtx_cost = (COST (*loc) + 1) >> 1; + struct table_elt *best_elt = elt; + rtx best_rtx = *loc; + int count; + + /* This is at worst case an O(n^2) algorithm, so limit our search + to the first 32 elements on the list. This avoids trouble + compiling code with very long basic blocks that can easily + call cse_gen_binary so many times that we run out of memory. */ + + found_better = 0; + for (p = elt->first_same_value, count = 0; + p && count < 32; + p = p->next_same_value, count++) + if (! p->flag + && (GET_CODE (p->exp) == REG + || exp_equiv_p (p->exp, p->exp, 1, 0))) + { + rtx new = cse_gen_binary (GET_CODE (*loc), Pmode, p->exp, c); + + if ((ADDRESS_COST (new) < best_addr_cost + || (ADDRESS_COST (new) == best_addr_cost + && (COST (new) + 1) >> 1 > best_rtx_cost))) + { + found_better = 1; + best_addr_cost = ADDRESS_COST (new); + best_rtx_cost = (COST (new) + 1) >> 1; + best_elt = p; + best_rtx = new; + } + } + + if (found_better) + { + if (validate_change (insn, loc, + canon_reg (copy_rtx (best_rtx), + NULL_RTX), 0)) + return; + else + best_elt->flag = 1; + } + } + } +#endif +} + +/* Given an operation (CODE, *PARG1, *PARG2), where code is a comparison + operation (EQ, NE, GT, etc.), follow it back through the hash table and + what values are being compared. + + *PARG1 and *PARG2 are updated to contain the rtx representing the values + actually being compared. For example, if *PARG1 was (cc0) and *PARG2 + was (const_int 0), *PARG1 and *PARG2 will be set to the objects that were + compared to produce cc0. + + The return value is the comparison operator and is either the code of + A or the code corresponding to the inverse of the comparison. */ + +static enum rtx_code +find_comparison_args (code, parg1, parg2, pmode1, pmode2) + enum rtx_code code; + rtx *parg1, *parg2; + enum machine_mode *pmode1, *pmode2; +{ + rtx arg1, arg2; + + arg1 = *parg1, arg2 = *parg2; + + /* If ARG2 is const0_rtx, see what ARG1 is equivalent to. */ + + while (arg2 == CONST0_RTX (GET_MODE (arg1))) + { + /* Set non-zero when we find something of interest. */ + rtx x = 0; + int reverse_code = 0; + struct table_elt *p = 0; + + /* If arg1 is a COMPARE, extract the comparison arguments from it. + On machines with CC0, this is the only case that can occur, since + fold_rtx will return the COMPARE or item being compared with zero + when given CC0. */ + + if (GET_CODE (arg1) == COMPARE && arg2 == const0_rtx) + x = arg1; + + /* If ARG1 is a comparison operator and CODE is testing for + STORE_FLAG_VALUE, get the inner arguments. */ + + else if (GET_RTX_CLASS (GET_CODE (arg1)) == '<') + { + if (code == NE + || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT + && code == LT && STORE_FLAG_VALUE == -1) +#ifdef FLOAT_STORE_FLAG_VALUE + || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT + && FLOAT_STORE_FLAG_VALUE < 0) +#endif + ) + x = arg1; + else if (code == EQ + || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_INT + && code == GE && STORE_FLAG_VALUE == -1) +#ifdef FLOAT_STORE_FLAG_VALUE + || (GET_MODE_CLASS (GET_MODE (arg1)) == MODE_FLOAT + && FLOAT_STORE_FLAG_VALUE < 0) +#endif + ) + x = arg1, reverse_code = 1; + } + + /* ??? We could also check for + + (ne (and (eq (...) (const_int 1))) (const_int 0)) + + and related forms, but let's wait until we see them occurring. */ + + if (x == 0) + /* Look up ARG1 in the hash table and see if it has an equivalence + that lets us see what is being compared. */ + p = lookup (arg1, safe_hash (arg1, GET_MODE (arg1)) % NBUCKETS, + GET_MODE (arg1)); + if (p) p = p->first_same_value; + + for (; p; p = p->next_same_value) + { + enum machine_mode inner_mode = GET_MODE (p->exp); + + /* If the entry isn't valid, skip it. */ + if (! exp_equiv_p (p->exp, p->exp, 1, 0)) + continue; + + if (GET_CODE (p->exp) == COMPARE + /* Another possibility is that this machine has a compare insn + that includes the comparison code. In that case, ARG1 would + be equivalent to a comparison operation that would set ARG1 to + either STORE_FLAG_VALUE or zero. If this is an NE operation, + ORIG_CODE is the actual comparison being done; if it is an EQ, + we must reverse ORIG_CODE. On machine with a negative value + for STORE_FLAG_VALUE, also look at LT and GE operations. */ + || ((code == NE + || (code == LT + && GET_MODE_CLASS (inner_mode) == MODE_INT + && (GET_MODE_BITSIZE (inner_mode) + <= HOST_BITS_PER_WIDE_INT) + && (STORE_FLAG_VALUE + & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (inner_mode) - 1)))) +#ifdef FLOAT_STORE_FLAG_VALUE + || (code == LT + && GET_MODE_CLASS (inner_mode) == MODE_FLOAT + && FLOAT_STORE_FLAG_VALUE < 0) +#endif + ) + && GET_RTX_CLASS (GET_CODE (p->exp)) == '<')) + { + x = p->exp; + break; + } + else if ((code == EQ + || (code == GE + && GET_MODE_CLASS (inner_mode) == MODE_INT + && (GET_MODE_BITSIZE (inner_mode) + <= HOST_BITS_PER_WIDE_INT) + && (STORE_FLAG_VALUE + & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (inner_mode) - 1)))) +#ifdef FLOAT_STORE_FLAG_VALUE + || (code == GE + && GET_MODE_CLASS (inner_mode) == MODE_FLOAT + && FLOAT_STORE_FLAG_VALUE < 0) +#endif + ) + && GET_RTX_CLASS (GET_CODE (p->exp)) == '<') + { + reverse_code = 1; + x = p->exp; + break; + } + + /* If this is fp + constant, the equivalent is a better operand since + it may let us predict the value of the comparison. */ + else if (NONZERO_BASE_PLUS_P (p->exp)) + { + arg1 = p->exp; + continue; + } + } + + /* If we didn't find a useful equivalence for ARG1, we are done. + Otherwise, set up for the next iteration. */ + if (x == 0) + break; + + arg1 = XEXP (x, 0), arg2 = XEXP (x, 1); + if (GET_RTX_CLASS (GET_CODE (x)) == '<') + code = GET_CODE (x); + + if (reverse_code) + code = reverse_condition (code); + } + + /* Return our results. Return the modes from before fold_rtx + because fold_rtx might produce const_int, and then it's too late. */ + *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2); + *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0); + + return code; +} + +/* Try to simplify a unary operation CODE whose output mode is to be + MODE with input operand OP whose mode was originally OP_MODE. + Return zero if no simplification can be made. */ + +rtx +simplify_unary_operation (code, mode, op, op_mode) + enum rtx_code code; + enum machine_mode mode; + rtx op; + enum machine_mode op_mode; +{ + register int width = GET_MODE_BITSIZE (mode); + + /* The order of these tests is critical so that, for example, we don't + check the wrong mode (input vs. output) for a conversion operation, + such as FIX. At some point, this should be simplified. */ + +#if !defined(REAL_IS_NOT_DOUBLE) || defined(REAL_ARITHMETIC) + + if (code == FLOAT && GET_MODE (op) == VOIDmode + && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)) + { + HOST_WIDE_INT hv, lv; + REAL_VALUE_TYPE d; + + if (GET_CODE (op) == CONST_INT) + lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0; + else + lv = CONST_DOUBLE_LOW (op), hv = CONST_DOUBLE_HIGH (op); + +#ifdef REAL_ARITHMETIC + REAL_VALUE_FROM_INT (d, lv, hv); +#else + if (hv < 0) + { + d = (double) (~ hv); + d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) + * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))); + d += (double) (unsigned HOST_WIDE_INT) (~ lv); + d = (- d - 1.0); + } + else + { + d = (double) hv; + d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) + * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))); + d += (double) (unsigned HOST_WIDE_INT) lv; + } +#endif /* REAL_ARITHMETIC */ + d = real_value_truncate (mode, d); + return CONST_DOUBLE_FROM_REAL_VALUE (d, mode); + } + else if (code == UNSIGNED_FLOAT && GET_MODE (op) == VOIDmode + && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)) + { + HOST_WIDE_INT hv, lv; + REAL_VALUE_TYPE d; + + if (GET_CODE (op) == CONST_INT) + lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0; + else + lv = CONST_DOUBLE_LOW (op), hv = CONST_DOUBLE_HIGH (op); + + if (op_mode == VOIDmode) + { + /* We don't know how to interpret negative-looking numbers in + this case, so don't try to fold those. */ + if (hv < 0) + return 0; + } + else if (GET_MODE_BITSIZE (op_mode) >= HOST_BITS_PER_WIDE_INT * 2) + ; + else + hv = 0, lv &= GET_MODE_MASK (op_mode); + +#ifdef REAL_ARITHMETIC + REAL_VALUE_FROM_UNSIGNED_INT (d, lv, hv); +#else + + d = (double) (unsigned HOST_WIDE_INT) hv; + d *= ((double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2)) + * (double) ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 2))); + d += (double) (unsigned HOST_WIDE_INT) lv; +#endif /* REAL_ARITHMETIC */ + d = real_value_truncate (mode, d); + return CONST_DOUBLE_FROM_REAL_VALUE (d, mode); + } +#endif + + if (GET_CODE (op) == CONST_INT + && width <= HOST_BITS_PER_WIDE_INT && width > 0) + { + register HOST_WIDE_INT arg0 = INTVAL (op); + register HOST_WIDE_INT val; + + switch (code) + { + case NOT: + val = ~ arg0; + break; + + case NEG: + val = - arg0; + break; + + case ABS: + val = (arg0 >= 0 ? arg0 : - arg0); + break; + + case FFS: + /* Don't use ffs here. Instead, get low order bit and then its + number. If arg0 is zero, this will return 0, as desired. */ + arg0 &= GET_MODE_MASK (mode); + val = exact_log2 (arg0 & (- arg0)) + 1; + break; + + case TRUNCATE: + val = arg0; + break; + + case ZERO_EXTEND: + if (op_mode == VOIDmode) + op_mode = mode; + if (GET_MODE_BITSIZE (op_mode) == HOST_BITS_PER_WIDE_INT) + { + /* If we were really extending the mode, + we would have to distinguish between zero-extension + and sign-extension. */ + if (width != GET_MODE_BITSIZE (op_mode)) + abort (); + val = arg0; + } + else if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT) + val = arg0 & ~((HOST_WIDE_INT) (-1) << GET_MODE_BITSIZE (op_mode)); + else + return 0; + break; + + case SIGN_EXTEND: + if (op_mode == VOIDmode) + op_mode = mode; + if (GET_MODE_BITSIZE (op_mode) == HOST_BITS_PER_WIDE_INT) + { + /* If we were really extending the mode, + we would have to distinguish between zero-extension + and sign-extension. */ + if (width != GET_MODE_BITSIZE (op_mode)) + abort (); + val = arg0; + } + else if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT) + { + val + = arg0 & ~((HOST_WIDE_INT) (-1) << GET_MODE_BITSIZE (op_mode)); + if (val + & ((HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (op_mode) - 1))) + val -= (HOST_WIDE_INT) 1 << GET_MODE_BITSIZE (op_mode); + } + else + return 0; + break; + + case SQRT: + return 0; + + default: + abort (); + } + + /* Clear the bits that don't belong in our mode, + unless they and our sign bit are all one. + So we get either a reasonable negative value or a reasonable + unsigned value for this mode. */ + if (width < HOST_BITS_PER_WIDE_INT + && ((val & ((HOST_WIDE_INT) (-1) << (width - 1))) + != ((HOST_WIDE_INT) (-1) << (width - 1)))) + val &= ((HOST_WIDE_INT) 1 << width) - 1; + + return GEN_INT (val); + } + + /* We can do some operations on integer CONST_DOUBLEs. Also allow + for a DImode operation on a CONST_INT. */ + else if (GET_MODE (op) == VOIDmode && width <= HOST_BITS_PER_INT * 2 + && (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)) + { + HOST_WIDE_INT l1, h1, lv, hv; + + if (GET_CODE (op) == CONST_DOUBLE) + l1 = CONST_DOUBLE_LOW (op), h1 = CONST_DOUBLE_HIGH (op); + else + l1 = INTVAL (op), h1 = l1 < 0 ? -1 : 0; + + switch (code) + { + case NOT: + lv = ~ l1; + hv = ~ h1; + break; + + case NEG: + neg_double (l1, h1, &lv, &hv); + break; + + case ABS: + if (h1 < 0) + neg_double (l1, h1, &lv, &hv); + else + lv = l1, hv = h1; + break; + + case FFS: + hv = 0; + if (l1 == 0) + lv = HOST_BITS_PER_WIDE_INT + exact_log2 (h1 & (-h1)) + 1; + else + lv = exact_log2 (l1 & (-l1)) + 1; + break; + + case TRUNCATE: + /* This is just a change-of-mode, so do nothing. */ + lv = l1, hv = h1; + break; + + case ZERO_EXTEND: + if (op_mode == VOIDmode + || GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT) + return 0; + + hv = 0; + lv = l1 & GET_MODE_MASK (op_mode); + break; + + case SIGN_EXTEND: + if (op_mode == VOIDmode + || GET_MODE_BITSIZE (op_mode) > HOST_BITS_PER_WIDE_INT) + return 0; + else + { + lv = l1 & GET_MODE_MASK (op_mode); + if (GET_MODE_BITSIZE (op_mode) < HOST_BITS_PER_WIDE_INT + && (lv & ((HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (op_mode) - 1))) != 0) + lv -= (HOST_WIDE_INT) 1 << GET_MODE_BITSIZE (op_mode); + + hv = (lv < 0) ? ~ (HOST_WIDE_INT) 0 : 0; + } + break; + + case SQRT: + return 0; + + default: + return 0; + } + + return immed_double_const (lv, hv, mode); + } + +#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) + else if (GET_CODE (op) == CONST_DOUBLE + && GET_MODE_CLASS (mode) == MODE_FLOAT) + { + REAL_VALUE_TYPE d; + jmp_buf handler; + rtx x; + + if (setjmp (handler)) + /* There used to be a warning here, but that is inadvisable. + People may want to cause traps, and the natural way + to do it should not get a warning. */ + return 0; + + set_float_handler (handler); + + REAL_VALUE_FROM_CONST_DOUBLE (d, op); + + switch (code) + { + case NEG: + d = REAL_VALUE_NEGATE (d); + break; + + case ABS: + if (REAL_VALUE_NEGATIVE (d)) + d = REAL_VALUE_NEGATE (d); + break; + + case FLOAT_TRUNCATE: + d = real_value_truncate (mode, d); + break; + + case FLOAT_EXTEND: + /* All this does is change the mode. */ + break; + + case FIX: + d = REAL_VALUE_RNDZINT (d); + break; + + case UNSIGNED_FIX: + d = REAL_VALUE_UNSIGNED_RNDZINT (d); + break; + + case SQRT: + return 0; + + default: + abort (); + } + + x = CONST_DOUBLE_FROM_REAL_VALUE (d, mode); + set_float_handler (NULL_PTR); + return x; + } + + else if (GET_CODE (op) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT + && GET_MODE_CLASS (mode) == MODE_INT + && width <= HOST_BITS_PER_WIDE_INT && width > 0) + { + REAL_VALUE_TYPE d; + jmp_buf handler; + HOST_WIDE_INT val; + + if (setjmp (handler)) + return 0; + + set_float_handler (handler); + + REAL_VALUE_FROM_CONST_DOUBLE (d, op); + + switch (code) + { + case FIX: + val = REAL_VALUE_FIX (d); + break; + + case UNSIGNED_FIX: + val = REAL_VALUE_UNSIGNED_FIX (d); + break; + + default: + abort (); + } + + set_float_handler (NULL_PTR); + + /* Clear the bits that don't belong in our mode, + unless they and our sign bit are all one. + So we get either a reasonable negative value or a reasonable + unsigned value for this mode. */ + if (width < HOST_BITS_PER_WIDE_INT + && ((val & ((HOST_WIDE_INT) (-1) << (width - 1))) + != ((HOST_WIDE_INT) (-1) << (width - 1)))) + val &= ((HOST_WIDE_INT) 1 << width) - 1; + + /* If this would be an entire word for the target, but is not for + the host, then sign-extend on the host so that the number will look + the same way on the host that it would on the target. + + For example, when building a 64 bit alpha hosted 32 bit sparc + targeted compiler, then we want the 32 bit unsigned value -1 to be + represented as a 64 bit value -1, and not as 0x00000000ffffffff. + The later confuses the sparc backend. */ + + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width + && (val & ((HOST_WIDE_INT) 1 << (width - 1)))) + val |= ((HOST_WIDE_INT) (-1) << width); + + return GEN_INT (val); + } +#endif + /* This was formerly used only for non-IEEE float. + eggert@twinsun.com says it is safe for IEEE also. */ + else + { + /* There are some simplifications we can do even if the operands + aren't constant. */ + switch (code) + { + case NEG: + case NOT: + /* (not (not X)) == X, similarly for NEG. */ + if (GET_CODE (op) == code) + return XEXP (op, 0); + break; + + case SIGN_EXTEND: + /* (sign_extend (truncate (minus (label_ref L1) (label_ref L2)))) + becomes just the MINUS if its mode is MODE. This allows + folding switch statements on machines using casesi (such as + the Vax). */ + if (GET_CODE (op) == TRUNCATE + && GET_MODE (XEXP (op, 0)) == mode + && GET_CODE (XEXP (op, 0)) == MINUS + && GET_CODE (XEXP (XEXP (op, 0), 0)) == LABEL_REF + && GET_CODE (XEXP (XEXP (op, 0), 1)) == LABEL_REF) + return XEXP (op, 0); + +#ifdef POINTERS_EXTEND_UNSIGNED + if (! POINTERS_EXTEND_UNSIGNED + && mode == Pmode && GET_MODE (op) == ptr_mode + && CONSTANT_P (op)) + return convert_memory_address (Pmode, op); +#endif + break; + +#ifdef POINTERS_EXTEND_UNSIGNED + case ZERO_EXTEND: + if (POINTERS_EXTEND_UNSIGNED + && mode == Pmode && GET_MODE (op) == ptr_mode + && CONSTANT_P (op)) + return convert_memory_address (Pmode, op); + break; +#endif + } + + return 0; + } +} + +/* Simplify a binary operation CODE with result mode MODE, operating on OP0 + and OP1. Return 0 if no simplification is possible. + + Don't use this for relational operations such as EQ or LT. + Use simplify_relational_operation instead. */ + +rtx +simplify_binary_operation (code, mode, op0, op1) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; +{ + register HOST_WIDE_INT arg0, arg1, arg0s, arg1s; + HOST_WIDE_INT val; + int width = GET_MODE_BITSIZE (mode); + rtx tem; + + /* Relational operations don't work here. We must know the mode + of the operands in order to do the comparison correctly. + Assuming a full word can give incorrect results. + Consider comparing 128 with -128 in QImode. */ + + if (GET_RTX_CLASS (code) == '<') + abort (); + +#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) + if (GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_CODE (op0) == CONST_DOUBLE && GET_CODE (op1) == CONST_DOUBLE + && mode == GET_MODE (op0) && mode == GET_MODE (op1)) + { + REAL_VALUE_TYPE f0, f1, value; + jmp_buf handler; + + if (setjmp (handler)) + return 0; + + set_float_handler (handler); + + REAL_VALUE_FROM_CONST_DOUBLE (f0, op0); + REAL_VALUE_FROM_CONST_DOUBLE (f1, op1); + f0 = real_value_truncate (mode, f0); + f1 = real_value_truncate (mode, f1); + +#ifdef REAL_ARITHMETIC + REAL_ARITHMETIC (value, rtx_to_tree_code (code), f0, f1); +#else + switch (code) + { + case PLUS: + value = f0 + f1; + break; + case MINUS: + value = f0 - f1; + break; + case MULT: + value = f0 * f1; + break; + case DIV: +#ifndef REAL_INFINITY + if (f1 == 0) + return 0; +#endif + value = f0 / f1; + break; + case SMIN: + value = MIN (f0, f1); + break; + case SMAX: + value = MAX (f0, f1); + break; + default: + abort (); + } +#endif + + value = real_value_truncate (mode, value); + set_float_handler (NULL_PTR); + return CONST_DOUBLE_FROM_REAL_VALUE (value, mode); + } +#endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */ + + /* We can fold some multi-word operations. */ + if (GET_MODE_CLASS (mode) == MODE_INT + && width == HOST_BITS_PER_WIDE_INT * 2 + && (GET_CODE (op0) == CONST_DOUBLE || GET_CODE (op0) == CONST_INT) + && (GET_CODE (op1) == CONST_DOUBLE || GET_CODE (op1) == CONST_INT)) + { + HOST_WIDE_INT l1, l2, h1, h2, lv, hv; + + if (GET_CODE (op0) == CONST_DOUBLE) + l1 = CONST_DOUBLE_LOW (op0), h1 = CONST_DOUBLE_HIGH (op0); + else + l1 = INTVAL (op0), h1 = l1 < 0 ? -1 : 0; + + if (GET_CODE (op1) == CONST_DOUBLE) + l2 = CONST_DOUBLE_LOW (op1), h2 = CONST_DOUBLE_HIGH (op1); + else + l2 = INTVAL (op1), h2 = l2 < 0 ? -1 : 0; + + switch (code) + { + case MINUS: + /* A - B == A + (-B). */ + neg_double (l2, h2, &lv, &hv); + l2 = lv, h2 = hv; + + /* .. fall through ... */ + + case PLUS: + add_double (l1, h1, l2, h2, &lv, &hv); + break; + + case MULT: + mul_double (l1, h1, l2, h2, &lv, &hv); + break; + + case DIV: case MOD: case UDIV: case UMOD: + /* We'd need to include tree.h to do this and it doesn't seem worth + it. */ + return 0; + + case AND: + lv = l1 & l2, hv = h1 & h2; + break; + + case IOR: + lv = l1 | l2, hv = h1 | h2; + break; + + case XOR: + lv = l1 ^ l2, hv = h1 ^ h2; + break; + + case SMIN: + if (h1 < h2 + || (h1 == h2 + && ((unsigned HOST_WIDE_INT) l1 + < (unsigned HOST_WIDE_INT) l2))) + lv = l1, hv = h1; + else + lv = l2, hv = h2; + break; + + case SMAX: + if (h1 > h2 + || (h1 == h2 + && ((unsigned HOST_WIDE_INT) l1 + > (unsigned HOST_WIDE_INT) l2))) + lv = l1, hv = h1; + else + lv = l2, hv = h2; + break; + + case UMIN: + if ((unsigned HOST_WIDE_INT) h1 < (unsigned HOST_WIDE_INT) h2 + || (h1 == h2 + && ((unsigned HOST_WIDE_INT) l1 + < (unsigned HOST_WIDE_INT) l2))) + lv = l1, hv = h1; + else + lv = l2, hv = h2; + break; + + case UMAX: + if ((unsigned HOST_WIDE_INT) h1 > (unsigned HOST_WIDE_INT) h2 + || (h1 == h2 + && ((unsigned HOST_WIDE_INT) l1 + > (unsigned HOST_WIDE_INT) l2))) + lv = l1, hv = h1; + else + lv = l2, hv = h2; + break; + + case LSHIFTRT: case ASHIFTRT: + case ASHIFT: + case ROTATE: case ROTATERT: +#ifdef SHIFT_COUNT_TRUNCATED + if (SHIFT_COUNT_TRUNCATED) + l2 &= (GET_MODE_BITSIZE (mode) - 1), h2 = 0; +#endif + + if (h2 != 0 || l2 < 0 || l2 >= GET_MODE_BITSIZE (mode)) + return 0; + + if (code == LSHIFTRT || code == ASHIFTRT) + rshift_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv, + code == ASHIFTRT); + else if (code == ASHIFT) + lshift_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv, 1); + else if (code == ROTATE) + lrotate_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv); + else /* code == ROTATERT */ + rrotate_double (l1, h1, l2, GET_MODE_BITSIZE (mode), &lv, &hv); + break; + + default: + return 0; + } + + return immed_double_const (lv, hv, mode); + } + + if (GET_CODE (op0) != CONST_INT || GET_CODE (op1) != CONST_INT + || width > HOST_BITS_PER_WIDE_INT || width == 0) + { + /* Even if we can't compute a constant result, + there are some cases worth simplifying. */ + + switch (code) + { + case PLUS: + /* In IEEE floating point, x+0 is not the same as x. Similarly + for the other optimizations below. */ + if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT + && FLOAT_MODE_P (mode) && ! flag_fast_math) + break; + + if (op1 == CONST0_RTX (mode)) + return op0; + + /* ((-a) + b) -> (b - a) and similarly for (a + (-b)) */ + if (GET_CODE (op0) == NEG) + return cse_gen_binary (MINUS, mode, op1, XEXP (op0, 0)); + else if (GET_CODE (op1) == NEG) + return cse_gen_binary (MINUS, mode, op0, XEXP (op1, 0)); + + /* Handle both-operands-constant cases. We can only add + CONST_INTs to constants since the sum of relocatable symbols + can't be handled by most assemblers. Don't add CONST_INT + to CONST_INT since overflow won't be computed properly if wider + than HOST_BITS_PER_WIDE_INT. */ + + if (CONSTANT_P (op0) && GET_MODE (op0) != VOIDmode + && GET_CODE (op1) == CONST_INT) + return plus_constant (op0, INTVAL (op1)); + else if (CONSTANT_P (op1) && GET_MODE (op1) != VOIDmode + && GET_CODE (op0) == CONST_INT) + return plus_constant (op1, INTVAL (op0)); + + /* See if this is something like X * C - X or vice versa or + if the multiplication is written as a shift. If so, we can + distribute and make a new multiply, shift, or maybe just + have X (if C is 2 in the example above). But don't make + real multiply if we didn't have one before. */ + + if (! FLOAT_MODE_P (mode)) + { + HOST_WIDE_INT coeff0 = 1, coeff1 = 1; + rtx lhs = op0, rhs = op1; + int had_mult = 0; + + if (GET_CODE (lhs) == NEG) + coeff0 = -1, lhs = XEXP (lhs, 0); + else if (GET_CODE (lhs) == MULT + && GET_CODE (XEXP (lhs, 1)) == CONST_INT) + { + coeff0 = INTVAL (XEXP (lhs, 1)), lhs = XEXP (lhs, 0); + had_mult = 1; + } + else if (GET_CODE (lhs) == ASHIFT + && GET_CODE (XEXP (lhs, 1)) == CONST_INT + && INTVAL (XEXP (lhs, 1)) >= 0 + && INTVAL (XEXP (lhs, 1)) < HOST_BITS_PER_WIDE_INT) + { + coeff0 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (lhs, 1)); + lhs = XEXP (lhs, 0); + } + + if (GET_CODE (rhs) == NEG) + coeff1 = -1, rhs = XEXP (rhs, 0); + else if (GET_CODE (rhs) == MULT + && GET_CODE (XEXP (rhs, 1)) == CONST_INT) + { + coeff1 = INTVAL (XEXP (rhs, 1)), rhs = XEXP (rhs, 0); + had_mult = 1; + } + else if (GET_CODE (rhs) == ASHIFT + && GET_CODE (XEXP (rhs, 1)) == CONST_INT + && INTVAL (XEXP (rhs, 1)) >= 0 + && INTVAL (XEXP (rhs, 1)) < HOST_BITS_PER_WIDE_INT) + { + coeff1 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (rhs, 1)); + rhs = XEXP (rhs, 0); + } + + if (rtx_equal_p (lhs, rhs)) + { + tem = cse_gen_binary (MULT, mode, lhs, + GEN_INT (coeff0 + coeff1)); + return (GET_CODE (tem) == MULT && ! had_mult) ? 0 : tem; + } + } + + /* If one of the operands is a PLUS or a MINUS, see if we can + simplify this by the associative law. + Don't use the associative law for floating point. + The inaccuracy makes it nonassociative, + and subtle programs can break if operations are associated. */ + + if (INTEGRAL_MODE_P (mode) + && (GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS + || GET_CODE (op1) == PLUS || GET_CODE (op1) == MINUS) + && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0) + return tem; + break; + + case COMPARE: +#ifdef HAVE_cc0 + /* Convert (compare FOO (const_int 0)) to FOO unless we aren't + using cc0, in which case we want to leave it as a COMPARE + so we can distinguish it from a register-register-copy. + + In IEEE floating point, x-0 is not the same as x. */ + + if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (mode) || flag_fast_math) + && op1 == CONST0_RTX (mode)) + return op0; +#else + /* Do nothing here. */ +#endif + break; + + case MINUS: + /* None of these optimizations can be done for IEEE + floating point. */ + if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT + && FLOAT_MODE_P (mode) && ! flag_fast_math) + break; + + /* We can't assume x-x is 0 even with non-IEEE floating point, + but since it is zero except in very strange circumstances, we + will treat it as zero with -ffast-math. */ + if (rtx_equal_p (op0, op1) + && ! side_effects_p (op0) + && (! FLOAT_MODE_P (mode) || flag_fast_math)) + return CONST0_RTX (mode); + + /* Change subtraction from zero into negation. */ + if (op0 == CONST0_RTX (mode)) + return gen_rtx (NEG, mode, op1); + + /* (-1 - a) is ~a. */ + if (op0 == constm1_rtx) + return gen_rtx (NOT, mode, op1); + + /* Subtracting 0 has no effect. */ + if (op1 == CONST0_RTX (mode)) + return op0; + + /* See if this is something like X * C - X or vice versa or + if the multiplication is written as a shift. If so, we can + distribute and make a new multiply, shift, or maybe just + have X (if C is 2 in the example above). But don't make + real multiply if we didn't have one before. */ + + if (! FLOAT_MODE_P (mode)) + { + HOST_WIDE_INT coeff0 = 1, coeff1 = 1; + rtx lhs = op0, rhs = op1; + int had_mult = 0; + + if (GET_CODE (lhs) == NEG) + coeff0 = -1, lhs = XEXP (lhs, 0); + else if (GET_CODE (lhs) == MULT + && GET_CODE (XEXP (lhs, 1)) == CONST_INT) + { + coeff0 = INTVAL (XEXP (lhs, 1)), lhs = XEXP (lhs, 0); + had_mult = 1; + } + else if (GET_CODE (lhs) == ASHIFT + && GET_CODE (XEXP (lhs, 1)) == CONST_INT + && INTVAL (XEXP (lhs, 1)) >= 0 + && INTVAL (XEXP (lhs, 1)) < HOST_BITS_PER_WIDE_INT) + { + coeff0 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (lhs, 1)); + lhs = XEXP (lhs, 0); + } + + if (GET_CODE (rhs) == NEG) + coeff1 = - 1, rhs = XEXP (rhs, 0); + else if (GET_CODE (rhs) == MULT + && GET_CODE (XEXP (rhs, 1)) == CONST_INT) + { + coeff1 = INTVAL (XEXP (rhs, 1)), rhs = XEXP (rhs, 0); + had_mult = 1; + } + else if (GET_CODE (rhs) == ASHIFT + && GET_CODE (XEXP (rhs, 1)) == CONST_INT + && INTVAL (XEXP (rhs, 1)) >= 0 + && INTVAL (XEXP (rhs, 1)) < HOST_BITS_PER_WIDE_INT) + { + coeff1 = ((HOST_WIDE_INT) 1) << INTVAL (XEXP (rhs, 1)); + rhs = XEXP (rhs, 0); + } + + if (rtx_equal_p (lhs, rhs)) + { + tem = cse_gen_binary (MULT, mode, lhs, + GEN_INT (coeff0 - coeff1)); + return (GET_CODE (tem) == MULT && ! had_mult) ? 0 : tem; + } + } + + /* (a - (-b)) -> (a + b). */ + if (GET_CODE (op1) == NEG) + return cse_gen_binary (PLUS, mode, op0, XEXP (op1, 0)); + + /* If one of the operands is a PLUS or a MINUS, see if we can + simplify this by the associative law. + Don't use the associative law for floating point. + The inaccuracy makes it nonassociative, + and subtle programs can break if operations are associated. */ + + if (INTEGRAL_MODE_P (mode) + && (GET_CODE (op0) == PLUS || GET_CODE (op0) == MINUS + || GET_CODE (op1) == PLUS || GET_CODE (op1) == MINUS) + && (tem = simplify_plus_minus (code, mode, op0, op1)) != 0) + return tem; + + /* Don't let a relocatable value get a negative coeff. */ + if (GET_CODE (op1) == CONST_INT && GET_MODE (op0) != VOIDmode) + return plus_constant (op0, - INTVAL (op1)); + + /* (x - (x & y)) -> (x & ~y) */ + if (GET_CODE (op1) == AND) + { + if (rtx_equal_p (op0, XEXP (op1, 0))) + return cse_gen_binary (AND, mode, op0, gen_rtx (NOT, mode, XEXP (op1, 1))); + if (rtx_equal_p (op0, XEXP (op1, 1))) + return cse_gen_binary (AND, mode, op0, gen_rtx (NOT, mode, XEXP (op1, 0))); + } + break; + + case MULT: + if (op1 == constm1_rtx) + { + tem = simplify_unary_operation (NEG, mode, op0, mode); + + return tem ? tem : gen_rtx (NEG, mode, op0); + } + + /* In IEEE floating point, x*0 is not always 0. */ + if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (mode) || flag_fast_math) + && op1 == CONST0_RTX (mode) + && ! side_effects_p (op0)) + return op1; + + /* In IEEE floating point, x*1 is not equivalent to x for nans. + However, ANSI says we can drop signals, + so we can do this anyway. */ + if (op1 == CONST1_RTX (mode)) + return op0; + + /* Convert multiply by constant power of two into shift unless + we are still generating RTL. This test is a kludge. */ + if (GET_CODE (op1) == CONST_INT + && (val = exact_log2 (INTVAL (op1))) >= 0 + && ! rtx_equal_function_value_matters) + return gen_rtx (ASHIFT, mode, op0, GEN_INT (val)); + + if (GET_CODE (op1) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (op1)) == MODE_FLOAT) + { + REAL_VALUE_TYPE d; + jmp_buf handler; + int op1is2, op1ism1; + + if (setjmp (handler)) + return 0; + + set_float_handler (handler); + REAL_VALUE_FROM_CONST_DOUBLE (d, op1); + op1is2 = REAL_VALUES_EQUAL (d, dconst2); + op1ism1 = REAL_VALUES_EQUAL (d, dconstm1); + set_float_handler (NULL_PTR); + + /* x*2 is x+x and x*(-1) is -x */ + if (op1is2 && GET_MODE (op0) == mode) + return gen_rtx (PLUS, mode, op0, copy_rtx (op0)); + + else if (op1ism1 && GET_MODE (op0) == mode) + return gen_rtx (NEG, mode, op0); + } + break; + + case IOR: + if (op1 == const0_rtx) + return op0; + if (GET_CODE (op1) == CONST_INT + && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode)) + return op1; + if (rtx_equal_p (op0, op1) && ! side_effects_p (op0)) + return op0; + /* A | (~A) -> -1 */ + if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1)) + || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0))) + && ! side_effects_p (op0) + && GET_MODE_CLASS (mode) != MODE_CC) + return constm1_rtx; + break; + + case XOR: + if (op1 == const0_rtx) + return op0; + if (GET_CODE (op1) == CONST_INT + && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode)) + return gen_rtx (NOT, mode, op0); + if (op0 == op1 && ! side_effects_p (op0) + && GET_MODE_CLASS (mode) != MODE_CC) + return const0_rtx; + break; + + case AND: + if (op1 == const0_rtx && ! side_effects_p (op0)) + return const0_rtx; + if (GET_CODE (op1) == CONST_INT + && (INTVAL (op1) & GET_MODE_MASK (mode)) == GET_MODE_MASK (mode)) + return op0; + if (op0 == op1 && ! side_effects_p (op0) + && GET_MODE_CLASS (mode) != MODE_CC) + return op0; + /* A & (~A) -> 0 */ + if (((GET_CODE (op0) == NOT && rtx_equal_p (XEXP (op0, 0), op1)) + || (GET_CODE (op1) == NOT && rtx_equal_p (XEXP (op1, 0), op0))) + && ! side_effects_p (op0) + && GET_MODE_CLASS (mode) != MODE_CC) + return const0_rtx; + break; + + case UDIV: + /* Convert divide by power of two into shift (divide by 1 handled + below). */ + if (GET_CODE (op1) == CONST_INT + && (arg1 = exact_log2 (INTVAL (op1))) > 0) + return gen_rtx (LSHIFTRT, mode, op0, GEN_INT (arg1)); + + /* ... fall through ... */ + + case DIV: + if (op1 == CONST1_RTX (mode)) + return op0; + + /* In IEEE floating point, 0/x is not always 0. */ + if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (mode) || flag_fast_math) + && op0 == CONST0_RTX (mode) + && ! side_effects_p (op1)) + return op0; + +#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) + /* Change division by a constant into multiplication. Only do + this with -ffast-math until an expert says it is safe in + general. */ + else if (GET_CODE (op1) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (op1)) == MODE_FLOAT + && op1 != CONST0_RTX (mode) + && flag_fast_math) + { + REAL_VALUE_TYPE d; + REAL_VALUE_FROM_CONST_DOUBLE (d, op1); + + if (! REAL_VALUES_EQUAL (d, dconst0)) + { +#if defined (REAL_ARITHMETIC) + REAL_ARITHMETIC (d, rtx_to_tree_code (DIV), dconst1, d); + return gen_rtx (MULT, mode, op0, + CONST_DOUBLE_FROM_REAL_VALUE (d, mode)); +#else + return gen_rtx (MULT, mode, op0, + CONST_DOUBLE_FROM_REAL_VALUE (1./d, mode)); +#endif + } + } +#endif + break; + + case UMOD: + /* Handle modulus by power of two (mod with 1 handled below). */ + if (GET_CODE (op1) == CONST_INT + && exact_log2 (INTVAL (op1)) > 0) + return gen_rtx (AND, mode, op0, GEN_INT (INTVAL (op1) - 1)); + + /* ... fall through ... */ + + case MOD: + if ((op0 == const0_rtx || op1 == const1_rtx) + && ! side_effects_p (op0) && ! side_effects_p (op1)) + return const0_rtx; + break; + + case ROTATERT: + case ROTATE: + /* Rotating ~0 always results in ~0. */ + if (GET_CODE (op0) == CONST_INT && width <= HOST_BITS_PER_WIDE_INT + && INTVAL (op0) == GET_MODE_MASK (mode) + && ! side_effects_p (op1)) + return op0; + + /* ... fall through ... */ + + case ASHIFT: + case ASHIFTRT: + case LSHIFTRT: + if (op1 == const0_rtx) + return op0; + if (op0 == const0_rtx && ! side_effects_p (op1)) + return op0; + break; + + case SMIN: + if (width <= HOST_BITS_PER_WIDE_INT && GET_CODE (op1) == CONST_INT + && INTVAL (op1) == (HOST_WIDE_INT) 1 << (width -1) + && ! side_effects_p (op0)) + return op1; + else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0)) + return op0; + break; + + case SMAX: + if (width <= HOST_BITS_PER_WIDE_INT && GET_CODE (op1) == CONST_INT + && (INTVAL (op1) + == (unsigned HOST_WIDE_INT) GET_MODE_MASK (mode) >> 1) + && ! side_effects_p (op0)) + return op1; + else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0)) + return op0; + break; + + case UMIN: + if (op1 == const0_rtx && ! side_effects_p (op0)) + return op1; + else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0)) + return op0; + break; + + case UMAX: + if (op1 == constm1_rtx && ! side_effects_p (op0)) + return op1; + else if (rtx_equal_p (op0, op1) && ! side_effects_p (op0)) + return op0; + break; + + default: + abort (); + } + + return 0; + } + + /* Get the integer argument values in two forms: + zero-extended in ARG0, ARG1 and sign-extended in ARG0S, ARG1S. */ + + arg0 = INTVAL (op0); + arg1 = INTVAL (op1); + + if (width < HOST_BITS_PER_WIDE_INT) + { + arg0 &= ((HOST_WIDE_INT) 1 << width) - 1; + arg1 &= ((HOST_WIDE_INT) 1 << width) - 1; + + arg0s = arg0; + if (arg0s & ((HOST_WIDE_INT) 1 << (width - 1))) + arg0s |= ((HOST_WIDE_INT) (-1) << width); + + arg1s = arg1; + if (arg1s & ((HOST_WIDE_INT) 1 << (width - 1))) + arg1s |= ((HOST_WIDE_INT) (-1) << width); + } + else + { + arg0s = arg0; + arg1s = arg1; + } + + /* Compute the value of the arithmetic. */ + + switch (code) + { + case PLUS: + val = arg0s + arg1s; + break; + + case MINUS: + val = arg0s - arg1s; + break; + + case MULT: + val = arg0s * arg1s; + break; + + case DIV: + if (arg1s == 0) + return 0; + val = arg0s / arg1s; + break; + + case MOD: + if (arg1s == 0) + return 0; + val = arg0s % arg1s; + break; + + case UDIV: + if (arg1 == 0) + return 0; + val = (unsigned HOST_WIDE_INT) arg0 / arg1; + break; + + case UMOD: + if (arg1 == 0) + return 0; + val = (unsigned HOST_WIDE_INT) arg0 % arg1; + break; + + case AND: + val = arg0 & arg1; + break; + + case IOR: + val = arg0 | arg1; + break; + + case XOR: + val = arg0 ^ arg1; + break; + + case LSHIFTRT: + /* If shift count is undefined, don't fold it; let the machine do + what it wants. But truncate it if the machine will do that. */ + if (arg1 < 0) + return 0; + +#ifdef SHIFT_COUNT_TRUNCATED + if (SHIFT_COUNT_TRUNCATED) + arg1 %= width; +#endif + + val = ((unsigned HOST_WIDE_INT) arg0) >> arg1; + break; + + case ASHIFT: + if (arg1 < 0) + return 0; + +#ifdef SHIFT_COUNT_TRUNCATED + if (SHIFT_COUNT_TRUNCATED) + arg1 %= width; +#endif + + val = ((unsigned HOST_WIDE_INT) arg0) << arg1; + break; + + case ASHIFTRT: + if (arg1 < 0) + return 0; + +#ifdef SHIFT_COUNT_TRUNCATED + if (SHIFT_COUNT_TRUNCATED) + arg1 %= width; +#endif + + val = arg0s >> arg1; + + /* Bootstrap compiler may not have sign extended the right shift. + Manually extend the sign to insure bootstrap cc matches gcc. */ + if (arg0s < 0 && arg1 > 0) + val |= ((HOST_WIDE_INT) -1) << (HOST_BITS_PER_WIDE_INT - arg1); + + break; + + case ROTATERT: + if (arg1 < 0) + return 0; + + arg1 %= width; + val = ((((unsigned HOST_WIDE_INT) arg0) << (width - arg1)) + | (((unsigned HOST_WIDE_INT) arg0) >> arg1)); + break; + + case ROTATE: + if (arg1 < 0) + return 0; + + arg1 %= width; + val = ((((unsigned HOST_WIDE_INT) arg0) << arg1) + | (((unsigned HOST_WIDE_INT) arg0) >> (width - arg1))); + break; + + case COMPARE: + /* Do nothing here. */ + return 0; + + case SMIN: + val = arg0s <= arg1s ? arg0s : arg1s; + break; + + case UMIN: + val = ((unsigned HOST_WIDE_INT) arg0 + <= (unsigned HOST_WIDE_INT) arg1 ? arg0 : arg1); + break; + + case SMAX: + val = arg0s > arg1s ? arg0s : arg1s; + break; + + case UMAX: + val = ((unsigned HOST_WIDE_INT) arg0 + > (unsigned HOST_WIDE_INT) arg1 ? arg0 : arg1); + break; + + default: + abort (); + } + + /* Clear the bits that don't belong in our mode, unless they and our sign + bit are all one. So we get either a reasonable negative value or a + reasonable unsigned value for this mode. */ + if (width < HOST_BITS_PER_WIDE_INT + && ((val & ((HOST_WIDE_INT) (-1) << (width - 1))) + != ((HOST_WIDE_INT) (-1) << (width - 1)))) + val &= ((HOST_WIDE_INT) 1 << width) - 1; + + /* If this would be an entire word for the target, but is not for + the host, then sign-extend on the host so that the number will look + the same way on the host that it would on the target. + + For example, when building a 64 bit alpha hosted 32 bit sparc + targeted compiler, then we want the 32 bit unsigned value -1 to be + represented as a 64 bit value -1, and not as 0x00000000ffffffff. + The later confuses the sparc backend. */ + + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width + && (val & ((HOST_WIDE_INT) 1 << (width - 1)))) + val |= ((HOST_WIDE_INT) (-1) << width); + + return GEN_INT (val); +} + +/* Simplify a PLUS or MINUS, at least one of whose operands may be another + PLUS or MINUS. + + Rather than test for specific case, we do this by a brute-force method + and do all possible simplifications until no more changes occur. Then + we rebuild the operation. */ + +static rtx +simplify_plus_minus (code, mode, op0, op1) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; +{ + rtx ops[8]; + int negs[8]; + rtx result, tem; + int n_ops = 2, input_ops = 2, input_consts = 0, n_consts = 0; + int first = 1, negate = 0, changed; + int i, j; + + bzero ((char *) ops, sizeof ops); + + /* Set up the two operands and then expand them until nothing has been + changed. If we run out of room in our array, give up; this should + almost never happen. */ + + ops[0] = op0, ops[1] = op1, negs[0] = 0, negs[1] = (code == MINUS); + + changed = 1; + while (changed) + { + changed = 0; + + for (i = 0; i < n_ops; i++) + switch (GET_CODE (ops[i])) + { + case PLUS: + case MINUS: + if (n_ops == 7) + return 0; + + ops[n_ops] = XEXP (ops[i], 1); + negs[n_ops++] = GET_CODE (ops[i]) == MINUS ? !negs[i] : negs[i]; + ops[i] = XEXP (ops[i], 0); + input_ops++; + changed = 1; + break; + + case NEG: + ops[i] = XEXP (ops[i], 0); + negs[i] = ! negs[i]; + changed = 1; + break; + + case CONST: + ops[i] = XEXP (ops[i], 0); + input_consts++; + changed = 1; + break; + + case NOT: + /* ~a -> (-a - 1) */ + if (n_ops != 7) + { + ops[n_ops] = constm1_rtx; + negs[n_ops++] = negs[i]; + ops[i] = XEXP (ops[i], 0); + negs[i] = ! negs[i]; + changed = 1; + } + break; + + case CONST_INT: + if (negs[i]) + ops[i] = GEN_INT (- INTVAL (ops[i])), negs[i] = 0, changed = 1; + break; + } + } + + /* If we only have two operands, we can't do anything. */ + if (n_ops <= 2) + return 0; + + /* Now simplify each pair of operands until nothing changes. The first + time through just simplify constants against each other. */ + + changed = 1; + while (changed) + { + changed = first; + + for (i = 0; i < n_ops - 1; i++) + for (j = i + 1; j < n_ops; j++) + if (ops[i] != 0 && ops[j] != 0 + && (! first || (CONSTANT_P (ops[i]) && CONSTANT_P (ops[j])))) + { + rtx lhs = ops[i], rhs = ops[j]; + enum rtx_code ncode = PLUS; + + if (negs[i] && ! negs[j]) + lhs = ops[j], rhs = ops[i], ncode = MINUS; + else if (! negs[i] && negs[j]) + ncode = MINUS; + + tem = simplify_binary_operation (ncode, mode, lhs, rhs); + if (tem) + { + ops[i] = tem, ops[j] = 0; + negs[i] = negs[i] && negs[j]; + if (GET_CODE (tem) == NEG) + ops[i] = XEXP (tem, 0), negs[i] = ! negs[i]; + + if (GET_CODE (ops[i]) == CONST_INT && negs[i]) + ops[i] = GEN_INT (- INTVAL (ops[i])), negs[i] = 0; + changed = 1; + } + } + + first = 0; + } + + /* Pack all the operands to the lower-numbered entries and give up if + we didn't reduce the number of operands we had. Make sure we + count a CONST as two operands. If we have the same number of + operands, but have made more CONSTs than we had, this is also + an improvement, so accept it. */ + + for (i = 0, j = 0; j < n_ops; j++) + if (ops[j] != 0) + { + ops[i] = ops[j], negs[i++] = negs[j]; + if (GET_CODE (ops[j]) == CONST) + n_consts++; + } + + if (i + n_consts > input_ops + || (i + n_consts == input_ops && n_consts <= input_consts)) + return 0; + + n_ops = i; + + /* If we have a CONST_INT, put it last. */ + for (i = 0; i < n_ops - 1; i++) + if (GET_CODE (ops[i]) == CONST_INT) + { + tem = ops[n_ops - 1], ops[n_ops - 1] = ops[i] , ops[i] = tem; + j = negs[n_ops - 1], negs[n_ops - 1] = negs[i], negs[i] = j; + } + + /* Put a non-negated operand first. If there aren't any, make all + operands positive and negate the whole thing later. */ + for (i = 0; i < n_ops && negs[i]; i++) + ; + + if (i == n_ops) + { + for (i = 0; i < n_ops; i++) + negs[i] = 0; + negate = 1; + } + else if (i != 0) + { + tem = ops[0], ops[0] = ops[i], ops[i] = tem; + j = negs[0], negs[0] = negs[i], negs[i] = j; + } + + /* Now make the result by performing the requested operations. */ + result = ops[0]; + for (i = 1; i < n_ops; i++) + result = cse_gen_binary (negs[i] ? MINUS : PLUS, mode, result, ops[i]); + + return negate ? gen_rtx (NEG, mode, result) : result; +} + +/* Make a binary operation by properly ordering the operands and + seeing if the expression folds. */ + +static rtx +cse_gen_binary (code, mode, op0, op1) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; +{ + rtx tem; + + /* Put complex operands first and constants second if commutative. */ + if (GET_RTX_CLASS (code) == 'c' + && ((CONSTANT_P (op0) && GET_CODE (op1) != CONST_INT) + || (GET_RTX_CLASS (GET_CODE (op0)) == 'o' + && GET_RTX_CLASS (GET_CODE (op1)) != 'o') + || (GET_CODE (op0) == SUBREG + && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op0))) == 'o' + && GET_RTX_CLASS (GET_CODE (op1)) != 'o'))) + tem = op0, op0 = op1, op1 = tem; + + /* If this simplifies, do it. */ + tem = simplify_binary_operation (code, mode, op0, op1); + + if (tem) + return tem; + + /* Handle addition and subtraction of CONST_INT specially. Otherwise, + just form the operation. */ + + if (code == PLUS && GET_CODE (op1) == CONST_INT + && GET_MODE (op0) != VOIDmode) + return plus_constant (op0, INTVAL (op1)); + else if (code == MINUS && GET_CODE (op1) == CONST_INT + && GET_MODE (op0) != VOIDmode) + return plus_constant (op0, - INTVAL (op1)); + else + return gen_rtx (code, mode, op0, op1); +} + +/* Like simplify_binary_operation except used for relational operators. + MODE is the mode of the operands, not that of the result. If MODE + is VOIDmode, both operands must also be VOIDmode and we compare the + operands in "infinite precision". + + If no simplification is possible, this function returns zero. Otherwise, + it returns either const_true_rtx or const0_rtx. */ + +rtx +simplify_relational_operation (code, mode, op0, op1) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; +{ + int equal, op0lt, op0ltu, op1lt, op1ltu; + rtx tem; + + /* If op0 is a compare, extract the comparison arguments from it. */ + if (GET_CODE (op0) == COMPARE && op1 == const0_rtx) + op1 = XEXP (op0, 1), op0 = XEXP (op0, 0); + + /* We can't simplify MODE_CC values since we don't know what the + actual comparison is. */ + if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC +#ifdef HAVE_cc0 + || op0 == cc0_rtx +#endif + ) + return 0; + + /* For integer comparisons of A and B maybe we can simplify A - B and can + then simplify a comparison of that with zero. If A and B are both either + a register or a CONST_INT, this can't help; testing for these cases will + prevent infinite recursion here and speed things up. + + If CODE is an unsigned comparison, then we can never do this optimization, + because it gives an incorrect result if the subtraction wraps around zero. + ANSI C defines unsigned operations such that they never overflow, and + thus such cases can not be ignored. */ + + if (INTEGRAL_MODE_P (mode) && op1 != const0_rtx + && ! ((GET_CODE (op0) == REG || GET_CODE (op0) == CONST_INT) + && (GET_CODE (op1) == REG || GET_CODE (op1) == CONST_INT)) + && 0 != (tem = simplify_binary_operation (MINUS, mode, op0, op1)) + && code != GTU && code != GEU && code != LTU && code != LEU) + return simplify_relational_operation (signed_condition (code), + mode, tem, const0_rtx); + + /* For non-IEEE floating-point, if the two operands are equal, we know the + result. */ + if (rtx_equal_p (op0, op1) + && (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (GET_MODE (op0)) || flag_fast_math)) + equal = 1, op0lt = 0, op0ltu = 0, op1lt = 0, op1ltu = 0; + + /* If the operands are floating-point constants, see if we can fold + the result. */ +#if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) + else if (GET_CODE (op0) == CONST_DOUBLE && GET_CODE (op1) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT) + { + REAL_VALUE_TYPE d0, d1; + jmp_buf handler; + + if (setjmp (handler)) + return 0; + + set_float_handler (handler); + REAL_VALUE_FROM_CONST_DOUBLE (d0, op0); + REAL_VALUE_FROM_CONST_DOUBLE (d1, op1); + equal = REAL_VALUES_EQUAL (d0, d1); + op0lt = op0ltu = REAL_VALUES_LESS (d0, d1); + op1lt = op1ltu = REAL_VALUES_LESS (d1, d0); + set_float_handler (NULL_PTR); + } +#endif /* not REAL_IS_NOT_DOUBLE, or REAL_ARITHMETIC */ + + /* Otherwise, see if the operands are both integers. */ + else if ((GET_MODE_CLASS (mode) == MODE_INT || mode == VOIDmode) + && (GET_CODE (op0) == CONST_DOUBLE || GET_CODE (op0) == CONST_INT) + && (GET_CODE (op1) == CONST_DOUBLE || GET_CODE (op1) == CONST_INT)) + { + int width = GET_MODE_BITSIZE (mode); + HOST_WIDE_INT l0s, h0s, l1s, h1s; + unsigned HOST_WIDE_INT l0u, h0u, l1u, h1u; + + /* Get the two words comprising each integer constant. */ + if (GET_CODE (op0) == CONST_DOUBLE) + { + l0u = l0s = CONST_DOUBLE_LOW (op0); + h0u = h0s = CONST_DOUBLE_HIGH (op0); + } + else + { + l0u = l0s = INTVAL (op0); + h0u = 0, h0s = l0s < 0 ? -1 : 0; + } + + if (GET_CODE (op1) == CONST_DOUBLE) + { + l1u = l1s = CONST_DOUBLE_LOW (op1); + h1u = h1s = CONST_DOUBLE_HIGH (op1); + } + else + { + l1u = l1s = INTVAL (op1); + h1u = 0, h1s = l1s < 0 ? -1 : 0; + } + + /* If WIDTH is nonzero and smaller than HOST_BITS_PER_WIDE_INT, + we have to sign or zero-extend the values. */ + if (width != 0 && width <= HOST_BITS_PER_WIDE_INT) + h0u = h1u = 0, h0s = l0s < 0 ? -1 : 0, h1s = l1s < 0 ? -1 : 0; + + if (width != 0 && width < HOST_BITS_PER_WIDE_INT) + { + l0u &= ((HOST_WIDE_INT) 1 << width) - 1; + l1u &= ((HOST_WIDE_INT) 1 << width) - 1; + + if (l0s & ((HOST_WIDE_INT) 1 << (width - 1))) + l0s |= ((HOST_WIDE_INT) (-1) << width); + + if (l1s & ((HOST_WIDE_INT) 1 << (width - 1))) + l1s |= ((HOST_WIDE_INT) (-1) << width); + } + + equal = (h0u == h1u && l0u == l1u); + op0lt = (h0s < h1s || (h0s == h1s && l0s < l1s)); + op1lt = (h1s < h0s || (h1s == h0s && l1s < l0s)); + op0ltu = (h0u < h1u || (h0u == h1u && l0u < l1u)); + op1ltu = (h1u < h0u || (h1u == h0u && l1u < l0u)); + } + + /* Otherwise, there are some code-specific tests we can make. */ + else + { + switch (code) + { + case EQ: + /* References to the frame plus a constant or labels cannot + be zero, but a SYMBOL_REF can due to #pragma weak. */ + if (((NONZERO_BASE_PLUS_P (op0) && op1 == const0_rtx) + || GET_CODE (op0) == LABEL_REF) +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + /* On some machines, the ap reg can be 0 sometimes. */ + && op0 != arg_pointer_rtx +#endif + ) + return const0_rtx; + break; + + case NE: + if (((NONZERO_BASE_PLUS_P (op0) && op1 == const0_rtx) + || GET_CODE (op0) == LABEL_REF) +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + && op0 != arg_pointer_rtx +#endif + ) + return const_true_rtx; + break; + + case GEU: + /* Unsigned values are never negative. */ + if (op1 == const0_rtx) + return const_true_rtx; + break; + + case LTU: + if (op1 == const0_rtx) + return const0_rtx; + break; + + case LEU: + /* Unsigned values are never greater than the largest + unsigned value. */ + if (GET_CODE (op1) == CONST_INT + && INTVAL (op1) == GET_MODE_MASK (mode) + && INTEGRAL_MODE_P (mode)) + return const_true_rtx; + break; + + case GTU: + if (GET_CODE (op1) == CONST_INT + && INTVAL (op1) == GET_MODE_MASK (mode) + && INTEGRAL_MODE_P (mode)) + return const0_rtx; + break; + } + + return 0; + } + + /* If we reach here, EQUAL, OP0LT, OP0LTU, OP1LT, and OP1LTU are set + as appropriate. */ + switch (code) + { + case EQ: + return equal ? const_true_rtx : const0_rtx; + case NE: + return ! equal ? const_true_rtx : const0_rtx; + case LT: + return op0lt ? const_true_rtx : const0_rtx; + case GT: + return op1lt ? const_true_rtx : const0_rtx; + case LTU: + return op0ltu ? const_true_rtx : const0_rtx; + case GTU: + return op1ltu ? const_true_rtx : const0_rtx; + case LE: + return equal || op0lt ? const_true_rtx : const0_rtx; + case GE: + return equal || op1lt ? const_true_rtx : const0_rtx; + case LEU: + return equal || op0ltu ? const_true_rtx : const0_rtx; + case GEU: + return equal || op1ltu ? const_true_rtx : const0_rtx; + } + + abort (); +} + +/* Simplify CODE, an operation with result mode MODE and three operands, + OP0, OP1, and OP2. OP0_MODE was the mode of OP0 before it became + a constant. Return 0 if no simplifications is possible. */ + +rtx +simplify_ternary_operation (code, mode, op0_mode, op0, op1, op2) + enum rtx_code code; + enum machine_mode mode, op0_mode; + rtx op0, op1, op2; +{ + int width = GET_MODE_BITSIZE (mode); + + /* VOIDmode means "infinite" precision. */ + if (width == 0) + width = HOST_BITS_PER_WIDE_INT; + + switch (code) + { + case SIGN_EXTRACT: + case ZERO_EXTRACT: + if (GET_CODE (op0) == CONST_INT + && GET_CODE (op1) == CONST_INT + && GET_CODE (op2) == CONST_INT + && INTVAL (op1) + INTVAL (op2) <= GET_MODE_BITSIZE (op0_mode) + && width <= HOST_BITS_PER_WIDE_INT) + { + /* Extracting a bit-field from a constant */ + HOST_WIDE_INT val = INTVAL (op0); + + if (BITS_BIG_ENDIAN) + val >>= (GET_MODE_BITSIZE (op0_mode) + - INTVAL (op2) - INTVAL (op1)); + else + val >>= INTVAL (op2); + + if (HOST_BITS_PER_WIDE_INT != INTVAL (op1)) + { + /* First zero-extend. */ + val &= ((HOST_WIDE_INT) 1 << INTVAL (op1)) - 1; + /* If desired, propagate sign bit. */ + if (code == SIGN_EXTRACT + && (val & ((HOST_WIDE_INT) 1 << (INTVAL (op1) - 1)))) + val |= ~ (((HOST_WIDE_INT) 1 << INTVAL (op1)) - 1); + } + + /* Clear the bits that don't belong in our mode, + unless they and our sign bit are all one. + So we get either a reasonable negative value or a reasonable + unsigned value for this mode. */ + if (width < HOST_BITS_PER_WIDE_INT + && ((val & ((HOST_WIDE_INT) (-1) << (width - 1))) + != ((HOST_WIDE_INT) (-1) << (width - 1)))) + val &= ((HOST_WIDE_INT) 1 << width) - 1; + + return GEN_INT (val); + } + break; + + case IF_THEN_ELSE: + if (GET_CODE (op0) == CONST_INT) + return op0 != const0_rtx ? op1 : op2; + break; + + default: + abort (); + } + + return 0; +} + +/* If X is a nontrivial arithmetic operation on an argument + for which a constant value can be determined, return + the result of operating on that value, as a constant. + Otherwise, return X, possibly with one or more operands + modified by recursive calls to this function. + + If X is a register whose contents are known, we do NOT + return those contents here. equiv_constant is called to + perform that task. + + INSN is the insn that we may be modifying. If it is 0, make a copy + of X before modifying it. */ + +static rtx +fold_rtx (x, insn) + rtx x; + rtx insn; +{ + register enum rtx_code code; + register enum machine_mode mode; + register char *fmt; + register int i; + rtx new = 0; + int copied = 0; + int must_swap = 0; + + /* Folded equivalents of first two operands of X. */ + rtx folded_arg0; + rtx folded_arg1; + + /* Constant equivalents of first three operands of X; + 0 when no such equivalent is known. */ + rtx const_arg0; + rtx const_arg1; + rtx const_arg2; + + /* The mode of the first operand of X. We need this for sign and zero + extends. */ + enum machine_mode mode_arg0; + + if (x == 0) + return x; + + mode = GET_MODE (x); + code = GET_CODE (x); + switch (code) + { + case CONST: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case LABEL_REF: + case REG: + /* No use simplifying an EXPR_LIST + since they are used only for lists of args + in a function call's REG_EQUAL note. */ + case EXPR_LIST: + return x; + +#ifdef HAVE_cc0 + case CC0: + return prev_insn_cc0; +#endif + + case PC: + /* If the next insn is a CODE_LABEL followed by a jump table, + PC's value is a LABEL_REF pointing to that label. That + lets us fold switch statements on the Vax. */ + if (insn && GET_CODE (insn) == JUMP_INSN) + { + rtx next = next_nonnote_insn (insn); + + if (next && GET_CODE (next) == CODE_LABEL + && NEXT_INSN (next) != 0 + && GET_CODE (NEXT_INSN (next)) == JUMP_INSN + && (GET_CODE (PATTERN (NEXT_INSN (next))) == ADDR_VEC + || GET_CODE (PATTERN (NEXT_INSN (next))) == ADDR_DIFF_VEC)) + return gen_rtx (LABEL_REF, Pmode, next); + } + break; + + case SUBREG: + /* See if we previously assigned a constant value to this SUBREG. */ + if ((new = lookup_as_function (x, CONST_INT)) != 0 + || (new = lookup_as_function (x, CONST_DOUBLE)) != 0) + return new; + + /* If this is a paradoxical SUBREG, we have no idea what value the + extra bits would have. However, if the operand is equivalent + to a SUBREG whose operand is the same as our mode, and all the + modes are within a word, we can just use the inner operand + because these SUBREGs just say how to treat the register. + + Similarly if we find an integer constant. */ + + if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) + { + enum machine_mode imode = GET_MODE (SUBREG_REG (x)); + struct table_elt *elt; + + if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD + && GET_MODE_SIZE (imode) <= UNITS_PER_WORD + && (elt = lookup (SUBREG_REG (x), HASH (SUBREG_REG (x), imode), + imode)) != 0) + for (elt = elt->first_same_value; + elt; elt = elt->next_same_value) + { + if (CONSTANT_P (elt->exp) + && GET_MODE (elt->exp) == VOIDmode) + return elt->exp; + + if (GET_CODE (elt->exp) == SUBREG + && GET_MODE (SUBREG_REG (elt->exp)) == mode + && exp_equiv_p (elt->exp, elt->exp, 1, 0)) + return copy_rtx (SUBREG_REG (elt->exp)); + } + + return x; + } + + /* Fold SUBREG_REG. If it changed, see if we can simplify the SUBREG. + We might be able to if the SUBREG is extracting a single word in an + integral mode or extracting the low part. */ + + folded_arg0 = fold_rtx (SUBREG_REG (x), insn); + const_arg0 = equiv_constant (folded_arg0); + if (const_arg0) + folded_arg0 = const_arg0; + + if (folded_arg0 != SUBREG_REG (x)) + { + new = 0; + + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_SIZE (mode) == UNITS_PER_WORD + && GET_MODE (SUBREG_REG (x)) != VOIDmode) + new = operand_subword (folded_arg0, SUBREG_WORD (x), 0, + GET_MODE (SUBREG_REG (x))); + if (new == 0 && subreg_lowpart_p (x)) + new = gen_lowpart_if_possible (mode, folded_arg0); + if (new) + return new; + } + + /* If this is a narrowing SUBREG and our operand is a REG, see if + we can find an equivalence for REG that is an arithmetic operation + in a wider mode where both operands are paradoxical SUBREGs + from objects of our result mode. In that case, we couldn't report + an equivalent value for that operation, since we don't know what the + extra bits will be. But we can find an equivalence for this SUBREG + by folding that operation is the narrow mode. This allows us to + fold arithmetic in narrow modes when the machine only supports + word-sized arithmetic. + + Also look for a case where we have a SUBREG whose operand is the + same as our result. If both modes are smaller than a word, we + are simply interpreting a register in different modes and we + can use the inner value. */ + + if (GET_CODE (folded_arg0) == REG + && GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (folded_arg0)) + && subreg_lowpart_p (x)) + { + struct table_elt *elt; + + /* We can use HASH here since we know that canon_hash won't be + called. */ + elt = lookup (folded_arg0, + HASH (folded_arg0, GET_MODE (folded_arg0)), + GET_MODE (folded_arg0)); + + if (elt) + elt = elt->first_same_value; + + for (; elt; elt = elt->next_same_value) + { + enum rtx_code eltcode = GET_CODE (elt->exp); + + /* Just check for unary and binary operations. */ + if (GET_RTX_CLASS (GET_CODE (elt->exp)) == '1' + && GET_CODE (elt->exp) != SIGN_EXTEND + && GET_CODE (elt->exp) != ZERO_EXTEND + && GET_CODE (XEXP (elt->exp, 0)) == SUBREG + && GET_MODE (SUBREG_REG (XEXP (elt->exp, 0))) == mode) + { + rtx op0 = SUBREG_REG (XEXP (elt->exp, 0)); + + if (GET_CODE (op0) != REG && ! CONSTANT_P (op0)) + op0 = fold_rtx (op0, NULL_RTX); + + op0 = equiv_constant (op0); + if (op0) + new = simplify_unary_operation (GET_CODE (elt->exp), mode, + op0, mode); + } + else if ((GET_RTX_CLASS (GET_CODE (elt->exp)) == '2' + || GET_RTX_CLASS (GET_CODE (elt->exp)) == 'c') + && eltcode != DIV && eltcode != MOD + && eltcode != UDIV && eltcode != UMOD + && eltcode != ASHIFTRT && eltcode != LSHIFTRT + && eltcode != ROTATE && eltcode != ROTATERT + && ((GET_CODE (XEXP (elt->exp, 0)) == SUBREG + && (GET_MODE (SUBREG_REG (XEXP (elt->exp, 0))) + == mode)) + || CONSTANT_P (XEXP (elt->exp, 0))) + && ((GET_CODE (XEXP (elt->exp, 1)) == SUBREG + && (GET_MODE (SUBREG_REG (XEXP (elt->exp, 1))) + == mode)) + || CONSTANT_P (XEXP (elt->exp, 1)))) + { + rtx op0 = gen_lowpart_common (mode, XEXP (elt->exp, 0)); + rtx op1 = gen_lowpart_common (mode, XEXP (elt->exp, 1)); + + if (op0 && GET_CODE (op0) != REG && ! CONSTANT_P (op0)) + op0 = fold_rtx (op0, NULL_RTX); + + if (op0) + op0 = equiv_constant (op0); + + if (op1 && GET_CODE (op1) != REG && ! CONSTANT_P (op1)) + op1 = fold_rtx (op1, NULL_RTX); + + if (op1) + op1 = equiv_constant (op1); + + /* If we are looking for the low SImode part of + (ashift:DI c (const_int 32)), it doesn't work + to compute that in SImode, because a 32-bit shift + in SImode is unpredictable. We know the value is 0. */ + if (op0 && op1 + && GET_CODE (elt->exp) == ASHIFT + && GET_CODE (op1) == CONST_INT + && INTVAL (op1) >= GET_MODE_BITSIZE (mode)) + { + if (INTVAL (op1) < GET_MODE_BITSIZE (GET_MODE (elt->exp))) + + /* If the count fits in the inner mode's width, + but exceeds the outer mode's width, + the value will get truncated to 0 + by the subreg. */ + new = const0_rtx; + else + /* If the count exceeds even the inner mode's width, + don't fold this expression. */ + new = 0; + } + else if (op0 && op1) + new = simplify_binary_operation (GET_CODE (elt->exp), mode, + op0, op1); + } + + else if (GET_CODE (elt->exp) == SUBREG + && GET_MODE (SUBREG_REG (elt->exp)) == mode + && (GET_MODE_SIZE (GET_MODE (folded_arg0)) + <= UNITS_PER_WORD) + && exp_equiv_p (elt->exp, elt->exp, 1, 0)) + new = copy_rtx (SUBREG_REG (elt->exp)); + + if (new) + return new; + } + } + + return x; + + case NOT: + case NEG: + /* If we have (NOT Y), see if Y is known to be (NOT Z). + If so, (NOT Y) simplifies to Z. Similarly for NEG. */ + new = lookup_as_function (XEXP (x, 0), code); + if (new) + return fold_rtx (copy_rtx (XEXP (new, 0)), insn); + break; + + case MEM: + /* If we are not actually processing an insn, don't try to find the + best address. Not only don't we care, but we could modify the + MEM in an invalid way since we have no insn to validate against. */ + if (insn != 0) + find_best_addr (insn, &XEXP (x, 0)); + + { + /* Even if we don't fold in the insn itself, + we can safely do so here, in hopes of getting a constant. */ + rtx addr = fold_rtx (XEXP (x, 0), NULL_RTX); + rtx base = 0; + HOST_WIDE_INT offset = 0; + + if (GET_CODE (addr) == REG + && REGNO_QTY_VALID_P (REGNO (addr)) + && GET_MODE (addr) == qty_mode[reg_qty[REGNO (addr)]] + && qty_const[reg_qty[REGNO (addr)]] != 0) + addr = qty_const[reg_qty[REGNO (addr)]]; + + /* If address is constant, split it into a base and integer offset. */ + if (GET_CODE (addr) == SYMBOL_REF || GET_CODE (addr) == LABEL_REF) + base = addr; + else if (GET_CODE (addr) == CONST && GET_CODE (XEXP (addr, 0)) == PLUS + && GET_CODE (XEXP (XEXP (addr, 0), 1)) == CONST_INT) + { + base = XEXP (XEXP (addr, 0), 0); + offset = INTVAL (XEXP (XEXP (addr, 0), 1)); + } + else if (GET_CODE (addr) == LO_SUM + && GET_CODE (XEXP (addr, 1)) == SYMBOL_REF) + base = XEXP (addr, 1); + + /* If this is a constant pool reference, we can fold it into its + constant to allow better value tracking. */ + if (base && GET_CODE (base) == SYMBOL_REF + && CONSTANT_POOL_ADDRESS_P (base)) + { + rtx constant = get_pool_constant (base); + enum machine_mode const_mode = get_pool_mode (base); + rtx new; + + if (CONSTANT_P (constant) && GET_CODE (constant) != CONST_INT) + constant_pool_entries_cost = COST (constant); + + /* If we are loading the full constant, we have an equivalence. */ + if (offset == 0 && mode == const_mode) + return constant; + + /* If this actually isn't a constant (weird!), we can't do + anything. Otherwise, handle the two most common cases: + extracting a word from a multi-word constant, and extracting + the low-order bits. Other cases don't seem common enough to + worry about. */ + if (! CONSTANT_P (constant)) + return x; + + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_SIZE (mode) == UNITS_PER_WORD + && offset % UNITS_PER_WORD == 0 + && (new = operand_subword (constant, + offset / UNITS_PER_WORD, + 0, const_mode)) != 0) + return new; + + if (((BYTES_BIG_ENDIAN + && offset == GET_MODE_SIZE (GET_MODE (constant)) - 1) + || (! BYTES_BIG_ENDIAN && offset == 0)) + && (new = gen_lowpart_if_possible (mode, constant)) != 0) + return new; + } + + /* If this is a reference to a label at a known position in a jump + table, we also know its value. */ + if (base && GET_CODE (base) == LABEL_REF) + { + rtx label = XEXP (base, 0); + rtx table_insn = NEXT_INSN (label); + + if (table_insn && GET_CODE (table_insn) == JUMP_INSN + && GET_CODE (PATTERN (table_insn)) == ADDR_VEC) + { + rtx table = PATTERN (table_insn); + + if (offset >= 0 + && (offset / GET_MODE_SIZE (GET_MODE (table)) + < XVECLEN (table, 0))) + return XVECEXP (table, 0, + offset / GET_MODE_SIZE (GET_MODE (table))); + } + if (table_insn && GET_CODE (table_insn) == JUMP_INSN + && GET_CODE (PATTERN (table_insn)) == ADDR_DIFF_VEC) + { + rtx table = PATTERN (table_insn); + + if (offset >= 0 + && (offset / GET_MODE_SIZE (GET_MODE (table)) + < XVECLEN (table, 1))) + { + offset /= GET_MODE_SIZE (GET_MODE (table)); + new = gen_rtx (MINUS, Pmode, XVECEXP (table, 1, offset), + XEXP (table, 0)); + + if (GET_MODE (table) != Pmode) + new = gen_rtx (TRUNCATE, GET_MODE (table), new); + + /* Indicate this is a constant. This isn't a + valid form of CONST, but it will only be used + to fold the next insns and then discarded, so + it should be safe. */ + return gen_rtx (CONST, GET_MODE (new), new); + } + } + } + + return x; + } + } + + const_arg0 = 0; + const_arg1 = 0; + const_arg2 = 0; + mode_arg0 = VOIDmode; + + /* Try folding our operands. + Then see which ones have constant values known. */ + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + if (fmt[i] == 'e') + { + rtx arg = XEXP (x, i); + rtx folded_arg = arg, const_arg = 0; + enum machine_mode mode_arg = GET_MODE (arg); + rtx cheap_arg, expensive_arg; + rtx replacements[2]; + int j; + + /* Most arguments are cheap, so handle them specially. */ + switch (GET_CODE (arg)) + { + case REG: + /* This is the same as calling equiv_constant; it is duplicated + here for speed. */ + if (REGNO_QTY_VALID_P (REGNO (arg)) + && qty_const[reg_qty[REGNO (arg)]] != 0 + && GET_CODE (qty_const[reg_qty[REGNO (arg)]]) != REG + && GET_CODE (qty_const[reg_qty[REGNO (arg)]]) != PLUS) + const_arg + = gen_lowpart_if_possible (GET_MODE (arg), + qty_const[reg_qty[REGNO (arg)]]); + break; + + case CONST: + case CONST_INT: + case SYMBOL_REF: + case LABEL_REF: + case CONST_DOUBLE: + const_arg = arg; + break; + +#ifdef HAVE_cc0 + case CC0: + folded_arg = prev_insn_cc0; + mode_arg = prev_insn_cc0_mode; + const_arg = equiv_constant (folded_arg); + break; +#endif + + default: + folded_arg = fold_rtx (arg, insn); + const_arg = equiv_constant (folded_arg); + } + + /* For the first three operands, see if the operand + is constant or equivalent to a constant. */ + switch (i) + { + case 0: + folded_arg0 = folded_arg; + const_arg0 = const_arg; + mode_arg0 = mode_arg; + break; + case 1: + folded_arg1 = folded_arg; + const_arg1 = const_arg; + break; + case 2: + const_arg2 = const_arg; + break; + } + + /* Pick the least expensive of the folded argument and an + equivalent constant argument. */ + if (const_arg == 0 || const_arg == folded_arg + || COST (const_arg) > COST (folded_arg)) + cheap_arg = folded_arg, expensive_arg = const_arg; + else + cheap_arg = const_arg, expensive_arg = folded_arg; + + /* Try to replace the operand with the cheapest of the two + possibilities. If it doesn't work and this is either of the first + two operands of a commutative operation, try swapping them. + If THAT fails, try the more expensive, provided it is cheaper + than what is already there. */ + + if (cheap_arg == XEXP (x, i)) + continue; + + if (insn == 0 && ! copied) + { + x = copy_rtx (x); + copied = 1; + } + + replacements[0] = cheap_arg, replacements[1] = expensive_arg; + for (j = 0; + j < 2 && replacements[j] + && COST (replacements[j]) < COST (XEXP (x, i)); + j++) + { + if (validate_change (insn, &XEXP (x, i), replacements[j], 0)) + break; + + if (code == NE || code == EQ || GET_RTX_CLASS (code) == 'c') + { + validate_change (insn, &XEXP (x, i), XEXP (x, 1 - i), 1); + validate_change (insn, &XEXP (x, 1 - i), replacements[j], 1); + + if (apply_change_group ()) + { + /* Swap them back to be invalid so that this loop can + continue and flag them to be swapped back later. */ + rtx tem; + + tem = XEXP (x, 0); XEXP (x, 0) = XEXP (x, 1); + XEXP (x, 1) = tem; + must_swap = 1; + break; + } + } + } + } + + else if (fmt[i] == 'E') + /* Don't try to fold inside of a vector of expressions. + Doing nothing is harmless. */ + ; + + /* If a commutative operation, place a constant integer as the second + operand unless the first operand is also a constant integer. Otherwise, + place any constant second unless the first operand is also a constant. */ + + if (code == EQ || code == NE || GET_RTX_CLASS (code) == 'c') + { + if (must_swap || (const_arg0 + && (const_arg1 == 0 + || (GET_CODE (const_arg0) == CONST_INT + && GET_CODE (const_arg1) != CONST_INT)))) + { + register rtx tem = XEXP (x, 0); + + if (insn == 0 && ! copied) + { + x = copy_rtx (x); + copied = 1; + } + + validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1); + validate_change (insn, &XEXP (x, 1), tem, 1); + if (apply_change_group ()) + { + tem = const_arg0, const_arg0 = const_arg1, const_arg1 = tem; + tem = folded_arg0, folded_arg0 = folded_arg1, folded_arg1 = tem; + } + } + } + + /* If X is an arithmetic operation, see if we can simplify it. */ + + switch (GET_RTX_CLASS (code)) + { + case '1': + { + int is_const = 0; + + /* We can't simplify extension ops unless we know the + original mode. */ + if ((code == ZERO_EXTEND || code == SIGN_EXTEND) + && mode_arg0 == VOIDmode) + break; + + /* If we had a CONST, strip it off and put it back later if we + fold. */ + if (const_arg0 != 0 && GET_CODE (const_arg0) == CONST) + is_const = 1, const_arg0 = XEXP (const_arg0, 0); + + new = simplify_unary_operation (code, mode, + const_arg0 ? const_arg0 : folded_arg0, + mode_arg0); + if (new != 0 && is_const) + new = gen_rtx (CONST, mode, new); + } + break; + + case '<': + /* See what items are actually being compared and set FOLDED_ARG[01] + to those values and CODE to the actual comparison code. If any are + constant, set CONST_ARG0 and CONST_ARG1 appropriately. We needn't + do anything if both operands are already known to be constant. */ + + if (const_arg0 == 0 || const_arg1 == 0) + { + struct table_elt *p0, *p1; + rtx true = const_true_rtx, false = const0_rtx; + enum machine_mode mode_arg1; + +#ifdef FLOAT_STORE_FLAG_VALUE + if (GET_MODE_CLASS (mode) == MODE_FLOAT) + { + true = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE, + mode); + false = CONST0_RTX (mode); + } +#endif + + code = find_comparison_args (code, &folded_arg0, &folded_arg1, + &mode_arg0, &mode_arg1); + const_arg0 = equiv_constant (folded_arg0); + const_arg1 = equiv_constant (folded_arg1); + + /* If the mode is VOIDmode or a MODE_CC mode, we don't know + what kinds of things are being compared, so we can't do + anything with this comparison. */ + + if (mode_arg0 == VOIDmode || GET_MODE_CLASS (mode_arg0) == MODE_CC) + break; + + /* If we do not now have two constants being compared, see if we + can nevertheless deduce some things about the comparison. */ + if (const_arg0 == 0 || const_arg1 == 0) + { + /* Is FOLDED_ARG0 frame-pointer plus a constant? Or non-explicit + constant? These aren't zero, but we don't know their sign. */ + if (const_arg1 == const0_rtx + && (NONZERO_BASE_PLUS_P (folded_arg0) +#if 0 /* Sad to say, on sysvr4, #pragma weak can make a symbol address + come out as 0. */ + || GET_CODE (folded_arg0) == SYMBOL_REF +#endif + || GET_CODE (folded_arg0) == LABEL_REF + || GET_CODE (folded_arg0) == CONST)) + { + if (code == EQ) + return false; + else if (code == NE) + return true; + } + + /* See if the two operands are the same. We don't do this + for IEEE floating-point since we can't assume x == x + since x might be a NaN. */ + + if ((TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT + || ! FLOAT_MODE_P (mode_arg0) || flag_fast_math) + && (folded_arg0 == folded_arg1 + || (GET_CODE (folded_arg0) == REG + && GET_CODE (folded_arg1) == REG + && (reg_qty[REGNO (folded_arg0)] + == reg_qty[REGNO (folded_arg1)])) + || ((p0 = lookup (folded_arg0, + (safe_hash (folded_arg0, mode_arg0) + % NBUCKETS), mode_arg0)) + && (p1 = lookup (folded_arg1, + (safe_hash (folded_arg1, mode_arg0) + % NBUCKETS), mode_arg0)) + && p0->first_same_value == p1->first_same_value))) + return ((code == EQ || code == LE || code == GE + || code == LEU || code == GEU) + ? true : false); + + /* If FOLDED_ARG0 is a register, see if the comparison we are + doing now is either the same as we did before or the reverse + (we only check the reverse if not floating-point). */ + else if (GET_CODE (folded_arg0) == REG) + { + int qty = reg_qty[REGNO (folded_arg0)]; + + if (REGNO_QTY_VALID_P (REGNO (folded_arg0)) + && (comparison_dominates_p (qty_comparison_code[qty], code) + || (comparison_dominates_p (qty_comparison_code[qty], + reverse_condition (code)) + && ! FLOAT_MODE_P (mode_arg0))) + && (rtx_equal_p (qty_comparison_const[qty], folded_arg1) + || (const_arg1 + && rtx_equal_p (qty_comparison_const[qty], + const_arg1)) + || (GET_CODE (folded_arg1) == REG + && (reg_qty[REGNO (folded_arg1)] + == qty_comparison_qty[qty])))) + return (comparison_dominates_p (qty_comparison_code[qty], + code) + ? true : false); + } + } + } + + /* If we are comparing against zero, see if the first operand is + equivalent to an IOR with a constant. If so, we may be able to + determine the result of this comparison. */ + + if (const_arg1 == const0_rtx) + { + rtx y = lookup_as_function (folded_arg0, IOR); + rtx inner_const; + + if (y != 0 + && (inner_const = equiv_constant (XEXP (y, 1))) != 0 + && GET_CODE (inner_const) == CONST_INT + && INTVAL (inner_const) != 0) + { + int sign_bitnum = GET_MODE_BITSIZE (mode_arg0) - 1; + int has_sign = (HOST_BITS_PER_WIDE_INT >= sign_bitnum + && (INTVAL (inner_const) + & ((HOST_WIDE_INT) 1 << sign_bitnum))); + rtx true = const_true_rtx, false = const0_rtx; + +#ifdef FLOAT_STORE_FLAG_VALUE + if (GET_MODE_CLASS (mode) == MODE_FLOAT) + { + true = CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE, + mode); + false = CONST0_RTX (mode); + } +#endif + + switch (code) + { + case EQ: + return false; + case NE: + return true; + case LT: case LE: + if (has_sign) + return true; + break; + case GT: case GE: + if (has_sign) + return false; + break; + } + } + } + + new = simplify_relational_operation (code, mode_arg0, + const_arg0 ? const_arg0 : folded_arg0, + const_arg1 ? const_arg1 : folded_arg1); +#ifdef FLOAT_STORE_FLAG_VALUE + if (new != 0 && GET_MODE_CLASS (mode) == MODE_FLOAT) + new = ((new == const0_rtx) ? CONST0_RTX (mode) + : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE, mode)); +#endif + break; + + case '2': + case 'c': + switch (code) + { + case PLUS: + /* If the second operand is a LABEL_REF, see if the first is a MINUS + with that LABEL_REF as its second operand. If so, the result is + the first operand of that MINUS. This handles switches with an + ADDR_DIFF_VEC table. */ + if (const_arg1 && GET_CODE (const_arg1) == LABEL_REF) + { + rtx y + = GET_CODE (folded_arg0) == MINUS ? folded_arg0 + : lookup_as_function (folded_arg0, MINUS); + + if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF + && XEXP (XEXP (y, 1), 0) == XEXP (const_arg1, 0)) + return XEXP (y, 0); + + /* Now try for a CONST of a MINUS like the above. */ + if ((y = (GET_CODE (folded_arg0) == CONST ? folded_arg0 + : lookup_as_function (folded_arg0, CONST))) != 0 + && GET_CODE (XEXP (y, 0)) == MINUS + && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF + && XEXP (XEXP (XEXP (y, 0),1), 0) == XEXP (const_arg1, 0)) + return XEXP (XEXP (y, 0), 0); + } + + /* Likewise if the operands are in the other order. */ + if (const_arg0 && GET_CODE (const_arg0) == LABEL_REF) + { + rtx y + = GET_CODE (folded_arg1) == MINUS ? folded_arg1 + : lookup_as_function (folded_arg1, MINUS); + + if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF + && XEXP (XEXP (y, 1), 0) == XEXP (const_arg0, 0)) + return XEXP (y, 0); + + /* Now try for a CONST of a MINUS like the above. */ + if ((y = (GET_CODE (folded_arg1) == CONST ? folded_arg1 + : lookup_as_function (folded_arg1, CONST))) != 0 + && GET_CODE (XEXP (y, 0)) == MINUS + && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF + && XEXP (XEXP (XEXP (y, 0),1), 0) == XEXP (const_arg0, 0)) + return XEXP (XEXP (y, 0), 0); + } + + /* If second operand is a register equivalent to a negative + CONST_INT, see if we can find a register equivalent to the + positive constant. Make a MINUS if so. Don't do this for + a negative constant since we might then alternate between + chosing positive and negative constants. Having the positive + constant previously-used is the more common case. */ + if (const_arg1 && GET_CODE (const_arg1) == CONST_INT + && INTVAL (const_arg1) < 0 && GET_CODE (folded_arg1) == REG) + { + rtx new_const = GEN_INT (- INTVAL (const_arg1)); + struct table_elt *p + = lookup (new_const, safe_hash (new_const, mode) % NBUCKETS, + mode); + + if (p) + for (p = p->first_same_value; p; p = p->next_same_value) + if (GET_CODE (p->exp) == REG) + return cse_gen_binary (MINUS, mode, folded_arg0, + canon_reg (p->exp, NULL_RTX)); + } + goto from_plus; + + case MINUS: + /* If we have (MINUS Y C), see if Y is known to be (PLUS Z C2). + If so, produce (PLUS Z C2-C). */ + if (const_arg1 != 0 && GET_CODE (const_arg1) == CONST_INT) + { + rtx y = lookup_as_function (XEXP (x, 0), PLUS); + if (y && GET_CODE (XEXP (y, 1)) == CONST_INT) + return fold_rtx (plus_constant (copy_rtx (y), + -INTVAL (const_arg1)), + NULL_RTX); + } + + /* ... fall through ... */ + + from_plus: + case SMIN: case SMAX: case UMIN: case UMAX: + case IOR: case AND: case XOR: + case MULT: case DIV: case UDIV: + case ASHIFT: case LSHIFTRT: case ASHIFTRT: + /* If we have ( ) for an associative OP and REG + is known to be of similar form, we may be able to replace the + operation with a combined operation. This may eliminate the + intermediate operation if every use is simplified in this way. + Note that the similar optimization done by combine.c only works + if the intermediate operation's result has only one reference. */ + + if (GET_CODE (folded_arg0) == REG + && const_arg1 && GET_CODE (const_arg1) == CONST_INT) + { + int is_shift + = (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT); + rtx y = lookup_as_function (folded_arg0, code); + rtx inner_const; + enum rtx_code associate_code; + rtx new_const; + + if (y == 0 + || 0 == (inner_const + = equiv_constant (fold_rtx (XEXP (y, 1), 0))) + || GET_CODE (inner_const) != CONST_INT + /* If we have compiled a statement like + "if (x == (x & mask1))", and now are looking at + "x & mask2", we will have a case where the first operand + of Y is the same as our first operand. Unless we detect + this case, an infinite loop will result. */ + || XEXP (y, 0) == folded_arg0) + break; + + /* Don't associate these operations if they are a PLUS with the + same constant and it is a power of two. These might be doable + with a pre- or post-increment. Similarly for two subtracts of + identical powers of two with post decrement. */ + + if (code == PLUS && INTVAL (const_arg1) == INTVAL (inner_const) + && (0 +#if defined(HAVE_PRE_INCREMENT) || defined(HAVE_POST_INCREMENT) + || exact_log2 (INTVAL (const_arg1)) >= 0 +#endif +#if defined(HAVE_PRE_DECREMENT) || defined(HAVE_POST_DECREMENT) + || exact_log2 (- INTVAL (const_arg1)) >= 0 +#endif + )) + break; + + /* Compute the code used to compose the constants. For example, + A/C1/C2 is A/(C1 * C2), so if CODE == DIV, we want MULT. */ + + associate_code + = (code == MULT || code == DIV || code == UDIV ? MULT + : is_shift || code == PLUS || code == MINUS ? PLUS : code); + + new_const = simplify_binary_operation (associate_code, mode, + const_arg1, inner_const); + + if (new_const == 0) + break; + + /* If we are associating shift operations, don't let this + produce a shift of the size of the object or larger. + This could occur when we follow a sign-extend by a right + shift on a machine that does a sign-extend as a pair + of shifts. */ + + if (is_shift && GET_CODE (new_const) == CONST_INT + && INTVAL (new_const) >= GET_MODE_BITSIZE (mode)) + { + /* As an exception, we can turn an ASHIFTRT of this + form into a shift of the number of bits - 1. */ + if (code == ASHIFTRT) + new_const = GEN_INT (GET_MODE_BITSIZE (mode) - 1); + else + break; + } + + y = copy_rtx (XEXP (y, 0)); + + /* If Y contains our first operand (the most common way this + can happen is if Y is a MEM), we would do into an infinite + loop if we tried to fold it. So don't in that case. */ + + if (! reg_mentioned_p (folded_arg0, y)) + y = fold_rtx (y, insn); + + return cse_gen_binary (code, mode, y, new_const); + } + } + + new = simplify_binary_operation (code, mode, + const_arg0 ? const_arg0 : folded_arg0, + const_arg1 ? const_arg1 : folded_arg1); + break; + + case 'o': + /* (lo_sum (high X) X) is simply X. */ + if (code == LO_SUM && const_arg0 != 0 + && GET_CODE (const_arg0) == HIGH + && rtx_equal_p (XEXP (const_arg0, 0), const_arg1)) + return const_arg1; + break; + + case '3': + case 'b': + new = simplify_ternary_operation (code, mode, mode_arg0, + const_arg0 ? const_arg0 : folded_arg0, + const_arg1 ? const_arg1 : folded_arg1, + const_arg2 ? const_arg2 : XEXP (x, 2)); + break; + } + + return new ? new : x; +} + +/* Return a constant value currently equivalent to X. + Return 0 if we don't know one. */ + +static rtx +equiv_constant (x) + rtx x; +{ + if (GET_CODE (x) == REG + && REGNO_QTY_VALID_P (REGNO (x)) + && qty_const[reg_qty[REGNO (x)]]) + x = gen_lowpart_if_possible (GET_MODE (x), qty_const[reg_qty[REGNO (x)]]); + + if (x != 0 && CONSTANT_P (x)) + return x; + + /* If X is a MEM, try to fold it outside the context of any insn to see if + it might be equivalent to a constant. That handles the case where it + is a constant-pool reference. Then try to look it up in the hash table + in case it is something whose value we have seen before. */ + + if (GET_CODE (x) == MEM) + { + struct table_elt *elt; + + x = fold_rtx (x, NULL_RTX); + if (CONSTANT_P (x)) + return x; + + elt = lookup (x, safe_hash (x, GET_MODE (x)) % NBUCKETS, GET_MODE (x)); + if (elt == 0) + return 0; + + for (elt = elt->first_same_value; elt; elt = elt->next_same_value) + if (elt->is_const && CONSTANT_P (elt->exp)) + return elt->exp; + } + + return 0; +} + +/* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a fixed-point + number, return an rtx (MEM, SUBREG, or CONST_INT) that refers to the + least-significant part of X. + MODE specifies how big a part of X to return. + + If the requested operation cannot be done, 0 is returned. + + This is similar to gen_lowpart in emit-rtl.c. */ + +rtx +gen_lowpart_if_possible (mode, x) + enum machine_mode mode; + register rtx x; +{ + rtx result = gen_lowpart_common (mode, x); + + if (result) + return result; + else if (GET_CODE (x) == MEM) + { + /* This is the only other case we handle. */ + register int offset = 0; + rtx new; + + if (WORDS_BIG_ENDIAN) + offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); + if (BYTES_BIG_ENDIAN) + /* Adjust the address so that the address-after-the-data is + unchanged. */ + offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) + - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))); + new = gen_rtx (MEM, mode, plus_constant (XEXP (x, 0), offset)); + if (! memory_address_p (mode, XEXP (new, 0))) + return 0; + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x); + return new; + } + else + return 0; +} + +/* Given INSN, a jump insn, TAKEN indicates if we are following the "taken" + branch. It will be zero if not. + + In certain cases, this can cause us to add an equivalence. For example, + if we are following the taken case of + if (i == 2) + we can add the fact that `i' and '2' are now equivalent. + + In any case, we can record that this comparison was passed. If the same + comparison is seen later, we will know its value. */ + +static void +record_jump_equiv (insn, taken) + rtx insn; + int taken; +{ + int cond_known_true; + rtx op0, op1; + enum machine_mode mode, mode0, mode1; + int reversed_nonequality = 0; + enum rtx_code code; + + /* Ensure this is the right kind of insn. */ + if (! condjump_p (insn) || simplejump_p (insn)) + return; + + /* See if this jump condition is known true or false. */ + if (taken) + cond_known_true = (XEXP (SET_SRC (PATTERN (insn)), 2) == pc_rtx); + else + cond_known_true = (XEXP (SET_SRC (PATTERN (insn)), 1) == pc_rtx); + + /* Get the type of comparison being done and the operands being compared. + If we had to reverse a non-equality condition, record that fact so we + know that it isn't valid for floating-point. */ + code = GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 0)); + op0 = fold_rtx (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 0), insn); + op1 = fold_rtx (XEXP (XEXP (SET_SRC (PATTERN (insn)), 0), 1), insn); + + code = find_comparison_args (code, &op0, &op1, &mode0, &mode1); + if (! cond_known_true) + { + reversed_nonequality = (code != EQ && code != NE); + code = reverse_condition (code); + } + + /* The mode is the mode of the non-constant. */ + mode = mode0; + if (mode1 != VOIDmode) + mode = mode1; + + record_jump_cond (code, mode, op0, op1, reversed_nonequality); +} + +/* We know that comparison CODE applied to OP0 and OP1 in MODE is true. + REVERSED_NONEQUALITY is nonzero if CODE had to be swapped. + Make any useful entries we can with that information. Called from + above function and called recursively. */ + +static void +record_jump_cond (code, mode, op0, op1, reversed_nonequality) + enum rtx_code code; + enum machine_mode mode; + rtx op0, op1; + int reversed_nonequality; +{ + unsigned op0_hash, op1_hash; + int op0_in_memory, op0_in_struct, op1_in_memory, op1_in_struct; + struct table_elt *op0_elt, *op1_elt; + + /* If OP0 and OP1 are known equal, and either is a paradoxical SUBREG, + we know that they are also equal in the smaller mode (this is also + true for all smaller modes whether or not there is a SUBREG, but + is not worth testing for with no SUBREG. */ + + /* Note that GET_MODE (op0) may not equal MODE. */ + if (code == EQ && GET_CODE (op0) == SUBREG + && (GET_MODE_SIZE (GET_MODE (op0)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))))) + { + enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op0)); + rtx tem = gen_lowpart_if_possible (inner_mode, op1); + + record_jump_cond (code, mode, SUBREG_REG (op0), + tem ? tem : gen_rtx (SUBREG, inner_mode, op1, 0), + reversed_nonequality); + } + + if (code == EQ && GET_CODE (op1) == SUBREG + && (GET_MODE_SIZE (GET_MODE (op1)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1))))) + { + enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op1)); + rtx tem = gen_lowpart_if_possible (inner_mode, op0); + + record_jump_cond (code, mode, SUBREG_REG (op1), + tem ? tem : gen_rtx (SUBREG, inner_mode, op0, 0), + reversed_nonequality); + } + + /* Similarly, if this is an NE comparison, and either is a SUBREG + making a smaller mode, we know the whole thing is also NE. */ + + /* Note that GET_MODE (op0) may not equal MODE; + if we test MODE instead, we can get an infinite recursion + alternating between two modes each wider than MODE. */ + + if (code == NE && GET_CODE (op0) == SUBREG + && subreg_lowpart_p (op0) + && (GET_MODE_SIZE (GET_MODE (op0)) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (op0))))) + { + enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op0)); + rtx tem = gen_lowpart_if_possible (inner_mode, op1); + + record_jump_cond (code, mode, SUBREG_REG (op0), + tem ? tem : gen_rtx (SUBREG, inner_mode, op1, 0), + reversed_nonequality); + } + + if (code == NE && GET_CODE (op1) == SUBREG + && subreg_lowpart_p (op1) + && (GET_MODE_SIZE (GET_MODE (op1)) + < GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1))))) + { + enum machine_mode inner_mode = GET_MODE (SUBREG_REG (op1)); + rtx tem = gen_lowpart_if_possible (inner_mode, op0); + + record_jump_cond (code, mode, SUBREG_REG (op1), + tem ? tem : gen_rtx (SUBREG, inner_mode, op0, 0), + reversed_nonequality); + } + + /* Hash both operands. */ + + do_not_record = 0; + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + op0_hash = HASH (op0, mode); + op0_in_memory = hash_arg_in_memory; + op0_in_struct = hash_arg_in_struct; + + if (do_not_record) + return; + + do_not_record = 0; + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + op1_hash = HASH (op1, mode); + op1_in_memory = hash_arg_in_memory; + op1_in_struct = hash_arg_in_struct; + + if (do_not_record) + return; + + /* Look up both operands. */ + op0_elt = lookup (op0, op0_hash, mode); + op1_elt = lookup (op1, op1_hash, mode); + + /* If both operands are already equivalent or if they are not in the + table but are identical, do nothing. */ + if ((op0_elt != 0 && op1_elt != 0 + && op0_elt->first_same_value == op1_elt->first_same_value) + || op0 == op1 || rtx_equal_p (op0, op1)) + return; + + /* If we aren't setting two things equal all we can do is save this + comparison. Similarly if this is floating-point. In the latter + case, OP1 might be zero and both -0.0 and 0.0 are equal to it. + If we record the equality, we might inadvertently delete code + whose intent was to change -0 to +0. */ + + if (code != EQ || FLOAT_MODE_P (GET_MODE (op0))) + { + /* If we reversed a floating-point comparison, if OP0 is not a + register, or if OP1 is neither a register or constant, we can't + do anything. */ + + if (GET_CODE (op1) != REG) + op1 = equiv_constant (op1); + + if ((reversed_nonequality && FLOAT_MODE_P (mode)) + || GET_CODE (op0) != REG || op1 == 0) + return; + + /* Put OP0 in the hash table if it isn't already. This gives it a + new quantity number. */ + if (op0_elt == 0) + { + if (insert_regs (op0, NULL_PTR, 0)) + { + rehash_using_reg (op0); + op0_hash = HASH (op0, mode); + + /* If OP0 is contained in OP1, this changes its hash code + as well. Faster to rehash than to check, except + for the simple case of a constant. */ + if (! CONSTANT_P (op1)) + op1_hash = HASH (op1,mode); + } + + op0_elt = insert (op0, NULL_PTR, op0_hash, mode); + op0_elt->in_memory = op0_in_memory; + op0_elt->in_struct = op0_in_struct; + } + + qty_comparison_code[reg_qty[REGNO (op0)]] = code; + if (GET_CODE (op1) == REG) + { + /* Look it up again--in case op0 and op1 are the same. */ + op1_elt = lookup (op1, op1_hash, mode); + + /* Put OP1 in the hash table so it gets a new quantity number. */ + if (op1_elt == 0) + { + if (insert_regs (op1, NULL_PTR, 0)) + { + rehash_using_reg (op1); + op1_hash = HASH (op1, mode); + } + + op1_elt = insert (op1, NULL_PTR, op1_hash, mode); + op1_elt->in_memory = op1_in_memory; + op1_elt->in_struct = op1_in_struct; + } + + qty_comparison_qty[reg_qty[REGNO (op0)]] = reg_qty[REGNO (op1)]; + qty_comparison_const[reg_qty[REGNO (op0)]] = 0; + } + else + { + qty_comparison_qty[reg_qty[REGNO (op0)]] = -1; + qty_comparison_const[reg_qty[REGNO (op0)]] = op1; + } + + return; + } + + /* If either side is still missing an equivalence, make it now, + then merge the equivalences. */ + + if (op0_elt == 0) + { + if (insert_regs (op0, NULL_PTR, 0)) + { + rehash_using_reg (op0); + op0_hash = HASH (op0, mode); + } + + op0_elt = insert (op0, NULL_PTR, op0_hash, mode); + op0_elt->in_memory = op0_in_memory; + op0_elt->in_struct = op0_in_struct; + } + + if (op1_elt == 0) + { + if (insert_regs (op1, NULL_PTR, 0)) + { + rehash_using_reg (op1); + op1_hash = HASH (op1, mode); + } + + op1_elt = insert (op1, NULL_PTR, op1_hash, mode); + op1_elt->in_memory = op1_in_memory; + op1_elt->in_struct = op1_in_struct; + } + + merge_equiv_classes (op0_elt, op1_elt); + last_jump_equiv_class = op0_elt; +} + +/* CSE processing for one instruction. + First simplify sources and addresses of all assignments + in the instruction, using previously-computed equivalents values. + Then install the new sources and destinations in the table + of available values. + + If IN_LIBCALL_BLOCK is nonzero, don't record any equivalence made in + the insn. */ + +/* Data on one SET contained in the instruction. */ + +struct set +{ + /* The SET rtx itself. */ + rtx rtl; + /* The SET_SRC of the rtx (the original value, if it is changing). */ + rtx src; + /* The hash-table element for the SET_SRC of the SET. */ + struct table_elt *src_elt; + /* Hash value for the SET_SRC. */ + unsigned src_hash; + /* Hash value for the SET_DEST. */ + unsigned dest_hash; + /* The SET_DEST, with SUBREG, etc., stripped. */ + rtx inner_dest; + /* Place where the pointer to the INNER_DEST was found. */ + rtx *inner_dest_loc; + /* Nonzero if the SET_SRC is in memory. */ + char src_in_memory; + /* Nonzero if the SET_SRC is in a structure. */ + char src_in_struct; + /* Nonzero if the SET_SRC contains something + whose value cannot be predicted and understood. */ + char src_volatile; + /* Original machine mode, in case it becomes a CONST_INT. */ + enum machine_mode mode; + /* A constant equivalent for SET_SRC, if any. */ + rtx src_const; + /* Hash value of constant equivalent for SET_SRC. */ + unsigned src_const_hash; + /* Table entry for constant equivalent for SET_SRC, if any. */ + struct table_elt *src_const_elt; +}; + +static void +cse_insn (insn, in_libcall_block) + rtx insn; + int in_libcall_block; +{ + register rtx x = PATTERN (insn); + register int i; + rtx tem; + register int n_sets = 0; + + /* Records what this insn does to set CC0. */ + rtx this_insn_cc0 = 0; + enum machine_mode this_insn_cc0_mode; + struct write_data writes_memory; + static struct write_data init = {0, 0, 0, 0}; + + rtx src_eqv = 0; + struct table_elt *src_eqv_elt = 0; + int src_eqv_volatile; + int src_eqv_in_memory; + int src_eqv_in_struct; + unsigned src_eqv_hash; + + struct set *sets; + + this_insn = insn; + writes_memory = init; + + /* Find all the SETs and CLOBBERs in this instruction. + Record all the SETs in the array `set' and count them. + Also determine whether there is a CLOBBER that invalidates + all memory references, or all references at varying addresses. */ + + if (GET_CODE (insn) == CALL_INSN) + { + for (tem = CALL_INSN_FUNCTION_USAGE (insn); tem; tem = XEXP (tem, 1)) + if (GET_CODE (XEXP (tem, 0)) == CLOBBER) + invalidate (SET_DEST (XEXP (tem, 0)), VOIDmode); + } + + if (GET_CODE (x) == SET) + { + sets = (struct set *) alloca (sizeof (struct set)); + sets[0].rtl = x; + + /* Ignore SETs that are unconditional jumps. + They never need cse processing, so this does not hurt. + The reason is not efficiency but rather + so that we can test at the end for instructions + that have been simplified to unconditional jumps + and not be misled by unchanged instructions + that were unconditional jumps to begin with. */ + if (SET_DEST (x) == pc_rtx + && GET_CODE (SET_SRC (x)) == LABEL_REF) + ; + + /* Don't count call-insns, (set (reg 0) (call ...)), as a set. + The hard function value register is used only once, to copy to + someplace else, so it isn't worth cse'ing (and on 80386 is unsafe)! + Ensure we invalidate the destination register. On the 80386 no + other code would invalidate it since it is a fixed_reg. + We need not check the return of apply_change_group; see canon_reg. */ + + else if (GET_CODE (SET_SRC (x)) == CALL) + { + canon_reg (SET_SRC (x), insn); + apply_change_group (); + fold_rtx (SET_SRC (x), insn); + invalidate (SET_DEST (x), VOIDmode); + } + else + n_sets = 1; + } + else if (GET_CODE (x) == PARALLEL) + { + register int lim = XVECLEN (x, 0); + + sets = (struct set *) alloca (lim * sizeof (struct set)); + + /* Find all regs explicitly clobbered in this insn, + and ensure they are not replaced with any other regs + elsewhere in this insn. + When a reg that is clobbered is also used for input, + we should presume that that is for a reason, + and we should not substitute some other register + which is not supposed to be clobbered. + Therefore, this loop cannot be merged into the one below + because a CALL may precede a CLOBBER and refer to the + value clobbered. We must not let a canonicalization do + anything in that case. */ + for (i = 0; i < lim; i++) + { + register rtx y = XVECEXP (x, 0, i); + if (GET_CODE (y) == CLOBBER) + { + rtx clobbered = XEXP (y, 0); + + if (GET_CODE (clobbered) == REG + || GET_CODE (clobbered) == SUBREG) + invalidate (clobbered, VOIDmode); + else if (GET_CODE (clobbered) == STRICT_LOW_PART + || GET_CODE (clobbered) == ZERO_EXTRACT) + invalidate (XEXP (clobbered, 0), GET_MODE (clobbered)); + } + } + + for (i = 0; i < lim; i++) + { + register rtx y = XVECEXP (x, 0, i); + if (GET_CODE (y) == SET) + { + /* As above, we ignore unconditional jumps and call-insns and + ignore the result of apply_change_group. */ + if (GET_CODE (SET_SRC (y)) == CALL) + { + canon_reg (SET_SRC (y), insn); + apply_change_group (); + fold_rtx (SET_SRC (y), insn); + invalidate (SET_DEST (y), VOIDmode); + } + else if (SET_DEST (y) == pc_rtx + && GET_CODE (SET_SRC (y)) == LABEL_REF) + ; + else + sets[n_sets++].rtl = y; + } + else if (GET_CODE (y) == CLOBBER) + { + /* If we clobber memory, take note of that, + and canon the address. + This does nothing when a register is clobbered + because we have already invalidated the reg. */ + if (GET_CODE (XEXP (y, 0)) == MEM) + { + canon_reg (XEXP (y, 0), NULL_RTX); + note_mem_written (XEXP (y, 0), &writes_memory); + } + } + else if (GET_CODE (y) == USE + && ! (GET_CODE (XEXP (y, 0)) == REG + && REGNO (XEXP (y, 0)) < FIRST_PSEUDO_REGISTER)) + canon_reg (y, NULL_RTX); + else if (GET_CODE (y) == CALL) + { + /* The result of apply_change_group can be ignored; see + canon_reg. */ + canon_reg (y, insn); + apply_change_group (); + fold_rtx (y, insn); + } + } + } + else if (GET_CODE (x) == CLOBBER) + { + if (GET_CODE (XEXP (x, 0)) == MEM) + { + canon_reg (XEXP (x, 0), NULL_RTX); + note_mem_written (XEXP (x, 0), &writes_memory); + } + } + + /* Canonicalize a USE of a pseudo register or memory location. */ + else if (GET_CODE (x) == USE + && ! (GET_CODE (XEXP (x, 0)) == REG + && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER)) + canon_reg (XEXP (x, 0), NULL_RTX); + else if (GET_CODE (x) == CALL) + { + /* The result of apply_change_group can be ignored; see canon_reg. */ + canon_reg (x, insn); + apply_change_group (); + fold_rtx (x, insn); + } + + /* Store the equivalent value in SRC_EQV, if different, or if the DEST + is a STRICT_LOW_PART. The latter condition is necessary because SRC_EQV + is handled specially for this case, and if it isn't set, then there will + be no equivalence for the destination. */ + if (n_sets == 1 && REG_NOTES (insn) != 0 + && (tem = find_reg_note (insn, REG_EQUAL, NULL_RTX)) != 0 + && (! rtx_equal_p (XEXP (tem, 0), SET_SRC (sets[0].rtl)) + || GET_CODE (SET_DEST (sets[0].rtl)) == STRICT_LOW_PART)) + src_eqv = canon_reg (XEXP (tem, 0), NULL_RTX); + + /* Canonicalize sources and addresses of destinations. + We do this in a separate pass to avoid problems when a MATCH_DUP is + present in the insn pattern. In that case, we want to ensure that + we don't break the duplicate nature of the pattern. So we will replace + both operands at the same time. Otherwise, we would fail to find an + equivalent substitution in the loop calling validate_change below. + + We used to suppress canonicalization of DEST if it appears in SRC, + but we don't do this any more. */ + + for (i = 0; i < n_sets; i++) + { + rtx dest = SET_DEST (sets[i].rtl); + rtx src = SET_SRC (sets[i].rtl); + rtx new = canon_reg (src, insn); + + if ((GET_CODE (new) == REG && GET_CODE (src) == REG + && ((REGNO (new) < FIRST_PSEUDO_REGISTER) + != (REGNO (src) < FIRST_PSEUDO_REGISTER))) + || insn_n_dups[recog_memoized (insn)] > 0) + validate_change (insn, &SET_SRC (sets[i].rtl), new, 1); + else + SET_SRC (sets[i].rtl) = new; + + if (GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SIGN_EXTRACT) + { + validate_change (insn, &XEXP (dest, 1), + canon_reg (XEXP (dest, 1), insn), 1); + validate_change (insn, &XEXP (dest, 2), + canon_reg (XEXP (dest, 2), insn), 1); + } + + while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART + || GET_CODE (dest) == ZERO_EXTRACT + || GET_CODE (dest) == SIGN_EXTRACT) + dest = XEXP (dest, 0); + + if (GET_CODE (dest) == MEM) + canon_reg (dest, insn); + } + + /* Now that we have done all the replacements, we can apply the change + group and see if they all work. Note that this will cause some + canonicalizations that would have worked individually not to be applied + because some other canonicalization didn't work, but this should not + occur often. + + The result of apply_change_group can be ignored; see canon_reg. */ + + apply_change_group (); + + /* Set sets[i].src_elt to the class each source belongs to. + Detect assignments from or to volatile things + and set set[i] to zero so they will be ignored + in the rest of this function. + + Nothing in this loop changes the hash table or the register chains. */ + + for (i = 0; i < n_sets; i++) + { + register rtx src, dest; + register rtx src_folded; + register struct table_elt *elt = 0, *p; + enum machine_mode mode; + rtx src_eqv_here; + rtx src_const = 0; + rtx src_related = 0; + struct table_elt *src_const_elt = 0; + int src_cost = 10000, src_eqv_cost = 10000, src_folded_cost = 10000; + int src_related_cost = 10000, src_elt_cost = 10000; + /* Set non-zero if we need to call force_const_mem on with the + contents of src_folded before using it. */ + int src_folded_force_flag = 0; + + dest = SET_DEST (sets[i].rtl); + src = SET_SRC (sets[i].rtl); + + /* If SRC is a constant that has no machine mode, + hash it with the destination's machine mode. + This way we can keep different modes separate. */ + + mode = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src); + sets[i].mode = mode; + + if (src_eqv) + { + enum machine_mode eqvmode = mode; + if (GET_CODE (dest) == STRICT_LOW_PART) + eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0))); + do_not_record = 0; + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + src_eqv = fold_rtx (src_eqv, insn); + src_eqv_hash = HASH (src_eqv, eqvmode); + + /* Find the equivalence class for the equivalent expression. */ + + if (!do_not_record) + src_eqv_elt = lookup (src_eqv, src_eqv_hash, eqvmode); + + src_eqv_volatile = do_not_record; + src_eqv_in_memory = hash_arg_in_memory; + src_eqv_in_struct = hash_arg_in_struct; + } + + /* If this is a STRICT_LOW_PART assignment, src_eqv corresponds to the + value of the INNER register, not the destination. So it is not + a valid substitution for the source. But save it for later. */ + if (GET_CODE (dest) == STRICT_LOW_PART) + src_eqv_here = 0; + else + src_eqv_here = src_eqv; + + /* Simplify and foldable subexpressions in SRC. Then get the fully- + simplified result, which may not necessarily be valid. */ + src_folded = fold_rtx (src, insn); + +#if 0 + /* ??? This caused bad code to be generated for the m68k port with -O2. + Suppose src is (CONST_INT -1), and that after truncation src_folded + is (CONST_INT 3). Suppose src_folded is then used for src_const. + At the end we will add src and src_const to the same equivalence + class. We now have 3 and -1 on the same equivalence class. This + causes later instructions to be mis-optimized. */ + /* If storing a constant in a bitfield, pre-truncate the constant + so we will be able to record it later. */ + if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT + || GET_CODE (SET_DEST (sets[i].rtl)) == SIGN_EXTRACT) + { + rtx width = XEXP (SET_DEST (sets[i].rtl), 1); + + if (GET_CODE (src) == CONST_INT + && GET_CODE (width) == CONST_INT + && INTVAL (width) < HOST_BITS_PER_WIDE_INT + && (INTVAL (src) & ((HOST_WIDE_INT) (-1) << INTVAL (width)))) + src_folded + = GEN_INT (INTVAL (src) & (((HOST_WIDE_INT) 1 + << INTVAL (width)) - 1)); + } +#endif + + /* Compute SRC's hash code, and also notice if it + should not be recorded at all. In that case, + prevent any further processing of this assignment. */ + do_not_record = 0; + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + + sets[i].src = src; + sets[i].src_hash = HASH (src, mode); + sets[i].src_volatile = do_not_record; + sets[i].src_in_memory = hash_arg_in_memory; + sets[i].src_in_struct = hash_arg_in_struct; + +#if 0 + /* It is no longer clear why we used to do this, but it doesn't + appear to still be needed. So let's try without it since this + code hurts cse'ing widened ops. */ + /* If source is a perverse subreg (such as QI treated as an SI), + treat it as volatile. It may do the work of an SI in one context + where the extra bits are not being used, but cannot replace an SI + in general. */ + if (GET_CODE (src) == SUBREG + && (GET_MODE_SIZE (GET_MODE (src)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (src))))) + sets[i].src_volatile = 1; +#endif + + /* Locate all possible equivalent forms for SRC. Try to replace + SRC in the insn with each cheaper equivalent. + + We have the following types of equivalents: SRC itself, a folded + version, a value given in a REG_EQUAL note, or a value related + to a constant. + + Each of these equivalents may be part of an additional class + of equivalents (if more than one is in the table, they must be in + the same class; we check for this). + + If the source is volatile, we don't do any table lookups. + + We note any constant equivalent for possible later use in a + REG_NOTE. */ + + if (!sets[i].src_volatile) + elt = lookup (src, sets[i].src_hash, mode); + + sets[i].src_elt = elt; + + if (elt && src_eqv_here && src_eqv_elt) + { + if (elt->first_same_value != src_eqv_elt->first_same_value) + { + /* The REG_EQUAL is indicating that two formerly distinct + classes are now equivalent. So merge them. */ + merge_equiv_classes (elt, src_eqv_elt); + src_eqv_hash = HASH (src_eqv, elt->mode); + src_eqv_elt = lookup (src_eqv, src_eqv_hash, elt->mode); + } + + src_eqv_here = 0; + } + + else if (src_eqv_elt) + elt = src_eqv_elt; + + /* Try to find a constant somewhere and record it in `src_const'. + Record its table element, if any, in `src_const_elt'. Look in + any known equivalences first. (If the constant is not in the + table, also set `sets[i].src_const_hash'). */ + if (elt) + for (p = elt->first_same_value; p; p = p->next_same_value) + if (p->is_const) + { + src_const = p->exp; + src_const_elt = elt; + break; + } + + if (src_const == 0 + && (CONSTANT_P (src_folded) + /* Consider (minus (label_ref L1) (label_ref L2)) as + "constant" here so we will record it. This allows us + to fold switch statements when an ADDR_DIFF_VEC is used. */ + || (GET_CODE (src_folded) == MINUS + && GET_CODE (XEXP (src_folded, 0)) == LABEL_REF + && GET_CODE (XEXP (src_folded, 1)) == LABEL_REF))) + src_const = src_folded, src_const_elt = elt; + else if (src_const == 0 && src_eqv_here && CONSTANT_P (src_eqv_here)) + src_const = src_eqv_here, src_const_elt = src_eqv_elt; + + /* If we don't know if the constant is in the table, get its + hash code and look it up. */ + if (src_const && src_const_elt == 0) + { + sets[i].src_const_hash = HASH (src_const, mode); + src_const_elt = lookup (src_const, sets[i].src_const_hash, mode); + } + + sets[i].src_const = src_const; + sets[i].src_const_elt = src_const_elt; + + /* If the constant and our source are both in the table, mark them as + equivalent. Otherwise, if a constant is in the table but the source + isn't, set ELT to it. */ + if (src_const_elt && elt + && src_const_elt->first_same_value != elt->first_same_value) + merge_equiv_classes (elt, src_const_elt); + else if (src_const_elt && elt == 0) + elt = src_const_elt; + + /* See if there is a register linearly related to a constant + equivalent of SRC. */ + if (src_const + && (GET_CODE (src_const) == CONST + || (src_const_elt && src_const_elt->related_value != 0))) + { + src_related = use_related_value (src_const, src_const_elt); + if (src_related) + { + struct table_elt *src_related_elt + = lookup (src_related, HASH (src_related, mode), mode); + if (src_related_elt && elt) + { + if (elt->first_same_value + != src_related_elt->first_same_value) + /* This can occur when we previously saw a CONST + involving a SYMBOL_REF and then see the SYMBOL_REF + twice. Merge the involved classes. */ + merge_equiv_classes (elt, src_related_elt); + + src_related = 0; + src_related_elt = 0; + } + else if (src_related_elt && elt == 0) + elt = src_related_elt; + } + } + + /* See if we have a CONST_INT that is already in a register in a + wider mode. */ + + if (src_const && src_related == 0 && GET_CODE (src_const) == CONST_INT + && GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_BITSIZE (mode) < BITS_PER_WORD) + { + enum machine_mode wider_mode; + + for (wider_mode = GET_MODE_WIDER_MODE (mode); + GET_MODE_BITSIZE (wider_mode) <= BITS_PER_WORD + && src_related == 0; + wider_mode = GET_MODE_WIDER_MODE (wider_mode)) + { + struct table_elt *const_elt + = lookup (src_const, HASH (src_const, wider_mode), wider_mode); + + if (const_elt == 0) + continue; + + for (const_elt = const_elt->first_same_value; + const_elt; const_elt = const_elt->next_same_value) + if (GET_CODE (const_elt->exp) == REG) + { + src_related = gen_lowpart_if_possible (mode, + const_elt->exp); + break; + } + } + } + + /* Another possibility is that we have an AND with a constant in + a mode narrower than a word. If so, it might have been generated + as part of an "if" which would narrow the AND. If we already + have done the AND in a wider mode, we can use a SUBREG of that + value. */ + + if (flag_expensive_optimizations && ! src_related + && GET_CODE (src) == AND && GET_CODE (XEXP (src, 1)) == CONST_INT + && GET_MODE_SIZE (mode) < UNITS_PER_WORD) + { + enum machine_mode tmode; + rtx new_and = gen_rtx (AND, VOIDmode, NULL_RTX, XEXP (src, 1)); + + for (tmode = GET_MODE_WIDER_MODE (mode); + GET_MODE_SIZE (tmode) <= UNITS_PER_WORD; + tmode = GET_MODE_WIDER_MODE (tmode)) + { + rtx inner = gen_lowpart_if_possible (tmode, XEXP (src, 0)); + struct table_elt *larger_elt; + + if (inner) + { + PUT_MODE (new_and, tmode); + XEXP (new_and, 0) = inner; + larger_elt = lookup (new_and, HASH (new_and, tmode), tmode); + if (larger_elt == 0) + continue; + + for (larger_elt = larger_elt->first_same_value; + larger_elt; larger_elt = larger_elt->next_same_value) + if (GET_CODE (larger_elt->exp) == REG) + { + src_related + = gen_lowpart_if_possible (mode, larger_elt->exp); + break; + } + + if (src_related) + break; + } + } + } + +#ifdef LOAD_EXTEND_OP + /* See if a MEM has already been loaded with a widening operation; + if it has, we can use a subreg of that. Many CISC machines + also have such operations, but this is only likely to be + beneficial these machines. */ + + if (flag_expensive_optimizations && src_related == 0 + && (GET_MODE_SIZE (mode) < UNITS_PER_WORD) + && GET_MODE_CLASS (mode) == MODE_INT + && GET_CODE (src) == MEM && ! do_not_record + && LOAD_EXTEND_OP (mode) != NIL) + { + enum machine_mode tmode; + + /* Set what we are trying to extend and the operation it might + have been extended with. */ + PUT_CODE (memory_extend_rtx, LOAD_EXTEND_OP (mode)); + XEXP (memory_extend_rtx, 0) = src; + + for (tmode = GET_MODE_WIDER_MODE (mode); + GET_MODE_SIZE (tmode) <= UNITS_PER_WORD; + tmode = GET_MODE_WIDER_MODE (tmode)) + { + struct table_elt *larger_elt; + + PUT_MODE (memory_extend_rtx, tmode); + larger_elt = lookup (memory_extend_rtx, + HASH (memory_extend_rtx, tmode), tmode); + if (larger_elt == 0) + continue; + + for (larger_elt = larger_elt->first_same_value; + larger_elt; larger_elt = larger_elt->next_same_value) + if (GET_CODE (larger_elt->exp) == REG) + { + src_related = gen_lowpart_if_possible (mode, + larger_elt->exp); + break; + } + + if (src_related) + break; + } + } +#endif /* LOAD_EXTEND_OP */ + + if (src == src_folded) + src_folded = 0; + + /* At this point, ELT, if non-zero, points to a class of expressions + equivalent to the source of this SET and SRC, SRC_EQV, SRC_FOLDED, + and SRC_RELATED, if non-zero, each contain additional equivalent + expressions. Prune these latter expressions by deleting expressions + already in the equivalence class. + + Check for an equivalent identical to the destination. If found, + this is the preferred equivalent since it will likely lead to + elimination of the insn. Indicate this by placing it in + `src_related'. */ + + if (elt) elt = elt->first_same_value; + for (p = elt; p; p = p->next_same_value) + { + enum rtx_code code = GET_CODE (p->exp); + + /* If the expression is not valid, ignore it. Then we do not + have to check for validity below. In most cases, we can use + `rtx_equal_p', since canonicalization has already been done. */ + if (code != REG && ! exp_equiv_p (p->exp, p->exp, 1, 0)) + continue; + + if (src && GET_CODE (src) == code && rtx_equal_p (src, p->exp)) + src = 0; + else if (src_folded && GET_CODE (src_folded) == code + && rtx_equal_p (src_folded, p->exp)) + src_folded = 0; + else if (src_eqv_here && GET_CODE (src_eqv_here) == code + && rtx_equal_p (src_eqv_here, p->exp)) + src_eqv_here = 0; + else if (src_related && GET_CODE (src_related) == code + && rtx_equal_p (src_related, p->exp)) + src_related = 0; + + /* This is the same as the destination of the insns, we want + to prefer it. Copy it to src_related. The code below will + then give it a negative cost. */ + if (GET_CODE (dest) == code && rtx_equal_p (p->exp, dest)) + src_related = dest; + + } + + /* Find the cheapest valid equivalent, trying all the available + possibilities. Prefer items not in the hash table to ones + that are when they are equal cost. Note that we can never + worsen an insn as the current contents will also succeed. + If we find an equivalent identical to the destination, use it as best, + since this insn will probably be eliminated in that case. */ + if (src) + { + if (rtx_equal_p (src, dest)) + src_cost = -1; + else + src_cost = COST (src); + } + + if (src_eqv_here) + { + if (rtx_equal_p (src_eqv_here, dest)) + src_eqv_cost = -1; + else + src_eqv_cost = COST (src_eqv_here); + } + + if (src_folded) + { + if (rtx_equal_p (src_folded, dest)) + src_folded_cost = -1; + else + src_folded_cost = COST (src_folded); + } + + if (src_related) + { + if (rtx_equal_p (src_related, dest)) + src_related_cost = -1; + else + src_related_cost = COST (src_related); + } + + /* If this was an indirect jump insn, a known label will really be + cheaper even though it looks more expensive. */ + if (dest == pc_rtx && src_const && GET_CODE (src_const) == LABEL_REF) + src_folded = src_const, src_folded_cost = -1; + + /* Terminate loop when replacement made. This must terminate since + the current contents will be tested and will always be valid. */ + while (1) + { + rtx trial; + + /* Skip invalid entries. */ + while (elt && GET_CODE (elt->exp) != REG + && ! exp_equiv_p (elt->exp, elt->exp, 1, 0)) + elt = elt->next_same_value; + + if (elt) src_elt_cost = elt->cost; + + /* Find cheapest and skip it for the next time. For items + of equal cost, use this order: + src_folded, src, src_eqv, src_related and hash table entry. */ + if (src_folded_cost <= src_cost + && src_folded_cost <= src_eqv_cost + && src_folded_cost <= src_related_cost + && src_folded_cost <= src_elt_cost) + { + trial = src_folded, src_folded_cost = 10000; + if (src_folded_force_flag) + trial = force_const_mem (mode, trial); + } + else if (src_cost <= src_eqv_cost + && src_cost <= src_related_cost + && src_cost <= src_elt_cost) + trial = src, src_cost = 10000; + else if (src_eqv_cost <= src_related_cost + && src_eqv_cost <= src_elt_cost) + trial = copy_rtx (src_eqv_here), src_eqv_cost = 10000; + else if (src_related_cost <= src_elt_cost) + trial = copy_rtx (src_related), src_related_cost = 10000; + else + { + trial = copy_rtx (elt->exp); + elt = elt->next_same_value; + src_elt_cost = 10000; + } + + /* We don't normally have an insn matching (set (pc) (pc)), so + check for this separately here. We will delete such an + insn below. + + Tablejump insns contain a USE of the table, so simply replacing + the operand with the constant won't match. This is simply an + unconditional branch, however, and is therefore valid. Just + insert the substitution here and we will delete and re-emit + the insn later. */ + + if (n_sets == 1 && dest == pc_rtx + && (trial == pc_rtx + || (GET_CODE (trial) == LABEL_REF + && ! condjump_p (insn)))) + { + /* If TRIAL is a label in front of a jump table, we are + really falling through the switch (this is how casesi + insns work), so we must branch around the table. */ + if (GET_CODE (trial) == CODE_LABEL + && NEXT_INSN (trial) != 0 + && GET_CODE (NEXT_INSN (trial)) == JUMP_INSN + && (GET_CODE (PATTERN (NEXT_INSN (trial))) == ADDR_DIFF_VEC + || GET_CODE (PATTERN (NEXT_INSN (trial))) == ADDR_VEC)) + + trial = gen_rtx (LABEL_REF, Pmode, get_label_after (trial)); + + SET_SRC (sets[i].rtl) = trial; + cse_jumps_altered = 1; + break; + } + + /* Look for a substitution that makes a valid insn. */ + else if (validate_change (insn, &SET_SRC (sets[i].rtl), trial, 0)) + { + /* The result of apply_change_group can be ignored; see + canon_reg. */ + + validate_change (insn, &SET_SRC (sets[i].rtl), + canon_reg (SET_SRC (sets[i].rtl), insn), + 1); + apply_change_group (); + break; + } + + /* If we previously found constant pool entries for + constants and this is a constant, try making a + pool entry. Put it in src_folded unless we already have done + this since that is where it likely came from. */ + + else if (constant_pool_entries_cost + && CONSTANT_P (trial) + && ! (GET_CODE (trial) == CONST + && GET_CODE (XEXP (trial, 0)) == TRUNCATE) + && (src_folded == 0 + || (GET_CODE (src_folded) != MEM + && ! src_folded_force_flag)) + && GET_MODE_CLASS (mode) != MODE_CC) + { + src_folded_force_flag = 1; + src_folded = trial; + src_folded_cost = constant_pool_entries_cost; + } + } + + src = SET_SRC (sets[i].rtl); + + /* In general, it is good to have a SET with SET_SRC == SET_DEST. + However, there is an important exception: If both are registers + that are not the head of their equivalence class, replace SET_SRC + with the head of the class. If we do not do this, we will have + both registers live over a portion of the basic block. This way, + their lifetimes will likely abut instead of overlapping. */ + if (GET_CODE (dest) == REG + && REGNO_QTY_VALID_P (REGNO (dest)) + && qty_mode[reg_qty[REGNO (dest)]] == GET_MODE (dest) + && qty_first_reg[reg_qty[REGNO (dest)]] != REGNO (dest) + && GET_CODE (src) == REG && REGNO (src) == REGNO (dest) + /* Don't do this if the original insn had a hard reg as + SET_SRC. */ + && (GET_CODE (sets[i].src) != REG + || REGNO (sets[i].src) >= FIRST_PSEUDO_REGISTER)) + /* We can't call canon_reg here because it won't do anything if + SRC is a hard register. */ + { + int first = qty_first_reg[reg_qty[REGNO (src)]]; + + src = SET_SRC (sets[i].rtl) + = first >= FIRST_PSEUDO_REGISTER ? regno_reg_rtx[first] + : gen_rtx (REG, GET_MODE (src), first); + + /* If we had a constant that is cheaper than what we are now + setting SRC to, use that constant. We ignored it when we + thought we could make this into a no-op. */ + if (src_const && COST (src_const) < COST (src) + && validate_change (insn, &SET_SRC (sets[i].rtl), src_const, 0)) + src = src_const; + } + + /* If we made a change, recompute SRC values. */ + if (src != sets[i].src) + { + do_not_record = 0; + hash_arg_in_memory = 0; + hash_arg_in_struct = 0; + sets[i].src = src; + sets[i].src_hash = HASH (src, mode); + sets[i].src_volatile = do_not_record; + sets[i].src_in_memory = hash_arg_in_memory; + sets[i].src_in_struct = hash_arg_in_struct; + sets[i].src_elt = lookup (src, sets[i].src_hash, mode); + } + + /* If this is a single SET, we are setting a register, and we have an + equivalent constant, we want to add a REG_NOTE. We don't want + to write a REG_EQUAL note for a constant pseudo since verifying that + that pseudo hasn't been eliminated is a pain. Such a note also + won't help anything. */ + if (n_sets == 1 && src_const && GET_CODE (dest) == REG + && GET_CODE (src_const) != REG) + { + tem = find_reg_note (insn, REG_EQUAL, NULL_RTX); + + /* Record the actual constant value in a REG_EQUAL note, making + a new one if one does not already exist. */ + if (tem) + XEXP (tem, 0) = src_const; + else + REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, + src_const, REG_NOTES (insn)); + + /* If storing a constant value in a register that + previously held the constant value 0, + record this fact with a REG_WAS_0 note on this insn. + + Note that the *register* is required to have previously held 0, + not just any register in the quantity and we must point to the + insn that set that register to zero. + + Rather than track each register individually, we just see if + the last set for this quantity was for this register. */ + + if (REGNO_QTY_VALID_P (REGNO (dest)) + && qty_const[reg_qty[REGNO (dest)]] == const0_rtx) + { + /* See if we previously had a REG_WAS_0 note. */ + rtx note = find_reg_note (insn, REG_WAS_0, NULL_RTX); + rtx const_insn = qty_const_insn[reg_qty[REGNO (dest)]]; + + if ((tem = single_set (const_insn)) != 0 + && rtx_equal_p (SET_DEST (tem), dest)) + { + if (note) + XEXP (note, 0) = const_insn; + else + REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_WAS_0, + const_insn, REG_NOTES (insn)); + } + } + } + + /* Now deal with the destination. */ + do_not_record = 0; + sets[i].inner_dest_loc = &SET_DEST (sets[0].rtl); + + /* Look within any SIGN_EXTRACT or ZERO_EXTRACT + to the MEM or REG within it. */ + while (GET_CODE (dest) == SIGN_EXTRACT + || GET_CODE (dest) == ZERO_EXTRACT + || GET_CODE (dest) == SUBREG + || GET_CODE (dest) == STRICT_LOW_PART) + { + sets[i].inner_dest_loc = &XEXP (dest, 0); + dest = XEXP (dest, 0); + } + + sets[i].inner_dest = dest; + + if (GET_CODE (dest) == MEM) + { + dest = fold_rtx (dest, insn); + + /* Decide whether we invalidate everything in memory, + or just things at non-fixed places. + Writing a large aggregate must invalidate everything + because we don't know how long it is. */ + note_mem_written (dest, &writes_memory); + } + + /* Compute the hash code of the destination now, + before the effects of this instruction are recorded, + since the register values used in the address computation + are those before this instruction. */ + sets[i].dest_hash = HASH (dest, mode); + + /* Don't enter a bit-field in the hash table + because the value in it after the store + may not equal what was stored, due to truncation. */ + + if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT + || GET_CODE (SET_DEST (sets[i].rtl)) == SIGN_EXTRACT) + { + rtx width = XEXP (SET_DEST (sets[i].rtl), 1); + + if (src_const != 0 && GET_CODE (src_const) == CONST_INT + && GET_CODE (width) == CONST_INT + && INTVAL (width) < HOST_BITS_PER_WIDE_INT + && ! (INTVAL (src_const) + & ((HOST_WIDE_INT) (-1) << INTVAL (width)))) + /* Exception: if the value is constant, + and it won't be truncated, record it. */ + ; + else + { + /* This is chosen so that the destination will be invalidated + but no new value will be recorded. + We must invalidate because sometimes constant + values can be recorded for bitfields. */ + sets[i].src_elt = 0; + sets[i].src_volatile = 1; + src_eqv = 0; + src_eqv_elt = 0; + } + } + + /* If only one set in a JUMP_INSN and it is now a no-op, we can delete + the insn. */ + else if (n_sets == 1 && dest == pc_rtx && src == pc_rtx) + { + PUT_CODE (insn, NOTE); + NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; + NOTE_SOURCE_FILE (insn) = 0; + cse_jumps_altered = 1; + /* One less use of the label this insn used to jump to. */ + --LABEL_NUSES (JUMP_LABEL (insn)); + /* No more processing for this set. */ + sets[i].rtl = 0; + } + + /* If this SET is now setting PC to a label, we know it used to + be a conditional or computed branch. So we see if we can follow + it. If it was a computed branch, delete it and re-emit. */ + else if (dest == pc_rtx && GET_CODE (src) == LABEL_REF) + { + rtx p; + + /* If this is not in the format for a simple branch and + we are the only SET in it, re-emit it. */ + if (! simplejump_p (insn) && n_sets == 1) + { + rtx new = emit_jump_insn_before (gen_jump (XEXP (src, 0)), insn); + JUMP_LABEL (new) = XEXP (src, 0); + LABEL_NUSES (XEXP (src, 0))++; + delete_insn (insn); + insn = new; + } + else + /* Otherwise, force rerecognition, since it probably had + a different pattern before. + This shouldn't really be necessary, since whatever + changed the source value above should have done this. + Until the right place is found, might as well do this here. */ + INSN_CODE (insn) = -1; + + /* Now that we've converted this jump to an unconditional jump, + there is dead code after it. Delete the dead code until we + reach a BARRIER, the end of the function, or a label. Do + not delete NOTEs except for NOTE_INSN_DELETED since later + phases assume these notes are retained. */ + + p = insn; + + while (NEXT_INSN (p) != 0 + && GET_CODE (NEXT_INSN (p)) != BARRIER + && GET_CODE (NEXT_INSN (p)) != CODE_LABEL) + { + if (GET_CODE (NEXT_INSN (p)) != NOTE + || NOTE_LINE_NUMBER (NEXT_INSN (p)) == NOTE_INSN_DELETED) + delete_insn (NEXT_INSN (p)); + else + p = NEXT_INSN (p); + } + + /* If we don't have a BARRIER immediately after INSN, put one there. + Much code assumes that there are no NOTEs between a JUMP_INSN and + BARRIER. */ + + if (NEXT_INSN (insn) == 0 + || GET_CODE (NEXT_INSN (insn)) != BARRIER) + emit_barrier_before (NEXT_INSN (insn)); + + /* We might have two BARRIERs separated by notes. Delete the second + one if so. */ + + if (p != insn && NEXT_INSN (p) != 0 + && GET_CODE (NEXT_INSN (p)) == BARRIER) + delete_insn (NEXT_INSN (p)); + + cse_jumps_altered = 1; + sets[i].rtl = 0; + } + + /* If destination is volatile, invalidate it and then do no further + processing for this assignment. */ + + else if (do_not_record) + { + if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG + || GET_CODE (dest) == MEM) + invalidate (dest, VOIDmode); + else if (GET_CODE (dest) == STRICT_LOW_PART + || GET_CODE (dest) == ZERO_EXTRACT) + invalidate (XEXP (dest, 0), GET_MODE (dest)); + sets[i].rtl = 0; + } + + if (sets[i].rtl != 0 && dest != SET_DEST (sets[i].rtl)) + sets[i].dest_hash = HASH (SET_DEST (sets[i].rtl), mode); + +#ifdef HAVE_cc0 + /* If setting CC0, record what it was set to, or a constant, if it + is equivalent to a constant. If it is being set to a floating-point + value, make a COMPARE with the appropriate constant of 0. If we + don't do this, later code can interpret this as a test against + const0_rtx, which can cause problems if we try to put it into an + insn as a floating-point operand. */ + if (dest == cc0_rtx) + { + this_insn_cc0 = src_const && mode != VOIDmode ? src_const : src; + this_insn_cc0_mode = mode; + if (FLOAT_MODE_P (mode)) + this_insn_cc0 = gen_rtx (COMPARE, VOIDmode, this_insn_cc0, + CONST0_RTX (mode)); + } +#endif + } + + /* Now enter all non-volatile source expressions in the hash table + if they are not already present. + Record their equivalence classes in src_elt. + This way we can insert the corresponding destinations into + the same classes even if the actual sources are no longer in them + (having been invalidated). */ + + if (src_eqv && src_eqv_elt == 0 && sets[0].rtl != 0 && ! src_eqv_volatile + && ! rtx_equal_p (src_eqv, SET_DEST (sets[0].rtl))) + { + register struct table_elt *elt; + register struct table_elt *classp = sets[0].src_elt; + rtx dest = SET_DEST (sets[0].rtl); + enum machine_mode eqvmode = GET_MODE (dest); + + if (GET_CODE (dest) == STRICT_LOW_PART) + { + eqvmode = GET_MODE (SUBREG_REG (XEXP (dest, 0))); + classp = 0; + } + if (insert_regs (src_eqv, classp, 0)) + { + rehash_using_reg (src_eqv); + src_eqv_hash = HASH (src_eqv, eqvmode); + } + elt = insert (src_eqv, classp, src_eqv_hash, eqvmode); + elt->in_memory = src_eqv_in_memory; + elt->in_struct = src_eqv_in_struct; + src_eqv_elt = elt; + + /* Check to see if src_eqv_elt is the same as a set source which + does not yet have an elt, and if so set the elt of the set source + to src_eqv_elt. */ + for (i = 0; i < n_sets; i++) + if (sets[i].rtl && sets[i].src_elt == 0 + && rtx_equal_p (SET_SRC (sets[i].rtl), src_eqv)) + sets[i].src_elt = src_eqv_elt; + } + + for (i = 0; i < n_sets; i++) + if (sets[i].rtl && ! sets[i].src_volatile + && ! rtx_equal_p (SET_SRC (sets[i].rtl), SET_DEST (sets[i].rtl))) + { + if (GET_CODE (SET_DEST (sets[i].rtl)) == STRICT_LOW_PART) + { + /* REG_EQUAL in setting a STRICT_LOW_PART + gives an equivalent for the entire destination register, + not just for the subreg being stored in now. + This is a more interesting equivalence, so we arrange later + to treat the entire reg as the destination. */ + sets[i].src_elt = src_eqv_elt; + sets[i].src_hash = src_eqv_hash; + } + else + { + /* Insert source and constant equivalent into hash table, if not + already present. */ + register struct table_elt *classp = src_eqv_elt; + register rtx src = sets[i].src; + register rtx dest = SET_DEST (sets[i].rtl); + enum machine_mode mode + = GET_MODE (src) == VOIDmode ? GET_MODE (dest) : GET_MODE (src); + + if (sets[i].src_elt == 0) + { + register struct table_elt *elt; + + /* Note that these insert_regs calls cannot remove + any of the src_elt's, because they would have failed to + match if not still valid. */ + if (insert_regs (src, classp, 0)) + { + rehash_using_reg (src); + sets[i].src_hash = HASH (src, mode); + } + elt = insert (src, classp, sets[i].src_hash, mode); + elt->in_memory = sets[i].src_in_memory; + elt->in_struct = sets[i].src_in_struct; + sets[i].src_elt = classp = elt; + } + + if (sets[i].src_const && sets[i].src_const_elt == 0 + && src != sets[i].src_const + && ! rtx_equal_p (sets[i].src_const, src)) + sets[i].src_elt = insert (sets[i].src_const, classp, + sets[i].src_const_hash, mode); + } + } + else if (sets[i].src_elt == 0) + /* If we did not insert the source into the hash table (e.g., it was + volatile), note the equivalence class for the REG_EQUAL value, if any, + so that the destination goes into that class. */ + sets[i].src_elt = src_eqv_elt; + + invalidate_from_clobbers (&writes_memory, x); + + /* Some registers are invalidated by subroutine calls. Memory is + invalidated by non-constant calls. */ + + if (GET_CODE (insn) == CALL_INSN) + { + static struct write_data everything = {0, 1, 1, 1}; + + if (! CONST_CALL_P (insn)) + invalidate_memory (&everything); + invalidate_for_call (); + } + + /* Now invalidate everything set by this instruction. + If a SUBREG or other funny destination is being set, + sets[i].rtl is still nonzero, so here we invalidate the reg + a part of which is being set. */ + + for (i = 0; i < n_sets; i++) + if (sets[i].rtl) + { + /* We can't use the inner dest, because the mode associated with + a ZERO_EXTRACT is significant. */ + register rtx dest = SET_DEST (sets[i].rtl); + + /* Needed for registers to remove the register from its + previous quantity's chain. + Needed for memory if this is a nonvarying address, unless + we have just done an invalidate_memory that covers even those. */ + if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG + || (GET_CODE (dest) == MEM && ! writes_memory.all + && ! cse_rtx_addr_varies_p (dest))) + invalidate (dest, VOIDmode); + else if (GET_CODE (dest) == STRICT_LOW_PART + || GET_CODE (dest) == ZERO_EXTRACT) + invalidate (XEXP (dest, 0), GET_MODE (dest)); + } + + /* Make sure registers mentioned in destinations + are safe for use in an expression to be inserted. + This removes from the hash table + any invalid entry that refers to one of these registers. + + We don't care about the return value from mention_regs because + we are going to hash the SET_DEST values unconditionally. */ + + for (i = 0; i < n_sets; i++) + if (sets[i].rtl && GET_CODE (SET_DEST (sets[i].rtl)) != REG) + mention_regs (SET_DEST (sets[i].rtl)); + + /* We may have just removed some of the src_elt's from the hash table. + So replace each one with the current head of the same class. */ + + for (i = 0; i < n_sets; i++) + if (sets[i].rtl) + { + if (sets[i].src_elt && sets[i].src_elt->first_same_value == 0) + /* If elt was removed, find current head of same class, + or 0 if nothing remains of that class. */ + { + register struct table_elt *elt = sets[i].src_elt; + + while (elt && elt->prev_same_value) + elt = elt->prev_same_value; + + while (elt && elt->first_same_value == 0) + elt = elt->next_same_value; + sets[i].src_elt = elt ? elt->first_same_value : 0; + } + } + + /* Now insert the destinations into their equivalence classes. */ + + for (i = 0; i < n_sets; i++) + if (sets[i].rtl) + { + register rtx dest = SET_DEST (sets[i].rtl); + register struct table_elt *elt; + + /* Don't record value if we are not supposed to risk allocating + floating-point values in registers that might be wider than + memory. */ + if ((flag_float_store + && GET_CODE (dest) == MEM + && FLOAT_MODE_P (GET_MODE (dest))) + /* Don't record values of destinations set inside a libcall block + since we might delete the libcall. Things should have been set + up so we won't want to reuse such a value, but we play it safe + here. */ + || in_libcall_block + /* If we didn't put a REG_EQUAL value or a source into the hash + table, there is no point is recording DEST. */ + || sets[i].src_elt == 0 + /* If DEST is a paradoxical SUBREG and SRC is a ZERO_EXTEND + or SIGN_EXTEND, don't record DEST since it can cause + some tracking to be wrong. + + ??? Think about this more later. */ + || (GET_CODE (dest) == SUBREG + && (GET_MODE_SIZE (GET_MODE (dest)) + > GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))) + && (GET_CODE (sets[i].src) == SIGN_EXTEND + || GET_CODE (sets[i].src) == ZERO_EXTEND))) + continue; + + /* STRICT_LOW_PART isn't part of the value BEING set, + and neither is the SUBREG inside it. + Note that in this case SETS[I].SRC_ELT is really SRC_EQV_ELT. */ + if (GET_CODE (dest) == STRICT_LOW_PART) + dest = SUBREG_REG (XEXP (dest, 0)); + + if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG) + /* Registers must also be inserted into chains for quantities. */ + if (insert_regs (dest, sets[i].src_elt, 1)) + { + /* If `insert_regs' changes something, the hash code must be + recalculated. */ + rehash_using_reg (dest); + sets[i].dest_hash = HASH (dest, GET_MODE (dest)); + } + + elt = insert (dest, sets[i].src_elt, + sets[i].dest_hash, GET_MODE (dest)); + elt->in_memory = (GET_CODE (sets[i].inner_dest) == MEM + && ! RTX_UNCHANGING_P (sets[i].inner_dest)); + + if (elt->in_memory) + { + /* This implicitly assumes a whole struct + need not have MEM_IN_STRUCT_P. + But a whole struct is *supposed* to have MEM_IN_STRUCT_P. */ + elt->in_struct = (MEM_IN_STRUCT_P (sets[i].inner_dest) + || sets[i].inner_dest != SET_DEST (sets[i].rtl)); + } + + /* If we have (set (subreg:m1 (reg:m2 foo) 0) (bar:m1)), M1 is no + narrower than M2, and both M1 and M2 are the same number of words, + we are also doing (set (reg:m2 foo) (subreg:m2 (bar:m1) 0)) so + make that equivalence as well. + + However, BAR may have equivalences for which gen_lowpart_if_possible + will produce a simpler value than gen_lowpart_if_possible applied to + BAR (e.g., if BAR was ZERO_EXTENDed from M2), so we will scan all + BAR's equivalences. If we don't get a simplified form, make + the SUBREG. It will not be used in an equivalence, but will + cause two similar assignments to be detected. + + Note the loop below will find SUBREG_REG (DEST) since we have + already entered SRC and DEST of the SET in the table. */ + + if (GET_CODE (dest) == SUBREG + && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) - 1) + / UNITS_PER_WORD) + == (GET_MODE_SIZE (GET_MODE (dest)) - 1)/ UNITS_PER_WORD) + && (GET_MODE_SIZE (GET_MODE (dest)) + >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))) + && sets[i].src_elt != 0) + { + enum machine_mode new_mode = GET_MODE (SUBREG_REG (dest)); + struct table_elt *elt, *classp = 0; + + for (elt = sets[i].src_elt->first_same_value; elt; + elt = elt->next_same_value) + { + rtx new_src = 0; + unsigned src_hash; + struct table_elt *src_elt; + + /* Ignore invalid entries. */ + if (GET_CODE (elt->exp) != REG + && ! exp_equiv_p (elt->exp, elt->exp, 1, 0)) + continue; + + new_src = gen_lowpart_if_possible (new_mode, elt->exp); + if (new_src == 0) + new_src = gen_rtx (SUBREG, new_mode, elt->exp, 0); + + src_hash = HASH (new_src, new_mode); + src_elt = lookup (new_src, src_hash, new_mode); + + /* Put the new source in the hash table is if isn't + already. */ + if (src_elt == 0) + { + if (insert_regs (new_src, classp, 0)) + { + rehash_using_reg (new_src); + src_hash = HASH (new_src, new_mode); + } + src_elt = insert (new_src, classp, src_hash, new_mode); + src_elt->in_memory = elt->in_memory; + src_elt->in_struct = elt->in_struct; + } + else if (classp && classp != src_elt->first_same_value) + /* Show that two things that we've seen before are + actually the same. */ + merge_equiv_classes (src_elt, classp); + + classp = src_elt->first_same_value; + } + } + } + + /* Special handling for (set REG0 REG1) + where REG0 is the "cheapest", cheaper than REG1. + After cse, REG1 will probably not be used in the sequel, + so (if easily done) change this insn to (set REG1 REG0) and + replace REG1 with REG0 in the previous insn that computed their value. + Then REG1 will become a dead store and won't cloud the situation + for later optimizations. + + Do not make this change if REG1 is a hard register, because it will + then be used in the sequel and we may be changing a two-operand insn + into a three-operand insn. + + Also do not do this if we are operating on a copy of INSN. */ + + if (n_sets == 1 && sets[0].rtl && GET_CODE (SET_DEST (sets[0].rtl)) == REG + && NEXT_INSN (PREV_INSN (insn)) == insn + && GET_CODE (SET_SRC (sets[0].rtl)) == REG + && REGNO (SET_SRC (sets[0].rtl)) >= FIRST_PSEUDO_REGISTER + && REGNO_QTY_VALID_P (REGNO (SET_SRC (sets[0].rtl))) + && (qty_first_reg[reg_qty[REGNO (SET_SRC (sets[0].rtl))]] + == REGNO (SET_DEST (sets[0].rtl)))) + { + rtx prev = PREV_INSN (insn); + while (prev && GET_CODE (prev) == NOTE) + prev = PREV_INSN (prev); + + if (prev && GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SET + && SET_DEST (PATTERN (prev)) == SET_SRC (sets[0].rtl)) + { + rtx dest = SET_DEST (sets[0].rtl); + rtx note = find_reg_note (prev, REG_EQUIV, NULL_RTX); + + validate_change (prev, & SET_DEST (PATTERN (prev)), dest, 1); + validate_change (insn, & SET_DEST (sets[0].rtl), + SET_SRC (sets[0].rtl), 1); + validate_change (insn, & SET_SRC (sets[0].rtl), dest, 1); + apply_change_group (); + + /* If REG1 was equivalent to a constant, REG0 is not. */ + if (note) + PUT_REG_NOTE_KIND (note, REG_EQUAL); + + /* If there was a REG_WAS_0 note on PREV, remove it. Move + any REG_WAS_0 note on INSN to PREV. */ + note = find_reg_note (prev, REG_WAS_0, NULL_RTX); + if (note) + remove_note (prev, note); + + note = find_reg_note (insn, REG_WAS_0, NULL_RTX); + if (note) + { + remove_note (insn, note); + XEXP (note, 1) = REG_NOTES (prev); + REG_NOTES (prev) = note; + } + + /* If INSN has a REG_EQUAL note, and this note mentions REG0, + then we must delete it, because the value in REG0 has changed. */ + note = find_reg_note (insn, REG_EQUAL, NULL_RTX); + if (note && reg_mentioned_p (dest, XEXP (note, 0))) + remove_note (insn, note); + } + } + + /* If this is a conditional jump insn, record any known equivalences due to + the condition being tested. */ + + last_jump_equiv_class = 0; + if (GET_CODE (insn) == JUMP_INSN + && n_sets == 1 && GET_CODE (x) == SET + && GET_CODE (SET_SRC (x)) == IF_THEN_ELSE) + record_jump_equiv (insn, 0); + +#ifdef HAVE_cc0 + /* If the previous insn set CC0 and this insn no longer references CC0, + delete the previous insn. Here we use the fact that nothing expects CC0 + to be valid over an insn, which is true until the final pass. */ + if (prev_insn && GET_CODE (prev_insn) == INSN + && (tem = single_set (prev_insn)) != 0 + && SET_DEST (tem) == cc0_rtx + && ! reg_mentioned_p (cc0_rtx, x)) + { + PUT_CODE (prev_insn, NOTE); + NOTE_LINE_NUMBER (prev_insn) = NOTE_INSN_DELETED; + NOTE_SOURCE_FILE (prev_insn) = 0; + } + + prev_insn_cc0 = this_insn_cc0; + prev_insn_cc0_mode = this_insn_cc0_mode; +#endif + + prev_insn = insn; +} + +/* Store 1 in *WRITES_PTR for those categories of memory ref + that must be invalidated when the expression WRITTEN is stored in. + If WRITTEN is null, say everything must be invalidated. */ + +static void +note_mem_written (written, writes_ptr) + rtx written; + struct write_data *writes_ptr; +{ + static struct write_data everything = {0, 1, 1, 1}; + + if (written == 0) + *writes_ptr = everything; + else if (GET_CODE (written) == MEM) + { + /* Pushing or popping the stack invalidates just the stack pointer. */ + rtx addr = XEXP (written, 0); + if ((GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC + || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC) + && GET_CODE (XEXP (addr, 0)) == REG + && REGNO (XEXP (addr, 0)) == STACK_POINTER_REGNUM) + { + writes_ptr->sp = 1; + return; + } + else if (GET_MODE (written) == BLKmode) + *writes_ptr = everything; + /* (mem (scratch)) means clobber everything. */ + else if (GET_CODE (addr) == SCRATCH) + *writes_ptr = everything; + else if (cse_rtx_addr_varies_p (written)) + { + /* A varying address that is a sum indicates an array element, + and that's just as good as a structure element + in implying that we need not invalidate scalar variables. + However, we must allow QImode aliasing of scalars, because the + ANSI C standard allows character pointers to alias anything. */ + if (! ((MEM_IN_STRUCT_P (written) + || GET_CODE (XEXP (written, 0)) == PLUS) + && GET_MODE (written) != QImode)) + writes_ptr->all = 1; + writes_ptr->nonscalar = 1; + } + writes_ptr->var = 1; + } +} + +/* Perform invalidation on the basis of everything about an insn + except for invalidating the actual places that are SET in it. + This includes the places CLOBBERed, and anything that might + alias with something that is SET or CLOBBERed. + + W points to the writes_memory for this insn, a struct write_data + saying which kinds of memory references must be invalidated. + X is the pattern of the insn. */ + +static void +invalidate_from_clobbers (w, x) + struct write_data *w; + rtx x; +{ + /* If W->var is not set, W specifies no action. + If W->all is set, this step gets all memory refs + so they can be ignored in the rest of this function. */ + if (w->var) + invalidate_memory (w); + + if (w->sp) + { + if (reg_tick[STACK_POINTER_REGNUM] >= 0) + reg_tick[STACK_POINTER_REGNUM]++; + + /* This should be *very* rare. */ + if (TEST_HARD_REG_BIT (hard_regs_in_table, STACK_POINTER_REGNUM)) + invalidate (stack_pointer_rtx, VOIDmode); + } + + if (GET_CODE (x) == CLOBBER) + { + rtx ref = XEXP (x, 0); + if (ref) + { + if (GET_CODE (ref) == REG || GET_CODE (ref) == SUBREG + || (GET_CODE (ref) == MEM && ! w->all)) + invalidate (ref, VOIDmode); + else if (GET_CODE (ref) == STRICT_LOW_PART + || GET_CODE (ref) == ZERO_EXTRACT) + invalidate (XEXP (ref, 0), GET_MODE (ref)); + } + } + else if (GET_CODE (x) == PARALLEL) + { + register int i; + for (i = XVECLEN (x, 0) - 1; i >= 0; i--) + { + register rtx y = XVECEXP (x, 0, i); + if (GET_CODE (y) == CLOBBER) + { + rtx ref = XEXP (y, 0); + if (ref) + { + if (GET_CODE (ref) == REG || GET_CODE (ref) == SUBREG + || (GET_CODE (ref) == MEM && !w->all)) + invalidate (ref, VOIDmode); + else if (GET_CODE (ref) == STRICT_LOW_PART + || GET_CODE (ref) == ZERO_EXTRACT) + invalidate (XEXP (ref, 0), GET_MODE (ref)); + } + } + } + } +} + +/* Process X, part of the REG_NOTES of an insn. Look at any REG_EQUAL notes + and replace any registers in them with either an equivalent constant + or the canonical form of the register. If we are inside an address, + only do this if the address remains valid. + + OBJECT is 0 except when within a MEM in which case it is the MEM. + + Return the replacement for X. */ + +static rtx +cse_process_notes (x, object) + rtx x; + rtx object; +{ + enum rtx_code code = GET_CODE (x); + char *fmt = GET_RTX_FORMAT (code); + int i; + + switch (code) + { + case CONST_INT: + case CONST: + case SYMBOL_REF: + case LABEL_REF: + case CONST_DOUBLE: + case PC: + case CC0: + case LO_SUM: + return x; + + case MEM: + XEXP (x, 0) = cse_process_notes (XEXP (x, 0), x); + return x; + + case EXPR_LIST: + case INSN_LIST: + if (REG_NOTE_KIND (x) == REG_EQUAL) + XEXP (x, 0) = cse_process_notes (XEXP (x, 0), NULL_RTX); + if (XEXP (x, 1)) + XEXP (x, 1) = cse_process_notes (XEXP (x, 1), NULL_RTX); + return x; + + case SIGN_EXTEND: + case ZERO_EXTEND: + { + rtx new = cse_process_notes (XEXP (x, 0), object); + /* We don't substitute VOIDmode constants into these rtx, + since they would impede folding. */ + if (GET_MODE (new) != VOIDmode) + validate_change (object, &XEXP (x, 0), new, 0); + return x; + } + + case REG: + i = reg_qty[REGNO (x)]; + + /* Return a constant or a constant register. */ + if (REGNO_QTY_VALID_P (REGNO (x)) + && qty_const[i] != 0 + && (CONSTANT_P (qty_const[i]) + || GET_CODE (qty_const[i]) == REG)) + { + rtx new = gen_lowpart_if_possible (GET_MODE (x), qty_const[i]); + if (new) + return new; + } + + /* Otherwise, canonicalize this register. */ + return canon_reg (x, NULL_RTX); + } + + for (i = 0; i < GET_RTX_LENGTH (code); i++) + if (fmt[i] == 'e') + validate_change (object, &XEXP (x, i), + cse_process_notes (XEXP (x, i), object), 0); + + return x; +} + +/* Find common subexpressions between the end test of a loop and the beginning + of the loop. LOOP_START is the CODE_LABEL at the start of a loop. + + Often we have a loop where an expression in the exit test is used + in the body of the loop. For example "while (*p) *q++ = *p++;". + Because of the way we duplicate the loop exit test in front of the loop, + however, we don't detect that common subexpression. This will be caught + when global cse is implemented, but this is a quite common case. + + This function handles the most common cases of these common expressions. + It is called after we have processed the basic block ending with the + NOTE_INSN_LOOP_END note that ends a loop and the previous JUMP_INSN + jumps to a label used only once. */ + +static void +cse_around_loop (loop_start) + rtx loop_start; +{ + rtx insn; + int i; + struct table_elt *p; + + /* If the jump at the end of the loop doesn't go to the start, we don't + do anything. */ + for (insn = PREV_INSN (loop_start); + insn && (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) >= 0); + insn = PREV_INSN (insn)) + ; + + if (insn == 0 + || GET_CODE (insn) != NOTE + || NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_BEG) + return; + + /* If the last insn of the loop (the end test) was an NE comparison, + we will interpret it as an EQ comparison, since we fell through + the loop. Any equivalences resulting from that comparison are + therefore not valid and must be invalidated. */ + if (last_jump_equiv_class) + for (p = last_jump_equiv_class->first_same_value; p; + p = p->next_same_value) + if (GET_CODE (p->exp) == MEM || GET_CODE (p->exp) == REG + || (GET_CODE (p->exp) == SUBREG + && GET_CODE (SUBREG_REG (p->exp)) == REG)) + invalidate (p->exp, VOIDmode); + else if (GET_CODE (p->exp) == STRICT_LOW_PART + || GET_CODE (p->exp) == ZERO_EXTRACT) + invalidate (XEXP (p->exp, 0), GET_MODE (p->exp)); + + /* Process insns starting after LOOP_START until we hit a CALL_INSN or + a CODE_LABEL (we could handle a CALL_INSN, but it isn't worth it). + + The only thing we do with SET_DEST is invalidate entries, so we + can safely process each SET in order. It is slightly less efficient + to do so, but we only want to handle the most common cases. */ + + for (insn = NEXT_INSN (loop_start); + GET_CODE (insn) != CALL_INSN && GET_CODE (insn) != CODE_LABEL + && ! (GET_CODE (insn) == NOTE + && NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END); + insn = NEXT_INSN (insn)) + { + if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' + && (GET_CODE (PATTERN (insn)) == SET + || GET_CODE (PATTERN (insn)) == CLOBBER)) + cse_set_around_loop (PATTERN (insn), insn, loop_start); + else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i' + && GET_CODE (PATTERN (insn)) == PARALLEL) + for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) + if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET + || GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == CLOBBER) + cse_set_around_loop (XVECEXP (PATTERN (insn), 0, i), insn, + loop_start); + } +} + +/* Variable used for communications between the next two routines. */ + +static struct write_data skipped_writes_memory; + +/* Process one SET of an insn that was skipped. We ignore CLOBBERs + since they are done elsewhere. This function is called via note_stores. */ + +static void +invalidate_skipped_set (dest, set) + rtx set; + rtx dest; +{ + if (GET_CODE (set) == CLOBBER +#ifdef HAVE_cc0 + || dest == cc0_rtx +#endif + || dest == pc_rtx) + return; + + if (GET_CODE (dest) == MEM) + note_mem_written (dest, &skipped_writes_memory); + + /* There are times when an address can appear varying and be a PLUS + during this scan when it would be a fixed address were we to know + the proper equivalences. So promote "nonscalar" to be "all". */ + if (skipped_writes_memory.nonscalar) + skipped_writes_memory.all = 1; + + if (GET_CODE (dest) == REG || GET_CODE (dest) == SUBREG + || (! skipped_writes_memory.all && ! cse_rtx_addr_varies_p (dest))) + invalidate (dest, VOIDmode); + else if (GET_CODE (dest) == STRICT_LOW_PART + || GET_CODE (dest) == ZERO_EXTRACT) + invalidate (XEXP (dest, 0), GET_MODE (dest)); +} + +/* Invalidate all insns from START up to the end of the function or the + next label. This called when we wish to CSE around a block that is + conditionally executed. */ + +static void +invalidate_skipped_block (start) + rtx start; +{ + rtx insn; + static struct write_data init = {0, 0, 0, 0}; + static struct write_data everything = {0, 1, 1, 1}; + + for (insn = start; insn && GET_CODE (insn) != CODE_LABEL; + insn = NEXT_INSN (insn)) + { + if (GET_RTX_CLASS (GET_CODE (insn)) != 'i') + continue; + + skipped_writes_memory = init; + + if (GET_CODE (insn) == CALL_INSN) + { + invalidate_for_call (); + skipped_writes_memory = everything; + } + + note_stores (PATTERN (insn), invalidate_skipped_set); + invalidate_from_clobbers (&skipped_writes_memory, PATTERN (insn)); + } +} + +/* Used for communication between the following two routines; contains a + value to be checked for modification. */ + +static rtx cse_check_loop_start_value; + +/* If modifying X will modify the value in CSE_CHECK_LOOP_START_VALUE, + indicate that fact by setting CSE_CHECK_LOOP_START_VALUE to 0. */ + +static void +cse_check_loop_start (x, set) + rtx x; + rtx set; +{ + if (cse_check_loop_start_value == 0 + || GET_CODE (x) == CC0 || GET_CODE (x) == PC) + return; + + if ((GET_CODE (x) == MEM && GET_CODE (cse_check_loop_start_value) == MEM) + || reg_overlap_mentioned_p (x, cse_check_loop_start_value)) + cse_check_loop_start_value = 0; +} + +/* X is a SET or CLOBBER contained in INSN that was found near the start of + a loop that starts with the label at LOOP_START. + + If X is a SET, we see if its SET_SRC is currently in our hash table. + If so, we see if it has a value equal to some register used only in the + loop exit code (as marked by jump.c). + + If those two conditions are true, we search backwards from the start of + the loop to see if that same value was loaded into a register that still + retains its value at the start of the loop. + + If so, we insert an insn after the load to copy the destination of that + load into the equivalent register and (try to) replace our SET_SRC with that + register. + + In any event, we invalidate whatever this SET or CLOBBER modifies. */ + +static void +cse_set_around_loop (x, insn, loop_start) + rtx x; + rtx insn; + rtx loop_start; +{ + struct table_elt *src_elt; + static struct write_data init = {0, 0, 0, 0}; + struct write_data writes_memory; + + writes_memory = init; + + /* If this is a SET, see if we can replace SET_SRC, but ignore SETs that + are setting PC or CC0 or whose SET_SRC is already a register. */ + if (GET_CODE (x) == SET + && GET_CODE (SET_DEST (x)) != PC && GET_CODE (SET_DEST (x)) != CC0 + && GET_CODE (SET_SRC (x)) != REG) + { + src_elt = lookup (SET_SRC (x), + HASH (SET_SRC (x), GET_MODE (SET_DEST (x))), + GET_MODE (SET_DEST (x))); + + if (src_elt) + for (src_elt = src_elt->first_same_value; src_elt; + src_elt = src_elt->next_same_value) + if (GET_CODE (src_elt->exp) == REG && REG_LOOP_TEST_P (src_elt->exp) + && COST (src_elt->exp) < COST (SET_SRC (x))) + { + rtx p, set; + + /* Look for an insn in front of LOOP_START that sets + something in the desired mode to SET_SRC (x) before we hit + a label or CALL_INSN. */ + + for (p = prev_nonnote_insn (loop_start); + p && GET_CODE (p) != CALL_INSN + && GET_CODE (p) != CODE_LABEL; + p = prev_nonnote_insn (p)) + if ((set = single_set (p)) != 0 + && GET_CODE (SET_DEST (set)) == REG + && GET_MODE (SET_DEST (set)) == src_elt->mode + && rtx_equal_p (SET_SRC (set), SET_SRC (x))) + { + /* We now have to ensure that nothing between P + and LOOP_START modified anything referenced in + SET_SRC (x). We know that nothing within the loop + can modify it, or we would have invalidated it in + the hash table. */ + rtx q; + + cse_check_loop_start_value = SET_SRC (x); + for (q = p; q != loop_start; q = NEXT_INSN (q)) + if (GET_RTX_CLASS (GET_CODE (q)) == 'i') + note_stores (PATTERN (q), cse_check_loop_start); + + /* If nothing was changed and we can replace our + SET_SRC, add an insn after P to copy its destination + to what we will be replacing SET_SRC with. */ + if (cse_check_loop_start_value + && validate_change (insn, &SET_SRC (x), + src_elt->exp, 0)) + emit_insn_after (gen_move_insn (src_elt->exp, + SET_DEST (set)), + p); + break; + } + } + } + + /* Now invalidate anything modified by X. */ + note_mem_written (SET_DEST (x), &writes_memory); + + if (writes_memory.var) + invalidate_memory (&writes_memory); + + /* See comment on similar code in cse_insn for explanation of these tests. */ + if (GET_CODE (SET_DEST (x)) == REG || GET_CODE (SET_DEST (x)) == SUBREG + || (GET_CODE (SET_DEST (x)) == MEM && ! writes_memory.all + && ! cse_rtx_addr_varies_p (SET_DEST (x)))) + invalidate (SET_DEST (x), VOIDmode); + else if (GET_CODE (SET_DEST (x)) == STRICT_LOW_PART + || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) + invalidate (XEXP (SET_DEST (x), 0), GET_MODE (SET_DEST (x))); +} + +/* Find the end of INSN's basic block and return its range, + the total number of SETs in all the insns of the block, the last insn of the + block, and the branch path. + + The branch path indicates which branches should be followed. If a non-zero + path size is specified, the block should be rescanned and a different set + of branches will be taken. The branch path is only used if + FLAG_CSE_FOLLOW_JUMPS or FLAG_CSE_SKIP_BLOCKS is non-zero. + + DATA is a pointer to a struct cse_basic_block_data, defined below, that is + used to describe the block. It is filled in with the information about + the current block. The incoming structure's branch path, if any, is used + to construct the output branch path. */ + +void +cse_end_of_basic_block (insn, data, follow_jumps, after_loop, skip_blocks) + rtx insn; + struct cse_basic_block_data *data; + int follow_jumps; + int after_loop; + int skip_blocks; +{ + rtx p = insn, q; + int nsets = 0; + int low_cuid = INSN_CUID (insn), high_cuid = INSN_CUID (insn); + rtx next = GET_RTX_CLASS (GET_CODE (insn)) == 'i' ? insn : next_real_insn (insn); + int path_size = data->path_size; + int path_entry = 0; + int i; + + /* Update the previous branch path, if any. If the last branch was + previously TAKEN, mark it NOT_TAKEN. If it was previously NOT_TAKEN, + shorten the path by one and look at the previous branch. We know that + at least one branch must have been taken if PATH_SIZE is non-zero. */ + while (path_size > 0) + { + if (data->path[path_size - 1].status != NOT_TAKEN) + { + data->path[path_size - 1].status = NOT_TAKEN; + break; + } + else + path_size--; + } + + /* Scan to end of this basic block. */ + while (p && GET_CODE (p) != CODE_LABEL) + { + /* Don't cse out the end of a loop. This makes a difference + only for the unusual loops that always execute at least once; + all other loops have labels there so we will stop in any case. + Cse'ing out the end of the loop is dangerous because it + might cause an invariant expression inside the loop + to be reused after the end of the loop. This would make it + hard to move the expression out of the loop in loop.c, + especially if it is one of several equivalent expressions + and loop.c would like to eliminate it. + + If we are running after loop.c has finished, we can ignore + the NOTE_INSN_LOOP_END. */ + + if (! after_loop && GET_CODE (p) == NOTE + && NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END) + break; + + /* Don't cse over a call to setjmp; on some machines (eg vax) + the regs restored by the longjmp come from + a later time than the setjmp. */ + if (GET_CODE (p) == NOTE + && NOTE_LINE_NUMBER (p) == NOTE_INSN_SETJMP) + break; + + /* A PARALLEL can have lots of SETs in it, + especially if it is really an ASM_OPERANDS. */ + if (GET_RTX_CLASS (GET_CODE (p)) == 'i' + && GET_CODE (PATTERN (p)) == PARALLEL) + nsets += XVECLEN (PATTERN (p), 0); + else if (GET_CODE (p) != NOTE) + nsets += 1; + + /* Ignore insns made by CSE; they cannot affect the boundaries of + the basic block. */ + + if (INSN_UID (p) <= max_uid && INSN_CUID (p) > high_cuid) + high_cuid = INSN_CUID (p); + if (INSN_UID (p) <= max_uid && INSN_CUID (p) < low_cuid) + low_cuid = INSN_CUID (p); + + /* See if this insn is in our branch path. If it is and we are to + take it, do so. */ + if (path_entry < path_size && data->path[path_entry].branch == p) + { + if (data->path[path_entry].status != NOT_TAKEN) + p = JUMP_LABEL (p); + + /* Point to next entry in path, if any. */ + path_entry++; + } + + /* If this is a conditional jump, we can follow it if -fcse-follow-jumps + was specified, we haven't reached our maximum path length, there are + insns following the target of the jump, this is the only use of the + jump label, and the target label is preceded by a BARRIER. + + Alternatively, we can follow the jump if it branches around a + block of code and there are no other branches into the block. + In this case invalidate_skipped_block will be called to invalidate any + registers set in the block when following the jump. */ + + else if ((follow_jumps || skip_blocks) && path_size < PATHLENGTH - 1 + && GET_CODE (p) == JUMP_INSN + && GET_CODE (PATTERN (p)) == SET + && GET_CODE (SET_SRC (PATTERN (p))) == IF_THEN_ELSE + && LABEL_NUSES (JUMP_LABEL (p)) == 1 + && NEXT_INSN (JUMP_LABEL (p)) != 0) + { + for (q = PREV_INSN (JUMP_LABEL (p)); q; q = PREV_INSN (q)) + if ((GET_CODE (q) != NOTE + || NOTE_LINE_NUMBER (q) == NOTE_INSN_LOOP_END + || NOTE_LINE_NUMBER (q) == NOTE_INSN_SETJMP) + && (GET_CODE (q) != CODE_LABEL || LABEL_NUSES (q) != 0)) + break; + + /* If we ran into a BARRIER, this code is an extension of the + basic block when the branch is taken. */ + if (follow_jumps && q != 0 && GET_CODE (q) == BARRIER) + { + /* Don't allow ourself to keep walking around an + always-executed loop. */ + if (next_real_insn (q) == next) + { + p = NEXT_INSN (p); + continue; + } + + /* Similarly, don't put a branch in our path more than once. */ + for (i = 0; i < path_entry; i++) + if (data->path[i].branch == p) + break; + + if (i != path_entry) + break; + + data->path[path_entry].branch = p; + data->path[path_entry++].status = TAKEN; + + /* This branch now ends our path. It was possible that we + didn't see this branch the last time around (when the + insn in front of the target was a JUMP_INSN that was + turned into a no-op). */ + path_size = path_entry; + + p = JUMP_LABEL (p); + /* Mark block so we won't scan it again later. */ + PUT_MODE (NEXT_INSN (p), QImode); + } + /* Detect a branch around a block of code. */ + else if (skip_blocks && q != 0 && GET_CODE (q) != CODE_LABEL) + { + register rtx tmp; + + if (next_real_insn (q) == next) + { + p = NEXT_INSN (p); + continue; + } + + for (i = 0; i < path_entry; i++) + if (data->path[i].branch == p) + break; + + if (i != path_entry) + break; + + /* This is no_labels_between_p (p, q) with an added check for + reaching the end of a function (in case Q precedes P). */ + for (tmp = NEXT_INSN (p); tmp && tmp != q; tmp = NEXT_INSN (tmp)) + if (GET_CODE (tmp) == CODE_LABEL) + break; + + if (tmp == q) + { + data->path[path_entry].branch = p; + data->path[path_entry++].status = AROUND; + + path_size = path_entry; + + p = JUMP_LABEL (p); + /* Mark block so we won't scan it again later. */ + PUT_MODE (NEXT_INSN (p), QImode); + } + } + } + p = NEXT_INSN (p); + } + + data->low_cuid = low_cuid; + data->high_cuid = high_cuid; + data->nsets = nsets; + data->last = p; + + /* If all jumps in the path are not taken, set our path length to zero + so a rescan won't be done. */ + for (i = path_size - 1; i >= 0; i--) + if (data->path[i].status != NOT_TAKEN) + break; + + if (i == -1) + data->path_size = 0; + else + data->path_size = path_size; + + /* End the current branch path. */ + data->path[path_size].branch = 0; +} + +/* Perform cse on the instructions of a function. + F is the first instruction. + NREGS is one plus the highest pseudo-reg number used in the instruction. + + AFTER_LOOP is 1 if this is the cse call done after loop optimization + (only if -frerun-cse-after-loop). + + Returns 1 if jump_optimize should be redone due to simplifications + in conditional jump instructions. */ + +int +cse_main (f, nregs, after_loop, file) + rtx f; + int nregs; + int after_loop; + FILE *file; +{ + struct cse_basic_block_data val; + register rtx insn = f; + register int i; + + cse_jumps_altered = 0; + recorded_label_ref = 0; + constant_pool_entries_cost = 0; + val.path_size = 0; + + init_recog (); + + max_reg = nregs; + + all_minus_one = (int *) alloca (nregs * sizeof (int)); + consec_ints = (int *) alloca (nregs * sizeof (int)); + + for (i = 0; i < nregs; i++) + { + all_minus_one[i] = -1; + consec_ints[i] = i; + } + + reg_next_eqv = (int *) alloca (nregs * sizeof (int)); + reg_prev_eqv = (int *) alloca (nregs * sizeof (int)); + reg_qty = (int *) alloca (nregs * sizeof (int)); + reg_in_table = (int *) alloca (nregs * sizeof (int)); + reg_tick = (int *) alloca (nregs * sizeof (int)); + +#ifdef LOAD_EXTEND_OP + + /* Allocate scratch rtl here. cse_insn will fill in the memory reference + and change the code and mode as appropriate. */ + memory_extend_rtx = gen_rtx (ZERO_EXTEND, VOIDmode, 0); +#endif + + /* Discard all the free elements of the previous function + since they are allocated in the temporarily obstack. */ + bzero ((char *) table, sizeof table); + free_element_chain = 0; + n_elements_made = 0; + + /* Find the largest uid. */ + + max_uid = get_max_uid (); + uid_cuid = (int *) alloca ((max_uid + 1) * sizeof (int)); + bzero ((char *) uid_cuid, (max_uid + 1) * sizeof (int)); + + /* Compute the mapping from uids to cuids. + CUIDs are numbers assigned to insns, like uids, + except that cuids increase monotonically through the code. + Don't assign cuids to line-number NOTEs, so that the distance in cuids + between two insns is not affected by -g. */ + + for (insn = f, i = 0; insn; insn = NEXT_INSN (insn)) + { + if (GET_CODE (insn) != NOTE + || NOTE_LINE_NUMBER (insn) < 0) + INSN_CUID (insn) = ++i; + else + /* Give a line number note the same cuid as preceding insn. */ + INSN_CUID (insn) = i; + } + + /* Initialize which registers are clobbered by calls. */ + + CLEAR_HARD_REG_SET (regs_invalidated_by_call); + + for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) + if ((call_used_regs[i] + /* Used to check !fixed_regs[i] here, but that isn't safe; + fixed regs are still call-clobbered, and sched can get + confused if they can "live across calls". + + The frame pointer is always preserved across calls. The arg + pointer is if it is fixed. The stack pointer usually is, unless + RETURN_POPS_ARGS, in which case an explicit CLOBBER + will be present. If we are generating PIC code, the PIC offset + table register is preserved across calls. */ + + && i != STACK_POINTER_REGNUM + && i != FRAME_POINTER_REGNUM +#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM + && i != HARD_FRAME_POINTER_REGNUM +#endif +#if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM + && ! (i == ARG_POINTER_REGNUM && fixed_regs[i]) +#endif +#if defined (PIC_OFFSET_TABLE_REGNUM) && !defined (PIC_OFFSET_TABLE_REG_CALL_CLOBBERED) + && ! (i == PIC_OFFSET_TABLE_REGNUM && flag_pic) +#endif + ) + || global_regs[i]) + SET_HARD_REG_BIT (regs_invalidated_by_call, i); + + /* Loop over basic blocks. + Compute the maximum number of qty's needed for each basic block + (which is 2 for each SET). */ + insn = f; + while (insn) + { + cse_end_of_basic_block (insn, &val, flag_cse_follow_jumps, after_loop, + flag_cse_skip_blocks); + + /* If this basic block was already processed or has no sets, skip it. */ + if (val.nsets == 0 || GET_MODE (insn) == QImode) + { + PUT_MODE (insn, VOIDmode); + insn = (val.last ? NEXT_INSN (val.last) : 0); + val.path_size = 0; + continue; + } + + cse_basic_block_start = val.low_cuid; + cse_basic_block_end = val.high_cuid; + max_qty = val.nsets * 2; + + if (file) + fprintf (file, ";; Processing block from %d to %d, %d sets.\n", + INSN_UID (insn), val.last ? INSN_UID (val.last) : 0, + val.nsets); + + /* Make MAX_QTY bigger to give us room to optimize + past the end of this basic block, if that should prove useful. */ + if (max_qty < 500) + max_qty = 500; + + max_qty += max_reg; + + /* If this basic block is being extended by following certain jumps, + (see `cse_end_of_basic_block'), we reprocess the code from the start. + Otherwise, we start after this basic block. */ + if (val.path_size > 0) + cse_basic_block (insn, val.last, val.path, 0); + else + { + int old_cse_jumps_altered = cse_jumps_altered; + rtx temp; + + /* When cse changes a conditional jump to an unconditional + jump, we want to reprocess the block, since it will give + us a new branch path to investigate. */ + cse_jumps_altered = 0; + temp = cse_basic_block (insn, val.last, val.path, ! after_loop); + if (cse_jumps_altered == 0 + || (flag_cse_follow_jumps == 0 && flag_cse_skip_blocks == 0)) + insn = temp; + + cse_jumps_altered |= old_cse_jumps_altered; + } + +#ifdef USE_C_ALLOCA + alloca (0); +#endif + } + + /* Tell refers_to_mem_p that qty_const info is not available. */ + qty_const = 0; + + if (max_elements_made < n_elements_made) + max_elements_made = n_elements_made; + + return cse_jumps_altered || recorded_label_ref; +} + +/* Process a single basic block. FROM and TO and the limits of the basic + block. NEXT_BRANCH points to the branch path when following jumps or + a null path when not following jumps. + + AROUND_LOOP is non-zero if we are to try to cse around to the start of a + loop. This is true when we are being called for the last time on a + block and this CSE pass is before loop.c. */ + +static rtx +cse_basic_block (from, to, next_branch, around_loop) + register rtx from, to; + struct branch_path *next_branch; + int around_loop; +{ + register rtx insn; + int to_usage = 0; + int in_libcall_block = 0; + + /* Each of these arrays is undefined before max_reg, so only allocate + the space actually needed and adjust the start below. */ + + qty_first_reg = (int *) alloca ((max_qty - max_reg) * sizeof (int)); + qty_last_reg = (int *) alloca ((max_qty - max_reg) * sizeof (int)); + qty_mode= (enum machine_mode *) alloca ((max_qty - max_reg) * sizeof (enum machine_mode)); + qty_const = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx)); + qty_const_insn = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx)); + qty_comparison_code + = (enum rtx_code *) alloca ((max_qty - max_reg) * sizeof (enum rtx_code)); + qty_comparison_qty = (int *) alloca ((max_qty - max_reg) * sizeof (int)); + qty_comparison_const = (rtx *) alloca ((max_qty - max_reg) * sizeof (rtx)); + + qty_first_reg -= max_reg; + qty_last_reg -= max_reg; + qty_mode -= max_reg; + qty_const -= max_reg; + qty_const_insn -= max_reg; + qty_comparison_code -= max_reg; + qty_comparison_qty -= max_reg; + qty_comparison_const -= max_reg; + + new_basic_block (); + + /* TO might be a label. If so, protect it from being deleted. */ + if (to != 0 && GET_CODE (to) == CODE_LABEL) + ++LABEL_NUSES (to); + + for (insn = from; insn != to; insn = NEXT_INSN (insn)) + { + register enum rtx_code code; + + /* See if this is a branch that is part of the path. If so, and it is + to be taken, do so. */ + if (next_branch->branch == insn) + { + enum taken status = next_branch++->status; + if (status != NOT_TAKEN) + { + if (status == TAKEN) + record_jump_equiv (insn, 1); + else + invalidate_skipped_block (NEXT_INSN (insn)); + + /* Set the last insn as the jump insn; it doesn't affect cc0. + Then follow this branch. */ +#ifdef HAVE_cc0 + prev_insn_cc0 = 0; +#endif + prev_insn = insn; + insn = JUMP_LABEL (insn); + continue; + } + } + + code = GET_CODE (insn); + if (GET_MODE (insn) == QImode) + PUT_MODE (insn, VOIDmode); + + if (GET_RTX_CLASS (code) == 'i') + { + /* Process notes first so we have all notes in canonical forms when + looking for duplicate operations. */ + + if (REG_NOTES (insn)) + REG_NOTES (insn) = cse_process_notes (REG_NOTES (insn), NULL_RTX); + + /* Track when we are inside in LIBCALL block. Inside such a block, + we do not want to record destinations. The last insn of a + LIBCALL block is not considered to be part of the block, since + its destination is the result of the block and hence should be + recorded. */ + + if (find_reg_note (insn, REG_LIBCALL, NULL_RTX)) + in_libcall_block = 1; + else if (find_reg_note (insn, REG_RETVAL, NULL_RTX)) + in_libcall_block = 0; + + cse_insn (insn, in_libcall_block); + } + + /* If INSN is now an unconditional jump, skip to the end of our + basic block by pretending that we just did the last insn in the + basic block. If we are jumping to the end of our block, show + that we can have one usage of TO. */ + + if (simplejump_p (insn)) + { + if (to == 0) + return 0; + + if (JUMP_LABEL (insn) == to) + to_usage = 1; + + /* Maybe TO was deleted because the jump is unconditional. + If so, there is nothing left in this basic block. */ + /* ??? Perhaps it would be smarter to set TO + to whatever follows this insn, + and pretend the basic block had always ended here. */ + if (INSN_DELETED_P (to)) + break; + + insn = PREV_INSN (to); + } + + /* See if it is ok to keep on going past the label + which used to end our basic block. Remember that we incremented + the count of that label, so we decrement it here. If we made + a jump unconditional, TO_USAGE will be one; in that case, we don't + want to count the use in that jump. */ + + if (to != 0 && NEXT_INSN (insn) == to + && GET_CODE (to) == CODE_LABEL && --LABEL_NUSES (to) == to_usage) + { + struct cse_basic_block_data val; + rtx prev; + + insn = NEXT_INSN (to); + + if (LABEL_NUSES (to) == 0) + insn = delete_insn (to); + + /* If TO was the last insn in the function, we are done. */ + if (insn == 0) + return 0; + + /* If TO was preceded by a BARRIER we are done with this block + because it has no continuation. */ + prev = prev_nonnote_insn (to); + if (prev && GET_CODE (prev) == BARRIER) + return insn; + + /* Find the end of the following block. Note that we won't be + following branches in this case. */ + to_usage = 0; + val.path_size = 0; + cse_end_of_basic_block (insn, &val, 0, 0, 0); + + /* If the tables we allocated have enough space left + to handle all the SETs in the next basic block, + continue through it. Otherwise, return, + and that block will be scanned individually. */ + if (val.nsets * 2 + next_qty > max_qty) + break; + + cse_basic_block_start = val.low_cuid; + cse_basic_block_end = val.high_cuid; + to = val.last; + + /* Prevent TO from being deleted if it is a label. */ + if (to != 0 && GET_CODE (to) == CODE_LABEL) + ++LABEL_NUSES (to); + + /* Back up so we process the first insn in the extension. */ + insn = PREV_INSN (insn); + } + } + + if (next_qty > max_qty) + abort (); + + /* If we are running before loop.c, we stopped on a NOTE_INSN_LOOP_END, and + the previous insn is the only insn that branches to the head of a loop, + we can cse into the loop. Don't do this if we changed the jump + structure of a loop unless we aren't going to be following jumps. */ + + if ((cse_jumps_altered == 0 + || (flag_cse_follow_jumps == 0 && flag_cse_skip_blocks == 0)) + && around_loop && to != 0 + && GET_CODE (to) == NOTE && NOTE_LINE_NUMBER (to) == NOTE_INSN_LOOP_END + && GET_CODE (PREV_INSN (to)) == JUMP_INSN + && JUMP_LABEL (PREV_INSN (to)) != 0 + && LABEL_NUSES (JUMP_LABEL (PREV_INSN (to))) == 1) + cse_around_loop (JUMP_LABEL (PREV_INSN (to))); + + return to ? NEXT_INSN (to) : 0; +} + +/* Count the number of times registers are used (not set) in X. + COUNTS is an array in which we accumulate the count, INCR is how much + we count each register usage. + + Don't count a usage of DEST, which is the SET_DEST of a SET which + contains X in its SET_SRC. This is because such a SET does not + modify the liveness of DEST. */ + +static void +count_reg_usage (x, counts, dest, incr) + rtx x; + int *counts; + rtx dest; + int incr; +{ + enum rtx_code code; + char *fmt; + int i, j; + + if (x == 0) + return; + + switch (code = GET_CODE (x)) + { + case REG: + if (x != dest) + counts[REGNO (x)] += incr; + return; + + case PC: + case CC0: + case CONST: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case LABEL_REF: + case CLOBBER: + return; + + case SET: + /* Unless we are setting a REG, count everything in SET_DEST. */ + if (GET_CODE (SET_DEST (x)) != REG) + count_reg_usage (SET_DEST (x), counts, NULL_RTX, incr); + + /* If SRC has side-effects, then we can't delete this insn, so the + usage of SET_DEST inside SRC counts. + + ??? Strictly-speaking, we might be preserving this insn + because some other SET has side-effects, but that's hard + to do and can't happen now. */ + count_reg_usage (SET_SRC (x), counts, + side_effects_p (SET_SRC (x)) ? NULL_RTX : SET_DEST (x), + incr); + return; + + case CALL_INSN: + count_reg_usage (CALL_INSN_FUNCTION_USAGE (x), counts, NULL_RTX, incr); + + /* ... falls through ... */ + case INSN: + case JUMP_INSN: + count_reg_usage (PATTERN (x), counts, NULL_RTX, incr); + + /* Things used in a REG_EQUAL note aren't dead since loop may try to + use them. */ + + count_reg_usage (REG_NOTES (x), counts, NULL_RTX, incr); + return; + + case EXPR_LIST: + case INSN_LIST: + if (REG_NOTE_KIND (x) == REG_EQUAL + || GET_CODE (XEXP (x,0)) == USE) + count_reg_usage (XEXP (x, 0), counts, NULL_RTX, incr); + count_reg_usage (XEXP (x, 1), counts, NULL_RTX, incr); + return; + } + + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'e') + count_reg_usage (XEXP (x, i), counts, dest, incr); + else if (fmt[i] == 'E') + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + count_reg_usage (XVECEXP (x, i, j), counts, dest, incr); + } +} + +/* Scan all the insns and delete any that are dead; i.e., they store a register + that is never used or they copy a register to itself. + + This is used to remove insns made obviously dead by cse. It improves the + heuristics in loop since it won't try to move dead invariants out of loops + or make givs for dead quantities. The remaining passes of the compilation + are also sped up. */ + +void +delete_dead_from_cse (insns, nreg) + rtx insns; + int nreg; +{ + int *counts = (int *) alloca (nreg * sizeof (int)); + rtx insn, prev; + rtx tem; + int i; + int in_libcall = 0; + + /* First count the number of times each register is used. */ + bzero ((char *) counts, sizeof (int) * nreg); + for (insn = next_real_insn (insns); insn; insn = next_real_insn (insn)) + count_reg_usage (insn, counts, NULL_RTX, 1); + + /* Go from the last insn to the first and delete insns that only set unused + registers or copy a register to itself. As we delete an insn, remove + usage counts for registers it uses. */ + for (insn = prev_real_insn (get_last_insn ()); insn; insn = prev) + { + int live_insn = 0; + + prev = prev_real_insn (insn); + + /* Don't delete any insns that are part of a libcall block. + Flow or loop might get confused if we did that. Remember + that we are scanning backwards. */ + if (find_reg_note (insn, REG_RETVAL, NULL_RTX)) + in_libcall = 1; + + if (in_libcall) + live_insn = 1; + else if (GET_CODE (PATTERN (insn)) == SET) + { + if (GET_CODE (SET_DEST (PATTERN (insn))) == REG + && SET_DEST (PATTERN (insn)) == SET_SRC (PATTERN (insn))) + ; + +#ifdef HAVE_cc0 + else if (GET_CODE (SET_DEST (PATTERN (insn))) == CC0 + && ! side_effects_p (SET_SRC (PATTERN (insn))) + && ((tem = next_nonnote_insn (insn)) == 0 + || GET_RTX_CLASS (GET_CODE (tem)) != 'i' + || ! reg_referenced_p (cc0_rtx, PATTERN (tem)))) + ; +#endif + else if (GET_CODE (SET_DEST (PATTERN (insn))) != REG + || REGNO (SET_DEST (PATTERN (insn))) < FIRST_PSEUDO_REGISTER + || counts[REGNO (SET_DEST (PATTERN (insn)))] != 0 + || side_effects_p (SET_SRC (PATTERN (insn)))) + live_insn = 1; + } + else if (GET_CODE (PATTERN (insn)) == PARALLEL) + for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) + { + rtx elt = XVECEXP (PATTERN (insn), 0, i); + + if (GET_CODE (elt) == SET) + { + if (GET_CODE (SET_DEST (elt)) == REG + && SET_DEST (elt) == SET_SRC (elt)) + ; + +#ifdef HAVE_cc0 + else if (GET_CODE (SET_DEST (elt)) == CC0 + && ! side_effects_p (SET_SRC (elt)) + && ((tem = next_nonnote_insn (insn)) == 0 + || GET_RTX_CLASS (GET_CODE (tem)) != 'i' + || ! reg_referenced_p (cc0_rtx, PATTERN (tem)))) + ; +#endif + else if (GET_CODE (SET_DEST (elt)) != REG + || REGNO (SET_DEST (elt)) < FIRST_PSEUDO_REGISTER + || counts[REGNO (SET_DEST (elt))] != 0 + || side_effects_p (SET_SRC (elt))) + live_insn = 1; + } + else if (GET_CODE (elt) != CLOBBER && GET_CODE (elt) != USE) + live_insn = 1; + } + else + live_insn = 1; + + /* If this is a dead insn, delete it and show registers in it aren't + being used. */ + + if (! live_insn) + { + count_reg_usage (insn, counts, NULL_RTX, -1); + delete_insn (insn); + } + + if (find_reg_note (insn, REG_LIBCALL, NULL_RTX)) + in_libcall = 0; + } +} diff --git a/contrib/gcc/dbxout.c b/contrib/gcc/dbxout.c new file mode 100644 index 00000000000..e3226147aee --- /dev/null +++ b/contrib/gcc/dbxout.c @@ -0,0 +1,2518 @@ +/* Output dbx-format symbol table information from GNU compiler. + Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Output dbx-format symbol table data. + This consists of many symbol table entries, each of them + a .stabs assembler pseudo-op with four operands: + a "name" which is really a description of one symbol and its type, + a "code", which is a symbol defined in stab.h whose name starts with N_, + an unused operand always 0, + and a "value" which is an address or an offset. + The name is enclosed in doublequote characters. + + Each function, variable, typedef, and structure tag + has a symbol table entry to define it. + The beginning and end of each level of name scoping within + a function are also marked by special symbol table entries. + + The "name" consists of the symbol name, a colon, a kind-of-symbol letter, + and a data type number. The data type number may be followed by + "=" and a type definition; normally this will happen the first time + the type number is mentioned. The type definition may refer to + other types by number, and those type numbers may be followed + by "=" and nested definitions. + + This can make the "name" quite long. + When a name is more than 80 characters, we split the .stabs pseudo-op + into two .stabs pseudo-ops, both sharing the same "code" and "value". + The first one is marked as continued with a double-backslash at the + end of its "name". + + The kind-of-symbol letter distinguished function names from global + variables from file-scope variables from parameters from auto + variables in memory from typedef names from register variables. + See `dbxout_symbol'. + + The "code" is mostly redundant with the kind-of-symbol letter + that goes in the "name", but not entirely: for symbols located + in static storage, the "code" says which segment the address is in, + which controls how it is relocated. + + The "value" for a symbol in static storage + is the core address of the symbol (actually, the assembler + label for the symbol). For a symbol located in a stack slot + it is the stack offset; for one in a register, the register number. + For a typedef symbol, it is zero. + + If DEBUG_SYMS_TEXT is defined, all debugging symbols must be + output while in the text section. + + For more on data type definitions, see `dbxout_type'. */ + +/* Include these first, because they may define MIN and MAX. */ +#include +#include + +#include "config.h" +#include "tree.h" +#include "rtl.h" +#include "flags.h" +#include "regs.h" +#include "insn-config.h" +#include "reload.h" +#include "defaults.h" +#include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */ + +#ifndef errno +extern int errno; +#endif + +#ifdef XCOFF_DEBUGGING_INFO +#include "xcoffout.h" +#endif + +#ifndef ASM_STABS_OP +#define ASM_STABS_OP ".stabs" +#endif + +#ifndef ASM_STABN_OP +#define ASM_STABN_OP ".stabn" +#endif + +#ifndef DBX_TYPE_DECL_STABS_CODE +#define DBX_TYPE_DECL_STABS_CODE N_LSYM +#endif + +#ifndef DBX_STATIC_CONST_VAR_CODE +#define DBX_STATIC_CONST_VAR_CODE N_FUN +#endif + +#ifndef DBX_REGPARM_STABS_CODE +#define DBX_REGPARM_STABS_CODE N_RSYM +#endif + +#ifndef DBX_REGPARM_STABS_LETTER +#define DBX_REGPARM_STABS_LETTER 'P' +#endif + +/* This is used for parameters passed by invisible reference in a register. */ +#ifndef GDB_INV_REF_REGPARM_STABS_LETTER +#define GDB_INV_REF_REGPARM_STABS_LETTER 'a' +#endif + +#ifndef DBX_MEMPARM_STABS_LETTER +#define DBX_MEMPARM_STABS_LETTER 'p' +#endif + +#ifndef FILE_NAME_JOINER +#define FILE_NAME_JOINER "/" +#endif + +/* Nonzero means if the type has methods, only output debugging + information if methods are actually written to the asm file. */ + +static int flag_minimal_debug = 1; + +/* Nonzero if we have actually used any of the GDB extensions + to the debugging format. The idea is that we use them for the + first time only if there's a strong reason, but once we have done that, + we use them whenever convenient. */ + +static int have_used_extensions = 0; + +/* Number for the next N_SOL filename stabs label. The number 0 is reserved + for the N_SO filename stabs label. */ + +static int source_label_number = 1; + +char *getpwd (); + +/* Typical USG systems don't have stab.h, and they also have + no use for DBX-format debugging info. */ + +#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) + +#ifdef DEBUG_SYMS_TEXT +#define FORCE_TEXT text_section (); +#else +#define FORCE_TEXT +#endif + +#if defined (USG) || defined (NO_STAB_H) +#include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */ +#else +#include /* On BSD, use the system's stab.h. */ + +/* This is a GNU extension we need to reference in this file. */ +#ifndef N_CATCH +#define N_CATCH 0x54 +#endif +#endif /* not USG */ + +#ifdef __GNU_STAB__ +#define STAB_CODE_TYPE enum __stab_debug_code +#else +#define STAB_CODE_TYPE int +#endif + +/* 1 if PARM is passed to this function in memory. */ + +#define PARM_PASSED_IN_MEMORY(PARM) \ + (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM) + +/* A C expression for the integer offset value of an automatic variable + (N_LSYM) having address X (an RTX). */ +#ifndef DEBUGGER_AUTO_OFFSET +#define DEBUGGER_AUTO_OFFSET(X) \ + (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0) +#endif + +/* A C expression for the integer offset value of an argument (N_PSYM) + having address X (an RTX). The nominal offset is OFFSET. */ +#ifndef DEBUGGER_ARG_OFFSET +#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET) +#endif + +/* Stream for writing to assembler file. */ + +static FILE *asmfile; + +/* Last source file name mentioned in a NOTE insn. */ + +static char *lastfile; + +/* Current working directory. */ + +static char *cwd; + +enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED}; + +/* Vector recording the status of describing C data types. + When we first notice a data type (a tree node), + we assign it a number using next_type_number. + That is its index in this vector. + The vector element says whether we have yet output + the definition of the type. TYPE_XREF says we have + output it as a cross-reference only. */ + +enum typestatus *typevec; + +/* Number of elements of space allocated in `typevec'. */ + +static int typevec_len; + +/* In dbx output, each type gets a unique number. + This is the number for the next type output. + The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */ + +static int next_type_number; + +/* In dbx output, we must assign symbol-blocks id numbers + in the order in which their beginnings are encountered. + We output debugging info that refers to the beginning and + end of the ranges of code in each block + with assembler labels LBBn and LBEn, where n is the block number. + The labels are generated in final, which assigns numbers to the + blocks in the same way. */ + +static int next_block_number; + +/* These variables are for dbxout_symbol to communicate to + dbxout_finish_symbol. + current_sym_code is the symbol-type-code, a symbol N_... define in stab.h. + current_sym_value and current_sym_addr are two ways to address the + value to store in the symtab entry. + current_sym_addr if nonzero represents the value as an rtx. + If that is zero, current_sym_value is used. This is used + when the value is an offset (such as for auto variables, + register variables and parms). */ + +static STAB_CODE_TYPE current_sym_code; +static int current_sym_value; +static rtx current_sym_addr; + +/* Number of chars of symbol-description generated so far for the + current symbol. Used by CHARS and CONTIN. */ + +static int current_sym_nchars; + +/* Report having output N chars of the current symbol-description. */ + +#define CHARS(N) (current_sym_nchars += (N)) + +/* Break the current symbol-description, generating a continuation, + if it has become long. */ + +#ifndef DBX_CONTIN_LENGTH +#define DBX_CONTIN_LENGTH 80 +#endif + +#if DBX_CONTIN_LENGTH > 0 +#define CONTIN \ + do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0) +#else +#define CONTIN +#endif + +void dbxout_types (); +void dbxout_args (); +void dbxout_symbol (); +static void dbxout_type_name (); +static void dbxout_type (); +static void dbxout_typedefs (); +static void dbxout_symbol_name (); +static void dbxout_symbol_location (); +static void dbxout_prepare_symbol (); +static void dbxout_finish_symbol (); +static void dbxout_continue (); +static void print_int_cst_octal (); +static void print_octal (); + +#if 0 /* Not clear we will actually need this. */ + +/* Return the absolutized filename for the given relative + filename. Note that if that filename is already absolute, it may + still be returned in a modified form because this routine also + eliminates redundant slashes and single dots and eliminates double + dots to get a shortest possible filename from the given input + filename. The absolutization of relative filenames is made by + assuming that the given filename is to be taken as relative to + the first argument (cwd) or to the current directory if cwd is + NULL. */ + +static char * +abspath (rel_filename) + char *rel_filename; +{ + /* Setup the current working directory as needed. */ + char *abs_buffer + = (char *) alloca (strlen (cwd) + strlen (rel_filename) + 1); + char *endp = abs_buffer; + char *outp, *inp; + char *value; + + /* Copy the filename (possibly preceded by the current working + directory name) into the absolutization buffer. */ + + { + char *src_p; + + if (rel_filename[0] != '/') + { + src_p = cwd; + while (*endp++ = *src_p++) + continue; + *(endp-1) = '/'; /* overwrite null */ + } + src_p = rel_filename; + while (*endp++ = *src_p++) + continue; + if (endp[-1] == '/') + *endp = '\0'; + + /* Now make a copy of abs_buffer into abs_buffer, shortening the + filename (by taking out slashes and dots) as we go. */ + + outp = inp = abs_buffer; + *outp++ = *inp++; /* copy first slash */ + for (;;) + { + if (!inp[0]) + break; + else if (inp[0] == '/' && outp[-1] == '/') + { + inp++; + continue; + } + else if (inp[0] == '.' && outp[-1] == '/') + { + if (!inp[1]) + break; + else if (inp[1] == '/') + { + inp += 2; + continue; + } + else if ((inp[1] == '.') && (inp[2] == 0 || inp[2] == '/')) + { + inp += (inp[2] == '/') ? 3 : 2; + outp -= 2; + while (outp >= abs_buffer && *outp != '/') + outp--; + if (outp < abs_buffer) + { + /* Catch cases like /.. where we try to backup to a + point above the absolute root of the logical file + system. */ + + fprintf (stderr, "%s: invalid file name: %s\n", + pname, rel_filename); + exit (1); + } + *++outp = '\0'; + continue; + } + } + *outp++ = *inp++; + } + + /* On exit, make sure that there is a trailing null, and make sure that + the last character of the returned string is *not* a slash. */ + + *outp = '\0'; + if (outp[-1] == '/') + *--outp = '\0'; + + /* Make a copy (in the heap) of the stuff left in the absolutization + buffer and return a pointer to the copy. */ + + value = (char *) oballoc (strlen (abs_buffer) + 1); + strcpy (value, abs_buffer); + return value; +} +#endif /* 0 */ + +/* At the beginning of compilation, start writing the symbol table. + Initialize `typevec' and output the standard data types of C. */ + +void +dbxout_init (asm_file, input_file_name, syms) + FILE *asm_file; + char *input_file_name; + tree syms; +{ + char ltext_label_name[100]; + + asmfile = asm_file; + + typevec_len = 100; + typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]); + bzero ((char *) typevec, typevec_len * sizeof typevec[0]); + + /* Convert Ltext into the appropriate format for local labels in case + the system doesn't insert underscores in front of user generated + labels. */ + ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0); + + /* Put the current working directory in an N_SO symbol. */ +#ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this, + but GDB always does. */ + if (use_gnu_debug_info_extensions) +#endif + { + if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/')) + { + char *wdslash = xmalloc (strlen (cwd) + sizeof (FILE_NAME_JOINER)); + sprintf (wdslash, "%s%s", cwd, FILE_NAME_JOINER); + cwd = wdslash; + } + if (cwd) + { +#ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY + DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd); +#else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ + fprintf (asmfile, "%s ", ASM_STABS_OP); + output_quoted_string (asmfile, cwd); + fprintf (asmfile, ",%d,0,0,%s\n", N_SO, <ext_label_name[1]); +#endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ + } + } + +#ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME + /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That + would give us an N_SOL, and we want an N_SO. */ + DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name); +#else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */ + /* We include outputting `Ltext:' here, + because that gives you a way to override it. */ + /* Used to put `Ltext:' before the reference, but that loses on sun 4. */ + fprintf (asmfile, "%s ", ASM_STABS_OP); + output_quoted_string (asmfile, input_file_name); + fprintf (asmfile, ",%d,0,0,%s\n", + N_SO, <ext_label_name[1]); + text_section (); + ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0); +#endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */ + + /* Possibly output something to inform GDB that this compilation was by + GCC. It's easier for GDB to parse it when after the N_SO's. This + is used in Solaris 2. */ +#ifdef ASM_IDENTIFY_GCC_AFTER_SOURCE + ASM_IDENTIFY_GCC_AFTER_SOURCE (asmfile); +#endif + + lastfile = input_file_name; + + next_type_number = 1; + next_block_number = 2; + + /* Make sure that types `int' and `char' have numbers 1 and 2. + Definitions of other integer types will refer to those numbers. + (Actually it should no longer matter what their numbers are. + Also, if any types with tags have been defined, dbxout_symbol + will output them first, so the numbers won't be 1 and 2. That + happens in C++. So it's a good thing it should no longer matter). */ + +#ifdef DBX_OUTPUT_STANDARD_TYPES + DBX_OUTPUT_STANDARD_TYPES (syms); +#else + dbxout_symbol (TYPE_NAME (integer_type_node), 0); + dbxout_symbol (TYPE_NAME (char_type_node), 0); +#endif + + /* Get all permanent types that have typedef names, + and output them all, except for those already output. */ + + dbxout_typedefs (syms); +} + +/* Output any typedef names for types described by TYPE_DECLs in SYMS, + in the reverse order from that which is found in SYMS. */ + +static void +dbxout_typedefs (syms) + tree syms; +{ + if (syms) + { + dbxout_typedefs (TREE_CHAIN (syms)); + if (TREE_CODE (syms) == TYPE_DECL) + { + tree type = TREE_TYPE (syms); + if (TYPE_NAME (type) + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && ! TREE_ASM_WRITTEN (TYPE_NAME (type))) + dbxout_symbol (TYPE_NAME (type), 0); + } + } +} + +/* Output debugging info to FILE to switch to sourcefile FILENAME. */ + +void +dbxout_source_file (file, filename) + FILE *file; + char *filename; +{ + char ltext_label_name[100]; + + if (filename && (lastfile == 0 || strcmp (filename, lastfile))) + { +#ifdef DBX_OUTPUT_SOURCE_FILENAME + DBX_OUTPUT_SOURCE_FILENAME (file, filename); +#else + ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", + source_label_number); + fprintf (file, "%s ", ASM_STABS_OP); + output_quoted_string (file, filename); + fprintf (file, ",%d,0,0,%s\n", N_SOL, <ext_label_name[1]); + if (current_function_decl != NULL_TREE + && DECL_SECTION_NAME (current_function_decl) != NULL_TREE) + ; /* Don't change section amid function. */ + else + text_section (); + ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number); + source_label_number++; +#endif + lastfile = filename; + } +} + +/* Output a line number symbol entry into output stream FILE, + for source file FILENAME and line number LINENO. */ + +void +dbxout_source_line (file, filename, lineno) + FILE *file; + char *filename; + int lineno; +{ + dbxout_source_file (file, filename); + +#ifdef ASM_OUTPUT_SOURCE_LINE + ASM_OUTPUT_SOURCE_LINE (file, lineno); +#else + fprintf (file, "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno); +#endif +} + +/* At the end of compilation, finish writing the symbol table. + Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is + to do nothing. */ + +void +dbxout_finish (file, filename) + FILE *file; + char *filename; +{ +#ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END + DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename); +#endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */ +} + +/* Continue a symbol-description that gets too big. + End one symbol table entry with a double-backslash + and start a new one, eventually producing something like + .stabs "start......\\",code,0,value + .stabs "...rest",code,0,value */ + +static void +dbxout_continue () +{ +#ifdef DBX_CONTIN_CHAR + fprintf (asmfile, "%c", DBX_CONTIN_CHAR); +#else + fprintf (asmfile, "\\\\"); +#endif + dbxout_finish_symbol (NULL_TREE); + fprintf (asmfile, "%s \"", ASM_STABS_OP); + current_sym_nchars = 0; +} + +/* Subroutine of `dbxout_type'. Output the type fields of TYPE. + This must be a separate function because anonymous unions require + recursive calls. */ + +static void +dbxout_type_fields (type) + tree type; +{ + tree tem; + /* Output the name, type, position (in bits), size (in bits) of each + field. */ + for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) + { + /* Omit here local type decls until we know how to support them. */ + if (TREE_CODE (tem) == TYPE_DECL) + continue; + /* Omit fields whose position or size are variable. */ + else if (TREE_CODE (tem) == FIELD_DECL + && (TREE_CODE (DECL_FIELD_BITPOS (tem)) != INTEGER_CST + || TREE_CODE (DECL_SIZE (tem)) != INTEGER_CST)) + continue; + /* Omit here the nameless fields that are used to skip bits. */ + else if (TREE_CODE (tem) != CONST_DECL) + { + /* Continue the line if necessary, + but not before the first field. */ + if (tem != TYPE_FIELDS (type)) + CONTIN; + + if (use_gnu_debug_info_extensions + && flag_minimal_debug + && TREE_CODE (tem) == FIELD_DECL + && DECL_VIRTUAL_P (tem) + && DECL_ASSEMBLER_NAME (tem)) + { + have_used_extensions = 1; + CHARS (3 + IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (tem))); + fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile); + dbxout_type (DECL_FCONTEXT (tem), 0, 0); + fprintf (asmfile, ":"); + dbxout_type (TREE_TYPE (tem), 0, 0); + fprintf (asmfile, ",%d;", + TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))); + continue; + } + + if (DECL_NAME (tem)) + { + fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem))); + CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem))); + } + else + { + fprintf (asmfile, ":"); + CHARS (2); + } + + if (use_gnu_debug_info_extensions + && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem) + || TREE_CODE (tem) != FIELD_DECL)) + { + have_used_extensions = 1; + putc ('/', asmfile); + putc ((TREE_PRIVATE (tem) ? '0' + : TREE_PROTECTED (tem) ? '1' : '2'), + asmfile); + CHARS (2); + } + + dbxout_type ((TREE_CODE (tem) == FIELD_DECL + && DECL_BIT_FIELD_TYPE (tem)) + ? DECL_BIT_FIELD_TYPE (tem) + : TREE_TYPE (tem), 0, 0); + + if (TREE_CODE (tem) == VAR_DECL) + { + if (TREE_STATIC (tem) && use_gnu_debug_info_extensions) + { + char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)); + have_used_extensions = 1; + fprintf (asmfile, ":%s;", name); + CHARS (strlen (name)); + } + else + { + /* If TEM is non-static, GDB won't understand it. */ + fprintf (asmfile, ",0,0;"); + } + } + else if (TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST) + { + fprintf (asmfile, ",%d,%d;", + TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)), + TREE_INT_CST_LOW (DECL_SIZE (tem))); + } + CHARS (23); + } + } +} + +/* Subroutine of `dbxout_type_methods'. Output debug info about the + method described DECL. DEBUG_NAME is an encoding of the method's + type signature. ??? We may be able to do without DEBUG_NAME altogether + now. */ + +static void +dbxout_type_method_1 (decl, debug_name) + tree decl; + char *debug_name; +{ + char c1 = 'A', c2; + + if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE) + c2 = '?'; + else /* it's a METHOD_TYPE. */ + { + tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))); + /* A for normal functions. + B for `const' member functions. + C for `volatile' member functions. + D for `const volatile' member functions. */ + if (TYPE_READONLY (TREE_TYPE (firstarg))) + c1 += 1; + if (TYPE_VOLATILE (TREE_TYPE (firstarg))) + c1 += 2; + + if (DECL_VINDEX (decl)) + c2 = '*'; + else + c2 = '.'; + } + + fprintf (asmfile, ":%s;%c%c%c", debug_name, + TREE_PRIVATE (decl) ? '0' : TREE_PROTECTED (decl) ? '1' : '2', c1, c2); + CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6 + - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); + if (DECL_VINDEX (decl)) + { + fprintf (asmfile, "%d;", + TREE_INT_CST_LOW (DECL_VINDEX (decl))); + dbxout_type (DECL_CONTEXT (decl), 0, 0); + fprintf (asmfile, ";"); + CHARS (8); + } +} + +/* Subroutine of `dbxout_type'. Output debug info about the methods defined + in TYPE. */ + +static void +dbxout_type_methods (type) + register tree type; +{ + /* C++: put out the method names and their parameter lists */ + tree methods = TYPE_METHODS (type); + tree type_encoding; + register tree fndecl; + register tree last; + char formatted_type_identifier_length[16]; + register int type_identifier_length; + + if (methods == NULL_TREE) + return; + + type_encoding = DECL_NAME (TYPE_NAME (type)); + +#if 0 + /* C++: Template classes break some assumptions made by this code about + the class names, constructor names, and encodings for assembler + label names. For now, disable output of dbx info for them. */ + { + char *ptr = IDENTIFIER_POINTER (type_encoding); + /* This should use index. (mrs) */ + while (*ptr && *ptr != '<') ptr++; + if (*ptr != 0) + { + static int warned; + if (!warned) + { + warned = 1; +#ifdef HAVE_TEMPLATES + if (warn_template_debugging) + warning ("dbx info for template class methods not yet supported"); +#endif + } + return; + } + } +#endif + + type_identifier_length = IDENTIFIER_LENGTH (type_encoding); + + sprintf(formatted_type_identifier_length, "%d", type_identifier_length); + + if (TREE_CODE (methods) == FUNCTION_DECL) + fndecl = methods; + else if (TREE_VEC_ELT (methods, 0) != NULL_TREE) + fndecl = TREE_VEC_ELT (methods, 0); + else + fndecl = TREE_VEC_ELT (methods, 1); + + while (fndecl) + { + tree name = DECL_NAME (fndecl); + int need_prefix = 1; + + /* Group together all the methods for the same operation. + These differ in the types of the arguments. */ + for (last = NULL_TREE; + fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last)); + fndecl = TREE_CHAIN (fndecl)) + /* Output the name of the field (after overloading), as + well as the name of the field before overloading, along + with its parameter list */ + { + /* This is the "mangled" name of the method. + It encodes the argument types. */ + char *debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)); + int destructor = 0; + + CONTIN; + + last = fndecl; + + if (DECL_IGNORED_P (fndecl)) + continue; + + if (flag_minimal_debug) + { + /* Detect ordinary methods because their mangled names + start with the operation name. */ + if (!strncmp (IDENTIFIER_POINTER (name), debug_name, + IDENTIFIER_LENGTH (name))) + { + debug_name += IDENTIFIER_LENGTH (name); + if (debug_name[0] == '_' && debug_name[1] == '_') + { + char *method_name = debug_name + 2; + char *length_ptr = formatted_type_identifier_length; + /* Get past const and volatile qualifiers. */ + while (*method_name == 'C' || *method_name == 'V') + method_name++; + /* Skip digits for length of type_encoding. */ + while (*method_name == *length_ptr && *length_ptr) + length_ptr++, method_name++; + if (! strncmp (method_name, + IDENTIFIER_POINTER (type_encoding), + type_identifier_length)) + method_name += type_identifier_length; + debug_name = method_name; + } + } + /* Detect constructors by their style of name mangling. */ + else if (debug_name[0] == '_' && debug_name[1] == '_') + { + char *ctor_name = debug_name + 2; + char *length_ptr = formatted_type_identifier_length; + while (*ctor_name == 'C' || *ctor_name == 'V') + ctor_name++; + /* Skip digits for length of type_encoding. */ + while (*ctor_name == *length_ptr && *length_ptr) + length_ptr++, ctor_name++; + if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name, + type_identifier_length)) + debug_name = ctor_name + type_identifier_length; + } + /* The other alternative is a destructor. */ + else + destructor = 1; + + /* Output the operation name just once, for the first method + that we output. */ + if (need_prefix) + { + fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name)); + CHARS (IDENTIFIER_LENGTH (name) + 2); + need_prefix = 0; + } + } + + dbxout_type (TREE_TYPE (fndecl), 0, destructor); + + dbxout_type_method_1 (fndecl, debug_name); + } + if (!need_prefix) + { + putc (';', asmfile); + CHARS (1); + } + } +} + +/* Emit a "range" type specification, which has the form: + "r;;;". + TYPE is an INTEGER_TYPE. */ + +static void +dbxout_range_type (type) + tree type; +{ + fprintf (asmfile, "r"); + if (TREE_TYPE (type)) + dbxout_type (TREE_TYPE (type), 0, 0); + else if (TREE_CODE (type) != INTEGER_TYPE) + dbxout_type (type, 0, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */ + else + { + /* This used to say `r1' and we used to take care + to make sure that `int' was type number 1. */ + fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (integer_type_node)); + } + if (TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST) + fprintf (asmfile, ";%d", + TREE_INT_CST_LOW (TYPE_MIN_VALUE (type))); + else + fprintf (asmfile, ";0"); + if (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) + fprintf (asmfile, ";%d;", + TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))); + else + fprintf (asmfile, ";-1;"); +} + +/* Output a reference to a type. If the type has not yet been + described in the dbx output, output its definition now. + For a type already defined, just refer to its definition + using the type number. + + If FULL is nonzero, and the type has been described only with + a forward-reference, output the definition now. + If FULL is zero in this case, just refer to the forward-reference + using the number previously allocated. + + If SHOW_ARG_TYPES is nonzero, we output a description of the argument + types for a METHOD_TYPE. */ + +static void +dbxout_type (type, full, show_arg_types) + tree type; + int full; + int show_arg_types; +{ + register tree tem; + static int anonymous_type_number = 0; + + /* If there was an input error and we don't really have a type, + avoid crashing and write something that is at least valid + by assuming `int'. */ + if (type == error_mark_node) + type = integer_type_node; + else + { + type = TYPE_MAIN_VARIANT (type); + if (TYPE_NAME (type) + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type))) + full = 0; + } + + if (TYPE_SYMTAB_ADDRESS (type) == 0) + { + /* Type has no dbx number assigned. Assign next available number. */ + TYPE_SYMTAB_ADDRESS (type) = next_type_number++; + + /* Make sure type vector is long enough to record about this type. */ + + if (next_type_number == typevec_len) + { + typevec = + (enum typestatus *) xrealloc (typevec, + typevec_len * 2 * sizeof typevec[0]); + bzero ((char *) (typevec + typevec_len), + typevec_len * sizeof typevec[0]); + typevec_len *= 2; + } + } + + /* Output the number of this type, to refer to it. */ + fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type)); + CHARS (3); + +#ifdef DBX_TYPE_DEFINED + if (DBX_TYPE_DEFINED (type)) + return; +#endif + + /* If this type's definition has been output or is now being output, + that is all. */ + + switch (typevec[TYPE_SYMTAB_ADDRESS (type)]) + { + case TYPE_UNSEEN: + break; + case TYPE_XREF: + /* If we have already had a cross reference, + and either that's all we want or that's the best we could do, + don't repeat the cross reference. + Sun dbx crashes if we do. */ + if (! full || TYPE_SIZE (type) == 0 + /* No way in DBX fmt to describe a variable size. */ + || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) + return; + break; + case TYPE_DEFINED: + return; + } + +#ifdef DBX_NO_XREFS + /* For systems where dbx output does not allow the `=xsNAME:' syntax, + leave the type-number completely undefined rather than output + a cross-reference. If we have already used GNU debug info extensions, + then it is OK to output a cross reference. This is necessary to get + proper C++ debug output. */ + if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE + || TREE_CODE (type) == QUAL_UNION_TYPE + || TREE_CODE (type) == ENUMERAL_TYPE) + && ! use_gnu_debug_info_extensions) + /* We must use the same test here as we use twice below when deciding + whether to emit a cross-reference. */ + if ((TYPE_NAME (type) != 0 + && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_IGNORED_P (TYPE_NAME (type))) + && !full) + || TYPE_SIZE (type) == 0 + /* No way in DBX fmt to describe a variable size. */ + || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) + { + typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF; + return; + } +#endif + + /* Output a definition now. */ + + fprintf (asmfile, "="); + CHARS (1); + + /* Mark it as defined, so that if it is self-referent + we will not get into an infinite recursion of definitions. */ + + typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED; + + switch (TREE_CODE (type)) + { + case VOID_TYPE: + case LANG_TYPE: + /* For a void type, just define it as itself; ie, "5=5". + This makes us consider it defined + without saying what it is. The debugger will make it + a void type when the reference is seen, and nothing will + ever override that default. */ + fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type)); + CHARS (3); + break; + + case INTEGER_TYPE: + if (type == char_type_node && ! TREE_UNSIGNED (type)) + /* Output the type `char' as a subrange of itself! + I don't understand this definition, just copied it + from the output of pcc. + This used to use `r2' explicitly and we used to + take care to make sure that `char' was type number 2. */ + fprintf (asmfile, "r%d;0;127;", TYPE_SYMTAB_ADDRESS (type)); + else if (use_gnu_debug_info_extensions + && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node) + || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT)) + { + /* This used to say `r1' and we used to take care + to make sure that `int' was type number 1. */ + fprintf (asmfile, "r%d;", TYPE_SYMTAB_ADDRESS (integer_type_node)); + print_int_cst_octal (TYPE_MIN_VALUE (type)); + fprintf (asmfile, ";"); + print_int_cst_octal (TYPE_MAX_VALUE (type)); + fprintf (asmfile, ";"); + } + else /* Output other integer types as subranges of `int'. */ + dbxout_range_type (type); + CHARS (25); + break; + + case REAL_TYPE: + /* This used to say `r1' and we used to take care + to make sure that `int' was type number 1. */ + fprintf (asmfile, "r%d;%d;0;", TYPE_SYMTAB_ADDRESS (integer_type_node), + int_size_in_bytes (type)); + CHARS (16); + break; + + case CHAR_TYPE: + if (use_gnu_debug_info_extensions) + fprintf (asmfile, "@s%d;-20;", + BITS_PER_UNIT * int_size_in_bytes (type)); + else + /* Output the type `char' as a subrange of itself. + That is what pcc seems to do. */ + fprintf (asmfile, "r%d;0;%d;", TYPE_SYMTAB_ADDRESS (char_type_node), + TREE_UNSIGNED (type) ? 255 : 127); + CHARS (9); + break; + + case BOOLEAN_TYPE: + if (use_gnu_debug_info_extensions) + fprintf (asmfile, "@s%d;-16;", + BITS_PER_UNIT * int_size_in_bytes (type)); + else /* Define as enumeral type (False, True) */ + fprintf (asmfile, "eFalse:0,True:1,;"); + CHARS (17); + break; + + case FILE_TYPE: + putc ('d', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + break; + + case COMPLEX_TYPE: + /* Differs from the REAL_TYPE by its new data type number */ + + if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) + { + fprintf (asmfile, "r%d;%d;0;", + TYPE_SYMTAB_ADDRESS (type), + int_size_in_bytes (TREE_TYPE (type))); + CHARS (15); /* The number is probably incorrect here. */ + } + else + { + /* Output a complex integer type as a structure, + pending some other way to do it. */ + fprintf (asmfile, "s%d", int_size_in_bytes (type)); + + fprintf (asmfile, "real:"); + CHARS (10); + dbxout_type (TREE_TYPE (type), 0, 0); + fprintf (asmfile, ",%d,%d;", + 0, TYPE_PRECISION (TREE_TYPE (type))); + CHARS (8); + fprintf (asmfile, "imag:"); + CHARS (5); + dbxout_type (TREE_TYPE (type), 0, 0); + fprintf (asmfile, ",%d,%d;;", + TYPE_PRECISION (TREE_TYPE (type)), + TYPE_PRECISION (TREE_TYPE (type))); + CHARS (9); + } + break; + + case SET_TYPE: + if (use_gnu_debug_info_extensions) + { + have_used_extensions = 1; + fprintf (asmfile, "@s%d;", + BITS_PER_UNIT * int_size_in_bytes (type)); + /* Check if a bitstring type, which in Chill is + different from a [power]set. */ + if (TYPE_STRING_FLAG (type)) + fprintf (asmfile, "@S;"); + } + putc ('S', asmfile); + CHARS (1); + dbxout_type (TYPE_DOMAIN (type), 0, 0); + break; + + case ARRAY_TYPE: + /* Output "a" followed by a range type definition + for the index type of the array + followed by a reference to the target-type. + ar1;0;N;M for a C array of type M and size N+1. */ + /* Check if a character string type, which in Chill is + different from an array of characters. */ + if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions) + { + have_used_extensions = 1; + fprintf (asmfile, "@S;"); + } + tem = TYPE_DOMAIN (type); + if (tem == NULL) + fprintf (asmfile, "ar%d;0;-1;", + TYPE_SYMTAB_ADDRESS (integer_type_node)); + else + { + fprintf (asmfile, "a"); + dbxout_range_type (tem); + } + CHARS (17); + dbxout_type (TREE_TYPE (type), 0, 0); + break; + + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + { + int i, n_baseclasses = 0; + + if (TYPE_BINFO (type) != 0 && TYPE_BINFO_BASETYPES (type) != 0) + n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); + + /* Output a structure type. We must use the same test here as we + use in the DBX_NO_XREFS case above. */ + if ((TYPE_NAME (type) != 0 + && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_IGNORED_P (TYPE_NAME (type))) + && !full) + || TYPE_SIZE (type) == 0 + /* No way in DBX fmt to describe a variable size. */ + || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) + { + /* If the type is just a cross reference, output one + and mark the type as partially described. + If it later becomes defined, we will output + its real definition. + If the type has a name, don't nest its definition within + another type's definition; instead, output an xref + and let the definition come when the name is defined. */ + fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu"); + CHARS (3); +#if 0 /* This assertion is legitimately false in C++. */ + /* We shouldn't be outputting a reference to a type before its + definition unless the type has a tag name. + A typedef name without a tag name should be impossible. */ + if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE) + abort (); +#endif + if (TYPE_NAME (type) != 0) + dbxout_type_name (type); + else + fprintf (asmfile, "$$%d", anonymous_type_number++); + fprintf (asmfile, ":"); + typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF; + break; + } + + /* Identify record or union, and print its size. */ + fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d", + int_size_in_bytes (type)); + + if (use_gnu_debug_info_extensions) + { + if (n_baseclasses) + { + have_used_extensions = 1; + fprintf (asmfile, "!%d,", n_baseclasses); + CHARS (8); + } + } + for (i = 0; i < n_baseclasses; i++) + { + tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i); + if (use_gnu_debug_info_extensions) + { + have_used_extensions = 1; + putc (TREE_VIA_VIRTUAL (child) ? '1' + : '0', + asmfile); + putc (TREE_VIA_PUBLIC (child) ? '2' + : '0', + asmfile); + fprintf (asmfile, "%d,", + TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT); + CHARS (15); + dbxout_type (BINFO_TYPE (child), 0, 0); + putc (';', asmfile); + } + else + { + /* Print out the base class information with fields + which have the same names at the types they hold. */ + dbxout_type_name (BINFO_TYPE (child)); + putc (':', asmfile); + dbxout_type (BINFO_TYPE (child), full, 0); + fprintf (asmfile, ",%d,%d;", + TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT, + TREE_INT_CST_LOW (DECL_SIZE (TYPE_NAME (BINFO_TYPE (child)))) * BITS_PER_UNIT); + CHARS (20); + } + } + } + + CHARS (11); + + /* Write out the field declarations. */ + dbxout_type_fields (type); + if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE) + { + have_used_extensions = 1; + dbxout_type_methods (type); + } + putc (';', asmfile); + + if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE + /* Avoid the ~ if we don't really need it--it confuses dbx. */ + && TYPE_VFIELD (type)) + { + have_used_extensions = 1; + + /* Tell GDB+ that it may keep reading. */ + putc ('~', asmfile); + + /* We need to write out info about what field this class + uses as its "main" vtable pointer field, because if this + field is inherited from a base class, GDB cannot necessarily + figure out which field it's using in time. */ + if (TYPE_VFIELD (type)) + { + putc ('%', asmfile); + dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0); + } + putc (';', asmfile); + CHARS (3); + } + break; + + case ENUMERAL_TYPE: + /* We must use the same test here as we use in the DBX_NO_XREFS case + above. We simplify it a bit since an enum will never have a variable + size. */ + if ((TYPE_NAME (type) != 0 + && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_IGNORED_P (TYPE_NAME (type))) + && !full) + || TYPE_SIZE (type) == 0) + { + fprintf (asmfile, "xe"); + CHARS (3); + dbxout_type_name (type); + typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF; + fprintf (asmfile, ":"); + return; + } +#ifdef DBX_OUTPUT_ENUM + DBX_OUTPUT_ENUM (asmfile, type); +#else + if (use_gnu_debug_info_extensions + && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) + fprintf (asmfile, "@s%d;", TYPE_PRECISION (type)); + putc ('e', asmfile); + CHARS (1); + for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem)) + { + fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem))); + if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0) + fprintf (asmfile, "%lu", + (unsigned long) TREE_INT_CST_LOW (TREE_VALUE (tem))); + else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1 + && TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0) + fprintf (asmfile, "%ld", + (long) TREE_INT_CST_LOW (TREE_VALUE (tem))); + else + print_int_cst_octal (TREE_VALUE (tem)); + fprintf (asmfile, ","); + CHARS (20 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem))); + if (TREE_CHAIN (tem) != 0) + CONTIN; + } + putc (';', asmfile); + CHARS (1); +#endif + break; + + case POINTER_TYPE: + putc ('*', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + break; + + case METHOD_TYPE: + if (use_gnu_debug_info_extensions) + { + have_used_extensions = 1; + putc ('#', asmfile); + CHARS (1); + if (flag_minimal_debug && !show_arg_types) + { + /* Normally, just output the return type. + The argument types are encoded in the method name. */ + putc ('#', asmfile); + dbxout_type (TREE_TYPE (type), 0, 0); + putc (';', asmfile); + CHARS (1); + } + else + { + /* When outputting destructors, we need to write + the argument types out longhand. */ + dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0); + putc (',', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + dbxout_args (TYPE_ARG_TYPES (type)); + putc (';', asmfile); + CHARS (1); + } + } + else + { + /* Treat it as a function type. */ + dbxout_type (TREE_TYPE (type), 0, 0); + } + break; + + case OFFSET_TYPE: + if (use_gnu_debug_info_extensions) + { + have_used_extensions = 1; + putc ('@', asmfile); + CHARS (1); + dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0); + putc (',', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + } + else + { + /* Should print as an int, because it is really + just an offset. */ + dbxout_type (integer_type_node, 0, 0); + } + break; + + case REFERENCE_TYPE: + if (use_gnu_debug_info_extensions) + have_used_extensions = 1; + putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + break; + + case FUNCTION_TYPE: + putc ('f', asmfile); + CHARS (1); + dbxout_type (TREE_TYPE (type), 0, 0); + break; + + default: + abort (); + } +} + +/* Print the value of integer constant C, in octal, + handling double precision. */ + +static void +print_int_cst_octal (c) + tree c; +{ + unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c); + unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c); + int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3)); + int width = TYPE_PRECISION (TREE_TYPE (c)); + + /* GDB wants constants with no extra leading "1" bits, so + we need to remove any sign-extension that might be + present. */ + if (width == HOST_BITS_PER_WIDE_INT * 2) + ; + else if (width > HOST_BITS_PER_WIDE_INT) + high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1); + else if (width == HOST_BITS_PER_WIDE_INT) + high = 0; + else + high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1); + + fprintf (asmfile, "0"); + + if (excess == 3) + { + print_octal (high, HOST_BITS_PER_WIDE_INT / 3); + print_octal (low, HOST_BITS_PER_WIDE_INT / 3); + } + else + { + unsigned HOST_WIDE_INT beg = high >> excess; + unsigned HOST_WIDE_INT middle + = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess) + | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3))); + unsigned HOST_WIDE_INT end + = low & (((unsigned HOST_WIDE_INT) 1 + << (HOST_BITS_PER_WIDE_INT / 3 * 3)) + - 1); + + fprintf (asmfile, "%o%01o", beg, middle); + print_octal (end, HOST_BITS_PER_WIDE_INT / 3); + } +} + +static void +print_octal (value, digits) + unsigned HOST_WIDE_INT value; + int digits; +{ + int i; + + for (i = digits - 1; i >= 0; i--) + fprintf (asmfile, "%01o", ((value >> (3 * i)) & 7)); +} + +/* Output the name of type TYPE, with no punctuation. + Such names can be set up either by typedef declarations + or by struct, enum and union tags. */ + +static void +dbxout_type_name (type) + register tree type; +{ + tree t; + if (TYPE_NAME (type) == 0) + abort (); + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + { + t = TYPE_NAME (type); + } + else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) + { + t = DECL_NAME (TYPE_NAME (type)); + } + else + abort (); + + fprintf (asmfile, "%s", IDENTIFIER_POINTER (t)); + CHARS (IDENTIFIER_LENGTH (t)); +} + +/* Output a .stabs for the symbol defined by DECL, + which must be a ..._DECL node in the normal namespace. + It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL. + LOCAL is nonzero if the scope is less than the entire file. */ + +void +dbxout_symbol (decl, local) + tree decl; + int local; +{ + tree type = TREE_TYPE (decl); + tree context = NULL_TREE; + + /* Cast avoids warning in old compilers. */ + current_sym_code = (STAB_CODE_TYPE) 0; + current_sym_value = 0; + current_sym_addr = 0; + + /* Ignore nameless syms, but don't ignore type tags. */ + + if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL) + || DECL_IGNORED_P (decl)) + return; + + dbxout_prepare_symbol (decl); + + /* The output will always start with the symbol name, + so always count that in the length-output-so-far. */ + + if (DECL_NAME (decl) != 0) + current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl)); + + switch (TREE_CODE (decl)) + { + case CONST_DECL: + /* Enum values are defined by defining the enum type. */ + break; + + case FUNCTION_DECL: + if (DECL_RTL (decl) == 0) + return; + if (DECL_EXTERNAL (decl)) + break; + /* Don't mention a nested function under its parent. */ + context = decl_function_context (decl); + if (context == current_function_decl) + break; + if (GET_CODE (DECL_RTL (decl)) != MEM + || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF) + break; + FORCE_TEXT; + + fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), + TREE_PUBLIC (decl) ? 'F' : 'f'); + + current_sym_code = N_FUN; + current_sym_addr = XEXP (DECL_RTL (decl), 0); + + if (TREE_TYPE (type)) + dbxout_type (TREE_TYPE (type), 0, 0); + else + dbxout_type (void_type_node, 0, 0); + + /* For a nested function, when that function is compiled, + mention the containing function name + as well as (since dbx wants it) our own assembler-name. */ + if (context != 0) + fprintf (asmfile, ",%s,%s", + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), + IDENTIFIER_POINTER (DECL_NAME (context))); + + dbxout_finish_symbol (decl); + break; + + case TYPE_DECL: +#if 0 + /* This seems all wrong. Outputting most kinds of types gives no name + at all. A true definition gives no name; a cross-ref for a + structure can give the tag name, but not a type name. + It seems that no typedef name is defined by outputting a type. */ + + /* If this typedef name was defined by outputting the type, + don't duplicate it. */ + if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED + && TYPE_NAME (TREE_TYPE (decl)) == decl) + return; +#endif + /* Don't output the same typedef twice. + And don't output what language-specific stuff doesn't want output. */ + if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl)) + return; + + FORCE_TEXT; + + { + int tag_needed = 1; + int did_output = 0; + + if (DECL_NAME (decl)) + { + /* Nonzero means we must output a tag as well as a typedef. */ + tag_needed = 0; + + /* Handle the case of a C++ structure or union + where the TYPE_NAME is a TYPE_DECL + which gives both a typedef name and a tag. */ + /* dbx requires the tag first and the typedef second. */ + if ((TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE + || TREE_CODE (type) == QUAL_UNION_TYPE) + && TYPE_NAME (type) == decl + && !(use_gnu_debug_info_extensions && have_used_extensions) + && !TREE_ASM_WRITTEN (TYPE_NAME (type)) + /* Distinguish the implicit typedefs of C++ + from explicit ones that might be found in C. */ + && (!strcmp (lang_identify (), "cplusplus") + /* The following line maybe unnecessary; + in 2.6, try removing it. */ + || DECL_SOURCE_LINE (decl) == 0)) + { + tree name = TYPE_NAME (type); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + current_sym_code = DBX_TYPE_DECL_STABS_CODE; + current_sym_value = 0; + current_sym_addr = 0; + current_sym_nchars = 2 + IDENTIFIER_LENGTH (name); + + fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP, + IDENTIFIER_POINTER (name)); + dbxout_type (type, 1, 0); + dbxout_finish_symbol (NULL_TREE); + } + + /* Output typedef name. */ + fprintf (asmfile, "%s \"%s:", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (decl))); + + /* Short cut way to output a tag also. */ + if ((TREE_CODE (type) == RECORD_TYPE + || TREE_CODE (type) == UNION_TYPE + || TREE_CODE (type) == QUAL_UNION_TYPE) + && TYPE_NAME (type) == decl) + { + if (use_gnu_debug_info_extensions && have_used_extensions) + { + putc ('T', asmfile); + TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1; + } +#if 0 /* Now we generate the tag for this case up above. */ + else + tag_needed = 1; +#endif + } + + putc ('t', asmfile); + current_sym_code = DBX_TYPE_DECL_STABS_CODE; + + dbxout_type (type, 1, 0); + dbxout_finish_symbol (decl); + did_output = 1; + } + + /* Don't output a tag if this is an incomplete type (TYPE_SIZE is + zero). This prevents the sun4 Sun OS 4.x dbx from crashing. */ + + if (tag_needed && TYPE_NAME (type) != 0 + && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE + || (DECL_NAME (TYPE_NAME (type)) != 0)) + && TYPE_SIZE (type) != 0 + && !TREE_ASM_WRITTEN (TYPE_NAME (type))) + { + /* For a TYPE_DECL with no name, but the type has a name, + output a tag. + This is what represents `struct foo' with no typedef. */ + /* In C++, the name of a type is the corresponding typedef. + In C, it is an IDENTIFIER_NODE. */ + tree name = TYPE_NAME (type); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + current_sym_code = DBX_TYPE_DECL_STABS_CODE; + current_sym_value = 0; + current_sym_addr = 0; + current_sym_nchars = 2 + IDENTIFIER_LENGTH (name); + + fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP, + IDENTIFIER_POINTER (name)); + dbxout_type (type, 1, 0); + dbxout_finish_symbol (NULL_TREE); + did_output = 1; + } + + /* If an enum type has no name, it cannot be referred to, + but we must output it anyway, since the enumeration constants + can be referred to. */ + if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE) + { + current_sym_code = DBX_TYPE_DECL_STABS_CODE; + current_sym_value = 0; + current_sym_addr = 0; + current_sym_nchars = 2; + + /* Some debuggers fail when given NULL names, so give this a + harmless name of ` '. */ + fprintf (asmfile, "%s \" :T", ASM_STABS_OP); + dbxout_type (type, 1, 0); + dbxout_finish_symbol (NULL_TREE); + } + + /* Prevent duplicate output of a typedef. */ + TREE_ASM_WRITTEN (decl) = 1; + break; + } + + case PARM_DECL: + /* Parm decls go in their own separate chains + and are output by dbxout_reg_parms and dbxout_parms. */ + abort (); + + case RESULT_DECL: + /* Named return value, treat like a VAR_DECL. */ + case VAR_DECL: + if (DECL_RTL (decl) == 0) + return; + /* Don't mention a variable that is external. + Let the file that defines it describe it. */ + if (DECL_EXTERNAL (decl)) + break; + + /* If the variable is really a constant + and not written in memory, inform the debugger. */ + if (TREE_STATIC (decl) && TREE_READONLY (decl) + && DECL_INITIAL (decl) != 0 + && ! TREE_ASM_WRITTEN (decl) + && (DECL_FIELD_CONTEXT (decl) == NULL_TREE + || TREE_CODE (DECL_FIELD_CONTEXT (decl)) == BLOCK)) + { + if (TREE_PUBLIC (decl) == 0) + { + /* The sun4 assembler does not grok this. */ + char *name = IDENTIFIER_POINTER (DECL_NAME (decl)); + if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) + { + HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl)); +#ifdef DBX_OUTPUT_CONSTANT_SYMBOL + DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival); +#else + fprintf (asmfile, "%s \"%s:c=i%d\",0x%x,0,0,0\n", + ASM_STABS_OP, name, ival, N_LSYM); +#endif + return; + } + else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE) + { + /* don't know how to do this yet. */ + } + break; + } + /* else it is something we handle like a normal variable. */ + } + + DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX); +#ifdef LEAF_REG_REMAP + if (leaf_function) + leaf_renumber_regs_insn (DECL_RTL (decl)); +#endif + + dbxout_symbol_location (decl, type, 0, DECL_RTL (decl)); + } +} + +/* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL. + Add SUFFIX to its name, if SUFFIX is not 0. + Describe the variable as residing in HOME + (usually HOME is DECL_RTL (DECL), but not always). */ + +static void +dbxout_symbol_location (decl, type, suffix, home) + tree decl, type; + char *suffix; + rtx home; +{ + int letter = 0; + int regno = -1; + + /* Don't mention a variable at all + if it was completely optimized into nothingness. + + If the decl was from an inline function, then it's rtl + is not identically the rtl that was used in this + particular compilation. */ + if (GET_CODE (home) == REG) + { + regno = REGNO (home); + if (regno >= FIRST_PSEUDO_REGISTER) + return; + } + else if (GET_CODE (home) == SUBREG) + { + rtx value = home; + int offset = 0; + while (GET_CODE (value) == SUBREG) + { + offset += SUBREG_WORD (value); + value = SUBREG_REG (value); + } + if (GET_CODE (value) == REG) + { + regno = REGNO (value); + if (regno >= FIRST_PSEUDO_REGISTER) + return; + regno += offset; + } + alter_subreg (home); + } + + /* The kind-of-variable letter depends on where + the variable is and on the scope of its name: + G and N_GSYM for static storage and global scope, + S for static storage and file scope, + V for static storage and local scope, + for those two, use N_LCSYM if data is in bss segment, + N_STSYM if in data segment, N_FUN otherwise. + (We used N_FUN originally, then changed to N_STSYM + to please GDB. However, it seems that confused ld. + Now GDB has been fixed to like N_FUN, says Kingdon.) + no letter at all, and N_LSYM, for auto variable, + r and N_RSYM for register variable. */ + + if (GET_CODE (home) == MEM + && GET_CODE (XEXP (home, 0)) == SYMBOL_REF) + { + if (TREE_PUBLIC (decl)) + { + letter = 'G'; + current_sym_code = N_GSYM; + } + else + { + current_sym_addr = XEXP (home, 0); + + letter = decl_function_context (decl) ? 'V' : 'S'; + + /* This should be the same condition as in assemble_variable, but + we don't have access to dont_output_data here. So, instead, + we rely on the fact that error_mark_node initializers always + end up in bss for C++ and never end up in bss for C. */ + if (DECL_INITIAL (decl) == 0 + || (!strcmp (lang_identify (), "cplusplus") + && DECL_INITIAL (decl) == error_mark_node)) + current_sym_code = N_LCSYM; + else if (DECL_IN_TEXT_SECTION (decl)) + /* This is not quite right, but it's the closest + of all the codes that Unix defines. */ + current_sym_code = DBX_STATIC_CONST_VAR_CODE; + else + { + /* Ultrix `as' seems to need this. */ +#ifdef DBX_STATIC_STAB_DATA_SECTION + data_section (); +#endif + current_sym_code = N_STSYM; + } + } + } + else if (regno >= 0) + { + letter = 'r'; + current_sym_code = N_RSYM; + current_sym_value = DBX_REGISTER_NUMBER (regno); + } + else if (GET_CODE (home) == MEM + && (GET_CODE (XEXP (home, 0)) == MEM + || (GET_CODE (XEXP (home, 0)) == REG + && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM))) + /* If the value is indirect by memory or by a register + that isn't the frame pointer + then it means the object is variable-sized and address through + that register or stack slot. DBX has no way to represent this + so all we can do is output the variable as a pointer. + If it's not a parameter, ignore it. + (VAR_DECLs like this can be made by integrate.c.) */ + { + if (GET_CODE (XEXP (home, 0)) == REG) + { + letter = 'r'; + current_sym_code = N_RSYM; + current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0))); + } + else + { + current_sym_code = N_LSYM; + /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))). + We want the value of that CONST_INT. */ + current_sym_value + = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0)); + } + + /* Effectively do build_pointer_type, but don't cache this type, + since it might be temporary whereas the type it points to + might have been saved for inlining. */ + /* Don't use REFERENCE_TYPE because dbx can't handle that. */ + type = make_node (POINTER_TYPE); + TREE_TYPE (type) = TREE_TYPE (decl); + } + else if (GET_CODE (home) == MEM + && GET_CODE (XEXP (home, 0)) == REG) + { + current_sym_code = N_LSYM; + current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); + } + else if (GET_CODE (home) == MEM + && GET_CODE (XEXP (home, 0)) == PLUS + && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT) + { + current_sym_code = N_LSYM; + /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...))) + We want the value of that CONST_INT. */ + current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); + } + else if (GET_CODE (home) == MEM + && GET_CODE (XEXP (home, 0)) == CONST) + { + /* Handle an obscure case which can arise when optimizing and + when there are few available registers. (This is *always* + the case for i386/i486 targets). The RTL looks like + (MEM (CONST ...)) even though this variable is a local `auto' + or a local `register' variable. In effect, what has happened + is that the reload pass has seen that all assignments and + references for one such a local variable can be replaced by + equivalent assignments and references to some static storage + variable, thereby avoiding the need for a register. In such + cases we're forced to lie to debuggers and tell them that + this variable was itself `static'. */ + current_sym_code = N_LCSYM; + letter = 'V'; + current_sym_addr = XEXP (XEXP (home, 0), 0); + } + else if (GET_CODE (home) == CONCAT) + { + tree subtype = TREE_TYPE (type); + + /* If the variable's storage is in two parts, + output each as a separate stab with a modified name. */ + if (WORDS_BIG_ENDIAN) + dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0)); + else + dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0)); + + /* Cast avoids warning in old compilers. */ + current_sym_code = (STAB_CODE_TYPE) 0; + current_sym_value = 0; + current_sym_addr = 0; + dbxout_prepare_symbol (decl); + + if (WORDS_BIG_ENDIAN) + dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1)); + else + dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1)); + return; + } + else + /* Address might be a MEM, when DECL is a variable-sized object. + Or it might be const0_rtx, meaning previous passes + want us to ignore this variable. */ + return; + + /* Ok, start a symtab entry and output the variable name. */ + FORCE_TEXT; + +#ifdef DBX_STATIC_BLOCK_START + DBX_STATIC_BLOCK_START (asmfile, current_sym_code); +#endif + + dbxout_symbol_name (decl, suffix, letter); + dbxout_type (type, 0, 0); + dbxout_finish_symbol (decl); + +#ifdef DBX_STATIC_BLOCK_END + DBX_STATIC_BLOCK_END (asmfile, current_sym_code); +#endif +} + +/* Output the symbol name of DECL for a stabs, with suffix SUFFIX. + Then output LETTER to indicate the kind of location the symbol has. */ + +static void +dbxout_symbol_name (decl, suffix, letter) + tree decl; + char *suffix; + int letter; +{ + /* One slight hitch: if this is a VAR_DECL which is a static + class member, we must put out the mangled name instead of the + DECL_NAME. Note also that static member (variable) names DO NOT begin + with underscores in .stabs directives. */ + char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); + if (name == 0) + name = "(anon)"; + fprintf (asmfile, "%s \"%s%s:", ASM_STABS_OP, name, + (suffix ? suffix : "")); + + if (letter) putc (letter, asmfile); +} + +static void +dbxout_prepare_symbol (decl) + tree decl; +{ +#ifdef WINNING_GDB + char *filename = DECL_SOURCE_FILE (decl); + + dbxout_source_file (asmfile, filename); +#endif +} + +static void +dbxout_finish_symbol (sym) + tree sym; +{ +#ifdef DBX_FINISH_SYMBOL + DBX_FINISH_SYMBOL (sym); +#else + int line = 0; + if (use_gnu_debug_info_extensions && sym != 0) + line = DECL_SOURCE_LINE (sym); + + fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line); + if (current_sym_addr) + output_addr_const (asmfile, current_sym_addr); + else + fprintf (asmfile, "%d", current_sym_value); + putc ('\n', asmfile); +#endif +} + +/* Output definitions of all the decls in a chain. */ + +void +dbxout_syms (syms) + tree syms; +{ + while (syms) + { + dbxout_symbol (syms, 1); + syms = TREE_CHAIN (syms); + } +} + +/* The following two functions output definitions of function parameters. + Each parameter gets a definition locating it in the parameter list. + Each parameter that is a register variable gets a second definition + locating it in the register. + + Printing or argument lists in gdb uses the definitions that + locate in the parameter list. But reference to the variable in + expressions uses preferentially the definition as a register. */ + +/* Output definitions, referring to storage in the parmlist, + of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ + +void +dbxout_parms (parms) + tree parms; +{ + for (; parms; parms = TREE_CHAIN (parms)) + if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node) + { + dbxout_prepare_symbol (parms); + + /* Perform any necessary register eliminations on the parameter's rtl, + so that the debugging output will be accurate. */ + DECL_INCOMING_RTL (parms) + = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX); + DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX); +#ifdef LEAF_REG_REMAP + if (leaf_function) + { + leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms)); + leaf_renumber_regs_insn (DECL_RTL (parms)); + } +#endif + + if (PARM_PASSED_IN_MEMORY (parms)) + { + rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0); + + /* ??? Here we assume that the parm address is indexed + off the frame pointer or arg pointer. + If that is not true, we produce meaningless results, + but do not crash. */ + if (GET_CODE (addr) == PLUS + && GET_CODE (XEXP (addr, 1)) == CONST_INT) + current_sym_value = INTVAL (XEXP (addr, 1)); + else + current_sym_value = 0; + + current_sym_code = N_PSYM; + current_sym_addr = 0; + + FORCE_TEXT; + if (DECL_NAME (parms)) + { + current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms)); + + fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (parms)), + DBX_MEMPARM_STABS_LETTER); + } + else + { + current_sym_nchars = 8; + fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP, + DBX_MEMPARM_STABS_LETTER); + } + + dbxout_type (DECL_ARG_TYPE (parms), 0, 0); + current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr); + dbxout_finish_symbol (parms); + } + else if (GET_CODE (DECL_RTL (parms)) == REG) + { + rtx best_rtl; + char regparm_letter; + tree parm_type; + /* Parm passed in registers and lives in registers or nowhere. */ + + current_sym_code = DBX_REGPARM_STABS_CODE; + regparm_letter = DBX_REGPARM_STABS_LETTER; + current_sym_addr = 0; + + /* If parm lives in a register, use that register; + pretend the parm was passed there. It would be more consistent + to describe the register where the parm was passed, + but in practice that register usually holds something else. + + If we use DECL_RTL, then we must use the declared type of + the variable, not the type that it arrived in. */ + if (REGNO (DECL_RTL (parms)) >= 0 + && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) + { + best_rtl = DECL_RTL (parms); + parm_type = TREE_TYPE (parms); + } + /* If the parm lives nowhere, use the register where it was + passed. It is also better to use the declared type here. */ + else + { + best_rtl = DECL_INCOMING_RTL (parms); + parm_type = TREE_TYPE (parms); + } + current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl)); + + FORCE_TEXT; + if (DECL_NAME (parms)) + { + current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms)); + fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (parms)), + regparm_letter); + } + else + { + current_sym_nchars = 8; + fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP, + regparm_letter); + } + + dbxout_type (parm_type, 0, 0); + dbxout_finish_symbol (parms); + } + else if (GET_CODE (DECL_RTL (parms)) == MEM + && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG + && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM + && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM +#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM + && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM +#endif + ) + { + /* Parm was passed via invisible reference. + That is, its address was passed in a register. + Output it as if it lived in that register. + The debugger will know from the type + that it was actually passed by invisible reference. */ + + char regparm_letter; + /* Parm passed in registers and lives in registers or nowhere. */ + + current_sym_code = DBX_REGPARM_STABS_CODE; + if (use_gnu_debug_info_extensions) + regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER; + else + regparm_letter = DBX_REGPARM_STABS_LETTER; + + /* DECL_RTL looks like (MEM (REG...). Get the register number. + If it is an unallocated pseudo-reg, then use the register where + it was passed instead. */ + if (REGNO (XEXP (DECL_RTL (parms), 0)) >= 0 + && REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER) + current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0)); + else + current_sym_value = REGNO (DECL_INCOMING_RTL (parms)); + + current_sym_addr = 0; + + FORCE_TEXT; + if (DECL_NAME (parms)) + { + current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms))); + + fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (parms)), + regparm_letter); + } + else + { + current_sym_nchars = 8; + fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP, + regparm_letter); + } + + dbxout_type (TREE_TYPE (parms), 0, 0); + dbxout_finish_symbol (parms); + } + else if (GET_CODE (DECL_RTL (parms)) == MEM + && XEXP (DECL_RTL (parms), 0) != const0_rtx + /* ??? A constant address for a parm can happen + when the reg it lives in is equiv to a constant in memory. + Should make this not happen, after 2.4. */ + && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0))) + { + /* Parm was passed in registers but lives on the stack. */ + + current_sym_code = N_PSYM; + /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), + in which case we want the value of that CONST_INT, + or (MEM (REG ...)) or (MEM (MEM ...)), + in which case we use a value of zero. */ + if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG + || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM) + current_sym_value = 0; + else + current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); + current_sym_addr = 0; + + FORCE_TEXT; + if (DECL_NAME (parms)) + { + current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms))); + + fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (parms)), + DBX_MEMPARM_STABS_LETTER); + } + else + { + current_sym_nchars = 8; + fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP, + DBX_MEMPARM_STABS_LETTER); + } + + current_sym_value + = DEBUGGER_ARG_OFFSET (current_sym_value, + XEXP (DECL_RTL (parms), 0)); + dbxout_type (TREE_TYPE (parms), 0, 0); + dbxout_finish_symbol (parms); + } + } +} + +/* Output definitions for the places where parms live during the function, + when different from where they were passed, when the parms were passed + in memory. + + It is not useful to do this for parms passed in registers + that live during the function in different registers, because it is + impossible to look in the passed register for the passed value, + so we use the within-the-function register to begin with. + + PARMS is a chain of PARM_DECL nodes. */ + +void +dbxout_reg_parms (parms) + tree parms; +{ + for (; parms; parms = TREE_CHAIN (parms)) + if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms)) + { + dbxout_prepare_symbol (parms); + + /* Report parms that live in registers during the function + but were passed in memory. */ + if (GET_CODE (DECL_RTL (parms)) == REG + && REGNO (DECL_RTL (parms)) >= 0 + && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) + dbxout_symbol_location (parms, TREE_TYPE (parms), + 0, DECL_RTL (parms)); + else if (GET_CODE (DECL_RTL (parms)) == CONCAT) + dbxout_symbol_location (parms, TREE_TYPE (parms), + 0, DECL_RTL (parms)); + /* Report parms that live in memory but not where they were passed. */ + else if (GET_CODE (DECL_RTL (parms)) == MEM + && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) + dbxout_symbol_location (parms, TREE_TYPE (parms), + 0, DECL_RTL (parms)); + } +} + +/* Given a chain of ..._TYPE nodes (as come in a parameter list), + output definitions of those names, in raw form */ + +void +dbxout_args (args) + tree args; +{ + while (args) + { + putc (',', asmfile); + dbxout_type (TREE_VALUE (args), 0, 0); + CHARS (1); + args = TREE_CHAIN (args); + } +} + +/* Given a chain of ..._TYPE nodes, + find those which have typedef names and output those names. + This is to ensure those types get output. */ + +void +dbxout_types (types) + register tree types; +{ + while (types) + { + if (TYPE_NAME (types) + && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL + && ! TREE_ASM_WRITTEN (TYPE_NAME (types))) + dbxout_symbol (TYPE_NAME (types), 1); + types = TREE_CHAIN (types); + } +} + +/* Output everything about a symbol block (a BLOCK node + that represents a scope level), + including recursive output of contained blocks. + + BLOCK is the BLOCK node. + DEPTH is its depth within containing symbol blocks. + ARGS is usually zero; but for the outermost block of the + body of a function, it is a chain of PARM_DECLs for the function parameters. + We output definitions of all the register parms + as if they were local variables of that block. + + If -g1 was used, we count blocks just the same, but output nothing + except for the outermost block. + + Actually, BLOCK may be several blocks chained together. + We handle them all in sequence. */ + +static void +dbxout_block (block, depth, args) + register tree block; + int depth; + tree args; +{ + int blocknum; + + while (block) + { + /* Ignore blocks never expanded or otherwise marked as real. */ + if (TREE_USED (block)) + { +#ifndef DBX_LBRAC_FIRST + /* In dbx format, the syms of a block come before the N_LBRAC. */ + if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0) + dbxout_syms (BLOCK_VARS (block)); + if (args) + dbxout_reg_parms (args); +#endif + + /* Now output an N_LBRAC symbol to represent the beginning of + the block. Use the block's tree-walk order to generate + the assembler symbols LBBn and LBEn + that final will define around the code in this block. */ + if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE) + { + char buf[20]; + blocknum = next_block_number++; + ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum); + + if (BLOCK_HANDLER_BLOCK (block)) + { + /* A catch block. Must precede N_LBRAC. */ + tree decl = BLOCK_VARS (block); + while (decl) + { +#ifdef DBX_OUTPUT_CATCH + DBX_OUTPUT_CATCH (asmfile, decl, buf); +#else + fprintf (asmfile, "%s \"%s:C1\",%d,0,0,", ASM_STABS_OP, + IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH); + assemble_name (asmfile, buf); + fprintf (asmfile, "\n"); +#endif + decl = TREE_CHAIN (decl); + } + } + +#ifdef DBX_OUTPUT_LBRAC + DBX_OUTPUT_LBRAC (asmfile, buf); +#else + fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC); + assemble_name (asmfile, buf); +#if DBX_BLOCKS_FUNCTION_RELATIVE + fputc ('-', asmfile); + assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); +#endif + fprintf (asmfile, "\n"); +#endif + } + else if (depth > 0) + /* Count blocks the same way regardless of debug_info_level. */ + next_block_number++; + +#ifdef DBX_LBRAC_FIRST + /* On some weird machines, the syms of a block + come after the N_LBRAC. */ + if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0) + dbxout_syms (BLOCK_VARS (block)); + if (args) + dbxout_reg_parms (args); +#endif + + /* Output the subblocks. */ + dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE); + + /* Refer to the marker for the end of the block. */ + if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE) + { + char buf[20]; + ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum); +#ifdef DBX_OUTPUT_RBRAC + DBX_OUTPUT_RBRAC (asmfile, buf); +#else + fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC); + assemble_name (asmfile, buf); +#if DBX_BLOCKS_FUNCTION_RELATIVE + fputc ('-', asmfile); + assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); +#endif + fprintf (asmfile, "\n"); +#endif + } + } + block = BLOCK_CHAIN (block); + } +} + +/* Output the information about a function and its arguments and result. + Usually this follows the function's code, + but on some systems, it comes before. */ + +static void +dbxout_really_begin_function (decl) + tree decl; +{ + dbxout_symbol (decl, 0); + dbxout_parms (DECL_ARGUMENTS (decl)); + if (DECL_NAME (DECL_RESULT (decl)) != 0) + dbxout_symbol (DECL_RESULT (decl), 1); +} + +/* Called at beginning of output of function definition. */ + +void +dbxout_begin_function (decl) + tree decl; +{ +#ifdef DBX_FUNCTION_FIRST + dbxout_really_begin_function (decl); +#endif +} + +/* Output dbx data for a function definition. + This includes a definition of the function name itself (a symbol), + definitions of the parameters (locating them in the parameter list) + and then output the block that makes up the function's body + (including all the auto variables of the function). */ + +void +dbxout_function (decl) + tree decl; +{ +#ifndef DBX_FUNCTION_FIRST + dbxout_really_begin_function (decl); +#endif + dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl)); +#ifdef DBX_OUTPUT_FUNCTION_END + DBX_OUTPUT_FUNCTION_END (asmfile, decl); +#endif +} +#endif /* DBX_DEBUGGING_INFO */ diff --git a/contrib/gcc/dbxstclass.h b/contrib/gcc/dbxstclass.h new file mode 100644 index 00000000000..2d003fed3bb --- /dev/null +++ b/contrib/gcc/dbxstclass.h @@ -0,0 +1,17 @@ +/* Storage classes in XCOFF object file format designed for DBX's use. + This info is from the `Files Reference' manual for IBM's AIX version 3 + for the RS6000. */ + +#define C_GSYM 0x80 +#define C_LSYM 0x81 +#define C_PSYM 0x82 +#define C_RSYM 0x83 +#define C_RPSYM 0x84 +#define C_STSYM 0x85 + +#define C_BCOMM 0x87 +#define C_ECOML 0x88 +#define C_ECOMM 0x89 +#define C_DECL 0x8c +#define C_ENTRY 0x8d +#define C_FUN 0x8e diff --git a/contrib/gcc/defaults.h b/contrib/gcc/defaults.h new file mode 100644 index 00000000000..27d4f3f9e56 --- /dev/null +++ b/contrib/gcc/defaults.h @@ -0,0 +1,143 @@ +/* Definitions of various defaults for how to do assembler output + (most of which are designed to be appropriate for GAS or for + some BSD assembler). + + Written by Ron Guilmette (rfg@netcom.com) + +Copyright (C) 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* Store in OUTPUT a string (made with alloca) containing + an assembler-name for a local static variable or function named NAME. + LABELNO is an integer which is different for each call. */ + +#ifndef ASM_FORMAT_PRIVATE_NAME +#define ASM_FORMAT_PRIVATE_NAME(OUTPUT, NAME, LABELNO) \ + do { \ + int len = strlen (NAME); \ + char *temp = (char *) alloca (len + 3); \ + temp[0] = 'L'; \ + strcpy (&temp[1], (NAME)); \ + temp[len + 1] = '.'; \ + temp[len + 2] = 0; \ + (OUTPUT) = (char *) alloca (strlen (NAME) + 11); \ + ASM_GENERATE_INTERNAL_LABEL (OUTPUT, temp, LABELNO); \ + } while (0) +#endif + +#ifndef ASM_STABD_OP +#define ASM_STABD_OP ".stabd" +#endif + +/* This is how to output an element of a case-vector that is absolute. + Some targets don't use this, but we have to define it anyway. */ + +#ifndef ASM_OUTPUT_ADDR_VEC_ELT +#define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE) \ +do { fprintf (FILE, "\t%s\t", ASM_LONG); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "L", (VALUE)); \ + fputc ('\n', FILE); \ + } while (0) +#endif + +/* This is how to output an element of a case-vector that is relative. + Some targets don't use this, but we have to define it anyway. */ + +#ifndef ASM_OUTPUT_ADDR_DIFF_ELT +#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \ +do { fprintf (FILE, "\t%s\t", ASM_SHORT); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "L", (VALUE)); \ + fputc ('-', FILE); \ + ASM_OUTPUT_INTERNAL_LABEL (FILE, "L", (REL)); \ + fputc ('\n', FILE); \ + } while (0) +#endif + +/* choose a reasonable default for ASM_OUTPUT_ASCII. */ + +#ifndef ASM_OUTPUT_ASCII +#define ASM_OUTPUT_ASCII(MYFILE, MYSTRING, MYLENGTH) \ + do { \ + FILE *_hide_asm_out_file = (MYFILE); \ + unsigned char *_hide_p = (unsigned char *) (MYSTRING); \ + int _hide_thissize = (MYLENGTH); \ + { \ + FILE *asm_out_file = _hide_asm_out_file; \ + unsigned char *p = _hide_p; \ + int thissize = _hide_thissize; \ + int i; \ + fprintf (asm_out_file, "\t.ascii \""); \ + \ + for (i = 0; i < thissize; i++) \ + { \ + register int c = p[i]; \ + if (c == '\"' || c == '\\') \ + putc ('\\', asm_out_file); \ + if (c >= ' ' && c < 0177) \ + putc (c, asm_out_file); \ + else \ + { \ + fprintf (asm_out_file, "\\%o", c); \ + /* After an octal-escape, if a digit follows, \ + terminate one string constant and start another. \ + The Vax assembler fails to stop reading the escape \ + after three digits, so this is the only way we \ + can get it to parse the data properly. */ \ + if (i < thissize - 1 \ + && p[i + 1] >= '0' && p[i + 1] <= '9') \ + fprintf (asm_out_file, "\"\n\t.ascii \""); \ + } \ + } \ + fprintf (asm_out_file, "\"\n"); \ + } \ + } \ + while (0) +#endif + +#ifndef ASM_IDENTIFY_GCC + /* Default the definition, only if ASM_IDENTIFY_GCC is not set, + because if it is set, we might not want ASM_IDENTIFY_LANGUAGE + outputting labels, if we do want it to, then it must be defined + in the tm.h file. */ +#ifndef ASM_IDENTIFY_LANGUAGE +#define ASM_IDENTIFY_LANGUAGE(FILE) output_lang_identify (FILE); +#endif +#endif + +/* This is how we tell the assembler to equate two values. */ +#ifdef SET_ASM_OP +#ifndef ASM_OUTPUT_DEF +#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ + do { fprintf ((FILE), "\t%s\t", SET_ASM_OP); \ + assemble_name (FILE, LABEL1); \ + fprintf (FILE, ","); \ + assemble_name (FILE, LABEL2); \ + fprintf (FILE, "\n"); \ + } while (0) +#endif +#endif + +/* This determines whether or not we support weak symbols. */ +#ifndef SUPPORTS_WEAK +#ifdef ASM_WEAKEN_LABEL +#define SUPPORTS_WEAK 1 +#else +#define SUPPORTS_WEAK 0 +#endif +#endif diff --git a/contrib/gcc/demangle.h b/contrib/gcc/demangle.h new file mode 100644 index 00000000000..8dcd5fd06a6 --- /dev/null +++ b/contrib/gcc/demangle.h @@ -0,0 +1,108 @@ +/* Defs for interface to demanglers. + Copyright 1992, 1995 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + +#if !defined (DEMANGLE_H) +#define DEMANGLE_H + +#ifdef IN_GCC + +/* Add prototype support. */ +#ifndef PROTO +#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__) +#define PROTO(ARGS) ARGS +#else +#define PROTO(ARGS) () +#endif +#endif + +#define PARAMS(ARGS) PROTO(ARGS) + +#ifdef __STDC__ +#define PTR void * +#else +#ifndef const +#define const +#endif +#define PTR char * +#endif + +#else /* ! IN_GCC */ +#include +#endif /* IN_GCC */ + +/* Options passed to cplus_demangle (in 2nd parameter). */ + +#define DMGL_NO_OPTS 0 /* For readability... */ +#define DMGL_PARAMS (1 << 0) /* Include function args */ +#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ + +#define DMGL_AUTO (1 << 8) +#define DMGL_GNU (1 << 9) +#define DMGL_LUCID (1 << 10) +#define DMGL_ARM (1 << 11) +/* If none of these are set, use 'current_demangling_style' as the default. */ +#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM) + +/* Enumeration of possible demangling styles. + + Lucid and ARM styles are still kept logically distinct, even though + they now both behave identically. The resulting style is actual the + union of both. I.E. either style recognizes both "__pt__" and "__rf__" + for operator "->", even though the first is lucid style and the second + is ARM style. (FIXME?) */ + +extern enum demangling_styles +{ + unknown_demangling = 0, + auto_demangling = DMGL_AUTO, + gnu_demangling = DMGL_GNU, + lucid_demangling = DMGL_LUCID, + arm_demangling = DMGL_ARM +} current_demangling_style; + +/* Define string names for the various demangling styles. */ + +#define AUTO_DEMANGLING_STYLE_STRING "auto" +#define GNU_DEMANGLING_STYLE_STRING "gnu" +#define LUCID_DEMANGLING_STYLE_STRING "lucid" +#define ARM_DEMANGLING_STYLE_STRING "arm" + +/* Some macros to test what demangling style is active. */ + +#define CURRENT_DEMANGLING_STYLE current_demangling_style +#define AUTO_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_AUTO) +#define GNU_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU) +#define LUCID_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_LUCID) +#define ARM_DEMANGLING (CURRENT_DEMANGLING_STYLE & DMGL_ARM) + +extern char * +cplus_demangle PARAMS ((const char *mangled, int options)); + +extern int +cplus_demangle_opname PARAMS ((char *opname, char *result, int options)); + +extern char * +cplus_mangle_opname PARAMS ((char *opname, int options)); + +/* Note: This sets global state. FIXME if you care about multi-threading. */ + +extern void +set_cplus_marker_for_demangling PARAMS ((int ch)); + +#endif /* DEMANGLE_H */ diff --git a/contrib/gcc/doschk.c b/contrib/gcc/doschk.c new file mode 100644 index 00000000000..7fbb7334dc1 --- /dev/null +++ b/contrib/gcc/doschk.c @@ -0,0 +1,360 @@ +/* +** DosFCheck - check file names for DOS consistency +** +** Distribute freely, it only encourages DOS compatibility! +** - DJ Delorie +*/ + +/* This file is not part of GCC. */ + +#include +#ifdef __MSDOS__ +#include +#else +#include +#endif +#include +#include + +typedef struct ENT +{ + struct ENT *next; + char *dos_name; + char *full_name; + char *path; + int tagged; +} ENT; + +ENT *eroot = 0; + +int first_inv = 1; +int first_msg = 1; + +/****************************************************************\ + * Utility routines * +\****************************************************************/ + +void +invalid_msg () +{ + if (first_inv) + { + if (first_msg) + first_msg = 0; + else + putchar ('\n'); + printf ("The following files are not valid DOS file names:\n"); + first_inv = 0; + } +} + +ENT * +alloc_ent () +{ + ENT *rv = (ENT *)malloc (sizeof (ENT)); + if (rv == 0) + { + fprintf (stderr, "Unable to allocate memory for an ENT\n"); + exit (1); + } + memset (rv, 0, sizeof (ENT)); + return rv; +} + +void +fill_ent (ent, path) +ENT *ent; +char *path; +{ + char *first = path; + char *null = path+strlen (path); + char *last_slash = strrchr (path, '/'); + char *cp, *dp; + int dots_seen, chars_seen; + + if (last_slash+1 == null) + { + * --null = '\0'; + last_slash = strrchr (path, '/'); + } + + if (!last_slash) + { + last_slash = first-1; + } + + if (null-last_slash < 13) + ent->dos_name = (char *)malloc (null-last_slash); + else + ent->dos_name = (char *)malloc (13); + ent->full_name = (char *)malloc (null-last_slash); + ent->path = (char *)malloc (last_slash-first+1); + + strcpy (ent->full_name, last_slash+1); + if (last_slash > first) + { + strncpy (ent->path, first, last_slash-first); + ent->path[last_slash-first] = '\0'; + } + else + *ent->path = '\0'; + + cp = last_slash+1; + dp = ent->dos_name; + dots_seen = 0; + chars_seen = 0; + while (1) + { + if (! *cp) + break; + switch (*cp) + { + case '.': + if (cp == last_slash+1 && strcmp (last_slash+1, ".")) + { + invalid_msg (); + printf ("%s - file name cannot start with dot\n", path); + *dp = 0; + break; + } + if (dots_seen == 1) + { + invalid_msg (); + printf ("%s - too many dots\n", path); + *dp = '\0'; + break; + } + *dp++ = '.'; + chars_seen = 0; + dots_seen++; + break; + case '"': + case '*': + case '+': + case ',': + case ';': + case '<': + case '=': + case '>': + case '?': + case '[': + case '\\': + case ']': + case '|': + invalid_msg (); + printf ("%s - invalid character `%c'\n", path, *cp); + *dp++ = '?'; + chars_seen++; + break; + default: + if (dots_seen) + { + if (chars_seen >= 3) + break; + } + else + if (chars_seen >= 8) + break; + if ((*cp <= ' ') || (*cp >= 0x7f)) + { + invalid_msg (); + printf ("%s - invalid character `%c'\n", path, *cp); + *dp++ = '?'; + chars_seen++; + break; + } + if (islower (*cp)) + *dp++ = toupper (*cp); + else + *dp++ = *cp; + chars_seen++; + break; + } + cp++; + } + *dp++ = '\0'; +} + +int +compare_ent_dosname (e1, e2) +ENT **e1; +ENT **e2; +{ + int r = strcmp ((*e1)->dos_name, (*e2)->dos_name); + if (r == 0) + r = strcmp ((*e1)->path, (*e2)->path); + if (r == 0) + r = strcmp ((*e1)->full_name, (*e2)->full_name); + return r; +} + +int +compare_ent_fullname (e1, e2) +ENT **e1; +ENT **e2; +{ + int r = strncmp ((*e1)->full_name, (*e2)->full_name, 14); + if (r == 0) + r = strcmp ((*e1)->path, (*e2)->path); + if (r == 0) + r = strcmp ((*e1)->full_name, (*e2)->full_name); + return r; +} + +char * +mpath (ent) +ENT *ent; +{ + static char buf[500]; + if (ent->path && ent->path[0]) + sprintf (buf, "%s/%s", ent->path, ent->full_name); + else + return ent->full_name; + return buf; +} + +/****************************************************************\ + * List handling routines * +\****************************************************************/ + +void +add_ent (ent) +ENT *ent; +{ + ent->next = eroot; + eroot = ent; +} + +void +handle_input (line) +char *line; +{ + ENT *ent = alloc_ent (); + fill_ent (ent, line); + add_ent (ent); +} + +void +display_problems () +{ + ENT **elist, *ent; + int ecount, i, first, first_err; + + for (ecount=0, ent=eroot; ent; ent=ent->next, ecount++); + elist = (ENT **)malloc (sizeof (ENT *) * ecount); + for (ecount=0, ent=eroot; ent; ent=ent->next, ecount++) + elist[ecount] = ent; + + qsort (elist, ecount, sizeof (ENT *), compare_ent_dosname); + + first = 1; + first_err = 1; + for (i=0; idos_name, elist[i+1]->dos_name) == 0) && + (strcmp (elist[i]->path, elist[i+1]->path) == 0)) + { + if (first_err) + { + if (first_msg) + first_msg = 0; + else + putchar ('\n'); + printf ("The following resolve to the same DOS file names:\n"); + first_err = 0; + } + if (first) + { + printf ("%14s : %s\n", elist[i]->dos_name, mpath (elist[i])); + first = 0; + } + printf ("\t\t %s\n", mpath (elist[i+1])); + } + else + first = 1; + } + + qsort (elist, ecount, sizeof (ENT *), compare_ent_fullname); + + first = 1; + first_err = 1; + for (i=0; ifull_name, elist[i+1]->full_name, 14) == 0) && + (strcmp (elist[i]->path, elist[i+1]->path) == 0)) + { + if (first_err) + { + if (first_msg) + first_msg = 0; + else + putchar ('\n'); + printf ("The following resolve to the same SysV file names:\n"); + first_err = 0; + } + if (first) + { + printf ("%.14s : %s\n", elist[i]->full_name, mpath (elist[i])); + first = 0; + elist[i]->tagged = 1; + } + printf ("\t\t %s\n", mpath (elist[i+1])); + elist[i+1]->tagged = 1; + } + else + first = 1; + } + + first_err = 1; + for (i=0; ifull_name) > 14) && !elist[i]->tagged) + { + if (first_err) + { + if (first_msg) + first_msg = 0; + else + putchar ('\n'); + printf ("The following file names are too long for SysV:\n"); + first_err = 0; + } + printf ("%.14s : %s\n", elist[i]->full_name, mpath (elist[i])); + } + } +} + +/****************************************************************\ + * Main entry point * +\****************************************************************/ + +main (argc, argv) +int argc; +char **argv; +{ + FILE *input = stdin; + if (argc > 1) + { + input = fopen (argv[1], "r"); + if (!input) + { + perror (argv[1]); + exit (1); + } + } + while (1) + { + char line[500]; + char *lp; + fgets (line, 500, input); + if (feof (input)) + break; + lp = line+strlen (line); + while ((lp != line) && (*lp <= ' ')) + lp--; + lp[1] = 0; + handle_input (line); + } + display_problems (); +} + diff --git a/contrib/gcc/dostage2 b/contrib/gcc/dostage2 new file mode 100755 index 00000000000..bb33f7dc27e --- /dev/null +++ b/contrib/gcc/dostage2 @@ -0,0 +1,2 @@ +#!/bin/sh +make -k LANGUAGES=c $1 CC=stage1/xgcc XCFLAGS=-Bstage1/ CFLAGS="-g $2" >log2 2>&1 diff --git a/contrib/gcc/dostage3 b/contrib/gcc/dostage3 new file mode 100755 index 00000000000..21f17fc11c7 --- /dev/null +++ b/contrib/gcc/dostage3 @@ -0,0 +1,3 @@ +#!/bin/sh +make -k LANGUAGES=c $1 CC=stage2/xgcc XCFLAGS=-Bstage2/ CFLAGS="-g $2" >log3 2>&1 + diff --git a/contrib/gcc/dwarf.h b/contrib/gcc/dwarf.h new file mode 100644 index 00000000000..014a4fc48b8 --- /dev/null +++ b/contrib/gcc/dwarf.h @@ -0,0 +1,311 @@ +/* Declarations and definitions of codes relating to the DWARF symbolic + debugging information format. + + Written by Ron Guilmette (rfg@netcom.com) + +Copyright (C) 1992 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This file is derived from the DWARF specification (a public document) + Revision 1.0.1 (April 8, 1992) developed by the UNIX International + Programming Languages Special Interest Group (UI/PLSIG) and distributed + by UNIX International. Copies of this specification are available from + UNIX International, 20 Waterview Boulevard, Parsippany, NJ, 07054. +*/ + +/* Tag names and codes. */ + +enum dwarf_tag { + TAG_padding = 0x0000, + TAG_array_type = 0x0001, + TAG_class_type = 0x0002, + TAG_entry_point = 0x0003, + TAG_enumeration_type = 0x0004, + TAG_formal_parameter = 0x0005, + TAG_global_subroutine = 0x0006, + TAG_global_variable = 0x0007, + /* 0x0008 -- reserved */ + /* 0x0009 -- reserved */ + TAG_label = 0x000a, + TAG_lexical_block = 0x000b, + TAG_local_variable = 0x000c, + TAG_member = 0x000d, + /* 0x000e -- reserved */ + TAG_pointer_type = 0x000f, + TAG_reference_type = 0x0010, + TAG_compile_unit = 0x0011, + TAG_string_type = 0x0012, + TAG_structure_type = 0x0013, + TAG_subroutine = 0x0014, + TAG_subroutine_type = 0x0015, + TAG_typedef = 0x0016, + TAG_union_type = 0x0017, + TAG_unspecified_parameters = 0x0018, + TAG_variant = 0x0019, + TAG_common_block = 0x001a, + TAG_common_inclusion = 0x001b, + TAG_inheritance = 0x001c, + TAG_inlined_subroutine = 0x001d, + TAG_module = 0x001e, + TAG_ptr_to_member_type = 0x001f, + TAG_set_type = 0x0020, + TAG_subrange_type = 0x0021, + TAG_with_stmt = 0x0022, + + /* GNU extensions */ + + TAG_format_label = 0x8000, /* for FORTRAN 77 and Fortran 90 */ + TAG_namelist = 0x8001, /* For Fortran 90 */ + TAG_function_template = 0x8002, /* for C++ */ + TAG_class_template = 0x8003 /* for C++ */ +}; + +#define TAG_lo_user 0x8000 /* implementation-defined range start */ +#define TAG_hi_user 0xffff /* implementation-defined range end */ +#define TAG_source_file TAG_compile_unit /* for backward compatibility */ + +/* Form names and codes. */ + +enum dwarf_form { + FORM_ADDR = 0x1, + FORM_REF = 0x2, + FORM_BLOCK2 = 0x3, + FORM_BLOCK4 = 0x4, + FORM_DATA2 = 0x5, + FORM_DATA4 = 0x6, + FORM_DATA8 = 0x7, + FORM_STRING = 0x8 +}; + +/* Attribute names and codes. */ + +enum dwarf_attribute { + AT_sibling = (0x0010|FORM_REF), + AT_location = (0x0020|FORM_BLOCK2), + AT_name = (0x0030|FORM_STRING), + AT_fund_type = (0x0050|FORM_DATA2), + AT_mod_fund_type = (0x0060|FORM_BLOCK2), + AT_user_def_type = (0x0070|FORM_REF), + AT_mod_u_d_type = (0x0080|FORM_BLOCK2), + AT_ordering = (0x0090|FORM_DATA2), + AT_subscr_data = (0x00a0|FORM_BLOCK2), + AT_byte_size = (0x00b0|FORM_DATA4), + AT_bit_offset = (0x00c0|FORM_DATA2), + AT_bit_size = (0x00d0|FORM_DATA4), + /* (0x00e0|FORM_xxxx) -- reserved */ + AT_element_list = (0x00f0|FORM_BLOCK4), + AT_stmt_list = (0x0100|FORM_DATA4), + AT_low_pc = (0x0110|FORM_ADDR), + AT_high_pc = (0x0120|FORM_ADDR), + AT_language = (0x0130|FORM_DATA4), + AT_member = (0x0140|FORM_REF), + AT_discr = (0x0150|FORM_REF), + AT_discr_value = (0x0160|FORM_BLOCK2), + /* (0x0170|FORM_xxxx) -- reserved */ + /* (0x0180|FORM_xxxx) -- reserved */ + AT_string_length = (0x0190|FORM_BLOCK2), + AT_common_reference = (0x01a0|FORM_REF), + AT_comp_dir = (0x01b0|FORM_STRING), + AT_const_value_string = (0x01c0|FORM_STRING), + AT_const_value_data2 = (0x01c0|FORM_DATA2), + AT_const_value_data4 = (0x01c0|FORM_DATA4), + AT_const_value_data8 = (0x01c0|FORM_DATA8), + AT_const_value_block2 = (0x01c0|FORM_BLOCK2), + AT_const_value_block4 = (0x01c0|FORM_BLOCK4), + AT_containing_type = (0x01d0|FORM_REF), + AT_default_value_addr = (0x01e0|FORM_ADDR), + AT_default_value_data2 = (0x01e0|FORM_DATA2), + AT_default_value_data4 = (0x01e0|FORM_DATA4), + AT_default_value_data8 = (0x01e0|FORM_DATA8), + AT_default_value_string = (0x01e0|FORM_STRING), + AT_friends = (0x01f0|FORM_BLOCK2), + AT_inline = (0x0200|FORM_STRING), + AT_is_optional = (0x0210|FORM_STRING), + AT_lower_bound_ref = (0x0220|FORM_REF), + AT_lower_bound_data2 = (0x0220|FORM_DATA2), + AT_lower_bound_data4 = (0x0220|FORM_DATA4), + AT_lower_bound_data8 = (0x0220|FORM_DATA8), + AT_private = (0x0240|FORM_STRING), + AT_producer = (0x0250|FORM_STRING), + AT_program = (0x0230|FORM_STRING), + AT_protected = (0x0260|FORM_STRING), + AT_prototyped = (0x0270|FORM_STRING), + AT_public = (0x0280|FORM_STRING), + AT_pure_virtual = (0x0290|FORM_STRING), + AT_return_addr = (0x02a0|FORM_BLOCK2), + AT_abstract_origin = (0x02b0|FORM_REF), + AT_start_scope = (0x02c0|FORM_DATA4), + AT_stride_size = (0x02e0|FORM_DATA4), + AT_upper_bound_ref = (0x02f0|FORM_REF), + AT_upper_bound_data2 = (0x02f0|FORM_DATA2), + AT_upper_bound_data4 = (0x02f0|FORM_DATA4), + AT_upper_bound_data8 = (0x02f0|FORM_DATA8), + AT_virtual = (0x0300|FORM_STRING), + + /* GNU extensions. */ + + AT_sf_names = (0x8000|FORM_DATA4), + AT_src_info = (0x8010|FORM_DATA4), + AT_mac_info = (0x8020|FORM_DATA4), + AT_src_coords = (0x8030|FORM_DATA4), + AT_body_begin = (0x8040|FORM_ADDR), + AT_body_end = (0x8050|FORM_ADDR) +}; + +#define AT_lo_user 0x2000 /* implementation-defined range start */ +#define AT_hi_user 0x3ff0 /* implementation-defined range end */ + +/* Location atom names and codes. */ + +enum dwarf_location_atom { + OP_REG = 0x01, + OP_BASEREG = 0x02, + OP_ADDR = 0x03, + OP_CONST = 0x04, + OP_DEREF2 = 0x05, + OP_DEREF4 = 0x06, + OP_ADD = 0x07 +}; + +#define OP_LO_USER 0x80 /* implementation-defined range start */ +#define OP_HI_USER 0xff /* implementation-defined range end */ + +/* Fundamental type names and codes. */ + +enum dwarf_fundamental_type { + FT_char = 0x0001, + FT_signed_char = 0x0002, + FT_unsigned_char = 0x0003, + FT_short = 0x0004, + FT_signed_short = 0x0005, + FT_unsigned_short = 0x0006, + FT_integer = 0x0007, + FT_signed_integer = 0x0008, + FT_unsigned_integer = 0x0009, + FT_long = 0x000a, + FT_signed_long = 0x000b, + FT_unsigned_long = 0x000c, + FT_pointer = 0x000d, /* an alias for (void *) */ + FT_float = 0x000e, + FT_dbl_prec_float = 0x000f, + FT_ext_prec_float = 0x0010, /* breaks "classic" svr4 SDB */ + FT_complex = 0x0011, /* breaks "classic" svr4 SDB */ + FT_dbl_prec_complex = 0x0012, /* breaks "classic" svr4 SDB */ + /* 0x0013 -- reserved */ + FT_void = 0x0014, + FT_boolean = 0x0015, /* breaks "classic" svr4 SDB */ + FT_ext_prec_complex = 0x0016, /* breaks "classic" svr4 SDB */ + FT_label = 0x0017, + + /* GNU extensions + The low order byte must indicate the size (in bytes) for the type. + All of these types will probably break "classic" svr4 SDB */ + + FT_long_long = 0x8008, + FT_signed_long_long = 0x8108, + FT_unsigned_long_long = 0x8208, + + FT_int8 = 0x9001, + FT_signed_int8 = 0x9101, + FT_unsigned_int8 = 0x9201, + FT_int16 = 0x9302, + FT_signed_int16 = 0x9402, + FT_unsigned_int16 = 0x9502, + FT_int32 = 0x9604, + FT_signed_int32 = 0x9704, + FT_unsigned_int32 = 0x9804, + FT_int64 = 0x9908, + FT_signed_int64 = 0x9a08, + FT_unsigned_int64 = 0x9b08, + + FT_real32 = 0xa004, + FT_real64 = 0xa108, + FT_real96 = 0xa20c, + FT_real128 = 0xa310 +}; + +#define FT_lo_user 0x8000 /* implementation-defined range start */ +#define FT_hi_user 0xffff /* implementation defined range end */ + +/* Type modifier names and codes. */ + +enum dwarf_type_modifier { + MOD_pointer_to = 0x01, + MOD_reference_to = 0x02, + MOD_const = 0x03, + MOD_volatile = 0x04 +}; + +#define MOD_lo_user 0x80 /* implementation-defined range start */ +#define MOD_hi_user 0xff /* implementation-defined range end */ + +/* Array ordering names and codes. */ + +enum dwarf_array_dim_ordering { + ORD_row_major = 0, + ORD_col_major = 1 +}; + +/* Array subscript format names and codes. */ + +enum dwarf_subscr_data_formats { + FMT_FT_C_C = 0x0, + FMT_FT_C_X = 0x1, + FMT_FT_X_C = 0x2, + FMT_FT_X_X = 0x3, + FMT_UT_C_C = 0x4, + FMT_UT_C_X = 0x5, + FMT_UT_X_C = 0x6, + FMT_UT_X_X = 0x7, + FMT_ET = 0x8 +}; + +/* Derived from above for ease of use. */ + +#define FMT_CODE(_FUNDAMENTAL_TYPE_P, _UB_CONST_P, _LB_CONST_P) \ + (((_FUNDAMENTAL_TYPE_P) ? 0 : 4) \ + | ((_UB_CONST_P) ? 0 : 2) \ + | ((_LB_CONST_P) ? 0 : 1)) + +/* Source language names and codes. */ + +enum dwarf_source_language { + LANG_C89 = 0x00000001, + LANG_C = 0x00000002, + LANG_ADA83 = 0x00000003, + LANG_C_PLUS_PLUS = 0x00000004, + LANG_COBOL74 = 0x00000005, + LANG_COBOL85 = 0x00000006, + LANG_FORTRAN77 = 0x00000007, + LANG_FORTRAN90 = 0x00000008, + LANG_PASCAL83 = 0x00000009, + LANG_MODULA2 = 0x0000000a +}; + +#define LANG_lo_user 0x00008000 /* implementation-defined range start */ +#define LANG_hi_user 0x0000ffff /* implementation-defined range end */ + +/* Names and codes for GNU "macinfo" extension. */ + +enum dwarf_macinfo_record_type { + MACINFO_start = 's', + MACINFO_resume = 'r', + MACINFO_define = 'd', + MACINFO_undef = 'u' +}; diff --git a/contrib/gcc/dwarfout.c b/contrib/gcc/dwarfout.c new file mode 100644 index 00000000000..b484e5a9eb2 --- /dev/null +++ b/contrib/gcc/dwarfout.c @@ -0,0 +1,5651 @@ +/* Output Dwarf format symbol table information from the GNU C compiler. + Copyright (C) 1992, 1993, 1995 Free Software Foundation, Inc. + + Written by Ron Guilmette (rfg@netcom.com) for + Network Computing Devices, August, September, October, November 1990. + Generously contributed by NCD to the Free Software Foundation. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#include "config.h" + +#ifdef DWARF_DEBUGGING_INFO +#include +#include "dwarf.h" +#include "tree.h" +#include "flags.h" +#include "rtl.h" +#include "hard-reg-set.h" +#include "insn-config.h" +#include "reload.h" +#include "output.h" +#include "defaults.h" + +#ifndef DWARF_VERSION +#define DWARF_VERSION 1 +#endif + +/* #define NDEBUG 1 */ +#include "assert.h" + +#if defined(DWARF_TIMESTAMPS) +#if defined(POSIX) +#include +#else /* !defined(POSIX) */ +#include +#if defined(__STDC__) +extern time_t time (time_t *); +#else /* !defined(__STDC__) */ +extern time_t time (); +#endif /* !defined(__STDC__) */ +#endif /* !defined(POSIX) */ +#endif /* defined(DWARF_TIMESTAMPS) */ + +extern char *getpwd (); + +extern char *index (); +extern char *rindex (); + +/* IMPORTANT NOTE: Please see the file README.DWARF for important details + regarding the GNU implementation of Dwarf. */ + +/* NOTE: In the comments in this file, many references are made to + so called "Debugging Information Entries". For the sake of brevity, + this term is abbreviated to `DIE' throughout the remainder of this + file. */ + +/* Note that the implementation of C++ support herein is (as yet) unfinished. + If you want to try to complete it, more power to you. */ + +#if defined(__GNUC__) && (NDEBUG == 1) +#define inline static inline +#else +#define inline static +#endif + +/* How to start an assembler comment. */ +#ifndef ASM_COMMENT_START +#define ASM_COMMENT_START ";#" +#endif + +/* How to print out a register name. */ +#ifndef PRINT_REG +#define PRINT_REG(RTX, CODE, FILE) \ + fprintf ((FILE), "%s", reg_names[REGNO (RTX)]) +#endif + +/* Define a macro which returns non-zero for any tagged type which is + used (directly or indirectly) in the specification of either some + function's return type or some formal parameter of some function. + We use this macro when we are operating in "terse" mode to help us + know what tagged types have to be represented in Dwarf (even in + terse mode) and which ones don't. + + A flag bit with this meaning really should be a part of the normal + GCC ..._TYPE nodes, but at the moment, there is no such bit defined + for these nodes. For now, we have to just fake it. It it safe for + us to simply return zero for all complete tagged types (which will + get forced out anyway if they were used in the specification of some + formal or return type) and non-zero for all incomplete tagged types. +*/ + +#define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) + +extern int flag_traditional; +extern char *version_string; +extern char *language_string; + +/* Maximum size (in bytes) of an artificially generated label. */ + +#define MAX_ARTIFICIAL_LABEL_BYTES 30 + +/* Make sure we know the sizes of the various types dwarf can describe. + These are only defaults. If the sizes are different for your target, + you should override these values by defining the appropriate symbols + in your tm.h file. */ + +#ifndef CHAR_TYPE_SIZE +#define CHAR_TYPE_SIZE BITS_PER_UNIT +#endif + +#ifndef SHORT_TYPE_SIZE +#define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) +#endif + +#ifndef INT_TYPE_SIZE +#define INT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_TYPE_SIZE +#define LONG_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef LONG_LONG_TYPE_SIZE +#define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef WCHAR_TYPE_SIZE +#define WCHAR_TYPE_SIZE INT_TYPE_SIZE +#endif + +#ifndef WCHAR_UNSIGNED +#define WCHAR_UNSIGNED 0 +#endif + +#ifndef FLOAT_TYPE_SIZE +#define FLOAT_TYPE_SIZE BITS_PER_WORD +#endif + +#ifndef DOUBLE_TYPE_SIZE +#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +#ifndef LONG_DOUBLE_TYPE_SIZE +#define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) +#endif + +/* Structure to keep track of source filenames. */ + +struct filename_entry { + unsigned number; + char * name; +}; + +typedef struct filename_entry filename_entry; + +/* Pointer to an array of elements, each one having the structure above. */ + +static filename_entry *filename_table; + +/* Total number of entries in the table (i.e. array) pointed to by + `filename_table'. This is the *total* and includes both used and + unused slots. */ + +static unsigned ft_entries_allocated; + +/* Number of entries in the filename_table which are actually in use. */ + +static unsigned ft_entries; + +/* Size (in elements) of increments by which we may expand the filename + table. Actually, a single hunk of space of this size should be enough + for most typical programs. */ + +#define FT_ENTRIES_INCREMENT 64 + +/* Local pointer to the name of the main input file. Initialized in + dwarfout_init. */ + +static char *primary_filename; + +/* Pointer to the most recent filename for which we produced some line info. */ + +static char *last_filename; + +/* For Dwarf output, we must assign lexical-blocks id numbers + in the order in which their beginnings are encountered. + We output Dwarf debugging info that refers to the beginnings + and ends of the ranges of code for each lexical block with + assembler labels ..Bn and ..Bn.e, where n is the block number. + The labels themselves are generated in final.c, which assigns + numbers to the blocks in the same way. */ + +static unsigned next_block_number = 2; + +/* Counter to generate unique names for DIEs. */ + +static unsigned next_unused_dienum = 1; + +/* Number of the DIE which is currently being generated. */ + +static unsigned current_dienum; + +/* Number to use for the special "pubname" label on the next DIE which + represents a function or data object defined in this compilation + unit which has "extern" linkage. */ + +static next_pubname_number = 0; + +#define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1] + +/* Pointer to a dynamically allocated list of pre-reserved and still + pending sibling DIE numbers. Note that this list will grow as needed. */ + +static unsigned *pending_sibling_stack; + +/* Counter to keep track of the number of pre-reserved and still pending + sibling DIE numbers. */ + +static unsigned pending_siblings; + +/* The currently allocated size of the above list (expressed in number of + list elements). */ + +static unsigned pending_siblings_allocated; + +/* Size (in elements) of increments by which we may expand the pending + sibling stack. Actually, a single hunk of space of this size should + be enough for most typical programs. */ + +#define PENDING_SIBLINGS_INCREMENT 64 + +/* Non-zero if we are performing our file-scope finalization pass and if + we should force out Dwarf descriptions of any and all file-scope + tagged types which are still incomplete types. */ + +static int finalizing = 0; + +/* A pointer to the base of a list of pending types which we haven't + generated DIEs for yet, but which we will have to come back to + later on. */ + +static tree *pending_types_list; + +/* Number of elements currently allocated for the pending_types_list. */ + +static unsigned pending_types_allocated; + +/* Number of elements of pending_types_list currently in use. */ + +static unsigned pending_types; + +/* Size (in elements) of increments by which we may expand the pending + types list. Actually, a single hunk of space of this size should + be enough for most typical programs. */ + +#define PENDING_TYPES_INCREMENT 64 + +/* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init. + This is used in a hack to help us get the DIEs describing types of + formal parameters to come *after* all of the DIEs describing the formal + parameters themselves. That's necessary in order to be compatible + with what the brain-damaged svr4 SDB debugger requires. */ + +static tree fake_containing_scope; + +/* The number of the current function definition that we are generating + debugging information for. These numbers range from 1 up to the maximum + number of function definitions contained within the current compilation + unit. These numbers are used to create unique labels for various things + contained within various function definitions. */ + +static unsigned current_funcdef_number = 1; + +/* A pointer to the ..._DECL node which we have most recently been working + on. We keep this around just in case something about it looks screwy + and we want to tell the user what the source coordinates for the actual + declaration are. */ + +static tree dwarf_last_decl; + +/* Forward declarations for functions defined in this file. */ + +static void output_type (); +static void type_attribute (); +static void output_decls_for_scope (); +static void output_decl (); +static unsigned lookup_filename (); + +/* Definitions of defaults for assembler-dependent names of various + pseudo-ops and section names. + + Theses may be overridden in your tm.h file (if necessary) for your + particular assembler. The default values provided here correspond to + what is expected by "standard" AT&T System V.4 assemblers. */ + +#ifndef FILE_ASM_OP +#define FILE_ASM_OP ".file" +#endif +#ifndef VERSION_ASM_OP +#define VERSION_ASM_OP ".version" +#endif +#ifndef UNALIGNED_SHORT_ASM_OP +#define UNALIGNED_SHORT_ASM_OP ".2byte" +#endif +#ifndef UNALIGNED_INT_ASM_OP +#define UNALIGNED_INT_ASM_OP ".4byte" +#endif +#ifndef ASM_BYTE_OP +#define ASM_BYTE_OP ".byte" +#endif +#ifndef SET_ASM_OP +#define SET_ASM_OP ".set" +#endif + +/* Pseudo-ops for pushing the current section onto the section stack (and + simultaneously changing to a new section) and for poping back to the + section we were in immediately before this one. Note that most svr4 + assemblers only maintain a one level stack... you can push all the + sections you want, but you can only pop out one level. (The sparc + svr4 assembler is an exception to this general rule.) That's + OK because we only use at most one level of the section stack herein. */ + +#ifndef PUSHSECTION_ASM_OP +#define PUSHSECTION_ASM_OP ".section" +#endif +#ifndef POPSECTION_ASM_OP +#define POPSECTION_ASM_OP ".previous" +#endif + +/* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below) + to print the PUSHSECTION_ASM_OP and the section name. The default here + works for almost all svr4 assemblers, except for the sparc, where the + section name must be enclosed in double quotes. (See sparcv4.h.) */ + +#ifndef PUSHSECTION_FORMAT +#define PUSHSECTION_FORMAT "\t%s\t%s\n" +#endif + +#ifndef DEBUG_SECTION +#define DEBUG_SECTION ".debug" +#endif +#ifndef LINE_SECTION +#define LINE_SECTION ".line" +#endif +#ifndef SFNAMES_SECTION +#define SFNAMES_SECTION ".debug_sfnames" +#endif +#ifndef SRCINFO_SECTION +#define SRCINFO_SECTION ".debug_srcinfo" +#endif +#ifndef MACINFO_SECTION +#define MACINFO_SECTION ".debug_macinfo" +#endif +#ifndef PUBNAMES_SECTION +#define PUBNAMES_SECTION ".debug_pubnames" +#endif +#ifndef ARANGES_SECTION +#define ARANGES_SECTION ".debug_aranges" +#endif +#ifndef TEXT_SECTION +#define TEXT_SECTION ".text" +#endif +#ifndef DATA_SECTION +#define DATA_SECTION ".data" +#endif +#ifndef DATA1_SECTION +#define DATA1_SECTION ".data1" +#endif +#ifndef RODATA_SECTION +#define RODATA_SECTION ".rodata" +#endif +#ifndef RODATA1_SECTION +#define RODATA1_SECTION ".rodata1" +#endif +#ifndef BSS_SECTION +#define BSS_SECTION ".bss" +#endif + +/* Definitions of defaults for formats and names of various special + (artificial) labels which may be generated within this file (when + the -g options is used and DWARF_DEBUGGING_INFO is in effect. + + If necessary, these may be overridden from within your tm.h file, + but typically, you should never need to override these. + + These labels have been hacked (temporarily) so that they all begin with + a `.L' sequence so as to appease the stock sparc/svr4 assembler and the + stock m88k/svr4 assembler, both of which need to see .L at the start of + a label in order to prevent that label from going into the linker symbol + table). When I get time, I'll have to fix this the right way so that we + will use ASM_GENERATE_INTERNAL_LABEL and ASM_OUTPUT_INTERNAL_LABEL herein, + but that will require a rather massive set of changes. For the moment, + the following definitions out to produce the right results for all svr4 + and svr3 assemblers. -- rfg +*/ + +#ifndef TEXT_BEGIN_LABEL +#define TEXT_BEGIN_LABEL ".L_text_b" +#endif +#ifndef TEXT_END_LABEL +#define TEXT_END_LABEL ".L_text_e" +#endif + +#ifndef DATA_BEGIN_LABEL +#define DATA_BEGIN_LABEL ".L_data_b" +#endif +#ifndef DATA_END_LABEL +#define DATA_END_LABEL ".L_data_e" +#endif + +#ifndef DATA1_BEGIN_LABEL +#define DATA1_BEGIN_LABEL ".L_data1_b" +#endif +#ifndef DATA1_END_LABEL +#define DATA1_END_LABEL ".L_data1_e" +#endif + +#ifndef RODATA_BEGIN_LABEL +#define RODATA_BEGIN_LABEL ".L_rodata_b" +#endif +#ifndef RODATA_END_LABEL +#define RODATA_END_LABEL ".L_rodata_e" +#endif + +#ifndef RODATA1_BEGIN_LABEL +#define RODATA1_BEGIN_LABEL ".L_rodata1_b" +#endif +#ifndef RODATA1_END_LABEL +#define RODATA1_END_LABEL ".L_rodata1_e" +#endif + +#ifndef BSS_BEGIN_LABEL +#define BSS_BEGIN_LABEL ".L_bss_b" +#endif +#ifndef BSS_END_LABEL +#define BSS_END_LABEL ".L_bss_e" +#endif + +#ifndef LINE_BEGIN_LABEL +#define LINE_BEGIN_LABEL ".L_line_b" +#endif +#ifndef LINE_LAST_ENTRY_LABEL +#define LINE_LAST_ENTRY_LABEL ".L_line_last" +#endif +#ifndef LINE_END_LABEL +#define LINE_END_LABEL ".L_line_e" +#endif + +#ifndef DEBUG_BEGIN_LABEL +#define DEBUG_BEGIN_LABEL ".L_debug_b" +#endif +#ifndef SFNAMES_BEGIN_LABEL +#define SFNAMES_BEGIN_LABEL ".L_sfnames_b" +#endif +#ifndef SRCINFO_BEGIN_LABEL +#define SRCINFO_BEGIN_LABEL ".L_srcinfo_b" +#endif +#ifndef MACINFO_BEGIN_LABEL +#define MACINFO_BEGIN_LABEL ".L_macinfo_b" +#endif + +#ifndef DIE_BEGIN_LABEL_FMT +#define DIE_BEGIN_LABEL_FMT ".L_D%u" +#endif +#ifndef DIE_END_LABEL_FMT +#define DIE_END_LABEL_FMT ".L_D%u_e" +#endif +#ifndef PUB_DIE_LABEL_FMT +#define PUB_DIE_LABEL_FMT ".L_P%u" +#endif +#ifndef INSN_LABEL_FMT +#define INSN_LABEL_FMT ".L_I%u_%u" +#endif +#ifndef BLOCK_BEGIN_LABEL_FMT +#define BLOCK_BEGIN_LABEL_FMT ".L_B%u" +#endif +#ifndef BLOCK_END_LABEL_FMT +#define BLOCK_END_LABEL_FMT ".L_B%u_e" +#endif +#ifndef SS_BEGIN_LABEL_FMT +#define SS_BEGIN_LABEL_FMT ".L_s%u" +#endif +#ifndef SS_END_LABEL_FMT +#define SS_END_LABEL_FMT ".L_s%u_e" +#endif +#ifndef EE_BEGIN_LABEL_FMT +#define EE_BEGIN_LABEL_FMT ".L_e%u" +#endif +#ifndef EE_END_LABEL_FMT +#define EE_END_LABEL_FMT ".L_e%u_e" +#endif +#ifndef MT_BEGIN_LABEL_FMT +#define MT_BEGIN_LABEL_FMT ".L_t%u" +#endif +#ifndef MT_END_LABEL_FMT +#define MT_END_LABEL_FMT ".L_t%u_e" +#endif +#ifndef LOC_BEGIN_LABEL_FMT +#define LOC_BEGIN_LABEL_FMT ".L_l%u" +#endif +#ifndef LOC_END_LABEL_FMT +#define LOC_END_LABEL_FMT ".L_l%u_e" +#endif +#ifndef BOUND_BEGIN_LABEL_FMT +#define BOUND_BEGIN_LABEL_FMT ".L_b%u_%u_%c" +#endif +#ifndef BOUND_END_LABEL_FMT +#define BOUND_END_LABEL_FMT ".L_b%u_%u_%c_e" +#endif +#ifndef DERIV_BEGIN_LABEL_FMT +#define DERIV_BEGIN_LABEL_FMT ".L_d%u" +#endif +#ifndef DERIV_END_LABEL_FMT +#define DERIV_END_LABEL_FMT ".L_d%u_e" +#endif +#ifndef SL_BEGIN_LABEL_FMT +#define SL_BEGIN_LABEL_FMT ".L_sl%u" +#endif +#ifndef SL_END_LABEL_FMT +#define SL_END_LABEL_FMT ".L_sl%u_e" +#endif +#ifndef BODY_BEGIN_LABEL_FMT +#define BODY_BEGIN_LABEL_FMT ".L_b%u" +#endif +#ifndef BODY_END_LABEL_FMT +#define BODY_END_LABEL_FMT ".L_b%u_e" +#endif +#ifndef FUNC_END_LABEL_FMT +#define FUNC_END_LABEL_FMT ".L_f%u_e" +#endif +#ifndef TYPE_NAME_FMT +#define TYPE_NAME_FMT ".L_T%u" +#endif +#ifndef DECL_NAME_FMT +#define DECL_NAME_FMT ".L_E%u" +#endif +#ifndef LINE_CODE_LABEL_FMT +#define LINE_CODE_LABEL_FMT ".L_LC%u" +#endif +#ifndef SFNAMES_ENTRY_LABEL_FMT +#define SFNAMES_ENTRY_LABEL_FMT ".L_F%u" +#endif +#ifndef LINE_ENTRY_LABEL_FMT +#define LINE_ENTRY_LABEL_FMT ".L_LE%u" +#endif + +/* Definitions of defaults for various types of primitive assembly language + output operations. + + If necessary, these may be overridden from within your tm.h file, + but typically, you shouldn't need to override these. */ + +#ifndef ASM_OUTPUT_PUSH_SECTION +#define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \ + fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION) +#endif + +#ifndef ASM_OUTPUT_POP_SECTION +#define ASM_OUTPUT_POP_SECTION(FILE) \ + fprintf ((FILE), "\t%s\n", POPSECTION_ASM_OP) +#endif + +#ifndef ASM_OUTPUT_SOURCE_FILENAME +#define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \ + do { fprintf (FILE, "\t%s\t", FILE_ASM_OP); \ + output_quoted_string (FILE, NAME); \ + fputc ('\n', FILE); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_DELTA2 +#define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ + do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ + assemble_name (FILE, LABEL1); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, LABEL2); \ + fprintf (FILE, "\n"); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_DELTA4 +#define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ + do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ + assemble_name (FILE, LABEL1); \ + fprintf (FILE, "-"); \ + assemble_name (FILE, LABEL2); \ + fprintf (FILE, "\n"); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_TAG +#define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", \ + UNALIGNED_SHORT_ASM_OP, (unsigned) TAG); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_tag_name (TAG)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_ATTRIBUTE +#define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", \ + UNALIGNED_SHORT_ASM_OP, (unsigned) ATTR); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_attr_name (ATTR)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_STACK_OP +#define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) OP); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_stack_op_name (OP)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_FUND_TYPE +#define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", \ + UNALIGNED_SHORT_ASM_OP, (unsigned) FT); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_fund_type_name (FT)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_FMT_BYTE +#define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) FMT); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_fmt_byte_name (FMT)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER +#define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \ + do { \ + fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) MOD); \ + if (flag_verbose_asm) \ + fprintf ((FILE), "\t%s %s", \ + ASM_COMMENT_START, dwarf_typemod_name (MOD)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_ADDR +#define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ + do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ + assemble_name (FILE, LABEL); \ + fprintf (FILE, "\n"); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_ADDR_CONST +#define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ + do { \ + fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ + output_addr_const ((FILE), (RTX)); \ + fputc ('\n', (FILE)); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_REF +#define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \ + do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ + assemble_name (FILE, LABEL); \ + fprintf (FILE, "\n"); \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_DATA1 +#define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ + fprintf ((FILE), "\t%s\t0x%x\n", ASM_BYTE_OP, VALUE) +#endif + +#ifndef ASM_OUTPUT_DWARF_DATA2 +#define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) +#endif + +#ifndef ASM_OUTPUT_DWARF_DATA4 +#define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) +#endif + +#ifndef ASM_OUTPUT_DWARF_DATA8 +#define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ + do { \ + if (WORDS_BIG_ENDIAN) \ + { \ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ + } \ + else \ + { \ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ + fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ + } \ + } while (0) +#endif + +#ifndef ASM_OUTPUT_DWARF_STRING +#define ASM_OUTPUT_DWARF_STRING(FILE,P) \ + ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1) +#endif + +/************************ general utility functions **************************/ + +inline char * +xstrdup (s) + register char *s; +{ + register char *p = (char *) xmalloc (strlen (s) + 1); + + strcpy (p, s); + return p; +} + +inline int +is_pseudo_reg (rtl) + register rtx rtl; +{ + return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) + || ((GET_CODE (rtl) == SUBREG) + && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER))); +} + +inline tree +type_main_variant (type) + register tree type; +{ + type = TYPE_MAIN_VARIANT (type); + + /* There really should be only one main variant among any group of variants + of a given type (and all of the MAIN_VARIANT values for all members of + the group should point to that one type) but sometimes the C front-end + messes this up for array types, so we work around that bug here. */ + + if (TREE_CODE (type) == ARRAY_TYPE) + { + while (type != TYPE_MAIN_VARIANT (type)) + type = TYPE_MAIN_VARIANT (type); + } + + return type; +} + +/* Return non-zero if the given type node represents a tagged type. */ + +inline int +is_tagged_type (type) + register tree type; +{ + register enum tree_code code = TREE_CODE (type); + + return (code == RECORD_TYPE || code == UNION_TYPE + || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); +} + +static char * +dwarf_tag_name (tag) + register unsigned tag; +{ + switch (tag) + { + case TAG_padding: return "TAG_padding"; + case TAG_array_type: return "TAG_array_type"; + case TAG_class_type: return "TAG_class_type"; + case TAG_entry_point: return "TAG_entry_point"; + case TAG_enumeration_type: return "TAG_enumeration_type"; + case TAG_formal_parameter: return "TAG_formal_parameter"; + case TAG_global_subroutine: return "TAG_global_subroutine"; + case TAG_global_variable: return "TAG_global_variable"; + case TAG_label: return "TAG_label"; + case TAG_lexical_block: return "TAG_lexical_block"; + case TAG_local_variable: return "TAG_local_variable"; + case TAG_member: return "TAG_member"; + case TAG_pointer_type: return "TAG_pointer_type"; + case TAG_reference_type: return "TAG_reference_type"; + case TAG_compile_unit: return "TAG_compile_unit"; + case TAG_string_type: return "TAG_string_type"; + case TAG_structure_type: return "TAG_structure_type"; + case TAG_subroutine: return "TAG_subroutine"; + case TAG_subroutine_type: return "TAG_subroutine_type"; + case TAG_typedef: return "TAG_typedef"; + case TAG_union_type: return "TAG_union_type"; + case TAG_unspecified_parameters: return "TAG_unspecified_parameters"; + case TAG_variant: return "TAG_variant"; + case TAG_common_block: return "TAG_common_block"; + case TAG_common_inclusion: return "TAG_common_inclusion"; + case TAG_inheritance: return "TAG_inheritance"; + case TAG_inlined_subroutine: return "TAG_inlined_subroutine"; + case TAG_module: return "TAG_module"; + case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type"; + case TAG_set_type: return "TAG_set_type"; + case TAG_subrange_type: return "TAG_subrange_type"; + case TAG_with_stmt: return "TAG_with_stmt"; + + /* GNU extensions. */ + + case TAG_format_label: return "TAG_format_label"; + case TAG_namelist: return "TAG_namelist"; + case TAG_function_template: return "TAG_function_template"; + case TAG_class_template: return "TAG_class_template"; + + default: return "TAG_"; + } +} + +static char * +dwarf_attr_name (attr) + register unsigned attr; +{ + switch (attr) + { + case AT_sibling: return "AT_sibling"; + case AT_location: return "AT_location"; + case AT_name: return "AT_name"; + case AT_fund_type: return "AT_fund_type"; + case AT_mod_fund_type: return "AT_mod_fund_type"; + case AT_user_def_type: return "AT_user_def_type"; + case AT_mod_u_d_type: return "AT_mod_u_d_type"; + case AT_ordering: return "AT_ordering"; + case AT_subscr_data: return "AT_subscr_data"; + case AT_byte_size: return "AT_byte_size"; + case AT_bit_offset: return "AT_bit_offset"; + case AT_bit_size: return "AT_bit_size"; + case AT_element_list: return "AT_element_list"; + case AT_stmt_list: return "AT_stmt_list"; + case AT_low_pc: return "AT_low_pc"; + case AT_high_pc: return "AT_high_pc"; + case AT_language: return "AT_language"; + case AT_member: return "AT_member"; + case AT_discr: return "AT_discr"; + case AT_discr_value: return "AT_discr_value"; + case AT_string_length: return "AT_string_length"; + case AT_common_reference: return "AT_common_reference"; + case AT_comp_dir: return "AT_comp_dir"; + case AT_const_value_string: return "AT_const_value_string"; + case AT_const_value_data2: return "AT_const_value_data2"; + case AT_const_value_data4: return "AT_const_value_data4"; + case AT_const_value_data8: return "AT_const_value_data8"; + case AT_const_value_block2: return "AT_const_value_block2"; + case AT_const_value_block4: return "AT_const_value_block4"; + case AT_containing_type: return "AT_containing_type"; + case AT_default_value_addr: return "AT_default_value_addr"; + case AT_default_value_data2: return "AT_default_value_data2"; + case AT_default_value_data4: return "AT_default_value_data4"; + case AT_default_value_data8: return "AT_default_value_data8"; + case AT_default_value_string: return "AT_default_value_string"; + case AT_friends: return "AT_friends"; + case AT_inline: return "AT_inline"; + case AT_is_optional: return "AT_is_optional"; + case AT_lower_bound_ref: return "AT_lower_bound_ref"; + case AT_lower_bound_data2: return "AT_lower_bound_data2"; + case AT_lower_bound_data4: return "AT_lower_bound_data4"; + case AT_lower_bound_data8: return "AT_lower_bound_data8"; + case AT_private: return "AT_private"; + case AT_producer: return "AT_producer"; + case AT_program: return "AT_program"; + case AT_protected: return "AT_protected"; + case AT_prototyped: return "AT_prototyped"; + case AT_public: return "AT_public"; + case AT_pure_virtual: return "AT_pure_virtual"; + case AT_return_addr: return "AT_return_addr"; + case AT_abstract_origin: return "AT_abstract_origin"; + case AT_start_scope: return "AT_start_scope"; + case AT_stride_size: return "AT_stride_size"; + case AT_upper_bound_ref: return "AT_upper_bound_ref"; + case AT_upper_bound_data2: return "AT_upper_bound_data2"; + case AT_upper_bound_data4: return "AT_upper_bound_data4"; + case AT_upper_bound_data8: return "AT_upper_bound_data8"; + case AT_virtual: return "AT_virtual"; + + /* GNU extensions */ + + case AT_sf_names: return "AT_sf_names"; + case AT_src_info: return "AT_src_info"; + case AT_mac_info: return "AT_mac_info"; + case AT_src_coords: return "AT_src_coords"; + case AT_body_begin: return "AT_body_begin"; + case AT_body_end: return "AT_body_end"; + + default: return "AT_"; + } +} + +static char * +dwarf_stack_op_name (op) + register unsigned op; +{ + switch (op) + { + case OP_REG: return "OP_REG"; + case OP_BASEREG: return "OP_BASEREG"; + case OP_ADDR: return "OP_ADDR"; + case OP_CONST: return "OP_CONST"; + case OP_DEREF2: return "OP_DEREF2"; + case OP_DEREF4: return "OP_DEREF4"; + case OP_ADD: return "OP_ADD"; + default: return "OP_"; + } +} + +static char * +dwarf_typemod_name (mod) + register unsigned mod; +{ + switch (mod) + { + case MOD_pointer_to: return "MOD_pointer_to"; + case MOD_reference_to: return "MOD_reference_to"; + case MOD_const: return "MOD_const"; + case MOD_volatile: return "MOD_volatile"; + default: return "MOD_"; + } +} + +static char * +dwarf_fmt_byte_name (fmt) + register unsigned fmt; +{ + switch (fmt) + { + case FMT_FT_C_C: return "FMT_FT_C_C"; + case FMT_FT_C_X: return "FMT_FT_C_X"; + case FMT_FT_X_C: return "FMT_FT_X_C"; + case FMT_FT_X_X: return "FMT_FT_X_X"; + case FMT_UT_C_C: return "FMT_UT_C_C"; + case FMT_UT_C_X: return "FMT_UT_C_X"; + case FMT_UT_X_C: return "FMT_UT_X_C"; + case FMT_UT_X_X: return "FMT_UT_X_X"; + case FMT_ET: return "FMT_ET"; + default: return "FMT_"; + } +} +static char * +dwarf_fund_type_name (ft) + register unsigned ft; +{ + switch (ft) + { + case FT_char: return "FT_char"; + case FT_signed_char: return "FT_signed_char"; + case FT_unsigned_char: return "FT_unsigned_char"; + case FT_short: return "FT_short"; + case FT_signed_short: return "FT_signed_short"; + case FT_unsigned_short: return "FT_unsigned_short"; + case FT_integer: return "FT_integer"; + case FT_signed_integer: return "FT_signed_integer"; + case FT_unsigned_integer: return "FT_unsigned_integer"; + case FT_long: return "FT_long"; + case FT_signed_long: return "FT_signed_long"; + case FT_unsigned_long: return "FT_unsigned_long"; + case FT_pointer: return "FT_pointer"; + case FT_float: return "FT_float"; + case FT_dbl_prec_float: return "FT_dbl_prec_float"; + case FT_ext_prec_float: return "FT_ext_prec_float"; + case FT_complex: return "FT_complex"; + case FT_dbl_prec_complex: return "FT_dbl_prec_complex"; + case FT_void: return "FT_void"; + case FT_boolean: return "FT_boolean"; + case FT_ext_prec_complex: return "FT_ext_prec_complex"; + case FT_label: return "FT_label"; + + /* GNU extensions. */ + + case FT_long_long: return "FT_long_long"; + case FT_signed_long_long: return "FT_signed_long_long"; + case FT_unsigned_long_long: return "FT_unsigned_long_long"; + + case FT_int8: return "FT_int8"; + case FT_signed_int8: return "FT_signed_int8"; + case FT_unsigned_int8: return "FT_unsigned_int8"; + case FT_int16: return "FT_int16"; + case FT_signed_int16: return "FT_signed_int16"; + case FT_unsigned_int16: return "FT_unsigned_int16"; + case FT_int32: return "FT_int32"; + case FT_signed_int32: return "FT_signed_int32"; + case FT_unsigned_int32: return "FT_unsigned_int32"; + case FT_int64: return "FT_int64"; + case FT_signed_int64: return "FT_signed_int64"; + case FT_unsigned_int64: return "FT_signed_int64"; + + case FT_real32: return "FT_real32"; + case FT_real64: return "FT_real64"; + case FT_real96: return "FT_real96"; + case FT_real128: return "FT_real128"; + + default: return "FT_"; + } +} + +/* Determine the "ultimate origin" of a decl. The decl may be an + inlined instance of an inlined instance of a decl which is local + to an inline function, so we have to trace all of the way back + through the origin chain to find out what sort of node actually + served as the original seed for the given block. */ + +static tree +decl_ultimate_origin (decl) + register tree decl; +{ + register tree immediate_origin = DECL_ABSTRACT_ORIGIN (decl); + + if (immediate_origin == NULL) + return NULL; + else + { + register tree ret_val; + register tree lookahead = immediate_origin; + + do + { + ret_val = lookahead; + lookahead = DECL_ABSTRACT_ORIGIN (ret_val); + } + while (lookahead != NULL && lookahead != ret_val); + return ret_val; + } +} + +/* Determine the "ultimate origin" of a block. The block may be an + inlined instance of an inlined instance of a block which is local + to an inline function, so we have to trace all of the way back + through the origin chain to find out what sort of node actually + served as the original seed for the given block. */ + +static tree +block_ultimate_origin (block) + register tree block; +{ + register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); + + if (immediate_origin == NULL) + return NULL; + else + { + register tree ret_val; + register tree lookahead = immediate_origin; + + do + { + ret_val = lookahead; + lookahead = (TREE_CODE (ret_val) == BLOCK) + ? BLOCK_ABSTRACT_ORIGIN (ret_val) + : NULL; + } + while (lookahead != NULL && lookahead != ret_val); + return ret_val; + } +} + +static void +output_unsigned_leb128 (value) + register unsigned long value; +{ + register unsigned long orig_value = value; + + do + { + register unsigned byte = (value & 0x7f); + + value >>= 7; + if (value != 0) /* more bytes to follow */ + byte |= 0x80; + fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte); + if (flag_verbose_asm && value == 0) + fprintf (asm_out_file, "\t%s ULEB128 number - value = %u", + ASM_COMMENT_START, orig_value); + fputc ('\n', asm_out_file); + } + while (value != 0); +} + +static void +output_signed_leb128 (value) + register long value; +{ + register long orig_value = value; + register int negative = (value < 0); + register int more; + + do + { + register unsigned byte = (value & 0x7f); + + value >>= 7; + if (negative) + value |= 0xfe000000; /* manually sign extend */ + if (((value == 0) && ((byte & 0x40) == 0)) + || ((value == -1) && ((byte & 0x40) == 1))) + more = 0; + else + { + byte |= 0x80; + more = 1; + } + fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) byte); + if (flag_verbose_asm && more == 0) + fprintf (asm_out_file, "\t%s SLEB128 number - value = %d", + ASM_COMMENT_START, orig_value); + fputc ('\n', asm_out_file); + } + while (more); +} + +/**************** utility functions for attribute functions ******************/ + +/* Given a pointer to a BLOCK node return non-zero if (and only if) the + node in question represents the outermost pair of curly braces (i.e. + the "body block") of a function or method. + + For any BLOCK node representing a "body block" of a function or method, + the BLOCK_SUPERCONTEXT of the node will point to another BLOCK node + which represents the outermost (function) scope for the function or + method (i.e. the one which includes the formal parameters). The + BLOCK_SUPERCONTEXT of *that* node in turn will point to the relevant + FUNCTION_DECL node. +*/ + +inline int +is_body_block (stmt) + register tree stmt; +{ + if (TREE_CODE (stmt) == BLOCK) + { + register tree parent = BLOCK_SUPERCONTEXT (stmt); + + if (TREE_CODE (parent) == BLOCK) + { + register tree grandparent = BLOCK_SUPERCONTEXT (parent); + + if (TREE_CODE (grandparent) == FUNCTION_DECL) + return 1; + } + } + return 0; +} + +/* Given a pointer to a tree node for some type, return a Dwarf fundamental + type code for the given type. + + This routine must only be called for GCC type nodes that correspond to + Dwarf fundamental types. + + The current Dwarf draft specification calls for Dwarf fundamental types + to accurately reflect the fact that a given type was either a "plain" + integral type or an explicitly "signed" integral type. Unfortunately, + we can't always do this, because GCC may already have thrown away the + information about the precise way in which the type was originally + specified, as in: + + typedef signed int my_type; + + struct s { my_type f; }; + + Since we may be stuck here without enought information to do exactly + what is called for in the Dwarf draft specification, we do the best + that we can under the circumstances and always use the "plain" integral + fundamental type codes for int, short, and long types. That's probably + good enough. The additional accuracy called for in the current DWARF + draft specification is probably never even useful in practice. */ + +static int +fundamental_type_code (type) + register tree type; +{ + if (TREE_CODE (type) == ERROR_MARK) + return 0; + + switch (TREE_CODE (type)) + { + case ERROR_MARK: + return FT_void; + + case VOID_TYPE: + return FT_void; + + case INTEGER_TYPE: + /* Carefully distinguish all the standard types of C, + without messing up if the language is not C. + Note that we check only for the names that contain spaces; + other names might occur by coincidence in other languages. */ + if (TYPE_NAME (type) != 0 + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_NAME (TYPE_NAME (type)) != 0 + && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) + { + char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + + if (!strcmp (name, "unsigned char")) + return FT_unsigned_char; + if (!strcmp (name, "signed char")) + return FT_signed_char; + if (!strcmp (name, "unsigned int")) + return FT_unsigned_integer; + if (!strcmp (name, "short int")) + return FT_short; + if (!strcmp (name, "short unsigned int")) + return FT_unsigned_short; + if (!strcmp (name, "long int")) + return FT_long; + if (!strcmp (name, "long unsigned int")) + return FT_unsigned_long; + if (!strcmp (name, "long long int")) + return FT_long_long; /* Not grok'ed by svr4 SDB */ + if (!strcmp (name, "long long unsigned int")) + return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */ + } + + /* Most integer types will be sorted out above, however, for the + sake of special `array index' integer types, the following code + is also provided. */ + + if (TYPE_PRECISION (type) == INT_TYPE_SIZE) + return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer); + + if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) + return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long); + + if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) + return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long); + + if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) + return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short); + + if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) + return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char); + + abort (); + + case REAL_TYPE: + /* Carefully distinguish all the standard types of C, + without messing up if the language is not C. */ + if (TYPE_NAME (type) != 0 + && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + && DECL_NAME (TYPE_NAME (type)) != 0 + && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) + { + char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); + + /* Note that here we can run afowl of a serious bug in "classic" + svr4 SDB debuggers. They don't seem to understand the + FT_ext_prec_float type (even though they should). */ + + if (!strcmp (name, "long double")) + return FT_ext_prec_float; + } + + if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) + return FT_dbl_prec_float; + if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) + return FT_float; + + /* Note that here we can run afowl of a serious bug in "classic" + svr4 SDB debuggers. They don't seem to understand the + FT_ext_prec_float type (even though they should). */ + + if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) + return FT_ext_prec_float; + abort (); + + case COMPLEX_TYPE: + return FT_complex; /* GNU FORTRAN COMPLEX type. */ + + case CHAR_TYPE: + return FT_char; /* GNU Pascal CHAR type. Not used in C. */ + + case BOOLEAN_TYPE: + return FT_boolean; /* GNU FORTRAN BOOLEAN type. */ + + default: + abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ + } + return 0; +} + +/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to + the Dwarf "root" type for the given input type. The Dwarf "root" type + of a given type is generally the same as the given type, except that if + the given type is a pointer or reference type, then the root type of + the given type is the root type of the "basis" type for the pointer or + reference type. (This definition of the "root" type is recursive.) + Also, the root type of a `const' qualified type or a `volatile' + qualified type is the root type of the given type without the + qualifiers. */ + +static tree +root_type (type) + register tree type; +{ + if (TREE_CODE (type) == ERROR_MARK) + return error_mark_node; + + switch (TREE_CODE (type)) + { + case ERROR_MARK: + return error_mark_node; + + case POINTER_TYPE: + case REFERENCE_TYPE: + return type_main_variant (root_type (TREE_TYPE (type))); + + default: + return type_main_variant (type); + } +} + +/* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence + of zero or more Dwarf "type-modifier" bytes applicable to the type. */ + +static void +write_modifier_bytes (type, decl_const, decl_volatile) + register tree type; + register int decl_const; + register int decl_volatile; +{ + if (TREE_CODE (type) == ERROR_MARK) + return; + + if (TYPE_READONLY (type) || decl_const) + ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const); + if (TYPE_VOLATILE (type) || decl_volatile) + ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile); + switch (TREE_CODE (type)) + { + case POINTER_TYPE: + ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to); + write_modifier_bytes (TREE_TYPE (type), 0, 0); + return; + + case REFERENCE_TYPE: + ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to); + write_modifier_bytes (TREE_TYPE (type), 0, 0); + return; + + case ERROR_MARK: + default: + return; + } +} + +/* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the + given input type is a Dwarf "fundamental" type. Otherwise return zero. */ + +inline int +type_is_fundamental (type) + register tree type; +{ + switch (TREE_CODE (type)) + { + case ERROR_MARK: + case VOID_TYPE: + case INTEGER_TYPE: + case REAL_TYPE: + case COMPLEX_TYPE: + case BOOLEAN_TYPE: + case CHAR_TYPE: + return 1; + + case SET_TYPE: + case ARRAY_TYPE: + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + case ENUMERAL_TYPE: + case FUNCTION_TYPE: + case METHOD_TYPE: + case POINTER_TYPE: + case REFERENCE_TYPE: + case FILE_TYPE: + case OFFSET_TYPE: + case LANG_TYPE: + return 0; + + default: + abort (); + } + return 0; +} + +/* Given a pointer to some ..._DECL tree node, generate an assembly language + equate directive which will associate a symbolic name with the current DIE. + + The name used is an artificial label generated from the DECL_UID number + associated with the given decl node. The name it gets equated to is the + symbolic label that we (previously) output at the start of the DIE that + we are currently generating. + + Calling this function while generating some "decl related" form of DIE + makes it possible to later refer to the DIE which represents the given + decl simply by re-generating the symbolic name from the ..._DECL node's + UID number. */ + +static void +equate_decl_number_to_die_number (decl) + register tree decl; +{ + /* In the case where we are generating a DIE for some ..._DECL node + which represents either some inline function declaration or some + entity declared within an inline function declaration/definition, + setup a symbolic name for the current DIE so that we have a name + for this DIE that we can easily refer to later on within + AT_abstract_origin attributes. */ + + char decl_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl)); + sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); + ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label); +} + +/* Given a pointer to some ..._TYPE tree node, generate an assembly language + equate directive which will associate a symbolic name with the current DIE. + + The name used is an artificial label generated from the TYPE_UID number + associated with the given type node. The name it gets equated to is the + symbolic label that we (previously) output at the start of the DIE that + we are currently generating. + + Calling this function while generating some "type related" form of DIE + makes it easy to later refer to the DIE which represents the given type + simply by re-generating the alternative name from the ..._TYPE node's + UID number. */ + +inline void +equate_type_number_to_die_number (type) + register tree type; +{ + char type_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + /* We are generating a DIE to represent the main variant of this type + (i.e the type without any const or volatile qualifiers) so in order + to get the equate to come out right, we need to get the main variant + itself here. */ + + type = type_main_variant (type); + + sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type)); + sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); + ASM_OUTPUT_DEF (asm_out_file, type_label, die_label); +} + +static void +output_reg_number (rtl) + register rtx rtl; +{ + register unsigned regno = REGNO (rtl); + + if (regno >= FIRST_PSEUDO_REGISTER) + { + warning_with_decl (dwarf_last_decl, "internal regno botch: regno = %d\n", + regno); + regno = 0; + } + fprintf (asm_out_file, "\t%s\t0x%x", + UNALIGNED_INT_ASM_OP, DBX_REGISTER_NUMBER (regno)); + if (flag_verbose_asm) + { + fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START); + PRINT_REG (rtl, 0, asm_out_file); + } + fputc ('\n', asm_out_file); +} + +/* The following routine is a nice and simple transducer. It converts the + RTL for a variable or parameter (resident in memory) into an equivalent + Dwarf representation of a mechanism for getting the address of that same + variable onto the top of a hypothetical "address evaluation" stack. + + When creating memory location descriptors, we are effectively trans- + forming the RTL for a memory-resident object into its Dwarf postfix + expression equivalent. This routine just recursively descends an + RTL tree, turning it into Dwarf postfix code as it goes. */ + +static void +output_mem_loc_descriptor (rtl) + register rtx rtl; +{ + /* Note that for a dynamically sized array, the location we will + generate a description of here will be the lowest numbered location + which is actually within the array. That's *not* necessarily the + same as the zeroth element of the array. */ + + switch (GET_CODE (rtl)) + { + case SUBREG: + + /* The case of a subreg may arise when we have a local (register) + variable or a formal (register) parameter which doesn't quite + fill up an entire register. For now, just assume that it is + legitimate to make the Dwarf info refer to the whole register + which contains the given subreg. */ + + rtl = XEXP (rtl, 0); + /* Drop thru. */ + + case REG: + + /* Whenever a register number forms a part of the description of + the method for calculating the (dynamic) address of a memory + resident object, DWARF rules require the register number to + be referred to as a "base register". This distinction is not + based in any way upon what category of register the hardware + believes the given register belongs to. This is strictly + DWARF terminology we're dealing with here. + + Note that in cases where the location of a memory-resident data + object could be expressed as: + + OP_ADD (OP_BASEREG (basereg), OP_CONST (0)) + + the actual DWARF location descriptor that we generate may just + be OP_BASEREG (basereg). This may look deceptively like the + object in question was allocated to a register (rather than + in memory) so DWARF consumers need to be aware of the subtle + distinction between OP_REG and OP_BASEREG. */ + + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG); + output_reg_number (rtl); + break; + + case MEM: + output_mem_loc_descriptor (XEXP (rtl, 0)); + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4); + break; + + case CONST: + case SYMBOL_REF: + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR); + ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); + break; + + case PLUS: + output_mem_loc_descriptor (XEXP (rtl, 0)); + output_mem_loc_descriptor (XEXP (rtl, 1)); + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); + break; + + case CONST_INT: + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl)); + break; + + default: + abort (); + } +} + +/* Output a proper Dwarf location descriptor for a variable or parameter + which is either allocated in a register or in a memory location. For + a register, we just generate an OP_REG and the register number. For a + memory location we provide a Dwarf postfix expression describing how to + generate the (dynamic) address of the object onto the address stack. */ + +static void +output_loc_descriptor (rtl) + register rtx rtl; +{ + switch (GET_CODE (rtl)) + { + case SUBREG: + + /* The case of a subreg may arise when we have a local (register) + variable or a formal (register) parameter which doesn't quite + fill up an entire register. For now, just assume that it is + legitimate to make the Dwarf info refer to the whole register + which contains the given subreg. */ + + rtl = XEXP (rtl, 0); + /* Drop thru. */ + + case REG: + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG); + output_reg_number (rtl); + break; + + case MEM: + output_mem_loc_descriptor (XEXP (rtl, 0)); + break; + + default: + abort (); /* Should never happen */ + } +} + +/* Given a tree node describing an array bound (either lower or upper) + output a representation for that bound. */ + +static void +output_bound_representation (bound, dim_num, u_or_l) + register tree bound; + register unsigned dim_num; /* For multi-dimensional arrays. */ + register char u_or_l; /* Designates upper or lower bound. */ +{ + switch (TREE_CODE (bound)) + { + + case ERROR_MARK: + return; + + /* All fixed-bounds are represented by INTEGER_CST nodes. */ + + case INTEGER_CST: + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, + (unsigned) TREE_INT_CST_LOW (bound)); + break; + + /* Dynamic bounds may be represented by NOP_EXPR nodes containing + SAVE_EXPR nodes. */ + + case NOP_EXPR: + bound = TREE_OPERAND (bound, 0); + /* ... fall thru... */ + + case SAVE_EXPR: + { + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (begin_label, BOUND_BEGIN_LABEL_FMT, + current_dienum, dim_num, u_or_l); + + sprintf (end_label, BOUND_END_LABEL_FMT, + current_dienum, dim_num, u_or_l); + + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* If we are working on a bound for a dynamic dimension in C, + the dynamic dimension in question had better have a static + (zero) lower bound and a dynamic *upper* bound. */ + + if (u_or_l != 'u') + abort (); + + /* If optimization is turned on, the SAVE_EXPRs that describe + how to access the upper bound values are essentially bogus. + They only describe (at best) how to get at these values at + the points in the generated code right after they have just + been computed. Worse yet, in the typical case, the upper + bound values will not even *be* computed in the optimized + code, so these SAVE_EXPRs are entirely bogus. + + In order to compensate for this fact, we check here to see + if optimization is enabled, and if so, we effectively create + an empty location description for the (unknown and unknowable) + upper bound. + + This should not cause too much trouble for existing (stupid?) + debuggers because they have to deal with empty upper bounds + location descriptions anyway in order to be able to deal with + incomplete array types. + + Of course an intelligent debugger (GDB?) should be able to + comprehend that a missing upper bound specification in a + array type used for a storage class `auto' local array variable + indicates that the upper bound is both unknown (at compile- + time) and unknowable (at run-time) due to optimization. + */ + + if (! optimize) + output_loc_descriptor + (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX)); + + ASM_OUTPUT_LABEL (asm_out_file, end_label); + } + break; + + default: + abort (); + } +} + +/* Recursive function to output a sequence of value/name pairs for + enumeration constants in reversed order. This is called from + enumeration_type_die. */ + +static void +output_enumeral_list (link) + register tree link; +{ + if (link) + { + output_enumeral_list (TREE_CHAIN (link)); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, + (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); + ASM_OUTPUT_DWARF_STRING (asm_out_file, + IDENTIFIER_POINTER (TREE_PURPOSE (link))); + } +} + +/* Given an unsigned value, round it up to the lowest multiple of `boundary' + which is not less than the value itself. */ + +inline unsigned +ceiling (value, boundary) + register unsigned value; + register unsigned boundary; +{ + return (((value + boundary - 1) / boundary) * boundary); +} + +/* Given a pointer to what is assumed to be a FIELD_DECL node, return a + pointer to the declared type for the relevant field variable, or return + `integer_type_node' if the given node turns out to be an ERROR_MARK node. */ + +inline tree +field_type (decl) + register tree decl; +{ + register tree type; + + if (TREE_CODE (decl) == ERROR_MARK) + return integer_type_node; + + type = DECL_BIT_FIELD_TYPE (decl); + if (type == NULL) + type = TREE_TYPE (decl); + return type; +} + +/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE + node, return the alignment in bits for the type, or else return + BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */ + +inline unsigned +simple_type_align_in_bits (type) + register tree type; +{ + return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; +} + +/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE + node, return the size in bits for the type if it is a constant, or + else return the alignment for the type if the type's size is not + constant, or else return BITS_PER_WORD if the type actually turns out + to be an ERROR_MARK node. */ + +inline unsigned +simple_type_size_in_bits (type) + register tree type; +{ + if (TREE_CODE (type) == ERROR_MARK) + return BITS_PER_WORD; + else + { + register tree type_size_tree = TYPE_SIZE (type); + + if (TREE_CODE (type_size_tree) != INTEGER_CST) + return TYPE_ALIGN (type); + + return (unsigned) TREE_INT_CST_LOW (type_size_tree); + } +} + +/* Given a pointer to what is assumed to be a FIELD_DECL node, compute and + return the byte offset of the lowest addressed byte of the "containing + object" for the given FIELD_DECL, or return 0 if we are unable to deter- + mine what that offset is, either because the argument turns out to be a + pointer to an ERROR_MARK node, or because the offset is actually variable. + (We can't handle the latter case just yet.) */ + +static unsigned +field_byte_offset (decl) + register tree decl; +{ + register unsigned type_align_in_bytes; + register unsigned type_align_in_bits; + register unsigned type_size_in_bits; + register unsigned object_offset_in_align_units; + register unsigned object_offset_in_bits; + register unsigned object_offset_in_bytes; + register tree type; + register tree bitpos_tree; + register tree field_size_tree; + register unsigned bitpos_int; + register unsigned deepest_bitpos; + register unsigned field_size_in_bits; + + if (TREE_CODE (decl) == ERROR_MARK) + return 0; + + if (TREE_CODE (decl) != FIELD_DECL) + abort (); + + type = field_type (decl); + + bitpos_tree = DECL_FIELD_BITPOS (decl); + field_size_tree = DECL_SIZE (decl); + + /* We cannot yet cope with fields whose positions or sizes are variable, + so for now, when we see such things, we simply return 0. Someday, + we may be able to handle such cases, but it will be damn difficult. */ + + if (TREE_CODE (bitpos_tree) != INTEGER_CST) + return 0; + bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); + + if (TREE_CODE (field_size_tree) != INTEGER_CST) + return 0; + field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree); + + type_size_in_bits = simple_type_size_in_bits (type); + + type_align_in_bits = simple_type_align_in_bits (type); + type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; + + /* Note that the GCC front-end doesn't make any attempt to keep track + of the starting bit offset (relative to the start of the containing + structure type) of the hypothetical "containing object" for a bit- + field. Thus, when computing the byte offset value for the start of + the "containing object" of a bit-field, we must deduce this infor- + mation on our own. + + This can be rather tricky to do in some cases. For example, handling + the following structure type definition when compiling for an i386/i486 + target (which only aligns long long's to 32-bit boundaries) can be very + tricky: + + struct S { + int field1; + long long field2:31; + }; + + Fortunately, there is a simple rule-of-thumb which can be used in such + cases. When compiling for an i386/i486, GCC will allocate 8 bytes for + the structure shown above. It decides to do this based upon one simple + rule for bit-field allocation. Quite simply, GCC allocates each "con- + taining object" for each bit-field at the first (i.e. lowest addressed) + legitimate alignment boundary (based upon the required minimum alignment + for the declared type of the field) which it can possibly use, subject + to the condition that there is still enough available space remaining + in the containing object (when allocated at the selected point) to + fully accommodate all of the bits of the bit-field itself. + + This simple rule makes it obvious why GCC allocates 8 bytes for each + object of the structure type shown above. When looking for a place to + allocate the "containing object" for `field2', the compiler simply tries + to allocate a 64-bit "containing object" at each successive 32-bit + boundary (starting at zero) until it finds a place to allocate that 64- + bit field such that at least 31 contiguous (and previously unallocated) + bits remain within that selected 64 bit field. (As it turns out, for + the example above, the compiler finds that it is OK to allocate the + "containing object" 64-bit field at bit-offset zero within the + structure type.) + + Here we attempt to work backwards from the limited set of facts we're + given, and we try to deduce from those facts, where GCC must have + believed that the containing object started (within the structure type). + + The value we deduce is then used (by the callers of this routine) to + generate AT_location and AT_bit_offset attributes for fields (both + bit-fields and, in the case of AT_location, regular fields as well). + */ + + /* Figure out the bit-distance from the start of the structure to the + "deepest" bit of the bit-field. */ + deepest_bitpos = bitpos_int + field_size_in_bits; + + /* This is the tricky part. Use some fancy footwork to deduce where the + lowest addressed bit of the containing object must be. */ + object_offset_in_bits + = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; + + /* Compute the offset of the containing object in "alignment units". */ + object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; + + /* Compute the offset of the containing object in bytes. */ + object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; + + return object_offset_in_bytes; +} + +/****************************** attributes *********************************/ + +/* The following routines are responsible for writing out the various types + of Dwarf attributes (and any following data bytes associated with them). + These routines are listed in order based on the numerical codes of their + associated attributes. */ + +/* Generate an AT_sibling attribute. */ + +inline void +sibling_attribute () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling); + sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); + ASM_OUTPUT_DWARF_REF (asm_out_file, label); +} + +/* Output the form of location attributes suitable for whole variables and + whole parameters. Note that the location attributes for struct fields + are generated by the routine `data_member_location_attribute' below. */ + +static void +location_attribute (rtl) + register rtx rtl; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); + sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* Handle a special case. If we are about to output a location descriptor + for a variable or parameter which has been optimized out of existence, + don't do that. Instead we output a zero-length location descriptor + value as part of the location attribute. + + A variable which has been optimized out of existence will have a + DECL_RTL value which denotes a pseudo-reg. + + Currently, in some rare cases, variables can have DECL_RTL values + which look like (MEM (REG pseudo-reg#)). These cases are due to + bugs elsewhere in the compiler. We treat such cases + as if the variable(s) in question had been optimized out of existence. + + Note that in all cases where we wish to express the fact that a + variable has been optimized out of existence, we do not simply + suppress the generation of the entire location attribute because + the absence of a location attribute in certain kinds of DIEs is + used to indicate something else entirely... i.e. that the DIE + represents an object declaration, but not a definition. So saith + the PLSIG. + */ + + if (! is_pseudo_reg (rtl) + && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0)))) + output_loc_descriptor (eliminate_regs (rtl, 0, NULL_RTX)); + + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +/* Output the specialized form of location attribute used for data members + of struct and union types. + + In the special case of a FIELD_DECL node which represents a bit-field, + the "offset" part of this special location descriptor must indicate the + distance in bytes from the lowest-addressed byte of the containing + struct or union type to the lowest-addressed byte of the "containing + object" for the bit-field. (See the `field_byte_offset' function above.) + + For any given bit-field, the "containing object" is a hypothetical + object (of some integral or enum type) within which the given bit-field + lives. The type of this hypothetical "containing object" is always the + same as the declared type of the individual bit-field itself (for GCC + anyway... the DWARF spec doesn't actually mandate this). + + Note that it is the size (in bytes) of the hypothetical "containing + object" which will be given in the AT_byte_size attribute for this + bit-field. (See the `byte_size_attribute' function below.) It is + also used when calculating the value of the AT_bit_offset attribute. + (See the `bit_offset_attribute' function below.) +*/ + +static void +data_member_location_attribute (decl) + register tree decl; +{ + register unsigned object_offset_in_bytes = field_byte_offset (decl); + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); + sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes); + ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +/* Output an AT_const_value attribute for a variable or a parameter which + does not have a "location" either in memory or in a register. These + things can arise in GNU C when a constant is passed as an actual + parameter to an inlined function. They can also arise in C++ where + declared constants do not necessarily get memory "homes". */ + +static void +const_value_attribute (rtl) + register rtx rtl; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4); + sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + switch (GET_CODE (rtl)) + { + case CONST_INT: + /* Note that a CONST_INT rtx could represent either an integer or + a floating-point constant. A CONST_INT is used whenever the + constant will fit into a single word. In all such cases, the + original mode of the constant value is wiped out, and the + CONST_INT rtx is assigned VOIDmode. Since we no longer have + precise mode information for these constants, we always just + output them using 4 bytes. */ + + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl)); + break; + + case CONST_DOUBLE: + /* Note that a CONST_DOUBLE rtx could represent either an integer + or a floating-point constant. A CONST_DOUBLE is used whenever + the constant requires more than one word in order to be adequately + represented. In all such cases, the original mode of the constant + value is preserved as the mode of the CONST_DOUBLE rtx, but for + simplicity we always just output CONST_DOUBLEs using 8 bytes. */ + + ASM_OUTPUT_DWARF_DATA8 (asm_out_file, + (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (rtl), + (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (rtl)); + break; + + case CONST_STRING: + ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0)); + break; + + case SYMBOL_REF: + case LABEL_REF: + case CONST: + ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); + break; + + case PLUS: + /* In cases where an inlined instance of an inline function is passed + the address of an `auto' variable (which is local to the caller) + we can get a situation where the DECL_RTL of the artificial + local variable (for the inlining) which acts as a stand-in for + the corresponding formal parameter (of the inline function) + will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). + This is not exactly a compile-time constant expression, but it + isn't the address of the (artificial) local variable either. + Rather, it represents the *value* which the artificial local + variable always has during its lifetime. We currently have no + way to represent such quasi-constant values in Dwarf, so for now + we just punt and generate an AT_const_value attribute with form + FORM_BLOCK4 and a length of zero. */ + break; + + default: + abort (); /* No other kinds of rtx should be possible here. */ + } + + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +/* Generate *either* an AT_location attribute or else an AT_const_value + data attribute for a variable or a parameter. We generate the + AT_const_value attribute only in those cases where the given + variable or parameter does not have a true "location" either in + memory or in a register. This can happen (for example) when a + constant is passed as an actual argument in a call to an inline + function. (It's possible that these things can crop up in other + ways also.) Note that one type of constant value which can be + passed into an inlined function is a constant pointer. This can + happen for example if an actual argument in an inlined function + call evaluates to a compile-time constant address. */ + +static void +location_or_const_value_attribute (decl) + register tree decl; +{ + register rtx rtl; + + if (TREE_CODE (decl) == ERROR_MARK) + return; + + if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL)) + { + /* Should never happen. */ + abort (); + return; + } + + /* Here we have to decide where we are going to say the parameter "lives" + (as far as the debugger is concerned). We only have a couple of choices. + GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL + normally indicates where the parameter lives during most of the activa- + tion of the function. If optimization is enabled however, this could + be either NULL or else a pseudo-reg. Both of those cases indicate that + the parameter doesn't really live anywhere (as far as the code generation + parts of GCC are concerned) during most of the function's activation. + That will happen (for example) if the parameter is never referenced + within the function. + + We could just generate a location descriptor here for all non-NULL + non-pseudo values of DECL_RTL and ignore all of the rest, but we can + be a little nicer than that if we also consider DECL_INCOMING_RTL in + cases where DECL_RTL is NULL or is a pseudo-reg. + + Note however that we can only get away with using DECL_INCOMING_RTL as + a backup substitute for DECL_RTL in certain limited cases. In cases + where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl) + we can be sure that the parameter was passed using the same type as it + is declared to have within the function, and that its DECL_INCOMING_RTL + points us to a place where a value of that type is passed. In cases + where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types + however, we cannot (in general) use DECL_INCOMING_RTL as a backup + substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL + points us to a value of some type which is *different* from the type + of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL + to generate a location attribute in such cases, the debugger would + end up (for example) trying to fetch a `float' from a place which + actually contains the first part of a `double'. That would lead to + really incorrect and confusing output at debug-time, and we don't + want that now do we? + + So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL + in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a + couple of cute exceptions however. On little-endian machines we can + get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is + not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is + an integral type which is smaller than TREE_TYPE(decl). These cases + arise when (on a little-endian machine) a non-prototyped function has + a parameter declared to be of type `short' or `char'. In such cases, + TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be + `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the + passed `int' value. If the debugger then uses that address to fetch a + `short' or a `char' (on a little-endian machine) the result will be the + correct data, so we allow for such exceptional cases below. + + Note that our goal here is to describe the place where the given formal + parameter lives during most of the function's activation (i.e. between + the end of the prologue and the start of the epilogue). We'll do that + as best as we can. Note however that if the given formal parameter is + modified sometime during the execution of the function, then a stack + backtrace (at debug-time) will show the function as having been called + with the *new* value rather than the value which was originally passed + in. This happens rarely enough that it is not a major problem, but it + *is* a problem, and I'd like to fix it. A future version of dwarfout.c + may generate two additional attributes for any given TAG_formal_parameter + DIE which will describe the "passed type" and the "passed location" for + the given formal parameter in addition to the attributes we now generate + to indicate the "declared type" and the "active location" for each + parameter. This additional set of attributes could be used by debuggers + for stack backtraces. + + Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL + can be NULL also. This happens (for example) for inlined-instances of + inline function formal parameters which are never referenced. This really + shouldn't be happening. All PARM_DECL nodes should get valid non-NULL + DECL_INCOMING_RTL values, but integrate.c doesn't currently generate + these values for inlined instances of inline function parameters, so + when we see such cases, we are just SOL (shit-out-of-luck) for the time + being (until integrate.c gets fixed). + */ + + /* Use DECL_RTL as the "location" unless we find something better. */ + rtl = DECL_RTL (decl); + + if (TREE_CODE (decl) == PARM_DECL) + if (rtl == NULL_RTX || is_pseudo_reg (rtl)) + { + /* This decl represents a formal parameter which was optimized out. */ + register tree declared_type = type_main_variant (TREE_TYPE (decl)); + register tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); + + /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle + *all* cases where (rtl == NULL_RTX) just below. */ + + if (declared_type == passed_type) + rtl = DECL_INCOMING_RTL (decl); + else if (! BYTES_BIG_ENDIAN) + if (TREE_CODE (declared_type) == INTEGER_TYPE) + if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) + rtl = DECL_INCOMING_RTL (decl); + } + + if (rtl == NULL_RTX) + return; + + switch (GET_CODE (rtl)) + { + case CONST_INT: + case CONST_DOUBLE: + case CONST_STRING: + case SYMBOL_REF: + case LABEL_REF: + case CONST: + case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ + const_value_attribute (rtl); + break; + + case MEM: + case REG: + case SUBREG: + location_attribute (rtl); + break; + + default: + abort (); /* Should never happen. */ + } +} + +/* Generate an AT_name attribute given some string value to be included as + the value of the attribute. */ + +inline void +name_attribute (name_string) + register char *name_string; +{ + if (name_string && *name_string) + { + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name); + ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string); + } +} + +inline void +fund_type_attribute (ft_code) + register unsigned ft_code; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type); + ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code); +} + +static void +mod_fund_type_attribute (type, decl_const, decl_volatile) + register tree type; + register int decl_const; + register int decl_volatile; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type); + sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, MT_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + write_modifier_bytes (type, decl_const, decl_volatile); + ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, + fundamental_type_code (root_type (type))); + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +inline void +user_def_type_attribute (type) + register tree type; +{ + char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type); + sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type)); + ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); +} + +static void +mod_u_d_type_attribute (type, decl_const, decl_volatile) + register tree type; + register int decl_const; + register int decl_volatile; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type); + sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, MT_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + write_modifier_bytes (type, decl_const, decl_volatile); + sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type))); + ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +#ifdef USE_ORDERING_ATTRIBUTE +inline void +ordering_attribute (ordering) + register unsigned ordering; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering); +} +#endif /* defined(USE_ORDERING_ATTRIBUTE) */ + +/* Note that the block of subscript information for an array type also + includes information about the element type of type given array type. */ + +static void +subscript_data_attribute (type) + register tree type; +{ + register unsigned dimension_number; + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data); + sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, SS_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* The GNU compilers represent multidimensional array types as sequences + of one dimensional array types whose element types are themselves array + types. Here we squish that down, so that each multidimensional array + type gets only one array_type DIE in the Dwarf debugging info. The + draft Dwarf specification say that we are allowed to do this kind + of compression in C (because there is no difference between an + array or arrays and a multidimensional array in C) but for other + source languages (e.g. Ada) we probably shouldn't do this. */ + + for (dimension_number = 0; + TREE_CODE (type) == ARRAY_TYPE; + type = TREE_TYPE (type), dimension_number++) + { + register tree domain = TYPE_DOMAIN (type); + + /* Arrays come in three flavors. Unspecified bounds, fixed + bounds, and (in GNU C only) variable bounds. Handle all + three forms here. */ + + if (domain) + { + /* We have an array type with specified bounds. */ + + register tree lower = TYPE_MIN_VALUE (domain); + register tree upper = TYPE_MAX_VALUE (domain); + + /* Handle only fundamental types as index types for now. */ + + if (! type_is_fundamental (domain)) + abort (); + + /* Output the representation format byte for this dimension. */ + + ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, + FMT_CODE (1, + TREE_CODE (lower) == INTEGER_CST, + TREE_CODE (upper) == INTEGER_CST)); + + /* Output the index type for this dimension. */ + + ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, + fundamental_type_code (domain)); + + /* Output the representation for the lower bound. */ + + output_bound_representation (lower, dimension_number, 'l'); + + /* Output the representation for the upper bound. */ + + output_bound_representation (upper, dimension_number, 'u'); + } + else + { + /* We have an array type with an unspecified length. For C and + C++ we can assume that this really means that (a) the index + type is an integral type, and (b) the lower bound is zero. + Note that Dwarf defines the representation of an unspecified + (upper) bound as being a zero-length location description. */ + + /* Output the array-bounds format byte. */ + + ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X); + + /* Output the (assumed) index type. */ + + ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer); + + /* Output the (assumed) lower bound (constant) value. */ + + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + + /* Output the (empty) location description for the upper bound. */ + + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); + } + } + + /* Output the prefix byte that says that the element type is coming up. */ + + ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET); + + /* Output a representation of the type of the elements of this array type. */ + + type_attribute (type, 0, 0); + + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +static void +byte_size_attribute (tree_node) + register tree tree_node; +{ + register unsigned size; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size); + switch (TREE_CODE (tree_node)) + { + case ERROR_MARK: + size = 0; + break; + + case ENUMERAL_TYPE: + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + size = int_size_in_bytes (tree_node); + break; + + case FIELD_DECL: + /* For a data member of a struct or union, the AT_byte_size is + generally given as the number of bytes normally allocated for + an object of the *declared* type of the member itself. This + is true even for bit-fields. */ + size = simple_type_size_in_bits (field_type (tree_node)) + / BITS_PER_UNIT; + break; + + default: + abort (); + } + + /* Note that `size' might be -1 when we get to this point. If it + is, that indicates that the byte size of the entity in question + is variable. We have no good way of expressing this fact in Dwarf + at the present time, so just let the -1 pass on through. */ + + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size); +} + +/* For a FIELD_DECL node which represents a bit-field, output an attribute + which specifies the distance in bits from the highest order bit of the + "containing object" for the bit-field to the highest order bit of the + bit-field itself. + + For any given bit-field, the "containing object" is a hypothetical + object (of some integral or enum type) within which the given bit-field + lives. The type of this hypothetical "containing object" is always the + same as the declared type of the individual bit-field itself. + + The determination of the exact location of the "containing object" for + a bit-field is rather complicated. It's handled by the `field_byte_offset' + function (above). + + Note that it is the size (in bytes) of the hypothetical "containing + object" which will be given in the AT_byte_size attribute for this + bit-field. (See `byte_size_attribute' above.) +*/ + +inline void +bit_offset_attribute (decl) + register tree decl; +{ + register unsigned object_offset_in_bytes = field_byte_offset (decl); + register tree type = DECL_BIT_FIELD_TYPE (decl); + register tree bitpos_tree = DECL_FIELD_BITPOS (decl); + register unsigned bitpos_int; + register unsigned highest_order_object_bit_offset; + register unsigned highest_order_field_bit_offset; + register unsigned bit_offset; + + assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ + assert (type); /* Must be a bit field. */ + + /* We can't yet handle bit-fields whose offsets are variable, so if we + encounter such things, just return without generating any attribute + whatsoever. */ + + if (TREE_CODE (bitpos_tree) != INTEGER_CST) + return; + bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree); + + /* Note that the bit offset is always the distance (in bits) from the + highest-order bit of the "containing object" to the highest-order + bit of the bit-field itself. Since the "high-order end" of any + object or field is different on big-endian and little-endian machines, + the computation below must take account of these differences. */ + + highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; + highest_order_field_bit_offset = bitpos_int; + + if (! BYTES_BIG_ENDIAN) + { + highest_order_field_bit_offset + += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)); + + highest_order_object_bit_offset += simple_type_size_in_bits (type); + } + + bit_offset = + (! BYTES_BIG_ENDIAN + ? highest_order_object_bit_offset - highest_order_field_bit_offset + : highest_order_field_bit_offset - highest_order_object_bit_offset); + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset); +} + +/* For a FIELD_DECL node which represents a bit field, output an attribute + which specifies the length in bits of the given field. */ + +inline void +bit_size_attribute (decl) + register tree decl; +{ + assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ + assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, + (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); +} + +/* The following routine outputs the `element_list' attribute for enumeration + type DIEs. The element_lits attribute includes the names and values of + all of the enumeration constants associated with the given enumeration + type. */ + +inline void +element_list_attribute (element) + register tree element; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list); + sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, EE_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* Here we output a list of value/name pairs for each enumeration constant + defined for this enumeration type (as required), but we do it in REVERSE + order. The order is the one required by the draft #5 Dwarf specification + published by the UI/PLSIG. */ + + output_enumeral_list (element); /* Recursively output the whole list. */ + + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +/* Generate an AT_stmt_list attribute. These are normally present only in + DIEs with a TAG_compile_unit tag. */ + +inline void +stmt_list_attribute (label) + register char *label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list); + /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); +} + +/* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or + for a subroutine DIE. */ + +inline void +low_pc_attribute (asm_low_label) + register char *asm_low_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label); +} + +/* Generate an AT_high_pc attribute for a lexical_block DIE or for a + subroutine DIE. */ + +inline void +high_pc_attribute (asm_high_label) + register char *asm_high_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label); +} + +/* Generate an AT_body_begin attribute for a subroutine DIE. */ + +inline void +body_begin_attribute (asm_begin_label) + register char *asm_begin_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label); +} + +/* Generate an AT_body_end attribute for a subroutine DIE. */ + +inline void +body_end_attribute (asm_end_label) + register char *asm_end_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label); +} + +/* Generate an AT_language attribute given a LANG value. These attributes + are used only within TAG_compile_unit DIEs. */ + +inline void +language_attribute (language_code) + register unsigned language_code; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code); +} + +inline void +member_attribute (context) + register tree context; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + /* Generate this attribute only for members in C++. */ + + if (context != NULL && is_tagged_type (context)) + { + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member); + sprintf (label, TYPE_NAME_FMT, TYPE_UID (context)); + ASM_OUTPUT_DWARF_REF (asm_out_file, label); + } +} + +inline void +string_length_attribute (upper_bound) + register tree upper_bound; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length); + sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, SL_END_LABEL_FMT, current_dienum); + ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + output_bound_representation (upper_bound, 0, 'u'); + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +inline void +comp_dir_attribute (dirname) + register char *dirname; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir); + ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); +} + +inline void +sf_names_attribute (sf_names_start_label) + register char *sf_names_start_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names); + /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label); +} + +inline void +src_info_attribute (src_info_start_label) + register char *src_info_start_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info); + /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label); +} + +inline void +mac_info_attribute (mac_info_start_label) + register char *mac_info_start_label; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info); + /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label); +} + +inline void +prototyped_attribute (func_type) + register tree func_type; +{ + if ((strcmp (language_string, "GNU C") == 0) + && (TYPE_ARG_TYPES (func_type) != NULL)) + { + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped); + ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); + } +} + +inline void +producer_attribute (producer) + register char *producer; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer); + ASM_OUTPUT_DWARF_STRING (asm_out_file, producer); +} + +inline void +inline_attribute (decl) + register tree decl; +{ + if (DECL_INLINE (decl)) + { + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline); + ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); + } +} + +inline void +containing_type_attribute (containing_type) + register tree containing_type; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type); + sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type)); + ASM_OUTPUT_DWARF_REF (asm_out_file, label); +} + +inline void +abstract_origin_attribute (origin) + register tree origin; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin); + switch (TREE_CODE_CLASS (TREE_CODE (origin))) + { + case 'd': + sprintf (label, DECL_NAME_FMT, DECL_UID (origin)); + break; + + case 't': + sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin)); + break; + + default: + abort (); /* Should never happen. */ + + } + ASM_OUTPUT_DWARF_REF (asm_out_file, label); +} + +#ifdef DWARF_DECL_COORDINATES +inline void +src_coords_attribute (src_fileno, src_lineno) + register unsigned src_fileno; + register unsigned src_lineno; +{ + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno); +} +#endif /* defined(DWARF_DECL_COORDINATES) */ + +inline void +pure_or_virtual_attribute (func_decl) + register tree func_decl; +{ + if (DECL_VIRTUAL_P (func_decl)) + { +#if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */ + if (DECL_ABSTRACT_VIRTUAL_P (func_decl)) + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual); + else +#endif + ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual); + ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); + } +} + +/************************* end of attributes *****************************/ + +/********************* utility routines for DIEs *************************/ + +/* Output an AT_name attribute and an AT_src_coords attribute for the + given decl, but only if it actually has a name. */ + +static void +name_and_src_coords_attributes (decl) + register tree decl; +{ + register tree decl_name = DECL_NAME (decl); + + if (decl_name && IDENTIFIER_POINTER (decl_name)) + { + name_attribute (IDENTIFIER_POINTER (decl_name)); +#ifdef DWARF_DECL_COORDINATES + { + register unsigned file_index; + + /* This is annoying, but we have to pop out of the .debug section + for a moment while we call `lookup_filename' because calling it + may cause a temporary switch into the .debug_sfnames section and + most svr4 assemblers are not smart enough be be able to nest + section switches to any depth greater than one. Note that we + also can't skirt this issue by delaying all output to the + .debug_sfnames section unit the end of compilation because that + would cause us to have inter-section forward references and + Fred Fish sez that m68k/svr4 assemblers botch those. */ + + ASM_OUTPUT_POP_SECTION (asm_out_file); + file_index = lookup_filename (DECL_SOURCE_FILE (decl)); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); + + src_coords_attribute (file_index, DECL_SOURCE_LINE (decl)); + } +#endif /* defined(DWARF_DECL_COORDINATES) */ + } +} + +/* Many forms of DIEs contain a "type description" part. The following + routine writes out these "type descriptor" parts. */ + +static void +type_attribute (type, decl_const, decl_volatile) + register tree type; + register int decl_const; + register int decl_volatile; +{ + register enum tree_code code = TREE_CODE (type); + register int root_type_modified; + + if (TREE_CODE (type) == ERROR_MARK) + return; + + /* Handle a special case. For functions whose return type is void, + we generate *no* type attribute. (Note that no object may have + type `void', so this only applies to function return types. */ + + if (TREE_CODE (type) == VOID_TYPE) + return; + + root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE + || decl_const || decl_volatile + || TYPE_READONLY (type) || TYPE_VOLATILE (type)); + + if (type_is_fundamental (root_type (type))) + if (root_type_modified) + mod_fund_type_attribute (type, decl_const, decl_volatile); + else + fund_type_attribute (fundamental_type_code (type)); + else + if (root_type_modified) + mod_u_d_type_attribute (type, decl_const, decl_volatile); + else + /* We have to get the type_main_variant here (and pass that to the + `user_def_type_attribute' routine) because the ..._TYPE node we + have might simply be a *copy* of some original type node (where + the copy was created to help us keep track of typedef names) + and that copy might have a different TYPE_UID from the original + ..._TYPE node. (Note that when `equate_type_number_to_die_number' + is labeling a given type DIE for future reference, it always and + only creates labels for DIEs representing *main variants*, and it + never even knows about non-main-variants.) */ + user_def_type_attribute (type_main_variant (type)); +} + +/* Given a tree pointer to a struct, class, union, or enum type node, return + a pointer to the (string) tag name for the given type, or zero if the + type was declared without a tag. */ + +static char * +type_tag (type) + register tree type; +{ + register char *name = 0; + + if (TYPE_NAME (type) != 0) + { + register tree t = 0; + + /* Find the IDENTIFIER_NODE for the type name. */ + if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) + t = TYPE_NAME (type); +#if 0 + /* The g++ front end makes the TYPE_NAME of *each* tagged type point + to a TYPE_DECL node, regardless of whether or not a `typedef' was + involved. This is distinctly different from what the gcc front-end + does. It always makes the TYPE_NAME for each tagged type be either + NULL (signifying an anonymous tagged type) or else a pointer to an + IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf + for both C and C++, but given this inconsistency in the TREE + representation of tagged types for C and C++ in the GNU front-ends, + we cannot support both languages correctly unless we introduce some + front-end specific code here, and rms objects to that, so we can + only generate correct Dwarf for one of these two languages. C is + more important, so for now we'll do the right thing for C and let + g++ go fish. */ + + else + if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) + t = DECL_NAME (TYPE_NAME (type)); +#endif + /* Now get the name as a string, or invent one. */ + if (t != 0) + name = IDENTIFIER_POINTER (t); + } + + return (name == 0 || *name == '\0') ? 0 : name; +} + +inline void +dienum_push () +{ + /* Start by checking if the pending_sibling_stack needs to be expanded. + If necessary, expand it. */ + + if (pending_siblings == pending_siblings_allocated) + { + pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT; + pending_sibling_stack + = (unsigned *) xrealloc (pending_sibling_stack, + pending_siblings_allocated * sizeof(unsigned)); + } + + pending_siblings++; + NEXT_DIE_NUM = next_unused_dienum++; +} + +/* Pop the sibling stack so that the most recently pushed DIEnum becomes the + NEXT_DIE_NUM. */ + +inline void +dienum_pop () +{ + pending_siblings--; +} + +inline tree +member_declared_type (member) + register tree member; +{ + return (DECL_BIT_FIELD_TYPE (member)) + ? DECL_BIT_FIELD_TYPE (member) + : TREE_TYPE (member); +} + +/* Get the function's label, as described by its RTL. + This may be different from the DECL_NAME name used + in the source file. */ + +static char * +function_start_label (decl) + register tree decl; +{ + rtx x; + char *fnname; + + x = DECL_RTL (decl); + if (GET_CODE (x) != MEM) + abort (); + x = XEXP (x, 0); + if (GET_CODE (x) != SYMBOL_REF) + abort (); + fnname = XSTR (x, 0); + return fnname; +} + + +/******************************* DIEs ************************************/ + +/* Output routines for individual types of DIEs. */ + +/* Note that every type of DIE (except a null DIE) gets a sibling. */ + +static void +output_array_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + member_attribute (TYPE_CONTEXT (type)); + + /* I believe that we can default the array ordering. SDB will probably + do the right things even if AT_ordering is not present. It's not + even an issue until we start to get into multidimensional arrays + anyway. If SDB is ever caught doing the Wrong Thing for multi- + dimensional arrays, then we'll have to put the AT_ordering attribute + back in. (But if and when we find out that we need to put these in, + we will only do so for multidimensional arrays. After all, we don't + want to waste space in the .debug section now do we?) */ + +#ifdef USE_ORDERING_ATTRIBUTE + ordering_attribute (ORD_row_major); +#endif /* defined(USE_ORDERING_ATTRIBUTE) */ + + subscript_data_attribute (type); +} + +static void +output_set_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + member_attribute (TYPE_CONTEXT (type)); + type_attribute (TREE_TYPE (type), 0, 0); +} + +#if 0 +/* Implement this when there is a GNU FORTRAN or GNU Ada front end. */ +static void +output_entry_point_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point); + sibling_attribute (); + dienum_push (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + name_and_src_coords_attributes (decl); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + low_pc_attribute (function_start_label (decl)); +} +#endif + +/* Output a DIE to represent an inlined instance of an enumeration type. */ + +static void +output_inlined_enumeration_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); + sibling_attribute (); + assert (TREE_ASM_WRITTEN (type)); + abstract_origin_attribute (type); +} + +/* Output a DIE to represent an inlined instance of a structure type. */ + +static void +output_inlined_structure_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); + sibling_attribute (); + assert (TREE_ASM_WRITTEN (type)); + abstract_origin_attribute (type); +} + +/* Output a DIE to represent an inlined instance of a union type. */ + +static void +output_inlined_union_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); + sibling_attribute (); + assert (TREE_ASM_WRITTEN (type)); + abstract_origin_attribute (type); +} + +/* Output a DIE to represent an enumeration type. Note that these DIEs + include all of the information about the enumeration values also. + This information is encoded into the element_list attribute. */ + +static void +output_enumeration_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + name_attribute (type_tag (type)); + member_attribute (TYPE_CONTEXT (type)); + + /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the + given enum type is incomplete, do not generate the AT_byte_size + attribute or the AT_element_list attribute. */ + + if (TYPE_SIZE (type)) + { + byte_size_attribute (type); + element_list_attribute (TYPE_FIELDS (type)); + } +} + +/* Output a DIE to represent either a real live formal parameter decl or + to represent just the type of some formal parameter position in some + function type. + + Note that this routine is a bit unusual because its argument may be + a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which + represents an inlining of some PARM_DECL) or else some sort of a + ..._TYPE node. If it's the former then this function is being called + to output a DIE to represent a formal parameter object (or some inlining + thereof). If it's the latter, then this function is only being called + to output a TAG_formal_parameter DIE to stand as a placeholder for some + formal argument type of some subprogram type. */ + +static void +output_formal_parameter_die (arg) + register void *arg; +{ + register tree node = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter); + sibling_attribute (); + + switch (TREE_CODE_CLASS (TREE_CODE (node))) + { + case 'd': /* We were called with some kind of a ..._DECL node. */ + { + register tree origin = decl_ultimate_origin (node); + + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + name_and_src_coords_attributes (node); + type_attribute (TREE_TYPE (node), + TREE_READONLY (node), TREE_THIS_VOLATILE (node)); + } + if (DECL_ABSTRACT (node)) + equate_decl_number_to_die_number (node); + else + location_or_const_value_attribute (node); + } + break; + + case 't': /* We were called with some kind of a ..._TYPE node. */ + type_attribute (node, 0, 0); + break; + + default: + abort (); /* Should never happen. */ + } +} + +/* Output a DIE to represent a declared function (either file-scope + or block-local) which has "external linkage" (according to ANSI-C). */ + +static void +output_global_subroutine_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine); + sibling_attribute (); + dienum_push (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + register tree type = TREE_TYPE (decl); + + name_and_src_coords_attributes (decl); + inline_attribute (decl); + prototyped_attribute (type); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (type), 0, 0); + pure_or_virtual_attribute (decl); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + { + if (! DECL_EXTERNAL (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + low_pc_attribute (function_start_label (decl)); + sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); + high_pc_attribute (label); + sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number); + body_begin_attribute (label); + sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number); + body_end_attribute (label); + } + } +} + +/* Output a DIE to represent a declared data object (either file-scope + or block-local) which has "external linkage" (according to ANSI-C). */ + +static void +output_global_variable_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable); + sibling_attribute (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + name_and_src_coords_attributes (decl); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (decl), + TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + { + if (!DECL_EXTERNAL (decl)) + location_or_const_value_attribute (decl); + } +} + +static void +output_label_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label); + sibling_attribute (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + name_and_src_coords_attributes (decl); + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + { + register rtx insn = DECL_RTL (decl); + + if (GET_CODE (insn) == CODE_LABEL) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + /* When optimization is enabled (via -O) some parts of the compiler + (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which + represent source-level labels which were explicitly declared by + the user. This really shouldn't be happening though, so catch + it if it ever does happen. */ + + if (INSN_DELETED_P (insn)) + abort (); /* Should never happen. */ + + sprintf (label, INSN_LABEL_FMT, current_funcdef_number, + (unsigned) INSN_UID (insn)); + low_pc_attribute (label); + } + } +} + +static void +output_lexical_block_die (arg) + register void *arg; +{ + register tree stmt = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block); + sibling_attribute (); + dienum_push (); + if (! BLOCK_ABSTRACT (stmt)) + { + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); + low_pc_attribute (begin_label); + sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); + high_pc_attribute (end_label); + } +} + +static void +output_inlined_subroutine_die (arg) + register void *arg; +{ + register tree stmt = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine); + sibling_attribute (); + dienum_push (); + abstract_origin_attribute (block_ultimate_origin (stmt)); + if (! BLOCK_ABSTRACT (stmt)) + { + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); + low_pc_attribute (begin_label); + sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); + high_pc_attribute (end_label); + } +} + +/* Output a DIE to represent a declared data object (either file-scope + or block-local) which has "internal linkage" (according to ANSI-C). */ + +static void +output_local_variable_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable); + sibling_attribute (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + name_and_src_coords_attributes (decl); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (decl), + TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + location_or_const_value_attribute (decl); +} + +static void +output_member_die (arg) + register void *arg; +{ + register tree decl = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member); + sibling_attribute (); + name_and_src_coords_attributes (decl); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (member_declared_type (decl), + TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); + if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */ + { + byte_size_attribute (decl); + bit_size_attribute (decl); + bit_offset_attribute (decl); + } + data_member_location_attribute (decl); +} + +#if 0 +/* Don't generate either pointer_type DIEs or reference_type DIEs. Use + modified types instead. + + We keep this code here just in case these types of DIEs may be needed + to represent certain things in other languages (e.g. Pascal) someday. +*/ + +static void +output_pointer_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + member_attribute (TYPE_CONTEXT (type)); + type_attribute (TREE_TYPE (type), 0, 0); +} + +static void +output_reference_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + member_attribute (TYPE_CONTEXT (type)); + type_attribute (TREE_TYPE (type), 0, 0); +} +#endif + +static void +output_ptr_to_mbr_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + member_attribute (TYPE_CONTEXT (type)); + containing_type_attribute (TYPE_OFFSET_BASETYPE (type)); + type_attribute (TREE_TYPE (type), 0, 0); +} + +static void +output_compile_unit_die (arg) + register void *arg; +{ + register char *main_input_filename = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit); + sibling_attribute (); + dienum_push (); + name_attribute (main_input_filename); + + { + char producer[250]; + + sprintf (producer, "%s %s", language_string, version_string); + producer_attribute (producer); + } + + if (strcmp (language_string, "GNU C++") == 0) + language_attribute (LANG_C_PLUS_PLUS); + else if (strcmp (language_string, "GNU Ada") == 0) + language_attribute (LANG_ADA83); + else if (strcmp (language_string, "GNU F77") == 0) + language_attribute (LANG_FORTRAN77); + else if (flag_traditional) + language_attribute (LANG_C); + else + language_attribute (LANG_C89); + low_pc_attribute (TEXT_BEGIN_LABEL); + high_pc_attribute (TEXT_END_LABEL); + if (debug_info_level >= DINFO_LEVEL_NORMAL) + stmt_list_attribute (LINE_BEGIN_LABEL); + last_filename = xstrdup (main_input_filename); + + { + char *wd = getpwd (); + if (wd) + comp_dir_attribute (wd); + } + + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + sf_names_attribute (SFNAMES_BEGIN_LABEL); + src_info_attribute (SRCINFO_BEGIN_LABEL); + if (debug_info_level >= DINFO_LEVEL_VERBOSE) + mac_info_attribute (MACINFO_BEGIN_LABEL); + } +} + +static void +output_string_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type); + sibling_attribute (); + member_attribute (TYPE_CONTEXT (type)); + + /* Fudge the string length attribute for now. */ + + string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); +} + +static void +output_structure_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + name_attribute (type_tag (type)); + member_attribute (TYPE_CONTEXT (type)); + + /* If this type has been completed, then give it a byte_size attribute + and prepare to give a list of members. Otherwise, don't do either of + these things. In the latter case, we will not be generating a list + of members (since we don't have any idea what they might be for an + incomplete type). */ + + if (TYPE_SIZE (type)) + { + dienum_push (); + byte_size_attribute (type); + } +} + +/* Output a DIE to represent a declared function (either file-scope + or block-local) which has "internal linkage" (according to ANSI-C). */ + +static void +output_local_subroutine_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine); + sibling_attribute (); + dienum_push (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + register tree type = TREE_TYPE (decl); + + name_and_src_coords_attributes (decl); + inline_attribute (decl); + prototyped_attribute (type); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (type), 0, 0); + pure_or_virtual_attribute (decl); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); + else + { + /* Avoid getting screwed up in cases where a function was declared + static but where no definition was ever given for it. */ + + if (TREE_ASM_WRITTEN (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + low_pc_attribute (function_start_label (decl)); + sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); + high_pc_attribute (label); + sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number); + body_begin_attribute (label); + sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number); + body_end_attribute (label); + } + } +} + +static void +output_subroutine_type_die (arg) + register void *arg; +{ + register tree type = arg; + register tree return_type = TREE_TYPE (type); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type); + sibling_attribute (); + dienum_push (); + equate_type_number_to_die_number (type); + prototyped_attribute (type); + member_attribute (TYPE_CONTEXT (type)); + type_attribute (return_type, 0, 0); +} + +static void +output_typedef_die (arg) + register void *arg; +{ + register tree decl = arg; + register tree origin = decl_ultimate_origin (decl); + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef); + sibling_attribute (); + if (origin != NULL) + abstract_origin_attribute (origin); + else + { + name_and_src_coords_attributes (decl); + member_attribute (DECL_CONTEXT (decl)); + type_attribute (TREE_TYPE (decl), + TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); + } + if (DECL_ABSTRACT (decl)) + equate_decl_number_to_die_number (decl); +} + +static void +output_union_type_die (arg) + register void *arg; +{ + register tree type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); + sibling_attribute (); + equate_type_number_to_die_number (type); + name_attribute (type_tag (type)); + member_attribute (TYPE_CONTEXT (type)); + + /* If this type has been completed, then give it a byte_size attribute + and prepare to give a list of members. Otherwise, don't do either of + these things. In the latter case, we will not be generating a list + of members (since we don't have any idea what they might be for an + incomplete type). */ + + if (TYPE_SIZE (type)) + { + dienum_push (); + byte_size_attribute (type); + } +} + +/* Generate a special type of DIE used as a stand-in for a trailing ellipsis + at the end of an (ANSI prototyped) formal parameters list. */ + +static void +output_unspecified_parameters_die (arg) + register void *arg; +{ + register tree decl_or_type = arg; + + ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters); + sibling_attribute (); + + /* This kludge is here only for the sake of being compatible with what + the USL CI5 C compiler does. The specification of Dwarf Version 1 + doesn't say that TAG_unspecified_parameters DIEs should contain any + attributes other than the AT_sibling attribute, but they are certainly + allowed to contain additional attributes, and the CI5 compiler + generates AT_name, AT_fund_type, and AT_location attributes within + TAG_unspecified_parameters DIEs which appear in the child lists for + DIEs representing function definitions, so we do likewise here. */ + + if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type)) + { + name_attribute ("..."); + fund_type_attribute (FT_pointer); + /* location_attribute (?); */ + } +} + +static void +output_padded_null_die (arg) + register void *arg; +{ + ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */ +} + +/*************************** end of DIEs *********************************/ + +/* Generate some type of DIE. This routine generates the generic outer + wrapper stuff which goes around all types of DIE's (regardless of their + TAGs. All forms of DIEs start with a DIE-specific label, followed by a + DIE-length word, followed by the guts of the DIE itself. After the guts + of the DIE, there must always be a terminator label for the DIE. */ + +static void +output_die (die_specific_output_function, param) + register void (*die_specific_output_function)(); + register void *param; +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + current_dienum = NEXT_DIE_NUM; + NEXT_DIE_NUM = next_unused_dienum; + + sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); + sprintf (end_label, DIE_END_LABEL_FMT, current_dienum); + + /* Write a label which will act as the name for the start of this DIE. */ + + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* Write the DIE-length word. */ + + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); + + /* Fill in the guts of the DIE. */ + + next_unused_dienum++; + die_specific_output_function (param); + + /* Write a label which will act as the name for the end of this DIE. */ + + ASM_OUTPUT_LABEL (asm_out_file, end_label); +} + +static void +end_sibling_chain () +{ + char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + current_dienum = NEXT_DIE_NUM; + NEXT_DIE_NUM = next_unused_dienum; + + sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); + + /* Write a label which will act as the name for the start of this DIE. */ + + ASM_OUTPUT_LABEL (asm_out_file, begin_label); + + /* Write the DIE-length word. */ + + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); + + dienum_pop (); +} + +/* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a + TAG_unspecified_parameters DIE) to represent the types of the formal + parameters as specified in some function type specification (except + for those which appear as part of a function *definition*). + + Note that we must be careful here to output all of the parameter DIEs + *before* we output any DIEs needed to represent the types of the formal + parameters. This keeps svr4 SDB happy because it (incorrectly) thinks + that the first non-parameter DIE it sees ends the formal parameter list. +*/ + +static void +output_formal_types (function_or_method_type) + register tree function_or_method_type; +{ + register tree link; + register tree formal_type = NULL; + register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); + + /* In the case where we are generating a formal types list for a C++ + non-static member function type, skip over the first thing on the + TYPE_ARG_TYPES list because it only represents the type of the + hidden `this pointer'. The debugger should be able to figure + out (without being explicitly told) that this non-static member + function type takes a `this pointer' and should be able to figure + what the type of that hidden parameter is from the AT_member + attribute of the parent TAG_subroutine_type DIE. */ + + if (TREE_CODE (function_or_method_type) == METHOD_TYPE) + first_parm_type = TREE_CHAIN (first_parm_type); + + /* Make our first pass over the list of formal parameter types and output + a TAG_formal_parameter DIE for each one. */ + + for (link = first_parm_type; link; link = TREE_CHAIN (link)) + { + formal_type = TREE_VALUE (link); + if (formal_type == void_type_node) + break; + + /* Output a (nameless) DIE to represent the formal parameter itself. */ + + output_die (output_formal_parameter_die, formal_type); + } + + /* If this function type has an ellipsis, add a TAG_unspecified_parameters + DIE to the end of the parameter list. */ + + if (formal_type != void_type_node) + output_die (output_unspecified_parameters_die, function_or_method_type); + + /* Make our second (and final) pass over the list of formal parameter types + and output DIEs to represent those types (as necessary). */ + + for (link = TYPE_ARG_TYPES (function_or_method_type); + link; + link = TREE_CHAIN (link)) + { + formal_type = TREE_VALUE (link); + if (formal_type == void_type_node) + break; + + output_type (formal_type, function_or_method_type); + } +} + +/* Remember a type in the pending_types_list. */ + +static void +pend_type (type) + register tree type; +{ + if (pending_types == pending_types_allocated) + { + pending_types_allocated += PENDING_TYPES_INCREMENT; + pending_types_list + = (tree *) xrealloc (pending_types_list, + sizeof (tree) * pending_types_allocated); + } + pending_types_list[pending_types++] = type; + + /* Mark the pending type as having been output already (even though + it hasn't been). This prevents the type from being added to the + pending_types_list more than once. */ + + TREE_ASM_WRITTEN (type) = 1; +} + +/* Return non-zero if it is legitimate to output DIEs to represent a + given type while we are generating the list of child DIEs for some + DIE (e.g. a function or lexical block DIE) associated with a given scope. + + See the comments within the function for a description of when it is + considered legitimate to output DIEs for various kinds of types. + + Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope) + or it may point to a BLOCK node (for types local to a block), or to a + FUNCTION_DECL node (for types local to the heading of some function + definition), or to a FUNCTION_TYPE node (for types local to the + prototyped parameter list of a function type specification), or to a + RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node + (in the case of C++ nested types). + + The `scope' parameter should likewise be NULL or should point to a + BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE + node, a UNION_TYPE node, or a QUAL_UNION_TYPE node. + + This function is used only for deciding when to "pend" and when to + "un-pend" types to/from the pending_types_list. + + Note that we sometimes make use of this "type pending" feature in a + rather twisted way to temporarily delay the production of DIEs for the + types of formal parameters. (We do this just to make svr4 SDB happy.) + It order to delay the production of DIEs representing types of formal + parameters, callers of this function supply `fake_containing_scope' as + the `scope' parameter to this function. Given that fake_containing_scope + is a tagged type which is *not* the containing scope for *any* other type, + the desired effect is achieved, i.e. output of DIEs representing types + is temporarily suspended, and any type DIEs which would have otherwise + been output are instead placed onto the pending_types_list. Later on, + we force these (temporarily pended) types to be output simply by calling + `output_pending_types_for_scope' with an actual argument equal to the + true scope of the types we temporarily pended. +*/ + +inline int +type_ok_for_scope (type, scope) + register tree type; + register tree scope; +{ + /* Tagged types (i.e. struct, union, and enum types) must always be + output only in the scopes where they actually belong (or else the + scoping of their own tag names and the scoping of their member + names will be incorrect). Non-tagged-types on the other hand can + generally be output anywhere, except that svr4 SDB really doesn't + want to see them nested within struct or union types, so here we + say it is always OK to immediately output any such a (non-tagged) + type, so long as we are not within such a context. Note that the + only kinds of non-tagged types which we will be dealing with here + (for C and C++ anyway) will be array types and function types. */ + + return is_tagged_type (type) + ? (TYPE_CONTEXT (type) == scope) + : (scope == NULL_TREE || ! is_tagged_type (scope)); +} + +/* Output any pending types (from the pending_types list) which we can output + now (taking into account the scope that we are working on now). + + For each type output, remove the given type from the pending_types_list + *before* we try to output it. + + Note that we have to process the list in beginning-to-end order, + because the call made here to output_type may cause yet more types + to be added to the end of the list, and we may have to output some + of them too. +*/ + +static void +output_pending_types_for_scope (containing_scope) + register tree containing_scope; +{ + register unsigned i; + + for (i = 0; i < pending_types; ) + { + register tree type = pending_types_list[i]; + + if (type_ok_for_scope (type, containing_scope)) + { + register tree *mover; + register tree *limit; + + pending_types--; + limit = &pending_types_list[pending_types]; + for (mover = &pending_types_list[i]; mover < limit; mover++) + *mover = *(mover+1); + + /* Un-mark the type as having been output already (because it + hasn't been, really). Then call output_type to generate a + Dwarf representation of it. */ + + TREE_ASM_WRITTEN (type) = 0; + output_type (type, containing_scope); + + /* Don't increment the loop counter in this case because we + have shifted all of the subsequent pending types down one + element in the pending_types_list array. */ + } + else + i++; + } +} + +static void +output_type (type, containing_scope) + register tree type; + register tree containing_scope; +{ + if (type == 0 || type == error_mark_node) + return; + + /* We are going to output a DIE to represent the unqualified version of + of this type (i.e. without any const or volatile qualifiers) so get + the main variant (i.e. the unqualified version) of this type now. */ + + type = type_main_variant (type); + + if (TREE_ASM_WRITTEN (type)) + return; + + /* Don't generate any DIEs for this type now unless it is OK to do so + (based upon what `type_ok_for_scope' tells us). */ + + if (! type_ok_for_scope (type, containing_scope)) + { + pend_type (type); + return; + } + + switch (TREE_CODE (type)) + { + case ERROR_MARK: + break; + + case POINTER_TYPE: + case REFERENCE_TYPE: + /* For these types, all that is required is that we output a DIE + (or a set of DIEs) to represent the "basis" type. */ + output_type (TREE_TYPE (type), containing_scope); + break; + + case OFFSET_TYPE: + /* This code is used for C++ pointer-to-data-member types. */ + /* Output a description of the relevant class type. */ + output_type (TYPE_OFFSET_BASETYPE (type), containing_scope); + /* Output a description of the type of the object pointed to. */ + output_type (TREE_TYPE (type), containing_scope); + /* Now output a DIE to represent this pointer-to-data-member type + itself. */ + output_die (output_ptr_to_mbr_type_die, type); + break; + + case SET_TYPE: + output_type (TYPE_DOMAIN (type), containing_scope); + output_die (output_set_type_die, type); + break; + + case FILE_TYPE: + output_type (TREE_TYPE (type), containing_scope); + abort (); /* No way to represent these in Dwarf yet! */ + break; + + case FUNCTION_TYPE: + /* Force out return type (in case it wasn't forced out already). */ + output_type (TREE_TYPE (type), containing_scope); + output_die (output_subroutine_type_die, type); + output_formal_types (type); + end_sibling_chain (); + break; + + case METHOD_TYPE: + /* Force out return type (in case it wasn't forced out already). */ + output_type (TREE_TYPE (type), containing_scope); + output_die (output_subroutine_type_die, type); + output_formal_types (type); + end_sibling_chain (); + break; + + case ARRAY_TYPE: + if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE) + { + output_type (TREE_TYPE (type), containing_scope); + output_die (output_string_type_die, type); + } + else + { + register tree element_type; + + element_type = TREE_TYPE (type); + while (TREE_CODE (element_type) == ARRAY_TYPE) + element_type = TREE_TYPE (element_type); + + output_type (element_type, containing_scope); + output_die (output_array_type_die, type); + } + break; + + case ENUMERAL_TYPE: + case RECORD_TYPE: + case UNION_TYPE: + case QUAL_UNION_TYPE: + + /* For a non-file-scope tagged type, we can always go ahead and + output a Dwarf description of this type right now, even if + the type in question is still incomplete, because if this + local type *was* ever completed anywhere within its scope, + that complete definition would already have been attached to + this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE + node by the time we reach this point. That's true because of the + way the front-end does its processing of file-scope declarations (of + functions and class types) within which other types might be + nested. The C and C++ front-ends always gobble up such "local + scope" things en-mass before they try to output *any* debugging + information for any of the stuff contained inside them and thus, + we get the benefit here of what is (in effect) a pre-resolution + of forward references to tagged types in local scopes. + + Note however that for file-scope tagged types we cannot assume + that such pre-resolution of forward references has taken place. + A given file-scope tagged type may appear to be incomplete when + we reach this point, but it may yet be given a full definition + (at file-scope) later on during compilation. In order to avoid + generating a premature (and possibly incorrect) set of Dwarf + DIEs for such (as yet incomplete) file-scope tagged types, we + generate nothing at all for as-yet incomplete file-scope tagged + types here unless we are making our special "finalization" pass + for file-scope things at the very end of compilation. At that + time, we will certainly know as much about each file-scope tagged + type as we are ever going to know, so at that point in time, we + can safely generate correct Dwarf descriptions for these file- + scope tagged types. + */ + + if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing) + return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */ + + /* Prevent infinite recursion in cases where the type of some + member of this type is expressed in terms of this type itself. */ + + TREE_ASM_WRITTEN (type) = 1; + + /* Output a DIE to represent the tagged type itself. */ + + switch (TREE_CODE (type)) + { + case ENUMERAL_TYPE: + output_die (output_enumeration_type_die, type); + return; /* a special case -- nothing left to do so just return */ + + case RECORD_TYPE: + output_die (output_structure_type_die, type); + break; + + case UNION_TYPE: + case QUAL_UNION_TYPE: + output_die (output_union_type_die, type); + break; + + default: + abort (); /* Should never happen. */ + } + + /* If this is not an incomplete type, output descriptions of + each of its members. + + Note that as we output the DIEs necessary to represent the + members of this record or union type, we will also be trying + to output DIEs to represent the *types* of those members. + However the `output_type' function (above) will specifically + avoid generating type DIEs for member types *within* the list + of member DIEs for this (containing) type execpt for those + types (of members) which are explicitly marked as also being + members of this (containing) type themselves. The g++ front- + end can force any given type to be treated as a member of some + other (containing) type by setting the TYPE_CONTEXT of the + given (member) type to point to the TREE node representing the + appropriate (containing) type. + */ + + if (TYPE_SIZE (type)) + { + { + register tree normal_member; + + /* First output info about the data members and type members. */ + + for (normal_member = TYPE_FIELDS (type); + normal_member; + normal_member = TREE_CHAIN (normal_member)) + output_decl (normal_member, type); + } + + { + register tree vec_base; + + /* Now output info about the function members (if any). */ + + vec_base = TYPE_METHODS (type); + if (vec_base) + { + register tree first_func_member = TREE_VEC_ELT (vec_base, 0); + register tree func_member; + + /* This isn't documented, but the first element of the + vector of member functions can be NULL in cases where + the class type in question didn't have either a + constructor or a destructor declared for it. We have + to make allowances for that here. */ + + if (first_func_member == NULL) + first_func_member = TREE_VEC_ELT (vec_base, 1); + + for (func_member = first_func_member; + func_member; + func_member = TREE_CHAIN (func_member)) + output_decl (func_member, type); + } + } + + /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves + scopes (at least in C++) so we must now output any nested + pending types which are local just to this type. */ + + output_pending_types_for_scope (type); + + end_sibling_chain (); /* Terminate member chain. */ + } + + break; + + case VOID_TYPE: + case INTEGER_TYPE: + case REAL_TYPE: + case COMPLEX_TYPE: + case BOOLEAN_TYPE: + case CHAR_TYPE: + break; /* No DIEs needed for fundamental types. */ + + case LANG_TYPE: /* No Dwarf representation currently defined. */ + break; + + default: + abort (); + } + + TREE_ASM_WRITTEN (type) = 1; +} + +static void +output_tagged_type_instantiation (type) + register tree type; +{ + if (type == 0 || type == error_mark_node) + return; + + /* We are going to output a DIE to represent the unqualified version of + of this type (i.e. without any const or volatile qualifiers) so make + sure that we have the main variant (i.e. the unqualified version) of + this type now. */ + + assert (type == type_main_variant (type)); + + assert (TREE_ASM_WRITTEN (type)); + + switch (TREE_CODE (type)) + { + case ERROR_MARK: + break; + + case ENUMERAL_TYPE: + output_die (output_inlined_enumeration_type_die, type); + break; + + case RECORD_TYPE: + output_die (output_inlined_structure_type_die, type); + break; + + case UNION_TYPE: + case QUAL_UNION_TYPE: + output_die (output_inlined_union_type_die, type); + break; + + default: + abort (); /* Should never happen. */ + } +} + +/* Output a TAG_lexical_block DIE followed by DIEs to represent all of + the things which are local to the given block. */ + +static void +output_block (stmt) + register tree stmt; +{ + register int must_output_die = 0; + register tree origin; + register enum tree_code origin_code; + + /* Ignore blocks never really used to make RTL. */ + + if (! stmt || ! TREE_USED (stmt)) + return; + + /* Determine the "ultimate origin" of this block. This block may be an + inlined instance of an inlined instance of inline function, so we + have to trace all of the way back through the origin chain to find + out what sort of node actually served as the original seed for the + creation of the current block. */ + + origin = block_ultimate_origin (stmt); + origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; + + /* Determine if we need to output any Dwarf DIEs at all to represent this + block. */ + + if (origin_code == FUNCTION_DECL) + /* The outer scopes for inlinings *must* always be represented. We + generate TAG_inlined_subroutine DIEs for them. (See below.) */ + must_output_die = 1; + else + { + /* In the case where the current block represents an inlining of the + "body block" of an inline function, we must *NOT* output any DIE + for this block because we have already output a DIE to represent + the whole inlined function scope and the "body block" of any + function doesn't really represent a different scope according to + ANSI C rules. So we check here to make sure that this block does + not represent a "body block inlining" before trying to set the + `must_output_die' flag. */ + + if (origin == NULL || ! is_body_block (origin)) + { + /* Determine if this block directly contains any "significant" + local declarations which we will need to output DIEs for. */ + + if (debug_info_level > DINFO_LEVEL_TERSE) + /* We are not in terse mode so *any* local declaration counts + as being a "significant" one. */ + must_output_die = (BLOCK_VARS (stmt) != NULL); + else + { + register tree decl; + + /* We are in terse mode, so only local (nested) function + definitions count as "significant" local declarations. */ + + for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) + { + must_output_die = 1; + break; + } + } + } + } + + /* It would be a waste of space to generate a Dwarf TAG_lexical_block + DIE for any block which contains no significant local declarations + at all. Rather, in such cases we just call `output_decls_for_scope' + so that any needed Dwarf info for any sub-blocks will get properly + generated. Note that in terse mode, our definition of what constitutes + a "significant" local declaration gets restricted to include only + inlined function instances and local (nested) function definitions. */ + + if (must_output_die) + { + output_die ((origin_code == FUNCTION_DECL) + ? output_inlined_subroutine_die + : output_lexical_block_die, + stmt); + output_decls_for_scope (stmt); + end_sibling_chain (); + } + else + output_decls_for_scope (stmt); +} + +/* Output all of the decls declared within a given scope (also called + a `binding contour') and (recursively) all of it's sub-blocks. */ + +static void +output_decls_for_scope (stmt) + register tree stmt; +{ + /* Ignore blocks never really used to make RTL. */ + + if (! stmt || ! TREE_USED (stmt)) + return; + + if (! BLOCK_ABSTRACT (stmt)) + next_block_number++; + + /* Output the DIEs to represent all of the data objects, functions, + typedefs, and tagged types declared directly within this block + but not within any nested sub-blocks. */ + + { + register tree decl; + + for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) + output_decl (decl, stmt); + } + + output_pending_types_for_scope (stmt); + + /* Output the DIEs to represent all sub-blocks (and the items declared + therein) of this block. */ + + { + register tree subblocks; + + for (subblocks = BLOCK_SUBBLOCKS (stmt); + subblocks; + subblocks = BLOCK_CHAIN (subblocks)) + output_block (subblocks); + } +} + +/* Output Dwarf .debug information for a decl described by DECL. */ + +static void +output_decl (decl, containing_scope) + register tree decl; + register tree containing_scope; +{ + /* Make a note of the decl node we are going to be working on. We may + need to give the user the source coordinates of where it appeared in + case we notice (later on) that something about it looks screwy. */ + + dwarf_last_decl = decl; + + if (TREE_CODE (decl) == ERROR_MARK) + return; + + /* If a structure is declared within an initialization, e.g. as the + operand of a sizeof, then it will not have a name. We don't want + to output a DIE for it, as the tree nodes are in the temporary obstack */ + + if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) + && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0) + || (TYPE_FIELDS (TREE_TYPE (decl)) + && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK)))) + return; + + /* If this ..._DECL node is marked to be ignored, then ignore it. + But don't ignore a function definition, since that would screw + up our count of blocks, and that it turn will completely screw up the + the labels we will reference in subsequent AT_low_pc and AT_high_pc + attributes (for subsequent blocks). */ + + if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL) + return; + + switch (TREE_CODE (decl)) + { + case CONST_DECL: + /* The individual enumerators of an enum type get output when we + output the Dwarf representation of the relevant enum type itself. */ + break; + + case FUNCTION_DECL: + /* If we are in terse mode, don't output any DIEs to represent + mere function declarations. Also, if we are conforming + to the DWARF version 1 specification, don't output DIEs for + mere function declarations. */ + + if (DECL_INITIAL (decl) == NULL_TREE) +#if (DWARF_VERSION > 1) + if (debug_info_level <= DINFO_LEVEL_TERSE) +#endif + break; + + /* Before we describe the FUNCTION_DECL itself, make sure that we + have described its return type. */ + + output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope); + + /* If the following DIE will represent a function definition for a + function with "extern" linkage, output a special "pubnames" DIE + label just ahead of the actual DIE. A reference to this label + was already generated in the .debug_pubnames section sub-entry + for this function definition. */ + + if (TREE_PUBLIC (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); + ASM_OUTPUT_LABEL (asm_out_file, label); + } + + /* Now output a DIE to represent the function itself. */ + + output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl) + ? output_global_subroutine_die + : output_local_subroutine_die, + decl); + + /* Now output descriptions of the arguments for this function. + This gets (unnecessarily?) complex because of the fact that + the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate + cases where there was a trailing `...' at the end of the formal + parameter list. In order to find out if there was a trailing + ellipsis or not, we must instead look at the type associated + with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE. + If the chain of type nodes hanging off of this FUNCTION_TYPE node + ends with a void_type_node then there should *not* be an ellipsis + at the end. */ + + /* In the case where we are describing a mere function declaration, all + we need to do here (and all we *can* do here) is to describe + the *types* of its formal parameters. */ + + if (DECL_INITIAL (decl) == NULL_TREE) + output_formal_types (TREE_TYPE (decl)); + else + { + /* Generate DIEs to represent all known formal parameters */ + + register tree arg_decls = DECL_ARGUMENTS (decl); + register tree parm; + + /* WARNING! Kludge zone ahead! Here we have a special + hack for svr4 SDB compatibility. Instead of passing the + current FUNCTION_DECL node as the second parameter (i.e. + the `containing_scope' parameter) to `output_decl' (as + we ought to) we instead pass a pointer to our own private + fake_containing_scope node. That node is a RECORD_TYPE + node which NO OTHER TYPE may ever actually be a member of. + + This pointer will ultimately get passed into `output_type' + as its `containing_scope' parameter. `Output_type' will + then perform its part in the hack... i.e. it will pend + the type of the formal parameter onto the pending_types + list. Later on, when we are done generating the whole + sequence of formal parameter DIEs for this function + definition, we will un-pend all previously pended types + of formal parameters for this function definition. + + This whole kludge prevents any type DIEs from being + mixed in with the formal parameter DIEs. That's good + because svr4 SDB believes that the list of formal + parameter DIEs for a function ends wherever the first + non-formal-parameter DIE appears. Thus, we have to + keep the formal parameter DIEs segregated. They must + all appear (consecutively) at the start of the list of + children for the DIE representing the function definition. + Then (and only then) may we output any additional DIEs + needed to represent the types of these formal parameters. + */ + + /* + When generating DIEs, generate the unspecified_parameters + DIE instead if we come across the arg "__builtin_va_alist" + */ + + for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) + if (TREE_CODE (parm) == PARM_DECL) + { + if (DECL_NAME(parm) && + !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)), + "__builtin_va_alist") ) + output_die (output_unspecified_parameters_die, decl); + else + output_decl (parm, fake_containing_scope); + } + + /* + Now that we have finished generating all of the DIEs to + represent the formal parameters themselves, force out + any DIEs needed to represent their types. We do this + simply by un-pending all previously pended types which + can legitimately go into the chain of children DIEs for + the current FUNCTION_DECL. + */ + + output_pending_types_for_scope (decl); + + /* + Decide whether we need a unspecified_parameters DIE at the end. + There are 2 more cases to do this for: + 1) the ansi ... declaration - this is detectable when the end + of the arg list is not a void_type_node + 2) an unprototyped function declaration (not a definition). This + just means that we have no info about the parameters at all. + */ + + { + register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); + + if (fn_arg_types) + { + /* this is the prototyped case, check for ... */ + if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) + output_die (output_unspecified_parameters_die, decl); + } + else + { + /* this is unprototyped, check for undefined (just declaration) */ + if (!DECL_INITIAL (decl)) + output_die (output_unspecified_parameters_die, decl); + } + } + } + + /* Output Dwarf info for all of the stuff within the body of the + function (if it has one - it may be just a declaration). */ + + { + register tree outer_scope = DECL_INITIAL (decl); + + if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) + { + /* Note that here, `outer_scope' is a pointer to the outermost + BLOCK node created to represent a function. + This outermost BLOCK actually represents the outermost + binding contour for the function, i.e. the contour in which + the function's formal parameters and labels get declared. + + Curiously, it appears that the front end doesn't actually + put the PARM_DECL nodes for the current function onto the + BLOCK_VARS list for this outer scope. (They are strung + off of the DECL_ARGUMENTS list for the function instead.) + The BLOCK_VARS list for the `outer_scope' does provide us + with a list of the LABEL_DECL nodes for the function however, + and we output DWARF info for those here. + + Just within the `outer_scope' there will be another BLOCK + node representing the function's outermost pair of curly + braces. We mustn't generate a lexical_block DIE for this + outermost pair of curly braces because that is not really an + independent scope according to ANSI C rules. Rather, it is + the same scope in which the parameters were declared. */ + + { + register tree label; + + for (label = BLOCK_VARS (outer_scope); + label; + label = TREE_CHAIN (label)) + output_decl (label, outer_scope); + } + + /* Note here that `BLOCK_SUBBLOCKS (outer_scope)' points to a + list of BLOCK nodes which is always only one element long. + That one element represents the outermost pair of curley + braces for the function body. */ + + output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope)); + + /* Finally, force out any pending types which are local to the + outermost block of this function definition. These will + all have a TYPE_CONTEXT which points to the FUNCTION_DECL + node itself. */ + + output_pending_types_for_scope (decl); + } + } + + /* Generate a terminator for the list of stuff `owned' by this + function. */ + + end_sibling_chain (); + + break; + + case TYPE_DECL: + /* If we are in terse mode, don't generate any DIEs to represent + any actual typedefs. Note that even when we are in terse mode, + we must still output DIEs to represent those tagged types which + are used (directly or indirectly) in the specification of either + a return type or a formal parameter type of some function. */ + + if (debug_info_level <= DINFO_LEVEL_TERSE) + if (DECL_NAME (decl) != NULL + || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) + return; + + /* In the special case of a null-named TYPE_DECL node (representing + the declaration of some type tag), if the given TYPE_DECL is + marked as having been instantiated from some other (original) + TYPE_DECL node (e.g. one which was generated within the original + definition of an inline function) we have to generate a special + (abbreviated) TAG_structure_type, TAG_union_type, or + TAG_enumeration-type DIE here. */ + + if (! DECL_NAME (decl) && DECL_ABSTRACT_ORIGIN (decl)) + { + output_tagged_type_instantiation (TREE_TYPE (decl)); + return; + } + + output_type (TREE_TYPE (decl), containing_scope); + + /* Note that unlike the gcc front end (which generates a NULL named + TYPE_DECL node for each complete tagged type, each array type, + and each function type node created) the g++ front end generates + a *named* TYPE_DECL node for each tagged type node created. + Unfortunately, these g++ TYPE_DECL nodes cause us to output many + superfluous and unnecessary TAG_typedef DIEs here. When g++ is + fixed to stop generating these superfluous named TYPE_DECL nodes, + the superfluous TAG_typedef DIEs will likewise cease. */ + + if (DECL_NAME (decl)) + /* Output a DIE to represent the typedef itself. */ + output_die (output_typedef_die, decl); + break; + + case LABEL_DECL: + if (debug_info_level >= DINFO_LEVEL_NORMAL) + output_die (output_label_die, decl); + break; + + case VAR_DECL: + /* If we are conforming to the DWARF version 1 specification, don't + generated any DIEs to represent mere external object declarations. */ + +#if (DWARF_VERSION <= 1) + if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl)) + break; +#endif + + /* If we are in terse mode, don't generate any DIEs to represent + any variable declarations or definitions. */ + + if (debug_info_level <= DINFO_LEVEL_TERSE) + break; + + /* Output any DIEs that are needed to specify the type of this data + object. */ + + output_type (TREE_TYPE (decl), containing_scope); + + /* If the following DIE will represent a data object definition for a + data object with "extern" linkage, output a special "pubnames" DIE + label just ahead of the actual DIE. A reference to this label + was already generated in the .debug_pubnames section sub-entry + for this data object definition. */ + + if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); + ASM_OUTPUT_LABEL (asm_out_file, label); + } + + /* Now output the DIE to represent the data object itself. This gets + complicated because of the possibility that the VAR_DECL really + represents an inlined instance of a formal parameter for an inline + function. */ + + { + register void (*func) (); + register tree origin = decl_ultimate_origin (decl); + + if (origin != NULL && TREE_CODE (origin) == PARM_DECL) + func = output_formal_parameter_die; + else + { + if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) + func = output_global_variable_die; + else + func = output_local_variable_die; + } + output_die (func, decl); + } + break; + + case FIELD_DECL: + /* Ignore the nameless fields that are used to skip bits. */ + if (DECL_NAME (decl) != 0) + { + output_type (member_declared_type (decl), containing_scope); + output_die (output_member_die, decl); + } + break; + + case PARM_DECL: + /* Force out the type of this formal, if it was not forced out yet. + Note that here we can run afowl of a bug in "classic" svr4 SDB. + It should be able to grok the presence of type DIEs within a list + of TAG_formal_parameter DIEs, but it doesn't. */ + + output_type (TREE_TYPE (decl), containing_scope); + output_die (output_formal_parameter_die, decl); + break; + + default: + abort (); + } +} + +void +dwarfout_file_scope_decl (decl, set_finalizing) + register tree decl; + register int set_finalizing; +{ + if (TREE_CODE (decl) == ERROR_MARK) + return; + + /* If this ..._DECL node is marked to be ignored, then ignore it. We + gotta hope that the node in question doesn't represent a function + definition. If it does, then totally ignoring it is bound to screw + up our count of blocks, and that it turn will completely screw up the + the labels we will reference in subsequent AT_low_pc and AT_high_pc + attributes (for subsequent blocks). (It's too bad that BLOCK nodes + don't carry their own sequence numbers with them!) */ + + if (DECL_IGNORED_P (decl)) + { + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL) + abort (); + return; + } + + switch (TREE_CODE (decl)) + { + case FUNCTION_DECL: + + /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of + a builtin function. Explicit programmer-supplied declarations of + these same functions should NOT be ignored however. */ + + if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) + return; + + /* What we would really like to do here is to filter out all mere + file-scope declarations of file-scope functions which are never + referenced later within this translation unit (and keep all of + ones that *are* referenced later on) but we aren't clairvoyant, + so we have no idea which functions will be referenced in the + future (i.e. later on within the current translation unit). + So here we just ignore all file-scope function declarations + which are not also definitions. If and when the debugger needs + to know something about these functions, it wil have to hunt + around and find the DWARF information associated with the + *definition* of the function. + + Note that we can't just check `DECL_EXTERNAL' to find out which + FUNCTION_DECL nodes represent definitions and which ones represent + mere declarations. We have to check `DECL_INITIAL' instead. That's + because the C front-end supports some weird semantics for "extern + inline" function definitions. These can get inlined within the + current translation unit (an thus, we need to generate DWARF info + for their abstract instances so that the DWARF info for the + concrete inlined instances can have something to refer to) but + the compiler never generates any out-of-lines instances of such + things (despite the fact that they *are* definitions). The + important point is that the C front-end marks these "extern inline" + functions as DECL_EXTERNAL, but we need to generate DWARf for them + anyway. + + Note that the C++ front-end also plays some similar games for inline + function definitions appearing within include files which also + contain `#pragma interface' pragmas. */ + + if (DECL_INITIAL (decl) == NULL_TREE) + return; + + if (TREE_PUBLIC (decl) + && ! DECL_EXTERNAL (decl) + && ! DECL_ABSTRACT (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + /* Output a .debug_pubnames entry for a public function + defined in this compilation unit. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); + sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); + ASM_OUTPUT_DWARF_STRING (asm_out_file, + IDENTIFIER_POINTER (DECL_NAME (decl))); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + + break; + + case VAR_DECL: + + /* Ignore this VAR_DECL if it refers to a file-scope extern data + object declaration and if the declaration was never even + referenced from within this entire compilation unit. We + suppress these DIEs in order to save space in the .debug section + (by eliminating entries which are probably useless). Note that + we must not suppress block-local extern declarations (whether + used or not) because that would screw-up the debugger's name + lookup mechanism and cause it to miss things which really ought + to be in scope at a given point. */ + + if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) + return; + + if (TREE_PUBLIC (decl) + && ! DECL_EXTERNAL (decl) + && GET_CODE (DECL_RTL (decl)) == MEM + && ! DECL_ABSTRACT (decl)) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + /* Output a .debug_pubnames entry for a public variable + defined in this compilation unit. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); + sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); + ASM_OUTPUT_DWARF_STRING (asm_out_file, + IDENTIFIER_POINTER (DECL_NAME (decl))); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + + if (DECL_INITIAL (decl) == NULL) + { + /* Output a .debug_aranges entry for a public variable + which is tentatively defined in this compilation unit. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, + IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, + (unsigned) int_size_in_bytes (TREE_TYPE (decl))); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + } + + /* If we are in terse mode, don't generate any DIEs to represent + any variable declarations or definitions. */ + + if (debug_info_level <= DINFO_LEVEL_TERSE) + return; + + break; + + case TYPE_DECL: + /* Don't bother trying to generate any DIEs to represent any of the + normal built-in types for the language we are compiling, except + in cases where the types in question are *not* DWARF fundamental + types. We make an exception in the case of non-fundamental types + for the sake of objective C (and perhaps C++) because the GNU + front-ends for these languages may in fact create certain "built-in" + types which are (for example) RECORD_TYPEs. In such cases, we + really need to output these (non-fundamental) types because other + DIEs may contain references to them. */ + + if (DECL_SOURCE_LINE (decl) == 0 + && type_is_fundamental (TREE_TYPE (decl))) + return; + + /* If we are in terse mode, don't generate any DIEs to represent + any actual typedefs. Note that even when we are in terse mode, + we must still output DIEs to represent those tagged types which + are used (directly or indirectly) in the specification of either + a return type or a formal parameter type of some function. */ + + if (debug_info_level <= DINFO_LEVEL_TERSE) + if (DECL_NAME (decl) != NULL + || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) + return; + + break; + + default: + return; + } + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); + finalizing = set_finalizing; + output_decl (decl, NULL_TREE); + + /* NOTE: The call above to `output_decl' may have caused one or more + file-scope named types (i.e. tagged types) to be placed onto the + pending_types_list. We have to get those types off of that list + at some point, and this is the perfect time to do it. If we didn't + take them off now, they might still be on the list when cc1 finally + exits. That might be OK if it weren't for the fact that when we put + types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag + for these types, and that causes them never to be output unless + `output_pending_types_for_scope' takes them off of the list and un-sets + their TREE_ASM_WRITTEN flags. */ + + output_pending_types_for_scope (NULL_TREE); + + /* The above call should have totally emptied the pending_types_list. */ + + assert (pending_types == 0); + + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL) + current_funcdef_number++; +} + +/* Output a marker (i.e. a label) for the beginning of the generated code + for a lexical block. */ + +void +dwarfout_begin_block (blocknum) + register unsigned blocknum; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + function_section (current_function_decl); + sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); + ASM_OUTPUT_LABEL (asm_out_file, label); +} + +/* Output a marker (i.e. a label) for the end of the generated code + for a lexical block. */ + +void +dwarfout_end_block (blocknum) + register unsigned blocknum; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + function_section (current_function_decl); + sprintf (label, BLOCK_END_LABEL_FMT, blocknum); + ASM_OUTPUT_LABEL (asm_out_file, label); +} + +/* Output a marker (i.e. a label) at a point in the assembly code which + corresponds to a given source level label. */ + +void +dwarfout_label (insn) + register rtx insn; +{ + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + function_section (current_function_decl); + sprintf (label, INSN_LABEL_FMT, current_funcdef_number, + (unsigned) INSN_UID (insn)); + ASM_OUTPUT_LABEL (asm_out_file, label); + } +} + +/* Output a marker (i.e. a label) for the point in the generated code where + the real body of the function begins (after parameters have been moved + to their home locations). */ + +void +dwarfout_begin_function () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + function_section (current_function_decl); + sprintf (label, BODY_BEGIN_LABEL_FMT, current_funcdef_number); + ASM_OUTPUT_LABEL (asm_out_file, label); +} + +/* Output a marker (i.e. a label) for the point in the generated code where + the real body of the function ends (just before the epilogue code). */ + +void +dwarfout_end_function () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + function_section (current_function_decl); + sprintf (label, BODY_END_LABEL_FMT, current_funcdef_number); + ASM_OUTPUT_LABEL (asm_out_file, label); +} + +/* Output a marker (i.e. a label) for the absolute end of the generated code + for a function definition. This gets called *after* the epilogue code + has been generated. */ + +void +dwarfout_end_epilogue () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + /* Output a label to mark the endpoint of the code generated for this + function. */ + + sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); + ASM_OUTPUT_LABEL (asm_out_file, label); +} + +static void +shuffle_filename_entry (new_zeroth) + register filename_entry *new_zeroth; +{ + filename_entry temp_entry; + register filename_entry *limit_p; + register filename_entry *move_p; + + if (new_zeroth == &filename_table[0]) + return; + + temp_entry = *new_zeroth; + + /* Shift entries up in the table to make room at [0]. */ + + limit_p = &filename_table[0]; + for (move_p = new_zeroth; move_p > limit_p; move_p--) + *move_p = *(move_p-1); + + /* Install the found entry at [0]. */ + + filename_table[0] = temp_entry; +} + +/* Create a new (string) entry for the .debug_sfnames section. */ + +static void +generate_new_sfname_entry () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION); + sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number); + ASM_OUTPUT_LABEL (asm_out_file, label); + ASM_OUTPUT_DWARF_STRING (asm_out_file, + filename_table[0].name + ? filename_table[0].name + : ""); + ASM_OUTPUT_POP_SECTION (asm_out_file); +} + +/* Lookup a filename (in the list of filenames that we know about here in + dwarfout.c) and return its "index". The index of each (known) filename + is just a unique number which is associated with only that one filename. + We need such numbers for the sake of generating labels (in the + .debug_sfnames section) and references to those unique labels (in the + .debug_srcinfo and .debug_macinfo sections). + + If the filename given as an argument is not found in our current list, + add it to the list and assign it the next available unique index number. + + Whatever we do (i.e. whether we find a pre-existing filename or add a new + one), we shuffle the filename found (or added) up to the zeroth entry of + our list of filenames (which is always searched linearly). We do this so + as to optimize the most common case for these filename lookups within + dwarfout.c. The most common case by far is the case where we call + lookup_filename to lookup the very same filename that we did a lookup + on the last time we called lookup_filename. We make sure that this + common case is fast because such cases will constitute 99.9% of the + lookups we ever do (in practice). + + If we add a new filename entry to our table, we go ahead and generate + the corresponding entry in the .debug_sfnames section right away. + Doing so allows us to avoid tickling an assembler bug (present in some + m68k assemblers) which yields assembly-time errors in cases where the + difference of two label addresses is taken and where the two labels + are in a section *other* than the one where the difference is being + calculated, and where at least one of the two symbol references is a + forward reference. (This bug could be tickled by our .debug_srcinfo + entries if we don't output their corresponding .debug_sfnames entries + before them.) +*/ + +static unsigned +lookup_filename (file_name) + char *file_name; +{ + register filename_entry *search_p; + register filename_entry *limit_p = &filename_table[ft_entries]; + + for (search_p = filename_table; search_p < limit_p; search_p++) + if (!strcmp (file_name, search_p->name)) + { + /* When we get here, we have found the filename that we were + looking for in the filename_table. Now we want to make sure + that it gets moved to the zero'th entry in the table (if it + is not already there) so that subsequent attempts to find the + same filename will find it as quickly as possible. */ + + shuffle_filename_entry (search_p); + return filename_table[0].number; + } + + /* We come here whenever we have a new filename which is not registered + in the current table. Here we add it to the table. */ + + /* Prepare to add a new table entry by making sure there is enough space + in the table to do so. If not, expand the current table. */ + + if (ft_entries == ft_entries_allocated) + { + ft_entries_allocated += FT_ENTRIES_INCREMENT; + filename_table + = (filename_entry *) + xrealloc (filename_table, + ft_entries_allocated * sizeof (filename_entry)); + } + + /* Initially, add the new entry at the end of the filename table. */ + + filename_table[ft_entries].number = ft_entries; + filename_table[ft_entries].name = xstrdup (file_name); + + /* Shuffle the new entry into filename_table[0]. */ + + shuffle_filename_entry (&filename_table[ft_entries]); + + if (debug_info_level >= DINFO_LEVEL_NORMAL) + generate_new_sfname_entry (); + + ft_entries++; + return filename_table[0].number; +} + +static void +generate_srcinfo_entry (line_entry_num, files_entry_num) + unsigned line_entry_num; + unsigned files_entry_num; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); + sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL); + sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); +} + +void +dwarfout_line (filename, line) + register char *filename; + register unsigned line; +{ + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + static unsigned last_line_entry_num = 0; + static unsigned prev_file_entry_num = (unsigned) -1; + register unsigned this_file_entry_num = lookup_filename (filename); + + function_section (current_function_decl); + sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num); + ASM_OUTPUT_LABEL (asm_out_file, label); + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); + + if (this_file_entry_num != prev_file_entry_num) + { + char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES]; + + sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num); + ASM_OUTPUT_LABEL (asm_out_file, line_entry_label); + } + + { + register char *tail = rindex (filename, '/'); + + if (tail != NULL) + filename = tail; + } + + fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n", + UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START, + filename, line); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (this_file_entry_num != prev_file_entry_num) + generate_srcinfo_entry (last_line_entry_num, this_file_entry_num); + prev_file_entry_num = this_file_entry_num; + } +} + +/* Generate an entry in the .debug_macinfo section. */ + +static void +generate_macinfo_entry (type_and_offset, string) + register char *type_and_offset; + register char *string; +{ + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); + fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset); + ASM_OUTPUT_DWARF_STRING (asm_out_file, string); + ASM_OUTPUT_POP_SECTION (asm_out_file); +} + +void +dwarfout_start_new_source_file (filename) + register char *filename; +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3]; + + sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename)); + sprintf (type_and_offset, "0x%08x+%s-%s", + ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL); + generate_macinfo_entry (type_and_offset, ""); +} + +void +dwarfout_resume_previous_source_file (lineno) + register unsigned lineno; +{ + char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; + + sprintf (type_and_offset, "0x%08x+%u", + ((unsigned) MACINFO_resume << 24), lineno); + generate_macinfo_entry (type_and_offset, ""); +} + +/* Called from check_newline in c-parse.y. The `buffer' parameter + contains the tail part of the directive line, i.e. the part which + is past the initial whitespace, #, whitespace, directive-name, + whitespace part. */ + +void +dwarfout_define (lineno, buffer) + register unsigned lineno; + register char *buffer; +{ + static int initialized = 0; + char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; + + if (!initialized) + { + dwarfout_start_new_source_file (primary_filename); + initialized = 1; + } + sprintf (type_and_offset, "0x%08x+%u", + ((unsigned) MACINFO_define << 24), lineno); + generate_macinfo_entry (type_and_offset, buffer); +} + +/* Called from check_newline in c-parse.y. The `buffer' parameter + contains the tail part of the directive line, i.e. the part which + is past the initial whitespace, #, whitespace, directive-name, + whitespace part. */ + +void +dwarfout_undef (lineno, buffer) + register unsigned lineno; + register char *buffer; +{ + char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; + + sprintf (type_and_offset, "0x%08x+%u", + ((unsigned) MACINFO_undef << 24), lineno); + generate_macinfo_entry (type_and_offset, buffer); +} + +/* Set up for Dwarf output at the start of compilation. */ + +void +dwarfout_init (asm_out_file, main_input_filename) + register FILE *asm_out_file; + register char *main_input_filename; +{ + /* Remember the name of the primary input file. */ + + primary_filename = main_input_filename; + + /* Allocate the initial hunk of the pending_sibling_stack. */ + + pending_sibling_stack + = (unsigned *) + xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned)); + pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT; + pending_siblings = 1; + + /* Allocate the initial hunk of the filename_table. */ + + filename_table + = (filename_entry *) + xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry)); + ft_entries_allocated = FT_ENTRIES_INCREMENT; + ft_entries = 0; + + /* Allocate the initial hunk of the pending_types_list. */ + + pending_types_list + = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree)); + pending_types_allocated = PENDING_TYPES_INCREMENT; + pending_types = 0; + + /* Create an artificial RECORD_TYPE node which we can use in our hack + to get the DIEs representing types of formal parameters to come out + only *after* the DIEs for the formal parameters themselves. */ + + fake_containing_scope = make_node (RECORD_TYPE); + + /* Output a starting label for the .text section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Output a starting label for the .data section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + +#if 0 /* GNU C doesn't currently use .data1. */ + /* Output a starting label for the .data1 section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); +#endif + + /* Output a starting label for the .rodata section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + +#if 0 /* GNU C doesn't currently use .rodata1. */ + /* Output a starting label for the .rodata1 section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); +#endif + + /* Output a starting label for the .bss section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + /* Output a starting label and an initial (compilation directory) + entry for the .debug_sfnames section. The starting label will be + referenced by the initial entry in the .debug_srcinfo section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, SFNAMES_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL); + { + register char *pwd; + register unsigned len; + register char *dirname; + + pwd = getpwd (); + if (!pwd) + pfatal_with_name ("getpwd"); + len = strlen (pwd); + dirname = (char *) xmalloc (len + 2); + + strcpy (dirname, pwd); + strcpy (dirname + len, "/"); + ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); + free (dirname); + } + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (debug_info_level >= DINFO_LEVEL_VERBOSE) + { + /* Output a starting label for the .debug_macinfo section. This + label will be referenced by the AT_mac_info attribute in the + TAG_compile_unit DIE. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + + /* Generate the initial entry for the .line section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Generate the initial entry for the .debug_srcinfo section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL); +#ifdef DWARF_TIMESTAMPS + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL)); +#else + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); +#endif + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Generate the initial entry for the .debug_pubnames section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Generate the initial entry for the .debug_aranges section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); + ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + + /* Setup first DIE number == 1. */ + NEXT_DIE_NUM = next_unused_dienum++; + + /* Generate the initial DIE for the .debug section. Note that the + (string) value given in the AT_name attribute of the TAG_compile_unit + DIE will (typically) be a relative pathname and that this pathname + should be taken as being relative to the directory from which the + compiler was invoked when the given (base) source file was compiled. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL); + output_die (output_compile_unit_die, main_input_filename); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + fputc ('\n', asm_out_file); +} + +/* Output stuff that dwarf requires at the end of every file. */ + +void +dwarfout_finish () +{ + char label[MAX_ARTIFICIAL_LABEL_BYTES]; + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); + + /* Mark the end of the chain of siblings which represent all file-scope + declarations in this compilation unit. */ + + /* The (null) DIE which represents the terminator for the (sibling linked) + list of file-scope items is *special*. Normally, we would just call + end_sibling_chain at this point in order to output a word with the + value `4' and that word would act as the terminator for the list of + DIEs describing file-scope items. Unfortunately, if we were to simply + do that, the label that would follow this DIE in the .debug section + (i.e. `..D2') would *not* be properly aligned (as it must be on some + machines) to a 4 byte boundary. + + In order to force the label `..D2' to get aligned to a 4 byte boundary, + the trick used is to insert extra (otherwise useless) padding bytes + into the (null) DIE that we know must precede the ..D2 label in the + .debug section. The amount of padding required can be anywhere between + 0 and 3 bytes. The length word at the start of this DIE (i.e. the one + with the padding) would normally contain the value 4, but now it will + also have to include the padding bytes, so it will instead have some + value in the range 4..7. + + Fortunately, the rules of Dwarf say that any DIE whose length word + contains *any* value less than 8 should be treated as a null DIE, so + this trick works out nicely. Clever, eh? Don't give me any credit + (or blame). I didn't think of this scheme. I just conformed to it. + */ + + output_die (output_padded_null_die, (void *)0); + dienum_pop (); + + sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); + ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */ + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Output a terminator label for the .text section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Output a terminator label for the .data section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + +#if 0 /* GNU C doesn't currently use .data1. */ + /* Output a terminator label for the .data1 section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); +#endif + + /* Output a terminator label for the .rodata section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + +#if 0 /* GNU C doesn't currently use .rodata1. */ + /* Output a terminator label for the .rodata1 section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); +#endif + + /* Output a terminator label for the .bss section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (debug_info_level >= DINFO_LEVEL_NORMAL) + { + /* Output a terminating entry for the .line section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); + ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); + ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Output a terminating entry for the .debug_srcinfo section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, SRCINFO_SECTION); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, + LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + if (debug_info_level >= DINFO_LEVEL_VERBOSE) + { + /* Output terminating entries for the .debug_macinfo section. */ + + dwarfout_resume_previous_source_file (0); + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, MACINFO_SECTION); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); + ASM_OUTPUT_POP_SECTION (asm_out_file); + } + + /* Generate the terminating entry for the .debug_pubnames section. */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, PUBNAMES_SECTION); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); + ASM_OUTPUT_POP_SECTION (asm_out_file); + + /* Generate the terminating entries for the .debug_aranges section. + + Note that we want to do this only *after* we have output the end + labels (for the various program sections) which we are going to + refer to here. This allows us to work around a bug in the m68k + svr4 assembler. That assembler gives bogus assembly-time errors + if (within any given section) you try to take the difference of + two relocatable symbols, both of which are located within some + other section, and if one (or both?) of the symbols involved is + being forward-referenced. By generating the .debug_aranges + entries at this late point in the assembly output, we skirt the + issue simply by avoiding forward-references. + */ + + fputc ('\n', asm_out_file); + ASM_OUTPUT_PUSH_SECTION (asm_out_file, ARANGES_SECTION); + + ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); + + ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL); + +#if 0 /* GNU C doesn't currently use .data1. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL, + DATA1_BEGIN_LABEL); +#endif + + ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL, + RODATA_BEGIN_LABEL); + +#if 0 /* GNU C doesn't currently use .rodata1. */ + ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL, + RODATA1_BEGIN_LABEL); +#endif + + ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL); + ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL); + + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); + + ASM_OUTPUT_POP_SECTION (asm_out_file); + } +} + +#endif /* DWARF_DEBUGGING_INFO */ diff --git a/contrib/gcc/emit-rtl.c b/contrib/gcc/emit-rtl.c new file mode 100644 index 00000000000..9600f2f63aa --- /dev/null +++ b/contrib/gcc/emit-rtl.c @@ -0,0 +1,3448 @@ +/* Emit RTL for the GNU C-Compiler expander. + Copyright (C) 1987, 88, 92, 93, 94, 1995 Free Software Foundation, Inc. + +This file is part of GNU CC. + +GNU CC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU CC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + + +/* Middle-to-low level generation of rtx code and insns. + + This file contains the functions `gen_rtx', `gen_reg_rtx' + and `gen_label_rtx' that are the usual ways of creating rtl + expressions for most purposes. + + It also has the functions for creating insns and linking + them in the doubly-linked chain. + + The patterns of the insns are created by machine-dependent + routines in insn-emit.c, which is generated automatically from + the machine description. These routines use `gen_rtx' to make + the individual rtx's of the pattern; what is machine dependent + is the kind of rtx's they make and what arguments they use. */ + +#include "config.h" +#ifdef __STDC__ +#include +#else +#include +#endif +#include "rtl.h" +#include "tree.h" +#include "flags.h" +#include "function.h" +#include "expr.h" +#include "regs.h" +#include "insn-config.h" +#include "real.h" +#include "obstack.h" + +#include "bytecode.h" +#include "machmode.h" +#include "bc-opcode.h" +#include "bc-typecd.h" +#include "bc-optab.h" +#include "bc-emit.h" + +#include + + +/* Opcode names */ +#ifdef BCDEBUG_PRINT_CODE +char *opcode_name[] = +{ +#include "bc-opname.h" + +"***END***" +}; +#endif + + +/* Commonly used modes. */ + +enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */ +enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */ +enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */ + +/* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function. + After rtl generation, it is 1 plus the largest register number used. */ + +int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1; + +/* This is *not* reset after each function. It gives each CODE_LABEL + in the entire compilation a unique label number. */ + +static int label_num = 1; + +/* Lowest label number in current function. */ + +static int first_label_num; + +/* Highest label number in current function. + Zero means use the value of label_num instead. + This is nonzero only when belatedly compiling an inline function. */ + +static int last_label_num; + +/* Value label_num had when set_new_first_and_last_label_number was called. + If label_num has not changed since then, last_label_num is valid. */ + +static int base_label_num; + +/* Nonzero means do not generate NOTEs for source line numbers. */ + +static int no_line_numbers; + +/* Commonly used rtx's, so that we only need space for one copy. + These are initialized once for the entire compilation. + All of these except perhaps the floating-point CONST_DOUBLEs + are unique; no other rtx-object will be equal to any of these. */ + +rtx pc_rtx; /* (PC) */ +rtx cc0_rtx; /* (CC0) */ +rtx cc1_rtx; /* (CC1) (not actually used nowadays) */ +rtx const0_rtx; /* (CONST_INT 0) */ +rtx const1_rtx; /* (CONST_INT 1) */ +rtx const2_rtx; /* (CONST_INT 2) */ +rtx constm1_rtx; /* (CONST_INT -1) */ +rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */ + +/* We record floating-point CONST_DOUBLEs in each floating-point mode for + the values of 0, 1, and 2. For the integer entries and VOIDmode, we + record a copy of const[012]_rtx. */ + +rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE]; + +REAL_VALUE_TYPE dconst0; +REAL_VALUE_TYPE dconst1; +REAL_VALUE_TYPE dconst2; +REAL_VALUE_TYPE dconstm1; + +/* All references to the following fixed hard registers go through + these unique rtl objects. On machines where the frame-pointer and + arg-pointer are the same register, they use the same unique object. + + After register allocation, other rtl objects which used to be pseudo-regs + may be clobbered to refer to the frame-pointer register. + But references that were originally to the frame-pointer can be + distinguished from the others because they contain frame_pointer_rtx. + + When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little + tricky: until register elimination has taken place hard_frame_pointer_rtx + should be used if it is being set, and frame_pointer_rtx otherwise. After + register elimination hard_frame_pointer_rtx should always be used. + On machines where the two registers are same (most) then these are the + same. + + In an inline procedure, the stack and frame pointer rtxs may not be + used for anything else. */ +rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */ +rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */ +rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */ +rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */ +rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */ +rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */ +rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */ +rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */ +rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */ + +rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */ +rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */ +rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */ +rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */ + +/* We make one copy of (const_int C) where C is in + [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT] + to save space during the compilation and simplify comparisons of + integers. */ + +#define MAX_SAVED_CONST_INT 64 + +static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1]; + +/* The ends of the doubly-linked chain of rtl for the current function. + Both are reset to null at the start of rtl generation for the function. + + start_sequence saves both of these on `sequence_stack' along with + `sequence_rtl_expr' and then starts a new, nested sequence of insns. */ + +static rtx first_insn = NULL; +static rtx last_insn = NULL; + +/* RTL_EXPR within which the current sequence will be placed. Use to + prevent reuse of any temporaries within the sequence until after the + RTL_EXPR is emitted. */ + +tree sequence_rtl_expr = NULL; + +/* INSN_UID for next insn emitted. + Reset to 1 for each function compiled. */ + +static int cur_insn_uid = 1; + +/* Line number and source file of the last line-number NOTE emitted. + This is used to avoid generating duplicates. */ + +static int last_linenum = 0; +static char *last_filename = 0; + +/* A vector indexed by pseudo reg number. The allocated length + of this vector is regno_pointer_flag_length. Since this + vector is needed during the expansion phase when the total + number of registers in the function is not yet known, + it is copied and made bigger when necessary. */ + +char *regno_pointer_flag; +int regno_pointer_flag_length; + +/* Indexed by pseudo register number, gives the rtx for that pseudo. + Allocated in parallel with regno_pointer_flag. */ + +rtx *regno_reg_rtx; + +/* Stack of pending (incomplete) sequences saved by `start_sequence'. + Each element describes one pending sequence. + The main insn-chain is saved in the last element of the chain, + unless the chain is empty. */ + +struct sequence_stack *sequence_stack; + +/* start_sequence and gen_sequence can make a lot of rtx expressions which are + shortly thrown away. We use two mechanisms to prevent this waste: + + First, we keep a list of the expressions used to represent the sequence + stack in sequence_element_free_list. + + Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated + rtvec for use by gen_sequence. One entry for each size is sufficient + because most cases are calls to gen_sequence followed by immediately + emitting the SEQUENCE. Reuse is safe since emitting a sequence is + destructive on the insn in it anyway and hence can't be redone. + + We do not bother to save this cached data over nested function calls. + Instead, we just reinitialize them. */ + +#define SEQUENCE_RESULT_SIZE 5 + +static struct sequence_stack *sequence_element_free_list; +static rtx sequence_result[SEQUENCE_RESULT_SIZE]; + +extern int rtx_equal_function_value_matters; + +/* Filename and line number of last line-number note, + whether we actually emitted it or not. */ +extern char *emit_filename; +extern int emit_lineno; + +rtx change_address (); +void init_emit (); + +extern struct obstack *rtl_obstack; + +extern int stack_depth; +extern int max_stack_depth; + +/* rtx gen_rtx (code, mode, [element1, ..., elementn]) +** +** This routine generates an RTX of the size specified by +** , which is an RTX code. The RTX structure is initialized +** from the arguments through , which are +** interpreted according to the specific RTX type's format. The +** special machine mode associated with the rtx (if any) is specified +** in . +** +** gen_rtx can be invoked in a way which resembles the lisp-like +** rtx it will generate. For example, the following rtx structure: +** +** (plus:QI (mem:QI (reg:SI 1)) +** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3)))) +** +** ...would be generated by the following C code: +** +** gen_rtx (PLUS, QImode, +** gen_rtx (MEM, QImode, +** gen_rtx (REG, SImode, 1)), +** gen_rtx (MEM, QImode, +** gen_rtx (PLUS, SImode, +** gen_rtx (REG, SImode, 2), +** gen_rtx (REG, SImode, 3)))), +*/ + +/*VARARGS2*/ +rtx +gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...)) +{ +#ifndef __STDC__ + enum rtx_code code; + enum machine_mode mode; +#endif + va_list p; + register int i; /* Array indices... */ + register char *fmt; /* Current rtx's format... */ + register rtx rt_val; /* RTX to return to caller... */ + + VA_START (p, mode); + +#ifndef __STDC__ + code = va_arg (p, enum rtx_code); + mode = va_arg (p, enum machine_mode); +#endif + + if (code == CONST_INT) + { + HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT); + + if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT) + return const_int_rtx[arg + MAX_SAVED_CONST_INT]; + + if (const_true_rtx && arg == STORE_FLAG_VALUE) + return const_true_rtx; + + rt_val = rtx_alloc (code); + INTVAL (rt_val) = arg; + } + else if (code == REG) + { + int regno = va_arg (p, int); + + /* In case the MD file explicitly references the frame pointer, have + all such references point to the same frame pointer. This is used + during frame pointer elimination to distinguish the explicit + references to these registers from pseudos that happened to be + assigned to them. + + If we have eliminated the frame pointer or arg pointer, we will + be using it as a normal register, for example as a spill register. + In such cases, we might be accessing it in a mode that is not + Pmode and therefore cannot use the pre-allocated rtx. + + Also don't do this when we are making new REGs in reload, + since we don't want to get confused with the real pointers. */ + + if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode + && ! reload_in_progress) + return frame_pointer_rtx; +#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM + if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM + && mode == Pmode && ! reload_in_progress) + return hard_frame_pointer_rtx; +#endif +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode + && ! reload_in_progress) + return arg_pointer_rtx; +#endif + if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode + && ! reload_in_progress) + return stack_pointer_rtx; + else + { + rt_val = rtx_alloc (code); + rt_val->mode = mode; + REGNO (rt_val) = regno; + return rt_val; + } + } + else + { + rt_val = rtx_alloc (code); /* Allocate the storage space. */ + rt_val->mode = mode; /* Store the machine mode... */ + + fmt = GET_RTX_FORMAT (code); /* Find the right format... */ + for (i = 0; i < GET_RTX_LENGTH (code); i++) + { + switch (*fmt++) + { + case '0': /* Unused field. */ + break; + + case 'i': /* An integer? */ + XINT (rt_val, i) = va_arg (p, int); + break; + + case 'w': /* A wide integer? */ + XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT); + break; + + case 's': /* A string? */ + XSTR (rt_val, i) = va_arg (p, char *); + break; + + case 'e': /* An expression? */ + case 'u': /* An insn? Same except when printing. */ + XEXP (rt_val, i) = va_arg (p, rtx); + break; + + case 'E': /* An RTX vector? */ + XVEC (rt_val, i) = va_arg (p, rtvec); + break; + + default: + abort (); + } + } + } + va_end (p); + return rt_val; /* Return the new RTX... */ +} + +/* gen_rtvec (n, [rt1, ..., rtn]) +** +** This routine creates an rtvec and stores within it the +** pointers to rtx's which are its arguments. +*/ + +/*VARARGS1*/ +rtvec +gen_rtvec VPROTO((int n, ...)) +{ +#ifndef __STDC__ + int n; +#endif + int i; + va_list p; + rtx *vector; + + VA_START (p, n); + +#ifndef __STDC__ + n = va_arg (p, int); +#endif + + if (n == 0) + return NULL_RTVEC; /* Don't allocate an empty rtvec... */ + + vector = (rtx *) alloca (n * sizeof (rtx)); + + for (i = 0; i < n; i++) + vector[i] = va_arg (p, rtx); + va_end (p); + + return gen_rtvec_v (n, vector); +} + +rtvec +gen_rtvec_v (n, argp) + int n; + rtx *argp; +{ + register int i; + register rtvec rt_val; + + if (n == 0) + return NULL_RTVEC; /* Don't allocate an empty rtvec... */ + + rt_val = rtvec_alloc (n); /* Allocate an rtvec... */ + + for (i = 0; i < n; i++) + rt_val->elem[i].rtx = *argp++; + + return rt_val; +} + +/* Generate a REG rtx for a new pseudo register of mode MODE. + This pseudo is assigned the next sequential register number. */ + +rtx +gen_reg_rtx (mode) + enum machine_mode mode; +{ + register rtx val; + + /* Don't let anything called by or after reload create new registers + (actually, registers can't be created after flow, but this is a good + approximation). */ + + if (reload_in_progress || reload_completed) + abort (); + + if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT + || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT) + { + /* For complex modes, don't make a single pseudo. + Instead, make a CONCAT of two pseudos. + This allows noncontiguous allocation of the real and imaginary parts, + which makes much better code. Besides, allocating DCmode + pseudos overstrains reload on some machines like the 386. */ + rtx realpart, imagpart; + int size = GET_MODE_UNIT_SIZE (mode); + enum machine_mode partmode + = mode_for_size (size * BITS_PER_UNIT, + (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT + ? MODE_FLOAT : MODE_INT), + 0); + + realpart = gen_reg_rtx (partmode); + imagpart = gen_reg_rtx (partmode); + return gen_rtx (CONCAT, mode, realpart, imagpart); + } + + /* Make sure regno_pointer_flag and regno_reg_rtx are large + enough to have an element for this pseudo reg number. */ + + if (reg_rtx_no == regno_pointer_flag_length) + { + rtx *new1; + char *new = + (char *) oballoc (regno_pointer_flag_length * 2); + bcopy (regno_pointer_flag, new, regno_pointer_flag_length); + bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length); + regno_pointer_flag = new; + + new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx)); + bcopy ((char *) regno_reg_rtx, (char *) new1, + regno_pointer_flag_length * sizeof (rtx)); + bzero ((char *) &new1[regno_pointer_flag_length], + regno_pointer_flag_length * sizeof (rtx)); + regno_reg_rtx = new1; + + regno_pointer_flag_length *= 2; + } + + val = gen_rtx (REG, mode, reg_rtx_no); + regno_reg_rtx[reg_rtx_no++] = val; + return val; +} + +/* Identify REG as a probable pointer register. */ + +void +mark_reg_pointer (reg) + rtx reg; +{ + REGNO_POINTER_FLAG (REGNO (reg)) = 1; +} + +/* Return 1 plus largest pseudo reg number used in the current function. */ + +int +max_reg_num () +{ + return reg_rtx_no; +} + +/* Return 1 + the largest label number used so far in the current function. */ + +int +max_label_num () +{ + if (last_label_num && label_num == base_label_num) + return last_label_num; + return label_num; +} + +/* Return first label number used in this function (if any were used). */ + +int +get_first_label_num () +{ + return first_label_num; +} + +/* Return a value representing some low-order bits of X, where the number + of low-order bits is given by MODE. Note that no conversion is done + between floating-point and fixed-point values, rather, the bit + representation is returned. + + This function handles the cases in common between gen_lowpart, below, + and two variants in cse.c and combine.c. These are the cases that can + be safely handled at all points in the compilation. + + If this is not a case we can handle, return 0. */ + +rtx +gen_lowpart_common (mode, x) + enum machine_mode mode; + register rtx x; +{ + int word = 0; + + if (GET_MODE (x) == mode) + return x; + + /* MODE must occupy no more words than the mode of X. */ + if (GET_MODE (x) != VOIDmode + && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD + > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1)) + / UNITS_PER_WORD))) + return 0; + + if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) + word = ((GET_MODE_SIZE (GET_MODE (x)) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)) + / UNITS_PER_WORD); + + if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND) + && (GET_MODE_CLASS (mode) == MODE_INT + || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)) + { + /* If we are getting the low-order part of something that has been + sign- or zero-extended, we can either just use the object being + extended or make a narrower extension. If we want an even smaller + piece than the size of the object being extended, call ourselves + recursively. + + This case is used mostly by combine and cse. */ + + if (GET_MODE (XEXP (x, 0)) == mode) + return XEXP (x, 0); + else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0)))) + return gen_lowpart_common (mode, XEXP (x, 0)); + else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x))) + return gen_rtx (GET_CODE (x), mode, XEXP (x, 0)); + } + else if (GET_CODE (x) == SUBREG + && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD + || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x)))) + return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0 + ? SUBREG_REG (x) + : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x))); + else if (GET_CODE (x) == REG) + { + /* If the register is not valid for MODE, return 0. If we don't + do this, there is no way to fix up the resulting REG later. + But we do do this if the current REG is not valid for its + mode. This latter is a kludge, but is required due to the + way that parameters are passed on some machines, most + notably Sparc. */ + if (REGNO (x) < FIRST_PSEUDO_REGISTER + && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode) + && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x))) + return 0; + else if (REGNO (x) < FIRST_PSEUDO_REGISTER + /* integrate.c can't handle parts of a return value register. */ + && (! REG_FUNCTION_VALUE_P (x) + || ! rtx_equal_function_value_matters) + /* We want to keep the stack, frame, and arg pointers + special. */ + && x != frame_pointer_rtx +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + && x != arg_pointer_rtx +#endif + && x != stack_pointer_rtx) + return gen_rtx (REG, mode, REGNO (x) + word); + else + return gen_rtx (SUBREG, mode, x, word); + } + /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits + from the low-order part of the constant. */ + else if ((GET_MODE_CLASS (mode) == MODE_INT + || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) + && GET_MODE (x) == VOIDmode + && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) + { + /* If MODE is twice the host word size, X is already the desired + representation. Otherwise, if MODE is wider than a word, we can't + do this. If MODE is exactly a word, return just one CONST_INT. + If MODE is smaller than a word, clear the bits that don't belong + in our mode, unless they and our sign bit are all one. So we get + either a reasonable negative value or a reasonable unsigned value + for this mode. */ + + if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT) + return x; + else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) + return 0; + else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT) + return (GET_CODE (x) == CONST_INT ? x + : GEN_INT (CONST_DOUBLE_LOW (x))); + else + { + /* MODE must be narrower than HOST_BITS_PER_INT. */ + int width = GET_MODE_BITSIZE (mode); + HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x) + : CONST_DOUBLE_LOW (x)); + + if (((val & ((HOST_WIDE_INT) (-1) << (width - 1))) + != ((HOST_WIDE_INT) (-1) << (width - 1)))) + val &= ((HOST_WIDE_INT) 1 << width) - 1; + + return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x + : GEN_INT (val)); + } + } + + /* If X is an integral constant but we want it in floating-point, it + must be the case that we have a union of an integer and a floating-point + value. If the machine-parameters allow it, simulate that union here + and return the result. The two-word and single-word cases are + different. */ + + else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_SIZE (mode) == UNITS_PER_WORD + && GET_CODE (x) == CONST_INT + && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT) +#ifdef REAL_ARITHMETIC + { + REAL_VALUE_TYPE r; + HOST_WIDE_INT i; + + i = INTVAL (x); + r = REAL_VALUE_FROM_TARGET_SINGLE (i); + return CONST_DOUBLE_FROM_REAL_VALUE (r, mode); + } +#else + { + union {HOST_WIDE_INT i; float d; } u; + + u.i = INTVAL (x); + return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode); + } +#endif + else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD + && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) + && GET_MODE (x) == VOIDmode + && (sizeof (double) * HOST_BITS_PER_CHAR + == 2 * HOST_BITS_PER_WIDE_INT)) +#ifdef REAL_ARITHMETIC + { + REAL_VALUE_TYPE r; + HOST_WIDE_INT i[2]; + HOST_WIDE_INT low, high; + + if (GET_CODE (x) == CONST_INT) + low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1); + else + low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x); + + /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the + target machine. */ + if (WORDS_BIG_ENDIAN) + i[0] = high, i[1] = low; + else + i[0] = low, i[1] = high; + + r = REAL_VALUE_FROM_TARGET_DOUBLE (i); + return CONST_DOUBLE_FROM_REAL_VALUE (r, mode); + } +#else + { + union {HOST_WIDE_INT i[2]; double d; } u; + HOST_WIDE_INT low, high; + + if (GET_CODE (x) == CONST_INT) + low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1); + else + low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x); + +#ifdef HOST_WORDS_BIG_ENDIAN + u.i[0] = high, u.i[1] = low; +#else + u.i[0] = low, u.i[1] = high; +#endif + + return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode); + } +#endif + /* Similarly, if this is converting a floating-point value into a + single-word integer. Only do this is the host and target parameters are + compatible. */ + + else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && (GET_MODE_CLASS (mode) == MODE_INT + || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) + && GET_CODE (x) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT + && GET_MODE_BITSIZE (mode) == BITS_PER_WORD) + return operand_subword (x, 0, 0, GET_MODE (x)); + + /* Similarly, if this is converting a floating-point value into a + two-word integer, we can do this one word at a time and make an + integer. Only do this is the host and target parameters are + compatible. */ + + else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && (GET_MODE_CLASS (mode) == MODE_INT + || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT) + && GET_CODE (x) == CONST_DOUBLE + && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT + && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD) + { + rtx lowpart = operand_subword (x, WORDS_BIG_ENDIAN, 0, GET_MODE (x)); + rtx highpart = operand_subword (x, ! WORDS_BIG_ENDIAN, 0, GET_MODE (x)); + + if (lowpart && GET_CODE (lowpart) == CONST_INT + && highpart && GET_CODE (highpart) == CONST_INT) + return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode); + } + + /* Otherwise, we can't do this. */ + return 0; +} + +/* Return the real part (which has mode MODE) of a complex value X. + This always comes at the low address in memory. */ + +rtx +gen_realpart (mode, x) + enum machine_mode mode; + register rtx x; +{ + if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode) + return XEXP (x, 0); + else if (WORDS_BIG_ENDIAN) + return gen_highpart (mode, x); + else + return gen_lowpart (mode, x); +} + +/* Return the imaginary part (which has mode MODE) of a complex value X. + This always comes at the high address in memory. */ + +rtx +gen_imagpart (mode, x) + enum machine_mode mode; + register rtx x; +{ + if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode) + return XEXP (x, 1); + else if (WORDS_BIG_ENDIAN) + return gen_lowpart (mode, x); + else + return gen_highpart (mode, x); +} + +/* Return 1 iff X, assumed to be a SUBREG, + refers to the real part of the complex value in its containing reg. + Complex values are always stored with the real part in the first word, + regardless of WORDS_BIG_ENDIAN. */ + +int +subreg_realpart_p (x) + rtx x; +{ + if (GET_CODE (x) != SUBREG) + abort (); + + return SUBREG_WORD (x) == 0; +} + +/* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value, + return an rtx (MEM, SUBREG, or CONST_INT) that refers to the + least-significant part of X. + MODE specifies how big a part of X to return; + it usually should not be larger than a word. + If X is a MEM whose address is a QUEUED, the value may be so also. */ + +rtx +gen_lowpart (mode, x) + enum machine_mode mode; + register rtx x; +{ + rtx result = gen_lowpart_common (mode, x); + + if (result) + return result; + else if (GET_CODE (x) == REG) + { + /* Must be a hard reg that's not valid in MODE. */ + result = gen_lowpart_common (mode, copy_to_reg (x)); + if (result == 0) + abort (); + } + else if (GET_CODE (x) == MEM) + { + /* The only additional case we can do is MEM. */ + register int offset = 0; + if (WORDS_BIG_ENDIAN) + offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); + + if (BYTES_BIG_ENDIAN) + /* Adjust the address so that the address-after-the-data + is unchanged. */ + offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)) + - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))); + + return change_address (x, mode, plus_constant (XEXP (x, 0), offset)); + } + else + abort (); +} + +/* Like `gen_lowpart', but refer to the most significant part. + This is used to access the imaginary part of a complex number. */ + +rtx +gen_highpart (mode, x) + enum machine_mode mode; + register rtx x; +{ + /* This case loses if X is a subreg. To catch bugs early, + complain if an invalid MODE is used even in other cases. */ + if (GET_MODE_SIZE (mode) > UNITS_PER_WORD + && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x))) + abort (); + if (GET_CODE (x) == CONST_DOUBLE +#if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE)) + && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT +#endif + ) + return gen_rtx (CONST_INT, VOIDmode, + CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode)); + else if (GET_CODE (x) == CONST_INT) + return const0_rtx; + else if (GET_CODE (x) == MEM) + { + register int offset = 0; + if (! WORDS_BIG_ENDIAN) + offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)); + + if (! BYTES_BIG_ENDIAN + && GET_MODE_SIZE (mode) < UNITS_PER_WORD) + offset -= (GET_MODE_SIZE (mode) + - MIN (UNITS_PER_WORD, + GET_MODE_SIZE (GET_MODE (x)))); + + return change_address (x, mode, plus_constant (XEXP (x, 0), offset)); + } + else if (GET_CODE (x) == SUBREG) + { + /* The only time this should occur is when we are looking at a + multi-word item with a SUBREG whose mode is the same as that of the + item. It isn't clear what we would do if it wasn't. */ + if (SUBREG_WORD (x) != 0) + abort (); + return gen_highpart (mode, SUBREG_REG (x)); + } + else if (GET_CODE (x) == REG) + { + int word = 0; + + if (! WORDS_BIG_ENDIAN + && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD) + word = ((GET_MODE_SIZE (GET_MODE (x)) + - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD)) + / UNITS_PER_WORD); + + /* + * ??? This fails miserably for complex values being passed in registers + * where the sizeof the real and imaginary part are not equal to the + * sizeof SImode. FIXME + */ + + if (REGNO (x) < FIRST_PSEUDO_REGISTER + /* integrate.c can't handle parts of a return value register. */ + && (! REG_FUNCTION_VALUE_P (x) + || ! rtx_equal_function_value_matters) + /* We want to keep the stack, frame, and arg pointers special. */ + && x != frame_pointer_rtx +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + && x != arg_pointer_rtx +#endif + && x != stack_pointer_rtx) + return gen_rtx (REG, mode, REGNO (x) + word); + else + return gen_rtx (SUBREG, mode, x, word); + } + else + abort (); +} + +/* Return 1 iff X, assumed to be a SUBREG, + refers to the least significant part of its containing reg. + If X is not a SUBREG, always return 1 (it is its own low part!). */ + +int +subreg_lowpart_p (x) + rtx x; +{ + if (GET_CODE (x) != SUBREG) + return 1; + + if (WORDS_BIG_ENDIAN + && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD) + return (SUBREG_WORD (x) + == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) + - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)) + / UNITS_PER_WORD)); + + return SUBREG_WORD (x) == 0; +} + +/* Return subword I of operand OP. + The word number, I, is interpreted as the word number starting at the + low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN, + otherwise it is the high-order word. + + If we cannot extract the required word, we return zero. Otherwise, an + rtx corresponding to the requested word will be returned. + + VALIDATE_ADDRESS is nonzero if the address should be validated. Before + reload has completed, a valid address will always be returned. After + reload, if a valid address cannot be returned, we return zero. + + If VALIDATE_ADDRESS is zero, we simply form the required address; validating + it is the responsibility of the caller. + + MODE is the mode of OP in case it is a CONST_INT. */ + +rtx +operand_subword (op, i, validate_address, mode) + rtx op; + int i; + int validate_address; + enum machine_mode mode; +{ + HOST_WIDE_INT val; + int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD; + + if (mode == VOIDmode) + mode = GET_MODE (op); + + if (mode == VOIDmode) + abort (); + + /* If OP is narrower than a word or if we want a word outside OP, fail. */ + if (mode != BLKmode + && (GET_MODE_SIZE (mode) < UNITS_PER_WORD + || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))) + return 0; + + /* If OP is already an integer word, return it. */ + if (GET_MODE_CLASS (mode) == MODE_INT + && GET_MODE_SIZE (mode) == UNITS_PER_WORD) + return op; + + /* If OP is a REG or SUBREG, we can handle it very simply. */ + if (GET_CODE (op) == REG) + { + /* If the register is not valid for MODE, return 0. If we don't + do this, there is no way to fix up the resulting REG later. */ + if (REGNO (op) < FIRST_PSEUDO_REGISTER + && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode)) + return 0; + else if (REGNO (op) >= FIRST_PSEUDO_REGISTER + || (REG_FUNCTION_VALUE_P (op) + && rtx_equal_function_value_matters) + /* We want to keep the stack, frame, and arg pointers + special. */ + || op == frame_pointer_rtx +#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM + || op == arg_pointer_rtx +#endif + || op == stack_pointer_rtx) + return gen_rtx (SUBREG, word_mode, op, i); + else + return gen_rtx (REG, word_mode, REGNO (op) + i); + } + else if (GET_CODE (op) == SUBREG) + return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op)); + else if (GET_CODE (op) == CONCAT) + { + int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD; + if (i < partwords) + return operand_subword (XEXP (op, 0), i, validate_address, mode); + return operand_subword (XEXP (op, 1), i - partwords, + validate_address, mode); + } + + /* Form a new MEM at the requested address. */ + if (GET_CODE (op) == MEM) + { + rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD); + rtx new; + + if (validate_address) + { + if (reload_completed) + { + if (! strict_memory_address_p (word_mode, addr)) + return 0; + } + else + addr = memory_address (word_mode, addr); + } + + new = gen_rtx (MEM, word_mode, addr); + + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op); + + return new; + } + + /* The only remaining cases are when OP is a constant. If the host and + target floating formats are the same, handling two-word floating + constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE} + are defined as returning one or two 32 bit values, respectively, + and not values of BITS_PER_WORD bits. */ +#ifdef REAL_ARITHMETIC +/* The output is some bits, the width of the target machine's word. + A wider-word host can surely hold them in a CONST_INT. A narrower-word + host can't. */ + if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD + && GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_BITSIZE (mode) == 64 + && GET_CODE (op) == CONST_DOUBLE) + { + long k[2]; + REAL_VALUE_TYPE rv; + + REAL_VALUE_FROM_CONST_DOUBLE (rv, op); + REAL_VALUE_TO_TARGET_DOUBLE (rv, k); + + /* We handle 32-bit and >= 64-bit words here. Note that the order in + which the words are written depends on the word endianness. + + ??? This is a potential portability problem and should + be fixed at some point. */ + if (BITS_PER_WORD == 32) + return GEN_INT ((HOST_WIDE_INT) k[i]); +#if HOST_BITS_PER_WIDE_INT > 32 + else if (BITS_PER_WORD >= 64 && i == 0) + return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32) + | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]); +#endif + else if (BITS_PER_WORD == 16) + { + long value; + value = k[i >> 1]; + if ((i & 0x1) == 0) + value >>= 16; + value &= 0xffff; + return GEN_INT ((HOST_WIDE_INT) value); + } + else + abort (); + } +#else /* no REAL_ARITHMETIC */ + if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD + && GET_CODE (op) == CONST_DOUBLE) + { + /* The constant is stored in the host's word-ordering, + but we want to access it in the target's word-ordering. Some + compilers don't like a conditional inside macro args, so we have two + copies of the return. */ +#ifdef HOST_WORDS_BIG_ENDIAN + return GEN_INT (i == WORDS_BIG_ENDIAN + ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op)); +#else + return GEN_INT (i != WORDS_BIG_ENDIAN + ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op)); +#endif + } +#endif /* no REAL_ARITHMETIC */ + + /* Single word float is a little harder, since single- and double-word + values often do not have the same high-order bits. We have already + verified that we want the only defined word of the single-word value. */ +#ifdef REAL_ARITHMETIC + if (GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_BITSIZE (mode) == 32 + && GET_CODE (op) == CONST_DOUBLE) + { + long l; + REAL_VALUE_TYPE rv; + + REAL_VALUE_FROM_CONST_DOUBLE (rv, op); + REAL_VALUE_TO_TARGET_SINGLE (rv, l); + return GEN_INT ((HOST_WIDE_INT) l); + } +#else + if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT + && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD) + || flag_pretend_float) + && GET_MODE_CLASS (mode) == MODE_FLOAT + && GET_MODE_SIZE (mode) == UNITS_PER_WORD + && GET_CODE (op) == CONST_DOUBLE) + { + double d; + union {float f; HOST_WIDE_INT i; } u; + + REAL_VALUE_FROM_CONST_DOUBLE (d, op); + + u.f = d; + return GEN_INT (u.i); + } +#endif /* no REAL_ARITHMETIC */ + + /* The only remaining cases that we can handle are integers. + Convert to proper endianness now since these cases need it. + At this point, i == 0 means the low-order word. + + We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT + in general. However, if OP is (const_int 0), we can just return + it for any word. */ + + if (op == const0_rtx) + return op; + + if (GET_MODE_CLASS (mode) != MODE_INT + || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE) + || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT) + return 0; + + if (WORDS_BIG_ENDIAN) + i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i; + + /* Find out which word on the host machine this value is in and get + it from the constant. */ + val = (i / size_ratio == 0 + ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op)) + : (GET_CODE (op) == CONST_INT + ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op))); + + /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */ + if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT) + val = ((val >> ((i % size_ratio) * BITS_PER_WORD)) + & (((HOST_WIDE_INT) 1 + << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1)); + + return GEN_INT (val); +} + +/* Similar to `operand_subword', but never return 0. If we can't extract + the required subword, put OP into a register and try again. If that fails, + abort. We always validate the address in this case. It is not valid + to call this function after reload; it is mostly meant for RTL + generation. + + MODE is the mode of OP, in case it is CONST_INT. */ + +rtx +operand_subword_force (op, i, mode) + rtx op; + int i; + enum machine_mode mode; +{ + rtx result = operand_subword (op, i, 1, mode); + + if (result) + return result; + + if (mode != BLKmode && mode != VOIDmode) + op = force_reg (mode, op); + + result = operand_subword (op, i, 1, mode); + if (result == 0) + abort (); + + return result; +} + +/* Given a compare instruction, swap the operands. + A test instruction is changed into a compare of 0 against the operand. */ + +void +reverse_comparison (insn) + rtx insn; +{ + rtx body = PATTERN (insn); + rtx comp; + + if (GET_CODE (body) == SET) + comp = SET_SRC (body); + else + comp = SET_SRC (XVECEXP (body, 0, 0)); + + if (GET_CODE (comp) == COMPARE) + { + rtx op0 = XEXP (comp, 0); + rtx op1 = XEXP (comp, 1); + XEXP (comp, 0) = op1; + XEXP (comp, 1) = op0; + } + else + { + rtx new = gen_rtx (COMPARE, VOIDmode, + CONST0_RTX (GET_MODE (comp)), comp); + if (GET_CODE (body) == SET) + SET_SRC (body) = new; + else + SET_SRC (XVECEXP (body, 0, 0)) = new; + } +} + +/* Return a memory reference like MEMREF, but with its mode changed + to MODE and its address changed to ADDR. + (VOIDmode means don't change the mode. + NULL for ADDR means don't change the address.) */ + +rtx +change_address (memref, mode, addr) + rtx memref; + enum machine_mode mode; + rtx addr; +{ + rtx new; + + if (GET_CODE (memref) != MEM) + abort (); + if (mode == VOIDmode) + mode = GET_MODE (memref); + if (addr == 0) + addr = XEXP (memref, 0); + + /* If reload is in progress or has completed, ADDR must be valid. + Otherwise, we can call memory_address to make it valid. */ + if (reload_completed || reload_in_progress) + { + if (! memory_address_p (mode, addr)) + abort (); + } + else + addr = memory_address (mode, addr); + + new = gen_rtx (MEM, mode, addr); + MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref); + RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref); + MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref); + return new; +} + +/* Return a newly created CODE_LABEL rtx with a unique label number. */ + +rtx +gen_label_rtx () +{ + register rtx label; + + label = (output_bytecode + ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ()) + : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR)); + + LABEL_NUSES (label) = 0; + return label; +} + +/* For procedure integration. */ + +/* Return a newly created INLINE_HEADER rtx. Should allocate this + from a permanent obstack when the opportunity arises. */ + +rtx +gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno, + last_labelno, max_parm_regnum, max_regnum, args_size, + pops_args, stack_slots, forced_labels, function_flags, + outgoing_args_size, original_arg_vector, + original_decl_initial) + rtx first_insn, first_parm_insn; + int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size; + int pops_args; + rtx stack_slots; + rtx forced_labels; + int function_flags; + int outgoing_args_size; + rtvec original_arg_vector; + rtx original_decl_initial; +{ + rtx header = gen_rtx (INLINE_HEADER, VOIDmode, + cur_insn_uid++, NULL_RTX, + first_insn, first_parm_insn, + first_labelno, last_labelno, + max_parm_regnum, max_regnum, args_size, pops_args, + stack_slots, forced_labels, function_flags, + outgoing_args_size, + original_arg_vector, original_decl_initial); + return header; +} + +/* Install new pointers to the first and last insns in the chain. + Used for an inline-procedure after copying the insn chain. */ + +void +set_new_first_and_last_insn (first, last) + rtx first, last; +{ + first_insn = first; + last_insn = last; +} + +/* Set the range of label numbers found in the current function. + This is used when belatedly compiling an inline function. */ + +void +set_new_first_and_last_label_num (first, last) + int first, last; +{ + base_label_num = label_num; + first_label_num = first; + last_label_num = last; +} + +/* Save all variables describing the current status into the structure *P. + This is used before starting a nested function. */ + +void +save_emit_status (p) + struct function *p; +{ + p->reg_rtx_no = reg_rtx_no; + p->first_label_num = first_label_num; + p->first_insn = first_insn; + p->last_insn = last_insn; + p->sequence_rtl_expr = sequence_rtl_expr; + p->sequence_stack = sequence_stack; + p->cur_insn_uid = cur_insn_uid; + p->last_linenum = last_linenum; + p->last_filename = last_filename; + p->regno_pointer_flag = regno_pointer_flag; + p->regno_pointer_flag_length = regno_pointer_flag_length; + p->regno_reg_rtx = regno_reg_rtx; +} + +/* Restore all variables describing the current status from the structure *P. + This is used after a nested function. */ + +void +restore_emit_status (p) + struct function *p; +{ + int i; + + reg_rtx_no = p->reg_rtx_no; + first_label_num = p->first_label_num; + last_label_num = 0; + first_insn = p->first_insn; + last_insn = p->last_insn; + sequence_rtl_expr = p->sequence_rtl_expr; + sequence_stack = p->sequence_stack; + cur_insn_uid = p->cur_insn_uid; + last_linenum = p->last_linenum; + last_filename = p->last_filename; + regno_pointer_flag = p->regno_pointer_flag; + regno_pointer_flag_length = p->regno_pointer_flag_length; + regno_reg_rtx = p->regno_reg_rtx; + + /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */ + sequence_element_free_list = 0; + for (i = 0; i < SEQUENCE_RESULT_SIZE; i++) + sequence_result[i] = 0; +} + +/* Go through all the RTL insn bodies and copy any invalid shared structure. + It does not work to do this twice, because the mark bits set here + are not cleared afterwards. */ + +void +unshare_all_rtl (insn) + register rtx insn; +{ + for (; insn; insn = NEXT_INSN (insn)) + if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN + || GET_CODE (insn) == CALL_INSN) + { + PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn)); + REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn)); + LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn)); + } + + /* Make sure the addresses of stack slots found outside the insn chain + (such as, in DECL_RTL of a variable) are not shared + with the insn chain. + + This special care is necessary when the stack slot MEM does not + actually appear in the insn chain. If it does appear, its address + is unshared from all else at that point. */ + + copy_rtx_if_shared (stack_slot_list); +} + +/* Mark ORIG as in use, and return a copy of it if it was already in use. + Recursively does the same for subexpressions. */ + +rtx +copy_rtx_if_shared (orig) + rtx orig; +{ + register rtx x = orig; + register int i; + register enum rtx_code code; + register char *format_ptr; + int copied = 0; + + if (x == 0) + return 0; + + code = GET_CODE (x); + + /* These types may be freely shared. */ + + switch (code) + { + case REG: + case QUEUED: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case CODE_LABEL: + case PC: + case CC0: + case SCRATCH: + /* SCRATCH must be shared because they represent distinct values. */ + return x; + + case CONST: + /* CONST can be shared if it contains a SYMBOL_REF. If it contains + a LABEL_REF, it isn't sharable. */ + if (GET_CODE (XEXP (x, 0)) == PLUS + && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF + && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT) + return x; + break; + + case INSN: + case JUMP_INSN: + case CALL_INSN: + case NOTE: + case BARRIER: + /* The chain of insns is not being copied. */ + return x; + + case MEM: + /* A MEM is allowed to be shared if its address is constant + or is a constant plus one of the special registers. */ + if (CONSTANT_ADDRESS_P (XEXP (x, 0)) + || XEXP (x, 0) == virtual_stack_vars_rtx + || XEXP (x, 0) == virtual_incoming_args_rtx) + return x; + + if (GET_CODE (XEXP (x, 0)) == PLUS + && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx + || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx) + && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1))) + { + /* This MEM can appear in more than one place, + but its address better not be shared with anything else. */ + if (! x->used) + XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0)); + x->used = 1; + return x; + } + } + + /* This rtx may not be shared. If it has already been seen, + replace it with a copy of itself. */ + + if (x->used) + { + register rtx copy; + + copy = rtx_alloc (code); + bcopy ((char *) x, (char *) copy, + (sizeof (*copy) - sizeof (copy->fld) + + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code))); + x = copy; + copied = 1; + } + x->used = 1; + + /* Now scan the subexpressions recursively. + We can store any replaced subexpressions directly into X + since we know X is not shared! Any vectors in X + must be copied if X was copied. */ + + format_ptr = GET_RTX_FORMAT (code); + + for (i = 0; i < GET_RTX_LENGTH (code); i++) + { + switch (*format_ptr++) + { + case 'e': + XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i)); + break; + + case 'E': + if (XVEC (x, i) != NULL) + { + register int j; + int len = XVECLEN (x, i); + + if (copied && len > 0) + XVEC (x, i) = gen_rtvec_v (len, &XVECEXP (x, i, 0)); + for (j = 0; j < len; j++) + XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j)); + } + break; + } + } + return x; +} + +/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used + to look for shared sub-parts. */ + +void +reset_used_flags (x) + rtx x; +{ + register int i, j; + register enum rtx_code code; + register char *format_ptr; + + if (x == 0) + return; + + code = GET_CODE (x); + + /* These types may be freely shared so we needn't do any resetting + for them. */ + + switch (code) + { + case REG: + case QUEUED: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case CODE_LABEL: + case PC: + case CC0: + return; + + case INSN: + case JUMP_INSN: + case CALL_INSN: + case NOTE: + case LABEL_REF: + case BARRIER: + /* The chain of insns is not being copied. */ + return; + } + + x->used = 0; + + format_ptr = GET_RTX_FORMAT (code); + for (i = 0; i < GET_RTX_LENGTH (code); i++) + { + switch (*format_ptr++) + { + case 'e': + reset_used_flags (XEXP (x, i)); + break; + + case 'E': + for (j = 0; j < XVECLEN (x, i); j++) + reset_used_flags (XVECEXP (x, i, j)); + break; + } + } +} + +/* Copy X if necessary so that it won't be altered by changes in OTHER. + Return X or the rtx for the pseudo reg the value of X was copied into. + OTHER must be valid as a SET_DEST. */ + +rtx +make_safe_from (x, other) + rtx x, other; +{ + while (1) + switch (GET_CODE (other)) + { + case SUBREG: + other = SUBREG_REG (other); + break; + case STRICT_LOW_PART: + case SIGN_EXTEND: + case ZERO_EXTEND: + other = XEXP (other, 0); + break; + default: + goto done; + } + done: + if ((GET_CODE (other) == MEM + && ! CONSTANT_P (x) + && GET_CODE (x) != REG + && GET_CODE (x) != SUBREG) + || (GET_CODE (other) == REG + && (REGNO (other) < FIRST_PSEUDO_REGISTER + || reg_mentioned_p (other, x)))) + { + rtx temp = gen_reg_rtx (GET_MODE (x)); + emit_move_insn (temp, x); + return temp; + } + return x; +} + +/* Emission of insns (adding them to the doubly-linked list). */ + +/* Return the first insn of the current sequence or current function. */ + +rtx +get_insns () +{ + return first_insn; +} + +/* Return the last insn emitted in current sequence or current function. */ + +rtx +get_last_insn () +{ + return last_insn; +} + +/* Specify a new insn as the last in the chain. */ + +void +set_last_insn (insn) + rtx insn; +{ + if (NEXT_INSN (insn) != 0) + abort (); + last_insn = insn; +} + +/* Return the last insn emitted, even if it is in a sequence now pushed. */ + +rtx +get_last_insn_anywhere () +{ + struct sequence_stack *stack; + if (last_insn) + return last_insn; + for (stack = sequence_stack; stack; stack = stack->next) + if (stack->last != 0) + return stack->last; + return 0; +} + +/* Return a number larger than any instruction's uid in this function. */ + +int +get_max_uid () +{ + return cur_insn_uid; +} + +/* Return the next insn. If it is a SEQUENCE, return the first insn + of the sequence. */ + +rtx +next_insn (insn) + rtx insn; +{ + if (insn) + { + insn = NEXT_INSN (insn); + if (insn && GET_CODE (insn) == INSN + && GET_CODE (PATTERN (insn)) == SEQUENCE) + insn = XVECEXP (PATTERN (insn), 0, 0); + } + + return insn; +} + +/* Return the previous insn. If it is a SEQUENCE, return the last insn + of the sequence. */ + +rtx +previous_insn (insn) + rtx insn; +{ + if (insn) + { + insn = PREV_INSN (insn); + if (insn && GET_CODE (insn) == INSN + && GET_CODE (PATTERN (insn)) == SEQUENCE) + insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1); + } + + return insn; +} + +/* Return the next insn after INSN that is not a NOTE. This routine does not + look inside SEQUENCEs. */ + +rtx +next_nonnote_insn (insn) + rtx insn; +{ + while (insn) + { + insn = NEXT_INSN (insn); + if (insn == 0 || GET_CODE (insn) != NOTE) + break; + } + + return insn; +} + +/* Return the previous insn before INSN that is not a NOTE. This routine does + not look inside SEQUENCEs. */ + +rtx +prev_nonnote_insn (insn) + rtx insn; +{ + while (insn) + { + insn = PREV_INSN (insn); + if (insn == 0 || GET_CODE (insn) != NOTE) + break; + } + + return insn; +} + +/* Return the next INSN, CALL_INSN or JUMP_INSN after INSN; + or 0, if there is none. This routine does not look inside + SEQUENCEs. */ + +rtx +next_real_insn (insn) + rtx insn; +{ + while (insn) + { + insn = NEXT_INSN (insn); + if (insn == 0 || GET_CODE (insn) == INSN + || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN) + break; + } + + return insn; +} + +/* Return the last INSN, CALL_INSN or JUMP_INSN before INSN; + or 0, if there is none. This routine does not look inside + SEQUENCEs. */ + +rtx +prev_real_insn (insn) + rtx insn; +{ + while (insn) + { + insn = PREV_INSN (insn); + if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN + || GET_CODE (insn) == JUMP_INSN) + break; + } + + return insn; +} + +/* Find the next insn after INSN that really does something. This routine + does not look inside SEQUENCEs. Until reload has completed, this is the + same as next_real_insn. */ + +rtx +next_active_insn (insn) + rtx insn; +{ + while (insn) + { + insn = NEXT_INSN (insn); + if (insn == 0 + || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN + || (GET_CODE (insn) == INSN + && (! reload_completed + || (GET_CODE (PATTERN (insn)) != USE + && GET_CODE (PATTERN (insn)) != CLOBBER)))) + break; + } + + return insn; +} + +/* Find the last insn before INSN that really does something. This routine + does not look inside SEQUENCEs. Until reload has completed, this is the + same as prev_real_insn. */ + +rtx +prev_active_insn (insn) + rtx insn; +{ + while (insn) + { + insn = PREV_INSN (insn); + if (insn == 0 + || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN + || (GET_CODE (insn) == INSN + && (! reload_completed + || (GET_CODE (PATTERN (insn)) != USE + && GET_CODE (PATTERN (insn)) != CLOBBER)))) + break; + } + + return insn; +} + +/* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */ + +rtx +next_label (insn) + rtx insn; +{ + while (insn) + { + insn = NEXT_INSN (insn); + if (insn == 0 || GET_CODE (insn) == CODE_LABEL) + break; + } + + return insn; +} + +/* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */ + +rtx +prev_label (insn) + rtx insn; +{ + while (insn) + { + insn = PREV_INSN (insn); + if (insn == 0 || GET_CODE (insn) == CODE_LABEL) + break; + } + + return insn; +} + +#ifdef HAVE_cc0 +/* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER + and REG_CC_USER notes so we can find it. */ + +void +link_cc0_insns (insn) + rtx insn; +{ + rtx user = next_nonnote_insn (insn); + + if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE) + user = XVECEXP (PATTERN (user), 0, 0); + + REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn, + REG_NOTES (user)); + REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn)); +} + +/* Return the next insn that uses CC0 after INSN, which is assumed to + set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter + applied to the result of this function should yield INSN). + + Normally, this is simply the next insn. However, if a REG_CC_USER note + is present, it contains the insn that uses CC0. + + Return 0 if we can't find the insn. */ + +rtx +next_cc0_user (insn) + rtx insn; +{ + rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX); + + if (note) + return XEXP (note, 0); + + insn = next_nonnote_insn (insn); + if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE) + insn = XVECEXP (PATTERN (insn), 0, 0); + + if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i' + && reg_mentioned_p (cc0_rtx, PATTERN (insn))) + return insn; + + return 0; +} + +/* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER + note, it is the previous insn. */ + +rtx +prev_cc0_setter (insn) + rtx insn; +{ + rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX); + rtx link; + + if (note) + return XEXP (note, 0); + + insn = prev_nonnote_insn (insn); + if (! sets_cc0_p (PATTERN (insn))) + abort (); + + return insn; +} +#endif + +/* Try splitting insns that can be split for better scheduling. + PAT is the pattern which might split. + TRIAL is the insn providing PAT. + LAST is non-zero if we should return the last insn of the sequence produced. + + If this routine succeeds in splitting, it returns the first or last + replacement insn depending on the value of LAST. Otherwise, it + returns TRIAL. If the insn to be returned can be split, it will be. */ + +rtx +try_split (pat, trial, last) + rtx pat, trial; + int last; +{ + rtx before = PREV_INSN (trial); + rtx after = NEXT_INSN (trial); + rtx seq = split_insns (pat, trial); + int has_barrier = 0; + rtx tem; + + /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER. + We may need to handle this specially. */ + if (after && GET_CODE (after) == BARRIER) + { + has_barrier = 1; + after = NEXT_INSN (after); + } + + if (seq) + { + /* SEQ can either be a SEQUENCE or the pattern of a single insn. + The latter case will normally arise only when being done so that + it, in turn, will be split (SFmode on the 29k is an example). */ + if (GET_CODE (seq) == SEQUENCE) + { + /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in + SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero, + increment the usage count so we don't delete the label. */ + int i; + + if (GET_CODE (trial) == JUMP_INSN) + for (i = XVECLEN (seq, 0) - 1; i >= 0; i--) + if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN) + { + JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial); + + if (JUMP_LABEL (trial)) + LABEL_NUSES (JUMP_LABEL (trial))++; + } + + tem = emit_insn_after (seq, before); + + delete_insn (trial); + if (has_barrier) + emit_barrier_after (tem); + + /* Recursively call try_split for each new insn created; by the + time control returns here that insn will be fully split, so + set LAST and continue from the insn after the one returned. + We can't use next_active_insn here since AFTER may be a note. + Ignore deleted insns, which can be occur if not optimizing. */ + for (tem = NEXT_INSN (before); tem != after; + tem = NEXT_INSN (tem)) + if (! INSN_DELETED_P (tem)) + tem = try_split (PATTERN (tem), tem, 1); + } + /* Avoid infinite loop if the result matches the original pattern. */ + else if (rtx_equal_p (seq, pat)) + return trial; + else + { + PATTERN (trial) = seq; + INSN_CODE (trial) = -1; + try_split (seq, trial, last); + } + + /* Return either the first or the last insn, depending on which was + requested. */ + return last ? prev_active_insn (after) : next_active_insn (before); + } + + return trial; +} + +/* Make and return an INSN rtx, initializing all its slots. + Store PATTERN in the pattern slots. */ + +rtx +make_insn_raw (pattern) + rtx pattern; +{ + register rtx insn; + + insn = rtx_alloc (INSN); + INSN_UID (insn) = cur_insn_uid++; + + PATTERN (insn) = pattern; + INSN_CODE (insn) = -1; + LOG_LINKS (insn) = NULL; + REG_NOTES (insn) = NULL; + + return insn; +} + +/* Like `make_insn' but make a JUMP_INSN instead of an insn. */ + +static rtx +make_jump_insn_raw (pattern) + rtx pattern; +{ + register rtx insn; + + insn = rtx_alloc (JUMP_INSN); + INSN_UID (insn) = cur_insn_uid++; + + PATTERN (insn) = pattern; + INSN_CODE (insn) = -1; + LOG_LINKS (insn) = NULL; + REG_NOTES (insn) = NULL; + JUMP_LABEL (insn) = NULL; + + return insn; +} + +/* Like `make_insn' but make a CALL_INSN instead of an insn. */ + +static rtx +make_call_insn_raw (pattern) + rtx pattern; +{ + register rtx insn; + + insn = rtx_alloc (CALL_INSN); + INSN_UID (insn) = cur_insn_uid++; + + PATTERN (insn) = pattern; + INSN_CODE (insn) = -1; + LOG_LINKS (insn) = NULL; + REG_NOTES (insn) = NULL; + CALL_INSN_FUNCTION_USAGE (insn) = NULL; + + return insn; +} + +/* Add INSN to the end of the doubly-linked list. + INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */ + +void +add_insn (insn) + register rtx insn; +{ + PREV_INSN (insn) = last_insn; + NEXT_INSN (insn) = 0; + + if (NULL != last_insn) + NEXT_INSN (last_insn) = insn; + + if (NULL == first_insn) + first_insn = insn; + + last_insn = insn; +} + +/* Add INSN into the doubly-linked list after insn AFTER. This and + the next should be the only functions called to insert an insn once + delay slots have been filled since only they know how to update a + SEQUENCE. */ + +void +add_insn_after (insn, after) + rtx insn, after; +{ + rtx next = NEXT_INSN (after); + + if (optimize && INSN_DELETED_P (after)) + abort (); + + NEXT_INSN (insn) = next; + PREV_INSN (insn) = after; + + if (next) + { + PREV_INSN (next) = insn; + if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE) + PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn; + } + else if (last_insn == after) + last_insn = insn; + else + { + struct sequence_stack *stack = sequence_stack; + /* Scan all pending sequences too. */ + for (; stack; stack = stack->next) + if (after == stack->last) + { + stack->last = insn; + break; + } + + if (stack == 0) + abort (); + } + + NEXT_INSN (after) = insn; + if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE) + { + rtx sequence = PATTERN (after); + NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn; + } +} + +/* Add INSN into the doubly-linked list before insn BEFORE. This and + the previous should be the only functions called to insert an insn once + delay slots have been filled since only they know how to update a + SEQUENCE. */ + +void +add_insn_before (insn, before) + rtx insn, before; +{ + rtx prev = PREV_INSN (before); + + if (optimize && INSN_DELETED_P (before)) + abort (); + + PREV_INSN (insn) = prev; + NEXT_INSN (insn) = before; + + if (prev) + { + NEXT_INSN (prev) = insn; + if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE) + { + rtx sequence = PATTERN (prev); + NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn; + } + } + else if (first_insn == before) + first_insn = insn; + else + { + struct sequence_stack *stack = sequence_stack; + /* Scan all pending sequences too. */ + for (; stack; stack = stack->next) + if (before == stack->first) + { + stack->first = insn; + break; + } + + if (stack == 0) + abort (); + } + + PREV_INSN (before) = insn; + if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE) + PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn; +} + +/* Delete all insns made since FROM. + FROM becomes the new last instruction. */ + +void +delete_insns_since (from) + rtx from; +{ + if (from == 0) + first_insn = 0; + else + NEXT_INSN (from) = 0; + last_insn = from; +} + +/* This function is deprecated, please use sequences instead. + + Move a consecutive bunch of insns to a different place in the chain. + The insns to be moved are those between FROM and TO. + They are moved to a new position after the insn AFTER. + AFTER must not be FROM or TO or any insn in between. + + This function does not know about SEQUENCEs and hence should not be + called after delay-slot filling has been done. */ + +void +reorder_insns (from, to, after) + rtx from, to, after; +{ + /* Splice this bunch out of where it is now. */ + if (PREV_INSN (from)) + NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to); + if (NEXT_INSN (to)) + PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from); + if (last_insn == to) + last_insn = PREV_INSN (from); + if (first_insn == from) + first_insn = NEXT_INSN (to); + + /* Make the new neighbors point to it and it to them. */ + if (NEXT_INSN (after)) + PREV_INSN (NEXT_INSN (after)) = to; + + NEXT_INSN (to) = NEXT_INSN (after); + PREV_INSN (from) = after; + NEXT_INSN (after) = from; + if (after == last_insn) + last_insn = to; +} + +/* Return the line note insn preceding INSN. */ + +static rtx +find_line_note (insn) + rtx insn; +{ + if (no_line_numbers) + return 0; + + for (; insn; insn = PREV_INSN (insn)) + if (GET_CODE (insn) == NOTE + && NOTE_LINE_NUMBER (insn) >= 0) + break; + + return insn; +} + +/* Like reorder_insns, but inserts line notes to preserve the line numbers + of the moved insns when debugging. This may insert a note between AFTER + and FROM, and another one after TO. */ + +void +reorder_insns_with_line_notes (from, to, after) + rtx from, to, after; +{ + rtx from_line = find_line_note (from); + rtx after_line = find_line_note (after); + + reorder_insns (from, to, after); + + if (from_line == after_line) + return; + + if (from_line) + emit_line_note_after (NOTE_SOURCE_FILE (from_line), + NOTE_LINE_NUMBER (from_line), + after); + if (after_line) + emit_line_note_after (NOTE_SOURCE_FILE (after_line), + NOTE_LINE_NUMBER (after_line), + to); +} + +/* Emit an insn of given code and pattern + at a specified place within the doubly-linked list. */ + +/* Make an instruction with body PATTERN + and output it before the instruction BEFORE. */ + +rtx +emit_insn_before (pattern, before) + register rtx pattern, before; +{ + register rtx insn = before; + + if (GET_CODE (pattern) == SEQUENCE) + { + register int i; + + for (i = 0; i < XVECLEN (pattern, 0); i++) + { + insn = XVECEXP (pattern, 0, i); + add_insn_before (insn, before); + } + if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE) + sequence_result[XVECLEN (pattern, 0)] = pattern; + } + else + { + insn = make_insn_raw (pattern); + add_insn_before (insn, before); + } + + return insn; +} + +/* Make an instruction with body PATTERN and code JUMP_INSN + and output it before the instruction BEFORE. */ + +rtx +emit_jump_insn_before (pattern, before) + register rtx pattern, before; +{ + register rtx insn; + + if (GET_CODE (pattern) == SEQUENCE) + insn = emit_insn_before (pattern, before); + else + { + insn = make_jump_insn_raw (pattern); + add_insn_before (insn, before); + } + + return insn; +} + +/* Make an instruction with body PATTERN and code CALL_INSN + and output it before the instruction BEFORE. */ + +rtx +emit_call_insn_before (pattern, before) + register rtx pattern, before; +{ + register rtx insn; + + if (GET_CODE (pattern) == SEQUENCE) + insn = emit_insn_before (pattern, before); + else + { + insn = make_call_insn_raw (pattern); + add_insn_before (insn, before); + PUT_CODE (insn, CALL_INSN); + } + + return insn; +} + +/* Make an insn of code BARRIER + and output it before the insn AFTER. */ + +rtx +emit_barrier_before (before) + register rtx before; +{ + register rtx insn = rtx_alloc (BARRIER); + + INSN_UID (insn) = cur_insn_uid++; + + add_insn_before (insn, before); + return insn; +} + +/* Emit a note of subtype SUBTYPE before the insn BEFORE. */ + +rtx +emit_note_before (subtype, before) + int subtype; + rtx before; +{ + register rtx note = rtx_alloc (NOTE); + INSN_UID (note) = cur_insn_uid++; + NOTE_SOURCE_FILE (note) = 0; + NOTE_LINE_NUMBER (note) = subtype; + + add_insn_before (note, before); + return note; +} + +/* Make an insn of code INSN with body PATTERN + and output it after the insn AFTER. */ + +rtx +emit_insn_after (pattern, after) + register rtx pattern, after; +{ + register rtx insn = after; + + if (GET_CODE (pattern) == SEQUENCE) + { + register int i; + + for (i = 0; i < XVECLEN (pattern, 0); i++) + { + insn = XVECEXP (pattern, 0, i); + add_insn_after (insn, after); + after = insn; + } + if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE) + sequence_result[XVECLEN (pattern, 0)] = pattern; + } + else + { + insn = make_insn_raw (pattern); + add_insn_after (insn, after); + } + + return insn; +} + +/* Similar to emit_insn_after, except that line notes are to be inserted so + as to act as if this insn were at FROM. */ + +void +emit_insn_after_with_line_notes (pattern, after, from) + rtx pattern, after, from; +{ + rtx from_line = find_line_note (from); + rtx after_line = find_line_note (after); + rtx insn = emit_insn_after (pattern, after); + + if (from_line) + emit_line_note_after (NOTE_SOURCE_FILE (from_line), + NOTE_LINE_NUMBER (from_line), + after); + + if (after_line) + emit_line_note_after (NOTE_SOURCE_FILE (after_line), + NOTE_LINE_NUMBER (after_line), + insn); +} + +/* Make an insn of code JUMP_INSN with body PATTERN + and output it after the insn AFTER. */ + +rtx +emit_jump_insn_after (pattern, after) + register rtx pattern, after; +{ + register rtx insn; + + if (GET_CODE (pattern) == SEQUENCE) + insn = emit_insn_after (pattern, after); + else + { + insn = make_jump_insn_raw (pattern); + add_insn_after (insn, after); + } + + return insn; +} + +/* Make an insn of code BARRIER + and output it after the insn AFTER. */ + +rtx +emit_barrier_after (after) + register rtx after; +{ + register rtx insn = rtx_alloc (BARRIER); + + INSN_UID (insn) = cur_insn_uid++; + + add_insn_after (insn, after); + return insn; +} + +/* Emit the label LABEL after the insn AFTER. */ + +rtx +emit_label_after (label, after) + rtx label, after; +{ + /* This can be called twice for the same label + as a result of the confusion that follows a syntax error! + So make it harmless. */ + if (INSN_UID (label) == 0) + { + INSN_UID (label) = cur_insn_uid++; + add_insn_after (label, after); + } + + return label; +} + +/* Emit a note of subtype SUBTYPE after the insn AFTER. */ + +rtx +emit_note_after (subtype, after) + int subtype; + rtx after; +{ + register rtx note = rtx_alloc (NOTE); + INSN_UID (note) = cur_insn_uid++; + NOTE_SOURCE_FILE (note) = 0; + NOTE_LINE_NUMBER (note) = subtype; + add_insn_after (note, after); + return note; +} + +/* Emit a line note for FILE and LINE after the insn AFTER. */ + +rtx +emit_line_note_after (file, line, after) + char *file; + int line; + rtx after; +{ + register rtx note; + + if (no_line_numbers && line > 0) + { + cur_insn_uid++; + return 0; + } + + note = rtx_alloc (NOTE); + INSN_UID (note) = cur_insn_uid++; + NOTE_SOURCE_FILE (note) = file; + NOTE_LINE_NUMBER (note) = line; + add_insn_after (note, after); + return note; +} + +/* Make an insn of code INSN with pattern PATTERN + and add it to the end of the doubly-linked list. + If PATTERN is a SEQUENCE, take the elements of it + and emit an insn for each element. + + Returns the last insn emitted. */ + +rtx +emit_insn (pattern) + rtx pattern; +{ + rtx insn = last_insn; + + if (GET_CODE (pattern) == SEQUENCE) + { + register int i; + + for (i = 0; i < XVECLEN (pattern, 0); i++) + { + insn = XVECEXP (pattern, 0, i); + add_insn (insn); + } + if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE) + sequence_result[XVECLEN (pattern, 0)] = pattern; + } + else + { + insn = make_insn_raw (pattern); + add_insn (insn); + } + + return insn; +} + +/* Emit the insns in a chain starting with INSN. + Return the last insn emitted. */ + +rtx +emit_insns (insn) + rtx insn; +{ + rtx last = 0; + + while (insn) + { + rtx next = NEXT_INSN (insn); + add_insn (insn); + last = insn; + insn = next; + } + + return last; +} + +/* Emit the insns in a chain starting with INSN and place them in front of + the insn BEFORE. Return the last insn emitted. */ + +rtx +emit_insns_before (insn, before) + rtx insn; + rtx before; +{ + rtx last = 0; + + while (insn) + { + rtx next = NEXT_INSN (insn); + add_insn_before (insn, before); + last = insn; + insn = next; + } + + return last; +} + +/* Emit the insns in a chain starting with FIRST and place them in back of + the insn AFTER. Return the last insn emitted. */ + +rtx +emit_insns_after (first, after) + register rtx first; + register rtx after; +{ + register rtx last; + register rtx after_after; + + if (!after) + abort (); + + if (!first) + return first; + + for (last = first; NEXT_INSN (last); last = NEXT_INSN (last)) + continue; + + after_after = NEXT_INSN (after); + + NEXT_INSN (after) = first; + PREV_INSN (first) = after; + NEXT_INSN (last) = after_after; + if (after_after) + PREV_INSN (after_after) = last; + + if (after == last_insn) + last_insn = last; + return last; +} + +/* Make an insn of code JUMP_INSN with pattern PATTERN + and add it to the end of the doubly-linked list. */ + +rtx +emit_jump_insn (pattern) + rtx pattern; +{ + if (GET_CODE (pattern) == SEQUENCE) + return emit_insn (pattern); + else + { + register rtx insn = make_jump_insn_raw (pattern); + add_insn (insn); + return insn; + } +} + +/* Make an insn of code CALL_INSN with pattern PATTERN + and add it to the end of the doubly-linked list. */ + +rtx +emit_call_insn (pattern) + rtx pattern; +{ + if (GET_CODE (pattern) == SEQUENCE) + return emit_insn (pattern); + else + { + register rtx insn = make_call_insn_raw (pattern); + add_insn (insn); + PUT_CODE (insn, CALL_INSN); + return insn; + } +} + +/* Add the label LABEL to the end of the doubly-linked list. */ + +rtx +emit_label (label) + rtx label; +{ + /* This can be called twice for the same label + as a result of the confusion that follows a syntax error! + So make it harmless. */ + if (INSN_UID (label) == 0) + { + INSN_UID (label) = cur_insn_uid++; + add_insn (label); + } + return label; +} + +/* Make an insn of code BARRIER + and add it to the end of the doubly-linked list. */ + +rtx +emit_barrier () +{ + register rtx barrier = rtx_alloc (BARRIER); + INSN_UID (barrier) = cur_insn_uid++; + add_insn (barrier); + return barrier; +} + +/* Make an insn of code NOTE + with data-fields specified by FILE and LINE + and add it to the end of the doubly-linked list, + but only if line-numbers are desired for debugging info. */ + +rtx +emit_line_note (file, line) + char *file; + int line; +{ + if (output_bytecode) + { + /* FIXME: for now we do nothing, but eventually we will have to deal with + debugging information. */ + return 0; + } + + emit_filename = file; + emit_lineno = line; + +#if 0 + if (no_line_numbers) + return 0; +#endif + + return emit_note (file, line); +} + +/* Make an insn of code NOTE + with data-fields specified by FILE and LINE + and add it to the end of the doubly-linked list. + If it is a line-number NOTE, omit it if it matches the previous one. */ + +rtx +emit_note (file, line) + char *file; + int line; +{ + register rtx note; + + if (line > 0) + { + if (file && last_filename && !strcmp (file, last_filename) + && line == last_linenum) + return 0; + last_filename = file; + last_linenum = line; + } + + if (no_line_numbers && line > 0) + { + cur_insn_uid++; + return 0; + } + + note = rtx_alloc (NOTE); + INSN_UID (note) = cur_insn_uid++; + NOTE_SOURCE_FILE (note) = file; + NOTE_LINE_NUMBER (note) = line; + add_insn (note); + return note; +} + +/* Emit a NOTE, and don't omit it even if LINE it the previous note. */ + +rtx +emit_line_note_force (file, line) + char *file; + int line; +{ + last_linenum = -1; + return emit_line_note (file, line); +} + +/* Cause next statement to emit a line note even if the line number + has not changed. This is used at the beginning of a function. */ + +void +force_next_line_note () +{ + last_linenum = -1; +} + +/* Return an indication of which type of insn should have X as a body. + The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */ + +enum rtx_code +classify_insn (x) + rtx x; +{ + if (GET_CODE (x) == CODE_LABEL) + return CODE_LABEL; + if (GET_CODE (x) == CALL) + return CALL_INSN; + if (GET_CODE (x) == RETURN) + return JUMP_INSN; + if (GET_CODE (x) == SET) + { + if (SET_DEST (x) == pc_rtx) + return JUMP_INSN; + else if (GET_CODE (SET_SRC (x)) == CALL) + return CALL_INSN; + else + return INSN; + } + if (GET_CODE (x) == PARALLEL) + { + register int j; + for (j = XVECLEN (x, 0) - 1; j >= 0; j--) + if (GET_CODE (XVECEXP (x, 0, j)) == CALL) + return CALL_INSN; + else if (GET_CODE (XVECEXP (x, 0, j)) == SET + && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx) + return JUMP_INSN; + else if (GET_CODE (XVECEXP (x, 0, j)) == SET + && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL) + return CALL_INSN; + } + return INSN; +} + +/* Emit the rtl pattern X as an appropriate kind of insn. + If X is a label, it is simply added into the insn chain. */ + +rtx +emit (x) + rtx x; +{ + enum rtx_code code = classify_insn (x); + + if (code == CODE_LABEL) + return emit_label (x); + else if (code == INSN) + return emit_insn (x); + else if (code == JUMP_INSN) + { + register rtx insn = emit_jump_insn (x); + if (simplejump_p (insn) || GET_CODE (x) == RETURN) + return emit_barrier (); + return insn; + } + else if (code == CALL_INSN) + return emit_call_insn (x); + else + abort (); +} + +/* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */ + +void +start_sequence () +{ + struct sequence_stack *tem; + + if (sequence_element_free_list) + { + /* Reuse a previously-saved struct sequence_stack. */ + tem = sequence_element_free_list; + sequence_element_free_list = tem->next; + } + else + tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack)); + + tem->next = sequence_stack; + tem->first = first_insn; + tem->last = last_insn; + tem->sequence_rtl_expr = sequence_rtl_expr; + + sequence_stack = tem; + + first_insn = 0; + last_insn = 0; +} + +/* Similarly, but indicate that this sequence will be placed in + T, an RTL_EXPR. */ + +void +start_sequence_for_rtl_expr (t) + tree t; +{ + start_sequence (); + + sequence_rtl_expr = t; +} + +/* Set up the insn chain starting with FIRST + as the current sequence, saving the previously current one. */ + +void +push_to_sequence (first) + rtx first; +{ + rtx last; + + start_sequence (); + + for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last)); + + first_insn = first; + last_insn = last; +} + +/* Set up the outer-level insn chain + as the current sequence, saving the previously current one. */ + +void +push_topmost_sequence () +{ + struct sequence_stack *stack, *top; + + start_sequence (); + + for (stack = sequence_stack; stack; stack = stack->next) + top = stack; + + first_insn = top->first; + last_insn = top->last; + sequence_rtl_expr = top->sequence_rtl_expr; +} + +/* After emitting to the outer-level insn chain, update the outer-level + insn chain, and restore the previous saved state. */ + +void +pop_topmost_sequence () +{ + struct sequence_stack *stack, *top; + + for (stack = sequence_stack; stack; stack = stack->next) + top = stack; + + top->first = first_insn; + top->last = last_insn; + /* ??? Why don't we save sequence_rtl_expr here? */ + + end_sequence (); +} + +/* After emitting to a sequence, restore previous saved state. + + To get the contents of the sequence just made, + you must call `gen_sequence' *before* calling here. */ + +void +end_sequence () +{ + struct sequence_stack *tem = sequence_stack; + + first_insn = tem->first; + last_insn = tem->last; + sequence_rtl_expr = tem->sequence_rtl_expr; + sequence_stack = tem->next; + + tem->next = sequence_element_free_list; + sequence_element_free_list = tem; +} + +/* Return 1 if currently emitting into a sequence. */ + +int +in_sequence_p () +{ + return sequence_stack != 0; +} + +/* Generate a SEQUENCE rtx containing the insns already emitted + to the current sequence. + + This is how the gen_... function from a DEFINE_EXPAND + constructs the SEQUENCE that it returns. */ + +rtx +gen_sequence () +{ + rtx result; + rtx tem; + int i; + int len; + + /* Count the insns in the chain. */ + len = 0; + for (tem = first_insn; tem; tem = NEXT_INSN (tem)) + len++; + + /* If only one insn, return its pattern rather than a SEQUENCE. + (Now that we cache SEQUENCE expressions, it isn't worth special-casing + the case of an empty list.) */ + if (len == 1 + && (GET_CODE (first_insn) == INSN + || GET_CODE (first_insn) == JUMP_INSN + /* Don't discard the call usage field. */ + || (GET_CODE (first_insn) == CALL_INSN + && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX))) + return PATTERN (first_insn); + + /* Put them in a vector. See if we already have a SEQUENCE of the + appropriate length around. */ + if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0) + sequence_result[len] = 0; + else + { + /* Ensure that this rtl goes in saveable_obstack, since we may + cache it. */ + push_obstacks_nochange (); + rtl_in_saveable_obstack (); + result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len)); + pop_obstacks (); + } + + for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++) + XVECEXP (result, 0, i) = tem; + + return result; +} + +/* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag + according to the chain of insns starting with FIRST. + + Also set cur_insn_uid to exceed the largest uid in that chain. + + This is used when an inline function's rtl is saved + and passed to rest_of_compilation later. */ + +static void restore_reg_data_1 (); + +void +restore_reg_data (first) + rtx first; +{ + register rtx insn; + int i; + register int max_uid = 0; + + for (insn = first; insn; insn = NEXT_INSN (insn)) + { + if (INSN_UID (insn) >= max_uid) + max_uid = INSN_UID (insn); + + switch (GET_CODE (insn)) + { + case NOTE: + case CODE_LABEL: + case BARRIER: + break; + + case JUMP_INSN: + case CALL_INSN: + case INSN: + restore_reg_data_1 (PATTERN (insn)); + break; + } + } + + /* Don't duplicate the uids already in use. */ + cur_insn_uid = max_uid + 1; + + /* If any regs are missing, make them up. + + ??? word_mode is not necessarily the right mode. Most likely these REGs + are never used. At some point this should be checked. */ + + for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++) + if (regno_reg_rtx[i] == 0) + regno_reg_rtx[i] = gen_rtx (REG, word_mode, i); +} + +static void +restore_reg_data_1 (orig) + rtx orig; +{ + register rtx x = orig; + register int i; + register enum rtx_code code; + register char *format_ptr; + + code = GET_CODE (x); + + switch (code) + { + case QUEUED: + case CONST_INT: + case CONST_DOUBLE: + case SYMBOL_REF: + case CODE_LABEL: + case PC: + case CC0: + case LABEL_REF: + return; + + case REG: + if (REGNO (x) >= FIRST_PSEUDO_REGISTER) + { + /* Make sure regno_pointer_flag and regno_reg_rtx are large + enough to have an element for this pseudo reg number. */ + if (REGNO (x) >= reg_rtx_no) + { + reg_rtx_no = REGNO (x); + + if (reg_rtx_no >= regno_pointer_flag_length) + { + int newlen = MAX (regno_pointer_flag_length * 2, + reg_rtx_no + 30); + rtx *new1; + char *new = (char *) oballoc (newlen); + bzero (new, newlen); + bcopy (regno_pointer_flag, new, regno_pointer_flag_length); + + new1 = (rtx *) oballoc (newlen * sizeof (rtx)); + bzero ((char *) new1, newlen * sizeof (rtx)); + bcopy ((char *) regno_reg_rtx, (char *) new1, + regno_pointer_flag_length * sizeof (rtx)); + + regno_pointer_flag = new; + regno_reg_rtx = new1; + regno_pointer_flag_length = newlen; + } + reg_rtx_no ++; + } + regno_reg_rtx[REGNO (x)] = x; + } + return; + + case MEM: + if (GET_CODE (XEXP (x, 0)) == REG) + mark_reg_pointer (XEXP (x, 0)); + restore_reg_data_1 (XEXP (x, 0)); + return; + } + + /* Now scan the subexpressions recursively. */ + + format_ptr = GET_RTX_FORMAT (code); + + for (i = 0; i < GET_RTX_LENGTH (code); i++) + { + switch (*format_ptr++) + { + case 'e': + restore_reg_data_1 (XEXP (x, i)); + break; + + case 'E': + if (XVEC (x, i) != NULL) + { + register int j; + + for (j = 0; j < XVECLEN (x, i); j++) + restore_reg_data_1 (XVECEXP (x, i, j)); + } + break; + } + } +} + +/* Initialize data structures and variables in this file + before generating rtl for each function. */ + +void +init_emit () +{ + int i; + + first_insn = NULL; + last_insn = NULL; + sequence_rtl_expr = NULL; + cur_insn_uid = 1; + reg_rtx_no = LAST_VIRTUAL_REGISTER + 1; + last_linenum = 0; + last_filename = 0; + first_label_num = label_num; + last_label_num = 0; + sequence_stack = NULL; + + /* Clear the start_sequence/gen_sequence cache. */ + sequence_element_free_list = 0; + for (i = 0; i < SEQUENCE_RESULT_SIZE; i++) + sequence_result[i] = 0; + + /* Init the tables that describe all the pseudo regs. */ + + regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101; + + regno_pointer_flag + = (char *) oballoc (regno_pointer_flag_length); + bzero (regno_pointer_flag, regno_pointer_flag_length); + + regno_reg_rtx + = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx)); + bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx)); + + /* Put copies of all the virtual register rtx into regno_reg_rtx. */ + regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx; + regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx; + regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx; + regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx; + + /* Indicate that the virtual registers and stack locations are + all pointers. */ + REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1; + REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1; + REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1; + REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1; + + REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1; + REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1; + REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1; + REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1; + +#ifdef INIT_EXPANDERS + INIT_EXPANDERS; +#endif +} + +/* Create some permanent unique rtl objects shared between all functions. + LINE_NUMBERS is nonzero if line numbers are to be generated. */ + +void +init_emit_once (line_numbers) + int line_numbers; +{ + int i; + enum machine_mode mode; + + no_line_numbers = ! line_numbers; + + sequence_stack = NULL; + + /* Compute the word and byte modes. */ + + byte_mode = VOIDmode; + word_mode = VOIDmode; + + for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode; + mode = GET_MODE_WIDER_MODE (mode)) + { + if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT + && byte_mode == VOIDmode) + byte_mode = mode; + + if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD + && word_mode == VOIDmode) + word_mode = mode; + } + + ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0); + + /* Create the unique rtx's for certain rtx codes and operand values. */ + + pc_rtx = gen_rtx (PC, VOIDmode); + cc0_rtx = gen_rtx (CC0, VOIDmode); + + /* Don't use gen_rtx here since gen_rtx in this case + tries to use these variables. */ + for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++) + { + const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT); + PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode); + INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i; + } + + /* These four calls obtain some of the rtx expressions made above. */ + const0_rtx = GEN_INT (0); + const1_rtx = GEN_INT (1); + const2_rtx = GEN_INT (2); + constm1_rtx = GEN_INT (-1); + + /* This will usually be one of the above constants, but may be a new rtx. */ + const_true_rtx = GEN_INT (STORE_FLAG_VALUE); + + dconst0 = REAL_VALUE_ATOF ("0", DFmode); + dconst1 = REAL_VALUE_ATOF ("1", DFmode); + dconst2 = REAL_VALUE_ATOF ("2", DFmode); + dconstm1 = REAL_VALUE_ATOF ("-1", DFmode); + + for (i = 0; i <= 2; i++) + { + for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode; + mode = GET_MODE_WIDER_MODE (mode)) + { + rtx tem = rtx_alloc (CONST_DOUBLE); + union real_extract u; + + bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */ + u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2; + + bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u); + CONST_DOUBLE_MEM (tem) = cc0_rtx; + PUT_MODE (tem, mode); + + const_tiny_rtx[i][(int) mode] = tem; + } + + const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i); + + for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode; + mode = GET_MODE_WIDER_MODE (mode)) + const_tiny_rtx[i][(int) mode] = GEN_INT (i); + + for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT); + mode != VOIDmode; + mode = GET_MODE_WIDER_MODE (mode)) + const_tiny_rtx[i][(int) mode] = GEN_INT (i); + } + + for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode; + mode = GET_MODE_WIDER_MODE (mode)) + const_tiny_rtx[0][(int) mode] = const0_rtx; + + stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM); + frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM); + + if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM) + hard_frame_pointer_rtx = frame_pointer_rtx; + else + hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM); + + if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM) + arg_pointer_rtx = frame_pointer_rtx; + else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM) + arg_pointer_rtx = hard_frame_pointer_rtx; + else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM) + arg_pointer_rtx = stack_pointer_rtx; + else + arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM); + + /* Create the virtual registers. Do so here since the following objects + might reference them. */ + + virtual_incoming_args_rtx = gen_rtx (REG, Pmode, + VIRTUAL_INCOMING_ARGS_REGNUM); + virtual_stack_vars_rtx = gen_rtx (REG, Pmode, + VIRTUAL_STACK_VARS_REGNUM); + virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode, + VIRTUAL_STACK_DYNAMIC_REGNUM); + virtual_outgoing_args_rtx = gen_rtx (REG, Pmode, + VIRTUAL_OUTGOING_ARGS_REGNUM); + +#ifdef STRUCT_VALUE + struct_value_rtx = STRUCT_VALUE; +#else + struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM); +#endif + +#ifdef STRUCT_VALUE_INCOMING + struct_value_incoming_rtx = STRUCT_VALUE_INCOMING; +#else +#ifdef STRUCT_VALUE_INCOMING_REGNUM + struct_value_incoming_rtx + = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM); +#else + struct_value_incoming_rtx = struct_value_rtx; +#endif +#endif + +#ifdef STATIC_CHAIN_REGNUM + static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM); + +#ifdef STATIC_CHAIN_INCOMING_REGNUM + if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM) + static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM); + else +#endif + static_chain_incoming_rtx = static_chain_rtx; +#endif + +#ifdef STATIC_CHAIN + static_chain_rtx = STATIC_CHAIN; + +#ifdef STATIC_CHAIN_INCOMING + static_chain_incoming_rtx = STATIC_CHAIN_INCOMING; +#else + static_chain_incoming_rtx = static_chain_rtx; +#endif +#endif + +#ifdef PIC_OFFSET_TABLE_REGNUM + pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM); +#endif +} diff --git a/contrib/gcc/enquire.c b/contrib/gcc/enquire.c new file mode 100644 index 00000000000..763b1a44c9d --- /dev/null +++ b/contrib/gcc/enquire.c @@ -0,0 +1,2837 @@ +/* Everything you wanted to know about your machine and C compiler, + but didn't know who to ask. */ + +#ifndef VERSION +#define VERSION "4.3" +#endif + +/* Author: Steven Pemberton, CWI, Amsterdam; steven@cwi.nl + Bugfixes and upgrades gratefully received. + + Copyright (c) 1988, 1989, 1990 Steven Pemberton, CWI, Amsterdam. + All rights reserved. + + Changes by Richard Stallman: + Undef CHAR_BIT, etc., if defined in stdio.h, Richard Stallman, Aug 90. + In EPROP, avoid a <= old if bad is set, Richard Stallman, May 91. + Use gstddef.h, not stddef.h, Richard Stallman, Nov 91. + Don't declare malloc, instead cast the value, Richard Stallman, Nov 91. + Include sys/types.h before signal.h, Apr 92. + Support NO_LONG_DOUBLE_IO in f_define and f_rep; new fn fake_f_rep, Apr 92. + Enclose -f output in #ifndef _FLOAT_H___, Richard Stallman, May 92. + + Change by Jim Wilson: + Add #undef before every #define, Dec 92. + Use stddef.h not gstddef.h, Mar 94. + + Changes by Paul Eggert, installed Feb 93: + (fake_f_rep): Clear all of u, initially. Make the ints in u unsigned. + (f_define): Use ordinary constants for long double + if it's same width as double. Make __convert_long_double_i unsigned. + Richard Stallman, May 93: + In F_check, check NO_LONG_DOUBLE_IO. + + Changes by Stephen Moshier, installed Sep 93: + (FPROP): Recognize 80387 or 68881 XFmode format. + + + COMPILING + With luck and a following wind, just the following will work: + cc enquire.c -o enquire + You may get some messages about unreachable code, which you can ignore. + + If your compiler doesn't support: add flag: + signed char (eg pcc) -DNO_SC + unsigned char -DNO_UC + unsigned short and long -DNO_UI + void -DNO_VOID + signal(), or setjmp/longjmp() -DNO_SIG + %Lf in printf -DNO_LONG_DOUBLE_IO + + Try to compile first with no flags, and see if you get any errors - + you might be surprised. (Most non-ANSI compilers need -DNO_SC, though.) + Some compilers need a -f flag for floating point. + + Don't use any optimisation flags: the program may not work if you do. + Though "while (a+1.0-a-1.0 == 0.0)" may look like "while(1)" to an + optimiser, to a floating-point unit there's a world of difference. + + Some compilers offer various flags for different floating point + modes; it's worth trying all possible combinations of these. + + Add -DID=\"name\" if you want the machine/flags identified in the output. + + FAULTY COMPILERS + Because of bugs and/or inadequacies, some compilers need the following + defines: + + If your C preprocessor doesn't have the predefined __FILE__ macro, and + you don't want to call this file enquire.c but, say, tell.c, add the + flag -DFILENAME=\"tell.c\" . + + Some compilers won't accept the line "#include FILENAME". + Add flag -DNO_FILE. In that case, this file *must* be called enquire.c. + + Some compilers can't cope with "#ifdef __FILE__". Use -DFILENAME= + or -DNO_FILE as above. + + Some naughty compilers define __STDC__, but don't really support it. + Some define it as 0, in which case we treat it as undefined. + But if your compiler defines it, and isn't really ANSI C, + add flag -DNO_STDC. (To those compiler writers: for shame). + + Some naughty compilers define __STDC__, but don't have the stddef.h + include file. Add flag -DNO_STDDEF. + + Summary of naughty-compiler flags: + If your compiler doesn't support: add flag: + __FILE__ (and you changed the filename) -DFILENAME=\"name.c\" + #ifdef __FILE__ -DNO_FILE or -DFILENAME=... + #include FILENAME -DNO_FILE + __STDC__ (properly) -DNO_STDC + stddef.h -DNO_STDDEF + + Some systems crash when you try to malloc all store. To save users of + such defective systems too much grief, they may compile with -DNO_MEM, + which ignores that bit of the code. + + While it is not our policy to support defective compilers, pity has been + taken on people with compilers that can't produce object files bigger than + 32k (especially since it was an easy addition). Compile the program + into separate parts like this: + cc -DSEP -DPASS0 -o p0.o enquire.c + cc -DSEP -DPASS1 -o p1.o enquire.c + cc -DSEP -DPASS2 -o p2.o enquire.c + cc -DSEP -DPASS3 -o p3.o enquire.c + cc -o enquire p0.o p1.o p2.o p3.o + + SYSTEM DEPENDENCIES + You may possibly need to add some calls to signal() for other sorts of + exception on your machine than SIGFPE, and SIGOVER. See lines beginning + #ifdef SIGxxx in main() (and communicate the differences to me!). + + OUTPUT + Run without argument to get the information as English text. If run + with argument -l (e.g. enquire -l), output is a series of #define's for + the ANSI standard limits.h include file, excluding MB_MAX_CHAR. If run + with argument -f, output is a series of #define's for the ANSI standard + float.h include file (according to ANSI C Draft of Dec 7, 1988). + Flag -v gives verbose output: output includes the English text above + as C comments. The program exit(0)'s if everything went ok, otherwise + it exits with a positive number, telling how many problems there were. + + VERIFYING THE COMPILER + If, having produced the float.h and limits.h header files, you want to + verify that the compiler reads them back correctly (there are a lot of + boundary cases, of course, like minimum and maximum numbers), you can + recompile enquire.c with -DVERIFY set (plus the other flags that you used + when compiling the version that produced the header files). This then + recompiles the program so that it #includes "limits.h" and "float.h", + and checks that the constants it finds there are the same as the + constants it produces. Run the resulting program with enquire -fl. + Very few compilers have passed without error. + NB: You *must* recompile with the same compiler and flags, otherwise + you may get odd results. + + You can also use this option if your compiler already has both files, + and you want to confirm that this program produces the right results. + + TROUBLESHOOTING. + This program is now quite trustworthy, and suspicious and wrong output + may well be caused by bugs in the compiler, not in the program (however + of course, this is not guaranteed, and no responsibility can be + accepted, etc.) + + The program only works if overflows are ignored by the C system or + are catchable with signal(). + + If the program fails to run to completion (often with the error message + "Unexpected signal at point x"), this often turns out to be a bug in the + C compiler's run-time system. Check what was about to be printed, and + try to narrow the problem down. + + Another possible problem is that you have compiled the program to produce + loss-of-precision arithmetic traps. The program cannot cope with these, + and you should re-compile without them. (They should never be the default). + + Make sure you compiled with optimisation turned off. + + Output preceded by *** WARNING: identifies behaviour of the C system + deemed incorrect by the program. Likely problems are that printf or + scanf don't cope properly with certain boundary numbers: this program + goes to a lot of trouble to calculate its values, and these values + are mostly boundary numbers. Experience has shown that often printf + cannot cope with these values, and so in an attempt to increase + confidence in the output, for each float and double that is printed, + the printed value is checked by using sscanf to read it back. + Care is taken that numbers are printed with enough digits to uniquely + identify them, and therefore that they can be read back identically. + If the number read back is different, then there is probably a bug in + printf or sscanf, and the program prints the warning message. + If the two numbers in the warning look identical, then printf is more + than likely rounding the last digit(s) incorrectly. To put you at ease + that the two really are different, the bit patterns of the two numbers + are also printed. The difference is very likely in the last bit. + Many scanf's read the minimum double back as 0.0, and similarly cause + overflow when reading the maximum double. This program quite ruthlessly + declares all these behaviours faulty. The point is that if you get + one of these warnings, the output may be wrong, so you should check + the result carefully if you intend to use the results. Of course, printf + and sscanf may both be wrong, and cancel each other out, so you should + check the output carefully anyway. + + The warning that "a cast didn't work" refers to cases like this: + + float f; + #define C 1.234567890123456789 + f= C; + if (f != (float) C) printf ("Wrong!"); + + A faulty compiler will widen f to double and ignore the cast to float, + and because there is more accuracy in a double than a float, fail to + recognise that they are the same. In the actual case in point, f and C + are passed as parameters to a function that discovers they are not equal, + so it's just possible that the error was in the parameter passing, + not in the cast (see function Validate()). + For ANSI C, which has float constants, the error message is "constant has + wrong precision". + + REPORTING PROBLEMS + If the program doesn't work for you for any reason that can't be + narrowed down to a problem in the C compiler, or it has to be changed in + order to get it to compile, or it produces suspicious output (like a very + low maximum float, for instance), please mail the problem and an example + of the incorrect output to steven@cwi.nl or ..!hp4nl!cwi.nl!steven, so that + improvements can be worked into future versions; cwi.nl is the European + backbone, and is connected to uunet and other fine hosts. + + The program tries to catch and diagnose bugs in the compiler/run-time + system. I would be especially pleased to have reports of failures so + that I can improve this service. + + I apologise unreservedly for the contorted use of the preprocessor... + + THE SMALL PRINT + You may copy and distribute verbatim copies of this source file. + + You may modify this source file, and copy and distribute such + modified versions, provided that you leave the copyright notice + at the top of the file and also cause the modified file to carry + prominent notices stating that you changed the files and the date + of any change; and cause the whole of any work that you distribute + or publish, that in whole or in part contains or is a derivative of + this program or any part thereof, to be licensed at no charge to + all third parties on terms identical to those here. + + If you do have a fix to any problem, please send it to me, so that + other people can have the benefits. + + While every effort has been taken to make this program as reliable as + possible, no responsibility can be taken for the correctness of the + output, nor suitability for any particular use. + + This program is an offshoot of a project funded by public funds. + If you use this program for research or commercial use (i.e. more + than just for the fun of knowing about your compiler) mailing a short + note of acknowledgement may help keep enquire.c supported. + + ACKNOWLEDGEMENTS + Many people have given time and ideas to making this program what it is. + To all of them thanks, and apologies for not mentioning them by name. + + HISTORY + Originally started as a program to generate configuration constants + for a large piece of software we were writing, which later took on + a life of its own... + 1.0 Length 6658!; end 1984? + Unix only. Only printed a dozen maximum int/double values. + 2.0 Length 10535; Spring 1985 + Prints values as #defines (about 20 of them) + More extensive floating point, using Cody and Waite + Handles signals better + Programs around optimisations + Handles Cybers + 3.0 Length 12648; Aug 1987; prints about 42 values + Added PASS stuff, so treats float as well as double + 4.0 Length 33891; Feb 1989; prints around 85 values + First GNU version (for gcc, where they call it hard-params.c) + Generates float.h and limits.h files + Handles long double + Generates warnings for dubious output + 4.1 Length 47738; April 1989 + Added VERIFY and TEST + 4.2 Length 63442; Feb 1990 + Added SEP + Fixed eps/epsneg + Added check for pseudo-unsigned chars + Added description for each #define output + Added check for absence of defines during verify + Added prototypes + Added NO_STDC and NO_FILE + Fixed alignments output + 4.3 Length 75000; Oct 1990; around 114 lines of output + Function xmalloc defined, Richard Stallman, June 89. + Alignments computed from member offsets rather than structure sizes, + Richard Stallman, Oct 89. + Print whether char* and int* pointers have the same format; + also char * and function *. + Update to Draft C version Dec 7, 1988 + - types of constants produced in limits.h + (whether to put a U after unsigned shorts and chars and + whether to output -1024 as (-1023-1)) + - values of SCHAR_MIN/MAX + - values of *_EPSILON (not the smallest but the effective smallest) + Added FILENAME, since standard C doesn't allow #define __FILE__ + Renamed from config.c to enquire.c + Added size_t and ptrdiff_t enquiries + Added promotion enquiries + Added type checks of #defines + Added NO_STDDEF + Changed endian to allow for cases where not all bits are used + Sanity check for max integrals + Fixed definition of setjmp for -DNO_SIG + Moved #define ... 0.0L inside #ifdef STDC, in case some cpp's tokenize + Added NO_MEM +*/ + +/* Set FILENAME to the name of this file */ +#ifndef FILENAME +#ifdef NO_FILE +#define FILENAME "enquire.c" +#else +#ifdef __FILE__ /* It's a compiler bug if this fails. Compile with -DNO_FILE */ +#define FILENAME __FILE__ +#else +#define FILENAME "enquire.c" +#endif /* __FILE__ */ +#endif /* NO_FILE */ +#endif /* FILENAME */ + +/* If PASS isn't defined, then this is the first pass over this file. */ +#ifndef PASS +#ifndef SEP +#define PASS 1 +#define PASS0 1 +#define PASS1 1 +#endif /* SEP */ + +/* A description of the ANSI constants */ +#define D_CHAR_BIT "Number of bits in a storage unit" +#define D_CHAR_MAX "Maximum char" +#define D_CHAR_MIN "Minimum char" +#define D_SCHAR_MAX "Maximum signed char" +#define D_SCHAR_MIN "Minimum signed char" +#define D_UCHAR_MAX "Maximum unsigned char (minimum is always 0)" + +#define D_INT_MAX "Maximum %s" +#define D_INT_MIN "Minimum %s" +#define D_UINT_MAX "Maximum unsigned %s (minimum is always 0)" + +#define D_FLT_ROUNDS "Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown" +#define D_FLT_RADIX "Radix of exponent representation" +#define D_MANT_DIG "Number of base-FLT_RADIX digits in the significand of a %s" +#define D_DIG "Number of decimal digits of precision in a %s" +#define D_MIN_EXP "Minimum int x such that FLT_RADIX**(x-1) is a normalised %s" +#define D_MIN_10_EXP "Minimum int x such that 10**x is a normalised %s" +#define D_MAX_EXP "Maximum int x such that FLT_RADIX**(x-1) is a representable %s" +#define D_MAX_10_EXP "Maximum int x such that 10**x is a representable %s" +#define D_MAX "Maximum %s" +#define D_EPSILON "Difference between 1.0 and the minimum %s greater than 1.0" +#define D_MIN "Minimum normalised %s" + +/* Procedure just marks the functions that don't return a result */ +#ifdef NO_VOID +#define Procedure int +#else +#define Procedure void +#endif + +/* Some bad compilers define __STDC__, when they don't support it. + Compile with -DNO_STDC to get round this. +*/ +#ifndef NO_STDC +#ifdef __STDC__ +#if __STDC__ /* If __STDC__ is 0, assume it isn't supported */ +#define STDC +#endif +#endif +#endif + +/* Stuff different for ANSI C, and old C: + ARGS and NOARGS are used for function prototypes. + Volatile is used to reduce the chance of optimisation, + and to prevent variables being put in registers (when setjmp/longjmp + wouldn't work as we want) + Long_double is the longest floating point type available. + stdc is used in tests like "if (stdc)", which is less ugly than #ifdef. + U is output after unsigned constants. + */ +#ifdef STDC + +#define ARGS(x) x +#define NOARGS (void) +#define Volatile volatile +#define Long_double long double +#define stdc 1 +#define U "U" + +#else /* Old style C */ + +#define ARGS(x) () +#define NOARGS () +#define Volatile static +#define Long_double double +#define stdc 0 +#define U "" + +#endif /* STDC */ + +/* include files */ +#include + +#ifdef STDC +#ifndef NO_STDDEF +#include /* for size_t: if this fails, define NO_STDDEF */ +#endif +#endif + +#ifdef NO_SIG +#define jmp_buf int +#else +#include +#include +#include +#endif + +/* Kludge around the possibility that includes */ +#ifdef CHAR_BIT +#undef CHAR_BIT +#undef CHAR_MAX +#undef CHAR_MIN +#undef SCHAR_MAX +#undef SCHAR_MIN +#undef UCHAR_MAX +#undef UCHAR_MIN +#endif + +#ifdef VERIFY +#include "limits.h" +#include "float.h" +#endif + +#define Vprintf if (V) printf +#define Unexpected(place) if (setjmp(lab)!=0) croak(place) +#define fabs(x) (((x)<0.0)?(-x):(x)) + +#endif /* PASS */ + +#ifdef PASS0 + +/* Prototypes for what's to come: */ + +int false NOARGS; + +#ifdef NO_STDDEF +char *malloc (); /* Old style prototype */ +#else +char *malloc ARGS((size_t size)); +#endif + +Procedure exit ARGS((int status)); + +char *f_rep ARGS((int precision, Long_double val)); +char *fake_f_rep ARGS((char *type, Long_double val)); + +int maximum_int NOARGS; +int cprop NOARGS; +int basic NOARGS; +Procedure sprop NOARGS; +Procedure iprop NOARGS; +Procedure lprop NOARGS; +Procedure usprop NOARGS; +Procedure uiprop NOARGS; +Procedure ulprop NOARGS; +int fprop ARGS((int bits_per_byte)); +int dprop ARGS((int bits_per_byte)); +int ldprop ARGS((int bits_per_byte)); +Procedure efprop ARGS((int fprec, int dprec, int lprec)); +Procedure edprop ARGS((int fprec, int dprec, int lprec)); +Procedure eldprop ARGS((int fprec, int dprec, int lprec)); + +int setmode ARGS((char *s)); +Procedure farewell ARGS((int bugs)); +Procedure describe ARGS((char *description, char *extra)); +Procedure missing ARGS((char *s)); +Procedure fmissing ARGS((char *s)); +Procedure check_defines NOARGS; +Procedure bitpattern ARGS((char *p, unsigned int size)); +int ceil_log ARGS((int base, Long_double x)); +Procedure croak ARGS((int place)); +Procedure eek_a_bug ARGS((char *problem)); +Procedure endian ARGS((int bits_per_byte)); +int exponent ARGS((Long_double x, double *fract, int *exp)); +int floor_log ARGS((int base, Long_double x)); +Procedure f_define ARGS((char *desc, char *extra, char *sort, char *name, + int prec, Long_double val, char *mark)); +Procedure i_define ARGS((char *desc, char *extra, char *sort, char *name, + long val, long lim, long req, char *mark)); +Procedure u_define ARGS((char *desc, char *extra, char *sort, char *name, + unsigned long val, unsigned long req, char *mark)); + +#ifdef NO_SIG /* There's no signal(), or setjmp/longjmp() */ + + /* Dummy routines instead */ + + int setjmp ARGS((int lab)); + + int lab=1; + int setjmp(lab) int lab; { return(0); } + Procedure signal(i, p) int i, (*p)(); {} + +#else + jmp_buf lab; + Procedure overflow(sig) int sig; { /* what to do on over/underflow */ + signal(sig, overflow); + longjmp(lab, 1); + } + +#endif /*NO_SIG*/ + +int V= 0, /* verbose */ + L= 0, /* produce limits.h */ + F= 0, /* produce float.h */ + bugs=0; /* The number of (possible) bugs in the output */ + +char co[4], oc[4]; /* Comment starter and ender symbols */ + +int bits_per_byte; /* the number of bits per unit returned by sizeof() */ +int flt_rounds; /* The calculated value of FLT_ROUNDS */ +int flt_radix; /* The calculated value of FLT_RADIX */ + +#ifdef TEST +/* Set the fp modes on a SUN with 68881 chip, to check that different + rounding modes etc. get properly detected. + Compile with -f68881 for cc, -m68881 for gcc, and with additional flag + -DTEST. Run with additional parameter +hex-number, to set the 68881 mode + register to hex-number +*/ + +/* Bits 0x30 = rounding mode */ +#define ROUND_BITS 0x30 +#define TO_NEAREST 0x00 +#define TO_ZERO 0x10 +#define TO_MINUS_INF 0x20 +#define TO_PLUS_INF 0x30 /* The SUN FP user's guide seems to be wrong here */ + +/* Bits 0xc0 = extended rounding */ +#define EXT_BITS 0xc0 +#define ROUND_EXTENDED 0x00 +#define ROUND_SINGLE 0x40 +#define ROUND_DOUBLE 0x80 + +/* Enabled traps */ +#define EXE_INEX1 0x100 +#define EXE_INEX2 0x200 +#define EXE_DZ 0x400 +#define EXE_UNFL 0x800 +#define EXE_OVFL 0x1000 +#define EXE_OPERR 0x2000 +#define EXE_SNAN 0x4000 +#define EXE_BSUN 0x8000 + +/* Only used for testing, on a Sun with 68881 chip */ +/* Print the FP mode */ +printmode(new) unsigned new; { + fpmode_(&new); + printf("New fp mode:\n"); + printf(" Round toward "); + switch (new & ROUND_BITS) { + case TO_NEAREST: printf("nearest"); break; + case TO_ZERO: printf("zero"); break; + case TO_MINUS_INF: printf("minus infinity"); break; + case TO_PLUS_INF: printf("plus infinity"); break; + default: printf("???"); break; + } + + printf("\n Extended rounding precision: "); + + switch (new & EXT_BITS) { + case ROUND_EXTENDED: printf("extended"); break; + case ROUND_SINGLE: printf("single"); break; + case ROUND_DOUBLE: printf("double"); break; + default: printf("???"); break; + } + + printf("\n Enabled exceptions:"); + if (new & (unsigned) EXE_INEX1) printf(" inex1"); + if (new & (unsigned) EXE_INEX2) printf(" inex2"); + if (new & (unsigned) EXE_DZ) printf(" dz"); + if (new & (unsigned) EXE_UNFL) printf(" unfl"); + if (new & (unsigned) EXE_OVFL) printf(" ovfl"); + if (new & (unsigned) EXE_OPERR) printf(" operr"); + if (new & (unsigned) EXE_SNAN) printf(" snan"); + if (new & (unsigned) EXE_BSUN) printf(" bsun"); + printf("\n"); +} + +/* Only used for testing, on a Sun with 68881 chip */ +/* Set the FP mode */ +int setmode(s) char *s; { + unsigned mode=0, dig; + char c; + + while (*s) { + c= *s++; + if (c>='0' && c<='9') dig= c-'0'; + else if (c>='a' && c<='f') dig= c-'a'+10; + else if (c>='A' && c<='F') dig= c-'A'+10; + else return 1; + mode= mode<<4 | dig; + } + printmode(mode); + return 0; +} +#else +/* ARGSUSED */ +int setmode(s) char *s; { + fprintf(stderr, "Can't set mode: not compiled with TEST\n"); + return(1); +} +#endif + +Procedure farewell(bugs) int bugs; { + if (bugs == 0) exit(0); + printf("\n%sFor hints on dealing with the ", co); + if (bugs == 1) printf("problem"); + else printf("%d problems", bugs); + printf(" above\n see the section 'TROUBLESHOOTING' in the file "); + printf("%s%s\n", FILENAME, oc); + exit(bugs); +} + +/* The program has received a signal where it wasn't expecting one */ +Procedure croak(place) int place; { + printf("*** Unexpected signal at point %d\n", place); + farewell(bugs+1); /* An exit isn't essential here, but avoids loops */ +} + +/* This is here in case alloca.c is used, which calls this. */ +char *xmalloc(size) unsigned size; { + char *value = (char *)malloc(size); + if (value == 0) { + fprintf(stderr, "Virtual memory exceeded\n"); + exit(bugs+1); + } + return value; +} + +int maxint; + +int maximum_int() { + /* Find the maximum integer */ + Volatile int newi, int_max, two=2; + + /* Calculate maxint ***********************************/ + /* Calculate 2**n-1 until overflow - then use the previous value */ + + newi=1; int_max=0; + + if (setjmp(lab)==0) { /* Yields int_max */ + while(newi>int_max) { + int_max=newi; + newi=newi*two+1; + } + } + Unexpected(0); + return int_max; +} + +int main(argc, argv) int argc; char *argv[]; { + int dprec, fprec, lprec; + int i; char *s; int bad; + +#ifdef SIGFPE + signal(SIGFPE, overflow); +#endif +#ifdef SIGOVER + signal(SIGOVER, overflow); +#endif +/* Add more calls as necessary */ + + Unexpected(1); + + bad=0; + for (i=1; i < argc; i++) { + s= argv[i]; + if (*s == '-') { + s++; + while (*s) { + switch (*(s++)) { + case 'v': V=1; break; + case 'l': L=1; break; + case 'f': F=1; break; + default: bad=1; break; + } + } + } else if (*s == '+') { + s++; + bad= setmode(s); + } else bad= 1; + } + if (bad) { + fprintf(stderr, + "Usage: %s [-vlf]\n v=Verbose l=Limits.h f=Float.h\n", + argv[0]); + exit(1); + } + if (L || F) { + co[0]= '/'; oc[0]= ' '; + co[1]= '*'; oc[1]= '*'; + co[2]= ' '; oc[2]= '/'; + co[3]= '\0'; oc[3]= '\0'; + } else { + co[0]= '\0'; oc[0]= '\0'; + V=1; + } + + if (L) printf("%slimits.h%s\n", co, oc); + if (F) printf("%sfloat.h%s\n", co, oc); + if (F) { + printf ("#ifndef _FLOAT_H___\n"); + printf ("#define _FLOAT_H___\n"); + } +#ifdef ID + printf("%sProduced on %s by enquire version %s, CWI, Amsterdam%s\n", + co, ID, VERSION, oc); +#else + printf("%sProduced by enquire version %s, CWI, Amsterdam%s\n", + co, VERSION, oc); +#endif + +#ifdef VERIFY + printf("%sVerification phase%s\n", co, oc); +#endif + +#ifdef NO_SIG + Vprintf("%sCompiled without signal(): %s%s\n", + co, + "there's nothing that can be done if overflow occurs", + oc); +#endif +#ifdef NO_SC + Vprintf("%sCompiled without signed char%s\n", co, oc); +#endif +#ifdef NO_UC + Vprintf("%Compiled without unsigned char%s\n", co, oc); +#endif +#ifdef NO_UI + Vprintf("%Compiled without unsigned short or long%s\n", co, oc); +#endif +#ifdef __STDC__ + Vprintf("%sCompiler claims to be ANSI C level %d%s\n", + co, __STDC__, oc); +#else + Vprintf("%sCompiler does not claim to be ANSI C%s\n", co, oc); +#endif + printf("\n"); + check_defines(); + + maxint= maximum_int(); + bits_per_byte= basic(); + Vprintf("\n"); + if (F||V) { + fprec= fprop(bits_per_byte); + dprec= dprop(bits_per_byte); + lprec= ldprop(bits_per_byte); + efprop(fprec, dprec, lprec); + edprop(fprec, dprec, lprec); + eldprop(fprec, dprec, lprec); + } +#ifndef NO_MEM + if (V) { + unsigned int size; + long total; + /* An extra goody: the approximate amount of data-space */ + /* Allocate store until no more available */ + /* Different implementations have a different argument type + to malloc. Here we assume that it's the same type as + that which sizeof() returns */ + size=1<<((bits_per_byte*sizeof(int))-2); + total=0; + while (size!=0) { + while ( malloc((false()?sizeof(int):size)) != + (char *)NULL + ) { + total+=(size/2); + } + size/=2; + } + + Vprintf("%sMemory mallocatable ~= %ld Kbytes%s\n", + co, (total+511)/512, oc); + } +#endif + if (F) { + printf ("#endif %s _FLOAT_H___%s\n", co, oc); + } + farewell(bugs); + return bugs; /* To keep compilers and lint happy */ +} + +Procedure eek_a_bug(problem) char *problem; { + /* The program has discovered a problem */ + printf("\n%s*** WARNING: %s%s\n", co, problem, oc); + bugs++; +} + +Procedure describe(description, extra) char *description, *extra; { + /* Produce the description for a #define */ + printf(" %s", co); + printf(description, extra); + printf("%s\n", oc); +} + +Procedure i_define(desc, extra, sort, name, val, lim, req, mark) + char *desc, *extra, *sort, *name; long val, lim, req; char *mark; { + /* Produce a #define for a signed int type */ + describe(desc, extra); + printf("#undef %s%s\n", sort, name); + if (val >= 0) { + printf("#define %s%s %ld%s\n", sort, name, val, mark); + } else if (val + lim < 0) { + /* We may not produce a constant like -1024 if the max + allowable value is 1023. It has then to be output as + -1023-1. lim is the max allowable value. */ + printf("#define %s%s (%ld%s%ld%s)\n", + sort, name, -lim, mark, val+lim, mark); + } else { + printf("#define %s%s (%ld%s)\n", sort, name, val, mark); + } + /* If VERIFY is not set, val and req are just the same value; + if it is set, val is the value as calculated, and req is + the #defined constant + */ + if (val != req) { + printf("%s*** Verify failed for above #define!\n", co); + printf(" Compiler has %ld for value%s\n\n", req, oc); + bugs++; + } + Vprintf("\n"); +} + +Procedure u_define(desc, extra, sort, name, val, req, mark) + char *desc, *extra, *sort, *name; unsigned long val, req; char *mark; { + /* Produce a #define for an unsigned value */ + describe(desc, extra); + printf("#undef %s%s\n", sort, name); + printf("#define %s%s %lu%s%s\n", sort, name, val, U, mark); + if (val != req) { + printf("%s*** Verify failed for above #define!\n", co); + printf(" Compiler has %lu for value%s\n\n", req, oc); + bugs++; + } + Vprintf("\n"); +} + +Procedure f_define(desc, extra, sort, name, precision, val, mark) + char *desc, *extra, *sort, *name; int precision; + Long_double val; char *mark; { + /* Produce a #define for a float/double/long double */ + describe(desc, extra); + printf ("#undef %s%s\n", sort, name); + if (stdc) { +#ifdef NO_LONG_DOUBLE_IO + static int union_defined = 0; + if (sizeof(double) != sizeof(Long_double) + && !strcmp(sort, "LDBL")) { + if (!union_defined) { + printf("#ifndef __LDBL_UNION__\n"); + printf("#define __LDBL_UNION__\n"); + printf("union __convert_long_double {\n"); + printf(" unsigned __convert_long_double_i[4];\n"); + printf(" long double __convert_long_double_d;\n"); + printf("};\n"); + printf("#endif\n"); + union_defined = 1; + } + printf("#define %s%s %s\n", + sort, name, fake_f_rep("long double", val)); + } else { + printf("#define %s%s %s%s\n", + sort, name, f_rep(precision, val), mark); + } +#else + printf("#define %s%s %s%s\n", + sort, name, f_rep(precision, val), mark); +#endif + } else if (*mark == 'F') { + /* non-ANSI C has no float constants, so cast the constant */ + printf("#define %s%s ((float)%s)\n", + sort, name, f_rep(precision, val)); + } else { + printf("#define %s%s %s\n", sort, name, f_rep(precision, val)); + } + Vprintf("\n"); +} + +int floor_log(base, x) int base; Long_double x; { + /* return floor(log base(x)) */ + int r=0; + while (x>=base) { r++; x/=base; } + return r; +} + +int ceil_log(base, x) int base; Long_double x; { + int r=0; + while (x>1.0) { r++; x/=base; } + return r; +} + +int exponent(x, fract, exp) Long_double x; double *fract; int *exp; { + /* Split x into a fraction and a power of ten; + returns 0 if x is unusable, 1 otherwise. + Only used for error messages about faulty output. + */ + int r=0, neg=0; + Long_double old; + *fract=0.0; *exp=0; + if (x<0.0) { + x= -x; + neg= 1; + } + if (x==0.0) return 1; + if (x>=10.0) { + while (x>=10.0) { + old=x; r++; x/=10.0; + if (old==x) return 0; + } + } else { + while (x<1.0) { + old=x; r--; x*=10.0; + if (old==x) return 0; + } + } + if (neg) *fract= (double) -x; + else *fract=(double) x; + *exp=r; + return 1; +} + +/* Print a value of type TYPE with value VAL, + assuming that sprintf can't handle this type properly (without truncation). + We create an expression that uses type casting to create the value from + a bit pattern. */ + +char *fake_f_rep(type, val) char *type; Long_double val; { + static char buf[1024]; + union { unsigned int i[4]; Long_double ld;} u; + u.i[0] = u.i[1] = u.i[2] = u.i[3] = 0; + u.ld = val; + sprintf(buf, "(__extension__ ((union __convert_long_double) {0x%x, 0x%x, 0x%x, 0x%x}).__convert_long_double_d)", + u.i[0], u.i[1], u.i[2], u.i[3]); + return buf; +} + +char *f_rep(precision, val) int precision; Long_double val; { + /* Return the floating representation of val */ + static char buf[1024]; +#ifdef NO_LONG_DOUBLE_IO + if (1) +#else + if (sizeof(double) == sizeof(Long_double)) +#endif + { + double d = val; + /* Assume they're the same, and use non-stdc format */ + /* This is for stdc compilers using non-stdc libraries */ + sprintf(buf, "%.*e", precision, d); + } else { + /* It had better support Le then */ + sprintf(buf, "%.*Le", precision, val); + } + return buf; +} + +Procedure bitpattern(p, size) char *p; unsigned int size; { + /* Printf the bit-pattern of p */ + char c; + int i, j; + + for (i=1; i<=size; i++) { + c= *p; + p++; + for (j=bits_per_byte-1; j>=0; j--) + printf("%c", (c>>j)&1 ? '1' : '0'); + if (i!=size) printf(" "); + } +} + +#define Order(x, px, mode)\ + printf("%s%s ", co, mode); for (i=0; i>(bits_per_byte*(sizeof(x)-i)))&mask);\ + putchar(c==0 ? '?' : (char)c); }\ + printf("%s\n", oc); + +Procedure endian(bits_per_byte) int bits_per_byte; { + /* Printf the byte-order used on this machine */ + /*unsigned*/ short s=0; + /*unsigned*/ int j=0; + /*unsigned*/ long l=0; + + char *ps= (char *) &s, + *pj= (char *) &j, + *pl= (char *) &l, + *ab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + unsigned int mask, i, c; + + mask=0; + for (i=1; i<=(unsigned)bits_per_byte; i++) mask= (mask<<1)|1; + + if (V) { + printf("%sCHARACTER ORDER%s\n", co, oc); + Order(s, ps, "short:"); + Order(j, pj, "int: "); + Order(l, pl, "long: "); + } +} + +Procedure missing(s) char *s; { + printf("%s*** #define %s missing from limits.h%s\n", co, s, oc); + bugs++; +} + +Procedure fmissing(s) char *s; { + printf("%s*** #define %s missing from float.h%s\n", co, s, oc); + bugs++; +} + +/* To try and fool optimisers */ +int false() { return 0; } + +#define Promoted(x) (false()?(x):(-1)) +#define is_signed(x) (Promoted(x) < 0) +#define sign_of(x) ((x)?"signed":"unsigned") +#define Signed 1 +#define Unsigned 0 +#define sgn(x) ((is_signed(x))?Signed:Unsigned) + +#define showtype(t, x) Vprintf("%s%s %s %s%s\n", co, t, sign_of(is_signed(x)), type_of(sizeof(x)), oc) + +char *type_of(x) int x; { + if (x == sizeof(char)) { + if (sizeof(char) == sizeof(int)) return "char/short/int"; + if (sizeof(char) == sizeof(short)) return "char/short"; + return "char"; + } + if (x == sizeof(short)) { + if (sizeof(short) == sizeof(int)) return "short/int"; + return "short"; + } + if (x == sizeof(int)) { + if (sizeof(int) == sizeof(long)) return "int/long"; + return "int"; + } + if (x == sizeof(long)) return "long"; + return "unknown-type"; +} + +char *ftype_of(x) int x; { + if (x == sizeof(float)) { + return "float"; + } + if (x == sizeof(double)) { + if (sizeof(double) == sizeof(Long_double)) + return "(long)double"; + return "double"; + } + if (x == sizeof(Long_double)) { + return "long double"; + } + return "unknown-type"; +} + +Procedure typerr(name, esign, esize, sign, size) + char *name; int esign, esize, sign, size; +{ + Vprintf("*** %s has wrong type: expected %s %s, found %s %s\n", + name, sign_of(esign), type_of(esize), + sign_of(sign), type_of(size)); +} + +Procedure ftyperr(name, esize, size) char *name; int esize, size; { + Vprintf("*** %s has wrong type: expected %s, found %s\n", + name, ftype_of(esize), ftype_of(size)); +} + +int promotions() { + int si = 0; long sl = 0; + unsigned int ui; unsigned long ul; + short ss; unsigned short us; + + Vprintf("\n%sPROMOTIONS%s\n", co, oc); + + if ( + /* Possible warnings here; no problem */ + (sizeof(Promoted(si)) != sizeof(int)) || + (sizeof(Promoted(sl)) != sizeof(long)) || + (sizeof(Promoted(ss)) != sizeof(int)) || + (sizeof(Promoted(ui)) != sizeof(int)) || + (sizeof(Promoted(ul)) != sizeof(long)) || + (sizeof(Promoted(us)) != sizeof(int)) || + is_signed(ui) || is_signed(ul) || + !is_signed(si) || !is_signed(sl) + ) + { + eek_a_bug("promotions don't work properly in conditional expressions\n"); + } + + showtype("unsigned short promotes to", Promoted((unsigned short)0)); + showtype("long+unsigned gives", sl+ui); + return 0; +} + +#define checktype(x, n, s, t) if((sgn(x)!=s)||(sizeof(x)!=sizeof(t))) typerr(n, s, sizeof(t), sign_of(x), sizeof(x)); + +#define fchecktype(x, n, t) if (sizeof(x) != sizeof(t)) ftyperr(n, sizeof(x), sizeof(t)); + +Procedure check_defines() { + /* ensure that all #defines are present and have the correct type */ +#ifdef VERIFY + int usign; + +#ifdef NO_UI + usign= Signed; +#else + /* Implementations promote unsigned short differently */ + usign= is_signed((unsigned short)0); +#endif + + if (L) { +#ifdef CHAR_BIT + checktype(CHAR_BIT, "CHAR_BIT", Signed, int); +#else + missing("CHAR_BIT"); +#endif +#ifdef CHAR_MAX + checktype(CHAR_MAX, "CHAR_MAX", Signed, int); +#else + missing("CHAR_MAX"); +#endif +#ifdef CHAR_MIN + checktype(CHAR_MIN, "CHAR_MIN", Signed, int); +#else + missing("CHAR_MIN"); +#endif +#ifdef SCHAR_MAX + checktype(SCHAR_MAX, "SCHAR_MAX", Signed, int); +#else + missing("SCHAR_MAX"); +#endif +#ifdef SCHAR_MIN + checktype(SCHAR_MIN, "SCHAR_MIN", Signed, int); +#else + missing("SCHAR_MIN"); +#endif +#ifdef UCHAR_MAX + checktype(UCHAR_MAX, "UCHAR_MAX", Signed, int); +#else + missing("UCHAR_MAX"); +#endif +#ifdef SHRT_MAX + checktype(SHRT_MAX, "SHRT_MAX", Signed, int); +#else + missing("SHRT_MAX"); +#endif +#ifdef SHRT_MIN + checktype(SHRT_MIN, "SHRT_MIN", Signed, int); +#else + missing("SHRT_MIN"); +#endif +#ifdef INT_MAX + checktype(INT_MAX, "INT_MAX", Signed, int); +#else + missing("INT_MAX"); +#endif +#ifdef INT_MIN + checktype(INT_MIN, "INT_MIN", Signed, int); +#else + missing("INT_MIN"); +#endif +#ifdef LONG_MAX + checktype(LONG_MAX, "LONG_MAX", Signed, long); +#else + missing("LONG_MAX"); +#endif +#ifdef LONG_MIN + checktype(LONG_MIN, "LONG_MIN", Signed, long); +#else + missing("LONG_MIN"); +#endif +#ifdef USHRT_MAX + checktype(USHRT_MAX, "USHRT_MAX", usign, int); +#else + missing("USHRT_MAX"); +#endif +#ifdef UINT_MAX + checktype(UINT_MAX, "UINT_MAX", Unsigned, int); +#else + missing("UINT_MAX"); +#endif +#ifdef ULONG_MAX + checktype(ULONG_MAX, "ULONG_MAX", Unsigned, long); +#else + missing("ULONG_MAX"); +#endif + } /* if (L) */ + + if (F) { +#ifdef FLT_RADIX + checktype(FLT_RADIX, "FLT_RADIX", Signed, int); +#else + fmissing("FLT_RADIX"); +#endif +#ifdef FLT_MANT_DIG + checktype(FLT_MANT_DIG, "FLT_MANT_DIG", Signed, int); +#else + fmissing("FLT_MANT_DIG"); +#endif +#ifdef FLT_DIG + checktype(FLT_DIG, "FLT_DIG", Signed, int); +#else + fmissing("FLT_DIG"); +#endif +#ifdef FLT_ROUNDS + checktype(FLT_ROUNDS, "FLT_ROUNDS", Signed, int); +#else + fmissing("FLT_ROUNDS"); +#endif +#ifdef FLT_EPSILON + fchecktype(FLT_EPSILON, "FLT_EPSILON", float); +#else + fmissing("FLT_EPSILON"); +#endif +#ifdef FLT_MIN_EXP + checktype(FLT_MIN_EXP, "FLT_MIN_EXP", Signed, int); +#else + fmissing("FLT_MIN_EXP"); +#endif +#ifdef FLT_MIN + fchecktype(FLT_MIN, "FLT_MIN", float); +#else + fmissing("FLT_MIN"); +#endif +#ifdef FLT_MIN_10_EXP + checktype(FLT_MIN_10_EXP, "FLT_MIN_10_EXP", Signed, int); +#else + fmissing("FLT_MIN_10_EXP"); +#endif +#ifdef FLT_MAX_EXP + checktype(FLT_MAX_EXP, "FLT_MAX_EXP", Signed, int); +#else + fmissing("FLT_MAX_EXP"); +#endif +#ifdef FLT_MAX + fchecktype(FLT_MAX, "FLT_MAX", float); +#else + fmissing("FLT_MAX"); +#endif +#ifdef FLT_MAX_10_EXP + checktype(FLT_MAX_10_EXP, "FLT_MAX_10_EXP", Signed, int); +#else + fmissing("FLT_MAX_10_EXP"); +#endif +#ifdef DBL_MANT_DIG + checktype(DBL_MANT_DIG, "DBL_MANT_DIG", Signed, int); +#else + fmissing("DBL_MANT_DIG"); +#endif +#ifdef DBL_DIG + checktype(DBL_DIG, "DBL_DIG", Signed, int); +#else + fmissing("DBL_DIG"); +#endif +#ifdef DBL_EPSILON + fchecktype(DBL_EPSILON, "DBL_EPSILON", double); +#else + fmissing("DBL_EPSILON"); +#endif +#ifdef DBL_MIN_EXP + checktype(DBL_MIN_EXP, "DBL_MIN_EXP", Signed, int); +#else + fmissing("DBL_MIN_EXP"); +#endif +#ifdef DBL_MIN + fchecktype(DBL_MIN, "DBL_MIN", double); +#else + fmissing("DBL_MIN"); +#endif +#ifdef DBL_MIN_10_EXP + checktype(DBL_MIN_10_EXP, "DBL_MIN_10_EXP", Signed, int); +#else + fmissing("DBL_MIN_10_EXP"); +#endif +#ifdef DBL_MAX_EXP + checktype(DBL_MAX_EXP, "DBL_MAX_EXP", Signed, int); +#else + fmissing("DBL_MAX_EXP"); +#endif +#ifdef DBL_MAX + fchecktype(DBL_MAX, "DBL_MAX", double); +#else + fmissing("DBL_MAX"); +#endif +#ifdef DBL_MAX_10_EXP + checktype(DBL_MAX_10_EXP, "DBL_MAX_10_EXP", Signed, int); +#else + fmissing("DBL_MAX_10_EXP"); +#endif +#ifdef STDC +#ifdef LDBL_MANT_DIG + checktype(LDBL_MANT_DIG, "LDBL_MANT_DIG", Signed, int); +#else + fmissing("LDBL_MANT_DIG"); +#endif +#ifdef LDBL_DIG + checktype(LDBL_DIG, "LDBL_DIG", Signed, int); +#else + fmissing("LDBL_DIG"); +#endif +#ifdef LDBL_EPSILON + fchecktype(LDBL_EPSILON, "LDBL_EPSILON", long double); +#else + fmissing("LDBL_EPSILON"); +#endif +#ifdef LDBL_MIN_EXP + checktype(LDBL_MIN_EXP, "LDBL_MIN_EXP", Signed, int); +#else + fmissing("LDBL_MIN_EXP"); +#endif +#ifdef LDBL_MIN + fchecktype(LDBL_MIN, "LDBL_MIN", long double); +#else + fmissing("LDBL_MIN"); +#endif +#ifdef LDBL_MIN_10_EXP + checktype(LDBL_MIN_10_EXP, "LDBL_MIN_10_EXP", Signed, int); +#else + fmissing("LDBL_MIN_10_EXP"); +#endif +#ifdef LDBL_MAX_EXP + checktype(LDBL_MAX_EXP, "LDBL_MAX_EXP", Signed, int); +#else + fmissing("LDBL_MAX_EXP"); +#endif +#ifdef LDBL_MAX + fchecktype(LDBL_MAX, "LDBL_MAX", long double); +#else + fmissing("LDBL_MAX"); +#endif +#ifdef LDBL_MAX_10_EXP + checktype(LDBL_MAX_10_EXP, "LDBL_MAX_10_EXP", Signed, int); +#else + fmissing("LDBL_MAX_10_EXP"); +#endif +#endif /* STDC */ + } /* if (F) */ +#endif /* VERIFY */ +} + +#ifdef VERIFY +#ifndef SCHAR_MAX +#define SCHAR_MAX char_max +#endif +#ifndef SCHAR_MIN +#define SCHAR_MIN char_min +#endif +#ifndef UCHAR_MAX +#define UCHAR_MAX char_max +#endif +#endif /* VERIFY */ + +#ifndef CHAR_BIT +#define CHAR_BIT char_bit +#endif +#ifndef CHAR_MAX +#define CHAR_MAX char_max +#endif +#ifndef CHAR_MIN +#define CHAR_MIN char_min +#endif +#ifndef SCHAR_MAX +#define SCHAR_MAX char_max +#endif +#ifndef SCHAR_MIN +#define SCHAR_MIN char_min +#endif +#ifndef UCHAR_MAX +#define UCHAR_MAX char_max +#endif + +int cprop() { + /* Properties of type char */ + Volatile char c, char_max, char_min; + Volatile int bits_per_byte, c_signed; + long char_bit; + + Unexpected(2); + + /* Calculate number of bits per character *************************/ + c=1; bits_per_byte=0; + do { c=c<<1; bits_per_byte++; } while(c!=0); + c= (char)(-1); + if (((int)c)<0) c_signed=1; + else c_signed=0; + Vprintf("%schar = %d bits, %ssigned%s\n", + co, (int)sizeof(c)*bits_per_byte, (c_signed?"":"un"), oc); + char_bit=(long)(sizeof(c)*bits_per_byte); + if (L) i_define(D_CHAR_BIT, "", "CHAR", "_BIT", + char_bit, 0L, (long) CHAR_BIT, ""); + + c=0; char_max=0; + c++; + if (setjmp(lab)==0) { /* Yields char_max */ + while (c>char_max) { + char_max=c; + c++; + } + } else { + Vprintf("%sCharacter overflow generates a trap!%s\n", co, oc); + } + c=0; char_min=0; + c--; + if (setjmp(lab)==0) { /* Yields char_min */ + while (cchar_max) { + char_max=c; + c++; + } + } + Unexpected(4); + if (sizeof(char) == sizeof(int)) { + u_define(D_UCHAR_MAX, "", "UCHAR", "_MAX", + (long) char_max, + (long) UCHAR_MAX, ""); + } else { + i_define(D_UCHAR_MAX, "", "UCHAR", "_MAX", + (long) char_max, 0L, + (long) UCHAR_MAX, ""); + } +#endif + } else { +#ifndef NO_SC +/* Define NO_SC if this gives a syntax error */ Volatile signed char c, char_max, char_min; + c=0; char_max=0; + c++; + if (setjmp(lab)==0) { /* Yields char_max */ + while (c>char_max) { + char_max=c; + c++; + } + } + c=0; char_min=0; + c--; + if (setjmp(lab)==0) { /* Yields char_min */ + while (csizeof(int)?" BEWARE! larger than int!":"", + oc); + Vprintf("%sint* =%d bits%s%s\n", + co, (int)sizeof(int *)*bits_per_byte, + sizeof(int *)>sizeof(int)?" BEWARE! larger than int!":"", + oc); + Vprintf("%sfunc*=%d bits%s%s\n", + co, (int)sizeof(function *)*bits_per_byte, + sizeof(function *)>sizeof(int)?" BEWARE! larger than int!":"", + oc); +if (V) printf ("%s%s %s %s%s\n", co, "Type size_t is", + ((((false()?( sizeof(int)):(-1)) < 0) )? + "signed":"unsigned") , + type_of(sizeof( + sizeof(int)+0 + ) + ), + oc); + showtype("Type size_t is", sizeof(0)); + + /* Alignment constants ********************************************/ + +#define alignment(TYPE) \ + ((long)((char *)&((struct{char c; TYPE d;}*)0)->d - (char *)0)) + + Vprintf("\n%sALIGNMENTS%s\n", co, oc); + + Vprintf("%schar=%ld short=%ld int=%ld long=%ld%s\n", + co, + alignment(char), alignment(short), + alignment(int), alignment(long), + oc); + + Vprintf("%sfloat=%ld double=%ld%s\n", + co, + alignment(float), alignment(double), + oc); + + if (stdc) { + Vprintf("%slong double=%ld%s\n", + co, + alignment(Long_double), + oc); + } + Vprintf("%schar*=%ld int*=%ld func*=%ld%s\n", + co, + alignment(char *), alignment(int *), alignment(function *), + oc); + + Vprintf("\n"); + + /* Ten little endians *********************************************/ + + endian(bits_per_byte); + + /* Pointers *******************************************************/ + + Vprintf("\n%sPROPERTIES OF POINTERS%s\n", co, oc); + + if ((long) (char *) &variable == (long) (int *) &variable) + Vprintf("%sChar and int pointer formats seem identical%s\n", + co, oc); + else + Vprintf("%sChar and int pointer formats are different%s\n", + co, oc); + if ((long) (char *) &variable == (long) (function *) &variable) + Vprintf("%sChar and function pointer formats seem identical%s\n", + co, oc); + else + Vprintf("%sChar and function pointer formats are different%s\n", + co, oc); + + if (V) { + if ("abcd"=="abcd") + printf("%sStrings are shared%s\n", co, oc); + else printf("%sStrings are not shared%s\n", co, oc); + } + + p=0; q=0; + showtype("Type ptrdiff_t is", p-q); + + Vprintf("\n%sPROPERTIES OF INTEGRAL TYPES%s\n", co, oc); + + sprop(); + iprop(); + lprop(); + usprop(); + uiprop(); + ulprop(); + + promotions(); + + Unexpected(6); + + return bits_per_byte; +} + +#else /* not PASS0 */ + +#ifdef SEP +extern jmp_buf lab; +extern int V, L, F, bugs, bits_per_byte; +extern char co[], oc[]; +extern char *f_rep(); +#endif /* SEP */ +#endif /* ifdef PASS0 */ + +/* As I said, I apologise for the contortions below. The functions are + expanded by the preprocessor twice or three times (for float and double, + and maybe for long double, and for short, int and long). That way, + I never make a change to one that I forget to make to the other. + You can look on it as C's fault for not supporting multi-line macro's. + This whole file is read 3 times by the preprocessor, with PASSn set for + n=1, 2 or 3, to decide which parts to reprocess. +*/ + +/* #undef on an already undefined thing is (wrongly) flagged as an error + by some compilers, therefore the #ifdef that follows: +*/ +#ifdef Number +#undef Number +#undef THING +#undef Thing +#undef thing +#undef FPROP +#undef Fname +#undef Store +#undef Sum +#undef Diff +#undef Mul +#undef Div +#undef ZERO +#undef HALF +#undef ONE +#undef TWO +#undef THREE +#undef FOUR +#undef Self +#undef F_check +#undef Validate +#undef EPROP +#undef MARK + +/* These are the float.h constants */ +#undef F_RADIX +#undef F_MANT_DIG +#undef F_DIG +#undef F_ROUNDS +#undef F_EPSILON +#undef F_MIN_EXP +#undef F_MIN +#undef F_MIN_10_EXP +#undef F_MAX_EXP +#undef F_MAX +#undef F_MAX_10_EXP +#endif + +#ifdef Integer +#undef Integer +#undef INT +#undef IPROP +#undef Iname +#undef UPROP +#undef Uname +#undef OK_UI +#undef IMARK + +#undef I_MAX +#undef I_MIN +#undef U_MAX +#endif + +#ifdef PASS1 + +/* Define the things we're going to use this pass */ + +#define Number float +#define THING "FLOAT" +#define Thing "Float" +#define thing "float" +#define Fname "FLT" +#define FPROP fprop +#define Store fStore +#define Sum fSum +#define Diff fDiff +#define Mul fMul +#define Div fDiv +#define ZERO 0.0 +#define HALF 0.5 +#define ONE 1.0 +#define TWO 2.0 +#define THREE 3.0 +#define FOUR 4.0 +#define Self fSelf +#define F_check fCheck +#define MARK "F" +#ifdef VERIFY +#define Validate(prec, val, req, same) fValidate(prec, val, req, same) +#endif + +#define EPROP efprop + +#define Integer short +#define INT "short" +#define IPROP sprop +#define Iname "SHRT" +#ifndef NO_UI +#define OK_UI 1 +#endif +#define IMARK "" + +#define UPROP usprop +#define Uname "USHRT" + +#ifdef VERIFY +#ifdef SHRT_MAX +#define I_MAX SHRT_MAX +#endif +#ifdef SHRT_MIN +#define I_MIN SHRT_MIN +#endif +#ifdef USHRT_MAX +#define U_MAX USHRT_MAX +#endif + +#ifdef FLT_RADIX +#define F_RADIX FLT_RADIX +#endif +#ifdef FLT_MANT_DIG +#define F_MANT_DIG FLT_MANT_DIG +#endif +#ifdef FLT_DIG +#define F_DIG FLT_DIG +#endif +#ifdef FLT_ROUNDS +#define F_ROUNDS FLT_ROUNDS +#endif +#ifdef FLT_EPSILON +#define F_EPSILON FLT_EPSILON +#endif +#ifdef FLT_MIN_EXP +#define F_MIN_EXP FLT_MIN_EXP +#endif +#ifdef FLT_MIN +#define F_MIN FLT_MIN +#endif +#ifdef FLT_MIN_10_EXP +#define F_MIN_10_EXP FLT_MIN_10_EXP +#endif +#ifdef FLT_MAX_EXP +#define F_MAX_EXP FLT_MAX_EXP +#endif +#ifdef FLT_MAX +#define F_MAX FLT_MAX +#endif +#ifdef FLT_MAX_10_EXP +#define F_MAX_10_EXP FLT_MAX_10_EXP +#endif +#endif /* VERIFY */ + +#endif /* PASS1 */ + +#ifdef PASS2 + +#define Number double +#define THING "DOUBLE" +#define Thing "Double" +#define thing "double" +#define Fname "DBL" +#define FPROP dprop +#define Store dStore +#define Sum dSum +#define Diff dDiff +#define Mul dMul +#define Div dDiv +#define ZERO 0.0 +#define HALF 0.5 +#define ONE 1.0 +#define TWO 2.0 +#define THREE 3.0 +#define FOUR 4.0 +#define Self dSelf +#define F_check dCheck +#define MARK "" +#ifdef VERIFY +#define Validate(prec, val, req, same) dValidate(prec, val, req, same) +#endif + +#define EPROP edprop + +#define Integer int +#define INT "int" +#define IPROP iprop +#define Iname "INT" +#define OK_UI 1 /* Unsigned int is always possible */ +#define IMARK "" + +#define UPROP uiprop +#define Uname "UINT" + +#ifdef VERIFY +#ifdef INT_MAX +#define I_MAX INT_MAX +#endif +#ifdef INT_MIN +#define I_MIN INT_MIN +#endif +#ifdef UINT_MAX +#define U_MAX UINT_MAX +#endif + +#ifdef DBL_MANT_DIG +#define F_MANT_DIG DBL_MANT_DIG +#endif +#ifdef DBL_DIG +#define F_DIG DBL_DIG +#endif +#ifdef DBL_EPSILON +#define F_EPSILON DBL_EPSILON +#endif +#ifdef DBL_MIN_EXP +#define F_MIN_EXP DBL_MIN_EXP +#endif +#ifdef DBL_MIN +#define F_MIN DBL_MIN +#endif +#ifdef DBL_MIN_10_EXP +#define F_MIN_10_EXP DBL_MIN_10_EXP +#endif +#ifdef DBL_MAX_EXP +#define F_MAX_EXP DBL_MAX_EXP +#endif +#ifdef DBL_MAX +#define F_MAX DBL_MAX +#endif +#ifdef DBL_MAX_10_EXP +#define F_MAX_10_EXP DBL_MAX_10_EXP +#endif +#endif /* VERIFY */ + +#endif /* PASS2 */ + +#ifdef PASS3 + +#ifdef STDC +#define Number long double + +#define ZERO 0.0L +#define HALF 0.5L +#define ONE 1.0L +#define TWO 2.0L +#define THREE 3.0L +#define FOUR 4.0L +#endif + +#define THING "LONG DOUBLE" +#define Thing "Long double" +#define thing "long double" +#define Fname "LDBL" +#define FPROP ldprop +#define Store ldStore +#define Sum ldSum +#define Diff ldDiff +#define Mul ldMul +#define Div ldDiv +#define Self ldSelf +#define F_check ldCheck +#define MARK "L" +#ifdef VERIFY +#define Validate(prec, val, req, same) ldValidate(prec, val, req, same) +#endif + +#define EPROP eldprop + +#define Integer long +#define INT "long" +#define IPROP lprop +#define Iname "LONG" +#ifndef NO_UI +#define OK_UI 1 +#endif +#define IMARK "L" + +#define UPROP ulprop +#define Uname "ULONG" + +#ifdef VERIFY +#ifdef LONG_MAX +#define I_MAX LONG_MAX +#endif +#ifdef LONG_MIN +#define I_MIN LONG_MIN +#endif +#ifdef ULONG_MAX +#define U_MAX ULONG_MAX +#endif + +#ifdef LDBL_MANT_DIG +#define F_MANT_DIG LDBL_MANT_DIG +#endif +#ifdef LDBL_DIG +#define F_DIG LDBL_DIG +#endif +#ifdef LDBL_EPSILON +#define F_EPSILON LDBL_EPSILON +#endif +#ifdef LDBL_MIN_EXP +#define F_MIN_EXP LDBL_MIN_EXP +#endif +#ifdef LDBL_MIN +#define F_MIN LDBL_MIN +#endif +#ifdef LDBL_MIN_10_EXP +#define F_MIN_10_EXP LDBL_MIN_10_EXP +#endif +#ifdef LDBL_MAX_EXP +#define F_MAX_EXP LDBL_MAX_EXP +#endif +#ifdef LDBL_MAX +#define F_MAX LDBL_MAX +#endif +#ifdef LDBL_MAX_10_EXP +#define F_MAX_10_EXP LDBL_MAX_10_EXP +#endif +#endif /* VERIFY */ + +#endif /* PASS3 */ + +#ifndef I_MAX +#define I_MAX int_max +#endif +#ifndef I_MIN +#define I_MIN int_min +#endif +#ifndef U_MAX +#define U_MAX u_max +#endif + +#ifndef F_RADIX +#define F_RADIX f_radix +#endif +#ifndef F_MANT_DIG +#define F_MANT_DIG f_mant_dig +#endif +#ifndef F_DIG +#define F_DIG f_dig +#endif +#ifndef F_ROUNDS +#define F_ROUNDS f_rounds +#endif +#ifndef F_EPSILON +#define F_EPSILON f_epsilon +#endif +#ifndef F_MIN_EXP +#define F_MIN_EXP f_min_exp +#endif +#ifndef F_MIN +#define F_MIN f_min +#endif +#ifndef F_MIN_10_EXP +#define F_MIN_10_EXP f_min_10_exp +#endif +#ifndef F_MAX_EXP +#define F_MAX_EXP f_max_exp +#endif +#ifndef F_MAX +#define F_MAX f_max +#endif +#ifndef F_MAX_10_EXP +#define F_MAX_10_EXP f_max_10_exp +#endif + +#ifndef VERIFY +#define Validate(prec, val, req, same) {;} +#endif + +#ifdef Integer + +Procedure IPROP() { + /* the properties of short, int, and long */ + Volatile Integer newi, int_max, maxeri, int_min, minneri; + Volatile int ibits, ipower, two=2; + + /* Calculate max short/int/long ***********************************/ + /* Calculate 2**n-1 until overflow - then use the previous value */ + + newi=1; int_max=0; + + if (setjmp(lab)==0) { /* Yields int_max */ + for(ipower=0; newi>int_max; ipower++) { + int_max=newi; + newi=newi*two+1; + } + Vprintf("%sOverflow of a%s %s does not generate a trap%s\n", + co, INT[0]=='i'?"n":"", INT, oc); + } else { + Vprintf("%sOverflow of a%s %s generates a trap%s\n", + co, INT[0]=='i'?"n":"", INT, oc); + } + Unexpected(7); + + /* Minimum value: assume either two's or one's complement *********/ + int_min= -int_max; + if (setjmp(lab)==0) { /* Yields int_min */ + if (int_min-1 < int_min) int_min--; + } + Unexpected(8); + + /* Now for those daft Cybers */ + + maxeri=0; newi=int_max; + + if (setjmp(lab)==0) { /* Yields maxeri */ + for(ibits=ipower; newi>maxeri; ibits++) { + maxeri=newi; + newi=newi+newi+1; + } + } + Unexpected(9); + + minneri= -maxeri; + if (setjmp(lab)==0) { /* Yields minneri */ + if (minneri-1 < minneri) minneri--; + } + Unexpected(10); + + Vprintf("%sMaximum %s = %ld (= 2**%d-1)%s\n", + co, INT, (long)int_max, ipower, oc); + Vprintf("%sMinimum %s = %ld%s\n", co, INT, (long)int_min, oc); + + if (L) i_define(D_INT_MAX, INT, Iname, "_MAX", + (long) int_max, 0L, + (long) I_MAX, IMARK); + if (L) i_define(D_INT_MIN, INT, Iname, "_MIN", + (long) int_min, (long) (PASS==1?maxint:int_max), + (long) I_MIN, IMARK); + + if(int_max < 0) { /* It has happened */ + eek_a_bug("signed integral comparison faulty?"); + } + + if (maxeri>int_max) { + Vprintf("%sThere is a larger %s, %ld (= 2**%d-1), %s %s%s\n", + co, INT, (long)maxeri, ibits, + "but only for addition, not multiplication", + "(I smell a Cyber!)", + oc); + } + + if (minneriu_max) { + u_max=newi; + newi=newi*two+1; + } + } + Unexpected(11); + Vprintf("%sMaximum unsigned %s = %lu%s\n", + co, INT, (unsigned long) u_max, oc); + + /* Oh woe: new standard C defines value preserving promotions */ + if (L) { + if (PASS == 1 && sizeof(short) < sizeof(int)) { + /* Special only for short */ + i_define(D_UINT_MAX, INT, Uname, "_MAX", + (unsigned long) u_max, 0L, + (unsigned long) U_MAX, IMARK); + } else { + u_define(D_UINT_MAX, INT, Uname, "_MAX", + (unsigned long) u_max, + (unsigned long) U_MAX, IMARK); + } + } +#endif +} + +#endif /* Integer */ + +#ifdef Number + +/* The following routines are intended to defeat any attempt at optimisation + or use of extended precision, and to defeat faulty narrowing casts. + The weird prototypes are because of widening incompatibilities. +*/ +#ifdef STDC +#define ARGS1(atype, a) (atype a) +#define ARGS2(atype, a, btype, b) (atype a, btype b) +#else +#define ARGS1(atype, a) (a) atype a; +#define ARGS2(atype, a, btype, b) (a, b) atype a; btype b; +#endif + +Procedure Store ARGS2(Number, a, Number *, b) { *b=a; } +Number Sum ARGS2(Number, a, Number, b) {Number r; Store(a+b, &r); return (r); } +Number Diff ARGS2(Number, a, Number, b){Number r; Store(a-b, &r); return (r); } +Number Mul ARGS2(Number, a, Number, b) {Number r; Store(a*b, &r); return (r); } +Number Div ARGS2(Number, a, Number, b) {Number r; Store(a/b, &r); return (r); } +Number Self ARGS1(Number, a) {Number r; Store(a, &r); return (r); } + +Procedure F_check ARGS((int precision, Long_double val1)); + +Procedure F_check(precision, val1) int precision; Long_double val1; { + /* You don't think I'm going to go to all the trouble of writing + a program that works out what all sorts of values are, only to + have printf go and print the wrong values out, do you? + No, you're right, so this function tries to see if printf + has written the right value, by reading it back again. + This introduces a new problem of course: suppose printf writes + the correct value, and scanf reads it back wrong... oh well. + But I'm adamant about this: the precision given is enough + to uniquely identify the printed number, therefore I insist + that sscanf read the number back identically. Harsh yes, but + sometimes you've got to be cruel to be kind. + */ + Number val, new, diff; + double rem; + int e; + char *rep; + char *f2; + +#ifdef NO_LONG_DOUBLE_IO + double new1; + /* On the Sun 3, sscanf clobbers 4 words, + which leads to a crash when this function tries to return. */ + f2= "%le"; /* Input */ + /* It is no use checking long doubles if we can't + read and write them. */ + if (sizeof (Number) > sizeof(double)) + return; +#else + Long_double new1; + if (sizeof(double) == sizeof(Long_double)) { + /* Assume they're the same, and use non-stdc format */ + /* This is for stdc compilers using non-stdc libraries */ + f2= "%le"; /* Input */ + } else { + /* It had better support Le then */ + f2= "%Le"; + } +#endif + val= val1; + rep= f_rep(precision, (Long_double) val); + if (setjmp(lab)==0) { + sscanf(rep, f2, &new1); + } else { + eek_a_bug("sscanf caused a trap"); + printf("%s scanning: %s format: %s%s\n\n", co, rep, f2, oc); + Unexpected(12); + return; + } + + if (setjmp(lab)==0) { /* See if new is usable */ + new= new1; + if (new != 0.0) { + diff= val/new - 1.0; + if (diff < 0.1) diff= 1.0; + /* That should be enough to generate a trap */ + } + } else { + eek_a_bug("sscanf returned an unusable number"); + printf("%s scanning: %s with format: %s%s\n\n", + co, rep, f2, oc); + Unexpected(13); + return; + } + + Unexpected(14); + if (new != val) { + eek_a_bug("Possibly bad output from printf above"); + if (!exponent((Long_double)val, &rem, &e)) { + printf("%s but value was an unusable number%s\n\n", + co, oc); + return; + } + printf("%s expected value around %.*fe%d, bit pattern:\n ", + co, precision, rem, e); + bitpattern((char *) &val, (unsigned)sizeof(val)); + printf ("%s\n", oc); + printf("%s sscanf gave %s, bit pattern:\n ", + co, f_rep(precision, (Long_double) new)); + bitpattern((char *) &new, (unsigned)sizeof(new)); + printf ("%s\n", oc); + if (setjmp(lab) == 0) { + diff= val-new; + printf("%s difference= %s%s\n\n", + co, f_rep(precision, (Long_double) diff), oc); + } /* else forget it */ + Unexpected(15); + } +} + +#ifdef VERIFY +Procedure Validate(prec, val, req, same) int prec, same; Long_double val, req; { + /* Check that the compiler has read a #define value correctly */ + Unexpected(16); + if (!same) { + printf("%s*** Verify failed for above #define!\n", co); + if (setjmp(lab) == 0) { /* for the case that req == nan */ + printf(" Compiler has %s for value%s\n", + f_rep(prec, req), oc); + } else { + printf(" Compiler has %s for value%s\n", + "an unusable number", oc); + } + if (setjmp(lab) == 0) { + F_check(prec, (Long_double) req); + } /*else forget it*/ + if (setjmp(lab) == 0) { + if (req > 0.0 && val > 0.0) { + printf("%s difference= %s%s\n", + co, f_rep(prec, val-req), oc); + } + } /*else forget it*/ + Unexpected(17); + printf("\n"); + bugs++; + } else if (val != req) { + if (stdc) eek_a_bug("constant has the wrong precision"); + else eek_a_bug("the cast didn't work"); + printf("\n"); + } +} +#endif /* VERIFY */ + +int FPROP(bits_per_byte) int bits_per_byte; { + /* Properties of floating types, using algorithms by Cody and Waite + from MA Malcolm, as modified by WM Gentleman and SB Marovich. + Further extended by S Pemberton. + + Returns the number of digits in the fraction. + */ + + Volatile int + i, f_radix, iexp, irnd, mrnd, f_rounds, f_mant_dig, + iz, k, inf, machep, f_max_exp, f_min_exp, mx, negeps, + mantbits, digs, f_dig, trap, + hidden, normal, f_min_10_exp, f_max_10_exp; + Volatile Number + a, b, base, basein, basem1, f_epsilon, epsneg, + eps, epsp1, etop, ebot, + f_max, newxmax, f_min, xminner, y, y1, z, z1, z2; + + Unexpected(18); + + Vprintf("%sPROPERTIES OF %s%s\n", co, THING, oc); + + /* Base and size of significand **************************************/ + /* First repeatedly double until adding 1 has no effect. */ + /* For instance, if base is 10, with 3 significant digits */ + /* it will try 1, 2, 4, 8, ... 512, 1024, and stop there, */ + /* since 1024 is only representable as 1020. */ + a=1.0; + if (setjmp(lab)==0) { /* inexact trap? */ + do { a=Sum(a, a); } + while (Diff(Diff(Sum(a, ONE), a), ONE) == ZERO); + } else { + fprintf(stderr, "*** Program got loss-of-precision trap!\n"); + /* And supporting those is just TOO much trouble! */ + farewell(bugs+1); + } + Unexpected(19); + /* Now double until you find a number that can be added to the */ + /* above number. For 1020 this is 8 or 16, depending whether the */ + /* result is rounded or truncated. */ + /* In either case the result is 1030. 1030-1020= the base, 10. */ + b=1.0; + do { b=Sum(b, b); } while ((base=Diff(Sum(a, b), a)) == ZERO); + f_radix=base; + Vprintf("%sBase = %d%s\n", co, f_radix, oc); + + /* Sanity check; if base<2, I can't guarantee the rest will work */ + if (f_radix < 2) { + eek_a_bug("Function return or parameter passing faulty? (This is a guess.)"); + printf("\n"); + return(0); + } + + if (PASS == 1) { /* only for FLT */ + flt_radix= f_radix; + if (F) i_define(D_FLT_RADIX, "", "FLT", "_RADIX", + (long) f_radix, 0L, (long) F_RADIX, ""); + } else if (f_radix != flt_radix) { + printf("\n%s*** WARNING: %s %s (%d) %s%s\n", + co, thing, "arithmetic has a different radix", + f_radix, "from float", oc); + bugs++; + } + + /* Now the number of digits precision */ + f_mant_dig=0; b=1.0; + do { f_mant_dig++; b=Mul(b, base); } + while (Diff(Diff(Sum(b, ONE), b), ONE) == ZERO); + f_dig=floor_log(10, (Long_double)(b/base)) + (base==10?1:0); + Vprintf("%sSignificant base digits = %d %s %d %s%s\n", + co, f_mant_dig, "(= at least", f_dig, "decimal digits)", oc); + if (F) i_define(D_MANT_DIG, thing, Fname, "_MANT_DIG", + (long) f_mant_dig, 0L, (long) F_MANT_DIG, ""); + if (F) i_define(D_DIG, thing, Fname, "_DIG", + (long) f_dig, 0L, (long) F_DIG, ""); + digs= ceil_log(10, (Long_double)b); /* the number of digits to printf */ + + /* Rounding *******************************************************/ + basem1=Diff(base, HALF); + if (Diff(Sum(a, basem1), a) != ZERO) { + if (f_radix == 2) basem1=0.375; + else basem1=1.0; + if (Diff(Sum(a, basem1), a) != ZERO) irnd=2; /* away from 0 */ + else irnd=1; /* to nearest */ + } else irnd=0; /* towards 0 */ + + basem1=Diff(base, HALF); + + if (Diff(Diff(-a, basem1), -a) != ZERO) { + if (f_radix == 2) basem1=0.375; + else basem1=1.0; + if (Diff(Diff(-a, basem1), -a) != ZERO) mrnd=2; /* away from 0*/ + else mrnd=1; /* to nearest */ + } else mrnd=0; /* towards 0 */ + + f_rounds= -1; /* Unknown rounding */ + if (irnd==0 && mrnd==0) f_rounds=0; /* zero = chops */ + if (irnd==1 && mrnd==1) f_rounds=1; /* nearest */ + if (irnd==2 && mrnd==0) f_rounds=2; /* +inf */ + if (irnd==0 && mrnd==2) f_rounds=3; /* -inf */ + + if (f_rounds != -1) { + Vprintf("%sArithmetic rounds towards ", co); + switch (f_rounds) { + case 0: Vprintf("zero (i.e. it chops)"); break; + case 1: Vprintf("nearest"); break; + case 2: Vprintf("+infinity"); break; + case 3: Vprintf("-infinity"); break; + default: Vprintf("???"); break; + } + Vprintf("%s\n", oc); + } else { /* Hmm, try to give some help here */ + Vprintf("%sArithmetic rounds oddly: %s\n", co, oc); + Vprintf("%s Negative numbers %s%s\n", + co, mrnd==0 ? "towards zero" : + mrnd==1 ? "to nearest" : + "away from zero", + oc); + Vprintf("%s Positive numbers %s%s\n", + co, irnd==0 ? "towards zero" : + irnd==1 ? "to nearest" : + "away from zero", + oc); + } + /* An extra goody */ + if (f_radix == 2 && f_rounds == 1) { + if (Diff(Sum(a, ONE), a) != ZERO) { + Vprintf("%s Tie breaking rounds up%s\n", co, oc); + } else if (Diff(Sum(a, THREE), a) == FOUR) { + Vprintf("%s Tie breaking rounds to even%s\n", co, oc); + } else { + Vprintf("%s Tie breaking rounds down%s\n", co, oc); + } + } + if (PASS == 1) { /* only for FLT */ + flt_rounds= f_rounds; + if (F) + i_define(D_FLT_ROUNDS, "", "FLT", "_ROUNDS", + (long) f_rounds, 1L, (long) F_ROUNDS, ""); + } else if (f_rounds != flt_rounds) { + printf("\n%s*** WARNING: %s %s (%d) %s%s\n", + co, thing, "arithmetic rounds differently", + f_rounds, "from float", oc); + bugs++; + } + + /* Various flavours of epsilon ************************************/ + negeps=f_mant_dig+f_mant_dig; + basein=1.0/base; + a=1.0; + for(i=1; i<=negeps; i++) a*=basein; + + b=a; + while (Diff(Diff(ONE, a), ONE) == ZERO) { + a*=base; + negeps--; + } + negeps= -negeps; + Vprintf("%sSmallest x such that 1.0-base**x != 1.0 = %d%s\n", + co, negeps, oc); + + etop = ONE; + ebot = ZERO; + eps = Sum(ebot, Div(Diff(etop, ebot), TWO)); + /* find the smallest epsneg (1-epsneg != 1) by binary search. + ebot and etop are the current bounds */ + while (eps != ebot && eps != etop) { + epsp1 = Diff(ONE, eps); + if (epsp1 < ONE) etop = eps; + else ebot = eps; + eps = Sum(ebot, Div(Diff(etop, ebot), TWO)); + } + eps= etop; + /* Sanity check */ + if (Diff(ONE, etop) >= ONE || Diff(ONE, ebot) != ONE) { + eek_a_bug("internal error calculating epsneg"); + } + Vprintf("%sSmallest x such that 1.0-x != 1.0 = %s%s\n", + co, f_rep(digs, (Long_double) eps), oc); + if (V) F_check(digs, (Long_double) eps); + + epsneg=a; + if ((f_radix!=2) && irnd) { + /* a=(a*(1.0+a))/(1.0+1.0); => */ + a=Div(Mul(a, Sum(ONE, a)), Sum(ONE, ONE)); + /* if ((1.0-a)-1.0 != 0.0) epsneg=a; => */ + if (Diff(Diff(ONE, a), ONE) != ZERO) epsneg=a; + } + /* epsneg is used later */ + Unexpected(20); + + machep= -f_mant_dig-f_mant_dig; + a=b; + while (Diff(Sum(ONE, a), ONE) == ZERO) { a*=base; machep++; } + Vprintf("%sSmallest x such that 1.0+base**x != 1.0 = %d%s\n", + co, machep, oc); + + etop = ONE; + ebot = ZERO; + eps = Sum(ebot, Div(Diff(etop, ebot), TWO)); + /* find the smallest eps (1+eps != 1) by binary search. + ebot and etop are the current bounds */ + while (eps != ebot && eps != etop) { + epsp1 = Sum(ONE, eps); + if (epsp1 > ONE) etop = eps; + else ebot = eps; + eps = Sum(ebot, Div(Diff(etop, ebot), TWO)); + } + /* Sanity check */ + if (Sum(ONE, etop) <= ONE || Sum(ONE, ebot) != ONE) { + eek_a_bug("internal error calculating eps"); + } + f_epsilon=etop; + + Vprintf("%sSmallest x such that 1.0+x != 1.0 = %s%s\n", + co, f_rep(digs, (Long_double) f_epsilon), oc); + + f_epsilon= Diff(Sum(ONE, f_epsilon), ONE); /* New C standard defn */ + Vprintf("%s(Above number + 1.0) - 1.0 = %s%s\n", + co, f_rep(digs, (Long_double) (f_epsilon)), oc); + + /* Possible loss of precision warnings here from non-stdc compilers */ + if (F) f_define(D_EPSILON, thing, + Fname, "_EPSILON", digs, (Long_double) f_epsilon, MARK); + if (V || F) F_check(digs, (Long_double) f_epsilon); + Unexpected(21); + if (F) Validate(digs, (Long_double) f_epsilon, (Long_double) F_EPSILON, + f_epsilon == Self(F_EPSILON)); + Unexpected(22); + + /* Extra chop info *************************************************/ + if (f_rounds == 0) { + if (Diff(Mul(Sum(ONE,f_epsilon),ONE),ONE) != ZERO) { + Vprintf("%sAlthough arithmetic chops, it uses guard digits%s\n", co, oc); + } + } + + /* Size of and minimum normalised exponent ************************/ + y=0; i=0; k=1; z=basein; z1=(1.0+f_epsilon)/base; + + /* Coarse search for the largest power of two */ + if (setjmp(lab)==0) { /* for underflow trap */ /* Yields i, k, y, y1 */ + do { + y=z; y1=z1; + z=Mul(y,y); z1=Mul(z1, y); + a=Mul(z,ONE); + z2=Div(z1,y); + if (z2 != y1) break; + if ((Sum(a,a) == ZERO) || (fabs(z) >= y)) break; + i++; + k+=k; + } while(1); + } else { + Vprintf("%s%s underflow generates a trap%s\n", co, Thing, oc); + } + Unexpected(23); + + if (f_radix != 10) { + iexp=i+1; /* for the sign */ + mx=k+k; + } else { + iexp=2; + iz=f_radix; + while (k >= iz) { iz*=f_radix; iexp++; } + mx=iz+iz-1; + } + + /* Fine tune starting with y and y1 */ + if (setjmp(lab)==0) { /* for underflow trap */ /* Yields k, f_min */ + do { + f_min=y; z1=y1; + y=Div(y,base); y1=Div(y1,base); + a=Mul(y,ONE); + z2=Mul(y1,base); + if (z2 != z1) break; + if ((Sum(a,a) == ZERO) || (fabs(y) >= f_min)) break; + k++; + } while (1); + } + Unexpected(24); + + f_min_exp=(-k)+1; + + if ((mx <= k+k-3) && (f_radix != 10)) { mx+=mx; iexp+=1; } + Vprintf("%sNumber of bits used for exponent = %d%s\n", co, iexp, oc); + Vprintf("%sMinimum normalised exponent = %d%s\n", co, f_min_exp-1, oc); + if (F) + i_define(D_MIN_EXP, thing, Fname, "_MIN_EXP", + (long) f_min_exp, (long) maxint, (long) F_MIN_EXP, ""); + + if (setjmp(lab)==0) { + Vprintf("%sMinimum normalised positive number = %s%s\n", + co, f_rep(digs, (Long_double) f_min), oc); + } else { + eek_a_bug("printf can't print the smallest normalised number"); + printf("\n"); + } + Unexpected(25); + /* Possible loss of precision warnings here from non-stdc compilers */ + if (setjmp(lab) == 0) { + if (F) f_define(D_MIN, thing, + Fname, "_MIN", digs, (Long_double) f_min, MARK); + if (V || F) F_check(digs, (Long_double) f_min); + } else { + eek_a_bug("xxx_MIN caused a trap"); + printf("\n"); + } + + if (setjmp(lab) == 0) { + if (F) Validate(digs, (Long_double) f_min, (Long_double) F_MIN, + f_min == Self(F_MIN)); + } else { + printf("%s*** Verify failed for above #define!\n %s %s\n\n", + co, "Compiler has an unusable number for value", oc); + bugs++; + } + Unexpected(26); + + a=1.0; f_min_10_exp=0; + while (a > f_min*10.0) { a/=10.0; f_min_10_exp--; } + if (F) i_define(D_MIN_10_EXP, thing, Fname, "_MIN_10_EXP", + (long) f_min_10_exp, (long) maxint, + (long) F_MIN_10_EXP, ""); + + /* Minimum exponent ************************************************/ + if (setjmp(lab)==0) { /* for underflow trap */ /* Yields xminner */ + do { + xminner=y; + y=Div(y,base); + a=Mul(y,ONE); + if ((Sum(a,a) == ZERO) || (fabs(y) >= xminner)) break; + } while (1); + } + Unexpected(27); + + if (xminner != 0.0 && xminner != f_min) { + normal= 0; + Vprintf("%sThe smallest numbers are not kept normalised%s\n", + co, oc); + if (setjmp(lab)==0) { + Vprintf("%sSmallest unnormalised positive number = %s%s\n", + co, f_rep(digs, (Long_double) xminner), oc); + if (V) F_check(digs, (Long_double) xminner); + } else { + eek_a_bug("printf can't print the smallest unnormalised number."); + printf("\n"); + } + Unexpected(28); + } else { + normal= 1; + Vprintf("%sThe smallest numbers are normalised%s\n", co, oc); + } + + /* Maximum exponent ************************************************/ + f_max_exp=2; f_max=1.0; newxmax=base+1.0; + inf=0; trap=0; + while (f_max