lib/ClangImporter/ImportDecl.cpp
/// Checks if we don't need to import the typedef itself.  If the typedef
/// should be skipped, returns the underlying declaration that the typedef
/// refers to -- this declaration should be imported instead.
Checks if we don't need to import the typedef itself.  If the typedef
should be skipped, returns the underlying declaration that the typedef
refers to -- this declaration should be imported instead.
Checks if we don ' t need to import the typedef itself . If the typedef should be skipped returns the underlying declaration that the typedef refers to -- this declaration should be imported instead .
static const clang::TagDecl *
canSkipOverTypedef(ClangImporter::Implementation &Impl,
                   const clang::NamedDecl *D,
                   bool &TypedefIsSuperfluous) {
  TypedefIsSuperfluous = false;
  auto *ClangTypedef = dyn_cast<clang::TypedefNameDecl>(D);
  if (!ClangTypedef)
    return nullptr;
  const clang::DeclContext *RedeclContext =
      ClangTypedef->getDeclContext()->getRedeclContext();
  if (!RedeclContext->isTranslationUnit())
    return nullptr;
  clang::QualType UnderlyingType = ClangTypedef->getUnderlyingType();
  auto *TypedefT = UnderlyingType->getAs<clang::TypedefType>();
  if (TypedefT)
    return nullptr;
  auto *TT = UnderlyingType->getAs<clang::TagType>();
  if (!TT)
    return nullptr;
  clang::TagDecl *UnderlyingDecl = TT->getDecl();
  if (UnderlyingDecl->getDeclContext()->getRedeclContext() != RedeclContext)
    return nullptr;
  if (UnderlyingDecl->getDeclName().isEmpty())
    return UnderlyingDecl;
  auto TypedefName = ClangTypedef->getDeclName();
  auto TagDeclName = UnderlyingDecl->getDeclName();
  if (TypedefName != TagDeclName)
    return nullptr;
  TypedefIsSuperfluous = true;
  return UnderlyingDecl;
}
static const clang :: TagDecl * canSkipOverTypedef ( ClangImporter :: Implementation & Impl , const clang :: NamedDecl * D , bool & TypedefIsSuperfluous ) { TypedefIsSuperfluous = false ; auto * ClangTypedef = dyn_cast < clang :: TypedefNameDecl > ( D ) ; if ( ! ClangTypedef ) return nullptr ; const clang :: DeclContext * RedeclContext = ClangTypedef -> getDeclContext ( ) -> getRedeclContext ( ) ; if ( ! RedeclContext -> isTranslationUnit ( ) ) return nullptr ; clang :: QualType UnderlyingType = ClangTypedef -> getUnderlyingType ( ) ; auto * TypedefT = UnderlyingType -> getAs < clang :: TypedefType > ( ) ; if ( TypedefT ) return nullptr ; auto * TT = UnderlyingType -> getAs < clang :: TagType > ( ) ; if ( ! TT ) return nullptr ; clang :: TagDecl * UnderlyingDecl = TT -> getDecl ( ) ; if ( UnderlyingDecl -> getDeclContext ( ) -> getRedeclContext ( ) != RedeclContext ) return nullptr ; if ( UnderlyingDecl -> getDeclName ( ) . isEmpty ( ) ) return UnderlyingDecl ; auto TypedefName = ClangTypedef -> getDeclName ( ) ; auto TagDeclName = UnderlyingDecl -> getDeclName ( ) ; if ( TypedefName != TagDeclName ) return nullptr ; TypedefIsSuperfluous = true ; return UnderlyingDecl ; }
Checks if we don't need to import the typedef itself.
Checks if we don ' t need to import the typedef itself .
// If we have a typedef that refers to a tag type of the same name, // skip the typedef and import the tag type directly. // A typedef to a typedef should get imported as a typealias.