objcp-decl.c 3.4 KB

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