Non default declaration search mechanism

Milian Wolff mail at
Sun Jan 22 02:03:25 UTC 2012

On Sunday 22 January 2012 02:36:47 Kucharski, Lukasz wrote:
> Hi all,
> I am currently working on a ttcn3 plug-in for kdevelop and I've encountered
> a problem that I don't how to solve in elegant and efficient way.

Hey there!

Cool to see more people working on KDev plugins. Are you doing this openly? If 
not, please do so! Put your code up on, should make it easier for 
you and all others to use it.

> Following C/C++ represents my problem:
> enum AAA
> {
>     one,
>     two
> };
> enum BBB
> {
>     one,
>     two
> };
> const AAA c_val1 = one;
> const BBB c_val2 = one;
> Of course this won't compile however equivalent ttcn3 code is valid.
> Having 'one' enumerator in two different enumeration types requires named
> context to allow use definition to valid enumerator.
> Enumeration types without named context allows to find all 'one'
> declarations but use chain is build always to first declaration, I mean
> declaration from AAA type. Enumeration types with named context
> [setPropagateDeclarations(true)] do not allow to find enumerator
> declarations with default search mechanism. I were able to successfully
> overload findLocalDeclarationsInternal and findDeclarationsInternal methods
> to achieve required functionality however it's very slow.

Personally, I would do it even differently. That is, (maybe) use 
propagateDeclarations, but definitely don't overload the findDeclarations* 
methods - that's pure suicide (as proven by looking at the actual 
implementation / the c++ overload).

Couldn't you maybe achieve the above by manually checking the following 
conditions in your usebuilder and handle them appropriatly?

- if inside assignment expression
- if target-type is of type enum
-> look for declaration in enum-declaration's internalContext

This might work for this case, but I'm not sure about your language's other 
features. Does it allow function-overloading?

foo(AAA) {...}
foo(BBB) {...}

foo(one); <-- which one is called?

> Is there anybody there that knows declaration search mechanism well enough
> to point me a right direction?

Personally I found it much simpler (in most of my C++ work and in all of my 
PHP work) to just use the plain old findDeclaration* functions just within the 
proper context.


Milian Wolff
mail at

More information about the KDevelop-devel mailing list