Exemplo n.º 1
0
/*
   returns the first parent of input s that is of type Decl
 */
const Decl* getDeclParent(const Stmt* s, ASTContext *Context){
	const Decl* ret = NULL;
	if(!s){
		return ret;
	}
	const ASTContext::DynTypedNodeList parents = Context->getParents(*s);
	if(parents.size() > 0){
		ret = parents[0].get<Decl>();
	}
	return ret;
}
Exemplo n.º 2
0
/*
   returns the first parent of input d that is of type Stmt
 */
const Stmt* getStmtParent(const Decl *d, ASTContext *Context){
	const Stmt* ret = NULL;
	if(!d) {
		return ret;
	}
	const ASTContext::DynTypedNodeList parents = Context->getParents(*d);
	if(parents.size() > 0){
		ret = parents[0].get<Stmt>();
	}
	return ret;
}
AST_MATCHER_P(Expr, hasParentIgnoringImpCasts,
              ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
  const Expr *E = &Node;
  do {
    ASTContext::DynTypedNodeList Parents =
        Finder->getASTContext().getParents(*E);
    if (Parents.size() != 1)
      return false;
    E = Parents[0].get<Expr>();
    if (!E)
      return false;
  } while (isa<ImplicitCastExpr>(E));

  return InnerMatcher.matches(*E, Finder, Builder);
}