aboutsummaryrefslogtreecommitdiff
path: root/odb/semantics/class.cxx
blob: acecb35fd7cc61f5dc07827d2ace36b392c6dad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// file      : odb/semantics/class.cxx
// license   : GNU GPL v3; see accompanying LICENSE file

#include <odb/gcc.hxx> // TYPE_HAS_DEFAULT_CONSTRUCTOR

#include <cutl/compiler/type-info.hxx>
#include <odb/semantics/class.hxx>

namespace semantics
{
  inherits::
  inherits (access_type access, bool virt)
      : virt_ (virt), access_ (access)
  {
  }

  class_::
  class_ (path const& file, size_t line, size_t column, tree tn)
      : node (file, line, column, tn)
  {
  }

  bool class_::
  default_ctor () const
  {
    tree t (tree_node ());

    // TYPE_HAS_DEFAULT_CONSTRUCTOR() returns true if we have a deleted
    // default ctor. locate_ctor(), on the other hand, returns NULL_TREE in
    // this case.
    //
    if (TYPE_HAS_DEFAULT_CONSTRUCTOR (t))
    {
#if BUILDING_GCC_MAJOR >= 8

      // Work around GCC bug 86441. Essentially, we should not trigger an
      // instantiation or completion of the default ctor. As a result, we will
      // assume that if we have a lazy default ctor, it is not implicitly
      // deleted.
      //
      if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
        return true;

      for (ovl_iterator i (CLASSTYPE_CONSTRUCTORS (t)); i; ++i)
      {
        tree f (*i);

        if (TREE_CODE (f) == FUNCTION_DECL && DECL_DELETED_FN (f))
          continue;

        if (default_ctor_p (f))
          return true;
      }
#else
      return locate_ctor (t) != NULL_TREE;
#endif

    }

    return false;
  }

  bool class_::
  complete () const
  {
    return COMPLETE_TYPE_P (tree_node ());
  }

  bool class_::
  abstract () const
  {
    return CLASSTYPE_PURE_VIRTUALS (tree_node ());
  }

  names* class_::
  lookup (string const& name,
          type_id const& ti,
          unsigned int flags,
          bool* ph) const
  {
    bool h (false);
    bool& rh (ph != 0 ? *ph : h);

    names* r (scope::lookup (name, ti, flags | exclude_outer, &rh));

    if (r != 0)
      return r;

    // If we found a name but the types didn't match, then bail out
    // unless we want hidden names.
    //
    if (rh && (flags & include_hidden) == 0)
      return 0;

    // Look in the base classes unless requested not to. For the name
    // lookup purposes, bases can be viewed as a parallel set of outer
    // scopes that are searched after the class scope and before any
    // real outer scope. Interestingly, outer scopes of bases are not
    // considered during this lookup, only their bases.
    //
    if ((flags & exclude_base) == 0)
    {
      // Being hidden in one base doesn't mean it is also hidden in the
      // other. Normally that would be an ambiguous lookup, but we use
      // relaxed rules.
      //
      bool any_h (false); // Indicates whether any base hides the name.

      for (inherits_iterator i (inherits_begin ()); i != inherits_end (); ++i)
      {
        bool h (false); // Indicates whether this base hides the name.
        names* br (i->base ().lookup (name, ti, flags | exclude_outer, &h));
        any_h = any_h || h;

        if (br != 0)
        {
          if (r != 0)
            throw ambiguous (*r, *br);

          r = br;

          if (h)
            rh = true;
        }
      }

      if (r != 0)
        return r;

      if (any_h)
      {
        rh = true;
        if ((flags & include_hidden) == 0)
          return 0;
      }
    }

    // Look in the outer scope unless requested not to.
    //
    if ((flags & exclude_outer) == 0)
      return scope ().lookup (name, ti, flags, &rh);

    return 0;
  }

  // type info
  //
  namespace
  {
    struct init
    {
      init ()
      {
        using compiler::type_info;

        // inherits
        //
        {
          type_info ti (typeid (inherits));
          ti.add_base (typeid (edge));
          insert (ti);
        }

        // class_
        //
        {
          type_info ti (typeid (class_));
          ti.add_base (typeid (type));
          ti.add_base (typeid (scope));
          insert (ti);
        }
      }
    } init_;
  }
}