Review Request 117458: Support for function expressions

Sven Brauch svenbrauch at googlemail.com
Tue Apr 22 22:03:08 UTC 2014



> On April 22, 2014, 9:50 p.m., Milian Wolff wrote:
> > looks pretty good, I'd say we can clean it up and commit it to test it out?
> > 
> > some notes on your commit message though:
> > 
> > "ExpressionVisitor stops visiting when it encounters a type (no need to traverse the AST down to its bottom if the top-most expression is enough to determine a type). This gives it a O(1) time complexity." - That is not O(1), as it still depends on the depth of the type it first encounters (which could be far down, no?). Just remove that Big-O stuff ;-)
> > 
> > thanks

I agree, not O(1), e.g. for stacked binary operators it's still O(n).

Sorry Milian, but I think this patch was split up and submitted in separate parts already. Denis, can you make sure you close it (and other reviews which you might no longer intend to submit) as discarded to avoid confusion? Thanks!


- Sven


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


On April 11, 2014, 2:38 p.m., Denis Steckelmacher wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/117458/
> -----------------------------------------------------------
> 
> (Updated April 11, 2014, 2:38 p.m.)
> 
> 
> Review request for KDevelop.
> 
> 
> Repository: kdev-qmljs
> 
> 
> Description
> -------
> 
> This patch adds support for function expressions to the QML/JS plugin. This support required the following changes:
> 
> * ExpressionVisitor stops visiting when it encounters a type (no need to traverse the AST down to its bottom if the top-most expression is enough to determine a type). This gives it a O(1) time complexity.
> * When DeclarationBuilder wants to know the type of an expression, it first visits this expression (to build any needed declaration), then only starts an ExpressionVisitor. This way, ExpressionVisitor knows all the declarations that may occur in the expression and is able to return its complete type. Moreover, if DeclarationBuilder has called getType (and has visited an expression), then will not enter the node it is visiting (as it already did so). This way, DeclarationBuilder keeps an O(n) time complexity.
> * These two changes are illustrated by the support of "var f = function() { return true; }" statements.
> * This patch also adds support for binary operators ("a == b" is always a boolean, "a << 2" is always an int, etc). This fixes a bug where the type of "(a == 5)" was wrongly guessed as "int"
> 
> The support for function expressions is split between DeclarationBuilder and ExpressionVisitor. DeclarationBuilder, when it encounters a function expression, creates a declaration for it, giving it a name built from the hexadecimal representation of its FunctionExpression* node pointer. When DeclarationBuilder sees a return statement, it sets the type of the enclosing function (whether it is a function declaration or a function expression has no importance here). When ExpressionVisitor is used to find the type of an expression, and this expression is a function expression, then ExpressionVisitor will build the hexadecimal name of the function and use getDeclaration to find its type.
> 
> 
> Diffs
> -----
> 
>   duchain/CMakeLists.txt 9fab69c 
>   duchain/contextbuilder.h d53b2fe 
>   duchain/contextbuilder.cpp d38da2d 
>   duchain/declarationbuilder.h 001c3b2 
>   duchain/declarationbuilder.cpp 98da341 
>   duchain/expressionvisitor.h b4f0851 
>   duchain/expressionvisitor.cpp 766435d 
>   duchain/helper.h 23a6d0e 
>   duchain/helper.cpp 3ffdd56 
>   duchain/parsesession.h 0eb2762 
>   duchain/parsesession.cpp dbc4d90 
>   duchain/tests/testdeclarations.cpp 668efaa 
>   tests/files/helloworld.js ff40f1c 
> 
> Diff: https://git.reviewboard.kde.org/r/117458/diff/
> 
> 
> Testing
> -------
> 
> All the unit tests of the QML/JS plugin pass with this patch. Three tests have been added:
> 
> * The test for type inference is not expected to fail anymore, as the plugin is able to infer simple types
> * New test for "(a == b)" expressions
> * New test for "function() {}" expressions
> 
> Manual testing shows that syntax highlighting is correct, and also the "outline" view. Building the anonymous declarations by passing them an empty range (RangeInRevision()) removes the anonymous function from the outline view and disables any highlighting related to this declaration in the source view. The function can still have a name which can be freely chosen by the plugin.
> 
> 
> Thanks,
> 
> Denis Steckelmacher
> 
>

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


More information about the KDevelop-devel mailing list