]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/objcp/objcp-decl.c
2015-06-17 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / objcp / objcp-decl.c
1 /* Process the ObjC-specific declarations and variables for
2 the Objective-C++ compiler.
3 Copyright (C) 2005-2015 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 "vec.h"
27 #include "alias.h"
28 #include "symtab.h"
29 #include "options.h"
30 #include "inchash.h"
31 #include "tree.h"
32 #include "cp-tree.h"
33
34 #include "c-family/c-objc.h"
35 #include "objc-act.h"
36 #include "objcp-decl.h"
37
38 /* Hacks to simulate start_struct() and finish_struct(). */
39
40 tree
41 objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
42 enum tree_code code ATTRIBUTE_UNUSED, tree name)
43 {
44 tree s;
45 /* The idea here is to mimic the actions that the C++ parser takes when
46 constructing 'extern "C" struct NAME {'. */
47 push_lang_context (lang_name_c);
48
49 if (!name)
50 name = make_anon_name ();
51
52 s = xref_tag (record_type, name, ts_global, 0);
53 CLASSTYPE_DECLARED_CLASS (s) = 0; /* this is a 'struct', not a 'class'. */
54 xref_basetypes (s, NULL_TREE); /* no base classes here! */
55
56 return begin_class_definition (s);
57 }
58
59 tree
60 objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
61 tree t, tree fieldlist, tree attributes)
62 {
63 tree field, next_field;
64
65 for (field = fieldlist; field; field = next_field)
66 {
67 next_field = TREE_CHAIN (field); /* insert one field at a time; */
68 TREE_CHAIN (field) = NULL_TREE; /* otherwise, grokfield croaks. */
69 finish_member_declaration (field);
70 }
71 t = finish_struct (t, attributes);
72
73 /* If we are inside an @interface and are generating the list of
74 ivars, we need to check for duplicate ivars.
75 */
76 if (fieldlist)
77 objc_detect_field_duplicates (true);
78
79 pop_lang_context ();
80
81 return t;
82 }
83
84 void
85 objcp_finish_function (void)
86 {
87 /* The C++ flavor of 'finish_function' does not generate RTL -- one has
88 to call 'expand_or_defer_fn' to do that. */
89 expand_or_defer_fn (finish_function (0));
90 }
91
92 tree
93 objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
94 {
95 return xref_tag (record_type, name, ts_global, false);
96 }
97
98 int
99 objcp_comptypes (tree type1, tree type2)
100 {
101 return comptypes (type1, type2, COMPARE_STRICT);
102 }
103
104 tree
105 objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
106 {
107 return begin_compound_stmt (0);
108 }
109
110 tree
111 objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
112 {
113 /* The following has been snarfed from
114 cp/semantics.c:finish_compound_stmt(). */
115 if (TREE_CODE (stmt) == BIND_EXPR)
116 BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
117 else if (STATEMENT_LIST_NO_SCOPE (stmt))
118 stmt = pop_stmt_list (stmt);
119 else
120 stmt = do_poplevel (stmt);
121
122 return stmt;
123 }