Commit ae0738b4 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Format

parent 85ef47bf
...@@ -74,7 +74,7 @@ static void dump(DeclContext* ctx) { ...@@ -74,7 +74,7 @@ static void dump(DeclContext* ctx) {
class RefcheckingVisitor : public RecursiveASTVisitor<RefcheckingVisitor> { class RefcheckingVisitor : public RecursiveASTVisitor<RefcheckingVisitor> {
private: private:
ASTContext *Context; ASTContext* Context;
enum RefType { enum RefType {
UNKNOWN, UNKNOWN,
...@@ -118,7 +118,7 @@ private: ...@@ -118,7 +118,7 @@ private:
} }
BlockState() {} BlockState() {}
BlockState(const BlockState &rhs) { BlockState(const BlockState& rhs) {
states = rhs.states; states = rhs.states;
for (auto&& p : rhs.vars) { for (auto&& p : rhs.vars) {
auto it = states.begin(); auto it = states.begin();
...@@ -167,7 +167,7 @@ private: ...@@ -167,7 +167,7 @@ private:
} }
} }
for (auto&& bstate : {state1, state2}) { for (auto&& bstate : { state1, state2 }) {
for (auto&& state : state1.states) { for (auto&& state : state1.states) {
if (state.num_refs == 0) if (state.num_refs == 0)
continue; continue;
...@@ -358,8 +358,7 @@ private: ...@@ -358,8 +358,7 @@ private:
if (auto dostmt = dyn_cast<DoStmt>(stmt)) { if (auto dostmt = dyn_cast<DoStmt>(stmt)) {
Expr* cond = dostmt->getCond(); Expr* cond = dostmt->getCond();
auto cond_casted = dyn_cast<CXXBoolLiteralExpr>(cond); auto cond_casted = dyn_cast<CXXBoolLiteralExpr>(cond);
RELEASE_ASSERT( RELEASE_ASSERT(cond_casted && cond_casted->getValue() == false,
cond_casted && cond_casted->getValue() == false,
"Only support `do {} while(false);` statements for now"); "Only support `do {} while(false);` statements for now");
handle(dostmt->getBody(), state); handle(dostmt->getBody(), state);
return; return;
...@@ -369,8 +368,10 @@ private: ...@@ -369,8 +368,10 @@ private:
handle(ifstmt->getCond(), state); handle(ifstmt->getCond(), state);
BlockState else_state(state); BlockState else_state(state);
if (ifstmt->getThen()) handle(ifstmt->getThen(), state); if (ifstmt->getThen())
if (ifstmt->getElse()) handle(ifstmt->getElse(), else_state); handle(ifstmt->getThen(), state);
if (ifstmt->getElse())
handle(ifstmt->getElse(), else_state);
checkSameAndMerge(state, else_state); checkSameAndMerge(state, else_state);
return; return;
} }
...@@ -443,11 +444,9 @@ private: ...@@ -443,11 +444,9 @@ private:
} }
public: public:
explicit RefcheckingVisitor(ASTContext *Context) : Context(Context) { explicit RefcheckingVisitor(ASTContext* Context) : Context(Context) {}
}
virtual ~RefcheckingVisitor() { virtual ~RefcheckingVisitor() {}
}
virtual bool VisitFunctionDecl(FunctionDecl* func) { virtual bool VisitFunctionDecl(FunctionDecl* func) {
if (!func->hasBody()) if (!func->hasBody())
...@@ -467,10 +466,10 @@ public: ...@@ -467,10 +466,10 @@ public:
if (filename.find("lib/clang") != StringRef::npos) if (filename.find("lib/clang") != StringRef::npos)
return true; return true;
//errs() << filename << '\n'; // errs() << filename << '\n';
//if (func->getNameInfo().getAsString() != "firstlineno") // if (func->getNameInfo().getAsString() != "firstlineno")
//return true; // return true;
checkFunction(func); checkFunction(func);
...@@ -483,25 +482,23 @@ private: ...@@ -483,25 +482,23 @@ private:
RefcheckingVisitor visitor; RefcheckingVisitor visitor;
public: public:
explicit RefcheckingASTConsumer(ASTContext *Context) : visitor(Context) { explicit RefcheckingASTConsumer(ASTContext* Context) : visitor(Context) {}
}
virtual void HandleTranslationUnit(ASTContext &Context) { virtual void HandleTranslationUnit(ASTContext& Context) {
visitor.TraverseDecl(Context.getTranslationUnitDecl()); visitor.TraverseDecl(Context.getTranslationUnitDecl());
//dumper()->TraverseDecl(Context.getTranslationUnitDecl()); // dumper()->TraverseDecl(Context.getTranslationUnitDecl());
} }
}; };
class RefcheckingFrontendAction : public ASTFrontendAction { class RefcheckingFrontendAction : public ASTFrontendAction {
public: public:
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef fname) { virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance& CI, StringRef fname) {
return std::unique_ptr<ASTConsumer>(new RefcheckingASTConsumer(&CI.getASTContext())); return std::unique_ptr<ASTConsumer>(new RefcheckingASTConsumer(&CI.getASTContext()));
} }
}; };
int main(int argc, const char **argv) { int main(int argc, const char** argv) {
CommonOptionsParser OptionsParser(argc, argv, RefcheckingToolCategory); CommonOptionsParser OptionsParser(argc, argv, RefcheckingToolCategory);
ClangTool Tool(OptionsParser.getCompilations(), ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList());
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory<RefcheckingFrontendAction>().get()); return Tool.run(newFrontendActionFactory<RefcheckingFrontendAction>().get());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment