From 8d08fdba598cf87c3794df53beae1026345ebb02 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Thu, 24 Feb 1994 01:02:37 +0000 Subject: [PATCH] Initial revision From-SVN: r6613 --- gcc/cp/Makefile.in | 318 ++ gcc/cp/call.c | 4205 +++++++++++++++ gcc/cp/class.c | 5048 ++++++++++++++++++ gcc/cp/class.h | 161 + gcc/cp/cp-tree.def | 92 + gcc/cp/cp-tree.h | 2228 ++++++++ gcc/cp/cvt.c | 1997 +++++++ gcc/cp/decl.c | 12087 +++++++++++++++++++++++++++++++++++++++++++ gcc/cp/decl.h | 59 + gcc/cp/decl2.c | 2823 ++++++++++ gcc/cp/errfn.c | 217 + gcc/cp/error.c | 1339 +++++ gcc/cp/except.c | 1224 +++++ gcc/cp/expr.c | 268 + gcc/cp/gxx.gperf | 91 + gcc/cp/gxxint.texi | 1030 ++++ gcc/cp/hash.h | 207 + gcc/cp/init.c | 4181 +++++++++++++++ gcc/cp/input.c | 184 + gcc/cp/lex.c | 4783 +++++++++++++++++ gcc/cp/lex.h | 124 + gcc/cp/method.c | 1651 ++++++ gcc/cp/parse.y | 4099 +++++++++++++++ gcc/cp/pt.c | 2311 +++++++++ gcc/cp/ptree.c | 163 + gcc/cp/search.c | 3308 ++++++++++++ gcc/cp/sig.c | 998 ++++ gcc/cp/spew.c | 1141 ++++ gcc/cp/tree.c | 1797 +++++++ gcc/cp/typeck.c | 6926 +++++++++++++++++++++++++ gcc/cp/typeck2.c | 1827 +++++++ gcc/cp/xref.c | 827 +++ 32 files changed, 67714 insertions(+) create mode 100644 gcc/cp/Makefile.in create mode 100644 gcc/cp/call.c create mode 100644 gcc/cp/class.c create mode 100644 gcc/cp/class.h create mode 100644 gcc/cp/cp-tree.def create mode 100644 gcc/cp/cp-tree.h create mode 100644 gcc/cp/cvt.c create mode 100644 gcc/cp/decl.c create mode 100644 gcc/cp/decl.h create mode 100644 gcc/cp/decl2.c create mode 100644 gcc/cp/errfn.c create mode 100644 gcc/cp/error.c create mode 100644 gcc/cp/except.c create mode 100644 gcc/cp/expr.c create mode 100644 gcc/cp/gxx.gperf create mode 100644 gcc/cp/gxxint.texi create mode 100644 gcc/cp/hash.h create mode 100644 gcc/cp/init.c create mode 100644 gcc/cp/input.c create mode 100644 gcc/cp/lex.c create mode 100644 gcc/cp/lex.h create mode 100644 gcc/cp/method.c create mode 100644 gcc/cp/parse.y create mode 100644 gcc/cp/pt.c create mode 100644 gcc/cp/ptree.c create mode 100644 gcc/cp/search.c create mode 100644 gcc/cp/sig.c create mode 100644 gcc/cp/spew.c create mode 100644 gcc/cp/tree.c create mode 100644 gcc/cp/typeck.c create mode 100644 gcc/cp/typeck2.c create mode 100644 gcc/cp/xref.c diff --git a/gcc/cp/Makefile.in b/gcc/cp/Makefile.in new file mode 100644 index 00000000000..686b5b54635 --- /dev/null +++ b/gcc/cp/Makefile.in @@ -0,0 +1,318 @@ +# Makefile for GNU C++ compiler. +# Copyright (C) 1987, 88, 90, 91, 92, 93, 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, 675 Mass Ave, Cambridge, MA 02139, USA. + +# The targets for external use include: +# all, doc, TAGS, mostlyclean, clean, distclean, realclean, + +# 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. + +INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config + +# 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 +# CYGNUS LOCAL: we use byacc instead of bison, DO NOT SEND TO RMS +BISON = `if [ -f ../../byacc/byacc ] ; then echo ../../byacc/byacc ; else echo byacc ; fi` +BISONFLAGS = +LEX = `if [ -f ../../flex/flex ] ; then echo ../../flex/flex ; else echo flex ; fi` +LEXFLAGS= +AR = ar +OLDAR_FLAGS = qc +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 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. + +# CYGNUS LOCAL: we don't use cross-make. Instead we use the tools +# from the build tree, if they are available. +# program_transform_name and objdir are set by configure.in. +program_transform_name = +objdir = . + +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 = . + +# Change this to a null string if obstacks are installed in the +# system library. +OBSTACK=obstack.o + +# Directory to link to, when using the target `maketest'. +DIR = ../gcc + +# 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 +####site overrides + +# Now figure out from those variables how to compile and link. + +all.indirect: Makefile ../cc1plus + +# IN_GCC tells obstack.h to use gstddef.h. +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) + +SUBDIR_OBSTACK = `if [ x$(OBSTACK) != x ]; then echo ../$(OBSTACK); else true; fi` +SUBDIR_USE_ALLOCA = `if [ x$(USE_ALLOCA) != x ]; then echo ../$(USE_ALLOCA); else true; fi` +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) + +# 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 + +# Files specific to the C interpreter bytecode compiler(s). +BC_OBJS = ../bc-emit.o ../bc-optab.o + +# 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 ../aux-output.o ../getpwd.o ../convert.o \ + ../c-common.o + +compiler: ../cc1plus +../cc1plus: $(P) $(CXX_OBJS) $(OBJS) $(BC_OBJS) $(LIBDEPS) + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o ../cc1plus \ + $(CXX_OBJS) $(OBJS) $(BC_OBJS) $(LIBS) + + +Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure + cd ..; $(SHELL) config.status + +native: config.status ../cc1plus + +# 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 + + +# Compiling object files from source files. + +# Note that dependencies on obstack.h are not written +# because that file is not part of GCC. +# Dependencies on gvarargs.h are not written +# because all that file does, when not compiling with GCC, +# is include the system varargs.h. + +# C++ language specific files. + +TREE_H = ../tree.h ../real.h ../tree.def ../machmode.h ../machmode.def +CXX_TREE_H = $(TREE_H) cp-tree.h tree.def + +parse.o : $(srcdir)/parse.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h lex.h + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(BIG_SWITCHFLAG) \ + `echo $(srcdir)/parse.c | sed 's,^\./,,'` + +$(srcdir)/parse.c $(srcdir)/parse.h : $(srcdir)/parse.y + @echo expect 28 shift/reduce conflicts, 14 reduce/reduce conflicts. + cd $(srcdir); $(BISON) $(BISONFLAGS) -d -o parse.c parse.y + cd $(srcdir); grep '^#define[ ]*YYEMPTY' parse.c >>parse.h + +# 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 ../flags.h lex.h +lex.o : lex.c $(CONFIG_H) $(CXX_TREE_H) \ + parse.h input.c ../flags.h hash.h lex.h +decl.o : decl.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h \ + lex.h decl.h ../stack.h +decl2.o : decl2.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h \ + lex.h decl.h +typeck2.o : typeck2.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h +typeck.o : typeck.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h $(RTL_H) +class.o : class.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h +call.o : call.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h class.h +init.o : init.c $(CONFIG_H) $(CXX_TREE_H) ../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) ../stack.h ../flags.h +tree.o : tree.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h +ptree.o : ptree.c $(CONFIG_H) $(CXX_TREE_H) +gc.o : gc.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h +except.o : except.c $(CONFIG_H) $(CXX_TREE_H) ../flags.h $(RTL_H) +expr.o : expr.c $(CONFIG_H) $(CXX_TREE_H) $(RTL_H) ../flags.h \ + ../expr.h ../insn-codes.h +edsel.o : edsel.c $(CONFIG_H) $(CXX_TREE_H) ../stack.h ../flags.h +xref.o : xref.c $(CONFIG_H) $(CXX_TREE_H) ../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) ../flags.h + +doc: info +info: + +dvi: + + +# Deletion of files made during compilation. +# There are four levels of this: +# `mostlyclean', `clean', `distclean' and `realclean'. +# `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. +# `realclean' also deletes everything that could be regenerated automatically. + + +mostlyclean: +# Delete the stamp files. + -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 +# Delete unwanted output files from TeX. + -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 + -rm -f *.o ../cc1plus + +# Delete all files made by compilation +# that don't exist in the distribution. +clean: mostlyclean + -rm -f *.dvi + +# Delete all files that users would normally create +# while building and installing GCC. +distclean: clean + -rm -f config.status Makefile *.oaux + -rm -f parse.output + +# Delete anything likely to be found in the source directory +# that shouldn't be in the distribution. +extraclean: distclean + -rm -rf =* ./"#"* *~* + -rm -f patch* *.orig *.rej + -rm -f *.dvi *.oaux *.d *.[zZ] *.gz + -rm -f *.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. +realclean: distclean + -rm -f TAGS + -rm -f parse.c parse.h parse.output + +# These exist for maintenance purposes. + +# This target creates the files that can be rebuilt, but go in the +# distribution anyway. +distdir: parse.c hash.h + +# 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: clean realclean TAGS + +force: diff --git a/gcc/cp/call.c b/gcc/cp/call.c new file mode 100644 index 00000000000..02fc964e3ae --- /dev/null +++ b/gcc/cp/call.c @@ -0,0 +1,4205 @@ +/* Functions related to invoking methods and overloaded functions. + Copyright (C) 1987, 1992, 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "class.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 cp-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 int convert_harshness_old (); +static struct harshness_code convert_harshness_ansi (); + +/* OLD METHOD */ +/* Note the old method also uses USER_HARSHNESS, BASE_DERIVED_HARSHNESS, + CONST_HARSHNESS. */ +#define EVIL 1 +#define TRIVIAL 0 +#define EVIL_HARSHNESS(ARG) ((ARG) & 1) +#define ELLIPSIS_HARSHNESS(ARG) ((ARG) & 2) +#define CONTRAVARIANT_HARSHNESS(ARG) ((ARG) & 8) +#define INT_TO_BD_HARSHNESS(ARG) (((ARG) << 5) | 16) +#define INT_FROM_BD_HARSHNESS(ARG) ((ARG) >> 5) +#define INT_TO_EASY_HARSHNESS(ARG) ((ARG) << 5) +#define INT_FROM_EASY_HARSHNESS(ARG) ((ARG) >> 5) +#define ONLY_EASY_HARSHNESS(ARG) (((ARG) & 31) == 0) + + +/* NEW METHOD */ +#define EVIL_RETURN(ARG) ((ARG).code = EVIL_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)) + +#define USER_HARSHNESS(ARG) ((ARG) & 4) +#define BASE_DERIVED_HARSHNESS(ARG) ((ARG) & 16) +#define CONST_HARSHNESS(ARG) ((ARG) & 2048) + +/* Ordering function for overload resolution. Compare two candidates + by gross quality. */ +int +rank_for_overload_ansi (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->v.ansi_harshness[0].code & CONST_CODE) ^ (x->v.ansi_harshness[0].code & CONST_CODE)) + return y->v.ansi_harshness[0].code - x->v.ansi_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; +} + +int +rank_for_overload_old (x, y) + struct candidate *x, *y; +{ + if (y->evil - x->evil) + return y->evil - x->evil; + if (CONST_HARSHNESS (y->v.old_harshness[0]) ^ CONST_HARSHNESS (x->v.old_harshness[0])) + return y->v.old_harshness[0] - x->v.old_harshness[0]; + if (y->ellipsis - x->ellipsis) + return y->ellipsis - x->ellipsis; + if (y->user - x->user) + return y->user - x->user; + if (y->b_or_d - x->b_or_d) + return y->b_or_d - x->b_or_d; + return y->easy - x->easy; +} + +int +rank_for_overload (x, y) + struct candidate *x, *y; +{ + if (flag_ansi_overloading) + return rank_for_overload_ansi (x, y); + else + return rank_for_overload_old (x, y); +} + +/* 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->v.ansi_harshness[i].code - x->v.ansi_harshness[i].code) + return y->v.ansi_harshness[i].code - x->v.ansi_harshness[i].code; + if ((y->v.ansi_harshness[i].code & STD_CODE) + && (y->v.ansi_harshness[i].distance - x->v.ansi_harshness[i].distance)) + return y->v.ansi_harshness[i].distance - x->v.ansi_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->v.ansi_harshness[0].code & PROMO_CODE + && (y->v.ansi_harshness[i].int_penalty ^ x->v.ansi_harshness[i].int_penalty)) + return y->v.ansi_harshness[i].int_penalty - x->v.ansi_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_ansi (type, parmtype, parm) + register tree type, parmtype; + tree parm; +{ + struct harshness_code h; + register enum tree_code codel; + register enum tree_code coder; + + h.code = 0; + h.distance = 0; + h.int_penalty = 0; + +#ifdef GATHER_STATISTICS + n_convert_harshness++; +#endif + + 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 == 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); + + /* We allow the default conversion between function type + and pointer-to-function type for free. */ + if (type == parmtype) + return ZERO_RETURN (h); + + /* Compare return types. */ + p1 = TREE_TYPE (type); + p2 = TREE_TYPE (parmtype); + h2 = convert_harshness_ansi (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)) + { + static int explained = 0; + if (h2.distance < 0) + message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p2, p1); + else + message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p1, p2); + + if (! explained++) + sorry ("(because pointer values change during conversion)"); + 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_ansi (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) + { + /* Get to the OFFSET_TYPE that this might be. */ + type = TREE_TYPE (type); + + if (coder != TREE_CODE (type)) + return EVIL_RETURN (h); + + if (TYPE_OFFSET_BASETYPE (type) == TYPE_OFFSET_BASETYPE (parmtype)) + h.code = 0; + else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (type), + TYPE_OFFSET_BASETYPE (parmtype))) + { + h.code = STD_CODE; + h.distance = 1; + } + else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (parmtype), + TYPE_OFFSET_BASETYPE (type))) + { + h.code = STD_CODE; + h.distance = -1; + } + else + return EVIL_RETURN (h); + /* 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 == ENUMERAL_TYPE || codel == INTEGER_TYPE) + { + /* 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 (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE) + { + if ((TREE_UNSIGNED (type) ^ TREE_UNSIGNED (parmtype)) + || codel != coder + || TYPE_MODE (type) != TYPE_MODE (parmtype)) + { + /* Make sure a value-preserving condition [from a smaller type to + a larger type] is preferred to a possibly value-destroying + standard conversion [from a larger type to a smaller type]. */ + if (TYPE_PRECISION (type) >= TYPE_PRECISION (parmtype)) + { + h.code = PROMO_CODE; + /* 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; + } + else + h.code = STD_CODE; + } + + /* If the three above conditions didn't trigger, we have found two + very similar types. On systems where they're the same size, we + can end up here with TYPE as `long' and PARMTYPE as `int'. Make + sure we realize that, even though they're the same mode, we will + have to do some sort of integral promotion on the type, since + they're not the same. */ + if (! comptypes (type, parmtype, 1) && h.code == 0) + { + /* This call to common_type will return the best type for the + combination. If it matches TYPE, that means we'll be converting + from a so-called smaller type (in PARMTYPE) to the larger in TYPE, + thus an integral promotion. Otherwise, it must be going from a + larger type in PARMTYPE to a smaller expected type in TYPE, so we + make it a standard conversion instead. */ + if (common_type (type, parmtype) == type) + h.code = PROMO_CODE; + 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) + { + /* Shun converting among float, double, and long double if a + choice exists. */ + h.code = PROMO_CODE; + return h; + } + else if (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE) + { + h.code = STD_CODE; + h.distance = 0; + return h; + } + } + + /* Convert arrays which have not previously been converted. */ + if (codel == ARRAY_TYPE) + codel = POINTER_TYPE; + if (coder == ARRAY_TYPE) + coder = POINTER_TYPE; + + /* 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 *. void * converts to anything. + Since these 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) + { + if (TREE_UNSIGNED (ttl) != TREE_UNSIGNED (ttr)) + { + ttl = unsigned_type (ttl); + ttr = unsigned_type (ttr); + penalty = 10; + } + if (! comp_target_types (ttl, ttr, 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)))) + 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; + 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++: one of the types must be a reference type. */ + { + tree ttl, ttr; + register tree intype = TYPE_MAIN_VARIANT (parmtype); + register enum tree_code form = TREE_CODE (intype); + int penalty; + + if (codel == REFERENCE_TYPE || coder == REFERENCE_TYPE) + { + ttl = TYPE_MAIN_VARIANT (type); + + if (codel == REFERENCE_TYPE) + { + ttl = TREE_TYPE (ttl); + + /* When passing a non-const argument into a const reference, + dig it a little, so a non-const reference is preferred over + this one. (mrs) */ + if (parm && TREE_READONLY (ttl) && ! TREE_READONLY (parm)) + penalty = 2; + else + penalty = 0; + + ttl = TYPE_MAIN_VARIANT (ttl); + + if (form == OFFSET_TYPE) + { + intype = TREE_TYPE (intype); + form = TREE_CODE (intype); + } + + if (form == REFERENCE_TYPE) + { + intype = TYPE_MAIN_VARIANT (TREE_TYPE (intype)); + + if (ttl == intype) + return ZERO_RETURN (h); + penalty = 2; + } + else + { + /* Can reference be built up? */ + if (ttl == intype && penalty == 0) { + /* Because the READONLY and VIRTUAL bits are not always in + the type, this extra check is necessary. The problem + should be fixed someplace else, and this extra code + removed. + + Also, if type if a reference, the readonly bits could + either be in the outer type (with reference) or on the + inner type (the thing being referenced). (mrs) */ + if (parm + && ((TREE_READONLY (parm) + && ! (TYPE_READONLY (type) + || (TREE_CODE (type) == REFERENCE_TYPE + && TYPE_READONLY (TREE_TYPE (type))))) + || (TREE_SIDE_EFFECTS (parm) + && ! (TYPE_VOLATILE (type) + || (TREE_CODE (type) == REFERENCE_TYPE + && TYPE_VOLATILE (TREE_TYPE (type))))))) + penalty = 2; + else + return ZERO_RETURN (h); + } + else + penalty = 2; + } + } + else if (form == REFERENCE_TYPE) + { + if (parm) + { + tree tmp = convert_from_reference (parm); + intype = TYPE_MAIN_VARIANT (TREE_TYPE (tmp)); + } + else + { + intype = parmtype; + do + intype = TREE_TYPE (intype); + while (TREE_CODE (intype) == REFERENCE_TYPE); + intype = TYPE_MAIN_VARIANT (intype); + } + + if (ttl == intype) + return ZERO_RETURN (h); + else + penalty = 2; + } + + if (TREE_UNSIGNED (ttl) ^ TREE_UNSIGNED (intype)) + { + ttl = unsigned_type (ttl); + intype = unsigned_type (intype); + penalty += 2; + } + + ttr = intype; + + /* If the initializer is not an lvalue, then it does not + matter if we make life easier for the programmer + by creating a temporary variable with which to + hold the result. */ + if (parm && (coder == INTEGER_TYPE + || coder == ENUMERAL_TYPE + || coder == REAL_TYPE) + && ! lvalue_p (parm)) + { + h = convert_harshness_ansi (ttl, ttr, NULL_TREE); + if (penalty > 2 || h.code != 0) + h.code |= STD_CODE; + else + h.code |= TRIVIAL_CODE; + h.distance = 0; + return h; + } + + if (ttl == ttr) + { + if (penalty > 2) + { + h.code = STD_CODE; + h.distance = 0; + } + else + { + h.code = TRIVIAL_CODE; + /* We set this here so that build_overload_call_real will be + able to see the penalty we found, rather than just looking + at a TRIVIAL_CODE with no other information. */ + h.int_penalty = penalty; + } + return h; + } + + /* Pointers to voids always convert for pointers. But + make them less natural than more specific matches. */ + if (TREE_CODE (ttl) == POINTER_TYPE && TREE_CODE (ttr) == POINTER_TYPE) + { + if (TREE_TYPE (ttl) == void_type_node + || TREE_TYPE (ttr) == void_type_node) + { + h.code = STD_CODE; + h.distance = 0; + return h; + } + } + + if (parm && codel != REFERENCE_TYPE) + { + h = convert_harshness_ansi (ttl, ttr, NULL_TREE); + if (penalty) + h.code |= STD_CODE; + h.distance = 0; + return h; + } + + /* Here it does matter. If this conversion is from derived to base, + allow it. Otherwise, types must be compatible in the strong sense. */ + 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; + } + /* Say that this conversion is relatively painless. + If it turns out that there is a user-defined X(X&) + constructor, then that will be invoked, but that's + preferable to dealing with other user-defined conversions + that may produce surprising results. */ + else + h.distance = b_or_d; + h.code = STD_CODE; + return h; + } + + if (comp_target_types (ttl, intype, 1)) + { + if (penalty) + h.code = STD_CODE; + h.distance = 0; + 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); +} + +/* 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 int +convert_harshness_old (type, parmtype, parm) + register tree type, parmtype; + tree parm; +{ + register enum tree_code codel; + register enum tree_code coder; + +#ifdef GATHER_STATISTICS + n_convert_harshness++; +#endif + + 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 TRIVIAL; + + if (coder == ERROR_MARK) + return EVIL; + + if (codel == POINTER_TYPE && fntype_p (parmtype)) + { + tree p1, p2; + int harshness, new_harshness; + + /* 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; + + harshness = 0; + + /* We allow the default conversion between function type + and pointer-to-function type for free. */ + if (type == parmtype) + return TRIVIAL; + + /* Compare return types. */ + p1 = TREE_TYPE (type); + p2 = TREE_TYPE (parmtype); + new_harshness = convert_harshness_old (p1, p2, NULL_TREE); + if (EVIL_HARSHNESS (new_harshness)) + return EVIL; + + if (BASE_DERIVED_HARSHNESS (new_harshness)) + { + tree binfo; + + /* This only works for pointers. */ + if (TREE_CODE (p1) != POINTER_TYPE + && TREE_CODE (p1) != REFERENCE_TYPE) + return EVIL; + + 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; + if (CONTRAVARIANT_HARSHNESS (new_harshness)) + binfo = get_binfo (p2, p1, 0); + else + binfo = get_binfo (p1, p2, 0); + + if (! BINFO_OFFSET_ZEROP (binfo)) + { + static int explained = 0; + if (CONTRAVARIANT_HARSHNESS (new_harshness)) + message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p2, p1); + else + message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p1, p2); + + if (! explained++) + sorry ("(because pointer values change during conversion)"); + return EVIL; + } + } + + harshness |= new_harshness; + + 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) + { + new_harshness = convert_harshness_old (TREE_VALUE (p1), + TREE_VALUE (p2), NULL_TREE); + if (EVIL_HARSHNESS (new_harshness)) + return EVIL; + + if (BASE_DERIVED_HARSHNESS (new_harshness)) + { + /* This only works for pointers and references. */ + if (TREE_CODE (TREE_VALUE (p1)) != POINTER_TYPE + && TREE_CODE (TREE_VALUE (p1)) != REFERENCE_TYPE) + return EVIL; + new_harshness ^= CONTRAVARIANT_HARSHNESS (new_harshness); + harshness |= new_harshness; + } + /* This trick allows use to accumulate easy type + conversions without messing up the bits that encode + info about more involved things. */ + else if (ONLY_EASY_HARSHNESS (new_harshness)) + harshness += new_harshness; + else + harshness |= new_harshness; + p1 = TREE_CHAIN (p1); + p2 = TREE_CHAIN (p2); + } + if (p1 == p2) + return harshness; + if (p2) + return p1 ? EVIL : (harshness | ELLIPSIS_HARSHNESS (-1)); + if (p1) + return harshness | (TREE_PURPOSE (p1) == NULL_TREE); + } + else if (codel == POINTER_TYPE && coder == OFFSET_TYPE) + { + /* XXX: Note this is set a few times, but it's never actually + used! (bpk) */ + int harshness; + + /* Get to the OFFSET_TYPE that this might be. */ + type = TREE_TYPE (type); + + if (coder != TREE_CODE (type)) + return EVIL; + + harshness = 0; + + if (TYPE_OFFSET_BASETYPE (type) == TYPE_OFFSET_BASETYPE (parmtype)) + harshness = 0; + else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (type), + TYPE_OFFSET_BASETYPE (parmtype))) + harshness = INT_TO_BD_HARSHNESS (1); + else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (parmtype), + TYPE_OFFSET_BASETYPE (type))) + harshness = CONTRAVARIANT_HARSHNESS (-1); + else + return EVIL; + /* 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 EVIL; + } + + if (coder == VOID_TYPE) + return EVIL; + + if (codel == ENUMERAL_TYPE || codel == INTEGER_TYPE) + { + /* 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; + } + + /* else enums and ints (almost) freely interconvert. */ + + if (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE) + { + int easy = TREE_UNSIGNED (type) ^ TREE_UNSIGNED (parmtype); + if (codel != coder) + easy += 1; + if (TYPE_MODE (type) != TYPE_MODE (parmtype)) + easy += 2; + return INT_TO_EASY_HARSHNESS (easy); + } + else if (coder == REAL_TYPE) + return INT_TO_EASY_HARSHNESS (4); + } + + if (codel == REAL_TYPE) + if (coder == REAL_TYPE) + /* Shun converting between float and double if a choice exists. */ + { + if (TYPE_MODE (type) != TYPE_MODE (parmtype)) + return INT_TO_EASY_HARSHNESS (2); + return TRIVIAL; + } + else if (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE) + return INT_TO_EASY_HARSHNESS (4); + + /* convert arrays which have not previously been converted. */ + if (codel == ARRAY_TYPE) + codel = POINTER_TYPE; + if (coder == ARRAY_TYPE) + coder = POINTER_TYPE; + + /* 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 *. void * converts to anything. + Since these 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 unsinged pointer types. */ + + if ((TREE_CODE (ttl) == METHOD_TYPE + || TREE_CODE (ttl) == FUNCTION_TYPE) + && TREE_CODE (ttl) == TREE_CODE (ttr)) + { + if (comptypes (ttl, ttr, -1)) + return INT_TO_EASY_HARSHNESS (penalty); + return EVIL; + } + + 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)))) + return EVIL; + + if (penalty == 10) + return INT_TO_EASY_HARSHNESS (10); + if (ttr == ttl) + return INT_TO_BD_HARSHNESS (0); + + 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 CONTRAVARIANT_HARSHNESS (-1); + } + return INT_TO_BD_HARSHNESS (b_or_d); + } + /* 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)) + return INT_TO_BD_HARSHNESS (CLASSTYPE_MAX_DEPTH (ttr)+1); + return INT_TO_EASY_HARSHNESS (penalty); + } + + 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)) + return INT_TO_EASY_HARSHNESS (4); + } + + /* 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 0; + + /* C++: one of the types must be a reference type. */ + { + tree ttl, ttr; + register tree intype = TYPE_MAIN_VARIANT (parmtype); + register enum tree_code form = TREE_CODE (intype); + int penalty; + + if (codel == REFERENCE_TYPE || coder == REFERENCE_TYPE) + { + ttl = TYPE_MAIN_VARIANT (type); + + if (codel == REFERENCE_TYPE) + { + ttl = TREE_TYPE (ttl); + + /* When passing a non-const argument into a const reference, + dig it a little, so a non-const reference is preferred over + this one. (mrs) */ + if (parm && TREE_READONLY (ttl) && ! TREE_READONLY (parm)) + penalty = 2; + else + penalty = 0; + + ttl = TYPE_MAIN_VARIANT (ttl); + + if (form == OFFSET_TYPE) + { + intype = TREE_TYPE (intype); + form = TREE_CODE (intype); + } + + if (form == REFERENCE_TYPE) + { + intype = TYPE_MAIN_VARIANT (TREE_TYPE (intype)); + + if (ttl == intype) + return TRIVIAL; + penalty = 2; + } + else + { + /* Can reference be built up? */ + if (ttl == intype && penalty == 0) { + /* Because the READONLY bits and VIRTUAL bits are not always + in the type, this extra check is necessary. The problem + should be fixed someplace else, and this extra code + removed. + + Also, if type if a reference, the readonly bits could + either be in the outer type (with reference) or on the + inner type (the thing being referenced). (mrs) */ + if (parm + && ((TREE_READONLY (parm) + && ! (TYPE_READONLY (type) + || (TREE_CODE (type) == REFERENCE_TYPE + && TYPE_READONLY (TREE_TYPE (type))))) + || (TREE_SIDE_EFFECTS (parm) + && ! (TYPE_VOLATILE (type) + || (TREE_CODE (type) == REFERENCE_TYPE + && TYPE_VOLATILE (TREE_TYPE (type))))))) + penalty = 2; + else + return TRIVIAL; + } + else + penalty = 2; + } + } + else if (form == REFERENCE_TYPE) + { + if (parm) + { + tree tmp = convert_from_reference (parm); + intype = TYPE_MAIN_VARIANT (TREE_TYPE (tmp)); + } + else + { + intype = parmtype; + do + { + intype = TREE_TYPE (intype); + } + while (TREE_CODE (intype) == REFERENCE_TYPE); + intype = TYPE_MAIN_VARIANT (intype); + } + + if (ttl == intype) + return TRIVIAL; + else + penalty = 2; + } + + if (TREE_UNSIGNED (ttl) ^ TREE_UNSIGNED (intype)) + { + ttl = unsigned_type (ttl); + intype = unsigned_type (intype); + penalty += 2; + } + + ttr = intype; + + /* If the initializer is not an lvalue, then it does not + matter if we make life easier for the programmer + by creating a temporary variable with which to + hold the result. */ + if (parm && (coder == INTEGER_TYPE + || coder == ENUMERAL_TYPE + || coder == REAL_TYPE) + && ! lvalue_p (parm)) + return (convert_harshness_old (ttl, ttr, NULL_TREE) + | INT_TO_EASY_HARSHNESS (penalty)); + + if (ttl == ttr) + { + if (penalty) + return INT_TO_EASY_HARSHNESS (penalty); + return INT_TO_BD_HARSHNESS (0); + } + + /* Pointers to voids always convert for pointers. But + make them less natural than more specific matches. */ + if (TREE_CODE (ttl) == POINTER_TYPE && TREE_CODE (ttr) == POINTER_TYPE) + if (TREE_TYPE (ttl) == void_type_node + || TREE_TYPE (ttr) == void_type_node) + return INT_TO_EASY_HARSHNESS (penalty+1); + + if (parm && codel != REFERENCE_TYPE) + return (convert_harshness_old (ttl, ttr, NULL_TREE) + | INT_TO_EASY_HARSHNESS (penalty)); + + /* Here it does matter. If this conversion is from + derived to base, allow it. Otherwise, types must + be compatible in the strong sense. */ + 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 CONTRAVARIANT_HARSHNESS (-1); + } + /* Say that this conversion is relatively painless. + If it turns out that there is a user-defined X(X&) + constructor, then that will be invoked, but that's + preferable to dealing with other user-defined conversions + that may produce surprising results. */ + return INT_TO_BD_HARSHNESS (b_or_d); + } + + if (comp_target_types (ttl, intype, 1)) + return INT_TO_EASY_HARSHNESS (penalty); + } + } + 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 CONTRAVARIANT_HARSHNESS (-1); + } + return INT_TO_BD_HARSHNESS (b_or_d); + } + return EVIL; +} + +#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_ansi (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; + +#ifdef GATHER_STATISTICS + n_compute_conversion_costs++; +#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 (cp->v.ansi_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_ansi (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_ansi (TREE_VALUE (ttf), + TREE_TYPE (TREE_VALUE (tta)), + TREE_VALUE (tta)); + +#ifdef DEBUG_MATCHING + cp_error (" evaluated %s", print_harshness (&h)); +#endif + } + + cp->v.ansi_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_ansi'. */ + 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; + 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->v.ansi_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; + return; + } + /* Store index of first default. */ + cp->v.ansi_harshness[arglen].distance = strike_index+1; + } + else + cp->v.ansi_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; + 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->v.ansi_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); + + 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)) + { + if (TREE_CODE (formal_type) == INTEGER_TYPE + && TYPE_HAS_INT_CONVERSION (actual_type)) + win++; + else if (TREE_CODE (formal_type) == REAL_TYPE + && TYPE_HAS_REAL_CONVERSION (actual_type)) + win++; + else + { + tree conv; + /* Don't issue warnings since we're only groping + around for the right answer, we haven't yet + committed to going with this solution. */ + int old_inhibit_warnings = inhibit_warnings; + + inhibit_warnings = 1; + conv = build_type_conversion (CALL_EXPR, TREE_VALUE (ttf), TREE_VALUE (tta), 0); + inhibit_warnings = old_inhibit_warnings; + + if (conv) + { + if (conv == error_mark_node) + win += 2; + else + win++; + } + else if (TREE_CODE (TREE_VALUE (ttf)) == REFERENCE_TYPE) + { + conv = build_type_conversion (CALL_EXPR, formal_type, TREE_VALUE (tta), 0); + if (conv) + { + if (conv == error_mark_node) + win += 2; + else + win++; + } + } + } + } + } + dont_convert_types = 0; + + if (win == 1) + { + user_strikes += 1; + cp->v.ansi_harshness[strike_index].code = USER_CODE; + 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->v.ansi_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->v.ansi_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; +#ifdef DEBUG_MATCHING + cp_error ("final eval %s", print_harshness (&cp->h)); +#endif +} + +void +compute_conversion_costs_old (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, lose; + +#ifdef GATHER_STATISTICS + n_compute_conversion_costs++; +#endif + + cp->function = function; + cp->arg = tta ? TREE_VALUE (tta) : NULL_TREE; + cp->u.bad_arg = 0; /* optimistic! */ + + bzero (cp->v.old_harshness, (cp->h_len + 1) * sizeof (unsigned short)); + + while (ttf && tta) + { + int harshness; + + 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) + harshness = 1; + else + { + harshness = convert_harshness_old (lhstype, TREE_TYPE (rhs), + rhs); + /* harshness |= 2; */ + } + } + else + harshness = convert_harshness_old (TREE_VALUE (ttf), + TREE_TYPE (TREE_VALUE (tta)), + TREE_VALUE (tta)); + + cp->v.old_harshness[strike_index] = harshness; + if (EVIL_HARSHNESS (harshness) + || CONTRAVARIANT_HARSHNESS (harshness)) + { + cp->u.bad_arg = strike_index; + evil_strikes = 1; + } + else if (ELLIPSIS_HARSHNESS (harshness)) + { + ellipsis_strikes += 1; + } +#if 0 + /* This is never set by `convert_harshness_old'. */ + else if (USER_HARSHNESS (harshness)) + { + user_strikes += 1; + } +#endif + else if (BASE_DERIVED_HARSHNESS (harshness)) + { + b_or_d_strikes += INT_FROM_BD_HARSHNESS (harshness); + } + else + easy_strikes += INT_FROM_EASY_HARSHNESS (harshness); + 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->evil = 1; + cp->u.bad_arg = -1; + return; + } + else ellipsis_strikes += list_length (tta); + } + else if (ttf && ttf != void_list_node) + { + /* ran out of actuals, and no defaults. */ + if (TREE_PURPOSE (ttf) == NULL_TREE) + { + cp->evil = 1; + cp->u.bad_arg = -2; + return; + } + /* Store index of first default. */ + cp->v.old_harshness[arglen] = strike_index+1; + } + else + cp->v.old_harshness[arglen] = 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->evil = 1; + 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->v.old_harshness[strike_index]; + if (EVIL_HARSHNESS (lose) + || CONTRAVARIANT_HARSHNESS (lose)) + { + tree actual_type = TREE_TYPE (TREE_VALUE (tta)); + tree formal_type = TREE_VALUE (ttf); + + 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. */ + if (convert_to_aggr (formal_type, TREE_VALUE (tta), 0, 1) + != error_mark_node) + { + /* @@ There is no way to save this result yet. + @@ So success is NULL_TREE for now. */ + win++; + } + } + if (TYPE_LANG_SPECIFIC (actual_type) && TYPE_HAS_CONVERSION (actual_type)) + { + if (TREE_CODE (formal_type) == INTEGER_TYPE + && TYPE_HAS_INT_CONVERSION (actual_type)) + win++; + else if (TREE_CODE (formal_type) == REAL_TYPE + && TYPE_HAS_REAL_CONVERSION (actual_type)) + win++; + else + { + tree conv = build_type_conversion (CALL_EXPR, TREE_VALUE (ttf), TREE_VALUE (tta), 0); + if (conv) + { + if (conv == error_mark_node) + win += 2; + else + win++; + } + else if (TREE_CODE (TREE_VALUE (ttf)) == REFERENCE_TYPE) + { + conv = build_type_conversion (CALL_EXPR, formal_type, TREE_VALUE (tta), 0); + if (conv) + { + if (conv == error_mark_node) + win += 2; + else + win++; + } + } + } + } + } + dont_convert_types = 0; + + if (win == 1) + { + user_strikes += 1; + cp->v.old_harshness[strike_index] = USER_HARSHNESS (-1); + 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->v.old_harshness[0] += INT_TO_EASY_HARSHNESS (1); + ++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->v.old_harshness[0] |= CONST_HARSHNESS (-1); + } + } + + cp->evil = evil_strikes; + cp->ellipsis = ellipsis_strikes; + cp->user = user_strikes; + cp->b_or_d = b_or_d_strikes; + cp->easy = easy_strikes; +} + +void +compute_conversion_costs (function, tta_in, cp, arglen) + tree function; + tree tta_in; + struct candidate *cp; + int arglen; +{ + if (flag_ansi_overloading) + compute_conversion_costs_ansi (function, tta_in, cp, arglen); + else + compute_conversion_costs_old (function, tta_in, cp, arglen); +} + +/* 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_old (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 index, i; + tree ttf; + + qsort (candidates, /* char *base */ + n_candidates, /* int nel */ + sizeof (struct candidate), /* int width */ + rank_for_overload); /* int (*compar)() */ + + /* If the best candidate requires user-defined conversions, + and its user-defined conversions are a strict subset + of all other candidates requiring user-defined conversions, + then it is, in fact, the best. */ + for (i = -1; cp + i != candidates; i--) + if (cp[i].user == 0) + break; + + if (i < -1) + { + tree ttf0; + + /* Check that every other candidate requires those conversions + as a strict subset of their conversions. */ + if (cp[i].user == cp[-1].user) + goto non_subset; + + /* Look at subset relationship more closely. */ + while (i != -1) + { + for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[i].function)), + ttf0 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function)), + index = 0; index < len; index++) + { + if (USER_HARSHNESS (cp[i].v.old_harshness[index])) + { + /* If our "best" candidate also needs a conversion, + it must be the same one. */ + if (USER_HARSHNESS (cp[-1].v.old_harshness[index]) + && TREE_VALUE (ttf) != TREE_VALUE (ttf0)) + goto non_subset; + } + ttf = TREE_CHAIN (ttf); + ttf0 = TREE_CHAIN (ttf0); + /* Handle `...' gracefully. */ + if (ttf == NULL_TREE || ttf0 == NULL_TREE) + break; + } + i++; + } + /* The best was the best. */ + return cp - 1; + non_subset: + /* Use other rules for determining "bestness". */ + ; + } + + /* If the best two candidates we find require user-defined + conversions, we may need to report and error message. */ + if (cp[-1].user && cp[-2].user + && (cp[-1].b_or_d || cp[-2].b_or_d == 0)) + { + /* If the best two methods found involved user-defined + type conversions, then we must see whether one + of them is exactly what we wanted. If not, then + we have an ambiguity. */ + int best = 0; + tree tta = parms; + tree f1; +#if 0 + /* for LUCID */ + tree p1; +#endif + + /* Stash all of our parameters in safe places + so that we can perform type conversions in place. */ + while (tta) + { + TREE_PURPOSE (tta) = TREE_VALUE (tta); + tta = TREE_CHAIN (tta); + } + + i = 0; + do + { + int exact_conversions = 0; + + i -= 1; + tta = parms; + if (DECL_STATIC_FUNCTION_P (cp[i].function)) + tta = TREE_CHAIN (tta); + /* special note, we don't go through len parameters, because we + may only need len-1 parameters because of a call to a static + member. */ + for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[i].function)), index = 0; + tta; + tta = TREE_CHAIN (tta), ttf = TREE_CHAIN (ttf), index++) + { + /* If this is a varargs function, there's no conversion to do, + but don't accept an arg that needs a copy ctor. */ + if (ttf == NULL_TREE) + { + /* FIXME: verify that we cannot get here with an + arg that needs a ctor. */ + break; + } + + if (USER_HARSHNESS (cp[i].v.old_harshness[index])) + { + tree this_parm = build_type_conversion (CALL_EXPR, TREE_VALUE (ttf), TREE_PURPOSE (tta), 2); + if (basetype != NULL_TREE) + TREE_VALUE (tta) = this_parm; + if (this_parm) + { + if (TREE_CODE (this_parm) != CONVERT_EXPR + && (TREE_CODE (this_parm) != NOP_EXPR + || comp_target_types (TREE_TYPE (this_parm), + TREE_TYPE (TREE_OPERAND (this_parm, 0)), 1))) + exact_conversions += 1; + } + else if (PROMOTES_TO_AGGR_TYPE (TREE_VALUE (ttf), REFERENCE_TYPE)) + { + /* To get here we had to have succeeded via + a constructor. */ + TREE_VALUE (tta) = TREE_PURPOSE (tta); + exact_conversions += 1; + } + } + } + if (exact_conversions == cp[i].user) + { + if (best == 0) + { + best = i; + f1 = cp[best].function; +#if 0 + /* For LUCID */ + p1 = TYPE_ARG_TYPES (TREE_TYPE (f1)); +#endif + } + else + { + /* Don't complain if next best is from base class. */ + tree f2 = cp[i].function; + + if (TREE_CODE (TREE_TYPE (f1)) == METHOD_TYPE + && TREE_CODE (TREE_TYPE (f2)) == METHOD_TYPE + && BASE_DERIVED_HARSHNESS (cp[i].v.old_harshness[0]) + && cp[best].v.old_harshness[0] < cp[i].v.old_harshness[0]) + { +#if 0 + tree p2 = TYPE_ARG_TYPES (TREE_TYPE (f2)); + /* For LUCID. */ + if (! compparms (TREE_CHAIN (p1), TREE_CHAIN (p2), 1)) + goto ret0; + else +#endif + continue; + } + else + { + /* Ensure that there's nothing ambiguous about these + two fns. */ + int identical = 1; + for (index = 0; index < len; index++) + { + /* Type conversions must be piecewise equivalent. */ + if (USER_HARSHNESS (cp[best].v.old_harshness[index]) + != USER_HARSHNESS (cp[i].v.old_harshness[index])) + goto ret0; + /* If there's anything we like better about the + other function, consider it ambiguous. */ + if (cp[i].v.old_harshness[index] < cp[best].v.old_harshness[index]) + goto ret0; + /* If any single one it diffent, then the whole is + not identical. */ + if (cp[i].v.old_harshness[index] != cp[best].v.old_harshness[index]) + identical = 0; + } + + /* If we can't tell the difference between the two, it + is ambiguous. */ + if (identical) + goto ret0; + + /* If we made it to here, it means we're satisfied that + BEST is still best. */ + continue; + } + } + } + } while (cp + i != candidates); + + if (best) + { + int exact_conversions = cp[best].user; + tta = parms; + if (DECL_STATIC_FUNCTION_P (cp[best].function)) + tta = TREE_CHAIN (parms); + for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[best].function)), index = 0; + exact_conversions > 0; + tta = TREE_CHAIN (tta), ttf = TREE_CHAIN (ttf), index++) + { + if (USER_HARSHNESS (cp[best].v.old_harshness[index])) + { + /* We must now fill in the slot we left behind. + @@ This could be optimized to use the value previously + @@ computed by build_type_conversion in some cases. */ + if (basetype != NULL_TREE) + TREE_VALUE (tta) = convert (TREE_VALUE (ttf), TREE_PURPOSE (tta)); + exact_conversions -= 1; + } + else + TREE_VALUE (tta) = TREE_PURPOSE (tta); + } + return cp + best; + } + goto ret0; + } + /* If the best two candidates we find both use default parameters, + we may need to report and error. Don't need to worry if next-best + candidate is forced to use user-defined conversion when best is not. */ + if (cp[-2].user == 0 + && cp[-1].v.old_harshness[len] != 0 && cp[-2].v.old_harshness[len] != 0) + { + tree tt1 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function)); + tree tt2 = TYPE_ARG_TYPES (TREE_TYPE (cp[-2].function)); + unsigned i = cp[-1].v.old_harshness[len]; + + if (cp[-2].v.old_harshness[len] < i) + i = cp[-2].v.old_harshness[len]; + while (--i > 0) + { + if (TYPE_MAIN_VARIANT (TREE_VALUE (tt1)) + != TYPE_MAIN_VARIANT (TREE_VALUE (tt2))) + /* These lists are not identical, so we can choose our best candidate. */ + return cp - 1; + tt1 = TREE_CHAIN (tt1); + tt2 = TREE_CHAIN (tt2); + } + /* To get here, both lists had the same parameters up to the defaults + which were used. This is an ambiguous request. */ + goto ret0; + } + + /* Otherwise, return our best candidate. Note that if we get candidates + from independent base classes, we have an ambiguity, even if one + argument list look a little better than another one. */ + if (cp[-1].b_or_d && basetype && TYPE_USES_MULTIPLE_INHERITANCE (basetype)) + { + int i = n_candidates - 1, best = i; + tree base1 = NULL_TREE; + + if (TREE_CODE (TREE_TYPE (candidates[i].function)) == FUNCTION_TYPE) + return cp - 1; + + for (; i >= 0 && candidates[i].user == 0 && candidates[i].evil == 0; i--) + { + if (TREE_CODE (TREE_TYPE (candidates[i].function)) == METHOD_TYPE) + { + tree newbase = DECL_CLASS_CONTEXT (candidates[i].function); + + if (base1 != NULL_TREE) + { + /* newbase could be a base or a parent of base1 */ + if (newbase != base1 && ! UNIQUELY_DERIVED_FROM_P (newbase, base1) + && ! UNIQUELY_DERIVED_FROM_P (base1, newbase)) + { + cp_error ("ambiguous request for function from distinct base classes of type `%T'", basetype); + cp_error_at (" first candidate is `%#D'", + candidates[best].function); + cp_error_at (" second candidate is `%#D'", + candidates[i].function); + cp[-1].evil = 1; + return cp - 1; + } + } + else + { + best = i; + base1 = newbase; + } + } + else + return cp - 1; + } + } + + /* Don't accept a candidate as being ideal if it's indistinguishable + from another candidate. */ + if (rank_for_overload (cp-1, cp-2) == 0) + { + /* If the types are distinguishably different (like + `long' vs. `unsigned long'), that's ok. But if they are arbitrarily + different, such as `int (*)(void)' vs. `void (*)(int)', + that's not ok. */ + tree p1 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function)); + tree p2 = TYPE_ARG_TYPES (TREE_TYPE (cp[-2].function)); + while (p1 && p2) + { + if (TREE_CODE (TREE_VALUE (p1)) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (TREE_VALUE (p1))) == FUNCTION_TYPE + && TREE_VALUE (p1) != TREE_VALUE (p2)) + return NULL; + p1 = TREE_CHAIN (p1); + p2 = TREE_CHAIN (p2); + } + if (p1 || p2) + return NULL; + } + + return cp - 1; + + ret0: + /* In the case where there is no ideal candidate, restore + TREE_VALUE slots of PARMS from TREE_PURPOSE slots. */ + while (parms) + { + TREE_VALUE (parms) = TREE_PURPOSE (parms); + parms = TREE_CHAIN (parms); + } + return NULL; +} + +/* 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; +} + +static struct candidate * +ideal_candidate_ansi (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].v.ansi_harshness[i].code < cp[-2].v.ansi_harshness[i].code) + better = 1; + else if (cp[-1].v.ansi_harshness[i].code > cp[-2].v.ansi_harshness[i].code) + worse = 1; + else if (cp[-1].v.ansi_harshness[i].code & STD_CODE) + { + /* If it involves a standard conversion, let the + inheritance lattice be the final arbiter. */ + if (cp[-1].v.ansi_harshness[i].distance > cp[-2].v.ansi_harshness[i].distance) + worse = 1; + else if (cp[-1].v.ansi_harshness[i].distance < cp[-2].v.ansi_harshness[i].distance) + better = 1; + } + else if (cp[-1].v.ansi_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].v.ansi_harshness[i].int_penalty > cp[-2].v.ansi_harshness[i].int_penalty) + worse = 1; + else if (cp[-1].v.ansi_harshness[i].int_penalty < cp[-2].v.ansi_harshness[i].int_penalty) + better = 1; + } + } + + if (! better || worse) + return NULL; + } + return cp-1; +} + +static struct candidate * +ideal_candidate (basetype, candidates, n_candidates, parms, len) + tree basetype; + struct candidate *candidates; + int n_candidates; + tree parms; + int len; +{ + if (flag_ansi_overloading) + return ideal_candidate_ansi (basetype, candidates, n_candidates, parms, + len); + else + return ideal_candidate_old (basetype, candidates, n_candidates, parms, + len); +} + +/* 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) + { + /* 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; + } + 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 = IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name, 0)); + if (basetype != name) + cp_error ("qualified type `%T' does not match destructor type `%T'", + basetype, name); + return void_zero_node; + } + + 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 (TREE_TYPE (decl) != + (IDENTIFIER_CLASS_VALUE (name) + ? IDENTIFIER_CLASS_TYPE_VALUE (name) + : IDENTIFIER_TYPE_VALUE (name))) + { + cp_error + ("qualified type `%T' does not match destructor type `%T'", + TREE_TYPE (decl), name); + return error_mark_node; + } + if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl))) + return void_zero_node; + + 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, NULL_TREE, + 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 works, return it. */ + if (result && result != error_mark_node) + 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; + } + + if (TREE_CODE (name) == BIT_NOT_EXPR) + { + flags |= LOOKUP_DESTRUCTOR; + name = TREE_OPERAND (name, 0); + if (parms) + error ("destructors take no parameters"); + basetype = get_type_value (name); + if (basetype == NULL_TREE) + { + cp_error ("call to destructor for non-type `%D'", name); + return void_zero_node; + } + if (! TYPE_HAS_DESTRUCTOR (basetype)) + return void_zero_node; + 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 (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; + + instance = C_C_D; + instance_ptr = current_class_decl; + result = build_field_call (TYPE_BINFO (current_class_type), + 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, TYPE_POINTER_TO (basetype), instance); + } + else if (instance == current_exception_object) + { + instance_ptr = build1 (ADDR_EXPR, TYPE_POINTER_TO (current_exception_type), + TREE_OPERAND (current_exception_object, 0)); + mark_addressable (TREE_OPERAND (current_exception_object, 0)); + result = build_field_call (TYPE_BINFO (current_exception_type), + instance_ptr, name, parms); + if (result) + return result; + cp_error ("exception member `%D' cannot be invoked", name); + return error_mark_node; + } + 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); + + /* the base type of an instance variable is pointer to class */ + basetype = TREE_TYPE (instance); + + if (TREE_CODE (basetype) == REFERENCE_TYPE) + { + basetype = TYPE_MAIN_VARIANT (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, TYPE_POINTER_TO (basetype), instance); + inst_ptr_basetype = basetype; + } + else + { + if (! IS_AGGR_TYPE (basetype)) + goto non_aggr_error; + + if (IS_SIGNATURE_POINTER (basetype) + || IS_SIGNATURE_REFERENCE (basetype)) + basetype = SIGNATURE_TYPE (basetype); + + if ((IS_SIGNATURE (basetype) + && (instance_ptr = build_optr_ref (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); + 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? */ + 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 (TYPE_POINTER_TO (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 = 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 (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)); + } + if (t == error_mark_node) + return error_mark_node; + last = build_tree_list (NULL_TREE, t); + parmtypes = chainon (parmtypes, last); + } + + if (instance) + { + constp = TREE_READONLY (instance); + volatilep = TREE_THIS_VOLATILE (instance); + 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); + } + + if (flag_this_is_variable > 0) + { + constp = 0; + volatilep = 0; + parms = tree_cons (NULL_TREE, build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), integer_zero_node), parms); + } + else + { + constp = 0; + volatilep = 0; + instance_ptr = build_new (NULL_TREE, basetype, void_type_node, 0); + if (instance_ptr == error_mark_node) + return error_mark_node; + instance_ptr = save_expr (instance_ptr); + TREE_CALLS_NEW (instance_ptr) = 1; + instance = build_indirect_ref (instance_ptr, NULL_PTR); + + /* If it's a default argument initialized from a ctor, what we get + from instance_ptr will match the arglist for the FUNCTION_DECL + of the constructor. */ + if (parms && TREE_CODE (TREE_VALUE (parms)) == CALL_EXPR + && TREE_OPERAND (TREE_VALUE (parms), 1) + && TREE_CALLS_NEW (TREE_VALUE (TREE_OPERAND (TREE_VALUE (parms), 1)))) + parms = build_tree_list (NULL_TREE, instance_ptr); + else + parms = tree_cons (NULL_TREE, instance_ptr, parms); + } + } + parmtypes = tree_cons (NULL_TREE, + build_pointer_type (build_type_variant (basetype, constp, volatilep)), + parmtypes); + if (last == NULL_TREE) + last = parmtypes; + + /* Look up function name in the structure type definition. */ + + if ((IDENTIFIER_HAS_TYPE_VALUE (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; + + + /* 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; + + 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 (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 = TREE_VALUE (parms); + + if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE) + friend_parms = parms; + else if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE) + { + tree new_type; + parm = build_indirect_ref (parm, "friendifying parms (compiler error)"); + new_type = build_reference_type (TREE_TYPE (parm)); + /* It is possible that this should go down a layer. */ + new_type = build_type_variant (new_type, + TREE_READONLY (parm), + TREE_THIS_VOLATILE (parm)); + parm = convert (new_type, parm); + friend_parms = tree_cons (NULL_TREE, parm, TREE_CHAIN (parms)); + } + else + my_friendly_abort (167); + + cp->h_len = len; + if (flag_ansi_overloading) + cp->v.ansi_harshness = (struct harshness_code *) + alloca ((len + 1) * sizeof (struct harshness_code)); + else + cp->v.old_harshness = (unsigned short *) + alloca ((len + 1) * sizeof (unsigned short)); + + 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; + + if (flag_ansi_overloading) + 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->v.ansi_harshness[len].distance == 0 + && cp->h.code < best) + best = cp->h.code; + cp += 1; + } + else + while (cp->evil == 0) + { + /* non-standard uses: set the field to 0 to indicate + we are using a non-member function. */ + cp->u.field = 0; + if (cp->v.old_harshness[len] == 0 + && cp->v.old_harshness[len] == 0 + && cp->ellipsis == 0 && cp->user == 0 && cp->b_or_d == 0 + && cp->easy < best) + best = cp->easy; + 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); + + /* Cast the instance variable to the appropriate type. */ + TREE_VALUE (parms) = convert_force (TYPE_POINTER_TO (basetype), + instance_ptr); + /* 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; + + 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 (pass == 0 + && DECL_ASSEMBLER_NAME (function) == method_name) + goto found; + + if (pass > 0) + { + tree these_parms = parms; + +#ifdef GATHER_STATISTICS + n_inner_fields_searched++; +#endif + cp->h_len = len; + if (flag_ansi_overloading) + cp->v.ansi_harshness = (struct harshness_code *) + alloca ((len + 1) * sizeof (struct harshness_code)); + else + cp->v.old_harshness = (unsigned short *) + alloca ((len + 1) * sizeof (unsigned short)); + + if (DECL_STATIC_FUNCTION_P (function)) + these_parms = TREE_CHAIN (these_parms); + compute_conversion_costs (function, these_parms, cp, len); + + if (!flag_ansi_overloading) + cp->b_or_d += b_or_d; + + if ((flag_ansi_overloading && (cp->h.code & EVIL_CODE) == 0) + || (!flag_ansi_overloading && cp->evil == 0)) + { + cp->u.field = function; + cp->function = function; + cp->basetypes = basetype_path; + + /* No "two-level" conversions. */ + if (flags & LOOKUP_NO_CONVERSION + && ((flag_ansi_overloading + && (cp->h.code & USER_CODE)) + || (!flag_ansi_overloading + && cp->user != 0))) + continue; + + /* If we used default parameters, we must + check to see whether anyone else might + use them also, and report a possible + ambiguity. */ + if (! TYPE_USES_MULTIPLE_INHERITANCE (save_basetype) + && ((flag_ansi_overloading + && cp->v.ansi_harshness[len].distance == 0 + && cp->h.code < best) + || (!flag_ansi_overloading + && cp->v.old_harshness[len] == 0 + && CONST_HARSHNESS (cp->v.old_harshness[0]) == 0 + && cp->ellipsis == 0 && cp->user == 0 && cp->b_or_d == 0 + && cp->easy < best))) + { + if (! DECL_STATIC_FUNCTION_P (function)) + TREE_VALUE (parms) = cp->arg; + if (best == 1) + goto found_and_maybe_warn; + } + 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 = IDENTIFIER_GLOBAL_VALUE (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) + { + cp = ideal_candidate (save_basetype, candidates, + cp - candidates, parms, len); + if (cp == (struct candidate *)0) + { + cp_error ("ambiguous type conversion requested for %s `%D'", + name_kind, name); + return error_mark_node; + } + if ((flag_ansi_overloading && (cp->h.code & EVIL_CODE)) + || (!flag_ansi_overloading && cp->evil)) + return error_mark_node; + } + else if ((flag_ansi_overloading && (cp[-1].h.code & EVIL_CODE)) + || (!flag_ansi_overloading && cp[-1].evil == 2)) + { + 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_GLOBAL) & (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)'", + TREE_TYPE (TREE_TYPE (instance_ptr)), + name, TREE_CHAIN (parmtypes)); + 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 ((flag_ansi_overloading + && (cp->v.ansi_harshness[0].code & CONST_CODE)) + || (!flag_ansi_overloading + && CONST_HARSHNESS (cp->v.old_harshness[0]))) + { + 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 (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); + + 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; + } + + /* We do not pass FUNCTION into `convert_arguments', because by + now everything should be ok. If not, then we have a serious error. */ + if (DECL_STATIC_FUNCTION_P (function)) + parms = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype), + TREE_CHAIN (parms), NULL_TREE, 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), NULL_TREE, 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), NULL_TREE, 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 (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); + if (DECL_INLINE (function)) + function = build1 (ADDR_EXPR, build_pointer_type (fntype), function); + else + { + assemble_external (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_RAISES (result) + = TYPE_RAISES_EXCEPTIONS (fntype) || (parms && TREE_RAISES (parms)); + TREE_HAS_CONSTRUCTOR (result) = is_constructor; + 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) + { + if (flag_ansi_overloading) + { + 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; + } + else + { + final_cp[0].evil = 0; + final_cp[0].user = 0; + final_cp[0].b_or_d = 0; + final_cp[0].easy = 0; + final_cp[0].function = 0; + /* end marker. */ + final_cp[1].evil = 1; + } + } + + for (parm = parms; parm; parm = TREE_CHAIN (parm)) + { + register tree t = TREE_TYPE (TREE_VALUE (parm)); + + if (t == error_mark_node) + { + if (final_cp) + { + if (flag_ansi_overloading) + final_cp->h.code = EVIL_CODE; + else + final_cp->evil = 1; + } + return error_mark_node; + } + if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == OFFSET_TYPE) + { + /* 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 (! flag_ansi_overloading) + { + /* This is a speed improvement that ends up not working properly in + the situation of fns with and without default parameters. I turned + this off in the new method so it'll go through the argument matching + code to properly diagnose a match/failure. (bpk) */ + overload_name = build_decl_overload (fnname, parmtypes, 0); + + /* Now check to see whether or not we can win. + Note that if we are called from `build_method_call', + then we cannot have a mis-match, because we would have + already found such a winning case. */ + + if (IDENTIFIER_GLOBAL_VALUE (overload_name)) + if (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (overload_name)) != TREE_LIST) + return build_function_call (DECL_MAIN_VARIANT (IDENTIFIER_GLOBAL_VALUE (overload_name)), parms); + } + + functions = IDENTIFIER_GLOBAL_VALUE (fnname); + + if (functions == NULL_TREE) + { + if (flags & LOOKUP_SPECULATIVELY) + return NULL_TREE; + if (flags & LOOKUP_COMPLAIN) + error ("only member functions apply"); + if (final_cp) + { + if (flag_ansi_overloading) + final_cp->h.code = EVIL_CODE; + else + final_cp->evil = 1; + } + return error_mark_node; + } + + if (! TREE_OVERLOADED (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) + { + if (flag_ansi_overloading) + final_cp->h.code = EVIL_CODE; + else + final_cp->evil = 1; + } + 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 (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) + { + struct candidate *cp2; + + function = instantiate_template (function, targs); + /* Now check that the template instantiated for this is not + the same as a function that's in the list due to some + previous instantiation. */ + cp2 = candidates; + while (cp2 != cp) + if (cp2->function == function) + break; + else + cp2 += 1; + if (cp2->function == function) + continue; + } + } + + if (TREE_CODE (function) == TEMPLATE_DECL) + { + /* Unconverted template -- failed match. */ + cp->function = function; + cp->u.bad_arg = -4; + if (flag_ansi_overloading) + cp->h.code = EVIL_CODE; + else + cp->evil = 1; + } + else + { + function = DECL_MAIN_VARIANT (function); + + /* Can't use alloca here, since result might be + passed to calling function. */ + cp->h_len = parmlength; + if (flag_ansi_overloading) + cp->v.ansi_harshness = (struct harshness_code *) + oballoc ((parmlength + 1) * sizeof (struct harshness_code)); + else + cp->v.old_harshness = (unsigned short *) + oballoc ((parmlength + 1) * sizeof (unsigned short)); + + compute_conversion_costs (function, parms, cp, parmlength); + + if (flag_ansi_overloading) + /* Make sure this is clear as well. */ + cp->h.int_penalty += template_cost; + else + /* Should really add another field... */ + cp->easy = cp->easy * 128 + template_cost; + + /* It seemed easier to have both if stmts in here, rather + than excluding the hell out of it with flag_ansi_overloading + everywhere. (bpk) */ + if (flag_ansi_overloading) + { + if ((cp[0].h.code & EVIL_CODE) == 0) + { + cp[1].h.code = EVIL_CODE; + + /* int_penalty is set by convert_harshness_ansi for cases + where we need to know about any penalties that would + otherwise make a TRIVIAL_CODE pass. */ + if (final_cp + && template_cost == 0 + && cp[0].h.code <= TRIVIAL_CODE + && cp[0].h.int_penalty == 0) + { + final_cp[0].h = cp[0].h; + return function; + } + cp++; + } + } + else + { + if (cp[0].evil == 0) + { + cp[1].evil = 1; + if (final_cp + && cp[0].user == 0 && cp[0].b_or_d == 0 + && template_cost == 0 + && cp[0].easy <= 1) + { + final_cp[0].easy = cp[0].easy; + return function; + } + cp++; + } + } + } + } + + if (cp - candidates) + { + tree rval = error_mark_node; + + /* Leave marker. */ + if (flag_ansi_overloading) + cp[0].h.code = EVIL_CODE; + else + cp[0].evil = 1; + 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 ((flag_ansi_overloading && (cp->h.code & EVIL_CODE)) + || (!flag_ansi_overloading && cp->evil > 1)) + { + 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/gcc/cp/class.c b/gcc/cp/class.c new file mode 100644 index 00000000000..e6400105112 --- /dev/null +++ b/gcc/cp/class.c @@ -0,0 +1,5048 @@ +/* Functions related to building classes and their related objects. + Copyright (C) 1987, 1992, 1993, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */ + + +/* High-level class interface. */ + +#include "config.h" +#include "tree.h" +#include +#include "cp-tree.h" +#include "flags.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 */ +tree current_vtable_decl; + +/* 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; +static int current_lang_stacksize; + +/* Names of languages we recognize. */ +tree lang_name_c, lang_name_cplusplus; +tree current_lang_name; + +/* 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 cp-class.c and cp-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; + + /* 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 convertions. 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 && !flag_assume_nonnull_objects + && null_expr == NULL_TREE) + { + null_expr = build1 (NOP_EXPR, TYPE_POINTER_TO (last_virtual), integer_zero_node); + expr = build (COND_EXPR, TYPE_POINTER_TO (last_virtual), + build (EQ_EXPR, integer_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)) + basetype = intype; + else + { + tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0); + basetype = last; + 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)) + { + /* 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 legal value to + which we may add. */ + if (nonnull == 0 && (alias_this == 0 || flag_this_is_variable > 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, integer_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. Usually this is used only when classes have virtual + baseclasses, but it can happen also when classes have non-virtual + baseclasses if the derived class overrides baseclass functions + at different offsets. */ +static tree pending_hard_virtuals; +static int doing_hard_virtuals; + +/* XXX This is set but never used. (bpk) */ +#if 0 +/* Temporary binfo list to memoize lookups of the left-most non-virtual + baseclass B in a lattice topped by T. B can appear multiple times + in the lattice. + TREE_PURPOSE is B's TYPE_MAIN_VARIANT. + TREE_VALUE is the path by which B is reached from T. + TREE_TYPE is B's real type. + + If TREE_TYPE is NULL_TREE, it means that B was reached via + a virtual baseclass. + N.B.: This list consists of nodes on the temporary obstack. */ +static tree leftmost_baseclasses; +#endif + +/* 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; +{ + 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) + { + if (current_vtable_decl == NULL_TREE + || current_vtable_decl == error_mark_node + || !UNIQUELY_DERIVED_FROM_P (DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type)), basetype)) + vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), NULL_PTR); + else + vtbl = current_vtable_decl; + } + 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)) + && !IS_SIGNATURE_POINTER (TREE_TYPE (instance)) + && !IS_SIGNATURE_REFERENCE (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)); + + *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); +} + +/* Set TREE_PUBLIC and/or TREE_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. */ + +static void +import_export_vtable (decl, type) + tree decl, type; +{ + if (write_virtuals >= 2) + { + if (CLASSTYPE_INTERFACE_KNOWN (type)) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type); + } + } + else if (write_virtuals != 0) + { + TREE_PUBLIC (decl) = 1; + if (write_virtuals < 0) + DECL_EXTERNAL (decl) = 1; + } +} + +/* 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 (sizeof (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); + + 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; +#if 0 + /* Remember which class this vtable is really for. */ + if (binfo) + DECL_VPARENT (decl) = BINFO_TYPE (binfo); + else + DECL_VPARENT (decl) = type; +#endif + DECL_CONTEXT (decl) = type; + + binfo = TYPE_BINFO (type); + SET_BINFO_VTABLE_PATH_MARKED (binfo); + 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; +} + +/* 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. + + The way we update BASE_BINFO's vtable information is just to change the + association information in FOR_TYPE's association list. */ +static void +prepare_fresh_vtable (binfo, base_binfo, for_type) + tree binfo, base_binfo, for_type; +{ + tree basetype = BINFO_TYPE (binfo); + tree orig_decl = BINFO_VTABLE (binfo); + 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; + int result; + + /* Remember which class this vtable is really for. */ +#if 0 + DECL_VPARENT (new_decl) = BINFO_TYPE (base_binfo); +#endif + 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)); + /* Install the value for `headof' if that's what we're doing. */ + if (flag_dossier) + TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo))) + = build_vtable_entry (size_binop (MINUS_EXPR, integer_zero_node, BINFO_OFFSET (binfo)), + FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo))))); + +#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); + + 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); + SET_BINFO_VTABLE_PATH_MARKED (binfo); + + /* Mark all types between FOR_TYPE and TYPE as having been + touched, so that if we change virtual function table entries, + new vtables will be initialized. We may reach the virtual + baseclass via ambiguous intervening baseclasses. This + loop makes sure we get through to the actual baseclass we marked. + + Also, update the vtable entries to reflect the overrides + of the top-most class (short of the top type). */ + + do + { + result = get_base_distance (basetype, for_type, 0, &path); + for_type = path; + while (path) + { + tree path_binfo = path; + tree path_type = BINFO_TYPE (path); + + if (TREE_VIA_VIRTUAL (path)) + path_binfo = binfo_member (path_type, + CLASSTYPE_VBASECLASSES (current_class_type)); + + SET_BINFO_VTABLE_PATH_MARKED (path_binfo); + if (BINFO_INHERITANCE_CHAIN (path) + && CLASSTYPE_VFIELD (path_type) != NULL_TREE + && (DECL_NAME (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))) + == DECL_NAME (CLASSTYPE_VFIELD (path_type))) + /* This is the baseclass just before the original FOR_TYPE. */ + && BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path)) == NULL_TREE) + { + tree old_virtuals = TREE_CHAIN (BINFO_VIRTUALS (binfo)); + tree new_virtuals = TREE_CHAIN (BINFO_VIRTUALS (path_binfo)); + if (flag_dossier) + { + old_virtuals = TREE_CHAIN (old_virtuals); + new_virtuals = TREE_CHAIN (new_virtuals); + } + while (old_virtuals) + { + TREE_VALUE (old_virtuals) = TREE_VALUE (new_virtuals); + old_virtuals = TREE_CHAIN (old_virtuals); + new_virtuals = TREE_CHAIN (new_virtuals); + } + } + path = BINFO_INHERITANCE_CHAIN (path); + } + } + while (result == -2); +} + +/* Access the virtual function table entry that logically + contains BASE_FNDECL. VIRTUALS is the virtual function table's + initializer. */ +static tree +get_vtable_entry (virtuals, base_fndecl) + tree virtuals, base_fndecl; +{ + unsigned HOST_WIDE_INT i = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD +#ifdef VTABLE_USES_MASK + && 0 +#endif + ? (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 += i; +#endif + + while (i > 0) + { + virtuals = TREE_CHAIN (virtuals); + i -= 1; + } + 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_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)); + tree vindex; + +#ifdef NOTQUITE + cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (TREE_OPERAND (base_pfn, 0)), DECL_ASSEMBLER_NAME (fndecl)); +#endif + /* We can't put in the really right offset information + here, since we have not yet laid out the class to + take into account virtual base classes. */ + TREE_VALUE (old_entry_in_list) = new_entry; + vindex = DECL_VINDEX (TREE_OPERAND (base_pfn, 0)); + if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST) + DECL_VINDEX (fndecl) = vindex; + else + { + if (! tree_int_cst_equal (DECL_VINDEX (fndecl), vindex)) + { + tree elts = CONSTRUCTOR_ELTS (new_entry); + + if (! doing_hard_virtuals) + { + pending_hard_virtuals + = tree_cons (fndecl, FNADDR_FROM_VTABLE_ENTRY (new_entry), + pending_hard_virtuals); + TREE_TYPE (pending_hard_virtuals) = TREE_OPERAND (base_pfn, 0); + return; + } + } + } +} + +/* Check to ensure that the virtual function table slot in VFIELD, + found by DECL_VINDEX of the BASE_FNDECL is in fact from a parent + virtual function table that is the same parent as for the + BASE_FNDECL given to us. */ + +static int +related_vslot (base_fndecl, vfields, type) + tree base_fndecl, vfields, type; +{ + tree base_context = TYPE_MAIN_VARIANT (DECL_CONTEXT (base_fndecl)); + tree base; + tree path; + int distance; + + if (TREE_CODE (vfields) != TREE_LIST) + abort (); + base = VF_NORMAL_VALUE (vfields); + if (base == NULL_TREE) + base = VF_BASETYPE_VALUE (vfields); + + /* The simple right way to do this is to ensure that the context of + the base virtual function is found along the leftmost path + between the most derived type associated with the vfield and the + current type. */ + distance = get_base_distance (base, type, 0, &path); + if (distance == -1) + abort (); + while (path) + { + if (BINFO_TYPE (path) == base_context) + return 1; + path = BINFO_INHERITANCE_CHAIN (path); + } + + /* given: + Rr + / \ + Mm Hh + \ / + P + + make sure we fill in P's vtable for H with overrides of r, + but be cautious of virtual base classes. */ + /* Combine the two below after debugging. */ + if (get_base_distance (base_context, base, 0, &path) != -1) + { + while (path) + { + if (TREE_VIA_VIRTUAL (path)) + return 0; + path = BINFO_INHERITANCE_CHAIN (path); + } + /* Make sure that: + + RRB + | + RL RR + \ / + L R + \ / + C + + returns 0. VF_BASETYPE_VALUE is RL, base_context is RRB, type is C, + and the vfield we are checking is R. */ + if (VF_BASETYPE_VALUE (vfields) + && get_base_distance (base_context, VF_BASETYPE_VALUE (vfields), 0, &path) == -1 + && get_base_distance (VF_BASETYPE_VALUE (vfields), base_context, 0, &path) == -1) + return 0; + return 1; + } + return 0; +} + +static void modify_vtable_entries (); + +/* Access the virtual function table entry i. VIRTUALS is the virtual + function table's initializer. */ +static tree +get_vtable_entry_n (virtuals, i) + tree virtuals; + unsigned HOST_WIDE_INT i; +{ + while (i > 0) + { + virtuals = TREE_CHAIN (virtuals); + i -= 1; + } + return virtuals; +} + +#if 0 +/* Find the vfield (in the CLASSTYPE_VFIELDS chain) of the given binfo. */ +static tree +find_associated_vfield (binfo, t) + tree t, binfo; +{ + tree vfields; + tree save_vfields = 0; + for (vfields = CLASSTYPE_VFIELDS (t); vfields; vfields = TREE_CHAIN (vfields)) + { + if (VF_BINFO_VALUE (vfields) == binfo) + return vfields; + } + for (vfields = CLASSTYPE_VFIELDS (t); vfields; vfields = TREE_CHAIN (vfields)) + { + tree path; + get_base_distance (VF_BASETYPE_VALUE (vfields), t, 0, &path); + while (path) + { + if (path == binfo) + return vfields; + path = BINFO_INHERITANCE_CHAIN (path); + } + } + /* This is from a virtual base class's vtable, hopefully. */ + return 0; +} +#endif + + +/* Returns != 0 is the BINFO is the normal one for the main vfield, 0 + otherwise. We don't have to worry about the finding BINFO in + CLASSTYPE_VBASECLASSES, if it is virtual, as we never inherit + vtables from virtual base classes. */ +static int +is_normal (binfo, t) + tree t, binfo; +{ + tree binfo2; + int i = CLASSTYPE_VFIELD_PARENT (t); + if (i != -1) + { + tree base_binfo = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (t)), i); + if (base_binfo == binfo) + return 1; + } + return 0; +} + +/* Modify virtual function tables in lattice topped by T to place + FNDECL in tables which previously held BASE_FNDECL. This marches + through the vtables directly, looking for exact mactes to + modify. */ +static void +modify_other_vtable_entries (t, binfo, fndecl, base_fndecl, pfn) + tree t, binfo; + tree fndecl, base_fndecl, pfn; +{ + tree vfields, virtuals; + tree binfos; + int i, n_baselinks; + unsigned HOST_WIDE_INT n; + + virtuals = BINFO_VIRTUALS (binfo); + n = 0; + while (virtuals) + { + tree current_fndecl = TREE_VALUE (virtuals); + tree *binfo2_ptr; + current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl); + current_fndecl = TREE_OPERAND (current_fndecl, 0); + if (current_fndecl && SAME_FN (current_fndecl, base_fndecl)) + { + /* Most of the below was copied from + modify_vtable_entries (t, fndecl, base_fndecl, pfn); */ + tree base_offset, offset; + tree context = DECL_CLASS_CONTEXT (fndecl); + tree vfield = CLASSTYPE_VFIELD (t); + int normal = 1; + tree binfo2, this_offset; + tree base, path; + + offset = integer_zero_node; + if (context != t && TYPE_USES_COMPLEX_INHERITANCE (t)) + { + offset = virtual_offset (context, CLASSTYPE_VBASECLASSES (t), offset); + if (offset == NULL_TREE) + { + tree binfo = get_binfo (context, t, 0); + offset = BINFO_OFFSET (binfo); + } + } + + /* Get the path starting from the deepest base class CONTEXT + of T (i.e., first defn of BASE_FNDECL). */ + get_base_distance (binfo, t, 0, &path); + binfo2_ptr = 0; + + /* Get our best approximation of what to use for constructing + the virtual function table for T. */ + do + { + /* Walk from base toward derived, stopping at the + most derived baseclass that matters. That baseclass + is exactly the one which provides the vtable along + the VFIELD spine, but no more. */ + if (TREE_VIA_VIRTUAL (path)) + { + base = path; + binfo2 = binfo_member (BINFO_TYPE (base), CLASSTYPE_VBASECLASSES (t)); + /* This should never have TREE_USED set. */ + binfo2_ptr = 0; + break; + } + if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE + || (BINFO_TYPE (BINFO_BASETYPE (BINFO_INHERITANCE_CHAIN (path), 0)) + != BINFO_TYPE (path)) + || BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path)) == NULL_TREE) + { + base = path; + binfo2 = base; + binfo2_ptr = 0; + break; + } + path = BINFO_INHERITANCE_CHAIN (path); + binfo2_ptr = &BINFO_INHERITANCE_CHAIN (path); + } + while (1); + + /* Find the right offset for the this pointer based on the base + class we just found. */ + base_offset = BINFO_OFFSET (binfo2); + this_offset = size_binop (MINUS_EXPR, offset, base_offset); + + /* Make sure we can modify the derived association with immunity. */ + if (TREE_USED (binfo2)) { + my_friendly_assert (*binfo2_ptr == binfo2, 999); + *binfo2_ptr = copy_binfo (binfo2); + } + +#if 0 + vfields = find_associated_vfield (binfo2, t); + + /* We call this case NORMAL iff this virtual function table + pointer field has its storage reserved in this class. + This is normally the case without virtual baseclasses + or off-center multiple baseclasses. */ + normal = (vfields && vfield != NULL_TREE + && VF_BASETYPE_VALUE (vfields) == DECL_FCONTEXT (vfield) + && (VF_BINFO_VALUE (vfields) == NULL_TREE + || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))); + + if (normal && VF_BINFO_VALUE (vfields)) + /* Everything looks normal so far...check that we are really + working from VFIELD's basetype, and not some other appearance + of that basetype in the lattice. */ + normal = (VF_BINFO_VALUE (vfields) + == get_binfo (VF_BASETYPE_VALUE (vfields), t, 0)); +#else + normal = is_normal (binfo2, t); +#endif + + if (normal) + { + /* 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. */ + binfo2 = TYPE_BINFO (t); + if (! BINFO_NEW_VTABLE_MARKED (binfo2)) + 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 (binfo2)) + prepare_fresh_vtable (binfo2, base, t); + } + +#ifdef NOTQUITE + cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo2))); +#endif + modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo2), n), + build_vtable_entry (this_offset, pfn), + fndecl); + } else if (current_fndecl && DECL_NAME (current_fndecl) == DECL_NAME (base_fndecl)) + { +#ifdef NOTQUITE + cp_warning ("%D not replaced (looking for %D) in %D", DECL_ASSEMBLER_NAME (current_fndecl), DECL_ASSEMBLER_NAME (base_fndecl), DECL_NAME (BINFO_VTABLE (binfo))); +#endif + } + ++n; + virtuals = TREE_CHAIN (virtuals); + } + binfos = BINFO_BASETYPES (binfo); + n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; + for (i = 0; i < n_baselinks; i++) + { + tree base_binfo = TREE_VEC_ELT (binfos, i); + /* Don't modify virtual bases, as we share them down this way. */ + /* We hope that other places will get things down this direction. */ + if (TREE_VIA_VIRTUAL (base_binfo)) + continue; + modify_other_vtable_entries (t, base_binfo, fndecl, base_fndecl, pfn); + } +} + +/* Modify virtual function tables in lattice topped by T to + place FNDECL in tables which previously held BASE_FNDECL. + PFN is just FNDECL wrapped in an ADDR_EXPR, so that it + is suitable for placement directly into an initializer. + + All distinct virtual function tables that this type uses + must be updated. */ +static void +modify_vtable_entries (t, fndecl, base_fndecl, pfn) + tree t; + tree fndecl, base_fndecl, pfn; +{ + tree base_offset, offset; + tree base_context = DECL_CONTEXT (base_fndecl); + tree context = DECL_CLASS_CONTEXT (fndecl); + tree vfield = CLASSTYPE_VFIELD (t); + tree vfields, vbases; + tree saved_pfn; + +#ifdef NOTQUITE + cp_warning ("modifing all %D into %D for %T", base_fndecl, fndecl, t); + if (DECL_CONTEXT (fndecl) != DECL_CONTEXT (base_fndecl)) + { + cp_warning ("switching contexts from %T to %T for %x", + DECL_CONTEXT (fndecl), + DECL_CONTEXT (base_fndecl), fndecl); + cp_warning ("base was %D, new is %D", DECL_ASSEMBLER_NAME (base_fndecl), + DECL_ASSEMBLER_NAME(fndecl)); + } +#endif + DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl); + + offset = integer_zero_node; + if (context != t && TYPE_USES_COMPLEX_INHERITANCE (t)) + { + offset = virtual_offset (context, CLASSTYPE_VBASECLASSES (t), offset); + if (offset == NULL_TREE) + { + tree binfo = get_binfo (context, t, 0); + offset = BINFO_OFFSET (binfo); + } + } + + /* For each layer of base class (i.e., the first base class, and each + virtual base class from that one), modify the virtual function table + of the derived class to contain the new virtual function. + A class has as many vfields as it has virtual base classes (total). */ + for (vfields = CLASSTYPE_VFIELDS (t); vfields; vfields = TREE_CHAIN (vfields)) + { + int normal = 1; + tree binfo, this_offset; + tree base, path; + + if (!related_vslot (base_fndecl, vfields, t)) + continue; + + /* Find the right base class for this derived class, call it BASE. */ + base = VF_BASETYPE_VALUE (vfields); + + /* Get the path starting from the deepest base class CONTEXT + of T (i.e., first defn of BASE_FNDECL). */ + get_base_distance (DECL_CONTEXT (base_fndecl), t, 0, &path); + + /* Get our best approximation of what to use for constructing + the virtual function table for T. */ + do + { + /* Walk from base toward derived, stopping at the + most derived baseclass that matters. That baseclass + is exactly the one which provides the vtable along + the VFIELD spine, but no more. */ + if (TREE_VIA_VIRTUAL (path)) + { + base = path; + binfo = binfo_member (BINFO_TYPE (base), CLASSTYPE_VBASECLASSES (t)); + break; + } + if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE + || (BINFO_TYPE (BINFO_BASETYPE (BINFO_INHERITANCE_CHAIN (path), 0)) + != BINFO_TYPE (path)) + || BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path)) == NULL_TREE) + { + base = path; + binfo = base; + break; + } + path = BINFO_INHERITANCE_CHAIN (path); + } + while (1); + + /* Find the right offset for the this pointer based on the base + class we just found. */ + base_offset = 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 (TYPE_BINFO (t))) + TYPE_BINFO (t) = copy_binfo (TYPE_BINFO (t)); + + /* We call this case NORMAL iff this virtual function table + pointer field has its storage reserved in this class. + This is normally the case without virtual baseclasses + or off-center multiple baseclasses. */ + normal = (vfield != NULL_TREE + && VF_BASETYPE_VALUE (vfields) == DECL_FCONTEXT (vfield) + && (VF_BINFO_VALUE (vfields) == NULL_TREE + || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))); + + if (normal && VF_BINFO_VALUE (vfields)) + /* Everything looks normal so far...check that we are really + working from VFIELD's basetype, and not some other appearance + of that basetype in the lattice. */ + normal = (VF_BINFO_VALUE (vfields) + == get_binfo (VF_BASETYPE_VALUE (vfields), t, 0)); + + if (normal) + { + /* 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. */ + base_context = t; + binfo = TYPE_BINFO (t); + 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, base, t); + } + + saved_pfn = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (binfo), base_fndecl))), 0); +#ifdef NOTQUITE + cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo))); +#endif + /* The this_offset can be wrong, if we try and modify an entry + that had been modified once before. */ + if (! SAME_FN (saved_pfn, fndecl)) + { + modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (binfo), base_fndecl), + build_vtable_entry (this_offset, pfn), + fndecl); + modify_other_vtable_entries (t, TYPE_BINFO (t), fndecl, saved_pfn, pfn); + } + } + for (vbases = CLASSTYPE_VBASECLASSES (t); vbases; vbases = TREE_CHAIN (vbases)) + { + tree this_offset; + tree base, path; + + if (! BINFO_VTABLE (vbases)) + /* There are only two ways that a type can fail to have + virtual functions: neither it nor any of its base + types define virtual functions (in which case + no updating need be done), or virtual functions + accessible to it come from virtual base classes + (in which case we have or will get them modified + in other passes of this loop). */ + continue; + + base = BINFO_TYPE (vbases); + path = NULL_TREE; + + if (base != base_context + && get_base_distance (base_context, base, 0, &path) == -1) + continue; + + if (path) + this_offset = size_binop (MINUS_EXPR, offset, BINFO_OFFSET (path)); + else + this_offset = offset; + + /* Doesn't matter if not actually from this virtual base class, + but shouldn't come from deeper virtual baseclasses. The enclosing + loop should take care of such baseclasses. */ + while (path) + { + if (TREE_VIA_VIRTUAL (path)) + goto skip; + path = BINFO_INHERITANCE_CHAIN (path); + } + + base_offset = BINFO_OFFSET (vbases); + this_offset = size_binop (MINUS_EXPR, this_offset, base_offset); + + /* Make sure we can modify the derived association with immunity. */ + if (TREE_USED (TYPE_BINFO (t))) + TYPE_BINFO (t) = copy_binfo (TYPE_BINFO (t)); + + /* This is our very own copy of `basetype' to play with. */ + if (! BINFO_NEW_VTABLE_MARKED (vbases)) + { + tree context_binfo = binfo_value (base_context, base); + prepare_fresh_vtable (vbases, context_binfo, t); + } + saved_pfn = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (vbases), base_fndecl))), 0); +#ifdef NOTQUITE + cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (vbases))); +#endif + /* The this_offset can be wrong, if we try and modify an entry + that had been modified once before. */ + if (! SAME_FN (saved_pfn, fndecl)) + { + modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (vbases), + base_fndecl), + build_vtable_entry (this_offset, pfn), + fndecl); + modify_other_vtable_entries (t, TYPE_BINFO (t), fndecl, saved_pfn, pfn); + } + skip: {} + } +} + +static tree +add_virtual_function (pending_virtuals, has_virtual, x, t) + tree pending_virtuals; + int *has_virtual; + tree x; + tree t; /* Structure type. */ +{ + int debug_vbase = 1; + + /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely + convert to void *. Make such a conversion here. */ + tree vfn = build1 (ADDR_EXPR, ptr_type_node, x); + TREE_CONSTANT (vfn) = 1; + + /* current_class_type may be NULL_TREE in case of error. */ + if (current_class_type) + TREE_ADDRESSABLE (x) = CLASSTYPE_VTABLE_NEEDS_WRITING (current_class_type); + + /* 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 (x) == error_mark_node) + { + tree entry = build_vtable_entry (integer_zero_node, vfn); + + if (flag_dossier && *has_virtual == 0) + { + /* CLASSTYPE_DOSSIER is only used as a Boolean (NULL or not). */ + CLASSTYPE_DOSSIER (t) = integer_one_node; + *has_virtual = 1; + } + + /* Build a new INT_CST for this DECL_VINDEX. */ +#ifdef VTABLE_USES_MASK + SET_DECL_VINDEX (x, build_int_2 (++(*has_virtual), 0)); +#else + { + static tree index_table[256]; + tree index; + 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]; + + DECL_VINDEX (x) = index; + } +#endif + pending_virtuals = tree_cons (DECL_VINDEX (x), entry, pending_virtuals); + } + /* Happens if declared twice in class or we're not in a class definition. + We will give error later or we've already given it. */ + else if (TREE_CODE (DECL_VINDEX (x)) == INTEGER_CST + || current_class_type == NULL_TREE) + return pending_virtuals; + else if (debug_vbase && TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + { + /* 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 (x, vfn, pending_hard_virtuals); + } + else + { + /* Need an entry in some other virtual function table. + We can do this now. */ + tree base_fndecl_list = DECL_VINDEX (x), base_fndecls, prev = 0; + tree vtable_context = DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type)); + tree true_base_fndecl = 0; + + /* First assign DECL_VINDEX from the base vfn with which + we share our vtable. */ + base_fndecls = base_fndecl_list; + while (base_fndecls) + { + if (TREE_CHAIN (base_fndecls) == NULL_TREE + || DECL_FCONTEXT (CLASSTYPE_VFIELD (DECL_CLASS_CONTEXT (TREE_VALUE (base_fndecls)))) == vtable_context) + { + true_base_fndecl = TREE_VALUE (base_fndecls); + modify_vtable_entries (current_class_type, x, + true_base_fndecl, vfn); + if (prev) + TREE_CHAIN (prev) = TREE_CHAIN (base_fndecls); + else + base_fndecl_list = prev; + break; + } + prev = base_fndecls; + base_fndecls = TREE_CHAIN (base_fndecls); + } + + /* Now fill in the rest of the vtables. */ + base_fndecls = base_fndecl_list; + while (base_fndecls) + { + /* If we haven't found one we like, first one wins. */ + if (true_base_fndecl == 0) + true_base_fndecl = TREE_VALUE (base_fndecls); + + modify_vtable_entries (current_class_type, x, + TREE_VALUE (base_fndecls), vfn); + base_fndecls = TREE_CHAIN (base_fndecls); + } + + DECL_CONTEXT (x) = DECL_CONTEXT (true_base_fndecl); + } + 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 (method_vec, 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, field_ptr, fields) + tree field, *field_ptr, fields; +{ + tree x; + tree prev = field_ptr ? *field_ptr : 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, field_ptr, fields); + if (prev) + TREE_CHAIN (prev) = 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, (tree *)0, 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 class scope 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, &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) && access != access_private) + cp_error_at ("cannot make private `%D' non-private", fdecl); + else if (TREE_PROTECTED (fdecl)) + { + if (access == access_public) + cp_error_at ("cannot make protected `%D' public", 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 (TREE_PUBLIC (fdecl) + && (access == access_private + || access == access_protected)) + 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; +} + +static tree +get_vfield_offset (binfo) + tree binfo; +{ + return size_binop (PLUS_EXPR, + DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))), + BINFO_OFFSET (binfo)); +} + +/* 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 (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_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_NEEDS_CONSTRUCTING (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), + BINFO_TYPE (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); + } + + /* 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; + + 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; + 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 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 has_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0; + tree binfos = TYPE_BINFO_BASETYPES (t); + for (i = n_baseclasses-1; i >= 0; i--) + { + has_abstract_virtuals + |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0); + if (has_abstract_virtuals) + break; + } + if (has_abstract_virtuals) + 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; + } + } + + /* Need to test METHOD_VEC here in case all methods + (conversions and otherwise) are inherited. */ + if (TYPE_HAS_CONVERSION (t) && method_vec != NULL_TREE) + { + tree first_conversions[last_conversion_type]; + tree last_conversions[last_conversion_type]; + enum conversion_type conv_index; + tree *tmp; + int i; + + bzero (first_conversions, sizeof (first_conversions)); + bzero (last_conversions, sizeof (last_conversions)); + for (tmp = &TREE_VEC_ELT (method_vec, 1); + tmp != TREE_VEC_END (method_vec); tmp += 1) + { + /* ??? This should compare DECL_NAME (*tmp) == ansi_opname[TYPE_EXPR]. */ + if (IDENTIFIER_TYPENAME_P (DECL_ASSEMBLER_NAME (*tmp))) + { + tree fntype = TREE_TYPE (*tmp); + tree return_type = TREE_TYPE (fntype); + my_friendly_assert (TREE_CODE (fntype) == METHOD_TYPE, 171); + + if (typecode_p (return_type, POINTER_TYPE)) + { + if (TYPE_READONLY (TREE_TYPE (return_type))) + conv_index = constptr_conv; + else + conv_index = ptr_conv; + } + else if (typecode_p (return_type, INTEGER_TYPE)) + { + TYPE_HAS_INT_CONVERSION (t) = 1; + conv_index = int_conv; + } + else if (typecode_p (return_type, REAL_TYPE)) + { + TYPE_HAS_REAL_CONVERSION (t) = 1; + conv_index = real_conv; + } + else + continue; + + if (first_conversions[(int) conv_index] == NULL_TREE) + first_conversions[(int) conv_index] = *tmp; + last_conversions[(int) conv_index] = *tmp; + } + } + + for (i = 0; i < (int) last_conversion_type; i++) + if (first_conversions[i] != last_conversions[i]) + CLASSTYPE_CONVERSION (t, i) = error_mark_node; + else + CLASSTYPE_CONVERSION (t, i) = first_conversions[i]; + } + + /* If this type has constructors, force its mode to be BLKmode, + and force its TREE_ADDRESSABLE bit to be nonzero. */ + if (TYPE_NEEDS_CONSTRUCTING (t) || TYPE_NEEDS_DESTRUCTOR (t)) + { + tree variants = t; + + if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL) + DECL_MODE (TYPE_NAME (t)) = BLKmode; + while (variants) + { + TYPE_MODE (variants) = BLKmode; + TREE_ADDRESSABLE (variants) = 1; + variants = TYPE_NEXT_VARIANT (variants); + } + } +} + +/* 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 TREE_CHAIN of the FUNCTION_DECLs. Friends are + chained in the same way as member functions, 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 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)); + + while (fn_fields) + { + /* NEXT Pointer, TEST Pointer, and BASE Pointer. */ + tree nextp, *testp; + 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; + + /* 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; + } + } + } + else if (fn_name == ansi_opname[(int) MODIFY_EXPR]) + { + tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields)); + + if (TREE_CODE (parmtype) == REFERENCE_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t) + { + 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; + } + } + + /* Constructors are handled easily in search routines. + Besides, we know we won't find any, so do not bother looking. */ + if (fn_name == name && TREE_VEC_ELT (method_vec, 0) == 0) + TREE_VEC_ELT (method_vec, 0) = fn_fields; + else + { + 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) != fn_name) + 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_fields) == ansi_opname[(int) DELETE_EXPR]) + { + /* ANSI C++ June 5 1992 WP 12.5.5.1 */ + cp_error_at ("`%D' overloaded", fn_fields); + cp_error_at ("previous declaration as `%D' here", x); + } + if (DECL_ASSEMBLER_NAME (fn_fields)==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_fields))) + cp_error_at ("ambiguous method `%#D' in structure", + fn_fields); + break; + } + prev_x = x; + } + if (x == 0) + { + if (*testp) + DECL_CHAIN (prev_x) = fn_fields; + else + *testp = fn_fields; + } + } + else + { + obstack_ptr_grow (&class_obstack, fn_fields); + method_vec = (tree)obstack_base (&class_obstack); + } + } + 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) + warning ("class `%s' only defines a private destructor and has no friends", + TYPE_NAME_STRING (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; + } + } + +#if 0 + TYPE_METHODS (t) = TREE_VEC_ELT (method_vec, 0) + ? TREE_VEC_ELT (method_vec, 0) : TREE_VEC_ELT (method_vec, 1); +#else + TYPE_METHODS (t) = method_vec; +#endif + + 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); + + /* 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 (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; +} + +/* 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 (t, list_of_fieldlists, warn_anon) + tree t; + tree list_of_fieldlists; + int warn_anon; +{ + extern int interface_only, interface_unknown; + extern tree EHS_type; + + int old; + int round_up_size = 1; + + enum tree_code code = TREE_CODE (t); + register tree x, last_x, method_vec; + int needs_virtual_dtor; + tree name = TYPE_NAME (t), fields, fn_fields, tail; + enum access_type access; + 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 do_mem_init = 0; + int nonprivate_method = 0; + tree t_binfo = TYPE_BINFO (t); + tree access_decls = 0; + + if (TREE_CODE (name) == TYPE_DECL) + { +#if 0 /* Maybe later. -jason */ + struct tinst_level *til = tinst_for_decl(); + + if (til) + { + DECL_SOURCE_FILE (name) = til->file; + if (DECL_SOURCE_LINE (name)) + DECL_SOURCE_LINE (name) = til->line; + } + else +#endif + { + 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; + } + name = DECL_NAME (name); + } + + if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (name)) + warning ("anonymous class type not used to declare any objects"); + +#if 0 + /* This is set here, but it's never actually used anywhere. (bpk) */ + leftmost_baseclasses = NULL_TREE; +#endif + if (TYPE_SIZE (t)) + { + if (IS_AGGR_TYPE (t)) + cp_error ("redefinition of `%#T'", t); + else + my_friendly_abort (172); + popclass (0); + return t; + } + + /* Append the fields we need for constructing signature tables. */ + if (IS_SIGNATURE (t)) + append_signature_fields (list_of_fieldlists); + + 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) = 0; + CLASSTYPE_GOT_SEMICOLON (t) = 0; + + /* A signature type will contain the fields of the signature table. + Therefore, it's not only an interface. */ + if (IS_SIGNATURE (t)) + { + CLASSTYPE_INTERFACE_ONLY (t) = 0; + SET_CLASSTYPE_INTERFACE_KNOWN (t); + } + else + { + CLASSTYPE_INTERFACE_ONLY (t) = interface_only; + SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); + } + + if (flag_dossier) + build_t_desc (t, 0); + + 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). */ + fields = layout_basetypes (t, BINFO_BASETYPES (t_binfo)); + last_x = tree_last (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)); + } + else + { + first_vfn_base_index = -1; + has_virtual = 0; + max_has_virtual = has_virtual; + vfield = NULL_TREE; + vfields = NULL_TREE; + fields = 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 (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t) + && current_lang_name == lang_name_cplusplus && ! IS_SIGNATURE (t)) + { + CLASSTYPE_INTERFACE_ONLY (t) = interface_only; + CLASSTYPE_VTABLE_NEEDS_WRITING (t) = ! interface_only; + } + else if (IS_SIGNATURE (t)) + CLASSTYPE_VTABLE_NEEDS_WRITING (t) = 0; + + /* 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; + + fn_fields = NULL_TREE; + tail = NULL_TREE; + if (last_x && list_of_fieldlists) + TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists); + + 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 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) + { + nonprivate_method = 1; + 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; + GNU_xref_member (current_class_name, x); + + if (TREE_CODE (x) == TYPE_DECL) + { + /* Make sure we set this up. In find_scoped_type, it explicitly + looks for a TYPE_DECL in the TYPE_FIELDS list. If we don't + do this here, we'll miss including this TYPE_DECL in the + list. */ + if (! fields) + fields = x; + last_x = x; + DECL_CONTEXT (x) = t; + continue; + } + + + if (TREE_CODE (x) == FUNCTION_DECL) + { + 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; + + if (last_x) + TREE_CHAIN (last_x) = TREE_CHAIN (x); + if (! fn_fields) + fn_fields = x; + else + TREE_CHAIN (tail) = x; + tail = x; + +#if 0 + /* ??? What if we have duplicate declarations + in T's definition? */ + if (DECL_CLASS_CONTEXT (x)) + continue; +#endif + DECL_CLASS_CONTEXT (x) = t; + + 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); + } + continue; + } + + /* Handle access declarations. */ + if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF) + { + tree fdecl = TREE_OPERAND (DECL_NAME (x), 1); + + if (last_x) + TREE_CHAIN (last_x) = TREE_CHAIN (x); + access_decls = tree_cons ((tree) access, fdecl, access_decls); + 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 (TREE_TYPE (x) == error_mark_node) + continue; + + if (! fields) + fields = x; + last_x = x; + + 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 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] is the only + way to initialize a nonstatic const and reference + [member]. */ + cant_synth_asn_ref = 1; + cant_have_default_ctor = 1; + TYPE_HAS_COMPLEX_INIT_REF (t) = 1; + + if (! TYPE_HAS_CONSTRUCTOR (t)) + { + if (DECL_NAME (x)) + cp_pedwarn_at ("non-static reference `%#D' in class without a constructor", x); + else + cp_pedwarn_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] is the only + way to initialize a nonstatic const and reference + [member]. */ + cant_synth_asn_ref = 1; + cant_have_default_ctor = 1; + TYPE_HAS_COMPLEX_INIT_REF (t) = 1; + + if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)) + { + if (DECL_NAME (x)) + cp_pedwarn_at ("non-static const member `%#D' in class without a constructor", x); + else + cp_pedwarn_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) + && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE + && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) + { + cp_error_at ("bit-field `%D' has invalid 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 ((unsigned)width > TYPE_PRECISION (TREE_TYPE (x))) + { + DECL_INITIAL (x) = NULL; + cp_error_at ("width of `%D' exceeds its 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)) + { + /* 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 = 0; + 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) + || TYPE_NEEDS_CONSTRUCTING (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 (! 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); + } + } + } + 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; + } + } + } + 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); + } + } + + if (tail) TREE_CHAIN (tail) = NULL_TREE; + + /* 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; + + 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, fields, + 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 + { + if (! fn_fields) + fn_fields = dtor; + else + TREE_CHAIN (tail) = dtor; + tail = dtor; + + if (DECL_VINDEX (dtor) == NULL_TREE + && ! CLASSTYPE_DECLARED_EXCEPTION (t) + && (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, NULL_TREE); + nonprivate_method = 1; + } + } + + TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t); + + /* Synthesize any needed methods. Note that methods will be synthesized + for anonymous unions; grok_x_components undoes that. */ + + if (! fn_fields) + nonprivate_method = 1; + + TYPE_HAS_COMPLEX_INIT_REF (t) + |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) + || has_virtual || any_default_members || first_vfn_base_index >= 0); + TYPE_NEEDS_CONSTRUCTING (t) + |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) + || has_virtual || any_default_members || first_vfn_base_index >= 0); + + /* 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) + { + tree default_fn = cons_up_default_function (t, name, fields, 2); + TREE_CHAIN (default_fn) = fn_fields; + fn_fields = default_fn; + } + + /* Create default copy constructor, if needed. Don't do it for + the exception handler. */ + if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor && t != EHS_type) + { + /* 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, fields, + cant_have_const_ctor ? 4 : 3); + 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) + || has_virtual || first_vfn_base_index >= 0); + + if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref) + { + tree default_fn = + cons_up_default_function (t, name, fields, + no_const_asn_ref ? 6 : 5); + 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_DECLARED_EXCEPTION (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 = TREE_VEC_LENGTH (method_vec); + + 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 = 0; + 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 = 0; + 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 = 0; + 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_FIELD_SIZE (vfield) = 0; + DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node); + if (CLASSTYPE_DOSSIER (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) == 0, 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); + + /* 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. */ + + { + 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) == 0 + && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + { + tree uelt = TYPE_FIELDS (TREE_TYPE (field)); + for (; uelt; uelt = TREE_CHAIN (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) + { + 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) = 0; + } + + 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) == 0 + && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + { + tree uelt = TYPE_FIELDS (TREE_TYPE (field)); + for (; uelt; uelt = TREE_CHAIN (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); + + while (vbases) + { + /* Update dossier info with offsets for virtual baseclasses. */ + if (flag_dossier && ! BINFO_NEW_VTABLE_MARKED (vbases)) + prepare_fresh_vtable (vbases, vbases, t); + + vbases = TREE_CHAIN (vbases); + } + } + +#ifdef NOTQUITE + cp_warning ("Doing hard virtuals for %T...", t); +#endif + while (pending_hard_virtuals) + { + /* Need an entry in some other virtual function table. */ + if (TREE_TYPE (pending_hard_virtuals)) + { + /* This is how we modify entries when a vfn's index changes + between derived and base type. */ + modify_vtable_entries (t, TREE_PURPOSE (pending_hard_virtuals), + TREE_TYPE (pending_hard_virtuals), + TREE_VALUE (pending_hard_virtuals)); + } + else + { + /* This is how we modify entries when a vfn comes from + a virtual baseclass. */ + tree base_fndecls = DECL_VINDEX (TREE_PURPOSE (pending_hard_virtuals)); + /* Only do this, if it was missed before. */ + if (TREE_CODE (base_fndecls) != INTEGER_CST) + { + my_friendly_assert (base_fndecls != error_mark_node, 176); + while (base_fndecls) + { + modify_vtable_entries (t, TREE_PURPOSE (pending_hard_virtuals), + TREE_VALUE (base_fndecls), + TREE_VALUE (pending_hard_virtuals)); + modify_other_vtable_entries (t, TYPE_BINFO (t), + TREE_PURPOSE (pending_hard_virtuals), + TREE_VALUE (base_fndecls), + TREE_VALUE (pending_hard_virtuals)); + base_fndecls = TREE_CHAIN (base_fndecls); + } + } else { +#ifdef NOTQUITE + cp_warning ("missed bases for `%D'", TREE_PURPOSE (pending_hard_virtuals)); +#endif + } + } + pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals); + } + + if (TYPE_USES_VIRTUAL_BASECLASSES (t)) + { + tree vbases; + + vbases = CLASSTYPE_VBASECLASSES (t); + CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases); + + /* This loop makes all the entries in the virtual function tables + of interest contain the "latest" version of the functions + we have defined. */ + + while (vbases) + { + tree virtuals = BINFO_VIRTUALS (vbases); + + if (virtuals) + { + /* Get past the `null' vtable entry... */ + virtuals = TREE_CHAIN (virtuals); + /* and the `dossier' vtable entry if we're doing dossiers. */ + if (flag_dossier) + virtuals = TREE_CHAIN (virtuals); + } + + while (virtuals != NULL_TREE) + { + tree pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)); + tree base_fndecl = TREE_OPERAND (pfn, 0); + tree decl = get_first_matching_virtual (TYPE_BINFO (t), base_fndecl, + DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))); + tree context = DECL_CLASS_CONTEXT (decl); + if (! SAME_FN (decl, base_fndecl)) + { + tree base_context = DECL_CLASS_CONTEXT (base_fndecl); + tree binfo = NULL_TREE, these_virtuals; +#if 0 + unsigned HOST_WIDE_INT i + = (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)) + & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1)); +#endif + + if (TYPE_USES_VIRTUAL_BASECLASSES (context)) + binfo = virtual_member (base_context, + CLASSTYPE_VBASECLASSES (context)); + if (binfo == NULL_TREE) + binfo = binfo_value (base_context, context); + if (binfo != NULL_TREE) + { +#if 1 + pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (binfo), base_fndecl))); +#else + these_virtuals = BINFO_VIRTUALS (binfo); + + while (i-- > 0) + these_virtuals = TREE_CHAIN (these_virtuals); + pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (these_virtuals)); +#endif + pfn = build1 (ADDR_EXPR, ptr_type_node, decl); + TREE_CONSTANT (pfn) = 1; + modify_vtable_entries (t, decl, base_fndecl, pfn); + } + } + virtuals = TREE_CHAIN (virtuals); + } + + vbases = TREE_CHAIN (vbases); + } + } + doing_hard_virtuals = 0; + + /* Under our model of GC, every C++ class gets its own virtual + function table, at least virtually. */ + if (pending_virtuals || CLASSTYPE_DOSSIER (t)) + { + pending_virtuals = nreverse (pending_virtuals); + /* We must enter these virtuals into the table. */ + if (first_vfn_base_index < 0) + { + if (flag_dossier) + pending_virtuals = tree_cons (NULL_TREE, + build_vtable_entry (integer_zero_node, + build_t_desc (t, 0)), + pending_virtuals); + pending_virtuals = tree_cons (NULL_TREE, the_null_vtable_entry, + pending_virtuals); + build_vtable (NULL_TREE, t); + } + else + { + /* 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); + + /* Update the dossier pointer for this class. */ + if (flag_dossier) + TREE_VALUE (TREE_CHAIN (TYPE_BINFO_VIRTUALS (t))) + = build_vtable_entry (integer_zero_node, build_t_desc (t, 0)); + } + + /* 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); +#if 0 + /* For testing. */ + tree binfo1 = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0); + if (binfo != binfo1) + warning ("binfos are different in vtable creation"); +#endif + + /* 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 (has_virtual > max_has_virtual) + max_has_virtual = has_virtual; + if (max_has_virtual || first_vfn_base_index >= 0) + { +#ifdef VTABLE_USES_MASK + if (max_has_virtual >= VINDEX_MAX) + { + cp_error ("too many virtual functions for `%#T' (VINDEX_MAX < %d)", + t, has_virtual); + } +#endif + TYPE_VIRTUAL_P (t) = 1; + 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; + 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); + + /* Promote each bit-field's type to int if it is narrower than that. + There's more: complete the rtl for any static member objects which + is of the same type we're working on. */ + for (x = fields; 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 (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 = build_lang_decl (TYPE_DECL, TREE_PURPOSE (x), TREE_VALUE (x)); +#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 */ + DECL_CONTEXT (tag) = t; + DECL_CLASS_CONTEXT (tag) = t; + x = TREE_CHAIN (x); + last_x = chainon (last_x, tag); + } + if (TYPE_FIELDS (t) == 0) + 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 (current_lang_name == lang_name_cplusplus) + { + if (! CLASSTYPE_DECLARED_EXCEPTION (t) + && ! 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 ((flag_this_is_variable & 1) == 0) + { + tree vtbl_ptr = build_decl (VAR_DECL, get_identifier (VPTR_NAME), + TREE_TYPE (vfield)); + DECL_REGISTER (vtbl_ptr) = 1; + CLASSTYPE_VTBL_PTR (t) = vtbl_ptr; + } + 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; + } + + /* 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. */ + unmark_finished_struct (t); + TYPE_BEING_DEFINED (t) = 0; + + if (flag_dossier && CLASSTYPE_VTABLE_NEEDS_WRITING (t)) + { + tree variants; + tree tdecl; + + /* Now instantiate its type descriptors. */ + tdecl = TREE_OPERAND (build_t_desc (t, 1), 0); + variants = TYPE_POINTER_TO (t); + build_type_variant (variants, 1, 0); + while (variants) + { + build_t_desc (variants, 1); + variants = TYPE_NEXT_VARIANT (variants); + } + variants = build_reference_type (t); + build_type_variant (variants, 1, 0); + while (variants) + { + build_t_desc (variants, 1); + variants = TYPE_NEXT_VARIANT (variants); + } +#if 0 + DECL_VPARENT (tdecl) = t; +#endif + DECL_CONTEXT (tdecl) = t; + } + /* Still need to instantiate this C struct's type descriptor. */ + else if (flag_dossier && ! CLASSTYPE_DOSSIER (t)) + build_t_desc (t, 1); + + if (TYPE_NAME (t) && TYPE_IDENTIFIER (t)) + undo_template_name_overload (TYPE_IDENTIFIER (t), 1); + if (current_class_type) + popclass (0); + else + error ("trying to finish struct, but kicked out due to previous parse errors."); + + hack_incomplete_structures (t); + + 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) + DECL_IGNORED_P (TYPE_NAME (t)) + = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0); + else if (CLASSTYPE_INTERFACE_ONLY (t)) + DECL_IGNORED_P (TYPE_NAME (t)) = 1; + else if (CLASSTYPE_INTERFACE_UNKNOWN (t)) + /* Only a first approximation! */ + DECL_IGNORED_P (TYPE_NAME (t)) = 1; + } + else if (CLASSTYPE_INTERFACE_ONLY (t)) + DECL_IGNORED_P (TYPE_NAME (t)) = 1; + } + + /* Finish debugging output for this type. */ + rest_of_type_compilation (t, global_bindings_p ()); + + return t; +} + +/* 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 (); + overload_template_name (current_class_name, 0); + } + 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, our cacheing was successful, 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); + } + + 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. */ +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 (TREE_CODE (current_class_type) == UNINSTANTIATED_P_TYPE) + undo_template_name_overload (current_class_name, 0); + + poplevel_class (); + + /* 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; + + if (current_class_type) + { + if (CLASSTYPE_VTBL_PTR (current_class_type)) + { + current_vtable_decl = lookup_name (DECL_NAME (CLASSTYPE_VTBL_PTR (current_class_type)), 0); + if (current_vtable_decl) + current_vtable_decl = build_indirect_ref (current_vtable_decl, + NULL_PTR); + } + current_class_decl = lookup_name (this_identifier, 0); + if (current_class_decl) + { + if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE) + { + tree temp; + /* Can't call build_indirect_ref here, because it has special + logic to return C_C_D given this argument. */ + C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl); + temp = TREE_TYPE (TREE_TYPE (current_class_decl)); + TREE_READONLY (C_C_D) = TYPE_READONLY (temp); + TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (temp); + TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (temp); + } + else + C_C_D = current_class_decl; + } + else + C_C_D = NULL_TREE; + } + else + { + current_class_decl = NULL_TREE; + current_vtable_decl = NULL_TREE; + C_C_D = NULL_TREE; + } + + 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 = 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 = TREE_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 = TREE_CHAIN (field); + if (field) + { + TREE_OPERAND (rhs, 1) = field; + field = TREE_CHAIN (field); + while (field && ! comptypes (lhstype, TREE_TYPE (field), 0)) + field = TREE_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 (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 (TREE_TYPE (elem) != lhstype) + elem = DECL_CHAIN (elem); + else + return elem; + /* No exact match found, look for a compatible function. */ + elem = get_first_fn (rhs); + while (elem && ! comp_target_types (lhstype, TREE_TYPE (elem), 1)) + elem = DECL_CHAIN (elem); + if (elem) + { + tree save_elem = elem; + elem = DECL_CHAIN (elem); + while (elem && ! comp_target_types (lhstype, TREE_TYPE (elem), + 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; + } + if (TREE_CODE (save_elem) == TEMPLATE_DECL) + { + int ntparms = TREE_VEC_LENGTH + (DECL_TEMPLATE_PARMS (save_elem)); + tree *targs = (tree *) alloca (sizeof (tree) * ntparms); + int i, dummy; + i = type_unification + (DECL_TEMPLATE_PARMS (save_elem), targs, + TYPE_ARG_TYPES (TREE_TYPE (save_elem)), + TYPE_ARG_TYPES (lhstype), &dummy, 0); + save_elem = instantiate_template (save_elem, targs); + } + return save_elem; + } + if (complain) + { + cp_error ("cannot resolve overload to target type `%#T';", + lhstype); + cp_error ("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 (TREE_TYPE (elem) != lhstype) + elem = TREE_CHAIN (elem); + else + return 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)) + elem = TREE_CHAIN (elem); + if (elem) + { + tree save_elem = elem; + elem = TREE_CHAIN (elem); + while (elem && ! comp_target_types (lhstype, TREE_TYPE (elem), 0)) + elem = TREE_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 (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0) + { + /* Try to instantiate from non-member functions. */ + rhs = IDENTIFIER_GLOBAL_VALUE (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); + } + } + } + if (complain) + error ("no static member functions named `%s'", + IDENTIFIER_POINTER (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 ("illegal 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 (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_OPERAND (rhs, 0) = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); + if (TREE_OPERAND (rhs, 0) == error_mark_node) + return error_mark_node; + + mark_addressable (TREE_OPERAND (rhs, 0)); + 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/gcc/cp/class.h b/gcc/cp/class.h new file mode 100644 index 00000000000..fb25a5f56b4 --- /dev/null +++ b/gcc/cp/class.h @@ -0,0 +1,161 @@ +/* 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, 675 Mass Ave, Cambridge, MA 02139, 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. + + If two candidates have a non-monotonic derived/base pointer + relationship, and/or a non-monotonic easy conversion relationship, + then a warning is emitted to show which paths are possible, and + which one is being chosen. + + For example: + + int i; + double x; + + overload f; + int f (int, int); + double f (double, double); + + f (i, x); // draws a warning + + struct B + { + f (int); + } *bb; + struct D : B + { + f (double); + } *dd; + + dd->f (x); // exact match + dd->f (i); // draws warning + + 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 +{ + /* OLD METHOD */ + unsigned char evil; /* !0 if this will never convert. */ + unsigned char ellipsis; /* !0 if a match against an ellipsis occurred */ + unsigned char user; /* !0 if at least one user-defined type conv. */ + unsigned short b_or_d; /* count number of derived->base or + base->derived conv. */ + unsigned short easy; /* count number of builtin type conv. */ + + /* NEW METHOD */ + struct harshness_code h; /* Used for single-argument conversions. */ + + int h_len; /* The length of the harshness vector. */ + + /* Both methods. */ + tree function; /* A FUNCTION_DECL */ + tree basetypes; /* The path to function. */ + tree arg; /* first parm to function. */ + + /* This union is only here while we maintain both the old and new + argument matching schemes. When it goes away, all v.ansi_harshness + references will be just `harshness'. */ + union + { + /* 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 *ansi_harshness; /* NEW METHOD */ + unsigned short *old_harshness; /* OLD METHOD */ + } v; + + 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 cp-class.c and cp-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/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def new file mode 100644 index 00000000000..dc4bbdad085 --- /dev/null +++ b/gcc/cp/cp-tree.def @@ -0,0 +1,92 @@ +/* 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, 675 Mass Ave, Cambridge, MA 02139, 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) + +/* 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) + +/* Distinguish variables that are only used to identify exceptions + that were caught. Only the DECL_NAME (and TREE_CHAIN) + is really used. */ +DEFTREECODE (CPLUS_CATCH_DECL, "catch_decl", "d", 0) + +/* 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) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h new file mode 100644 index 00000000000..b431e160a6b --- /dev/null +++ b/gcc/cp/cp-tree.h @@ -0,0 +1,2228 @@ +/* Definitions for C++ parsing and type checking. + Copyright (C) 1987, 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, 675 Mass Ave, Cambridge, MA 02139, 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 IDENTIFIER_HAS_CLASS_TYPE_VALUE(NODE) \ + (IDENTIFIER_CLASS_VALUE (NODE) && TREE_TYPE (IDENTIFIER_CLASS_VALUE (NODE))) +#define IDENTIFIER_CLASS_TYPE_VALUE(NODE) \ + TREE_TYPE (IDENTIFIER_CLASS_VALUE (NODE)) + +#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) + +/* 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; + +/* 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 recognize and handle exception handling constructs. */ + +extern int flag_handle_exceptions; + +/* Nonzero means recognize and handle ansi-style exception handling constructs. */ + +extern int flag_ansi_exceptions; + +/* Nonzero means do argument matching for overloading according to the + ANSI rules, rather than what g++ used to believe to be correct. */ + +extern int flag_ansi_overloading; + +/* 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)))) + +#define IS_AGGR_TYPE(t) (TYPE_LANG_FLAG_5 (t)) +#define IS_AGGR_TYPE_CODE(t) (t == RECORD_TYPE || t == UNION_TYPE) +#define IS_AGGR_TYPE_2(TYPE1,TYPE2) \ + (TREE_CODE (TYPE1) == TREE_CODE (TYPE2) \ + && IS_AGGR_TYPE (TYPE1)&IS_AGGR_TYPE (TYPE2)) + +/* 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. */ + +#if 1 +/* Virtual function addresses can be gotten from a virtual function + table entry using this macro. */ +#define FNADDR_FROM_VTABLE_ENTRY(ENTRY) \ + TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (ENTRY)))) +#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) + +enum conversion_type { ptr_conv, constptr_conv, int_conv, + real_conv, last_conversion_type }; + +/* 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 : 1; + unsigned gets_placed_new : 1; + unsigned gets_delete : 1; + 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 declared_exception : 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; + + /* 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 : 22; + + 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 *vtbl_ptr; + union tree_node *instance_variable; + union tree_node *friend_classes; + + char *mi_matrix; + union tree_node *conversions[last_conversion_type]; + + union tree_node *dossier; + + union tree_node *signature; + union tree_node *signature_pointer_to; + union tree_node *signature_reference_to; +}; + +/* Indicates whether a template should be (or has been) expanded for this + class definition. 0=do, 1=did, 2=don't, 3=didn't. */ +#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 TREE_GETS_NEW(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_new) +#define TREE_GETS_PLACED_NEW(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_placed_new) +#define TREE_GETS_DELETE(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.gets_delete) + +/* 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 dossier. */ +#define CLASSTYPE_DOSSIER(NODE) (TYPE_LANG_SPECIFIC(NODE)->dossier) + +/* 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) + +/* 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) + +/* Slot in which to cache a copy of the local vtable pointer. */ +#define CLASSTYPE_VTBL_PTR(NODE) (TYPE_LANG_SPECIFIC(NODE)->vtbl_ptr) + +/* Hold the instance object associated with this method. */ +#define CLASSTYPE_INST_VAR(NODE) (TYPE_LANG_SPECIFIC(NODE)->instance_variable) + +/* 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) + +/* If there is exactly one conversion to a non-void, non-const pointer type, + remember that here. If there are more than one, put + `error_mark_node' here. If there are none, this holds NULL_TREE. */ +#define CLASSTYPE_CONVERSION(NODE,KIND) \ + (TYPE_LANG_SPECIFIC(NODE)->conversions[(int) KIND]) + +/* 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) +/* Say whether this node was declared as a "class" or a "struct". */ +#define CLASSTYPE_DECLARED_EXCEPTION(NODE) (TYPE_LANG_SPECIFIC(NODE)->type_flags.declared_exception) +/* 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) + +/* 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) + +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 synthesized : 1; + unsigned dummy : 10; + + 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 vbase_init_list; + 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 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 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 is used + only to compute access information. */ +#define DECL_CLASS_CONTEXT(NODE) (DECL_LANG_SPECIFIC(NODE)->decl_flags.context) + +/* 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 + +/* 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) + +/* 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) + +/* Holds information about how virtual base classes should be initialized + by this constructor *if* this constructor is the one to perform + such initialization. */ +#define DECL_VBASE_INIT_LIST(NODE) (DECL_LANG_SPECIFIC(NODE)->vbase_init_list) + +/* 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 overloaded, and + should be looked up in a non-standard way. */ +#define TREE_OVERLOADED(NODE) (TREE_LANG_FLAG_0 (NODE)) +#define DECL_OVERLOADED(NODE) (DECL_LANG_FLAG_4 (NODE)) + +/* 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) (DECL_LANG_FLAG_5 (NODE)) + +/* 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 + +/* This method was synthesized by cons_up_default_function. */ +#define DECL_SYNTHESIZED(NODE) (DECL_LANG_SPECIFIC (NODE)->decl_flags.synthesized) + +/* 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)) + +/* 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)) + +/* 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)) + +/* 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)) + +/* 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_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 _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 node means that `external' was specified in + its declaration. */ +#define DECL_THIS_EXTERN(NODE) (DECL_LANG_FLAG_2(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_INITIAL(NODE) +/* For function, method, class-data templates. */ +#define DECL_TEMPLATE_RESULT(NODE) DECL_RESULT(NODE) +#define DECL_TEMPLATE_INSTANTIATIONS(NODE) DECL_VINDEX(NODE) + +/* ...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, + exception_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)); +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 cp-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, __i_desc_type_node, __m_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; + +/* 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 exception_type_node, unknown_type_node; +extern tree opaque_type_node, signature_type_node; + +/* The largest size a virtual function table can be. + Must be a (power of 2). */ +#ifndef VINDEX_MAX +#define VINDEX_MAX ((unsigned)128) +/* This is the integer ~ (vindex_max - 1). */ +#endif +extern tree vtbl_mask; + +/* 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; + +/* in cp-except.c */ +extern tree current_exception_type; +extern tree current_exception_decl; +extern tree current_exception_object; + +/* in cp-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; +}; + +extern struct tinst_level *current_tinst_level; + +/* in cp-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; +extern tree current_vtable_decl; + +/* in cp-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 "_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 "_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 "__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_VPTR_NAME "__vptr" +#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_CODE_NAME "__code" +#define SIGTABLE_OFFSET_NAME "__offset" +#define SIGTABLE_PFN_NAME "__pfn" +#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 cp-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 cp-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 'dossiers' that give run-time type information. */ + +extern int flag_dossier; + +/* 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; + +/* 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_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) +/* 128 & 256 are free */ +#define LOOKUP_NO_CONVERSION (512) +#define LOOKUP_DESTRUCTOR (512) + +/* 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 cp-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 cp-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 cp-class.c */ +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 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)); + +/* in cp-cvt.c */ +extern tree convert_to_reference PROTO((tree, tree, tree, tree, int, char *, int, int)); +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 convert_force PROTO((tree, tree)); +extern tree build_type_conversion PROTO((enum tree_code, tree, tree, int)); +extern int build_default_binary_type_conversion PROTO((enum tree_code, tree *, tree *)); +extern int build_default_unary_type_conversion PROTO((enum tree_code, tree *)); + +/* cp-decl.c */ +extern int global_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((void)); +/* 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 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 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_name_current_level PROTO((tree)); +extern void init_decl_processing PROTO((void)); +/* skipped define_function */ +extern void shadow_tag PROTO((tree)); +extern void grok_ctor_properties PROTO((tree, tree)); +extern tree groktypename PROTO((tree)); +extern tree start_decl PROTO((tree, tree, int, tree)); +extern void finish_decl PROTO((tree, tree, tree, 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)); +extern tree grokdeclarator (); /* PROTO((tree, tree, enum decl_context, int, tree)); */ +extern tree xref_defn_tag PROTO((tree, tree, tree)); +extern tree xref_tag PROTO((tree, tree, tree, int)); +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, int)); +extern void store_parm_decls PROTO((void)); +extern void store_return_init PROTO((tree, tree)); +extern void finish_function PROTO((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 cp-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 void check_classfn PROTO((tree, tree, tree)); +extern tree grokfield PROTO((tree, tree, tree, tree, tree)); +extern tree grokbitfield PROTO((tree, tree, tree)); +extern tree groktypefield PROTO((tree, tree)); +extern tree grokoptypename PROTO((tree, int)); +extern tree build_push_scope PROTO((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 finish_file PROTO((void)); +extern void warn_if_unknown_interface PROTO((void)); +extern tree grok_x_components PROTO((tree, tree)); + +/* in cp-edsel.c */ + +/* in cp-except.c */ +extern tree lookup_exception_cname PROTO((tree, tree, tree)); +extern tree lookup_exception_tname PROTO((tree)); +extern tree lookup_exception_object PROTO((tree, tree, int)); +extern tree lookup_exception_type PROTO((tree, tree, tree)); +extern tree finish_exception PROTO((tree, tree)); +extern void finish_exception_decl PROTO((tree, tree)); +extern void end_exception_decls PROTO((void)); +extern void cplus_expand_start_try PROTO((int)); +extern tree cplus_expand_end_try PROTO((int)); +extern void cplus_expand_start_except PROTO((tree, tree)); +extern void cplus_expand_end_except PROTO((tree)); +extern void cplus_expand_raise PROTO((tree, tree, tree, int)); +extern tree ansi_exception_object_lookup PROTO((tree)); +extern void cplus_expand_throw PROTO((tree)); +extern tree cplus_expand_start_catch PROTO((tree)); +extern tree ansi_expand_start_catch PROTO((tree)); +extern void cplus_expand_end_catch PROTO((int)); +extern void cplus_expand_reraise PROTO((tree)); +extern void setup_exception_throw_decl PROTO((void)); +extern void init_exception_processing PROTO((void)); +extern void init_exception_processing_1 PROTO((void)); + +/* in cp-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)); + +/* in cp-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 cp-init.c */ +extern void emit_base_init PROTO((tree, int)); +extern void check_base_init PROTO((tree)); +extern tree build_virtual_init PROTO((tree, tree, tree)); +extern void init_vtbl_ptrs PROTO((tree, int, int)); +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)); +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, 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, tree)); + +/* in cp-input.c */ + +/* in cp-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, 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 cp-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)); + +/* in cp-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 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 cp-pt.c */ +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)); +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)); + +/* in cp-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 check_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 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_first_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 tree build_vbase_vtables_init PROTO((tree, 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)); + +/* in cp-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)); +extern tree build_vptr_ref PROTO((tree)); + +/* in cp-spew.c */ +extern void init_spew PROTO((void)); +extern int yylex PROTO((void)); +extern tree arbitrate_lookup PROTO((tree, tree, tree)); + +/* in cp-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 copy_binfo PROTO((tree)); +extern tree binfo_value PROTO((tree, tree)); +extern tree reverse_path PROTO((tree)); +extern tree virtual_member PROTO((tree, tree)); +extern tree virtual_offset PROTO((tree, tree, tree)); +extern void debug_binfo PROTO((tree)); +extern int decl_list_length 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, 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)); + +/* in cp-typeck.c */ +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 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 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_c_cast PROTO((tree, tree)); +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 cp-type2.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 cp-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_def 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/gcc/cp/cvt.c b/gcc/cp/cvt.c new file mode 100644 index 00000000000..347a901a821 --- /dev/null +++ b/gcc/cp/cvt.c @@ -0,0 +1,1997 @@ +/* Language-level data type conversion for GNU C++. + Copyright (C) 1987, 1988, 1992, 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, 675 Mass Ave, Cambridge, MA 02139, 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; +{ + tree binfo = get_binfo (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (expr))), + 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)); +} + +/* 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 = 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 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 (TYPE_MAIN_VARIANT (type) != intype + && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE + && TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (intype)) == METHOD_TYPE) + return convert_fn_ptr (type, expr); + + 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 (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); + } + + 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), basetype = argtype; + tree target_type = TREE_TYPE (type); + tree binfo = NULL_TREE; + + my_friendly_assert (TREE_CODE (type) == REFERENCE_TYPE, 187); + if (flags != 0 + && 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 ((flags & LOOKUP_PROTECT) && binfo == error_mark_node) + return error_mark_node; + if (binfo == NULL_TREE) + return error_not_base_type (target_type, argtype); + basetype = BINFO_TYPE (binfo); + } + + /* Pass along const and volatile down into the type. */ + if (TYPE_READONLY (type) || TYPE_VOLATILE (type)) + target_type = build_type_variant (target_type, TYPE_READONLY (type), + TYPE_VOLATILE (type)); + targ = arg; + if (TREE_CODE (targ) == SAVE_EXPR) + 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_but_maybe_warn; + + /* 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_but_maybe_warn; + + /* 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 (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 + } + /* Fall through. */ + case VAR_DECL: + case CONST_DECL: + if (DECL_REGISTER (targ) && !TREE_ADDRESSABLE (targ)) + warning ("address needed to build reference for `%s', which is declared `register'", + IDENTIFIER_POINTER (DECL_NAME (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 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)); + + 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); + rval = build1 (ADDR_EXPR, type, temp); + goto done; + } + else + { + temp = get_temp_name (argtype, 0); + if (global_bindings_p ()) + { + /* Give this new temp some rtl and initialize it. */ + DECL_INITIAL (temp) = targ; + TREE_STATIC (temp) = 1; + finish_decl (temp, targ, NULL_TREE, 0); + /* 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_but_maybe_warn: + if (checkconst && TREE_READONLY (arg) && ! TYPE_READONLY (target_type)) + readonly_error (arg, "conversion to reference", 1); + + done: + if (TYPE_USES_COMPLEX_INHERITANCE (argtype)) + { + TREE_TYPE (rval) = TYPE_POINTER_TO (argtype); + rval = convert_pointer_to (target_type, rval); + TREE_TYPE (rval) = 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. + + If DECL is NULL_TREE it means convert as though casting (by force). + If it is ERROR_MARK_NODE, it means the conversion is implicit, + and that temporaries may be created. + Make sure the use of user-defined conversion operators is un-ambiguous. + Otherwise, DECL is a _DECL node which can be used in error reporting. + + FNDECL, PARMNUM, and ERRTYPE are only used when checking for use of + volatile or const references where they aren't desired. */ + +tree +convert_to_reference (decl, reftype, expr, fndecl, parmnum, + errtype, strict, flags) + tree decl; + tree reftype, expr; + tree fndecl; + int parmnum; + char *errtype; + int strict, flags; +{ + register tree type = TYPE_MAIN_VARIANT (TREE_TYPE (reftype)); + register tree intype = TREE_TYPE (expr); + register enum tree_code form = TREE_CODE (intype); + tree rval = NULL_TREE; + + if (TREE_CODE(type) == ARRAY_TYPE) + type = build_pointer_type (TREE_TYPE(type)); + if (form == REFERENCE_TYPE) + intype = TREE_TYPE (intype); + intype = TYPE_MAIN_VARIANT (intype); + + if (IS_AGGR_TYPE (intype) + && (rval = build_type_conversion (CONVERT_EXPR, reftype, expr, 1))) + { + if (rval == error_mark_node) + cp_error ("conversion from `%T' to `%T' is ambiguous", + intype, reftype); + return rval; + } + + if (comptypes (type, intype, strict)) + { + /* Section 13. */ + if (flags & LOOKUP_COMPLAIN) + { + /* Since convert_for_initialization didn't call convert_for_assignment, + we have to do this checking here. FIXME: We should have a common + routine between here and convert_for_assignment. */ + if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE) + { + register tree ttl = TREE_TYPE (reftype); + register tree ttr = TREE_TYPE (TREE_TYPE (expr)); + + if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards const", + TREE_TYPE (expr), parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards const", + errtype, reftype, TREE_TYPE (expr)); + } + if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr)) + { + if (fndecl) + cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile", + TREE_TYPE (expr), parmnum, fndecl); + else + cp_pedwarn ("%s to `%T' from `%T' discards volatile", + errtype, reftype, TREE_TYPE (expr)); + } + } else if (TREE_CODE (reftype) == REFERENCE_TYPE + && ! TREE_READONLY (TREE_TYPE (reftype)) + && ! lvalue_p (expr)) + { + /* Ensure semantics of 8.4.3 */ + if (fndecl) + cp_pedwarn ("ANSI C++ forbids passing non-lvalue `%T' as argument %P of `%D' into non-const &", + TREE_TYPE (expr), parmnum, fndecl); + else + cp_pedwarn ("ANSI C++ forbids %s to `%T' from non-lvalue `%T'", + errtype, reftype, TREE_TYPE (expr)); + } + } + + /* If EXPR is of aggregate type, and is really a CALL_EXPR, + then we don't need to convert it to reference type if + it is only being used to initialize DECL which is also + of the same aggregate type. */ + if (form == REFERENCE_TYPE + || (decl != NULL_TREE && decl != error_mark_node + && IS_AGGR_TYPE (type) + && TREE_CODE (expr) == CALL_EXPR + && TYPE_MAIN_VARIANT (type) == intype)) + { + if (decl && decl != error_mark_node) + { + tree e1 = build (INIT_EXPR, void_type_node, decl, expr); + tree e2; + + TREE_SIDE_EFFECTS (e1) = 1; + if (form == REFERENCE_TYPE) + e2 = build1 (NOP_EXPR, reftype, decl); + else + { + e2 = build_unary_op (ADDR_EXPR, decl, 0); + TREE_TYPE (e2) = reftype; + TREE_REFERENCE_EXPR (e2) = 1; + } + return build_compound_expr (tree_cons (NULL_TREE, e1, + build_tree_list (NULL_TREE, e2))); + } + expr = copy_node (expr); + TREE_TYPE (expr) = reftype; + return expr; + } + return build_up_reference (reftype, expr, flags, decl!=NULL_TREE); + } + + if (decl == error_mark_node) + { + tree rval_as_conversion = NULL_TREE; + tree rval_as_ctor = NULL_TREE; + + if (IS_AGGR_TYPE (intype) + && (rval = build_type_conversion (CONVERT_EXPR, type, expr, 1))) + { + if (rval == error_mark_node) + return rval; + + rval_as_conversion = build_up_reference (reftype, rval, flags, 1); + } + + /* Definitely need to go through a constructor here. */ + if (TYPE_HAS_CONSTRUCTOR (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))) + { + tree init; + + if (global_bindings_p ()) + { + extern tree static_aggregates; + decl = get_temp_name (type, global_bindings_p ()); + init = build_method_call (decl, constructor_name_full (type), + build_tree_list (NULL_TREE, expr), + TYPE_BINFO (type), LOOKUP_NORMAL|LOOKUP_NO_CONVERSION); + + if (init == error_mark_node) + return error_mark_node; + + make_decl_rtl (decl, NULL_PTR, 1); + static_aggregates = perm_tree_cons (expr, decl, static_aggregates); + rval = build_unary_op (ADDR_EXPR, decl, 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); + + 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 ("converting `%T' to non-const `%T' will use a temporary", + intype, reftype); + } + + if (rval) + { + /* If we found a way to convert earlier, then use it. */ + return rval; + } + + my_friendly_assert (form != OFFSET_TYPE, 189); + + if ((flags & (LOOKUP_COMPLAIN|LOOKUP_SPECULATIVELY)) == 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) + { + tree target_type = TREE_TYPE (type); + tree nval; + + /* This can happen if we cast to a reference type. */ + if (TREE_CODE (val) == ADDR_EXPR) + { + nval = build1 (NOP_EXPR, build_pointer_type (target_type), val); + nval = build_indirect_ref (nval, NULL_PTR); + /* The below was missing, are other important flags missing too? */ + TREE_SIDE_EFFECTS (nval) = TREE_SIDE_EFFECTS (val); + return nval; + } + + nval = build1 (INDIRECT_REF, TYPE_MAIN_VARIANT (target_type), val); + + TREE_THIS_VOLATILE (nval) = TYPE_VOLATILE (target_type); + TREE_SIDE_EFFECTS (nval) = TYPE_VOLATILE (target_type); + TREE_READONLY (nval) = TYPE_READONLY (target_type); + /* The below was missing, are other important flags missing too? */ + TREE_SIDE_EFFECTS (nval) |= TREE_SIDE_EFFECTS (val); + return nval; + } + 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, TYPE_POINTER_TO (basetype), parmtypes); + + 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); + } + + /* 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; + if (flag_ansi_overloading) + cp->v.ansi_harshness = (struct harshness_code *) + alloca (3 * sizeof (struct harshness_code)); + else + cp->v.old_harshness = (unsigned short *) + alloca (3 * sizeof (short)); + + compute_conversion_costs (fndecl, parmlist, cp, 2); + if ((flag_ansi_overloading && (cp->h.code & EVIL_CODE) == 0) + || (!flag_ansi_overloading && cp->evil == 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 ((flag_ansi_overloading && cp->h.code <= TRIVIAL_CODE) + || (!flag_ansi_overloading + && cp->user == 0 && cp->b_or_d == 0 + && cp->easy <= 1)) + 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 ((flag_ansi_overloading && (cp->h.code & EVIL_CODE)) + || (!flag_ansi_overloading && cp->evil > 1)) + { + 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"; + } + return error_mark_node; + } + /* NOTREACHED */ + + not_found: + if (msgp) *msgp = "no appropriate conversion to type `%s'"; + return error_mark_node; + 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); + if (DECL_INLINE (function) && TREE_CODE (function) == FUNCTION_DECL) + function = build1 (ADDR_EXPR, build_pointer_type (fntype), function); + else + 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; + TREE_RAISES (result) = !! TYPE_RAISES_EXCEPTIONS (fntype); + 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'", + TREE_TYPE (intype)); + cp_error ("to a pointer of type `%T'", 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); +} + +/* Same as above, but don't abort if we get an "ambiguous" baseclass. + There's only one virtual baseclass we are looking for, and once + we find one such virtual baseclass, we have found them all. */ + +tree +convert_pointer_to_vbase (binfo, expr) + tree binfo; + tree expr; +{ + tree intype = TREE_TYPE (TREE_TYPE (expr)); + tree binfos = TYPE_BINFO_BASETYPES (intype); + int i; + + for (i = TREE_VEC_LENGTH (binfos)-1; i >= 0; i--) + { + tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); + if (BINFO_TYPE (binfo) == basetype) + return convert_pointer_to (binfo, expr); + if (binfo_member (BINFO_TYPE (binfo), CLASSTYPE_VBASECLASSES (basetype))) + return convert_pointer_to_vbase (binfo, convert_pointer_to (basetype, expr)); + } + my_friendly_abort (6); + /* NOTREACHED */ + return NULL_TREE; +} + +/* 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) + { + /* We're converting to a void type; see if they have an + `operator void'. */ + tree rval = build_type_conversion (NOP_EXPR, type, e, 0); + /* If we can convert to void type via a type conversion, do so. */ + if (rval) + return rval; + 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 + + /* Just convert to the type of the member. */ + if (code == OFFSET_TYPE) + { + type = TREE_TYPE (type); + code = TREE_CODE (type); + } + + /* C++ */ + if (code == REFERENCE_TYPE) + return fold (convert_to_reference (error_mark_node, type, e, NULL_TREE, + -1, "conversion", -1, LOOKUP_NORMAL)); + else if (TREE_CODE (TREE_TYPE (e)) == REFERENCE_TYPE) + e = convert_from_reference (e); + + if (code == INTEGER_TYPE || code == ENUMERAL_TYPE) + { + tree intype = TREE_TYPE (expr); + 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 + && (form == INTEGER_TYPE || form == REAL_TYPE + || form == ENUMERAL_TYPE)) + { + cp_pedwarn ("conversion from `%#T' to `%#T'", intype, type); + + if (flag_pedantic_errors) + return error_mark_node; + } + if (form == OFFSET_TYPE) + cp_error_at ("pointer-to-member expression object not composed with type `%D' object", + TYPE_NAME (TYPE_OFFSET_BASETYPE (intype))); + else if (IS_AGGR_TYPE (intype)) + { + tree rval; + rval = build_type_conversion (CONVERT_EXPR, type, expr, 1); + if (rval) return rval; + cp_error ("`%#T' used where an `int' was expected", intype); + return error_mark_node; + } + return fold (convert_to_integer (type, e)); + } + if (code == POINTER_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 + 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); + + if (TREE_CODE (dtype) == REFERENCE_TYPE) + { + e = convert_from_reference (e); + dtype = TREE_TYPE (e); + } + 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); + finish_decl (sig_ptr, constructor, 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. */ + + else if (IS_AGGR_TYPE (dtype)) + { + tree binfo; + + tree conversion = TYPE_HAS_CONVERSION (dtype) + ? build_type_conversion (CONVERT_EXPR, type, e, 1) : NULL_TREE; + + if (TYPE_HAS_CONSTRUCTOR (type)) + { + tree rval = build_method_call (NULL_TREE, constructor_name_full (type), + build_tree_list (NULL_TREE, e), + TYPE_BINFO (type), + conversion ? LOOKUP_NO_CONVERSION : 0); + + if (rval != error_mark_node) + { + if (conversion) + { + error ("both constructor and type conversion operator apply"); + return error_mark_node; + } + /* call to constructor successful. */ + rval = build_cplus_new (type, rval, 0); + return rval; + } + } + /* Type conversion successful/applies. */ + if (conversion) + { + if (conversion == error_mark_node) + error ("ambiguous pointer conversion"); + return conversion; + } + + /* now try normal C++ assignment semantics. */ + binfo = TYPE_BINFO (dtype); + if (BINFO_TYPE (binfo) == type + || (binfo = get_binfo (type, dtype, 1))) + { + if (binfo == error_mark_node) + return error_mark_node; + } + if (binfo != NULL_TREE) + { + if (lvalue_p (e)) + { + e = build_unary_op (ADDR_EXPR, e, 0); + + if (! BINFO_OFFSET_ZEROP (binfo)) + e = build (PLUS_EXPR, TYPE_POINTER_TO (type), + e, BINFO_OFFSET (binfo)); + return build1 (INDIRECT_REF, type, e); + } + + sorry ("addressable aggregates"); + return error_mark_node; + } + error ("conversion between incompatible aggregate types requested"); + return error_mark_node; + } + /* conversion from non-aggregate to aggregate type requires + constructor. */ + else if (TYPE_HAS_CONSTRUCTOR (type)) + { + tree rval; + tree init = build_method_call (NULL_TREE, constructor_name_full (type), + build_tree_list (NULL_TREE, e), + TYPE_BINFO (type), LOOKUP_NORMAL); + if (init == error_mark_node) + { + cp_error ("in conversion to type `%T'", type); + return error_mark_node; + } + rval = build_cplus_new (type, init, 0); + return rval; + } + } + + /* If TYPE or TREE_TYPE (EXPR) 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 (expr)) == TREE_TYPE (type) + && index_type_equal (TYPE_DOMAIN (TREE_TYPE (expr)), TYPE_DOMAIN (type))) + return expr; + + cp_error ("conversion from `%T' to non-scalar type `%T' requested", + TREE_TYPE (expr), 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). */ +tree +convert_force (type, expr) + tree type; + tree expr; +{ + register tree e = expr; + register enum tree_code code = TREE_CODE (type); + + if (code == REFERENCE_TYPE) + return fold (convert_to_reference (0, type, e, NULL_TREE, -1, + NULL, -1, 0)); + 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 cp-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 (type)) + { + /* compatible pointer to member functions. */ + e = build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), e, 1); + if (e == 0) + return error_mark_node; + return digest_init (type, e, (tree *)0); + } + { + int old_equiv = flag_int_enum_equivalence; + flag_int_enum_equivalence = 1; + e = convert (type, e); + flag_int_enum_equivalence = old_equiv; + } + return e; +} + +/* 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 first_arg = expr; + tree rval; + int flags; + + if (for_sure == 0) + { + if (! lvalue_p (expr)) + first_arg = build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), integer_zero_node); + flags = LOOKUP_PROTECT; + } + else + flags = LOOKUP_NORMAL; + + rval = build_method_call (first_arg, constructor_name_full (typename), + NULL_TREE, NULL_TREE, flags); + if (rval == error_mark_node) + { + if (for_sure == 0) + return NULL_TREE; + return error_mark_node; + } + if (first_arg != expr) + { + expr = build_up_reference (build_reference_type (TREE_TYPE (expr)), expr, + LOOKUP_COMPLAIN, 1); + TREE_VALUE (TREE_OPERAND (rval, 1)) = build_unary_op (ADDR_EXPR, expr, 0); + } + if (TREE_CODE (TREE_TYPE (rval)) == REFERENCE_TYPE + && TREE_CODE (xtype) != REFERENCE_TYPE) + rval = default_conversion (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. + + If FOR_SURE >= 2, then we only look for exact conversions. + + TYPE may be a reference type, in which case we first look + for something that will convert to a reference type. If + that fails, we will try to look for something of the + reference's target type, and then return a reference to that. */ +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 scalar type. */ + tree type, type_default; + tree typename = build_typename_overload (xtype), *typenames; + int n_variants = 0; + tree basetype, save_basetype; + tree rval; + int exact_conversion = for_sure >= 2; + for_sure &= 1; + + 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; + + if (TREE_CODE (xtype) == POINTER_TYPE + || TREE_CODE (xtype) == REFERENCE_TYPE) + { + /* Prepare to match a variant of this type. */ + type = TYPE_MAIN_VARIANT (TREE_TYPE (xtype)); + for (n_variants = 0; type; type = TYPE_NEXT_VARIANT (type)) + n_variants++; + typenames = (tree *)alloca (n_variants * sizeof (tree)); + for (n_variants = 0, type = TYPE_MAIN_VARIANT (TREE_TYPE (xtype)); + type; n_variants++, type = TYPE_NEXT_VARIANT (type)) + { + if (type == TREE_TYPE (xtype)) + typenames[n_variants] = typename; + else if (TREE_CODE (xtype) == POINTER_TYPE) + typenames[n_variants] = build_typename_overload (build_pointer_type (type)); + else + typenames[n_variants] = build_typename_overload (build_reference_type (type)); + } + } + + save_basetype = basetype; + type = xtype; + + while (TYPE_HAS_CONVERSION (basetype)) + { + int i; + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + for (i = 0; i < n_variants; i++) + if (typenames[i] != typename + && lookup_fnfields (TYPE_BINFO (basetype), typenames[i], 0)) + return build_type_conversion_1 (xtype, basetype, expr, typenames[i], for_sure); + + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + + if (TREE_CODE (type) == REFERENCE_TYPE) + { + tree first_arg = expr; + type = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + basetype = save_basetype; + + /* May need to build a temporary for this. */ + while (TYPE_HAS_CONVERSION (basetype)) + { + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + { + int flags; + + if (for_sure == 0) + { + if (! lvalue_p (expr)) + first_arg = build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), integer_zero_node); + flags = LOOKUP_PROTECT; + } + else + flags = LOOKUP_NORMAL; + rval = build_method_call (first_arg, constructor_name_full (typename), + NULL_TREE, NULL_TREE, flags); + if (rval == error_mark_node) + { + if (for_sure == 0) + return NULL_TREE; + return error_mark_node; + } + TREE_VALUE (TREE_OPERAND (rval, 1)) = expr; + + if (IS_AGGR_TYPE (type)) + { + tree init = build_method_call (NULL_TREE, + constructor_name_full (type), + build_tree_list (NULL_TREE, rval), NULL_TREE, LOOKUP_NORMAL); + tree temp = build_cplus_new (type, init, 1); + return build_up_reference (TYPE_REFERENCE_TO (type), temp, + LOOKUP_COMPLAIN, 1); + } + return convert (xtype, rval); + } + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + /* No free conversions for reference types, right?. */ + return NULL_TREE; + } + + if (exact_conversion) + return NULL_TREE; + + /* No perfect match found, try default. */ +#if 0 /* This is wrong; there is no standard conversion from void* to + anything. -jason */ + if (code == CONVERT_EXPR && TREE_CODE (type) == POINTER_TYPE) + type_default = ptr_type_node; + else +#endif + if (type == void_type_node) + return NULL_TREE; + else + { + tree tmp = default_conversion (build1 (NOP_EXPR, type, integer_zero_node)); + if (tmp == error_mark_node) + return NULL_TREE; + type_default = TREE_TYPE (tmp); + } + + basetype = save_basetype; + + if (type_default != type) + { + type = type_default; + typename = build_typename_overload (type); + + while (TYPE_HAS_CONVERSION (basetype)) + { + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + } + + try_pointer: + + if (type == ptr_type_node) + { + /* Try converting to some other pointer type + with which void* is compatible, or in situations + in which void* is appropriate (such as &&,||, and !). */ + + while (TYPE_HAS_CONVERSION (basetype)) + { + if (CLASSTYPE_CONVERSION (basetype, ptr_conv) != 0) + { + if (CLASSTYPE_CONVERSION (basetype, ptr_conv) == error_mark_node) + return error_mark_node; + typename = DECL_NAME (CLASSTYPE_CONVERSION (basetype, ptr_conv)); + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + } + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + } + if (TREE_CODE (type) == POINTER_TYPE + && TYPE_READONLY (TREE_TYPE (type)) + && TYPE_MAIN_VARIANT (TREE_TYPE (type)) == void_type_node) + { + /* Try converting to some other pointer type + with which const void* is compatible. */ + + while (TYPE_HAS_CONVERSION (basetype)) + { + if (CLASSTYPE_CONVERSION (basetype, constptr_conv) != 0) + { + if (CLASSTYPE_CONVERSION (basetype, constptr_conv) == error_mark_node) + return error_mark_node; + typename = DECL_NAME (CLASSTYPE_CONVERSION (basetype, constptr_conv)); + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + } + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + } + /* Use the longer or shorter conversion that is appropriate. Have + to check against 0 because the conversion may come from a baseclass. */ + if (TREE_CODE (type) == INTEGER_TYPE + && TYPE_HAS_INT_CONVERSION (basetype) + && CLASSTYPE_CONVERSION (basetype, int_conv) != 0 + && CLASSTYPE_CONVERSION (basetype, int_conv) != error_mark_node) + { + typename = DECL_NAME (CLASSTYPE_CONVERSION (basetype, int_conv)); + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + } + + if (TREE_CODE (type) == REAL_TYPE + && TYPE_HAS_REAL_CONVERSION (basetype) + && CLASSTYPE_CONVERSION (basetype, real_conv) != 0 + && CLASSTYPE_CONVERSION (basetype, real_conv) != error_mark_node) + { + /* Only accept using an operator double() if there isn't a conflicting + operator int(). */ + if (flag_ansi_overloading && TYPE_HAS_INT_CONVERSION (basetype)) + { + error ("two possible conversions for type `%s'", + TYPE_NAME_STRING (type)); + return error_mark_node; + } + + typename = DECL_NAME (CLASSTYPE_CONVERSION (basetype, real_conv)); + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + } + + /* THIS IS A KLUDGE. */ + if (TREE_CODE (type) != POINTER_TYPE + && (code == TRUTH_ANDIF_EXPR + || code == TRUTH_ORIF_EXPR + || code == TRUTH_NOT_EXPR)) + { + /* Here's when we can convert to a pointer. */ + type = ptr_type_node; + goto try_pointer; + } + + /* THESE ARE TOTAL KLUDGES. */ + /* Default promotion yields no new alternatives, try + conversions which are anti-default, such as + + double -> float or int -> unsigned or unsigned -> long + + */ + if (type_default == type + && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == REAL_TYPE)) + { + int not_again = 0; + + if (type == double_type_node) + typename = build_typename_overload (float_type_node); + else if (type == integer_type_node) + typename = build_typename_overload (unsigned_type_node); + else if (type == unsigned_type_node) + typename = build_typename_overload (long_integer_type_node); + + again: + basetype = save_basetype; + while (TYPE_HAS_CONVERSION (basetype)) + { + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + return build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + if (! not_again) + { + if (type == integer_type_node) + { + typename = build_typename_overload (long_integer_type_node); + not_again = 1; + goto again; + } + else + { + typename = build_typename_overload (integer_type_node); + not_again = 1; + goto again; + } + } + } + + /* Now, try C promotions... + + float -> int + int -> float, void * + void * -> int + + Truthvalue conversions let us try to convert + to pointer if we were going for int, and to int + if we were looking for pointer. */ + + basetype = save_basetype; + if (TREE_CODE (type) == REAL_TYPE + || (TREE_CODE (type) == POINTER_TYPE + && (code == TRUTH_ANDIF_EXPR + || code == TRUTH_ORIF_EXPR + || code == TRUTH_NOT_EXPR))) + type = integer_type_node; + else if (TREE_CODE (type) == INTEGER_TYPE) + if (TYPE_HAS_REAL_CONVERSION (basetype)) + type = double_type_node; + else + return NULL_TREE; + else + return NULL_TREE; + + typename = build_typename_overload (type); + while (TYPE_HAS_CONVERSION (basetype)) + { + if (lookup_fnfields (TYPE_BINFO (basetype), typename, 0)) + { + rval = build_type_conversion_1 (xtype, basetype, expr, typename, for_sure); + return rval; + } + if (TYPE_BINFO_BASETYPES (basetype)) + basetype = TYPE_BINFO_BASETYPE (basetype, 0); + else + break; + } + + 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; +{ + tree type1 = TREE_TYPE (*arg1); + tree type2 = TREE_TYPE (*arg2); + + if (TREE_CODE (type1) == REFERENCE_TYPE + || TREE_CODE (type1) == POINTER_TYPE) + type1 = TREE_TYPE (type1); + if (TREE_CODE (type2) == REFERENCE_TYPE + || TREE_CODE (type2) == POINTER_TYPE) + type2 = TREE_TYPE (type2); + + if (TREE_CODE (TYPE_NAME (type1)) != TYPE_DECL) + { + tree decl = typedecl_for_tag (type1); + if (decl) + error ("type conversion nonexistent for type `%s'", + IDENTIFIER_POINTER (DECL_NAME (decl))); + else + error ("type conversion nonexistent for non-C++ type"); + return 0; + } + if (TREE_CODE (TYPE_NAME (type2)) != TYPE_DECL) + { + tree decl = typedecl_for_tag (type2); + if (decl) + error ("type conversion nonexistent for type `%s'", + IDENTIFIER_POINTER (decl)); + else + error ("type conversion nonexistent for non-C++ type"); + return 0; + } + + if (!IS_AGGR_TYPE (type1) || !TYPE_HAS_CONVERSION (type1)) + { + if (!IS_AGGR_TYPE (type2) || !TYPE_HAS_CONVERSION (type2)) + cp_error ("no conversion from `%T' and `%T' to types with default `%O' ", + type1, type2, code); + else + cp_error ("no conversion from `%T' to type with default `%O'", + type1, code); + return 0; + } + else if (!IS_AGGR_TYPE (type2) || !TYPE_HAS_CONVERSION (type2)) + { + cp_error ("no conversion from `%T' to type with default `%O'", + type2, code); + return 0; + } + + if (TYPE_HAS_INT_CONVERSION (type1) && TYPE_HAS_REAL_CONVERSION (type1)) + cp_warning ("ambiguous type conversion for type `%T', defaulting to int", + type1); + if (TYPE_HAS_INT_CONVERSION (type1)) + { + *arg1 = build_type_conversion (code, integer_type_node, *arg1, 1); + *arg2 = build_type_conversion (code, integer_type_node, *arg2, 1); + } + else if (TYPE_HAS_REAL_CONVERSION (type1)) + { + *arg1 = build_type_conversion (code, double_type_node, *arg1, 1); + *arg2 = build_type_conversion (code, double_type_node, *arg2, 1); + } + else + { + *arg1 = build_type_conversion (code, ptr_type_node, *arg1, 1); + if (*arg1 == error_mark_node) + error ("ambiguous pointer conversion"); + *arg2 = build_type_conversion (code, ptr_type_node, *arg2, 1); + if (*arg1 != error_mark_node && *arg2 == error_mark_node) + error ("ambiguous pointer conversion"); + } + if (*arg1 == 0) + { + if (*arg2 == 0 && type1 != type2) + cp_error ("default type conversion for types `%T' and `%T' failed", + type1, type2); + else + cp_error ("default type conversion for type `%T' failed", type1); + return 0; + } + else if (*arg2 == 0) + { + cp_error ("default type conversion for type `%T' failed", type2); + return 0; + } + return 1; +} + +/* 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. + + The type of the argument is expected to be of aggregate type here. + + @@ What are the real semantics of this supposed to be??? */ +int +build_default_unary_type_conversion (code, arg) + enum tree_code code; + tree *arg; +{ + tree type = TREE_TYPE (*arg); + tree id = TREE_CODE (TYPE_NAME (type)) == TYPE_DECL + ? TYPE_IDENTIFIER (type) : TYPE_NAME (type); + char *name = IDENTIFIER_POINTER (id); + + if (! TYPE_HAS_CONVERSION (type)) + { + error ("type conversion required for type `%s'", name); + return 0; + } + + if (TYPE_HAS_INT_CONVERSION (type) && TYPE_HAS_REAL_CONVERSION (type)) + warning ("ambiguous type conversion for type `%s', defaulting to int", + name); + if (TYPE_HAS_INT_CONVERSION (type)) + *arg = build_type_conversion (code, integer_type_node, *arg, 1); + else if (TYPE_HAS_REAL_CONVERSION (type)) + *arg = build_type_conversion (code, double_type_node, *arg, 1); + else + { + *arg = build_type_conversion (code, ptr_type_node, *arg, 1); + if (*arg == error_mark_node) + error ("ambiguous pointer conversion"); + } + if (*arg == NULL_TREE) + { + error ("default type conversion for type `%s' failed", name); + return 0; + } + return 1; +} diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c new file mode 100644 index 00000000000..9a31201f054 --- /dev/null +++ b/gcc/cp/decl.c @@ -0,0 +1,12087 @@ +/* Process declarations and variables for C compiler. + Copyright (C) 1988, 1992, 1993, 1994 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, 675 Mass Ave, Cambridge, MA 02139, 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 struct obstack permanent_obstack; + +extern int current_class_depth; + +/* 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 + +/* 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 + +#define builtin_function(NAME, TYPE, CODE, LIBNAME) \ + define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) +#define auto_function(NAME, TYPE, CODE) \ + do { \ + tree __name = NAME; \ + tree __type = TYPE; \ + define_function (IDENTIFIER_POINTER (__name), __type, CODE, \ + (void (*)())push_overloaded_decl_1, \ + IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\ + } while (0) + +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)); +static void deactivate_exception_cleanups PROTO((void)); + +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 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; + +/* 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; +tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node; +tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; +tree class_star_type_node; +tree class_type_node, record_type_node, union_type_node, enum_type_node; +tree exception_type_node, unknown_type_node; +tree opaque_type_node, signature_type_node; +tree sigtable_entry_type; +tree maybe_gc_cleanup; + +/* Used for virtual function tables. */ +tree vtbl_mask; + +/* Array type `vtable_entry_type[]' */ +tree vtbl_type_node; + +/* Static decls which do not have static initializers have no + initializers as far as GNU C is concerned. EMPTY_INIT_NODE + is a static initializer which makes varasm code place the decl + in data rather than in bss space. Such gymnastics are necessary + to avoid the problem that the linker will not include a library + file if all the library appears to contribute are bss variables. */ + +tree empty_init_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 `unhandled_exception'. + Not necessarily the one that the user will declare, + but sufficient to be called by routines that want to abort the program. */ + +tree unhandled_exception_fndecl; + +/* 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. */ +rtx base_init_insns; + +/* 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, and in vtables. */ +tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; +tree pfn_or_delta2_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; + +/* A list of functions which were declared inline, but later had their + address taken. Used only for non-virtual member functions, since we can + find other functions easily enough. */ +tree pending_addressable_inlines; + +/* A list of overloaded functions which we should forget ever + existed, such as functions declared in a function's scope, + once we leave that function's scope. */ +static tree overloads_to_forget; + +/* -- 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; + +/* 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 when starting a function declared `extern inline'. */ + +static int current_extern_inline; + +/* 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 do emit exported implementations of functions even if + they can be inlined. */ + +extern int flag_implement_inlines; + +/* Nonzero means handle things in ANSI, instead of GNU fashion. This + flag should be tested for language behavior that's different between + ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */ + +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 flaging 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 cp-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 cp-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; + + /* Number of decls in `names' that have incomplete + structure or union types. */ + unsigned short n_incomplete; + + /* 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 this level can safely have additional + exception-raising statements added to it. */ + unsigned more_exceptions_ok : 1; + unsigned have_exceptions : 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; + + /* Two bits 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->more_exceptions_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; + } +} + +/* 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->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; +} + +/* Identify this binding level as a level of a default exception handler. */ + +void +declare_implicit_exception () +{ + current_binding_level->parm_flag = 3; +} + +/* Nonzero if current binding contour contains expressions + that might raise exceptions. */ + +int +have_exceptions_p () +{ + return current_binding_level->have_exceptions; +} + +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; +} + +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; +} + +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)) + { + /* 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 = 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); + + /* 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 && !implicit_try_block) + { +#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; +} + +/* 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. */ +tree +poplevel_class () +{ + 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 IDENTIFER_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 caching effect if the + next time we're entering a class scope, it is the same class. */ + if (current_class_depth != 1) + 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", + lvl->n_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"); + if (lvl->more_exceptions_ok) + fprintf (stderr, " more-exceptions-ok"); + if (lvl->have_exceptions) + fprintf (stderr, " have-exceptions"); + 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); +} + +/* 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, class_decl, function_decl; + struct binding_level *class_bindings; + tree previous_class_type; +}; +static struct saved_scope *current_saved_scope; +extern tree prev_class_type; + +void +push_to_top_level () +{ + 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->class_decl = current_class_decl; + s->function_decl = current_function_decl; + s->class_bindings = class_binding_level; + s->previous_class_type = previous_class_type; + current_class_name = current_class_type = current_class_decl = NULL_TREE; + current_function_decl = NULL_TREE; + class_binding_level = (struct binding_level *)0; + previous_class_type = NULL_TREE; + + s->prev = current_saved_scope; + s->old_bindings = old_bindings; + current_saved_scope = s; +} + +void +pop_from_top_level () +{ + 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_class_decl = s->class_decl; + if (current_class_type) + C_C_D = CLASSTYPE_INST_VAR (current_class_type); + else + C_C_D = NULL_TREE; + current_function_decl = s->function_decl; + class_binding_level = s->class_bindings; + previous_class_type = s->previous_class_type; + 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; +{ + my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); + if (classname != NULL_TREE) + { + char *buf; + 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); + + /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no + correspondence in any binding_level. This is ok since the + DECL_NESTED_TYPENAME is just a convenience identifier whose + IDENTIFIER_TYPE_VALUE will remain constant from now on. */ + SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type); + } + else + DECL_NESTED_TYPENAME (decl) = name; +} + +#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 cp-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-tranparent 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 t_context = 0; + + b = inner_binding_level; + while (b->tag_transparent + || (globalize && b->parm_flag == 2)) + b = b->level_chain; + + if (b == global_binding_level) + b->tags = perm_tree_cons (name, type, b->tags); + else + b->tags = saveable_tree_cons (name, type, b->tags); + + if (name) + { + t_context = type ? TYPE_CONTEXT(type) : NULL_TREE; + if (!t_context && !globalize) + t_context = current_class_type; + + /* Record the identifier as the type's name if it has none. */ + if (TYPE_NAME (type) == NULL_TREE) + TYPE_NAME (type) = name; + + /* Do C++ gratuitous typedefing. */ + if (IDENTIFIER_TYPE_VALUE (name) != type + && (TREE_CODE (type) != RECORD_TYPE + || b->parm_flag != 2 + || !CLASSTYPE_DECLARED_EXCEPTION (type))) + { + register tree d; + int newdecl = 0; + + if (b->parm_flag != 2 + || TYPE_SIZE (current_class_type) != NULL_TREE) + { + if (current_lang_name == lang_name_cplusplus) + d = lookup_nested_type (type, + t_context ? TYPE_NAME (t_context) : NULL_TREE); + else + d = NULL_TREE; + + 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); +#endif +#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); + + /* If it is anonymous, then we are called from pushdecl, + and we don't want to infinitely recurse. Also, if the + name is already in scope, we don't want to push it + again--pushdecl is only for pushing new decls. */ + if (! ANON_AGGRNAME_P (name) + && TYPE_NAME (type) + && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL + || lookup_name (name, 1) != TYPE_NAME (type))) + { + 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_lang_field_decl (TYPE_DECL, name, type); +#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 */ + /* 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 (write_symbols != DWARF_DEBUG) + { + if (ANON_AGGRNAME_P (name)) + DECL_IGNORED_P (d) = 1; + } + TYPE_NAME (type) = d; + + if ((t_context == NULL_TREE + && current_function_decl == NULL_TREE) + || current_lang_name != lang_name_cplusplus) + /* Non-nested class. */ + DECL_NESTED_TYPENAME (d) = name; + else if (current_function_decl != NULL_TREE) + { + /* Function-nested class. */ + set_nested_typename (d, + DECL_ASSEMBLER_NAME (current_function_decl), name, type); + /* This builds the links for classes nested in fn scope. */ + DECL_CONTEXT (d) = current_function_decl; + } +/* else if (TYPE_SIZE (current_class_type) == NULL_TREE) +*/ + else if (t_context && TREE_CODE (t_context) == RECORD_TYPE) + { + /* Class-nested class. */ + set_nested_typename (d, + DECL_NESTED_TYPENAME (TYPE_NAME (t_context)), name, type); + /* This builds the links for classes nested in type scope. */ + DECL_CONTEXT (d) = t_context; + DECL_CLASS_CONTEXT (d) = t_context; + } + TYPE_CONTEXT (type) = DECL_CONTEXT (d); + if (newdecl) + 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&'. */ +static 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 (&f1, &newdecl, &p1); + else if (TREE_CODE (f2) == METHOD_TYPE + && DECL_STATIC_FUNCTION_P (newdecl)) + revert_static_member_fn (&f2, &olddecl, &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 (TYPE_MAIN_VARIANT (TREE_TYPE (f1)), + TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 2)) + types_match = compparms (p1, p2, 2); + else + types_match = 0; + } + 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 + 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 + || (! warn_extern_inline + && DECL_INLINE (newdecl))) + return; + + name = DECL_ASSEMBLER_NAME (newdecl); + if (TREE_PUBLIC (name) && ! TREE_PUBLIC (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_warning (IDENTIFIER_IMPLICIT_DECL (name) + ? implicit_extern_static_warning + : explicit_extern_static_warning, newdecl); + if (olddecl != NULL_TREE) + cp_warning_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. */ + +static 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 (newdecl) == FUNCTION_DECL + && is_overloaded_fn (olddecl)) + { + olddecl = get_first_fn (olddecl); + + while (olddecl) + { + if (DECL_LANGUAGE (olddecl) == lang_c) + previous_c_decl = olddecl; + + /* Redeclaration. */ + if (decls_match (newdecl, olddecl)) + { + types_match = 1; + break; + } + /* Ambiguous overload. */ + else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), + TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2)) + break; + + /* Attempt to define multiple C-binding fns. */ + if (previous_c_decl) + break; + + olddecl = DECL_CHAIN (olddecl); + } + if (!olddecl) + { + /* If we found no match, make this join the other + overloaded decls. */ + DECL_OVERLOADED (newdecl) = 1; + return 1; + } + } + else + 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 (TREE_CODE (olddecl) != TREE_CODE (newdecl)) + { + 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; + } + + 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_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) + cp_warning ("shadowing %s function `%#D'", + DECL_BUILT_IN (olddecl) ? "built-in" : "library", + newdecl); + /* Discard the old built-in function. */ + return 0; + } + /* Likewise, if the built-in is not ansi, then programs can + override it even globally without an error. */ + else if (! DECL_BUILT_IN (olddecl)) + cp_warning ("library function `%#D' declared as non-function", + newdecl); + + if (!types_match) + { + cp_warning ("declaration of `%#D'", newdecl); + cp_warning ("conflicts with built-in declaration `%#D'", + olddecl); + return 0; + } + } + else if (!types_match && previous_c_decl + && DECL_LANGUAGE (newdecl) == lang_c) + { + cp_error ("declaration of C function `%#D' conflicts with", newdecl); + cp_error_at ("previous declaration `%#D' here", previous_c_decl); + } + else if (!types_match) + { + tree oldtype = TREE_TYPE (olddecl); + tree newtype = TREE_TYPE (newdecl); + int give_error = 0; + + /* Already complained about this, so don't do so again. */ + if (current_class_type == NULL_TREE + || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) + { + give_error = 1; + + /* Since we're doing this before finish_struct can set the + line number on NEWDECL, we just do a regular error here. */ + if (DECL_SOURCE_LINE (newdecl) == 0) + cp_error ("conflicting types for `%#D'", newdecl); + else + cp_error_at ("conflicting types for `%#D'", newdecl); + } + + /* 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), 1) + && ((TYPE_ARG_TYPES (oldtype) == NULL_TREE + && DECL_INITIAL (olddecl) == NULL_TREE) + || (TYPE_ARG_TYPES (newtype) == NULL_TREE + && DECL_INITIAL (newdecl) == NULL_TREE))) + { + /* Classify the problem further. */ + register tree t = TYPE_ARG_TYPES (oldtype); + + if (t == NULL_TREE) + t = TYPE_ARG_TYPES (newtype); + for (; t; t = TREE_CHAIN (t)) + { + register tree type = TREE_VALUE (t); + + if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node) + { + give_error = 1; + 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)) + { + give_error = 1; + error ("An argument type that has a default promotion"); + error ("can't match an empty parameter name list declaration."); + break; + } + } + } + if (give_error) + cp_error_at ("previous declaration as `%#D'", olddecl); + + /* There is one thing GNU C++ cannot tolerate: a constructor + which takes the type of object being constructed. + Farm that case out here. */ + if (TREE_CODE (newdecl) == FUNCTION_DECL + && DECL_CONSTRUCTOR_P (newdecl)) + { + tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype)); + + if (tmp != NULL_TREE + && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp)) + == TYPE_METHOD_BASETYPE (newtype))) + { + tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl)); + tree argtypes + = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)), + TREE_CHAIN (tmp)); + + DECL_ARG_TYPE (parm) + = TREE_TYPE (parm) + = TYPE_REFERENCE_TO (TREE_VALUE (tmp)); + + TREE_TYPE (newdecl) = newtype + = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype), + TREE_TYPE (newtype), argtypes); + error ("constructor cannot take as argument the type being constructed"); + SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type); + } + } + } + else + { + char *errmsg = redeclaration_error_message (newdecl, olddecl); + if (errmsg) + { + error_with_decl (newdecl, errmsg); + 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)); + } + + /* These bits are logically part of the type. */ + if (pedantic + && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) + || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) + cp_error_at ("type qualifiers for `%D' conflict with previous decl", newdecl); + } + + /* 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_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) + DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (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); + + 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); + } + /* why assert here? Just because debugging information is + messed up? (mrs) */ + /* it happens on something like: + typedef struct Thing { + Thing(); + int x; + } Thing; + */ +#if 0 + 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_SOURCE_LINE (olddecl) != 0 + && !(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 ("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); + /* Merge the data types specified in the two decls. */ + tree 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 (ctype, newtype, + TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); + TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype, + TYPE_RAISES_EXCEPTIONS (oldtype)); + + if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0)) + { + cp_error ("declaration of `%D' raises 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)) + { + 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); + } + + /* 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 (newdecl) = DECL_INITIAL (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); + } + /* 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. */ + if (DECL_EXTERNAL (newdecl)) + { + TREE_STATIC (newdecl) = TREE_STATIC (olddecl); + DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (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_ASSEMBLER_NAME (olddecl)) = 0; + } + else + TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); + } + else + { + TREE_STATIC (olddecl) = TREE_STATIC (newdecl); + /* A `const' which was not declared `extern' and is + in static storage is invisible. */ + if (TREE_CODE (newdecl) == VAR_DECL + && TREE_READONLY (newdecl) && TREE_STATIC (newdecl) + && ! DECL_THIS_EXTERN (newdecl)) + TREE_PUBLIC (newdecl) = 0; + 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) == NULL_TREE) + DECL_INLINE (olddecl) = 1; + DECL_INLINE (newdecl) = DECL_INLINE (olddecl); + + if (TREE_CODE (newdecl) == FUNCTION_DECL) + { + 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_SET_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); + } + } + + /* 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); + + /* 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); + } + + 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 + + /* Don't change DECL_CONTEXT of virtual methods. */ + if (x != current_function_decl + && (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) + 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); + } + + if (t != NULL_TREE) + { + if (TREE_CODE (t) == PARM_DECL) + { + if (DECL_CONTEXT (t) == NULL_TREE) + fatal ("parse errors have confused me too much"); + } + file = DECL_SOURCE_FILE (t); + line = DECL_SOURCE_LINE (t); + } + + if (t != NULL_TREE + && (TREE_CODE (t) != TREE_CODE (x) || is_overloaded_fn (t))) + { + if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL) + { + /* 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 (t != NULL_TREE && 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. */ + else 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; + } +#endif + + /* Due to interference in memory reclamation (X may be + obstack-deallocated at this point), we must guard against + one really special case. */ + if (current_function_decl == x) + current_function_decl = t; + + return t; + } + + /* 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); + + 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); + + if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name)) + set_nested_typename (x, current_class_name, + DECL_NAME (name), 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. + Avoid duplicate warnings where they are used. */ + if (TREE_PUBLIC (x) && !DECL_INLINE (x)) + { + 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 && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1) + /* If different sort of thing, we already gave an error. */ + && TREE_CODE (decl) == TREE_CODE (x) + /* If old decl is built-in, we already warned if we should. */ + && !DECL_BUILT_IN (decl)) + { + 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. */ + + /* Rule for VAR_DECLs, but not for other kinds of _DECLs: + A `const' which was not declared `extern' is invisible. */ + if (TREE_CODE (x) == VAR_DECL + && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x)) + TREE_PUBLIC (x) = 0; + + /* If the first global decl has external linkage, + warn if we later see static one. */ + if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) + TREE_PUBLIC (name) = 1; + + /* Don't install a TYPE_DECL if we already have another + sort of _DECL with that name. */ + if (TREE_CODE (x) != TYPE_DECL + || t == NULL_TREE + || TREE_CODE (t) == TYPE_DECL) + 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. */ + 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); + + 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); + + /* 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) && !DECL_INLINE (x) + && oldglobal != NULL_TREE + && TREE_CODE (x) == FUNCTION_DECL + && TREE_CODE (oldglobal) == FUNCTION_DECL) + { + /* We have one. Their types must agree. */ + if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1)) + { + cp_warning ("extern declaration of `%#D' doesn't match", x); + cp_warning_at ("global declaration `%#D'", oldglobal); + } + 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 + ? NULL_TREE : 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_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal)); + } + /* Keep the arg types from a file-scope fcn defn. */ + if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE + && DECL_INITIAL (oldglobal) + && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE) + TREE_TYPE (x) = TREE_TYPE (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); + } + /* 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 = 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 + && !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 storing a local value, there may already be one (inherited). + If so, record it for restoration when this binding level ends. */ + if (oldlocal != NULL_TREE) + b->shadowed = tree_cons (name, oldlocal, b->shadowed); + } + + /* Keep count of variables in this level with incomplete type. */ + if (TREE_CODE (x) != TEMPLATE_DECL + && TREE_CODE (x) != CPLUS_CATCH_DECL + && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE + && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) + { + if (++b->n_incomplete == 0) + error ("too many incomplete variables at this point"); + } + } + + if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE) + { + if (current_class_name) + { + if (!DECL_NESTED_TYPENAME (x)) + set_nested_typename (x, current_class_name, DECL_NAME (x), + TREE_TYPE (x)); + } + } + + /* 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) + { + push_class_level_binding (name, x); + if (TREE_CODE (x) == TYPE_DECL) + { + set_identifier_type_value (name, TREE_TYPE (x)); + if (!DECL_NESTED_TYPENAME (x)) + set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); + } + } + return x; +} + +/* 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; +{ + 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 IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL)) + 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 glob = IDENTIFIER_GLOBAL_VALUE (orig_name); + + DECL_OVERLOADED (decl) = 1; + + if (forgettable + && ! flag_traditional + && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1) + && !global_bindings_p () + && !pseudo_global_level_p ()) + overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget); + + if (glob) + { + if (DECL_LANGUAGE (decl) == lang_c) + { + tree decls = get_first_fn (glob); + while (decls && DECL_LANGUAGE (decls) == lang_cplusplus) + decls = DECL_CHAIN (decls); + if (decls) + { + cp_error_at ("C-language function `%#D'", decls); + cp_error ("overloaded as `%#D'", decl); + } + } + + /* 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 (glob) == ADDR_EXPR) + glob = TREE_OPERAND (glob, 0); + + else if (TREE_CODE (decl) == TEMPLATE_DECL) + { + tree tmp; + + for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp)) + if (decl == tmp) + return decl; + } + else if (TREE_CODE (glob) == VAR_DECL) + { + cp_error_at ("previous non-function declaration `%#D'", glob); + cp_error ("conflicts with function declaration `%#D'", decl); + return error_mark_node; + } + else if (is_overloaded_fn (glob)) + { + tree name = DECL_ASSEMBLER_NAME (decl); + tree tmp; + + for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp)) + { + if (TREE_CODE (tmp) == FUNCTION_DECL + && comptypes (TREE_TYPE (tmp), TREE_TYPE (decl), 2)) + { + if (DECL_LANGUAGE (tmp) != DECL_LANGUAGE (decl)) + { + if (current_lang_stack == current_lang_base) + { + DECL_LANGUAGE (decl) = DECL_LANGUAGE (tmp); + return tmp; + } + cp_error_at ("previous declaration of `%#D' with %L linkage", + tmp, DECL_LANGUAGE (tmp)); + cp_error ("conflicts with new %L-language declaration", + DECL_LANGUAGE (decl)); + } + else if (TREE_CODE (tmp) != TEMPLATE_DECL + && DECL_ASSEMBLER_NAME (tmp) != name) + { + cp_error ("new declaration `%#D'", decl); + cp_error_at ("ambiguates old declaration `%#D'", tmp); + } + } + /* If we really have seen this before, then if it ambiguates + something, we've already given an error before. */ + if (TREE_CODE (tmp) != TEMPLATE_DECL + && DECL_ASSEMBLER_NAME (tmp) == name) + return decl; + } + } + } + if (glob || TREE_CODE (decl) == TEMPLATE_DECL) + { + if (glob && is_overloaded_fn (glob)) + DECL_CHAIN (decl) = get_first_fn (glob); + else + DECL_CHAIN (decl) = NULL_TREE; + glob = tree_cons (orig_name, decl, NULL_TREE); + TREE_TYPE (glob) = unknown_type_node; + } + else + /* orig_name is not ambiguous. */ + glob = decl; + + IDENTIFIER_GLOBAL_VALUE (orig_name) = glob; + 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 + || current_binding_level == global_binding_level)) + 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 (newdecl, olddecl, 0)) + return 0; + else + return "redefinition of `%s'"; + } + 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; + + /* 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) != NULL_TREE + && DECL_INITIAL (newdecl) != NULL_TREE + /* 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)))) + { + if (DECL_NAME (olddecl) == NULL_TREE) + return "`%s' not declared in class"; + else + 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) != NULL_TREE + && DECL_INITIAL (newdecl) != NULL_TREE) + 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 + { + /* 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 `%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 == 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 (DECL_INITIAL (decl) != NULL_TREE) + { + cp_error ("duplicate label `%D'", decl); + return 0; + } + else + { + tree uses, prev; + + /* 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_SOURCE_LINE (new_decls) != 0 + && ((DECL_INITIAL (new_decls) != NULL_TREE + && DECL_INITIAL (new_decls) != error_mark_node) + || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) + { + if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE) + cp_error ("invalid jump to label `%D'", decl); + SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl); + cp_error ("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; + } +} + +/* 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 (); + if (cleanup) + { + static int explained = 0; + cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); + error ("where case label appears here"); + if (!explained) + { + error ("(enclose actions of previous case statements requiring"); + error ("destructors in their own binding contours.)"); + explained = 1; + } + } + + /* 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: + return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE; + break; + default: + my_friendly_abort (12); + } + } + 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 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 = 0, we prefer non-TYPE_DECLs. + If PREFER_TYPE is < 0, we arbitrate according to lexical context. */ + +tree +lookup_name (name, prefer_type) + tree name; + int prefer_type; +{ + register tree 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) + { + val = IDENTIFIER_CLASS_VALUE (name); + if (val == NULL_TREE + && TYPE_SIZE (current_class_type) == NULL_TREE + && 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, prefer_type < 0); + if (val == error_mark_node) + return val; + if (val && TREE_CODE (val) != TYPE_DECL) + val = NULL_TREE; + } + + /* 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, prefer_type != -2); + + if (val == NULL_TREE) + val = IDENTIFIER_GLOBAL_VALUE (name); + } + else + val = IDENTIFIER_GLOBAL_VALUE (name); + + if (val) + { + extern int looking_for_typename; + + /* Arbitrate between finding a TYPE_DECL and finding + other kinds of _DECLs. */ + if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0) + return val; + + if (IDENTIFIER_HAS_TYPE_VALUE (name)) + { + register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); + + if (val == val_as_type || prefer_type > 0 + || looking_for_typename > 0) + return val_as_type; + if (prefer_type == 0) + return val; + return arbitrate_lookup (name, val, val_as_type); + } + if (TREE_TYPE (val) == error_mark_node) + return error_mark_node; + } + + return val; +} + +/* 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) + { + for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) + if (DECL_NAME (t) == name) + break; + } + + 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_dossier) + { + 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_type_variant (TYPE_POINTER_TO (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_type_variant (TYPE_REFERENCE_TO (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); +} + +/* 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; + + /* Have to make these distinct before we try using them. */ + lang_name_cplusplus = get_identifier ("C++"); + lang_name_c = get_identifier ("C"); + + /* 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_dossier) + { + 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; + + pushlevel (0); /* make the binding_level structure for global names. */ + 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"); + + /* 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; + empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); + + /* 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_function ("__builtin_alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, "alloca"); +#if 0 + builtin_function ("alloca", + build_function_type (ptr_type_node, + tree_cons (NULL_TREE, + sizetype, + endlink)), + BUILT_IN_ALLOCA, NULL_PTR); +#endif + + 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, endlink), + 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); + } + +#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; +#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); + + /* 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)); + } + + /* Simplify life by making a "vtable_entry_type". Give its + fields names so that the debugger can use them. */ + + 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); + +#ifdef VTABLE_USES_MASK + /* This is primarily for virtual function definition. We + declare an array of `void *', which can later be + converted to the appropriate function pointer type. + To do pointers to members, we need a mask which can + distinguish an index value into a virtual function table + from an address. */ + vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1); +#endif + + vtbl_type_node + = build_array_type (vtable_entry_type, NULL_TREE); + layout_type (vtbl_type_node); + vtbl_type_node = 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, get_identifier (SIGTABLE_CODE_NAME), short_integer_type_node); + fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_OFFSET_NAME), short_integer_type_node); + fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_PFN_NAME), ptr_type_node); + finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2, + double_type_node); + sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); + record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); + } + + if (flag_dossier) + { + /* 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 (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE); + __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE); + __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__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"), + TYPE_POINTER_TO (__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"), + TYPE_POINTER_TO (__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"), + TYPE_POINTER_TO (__t_desc_type_node)); + fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), + TYPE_POINTER_TO (__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 (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE))); + finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node); + } + + /* Now, C++. */ + current_lang_name = lang_name_cplusplus; + if (flag_dossier) + { + 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; + } + } + + 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) 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 ("abort", + build_function_type (void_type_node, void_list_node), + NOT_BUILT_IN, 0, 0); + + unhandled_exception_fndecl + = define_function ("__unhandled_exception", + build_function_type (void_type_node, NULL_TREE), + NOT_BUILT_IN, 0, 0); + + /* Perform other language dependent initializations. */ + init_class_processing (); + init_init_processing (); + init_search_processing (); + + if (flag_handle_exceptions) + { + if (flag_handle_exceptions == 2) + /* Too much trouble to inline all the trys needed for this. */ + flag_this_is_variable = 2; + init_exception_processing (); + } + if (flag_gc) + init_gc_processing (); + if (flag_no_inline) + { + flag_inline_functions = 0; +#if 0 + /* This causes uneccessary 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 (); +} + +/* 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; + + /* 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_SET_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; + int warned = 0; + int static_or_extern = 0; + 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) + /* Used to test also that TYPE_SIZE (value) != 0. + That caused warning for `struct foo;' at top level in the file. */ + { + register tree name = TYPE_NAME (value); + + if (name == NULL_TREE) + name = lookup_tag_reverse (value, NULL_TREE); + + if (name && TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + t = lookup_tag (code, name, inner_binding_level, 1); + + if (t == NULL_TREE) + { + push_obstacks (&permanent_obstack, &permanent_obstack); + if (IS_AGGR_TYPE_CODE (code)) + t = make_lang_type (code); + else + t = make_node (code); + pushtag (name, t, 0); + pop_obstacks (); + ok_code = code; + break; + } + else if (name != NULL_TREE || code == ENUMERAL_TYPE) + ok_code = code; + + if (ok_code != ERROR_MARK) + found_tag++; + else + { + if (!warned) + pedwarn ("useless keyword or type name in declaration"); + warned = 1; + } + } + else if (value == ridpointers[(int) RID_STATIC] + || value == ridpointers[(int) RID_EXTERN]) + static_or_extern = 1; + } + + /* 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); + 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 + static/extern specifiers in this branch. */ + if (static_or_extern) + error ("static/extern can only be specified for objects and functions"); + + if (ok_code == RECORD_TYPE + && found_tag == 1 + && TYPE_LANG_SPECIFIC (t) + && CLASSTYPE_DECLARED_EXCEPTION (t)) + { + if (TYPE_SIZE (t)) + cp_error ("redeclaration of exception `%T'", t); + else + { + tree ename, decl; + + push_obstacks (&permanent_obstack, &permanent_obstack); + + pushclass (t, 0); + finish_exception (t, NULL_TREE); + + ename = TYPE_NAME (t); + if (TREE_CODE (ename) == TYPE_DECL) + ename = DECL_NAME (ename); + decl = build_lang_field_decl (VAR_DECL, ename, t); + finish_exception_decl (current_class_name, decl); + end_exception_decls (); + + pop_obstacks (); + } + } + else if (!warned && found_tag > 1) + warning ("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); +} + +/* 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, 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); + 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 (); + } + + /* Interesting work for this is done in `finish_exception_decl'. */ + if (TREE_CODE (type) == RECORD_TYPE + && CLASSTYPE_DECLARED_EXCEPTION (type)) + return decl; + + /* Corresponding pop_obstacks is done in `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)); + if (interface_unknown && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl)) + warn_if_unknown_interface (); + TREE_PUBLIC (d) = TREE_PUBLIC (decl) = flag_external_templates && !interface_unknown; + TREE_STATIC (d) = TREE_STATIC (decl); + DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) + && !(context && !DECL_THIS_EXTERN (decl))); + DECL_TEMPLATE_RESULT (d) = decl; + DECL_OVERLOADED (d) = 1; + decl = d; + } + + if (context && TYPE_SIZE (context) != NULL_TREE) + { + /* If it was not explicitly declared `extern', + revoke any previous claims of DECL_EXTERNAL. */ + if (DECL_THIS_EXTERN (decl) == 0) + DECL_EXTERNAL (decl) = 0; + if (DECL_LANG_SPECIFIC (decl)) + DECL_IN_AGGR_P (decl) = 0; + pushclass (context, 2); + } + + /* 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 `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) + { + 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_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 (current_binding_level != global_binding_level + && DECL_EXTERNAL (decl)) + cp_warning ("declaration of `%#D' has `extern' and is initialized", + decl); + 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; + } + + /* 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); + if (is_overloaded_fn (tem)) + { + tree tem2; + tem = get_first_fn (tem); + tem2 = decl_value_member (decl, tem); + + if (tem2 != NULL_TREE) + tem = tem2; + else + { + while (tem && ! decls_match (decl, tem)) + tem = DECL_CHAIN (tem); + if (tem == NULL_TREE) + tem = decl; + } + } + } + + /* Tell the back-end to use or not use .common as appropriate. */ + DECL_COMMON (tem) = flag_conserve_space; + +#if 0 + /* We don't do this yet for GNU C++. */ + /* 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) == 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) == FUNCTION_DECL && DECL_OVERLOADED (decl)) + /* @@ Also done in start_function. */ + tem = push_overloaded_decl (tem, 1); + else 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) == VAR_DECL */ 1) + { +#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)); +#endif + return tem; + } + my_friendly_abort (13); + } + else if (TREE_CODE (result) == FUNCTION_DECL) + tem = push_overloaded_decl (tem, 0); + else if (TREE_CODE (result) == VAR_DECL + || 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 (current_binding_level == global_binding_level && 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; +} + +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, + current_binding_level == global_binding_level); + tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); + } + + TREE_TYPE (tmp_addr) = build_pointer_type (target_type); + DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr); + TREE_TYPE (DECL_INITIAL (decl)) = type; + if (TYPE_NEEDS_CONSTRUCTING (target_type)) + { + if (current_binding_level == global_binding_level) + { + /* 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) = current_binding_level == global_binding_level; + finish_decl (tmp, init, 0, 0); + } + if (TREE_STATIC (tmp)) + preserve_initializer (); +} + +/* Handle initialization of references. + These three arguments from from `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; +{ + char *errstr = NULL; + int is_reference; + tree tmp; + tree this_ptr_type, actual_init = NULL_TREE; + + if (init == NULL_TREE) + { + if (DECL_LANG_SPECIFIC (decl) == 0 + || DECL_IN_AGGR_P (decl) == 0) + { + 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); + is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE; + tmp = is_reference ? convert_from_reference (init) : 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); + } + + /* Can we just enreference this lvalue? */ + if ((is_reference || lvalue_p (init) + || (actual_init = unary_complex_lvalue (ADDR_EXPR, init))) + && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), + TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0)) + { + /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */ + + /* A reference to a volatile T cannot be initialized with + a const T, and vice-versa. */ + if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init)) + errstr = "cannot initialize a reference to a volatile `%T' with a const `%T'"; + else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init)) + errstr = "cannot initialize a reference to a const `%T' with a volatile `%T'"; + /* A reference to a plain T can be initialized only with a plain T. */ + else if (!TYPE_VOLATILE (TREE_TYPE (type)) + && !TYPE_READONLY (TREE_TYPE (type))) + { + if (TREE_READONLY (init)) + errstr = "cannot initialize a reference to `%T' with a const `%T'"; + else if (TREE_THIS_VOLATILE (init)) + errstr = "cannot initialize a reference to `%T' with a volatile `%T'"; + } + if (errstr) + { + cp_error (errstr, TREE_TYPE (type), TREE_TYPE (tmp)); + goto fail; + } + } + /* OK, can we generate a reference then? */ + else if ((actual_init = convert_to_reference + (decl, type, init, 0, 0, "initialization", 0, + LOOKUP_SPECULATIVELY|LOOKUP_NORMAL))) + { + if (actual_init == error_mark_node) + goto fail; + + init = actual_init; + is_reference = 1; + } + /* OK, try going through a temporary. */ + else if ((actual_init = convert_to_reference + (error_mark_node, type, init, 0, 0, "initialization", + 0, LOOKUP_NORMAL))) + { + if (actual_init == error_mark_node) + goto fail; + + init = actual_init; + is_reference = 1; + + if (TREE_CODE (init) == WITH_CLEANUP_EXPR) + { + /* Associate the cleanup with the reference so that we + don't get burned by "aggressive" cleanup policy. */ + *cleanupp = TREE_OPERAND (init, 2); + TREE_OPERAND (init, 2) = error_mark_node; + } + } + else + { + cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); + goto fail; + } + + /* In the case of initialization, it is permissible + to assign one reference to another. */ + this_ptr_type = build_pointer_type (TREE_TYPE (type)); + + if (is_reference) + { + if (TREE_SIDE_EFFECTS (init)) + DECL_INITIAL (decl) = save_expr (init); + else + DECL_INITIAL (decl) = init; + } + else if (lvalue_p (init)) + { + tmp = build_unary_op (ADDR_EXPR, init, 0); + if (TREE_CODE (tmp) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR) + { + if (*cleanupp) my_friendly_abort (1); + *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2); + TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node; + } + if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type))) + DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp); + else + DECL_INITIAL (decl) = convert (this_ptr_type, tmp); + + DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); + if (DECL_INITIAL (decl) == current_class_decl) + DECL_INITIAL (decl) = copy_node (current_class_decl); + TREE_TYPE (DECL_INITIAL (decl)) = type; + } + /* If actual_init is set here, it is set from the first check above. */ + else if (actual_init) + { + /* The initializer for this decl goes into its + DECL_REFERENCE_SLOT. Make sure that we can handle + multiple evaluations without ill effect. */ + if (TREE_CODE (actual_init) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR) + actual_init = save_expr (actual_init); + DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init); + DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); + TREE_TYPE (DECL_INITIAL (decl)) = type; + } + else + my_friendly_abort (1); + + done: + /* ?? 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; +} + +/* 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++, `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. + + For functions that take default parameters, DECL points to its + "maximal" instantiation. `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 +finish_decl (decl, init, asmspec_tree, need_pop) + tree decl, init; + tree asmspec_tree; + int need_pop; +{ + 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 (asmspec_tree) + { + asmspec = TREE_STRING_POINTER (asmspec_tree); + /* Zero out old RTL, since we will rewrite it. */ + DECL_RTL (decl) = NULL_RTX; + } + + /* 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); + + 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 (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 (type != error_mark_node && IS_AGGR_TYPE (type) + && CLASSTYPE_DECLARED_EXCEPTION (type)) + { + finish_exception_decl (NULL_TREE, decl); + CLASSTYPE_GOT_SEMICOLON (type) = 1; + 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. + + @@ Should emit an error if this redefines an asm-specified + @@ name, or if we have already used the function's name. */ + 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))) + { + grok_reference_init (decl, type, init, &cleanup); + init = NULL_TREE; + } + + GNU_xref_decl (current_function_decl, decl); + + if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (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 + && CONSTRUCTOR_ELTS (init) != NULL_TREE) + { + if (TYPE_NEEDS_CONSTRUCTING (type)) + { + cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl); + init = error_mark_node; + } + else + goto dont_use_constructor; + } +#if 0 + /* fix this in `build_functional_cast' instead. + Here's the trigger code: + + struct ostream + { + ostream (); + ostream (int, char *); + ostream (char *); + operator char *(); + ostream (void *); + operator void *(); + operator << (int); + }; + int buf_size = 1024; + static char buf[buf_size]; + const char *debug(int i) { + char *b = &buf[0]; + ostream o = ostream(buf_size, b); + o << i; + return buf; + } + */ + + else if (TREE_CODE (init) == TARGET_EXPR + && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR)) + { + /* User wrote something like `foo x = foo (args)' */ + my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150); + my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151); + + /* User wrote exactly `foo x = foo (args)' */ + if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init)) + { + init = build (CALL_EXPR, TREE_TYPE (init), + TREE_OPERAND (TREE_OPERAND (init, 1), 0), + TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0); + TREE_SIDE_EFFECTS (init) = 1; + } + } +#endif + + /* We must hide the initializer so that expand_decl + won't try to do something it does not understand. */ + if (current_binding_level == global_binding_level) + { + tree value; + if (flag_conserve_space) + /* If we say -fconserve-space, we want this to save + space, at the expense of wrong semantics. */ + /* Should this be a NULL_TREE? */ + value = error_mark_node; + else + /* If we say -fno-conserve-space, we want this to + produce errors about redefs, to do this we make it + go in the data space */ + value = digest_init (type, empty_init_node, (tree *) 0); + DECL_INITIAL (decl) = value; + } + else + DECL_INITIAL (decl) = error_mark_node; + } + else + { + dont_use_constructor: + if (TREE_CODE (init) != TREE_VEC) + init = store_init_value (decl, init); + + if (init) + /* Don't let anyone try to initialize this variable + until we are ready to do so. */ + DECL_INITIAL (decl) = error_mark_node; + } + } + 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); + + /* Initialize variables in need of static initialization + with `empty_init_node' to keep assemble_variable from putting them + in the wrong program space. (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.) */ + if (flag_pic == 0 + && TREE_STATIC (decl) + && TREE_PUBLIC (decl) + && ! DECL_EXTERNAL (decl) + && TREE_CODE (decl) == VAR_DECL + && TYPE_NEEDS_CONSTRUCTING (type) + && (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + /* If we say -fconserve-space, we want this to save space, + at the expense of wrong semantics. */ + && ! flag_conserve_space) + { + tree value = digest_init (type, empty_init_node, (tree *) 0); + DECL_INITIAL (decl) = value; + } + } + 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 (current_binding_level == global_binding_level && 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 ((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; + current_binding_level->more_exceptions_ok = 0; + } + 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 = (current_binding_level == global_binding_level + || 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 we are in need of a cleanup, get out of any implicit + handlers that have been established so far. */ + if (cleanup && current_binding_level->parm_flag == 3) + { + pop_implicit_try_blocks (decl); + current_binding_level->more_exceptions_ok = 0; + } + + if (TREE_CODE (decl) == VAR_DECL + && current_binding_level != global_binding_level + && ! 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 + && DECL_INITIAL (decl) != empty_init_node) + { + 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) + { + /* Keep GCC from complaining that this variable + is defined but never used. */ + TREE_USED (decl) = 1; + /* If this is a static const, change its apparent linkage + if it belongs to a #pragma interface. */ + if (TREE_STATIC (decl) && !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) + { + /* C++: Handle overloaded functions with default parameters. */ + if (DECL_OVERLOADED (decl)) + { + tree parmtypes = TYPE_ARG_TYPES (type); + tree prev = NULL_TREE; + tree original_name = DECL_NAME (decl); + struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl); + /* All variants will share an uncollectible lang_decl. */ + copy_decl_lang_specific (decl); + + while (parmtypes && parmtypes != void_list_node) + { + /* The default value for the parameter in parmtypes is + stored in the TREE_PURPOSE of the TREE_LIST. */ + if (TREE_PURPOSE (parmtypes)) + { + tree fnname, fndecl; + tree *argp; + + argp = prev ? & TREE_CHAIN (prev) + : & TYPE_ARG_TYPES (type); + + *argp = NULL_TREE; + fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0); + *argp = parmtypes; + fndecl = build_decl (FUNCTION_DECL, fnname, type); + DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl); + TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl); + DECL_INLINE (fndecl) = DECL_INLINE (decl); + /* Keep G++ from thinking this function is unused. + It is only used to speed up search in name space. */ + TREE_USED (fndecl) = 1; + TREE_ASM_WRITTEN (fndecl) = 1; + DECL_INITIAL (fndecl) = NULL_TREE; + DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl); + fndecl = pushdecl (fndecl); + DECL_INITIAL (fndecl) = error_mark_node; + DECL_RTL (fndecl) = DECL_RTL (decl); + } + prev = parmtypes; + parmtypes = TREE_CHAIN (parmtypes); + } + DECL_LANG_SPECIFIC (decl) = tmp_lang_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) + expand_static_init (decl, init); + else if (TYPE_NEEDS_DESTRUCTOR (type)) + static_aggregates = perm_tree_cons (NULL_TREE, decl, + static_aggregates); + + /* Make entry in appropriate vector. */ + if (flag_gc && type_needs_gc_entry (type)) + build_static_gc_entry (decl, type); + } + else if (! toplev) + { + /* 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) + { + expand_decl_cleanup (NULL_TREE, cleanup); + /* 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); + } + + /* Set this to 0 so we can tell whether an aggregate + which was initialized was ever used. */ + if (TYPE_NEEDS_CONSTRUCTING (type)) + TREE_USED (decl) = 0; + + /* Store the cleanup, if there was one. */ + if (cleanup) + { + if (! expand_decl_cleanup (decl, cleanup)) + cp_error ("parser lost in parsing declaration of `%D'", decl); + } + } + } + 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_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 (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); +} + +void +expand_static_init (decl, init) + tree decl; + tree init; +{ + tree oldstatic = value_member (decl, static_aggregates); + if (oldstatic) + { + if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) + cp_error ("multiple initializations given for `%D'", decl); + } + else if (current_binding_level != global_binding_level) + { + /* 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); + expand_assignment (temp, integer_one_node, 0, 0); + if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) + { + expand_aggr_init (decl, init, 0); + do_pending_stack_adjust (); + } + else + expand_assignment (decl, init, 0, 0); + 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) + maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0); + else if (TREE_CODE (initial_value) == CONSTRUCTOR) + { + register int nelts + = list_length (CONSTRUCTOR_ELTS (initial_value)); + maxindex = build_int_2 (nelts - 1, - (nelts == 0)); + } + 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); + } + + /* 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 raises declaration", 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, check, publicp) + tree ctype, type; + tree declarator; + int virtualp; + enum overload_flags flags; + tree quals, raises; + int check, publicp; +{ + 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 (ctype, 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; + } + + if (publicp) + TREE_PUBLIC (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); + grok_ctor_properties (ctype, decl); + if (check == 0) + { + /* 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). + Pretend we are at top level, we will get true + reference later, perhaps. + + 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); + + /* 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_first_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; + +#if 0 + /* Disable this as we want the most recent fndecl, not the most + base fndecl. */ + if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo)) + || TYPE_USES_MULTIPLE_INHERITANCE (ctype)) + && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp)) + tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)), + decl, flags == DTOR_FLAG); +#endif + if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE) + { + /* 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 (ctype, type, raises); + raises = TYPE_RAISES_EXCEPTIONS (type); + } + TREE_TYPE (decl) = type; + DECL_VINDEX (decl) + = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); + } + } + } + } + } + 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) + tree type; + tree declarator; + RID_BIT_TYPE specbits; + int initialized; +{ + 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 field = lookup_field (TYPE_OFFSET_BASETYPE (type), + declarator, 0, 0); + if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) + { + tree basetype = TYPE_OFFSET_BASETYPE (type); + error ("`%s' is not a static member of class `%s'", + IDENTIFIER_POINTER (declarator), + TYPE_NAME_STRING (basetype)); + type = TREE_TYPE (type); + decl = build_lang_field_decl (VAR_DECL, declarator, type); + DECL_CONTEXT (decl) = basetype; + DECL_CLASS_CONTEXT (decl) = basetype; + } + else + { + tree f_type = TREE_TYPE (field); + tree o_type = TREE_TYPE (type); + + if (TYPE_SIZE (f_type) == NULL_TREE) + { + if (TREE_CODE (f_type) != TREE_CODE (o_type) + || (TREE_CODE (f_type) == ARRAY_TYPE + && TREE_TYPE (f_type) != TREE_TYPE (o_type))) + error ("redeclaration of type for `%s'", + IDENTIFIER_POINTER (declarator)); + else if (TYPE_SIZE (o_type) != NULL_TREE) + TREE_TYPE (field) = type; + } + else if (f_type != o_type) + error ("redeclaration of type for `%s'", + IDENTIFIER_POINTER (declarator)); + decl = field; + if (initialized && DECL_INITIAL (decl) + /* Complain about multiply-initialized + member variables, but don't be faked + out if initializer is faked up from `empty_init_node'. */ + && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR + || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE)) + error_with_aggr_type (DECL_CONTEXT (decl), + "multiple initializations of static member `%s::%s'", + IDENTIFIER_POINTER (DECL_NAME (decl))); + } + } + else + decl = build_decl (VAR_DECL, declarator, type); + + 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) = !initialized; + } + /* At top level, either `static' or no s.c. makes a definition + (perhaps tentative), and absence of `static' makes it public. */ + else if (current_binding_level == global_binding_level) + { + TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits); + 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); + 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; + + 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. + 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) + tree declspecs; + tree declarator; + enum decl_context decl_context; + int initialized; + tree raises; +{ + RID_BIT_TYPE specbits; + int nclasses = 0; + tree spec; + tree type = NULL_TREE; + int longlong = 0; + int constp; + int volatilep; + int virtualp, 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; + /* 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; + int seen_scope_ref = 0; + 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 type, 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 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, 1); + return 0; + } + innermost_code = TREE_CODE (decl); + decl = TREE_OPERAND (decl, 0); + if (decl_context == FIELD && ctype == NULL_TREE) + ctype = current_class_type; + 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; + name = IDENTIFIER_POINTER (decl); + decl = NULL_TREE; + 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; + + case TYPE_EXPR: + my_friendly_assert (flags == NO_SPECIAL, 154); + flags = TYPENAME_FLAG; + name = "operator "; /* We don't know the type yet. */ + /* Go to the absdcl. */ + decl = TREE_OPERAND (decl, 0); + return_type = return_conversion; + break; + + /* C++ extension */ + case SCOPE_REF: +/* + if (seen_scope_ref == 1) + error ("multiple `::' terms in declarator invalid"); +*/ + seen_scope_ref += 1; + { + /* 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; + } + } + + 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)) + { + return_type = return_dtor; + ctor_return_type = ctype; + flags = DTOR_FLAG; + decl = TREE_OPERAND (decl, 0); + } + } + } + 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; + + /* 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). */ + + if (decl_context == NORMAL + && current_binding_level->level_chain == global_binding_level) + 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 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]) + { + if (type) + error ("extraneous `int' ignored"); + else + { + explicit_int = 1; + type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); + } + goto found; + } + if (id == ridpointers[(int) RID_CHAR]) + { + if (type) + error ("extraneous `char' ignored"); + else + { + explicit_char = 1; + type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); + } + goto found; + } + if (id == ridpointers[(int) RID_WCHAR]) + { + if (type) + error ("extraneous `__wchar_t' ignored"); + else + { + 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_MAX; i++) + { + if (ridpointers[i] == id) + { + if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) + { +#if 0 + if (pedantic) + pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); + else +#endif + if (longlong) + error ("`long long long' is too long for GCC"); + else + longlong = 1; + } + else if (RIDBIT_SETP (i, specbits)) + warning ("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); + 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) + { + explicit_int = -1; + if (return_type == return_dtor) + type = void_type_node; + else if (return_type == return_ctor) + type = TYPE_POINTER_TO (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); + } + else + { + if (funcdef_flag && warn_return_type + && return_type == return_normal + && ! (RIDBIT_SETP (RID_SIGNED, specbits) + || RIDBIT_SETP (RID_UNSIGNED, specbits) + || RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits))) + warn_about_return_type = 1; + /* Save warning until we know what is really going on. */ + 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 = TYPE_POINTER_TO (ctor_return_type); + } + + 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 || type == wchar_type_node) + 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 (constp > 1) + warning ("duplicate `const'"); + if (volatilep > 1) + warning ("duplicate `volatile'"); + virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); + + /* operators new and delete are implicitly static. */ + 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_VIRTUAL, 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); + } + else if (staticp) + { + error ("static `%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) + { + 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 + && (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 splice it out of the chain of declspecs, 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); + + /* 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); + + 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); + + 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)) + /* 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 = TREE_OPERAND (declarator, 0); + register int 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" : "structure field"), + op ? operator_name_string (tmp) : name); + } + else + error ((decl_context == PARM + ? "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 (current_binding_level == global_binding_level) + { + /* It's common practice (and completely legal) 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 + && current_binding_level != global_binding_level) + error ("nested function `%s' declared `extern'", name); + else if (current_binding_level == global_binding_level) + { + 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) + a TYPE_EXPR (for operator typenames) + + 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); + + 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 legal 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)) + { + constant_expression_warning (size); + if (INT_CST_LT (size, integer_zero_node)) + { + cp_error ("size of array `%D' is negative", dname); + size = integer_one_node; + } + itype = build_index_type (size_binop (MINUS_EXPR, size, + integer_one_node)); + } + else + { + if (pedantic) + cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname); + dont_grok_size: + itype = + build_binary_op (MINUS_EXPR, size, integer_one_node, 1); + /* Make sure the array size remains visibly nonconstant + even if it is (eg) a const variable with known value. */ + size_varies = 1; + 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) + /* Should this be c_build_type_variant? -jason */ + type = build_type_variant (type, constp, volatilep); + + ctype = NULL_TREE; + } + break; + + case CALL_EXPR: + { + tree arg_types; + + /* 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 target type + for the pointer. */ + + if (constp || volatilep) + { + type = 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 (ctype == NULL_TREE + && decl_context == FIELD + && (friendp == 0 || dname == current_class_name)) + ctype = current_class_type; + + if (ctype && flags == TYPENAME_FLAG) + 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 (TYPE_READONLY (type)) + { + error ("destructors cannot be declared `const'"); + return void_type_node; + } + if (TYPE_VOLATILE (type)) + { + error ("destructors cannot be declared `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. */ + { + /* 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 (TYPE_READONLY (type)) + { + error ("constructors cannot be declared `const'"); + return void_type_node; + } + if (TYPE_VOLATILE (type)) + { + error ("constructors cannot be declared `volatile'"); + return void_type_node; + } + { + int inlinep, staticp; + inlinep = RIDBIT_SETP (RID_INLINE, specbits); + staticp = RIDBIT_SETP (RID_STATIC, specbits); + RIDBIT_RESET (RID_INLINE, specbits); + RIDBIT_RESET (RID_STATIC, specbits); + if (RIDBIT_ANY_SET (specbits)) + error ("return value type specifier for constructor ignored"); + if (inlinep) + RIDBIT_SET (RID_INLINE, specbits); + if (staticp) + RIDBIT_SET (RID_STATIC, specbits); + } + type = TYPE_POINTER_TO (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 && virtualp) + { + /* Cannot be both friend and virtual. */ + error ("virtual functions cannot be friends"); + RIDBIT_RESET (RID_FRIEND, specbits); + friendp = 0; + } + + if (decl_context == NORMAL && friendp) + error ("friend declaration not in class definition"); + + /* Pick up type qualifiers which should be applied to `this'. */ + quals = TREE_OPERAND (declarator, 2); + + /* 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. */ + + { + int funcdef_p; + tree inner_parms = TREE_OPERAND (declarator, 1); + tree inner_decl = TREE_OPERAND (declarator, 0); + + declarator = TREE_OPERAND (declarator, 0); + + if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) + inner_decl = TREE_OPERAND (inner_decl, 1); + + /* Say it's a definition only for the CALL_EXPR + closest to the identifier. */ + funcdef_p = + (inner_decl && + (TREE_CODE (inner_decl) == IDENTIFIER_NODE + || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0; + + /* FIXME: This is where default args should be fully + processed. */ + + arg_types = grokparms (inner_parms, funcdef_p); + } + + 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; + } + + /* 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 = 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) + warning ("empty signature `%s' used in signature reference declaration", + TYPE_NAME_STRING(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) + warning ("empty signature `%s' used in signature pointer declaration", + TYPE_NAME_STRING(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) + warning ("duplicate `const'"); + if (volatilep > 1) + warning ("duplicate `volatile'"); + } + 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) + { + /* I'm not really sure what pushclass calls this popclass + corresponds to. One is in build_push_scope and that has + been changed to a push_nested_class call, that's why I + try to use pop_nested_class here instead. + -niklas@appli.se */ + 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 (TREE_CODE (type) == FUNCTION_TYPE) + { + if (current_class_type == NULL_TREE + || TYPE_MAIN_VARIANT (ctype) == current_class_type + || friendp) + type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), + TREE_TYPE (type), TYPE_ARG_TYPES (type)); + else + { + error ("cannot declare member function `%s::%s' within this class", + TYPE_NAME_STRING (ctype), name); + return void_type_node; + } + } + else if (TYPE_MAIN_VARIANT (ctype) == current_class_type) + { + if (extra_warnings) + warning ("extra qualification `%s' on member `%s' ignored", + TYPE_NAME_STRING (ctype), name); + type = build_offset_type (ctype, type); + } + 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; */ + + 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) + error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname)); + 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; + } + + if (flags == TYPENAME_FLAG) + cp_error ("type conversion is not a member of structure `%T'", ctype); + else + cp_error + ("field `%D' is not a member of structure `%T'", + sname, ctype); + } + + if (current_class_type) + { + if (TYPE_MAIN_VARIANT (ctype) != current_class_type) + { + cp_error ("cannot declare member `%T::%s' within `%T'", + ctype, name, current_class_type); + return void_type_node; + } + else if (extra_warnings) + cp_warning ("extra qualification `%T' on member `%s' ignored", + ctype, name); + } + 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) == TYPE_EXPR) + { + /* A TYPE_EXPR will change types out from under us. + So do the TYPE_EXPR now, and make this SCOPE_REF + inner to the TYPE_EXPR's CALL_EXPR. + + This does not work if we don't get a CALL_EXPR back. + I did not think about error recovery, hence the + my_friendly_abort. */ + + /* Get the CALL_EXPR. */ + sname = grokoptypename (sname, 0); + my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157); + type = TREE_TYPE (TREE_OPERAND (sname, 0)); + /* Scope the CALL_EXPR's name. */ + TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0); + /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position. */ + TREE_OPERAND (sname, 0) = declarator; + /* Now work from the CALL_EXPR. */ + declarator = sname; + continue; + } + 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 TYPE_EXPR: + declarator = grokoptypename (declarator, 0); + if (explicit_int != -1) + { + tree stype = TREE_TYPE (TREE_OPERAND (declarator, 0)); + if (comp_target_types (type, stype, 1) == 0) + cp_error ("`operator %T' declared to return `%T'", stype, + type); + else + cp_pedwarn ("return type specified for `operator %T'", type); + } + dname = declarator; + type = TREE_TYPE (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); + } + } + + /* Now TYPE has the actual type. */ + + /* If this is declaring a typedef name, return a TYPE_DECL. */ + + if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + { + tree decl; + + /* Note that the grammar rejects storage classes + in typenames, fields or parameters. */ + if (constp || volatilep) + type = 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); + } + } + +#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); + TREE_TYPE (decl) = error_mark_node; + } + 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 = build_type_variant (type, constp, volatilep); + + /* Special case: "friend class foo" looks like a TYPENAME context. */ + if (friendp) + { + /* 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 + && 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 (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) + { + tree parmtype = type; + + 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. + + Don't be misled by references. */ + + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + if (TREE_CODE (type) == ARRAY_TYPE) + { + if (parmtype == type) + { + /* Transfer const-ness of array into that of type + pointed to. */ + type = build_pointer_type + (build_type_variant (TREE_TYPE (type), constp, volatilep)); + volatilep = constp = 0; + } + else + type = build_pointer_type (TREE_TYPE (type)); + } + else if (TREE_CODE (type) == FUNCTION_TYPE) + type = build_pointer_type (type); + else if (TREE_CODE (type) == OFFSET_TYPE) + type = build_pointer_type (type); + + if (TREE_CODE (parmtype) == REFERENCE_TYPE) + { + /* Transfer const-ness of reference into that of type pointed to. */ + type = build_type_variant (build_reference_type (type), constp, volatilep); + constp = volatilep = 0; + } + + 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; + if (TYPE_MAIN_VARIANT (type) == float_type_node) + DECL_ARG_TYPE (decl) = build_type_variant (double_type_node, + TYPE_READONLY (type), + TYPE_VOLATILE (type)); + else if (C_PROMOTING_INTEGER_TYPE_P (type)) + { + tree argtype; + + /* Retain unsignedness if traditional or if not really + getting wider. */ + if (TREE_UNSIGNED (type) + && (flag_traditional + || TYPE_PRECISION (type) + == TYPE_PRECISION (integer_type_node))) + argtype = unsigned_type_node; + else + argtype = integer_type_node; + DECL_ARG_TYPE (decl) = build_type_variant (argtype, + TYPE_READONLY (type), + TYPE_VOLATILE (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) 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 = (RIDBIT_SETP (RID_EXTERN, specbits) + || (ctype != NULL_TREE && funcdef_flag >= 0) + || (friendp + && ! funcdef_flag + && RIDBIT_NOTSETP (RID_STATIC, specbits) + && RIDBIT_NOTSETP (RID_INLINE, specbits))); + decl = grokfndecl (ctype, type, declarator, + virtualp, flags, quals, + raises, friendp ? -1 : 0, publicp); + DECL_INLINE (decl) = inlinep; + } + else if (TREE_CODE (type) == METHOD_TYPE) + { + /* All method decls are public, so tell grokfndecl to set + TREE_PUBLIC, also. */ + decl = grokfndecl (ctype, type, declarator, + virtualp, flags, quals, + raises, friendp ? -1 : 0, 1); + DECL_INLINE (decl) = inlinep; + } + else if (TREE_CODE (type) == RECORD_TYPE + && CLASSTYPE_DECLARED_EXCEPTION (type)) + { + /* Handle a class-local exception declaration. */ + decl = build_lang_field_decl (VAR_DECL, declarator, type); + if (ctype == NULL_TREE) + ctype = current_class_type; + finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL + ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl); + return void_type_node; + } + else if (TYPE_SIZE (type) == NULL_TREE && !staticp + && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) + { + error ("field `%s' has incomplete type", + IDENTIFIER_POINTER (declarator)); + + /* 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) + error (" in instantiation of template `%s'", + TYPE_NAME_STRING (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) + { + /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2. A member-declarator + cannot have an initializer, and a static member declaration must + be defined elsewhere. */ + if (initialized) + { + if (staticp) + error ("static member `%s' must be defined separately from its declaration", + IDENTIFIER_POINTER (declarator)); + /* 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 + aggregate) is the only way to initialize nonstatic const + and reference members. */ + else + pedwarn ("ANSI C++ forbids initialization of %s `%s'", + constp ? "const member" : "member", + IDENTIFIER_POINTER (declarator)); + } + + if (staticp || (constp && initialized)) + { + /* 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); + if (staticp || TREE_CODE (type) == ARRAY_TYPE) + TREE_STATIC (decl) = 1; + /* In class context, static means public access. */ + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = !initialized; + } + 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) + { + int was_overloaded = 0; + tree original_name = declarator; + int publicp = 0; + + if (! declarator) + return NULL_TREE; + + if (RIDBIT_SETP (RID_AUTO, specbits) + || RIDBIT_SETP (RID_REGISTER, specbits)) + 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 + && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits)) + && pedantic) + pedwarn ("invalid storage class for function `%s'", 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); + was_overloaded = 1; + } + } + 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' is like `static'. + Methods of classes should be public, unless we're dropping them + into some other file, so we don't clear TREE_PUBLIC for them. */ + publicp + = ((ctype + && CLASSTYPE_INTERFACE_KNOWN (ctype) + && ! CLASSTYPE_INTERFACE_ONLY (ctype)) + || !(RIDBIT_SETP (RID_STATIC, specbits) + || RIDBIT_SETP (RID_INLINE, specbits))); + + decl = grokfndecl (ctype, type, original_name, + virtualp, flags, quals, + raises, + processing_template_decl ? 0 : friendp ? 2 : 1, + publicp); + + if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c) + DECL_ASSEMBLER_NAME (decl) = 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_error_at ("cannot declare member function `%D' to have static linkage", decl); + illegal_static = 1; + } + else if (! was_overloaded + && ! ctype + && IDENTIFIER_LENGTH (original_name) == 4 + && IDENTIFIER_POINTER (original_name)[0] == 'm' + && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) + { + error ("cannot declare function `main' to have static linkage"); + 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); + } + } + + /* Record presence of `inline', if it is reasonable. */ + if (inlinep) + { + tree last = tree_last (TYPE_ARG_TYPES (type)); + + if (! was_overloaded + && ! ctype + && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) + error ("cannot inline function `main'"); + else if (last && last != void_list_node) + cp_warning ("cannot inline function `%D' which takes `...'", original_name); + else + /* Assume that otherwise the function can be inlined. */ + DECL_INLINE (decl) = 1; + + if (RIDBIT_SETP (RID_EXTERN, specbits)) + { + current_extern_inline = 1; + if (flag_ansi || pedantic || flag_pedantic_errors) + pedwarn ("ANSI C++ does not permit `extern inline'"); + } + } + if (was_overloaded) + DECL_OVERLOADED (decl) = 1; + } + else + { + /* It's a variable. */ + + /* An uninitialized decl with `extern' is a reference. */ + decl = grokvardecl (type, declarator, specbits, initialized); + bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, + inlinep, friendp, raises != NULL_TREE); + + if (ctype) + { + if (staticp == 1) + { + cp_error ("static member `%D' re-declared as static", + decl); + staticp = 0; + RIDBIT_RESET (RID_STATIC, specbits); + } + if (RIDBIT_SETP (RID_EXTERN, specbits)) + { + cp_error ("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; + + /* 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 (current_binding_level == global_binding_level) + { + /* 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); + 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) + { + 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); + } + else if (any_init) + { + error ("all trailing parameters must have default arguments"); + any_error = 1; + } + } + 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. */ +void +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); + TYPE_GETS_INIT_AGGR (ctype) = 1; + } + else if (TREE_CODE (parmtype) == VOID_TYPE + || TREE_PURPOSE (parmtypes) != NULL_TREE) + TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; +} + +/* An operator with this name can be either unary or binary. */ +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. */ +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); + tree t; + + if (! friendp) + for (t = current_class_type; t; t = TYPE_NEXT_VARIANT (t)) + { + if (name == ansi_opname[(int) MODIFY_EXPR]) + TYPE_HAS_ASSIGNMENT (t) = 1; + else if (name == ansi_opname[(int) CALL_EXPR]) + TYPE_OVERLOADS_CALL_EXPR (t) = 1; + else if (name == ansi_opname[(int) ARRAY_REF]) + TYPE_OVERLOADS_ARRAY_REF (t) = 1; + else if (name == ansi_opname[(int) COMPONENT_REF] + || name == ansi_opname[(int) MEMBER_REF]) + TYPE_OVERLOADS_ARROW (t) = 1; + else if (name == ansi_opname[(int) NEW_EXPR]) + { + if (TREE_CHAIN (argtypes) == void_list_node) + TREE_GETS_NEW (t) = 1; + else + TREE_GETS_PLACED_NEW (t) = 1; + } + else if (name == ansi_opname[(int) DELETE_EXPR]) + TREE_GETS_DELETE (t) = 1; +#if 0 + else if (name == ansi_opname[(int) VEC_NEW_EXPR]) + TREE_GETS_NEW (t) = 1; + else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) + TREE_GETS_DELETE (t) = 1; +#endif + } + + if (name == ansi_opname[(int) NEW_EXPR]) + { +#if 0 + /* 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. */ + my_friendly_assert (!methodp, 355); +#endif + + /* 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 + decl = coerce_new_type (TREE_TYPE (decl)); + } +#if 0 + else if (name == ansi_opname[(int) VEC_NEW_EXPR]) + { + } +#endif + else if (name == ansi_opname[(int) DELETE_EXPR]) + { +#if 0 + my_friendly_assert (!methodp, 355); +#endif + + if (argtypes == NULL_TREE) + TREE_TYPE (decl) = + build_function_type (void_type_node, + hash_tree_chain (ptr_type_node, + void_list_node)); + else + decl = coerce_delete_type (TREE_TYPE (decl)); + } +#if 0 + else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) + { + } +#endif + 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) + { + 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 (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 (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 (TREE_CODE (parmtype) == REFERENCE_TYPE + && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) + == current_class_type) + { + TYPE_HAS_ASSIGN_REF (current_class_type) = 1; + if (TYPE_READONLY (TREE_TYPE (parmtype))) + TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; + } + } + 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.) */ + +/* avoid rewriting all callers of xref_tag */ +static int xref_next_defn = 0; + +tree +xref_defn_tag (code_type_node, name, binfo) + tree code_type_node; + tree name, binfo; +{ + tree rv, ncp; + xref_next_defn = 1; + + if (class_binding_level) + { + tree n1; + char *buf; + /* we need to build a new IDENTIFIER_NODE for name which nukes + * the pieces... */ +/* + n1 = IDENTIFIER_LOCAL_VALUE (current_class_name); + if (n1) + n1 = DECL_NAME (n1); + else + n1 = current_class_name; +*/ + n1 = TYPE_NAME(current_class_type); + if (n1) + n1 = DECL_NESTED_TYPENAME(n1); + else + n1 = current_class_name; + + buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1) + + IDENTIFIER_LENGTH (name)); + + sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1), + IDENTIFIER_POINTER (name)); + ncp = get_identifier (buf); +#ifdef SPEW_DEBUG + if (spew_debug) + printf("*** %s ***\n", IDENTIFIER_POINTER (ncp)); +#endif +#if 0 + IDENTIFIER_LOCAL_VALUE (name) = + build_lang_decl (TYPE_DECL, ncp, NULL_TREE); +#endif + rv = xref_tag (code_type_node, name, binfo, 0); + if (! ANON_AGGRNAME_P (name)) + { + register tree type_decl = build_lang_decl (TYPE_DECL, ncp, rv); +#ifdef DWARF_DEBUGGING_INFO + /* 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. */ + if (write_symbols == DWARF_DEBUG) + DECL_IGNORED_P (type_decl) = 1; +#endif /* DWARF_DEBUGGING_INFO */ + pushdecl_top_level (type_decl); + } + } + else + { + rv = xref_tag (code_type_node, name, binfo, 0); + } + xref_next_defn = 0; + return rv; +} + +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, len; + 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 exception_type: + case signature_type: + code = RECORD_TYPE; + len = list_length (binfo); + break; + case union_type: + code = UNION_TYPE; + if (binfo) + { + cp_error ("derived union `%T' invalid", name); + binfo = NULL_TREE; + } + len = 0; + 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. */ + if (t = IDENTIFIER_TYPE_VALUE(name)) + { + if (TREE_CODE(t) != code) t = NULL_TREE; + } + if (xref_next_defn) + { + /* 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. */ + xref_next_defn = 0; + if (t && TYPE_CONTEXT(t) && strstr(IDENTIFIER_POINTER(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 if (tag_code == exception_type) + { + ref = make_lang_type (code); + /* Enable us to recognize when an exception type is created in + class context. To do nested classes correctly, this should + probably be cleared out when we leave this class's scope. */ + CLASSTYPE_DECLARED_EXCEPTION (ref) = 1; + pushtag (name, ref, globalize); + if (flag_cadillac) + cadillac_start_struct (ref); + } + else + { + extern tree pending_vtables; + struct binding_level *old_b = class_binding_level; + int needs_writing; + + ref = make_lang_type (code); + + /* A signature type will contain the fields of the signature + table. Therefore, it's not only an interface. */ + if (tag_code == signature_type) + { + SET_SIGNATURE (ref); + CLASSTYPE_INTERFACE_ONLY (ref) = 0; + CLASSTYPE_INTERFACE_UNKNOWN (ref) = 0; + } + + /* 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 (ref) + && CLASSTYPE_INTERFACE_KNOWN (ref); + break; + default: + needs_writing = 0; + } + + /* Signatures don't have a vtable. As long as we don't have default + implementations, they behave as if `write_virtuals' were 3. */ + if (tag_code == signature_type) + CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; + else + CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing; + +#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 (IS_AGGR_TYPE_CODE (code)) + { + if (IS_AGGR_TYPE (ref) + && ((tag_code == exception_type) + != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1))) + { + cp_error ("type `%T' is both exception and aggregate type", ref); + CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type); + } + } + + /* 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 (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 (); + } + } + + if (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; + + 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) + { + error ("base type `%s' fails to be a struct or class type", + IDENTIFIER_POINTER (TREE_VALUE (binfo))); + continue; + } +#if 1 + /* This code replaces similar code in layout_basetypes. */ + else if (TYPE_SIZE (basetype) == NULL_TREE) + { + 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), 0); + + 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; + + 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); + TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype); + TREE_GETS_PLACED_NEW (ref) |= TREE_GETS_PLACED_NEW (basetype); + TREE_GETS_DELETE (ref) |= TREE_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); + } + + 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; +} + +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 (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_unsigned_type (enumtype); + + /* 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); + + 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 pair, tem; + register HOST_WIDE_INT maxvalue = 0; + register HOST_WIDE_INT minvalue = 0; + register HOST_WIDE_INT i; + + TYPE_VALUES (enumtype) = values; + + /* Calculate the maximum value of any enumerator in this type. */ + + if (values) + { + /* Speed up the main loop by performing some precalculations */ + + HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values)); + TREE_TYPE (TREE_VALUE (values)) = enumtype; + minvalue = maxvalue = value; + + for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) + { + value = TREE_INT_CST_LOW (TREE_VALUE (pair)); + if (value > maxvalue) + maxvalue = value; + else if (value < minvalue) + minvalue = value; + TREE_TYPE (TREE_VALUE (pair)) = enumtype; + } + } + + if (flag_short_enums) + { + /* Determine the precision this type needs, lay it out, and define it. */ + + for (i = maxvalue; i; i >>= 1) + TYPE_PRECISION (enumtype)++; + + if (!TYPE_PRECISION (enumtype)) + TYPE_PRECISION (enumtype) = 1; + + /* Cancel the laying out previously done for the enum type, + so that fixup_unsigned_type will do it over. */ + TYPE_SIZE (enumtype) = NULL_TREE; + + fixup_unsigned_type (enumtype); + } + + TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue; + + /* An enum can have some negative values; then it is signed. */ + if (minvalue < 0) + { + TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue; + TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1; + TREE_UNSIGNED (enumtype) = 0; + } + if (flag_cadillac) + cadillac_finish_enum (enumtype); + + /* 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 + { + error ("enumerator value for `%s' not integer constant", + IDENTIFIER_POINTER (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; + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); + + /* Make up for hacks in cp-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; + } + + result = saveable_tree_cons (name, value, NULL_TREE); + + /* C++ associates enums with global, function, or class declarations. */ + + /* There are a number of cases we need to be aware of here: + current_class_type current_function_decl + * global enums NULL NULL + * fn-local enum NULL SET + * class-local enum SET NULL + * class->fn->enum SET SET + * fn->class->enum SET SET + + Those last two make life interesting. If it's a fn-local enum which is + itself inside a class, we need the enum to go into the fn's decls (our + second case below). But if it's a class-local enum and the class itself + is inside a function, we need that enum 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 enum into + the class's scope. */ + + if ((current_class_type && ! current_function_decl) + || (current_class_type && current_function_decl + && TYPE_CONTEXT (current_class_type) == current_function_decl)) + { + /* 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); + if (enum_next_value == integer_one_node) + enum_next_value = copy_node (enum_next_value); + + 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, pre_parsed_p) + tree declarator, declspecs, raises; + int pre_parsed_p; +{ + extern tree EHS_decl; + 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; + + if (flag_handle_exceptions && EHS_decl == NULL_TREE) + init_exception_processing_1 (); + + /* 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; + current_extern_inline = 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; + + 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))); + } + + 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; + } + + if ( !(DECL_VINDEX (decl1) + && write_virtuals >= 2 + && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype))) + current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1); + + raises = TYPE_RAISES_EXCEPTIONS (fntype); + + /* In a fcn definition, arg types must be complete. */ + require_complete_types_for_parms (last_function_parms); + } + else + { + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises); + /* 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) + { + warning ("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, 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; + + /* 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. */ + if (interface_unknown == 0) + { + TREE_PUBLIC (decl1) = 1; + DECL_EXTERNAL (decl1) = (interface_only + || (DECL_INLINE (decl1) + && ! flag_implement_inlines)); + } + else + /* 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; + + /* Now see if this is the implementation of a declared function. */ + if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus + && !DECL_CONTEXT (decl1)) + { + olddecl = lookup_name_current_level (DECL_NAME (decl1)); + if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL) + olddecl = NULL_TREE; + if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl)) + { + /* Collision between user and internal naming scheme. */ + olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1)); + if (olddecl == NULL_TREE) + olddecl = decl1; + } + if (olddecl && olddecl != decl1 + && DECL_NAME (decl1) == DECL_NAME (olddecl)) + { + if (TREE_CODE (olddecl) == FUNCTION_DECL + && decls_match (decl1, olddecl)) + { + olddecl = DECL_MAIN_VARIANT (olddecl); + /* The following copy is needed to handle forcing a function's + linkage to obey the linkage of the original decl. */ + DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl); + DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl); + if (! DECL_BUILT_IN (olddecl) && DECL_INITIAL (olddecl)) + redeclaration_error_message (decl1, olddecl); + if (duplicate_decls (decl1, olddecl)) + decl1 = olddecl; + else + olddecl = NULL_TREE; + } + else + olddecl = NULL_TREE; + } + } + + /* 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 (olddecl) + current_function_decl = olddecl; + else if (pre_parsed_p == 0) + { + current_function_decl = pushdecl (decl1); + if (TREE_CODE (current_function_decl) == TREE_LIST) + { + /* @@ revert to modified original declaration. */ + decl1 = DECL_MAIN_VARIANT (decl1); + current_function_decl = decl1; + } + else + { + decl1 = current_function_decl; + DECL_MAIN_VARIANT (decl1) = decl1; + } + fntype = TREE_TYPE (decl1); + } + else + current_function_decl = decl1; + + if (DECL_OVERLOADED (decl1)) + decl1 = push_overloaded_decl (decl1, 1); + + 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); + + 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); + + make_function_rtl (decl1); + + 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'. */ + current_class_decl = last_function_parms; + my_friendly_assert (current_class_decl != NULL_TREE + && TREE_CODE (current_class_decl) == PARM_DECL, 162); + if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE) + { + tree variant = TREE_TYPE (TREE_TYPE (current_class_decl)); + if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE) + { + /* Can't call build_indirect_ref here, because it has special + logic to return C_C_D given this argument. */ + C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl); + CLASSTYPE_INST_VAR (ctype) = C_C_D; + } + else + { + C_C_D = CLASSTYPE_INST_VAR (ctype); + /* `current_class_decl' is different for every + function we compile. */ + TREE_OPERAND (C_C_D, 0) = current_class_decl; + } + TREE_READONLY (C_C_D) = TYPE_READONLY (variant); + TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant); + TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant); + } + else + C_C_D = current_class_decl; + } + } + else + { + if (DECL_STATIC_FUNCTION_P (decl1)) + push_nested_class (DECL_CONTEXT (decl1), 2); + else + push_memoized_context (0, 1); + } + + /* 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, restype); + + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))) + { + 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; +} + +/* 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; + tree eh_decl; + + /* 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 (current_binding_level == global_binding_level) + 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); + + /* Prepare to catch raises, if appropriate. */ + if (flag_handle_exceptions) + { + /* Get this cleanup to be run last, since it + is a call to `longjmp'. */ + setup_exception_throw_decl (); + eh_decl = current_binding_level->names; + current_binding_level->names = TREE_CHAIN (current_binding_level->names); + } + if (flag_handle_exceptions) + expand_start_try (integer_one_node, 0, 1); + + 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); + expand_decl_cleanup (parm, cleanup); + 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); + + if (flag_handle_exceptions) + { + /* Make the throw decl visible at this level, just + not in the way of the parameters. */ + pushdecl (eh_decl); + expand_decl_init (eh_decl); + } + + /* 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); + expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup); + } + + /* 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 (flag_dossier) + output_builtin_tdesc_entries (); + } +} + +/* 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. */ + error ("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 `finish_decl' know that this initializer is ok. */ + DECL_INITIAL (decl) = init; + pushdecl (decl); + finish_decl (decl, init, 0, 0); + } +} + +#if 0 +/* Generate code for default X() constructor. */ +static void +build_default_constructor (fndecl) + tree fndecl; +{ + int i = CLASSTYPE_N_BASECLASSES (current_class_type); + tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); + tree fields = TYPE_FIELDS (current_class_type); + tree binfos = TYPE_BINFO_BASETYPES (current_class_type); + + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + parm = TREE_CHAIN (parm); + parm = DECL_REFERENCE_SLOT (parm); + + while (--i >= 0) + { + tree basetype = TREE_VEC_ELT (binfos, i); + if (TYPE_HAS_INIT_REF (basetype)) + { + tree name = TYPE_NAME (basetype); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + current_base_init_list = tree_cons (name, parm, current_base_init_list); + } + } + for (; fields; fields = TREE_CHAIN (fields)) + { + tree name, init; + if (TREE_STATIC (fields)) + continue; + if (TREE_CODE (fields) != FIELD_DECL) + continue; + if (DECL_NAME (fields)) + { + if (VFIELD_NAME_P (DECL_NAME (fields))) + continue; + if (VBASE_NAME_P (DECL_NAME (fields))) + continue; + + /* True for duplicate members. */ + if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields) + continue; + } + + init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields); + init = build_tree_list (NULL_TREE, init); + + current_member_init_list + = tree_cons (DECL_NAME (fields), init, current_member_init_list); + } +} +#endif + +/* 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) + int lineno; + int call_poplevel; +{ + register tree fndecl = current_function_decl; + tree fntype, ctype = NULL_TREE; + rtx head, last_parm_insn, mark; + extern int sets_exception_throw_decl; + /* 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, integer_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. */ + mark = get_last_insn (); + last_parm_insn = get_first_nonparm_insn (); + + if ((flag_this_is_variable & 1) == 0) + ok_to_optimize_dtor = 1; + else if (mark == last_parm_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) + || TREE_GETS_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 (vbases, current_class_decl); + expand_expr_stmt (build_delete (TYPE_POINTER_TO (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 (TREE_GETS_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, TYPE_POINTER_TO (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. */ + mark = get_last_insn (); + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + last_parm_insn = mark; + else + last_parm_insn = previous_insn (last_parm_insn); + + /* Make all virtual function table pointers in non-virtual base + classes point to CURRENT_CLASS_TYPE's virtual function + tables. */ + init_vtbl_ptrs (binfo, 1, 0); + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + expand_expr_stmt (build_vbase_vtables_init (binfo, 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); + } + if (mark != get_last_insn ()) + reorder_insns (next_insn (mark), get_last_insn (), 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)) + { + expand_label (ctor_label); + ctor_label = NULL_TREE; + + if (call_poplevel) + { + decls = getdecls (); + if (flag_handle_exceptions == 2) + deactivate_exception_cleanups (); + 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_insns = NULL_RTX; + } + 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)); + if (flag_handle_exceptions == 2) + { + tree cleanup, cleanup_deallocate; + tree virtual_size; + + /* This is the size of the virtual object pointed to by + allocated_this. In this case, it is simple. */ + virtual_size = c_sizeof (current_class_type); + + allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node); + DECL_REGISTER (allocated_this) = 1; + DECL_INITIAL (allocated_this) = error_mark_node; + expand_decl (allocated_this); + expand_decl_init (allocated_this); + /* How we cleanup `this' if an exception was raised before + we are ready to bail out. */ + cleanup = TREE_GETS_DELETE (current_class_type) + ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE) + /* The size of allocated_this is wrong, and hence the + second argument to operator delete will be wrong. */ + : build_delete (TREE_TYPE (allocated_this), allocated_this, + integer_three_node, + LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1); + cleanup_deallocate + = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node); + cleanup = tree_cons (NULL_TREE, cleanup, + build_tree_list (NULL_TREE, cleanup_deallocate)); + + expand_decl_cleanup (allocated_this, + build (COND_EXPR, integer_type_node, + build (NE_EXPR, integer_type_node, + allocated_this, integer_zero_node), + build_compound_expr (cleanup), + integer_zero_node)); + } + } + + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; + + /* must keep the first insn safe. */ + head = get_insns (); + + /* this note will come up to the top with us. */ + mark = get_last_insn (); + + if (flag_this_is_variable > 0) + { + expand_start_cond (cond, 0); + expand_expr_stmt (thenclause); + if (flag_handle_exceptions == 2) + expand_assignment (allocated_this, current_class_decl, 0, 0); + 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). */ + emit_insns (base_init_insns); + base_init_insns = NULL_RTX; + + /* 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 = mark; + else + last_parm_insn = previous_insn (last_parm_insn); + + if (mark != get_last_insn ()) + reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); + + /* This is where the body of the constructor ends. */ + expand_label (ctor_label); + ctor_label = NULL_TREE; + if (flag_handle_exceptions == 2) + { + expand_assignment (allocated_this, integer_zero_node, 0, 0); + if (call_poplevel) + deactivate_exception_cleanups (); + } + + pop_implicit_try_blocks (NULL_TREE); + + if (call_poplevel) + { + expand_end_bindings (decls = getdecls (), 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 (); + + /* That's the end of the vtable decl's life. Need to mark it such + if doing stupid register allocation. + + Note that current_vtable_decl is really an INDIRECT_REF + on top of a VAR_DECL here. */ + if (obey_regdecls && current_vtable_decl) + use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0))); + + /* 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); + +#if 1 + /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */ + if (exception_throw_decl && sets_exception_throw_decl == 0) + expand_assignment (exception_throw_decl, integer_zero_node, 0, 0); +#endif + + if (flag_handle_exceptions) + { + expand_end_try (); + expand_start_except (0, 0); + expand_end_except (); + } + + /* 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); + } + + /* 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); + + /* Forget about all overloaded functions defined in + this scope which go away. */ + while (overloads_to_forget) + { + IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget)) + = TREE_VALUE (overloads_to_forget); + overloads_to_forget = TREE_CHAIN (overloads_to_forget); + } + + /* Generate rtl for function exit. */ + expand_function_end (input_filename, lineno, 1); + + /* 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); + + /* 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; + + /* ??? Compensate for Sun brain damage in dealing with data segments + of PIC code. */ + if (flag_pic + && (DECL_CONSTRUCTOR_P (fndecl) + || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) + && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype))) + DECL_INLINE (fndecl) = 0; + + if (DECL_EXTERNAL (fndecl) + /* This function is just along for the ride. If we can make + it inline, that's great. Otherwise, just punt it. */ + && (DECL_INLINE (fndecl) == 0 + || flag_no_inline + || function_cannot_inline_p (fndecl))) + { + extern int rtl_dump_and_exit; + int old_rtl_dump_and_exit = rtl_dump_and_exit; + int inline_spec = DECL_INLINE (fndecl); + + /* This throws away the code for FNDECL. */ + rtl_dump_and_exit = 1; + /* This throws away the memory of the code for FNDECL. */ + if (flag_no_inline) + DECL_INLINE (fndecl) = 0; + rest_of_compilation (fndecl); + rtl_dump_and_exit = old_rtl_dump_and_exit; + DECL_INLINE (fndecl) = inline_spec; + } + else + { + /* Run the optimizers and output the assembler code for this + function. */ + rest_of_compilation (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. */ + permanent_allocation (); + + 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; + } + + /* Let the error reporting routines know that we're outside a function. */ + current_function_decl = NULL_TREE; + named_label_uses = 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); + + /* 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; + } + + /* If we're expanding a template, a function must be explicitly declared + inline if we're to compile it now. If it isn't, we have to wait to see + whether it's needed, and whether an override exists. */ + if (flag_default_inline && !processing_template_defn) + DECL_INLINE (fndecl) = 1; + + /* 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)) + grok_ctor_properties (current_class_type, fndecl); + else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) + grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); + } + + finish_decl (fndecl, NULL_TREE, NULL_TREE, 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; + tree context = DECL_CONTEXT (fndecl); + + 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 decl; + + if (current_binding_level->n_incomplete == 0) + return; + + if (!type) /* Don't do this for class templates. */ + return; + + for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) + if (TREE_TYPE (decl) == type + || (TREE_TYPE (decl) + && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE + && TREE_TYPE (TREE_TYPE (decl)) == type)) + { + if (TREE_CODE (decl) == TYPE_DECL) + layout_type (TREE_TYPE (decl)); + else + { + int toplevel = global_binding_level == current_binding_level; + 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) + { + expand_decl (decl); + expand_decl_cleanup (decl, maybe_build_cleanup (decl)); + expand_decl_init (decl); + } + } + my_friendly_assert (current_binding_level->n_incomplete > 0, 164); + --current_binding_level->n_incomplete; + } +} + +/* 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; + + /* Use TYPE_MAIN_VARIANT so we don't get a warning about + calling delete on a `const' variable. */ + if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval)))) + rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval); + + 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)))); + + current_binding_level->have_cleanups = 1; + current_binding_level->more_exceptions_ok = 0; + + 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 (TREE_RAISES (exp)) + { + my_friendly_assert (flag_handle_exceptions, 165); + if (flag_handle_exceptions == 2) + { + if (! current_binding_level->more_exceptions_ok) + { + extern struct nesting *nesting_stack, *block_stack; + + remove_implicit_immediately + = (nesting_stack != block_stack); + cplus_expand_start_try (1); + } + current_binding_level->have_exceptions = 1; + } + } + + expand_expr_stmt (break_out_cleanups (exp)); + + if (remove_implicit_immediately) + pop_implicit_try_blocks (NULL_TREE); + } + + /* 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; + emit_insns (base_init_insns); + check_base_init (current_class_type); + } + current_function_assigns_this = 1; + + if (flag_cadillac) + cadillac_finish_stmt (); +} + +void +pop_implicit_try_blocks (decl) + tree decl; +{ + if (decl) + { + my_friendly_assert (current_binding_level->parm_flag == 3, 166); + current_binding_level->names = TREE_CHAIN (decl); + } + + while (current_binding_level->parm_flag == 3) + { + tree name = get_identifier ("(compiler error)"); + tree orig_ex_type = current_exception_type; + tree orig_ex_decl = current_exception_decl; + tree orig_ex_obj = current_exception_object; + tree decl = cplus_expand_end_try (2); + + /* @@ It would be nice to make all these point + to exactly the same handler. */ + /* Start hidden EXCEPT. */ + cplus_expand_start_except (name, decl); + /* reraise ALL. */ + cplus_expand_reraise (NULL_TREE); + current_exception_type = orig_ex_type; + current_exception_decl = orig_ex_decl; + current_exception_object = orig_ex_obj; + /* This will reraise for us. */ + cplus_expand_end_except (error_mark_node); + } + + if (decl) + { + TREE_CHAIN (decl) = current_binding_level->names; + current_binding_level->names = decl; + } +} + +/* Push a cleanup onto the current binding contour that will cause + ADDR to be cleaned up, in the case that an exception propagates + through its binding contour. */ + +void +push_exception_cleanup (addr) + tree addr; +{ + tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node); + tree cleanup; + + decl = pushdecl (decl); + DECL_REGISTER (decl) = 1; + store_init_value (decl, addr); + expand_decl (decl); + expand_decl_init (decl); + + cleanup = build (COND_EXPR, integer_type_node, + build (NE_EXPR, integer_type_node, + decl, integer_zero_node), + build_delete (TREE_TYPE (addr), decl, + lookup_name (in_charge_identifier, 0), + LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0), + integer_zero_node); + expand_decl_cleanup (decl, cleanup); +} + +/* For each binding contour, emit code that deactivates the + exception cleanups. All other cleanups are left as they were. */ + +static void +deactivate_exception_cleanups () +{ + struct binding_level *b = current_binding_level; + tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME); + while (b != class_binding_level) + { + if (b->parm_flag == 3) + { + tree decls = b->names; + while (decls) + { + if (DECL_NAME (decls) == xyzzy) + expand_assignment (decls, integer_zero_node, 0, 0); + decls = TREE_CHAIN (decls); + } + } + b = b->level_chain; + } +} + +/* Change a static member function definition into a FUNCTION_TYPE, instead + of the METHOD_TYPE that we create when it's originally parsed. */ +void +revert_static_member_fn (fn, decl, argtypes) + tree *fn, *decl, *argtypes; +{ + tree tmp, function = *fn; + + *argtypes = TREE_CHAIN (*argtypes); + tmp = build_function_type (TREE_TYPE (function), *argtypes); + tmp = build_type_variant (tmp, TYPE_READONLY (function), + TYPE_VOLATILE (function)); + tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp, + TYPE_RAISES_EXCEPTIONS (function)); + TREE_TYPE (*decl) = tmp; + *fn = tmp; + DECL_STATIC_FUNCTION_P (*decl) = 1; +} diff --git a/gcc/cp/decl.h b/gcc/cp/decl.h new file mode 100644 index 00000000000..aabfa2fb926 --- /dev/null +++ b/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, 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* 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) */ + MEMFUNCDEF /* Member function definition */ +}; + +/* 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; + +/* A list of functions which were declared inline, but later had their + address taken. Used only for non-virtual member functions, since we can + find other functions easily enough. */ +extern tree pending_addressable_inlines; + +#ifdef DEBUG_CP_BINDING_LEVELS +/* Purely for debugging purposes. */ +extern int debug_bindings_indentation; +#endif diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c new file mode 100644 index 00000000000..201dcf73a11 --- /dev/null +++ b/gcc/cp/decl2.c @@ -0,0 +1,2823 @@ +/* Process declarations and variables for C compiler. + Copyright (C) 1988, 1992, 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, 675 Mass Ave, Cambridge, MA 02139, 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" + +extern tree grokdeclarator (); +extern tree get_file_function_name (); +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; + +extern tree pending_addressable_inlines; + +/* Used to help generate temporary names which are unique within + a function. Reset to 0 by start_function. */ + +static 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 cp-spew.c */ + +extern int spew_debug; + +/* 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 the non-ANSI builtin functions. */ + +int flag_no_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 = 0; + +/* Nonzero means handle things in ANSI, instead of GNU fashion. This + flag should be tested for language behavior that's different between + ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */ + +int flag_ansi = 0; + +/* Nonzero means do argument matching for overloading according to the + ANSI rules, rather than what g++ used to believe to be correct. */ + +int flag_ansi_overloading = 1; + +/* 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 = 0; + +/* 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 = 0; + +/* 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; + +/* 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 = 1; + +/* 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 = 1; + +/* Non-zero means warn when a function is declared extern and later inline. */ +int warn_extern_inline; + +/* 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 -no-strict-prototype switch: do not consider empty + argument prototype to mean function takes no arguments. */ + +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. + 2 means handle exceptions the way Spring wants them handled. */ + +int flag_handle_exceptions; + +/* Nonzero means recognize and handle exception handling constructs. + Use ansi syntax and semantics. WORK IN PROGRESS! + 2 means handle exceptions the way Spring wants them handled. */ + +int flag_ansi_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 'dossiers' that give + run-time type information. */ +int flag_dossier; + +/* 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; + +/* 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 flaging multiple + definitions. */ +int flag_conserve_space; + +/* 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", &strict_prototypes_lang_cplusplus, 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}, + {"ansi-exceptions", &flag_ansi_exceptions, 1}, + {"handle-signatures", &flag_handle_signatures, 1}, + {"spring-exceptions", &flag_handle_exceptions, 2}, + {"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}, + {"dossier", &flag_dossier, 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}, + {"ansi-overloading", &flag_ansi_overloading, 1}, + {"huge-objects", &flag_huge_objects, 1}, + {"conserve-space", &flag_conserve_space, 1}, +}; + +/* 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; + /* 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_dossier = 1; + found = 1; + } + else if (! strcmp (p, "no-gc")) + { + flag_gc = 0; + /* This must come along for the ride. */ + flag_dossier = 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 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, "extern-inline")) + warn_extern_inline = 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_missing_braces = setting; + warn_extern_inline = 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; + } + + else if (!strcmp (p, "overloaded-virtual")) + warn_overloaded_virtual = setting; + else return 0; + } + else if (!strcmp (p, "-ansi")) + flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 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 (ctype, fntype, raises); + + TREE_TYPE (function) = fntype; + return ctype; +} + +/* 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); + } +} + +/* 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 () +{ + static int already_warned = 0; + if (++already_warned == 1) + warning ("templates that are built with -fexternal-templates should be in files that have #pragma interface/implementation"); +} + +/* 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; + else if (CLASSTYPE_DECLARED_EXCEPTION(t)) + tcode = exception_type_node; + + t = xref_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE); + if (TYPE_CONTEXT(t)) + CLASSTYPE_NO_GLOBALIZE(t) = 1; + if (TYPE_LANG_SPECIFIC (t) + && CLASSTYPE_DECLARED_EXCEPTION (t)) + shadow_tag (specs); + 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_defn_tag(tcode, TYPE_IDENTIFIER(t), NULL_TREE); + 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; + + if (fn_name == NULL_TREE) + { + error ("name missing for member function"); + fn_name = get_identifier (""); + DECL_NAME (function) = fn_name; + } + + if (quals) + ctype = grok_method_quals (ctype, function, quals); + + 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); + + if (flags == DTOR_FLAG) + type = TYPE_MAIN_VARIANT (type); + else 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". */ + DECL_SOURCE_LINE (parm) = 0; + 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". */ + DECL_SOURCE_LINE (parm) = 0; + 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 0 + /* it is wrong to flag the object as readonly, when + flag_this_is_variable is 0. */ + if (flags != DTOR_FLAG + && (flag_this_is_variable <= 0 || TYPE_READONLY (type))) +#else + if (flags != DTOR_FLAG && TYPE_READONLY (type)) +#endif + 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". */ + DECL_SOURCE_LINE (parm) = 0; + 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; + + TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node, + arg_types); + 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)); + TREE_TYPE (function) + = build_cplus_method_type (ctype, + TREE_TYPE (TREE_TYPE (function)), + arg_types); + 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 (TYPE_POINTER_TO (ctype), 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/Interger.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); + + 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) == POINTER_TYPE + || TREE_CODE (type) == ARRAY_TYPE) + return build_array_ref (array_expr, index_exp); + + /* Woops, looks like they did something like `5[a]' instead of `a[5]'. + We don't emit a warning or error for this, since it's allowed + by ARM $8.2.4. */ + + type = TREE_TYPE (index_exp); + + if (TREE_CODE (type) == OFFSET_TYPE + || TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); + + if (TYPE_LANG_SPECIFIC (type) + && TYPE_OVERLOADS_ARRAY_REF (type)) + error ("array expression backwards"); + else if (TREE_CODE (type) == POINTER_TYPE + || TREE_CODE (type) == ARRAY_TYPE) + return build_array_ref (index_exp, array_expr); + else + error("`[]' applied to non-pointer type"); + + /* We gave an error, so give an error. Huh? */ + return error_mark_node; +} + +/* 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 ("ANSI C++ forbids 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 legal and has no effect. */ + if (integer_zerop (t)) + return build1 (NOP_EXPR, void_type_node, t); + } + + /* You can't delete a pointer to constant. */ + if (code == POINTER_TYPE && TREE_READONLY (TREE_TYPE (type))) + { + error ("`const *' cannot be deleted"); + return error_mark_node; + } + + /* 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; + + if (doing_vec) + return build_vec_delete (t, maxindex, elt_size, NULL_TREE, + integer_one_node, integer_two_node); + else + return build_delete (type, t, integer_three_node, + LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, + use_global_delete + || TYPE_HAS_DESTRUCTOR (TREE_TYPE (type))); +} + +/* 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. */ + +void +check_classfn (ctype, cname, function) + tree ctype, cname, function; +{ + tree fn_name = DECL_NAME (function); + tree fndecl; + int need_quotes = 0; + 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 == cname) + 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 = DECL_CHAIN (fndecl); + } + break; /* loser */ + } + } + } + + if (methods != end) + cp_error ("argument list for `%D' does not match any in class `%T'", + fn_name, ctype); + else + { + methods = 0; + cp_error ("no `%D' member function declared in class `%T'", + fn_name, ctype); + } + + /* If we did not find the method in the class, add it to + avoid spurious errors. */ + add_method (ctype, methods, function); +} + +/* 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) + tree declarator, declspecs, raises, init, asmspec_tree; +{ + register tree value; + char *asmspec = 0; + + /* 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); + } + + 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); + if (! value) + return NULL_TREE; /* friends 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; + CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1; + 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) + { + if (DECL_NAME (value)) + pedwarn ("ANSI C++ forbids initialization of member `%s'", + IDENTIFIER_POINTER (DECL_NAME (value))); + else + pedwarn ("ANSI C++ forbids initialization of fields"); + + 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 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 finish_decl to do the right thing, namely, to + put this decl out straight away. */ + if (TREE_STATIC (value)) + { + /* current_class_type can be NULL_TREE in case of error. */ + if (asmspec == 0 && current_class_type) + { + tree name; + char *buf, *buf2; + + buf2 = build_overload_name (current_class_type, 1, 1); + buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value)) + + sizeof (STATIC_NAME_FORMAT) + + strlen (buf2)); + sprintf (buf, STATIC_NAME_FORMAT, buf2, + IDENTIFIER_POINTER (DECL_NAME (value))); + name = get_identifier (buf); + TREE_PUBLIC (value) = 1; + DECL_INITIAL (value) = error_mark_node; + DECL_ASSEMBLER_NAME (value) = name; + } + 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; + + finish_decl (value, init, asmspec_tree, 1); + pushdecl_class_level (value); + return value; + } + if (TREE_CODE (value) == FIELD_DECL) + { + if (asmspec) + DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec); + if (DECL_INITIAL (value) == error_mark_node) + init = error_mark_node; + finish_decl (value, init, asmspec_tree, 1); + DECL_INITIAL (value) = init; + DECL_IN_AGGR_P (value) = 1; + return value; + } + if (TREE_CODE (value) == FUNCTION_DECL) + { + /* grokdeclarator defers setting this. */ + TREE_PUBLIC (value) = 1; + 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); + } + finish_decl (value, init, asmspec_tree, 1); + + /* Pass friends back this way. */ + if (DECL_FRIEND_P (value)) + return void_type_node; + + 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); + + 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; + } + finish_decl (value, NULL_TREE, NULL_TREE, 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; +} + +/* 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); + 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; + } + + finish_decl (decl, NULL_TREE, NULL_TREE, 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; +} + +/* The precedence rules of this grammar (or any other deterministic LALR + grammar, for that matter), place the CALL_EXPR somewhere where we + may not want it. The solution is to grab the first CALL_EXPR we see, + pretend that that is the one that belongs to the parameter list of + the type conversion function, and leave everything else alone. + We pull it out in place. + + CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR + does not appear in DECL. */ +tree +grokoptypename (decl, call_required) + tree decl; + int call_required; +{ + tree tmp, last; + + my_friendly_assert (TREE_CODE (decl) == TYPE_EXPR, 195); + + tmp = TREE_OPERAND (decl, 0); + last = NULL_TREE; + + while (tmp) + { + switch (TREE_CODE (tmp)) + { + case CALL_EXPR: + { + tree parms = TREE_OPERAND (tmp, 1); + + if (last) + TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0); + else + TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0); + + last = grokdeclarator (TREE_OPERAND (decl, 0), + TREE_TYPE (decl), + TYPENAME, 0, NULL_TREE); + TREE_OPERAND (tmp, 0) = build_typename_overload (last); + TREE_TYPE (TREE_OPERAND (tmp, 0)) = last; + + if (parms + && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST) + TREE_VALUE (parms) + = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)), + TREE_PURPOSE (TREE_VALUE (parms)), + TYPENAME, 0, NULL_TREE); + if (parms) + { + if (TREE_VALUE (parms) != void_type_node) + cp_error ("`operator %T' requires empty parameter list", + last); + else + /* Canonicalize parameter lists. */ + TREE_OPERAND (tmp, 1) = void_list_node; + } + + return tmp; + } + + case INDIRECT_REF: + case ADDR_EXPR: + case ARRAY_REF: + break; + + case SCOPE_REF: + /* This is legal when declaring a conversion to + something of type pointer-to-member. */ + if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF) + { + tmp = TREE_OPERAND (tmp, 1); + } + else + { +#if 0 + /* We may need to do this if grokdeclarator cannot handle this. */ + error ("type `member of class %s' invalid return type", + TYPE_NAME_STRING (TREE_OPERAND (tmp, 0))); + TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1)); +#endif + tmp = TREE_OPERAND (tmp, 1); + } + break; + + default: + my_friendly_abort (196); + } + last = tmp; + tmp = TREE_OPERAND (tmp, 0); + } + + last = grokdeclarator (TREE_OPERAND (decl, 0), + TREE_TYPE (decl), + TYPENAME, 0, NULL_TREE); + + if (call_required) + cp_error ("`operator %T' construct requires parameter list", last); + + tmp = build_parse_node (CALL_EXPR, build_typename_overload (last), + void_list_node, NULL_TREE); + TREE_TYPE (TREE_OPERAND (tmp, 0)) = last; + return tmp; +} + +/* 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; + }; + +*/ + +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); + extern tree abort_fndecl; + + 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)) + { + /* Mark this function as being "defined". */ + DECL_INITIAL (decl) = error_mark_node; + /* pure virtual destructors must be defined. */ + if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl))) + { + /* Give this node rtl from `abort'. */ + DECL_RTL (decl) = DECL_RTL (abort_fndecl); + } + DECL_ABSTRACT_VIRTUAL_P (decl) = 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 intializers (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) + tree decl, attributes; +{ + if (decl) + decl_attributes (decl, attributes); +} + +/* 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; +{ + tree t; + 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 rtx base_init_insns; + + if (base_init_insns == 0 + && DECL_CONSTRUCTOR_P (current_function_decl)) + emit_base_init (current_class_type, 0); + +#if 0 + /* This has something a little wrong with it. + + On a sun4, code like: + + be L6 + ld [%i0],%o1 + + is generated, when the below is used when -O4 is given. The delay + slot it filled with an instruction that is safe, when this isn't + used, like in: + + be L6 + sethi %hi(LC1),%o0 + ld [%i0],%o1 + + on code like: + + struct A { + virtual void print() { printf("xxx"); } + void f(); + }; + + void A::f() { + if (this) { + print(); + } else { + printf("0"); + } + } + + And that is why this is disabled for now. (mrs) + */ + + if ((flag_this_is_variable & 1) == 0 + && optimize + && current_class_type + && CLASSTYPE_VSIZE (current_class_type) + && ! DECL_STATIC_FUNCTION_P (current_function_decl)) + { + tree vfield = build_vfield_ref (C_C_D, current_class_type); + current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type); + DECL_RTL (current_vtable_decl) = 0; + DECL_INITIAL (current_vtable_decl) = error_mark_node; + /* Have to cast the initializer, since it may have come from a + more base class then we ascribe CURRENT_VTABLE_DECL to be. */ + finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0); + current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR); + } + else +#endif + current_vtable_decl = NULL_TREE; +} + +/* Record the existence of an addressable inline function. */ +void +mark_inline_for_output (decl) + tree decl; +{ + 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; + } + pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl, + pending_addressable_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 = global_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; + } + + while (field) + { + tree 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 + && 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; + field = TREE_CHAIN (field); + } + if (static_p) + { + make_decl_rtl (main_decl, 0, global_bindings_p ()); + DECL_RTL (anon_union_decl) = DECL_RTL (main_decl); + } + + /* 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 (empty_table == NULL_TREE) + { + 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))); + finish_decl (empty_table, init, asmspec, 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))); + } + + finish_decl (decl, init, asmspec, 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 = 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 +write_vtable_entries (decl) + tree decl; +{ + tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))); + + if (flag_dossier) + entries = TREE_CHAIN (entries); + + for (; entries; entries = TREE_CHAIN (entries)) + { + tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries)); + tree fn = TREE_OPERAND (fnaddr, 0); + if (! DECL_EXTERNAL (fn) && ! TREE_ASM_WRITTEN (fn) + && DECL_SAVED_INSNS (fn)) + { + if (TREE_PUBLIC (DECL_CLASS_CONTEXT (fn))) + TREE_PUBLIC (fn) = 1; + TREE_ADDRESSABLE (fn) = 1; + temporary_allocation (); + output_inline_function (fn); + permanent_allocation (); + } + else + assemble_external (fn); + } +} + +/* Note even though prev is never used in here, walk_vtables + expects this to have two arguments, so concede. */ +static void +finish_vtable_typedecl (prev, vars) + tree prev, vars; +{ + tree decl = TYPE_BINFO_VTABLE (TREE_TYPE (vars)); + + /* If we are controlled by `+e2', obey. */ + if (write_virtuals == 2) + { + tree binfo = value_member (DECL_NAME (vars), pending_vtables); + if (binfo) + TREE_PURPOSE (binfo) = void_type_node; + else + decl = NULL_TREE; + } + /* If this type has inline virtual functions, then + write those functions out now. */ + if (decl && write_virtuals >= 0 + && ! DECL_EXTERNAL (decl) && (TREE_PUBLIC (decl) || TREE_USED (decl))) + write_vtable_entries (decl); +} + +static void +finish_vtable_vardecl (prev, vars) + tree prev, vars; +{ + if (write_virtuals >= 0 + && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars))) + { + extern tree the_null_vtable_entry; + + /* Stuff this virtual function table's size into + `pfn' slot of `the_null_vtable_entry'. */ + tree nelts = array_type_nelts (TREE_TYPE (vars)); + SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts); + /* Kick out the dossier before writing out the vtable. */ + if (flag_dossier) + rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1); + + /* Write it out. */ + write_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, 0, 1, 1); + } + /* 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) == TYPE_DECL + && type != error_mark_node + && TYPE_LANG_SPECIFIC (type) + && CLASSTYPE_VSIZE (type)) + { + if (typedecl_fn) (*typedecl_fn) (prev, vars); + } + else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars)) + { + if (vardecl_fn) (*vardecl_fn) (prev, vars); + } + else + prev = vars; + } +} + +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 = static_aggregates; + 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); + + /* Set up the name of the file-level functions we may need. */ + /* Use a global object (which is already required to be unique over + the program) rather than the file name (which imposes extra + constraints). -- Raeburn@MIT.EDU, 10 Jan 1990. */ + + /* 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; + + /* Otherwise, GDB can get confused, because in only knows + about source for LINENO-1 lines. */ + lineno -= 1; + + fnname = get_file_function_name ('D'); + start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 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! */ + while (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, TYPE_POINTER_TO (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 (); + } + vars = TREE_CHAIN (vars); + } + + expand_end_bindings (getdecls(), 1, 0); + poplevel (1, 0, 0); + pop_momentary (); + + finish_function (lineno, 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 (vars != NULL_TREE) + { + fnname = get_file_function_name ('I'); + start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0); + fnname = DECL_ASSEMBLER_NAME (current_function_decl); + store_parm_decls (); + + pushlevel (0); + clear_last_expr (); + push_momentary (); + expand_start_bindings (0); + + while (vars) + { + tree decl = TREE_VALUE (vars); + tree init = TREE_PURPOSE (vars); + + /* 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); + + if (init) + { + if (TREE_CODE (init) == VAR_DECL) + { + /* This behavior results when there are + multiple declarations of an aggregate, + the last of which defines it. */ + if (DECL_RTL (init) == DECL_RTL (decl)) + { + my_friendly_assert (DECL_INITIAL (decl) == error_mark_node + || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR + && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE), + 199); + init = DECL_INITIAL (init); + if (TREE_CODE (init) == CONSTRUCTOR + && CONSTRUCTOR_ELTS (init) == NULL_TREE) + init = NULL_TREE; + } +#if 0 + else if (TREE_TYPE (decl) == TREE_TYPE (init)) + { +#if 1 + my_friendly_abort (200); +#else + /* point to real decl's rtl anyway. */ + DECL_RTL (init) = DECL_RTL (decl); + my_friendly_assert (DECL_INITIAL (decl) == error_mark_node, + 201); + init = DECL_INITIAL (init); +#endif /* 1 */ + } +#endif /* 0 */ + } + } + if (IS_AGGR_TYPE (TREE_TYPE (decl)) + || init == 0 + || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) + { +#if 0 + /* Set this up so is_friend() works properly on _GLOBAL_ + fns. */ + tree old_dcc = DECL_CLASS_CONTEXT (current_function_decl); + if (old_dcc == NULL_TREE && IS_AGGR_TYPE (TREE_TYPE (decl))) + DECL_CLASS_CONTEXT (current_function_decl) = TREE_TYPE (decl); + expand_aggr_init (decl, init, 0); + DECL_CLASS_CONTEXT (current_function_decl) = old_dcc; +#else + expand_aggr_init (decl, init, 0); +#endif + } + 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); + } + 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 (); + expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0); + } + } + else if (decl == error_mark_node) + ; + else my_friendly_abort (22); + vars = TREE_CHAIN (vars); + } + + expand_end_bindings (getdecls(), 1, 0); + poplevel (1, 0, 0); + pop_momentary (); + + finish_function (lineno, 0); + assemble_constructor (IDENTIFIER_POINTER (fnname)); + } + + /* 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; + + /* Now write out inline functions which had their addresses taken + and which were not declared virtual and which were not declared + `extern inline'. */ + while (pending_addressable_inlines) + { + tree decl = TREE_VALUE (pending_addressable_inlines); + if (! TREE_ASM_WRITTEN (decl) + && ! DECL_EXTERNAL (decl) + && DECL_SAVED_INSNS (decl)) + { + temporary_allocation (); + output_inline_function (decl); + permanent_allocation (); + } + pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines); + } + + start_time = get_run_time (); + + /* Now delete from the chain of variables all virtual function tables. + We output them all ourselves, because each will be treated specially. */ + +#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 + cp-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; + DECL_SOURCE_LINE (vars) = 0; + pushdecl (vars); +#endif + + walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl); + + 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); + } + } + + permanent_allocation (); + this_time = get_run_time (); + parse_time -= this_time - start_time; + varconst_time += this_time - start_time; + + if (flag_detailed_statistics) + dump_time_statistics (); +} diff --git a/gcc/cp/errfn.c b/gcc/cp/errfn.c new file mode 100644 index 00000000000..21feb772b47 --- /dev/null +++ b/gcc/cp/errfn.c @@ -0,0 +1,217 @@ +/* Provide a call-back mechanism for handling error output. + Copyright (C) 1993 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, 675 Mass Ave, Cambridge, MA 02139, 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 cp-error.c for an example use of this code. */ + +typedef char* cp_printer PROTO((HOST_WIDE_INT, int)); +extern cp_printer * cp_printers[256]; + +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 3 +#define arglist a1, a2, a3 +#define arglist_dcl HOST_WIDE_INT a1, a2, a3; +#define ARGSINIT args[0] = a1; args[1] = a2; args[2] = a3; +#define ARGSLIST args[0], args[1], args[2] + +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[*f]; + + if (function) + { + char *p; + + if (arg >= NARGS) abort (); + + if (maybe_here && atarg) + 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; + cp_thing (error, 0, format, arglist); +} + +void +cp_warning (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn warning; + cp_thing (warning, 0, format, arglist); +} + +void +cp_pedwarn (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn pedwarn; + cp_thing (pedwarn, 0, format, arglist); +} + +void +cp_compiler_error (format, arglist) + char *format; + arglist_dcl +{ + extern errorfn compiler_error; + 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; + 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; + 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; + cp_thing (pedwarn_with_file_and_line, 1, format, arglist); +} diff --git a/gcc/cp/error.c b/gcc/cp/error.c new file mode 100644 index 00000000000..75167fcdf4e --- /dev/null +++ b/gcc/cp/error.c @@ -0,0 +1,1339 @@ +/* Call-backs for C++ error reporting. + This code is non-reentrant. + 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, 675 Mass Ave, Cambridge, MA 02139, 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 _ (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, _, _, _, _, _, _, _, _, _, _, _, /* 0x50 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x60 */ + _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0x70 */ +}; +#undef C +#undef D +#undef E +#undef L +#undef O +#undef P +#undef T +#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 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); +} + +/* Counter to help build parameter names in case they were omitted. */ +static int dummy_name; + +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_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 (""); + break; + + case UNKNOWN_TYPE: + OB_PUTS (""); + 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_readonly_or_volatile (t, after); + OB_PUTID (DECL_NAME (t)); + 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: + dump_readonly_or_volatile (t, after); + OB_PUTID (TYPE_IDENTIFIER (t)); + break; + + case TEMPLATE_TYPE_PARM: + OB_PUTS ("