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

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? 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?


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…


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).




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,


cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit


Back to the top