~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/src/CRecord.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-06-15 10:17:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090615101702-qsr30iptwbxylmo2
Tags: 1.0pre4~svn.20090615-1
* New upstream release.
* don't ignore errors in the postrm script
* avoid spurious creation of empty dir ./usr/sbin/
* improve short descriptions of libpuma-doc and libpuma-dev
* bump Standards-Version to 3.8.1
* bump debhelper compat level to level 7 (latest in stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "Puma/CUnionInfo.h"
22
22
#include "Puma/CFunctionInfo.h"
23
23
#include "Puma/CTemplateInfo.h"
 
24
#include "Puma/CAttributeInfo.h"
 
25
#include "Puma/CTemplateInstance.h"
 
26
#include "Puma/CBaseClassInfo.h"
24
27
#include "Puma/CTree.h"
25
28
#include "Puma/CSemDatabase.h"
26
29
#include <string.h>
41
44
}
42
45
 
43
46
bool CRecord::isComplete (unsigned long pos) const {
44
 
  CRecord *info = (CRecord*)DefObject ();
45
 
  if (info->isDefined ()) { 
 
47
  CRecord *record = (CRecord*)DefObject ();
 
48
  if (record->isDefined ()) { 
46
49
    if (pos == 0)
47
50
      return true;
 
51
    CObjectInfo *info = record;
 
52
    if (info->isTemplateInstance ()) {
 
53
      info = info->TemplateInstance ()->Template ()->ObjectInfo ();
 
54
    }
48
55
    CT_Token *token = info->Tree ()->token_node ();
49
56
    if (token && token->Number () <= pos)
50
57
      return true;
57
64
                     Tree ()->NodeName () == CT_UnionDef::NodeId ()); 
58
65
}
59
66
 
 
67
/** Yields true if the class has a trivial copy assignment operator. */
 
68
bool CRecord::hasTrivialAssign () const {
 
69
  // §12.8p11
 
70
  // A copy assignment operator for class X is trivial if it is implicitly declared and if:
 
71
  // — class X has no virtual functions (10.3) and no virtual base classes (10.1), and
 
72
  // — each direct base class of X has a trivial copy assignment operator, and
 
73
  // — for all the nonstatic data members of X that are of class type (or array thereof),
 
74
  //   each such class type has a trivial copy assignment operator.
 
75
  bool oper_found = false;
 
76
  unsigned i, num = Functions ();
 
77
  for (i = 0; i < num; i++) {
 
78
    CFunctionInfo* mf = Function (i);
 
79
    // virtual function
 
80
    if (mf->isVirtual ())
 
81
      return false;
 
82
    // implicit assignment operator
 
83
    if (! oper_found && mf->isBuiltin () && mf->isCopyAssignOperator ())
 
84
      oper_found = true;
 
85
  }
 
86
  // no implicit assignment operator found
 
87
  if (! oper_found)
 
88
    return false;
 
89
 
 
90
  // check if base classes have a trivial assignment operator and are not virtual
 
91
  CClassInfo* c = ClassInfo ();
 
92
  num = c ? c->BaseClasses () : 0;
 
93
  for (i = 0; i < num; i++) {
 
94
    CBaseClassInfo* bc = c->BaseClass (i);
 
95
    if (bc->isVirtual () || ! bc->Class ()->hasTrivialAssign ())
 
96
      return false;
 
97
  }
 
98
 
 
99
  // check non-static data members
 
100
  num = Attributes ();
 
101
  for (i = 0; i < num; i++) {
 
102
    CAttributeInfo* ai = Attribute (i);
 
103
    if (! ai->isStatic ()) {
 
104
      CTypeInfo* type = ai->TypeInfo ();
 
105
      // get underlying type of array
 
106
      while (type->isArray ())
 
107
        type = type->VirtualType ()->BaseType ();
 
108
      // check if data member has trivial assignment operator
 
109
      if (type->isClassOrUnion ()) {
 
110
        CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
 
111
        if (tr && tr->Record () && ! tr->Record ()->hasTrivialAssign ()) {
 
112
          // data member with non-trivial assignment operator found
 
113
          return false;
 
114
        }
 
115
      }
 
116
    }
 
117
  }
 
118
  return true;
 
119
}
 
120
 
 
121
/** Yields true if the class has a trivial copy constructor. */
 
122
bool CRecord::hasTrivialCopy () const {
 
123
  // §12.8p6
 
124
  // A copy constructor for class X is trivial if it is implicitly declared and if:
 
125
  // — class X has no virtual functions (10.3) and no virtual base classes (10.1), and
 
126
  // — each direct base class of X has a trivial copy constructor, and
 
127
  // — for all the non-static data members of X that are of class type (or array thereof),
 
128
  //   each such class type has trivial copy constructor.
 
129
  bool ctor_found = false;
 
130
  unsigned i, num = Functions ();
 
131
  for (i = 0; i < num; i++) {
 
132
    CFunctionInfo* mf = Function (i);
 
133
    // virtual function
 
134
    if (mf->isVirtual ())
 
135
      return false;
 
136
    // implicit copy constructor
 
137
    if (! ctor_found && mf->isBuiltin () && mf->isCopyConstructor ())
 
138
      ctor_found = true;
 
139
  }
 
140
  // no implicit default ctor found
 
141
  if (! ctor_found)
 
142
    return false;
 
143
 
 
144
  // check if base classes have a trivial copy constructor and are not virtual
 
145
  CClassInfo* c = ClassInfo ();
 
146
  num = c ? c->BaseClasses () : 0;
 
147
  for (i = 0; i < num; i++) {
 
148
    CBaseClassInfo* bc = c->BaseClass (i);
 
149
    if (bc->isVirtual () || ! bc->Class ()->hasTrivialCopy ())
 
150
      return false;
 
151
  }
 
152
 
 
153
  // check non-static data members
 
154
  num = Attributes ();
 
155
  for (i = 0; i < num; i++) {
 
156
    CAttributeInfo* ai = Attribute (i);
 
157
    if (! ai->isStatic ()) {
 
158
      CTypeInfo* type = ai->TypeInfo ();
 
159
      // get underlying type of array
 
160
      while (type->isArray ())
 
161
        type = type->VirtualType ()->BaseType ();
 
162
      // check if data member has trivial copy ctor
 
163
      if (type->isClassOrUnion ()) {
 
164
        CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
 
165
        if (tr && tr->Record () && ! tr->Record ()->hasTrivialCopy ()) {
 
166
          // data member with non-trivial copy constructor found
 
167
          return false;
 
168
        }
 
169
      }
 
170
    }
 
171
  }
 
172
  return true;
 
173
}
 
174
 
 
175
/** Yields true if the class has a trivial default constructor. */
 
176
bool CRecord::hasTrivialCtor () const {
 
177
  // §12.1p5
 
178
  // A constructor is trivial if it is an implicitly-declared default constructor and if:
 
179
  // — its class has no virtual functions (10.3) and no virtual base classes (10.1), and
 
180
  // — all the direct base classes of its class have trivial constructors, and
 
181
  // — for all the nonstatic data members of its class that are of class type (or array
 
182
  //   thereof), each such class has a trivial constructor.
 
183
  bool ctor_found = false;
 
184
  unsigned i, num = Functions ();
 
185
  for (i = 0; i < num; i++) {
 
186
    CFunctionInfo* mf = Function (i);
 
187
    // virtual function
 
188
    if (mf->isVirtual ())
 
189
      return false;
 
190
    // implicit default constructor
 
191
    if (! ctor_found && mf->isBuiltin () && mf->isDefaultConstructor ())
 
192
      ctor_found = true;
 
193
  }
 
194
  // no implicit default ctor found
 
195
  if (! ctor_found)
 
196
    return false;
 
197
 
 
198
  // check if base classes have a trivial constructor and are not virtual
 
199
  CClassInfo* c = ClassInfo ();
 
200
  num = c ? c->BaseClasses () : 0;
 
201
  for (i = 0; i < num; i++) {
 
202
    CBaseClassInfo* bc = c->BaseClass (i);
 
203
    if (bc->isVirtual () || ! bc->Class ()->hasTrivialCtor ())
 
204
      return false;
 
205
  }
 
206
 
 
207
  // check non-static data members
 
208
  num = Attributes ();
 
209
  for (i = 0; i < num; i++) {
 
210
    CAttributeInfo* ai = Attribute (i);
 
211
    if (! ai->isStatic ()) {
 
212
      CTypeInfo* type = ai->TypeInfo ();
 
213
      // get underlying type of array
 
214
      while (type->isArray ())
 
215
        type = type->VirtualType ()->BaseType ();
 
216
      // check if data member has trivial ctor
 
217
      if (type->isClassOrUnion ()) {
 
218
        CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
 
219
        if (tr && tr->Record () && ! tr->Record ()->hasTrivialCtor ()) {
 
220
          // data member with non-trivial constructor found
 
221
          return false;
 
222
        }
 
223
      }
 
224
    }
 
225
  }
 
226
  return true;
 
227
}
 
228
 
 
229
/** Yields true if the class has a trivial destructor. */
 
230
bool CRecord::hasTrivialDtor () const {
 
231
  // §12.4p3
 
232
  // A destructor is trivial if it is an implicitly-declared destructor and if:
 
233
  // — all of the direct base classes of its class have trivial destructors and
 
234
  // — for all of the non-static data members of its class that are of class type
 
235
  //   (or array thereof), each such class has a trivial destructor.
 
236
  unsigned i, num = Functions ();
 
237
  for (i = 0; i < num; i++) {
 
238
    CFunctionInfo* mf = Function (i);
 
239
    if (mf->isDestructor () && mf->isBuiltin ())
 
240
      break;
 
241
  }
 
242
  // no implicit destructor found
 
243
  if (i == num)
 
244
    return false;
 
245
 
 
246
  // check if base classes have a trivial destructor
 
247
  CClassInfo* c = ClassInfo ();
 
248
  num = c ? c->BaseClasses () : 0;
 
249
  for (i = 0; i < num; i++)
 
250
    if (! c->BaseClass (i)->Class ()->hasTrivialDtor ())
 
251
      return false;
 
252
 
 
253
  // check non-static data members
 
254
  num = Attributes ();
 
255
  for (i = 0; i < num; i++) {
 
256
    CAttributeInfo* ai = Attribute (i);
 
257
    if (! ai->isStatic ()) {
 
258
      CTypeInfo* type = ai->TypeInfo ();
 
259
      // get underlying type of array
 
260
      while (type->isArray ())
 
261
        type = type->VirtualType ()->BaseType ();
 
262
      // check if data member has trivial dtor
 
263
      if (type->isClassOrUnion ()) {
 
264
        CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
 
265
        if (tr && tr->Record () && ! tr->Record ()->hasTrivialDtor ()) {
 
266
          // data member with non-trivial destructor found
 
267
          return false;
 
268
        }
 
269
      }
 
270
    }
 
271
  }
 
272
  return true;
 
273
}
 
274
 
60
275
 
61
276
} // namespace Puma