#ifndef TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_
#define TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_
#include <vector>
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "llvm/ADT/StringSet.h"
namespace chrome_checker {
class CheckIPCVisitor {
public:
explicit CheckIPCVisitor(clang::CompilerInstance& compiler);
void set_context(clang::ASTContext* context) { context_ = context; }
void BeginDecl(clang::Decl* decl);
void EndDecl();
void VisitTemplateSpecializationType(
clang::TemplateSpecializationType* spec);
void VisitCallExpr(clang::CallExpr* call_expr);
private:
bool ValidateWriteParam(const clang::CallExpr* call_expr);
bool ValidateWriteParamSignature(const clang::CallExpr* call_expr);
bool ValidateWriteParamArgument(const clang::Expr* arg_expr);
bool ValidateCheckedTuple(
const clang::TemplateSpecializationType* spec);
template <typename T>
const T* GetParentDecl() const;
bool IsBlacklistedType(clang::QualType type) const;
bool IsBlacklistedTypedef(const clang::TypedefNameDecl* tdef) const;
struct CheckDetails {
clang::QualType entry_type;
clang::QualType exit_type;
llvm::SmallVector<const clang::TypedefType*, 5> typedefs;
};
bool CheckType(clang::QualType type, CheckDetails* details) const;
bool CheckIntegerType(clang::QualType type, CheckDetails* details) const;
bool CheckTemplateArgument(const clang::TemplateArgument& arg,
CheckDetails* details) const;
void ReportCheckError(const CheckDetails& details,
clang::SourceLocation loc,
unsigned error);
clang::CompilerInstance& compiler_;
clang::ASTContext* context_;
unsigned error_write_param_bad_type_;
unsigned error_tuple_bad_type_;
unsigned error_write_param_bad_signature_;
unsigned note_see_here_;
std::vector<const clang::Decl*> decl_stack_;
llvm::StringSet<> blacklisted_typedefs_;
};
}
#endif