OSDN Git Service

Merge from pch-branch.
[pf3gnuchains/gcc-fork.git] / gcc / cp / expr.c
1 /* Convert language-specific tree expression to rtl instructions,
2    for GNU compiler.
3    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4    2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "flags.h"
31 #include "expr.h"
32 #include "cp-tree.h"
33 #include "toplev.h"
34 #include "except.h"
35 #include "tm_p.h"
36
37 /* Hook used by output_constant to expand language-specific
38    constants.  */
39
40 tree
41 cplus_expand_constant (cst)
42      tree cst;
43 {
44   switch (TREE_CODE (cst))
45     {
46     case PTRMEM_CST:
47       {
48         tree type = TREE_TYPE (cst);
49         tree member;
50       
51         /* Find the member.  */
52         member = PTRMEM_CST_MEMBER (cst);
53
54         if (TREE_CODE (member) == FIELD_DECL) 
55           {
56             /* Find the offset for the field.  */
57             tree offset = byte_position (member);
58             cst = fold (build1 (NOP_EXPR, type, offset));
59           }
60         else
61           {
62             tree delta;
63             tree pfn;
64
65             expand_ptrmemfunc_cst (cst, &delta, &pfn);
66             cst = build_ptrmemfunc1 (type, delta, pfn);
67           }
68       }
69       break;
70
71     default:
72       /* There's nothing to do.  */
73       break;
74     }
75
76   return cst;
77 }
78
79 /* Hook used by expand_expr to expand language-specific tree codes.  */
80
81 rtx
82 cxx_expand_expr (exp, target, tmode, modifier)
83      tree exp;
84      rtx target;
85      enum machine_mode tmode;
86      int modifier;  /* Actually an enum expand_modifier.  */
87 {
88   tree type = TREE_TYPE (exp);
89   register enum machine_mode mode = TYPE_MODE (type);
90   register enum tree_code code = TREE_CODE (exp);
91   rtx ret;
92
93   /* No sense saving up arithmetic to be done
94      if it's all in the wrong mode to form part of an address.
95      And force_operand won't know whether to sign-extend or zero-extend.  */
96
97   if (mode != Pmode && modifier == EXPAND_SUM)
98     modifier = EXPAND_NORMAL;
99
100   switch (code)
101     {
102     case PTRMEM_CST:
103       return expand_expr (cplus_expand_constant (exp),
104                           target, tmode, modifier);
105
106     case OFFSET_REF:
107       /* Offset refs should not make it through to here.  */
108       abort ();
109       return const0_rtx;
110       
111     case THROW_EXPR:
112       expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
113       return NULL;
114
115     case MUST_NOT_THROW_EXPR:
116       expand_eh_region_start ();
117       ret = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
118       expand_eh_region_end_must_not_throw (build_call (terminate_node, 0));
119       return ret;
120
121     case EMPTY_CLASS_EXPR:
122       /* We don't need to generate any code for an empty class.  */
123       return const0_rtx;
124
125     case BASELINK:
126       return expand_expr (BASELINK_FUNCTIONS (exp), target, tmode,
127                           modifier);
128
129     default:
130       return c_expand_expr (exp, target, tmode, modifier);
131     }
132   abort ();
133   /* NOTREACHED */
134   return NULL;
135 }