Home | History | Annotate | Download | only in gcmole

Lines Matching full:clang

28 // This is clang plugin used by gcmole tool. See README for more details.
30 #include "clang/AST/AST.h"
31 #include "clang/AST/ASTConsumer.h"
32 #include "clang/AST/Mangle.h"
33 #include "clang/AST/RecursiveASTVisitor.h"
34 #include "clang/AST/StmtVisitor.h"
35 #include "clang/Frontend/FrontendPluginRegistry.h"
36 #include "clang/Frontend/CompilerInstance.h"
51 static bool GetMangledName(clang::MangleContext* ctx,
52 const clang::NamedDecl* decl,
54 if (!llvm::isa<clang::CXXConstructorDecl>(decl) &&
55 !llvm::isa<clang::CXXDestructorDecl>(decl)) {
67 static bool InV8Namespace(const clang::NamedDecl* decl) {
75 static bool IsExternalVMState(const clang::ValueDecl* var) {
76 const clang::EnumConstantDecl* enum_constant =
77 llvm::dyn_cast<clang::EnumConstantDecl>(var);
79 clang::QualType type = enum_constant->getType();
88 explicit Resolver(clang::ASTContext& ctx)
92 Resolver(clang::ASTContext& ctx, clang::DeclContext* decl_ctx)
96 clang::DeclarationName ResolveName(const char* n) {
97 clang::IdentifierInfo* ident = &ctx_.Idents.get(n);
102 return Resolver(ctx_, Resolve<clang::NamespaceDecl>(n));
109 clang::DeclContext::lookup_result result =
112 clang::DeclContext::lookup_iterator end = result.end();
113 for (clang::DeclContext::lookup_iterator i = result.begin(); i != end;
122 clang::ASTContext& ctx_;
123 clang::DeclContext* decl_ctx_;
127 class CalleesPrinter : public clang::RecursiveASTVisitor<CalleesPrinter> {
129 explicit CalleesPrinter(clang::MangleContext* ctx) : ctx_(ctx) {
132 virtual bool VisitCallExpr(clang::CallExpr* expr) {
133 const clang::FunctionDecl* callee = expr->getDirectCallee();
138 virtual bool VisitDeclRefExpr(clang::DeclRefExpr* expr) {
145 void AnalyzeFunction(const clang::FunctionDecl* f) {
150 const clang::FunctionDecl* body = NULL;
199 clang::MangleContext* ctx_;
207 : public clang::ASTConsumer,
208 public clang::RecursiveASTVisitor<FunctionDeclarationFinder> {
210 explicit FunctionDeclarationFinder(clang::DiagnosticsEngine& d,
211 clang::SourceManager& sm,
215 virtual void HandleTranslationUnit(clang::ASTContext &ctx) {
216 mangle_context_ = clang::ItaniumMangleContext::create(ctx, d_);
224 virtual bool VisitFunctionDecl(clang::FunctionDecl* decl) {
230 clang::DiagnosticsEngine& d_;
231 clang::SourceManager& sm_;
232 clang::MangleContext* mangle_context_;
254 static bool KnownToCauseGC(clang::MangleContext* ctx,
255 const clang::FunctionDecl* decl) {
539 FunctionAnalyzer(clang::MangleContext* ctx,
540 clang::DeclarationName handle_decl_name,
541 clang::CXXRecordDecl* object_decl,
542 clang::CXXRecordDecl* smi_decl, clang::DiagnosticsEngine& d,
543 clang::SourceManager& sm, bool dead_vars_analysis)
558 ExprEffect VisitExpr(clang::Expr* expr, const Environment& env) {
561 clang::type* concrete_expr = llvm::dyn_cast_or_null<clang::type>(expr); \
626 ExprEffect Visit##type (clang::type* expr, const Environment& env)
629 ExprEffect Visit##type (clang::type* expr, const Environment& env) { \
678 clang::Expr* exprs[2] = {expr->getBase(), expr->getIdx()};
682 bool IsRawPointerVar(clang::Expr* expr, std::string* var_name) {
683 if (llvm::isa<clang::DeclRefExpr>(expr)) {
685 llvm::cast<clang::DeclRefExpr>(expr)->getDecl()->getNameAsString();
692 clang::Expr* lhs = expr->getLHS();
693 clang::Expr* rhs = expr->getRHS();
694 clang::Expr* exprs[2] = {lhs, rhs};
697 case clang::BO_Comma:
700 case clang::BO_LAnd:
701 case clang::BO_LOr:
704 case clang::BO_Assign: {
770 if (expr->getOpcode() == clang::UO_AddrOf) {
787 ExprEffect Par(clang::Expr* parent,
789 clang::Expr** exprs,
802 ExprEffect Seq(clang::Stmt* parent,
804 clang::Expr** exprs,
815 ExprEffect Use(const clang::Expr* parent,
816 const clang::QualType& var_type,
828 ExprEffect Use(const clang::Expr* parent,
829 const clang::ValueDecl* var,
856 ExprEffect VisitCallExpr(clang::CallExpr* call,
860 clang::CXXMemberCallExpr* memcall =
861 llvm::dyn_cast_or_null<clang::CXXMemberCallExpr>(call);
863 clang::Expr* receiver = memcall->getImplicitObjectArgument();
874 clang::FunctionDecl* callee = call->getDirectCallee();
886 Environment VisitStmt(clang::Stmt* stmt, const Environment& env) {
889 clang::type* concrete_stmt = llvm::dyn_cast_or_null<clang::type>(stmt); \
895 if (clang::Expr* expr = llvm::dyn_cast_or_null<clang::Expr>(stmt)) {
924 Environment Visit##type (clang::type* stmt, const Environment& env)
927 Environment Visit##type (clang::type* stmt, const Environment& env) { \
984 void Seq(clang::Stmt* a, clang::Stmt* b, clang::Stmt* c) {
991 void Seq(clang::Stmt* a, clang::Stmt* b) {
997 void Loop(clang::Stmt* a, clang::Stmt* b, clang::Stmt* c) {
1002 void Loop(clang::Stmt* a, clang::Stmt* b) {
1029 clang::CompoundStmt::body_iterator end = stmt->body_end();
1030 for (clang::CompoundStmt::body_iterator s = stmt->body_begin();
1093 const clang::TagType* ToTagType(const clang::Type* t) {
1096 } else if (llvm::isa<clang::TagType>(t)) {
1097 return llvm::cast<clang::TagType>(t);
1098 } else if (llvm::isa<clang::SubstTemplateTypeParmType>(t)) {
1099 return ToTagType(llvm::cast<clang::SubstTemplateTypeParmType>(t)
1107 bool IsDerivedFrom(clang::CXXRecordDecl* record,
1108 clang::CXXRecordDecl* base) {
1112 bool IsRawPointerType(clang::QualType qtype) {
1113 const clang::PointerType* type =
1114 llvm::dyn_cast_or_null<clang::PointerType>(qtype.getTypePtrOrNull());
1117 const clang::TagType* pointee =
1121 clang::CXXRecordDecl* record =
1122 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(pointee->getDecl());
1135 Environment VisitDecl(clang::Decl* decl, const Environment& env) {
1136 if (clang::VarDecl* var = llvm::dyn_cast<clang::VarDecl>(decl)) {
1151 clang::DeclStmt::decl_iterator end = stmt->decl_end();
1152 for (clang::DeclStmt::decl_iterator decl = stmt->decl_begin();
1161 void DefineParameters(const clang
1164 clang::FunctionDecl::param_const_iterator end = f->param_end();
1165 for (clang::FunctionDecl::param_const_iterator p = f->param_begin();
1173 void AnalyzeFunction(const clang::FunctionDecl* f) {
1174 const clang::FunctionDecl* body = NULL;
1194 void ReportUnsafe(const clang::Expr* expr, const std::string& msg) {
1195 d_.Report(clang::FullSourceLoc(expr->getExprLoc(), sm_),
1196 d_.getCustomDiagID(clang::DiagnosticsEngine::Warning, "%0"))
1201 clang::MangleContext* ctx_;
1202 clang::DeclarationName handle_decl_name_;
1203 clang::CXXRecordDecl* object_decl_;
1204 clang::CXXRecordDecl* smi_decl_;
1206 clang::DiagnosticsEngine& d_;
1207 clang::SourceManager& sm_;
1214 class ProblemsFinder : public clang::ASTConsumer,
1215 public clang::RecursiveASTVisitor<ProblemsFinder> {
1217 ProblemsFinder(clang::DiagnosticsEngine& d, clang::SourceManager& sm,
1227 virtual void HandleTranslationUnit(clang::ASTContext &ctx) {
1230 clang::CXXRecordDecl* object_decl =
1232 Resolve<clang::CXXRecordDecl>("Object");
1234 clang::CXXRecordDecl* smi_decl =
1236 Resolve<clang::CXXRecordDecl>("Smi");
1244 clang::ItaniumMangleContext::create(ctx, d_), r.ResolveName("Handle"),
1257 virtual bool VisitFunctionDecl(clang::FunctionDecl* decl) {
1263 clang::DiagnosticsEngine& d_;
1264 clang::SourceManager& sm_;
1272 class Action : public clang::PluginASTAction {
1274 clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &CI,
1279 bool ParseArgs(const clang::CompilerInstance &CI,
1294 static clang::FrontendPluginRegistry::Add<Action<ProblemsFinder> >
1297 static clang::FrontendPluginRegistry::Add<