Definition/Declaration/Use usage

David Nolden zwabel at googlemail.com
Tue Aug 28 13:50:26 UTC 2007


"int i" is a Declaration ,and a Definition, so 
Declaration::declarationIsDefinition() returns true

"i = 2" The first part, the "i" is a Use of the Declaration above
"int j = i+1;" The first part is a Declaration+Definition of "j", the "i" is a 
use of the Declaration above.

The only cases where a Declaration is not a Definition in C++ is in case of 
functions declared without definition. That's the only use of 
the "Definition" class in C++.


To the redeclaration:
The du-chain can contain as many declarations of a name as you wish, it 
probably just isn't useful.

As I've written to Aleix, the most logical solution would be:
- Always test if the variable is already declared by using findDeclarations.
  - If it is, create a Use.
  - If it is not, create a Declaration.

That way foo=myobject1() would be a declaration, and foo=myobject2() would be 
a use.

It of course depends on the language whether it's logical.

You could also simply create declarations all the time, and always only use 
the last declaration found. That might make the du-chain significantly slower 
and bigger though, depends on the amout of duplication.

greetings, David




More information about the KDevelop-devel mailing list