[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [qmlweb/development/qmlweb2] /: [Compiler] Add some missing expressions
From:       Jan Marker <jan () jangmarker ! de>
Date:       2015-09-30 20:44:35
Message-ID: E1ZhOEt-0000CB-Ds () scm ! kde ! org
[Download RAW message or body]

Git commit 0945848beca425a9324bbbafd5d3a025c19c7ffb by Jan Marker.
Committed on 30/09/2015 at 20:41.
Pushed by jangmarker into branch 'development/qmlweb2'.

[Compiler] Add some missing expressions

* void, delete, typeof
* unary +,-,!,~
* new
* conditional expression
* nested expression

M  +59   -0    src/qmljsc/purejavascriptgenerator.cpp
M  +11   -0    src/qmljsc/purejavascriptgenerator.h
M  +1    -1    tests/auto/data/javascript/expressions.js
A  +1    -0    tests/auto/data/javascript/lefthandexpressions.compiled.js
A  +7    -0    tests/auto/data/javascript/lefthandexpressions.js
D  +0    -1    tests/auto/data/javascript/propertyaccess.compiled.js
D  +0    -3    tests/auto/data/javascript/propertyaccess.js
A  +1    -0    tests/auto/data/javascript/unaryoperators.js
M  +39   -1    tests/auto/qmljsc/testpurejavascriptgenerator.cpp
M  +2    -1    tests/auto/qmljsc/testpurejavascriptgenerator_integration.cpp

http://commits.kde.org/qmlweb/0945848beca425a9324bbbafd5d3a025c19c7ffb

diff --git a/src/qmljsc/purejavascriptgenerator.cpp b/src/qmljsc/purejavascriptgenerator.cpp
index ae1fd2e..10708c6 100644
--- a/src/qmljsc/purejavascriptgenerator.cpp
+++ b/src/qmljsc/purejavascriptgenerator.cpp
@@ -230,12 +230,24 @@ void PureJavaScriptGenerator::endVisit(AST::CaseClauses *caseClauses) {
     reduceListStack<AST::CaseClauses>(caseClauses);
 }
 
+void PureJavaScriptGenerator::endVisit(AST::ConditionalExpression *) {
+    const QString secondExpression = m_outputStack.pop();
+    const QString firstExpression = m_outputStack.pop();
+    const QString condition = m_outputStack.pop();
+    m_outputStack << condition + '?' + firstExpression + ':' + secondExpression;
+}
+
 void PureJavaScriptGenerator::endVisit(AST::DefaultClause *) {
     const QString statement = m_outputStack.pop();
     const QString defaultKeyword = m_outputStack.pop();
     m_outputStack << defaultKeyword + ':' + statement;
 }
 
+void PureJavaScriptGenerator::endVisit(AST::DeleteExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << "delete " + expression;
+}
+
 void PureJavaScriptGenerator::endVisit(AST::ElementList *elementList) {
     QString code;
     AST::ElementList *currentElement = elementList;
@@ -335,6 +347,27 @@ void PureJavaScriptGenerator::endVisit(AST::LocalForStatement *localForStatement
     m_outputStack << "for(" + declaration + ';' + condition + ';' + incrementExpression + ')' + \
statement;  }
 
+void PureJavaScriptGenerator::endVisit(AST::NewExpression *) {
+    const QString constructor = m_outputStack.pop();
+    m_outputStack << "new " + constructor;
+}
+
+void PureJavaScriptGenerator::endVisit(AST::NewMemberExpression *newMemberExpression) {
+    const QString arguments = (newMemberExpression->arguments)?m_outputStack.pop():"";
+    const QString constructor = m_outputStack.pop();
+    m_outputStack << "new " + constructor + '(' + arguments + ')';
+}
+
+void PureJavaScriptGenerator::endVisit(AST::NestedExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << '(' + expression + ')';
+}
+
+void PureJavaScriptGenerator::endVisit(AST::NotExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << '!' + expression;
+}
+
 void PureJavaScriptGenerator::endVisit(AST::NumericLiteral *) {
 }
 
@@ -406,6 +439,26 @@ void PureJavaScriptGenerator::endVisit(AST::SwitchStatement *) {
     m_outputStack << "switch(" + expression + ')' + clauseBlock;
 }
 
+void PureJavaScriptGenerator::endVisit(AST::TildeExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << '~' + expression;
+}
+
+void PureJavaScriptGenerator::endVisit(AST::TypeOfExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << "typeof " + expression;
+}
+
+void PureJavaScriptGenerator::endVisit(AST::UnaryMinusExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << '-' + expression;
+}
+
+void PureJavaScriptGenerator::endVisit(AST::UnaryPlusExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << '+' + expression;
+}
+
 void PureJavaScriptGenerator::endVisit(AST::VariableDeclaration *declaration) {
     const QString expression = (declaration->expression) ? "="+m_outputStack.pop() : "";
     const QString variableName = declaration->name.toString();
@@ -423,6 +476,12 @@ void PureJavaScriptGenerator::endVisit(AST::VariableStatement *) {
     m_outputStack << m_outputStack.pop() + ';';
 }
 
+void PureJavaScriptGenerator::endVisit(AST::VoidExpression *) {
+    const QString expression = m_outputStack.pop();
+    m_outputStack << "void " + expression;
+}
+
+
 void PureJavaScriptGenerator::endVisit(AST::WhileStatement *) {
     const QString statement = m_outputStack.pop();
     const QString expression = m_outputStack.pop();
diff --git a/src/qmljsc/purejavascriptgenerator.h b/src/qmljsc/purejavascriptgenerator.h
index 35dfa35..ad4635e 100644
--- a/src/qmljsc/purejavascriptgenerator.h
+++ b/src/qmljsc/purejavascriptgenerator.h
@@ -57,7 +57,9 @@ public:
     virtual void endVisit(QQmlJS::AST::CaseBlock *) override;
     virtual void endVisit(QQmlJS::AST::CaseClause *) override;
     virtual void endVisit(QQmlJS::AST::CaseClauses *) override;
+    virtual void endVisit(QQmlJS::AST::ConditionalExpression *) override;
     virtual void endVisit(QQmlJS::AST::DefaultClause *) override;
+    virtual void endVisit(QQmlJS::AST::DeleteExpression *) override;
     virtual void endVisit(QQmlJS::AST::DoWhileStatement *) override;
     virtual void endVisit(QQmlJS::AST::ElementList *) override;
     virtual void endVisit(QQmlJS::AST::EmptyStatement *) override;
@@ -71,6 +73,10 @@ public:
     virtual void endVisit(QQmlJS::AST::IfStatement *) override;
     virtual void endVisit(QQmlJS::AST::LocalForEachStatement *) override;
     virtual void endVisit(QQmlJS::AST::LocalForStatement *) override;
+    virtual void endVisit(QQmlJS::AST::NewExpression *) override;
+    virtual void endVisit(QQmlJS::AST::NewMemberExpression *) override;
+    virtual void endVisit(QQmlJS::AST::NestedExpression *) override;
+    virtual void endVisit(QQmlJS::AST::NotExpression *) override;
     virtual void endVisit(QQmlJS::AST::NumericLiteral *) override;
     virtual void endVisit(QQmlJS::AST::ObjectLiteral *) override;
     virtual void endVisit(QQmlJS::AST::PostDecrementExpression *) override;
@@ -85,9 +91,14 @@ public:
     virtual void endVisit(QQmlJS::AST::StringLiteral *) override;
     virtual void endVisit(QQmlJS::AST::StatementList *) override;
     virtual void endVisit(QQmlJS::AST::SwitchStatement *) override;
+    virtual void endVisit(QQmlJS::AST::TildeExpression *) override;
+    virtual void endVisit(QQmlJS::AST::TypeOfExpression *) override;
+    virtual void endVisit(QQmlJS::AST::UnaryMinusExpression *) override;
+    virtual void endVisit(QQmlJS::AST::UnaryPlusExpression *) override;
     virtual void endVisit(QQmlJS::AST::VariableDeclaration *) override;
     virtual void endVisit(QQmlJS::AST::VariableDeclarationList *) override;
     virtual void endVisit(QQmlJS::AST::VariableStatement *) override;
+    virtual void endVisit(QQmlJS::AST::VoidExpression *) override;
     virtual void endVisit(QQmlJS::AST::WhileStatement *) override;
 
 private:
diff --git a/tests/auto/data/javascript/expressions.js b/tests/auto/data/javascript/expressions.js
index b97808a..3923c92 100644
--- a/tests/auto/data/javascript/expressions.js
+++ b/tests/auto/data/javascript/expressions.js
@@ -1 +1 @@
-var x;var i;var e=i++;e=++i;e=i--;e=--i;
\ No newline at end of file
+var x;var i;var e=i++;e=++i;e=i--;e=--i;5*(2+3);true?1:2;
\ No newline at end of file
diff --git a/tests/auto/data/javascript/lefthandexpressions.compiled.js \
b/tests/auto/data/javascript/lefthandexpressions.compiled.js new file mode 100644
index 0000000..6a83ce4
--- /dev/null
+++ b/tests/auto/data/javascript/lefthandexpressions.compiled.js
@@ -0,0 +1 @@
+obj.prop;obj["prop"];obj[0];new great();new greater(1);new greater(1,2);new great;
\ No newline at end of file
diff --git a/tests/auto/data/javascript/lefthandexpressions.js \
b/tests/auto/data/javascript/lefthandexpressions.js new file mode 100644
index 0000000..656bd83
--- /dev/null
+++ b/tests/auto/data/javascript/lefthandexpressions.js
@@ -0,0 +1,7 @@
+obj.prop;
+obj["prop"];
+obj[0];
+new great();
+new greater(1);
+new greater(1, 2);
+new great;
\ No newline at end of file
diff --git a/tests/auto/data/javascript/propertyaccess.compiled.js \
b/tests/auto/data/javascript/propertyaccess.compiled.js deleted file mode 100644
index 4a11b7d..0000000
--- a/tests/auto/data/javascript/propertyaccess.compiled.js
+++ /dev/null
@@ -1 +0,0 @@
-obj.prop;obj["prop"];obj[0];
\ No newline at end of file
diff --git a/tests/auto/data/javascript/propertyaccess.js b/tests/auto/data/javascript/propertyaccess.js
deleted file mode 100644
index 094b1ed..0000000
--- a/tests/auto/data/javascript/propertyaccess.js
+++ /dev/null
@@ -1,3 +0,0 @@
-obj.prop;
-obj["prop"];
-obj[0];
\ No newline at end of file
diff --git a/tests/auto/data/javascript/unaryoperators.js b/tests/auto/data/javascript/unaryoperators.js
new file mode 100644
index 0000000..26e391a
--- /dev/null
+++ b/tests/auto/data/javascript/unaryoperators.js
@@ -0,0 +1 @@
+delete v;void 4;typeof o;+5;-5;~4;!false;
\ No newline at end of file
diff --git a/tests/auto/qmljsc/testpurejavascriptgenerator.cpp \
b/tests/auto/qmljsc/testpurejavascriptgenerator.cpp index 67573fe..4542e21 100644
--- a/tests/auto/qmljsc/testpurejavascriptgenerator.cpp
+++ b/tests/auto/qmljsc/testpurejavascriptgenerator.cpp
@@ -114,6 +114,7 @@ public:
         , m_twoPropertiesPart2(&m_twoProperties, &m_propertyNameAndValue)
         , m_objectLiteral(&m_twoProperties)
         , m_equalsBinaryExpression(nullptr, QSOperator::Equal, nullptr)
+        , m_nestedExpression(nullptr)
         , m_postDecrementExpression(&m_numericalExpressionPi)
         , m_postIncrementExpression(&m_numericalExpressionPi)
         , m_preDecrementExpression(&m_numericalExpressionPi)
@@ -126,6 +127,17 @@ public:
         , m_argumentListTwoArgumentsPart2(&m_argumentListTwoArguments, &m_trueLiteral)
         , m_callExpressionWithArguments(&m_identifierExpression, &m_argumentListTwoArguments)
         , m_callExpressionWithoutArguments(&m_identifierExpression, nullptr)
+        , m_newMemberExpressionArguments(&m_identifierExpression, &m_argumentListOneArgument)
+        , m_newMemberExpressionNoArguments(&m_identifierExpression, nullptr)
+        , m_newExpression(&m_identifierExpression)
+        , m_tildeExpression(&m_identifierExpression)
+        , m_notExpression(&m_identifierExpression)
+        , m_unaryPlusExpression(&m_identifierExpression)
+        , m_unaryMinusExpression(&m_identifierExpression)
+        , m_deleteExpression(&m_identifierExpression)
+        , m_typeOfExpression(&m_identifierExpression)
+        , m_voidExpression(&m_identifierExpression)
+        , m_conditionalExpression(&m_trueLiteral, &m_numericalExpressionPi, &m_numericalExpressionPi)
         /* Variable Declarations */
         , m_constDeclaration1(m_someIdentifierStringRef, nullptr)
         , m_constDeclaration2(m_anotherIdentifierStringRef, nullptr)
@@ -252,6 +264,7 @@ private:
     AST::ObjectLiteral m_objectLiteral;
 
     AST::BinaryExpression m_equalsBinaryExpression;
+    AST::NestedExpression m_nestedExpression;
 
     AST::PostDecrementExpression m_postDecrementExpression;
     AST::PostIncrementExpression m_postIncrementExpression;
@@ -266,6 +279,19 @@ private:
     AST::ArgumentList m_argumentListTwoArgumentsPart2;
     AST::CallExpression m_callExpressionWithArguments;
     AST::CallExpression m_callExpressionWithoutArguments;
+    AST::NewMemberExpression m_newMemberExpressionNoArguments;
+    AST::NewMemberExpression m_newMemberExpressionArguments;
+    AST::NewExpression m_newExpression;
+
+    AST::TildeExpression m_tildeExpression;
+    AST::NotExpression m_notExpression;
+    AST::UnaryPlusExpression m_unaryPlusExpression;
+    AST::UnaryMinusExpression m_unaryMinusExpression;
+    AST::DeleteExpression m_deleteExpression;
+    AST::TypeOfExpression m_typeOfExpression;
+    AST::VoidExpression m_voidExpression;
+
+    AST::ConditionalExpression m_conditionalExpression;
 
     /* Variable Declarations */
     AST::VariableDeclaration m_constDeclaration1;
@@ -415,8 +441,10 @@ private slots:
     TEST_ENDVISIT_REDUCES(CaseBlock               , CasesDefaultCases , "{cases;default;cases;}", \
                ({"cases;", "default;", "cases;"}), m_caseBlockCasesDefaultCases)
     TEST_ENDVISIT_REDUCES(CaseClause              , CaseWithStatement , "case exp:stm;"   , ({"case", \
                "exp", "stm;"})    , m_caseClause)
     TEST_ENDVISIT_REDUCES(CaseClauses             , TwoClauses        , "case e:s;case e2:s2;", ({"case \
e:s;", "case e2:s2;"}), m_twoCaseClauses) +    TEST_ENDVISIT_REDUCES(ConditionalExpression   , AnyCase    \
                , "condition?e1:e2" , ({"condition", "e1", "e2"})  , m_conditionalExpression)
     TEST_ENDVISIT_REDUCES(DefaultClause           , AnyCase           , "default:stm"     , ({"default", \
                "stm"})         , m_defaultClause)
-    TEST_ENDVISIT_REDUCES(DoWhileStatement        , AnyCase           , "do stm;while(e);", ({"stm;", \
"e"})               , m_doWhileStatement) +    TEST_ENDVISIT_REDUCES(DeleteExpression        , AnyCase    \
, "delete v"        , ({"v"})                      , m_deleteExpression) +    \
TEST_ENDVISIT_REDUCES(DoWhileStatement        , AnyCase           , "do stm;while(e);", ({"stm;", "e"})   \
                , m_doWhileStatement)
     TEST_ENDVISIT_REDUCES(ElementList             , Expression        , "expr,"           , ({"expr"})   \
                , m_arrayElementsExp)
     TEST_ENDVISIT_REDUCES(ElementList             , TwoExpressions    , "expr,expr,"      , ({"expr", \
                "expr"})           , m_arrayElementsExpExp)
     TEST_ENDVISIT_REDUCES(ElementList             , ElisionExpression , "elisionexpr,"    , ({"elision", \
"expr"})        , m_arrayElementsElisionExp) @@ -438,6 +466,11 @@ private slots:
     TEST_ENDVISIT_REDUCES(LocalForEachStatement   , AnyCase           , "for(var i in o)stm;", ({"i", \
                "o", "stm;"})      , m_localForEachStatement)
     TEST_ENDVISIT_REDUCES(LocalForStatement       , AllParts          , "for(var i;c;++)stm;", ({"var \
                i", "c", "++", "stm;"}), m_localForStatementAllParts)
     TEST_ENDVISIT_REDUCES(LocalForStatement       , NoPart            , "for(;;)stm;"     , ({"stm;"})   \
, m_localForStatementNoPart) +    TEST_ENDVISIT_REDUCES(NestedExpression        , AnyCase           , \
"(expression)"    , ({"expression"})             , m_nestedExpression) +    \
TEST_ENDVISIT_REDUCES(NewExpression           , AnyCase           , "new constr"      , ({"constr"})      \
, m_newExpression) +    TEST_ENDVISIT_REDUCES(NewMemberExpression     , NoArguments       , "new \
constr()"    , ({"constr"})                 , m_newMemberExpressionNoArguments) +    \
TEST_ENDVISIT_REDUCES(NewMemberExpression     , Arguments         , "new constr(arg)" , ({"constr", \
"arg"})          , m_newMemberExpressionArguments) +    TEST_ENDVISIT_REDUCES(NotExpression           , \
                AnyCase           , "!5"              , ({"5"})                      , m_notExpression)
     TEST_ENDVISIT_REDUCES(NumericLiteral          , AnyCase           , "2.7"             , ({"2.7"})    \
                , m_numericalExpressionPi)
     TEST_ENDVISIT_REDUCES(ObjectLiteral           , AnyCase           , "{properties}"    , \
                ({"properties"})             , m_objectLiteral)
     TEST_ENDVISIT_REDUCES(PostDecrementExpression , AnyCase           , "2.7--"           , ({"2.7"})    \
, m_postDecrementExpression) @@ -456,12 +489,17 @@ private slots:
     TEST_ENDVISIT_REDUCES(SourceElements          , ThreeStatements   , "st1st2st3"       , ({"st1", \
                "st2", "st3"})      , m_threeStatementsList)
     TEST_ENDVISIT_REDUCES(StringLiteral           , AnyCase           , "another string"  , ({"another \
                string"})         , m_stringLiteral)
     TEST_ENDVISIT_REDUCES(SwitchStatement         , AnyCase           , "switch(e){blk}"  , ({"e", \
"{blk}"})             , m_switchStatement) +    TEST_ENDVISIT_REDUCES(TildeExpression         , AnyCase   \
, "~5"              , ({"5"})                      , m_tildeExpression) +    \
TEST_ENDVISIT_REDUCES(TypeOfExpression        , AnyCase           , "typeof v"        , ({"v"})           \
, m_typeOfExpression) +    TEST_ENDVISIT_REDUCES(UnaryMinusExpression    , AnyCase           , "-5"       \
, ({"5"})                      , m_unaryMinusExpression) +    TEST_ENDVISIT_REDUCES(UnaryPlusExpression   \
                , AnyCase           , "+5"              , ({"5"})                      , \
                m_unaryPlusExpression)
     TEST_ENDVISIT_REDUCES(VariableDeclaration     , WithAssignment    , "i=5"             , ({"5"})      \
                , m_variableDeclarationWithAssignment)
     TEST_ENDVISIT_REDUCES(VariableDeclaration     , WithoutAssignment , "i"               , ({})         \
                , m_variableDeclarationWithoutAssignment)
     TEST_ENDVISIT_REDUCES(VariableDeclarationList , TwoDeclarations   , "var i,e=5"       , ({"i", \
                "e=5"})               , m_twoVarDeclarations)
     TEST_ENDVISIT_REDUCES(VariableDeclarationList , OneDeclaration    , "var e=5"         , ({"e=5"})    \
                , m_twoVarDeclarationsPart2)
     TEST_ENDVISIT_REDUCES(VariableDeclarationList , ConstDeclaration  , "const e=5"       , ({"e=5"})    \
                , m_twoConstDeclarationsPart2)
     TEST_ENDVISIT_REDUCES(VariableStatement       , AnyCase           , "x;"              , ({"x"})      \
, m_variableStatement) +    TEST_ENDVISIT_REDUCES(VoidExpression          , AnyCase           , "void v"  \
                , ({"v"})                      , m_voidExpression)
     TEST_ENDVISIT_REDUCES(WhileStatement          , AnyCase           , "while(e)stm"     , ({"e", \
"stm"})               , m_whileStatement)  
     TEST_VISIT_BINARYOP_PUTS_ON_STACK(Assign, "=")
diff --git a/tests/auto/qmljsc/testpurejavascriptgenerator_integration.cpp \
b/tests/auto/qmljsc/testpurejavascriptgenerator_integration.cpp index 9ec3227..606e556 100644
--- a/tests/auto/qmljsc/testpurejavascriptgenerator_integration.cpp
+++ b/tests/auto/qmljsc/testpurejavascriptgenerator_integration.cpp
@@ -83,6 +83,7 @@ private slots:
         addRowForFileWithCompiled("declarations");
         addRowForFile("expressions");
         addRowForFileWithCompiled("functions");
+        addRowForFile("unaryoperators");
         addRowForFileWithCompiled("binaryoperations");
         addRowForFileWithCompiled("otherstatements");
         addRowForFileWithCompiled("ifstatements");
@@ -90,7 +91,7 @@ private slots:
         addRowForFileWithCompiled("literals");
         addRowForFileWithCompiled("arrayliterals");
         addRowForFileWithCompiled("objectliterals");
-        addRowForFileWithCompiled("propertyaccess");
+        addRowForFileWithCompiled("lefthandexpressions");
         addRowForFileWithCompiled("functioncalls");
         addRowForFileWithCompiled("loops");
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic