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