llvm::FoldingSetNodeID to compare Stmt

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:

{
m();
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?

Thanks,

Pedro.

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.