clang/lib/Sema/SemaDeclAttr.cpp
NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
                                      SourceLocation Loc) {
  assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
  NamedDecl *NewD = nullptr;
  if (auto *FD = dyn_cast<FunctionDecl>(ND)) {
    FunctionDecl *NewFD;
    // FIXME: Missing call to CheckFunctionDeclaration().
    // FIXME: Mangling?
    // FIXME: Is the qualifier info correct?
    // FIXME: Is the DeclContext correct?
    NewFD = FunctionDecl::Create(
        FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
        DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
        false /*isInlineSpecified*/, FD->hasPrototype(),
        ConstexprSpecKind::Unspecified, FD->getTrailingRequiresClause());
    NewD = NewFD;

    if (FD->getQualifier())
      NewFD->setQualifierInfo(FD->getQualifierLoc());

    // Fake up parameter variables; they are declared as if this were
    // a typedef.
    QualType FDTy = FD->getType();
    if (const auto *FT = FDTy->getAs<FunctionProtoType>()) {
      SmallVector<ParmVarDecl*, 16> Params;
      for (const auto &AI : FT->param_types()) {
        ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
        Param->setScopeInfo(0, Params.size());
        Params.push_back(Param);
      }
      NewFD->setParams(Params);
    }
  } else if (auto *VD = dyn_cast<VarDecl>(ND)) {
    NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(),
                           VD->getInnerLocStart(), VD->getLocation(), II,
                           VD->getType(), VD->getTypeSourceInfo(),
                           VD->getStorageClass());
    if (VD->getQualifier())
      cast<VarDecl>(NewD)->setQualifierInfo(VD->getQualifierLoc());
  }
  return NewD;
}
/// DeclClonePragmaWeak - clone existing decl (maybe definition),
/// \#pragma weak needs a non-definition decl and source may not have one.
clone existing decl (maybe definition),
\#pragma weak needs a non-definition decl and source may not have one.
clone existing decl ( maybe definition ) \ #pragma weak needs a non - definition decl and source may not have one .
NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
                                      SourceLocation Loc) {
  assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
  NamedDecl *NewD = nullptr;
  if (auto *FD = dyn_cast<FunctionDecl>(ND)) {
    FunctionDecl *NewFD;
    NewFD = FunctionDecl::Create(
        FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
        DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
        false , FD->hasPrototype(),
        ConstexprSpecKind::Unspecified, FD->getTrailingRequiresClause());
    NewD = NewFD;
    if (FD->getQualifier())
      NewFD->setQualifierInfo(FD->getQualifierLoc());
    QualType FDTy = FD->getType();
    if (const auto *FT = FDTy->getAs<FunctionProtoType>()) {
      SmallVector<ParmVarDecl*, 16> Params;
      for (const auto &AI : FT->param_types()) {
        ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
        Param->setScopeInfo(0, Params.size());
        Params.push_back(Param);
      }
      NewFD->setParams(Params);
    }
  } else if (auto *VD = dyn_cast<VarDecl>(ND)) {
    NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(),
                           VD->getInnerLocStart(), VD->getLocation(), II,
                           VD->getType(), VD->getTypeSourceInfo(),
                           VD->getStorageClass());
    if (VD->getQualifier())
      cast<VarDecl>(NewD)->setQualifierInfo(VD->getQualifierLoc());
  }
  return NewD;
}
NamedDecl * Sema :: DeclClonePragmaWeak ( NamedDecl * ND , IdentifierInfo * II , SourceLocation Loc ) { assert ( isa < FunctionDecl > ( ND ) || isa < VarDecl > ( ND ) ) ; NamedDecl * NewD = nullptr ; if ( auto * FD = dyn_cast < FunctionDecl > ( ND ) ) { FunctionDecl * NewFD ; NewFD = FunctionDecl :: Create ( FD -> getASTContext ( ) , FD -> getDeclContext ( ) , Loc , Loc , DeclarationName ( II ) , FD -> getType ( ) , FD -> getTypeSourceInfo ( ) , SC_None , false , FD -> hasPrototype ( ) , ConstexprSpecKind :: Unspecified , FD -> getTrailingRequiresClause ( ) ) ; NewD = NewFD ; if ( FD -> getQualifier ( ) ) NewFD -> setQualifierInfo ( FD -> getQualifierLoc ( ) ) ; QualType FDTy = FD -> getType ( ) ; if ( const auto * FT = FDTy -> getAs < FunctionProtoType > ( ) ) { SmallVector < ParmVarDecl * , 16 > Params ; for ( const auto & AI : FT -> param_types ( ) ) { ParmVarDecl * Param = BuildParmVarDeclForTypedef ( NewFD , Loc , AI ) ; Param -> setScopeInfo ( 0 , Params . size ( ) ) ; Params . push_back ( Param ) ; } NewFD -> setParams ( Params ) ; } } else if ( auto * VD = dyn_cast < VarDecl > ( ND ) ) { NewD = VarDecl :: Create ( VD -> getASTContext ( ) , VD -> getDeclContext ( ) , VD -> getInnerLocStart ( ) , VD -> getLocation ( ) , II , VD -> getType ( ) , VD -> getTypeSourceInfo ( ) , VD -> getStorageClass ( ) ) ; if ( VD -> getQualifier ( ) ) cast < VarDecl > ( NewD ) -> setQualifierInfo ( VD -> getQualifierLoc ( ) ) ; } return NewD ; }
DeclClonePragmaWeak - clone existing decl (maybe definition),
\#pragma weak needs a non-definition decl and source may not have one.
DeclClonePragmaWeak - clone existing decl ( maybe definition ) \ #pragma weak needs a non - definition decl and source may not have one .
// FIXME: Missing call to CheckFunctionDeclaration(). // FIXME: Mangling? // FIXME: Is the qualifier info correct? // FIXME: Is the DeclContext correct? /*isInlineSpecified*/ // Fake up parameter variables; they are declared as if this were // a typedef.