Finding the declaration owning a type
Sven Brauch
svenbrauch at googlemail.com
Sun Apr 13 15:07:59 UTC 2014
Hi!
On Sunday 13 April 2014 16:39:54 Denis Steckelmacher wrote:
> Most of the time, types are created and then assigned to a declaration.
> If I have not missed something, the declaration knows its type but a
> type doesn't know its declaration.
The type's declaration is the declaration which declared the type itself
(which can be retrieved for IdentifiedTypes); not a variable which has that
type. The type data is shared among all variables which have that type. E.g.
if you have a class declaration, that will create a type (which is just one
object) and all variables which are instances of that class just point to that
object. There isn't a copy of the type data for each of them. Thus you cannot
have the type data point to a particular variable declaration with that type.
> This works, but it is not particularly elegant.
Yes, it sucks. Still, it's what e.g. Python and other languages do too; they
find the declaration as well as the type.
It does not *really* introduce any additional complexity though, just
additional code: When you find the types in the expression visitor, you get
them from a literal or a declaration sooner or later anyways for the cases
where the declaration's type could be updated. So you just have to store that
as well.
For updating function arguments, you can just get the nth argument of func's
argument context.
Maybe a simple solution would be to have base expression visitor class which
handles this complexity, e.g. through having a method to set the current type
from a declaration.
Greetings!
More information about the KDevelop-devel
mailing list