Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-core-dev] IASTReference.getReferencedElement() == null

Hi,

I just wanted to inform everybody that I found a solution to my problem.
Inside the callback method (e.g.
acceptVariableReference(IASTVariableReference ref)) I can access the
referenced element, so I just save it there.
I tried this after finding a hint in the Parser Framework Overview for CDT
1.2 ("Another_Parser_Document" ;-)):

"It is expected that clients of ISourceElementRequestor do not keep hold of
the nodes once they are processed in the callback.  In
ParserMode.COMPLETE_PARSE mode, local variable definitions are garbage
collected when they go out of scope, by holding onto these references you
would be doing the CDT a disservice."

So, I tried not to keep hold of the nodes too long... and it worked! ;-)

   Philipp


Quoting haller@xxxxxx:

> 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
> 
> 
> 
> _______________________________________________
> cdt-core-dev mailing list
> cdt-core-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/cdt-core-dev
> 







Back to the top