home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gcc-2.3.3-src.lha
/
GNU
/
src
/
amiga
/
gcc-2.3.3
/
cp-tree.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-06
|
49KB
|
1,754 lines
/* Language-dependent node constructors for parse phase of GNU compiler.
Copyright (C) 1987, 1988, 1992 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. */
#include "config.h"
#include <stdio.h>
#include "obstack.h"
#include "tree.h"
#include "cp-tree.h"
#include "flags.h"
#define CEIL(x,y) (((x) + (y) - 1) / (y))
/* Return nonzero if REF is an lvalue valid for this language.
Lvalues can be assigned, unless they have TREE_READONLY.
Lvalues can have their address taken, unless they have DECL_REGISTER. */
int
lvalue_p (ref)
tree ref;
{
register enum tree_code code = TREE_CODE (ref);
if (language_lvalue_valid (ref))
switch (code)
{
/* preincrements and predecrements are valid lvals, provided
what they refer to are valid lvals. */
case PREINCREMENT_EXPR:
case PREDECREMENT_EXPR:
case COMPONENT_REF:
return lvalue_p (TREE_OPERAND (ref, 0));
case STRING_CST:
return 1;
case VAR_DECL:
if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return 0;
case INDIRECT_REF:
case ARRAY_REF:
case PARM_DECL:
case RESULT_DECL:
case ERROR_MARK:
if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
&& TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
return 1;
break;
case TARGET_EXPR:
case WITH_CLEANUP_EXPR:
return 1;
case CALL_EXPR:
if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE
/* unary_complex_lvalue knows how to deal with this case. */
|| TREE_ADDRESSABLE (TREE_TYPE (ref)))
return 1;
break;
/* A currently unresolved scope ref. */
case SCOPE_REF:
my_friendly_abort (103);
case OFFSET_REF:
if (TREE_CODE (TREE_OPERAND (ref, 1)) == FUNCTION_DECL)
return 1;
if (TREE_CODE (TREE_OPERAND (ref, 1)) == VAR_DECL)
if (TREE_READONLY (ref) && ! TREE_STATIC (ref)
&& DECL_LANG_SPECIFIC (ref)
&& DECL_IN_AGGR_P (ref))
return 0;
else
return 1;
break;
case ADDR_EXPR:
/* ANSI C++ June 5 1992 WP 5.4.14. The result of a cast to a
reference is an lvalue. */
if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
return 1;
break;
}
return 0;
}
/* Return nonzero if REF is an lvalue valid for this language;
otherwise, print an error message and return zero. */
int
lvalue_or_else (ref, string)
tree ref;
char *string;
{
int win = lvalue_p (ref);
if (! win)
error ("invalid lvalue in %s", string);
return win;
}
/* INIT is a CALL_EXPR which needs info about its target.
TYPE is the type that this initialization should appear to have.
Build an encapsulation of the initialization to perform
and return it so that it can be processed by language-independent
and language-specific expression expanders.
If WITH_CLEANUP_P is nonzero, we build a cleanup for this expression.
Otherwise, cleanups are not built here. For example, when building
an initialization for a stack slot, since the called function handles
the cleanup, we would not want to do it here. */
tree
build_cplus_new (type, init, with_cleanup_p)
tree type;
tree init;
int with_cleanup_p;
{
tree slot = build (VAR_DECL, type);
tree rval = build (NEW_EXPR, type,
TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), slot);
TREE_SIDE_EFFECTS (rval) = 1;
TREE_ADDRESSABLE (rval) = 1;
rval = build (TARGET_EXPR, type, slot, rval, 0);
TREE_SIDE_EFFECTS (rval) = 1;
TREE_ADDRESSABLE (rval) = 1;
if (with_cleanup_p && TYPE_NEEDS_DESTRUCTOR (type))
{
rval = build (WITH_CLEANUP_EXPR, type, rval, 0,
build_delete (TYPE_POINTER_TO (type),
build_unary_op (ADDR_EXPR, slot, 0),
integer_two_node,
LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0));
TREE_SIDE_EFFECTS (rval) = 1;
}
return rval;
}
/* Recursively search EXP for CALL_EXPRs that need cleanups and replace
these CALL_EXPRs with tree nodes that will perform the cleanups. */
tree
break_out_cleanups (exp)
tree exp;
{
tree tmp = exp;
if (TREE_CODE (tmp) == CALL_EXPR
&& TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (tmp)))
return build_cplus_new (TREE_TYPE (tmp), tmp, 1);
while (TREE_CODE (tmp) == NOP_EXPR
|| TREE_CODE (tmp) == CONVERT_EXPR
|| TREE_CODE (tmp) == NON_LVALUE_EXPR)
{
if (TREE_CODE (TREE_OPERAND (tmp, 0)) == CALL_EXPR
&& TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (TREE_OPERAND (tmp, 0))))
{
TREE_OPERAND (tmp, 0)
= build_cplus_new (TREE_TYPE (TREE_OPERAND (tmp, 0)),
TREE_OPERAND (tmp, 0), 1);
break;
}
else
tmp = TREE_OPERAND (tmp, 0);
}
return exp;
}
/* Recursively perform a preorder search EXP for CALL_EXPRs, making
copies where they are found. Returns a deep copy all nodes transitively
containing CALL_EXPRs. */
tree
break_out_calls (exp)
tree exp;
{
register tree t1, t2;
register enum tree_code code;
register int changed = 0;
register int i;
if (exp == NULL_TREE)
return exp;
code = TREE_CODE (exp);
if (code == CALL_EXPR)
return copy_node (exp);
/* Don't try and defeat a save_expr, as it should only be done once. */
if (code == SAVE_EXPR)
return exp;
switch (TREE_CODE_CLASS (code))
{
default:
abort ();
case 'c': /* a constant */
case 't': /* a type node */
case 'x': /* something random, like an identifier or an ERROR_MARK. */
return exp;
case 'd': /* A decl node */
t1 = break_out_calls (DECL_INITIAL (exp));
if (t1 != DECL_INITIAL (exp))
{
exp = copy_node (exp);
DECL_INITIAL (exp) = t1;
}
return exp;
case 'b': /* A block node */
{
/* Don't know how to handle these correctly yet. Must do a
break_out_calls on all DECL_INITIAL values for local variables,
and also break_out_calls on all sub-blocks and sub-statements. */
abort ();
}
return exp;
case 'e': /* an expression */
case 'r': /* a reference */
case 's': /* an expression with side effects */
for (i = tree_code_length[(int) code] - 1; i >= 0; i--)
{
t1 = break_out_calls (TREE_OPERAND (exp, i));
if (t1 != TREE_OPERAND (exp, i))
{
if (changed++ == 0)
exp = copy_node (exp);
TREE_OPERAND (exp, i) = t1;
}
}
return exp;
case '<': /* a comparison expression */
case '2': /* a binary arithmetic expression */
t2 = break_out_calls (TREE_OPERAND (exp, 1));
if (t2 != TREE_OPERAND (exp, 1))
changed = 1;
case '1': /* a unary arithmetic expression */
t1 = break_out_calls (TREE_OPERAND (exp, 0));
if (t1 != TREE_OPERAND (exp, 0))
changed = 1;
if (changed)
{
if (tree_code_length[(int) code] == 1)
return build1 (code, TREE_TYPE (exp), t1);
else
return build (code, TREE_TYPE (exp), t1, t2);
}
return exp;
}
}
extern struct obstack *current_obstack;
extern struct obstack permanent_obstack, class_obstack;
extern struct obstack *saveable_obstack;
/* Here is how primitive or already-canonicalized types' hash
codes are made. MUST BE CONSISTENT WITH tree.c !!! */
#define TYPE_HASH(TYPE) ((HOST_WIDE_INT) (TYPE) & 0777777)
/* Construct, lay out and return the type of methods belonging to class
BASETYPE and whose arguments and values are described by TYPE.
If that type exists already, reuse it.
TYPE must be a FUNCTION_TYPE node. */
tree
build_cplus_method_type (basetype, rettype, argtypes)
tree basetype, rettype,