From: Steve Naroff Date: Tue, 23 Sep 2008 21:15:53 +0000 (+0000) Subject: RewriteBlocks::RewriteBlockPointerDecl(): Handle TypedefDecl's and VarDecl's uniformly. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca3bb4f14fcfb606d9c9d6c574bb76131f952ed4;p=clang RewriteBlocks::RewriteBlockPointerDecl(): Handle TypedefDecl's and VarDecl's uniformly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56500 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp index b61e9a2241..b9e2217db2 100644 --- a/Driver/RewriteBlocks.cpp +++ b/Driver/RewriteBlocks.cpp @@ -847,47 +847,44 @@ void RewriteBlocks::GetExtentOfArgList(const char *Name, } void RewriteBlocks::RewriteBlockPointerDecl(NamedDecl *ND) { - SourceLocation DeclLoc = ND->getLocation(); - const char *startBuf, *endBuf; - if (FunctionDecl *FD = dyn_cast(ND)) { RewriteBlockPointerFunctionArgs(FD); return; - } else if (VarDecl *VD = dyn_cast(ND)) { - DeclLoc = VD->getLocation(); - startBuf = SM->getCharacterData(DeclLoc); - endBuf = startBuf; - // scan backward (from the decl location) for the end of the previous decl. - while (*startBuf != '^' && *startBuf != ';' && startBuf != MainFileStart) - startBuf--; - assert((*startBuf == '^') && - "RewriteBlockPointerDecl() scan error: no caret"); - // Replace the '^' with '*', computing a negative offset. - DeclLoc = DeclLoc.getFileLocWithOffset(startBuf-endBuf); - ReplaceText(DeclLoc, 1, "*", 1); + } + // Handle Variables and Typedefs. + SourceLocation DeclLoc = ND->getLocation(); + QualType DeclT; + if (VarDecl *VD = dyn_cast(ND)) + DeclT = VD->getType(); + else if (TypedefDecl *TDD = dyn_cast(ND)) + DeclT = TDD->getUnderlyingType(); + else + assert(0 && "RewriteBlockPointerDecl(): Decl type not yet handled"); - if (BlockPointerTypeTakesAnyBlockArguments(VD->getType())) { - // Replace the '^' with '*' for arguments. - DeclLoc = VD->getLocation(); - startBuf = SM->getCharacterData(DeclLoc); - char *argListBegin, *argListEnd; - GetExtentOfArgList(startBuf, argListBegin, argListEnd); - while (argListBegin < argListEnd) { - if (*argListBegin == '^') { - SourceLocation CaretLoc = DeclLoc.getFileLocWithOffset(argListBegin-startBuf); - ReplaceText(CaretLoc, 1, "*", 1); - } - argListBegin++; - } - } - } else if (TypedefDecl *TDD = dyn_cast(ND)) { - DeclLoc = TDD->getLocation(); + const char *startBuf = SM->getCharacterData(DeclLoc); + const char *endBuf = startBuf; + // scan backward (from the decl location) for the end of the previous decl. + while (*startBuf != '^' && *startBuf != ';' && startBuf != MainFileStart) + startBuf--; + assert((*startBuf == '^') && + "RewriteBlockPointerDecl() scan error: no caret"); + // Replace the '^' with '*', computing a negative offset. + DeclLoc = DeclLoc.getFileLocWithOffset(startBuf-endBuf); + ReplaceText(DeclLoc, 1, "*", 1); + + if (BlockPointerTypeTakesAnyBlockArguments(DeclT)) { + // Replace the '^' with '*' for arguments. + DeclLoc = ND->getLocation(); startBuf = SM->getCharacterData(DeclLoc); - if (!strncmp("typedef ", startBuf, 8)) { - startBuf += 8; // skip the typedef... - DeclLoc = DeclLoc.getFileLocWithOffset(8); + char *argListBegin, *argListEnd; + GetExtentOfArgList(startBuf, argListBegin, argListEnd); + while (argListBegin < argListEnd) { + if (*argListBegin == '^') { + SourceLocation CaretLoc = DeclLoc.getFileLocWithOffset(argListBegin-startBuf); + ReplaceText(CaretLoc, 1, "*", 1); + } + argListBegin++; } - endBuf = startBuf; } return; }