@@ -560,21 +560,20 @@ namespace utils {
560560 } else {
561561
562562 Decl* decl = nullptr ;
563- const TypedefType* typedeftype =
564- dyn_cast_or_null<TypedefType>(&(*desugared));
565- const UsingType* usingtype =
566- dyn_cast_or_null<UsingType>(&(*desugared));
567- if (typedeftype) {
568- decl = typedeftype->getDecl ();
569- } else if (usingtype) {
570- decl = usingtype->getFoundDecl ();
571- } else {
572- // There are probably other cases ...
573- const TagType* tagdecltype = dyn_cast_or_null<TagType>(&(*desugared));
574- if (tagdecltype) {
575- decl = tagdecltype->getDecl ();
576- } else {
577- decl = desugared->getAsCXXRecordDecl ();
563+ if (!desugared.isNull ()) {
564+ const Type* desugaredTy = desugared.getTypePtr ();
565+ switch (desugaredTy->getTypeClass ()) {
566+ case Type::Typedef:
567+ decl = cast<TypedefType>(desugaredTy)->getDecl ();
568+ break ;
569+ case Type::Using:
570+ decl = cast<UsingType>(desugaredTy)->getFoundDecl ();
571+ break ;
572+ case Type::Record:
573+ case Type::Enum:
574+ decl = cast<TagType>(desugaredTy)->getDecl ();
575+ break ;
576+ default : decl = desugared->getAsCXXRecordDecl (); break ;
578577 }
579578 }
580579 if (decl) {
@@ -1142,22 +1141,15 @@ namespace utils {
11421141 // in which case we want to add it ... but we can't really preserve
11431142 // the typedef in this case ...
11441143
1145- Decl *decl = nullptr ;
1146- const TypedefType* typedeftype =
1147- dyn_cast_or_null<TypedefType>(QT .getTypePtr ());
1148- const UsingType* usingtype =
1149- dyn_cast_or_null<UsingType>(QT .getTypePtr ());
1150- if (typedeftype) {
1151- decl = typedeftype->getDecl ();
1152- } else if (usingtype) {
1153- decl = usingtype->getFoundDecl ();
1154- } else {
1155- // There are probably other cases ...
1156- const TagType* tagdecltype = dyn_cast_or_null<TagType>(QT .getTypePtr ());
1157- if (tagdecltype) {
1158- decl = tagdecltype->getDecl ();
1159- } else {
1160- decl = QT ->getAsCXXRecordDecl ();
1144+ Decl* decl = nullptr ;
1145+ if (!QT .isNull ()) {
1146+ const Type* QTTy = QT .getTypePtr ();
1147+ switch (QTTy->getTypeClass ()) {
1148+ case Type::Typedef: decl = cast<TypedefType>(QTTy)->getDecl (); break ;
1149+ case Type::Using: decl = cast<UsingType>(QTTy)->getFoundDecl (); break ;
1150+ case Type::Record:
1151+ case Type::Enum: decl = cast<TagType>(QTTy)->getDecl (); break ;
1152+ default : decl = QT ->getAsCXXRecordDecl (); break ;
11611153 }
11621154 }
11631155 if (decl) {
0 commit comments