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

          Line data    Source code
       1             : /* parser.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             : 
      38             : #include "as2js/message.h"
      39             : 
      40             : 
      41             : namespace as2js
      42             : {
      43             : 
      44             : 
      45             : /**********************************************************************/
      46             : /**********************************************************************/
      47             : /***  PARSER  *********************************************************/
      48             : /**********************************************************************/
      49             : /**********************************************************************/
      50             : 
      51     1097862 : Parser::Parser(Input::pointer_t input, Options::pointer_t options)
      52     1097862 :     : f_lexer(new Lexer(input, options))
      53     2195724 :     , f_options(options)
      54             :     //, f_root(nullptr) -- auto-init [we keep it unknown at the start]
      55             :     //, f_node(nullptr) -- auto-init
      56             :     //, f_unget() -- auto-init
      57             : {
      58     1097862 : }
      59             : 
      60             : 
      61     1097862 : Node::pointer_t Parser::parse()
      62             : {
      63             :     // This parses everything and creates ONE tree
      64             :     // with the result. The tree obviously needs to
      65             :     // fit in RAM...
      66             : 
      67             :     // We lose the previous tree if any and create a new
      68             :     // root node. This is our program node.
      69     1097862 :     get_token();
      70     1097862 :     program(f_root);
      71             : 
      72     1097862 :     return f_root;
      73             : }
      74             : 
      75             : 
      76    41899002 : void Parser::get_token()
      77             : {
      78    41899002 :     bool const reget(!f_unget.empty());
      79             : 
      80    41899002 :     if(reget)
      81             :     {
      82     1089669 :         f_node = f_unget.back();
      83     1089669 :         f_unget.pop_back();
      84             :     }
      85             :     else
      86             :     {
      87    40809333 :         f_node = f_lexer->get_next_token();
      88             :     }
      89    41899002 : }
      90             : 
      91             : 
      92     1089669 : void Parser::unget_token(Node::pointer_t& node)
      93             : {
      94     1089669 :     f_unget.push_back(node);
      95     1089669 : }
      96             : 
      97             : 
      98             : 
      99             : /** \brief Check whether a given option is set.
     100             :  *
     101             :  * Because the parser checks options in many places, it makes use of this
     102             :  * helper function to avoid having to check the f_options pointer
     103             :  * every single time.
     104             :  *
     105             :  * This function checks whether the specified option is set. If so,
     106             :  * then it returns true, otherwise it returns false.
     107             :  *
     108             :  * If no option were specified when the Parser object was created,
     109             :  * then the function always returns false.
     110             :  *
     111             :  * \param[in] option  The option to check.
     112             :  *
     113             :  * \return true if the option was set, false otherwise.
     114             :  */
     115      475192 : bool Parser::has_option_set(Options::option_t option) const
     116             : {
     117      475192 :     if(f_options)
     118             :     {
     119      475136 :         return f_options->get_option(option) != 0;
     120             :     }
     121             : 
     122          56 :     return false;
     123             : }
     124             : 
     125             : 
     126             : 
     127          20 : }
     128             : // namespace as2js
     129             : 
     130             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.9