Finding the declaration owning a type

Denis Steckelmacher steckdenis at yahoo.fr
Sun Apr 13 14:39:54 UTC 2014


Hi,

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.

I've just proposed a patch that adds support to the QML/JS parser for 
variables whose types are known only after the first assignation to 
them. When an assignation to such a variable is encountered, 
ExpressionVisitor tries to find its declaration, and DeclarationBuilder 
updates its type.

This works, but it is not particularly elegant. These kinds of features 
should be easier to implement if AbstractType knows its declaration (if 
it has one). For instance, adding a method DeclarationPointer 
AbstractType::owner() could allow things like that:

* Updating the type of variables when assignation statements are 
encountered: "leftType->owner()->setAbstractType(mergeTypes(leftType, 
rightType))"
* Updating the type of function parameters at every call site: 
"func->arguments()[i]->owner()->setAbstractType(mergeTypes(..., 
typeOfArgumentInCall[i]))". I will submit a patch that does that without 
requiring AbstractType::owner(), but I will need to use the internal 
function context of the functions (to get their parameters), then to 
rely on the fact that parameters are declared in order.

What do you think about that? Is there something that I have missed or 
something that prevents such a feature from being added (for instance, 
if types are de-duplicated in some way or the other and therefore can 
have more than one declaration)?

Denis Steckelmacher


More information about the KDevelop-devel mailing list