78
80
CTypeInfo *CTypeInfo::CTYPE_SIZE_T = &CTYPE_UNSIGNED_INT; // default type
79
81
CTypeInfo *CTypeInfo::CTYPE_PTRDIFF_T = &CTYPE_INT; // default type
81
bool CTypeInfo::equalTemplateParams (CTemplateParamInfo *p1, CTemplateParamInfo *p2) const {
82
if (p1->isTemplate () != p2->isTemplate ())
84
if (p1->isTypeParam () != p2->isTypeParam ())
86
if (p1->ValueType () && p2->ValueType () && *p1->ValueType () != *p2->ValueType ())
89
if (p1->isTemplate ()) {
90
CTemplateInfo *t1 = p1->TemplateTemplate ();
91
CTemplateInfo *t2 = p1->TemplateTemplate ();
92
if (! t1 || ! t2 || (t1->Parameters () != t2->Parameters ()))
94
for (unsigned i = 0; i < t1->Parameters (); i++) {
95
p1 = t1->Parameter (i);
96
p2 = t2->Parameter (i);
97
if (*p1->TypeInfo () != *p2->TypeInfo ())
104
83
bool CTypeInfo::operator ==(const CTypeInfo &type) const {
105
84
if (! (_Id == type._Id)) {
198
// check if a typedef is defined in a generated template argument scope
199
bool isInTemplateArgScope (CObjectInfo *obj) {
200
bool result = (obj->Scope ()->isNamespace () &&
201
((obj->Scope ()->isAnonymous () && strstr (obj->Scope ()->Name (), "<")) ||
202
strstr (obj->Scope ()->Name (), "__puma_")));
177
bool CTypeInfo::isTemplateInstanceArg () const {
180
CScopeInfo* scope = _TypedefInfo->Scope ();
181
if (strcmp (_TypedefInfo->Name (), "__puma_redirect") == 0)
182
scope = scope->Parent ();
183
if (scope->isNamespace () && scope->isAnonymous () && strstr (scope->Name (), "<"))
206
189
void CTypeInfo::TypeText (char state, ostream &out, const char *t) const {
207
// check for prefix, safe, and clear the flag
190
// check for prefix, save and clear the flag
208
191
bool prefix = state & PRINT_PRE;
209
192
state = state & ~PRINT_PRE;
211
if (isTypedef () && !isInTemplateArgScope (TypedefInfo ()) &&
194
if (isTypedef () && ! isTemplateInstanceArg () &&
212
195
((state & PRINT_TDN) ||
213
196
(TypeEnum () && EnumInfo ()->isAnonymous ()) ||
214
197
(TypeRecord () && Record ()->isAnonymous ()))) {
318
302
printName (state, out, TypeClass ()->Record ());
319
303
} else if (TypeUnion ()) {
321
if (state & PRINT_ELA) {
305
if ((state & PRINT_ELA) && !(state & PRINT_INE)) {
324
308
printScope (state, out, TypeUnion ()->Record ());
325
309
printName (state, out, TypeUnion ()->Record ());
326
310
} else if (TypeEnum ()) {
328
if (state & PRINT_ELA) {
312
if ((state & PRINT_ELA) && !(state & PRINT_INE)) {
331
315
printScope (state, out, TypeEnum ()->EnumInfo ());
772
756
if (isTemplateInstance ()) {
773
757
if ((TypeRecord () &&
774
TypeRecord ()->Record ()->TemplateInstance ()->isPseudoInstance ()) ||
758
! TypeRecord ()->Record ()->TemplateInstance ()->canInstantiate ()) ||
775
759
(TypeFunction () &&
776
TypeFunction ()->FunctionInfo ()->TemplateInstance ()->isPseudoInstance ()))
779
// HACK? Needed for template template parameters
783
TypeClass ()->ClassInfo () &&
784
TypeClass ()->ClassInfo ()->hasDepBaseClass () &&
785
! TypeClass ()->ClassInfo ()->isTemplate ())
760
! TypeFunction ()->FunctionInfo ()->TemplateInstance ()->canInstantiate ()))
763
if (TypeClass () && TypeClass ()->ClassInfo ()) {
764
CClassInfo* ci = TypeClass ()->ClassInfo ();
765
if (! ci->isTemplate () && ci->hasDepBaseClass ())
767
if (! is_named_type && ci->isTemplate () && ci->hasDepBaseClass ())
787
770
return BaseType () && this != BaseType () &&
788
BaseType ()->isDependent (consider_unknown_t);
771
BaseType ()->isDependent (consider_unknown_t, is_named_type);
791
774
bool CTypeList::isDependent () const {
968
949
return _Enum ? _Enum->UnderlyingType() : &CTYPE_INT;
952
bool CTypeClass::instantiate (CStructure *scope) {
953
// If this is the type of a pseudo class instance,
954
// create a real instance of the corresponding template.
955
// Return true if instantiation succeeded.
956
CClassInfo* ci = ClassInfo ();
958
CTemplateInstance* ti = ci->TemplateInstance ();
959
if (ti && ! ti->isInstantiated () && ti->canInstantiate ()) {
961
return ti->instantiate (scope);
967
/** Check if this is a plain old data (POD) type. */
968
bool CTypeInfo::isPOD () const {
970
// Arithmetic types (3.9.1), enumeration types, pointer types, and pointer
971
// to member types (3.9.2), and cv-qualified versions of these types (3.9.3) are
972
// collectively called scalar types. Scalar types, POD-struct types, POD-union
973
// types (clause 9), arrays of such types and cv-qualified versions of these
974
// types (3.9.3) are collectively called POD types.
979
// A POD-struct is an aggregate class that has no non-static data members of
980
// type pointer to member, non-POD-struct, non-POD-union, or array of such types,
981
// or reference, and has no user-defined copy assignment operator and no user-defined
982
// destructor. Similarly, a POD-union is an aggregate union that has no non-static
983
// data members of type pointer to member, non-POD-struct, non-POD-union, or array
984
// of such types, or reference, and has no user-defined copy assignment operator
985
// and no user-defined destructor. A POD class is a class that is either a POD-struct
989
// An aggregate is an array or a class (clause 9) with no user-declared constructors
990
// (12.1), no private or protected non-static data members (clause 11), no base
991
// classes (clause 10), and no virtual functions (10.3).
992
CRecord* c = isClassOrUnion () ? VirtualType ()->TypeRecord ()->Record () : 0;
994
// class or union without base classes
995
if (c && (! c->ClassInfo () || ! c->ClassInfo ()->BaseClasses ())) {
997
// check data members
998
unsigned i, num = c->Attributes ();
999
for (i = 0; i < num; i++) {
1000
CAttributeInfo* member = c->Attribute (i);
1001
// private or protected data member
1002
if (member->Protection () == CProtection::PROT_PRIVATE ||
1003
member->Protection () == CProtection::PROT_PROTECTED)
1005
// static members don't matter
1006
if (! member->isStatic ()) {
1007
CTypeInfo* type = member->TypeInfo ();
1009
if (type->isAddress ())
1011
// get underlying type of array
1012
while (type->isArray ())
1013
type = type->VirtualType ()->BaseType ();
1014
// pointer to member
1015
if (type->isMemberPointer ())
1018
if (type->isClassOrUnion () && ! type->isPOD ())
1022
// non-POD member found
1026
// check member functions
1027
num = c->Functions ();
1028
for (i = 0; i < num; i++) {
1029
CFunctionInfo* member = c->Function (i);
1031
if (member->isVirtual ())
1034
if (! member->isBuiltin ()) {
1035
// user-defined constructor or destructor
1036
if (member->isConstructor () || member->isDestructor ())
1038
// copy assignment operator
1039
if (member->isCopyAssignOperator ())
1052
long int CTypeInfo::Align () const {
1053
// TODO: Calculation of alignment not yet implemented
1054
// except for class and union types.
972
1059
} // namespace Puma