[cfe-commits] r161703 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp

Abramo Bagnara abramo.bagnara at gmail.com
Mon Aug 13 14:36:44 PDT 2012


Il 13/08/2012 22:36, Chandler Carruth ha scritto:
> Just to explain perhaps a bit more, as I too agree with Eli and Chad here...
> 
> On Mon, Aug 13, 2012 at 4:36 AM, João Matos <ripzonetriton at gmail.com
> <mailto:ripzonetriton at gmail.com>> wrote:
> 
>     I agree, it would be best to store one node per statement in the
>     AST, even if semantically they will be handled as one.
> 
> 
> This is a pretty fundamental deviation from the model for the AST.
> 
> We have AST nodes to represent the structural semantics of the program.
> Many of these do not even correspond to syntax in the source program.
> They are there to expose the underlying semantics of the structure after
> parsing has taken place. The inverse applies here: even though there may
> be syntax recognized by the parser that resembles that of multiple
> statements, if the actual semantic model is that of a single statement,
> the AST should reflect that.
> 
> When you say "It would be best to store one node per statement in the
> AST" you are begging the question by assuming there are multiple
> statements in the source program. I think what Eli and Chad are arguing
> is that there is exactly one node per statement in the AST, and all of
> the inline asm instructions are part of a single statement due to their
> semantic model.

I'm really failing to understand how multiple __asm keyword with their
arguments can be considered a single statement...

In http://msdn.microsoft.com/en-us/library/45yd4tzz.aspx it is stated
clearly that:

> Because the __asm keyword is a statement separator, you can also put >
assembly instructions on the same line:

> __asm mov al, 2   __asm mov dx, 0xD007   __asm out dx, al

So these are definitely (according to Microsoft documentation) three
statements and not one.

That apart, currently clang AST rather surprisingly looks like:

void p1() {
  asm nop
  asm nop
}

void p2() {
  asm { nop }
  asm { nop }
}

void q1() {
  asm nop;
  asm nop;
}

void q2() {
  asm { nop };
  asm { nop };
}


void p1() (CompoundStmt 0x3114ec0 <p.cc:2:11, line:5:1>
  (MSAsmStmt 0x3114e40 <line:3:3, line:4:7>))


void p2() (CompoundStmt 0x3141378 <p.cc:7:11, line:10:1>
  (MSAsmStmt 0x3114fa0 <line:8:3, line:9:13>))


void q1() (CompoundStmt 0x31414d0 <p.cc:12:11, line:15:1>
  (MSAsmStmt 0x3141450 <line:13:3, line:14:10>))


void q2() (CompoundStmt 0x31416a0 <p.cc:17:11, line:20:1>
  (MSAsmStmt 0x31415b0 <line:18:3, col:13>)
  (NullStmt 0x3141618 <col:14>)
  (MSAsmStmt 0x3141628 <line:19:3, col:13>)
  (NullStmt 0x3141690 <col:14>))

What is special in q2? Why the NullStmt?






More information about the cfe-commits mailing list