aboutsummaryrefslogtreecommitdiff
path: root/gcc/objcp/objcp-decl.c
blob: 8c6848ab87bc18acd22a8d864179d5205ec66f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* APPLE LOCAL file Objective-C++ */
/* Process the ObjC-specific declarations and variables for 
   the Objective-C++ compiler.
   Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   2001 Free Software Foundation, Inc.

This file is part of GCC.

GCC 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.

GCC 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 GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  */

/* Process declarations and symbol lookup for C front end.
   Also constructs types; the standard scalar types at initialization,
   and structure, union, array and enum types when they are declared.  */

/* ??? not all decl nodes are given the most useful possible
   line numbers.  For example, the CONST_DECLs for enum values.  */

#include "config.h"
#include "system.h"
#include "tree.h"
#include "rtl.h"
#include "expr.h"
#include "cp-tree.h"
#include "lex.h"
#include "c-common.h"
#include "flags.h"
#include "input.h"
#include "except.h"
#include "output.h"
#include "toplev.h"
#include "cpplib.h"
#include "debug.h"
#include "target.h"
#include "varray.h"

#include "objc-act.h"
#include "objcp-decl.h"

/* APPLE LOCAL indexing */
#include "genindex.h"

static tree objcp_parmlist = NULL_TREE;

/* Hacks to simulate start_struct() and finish_struct(). */

tree 
objcp_start_struct (code, name)
     enum tree_code code ATTRIBUTE_UNUSED; 
     tree name;
{ 
  int new_scope = 0;
  tree h, s;
  /* The idea here is to mimic the actions that the C++ parser takes when
     constructing 'extern "C" struct {'.  */
  push_lang_context (lang_name_c);
  if (!name)
     name = make_anon_name ();
  h = handle_class_head (record_type, 0, name, 0, 1, &new_scope);

  /* APPLE LOCAL indexing dpatel */
  flag_suppress_builtin_indexing = 1;

  s = begin_class_definition (TREE_TYPE (h));

  /* APPLE LOCAL indexing dpatel */
  flag_suppress_builtin_indexing = 0;

  return s;	
}

tree 
objcp_finish_struct (t, fieldlist, attributes)
     tree t; 
     tree fieldlist, attributes;
{
  tree s, field, next_field;

  /* APPLE LOCAL indexing dpatel */
  flag_suppress_builtin_indexing = 1;

  for (field = fieldlist; field; field = next_field) 
  {
    next_field = TREE_CHAIN (field);      /* insert one field at a time;  */
    TREE_CHAIN (field) = NULL_TREE;       /* otherwise, grokfield croaks. */
    finish_member_declaration (field);
  } 
  s = finish_class_definition (t, attributes, 1, 0);  

  /* APPLE LOCAL indexing dpatel */
  flag_suppress_builtin_indexing = 0;

  pop_lang_context ();
  return s;
}

int
objcp_start_function (declspecs, declarator, attributes)
     tree declspecs, declarator, attributes;
{ 
  return start_function (declspecs, declarator, attributes, 0);
}

void
objcp_finish_function (nested)
     int nested ATTRIBUTE_UNUSED;
{
  /* The C++ flavor of 'finish_function' does not generate RTL -- one has
     to call 'expand_body' to do that.  */
  expand_body (finish_function (0));
}

tree 
objcp_start_decl (declarator, declspecs, initialized, attributes)
     tree declarator, declspecs;
     int initialized;
     tree attributes;
{
  return start_decl (declarator, declspecs, initialized, 
		     attributes, NULL_TREE);
}
			  
void
objcp_finish_decl (decl, init, asmspec)
     tree decl, init, asmspec;
{
  cp_finish_decl (decl, init, asmspec, 0);
}

tree
objcp_lookup_name (name)
     tree name;
{
  return lookup_name (name, -1);
}

/* Hacks to simulate push_parm_decl() and get_parm_info(). */

tree
objcp_push_parm_decl (parm)
     tree parm;
{
  /* C++ parms are laid out slightly differently from C parms.  Adjust
     for this here.  */
  TREE_VALUE (parm) = TREE_PURPOSE (parm);
  TREE_PURPOSE (parm) = NULL_TREE;   
  
  if (objcp_parmlist)
    objcp_parmlist = chainon (objcp_parmlist, parm);
  else
    objcp_parmlist = parm;

  return objcp_parmlist;
}

tree 
objcp_get_parm_info (void_at_end) 
     int void_at_end;
{
  tree parm_info = finish_parmlist (objcp_parmlist, !void_at_end);
  
  /* The C++ notion of a parameter list differs slightly from that of
     C.  Adjust for this.  */
  parm_info = build_tree_list (parm_info, NULL_TREE);       
  objcp_parmlist = NULL_TREE;

  return parm_info;
}

void 
objcp_store_parm_decls ()
{
  /* In C++ land, 'start_function' calls 'store_parm_decls'; hence we
     do not need to do anything here.  */
}

tree
objcp_build_function_call (function, args)
     tree function, args;
{
  /* APPLE MERGE this is probably wrong */
  return build_function_call (function, args);
}
      
tree 
objcp_xref_tag (code, name)
     enum tree_code code;
     tree name;
{  
  if (code != RECORD_TYPE)
    abort ();   /* this is sheer laziness... */   
  return xref_tag (record_type, name, 0, 1);
}

tree
objcp_grokfield (filename, line, declarator, declspecs, width)
     const char *filename ATTRIBUTE_UNUSED;
     int line ATTRIBUTE_UNUSED;
     tree declarator, declspecs, width;
{     
  return (width) ? grokbitfield (declarator, declspecs, width)
		 : grokfield (declarator, declspecs, 0, 0, 0);
}		 

tree
objcp_build_component_ref (datum, component) 
     tree datum, component;
{
  /* The 'build_component_ref' routine has been removed from the C++
     front-end, but 'finish_class_member_access_expr' seems to be
     a worthy substitute.  */
  return finish_class_member_access_expr (datum, component);
}  

int
objcp_comptypes (type1, type2) 
     tree type1, type2;
{     
  return comptypes (type1, type2, 0);
}

tree 
objcp_type_name (type)
     tree type;
{
  if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
    return DECL_NAME (TYPE_NAME (type));
  else
    return TYPE_NAME (type);
}

tree 
objcp_type_size (type)
     tree type;
{
  tree size = TYPE_SIZE (type);
  if (size == NULL_TREE)
    {
      warning ("Requesting size of incomplete type `%s'",
	       IDENTIFIER_POINTER (objcp_type_name (type)));
      layout_type (type);
      size = TYPE_SIZE (type);
    }
  return build_int_2 (TREE_INT_CST_LOW (size), 0);
}

/* C++'s version of 'builtin_function' winds up placing our precious
   objc_msgSend and friends in namespace std!  This will not do.
   We shall hence duplicate C's 'builtin_function' here instead.   */
   
tree
objcp_builtin_function (name, type, code, class, libname, attrs)
     const char *name;
     tree type;
     int code;
     enum built_in_class class;
     const char *libname ATTRIBUTE_UNUSED;
     tree attrs;
{
  tree decl = NULL;
  decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
  DECL_EXTERNAL (decl) = 1;
  TREE_PUBLIC (decl) = 1;
  make_decl_rtl (decl, NULL);
  pushdecl (decl);
  DECL_BUILT_IN_CLASS (decl) = class;
  DECL_FUNCTION_CODE (decl) = code;
  DECL_ANTICIPATED (decl) = 1;

  /* Possibly apply some default attributes to this built-in function.  */
  if (attrs)
    decl_attributes (&decl, attrs, ATTR_FLAG_BUILT_IN);
  else
    decl_attributes (&decl, NULL_TREE, 0);

  return decl;
}

int
objcp_lookup_identifier (token, id, check_conflict)
     tree token;
     tree *id;
     int check_conflict;
{
  tree objc_id = lookup_objc_ivar (token);
  
  if (!check_conflict || objc_id && IS_SUPER (objc_id))
    *id = objc_id;
  else if (objc_id && *id && IDENTIFIER_BINDING (token)) 
    warning ("local declaration of `%s' hides instance variable",
	     IDENTIFIER_POINTER (token));
	     
  return (objc_id != NULL_TREE);
}