LCOV - code coverage report
Current view: top level - as2js/lib - parser_variable.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 36 100.0 %
Date: 2014-08-10 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* parser_variable.cpp -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       2             : 
       3             : /*
       4             : 
       5             : Copyright (c) 2005-2014 Made to Order Software Corp.
       6             : 
       7             : http://snapwebsites.org/project/as2js
       8             : 
       9             : Permission is hereby granted, free of charge, to any
      10             : person obtaining a copy of this software and
      11             : associated documentation files (the "Software"), to
      12             : deal in the Software without restriction, including
      13             : without limitation the rights to use, copy, modify,
      14             : merge, publish, distribute, sublicense, and/or sell
      15             : copies of the Software, and to permit persons to whom
      16             : the Software is furnished to do so, subject to the
      17             : following conditions:
      18             : 
      19             : The above copyright notice and this permission notice
      20             : shall be included in all copies or substantial
      21             : portions of the Software.
      22             : 
      23             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      24             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      25             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      26             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      27             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      28             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      29             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      30             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      31             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      32             : SOFTWARE.
      33             : 
      34             : */
      35             : 
      36             : #include    "as2js/parser.h"
      37             : #include    "as2js/message.h"
      38             : 
      39             : 
      40             : namespace as2js
      41             : {
      42             : 
      43             : 
      44             : /**********************************************************************/
      45             : /**********************************************************************/
      46             : /***  PARSER VARIABLE  ************************************************/
      47             : /**********************************************************************/
      48             : /**********************************************************************/
      49             : 
      50      114702 : void Parser::variable(Node::pointer_t& node, bool const constant)
      51             : {
      52      114702 :     node = f_lexer->get_new_node(Node::node_t::NODE_VAR);
      53             :     for(;;)
      54             :     {
      55      114702 :         Node::pointer_t variable_node(f_lexer->get_new_node(Node::node_t::NODE_VARIABLE));
      56      114702 :         if(constant)
      57             :         {
      58       40965 :             variable_node->set_flag(Node::flag_t::NODE_VARIABLE_FLAG_CONST, true);
      59             :         }
      60      114702 :         node->append_child(variable_node);
      61             : 
      62      114702 :         if(f_node->get_type() == Node::node_t::NODE_IDENTIFIER)
      63             :         {
      64       98316 :             variable_node->set_string(f_node->get_string());
      65       98316 :             get_token();
      66             :         }
      67             :         else
      68             :         {
      69       16386 :             Message msg(message_level_t::MESSAGE_LEVEL_ERROR, err_code_t::AS_ERR_INVALID_VARIABLE, f_lexer->get_input()->get_position());
      70       16386 :             msg << "expected an identifier as the " << (constant ? "const" : "variable") << " name.";
      71             :         }
      72             : 
      73      114702 :         if(f_node->get_type() == Node::node_t::NODE_COLON)
      74             :         {
      75       16386 :             get_token();
      76       16386 :             Node::pointer_t type(f_lexer->get_new_node(Node::node_t::NODE_TYPE));
      77       16386 :             Node::pointer_t expr;
      78       16386 :             conditional_expression(expr, false);
      79       16386 :             type->append_child(expr);
      80       32772 :             variable_node->append_child(type);
      81             :         }
      82             : 
      83      114702 :         if(f_node->get_type() == Node::node_t::NODE_ASSIGNMENT)
      84             :         {
      85             :             // TBD: should we avoid the NODE_SET on each attribute?
      86             :             //      at this time we get one expression per attribute...
      87       98316 :             get_token();
      88      114702 :             do
      89             :             {
      90             :                 // TODO: to really support all attributes we need to have
      91             :                 //       a switch here to include all the keyword based
      92             :                 //       attributes (i.e. private, abstract, etc.)
      93             :                 //
      94             :                 //       [however, we must make sure we do not interfere with
      95             :                 //       other uses of those keywords in expressions, private
      96             :                 //       and public are understood as scoping keywords!]
      97             :                 //
      98      114702 :                 Node::pointer_t initializer(f_lexer->get_new_node(Node::node_t::NODE_SET));
      99      114702 :                 Node::pointer_t expr;
     100      114702 :                 conditional_expression(expr, false);
     101      114702 :                 initializer->append_child(expr);
     102      229404 :                 variable_node->append_child(initializer);
     103             :                 // We loop in case we have a list of attributes!
     104             :                 // This could also be a big syntax error (a missing
     105             :                 // operator in most cases.) We will report the error
     106             :                 // later once we know where the variable is being
     107             :                 // used.
     108             :             }
     109             :             while(constant
     110       49158 :                 && f_node->get_type() != Node::node_t::NODE_COMMA
     111       49158 :                 && f_node->get_type() != Node::node_t::NODE_SEMICOLON
     112       16386 :                 && f_node->get_type() != Node::node_t::NODE_OPEN_CURVLY_BRACKET
     113       16386 :                 && f_node->get_type() != Node::node_t::NODE_CLOSE_CURVLY_BRACKET
     114      163860 :                 && f_node->get_type() != Node::node_t::NODE_CLOSE_PARENTHESIS);
     115             :         }
     116             : 
     117      114702 :         if(f_node->get_type() != Node::node_t::NODE_COMMA)
     118             :         {
     119      229404 :             return;
     120             :         }
     121      114702 :         get_token();
     122      114702 :     }
     123             : }
     124             : 
     125             : 
     126             : 
     127             : 
     128          20 : }
     129             : // namespace as2js
     130             : 
     131             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.9