[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-core-dev] IASTReference.getReferencedElement() == null
|
Hello all,
I have been experimenting with the CDT parser (from CDT SDK 2.0) trying to
extract references inside of functions. So, for example, in
int i = 0;
void f() {
i++;
}
I want to extract the information that inside of function f there is a
reference to variable i.
To do that I created scanner and parser with ParserMode.COMPLETE_PARSE mode
and wrote a custom Callback that inherits from StructuralParseCallback as I
want to reuse the functionality of collecting declarations. Additionally,
methods such as acceptVariableReference() are overridden like that:
public void acceptVariableReference(IASTVariableReference reference) {
if (insideFunction()) {
currentFunction.refs.add(reference);
}
}
Note that currentFunction is not an instance of type IASTFunction. It is a
custom function object that can collect references.
When I parse the small sample code above, I get a IASTVariableReference that
prints itself out as
"org.eclipse.cdt.internal.core.parser.ast.complete.ReferenceCache$ASTVariableReference@1c99159",
which looks pretty good, but when I call getReferencedElement() on that I
get a null. The parser doesn't report an error, i.e. parser.parse() ==
true.
Maybe somebody here has an idea where my mistake is.
Thanks,
Philipp Haller