Review Request 117516: Recognize the type of function expressions

Sven Brauch svenbrauch at googlemail.com
Sat Apr 12 19:02:24 UTC 2014


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/117516/#review55532
-----------------------------------------------------------

Ship it!


Looks good. By the way, KDevelop requires C++11, so feel free to use e.g. auto as it seems appropriate.

Thanks!

- Sven Brauch


On April 12, 2014, 6:36 p.m., Denis Steckelmacher wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/117516/
> -----------------------------------------------------------
> 
> (Updated April 12, 2014, 6:36 p.m.)
> 
> 
> Review request for KDevelop.
> 
> 
> Repository: kdev-qmljs
> 
> 
> Description
> -------
> 
> In Javascript, functions can be declared on their own (using "function foo() {}") or be anonymous and declared in an expression ("var f = function(){}", and also "setTimeout(function() { ... })"). This latter form is very common in Javascript, as callbacks are widely used.
> 
> ContextBuilder already supports function expressions (it correctly builds contexts for them and for their arguments). This patch adds support for function expressions in DeclarationBuilder and ExpressionVisitor. DeclarationBuilder builds anonymous declarations for the functions, and ExpressionVisitor uses the fact that anonymous functions open a context of which they are the owner in order to find their type.
> 
> When a function is declared, its return type is left to NULL. It is set to void only when DeclarationBuilder ends visiting a function expression or declaration. I do this because the next patch will add support for unsure types, and every return statement will add its type to the return type of the function, so this return type needs to be empty at the beginning of the function. Having all the functions returning "void or int" or "void or string" is useless.
> 
> This patch also fixes a small bug in return statements: "return;" was setting the return type of the function to "mixed" instead of "void", because ContextBuilder::findType returns mixed if the node passed as argument is NULL.
> 
> 
> Diffs
> -----
> 
>   duchain/declarationbuilder.h 8d8f771 
>   duchain/declarationbuilder.cpp 1d5610e 
>   duchain/expressionvisitor.h 4e8ac29 
>   duchain/expressionvisitor.cpp 418f1a9 
>   tests/files/helloworld.js df86d4f 
> 
> Diff: https://git.reviewboard.kde.org/r/117516/diff/
> 
> 
> Testing
> -------
> 
> This patch adds various tests for function expressions. Here is an example of the expressions recognized:
> 
> var f = function() { return 2; };        // function int ()
> var g = function(a, b) { return a + b; } // function mixed (mixed, mixed)
> var a = (function() { return true; })(); // bool, the function has been called
> 
> 
> Thanks,
> 
> Denis Steckelmacher
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20140412/16f2b9a5/attachment.html>


More information about the KDevelop-devel mailing list