OSDN Git Service

Build compiler checksum from object files v2
[pf3gnuchains/gcc-fork.git] / gcc / objcp / objcp-decl.c
1 /* Process the ObjC-specific declarations and variables for 
2    the Objective-C++ compiler.
3    Copyright (C) 2005, 2007 Free Software Foundation, Inc.
4    Contributed by Ziemowit Laski  <zlaski@apple.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "cp-tree.h"
28 #include "hashtab.h"
29
30 #include "objc-act.h"
31 #include "objcp-decl.h"
32
33 /* Hacks to simulate start_struct() and finish_struct(). */
34
35 tree 
36 objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
37                     enum tree_code code ATTRIBUTE_UNUSED, tree name)
38 {
39   tree s;
40   /* The idea here is to mimic the actions that the C++ parser takes when
41      constructing 'extern "C" struct NAME {'.  */
42   push_lang_context (lang_name_c);
43
44   if (!name)
45     name = make_anon_name ();
46
47   s = xref_tag (record_type, name, ts_global, 0);
48   CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
49   xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
50
51   return begin_class_definition (s, NULL_TREE);
52 }
53
54 tree 
55 objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
56                      tree t, tree fieldlist, tree attributes)
57 {
58   tree field, next_field;
59
60   for (field = fieldlist; field; field = next_field)
61   {
62     next_field = TREE_CHAIN (field);      /* insert one field at a time;  */
63     TREE_CHAIN (field) = NULL_TREE;       /* otherwise, grokfield croaks. */
64     finish_member_declaration (field);
65   }
66   t = finish_struct (t, attributes);
67
68   /* If we are inside an @interface and are generating the list of
69      ivars, we need to check for duplicate ivars.
70   */
71   if (fieldlist)
72     {
73       tree original_fieldlist = fieldlist;
74       fieldlist = objc_get_interface_ivars (fieldlist);
75       if (fieldlist != original_fieldlist)
76         {
77           /* Minimal implementation of the equivalent of the C
78              front-end's detect_field_duplicates().
79           */
80           htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
81           tree x, y;
82           void **slot;
83           
84           for (x = fieldlist; x ; x = DECL_CHAIN (x))
85             if ((y = DECL_NAME (x)) != 0)
86               {
87                 slot = htab_find_slot (htab, y, INSERT);
88                 if (*slot)
89                   {
90                     error ("duplicate member %q+D", x);
91                     DECL_NAME (x) = NULL_TREE;
92                   }
93                 *slot = y;
94               }
95           
96           htab_delete (htab);
97         }
98     }
99
100   pop_lang_context ();
101
102   return t;
103 }
104
105 void
106 objcp_finish_function (void)
107 {
108   /* The C++ flavor of 'finish_function' does not generate RTL -- one has
109      to call 'expand_or_defer_fn' to do that.  */
110   expand_or_defer_fn (finish_function (0));
111 }
112
113 tree
114 objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
115 {
116   return xref_tag (record_type, name, ts_global, false);
117 }
118
119 int
120 objcp_comptypes (tree type1, tree type2)
121 {     
122   return comptypes (type1, type2, COMPARE_STRICT);
123 }
124
125 tree
126 objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
127 {
128   return begin_compound_stmt (0);
129 }
130
131 tree
132 objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
133 {
134   /* The following has been snarfed from
135      cp/semantics.c:finish_compound_stmt().  */
136   if (TREE_CODE (stmt) == BIND_EXPR)
137     BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
138   else if (STATEMENT_LIST_NO_SCOPE (stmt))
139     stmt = pop_stmt_list (stmt);
140   else
141     stmt = do_poplevel (stmt);
142
143   return stmt;
144 }