Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » ASTVisitor - Function Call binding is returning null
ASTVisitor - Function Call binding is returning null [message #181746] Tue, 02 January 2007 17:14 Go to next message
Eclipse UserFriend
Originally posted by: bgarcia.dextratech.com

I'm parsing c++ source files through an ASTVisitor over an
IASTTranslationUnit object in order to detect Function Calls expressions:



IASTTranslationUnit asttu = serviceProvider.getTranslationUnit( file);

asttu.accept(new ASTVisitor() {

{

shouldVisitStatements = true;

shouldVisitExpressions = true;

}

public int visit(IASTStatement statement) {

try {

// Perform the visit

} catch (Exception e) {


e.printStackTrace();

}

return PROCESS_CONTINUE;

}



When I get a CPPASTFunctionCallExpression node and go through nodes
hierarchy, I was getting a getBinding() method which was giving me the
class
Re: ASTVisitor - Function Call binding is returning null [message #182777 is a reply to message #181746] Tue, 23 January 2007 17:42 Go to previous messageGo to next message
Eclipse UserFriend
Use IASTName.resolveBinding() instead.

Binding resolution is on demand, if nobody has resolved that particular binding
yet, getBinding will return null. Notice the javadoc on IASTName.getBinding():
"Get the semantic object attached to this name. May be null if this name
has not yet been semantically resolved (@see resolveBinding)"

As a general rule, you should be using the interfaces instead of the
implementing methods. On the syntactic side there are other names that
implement IASTName but aren't CPPASTName (ie qualified names and template ids).
Similarily on the semantic side, there are bindings that implement ICPPMethod
but aren't CPPMethod.

-Andrew

cdt1 wrote:
> I'm parsing c++ source files through an ASTVisitor over an
> IASTTranslationUnit object in order to detect Function Calls expressions:
>
>
>
> IASTTranslationUnit asttu = serviceProvider.getTranslationUnit( file);
>
> asttu.accept(new ASTVisitor() {
>
> {
>
> shouldVisitStatements = true;
>
> shouldVisitExpressions = true;
>
> }
>
> public int visit(IASTStatement statement) {
>
> try {
>
> // Perform the visit
>
> } catch (Exception e) {
>
>
> e.printStackTrace();
>
> }
>
> return PROCESS_CONTINUE;
>
> }
>
>
>
> When I get a CPPASTFunctionCallExpression node and go through nodes
> hierarchy, I was getting a getBinding() method which was giving me the
> classàfunction information of the function being called:
>
>
>
> private void processIdExpression(CPPASTIdExpression functionName) {
>
> if (functionName.getName() instanceof CPPASTName) {
>
> CPPASTName name =
> (CPPASTName)functionName.getName();
>
> if (name.getBinding() instanceof CPPMethod) {
>
> CPPMethod binding =
> (CPPMethod)name.getBinding();
>
> if (binding.getQualifiedName().length ==
> 2)
>
>
> System.out.println("class:"+binding.getQualifiedName()[0]+ "
> function:"+binding.getQualifiedName()[1]);
>
> }
>
> }
>
> }
>
>
>
> Now, the getBinding() method is returning null for all the Function Calls
> found, so I can't get the classàfunction information of the call anymore.
> Any idea about why the getBinding() method is returning null?
>
>
Re: ASTVisitor - Function Call binding is returning null [message #182852 is a reply to message #182777] Wed, 24 January 2007 05:38 Go to previous message
Eclipse UserFriend
By the way, if you want to mainapulate the AST, the static analyzer for C++
is a good example. It can be downloaded from
http://www.eclipse.org/tptp/home/downloads/

"Andrew Niefer" <aniefer@ca.ibm.com>
??????:ep62vt$2tg$1@utils.eclipse.org...
> Use IASTName.resolveBinding() instead.
>
> Binding resolution is on demand, if nobody has resolved that particular
> binding yet, getBinding will return null. Notice the javadoc on
> IASTName.getBinding(): "Get the semantic object attached to this name.
> May be null if this name
> has not yet been semantically resolved (@see resolveBinding)"
>
> As a general rule, you should be using the interfaces instead of the
> implementing methods. On the syntactic side there are other names that
> implement IASTName but aren't CPPASTName (ie qualified names and template
> ids).
> Similarily on the semantic side, there are bindings that implement
> ICPPMethod but aren't CPPMethod.
>
> -Andrew
>
> cdt1 wrote:
>> I'm parsing c++ source files through an ASTVisitor over an
>> IASTTranslationUnit object in order to detect Function Calls expressions:
>>
>>
>>
>> IASTTranslationUnit asttu = serviceProvider.getTranslationUnit( file);
>>
>> asttu.accept(new ASTVisitor() {
>>
>> {
>>
>> shouldVisitStatements = true;
>>
>> shouldVisitExpressions = true;
>>
>> }
>>
>> public int visit(IASTStatement statement) {
>>
>> try {
>>
>> // Perform the visit
>>
>> } catch (Exception e) {
>>
>>
>> e.printStackTrace();
>>
>> }
>>
>> return PROCESS_CONTINUE;
>>
>> }
>>
>>
>>
>> When I get a CPPASTFunctionCallExpression node and go through nodes
>> hierarchy, I was getting a getBinding() method which was giving me the
>> class
Previous Topic:Where to download CDT 4 M4
Next Topic:C/C++ Code Review Provider
Goto Forum:
  


Current Time: Sun Jul 27 18:40:10 EDT 2025

Powered by FUDForum. Page generated in 0.03209 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top