When create DUContexts

Andreas Pakulat apaku at gmx.de
Sat Jun 14 12:35:45 UTC 2008


On 14.06.08 21:02:29, Hamish Rodda wrote:
> 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 :)

That needs to go into the DUChain design document, because thats exactly
what authors of language parts need to know :) (I don't have time right
now to do that)

> > > 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)

Note that there's already a basecontextbuilder in
kdevplatform/language/duchain. Its been formed by me from the
python+qmake builders, so hopefully is good enough that you can just go
on with declaration and typebuilder :) (as I don't see myself doing
qmake support in the near future, given all those little bugs all
around)

Andreas

-- 
Never reveal your best argument.




More information about the KDevelop-devel mailing list