Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / objcp / objcp-decl.c
blob3804cba2be9cde6fedec8f8f1650ff884ec84d38
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>
6 This file is part of GCC.
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.
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.
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/>. */
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"
30 #include "c-family/c-objc.h"
31 #include "objc-act.h"
32 #include "objcp-decl.h"
34 /* Hacks to simulate start_struct() and finish_struct(). */
36 tree
37 objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
38 enum tree_code code ATTRIBUTE_UNUSED, tree name)
40 tree s;
41 /* The idea here is to mimic the actions that the C++ parser takes when
42 constructing 'extern "C" struct NAME {'. */
43 push_lang_context (lang_name_c);
45 if (!name)
46 name = make_anon_name ();
48 s = xref_tag (record_type, name, ts_global, 0);
49 CLASSTYPE_DECLARED_CLASS (s) = 0; /* this is a 'struct', not a 'class'. */
50 xref_basetypes (s, NULL_TREE); /* no base classes here! */
52 return begin_class_definition (s, NULL_TREE);
55 tree
56 objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
57 tree t, tree fieldlist, tree attributes)
59 tree field, next_field;
61 for (field = fieldlist; field; field = next_field)
63 next_field = TREE_CHAIN (field); /* insert one field at a time; */
64 TREE_CHAIN (field) = NULL_TREE; /* otherwise, grokfield croaks. */
65 finish_member_declaration (field);
67 t = finish_struct (t, attributes);
69 /* If we are inside an @interface and are generating the list of
70 ivars, we need to check for duplicate ivars.
72 if (fieldlist)
74 tree original_fieldlist = fieldlist;
75 fieldlist = objc_get_interface_ivars (fieldlist);
76 if (fieldlist != original_fieldlist)
78 /* Minimal implementation of the equivalent of the C
79 front-end's detect_field_duplicates().
81 htab_t htab = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
82 tree x, y;
83 void **slot;
85 for (x = fieldlist; x ; x = DECL_CHAIN (x))
86 if ((y = DECL_NAME (x)) != 0)
88 slot = htab_find_slot (htab, y, INSERT);
89 if (*slot)
91 error ("duplicate member %q+D", x);
92 DECL_NAME (x) = NULL_TREE;
94 *slot = y;
97 htab_delete (htab);
101 pop_lang_context ();
103 return t;
106 void
107 objcp_finish_function (void)
109 /* The C++ flavor of 'finish_function' does not generate RTL -- one has
110 to call 'expand_or_defer_fn' to do that. */
111 expand_or_defer_fn (finish_function (0));
114 tree
115 objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
117 return xref_tag (record_type, name, ts_global, false);
121 objcp_comptypes (tree type1, tree type2)
123 return comptypes (type1, type2, COMPARE_STRICT);
126 tree
127 objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
129 return begin_compound_stmt (0);
132 tree
133 objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
135 /* The following has been snarfed from
136 cp/semantics.c:finish_compound_stmt(). */
137 if (TREE_CODE (stmt) == BIND_EXPR)
138 BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
139 else if (STATEMENT_LIST_NO_SCOPE (stmt))
140 stmt = pop_stmt_list (stmt);
141 else
142 stmt = do_poplevel (stmt);
144 return stmt;