git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121795 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Abramo Bagnara 2010-12-14 22:11:44 +00:00
Родитель 8786da7798
Коммит 723df24530
14 изменённых файлов: 47 добавлений и 32 удалений

Просмотреть файл

@ -694,7 +694,9 @@ public:
/// IgnoreParens - Returns the specified type after dropping any
/// outer-level parentheses.
QualType IgnoreParens() const {
return QualType::IgnoreParens(*this);
if (isa<ParenType>(*this))
return QualType::IgnoreParens(*this);
return *this;
}
/// operator==/!= - Indicate whether the specified types and qualifiers are

Просмотреть файл

@ -115,7 +115,11 @@ public:
/// \brief Skips past any qualifiers, if this is qualified.
UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
TypeLoc IgnoreParens() const;
TypeLoc IgnoreParens() const {
if (isa<ParenTypeLoc>(this))
return IgnoreParensImpl(*this);
return *this;
}
/// \brief Initializes this to state that every location in this
/// type is the given location.
@ -146,6 +150,7 @@ private:
static void initializeImpl(TypeLoc TL, SourceLocation Loc);
static void initializeFullCopyImpl(TypeLoc TL, TypeLoc Other);
static TypeLoc getNextTypeLocImpl(TypeLoc TL);
static TypeLoc IgnoreParensImpl(TypeLoc TL);
static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
};

Просмотреть файл

@ -366,9 +366,15 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
PrintingPolicy SubPolicy(Policy);
SubPolicy.SuppressSpecifiers = false;
std::string Proto = D->getNameInfo().getAsString();
if (isa<FunctionType>(D->getType().getTypePtr())) {
const FunctionType *AFT = D->getType()->getAs<FunctionType>();
QualType Ty = D->getType();
while (ParenType* PT = dyn_cast<ParenType>(Ty)) {
Proto = '(' + Proto + ')';
Ty = PT->getInnerType();
}
if (isa<FunctionType>(Ty)) {
const FunctionType *AFT = Ty->getAs<FunctionType>();
const FunctionProtoType *FT = 0;
if (D->hasWrittenPrototype())
FT = dyn_cast<FunctionProtoType>(AFT);
@ -487,7 +493,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
else
AFT->getResultType().getAsStringInternal(Proto, Policy);
} else {
D->getType().getAsStringInternal(Proto, Policy);
Ty.getAsStringInternal(Proto, Policy);
}
Out << Proto;

Просмотреть файл

@ -230,8 +230,7 @@ TypeSpecifierType BuiltinTypeLoc::getWrittenTypeSpec() const {
return TST_unspecified;
}
TypeLoc TypeLoc::IgnoreParens() const {
TypeLoc TL = *this;
TypeLoc TypeLoc::IgnoreParensImpl(TypeLoc TL) {
while (ParenTypeLoc* PTL = dyn_cast<ParenTypeLoc>(&TL))
TL = PTL->getInnerLoc();
return TL;

Просмотреть файл

@ -242,7 +242,8 @@ void WalkAST::CheckCall_gets(const CallExpr *CE, const FunctionDecl *FD) {
if (FD->getIdentifier() != GetIdentifier(II_gets, "gets"))
return;
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FPT
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FPT)
return;
@ -276,7 +277,8 @@ void WalkAST::CheckCall_getpw(const CallExpr *CE, const FunctionDecl *FD) {
if (FD->getIdentifier() != GetIdentifier(II_getpw, "getpw"))
return;
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FPT
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FPT)
return;
@ -314,7 +316,8 @@ void WalkAST::CheckCall_mktemp(const CallExpr *CE, const FunctionDecl *FD) {
if (FD->getIdentifier() != GetIdentifier(II_mktemp, "mktemp"))
return;
const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FPT
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if(!FPT)
return;
@ -369,7 +372,8 @@ void WalkAST::CheckCall_rand(const CallExpr *CE, const FunctionDecl *FD) {
if (identifierid >= num_rands)
return;
const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FTP
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;
@ -410,7 +414,8 @@ void WalkAST::CheckCall_random(const CallExpr *CE, const FunctionDecl *FD) {
if (FD->getIdentifier() != GetIdentifier(II_random, "random"))
return;
const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FTP
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;
@ -457,7 +462,8 @@ void WalkAST::CheckUncheckedReturnValue(CallExpr *CE) {
if (identifierid >= num_setids)
return;
const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(FD->getType());
const FunctionProtoType *FTP
= dyn_cast<FunctionProtoType>(FD->getType().IgnoreParens());
if (!FTP)
return;

Просмотреть файл

@ -472,7 +472,8 @@ namespace {
void RewriteObjC::RewriteBlocksInFunctionProtoType(QualType funcType,
NamedDecl *D) {
if (FunctionProtoType *fproto = dyn_cast<FunctionProtoType>(funcType)) {
if (FunctionProtoType *fproto
= dyn_cast<FunctionProtoType>(funcType.IgnoreParens())) {
for (FunctionProtoType::arg_type_iterator I = fproto->arg_type_begin(),
E = fproto->arg_type_end(); I && (I != E); ++I)
if (isTopLevelBlockPointerType(*I)) {

Просмотреть файл

@ -1918,10 +1918,7 @@ static std::string FormatFunctionParameter(ASTContext &Context,
// then we're done.
if (BlockPointerTypeLoc *BlockPtr
= dyn_cast<BlockPointerTypeLoc>(&TL)) {
TL = BlockPtr->getPointeeLoc();
// Skip any paren typeloc.
while (ParenTypeLoc *ParenPtr = dyn_cast<ParenTypeLoc>(&TL))
TL = ParenPtr->getInnerLoc();
TL = BlockPtr->getPointeeLoc().IgnoreParens();
Block = dyn_cast<FunctionProtoTypeLoc>(&TL);
}
break;

Просмотреть файл

@ -3761,7 +3761,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
// Copy the parameter declarations from the declarator D to the function
// declaration NewFD, if they are available. First scavenge them into Params.
llvm::SmallVector<ParmVarDecl*, 16> Params;
if (D.getNumTypeObjects() > 0) {
if (D.isFunctionDeclarator()) {
DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo();
// Check for C99 6.7.5.3p10 - foo(void) is a non-varargs
@ -4283,7 +4283,7 @@ void Sema::CheckMain(FunctionDecl* FD) {
if (!Context.hasSameUnqualifiedType(FT->getResultType(), Context.IntTy)) {
TypeSourceInfo *TSI = FD->getTypeSourceInfo();
TypeLoc TL = TSI->getTypeLoc();
TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
const SemaDiagnosticBuilder& D = Diag(FD->getTypeSpecStartLoc(),
diag::err_main_returns_nonint);
if (FunctionTypeLoc* PTL = dyn_cast<FunctionTypeLoc>(&TL)) {

Просмотреть файл

@ -2170,7 +2170,7 @@ static void HandleGlobalAttr(Decl *d, const AttributeList &Attr, Sema &S) {
FunctionDecl *FD = cast<FunctionDecl>(d);
if (!FD->getResultType()->isVoidType()) {
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc().IgnoreParens();
if (FunctionTypeLoc* FTL = dyn_cast<FunctionTypeLoc>(&TL)) {
S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
<< FD->getType()

Просмотреть файл

@ -81,7 +81,6 @@ bool Sema::CheckSpecifiedExceptionType(QualType T, const SourceRange &Range) {
/// to member to a function with an exception specification. This means that
/// it is invalid to add another level of indirection.
bool Sema::CheckDistantExceptionSpec(QualType T) {
T = T.IgnoreParens();
if (const PointerType *PT = T->getAs<PointerType>())
T = PT->getPointeeType();
else if (const MemberPointerType *PT = T->getAs<MemberPointerType>())
@ -89,7 +88,6 @@ bool Sema::CheckDistantExceptionSpec(QualType T) {
else
return false;
T = T.IgnoreParens();
const FunctionProtoType *FnT = T->getAs<FunctionProtoType>();
if (!FnT)
return false;
@ -198,7 +196,7 @@ bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
SourceLocation AfterParenLoc;
if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) {
TypeLoc TL = TSInfo->getTypeLoc();
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
if (const FunctionTypeLoc *FTLoc = dyn_cast<FunctionTypeLoc>(&TL))
AfterParenLoc = PP.getLocForEndOfToken(FTLoc->getRParenLoc());
}

Просмотреть файл

@ -8240,8 +8240,9 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
// Push block parameters from the declarator if we had them.
llvm::SmallVector<ParmVarDecl*, 8> Params;
if (isa<FunctionProtoType>(T)) {
FunctionProtoTypeLoc TL = cast<FunctionProtoTypeLoc>(Sig->getTypeLoc());
if (isa<FunctionProtoType>(T.IgnoreParens())) {
FunctionProtoTypeLoc TL
= cast<FunctionProtoTypeLoc>(Sig->getTypeLoc().IgnoreParens());
for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) {
ParmVarDecl *Param = TL.getArg(I);
if (Param->getIdentifier() == 0 &&

Просмотреть файл

@ -990,7 +990,7 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
if (T->getType()->isDependentType() || T->getType()->isVariablyModifiedType())
return true;
TypeLoc TL = T->getTypeLoc();
TypeLoc TL = T->getTypeLoc().IgnoreParens();
if (!isa<FunctionProtoTypeLoc>(TL))
return false;

Просмотреть файл

@ -1264,16 +1264,16 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
return 0;
QualType T = TInfo->getType();
// \brief If the type of this function is not *directly* a function
// type, then we're instantiating the a function that was declared
// via a typedef, e.g.,
// \brief If the type of this function, after ignoring parentheses,
// is not *directly* a function type, then we're instantiating a function
// that was declared via a typedef, e.g.,
//
// typedef int functype(int, int);
// functype func;
//
// In this case, we'll just go instantiate the ParmVarDecls that we
// synthesized in the method declaration.
if (!isa<FunctionProtoType>(T)) {
if (!isa<FunctionProtoType>(T.IgnoreParens())) {
assert(!Params.size() && "Instantiating type could not yield parameters");
for (unsigned I = 0, N = D->getNumParams(); I != N; ++I) {
ParmVarDecl *P = SemaRef.SubstParmVarDecl(D->getParamDecl(I),

Просмотреть файл

@ -693,7 +693,7 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
// Visit the function declaration's syntactic components in the order
// written. This requires a bit of work.
TypeLoc TL = TSInfo->getTypeLoc();
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL);
// If we have a function declared directly (without the use of a typedef),