xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/objcp/objcp-decl.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
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 "rtl.h"
28 #include "expr.h"
29 #include "cp-tree.h"
30 #include "c-common.h"
31 #include "flags.h"
32 #include "input.h"
33 #include "except.h"
34 #include "output.h"
35 #include "toplev.h"
36 #include "cpplib.h"
37 #include "debug.h"
38 #include "target.h"
39 #include "varray.h"
40 
41 #include "objc-act.h"
42 #include "objcp-decl.h"
43 
44 /* Hacks to simulate start_struct() and finish_struct(). */
45 
46 tree
47 objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
48 		    enum tree_code code ATTRIBUTE_UNUSED, tree name)
49 {
50   tree s;
51   /* The idea here is to mimic the actions that the C++ parser takes when
52      constructing 'extern "C" struct NAME {'.  */
53   push_lang_context (lang_name_c);
54 
55   if (!name)
56     name = make_anon_name ();
57 
58   s = xref_tag (record_type, name, ts_global, 0);
59   CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
60   xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
61 
62   return begin_class_definition (s, NULL_TREE);
63 }
64 
65 tree
66 objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
67 		     tree t, tree fieldlist, tree attributes)
68 {
69   tree field, next_field;
70 
71   for (field = fieldlist; field; field = next_field)
72   {
73     next_field = TREE_CHAIN (field);      /* insert one field at a time;  */
74     TREE_CHAIN (field) = NULL_TREE;       /* otherwise, grokfield croaks. */
75     finish_member_declaration (field);
76   }
77   t = finish_struct (t, attributes);
78   pop_lang_context ();
79 
80   return t;
81 }
82 
83 void
84 objcp_finish_function (void)
85 {
86   /* The C++ flavor of 'finish_function' does not generate RTL -- one has
87      to call 'expand_or_defer_fn' to do that.  */
88   expand_or_defer_fn (finish_function (0));
89 }
90 
91 tree
92 objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
93 {
94   return xref_tag (record_type, name, ts_global, false);
95 }
96 
97 int
98 objcp_comptypes (tree type1, tree type2)
99 {
100   return comptypes (type1, type2, COMPARE_STRICT);
101 }
102 
103 tree
104 objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
105 {
106   return begin_compound_stmt (0);
107 }
108 
109 tree
110 objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
111 {
112   /* The following has been snarfed from
113      cp/semantics.c:finish_compound_stmt().  */
114   if (TREE_CODE (stmt) == BIND_EXPR)
115     BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
116   else if (STATEMENT_LIST_NO_SCOPE (stmt))
117     stmt = pop_stmt_list (stmt);
118   else
119     stmt = do_poplevel (stmt);
120 
121   return stmt;
122 }
123