<html>
<head></head>
<body>
<p>Wow, so simple... That function mixed me up as it said "it’s not as trivial to test if two expressions are the same", but it should say "equivalent" instead of "same".</p>
<p>You really helped me. Thanks a lot Richard!</p>
<p>Pedro.</p>
<br/>
<div><em>El día 22 ene 2014 01:22, Richard Smith <metafoo@gmail.com> escribió:</em></div><blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>On Sat Jan 18 2014 at 4:23:08 AM, Pedro Delgado Perez <<a href="mailto:pedro.delgadoperez@mail.uca.es">pedro.delgadoperez@mail.uca.es</a>> wrote:</div><blockquote class="gmail_quote" style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><p>Hi,</p>
<p>Up to now, to determine if two objects "Stmt" were the same, I have been using the function "areSameExpr", which appers at the end of this link:</p>
<p><a href="http://clang.llvm.org/docs/LibASTMatchersTutorial.html" target="_blank">http://clang.llvm.org/docs/LibASTMatchersTutorial.html</a></p>
<pre><span>static</span> <span>bool</span> <span>areSameExpr</span><span>(</span><span>ASTContext</span> <span>*</span><span>Context</span><span>,</span> <span>const</span> <span>Expr</span> <span>*</span><span>First</span><span>,</span>                        <span>const</span> <span>Expr</span> <span>*</span><span>Second</span><span>)</span> <span>{</span>  <span>if</span> <span>(</span><span>!</span><span>First</span> <span>||</span> <span>!</span><span>Second</span><span>)</span>    <span>return</span> <span>false</span><span>;</span>  <span>llvm</span><span>::</span><span>FoldingSetNodeID</span> <span>FirstID</span><span>,</span> <span>SecondID</span><span>;</span>  <span>First</span><span>-></span><span>Profile</span><span>(</span><span>FirstID</span><span>,</span> <span>*</span><span>Context</span><span>,</span> <span>true</span><span>);</span>  <span>Second</span><span>-></span><span>Profile</span><span>(</span><span>SecondID</span><span>,</span> <span>*</span><span>Context</span><span>,</span> <span>true</span><span>);</span>  <span>return</span> <span>FirstID</span> <span>==</span> <span>SecondID</span><span>;</span><span>}</span></pre><p>However, I have a problem with that function. To illustrate the issue, I retrieve a concrete Stmt (in bold in the example below) in a CompoundStmt through a matcher:</p>
<p>{<br />A::getca();<br />m();<br /><strong>A::getca(); </strong><br />int  l = 1; <br />}</p>
<p>Then, when handling that Stmt, I search for the position of that stmt within the compoundStmt with a simple loop and using the function  <span>"areSameExpr</span>" aforementioned.</p>
<p>for(CompoundStmt::body_iterator st = CompStmt->body_begin(); st != CompStmt->body_end(); st++){ <br />                     <br />                    if(areSameStmt(Context, *st, StmtBound)){<br />                    ....<br />                   }<br />}</p>
<p>However, this function considers that the first stmt in the compoundStmt is the same as the third one, and that is a problem in my case because I need to determine every stmt as unique to know the position. <br />I have been studying the class llvm::FoldingSetNodeID<br /><a href="http://llvm.org/docs/doxygen/html/classllvm_1_1FoldingSetNodeID.html#a66f5b8a0b6a74b310d856ca736c1eb8c" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1FoldingSetNodeID.html#a66f5b8a0b6a74b310d856ca736c1eb8c</a></p>
<p>I tried to use the method "ComputeHash" to compare both stmt, but it didn't suppose any change.</p>
<p>Please, does anyone know how I could fix this?</p>
</div></blockquote><div>If you want to check if you have the same Stmt, just compare the Stmt*. The Profile mechanism is intended to allow you to determine if two Stmts are equivalent.</div><blockquote class="gmail_quote" style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><p>Thanks,</p>
<p>Pedro.</p>
</div></blockquote></blockquote>
</body>
</html>