Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Getting the right IBinding for multiple types with the same name faster

Thanks, Sergey. Please find my comments in red below. Thanks!

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Sergey Prigogin
Sent: Thursday, August 07, 2014 4:54 PM
To: CDT General developers list.
Subject: Re: [cdt-dev] Getting the right IBinding for multiple types with the same name faster

 

 

 

On Thu, Aug 7, 2014 at 4:32 PM, Ayupov, Andrey <andrey.ayupov@xxxxxxxxx> wrote:

Hm… So let’s say I build an AST for a translation unit using index and option AST_SKIP_INDEXED_HEADERS. There’s a class definition in that unit and I can get a binding from the corresponding IASTName. The binding is of type ICPPClassType and then I call getFields() on it. Then, if I take one field and try to resolve its type (which is a class that’s defined in two different headers, i.e. it has ambiguous definition as far as the index goes), will I get binding for the right class or it is also not certain?

 

In the use case you described there is probably only one ugly hybrid binding for the field type in the index.

 

From your description and since I skipped indexed headers from the AST construction, it should have the same problem as the index?

 

Maybe we could have something similar to what you have with resolving fields for template classes, i.e. passing IASTNode “at”. Even if the binding is the same, getFields may return different set of fields for ambiguous binding depending on “at” node which could be used for disambiguation. It would be nice if it was possible to quickly find out the IASTName of the correct class in the current context by quickly looking at the chain of includes without building the complete AST, but I believe there is no corresponding API for that now, am I right?

 

There are methods IASTTranslationUnit.getDefinitionsinAST and getDeclarationsInAST. 

 

 

It will not work for ASTs that were built with AST_SKIP_INDEXED_HEADERS flag because those objects are in the some headers that I skip. I cannot afford building the complete AST in my case. But what I was talking about is another mode for AST creation that would just contain declarations maybe. Then I can afford creating this one and then finding the IASTName that correspond to my class.

 

 

Thank you!

 

By the way, when I get a binding from index for the class that has two definitions in the project, then calling getFields on the binding of type class will return fields from both classes, which is odd…

 

It is indeed. It is not clear how to define binding identity so that the two bindings could coexist in the index and be found effectively.

 

What if I request my users to use namespaces? Will two classes with the same name but different namespaces end up being different bindings?

 

-sergey

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Sergey Prigogin
Sent: Tuesday, August 05, 2014 8:37 PM
To: CDT General developers list.
Subject: Re: [cdt-dev] Getting the right IBinding for multiple types with the same name faster

 

If the binding is coming from the index, it cannot be disambiguated since the index doesn't store multiple bindings with the same fully qualified name, unless the binding is local to a particular file (IIndexBinding.getLocalToFile() returns non-null).

 

-sergey

 

On Tue, Aug 5, 2014 at 6:54 PM, Ayupov, Andrey <andrey.ayupov@xxxxxxxxx> wrote:

Suppose I have multiple class definitions with the same name in my project, when I see an instance of that class, let’s say as a local variable in my case, I’d like to be able to resolve it to the right class type (and IBinding). Of course, only one class is visible in that scope where that variable is declared. I use IASTName#resolveBinding that returns IVariable for which getType returns the ICPPClassType that correspond to the wrong class.  I found that the reason is in how AST was created. When I use

 

IASTTranslationUnit ast = tu.getAST(index,ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT);

it started to work, but is quite expensive.

 

Before I used IASTTranslationUnit ast = tu.getAST(index,ITranslationUnit.AST_SKIP_INDEXED_HEADERS);

but it didn’t work.

 

Do you see any other (less expensive) way to achieve what I want? Index doesn’t seem to be of help as I am dealing with function local variables. However, the type itself should be in the index, but it will show two types if I just search for it by name.  I thought I’d be able to skip all the function bodies (using ITranslationUnit.AST_SKIP_FUNCTION_BODIES) to speed AST construction up, but then it will skip my function as well K

 

Thank you,

Andrey


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

 


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

 


Back to the top