summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-11-20 16:26:53 +0100
committerLuboš Luňák <l.lunak@suse.cz>2012-11-20 16:30:02 +0100
commit1ed9af9a4419b50a76eea56eb2e4c684e616673b (patch)
tree1a223c88d69d6441cf66e83262f47f1569dd0442 /compilerplugins
parent13cca3de54265b884fc80a10450096c7e1061b36 (diff)
skip 'else' from a macro expansion too
Change-Id: I1a6d70d1554dc5bf8f46940ed62b47ab34983aa7
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/bodynotinblock.cxx17
-rw-r--r--compilerplugins/clang/bodynotinblock.hxx3
2 files changed, 11 insertions, 9 deletions
diff --git a/compilerplugins/clang/bodynotinblock.cxx b/compilerplugins/clang/bodynotinblock.cxx
index b6572bfc8a7a..90f79334db00 100644
--- a/compilerplugins/clang/bodynotinblock.cxx
+++ b/compilerplugins/clang/bodynotinblock.cxx
@@ -56,15 +56,15 @@ void BodyNotInBlock::traverseStatement( const Stmt* stmt, StmtParents& parents )
parents.push_back( *it );
if( const IfStmt* ifstmt = dyn_cast< IfStmt >( *it ))
{
- checkBody( ifstmt->getThen(), parents, 0, ifstmt->getElse() != NULL );
- checkBody( ifstmt->getElse(), parents, 0 );
+ checkBody( ifstmt->getThen(), ifstmt->getIfLoc(), parents, 0, ifstmt->getElse() != NULL );
+ checkBody( ifstmt->getElse(), ifstmt->getElseLoc(), parents, 0 );
}
else if( const WhileStmt* whilestmt = dyn_cast< WhileStmt >( *it ))
- checkBody( whilestmt->getBody(), parents, 1 );
+ checkBody( whilestmt->getBody(), whilestmt->getWhileLoc(), parents, 1 );
else if( const ForStmt* forstmt = dyn_cast< ForStmt >( *it ))
- checkBody( forstmt->getBody(), parents, 2 );
+ checkBody( forstmt->getBody(), forstmt->getForLoc(), parents, 2 );
else if( const CXXForRangeStmt* forstmt = dyn_cast< CXXForRangeStmt >( *it ))
- checkBody( forstmt->getBody(), parents, 2 );
+ checkBody( forstmt->getBody(), forstmt->getForLoc(), parents, 2 );
parents.pop_back();
}
}
@@ -72,16 +72,17 @@ void BodyNotInBlock::traverseStatement( const Stmt* stmt, StmtParents& parents )
parents.pop_back();
}
-void BodyNotInBlock::checkBody( const Stmt* body, const StmtParents& parents, int stmtType, bool dontGoUp )
+void BodyNotInBlock::checkBody( const Stmt* body, SourceLocation stmtLocation, const StmtParents& parents,
+ int stmtType, bool dontGoUp )
{
if( body == NULL || parents.size() < 2 )
return;
- // TODO: If the if/while/for comes from a macro expansion, ignore it completely for
+ // TODO: If the if/else/while/for comes from a macro expansion, ignore it completely for
// now. The code below could assume everything is in the same place (and thus also column)
// and give a false warning. Moreover some macros are rather lousily written and would
// result in poor formatting. To be evaluated later, maybe this could be handled
// including macro expansion.
- if( parents.back()->getLocStart().isMacroID())
+ if( stmtLocation.isMacroID())
return;
if( dyn_cast< CompoundStmt >( body ))
return; // if body is a compound statement, then it is in {}
diff --git a/compilerplugins/clang/bodynotinblock.hxx b/compilerplugins/clang/bodynotinblock.hxx
index 304bbf0a0480..3cfc9bafc8d5 100644
--- a/compilerplugins/clang/bodynotinblock.hxx
+++ b/compilerplugins/clang/bodynotinblock.hxx
@@ -27,7 +27,8 @@ class BodyNotInBlock
private:
typedef vector< const Stmt* > StmtParents;
void traverseStatement( const Stmt* stmt, StmtParents& parents );
- void checkBody( const Stmt* body, const StmtParents& parents, int stmtType, bool dontGoUp = false );
+ void checkBody( const Stmt* body, SourceLocation stmtLocation, const StmtParents& parents,
+ int stmtType, bool dontGoUp = false );
};
} // namespace