[cfe-dev] llvm::FoldingSetNodeID to compare Stmt
Richard Smith
metafoo at gmail.com
Tue Jan 21 16:22:33 PST 2014
On Sat Jan 18 2014 at 4:23:08 AM, Pedro Delgado Perez <
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
>
> 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
>
> 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/de352076/attachment.html>
More information about the cfe-dev
mailing list