ForwardDeclaration usage

Milian Wolff mail at milianw.de
Wed Feb 11 13:15:24 UTC 2009


Hi Devels!

I introduced a PreDeclarationBuilder for PHP but this introduced a bunch of 
bugs I only now realize. Before I try to fix them, I wanted to ask if I could 
not make it obsolete by using ForwardDeclarations. Take this code:

~~~~
<?php
$foo = new Bar;
class Bar {}
~~~~

I.e.: In PHP it is possible to use classes before they are actually declared.

For KDevelop we used the PreDeclarationBuilder (and before that just ran the 
DeclarationBuilder twice) to get all class declarations (and functions etc.) 
so the above definition of $foo finds the class Bar before it was declared.

But: Could I not use ForwardDeclaration at the "new Bar" (since it could not 
be found)? Then, once class Bar is found, resolve the ForwardDeclaration to be 
a "normal" ClassDeclaration? Is this done automatically? Can I access a list 
of unresolved ForwardDeclarations of a topcontext? I would need this for error 
reporting (class xyz could not be found).

Or should I simply do something like this "manually" i.e. introduce a 
container of AstNode to my DeclarationBuilder which stores nodes where not-
found Declarations are used. Then each new declaration of 
classes/functions/etc. could check the container and re-run visitNode(stored 
astnode); for those declarations which already used this new declaration.

What would you suggest?
-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20090211/634addc2/attachment.sig>


More information about the KDevelop-devel mailing list