1232633Smp/* Process the ObjC-specific declarations and variables for
259243Sobrien   the Objective-C++ compiler.
359243Sobrien   Copyright (C) 2005-2020 Free Software Foundation, Inc.
459243Sobrien   Contributed by Ziemowit Laski  <zlaski@apple.com>
559243Sobrien
6232633SmpThis file is part of GCC.
759243Sobrien
859243SobrienGCC is free software; you can redistribute it and/or modify it under
959243Sobrienthe terms of the GNU General Public License as published by the Free
1059243SobrienSoftware Foundation; either version 3, or (at your option) any later
1159243Sobrienversion.
1259243Sobrien
1359243SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1459243SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
15232633SmpFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16232633Smpfor more details.
17131962Smp
18You should have received a copy of the GNU General Public License
19along 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 "cp-tree.h"
26
27#include "c-family/c-objc.h"
28#include "objcp-decl.h"
29
30/* Hacks to simulate start_struct() and finish_struct(). */
31
32tree
33objcp_start_struct (location_t loc ATTRIBUTE_UNUSED,
34		    enum tree_code code ATTRIBUTE_UNUSED, tree name)
35{
36  tree s;
37  /* The idea here is to mimic the actions that the C++ parser takes when
38     constructing 'extern "C" struct NAME {'.  */
39  push_lang_context (lang_name_c);
40
41  if (!name)
42    name = make_anon_name ();
43
44  s = xref_tag (record_type, name, ts_global, 0);
45  CLASSTYPE_DECLARED_CLASS (s) = 0;  /* this is a 'struct', not a 'class'.  */
46  xref_basetypes (s, NULL_TREE);     /* no base classes here!  */
47
48  return begin_class_definition (s);
49}
50
51tree
52objcp_finish_struct (location_t loc ATTRIBUTE_UNUSED,
53		     tree t, tree fieldlist, tree attributes)
54{
55  tree field, next_field;
56
57  for (field = fieldlist; field; field = next_field)
58  {
59    next_field = TREE_CHAIN (field);      /* insert one field at a time;  */
60    TREE_CHAIN (field) = NULL_TREE;       /* otherwise, grokfield croaks. */
61    finish_member_declaration (field);
62  }
63  t = finish_struct (t, attributes);
64
65  /* If we are inside an @interface and are generating the list of
66     ivars, we need to check for duplicate ivars.
67  */
68  if (fieldlist)
69    objc_detect_field_duplicates (true);
70
71  pop_lang_context ();
72
73  return t;
74}
75
76void
77objcp_finish_function (void)
78{
79  /* The C++ flavor of 'finish_function' does not generate RTL -- one has
80     to call 'expand_or_defer_fn' to do that.  */
81  expand_or_defer_fn (finish_function (0));
82}
83
84tree
85objcp_xref_tag (enum tree_code code ATTRIBUTE_UNUSED, tree name)
86{
87  return xref_tag (record_type, name, ts_global, false);
88}
89
90int
91objcp_comptypes (tree type1, tree type2)
92{
93  return comptypes (type1, type2, COMPARE_STRICT);
94}
95
96tree
97objcp_begin_compound_stmt (int flags ATTRIBUTE_UNUSED)
98{
99  return begin_compound_stmt (0);
100}
101
102tree
103objcp_end_compound_stmt (tree stmt, int flags ATTRIBUTE_UNUSED)
104{
105  /* The following has been snarfed from
106     cp/semantics.c:finish_compound_stmt().  */
107  if (TREE_CODE (stmt) == BIND_EXPR)
108    BIND_EXPR_BODY (stmt) = do_poplevel (BIND_EXPR_BODY (stmt));
109  else if (STATEMENT_LIST_NO_SCOPE (stmt))
110    stmt = pop_stmt_list (stmt);
111  else
112    stmt = do_poplevel (stmt);
113
114  return stmt;
115}
116