LCOV - code coverage report
Current view: top level - ccode - valaccodeblock.vala (source / functions) Coverage Total Hit
Test: vala 0.57.0.253-297e8 Lines: 91.7 % 24 22
Test Date: 2024-02-21 16:21:37 Functions: - 0 0

            Line data    Source code
       1              : /* valaccodeblock.vala
       2              :  *
       3              :  * Copyright (C) 2006-2008  Jürg Billeter
       4              :  *
       5              :  * This library is free software; you can redistribute it and/or
       6              :  * modify it under the terms of the GNU Lesser General Public
       7              :  * License as published by the Free Software Foundation; either
       8              :  * version 2.1 of the License, or (at your option) any later version.
       9              : 
      10              :  * This library is distributed in the hope that it will be useful,
      11              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13              :  * Lesser General Public License for more details.
      14              : 
      15              :  * You should have received a copy of the GNU Lesser General Public
      16              :  * License along with this library; if not, write to the Free Software
      17              :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
      18              :  *
      19              :  * Author:
      20              :  *      Jürg Billeter <j@bitron.ch>
      21              :  */
      22              : 
      23              : using GLib;
      24              : 
      25              : /**
      26              :  * Represents a C code block.
      27              :  */
      28       412587 : public class Vala.CCodeBlock : CCodeStatement {
      29              :         /**
      30              :          * Specifies whether a newline at the end of the block should be
      31              :          * suppressed.
      32              :          */
      33         4708 :         public bool suppress_newline { get; set; }
      34              : 
      35       206172 :         private List<CCodeNode> statements = new ArrayList<CCodeNode> ();
      36              : 
      37              :         /**
      38              :          * Prepend the specified statement to the list of statements.
      39              :          */
      40            0 :         public void prepend_statement (CCodeNode statement) {
      41            0 :                 statements.insert (0, statement);
      42              :         }
      43              : 
      44              :         /**
      45              :          * Append the specified statement to the list of statements.
      46              :          */
      47       244428 :         public void add_statement (CCodeNode statement) {
      48              :                 /* allow generic nodes to include comments */
      49       244428 :                 statements.add (statement);
      50              :         }
      51              : 
      52        79544 :         public override void write (CCodeWriter writer) {
      53              :                 // the last reachable statement
      54        39772 :                 CCodeNode last_statement = null;
      55              : 
      56        39772 :                 writer.write_begin_block ();
      57       484270 :                 foreach (CCodeNode statement in statements) {
      58       222249 :                         statement.write_declaration (writer);
      59              : 
      60              :                         // determine last reachable statement
      61       222249 :                         if (statement is CCodeLabel || statement is CCodeCaseStatement) {
      62         2447 :                                 last_statement = null;
      63       219802 :                         } else if (statement is CCodeReturnStatement || statement is CCodeGotoStatement
      64       206087 :                         || statement is CCodeContinueStatement || statement is CCodeBreakStatement) {
      65        15612 :                                 last_statement = statement;
      66              :                         }
      67              :                 }
      68              : 
      69       452504 :                 foreach (CCodeNode statement in statements) {
      70       220833 :                         statement.write (writer);
      71              : 
      72              :                         // only output reachable code
      73       220833 :                         if (statement == last_statement) {
      74        14467 :                                 break;
      75              :                         }
      76              :                 }
      77              : 
      78        39772 :                 writer.write_end_block ();
      79              : 
      80        39772 :                 if (!suppress_newline) {
      81        35064 :                         writer.write_newline ();
      82              :                 }
      83              :         }
      84              : }
        

Generated by: LCOV version 2.0-1