[cfe-dev] llvm::FoldingSetNodeID to compare Stmt
Pedro Delgado Perez
pedro.delgadoperez at mail.uca.es
Wed Jan 22 01:31:15 PST 2014
Wow, so simple... That function mixed me up as it said "it[rsquo]s not as trivial to test if two expressions are the same", but it should say "equivalent" instead of "same".
You really helped me. Thanks a lot Richard!
Pedro.
El día 22 ene 2014 01:22, Richard Smith <metafoo at gmail.com> escribió:
> On Sat Jan 18 2014 at 4:23:08 AM, Pedro Delgado Perez <pedro.delgadoperez at mail.uca.es [ mailto:pedro.delgadoperez at mail.uca.es ]> wrote:
>
> Hi,
>
> 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:
>
> http://clang.llvm.org/docs/LibASTMatchersTutorial.html [ http://clang.llvm.org/docs/LibASTMatchersTutorial.html ]
> static bool areSameExpr(ASTContext *Context, const Expr *First, const Expr *Second) { if (!First || !Second) return false; llvm::FoldingSetNodeID FirstID, SecondID; First->Profile(FirstID, *Context, true); Second->Profile(SecondID, *Context, true); return FirstID == SecondID;}
> 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:
>
> {
> A::getca();
> m();
> A::getca();
> int l = 1;
> }
>
> Then, when handling that Stmt, I search for the position of that stmt within the compoundStmt with a simple loop and using the function "areSameExpr" aforementioned.
>
> for(CompoundStmt::body_iterator st = CompStmt->body_begin(); st != CompStmt->body_end(); st++){
>
> if(areSameStmt(Context, *st, StmtBound)){
> ....
> }
> }
>
> 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.
> I have been studying the class llvm::FoldingSetNodeID
> http://llvm.org/docs/doxygen/html/classllvm_1_1FoldingSetNodeID.html#a66f5b8a0b6a74b310d856ca736c1eb8c [ http://llvm.org/docs/doxygen/html/classllvm_1_1FoldingSetNodeID.html#a66f5b8a0b6a74b310d856ca736c1eb8c ]
>
> I tried to use the method "ComputeHash" to compare both stmt, but it didn't suppose any change.
>
> Please, does anyone know how I could fix this?
>
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.
Thanks,
Pedro.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140122/e7eda77c/attachment.html>
More information about the cfe-dev
mailing list