expr.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Convert language-specific tree expression to rtl instructions,
  2. for GNU compiler.
  3. Copyright (C) 1988-2015 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "tm.h"
  20. #include "hash-set.h"
  21. #include "machmode.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "flags.h"
  31. #include "cp-tree.h"
  32. #include "tm_p.h"
  33. /* Expand C++-specific constants. Currently, this means PTRMEM_CST. */
  34. tree
  35. cplus_expand_constant (tree cst)
  36. {
  37. switch (TREE_CODE (cst))
  38. {
  39. case PTRMEM_CST:
  40. {
  41. tree type = TREE_TYPE (cst);
  42. tree member;
  43. /* Find the member. */
  44. member = PTRMEM_CST_MEMBER (cst);
  45. /* We can't lower this until the class is complete. */
  46. if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
  47. return cst;
  48. if (TREE_CODE (member) == FIELD_DECL)
  49. {
  50. /* Find the offset for the field. */
  51. cst = byte_position (member);
  52. while (!same_type_p (DECL_CONTEXT (member),
  53. TYPE_PTRMEM_CLASS_TYPE (type)))
  54. {
  55. /* The MEMBER must have been nestled within an
  56. anonymous aggregate contained in TYPE. Find the
  57. anonymous aggregate. */
  58. member = lookup_anon_field (TYPE_PTRMEM_CLASS_TYPE (type),
  59. DECL_CONTEXT (member));
  60. cst = size_binop (PLUS_EXPR, cst, byte_position (member));
  61. }
  62. cst = fold (build_nop (type, cst));
  63. }
  64. else
  65. {
  66. tree delta;
  67. tree pfn;
  68. expand_ptrmemfunc_cst (cst, &delta, &pfn);
  69. cst = build_ptrmemfunc1 (type, delta, pfn);
  70. }
  71. }
  72. break;
  73. case CONSTRUCTOR:
  74. {
  75. constructor_elt *elt;
  76. unsigned HOST_WIDE_INT idx;
  77. FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (cst), idx, elt)
  78. elt->value = cplus_expand_constant (elt->value);
  79. }
  80. default:
  81. /* There's nothing to do. */
  82. break;
  83. }
  84. return cst;
  85. }
  86. /* Called whenever an expression is used
  87. in a rvalue context. */
  88. tree
  89. mark_rvalue_use (tree expr)
  90. {
  91. mark_exp_read (expr);
  92. return expr;
  93. }
  94. /* Called whenever an expression is used
  95. in a lvalue context. */
  96. tree
  97. mark_lvalue_use (tree expr)
  98. {
  99. mark_exp_read (expr);
  100. return expr;
  101. }
  102. /* Called whenever an expression is used in a type use context. */
  103. tree
  104. mark_type_use (tree expr)
  105. {
  106. mark_exp_read (expr);
  107. return expr;
  108. }
  109. /* Mark EXP as read, not just set, for set but not used -Wunused
  110. warning purposes. */
  111. void
  112. mark_exp_read (tree exp)
  113. {
  114. if (exp == NULL)
  115. return;
  116. switch (TREE_CODE (exp))
  117. {
  118. case VAR_DECL:
  119. case PARM_DECL:
  120. DECL_READ_P (exp) = 1;
  121. break;
  122. case ARRAY_REF:
  123. case COMPONENT_REF:
  124. case MODIFY_EXPR:
  125. case REALPART_EXPR:
  126. case IMAGPART_EXPR:
  127. CASE_CONVERT:
  128. case ADDR_EXPR:
  129. case INDIRECT_REF:
  130. case FLOAT_EXPR:
  131. mark_exp_read (TREE_OPERAND (exp, 0));
  132. break;
  133. case COMPOUND_EXPR:
  134. mark_exp_read (TREE_OPERAND (exp, 1));
  135. break;
  136. case COND_EXPR:
  137. if (TREE_OPERAND (exp, 1))
  138. mark_exp_read (TREE_OPERAND (exp, 1));
  139. if (TREE_OPERAND (exp, 2))
  140. mark_exp_read (TREE_OPERAND (exp, 2));
  141. break;
  142. default:
  143. break;
  144. }
  145. }