[kdev-qmljs] /: Register uses of declarations in the proper contexts

Denis Steckelmacher steckdenis at yahoo.fr
Wed Jul 9 11:58:31 UTC 2014

On 07/09/2014 11:39 AM, Milian Wolff wrote:
> Hey Denis,
> On Tuesday 08 July 2014 18:50:56 Denis Steckelmacher wrote:
>> Git commit 1cb1f6774841aaf7778a4b1e87fcf4396fcce0bb by Denis Steckelmacher.
>> Committed on 08/07/2014 at 18:46.
>> Pushed by dsteckelmacher into branch 'master'.
>> Register uses of declarations in the proper contexts
>> Use ContextBuilder::contextOnNode to open and close contexts as needed, so
>> that UseBuilder can register the uses in the correct contexts. This commit
>> also replaces DUContext* with DUContextPointer in ParseSession so that
>> deleted contexts don't crash KDevelop.
>> As usual, when something is fixed in UseBuilder, some use counts have to
>> change in the unit tests. All the uses are now correct and no declaration
>> gets counted as an use.
> Are you sure that a declaration should _not_ be a use? Afaik in other
> languages, the declaration is also a use, but maybe I'm mistaken?
> Bye

UseBuilder registers uses for any identifier it encounters. Your remark 
made me wondering why "var a;" declares a but does not use it. In fact, 
I looked closely at the QMLJS AST and declarations always "hide" what 
they are declaring.

For instance, "var a;" is represented using a VariableDeclaration node, 
that has a name (a QStringRef, not a node, so UseBuilder does not see 
it) and an optional initializer. In "{a: 3}", a PropertyNameAndValue 
node is used. This node has a name (again a QStringRef, not a node) and 
an initializer.

I think that this is the cause of the behavior of UseBuilder. If 
declared identifiers don't appear in AST Identifier nodes, then 
UseBuilder cannot see them. Is it really a problem that declarations are 
not also uses?

 >  Anyhow, did you ensure that browsing through uses (e.g. "next use" 
action in the navigation menu) cycles properly through all uses, 
including the initial declaration?

I may have missed it but I don't have any "next use" in the navigation 
menu. I've verified that the declaration of a variable and all its uses 
are properly shown in "show uses":

   Line X: var a;
In Global:
   Line Y: a = 2;
   Line Z: console.log(a);
In do_something(...):
   Line W: a += b;

More information about the KDevelop-devel mailing list