When create DUContexts

Hamish Rodda rodda at kde.org
Sat Jun 14 11:02:29 UTC 2008


On Sat, 14 Jun 2008 08:42:00 pm Niko Sams wrote:
> >> function foo() {
> >>     if (true) {
> >>         $i = 1;
> >>     }
> >>     echo $i; //prints 1
> >> }
> >
> > I don't exactly know php, but in C++ you would create:
> > - A context for foo parameters
> > - A context for foo body, which imports parameters
> > - A context for the condition in the if statement
> > - A context for the compound statement behind the if statement, that
> > imports the conditions context
>
> the problem is that $i is defined in line 3 in its own context and
> used in an outer context.
> In c++ this is not possible, but in php I would have to import the
> "if-body" context or something.
> OR: do we need a new context for the if-statement at all? (probably a
> very naive idea...)

That is right, don't create a context here if the declarations within those 
blocks are visible outside the blocks. Easy :)

> > What bothers me more than creating context when it comes to dynamic
> > languages is the creation of Declarations. You will probably have to
> > create a Declaration on the first assignment to a name, but will you be
> > able to tell that declarations type?
>
> I haven't thought about that much yet :D
>
> that case would be fairly easy:
> class A {}
> $foo = new A();
>
> but that one is hard:
> function createA() { return new A() }
> $foo = createA();
>
> the return-type of the createA function has to be evaluated to get the
> correct type.
> Do you think this might be possible?
>
> This is now impossible without running the code:
> $i = 'A';
> $foo = new $i();
>
> another idea:
> /**
>   * @return A
>   **/
> function createA() { return new A() }
> $foo = createA();

That's just a limitation of the language; how smart your code needs to be is 
the question.  It may not need to provide all of the type information.

BTW, I am about to start work on an abstract *builder base class to be shared 
between the language supports, when I'm done you'd probably want to port to 
that (should be pretty easy i'd say)

Cheers,
Hamish.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20080614/c543b1a9/attachment.sig>


More information about the KDevelop-devel mailing list