Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-dev] IScope.getPhysicalNode() not available in CDT 4.0 - answer

By the way, it seems that the IASTNode that I get from the scope (see
"could use this too" in the comment from the example  below)
 isn't the same one I got from the older IScope.getPhysicalNode().
The source locations don't match up in my analysis, that found potential
problems in OpenMP code, starts reporting all the  OpenMP variables  "out
of scope."
Need to look at it in more detail, haven't had time. Any ideas appreciated.

...Beth

Beth Tibbitts  (859) 243-4981  (TL 545-4981)
High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
IBM T.J.Watson Research Center
Mailing Address:  IBM Corp., 455 Park Place, Lexington, KY 40511


                                                                           
             Beth                                                          
             Tibbitts/Watson/I                                             
             BM@IBMUS                                                   To 
             Sent by:                  "CDT General developers list."      
             cdt-dev-bounces@e         <cdt-dev@xxxxxxxxxxx>               
             clipse.org                                                 cc 
                                                                           
                                                                   Subject 
             04/27/2007 09:25          RE: [cdt-dev]                       
             AM                        IScope.getPhysicalNode() not        
                                       available in CDT 4.0 -      answer  
                                                                           
             Please respond to                                             
               "CDT General                                                
             developers list."                                             
             <cdt-dev@eclipse.                                             
                   org>                                                    
                                                                           
                                                                           




Just so there's an answer in this thread, here's what worked:
As it turns out I didn't have to use the IScope, since I had an
IASTDeclarator
already, but I've included how to do it with that since that was the
original question.
The part that wasn't apparent was the instanceof/casting of IBinding into
something that can produce an IASTNode.  DUH. Seems obvious now.
If anyone knows of other classes I need to check for please let me know.
No others turned up in running on a bunch of (MPI and OpenMP) C benchmark
code I have.

Thanks, Chris (for some offline help as well.)

public IASTNode getPhysicalNode() {
      IASTNode node = null;
      IASTDeclarator declarator = getDeclarator();)
      IASTName dn = declarator.getName();

      // Also retrievable from IScope (which was original question)
      IScope scope = getScope();
      IName sn;
      try {
            sn = scope.getScopeName();
            if(sn instanceof IASTName){
                  dn=(IASTName)sn; // could use this too *****
            }
      } catch (DOMException e) {return null;}

      IBinding binding = dn.resolveBinding();
      if (binding instanceof CFunction) {
            CFunction cf = (CFunction) binding;
            node = cf.getPhysicalNode();
      } else if (binding instanceof CParameter) {
            CParameter cp = (CParameter) binding;;
      } else if (binding instanceof CVariable) {
            CVariable cv = (CVariable) binding;
            node = cv.getPhysicalNode();
      } else if (binding instanceof CTypedef) {
            CTypedef ct = (CTypedef) binding;
            node = ct.getPhysicalNode();
      } // any other types I can get a physical node from???
      return node;
}

...Beth

 Beth Tibbitts  (859) 243-4981  (TL 545-4981)
 High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
 IBM T.J.Watson Research Center
 Mailing Address:  IBM Corp., 455 Park Place, Lexington, KY 40511



             Chris Recoskie
             <recoskie@xxxxxx.
             com>                                                       To
             Sent by:                  "CDT General developers list."
             cdt-dev-bounces@e         <cdt-dev@xxxxxxxxxxx>
             clipse.org                                                 cc

                                                                   Subject
             04/26/2007 11:52          RE: [cdt-dev]
             AM                        IScope.getPhysicalNode() not
                                       available in CDT 4.0

             Please respond to
               "CDT General
             developers list."
             <cdt-dev@eclipse.
                   org>






The scope has an IName.  This means it's either an IASTName or an
IIndexName.

If it's an IASTName (I'm assuming so since the stuff you are doing is
editor based), then you can do resolveBinding() on it to get the IBinding,
at which point you can then do interesting things.

If it's an IIndexName, then ultimately it will be a PDOMName, and so you
can do a resolveBinding() on that instead.


===========================

Chris Recoskie
Team Lead, IBM CDT Team
IBM Toronto
http://www.eclipse.org/cdt




             Beth Tibbitts
             <tibbitts@xxxxxx.
             com>                                                       To
             Sent by:                  "CDT General developers list."
             cdt-dev-bounces@e         <cdt-dev@xxxxxxxxxxx>
             clipse.org                                                 cc

                                                                   Subject
             26/04/2007 11:38          RE: [cdt-dev]
             AM                        IScope.getPhysicalNode() not
                                       available in CDT 4.0

             Please respond to
               "CDT General
             developers list."
             <cdt-dev@eclipse.
                   org>






>Maybe I'm missing something, but doesn't getParent() do what you need?
Do you mean IScope.getParent()?  Seems like this one be one level higher
than the scope itself.
or IASTDeclarator.getParent()?   I'm trying to figure out if that gives the
original intent of the code.  It's not apparent.

Basically, CDT 3.1 had IScope.getPhysicalNode() which returned an IASTNode.
CDT 4.0 doesn't have this method on IScope.
(Can I get it from the Binding? it's not obvious to me anyway how to get
the IASTNode from the IScope.)

Sorry if I'm being dense...


...Beth

Beth Tibbitts  (859) 243-4981  (TL 545-4981)
High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
IBM T.J.Watson Research Center
Mailing Address:  IBM Corp., 455 Park Place, Lexington, KY 40511



             Doug Schaefer
             <DSchaefer@xxxxxx
             m>                                                         To
             Sent by:                  "CDT General developers list."
             cdt-dev-bounces@e         <cdt-dev@xxxxxxxxxxx>
             clipse.org                                                 cc

                                                                   Subject
             04/25/2007 01:51          RE: [cdt-dev]
             PM                        IScope.getPhysicalNode() not
                                       available in CDT 4.0

             Please respond to
               "CDT General
             developers list."
             <cdt-dev@eclipse.
                   org>






Maybe I'm missing something, but doesn't getParent() do what you need?

Doug Schaefer, QNX Software Systems
Eclipse CDT Project Lead, http://cdtdoug.blogspot.com,


> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On
> Behalf Of Beth Tibbitts
> Sent: Wednesday, April 25, 2007 10:29 AM
> To: cdt-dev@xxxxxxxxxxx
> Subject: [cdt-dev] IScope.getPhysicalNode() not available in CDT 4.0
>
>
> One of my last remaining things to convert our PTP analysis code to CDT
> 4.0  ...
> The problem is that a class of ours, "Symbol" contains   a method to get
> the defining function it's found within.
> It relied on IScope to supply the getPhysicalNode() method, which existed
> in CDT 3.1 but not CDT 4.0.
> Its ctor supplies:
>  public Symbol( IASTDeclarator declarator, IASTDeclaration declaration)
> whose args are core.dom.ast classes.
> A simplified version of this method is provided here (without checks for
> null, exception catching etc.)
> Any ideas on how to get the containing node from an IASTDeclarator?
>
>
>     /**
>      * getDefiningFunction - get the function in which declartor is
> defined
>      * @return IASTNode - either IASTTranslationUnit or
> IASTFunctionDefinition
>      */
>     public IASTNode getDefiningFunction()
>     {
>         IScope scope = declarator_.getName().resolveBinding().getScope
> ();//simplified
>         if (scope==).null)  return null;
>
>         IASTNode node  node = scope.getPhysicalNode();  // *** <===
> doesn't
> exist in CDT 4.0
>
>         // keep moving up the tree until we find the node
>         while(true) {
>             if (node==null)  return null;
>             if (node instanceof IASTTranslationUnit) return node;      //
> global dict
>             if (node instanceof IASTFunctionDefinition)  return node;  //
> our function
>             node = node.getParent();
>         }
>     }
>
> ...Beth
>
> Beth Tibbitts  (859) 243-4981  (TL 545-4981)
> High Productivity Tools / Parallel Tools  http://eclipse.org/ptp
> IBM T.J.Watson Research Center
> Mailing Address:  IBM Corp., 455 Park Place, Lexington, KY 40511
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev




Back to the top