xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/objcp/objcp-decl.c (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
136ac495dSmrg /* Process the ObjC-specific declarations and variables for
236ac495dSmrg    the Objective-C++ compiler.
3*8feb0f0bSmrg    Copyright (C) 2005-2020 Free Software Foundation, Inc.
436ac495dSmrg    Contributed by Ziemowit Laski  <zlaski@apple.com>
536ac495dSmrg 
636ac495dSmrg This file is part of GCC.
736ac495dSmrg 
836ac495dSmrg GCC is free software; you can redistribute it and/or modify it under
936ac495dSmrg the terms of the GNU General Public License as published by the Free
1036ac495dSmrg Software Foundation; either version 3, or (at your option) any later
1136ac495dSmrg version.
1236ac495dSmrg 
1336ac495dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1436ac495dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1536ac495dSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1636ac495dSmrg for more details.
1736ac495dSmrg 
1836ac495dSmrg You should have received a copy of the GNU General Public License
1936ac495dSmrg along with GCC; see the file COPYING3.  If not see
2036ac495dSmrg <http://www.gnu.org/licenses/>.  */
2136ac495dSmrg 
2236ac495dSmrg #include "config.h"
2336ac495dSmrg #include "system.h"
2436ac495dSmrg #include "coretypes.h"
2536ac495dSmrg #include "cp-tree.h"
2636ac495dSmrg 
2736ac495dSmrg #include "c-family/c-objc.h"
2836ac495dSmrg #include "objcp-decl.h"
2936ac495dSmrg 
3036ac495dSmrg /* Hacks to simulate start_struct() and finish_struct(). */
3136ac495dSmrg 
3236ac495dSmrg tree
objcp_start_struct(location_t loc ATTRIBUTE_UNUSED,enum tree_code code ATTRIBUTE_UNUSED,tree name)3336ac495dSmrg objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
3436ac495dSmrg 		    enum tree_code code ATTRIBUTE_UNUSED, tree name)
3536ac495dSmrg {
3636ac495dSmrg   tree s;
3736ac495dSmrg   /* The idea here is to mimic the actions that the C++ parser takes when
3836ac495dSmrg      constructing 'extern "C" struct NAME {'.  */
3936ac495dSmrg   push_lang_context (lang_name_c);
4036ac495dSmrg 
4136ac495dSmrg   if (!name)
4236ac495dSmrg     name = make_anon_name ();
4336ac495dSmrg 
4436ac495dSmrg   s = xref_tag (record_type, name, ts_global, 0);
4536ac495dSmrg   CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
4636ac495dSmrg   xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
4736ac495dSmrg 
4836ac495dSmrg   return begin_class_definition (s);
4936ac495dSmrg }
5036ac495dSmrg 
5136ac495dSmrg tree
objcp_finish_struct(location_t loc ATTRIBUTE_UNUSED,tree t,tree fieldlist,tree attributes)5236ac495dSmrg objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
5336ac495dSmrg 		     tree t, tree fieldlist, tree attributes)
5436ac495dSmrg {
5536ac495dSmrg   tree field, next_field;
5636ac495dSmrg 
5736ac495dSmrg   for (field = fieldlist; field; field = next_field)
5836ac495dSmrg   {
5936ac495dSmrg     next_field = TREE_CHAIN (field);      /* insert one field at a time;  */
6036ac495dSmrg     TREE_CHAIN (field) = NULL_TREE;       /* otherwise, grokfield croaks. */
6136ac495dSmrg     finish_member_declaration (field);
6236ac495dSmrg   }
6336ac495dSmrg   t = finish_struct (t, attributes);
6436ac495dSmrg 
6536ac495dSmrg   /* If we are inside an @interface and are generating the list of
6636ac495dSmrg      ivars, we need to check for duplicate ivars.
6736ac495dSmrg   */
6836ac495dSmrg   if (fieldlist)
6936ac495dSmrg     objc_detect_field_duplicates (true);
7036ac495dSmrg 
7136ac495dSmrg   pop_lang_context ();
7236ac495dSmrg 
7336ac495dSmrg   return t;
7436ac495dSmrg }
7536ac495dSmrg 
7636ac495dSmrg void
objcp_finish_function(void)7736ac495dSmrg objcp_finish_function (void)
7836ac495dSmrg {
7936ac495dSmrg   /* The C++ flavor of 'finish_function' does not generate RTL -- one has
8036ac495dSmrg      to call 'expand_or_defer_fn' to do that.  */
8136ac495dSmrg   expand_or_defer_fn (finish_function (0));
8236ac495dSmrg }
8336ac495dSmrg 
8436ac495dSmrg tree
objcp_xref_tag(enum tree_code code ATTRIBUTE_UNUSED,tree name)8536ac495dSmrg objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
8636ac495dSmrg {
8736ac495dSmrg   return xref_tag (record_type, name, ts_global, false);
8836ac495dSmrg }
8936ac495dSmrg 
9036ac495dSmrg int
objcp_comptypes(tree type1,tree type2)9136ac495dSmrg objcp_comptypes (tree type1, tree type2)
9236ac495dSmrg {
9336ac495dSmrg   return comptypes (type1, type2, COMPARE_STRICT);
9436ac495dSmrg }
9536ac495dSmrg 
9636ac495dSmrg tree
objcp_begin_compound_stmt(int flags ATTRIBUTE_UNUSED)9736ac495dSmrg objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
9836ac495dSmrg {
9936ac495dSmrg   return begin_compound_stmt (0);
10036ac495dSmrg }
10136ac495dSmrg 
10236ac495dSmrg tree
objcp_end_compound_stmt(tree stmt,int flags ATTRIBUTE_UNUSED)10336ac495dSmrg objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
10436ac495dSmrg {
10536ac495dSmrg   /* The following has been snarfed from
10636ac495dSmrg      cp/semantics.c:finish_compound_stmt().  */
10736ac495dSmrg   if (TREE_CODE (stmt) == BIND_EXPR)
10836ac495dSmrg     BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
10936ac495dSmrg   else if (STATEMENT_LIST_NO_SCOPE (stmt))
11036ac495dSmrg     stmt = pop_stmt_list (stmt);
11136ac495dSmrg   else
11236ac495dSmrg     stmt = do_poplevel (stmt);
11336ac495dSmrg 
11436ac495dSmrg   return stmt;
11536ac495dSmrg }
116