Types in dynamically typed languages
David Nolden
zwabel+kde at gmail.com
Sun Jun 29 12:05:02 UTC 2008
Am Sonntag, 29. Juni 2008 13:19:19 schrieb Niko Sams:
> Hi,
>
> How can I find out the type of this variable:
> $foo = new A();
> My Idea:
> When an assignmentExpression-node is encountered the type of the
> assigned value is detected
> by an ExprVisitor-class that walks the expr-ast and returns the Type.
> This is easy for the case
> above, also for function calls (that have a return-type). For any
> other expression an IntegralType
> must be used.
>
> next case; function return-type:
> function foo() {
> return new A();
> }
> Here I could In the TypeBuilder for every return statement set the
> return-type of the function. But
> there could be several return-statements in one function.
Yes I think you have exactly the right idea, that's what I thought to. You
need an expression visitor that can evaluate the possible types returned by
expressions, and you've got to assign those types either to the assigned
value, or to the function if it's a "return" statement. There's some
complexity problems though, because to be correct you would actually need to
follow every possible path, and you need to model somehow the dependency of
return-types from argument-types.
For a usable solution you probably wouldn't need to be all that correct
though. :)
Greetings, David
More information about the KDevelop-devel
mailing list