[cfe-dev] Remove implicitly generated AST nodes by Sema

Pan, Wei wei.pan at intel.com
Tue Jun 4 13:26:08 PDT 2013


Seemly this function can only remove implicit casts. There are some AST nodes, like CXXConstructExpr in the example, which will stick there.

http://clang.llvm.org/doxygen/Stmt_8cpp_source.html#l00099

Wei

From: Eli Friedman [mailto:eli.friedman at gmail.com]
Sent: Tuesday, June 04, 2013 3:54 PM
To: Pan, Wei
Cc: clang-dev Developers
Subject: Re: [cfe-dev] Remove implicitly generated AST nodes by Sema

Expr::IgnoreImplicit() lets you easily look through implicit expressions.

-Eli

On Tue, Jun 4, 2013 at 11:56 AM, Pan, Wei <wei.pan at intel.com<mailto:wei.pan at intel.com>> wrote:
Hi all,

I am wondering if it is possible to remove all the implicitly generated AST nodes.

For example (below), the only argument to call (1) is a "DeclRefExpr" to y, and the only
argument to call (2) is a "CXXContructExpr", if ignoring nodes created by the initialization
sequence for the call.

Basically, I want to get the "syntactic form" Expr from an expression with some semantic
analysis. Is there an existing way to do so? Or what would be a proper way to implement this?

Thanks!

Wei

------------------------------------------------------------------

struct Y { };
struct X { X(); X(Y&); };
void foo(X);

void bar(Y &y) {
  foo(y);     // (1)
  foo(X(y));  // (2)
}

|-CallExpr 0x2a6c790 <line:8:3, col:8> 'void'
| |-ImplicitCastExpr 0x2a6c778 <col:3> 'void (*)(struct X)' <FunctionToPointerDecay>
| | `-DeclRefExpr 0x2a6c728 <col:3> 'void (struct X)' lvalue Function 0x2a6c2c0 'foo' 'void (struct X)'
| `-CXXConstructExpr 0x2a6c9f8 <col:7> 'struct X' 'void (const struct X &) throw()' elidable
|   `-MaterializeTemporaryExpr 0x2a6c988 <col:7> 'const struct X' lvalue
|     `-ImplicitCastExpr 0x2a6c970 <col:7> 'const struct X' <NoOp>
|       `-ImplicitCastExpr 0x2a6c800 <col:7> 'struct X' <ConstructorConversion>
|         `-CXXConstructExpr 0x2a6c7c8 <col:7> 'struct X' 'void (struct Y &)'
|           `-DeclRefExpr 0x2a6c500 <col:7> 'struct Y' lvalue ParmVar 0x2a6c380 'y' 'struct Y &'
`-CallExpr 0x2a6cb60 <line:9:3, col:11> 'void'
  |-ImplicitCastExpr 0x2a6cb48 <col:3> 'void (*)(struct X)' <FunctionToPointerDecay>
  | `-DeclRefExpr 0x2a6cb20 <col:3> 'void (struct X)' lvalue Function 0x2a6c2c0 'foo' 'void (struct X)'
   `-CXXConstructExpr 0x2a6cbc8 <col:7, col:10> 'struct X' 'void (const struct X &) throw()' elidable
     `-MaterializeTemporaryExpr 0x2a6cbb0 <col:7, col:10> 'const struct X' lvalue
       `-ImplicitCastExpr 0x2a6cb98 <col:7, col:10> 'const struct X' <NoOp>
         `-CXXFunctionalCastExpr 0x2a6caf8 <col:7, col:10> 'struct X' functional cast to struct X <ConstructorConversion>
           `-CXXConstructExpr 0x2a6cac0 <col:7, col:10> 'struct X' 'void (struct Y &)'
             `-DeclRefExpr 0x2a6ca98 <col:9> 'struct Y' lvalue ParmVar 0x2a6c380 'y' 'struct Y &'

_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu<mailto:cfe-dev at cs.uiuc.edu>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130604/a24058fd/attachment.html>


More information about the cfe-dev mailing list