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 (!isa<clang::CXXConstructorDecl>(decl) &&
55 !isa<clang::CXXDestructorDecl>(decl)) {
67 static bool InV8Namespace(const clang::NamedDecl* decl) {
72 class CalleesPrinter : public clang::RecursiveASTVisitor<CalleesPrinter> {
74 explicit CalleesPrinter(clang::MangleContext* ctx) : ctx_(ctx) {
77 virtual bool VisitCallExpr(clang::CallExpr* expr) {
78 const clang::FunctionDecl* callee = expr->getDirectCallee();
83 void AnalyzeFunction(const clang::FunctionDecl* f) {
88 const clang::FunctionDecl* body = NULL;
137 clang::MangleContext* ctx_;
144 : public clang::ASTConsumer,
145 public clang::RecursiveASTVisitor<FunctionDeclarationFinder> {
147 explicit FunctionDeclarationFinder(clang::Diagnostic& d,
148 clang::SourceManager& sm)
151 virtual void HandleTranslationUnit(clang::ASTContext &ctx) {
152 mangle_context_ = clang::createItaniumMangleContext(ctx, d_);
160 virtual bool VisitFunctionDecl(clang::FunctionDecl* decl) {
166 clang::Diagnostic& d_;
167 clang::SourceManager& sm_;
168 clang::MangleContext* mangle_context_;
190 static bool KnownToCauseGC(clang::MangleContext* ctx,
191 const clang::FunctionDecl* decl) {
205 static bool IsHandleType(const clang::DeclarationName& handleDeclName,
206 const clang::QualType& qtype) {
207 const clang::Type* canonical_type =
210 if (const clang::TemplateSpecializationType* type =
211 canonical_type->getAs<clang::TemplateSpecializationType>()) {
212 if (clang::TemplateDecl* decl =
218 } else if (const clang::RecordType* type =
219 canonical_type->getAs<clang::RecordType>()) {
220 if (const clang::ClassTemplateSpecializationDecl* t =
221 dyn_cast<clang::ClassTemplateSpecializationDecl>(type->getDecl())) {
233 public clang::RecursiveASTVisitor<ExpressionClassifier> {
235 ExpressionClassifier(clang::DeclarationName handleDeclName,
236 clang::MangleContext* ctx,
237 clang::CXXRecordDecl* objectDecl)
243 bool IsBadExpression(clang::Expr* expr) {
249 bool IsBadCallSite(clang::Expr* expr) {
250 if (isa<clang::CallExpr>(expr)) {
251 clang::CallExpr* call = cast<clang::CallExpr>(expr);
262 virtual bool VisitExpr(clang::Expr* expr) {
267 virtual bool VisitCallExpr(clang::CallExpr* expr) {
272 void MarkHandleDereferenceAsArgument(clang::CallExpr* call) {
275 if (clang::CXXMemberCallExpr* memcall =
276 dyn_cast<clang::CXXMemberCallExpr>(call)) {
287 void MarkGCSuspectAsArgument(clang::CallExpr* call) {
290 clang::CXXMemberCallExpr* memcall =
291 dyn_cast_or_null<clang::CXXMemberCallExpr>(call);
301 const clang::TagType* ToTagType(const clang::Type* t) {
304 } else if (isa<clang::TagType>(t)) {
305 return cast<clang::TagType>(t);
306 } else if (isa<clang::SubstTemplateTypeParmType>(t)) {
307 return ToTagType(cast<clang::SubstTemplateTypeParmType>(t)->
314 bool IsRawPointerType(clang::Expr* expr) {
315 clang::QualType result = expr->getType();
317 const clang::PointerType* type =
318 dyn_cast_or_null<clang::PointerType>(expr->getType().getTypePtr());
321 const clang::TagType* pointee =
325 clang::CXXRecordDecl* record =
326 dyn_cast_or_null<clang::CXXRecordDecl>(pointee->getDecl());
334 bool IsHandleDereference(clang::Expr* expr) {
337 } else if (isa<clang::UnaryOperator>(expr)) {
338 clang::UnaryOperator* unop = cast<clang::UnaryOperator>(expr);
339 return unop->getOpcode() == clang::UO_Deref &&
341 } else if (isa<clang::CXXOperatorCallExpr>(expr)) {
342 clang::CXXOperatorCallExpr* op = cast<clang::CXXOperatorCallExpr>(expr);
343 return (op->getOperator() == clang::OO_Star ||
344 op->getOperator() == clang::OO_Arrow) &&
351 bool CanCauseGC(clang::Expr* expr) {
360 bool ManipulatesRawPointers(clang::Expr* expr) {
369 bool CanCauseGC(const clang::CallExpr* call) {
370 const clang::FunctionDecl* fn = call->getDirectCallee();
383 clang::DeclarationName handleDeclName_;
384 clang::MangleContext* ctx_;
385 clang::CXXRecordDecl* objectDecl_;
390 class ExpressionsFinder : public clang::ASTConsumer,
391 public clang::RecursiveASTVisitor<ExpressionsFinder> {
393 explicit ExpressionsFinder(clang::Diagnostic& d, clang::SourceManager& sm)
397 explicit Resolver(clang::ASTContext& ctx)
401 Resolver(clang::ASTContext& ctx, clang::DeclContext* decl_ctx)
405 clang::DeclarationName ResolveName(const char* n) {
406 clang::IdentifierInfo* ident = &ctx_.Idents.get(n);
411 return Resolver(ctx_, Resolve<clang::NamespaceDecl>(n));
418 clang::DeclContext::lookup_result result =
421 for (clang::DeclContext::lookup_iterator i = result.first,
432 clang::ASTContext& ctx_;
433 clang::DeclContext* decl_ctx_;
436 virtual void HandleTranslationUnit(clang::ASTContext &ctx) {
439 clang::CXXRecordDecl* objectDecl =
441 Resolve<clang::CXXRecordDecl>("Object");
446 clang::createItaniumMangleContext(ctx, d_),
454 virtual bool VisitExpr(clang::Expr* expr) {
456 d_.Report(clang::FullSourceLoc(expr->getExprLoc(), sm_),
457 d_.getCustomDiagID(clang::Diagnostic::Warning,
465 clang::Diagnostic& d_;
466 clang::SourceManager& sm_;
473 class Action : public clang::PluginASTAction {
475 clang::ASTConsumer *CreateASTConsumer(clang::CompilerInstance &CI,
480 bool ParseArgs(const clang::CompilerInstance &CI,
491 static clang::FrontendPluginRegistry::Add<Action<ExpressionsFinder> >
494 static clang::FrontendPluginRegistry::Add<Action<FunctionDeclarationFinder> >